@vizejs/composable 0.426.3 → 0.427.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,292 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a signal that aborts when the first input signal aborts.
|
|
3
|
+
*
|
|
4
|
+
* The standard `AbortSignal.any()` implementation is used when available.
|
|
5
|
+
* Older runtimes receive an equivalent listener-based implementation that
|
|
6
|
+
* removes every retained listener as soon as the result aborts. The first
|
|
7
|
+
* already-aborted input wins in iteration order, and its exact reason is
|
|
8
|
+
* forwarded. An empty iterable returns a fresh signal that never aborts.
|
|
9
|
+
*
|
|
10
|
+
* This function reads runtime constructors only when called and is safe to
|
|
11
|
+
* import during server rendering. Materializing the iterable happens before
|
|
12
|
+
* listeners are attached, so an iterable that throws cannot leak a partial
|
|
13
|
+
* subscription. If a non-standard signal throws while registering, listeners
|
|
14
|
+
* already attached to earlier inputs are released before the error propagates.
|
|
15
|
+
*
|
|
16
|
+
* @param signals Abort signals to compose; consumed exactly once.
|
|
17
|
+
* @returns A new first-abort-wins signal.
|
|
18
|
+
*/
|
|
19
|
+
export function anyAbortSignal(signals: Iterable<AbortSignal>): AbortSignal {
|
|
20
|
+
const inputs = [...signals];
|
|
21
|
+
const nativeAny = conformantNativeAbortSignalAny();
|
|
22
|
+
if (nativeAny !== undefined) return nativeAny.call(AbortSignal, inputs);
|
|
23
|
+
|
|
24
|
+
const controller = new AbortController();
|
|
25
|
+
const listeners: Array<readonly [AbortSignal, () => void]> = [];
|
|
26
|
+
const cleanup = () => {
|
|
27
|
+
for (const [signal, listener] of listeners) {
|
|
28
|
+
signal.removeEventListener("abort", listener);
|
|
29
|
+
}
|
|
30
|
+
listeners.length = 0;
|
|
31
|
+
};
|
|
32
|
+
const abortFrom = (signal: AbortSignal) => {
|
|
33
|
+
if (controller.signal.aborted) return;
|
|
34
|
+
cleanup();
|
|
35
|
+
controller.abort(signal.reason);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
for (const signal of inputs) {
|
|
39
|
+
if (signal.aborted) {
|
|
40
|
+
abortFrom(signal);
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
const listener = () => abortFrom(signal);
|
|
44
|
+
listeners.push([signal, listener]);
|
|
45
|
+
try {
|
|
46
|
+
signal.addEventListener("abort", listener, { once: true });
|
|
47
|
+
} catch (error) {
|
|
48
|
+
cleanup();
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// A host adapter may change state between the preflight read and listener
|
|
53
|
+
// registration. The second read closes that race without changing native
|
|
54
|
+
// EventTarget behavior.
|
|
55
|
+
if (signal.aborted) {
|
|
56
|
+
abortFrom(signal);
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return controller.signal;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let probedNativeAny: unknown;
|
|
65
|
+
let cachedNativeAny: typeof AbortSignal.any | undefined;
|
|
66
|
+
|
|
67
|
+
/** Resolve the current native implementation only after its first-reason contract passes. */
|
|
68
|
+
function conformantNativeAbortSignalAny(): typeof AbortSignal.any | undefined {
|
|
69
|
+
let candidate: typeof AbortSignal.any | undefined;
|
|
70
|
+
try {
|
|
71
|
+
candidate = Reflect.get(AbortSignal, "any") as typeof AbortSignal.any | undefined;
|
|
72
|
+
} catch {
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
if (candidate === probedNativeAny) return cachedNativeAny;
|
|
76
|
+
|
|
77
|
+
probedNativeAny = candidate;
|
|
78
|
+
cachedNativeAny =
|
|
79
|
+
typeof candidate === "function" && nativeAnyReasonIsStable(candidate) ? candidate : undefined;
|
|
80
|
+
return cachedNativeAny;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Detect runtimes whose combined reason changes when an earlier array member
|
|
85
|
+
* aborts after the winner. The probe deliberately does not read the reason
|
|
86
|
+
* until both inputs abort, catching lazy native implementations as well.
|
|
87
|
+
*/
|
|
88
|
+
function nativeAnyReasonIsStable(candidate: typeof AbortSignal.any): boolean {
|
|
89
|
+
try {
|
|
90
|
+
const late = new AbortController();
|
|
91
|
+
const winner = new AbortController();
|
|
92
|
+
const expected = {};
|
|
93
|
+
const combined = candidate.call(AbortSignal, [late.signal, winner.signal]);
|
|
94
|
+
winner.abort(expected);
|
|
95
|
+
late.abort({});
|
|
96
|
+
return combined.aborted && combined.reason === expected;
|
|
97
|
+
} catch {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Options for {@link timeoutAbortSignal}. */
|
|
103
|
+
export interface TimeoutAbortSignalOptions {
|
|
104
|
+
/**
|
|
105
|
+
* Abort the returned signal early when this parent aborts.
|
|
106
|
+
*
|
|
107
|
+
* @default undefined
|
|
108
|
+
*/
|
|
109
|
+
readonly signal?: AbortSignal;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Reason used when the timeout elapses. Parent cancellation always forwards
|
|
113
|
+
* the parent's reason instead.
|
|
114
|
+
*
|
|
115
|
+
* @default DOMException("The operation timed out.", "TimeoutError")
|
|
116
|
+
*/
|
|
117
|
+
readonly reason?: unknown;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Deterministic or host-specific single-shot timer implementation. Supplying
|
|
121
|
+
* a scheduler selects the compatibility implementation.
|
|
122
|
+
*
|
|
123
|
+
* @default globalThis timer functions
|
|
124
|
+
*/
|
|
125
|
+
readonly scheduler?: TimeoutScheduler;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Options for {@link deadlineAbortSignal}. */
|
|
129
|
+
export interface DeadlineAbortSignalOptions extends TimeoutAbortSignalOptions {
|
|
130
|
+
/**
|
|
131
|
+
* Clock returning Unix epoch milliseconds.
|
|
132
|
+
*
|
|
133
|
+
* @default Date.now
|
|
134
|
+
*/
|
|
135
|
+
readonly now?: () => number;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Create a signal that aborts after a portable, non-negative delay.
|
|
140
|
+
*
|
|
141
|
+
* The native `AbortSignal.timeout()` implementation is used when available
|
|
142
|
+
* and neither a custom scheduler nor a custom reason is supplied. Older
|
|
143
|
+
* runtimes use the same owned-timer path as injected schedulers. Parent
|
|
144
|
+
* cancellation is composed with first-reason-wins semantics. Compatibility
|
|
145
|
+
* scheduling owns exactly one timer and removes its parent listener whenever
|
|
146
|
+
* either source aborts. A zero delay remains asynchronous.
|
|
147
|
+
*
|
|
148
|
+
* The delay must be an integer from `0` through `2_147_483_647`; this common
|
|
149
|
+
* signed 32-bit timer ceiling avoids host-specific clamping. The function
|
|
150
|
+
* accesses timers and abort constructors only when called and is safe to
|
|
151
|
+
* import during server rendering.
|
|
152
|
+
*
|
|
153
|
+
* @param delayMs Delay in milliseconds.
|
|
154
|
+
* @param options Parent signal, timeout reason, and scheduler.
|
|
155
|
+
* @default options {}
|
|
156
|
+
* @throws {RangeError} Tagged `VIZE_COMPOSE_ABORT_TIMEOUT_INVALID_DELAY` when
|
|
157
|
+
* the delay is fractional, negative, non-finite, or exceeds the portable
|
|
158
|
+
* timer ceiling.
|
|
159
|
+
* @returns A new timeout or parent-cancelled signal.
|
|
160
|
+
*/
|
|
161
|
+
export function timeoutAbortSignal(
|
|
162
|
+
delayMs: number,
|
|
163
|
+
options: TimeoutAbortSignalOptions = {},
|
|
164
|
+
): AbortSignal {
|
|
165
|
+
assertPortableTimeout(delayMs);
|
|
166
|
+
|
|
167
|
+
const parent = options.signal;
|
|
168
|
+
if (parent?.aborted) {
|
|
169
|
+
const controller = new AbortController();
|
|
170
|
+
controller.abort(parent.reason);
|
|
171
|
+
return controller.signal;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (
|
|
175
|
+
options.scheduler === undefined &&
|
|
176
|
+
options.reason === undefined &&
|
|
177
|
+
typeof AbortSignal.timeout === "function"
|
|
178
|
+
) {
|
|
179
|
+
const timeout = AbortSignal.timeout(delayMs);
|
|
180
|
+
return options.signal === undefined ? timeout : anyAbortSignal([options.signal, timeout]);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const controller = new AbortController();
|
|
184
|
+
const scheduler = options.scheduler ?? defaultTimeoutScheduler;
|
|
185
|
+
|
|
186
|
+
let handle: unknown;
|
|
187
|
+
let timerPending = true;
|
|
188
|
+
let parentListening = false;
|
|
189
|
+
const stopTimer = () => {
|
|
190
|
+
if (!timerPending) return;
|
|
191
|
+
timerPending = false;
|
|
192
|
+
scheduler.clearTimeout(handle);
|
|
193
|
+
handle = undefined;
|
|
194
|
+
};
|
|
195
|
+
const stopParent = () => {
|
|
196
|
+
if (!parentListening || parent === undefined) return;
|
|
197
|
+
parentListening = false;
|
|
198
|
+
parent.removeEventListener("abort", abortFromParent);
|
|
199
|
+
};
|
|
200
|
+
const abort = (reason: unknown) => {
|
|
201
|
+
if (controller.signal.aborted) return;
|
|
202
|
+
stopTimer();
|
|
203
|
+
stopParent();
|
|
204
|
+
controller.abort(reason);
|
|
205
|
+
};
|
|
206
|
+
const abortFromParent = () => abort(parent?.reason);
|
|
207
|
+
const timeoutReason =
|
|
208
|
+
options.reason === undefined
|
|
209
|
+
? new DOMException("The operation timed out.", "TimeoutError")
|
|
210
|
+
: options.reason;
|
|
211
|
+
|
|
212
|
+
handle = scheduler.setTimeout(() => {
|
|
213
|
+
timerPending = false;
|
|
214
|
+
handle = undefined;
|
|
215
|
+
abort(timeoutReason);
|
|
216
|
+
}, delayMs);
|
|
217
|
+
if (controller.signal.aborted || parent === undefined) return controller.signal;
|
|
218
|
+
|
|
219
|
+
try {
|
|
220
|
+
// Assume registration may have succeeded before a non-standard adapter
|
|
221
|
+
// throws. Removing an absent listener is harmless, while delaying this
|
|
222
|
+
// ownership flag until after registration could leak a partial listener.
|
|
223
|
+
parentListening = true;
|
|
224
|
+
parent.addEventListener("abort", abortFromParent, { once: true });
|
|
225
|
+
if (controller.signal.aborted) {
|
|
226
|
+
parent.removeEventListener("abort", abortFromParent);
|
|
227
|
+
parentListening = false;
|
|
228
|
+
return controller.signal;
|
|
229
|
+
}
|
|
230
|
+
if (parent.aborted) abortFromParent();
|
|
231
|
+
} catch (error) {
|
|
232
|
+
stopParent();
|
|
233
|
+
stopTimer();
|
|
234
|
+
throw error;
|
|
235
|
+
}
|
|
236
|
+
return controller.signal;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Create a timeout signal from an absolute Unix-epoch deadline.
|
|
241
|
+
*
|
|
242
|
+
* Fractional positive differences are rounded up so cancellation never occurs
|
|
243
|
+
* before the requested deadline. Past deadlines become an asynchronous
|
|
244
|
+
* zero-delay timeout. `Date` and numeric deadlines are both accepted.
|
|
245
|
+
*
|
|
246
|
+
* @param deadline Absolute deadline as a `Date` or Unix epoch milliseconds.
|
|
247
|
+
* @param options Clock, parent signal, timeout reason, and scheduler.
|
|
248
|
+
* @default options {}
|
|
249
|
+
* @throws {RangeError} Tagged `VIZE_COMPOSE_ABORT_DEADLINE_INVALID` when the
|
|
250
|
+
* deadline, current clock value, or their positive difference is non-finite
|
|
251
|
+
* or cannot fit the portable timeout range.
|
|
252
|
+
* @returns A new deadline or parent-cancelled signal.
|
|
253
|
+
*/
|
|
254
|
+
export function deadlineAbortSignal(
|
|
255
|
+
deadline: Date | number,
|
|
256
|
+
options: DeadlineAbortSignalOptions = {},
|
|
257
|
+
): AbortSignal {
|
|
258
|
+
const deadlineMs = deadline instanceof Date ? deadline.getTime() : deadline;
|
|
259
|
+
const nowMs = (options.now ?? Date.now)();
|
|
260
|
+
const difference = deadlineMs - nowMs;
|
|
261
|
+
if (
|
|
262
|
+
!Number.isFinite(deadlineMs) ||
|
|
263
|
+
!Number.isFinite(nowMs) ||
|
|
264
|
+
!Number.isFinite(difference) ||
|
|
265
|
+
difference > maximumPortableTimeoutMs
|
|
266
|
+
) {
|
|
267
|
+
throw new RangeError(
|
|
268
|
+
`[VIZE_COMPOSE_ABORT_DEADLINE_INVALID] deadline and now must produce a finite delay from 0 through ${String(maximumPortableTimeoutMs)} milliseconds; received deadline=${String(deadlineMs)}, now=${String(nowMs)}`,
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const { now: _now, ...timeoutOptions } = options;
|
|
273
|
+
return timeoutAbortSignal(Math.ceil(Math.max(0, difference)), timeoutOptions);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function assertPortableTimeout(delayMs: number): void {
|
|
277
|
+
if (!Number.isSafeInteger(delayMs) || delayMs < 0 || delayMs > maximumPortableTimeoutMs) {
|
|
278
|
+
throw new RangeError(
|
|
279
|
+
`[VIZE_COMPOSE_ABORT_TIMEOUT_INVALID_DELAY] delayMs must be an integer from 0 through ${String(maximumPortableTimeoutMs)}; received ${String(delayMs)}`,
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
import type { TimeoutScheduler } from "./timeout-scheduler.ts";
|
|
284
|
+
|
|
285
|
+
const maximumPortableTimeoutMs = 2_147_483_647;
|
|
286
|
+
|
|
287
|
+
const defaultTimeoutScheduler: TimeoutScheduler = {
|
|
288
|
+
setTimeout: (callback, delayMs) => globalThis.setTimeout(callback, delayMs),
|
|
289
|
+
clearTimeout: (handle) => {
|
|
290
|
+
globalThis.clearTimeout(handle as ReturnType<typeof setTimeout>);
|
|
291
|
+
},
|
|
292
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { hasInjectionContext, onMounted, shallowRef, toValue, watch } from "vue";
|
|
2
|
+
import type { MaybeRefOrGetter, ShallowRef } from "vue";
|
|
3
|
+
|
|
4
|
+
import { tryOnScopeDispose } from "./scope.ts";
|
|
5
|
+
|
|
6
|
+
/** Document-like capability observed by {@link useActiveElement}. */
|
|
7
|
+
export interface ActiveElementHost extends EventTarget {
|
|
8
|
+
/** Currently focused element. */
|
|
9
|
+
readonly activeElement: Element | null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Options for {@link useActiveElement}. */
|
|
13
|
+
export interface UseActiveElementOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Descend into open shadow roots to report the innermost focused element.
|
|
16
|
+
*
|
|
17
|
+
* @default true
|
|
18
|
+
*/
|
|
19
|
+
readonly deep?: boolean;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Reactive document capability for alternate runtimes and tests.
|
|
23
|
+
*
|
|
24
|
+
* @default globalThis.document when available
|
|
25
|
+
*/
|
|
26
|
+
readonly host?: MaybeRefOrGetter<ActiveElementHost | null | undefined>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Track the focused element of a document.
|
|
31
|
+
*
|
|
32
|
+
* Listens for capturing `focus`/`blur` events on the document, so focus
|
|
33
|
+
* changes anywhere (including inside shadow trees) update the ref.
|
|
34
|
+
* Server renders expose `null`. Listeners are removed with the owning scope.
|
|
35
|
+
*
|
|
36
|
+
* @param options Shadow-DOM traversal and document capability.
|
|
37
|
+
* @default options {}
|
|
38
|
+
* @returns Readonly shallow ref of the active element.
|
|
39
|
+
*/
|
|
40
|
+
export function useActiveElement(
|
|
41
|
+
options: UseActiveElementOptions = {},
|
|
42
|
+
): Readonly<ShallowRef<Element | null>> {
|
|
43
|
+
const deep = options.deep ?? true;
|
|
44
|
+
const active = shallowRef<Element | null>(null);
|
|
45
|
+
// Inside a component the host is read once it has mounted, so a hydrating
|
|
46
|
+
// client first renders the same fallback as the server. `hasInjectionContext`
|
|
47
|
+
// also detects Vapor components (unlike `getCurrentInstance`).
|
|
48
|
+
const mounted = shallowRef(!hasInjectionContext());
|
|
49
|
+
if (!mounted.value) {
|
|
50
|
+
onMounted(() => {
|
|
51
|
+
mounted.value = true;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const stop = watch(
|
|
56
|
+
() =>
|
|
57
|
+
!mounted.value
|
|
58
|
+
? undefined
|
|
59
|
+
: options.host === undefined
|
|
60
|
+
? browserActiveElementHost()
|
|
61
|
+
: toValue(options.host),
|
|
62
|
+
(host, _previous, onCleanup) => {
|
|
63
|
+
if (!host) {
|
|
64
|
+
active.value = null;
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const update = (): void => {
|
|
68
|
+
active.value = readActive(host.activeElement, deep);
|
|
69
|
+
};
|
|
70
|
+
update();
|
|
71
|
+
host.addEventListener("focus", update, { capture: true, passive: true });
|
|
72
|
+
host.addEventListener("blur", update, { capture: true, passive: true });
|
|
73
|
+
onCleanup(() => {
|
|
74
|
+
host.removeEventListener("focus", update, { capture: true });
|
|
75
|
+
host.removeEventListener("blur", update, { capture: true });
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
{ immediate: true },
|
|
79
|
+
);
|
|
80
|
+
tryOnScopeDispose(() => stop.stop());
|
|
81
|
+
|
|
82
|
+
return active;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function readActive(element: Element | null, deep: boolean): Element | null {
|
|
86
|
+
let current = element;
|
|
87
|
+
while (deep && current?.shadowRoot?.activeElement) current = current.shadowRoot.activeElement;
|
|
88
|
+
return current;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function browserActiveElementHost(): ActiveElementHost | undefined {
|
|
92
|
+
return typeof document !== "undefined" ? document : undefined;
|
|
93
|
+
}
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { computed, readonly, ref, shallowRef, toValue, watch } from "vue";
|
|
2
|
+
import type { MaybeRefOrGetter, Ref, ShallowRef, WritableComputedRef } 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
|
+
|
|
8
|
+
/** CSS property names (camelCase) that accept string values on `CSSStyleDeclaration`. */
|
|
9
|
+
export type AnimatableCssProperty = {
|
|
10
|
+
[Key in keyof CSSStyleDeclaration]: Key extends string
|
|
11
|
+
? CSSStyleDeclaration[Key] extends string
|
|
12
|
+
? Key
|
|
13
|
+
: never
|
|
14
|
+
: never;
|
|
15
|
+
}[keyof CSSStyleDeclaration];
|
|
16
|
+
|
|
17
|
+
type KeyframeProperty = Exclude<AnimatableCssProperty, "offset" | "cssText">;
|
|
18
|
+
|
|
19
|
+
/** Keyframe whose property names are checked against `CSSStyleDeclaration`. */
|
|
20
|
+
export type TypedKeyframe = {
|
|
21
|
+
readonly [Key in KeyframeProperty]?: string | number | null;
|
|
22
|
+
} & {
|
|
23
|
+
/** Position of the keyframe in `[0, 1]`. */
|
|
24
|
+
readonly offset?: number | null;
|
|
25
|
+
/** Easing applied from this keyframe to the next. */
|
|
26
|
+
readonly easing?: string;
|
|
27
|
+
/** Composite operation for this keyframe. */
|
|
28
|
+
readonly composite?: CompositeOperationOrAuto;
|
|
29
|
+
/** CSS `offset` shorthand (motion path); WAAPI names it `cssOffset` to avoid the keyframe offset. */
|
|
30
|
+
readonly cssOffset?: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/** Value list of one property in property-indexed keyframes. */
|
|
34
|
+
export type IndexedKeyframeValue =
|
|
35
|
+
| string
|
|
36
|
+
| number
|
|
37
|
+
| null
|
|
38
|
+
| readonly string[]
|
|
39
|
+
| readonly (number | null)[];
|
|
40
|
+
|
|
41
|
+
/** Property-indexed keyframes with checked property names. */
|
|
42
|
+
export type TypedPropertyIndexedKeyframes = {
|
|
43
|
+
readonly [Key in KeyframeProperty]?: IndexedKeyframeValue;
|
|
44
|
+
} & {
|
|
45
|
+
/** Keyframe positions. */
|
|
46
|
+
readonly offset?: number | null | readonly (number | null)[];
|
|
47
|
+
/** Easings. */
|
|
48
|
+
readonly easing?: string | readonly string[];
|
|
49
|
+
/** Composite operations. */
|
|
50
|
+
readonly composite?: CompositeOperationOrAuto | readonly CompositeOperationOrAuto[];
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/** Keyframes accepted by {@link useAnimate}. */
|
|
54
|
+
export type AnimationKeyframes = readonly TypedKeyframe[] | TypedPropertyIndexedKeyframes;
|
|
55
|
+
|
|
56
|
+
/** Frame scheduler used to keep `currentTime` in sync while running. */
|
|
57
|
+
export interface AnimateFrameHost {
|
|
58
|
+
/** Schedule a callback before the next repaint. */
|
|
59
|
+
readonly requestAnimationFrame: (callback: FrameRequestCallback) => number;
|
|
60
|
+
/** Cancel a scheduled frame. */
|
|
61
|
+
readonly cancelAnimationFrame: (handle: number) => void;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Options for {@link useAnimate}. */
|
|
65
|
+
export interface UseAnimateOptions extends KeyframeAnimationOptions {
|
|
66
|
+
/**
|
|
67
|
+
* Start playing as soon as the element resolves.
|
|
68
|
+
*
|
|
69
|
+
* @default true
|
|
70
|
+
*/
|
|
71
|
+
readonly immediate?: boolean;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Commit the final computed styles to the element's `style` on finish.
|
|
75
|
+
*
|
|
76
|
+
* @default false
|
|
77
|
+
*/
|
|
78
|
+
readonly commitStyles?: boolean;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Keep the animation from being auto-removed by the browser when it is
|
|
82
|
+
* replaced by another filling animation.
|
|
83
|
+
*
|
|
84
|
+
* @default false
|
|
85
|
+
*/
|
|
86
|
+
readonly persist?: boolean;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Called once the animation object is created.
|
|
90
|
+
*
|
|
91
|
+
* @default undefined
|
|
92
|
+
*/
|
|
93
|
+
readonly onReady?: (animation: Animation) => void;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Called when creating the animation throws (e.g. invalid keyframes).
|
|
97
|
+
*
|
|
98
|
+
* @default undefined
|
|
99
|
+
*/
|
|
100
|
+
readonly onError?: (error: unknown) => void;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Frame scheduler used to sync `currentTime` while running.
|
|
104
|
+
*
|
|
105
|
+
* @default globalThis.window when available
|
|
106
|
+
*/
|
|
107
|
+
readonly frameHost?: MaybeRefOrGetter<AnimateFrameHost | null | undefined>;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Reactive animation state returned by {@link useAnimate}. */
|
|
111
|
+
export interface AnimateControls {
|
|
112
|
+
/** Whether the resolved element supports `animate()`. `false` during server rendering. */
|
|
113
|
+
readonly isSupported: Readonly<Ref<boolean>>;
|
|
114
|
+
/** Underlying `Animation`, once created. */
|
|
115
|
+
readonly animation: Readonly<ShallowRef<Animation | null>>;
|
|
116
|
+
/** Playback state. */
|
|
117
|
+
readonly playState: Readonly<Ref<AnimationPlayState>>;
|
|
118
|
+
/** Whether a play/pause is pending. */
|
|
119
|
+
readonly pending: Readonly<Ref<boolean>>;
|
|
120
|
+
/** Current time in milliseconds (writable to seek). */
|
|
121
|
+
readonly currentTime: WritableComputedRef<number | null>;
|
|
122
|
+
/** Playback rate (writable). */
|
|
123
|
+
readonly playbackRate: WritableComputedRef<number>;
|
|
124
|
+
/** Play (creating the animation if needed). */
|
|
125
|
+
readonly play: () => void;
|
|
126
|
+
/** Pause. */
|
|
127
|
+
readonly pause: () => void;
|
|
128
|
+
/** Reverse the playback direction. */
|
|
129
|
+
readonly reverse: () => void;
|
|
130
|
+
/** Jump to the end. */
|
|
131
|
+
readonly finish: () => void;
|
|
132
|
+
/** Cancel and clear effects. */
|
|
133
|
+
readonly cancel: () => void;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Drive the Web Animations API reactively with typed keyframes.
|
|
138
|
+
*
|
|
139
|
+
* Keyframe property names are checked against `CSSStyleDeclaration`, so typos
|
|
140
|
+
* are compile errors. Changing keyframes updates the running effect in place.
|
|
141
|
+
* Playback state is synced after every control call, on `finish`/`cancel`/
|
|
142
|
+
* `remove`, and every animation frame while running. The animation is
|
|
143
|
+
* cancelled when the owning reactive scope stops. Nothing runs during server
|
|
144
|
+
* rendering (`playState` is `"idle"`).
|
|
145
|
+
*
|
|
146
|
+
* @param target Reactive element target.
|
|
147
|
+
* @param keyframes Reactive typed keyframes (`null` to pause creation).
|
|
148
|
+
* @param options Duration in milliseconds, or timing plus lifecycle options.
|
|
149
|
+
* @returns Reactive playback state and controls.
|
|
150
|
+
*/
|
|
151
|
+
export function useAnimate(
|
|
152
|
+
target: MaybeElementTarget,
|
|
153
|
+
keyframes: MaybeRefOrGetter<AnimationKeyframes | null>,
|
|
154
|
+
options: number | UseAnimateOptions,
|
|
155
|
+
): AnimateControls {
|
|
156
|
+
const settings: UseAnimateOptions = typeof options === "number" ? { duration: options } : options;
|
|
157
|
+
const {
|
|
158
|
+
immediate = true,
|
|
159
|
+
commitStyles = false,
|
|
160
|
+
persist = false,
|
|
161
|
+
onReady,
|
|
162
|
+
onError,
|
|
163
|
+
frameHost,
|
|
164
|
+
...timing
|
|
165
|
+
} = settings;
|
|
166
|
+
const animation = shallowRef<Animation | null>(null);
|
|
167
|
+
const isSupported = ref(false);
|
|
168
|
+
const playState = ref<AnimationPlayState>("idle");
|
|
169
|
+
const pending = ref(false);
|
|
170
|
+
const time = ref<number | null>(null);
|
|
171
|
+
const rate = ref(timing.playbackRate ?? 1);
|
|
172
|
+
let stopFrames = (): void => undefined;
|
|
173
|
+
|
|
174
|
+
const readTime = (value: CSSNumberish | null): number | null =>
|
|
175
|
+
typeof value === "number" ? value : null;
|
|
176
|
+
const sync = (): void => {
|
|
177
|
+
const current = animation.value;
|
|
178
|
+
if (!current) return;
|
|
179
|
+
playState.value = current.playState;
|
|
180
|
+
pending.value = current.pending;
|
|
181
|
+
time.value = readTime(current.currentTime);
|
|
182
|
+
rate.value = current.playbackRate;
|
|
183
|
+
if (current.playState === "running") startFrames();
|
|
184
|
+
else stopFrames();
|
|
185
|
+
};
|
|
186
|
+
const startFrames = (): void => {
|
|
187
|
+
const frames = frameHost === undefined ? browserFrameHost() : toValue(frameHost);
|
|
188
|
+
if (!frames) return;
|
|
189
|
+
stopFrames();
|
|
190
|
+
let handle = frames.requestAnimationFrame(function tick() {
|
|
191
|
+
sync();
|
|
192
|
+
if (animation.value?.playState === "running") handle = frames.requestAnimationFrame(tick);
|
|
193
|
+
});
|
|
194
|
+
stopFrames = () => {
|
|
195
|
+
frames.cancelAnimationFrame(handle);
|
|
196
|
+
stopFrames = () => undefined;
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
const create = (): Animation | null => {
|
|
201
|
+
const element = resolveElement(target);
|
|
202
|
+
const frames = toValue(keyframes);
|
|
203
|
+
isSupported.value = element !== null && typeof element.animate === "function";
|
|
204
|
+
if (!element || !frames || !isSupported.value) return null;
|
|
205
|
+
try {
|
|
206
|
+
const created = element.animate(toPlatformKeyframes(frames), timing);
|
|
207
|
+
if (persist) created.persist();
|
|
208
|
+
if (commitStyles) {
|
|
209
|
+
created.addEventListener("finish", () => {
|
|
210
|
+
try {
|
|
211
|
+
created.commitStyles();
|
|
212
|
+
} catch {
|
|
213
|
+
// Committing fails for disconnected elements; the fill still applies.
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
for (const type of ["finish", "cancel", "remove"] as const) {
|
|
218
|
+
created.addEventListener(type, sync);
|
|
219
|
+
}
|
|
220
|
+
animation.value = created;
|
|
221
|
+
onReady?.(created);
|
|
222
|
+
return created;
|
|
223
|
+
} catch (error) {
|
|
224
|
+
onError?.(error);
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
const stopTarget = watch(
|
|
230
|
+
() => resolveElement(target),
|
|
231
|
+
(element, _previous, onCleanup) => {
|
|
232
|
+
if (!element) return;
|
|
233
|
+
const created = create();
|
|
234
|
+
if (created && !immediate) created.pause();
|
|
235
|
+
sync();
|
|
236
|
+
onCleanup(() => {
|
|
237
|
+
stopFrames();
|
|
238
|
+
created?.cancel();
|
|
239
|
+
if (animation.value === created) animation.value = null;
|
|
240
|
+
playState.value = "idle";
|
|
241
|
+
});
|
|
242
|
+
},
|
|
243
|
+
{ immediate: true, flush: "post" },
|
|
244
|
+
);
|
|
245
|
+
const stopKeyframes = watch(
|
|
246
|
+
() => toValue(keyframes),
|
|
247
|
+
(frames) => {
|
|
248
|
+
const effect = animation.value?.effect;
|
|
249
|
+
if (frames && effect && isKeyframeEffect(effect))
|
|
250
|
+
effect.setKeyframes(toPlatformKeyframes(frames));
|
|
251
|
+
},
|
|
252
|
+
{ deep: true },
|
|
253
|
+
);
|
|
254
|
+
tryOnScopeDispose(() => {
|
|
255
|
+
stopTarget.stop();
|
|
256
|
+
stopKeyframes.stop();
|
|
257
|
+
stopFrames();
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
const control = (action: (current: Animation) => void) => (): void => {
|
|
261
|
+
const current = animation.value ?? create();
|
|
262
|
+
if (!current) return;
|
|
263
|
+
action(current);
|
|
264
|
+
sync();
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
return {
|
|
268
|
+
isSupported: readonly(isSupported),
|
|
269
|
+
animation,
|
|
270
|
+
playState: readonly(playState),
|
|
271
|
+
pending: readonly(pending),
|
|
272
|
+
currentTime: computed({
|
|
273
|
+
get: () => time.value,
|
|
274
|
+
set: (value: number | null) => {
|
|
275
|
+
if (!animation.value) return;
|
|
276
|
+
animation.value.currentTime = value;
|
|
277
|
+
sync();
|
|
278
|
+
},
|
|
279
|
+
}),
|
|
280
|
+
playbackRate: computed({
|
|
281
|
+
get: () => rate.value,
|
|
282
|
+
set: (value: number) => {
|
|
283
|
+
rate.value = value;
|
|
284
|
+
if (!animation.value) return;
|
|
285
|
+
animation.value.playbackRate = value;
|
|
286
|
+
sync();
|
|
287
|
+
},
|
|
288
|
+
}),
|
|
289
|
+
play: control((current) => current.play()),
|
|
290
|
+
pause: control((current) => current.pause()),
|
|
291
|
+
reverse: control((current) => current.reverse()),
|
|
292
|
+
finish: control((current) => current.finish()),
|
|
293
|
+
cancel: control((current) => current.cancel()),
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function toPlatformKeyframes(frames: AnimationKeyframes): Keyframe[] | PropertyIndexedKeyframes {
|
|
298
|
+
if (isKeyframeList(frames)) return frames.map((frame) => ({ ...frame }));
|
|
299
|
+
const indexed: PropertyIndexedKeyframes = {};
|
|
300
|
+
for (const [key, value] of Object.entries(frames)) {
|
|
301
|
+
if (value !== undefined) indexed[key] = copyIndexedValue(value);
|
|
302
|
+
}
|
|
303
|
+
return indexed;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function copyIndexedValue(
|
|
307
|
+
value: IndexedKeyframeValue,
|
|
308
|
+
): string | number | null | string[] | (number | null)[] {
|
|
309
|
+
return typeof value === "object" && value !== null ? value.slice() : value;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
function isKeyframeList(frames: AnimationKeyframes): frames is readonly TypedKeyframe[] {
|
|
313
|
+
return Array.isArray(frames);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function isKeyframeEffect(effect: AnimationEffect): effect is KeyframeEffect {
|
|
317
|
+
return "setKeyframes" in effect && typeof effect.setKeyframes === "function";
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function browserFrameHost(): AnimateFrameHost | undefined {
|
|
321
|
+
return typeof window !== "undefined" ? window : undefined;
|
|
322
|
+
}
|