@hanzogui/use-window-dimensions 3.0.5 → 4.3.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/dist/cjs/helpers.cjs +44 -29
- package/dist/cjs/helpers.native.js +14 -11
- package/dist/cjs/helpers.native.js.map +1 -1
- package/dist/cjs/index.cjs +29 -27
- package/dist/cjs/index.native.js +29 -27
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/initialValue.cjs +12 -10
- package/dist/cjs/initialValue.native.js +12 -10
- package/dist/cjs/initialValue.native.js.map +1 -1
- package/dist/cjs/types.cjs +7 -5
- package/dist/cjs/types.native.js +7 -5
- package/dist/cjs/types.native.js.map +1 -1
- package/dist/esm/helpers.mjs +30 -17
- package/dist/esm/helpers.mjs.map +1 -1
- package/dist/esm/helpers.native.js +2 -1
- package/dist/esm/helpers.native.js.map +1 -1
- package/package.json +3 -3
- package/src/helpers.ts +8 -3
- package/types/helpers.d.ts.map +2 -2
package/dist/cjs/helpers.cjs
CHANGED
|
@@ -3,20 +3,22 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
5
|
var __export = (target, all) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
14
|
get: () => from[key],
|
|
14
15
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
16
|
});
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
18
20
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
-
value:
|
|
21
|
+
value: true
|
|
20
22
|
}), mod);
|
|
21
23
|
var helpers_exports = {};
|
|
22
24
|
__export(helpers_exports, {
|
|
@@ -24,11 +26,14 @@ __export(helpers_exports, {
|
|
|
24
26
|
subscribe: () => subscribe
|
|
25
27
|
});
|
|
26
28
|
module.exports = __toCommonJS(helpers_exports);
|
|
27
|
-
var import_constants = require("@hanzogui/constants")
|
|
28
|
-
|
|
29
|
-
let lastSize = import_initialValue.initialValue
|
|
30
|
-
|
|
29
|
+
var import_constants = require("@hanzogui/constants");
|
|
30
|
+
var import_initialValue = require("./initialValue.cjs");
|
|
31
|
+
let lastSize = import_initialValue.initialValue;
|
|
32
|
+
let docEl = null;
|
|
31
33
|
function getWindowSize() {
|
|
34
|
+
if (false) {
|
|
35
|
+
return import_initialValue.initialValue;
|
|
36
|
+
}
|
|
32
37
|
docEl ||= window.document.documentElement;
|
|
33
38
|
const nextSize = {
|
|
34
39
|
fontScale: 1,
|
|
@@ -36,26 +41,36 @@ function getWindowSize() {
|
|
|
36
41
|
scale: window.devicePixelRatio || 1,
|
|
37
42
|
width: docEl.clientWidth
|
|
38
43
|
};
|
|
39
|
-
|
|
44
|
+
if (nextSize.height !== lastSize.height || nextSize.width !== lastSize.width || nextSize.scale !== lastSize.scale) {
|
|
45
|
+
lastSize = nextSize;
|
|
46
|
+
return nextSize;
|
|
47
|
+
}
|
|
48
|
+
return lastSize;
|
|
40
49
|
}
|
|
41
50
|
const cbs = /* @__PURE__ */new Set();
|
|
42
|
-
if (import_constants.isClient) {
|
|
51
|
+
if (import_constants.isClient && typeof window !== "undefined" && typeof window.addEventListener === "function") {
|
|
43
52
|
let flushUpdate = function () {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
lastUpdate = Date.now();
|
|
54
|
+
cbs.forEach(cb => cb(getWindowSize()));
|
|
55
|
+
};
|
|
56
|
+
let lastUpdate = Date.now();
|
|
57
|
+
let tm;
|
|
58
|
+
const USER_MAX_MS = process.env.GUI_USE_WINDOW_DIMENSIONS_MAX_UPDATE_MS;
|
|
59
|
+
const updateMaxMs = USER_MAX_MS ? +USER_MAX_MS : 100;
|
|
60
|
+
const onResize = () => {
|
|
61
|
+
clearTimeout(tm);
|
|
62
|
+
const timeSinceLast = Date.now() - lastUpdate;
|
|
63
|
+
if (timeSinceLast < updateMaxMs) {
|
|
64
|
+
tm = setTimeout(() => {
|
|
54
65
|
flushUpdate();
|
|
55
|
-
}, updateMaxMs - timeSinceLast)
|
|
56
|
-
}
|
|
66
|
+
}, updateMaxMs - timeSinceLast);
|
|
67
|
+
} else {
|
|
68
|
+
flushUpdate();
|
|
69
|
+
}
|
|
70
|
+
};
|
|
57
71
|
window.addEventListener("resize", onResize);
|
|
58
72
|
}
|
|
59
73
|
function subscribe(cb) {
|
|
60
|
-
|
|
74
|
+
cbs.add(cb);
|
|
75
|
+
return () => cbs.delete(cb);
|
|
61
76
|
}
|
|
@@ -5,20 +5,22 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
16
|
get: () => from[key],
|
|
16
17
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
18
|
});
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
20
22
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
-
value:
|
|
23
|
+
value: true
|
|
22
24
|
}), mod);
|
|
23
25
|
var helpers_native_exports = {};
|
|
24
26
|
__export(helpers_native_exports, {
|
|
@@ -40,7 +42,8 @@ import_react_native.Dimensions.addEventListener("change", function (param) {
|
|
|
40
42
|
});
|
|
41
43
|
});
|
|
42
44
|
function subscribe(cb) {
|
|
43
|
-
|
|
45
|
+
cbs.add(cb);
|
|
46
|
+
return function () {
|
|
44
47
|
return cbs.delete(cb);
|
|
45
48
|
};
|
|
46
49
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["helpers_native_exports","__export","getWindowSize","subscribe","module","exports","__toCommonJS","import_react_native","require","Dimensions","get","cbs","Set","addEventListener","param","window","forEach","cb","add","delete"],"sources":["../../src/helpers.native.ts"],"sourcesContent":[null],"mappings":"
|
|
1
|
+
{"version":3,"names":["helpers_native_exports","__export","getWindowSize","subscribe","module","exports","__toCommonJS","import_react_native","require","Dimensions","get","cbs","Set","addEventListener","param","window","forEach","cb","add","delete"],"sources":["../../src/helpers.native.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,sBAAA;AAAAC,QAAA,CAAAD,sBAAA;EAAAE,aAAA,EAAAA,CAAA,KAAAA,aAAA;EAAAC,SAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAC,YAAA,CAAAN,sBAAA;AAAA,IAAAO,mBAAA,GAA2BC,OAAA;AACpB,SAASN,cAAA,EAAgB;EAC5B,OAAOK,mBAAA,CAAAE,UAAA,CAAWC,GAAA,CAAI,QAAQ;AAClC;AACA,IAAIC,GAAA,GAAM,mBAAIC,GAAA,CAAI;AAClBL,mBAAA,CAAAE,UAAA,CAAWI,gBAAA,CAAiB,UAAU,UAASC,KAAA,EAAO;EAClD,IAAI;IAAEC;EAAO,IAAID,KAAA;EACjBH,GAAA,CAAIK,OAAA,CAAQ,UAASC,EAAA,EAAI;IACrB,OAAOA,EAAA,CAAGF,MAAM;EACpB,CAAC;AACL,CAAC;AACM,SAASZ,UAAUc,EAAA,EAAI;EAC1BN,GAAA,CAAIO,GAAA,CAAID,EAAE;EACV,OAAO,YAAW;IACd,OAAON,GAAA,CAAIQ,MAAA,CAAOF,EAAE;EACxB;AACJ","ignoreList":[]}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -2,44 +2,46 @@ var __create = Object.create;
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf
|
|
6
|
-
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
16
|
get: () => from[key],
|
|
16
17
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
18
|
});
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
20
22
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
+
value: mod,
|
|
29
|
+
enumerable: true
|
|
30
|
+
}) : target, mod));
|
|
31
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
+
value: true
|
|
33
|
+
}), mod);
|
|
32
34
|
var index_exports = {};
|
|
33
35
|
__export(index_exports, {
|
|
34
36
|
configureInitialWindowDimensions: () => import_initialValue2.configureInitialWindowDimensions,
|
|
35
37
|
useWindowDimensions: () => useWindowDimensions
|
|
36
38
|
});
|
|
37
39
|
module.exports = __toCommonJS(index_exports);
|
|
38
|
-
var import_react = __toESM(require("react"), 1)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
var import_react = __toESM(require("react"), 1);
|
|
41
|
+
var import_constants = require("@hanzogui/constants");
|
|
42
|
+
var import_helpers = require("./helpers.cjs");
|
|
43
|
+
var import_initialValue = require("./initialValue.cjs");
|
|
44
|
+
var import_initialValue2 = require("./initialValue.cjs");
|
|
43
45
|
function useWindowDimensions({
|
|
44
46
|
serverValue = import_initialValue.initialValue
|
|
45
47
|
} = {}) {
|
package/dist/cjs/index.native.js
CHANGED
|
@@ -4,44 +4,46 @@ var __create = Object.create;
|
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf
|
|
8
|
-
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
9
|
var __export = (target, all) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
for (var name in all) __defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: true
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
18
|
get: () => from[key],
|
|
18
19
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
20
|
});
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
22
24
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
30
|
+
value: mod,
|
|
31
|
+
enumerable: true
|
|
32
|
+
}) : target, mod));
|
|
33
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
34
|
+
value: true
|
|
35
|
+
}), mod);
|
|
34
36
|
var index_exports = {};
|
|
35
37
|
__export(index_exports, {
|
|
36
38
|
configureInitialWindowDimensions: () => import_initialValue2.configureInitialWindowDimensions,
|
|
37
39
|
useWindowDimensions: () => useWindowDimensions
|
|
38
40
|
});
|
|
39
41
|
module.exports = __toCommonJS(index_exports);
|
|
40
|
-
var import_react = __toESM(require("react"), 1)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
var import_react = __toESM(require("react"), 1);
|
|
43
|
+
var import_constants = require("@hanzogui/constants");
|
|
44
|
+
var import_helpers = require("./helpers.native.js");
|
|
45
|
+
var import_initialValue = require("./initialValue.native.js");
|
|
46
|
+
var import_initialValue2 = require("./initialValue.native.js");
|
|
45
47
|
function useWindowDimensions() {
|
|
46
48
|
var {
|
|
47
49
|
serverValue = import_initialValue.initialValue
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","index_exports","__export","configureInitialWindowDimensions","import_initialValue2","useWindowDimensions","module","exports","import_react","__toESM","require","import_constants","import_helpers","import_initialValue","serverValue","initialValue","arguments","length","default","useSyncExternalStore","subscribe","getWindowSize","isWeb"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,aAAA;AAAAC,QAAA,CAAAD,aAAA;EAAAE,gCAAA,EAAAA,CAAA,KAAAC,oBAAA,CAAAD,gCAAA;EAAAE,mBAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAX,YAAkB,CAAAK,aAAA;AAClB,IAAAO,YAAA,GAAAC,OAAsB,CAAAC,OAAA;AAEtB,IAAAC,gBAAA,GAAyCD,OAAA;AAEzC,IAAAE,cAAA,GAAAF,OAA6B;AAE7B,IAAAG,mBAAA,GAAAH,OAAiD;AAE1C,IAAAN,oBAAS,GAAAM,OAAoB;AAAA,SAClCL,mBAAcA,CAAA;EAChB,IAAmC;IAAeS,WAAA,GAAAD,mBAAA,CAAAE;EAAA,IAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,iBAAAA,SAAA;EAChD,OAAOR,YAAA,CAAAU,OAAA,CAAMC,oBAAA,CAAAP,cAAA,CAAAQ,SAAA,EAAAR,cAAA,CAAAS,aAAA;IAAqB,OAAAV,gBAAA,CAAAW,KAAA,GAAAR,WAAA,OAAAF,cAAA,CAAAS,aAAA;EAAA,EAAW;AAAA","ignoreList":[]}
|
|
@@ -3,20 +3,22 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
5
|
var __export = (target, all) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
14
|
get: () => from[key],
|
|
14
15
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
16
|
});
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
18
20
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
-
value:
|
|
21
|
+
value: true
|
|
20
22
|
}), mod);
|
|
21
23
|
var initialValue_exports = {};
|
|
22
24
|
__export(initialValue_exports, {
|
|
@@ -5,20 +5,22 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
16
|
get: () => from[key],
|
|
16
17
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
18
|
});
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
20
22
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
-
value:
|
|
23
|
+
value: true
|
|
22
24
|
}), mod);
|
|
23
25
|
var initialValue_exports = {};
|
|
24
26
|
__export(initialValue_exports, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","initialValue_exports","__export","configureInitialWindowDimensions","initialValue","module","exports","width","height","scale","fontScale","next","Object","assign"],"sources":["../../src/initialValue.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,oBAAA;AAAAC,QAAA,CAAAD,oBAAA;EAAAE,gCAAA,EAAAA,CAAA,KAAAA,gCAAA;EAAAC,YAAA,EAAAA,CAAA,KAAAA;AAAA;AAKOC,MAAM,CAAAC,OAAA,GAAAV,YAA2B,CAAAK,oBAAA;AAAA,IACtCG,YAAO;EACPG,KAAA,KAAQ;EACRC,MAAA,EAAO;EACPC,KAAA;EACFC,SAAA;AAEO;AACL,SAAOP,gCAAyBA,CAAAQ,IAAA;EAClCC,MAAA,CAAAC,MAAA,CAAAT,YAAA,EAAAO,IAAA","ignoreList":[]}
|
package/dist/cjs/types.cjs
CHANGED
|
@@ -3,14 +3,16 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
5
|
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
if (from && typeof from
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
8
|
+
get: () => from[key],
|
|
9
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
10
|
+
});
|
|
11
|
+
}
|
|
10
12
|
return to;
|
|
11
13
|
};
|
|
12
14
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
13
|
-
value:
|
|
15
|
+
value: true
|
|
14
16
|
}), mod);
|
|
15
17
|
var types_exports = {};
|
|
16
18
|
module.exports = __toCommonJS(types_exports);
|
package/dist/cjs/types.native.js
CHANGED
|
@@ -5,14 +5,16 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __copyProps = (to, from, except, desc) => {
|
|
8
|
-
if (from && typeof from
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
10
|
+
get: () => from[key],
|
|
11
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
12
|
+
});
|
|
13
|
+
}
|
|
12
14
|
return to;
|
|
13
15
|
};
|
|
14
16
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
15
|
-
value:
|
|
17
|
+
value: true
|
|
16
18
|
}), mod);
|
|
17
19
|
var types_exports = {};
|
|
18
20
|
module.exports = __toCommonJS(types_exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","types_exports"],"sources":["../../src/types.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,aAAA","ignoreList":[]}
|
package/dist/esm/helpers.mjs
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { isClient } from "@hanzogui/constants";
|
|
2
2
|
import { initialValue } from "./initialValue.mjs";
|
|
3
|
-
let lastSize = initialValue
|
|
4
|
-
|
|
3
|
+
let lastSize = initialValue;
|
|
4
|
+
let docEl = null;
|
|
5
5
|
function getWindowSize() {
|
|
6
|
+
if (false) {
|
|
7
|
+
return initialValue;
|
|
8
|
+
}
|
|
6
9
|
docEl ||= window.document.documentElement;
|
|
7
10
|
const nextSize = {
|
|
8
11
|
fontScale: 1,
|
|
@@ -10,28 +13,38 @@ function getWindowSize() {
|
|
|
10
13
|
scale: window.devicePixelRatio || 1,
|
|
11
14
|
width: docEl.clientWidth
|
|
12
15
|
};
|
|
13
|
-
|
|
16
|
+
if (nextSize.height !== lastSize.height || nextSize.width !== lastSize.width || nextSize.scale !== lastSize.scale) {
|
|
17
|
+
lastSize = nextSize;
|
|
18
|
+
return nextSize;
|
|
19
|
+
}
|
|
20
|
+
return lastSize;
|
|
14
21
|
}
|
|
15
22
|
const cbs = /* @__PURE__ */new Set();
|
|
16
|
-
if (isClient) {
|
|
23
|
+
if (isClient && typeof window !== "undefined" && typeof window.addEventListener === "function") {
|
|
17
24
|
let flushUpdate = function () {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
lastUpdate = Date.now();
|
|
26
|
+
cbs.forEach(cb => cb(getWindowSize()));
|
|
27
|
+
};
|
|
28
|
+
let lastUpdate = Date.now();
|
|
29
|
+
let tm;
|
|
30
|
+
const USER_MAX_MS = process.env.GUI_USE_WINDOW_DIMENSIONS_MAX_UPDATE_MS;
|
|
31
|
+
const updateMaxMs = USER_MAX_MS ? +USER_MAX_MS : 100;
|
|
32
|
+
const onResize = () => {
|
|
33
|
+
clearTimeout(tm);
|
|
34
|
+
const timeSinceLast = Date.now() - lastUpdate;
|
|
35
|
+
if (timeSinceLast < updateMaxMs) {
|
|
36
|
+
tm = setTimeout(() => {
|
|
28
37
|
flushUpdate();
|
|
29
|
-
}, updateMaxMs - timeSinceLast)
|
|
30
|
-
}
|
|
38
|
+
}, updateMaxMs - timeSinceLast);
|
|
39
|
+
} else {
|
|
40
|
+
flushUpdate();
|
|
41
|
+
}
|
|
42
|
+
};
|
|
31
43
|
window.addEventListener("resize", onResize);
|
|
32
44
|
}
|
|
33
45
|
function subscribe(cb) {
|
|
34
|
-
|
|
46
|
+
cbs.add(cb);
|
|
47
|
+
return () => cbs.delete(cb);
|
|
35
48
|
}
|
|
36
49
|
export { getWindowSize, subscribe };
|
|
37
50
|
//# sourceMappingURL=helpers.mjs.map
|
package/dist/esm/helpers.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["isClient","initialValue","lastSize","docEl","getWindowSize","window","document","documentElement","nextSize","fontScale","height","clientHeight","scale","devicePixelRatio","width","clientWidth","cbs","Set","flushUpdate","lastUpdate","Date","now","forEach","cb","tm","USER_MAX_MS","process","env","
|
|
1
|
+
{"version":3,"names":["isClient","initialValue","lastSize","docEl","getWindowSize","window","document","documentElement","nextSize","fontScale","height","clientHeight","scale","devicePixelRatio","width","clientWidth","cbs","Set","addEventListener","flushUpdate","lastUpdate","Date","now","forEach","cb","tm","USER_MAX_MS","process","env","GUI_USE_WINDOW_DIMENSIONS_MAX_UPDATE_MS","updateMaxMs","onResize","clearTimeout","timeSinceLast","setTimeout","subscribe","add","delete"],"sources":["../../src/helpers.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,QAAA,QAAgB;AACzB,SAASC,YAAA,QAAoB;AAG7B,IAAIC,QAAA,GAAuBD,YAAA;AAC3B,IAAIE,KAAA,GAA4B;AAEzB,SAASC,cAAA,EAA4B;EAC1C,IAAI,OAAkC;IACpC,OAAOH,YAAA;EACT;EAEAE,KAAA,KAAUE,MAAA,CAAOC,QAAA,CAASC,eAAA;EAE1B,MAAMC,QAAA,GAAuB;IAC3BC,SAAA,EAAW;IACXC,MAAA,EAAQP,KAAA,CAAMQ,YAAA;IACdC,KAAA,EAAOP,MAAA,CAAOQ,gBAAA,IAAoB;IAClCC,KAAA,EAAOX,KAAA,CAAMY;EACf;EAEA,IACEP,QAAA,CAASE,MAAA,KAAWR,QAAA,CAASQ,MAAA,IAC7BF,QAAA,CAASM,KAAA,KAAUZ,QAAA,CAASY,KAAA,IAC5BN,QAAA,CAASI,KAAA,KAAUV,QAAA,CAASU,KAAA,EAC5B;IACAV,QAAA,GAAWM,QAAA;IACX,OAAOA,QAAA;EACT;EAEA,OAAON,QAAA;AACT;AAEA,MAAMc,GAAA,GAAM,mBAAIC,GAAA,CAAwB;AAIxC,IACEjB,QAAA,IACA,OAAOK,MAAA,KAAW,eAClB,OAAOA,MAAA,CAAOa,gBAAA,KAAqB,YACnC;EAMA,IAASC,WAAA,GAAT,SAAAA,CAAA,EAAuB;IACrBC,UAAA,GAAaC,IAAA,CAAKC,GAAA,CAAI;IACtBN,GAAA,CAAIO,OAAA,CAASC,EAAA,IAAOA,EAAA,CAAGpB,aAAA,CAAc,CAAC,CAAC;EACzC;EARA,IAAIgB,UAAA,GAAaC,IAAA,CAAKC,GAAA,CAAI;EAC1B,IAAIG,EAAA;EACJ,MAAMC,WAAA,GAAcC,OAAA,CAAQC,GAAA,CAAIC,uCAAA;EAChC,MAAMC,WAAA,GAAcJ,WAAA,GAAc,CAACA,WAAA,GAAc;EAOjD,MAAMK,QAAA,GAAWA,CAAA,KAAM;IACrBC,YAAA,CAAaP,EAAE;IAGf,MAAMQ,aAAA,GAAgBZ,IAAA,CAAKC,GAAA,CAAI,IAAIF,UAAA;IACnC,IAAIa,aAAA,GAAgBH,WAAA,EAAa;MAC/BL,EAAA,GAAKS,UAAA,CAAW,MAAM;QACpBf,WAAA,CAAY;MACd,GAAGW,WAAA,GAAcG,aAAa;IAChC,OAAO;MACLd,WAAA,CAAY;IACd;EACF;EAEAd,MAAA,CAAOa,gBAAA,CAAiB,UAAUa,QAAQ;AAC5C;AAEO,SAASI,UAAUX,EAAA,EAAoC;EAC5DR,GAAA,CAAIoB,GAAA,CAAIZ,EAAE;EACV,OAAO,MAAMR,GAAA,CAAIqB,MAAA,CAAOb,EAAE;AAC5B","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Dimensions","getWindowSize","get","cbs","Set","addEventListener","param","window","forEach","cb","subscribe","add","delete"],"sources":["../../src/helpers.native.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,UAAA,QAAkB;AACpB,SAASC,cAAA,EAAgB;EAC5B,OAAOD,UAAA,CAAWE,GAAA,CAAI,QAAQ;AAClC;AACA,IAAIC,GAAA,GAAM,mBAAIC,GAAA,CAAI;AAClBJ,UAAA,CAAWK,gBAAA,CAAiB,UAAU,UAASC,KAAA,EAAO;EAClD,IAAI;IAAEC;EAAO,IAAID,KAAA;EACjBH,GAAA,CAAIK,OAAA,CAAQ,UAASC,EAAA,EAAI;IACrB,OAAOA,EAAA,CAAGF,MAAM;EACpB,CAAC;AACL,CAAC;AACM,SAASG,UAAUD,EAAA,EAAI;
|
|
1
|
+
{"version":3,"names":["Dimensions","getWindowSize","get","cbs","Set","addEventListener","param","window","forEach","cb","subscribe","add","delete"],"sources":["../../src/helpers.native.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,UAAA,QAAkB;AACpB,SAASC,cAAA,EAAgB;EAC5B,OAAOD,UAAA,CAAWE,GAAA,CAAI,QAAQ;AAClC;AACA,IAAIC,GAAA,GAAM,mBAAIC,GAAA,CAAI;AAClBJ,UAAA,CAAWK,gBAAA,CAAiB,UAAU,UAASC,KAAA,EAAO;EAClD,IAAI;IAAEC;EAAO,IAAID,KAAA;EACjBH,GAAA,CAAIK,OAAA,CAAQ,UAASC,EAAA,EAAI;IACrB,OAAOA,EAAA,CAAGF,MAAM;EACpB,CAAC;AACL,CAAC;AACM,SAASG,UAAUD,EAAA,EAAI;EAC1BN,GAAA,CAAIQ,GAAA,CAAIF,EAAE;EACV,OAAO,YAAW;IACd,OAAON,GAAA,CAAIS,MAAA,CAAOH,EAAE;EACxB;AACJ","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hanzogui/use-window-dimensions",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "4.3.1",
|
|
4
4
|
"gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14",
|
|
5
5
|
"files": [
|
|
6
6
|
"src",
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
"clean:build": "hanzo-gui-build clean:build"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@hanzogui/constants": "3.0.
|
|
37
|
+
"@hanzogui/constants": "3.0.6"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@hanzogui/build": "3.0.
|
|
40
|
+
"@hanzogui/build": "3.0.6",
|
|
41
41
|
"react": ">=19",
|
|
42
42
|
"react-native": "0.83.2"
|
|
43
43
|
},
|
package/src/helpers.ts
CHANGED
|
@@ -6,7 +6,7 @@ let lastSize: WindowSize = initialValue
|
|
|
6
6
|
let docEl: HTMLElement | null = null
|
|
7
7
|
|
|
8
8
|
export function getWindowSize(): WindowSize {
|
|
9
|
-
if (process.env.
|
|
9
|
+
if (process.env.GUI_TARGET !== 'web') {
|
|
10
10
|
return initialValue
|
|
11
11
|
}
|
|
12
12
|
|
|
@@ -34,10 +34,15 @@ export function getWindowSize(): WindowSize {
|
|
|
34
34
|
const cbs = new Set<WindowSizeListener>()
|
|
35
35
|
|
|
36
36
|
// only attach resize listener on client (not during SSR)
|
|
37
|
-
|
|
37
|
+
// also guard window.addEventListener since isClient=true on native but window.addEventListener is undefined
|
|
38
|
+
if (
|
|
39
|
+
isClient &&
|
|
40
|
+
typeof window !== 'undefined' &&
|
|
41
|
+
typeof window.addEventListener === 'function'
|
|
42
|
+
) {
|
|
38
43
|
let lastUpdate = Date.now()
|
|
39
44
|
let tm: ReturnType<typeof setTimeout> | undefined
|
|
40
|
-
const USER_MAX_MS = process.env.
|
|
45
|
+
const USER_MAX_MS = process.env.GUI_USE_WINDOW_DIMENSIONS_MAX_UPDATE_MS
|
|
41
46
|
const updateMaxMs = USER_MAX_MS ? +USER_MAX_MS : 100
|
|
42
47
|
|
|
43
48
|
function flushUpdate() {
|
package/types/helpers.d.ts.map
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"mappings": "AAEA,cAAc,YAAY,0BAA0B;AAKpD,OAAO,iBAAS,iBAAiB;
|
|
2
|
+
"mappings": "AAEA,cAAc,YAAY,0BAA0B;AAKpD,OAAO,iBAAS,iBAAiB;AA8DjC,OAAO,iBAAS,UAAU,IAAI",
|
|
3
3
|
"names": [],
|
|
4
4
|
"sources": [
|
|
5
5
|
"src/helpers.ts"
|
|
6
6
|
],
|
|
7
7
|
"version": 3,
|
|
8
8
|
"sourcesContent": [
|
|
9
|
-
"import { isClient } from '@hanzogui/constants'\nimport { initialValue } from './initialValue'\nimport type { WindowSize, WindowSizeListener } from './types'\n\nlet lastSize: WindowSize = initialValue\nlet docEl: HTMLElement | null = null\n\nexport function getWindowSize(): WindowSize {\n if (process.env.
|
|
9
|
+
"import { isClient } from '@hanzogui/constants'\nimport { initialValue } from './initialValue'\nimport type { WindowSize, WindowSizeListener } from './types'\n\nlet lastSize: WindowSize = initialValue\nlet docEl: HTMLElement | null = null\n\nexport function getWindowSize(): WindowSize {\n if (process.env.GUI_TARGET !== 'web') {\n return initialValue\n }\n\n docEl ||= window.document.documentElement\n\n const nextSize: WindowSize = {\n fontScale: 1,\n height: docEl.clientHeight,\n scale: window.devicePixelRatio || 1,\n width: docEl.clientWidth,\n }\n\n if (\n nextSize.height !== lastSize.height ||\n nextSize.width !== lastSize.width ||\n nextSize.scale !== lastSize.scale\n ) {\n lastSize = nextSize\n return nextSize\n }\n\n return lastSize\n}\n\nconst cbs = new Set<WindowSizeListener>()\n\n// only attach resize listener on client (not during SSR)\n// also guard window.addEventListener since isClient=true on native but window.addEventListener is undefined\nif (\n isClient &&\n typeof window !== 'undefined' &&\n typeof window.addEventListener === 'function'\n) {\n let lastUpdate = Date.now()\n let tm: ReturnType<typeof setTimeout> | undefined\n const USER_MAX_MS = process.env.GUI_USE_WINDOW_DIMENSIONS_MAX_UPDATE_MS\n const updateMaxMs = USER_MAX_MS ? +USER_MAX_MS : 100\n\n function flushUpdate() {\n lastUpdate = Date.now()\n cbs.forEach((cb) => cb(getWindowSize()))\n }\n\n const onResize = () => {\n clearTimeout(tm)\n\n // only update every few frames\n const timeSinceLast = Date.now() - lastUpdate\n if (timeSinceLast < updateMaxMs) {\n tm = setTimeout(() => {\n flushUpdate()\n }, updateMaxMs - timeSinceLast)\n } else {\n flushUpdate()\n }\n }\n\n window.addEventListener('resize', onResize)\n}\n\nexport function subscribe(cb: WindowSizeListener): () => void {\n cbs.add(cb)\n return () => cbs.delete(cb)\n}\n"
|
|
10
10
|
]
|
|
11
11
|
}
|