@radix-ui/react-use-size 1.0.1 → 1.1.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +67 -58
- package/dist/index.js.map +7 -1
- package/dist/index.mjs +39 -55
- package/dist/index.mjs.map +7 -1
- package/package.json +4 -4
- package/dist/index.d.ts.map +0 -1
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,61 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
10
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
11
|
+
}) : x)(function(x) {
|
|
12
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
13
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
14
|
+
});
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from))
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
3
31
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
setSize({
|
|
40
|
-
width: width,
|
|
41
|
-
height: height
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
resizeObserver.observe(element, {
|
|
45
|
-
box: 'border-box'
|
|
46
|
-
});
|
|
47
|
-
return ()=>resizeObserver.unobserve(element)
|
|
48
|
-
;
|
|
49
|
-
} else // We only want to reset to `undefined` when the element becomes `null`,
|
|
50
|
-
// not if it changes to another element.
|
|
51
|
-
setSize(undefined);
|
|
52
|
-
}, [
|
|
53
|
-
element
|
|
54
|
-
]);
|
|
32
|
+
// packages/react/use-size/src/useSize.tsx
|
|
33
|
+
var React = __toESM(__require("react"));
|
|
34
|
+
var import_react_use_layout_effect = __require("@radix-ui/react-use-layout-effect");
|
|
35
|
+
function useSize(element) {
|
|
36
|
+
const [size, setSize] = React.useState(void 0);
|
|
37
|
+
(0, import_react_use_layout_effect.useLayoutEffect)(() => {
|
|
38
|
+
if (element) {
|
|
39
|
+
setSize({ width: element.offsetWidth, height: element.offsetHeight });
|
|
40
|
+
const resizeObserver = new ResizeObserver((entries) => {
|
|
41
|
+
if (!Array.isArray(entries)) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (!entries.length) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const entry = entries[0];
|
|
48
|
+
let width;
|
|
49
|
+
let height;
|
|
50
|
+
if ("borderBoxSize" in entry) {
|
|
51
|
+
const borderSizeEntry = entry["borderBoxSize"];
|
|
52
|
+
const borderSize = Array.isArray(borderSizeEntry) ? borderSizeEntry[0] : borderSizeEntry;
|
|
53
|
+
width = borderSize["inlineSize"];
|
|
54
|
+
height = borderSize["blockSize"];
|
|
55
|
+
} else {
|
|
56
|
+
width = element.offsetWidth;
|
|
57
|
+
height = element.offsetHeight;
|
|
58
|
+
}
|
|
59
|
+
setSize({ width, height });
|
|
60
|
+
});
|
|
61
|
+
resizeObserver.observe(element, { box: "border-box" });
|
|
62
|
+
return () => resizeObserver.unobserve(element);
|
|
63
|
+
} else {
|
|
64
|
+
setSize(void 0);
|
|
65
|
+
}
|
|
66
|
+
}, [element]);
|
|
55
67
|
return size;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
68
|
+
}
|
|
69
|
+
})();
|
|
61
70
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/useSize.tsx"],
|
|
4
|
+
"sourcesContent": ["/// <reference types=\"resize-observer-browser\" />\n\nimport * as React from 'react';\nimport { useLayoutEffect } from '@radix-ui/react-use-layout-effect';\n\nfunction useSize(element: HTMLElement | null) {\n const [size, setSize] = React.useState<{ width: number; height: number } | undefined>(undefined);\n\n useLayoutEffect(() => {\n if (element) {\n // provide size as early as possible\n setSize({ width: element.offsetWidth, height: element.offsetHeight });\n\n const resizeObserver = new ResizeObserver((entries) => {\n if (!Array.isArray(entries)) {\n return;\n }\n\n // Since we only observe the one element, we don't need to loop over the\n // array\n if (!entries.length) {\n return;\n }\n\n const entry = entries[0];\n let width: number;\n let height: number;\n\n if ('borderBoxSize' in entry) {\n const borderSizeEntry = entry['borderBoxSize'];\n // iron out differences between browsers\n const borderSize = Array.isArray(borderSizeEntry) ? borderSizeEntry[0] : borderSizeEntry;\n width = borderSize['inlineSize'];\n height = borderSize['blockSize'];\n } else {\n // for browsers that don't support `borderBoxSize`\n // we calculate it ourselves to get the correct border box.\n width = element.offsetWidth;\n height = element.offsetHeight;\n }\n\n setSize({ width, height });\n });\n\n resizeObserver.observe(element, { box: 'border-box' });\n\n return () => resizeObserver.unobserve(element);\n } else {\n // We only want to reset to `undefined` when the element becomes `null`,\n // not if it changes to another element.\n setSize(undefined);\n }\n }, [element]);\n\n return size;\n}\n\nexport { useSize };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,cAAuB;AACvB,uCAAgC;AAEhC,WAAS,QAAQ,SAA6B;AAC5C,UAAM,CAAC,MAAM,OAAO,IAAU,eAAwD,MAAS;AAE/F,wDAAgB,MAAM;AACpB,UAAI,SAAS;AAEX,gBAAQ,EAAE,OAAO,QAAQ,aAAa,QAAQ,QAAQ,aAAa,CAAC;AAEpE,cAAM,iBAAiB,IAAI,eAAe,CAAC,YAAY;AACrD,cAAI,CAAC,MAAM,QAAQ,OAAO,GAAG;AAC3B;AAAA,UACF;AAIA,cAAI,CAAC,QAAQ,QAAQ;AACnB;AAAA,UACF;AAEA,gBAAM,QAAQ,QAAQ,CAAC;AACvB,cAAI;AACJ,cAAI;AAEJ,cAAI,mBAAmB,OAAO;AAC5B,kBAAM,kBAAkB,MAAM,eAAe;AAE7C,kBAAM,aAAa,MAAM,QAAQ,eAAe,IAAI,gBAAgB,CAAC,IAAI;AACzE,oBAAQ,WAAW,YAAY;AAC/B,qBAAS,WAAW,WAAW;AAAA,UACjC,OAAO;AAGL,oBAAQ,QAAQ;AAChB,qBAAS,QAAQ;AAAA,UACnB;AAEA,kBAAQ,EAAE,OAAO,OAAO,CAAC;AAAA,QAC3B,CAAC;AAED,uBAAe,QAAQ,SAAS,EAAE,KAAK,aAAa,CAAC;AAErD,eAAO,MAAM,eAAe,UAAU,OAAO;AAAA,MAC/C,OAAO;AAGL,gBAAQ,MAAS;AAAA,MACnB;AAAA,IACF,GAAG,CAAC,OAAO,CAAC;AAEZ,WAAO;AAAA,EACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,57 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
resizeObserver.observe(element, {
|
|
40
|
-
box: 'border-box'
|
|
41
|
-
});
|
|
42
|
-
return ()=>resizeObserver.unobserve(element)
|
|
43
|
-
;
|
|
44
|
-
} else // We only want to reset to `undefined` when the element becomes `null`,
|
|
45
|
-
// not if it changes to another element.
|
|
46
|
-
setSize(undefined);
|
|
47
|
-
}, [
|
|
48
|
-
element
|
|
49
|
-
]);
|
|
50
|
-
return size;
|
|
1
|
+
// packages/react/use-size/src/useSize.tsx
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { useLayoutEffect } from "@radix-ui/react-use-layout-effect";
|
|
4
|
+
function useSize(element) {
|
|
5
|
+
const [size, setSize] = React.useState(void 0);
|
|
6
|
+
useLayoutEffect(() => {
|
|
7
|
+
if (element) {
|
|
8
|
+
setSize({ width: element.offsetWidth, height: element.offsetHeight });
|
|
9
|
+
const resizeObserver = new ResizeObserver((entries) => {
|
|
10
|
+
if (!Array.isArray(entries)) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (!entries.length) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const entry = entries[0];
|
|
17
|
+
let width;
|
|
18
|
+
let height;
|
|
19
|
+
if ("borderBoxSize" in entry) {
|
|
20
|
+
const borderSizeEntry = entry["borderBoxSize"];
|
|
21
|
+
const borderSize = Array.isArray(borderSizeEntry) ? borderSizeEntry[0] : borderSizeEntry;
|
|
22
|
+
width = borderSize["inlineSize"];
|
|
23
|
+
height = borderSize["blockSize"];
|
|
24
|
+
} else {
|
|
25
|
+
width = element.offsetWidth;
|
|
26
|
+
height = element.offsetHeight;
|
|
27
|
+
}
|
|
28
|
+
setSize({ width, height });
|
|
29
|
+
});
|
|
30
|
+
resizeObserver.observe(element, { box: "border-box" });
|
|
31
|
+
return () => resizeObserver.unobserve(element);
|
|
32
|
+
} else {
|
|
33
|
+
setSize(void 0);
|
|
34
|
+
}
|
|
35
|
+
}, [element]);
|
|
36
|
+
return size;
|
|
51
37
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
export {$db6c3485150b8e66$export$1ab7ae714698c4b8 as useSize};
|
|
38
|
+
export {
|
|
39
|
+
useSize
|
|
40
|
+
};
|
|
57
41
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/useSize.tsx"],
|
|
4
|
+
"sourcesContent": ["/// <reference types=\"resize-observer-browser\" />\n\nimport * as React from 'react';\nimport { useLayoutEffect } from '@radix-ui/react-use-layout-effect';\n\nfunction useSize(element: HTMLElement | null) {\n const [size, setSize] = React.useState<{ width: number; height: number } | undefined>(undefined);\n\n useLayoutEffect(() => {\n if (element) {\n // provide size as early as possible\n setSize({ width: element.offsetWidth, height: element.offsetHeight });\n\n const resizeObserver = new ResizeObserver((entries) => {\n if (!Array.isArray(entries)) {\n return;\n }\n\n // Since we only observe the one element, we don't need to loop over the\n // array\n if (!entries.length) {\n return;\n }\n\n const entry = entries[0];\n let width: number;\n let height: number;\n\n if ('borderBoxSize' in entry) {\n const borderSizeEntry = entry['borderBoxSize'];\n // iron out differences between browsers\n const borderSize = Array.isArray(borderSizeEntry) ? borderSizeEntry[0] : borderSizeEntry;\n width = borderSize['inlineSize'];\n height = borderSize['blockSize'];\n } else {\n // for browsers that don't support `borderBoxSize`\n // we calculate it ourselves to get the correct border box.\n width = element.offsetWidth;\n height = element.offsetHeight;\n }\n\n setSize({ width, height });\n });\n\n resizeObserver.observe(element, { box: 'border-box' });\n\n return () => resizeObserver.unobserve(element);\n } else {\n // We only want to reset to `undefined` when the element becomes `null`,\n // not if it changes to another element.\n setSize(undefined);\n }\n }, [element]);\n\n return size;\n}\n\nexport { useSize };\n"],
|
|
5
|
+
"mappings": ";AAEA,YAAY,WAAW;AACvB,SAAS,uBAAuB;AAEhC,SAAS,QAAQ,SAA6B;AAC5C,QAAM,CAAC,MAAM,OAAO,IAAU,eAAwD,MAAS;AAE/F,kBAAgB,MAAM;AACpB,QAAI,SAAS;AAEX,cAAQ,EAAE,OAAO,QAAQ,aAAa,QAAQ,QAAQ,aAAa,CAAC;AAEpE,YAAM,iBAAiB,IAAI,eAAe,CAAC,YAAY;AACrD,YAAI,CAAC,MAAM,QAAQ,OAAO,GAAG;AAC3B;AAAA,QACF;AAIA,YAAI,CAAC,QAAQ,QAAQ;AACnB;AAAA,QACF;AAEA,cAAM,QAAQ,QAAQ,CAAC;AACvB,YAAI;AACJ,YAAI;AAEJ,YAAI,mBAAmB,OAAO;AAC5B,gBAAM,kBAAkB,MAAM,eAAe;AAE7C,gBAAM,aAAa,MAAM,QAAQ,eAAe,IAAI,gBAAgB,CAAC,IAAI;AACzE,kBAAQ,WAAW,YAAY;AAC/B,mBAAS,WAAW,WAAW;AAAA,QACjC,OAAO;AAGL,kBAAQ,QAAQ;AAChB,mBAAS,QAAQ;AAAA,QACnB;AAEA,gBAAQ,EAAE,OAAO,OAAO,CAAC;AAAA,MAC3B,CAAC;AAED,qBAAe,QAAQ,SAAS,EAAE,KAAK,aAAa,CAAC;AAErD,aAAO,MAAM,eAAe,UAAU,OAAO;AAAA,IAC/C,OAAO;AAGL,cAAQ,MAAS;AAAA,IACnB;AAAA,EACF,GAAG,CAAC,OAAO,CAAC;AAEZ,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@radix-ui/react-use-size",
|
|
3
|
-
"version": "1.0.1",
|
|
3
|
+
"version": "1.1.0-rc.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -28,8 +28,7 @@
|
|
|
28
28
|
"version": "yarn version"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@
|
|
32
|
-
"@radix-ui/react-use-layout-effect": "1.0.1"
|
|
31
|
+
"@radix-ui/react-use-layout-effect": "1.1.0-rc.1"
|
|
33
32
|
},
|
|
34
33
|
"peerDependencies": {
|
|
35
34
|
"@types/react": "*",
|
|
@@ -50,5 +49,6 @@
|
|
|
50
49
|
},
|
|
51
50
|
"bugs": {
|
|
52
51
|
"url": "https://github.com/radix-ui/primitives/issues"
|
|
53
|
-
}
|
|
52
|
+
},
|
|
53
|
+
"stableVersion": "1.0.1"
|
|
54
54
|
}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":"AAKA,wBAAiB,OAAO,EAAE,WAAW,GAAG,IAAI;WACM,MAAM;YAAU,MAAM;cAiDvE","sources":["packages/react/use-size/src/packages/react/use-size/src/useSize.tsx","packages/react/use-size/src/packages/react/use-size/src/index.ts","packages/react/use-size/src/index.ts"],"sourcesContent":[null,null,"export { useSize } from './useSize';\n"],"names":[],"version":3,"file":"index.d.ts.map"}
|