vfit 0.1.0 → 0.1.1
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 +32 -0
- package/dist/fitscale.es.js +20 -20
- package/dist/fitscale.umd.js +1 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# vfit
|
|
2
|
+
|
|
3
|
+
A tiny Vue 3 plugin and component to auto-fit UI scale based on container size.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
npm i vfit
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Use
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { createFitScale } from 'vfit'
|
|
15
|
+
app.use(createFitScale({ target: '#app', designHeight: 1080 }))
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Component
|
|
19
|
+
|
|
20
|
+
```vue
|
|
21
|
+
<template>
|
|
22
|
+
<FitContainer :top="50" :left="50" :unit="'%'">
|
|
23
|
+
<!-- content -->
|
|
24
|
+
</FitContainer>
|
|
25
|
+
</template>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## API
|
|
29
|
+
|
|
30
|
+
- createFitScale(options)
|
|
31
|
+
- useFitScale()
|
|
32
|
+
- FitContainer
|
package/dist/fitscale.es.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { defineComponent as m, reactive as p, inject as f, ref as l, watch as d, createElementBlock as g, openBlock as
|
|
1
|
+
import { defineComponent as m, reactive as p, inject as f, ref as l, watch as d, createElementBlock as g, openBlock as b, normalizeStyle as v, normalizeClass as y, renderSlot as h } from "vue";
|
|
2
2
|
function S(o, e, t) {
|
|
3
|
-
const r = new ResizeObserver((
|
|
4
|
-
for (const
|
|
5
|
-
const
|
|
6
|
-
let
|
|
7
|
-
|
|
3
|
+
const r = new ResizeObserver((c) => {
|
|
4
|
+
for (const a of c) {
|
|
5
|
+
const i = a.contentRect.height, n = a.contentRect.width;
|
|
6
|
+
let s;
|
|
7
|
+
n / i < 1.7666666666666666 ? s = n / 1920 * 0.98 : s = i / e, t(s);
|
|
8
8
|
}
|
|
9
9
|
});
|
|
10
10
|
return r.observe(o), r;
|
|
@@ -28,31 +28,31 @@ const _ = /* @__PURE__ */ m({
|
|
|
28
28
|
right: "auto"
|
|
29
29
|
}), t = o, r = f(u, l(1));
|
|
30
30
|
return d([() => t.scale, r], () => {
|
|
31
|
-
const
|
|
32
|
-
e.scale = `scale(${
|
|
33
|
-
const
|
|
34
|
-
t.unit === "%" ? e[
|
|
31
|
+
const c = t.scale && t.scale > 0 ? t.scale : (r == null ? void 0 : r.value) ?? 1;
|
|
32
|
+
e.scale = `scale(${c})`, ["top", "bottom", "left", "right"].forEach((i) => {
|
|
33
|
+
const n = t[i];
|
|
34
|
+
t.unit === "%" ? e[i] = n == null ? "auto" : `${n}${t.unit}` : e[i] = n == null ? "auto" : `${n * c}${t.unit}`;
|
|
35
35
|
});
|
|
36
|
-
}, { immediate: !0 }), (
|
|
37
|
-
class:
|
|
38
|
-
style:
|
|
36
|
+
}, { immediate: !0 }), (c, a) => (b(), g("div", {
|
|
37
|
+
class: y(["fit-container", { "fit-container-right": t.right !== void 0 }]),
|
|
38
|
+
style: v({ transform: e.scale, top: e.top, bottom: e.bottom, left: e.left, right: e.right })
|
|
39
39
|
}, [
|
|
40
|
-
h(
|
|
40
|
+
h(c.$slots, "default", {}, void 0, !0)
|
|
41
41
|
], 6));
|
|
42
42
|
}
|
|
43
43
|
}), F = (o, e) => {
|
|
44
44
|
const t = o.__vccOpts || o;
|
|
45
|
-
for (const [r,
|
|
46
|
-
t[r] =
|
|
45
|
+
for (const [r, c] of e)
|
|
46
|
+
t[r] = c;
|
|
47
47
|
return t;
|
|
48
|
-
}, $ = /* @__PURE__ */ F(_, [["__scopeId", "data-v-
|
|
48
|
+
}, $ = /* @__PURE__ */ F(_, [["__scopeId", "data-v-1ab0024a"]]), u = Symbol("FitScale");
|
|
49
49
|
function N(o = {}) {
|
|
50
50
|
const e = l(1);
|
|
51
51
|
return {
|
|
52
52
|
install(t) {
|
|
53
|
-
const
|
|
54
|
-
S(
|
|
55
|
-
e.value =
|
|
53
|
+
const c = (typeof o.target == "string" ? document.querySelector(o.target) : o.target) || document.querySelector("#app");
|
|
54
|
+
S(c, o.designHeight ?? 1080, (a) => {
|
|
55
|
+
e.value = a;
|
|
56
56
|
}), t.provide(u, e), t.config.globalProperties.$fitScale = e, t.component("FitContainer", $);
|
|
57
57
|
}
|
|
58
58
|
};
|
package/dist/fitscale.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(c,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(c=typeof globalThis<"u"?globalThis:c||self,e(c.FitScale={},c.Vue))})(this,function(c,e){"use strict";function m(n,o,t){const i=new ResizeObserver(r=>{for(const
|
|
1
|
+
(function(c,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(c=typeof globalThis<"u"?globalThis:c||self,e(c.FitScale={},c.Vue))})(this,function(c,e){"use strict";function m(n,o,t){const i=new ResizeObserver(r=>{for(const s of r){const l=s.contentRect.height,a=s.contentRect.width;let u;a/l<1.7666666666666666?u=a/1920*.98:u=l/o,t(u)}});return i.observe(n),i}const d=((n,o)=>{const t=n.__vccOpts||n;for(const[i,r]of o)t[i]=r;return t})(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"}},setup(n){const o=e.reactive({scale:"scale(1)",top:"auto",bottom:"auto",left:"auto",right:"auto"}),t=n,i=e.inject(f,e.ref(1));return e.watch([()=>t.scale,i],()=>{const r=t.scale&&t.scale>0?t.scale:(i==null?void 0:i.value)??1;o.scale=`scale(${r})`,["top","bottom","left","right"].forEach(l=>{const a=t[l];t.unit==="%"?o[l]=a==null?"auto":`${a}${t.unit}`:o[l]=a==null?"auto":`${a*r}${t.unit}`})},{immediate:!0}),(r,s)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["fit-container",{"fit-container-right":t.right!==void 0}]),style:e.normalizeStyle({transform:o.scale,top:o.top,bottom:o.bottom,left:o.left,right:o.right})},[e.renderSlot(r.$slots,"default",{},void 0,!0)],6))}}),[["__scopeId","data-v-1ab0024a"]]),f=Symbol("FitScale");function p(n={}){const o=e.ref(1);return{install(t){const r=(typeof n.target=="string"?document.querySelector(n.target):n.target)||document.querySelector("#app");m(r,n.designHeight??1080,s=>{o.value=s}),t.provide(f,o),t.config.globalProperties.$fitScale=o,t.component("FitContainer",d)}}}function y(){return e.inject(f,e.ref(1))}c.FitContainer=d,c.FitScaleKey=f,c.createFitScale=p,c.useFitScale=y,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.fit-container[data-v-
|
|
1
|
+
.fit-container[data-v-1ab0024a]{position:absolute;transform-origin:0 0;z-index:300}.fit-container-right[data-v-1ab0024a]{transform-origin:100% 0}
|
package/package.json
CHANGED