foldkit-primitives 0.15.4 → 0.16.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/device/fullscreen.d.ts +28 -0
- package/dist/device/fullscreen.d.ts.map +1 -0
- package/dist/device/fullscreen.js +69 -0
- package/dist/device/fullscreen.js.map +1 -0
- package/dist/device/geolocation.d.ts +56 -0
- package/dist/device/geolocation.d.ts.map +1 -0
- package/dist/device/geolocation.js +87 -0
- package/dist/device/geolocation.js.map +1 -0
- package/dist/device/index.d.ts +5 -0
- package/dist/device/index.js +6 -0
- package/dist/device/media-devices.d.ts +88 -0
- package/dist/device/media-devices.d.ts.map +1 -0
- package/dist/device/media-devices.js +117 -0
- package/dist/device/media-devices.js.map +1 -0
- package/dist/device/media-stream.d.ts +93 -0
- package/dist/device/media-stream.d.ts.map +1 -0
- package/dist/device/media-stream.js +106 -0
- package/dist/device/media-stream.js.map +1 -0
- package/dist/device/permissions.d.ts +106 -0
- package/dist/device/permissions.d.ts.map +1 -0
- package/dist/device/permissions.js +143 -0
- package/dist/device/permissions.js.map +1 -0
- package/dist/dom/autofocus.d.ts +15 -0
- package/dist/dom/autofocus.d.ts.map +1 -0
- package/dist/dom/autofocus.js +22 -0
- package/dist/dom/autofocus.js.map +1 -0
- package/dist/dom/clipboard.d.ts +30 -0
- package/dist/dom/clipboard.d.ts.map +1 -0
- package/dist/dom/clipboard.js +50 -0
- package/dist/dom/clipboard.js.map +1 -0
- package/dist/dom/editable-text.d.ts +72 -0
- package/dist/dom/editable-text.d.ts.map +1 -0
- package/dist/dom/editable-text.js +232 -0
- package/dist/dom/editable-text.js.map +1 -0
- package/dist/dom/fluid-hover.d.ts +93 -0
- package/dist/dom/fluid-hover.d.ts.map +1 -0
- package/dist/dom/fluid-hover.js +294 -0
- package/dist/dom/fluid-hover.js.map +1 -0
- package/dist/dom/focus-scope.d.ts +21 -0
- package/dist/dom/focus-scope.d.ts.map +1 -0
- package/dist/dom/focus-scope.js +93 -0
- package/dist/dom/focus-scope.js.map +1 -0
- package/dist/dom/follow-tab-stop.d.ts +11 -0
- package/dist/dom/follow-tab-stop.d.ts.map +1 -0
- package/dist/dom/follow-tab-stop.js +54 -0
- package/dist/dom/follow-tab-stop.js.map +1 -0
- package/dist/dom/image-decode.d.ts +27 -0
- package/dist/dom/image-decode.d.ts.map +1 -0
- package/dist/dom/image-decode.js +50 -0
- package/dist/dom/image-decode.js.map +1 -0
- package/dist/dom/index.d.ts +24 -0
- package/dist/dom/index.js +25 -0
- package/dist/dom/input-mask.d.ts +35 -0
- package/dist/dom/input-mask.d.ts.map +1 -0
- package/dist/dom/input-mask.js +90 -0
- package/dist/dom/input-mask.js.map +1 -0
- package/dist/dom/keep-in-view.d.ts +16 -0
- package/dist/dom/keep-in-view.d.ts.map +1 -0
- package/dist/dom/keep-in-view.js +38 -0
- package/dist/dom/keep-in-view.js.map +1 -0
- package/dist/dom/keyboard-inset.d.ts +29 -0
- package/dist/dom/keyboard-inset.d.ts.map +1 -0
- package/dist/dom/keyboard-inset.js +45 -0
- package/dist/dom/keyboard-inset.js.map +1 -0
- package/dist/dom/layers.d.ts +6 -0
- package/dist/dom/layers.d.ts.map +1 -0
- package/dist/dom/layers.js +35 -0
- package/dist/dom/layers.js.map +1 -0
- package/dist/dom/measure.d.ts +42 -0
- package/dist/dom/measure.d.ts.map +1 -0
- package/dist/dom/measure.js +123 -0
- package/dist/dom/measure.js.map +1 -0
- package/dist/dom/move.d.ts +45 -0
- package/dist/dom/move.d.ts.map +1 -0
- package/dist/dom/move.js +96 -0
- package/dist/dom/move.js.map +1 -0
- package/dist/dom/pointed-links.d.ts +13 -0
- package/dist/dom/pointed-links.d.ts.map +1 -0
- package/dist/dom/pointed-links.js +59 -0
- package/dist/dom/pointed-links.js.map +1 -0
- package/dist/dom/pointer-drag.d.ts +132 -0
- package/dist/dom/pointer-drag.d.ts.map +1 -0
- package/dist/dom/pointer-drag.js +307 -0
- package/dist/dom/pointer-drag.js.map +1 -0
- package/dist/dom/pointer-position.d.ts +133 -0
- package/dist/dom/pointer-position.d.ts.map +1 -0
- package/dist/dom/pointer-position.js +173 -0
- package/dist/dom/pointer-position.js.map +1 -0
- package/dist/dom/script-loader.d.ts +12 -0
- package/dist/dom/script-loader.d.ts.map +1 -0
- package/dist/dom/script-loader.js +54 -0
- package/dist/dom/script-loader.js.map +1 -0
- package/dist/dom/scroll-bars.d.ts +52 -0
- package/dist/dom/scroll-bars.d.ts.map +1 -0
- package/dist/dom/scroll-bars.js +259 -0
- package/dist/dom/scroll-bars.js.map +1 -0
- package/dist/dom/scroll-settle.d.ts +33 -0
- package/dist/dom/scroll-settle.d.ts.map +1 -0
- package/dist/dom/scroll-settle.js +84 -0
- package/dist/dom/scroll-settle.js.map +1 -0
- package/dist/dom/scroll.d.ts +21 -0
- package/dist/dom/scroll.d.ts.map +1 -0
- package/dist/dom/scroll.js +141 -0
- package/dist/dom/scroll.js.map +1 -0
- package/dist/dom/share.d.ts +19 -0
- package/dist/dom/share.d.ts.map +1 -0
- package/dist/dom/share.js +41 -0
- package/dist/dom/share.js.map +1 -0
- package/dist/dom/swipe.d.ts +121 -0
- package/dist/dom/swipe.d.ts.map +1 -0
- package/dist/dom/swipe.js +291 -0
- package/dist/dom/swipe.js.map +1 -0
- package/dist/dom/targets.d.ts +45 -0
- package/dist/dom/targets.d.ts.map +1 -0
- package/dist/dom/targets.js +70 -0
- package/dist/dom/targets.js.map +1 -0
- package/dist/dom/track-box.d.ts +61 -0
- package/dist/dom/track-box.d.ts.map +1 -0
- package/dist/dom/track-box.js +131 -0
- package/dist/dom/track-box.js.map +1 -0
- package/dist/events/active-element.d.ts +15 -0
- package/dist/events/active-element.d.ts.map +1 -0
- package/dist/events/active-element.js +33 -0
- package/dist/events/active-element.js.map +1 -0
- package/dist/events/hotkeys.d.ts +22 -0
- package/dist/events/hotkeys.d.ts.map +1 -0
- package/dist/events/hotkeys.js +56 -0
- package/dist/events/hotkeys.js.map +1 -0
- package/dist/events/idle.d.ts +29 -0
- package/dist/events/idle.d.ts.map +1 -0
- package/dist/events/idle.js +51 -0
- package/dist/events/idle.js.map +1 -0
- package/dist/events/index.d.ts +9 -0
- package/dist/events/index.js +10 -0
- package/dist/{input-modality-l7InESYh.d.mts → events/input-modality.d.ts} +9 -10
- package/dist/events/input-modality.d.ts.map +1 -0
- package/dist/{input-modality-XwQOFLip.mjs → events/input-modality.js} +2 -2
- package/dist/events/input-modality.js.map +1 -0
- package/dist/events/keyboard.d.ts +30 -0
- package/dist/events/keyboard.d.ts.map +1 -0
- package/dist/events/keyboard.js +55 -0
- package/dist/events/keyboard.js.map +1 -0
- package/dist/events/pointer.d.ts +15 -0
- package/dist/events/pointer.d.ts.map +1 -0
- package/dist/events/pointer.js +28 -0
- package/dist/events/pointer.js.map +1 -0
- package/dist/events/scroll.d.ts +16 -0
- package/dist/events/scroll.d.ts.map +1 -0
- package/dist/events/scroll.js +29 -0
- package/dist/events/scroll.js.map +1 -0
- package/dist/events/visibility.d.ts +25 -0
- package/dist/events/visibility.d.ts.map +1 -0
- package/dist/events/visibility.js +28 -0
- package/dist/events/visibility.js.map +1 -0
- package/dist/events/window-size.d.ts +30 -0
- package/dist/events/window-size.d.ts.map +1 -0
- package/dist/events/window-size.js +63 -0
- package/dist/events/window-size.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +10 -0
- package/dist/interaction/bundle-behavior.d.ts +37 -0
- package/dist/interaction/bundle-behavior.d.ts.map +1 -0
- package/dist/interaction/bundle-behavior.js +34 -0
- package/dist/interaction/bundle-behavior.js.map +1 -0
- package/dist/interaction/dismiss-layer.d.ts +100 -0
- package/dist/interaction/dismiss-layer.d.ts.map +1 -0
- package/dist/interaction/dismiss-layer.js +140 -0
- package/dist/interaction/dismiss-layer.js.map +1 -0
- package/dist/interaction/editable-text.d.ts +13 -0
- package/dist/interaction/editable-text.d.ts.map +1 -0
- package/dist/interaction/editable-text.js +17 -0
- package/dist/interaction/editable-text.js.map +1 -0
- package/dist/interaction/focus-scope.d.ts +21 -0
- package/dist/interaction/focus-scope.d.ts.map +1 -0
- package/dist/interaction/focus-scope.js +25 -0
- package/dist/interaction/focus-scope.js.map +1 -0
- package/dist/interaction/focus-visible.d.ts +9 -0
- package/dist/interaction/focus-visible.d.ts.map +1 -0
- package/dist/interaction/focus-visible.js +10 -0
- package/dist/interaction/focus-visible.js.map +1 -0
- package/dist/interaction/grid-navigation.d.ts +73 -0
- package/dist/interaction/grid-navigation.d.ts.map +1 -0
- package/dist/interaction/grid-navigation.js +137 -0
- package/dist/interaction/grid-navigation.js.map +1 -0
- package/dist/interaction/index.d.ts +21 -0
- package/dist/interaction/index.js +21 -0
- package/dist/interaction/layers.d.ts +12 -0
- package/dist/interaction/layers.d.ts.map +1 -0
- package/dist/interaction/layers.js +14 -0
- package/dist/interaction/layers.js.map +1 -0
- package/dist/interaction/list-navigation.d.ts +105 -0
- package/dist/interaction/list-navigation.d.ts.map +1 -0
- package/dist/interaction/list-navigation.js +168 -0
- package/dist/interaction/list-navigation.js.map +1 -0
- package/dist/interaction/live-announce.d.ts +70 -0
- package/dist/interaction/live-announce.d.ts.map +1 -0
- package/dist/interaction/live-announce.js +115 -0
- package/dist/interaction/live-announce.js.map +1 -0
- package/dist/interaction/long-press.d.ts +102 -0
- package/dist/interaction/long-press.d.ts.map +1 -0
- package/dist/interaction/long-press.js +115 -0
- package/dist/interaction/long-press.js.map +1 -0
- package/dist/interaction/move.d.ts +10 -0
- package/dist/interaction/move.d.ts.map +1 -0
- package/dist/interaction/move.js +17 -0
- package/dist/interaction/move.js.map +1 -0
- package/dist/interaction/overlay.d.ts +45 -0
- package/dist/interaction/overlay.d.ts.map +1 -0
- package/dist/interaction/overlay.js +57 -0
- package/dist/interaction/overlay.js.map +1 -0
- package/dist/interaction/placing.d.ts +86 -0
- package/dist/interaction/placing.d.ts.map +1 -0
- package/dist/interaction/placing.js +239 -0
- package/dist/interaction/placing.js.map +1 -0
- package/dist/interaction/pointer-drag.d.ts +23 -0
- package/dist/interaction/pointer-drag.d.ts.map +1 -0
- package/dist/interaction/pointer-drag.js +21 -0
- package/dist/interaction/pointer-drag.js.map +1 -0
- package/dist/interaction/press.d.ts +152 -0
- package/dist/interaction/press.d.ts.map +1 -0
- package/dist/interaction/press.js +229 -0
- package/dist/interaction/press.js.map +1 -0
- package/dist/interaction/roving-tabindex.d.ts +85 -0
- package/dist/interaction/roving-tabindex.d.ts.map +1 -0
- package/dist/interaction/roving-tabindex.js +142 -0
- package/dist/interaction/roving-tabindex.js.map +1 -0
- package/dist/interaction/selection.d.ts +72 -0
- package/dist/interaction/selection.d.ts.map +1 -0
- package/dist/interaction/selection.js +129 -0
- package/dist/interaction/selection.js.map +1 -0
- package/dist/interaction/targets.d.ts +15 -0
- package/dist/interaction/targets.d.ts.map +1 -0
- package/dist/interaction/targets.js +20 -0
- package/dist/interaction/targets.js.map +1 -0
- package/dist/interaction/tree-navigation.d.ts +111 -0
- package/dist/interaction/tree-navigation.d.ts.map +1 -0
- package/dist/interaction/tree-navigation.js +207 -0
- package/dist/interaction/tree-navigation.js.map +1 -0
- package/dist/interaction/typeahead.d.ts +73 -0
- package/dist/interaction/typeahead.d.ts.map +1 -0
- package/dist/interaction/typeahead.js +113 -0
- package/dist/interaction/typeahead.js.map +1 -0
- package/dist/internal.d.ts +16 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/{internal-C4gHodLc.mjs → internal.js} +7 -5
- package/dist/internal.js.map +1 -0
- package/dist/media/breakpoints.d.ts +37 -0
- package/dist/media/breakpoints.d.ts.map +1 -0
- package/dist/media/breakpoints.js +64 -0
- package/dist/media/breakpoints.js.map +1 -0
- package/dist/media/index.d.ts +3 -0
- package/dist/media/index.js +4 -0
- package/dist/media/mediaquery.d.ts +40 -0
- package/dist/media/mediaquery.d.ts.map +1 -0
- package/dist/media/mediaquery.js +42 -0
- package/dist/media/mediaquery.js.map +1 -0
- package/dist/media/platform.d.ts +30 -0
- package/dist/media/platform.d.ts.map +1 -0
- package/dist/media/platform.js +50 -0
- package/dist/media/platform.js.map +1 -0
- package/dist/motion/index.d.ts +5 -0
- package/dist/motion/index.js +5 -0
- package/dist/motion/motion.d.ts +16 -0
- package/dist/motion/motion.d.ts.map +1 -0
- package/dist/motion/motion.js +25 -0
- package/dist/motion/motion.js.map +1 -0
- package/dist/motion/presence.d.ts +37 -0
- package/dist/motion/presence.d.ts.map +1 -0
- package/dist/motion/presence.js +65 -0
- package/dist/motion/presence.js.map +1 -0
- package/dist/motion/spring.d.ts +50 -0
- package/dist/motion/spring.d.ts.map +1 -0
- package/dist/motion/spring.js +92 -0
- package/dist/motion/spring.js.map +1 -0
- package/dist/motion/tween.d.ts +44 -0
- package/dist/motion/tween.d.ts.map +1 -0
- package/dist/motion/tween.js +65 -0
- package/dist/motion/tween.js.map +1 -0
- package/dist/net/broadcast.d.ts +39 -0
- package/dist/net/broadcast.d.ts.map +1 -0
- package/dist/net/broadcast.js +73 -0
- package/dist/net/broadcast.js.map +1 -0
- package/dist/net/index.d.ts +5 -0
- package/dist/net/index.js +6 -0
- package/dist/net/online.d.ts +24 -0
- package/dist/net/online.d.ts.map +1 -0
- package/dist/net/online.js +26 -0
- package/dist/net/online.js.map +1 -0
- package/dist/net/sharedHost.d.ts +64 -0
- package/dist/net/sharedHost.d.ts.map +1 -0
- package/dist/net/sharedHost.js +124 -0
- package/dist/net/sharedHost.js.map +1 -0
- package/dist/net/sse.d.ts +115 -0
- package/dist/net/sse.d.ts.map +1 -0
- package/dist/net/sse.js +138 -0
- package/dist/net/sse.js.map +1 -0
- package/dist/net/websocket.d.ts +172 -0
- package/dist/net/websocket.d.ts.map +1 -0
- package/dist/net/websocket.js +199 -0
- package/dist/net/websocket.js.map +1 -0
- package/dist/observers/bounds.d.ts +24 -0
- package/dist/observers/bounds.d.ts.map +1 -0
- package/dist/observers/bounds.js +51 -0
- package/dist/observers/bounds.js.map +1 -0
- package/dist/observers/index.d.ts +4 -0
- package/dist/observers/index.js +5 -0
- package/dist/observers/intersection.d.ts +18 -0
- package/dist/observers/intersection.d.ts.map +1 -0
- package/dist/observers/intersection.js +33 -0
- package/dist/observers/intersection.js.map +1 -0
- package/dist/observers/mutation.d.ts +25 -0
- package/dist/observers/mutation.d.ts.map +1 -0
- package/dist/observers/mutation.js +53 -0
- package/dist/observers/mutation.js.map +1 -0
- package/dist/observers/resize.d.ts +18 -0
- package/dist/observers/resize.d.ts.map +1 -0
- package/dist/observers/resize.js +33 -0
- package/dist/observers/resize.js.map +1 -0
- package/dist/state/history.d.ts +115 -0
- package/dist/state/history.d.ts.map +1 -0
- package/dist/state/history.js +167 -0
- package/dist/state/history.js.map +1 -0
- package/dist/state/index.d.ts +6 -0
- package/dist/state/index.js +7 -0
- package/dist/state/locale.d.ts +27 -0
- package/dist/state/locale.d.ts.map +1 -0
- package/dist/state/locale.js +25 -0
- package/dist/state/locale.js.map +1 -0
- package/dist/state/pagination.d.ts +53 -0
- package/dist/state/pagination.d.ts.map +1 -0
- package/dist/state/pagination.js +72 -0
- package/dist/state/pagination.js.map +1 -0
- package/dist/state/range.d.ts +9 -0
- package/dist/state/range.d.ts.map +1 -0
- package/dist/state/range.js +18 -0
- package/dist/state/range.js.map +1 -0
- package/dist/state/selection.d.ts +47 -0
- package/dist/state/selection.d.ts.map +1 -0
- package/dist/state/selection.js +39 -0
- package/dist/state/selection.js.map +1 -0
- package/dist/state/virtual.d.ts +201 -0
- package/dist/state/virtual.d.ts.map +1 -0
- package/dist/state/{index.mjs → virtual.js} +10 -306
- package/dist/state/virtual.js.map +1 -0
- package/dist/time/debounce.d.ts +43 -0
- package/dist/time/debounce.d.ts.map +1 -0
- package/dist/time/debounce.js +65 -0
- package/dist/time/debounce.js.map +1 -0
- package/dist/time/index.d.ts +6 -0
- package/dist/time/index.js +7 -0
- package/dist/time/interval.d.ts +37 -0
- package/dist/time/interval.d.ts.map +1 -0
- package/dist/time/interval.js +52 -0
- package/dist/time/interval.js.map +1 -0
- package/dist/time/relative.d.ts +8 -0
- package/dist/time/relative.d.ts.map +1 -0
- package/dist/time/relative.js +27 -0
- package/dist/time/relative.js.map +1 -0
- package/dist/time/throttle.d.ts +38 -0
- package/dist/time/throttle.d.ts.map +1 -0
- package/dist/time/throttle.js +39 -0
- package/dist/time/throttle.js.map +1 -0
- package/dist/time/ticks.d.ts +21 -0
- package/dist/time/ticks.d.ts.map +1 -0
- package/dist/time/ticks.js +30 -0
- package/dist/time/ticks.js.map +1 -0
- package/dist/time/timer.d.ts +32 -0
- package/dist/time/timer.d.ts.map +1 -0
- package/dist/time/timer.js +50 -0
- package/dist/time/timer.js.map +1 -0
- package/package.json +31 -31
- package/dist/device/index.d.mts +0 -335
- package/dist/device/index.d.mts.map +0 -1
- package/dist/device/index.mjs +0 -493
- package/dist/device/index.mjs.map +0 -1
- package/dist/dom/index.d.mts +0 -714
- package/dist/dom/index.d.mts.map +0 -1
- package/dist/dom/index.mjs +0 -1840
- package/dist/dom/index.mjs.map +0 -1
- package/dist/editable-text-Bg7vil7h.d.mts +0 -307
- package/dist/editable-text-Bg7vil7h.d.mts.map +0 -1
- package/dist/events/index.d.mts +0 -168
- package/dist/events/index.d.mts.map +0 -1
- package/dist/events/index.mjs +0 -307
- package/dist/events/index.mjs.map +0 -1
- package/dist/follow-tab-stop-DM5EI4Ci.mjs +0 -856
- package/dist/follow-tab-stop-DM5EI4Ci.mjs.map +0 -1
- package/dist/index-Bomdwb7e.d.mts +0 -142
- package/dist/index-Bomdwb7e.d.mts.map +0 -1
- package/dist/index.d.mts +0 -12
- package/dist/index.mjs +0 -12
- package/dist/input-modality-XwQOFLip.mjs.map +0 -1
- package/dist/input-modality-l7InESYh.d.mts.map +0 -1
- package/dist/interaction/index.d.mts +0 -1193
- package/dist/interaction/index.d.mts.map +0 -1
- package/dist/interaction/index.mjs +0 -1992
- package/dist/interaction/index.mjs.map +0 -1
- package/dist/internal-C4gHodLc.mjs.map +0 -1
- package/dist/media/index.d.mts +0 -103
- package/dist/media/index.d.mts.map +0 -1
- package/dist/media/index.mjs +0 -146
- package/dist/media/index.mjs.map +0 -1
- package/dist/motion/index.d.mts +0 -2
- package/dist/motion/index.mjs +0 -1
- package/dist/motion-BmlJCjn6.mjs +0 -236
- package/dist/motion-BmlJCjn6.mjs.map +0 -1
- package/dist/net/index.d.mts +0 -338
- package/dist/net/index.d.mts.map +0 -1
- package/dist/net/index.mjs +0 -530
- package/dist/net/index.mjs.map +0 -1
- package/dist/observers/index.d.mts +0 -76
- package/dist/observers/index.d.mts.map +0 -1
- package/dist/observers/index.mjs +0 -155
- package/dist/observers/index.mjs.map +0 -1
- package/dist/rolldown-runtime-D8jQpDG7.mjs +0 -12
- package/dist/state/index.d.mts +0 -432
- package/dist/state/index.d.mts.map +0 -1
- package/dist/state/index.mjs.map +0 -1
- package/dist/time/index.d.mts +0 -167
- package/dist/time/index.d.mts.map +0 -1
- package/dist/time/index.mjs +0 -236
- package/dist/time/index.mjs.map +0 -1
package/dist/dom/index.mjs
DELETED
|
@@ -1,1840 +0,0 @@
|
|
|
1
|
-
import { A as FocusScope, C as targetOf, D as Moved, E as MoveStarted, O as HideOutside, S as Targets, T as MoveEnded, _ as PointerDrag, a as TextCommitted, b as TargetHovered, c as DRAG_THRESHOLD, d as DragPlace, f as DragStarted, g as HOLD_TO_DRAG_MS, h as HOLD_SLOP, i as TextCancelled, j as tabbableWithin, k as ScrollLock, l as DragCancelled, m as DraggedOver, n as EditAsked, o as TextEdited, p as DragZone, r as EditableText, s as textOf, t as FollowTabStop, u as DragDropped, v as boxOf, w as Move, x as TargetPressed, y as zoneOf } from "../follow-tab-stop-DM5EI4Ci.mjs";
|
|
2
|
-
import { Effect, Option, Queue, Schema, Stream } from "effect";
|
|
3
|
-
import * as Mount from "foldkit/mount";
|
|
4
|
-
import { defineMessageUnion } from "foldkit/message";
|
|
5
|
-
import * as Dom from "foldkit/dom";
|
|
6
|
-
import { fromString, toString } from "foldkit/url";
|
|
7
|
-
// src/dom/autofocus.ts
|
|
8
|
-
const Focused = Schema.TaggedStruct("Focused", {});
|
|
9
|
-
/**
|
|
10
|
-
* Autofocus as a Mount: focuses the element on insert, then emits `Focused`.
|
|
11
|
-
* The message means focus was requested — a non-focusable element or a
|
|
12
|
-
* hidden tab may decline, and the browser does not report that. Plain
|
|
13
|
-
* `focus()`, no scroll options: scroll behavior stays the application's
|
|
14
|
-
* choice.
|
|
15
|
-
*/
|
|
16
|
-
const Autofocus = Mount.define("Autofocus", {
|
|
17
|
-
messages: [Focused],
|
|
18
|
-
execute: ({ element }) => Effect.sync(() => {
|
|
19
|
-
const focusable = element;
|
|
20
|
-
if (typeof focusable.focus === "function") focusable.focus.call(element);
|
|
21
|
-
return Focused.make({});
|
|
22
|
-
})
|
|
23
|
-
});
|
|
24
|
-
// src/dom/clipboard.ts
|
|
25
|
-
/**
|
|
26
|
-
* The clipboard as Commands: run in `update` beside any bundle. A copy yields
|
|
27
|
-
* `Copied` or `CopyFailed`, a read `Read` or `ReadFailed`. No Model involved:
|
|
28
|
-
* the clipboard is not application state.
|
|
29
|
-
*/
|
|
30
|
-
const ClipboardMessage = defineMessageUnion({
|
|
31
|
-
Copied: {},
|
|
32
|
-
CopyFailed: { message: Schema.String }
|
|
33
|
-
});
|
|
34
|
-
const ClipboardReadMessage = defineMessageUnion({
|
|
35
|
-
Read: { text: Schema.String },
|
|
36
|
-
ReadFailed: { message: Schema.String }
|
|
37
|
-
});
|
|
38
|
-
const failMessage$2 = (error) => error instanceof Error ? error.message : String(error);
|
|
39
|
-
/**
|
|
40
|
-
* Copies text to the clipboard. Without a clipboard API (SSR, insecure
|
|
41
|
-
* context, denied permission) the command yields `CopyFailed` instead of
|
|
42
|
-
* throwing, so `update` handles both outcomes as Messages.
|
|
43
|
-
*/
|
|
44
|
-
const copyText = (text) => ({
|
|
45
|
-
name: "Clipboard.copy",
|
|
46
|
-
args: { text },
|
|
47
|
-
effect: typeof navigator !== "undefined" && typeof navigator.clipboard?.writeText === "function" ? Effect.matchEffect(Effect.tryPromise({
|
|
48
|
-
try: () => navigator.clipboard.writeText(text),
|
|
49
|
-
catch: failMessage$2
|
|
50
|
-
}), {
|
|
51
|
-
onFailure: (message) => Effect.succeed(ClipboardMessage.CopyFailed({ message })),
|
|
52
|
-
onSuccess: () => Effect.succeed(ClipboardMessage.Copied())
|
|
53
|
-
}) : Effect.succeed(ClipboardMessage.CopyFailed({ message: "clipboard is unavailable" }))
|
|
54
|
-
});
|
|
55
|
-
/**
|
|
56
|
-
* Reads the clipboard's text. The browser may ask the user first; a refusal,
|
|
57
|
-
* an insecure context or no clipboard API yields `ReadFailed`.
|
|
58
|
-
*/
|
|
59
|
-
const readText = () => ({
|
|
60
|
-
name: "Clipboard.read",
|
|
61
|
-
effect: typeof navigator !== "undefined" && typeof navigator.clipboard?.readText === "function" ? Effect.matchEffect(Effect.tryPromise({
|
|
62
|
-
try: () => navigator.clipboard.readText(),
|
|
63
|
-
catch: failMessage$2
|
|
64
|
-
}), {
|
|
65
|
-
onFailure: (message) => Effect.succeed(ClipboardReadMessage.ReadFailed({ message })),
|
|
66
|
-
onSuccess: (text) => Effect.succeed(ClipboardReadMessage.Read({ text }))
|
|
67
|
-
}) : Effect.succeed(ClipboardReadMessage.ReadFailed({ message: "clipboard is unavailable" }))
|
|
68
|
-
});
|
|
69
|
-
// src/dom/input-mask.ts
|
|
70
|
-
/** What `InputMask` reports after each edit: the masked text shown, and the characters typed. */
|
|
71
|
-
const Input = Schema.TaggedStruct("Input", {
|
|
72
|
-
value: Schema.String,
|
|
73
|
-
raw: Schema.String
|
|
74
|
-
});
|
|
75
|
-
const isDigit = (char) => char >= "0" && char <= "9";
|
|
76
|
-
const isLetter = (char) => char >= "a" && char <= "z" || char >= "A" && char <= "Z";
|
|
77
|
-
const matches = (placeholder, char) => placeholder === "#" ? isDigit(char) : placeholder === "A" ? isLetter(char) : isDigit(char) || isLetter(char);
|
|
78
|
-
const isPlaceholder = (char) => char === "#" || char === "A" || char === "*";
|
|
79
|
-
/** Whether any placeholder at or after `from` consumes any input at or after `at`. */
|
|
80
|
-
const fillable = (pattern, from, value, at) => {
|
|
81
|
-
for (let i = from; i < pattern.length; i++) {
|
|
82
|
-
const placeholder = pattern[i];
|
|
83
|
-
if (!isPlaceholder(placeholder)) continue;
|
|
84
|
-
for (let j = at; j < value.length; j++) if (matches(placeholder, value[j])) return true;
|
|
85
|
-
}
|
|
86
|
-
return false;
|
|
87
|
-
};
|
|
88
|
-
/**
|
|
89
|
-
* The mask as a pure function: `#` takes a digit, `A` a letter, `*` either, and
|
|
90
|
-
* any other character of the pattern is written in once input reaches past it.
|
|
91
|
-
* Input that fits no placeholder is skipped. `masked` is what the field shows;
|
|
92
|
-
* `raw` is only the characters typed.
|
|
93
|
-
*/
|
|
94
|
-
const applyMask = (value, pattern) => {
|
|
95
|
-
let masked = "";
|
|
96
|
-
let raw = "";
|
|
97
|
-
let at = 0;
|
|
98
|
-
for (let i = 0; i < pattern.length; i++) {
|
|
99
|
-
const slot = pattern[i];
|
|
100
|
-
if (isPlaceholder(slot)) {
|
|
101
|
-
while (at < value.length && !matches(slot, value[at])) at++;
|
|
102
|
-
if (at >= value.length) break;
|
|
103
|
-
masked += value[at];
|
|
104
|
-
raw += value[at];
|
|
105
|
-
at++;
|
|
106
|
-
} else if (fillable(pattern, i + 1, value, at)) masked += slot;
|
|
107
|
-
else break;
|
|
108
|
-
}
|
|
109
|
-
return {
|
|
110
|
-
masked,
|
|
111
|
-
raw
|
|
112
|
-
};
|
|
113
|
-
};
|
|
114
|
-
const asField = (element) => {
|
|
115
|
-
const field = element;
|
|
116
|
-
return typeof field.value === "string" && typeof field.addEventListener === "function" ? field : null;
|
|
117
|
-
};
|
|
118
|
-
/**
|
|
119
|
-
* An input mask as a Mount plus a pure mask function. The pattern language
|
|
120
|
-
* is three placeholders — `#` digit, `A` letter, `*` either, all ASCII —
|
|
121
|
-
* with every other character literal. Literals appear only once a later placeholder
|
|
122
|
-
* consumes input, so partial values never dangle a separator. The Mount
|
|
123
|
-
* rewrites the field, restores the caret approximately, and emits `Input`
|
|
124
|
-
* with both the masked and raw values; the parent owns the state, like any
|
|
125
|
-
* controlled input.
|
|
126
|
-
*/
|
|
127
|
-
const InputMask = Mount.defineStream("InputMask", {
|
|
128
|
-
messages: [Input],
|
|
129
|
-
args: { pattern: Schema.String },
|
|
130
|
-
execute: ({ element, pattern }) => Stream.callback((queue) => Effect.gen(function* () {
|
|
131
|
-
const field = asField(element);
|
|
132
|
-
if (field === null) return;
|
|
133
|
-
const onInput = () => {
|
|
134
|
-
const { masked, raw } = applyMask(field.value, pattern);
|
|
135
|
-
if (masked !== field.value) {
|
|
136
|
-
const caret = field.selectionStart ?? masked.length;
|
|
137
|
-
field.value = masked;
|
|
138
|
-
const at = Math.min(caret, masked.length);
|
|
139
|
-
try {
|
|
140
|
-
field.setSelectionRange?.(at, at);
|
|
141
|
-
} catch {}
|
|
142
|
-
}
|
|
143
|
-
Queue.offerUnsafe(queue, Input.make({
|
|
144
|
-
value: masked,
|
|
145
|
-
raw
|
|
146
|
-
}));
|
|
147
|
-
};
|
|
148
|
-
yield* Effect.acquireRelease(Effect.sync(() => {
|
|
149
|
-
field.addEventListener("input", onInput);
|
|
150
|
-
return field;
|
|
151
|
-
}), (current) => Effect.sync(() => current.removeEventListener("input", onInput)));
|
|
152
|
-
}))
|
|
153
|
-
});
|
|
154
|
-
// src/dom/keep-in-view.ts
|
|
155
|
-
/**
|
|
156
|
-
* Keeps what is marked in view as a Mount: whenever an element in the mounted
|
|
157
|
-
* one's subtree newly matches `selector`, such as the row just selected in a
|
|
158
|
-
* list, it is scrolled into view the least amount that shows it (`nearest`).
|
|
159
|
-
* The element keeps its identity and its focus: nothing is redrawn to move it.
|
|
160
|
-
*
|
|
161
|
-
* It watches with a `MutationObserver` for as long as it is mounted, which is as
|
|
162
|
-
* long as the list or canvas that can change what is marked.
|
|
163
|
-
*/
|
|
164
|
-
const KeepInView = Mount.defineStream("KeepInView", {
|
|
165
|
-
messages: [Schema.Never],
|
|
166
|
-
args: {
|
|
167
|
-
/** What is marked, as a selector within the element: `[aria-selected="true"]`. */
|
|
168
|
-
selector: Schema.String },
|
|
169
|
-
execute: ({ element, selector }) => Stream.callback(() => Effect.acquireRelease(Effect.sync(() => {
|
|
170
|
-
let marked = element.querySelector(selector);
|
|
171
|
-
const observer = new MutationObserver(() => {
|
|
172
|
-
const now = element.querySelector(selector);
|
|
173
|
-
if (now !== null && now !== marked && typeof now.scrollIntoView === "function") now.scrollIntoView({
|
|
174
|
-
block: "nearest",
|
|
175
|
-
inline: "nearest"
|
|
176
|
-
});
|
|
177
|
-
marked = now;
|
|
178
|
-
});
|
|
179
|
-
observer.observe(element, {
|
|
180
|
-
subtree: true,
|
|
181
|
-
childList: true,
|
|
182
|
-
attributes: true
|
|
183
|
-
});
|
|
184
|
-
return observer;
|
|
185
|
-
}), (observer) => Effect.sync(() => observer.disconnect())))
|
|
186
|
-
});
|
|
187
|
-
// src/dom/script-loader.ts
|
|
188
|
-
/**
|
|
189
|
-
* Script loading as a Command: appends a `src` script to the head unless one
|
|
190
|
-
* is already there. Idempotent by URL — concurrent placements collapse onto
|
|
191
|
-
* the first tag instead of fetching twice. Yields `Loaded` on success and
|
|
192
|
-
* `LoadFailed` otherwise (network error, no document), so `update` handles
|
|
193
|
-
* both outcomes as Messages.
|
|
194
|
-
*/
|
|
195
|
-
const ScriptMessage = defineMessageUnion({
|
|
196
|
-
Loaded: {},
|
|
197
|
-
LoadFailed: { message: Schema.String }
|
|
198
|
-
});
|
|
199
|
-
const failMessage$1 = (error) => error instanceof Error ? error.message : String(error);
|
|
200
|
-
const inflight = /* @__PURE__ */ new Map();
|
|
201
|
-
/** Loads a script by URL, once per URL. */
|
|
202
|
-
const loadScript = (src) => ({
|
|
203
|
-
name: "Script.load",
|
|
204
|
-
args: { src },
|
|
205
|
-
effect: Effect.matchEffect(Effect.tryPromise({
|
|
206
|
-
try: () => {
|
|
207
|
-
if (typeof document === "undefined") return Promise.reject(/* @__PURE__ */ new Error("script loading is unavailable"));
|
|
208
|
-
const running = inflight.get(src);
|
|
209
|
-
if (running !== void 0) return running;
|
|
210
|
-
if (Array.from(document.getElementsByTagName("script")).some((element) => element.getAttribute("src") === src)) return Promise.resolve();
|
|
211
|
-
const tracked = new Promise((resolve, reject) => {
|
|
212
|
-
const element = document.createElement("script");
|
|
213
|
-
element.src = src;
|
|
214
|
-
element.async = true;
|
|
215
|
-
element.onload = () => resolve();
|
|
216
|
-
element.onerror = () => {
|
|
217
|
-
element.remove();
|
|
218
|
-
reject(/* @__PURE__ */ new Error(`failed to load script: ${src}`));
|
|
219
|
-
};
|
|
220
|
-
document.head.appendChild(element);
|
|
221
|
-
}).then(() => {
|
|
222
|
-
inflight.delete(src);
|
|
223
|
-
}, (error) => {
|
|
224
|
-
inflight.delete(src);
|
|
225
|
-
throw error;
|
|
226
|
-
});
|
|
227
|
-
inflight.set(src, tracked);
|
|
228
|
-
return tracked;
|
|
229
|
-
},
|
|
230
|
-
catch: (error) => error
|
|
231
|
-
}), {
|
|
232
|
-
onFailure: (error) => Effect.succeed(ScriptMessage.LoadFailed({ message: failMessage$1(error) })),
|
|
233
|
-
onSuccess: () => Effect.succeed(ScriptMessage.Loaded())
|
|
234
|
-
})
|
|
235
|
-
});
|
|
236
|
-
// src/dom/share.ts
|
|
237
|
-
/**
|
|
238
|
-
* Web Share as a Command: runs in `update` beside any bundle, yields
|
|
239
|
-
* `Shared` on success. Dismissal is its own outcome, not a failure — the
|
|
240
|
-
* application tells a cancelled sheet apart from a broken one. Without a
|
|
241
|
-
* share API (desktop, insecure context) it yields `ShareFailed` instead of
|
|
242
|
-
* throwing, so `update` handles every outcome as a Message.
|
|
243
|
-
*/
|
|
244
|
-
const ShareData = Schema.Struct({
|
|
245
|
-
title: Schema.optional(Schema.String),
|
|
246
|
-
text: Schema.optional(Schema.String),
|
|
247
|
-
url: Schema.optional(Schema.String)
|
|
248
|
-
});
|
|
249
|
-
const ShareMessage = defineMessageUnion({
|
|
250
|
-
Shared: {},
|
|
251
|
-
Dismissed: {},
|
|
252
|
-
ShareFailed: { message: Schema.String }
|
|
253
|
-
});
|
|
254
|
-
const failMessage = (error) => error instanceof Error ? error.message : String(error);
|
|
255
|
-
const isDismissal = (error) => typeof error?.name === "string" && error.name === "AbortError";
|
|
256
|
-
/** Shares data through the platform sheet. */
|
|
257
|
-
const share = (data) => ({
|
|
258
|
-
name: "Share.share",
|
|
259
|
-
args: { data },
|
|
260
|
-
effect: typeof navigator !== "undefined" && typeof navigator.share === "function" ? Effect.matchEffect(Effect.tryPromise({
|
|
261
|
-
try: () => navigator.share({
|
|
262
|
-
...data.title !== void 0 ? { title: data.title } : {},
|
|
263
|
-
...data.text !== void 0 ? { text: data.text } : {},
|
|
264
|
-
...data.url !== void 0 ? { url: data.url } : {}
|
|
265
|
-
}),
|
|
266
|
-
catch: (error) => error
|
|
267
|
-
}), {
|
|
268
|
-
onFailure: (error) => Effect.succeed(isDismissal(error) ? ShareMessage.Dismissed() : ShareMessage.ShareFailed({ message: failMessage(error) })),
|
|
269
|
-
onSuccess: () => Effect.succeed(ShareMessage.Shared())
|
|
270
|
-
}) : Effect.succeed(ShareMessage.ShareFailed({ message: "share is unavailable" }))
|
|
271
|
-
});
|
|
272
|
-
// src/dom/measure.ts
|
|
273
|
-
/** The custom properties `Measure` writes for a target named `name`. */
|
|
274
|
-
const measured = (name) => ({
|
|
275
|
-
x: `--fk-${name}-x`,
|
|
276
|
-
y: `--fk-${name}-y`,
|
|
277
|
-
w: `--fk-${name}-w`,
|
|
278
|
-
h: `--fk-${name}-h`,
|
|
279
|
-
display: `--fk-${name}-display`,
|
|
280
|
-
/**
|
|
281
|
-
* `1` for the measure that finds the mark on another element than the
|
|
282
|
-
* last, `0` for any other (the layout moved or resized the same one, or
|
|
283
|
-
* it is the first found): an overlay that glides to a new mark scales its
|
|
284
|
-
* duration by it, so it keeps to its element as the layout settles.
|
|
285
|
-
*/
|
|
286
|
-
moving: `--fk-${name}-moving`
|
|
287
|
-
});
|
|
288
|
-
/**
|
|
289
|
-
* Measures marked elements as a Mount, for a view to draw something over them,
|
|
290
|
-
* such as an editor's selection outline, with no Message and no Model: where
|
|
291
|
-
* an element is, is presentation, known to the DOM and to no transition.
|
|
292
|
-
*
|
|
293
|
-
* For each named target, the first element in the mounted one's subtree that
|
|
294
|
-
* matches its selector is measured relative to the mounted element's scroll
|
|
295
|
-
* box, which is what an absolutely placed child of it is laid out in. The
|
|
296
|
-
* mounted element gets `--fk-<name>-x`, `-y`, `-w` and `-h` in pixels, and
|
|
297
|
-
* `--fk-<name>-display`: `block` while a target is found, `none` while none is,
|
|
298
|
-
* and `--fk-<name>-moving` (see `measured`).
|
|
299
|
-
*
|
|
300
|
-
* It measures again when the subtree changes (a selection moves) or the
|
|
301
|
-
* mounted element or a measured one changes size, in the frame the change is
|
|
302
|
-
* drawn in; and, at most once a frame, when the mounted element scrolls, the
|
|
303
|
-
* window resizes, an image or a font inside loads, and on every frame of a
|
|
304
|
-
* transition or an animation inside. What moves a target by any other way,
|
|
305
|
-
* such as a stylesheet added that shifts it without resizing it, is seen at
|
|
306
|
-
* the next of these.
|
|
307
|
-
*/
|
|
308
|
-
const Measure = Mount.defineStream("Measure", {
|
|
309
|
-
messages: [Schema.Never],
|
|
310
|
-
args: {
|
|
311
|
-
/** Each target by name, as a selector within the element: `{ selected: '[aria-selected="true"]' }`. */
|
|
312
|
-
targets: Schema.Record(Schema.String, Schema.String) },
|
|
313
|
-
execute: ({ element, targets }) => Stream.callback(() => Effect.acquireRelease(Effect.sync(() => {
|
|
314
|
-
const container = element;
|
|
315
|
-
const names = Object.keys(targets);
|
|
316
|
-
let watched = [];
|
|
317
|
-
const last = /* @__PURE__ */ new Map();
|
|
318
|
-
let frame;
|
|
319
|
-
let animating = false;
|
|
320
|
-
const measure = () => {
|
|
321
|
-
if (frame !== void 0) cancelAnimationFrame(frame);
|
|
322
|
-
frame = void 0;
|
|
323
|
-
const box = container.getBoundingClientRect();
|
|
324
|
-
const found = [];
|
|
325
|
-
for (const name of names) {
|
|
326
|
-
const property = measured(name);
|
|
327
|
-
const target = container.querySelector(targets[name]);
|
|
328
|
-
if (target === null) {
|
|
329
|
-
container.style.setProperty(property.display, "none");
|
|
330
|
-
continue;
|
|
331
|
-
}
|
|
332
|
-
found.push(target);
|
|
333
|
-
const previous = last.get(name);
|
|
334
|
-
last.set(name, target);
|
|
335
|
-
const rect = target.getBoundingClientRect();
|
|
336
|
-
const x = rect.left - box.left - container.clientLeft + container.scrollLeft;
|
|
337
|
-
const y = rect.top - box.top - container.clientTop + container.scrollTop;
|
|
338
|
-
container.style.setProperty(property.x, `${x}px`);
|
|
339
|
-
container.style.setProperty(property.y, `${y}px`);
|
|
340
|
-
container.style.setProperty(property.w, `${rect.width}px`);
|
|
341
|
-
container.style.setProperty(property.h, `${rect.height}px`);
|
|
342
|
-
container.style.setProperty(property.display, "block");
|
|
343
|
-
container.style.setProperty(property.moving, previous === void 0 || previous === target ? "0" : "1");
|
|
344
|
-
}
|
|
345
|
-
if (found.length !== watched.length || found.some((each, at) => each !== watched[at])) {
|
|
346
|
-
for (const each of watched) sizes.unobserve(each);
|
|
347
|
-
for (const each of found) sizes.observe(each);
|
|
348
|
-
watched = found;
|
|
349
|
-
}
|
|
350
|
-
if (animating) {
|
|
351
|
-
animating = container.getAnimations({ subtree: true }).some((animation) => animation.playState === "running");
|
|
352
|
-
if (animating) soon();
|
|
353
|
-
}
|
|
354
|
-
};
|
|
355
|
-
const soon = () => {
|
|
356
|
-
if (frame === void 0) frame = requestAnimationFrame(measure);
|
|
357
|
-
};
|
|
358
|
-
const moving = () => {
|
|
359
|
-
animating = true;
|
|
360
|
-
soon();
|
|
361
|
-
};
|
|
362
|
-
const changes = new MutationObserver(measure);
|
|
363
|
-
const sizes = new ResizeObserver(measure);
|
|
364
|
-
document.fonts.addEventListener("loadingdone", soon);
|
|
365
|
-
changes.observe(container, {
|
|
366
|
-
subtree: true,
|
|
367
|
-
childList: true,
|
|
368
|
-
attributes: true
|
|
369
|
-
});
|
|
370
|
-
sizes.observe(container);
|
|
371
|
-
container.addEventListener("scroll", soon, { passive: true });
|
|
372
|
-
window.addEventListener("resize", soon);
|
|
373
|
-
container.addEventListener("load", soon, { capture: true });
|
|
374
|
-
container.addEventListener("transitionrun", moving);
|
|
375
|
-
container.addEventListener("animationstart", moving);
|
|
376
|
-
measure();
|
|
377
|
-
return () => {
|
|
378
|
-
if (frame !== void 0) cancelAnimationFrame(frame);
|
|
379
|
-
changes.disconnect();
|
|
380
|
-
sizes.disconnect();
|
|
381
|
-
container.removeEventListener("scroll", soon);
|
|
382
|
-
window.removeEventListener("resize", soon);
|
|
383
|
-
container.removeEventListener("load", soon, { capture: true });
|
|
384
|
-
document.fonts.removeEventListener("loadingdone", soon);
|
|
385
|
-
container.removeEventListener("transitionrun", moving);
|
|
386
|
-
container.removeEventListener("animationstart", moving);
|
|
387
|
-
};
|
|
388
|
-
}), (stop) => Effect.sync(stop)))
|
|
389
|
-
});
|
|
390
|
-
// src/dom/scroll.ts
|
|
391
|
-
/**
|
|
392
|
-
* Where the window is scrolled, across an application's own navigations, as
|
|
393
|
-
* a stream. Left to itself, a browser keeps the scroll of the entry it
|
|
394
|
-
* leaves when a link pushes a new one, and on Back restores the old offset
|
|
395
|
-
* before the application has drawn the entry it returns to, so the offset is
|
|
396
|
-
* clamped to a page still loading. Here a pushed entry starts at the top,
|
|
397
|
-
* and Back, Forward or a reload return where that entry was, once the page
|
|
398
|
-
* is tall enough to hold it.
|
|
399
|
-
*
|
|
400
|
-
* Three rules, each found the slow way:
|
|
401
|
-
*
|
|
402
|
-
* 1. The offset is taken when the reader acts. The next screen is drawn
|
|
403
|
-
* before a Navigate Command pushes the address, so by the time the URL
|
|
404
|
-
* changes the window is already clamped to the new, shorter page. The
|
|
405
|
-
* scroll is recorded at the reader's click or key (capture phase), and at
|
|
406
|
-
* the start of Back and Forward, which begin in the browser before
|
|
407
|
-
* anything is drawn.
|
|
408
|
-
* 2. A restore holds its place while the next screen settles. A restore made
|
|
409
|
-
* when the entry changes is undone by the loading state drawn right after
|
|
410
|
-
* it, so the target is held on each frame for a moment, until the reader
|
|
411
|
-
* scrolls, touches or types, or another navigation starts.
|
|
412
|
-
* 3. Entries are keyed by the Navigation API's entry key, which a reload and
|
|
413
|
-
* a full navigation keep; offsets rest in `sessionStorage`, so Back into
|
|
414
|
-
* another document restores too. Where the browser has no Navigation API
|
|
415
|
-
* the stream attaches nothing and leaves the browser's own behaviour
|
|
416
|
-
* alone.
|
|
417
|
-
*
|
|
418
|
-
* Lift with `Subscription.persistentEntry`; the stream sends no Messages. Only
|
|
419
|
-
* the window scrolls: a nested container is the route graph's to know, when
|
|
420
|
-
* `Site.transition` arrives.
|
|
421
|
-
*/
|
|
422
|
-
const navigationTypeOf = (event) => "navigationType" in event ? Option.some(event.navigationType) : Option.none();
|
|
423
|
-
const readSaved = (storageKey) => {
|
|
424
|
-
try {
|
|
425
|
-
const stored = JSON.parse(sessionStorage.getItem(storageKey) ?? "[]");
|
|
426
|
-
return new Map(Array.isArray(stored) ? stored.filter((pair) => Array.isArray(pair) && typeof pair[0] === "string" && typeof pair[1] === "number") : []);
|
|
427
|
-
} catch {
|
|
428
|
-
return /* @__PURE__ */ new Map();
|
|
429
|
-
}
|
|
430
|
-
};
|
|
431
|
-
/** Starts keeping the scroll; the release undoes everything it installed. */
|
|
432
|
-
const attach = (storageKey, kept, patience) => {
|
|
433
|
-
const navigation = window.navigation;
|
|
434
|
-
if (navigation === void 0) return () => {};
|
|
435
|
-
const restoration = window.history.scrollRestoration;
|
|
436
|
-
window.history.scrollRestoration = "manual";
|
|
437
|
-
const saved = readSaved(storageKey);
|
|
438
|
-
const detaches = [];
|
|
439
|
-
const on = (target, type, listener, capture) => {
|
|
440
|
-
target.addEventListener(type, listener, capture);
|
|
441
|
-
detaches.push(() => target.removeEventListener(type, listener, capture));
|
|
442
|
-
};
|
|
443
|
-
const keyOf = () => Option.fromNullOr(navigation.currentEntry).pipe(Option.map((entry) => entry.key));
|
|
444
|
-
/** Where the current entry was left, if it has been. */
|
|
445
|
-
const savedHere = () => Option.flatMap(keyOf(), (key) => Option.fromUndefinedOr(saved.get(key)));
|
|
446
|
-
const remember = () => {
|
|
447
|
-
const key = keyOf();
|
|
448
|
-
if (Option.isNone(key)) return;
|
|
449
|
-
saved.delete(key.value);
|
|
450
|
-
saved.set(key.value, window.scrollY);
|
|
451
|
-
for (const old of saved.keys()) {
|
|
452
|
-
if (saved.size <= kept) break;
|
|
453
|
-
saved.delete(old);
|
|
454
|
-
}
|
|
455
|
-
};
|
|
456
|
-
let settling = new AbortController();
|
|
457
|
-
/**
|
|
458
|
-
* Holds the window at `top` while the next screen settles, whenever the page
|
|
459
|
-
* can hold it, until the reader scrolls, touches or types, or another
|
|
460
|
-
* navigation starts.
|
|
461
|
-
*/
|
|
462
|
-
const settle = (top) => {
|
|
463
|
-
settling.abort();
|
|
464
|
-
settling = new AbortController();
|
|
465
|
-
const { signal } = settling;
|
|
466
|
-
for (const input of [
|
|
467
|
-
"wheel",
|
|
468
|
-
"touchstart",
|
|
469
|
-
"keydown",
|
|
470
|
-
"pointerdown"
|
|
471
|
-
]) window.addEventListener(input, () => settling.abort(), {
|
|
472
|
-
passive: true,
|
|
473
|
-
signal
|
|
474
|
-
});
|
|
475
|
-
const until = performance.now() + patience;
|
|
476
|
-
const step = () => {
|
|
477
|
-
if (signal.aborted) return;
|
|
478
|
-
if (document.documentElement.scrollHeight - window.innerHeight >= top && Math.round(window.scrollY) !== top) window.scrollTo({
|
|
479
|
-
top,
|
|
480
|
-
behavior: "instant"
|
|
481
|
-
});
|
|
482
|
-
if (performance.now() < until) requestAnimationFrame(step);
|
|
483
|
-
else settling.abort();
|
|
484
|
-
};
|
|
485
|
-
step();
|
|
486
|
-
};
|
|
487
|
-
const acted = () => remember();
|
|
488
|
-
for (const input of ["click", "keydown"]) on(window, input, acted, true);
|
|
489
|
-
const traversing = (event) => {
|
|
490
|
-
if (Option.contains(navigationTypeOf(event), "traverse")) remember();
|
|
491
|
-
};
|
|
492
|
-
on(navigation, "navigate", traversing);
|
|
493
|
-
const changed = (event) => {
|
|
494
|
-
const type = navigationTypeOf(event);
|
|
495
|
-
if (Option.contains(type, "push")) settle(0);
|
|
496
|
-
else if (Option.contains(type, "traverse")) settle(Option.getOrElse(savedHere(), () => 0));
|
|
497
|
-
};
|
|
498
|
-
on(navigation, "currententrychange", changed);
|
|
499
|
-
const hidden = () => {
|
|
500
|
-
remember();
|
|
501
|
-
try {
|
|
502
|
-
sessionStorage.setItem(storageKey, JSON.stringify([...saved]));
|
|
503
|
-
} catch {}
|
|
504
|
-
};
|
|
505
|
-
on(window, "pagehide", hidden);
|
|
506
|
-
const here = savedHere();
|
|
507
|
-
if (Option.isSome(here)) settle(here.value);
|
|
508
|
-
return () => {
|
|
509
|
-
settling.abort();
|
|
510
|
-
for (const detach of detaches) detach();
|
|
511
|
-
window.history.scrollRestoration = restoration;
|
|
512
|
-
};
|
|
513
|
-
};
|
|
514
|
-
/**
|
|
515
|
-
* Keeps the window's scroll across same-document navigations: a pushed entry
|
|
516
|
-
* starts at the top, and Back, Forward or a reload return where that entry
|
|
517
|
-
* was. Without a window the stream is empty instead of throwing. Lift with
|
|
518
|
-
* `Subscription.persistentEntry`; the stream sends no Messages.
|
|
519
|
-
*/
|
|
520
|
-
const keepScroll = (options = {}) => {
|
|
521
|
-
if (typeof window === "undefined") return Stream.empty;
|
|
522
|
-
const storageKey = options.storageKey ?? "foldkit:scroll";
|
|
523
|
-
const kept = options.kept ?? 50;
|
|
524
|
-
const patience = options.patience ?? 2e3;
|
|
525
|
-
return Stream.callback(() => Effect.acquireRelease(Effect.sync(() => attach(storageKey, kept, patience)), (detach) => Effect.sync(detach)));
|
|
526
|
-
};
|
|
527
|
-
// src/dom/pointed-links.ts
|
|
528
|
-
/**
|
|
529
|
-
* The address of the link a reader points at or tabs to, on the page's own
|
|
530
|
-
* origin: where they may go next, for a `Data.preload` before they go. Each
|
|
531
|
-
* link once while they stay on it, since crossing its text sends one event
|
|
532
|
-
* per element inside it. Without a document the stream is empty. Lift with
|
|
533
|
-
* `Subscription.persistentEntry`, mapping each address to a Message.
|
|
534
|
-
*/
|
|
535
|
-
const pointedLinks = () => {
|
|
536
|
-
if (typeof document === "undefined") return Stream.empty;
|
|
537
|
-
const linkOf = (event) => {
|
|
538
|
-
const link = event.target instanceof Element ? event.target.closest("a[href]") : null;
|
|
539
|
-
return link instanceof HTMLAnchorElement && link.origin === window.location.origin ? fromString(link.href) : Option.none();
|
|
540
|
-
};
|
|
541
|
-
return Stream.merge(Dom.streamFromEventFilterMap({
|
|
542
|
-
target: document,
|
|
543
|
-
type: "pointerover",
|
|
544
|
-
filterMapEvent: linkOf
|
|
545
|
-
}), Dom.streamFromEventFilterMap({
|
|
546
|
-
target: document,
|
|
547
|
-
type: "focusin",
|
|
548
|
-
filterMapEvent: linkOf
|
|
549
|
-
})).pipe(Stream.changesWith((a, b) => toString(a) === toString(b)));
|
|
550
|
-
};
|
|
551
|
-
// src/dom/fluid-hover.ts
|
|
552
|
-
/** The custom properties `FluidHover` writes on its container for a highlight named `name`. */
|
|
553
|
-
const fluidHovered = (name) => ({
|
|
554
|
-
x: `--fk-${name}-x`,
|
|
555
|
-
y: `--fk-${name}-y`,
|
|
556
|
-
w: `--fk-${name}-w`,
|
|
557
|
-
h: `--fk-${name}-h`,
|
|
558
|
-
/** `1` while an item is highlighted, `0` once the pointer and focus have left. */
|
|
559
|
-
shown: `--fk-${name}-shown`,
|
|
560
|
-
/**
|
|
561
|
-
* `0` for the frame the highlight appears in, then `1`: a highlight's
|
|
562
|
-
* movement scales its duration by it, so it appears on its item rather
|
|
563
|
-
* than sliding in from where it last was.
|
|
564
|
-
*/
|
|
565
|
-
moving: `--fk-${name}-moving`
|
|
566
|
-
});
|
|
567
|
-
/**
|
|
568
|
-
* The attribute `FluidHover` sets on its container, to the highlight's name,
|
|
569
|
-
* while it runs: a stylist draws the highlight, and drops each item's own
|
|
570
|
-
* hover, only under it.
|
|
571
|
-
*/
|
|
572
|
-
const FLUID_HOVER_ATTRIBUTE = "data-fluid-hover";
|
|
573
|
-
/** The attribute that names, inside an item, the control a press in a gap reaches. */
|
|
574
|
-
const FLUID_PRESS_ATTRIBUTE = "data-fluid-press";
|
|
575
|
-
/** The attribute on the item the highlight is shown on, for what CSS draws beside it. */
|
|
576
|
-
const FLUID_LIT_ATTRIBUTE = "data-fluid-lit";
|
|
577
|
-
/**
|
|
578
|
-
* The attribute `FluidHover` sets on its container, to the highlight's name,
|
|
579
|
-
* while the item that highlight is on is held. A stylist draws the press on
|
|
580
|
-
* the highlight (`data-fluid-held`) rather than on the item, whose own press
|
|
581
|
-
* is hidden under it; a press in a gap marks it too where `gapClick` sends
|
|
582
|
-
* that press to the lit item.
|
|
583
|
-
*/
|
|
584
|
-
const FLUID_HELD_ATTRIBUTE = "data-fluid-held";
|
|
585
|
-
const Axis = Schema.Literals([
|
|
586
|
-
"x",
|
|
587
|
-
"y",
|
|
588
|
-
"xy"
|
|
589
|
-
]);
|
|
590
|
-
/** How far a point is from a rectangle along each axis: zero inside it. */
|
|
591
|
-
const gap = (low, high, at) => Math.max(low - at, 0, at - high);
|
|
592
|
-
const away = {
|
|
593
|
-
x: (dx, dy) => dx * 1e6 + dy,
|
|
594
|
-
y: (dx, dy) => dy * 1e6 + dx,
|
|
595
|
-
xy: Math.hypot
|
|
596
|
-
};
|
|
597
|
-
const distance = (rect, x, y, axis) => away[axis](gap(rect.left, rect.right, x), gap(rect.top, rect.bottom, y));
|
|
598
|
-
const isDisabled = (item) => item.matches("[aria-disabled=\"true\"], [data-disabled]:not([data-disabled=\"false\"]), :disabled");
|
|
599
|
-
/**
|
|
600
|
-
* One highlight that follows the pointer across a container's items, as a
|
|
601
|
-
* Mount, with no Message and no Model: which item the pointer is nearest is
|
|
602
|
-
* presentation, known to the DOM and to no transition.
|
|
603
|
-
*
|
|
604
|
-
* The item nearest the pointer is the one highlighted, so the pointer in a gap
|
|
605
|
-
* between two items still points at one, and the highlight moves from item to
|
|
606
|
-
* item instead of blinking off between them. On the `y` axis nearness is read
|
|
607
|
-
* vertically (a list), on `x` horizontally (a strip), on `xy` both (a grid). A
|
|
608
|
-
* disabled item (`aria-disabled="true"`, `data-disabled`, `:disabled`) is never
|
|
609
|
-
* highlighted. An item reached by the keyboard (`:focus-visible`) is
|
|
610
|
-
* highlighted too, and with `focused`, the item that selector finds from a
|
|
611
|
-
* focused element that is no item (a tree's row, from its focused
|
|
612
|
-
* `treeitem`, which also holds the rows beneath it); a touch highlights
|
|
613
|
-
* nothing, since there is no pointer to
|
|
614
|
-
* follow before the press.
|
|
615
|
-
*
|
|
616
|
-
* The container gets `--fk-<name>-x`, `-y`, `-w` and `-h` in pixels, relative
|
|
617
|
-
* to its scroll box like `Measure`'s, and `-shown` and `-moving` (see
|
|
618
|
-
* `fluidHovered`); a view draws the highlight as an absolutely placed child
|
|
619
|
-
* that reads them. With `gapClick`, a click in a gap presses the highlighted
|
|
620
|
-
* item: its descendant marked `data-fluid-press`, or the item itself; with
|
|
621
|
-
* `gapReach` too, only a click within that many pixels of it, as a grid of
|
|
622
|
-
* cards with wide gutters wants (Fluid Functionalism's uses 16). A popup
|
|
623
|
-
* measured before it has a layout box keeps its last complete place, and
|
|
624
|
-
* tries again for three frames, rather than drawing the highlight at zero.
|
|
625
|
-
* The item the highlight is shown on carries `data-fluid-lit`, so a style
|
|
626
|
-
* can change what sits beside it (a table hides the lines around the lit
|
|
627
|
-
* row); its container carries `data-fluid-held` while that item is pressed.
|
|
628
|
-
*
|
|
629
|
-
* `follows` names the item the highlight sits on while the pointer is not
|
|
630
|
-
* moving it: a menu marks the row its keys reach (`[data-active]`), and the
|
|
631
|
-
* highlight goes there whenever that mark moves, so the keys and the pointer
|
|
632
|
-
* light the same one. `from` names the item a fresh highlight grows out of,
|
|
633
|
-
* as a tab's hover leaves the chosen tab. A highlight always fades where it
|
|
634
|
-
* is: once the pointer leaves, nothing should move. It stays only for an item
|
|
635
|
-
* the keyboard reached (`:focus-visible`), not one a click focused.
|
|
636
|
-
*/
|
|
637
|
-
const FluidHover = Mount.defineStream("FluidHover", {
|
|
638
|
-
messages: [Schema.Never],
|
|
639
|
-
args: {
|
|
640
|
-
/** The highlight's name, which names the custom properties. */
|
|
641
|
-
name: Schema.String,
|
|
642
|
-
/** The selector of an item within the container. */
|
|
643
|
-
item: Schema.String,
|
|
644
|
-
axis: Axis,
|
|
645
|
-
gapClick: Schema.Boolean,
|
|
646
|
-
/** How far from the highlighted item, in pixels, a click in a gap still presses it. */
|
|
647
|
-
gapReach: Schema.optional(Schema.Number),
|
|
648
|
-
/** The selector of the item the highlight sits on while the pointer is not moving it. */
|
|
649
|
-
follows: Schema.optional(Schema.String),
|
|
650
|
-
/** The selector of the item a fresh highlight grows out of. */
|
|
651
|
-
from: Schema.optional(Schema.String),
|
|
652
|
-
/** The selector, run from a focused element outside any item, of the item it lights. */
|
|
653
|
-
focused: Schema.optional(Schema.String)
|
|
654
|
-
},
|
|
655
|
-
execute: ({ element, name, item: selector, axis, gapClick, gapReach, follows, from, focused }) => Stream.callback(() => Effect.acquireRelease(Effect.sync(() => {
|
|
656
|
-
const container = element;
|
|
657
|
-
const property = fluidHovered(name);
|
|
658
|
-
let active = null;
|
|
659
|
-
let followed = null;
|
|
660
|
-
let pointer = null;
|
|
661
|
-
let frame;
|
|
662
|
-
const origin = () => from === void 0 ? null : container.querySelector(from);
|
|
663
|
-
let retries = 0;
|
|
664
|
-
const place = (at = active) => {
|
|
665
|
-
if (at === null) return;
|
|
666
|
-
const box = container.getBoundingClientRect();
|
|
667
|
-
const rect = at.getBoundingClientRect();
|
|
668
|
-
if (rect.width === 0 && rect.height === 0) {
|
|
669
|
-
if (retries < 3) {
|
|
670
|
-
retries += 1;
|
|
671
|
-
requestAnimationFrame(() => place(at));
|
|
672
|
-
}
|
|
673
|
-
return;
|
|
674
|
-
}
|
|
675
|
-
retries = 0;
|
|
676
|
-
const x = rect.left - box.left - container.clientLeft + container.scrollLeft;
|
|
677
|
-
const y = rect.top - box.top - container.clientTop + container.scrollTop;
|
|
678
|
-
container.style.setProperty(property.x, `${x}px`);
|
|
679
|
-
container.style.setProperty(property.y, `${y}px`);
|
|
680
|
-
container.style.setProperty(property.w, `${rect.width}px`);
|
|
681
|
-
container.style.setProperty(property.h, `${rect.height}px`);
|
|
682
|
-
};
|
|
683
|
-
/** Marks `item` as the lit one, and nothing else. */
|
|
684
|
-
const light = (item) => {
|
|
685
|
-
container.querySelectorAll(`[${FLUID_LIT_ATTRIBUTE}]`).forEach((each) => each !== item && each.removeAttribute("data-fluid-lit"));
|
|
686
|
-
item?.setAttribute(FLUID_LIT_ATTRIBUTE, "");
|
|
687
|
-
};
|
|
688
|
-
const show = (next) => {
|
|
689
|
-
const appearing = container.style.getPropertyValue(property.shown) !== "1";
|
|
690
|
-
active = next;
|
|
691
|
-
light(next);
|
|
692
|
-
const grows = appearing ? origin() : null;
|
|
693
|
-
if (appearing) container.style.setProperty(property.moving, "0");
|
|
694
|
-
if (grows === null) {
|
|
695
|
-
place();
|
|
696
|
-
container.style.setProperty(property.shown, "1");
|
|
697
|
-
} else {
|
|
698
|
-
place(grows);
|
|
699
|
-
requestAnimationFrame(() => {
|
|
700
|
-
if (active !== next) return;
|
|
701
|
-
place();
|
|
702
|
-
container.style.setProperty(property.shown, "1");
|
|
703
|
-
});
|
|
704
|
-
}
|
|
705
|
-
if (appearing) requestAnimationFrame(() => container.style.setProperty(property.moving, "1"));
|
|
706
|
-
};
|
|
707
|
-
const hide = () => {
|
|
708
|
-
container.style.setProperty(property.shown, "0");
|
|
709
|
-
container.removeAttribute(FLUID_HELD_ATTRIBUTE);
|
|
710
|
-
light(null);
|
|
711
|
-
};
|
|
712
|
-
/** Whether the keyboard has an item focused, which the highlight then stays on. */
|
|
713
|
-
const keyed = () => {
|
|
714
|
-
const focused = document.activeElement;
|
|
715
|
-
return focused !== null && container.contains(focused) && focused.matches(":focus-visible");
|
|
716
|
-
};
|
|
717
|
-
const nearest = (x, y) => {
|
|
718
|
-
let best = null;
|
|
719
|
-
let bestDistance = Infinity;
|
|
720
|
-
for (const each of Array.from(container.querySelectorAll(selector))) {
|
|
721
|
-
if (isDisabled(each)) continue;
|
|
722
|
-
const far = distance(each.getBoundingClientRect(), x, y, axis);
|
|
723
|
-
if (far < bestDistance) {
|
|
724
|
-
best = each;
|
|
725
|
-
bestDistance = far;
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
return best;
|
|
729
|
-
};
|
|
730
|
-
const follow = () => {
|
|
731
|
-
frame = void 0;
|
|
732
|
-
if (pointer === null) return;
|
|
733
|
-
const next = nearest(pointer.x, pointer.y);
|
|
734
|
-
if (next === null) hide();
|
|
735
|
-
else if (next !== active || container.style.getPropertyValue(property.shown) !== "1") show(next);
|
|
736
|
-
};
|
|
737
|
-
const move = (event) => {
|
|
738
|
-
if (event.pointerType === "touch") return;
|
|
739
|
-
pointer = {
|
|
740
|
-
x: event.clientX,
|
|
741
|
-
y: event.clientY
|
|
742
|
-
};
|
|
743
|
-
if (frame === void 0) frame = requestAnimationFrame(follow);
|
|
744
|
-
};
|
|
745
|
-
const leave = () => {
|
|
746
|
-
pointer = null;
|
|
747
|
-
release();
|
|
748
|
-
if (!keyed()) hide();
|
|
749
|
-
};
|
|
750
|
-
const focus = (event) => {
|
|
751
|
-
if (!(event.target instanceof Element) || !event.target.matches(":focus-visible")) return;
|
|
752
|
-
const owner = event.target.closest(selector) ?? (focused === void 0 ? null : event.target.querySelector(focused));
|
|
753
|
-
if (owner !== null && container.contains(owner) && !isDisabled(owner)) show(owner);
|
|
754
|
-
};
|
|
755
|
-
const blur = (event) => {
|
|
756
|
-
const to = event.relatedTarget;
|
|
757
|
-
if (pointer === null && !(to instanceof Node && container.contains(to))) hide();
|
|
758
|
-
};
|
|
759
|
-
const reachOf = (item, event) => gapReach === void 0 || distance(item.getBoundingClientRect(), event.clientX, event.clientY, "xy") <= gapReach;
|
|
760
|
-
/** Whether a click in a gap presses the lit item, within `gapReach` of it. */
|
|
761
|
-
const reaches = (item, event) => gapClick && reachOf(item, event);
|
|
762
|
-
const click = (event) => {
|
|
763
|
-
if (active === null) return;
|
|
764
|
-
if (container.style.getPropertyValue(property.shown) !== "1") return;
|
|
765
|
-
const target = event.target;
|
|
766
|
-
if (!(target instanceof Element) || target.closest(selector) !== null) return;
|
|
767
|
-
if (!reaches(active, event)) return;
|
|
768
|
-
const press = active.querySelector(`[data-fluid-press]`) ?? active;
|
|
769
|
-
if (press instanceof HTMLElement) press.click();
|
|
770
|
-
};
|
|
771
|
-
const soon = () => {
|
|
772
|
-
if (active !== null) requestAnimationFrame(() => place());
|
|
773
|
-
};
|
|
774
|
-
/**
|
|
775
|
-
* Marks the container as held where the press is the lit item's: the
|
|
776
|
-
* item itself, or a gap a click there reaches through (`gapClick`). A
|
|
777
|
-
* press on another item is that item's, once the pointer has lit it.
|
|
778
|
-
*/
|
|
779
|
-
const press = (event) => {
|
|
780
|
-
if (event.button !== 0 || active === null) return;
|
|
781
|
-
if (container.style.getPropertyValue(property.shown) !== "1") return;
|
|
782
|
-
const target = event.target;
|
|
783
|
-
if (!(target instanceof Element)) return;
|
|
784
|
-
const inItem = target.closest(selector) !== null;
|
|
785
|
-
if (inItem && !active.contains(target)) return;
|
|
786
|
-
if (!inItem && !reaches(active, event)) return;
|
|
787
|
-
container.setAttribute(FLUID_HELD_ATTRIBUTE, name);
|
|
788
|
-
};
|
|
789
|
-
const release = () => container.removeAttribute(FLUID_HELD_ATTRIBUTE);
|
|
790
|
-
/** The marked item moved: the highlight goes with it, or fades if it is gone. */
|
|
791
|
-
const marked = () => {
|
|
792
|
-
if (follows === void 0) return;
|
|
793
|
-
const next = container.querySelector(follows);
|
|
794
|
-
if (next === followed) return;
|
|
795
|
-
followed = next;
|
|
796
|
-
if (next !== null && !isDisabled(next)) show(next);
|
|
797
|
-
else if (pointer === null && !keyed()) hide();
|
|
798
|
-
};
|
|
799
|
-
const sizes = typeof ResizeObserver === "undefined" ? void 0 : new ResizeObserver(soon);
|
|
800
|
-
const marks = follows === void 0 ? void 0 : new MutationObserver(marked);
|
|
801
|
-
sizes?.observe(container);
|
|
802
|
-
marks?.observe(container, {
|
|
803
|
-
subtree: true,
|
|
804
|
-
childList: true,
|
|
805
|
-
attributes: true
|
|
806
|
-
});
|
|
807
|
-
container.addEventListener("pointermove", move, { passive: true });
|
|
808
|
-
container.addEventListener("pointerdown", press);
|
|
809
|
-
container.addEventListener("pointerleave", leave);
|
|
810
|
-
window.addEventListener("pointerup", release);
|
|
811
|
-
window.addEventListener("pointercancel", release);
|
|
812
|
-
container.addEventListener("focusin", focus);
|
|
813
|
-
container.addEventListener("focusout", blur);
|
|
814
|
-
container.addEventListener("click", click);
|
|
815
|
-
container.addEventListener("scroll", soon, { passive: true });
|
|
816
|
-
window.addEventListener("resize", soon);
|
|
817
|
-
container.style.setProperty(property.shown, "0");
|
|
818
|
-
container.setAttribute(FLUID_HOVER_ATTRIBUTE, name);
|
|
819
|
-
marked();
|
|
820
|
-
return () => {
|
|
821
|
-
if (frame !== void 0) cancelAnimationFrame(frame);
|
|
822
|
-
sizes?.disconnect();
|
|
823
|
-
marks?.disconnect();
|
|
824
|
-
container.removeAttribute(FLUID_HOVER_ATTRIBUTE);
|
|
825
|
-
container.removeAttribute(FLUID_HELD_ATTRIBUTE);
|
|
826
|
-
light(null);
|
|
827
|
-
container.removeEventListener("pointermove", move);
|
|
828
|
-
container.removeEventListener("pointerdown", press);
|
|
829
|
-
container.removeEventListener("pointerleave", leave);
|
|
830
|
-
window.removeEventListener("pointerup", release);
|
|
831
|
-
window.removeEventListener("pointercancel", release);
|
|
832
|
-
container.removeEventListener("focusin", focus);
|
|
833
|
-
container.removeEventListener("focusout", blur);
|
|
834
|
-
container.removeEventListener("click", click);
|
|
835
|
-
container.removeEventListener("scroll", soon);
|
|
836
|
-
window.removeEventListener("resize", soon);
|
|
837
|
-
};
|
|
838
|
-
}), (stop) => Effect.sync(stop)))
|
|
839
|
-
});
|
|
840
|
-
// src/dom/keyboard-inset.ts
|
|
841
|
-
/**
|
|
842
|
-
* The custom property `KeyboardInset` writes on its element: how much of the layout
|
|
843
|
-
* viewport's bottom the on-screen keyboard (or anything else the visual viewport leaves
|
|
844
|
-
* out) covers, in pixels.
|
|
845
|
-
*/
|
|
846
|
-
const KEYBOARD_INSET = "--fk-keyboard-inset";
|
|
847
|
-
/**
|
|
848
|
-
* The part of the layout viewport's height below the visual viewport: what the on-screen
|
|
849
|
-
* keyboard covers. Rounded down, since a fraction of a pixel of zoom is no keyboard.
|
|
850
|
-
*/
|
|
851
|
-
const keyboardInset = (view) => view.visualViewport === null ? 0 : Math.max(0, Math.floor(view.innerHeight - view.visualViewport.height - view.visualViewport.offsetTop));
|
|
852
|
-
/**
|
|
853
|
-
* The on-screen keyboard's height as a Mount, with no Message and no Model: where it is
|
|
854
|
-
* is the browser's. iOS Safari, and Chrome on Android unless the page asks otherwise,
|
|
855
|
-
* leave the layout viewport as it is when the keyboard opens, so a panel fixed to the
|
|
856
|
-
* screen keeps its height and its bottom under the keys. This writes `KEYBOARD_INSET` on
|
|
857
|
-
* the element, from the visual viewport's size and scroll, for a style to pad or shrink by
|
|
858
|
-
* (`var(--fk-keyboard-inset, 0px)`), and removes it when the element goes. Where there is
|
|
859
|
-
* no visual viewport it writes nothing.
|
|
860
|
-
*/
|
|
861
|
-
const KeyboardInset = Mount.defineStream("KeyboardInset", {
|
|
862
|
-
messages: [Schema.Never],
|
|
863
|
-
args: {},
|
|
864
|
-
execute: ({ element }) => Stream.callback(() => Effect.acquireRelease(Effect.sync(() => {
|
|
865
|
-
const view = element.ownerDocument.defaultView;
|
|
866
|
-
const viewport = view?.visualViewport;
|
|
867
|
-
if (!(element instanceof HTMLElement) || view === null || view === void 0 || viewport === null || viewport === void 0) return () => {};
|
|
868
|
-
const target = element;
|
|
869
|
-
const measure = () => target.style.setProperty(KEYBOARD_INSET, `${keyboardInset(view)}px`);
|
|
870
|
-
measure();
|
|
871
|
-
viewport.addEventListener("resize", measure);
|
|
872
|
-
viewport.addEventListener("scroll", measure);
|
|
873
|
-
return () => {
|
|
874
|
-
viewport.removeEventListener("resize", measure);
|
|
875
|
-
viewport.removeEventListener("scroll", measure);
|
|
876
|
-
target.style.removeProperty(KEYBOARD_INSET);
|
|
877
|
-
};
|
|
878
|
-
}), (release) => Effect.sync(release)))
|
|
879
|
-
});
|
|
880
|
-
// src/dom/scroll-bars.ts
|
|
881
|
-
/**
|
|
882
|
-
* The attribute that marks a bar beside a scroller `ScrollBars` runs on, set
|
|
883
|
-
* to the axis it shows: `block` (the up-and-down bar) or `inline`.
|
|
884
|
-
*/
|
|
885
|
-
const SCROLL_BAR_ATTRIBUTE = "data-scroll-bar";
|
|
886
|
-
/**
|
|
887
|
-
* The attribute `ScrollBars` sets on its scroller while it draws the bars, so a
|
|
888
|
-
* style hides the native bar only then: with no Mount running (a coarse
|
|
889
|
-
* pointer, a page not yet hydrated) the browser's bar stays.
|
|
890
|
-
*/
|
|
891
|
-
const SCROLL_OVERLAID_ATTRIBUTE = "data-scroll-overlaid";
|
|
892
|
-
/**
|
|
893
|
-
* The custom properties `ScrollBars` writes on each bar, in pixels, for its
|
|
894
|
-
* thumb to read: how far along the bar the thumb starts, and how long it is.
|
|
895
|
-
* Physical: an inline bar's offset is from its left edge in either direction.
|
|
896
|
-
*/
|
|
897
|
-
const scrollThumb = {
|
|
898
|
-
offset: "--fk-scroll-thumb-offset",
|
|
899
|
-
size: "--fk-scroll-thumb-size"
|
|
900
|
-
};
|
|
901
|
-
/** The shortest a thumb is drawn, however long the content, so it stays a target. */
|
|
902
|
-
const SHORTEST = 20;
|
|
903
|
-
const FINE_POINTER = "(hover: hover) and (pointer: fine)";
|
|
904
|
-
/**
|
|
905
|
-
* An overlay scrollbar as a Mount, with no Message and no Model: where a
|
|
906
|
-
* scroller is scrolled is the browser's, and the bar only shows it.
|
|
907
|
-
*
|
|
908
|
-
* It runs on the scroller (or on an element holding it, named by `scroller`,
|
|
909
|
-
* when the scroller carries another Mount) and drives the bars drawn beside
|
|
910
|
-
* it: the scroller's parent's children marked `data-scroll-bar` (`block` or
|
|
911
|
-
* `inline`), which a style lays over the scroller's edge. Each bar gets `data-scrollable` while its axis has
|
|
912
|
-
* more to scroll, `data-shown` while the scroller scrolls or the pointer moves
|
|
913
|
-
* over it, until `idle` milliseconds pass with neither (or longer, while the
|
|
914
|
-
* pointer rests on a bar), and `data-dragging` while its thumb is dragged; and
|
|
915
|
-
* `--fk-scroll-thumb-offset` and `-size` (see `scrollThumb`). Pressing a bar
|
|
916
|
-
* off its thumb moves the thumb there, then drags it.
|
|
917
|
-
*
|
|
918
|
-
* It does nothing where the primary pointer is coarse or cannot hover, decided
|
|
919
|
-
* when it mounts: touch keeps the browser's bar and its physics. Otherwise the
|
|
920
|
-
* scroller gets `data-scroll-overlaid`, for a style to hide the native bar.
|
|
921
|
-
* How the bar looks, rests, widens and fades is the style's.
|
|
922
|
-
*/
|
|
923
|
-
const ScrollBars = Mount.defineStream("ScrollBars", {
|
|
924
|
-
messages: [Schema.Never],
|
|
925
|
-
args: {
|
|
926
|
-
/** How long, in milliseconds, the bars stay after the last scroll or move. Default 600. */
|
|
927
|
-
idle: Schema.optional(Schema.Number),
|
|
928
|
-
/**
|
|
929
|
-
* The scroller, as a selector within the element, when it cannot hold this
|
|
930
|
-
* Mount itself (another component's, with a Mount of its own); looked for
|
|
931
|
-
* once, when it mounts. Default: the element is the scroller.
|
|
932
|
-
*/
|
|
933
|
-
scroller: Schema.optional(Schema.String)
|
|
934
|
-
},
|
|
935
|
-
execute: ({ element, idle = 600, scroller: within }) => Stream.callback(() => Effect.acquireRelease(Effect.sync(() => {
|
|
936
|
-
if (typeof matchMedia !== "function" || !matchMedia(FINE_POINTER).matches) return () => {};
|
|
937
|
-
const found = within === void 0 ? element : element.querySelector(within);
|
|
938
|
-
if (!(found instanceof HTMLElement)) return () => {};
|
|
939
|
-
const scroller = found;
|
|
940
|
-
const area = scroller.parentElement;
|
|
941
|
-
if (area === null) return () => {};
|
|
942
|
-
const isBar = (child) => child instanceof HTMLElement && child.hasAttribute("data-scroll-bar");
|
|
943
|
-
/** Looked for at each use, so a redraw that replaced a bar is followed. */
|
|
944
|
-
const bars = () => Array.from(area.children).filter(isBar);
|
|
945
|
-
const axisOf = (bar) => bar.getAttribute("data-scroll-bar") === "inline" ? "inline" : "block";
|
|
946
|
-
/** The scroller along one axis, with the start measured from the top or the left. */
|
|
947
|
-
const extent = (axis) => {
|
|
948
|
-
if (axis === "block") return {
|
|
949
|
-
view: scroller.clientHeight,
|
|
950
|
-
content: scroller.scrollHeight,
|
|
951
|
-
start: scroller.scrollTop
|
|
952
|
-
};
|
|
953
|
-
const room = scroller.scrollWidth - scroller.clientWidth;
|
|
954
|
-
const rtl = getComputedStyle(scroller).direction === "rtl";
|
|
955
|
-
return {
|
|
956
|
-
view: scroller.clientWidth,
|
|
957
|
-
content: scroller.scrollWidth,
|
|
958
|
-
start: rtl ? room + scroller.scrollLeft : scroller.scrollLeft
|
|
959
|
-
};
|
|
960
|
-
};
|
|
961
|
-
const scrollTo = (axis, start) => {
|
|
962
|
-
if (axis === "block") {
|
|
963
|
-
scroller.scrollTop = start;
|
|
964
|
-
return;
|
|
965
|
-
}
|
|
966
|
-
const room = scroller.scrollWidth - scroller.clientWidth;
|
|
967
|
-
const rtl = getComputedStyle(scroller).direction === "rtl";
|
|
968
|
-
scroller.scrollLeft = rtl ? start - room : start;
|
|
969
|
-
};
|
|
970
|
-
const trackOf = (bar, axis) => axis === "block" ? bar.clientHeight : bar.clientWidth;
|
|
971
|
-
/** Where the thumb is along its bar, or nothing while the axis has nothing to scroll. */
|
|
972
|
-
const thumbOf = (bar, axis) => {
|
|
973
|
-
const { view, content, start } = extent(axis);
|
|
974
|
-
const track = trackOf(bar, axis);
|
|
975
|
-
if (content - view < 1 || track <= 0) return null;
|
|
976
|
-
const size = Math.min(track, Math.max(SHORTEST, track * view / content));
|
|
977
|
-
return {
|
|
978
|
-
track,
|
|
979
|
-
size,
|
|
980
|
-
offset: (track - size) * start / (content - view),
|
|
981
|
-
room: content - view
|
|
982
|
-
};
|
|
983
|
-
};
|
|
984
|
-
const set = (bar, name, value) => {
|
|
985
|
-
if (bar.style.getPropertyValue(name) !== value) bar.style.setProperty(name, value);
|
|
986
|
-
};
|
|
987
|
-
const mark = (bar, name, on) => {
|
|
988
|
-
if (bar.hasAttribute(name) !== on) bar.toggleAttribute(name, on);
|
|
989
|
-
};
|
|
990
|
-
let frame;
|
|
991
|
-
const update = () => {
|
|
992
|
-
if (frame !== void 0) cancelAnimationFrame(frame);
|
|
993
|
-
frame = void 0;
|
|
994
|
-
for (const bar of bars()) {
|
|
995
|
-
const axis = axisOf(bar);
|
|
996
|
-
const { view, content } = extent(axis);
|
|
997
|
-
mark(bar, "data-scrollable", content - view >= 1);
|
|
998
|
-
const thumb = thumbOf(bar, axis);
|
|
999
|
-
if (thumb === null) continue;
|
|
1000
|
-
set(bar, scrollThumb.offset, `${thumb.offset}px`);
|
|
1001
|
-
set(bar, scrollThumb.size, `${thumb.size}px`);
|
|
1002
|
-
}
|
|
1003
|
-
};
|
|
1004
|
-
const soon = () => {
|
|
1005
|
-
if (frame === void 0) frame = requestAnimationFrame(update);
|
|
1006
|
-
};
|
|
1007
|
-
let hiding;
|
|
1008
|
-
let resting = null;
|
|
1009
|
-
/** Ends the drag under way, if one is. */
|
|
1010
|
-
let dragging = null;
|
|
1011
|
-
const hide = () => {
|
|
1012
|
-
hiding = void 0;
|
|
1013
|
-
if (resting !== null || dragging !== null) return;
|
|
1014
|
-
for (const bar of bars()) mark(bar, "data-shown", false);
|
|
1015
|
-
};
|
|
1016
|
-
const show = () => {
|
|
1017
|
-
for (const bar of bars()) mark(bar, "data-shown", true);
|
|
1018
|
-
if (hiding !== void 0) clearTimeout(hiding);
|
|
1019
|
-
hiding = setTimeout(hide, idle);
|
|
1020
|
-
};
|
|
1021
|
-
const scrolled = () => {
|
|
1022
|
-
update();
|
|
1023
|
-
show();
|
|
1024
|
-
};
|
|
1025
|
-
const moved = (event) => {
|
|
1026
|
-
if (event.pointerType !== "touch") show();
|
|
1027
|
-
};
|
|
1028
|
-
const entered = (event) => {
|
|
1029
|
-
if (event.pointerType === "touch") return;
|
|
1030
|
-
area.addEventListener("pointermove", moved, { passive: true });
|
|
1031
|
-
show();
|
|
1032
|
-
};
|
|
1033
|
-
const left = () => {
|
|
1034
|
-
area.removeEventListener("pointermove", moved);
|
|
1035
|
-
resting = null;
|
|
1036
|
-
if (hiding === void 0) hiding = setTimeout(hide, idle);
|
|
1037
|
-
};
|
|
1038
|
-
const over = (event) => {
|
|
1039
|
-
const target = event.target;
|
|
1040
|
-
resting = target instanceof Element ? bars().find((bar) => bar.contains(target)) ?? null : null;
|
|
1041
|
-
};
|
|
1042
|
-
const pressed = (event) => {
|
|
1043
|
-
if (event.button !== 0 || event.pointerType === "touch" || dragging !== null) return;
|
|
1044
|
-
const target = event.target;
|
|
1045
|
-
if (!(target instanceof Element)) return;
|
|
1046
|
-
const bar = bars().find((each) => each.contains(target));
|
|
1047
|
-
if (bar === void 0) return;
|
|
1048
|
-
const axis = axisOf(bar);
|
|
1049
|
-
const thumb = thumbOf(bar, axis);
|
|
1050
|
-
if (thumb === null) return;
|
|
1051
|
-
event.preventDefault();
|
|
1052
|
-
const along = (at) => {
|
|
1053
|
-
const box = bar.getBoundingClientRect();
|
|
1054
|
-
return axis === "block" ? at.clientY - box.top - bar.clientTop : at.clientX - box.left - bar.clientLeft;
|
|
1055
|
-
};
|
|
1056
|
-
const at = along(event);
|
|
1057
|
-
const onThumb = at >= thumb.offset && at <= thumb.offset + thumb.size;
|
|
1058
|
-
const grab = onThumb ? at - thumb.offset : thumb.size / 2;
|
|
1059
|
-
const follow = (to) => {
|
|
1060
|
-
const current = thumbOf(bar, axis);
|
|
1061
|
-
if (current === null) return;
|
|
1062
|
-
const offset = Math.min(Math.max(along(to) - grab, 0), current.track - current.size);
|
|
1063
|
-
scrollTo(axis, offset / (current.track - current.size) * current.room);
|
|
1064
|
-
};
|
|
1065
|
-
const id = event.pointerId;
|
|
1066
|
-
const move = (to) => {
|
|
1067
|
-
if (to.pointerId === id) follow(to);
|
|
1068
|
-
};
|
|
1069
|
-
const end = (to) => {
|
|
1070
|
-
if (to.pointerId === id) stop();
|
|
1071
|
-
};
|
|
1072
|
-
const owner = bar.ownerDocument;
|
|
1073
|
-
const stop = () => {
|
|
1074
|
-
owner.removeEventListener("pointermove", move);
|
|
1075
|
-
owner.removeEventListener("pointerup", end);
|
|
1076
|
-
owner.removeEventListener("pointercancel", end);
|
|
1077
|
-
mark(bar, "data-dragging", false);
|
|
1078
|
-
dragging = null;
|
|
1079
|
-
show();
|
|
1080
|
-
};
|
|
1081
|
-
owner.addEventListener("pointermove", move);
|
|
1082
|
-
owner.addEventListener("pointerup", end);
|
|
1083
|
-
owner.addEventListener("pointercancel", end);
|
|
1084
|
-
mark(bar, "data-dragging", true);
|
|
1085
|
-
dragging = stop;
|
|
1086
|
-
show();
|
|
1087
|
-
if (!onThumb) follow(event);
|
|
1088
|
-
};
|
|
1089
|
-
const sizes = new ResizeObserver(soon);
|
|
1090
|
-
const changes = new MutationObserver((records) => {
|
|
1091
|
-
for (const record of records) {
|
|
1092
|
-
for (const node of Array.from(record.removedNodes)) if (node instanceof Element) sizes.unobserve(node);
|
|
1093
|
-
for (const node of Array.from(record.addedNodes)) if (node instanceof Element && (record.target === scroller || isBar(node))) sizes.observe(node);
|
|
1094
|
-
}
|
|
1095
|
-
soon();
|
|
1096
|
-
});
|
|
1097
|
-
sizes.observe(scroller);
|
|
1098
|
-
for (const child of Array.from(scroller.children)) sizes.observe(child);
|
|
1099
|
-
for (const bar of bars()) sizes.observe(bar);
|
|
1100
|
-
changes.observe(scroller, { childList: true });
|
|
1101
|
-
changes.observe(area, { childList: true });
|
|
1102
|
-
scroller.addEventListener("scroll", scrolled, { passive: true });
|
|
1103
|
-
area.addEventListener("pointerenter", entered);
|
|
1104
|
-
area.addEventListener("pointerleave", left);
|
|
1105
|
-
area.addEventListener("pointerover", over);
|
|
1106
|
-
area.addEventListener("pointerdown", pressed);
|
|
1107
|
-
scroller.setAttribute(SCROLL_OVERLAID_ATTRIBUTE, "");
|
|
1108
|
-
update();
|
|
1109
|
-
return () => {
|
|
1110
|
-
dragging?.();
|
|
1111
|
-
if (frame !== void 0) cancelAnimationFrame(frame);
|
|
1112
|
-
if (hiding !== void 0) clearTimeout(hiding);
|
|
1113
|
-
sizes.disconnect();
|
|
1114
|
-
changes.disconnect();
|
|
1115
|
-
scroller.removeEventListener("scroll", scrolled);
|
|
1116
|
-
area.removeEventListener("pointerenter", entered);
|
|
1117
|
-
area.removeEventListener("pointerleave", left);
|
|
1118
|
-
area.removeEventListener("pointerover", over);
|
|
1119
|
-
area.removeEventListener("pointerdown", pressed);
|
|
1120
|
-
area.removeEventListener("pointermove", moved);
|
|
1121
|
-
scroller.removeAttribute(SCROLL_OVERLAID_ATTRIBUTE);
|
|
1122
|
-
for (const bar of bars()) {
|
|
1123
|
-
for (const name of [
|
|
1124
|
-
"data-scrollable",
|
|
1125
|
-
"data-shown",
|
|
1126
|
-
"data-dragging"
|
|
1127
|
-
]) bar.removeAttribute(name);
|
|
1128
|
-
bar.style.removeProperty(scrollThumb.offset);
|
|
1129
|
-
bar.style.removeProperty(scrollThumb.size);
|
|
1130
|
-
}
|
|
1131
|
-
};
|
|
1132
|
-
}), (stop) => Effect.sync(stop)))
|
|
1133
|
-
});
|
|
1134
|
-
// src/dom/swipe.ts
|
|
1135
|
-
const SwipeStarted = Schema.TaggedStruct("SwipeStarted", {
|
|
1136
|
-
pointerId: Schema.Number,
|
|
1137
|
-
pointerType: Schema.String,
|
|
1138
|
-
/** The border box of what `measure` names (the element itself by default), as the swipe starts. */
|
|
1139
|
-
width: Schema.Number,
|
|
1140
|
-
height: Schema.Number
|
|
1141
|
-
});
|
|
1142
|
-
const Swiped = Schema.TaggedStruct("Swiped", {
|
|
1143
|
-
pointerId: Schema.Number,
|
|
1144
|
-
/** From where the pointer went down, in CSS pixels. */
|
|
1145
|
-
deltaX: Schema.Number,
|
|
1146
|
-
deltaY: Schema.Number
|
|
1147
|
-
});
|
|
1148
|
-
const SwipeEnded = Schema.TaggedStruct("SwipeEnded", {
|
|
1149
|
-
pointerId: Schema.Number,
|
|
1150
|
-
/** From where the pointer went down to where it came up, in CSS pixels. */
|
|
1151
|
-
deltaX: Schema.Number,
|
|
1152
|
-
deltaY: Schema.Number,
|
|
1153
|
-
/**
|
|
1154
|
-
* How fast the pointer was moving as it came up, in pixels a millisecond,
|
|
1155
|
-
* over the last `SWIPE_WINDOW` milliseconds: 0 when it rested there first.
|
|
1156
|
-
*/
|
|
1157
|
-
velocityX: Schema.Number,
|
|
1158
|
-
velocityY: Schema.Number,
|
|
1159
|
-
/** `false` when the pointer was cancelled or capture was lost. */
|
|
1160
|
-
completed: Schema.Boolean
|
|
1161
|
-
});
|
|
1162
|
-
/** How far back, in milliseconds, the release velocity looks. */
|
|
1163
|
-
const SWIPE_WINDOW = 100;
|
|
1164
|
-
/**
|
|
1165
|
-
* What a swipe never starts on when its element `scrolls`: a field whose own
|
|
1166
|
-
* drag selects text or moves a thumb, and anything marked `data-no-swipe`.
|
|
1167
|
-
*/
|
|
1168
|
-
const NO_SWIPE = "input, textarea, select, [contenteditable=\"\"], [contenteditable=\"true\"], [data-no-swipe]";
|
|
1169
|
-
/** Every element a Swipe is mounted on: a touch inside one is that one's, not an outer one's. */
|
|
1170
|
-
const owners = /* @__PURE__ */ new WeakSet();
|
|
1171
|
-
/**
|
|
1172
|
-
* The velocity of the samples within `SWIPE_WINDOW` of the last: the way
|
|
1173
|
-
* from the oldest of them to the last over the time between. A pointer that
|
|
1174
|
-
* came to rest before the last sample has no recent way to measure, so 0.
|
|
1175
|
-
*/
|
|
1176
|
-
const velocityOf = (samples) => {
|
|
1177
|
-
const last = samples.at(-1);
|
|
1178
|
-
if (last === void 0) return {
|
|
1179
|
-
x: 0,
|
|
1180
|
-
y: 0
|
|
1181
|
-
};
|
|
1182
|
-
const first = samples.find((sample) => last.at - sample.at <= 100) ?? last;
|
|
1183
|
-
const elapsed = last.at - first.at;
|
|
1184
|
-
return elapsed <= 0 ? {
|
|
1185
|
-
x: 0,
|
|
1186
|
-
y: 0
|
|
1187
|
-
} : {
|
|
1188
|
-
x: (last.x - first.x) / elapsed,
|
|
1189
|
-
y: (last.y - first.y) / elapsed
|
|
1190
|
-
};
|
|
1191
|
-
};
|
|
1192
|
-
/**
|
|
1193
|
-
* Whether anything from `target` up to `root` can still scroll along `axis`
|
|
1194
|
-
* the way a finger moving `along` (positive is down or right) pulls it: a
|
|
1195
|
-
* finger going down scrolls content toward its start.
|
|
1196
|
-
*/
|
|
1197
|
-
const canScroll = (target, root, axis, along) => {
|
|
1198
|
-
for (let at = target; at !== null; at = at.parentElement) {
|
|
1199
|
-
const overflow = getComputedStyle(at)[axis === "y" ? "overflowY" : "overflowX"];
|
|
1200
|
-
if (overflow === "auto" || overflow === "scroll") {
|
|
1201
|
-
const position = Math.abs(axis === "y" ? at.scrollTop : at.scrollLeft);
|
|
1202
|
-
const room = axis === "y" ? at.scrollHeight - at.clientHeight : at.scrollWidth - at.clientWidth;
|
|
1203
|
-
if (room > 1 && (along > 0 ? position > .5 : position < room - .5)) return true;
|
|
1204
|
-
}
|
|
1205
|
-
if (at === root) return false;
|
|
1206
|
-
}
|
|
1207
|
-
return false;
|
|
1208
|
-
};
|
|
1209
|
-
/**
|
|
1210
|
-
* `Move` with the speed of its release, for a gesture that a flick ends
|
|
1211
|
-
* (a sheet dragged to dismiss, a card swiped away): a primary-button pointer
|
|
1212
|
-
* down (or, given a `slop`, its first move past it) captures the pointer,
|
|
1213
|
-
* each move reports the delta from where it was pressed, and up reports the
|
|
1214
|
-
* last delta with the velocity over the last `SWIPE_WINDOW` milliseconds, by
|
|
1215
|
-
* the events' own time stamps. Cancel or lost capture ends it incomplete.
|
|
1216
|
-
* The start reports the size of what is moved, so a distance can be read as
|
|
1217
|
-
* a share of it. What a delta or a speed means is the parent's `update`.
|
|
1218
|
-
* Capture is released with the Mount.
|
|
1219
|
-
*
|
|
1220
|
-
* Given `scrolls`, the element holds content that scrolls (a sheet's panel),
|
|
1221
|
-
* and a touch is followed by touch events, whose move can still refuse the
|
|
1222
|
-
* browser's scroll once the touch is under way, where a pointer's cannot:
|
|
1223
|
-
* past the slop, a touch that runs along the axis and finds nothing under it
|
|
1224
|
-
* that can scroll further its way swipes, and the browser scrolls any other.
|
|
1225
|
-
* A touch inside an element with a Swipe of its own (a handle in the panel)
|
|
1226
|
-
* is that one's, and none starts on a field or on `data-no-swipe`
|
|
1227
|
-
* (`NO_SWIPE`).
|
|
1228
|
-
*/
|
|
1229
|
-
const Swipe = Mount.defineStream("Swipe", {
|
|
1230
|
-
messages: [
|
|
1231
|
-
SwipeStarted,
|
|
1232
|
-
Swiped,
|
|
1233
|
-
SwipeEnded
|
|
1234
|
-
],
|
|
1235
|
-
args: {
|
|
1236
|
-
/**
|
|
1237
|
-
* The nearest ancestor matching this selector is measured as the swipe
|
|
1238
|
-
* starts, for what the swipe moves (a sheet's panel, dragged by its
|
|
1239
|
-
* handle). Default: the element itself.
|
|
1240
|
-
*/
|
|
1241
|
-
measure: Schema.optional(Schema.String),
|
|
1242
|
-
/**
|
|
1243
|
-
* How far, in pixels, a press must move before it is a swipe. Until
|
|
1244
|
-
* then nothing is captured or reported, so a press that stays put is
|
|
1245
|
-
* still a click on whatever is under it (a tab inside a drag grip).
|
|
1246
|
-
* Default 0: the press itself starts the swipe; with `scrolls`, the
|
|
1247
|
-
* first move decides.
|
|
1248
|
-
*/
|
|
1249
|
-
slop: Schema.optional(Schema.Number),
|
|
1250
|
-
/** The axis the element's content scrolls along, which a touch yields to; see above. */
|
|
1251
|
-
scrolls: Schema.optional(Schema.Literals(["x", "y"])),
|
|
1252
|
-
/** Follows touches alone: a mouse or a pen is left to the page (and to a handle's own Swipe). */
|
|
1253
|
-
touchOnly: Schema.optional(Schema.Boolean)
|
|
1254
|
-
},
|
|
1255
|
-
execute: ({ element, measure, slop = 0, scrolls, touchOnly = false }) => Stream.callback((queue) => Effect.acquireRelease(Effect.sync(() => {
|
|
1256
|
-
const target = element;
|
|
1257
|
-
let active = null;
|
|
1258
|
-
const offer = (fact) => Queue.offerUnsafe(queue, fact);
|
|
1259
|
-
const sampleOf = (at, x = 0, y = 0) => ({
|
|
1260
|
-
at,
|
|
1261
|
-
x,
|
|
1262
|
-
y
|
|
1263
|
-
});
|
|
1264
|
-
const end = (pointerId, last, completed, captured) => {
|
|
1265
|
-
if (active === null || active.pointerId !== pointerId) return;
|
|
1266
|
-
const { samples, started } = active;
|
|
1267
|
-
active = null;
|
|
1268
|
-
if (!started) return;
|
|
1269
|
-
if (captured) try {
|
|
1270
|
-
target.releasePointerCapture?.(pointerId);
|
|
1271
|
-
} catch {}
|
|
1272
|
-
const final = completed ? last : samples.at(-1) ?? last;
|
|
1273
|
-
const all = completed ? [...samples, final] : samples;
|
|
1274
|
-
const start = all[0] ?? final;
|
|
1275
|
-
const velocity = completed ? velocityOf(all) : {
|
|
1276
|
-
x: 0,
|
|
1277
|
-
y: 0
|
|
1278
|
-
};
|
|
1279
|
-
offer(SwipeEnded.make({
|
|
1280
|
-
pointerId,
|
|
1281
|
-
deltaX: final.x - start.x,
|
|
1282
|
-
deltaY: final.y - start.y,
|
|
1283
|
-
velocityX: velocity.x,
|
|
1284
|
-
velocityY: velocity.y,
|
|
1285
|
-
completed
|
|
1286
|
-
}));
|
|
1287
|
-
};
|
|
1288
|
-
const begin = (pointer, capture) => {
|
|
1289
|
-
pointer.started = true;
|
|
1290
|
-
if (capture) try {
|
|
1291
|
-
target.setPointerCapture?.(pointer.pointerId);
|
|
1292
|
-
} catch {}
|
|
1293
|
-
const box = (measure === void 0 ? element : element.closest(measure) ?? element).getBoundingClientRect();
|
|
1294
|
-
offer(SwipeStarted.make({
|
|
1295
|
-
pointerId: pointer.pointerId,
|
|
1296
|
-
pointerType: pointer.pointerType,
|
|
1297
|
-
width: box.width,
|
|
1298
|
-
height: box.height
|
|
1299
|
-
}));
|
|
1300
|
-
};
|
|
1301
|
-
const moved = (pointer, sample) => {
|
|
1302
|
-
const start = pointer.samples[0] ?? sample;
|
|
1303
|
-
pointer.samples = [
|
|
1304
|
-
start,
|
|
1305
|
-
...pointer.samples.slice(1).filter((each) => sample.at - each.at <= 100),
|
|
1306
|
-
sample
|
|
1307
|
-
];
|
|
1308
|
-
offer(Swiped.make({
|
|
1309
|
-
pointerId: pointer.pointerId,
|
|
1310
|
-
deltaX: sample.x - start.x,
|
|
1311
|
-
deltaY: sample.y - start.y
|
|
1312
|
-
}));
|
|
1313
|
-
};
|
|
1314
|
-
const ownTouch = (from) => {
|
|
1315
|
-
if (!(from instanceof Element)) return false;
|
|
1316
|
-
const field = from.closest(NO_SWIPE);
|
|
1317
|
-
if (field !== null && element.contains(field)) return false;
|
|
1318
|
-
for (let at = from; at !== null && at !== element; at = at.parentElement) if (owners.has(at)) return false;
|
|
1319
|
-
return true;
|
|
1320
|
-
};
|
|
1321
|
-
const touchOf = (event, id) => Array.from(event.changedTouches).find((touch) => touch.identifier === id);
|
|
1322
|
-
let touched = null;
|
|
1323
|
-
const pointerListeners = [
|
|
1324
|
-
["pointerdown", (event) => {
|
|
1325
|
-
const pointer = event;
|
|
1326
|
-
const type = pointer.pointerType ?? "mouse";
|
|
1327
|
-
if (scrolls !== void 0 && type === "touch") return;
|
|
1328
|
-
if (touchOnly && type !== "touch") return;
|
|
1329
|
-
if ((pointer.button ?? 0) !== 0 || active !== null) return;
|
|
1330
|
-
active = {
|
|
1331
|
-
pointerId: pointer.pointerId ?? 0,
|
|
1332
|
-
pointerType: type,
|
|
1333
|
-
samples: [sampleOf(pointer.timeStamp, pointer.clientX, pointer.clientY)],
|
|
1334
|
-
started: false
|
|
1335
|
-
};
|
|
1336
|
-
if (slop <= 0) begin(active, true);
|
|
1337
|
-
}],
|
|
1338
|
-
["pointermove", (event) => {
|
|
1339
|
-
const pointer = event;
|
|
1340
|
-
if (active === null || active.pointerId !== (pointer.pointerId ?? 0)) return;
|
|
1341
|
-
const sample = sampleOf(pointer.timeStamp, pointer.clientX, pointer.clientY);
|
|
1342
|
-
if (!active.started) {
|
|
1343
|
-
const start = active.samples[0] ?? sample;
|
|
1344
|
-
if (Math.hypot(sample.x - start.x, sample.y - start.y) < slop) return;
|
|
1345
|
-
begin(active, true);
|
|
1346
|
-
}
|
|
1347
|
-
moved(active, sample);
|
|
1348
|
-
}],
|
|
1349
|
-
...[
|
|
1350
|
-
"pointerup",
|
|
1351
|
-
"pointercancel",
|
|
1352
|
-
"lostpointercapture"
|
|
1353
|
-
].map((type) => [type, (event) => {
|
|
1354
|
-
const pointer = event;
|
|
1355
|
-
if (active?.pointerType === "touch" && scrolls !== void 0) return;
|
|
1356
|
-
end(pointer.pointerId ?? 0, sampleOf(pointer.timeStamp, pointer.clientX, pointer.clientY), type === "pointerup", true);
|
|
1357
|
-
}])
|
|
1358
|
-
];
|
|
1359
|
-
const touchListeners = scrolls === void 0 ? [] : [
|
|
1360
|
-
["touchstart", (event) => {
|
|
1361
|
-
const touches = event;
|
|
1362
|
-
const touch = touches.changedTouches[0];
|
|
1363
|
-
if (active !== null || touches.touches.length !== 1 || touch === void 0) return;
|
|
1364
|
-
if (!ownTouch(touches.target)) return;
|
|
1365
|
-
touched = touches.target;
|
|
1366
|
-
active = {
|
|
1367
|
-
pointerId: touch.identifier,
|
|
1368
|
-
pointerType: "touch",
|
|
1369
|
-
samples: [sampleOf(touches.timeStamp, touch.clientX, touch.clientY)],
|
|
1370
|
-
started: false
|
|
1371
|
-
};
|
|
1372
|
-
}],
|
|
1373
|
-
["touchmove", (event) => {
|
|
1374
|
-
const touches = event;
|
|
1375
|
-
if (active === null) return;
|
|
1376
|
-
const touch = touchOf(touches, active.pointerId);
|
|
1377
|
-
if (touch === void 0) return;
|
|
1378
|
-
const sample = sampleOf(touches.timeStamp, touch.clientX, touch.clientY);
|
|
1379
|
-
if (!active.started) {
|
|
1380
|
-
const start = active.samples[0] ?? sample;
|
|
1381
|
-
const dx = sample.x - start.x;
|
|
1382
|
-
const dy = sample.y - start.y;
|
|
1383
|
-
if (Math.hypot(dx, dy) < Math.max(slop, 1)) return;
|
|
1384
|
-
const along = scrolls === "y" ? dy : dx;
|
|
1385
|
-
if (Math.abs(scrolls === "y" ? dx : dy) > Math.abs(along) || canScroll(touched ?? element, element, scrolls, along) || !touches.cancelable) {
|
|
1386
|
-
active = null;
|
|
1387
|
-
return;
|
|
1388
|
-
}
|
|
1389
|
-
begin(active, false);
|
|
1390
|
-
}
|
|
1391
|
-
touches.preventDefault();
|
|
1392
|
-
moved(active, sample);
|
|
1393
|
-
}],
|
|
1394
|
-
...["touchend", "touchcancel"].map((type) => [type, (event) => {
|
|
1395
|
-
const touches = event;
|
|
1396
|
-
if (active === null) return;
|
|
1397
|
-
const touch = touchOf(touches, active.pointerId);
|
|
1398
|
-
if (touch === void 0) return;
|
|
1399
|
-
end(active.pointerId, sampleOf(touches.timeStamp, touch.clientX, touch.clientY), type === "touchend", false);
|
|
1400
|
-
}])
|
|
1401
|
-
];
|
|
1402
|
-
owners.add(element);
|
|
1403
|
-
for (const [type, listener] of pointerListeners) element.addEventListener(type, listener);
|
|
1404
|
-
for (const [type, listener] of touchListeners) element.addEventListener(type, listener, { passive: false });
|
|
1405
|
-
return {
|
|
1406
|
-
pointerListeners,
|
|
1407
|
-
touchListeners,
|
|
1408
|
-
current: () => active
|
|
1409
|
-
};
|
|
1410
|
-
}), ({ pointerListeners, touchListeners, current }) => Effect.sync(() => {
|
|
1411
|
-
owners.delete(element);
|
|
1412
|
-
for (const [type, listener] of pointerListeners) element.removeEventListener(type, listener);
|
|
1413
|
-
for (const [type, listener] of touchListeners) element.removeEventListener(type, listener);
|
|
1414
|
-
const pointer = current();
|
|
1415
|
-
if (pointer !== null && !(pointer.pointerType === "touch" && scrolls !== void 0)) try {
|
|
1416
|
-
element.releasePointerCapture?.(pointer.pointerId);
|
|
1417
|
-
} catch {}
|
|
1418
|
-
})))
|
|
1419
|
-
});
|
|
1420
|
-
// src/dom/scroll-settle.ts
|
|
1421
|
-
const ScrollSettled = Schema.TaggedStruct("ScrollSettled", {
|
|
1422
|
-
/** The item whose start lies nearest the scroller's start, from 0. */
|
|
1423
|
-
index: Schema.Number });
|
|
1424
|
-
/** How long a scroll must be still to count as settled, where `scrollend` is missing. */
|
|
1425
|
-
const SETTLE_QUIET = 120;
|
|
1426
|
-
/**
|
|
1427
|
-
* Hears a scroller come to rest, as a Mount: after a swipe, a fling, a
|
|
1428
|
-
* trackpad or a scroll a Command made, it reports which of its items starts
|
|
1429
|
-
* nearest its own start (inside its `scroll-padding`), the start being the
|
|
1430
|
-
* right edge right to left. A snapping carousel reads it as the slide shown.
|
|
1431
|
-
*
|
|
1432
|
-
* At insert it first scrolls, at once, to item `start` (the Mount's args are
|
|
1433
|
-
* read only then, so this is where a redrawn or restored scroller begins),
|
|
1434
|
-
* and reports where it lies, since a scroller drawn already at rest sends no
|
|
1435
|
-
* `scrollend`. It listens for `scrollend` where the browser has it, and
|
|
1436
|
-
* otherwise for a scroll that is quiet for `SETTLE_QUIET` milliseconds.
|
|
1437
|
-
*/
|
|
1438
|
-
const ScrollSettle = Mount.defineStream("ScrollSettle", {
|
|
1439
|
-
messages: [ScrollSettled],
|
|
1440
|
-
args: {
|
|
1441
|
-
/** Which children are the items; default every child. */
|
|
1442
|
-
item: Schema.optional(Schema.String),
|
|
1443
|
-
/** Default `inline`, the row a carousel scrolls along. */
|
|
1444
|
-
axis: Schema.optional(Schema.Literals(["inline", "block"])),
|
|
1445
|
-
/** The item to scroll to at insert; default the first, which needs no scroll. */
|
|
1446
|
-
start: Schema.optional(Schema.Number)
|
|
1447
|
-
},
|
|
1448
|
-
execute: ({ element, item, axis = "inline", start = 0 }) => Stream.callback((queue) => Effect.acquireRelease(Effect.sync(() => {
|
|
1449
|
-
const items = () => Array.from(item === void 0 ? element.children : element.querySelectorAll(`:scope > ${item}`));
|
|
1450
|
-
/** How far `child`'s start lies past the scroller's start, along the axis. */
|
|
1451
|
-
const offsetOf = (child) => {
|
|
1452
|
-
const style = getComputedStyle(element);
|
|
1453
|
-
const box = element.getBoundingClientRect();
|
|
1454
|
-
const own = child.getBoundingClientRect();
|
|
1455
|
-
if (axis === "block") return own.top - box.top - (parseFloat(style.scrollPaddingBlockStart) || 0);
|
|
1456
|
-
const padding = parseFloat(style.scrollPaddingInlineStart) || 0;
|
|
1457
|
-
return style.direction === "rtl" ? box.right - padding - own.right : own.left - box.left - padding;
|
|
1458
|
-
};
|
|
1459
|
-
const report = () => {
|
|
1460
|
-
let nearest = -1;
|
|
1461
|
-
let distance = Infinity;
|
|
1462
|
-
items().forEach((child, index) => {
|
|
1463
|
-
const away = Math.abs(offsetOf(child));
|
|
1464
|
-
if (away < distance) {
|
|
1465
|
-
nearest = index;
|
|
1466
|
-
distance = away;
|
|
1467
|
-
}
|
|
1468
|
-
});
|
|
1469
|
-
if (nearest >= 0) Queue.offerUnsafe(queue, ScrollSettled.make({ index: nearest }));
|
|
1470
|
-
};
|
|
1471
|
-
const first = items()[start];
|
|
1472
|
-
const before = element.scrollLeft + element.scrollTop;
|
|
1473
|
-
if (start > 0 && first !== void 0) {
|
|
1474
|
-
const by = offsetOf(first);
|
|
1475
|
-
const rtl = axis === "inline" && getComputedStyle(element).direction === "rtl";
|
|
1476
|
-
element.scrollTo(axis === "block" ? {
|
|
1477
|
-
top: element.scrollTop + by,
|
|
1478
|
-
behavior: "instant"
|
|
1479
|
-
} : {
|
|
1480
|
-
left: element.scrollLeft + (rtl ? -by : by),
|
|
1481
|
-
behavior: "instant"
|
|
1482
|
-
});
|
|
1483
|
-
}
|
|
1484
|
-
if (element.scrollLeft + element.scrollTop === before) report();
|
|
1485
|
-
let quiet;
|
|
1486
|
-
const hasEnd = "onscrollend" in element;
|
|
1487
|
-
const listener = hasEnd ? report : () => {
|
|
1488
|
-
clearTimeout(quiet);
|
|
1489
|
-
quiet = setTimeout(report, 120);
|
|
1490
|
-
};
|
|
1491
|
-
const type = hasEnd ? "scrollend" : "scroll";
|
|
1492
|
-
element.addEventListener(type, listener);
|
|
1493
|
-
return () => {
|
|
1494
|
-
clearTimeout(quiet);
|
|
1495
|
-
element.removeEventListener(type, listener);
|
|
1496
|
-
};
|
|
1497
|
-
}), (detach) => Effect.sync(detach)))
|
|
1498
|
-
});
|
|
1499
|
-
// src/dom/pointer-position.ts
|
|
1500
|
-
/**
|
|
1501
|
-
* A place in an element's padding box, in CSS pixels from its top left
|
|
1502
|
-
* corner, and the pointer's pressure there (0 to 1; a mouse reads 0.5 while
|
|
1503
|
-
* a button is down). A captured pointer can be outside the box, so `x` and
|
|
1504
|
-
* `y` can be negative or past its size.
|
|
1505
|
-
*/
|
|
1506
|
-
const PointerPoint = Schema.Struct({
|
|
1507
|
-
x: Schema.Number,
|
|
1508
|
-
y: Schema.Number,
|
|
1509
|
-
pressure: Schema.Number
|
|
1510
|
-
});
|
|
1511
|
-
/** The padding box's size at the event, in CSS pixels. */
|
|
1512
|
-
const Size = {
|
|
1513
|
-
width: Schema.Number,
|
|
1514
|
-
height: Schema.Number
|
|
1515
|
-
};
|
|
1516
|
-
const PointerPressed = Schema.TaggedStruct("PointerPressed", {
|
|
1517
|
-
...Size,
|
|
1518
|
-
point: PointerPoint,
|
|
1519
|
-
/** `mouse`, `pen` or `touch`, as the browser names it. */
|
|
1520
|
-
pointerType: Schema.String
|
|
1521
|
-
});
|
|
1522
|
-
const PointerMoved = Schema.TaggedStruct("PointerMoved", {
|
|
1523
|
-
...Size,
|
|
1524
|
-
/** Where the pointer is now. */
|
|
1525
|
-
point: PointerPoint,
|
|
1526
|
-
/**
|
|
1527
|
-
* Every place it passed since the last move, ending with `point`: the
|
|
1528
|
-
* browser's coalesced events, so a fast stroke keeps its curve. Just
|
|
1529
|
-
* `point` where the browser coalesces none.
|
|
1530
|
-
*/
|
|
1531
|
-
points: Schema.Array(PointerPoint)
|
|
1532
|
-
});
|
|
1533
|
-
const PointerReleased = Schema.TaggedStruct("PointerReleased", {
|
|
1534
|
-
/** `false` when the pointer was cancelled, lost its capture, or pressed again unreleased. */
|
|
1535
|
-
completed: Schema.Boolean });
|
|
1536
|
-
/**
|
|
1537
|
-
* The padding box of an element whose border box is `rect`: inside its
|
|
1538
|
-
* border, padding included. An absolutely positioned child (a thumb, a
|
|
1539
|
-
* stroke) is laid out against it, so a place read here is where that child
|
|
1540
|
-
* sits, whatever padding a stylist adds.
|
|
1541
|
-
*/
|
|
1542
|
-
const paddingBoxOf = (layout) => {
|
|
1543
|
-
const { rect, border } = layout;
|
|
1544
|
-
return {
|
|
1545
|
-
left: rect.left + border.left,
|
|
1546
|
-
top: rect.top + border.top,
|
|
1547
|
-
width: Math.max(0, rect.width - border.left - border.right),
|
|
1548
|
-
height: Math.max(0, rect.height - border.top - border.bottom)
|
|
1549
|
-
};
|
|
1550
|
-
};
|
|
1551
|
-
const borderOf = (style) => ({
|
|
1552
|
-
top: parseFloat(style.borderTopWidth),
|
|
1553
|
-
right: parseFloat(style.borderRightWidth),
|
|
1554
|
-
bottom: parseFloat(style.borderBottomWidth),
|
|
1555
|
-
left: parseFloat(style.borderLeftWidth)
|
|
1556
|
-
});
|
|
1557
|
-
/**
|
|
1558
|
-
* An element's padding box now, in the viewport, as `PointerPosition`
|
|
1559
|
-
* measures it: for a size kept beside its places, which a `ResizeObserver`'s
|
|
1560
|
-
* content box does not match once the element has padding. Read from the
|
|
1561
|
-
* bounding rectangle and the computed border, since `clientWidth` and
|
|
1562
|
-
* `clientLeft` round to whole pixels.
|
|
1563
|
-
*/
|
|
1564
|
-
const measurePaddingBox = (element) => paddingBoxOf({
|
|
1565
|
-
rect: element.getBoundingClientRect(),
|
|
1566
|
-
border: borderOf(getComputedStyle(element))
|
|
1567
|
-
});
|
|
1568
|
-
const pointIn = (box, event) => ({
|
|
1569
|
-
x: event.clientX - box.left,
|
|
1570
|
-
y: event.clientY - box.top,
|
|
1571
|
-
pressure: event.pressure
|
|
1572
|
-
});
|
|
1573
|
-
/**
|
|
1574
|
-
* Where one pointer is inside an element, as a Mount, for a surface the
|
|
1575
|
-
* pointer draws on or points into (a color area, a dial, a signature pad): a
|
|
1576
|
-
* primary press, each move until the release, and the release, each with
|
|
1577
|
-
* the place in the element's padding box and the box's size. The box is
|
|
1578
|
-
* measured at each event, so an element that moved or resized is followed.
|
|
1579
|
-
* Coordinates are raw, left to right and top down whatever the direction:
|
|
1580
|
-
* what a place means (a share, an angle, a reading direction) is the parent's.
|
|
1581
|
-
*
|
|
1582
|
-
* The pointer is captured from press to release, so a drag that leaves the
|
|
1583
|
-
* element is still heard, and the moves and the release are listened to only
|
|
1584
|
-
* meanwhile. A press keeps the browser's own focus and text selection away,
|
|
1585
|
-
* and a second pointer while one is down is ignored.
|
|
1586
|
-
*/
|
|
1587
|
-
const PointerPosition = Mount.defineStream("PointerPosition", {
|
|
1588
|
-
messages: [
|
|
1589
|
-
PointerPressed,
|
|
1590
|
-
PointerMoved,
|
|
1591
|
-
PointerReleased
|
|
1592
|
-
],
|
|
1593
|
-
args: {
|
|
1594
|
-
/**
|
|
1595
|
-
* A descendant to focus on a press, found by this selector (a thumb), so
|
|
1596
|
-
* the keys go on from where the pointer left it.
|
|
1597
|
-
*/
|
|
1598
|
-
focus: Schema.optionalKey(Schema.String) },
|
|
1599
|
-
execute: ({ element, focus }) => Stream.callback((queue) => Effect.acquireRelease(Effect.sync(() => {
|
|
1600
|
-
const offer = (fact) => Queue.offerUnsafe(queue, fact);
|
|
1601
|
-
let held = Option.none();
|
|
1602
|
-
const ours = (event) => event instanceof PointerEvent && Option.contains(held, event.pointerId);
|
|
1603
|
-
const release = () => {
|
|
1604
|
-
if (Option.isNone(held)) return;
|
|
1605
|
-
const pointerId = held.value;
|
|
1606
|
-
held = Option.none();
|
|
1607
|
-
for (const [type, listener] of during) element.removeEventListener(type, listener);
|
|
1608
|
-
try {
|
|
1609
|
-
element.releasePointerCapture(pointerId);
|
|
1610
|
-
} catch {}
|
|
1611
|
-
};
|
|
1612
|
-
const end = (completed) => (event) => {
|
|
1613
|
-
if (!ours(event)) return;
|
|
1614
|
-
release();
|
|
1615
|
-
offer(PointerReleased.make({ completed }));
|
|
1616
|
-
};
|
|
1617
|
-
const move = (event) => {
|
|
1618
|
-
if (!ours(event)) return;
|
|
1619
|
-
const box = measurePaddingBox(element);
|
|
1620
|
-
const point = pointIn(box, event);
|
|
1621
|
-
const coalesced = event.getCoalescedEvents?.() ?? [];
|
|
1622
|
-
offer(PointerMoved.make({
|
|
1623
|
-
width: box.width,
|
|
1624
|
-
height: box.height,
|
|
1625
|
-
point,
|
|
1626
|
-
points: coalesced.length > 0 ? coalesced.map((one) => pointIn(box, one)) : [point]
|
|
1627
|
-
}));
|
|
1628
|
-
};
|
|
1629
|
-
const during = [
|
|
1630
|
-
["pointermove", move],
|
|
1631
|
-
["pointerup", end(true)],
|
|
1632
|
-
["pointercancel", end(false)],
|
|
1633
|
-
["lostpointercapture", end(false)]
|
|
1634
|
-
];
|
|
1635
|
-
const down = (event) => {
|
|
1636
|
-
if (!(event instanceof PointerEvent) || event.button !== 0) return;
|
|
1637
|
-
if (Option.isSome(held)) {
|
|
1638
|
-
if (!ours(event)) return;
|
|
1639
|
-
release();
|
|
1640
|
-
offer(PointerReleased.make({ completed: false }));
|
|
1641
|
-
}
|
|
1642
|
-
held = Option.some(event.pointerId);
|
|
1643
|
-
for (const [type, listener] of during) element.addEventListener(type, listener);
|
|
1644
|
-
try {
|
|
1645
|
-
element.setPointerCapture(event.pointerId);
|
|
1646
|
-
} catch {}
|
|
1647
|
-
event.preventDefault();
|
|
1648
|
-
if (focus !== void 0) {
|
|
1649
|
-
const into = element.querySelector(focus);
|
|
1650
|
-
if (into instanceof HTMLElement) into.focus();
|
|
1651
|
-
}
|
|
1652
|
-
const box = measurePaddingBox(element);
|
|
1653
|
-
offer(PointerPressed.make({
|
|
1654
|
-
width: box.width,
|
|
1655
|
-
height: box.height,
|
|
1656
|
-
point: pointIn(box, event),
|
|
1657
|
-
pointerType: event.pointerType
|
|
1658
|
-
}));
|
|
1659
|
-
};
|
|
1660
|
-
element.addEventListener("pointerdown", down);
|
|
1661
|
-
return () => {
|
|
1662
|
-
element.removeEventListener("pointerdown", down);
|
|
1663
|
-
release();
|
|
1664
|
-
};
|
|
1665
|
-
}), (stop) => Effect.sync(stop)))
|
|
1666
|
-
});
|
|
1667
|
-
// src/dom/track-box.ts
|
|
1668
|
-
/** The attribute on the mounted element naming the element `TrackBox` follows, by id. */
|
|
1669
|
-
const TRACK_TARGET_ATTRIBUTE = "data-target";
|
|
1670
|
-
/** The custom properties `TrackBox` writes for `name`, as `measured` names `Measure`'s. */
|
|
1671
|
-
const trackedBox = (name) => ({
|
|
1672
|
-
x: `--fk-${name}-x`,
|
|
1673
|
-
y: `--fk-${name}-y`,
|
|
1674
|
-
w: `--fk-${name}-w`,
|
|
1675
|
-
h: `--fk-${name}-h`,
|
|
1676
|
-
radius: `--fk-${name}-radius`
|
|
1677
|
-
});
|
|
1678
|
-
/** Sent as the followed element changes: its id, and whether it is on the page. */
|
|
1679
|
-
const TrackedTarget = Schema.TaggedStruct("TrackedTarget", {
|
|
1680
|
-
target: Schema.String,
|
|
1681
|
-
found: Schema.Boolean
|
|
1682
|
-
});
|
|
1683
|
-
/**
|
|
1684
|
-
* The radius a box of `width` by `height` draws for a computed
|
|
1685
|
-
* `border-top-left-radius` of `value` (`8px`, `50%`, `8px 4px`): its
|
|
1686
|
-
* horizontal length in pixels, a share of the width for a percentage, and
|
|
1687
|
-
* never more than half the shorter side, where the browser stops it.
|
|
1688
|
-
*/
|
|
1689
|
-
const cornerRadius = (value, width, height) => {
|
|
1690
|
-
const first = value.trim().split(/\s+/)[0] ?? "";
|
|
1691
|
-
const length = parseFloat(first);
|
|
1692
|
-
if (!Number.isFinite(length)) return 0;
|
|
1693
|
-
const pixels = first.endsWith("%") ? length * width / 100 : length;
|
|
1694
|
-
return Math.max(0, Math.min(pixels, width / 2, height / 2));
|
|
1695
|
-
};
|
|
1696
|
-
/**
|
|
1697
|
-
* Follows another element's box, as a Mount: the element whose id is the
|
|
1698
|
-
* mounted element's `data-target` (`TRACK_TARGET_ATTRIBUTE`). Its box in
|
|
1699
|
-
* viewport pixels is written on the mounted element as `--fk-<name>-x`,
|
|
1700
|
-
* `-y`, `-w` and `-h`, and with `radius`, its top left corner's radius as
|
|
1701
|
-
* `--fk-<name>-radius` (`cornerRadius`), so a fixed overlay drawn from them
|
|
1702
|
-
* (a tour's cutout, a coach mark's ring) sits over it. While nothing is
|
|
1703
|
-
* followed they are removed, so a stylist's fallbacks apply.
|
|
1704
|
-
*
|
|
1705
|
-
* The box is read again on a scroll anywhere (heard on the way down, since
|
|
1706
|
-
* `scroll` does not bubble), a window resize, the followed element's own
|
|
1707
|
-
* resize, and any change to the document's elements, which is also how a
|
|
1708
|
-
* target drawn anew under the same id is found. `data-target` is read again
|
|
1709
|
-
* whenever it changes, so one element can glide from target to target
|
|
1710
|
-
* without being drawn again, which a Mount's args, read once, could not do.
|
|
1711
|
-
* What moves the target by any other way (a stylesheet added) is seen at the
|
|
1712
|
-
* next of these.
|
|
1713
|
-
*
|
|
1714
|
-
* Whether a target is on the page is the parent's to act on (a tour shows
|
|
1715
|
-
* the step in the middle instead), so each change of the target or of
|
|
1716
|
-
* whether it is found sends `TrackedTarget`, starting with the first one.
|
|
1717
|
-
* Since it sends a Message, a component may draw it by default: a Scene test
|
|
1718
|
-
* resolves it with what the parent maps it to. An empty `data-target` follows
|
|
1719
|
-
* nothing and sends nothing.
|
|
1720
|
-
*/
|
|
1721
|
-
const TrackBox = Mount.defineStream("TrackBox", {
|
|
1722
|
-
messages: [TrackedTarget],
|
|
1723
|
-
args: {
|
|
1724
|
-
/** The custom properties' prefix: `tour` writes `--fk-tour-x`. */
|
|
1725
|
-
name: Schema.String,
|
|
1726
|
-
/** Whether to write the target's corner radius too; it reads the target's computed style. */
|
|
1727
|
-
radius: Schema.optional(Schema.Boolean)
|
|
1728
|
-
},
|
|
1729
|
-
execute: ({ element, name, radius = false }) => Stream.callback((queue) => Effect.acquireRelease(Effect.sync(() => {
|
|
1730
|
-
const document = element.ownerDocument;
|
|
1731
|
-
const view = document.defaultView;
|
|
1732
|
-
const properties = trackedBox(name);
|
|
1733
|
-
const style = element instanceof HTMLElement ? element.style : void 0;
|
|
1734
|
-
let target = null;
|
|
1735
|
-
let told;
|
|
1736
|
-
const place = () => {
|
|
1737
|
-
if (style === void 0) return;
|
|
1738
|
-
if (target === null) {
|
|
1739
|
-
for (const property of Object.values(properties)) style.removeProperty(property);
|
|
1740
|
-
return;
|
|
1741
|
-
}
|
|
1742
|
-
const box = target.getBoundingClientRect();
|
|
1743
|
-
style.setProperty(properties.x, `${box.left}px`);
|
|
1744
|
-
style.setProperty(properties.y, `${box.top}px`);
|
|
1745
|
-
style.setProperty(properties.w, `${box.width}px`);
|
|
1746
|
-
style.setProperty(properties.h, `${box.height}px`);
|
|
1747
|
-
if (radius) {
|
|
1748
|
-
const corner = getComputedStyle(target).borderTopLeftRadius;
|
|
1749
|
-
style.setProperty(properties.radius, `${cornerRadius(corner, box.width, box.height)}px`);
|
|
1750
|
-
}
|
|
1751
|
-
};
|
|
1752
|
-
const follow = () => {
|
|
1753
|
-
const id = element.getAttribute("data-target") ?? "";
|
|
1754
|
-
const found = id === "" ? null : document.getElementById(id);
|
|
1755
|
-
if (found !== target) {
|
|
1756
|
-
if (target !== null) resized.unobserve(target);
|
|
1757
|
-
if (found !== null) resized.observe(found);
|
|
1758
|
-
target = found;
|
|
1759
|
-
}
|
|
1760
|
-
place();
|
|
1761
|
-
if (id !== "" && (told?.target !== id || told.found !== (found !== null))) {
|
|
1762
|
-
told = TrackedTarget.make({
|
|
1763
|
-
target: id,
|
|
1764
|
-
found: found !== null
|
|
1765
|
-
});
|
|
1766
|
-
Queue.offerUnsafe(queue, told);
|
|
1767
|
-
}
|
|
1768
|
-
};
|
|
1769
|
-
const resized = new ResizeObserver(place);
|
|
1770
|
-
const changed = new MutationObserver(follow);
|
|
1771
|
-
changed.observe(element, {
|
|
1772
|
-
attributes: true,
|
|
1773
|
-
attributeFilter: [TRACK_TARGET_ATTRIBUTE]
|
|
1774
|
-
});
|
|
1775
|
-
changed.observe(document, {
|
|
1776
|
-
childList: true,
|
|
1777
|
-
subtree: true
|
|
1778
|
-
});
|
|
1779
|
-
view?.addEventListener("scroll", place, {
|
|
1780
|
-
capture: true,
|
|
1781
|
-
passive: true
|
|
1782
|
-
});
|
|
1783
|
-
view?.addEventListener("resize", place);
|
|
1784
|
-
follow();
|
|
1785
|
-
return () => {
|
|
1786
|
-
changed.disconnect();
|
|
1787
|
-
resized.disconnect();
|
|
1788
|
-
view?.removeEventListener("scroll", place, { capture: true });
|
|
1789
|
-
view?.removeEventListener("resize", place);
|
|
1790
|
-
};
|
|
1791
|
-
}), (stop) => Effect.sync(stop)))
|
|
1792
|
-
});
|
|
1793
|
-
// src/dom/image-decode.ts
|
|
1794
|
-
/**
|
|
1795
|
-
* An image fetched and decoded before it is shown, as a Command: a lightbox
|
|
1796
|
-
* or a carousel asks for the next picture, and shows it on `Decoded`, so the
|
|
1797
|
-
* switch never passes through a blank frame. A Command, not a Mount: the
|
|
1798
|
-
* Model decides to show the image, so the Message that leads there carries
|
|
1799
|
-
* the news that it is ready.
|
|
1800
|
-
*/
|
|
1801
|
-
const ImageDecodeMessage = defineMessageUnion({
|
|
1802
|
-
Decoded: { src: Schema.String },
|
|
1803
|
-
DecodeFailed: {
|
|
1804
|
-
src: Schema.String,
|
|
1805
|
-
message: Schema.String
|
|
1806
|
-
}
|
|
1807
|
-
});
|
|
1808
|
-
/**
|
|
1809
|
-
* Fetches and decodes `source` (`img.decode()`), yielding `Decoded` once it
|
|
1810
|
-
* can be painted at once, or `DecodeFailed` when it cannot be fetched or read,
|
|
1811
|
-
* or there is no document (a server render). Given `srcset` and `sizes`, as
|
|
1812
|
-
* `foldkit-media`'s `Picture.Img` has them, the browser picks the candidate
|
|
1813
|
-
* it would draw, so the decoded file is the one shown.
|
|
1814
|
-
*/
|
|
1815
|
-
const decodeImage = (source) => ({
|
|
1816
|
-
name: "Image.decode",
|
|
1817
|
-
args: { src: source.src },
|
|
1818
|
-
effect: typeof document === "undefined" ? Effect.succeed(ImageDecodeMessage.DecodeFailed({
|
|
1819
|
-
src: source.src,
|
|
1820
|
-
message: "there is no document"
|
|
1821
|
-
})) : Effect.matchEffect(Effect.tryPromise({
|
|
1822
|
-
try: () => {
|
|
1823
|
-
const image = new Image();
|
|
1824
|
-
if (source.sizes !== void 0) image.sizes = source.sizes;
|
|
1825
|
-
if (source.srcset !== void 0) image.srcset = source.srcset;
|
|
1826
|
-
image.src = source.src;
|
|
1827
|
-
return image.decode();
|
|
1828
|
-
},
|
|
1829
|
-
catch: (error) => error instanceof Error ? error.message : String(error)
|
|
1830
|
-
}), {
|
|
1831
|
-
onFailure: (message) => Effect.succeed(ImageDecodeMessage.DecodeFailed({
|
|
1832
|
-
src: source.src,
|
|
1833
|
-
message
|
|
1834
|
-
})),
|
|
1835
|
-
onSuccess: () => Effect.succeed(ImageDecodeMessage.Decoded({ src: source.src }))
|
|
1836
|
-
})
|
|
1837
|
-
});
|
|
1838
|
-
export { Autofocus, ClipboardMessage, ClipboardReadMessage, DRAG_THRESHOLD, DragCancelled, DragDropped, DragPlace, DragStarted, DragZone, DraggedOver, EditAsked, EditableText, FLUID_HELD_ATTRIBUTE, FLUID_HOVER_ATTRIBUTE, FLUID_LIT_ATTRIBUTE, FLUID_PRESS_ATTRIBUTE, FluidHover, FocusScope, Focused, FollowTabStop, HOLD_SLOP, HOLD_TO_DRAG_MS, HideOutside, ImageDecodeMessage, Input, InputMask, KEYBOARD_INSET, KeepInView, KeyboardInset, Measure, Move, MoveEnded, MoveStarted, Moved, NO_SWIPE, PointerDrag, PointerMoved, PointerPoint, PointerPosition, PointerPressed, PointerReleased, SCROLL_BAR_ATTRIBUTE, SCROLL_OVERLAID_ATTRIBUTE, SETTLE_QUIET, SWIPE_WINDOW, ScriptMessage, ScrollBars, ScrollLock, ScrollSettle, ScrollSettled, ShareData, ShareMessage, Swipe, SwipeEnded, SwipeStarted, Swiped, TRACK_TARGET_ATTRIBUTE, TargetHovered, TargetPressed, Targets, TextCancelled, TextCommitted, TextEdited, TrackBox, TrackedTarget, applyMask, boxOf, canScroll, copyText, cornerRadius, decodeImage, fluidHovered, keepScroll, keyboardInset, loadScript, measurePaddingBox, measured, paddingBoxOf, pointedLinks, readText, scrollThumb, share, tabbableWithin, targetOf, textOf, trackedBox, velocityOf, zoneOf };
|
|
1839
|
-
|
|
1840
|
-
//# sourceMappingURL=index.mjs.map
|