vfit 0.1.0

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.
@@ -0,0 +1,68 @@
1
+ import { defineComponent as m, reactive as p, inject as f, ref as l, watch as d, createElementBlock as g, openBlock as v, normalizeStyle as y, normalizeClass as b, renderSlot as h } from "vue";
2
+ function S(o, e, t) {
3
+ const r = new ResizeObserver((n) => {
4
+ for (const s of n) {
5
+ const a = s.contentRect.height, c = s.contentRect.width;
6
+ let i;
7
+ c / a < 1.7666666666666666 ? i = c / 1920 * 0.98 : i = a / e, t(i);
8
+ }
9
+ });
10
+ return r.observe(o), r;
11
+ }
12
+ const _ = /* @__PURE__ */ m({
13
+ __name: "FitContainer",
14
+ props: {
15
+ scale: { type: Number, default: 0 },
16
+ top: { type: Number },
17
+ bottom: { type: Number },
18
+ left: { type: Number },
19
+ right: { type: Number },
20
+ unit: { type: String, default: "px" }
21
+ },
22
+ setup(o) {
23
+ const e = p({
24
+ scale: "scale(1)",
25
+ top: "auto",
26
+ bottom: "auto",
27
+ left: "auto",
28
+ right: "auto"
29
+ }), t = o, r = f(u, l(1));
30
+ return d([() => t.scale, r], () => {
31
+ const n = t.scale && t.scale > 0 ? t.scale : (r == null ? void 0 : r.value) ?? 1;
32
+ e.scale = `scale(${n})`, ["top", "bottom", "left", "right"].forEach((a) => {
33
+ const c = t[a];
34
+ t.unit === "%" ? e[a] = c == null ? "auto" : `${c}${t.unit}` : e[a] = c == null ? "auto" : `${c * n}${t.unit}`;
35
+ });
36
+ }, { immediate: !0 }), (n, s) => (v(), g("div", {
37
+ class: b(["fit-container", { "fit-container-right": t.right !== void 0 }]),
38
+ style: y({ transform: e.scale, top: e.top, bottom: e.bottom, left: e.left, right: e.right })
39
+ }, [
40
+ h(n.$slots, "default", {}, void 0, !0)
41
+ ], 6));
42
+ }
43
+ }), F = (o, e) => {
44
+ const t = o.__vccOpts || o;
45
+ for (const [r, n] of e)
46
+ t[r] = n;
47
+ return t;
48
+ }, $ = /* @__PURE__ */ F(_, [["__scopeId", "data-v-d7520246"]]), u = Symbol("FitScale");
49
+ function N(o = {}) {
50
+ const e = l(1);
51
+ return {
52
+ install(t) {
53
+ const n = (typeof o.target == "string" ? document.querySelector(o.target) : o.target) || document.querySelector("#app");
54
+ S(n, o.designHeight ?? 1080, (s) => {
55
+ e.value = s;
56
+ }), t.provide(u, e), t.config.globalProperties.$fitScale = e, t.component("FitContainer", $);
57
+ }
58
+ };
59
+ }
60
+ function E() {
61
+ return f(u, l(1));
62
+ }
63
+ export {
64
+ $ as FitContainer,
65
+ u as FitScaleKey,
66
+ N as createFitScale,
67
+ E as useFitScale
68
+ };
@@ -0,0 +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 a of r){const l=a.contentRect.height,s=a.contentRect.width;let u;s/l<1.7666666666666666?u=s/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 s=t[l];t.unit==="%"?o[l]=s==null?"auto":`${s}${t.unit}`:o[l]=s==null?"auto":`${s*r}${t.unit}`})},{immediate:!0}),(r,a)=>(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-d7520246"]]),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,a=>{o.value=a}),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 ADDED
@@ -0,0 +1 @@
1
+ .fit-container[data-v-d7520246]{position:absolute;transform-origin:0 0;z-index:300}.fit-container-right[data-v-d7520246]{transform-origin:100% 0}
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "vfit",
3
+ "version": "0.1.0",
4
+ "description": "A tiny Vue 3 plugin to auto-fit UI scale based on container size, plus a FitContainer component for easy positioning.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "dist/fitscale.umd.js",
8
+ "module": "dist/fitscale.es.js",
9
+ "exports": {
10
+ ".": {
11
+ "types": "dist/index.d.ts",
12
+ "import": "dist/fitscale.es.js",
13
+ "require": "dist/fitscale.umd.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "scripts": {
20
+ "build": "vite build"
21
+ },
22
+ "peerDependencies": {
23
+ "vue": ">=3.3.0"
24
+ },
25
+ "devDependencies": {
26
+ "@vitejs/plugin-vue": "^5.0.4",
27
+ "typescript": "^5.6.3",
28
+ "vite": "^5.4.0"
29
+ }
30
+ }