@labpane/os 1.5.0 → 1.5.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/pwa.js +4 -4
- package/dist/pwa.js.map +2 -2
- package/package.json +1 -1
package/dist/pwa.js
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
} from "react";
|
|
8
8
|
function useWindowControlsOverlay(enabled = true) {
|
|
9
9
|
const root = useRef(null);
|
|
10
|
+
const frame = useRef(0);
|
|
10
11
|
const [area, setArea] = useState();
|
|
11
12
|
useLayoutEffect(() => {
|
|
12
13
|
const overlay = navigator.windowControlsOverlay;
|
|
@@ -29,10 +30,9 @@ function useWindowControlsOverlay(enabled = true) {
|
|
|
29
30
|
(previous) => previous?.left === next?.left && previous?.right === next?.right && previous?.height === next?.height && previous?.insetRight === next?.insetRight ? previous : next
|
|
30
31
|
);
|
|
31
32
|
};
|
|
32
|
-
let frame = 0;
|
|
33
33
|
const schedule = () => {
|
|
34
|
-
cancelAnimationFrame(frame);
|
|
35
|
-
frame = requestAnimationFrame(measure);
|
|
34
|
+
cancelAnimationFrame(frame.current);
|
|
35
|
+
frame.current = requestAnimationFrame(measure);
|
|
36
36
|
};
|
|
37
37
|
measure();
|
|
38
38
|
const observer = new ResizeObserver(schedule);
|
|
@@ -42,7 +42,7 @@ function useWindowControlsOverlay(enabled = true) {
|
|
|
42
42
|
window.addEventListener("scroll", schedule, true);
|
|
43
43
|
document.addEventListener("fullscreenchange", schedule);
|
|
44
44
|
return () => {
|
|
45
|
-
cancelAnimationFrame(frame);
|
|
45
|
+
cancelAnimationFrame(frame.current);
|
|
46
46
|
observer.disconnect();
|
|
47
47
|
overlay.removeEventListener("geometrychange", schedule);
|
|
48
48
|
window.removeEventListener("resize", schedule);
|
package/dist/pwa.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../pwa.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n type RefObject,\n} from \"react\";\n\ntype Overlay = EventTarget & {\n visible: boolean;\n getTitlebarAreaRect: () => DOMRect;\n};\n\nexport type TitlebarArea = {\n left: number;\n right: number;\n height: number;\n insetRight: number;\n};\n\nexport type WindowControlsOverlay = {\n readonly root: RefObject<HTMLDivElement | null>;\n readonly area: TitlebarArea | undefined;\n};\n\n// Coordinates supplied by the browser are viewport-relative, while pane boxes\n// are workspace-relative. Never infer an overlay from the OS or display mode.\nexport function useWindowControlsOverlay(\n enabled = true,\n): WindowControlsOverlay {\n const root = useRef<HTMLDivElement>(null);\n const [area, setArea] = useState<TitlebarArea>();\n useLayoutEffect(() => {\n const overlay = (\n navigator as Navigator & { windowControlsOverlay?: Overlay }\n ).windowControlsOverlay;\n const element = root.current;\n if (!enabled || !overlay || !element) {\n setArea(undefined);\n return;\n }\n const measure = () => {\n const rect = overlay.getTitlebarAreaRect();\n const bounds = element.getBoundingClientRect();\n const height = rect.y + rect.height - bounds.top;\n const next =\n overlay.visible &&\n !document.fullscreenElement &&\n rect.width > 0 &&\n rect.height > 0 &&\n bounds.top >= rect.y &&\n height > 0\n ? {\n left: Math.max(0, rect.x - bounds.left),\n right: Math.min(bounds.width, rect.x + rect.width - bounds.left),\n height,\n insetRight: Math.max(0, bounds.right - rect.x - rect.width),\n }\n : undefined;\n setArea((previous) =>\n previous?.left === next?.left &&\n previous?.right === next?.right &&\n previous?.height === next?.height &&\n previous?.insetRight === next?.insetRight\n ? previous\n : next,\n );\n };\n
|
|
5
|
-
"mappings": ";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAqBA,SAAS,yBACd,UAAU,MACa;AACvB,QAAM,OAAO,OAAuB,IAAI;AACxC,QAAM,CAAC,MAAM,OAAO,IAAI,SAAuB;AAC/C,kBAAgB,MAAM;AACpB,UAAM,UACJ,UACA;AACF,UAAM,UAAU,KAAK;AACrB,QAAI,CAAC,WAAW,CAAC,WAAW,CAAC,SAAS;AACpC,cAAQ,MAAS;AACjB;AAAA,IACF;AACA,UAAM,UAAU,MAAM;AACpB,YAAM,OAAO,QAAQ,oBAAoB;AACzC,YAAM,SAAS,QAAQ,sBAAsB;AAC7C,YAAM,SAAS,KAAK,IAAI,KAAK,SAAS,OAAO;AAC7C,YAAM,OACJ,QAAQ,WACR,CAAC,SAAS,qBACV,KAAK,QAAQ,KACb,KAAK,SAAS,KACd,OAAO,OAAO,KAAK,KACnB,SAAS,IACL;AAAA,QACE,MAAM,KAAK,IAAI,GAAG,KAAK,IAAI,OAAO,IAAI;AAAA,QACtC,OAAO,KAAK,IAAI,OAAO,OAAO,KAAK,IAAI,KAAK,QAAQ,OAAO,IAAI;AAAA,QAC/D;AAAA,QACA,YAAY,KAAK,IAAI,GAAG,OAAO,QAAQ,KAAK,IAAI,KAAK,KAAK;AAAA,MAC5D,IACA;AACN;AAAA,QAAQ,CAAC,aACP,UAAU,SAAS,MAAM,QACzB,UAAU,UAAU,MAAM,SAC1B,UAAU,WAAW,MAAM,UAC3B,UAAU,eAAe,MAAM,aAC3B,WACA;AAAA,MACN;AAAA,IACF;AACA,
|
|
4
|
+
"sourcesContent": ["import {\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n type RefObject,\n} from \"react\";\n\ntype Overlay = EventTarget & {\n visible: boolean;\n getTitlebarAreaRect: () => DOMRect;\n};\n\nexport type TitlebarArea = {\n left: number;\n right: number;\n height: number;\n insetRight: number;\n};\n\nexport type WindowControlsOverlay = {\n readonly root: RefObject<HTMLDivElement | null>;\n readonly area: TitlebarArea | undefined;\n};\n\n// Coordinates supplied by the browser are viewport-relative, while pane boxes\n// are workspace-relative. Never infer an overlay from the OS or display mode.\nexport function useWindowControlsOverlay(\n enabled = true,\n): WindowControlsOverlay {\n const root = useRef<HTMLDivElement>(null);\n const frame = useRef(0);\n const [area, setArea] = useState<TitlebarArea>();\n useLayoutEffect(() => {\n const overlay = (\n navigator as Navigator & { windowControlsOverlay?: Overlay }\n ).windowControlsOverlay;\n const element = root.current;\n if (!enabled || !overlay || !element) {\n setArea(undefined);\n return;\n }\n const measure = () => {\n const rect = overlay.getTitlebarAreaRect();\n const bounds = element.getBoundingClientRect();\n const height = rect.y + rect.height - bounds.top;\n const next =\n overlay.visible &&\n !document.fullscreenElement &&\n rect.width > 0 &&\n rect.height > 0 &&\n bounds.top >= rect.y &&\n height > 0\n ? {\n left: Math.max(0, rect.x - bounds.left),\n right: Math.min(bounds.width, rect.x + rect.width - bounds.left),\n height,\n insetRight: Math.max(0, bounds.right - rect.x - rect.width),\n }\n : undefined;\n setArea((previous) =>\n previous?.left === next?.left &&\n previous?.right === next?.right &&\n previous?.height === next?.height &&\n previous?.insetRight === next?.insetRight\n ? previous\n : next,\n );\n };\n const schedule = () => {\n cancelAnimationFrame(frame.current);\n frame.current = requestAnimationFrame(measure);\n };\n measure();\n const observer = new ResizeObserver(schedule);\n observer.observe(element);\n overlay.addEventListener(\"geometrychange\", schedule);\n window.addEventListener(\"resize\", schedule);\n window.addEventListener(\"scroll\", schedule, true);\n document.addEventListener(\"fullscreenchange\", schedule);\n return () => {\n cancelAnimationFrame(frame.current);\n observer.disconnect();\n overlay.removeEventListener(\"geometrychange\", schedule);\n window.removeEventListener(\"resize\", schedule);\n window.removeEventListener(\"scroll\", schedule, true);\n document.removeEventListener(\"fullscreenchange\", schedule);\n };\n }, [enabled, root]);\n return useMemo(\n () => ({ root, area: enabled ? area : undefined }),\n [area, enabled],\n );\n}\n"],
|
|
5
|
+
"mappings": ";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAqBA,SAAS,yBACd,UAAU,MACa;AACvB,QAAM,OAAO,OAAuB,IAAI;AACxC,QAAM,QAAQ,OAAO,CAAC;AACtB,QAAM,CAAC,MAAM,OAAO,IAAI,SAAuB;AAC/C,kBAAgB,MAAM;AACpB,UAAM,UACJ,UACA;AAC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