@vizejs/composable 0.426.3 → 0.428.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/abort-signal.d.mts +1 -1
- package/dist/active-element.d.mts +37 -0
- package/dist/active-element.mjs +56 -0
- package/dist/animate.d.mts +114 -0
- package/dist/animate.mjs +157 -0
- package/dist/battery.d.mts +61 -0
- package/dist/battery.mjs +90 -0
- package/dist/breakpoints.d.mts +82 -0
- package/dist/breakpoints.mjs +91 -0
- package/dist/catalog-BeTXFKxF.d.mts +4188 -0
- package/dist/catalog-r4Z5nptX.mjs +5144 -0
- package/dist/catalog.d.mts +1 -1
- package/dist/catalog.mjs +1 -1
- package/dist/color-mode.d.mts +131 -0
- package/dist/color-mode.mjs +133 -0
- package/dist/computed-async.d.mts +63 -0
- package/dist/computed-async.mjs +43 -0
- package/dist/computed-with-control.d.mts +44 -0
- package/dist/computed-with-control.mjs +54 -0
- package/dist/create-event-hook.d.mts +77 -0
- package/dist/create-event-hook.mjs +66 -0
- package/dist/create-global-state.d.mts +24 -0
- package/dist/create-global-state.mjs +34 -0
- package/dist/create-injection-state.d.mts +51 -0
- package/dist/create-injection-state.mjs +19 -0
- package/dist/create-shared-composable.d.mts +38 -0
- package/dist/create-shared-composable.mjs +54 -0
- package/dist/device-motion.d.mts +71 -0
- package/dist/device-motion.mjs +75 -0
- package/dist/device-orientation.d.mts +82 -0
- package/dist/device-orientation.mjs +86 -0
- package/dist/device-pixel-ratio.d.mts +45 -0
- package/dist/device-pixel-ratio.mjs +50 -0
- package/dist/document-visibility.mjs +6 -2
- package/dist/draggable.d.mts +121 -0
- package/dist/draggable.mjs +153 -0
- package/dist/element-bounding.d.mts +87 -0
- package/dist/element-bounding.mjs +95 -0
- package/dist/element-by-point.d.mts +70 -0
- package/dist/element-by-point.mjs +69 -0
- package/dist/element-hover.d.mts +42 -0
- package/dist/element-hover.mjs +70 -0
- package/dist/element-ref.d.mts +34 -0
- package/dist/element-ref.mjs +23 -0
- package/dist/element-target-Crpxl4D9.d.mts +60 -0
- package/dist/element-target.d.mts +2 -0
- package/dist/element-target.mjs +58 -0
- package/dist/event-listener.mjs +7 -3
- package/dist/focus.d.mts +69 -0
- package/dist/focus.mjs +124 -0
- package/dist/fps.d.mts +59 -0
- package/dist/fps.mjs +64 -0
- package/dist/geolocation.d.mts +98 -0
- package/dist/geolocation.mjs +86 -0
- package/dist/i18n.d.mts +237 -0
- package/dist/i18n.mjs +215 -0
- package/dist/icu-message.d.mts +235 -0
- package/dist/icu-message.mjs +343 -0
- package/dist/idle.d.mts +79 -0
- package/dist/idle.mjs +90 -0
- package/dist/index.d.mts +172 -6
- package/dist/index.mjs +173 -7
- package/dist/infinite-scroll.d.mts +56 -0
- package/dist/infinite-scroll.mjs +72 -0
- package/dist/intersection-observer.d.mts +122 -0
- package/dist/intersection-observer.mjs +117 -0
- package/dist/magic-keys.d.mts +121 -0
- package/dist/magic-keys.mjs +163 -0
- package/dist/math.d.mts +96 -0
- package/dist/math.mjs +84 -0
- package/dist/media-query.d.mts +3 -1
- package/dist/media-query.mjs +5 -3
- package/dist/mouse-in-element.d.mts +49 -0
- package/dist/mouse-in-element.mjs +66 -0
- package/dist/mouse.d.mts +77 -0
- package/dist/mouse.mjs +100 -0
- package/dist/mutation-observer.d.mts +98 -0
- package/dist/mutation-observer.mjs +69 -0
- package/dist/network.d.mts +96 -0
- package/dist/network.mjs +117 -0
- package/dist/on-click-outside.d.mts +69 -0
- package/dist/on-click-outside.mjs +115 -0
- package/dist/on-key-stroke.d.mts +71 -0
- package/dist/on-key-stroke.mjs +79 -0
- package/dist/on-long-press.d.mts +82 -0
- package/dist/on-long-press.mjs +105 -0
- package/dist/on-start-typing.d.mts +44 -0
- package/dist/on-start-typing.mjs +61 -0
- package/dist/page-leave.d.mts +26 -0
- package/dist/page-leave.mjs +40 -0
- package/dist/parent-element.d.mts +16 -0
- package/dist/parent-element.mjs +27 -0
- package/dist/pinch.d.mts +73 -0
- package/dist/pinch.mjs +138 -0
- package/dist/pointer-lock.d.mts +79 -0
- package/dist/pointer-lock.mjs +126 -0
- package/dist/pointer.d.mts +78 -0
- package/dist/pointer.mjs +95 -0
- package/dist/preferences.d.mts +55 -0
- package/dist/preferences.mjs +63 -0
- package/dist/preferred-languages.d.mts +43 -0
- package/dist/preferred-languages.mjs +44 -0
- package/dist/reactify.d.mts +28 -0
- package/dist/reactify.mjs +7 -0
- package/dist/ref-auto-reset.d.mts +47 -0
- package/dist/ref-auto-reset.mjs +70 -0
- package/dist/ref-debounced.d.mts +29 -0
- package/dist/ref-debounced.mjs +29 -0
- package/dist/ref-default.d.mts +27 -0
- package/dist/ref-default.mjs +33 -0
- package/dist/resize-observer.d.mts +96 -0
- package/dist/resize-observer.mjs +111 -0
- package/dist/resolver.d.mts +124 -0
- package/dist/resolver.mjs +138 -0
- package/dist/retry-async.d.mts +2 -2
- package/dist/retry-delay-DYsdq4SE.d.mts +73 -0
- package/dist/retry-delay.d.mts +1 -72
- package/dist/screen-orientation.d.mts +77 -0
- package/dist/screen-orientation.mjs +74 -0
- package/dist/scroll-lock.d.mts +37 -0
- package/dist/scroll-lock.mjs +50 -0
- package/dist/scroll.d.mts +158 -0
- package/dist/scroll.mjs +172 -0
- package/dist/standard-schema-DmNgFVK5.d.mts +107 -0
- package/dist/standard-schema.d.mts +2 -0
- package/dist/standard-schema.mjs +60 -0
- package/dist/swipe.d.mts +125 -0
- package/dist/swipe.mjs +225 -0
- package/dist/sync-ref.d.mts +80 -0
- package/dist/sync-ref.mjs +43 -0
- package/dist/text-selection.d.mts +46 -0
- package/dist/text-selection.mjs +62 -0
- package/dist/textarea-autosize.d.mts +58 -0
- package/dist/textarea-autosize.mjs +54 -0
- package/dist/timeout-scheduler-CI8RVLZs.d.mts +18 -0
- package/dist/timeout-scheduler.d.mts +1 -17
- package/dist/to-reactive.d.mts +26 -0
- package/dist/to-reactive.mjs +46 -0
- package/dist/transition.d.mts +125 -0
- package/dist/transition.mjs +266 -0
- package/dist/until.d.mts +177 -0
- package/dist/until.mjs +111 -0
- package/dist/use-array.d.mts +112 -0
- package/dist/use-array.mjs +90 -0
- package/dist/use-async-queue.d.mts +109 -0
- package/dist/use-async-queue.mjs +96 -0
- package/dist/use-async-state.d.mts +86 -0
- package/dist/use-async-state.mjs +41 -0
- package/dist/use-barcode-detector.d.mts +159 -0
- package/dist/use-barcode-detector.mjs +143 -0
- package/dist/use-bluetooth.d.mts +164 -0
- package/dist/use-bluetooth.mjs +183 -0
- package/dist/use-broadcast-channel.d.mts +115 -0
- package/dist/use-broadcast-channel.mjs +121 -0
- package/dist/use-builtin-ai.d.mts +342 -0
- package/dist/use-builtin-ai.mjs +261 -0
- package/dist/use-clipboard.d.mts +169 -0
- package/dist/use-clipboard.mjs +226 -0
- package/dist/use-compression-stream.d.mts +173 -0
- package/dist/use-compression-stream.mjs +166 -0
- package/dist/use-confirm-dialog.d.mts +70 -0
- package/dist/use-confirm-dialog.mjs +57 -0
- package/dist/use-contact-picker.d.mts +117 -0
- package/dist/use-contact-picker.mjs +103 -0
- package/dist/use-cookie.d.mts +196 -0
- package/dist/use-cookie.mjs +259 -0
- package/dist/use-countdown.d.mts +85 -0
- package/dist/use-countdown.mjs +74 -0
- package/dist/use-css-var.d.mts +96 -0
- package/dist/use-css-var.mjs +104 -0
- package/dist/use-cycle-list.d.mts +76 -0
- package/dist/use-cycle-list.mjs +39 -0
- package/dist/use-date-format.d.mts +103 -0
- package/dist/use-date-format.mjs +147 -0
- package/dist/use-date-time-format.d.mts +75 -0
- package/dist/use-date-time-format.mjs +53 -0
- package/dist/use-debounced.d.mts +1 -1
- package/dist/use-display-media.d.mts +62 -0
- package/dist/use-display-media.mjs +46 -0
- package/dist/use-display-names.d.mts +75 -0
- package/dist/use-display-names.mjs +52 -0
- package/dist/use-document-title.d.mts +88 -0
- package/dist/use-document-title.mjs +100 -0
- package/dist/use-drop-zone.d.mts +128 -0
- package/dist/use-drop-zone.mjs +154 -0
- package/dist/use-event-source.d.mts +184 -0
- package/dist/use-event-source.mjs +226 -0
- package/dist/use-eye-dropper.d.mts +79 -0
- package/dist/use-eye-dropper.mjs +68 -0
- package/dist/use-favicon.d.mts +78 -0
- package/dist/use-favicon.mjs +68 -0
- package/dist/use-fetch.d.mts +230 -0
- package/dist/use-fetch.mjs +263 -0
- package/dist/use-field.d.mts +107 -0
- package/dist/use-field.mjs +117 -0
- package/dist/use-file-dialog.d.mts +139 -0
- package/dist/use-file-dialog.mjs +101 -0
- package/dist/use-file-system-access.d.mts +184 -0
- package/dist/use-file-system-access.mjs +151 -0
- package/dist/use-form-field-props.d.mts +235 -0
- package/dist/use-form-field-props.mjs +164 -0
- package/dist/use-form.d.mts +324 -0
- package/dist/use-form.mjs +482 -0
- package/dist/use-fullscreen.d.mts +104 -0
- package/dist/use-fullscreen.mjs +95 -0
- package/dist/use-gamepad.d.mts +242 -0
- package/dist/use-gamepad.mjs +218 -0
- package/dist/use-hid.d.mts +160 -0
- package/dist/use-hid.mjs +156 -0
- package/dist/use-id-generator.d.mts +44 -0
- package/dist/use-id-generator.mjs +38 -0
- package/dist/use-image.d.mts +125 -0
- package/dist/use-image.mjs +109 -0
- package/dist/use-indexed-db.d.mts +207 -0
- package/dist/use-indexed-db.mjs +251 -0
- package/dist/use-interval-BA55gTHT.d.mts +140 -0
- package/dist/use-interval.d.mts +2 -0
- package/dist/use-interval.mjs +100 -0
- package/dist/use-list-format.d.mts +60 -0
- package/dist/use-list-format.mjs +40 -0
- package/dist/use-machine.d.mts +90 -0
- package/dist/use-machine.mjs +78 -0
- package/dist/use-map.d.mts +90 -0
- package/dist/use-map.mjs +70 -0
- package/dist/use-media-controls.d.mts +198 -0
- package/dist/use-media-controls.mjs +264 -0
- package/dist/use-memoize.d.mts +73 -0
- package/dist/use-memoize.mjs +28 -0
- package/dist/use-mounted.d.mts +24 -0
- package/dist/use-mounted.mjs +29 -0
- package/dist/use-navigation-api.d.mts +360 -0
- package/dist/use-navigation-api.mjs +231 -0
- package/dist/use-notification.d.mts +139 -0
- package/dist/use-notification.mjs +131 -0
- package/dist/use-now.d.mts +137 -0
- package/dist/use-now.mjs +44 -0
- package/dist/use-number-format.d.mts +73 -0
- package/dist/use-number-format.mjs +58 -0
- package/dist/use-object-url.d.mts +47 -0
- package/dist/use-object-url.mjs +54 -0
- package/dist/use-offset-pagination.d.mts +91 -0
- package/dist/use-offset-pagination.mjs +80 -0
- package/dist/use-payment-request.d.mts +239 -0
- package/dist/use-payment-request.mjs +206 -0
- package/dist/use-performance-observer.d.mts +285 -0
- package/dist/use-performance-observer.mjs +132 -0
- package/dist/use-permission.d.mts +99 -0
- package/dist/use-permission.mjs +92 -0
- package/dist/use-plural-rules.d.mts +79 -0
- package/dist/use-plural-rules.mjs +59 -0
- package/dist/use-push-subscription.d.mts +154 -0
- package/dist/use-push-subscription.mjs +146 -0
- package/dist/use-queue.d.mts +89 -0
- package/dist/use-queue.mjs +116 -0
- package/dist/use-raf-fn.d.mts +87 -0
- package/dist/use-raf-fn.mjs +99 -0
- package/dist/use-relative-time-format.d.mts +111 -0
- package/dist/use-relative-time-format.mjs +119 -0
- package/dist/use-request-idle-callback.d.mts +122 -0
- package/dist/use-request-idle-callback.mjs +147 -0
- package/dist/use-route-query.d.mts +149 -0
- package/dist/use-route-query.mjs +86 -0
- package/dist/use-scheduler-post-task.d.mts +156 -0
- package/dist/use-scheduler-post-task.mjs +182 -0
- package/dist/use-screen-details.d.mts +205 -0
- package/dist/use-screen-details.mjs +188 -0
- package/dist/use-script-tag.d.mts +162 -0
- package/dist/use-script-tag.mjs +171 -0
- package/dist/use-segmenter.d.mts +78 -0
- package/dist/use-segmenter.mjs +66 -0
- package/dist/use-selection.d.mts +125 -0
- package/dist/use-selection.mjs +77 -0
- package/dist/use-serial.d.mts +165 -0
- package/dist/use-serial.mjs +205 -0
- package/dist/use-service-worker.d.mts +177 -0
- package/dist/use-service-worker.mjs +178 -0
- package/dist/use-set.d.mts +96 -0
- package/dist/use-set.mjs +74 -0
- package/dist/use-share.d.mts +92 -0
- package/dist/use-share.mjs +99 -0
- package/dist/use-sorted-locale.d.mts +62 -0
- package/dist/use-sorted-locale.mjs +52 -0
- package/dist/use-sorted.d.mts +29 -0
- package/dist/use-sorted.mjs +14 -0
- package/dist/use-speech-recognition.d.mts +150 -0
- package/dist/use-speech-recognition.mjs +168 -0
- package/dist/use-speech-synthesis.d.mts +148 -0
- package/dist/use-speech-synthesis.mjs +152 -0
- package/dist/use-stack.d.mts +83 -0
- package/dist/use-stack.mjs +93 -0
- package/dist/use-stepper.d.mts +79 -0
- package/dist/use-stepper.mjs +52 -0
- package/dist/use-storage-estimate.d.mts +151 -0
- package/dist/use-storage-estimate.mjs +170 -0
- package/dist/use-storage.d.mts +214 -0
- package/dist/use-storage.mjs +415 -0
- package/dist/use-style-tag.d.mts +102 -0
- package/dist/use-style-tag.mjs +91 -0
- package/dist/use-supported.d.mts +23 -0
- package/dist/use-supported.mjs +26 -0
- package/dist/use-throttled.d.mts +1 -1
- package/dist/use-time-ago.d.mts +163 -0
- package/dist/use-time-ago.mjs +95 -0
- package/dist/use-timeout.d.mts +122 -0
- package/dist/use-timeout.mjs +65 -0
- package/dist/use-url-hash.d.mts +88 -0
- package/dist/use-url-hash.mjs +145 -0
- package/dist/use-url-search-params.d.mts +223 -0
- package/dist/use-url-search-params.mjs +295 -0
- package/dist/use-usb.d.mts +212 -0
- package/dist/use-usb.mjs +137 -0
- package/dist/use-user-activation.d.mts +83 -0
- package/dist/use-user-activation.mjs +113 -0
- package/dist/use-user-media.d.mts +194 -0
- package/dist/use-user-media.mjs +214 -0
- package/dist/use-v-model.d.mts +113 -0
- package/dist/use-v-model.mjs +40 -0
- package/dist/use-vibrate.d.mts +81 -0
- package/dist/use-vibrate.mjs +90 -0
- package/dist/use-view-transition.d.mts +106 -0
- package/dist/use-view-transition.mjs +101 -0
- package/dist/use-visual-viewport.d.mts +105 -0
- package/dist/use-visual-viewport.mjs +104 -0
- package/dist/use-wake-lock.d.mts +96 -0
- package/dist/use-wake-lock.mjs +106 -0
- package/dist/use-web-authn.d.mts +404 -0
- package/dist/use-web-authn.mjs +323 -0
- package/dist/use-web-locks.d.mts +180 -0
- package/dist/use-web-locks.mjs +136 -0
- package/dist/use-web-midi.d.mts +148 -0
- package/dist/use-web-midi.mjs +140 -0
- package/dist/use-web-vitals.d.mts +142 -0
- package/dist/use-web-vitals.mjs +248 -0
- package/dist/use-websocket.d.mts +218 -0
- package/dist/use-websocket.mjs +257 -0
- package/dist/use-worker-fn.d.mts +119 -0
- package/dist/use-worker-fn.mjs +162 -0
- package/dist/virtual-list.d.mts +105 -0
- package/dist/virtual-list.mjs +128 -0
- package/dist/watch-debounced.d.mts +84 -0
- package/dist/watch-debounced.mjs +84 -0
- package/dist/watch-ignorable.d.mts +47 -0
- package/dist/watch-ignorable.mjs +61 -0
- package/dist/watch-once.d.mts +29 -0
- package/dist/watch-once.mjs +10 -0
- package/dist/watch-pausable.d.mts +51 -0
- package/dist/watch-pausable.mjs +23 -0
- package/dist/watch-source.d.mts +29 -0
- package/dist/watch-source.mjs +1 -0
- package/dist/watch-throttled.d.mts +70 -0
- package/dist/watch-throttled.mjs +94 -0
- package/dist/whenever.d.mts +39 -0
- package/dist/whenever.mjs +41 -0
- package/dist/window-size.d.mts +87 -0
- package/dist/window-size.mjs +65 -0
- package/package.json +846 -5
- package/registry/files/abort-signal.ts +292 -0
- package/registry/files/active-element.ts +93 -0
- package/registry/files/animate.ts +322 -0
- package/registry/files/async-resource.ts +190 -0
- package/registry/files/battery.ts +166 -0
- package/registry/files/breakpoints.ts +166 -0
- package/registry/files/capability.ts +171 -0
- package/registry/files/color-mode.ts +274 -0
- package/registry/files/computed-async.ts +123 -0
- package/registry/files/computed-with-control.ts +80 -0
- package/registry/files/create-event-hook.ts +139 -0
- package/registry/files/create-global-state.ts +34 -0
- package/registry/files/create-injection-state.ts +75 -0
- package/registry/files/create-shared-composable.ts +74 -0
- package/registry/files/device-motion.ts +152 -0
- package/registry/files/device-orientation.ts +168 -0
- package/registry/files/device-pixel-ratio.ts +100 -0
- package/registry/files/disposal-scope.ts +201 -0
- package/registry/files/document-visibility.ts +152 -0
- package/registry/files/draggable.ts +273 -0
- package/registry/files/element-bounding.ts +175 -0
- package/registry/files/element-by-point.ts +149 -0
- package/registry/files/element-hover.ts +104 -0
- package/registry/files/element-ref.ts +58 -0
- package/registry/files/element-target.ts +99 -0
- package/registry/files/event-listener.ts +188 -0
- package/registry/files/focus.ts +181 -0
- package/registry/files/fps.ts +133 -0
- package/registry/files/geolocation.ts +214 -0
- package/registry/files/i18n.ts +524 -0
- package/registry/files/icu-message.ts +701 -0
- package/registry/files/idle.ts +176 -0
- package/registry/files/infinite-scroll.ts +135 -0
- package/registry/files/intersection-observer.ts +261 -0
- package/registry/files/locale.ts +148 -0
- package/registry/files/magic-keys.ts +298 -0
- package/registry/files/math.ts +175 -0
- package/registry/files/media-query.ts +102 -0
- package/registry/files/mouse-in-element.ts +107 -0
- package/registry/files/mouse.ts +167 -0
- package/registry/files/mutation-observer.ts +183 -0
- package/registry/files/network.ts +229 -0
- package/registry/files/on-click-outside.ts +178 -0
- package/registry/files/on-key-stroke.ts +135 -0
- package/registry/files/on-long-press.ts +188 -0
- package/registry/files/on-start-typing.ts +88 -0
- package/registry/files/page-leave.ts +57 -0
- package/registry/files/parent-element.ts +29 -0
- package/registry/files/pinch.ts +187 -0
- package/registry/files/pointer-lock.ts +232 -0
- package/registry/files/pointer.ts +153 -0
- package/registry/files/preferences.ts +98 -0
- package/registry/files/preferred-languages.ts +88 -0
- package/registry/files/reactify.ts +39 -0
- package/registry/files/ref-auto-reset.ts +102 -0
- package/registry/files/ref-debounced.ts +34 -0
- package/registry/files/ref-default.ts +35 -0
- package/registry/files/resize-observer.ts +220 -0
- package/registry/files/retry-async.ts +261 -0
- package/registry/files/retry-delay.ts +132 -0
- package/registry/files/scope.ts +21 -0
- package/registry/files/screen-orientation.ts +165 -0
- package/registry/files/scroll-lock.ts +80 -0
- package/registry/files/scroll.ts +338 -0
- package/registry/files/standard-schema.ts +163 -0
- package/registry/files/swipe.ts +321 -0
- package/registry/files/sync-ref.ts +166 -0
- package/registry/files/temporal.ts +182 -0
- package/registry/files/text-selection.ts +110 -0
- package/registry/files/textarea-autosize.ts +114 -0
- package/registry/files/timeout-scheduler.ts +16 -0
- package/registry/files/to-reactive.ts +44 -0
- package/registry/files/transition.ts +271 -0
- package/registry/files/until.ts +352 -0
- package/registry/files/use-array.ts +201 -0
- package/registry/files/use-async-queue.ts +278 -0
- package/registry/files/use-async-state.ts +139 -0
- package/registry/files/use-barcode-detector.ts +321 -0
- package/registry/files/use-bluetooth.ts +409 -0
- package/registry/files/use-broadcast-channel.ts +250 -0
- package/registry/files/use-builtin-ai.ts +674 -0
- package/registry/files/use-clipboard.ts +425 -0
- package/registry/files/use-compression-stream.ts +364 -0
- package/registry/files/use-confirm-dialog.ts +137 -0
- package/registry/files/use-contact-picker.ts +246 -0
- package/registry/files/use-cookie.ts +500 -0
- package/registry/files/use-countdown.ts +161 -0
- package/registry/files/use-counter.ts +147 -0
- package/registry/files/use-css-var.ts +191 -0
- package/registry/files/use-cycle-list.ts +136 -0
- package/registry/files/use-date-format.ts +281 -0
- package/registry/files/use-date-time-format.ts +113 -0
- package/registry/files/use-debounced.ts +163 -0
- package/registry/files/use-display-media.ts +89 -0
- package/registry/files/use-display-names.ts +122 -0
- package/registry/files/use-document-title.ts +196 -0
- package/registry/files/use-drop-zone.ts +287 -0
- package/registry/files/use-event-source.ts +470 -0
- package/registry/files/use-eye-dropper.ts +134 -0
- package/registry/files/use-favicon.ts +140 -0
- package/registry/files/use-fetch.ts +578 -0
- package/registry/files/use-field.ts +247 -0
- package/registry/files/use-file-dialog.ts +257 -0
- package/registry/files/use-file-system-access.ts +383 -0
- package/registry/files/use-form-field-props.ts +381 -0
- package/registry/files/use-form.ts +980 -0
- package/registry/files/use-fullscreen.ts +214 -0
- package/registry/files/use-gamepad.ts +463 -0
- package/registry/files/use-hid.ts +359 -0
- package/registry/files/use-history.ts +231 -0
- package/registry/files/use-id-generator.ts +61 -0
- package/registry/files/use-image.ts +253 -0
- package/registry/files/use-indexed-db.ts +508 -0
- package/registry/files/use-interval.ts +253 -0
- package/registry/files/use-list-format.ts +85 -0
- package/registry/files/use-machine.ts +171 -0
- package/registry/files/use-map.ts +145 -0
- package/registry/files/use-media-controls.ts +545 -0
- package/registry/files/use-memoize.ts +118 -0
- package/registry/files/use-mounted.ts +30 -0
- package/registry/files/use-navigation-api.ts +641 -0
- package/registry/files/use-notification.ts +285 -0
- package/registry/files/use-now.ts +194 -0
- package/registry/files/use-number-format.ts +120 -0
- package/registry/files/use-object-url.ts +87 -0
- package/registry/files/use-offset-pagination.ts +168 -0
- package/registry/files/use-payment-request.ts +465 -0
- package/registry/files/use-performance-observer.ts +469 -0
- package/registry/files/use-permission.ts +220 -0
- package/registry/files/use-plural-rules.ts +134 -0
- package/registry/files/use-previous.ts +62 -0
- package/registry/files/use-push-subscription.ts +352 -0
- package/registry/files/use-queue.ts +197 -0
- package/registry/files/use-raf-fn.ts +176 -0
- package/registry/files/use-relative-time-format.ts +201 -0
- package/registry/files/use-request-idle-callback.ts +278 -0
- package/registry/files/use-route-query.ts +300 -0
- package/registry/files/use-scheduler-post-task.ts +397 -0
- package/registry/files/use-screen-details.ts +393 -0
- package/registry/files/use-script-tag.ts +341 -0
- package/registry/files/use-segmenter.ts +147 -0
- package/registry/files/use-selection.ts +233 -0
- package/registry/files/use-serial.ts +404 -0
- package/registry/files/use-service-worker.ts +413 -0
- package/registry/files/use-set.ts +154 -0
- package/registry/files/use-share.ts +168 -0
- package/registry/files/use-sorted-locale.ts +130 -0
- package/registry/files/use-sorted.ts +49 -0
- package/registry/files/use-speech-recognition.ts +357 -0
- package/registry/files/use-speech-synthesis.ts +333 -0
- package/registry/files/use-stack.ts +164 -0
- package/registry/files/use-stepper.ts +166 -0
- package/registry/files/use-storage-estimate.ts +352 -0
- package/registry/files/use-storage.ts +635 -0
- package/registry/files/use-style-tag.ts +200 -0
- package/registry/files/use-supported.ts +26 -0
- package/registry/files/use-throttled.ts +215 -0
- package/registry/files/use-time-ago.ts +276 -0
- package/registry/files/use-timeout.ts +218 -0
- package/registry/files/use-toggle.ts +54 -0
- package/registry/files/use-url-hash.ts +280 -0
- package/registry/files/use-url-search-params.ts +497 -0
- package/registry/files/use-usb.ts +395 -0
- package/registry/files/use-user-activation.ts +215 -0
- package/registry/files/use-user-media.ts +422 -0
- package/registry/files/use-v-model.ts +210 -0
- package/registry/files/use-vibrate.ts +174 -0
- package/registry/files/use-view-transition.ts +229 -0
- package/registry/files/use-visual-viewport.ts +228 -0
- package/registry/files/use-wake-lock.ts +206 -0
- package/registry/files/use-web-authn.ts +793 -0
- package/registry/files/use-web-locks.ts +363 -0
- package/registry/files/use-web-midi.ts +306 -0
- package/registry/files/use-web-vitals.ts +409 -0
- package/registry/files/use-websocket.ts +553 -0
- package/registry/files/use-worker-fn.ts +306 -0
- package/registry/files/virtual-list.ts +230 -0
- package/registry/files/watch-debounced.ts +206 -0
- package/registry/files/watch-ignorable.ts +128 -0
- package/registry/files/watch-once.ts +46 -0
- package/registry/files/watch-pausable.ts +93 -0
- package/registry/files/watch-source.ts +51 -0
- package/registry/files/watch-throttled.ts +201 -0
- package/registry/files/whenever.ts +70 -0
- package/registry/files/window-size.ts +151 -0
- package/registry/registry.json +5792 -0
- package/dist/catalog-D2AL3xYl.d.mts +0 -523
- package/dist/catalog-D5SYCsgW.mjs +0 -549
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import {
|
|
2
|
+
hasInjectionContext,
|
|
3
|
+
readonly,
|
|
4
|
+
ref,
|
|
5
|
+
shallowRef,
|
|
6
|
+
toValue,
|
|
7
|
+
watch,
|
|
8
|
+
watchPostEffect,
|
|
9
|
+
} from "vue";
|
|
10
|
+
import type { MaybeRefOrGetter, Ref } from "vue";
|
|
11
|
+
|
|
12
|
+
import { tryOnScopeDispose } from "./scope.ts";
|
|
13
|
+
|
|
14
|
+
/** Effective connection classes reported by the Network Information API. */
|
|
15
|
+
export type NetworkEffectiveType = "slow-2g" | "2g" | "3g" | "4g";
|
|
16
|
+
|
|
17
|
+
/** Physical connection types reported by the Network Information API. */
|
|
18
|
+
export type NetworkConnectionType =
|
|
19
|
+
| "bluetooth"
|
|
20
|
+
| "cellular"
|
|
21
|
+
| "ethernet"
|
|
22
|
+
| "none"
|
|
23
|
+
| "wifi"
|
|
24
|
+
| "wimax"
|
|
25
|
+
| "other"
|
|
26
|
+
| "unknown";
|
|
27
|
+
|
|
28
|
+
/** Subset of the (non-standard) `NetworkInformation` interface. */
|
|
29
|
+
export interface NetworkInformationLike extends EventTarget {
|
|
30
|
+
/** Estimated downlink bandwidth in Mbit/s. */
|
|
31
|
+
readonly downlink?: number;
|
|
32
|
+
/** Maximum downlink bandwidth in Mbit/s. */
|
|
33
|
+
readonly downlinkMax?: number;
|
|
34
|
+
/** Effective connection class. */
|
|
35
|
+
readonly effectiveType?: string;
|
|
36
|
+
/** Estimated round-trip time in milliseconds. */
|
|
37
|
+
readonly rtt?: number;
|
|
38
|
+
/** Whether the user requested reduced data usage. */
|
|
39
|
+
readonly saveData?: boolean;
|
|
40
|
+
/** Physical connection type. */
|
|
41
|
+
readonly type?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Window-like capability observed by the network composables. */
|
|
45
|
+
export interface NetworkHost extends EventTarget {
|
|
46
|
+
/** Navigator exposing connectivity. */
|
|
47
|
+
readonly navigator: {
|
|
48
|
+
/** Whether the browser believes it is online. */
|
|
49
|
+
readonly onLine: boolean;
|
|
50
|
+
/** Network Information API object, where supported. */
|
|
51
|
+
readonly connection?: NetworkInformationLike;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Options shared by {@link useOnline} and {@link useNetwork}. */
|
|
56
|
+
export interface UseNetworkOptions {
|
|
57
|
+
/**
|
|
58
|
+
* Connectivity exposed during server rendering.
|
|
59
|
+
*
|
|
60
|
+
* @default true
|
|
61
|
+
*/
|
|
62
|
+
readonly ssrOnline?: boolean;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Reactive window capability for alternate runtimes and tests.
|
|
66
|
+
*
|
|
67
|
+
* @default globalThis.window when available
|
|
68
|
+
*/
|
|
69
|
+
readonly host?: MaybeRefOrGetter<NetworkHost | null | undefined>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Reactive network state returned by {@link useNetwork}. */
|
|
73
|
+
export interface NetworkControls {
|
|
74
|
+
/** Whether the Network Information API is available. `false` during server rendering. */
|
|
75
|
+
readonly isSupported: Readonly<Ref<boolean>>;
|
|
76
|
+
/** Whether the browser reports being online. */
|
|
77
|
+
readonly isOnline: Readonly<Ref<boolean>>;
|
|
78
|
+
/** Epoch milliseconds of the latest `online` event. */
|
|
79
|
+
readonly onlineAt: Readonly<Ref<number | null>>;
|
|
80
|
+
/** Epoch milliseconds of the latest `offline` event. */
|
|
81
|
+
readonly offlineAt: Readonly<Ref<number | null>>;
|
|
82
|
+
/** Estimated downlink in Mbit/s. */
|
|
83
|
+
readonly downlink: Readonly<Ref<number | null>>;
|
|
84
|
+
/** Maximum downlink in Mbit/s. */
|
|
85
|
+
readonly downlinkMax: Readonly<Ref<number | null>>;
|
|
86
|
+
/** Effective connection class, or `null` when unknown. */
|
|
87
|
+
readonly effectiveType: Readonly<Ref<NetworkEffectiveType | null>>;
|
|
88
|
+
/** Estimated round-trip time in milliseconds. */
|
|
89
|
+
readonly rtt: Readonly<Ref<number | null>>;
|
|
90
|
+
/** Whether the user requested reduced data usage. */
|
|
91
|
+
readonly saveData: Readonly<Ref<boolean>>;
|
|
92
|
+
/** Physical connection type, or `null` when unknown. */
|
|
93
|
+
readonly type: Readonly<Ref<NetworkConnectionType | null>>;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Track connectivity and connection quality.
|
|
98
|
+
*
|
|
99
|
+
* Listens for `online`/`offline` on the window and `change` on
|
|
100
|
+
* `navigator.connection` where available. Unknown or future enum values
|
|
101
|
+
* normalize to `null` so the public unions stay closed. Server renders
|
|
102
|
+
* report `ssrOnline` with every quality metric `null`. Inside a component
|
|
103
|
+
* the connection is read after mounting, so hydration renders the server
|
|
104
|
+
* values first. Listeners are removed with the owning reactive scope.
|
|
105
|
+
*
|
|
106
|
+
* @param options Server fallback and window capability.
|
|
107
|
+
* @default options {}
|
|
108
|
+
* @returns Reactive connectivity and connection metrics.
|
|
109
|
+
*/
|
|
110
|
+
export function useNetwork(options: UseNetworkOptions = {}): NetworkControls {
|
|
111
|
+
const ssrOnline = options.ssrOnline ?? true;
|
|
112
|
+
const isSupported = ref(false);
|
|
113
|
+
const isOnline = ref(ssrOnline);
|
|
114
|
+
const onlineAt = ref<number | null>(null);
|
|
115
|
+
const offlineAt = ref<number | null>(null);
|
|
116
|
+
const downlink = ref<number | null>(null);
|
|
117
|
+
const downlinkMax = ref<number | null>(null);
|
|
118
|
+
const effectiveType = ref<NetworkEffectiveType | null>(null);
|
|
119
|
+
const rtt = ref<number | null>(null);
|
|
120
|
+
const saveData = ref(false);
|
|
121
|
+
const type = ref<NetworkConnectionType | null>(null);
|
|
122
|
+
// Inside a component the host is attached by a post-flush job (after the
|
|
123
|
+
// component mounted), so a hydrating client first renders the same server
|
|
124
|
+
// fallback. Outside components it is attached synchronously.
|
|
125
|
+
const hydrated = shallowRef(!hasInjectionContext());
|
|
126
|
+
if (!hydrated.value) {
|
|
127
|
+
watchPostEffect(() => {
|
|
128
|
+
hydrated.value = true;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const stop = watch(
|
|
133
|
+
() =>
|
|
134
|
+
hydrated.value
|
|
135
|
+
? options.host === undefined
|
|
136
|
+
? browserNetworkHost()
|
|
137
|
+
: toValue(options.host)
|
|
138
|
+
: undefined,
|
|
139
|
+
(host, _previous, onCleanup) => {
|
|
140
|
+
if (!host) {
|
|
141
|
+
isSupported.value = false;
|
|
142
|
+
isOnline.value = ssrOnline;
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const connection = host.navigator.connection;
|
|
146
|
+
isSupported.value = connection !== undefined;
|
|
147
|
+
const readConnection = (): void => {
|
|
148
|
+
isOnline.value = host.navigator.onLine;
|
|
149
|
+
if (!connection) return;
|
|
150
|
+
downlink.value = connection.downlink ?? null;
|
|
151
|
+
downlinkMax.value = connection.downlinkMax ?? null;
|
|
152
|
+
effectiveType.value = toEffectiveType(connection.effectiveType);
|
|
153
|
+
rtt.value = connection.rtt ?? null;
|
|
154
|
+
saveData.value = connection.saveData ?? false;
|
|
155
|
+
type.value = toConnectionType(connection.type);
|
|
156
|
+
};
|
|
157
|
+
const onOnline = (): void => {
|
|
158
|
+
onlineAt.value = Date.now();
|
|
159
|
+
readConnection();
|
|
160
|
+
};
|
|
161
|
+
const onOffline = (): void => {
|
|
162
|
+
offlineAt.value = Date.now();
|
|
163
|
+
readConnection();
|
|
164
|
+
};
|
|
165
|
+
readConnection();
|
|
166
|
+
host.addEventListener("online", onOnline, { passive: true });
|
|
167
|
+
host.addEventListener("offline", onOffline, { passive: true });
|
|
168
|
+
connection?.addEventListener("change", readConnection, { passive: true });
|
|
169
|
+
onCleanup(() => {
|
|
170
|
+
host.removeEventListener("online", onOnline);
|
|
171
|
+
host.removeEventListener("offline", onOffline);
|
|
172
|
+
connection?.removeEventListener("change", readConnection);
|
|
173
|
+
});
|
|
174
|
+
},
|
|
175
|
+
{ immediate: true },
|
|
176
|
+
);
|
|
177
|
+
tryOnScopeDispose(() => stop.stop());
|
|
178
|
+
|
|
179
|
+
return {
|
|
180
|
+
isSupported: readonly(isSupported),
|
|
181
|
+
isOnline: readonly(isOnline),
|
|
182
|
+
onlineAt: readonly(onlineAt),
|
|
183
|
+
offlineAt: readonly(offlineAt),
|
|
184
|
+
downlink: readonly(downlink),
|
|
185
|
+
downlinkMax: readonly(downlinkMax),
|
|
186
|
+
effectiveType: readonly(effectiveType),
|
|
187
|
+
rtt: readonly(rtt),
|
|
188
|
+
saveData: readonly(saveData),
|
|
189
|
+
type: readonly(type),
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Track whether the browser reports being online.
|
|
195
|
+
*
|
|
196
|
+
* Shorthand for `useNetwork(options).isOnline` with the same SSR fallback
|
|
197
|
+
* and cleanup semantics.
|
|
198
|
+
*
|
|
199
|
+
* @param options Server fallback and window capability.
|
|
200
|
+
* @default options {}
|
|
201
|
+
* @returns Readonly online flag.
|
|
202
|
+
*/
|
|
203
|
+
export function useOnline(options: UseNetworkOptions = {}): Readonly<Ref<boolean>> {
|
|
204
|
+
return useNetwork(options).isOnline;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function toEffectiveType(value: string | undefined): NetworkEffectiveType | null {
|
|
208
|
+
return value === "slow-2g" || value === "2g" || value === "3g" || value === "4g" ? value : null;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function toConnectionType(value: string | undefined): NetworkConnectionType | null {
|
|
212
|
+
switch (value) {
|
|
213
|
+
case "bluetooth":
|
|
214
|
+
case "cellular":
|
|
215
|
+
case "ethernet":
|
|
216
|
+
case "none":
|
|
217
|
+
case "wifi":
|
|
218
|
+
case "wimax":
|
|
219
|
+
case "other":
|
|
220
|
+
case "unknown":
|
|
221
|
+
return value;
|
|
222
|
+
default:
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function browserNetworkHost(): NetworkHost | undefined {
|
|
228
|
+
return typeof window !== "undefined" ? window : undefined;
|
|
229
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { toValue } from "vue";
|
|
2
|
+
import type { MaybeRefOrGetter } from "vue";
|
|
3
|
+
|
|
4
|
+
import { resolveElement } from "./element-target.ts";
|
|
5
|
+
import type { MaybeElementTarget } from "./element-target.ts";
|
|
6
|
+
import { tryOnScopeDispose } from "./scope.ts";
|
|
7
|
+
import type { TimeoutScheduler } from "./timeout-scheduler.ts";
|
|
8
|
+
|
|
9
|
+
/** Window-like capability observed by {@link onClickOutside}. */
|
|
10
|
+
export interface ClickOutsideHost extends EventTarget {
|
|
11
|
+
/** Document used to detect focus moving into an iframe. */
|
|
12
|
+
readonly document: { readonly activeElement: Element | null };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Ignore entry: an element target or a CSS selector matched against the event path. */
|
|
16
|
+
export type ClickOutsideIgnore = MaybeElementTarget | string;
|
|
17
|
+
|
|
18
|
+
/** Options for {@link onClickOutside}. */
|
|
19
|
+
export interface OnClickOutsideOptions {
|
|
20
|
+
/**
|
|
21
|
+
* Elements (or selectors) whose clicks never count as outside, e.g. the
|
|
22
|
+
* button that toggles a popover.
|
|
23
|
+
*
|
|
24
|
+
* @default []
|
|
25
|
+
*/
|
|
26
|
+
readonly ignore?: MaybeRefOrGetter<readonly ClickOutsideIgnore[]>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Listen in the capture phase so `stopPropagation()` inside the page
|
|
30
|
+
* cannot hide outside clicks.
|
|
31
|
+
*
|
|
32
|
+
* @default true
|
|
33
|
+
*/
|
|
34
|
+
readonly capture?: boolean;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Treat focus moving into an `<iframe>` outside the target as an outside
|
|
38
|
+
* click (iframes swallow pointer events).
|
|
39
|
+
*
|
|
40
|
+
* @default false
|
|
41
|
+
*/
|
|
42
|
+
readonly detectIframe?: boolean;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Owns the zero-delay timer used for iframe detection.
|
|
46
|
+
*
|
|
47
|
+
* @default globalThis timer functions
|
|
48
|
+
*/
|
|
49
|
+
readonly scheduler?: TimeoutScheduler;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Reactive window capability for alternate runtimes and tests.
|
|
53
|
+
*
|
|
54
|
+
* @default globalThis.window when available
|
|
55
|
+
*/
|
|
56
|
+
readonly host?: MaybeRefOrGetter<ClickOutsideHost | null | undefined>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const defaultScheduler: TimeoutScheduler = {
|
|
60
|
+
setTimeout: (callback, delayMs) => globalThis.setTimeout(callback, delayMs),
|
|
61
|
+
clearTimeout: (handle) => {
|
|
62
|
+
globalThis.clearTimeout(handle as ReturnType<typeof setTimeout>);
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Call a handler when the user clicks (or focuses an iframe) outside an element.
|
|
68
|
+
*
|
|
69
|
+
* A click counts as outside only when its `pointerdown` also started outside
|
|
70
|
+
* the target, so drags that begin inside (e.g. text selection) and end
|
|
71
|
+
* outside are ignored. Event paths (`composedPath()`) make shadow-DOM targets
|
|
72
|
+
* work. The host is resolved once, when called. Nothing is registered
|
|
73
|
+
* during server rendering; listeners are removed with the owning scope or by
|
|
74
|
+
* the returned stop function.
|
|
75
|
+
*
|
|
76
|
+
* @param target Reactive element target.
|
|
77
|
+
* @param handler Called with the outside `PointerEvent`/`MouseEvent` or `FocusEvent`.
|
|
78
|
+
* @param options Ignore list, phase, iframe detection, and capabilities.
|
|
79
|
+
* @default options {}
|
|
80
|
+
* @returns Stop function.
|
|
81
|
+
*/
|
|
82
|
+
export function onClickOutside(
|
|
83
|
+
target: MaybeElementTarget,
|
|
84
|
+
handler: (event: Event) => void,
|
|
85
|
+
options: OnClickOutsideOptions = {},
|
|
86
|
+
): () => void {
|
|
87
|
+
const host = options.host === undefined ? browserClickHost() : toValue(options.host);
|
|
88
|
+
if (!host) return () => undefined;
|
|
89
|
+
const capture = options.capture ?? true;
|
|
90
|
+
const scheduler = options.scheduler ?? defaultScheduler;
|
|
91
|
+
let startedInside = false;
|
|
92
|
+
let pendingBlur: unknown;
|
|
93
|
+
let hasPendingBlur = false;
|
|
94
|
+
|
|
95
|
+
const pathOf = (event: Event): readonly EventTarget[] => {
|
|
96
|
+
const path = typeof event.composedPath === "function" ? event.composedPath() : [];
|
|
97
|
+
return path.length > 0 ? path : event.target ? [event.target] : [];
|
|
98
|
+
};
|
|
99
|
+
const isIgnored = (event: Event): boolean => {
|
|
100
|
+
const path = pathOf(event);
|
|
101
|
+
for (const entry of toValue(options.ignore) ?? []) {
|
|
102
|
+
if (typeof entry === "string") {
|
|
103
|
+
if (path.some((node) => matchesSelector(node, entry))) return true;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
const element = resolveElement(entry);
|
|
107
|
+
if (element && path.some((node) => node === element || containsNode(element, node))) {
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return false;
|
|
112
|
+
};
|
|
113
|
+
const isInside = (event: Event): boolean => {
|
|
114
|
+
const element = resolveElement(target);
|
|
115
|
+
if (!element) return true;
|
|
116
|
+
return pathOf(event).some((node) => node === element || containsNode(element, node));
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const onPointerDown = (event: Event): void => {
|
|
120
|
+
startedInside = isInside(event) || isIgnored(event);
|
|
121
|
+
};
|
|
122
|
+
const onClick = (event: Event): void => {
|
|
123
|
+
const inside = isInside(event) || isIgnored(event);
|
|
124
|
+
const began = startedInside;
|
|
125
|
+
startedInside = false;
|
|
126
|
+
if (inside || began) return;
|
|
127
|
+
handler(event);
|
|
128
|
+
};
|
|
129
|
+
const onBlur = (event: Event): void => {
|
|
130
|
+
if (hasPendingBlur) scheduler.clearTimeout(pendingBlur);
|
|
131
|
+
hasPendingBlur = true;
|
|
132
|
+
pendingBlur = scheduler.setTimeout(() => {
|
|
133
|
+
hasPendingBlur = false;
|
|
134
|
+
const active = host.document.activeElement;
|
|
135
|
+
const element = resolveElement(target);
|
|
136
|
+
if (active?.tagName === "IFRAME" && element && !containsNode(element, active)) {
|
|
137
|
+
handler(event);
|
|
138
|
+
}
|
|
139
|
+
}, 0);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
host.addEventListener("pointerdown", onPointerDown, { capture, passive: true });
|
|
143
|
+
host.addEventListener("click", onClick, { capture, passive: true });
|
|
144
|
+
if (options.detectIframe) host.addEventListener("blur", onBlur);
|
|
145
|
+
|
|
146
|
+
let stopped = false;
|
|
147
|
+
const stop = (): void => {
|
|
148
|
+
if (stopped) return;
|
|
149
|
+
stopped = true;
|
|
150
|
+
host.removeEventListener("pointerdown", onPointerDown, { capture });
|
|
151
|
+
host.removeEventListener("click", onClick, { capture });
|
|
152
|
+
host.removeEventListener("blur", onBlur);
|
|
153
|
+
if (hasPendingBlur) scheduler.clearTimeout(pendingBlur);
|
|
154
|
+
};
|
|
155
|
+
tryOnScopeDispose(stop);
|
|
156
|
+
return stop;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function containsNode(element: Element, node: EventTarget): boolean {
|
|
160
|
+
return typeof element.contains === "function" && isNodeLike(node) && element.contains(node);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function isNodeLike(value: EventTarget): value is Node {
|
|
164
|
+
return "nodeType" in value;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function matchesSelector(node: EventTarget, selector: string): boolean {
|
|
168
|
+
if (!("matches" in node) || typeof node.matches !== "function") return false;
|
|
169
|
+
try {
|
|
170
|
+
return node.matches(selector) === true;
|
|
171
|
+
} catch {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function browserClickHost(): ClickOutsideHost | undefined {
|
|
177
|
+
return typeof window !== "undefined" ? window : undefined;
|
|
178
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { toValue, watch } from "vue";
|
|
2
|
+
import type { MaybeRefOrGetter } from "vue";
|
|
3
|
+
|
|
4
|
+
import { normalizeKeyName } from "./magic-keys.ts";
|
|
5
|
+
import type { KeyFilter } from "./magic-keys.ts";
|
|
6
|
+
import { tryOnScopeDispose } from "./scope.ts";
|
|
7
|
+
|
|
8
|
+
/** Keyboard event names accepted by {@link onKeyStroke}. */
|
|
9
|
+
export type KeyStrokeEventName = "keydown" | "keyup" | "keypress";
|
|
10
|
+
|
|
11
|
+
/** Options for {@link onKeyStroke}. */
|
|
12
|
+
export interface OnKeyStrokeOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Keyboard event to listen for.
|
|
15
|
+
*
|
|
16
|
+
* @default "keydown"
|
|
17
|
+
*/
|
|
18
|
+
readonly eventName?: KeyStrokeEventName;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Event target.
|
|
22
|
+
*
|
|
23
|
+
* @default globalThis.window when available
|
|
24
|
+
*/
|
|
25
|
+
readonly target?: MaybeRefOrGetter<EventTarget | null | undefined>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Register a passive listener (the handler then cannot `preventDefault()`).
|
|
29
|
+
*
|
|
30
|
+
* @default false
|
|
31
|
+
*/
|
|
32
|
+
readonly passive?: boolean;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Ignore auto-repeated `keydown` events while a key is held.
|
|
36
|
+
*
|
|
37
|
+
* @default false
|
|
38
|
+
*/
|
|
39
|
+
readonly dedupe?: MaybeRefOrGetter<boolean>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Run a handler when matching keys are pressed.
|
|
44
|
+
*
|
|
45
|
+
* `key` accepts a name, a list of names (normalized like combos, so `"esc"`
|
|
46
|
+
* matches `Escape` and `"a"` matches `KeyA`), a predicate, or `true` for every
|
|
47
|
+
* key. The listener follows the reactive target and is removed with the
|
|
48
|
+
* owning scope or the returned stop function; nothing is registered during
|
|
49
|
+
* server rendering.
|
|
50
|
+
*
|
|
51
|
+
* @param key Key filter, or `true` for any key.
|
|
52
|
+
* @param handler Called with the matching `KeyboardEvent`.
|
|
53
|
+
* @param options Event name, target, passivity, and dedupe.
|
|
54
|
+
* @default options {}
|
|
55
|
+
* @returns Stop function.
|
|
56
|
+
*/
|
|
57
|
+
export function onKeyStroke(
|
|
58
|
+
key: KeyFilter | true,
|
|
59
|
+
handler: (event: KeyboardEvent) => void,
|
|
60
|
+
options: OnKeyStrokeOptions = {},
|
|
61
|
+
): () => void {
|
|
62
|
+
const eventName = options.eventName ?? "keydown";
|
|
63
|
+
const names =
|
|
64
|
+
key === true || typeof key === "function"
|
|
65
|
+
? undefined
|
|
66
|
+
: new Set((typeof key === "string" ? [key] : key).map((name) => normalizeKeyName(name)));
|
|
67
|
+
const matches = (event: KeyboardEvent): boolean => {
|
|
68
|
+
if (key === true) return true;
|
|
69
|
+
if (typeof key === "function") return key(event);
|
|
70
|
+
return (
|
|
71
|
+
names !== undefined &&
|
|
72
|
+
(names.has(normalizeKeyName(event.key)) || names.has(normalizeKeyName(event.code)))
|
|
73
|
+
);
|
|
74
|
+
};
|
|
75
|
+
const listener = (event: Event): void => {
|
|
76
|
+
if (!isKeyboardEvent(event)) return;
|
|
77
|
+
if (event.repeat && toValue(options.dedupe)) return;
|
|
78
|
+
if (matches(event)) handler(event);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const stop = watch(
|
|
82
|
+
() => (options.target === undefined ? browserWindow() : toValue(options.target)),
|
|
83
|
+
(target, _previous, onCleanup) => {
|
|
84
|
+
if (!target) return;
|
|
85
|
+
target.addEventListener(eventName, listener, { passive: options.passive ?? false });
|
|
86
|
+
onCleanup(() => target.removeEventListener(eventName, listener));
|
|
87
|
+
},
|
|
88
|
+
{ immediate: true },
|
|
89
|
+
);
|
|
90
|
+
const dispose = (): void => stop.stop();
|
|
91
|
+
tryOnScopeDispose(dispose);
|
|
92
|
+
return dispose;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* {@link onKeyStroke} for `keydown`.
|
|
97
|
+
*
|
|
98
|
+
* @param key Key filter, or `true` for any key.
|
|
99
|
+
* @param handler Called with the matching `KeyboardEvent`.
|
|
100
|
+
* @param options Target, passivity, and dedupe.
|
|
101
|
+
* @default options {}
|
|
102
|
+
* @returns Stop function.
|
|
103
|
+
*/
|
|
104
|
+
export function onKeyDown(
|
|
105
|
+
key: KeyFilter | true,
|
|
106
|
+
handler: (event: KeyboardEvent) => void,
|
|
107
|
+
options: Omit<OnKeyStrokeOptions, "eventName"> = {},
|
|
108
|
+
): () => void {
|
|
109
|
+
return onKeyStroke(key, handler, { ...options, eventName: "keydown" });
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* {@link onKeyStroke} for `keyup`.
|
|
114
|
+
*
|
|
115
|
+
* @param key Key filter, or `true` for any key.
|
|
116
|
+
* @param handler Called with the matching `KeyboardEvent`.
|
|
117
|
+
* @param options Target, passivity, and dedupe.
|
|
118
|
+
* @default options {}
|
|
119
|
+
* @returns Stop function.
|
|
120
|
+
*/
|
|
121
|
+
export function onKeyUp(
|
|
122
|
+
key: KeyFilter | true,
|
|
123
|
+
handler: (event: KeyboardEvent) => void,
|
|
124
|
+
options: Omit<OnKeyStrokeOptions, "eventName"> = {},
|
|
125
|
+
): () => void {
|
|
126
|
+
return onKeyStroke(key, handler, { ...options, eventName: "keyup" });
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function isKeyboardEvent(event: Event): event is KeyboardEvent {
|
|
130
|
+
return "key" in event && "code" in event;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function browserWindow(): EventTarget | undefined {
|
|
134
|
+
return typeof window !== "undefined" ? window : undefined;
|
|
135
|
+
}
|