@hanzogui/use-window-dimensions 2.0.0-rc.41-hanzoai.5

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.
Files changed (47) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/helpers.cjs +68 -0
  3. package/dist/cjs/helpers.native.js +50 -0
  4. package/dist/cjs/helpers.native.js.map +1 -0
  5. package/dist/cjs/index.cjs +49 -0
  6. package/dist/cjs/index.native.js +55 -0
  7. package/dist/cjs/index.native.js.map +1 -0
  8. package/dist/cjs/initialValue.cjs +37 -0
  9. package/dist/cjs/initialValue.native.js +40 -0
  10. package/dist/cjs/initialValue.native.js.map +1 -0
  11. package/dist/cjs/types.cjs +18 -0
  12. package/dist/cjs/types.native.js +21 -0
  13. package/dist/cjs/types.native.js.map +1 -0
  14. package/dist/esm/helpers.mjs +43 -0
  15. package/dist/esm/helpers.mjs.map +1 -0
  16. package/dist/esm/helpers.native.js +21 -0
  17. package/dist/esm/helpers.native.js.map +1 -0
  18. package/dist/esm/index.js +12 -0
  19. package/dist/esm/index.js.map +1 -0
  20. package/dist/esm/index.mjs +12 -0
  21. package/dist/esm/index.mjs.map +1 -0
  22. package/dist/esm/index.native.js +15 -0
  23. package/dist/esm/index.native.js.map +1 -0
  24. package/dist/esm/initialValue.mjs +11 -0
  25. package/dist/esm/initialValue.mjs.map +1 -0
  26. package/dist/esm/initialValue.native.js +11 -0
  27. package/dist/esm/initialValue.native.js.map +1 -0
  28. package/dist/esm/types.mjs +2 -0
  29. package/dist/esm/types.mjs.map +1 -0
  30. package/dist/esm/types.native.js +2 -0
  31. package/dist/esm/types.native.js.map +1 -0
  32. package/package.json +48 -0
  33. package/src/helpers.native.ts +17 -0
  34. package/src/helpers.ts +73 -0
  35. package/src/index.ts +16 -0
  36. package/src/initialValue.ts +15 -0
  37. package/src/types.ts +10 -0
  38. package/types/helpers.d.ts +5 -0
  39. package/types/helpers.d.ts.map +11 -0
  40. package/types/helpers.native.d.ts +5 -0
  41. package/types/helpers.native.d.ts.map +11 -0
  42. package/types/index.d.ts +7 -0
  43. package/types/index.d.ts.map +11 -0
  44. package/types/initialValue.d.ts +8 -0
  45. package/types/initialValue.d.ts.map +11 -0
  46. package/types/types.d.ts +9 -0
  47. package/types/types.d.ts.map +11 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Nate Wienert
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,68 @@
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.TAMAGUI_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
+ }
@@ -0,0 +1,50 @@
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
+ import_react_native.Dimensions.addEventListener("change", function (param) {
37
+ var {
38
+ window
39
+ } = param;
40
+ cbs.forEach(function (cb) {
41
+ return cb(window);
42
+ });
43
+ });
44
+ function subscribe(cb) {
45
+ cbs.add(cb);
46
+ return function () {
47
+ return cbs.delete(cb);
48
+ };
49
+ }
50
+ //# sourceMappingURL=helpers.native.js.map
@@ -0,0 +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":";;;;;;;;;;;;;;;;;;;;;;;;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":[]}
@@ -0,0 +1,49 @@
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
+ }
@@ -0,0 +1,55 @@
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
@@ -0,0 +1 @@
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":[]}
@@ -0,0 +1,37 @@
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
+ }
@@ -0,0 +1,40 @@
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
@@ -0,0 +1 @@
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":[]}
@@ -0,0 +1,18 @@
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);
@@ -0,0 +1,21 @@
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
@@ -0,0 +1 @@
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":[]}
@@ -0,0 +1,43 @@
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.TAMAGUI_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
@@ -0,0 +1 @@
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","TAMAGUI_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;EAC1CD,KAAI,KAAAE,MAAQ,CAAIC,QAAA,CAAAC,eAAmB;EACjC,MAAAC,QAAO;IACTC,SAAA;IAEAC,MAAA,EAAAP,KAAU,CAAAQ,YAAgB;IAE1BC,KAAA,EAAMP,MAAA,CAAAQ,gBAAuB;IAAAC,KAC3B,EAAAX,KAAA,CAAWY;EAAA;EACG,IACdP,QAAO,CAAAE,MAAO,KAAAR,QAAA,CAAAQ,MAAoB,IAAAF,QAAA,CAAAM,KAAA,KAAAZ,QAAA,CAAAY,KAAA,IAAAN,QAAA,CAAAI,KAAA,KAAAV,QAAA,CAAAU,KAAA;IAAAV,QAClC,GAAOM,QAAM;IACf,OAAAA,QAAA;EAEA;EAKE,OAAAN,QAAW;AACX;AAAO,MACTc,GAAA,sBAAAC,GAAA;AAEA,IAAAjB,QAAO,WAAAK,MAAA,2BAAAA,MAAA,CAAAa,gBAAA;EACT,IAAAC,WAAA,YAAAA,CAAA;IAEAC,UAAY,GAAAC,IAAA,CAAAC,GAAA;IAIZN,GACE,CAAAO,OAAA,CAAAC,EACA,IAAAA,EAAO,CAAApB,aAAW;EAQlB;EACE,IAAAgB,UAAA,GAAaC,IAAK,CAAAC,GAAI;EACtB,IAAAG,EAAA;EAAuC,MACzCC,WAAA,GAAAC,OAAA,CAAAC,GAAA,CAAAC,2CAAA;EARA,MAAIC,WAAA,GAAaJ,WAAS,IAAAA,WAAA;EAC1B,MAAIK,QAAA,GAAAA,CAAA;IACJC,YAAM,CAAAP,EAAA;IACN,MAAMQ,aAAA,GAAcZ,IAAA,CAAAC,GAAA,KAAeF,UAAA;IAOnC,IAAAa,aAAiB,GAAAH,WAAM,EAAAL,EAAA,GAAAS,UAAA;MACrBf,WAAA;IAGA,GAAAW,WAAM,GAAAG,aAAqB,OAC3Bd,WAAI;EACF;EACEd,MAAA,CAAAa,gBAAY,WAAAa,QAAA;AAAA;AACgB,SAChCI,SAAOA,CAAAX,EAAA;EACLR,GAAA,CAAAoB,GAAA,CAAAZ,EAAA;EAAY,OACd,MAAAR,GAAA,CAAAqB,MAAA,CAAAb,EAAA;AAAA;AAGF,SAAOpB,aAAA,EAAA+B,SAAiB","ignoreList":[]}
@@ -0,0 +1,21 @@
1
+ import { Dimensions } from "react-native";
2
+ function getWindowSize() {
3
+ return Dimensions.get("window");
4
+ }
5
+ var cbs = /* @__PURE__ */new Set();
6
+ Dimensions.addEventListener("change", function (param) {
7
+ var {
8
+ window
9
+ } = param;
10
+ cbs.forEach(function (cb) {
11
+ return cb(window);
12
+ });
13
+ });
14
+ function subscribe(cb) {
15
+ cbs.add(cb);
16
+ return function () {
17
+ return cbs.delete(cb);
18
+ };
19
+ }
20
+ export { getWindowSize, subscribe };
21
+ //# sourceMappingURL=helpers.native.js.map
@@ -0,0 +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;EAC1BN,GAAA,CAAIQ,GAAA,CAAIF,EAAE;EACV,OAAO,YAAW;IACd,OAAON,GAAA,CAAIS,MAAA,CAAOH,EAAE;EACxB;AACJ","ignoreList":[]}
@@ -0,0 +1,12 @@
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.js.map
@@ -0,0 +1 @@
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":[]}
@@ -0,0 +1,12 @@
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
@@ -0,0 +1 @@
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":[]}
@@ -0,0 +1,15 @@
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
@@ -0,0 +1 @@
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":[]}
@@ -0,0 +1,11 @@
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
@@ -0,0 +1 @@
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":[]}
@@ -0,0 +1,11 @@
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
@@ -0,0 +1 @@
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":[]}
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":[],"sourcesContent":[],"mappings":"","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=types.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":[],"sourcesContent":[],"mappings":"","ignoreList":[]}
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@hanzogui/use-window-dimensions",
3
+ "version": "2.0.0-rc.41-hanzoai.5",
4
+ "gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14",
5
+ "files": [
6
+ "src",
7
+ "types",
8
+ "dist"
9
+ ],
10
+ "type": "module",
11
+ "sideEffects": false,
12
+ "main": "dist/cjs",
13
+ "module": "dist/esm",
14
+ "types": "./types/index.d.ts",
15
+ "exports": {
16
+ "./package.json": "./package.json",
17
+ ".": {
18
+ "types": "./types/index.d.ts",
19
+ "react-native": "./dist/esm/index.native.js",
20
+ "browser": "./dist/esm/index.mjs",
21
+ "module": "./dist/esm/index.mjs",
22
+ "import": "./dist/esm/index.mjs",
23
+ "require": "./dist/cjs/index.cjs",
24
+ "default": "./dist/esm/index.mjs"
25
+ }
26
+ },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "scripts": {
31
+ "build": "hanzogui-build",
32
+ "watch": "hanzogui-build --watch",
33
+ "clean": "hanzogui-build clean",
34
+ "clean:build": "hanzogui-build clean:build"
35
+ },
36
+ "dependencies": {
37
+ "@hanzogui/constants": "2.0.0-rc.41-hanzoai.5"
38
+ },
39
+ "devDependencies": {
40
+ "@hanzogui/build": "2.0.0-rc.41-hanzoai.5",
41
+ "react": ">=19",
42
+ "react-native": "0.83.2"
43
+ },
44
+ "peerDependencies": {
45
+ "react": ">=19",
46
+ "react-native": "*"
47
+ }
48
+ }
@@ -0,0 +1,17 @@
1
+ import { Dimensions } from 'react-native'
2
+ import type { WindowSize, WindowSizeListener } from './types'
3
+
4
+ export function getWindowSize(): WindowSize {
5
+ return Dimensions.get('window')
6
+ }
7
+
8
+ const cbs = new Set<WindowSizeListener>()
9
+
10
+ Dimensions.addEventListener('change', ({ window }) => {
11
+ cbs.forEach((cb) => cb(window))
12
+ })
13
+
14
+ export function subscribe(cb: WindowSizeListener): () => void {
15
+ cbs.add(cb)
16
+ return () => cbs.delete(cb)
17
+ }
package/src/helpers.ts ADDED
@@ -0,0 +1,73 @@
1
+ import { isClient } from '@hanzogui/constants'
2
+ import { initialValue } from './initialValue'
3
+ import type { WindowSize, WindowSizeListener } from './types'
4
+
5
+ let lastSize: WindowSize = initialValue
6
+ let docEl: HTMLElement | null = null
7
+
8
+ export function getWindowSize(): WindowSize {
9
+ if (process.env.TAMAGUI_TARGET !== 'web') {
10
+ return initialValue
11
+ }
12
+
13
+ docEl ||= window.document.documentElement
14
+
15
+ const nextSize: WindowSize = {
16
+ fontScale: 1,
17
+ height: docEl.clientHeight,
18
+ scale: window.devicePixelRatio || 1,
19
+ width: docEl.clientWidth,
20
+ }
21
+
22
+ if (
23
+ nextSize.height !== lastSize.height ||
24
+ nextSize.width !== lastSize.width ||
25
+ nextSize.scale !== lastSize.scale
26
+ ) {
27
+ lastSize = nextSize
28
+ return nextSize
29
+ }
30
+
31
+ return lastSize
32
+ }
33
+
34
+ const cbs = new Set<WindowSizeListener>()
35
+
36
+ // only attach resize listener on client (not during SSR)
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
+ ) {
43
+ let lastUpdate = Date.now()
44
+ let tm: ReturnType<typeof setTimeout> | undefined
45
+ const USER_MAX_MS = process.env.TAMAGUI_USE_WINDOW_DIMENSIONS_MAX_UPDATE_MS
46
+ const updateMaxMs = USER_MAX_MS ? +USER_MAX_MS : 100
47
+
48
+ function flushUpdate() {
49
+ lastUpdate = Date.now()
50
+ cbs.forEach((cb) => cb(getWindowSize()))
51
+ }
52
+
53
+ const onResize = () => {
54
+ clearTimeout(tm)
55
+
56
+ // only update every few frames
57
+ const timeSinceLast = Date.now() - lastUpdate
58
+ if (timeSinceLast < updateMaxMs) {
59
+ tm = setTimeout(() => {
60
+ flushUpdate()
61
+ }, updateMaxMs - timeSinceLast)
62
+ } else {
63
+ flushUpdate()
64
+ }
65
+ }
66
+
67
+ window.addEventListener('resize', onResize)
68
+ }
69
+
70
+ export function subscribe(cb: WindowSizeListener): () => void {
71
+ cbs.add(cb)
72
+ return () => cbs.delete(cb)
73
+ }
package/src/index.ts ADDED
@@ -0,0 +1,16 @@
1
+ import React from 'react'
2
+ import { isWeb } from '@hanzogui/constants'
3
+
4
+ import { getWindowSize, subscribe } from './helpers'
5
+ import type { WindowSize } from './types'
6
+ import { initialValue } from './initialValue'
7
+
8
+ export { configureInitialWindowDimensions } from './initialValue'
9
+
10
+ export function useWindowDimensions({
11
+ serverValue = initialValue,
12
+ }: { serverValue?: WindowSize } = {}): WindowSize {
13
+ return React.useSyncExternalStore(subscribe, getWindowSize, () =>
14
+ isWeb ? serverValue : getWindowSize()
15
+ )
16
+ }
@@ -0,0 +1,15 @@
1
+ import type { WindowSize } from './types'
2
+
3
+ /**
4
+ * SSR safe useWindowDimensions
5
+ */
6
+ export const initialValue: WindowSize = {
7
+ width: 800,
8
+ height: 600,
9
+ scale: 1,
10
+ fontScale: 1,
11
+ }
12
+
13
+ export function configureInitialWindowDimensions(next: WindowSize): void {
14
+ Object.assign(initialValue, next)
15
+ }
package/src/types.ts ADDED
@@ -0,0 +1,10 @@
1
+ import type { ScaledSize } from 'react-native'
2
+
3
+ export type Size = {
4
+ width: number
5
+ height: number
6
+ }
7
+
8
+ export type WindowSize = ScaledSize
9
+
10
+ export type WindowSizeListener = (size: WindowSize) => void
@@ -0,0 +1,5 @@
1
+ import type { WindowSize, WindowSizeListener } from "./types";
2
+ export declare function getWindowSize(): WindowSize;
3
+ export declare function subscribe(cb: WindowSizeListener): () => void;
4
+
5
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1,11 @@
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.TAMAGUI_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.TAMAGUI_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
+ }
@@ -0,0 +1,5 @@
1
+ import type { WindowSize, WindowSizeListener } from "./types";
2
+ export declare function getWindowSize(): WindowSize;
3
+ export declare function subscribe(cb: WindowSizeListener): () => void;
4
+
5
+ //# sourceMappingURL=helpers.native.d.ts.map
@@ -0,0 +1,11 @@
1
+ {
2
+ "mappings": "AACA,cAAc,YAAY,0BAA0B;AAEpD,OAAO,iBAAS,iBAAiB;AAUjC,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\nDimensions.addEventListener('change', ({ window }) => {\n cbs.forEach((cb) => cb(window))\n})\n\nexport function subscribe(cb: WindowSizeListener): () => void {\n cbs.add(cb)\n return () => cbs.delete(cb)\n}\n"
10
+ ]
11
+ }
@@ -0,0 +1,7 @@
1
+ import type { WindowSize } from "./types";
2
+ export { configureInitialWindowDimensions } from "./initialValue";
3
+ export declare function useWindowDimensions({ serverValue }?: {
4
+ serverValue?: WindowSize;
5
+ }): WindowSize;
6
+
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,11 @@
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
+ }
@@ -0,0 +1,8 @@
1
+ import type { WindowSize } from "./types";
2
+ /**
3
+ * SSR safe useWindowDimensions
4
+ */
5
+ export declare const initialValue: WindowSize;
6
+ export declare function configureInitialWindowDimensions(next: WindowSize): void;
7
+
8
+ //# sourceMappingURL=initialValue.d.ts.map
@@ -0,0 +1,11 @@
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
+ }
@@ -0,0 +1,9 @@
1
+ import type { ScaledSize } from "react-native";
2
+ export type Size = {
3
+ width: number;
4
+ height: number;
5
+ };
6
+ export type WindowSize = ScaledSize;
7
+ export type WindowSizeListener = (size: WindowSize) => void;
8
+
9
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,11 @@
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
+ }