gm-util 5.12.6 → 5.12.8
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/package.json +2 -2
- package/src/isZoom2.js +95 -55
- package/src/pinyinFilter.js +1 -1
package/package.json
CHANGED
package/src/isZoom2.js
CHANGED
|
@@ -1,85 +1,125 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 检测浏览器缩放
|
|
3
3
|
*/
|
|
4
|
-
export default function isZoom2
|
|
4
|
+
export default function isZoom2() {
|
|
5
5
|
const detectZoomFunc = {
|
|
6
|
-
ie: () => {
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
ie: () => {
|
|
7
|
+
return window.screen.deviceXDPI / window.screen.logicalXDPI;
|
|
8
|
+
},
|
|
9
|
+
firefox: () => {
|
|
10
|
+
return window.devicePixelRatio
|
|
11
|
+
? window.devicePixelRatio
|
|
12
|
+
: n("min--moz-device-pixel-ratio", "", 0, 10, 20, 1e-4);
|
|
13
|
+
},
|
|
14
|
+
opera: () => {
|
|
15
|
+
return window.outerWidth / window.innerWidth;
|
|
16
|
+
},
|
|
9
17
|
chrome: () => {
|
|
10
18
|
if (window.devicePixelRatio) {
|
|
11
|
-
return window.devicePixelRatio
|
|
19
|
+
return window.devicePixelRatio;
|
|
12
20
|
}
|
|
13
|
-
const o = window.document
|
|
14
|
-
const t = o.createElement(
|
|
15
|
-
t.innerHTML =
|
|
16
|
-
t.setAttribute(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
o.body.
|
|
21
|
-
|
|
21
|
+
const o = window.document;
|
|
22
|
+
const t = o.createElement("div");
|
|
23
|
+
t.innerHTML = "1";
|
|
24
|
+
t.setAttribute(
|
|
25
|
+
"style",
|
|
26
|
+
"font:100px/1em sans-serif-webkit-text-size-adjust:noneposition: absolutetop:-100%"
|
|
27
|
+
);
|
|
28
|
+
o.body.appendChild(t);
|
|
29
|
+
let n = 1e3 / t.clientHeight;
|
|
30
|
+
n = Math.round(100 * n) / 100;
|
|
31
|
+
o.body.removeChild(t);
|
|
32
|
+
return n;
|
|
22
33
|
},
|
|
23
|
-
safari: () => {
|
|
24
|
-
|
|
34
|
+
safari: () => {
|
|
35
|
+
return window.outerWidth / window.innerWidth;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
25
38
|
|
|
26
|
-
function round2
|
|
27
|
-
return
|
|
39
|
+
function round2(number, fractionDigits) {
|
|
40
|
+
return (
|
|
41
|
+
Math.round(number * Math.pow(10, fractionDigits)) /
|
|
42
|
+
Math.pow(10, fractionDigits)
|
|
43
|
+
);
|
|
28
44
|
}
|
|
29
45
|
|
|
30
|
-
function n
|
|
31
|
-
function l
|
|
32
|
-
const a = (e + o) / 2
|
|
33
|
-
if (i <= 0 || o - e < c) return a
|
|
34
|
-
const s =
|
|
35
|
-
return r(s).matches ? l(a, o, i - 1) : l(e, a, i - 1)
|
|
46
|
+
function n(t, n, i, a, s, c) {
|
|
47
|
+
function l(e, o, i) {
|
|
48
|
+
const a = (e + o) / 2;
|
|
49
|
+
if (i <= 0 || o - e < c) return a;
|
|
50
|
+
const s = "(" + t + ":" + a + n + ")";
|
|
51
|
+
return r(s).matches ? l(a, o, i - 1) : l(e, a, i - 1);
|
|
36
52
|
}
|
|
37
|
-
let r, d, m, p
|
|
38
|
-
let e = window;
|
|
53
|
+
let r, d, m, p;
|
|
54
|
+
let e = window;
|
|
55
|
+
let o = window.document;
|
|
39
56
|
if (e.matchMedia) {
|
|
40
|
-
r = e.matchMedia
|
|
57
|
+
r = e.matchMedia;
|
|
41
58
|
} else {
|
|
42
|
-
d = o.getElementsByTagName(
|
|
43
|
-
m = o.createElement(
|
|
44
|
-
d.appendChild(m)
|
|
45
|
-
p = o.createElement(
|
|
46
|
-
p.className =
|
|
47
|
-
p.style.display =
|
|
48
|
-
o.body.appendChild(p)
|
|
59
|
+
d = o.getElementsByTagName("head")[0];
|
|
60
|
+
m = o.createElement("style");
|
|
61
|
+
d.appendChild(m);
|
|
62
|
+
p = o.createElement("div");
|
|
63
|
+
p.className = "mediaQueryBinarySearch";
|
|
64
|
+
p.style.display = "none";
|
|
65
|
+
o.body.appendChild(p);
|
|
49
66
|
r = function (e) {
|
|
50
|
-
m.sheet.insertRule(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
67
|
+
m.sheet.insertRule(
|
|
68
|
+
"@media " +
|
|
69
|
+
e +
|
|
70
|
+
"{.mediaQueryBinarySearch {text-decoration: underline} }",
|
|
71
|
+
0
|
|
72
|
+
);
|
|
73
|
+
const t =
|
|
74
|
+
window.getComputedStyle(p, null).textDecoration === "underline";
|
|
75
|
+
m.sheet.deleteRule(0);
|
|
76
|
+
return { matches: t };
|
|
77
|
+
};
|
|
55
78
|
}
|
|
56
79
|
|
|
57
|
-
let u = l(i, a, s)
|
|
80
|
+
let u = l(i, a, s);
|
|
58
81
|
if (p) {
|
|
59
|
-
d.removeChild(m)
|
|
60
|
-
o.body.removeChild(p)
|
|
82
|
+
d.removeChild(m);
|
|
83
|
+
o.body.removeChild(p);
|
|
61
84
|
}
|
|
62
|
-
return u
|
|
85
|
+
return u;
|
|
63
86
|
}
|
|
64
87
|
|
|
65
|
-
function system
|
|
66
|
-
let ua = navigator.userAgent.toLowerCase()
|
|
67
|
-
return ua.indexOf(
|
|
88
|
+
function system() {
|
|
89
|
+
let ua = navigator.userAgent.toLowerCase();
|
|
90
|
+
return ua.indexOf("win") >= 0
|
|
91
|
+
? "win"
|
|
92
|
+
: ua.indexOf("mac") >= 0
|
|
93
|
+
? "mac"
|
|
94
|
+
: false;
|
|
68
95
|
}
|
|
69
96
|
|
|
70
|
-
function getBrowser
|
|
71
|
-
let ua = navigator.userAgent.toLowerCase()
|
|
72
|
-
return window.ActiveXObject ||
|
|
97
|
+
function getBrowser() {
|
|
98
|
+
let ua = navigator.userAgent.toLowerCase();
|
|
99
|
+
return window.ActiveXObject || "ActiveXObject" in window
|
|
100
|
+
? "ie"
|
|
101
|
+
: ua.indexOf("firefox") >= 0
|
|
102
|
+
? "firefox"
|
|
103
|
+
: ua.indexOf("chrome") >= 0
|
|
104
|
+
? "chrome"
|
|
105
|
+
: ua.indexOf("opera") >= 0
|
|
106
|
+
? "opera"
|
|
107
|
+
: ua.indexOf("safari") >= 0
|
|
108
|
+
? "safari"
|
|
109
|
+
: void 0;
|
|
73
110
|
}
|
|
74
111
|
|
|
75
|
-
function detectZoom
|
|
76
|
-
return detectZoomFunc[getBrowser()]()
|
|
112
|
+
function detectZoom() {
|
|
113
|
+
return detectZoomFunc[getBrowser() || "chrome"]();
|
|
77
114
|
}
|
|
78
115
|
|
|
79
|
-
function iszoom
|
|
80
|
-
return (
|
|
116
|
+
function iszoom(e) {
|
|
117
|
+
return (
|
|
118
|
+
(e.system === "win" && e.zoom !== 1) ||
|
|
119
|
+
(e.system === "mac" && e.zoom % 1 !== 0 && e.zoom % 2 !== 0)
|
|
120
|
+
);
|
|
81
121
|
}
|
|
82
122
|
|
|
83
|
-
const zoomData = { zoom: round2(detectZoom(), 2), system: system() }
|
|
84
|
-
return iszoom(zoomData)
|
|
123
|
+
const zoomData = { zoom: round2(detectZoom(), 2), system: system() };
|
|
124
|
+
return iszoom(zoomData);
|
|
85
125
|
}
|