color-star-custom-methods 0.0.2 → 0.0.3
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/es/index.mjs +23 -25
- package/lib/index.js +2 -2
- package/package.json +1 -1
package/es/index.mjs
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { ref as y, computed as
|
|
2
|
-
const E = (
|
|
3
|
-
const
|
|
4
|
-
return c >=
|
|
5
|
-
}, L = (
|
|
6
|
-
const { minScale:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { ref as y, computed as w, onMounted as f, onUnmounted as h } from "vue";
|
|
2
|
+
const i = 1, E = (d = 0.9) => {
|
|
3
|
+
const t = window.innerWidth, a = window.innerHeight, s = t === 1920, r = s ? i : t / 1920, n = s ? i : a / 1080, u = Math.min(r, n), c = Math.max(d, u);
|
|
4
|
+
return c >= i ? i : c;
|
|
5
|
+
}, L = (d = {}) => {
|
|
6
|
+
const { minScale: m = 0.9, enableZoomPrevention: l = !1 } = d, t = y(i), a = () => {
|
|
7
|
+
t.value = E(m), document.documentElement.style.setProperty(
|
|
8
|
+
"--app-scale",
|
|
9
|
+
t.value.toString()
|
|
10
|
+
);
|
|
11
|
+
}, s = (e) => {
|
|
10
12
|
if ((e.ctrlKey || e.metaKey) && (e.key === "+" || e.key === "-" || e.key === "=" || e.key === "0")) {
|
|
11
13
|
e.preventDefault();
|
|
12
14
|
return;
|
|
@@ -15,30 +17,26 @@ const E = (l = 0.9) => {
|
|
|
15
17
|
e.preventDefault();
|
|
16
18
|
return;
|
|
17
19
|
}
|
|
18
|
-
},
|
|
20
|
+
}, r = (e) => {
|
|
19
21
|
e.touches && e.touches.length > 1 && e.preventDefault();
|
|
20
22
|
}, n = (e) => {
|
|
21
23
|
e.preventDefault();
|
|
22
|
-
},
|
|
23
|
-
const e = t.value !==
|
|
24
|
+
}, u = w(() => {
|
|
25
|
+
const e = t.value !== i;
|
|
24
26
|
return {
|
|
25
27
|
transform: `scale(${t.value})`,
|
|
26
28
|
transformOrigin: "top left",
|
|
29
|
+
position: e ? "fixed" : "relative",
|
|
27
30
|
...e && {
|
|
28
|
-
position: "fixed",
|
|
29
31
|
top: "0",
|
|
30
32
|
left: "0",
|
|
31
33
|
width: `calc(100% / ${t.value})`,
|
|
32
34
|
height: `calc(100% / ${t.value})`
|
|
33
35
|
}
|
|
34
36
|
};
|
|
35
|
-
}),
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"app-container": e,
|
|
39
|
-
relative: !e
|
|
40
|
-
};
|
|
41
|
-
}), p = () => {
|
|
37
|
+
}), c = w(() => ({
|
|
38
|
+
"app-container": t.value !== i
|
|
39
|
+
})), p = () => {
|
|
42
40
|
if (typeof document > "u") return;
|
|
43
41
|
const e = "page-zoom-controller-styles";
|
|
44
42
|
let o = document.getElementById(e);
|
|
@@ -56,9 +54,9 @@ const E = (l = 0.9) => {
|
|
|
56
54
|
o && o.remove();
|
|
57
55
|
};
|
|
58
56
|
return f(() => {
|
|
59
|
-
|
|
57
|
+
a(), p(), window.addEventListener("resize", a), l && (window.addEventListener("wheel", s, { passive: !1 }), window.addEventListener("keydown", s), window.addEventListener("touchstart", r, {
|
|
60
58
|
passive: !1
|
|
61
|
-
}), window.addEventListener("touchmove",
|
|
59
|
+
}), window.addEventListener("touchmove", r, { passive: !1 }), window.addEventListener("gesturestart", n, {
|
|
62
60
|
passive: !1
|
|
63
61
|
}), window.addEventListener("gesturechange", n, {
|
|
64
62
|
passive: !1
|
|
@@ -66,10 +64,10 @@ const E = (l = 0.9) => {
|
|
|
66
64
|
passive: !1
|
|
67
65
|
}), document.body.style.touchAction = "none");
|
|
68
66
|
}), h(() => {
|
|
69
|
-
window.removeEventListener("resize",
|
|
67
|
+
window.removeEventListener("resize", a), v(), l && (window.removeEventListener("wheel", s), window.removeEventListener("keydown", s), window.removeEventListener("touchstart", r), window.removeEventListener("touchmove", r), window.removeEventListener("gesturestart", n), window.removeEventListener("gesturechange", n), window.removeEventListener("gestureend", n), document.body.style.touchAction === "none" && (document.body.style.touchAction = ""));
|
|
70
68
|
}), {
|
|
71
|
-
containerStyles:
|
|
72
|
-
containerClasses:
|
|
69
|
+
containerStyles: u,
|
|
70
|
+
containerClasses: c
|
|
73
71
|
};
|
|
74
72
|
};
|
|
75
73
|
export {
|
package/lib/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("vue"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("vue"),i=1,v=(d=.9)=>{const t=window.innerWidth,a=window.innerHeight,s=t===1920,r=s?i:t/1920,n=s?i:a/1080,m=Math.min(r,n),l=Math.max(d,m);return l>=i?i:l},f=(d={})=>{const{minScale:w=.9,enableZoomPrevention:u=!1}=d,t=c.ref(i),a=()=>{t.value=v(w),document.documentElement.style.setProperty("--app-scale",t.value.toString())},s=e=>{if((e.ctrlKey||e.metaKey)&&(e.key==="+"||e.key==="-"||e.key==="="||e.key==="0")){e.preventDefault();return}if(e.ctrlKey&&e.type==="wheel"){e.preventDefault();return}},r=e=>{e.touches&&e.touches.length>1&&e.preventDefault()},n=e=>{e.preventDefault()},m=c.computed(()=>{const e=t.value!==i;return{transform:`scale(${t.value})`,transformOrigin:"top left",position:e?"fixed":"relative",...e&&{top:"0",left:"0",width:`calc(100% / ${t.value})`,height:`calc(100% / ${t.value})`}}}),l=c.computed(()=>({"app-container":t.value!==i})),p=()=>{if(typeof document>"u")return;const e="page-zoom-controller-styles";let o=document.getElementById(e);o||(o=document.createElement("style"),o.id=e,o.textContent=`
|
|
2
2
|
.app-container * {
|
|
3
3
|
/* 优化字体渲染,防止缩放时字体模糊 */
|
|
4
4
|
-webkit-font-smoothing: antialiased !important;
|
|
5
5
|
-moz-osx-font-smoothing: grayscale !important;
|
|
6
6
|
text-rendering: optimizeLegibility !important;
|
|
7
7
|
}
|
|
8
|
-
`,document.head.appendChild(o))},y=()=>{if(typeof document>"u")return;const o=document.getElementById("page-zoom-controller-styles");o&&o.remove()};return c.onMounted(()=>{
|
|
8
|
+
`,document.head.appendChild(o))},y=()=>{if(typeof document>"u")return;const o=document.getElementById("page-zoom-controller-styles");o&&o.remove()};return c.onMounted(()=>{a(),p(),window.addEventListener("resize",a),u&&(window.addEventListener("wheel",s,{passive:!1}),window.addEventListener("keydown",s),window.addEventListener("touchstart",r,{passive:!1}),window.addEventListener("touchmove",r,{passive:!1}),window.addEventListener("gesturestart",n,{passive:!1}),window.addEventListener("gesturechange",n,{passive:!1}),window.addEventListener("gestureend",n,{passive:!1}),document.body.style.touchAction="none")}),c.onUnmounted(()=>{window.removeEventListener("resize",a),y(),u&&(window.removeEventListener("wheel",s),window.removeEventListener("keydown",s),window.removeEventListener("touchstart",r),window.removeEventListener("touchmove",r),window.removeEventListener("gesturestart",n),window.removeEventListener("gesturechange",n),window.removeEventListener("gestureend",n),document.body.style.touchAction==="none"&&(document.body.style.touchAction=""))}),{containerStyles:m,containerClasses:l}};exports.calculateScale=v;exports.usePageZoomController=f;
|