@vizejs/composable 0.809.0 → 0.811.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.mjs +0 -62
- package/dist/active-element.mjs +0 -11
- package/dist/animate.mjs +0 -19
- package/dist/async-resource.mjs +0 -17
- package/dist/battery.mjs +0 -13
- package/dist/breakpoints.mjs +0 -24
- package/dist/capability.mjs +0 -12
- package/dist/{catalog-BRX-Wg8B.mjs → catalog-CcpCnLjb.mjs} +0 -14
- package/dist/catalog.mjs +1 -1
- package/dist/color-mode.mjs +0 -23
- package/dist/computed-with-control.mjs +0 -22
- package/dist/create-event-hook.mjs +0 -27
- package/dist/create-global-state.mjs +0 -23
- package/dist/create-shared-composable.mjs +0 -23
- package/dist/device-motion.mjs +0 -11
- package/dist/device-orientation.mjs +0 -23
- package/dist/device-pixel-ratio.mjs +0 -11
- package/dist/disposal-scope.mjs +0 -25
- package/dist/document-visibility.mjs +0 -14
- package/dist/draggable.mjs +0 -14
- package/dist/element-bounding.mjs +0 -14
- package/dist/element-by-point.mjs +0 -10
- package/dist/element-hover.mjs +0 -13
- package/dist/element-target.mjs +0 -30
- package/dist/focus.mjs +0 -23
- package/dist/fps.mjs +0 -12
- package/dist/geolocation.mjs +0 -14
- package/dist/i18n.mjs +0 -86
- package/dist/icu-message.mjs +0 -58
- package/dist/idle.mjs +0 -16
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/infinite-scroll.mjs +0 -16
- package/dist/intersection-observer.mjs +0 -27
- package/dist/locale.mjs +0 -20
- package/dist/magic-keys.mjs +0 -35
- package/dist/math.mjs +0 -37
- package/dist/media-query.mjs +0 -29
- package/dist/mouse-in-element.mjs +0 -12
- package/dist/mouse.mjs +0 -12
- package/dist/mutation-observer.mjs +0 -15
- package/dist/network.mjs +0 -24
- package/dist/on-click-outside.mjs +0 -16
- package/dist/on-key-stroke.mjs +0 -33
- package/dist/on-long-press.mjs +0 -14
- package/dist/on-start-typing.mjs +0 -23
- package/dist/page-leave.mjs +0 -11
- package/dist/parent-element.mjs +0 -9
- package/dist/pinch.mjs +0 -14
- package/dist/pointer-lock.mjs +0 -23
- package/dist/pointer.mjs +0 -18
- package/dist/preferences.mjs +0 -31
- package/dist/preferred-languages.mjs +0 -13
- package/dist/ref-auto-reset.mjs +0 -24
- package/dist/ref-debounced.mjs +0 -22
- package/dist/ref-default.mjs +0 -21
- package/dist/resize-observer.mjs +0 -31
- package/dist/resolver.mjs +1 -58
- package/dist/retry-async.mjs +0 -25
- package/dist/retry-delay.mjs +0 -23
- package/dist/scope.mjs +0 -14
- package/dist/screen-orientation.mjs +0 -15
- package/dist/scroll-lock.mjs +0 -14
- package/dist/scroll.mjs +0 -27
- package/dist/standard-schema.mjs +0 -31
- package/dist/swipe.mjs +0 -36
- package/dist/temporal.mjs +0 -30
- package/dist/text-selection.mjs +0 -15
- package/dist/textarea-autosize.mjs +0 -13
- package/dist/to-reactive.mjs +0 -20
- package/dist/transition.mjs +0 -7
- package/dist/until.mjs +0 -25
- package/dist/use-array.mjs +0 -52
- package/dist/use-barcode-detector.mjs +0 -25
- package/dist/use-bluetooth.mjs +0 -27
- package/dist/use-broadcast-channel.mjs +0 -30
- package/dist/use-builtin-ai.mjs +0 -68
- package/dist/use-clipboard.mjs +0 -27
- package/dist/use-compression-stream.mjs +0 -78
- package/dist/use-contact-picker.mjs +0 -22
- package/dist/use-cookie.mjs +0 -63
- package/dist/use-countdown.mjs +0 -22
- package/dist/use-counter.mjs +0 -29
- package/dist/use-css-var.mjs +0 -28
- package/dist/use-date-format.mjs +0 -48
- package/dist/use-date-time-format.mjs +0 -22
- package/dist/use-debounced.mjs +0 -39
- package/dist/use-display-media.mjs +0 -22
- package/dist/use-display-names.mjs +0 -19
- package/dist/use-document-title.mjs +0 -25
- package/dist/use-drop-zone.mjs +0 -36
- package/dist/use-event-source.mjs +0 -25
- package/dist/use-eye-dropper.mjs +0 -19
- package/dist/use-favicon.mjs +0 -23
- package/dist/use-fetch.mjs +0 -27
- package/dist/use-field.mjs +0 -27
- package/dist/use-file-dialog.mjs +0 -21
- package/dist/{use-form-C2JXZ0i7.mjs → use-form-BZqwMs6k.mjs} +143 -70
- package/dist/use-form-field-props.mjs +0 -57
- package/dist/use-form.d.mts +123 -18
- package/dist/use-form.mjs +1 -1
- package/dist/use-fullscreen.mjs +0 -23
- package/dist/use-gamepad.mjs +0 -50
- package/dist/use-hid.mjs +0 -25
- package/dist/use-history.mjs +0 -43
- package/dist/use-id-generator.mjs +0 -21
- package/dist/use-image.mjs +0 -22
- package/dist/use-indexed-db.mjs +0 -39
- package/dist/use-interval.mjs +0 -28
- package/dist/use-list-format.mjs +0 -18
- package/dist/use-machine.mjs +0 -34
- package/dist/use-map.mjs +0 -28
- package/dist/use-media-controls.mjs +0 -28
- package/dist/use-mounted.mjs +0 -18
- package/dist/use-navigation-api.mjs +0 -27
- package/dist/use-notification.mjs +0 -24
- package/dist/use-number-format.mjs +0 -23
- package/dist/use-object-url.mjs +0 -22
- package/dist/use-offset-pagination.mjs +0 -18
- package/dist/use-payment-request.mjs +0 -25
- package/dist/use-performance-observer.mjs +0 -27
- package/dist/use-permission.mjs +0 -26
- package/dist/use-plural-rules.mjs +0 -21
- package/dist/use-push-subscription.mjs +0 -28
- package/dist/use-queue.mjs +0 -29
- package/dist/use-raf-fn.mjs +0 -23
- package/dist/use-relative-time-format.mjs +0 -35
- package/dist/use-request-idle-callback.mjs +0 -42
- package/dist/use-route-query.mjs +0 -17
- package/dist/use-scheduler-post-task.mjs +0 -27
- package/dist/use-screen-details.mjs +0 -42
- package/dist/use-script-tag.mjs +0 -28
- package/dist/use-segmenter.mjs +0 -20
- package/dist/use-serial.mjs +0 -24
- package/dist/use-service-worker.mjs +0 -27
- package/dist/use-set.mjs +0 -23
- package/dist/use-share.mjs +0 -23
- package/dist/use-sorted-locale.mjs +0 -20
- package/dist/use-speech-recognition.mjs +0 -24
- package/dist/use-speech-synthesis.mjs +0 -26
- package/dist/use-stack.mjs +0 -27
- package/dist/use-storage-estimate.mjs +0 -41
- package/dist/use-storage.mjs +0 -68
- package/dist/use-style-tag.mjs +0 -22
- package/dist/use-supported.mjs +0 -17
- package/dist/use-throttled.mjs +0 -46
- package/dist/use-time-ago.mjs +0 -22
- package/dist/use-toggle.mjs +0 -19
- package/dist/use-url-hash.mjs +0 -28
- package/dist/use-url-search-params.mjs +0 -99
- package/dist/use-usb.mjs +0 -23
- package/dist/use-user-activation.mjs +0 -22
- package/dist/use-user-media.mjs +0 -50
- package/dist/use-vibrate.mjs +0 -21
- package/dist/use-view-transition.mjs +0 -22
- package/dist/use-visual-viewport.mjs +0 -25
- package/dist/use-wake-lock.mjs +0 -21
- package/dist/use-web-authn.mjs +0 -61
- package/dist/use-web-locks.mjs +0 -25
- package/dist/use-web-midi.mjs +0 -22
- package/dist/use-web-vitals.mjs +0 -41
- package/dist/use-websocket.mjs +0 -27
- package/dist/use-worker-fn.mjs +0 -37
- package/dist/virtual-list.mjs +0 -14
- package/dist/whenever.mjs +0 -21
- package/dist/window-size.mjs +0 -12
- package/package.json +2 -2
- package/registry/files/form-control-types.ts +260 -0
- package/registry/files/form-dirty.ts +131 -0
- package/registry/files/form-options.ts +156 -0
- package/registry/files/form-path-types.ts +135 -0
- package/registry/files/use-form.ts +102 -449
- package/registry/registry.json +28 -4
package/dist/use-machine.mjs
CHANGED
|
@@ -1,42 +1,8 @@
|
|
|
1
1
|
import { computed, shallowRef } from "vue";
|
|
2
2
|
//#region src/use-machine.ts
|
|
3
|
-
/** Shallow ref typed through an unconstrained parameter, so literal unions stay intact. */
|
|
4
3
|
function ownedRef(value) {
|
|
5
4
|
return shallowRef(value);
|
|
6
5
|
}
|
|
7
|
-
/**
|
|
8
|
-
* Finite state machine with typed states, events, and targets.
|
|
9
|
-
*
|
|
10
|
-
* State names are inferred from the keys of `states`, event names from the
|
|
11
|
-
* keys of every `on` map, and every `target` (and `initial`) must name a
|
|
12
|
-
* declared state, so typos fail to compile. Transitions may carry guards
|
|
13
|
-
* (first passing guard wins) and actions that return the next context;
|
|
14
|
-
* `exit` runs on the old state before `entry` runs on the new one, and a
|
|
15
|
-
* self-transition runs both. Synchronous and free of globals: identical on
|
|
16
|
-
* server and client, nothing to dispose.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```ts
|
|
20
|
-
* const fetcher = useMachine({
|
|
21
|
-
* initial: "idle",
|
|
22
|
-
* context: { retries: 0 },
|
|
23
|
-
* states: {
|
|
24
|
-
* idle: { on: { FETCH: "loading" } },
|
|
25
|
-
* loading: { on: { RESOLVE: "success", REJECT: "failure" } },
|
|
26
|
-
* failure: {
|
|
27
|
-
* on: {
|
|
28
|
-
* RETRY: { target: "loading", guard: (c) => c.retries < 3, action: (c) => ({ retries: c.retries + 1 }) },
|
|
29
|
-
* },
|
|
30
|
-
* },
|
|
31
|
-
* success: {},
|
|
32
|
-
* },
|
|
33
|
-
* });
|
|
34
|
-
* fetcher.send("FETCH");
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* @param config States, events, context, and hooks.
|
|
38
|
-
* @returns The reactive machine.
|
|
39
|
-
*/
|
|
40
6
|
function useMachine(config) {
|
|
41
7
|
const state = ownedRef(config.initial);
|
|
42
8
|
const context = ownedRef(config.context);
|
package/dist/use-map.mjs
CHANGED
|
@@ -1,36 +1,8 @@
|
|
|
1
1
|
import { computed, shallowReactive, shallowReadonly } from "vue";
|
|
2
2
|
//#region src/use-map.ts
|
|
3
|
-
/**
|
|
4
|
-
* Narrow a `get` result using the matching `has` answer: when the key is
|
|
5
|
-
* present the result is a stored `Value`, even if that value is `undefined`.
|
|
6
|
-
*/
|
|
7
3
|
function isStored(value, present) {
|
|
8
4
|
return present;
|
|
9
5
|
}
|
|
10
|
-
/**
|
|
11
|
-
* Create a reactive `Map` with typed helpers.
|
|
12
|
-
*
|
|
13
|
-
* Key and value types are inferred from the initial entries
|
|
14
|
-
* (`useMap([["a", 1]])` is a `Map<string, number>`); pass type arguments
|
|
15
|
-
* for an initially empty map. Reads through `get`, `has`, and `map` are
|
|
16
|
-
* tracked per key, so an effect reading one key does not re-run when an
|
|
17
|
-
* unrelated key changes. Values are stored as-is (not deeply reactive).
|
|
18
|
-
*
|
|
19
|
-
* Purely synchronous state: safe during server rendering (no host globals,
|
|
20
|
-
* no timers) and nothing to dispose.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```ts
|
|
24
|
-
* const counts = useMap<string, number>();
|
|
25
|
-
* counts.update("clicks", (previous = 0) => previous + 1);
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
28
|
-
* @typeParam Key Key type, inferred from `initial`.
|
|
29
|
-
* @typeParam Value Value type, inferred from `initial`.
|
|
30
|
-
* @param initial Entries inserted at creation and restored by `reset`.
|
|
31
|
-
* @default initial []
|
|
32
|
-
* @returns The reactive map and its helpers.
|
|
33
|
-
*/
|
|
34
6
|
function useMap(initial = []) {
|
|
35
7
|
const baseline = [...initial];
|
|
36
8
|
const map = shallowReactive(new Map(baseline));
|
|
@@ -15,34 +15,6 @@ function chooseSource(element, source) {
|
|
|
15
15
|
if (element.canPlayType(candidate.type) !== "") return candidate.src;
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
/**
|
|
19
|
-
* Two-way reactive controls for a `<video>` or `<audio>` element.
|
|
20
|
-
*
|
|
21
|
-
* `playing`, `currentTime`, `volume`, `muted`, and `rate` mirror the
|
|
22
|
-
* element and are writable: assigning them drives the element, while
|
|
23
|
-
* element events update them without echoing the change back. The element
|
|
24
|
-
* is the source of truth whenever a new target attaches. Read-only state
|
|
25
|
-
* covers duration, buffering, seeking, waiting, stalls, text tracks, and
|
|
26
|
-
* picture-in-picture. A rejected `play()` (blocked autoplay) resets
|
|
27
|
-
* `playing` and is exposed through `error`. Listeners are removed when the
|
|
28
|
-
* target changes and when the owning reactive scope stops.
|
|
29
|
-
*
|
|
30
|
-
* Server rendering: the template ref is empty, so every value keeps its
|
|
31
|
-
* neutral default (paused, time 0, volume 1) and nothing is touched.
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```ts
|
|
35
|
-
* const video = useTemplateRef<HTMLVideoElement>("video");
|
|
36
|
-
* const { playing, currentTime, duration } = useMediaControls(video, {
|
|
37
|
-
* src: [{ src: "/clip.webm", type: "video/webm" }, { src: "/clip.mp4", type: "video/mp4" }],
|
|
38
|
-
* });
|
|
39
|
-
* ```
|
|
40
|
-
*
|
|
41
|
-
* @param target Reactive media element.
|
|
42
|
-
* @param options Source selection and picture-in-picture document.
|
|
43
|
-
* @default options {}
|
|
44
|
-
* @returns Reactive media state and actions.
|
|
45
|
-
*/
|
|
46
18
|
function useMediaControls(target, options = {}) {
|
|
47
19
|
const playing = ref(false);
|
|
48
20
|
const currentTime = ref(0);
|
package/dist/use-mounted.mjs
CHANGED
|
@@ -1,23 +1,5 @@
|
|
|
1
1
|
import { hasInjectionContext, onMounted, shallowRef } from "vue";
|
|
2
2
|
//#region src/use-mounted.ts
|
|
3
|
-
/**
|
|
4
|
-
* Whether the calling component has mounted.
|
|
5
|
-
*
|
|
6
|
-
* `false` during server rendering and during hydration, `true` from the
|
|
7
|
-
* component's `onMounted` on: gate client-only rendering behind it to keep
|
|
8
|
-
* hydration stable. Outside a component (no instance to mount) it stays
|
|
9
|
-
* `false`. Component detection uses `hasInjectionContext()` rather than
|
|
10
|
-
* `getCurrentInstance()`, which returns `null` inside Vapor components, so
|
|
11
|
-
* the flag also flips in Vapor.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* const mounted = useMounted();
|
|
16
|
-
* // <ClientOnlyChart v-if="mounted" />
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* @returns Readonly mounted flag.
|
|
20
|
-
*/
|
|
21
3
|
function useMounted() {
|
|
22
4
|
const mounted = shallowRef(false);
|
|
23
5
|
if (hasInjectionContext()) onMounted(() => {
|
|
@@ -25,33 +25,6 @@ function snapshot(entry) {
|
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
27
|
function ignore() {}
|
|
28
|
-
/**
|
|
29
|
-
* Reactive access to the Navigation API (`window.navigation`).
|
|
30
|
-
*
|
|
31
|
-
* Entry snapshots refresh on `currententrychange`, `navigatesuccess` and
|
|
32
|
-
* `navigateerror`. Actions resolve to a {@link NavigationOutcome} and never
|
|
33
|
-
* reject; failures also land in `error`. Listeners (including interceptors)
|
|
34
|
-
* are removed when the owning reactive scope stops; outside a scope the
|
|
35
|
-
* caller removes them with the returned functions.
|
|
36
|
-
*
|
|
37
|
-
* Server rendering: nothing is read or subscribed; `supported` is false,
|
|
38
|
-
* `currentEntry` null, `entries` empty, and actions resolve to
|
|
39
|
-
* `{ status: "unsupported" }`.
|
|
40
|
-
* Inside a component the host is resolved after mounting, so hydration
|
|
41
|
-
* renders this server state first.
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* ```ts
|
|
45
|
-
* const nav = useNavigationApi<{ tab: string }>();
|
|
46
|
-
* nav.intercept((url) => url.pathname.startsWith("/app/"), {
|
|
47
|
-
* handler: async () => renderRoute(location.pathname),
|
|
48
|
-
* });
|
|
49
|
-
* ```
|
|
50
|
-
*
|
|
51
|
-
* @param options Navigation host and state parser.
|
|
52
|
-
* @default options {}
|
|
53
|
-
* @returns Navigation state, hooks and actions.
|
|
54
|
-
*/
|
|
55
28
|
function useNavigationApi(options = {}) {
|
|
56
29
|
const currentEntry = shallowRef(null);
|
|
57
30
|
const entries = shallowRef([]);
|
|
@@ -14,30 +14,6 @@ const notificationEvents = [
|
|
|
14
14
|
"error",
|
|
15
15
|
"close"
|
|
16
16
|
];
|
|
17
|
-
/**
|
|
18
|
-
* Show typed Web Notifications with permission handling.
|
|
19
|
-
*
|
|
20
|
-
* `show` merges reactive defaults with per-call options, asks for
|
|
21
|
-
* permission first when it is still undecided (configurable), and resolves
|
|
22
|
-
* to a discriminated {@link WebNotificationResult}. Handlers registered with
|
|
23
|
-
* `on` apply to every notification this composable shows. The current
|
|
24
|
-
* notification is closed when the owning reactive scope stops.
|
|
25
|
-
*
|
|
26
|
-
* Server rendering: the API is never touched; `permission` is
|
|
27
|
-
* `"unsupported"` and `supported` is false.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```ts
|
|
31
|
-
* const notify = useWebNotification<{ id: string }>({ defaults: { icon: "/icon.png" } });
|
|
32
|
-
* notify.on("click", () => window.focus());
|
|
33
|
-
* await notify.show("Build finished", { data: { id: "42" } });
|
|
34
|
-
* ```
|
|
35
|
-
*
|
|
36
|
-
* @typeParam Data Application data attached to notifications.
|
|
37
|
-
* @param options Capability, defaults, and permission policy.
|
|
38
|
-
* @default options {}
|
|
39
|
-
* @returns Notification state and actions.
|
|
40
|
-
*/
|
|
41
17
|
function useWebNotification(options = {}) {
|
|
42
18
|
const resolveHost = () => options.host === void 0 ? browserNotificationHost() : unref(options.host) ?? void 0;
|
|
43
19
|
const readPermission = () => {
|
|
@@ -12,29 +12,6 @@ function formatRangeWith(formatter, start, end) {
|
|
|
12
12
|
function browserLanguage() {
|
|
13
13
|
return typeof window === "undefined" ? void 0 : window.navigator.language;
|
|
14
14
|
}
|
|
15
|
-
/**
|
|
16
|
-
* Format numbers reactively with `Intl.NumberFormat`.
|
|
17
|
-
*
|
|
18
|
-
* The formatter follows the reactive options (including `locale`) and is
|
|
19
|
-
* cached per locale and option set through {@link useLocale}. Without an
|
|
20
|
-
* explicit locale the browser language is used, falling back to `"en"`
|
|
21
|
-
* (always the case on the server). Invalid options surface as the
|
|
22
|
-
* platform's `RangeError`/`TypeError` on first read. No listeners or timers
|
|
23
|
-
* are created, so nothing needs cleanup.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```ts
|
|
27
|
-
* const price = ref(1234.5);
|
|
28
|
-
* const { formatted } = useNumberFormat(price, { locale: "de-DE", style: "currency", currency: "EUR" });
|
|
29
|
-
* formatted.value; // "1.234,50 €"
|
|
30
|
-
* ```
|
|
31
|
-
*
|
|
32
|
-
* @param value Reactive number; `null`/`undefined` format as `""`.
|
|
33
|
-
* @param options Reactive locale and `Intl.NumberFormat` options.
|
|
34
|
-
* @default value undefined
|
|
35
|
-
* @default options {}
|
|
36
|
-
* @returns Reactive formatted output and formatter helpers.
|
|
37
|
-
*/
|
|
38
15
|
function useNumberFormat(value, options = {}) {
|
|
39
16
|
const localeControls = useLocale(() => toValue(options).locale, { detect: browserLanguage });
|
|
40
17
|
const formatter = computed(() => {
|
package/dist/use-object-url.mjs
CHANGED
|
@@ -6,28 +6,6 @@ function browserObjectUrlHost() {
|
|
|
6
6
|
const { URL } = window;
|
|
7
7
|
return typeof URL.createObjectURL === "function" ? URL : void 0;
|
|
8
8
|
}
|
|
9
|
-
/**
|
|
10
|
-
* Create a reactive object URL for a `Blob`, `File`, or `MediaSource`.
|
|
11
|
-
*
|
|
12
|
-
* A new URL is created whenever the reactive object changes and the
|
|
13
|
-
* previous one is revoked immediately, so memory held by the old object is
|
|
14
|
-
* released. The last URL is revoked when the owning reactive scope stops.
|
|
15
|
-
* Outside a scope, the caller owns the last URL (it lives until unload).
|
|
16
|
-
*
|
|
17
|
-
* Server rendering: no URL is created and the ref stays `undefined`.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```ts
|
|
21
|
-
* const file = shallowRef<File>();
|
|
22
|
-
* const preview = useObjectUrl(file);
|
|
23
|
-
* // <img :src="preview">
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* @param object Reactive object to reference; `null`/`undefined` clears the URL.
|
|
27
|
-
* @param options Object-URL capability.
|
|
28
|
-
* @default options {}
|
|
29
|
-
* @returns Readonly ref holding the current object URL.
|
|
30
|
-
*/
|
|
31
9
|
function useObjectUrl(object, options = {}) {
|
|
32
10
|
const url = ref(void 0);
|
|
33
11
|
const resolveHost = () => options.host === void 0 ? browserObjectUrlHost() : unref(options.host) ?? void 0;
|
|
@@ -3,24 +3,6 @@ import { computed, isRef, shallowRef, toValue, watch } from "vue";
|
|
|
3
3
|
function toWritable(value, fallback) {
|
|
4
4
|
return isRef(value) ? value : shallowRef(value ?? fallback);
|
|
5
5
|
}
|
|
6
|
-
/**
|
|
7
|
-
* Offset-based pagination state.
|
|
8
|
-
*
|
|
9
|
-
* The page is clamped into `[1, pageCount]` on every read and write, so
|
|
10
|
-
* shrinking `total` or growing `pageSize` never leaves the cursor past the
|
|
11
|
-
* end. Writable `page`/`pageSize` refs are updated in place for two-way
|
|
12
|
-
* binding. Callbacks fire after the corresponding value settles.
|
|
13
|
-
* Synchronous state: SSR-safe; watchers follow the owning scope.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```ts
|
|
17
|
-
* const { currentPage, pageCount, next, offset } = useOffsetPagination({ total, pageSize: 20 });
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
* @param options Total, page, page size, and change callbacks.
|
|
21
|
-
* @default options {}
|
|
22
|
-
* @returns Pagination state and controls.
|
|
23
|
-
*/
|
|
24
6
|
function useOffsetPagination(options = {}) {
|
|
25
7
|
const page = toWritable(options.page, 1);
|
|
26
8
|
const size = toWritable(options.pageSize, 10);
|
|
@@ -15,31 +15,6 @@ function hasUpdateWith(event) {
|
|
|
15
15
|
function errorName(error) {
|
|
16
16
|
return typeof error === "object" && error !== null && "name" in error ? error.name : void 0;
|
|
17
17
|
}
|
|
18
|
-
/**
|
|
19
|
-
* Collect payments with a typed Payment Request API wrapper.
|
|
20
|
-
*
|
|
21
|
-
* Every `show()` constructs a fresh request from the reactive `methods`,
|
|
22
|
-
* `details`, and `paymentOptions`, wires the shipping hooks (which call
|
|
23
|
-
* `updateWith` synchronously when they return an update), and resolves to a
|
|
24
|
-
* discriminated {@link PaymentShowResult}. Call `complete()` after
|
|
25
|
-
* processing a `"completed"` result. A showing sheet is aborted when the
|
|
26
|
-
* owning reactive scope stops; outside a scope call `abort()`.
|
|
27
|
-
*
|
|
28
|
-
* Server rendering: nothing is constructed, `supported` is false and
|
|
29
|
-
* `state` is `"idle"`.
|
|
30
|
-
* Inside a component `supported` turns true only after mounting, so
|
|
31
|
-
* hydration renders this server state first.
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```ts
|
|
35
|
-
* const payment = usePaymentRequest({ methods, details: { total } });
|
|
36
|
-
* const result = await payment.show();
|
|
37
|
-
* if (result.status === "completed") await payment.complete(await charge(result.response));
|
|
38
|
-
* ```
|
|
39
|
-
*
|
|
40
|
-
* @param options Methods, details, hooks, and the constructor host.
|
|
41
|
-
* @returns Payment state and actions.
|
|
42
|
-
*/
|
|
43
18
|
function usePaymentRequest(options) {
|
|
44
19
|
const state = shallowRef("idle");
|
|
45
20
|
const response = shallowRef(void 0);
|
|
@@ -12,33 +12,6 @@ function browserPerformanceObserver() {
|
|
|
12
12
|
function isEntryOf(entry, types) {
|
|
13
13
|
return types.some((type) => type === entry.entryType);
|
|
14
14
|
}
|
|
15
|
-
/**
|
|
16
|
-
* Observe performance entries with callbacks typed by entry type.
|
|
17
|
-
*
|
|
18
|
-
* Each supported type is observed with its own `observe({ type })` call so
|
|
19
|
-
* `buffered` and `durationThreshold` apply. Types missing from
|
|
20
|
-
* `PerformanceObserver.supportedEntryTypes` are skipped; `supported` is false
|
|
21
|
-
* when none remain. The observer follows reactive `entryTypes` and is
|
|
22
|
-
* disconnected when the owning reactive scope stops; outside a scope the
|
|
23
|
-
* caller owns `stop()`.
|
|
24
|
-
*
|
|
25
|
-
* Server rendering: no observer is created and `supported` is false. Inside
|
|
26
|
-
* a component the observer connects after mounting, so hydration renders the
|
|
27
|
-
* server state first.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```ts
|
|
31
|
-
* usePerformanceObserver("largest-contentful-paint", (entries) => {
|
|
32
|
-
* console.log(entries.at(-1)?.renderTime);
|
|
33
|
-
* }, { buffered: true });
|
|
34
|
-
* ```
|
|
35
|
-
*
|
|
36
|
-
* @param entryTypes One entry type or a list of them.
|
|
37
|
-
* @param callback Receives batches of typed entries.
|
|
38
|
-
* @param options Constructor host and observation options.
|
|
39
|
-
* @default options {}
|
|
40
|
-
* @returns Observer state and actions.
|
|
41
|
-
*/
|
|
42
15
|
function usePerformanceObserver(entryTypes, callback, options = {}) {
|
|
43
16
|
const { durationThreshold } = options;
|
|
44
17
|
if (durationThreshold !== void 0 && (!Number.isFinite(durationThreshold) || durationThreshold < 0)) throw new RangeError(`[VIZE_COMPOSE_PERF_OBSERVER_INVALID_DURATION_THRESHOLD] durationThreshold must be a finite, non-negative number, received ${String(durationThreshold)}`);
|
package/dist/use-permission.mjs
CHANGED
|
@@ -11,32 +11,6 @@ function browserPermissions() {
|
|
|
11
11
|
function toDescriptor(name) {
|
|
12
12
|
return typeof name === "string" ? { name } : name;
|
|
13
13
|
}
|
|
14
|
-
/**
|
|
15
|
-
* Observe a browser permission reactively.
|
|
16
|
-
*
|
|
17
|
-
* The permission is queried when the composable is created and whenever
|
|
18
|
-
* the reactive name/descriptor or host changes; the `change` event of the
|
|
19
|
-
* returned `PermissionStatus` keeps `state` current (for example after the
|
|
20
|
-
* user revokes camera access in the site settings). The subscription is
|
|
21
|
-
* removed when the name changes and when the owning reactive scope stops.
|
|
22
|
-
*
|
|
23
|
-
* Server rendering: no browser window exists, so nothing is queried and
|
|
24
|
-
* `state` stays at `initialState` (`"unknown"`) with `supported` false.
|
|
25
|
-
* Unknown names (the browser rejects the query) report `"unsupported"`.
|
|
26
|
-
* Inside a component the first query runs after mounting, so hydration
|
|
27
|
-
* renders `initialState` exactly like the server did.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```ts
|
|
31
|
-
* const { state } = usePermission("camera");
|
|
32
|
-
* const canUseCamera = computed(() => state.value === "granted");
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* @param name Reactive permission name or full descriptor.
|
|
36
|
-
* @param options Capability host and initial state.
|
|
37
|
-
* @default options {}
|
|
38
|
-
* @returns The reactive permission state and a re-query control.
|
|
39
|
-
*/
|
|
40
14
|
function usePermission(name, options = {}) {
|
|
41
15
|
const initialState = options.initialState ?? "unknown";
|
|
42
16
|
const state = ref(initialState);
|
|
@@ -7,27 +7,6 @@ function browserLanguage() {
|
|
|
7
7
|
function renderMessage(message, count, formatted) {
|
|
8
8
|
return typeof message === "function" ? message(count, formatted) : message.replaceAll("{count}", formatted).replaceAll("#", formatted);
|
|
9
9
|
}
|
|
10
|
-
/**
|
|
11
|
-
* Choose and render a message by CLDR plural category (`Intl.PluralRules`).
|
|
12
|
-
*
|
|
13
|
-
* Messages are typed per category with a mandatory `other`, plus optional
|
|
14
|
-
* exact overrides (`"=0": "No items"`). Cardinal (`1 item`) and ordinal
|
|
15
|
-
* (`1st`, `2nd`) rules are supported via `type`. The count is formatted
|
|
16
|
-
* with the same locale for interpolation. Everything is derived state:
|
|
17
|
-
* no listeners or timers, deterministic during server rendering when the
|
|
18
|
-
* locale is explicit. Invalid options surface as the platform `RangeError`.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```ts
|
|
22
|
-
* const { message } = usePluralRules(count, { "=0": "No files", one: "# file", other: "# files" }, { locale: "en" });
|
|
23
|
-
* ```
|
|
24
|
-
*
|
|
25
|
-
* @param count Reactive count.
|
|
26
|
-
* @param messages Reactive messages per category.
|
|
27
|
-
* @param options Reactive locale and `Intl.PluralRules` options.
|
|
28
|
-
* @default options {}
|
|
29
|
-
* @returns Reactive category, message, and selection helpers.
|
|
30
|
-
*/
|
|
31
10
|
function usePluralRules(count, messages, options = {}) {
|
|
32
11
|
const localeControls = useLocale(() => toValue(options).locale, { detect: browserLanguage });
|
|
33
12
|
const rules = computed(() => {
|
|
@@ -28,34 +28,6 @@ function browserContainer() {
|
|
|
28
28
|
const { navigator } = window;
|
|
29
29
|
return "serviceWorker" in navigator && navigator.serviceWorker ? navigator.serviceWorker : void 0;
|
|
30
30
|
}
|
|
31
|
-
/**
|
|
32
|
-
* Manage a Web Push subscription.
|
|
33
|
-
*
|
|
34
|
-
* Uses the push manager of `options.registration`, or of
|
|
35
|
-
* `navigator.serviceWorker.ready` by default. The existing subscription is
|
|
36
|
-
* loaded when the registration becomes known; `subscribe` accepts the VAPID
|
|
37
|
-
* key as a base64url string. `json` is the snapshot to send to a push server.
|
|
38
|
-
* Nothing needs cleanup; pending results are ignored after the owning
|
|
39
|
-
* reactive scope stops.
|
|
40
|
-
*
|
|
41
|
-
* Server rendering: nothing is read, `supported` is false and the
|
|
42
|
-
* subscription is `null`.
|
|
43
|
-
* Inside a component the host is resolved after mounting, so hydration
|
|
44
|
-
* renders this server state first.
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* ```ts
|
|
48
|
-
* const push = usePushSubscription();
|
|
49
|
-
* const enable = async () => {
|
|
50
|
-
* await push.subscribe({ applicationServerKey: VAPID_PUBLIC_KEY });
|
|
51
|
-
* await fetch("/api/push", { method: "POST", body: JSON.stringify(push.json.value) });
|
|
52
|
-
* };
|
|
53
|
-
* ```
|
|
54
|
-
*
|
|
55
|
-
* @param options Registration override and initial read policy.
|
|
56
|
-
* @default options {}
|
|
57
|
-
* @returns Subscription state and actions.
|
|
58
|
-
*/
|
|
59
31
|
function usePushSubscription(options = {}) {
|
|
60
32
|
const subscription = shallowRef(null);
|
|
61
33
|
const error = shallowRef(void 0);
|
package/dist/use-queue.mjs
CHANGED
|
@@ -1,40 +1,11 @@
|
|
|
1
1
|
import { computed, shallowRef } from "vue";
|
|
2
2
|
//#region src/use-queue.ts
|
|
3
|
-
/** Compact the backing buffer once this many dequeued slots accumulate. */
|
|
4
3
|
const COMPACT_THRESHOLD = 32;
|
|
5
4
|
function validateCapacity(capacity) {
|
|
6
5
|
if (capacity === Number.POSITIVE_INFINITY) return capacity;
|
|
7
6
|
if (!Number.isSafeInteger(capacity) || capacity < 1) throw new RangeError(`[VIZE_COMPOSE_QUEUE_INVALID_CAPACITY] capacity must be a positive integer or Infinity; received ${String(capacity)}`);
|
|
8
7
|
return capacity;
|
|
9
8
|
}
|
|
10
|
-
/**
|
|
11
|
-
* Create a typed reactive FIFO queue.
|
|
12
|
-
*
|
|
13
|
-
* Dequeueing is amortized O(1): the head advances through a backing buffer
|
|
14
|
-
* that is compacted only after enough slots have been consumed, so large
|
|
15
|
-
* queues never pay for `Array.prototype.shift`. Reactivity is driven by a
|
|
16
|
-
* single version counter; `items`, `size`, `isEmpty`, and `peek` all
|
|
17
|
-
* re-evaluate after each mutation.
|
|
18
|
-
*
|
|
19
|
-
* Purely synchronous state: safe during server rendering (no host globals,
|
|
20
|
-
* no timers) and nothing to dispose.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```ts
|
|
24
|
-
* const jobs = useQueue<string>([], { capacity: 100, overflow: "reject" });
|
|
25
|
-
* jobs.enqueue("a", "b");
|
|
26
|
-
* jobs.dequeue(); // "a"
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* @typeParam Item Queued item type, inferred from `initial` when given.
|
|
30
|
-
* @param initial Items enqueued at creation, head first (overflow applies).
|
|
31
|
-
* @param options Capacity and overflow policy.
|
|
32
|
-
* @default initial []
|
|
33
|
-
* @default options {}
|
|
34
|
-
* @throws {RangeError} `[VIZE_COMPOSE_QUEUE_INVALID_CAPACITY]` when `capacity`
|
|
35
|
-
* is not a positive integer or `Infinity`.
|
|
36
|
-
* @returns The reactive queue and its controls.
|
|
37
|
-
*/
|
|
38
9
|
function useQueue(initial = [], options = {}) {
|
|
39
10
|
const capacity = validateCapacity(options.capacity ?? Number.POSITIVE_INFINITY);
|
|
40
11
|
const overflow = options.overflow ?? "drop-oldest";
|
package/dist/use-raf-fn.mjs
CHANGED
|
@@ -11,29 +11,6 @@ function resolveHost(scheduler) {
|
|
|
11
11
|
}
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
|
-
/**
|
|
15
|
-
* Run a callback on every animation frame, with pause/resume controls and an
|
|
16
|
-
* optional frame-rate cap.
|
|
17
|
-
*
|
|
18
|
-
* The host is resolved lazily on `resume()`, so importing and calling this
|
|
19
|
-
* during server rendering is safe: without a browser `window` (and without
|
|
20
|
-
* {@link UseRafFnOptions.runOnServer}), or without any frame host,
|
|
21
|
-
* `isActive` reports the requested state and no callbacks run, matching the
|
|
22
|
-
* client's initial render. The pending frame is cancelled when the owning reactive scope
|
|
23
|
-
* stops.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```ts
|
|
27
|
-
* const { pause } = useRafFn(({ delta }) => step(delta), { fpsLimit: 30 });
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* @param callback Invoked with frame timing for every delivered frame.
|
|
31
|
-
* @param options Start, rate-limit, and host policy.
|
|
32
|
-
* @default options {}
|
|
33
|
-
* @throws `RangeError` tagged `VIZE_COMPOSE_RAF_INVALID_FPS_LIMIT` when a
|
|
34
|
-
* resolved `fpsLimit` is not finite and greater than zero.
|
|
35
|
-
* @returns Pause/resume controls.
|
|
36
|
-
*/
|
|
37
14
|
function useRafFn(callback, options = {}) {
|
|
38
15
|
const isActive = shallowRef(false);
|
|
39
16
|
let host;
|
|
@@ -6,9 +6,7 @@ const MINUTE = 6e4;
|
|
|
6
6
|
const HOUR = 36e5;
|
|
7
7
|
const DAY = 864e5;
|
|
8
8
|
const WEEK = 6048e5;
|
|
9
|
-
/** Gregorian average month: 30.436875 days. */
|
|
10
9
|
const MONTH = 2629746e3;
|
|
11
|
-
/** Gregorian average year: 365.2425 days. */
|
|
12
10
|
const YEAR = 31556952e3;
|
|
13
11
|
const thresholds = [
|
|
14
12
|
[
|
|
@@ -42,17 +40,6 @@ const thresholds = [
|
|
|
42
40
|
"month"
|
|
43
41
|
]
|
|
44
42
|
];
|
|
45
|
-
/**
|
|
46
|
-
* Pick the largest unit that expresses a millisecond difference as a
|
|
47
|
-
* non-zero rounded amount: seconds below a minute, minutes below an hour,
|
|
48
|
-
* hours below a day, days below a week, weeks below a month, months below
|
|
49
|
-
* a year, and years otherwise (Gregorian average month/year lengths).
|
|
50
|
-
*
|
|
51
|
-
* @param diffMs Signed difference; negative is in the past.
|
|
52
|
-
* @returns The rounded amount and its unit.
|
|
53
|
-
* @throws {RangeError} `[VIZE_COMPOSE_RELATIVE_TIME_INVALID_DIFF]` for a
|
|
54
|
-
* non-finite difference.
|
|
55
|
-
*/
|
|
56
43
|
function selectRelativeTimeUnit(diffMs) {
|
|
57
44
|
if (!Number.isFinite(diffMs)) throw new RangeError(`[VIZE_COMPOSE_RELATIVE_TIME_INVALID_DIFF] the difference must be finite; received ${String(diffMs)}`);
|
|
58
45
|
const magnitude = Math.abs(diffMs);
|
|
@@ -68,28 +55,6 @@ function selectRelativeTimeUnit(diffMs) {
|
|
|
68
55
|
function browserLanguage() {
|
|
69
56
|
return typeof window === "undefined" ? void 0 : window.navigator.language;
|
|
70
57
|
}
|
|
71
|
-
/**
|
|
72
|
-
* Format relative times ("in 3 days", "yesterday") with `Intl.RelativeTimeFormat`.
|
|
73
|
-
*
|
|
74
|
-
* A pure formatting wrapper: it owns no clock or timer, so it never
|
|
75
|
-
* re-renders on its own and stays deterministic during server rendering
|
|
76
|
-
* (pair it with a clock composable for live "time ago" labels). The
|
|
77
|
-
* formatter follows the reactive options and is cached per locale and
|
|
78
|
-
* option set through {@link useLocale}; invalid options surface as the
|
|
79
|
-
* platform's `RangeError`.
|
|
80
|
-
*
|
|
81
|
-
* @example
|
|
82
|
-
* ```ts
|
|
83
|
-
* const { formatted } = useRelativeTimeFormat(-1, "day", { locale: "en", numeric: "auto" });
|
|
84
|
-
* formatted.value; // "yesterday"
|
|
85
|
-
* ```
|
|
86
|
-
*
|
|
87
|
-
* @param value Reactive signed amount; `null`/`undefined` format as `""`.
|
|
88
|
-
* @param unit Reactive unit.
|
|
89
|
-
* @param options Reactive locale and `Intl.RelativeTimeFormat` options.
|
|
90
|
-
* @default options {}
|
|
91
|
-
* @returns Reactive formatted output and formatting helpers.
|
|
92
|
-
*/
|
|
93
58
|
function useRelativeTimeFormat(value, unit, options = {}) {
|
|
94
59
|
const localeControls = useLocale(() => toValue(options).locale, { detect: browserLanguage });
|
|
95
60
|
const formatter = computed(() => {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { tryOnScopeDispose } from "./scope.mjs";
|
|
2
2
|
import { computed, hasInjectionContext, readonly, shallowRef, toValue, watch, watchPostEffect } from "vue";
|
|
3
3
|
//#region src/use-request-idle-callback.ts
|
|
4
|
-
/** Idle period length fabricated by the fallback, in milliseconds (the spec maximum). */
|
|
5
4
|
const FALLBACK_IDLE_PERIOD = 50;
|
|
6
5
|
function browserIdleHost() {
|
|
7
6
|
return typeof window !== "undefined" && typeof window.requestIdleCallback === "function" ? window : void 0;
|
|
@@ -19,7 +18,6 @@ function browserTimers() {
|
|
|
19
18
|
function validateTimeout(timeout) {
|
|
20
19
|
if (timeout !== void 0 && (!Number.isFinite(timeout) || timeout < 0)) throw new RangeError(`[VIZE_COMPOSE_IDLE_CALLBACK_INVALID_TIMEOUT] timeout must be a finite, non-negative number, received ${String(timeout)}`);
|
|
21
20
|
}
|
|
22
|
-
/** Schedule once; returns a canceller, or undefined when nothing could be scheduled. */
|
|
23
21
|
function scheduleIdle(options, callback) {
|
|
24
22
|
const host = options.host === void 0 ? browserIdleHost() : toValue(options.host);
|
|
25
23
|
if (host) {
|
|
@@ -38,30 +36,6 @@ function scheduleIdle(options, callback) {
|
|
|
38
36
|
}, 1);
|
|
39
37
|
return () => timers.clearTimeout(handle);
|
|
40
38
|
}
|
|
41
|
-
/**
|
|
42
|
-
* Run a callback in the next idle period with `requestIdleCallback`.
|
|
43
|
-
*
|
|
44
|
-
* When the API is missing, a `setTimeout` fallback fabricates a deadline
|
|
45
|
-
* with a 50 ms budget and `didTimeout: false`. The pending callback is
|
|
46
|
-
* cancelled when the owning reactive scope stops; outside a scope the
|
|
47
|
-
* caller owns `cancel()`.
|
|
48
|
-
*
|
|
49
|
-
* Server rendering: nothing is scheduled, `isPending` and `supported` are
|
|
50
|
-
* false. Inside a component the first callback is scheduled after mounting,
|
|
51
|
-
* so hydration renders the server state first.
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* ```ts
|
|
55
|
-
* const { start } = useRequestIdleCallback((deadline) => {
|
|
56
|
-
* while (deadline.timeRemaining() > 1 && queue.length) queue.shift()?.();
|
|
57
|
-
* }, { timeout: 2000, immediate: false });
|
|
58
|
-
* ```
|
|
59
|
-
*
|
|
60
|
-
* @param callback Receives the idle deadline.
|
|
61
|
-
* @param options Hosts, timeout and start policy.
|
|
62
|
-
* @default options {}
|
|
63
|
-
* @returns Scheduling state and actions.
|
|
64
|
-
*/
|
|
65
39
|
function useRequestIdleCallback(callback, options = {}) {
|
|
66
40
|
validateTimeout(options.timeout);
|
|
67
41
|
const isPending = shallowRef(false);
|
|
@@ -101,22 +75,6 @@ function useRequestIdleCallback(callback, options = {}) {
|
|
|
101
75
|
cancel
|
|
102
76
|
};
|
|
103
77
|
}
|
|
104
|
-
/**
|
|
105
|
-
* Resolve in the next idle period (or after `timeout`).
|
|
106
|
-
*
|
|
107
|
-
* Uses the same hosts and fallback as {@link useRequestIdleCallback}. When
|
|
108
|
-
* neither an idle host nor timers resolve (server rendering) it resolves on
|
|
109
|
-
* the next microtask with an exhausted deadline instead of hanging.
|
|
110
|
-
*
|
|
111
|
-
* @example
|
|
112
|
-
* ```ts
|
|
113
|
-
* await idle({ timeout: 1000 });
|
|
114
|
-
* ```
|
|
115
|
-
*
|
|
116
|
-
* @param options Hosts, timeout and abort signal.
|
|
117
|
-
* @default options {}
|
|
118
|
-
* @returns The idle deadline; rejects with `signal.reason` when aborted.
|
|
119
|
-
*/
|
|
120
78
|
function idle(options = {}) {
|
|
121
79
|
validateTimeout(options.timeout);
|
|
122
80
|
const { signal } = options;
|