vfit 2.0.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -6
- package/dist/fitscale.es.js +16 -6
- package/dist/fitscale.umd.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/useFitPosition.d.ts +0 -1
- package/package.json +23 -4
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
作者:一颗烂土豆
|
|
6
6
|
|
|
7
|
-
Vue 3 的轻量缩放与定位解决方案。通过插件提供全局缩放值,并内置 `FitContainer`
|
|
7
|
+
Vue 3 的轻量缩放与定位解决方案。通过插件提供全局缩放值,并内置 `FitContainer` 与 5 个专用定位组件,让页面元素在不同分辨率下保持比例与位置一致。
|
|
8
8
|
|
|
9
9
|
## 安装与初始化
|
|
10
10
|
|
|
@@ -27,24 +27,23 @@ app.use(createFitScale({ target: '#app', designHeight: 1080, designWidth: 1920,
|
|
|
27
27
|
- `%`:位置不随缩放变化,适合居中/相对位置
|
|
28
28
|
- `px`:位置随缩放乘积变化,适合固定像素布局
|
|
29
29
|
|
|
30
|
-
###
|
|
30
|
+
### 居中(专用组件)
|
|
31
31
|
|
|
32
32
|
```vue
|
|
33
33
|
<template>
|
|
34
34
|
<div class="viewport">
|
|
35
|
-
<
|
|
35
|
+
<vfit-center>
|
|
36
36
|
<div class="card">内容</div>
|
|
37
|
-
</
|
|
37
|
+
</vfit-center>
|
|
38
38
|
</div>
|
|
39
39
|
</template>
|
|
40
40
|
|
|
41
41
|
<style scoped>
|
|
42
42
|
.viewport { position: relative; width: 100%; height: 100vh; }
|
|
43
|
-
.card { transform: translate(-50%, -50%); }
|
|
44
43
|
</style>
|
|
45
44
|
```
|
|
46
45
|
|
|
47
|
-
|
|
46
|
+
要点:居中组件自动完成定位与居中,内部内容按比例缩放。
|
|
48
47
|
|
|
49
48
|
### 像素定位(随缩放)
|
|
50
49
|
|
|
@@ -80,6 +79,10 @@ app.use(createFitScale({ target: '#app', designHeight: 1080, designWidth: 1920,
|
|
|
80
79
|
- `top/bottom/left/right?: number`
|
|
81
80
|
- `unit?: 'px' | '%'`(默认 `px`)
|
|
82
81
|
- `scale?: number`(覆盖全局缩放)
|
|
82
|
+
- `z?: number`(默认 `300`)
|
|
83
|
+
- 专用定位组件:
|
|
84
|
+
- `<vfit-lt>`、`<vfit-rt>`、`<vfit-lb>`、`<vfit-rb>`:支持 `top/left/right/bottom`、`unit`、`scale`、`z`
|
|
85
|
+
- `<vfit-center>`:支持 `scale`、`z`
|
|
83
86
|
|
|
84
87
|
## 小贴士
|
|
85
88
|
|
package/dist/fitscale.es.js
CHANGED
|
@@ -30,12 +30,11 @@ function useFitScale() {
|
|
|
30
30
|
}
|
|
31
31
|
function useFitPosition(props, options = {}) {
|
|
32
32
|
const position = reactive({
|
|
33
|
-
scale: `scale(1)`,
|
|
33
|
+
scale: `scale(1) translateZ(0)`,
|
|
34
34
|
top: "auto",
|
|
35
35
|
bottom: "auto",
|
|
36
36
|
left: "auto",
|
|
37
|
-
right: "auto"
|
|
38
|
-
translate: "translate(0, 0)"
|
|
37
|
+
right: "auto"
|
|
39
38
|
});
|
|
40
39
|
const origin = computed(() => {
|
|
41
40
|
if (options.origin) return options.origin;
|
|
@@ -47,9 +46,18 @@ function useFitPosition(props, options = {}) {
|
|
|
47
46
|
return "0 0";
|
|
48
47
|
});
|
|
49
48
|
const fitScale = inject(FitScaleKey, ref(1));
|
|
50
|
-
watch([
|
|
49
|
+
watch([
|
|
50
|
+
() => props.scale,
|
|
51
|
+
() => props.unit,
|
|
52
|
+
() => props.top,
|
|
53
|
+
() => props.bottom,
|
|
54
|
+
() => props.left,
|
|
55
|
+
() => props.right,
|
|
56
|
+
fitScale
|
|
57
|
+
], () => {
|
|
51
58
|
const s = props.scale && props.scale > 0 ? props.scale : (fitScale == null ? void 0 : fitScale.value) ?? 1;
|
|
52
|
-
|
|
59
|
+
const baseTransform = `scale(${s}) translateZ(0)`;
|
|
60
|
+
position.scale = options.extraTransform ? `${baseTransform} ${options.extraTransform}` : baseTransform;
|
|
53
61
|
const styleKey = ["top", "bottom", "left", "right"];
|
|
54
62
|
styleKey.forEach((key) => {
|
|
55
63
|
const val = props[key];
|
|
@@ -206,7 +214,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
206
214
|
const props = __props;
|
|
207
215
|
const { position, origin } = useFitPosition(props, {
|
|
208
216
|
origin: "50% 50%",
|
|
209
|
-
scaleKeys: []
|
|
217
|
+
scaleKeys: [],
|
|
218
|
+
// No positioning props to scale
|
|
219
|
+
extraTransform: "translate(-50%, -50%)"
|
|
210
220
|
});
|
|
211
221
|
return (_ctx, _cache) => {
|
|
212
222
|
return openBlock(), createElementBlock("div", {
|
package/dist/fitscale.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(t,e){typeof exports==="object"&&typeof module!=="undefined"?e(exports,require("vue")):typeof define==="function"&&define.amd?define(["exports","vue"],e):(t=typeof globalThis!=="undefined"?globalThis:t||self,e(t.FitScale={},t.Vue))})(this,function(t,e){"use strict";function o(t,e,o,n="auto",r=1920){const i=new ResizeObserver(t=>{for(const i of t){const t=i.contentRect.height;const s=i.contentRect.width;let l;if(n==="height"){l=t/e}else if(n==="width"){l=s/r}else{const o=r/e;if(s/t<o){l=s/r}else{l=t/e}}o(l)}});i.observe(t);return i}const n=Symbol("FitScale");function r(){const t=e.inject(n,e.ref(1));return t}function i(t,o={}){const r=e.reactive({scale:`scale(1)`,top:"auto",bottom:"auto",left:"auto",right:"auto"
|
|
1
|
+
(function(t,e){typeof exports==="object"&&typeof module!=="undefined"?e(exports,require("vue")):typeof define==="function"&&define.amd?define(["exports","vue"],e):(t=typeof globalThis!=="undefined"?globalThis:t||self,e(t.FitScale={},t.Vue))})(this,function(t,e){"use strict";function o(t,e,o,n="auto",r=1920){const i=new ResizeObserver(t=>{for(const i of t){const t=i.contentRect.height;const s=i.contentRect.width;let l;if(n==="height"){l=t/e}else if(n==="width"){l=s/r}else{const o=r/e;if(s/t<o){l=s/r}else{l=t/e}}o(l)}});i.observe(t);return i}const n=Symbol("FitScale");function r(){const t=e.inject(n,e.ref(1));return t}function i(t,o={}){const r=e.reactive({scale:`scale(1) translateZ(0)`,top:"auto",bottom:"auto",left:"auto",right:"auto"});const i=e.computed(()=>{if(o.origin)return o.origin;const e=t.right!==void 0;const n=t.bottom!==void 0;if(e&&n)return"100% 100%";if(e)return"100% 0";if(n)return"0 100%";return"0 0"});const s=e.inject(n,e.ref(1));e.watch([()=>t.scale,()=>t.unit,()=>t.top,()=>t.bottom,()=>t.left,()=>t.right,s],()=>{const e=t.scale&&t.scale>0?t.scale:(s==null?void 0:s.value)??1;const n=`scale(${e}) translateZ(0)`;r.scale=o.extraTransform?`${n} ${o.extraTransform}`:n;const i=["top","bottom","left","right"];i.forEach(n=>{const i=t[n];if(t.unit==="%"){r[n]=i==void 0?"auto":`${i}${t.unit}`}else{const s=o.scaleKeys?o.scaleKeys.includes(n):n==="left"||n==="top";r[n]=i==void 0?"auto":`${s?i*e:i}${t.unit}`}})},{immediate:true});return{position:r,origin:i}}const s=e.defineComponent({__name:"FitContainer",props:{scale:{type:Number,default:0},top:{type:Number},bottom:{type:Number},left:{type:Number},right:{type:Number},unit:{type:String,default:"px"},z:{type:Number,default:300}},setup(t){const o=t;const{position:n,origin:r}=i(o);return(t,i)=>(e.openBlock(),e.createElementBlock("div",{class:"fit-container",style:e.normalizeStyle({transform:e.unref(n).scale,transformOrigin:e.unref(r),top:e.unref(n).top,bottom:e.unref(n).bottom,left:e.unref(n).left,right:e.unref(n).right,zIndex:o.z})},[e.renderSlot(t.$slots,"default",{},void 0,true)],4))}});const l=(t,e)=>{const o=t.__vccOpts||t;for(const[n,r]of e){o[n]=r}return o};const c=l(s,[["__scopeId","data-v-42c37d40"]]);const a=e.defineComponent({__name:"VFitLT",props:{scale:{type:Number,default:0},top:{type:Number},left:{type:Number},unit:{type:String,default:"px"},z:{type:Number,default:300}},setup(t){const o=t;const{position:n,origin:r}=i(o);return(t,i)=>(e.openBlock(),e.createElementBlock("div",{class:"vfit-lt",style:e.normalizeStyle({transform:e.unref(n).scale,transformOrigin:e.unref(r),top:e.unref(n).top,left:e.unref(n).left,zIndex:o.z})},[e.renderSlot(t.$slots,"default",{},void 0,true)],4))}});const u=l(a,[["__scopeId","data-v-1533313f"]]);const f=e.defineComponent({__name:"VFitRT",props:{scale:{type:Number,default:0},top:{type:Number},right:{type:Number},unit:{type:String,default:"px"},z:{type:Number,default:300}},setup(t){const o=t;const{position:n,origin:r}=i(o,{origin:"100% 0",scaleKeys:["top","right"]});return(t,i)=>(e.openBlock(),e.createElementBlock("div",{class:"vfit-rt",style:e.normalizeStyle({transform:e.unref(n).scale,transformOrigin:e.unref(r),top:e.unref(n).top,right:e.unref(n).right,zIndex:o.z})},[e.renderSlot(t.$slots,"default",{},void 0,true)],4))}});const p=l(f,[["__scopeId","data-v-dfa9fc63"]]);const d=e.defineComponent({__name:"VFitLB",props:{scale:{type:Number,default:0},bottom:{type:Number},left:{type:Number},unit:{type:String,default:"px"},z:{type:Number,default:300}},setup(t){const o=t;const{position:n,origin:r}=i(o,{origin:"0 100%",scaleKeys:["bottom","left"]});return(t,i)=>(e.openBlock(),e.createElementBlock("div",{class:"vfit-lb",style:e.normalizeStyle({transform:e.unref(n).scale,transformOrigin:e.unref(r),bottom:e.unref(n).bottom,left:e.unref(n).left,zIndex:o.z})},[e.renderSlot(t.$slots,"default",{},void 0,true)],4))}});const m=l(d,[["__scopeId","data-v-e2439afc"]]);const y=e.defineComponent({__name:"VFitRB",props:{scale:{type:Number,default:0},bottom:{type:Number},right:{type:Number},unit:{type:String,default:"px"},z:{type:Number,default:300}},setup(t){const o=t;const{position:n,origin:r}=i(o,{origin:"100% 100%",scaleKeys:["bottom","right"]});return(t,i)=>(e.openBlock(),e.createElementBlock("div",{class:"vfit-rb",style:e.normalizeStyle({transform:e.unref(n).scale,transformOrigin:e.unref(r),bottom:e.unref(n).bottom,right:e.unref(n).right,zIndex:o.z})},[e.renderSlot(t.$slots,"default",{},void 0,true)],4))}});const g=l(y,[["__scopeId","data-v-33198615"]]);const b=e.defineComponent({__name:"VFitCenter",props:{scale:{type:Number,default:0},z:{type:Number,default:300}},setup(t){const o=t;const{position:n,origin:r}=i(o,{origin:"50% 50%",scaleKeys:[],extraTransform:"translate(-50%, -50%)"});return(t,i)=>(e.openBlock(),e.createElementBlock("div",{class:"vfit-center",style:e.normalizeStyle({transform:e.unref(n).scale,transformOrigin:e.unref(r),zIndex:o.z})},[e.renderSlot(t.$slots,"default",{},void 0,true)],4))}});const v=l(b,[["__scopeId","data-v-289ce2dd"]]);function h(t={}){const r=e.ref(1);return{install(e){const i=typeof t.target==="string"?document.querySelector(t.target):t.target;const s=i||document.querySelector("#app");o(s,t.designHeight??1080,t=>{r.value=t},t.scaleMode??"auto",t.designWidth??1920);e.provide(n,r);e.config.globalProperties.$fitScale=r;e.component("FitContainer",c);e.component("vfit-lt",u);e.component("vfit-rt",p);e.component("vfit-lb",m);e.component("vfit-rb",g);e.component("vfit-center",v)}}}t.FitContainer=c;t.VFitCenter=v;t.VFitLB=m;t.VFitLT=u;t.VFitRB=g;t.VFitRT=p;t.createFitScale=h;t.useFitScale=r;Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { App } from 'vue';
|
|
2
|
-
import { useFitScale } from './useFitScale';
|
|
3
2
|
import FitContainer from './components/FitContainer.vue';
|
|
4
3
|
import VFitLT from './components/VFitLT.vue';
|
|
5
4
|
import VFitRT from './components/VFitRT.vue';
|
|
@@ -15,4 +14,5 @@ export type FitScaleOptions = {
|
|
|
15
14
|
export declare function createFitScale(options?: FitScaleOptions): {
|
|
16
15
|
install(app: App): void;
|
|
17
16
|
};
|
|
18
|
-
export { FitContainer, VFitLT, VFitRT, VFitLB, VFitRB, VFitCenter
|
|
17
|
+
export { FitContainer, VFitLT, VFitRT, VFitLB, VFitRB, VFitCenter };
|
|
18
|
+
export { useFitScale } from './useFitScale';
|
package/dist/useFitPosition.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,16 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vfit",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "A tiny Vue 3 plugin to auto-fit UI scale based on container size, plus a FitContainer component for easy positioning.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vue3",
|
|
7
7
|
"vfit",
|
|
8
|
+
"vue-plugin",
|
|
8
9
|
"scale",
|
|
9
10
|
"responsive",
|
|
10
|
-
"container",
|
|
11
|
-
"positioning",
|
|
12
11
|
"auto-scale",
|
|
13
|
-
"
|
|
12
|
+
"screen-adaptation",
|
|
13
|
+
"scale-to-fit",
|
|
14
|
+
"responsive-scaling",
|
|
15
|
+
"fit-container",
|
|
16
|
+
"positioning",
|
|
17
|
+
"big-screen",
|
|
18
|
+
"large-screen",
|
|
19
|
+
"data-screen",
|
|
20
|
+
"data-wall",
|
|
21
|
+
"dashboard",
|
|
22
|
+
"data-visualization",
|
|
23
|
+
"可视化大屏",
|
|
24
|
+
"数据大屏",
|
|
25
|
+
"大屏可视化",
|
|
26
|
+
"大屏适配",
|
|
27
|
+
"屏幕自适应",
|
|
28
|
+
"自适应缩放",
|
|
29
|
+
"大屏组件",
|
|
30
|
+
"大屏布局",
|
|
31
|
+
"可视化适配",
|
|
32
|
+
"屏幕缩放"
|
|
14
33
|
],
|
|
15
34
|
"license": "MIT",
|
|
16
35
|
"repository": {
|