@tamagui/use-window-dimensions 1.131.2 → 1.131.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/helpers.cjs +23 -18
- package/dist/cjs/helpers.js +16 -16
- package/dist/cjs/helpers.js.map +1 -1
- package/dist/cjs/index.cjs +5 -12
- package/dist/cjs/index.js +3 -12
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/index.native.js +3 -11
- package/dist/cjs/index.native.js.map +2 -2
- package/dist/cjs/initialValue.cjs +35 -0
- package/dist/cjs/initialValue.js +30 -0
- package/dist/cjs/initialValue.js.map +6 -0
- package/dist/cjs/initialValue.native.js +36 -0
- package/dist/cjs/initialValue.native.js.map +6 -0
- package/dist/esm/helpers.js +16 -15
- package/dist/esm/helpers.js.map +1 -1
- package/dist/esm/helpers.mjs +22 -17
- package/dist/esm/helpers.mjs.map +1 -1
- package/dist/esm/index.js +2 -9
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +2 -9
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js +2 -9
- package/dist/esm/index.native.js.map +1 -1
- package/dist/esm/initialValue.js +14 -0
- package/dist/esm/initialValue.js.map +6 -0
- package/dist/esm/initialValue.mjs +11 -0
- package/dist/esm/initialValue.mjs.map +1 -0
- package/dist/esm/initialValue.native.js +11 -0
- package/dist/esm/initialValue.native.js.map +1 -0
- package/package.json +3 -3
- package/src/helpers.ts +42 -19
- package/src/index.ts +2 -14
- package/src/initialValue.ts +15 -0
- package/types/helpers.d.ts.map +2 -2
- package/types/index.d.ts +1 -1
- package/types/index.d.ts.map +3 -5
- package/types/initialValue.d.ts +8 -0
- package/types/initialValue.d.ts.map +14 -0
package/dist/cjs/helpers.cjs
CHANGED
|
@@ -24,32 +24,37 @@ __export(helpers_exports, {
|
|
|
24
24
|
subscribe: () => subscribe
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(helpers_exports);
|
|
27
|
-
var import_constants = require("@tamagui/constants")
|
|
27
|
+
var import_constants = require("@tamagui/constants"),
|
|
28
|
+
import_initialValue = require("./initialValue.cjs");
|
|
29
|
+
let lastSize = import_initialValue.initialValue,
|
|
30
|
+
docEl = null;
|
|
28
31
|
function getWindowSize() {
|
|
29
|
-
if (!import_constants.isClient) return
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
scale: 1,
|
|
33
|
-
fontScale: 1
|
|
34
|
-
};
|
|
35
|
-
const win = window,
|
|
36
|
-
docEl = win.document.documentElement;
|
|
37
|
-
return {
|
|
32
|
+
if (!import_constants.isClient) return import_initialValue.initialValue;
|
|
33
|
+
docEl ||= window.document.documentElement;
|
|
34
|
+
const nextSize = {
|
|
38
35
|
fontScale: 1,
|
|
39
36
|
height: docEl.clientHeight,
|
|
40
|
-
scale:
|
|
37
|
+
scale: window.devicePixelRatio || 1,
|
|
41
38
|
width: docEl.clientWidth
|
|
42
39
|
};
|
|
40
|
+
return nextSize.height !== lastSize.height || nextSize.width !== lastSize.width || nextSize.scale !== lastSize.scale ? (lastSize = nextSize, nextSize) : lastSize;
|
|
43
41
|
}
|
|
44
42
|
const cbs = /* @__PURE__ */new Set();
|
|
45
|
-
let _raf = 0;
|
|
46
43
|
if (import_constants.isClient) {
|
|
47
|
-
let
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
44
|
+
let flushUpdate = function () {
|
|
45
|
+
lastUpdate = Date.now(), cbs.forEach(cb => cb(getWindowSize()));
|
|
46
|
+
},
|
|
47
|
+
lastUpdate = Date.now(),
|
|
48
|
+
tm;
|
|
49
|
+
const USER_MAX_MS = process.env.TAMAGUI_USE_WINDOW_DIMENSIONS_MAX_UPDATE_MS,
|
|
50
|
+
updateMaxMs = USER_MAX_MS ? +USER_MAX_MS : 100,
|
|
51
|
+
onResize = () => {
|
|
52
|
+
clearTimeout(tm);
|
|
53
|
+
const timeSinceLast = Date.now() - lastUpdate;
|
|
54
|
+
timeSinceLast < updateMaxMs ? setTimeout(() => {
|
|
55
|
+
flushUpdate();
|
|
56
|
+
}, updateMaxMs - timeSinceLast) : flushUpdate();
|
|
57
|
+
};
|
|
53
58
|
window.addEventListener("resize", onResize);
|
|
54
59
|
}
|
|
55
60
|
function subscribe(cb) {
|
package/dist/cjs/helpers.js
CHANGED
|
@@ -18,31 +18,31 @@ __export(helpers_exports, {
|
|
|
18
18
|
subscribe: () => subscribe
|
|
19
19
|
});
|
|
20
20
|
module.exports = __toCommonJS(helpers_exports);
|
|
21
|
-
var import_constants = require("@tamagui/constants");
|
|
21
|
+
var import_constants = require("@tamagui/constants"), import_initialValue = require("./initialValue");
|
|
22
|
+
let lastSize = import_initialValue.initialValue, docEl = null;
|
|
22
23
|
function getWindowSize() {
|
|
23
24
|
if (!import_constants.isClient)
|
|
24
|
-
return
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
scale: 1,
|
|
28
|
-
fontScale: 1
|
|
29
|
-
};
|
|
30
|
-
const win = window, docEl = win.document.documentElement;
|
|
31
|
-
return {
|
|
25
|
+
return import_initialValue.initialValue;
|
|
26
|
+
docEl ||= window.document.documentElement;
|
|
27
|
+
const nextSize = {
|
|
32
28
|
fontScale: 1,
|
|
33
29
|
height: docEl.clientHeight,
|
|
34
|
-
scale:
|
|
30
|
+
scale: window.devicePixelRatio || 1,
|
|
35
31
|
width: docEl.clientWidth
|
|
36
32
|
};
|
|
33
|
+
return nextSize.height !== lastSize.height || nextSize.width !== lastSize.width || nextSize.scale !== lastSize.scale ? (lastSize = nextSize, nextSize) : lastSize;
|
|
37
34
|
}
|
|
38
35
|
const cbs = /* @__PURE__ */ new Set();
|
|
39
|
-
let _raf = 0;
|
|
40
36
|
if (import_constants.isClient) {
|
|
41
|
-
let
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
37
|
+
let flushUpdate = function() {
|
|
38
|
+
lastUpdate = Date.now(), cbs.forEach((cb) => cb(getWindowSize()));
|
|
39
|
+
}, lastUpdate = Date.now(), tm;
|
|
40
|
+
const USER_MAX_MS = process.env.TAMAGUI_USE_WINDOW_DIMENSIONS_MAX_UPDATE_MS, updateMaxMs = USER_MAX_MS ? +USER_MAX_MS : 100, onResize = () => {
|
|
41
|
+
clearTimeout(tm);
|
|
42
|
+
const timeSinceLast = Date.now() - lastUpdate;
|
|
43
|
+
timeSinceLast < updateMaxMs ? setTimeout(() => {
|
|
44
|
+
flushUpdate();
|
|
45
|
+
}, updateMaxMs - timeSinceLast) : flushUpdate();
|
|
46
46
|
};
|
|
47
47
|
window.addEventListener("resize", onResize);
|
|
48
48
|
}
|
package/dist/cjs/helpers.js.map
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/helpers.ts"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAyB;
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAyB,+BACzB,sBAA6B;AAG7B,IAAI,WAAuB,kCACvB,QAA4B;AAEzB,SAAS,gBAA4B;AAC1C,MAAI,CAAC;AACH,WAAO;AAGT,YAAU,OAAO,SAAS;AAE1B,QAAM,WAAuB;AAAA,IAC3B,WAAW;AAAA,IACX,QAAQ,MAAM;AAAA,IACd,OAAO,OAAO,oBAAoB;AAAA,IAClC,OAAO,MAAM;AAAA,EACf;AAEA,SACE,SAAS,WAAW,SAAS,UAC7B,SAAS,UAAU,SAAS,SAC5B,SAAS,UAAU,SAAS,SAE5B,WAAW,UACJ,YAGF;AACT;AAEA,MAAM,MAAM,oBAAI,IAAwB;AAExC,IAAI,2BAAU;AAMZ,MAAS,cAAT,WAAuB;AACrB,iBAAa,KAAK,IAAI,GACtB,IAAI,QAAQ,CAAC,OAAO,GAAG,cAAc,CAAC,CAAC;AAAA,EACzC,GARI,aAAa,KAAK,IAAI,GACtB;AACJ,QAAM,cAAc,QAAQ,IAAI,6CAC1B,cAAc,cAAc,CAAC,cAAc,KAO3C,WAAW,MAAM;AACrB,iBAAa,EAAE;AAGf,UAAM,gBAAgB,KAAK,IAAI,IAAI;AACnC,IAAI,gBAAgB,cAClB,WAAW,MAAM;AACf,kBAAY;AAAA,IACd,GAAG,cAAc,aAAa,IAE9B,YAAY;AAAA,EAEhB;AAEA,SAAO,iBAAiB,UAAU,QAAQ;AAC5C;AAEO,SAAS,UAAU,IAAoC;AAC5D,aAAI,IAAI,EAAE,GACH,MAAM,IAAI,OAAO,EAAE;AAC5B;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -31,24 +31,17 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
31
31
|
}), mod);
|
|
32
32
|
var index_exports = {};
|
|
33
33
|
__export(index_exports, {
|
|
34
|
-
configureInitialWindowDimensions: () => configureInitialWindowDimensions,
|
|
34
|
+
configureInitialWindowDimensions: () => import_initialValue2.configureInitialWindowDimensions,
|
|
35
35
|
useWindowDimensions: () => useWindowDimensions
|
|
36
36
|
});
|
|
37
37
|
module.exports = __toCommonJS(index_exports);
|
|
38
38
|
var import_react = __toESM(require("react")),
|
|
39
39
|
import_constants = require("@tamagui/constants"),
|
|
40
|
-
import_helpers = require("./helpers.cjs")
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
height: 600,
|
|
44
|
-
scale: 1,
|
|
45
|
-
fontScale: 1
|
|
46
|
-
};
|
|
47
|
-
function configureInitialWindowDimensions(next) {
|
|
48
|
-
Object.assign(initialValue, next);
|
|
49
|
-
}
|
|
40
|
+
import_helpers = require("./helpers.cjs"),
|
|
41
|
+
import_initialValue = require("./initialValue.cjs"),
|
|
42
|
+
import_initialValue2 = require("./initialValue.cjs");
|
|
50
43
|
function useWindowDimensions({
|
|
51
|
-
serverValue = initialValue
|
|
44
|
+
serverValue = import_initialValue.initialValue
|
|
52
45
|
} = {}) {
|
|
53
46
|
return import_react.default.useSyncExternalStore(import_helpers.subscribe, import_helpers.getWindowSize, () => import_constants.isWeb ? serverValue : (0, import_helpers.getWindowSize)());
|
|
54
47
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -22,22 +22,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
22
|
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
23
23
|
var index_exports = {};
|
|
24
24
|
__export(index_exports, {
|
|
25
|
-
configureInitialWindowDimensions: () => configureInitialWindowDimensions,
|
|
25
|
+
configureInitialWindowDimensions: () => import_initialValue2.configureInitialWindowDimensions,
|
|
26
26
|
useWindowDimensions: () => useWindowDimensions
|
|
27
27
|
});
|
|
28
28
|
module.exports = __toCommonJS(index_exports);
|
|
29
|
-
var import_react = __toESM(require("react")), import_constants = require("@tamagui/constants"), import_helpers = require("./helpers");
|
|
30
|
-
const initialValue = {
|
|
31
|
-
width: 800,
|
|
32
|
-
height: 600,
|
|
33
|
-
scale: 1,
|
|
34
|
-
fontScale: 1
|
|
35
|
-
};
|
|
36
|
-
function configureInitialWindowDimensions(next) {
|
|
37
|
-
Object.assign(initialValue, next);
|
|
38
|
-
}
|
|
29
|
+
var import_react = __toESM(require("react")), import_constants = require("@tamagui/constants"), import_helpers = require("./helpers"), import_initialValue = require("./initialValue"), import_initialValue2 = require("./initialValue");
|
|
39
30
|
function useWindowDimensions({
|
|
40
|
-
serverValue = initialValue
|
|
31
|
+
serverValue = import_initialValue.initialValue
|
|
41
32
|
} = {}) {
|
|
42
33
|
return import_react.default.useSyncExternalStore(
|
|
43
34
|
import_helpers.subscribe,
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB,2BAClB,mBAAsB,+BAEtB,iBAAyC
|
|
5
|
-
"names": ["React"]
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB,2BAClB,mBAAsB,+BAEtB,iBAAyC,sBAEzC,sBAA6B,2BAE7BA,uBAAiD;AAE1C,SAAS,oBAAoB;AAAA,EAClC,cAAc;AAChB,IAAkC,CAAC,GAAe;AAChD,SAAO,aAAAC,QAAM;AAAA,IAAqB;AAAA,IAAW;AAAA,IAAe,MAC1D,yBAAQ,kBAAc,8BAAc;AAAA,EACtC;AACF;",
|
|
5
|
+
"names": ["import_initialValue", "React"]
|
|
6
6
|
}
|
package/dist/cjs/index.native.js
CHANGED
|
@@ -23,21 +23,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
24
24
|
var index_exports = {};
|
|
25
25
|
__export(index_exports, {
|
|
26
|
-
configureInitialWindowDimensions: () => configureInitialWindowDimensions,
|
|
26
|
+
configureInitialWindowDimensions: () => import_initialValue2.configureInitialWindowDimensions,
|
|
27
27
|
useWindowDimensions: () => useWindowDimensions
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(index_exports);
|
|
30
|
-
var import_react = __toESM(require("react")), import_constants = require("@tamagui/constants"), import_helpers = require("./helpers"), initialValue =
|
|
31
|
-
width: 800,
|
|
32
|
-
height: 600,
|
|
33
|
-
scale: 1,
|
|
34
|
-
fontScale: 1
|
|
35
|
-
};
|
|
36
|
-
function configureInitialWindowDimensions(next) {
|
|
37
|
-
Object.assign(initialValue, next);
|
|
38
|
-
}
|
|
30
|
+
var import_react = __toESM(require("react")), import_constants = require("@tamagui/constants"), import_helpers = require("./helpers"), import_initialValue = require("./initialValue"), import_initialValue2 = require("./initialValue");
|
|
39
31
|
function useWindowDimensions() {
|
|
40
|
-
var { serverValue = initialValue } = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
32
|
+
var { serverValue = import_initialValue.initialValue } = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
41
33
|
return import_react.default.useSyncExternalStore(import_helpers.subscribe, import_helpers.getWindowSize, function() {
|
|
42
34
|
return import_constants.isWeb ? serverValue : (0, import_helpers.getWindowSize)();
|
|
43
35
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;mBAAkB,2BAClB,mBAAsB,+BAEtB,iBAAyC,
|
|
5
|
-
"names": ["
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;mBAAkB,2BAClB,mBAAsB,+BAEtB,iBAAyC,sBAEzC,sBAA6B,2BAE7BA,uBAAiD;AAE1C,SAASC,sBAAAA;MAAoB,EAClCC,cAAcC,iCAAY,IADQ,UAAA,SAAA,KAAA,UAAA,CAAA,MAAA,SAAA,UAAA,CAAA,IAEF,CAAC;AACjC,SAAOC,aAAAA,QAAMC,qBAAqBC,0BAAWC,8BAAe,WAAA;WAC1DC,yBAAQN,kBAAcK,8BAAAA;;AAE1B;",
|
|
5
|
+
"names": ["import_initialValue", "useWindowDimensions", "serverValue", "initialValue", "React", "useSyncExternalStore", "subscribe", "getWindowSize", "isWeb"]
|
|
6
6
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
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: !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, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), mod);
|
|
21
|
+
var initialValue_exports = {};
|
|
22
|
+
__export(initialValue_exports, {
|
|
23
|
+
configureInitialWindowDimensions: () => configureInitialWindowDimensions,
|
|
24
|
+
initialValue: () => initialValue
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(initialValue_exports);
|
|
27
|
+
const initialValue = {
|
|
28
|
+
width: 800,
|
|
29
|
+
height: 600,
|
|
30
|
+
scale: 1,
|
|
31
|
+
fontScale: 1
|
|
32
|
+
};
|
|
33
|
+
function configureInitialWindowDimensions(next) {
|
|
34
|
+
Object.assign(initialValue, next);
|
|
35
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
8
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
15
|
+
var initialValue_exports = {};
|
|
16
|
+
__export(initialValue_exports, {
|
|
17
|
+
configureInitialWindowDimensions: () => configureInitialWindowDimensions,
|
|
18
|
+
initialValue: () => initialValue
|
|
19
|
+
});
|
|
20
|
+
module.exports = __toCommonJS(initialValue_exports);
|
|
21
|
+
const initialValue = {
|
|
22
|
+
width: 800,
|
|
23
|
+
height: 600,
|
|
24
|
+
scale: 1,
|
|
25
|
+
fontScale: 1
|
|
26
|
+
};
|
|
27
|
+
function configureInitialWindowDimensions(next) {
|
|
28
|
+
Object.assign(initialValue, next);
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=initialValue.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/initialValue.ts"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKO,MAAM,eAA2B;AAAA,EACtC,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,WAAW;AACb;AAEO,SAAS,iCAAiC,MAAwB;AACvE,SAAO,OAAO,cAAc,IAAI;AAClC;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
9
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
return to;
|
|
14
|
+
};
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
16
|
+
var initialValue_exports = {};
|
|
17
|
+
__export(initialValue_exports, {
|
|
18
|
+
configureInitialWindowDimensions: () => configureInitialWindowDimensions,
|
|
19
|
+
initialValue: () => initialValue
|
|
20
|
+
});
|
|
21
|
+
module.exports = __toCommonJS(initialValue_exports);
|
|
22
|
+
var initialValue = {
|
|
23
|
+
width: 800,
|
|
24
|
+
height: 600,
|
|
25
|
+
scale: 1,
|
|
26
|
+
fontScale: 1
|
|
27
|
+
};
|
|
28
|
+
function configureInitialWindowDimensions(next) {
|
|
29
|
+
Object.assign(initialValue, next);
|
|
30
|
+
}
|
|
31
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
+
0 && (module.exports = {
|
|
33
|
+
configureInitialWindowDimensions,
|
|
34
|
+
initialValue
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=initialValue.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/initialValue.ts"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;AAEA;;;;;;AAGO,IAAMA,eAA2B;EACtCC,OAAO;EACPC,QAAQ;EACRC,OAAO;EACPC,WAAW;AACb;AAEO,SAASC,iCAAiCC,MAAgB;AAC/DC,SAAOC,OAAOR,cAAcM,IAAAA;AAC9B;",
|
|
5
|
+
"names": ["initialValue", "width", "height", "scale", "fontScale", "configureInitialWindowDimensions", "next", "Object", "assign"]
|
|
6
|
+
}
|
package/dist/esm/helpers.js
CHANGED
|
@@ -1,28 +1,29 @@
|
|
|
1
1
|
import { isClient } from "@tamagui/constants";
|
|
2
|
+
import { initialValue } from "./initialValue";
|
|
3
|
+
let lastSize = initialValue, docEl = null;
|
|
2
4
|
function getWindowSize() {
|
|
3
5
|
if (!isClient)
|
|
4
|
-
return
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
scale: 1,
|
|
8
|
-
fontScale: 1
|
|
9
|
-
};
|
|
10
|
-
const win = window, docEl = win.document.documentElement;
|
|
11
|
-
return {
|
|
6
|
+
return initialValue;
|
|
7
|
+
docEl ||= window.document.documentElement;
|
|
8
|
+
const nextSize = {
|
|
12
9
|
fontScale: 1,
|
|
13
10
|
height: docEl.clientHeight,
|
|
14
|
-
scale:
|
|
11
|
+
scale: window.devicePixelRatio || 1,
|
|
15
12
|
width: docEl.clientWidth
|
|
16
13
|
};
|
|
14
|
+
return nextSize.height !== lastSize.height || nextSize.width !== lastSize.width || nextSize.scale !== lastSize.scale ? (lastSize = nextSize, nextSize) : lastSize;
|
|
17
15
|
}
|
|
18
16
|
const cbs = /* @__PURE__ */ new Set();
|
|
19
|
-
let _raf = 0;
|
|
20
17
|
if (isClient) {
|
|
21
|
-
let
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
let flushUpdate = function() {
|
|
19
|
+
lastUpdate = Date.now(), cbs.forEach((cb) => cb(getWindowSize()));
|
|
20
|
+
}, lastUpdate = Date.now(), tm;
|
|
21
|
+
const USER_MAX_MS = process.env.TAMAGUI_USE_WINDOW_DIMENSIONS_MAX_UPDATE_MS, updateMaxMs = USER_MAX_MS ? +USER_MAX_MS : 100, onResize = () => {
|
|
22
|
+
clearTimeout(tm);
|
|
23
|
+
const timeSinceLast = Date.now() - lastUpdate;
|
|
24
|
+
timeSinceLast < updateMaxMs ? setTimeout(() => {
|
|
25
|
+
flushUpdate();
|
|
26
|
+
}, updateMaxMs - timeSinceLast) : flushUpdate();
|
|
26
27
|
};
|
|
27
28
|
window.addEventListener("resize", onResize);
|
|
28
29
|
}
|
package/dist/esm/helpers.js.map
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/helpers.ts"],
|
|
4
|
-
"mappings": "AAAA,SAAS,gBAAgB;
|
|
4
|
+
"mappings": "AAAA,SAAS,gBAAgB;AACzB,SAAS,oBAAoB;AAG7B,IAAI,WAAuB,cACvB,QAA4B;AAEzB,SAAS,gBAA4B;AAC1C,MAAI,CAAC;AACH,WAAO;AAGT,YAAU,OAAO,SAAS;AAE1B,QAAM,WAAuB;AAAA,IAC3B,WAAW;AAAA,IACX,QAAQ,MAAM;AAAA,IACd,OAAO,OAAO,oBAAoB;AAAA,IAClC,OAAO,MAAM;AAAA,EACf;AAEA,SACE,SAAS,WAAW,SAAS,UAC7B,SAAS,UAAU,SAAS,SAC5B,SAAS,UAAU,SAAS,SAE5B,WAAW,UACJ,YAGF;AACT;AAEA,MAAM,MAAM,oBAAI,IAAwB;AAExC,IAAI,UAAU;AAMZ,MAAS,cAAT,WAAuB;AACrB,iBAAa,KAAK,IAAI,GACtB,IAAI,QAAQ,CAAC,OAAO,GAAG,cAAc,CAAC,CAAC;AAAA,EACzC,GARI,aAAa,KAAK,IAAI,GACtB;AACJ,QAAM,cAAc,QAAQ,IAAI,6CAC1B,cAAc,cAAc,CAAC,cAAc,KAO3C,WAAW,MAAM;AACrB,iBAAa,EAAE;AAGf,UAAM,gBAAgB,KAAK,IAAI,IAAI;AACnC,IAAI,gBAAgB,cAClB,WAAW,MAAM;AACf,kBAAY;AAAA,IACd,GAAG,cAAc,aAAa,IAE9B,YAAY;AAAA,EAEhB;AAEA,SAAO,iBAAiB,UAAU,QAAQ;AAC5C;AAEO,SAAS,UAAU,IAAoC;AAC5D,aAAI,IAAI,EAAE,GACH,MAAM,IAAI,OAAO,EAAE;AAC5B;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
package/dist/esm/helpers.mjs
CHANGED
|
@@ -1,29 +1,34 @@
|
|
|
1
1
|
import { isClient } from "@tamagui/constants";
|
|
2
|
+
import { initialValue } from "./initialValue.mjs";
|
|
3
|
+
let lastSize = initialValue,
|
|
4
|
+
docEl = null;
|
|
2
5
|
function getWindowSize() {
|
|
3
|
-
if (!isClient) return
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
scale: 1,
|
|
7
|
-
fontScale: 1
|
|
8
|
-
};
|
|
9
|
-
const win = window,
|
|
10
|
-
docEl = win.document.documentElement;
|
|
11
|
-
return {
|
|
6
|
+
if (!isClient) return initialValue;
|
|
7
|
+
docEl ||= window.document.documentElement;
|
|
8
|
+
const nextSize = {
|
|
12
9
|
fontScale: 1,
|
|
13
10
|
height: docEl.clientHeight,
|
|
14
|
-
scale:
|
|
11
|
+
scale: window.devicePixelRatio || 1,
|
|
15
12
|
width: docEl.clientWidth
|
|
16
13
|
};
|
|
14
|
+
return nextSize.height !== lastSize.height || nextSize.width !== lastSize.width || nextSize.scale !== lastSize.scale ? (lastSize = nextSize, nextSize) : lastSize;
|
|
17
15
|
}
|
|
18
16
|
const cbs = /* @__PURE__ */new Set();
|
|
19
|
-
let _raf = 0;
|
|
20
17
|
if (isClient) {
|
|
21
|
-
let
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
let flushUpdate = function () {
|
|
19
|
+
lastUpdate = Date.now(), cbs.forEach(cb => cb(getWindowSize()));
|
|
20
|
+
},
|
|
21
|
+
lastUpdate = Date.now(),
|
|
22
|
+
tm;
|
|
23
|
+
const USER_MAX_MS = process.env.TAMAGUI_USE_WINDOW_DIMENSIONS_MAX_UPDATE_MS,
|
|
24
|
+
updateMaxMs = USER_MAX_MS ? +USER_MAX_MS : 100,
|
|
25
|
+
onResize = () => {
|
|
26
|
+
clearTimeout(tm);
|
|
27
|
+
const timeSinceLast = Date.now() - lastUpdate;
|
|
28
|
+
timeSinceLast < updateMaxMs ? setTimeout(() => {
|
|
29
|
+
flushUpdate();
|
|
30
|
+
}, updateMaxMs - timeSinceLast) : flushUpdate();
|
|
31
|
+
};
|
|
27
32
|
window.addEventListener("resize", onResize);
|
|
28
33
|
}
|
|
29
34
|
function subscribe(cb) {
|
package/dist/esm/helpers.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["isClient","
|
|
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","TAMAGUI_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;EAC1C,IAAI,CAACJ,QAAA,EACH,OAAOC,YAAA;EAGTE,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,OACEP,QAAA,CAASE,MAAA,KAAWR,QAAA,CAASQ,MAAA,IAC7BF,QAAA,CAASM,KAAA,KAAUZ,QAAA,CAASY,KAAA,IAC5BN,QAAA,CAASI,KAAA,KAAUV,QAAA,CAASU,KAAA,IAE5BV,QAAA,GAAWM,QAAA,EACJA,QAAA,IAGFN,QAAA;AACT;AAEA,MAAMc,GAAA,GAAM,mBAAIC,GAAA,CAAwB;AAExC,IAAIjB,QAAA,EAAU;EAMZ,IAASkB,WAAA,GAAT,SAAAA,CAAA,EAAuB;MACrBC,UAAA,GAAaC,IAAA,CAAKC,GAAA,CAAI,GACtBL,GAAA,CAAIM,OAAA,CAASC,EAAA,IAAOA,EAAA,CAAGnB,aAAA,CAAc,CAAC,CAAC;IACzC;IARIe,UAAA,GAAaC,IAAA,CAAKC,GAAA,CAAI;IACtBG,EAAA;EACJ,MAAMC,WAAA,GAAcC,OAAA,CAAQC,GAAA,CAAIC,2CAAA;IAC1BC,WAAA,GAAcJ,WAAA,GAAc,CAACA,WAAA,GAAc;IAO3CK,QAAA,GAAWA,CAAA,KAAM;MACrBC,YAAA,CAAaP,EAAE;MAGf,MAAMQ,aAAA,GAAgBZ,IAAA,CAAKC,GAAA,CAAI,IAAIF,UAAA;MAC/Ba,aAAA,GAAgBH,WAAA,GAClBI,UAAA,CAAW,MAAM;QACff,WAAA,CAAY;MACd,GAAGW,WAAA,GAAcG,aAAa,IAE9Bd,WAAA,CAAY;IAEhB;EAEAb,MAAA,CAAO6B,gBAAA,CAAiB,UAAUJ,QAAQ;AAC5C;AAEO,SAASK,UAAUZ,EAAA,EAAoC;EAC5D,OAAAP,GAAA,CAAIoB,GAAA,CAAIb,EAAE,GACH,MAAMP,GAAA,CAAIqB,MAAA,CAAOd,EAAE;AAC5B","ignoreList":[]}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { isWeb } from "@tamagui/constants";
|
|
3
3
|
import { getWindowSize, subscribe } from "./helpers";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
height: 600,
|
|
7
|
-
scale: 1,
|
|
8
|
-
fontScale: 1
|
|
9
|
-
};
|
|
10
|
-
function configureInitialWindowDimensions(next) {
|
|
11
|
-
Object.assign(initialValue, next);
|
|
12
|
-
}
|
|
4
|
+
import { initialValue } from "./initialValue";
|
|
5
|
+
import { configureInitialWindowDimensions } from "./initialValue";
|
|
13
6
|
function useWindowDimensions({
|
|
14
7
|
serverValue = initialValue
|
|
15
8
|
} = {}) {
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
|
-
"mappings": "AAAA,OAAO,WAAW;AAClB,SAAS,aAAa;AAEtB,SAAS,eAAe,iBAAiB;
|
|
4
|
+
"mappings": "AAAA,OAAO,WAAW;AAClB,SAAS,aAAa;AAEtB,SAAS,eAAe,iBAAiB;AAEzC,SAAS,oBAAoB;AAE7B,SAAS,wCAAwC;AAE1C,SAAS,oBAAoB;AAAA,EAClC,cAAc;AAChB,IAAkC,CAAC,GAAe;AAChD,SAAO,MAAM;AAAA,IAAqB;AAAA,IAAW;AAAA,IAAe,MAC1D,QAAQ,cAAc,cAAc;AAAA,EACtC;AACF;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { isWeb } from "@tamagui/constants";
|
|
3
3
|
import { getWindowSize, subscribe } from "./helpers.mjs";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
height: 600,
|
|
7
|
-
scale: 1,
|
|
8
|
-
fontScale: 1
|
|
9
|
-
};
|
|
10
|
-
function configureInitialWindowDimensions(next) {
|
|
11
|
-
Object.assign(initialValue, next);
|
|
12
|
-
}
|
|
4
|
+
import { initialValue } from "./initialValue.mjs";
|
|
5
|
+
import { configureInitialWindowDimensions } from "./initialValue.mjs";
|
|
13
6
|
function useWindowDimensions({
|
|
14
7
|
serverValue = initialValue
|
|
15
8
|
} = {}) {
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","isWeb","getWindowSize","subscribe","initialValue","
|
|
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
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { isWeb } from "@tamagui/constants";
|
|
3
3
|
import { getWindowSize, subscribe } from "./helpers.native.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
height: 600,
|
|
7
|
-
scale: 1,
|
|
8
|
-
fontScale: 1
|
|
9
|
-
};
|
|
10
|
-
function configureInitialWindowDimensions(next) {
|
|
11
|
-
Object.assign(initialValue, next);
|
|
12
|
-
}
|
|
4
|
+
import { initialValue } from "./initialValue.native.js";
|
|
5
|
+
import { configureInitialWindowDimensions } from "./initialValue.native.js";
|
|
13
6
|
function useWindowDimensions() {
|
|
14
7
|
var {
|
|
15
8
|
serverValue = initialValue
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","isWeb","getWindowSize","subscribe","initialValue","
|
|
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,14 @@
|
|
|
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 {
|
|
11
|
+
configureInitialWindowDimensions,
|
|
12
|
+
initialValue
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=initialValue.js.map
|
|
@@ -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":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/use-window-dimensions",
|
|
3
|
-
"version": "1.131.
|
|
3
|
+
"version": "1.131.3",
|
|
4
4
|
"types": "./types/index.d.ts",
|
|
5
5
|
"main": "dist/cjs",
|
|
6
6
|
"module": "dist/esm",
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@tamagui/constants": "1.131.
|
|
34
|
+
"@tamagui/constants": "1.131.3"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@tamagui/build": "1.131.
|
|
37
|
+
"@tamagui/build": "1.131.3",
|
|
38
38
|
"react": "*",
|
|
39
39
|
"react-native": "^0.79.2"
|
|
40
40
|
},
|
package/src/helpers.ts
CHANGED
|
@@ -1,38 +1,61 @@
|
|
|
1
1
|
import { isClient } from '@tamagui/constants'
|
|
2
|
+
import { initialValue } from './initialValue'
|
|
2
3
|
import type { WindowSize, WindowSizeListener } from './types'
|
|
3
4
|
|
|
5
|
+
let lastSize: WindowSize = initialValue
|
|
6
|
+
let docEl: HTMLElement | null = null
|
|
7
|
+
|
|
4
8
|
export function getWindowSize(): WindowSize {
|
|
5
9
|
if (!isClient) {
|
|
6
|
-
return
|
|
7
|
-
width: 800,
|
|
8
|
-
height: 600,
|
|
9
|
-
scale: 1,
|
|
10
|
-
fontScale: 1,
|
|
11
|
-
}
|
|
10
|
+
return initialValue
|
|
12
11
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
|
|
13
|
+
docEl ||= window.document.documentElement
|
|
14
|
+
|
|
15
|
+
const nextSize: WindowSize = {
|
|
16
16
|
fontScale: 1,
|
|
17
17
|
height: docEl.clientHeight,
|
|
18
|
-
scale:
|
|
18
|
+
scale: window.devicePixelRatio || 1,
|
|
19
19
|
width: docEl.clientWidth,
|
|
20
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
|
|
21
32
|
}
|
|
22
33
|
|
|
23
34
|
const cbs = new Set<WindowSizeListener>()
|
|
24
|
-
let _raf = 0
|
|
25
35
|
|
|
26
36
|
if (isClient) {
|
|
27
|
-
let
|
|
37
|
+
let lastUpdate = Date.now()
|
|
38
|
+
let tm
|
|
39
|
+
const USER_MAX_MS = process.env.TAMAGUI_USE_WINDOW_DIMENSIONS_MAX_UPDATE_MS
|
|
40
|
+
const updateMaxMs = USER_MAX_MS ? +USER_MAX_MS : 100
|
|
41
|
+
|
|
42
|
+
function flushUpdate() {
|
|
43
|
+
lastUpdate = Date.now()
|
|
44
|
+
cbs.forEach((cb) => cb(getWindowSize()))
|
|
45
|
+
}
|
|
46
|
+
|
|
28
47
|
const onResize = () => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
48
|
+
clearTimeout(tm)
|
|
49
|
+
|
|
50
|
+
// only update every few frames
|
|
51
|
+
const timeSinceLast = Date.now() - lastUpdate
|
|
52
|
+
if (timeSinceLast < updateMaxMs) {
|
|
53
|
+
setTimeout(() => {
|
|
54
|
+
flushUpdate()
|
|
55
|
+
}, updateMaxMs - timeSinceLast)
|
|
56
|
+
} else {
|
|
57
|
+
flushUpdate()
|
|
58
|
+
}
|
|
36
59
|
}
|
|
37
60
|
|
|
38
61
|
window.addEventListener('resize', onResize)
|
package/src/index.ts
CHANGED
|
@@ -3,21 +3,9 @@ import { isWeb } from '@tamagui/constants'
|
|
|
3
3
|
|
|
4
4
|
import { getWindowSize, subscribe } from './helpers'
|
|
5
5
|
import type { WindowSize } from './types'
|
|
6
|
+
import { initialValue } from './initialValue'
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
* SSR safe useWindowDimensions
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
const initialValue: WindowSize = {
|
|
12
|
-
width: 800,
|
|
13
|
-
height: 600,
|
|
14
|
-
scale: 1,
|
|
15
|
-
fontScale: 1,
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function configureInitialWindowDimensions(next: WindowSize): void {
|
|
19
|
-
Object.assign(initialValue, next)
|
|
20
|
-
}
|
|
8
|
+
export { configureInitialWindowDimensions } from './initialValue'
|
|
21
9
|
|
|
22
10
|
export function useWindowDimensions({
|
|
23
11
|
serverValue = initialValue,
|
|
@@ -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/types/helpers.d.ts.map
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"mappings": "
|
|
2
|
+
"mappings": "AAEA,cAAc,YAAY,0BAA0B,SAAS;AAK7D,OAAO,iBAAS,iBAAiB;AAwDjC,OAAO,iBAAS,UAAUA,IAAI",
|
|
3
3
|
"names": [
|
|
4
4
|
"cb: WindowSizeListener"
|
|
5
5
|
],
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"src/helpers.ts"
|
|
8
8
|
],
|
|
9
9
|
"sourcesContent": [
|
|
10
|
-
"import { isClient } from '@tamagui/constants'\nimport type { WindowSize, WindowSizeListener } from './types'\n\nexport function getWindowSize(): WindowSize {\n if (!isClient) {\n return
|
|
10
|
+
"import { isClient } from '@tamagui/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 (!isClient) {\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\nif (isClient) {\n let lastUpdate = Date.now()\n let tm\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 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"
|
|
11
11
|
],
|
|
12
12
|
"version": 3
|
|
13
13
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { WindowSize } from "./types";
|
|
2
|
-
export
|
|
2
|
+
export { configureInitialWindowDimensions } from "./initialValue";
|
|
3
3
|
export declare function useWindowDimensions({ serverValue }?: {
|
|
4
4
|
serverValue?: WindowSize;
|
|
5
5
|
}): WindowSize;
|
package/types/index.d.ts.map
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"mappings": "AAIA,cAAc,kBAAkB,SAAS;
|
|
3
|
-
"names": [
|
|
4
|
-
"next: WindowSize"
|
|
5
|
-
],
|
|
2
|
+
"mappings": "AAIA,cAAc,kBAAkB,SAAS;AAGzC,SAAS,wCAAwC;AAEjD,OAAO,iBAAS,oBAAoB,EAClC,aAC6B,GAA5B;CAAE,cAAc;AAAY,IAAQ",
|
|
3
|
+
"names": [],
|
|
6
4
|
"sources": [
|
|
7
5
|
"src/index.ts"
|
|
8
6
|
],
|
|
9
7
|
"sourcesContent": [
|
|
10
|
-
"import React from 'react'\nimport { isWeb } from '@tamagui/constants'\n\nimport { getWindowSize, subscribe } from './helpers'\nimport type { WindowSize } from './types'\
|
|
8
|
+
"import React from 'react'\nimport { isWeb } from '@tamagui/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"
|
|
11
9
|
],
|
|
12
10
|
"version": 3
|
|
13
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,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mappings": "AAAA,cAAc,kBAAkB,SAAS;;;;AAKzC,OAAO,cAAMA,cAAc;AAO3B,OAAO,iBAAS,iCAAiCC,MAAM",
|
|
3
|
+
"names": [
|
|
4
|
+
"initialValue: WindowSize",
|
|
5
|
+
"next: WindowSize"
|
|
6
|
+
],
|
|
7
|
+
"sources": [
|
|
8
|
+
"src/initialValue.ts"
|
|
9
|
+
],
|
|
10
|
+
"sourcesContent": [
|
|
11
|
+
"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"
|
|
12
|
+
],
|
|
13
|
+
"version": 3
|
|
14
|
+
}
|