### Install vfit-react Source: https://github.com/v-plugin/vfit/blob/main/vfit-react/README.md Install the package via npm. ```bash npm install vfit-react ``` -------------------------------- ### Install vfit package Source: https://github.com/v-plugin/vfit/blob/main/docs/en/guide/getting-started.md Use npm to add the vfit dependency to your project. ```bash npm i vfit ``` -------------------------------- ### FitContainer Centered with Percentage Units Source: https://github.com/v-plugin/vfit/blob/main/docs/en/guide/fitcontainer.md This example demonstrates centering content using percentage-based positioning. When 'unit="%"' is used, the position remains fixed relative to the container, and only the content scales proportionally with the global scale. ```vue
Content
``` -------------------------------- ### Centering Element with Percentage Offsets Source: https://github.com/v-plugin/vfit/blob/main/docs/en/guide/positions.md This example demonstrates how to center an element using percentage-based offsets for `top` and `left`. The `transform: translate(-50%, -50%)` on the inner div is crucial for true centering when using percentage-based positioning. ```vue
Center
``` -------------------------------- ### Get Current Scale Value with useFitScale Source: https://context7.com/v-plugin/vfit/llms.txt Use the `useFitScale` composable within your Vue components to access the globally calculated scale value. This allows for dynamic styling or conditional rendering based on the current scale. ```APIDOC ## useFitScale - Get Current Scale Value The `useFitScale` composable returns a reactive reference to the current scale value, allowing components to access the global scale for custom calculations or conditional rendering based on the current scale level. ```vue ``` ``` -------------------------------- ### createFitScale(options) Source: https://github.com/v-plugin/vfit/blob/main/docs/en/guide/api.md Initializes the global scale configuration and injects it into the application. ```APIDOC ## createFitScale(options) ### Description Initializes the plugin and injects the global scale into the application via provide. ### Parameters #### Request Body - **target** (string | HTMLElement) - Optional - The target element to scale (default: #app) - **designHeight** (number) - Optional - The design height (default: 1080) - **designWidth** (number) - Optional - The design width (default: 1920) - **scaleMode** ('height' | 'width' | 'auto') - Optional - The scaling strategy (default: auto) ### Response - **plugin object** (Object) - Returns the plugin instance. ``` -------------------------------- ### createFitScale(options) Source: https://github.com/v-plugin/vfit/blob/main/docs/guide/api.md Initializes the vfit plugin to handle global screen scaling. ```APIDOC ## createFitScale(options) ### Description Initializes the plugin and injects global scaling into the Vue app. ### Parameters #### Request Body - **target** (string | HTMLElement) - Optional - The target element to scale, defaults to #app. - **designHeight** (number) - Optional - The design height, defaults to 1080. - **designWidth** (number) - Optional - The design width, defaults to 1920. - **scaleMode** ('height' | 'width' | 'auto') - Optional - The scaling strategy, defaults to auto. ``` -------------------------------- ### Initialize vfit plugin Source: https://github.com/v-plugin/vfit/blob/main/docs/en/guide/getting-started.md Register the plugin in your main entry file with design dimensions and scaling configuration. ```ts // main.ts import { createFitScale } from 'vfit' import 'vfit/style.css' app.use(createFitScale({ target: '#app', designHeight: 1080, designWidth: 1920, scaleMode: 'auto' })) ``` -------------------------------- ### Configure FitScaleProvider Source: https://github.com/v-plugin/vfit/blob/main/vfit-react/README.md Wrap the application with FitScaleProvider to enable global scaling based on design dimensions. ```tsx // App.tsx import React from 'react' import { FitScaleProvider } from 'vfit-react' const App = () => { return ( ) } export default App ``` -------------------------------- ### Build custom components with useFitPosition Source: https://context7.com/v-plugin/vfit/llms.txt The useFitPosition composable generates reactive style objects for custom positioning logic. ```vue ``` -------------------------------- ### Implement VFit in React Source: https://context7.com/v-plugin/vfit/llms.txt Wrap the application with FitScaleProvider to initialize scaling and use FitContainer for absolute positioning within the scaled environment. ```tsx // App.tsx import React from 'react' import { FitScaleProvider, FitContainer, useFitScale } from 'vfit-react' // Wrap your app with the provider function App() { return ( ) } // Use FitContainer for positioning function Dashboard() { const scale = useFitScale() // Access current scale value return (
{/* Top-left logo */} Logo {/* Top-right time */} {/* Centered main content */}
{/* Bottom-right controls with custom scale */} {/* Custom styling */}
) } export default App ``` -------------------------------- ### useFitScale() Source: https://github.com/v-plugin/vfit/blob/main/docs/guide/api.md Hook to retrieve the current scaling factor within components. ```APIDOC ## useFitScale() ### Description Returns a Ref representing the current scaling value calculated by the plugin. ``` -------------------------------- ### Plugin Initialization with createFitScale Source: https://context7.com/v-plugin/vfit/llms.txt Initialize the VFit plugin in your Vue application. You can use default options or provide custom configurations for target element, design dimensions, and scale mode. ```APIDOC ## createFitScale - Plugin Initialization The `createFitScale` function creates a Vue 3 plugin that monitors a target element for size changes and provides a reactive scale value to all child components. It accepts options for target element, design dimensions, and scale mode, and automatically registers all positioning components globally. ```typescript // main.ts import { createApp } from 'vue' import { createFitScale } from 'vfit' import 'vfit/style.css' import App from './App.vue' const app = createApp(App) // Basic setup with default options (1920x1080 design, auto scale mode) app.use(createFitScale()) // Custom configuration for a 4K design app.use(createFitScale({ target: '#app', // CSS selector or HTMLElement (default: '#app') designWidth: 3840, // Design width in pixels (default: 1920) designHeight: 2160, // Design height in pixels (default: 1080) scaleMode: 'auto' // 'auto' | 'width' | 'height' (default: 'auto') })) // Scale modes explained: // - 'height': scale = containerHeight / designHeight // - 'width': scale = containerWidth / designWidth // - 'auto': maintains aspect ratio, picks width or height based on which fits better app.mount('#app') ``` ``` -------------------------------- ### Create Fit Scale with Auto Mode Source: https://github.com/v-plugin/vfit/blob/main/docs/en/guide/scale-modes.md Use createFitScale to apply global scaling. Configure target element, design dimensions, and set scaleMode to 'auto' for automatic width or height scaling to maintain aspect ratio. ```typescript app.use(createFitScale({ target: '#app', designHeight: 1080, designWidth: 1920, scaleMode: 'auto' })) ``` -------------------------------- ### Top Left Layout (Logo, Weather) Source: https://github.com/v-plugin/vfit/blob/main/docs/en/recipes.md Position content at the top-left corner of the screen. ```vue ``` ```vue ``` -------------------------------- ### Positioning Components Source: https://github.com/v-plugin/vfit/blob/main/docs/guide/api.md Specialized components for absolute positioning at screen corners or center. ```APIDOC ## Positioning Components ### Description Components for corner (, , , ) and center () positioning. ### Parameters #### Corner Components Attributes - **top/bottom/left/right** (number) - Optional - Positioning offset. - **unit** (string) - Optional - Measurement unit. - **scale** (number) - Optional - Scaling override. - **z** (number) - Optional - Z-index value. #### Center Component Attributes - **scale** (number) - Optional - Scaling override. - **z** (number) - Optional - Z-index value. ``` -------------------------------- ### Bottom Right Layout (Control Panel) Source: https://github.com/v-plugin/vfit/blob/main/docs/en/recipes.md Position content at the bottom-right corner of the screen. ```vue ``` ```vue ``` -------------------------------- ### Initialize VFit Plugin Source: https://context7.com/v-plugin/vfit/llms.txt Register the VFit plugin in your Vue application entry point. You can use default settings or provide custom design dimensions and scale modes. ```typescript // main.ts import { createApp } from 'vue' import { createFitScale } from 'vfit' import 'vfit/style.css' import App from './App.vue' const app = createApp(App) // Basic setup with default options (1920x1080 design, auto scale mode) app.use(createFitScale()) // Custom configuration for a 4K design app.use(createFitScale({ target: '#app', // CSS selector or HTMLElement (default: '#app') designWidth: 3840, // Design width in pixels (default: 1920) designHeight: 2160, // Design height in pixels (default: 1080) scaleMode: 'auto' // 'auto' | 'width' | 'height' (default: 'auto') })) // Scale modes explained: // - 'height': scale = containerHeight / designHeight // - 'width': scale = containerWidth / designWidth // - 'auto': maintains aspect ratio, picks width or height based on which fits better app.mount('#app') ``` -------------------------------- ### Bottom Left Layout (Charts, Lists) Source: https://github.com/v-plugin/vfit/blob/main/docs/en/recipes.md Position content at the bottom-left corner of the screen. ```vue ``` ```vue ``` -------------------------------- ### Screen Center Layout (Main Chart, Map) Source: https://github.com/v-plugin/vfit/blob/main/docs/en/recipes.md Center content on the screen. The concise component handles centering automatically. ```vue ``` ```vue
``` -------------------------------- ### FitScaleProvider Component Source: https://github.com/v-plugin/vfit/blob/main/vfit-react/README.md The FitScaleProvider component wraps your application to provide global scaling values based on design dimensions. ```APIDOC ## FitScaleProvider Props ### Parameters #### Request Body - **options.target** (string | HTMLElement) - Optional - The container to listen for resize events (default: document.body) - **options.designHeight** (number) - Optional - The design draft height (default: 1080) - **options.designWidth** (number) - Optional - The design draft width (default: 1920) - **options.scaleMode** ('height' | 'width' | 'auto') - Optional - The scaling mode (default: 'auto') ``` -------------------------------- ### Positioning Components Source: https://github.com/v-plugin/vfit/blob/main/docs/en/guide/api.md Components for absolute positioning relative to the scaled container. ```APIDOC ## Positioning Components ### Description Components for corner and center positioning: , , , , . ### Parameters #### Corner Component Props - **top/bottom/left/right** (number) - Optional - Positioning offsets - **unit** (string) - Optional - Measurement unit - **scale** (number) - Optional - Scale override - **z** (number) - Optional - Z-index #### Center Component Props - **scale** (number) - Optional - Scale override - **z** (number) - Optional - Z-index ``` -------------------------------- ### Top Right Layout (Time, Status) Source: https://github.com/v-plugin/vfit/blob/main/docs/en/recipes.md Position content at the top-right corner of the screen. ```vue ``` ```vue ``` -------------------------------- ### useFitScale() Source: https://github.com/v-plugin/vfit/blob/main/docs/en/guide/api.md Retrieves the current scale value within a Vue component. ```APIDOC ## useFitScale() ### Description Returns the current scale value as a reactive reference. ### Response - **scale** (Ref) - The current scale factor. ``` -------------------------------- ### FitContainer Component Source: https://github.com/v-plugin/vfit/blob/main/docs/en/guide/api.md A container component for managing layout and scaling. ```APIDOC ## FitContainer ### Description Container component for applying specific layout and scaling rules. ### Parameters #### Props - **top/bottom/left/right** (number) - Optional - Positioning offsets - **unit** ('px' | '%') - Optional - Measurement unit (default: px) - **scale** (number) - Optional - Overrides global scale - **z** (number) - Optional - Z-index (default: 300) ``` -------------------------------- ### Use vfit-lt positioning component Source: https://github.com/v-plugin/vfit/blob/main/docs/en/guide/getting-started.md Implement the vfit-lt component for top-left aligned layout within a relative container. ```vue ``` -------------------------------- ### Custom Scale Configuration Source: https://github.com/v-plugin/vfit/blob/main/docs/en/recipes.md Apply a custom scale factor to a component. ```vue ``` ```vue ``` -------------------------------- ### Center content with vfit-center Source: https://context7.com/v-plugin/vfit/llms.txt Use vfit-center for automatic horizontal and vertical centering with optional scaling and z-index overrides. ```vue ``` -------------------------------- ### Use FitContainer for Positioning Source: https://github.com/v-plugin/vfit/blob/main/vfit-react/README.md Use FitContainer to position elements with automatic scaling support, choosing between pixel or percentage units. ```tsx import React from 'react' import { FitContainer } from 'vfit-react' const MyDashboard = () => { return (
{/* 百分比定位 - 保持居中 */}
Centered Content
{/* 像素定位 - 随屏幕缩放 */}
Scaled Box
) } ``` -------------------------------- ### Bottom-Left Positioning with vfit-lb Source: https://context7.com/v-plugin/vfit/llms.txt Employ vfit-lb for positioning content from the bottom-left corner, setting the transform origin to 0 100%. Suitable for auxiliary charts, data lists, and supplementary information panels. ```vue ``` -------------------------------- ### Access Scale with useFitScale Hook Source: https://github.com/v-plugin/vfit/blob/main/vfit-react/README.md Retrieve the current raw scaling value directly using the useFitScale hook. ```tsx import React from 'react' import { useFitScale } from 'vfit-react' const ScaleDisplay = () => { const scale = useFitScale() return
Current Scale: {scale}
} ``` -------------------------------- ### Position elements with FitContainer Source: https://context7.com/v-plugin/vfit/llms.txt FitContainer allows for precise edge-based positioning using top, bottom, left, and right offsets with configurable units. ```vue ``` -------------------------------- ### Custom Positioning Unit Source: https://github.com/v-plugin/vfit/blob/main/docs/en/recipes.md Override the default unit (px) with percentage (%) for positioning. ```vue ``` ```vue ``` -------------------------------- ### vfit-lt - Top-Left Positioning Component Source: https://context7.com/v-plugin/vfit/llms.txt The `vfit-lt` component is used for positioning elements absolutely from the top-left corner with automatic scaling. It accepts `top`, `left`, `z-index`, and an optional `scale` prop for fine-grained control. ```APIDOC ## vfit-lt - Top-Left Positioning Component The `vfit-lt` component positions content absolutely from the top-left corner with automatic scaling. It's ideal for logos, weather widgets, and other elements that should anchor to the top-left of the viewport. ```vue ``` ``` -------------------------------- ### FitContainer Component Source: https://github.com/v-plugin/vfit/blob/main/docs/guide/api.md A container component that applies scaling and positioning logic to its children. ```APIDOC ## FitContainer ### Description Provides a container with configurable scaling and positioning. ### Parameters #### Attributes - **top/bottom/left/right** (number) - Optional - Positioning offset. - **unit** ('px' | '%') - Optional - Measurement unit, defaults to px. - **scale** (number) - Optional - Scaling override. - **z** (number) - Optional - Z-index, defaults to 300. ``` -------------------------------- ### Fixed Offset Positioning with Pixels Source: https://github.com/v-plugin/vfit/blob/main/docs/en/guide/positions.md Use this snippet to position an element a fixed distance from the bottom-right corner. The `unit="px"` attribute ensures the offsets are interpreted as pixels. ```vue ``` -------------------------------- ### Access Scale Value with useFitScale Source: https://context7.com/v-plugin/vfit/llms.txt Use the useFitScale composable to retrieve a reactive reference to the current scale, enabling dynamic calculations or conditional rendering. ```vue ``` -------------------------------- ### Complete Dashboard Layout with vfit Components Source: https://context7.com/v-plugin/vfit/llms.txt This Vue.js component utilizes vfit positioning components to arrange elements like headers, charts, sidebars, and action panels within a responsive dashboard. It demonstrates combining multiple positioning strategies for a complex UI. ```vue ``` -------------------------------- ### Bottom-Right Positioning with vfit-rb Source: https://context7.com/v-plugin/vfit/llms.txt Utilize vfit-rb to position elements from the bottom-right corner, with a transform origin of 100% 100%. This is ideal for control panels, action buttons, and legends. ```vue ``` -------------------------------- ### FitContainer with Fixed Pixel Distance Source: https://github.com/v-plugin/vfit/blob/main/docs/en/guide/fitcontainer.md Use this snippet to position an element a fixed pixel distance from the top and right edges of the screen. The 'unit="px"' prop ensures that 'top' and 'left' values scale with the global scale, while 'right' and 'bottom' maintain their actual screen pixel distance. ```vue ``` -------------------------------- ### Top-Right Positioning with vfit-rt Source: https://context7.com/v-plugin/vfit/llms.txt Use vfit-rt to position elements from the top-right corner. It automatically sets the transform origin to 100% 0 for scaling from the right edge. Ideal for time displays, status indicators, and system information. ```vue ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.