vfit 2.0.3 → 2.0.4
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 +1 -1
- package/dist/fitscale.es.js +25 -15
- package/dist/fitscale.umd.js +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/style.css +1 -1
- package/dist/useFitPosition.d.ts +11 -9
- package/package.json +2 -3
package/README.md
CHANGED
package/dist/fitscale.es.js
CHANGED
|
@@ -64,7 +64,7 @@ function useFitPosition(props, options = {}) {
|
|
|
64
64
|
if (props.unit === "%") {
|
|
65
65
|
position[key] = val == void 0 ? "auto" : `${val}${props.unit}`;
|
|
66
66
|
} else {
|
|
67
|
-
const needScale = options.scaleKeys ? options.scaleKeys.includes(key) :
|
|
67
|
+
const needScale = options.scaleKeys ? options.scaleKeys.includes(key) : true;
|
|
68
68
|
position[key] = val == void 0 ? "auto" : `${needScale ? val * s : val}${props.unit}`;
|
|
69
69
|
}
|
|
70
70
|
});
|
|
@@ -74,6 +74,7 @@ function useFitPosition(props, options = {}) {
|
|
|
74
74
|
const _sfc_main$5 = /* @__PURE__ */ defineComponent({
|
|
75
75
|
__name: "FitContainer",
|
|
76
76
|
props: {
|
|
77
|
+
/* 自定义缩放因子,传 0 或不传时使用全局 fitScale */
|
|
77
78
|
scale: { type: Number, default: 0 },
|
|
78
79
|
top: { type: Number },
|
|
79
80
|
bottom: { type: Number },
|
|
@@ -87,7 +88,7 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
|
|
|
87
88
|
const { position, origin } = useFitPosition(props);
|
|
88
89
|
return (_ctx, _cache) => {
|
|
89
90
|
return openBlock(), createElementBlock("div", {
|
|
90
|
-
class: "fit-container",
|
|
91
|
+
class: "vfit-base fit-container",
|
|
91
92
|
style: normalizeStyle({ transform: unref(position).scale, transformOrigin: unref(origin), top: unref(position).top, bottom: unref(position).bottom, left: unref(position).left, right: unref(position).right, zIndex: props.z })
|
|
92
93
|
}, [
|
|
93
94
|
renderSlot(_ctx.$slots, "default", {}, void 0, true)
|
|
@@ -102,10 +103,11 @@ const _export_sfc = (sfc, props) => {
|
|
|
102
103
|
}
|
|
103
104
|
return target;
|
|
104
105
|
};
|
|
105
|
-
const FitContainer = /* @__PURE__ */ _export_sfc(_sfc_main$5, [["__scopeId", "data-v-
|
|
106
|
+
const FitContainer = /* @__PURE__ */ _export_sfc(_sfc_main$5, [["__scopeId", "data-v-351214cb"]]);
|
|
106
107
|
const _sfc_main$4 = /* @__PURE__ */ defineComponent({
|
|
107
108
|
__name: "VFitLT",
|
|
108
109
|
props: {
|
|
110
|
+
/* 自定义缩放因子,传 0 或不传时使用全局 fitScale */
|
|
109
111
|
scale: { type: Number, default: 0 },
|
|
110
112
|
top: { type: Number },
|
|
111
113
|
left: { type: Number },
|
|
@@ -117,7 +119,7 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
|
|
|
117
119
|
const { position, origin } = useFitPosition(props);
|
|
118
120
|
return (_ctx, _cache) => {
|
|
119
121
|
return openBlock(), createElementBlock("div", {
|
|
120
|
-
class: "vfit-lt",
|
|
122
|
+
class: "vfit-base vfit-lt",
|
|
121
123
|
style: normalizeStyle({ transform: unref(position).scale, transformOrigin: unref(origin), top: unref(position).top, left: unref(position).left, zIndex: props.z })
|
|
122
124
|
}, [
|
|
123
125
|
renderSlot(_ctx.$slots, "default", {}, void 0, true)
|
|
@@ -125,10 +127,11 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
|
|
|
125
127
|
};
|
|
126
128
|
}
|
|
127
129
|
});
|
|
128
|
-
const VFitLT = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["__scopeId", "data-v-
|
|
130
|
+
const VFitLT = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["__scopeId", "data-v-a7aa2e99"]]);
|
|
129
131
|
const _sfc_main$3 = /* @__PURE__ */ defineComponent({
|
|
130
132
|
__name: "VFitRT",
|
|
131
133
|
props: {
|
|
134
|
+
/* 自定义缩放因子,传 0 或不传时使用全局 fitScale */
|
|
132
135
|
scale: { type: Number, default: 0 },
|
|
133
136
|
top: { type: Number },
|
|
134
137
|
right: { type: Number },
|
|
@@ -143,7 +146,7 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
|
|
|
143
146
|
});
|
|
144
147
|
return (_ctx, _cache) => {
|
|
145
148
|
return openBlock(), createElementBlock("div", {
|
|
146
|
-
class: "vfit-rt",
|
|
149
|
+
class: "vfit-base vfit-rt",
|
|
147
150
|
style: normalizeStyle({ transform: unref(position).scale, transformOrigin: unref(origin), top: unref(position).top, right: unref(position).right, zIndex: props.z })
|
|
148
151
|
}, [
|
|
149
152
|
renderSlot(_ctx.$slots, "default", {}, void 0, true)
|
|
@@ -151,10 +154,11 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
|
|
|
151
154
|
};
|
|
152
155
|
}
|
|
153
156
|
});
|
|
154
|
-
const VFitRT = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["__scopeId", "data-v-
|
|
157
|
+
const VFitRT = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["__scopeId", "data-v-66feb296"]]);
|
|
155
158
|
const _sfc_main$2 = /* @__PURE__ */ defineComponent({
|
|
156
159
|
__name: "VFitLB",
|
|
157
160
|
props: {
|
|
161
|
+
/* 自定义缩放因子,传 0 或不传时使用全局 fitScale */
|
|
158
162
|
scale: { type: Number, default: 0 },
|
|
159
163
|
bottom: { type: Number },
|
|
160
164
|
left: { type: Number },
|
|
@@ -169,7 +173,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
|
|
|
169
173
|
});
|
|
170
174
|
return (_ctx, _cache) => {
|
|
171
175
|
return openBlock(), createElementBlock("div", {
|
|
172
|
-
class: "vfit-lb",
|
|
176
|
+
class: "vfit-base vfit-lb",
|
|
173
177
|
style: normalizeStyle({ transform: unref(position).scale, transformOrigin: unref(origin), bottom: unref(position).bottom, left: unref(position).left, zIndex: props.z })
|
|
174
178
|
}, [
|
|
175
179
|
renderSlot(_ctx.$slots, "default", {}, void 0, true)
|
|
@@ -177,10 +181,11 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
|
|
|
177
181
|
};
|
|
178
182
|
}
|
|
179
183
|
});
|
|
180
|
-
const VFitLB = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-
|
|
184
|
+
const VFitLB = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-812fdad7"]]);
|
|
181
185
|
const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
182
186
|
__name: "VFitRB",
|
|
183
187
|
props: {
|
|
188
|
+
/* 自定义缩放因子,传 0 或不传时使用全局 fitScale */
|
|
184
189
|
scale: { type: Number, default: 0 },
|
|
185
190
|
bottom: { type: Number },
|
|
186
191
|
right: { type: Number },
|
|
@@ -195,7 +200,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
195
200
|
});
|
|
196
201
|
return (_ctx, _cache) => {
|
|
197
202
|
return openBlock(), createElementBlock("div", {
|
|
198
|
-
class: "vfit-rb",
|
|
203
|
+
class: "vfit-base vfit-rb",
|
|
199
204
|
style: normalizeStyle({ transform: unref(position).scale, transformOrigin: unref(origin), bottom: unref(position).bottom, right: unref(position).right, zIndex: props.z })
|
|
200
205
|
}, [
|
|
201
206
|
renderSlot(_ctx.$slots, "default", {}, void 0, true)
|
|
@@ -203,24 +208,25 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
203
208
|
};
|
|
204
209
|
}
|
|
205
210
|
});
|
|
206
|
-
const VFitRB = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-
|
|
211
|
+
const VFitRB = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-c76864af"]]);
|
|
207
212
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
208
213
|
__name: "VFitCenter",
|
|
209
214
|
props: {
|
|
215
|
+
/* 自定义缩放因子,传 0 或不传时使用全局 fitScale */
|
|
210
216
|
scale: { type: Number, default: 0 },
|
|
211
217
|
z: { type: Number, default: 300 }
|
|
212
218
|
},
|
|
213
219
|
setup(__props) {
|
|
214
220
|
const props = __props;
|
|
215
221
|
const { position, origin } = useFitPosition(props, {
|
|
216
|
-
origin: "
|
|
222
|
+
origin: "0 0",
|
|
217
223
|
scaleKeys: [],
|
|
218
224
|
// No positioning props to scale
|
|
219
225
|
extraTransform: "translate(-50%, -50%)"
|
|
220
226
|
});
|
|
221
227
|
return (_ctx, _cache) => {
|
|
222
228
|
return openBlock(), createElementBlock("div", {
|
|
223
|
-
class: "vfit-center",
|
|
229
|
+
class: "vfit-base vfit-center",
|
|
224
230
|
style: normalizeStyle({ transform: unref(position).scale, transformOrigin: unref(origin), zIndex: props.z })
|
|
225
231
|
}, [
|
|
226
232
|
renderSlot(_ctx.$slots, "default", {}, void 0, true)
|
|
@@ -228,13 +234,17 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
228
234
|
};
|
|
229
235
|
}
|
|
230
236
|
});
|
|
231
|
-
const VFitCenter = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-
|
|
237
|
+
const VFitCenter = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-646ac2da"]]);
|
|
232
238
|
function createFitScale(options = {}) {
|
|
233
239
|
const fitScale = ref(1);
|
|
234
240
|
return {
|
|
235
241
|
install(app) {
|
|
236
|
-
const rootEl = typeof options.target === "string" ? document.querySelector(options.target) : options.target;
|
|
242
|
+
const rootEl = typeof options.target === "string" ? document.querySelector(options.target) : options.target ?? null;
|
|
237
243
|
const target = rootEl || document.querySelector("#app");
|
|
244
|
+
if (!target) {
|
|
245
|
+
console.warn("[vfit] Target element not found, scale observer not started.");
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
238
248
|
observeScale(target, options.designHeight ?? 1080, (v) => {
|
|
239
249
|
fitScale.value = v;
|
|
240
250
|
}, options.scaleMode ?? "auto", options.designWidth ?? 1920);
|
package/dist/fitscale.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).FitScale={},e.Vue)}(this,function(e,t){"use strict";const o=Symbol("FitScale");function n(e,n={}){const r=t.reactive({scale:"scale(1) translateZ(0)",top:"auto",bottom:"auto",left:"auto",right:"auto"}),i=t.computed(()=>{if(n.origin)return n.origin;const t=void 0!==e.right,o=void 0!==e.bottom;return t&&o?"100% 100%":t?"100% 0":o?"0 100%":"0 0"}),a=t.inject(o,t.ref(1));return t.watch([()=>e.scale,()=>e.unit,()=>e.top,()=>e.bottom,()=>e.left,()=>e.right,a],()=>{const t=e.scale&&e.scale>0?e.scale:(null==a?void 0:a.value)??1,o=`scale(${t}) translateZ(0)`;r.scale=n.extraTransform?`${o} ${n.extraTransform}`:o;["top","bottom","left","right"].forEach(o=>{const i=e[o];if("%"===e.unit)r[o]=null==i?"auto":`${i}${e.unit}`;else{const a=!n.scaleKeys||n.scaleKeys.includes(o);r[o]=null==i?"auto":`${a?i*t:i}${e.unit}`}})},{immediate:!0}),{position:r,origin:i}}const r=(e,t)=>{const o=e.__vccOpts||e;for(const[n,r]of t)o[n]=r;return o},i=r(t.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(e){const o=e,{position:r,origin:i}=n(o);return(e,n)=>(t.openBlock(),t.createElementBlock("div",{class:"vfit-base fit-container",style:t.normalizeStyle({transform:t.unref(r).scale,transformOrigin:t.unref(i),top:t.unref(r).top,bottom:t.unref(r).bottom,left:t.unref(r).left,right:t.unref(r).right,zIndex:o.z})},[t.renderSlot(e.$slots,"default",{},void 0,!0)],4))}}),[["__scopeId","data-v-351214cb"]]),a=r(t.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(e){const o=e,{position:r,origin:i}=n(o);return(e,n)=>(t.openBlock(),t.createElementBlock("div",{class:"vfit-base vfit-lt",style:t.normalizeStyle({transform:t.unref(r).scale,transformOrigin:t.unref(i),top:t.unref(r).top,left:t.unref(r).left,zIndex:o.z})},[t.renderSlot(e.$slots,"default",{},void 0,!0)],4))}}),[["__scopeId","data-v-a7aa2e99"]]),l=r(t.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(e){const o=e,{position:r,origin:i}=n(o,{origin:"100% 0",scaleKeys:["top","right"]});return(e,n)=>(t.openBlock(),t.createElementBlock("div",{class:"vfit-base vfit-rt",style:t.normalizeStyle({transform:t.unref(r).scale,transformOrigin:t.unref(i),top:t.unref(r).top,right:t.unref(r).right,zIndex:o.z})},[t.renderSlot(e.$slots,"default",{},void 0,!0)],4))}}),[["__scopeId","data-v-66feb296"]]),s=r(t.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(e){const o=e,{position:r,origin:i}=n(o,{origin:"0 100%",scaleKeys:["bottom","left"]});return(e,n)=>(t.openBlock(),t.createElementBlock("div",{class:"vfit-base vfit-lb",style:t.normalizeStyle({transform:t.unref(r).scale,transformOrigin:t.unref(i),bottom:t.unref(r).bottom,left:t.unref(r).left,zIndex:o.z})},[t.renderSlot(e.$slots,"default",{},void 0,!0)],4))}}),[["__scopeId","data-v-812fdad7"]]),u=r(t.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(e){const o=e,{position:r,origin:i}=n(o,{origin:"100% 100%",scaleKeys:["bottom","right"]});return(e,n)=>(t.openBlock(),t.createElementBlock("div",{class:"vfit-base vfit-rb",style:t.normalizeStyle({transform:t.unref(r).scale,transformOrigin:t.unref(i),bottom:t.unref(r).bottom,right:t.unref(r).right,zIndex:o.z})},[t.renderSlot(e.$slots,"default",{},void 0,!0)],4))}}),[["__scopeId","data-v-c76864af"]]),f=r(t.defineComponent({__name:"VFitCenter",props:{scale:{type:Number,default:0},z:{type:Number,default:300}},setup(e){const o=e,{position:r,origin:i}=n(o,{origin:"0 0",scaleKeys:[],extraTransform:"translate(-50%, -50%)"});return(e,n)=>(t.openBlock(),t.createElementBlock("div",{class:"vfit-base vfit-center",style:t.normalizeStyle({transform:t.unref(r).scale,transformOrigin:t.unref(i),zIndex:o.z})},[t.renderSlot(e.$slots,"default",{},void 0,!0)],4))}}),[["__scopeId","data-v-646ac2da"]]);e.FitContainer=i,e.VFitCenter=f,e.VFitLB=s,e.VFitLT=a,e.VFitRB=u,e.VFitRT=l,e.createFitScale=function(e={}){const n=t.ref(1);return{install(t){const r=("string"==typeof e.target?document.querySelector(e.target):e.target??null)||document.querySelector("#app");r?(!function(e,t,o,n="auto",r=1920){const i=new ResizeObserver(e=>{for(const i of e){const e=i.contentRect.height,a=i.contentRect.width;let l;l="height"===n?e/t:"width"===n||a/e<r/t?a/r:e/t,o(l)}});i.observe(e)}(r,e.designHeight??1080,e=>{n.value=e},e.scaleMode??"auto",e.designWidth??1920),t.provide(o,n),t.config.globalProperties.$fitScale=n,t.component("FitContainer",i),t.component("vfit-lt",a),t.component("vfit-rt",l),t.component("vfit-lb",s),t.component("vfit-rb",u),t.component("vfit-center",f)):console.warn("[vfit] Target element not found, scale observer not started.")}}},e.useFitScale=function(){return t.inject(o,t.ref(1))},Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import VFitRT from './components/VFitRT.vue';
|
|
|
5
5
|
import VFitLB from './components/VFitLB.vue';
|
|
6
6
|
import VFitRB from './components/VFitRB.vue';
|
|
7
7
|
import VFitCenter from './components/VFitCenter.vue';
|
|
8
|
+
import './style.css';
|
|
8
9
|
export type FitScaleOptions = {
|
|
9
10
|
target?: string | HTMLElement;
|
|
10
11
|
designHeight?: number;
|
|
@@ -16,3 +17,4 @@ export declare function createFitScale(options?: FitScaleOptions): {
|
|
|
16
17
|
};
|
|
17
18
|
export { FitContainer, VFitLT, VFitRT, VFitLB, VFitRB, VFitCenter };
|
|
18
19
|
export { useFitScale } from './useFitScale';
|
|
20
|
+
export type { FitPositionProps } from './useFitPosition';
|
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.fit-container[data-v-
|
|
1
|
+
.fit-container[data-v-351214cb],.vfit-lt[data-v-a7aa2e99]{transform-origin:0 0}.vfit-rt[data-v-66feb296]{transform-origin:100% 0}.vfit-lb[data-v-812fdad7]{transform-origin:0 100%}.vfit-rb[data-v-c76864af]{transform-origin:100% 100%}.vfit-center[data-v-646ac2da]{top:50%;left:50%;transform-origin:0 0}.vfit-base{position:absolute;will-change:transform;backface-visibility:hidden;perspective:1000px}
|
package/dist/useFitPosition.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
export
|
|
1
|
+
export interface FitPositionProps {
|
|
2
|
+
scale?: number;
|
|
3
|
+
top?: number;
|
|
4
|
+
bottom?: number;
|
|
5
|
+
left?: number;
|
|
6
|
+
right?: number;
|
|
7
|
+
unit?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function useFitPosition(props: FitPositionProps, options?: {
|
|
2
10
|
origin?: string;
|
|
3
|
-
scaleKeys?:
|
|
11
|
+
scaleKeys?: Array<'top' | 'bottom' | 'left' | 'right'>;
|
|
4
12
|
extraTransform?: string;
|
|
5
13
|
}): {
|
|
6
|
-
position:
|
|
7
|
-
scale: string;
|
|
8
|
-
top: string;
|
|
9
|
-
bottom: string;
|
|
10
|
-
left: string;
|
|
11
|
-
right: string;
|
|
12
|
-
};
|
|
14
|
+
position: Record<"top" | "bottom" | "left" | "right" | "scale", string>;
|
|
13
15
|
origin: import("vue").ComputedRef<string>;
|
|
14
16
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vfit",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
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",
|
|
@@ -48,8 +48,7 @@
|
|
|
48
48
|
"types": "./dist/index.d.ts",
|
|
49
49
|
"import": "./dist/fitscale.es.js",
|
|
50
50
|
"require": "./dist/fitscale.umd.js"
|
|
51
|
-
}
|
|
52
|
-
"./style.css": "./dist/style.css"
|
|
51
|
+
}
|
|
53
52
|
},
|
|
54
53
|
"files": [
|
|
55
54
|
"dist",
|