@hanzogui/use-window-dimensions 8.3.0 → 8.3.2
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.js +61 -0
- package/dist/cjs/helpers.js.map +1 -0
- package/dist/cjs/index.js +15 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/initialValue.js +17 -0
- package/dist/cjs/initialValue.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/helpers.js +57 -0
- package/dist/esm/helpers.js.map +1 -0
- package/dist/esm/index.js +8 -11
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/initialValue.js +13 -0
- package/dist/esm/initialValue.js.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/native/helpers.js +23 -0
- package/dist/native/helpers.js.map +1 -0
- package/dist/native/index.js +9 -0
- package/dist/native/index.js.map +1 -0
- package/dist/native/initialValue.js +13 -0
- package/dist/native/initialValue.js.map +1 -0
- package/dist/native/types.js +2 -0
- package/dist/native/types.js.map +1 -0
- package/package.json +14 -14
- package/src/helpers.native.ts +1 -1
- package/src/helpers.ts +2 -2
- package/src/index.ts +4 -4
- package/src/initialValue.ts +1 -1
- package/types/helpers.d.ts +1 -2
- package/types/helpers.d.ts.map +1 -11
- package/types/helpers.native.d.ts +1 -2
- package/types/helpers.native.d.ts.map +1 -11
- package/types/index.d.ts +4 -5
- package/types/index.d.ts.map +1 -11
- package/types/initialValue.d.ts +3 -4
- package/types/initialValue.d.ts.map +1 -11
- package/types/types.d.ts +3 -4
- package/types/types.d.ts.map +1 -11
- package/dist/cjs/helpers.cjs +0 -68
- package/dist/cjs/helpers.native.js +0 -56
- package/dist/cjs/helpers.native.js.map +0 -1
- package/dist/cjs/index.cjs +0 -49
- package/dist/cjs/index.native.js +0 -55
- package/dist/cjs/index.native.js.map +0 -1
- package/dist/cjs/initialValue.cjs +0 -37
- package/dist/cjs/initialValue.native.js +0 -40
- package/dist/cjs/initialValue.native.js.map +0 -1
- package/dist/cjs/types.cjs +0 -18
- package/dist/cjs/types.native.js +0 -21
- package/dist/cjs/types.native.js.map +0 -1
- package/dist/esm/helpers.mjs +0 -43
- package/dist/esm/helpers.mjs.map +0 -1
- package/dist/esm/helpers.native.js +0 -27
- package/dist/esm/helpers.native.js.map +0 -1
- package/dist/esm/index.mjs +0 -12
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js +0 -15
- package/dist/esm/index.native.js.map +0 -1
- package/dist/esm/initialValue.mjs +0 -11
- package/dist/esm/initialValue.mjs.map +0 -1
- package/dist/esm/initialValue.native.js +0 -11
- package/dist/esm/initialValue.native.js.map +0 -1
- package/dist/esm/types.mjs +0 -2
- package/dist/esm/types.mjs.map +0 -1
- package/dist/esm/types.native.js +0 -2
- package/dist/esm/types.native.js.map +0 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getWindowSize = getWindowSize;
|
|
4
|
+
exports.subscribe = subscribe;
|
|
5
|
+
const constants_1 = require("@hanzogui/constants");
|
|
6
|
+
const initialValue_ts_1 = require("./initialValue.js");
|
|
7
|
+
let lastSize = initialValue_ts_1.initialValue;
|
|
8
|
+
let docEl = null;
|
|
9
|
+
function getWindowSize() {
|
|
10
|
+
if ("web" !== 'web') {
|
|
11
|
+
return initialValue_ts_1.initialValue;
|
|
12
|
+
}
|
|
13
|
+
docEl || (docEl = window.document.documentElement);
|
|
14
|
+
const nextSize = {
|
|
15
|
+
fontScale: 1,
|
|
16
|
+
height: docEl.clientHeight,
|
|
17
|
+
scale: window.devicePixelRatio || 1,
|
|
18
|
+
width: docEl.clientWidth,
|
|
19
|
+
};
|
|
20
|
+
if (nextSize.height !== lastSize.height ||
|
|
21
|
+
nextSize.width !== lastSize.width ||
|
|
22
|
+
nextSize.scale !== lastSize.scale) {
|
|
23
|
+
lastSize = nextSize;
|
|
24
|
+
return nextSize;
|
|
25
|
+
}
|
|
26
|
+
return lastSize;
|
|
27
|
+
}
|
|
28
|
+
const cbs = new Set();
|
|
29
|
+
// only attach resize listener on client (not during SSR)
|
|
30
|
+
// also guard window.addEventListener since isClient=true on native but window.addEventListener is undefined
|
|
31
|
+
if (constants_1.isClient &&
|
|
32
|
+
typeof window !== 'undefined' &&
|
|
33
|
+
typeof window.addEventListener === 'function') {
|
|
34
|
+
let lastUpdate = Date.now();
|
|
35
|
+
let tm;
|
|
36
|
+
const USER_MAX_MS = process.env.GUI_USE_WINDOW_DIMENSIONS_MAX_UPDATE_MS;
|
|
37
|
+
const updateMaxMs = USER_MAX_MS ? +USER_MAX_MS : 100;
|
|
38
|
+
function flushUpdate() {
|
|
39
|
+
lastUpdate = Date.now();
|
|
40
|
+
cbs.forEach((cb) => cb(getWindowSize()));
|
|
41
|
+
}
|
|
42
|
+
const onResize = () => {
|
|
43
|
+
clearTimeout(tm);
|
|
44
|
+
// only update every few frames
|
|
45
|
+
const timeSinceLast = Date.now() - lastUpdate;
|
|
46
|
+
if (timeSinceLast < updateMaxMs) {
|
|
47
|
+
tm = setTimeout(() => {
|
|
48
|
+
flushUpdate();
|
|
49
|
+
}, updateMaxMs - timeSinceLast);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
flushUpdate();
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
window.addEventListener('resize', onResize);
|
|
56
|
+
}
|
|
57
|
+
function subscribe(cb) {
|
|
58
|
+
cbs.add(cb);
|
|
59
|
+
return () => cbs.delete(cb);
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":";;;;AAAA,mDAA8C;AAC9C,uDAAgD;AAGhD,IAAI,QAAQ,GAAe,8BAAY,CAAA;AACvC,IAAI,KAAK,GAAuB,IAAI,CAAA;AAEpC;IACE,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,KAAK,KAAK,EAAE,CAAC;QACrC,OAAO,8BAAY,CAAA;IACrB,CAAC;IAED,KAAK,KAAL,KAAK,GAAK,MAAM,CAAC,QAAQ,CAAC,eAAe,EAAA;IAEzC,MAAM,QAAQ,GAAe;QAC3B,SAAS,EAAE,CAAC;QACZ,MAAM,EAAE,KAAK,CAAC,YAAY;QAC1B,KAAK,EAAE,MAAM,CAAC,gBAAgB,IAAI,CAAC;QACnC,KAAK,EAAE,KAAK,CAAC,WAAW;KACzB,CAAA;IAED,IACE,QAAQ,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM;QACnC,QAAQ,CAAC,KAAK,KAAK,QAAQ,CAAC,KAAK;QACjC,QAAQ,CAAC,KAAK,KAAK,QAAQ,CAAC,KAAK,EACjC,CAAC;QACD,QAAQ,GAAG,QAAQ,CAAA;QACnB,OAAO,QAAQ,CAAA;IACjB,CAAC;IAED,OAAO,QAAQ,CAAA;AACjB,CAAC;AAED,MAAM,GAAG,GAAG,IAAI,GAAG,EAAsB,CAAA;AAEzC,yDAAyD;AACzD,4GAA4G;AAC5G,IACE,oBAAQ;IACR,OAAO,MAAM,KAAK,WAAW;IAC7B,OAAO,MAAM,CAAC,gBAAgB,KAAK,UAAU,EAC7C,CAAC;IACD,IAAI,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;IAC3B,IAAI,EAA6C,CAAA;IACjD,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAA;IACvE,MAAM,WAAW,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAA;IAEpD,SAAS,WAAW;QAClB,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QACvB,GAAG,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,aAAa,EAAE,CAAC,CAAC,CAAA;IAC1C,CAAC;IAED,MAAM,QAAQ,GAAG,GAAG,EAAE;QACpB,YAAY,CAAC,EAAE,CAAC,CAAA;QAEhB,+BAA+B;QAC/B,MAAM,aAAa,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,UAAU,CAAA;QAC7C,IAAI,aAAa,GAAG,WAAW,EAAE,CAAC;YAChC,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE;gBACnB,WAAW,EAAE,CAAA;YACf,CAAC,EAAE,WAAW,GAAG,aAAa,CAAC,CAAA;QACjC,CAAC;aAAM,CAAC;YACN,WAAW,EAAE,CAAA;QACf,CAAC;IACH,CAAC,CAAA;IAED,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;AAC7C,CAAC;AAED,mBAA0B,EAAsB;IAC9C,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IACX,OAAO,GAAG,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;AAC7B,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.configureInitialWindowDimensions = void 0;
|
|
4
|
+
exports.useWindowDimensions = useWindowDimensions;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const react_1 = tslib_1.__importDefault(require("react"));
|
|
7
|
+
const constants_1 = require("@hanzogui/constants");
|
|
8
|
+
const helpers_ts_1 = require("./helpers.js");
|
|
9
|
+
const initialValue_ts_1 = require("./initialValue.js");
|
|
10
|
+
var initialValue_ts_2 = require("./initialValue.js");
|
|
11
|
+
Object.defineProperty(exports, "configureInitialWindowDimensions", { enumerable: true, get: function () { return initialValue_ts_2.configureInitialWindowDimensions; } });
|
|
12
|
+
function useWindowDimensions({ serverValue = initialValue_ts_1.initialValue, } = {}) {
|
|
13
|
+
return react_1.default.useSyncExternalStore(helpers_ts_1.subscribe, helpers_ts_1.getWindowSize, () => constants_1.isWeb ? serverValue : (0, helpers_ts_1.getWindowSize)());
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;AAAA,0DAAyB;AACzB,mDAA2C;AAE3C,6CAAuD;AAEvD,uDAAgD;AAEhD,qDAAoE;AAA3D,mIAAA,gCAAgC,OAAA;AAEzC,6BAAoC,EAClC,WAAW,GAAG,8BAAY,GAC3B,GAAiC,EAAE;IAClC,OAAO,eAAK,CAAC,oBAAoB,CAAC,sBAAS,EAAE,0BAAa,EAAE,GAAG,EAAE,CAC/D,iBAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,IAAA,0BAAa,GAAE,CACtC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initialValue = void 0;
|
|
4
|
+
exports.configureInitialWindowDimensions = configureInitialWindowDimensions;
|
|
5
|
+
/**
|
|
6
|
+
* SSR safe useWindowDimensions
|
|
7
|
+
*/
|
|
8
|
+
exports.initialValue = {
|
|
9
|
+
width: 800,
|
|
10
|
+
height: 600,
|
|
11
|
+
scale: 1,
|
|
12
|
+
fontScale: 1,
|
|
13
|
+
};
|
|
14
|
+
function configureInitialWindowDimensions(next) {
|
|
15
|
+
Object.assign(exports.initialValue, next);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=initialValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initialValue.js","sourceRoot":"","sources":["../../src/initialValue.ts"],"names":[],"mappings":";;;;AAEA;;GAEG;AACU,QAAA,YAAY,GAAe;IACtC,KAAK,EAAE,GAAG;IACV,MAAM,EAAE,GAAG;IACX,KAAK,EAAE,CAAC;IACR,SAAS,EAAE,CAAC;CACb,CAAA;AAED,0CAAiD,IAAgB;IAC/D,MAAM,CAAC,MAAM,CAAC,QAAA,YAAY,EAAE,IAAI,CAAC,CAAA;AACnC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "commonjs" }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { isClient } from '@hanzogui/constants';
|
|
2
|
+
import { initialValue } from './initialValue.js';
|
|
3
|
+
let lastSize = initialValue;
|
|
4
|
+
let docEl = null;
|
|
5
|
+
export function getWindowSize() {
|
|
6
|
+
if ("web" !== 'web') {
|
|
7
|
+
return initialValue;
|
|
8
|
+
}
|
|
9
|
+
docEl || (docEl = window.document.documentElement);
|
|
10
|
+
const nextSize = {
|
|
11
|
+
fontScale: 1,
|
|
12
|
+
height: docEl.clientHeight,
|
|
13
|
+
scale: window.devicePixelRatio || 1,
|
|
14
|
+
width: docEl.clientWidth,
|
|
15
|
+
};
|
|
16
|
+
if (nextSize.height !== lastSize.height ||
|
|
17
|
+
nextSize.width !== lastSize.width ||
|
|
18
|
+
nextSize.scale !== lastSize.scale) {
|
|
19
|
+
lastSize = nextSize;
|
|
20
|
+
return nextSize;
|
|
21
|
+
}
|
|
22
|
+
return lastSize;
|
|
23
|
+
}
|
|
24
|
+
const cbs = new Set();
|
|
25
|
+
// only attach resize listener on client (not during SSR)
|
|
26
|
+
// also guard window.addEventListener since isClient=true on native but window.addEventListener is undefined
|
|
27
|
+
if (isClient &&
|
|
28
|
+
typeof window !== 'undefined' &&
|
|
29
|
+
typeof window.addEventListener === 'function') {
|
|
30
|
+
let lastUpdate = Date.now();
|
|
31
|
+
let tm;
|
|
32
|
+
const USER_MAX_MS = process.env.GUI_USE_WINDOW_DIMENSIONS_MAX_UPDATE_MS;
|
|
33
|
+
const updateMaxMs = USER_MAX_MS ? +USER_MAX_MS : 100;
|
|
34
|
+
function flushUpdate() {
|
|
35
|
+
lastUpdate = Date.now();
|
|
36
|
+
cbs.forEach((cb) => cb(getWindowSize()));
|
|
37
|
+
}
|
|
38
|
+
const onResize = () => {
|
|
39
|
+
clearTimeout(tm);
|
|
40
|
+
// only update every few frames
|
|
41
|
+
const timeSinceLast = Date.now() - lastUpdate;
|
|
42
|
+
if (timeSinceLast < updateMaxMs) {
|
|
43
|
+
tm = setTimeout(() => {
|
|
44
|
+
flushUpdate();
|
|
45
|
+
}, updateMaxMs - timeSinceLast);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
flushUpdate();
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
window.addEventListener('resize', onResize);
|
|
52
|
+
}
|
|
53
|
+
export function subscribe(cb) {
|
|
54
|
+
cbs.add(cb);
|
|
55
|
+
return () => cbs.delete(cb);
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAGhD,IAAI,QAAQ,GAAe,YAAY,CAAA;AACvC,IAAI,KAAK,GAAuB,IAAI,CAAA;AAEpC,MAAM,UAAU,aAAa;IAC3B,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,KAAK,KAAK,EAAE,CAAC;QACrC,OAAO,YAAY,CAAA;IACrB,CAAC;IAED,KAAK,KAAL,KAAK,GAAK,MAAM,CAAC,QAAQ,CAAC,eAAe,EAAA;IAEzC,MAAM,QAAQ,GAAe;QAC3B,SAAS,EAAE,CAAC;QACZ,MAAM,EAAE,KAAK,CAAC,YAAY;QAC1B,KAAK,EAAE,MAAM,CAAC,gBAAgB,IAAI,CAAC;QACnC,KAAK,EAAE,KAAK,CAAC,WAAW;KACzB,CAAA;IAED,IACE,QAAQ,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM;QACnC,QAAQ,CAAC,KAAK,KAAK,QAAQ,CAAC,KAAK;QACjC,QAAQ,CAAC,KAAK,KAAK,QAAQ,CAAC,KAAK,EACjC,CAAC;QACD,QAAQ,GAAG,QAAQ,CAAA;QACnB,OAAO,QAAQ,CAAA;IACjB,CAAC;IAED,OAAO,QAAQ,CAAA;AACjB,CAAC;AAED,MAAM,GAAG,GAAG,IAAI,GAAG,EAAsB,CAAA;AAEzC,yDAAyD;AACzD,4GAA4G;AAC5G,IACE,QAAQ;IACR,OAAO,MAAM,KAAK,WAAW;IAC7B,OAAO,MAAM,CAAC,gBAAgB,KAAK,UAAU,EAC7C,CAAC;IACD,IAAI,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;IAC3B,IAAI,EAA6C,CAAA;IACjD,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAA;IACvE,MAAM,WAAW,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAA;IAEpD,SAAS,WAAW;QAClB,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QACvB,GAAG,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,aAAa,EAAE,CAAC,CAAC,CAAA;IAC1C,CAAC;IAED,MAAM,QAAQ,GAAG,GAAG,EAAE;QACpB,YAAY,CAAC,EAAE,CAAC,CAAA;QAEhB,+BAA+B;QAC/B,MAAM,aAAa,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,UAAU,CAAA;QAC7C,IAAI,aAAa,GAAG,WAAW,EAAE,CAAC;YAChC,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE;gBACnB,WAAW,EAAE,CAAA;YACf,CAAC,EAAE,WAAW,GAAG,aAAa,CAAC,CAAA;QACjC,CAAC;aAAM,CAAC;YACN,WAAW,EAAE,CAAA;QACf,CAAC;IACH,CAAC,CAAA;IAED,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;AAC7C,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,EAAsB;IAC9C,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IACX,OAAO,GAAG,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;AAC7B,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import { isWeb } from
|
|
3
|
-
import { getWindowSize, subscribe } from
|
|
4
|
-
import { initialValue } from
|
|
5
|
-
|
|
6
|
-
function useWindowDimensions({
|
|
7
|
-
|
|
8
|
-
} = {}) {
|
|
9
|
-
return React.useSyncExternalStore(subscribe, getWindowSize, () => isWeb ? serverValue : getWindowSize());
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { isWeb } from '@hanzogui/constants';
|
|
3
|
+
import { getWindowSize, subscribe } from './helpers.js';
|
|
4
|
+
import { initialValue } from './initialValue.js';
|
|
5
|
+
export { configureInitialWindowDimensions } from './initialValue.js';
|
|
6
|
+
export function useWindowDimensions({ serverValue = initialValue, } = {}) {
|
|
7
|
+
return React.useSyncExternalStore(subscribe, getWindowSize, () => isWeb ? serverValue : getWindowSize());
|
|
10
8
|
}
|
|
11
|
-
|
|
12
|
-
//# sourceMappingURL=index.js.map
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAE3C,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAEvD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEhD,OAAO,EAAE,gCAAgC,EAAE,MAAM,mBAAmB,CAAA;AAEpE,MAAM,UAAU,mBAAmB,CAAC,EAClC,WAAW,GAAG,YAAY,GAC3B,GAAiC,EAAE;IAClC,OAAO,KAAK,CAAC,oBAAoB,CAAC,SAAS,EAAE,aAAa,EAAE,GAAG,EAAE,CAC/D,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,aAAa,EAAE,CACtC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SSR safe useWindowDimensions
|
|
3
|
+
*/
|
|
4
|
+
export const initialValue = {
|
|
5
|
+
width: 800,
|
|
6
|
+
height: 600,
|
|
7
|
+
scale: 1,
|
|
8
|
+
fontScale: 1,
|
|
9
|
+
};
|
|
10
|
+
export function configureInitialWindowDimensions(next) {
|
|
11
|
+
Object.assign(initialValue, next);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=initialValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initialValue.js","sourceRoot":"","sources":["../../src/initialValue.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAe;IACtC,KAAK,EAAE,GAAG;IACV,MAAM,EAAE,GAAG;IACX,KAAK,EAAE,CAAC;IACR,SAAS,EAAE,CAAC;CACb,CAAA;AAED,MAAM,UAAU,gCAAgC,CAAC,IAAgB;IAC/D,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,IAAI,CAAC,CAAA;AACnC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Dimensions } from 'react-native';
|
|
2
|
+
export function getWindowSize() {
|
|
3
|
+
return Dimensions.get('window');
|
|
4
|
+
}
|
|
5
|
+
const cbs = new Set();
|
|
6
|
+
let isListening = false;
|
|
7
|
+
const ensureListening = () => {
|
|
8
|
+
if (isListening)
|
|
9
|
+
return;
|
|
10
|
+
isListening = true;
|
|
11
|
+
// lazy-register: on Hermes, evaluating Dimensions.addEventListener at module
|
|
12
|
+
// top-level can fire before RN's Dimensions module finishes wiring up its
|
|
13
|
+
// event interface, throwing ReferenceError. Defer until first subscriber.
|
|
14
|
+
Dimensions.addEventListener('change', ({ window }) => {
|
|
15
|
+
cbs.forEach((cb) => cb(window));
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
export function subscribe(cb) {
|
|
19
|
+
ensureListening();
|
|
20
|
+
cbs.add(cb);
|
|
21
|
+
return () => cbs.delete(cb);
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.native.js","sourceRoot":"","sources":["../../src/helpers.native.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAGzC,MAAM,UAAU,aAAa;IAC3B,OAAO,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;AACjC,CAAC;AAED,MAAM,GAAG,GAAG,IAAI,GAAG,EAAsB,CAAA;AAEzC,IAAI,WAAW,GAAG,KAAK,CAAA;AACvB,MAAM,eAAe,GAAG,GAAG,EAAE;IAC3B,IAAI,WAAW;QAAE,OAAM;IACvB,WAAW,GAAG,IAAI,CAAA;IAClB,6EAA6E;IAC7E,0EAA0E;IAC1E,0EAA0E;IAC1E,UAAU,CAAC,gBAAgB,CAAC,QAAQ,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE;QACnD,GAAG,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAA;IACjC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,MAAM,UAAU,SAAS,CAAC,EAAsB;IAC9C,eAAe,EAAE,CAAA;IACjB,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IACX,OAAO,GAAG,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;AAC7B,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { isWeb } from '@hanzogui/constants';
|
|
3
|
+
import { getWindowSize, subscribe } from './helpers.js';
|
|
4
|
+
import { initialValue } from './initialValue.js';
|
|
5
|
+
export { configureInitialWindowDimensions } from './initialValue.js';
|
|
6
|
+
export function useWindowDimensions({ serverValue = initialValue, } = {}) {
|
|
7
|
+
return React.useSyncExternalStore(subscribe, getWindowSize, () => isWeb ? serverValue : getWindowSize());
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAE3C,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAEvD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEhD,OAAO,EAAE,gCAAgC,EAAE,MAAM,mBAAmB,CAAA;AAEpE,MAAM,UAAU,mBAAmB,CAAC,EAClC,WAAW,GAAG,YAAY,GAC3B,GAAiC,EAAE;IAClC,OAAO,KAAK,CAAC,oBAAoB,CAAC,SAAS,EAAE,aAAa,EAAE,GAAG,EAAE,CAC/D,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,aAAa,EAAE,CACtC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SSR safe useWindowDimensions
|
|
3
|
+
*/
|
|
4
|
+
export const initialValue = {
|
|
5
|
+
width: 800,
|
|
6
|
+
height: 600,
|
|
7
|
+
scale: 1,
|
|
8
|
+
fontScale: 1,
|
|
9
|
+
};
|
|
10
|
+
export function configureInitialWindowDimensions(next) {
|
|
11
|
+
Object.assign(initialValue, next);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=initialValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initialValue.js","sourceRoot":"","sources":["../../src/initialValue.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAe;IACtC,KAAK,EAAE,GAAG;IACV,MAAM,EAAE,GAAG;IACX,KAAK,EAAE,CAAC;IACR,SAAS,EAAE,CAAC;CACb,CAAA;AAED,MAAM,UAAU,gCAAgC,CAAC,IAAgB;IAC/D,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,IAAI,CAAC,CAAA;AACnC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hanzogui/use-window-dimensions",
|
|
3
|
-
"version": "8.3.
|
|
3
|
+
"version": "8.3.2",
|
|
4
4
|
"gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14",
|
|
5
5
|
"files": [
|
|
6
6
|
"src",
|
|
@@ -9,19 +9,19 @@
|
|
|
9
9
|
],
|
|
10
10
|
"type": "module",
|
|
11
11
|
"sideEffects": false,
|
|
12
|
-
"main": "dist/cjs",
|
|
13
|
-
"module": "dist/esm",
|
|
12
|
+
"main": "./dist/cjs/index.js",
|
|
13
|
+
"module": "./dist/esm/index.js",
|
|
14
14
|
"types": "./types/index.d.ts",
|
|
15
15
|
"exports": {
|
|
16
16
|
"./package.json": "./package.json",
|
|
17
17
|
".": {
|
|
18
18
|
"types": "./types/index.d.ts",
|
|
19
|
-
"react-native": "./dist/
|
|
20
|
-
"browser": "./dist/esm/index.
|
|
21
|
-
"module": "./dist/esm/index.
|
|
22
|
-
"import": "./dist/esm/index.
|
|
23
|
-
"require": "./dist/cjs/index.
|
|
24
|
-
"default": "./dist/esm/index.
|
|
19
|
+
"react-native": "./dist/native/index.js",
|
|
20
|
+
"browser": "./dist/esm/index.js",
|
|
21
|
+
"module": "./dist/esm/index.js",
|
|
22
|
+
"import": "./dist/esm/index.js",
|
|
23
|
+
"require": "./dist/cjs/index.js",
|
|
24
|
+
"default": "./dist/esm/index.js"
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
27
|
"publishConfig": {
|
|
@@ -34,15 +34,15 @@
|
|
|
34
34
|
"clean:build": "hanzogui-build clean:build"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@hanzogui/constants": "8.3.
|
|
37
|
+
"@hanzogui/constants": "8.3.2"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@hanzogui/build": "8.3.
|
|
41
|
-
"react": "
|
|
42
|
-
"react-native": "0.
|
|
40
|
+
"@hanzogui/build": "8.3.2",
|
|
41
|
+
"react": "19.2.8",
|
|
42
|
+
"react-native": "^0.87.1"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"react": ">=19"
|
|
45
|
+
"react": ">=19.2.8"
|
|
46
46
|
},
|
|
47
47
|
"repository": {
|
|
48
48
|
"type": "git",
|
package/src/helpers.native.ts
CHANGED
package/src/helpers.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isClient } from '@hanzogui/constants'
|
|
2
|
-
import { initialValue } from './initialValue'
|
|
3
|
-
import type { WindowSize, WindowSizeListener } from './types'
|
|
2
|
+
import { initialValue } from './initialValue.ts'
|
|
3
|
+
import type { WindowSize, WindowSizeListener } from './types.ts'
|
|
4
4
|
|
|
5
5
|
let lastSize: WindowSize = initialValue
|
|
6
6
|
let docEl: HTMLElement | null = null
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import { isWeb } from '@hanzogui/constants'
|
|
3
3
|
|
|
4
|
-
import { getWindowSize, subscribe } from './helpers'
|
|
5
|
-
import type { WindowSize } from './types'
|
|
6
|
-
import { initialValue } from './initialValue'
|
|
4
|
+
import { getWindowSize, subscribe } from './helpers.ts'
|
|
5
|
+
import type { WindowSize } from './types.ts'
|
|
6
|
+
import { initialValue } from './initialValue.ts'
|
|
7
7
|
|
|
8
|
-
export { configureInitialWindowDimensions } from './initialValue'
|
|
8
|
+
export { configureInitialWindowDimensions } from './initialValue.ts'
|
|
9
9
|
|
|
10
10
|
export function useWindowDimensions({
|
|
11
11
|
serverValue = initialValue,
|
package/src/initialValue.ts
CHANGED
package/types/helpers.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { WindowSize, WindowSizeListener } from
|
|
1
|
+
import type { WindowSize, WindowSizeListener } from './types.ts';
|
|
2
2
|
export declare function getWindowSize(): WindowSize;
|
|
3
3
|
export declare function subscribe(cb: WindowSizeListener): () => void;
|
|
4
|
-
|
|
5
4
|
//# sourceMappingURL=helpers.d.ts.map
|
package/types/helpers.d.ts.map
CHANGED
|
@@ -1,11 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"mappings": "AAEA,cAAc,YAAY,0BAA0B;AAKpD,OAAO,iBAAS,iBAAiB;AA8DjC,OAAO,iBAAS,UAAU,IAAI",
|
|
3
|
-
"names": [],
|
|
4
|
-
"sources": [
|
|
5
|
-
"src/helpers.ts"
|
|
6
|
-
],
|
|
7
|
-
"version": 3,
|
|
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.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
|
-
]
|
|
11
|
-
}
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAKhE,wBAAgB,aAAa,IAAI,UAAU,CAwB1C;AAsCD,wBAAgB,SAAS,CAAC,EAAE,EAAE,kBAAkB,GAAG,MAAM,IAAI,CAG5D"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { WindowSize, WindowSizeListener } from
|
|
1
|
+
import type { WindowSize, WindowSizeListener } from './types.ts';
|
|
2
2
|
export declare function getWindowSize(): WindowSize;
|
|
3
3
|
export declare function subscribe(cb: WindowSizeListener): () => void;
|
|
4
|
-
|
|
5
4
|
//# sourceMappingURL=helpers.native.d.ts.map
|
|
@@ -1,11 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"mappings": "AACA,cAAc,YAAY,0BAA0B;AAEpD,OAAO,iBAAS,iBAAiB;AAkBjC,OAAO,iBAAS,UAAU,IAAI",
|
|
3
|
-
"names": [],
|
|
4
|
-
"sources": [
|
|
5
|
-
"src/helpers.native.ts"
|
|
6
|
-
],
|
|
7
|
-
"version": 3,
|
|
8
|
-
"sourcesContent": [
|
|
9
|
-
"import { Dimensions } from 'react-native'\nimport type { WindowSize, WindowSizeListener } from './types'\n\nexport function getWindowSize(): WindowSize {\n return Dimensions.get('window')\n}\n\nconst cbs = new Set<WindowSizeListener>()\n\nlet isListening = false\nconst ensureListening = () => {\n if (isListening) return\n isListening = true\n // lazy-register: on Hermes, evaluating Dimensions.addEventListener at module\n // top-level can fire before RN's Dimensions module finishes wiring up its\n // event interface, throwing ReferenceError. Defer until first subscriber.\n Dimensions.addEventListener('change', ({ window }) => {\n cbs.forEach((cb) => cb(window))\n })\n}\n\nexport function subscribe(cb: WindowSizeListener): () => void {\n ensureListening()\n cbs.add(cb)\n return () => cbs.delete(cb)\n}\n"
|
|
10
|
-
]
|
|
11
|
-
}
|
|
1
|
+
{"version":3,"file":"helpers.native.d.ts","sourceRoot":"","sources":["../src/helpers.native.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAEhE,wBAAgB,aAAa,IAAI,UAAU,CAE1C;AAgBD,wBAAgB,SAAS,CAAC,EAAE,EAAE,kBAAkB,GAAG,MAAM,IAAI,CAI5D"}
|
package/types/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { WindowSize } from
|
|
2
|
-
export { configureInitialWindowDimensions } from
|
|
3
|
-
export declare function useWindowDimensions({ serverValue }?: {
|
|
4
|
-
|
|
1
|
+
import type { WindowSize } from './types.ts';
|
|
2
|
+
export { configureInitialWindowDimensions } from './initialValue.ts';
|
|
3
|
+
export declare function useWindowDimensions({ serverValue, }?: {
|
|
4
|
+
serverValue?: WindowSize;
|
|
5
5
|
}): WindowSize;
|
|
6
|
-
|
|
7
6
|
//# sourceMappingURL=index.d.ts.map
|
package/types/index.d.ts.map
CHANGED
|
@@ -1,11 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"mappings": "AAIA,cAAc,kBAAkB;AAGhC,SAAS,wCAAwC;AAEjD,OAAO,iBAAS,oBAAoB,EAClC,gBACC;CAAE,cAAc;IAAoB",
|
|
3
|
-
"names": [],
|
|
4
|
-
"sources": [
|
|
5
|
-
"src/index.ts"
|
|
6
|
-
],
|
|
7
|
-
"version": 3,
|
|
8
|
-
"sourcesContent": [
|
|
9
|
-
"import React from 'react'\nimport { isWeb } from '@hanzogui/constants'\n\nimport { getWindowSize, subscribe } from './helpers'\nimport type { WindowSize } from './types'\nimport { initialValue } from './initialValue'\n\nexport { configureInitialWindowDimensions } from './initialValue'\n\nexport function useWindowDimensions({\n serverValue = initialValue,\n}: { serverValue?: WindowSize } = {}): WindowSize {\n return React.useSyncExternalStore(subscribe, getWindowSize, () =>\n isWeb ? serverValue : getWindowSize()\n )\n}\n"
|
|
10
|
-
]
|
|
11
|
-
}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAG5C,OAAO,EAAE,gCAAgC,EAAE,MAAM,mBAAmB,CAAA;AAEpE,wBAAgB,mBAAmB,CAAC,EAClC,WAA0B,GAC3B,GAAE;IAAE,WAAW,CAAC,EAAE,UAAU,CAAA;CAAO,GAAG,UAAU,CAIhD"}
|
package/types/initialValue.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { WindowSize } from
|
|
1
|
+
import type { WindowSize } from './types.ts';
|
|
2
2
|
/**
|
|
3
|
-
* SSR safe useWindowDimensions
|
|
4
|
-
*/
|
|
3
|
+
* SSR safe useWindowDimensions
|
|
4
|
+
*/
|
|
5
5
|
export declare const initialValue: WindowSize;
|
|
6
6
|
export declare function configureInitialWindowDimensions(next: WindowSize): void;
|
|
7
|
-
|
|
8
7
|
//# sourceMappingURL=initialValue.d.ts.map
|
|
@@ -1,11 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"mappings": "AAAA,cAAc,kBAAkB;;;;AAKhC,OAAO,cAAM,cAAc;AAO3B,OAAO,iBAAS,iCAAiC,MAAM",
|
|
3
|
-
"names": [],
|
|
4
|
-
"sources": [
|
|
5
|
-
"src/initialValue.ts"
|
|
6
|
-
],
|
|
7
|
-
"version": 3,
|
|
8
|
-
"sourcesContent": [
|
|
9
|
-
"import type { WindowSize } from './types'\n\n/**\n * SSR safe useWindowDimensions\n */\nexport const initialValue: WindowSize = {\n width: 800,\n height: 600,\n scale: 1,\n fontScale: 1,\n}\n\nexport function configureInitialWindowDimensions(next: WindowSize): void {\n Object.assign(initialValue, next)\n}\n"
|
|
10
|
-
]
|
|
11
|
-
}
|
|
1
|
+
{"version":3,"file":"initialValue.d.ts","sourceRoot":"","sources":["../src/initialValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE5C;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,UAK1B,CAAA;AAED,wBAAgB,gCAAgC,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAEvE"}
|
package/types/types.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import type { ScaledSize } from
|
|
1
|
+
import type { ScaledSize } from 'react-native';
|
|
2
2
|
export type Size = {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
width: number;
|
|
4
|
+
height: number;
|
|
5
5
|
};
|
|
6
6
|
export type WindowSize = ScaledSize;
|
|
7
7
|
export type WindowSizeListener = (size: WindowSize) => void;
|
|
8
|
-
|
|
9
8
|
//# sourceMappingURL=types.d.ts.map
|
package/types/types.d.ts.map
CHANGED
|
@@ -1,11 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"mappings": "AAAA,cAAc,kBAAkB;AAEhC,YAAY,OAAO;CACjB;CACA;;AAGF,YAAY,aAAa;AAEzB,YAAY,sBAAsB,MAAM",
|
|
3
|
-
"names": [],
|
|
4
|
-
"sources": [
|
|
5
|
-
"src/types.ts"
|
|
6
|
-
],
|
|
7
|
-
"version": 3,
|
|
8
|
-
"sourcesContent": [
|
|
9
|
-
"import type { ScaledSize } from 'react-native'\n\nexport type Size = {\n width: number\n height: number\n}\n\nexport type WindowSize = ScaledSize\n\nexport type WindowSizeListener = (size: WindowSize) => void\n"
|
|
10
|
-
]
|
|
11
|
-
}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAE9C,MAAM,MAAM,IAAI,GAAG;IACjB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED,MAAM,MAAM,UAAU,GAAG,UAAU,CAAA;AAEnC,MAAM,MAAM,kBAAkB,GAAG,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAA"}
|
package/dist/cjs/helpers.cjs
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
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, {
|
|
14
|
-
get: () => from[key],
|
|
15
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
-
value: true
|
|
22
|
-
}), mod);
|
|
23
|
-
var helpers_exports = {};
|
|
24
|
-
__export(helpers_exports, {
|
|
25
|
-
getWindowSize: () => getWindowSize,
|
|
26
|
-
subscribe: () => subscribe
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(helpers_exports);
|
|
29
|
-
var import_constants = require("@hanzogui/constants");
|
|
30
|
-
let lastSize = require("./initialValue.cjs").initialValue;
|
|
31
|
-
let docEl = null;
|
|
32
|
-
function getWindowSize() {
|
|
33
|
-
docEl ||= window.document.documentElement;
|
|
34
|
-
const nextSize = {
|
|
35
|
-
fontScale: 1,
|
|
36
|
-
height: docEl.clientHeight,
|
|
37
|
-
scale: window.devicePixelRatio || 1,
|
|
38
|
-
width: docEl.clientWidth
|
|
39
|
-
};
|
|
40
|
-
if (nextSize.height !== lastSize.height || nextSize.width !== lastSize.width || nextSize.scale !== lastSize.scale) {
|
|
41
|
-
lastSize = nextSize;
|
|
42
|
-
return nextSize;
|
|
43
|
-
}
|
|
44
|
-
return lastSize;
|
|
45
|
-
}
|
|
46
|
-
const cbs = /* @__PURE__ */new Set();
|
|
47
|
-
if (import_constants.isClient && typeof window !== "undefined" && typeof window.addEventListener === "function") {
|
|
48
|
-
let flushUpdate = function () {
|
|
49
|
-
lastUpdate = Date.now();
|
|
50
|
-
cbs.forEach(cb => cb(getWindowSize()));
|
|
51
|
-
};
|
|
52
|
-
let lastUpdate = Date.now();
|
|
53
|
-
let tm;
|
|
54
|
-
const USER_MAX_MS = process.env.GUI_USE_WINDOW_DIMENSIONS_MAX_UPDATE_MS;
|
|
55
|
-
const updateMaxMs = USER_MAX_MS ? +USER_MAX_MS : 100;
|
|
56
|
-
const onResize = () => {
|
|
57
|
-
clearTimeout(tm);
|
|
58
|
-
const timeSinceLast = Date.now() - lastUpdate;
|
|
59
|
-
if (timeSinceLast < updateMaxMs) tm = setTimeout(() => {
|
|
60
|
-
flushUpdate();
|
|
61
|
-
}, updateMaxMs - timeSinceLast);else flushUpdate();
|
|
62
|
-
};
|
|
63
|
-
window.addEventListener("resize", onResize);
|
|
64
|
-
}
|
|
65
|
-
function subscribe(cb) {
|
|
66
|
-
cbs.add(cb);
|
|
67
|
-
return () => cbs.delete(cb);
|
|
68
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
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, {
|
|
16
|
-
get: () => from[key],
|
|
17
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
23
|
-
value: true
|
|
24
|
-
}), mod);
|
|
25
|
-
var helpers_native_exports = {};
|
|
26
|
-
__export(helpers_native_exports, {
|
|
27
|
-
getWindowSize: () => getWindowSize,
|
|
28
|
-
subscribe: () => subscribe
|
|
29
|
-
});
|
|
30
|
-
module.exports = __toCommonJS(helpers_native_exports);
|
|
31
|
-
var import_react_native = require("react-native");
|
|
32
|
-
function getWindowSize() {
|
|
33
|
-
return import_react_native.Dimensions.get("window");
|
|
34
|
-
}
|
|
35
|
-
var cbs = /* @__PURE__ */new Set();
|
|
36
|
-
var isListening = false;
|
|
37
|
-
var ensureListening = function () {
|
|
38
|
-
if (isListening) return;
|
|
39
|
-
isListening = true;
|
|
40
|
-
import_react_native.Dimensions.addEventListener("change", function (param) {
|
|
41
|
-
var {
|
|
42
|
-
window
|
|
43
|
-
} = param;
|
|
44
|
-
cbs.forEach(function (cb) {
|
|
45
|
-
return cb(window);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
function subscribe(cb) {
|
|
50
|
-
ensureListening();
|
|
51
|
-
cbs.add(cb);
|
|
52
|
-
return function () {
|
|
53
|
-
return cbs.delete(cb);
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
//# sourceMappingURL=helpers.native.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["helpers_native_exports","__export","getWindowSize","subscribe","module","exports","__toCommonJS","import_react_native","require","Dimensions","get","cbs","Set","isListening","ensureListening","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;AAClB,IAAIC,WAAA,GAAc;AAClB,IAAIC,eAAA,GAAkB,SAAAA,CAAA,EAAW;EAC7B,IAAID,WAAA,EAAa;EACjBA,WAAA,GAAc;EAIdN,mBAAA,CAAAE,UAAA,CAAWM,gBAAA,CAAiB,UAAU,UAASC,KAAA,EAAO;IAClD,IAAI;MAAEC;IAAO,IAAID,KAAA;IACjBL,GAAA,CAAIO,OAAA,CAAQ,UAASC,EAAA,EAAI;MACrB,OAAOA,EAAA,CAAGF,MAAM;IACpB,CAAC;EACL,CAAC;AACL;AACO,SAASd,UAAUgB,EAAA,EAAI;EAC1BL,eAAA,CAAgB;EAChBH,GAAA,CAAIS,GAAA,CAAID,EAAE;EACV,OAAO,YAAW;IACd,OAAOR,GAAA,CAAIU,MAAA,CAAOF,EAAE;EACxB;AACJ","ignoreList":[]}
|
package/dist/cjs/index.cjs
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
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, {
|
|
16
|
-
get: () => from[key],
|
|
17
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
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);
|
|
34
|
-
var index_exports = {};
|
|
35
|
-
__export(index_exports, {
|
|
36
|
-
configureInitialWindowDimensions: () => import_initialValue2.configureInitialWindowDimensions,
|
|
37
|
-
useWindowDimensions: () => useWindowDimensions
|
|
38
|
-
});
|
|
39
|
-
module.exports = __toCommonJS(index_exports);
|
|
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");
|
|
45
|
-
function useWindowDimensions({
|
|
46
|
-
serverValue = import_initialValue.initialValue
|
|
47
|
-
} = {}) {
|
|
48
|
-
return import_react.default.useSyncExternalStore(import_helpers.subscribe, import_helpers.getWindowSize, () => import_constants.isWeb ? serverValue : (0, import_helpers.getWindowSize)());
|
|
49
|
-
}
|
package/dist/cjs/index.native.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __export = (target, all) => {
|
|
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, {
|
|
18
|
-
get: () => from[key],
|
|
19
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
return to;
|
|
23
|
-
};
|
|
24
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
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);
|
|
36
|
-
var index_exports = {};
|
|
37
|
-
__export(index_exports, {
|
|
38
|
-
configureInitialWindowDimensions: () => import_initialValue2.configureInitialWindowDimensions,
|
|
39
|
-
useWindowDimensions: () => useWindowDimensions
|
|
40
|
-
});
|
|
41
|
-
module.exports = __toCommonJS(index_exports);
|
|
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");
|
|
47
|
-
function useWindowDimensions() {
|
|
48
|
-
var {
|
|
49
|
-
serverValue = import_initialValue.initialValue
|
|
50
|
-
} = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
51
|
-
return import_react.default.useSyncExternalStore(import_helpers.subscribe, import_helpers.getWindowSize, function () {
|
|
52
|
-
return import_constants.isWeb ? serverValue : (0, import_helpers.getWindowSize)();
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
//# sourceMappingURL=index.native.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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":[]}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
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, {
|
|
14
|
-
get: () => from[key],
|
|
15
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
-
value: true
|
|
22
|
-
}), mod);
|
|
23
|
-
var initialValue_exports = {};
|
|
24
|
-
__export(initialValue_exports, {
|
|
25
|
-
configureInitialWindowDimensions: () => configureInitialWindowDimensions,
|
|
26
|
-
initialValue: () => initialValue
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(initialValue_exports);
|
|
29
|
-
const initialValue = {
|
|
30
|
-
width: 800,
|
|
31
|
-
height: 600,
|
|
32
|
-
scale: 1,
|
|
33
|
-
fontScale: 1
|
|
34
|
-
};
|
|
35
|
-
function configureInitialWindowDimensions(next) {
|
|
36
|
-
Object.assign(initialValue, next);
|
|
37
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
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, {
|
|
16
|
-
get: () => from[key],
|
|
17
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
23
|
-
value: true
|
|
24
|
-
}), mod);
|
|
25
|
-
var initialValue_exports = {};
|
|
26
|
-
__export(initialValue_exports, {
|
|
27
|
-
configureInitialWindowDimensions: () => configureInitialWindowDimensions,
|
|
28
|
-
initialValue: () => initialValue
|
|
29
|
-
});
|
|
30
|
-
module.exports = __toCommonJS(initialValue_exports);
|
|
31
|
-
var initialValue = {
|
|
32
|
-
width: 800,
|
|
33
|
-
height: 600,
|
|
34
|
-
scale: 1,
|
|
35
|
-
fontScale: 1
|
|
36
|
-
};
|
|
37
|
-
function configureInitialWindowDimensions(next) {
|
|
38
|
-
Object.assign(initialValue, next);
|
|
39
|
-
}
|
|
40
|
-
//# sourceMappingURL=initialValue.native.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __copyProps = (to, from, except, desc) => {
|
|
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
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
15
|
-
value: true
|
|
16
|
-
}), mod);
|
|
17
|
-
var types_exports = {};
|
|
18
|
-
module.exports = __toCommonJS(types_exports);
|
package/dist/cjs/types.native.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __copyProps = (to, from, except, desc) => {
|
|
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
|
-
}
|
|
14
|
-
return to;
|
|
15
|
-
};
|
|
16
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
17
|
-
value: true
|
|
18
|
-
}), mod);
|
|
19
|
-
var types_exports = {};
|
|
20
|
-
module.exports = __toCommonJS(types_exports);
|
|
21
|
-
//# sourceMappingURL=types.native.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { isClient } from "@hanzogui/constants";
|
|
2
|
-
import { initialValue } from "./initialValue.mjs";
|
|
3
|
-
let lastSize = initialValue;
|
|
4
|
-
let docEl = null;
|
|
5
|
-
function getWindowSize() {
|
|
6
|
-
docEl ||= window.document.documentElement;
|
|
7
|
-
const nextSize = {
|
|
8
|
-
fontScale: 1,
|
|
9
|
-
height: docEl.clientHeight,
|
|
10
|
-
scale: window.devicePixelRatio || 1,
|
|
11
|
-
width: docEl.clientWidth
|
|
12
|
-
};
|
|
13
|
-
if (nextSize.height !== lastSize.height || nextSize.width !== lastSize.width || nextSize.scale !== lastSize.scale) {
|
|
14
|
-
lastSize = nextSize;
|
|
15
|
-
return nextSize;
|
|
16
|
-
}
|
|
17
|
-
return lastSize;
|
|
18
|
-
}
|
|
19
|
-
const cbs = /* @__PURE__ */new Set();
|
|
20
|
-
if (isClient && typeof window !== "undefined" && typeof window.addEventListener === "function") {
|
|
21
|
-
let flushUpdate = function () {
|
|
22
|
-
lastUpdate = Date.now();
|
|
23
|
-
cbs.forEach(cb => cb(getWindowSize()));
|
|
24
|
-
};
|
|
25
|
-
let lastUpdate = Date.now();
|
|
26
|
-
let tm;
|
|
27
|
-
const USER_MAX_MS = process.env.GUI_USE_WINDOW_DIMENSIONS_MAX_UPDATE_MS;
|
|
28
|
-
const updateMaxMs = USER_MAX_MS ? +USER_MAX_MS : 100;
|
|
29
|
-
const onResize = () => {
|
|
30
|
-
clearTimeout(tm);
|
|
31
|
-
const timeSinceLast = Date.now() - lastUpdate;
|
|
32
|
-
if (timeSinceLast < updateMaxMs) tm = setTimeout(() => {
|
|
33
|
-
flushUpdate();
|
|
34
|
-
}, updateMaxMs - timeSinceLast);else flushUpdate();
|
|
35
|
-
};
|
|
36
|
-
window.addEventListener("resize", onResize);
|
|
37
|
-
}
|
|
38
|
-
function subscribe(cb) {
|
|
39
|
-
cbs.add(cb);
|
|
40
|
-
return () => cbs.delete(cb);
|
|
41
|
-
}
|
|
42
|
-
export { getWindowSize, subscribe };
|
|
43
|
-
//# sourceMappingURL=helpers.mjs.map
|
package/dist/esm/helpers.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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":["helpers.mjs"],"sourcesContent":["import { isClient } from \"@hanzogui/constants\";\nimport { initialValue } from \"./initialValue\";\n\nlet lastSize = initialValue;\nlet docEl = null;\nfunction getWindowSize() {\n\tdocEl ||= window.document.documentElement;\n\tconst nextSize = {\n\t\tfontScale: 1,\n\t\theight: docEl.clientHeight,\n\t\tscale: window.devicePixelRatio || 1,\n\t\twidth: docEl.clientWidth\n\t};\n\tif (nextSize.height !== lastSize.height || nextSize.width !== lastSize.width || nextSize.scale !== lastSize.scale) {\n\t\tlastSize = nextSize;\n\t\treturn nextSize;\n\t}\n\treturn lastSize;\n}\nconst cbs = /* @__PURE__ */ new Set();\nif (isClient && typeof window !== \"undefined\" && typeof window.addEventListener === \"function\") {\n\tlet flushUpdate = function() {\n\t\tlastUpdate = Date.now();\n\t\tcbs.forEach((cb) => cb(getWindowSize()));\n\t};\n\tlet lastUpdate = Date.now();\n\tlet tm;\n\tconst USER_MAX_MS = process.env.GUI_USE_WINDOW_DIMENSIONS_MAX_UPDATE_MS;\n\tconst updateMaxMs = USER_MAX_MS ? +USER_MAX_MS : 100;\n\tconst onResize = () => {\n\t\tclearTimeout(tm);\n\t\tconst timeSinceLast = Date.now() - lastUpdate;\n\t\tif (timeSinceLast < updateMaxMs) tm = setTimeout(() => {\n\t\t\tflushUpdate();\n\t\t}, updateMaxMs - timeSinceLast);\n\t\telse flushUpdate();\n\t};\n\twindow.addEventListener(\"resize\", onResize);\n}\nfunction subscribe(cb) {\n\tcbs.add(cb);\n\treturn () => cbs.delete(cb);\n}\n\nexport { getWindowSize, subscribe };"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,qBAAqB;AAC9C,SAASC,YAAY,QAAQ,oBAAgB;AAE7C,IAAIC,QAAQ,GAAGD,YAAY;AAC3B,IAAIE,KAAK,GAAG,IAAI;AAChB,SAASC,aAAaA,CAAA,EAAG;EACxBD,KAAK,KAAKE,MAAM,CAACC,QAAQ,CAACC,eAAe;EACzC,MAAMC,QAAQ,GAAG;IAChBC,SAAS,EAAE,CAAC;IACZC,MAAM,EAAEP,KAAK,CAACQ,YAAY;IAC1BC,KAAK,EAAEP,MAAM,CAACQ,gBAAgB,IAAI,CAAC;IACnCC,KAAK,EAAEX,KAAK,CAACY;EACd,CAAC;EACD,IAAIP,QAAQ,CAACE,MAAM,KAAKR,QAAQ,CAACQ,MAAM,IAAIF,QAAQ,CAACM,KAAK,KAAKZ,QAAQ,CAACY,KAAK,IAAIN,QAAQ,CAACI,KAAK,KAAKV,QAAQ,CAACU,KAAK,EAAE;IAClHV,QAAQ,GAAGM,QAAQ;IACnB,OAAOA,QAAQ;EAChB;EACA,OAAON,QAAQ;AAChB;AACA,MAAMc,GAAG,GAAG,eAAgB,IAAIC,GAAG,CAAC,CAAC;AACrC,IAAIjB,QAAQ,IAAI,OAAOK,MAAM,KAAK,WAAW,IAAI,OAAOA,MAAM,CAACa,gBAAgB,KAAK,UAAU,EAAE;EAC/F,IAAIC,WAAW,GAAG,SAAAA,CAAA,EAAW;IAC5BC,UAAU,GAAGC,IAAI,CAACC,GAAG,CAAC,CAAC;IACvBN,GAAG,CAACO,OAAO,CAAEC,EAAE,IAAKA,EAAE,CAACpB,aAAa,CAAC,CAAC,CAAC,CAAC;EACzC,CAAC;EACD,IAAIgB,UAAU,GAAGC,IAAI,CAACC,GAAG,CAAC,CAAC;EAC3B,IAAIG,EAAE;EACN,MAAMC,WAAW,GAAGC,OAAO,CAACC,GAAG,CAACC,uCAAuC;EACvE,MAAMC,WAAW,GAAGJ,WAAW,GAAG,CAACA,WAAW,GAAG,GAAG;EACpD,MAAMK,QAAQ,GAAGA,CAAA,KAAM;IACtBC,YAAY,CAACP,EAAE,CAAC;IAChB,MAAMQ,aAAa,GAAGZ,IAAI,CAACC,GAAG,CAAC,CAAC,GAAGF,UAAU;IAC7C,IAAIa,aAAa,GAAGH,WAAW,EAAEL,EAAE,GAAGS,UAAU,CAAC,MAAM;MACtDf,WAAW,CAAC,CAAC;IACd,CAAC,EAAEW,WAAW,GAAGG,aAAa,CAAC,CAAC,KAC3Bd,WAAW,CAAC,CAAC;EACnB,CAAC;EACDd,MAAM,CAACa,gBAAgB,CAAC,QAAQ,EAAEa,QAAQ,CAAC;AAC5C;AACA,SAASI,SAASA,CAACX,EAAE,EAAE;EACtBR,GAAG,CAACoB,GAAG,CAACZ,EAAE,CAAC;EACX,OAAO,MAAMR,GAAG,CAACqB,MAAM,CAACb,EAAE,CAAC;AAC5B;AAEA,SAASpB,aAAa,EAAE+B,SAAS","ignoreList":[]}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Dimensions } from "react-native";
|
|
2
|
-
function getWindowSize() {
|
|
3
|
-
return Dimensions.get("window");
|
|
4
|
-
}
|
|
5
|
-
var cbs = /* @__PURE__ */new Set();
|
|
6
|
-
var isListening = false;
|
|
7
|
-
var ensureListening = function () {
|
|
8
|
-
if (isListening) return;
|
|
9
|
-
isListening = true;
|
|
10
|
-
Dimensions.addEventListener("change", function (param) {
|
|
11
|
-
var {
|
|
12
|
-
window
|
|
13
|
-
} = param;
|
|
14
|
-
cbs.forEach(function (cb) {
|
|
15
|
-
return cb(window);
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
function subscribe(cb) {
|
|
20
|
-
ensureListening();
|
|
21
|
-
cbs.add(cb);
|
|
22
|
-
return function () {
|
|
23
|
-
return cbs.delete(cb);
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
export { getWindowSize, subscribe };
|
|
27
|
-
//# sourceMappingURL=helpers.native.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["Dimensions","getWindowSize","get","cbs","Set","isListening","ensureListening","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;AAClB,IAAIC,WAAA,GAAc;AAClB,IAAIC,eAAA,GAAkB,SAAAA,CAAA,EAAW;EAC7B,IAAID,WAAA,EAAa;EACjBA,WAAA,GAAc;EAIdL,UAAA,CAAWO,gBAAA,CAAiB,UAAU,UAASC,KAAA,EAAO;IAClD,IAAI;MAAEC;IAAO,IAAID,KAAA;IACjBL,GAAA,CAAIO,OAAA,CAAQ,UAASC,EAAA,EAAI;MACrB,OAAOA,EAAA,CAAGF,MAAM;IACpB,CAAC;EACL,CAAC;AACL;AACO,SAASG,UAAUD,EAAA,EAAI;EAC1BL,eAAA,CAAgB;EAChBH,GAAA,CAAIU,GAAA,CAAIF,EAAE;EACV,OAAO,YAAW;IACd,OAAOR,GAAA,CAAIW,MAAA,CAAOH,EAAE;EACxB;AACJ","ignoreList":[]}
|
package/dist/esm/index.mjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { isWeb } from "@hanzogui/constants";
|
|
3
|
-
import { getWindowSize, subscribe } from "./helpers.mjs";
|
|
4
|
-
import { initialValue } from "./initialValue.mjs";
|
|
5
|
-
import { configureInitialWindowDimensions } from "./initialValue.mjs";
|
|
6
|
-
function useWindowDimensions({
|
|
7
|
-
serverValue = initialValue
|
|
8
|
-
} = {}) {
|
|
9
|
-
return React.useSyncExternalStore(subscribe, getWindowSize, () => isWeb ? serverValue : getWindowSize());
|
|
10
|
-
}
|
|
11
|
-
export { configureInitialWindowDimensions, useWindowDimensions };
|
|
12
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["React","isWeb","getWindowSize","subscribe","initialValue","configureInitialWindowDimensions","useWindowDimensions","serverValue","useSyncExternalStore"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,OAAOA,KAAA,MAAW;AAClB,SAASC,KAAA,QAAa;AAEtB,SAASC,aAAA,EAAeC,SAAA,QAAiB;AAEzC,SAASC,YAAA,QAAoB;AAE7B,SAASC,gCAAA,QAAwC;AAE1C,SAASC,oBAAoB;EAClCC,WAAA,GAAcH;AAChB,IAAkC,CAAC,GAAe;EAChD,OAAOJ,KAAA,CAAMQ,oBAAA,CAAqBL,SAAA,EAAWD,aAAA,EAAe,MAC1DD,KAAA,GAAQM,WAAA,GAAcL,aAAA,CAAc,CACtC;AACF","ignoreList":[]}
|
package/dist/esm/index.native.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { isWeb } from "@hanzogui/constants";
|
|
3
|
-
import { getWindowSize, subscribe } from "./helpers.native.js";
|
|
4
|
-
import { initialValue } from "./initialValue.native.js";
|
|
5
|
-
import { configureInitialWindowDimensions } from "./initialValue.native.js";
|
|
6
|
-
function useWindowDimensions() {
|
|
7
|
-
var {
|
|
8
|
-
serverValue = initialValue
|
|
9
|
-
} = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
10
|
-
return React.useSyncExternalStore(subscribe, getWindowSize, function () {
|
|
11
|
-
return isWeb ? serverValue : getWindowSize();
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
export { configureInitialWindowDimensions, useWindowDimensions };
|
|
15
|
-
//# sourceMappingURL=index.native.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["React","isWeb","getWindowSize","subscribe","initialValue","configureInitialWindowDimensions","useWindowDimensions","serverValue","arguments","length","useSyncExternalStore"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,OAAOA,KAAA,MAAW;AAClB,SAASC,KAAA,QAAa;AAEtB,SAASC,aAAA,EAAeC,SAAA,QAAiB;AAEzC,SAASC,YAAA,QAAoB;AAE7B,SAASC,gCAAA,QAAwC;AAE1C,SAASC,oBAAA,EAAoB;EAClC;IAAAC,WAAc,GAAAH;EAAA,IAAAI,SAAA,CAAAC,MAAA,QAAAD,SAAA,iBAAAA,SAAA;EAChB,OAAkDR,KAAA,CAAAU,oBAAA,CAAAP,SAAA,EAAAD,aAAA;IAChD,OAAOD,KAAM,GAAAM,WAAA,GAAAL,aAAA;EAAA,EAAqB;AAAA;AAAW,SAE7CG,gCAAA,EACFC,mBAAA","ignoreList":[]}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const initialValue = {
|
|
2
|
-
width: 800,
|
|
3
|
-
height: 600,
|
|
4
|
-
scale: 1,
|
|
5
|
-
fontScale: 1
|
|
6
|
-
};
|
|
7
|
-
function configureInitialWindowDimensions(next) {
|
|
8
|
-
Object.assign(initialValue, next);
|
|
9
|
-
}
|
|
10
|
-
export { configureInitialWindowDimensions, initialValue };
|
|
11
|
-
//# sourceMappingURL=initialValue.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["initialValue","width","height","scale","fontScale","configureInitialWindowDimensions","next","Object","assign"],"sources":["../../src/initialValue.ts"],"sourcesContent":[null],"mappings":"AAKO,MAAMA,YAAA,GAA2B;EACtCC,KAAA,EAAO;EACPC,MAAA,EAAQ;EACRC,KAAA,EAAO;EACPC,SAAA,EAAW;AACb;AAEO,SAASC,iCAAiCC,IAAA,EAAwB;EACvEC,MAAA,CAAOC,MAAA,CAAOR,YAAA,EAAcM,IAAI;AAClC","ignoreList":[]}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
var initialValue = {
|
|
2
|
-
width: 800,
|
|
3
|
-
height: 600,
|
|
4
|
-
scale: 1,
|
|
5
|
-
fontScale: 1
|
|
6
|
-
};
|
|
7
|
-
function configureInitialWindowDimensions(next) {
|
|
8
|
-
Object.assign(initialValue, next);
|
|
9
|
-
}
|
|
10
|
-
export { configureInitialWindowDimensions, initialValue };
|
|
11
|
-
//# sourceMappingURL=initialValue.native.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["initialValue","width","height","scale","fontScale","configureInitialWindowDimensions","next","Object","assign"],"sources":["../../src/initialValue.ts"],"sourcesContent":[null],"mappings":"AAKO,IAAAA,YAAM;EACXC,KAAA,EAAO;EACPC,MAAA,EAAQ;EACRC,KAAA,EAAO;EACPC,SAAA,EAAW;AACb;AAEO,SAASC,iCAAiCC,IAAA,EAAwB;EACvEC,MAAA,CAAOC,MAAA,CAAOR,YAAA,EAAcM,IAAI;AAClC","ignoreList":[]}
|
package/dist/esm/types.mjs
DELETED
package/dist/esm/types.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":[],"sourcesContent":[],"mappings":"","ignoreList":[]}
|
package/dist/esm/types.native.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":[],"sourcesContent":[],"mappings":"","ignoreList":[]}
|