@mcurros2/microm 1.1.101-0 → 1.1.102-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.
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +37 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -47876,17 +47876,28 @@ parcelRegister("lwxCY", function(module, exports) {
|
|
|
47876
47876
|
|
|
47877
47877
|
$parcel$export(module.exports, "useAncestorResize", function () { return $fab6abe4da65ff17$export$d994cf386c6f1d98; });
|
|
47878
47878
|
|
|
47879
|
+
function $fab6abe4da65ff17$var$parseUnit(value, ancestorWidth, ancestorHeight, baseFontSize) {
|
|
47880
|
+
if (value.endsWith("px")) return parseFloat(value);
|
|
47881
|
+
if (value.endsWith("vw")) return window.innerWidth * parseFloat(value) / 100;
|
|
47882
|
+
if (value.endsWith("vh")) return window.innerHeight * parseFloat(value) / 100;
|
|
47883
|
+
if (value.endsWith("rem")) return parseFloat(value) * baseFontSize;
|
|
47884
|
+
if (value.endsWith("em")) return parseFloat(value) * baseFontSize;
|
|
47885
|
+
if (value.endsWith("%")) return parseFloat(value) / 100 * (ancestorWidth || ancestorHeight);
|
|
47886
|
+
return parseFloat(value);
|
|
47887
|
+
}
|
|
47879
47888
|
function $fab6abe4da65ff17$export$d994cf386c6f1d98(minSize = {
|
|
47880
|
-
width:
|
|
47881
|
-
height:
|
|
47889
|
+
width: "300px",
|
|
47890
|
+
height: "400px"
|
|
47882
47891
|
}) {
|
|
47883
47892
|
const ref = (0, $b4te3$react.useRef)(null);
|
|
47884
|
-
const [size, setSize] = (0, $b4te3$react.useState)(
|
|
47893
|
+
const [size, setSize] = (0, $b4te3$react.useState)({
|
|
47894
|
+
width: 0,
|
|
47895
|
+
height: 0
|
|
47896
|
+
});
|
|
47885
47897
|
(0, $b4te3$react.useEffect)(()=>{
|
|
47886
47898
|
var _a;
|
|
47887
47899
|
if (!ref.current) return;
|
|
47888
|
-
|
|
47889
|
-
const findTargetAncestor = (el)=>{
|
|
47900
|
+
const findFirstScrollableAncestor = (el)=>{
|
|
47890
47901
|
while(el){
|
|
47891
47902
|
const overflowY = getComputedStyle(el).overflowY;
|
|
47892
47903
|
if (overflowY === "auto" || overflowY === "scroll") return el;
|
|
@@ -47894,17 +47905,30 @@ function $fab6abe4da65ff17$export$d994cf386c6f1d98(minSize = {
|
|
|
47894
47905
|
}
|
|
47895
47906
|
return null;
|
|
47896
47907
|
};
|
|
47897
|
-
const ancestor = (_a =
|
|
47898
|
-
if (!ancestor)
|
|
47899
|
-
|
|
47900
|
-
|
|
47908
|
+
const ancestor = (_a = findFirstScrollableAncestor(ref.current.parentElement)) !== null && _a !== void 0 ? _a : ref.current.parentElement;
|
|
47909
|
+
if (!ancestor) {
|
|
47910
|
+
console.warn("cant resize, noancestor");
|
|
47911
|
+
return;
|
|
47912
|
+
}
|
|
47913
|
+
const baseFontSize = parseFloat(getComputedStyle(document.documentElement).fontSize);
|
|
47914
|
+
const minWidth = $fab6abe4da65ff17$var$parseUnit(minSize.width, ancestor.clientWidth, ancestor.clientHeight, baseFontSize);
|
|
47915
|
+
const minHeight = $fab6abe4da65ff17$var$parseUnit(minSize.height, ancestor.clientWidth, ancestor.clientHeight, baseFontSize);
|
|
47916
|
+
const resize = ()=>{
|
|
47917
|
+
const width = ancestor.clientWidth;
|
|
47918
|
+
const height = ancestor.clientHeight;
|
|
47901
47919
|
setSize({
|
|
47902
|
-
width: Math.max(
|
|
47903
|
-
height: Math.max(
|
|
47920
|
+
width: Math.max(minWidth, width),
|
|
47921
|
+
height: Math.max(minHeight, height)
|
|
47904
47922
|
});
|
|
47905
|
-
}
|
|
47923
|
+
};
|
|
47924
|
+
const observer = new ResizeObserver(resize);
|
|
47906
47925
|
observer.observe(ancestor);
|
|
47907
|
-
|
|
47926
|
+
window.addEventListener("resize", resize);
|
|
47927
|
+
resize();
|
|
47928
|
+
return ()=>{
|
|
47929
|
+
observer.disconnect();
|
|
47930
|
+
window.removeEventListener("resize", resize);
|
|
47931
|
+
};
|
|
47908
47932
|
}, [
|
|
47909
47933
|
minSize.width,
|
|
47910
47934
|
minSize.height
|