gm-util 5.12.2 → 5.12.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/package.json +4 -4
- package/src/index.js +6 -2
- package/src/isZoom.js +1 -0
- package/src/isZoom2.js +85 -0
- package/src/warn.js +24 -0
- package/logs/gmfe.log +0 -31
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gm-util",
|
|
3
|
-
"version": "5.12.
|
|
3
|
+
"version": "5.12.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
-
"precommit": "eslint ./src/",
|
|
8
|
+
"precommit": "eslint --fix ./src/",
|
|
9
9
|
"publishpatch": "git add --all; git commit -m 'c'; npm version patch; git push origin HEAD:master; npm publish --registry='https://registry.npmjs.org'; cnpm sync gm-util; npm version;"
|
|
10
10
|
},
|
|
11
11
|
"repository": {
|
|
@@ -35,12 +35,12 @@
|
|
|
35
35
|
"husky": "^0.14.3",
|
|
36
36
|
"lodash": "^4.17.10",
|
|
37
37
|
"query-string": "^6.1.0",
|
|
38
|
-
"react": "^16.
|
|
38
|
+
"react": "^16.12.0"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"big.js": "^5.1.2",
|
|
42
42
|
"lodash": "^4.17.10",
|
|
43
43
|
"query-string": "^6.1.0",
|
|
44
|
-
"react": "^16.
|
|
44
|
+
"react": "^16.12.0"
|
|
45
45
|
}
|
|
46
46
|
}
|
package/src/index.js
CHANGED
|
@@ -36,6 +36,8 @@ import to from './to'
|
|
|
36
36
|
import formatNumber from './formatNumber'
|
|
37
37
|
import { getLocale, setLocale } from '../locales'
|
|
38
38
|
import isZoom from './isZoom'
|
|
39
|
+
import isZoom2 from './isZoom2'
|
|
40
|
+
import { devWarnForHook, devWarn, warn } from './warn'
|
|
39
41
|
|
|
40
42
|
export {
|
|
41
43
|
/* will deprecated */
|
|
@@ -59,7 +61,7 @@ export {
|
|
|
59
61
|
isElementOverViewport,
|
|
60
62
|
getElementPosition,
|
|
61
63
|
isZoom,
|
|
62
|
-
|
|
64
|
+
isZoom2,
|
|
63
65
|
isPathMatch,
|
|
64
66
|
setTitle, setIco,
|
|
65
67
|
getScrollTop,
|
|
@@ -81,5 +83,7 @@ export {
|
|
|
81
83
|
to,
|
|
82
84
|
formatNumber,
|
|
83
85
|
getLocale,
|
|
84
|
-
setLocale
|
|
86
|
+
setLocale,
|
|
87
|
+
|
|
88
|
+
devWarn, devWarnForHook, warn
|
|
85
89
|
}
|
package/src/isZoom.js
CHANGED
package/src/isZoom2.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 检测浏览器缩放
|
|
3
|
+
*/
|
|
4
|
+
export default function isZoom2 () {
|
|
5
|
+
const detectZoomFunc = {
|
|
6
|
+
ie: () => { return window.screen.deviceXDPI / window.screen.logicalXDPI },
|
|
7
|
+
firefox: () => { return window.devicePixelRatio ? window.devicePixelRatio : n('min--moz-device-pixel-ratio', '', 0, 10, 20, 1e-4) },
|
|
8
|
+
opera: () => { return window.outerWidth / window.innerWidth },
|
|
9
|
+
chrome: () => {
|
|
10
|
+
if (window.devicePixelRatio) {
|
|
11
|
+
return window.devicePixelRatio
|
|
12
|
+
}
|
|
13
|
+
const o = window.document
|
|
14
|
+
const t = o.createElement('div')
|
|
15
|
+
t.innerHTML = '1'
|
|
16
|
+
t.setAttribute('style', 'font:100px/1em sans-serif-webkit-text-size-adjust:noneposition: absolutetop:-100%')
|
|
17
|
+
o.body.appendChild(t)
|
|
18
|
+
let n = 1e3 / t.clientHeight
|
|
19
|
+
n = Math.round(100 * n) / 100
|
|
20
|
+
o.body.removeChild(t)
|
|
21
|
+
return n
|
|
22
|
+
},
|
|
23
|
+
safari: () => { return window.outerWidth / window.innerWidth }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function round2 (number, fractionDigits) {
|
|
27
|
+
return Math.round(number * Math.pow(10, fractionDigits)) / Math.pow(10, fractionDigits)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function n (t, n, i, a, s, c) {
|
|
31
|
+
function l (e, o, i) {
|
|
32
|
+
const a = (e + o) / 2
|
|
33
|
+
if (i <= 0 || o - e < c) return a
|
|
34
|
+
const s = '(' + t + ':' + a + n + ')'
|
|
35
|
+
return r(s).matches ? l(a, o, i - 1) : l(e, a, i - 1)
|
|
36
|
+
}
|
|
37
|
+
let r, d, m, p
|
|
38
|
+
let e = window; let o = window.document
|
|
39
|
+
if (e.matchMedia) {
|
|
40
|
+
r = e.matchMedia
|
|
41
|
+
} else {
|
|
42
|
+
d = o.getElementsByTagName('head')[0]
|
|
43
|
+
m = o.createElement('style')
|
|
44
|
+
d.appendChild(m)
|
|
45
|
+
p = o.createElement('div')
|
|
46
|
+
p.className = 'mediaQueryBinarySearch'
|
|
47
|
+
p.style.display = 'none'
|
|
48
|
+
o.body.appendChild(p)
|
|
49
|
+
r = function (e) {
|
|
50
|
+
m.sheet.insertRule('@media ' + e + '{.mediaQueryBinarySearch {text-decoration: underline} }', 0)
|
|
51
|
+
const t = window.getComputedStyle(p, null).textDecoration === 'underline'
|
|
52
|
+
m.sheet.deleteRule(0)
|
|
53
|
+
return { matches: t }
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let u = l(i, a, s)
|
|
58
|
+
if (p) {
|
|
59
|
+
d.removeChild(m)
|
|
60
|
+
o.body.removeChild(p)
|
|
61
|
+
}
|
|
62
|
+
return u
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function system () {
|
|
66
|
+
let ua = navigator.userAgent.toLowerCase()
|
|
67
|
+
return ua.indexOf('win') >= 0 ? 'win' : ua.indexOf('mac') >= 0 ? 'mac' : false
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function getBrowser () {
|
|
71
|
+
let ua = navigator.userAgent.toLowerCase()
|
|
72
|
+
return window.ActiveXObject || 'ActiveXObject' in window ? 'ie' : ua.indexOf('firefox') >= 0 ? 'firefox' : ua.indexOf('chrome') >= 0 ? 'chrome' : ua.indexOf('opera') >= 0 ? 'opera' : ua.indexOf('safari') >= 0 ? 'safari' : void 0
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function detectZoom () {
|
|
76
|
+
return detectZoomFunc[getBrowser()]()
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function iszoom (e) {
|
|
80
|
+
return (e.system === 'win' && e.zoom !== 1) || (e.system === 'mac' && e.zoom % 1 !== 0 && e.zoom % 2 !== 0)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const zoomData = { zoom: round2(detectZoom(), 2), system: system() }
|
|
84
|
+
return iszoom(zoomData)
|
|
85
|
+
}
|
package/src/warn.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useEffect } from 'react'
|
|
2
|
+
|
|
3
|
+
function warn () {
|
|
4
|
+
if (process.env.NODE_ENV === 'production') {
|
|
5
|
+
return
|
|
6
|
+
}
|
|
7
|
+
console.warn.apply(this, ['[react-gm warn] ', ...arguments])
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const devWarnForHook = callback => {
|
|
11
|
+
devWarn(() => {
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
callback()
|
|
14
|
+
}, [])
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const devWarn = callback => {
|
|
19
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
20
|
+
callback()
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { warn, devWarn, devWarnForHook }
|
package/logs/gmfe.log
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
[36m[2018-06-21T18:04:55.652] [DEBUG] log2file - [39mgmfe argv: { _: [ 'npm_publish' ],
|
|
2
|
-
version: false,
|
|
3
|
-
a: 'minor',
|
|
4
|
-
add: 'minor',
|
|
5
|
-
'$0': 'gmfe',
|
|
6
|
-
u: undefined,
|
|
7
|
-
t: undefined,
|
|
8
|
-
b: undefined,
|
|
9
|
-
w: undefined,
|
|
10
|
-
d: undefined,
|
|
11
|
-
m: undefined }
|
|
12
|
-
[32m[2018-06-21T18:05:14.619] [INFO] log2file - [39m【rm -rf package-lock.json; npm version minor; git push origin master:master;】 v5.6.0
|
|
13
|
-
[32m[2018-06-21T18:05:14.620] [INFO] default - [39mstart to publish gm-util ...
|
|
14
|
-
[32m[2018-06-21T18:05:31.200] [INFO] log2file - [39m【npm publish --registry="https://registry.npmjs.org"; cnpm sync gm-util;】 + gm-util@5.6.0
|
|
15
|
-
Start sync ["gm-util"].
|
|
16
|
-
sync gm-util, PUT http://registry.npm.taobao.org/gm-util/sync?publish=false&nodeps=false
|
|
17
|
-
logurl: https://npm.taobao.org/sync/gm-util#logid=1799338
|
|
18
|
-
[2018-06-21 18:05:28] user: anonymous, sync gm-util worker start, 1 concurrency, nodeps: false, publish: false, syncUpstreamFirst: false
|
|
19
|
-
[2018-06-21 18:05:28] ----------------- Syncing gm-util -------------------
|
|
20
|
-
[2018-06-21 18:05:29] [c#0] [gm-util] package(https://r.cnpmjs.org/gm-util) status: 200, dist-tags: {"latest":"5.5.4"}, time.modified: 2018-05-17T06:36:09.000Z, unpublished: null, start...
|
|
21
|
-
[2018-06-21 18:05:29] [gm-util] found 0 missing star users
|
|
22
|
-
[2018-06-21 18:05:29] [gm-util] all versions are exists
|
|
23
|
-
[2018-06-21 18:05:29] [gm-util] no versions need to deleted
|
|
24
|
-
[2018-06-21 18:05:29] [gm-util] all 1 npm users exists
|
|
25
|
-
[2018-06-21 18:05:29] [c#0] [gm-util] synced success, 0 versions:
|
|
26
|
-
[2018-06-21 18:05:29] ----------------- Synced gm-util success -------------------
|
|
27
|
-
[2018-06-21 18:05:29] [done] Sync gm-util package finished, 1 success, 0 fail
|
|
28
|
-
Success: [ gm-util ]
|
|
29
|
-
Fail: [ ]
|
|
30
|
-
Sync all packages done, successed: ["gm-util"], failed: []
|
|
31
|
-
[32m[2018-06-21T18:05:31.200] [INFO] default - [39m如果 cnpm 同步失败(最近经常同步失败),请访问 https://npm.taobao.org/sync/gm-util 手动触发更新。
|