@hanzogui/use-window-dimensions 3.0.6 → 4.4.0

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.
@@ -3,20 +3,22 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
5
  var __export = (target, all) => {
6
- for (var name in all) __defProp(target, name, {
7
- get: all[name],
8
- enumerable: !0
9
- });
10
- },
11
- __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
14
  get: () => from[key],
14
15
  enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
16
  });
16
- return to;
17
- };
17
+ }
18
+ return to;
19
+ };
18
20
  var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
19
- value: !0
21
+ value: true
20
22
  }), mod);
21
23
  var helpers_exports = {};
22
24
  __export(helpers_exports, {
@@ -24,11 +26,14 @@ __export(helpers_exports, {
24
26
  subscribe: () => subscribe
25
27
  });
26
28
  module.exports = __toCommonJS(helpers_exports);
27
- var import_constants = require("@hanzogui/constants"),
28
- import_initialValue = require("./initialValue.cjs");
29
- let lastSize = import_initialValue.initialValue,
30
- docEl = null;
29
+ var import_constants = require("@hanzogui/constants");
30
+ var import_initialValue = require("./initialValue.cjs");
31
+ let lastSize = import_initialValue.initialValue;
32
+ let docEl = null;
31
33
  function getWindowSize() {
34
+ if (false) {
35
+ return import_initialValue.initialValue;
36
+ }
32
37
  docEl ||= window.document.documentElement;
33
38
  const nextSize = {
34
39
  fontScale: 1,
@@ -36,26 +41,36 @@ function getWindowSize() {
36
41
  scale: window.devicePixelRatio || 1,
37
42
  width: docEl.clientWidth
38
43
  };
39
- return nextSize.height !== lastSize.height || nextSize.width !== lastSize.width || nextSize.scale !== lastSize.scale ? (lastSize = nextSize, nextSize) : lastSize;
44
+ if (nextSize.height !== lastSize.height || nextSize.width !== lastSize.width || nextSize.scale !== lastSize.scale) {
45
+ lastSize = nextSize;
46
+ return nextSize;
47
+ }
48
+ return lastSize;
40
49
  }
41
50
  const cbs = /* @__PURE__ */new Set();
42
- if (import_constants.isClient) {
51
+ if (import_constants.isClient && typeof window !== "undefined" && typeof window.addEventListener === "function") {
43
52
  let flushUpdate = function () {
44
- lastUpdate = Date.now(), cbs.forEach(cb => cb(getWindowSize()));
45
- },
46
- lastUpdate = Date.now(),
47
- tm;
48
- const USER_MAX_MS = process.env.HANZO_GUI_USE_WINDOW_DIMENSIONS_MAX_UPDATE_MS,
49
- updateMaxMs = USER_MAX_MS ? +USER_MAX_MS : 100,
50
- onResize = () => {
51
- clearTimeout(tm);
52
- const timeSinceLast = Date.now() - lastUpdate;
53
- timeSinceLast < updateMaxMs ? tm = setTimeout(() => {
53
+ lastUpdate = Date.now();
54
+ cbs.forEach(cb => cb(getWindowSize()));
55
+ };
56
+ let lastUpdate = Date.now();
57
+ let tm;
58
+ const USER_MAX_MS = process.env.GUI_USE_WINDOW_DIMENSIONS_MAX_UPDATE_MS;
59
+ const updateMaxMs = USER_MAX_MS ? +USER_MAX_MS : 100;
60
+ const onResize = () => {
61
+ clearTimeout(tm);
62
+ const timeSinceLast = Date.now() - lastUpdate;
63
+ if (timeSinceLast < updateMaxMs) {
64
+ tm = setTimeout(() => {
54
65
  flushUpdate();
55
- }, updateMaxMs - timeSinceLast) : flushUpdate();
56
- };
66
+ }, updateMaxMs - timeSinceLast);
67
+ } else {
68
+ flushUpdate();
69
+ }
70
+ };
57
71
  window.addEventListener("resize", onResize);
58
72
  }
59
73
  function subscribe(cb) {
60
- return cbs.add(cb), () => cbs.delete(cb);
74
+ cbs.add(cb);
75
+ return () => cbs.delete(cb);
61
76
  }
@@ -5,20 +5,22 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: !0
11
- });
12
- },
13
- __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
15
16
  get: () => from[key],
16
17
  enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
18
  });
18
- return to;
19
- };
19
+ }
20
+ return to;
21
+ };
20
22
  var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
- value: !0
23
+ value: true
22
24
  }), mod);
23
25
  var helpers_native_exports = {};
24
26
  __export(helpers_native_exports, {
@@ -40,7 +42,8 @@ import_react_native.Dimensions.addEventListener("change", function (param) {
40
42
  });
41
43
  });
42
44
  function subscribe(cb) {
43
- return cbs.add(cb), function () {
45
+ cbs.add(cb);
46
+ return function () {
44
47
  return cbs.delete(cb);
45
48
  };
46
49
  }
@@ -1 +1 @@
1
- {"version":3,"names":["helpers_native_exports","__export","getWindowSize","subscribe","module","exports","__toCommonJS","import_react_native","require","Dimensions","get","cbs","Set","addEventListener","param","window","forEach","cb","add","delete"],"sources":["../../src/helpers.native.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;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;EAC1B,OAAAN,GAAA,CAAIO,GAAA,CAAID,EAAE,GACH,YAAW;IACd,OAAON,GAAA,CAAIQ,MAAA,CAAOF,EAAE;EACxB;AACJ","ignoreList":[]}
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":[]}
@@ -2,44 +2,46 @@ var __create = Object.create;
2
2
  var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf,
6
- __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: !0
11
- });
12
- },
13
- __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
15
16
  get: () => from[key],
16
17
  enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
18
  });
18
- return to;
19
- };
19
+ }
20
+ return to;
21
+ };
20
22
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
- value: mod,
27
- enumerable: !0
28
- }) : target, mod)),
29
- __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
30
- value: !0
31
- }), mod);
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
28
+ value: mod,
29
+ enumerable: true
30
+ }) : target, mod));
31
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
+ value: true
33
+ }), mod);
32
34
  var index_exports = {};
33
35
  __export(index_exports, {
34
36
  configureInitialWindowDimensions: () => import_initialValue2.configureInitialWindowDimensions,
35
37
  useWindowDimensions: () => useWindowDimensions
36
38
  });
37
39
  module.exports = __toCommonJS(index_exports);
38
- var import_react = __toESM(require("react"), 1),
39
- import_constants = require("@hanzogui/constants"),
40
- import_helpers = require("./helpers.cjs"),
41
- import_initialValue = require("./initialValue.cjs"),
42
- import_initialValue2 = require("./initialValue.cjs");
40
+ var import_react = __toESM(require("react"), 1);
41
+ var import_constants = require("@hanzogui/constants");
42
+ var import_helpers = require("./helpers.cjs");
43
+ var import_initialValue = require("./initialValue.cjs");
44
+ var import_initialValue2 = require("./initialValue.cjs");
43
45
  function useWindowDimensions({
44
46
  serverValue = import_initialValue.initialValue
45
47
  } = {}) {
@@ -4,44 +4,46 @@ var __create = Object.create;
4
4
  var __defProp = Object.defineProperty;
5
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf,
8
- __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
9
  var __export = (target, all) => {
10
- for (var name in all) __defProp(target, name, {
11
- get: all[name],
12
- enumerable: !0
13
- });
14
- },
15
- __copyProps = (to, from, except, desc) => {
16
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
10
+ for (var name in all) __defProp(target, name, {
11
+ get: all[name],
12
+ enumerable: true
13
+ });
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
18
  get: () => from[key],
18
19
  enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
20
  });
20
- return to;
21
- };
21
+ }
22
+ return to;
23
+ };
22
24
  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: !0
30
- }) : target, mod)),
31
- __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
- value: !0
33
- }), mod);
25
+ // If the importer is in node compatibility mode or this is not an ESM
26
+ // file that has been converted to a CommonJS file using a Babel-
27
+ // compatible transform (i.e. "__esModule" has not been set), then set
28
+ // "default" to the CommonJS "module.exports" for node compatibility.
29
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
30
+ value: mod,
31
+ enumerable: true
32
+ }) : target, mod));
33
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
34
+ value: true
35
+ }), mod);
34
36
  var index_exports = {};
35
37
  __export(index_exports, {
36
38
  configureInitialWindowDimensions: () => import_initialValue2.configureInitialWindowDimensions,
37
39
  useWindowDimensions: () => useWindowDimensions
38
40
  });
39
41
  module.exports = __toCommonJS(index_exports);
40
- var import_react = __toESM(require("react"), 1),
41
- import_constants = require("@hanzogui/constants"),
42
- import_helpers = require("./helpers"),
43
- import_initialValue = require("./initialValue"),
44
- import_initialValue2 = require("./initialValue");
42
+ var import_react = __toESM(require("react"), 1);
43
+ var import_constants = require("@hanzogui/constants");
44
+ var import_helpers = require("./helpers.native.js");
45
+ var import_initialValue = require("./initialValue.native.js");
46
+ var import_initialValue2 = require("./initialValue.native.js");
45
47
  function useWindowDimensions() {
46
48
  var {
47
49
  serverValue = import_initialValue.initialValue
@@ -1 +1 @@
1
- {"version":3,"names":["__create","Object","create","__defProp","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__getProtoOf","getPrototypeOf","__hasOwnProp","prototype","hasOwnProperty","__export","target","all","name","get","enumerable","__copyProps","to","from","except","desc","key","call","__toESM","mod","isNodeMode","__esModule","value","__toCommonJS","index_exports","configureInitialWindowDimensions","import_initialValue2","useWindowDimensions","module","exports","import_react","require","import_constants","import_helpers","import_initialValue","serverValue","initialValue","arguments","length","default","useSyncExternalStore","subscribe","getWindowSize","isWeb"],"sources":["index.native.js"],"sourcesContent":["\"use strict\";\nvar __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: !0 });\n}, __copyProps = (to, from, except, desc) => {\n if (from && typeof from == \"object\" || typeof from == \"function\")\n for (let key of __getOwnPropNames(from))\n !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: !0 }) : target,\n mod\n)), __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: !0 }), mod);\nvar index_exports = {};\n__export(index_exports, {\n configureInitialWindowDimensions: () => import_initialValue2.configureInitialWindowDimensions,\n useWindowDimensions: () => useWindowDimensions\n});\nmodule.exports = __toCommonJS(index_exports);\nvar import_react = __toESM(require(\"react\"), 1), import_constants = require(\"@hanzogui/constants\"), import_helpers = require(\"./helpers\"), import_initialValue = require(\"./initialValue\"), import_initialValue2 = require(\"./initialValue\");\nfunction useWindowDimensions() {\n var { serverValue = import_initialValue.initialValue } = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};\n return import_react.default.useSyncExternalStore(import_helpers.subscribe, import_helpers.getWindowSize, function() {\n return import_constants.isWeb ? serverValue : (0, import_helpers.getWindowSize)();\n });\n}\n//# sourceMappingURL=index.js.map\n"],"mappings":"AAAA,YAAY;;AACZ,IAAIA,QAAQ,GAAGC,MAAM,CAACC,MAAM;AAC5B,IAAIC,SAAS,GAAGF,MAAM,CAACG,cAAc;AACrC,IAAIC,gBAAgB,GAAGJ,MAAM,CAACK,wBAAwB;AACtD,IAAIC,iBAAiB,GAAGN,MAAM,CAACO,mBAAmB;AAClD,IAAIC,YAAY,GAAGR,MAAM,CAACS,cAAc;EAAEC,YAAY,GAAGV,MAAM,CAACW,SAAS,CAACC,cAAc;AACxF,IAAIC,QAAQ,GAAGA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AAG,IAAKR,WAAW,CAACjB,SAAS,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE;IAAE4B,KAAK,EAAE,CAAC;EAAE,CAAC,CAAC,EAAEH,GAAG,CAAC;AACxF,IAAIK,aAAa,GAAG,CAAC,CAAC;AACtBnB,QAAQ,CAACmB,aAAa,EAAE;EACtBC,gCAAgC,EAAEA,CAAA,KAAMC,oBAAoB,CAACD,gCAAgC;EAC7FE,mBAAmB,EAAEA,CAAA,KAAMA;AAC7B,CAAC,CAAC;AACFC,MAAM,CAACC,OAAO,GAAGN,YAAY,CAACC,aAAa,CAAC;AAC5C,IAAIM,YAAY,GAAGZ,OAAO,CAACa,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;EAAEC,gBAAgB,GAAGD,OAAO,CAAC,qBAAqB,CAAC;EAAEE,cAAc,GAAGF,OAAO,CAAC,WAAW,CAAC;EAAEG,mBAAmB,GAAGH,OAAO,CAAC,gBAAgB,CAAC;EAAEL,oBAAoB,GAAGK,OAAO,CAAC,gBAAgB,CAAC;AAC5O,SAASJ,mBAAmBA,CAAA,EAAG;EAC7B,IAAI;IAAEQ,WAAW,GAAGD,mBAAmB,CAACE;EAAa,CAAC,GAAGC,SAAS,CAACC,MAAM,GAAG,CAAC,IAAID,SAAS,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,GAAGA,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;EAC5H,OAAOP,YAAY,CAACS,OAAO,CAACC,oBAAoB,CAACP,cAAc,CAACQ,SAAS,EAAER,cAAc,CAACS,aAAa,EAAE,YAAW;IAClH,OAAOV,gBAAgB,CAACW,KAAK,GAAGR,WAAW,GAAG,CAAC,CAAC,EAAEF,cAAc,CAACS,aAAa,EAAE,CAAC;EACnF,CAAC,CAAC;AACJ","ignoreList":[]}
1
+ {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","index_exports","__export","configureInitialWindowDimensions","import_initialValue2","useWindowDimensions","module","exports","import_react","__toESM","require","import_constants","import_helpers","import_initialValue","serverValue","initialValue","arguments","length","default","useSyncExternalStore","subscribe","getWindowSize","isWeb"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,aAAA;AAAAC,QAAA,CAAAD,aAAA;EAAAE,gCAAA,EAAAA,CAAA,KAAAC,oBAAA,CAAAD,gCAAA;EAAAE,mBAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAX,YAAkB,CAAAK,aAAA;AAClB,IAAAO,YAAA,GAAAC,OAAsB,CAAAC,OAAA;AAEtB,IAAAC,gBAAA,GAAyCD,OAAA;AAEzC,IAAAE,cAAA,GAAAF,OAA6B;AAE7B,IAAAG,mBAAA,GAAAH,OAAiD;AAE1C,IAAAN,oBAAS,GAAAM,OAAoB;AAAA,SAClCL,mBAAcA,CAAA;EAChB,IAAmC;IAAeS,WAAA,GAAAD,mBAAA,CAAAE;EAAA,IAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,iBAAAA,SAAA;EAChD,OAAOR,YAAA,CAAAU,OAAA,CAAMC,oBAAA,CAAAP,cAAA,CAAAQ,SAAA,EAAAR,cAAA,CAAAS,aAAA;IAAqB,OAAAV,gBAAA,CAAAW,KAAA,GAAAR,WAAA,OAAAF,cAAA,CAAAS,aAAA;EAAA,EAAW;AAAA","ignoreList":[]}
@@ -3,20 +3,22 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
5
  var __export = (target, all) => {
6
- for (var name in all) __defProp(target, name, {
7
- get: all[name],
8
- enumerable: !0
9
- });
10
- },
11
- __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
14
  get: () => from[key],
14
15
  enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
16
  });
16
- return to;
17
- };
17
+ }
18
+ return to;
19
+ };
18
20
  var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
19
- value: !0
21
+ value: true
20
22
  }), mod);
21
23
  var initialValue_exports = {};
22
24
  __export(initialValue_exports, {
@@ -5,20 +5,22 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: !0
11
- });
12
- },
13
- __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
15
16
  get: () => from[key],
16
17
  enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
18
  });
18
- return to;
19
- };
19
+ }
20
+ return to;
21
+ };
20
22
  var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
- value: !0
23
+ value: true
22
24
  }), mod);
23
25
  var initialValue_exports = {};
24
26
  __export(initialValue_exports, {
@@ -1 +1 @@
1
- {"version":3,"names":["__defProp","Object","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__hasOwnProp","prototype","hasOwnProperty","__export","target","all","name","get","enumerable","__copyProps","to","from","except","desc","key","call","__toCommonJS","mod","value","initialValue_exports","configureInitialWindowDimensions","initialValue","module","exports","width","height","scale","fontScale","next","assign"],"sources":["initialValue.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: !0 });\n}, __copyProps = (to, from, except, desc) => {\n if (from && typeof from == \"object\" || typeof from == \"function\")\n for (let key of __getOwnPropNames(from))\n !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: !0 }), mod);\nvar initialValue_exports = {};\n__export(initialValue_exports, {\n configureInitialWindowDimensions: () => configureInitialWindowDimensions,\n initialValue: () => initialValue\n});\nmodule.exports = __toCommonJS(initialValue_exports);\nvar initialValue = {\n width: 800,\n height: 600,\n scale: 1,\n fontScale: 1\n};\nfunction configureInitialWindowDimensions(next) {\n Object.assign(initialValue, next);\n}\n//# sourceMappingURL=initialValue.js.map\n"],"mappings":"AAAA,YAAY;;AACZ,IAAIA,SAAS,GAAGC,MAAM,CAACC,cAAc;AACrC,IAAIC,gBAAgB,GAAGF,MAAM,CAACG,wBAAwB;AACtD,IAAIC,iBAAiB,GAAGJ,MAAM,CAACK,mBAAmB;AAClD,IAAIC,YAAY,GAAGN,MAAM,CAACO,SAAS,CAACC,cAAc;AAClD,IAA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AAE,GAAG;EACVC,MAAM,EAAE,GAAG;EACXC,KAAK,EAAE,CAAC;EACRC,SAAS,EAAE;AACb,CAAC;AACD,SAASP,gCAAgCA,CAACQ,IAAI,EAAE;EAC9ClC,MAAM,CAACmC,MAAM,CAACR,YAAY,EAAEO,IAAI,CAAC;AACnC","ignoreList":[]}
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":[]}
@@ -3,14 +3,16 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
5
  var __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
7
- get: () => from[key],
8
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
9
- });
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
8
+ get: () => from[key],
9
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
10
+ });
11
+ }
10
12
  return to;
11
13
  };
12
14
  var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
13
- value: !0
15
+ value: true
14
16
  }), mod);
15
17
  var types_exports = {};
16
18
  module.exports = __toCommonJS(types_exports);
@@ -5,14 +5,16 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __copyProps = (to, from, except, desc) => {
8
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
9
- get: () => from[key],
10
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
11
- });
8
+ if (from && typeof from === "object" || typeof from === "function") {
9
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
10
+ get: () => from[key],
11
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
12
+ });
13
+ }
12
14
  return to;
13
15
  };
14
16
  var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
15
- value: !0
17
+ value: true
16
18
  }), mod);
17
19
  var types_exports = {};
18
20
  module.exports = __toCommonJS(types_exports);
@@ -1 +1 @@
1
- {"version":3,"names":["__defProp","Object","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__hasOwnProp","prototype","hasOwnProperty","__copyProps","to","from","except","desc","key","call","get","enumerable","__toCommonJS","mod","value","types_exports","module","exports"],"sources":["types.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from == \"object\" || typeof from == \"function\")\n for (let key of __getOwnPropNames(from))\n !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: !0 }), mod);\nvar types_exports = {};\nmodule.exports = __toCommonJS(types_exports);\n//# sourceMappingURL=types.js.map\n"],"mappings":"AAAA,YAAY;;AACZ,IAAIA,SAAS,GAAGC,MAAM,CAACC,cAAc;AACrC,IAAIC,gBAAgB,GAAGF,MAAM,CAACG,wBAAwB;AACtD,IAAIC,iBAAiB,GAAGJ,MAAM,CAACK,mBAAmB;AAClD,IAAIC,YAAY,GAAGN,MAAM,CAACO,SAAS,CAACC,cAAc;AAClD,IAAIC,WAAW,GAAGA,CAACC,EAAE,EAAEC,IAAI,EAAEC,MAAM,EAAEC,IAAI,KAAK;EAC5C,IAAIF,IAAI,IAAI,OAAOA,IAAI,IAAI,QAAQ,IAAI,OAAOA,IAAI,IAAI,UAAU,EAC9D,KAAK,IAAIG,GAAG,IAAIV,iBAAiB,CAACO,IAAI,CAAC,EACrC,CAACL,YAAY,CAACS,IAAI,CAACL,EAAE,EAAEI,GAAG,CAAC,IAAIA,GAAG,KAAKF,MAAM,IAAIb,SAAS,CAACW,EAAE,EAAEI,GAAG,EAAE;IAAEE,GAAG,EAAEA,CAAA,KAAML,IAAI,CAACG,GAAG,CAAC;IAAEG,UAAU,EAAE,EAAEJ,IAAI,GAAGX,gBAAgB,CAACS,IAAI,EAAEG,GAAG,CAAC,CAAC,IAAID,IAAI,CAACI;EAAW,CAAC,CAAC;EACvK,OAAOP,EAAE;AACX,CAAC;AACD,IAAIQ,YAAY,GAAIC,GAAG,IAAKV,WAAW,CAACV,SAAS,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE;EAAEqB,KAAK,EAAE,CAAC;AAAE,CAAC,CAAC,EAAED,GAAG,CAAC;AACxF,IAAIE,aAAa,GAAG,CAAC,CAAC;AACtBC,MAAM,CAACC,OAAO,GAAGL,YAAY,CAACG,aAAa,CAAC","ignoreList":[]}
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":[]}
@@ -1,8 +1,11 @@
1
1
  import { isClient } from "@hanzogui/constants";
2
2
  import { initialValue } from "./initialValue.mjs";
3
- let lastSize = initialValue,
4
- docEl = null;
3
+ let lastSize = initialValue;
4
+ let docEl = null;
5
5
  function getWindowSize() {
6
+ if (false) {
7
+ return initialValue;
8
+ }
6
9
  docEl ||= window.document.documentElement;
7
10
  const nextSize = {
8
11
  fontScale: 1,
@@ -10,28 +13,38 @@ function getWindowSize() {
10
13
  scale: window.devicePixelRatio || 1,
11
14
  width: docEl.clientWidth
12
15
  };
13
- return nextSize.height !== lastSize.height || nextSize.width !== lastSize.width || nextSize.scale !== lastSize.scale ? (lastSize = nextSize, nextSize) : lastSize;
16
+ if (nextSize.height !== lastSize.height || nextSize.width !== lastSize.width || nextSize.scale !== lastSize.scale) {
17
+ lastSize = nextSize;
18
+ return nextSize;
19
+ }
20
+ return lastSize;
14
21
  }
15
22
  const cbs = /* @__PURE__ */new Set();
16
- if (isClient) {
23
+ if (isClient && typeof window !== "undefined" && typeof window.addEventListener === "function") {
17
24
  let flushUpdate = function () {
18
- lastUpdate = Date.now(), cbs.forEach(cb => cb(getWindowSize()));
19
- },
20
- lastUpdate = Date.now(),
21
- tm;
22
- const USER_MAX_MS = process.env.HANZO_GUI_USE_WINDOW_DIMENSIONS_MAX_UPDATE_MS,
23
- updateMaxMs = USER_MAX_MS ? +USER_MAX_MS : 100,
24
- onResize = () => {
25
- clearTimeout(tm);
26
- const timeSinceLast = Date.now() - lastUpdate;
27
- timeSinceLast < updateMaxMs ? tm = setTimeout(() => {
25
+ lastUpdate = Date.now();
26
+ cbs.forEach(cb => cb(getWindowSize()));
27
+ };
28
+ let lastUpdate = Date.now();
29
+ let tm;
30
+ const USER_MAX_MS = process.env.GUI_USE_WINDOW_DIMENSIONS_MAX_UPDATE_MS;
31
+ const updateMaxMs = USER_MAX_MS ? +USER_MAX_MS : 100;
32
+ const onResize = () => {
33
+ clearTimeout(tm);
34
+ const timeSinceLast = Date.now() - lastUpdate;
35
+ if (timeSinceLast < updateMaxMs) {
36
+ tm = setTimeout(() => {
28
37
  flushUpdate();
29
- }, updateMaxMs - timeSinceLast) : flushUpdate();
30
- };
38
+ }, updateMaxMs - timeSinceLast);
39
+ } else {
40
+ flushUpdate();
41
+ }
42
+ };
31
43
  window.addEventListener("resize", onResize);
32
44
  }
33
45
  function subscribe(cb) {
34
- return cbs.add(cb), () => cbs.delete(cb);
46
+ cbs.add(cb);
47
+ return () => cbs.delete(cb);
35
48
  }
36
49
  export { getWindowSize, subscribe };
37
50
  //# sourceMappingURL=helpers.mjs.map
@@ -1 +1 @@
1
- {"version":3,"names":["isClient","initialValue","lastSize","docEl","getWindowSize","window","document","documentElement","nextSize","fontScale","height","clientHeight","scale","devicePixelRatio","width","clientWidth","cbs","Set","flushUpdate","lastUpdate","Date","now","forEach","cb","tm","USER_MAX_MS","process","env","HANZO_GUI_USE_WINDOW_DIMENSIONS_MAX_UPDATE_MS","updateMaxMs","onResize","clearTimeout","timeSinceLast","setTimeout","addEventListener","subscribe","add","delete"],"sources":["../../src/helpers.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,QAAA,QAAgB;AACzB,SAASC,YAAA,QAAoB;AAG7B,IAAIC,QAAA,GAAuBD,YAAA;EACvBE,KAAA,GAA4B;AAEzB,SAASC,cAAA,EAA4B;EAK1CD,KAAA,KAAUE,MAAA,CAAOC,Q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IoB,GAAA,CAAIb,EAAE,GACH,MAAMP,GAAA,CAAIqB,MAAA,CAAOd,EAAE;AAC5B","ignoreList":[]}
1
+ {"version":3,"names":["isClient","initialValue","lastSize","docEl","getWindowSize","window","document","documentElement","nextSize","fontScale","height","clientHeight","scale","devicePixelRatio","width","clientWidth","cbs","Set","addEventListener","flushUpdate","lastUpdate","Date","now","forEach","cb","tm","USER_MAX_MS","process","env","GUI_USE_WINDOW_DIMENSIONS_MAX_UPDATE_MS","updateMaxMs","onResize","clearTimeout","timeSinceLast","setTimeout","subscribe","add","delete"],"sources":["../../src/helpers.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,QAAA,QAAgB;AACzB,SAASC,YAAA,QAAoB;AAG7B,IAAIC,QAAA,GAAuBD,YAAA;AAC3B,IAAIE,KAAA,GAA4B;AAEzB,SAASC,cAAA,EAA4B;EAC1C,IAAI,OAAkC;IACpC,OAAOH,YAAA;EACT;EAEAE,KAAA,KAAUE,MAAA,CAAOC,QAAA,CAASC,eAAA;EAE1B,MAAMC,QAAA,GAAuB;IAC3BC,SAAA,EAAW;IACXC,MAAA,EAAQP,KAAA,CAAMQ,YAAA;IACdC,KAAA,EAAOP,MAAA,CAAOQ,gBAAA,IAAoB;IAClCC,KAAA,EAAOX,KAAA,CAAMY;EACf;EAEA,IACEP,QAAA,CAASE,MAAA,KAAWR,QAAA,CAASQ,MAAA,IAC7BF,QAAA,CAASM,KAAA,KAAUZ,QAAA,CAASY,KAAA,IAC5BN,QAAA,CAASI,KAAA,KAAUV,QAAA,CAASU,KAAA,EAC5B;IACAV,QAAA,GAAWM,QAAA;IACX,OAAOA,QAAA;EACT;EAEA,OAAON,QAAA;AACT;AAEA,MAAMc,GAAA,GAAM,mBAAIC,GAAA,CAAwB;AAIxC,IACEjB,QAAA,IACA,OAAOK,MAAA,KAAW,eAClB,OAAOA,MAAA,CAAOa,gBAAA,KAAqB,YACnC;EAMA,IAASC,WAAA,GAAT,SAAAA,CAAA,EAAuB;IACrBC,UAAA,GAAaC,IAAA,CAAKC,GAAA,CAAI;IACtBN,GAAA,CAAIO,OAAA,CAASC,EAAA,IAAOA,EAAA,CAAGpB,aAAA,CAAc,CAAC,CAAC;EACzC;EARA,IAAIgB,UAAA,GAAaC,IAAA,CAAKC,GAAA,CAAI;EAC1B,IAAIG,EAAA;EACJ,MAAMC,WAAA,GAAcC,OAAA,CAAQC,GAAA,CAAIC,uCAAA;EAChC,MAAMC,WAAA,GAAcJ,WAAA,GAAc,CAACA,WAAA,GAAc;EAOjD,MAAMK,QAAA,GAAWA,CAAA,KAAM;IACrBC,YAAA,CAAaP,EAAE;IAGf,MAAMQ,aAAA,GAAgBZ,IAAA,CAAKC,GAAA,CAAI,IAAIF,UAAA;IACnC,IAAIa,aAAA,GAAgBH,WAAA,EAAa;MAC/BL,EAAA,GAAKS,UAAA,CAAW,MAAM;QACpBf,WAAA,CAAY;MACd,GAAGW,WAAA,GAAcG,aAAa;IAChC,OAAO;MACLd,WAAA,CAAY;IACd;EACF;EAEAd,MAAA,CAAOa,gBAAA,CAAiB,UAAUa,QAAQ;AAC5C;AAEO,SAASI,UAAUX,EAAA,EAAoC;EAC5DR,GAAA,CAAIoB,GAAA,CAAIZ,EAAE;EACV,OAAO,MAAMR,GAAA,CAAIqB,MAAA,CAAOb,EAAE;AAC5B","ignoreList":[]}
@@ -12,7 +12,8 @@ Dimensions.addEventListener("change", function (param) {
12
12
  });
13
13
  });
14
14
  function subscribe(cb) {
15
- return cbs.add(cb), function () {
15
+ cbs.add(cb);
16
+ return function () {
16
17
  return cbs.delete(cb);
17
18
  };
18
19
  }
@@ -1 +1 @@
1
- {"version":3,"names":["Dimensions","getWindowSize","get","cbs","Set","addEventListener","param","window","forEach","cb","subscribe","add","delete"],"sources":["../../src/helpers.native.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,UAAA,QAAkB;AACpB,SAASC,cAAA,EAAgB;EAC5B,OAAOD,UAAA,CAAWE,GAAA,CAAI,QAAQ;AAClC;AACA,IAAIC,GAAA,GAAM,mBAAIC,GAAA,CAAI;AAClBJ,UAAA,CAAWK,gBAAA,CAAiB,UAAU,UAASC,KAAA,EAAO;EAClD,IAAI;IAAEC;EAAO,IAAID,KAAA;EACjBH,GAAA,CAAIK,OAAA,CAAQ,UAASC,EAAA,EAAI;IACrB,OAAOA,EAAA,CAAGF,MAAM;EACpB,CAAC;AACL,CAAC;AACM,SAASG,UAAUD,EAAA,EAAI;EAC1B,OAAAN,GAAA,CAAIQ,GAAA,CAAIF,EAAE,GACH,YAAW;IACd,OAAON,GAAA,CAAIS,MAAA,CAAOH,EAAE;EACxB;AACJ","ignoreList":[]}
1
+ {"version":3,"names":["Dimensions","getWindowSize","get","cbs","Set","addEventListener","param","window","forEach","cb","subscribe","add","delete"],"sources":["../../src/helpers.native.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,UAAA,QAAkB;AACpB,SAASC,cAAA,EAAgB;EAC5B,OAAOD,UAAA,CAAWE,GAAA,CAAI,QAAQ;AAClC;AACA,IAAIC,GAAA,GAAM,mBAAIC,GAAA,CAAI;AAClBJ,UAAA,CAAWK,gBAAA,CAAiB,UAAU,UAASC,KAAA,EAAO;EAClD,IAAI;IAAEC;EAAO,IAAID,KAAA;EACjBH,GAAA,CAAIK,OAAA,CAAQ,UAASC,EAAA,EAAI;IACrB,OAAOA,EAAA,CAAGF,MAAM;EACpB,CAAC;AACL,CAAC;AACM,SAASG,UAAUD,EAAA,EAAI;EAC1BN,GAAA,CAAIQ,GAAA,CAAIF,EAAE;EACV,OAAO,YAAW;IACd,OAAON,GAAA,CAAIS,MAAA,CAAOH,EAAE;EACxB;AACJ","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanzogui/use-window-dimensions",
3
- "version": "3.0.6",
3
+ "version": "4.4.0",
4
4
  "gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14",
5
5
  "files": [
6
6
  "src",
@@ -34,10 +34,10 @@
34
34
  "clean:build": "hanzo-gui-build clean:build"
35
35
  },
36
36
  "dependencies": {
37
- "@hanzogui/constants": "3.0.6"
37
+ "@hanzogui/constants": "4.4.0"
38
38
  },
39
39
  "devDependencies": {
40
- "@hanzogui/build": "3.0.6",
40
+ "@hanzogui/build": "4.4.0",
41
41
  "react": ">=19",
42
42
  "react-native": "0.83.2"
43
43
  },
package/src/helpers.ts CHANGED
@@ -6,7 +6,7 @@ let lastSize: WindowSize = initialValue
6
6
  let docEl: HTMLElement | null = null
7
7
 
8
8
  export function getWindowSize(): WindowSize {
9
- if (process.env.HANZO_GUI_TARGET !== 'web') {
9
+ if (process.env.GUI_TARGET !== 'web') {
10
10
  return initialValue
11
11
  }
12
12
 
@@ -34,10 +34,15 @@ export function getWindowSize(): WindowSize {
34
34
  const cbs = new Set<WindowSizeListener>()
35
35
 
36
36
  // only attach resize listener on client (not during SSR)
37
- if (isClient) {
37
+ // also guard window.addEventListener since isClient=true on native but window.addEventListener is undefined
38
+ if (
39
+ isClient &&
40
+ typeof window !== 'undefined' &&
41
+ typeof window.addEventListener === 'function'
42
+ ) {
38
43
  let lastUpdate = Date.now()
39
44
  let tm: ReturnType<typeof setTimeout> | undefined
40
- const USER_MAX_MS = process.env.HANZO_GUI_USE_WINDOW_DIMENSIONS_MAX_UPDATE_MS
45
+ const USER_MAX_MS = process.env.GUI_USE_WINDOW_DIMENSIONS_MAX_UPDATE_MS
41
46
  const updateMaxMs = USER_MAX_MS ? +USER_MAX_MS : 100
42
47
 
43
48
  function flushUpdate() {
@@ -1,11 +1,11 @@
1
1
  {
2
- "mappings": "AAEA,cAAc,YAAY,0BAA0B;AAKpD,OAAO,iBAAS,iBAAiB;AAyDjC,OAAO,iBAAS,UAAU,IAAI",
2
+ "mappings": "AAEA,cAAc,YAAY,0BAA0B;AAKpD,OAAO,iBAAS,iBAAiB;AA8DjC,OAAO,iBAAS,UAAU,IAAI",
3
3
  "names": [],
4
4
  "sources": [
5
5
  "src/helpers.ts"
6
6
  ],
7
7
  "version": 3,
8
8
  "sourcesContent": [
9
- "import { isClient } from '@hanzogui/constants'\nimport { initialValue } from './initialValue'\nimport type { WindowSize, WindowSizeListener } from './types'\n\nlet lastSize: WindowSize = initialValue\nlet docEl: HTMLElement | null = null\n\nexport function getWindowSize(): WindowSize {\n if (process.env.HANZO_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)\nif (isClient) {\n let lastUpdate = Date.now()\n let tm: ReturnType<typeof setTimeout> | undefined\n const USER_MAX_MS = process.env.HANZO_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"
9
+ "import { isClient } from '@hanzogui/constants'\nimport { initialValue } from './initialValue'\nimport type { WindowSize, WindowSizeListener } from './types'\n\nlet lastSize: WindowSize = initialValue\nlet docEl: HTMLElement | null = null\n\nexport function getWindowSize(): WindowSize {\n if (process.env.GUI_TARGET !== 'web') {\n return initialValue\n }\n\n docEl ||= window.document.documentElement\n\n const nextSize: WindowSize = {\n fontScale: 1,\n height: docEl.clientHeight,\n scale: window.devicePixelRatio || 1,\n width: docEl.clientWidth,\n }\n\n if (\n nextSize.height !== lastSize.height ||\n nextSize.width !== lastSize.width ||\n nextSize.scale !== lastSize.scale\n ) {\n lastSize = nextSize\n return nextSize\n }\n\n return lastSize\n}\n\nconst cbs = new Set<WindowSizeListener>()\n\n// only attach resize listener on client (not during SSR)\n// also guard window.addEventListener since isClient=true on native but window.addEventListener is undefined\nif (\n isClient &&\n typeof window !== 'undefined' &&\n typeof window.addEventListener === 'function'\n) {\n let lastUpdate = Date.now()\n let tm: ReturnType<typeof setTimeout> | undefined\n const USER_MAX_MS = process.env.GUI_USE_WINDOW_DIMENSIONS_MAX_UPDATE_MS\n const updateMaxMs = USER_MAX_MS ? +USER_MAX_MS : 100\n\n function flushUpdate() {\n lastUpdate = Date.now()\n cbs.forEach((cb) => cb(getWindowSize()))\n }\n\n const onResize = () => {\n clearTimeout(tm)\n\n // only update every few frames\n const timeSinceLast = Date.now() - lastUpdate\n if (timeSinceLast < updateMaxMs) {\n tm = setTimeout(() => {\n flushUpdate()\n }, updateMaxMs - timeSinceLast)\n } else {\n flushUpdate()\n }\n }\n\n window.addEventListener('resize', onResize)\n}\n\nexport function subscribe(cb: WindowSizeListener): () => void {\n cbs.add(cb)\n return () => cbs.delete(cb)\n}\n"
10
10
  ]
11
11
  }