@tearleads/windowing 0.2.37 → 0.2.38
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/README.md +1 -0
- package/docs/screensavers.md +74 -0
- package/index.d.ts +1 -0
- package/index.js +2 -1
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/screensaver/ScreensaverOverlay.d.ts +5 -0
- package/screensaver/ScreensaverOverlay.js +32 -0
- package/screensaver/ScreensaverOverlay.js.map +1 -0
- package/screensaver/ScreensaverProvider.d.ts +15 -0
- package/screensaver/ScreensaverProvider.js +13 -0
- package/screensaver/ScreensaverProvider.js.map +1 -0
- package/screensaver/screensaver.css +29 -0
- package/screensaver/screensaverHeldInput.d.ts +1 -0
- package/screensaver/screensaverHeldInput.js +76 -0
- package/screensaver/screensaverHeldInput.js.map +1 -0
- package/screensaver/screensaverInput.d.ts +2 -0
- package/screensaver/screensaverInput.js +105 -0
- package/screensaver/screensaverInput.js.map +1 -0
- package/screensaver/screensaverMachine.d.ts +34 -0
- package/screensaver/screensaverMachine.js +36 -0
- package/screensaver/screensaverMachine.js.map +1 -0
- package/screensaver/useScreensaverController.d.ts +6 -0
- package/screensaver/useScreensaverController.js +46 -0
- package/screensaver/useScreensaverController.js.map +1 -0
- package/screensaver/useScreensaverIsolation.d.ts +1 -0
- package/screensaver/useScreensaverIsolation.js +39 -0
- package/screensaver/useScreensaverIsolation.js.map +1 -0
package/README.md
CHANGED
|
@@ -69,6 +69,7 @@ desktop surface must be a positioned container.
|
|
|
69
69
|
- [Themes](./docs/appearance.md#themes)
|
|
70
70
|
- [Wallpapers and Display Properties](./docs/appearance.md#wallpapers-and-display-properties)
|
|
71
71
|
- [Styles](./docs/appearance.md#styles)
|
|
72
|
+
- [Pluggable screensavers](./docs/screensavers.md)
|
|
72
73
|
- [Publishing](./docs/publishing.md)
|
|
73
74
|
|
|
74
75
|
## Dependency compatibility
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Screensavers
|
|
2
|
+
|
|
3
|
+
Part of [@tearleads/windowing](../README.md).
|
|
4
|
+
|
|
5
|
+
Mount one `ScreensaverProvider` around the host's desktop and taskbar. It needs
|
|
6
|
+
no window-state or launcher provider. The host supplies the animation and the
|
|
7
|
+
control that starts it; this package adds no animation, idle timer, saved
|
|
8
|
+
preference, or global launch shortcut.
|
|
9
|
+
|
|
10
|
+
```tsx
|
|
11
|
+
import { ScreensaverProvider, useScreensaver } from "@tearleads/windowing";
|
|
12
|
+
|
|
13
|
+
function StartScreensaver() {
|
|
14
|
+
const { start } = useScreensaver();
|
|
15
|
+
return <button onClick={start}>Start screensaver</button>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
<ScreensaverProvider screensaver={MyAnimation}>
|
|
19
|
+
<Desktop />
|
|
20
|
+
<Taskbar />
|
|
21
|
+
<StartScreensaver />
|
|
22
|
+
</ScreensaverProvider>;
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
`MyAnimation` is a React component with no required props. It mounts only while
|
|
26
|
+
active, inside a viewport-sized container; a canvas can use `width: 100%` and
|
|
27
|
+
`height: 100%`. It owns its animation and must cancel its work on unmount.
|
|
28
|
+
Replacing the component while active replaces only that animation, not the
|
|
29
|
+
session or grace timer. Styles are included by the public import.
|
|
30
|
+
|
|
31
|
+
`useScreensaver()` returns stable `start()` and `stop()` callbacks and an
|
|
32
|
+
`isActive` boolean. It throws outside the provider. Repeated starts while active
|
|
33
|
+
are ignored. `stop()` exits immediately and intentionally cancels input
|
|
34
|
+
isolation, including a pending release tail; reserve it for explicit host
|
|
35
|
+
control or teardown, not an effect watching `isActive`. Start and stop do not
|
|
36
|
+
close, minimize, or recreate the host's windows.
|
|
37
|
+
|
|
38
|
+
The optional `gracePeriodMs` defaults to `2000`. Input during that initial
|
|
39
|
+
period is consumed without dismissal; Escape always exits. After grace,
|
|
40
|
+
keyboard, pointer, mouse, touch, and wheel activity dismiss. The dismissing
|
|
41
|
+
input and that discrete press's release/click tail are consumed so the desktop
|
|
42
|
+
does not receive an accidental click or shortcut. After that tail settles,
|
|
43
|
+
later presses are new host input, including a double-click's second press.
|
|
44
|
+
A new start during the isolated tail is ignored until
|
|
45
|
+
the gesture finishes. Idle listeners are passive and retain only modifiers,
|
|
46
|
+
not ordinary key presses. Meta release clears keys whose release the browser
|
|
47
|
+
omitted; losing focus or hiding the page clears the tail too. If a release is
|
|
48
|
+
lost while the page stays visible, press and release Escape to recover.
|
|
49
|
+
There is deliberately no deadline that unlocks under a still-held pointer:
|
|
50
|
+
that would allow its later release to click through. Escape is the explicit
|
|
51
|
+
recovery action, and its own release is consumed. Unmounting the provider
|
|
52
|
+
clears listeners and timers too. Isolation covers discrete releases/clicks,
|
|
53
|
+
not later trackpad momentum events after a wheel dismissal. Changing
|
|
54
|
+
`gracePeriodMs` during grace restarts the timer; `0` disables grace, so hosts
|
|
55
|
+
launching with a key should keep a positive grace period for that key's release.
|
|
56
|
+
|
|
57
|
+
The overlay is a native modal `dialog` in the document body, above windows and
|
|
58
|
+
the taskbar in the browser's top layer. It hides the cursor and makes the page
|
|
59
|
+
inert, including embedded frames. Native modal dialogs escape ancestor
|
|
60
|
+
inertness, per the [HTML modal dialog rules][modal-inertness]. The page
|
|
61
|
+
remains inert while a dismissing
|
|
62
|
+
press finishes, even though the animation and overlay have unmounted. The
|
|
63
|
+
animation itself is inert and hidden from assistive technology; the dialog
|
|
64
|
+
announces "Screensaver" and the Escape instruction. Focus returns to the
|
|
65
|
+
previous connected element unless the host has moved it elsewhere. Existing
|
|
66
|
+
body inertness is restored, not unconditionally removed.
|
|
67
|
+
|
|
68
|
+
Use a browser with native modal dialogs and `inert` support. This is a visual
|
|
69
|
+
screensaver, not an authentication lock or security boundary. Host code should
|
|
70
|
+
not open competing modal dialogs or change body inertness during a session.
|
|
71
|
+
Mount the provider only in layouts where the host wants screensaver behavior;
|
|
72
|
+
routed layouts need not include it.
|
|
73
|
+
|
|
74
|
+
[modal-inertness]: https://html.spec.whatwg.org/multipage/interaction.html#modal-dialogs-and-inert-subtrees
|
package/index.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ export { useLongPress } from "./menu/useLongPress.js";
|
|
|
31
31
|
export { RoutedPane, type RoutedPaneProps } from "./routed/RoutedPane.js";
|
|
32
32
|
export { RoutedPaneOverlayHostProvider, type RoutedPaneOverlayHostValue, useRoutedPaneOverlayHost, } from "./routed/RoutedPaneOverlayHost.js";
|
|
33
33
|
export type { SubscribeKeyboardVisibility } from "./routed/useMobileKeyboardVisible.js";
|
|
34
|
+
export { type ScreensaverControls, ScreensaverProvider, type ScreensaverProviderProps, useScreensaver, } from "./screensaver/ScreensaverProvider.js";
|
|
34
35
|
export { SidebarResizeHandle, useSidebarResize } from "./sidebar/SidebarResize.js";
|
|
35
36
|
export { ThemeProvider, useOptionalTheme, useTheme, } from "./theme/ThemeProvider.js";
|
|
36
37
|
export { ThemeSwitch } from "./theme/ThemeSwitch.js";
|
package/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import "./tokens.css";
|
|
|
4
4
|
// start menu and theme switch, the icons the chrome draws, a launcher of
|
|
5
5
|
// mini-apps that shows them in windows or in the routed (iPad / phone) shell,
|
|
6
6
|
// and desktop icons that open them, with a storage adapter for their layout,
|
|
7
|
-
// over a wallpaper chosen in Display Properties.
|
|
7
|
+
// over a wallpaper chosen in Display Properties, plus a host-supplied screensaver.
|
|
8
8
|
export { createRequiredContext, } from "./createRequiredContext.js";
|
|
9
9
|
export { DesktopIcons, } from "./desktop/DesktopIcons.js";
|
|
10
10
|
export { createMemoryDesktopStateStorage, createOpfsDesktopStateStorage, } from "./desktop/desktopStateStorage.js";
|
|
@@ -34,6 +34,7 @@ export { useContextMenuPositionState, useContextMenuState, } from "./menu/useCon
|
|
|
34
34
|
export { useLongPress } from "./menu/useLongPress.js";
|
|
35
35
|
export { RoutedPane } from "./routed/RoutedPane.js";
|
|
36
36
|
export { RoutedPaneOverlayHostProvider, useRoutedPaneOverlayHost, } from "./routed/RoutedPaneOverlayHost.js";
|
|
37
|
+
export { ScreensaverProvider, useScreensaver, } from "./screensaver/ScreensaverProvider.js";
|
|
37
38
|
export { SidebarResizeHandle, useSidebarResize } from "./sidebar/SidebarResize.js";
|
|
38
39
|
export { ThemeProvider, useOptionalTheme, useTheme, } from "./theme/ThemeProvider.js";
|
|
39
40
|
export { ThemeSwitch } from "./theme/ThemeSwitch.js";
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../home/runner/work/tearleads/tearleads/packages/windowing/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC;AAEtB,6EAA6E;AAC7E,8EAA8E;AAC9E,yEAAyE;AACzE,8EAA8E;AAC9E,6EAA6E;AAC7E,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../home/runner/work/tearleads/tearleads/packages/windowing/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC;AAEtB,6EAA6E;AAC7E,8EAA8E;AAC9E,yEAAyE;AACzE,8EAA8E;AAC9E,6EAA6E;AAC7E,mFAAmF;AACnF,OAAO,EACL,qBAAqB,GAEtB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,YAAY,GAEb,MAAM,wBAAwB,CAAC;AAKhC,OAAO,EACL,+BAA+B,EAC/B,6BAA6B,GAG9B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAEL,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,2BAA2B,EAC3B,mBAAmB,EACnB,4BAA4B,GAC7B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAEL,0BAA0B,EAE1B,4BAA4B,EAC5B,0BAA0B,EAC1B,uBAAuB,EACvB,kCAAkC,GACnC,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACL,eAAe,EAGf,wBAAwB,EACxB,oBAAoB,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,MAAM,wBAAwB,CAAC","sourcesContent":["import \"./tokens.css\";\n\n// The public windowing API: window state, window chrome and its registration\n// hooks, the menu and sidebar primitives the chrome renders with, a taskbar's\n// start menu and theme switch, the icons the chrome draws, a launcher of\n// mini-apps that shows them in windows or in the routed (iPad / phone) shell,\n// and desktop icons that open them, with a storage adapter for their layout,\n// over a wallpaper chosen in Display Properties, plus a host-supplied screensaver.\nexport {\n createRequiredContext,\n type RequiredContext,\n} from \"./createRequiredContext\";\nexport type { DesktopIconMenuItem } from \"./desktop/DesktopIconMenu\";\nexport {\n DesktopIcons,\n type DesktopIconsProps,\n} from \"./desktop/DesktopIcons\";\nexport type {\n DesktopIconPosition,\n DesktopState,\n} from \"./desktop/desktopState\";\nexport {\n createMemoryDesktopStateStorage,\n createOpfsDesktopStateStorage,\n type DesktopStateStorage,\n type OpfsDesktopStateStorageOptions,\n} from \"./desktop/desktopStateStorage\";\nexport { DisplayProperties } from \"./display/DisplayProperties\";\nexport {\n type WindowingIcons,\n WindowingIconsProvider,\n} from \"./icons/WindowingIcons\";\nexport type { WindowingIcon, WindowingIconProps } from \"./icons/windowingIcon\";\nexport {\n ROUTED_TABLET_BREAKPOINT_PX,\n ROUTED_TABLET_QUERY,\n WINDOWED_LAYOUT_MIN_WIDTH_PX,\n} from \"./launcher/breakpoints\";\nexport {\n type LauncherNavigationActions,\n LauncherNavigationProvider,\n type LauncherNavigationState,\n useLauncherNavigationActions,\n useLauncherNavigationState,\n useMiniAppRouteSegments,\n useOptionalLauncherNavigationState,\n} from \"./launcher/LauncherNavigationProvider\";\nexport {\n isLauncherAppId,\n type LauncherDefinition,\n type MiniAppDefinition,\n resolveLauncherHomeAppId,\n resolveLauncherOrder,\n} from \"./launcher/launcherDefinition\";\nexport {\n MiniAppRouteSegmentsProvider,\n useMiniAppWindowRouteSegments,\n} from \"./launcher/MiniAppRouteSegmentsContext\";\nexport { type MiniAppBoundary, MiniAppWindow } from \"./launcher/MiniAppWindow\";\nexport {\n NavigationModeOverrideProvider,\n useNavigationModeOverride,\n useOptionalNavigationModeOverride,\n} from \"./launcher/NavigationModeOverrideProvider\";\nexport { NavigationModeSwitch } from \"./launcher/NavigationModeSwitch\";\nexport {\n isWindowedLayoutEligible,\n type NavigationEnvironment,\n type NavigationMode,\n readNavigationEnvironment,\n resolveNavigationMode,\n} from \"./launcher/navigationMode\";\nexport {\n DEFAULT_MINI_APP_POSITION,\n type MiniAppWindowPlacement,\n type OpenMiniAppRequest,\n type PlaceMiniAppWindow,\n} from \"./launcher/openMiniAppWindow\";\nexport {\n buildMiniAppPath,\n type LauncherRoute,\n parseLauncherRoute,\n} from \"./launcher/routePaths\";\nexport {\n resolveActiveLauncherRoute,\n useActiveLauncherRoute,\n} from \"./launcher/useActiveLauncherRoute\";\nexport { useCompactRoutedMode } from \"./launcher/useCompactRoutedMode\";\nexport {\n type MiniAppRouteSetOptions,\n useMiniAppRouteState,\n} from \"./launcher/useMiniAppRouteState\";\nexport { useNavigationMode } from \"./launcher/useNavigationMode\";\nexport { useNavigationModeDocumentAttribute } from \"./launcher/useNavigationModeDocumentAttribute\";\nexport {\n useRoutedLayoutActive,\n useWindowedLayoutActive,\n} from \"./launcher/useRoutedLayoutActive\";\nexport {\n type RoutedLayoutTier,\n useRoutedLayoutTier,\n} from \"./launcher/useRoutedLayoutTier\";\nexport { Menu, type MenuPosition } from \"./menu/Menu\";\nexport { MenuItem, type MenuItemProps } from \"./menu/MenuItem\";\nexport {\n StartMenu,\n type StartMenuItem,\n type StartMenuProps,\n} from \"./menu/StartMenu\";\nexport {\n type ContextMenuState,\n useContextMenuPositionState,\n useContextMenuState,\n} from \"./menu/useContextMenuState\";\nexport { useLongPress } from \"./menu/useLongPress\";\nexport { RoutedPane, type RoutedPaneProps } from \"./routed/RoutedPane\";\nexport {\n RoutedPaneOverlayHostProvider,\n type RoutedPaneOverlayHostValue,\n useRoutedPaneOverlayHost,\n} from \"./routed/RoutedPaneOverlayHost\";\nexport type { SubscribeKeyboardVisibility } from \"./routed/useMobileKeyboardVisible\";\nexport {\n type ScreensaverControls,\n ScreensaverProvider,\n type ScreensaverProviderProps,\n useScreensaver,\n} from \"./screensaver/ScreensaverProvider\";\nexport { SidebarResizeHandle, useSidebarResize } from \"./sidebar/SidebarResize\";\nexport {\n ThemeProvider,\n useOptionalTheme,\n useTheme,\n} from \"./theme/ThemeProvider\";\nexport { ThemeSwitch } from \"./theme/ThemeSwitch\";\nexport type {\n DefaultTheme,\n ThemeDefinition,\n ThemeScheme,\n} from \"./theme/themes\";\nexport {\n DesktopWallpaper,\n type DesktopWallpaperProps,\n} from \"./wallpaper/DesktopWallpaper\";\nexport {\n BLOCKS_WALLPAPER,\n CHEVRON_WALLPAPER,\n HARLEQUIN_WALLPAPER,\n HONEYCOMB_WALLPAPER,\n PLAIN_WALLPAPER,\n TRIANGLES_WALLPAPER,\n} from \"./wallpaper/tessellations\";\nexport {\n useOptionalWallpaper,\n useWallpaper,\n WallpaperProvider,\n} from \"./wallpaper/WallpaperProvider\";\nexport type {\n WallpaperDefinition,\n WallpaperTile,\n} from \"./wallpaper/wallpapers\";\nexport {\n CurrentWindowProvider,\n useCurrentWindow,\n useSuppressWindowToolbar,\n useWindowBackground,\n useWindowContentSize,\n} from \"./window/CurrentWindowContext\";\nexport { Window, type WindowContentBoundary } from \"./window/Window\";\nexport { WindowTitleBarActionButtons } from \"./window/WindowChromeActions\";\nexport { WindowCloseButton } from \"./window/WindowCloseButton\";\nexport {\n useWindowBackAction,\n useWindowBackActionValue,\n useWindowFileMenuItem,\n useWindowRefreshMenuItem,\n useWindowRefreshMenuItemValue,\n useWindowTitleBarAction,\n useWindowTitleBarActions,\n useWindowToolbarReservation,\n useWindowViewMenuItem,\n WindowMenuProvider,\n} from \"./window/WindowMenuContext\";\nexport {\n hasWindowSidebar,\n useRegisteredWindowSidebar,\n useWindowSidebar,\n WindowSidebarProvider,\n} from \"./window/WindowSidebarContext\";\nexport {\n findTopWindow,\n useWindowActions,\n useWindowStateData,\n type WindowCreateOptions,\n type WindowEntry,\n type WindowGeometry,\n type WindowPosition,\n type WindowSize,\n type WindowStateActions,\n type WindowStateData,\n WindowStateProvider,\n} from \"./window/WindowStateProvider\";\nexport { WindowToolBar } from \"./window/WindowToolBar\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tearleads/windowing",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.38",
|
|
4
4
|
"description": "App-agnostic window management for React: window state, window chrome, and the menu and sidebar primitives it renders with.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useLayoutEffect, useRef } from "react";
|
|
3
|
+
import { createPortal } from "react-dom";
|
|
4
|
+
import "./screensaver.css";
|
|
5
|
+
export function ScreensaverOverlay({ children, onStop, }) {
|
|
6
|
+
const ref = useRef(null);
|
|
7
|
+
useLayoutEffect(() => {
|
|
8
|
+
const dialog = ref.current;
|
|
9
|
+
if (!dialog)
|
|
10
|
+
return;
|
|
11
|
+
const cancel = (event) => {
|
|
12
|
+
event.preventDefault();
|
|
13
|
+
event.stopImmediatePropagation();
|
|
14
|
+
onStop();
|
|
15
|
+
};
|
|
16
|
+
const close = () => {
|
|
17
|
+
if (!dialog.open)
|
|
18
|
+
onStop();
|
|
19
|
+
};
|
|
20
|
+
dialog.addEventListener("cancel", cancel);
|
|
21
|
+
dialog.addEventListener("close", close);
|
|
22
|
+
dialog.showModal();
|
|
23
|
+
dialog.focus();
|
|
24
|
+
return () => {
|
|
25
|
+
dialog.removeEventListener("cancel", cancel);
|
|
26
|
+
dialog.removeEventListener("close", close);
|
|
27
|
+
dialog.close();
|
|
28
|
+
};
|
|
29
|
+
}, [onStop]);
|
|
30
|
+
return createPortal(_jsx("dialog", { "aria-label": "Screensaver", "aria-description": "Press Escape to exit.", className: "screensaver-overlay", ref: ref, children: _jsx("div", { "aria-hidden": "true", inert: true, className: "screensaver-content", children: children }) }), document.body);
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=ScreensaverOverlay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScreensaverOverlay.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/screensaver/ScreensaverOverlay.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAkB,eAAe,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,mBAAmB,CAAC;AAE3B,MAAM,UAAU,kBAAkB,CAAC,EACjC,QAAQ,EACR,MAAM,GAIP;IACC,MAAM,GAAG,GAAG,MAAM,CAAoB,IAAI,CAAC,CAAC;IAC5C,eAAe,CAAC,GAAG,EAAE;QACnB,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC;QAC3B,IAAI,CAAC,MAAM;YAAE,OAAO;QACpB,MAAM,MAAM,GAAG,CAAC,KAAY,EAAE,EAAE;YAC9B,KAAK,CAAC,cAAc,EAAE,CAAC;YACvB,KAAK,CAAC,wBAAwB,EAAE,CAAC;YACjC,MAAM,EAAE,CAAC;QACX,CAAC,CAAC;QACF,MAAM,KAAK,GAAG,GAAG,EAAE;YACjB,IAAI,CAAC,MAAM,CAAC,IAAI;gBAAE,MAAM,EAAE,CAAC;QAC7B,CAAC,CAAC;QACF,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAC1C,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACxC,MAAM,CAAC,SAAS,EAAE,CAAC;QACnB,MAAM,CAAC,KAAK,EAAE,CAAC;QACf,OAAO,GAAG,EAAE;YACV,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;YAC7C,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YAC3C,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IACb,OAAO,YAAY,CACjB,+BACa,aAAa,sBACP,uBAAuB,EACxC,SAAS,EAAC,qBAAqB,EAC/B,GAAG,EAAE,GAAG,YAER,6BAAiB,MAAM,EAAC,KAAK,QAAC,SAAS,EAAC,qBAAqB,YAC1D,QAAQ,GACL,GACC,EACT,QAAQ,CAAC,IAAI,CACd,CAAC;AACJ,CAAC","sourcesContent":["import { type ReactNode, useLayoutEffect, useRef } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport \"./screensaver.css\";\n\nexport function ScreensaverOverlay({\n children,\n onStop,\n}: {\n children: ReactNode;\n onStop: () => void;\n}) {\n const ref = useRef<HTMLDialogElement>(null);\n useLayoutEffect(() => {\n const dialog = ref.current;\n if (!dialog) return;\n const cancel = (event: Event) => {\n event.preventDefault();\n event.stopImmediatePropagation();\n onStop();\n };\n const close = () => {\n if (!dialog.open) onStop();\n };\n dialog.addEventListener(\"cancel\", cancel);\n dialog.addEventListener(\"close\", close);\n dialog.showModal();\n dialog.focus();\n return () => {\n dialog.removeEventListener(\"cancel\", cancel);\n dialog.removeEventListener(\"close\", close);\n dialog.close();\n };\n }, [onStop]);\n return createPortal(\n <dialog\n aria-label=\"Screensaver\"\n aria-description=\"Press Escape to exit.\"\n className=\"screensaver-overlay\"\n ref={ref}\n >\n <div aria-hidden=\"true\" inert className=\"screensaver-content\">\n {children}\n </div>\n </dialog>,\n document.body,\n );\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type ComponentType, type ReactNode } from "react";
|
|
2
|
+
export interface ScreensaverControls {
|
|
3
|
+
start: () => void;
|
|
4
|
+
stop: () => void;
|
|
5
|
+
/** The animation is mounted; false can still consume a pending release. */
|
|
6
|
+
isActive: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface ScreensaverProviderProps {
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
screensaver: ComponentType;
|
|
11
|
+
gracePeriodMs?: number;
|
|
12
|
+
}
|
|
13
|
+
declare const useScreensaver: () => ScreensaverControls;
|
|
14
|
+
export { useScreensaver };
|
|
15
|
+
export declare function ScreensaverProvider({ children, screensaver: Screensaver, gracePeriodMs, }: ScreensaverProviderProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import { createRequiredContext } from "../createRequiredContext.js";
|
|
4
|
+
import { ScreensaverOverlay } from "./ScreensaverOverlay.js";
|
|
5
|
+
import { useScreensaverController } from "./useScreensaverController.js";
|
|
6
|
+
const { context: ScreensaverContext, useRequired: useScreensaver } = createRequiredContext("useScreensaver requires ScreensaverProvider");
|
|
7
|
+
export { useScreensaver };
|
|
8
|
+
export function ScreensaverProvider({ children, screensaver: Screensaver, gracePeriodMs = 2000, }) {
|
|
9
|
+
const { isActive, start, stop, session } = useScreensaverController(gracePeriodMs);
|
|
10
|
+
const value = useMemo(() => ({ start, stop, isActive }), [start, stop, isActive]);
|
|
11
|
+
return (_jsxs(ScreensaverContext.Provider, { value: value, children: [children, isActive && (_jsx(ScreensaverOverlay, { onStop: stop, children: _jsx(Screensaver, {}) }, session))] }));
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=ScreensaverProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScreensaverProvider.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/screensaver/ScreensaverProvider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAsC,OAAO,EAAE,MAAM,OAAO,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAatE,MAAM,EAAE,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,cAAc,EAAE,GAChE,qBAAqB,CACnB,6CAA6C,CAC9C,CAAC;AAEJ,OAAO,EAAE,cAAc,EAAE,CAAC;AAE1B,MAAM,UAAU,mBAAmB,CAAC,EAClC,QAAQ,EACR,WAAW,EAAE,WAAW,EACxB,aAAa,GAAG,IAAI,GACK;IACzB,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,GACtC,wBAAwB,CAAC,aAAa,CAAC,CAAC;IAC1C,MAAM,KAAK,GAAG,OAAO,CACnB,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,EACjC,CAAC,KAAK,EAAE,IAAI,EAAE,QAAQ,CAAC,CACxB,CAAC;IACF,OAAO,CACL,MAAC,kBAAkB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,aACtC,QAAQ,EACR,QAAQ,IAAI,CACX,KAAC,kBAAkB,IAAe,MAAM,EAAE,IAAI,YAC5C,KAAC,WAAW,KAAG,IADQ,OAAO,CAEX,CACtB,IAC2B,CAC/B,CAAC;AACJ,CAAC","sourcesContent":["import { type ComponentType, type ReactNode, useMemo } from \"react\";\nimport { createRequiredContext } from \"../createRequiredContext\";\nimport { ScreensaverOverlay } from \"./ScreensaverOverlay\";\nimport { useScreensaverController } from \"./useScreensaverController\";\n\nexport interface ScreensaverControls {\n start: () => void;\n stop: () => void;\n /** The animation is mounted; false can still consume a pending release. */\n isActive: boolean;\n}\nexport interface ScreensaverProviderProps {\n children: ReactNode;\n screensaver: ComponentType;\n gracePeriodMs?: number;\n}\nconst { context: ScreensaverContext, useRequired: useScreensaver } =\n createRequiredContext<ScreensaverControls>(\n \"useScreensaver requires ScreensaverProvider\",\n );\n\nexport { useScreensaver };\n\nexport function ScreensaverProvider({\n children,\n screensaver: Screensaver,\n gracePeriodMs = 2000,\n}: ScreensaverProviderProps) {\n const { isActive, start, stop, session } =\n useScreensaverController(gracePeriodMs);\n const value = useMemo(\n () => ({ start, stop, isActive }),\n [start, stop, isActive],\n );\n return (\n <ScreensaverContext.Provider value={value}>\n {children}\n {isActive && (\n <ScreensaverOverlay key={session} onStop={stop}>\n <Screensaver />\n </ScreensaverOverlay>\n )}\n </ScreensaverContext.Provider>\n );\n}\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
.screensaver-overlay {
|
|
2
|
+
position: fixed;
|
|
3
|
+
inset: 0;
|
|
4
|
+
width: 100%;
|
|
5
|
+
height: 100%;
|
|
6
|
+
max-width: none;
|
|
7
|
+
max-height: none;
|
|
8
|
+
margin: 0;
|
|
9
|
+
padding: 0;
|
|
10
|
+
border: 0;
|
|
11
|
+
overflow: hidden;
|
|
12
|
+
background: black;
|
|
13
|
+
cursor: none;
|
|
14
|
+
outline: none;
|
|
15
|
+
touch-action: none;
|
|
16
|
+
overscroll-behavior: none;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.screensaver-overlay::backdrop {
|
|
20
|
+
background: black;
|
|
21
|
+
cursor: none;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.screensaver-content {
|
|
25
|
+
width: 100%;
|
|
26
|
+
height: 100%;
|
|
27
|
+
pointer-events: none;
|
|
28
|
+
user-select: none;
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function trackHeldScreensaverInput(held: Set<string>, event: Event, includePresses: boolean): void;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Raw input inventory, independent of screensaver lifecycle. Observe idle
|
|
2
|
+
// input too, since a modifier may already be down when the host starts it.
|
|
3
|
+
function trackModifiers(held, event) {
|
|
4
|
+
// Input first held in an iframe cannot be observed by the parent. The next
|
|
5
|
+
// key/pointer event carries its modifier flags across the focus change.
|
|
6
|
+
const modifiers = {
|
|
7
|
+
Alt: event.altKey,
|
|
8
|
+
Control: event.ctrlKey,
|
|
9
|
+
Meta: event.metaKey,
|
|
10
|
+
Shift: event.shiftKey,
|
|
11
|
+
};
|
|
12
|
+
for (const [name, pressed] of Object.entries(modifiers)) {
|
|
13
|
+
const id = `modifier:${name}`;
|
|
14
|
+
if (pressed)
|
|
15
|
+
held.add(id);
|
|
16
|
+
else
|
|
17
|
+
held.delete(id);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function trackKey(held, event, includePresses) {
|
|
21
|
+
// Meta combinations may omit ordinary releases on macOS, but Escape's
|
|
22
|
+
// explicit recovery gesture must still consume its own keyup.
|
|
23
|
+
if (event.type === "keyup" && event.key === "Meta") {
|
|
24
|
+
for (const key of held)
|
|
25
|
+
if (key.startsWith("key:") && key !== "key:Escape")
|
|
26
|
+
held.delete(key);
|
|
27
|
+
}
|
|
28
|
+
if (!includePresses &&
|
|
29
|
+
!["Alt", "Control", "Meta", "Shift"].includes(event.key))
|
|
30
|
+
return;
|
|
31
|
+
const key = `key:${event.code || event.key}`;
|
|
32
|
+
if (event.type === "keydown")
|
|
33
|
+
held.add(key);
|
|
34
|
+
if (event.type === "keyup")
|
|
35
|
+
held.delete(key);
|
|
36
|
+
}
|
|
37
|
+
export function trackHeldScreensaverInput(held, event, includePresses) {
|
|
38
|
+
if (event instanceof KeyboardEvent || event instanceof MouseEvent) {
|
|
39
|
+
trackModifiers(held, event);
|
|
40
|
+
}
|
|
41
|
+
if (event instanceof KeyboardEvent) {
|
|
42
|
+
trackKey(held, event, includePresses);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (!includePresses)
|
|
46
|
+
return;
|
|
47
|
+
const pointer = event instanceof PointerEvent ? event.pointerId : 0;
|
|
48
|
+
const button = event instanceof MouseEvent ? event.button : 0;
|
|
49
|
+
switch (event.type) {
|
|
50
|
+
case "pointerdown":
|
|
51
|
+
held.add(`pointer:${pointer}`);
|
|
52
|
+
break;
|
|
53
|
+
case "pointerup":
|
|
54
|
+
case "pointercancel":
|
|
55
|
+
held.delete(`pointer:${pointer}`);
|
|
56
|
+
break;
|
|
57
|
+
case "mousedown":
|
|
58
|
+
held.add(`mouse:${button}`);
|
|
59
|
+
break;
|
|
60
|
+
case "mouseup":
|
|
61
|
+
held.delete(`mouse:${button}`);
|
|
62
|
+
break;
|
|
63
|
+
case "touchstart":
|
|
64
|
+
held.add("touch");
|
|
65
|
+
break;
|
|
66
|
+
case "touchend":
|
|
67
|
+
case "touchcancel":
|
|
68
|
+
if (typeof TouchEvent === "undefined" ||
|
|
69
|
+
!(event instanceof TouchEvent) ||
|
|
70
|
+
event.touches.length === 0) {
|
|
71
|
+
held.delete("touch");
|
|
72
|
+
}
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=screensaverHeldInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"screensaverHeldInput.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/screensaver/screensaverHeldInput.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,2EAA2E;AAC3E,SAAS,cAAc,CAAC,IAAiB,EAAE,KAAiC;IAC1E,2EAA2E;IAC3E,wEAAwE;IACxE,MAAM,SAAS,GAAG;QAChB,GAAG,EAAE,KAAK,CAAC,MAAM;QACjB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,IAAI,EAAE,KAAK,CAAC,OAAO;QACnB,KAAK,EAAE,KAAK,CAAC,QAAQ;KACtB,CAAC;IACF,KAAK,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QACxD,MAAM,EAAE,GAAG,YAAY,IAAI,EAAE,CAAC;QAC9B,IAAI,OAAO;YAAE,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;;YACrB,IAAI,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AC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IACpE,MAAM,MAAM,GAAG,KAAK,YAAY,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9D,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,aAAa;YAChB,IAAI,CAAC,GAAG,CAAC,WAAW,OAAO,EAAE,CAAC,CAAC;YAC/B,MAAM;QACR,KAAK,WAAW,CAAC;QACjB,KAAK,eAAe;YAClB,IAAI,CAAC,MAAM,CAAC,WAAW,OAAO,EAAE,CAAC,CAAC;YAClC,MAAM;QACR,KAAK,WAAW;YACd,IAAI,CAAC,GAAG,CAAC,SAAS,MAAM,EAAE,CAAC,CAAC;YAC5B,MAAM;QACR,KAAK,SAAS;YACZ,IAAI,CAAC,MAAM,CAAC,SAAS,MAAM,EAAE,CAAC,CAAC;YAC/B,MAAM;QACR,KAAK,YAAY;YACf,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAClB,MAAM;QACR,KAAK,UAAU,CAAC;QAChB,KAAK,aAAa;YAChB,IACE,OAAO,UAAU,KAAK,WAAW;gBACjC,CAAC,CAAC,KAAK,YAAY,UAAU,CAAC;gBAC9B,KAAK,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,EAC1B,CAAC;gBACD,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YACvB,CAAC;YACD,MAAM;IACV,CAAC;AACH,CAAC","sourcesContent":["// Raw input inventory, independent of screensaver lifecycle. Observe idle\n// input too, since a modifier may already be down when the host starts it.\nfunction trackModifiers(held: Set<string>, event: KeyboardEvent | MouseEvent) {\n // Input first held in an iframe cannot be observed by the parent. The next\n // key/pointer event carries its modifier flags across the focus change.\n const modifiers = {\n Alt: event.altKey,\n Control: event.ctrlKey,\n Meta: event.metaKey,\n Shift: event.shiftKey,\n };\n for (const [name, pressed] of Object.entries(modifiers)) {\n const id = `modifier:${name}`;\n if (pressed) held.add(id);\n else held.delete(id);\n }\n}\n\nfunction trackKey(\n held: Set<string>,\n event: KeyboardEvent,\n includePresses: boolean,\n) {\n // Meta combinations may omit ordinary releases on macOS, but Escape's\n // explicit recovery gesture must still consume its own keyup.\n if (event.type === \"keyup\" && event.key === \"Meta\") {\n for (const key of held)\n if (key.startsWith(\"key:\") && key !== \"key:Escape\") held.delete(key);\n }\n if (\n !includePresses &&\n ![\"Alt\", \"Control\", \"Meta\", \"Shift\"].includes(event.key)\n )\n return;\n const key = `key:${event.code || event.key}`;\n if (event.type === \"keydown\") held.add(key);\n if (event.type === \"keyup\") held.delete(key);\n}\n\nexport function trackHeldScreensaverInput(\n held: Set<string>,\n event: Event,\n includePresses: boolean,\n) {\n if (event instanceof KeyboardEvent || event instanceof MouseEvent) {\n trackModifiers(held, event);\n }\n if (event instanceof KeyboardEvent) {\n trackKey(held, event, includePresses);\n return;\n }\n if (!includePresses) return;\n const pointer = event instanceof PointerEvent ? event.pointerId : 0;\n const button = event instanceof MouseEvent ? event.button : 0;\n switch (event.type) {\n case \"pointerdown\":\n held.add(`pointer:${pointer}`);\n break;\n case \"pointerup\":\n case \"pointercancel\":\n held.delete(`pointer:${pointer}`);\n break;\n case \"mousedown\":\n held.add(`mouse:${button}`);\n break;\n case \"mouseup\":\n held.delete(`mouse:${button}`);\n break;\n case \"touchstart\":\n held.add(\"touch\");\n break;\n case \"touchend\":\n case \"touchcancel\":\n if (\n typeof TouchEvent === \"undefined\" ||\n !(event instanceof TouchEvent) ||\n event.touches.length === 0\n ) {\n held.delete(\"touch\");\n }\n break;\n }\n}\n"]}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { trackHeldScreensaverInput } from "./screensaverHeldInput.js";
|
|
2
|
+
const pointerReleases = [
|
|
3
|
+
"pointerup",
|
|
4
|
+
"mouseup",
|
|
5
|
+
"touchend",
|
|
6
|
+
"touchcancel",
|
|
7
|
+
"pointercancel",
|
|
8
|
+
];
|
|
9
|
+
function dismissEvent(event, hasHeldInput) {
|
|
10
|
+
return {
|
|
11
|
+
type: "dismiss",
|
|
12
|
+
escape: event instanceof KeyboardEvent && event.key === "Escape",
|
|
13
|
+
drain: hasHeldInput ||
|
|
14
|
+
pointerReleases.includes(event.type) ||
|
|
15
|
+
["keydown", "pointerdown", "mousedown", "touchstart"].includes(event.type) ||
|
|
16
|
+
(event instanceof MouseEvent && event.buttons !== 0),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function drainReleased(event, held) {
|
|
20
|
+
// Escape is an explicit recovery gesture even if a previous release was
|
|
21
|
+
// lost. Keep its own keyup isolated before restoring the page.
|
|
22
|
+
if (event instanceof KeyboardEvent && event.key === "Escape") {
|
|
23
|
+
if (event.type === "keydown" || event.type === "keyup")
|
|
24
|
+
held.clear();
|
|
25
|
+
if (event.type === "keydown")
|
|
26
|
+
held.add(`key:${event.code || event.key}`);
|
|
27
|
+
return event.type === "keyup";
|
|
28
|
+
}
|
|
29
|
+
return (held.size === 0 &&
|
|
30
|
+
[
|
|
31
|
+
"keyup",
|
|
32
|
+
"pointerup",
|
|
33
|
+
"mouseup",
|
|
34
|
+
"touchend",
|
|
35
|
+
"touchcancel",
|
|
36
|
+
"pointercancel",
|
|
37
|
+
"click",
|
|
38
|
+
"contextmenu",
|
|
39
|
+
].includes(event.type));
|
|
40
|
+
}
|
|
41
|
+
export function captureScreensaverInput(readState, send, held, engaged) {
|
|
42
|
+
const consume = (event) => {
|
|
43
|
+
const { status } = readState();
|
|
44
|
+
trackHeldScreensaverInput(held, event, status !== "idle");
|
|
45
|
+
if (status === "idle")
|
|
46
|
+
return;
|
|
47
|
+
event.preventDefault();
|
|
48
|
+
event.stopImmediatePropagation();
|
|
49
|
+
if (status === "settling")
|
|
50
|
+
return;
|
|
51
|
+
if (status === "draining") {
|
|
52
|
+
if (drainReleased(event, held))
|
|
53
|
+
send({ type: "released" });
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
send(dismissEvent(event, held.size > 0));
|
|
57
|
+
// A press can start during grace and first dismiss on its release. Keep
|
|
58
|
+
// isolation through the following click, even when nothing remains held.
|
|
59
|
+
if (held.size === 0 && pointerReleases.includes(event.type))
|
|
60
|
+
send({ type: "released" });
|
|
61
|
+
};
|
|
62
|
+
const events = [
|
|
63
|
+
"click",
|
|
64
|
+
"dblclick",
|
|
65
|
+
"auxclick",
|
|
66
|
+
"contextmenu",
|
|
67
|
+
"keydown",
|
|
68
|
+
"keyup",
|
|
69
|
+
"keypress",
|
|
70
|
+
"pointerdown",
|
|
71
|
+
"pointerup",
|
|
72
|
+
"pointermove",
|
|
73
|
+
"pointercancel",
|
|
74
|
+
"mousedown",
|
|
75
|
+
"mouseup",
|
|
76
|
+
"mousemove",
|
|
77
|
+
"touchstart",
|
|
78
|
+
"touchend",
|
|
79
|
+
"touchmove",
|
|
80
|
+
"touchcancel",
|
|
81
|
+
"wheel",
|
|
82
|
+
];
|
|
83
|
+
for (const type of events)
|
|
84
|
+
window.addEventListener(type, consume, {
|
|
85
|
+
capture: true,
|
|
86
|
+
passive: !engaged,
|
|
87
|
+
});
|
|
88
|
+
const blur = () => {
|
|
89
|
+
held.clear();
|
|
90
|
+
send({ type: "released" });
|
|
91
|
+
};
|
|
92
|
+
const visibility = () => {
|
|
93
|
+
if (document.visibilityState === "hidden")
|
|
94
|
+
blur();
|
|
95
|
+
};
|
|
96
|
+
document.addEventListener("visibilitychange", visibility);
|
|
97
|
+
window.addEventListener("blur", blur);
|
|
98
|
+
return () => {
|
|
99
|
+
document.removeEventListener("visibilitychange", visibility);
|
|
100
|
+
window.removeEventListener("blur", blur);
|
|
101
|
+
for (const type of events)
|
|
102
|
+
window.removeEventListener(type, consume, true);
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=screensaverInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"screensaverInput.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads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;QACvB,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE;YACrC,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,CAAC,OAAO;SAClB,CAAC,CAAC;IACL,MAAM,IAAI,GAAG,GAAG,EAAE;QAChB,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,IAAI,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;IAC7B,CAAC,CAAC;IACF,MAAM,UAAU,GAAG,GAAG,EAAE;QACtB,IAAI,QAAQ,CAAC,eAAe,KAAK,QAAQ;YAAE,IAAI,EAAE,CAAC;IACpD,CAAC,CAAC;IACF,QAAQ,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,UAAU,CAAC,CAAC;IAC1D,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACtC,OAAO,GAAG,EAAE;QACV,QAAQ,CAAC,mBAAmB,CAAC,kBAAkB,EAAE,UAAU,CAAC,CAAC;QAC7D,MAAM,CAAC,mBAAmB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACzC,KAAK,MAAM,IAAI,IAAI,MAAM;YAAE,MAAM,CAAC,mBAAmB,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;IAC7E,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { trackHeldScreensaverInput } from \"./screensaverHeldInput\";\nimport type { ScreensaverEvent, ScreensaverState } from \"./screensaverMachine\";\n\nconst pointerReleases = [\n \"pointerup\",\n \"mouseup\",\n \"touchend\",\n \"touchcancel\",\n \"pointercancel\",\n];\n\nfunction dismissEvent(event: Event, hasHeldInput: boolean): ScreensaverEvent {\n return {\n type: \"dismiss\",\n escape: event instanceof KeyboardEvent && event.key === \"Escape\",\n drain:\n hasHeldInput ||\n pointerReleases.includes(event.type) ||\n [\"keydown\", \"pointerdown\", \"mousedown\", \"touchstart\"].includes(\n event.type,\n ) ||\n (event instanceof MouseEvent && event.buttons !== 0),\n };\n}\n\nfunction drainReleased(event: Event, held: Set<string>) {\n // Escape is an explicit recovery gesture even if a previous release was\n // lost. Keep its own keyup isolated before restoring the page.\n if (event instanceof KeyboardEvent && event.key === \"Escape\") {\n if (event.type === \"keydown\" || event.type === \"keyup\") held.clear();\n if (event.type === \"keydown\") held.add(`key:${event.code || event.key}`);\n return event.type === \"keyup\";\n }\n return (\n held.size === 0 &&\n [\n \"keyup\",\n \"pointerup\",\n \"mouseup\",\n \"touchend\",\n \"touchcancel\",\n \"pointercancel\",\n \"click\",\n \"contextmenu\",\n ].includes(event.type)\n );\n}\n\nexport function captureScreensaverInput(\n readState: () => ScreensaverState,\n send: (event: ScreensaverEvent) => void,\n held: Set<string>,\n engaged: boolean,\n) {\n const consume = (event: Event) => {\n const { status } = readState();\n trackHeldScreensaverInput(held, event, status !== \"idle\");\n if (status === \"idle\") return;\n event.preventDefault();\n event.stopImmediatePropagation();\n if (status === \"settling\") return;\n if (status === \"draining\") {\n if (drainReleased(event, held)) send({ type: \"released\" });\n return;\n }\n send(dismissEvent(event, held.size > 0));\n // A press can start during grace and first dismiss on its release. Keep\n // isolation through the following click, even when nothing remains held.\n if (held.size === 0 && pointerReleases.includes(event.type))\n send({ type: \"released\" });\n };\n const events = [\n \"click\",\n \"dblclick\",\n \"auxclick\",\n \"contextmenu\",\n \"keydown\",\n \"keyup\",\n \"keypress\",\n \"pointerdown\",\n \"pointerup\",\n \"pointermove\",\n \"pointercancel\",\n \"mousedown\",\n \"mouseup\",\n \"mousemove\",\n \"touchstart\",\n \"touchend\",\n \"touchmove\",\n \"touchcancel\",\n \"wheel\",\n ];\n for (const type of events)\n window.addEventListener(type, consume, {\n capture: true,\n passive: !engaged,\n });\n const blur = () => {\n held.clear();\n send({ type: \"released\" });\n };\n const visibility = () => {\n if (document.visibilityState === \"hidden\") blur();\n };\n document.addEventListener(\"visibilitychange\", visibility);\n window.addEventListener(\"blur\", blur);\n return () => {\n document.removeEventListener(\"visibilitychange\", visibility);\n window.removeEventListener(\"blur\", blur);\n for (const type of events) window.removeEventListener(type, consume, true);\n };\n}\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export type ScreensaverState = {
|
|
2
|
+
status: "idle";
|
|
3
|
+
session: number;
|
|
4
|
+
} | {
|
|
5
|
+
status: "grace";
|
|
6
|
+
session: number;
|
|
7
|
+
} | {
|
|
8
|
+
status: "armed";
|
|
9
|
+
session: number;
|
|
10
|
+
} | {
|
|
11
|
+
status: "draining";
|
|
12
|
+
session: number;
|
|
13
|
+
} | {
|
|
14
|
+
status: "settling";
|
|
15
|
+
session: number;
|
|
16
|
+
};
|
|
17
|
+
export type ScreensaverEvent = {
|
|
18
|
+
type: "start";
|
|
19
|
+
} | {
|
|
20
|
+
type: "stop";
|
|
21
|
+
} | {
|
|
22
|
+
type: "dismiss";
|
|
23
|
+
escape: boolean;
|
|
24
|
+
drain: boolean;
|
|
25
|
+
} | {
|
|
26
|
+
type: "released";
|
|
27
|
+
} | {
|
|
28
|
+
type: "settled";
|
|
29
|
+
session: number;
|
|
30
|
+
} | {
|
|
31
|
+
type: "graceElapsed";
|
|
32
|
+
session: number;
|
|
33
|
+
};
|
|
34
|
+
export declare function transitionScreensaver(state: ScreensaverState, event: ScreensaverEvent): ScreensaverState;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
function dismiss(state, isEscape, drain) {
|
|
2
|
+
if (state.status !== "armed" && !(state.status === "grace" && isEscape))
|
|
3
|
+
return state;
|
|
4
|
+
return { status: drain ? "draining" : "idle", session: state.session };
|
|
5
|
+
}
|
|
6
|
+
export function transitionScreensaver(state, event) {
|
|
7
|
+
switch (event.type) {
|
|
8
|
+
case "start":
|
|
9
|
+
return state.status === "idle"
|
|
10
|
+
? { status: "grace", session: state.session + 1 }
|
|
11
|
+
: state;
|
|
12
|
+
case "dismiss":
|
|
13
|
+
return dismiss(state, event.escape, event.drain);
|
|
14
|
+
case "released":
|
|
15
|
+
return state.status === "draining"
|
|
16
|
+
? { status: "settling", session: state.session }
|
|
17
|
+
: state;
|
|
18
|
+
case "settled":
|
|
19
|
+
return state.status === "settling" && state.session === event.session
|
|
20
|
+
? { status: "idle", session: state.session }
|
|
21
|
+
: state;
|
|
22
|
+
case "stop":
|
|
23
|
+
return state.status === "idle"
|
|
24
|
+
? state
|
|
25
|
+
: { status: "idle", session: state.session };
|
|
26
|
+
case "graceElapsed":
|
|
27
|
+
return state.status === "grace" && state.session === event.session
|
|
28
|
+
? { status: "armed", session: state.session }
|
|
29
|
+
: state;
|
|
30
|
+
default: {
|
|
31
|
+
const exhaustive = event;
|
|
32
|
+
return exhaustive;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=screensaverMachine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"screensaverMachine.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/screensaver/screensaverMachine.ts"],"names":[],"mappings":"AAcA,SAAS,OAAO,CACd,KAAuB,EACvB,QAAiB,EACjB,KAAc;IAEd,IAAI,KAAK,CAAC,MAAM,KAAK,OAAO,IAAI,CAAC,CAAC,KAAK,CAAC,MAAM,KAAK,OAAO,IAAI,QAAQ,CAAC;QACrE,OAAO,KAAK,CAAC;IACf,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;AACzE,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,KAAuB,EACvB,KAAuB;IAEvB,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,OAAO;YACV,OAAO,KAAK,CAAC,MAAM,KAAK,MAAM;gBAC5B,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,GAAG,CAAC,EAAE;gBACjD,CAAC,CAAC,KAAK,CAAC;QACZ,KAAK,SAAS;YACZ,OAAO,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;QACnD,KAAK,UAAU;YACb,OAAO,KAAK,CAAC,MAAM,KAAK,UAAU;gBAChC,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE;gBAChD,CAAC,CAAC,KAAK,CAAC;QACZ,KAAK,SAAS;YACZ,OAAO,KAAK,CAAC,MAAM,KAAK,UAAU,IAAI,KAAK,CAAC,OAAO,KAAK,KAAK,CAAC,OAAO;gBACnE,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE;gBAC5C,CAAC,CAAC,KAAK,CAAC;QACZ,KAAK,MAAM;YACT,OAAO,KAAK,CAAC,MAAM,KAAK,MAAM;gBAC5B,CAAC,CAAC,KAAK;gBACP,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;QACjD,KAAK,cAAc;YACjB,OAAO,KAAK,CAAC,MAAM,KAAK,OAAO,IAAI,KAAK,CAAC,OAAO,KAAK,KAAK,CAAC,OAAO;gBAChE,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE;gBAC7C,CAAC,CAAC,KAAK,CAAC;QACZ,OAAO,CAAC,CAAC,CAAC;YACR,MAAM,UAAU,GAAU,KAAK,CAAC;YAChC,OAAO,UAAU,CAAC;QACpB,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["export type ScreensaverState =\n | { status: \"idle\"; session: number }\n | { status: \"grace\"; session: number }\n | { status: \"armed\"; session: number }\n | { status: \"draining\"; session: number }\n | { status: \"settling\"; session: number };\nexport type ScreensaverEvent =\n | { type: \"start\" }\n | { type: \"stop\" }\n | { type: \"dismiss\"; escape: boolean; drain: boolean }\n | { type: \"released\" }\n | { type: \"settled\"; session: number }\n | { type: \"graceElapsed\"; session: number };\n\nfunction dismiss(\n state: ScreensaverState,\n isEscape: boolean,\n drain: boolean,\n): ScreensaverState {\n if (state.status !== \"armed\" && !(state.status === \"grace\" && isEscape))\n return state;\n return { status: drain ? \"draining\" : \"idle\", session: state.session };\n}\n\nexport function transitionScreensaver(\n state: ScreensaverState,\n event: ScreensaverEvent,\n): ScreensaverState {\n switch (event.type) {\n case \"start\":\n return state.status === \"idle\"\n ? { status: \"grace\", session: state.session + 1 }\n : state;\n case \"dismiss\":\n return dismiss(state, event.escape, event.drain);\n case \"released\":\n return state.status === \"draining\"\n ? { status: \"settling\", session: state.session }\n : state;\n case \"settled\":\n return state.status === \"settling\" && state.session === event.session\n ? { status: \"idle\", session: state.session }\n : state;\n case \"stop\":\n return state.status === \"idle\"\n ? state\n : { status: \"idle\", session: state.session };\n case \"graceElapsed\":\n return state.status === \"grace\" && state.session === event.session\n ? { status: \"armed\", session: state.session }\n : state;\n default: {\n const exhaustive: never = event;\n return exhaustive;\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useCallback, useEffect, useLayoutEffect, useRef, useState, } from "react";
|
|
2
|
+
import { captureScreensaverInput } from "./screensaverInput.js";
|
|
3
|
+
import { transitionScreensaver, } from "./screensaverMachine.js";
|
|
4
|
+
import { useScreensaverIsolation } from "./useScreensaverIsolation.js";
|
|
5
|
+
export function useScreensaverController(gracePeriodMs) {
|
|
6
|
+
const [state, setState] = useState({
|
|
7
|
+
status: "idle",
|
|
8
|
+
session: 0,
|
|
9
|
+
});
|
|
10
|
+
const live = useRef(state);
|
|
11
|
+
const held = useRef(new Set());
|
|
12
|
+
const engaged = state.status !== "idle";
|
|
13
|
+
const send = useCallback((event) => {
|
|
14
|
+
const next = transitionScreensaver(live.current, event);
|
|
15
|
+
live.current = next;
|
|
16
|
+
setState(next);
|
|
17
|
+
}, []);
|
|
18
|
+
const rememberFocus = useScreensaverIsolation(state.status !== "idle");
|
|
19
|
+
const start = useCallback(() => {
|
|
20
|
+
if (live.current.status === "idle")
|
|
21
|
+
rememberFocus();
|
|
22
|
+
send({ type: "start" });
|
|
23
|
+
}, [send, rememberFocus]);
|
|
24
|
+
const stop = useCallback(() => send({ type: "stop" }), [send]);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (state.status !== "grace" && state.status !== "settling")
|
|
27
|
+
return;
|
|
28
|
+
const timer = setTimeout(() => send({
|
|
29
|
+
type: state.status === "grace" ? "graceElapsed" : "settled",
|
|
30
|
+
session: state.session,
|
|
31
|
+
}), state.status === "grace" ? gracePeriodMs : 0);
|
|
32
|
+
return () => clearTimeout(timer);
|
|
33
|
+
}, [state, gracePeriodMs, send]);
|
|
34
|
+
useLayoutEffect(() => {
|
|
35
|
+
if (!engaged)
|
|
36
|
+
held.current.clear();
|
|
37
|
+
return captureScreensaverInput(() => live.current, send, held.current, engaged);
|
|
38
|
+
}, [engaged, send]);
|
|
39
|
+
return {
|
|
40
|
+
isActive: state.status === "grace" || state.status === "armed",
|
|
41
|
+
session: state.session,
|
|
42
|
+
start,
|
|
43
|
+
stop,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=useScreensaverController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useScreensaverController.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/screensaver/useScreensaverController.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,SAAS,EACT,eAAe,EACf,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAGL,qBAAqB,GACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,MAAM,UAAU,wBAAwB,CAAC,aA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AI,EAAE,KAAK,CAAC,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS;YAC3D,OAAO,EAAE,KAAK,CAAC,OAAO;SACvB,CAAC,EACJ,KAAK,CAAC,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAC7C,CAAC;QACF,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,EAAE,IAAI,CAAC,CAAC,CAAC;IACjC,eAAe,CAAC,GAAG,EAAE;QACnB,IAAI,CAAC,OAAO;YAAE,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACnC,OAAO,uBAAuB,CAC5B,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,EAClB,IAAI,EACJ,IAAI,CAAC,OAAO,EACZ,OAAO,CACR,CAAC;IACJ,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;IACpB,OAAO;QACL,QAAQ,EAAE,KAAK,CAAC,MAAM,KAAK,OAAO,IAAI,KAAK,CAAC,MAAM,KAAK,OAAO;QAC9D,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,KAAK;QACL,IAAI;KACL,CAAC;AACJ,CAAC","sourcesContent":["import {\n useCallback,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\nimport { captureScreensaverInput } from \"./screensaverInput\";\nimport {\n type ScreensaverEvent,\n type ScreensaverState,\n transitionScreensaver,\n} from \"./screensaverMachine\";\nimport { useScreensaverIsolation } from \"./useScreensaverIsolation\";\n\nexport function useScreensaverController(gracePeriodMs: number) {\n const [state, setState] = useState<ScreensaverState>({\n status: \"idle\",\n session: 0,\n });\n const live = useRef(state);\n const held = useRef(new Set<string>());\n const engaged = state.status !== \"idle\";\n const send = useCallback((event: ScreensaverEvent) => {\n const next = transitionScreensaver(live.current, event);\n live.current = next;\n setState(next);\n }, []);\n const rememberFocus = useScreensaverIsolation(state.status !== \"idle\");\n const start = useCallback(() => {\n if (live.current.status === \"idle\") rememberFocus();\n send({ type: \"start\" });\n }, [send, rememberFocus]);\n const stop = useCallback(() => send({ type: \"stop\" }), [send]);\n useEffect(() => {\n if (state.status !== \"grace\" && state.status !== \"settling\") return;\n const timer = setTimeout(\n () =>\n send({\n type: state.status === \"grace\" ? \"graceElapsed\" : \"settled\",\n session: state.session,\n }),\n state.status === \"grace\" ? gracePeriodMs : 0,\n );\n return () => clearTimeout(timer);\n }, [state, gracePeriodMs, send]);\n useLayoutEffect(() => {\n if (!engaged) held.current.clear();\n return captureScreensaverInput(\n () => live.current,\n send,\n held.current,\n engaged,\n );\n }, [engaged, send]);\n return {\n isActive: state.status === \"grace\" || state.status === \"armed\",\n session: state.session,\n start,\n stop,\n };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useScreensaverIsolation(engaged: boolean): () => void;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useCallback, useEffect, useLayoutEffect, useRef } from "react";
|
|
2
|
+
// The modal isolates the page while visible. Keep that isolation through the
|
|
3
|
+
// release/click tail too: iframe events cannot be intercepted by their host.
|
|
4
|
+
// Per HTML 6.3.1, a showModal() dialog escapes ancestor inertness; only inert
|
|
5
|
+
// on the dialog itself would hide it. Keep the body lock across modal removal.
|
|
6
|
+
export function useScreensaverIsolation(engaged) {
|
|
7
|
+
const previousFocus = useRef(null);
|
|
8
|
+
const rememberFocus = useCallback(() => {
|
|
9
|
+
const focus = document.activeElement;
|
|
10
|
+
if (!focus?.closest("dialog.screensaver-overlay"))
|
|
11
|
+
previousFocus.current = focus;
|
|
12
|
+
}, []);
|
|
13
|
+
useLayoutEffect(() => {
|
|
14
|
+
if (!engaged)
|
|
15
|
+
return;
|
|
16
|
+
const body = document.body;
|
|
17
|
+
const wasInert = body.inert;
|
|
18
|
+
body.inert = true;
|
|
19
|
+
return () => {
|
|
20
|
+
body.inert = wasInert;
|
|
21
|
+
};
|
|
22
|
+
}, [engaged]);
|
|
23
|
+
// Restore after React's commit-time selection restoration, not in the layout
|
|
24
|
+
// cleanup which runs before it. A host that moved focus elsewhere keeps it.
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (!engaged)
|
|
27
|
+
return;
|
|
28
|
+
const focus = previousFocus.current;
|
|
29
|
+
return () => {
|
|
30
|
+
if (document.activeElement !== document.body)
|
|
31
|
+
return;
|
|
32
|
+
if (focus instanceof HTMLElement && focus.isConnected) {
|
|
33
|
+
focus.focus({ preventScroll: true });
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}, [engaged]);
|
|
37
|
+
return rememberFocus;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=useScreensaverIsolation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useScreensaverIsolation.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/screensaver/useScreensaverIsolation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAExE,6EAA6E;AAC7E,6EAA6E;AAC7E,8EAA8E;AAC9E,+EAA+E;AAC/E,MAAM,UAAU,uBAAuB,CAAC,OAAgB;IACtD,MAAM,aAAa,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IACnD,MAAM,aAAa,GAAG,WAAW,CAAC,GAAG,EAAE;QACrC,MAAM,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC;QACrC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,4BAA4B,CAAC;YAC/C,aAAa,CAAC,OAAO,GAAG,KAAK,CAAC;IAClC,CAAC,EAAE,EAAE,CAAC,CAAC;IACP,eAAe,CAAC,GAAG,EAAE;QACnB,IAAI,CAAC,OAAO;YAAE,OAAO;QACrB,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC;QAC3B,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC;QAC5B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,OAAO,GAAG,EAAE;YACV,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC;QACxB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IACd,6EAA6E;IAC7E,4EAA4E;IAC5E,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,OAAO;YAAE,OAAO;QACrB,MAAM,KAAK,GAAG,aAAa,CAAC,OAAO,CAAC;QACpC,OAAO,GAAG,EAAE;YACV,IAAI,QAAQ,CAAC,aAAa,KAAK,QAAQ,CAAC,IAAI;gBAAE,OAAO;YACrD,IAAI,KAAK,YAAY,WAAW,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC;gBACtD,KAAK,CAAC,KAAK,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;YACvC,CAAC;QACH,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IACd,OAAO,aAAa,CAAC;AACvB,CAAC","sourcesContent":["import { useCallback, useEffect, useLayoutEffect, useRef } from \"react\";\n\n// The modal isolates the page while visible. Keep that isolation through the\n// release/click tail too: iframe events cannot be intercepted by their host.\n// Per HTML 6.3.1, a showModal() dialog escapes ancestor inertness; only inert\n// on the dialog itself would hide it. Keep the body lock across modal removal.\nexport function useScreensaverIsolation(engaged: boolean) {\n const previousFocus = useRef<Element | null>(null);\n const rememberFocus = useCallback(() => {\n const focus = document.activeElement;\n if (!focus?.closest(\"dialog.screensaver-overlay\"))\n previousFocus.current = focus;\n }, []);\n useLayoutEffect(() => {\n if (!engaged) return;\n const body = document.body;\n const wasInert = body.inert;\n body.inert = true;\n return () => {\n body.inert = wasInert;\n };\n }, [engaged]);\n // Restore after React's commit-time selection restoration, not in the layout\n // cleanup which runs before it. A host that moved focus elsewhere keeps it.\n useEffect(() => {\n if (!engaged) return;\n const focus = previousFocus.current;\n return () => {\n if (document.activeElement !== document.body) return;\n if (focus instanceof HTMLElement && focus.isConnected) {\n focus.focus({ preventScroll: true });\n }\n };\n }, [engaged]);\n return rememberFocus;\n}\n"]}
|