@vuetify/v0 0.0.20 → 0.0.22

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.
@@ -1,2968 +0,0 @@
1
- import { _ as range, d as isObject, h as isUndefined, l as isNullOrUndefined, m as isSymbol, o as isFunction, p as isString, r as genId, s as isNaN } from "./utilities-BrFKLHFS.mjs";
2
- import { a as SUPPORTS_OBSERVER, s as __LOGGER_ENABLED__, t as IN_BROWSER } from "./globals-exvZ8fiO.mjs";
3
- import { computed, getCurrentInstance, inject, isRef, onScopeDispose, provide, reactive, shallowReactive, shallowReadonly, shallowRef, toRef, toValue, watch, watchEffect } from "vue";
4
-
5
- //#region src/composables/createContext/index.ts
6
- /**
7
- * Injects a context provided by an ancestor component.
8
- *
9
- * @param key The key of the context to inject.
10
- * @param defaultValue Optional default value if context is not found.
11
- * @template Z The type of the context.
12
- * @returns The injected context.
13
- * @throws An error if the context is not found and no default is provided.
14
- *
15
- * @see https://vuejs.org/api/composition-api-dependency-injection.html#inject
16
- * @see https://0.vuetifyjs.com/composables/foundation/create-context#use-context
17
- *
18
- * @example
19
- * ```ts
20
- * // Without default value
21
- * const context = useContext<MyContext>('my-context')
22
- *
23
- * // With default value
24
- * const context = useContext<MyContext>('my-context', defaultContext)
25
- * ```
26
- */
27
- function useContext(key, defaultValue) {
28
- const context = inject(key, defaultValue);
29
- if (/* @__PURE__ */ isUndefined(context)) throw new Error(`Context "${String(key)}" not found. Ensure it's provided by an ancestor.`);
30
- return context;
31
- }
32
- /**
33
- * Provides a context to all descendant components.
34
- *
35
- * @param key The key of the context to provide.
36
- * @param context The context to provide.
37
- * @param app Optional Vue app instance to provide the context at app level instead of component level.
38
- * @template Z The type of the context.
39
- * @returns The provided context.
40
- *
41
- * @remarks
42
- * When `app` parameter is provided, the context is made available to all components in the app.
43
- * When omitted, the context is provided at the current component level and available to descendants only.
44
- *
45
- * @see https://vuejs.org/api/composition-api-dependency-injection.html#provide
46
- * @see https://0.vuetifyjs.com/composables/foundation/create-context#provide-context
47
- *
48
- * @example
49
- * ```ts
50
- * // Component-level provision
51
- * provideContext<MyContext>('my-context', context)
52
- *
53
- * // App-level provision (typically used in plugins)
54
- * const app = createApp()
55
- * provideContext<MyContext>('my-context', context, app)
56
- * ```
57
- */
58
- function provideContext(key, context, app) {
59
- if (app) app.provide(key, context);
60
- else provide(key, context);
61
- return context;
62
- }
63
- function createContext(keyOrOptions, defaultValue) {
64
- if (/* @__PURE__ */ isString(keyOrOptions) || /* @__PURE__ */ isSymbol(keyOrOptions)) {
65
- const _key = keyOrOptions;
66
- function _provideContext$1(context, app) {
67
- return provideContext(_key, context, app);
68
- }
69
- function _useContext$1() {
70
- return useContext(_key, defaultValue);
71
- }
72
- return [_useContext$1, _provideContext$1];
73
- }
74
- const suffix = /* @__PURE__ */ isObject(keyOrOptions) ? keyOrOptions.suffix : void 0;
75
- function _provideContext(key, context, app) {
76
- return provideContext(suffix ? `${key}:${suffix}` : key, context, app);
77
- }
78
- function _useContext(key, defaultValue$1) {
79
- return useContext(suffix ? `${key}:${suffix}` : key, defaultValue$1);
80
- }
81
- return [_useContext, _provideContext];
82
- }
83
-
84
- //#endregion
85
- //#region src/composables/createTrinity/index.ts
86
- /**
87
- * Creates a new trinity for a context composable and its provider.
88
- *
89
- * @param useContext The function that retrieves/uses the context (typically named `useContext`).
90
- * @param provideContext The function that provides the context to descendants.
91
- * @param context The default context instance to use when no custom context is provided.
92
- * @template Z The type of the context.
93
- * @returns A readonly tuple containing: [useContext function, provideContext wrapper function, default context instance].
94
- *
95
- * @remarks The trinity pattern is a foundational pattern used throughout the codebase for creating reusable context systems. It provides three related elements:
96
- *
97
- * 1. A function to retrieve/use the context
98
- * 2. A function to provide the context (with default value support)
99
- * 3. The default context instance
100
- *
101
- * The returned tuple is readonly (using `as const`) to ensure proper type inference.
102
- *
103
- * @see https://0.vuetifyjs.com/composables/foundation/create-trinity#create-trinity
104
- *
105
- * @example
106
- * ```ts
107
- * interface MyContext {
108
- * foo: string
109
- * bar: number
110
- * }
111
- *
112
- * export function createMyFeature<E extends MyContext = MyContext>() {
113
- * const [useContext, _provideContext] = createContext<E>('my-context')
114
- *
115
- * const context = { foo: 'hello', bar: 42 }
116
- *
117
- * function provideContext (_context: E = context, app?: App): E {
118
- * return _provideContext(_context, app)
119
- * }
120
- *
121
- * return createTrinity<E>(useContext, provideContext, context)
122
- * }
123
- * ```
124
- */
125
- function createTrinity(useContext$1, provideContext$1, context) {
126
- return [
127
- useContext$1,
128
- (_context = context, app) => provideContext$1(_context, app),
129
- context
130
- ];
131
- }
132
-
133
- //#endregion
134
- //#region src/composables/createPlugin/index.ts
135
- /**
136
- * Creates a new Vue plugin.
137
- *
138
- * @param options The plugin options.
139
- * @returns A new Vue plugin.
140
- *
141
- * @see https://0.vuetifyjs.com/composables/foundation/create-plugin#create-plugin
142
- *
143
- * @example
144
- * ```ts
145
- * export const [useContext, provideContext] = createContext<MyContext>('my-plugin')
146
- *
147
- * const context = {}
148
- *
149
- * export const MyPlugin = createPlugin({
150
- * namespace: 'my-plugin',
151
- * provide: (app) => {
152
- * provideContext(context, app)
153
- * },
154
- * setup: (app) => {
155
- * // Optional setup logic
156
- * },
157
- * })
158
- */
159
- function createPlugin(options) {
160
- return { install(app) {
161
- app.runWithContext(() => {
162
- options.provide(app);
163
- options.setup?.(app);
164
- });
165
- } };
166
- }
167
-
168
- //#endregion
169
- //#region src/composables/useLogger/adapters/consola.ts
170
- var ConsolaLoggerAdapter = class {
171
- consola;
172
- constructor(consolaInstance) {
173
- if (!consolaInstance) throw new Error("Consola instance is required for ConsolaLoggerAdapter");
174
- this.consola = consolaInstance;
175
- }
176
- debug(message, ...args) {
177
- this.consola.debug(message, ...args);
178
- }
179
- info(message, ...args) {
180
- this.consola.info(message, ...args);
181
- }
182
- warn(message, ...args) {
183
- this.consola.warn(message, ...args);
184
- }
185
- error(message, ...args) {
186
- this.consola.error(message, ...args);
187
- }
188
- trace(message, ...args) {
189
- if (this.consola.trace) this.consola.trace(message, ...args);
190
- else this.consola.debug(message, ...args);
191
- }
192
- fatal(message, ...args) {
193
- if (this.consola.fatal) this.consola.fatal(message, ...args);
194
- else this.consola.error("[FATAL]", message, ...args);
195
- }
196
- };
197
-
198
- //#endregion
199
- //#region src/composables/useLogger/adapters/pino.ts
200
- /**
201
- * Pino logger adapter implementation
202
- *
203
- * This adapter integrates with the Pino logging library,
204
- * providing high-performance structured logging optimized
205
- * for Node.js applications with minimal overhead.
206
- */
207
- var PinoLoggerAdapter = class {
208
- pino;
209
- constructor(pinoInstance) {
210
- if (!pinoInstance) throw new Error("Pino instance is required for PinoLoggerAdapter");
211
- this.pino = pinoInstance;
212
- }
213
- debug(message, ...args) {
214
- this.pino.debug(this.format(message, ...args));
215
- }
216
- info(message, ...args) {
217
- this.pino.info(this.format(message, ...args));
218
- }
219
- warn(message, ...args) {
220
- this.pino.warn(this.format(message, ...args));
221
- }
222
- error(message, ...args) {
223
- this.pino.error(this.format(message, ...args));
224
- }
225
- trace(message, ...args) {
226
- this.pino.trace(this.format(message, ...args));
227
- }
228
- fatal(message, ...args) {
229
- this.pino.fatal(this.format(message, ...args));
230
- }
231
- format(message, ...args) {
232
- if (args.length === 0) return { msg: message };
233
- if (args.length === 1 && /* @__PURE__ */ isObject(args[0])) return {
234
- ...args[0],
235
- msg: message
236
- };
237
- return {
238
- msg: message,
239
- args
240
- };
241
- }
242
- };
243
-
244
- //#endregion
245
- //#region src/composables/useLogger/adapters/v0.ts
246
- /**
247
- * Vuetify0.x logger adapter implementation
248
- *
249
- * This adapter provides console-based logging with proper formatting,
250
- * color coding, timestamps, and log level filtering for development
251
- * and production environments.
252
- */
253
- var Vuetify0LoggerAdapter = class {
254
- prefix;
255
- colors;
256
- timestamps;
257
- constructor(options = {}) {
258
- this.prefix = options.prefix || "v0";
259
- this.colors = options.colors !== false;
260
- this.timestamps = options.timestamps !== false;
261
- }
262
- debug(message, ...args) {
263
- this.log("debug", "debug", message, ...args);
264
- }
265
- info(message, ...args) {
266
- this.log("info", "info", message, ...args);
267
- }
268
- warn(message, ...args) {
269
- this.log("warn", "warn", message, ...args);
270
- }
271
- error(message, ...args) {
272
- this.log("error", "error", message, ...args);
273
- }
274
- trace(message, ...args) {
275
- this.log("trace", "trace", message, ...args);
276
- }
277
- fatal(message, ...args) {
278
- this.log("fatal", "error", message, ...args);
279
- }
280
- format(level, message, ...args) {
281
- return [[
282
- this.timestamps ? this.timestamp() : "",
283
- `[${this.prefix} ${level.toLowerCase()}]`,
284
- message
285
- ].filter(Boolean).join(" "), ...args];
286
- }
287
- timestamp() {
288
- if (!IN_BROWSER) return (/* @__PURE__ */ new Date()).toISOString();
289
- return (/* @__PURE__ */ new Date()).toTimeString().split(" ")[0] ?? "";
290
- }
291
- style(level) {
292
- if (!this.colors || !IN_BROWSER) return "";
293
- return {
294
- trace: "color: #64748b",
295
- debug: "color: #3b82f6",
296
- info: "color: #10b981",
297
- warn: "color: #f59e0b",
298
- error: "color: #ef4444",
299
- fatal: "color: #dc2626; font-weight: bold",
300
- silent: ""
301
- }[level] || "";
302
- }
303
- log(level, method, message, ...args) {
304
- const [formattedMessage, ...restArgs] = this.format(level, message, ...args);
305
- const style = this.style(level);
306
- if (IN_BROWSER && style && /* @__PURE__ */ isFunction(console[method])) console[method](`%c${formattedMessage}`, style, ...restArgs);
307
- else if (/* @__PURE__ */ isFunction(console[method])) console[method](formattedMessage, ...restArgs);
308
- }
309
- };
310
-
311
- //#endregion
312
- //#region src/composables/useLogger/index.ts
313
- /**
314
- * @module useLogger
315
- *
316
- * @see https://0.vuetifyjs.com/composables/plugins/use-logger
317
- *
318
- * @remarks
319
- * Logging composable with adapter pattern supporting console, consola, and pino.
320
- *
321
- * Key features:
322
- * - Multiple log levels (trace, debug, info, warn, error, fatal)
323
- * - Adapter pattern for console/consola/pino integration
324
- * - Enable/disable logging
325
- * - Fallback logger for undefined loggers
326
- * - Context logging support
327
- *
328
- * Uses adapter pattern to abstract logging implementation.
329
- */
330
- /**
331
- * Creates a new logger instance.
332
- *
333
- * @param options The options for the logger instance.
334
- * @returns A new logger instance.
335
- *
336
- * @see https://0.vuetifyjs.com/composables/plugins/use-logger
337
- *
338
- * @example
339
- * ```ts
340
- * import { createLogger } from '@vuetify/v0'
341
- *
342
- * const logger = createLogger({
343
- * level: 'debug',
344
- * prefix: '[MyApp]',
345
- * })
346
- *
347
- * logger.info('This is an info message')
348
- * logger.debug('This is a debug message')
349
- * logger.error('This is an error message')
350
- * logger.level('debug')
351
- * logger.debug('This debug message will now be logged')
352
- * ```
353
- */
354
- function createLogger(options = {}) {
355
- const { adapter = new Vuetify0LoggerAdapter({ prefix: options.prefix }), level: initialLevel = "info", enabled: initialEnabled = __LOGGER_ENABLED__ } = options;
356
- const currentLevel = shallowRef(initialLevel);
357
- const isEnabled = shallowRef(initialEnabled);
358
- function value(level$1) {
359
- return {
360
- trace: 0,
361
- debug: 1,
362
- info: 2,
363
- warn: 3,
364
- error: 4,
365
- fatal: 5,
366
- silent: 6
367
- }[level$1] ?? 2;
368
- }
369
- function can(level$1) {
370
- if (!isEnabled.value) return false;
371
- return value(level$1) >= value(currentLevel.value);
372
- }
373
- function format(message) {
374
- return message;
375
- }
376
- function debug(message, ...args) {
377
- if (can("debug")) adapter.debug(format(message), ...args);
378
- }
379
- function info(message, ...args) {
380
- if (can("info")) adapter.info(format(message), ...args);
381
- }
382
- function warn(message, ...args) {
383
- if (can("warn")) adapter.warn(format(message), ...args);
384
- }
385
- function error(message, ...args) {
386
- if (can("error")) adapter.error(format(message), ...args);
387
- }
388
- function trace(message, ...args) {
389
- if (can("trace")) adapter.trace?.(format(message), ...args);
390
- }
391
- function fatal(message, ...args) {
392
- if (can("fatal")) adapter.fatal?.(format(message), ...args);
393
- }
394
- function level(newLevel) {
395
- currentLevel.value = newLevel;
396
- }
397
- function current() {
398
- return currentLevel.value;
399
- }
400
- function enabled() {
401
- return isEnabled.value;
402
- }
403
- function enable() {
404
- isEnabled.value = true;
405
- }
406
- function disable() {
407
- isEnabled.value = false;
408
- }
409
- return {
410
- debug,
411
- info,
412
- warn,
413
- error,
414
- trace,
415
- fatal,
416
- level,
417
- current,
418
- enabled,
419
- enable,
420
- disable
421
- };
422
- }
423
- function createFallbackLogger(namespace = "v0:logger") {
424
- function format(message, type) {
425
- return `[${namespace} ${type}] ${message}`;
426
- }
427
- return {
428
- debug: (message, ...args) => console.debug(format(message, "debug"), ...args),
429
- info: (message, ...args) => console.info(format(message, "info"), ...args),
430
- warn: (message, ...args) => console.warn(format(message, "warn"), ...args),
431
- error: (message, ...args) => console.error(format(message, "error"), ...args),
432
- trace: (message, ...args) => console.trace(format(message, "trace"), ...args),
433
- fatal: (message, ...args) => console.error(format(message, "fatal"), ...args),
434
- level: () => {},
435
- current: () => "info",
436
- enabled: () => true,
437
- enable: () => {},
438
- disable: () => {}
439
- };
440
- }
441
- /**
442
- * Creates a new logger context.
443
- *
444
- * @param options The options for the logger context.
445
- * @template E The type of the logger context.
446
- * @returns A new logger context.
447
- *
448
- * @see https://0.vuetifyjs.com/composables/plugins/use-logger
449
- *
450
- * @example
451
- * ```ts
452
- * import { createLoggerContext } from '@vuetify/v0'
453
- *
454
- * export const [useAppLogger, provideAppLogger, appLogger] = createLoggerContext({
455
- * namespace: 'app:logger',
456
- * level: 'debug',
457
- * })
458
- * ```
459
- */
460
- function createLoggerContext(_options = {}) {
461
- const { namespace = "v0:logger", ...options } = _options;
462
- const [useLoggerContext, _provideLoggerContext] = createContext(namespace);
463
- const context = createLogger(options);
464
- function provideLoggerContext(_context = context, app) {
465
- return _provideLoggerContext(_context, app);
466
- }
467
- return createTrinity(useLoggerContext, provideLoggerContext, context);
468
- }
469
- /**
470
- * Creates a new logger plugin.
471
- *
472
- * @param options The options for the logger plugin.
473
- * @returns A new logger plugin.
474
- *
475
- * @see https://0.vuetifyjs.com/composables/plugins/use-logger
476
- *
477
- * @example
478
- * ```ts
479
- * import { createApp } from 'vue'
480
- * import { createLoggerPlugin } from '@vuetify/v0'
481
- * import App from './App.vue'
482
- *
483
- * const app = createApp(App)
484
- *
485
- * app.use(
486
- * createLoggerPlugin({
487
- * level: 'debug',
488
- * prefix: '[MyApp]',
489
- * })
490
- * )
491
- *
492
- * app.mount('#app')
493
- * ```
494
- */
495
- function createLoggerPlugin(_options = {}) {
496
- const { namespace = "v0:logger", ...options } = _options;
497
- const [, provideLoggerContext, context] = createLoggerContext({
498
- ...options,
499
- namespace
500
- });
501
- return createPlugin({
502
- namespace,
503
- provide: (app) => {
504
- provideLoggerContext(context, app);
505
- },
506
- setup: (_app) => {
507
- if (process.env.NODE_ENV !== "production" && IN_BROWSER) window.__v0Logger__ = context;
508
- }
509
- });
510
- }
511
- /**
512
- * Uses an existing or creates a new logger instance.
513
- *
514
- * @param namespace The namespace for the logger context. Defaults to `'v0:logger'`.
515
- * @returns The logger instance.
516
- *
517
- * @see https://0.vuetifyjs.com/composables/plugins/use-logger
518
- *
519
- * @example
520
- * ```ts
521
- * import { useLogger } from '@vuetify/v0'
522
- *
523
- * const logger = useLogger()
524
- *
525
- * logger.info('This is an info message')
526
- * logger.debug('This is a debug message')
527
- * logger.error('This is an error message')
528
- * logger.level('debug')
529
- * logger.debug('This debug message will now be logged')
530
- * ```
531
- */
532
- function useLogger(namespace = "v0:logger") {
533
- const fallback = createFallbackLogger(namespace);
534
- if (!getCurrentInstance()) return fallback;
535
- try {
536
- return useContext(namespace, fallback);
537
- } catch {
538
- return fallback;
539
- }
540
- }
541
-
542
- //#endregion
543
- //#region src/composables/useRegistry/index.ts
544
- /**
545
- * Creates a new registry instance.
546
- *
547
- * @param options The options for the registry instance.
548
- * @template Z The type of registry ticket that extends RegistryTicket. Use this to add custom properties to tickets.
549
- * @template E The type of registry context that extends RegistryContext<Z>. Use this when extending the registry with additional methods.
550
- * @returns A new registry instance.
551
- *
552
- * @see https://0.vuetifyjs.com/composables/registration/use-registry#use-registry
553
- *
554
- * @example
555
- * ```ts
556
- * import { useRegistry } from '@vuetify/v0'
557
- *
558
- * const registry = useRegistry()
559
- *
560
- * const ticket1 = registry.register({ id: 'user-1', value: { name: 'John' } })
561
- * const ticket2 = registry.register({ id: 'user-2', value: { name: 'Jane' } })
562
- *
563
- * console.log(registry.size) // 2
564
- * console.log(registry.get('user-1')) // { id: 'user-1', index: 0, value: { name: 'John' }, ... }
565
- * ```
566
- */
567
- function useRegistry(options) {
568
- const logger = useLogger();
569
- const collection = /* @__PURE__ */ new Map();
570
- const catalog = /* @__PURE__ */ new Map();
571
- const directory = /* @__PURE__ */ new Map();
572
- const cache = /* @__PURE__ */ new Map();
573
- const listeners = /* @__PURE__ */ new Map();
574
- const events = options?.events ?? false;
575
- let indexDependentCount = 0;
576
- let needsReindex = false;
577
- let minDirtyIndex = Infinity;
578
- let batching = false;
579
- let pendingEmits = [];
580
- function emit(event, data = void 0) {
581
- if (!events) return;
582
- const cbs = listeners.get(event);
583
- if (!cbs) return;
584
- for (const cb of cbs) cb(data);
585
- }
586
- function on(event, cb) {
587
- if (!events) {
588
- logger.warn(`Events are disabled. Initialize with \`useRegistry({ events: true })\` to enable.`);
589
- return;
590
- }
591
- if (!listeners.has(event)) listeners.set(event, /* @__PURE__ */ new Set());
592
- listeners.get(event).add(cb);
593
- }
594
- function off(event, cb) {
595
- if (!events) {
596
- logger.warn(`Events are disabled. Initialize with \`useRegistry({ events: true })\` to enable.`);
597
- return;
598
- }
599
- listeners.get(event)?.delete(cb);
600
- }
601
- function dispose() {
602
- listeners.clear();
603
- clear();
604
- }
605
- function get(id) {
606
- return collection.get(id);
607
- }
608
- function upsert(id, patch = {}) {
609
- const existing = get(id);
610
- if (!existing) return register({
611
- ...patch,
612
- id
613
- });
614
- const hasValue = Object.prototype.hasOwnProperty.call(patch, "value");
615
- let value = existing.value;
616
- let valueIsIndex = existing.valueIsIndex;
617
- if (hasValue) {
618
- if (/* @__PURE__ */ isUndefined(patch.value)) {
619
- value = existing.index;
620
- valueIsIndex = true;
621
- } else {
622
- value = patch.value;
623
- valueIsIndex = false;
624
- }
625
- if (valueIsIndex !== existing.valueIsIndex) if (valueIsIndex) indexDependentCount++;
626
- else indexDependentCount--;
627
- if (!Object.is(value, existing.value)) {
628
- unassign(existing.value, id);
629
- assign(value, id);
630
- }
631
- }
632
- const updated = {
633
- ...existing,
634
- ...patch,
635
- id,
636
- index: existing.index,
637
- value,
638
- valueIsIndex
639
- };
640
- collection.set(id, updated);
641
- invalidate();
642
- emit("update:ticket", updated);
643
- return updated;
644
- }
645
- function browse(value) {
646
- if (indexDependentCount > 0 && needsReindex) reindex();
647
- return catalog.get(value);
648
- }
649
- function lookup(index) {
650
- if (needsReindex) reindex();
651
- return directory.get(index);
652
- }
653
- function has(id) {
654
- return collection.has(id);
655
- }
656
- function assign(value, id) {
657
- const bucket = catalog.get(value);
658
- if (bucket) {
659
- if (!bucket.includes(id)) bucket.push(id);
660
- } else catalog.set(value, [id]);
661
- }
662
- function unassign(value, id) {
663
- const bucket = catalog.get(value);
664
- if (!bucket) return;
665
- const next = bucket.filter((v) => v !== id);
666
- if (next.length === 0) catalog.delete(value);
667
- else catalog.set(value, next);
668
- }
669
- function keys() {
670
- const cached = cache.get("keys");
671
- if (!/* @__PURE__ */ isUndefined(cached)) return cached;
672
- const keys$1 = Array.from(collection.keys());
673
- cache.set("keys", keys$1);
674
- return keys$1;
675
- }
676
- function values() {
677
- const cached = cache.get("values");
678
- if (!/* @__PURE__ */ isUndefined(cached)) return cached;
679
- const values$1 = Array.from(collection.values());
680
- cache.set("values", values$1);
681
- return values$1;
682
- }
683
- function entries() {
684
- const cached = cache.get("entries");
685
- if (!/* @__PURE__ */ isUndefined(cached)) return cached;
686
- const entries$1 = Array.from(collection.entries());
687
- cache.set("entries", entries$1);
688
- return entries$1;
689
- }
690
- function clear() {
691
- collection.clear();
692
- catalog.clear();
693
- directory.clear();
694
- invalidate();
695
- indexDependentCount = 0;
696
- needsReindex = false;
697
- minDirtyIndex = Infinity;
698
- emit("clear:registry");
699
- }
700
- function invalidate() {
701
- if (batching) return;
702
- cache.clear();
703
- }
704
- function queueEmit(event, data) {
705
- if (batching) pendingEmits.push({
706
- event,
707
- data
708
- });
709
- else emit(event, data);
710
- }
711
- function batch(fn) {
712
- if (batching) return fn();
713
- batching = true;
714
- pendingEmits = [];
715
- try {
716
- const result = fn();
717
- cache.clear();
718
- for (const { event, data } of pendingEmits) emit(event, data);
719
- return result;
720
- } finally {
721
- batching = false;
722
- pendingEmits = [];
723
- }
724
- }
725
- function reindex() {
726
- const startIndex = minDirtyIndex === Infinity ? 0 : minDirtyIndex;
727
- if (startIndex === 0) {
728
- catalog.clear();
729
- directory.clear();
730
- }
731
- invalidate();
732
- let index = 0;
733
- for (const ticket of collection.values()) {
734
- if (index < startIndex) {
735
- index++;
736
- continue;
737
- }
738
- if (startIndex > 0) directory.delete(ticket.index);
739
- if (ticket.valueIsIndex) {
740
- if (startIndex > 0) unassign(ticket.value, ticket.id);
741
- ticket.value = index;
742
- assign(ticket.value, ticket.id);
743
- } else if (startIndex === 0) assign(ticket.value, ticket.id);
744
- ticket.index = index;
745
- directory.set(index, ticket.id);
746
- index++;
747
- }
748
- needsReindex = false;
749
- minDirtyIndex = Infinity;
750
- emit("reindex:registry");
751
- }
752
- function register(registration = {}) {
753
- const size = collection.size;
754
- const id = registration.id ?? /* @__PURE__ */ genId();
755
- if (has(id)) {
756
- logger.warn(`Ticket "${id}" already exists. Use \`upsert()\` to update or check \`has()\` before registering.`);
757
- return get(id);
758
- }
759
- const valueIsUndefined = /* @__PURE__ */ isUndefined(registration.value);
760
- const index = registration.index ?? size;
761
- const value = valueIsUndefined ? index : registration.value;
762
- const valueIsIndex = valueIsUndefined;
763
- if (valueIsIndex) indexDependentCount++;
764
- const ticket = {
765
- ...registration,
766
- id,
767
- index,
768
- value,
769
- valueIsIndex
770
- };
771
- collection.set(ticket.id, ticket);
772
- directory.set(ticket.index, ticket.id);
773
- assign(ticket.value, ticket.id);
774
- invalidate();
775
- queueEmit("register:ticket", ticket);
776
- return ticket;
777
- }
778
- function unregister(id) {
779
- const ticket = collection.get(id);
780
- if (!ticket) return;
781
- if (ticket.valueIsIndex) indexDependentCount--;
782
- collection.delete(ticket.id);
783
- directory.delete(ticket.index);
784
- unassign(ticket.value, ticket.id);
785
- const willReindex = indexDependentCount > 0 && ticket.index < collection.size;
786
- if (!willReindex) invalidate();
787
- emit("unregister:ticket", ticket);
788
- minDirtyIndex = Math.min(minDirtyIndex, ticket.index);
789
- if (willReindex) reindex();
790
- else needsReindex = true;
791
- }
792
- function offboard(ids) {
793
- const removed = [];
794
- for (const id of ids) {
795
- const ticket = collection.get(id);
796
- if (!ticket) continue;
797
- if (ticket.valueIsIndex) indexDependentCount--;
798
- minDirtyIndex = Math.min(minDirtyIndex, ticket.index);
799
- collection.delete(ticket.id);
800
- directory.delete(ticket.index);
801
- unassign(ticket.value, ticket.id);
802
- removed.push(ticket);
803
- }
804
- if (removed.length === 0) return;
805
- invalidate();
806
- for (const ticket of removed) queueEmit("unregister:ticket", ticket);
807
- needsReindex = true;
808
- }
809
- function seek(direction = "first", from, predicate) {
810
- if (collection.size === 0) return void 0;
811
- if (needsReindex) reindex();
812
- if (!predicate && /* @__PURE__ */ isUndefined(from)) {
813
- const tickets$1 = values();
814
- return direction === "first" ? tickets$1[0] : tickets$1.at(-1);
815
- }
816
- const tickets = values();
817
- const index = /* @__PURE__ */ isUndefined(from) ? void 0 : Math.max(0, Math.min(from, tickets.length - 1));
818
- if (direction === "last") {
819
- const start = /* @__PURE__ */ isUndefined(index) ? tickets.length - 1 : index;
820
- for (let i = start; i >= 0; i--) {
821
- const ticket = tickets[i];
822
- if (!predicate || predicate(ticket)) return ticket;
823
- }
824
- } else {
825
- const start = /* @__PURE__ */ isUndefined(index) ? 0 : index;
826
- for (let i = start; i < tickets.length; i++) {
827
- const ticket = tickets[i];
828
- if (!predicate || predicate(ticket)) return ticket;
829
- }
830
- }
831
- }
832
- return {
833
- collection,
834
- emit,
835
- on,
836
- off,
837
- dispose,
838
- has,
839
- keys,
840
- clear,
841
- browse,
842
- entries,
843
- values,
844
- lookup,
845
- get,
846
- upsert,
847
- register,
848
- unregister,
849
- reindex,
850
- seek,
851
- batch,
852
- onboard(registrations) {
853
- return batch(() => registrations.map((registration) => register(registration)));
854
- },
855
- offboard,
856
- get size() {
857
- return collection.size;
858
- }
859
- };
860
- }
861
- /**
862
- * Creates a new registry context.
863
- *
864
- * @param options The options for the registry context, including `namespace` (defaults to `'v0:registry'`) and `events`.
865
- * @template Z The type of registry ticket that extends RegistryTicket. Use this to add custom properties to tickets.
866
- * @template E The type of registry context that extends RegistryContext<Z>. Use this when extending the registry with additional methods.
867
- * @returns A new registry context.
868
- *
869
- * @see https://0.vuetifyjs.com/composables/registration/use-registry#create-registry-context
870
- *
871
- * @example
872
- * ```ts
873
- * import { createRegistryContext } from '@vuetify/v0'
874
- *
875
- * // With default namespace 'v0:registry'
876
- * export const [useItems, provideItems, items] = createRegistryContext()
877
- *
878
- * // Or with custom namespace
879
- * export const [useItems, provideItems, items] = createRegistryContext({ namespace: 'my-items' })
880
- *
881
- * // In a parent component:
882
- * provideItems()
883
- *
884
- * // In a child component:
885
- * const items = useItems()
886
- * items.register({ id: 'item-1', value: 'Value 1' })
887
- * ```
888
- */
889
- function createRegistryContext(_options = {}) {
890
- const { namespace = "v0:registry", ...options } = _options;
891
- const [useRegistryContext, _provideRegistryContext] = createContext(namespace);
892
- const context = useRegistry(options);
893
- function provideRegistryContext(_context = context, app) {
894
- return _provideRegistryContext(_context, app);
895
- }
896
- return createTrinity(useRegistryContext, provideRegistryContext, context);
897
- }
898
-
899
- //#endregion
900
- //#region src/composables/useSelection/index.ts
901
- /**
902
- * Creates a new selection instance for managing multiple selected items.
903
- *
904
- * Extends `useRegistry` with selection tracking via a reactive `Set` of selected IDs.
905
- * Supports disabled items, mandatory selection enforcement, and auto-enrollment.
906
- *
907
- * @param options The options for the selection instance.
908
- * @template Z The type of the selection ticket.
909
- * @template E The type of the selection context.
910
- * @returns A new selection instance with selection management methods.
911
- *
912
- * @remarks
913
- * **Key Features:**
914
- * - Multi-selection support (unlike `useSingle` which enforces single selection)
915
- * - Set-based `selectedIds` tracking for efficient lookups
916
- * - Computed `selectedItems` and `selectedValues` for reactive access
917
- * - Each ticket gets `isSelected`, `select()`, `unselect()`, and `toggle()` methods
918
- * - Disabled items cannot be selected
919
- * - Mandatory mode prevents deselecting the last item
920
- * - Force mode auto-selects first non-disabled item on registration
921
- * - Enroll option auto-selects all non-disabled items on registration
922
- *
923
- * **Inheritance Chain:**
924
- * `useRegistry` → `createSelection` → `createSingle`/`createGroup` → `createStep`
925
- *
926
- * @see https://0.vuetifyjs.com/composables/selection/use-selection
927
- *
928
- * @example
929
- * ```ts
930
- * import { createSelection } from '@vuetify/v0'
931
- *
932
- * const selection = createSelection({ mandatory: true })
933
- *
934
- * selection.onboard([
935
- * { id: 'item-1', value: 'Item 1' },
936
- * { id: 'item-2', value: 'Item 2', disabled: true },
937
- * { id: 'item-3', value: 'Item 3' },
938
- * ])
939
- *
940
- * selection.select('item-1')
941
- * selection.select('item-3')
942
- *
943
- * console.log(selection.selectedIds) // Set { 'item-1', 'item-3' }
944
- * console.log(Array.from(selection.selectedValues.value)) // ['Item 1', 'Item 3']
945
- * ```
946
- */
947
- function createSelection(_options = {}) {
948
- const { disabled = false, enroll = false, mandatory = false, multiple = false, ...options } = _options;
949
- const registry = useRegistry(options);
950
- const selectedIds = shallowReactive(/* @__PURE__ */ new Set());
951
- const selectedItems = computed(() => {
952
- return new Set(Array.from(selectedIds).map((id) => registry.get(id)).filter((item) => !/* @__PURE__ */ isUndefined(item)));
953
- });
954
- const selectedValues = computed(() => {
955
- return new Set(Array.from(selectedItems.value).map((item) => item.value));
956
- });
957
- function seek(direction = "first", from) {
958
- return registry.seek(direction, from, (ticket) => !toValue(ticket.disabled));
959
- }
960
- function mandate() {
961
- if (!mandatory || registry.size === 0 || selectedIds.size > 0) return;
962
- const ticket = seek("first");
963
- if (ticket) select(ticket.id);
964
- }
965
- function select(id) {
966
- if (toValue(disabled)) return;
967
- const item = registry.get(id);
968
- if (!item || toValue(item.disabled)) return;
969
- if (!multiple) selectedIds.clear();
970
- selectedIds.add(id);
971
- }
972
- function unselect(id) {
973
- if (toValue(disabled)) return;
974
- if (mandatory && selectedIds.size === 1) return;
975
- selectedIds.delete(id);
976
- }
977
- function toggle(id) {
978
- if (toValue(disabled)) return;
979
- if (selected(id)) unselect(id);
980
- else select(id);
981
- }
982
- function selected(id) {
983
- return selectedIds.has(id);
984
- }
985
- function register(registration = {}) {
986
- const id = registration.id ?? /* @__PURE__ */ genId();
987
- const item = {
988
- disabled: false,
989
- select: () => select(id),
990
- unselect: () => unselect(id),
991
- toggle: () => toggle(id),
992
- isSelected: toRef(() => selected(id)),
993
- ...registration,
994
- id
995
- };
996
- const ticket = registry.register(item);
997
- if (enroll && !toValue(disabled) && !toValue(item.disabled)) selectedIds.add(ticket.id);
998
- if (mandatory === "force") mandate();
999
- return ticket;
1000
- }
1001
- function unregister(id) {
1002
- selectedIds.delete(id);
1003
- registry.unregister(id);
1004
- }
1005
- function offboard(ids) {
1006
- for (const id of ids) selectedIds.delete(id);
1007
- registry.offboard(ids);
1008
- }
1009
- function onboard(registrations) {
1010
- return registrations.map((registration) => register(registration));
1011
- }
1012
- function reset() {
1013
- registry.clear();
1014
- selectedIds.clear();
1015
- mandate();
1016
- }
1017
- return {
1018
- ...registry,
1019
- disabled,
1020
- selectedIds,
1021
- selectedItems,
1022
- selectedValues,
1023
- register,
1024
- unregister,
1025
- onboard,
1026
- offboard,
1027
- reset,
1028
- mandate,
1029
- seek,
1030
- select,
1031
- unselect,
1032
- toggle,
1033
- selected,
1034
- get size() {
1035
- return registry.size;
1036
- }
1037
- };
1038
- }
1039
- /**
1040
- * Creates a new selection context.
1041
- *
1042
- * @param options The options for the selection context.
1043
- * @template Z The type of the selection ticket.
1044
- * @template E The type of the selection context.
1045
- * @returns A new selection context.
1046
- *
1047
- * @see https://0.vuetifyjs.com/composables/selection/use-selection
1048
- *
1049
- * @example
1050
- * ```ts
1051
- * import { createSelectionContext } from '@vuetify/v0'
1052
- *
1053
- * // With default namespace 'v0:selection'
1054
- * export const [useCheckboxes, provideCheckboxes, checkboxes] = createSelectionContext()
1055
- *
1056
- * // Or with custom namespace
1057
- * export const [useCheckboxes, provideCheckboxes, checkboxes] = createSelectionContext({ namespace: 'checkboxes' })
1058
- *
1059
- * // In a parent component:
1060
- * provideCheckboxes()
1061
- *
1062
- * // In a child component:
1063
- * const checkboxes = useCheckboxes()
1064
- * checkboxes.select('checkbox-1')
1065
- * ```
1066
- */
1067
- function createSelectionContext(_options = {}) {
1068
- const { namespace = "v0:selection", ...options } = _options;
1069
- const [useSelectionContext, _provideSelectionContext] = createContext(namespace);
1070
- const context = createSelection(options);
1071
- function provideSelectionContext(_context = context, app) {
1072
- return _provideSelectionContext(_context, app);
1073
- }
1074
- return createTrinity(useSelectionContext, provideSelectionContext, context);
1075
- }
1076
- /**
1077
- * Returns the current selection instance.
1078
- *
1079
- * @param namespace The namespace for the selection context. Defaults to `'v0:selection'`.
1080
- * @returns The current selection instance.
1081
- *
1082
- * @see https://0.vuetifyjs.com/composables/selection/use-selection
1083
- *
1084
- * @example
1085
- * ```vue
1086
- * <script setup lang="ts">
1087
- * import { useSelection } from '@vuetify/v0'
1088
- *
1089
- * const selection = useSelection()
1090
- * <\/script>
1091
- *
1092
- * <template>
1093
- * <div>
1094
- * <p>Selected: {{ selection.selectedIds.size }}</p>
1095
- * </div>
1096
- * </template>
1097
- * ```
1098
- */
1099
- function useSelection(namespace = "v0:selection") {
1100
- return useContext(namespace);
1101
- }
1102
-
1103
- //#endregion
1104
- //#region src/composables/toArray/index.ts
1105
- /**
1106
- * @module toArray
1107
- *
1108
- * @remarks
1109
- * Utility function to normalize single values and arrays into arrays.
1110
- *
1111
- * Converts single values into single-element arrays, passes arrays through unchanged,
1112
- * and handles null/undefined by returning empty arrays. Perfect for functions that
1113
- * accept both single values and arrays as input (e.g., ID | ID[]).
1114
- */
1115
- /**
1116
- * Converts a value to an array.
1117
- *
1118
- * @param value The value to convert.
1119
- * @template Z The type of the value.
1120
- * @returns The converted array.
1121
- *
1122
- * @see https://0.vuetifyjs.com/composables/transformers/to-array
1123
- *
1124
- * @example
1125
- * ```ts
1126
- * import { toArray } from '@vuetify/v0'
1127
- *
1128
- * const value = 'Example Value'
1129
- * const valueAsArray = toArray(value)
1130
- *
1131
- * console.log(valueAsArray) // ['Example Value']
1132
- * ```
1133
- */
1134
- function toArray(value) {
1135
- return /* @__PURE__ */ isNullOrUndefined(value) ? [] : Array.isArray(value) ? value : [value];
1136
- }
1137
-
1138
- //#endregion
1139
- //#region src/composables/useProxyModel/index.ts
1140
- /**
1141
- * Syncs a ref with a selection registry bidirectionally.
1142
- *
1143
- * @param registry The selection registry to bind to.
1144
- * @param model The ref to sync.
1145
- * @param options The options for the proxy model.
1146
- * @template Z The type of the selection ticket.
1147
- * @returns A function to stop the sync.
1148
- *
1149
- * @see https://0.vuetifyjs.com/composables/forms/use-proxy-model
1150
- *
1151
- * @example
1152
- * ```ts
1153
- * import { createSelection, useProxyModel } from '@vuetify/v0'
1154
- *
1155
- * const model = ref()
1156
- * const registry = createSelection({ events: true })
1157
- * registry.onboard([
1158
- * { id: 'item-1', value: 'Item 1' },
1159
- * { id: 'item-2', value: 'Item 2' },
1160
- * ])
1161
- *
1162
- * const stop = useProxyModel(registry, model)
1163
- * ```
1164
- */
1165
- function useProxyModel(registry, model, options) {
1166
- const multiple = options?.multiple ?? false;
1167
- const _transformIn = options?.transformIn;
1168
- const _transformOut = options?.transformOut;
1169
- function transformIn(val) {
1170
- const value = toValue(val);
1171
- return toArray(/* @__PURE__ */ isFunction(_transformIn) ? _transformIn(value) : value);
1172
- }
1173
- function transformOut(val) {
1174
- if (/* @__PURE__ */ isFunction(_transformOut)) return _transformOut(val);
1175
- return multiple ? val : val[0];
1176
- }
1177
- const modelAsArray = transformIn(model);
1178
- const pending = new Set(modelAsArray);
1179
- for (const value of modelAsArray) {
1180
- const ids = registry.browse(value);
1181
- if (ids) {
1182
- for (const id of ids) registry.select(id);
1183
- pending.delete(value);
1184
- }
1185
- }
1186
- const registryWatch = watch(registry.selectedValues, (val) => {
1187
- modelWatch.pause();
1188
- model.value = transformOut(Array.from(toValue(val)));
1189
- modelWatch.resume();
1190
- }, { flush: "sync" });
1191
- const modelWatch = watch(model, (val) => {
1192
- registryWatch.pause();
1193
- const currentIds = new Set(toValue(registry.selectedIds));
1194
- const targetIds = /* @__PURE__ */ new Set();
1195
- for (const value of transformIn(val)) {
1196
- const ids = registry.browse(value);
1197
- if (ids) for (const id of ids) targetIds.add(id);
1198
- }
1199
- if (multiple) {
1200
- for (const id of currentIds.difference(targetIds)) registry.selectedIds.delete(id);
1201
- for (const id of targetIds.difference(currentIds)) registry.selectedIds.add(id);
1202
- } else {
1203
- const next = targetIds.values().next().value;
1204
- const last = currentIds.values().next().value;
1205
- if (!/* @__PURE__ */ isUndefined(last)) registry.unselect(last);
1206
- if (!/* @__PURE__ */ isUndefined(next)) registry.select(next);
1207
- }
1208
- registryWatch.resume();
1209
- }, {
1210
- flush: "sync",
1211
- deep: multiple
1212
- });
1213
- function onRegister(data) {
1214
- const ticket = data;
1215
- if (!pending.has(ticket.value) || ticket.disabled) return;
1216
- registryWatch.pause();
1217
- modelWatch.pause();
1218
- registry.select(ticket.id);
1219
- pending.delete(ticket.value);
1220
- modelWatch.resume();
1221
- registryWatch.resume();
1222
- }
1223
- registry.on("register:ticket", onRegister);
1224
- function stop() {
1225
- registryWatch();
1226
- modelWatch();
1227
- registry.off("register:ticket", onRegister);
1228
- }
1229
- onScopeDispose(stop, true);
1230
- return stop;
1231
- }
1232
-
1233
- //#endregion
1234
- //#region src/composables/useProxyRegistry/index.ts
1235
- /**
1236
- * Creates a proxy registry that provides reactive objects for registry data.
1237
- *
1238
- * @param registry The registry instance to proxy.
1239
- * @param options The options for the proxy registry.
1240
- * @template Z The type of the registry ticket.
1241
- * @returns A proxy registry with reactive objects.
1242
- *
1243
- * @see https://0.vuetifyjs.com/composables/registration/use-proxy-registry
1244
- *
1245
- * @example
1246
- * ```ts
1247
- * import { useRegistry, useProxyRegistry } from '@vuetify/v0'
1248
- *
1249
- * const registry = useRegistry({ events: true })
1250
- * const proxy = useProxyRegistry(registry)
1251
- *
1252
- * registry.register({ value: 'Item 1' })
1253
- * console.log(proxy.size) // 1
1254
- * ```
1255
- */
1256
- function useProxyRegistry(registry, options) {
1257
- const state = (options?.deep ? reactive : shallowReactive)({
1258
- keys: registry.keys(),
1259
- values: registry.values(),
1260
- entries: registry.entries(),
1261
- size: registry.size
1262
- });
1263
- function update() {
1264
- state.keys = registry.keys();
1265
- state.values = registry.values();
1266
- state.entries = registry.entries();
1267
- state.size = registry.size;
1268
- }
1269
- registry.on("register:ticket", update);
1270
- registry.on("unregister:ticket", update);
1271
- registry.on("update:ticket", update);
1272
- registry.on("clear:registry", update);
1273
- onScopeDispose(() => {
1274
- registry.off("register:ticket", update);
1275
- registry.off("unregister:ticket", update);
1276
- registry.off("update:ticket", update);
1277
- registry.off("clear:registry", update);
1278
- }, true);
1279
- return state;
1280
- }
1281
-
1282
- //#endregion
1283
- //#region src/composables/useGroup/index.ts
1284
- /**
1285
- * Creates a new group instance with batch selection and tri-state support.
1286
- *
1287
- * Extends `createSelection` to support selecting, unselecting, and toggling multiple items
1288
- * at once by passing an array of IDs. Adds tri-state (mixed/indeterminate) support for
1289
- * checkbox trees and similar use cases.
1290
- *
1291
- * @param options The options for the group instance.
1292
- * @template Z The type of the group ticket.
1293
- * @template E The type of the group context.
1294
- * @returns A new group instance with batch selection and tri-state support.
1295
- *
1296
- * @remarks
1297
- * **Key Differences from `createSelection`:**
1298
- * - `select()` accepts `ID | ID[]` for batch operations
1299
- * - `unselect()` accepts `ID | ID[]` for batch operations
1300
- * - `toggle()` accepts `ID | ID[]` for batch operations
1301
- * - Adds `selectedIndexes` computed Set for getting selected item indexes
1302
- * - Adds tri-state support via `mix()`, `unmix()`, `mixed()`, `mixedIds`, `mixedItems`
1303
- * - Perfect for checkbox trees, multi-select dropdowns, and bulk operations
1304
- *
1305
- * **Tri-State Support:**
1306
- * - Items can be in one of three states: selected, mixed (indeterminate), or unselected
1307
- * - `mix(id)` sets item to mixed state (clears selected if set)
1308
- * - `unmix(id)` clears mixed state
1309
- * - `select(id)` clears mixed state before selecting
1310
- * - `toggle(id)` on a mixed item selects it (resolves the indeterminate state positively)
1311
- * - Mixed state works on disabled items (it's a computed state, not user action)
1312
- *
1313
- * **Batch Operations:**
1314
- * - Single ID: `group.select('item-1')`
1315
- * - Array of IDs: `group.select(['item-1', 'item-2', 'item-3'])`
1316
- * - Uses `toArray()` utility internally to normalize input
1317
- * - Disabled items are automatically skipped in select operations
1318
- * - Non-existent IDs are silently ignored
1319
- *
1320
- * **Inheritance Chain:**
1321
- * `useRegistry` → `createSelection` → `createGroup`
1322
- *
1323
- * **Used By:**
1324
- * - `createFeatures` for feature flag management with multiple selections
1325
- *
1326
- * @see https://0.vuetifyjs.com/composables/selection/use-group
1327
- *
1328
- * @example
1329
- * ```ts
1330
- * import { createGroup } from '@vuetify/v0'
1331
- *
1332
- * const checkboxes = createGroup()
1333
- *
1334
- * checkboxes.onboard([
1335
- * { id: 'option-a', value: 'Option A' },
1336
- * { id: 'option-b', value: 'Option B' },
1337
- * { id: 'option-c', value: 'Option C' },
1338
- * ])
1339
- *
1340
- * // Select multiple items at once
1341
- * checkboxes.select(['option-a', 'option-c'])
1342
- *
1343
- * console.log(checkboxes.selectedIds) // Set { 'option-a', 'option-c' }
1344
- * console.log(Array.from(checkboxes.selectedIndexes.value)) // [0, 2]
1345
- *
1346
- * // Set item to mixed/indeterminate state
1347
- * checkboxes.mix('option-a')
1348
- * console.log(checkboxes.mixedIds) // Set { 'option-a' }
1349
- * console.log(checkboxes.selectedIds) // Set { 'option-c' } (option-a removed)
1350
- *
1351
- * // Toggle a mixed item selects it
1352
- * checkboxes.toggle('option-a')
1353
- * console.log(checkboxes.selectedIds) // Set { 'option-a', 'option-c' }
1354
- * console.log(checkboxes.mixedIds) // Set {} (cleared)
1355
- * ```
1356
- */
1357
- function createGroup(_options = {}) {
1358
- const { mandatory = false, multiple = true, ...options } = _options;
1359
- const selection = createSelection({
1360
- ...options,
1361
- mandatory,
1362
- multiple,
1363
- events: true
1364
- });
1365
- const proxy = useProxyRegistry(selection);
1366
- const mixedIds = shallowReactive(/* @__PURE__ */ new Set());
1367
- const selectedIndexes = computed(() => {
1368
- return new Set(Array.from(selection.selectedItems.value).map((item) => item?.index).filter((index) => !/* @__PURE__ */ isUndefined(index)));
1369
- });
1370
- const mixedItems = computed(() => {
1371
- return new Set(Array.from(mixedIds).map((id) => selection.get(id)).filter((item) => !/* @__PURE__ */ isUndefined(item)));
1372
- });
1373
- function mixed(id) {
1374
- return mixedIds.has(id);
1375
- }
1376
- function mix(ids) {
1377
- for (const id of toArray(ids)) {
1378
- if (!selection.has(id)) continue;
1379
- selection.selectedIds.delete(id);
1380
- mixedIds.add(id);
1381
- }
1382
- }
1383
- function unmix(ids) {
1384
- for (const id of toArray(ids)) mixedIds.delete(id);
1385
- }
1386
- function select(ids) {
1387
- for (const id of toArray(ids)) {
1388
- mixedIds.delete(id);
1389
- selection.select(id);
1390
- }
1391
- }
1392
- function unselect(ids) {
1393
- for (const id of toArray(ids)) selection.unselect(id);
1394
- }
1395
- function toggle(ids) {
1396
- for (const id of toArray(ids)) if (mixed(id)) select(id);
1397
- else selection.toggle(id);
1398
- }
1399
- function register(registration = {}) {
1400
- const id = registration.id ?? /* @__PURE__ */ genId();
1401
- const item = {
1402
- ...registration,
1403
- id,
1404
- isMixed: toRef(() => mixed(id)),
1405
- select: () => select(id),
1406
- unselect: () => unselect(id),
1407
- toggle: () => toggle(id),
1408
- mix: () => mix(id),
1409
- unmix: () => unmix(id)
1410
- };
1411
- const ticket = selection.register(item);
1412
- if (toValue(registration.indeterminate)) mix(id);
1413
- return ticket;
1414
- }
1415
- function unregister(id) {
1416
- mixedIds.delete(id);
1417
- selection.unregister(id);
1418
- }
1419
- function offboard(ids) {
1420
- for (const id of ids) mixedIds.delete(id);
1421
- selection.offboard(ids);
1422
- }
1423
- function onboard(registrations) {
1424
- return registrations.map((registration) => register(registration));
1425
- }
1426
- function reset() {
1427
- mixedIds.clear();
1428
- selection.reset();
1429
- }
1430
- const selectableItems = computed(() => {
1431
- return proxy.values.filter((item) => !toValue(item.disabled));
1432
- });
1433
- const isAllSelected = computed(() => {
1434
- const items = selectableItems.value;
1435
- if (items.length === 0) return false;
1436
- return items.every((item) => selection.selectedIds.has(item.id));
1437
- });
1438
- const isNoneSelected = computed(() => selection.selectedIds.size === 0);
1439
- const isMixed = computed(() => {
1440
- return mixedIds.size > 0 || !isNoneSelected.value && !isAllSelected.value;
1441
- });
1442
- function selectAll() {
1443
- for (const item of selectableItems.value) {
1444
- mixedIds.delete(item.id);
1445
- selection.select(item.id);
1446
- }
1447
- }
1448
- function unselectAll() {
1449
- const first = selection.selectedIds.values().next().value;
1450
- selection.selectedIds.clear();
1451
- if (!mandatory || !first) return;
1452
- selection.select(first);
1453
- }
1454
- function toggleAll() {
1455
- if (isAllSelected.value) unselectAll();
1456
- else selectAll();
1457
- }
1458
- return {
1459
- ...selection,
1460
- mixed,
1461
- mix,
1462
- unmix,
1463
- select,
1464
- unselect,
1465
- toggle,
1466
- register,
1467
- unregister,
1468
- offboard,
1469
- onboard,
1470
- reset,
1471
- selectAll,
1472
- unselectAll,
1473
- toggleAll,
1474
- mixedIds,
1475
- mixedItems,
1476
- selectedIndexes,
1477
- isNoneSelected,
1478
- isAllSelected,
1479
- isMixed,
1480
- get size() {
1481
- return selection.size;
1482
- }
1483
- };
1484
- }
1485
- /**
1486
- * Creates a new group context.
1487
- *
1488
- * @param options The options for the group context.
1489
- * @template Z The type of the group ticket.
1490
- * @template E The type of the group context.
1491
- * @returns A new group context.
1492
- *
1493
- * @see https://0.vuetifyjs.com/composables/selection/use-group
1494
- *
1495
- * @example
1496
- * ```ts
1497
- * import { createGroupContext } from '@vuetify/v0'
1498
- *
1499
- * // With default namespace 'v0:group'
1500
- * export const [useMyGroup, provideMyGroup, myGroup] = createGroupContext()
1501
- *
1502
- * // Or with custom namespace
1503
- * export const [useMyGroup, provideMyGroup, myGroup] = createGroupContext({ namespace: 'my-group' })
1504
- *
1505
- * // In a parent component:
1506
- * provideMyGroup()
1507
- *
1508
- * // In a child component:
1509
- * const group = useMyGroup()
1510
- * ```
1511
- */
1512
- function createGroupContext(_options = {}) {
1513
- const { namespace = "v0:group", ...options } = _options;
1514
- const [useGroupContext, _provideGroupContext] = createContext(namespace);
1515
- const context = createGroup(options);
1516
- function provideGroupContext(_context = context, app) {
1517
- return _provideGroupContext(_context, app);
1518
- }
1519
- return createTrinity(useGroupContext, provideGroupContext, context);
1520
- }
1521
- /**
1522
- * Returns the current group instance.
1523
- *
1524
- * @param namespace The namespace for the group context. Defaults to `'v0:group'`.
1525
- * @returns The current group instance.
1526
- *
1527
- * @see https://0.vuetifyjs.com/composables/selection/use-group
1528
- *
1529
- * @example
1530
- * ```vue
1531
- * <script setup lang="ts">
1532
- * import { useGroup } from '@vuetify/v0'
1533
- *
1534
- * const group = useGroup()
1535
- * <\/script>
1536
- *
1537
- * <template>
1538
- * <div>
1539
- * <p>Selected: {{ group.selectedIds.size }}</p>
1540
- * </div>
1541
- * </template>
1542
- * ```
1543
- */
1544
- function useGroup(namespace = "v0:group") {
1545
- return useContext(namespace);
1546
- }
1547
-
1548
- //#endregion
1549
- //#region src/composables/useLocale/adapters/v0.ts
1550
- /**
1551
- * Vuetify0.x locale adapter implementation
1552
- *
1553
- * This adapter provides translation and number formatting
1554
- * capabilities using the Intl API and supports both
1555
- * numbered ({0}, {1}) and named ({name}) variables in translation strings.
1556
- */
1557
- var Vuetify0LocaleAdapter = class {
1558
- t(message, ...params) {
1559
- let resolvedMessage = message;
1560
- if (params.length > 0 && /* @__PURE__ */ isObject(params[0])) {
1561
- const variables = params[0];
1562
- resolvedMessage = resolvedMessage.replace(/{([a-zA-Z][a-zA-Z0-9_]*)}/g, (match, name) => {
1563
- return /* @__PURE__ */ isUndefined(variables[name]) ? match : String(variables[name]);
1564
- });
1565
- params = params.slice(1);
1566
- }
1567
- resolvedMessage = resolvedMessage.replace(/\{(\d+)\}/g, (match, index) => {
1568
- const idx = Number.parseInt(index, 10);
1569
- if (!/* @__PURE__ */ isUndefined(params[idx])) return String(params[idx]);
1570
- return match;
1571
- });
1572
- return resolvedMessage;
1573
- }
1574
- n(value, locale, ...params) {
1575
- if (!IN_BROWSER || !locale) return value.toString();
1576
- const options = params[0];
1577
- return new Intl.NumberFormat(String(locale), options).format(value);
1578
- }
1579
- };
1580
-
1581
- //#endregion
1582
- //#region src/composables/useSingle/index.ts
1583
- /**
1584
- * Creates a new single selection instance that enforces only one selected item at a time.
1585
- *
1586
- * Extends `createSelection` by automatically clearing previous selections when a new item is selected.
1587
- * Adds computed singular properties: `selectedId`, `selectedItem`, `selectedIndex`, `selectedValue`.
1588
- *
1589
- * @param options The options for the single selection instance.
1590
- * @template Z The type of the single selection ticket.
1591
- * @template E The type of the single selection context.
1592
- * @returns A new single selection instance with single-selection enforcement.
1593
- *
1594
- * @remarks
1595
- * **Key Differences from `createSelection`:**
1596
- * - Automatically clears `selectedIds` before selecting a new item (enforces single selection)
1597
- * - Provides singular computed properties instead of plural sets
1598
- * - Perfect for tabs, radio buttons, theme selectors, and other single-choice UI components
1599
- *
1600
- * **Computed Properties:**
1601
- * - `selectedId`: The ID of the selected item (undefined if none selected)
1602
- * - `selectedItem`: The selected ticket object (undefined if none selected)
1603
- * - `selectedIndex`: The index of the selected item (-1 if none selected)
1604
- * - `selectedValue`: The value of the selected item (undefined if none selected)
1605
- *
1606
- * **Inheritance Chain:**
1607
- * `useRegistry` → `createSelection` → `createSingle` → `createStep`
1608
- *
1609
- * @see https://0.vuetifyjs.com/composables/selection/use-single
1610
- *
1611
- * @example
1612
- * ```ts
1613
- * import { createSingle } from '@vuetify/v0'
1614
- *
1615
- * const tabs = createSingle({ mandatory: true })
1616
- *
1617
- * tabs.onboard([
1618
- * { id: 'home', value: 'Home' },
1619
- * { id: 'about', value: 'About' },
1620
- * { id: 'contact', value: 'Contact' },
1621
- * ])
1622
- *
1623
- * tabs.first() // Select first tab
1624
- *
1625
- * console.log(tabs.selectedId.value) // 'home'
1626
- * console.log(tabs.selectedIndex.value) // 0
1627
- *
1628
- * tabs.select('about') // Switch to about tab
1629
- * console.log(tabs.selectedId.value) // 'about'
1630
- * console.log(tabs.selectedIds.size) // 1 (always enforces single selection)
1631
- * ```
1632
- */
1633
- function createSingle(_options = {}) {
1634
- const { mandatory = false, multiple = false, ...options } = _options;
1635
- const registry = createSelection({
1636
- ...options,
1637
- mandatory,
1638
- multiple
1639
- });
1640
- const selectedId = computed(() => registry.selectedIds.values().next().value);
1641
- const selectedItem = computed(() => registry.selectedItems.value.values().next().value);
1642
- const selectedIndex = computed(() => selectedItem.value?.index ?? -1);
1643
- const selectedValue = computed(() => selectedItem.value?.value);
1644
- function unselect(id) {
1645
- if (mandatory && registry.selectedIds.size === 1) return;
1646
- registry.selectedIds.delete(id);
1647
- }
1648
- function toggle(id) {
1649
- if (registry.selectedIds.has(id)) unselect(id);
1650
- else registry.select(id);
1651
- }
1652
- return {
1653
- ...registry,
1654
- selectedId,
1655
- selectedItem,
1656
- selectedIndex,
1657
- selectedValue,
1658
- unselect,
1659
- toggle,
1660
- get size() {
1661
- return registry.size;
1662
- }
1663
- };
1664
- }
1665
- /**
1666
- * Creates a new single selection context.
1667
- *
1668
- * @param options The options for the single selection context.
1669
- * @template Z The type of the single selection ticket.
1670
- * @template E The type of the single selection context.
1671
- * @returns A new single selection context.
1672
- *
1673
- * @see https://0.vuetifyjs.com/composables/selection/use-single
1674
- *
1675
- * @example
1676
- * ```ts
1677
- * import { createSingleContext } from '@vuetify/v0'
1678
- *
1679
- * // With default namespace 'v0:single'
1680
- * export const [useSingle, provideSingle, context] = createSingleContext()
1681
- *
1682
- * // In a parent component:
1683
- * provideSingle()
1684
- *
1685
- * // In a child component:
1686
- * const single = useSingle()
1687
- * single.select('tab-1')
1688
- * ```
1689
- */
1690
- function createSingleContext(_options = {}) {
1691
- const { namespace = "v0:single", ...options } = _options;
1692
- const [useSingleContext, _provideSingleContext] = createContext(namespace);
1693
- const context = createSingle(options);
1694
- function provideSingleContext(_context = context, app) {
1695
- return _provideSingleContext(_context, app);
1696
- }
1697
- return createTrinity(useSingleContext, provideSingleContext, context);
1698
- }
1699
- /**
1700
- * Returns the current single selection instance.
1701
- *
1702
- * @param namespace The namespace for the single selection context. Defaults to `'v0:single'`.
1703
- * @returns The current single selection instance.
1704
- *
1705
- * @see https://0.vuetifyjs.com/composables/selection/use-single
1706
- *
1707
- * @example
1708
- * ```vue
1709
- * <script setup lang="ts">
1710
- * import { useSingle } from '@vuetify/v0'
1711
- *
1712
- * const tabs = useSingle()
1713
- * <\/script>
1714
- *
1715
- * <template>
1716
- * <div>
1717
- * <p>Selected: {{ tabs.selectedId }}</p>
1718
- * </div>
1719
- * </template>
1720
- * ```
1721
- */
1722
- function useSingle(namespace = "v0:single") {
1723
- return useContext(namespace);
1724
- }
1725
-
1726
- //#endregion
1727
- //#region src/composables/useTokens/index.ts
1728
- /**
1729
- * Creates a new token instance.
1730
- *
1731
- * @param tokens The tokens to use.
1732
- * @param options The options for the token instance.
1733
- * @template Z The type of the token ticket.
1734
- * @template E The type of the token context.
1735
- * @returns A new token instance.
1736
- *
1737
- * @see https://www.designtokens.org/tr/drafts/format/
1738
- * @see https://0.vuetifyjs.com/composables/registration/use-tokens
1739
- *
1740
- * @example
1741
- * ```ts
1742
- * import { useTokens } from '@vuetify/v0'
1743
- *
1744
- * const tokens = useTokens({
1745
- * colors: {
1746
- * primary: '#3b82f6',
1747
- * secondary: '{colors.primary}', // Alias reference
1748
- * },
1749
- * })
1750
- *
1751
- * console.log(tokens.resolve('{colors.primary}')) // '#3b82f6'
1752
- * console.log(tokens.resolve('{colors.secondary}')) // '#3b82f6'
1753
- * ```
1754
- */
1755
- function createTokens(tokens = {}, options = {}) {
1756
- const logger = useLogger();
1757
- const registry = useRegistry(options);
1758
- const cache = /* @__PURE__ */ new Map();
1759
- registry.onboard(flatten(tokens, options.prefix, !!options.flat));
1760
- function isAlias(token) {
1761
- return /* @__PURE__ */ isString(token) && token.length > 2 && token[0] === "{" && token.at(-1) === "}";
1762
- }
1763
- function isTokenAlias(value) {
1764
- return /* @__PURE__ */ isObject(value) && "$value" in value;
1765
- }
1766
- function resolve(token, visited = /* @__PURE__ */ new Set()) {
1767
- const cacheKey = /* @__PURE__ */ isString(token) ? token : JSON.stringify(token);
1768
- const cached = cache.get(cacheKey);
1769
- if (!/* @__PURE__ */ isUndefined(cached)) return cached;
1770
- const reference = isTokenAlias(token) ? token.$value : token;
1771
- const isAliasReference = /* @__PURE__ */ isString(reference) && isAlias(reference);
1772
- const clean = isAliasReference ? reference.slice(1, -1) : String(reference);
1773
- if (visited.has(clean)) {
1774
- logger.warn(`Circular alias detected for "${clean}"`);
1775
- cache.set(cacheKey, void 0);
1776
- return;
1777
- }
1778
- visited.add(clean);
1779
- let found = registry.get(clean);
1780
- let segments = [];
1781
- if (!found && clean.includes(".")) {
1782
- const parts = clean.split(".");
1783
- for (let i = parts.length - 1; i > 0; i--) {
1784
- const prefix = parts.slice(0, i).join(".");
1785
- const suffix = parts.slice(i);
1786
- const candidate = registry.get(prefix);
1787
- if (!/* @__PURE__ */ isUndefined(candidate?.value)) {
1788
- found = candidate;
1789
- segments = suffix;
1790
- break;
1791
- }
1792
- }
1793
- }
1794
- if (/* @__PURE__ */ isUndefined(found?.value)) {
1795
- if (isAliasReference) logger.warn(`Alias not found for "${String(reference)}"`);
1796
- cache.set(cacheKey, void 0);
1797
- return;
1798
- }
1799
- let result;
1800
- let current = found.value;
1801
- if (segments.length > 0) {
1802
- if (isTokenAlias(current)) current = current.$value;
1803
- for (const segment of segments) {
1804
- if (!/* @__PURE__ */ isObject(current) || !(segment in current)) {
1805
- current = void 0;
1806
- break;
1807
- }
1808
- current = current[segment];
1809
- if (isTokenAlias(current)) current = current.$value;
1810
- }
1811
- if (/* @__PURE__ */ isUndefined(current)) {
1812
- logger.warn(`Path not found inside "${clean}": ${segments.join(".")}`);
1813
- cache.set(cacheKey, void 0);
1814
- return;
1815
- }
1816
- result = current;
1817
- } else if (isTokenAlias(current)) {
1818
- const inner = current.$value;
1819
- if (/* @__PURE__ */ isString(inner) && isAlias(inner)) return resolve(inner, visited);
1820
- result = inner;
1821
- } else if (/* @__PURE__ */ isString(current) && isAlias(current)) return resolve(current, visited);
1822
- else result = current;
1823
- cache.set(cacheKey, result);
1824
- return result;
1825
- }
1826
- return {
1827
- ...registry,
1828
- resolve,
1829
- isAlias,
1830
- get size() {
1831
- return registry.size;
1832
- }
1833
- };
1834
- }
1835
- /**
1836
- * Creates a new token context.
1837
- *
1838
- * @param namespace The namespace for the token context.
1839
- * @param tokens The tokens to use.
1840
- * @template Z The type of the token ticket.
1841
- * @template E The type of the token context.
1842
- * @returns A new token context.
1843
- *
1844
- * @see https://0.vuetifyjs.com/composables/registration/use-tokens
1845
- *
1846
- * @example
1847
- * ```ts
1848
- * import { createTokensContext } from '@vuetify/v0'
1849
- *
1850
- * export const [useTokens, provideTokens, context] = createTokensContext({
1851
- * namespace: 'v0:tokens',
1852
- * tokens: {
1853
- * colors: {
1854
- * primary: '#3b82f6',
1855
- * secondary: '{colors.primary}', // Alias reference
1856
- * },
1857
- * },
1858
- * })
1859
- * ```
1860
- */
1861
- function createTokensContext(_options) {
1862
- const { namespace = "v0:tokens", tokens = {}, ...options } = _options;
1863
- const [useTokensContext, _provideTokensContext] = createContext(namespace);
1864
- const context = createTokens(tokens, options);
1865
- function provideTokensContext(_context = context, app) {
1866
- return _provideTokensContext(_context, app);
1867
- }
1868
- return createTrinity(useTokensContext, provideTokensContext, context);
1869
- }
1870
- /**
1871
- * Returns the current tokens instance.
1872
- *
1873
- * @param namespace The namespace for the tokens context. Defaults to `'v0:tokens'`.
1874
- * @returns The current tokens instance.
1875
- *
1876
- * @see https://0.vuetifyjs.com/composables/registration/use-tokens
1877
- *
1878
- * @example
1879
- * ```vue
1880
- * <script setup lang="ts">
1881
- * import { useTokens } from '@vuetify/v0'
1882
- *
1883
- * const tokens = useTokens()
1884
- * <\/script>
1885
- * ```
1886
- */
1887
- function useTokens(namespace = "v0:tokens") {
1888
- return useContext(namespace);
1889
- }
1890
- /**
1891
- * Flattens a nested collection of tokens into a flat array of tokens.
1892
- * Each token is represented by an object containing its ID & value.
1893
- * @param tokens The collection of tokens to flatten.
1894
- * @param prefix An optional prefix to prepend to each token ID.
1895
- * @returns An array of flattened tokens, each with an ID and value.
1896
- */
1897
- function flatten(tokens, prefix = "", flat = false) {
1898
- const flattened = [];
1899
- const stack = [{
1900
- tokens,
1901
- prefix,
1902
- flat
1903
- }];
1904
- while (stack.length > 0) {
1905
- const { tokens: currentTokens, prefix: currentPrefix, flat: flat$1 } = stack.pop();
1906
- const meta = {};
1907
- for (const k in currentTokens) if (k.startsWith("$")) meta[k] = currentTokens[k];
1908
- if (Object.keys(meta).length > 0 && currentPrefix) flattened.push({
1909
- id: currentPrefix,
1910
- value: meta
1911
- });
1912
- for (const key in currentTokens) {
1913
- if (key.startsWith("$")) continue;
1914
- const value = currentTokens[key];
1915
- const id = currentPrefix ? `${currentPrefix}.${key}` : key;
1916
- if (!/* @__PURE__ */ isObject(value)) {
1917
- flattened.push({
1918
- id,
1919
- value
1920
- });
1921
- continue;
1922
- }
1923
- if ("$value" in value) {
1924
- flattened.push({
1925
- id,
1926
- value
1927
- });
1928
- const inner = value.$value;
1929
- if (/* @__PURE__ */ isObject(inner) && !flat$1) for (const innerKey in inner) {
1930
- if (innerKey.startsWith("$")) continue;
1931
- const child = inner[innerKey];
1932
- const childId = `${id}.${innerKey}`;
1933
- if (!/* @__PURE__ */ isObject(child)) flattened.push({
1934
- id: childId,
1935
- value: child
1936
- });
1937
- else if ("$value" in child) flattened.push({
1938
- id: childId,
1939
- value: child
1940
- });
1941
- else stack.push({
1942
- tokens: child,
1943
- prefix: childId,
1944
- flat: flat$1
1945
- });
1946
- }
1947
- continue;
1948
- }
1949
- if (flat$1) {
1950
- flattened.push({
1951
- id,
1952
- value
1953
- });
1954
- continue;
1955
- }
1956
- stack.push({
1957
- tokens: value,
1958
- prefix: id,
1959
- flat: flat$1
1960
- });
1961
- }
1962
- }
1963
- return flattened;
1964
- }
1965
-
1966
- //#endregion
1967
- //#region src/composables/useLocale/index.ts
1968
- /**
1969
- * Creates a new locale instance.
1970
- *
1971
- * @param options The options for the locale instance.
1972
- * @template Z The type of the locale ticket.
1973
- * @template E The type of the locale context.
1974
- * @returns A new locale instance.
1975
- *
1976
- * @see https://0.vuetifyjs.com/composables/plugins/use-locale
1977
- */
1978
- function createLocale(_options = {}) {
1979
- const { adapter = new Vuetify0LocaleAdapter(), messages = {}, ...options } = _options;
1980
- const tokens = createTokens(messages);
1981
- const registry = createSingle(options);
1982
- for (const id in messages) {
1983
- registry.register({ id });
1984
- if (id === options.default && !registry.selectedId.value) registry.select(id);
1985
- }
1986
- function t(key, params, fallback) {
1987
- const locale = registry.selectedId.value;
1988
- const args = toArray(params);
1989
- if (!locale) return adapter.t(fallback ?? key, ...args);
1990
- const path = `${locale}.${key}`;
1991
- const message = tokens.get(path)?.value;
1992
- const template = /* @__PURE__ */ isString(message) ? resolve(locale, message) : fallback ?? key;
1993
- return adapter.t(template, ...args);
1994
- }
1995
- function n(value, ...params) {
1996
- return adapter.n(value, registry.selectedId.value, ...params);
1997
- }
1998
- function resolve(locale, str) {
1999
- return str.replace(/{([a-zA-Z0-9.-_]+)}/g, (match, key) => {
2000
- const [prefix, ...rest] = key.split(".");
2001
- const target = registry.has(prefix) ? prefix : locale;
2002
- const path = `${target}.${registry.has(prefix) ? rest.join(".") : key}`;
2003
- const resolved = tokens.get(path)?.value;
2004
- if (/* @__PURE__ */ isString(resolved)) return resolve(target, resolved);
2005
- return match;
2006
- });
2007
- }
2008
- return {
2009
- ...registry,
2010
- t,
2011
- n,
2012
- get size() {
2013
- return registry.size;
2014
- }
2015
- };
2016
- }
2017
- function createLocaleFallback() {
2018
- return {
2019
- size: 0,
2020
- t: (key, _params, fallback) => fallback ?? key,
2021
- n: String
2022
- };
2023
- }
2024
- /**
2025
- * Creates a new locale context.
2026
- *
2027
- * @param options The options for the locale context.
2028
- * @template Z The type of the locale ticket.
2029
- * @template E The type of the locale context.
2030
- * @returns A new locale context.
2031
- *
2032
- * @see https://0.vuetifyjs.com/composables/plugins/use-locale
2033
- *
2034
- * @example
2035
- * ```ts
2036
- * import { createLocaleContext } from '@vuetify/v0'
2037
- *
2038
- * export const [useAppLocale, provideAppLocale, appLocale] = createLocaleContext({
2039
- * namespace: 'app:locale',
2040
- * messages: {
2041
- * en: { hello: 'Hello' },
2042
- * es: { hello: 'Hola' },
2043
- * },
2044
- * })
2045
- *
2046
- * // In a parent component:
2047
- * provideAppLocale()
2048
- *
2049
- * // In a child component:
2050
- * const locale = useAppLocale()
2051
- * locale.select('es')
2052
- * ```
2053
- */
2054
- function createLocaleContext(_options = {}) {
2055
- const { namespace = "v0:locale", ...options } = _options;
2056
- const [useLocaleContext, _provideLocaleContext] = createContext(namespace);
2057
- const context = createLocale(options);
2058
- function provideLocaleContext(_context = context, app) {
2059
- return _provideLocaleContext(_context, app);
2060
- }
2061
- return createTrinity(useLocaleContext, provideLocaleContext, context);
2062
- }
2063
- /**
2064
- * Creates a new locale plugin.
2065
- *
2066
- * @param options The options for the locale plugin.
2067
- * @template Z The type of the locale ticket.
2068
- * @template E The type of the locale context.
2069
- * @template R The type of the token ticket.
2070
- * @template O The type of the token context.
2071
- * @returns A new locale plugin.
2072
- *
2073
- * @see https://0.vuetifyjs.com/composables/plugins/use-locale
2074
- */
2075
- function createLocalePlugin(_options = {}) {
2076
- const { namespace = "v0:locale", adapter = new Vuetify0LocaleAdapter(), messages = {}, ...options } = _options;
2077
- const [, provideLocaleContext, context] = createLocaleContext({
2078
- ...options,
2079
- namespace,
2080
- adapter,
2081
- messages
2082
- });
2083
- return createPlugin({
2084
- namespace,
2085
- provide: (app) => {
2086
- provideLocaleContext(context, app);
2087
- }
2088
- });
2089
- }
2090
- /**
2091
- * Returns the current locale instance.
2092
- *
2093
- * @returns The current locale instance.
2094
- *
2095
- * @see https://0.vuetifyjs.com/composables/plugins/use-locale
2096
- */
2097
- function useLocale(namespace = "v0:locale") {
2098
- const fallback = createLocaleFallback();
2099
- if (!getCurrentInstance()) return fallback;
2100
- try {
2101
- return useContext(namespace, fallback);
2102
- } catch {
2103
- return fallback;
2104
- }
2105
- }
2106
-
2107
- //#endregion
2108
- //#region src/composables/useHydration/index.ts
2109
- /**
2110
- * Creates a new hydration instance.
2111
- *
2112
- * @returns A new hydration instance.
2113
- *
2114
- * @see https://0.vuetifyjs.com/composables/plugins/use-hydration
2115
- *
2116
- * @example
2117
- * ```ts
2118
- * import { createHydration } from '@vuetify/v0'
2119
- *
2120
- * const hydration = createHydration()
2121
- * console.log(hydration.isHydrated.value) // false
2122
- * hydration.hydrate()
2123
- * console.log(hydration.isHydrated.value) // true
2124
- * ```
2125
- */
2126
- function createHydration() {
2127
- const isHydrated = shallowRef(false);
2128
- function hydrate() {
2129
- isHydrated.value = true;
2130
- }
2131
- return {
2132
- isHydrated: shallowReadonly(isHydrated),
2133
- hydrate
2134
- };
2135
- }
2136
- function createFallbackHydration() {
2137
- return {
2138
- isHydrated: shallowReadonly(shallowRef(true)),
2139
- hydrate: () => {}
2140
- };
2141
- }
2142
- /**
2143
- * Creates a new hydration context trinity.
2144
- *
2145
- * @param options Options for creating the hydration context.
2146
- * @template E The type of the hydration context.
2147
- * @returns A new hydration context trinity.
2148
- *
2149
- * @see https://0.vuetifyjs.com/composables/plugins/use-hydration
2150
- *
2151
- * @example
2152
- * ```ts
2153
- * import { createHydrationContext } from '@vuetify/v0'
2154
- *
2155
- * export const [useHydrationContext, provideHydrationContext, context] = createHydrationContext({
2156
- * namespace: 'app:hydration',
2157
- * })
2158
- * ```
2159
- */
2160
- function createHydrationContext(_options = {}) {
2161
- const { namespace = "v0:hydration" } = _options;
2162
- const [useHydrationContext, _provideHydrationContext] = createContext(namespace);
2163
- const context = createHydration();
2164
- function provideHydrationContext(_context = context, app) {
2165
- return _provideHydrationContext(_context, app);
2166
- }
2167
- return createTrinity(useHydrationContext, provideHydrationContext, context);
2168
- }
2169
- /**
2170
- * Creates a new hydration plugin.
2171
- *
2172
- * @param options The options for the hydration plugin.
2173
- * @template E The type of the hydration context.
2174
- * @returns A new hydration plugin.
2175
- *
2176
- * @see https://0.vuetifyjs.com/composables/plugins/use-hydration
2177
- *
2178
- * @example
2179
- * ```ts
2180
- * import { createApp } from 'vue'
2181
- * import { createHydrationPlugin } from '@vuetify/v0'
2182
- * import App from './App.vue'
2183
- *
2184
- * const app = createApp(App)
2185
- *
2186
- * app.use(createHydrationPlugin())
2187
- *
2188
- * app.mount('#app')
2189
- * ```
2190
- */
2191
- function createHydrationPlugin(_options = {}) {
2192
- const { namespace = "v0:hydration", ...options } = _options;
2193
- const [, provideHydrationContext, context] = createHydrationContext({
2194
- ...options,
2195
- namespace
2196
- });
2197
- return createPlugin({
2198
- namespace,
2199
- provide: (app) => {
2200
- provideHydrationContext(context, app);
2201
- },
2202
- setup: (app) => {
2203
- app.mixin({ mounted() {
2204
- if (this.$parent !== null) return;
2205
- context.hydrate();
2206
- } });
2207
- }
2208
- });
2209
- }
2210
- /**
2211
- * Returns the current hydration instance.
2212
- *
2213
- * @param namespace The namespace for the hydration context. Defaults to `v0:hydration`.
2214
- * @returns The current hydration instance.
2215
- *
2216
- * @see https://0.vuetifyjs.com/composables/plugins/use-hydration
2217
- *
2218
- * @example
2219
- * ```vue
2220
- * <script setup lang="ts">
2221
- * import { useHydration } from '@vuetify/v0'
2222
- *
2223
- * const hydration = useHydration()
2224
- * <\/script>
2225
- *
2226
- * <template>
2227
- * <div>
2228
- * <p>Is hydrated: {{ hydration.isHydrated.value }}</p>
2229
- * </div>
2230
- * </template>
2231
- * ```
2232
- */
2233
- function useHydration(namespace = "v0:hydration") {
2234
- const fallback = createFallbackHydration();
2235
- if (!getCurrentInstance()) return fallback;
2236
- try {
2237
- return useContext(namespace, fallback);
2238
- } catch {
2239
- return fallback;
2240
- }
2241
- }
2242
-
2243
- //#endregion
2244
- //#region src/composables/useResizeObserver/index.ts
2245
- /**
2246
- * A composable that uses the Resize Observer API to detect when an element's
2247
- * size changes.
2248
- *
2249
- * @param target The element to observe.
2250
- * @param callback The callback to execute when the element's size changes.
2251
- * @param options The options for the Resize Observer.
2252
- * @returns An object with methods to control the observer.
2253
- *
2254
- * @see https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver
2255
- * @see https://0.vuetifyjs.com/composables/system/use-resize-observer
2256
- *
2257
- * @example
2258
- * ```ts
2259
- * import { ref } from 'vue'
2260
- * import { useResizeObserver } from '@vuetify/v0'
2261
- *
2262
- * const el = ref<HTMLElement>()
2263
- * const width = ref(0)
2264
- * const height = ref(0)
2265
- *
2266
- * const { pause, resume, isPaused } = useResizeObserver(
2267
- * el,
2268
- * (entries) => {
2269
- * const entry = entries[0]
2270
- * if (entry) {
2271
- * width.value = entry.contentRect.width
2272
- * height.value = entry.contentRect.height
2273
- * console.log('Size changed:', width.value, 'x', height.value)
2274
- * }
2275
- * },
2276
- * { immediate: true }
2277
- * )
2278
- *
2279
- * // Pause observation
2280
- * pause()
2281
- *
2282
- * // Resume observation
2283
- * resume()
2284
- * ```
2285
- */
2286
- function useResizeObserver(target, callback, options = {}) {
2287
- const { isHydrated } = useHydration();
2288
- const observer = shallowRef();
2289
- const isPaused = shallowRef(false);
2290
- const isActive = toRef(() => !!observer.value);
2291
- function setup() {
2292
- if (observer.value === null) return;
2293
- if (!isHydrated.value || !SUPPORTS_OBSERVER || !target.value || isPaused.value) return;
2294
- observer.value = new ResizeObserver((entries) => {
2295
- callback(entries.map((entry) => ({
2296
- contentRect: {
2297
- width: entry.contentRect.width,
2298
- height: entry.contentRect.height,
2299
- top: entry.contentRect.top,
2300
- left: entry.contentRect.left
2301
- },
2302
- target: entry.target
2303
- })));
2304
- if (options.once) stop();
2305
- });
2306
- observer.value.observe(target.value, { box: options.box || "content-box" });
2307
- if (options.immediate) {
2308
- const rect = target.value.getBoundingClientRect();
2309
- callback([{
2310
- contentRect: {
2311
- width: rect.width,
2312
- height: rect.height,
2313
- top: rect.top,
2314
- left: rect.left
2315
- },
2316
- target: target.value
2317
- }]);
2318
- }
2319
- }
2320
- watchEffect(() => {
2321
- const hydrated = isHydrated.value;
2322
- const el = target.value;
2323
- cleanup();
2324
- if (hydrated && el) setup();
2325
- });
2326
- function cleanup() {
2327
- if (observer.value) {
2328
- observer.value.disconnect();
2329
- observer.value = void 0;
2330
- }
2331
- }
2332
- function pause() {
2333
- isPaused.value = true;
2334
- observer.value?.disconnect();
2335
- }
2336
- function resume() {
2337
- isPaused.value = false;
2338
- setup();
2339
- }
2340
- function stop() {
2341
- cleanup();
2342
- observer.value = null;
2343
- }
2344
- onScopeDispose(stop, true);
2345
- return {
2346
- isActive: shallowReadonly(isActive),
2347
- isPaused: shallowReadonly(isPaused),
2348
- pause,
2349
- resume,
2350
- stop
2351
- };
2352
- }
2353
- /**
2354
- * A convenience composable that uses the Resize Observer API to track an
2355
- * element's size.
2356
- *
2357
- * @param target The element to observe.
2358
- * @returns An object with the element's width and height.
2359
- *
2360
- * @see https://0.vuetifyjs.com/composables/system/use-resize-observer#use-element-size
2361
- *
2362
- * @example
2363
- * ```ts
2364
- * import { ref, watchEffect } from 'vue'
2365
- * import { useElementSize } from '@vuetify/v0'
2366
- *
2367
- * const box = ref<HTMLElement>()
2368
- * const { width, height } = useElementSize(box)
2369
- *
2370
- * // Width and height are reactive refs
2371
- * watchEffect(() => {
2372
- * console.log('Box size:', width.value, 'x', height.value)
2373
- * })
2374
- * ```
2375
- */
2376
- function useElementSize(target) {
2377
- const width = shallowRef(0);
2378
- const height = shallowRef(0);
2379
- const { pause: _pause, resume, stop, isActive, isPaused } = useResizeObserver(target, (entries) => {
2380
- const entry = entries[0];
2381
- if (entry) {
2382
- width.value = entry.contentRect.width;
2383
- height.value = entry.contentRect.height;
2384
- }
2385
- }, { immediate: true });
2386
- function pause() {
2387
- width.value = 0;
2388
- height.value = 0;
2389
- _pause();
2390
- }
2391
- return {
2392
- width,
2393
- height,
2394
- isActive,
2395
- isPaused,
2396
- pause,
2397
- resume,
2398
- stop
2399
- };
2400
- }
2401
-
2402
- //#endregion
2403
- //#region src/composables/useOverflow/index.ts
2404
- /**
2405
- * Creates a new overflow context for computing how many items fit in a container.
2406
- *
2407
- * @param options Configuration options
2408
- * @returns Overflow context with container ref, capacity, and measurement functions
2409
- *
2410
- * @example Variable-width mode (Breadcrumbs)
2411
- * ```vue
2412
- * <script lang="ts" setup>
2413
- * import { useTemplateRef } from 'vue'
2414
- * import { createOverflow } from '@vuetify/v0'
2415
- *
2416
- * const containerRef = useTemplateRef('container')
2417
- * const overflow = createOverflow({
2418
- * container: containerRef,
2419
- * gap: 8,
2420
- * reserved: 40,
2421
- * })
2422
- * <\/script>
2423
- *
2424
- * <template>
2425
- * <div ref="container">
2426
- * <span
2427
- * v-for="(item, i) in items.slice(0, overflow.capacity.value)"
2428
- * :key="i"
2429
- * :ref="el => overflow.measure(i, el)"
2430
- * >
2431
- * {{ item }}
2432
- * </span>
2433
- * <span v-if="overflow.isOverflowing.value">...</span>
2434
- * </div>
2435
- * </template>
2436
- * ```
2437
- *
2438
- * @example Uniform-width mode (Pagination)
2439
- * ```ts
2440
- * const overflow = createOverflow({
2441
- * container: () => atom.value?.element,
2442
- * itemWidth: buttonWidth,
2443
- * reserved: () => buttonWidth.value * 4,
2444
- * })
2445
- * ```
2446
- */
2447
- function createOverflow(options = {}) {
2448
- const { container: _container, gap = 0, reserved = 0, itemWidth, reverse } = options;
2449
- const container = /* @__PURE__ */ isUndefined(_container) ? shallowRef() : toRef(_container);
2450
- const widths = shallowRef(/* @__PURE__ */ new Map());
2451
- const { width } = useElementSize(container);
2452
- function measure(index, el) {
2453
- if (!el) {
2454
- if (widths.value.has(index)) {
2455
- const next = new Map(widths.value);
2456
- next.delete(index);
2457
- widths.value = next;
2458
- }
2459
- return;
2460
- }
2461
- const style = getComputedStyle(el);
2462
- const marginX = Number.parseFloat(style.marginLeft) + Number.parseFloat(style.marginRight);
2463
- const w = el.offsetWidth + marginX;
2464
- if (widths.value.get(index) !== w) widths.value = new Map(widths.value).set(index, w);
2465
- }
2466
- function reset() {
2467
- widths.value = /* @__PURE__ */ new Map();
2468
- }
2469
- const total = computed(() => {
2470
- const g = toValue(gap);
2471
- let sum = 0;
2472
- let count = 0;
2473
- for (const w of widths.value.values()) {
2474
- sum += w + (count > 0 ? g : 0);
2475
- count++;
2476
- }
2477
- return sum;
2478
- });
2479
- return {
2480
- container,
2481
- width,
2482
- capacity: computed(() => {
2483
- const available = width.value - toValue(reserved);
2484
- if (width.value === 0) return Infinity;
2485
- if (available <= 0) return 0;
2486
- const g = toValue(gap);
2487
- const uniformWidth = toValue(itemWidth);
2488
- if (uniformWidth && uniformWidth > 0) {
2489
- const first = uniformWidth;
2490
- const subsequent = uniformWidth + g;
2491
- if (available < first) return 0;
2492
- return Math.max(1, Math.floor((available - first) / subsequent) + 1);
2493
- }
2494
- const entries = [...widths.value.entries()].toSorted((a, b) => a[0] - b[0]);
2495
- if (toValue(reverse)) entries.reverse();
2496
- let sum = 0;
2497
- let count = 0;
2498
- for (const [, w] of entries) {
2499
- const next = sum + w + (count > 0 ? g : 0);
2500
- if (next > available) break;
2501
- sum = next;
2502
- count++;
2503
- }
2504
- return count;
2505
- }),
2506
- total,
2507
- isOverflowing: toRef(() => {
2508
- return total.value > width.value - toValue(reserved);
2509
- }),
2510
- measure,
2511
- reset
2512
- };
2513
- }
2514
- /**
2515
- * Creates an overflow context with dependency injection support.
2516
- *
2517
- * @param options Configuration options including namespace
2518
- * @returns Trinity tuple: [useContext, provideContext, defaultContext]
2519
- *
2520
- * @example
2521
- * ```ts
2522
- * // Create injectable context
2523
- * const [useOverflow, provideOverflow, overflow] = createOverflowContext({
2524
- * namespace: 'my-overflow',
2525
- * gap: 8,
2526
- * reserved: 160,
2527
- * })
2528
- *
2529
- * // In parent component
2530
- * provideOverflow()
2531
- *
2532
- * // In child component
2533
- * const overflow = useOverflow()
2534
- * ```
2535
- */
2536
- function createOverflowContext(_options = {}) {
2537
- const { namespace = "v0:overflow", ...options } = _options;
2538
- const [useOverflowContext, _provideOverflowContext] = createContext(namespace);
2539
- const context = createOverflow(options);
2540
- function provideOverflowContext(_context = context, app) {
2541
- return _provideOverflowContext(_context, app);
2542
- }
2543
- return createTrinity(useOverflowContext, provideOverflowContext, context);
2544
- }
2545
- /**
2546
- * Returns the current overflow context from dependency injection.
2547
- *
2548
- * @param namespace The namespace for the overflow context. Defaults to `v0:overflow`.
2549
- * @returns The current overflow context.
2550
- *
2551
- * @example
2552
- * ```vue
2553
- * <script lang="ts" setup>
2554
- * import { useOverflow } from '@vuetify/v0'
2555
- *
2556
- * // Inject overflow context provided by parent
2557
- * const overflow = useOverflow()
2558
- * <\/script>
2559
- *
2560
- * <template>
2561
- * <div>
2562
- * <p>Capacity: {{ overflow.capacity.value }}</p>
2563
- * </div>
2564
- * </template>
2565
- * ```
2566
- */
2567
- function useOverflow(namespace = "v0:overflow") {
2568
- return useContext(namespace);
2569
- }
2570
-
2571
- //#endregion
2572
- //#region src/composables/usePagination/index.ts
2573
- /**
2574
- * Creates a pagination instance.
2575
- *
2576
- * @param options The options for the pagination instance.
2577
- * @returns A pagination context with navigation methods.
2578
- *
2579
- * @example
2580
- * ```ts
2581
- * import { createPagination } from '@vuetify/v0'
2582
- *
2583
- * // Basic usage
2584
- * const pagination = createPagination({ size: 100 })
2585
- * pagination.next()
2586
- * pagination.items.value // [{ type: 'page', value: 1 }, { type: 'page', value: 2 }, ...]
2587
- *
2588
- * // With v-model (pass a ref)
2589
- * const page = ref(1)
2590
- * const pagination = createPagination({ page, size: 100 })
2591
- * // Mutating pagination.page or the passed ref syncs both
2592
- * ```
2593
- */
2594
- function createPagination(_options = {}) {
2595
- const { page: _page = 1, itemsPerPage: _itemsPerPage = 10, size: _size = 0, visible: _visible = 7, ellipsis = "..." } = _options;
2596
- const page = isRef(_page) ? _page : shallowRef(_page);
2597
- const pages = computed(() => {
2598
- const size = toValue(_size);
2599
- const perPage = toValue(_itemsPerPage);
2600
- if (size <= 0 || /* @__PURE__ */ isNaN(size)) return 0;
2601
- return Math.ceil(size / perPage);
2602
- });
2603
- function first() {
2604
- page.value = 1;
2605
- }
2606
- function last() {
2607
- page.value = Math.max(1, pages.value);
2608
- }
2609
- function next() {
2610
- if (page.value < pages.value) page.value++;
2611
- }
2612
- function prev() {
2613
- if (page.value > 1) page.value--;
2614
- }
2615
- function select(value) {
2616
- if (value < 1) page.value = 1;
2617
- else if (value > pages.value) page.value = Math.max(1, pages.value);
2618
- else page.value = value;
2619
- }
2620
- const isFirst = computed(() => page.value <= 1);
2621
- const isLast = computed(() => page.value >= pages.value);
2622
- const pageStart = computed(() => (page.value - 1) * toValue(_itemsPerPage));
2623
- const pageStop = computed(() => Math.min(pageStart.value + toValue(_itemsPerPage), toValue(_size)));
2624
- function toPage(value) {
2625
- return {
2626
- type: "page",
2627
- value
2628
- };
2629
- }
2630
- function toEllipsis() {
2631
- return ellipsis === false ? false : {
2632
- type: "ellipsis",
2633
- value: ellipsis
2634
- };
2635
- }
2636
- function filter(array) {
2637
- return array.filter((item) => item !== false);
2638
- }
2639
- return {
2640
- page,
2641
- ellipsis,
2642
- items: computed(() => {
2643
- const pageCount = pages.value;
2644
- const visible = toValue(_visible);
2645
- const current = page.value;
2646
- if (pageCount <= 0 || /* @__PURE__ */ isNaN(pageCount) || pageCount > Number.MAX_SAFE_INTEGER) return [];
2647
- if (visible <= 0) return [];
2648
- if (visible <= 2) return [toPage(current)];
2649
- if (pageCount <= visible) return (/* @__PURE__ */ range(pageCount, 1)).map(toPage);
2650
- if (visible === 3) {
2651
- const mid = current <= 1 ? 2 : current >= pageCount ? pageCount - 1 : current;
2652
- return [
2653
- toPage(1),
2654
- toPage(mid),
2655
- toPage(pageCount)
2656
- ];
2657
- }
2658
- const boundary = visible - 2;
2659
- const middle = visible - 4;
2660
- if (middle <= 0) {
2661
- if (current <= boundary) return filter([
2662
- ...(/* @__PURE__ */ range(boundary, 1)).map(toPage),
2663
- toEllipsis(),
2664
- toPage(pageCount)
2665
- ]);
2666
- if (current > pageCount - boundary) return filter([
2667
- toPage(1),
2668
- toEllipsis(),
2669
- ...(/* @__PURE__ */ range(boundary, pageCount - boundary + 1)).map(toPage)
2670
- ]);
2671
- return current <= Math.ceil(pageCount / 2) ? filter([
2672
- toPage(1),
2673
- toPage(current),
2674
- toEllipsis(),
2675
- toPage(pageCount)
2676
- ]) : filter([
2677
- toPage(1),
2678
- toEllipsis(),
2679
- toPage(current),
2680
- toPage(pageCount)
2681
- ]);
2682
- }
2683
- const leftThreshold = boundary - 1;
2684
- const rightThreshold = pageCount - boundary + 2;
2685
- if (current <= leftThreshold) return filter([
2686
- ...(/* @__PURE__ */ range(boundary, 1)).map(toPage),
2687
- toEllipsis(),
2688
- toPage(pageCount)
2689
- ]);
2690
- else if (current >= rightThreshold) return filter([
2691
- toPage(1),
2692
- toEllipsis(),
2693
- ...(/* @__PURE__ */ range(boundary, pageCount - boundary + 1)).map(toPage)
2694
- ]);
2695
- else {
2696
- const start = current - Math.floor(middle / 2);
2697
- return filter([
2698
- toPage(1),
2699
- toEllipsis(),
2700
- ...(/* @__PURE__ */ range(middle, start)).map(toPage),
2701
- toEllipsis(),
2702
- toPage(pageCount)
2703
- ]);
2704
- }
2705
- }),
2706
- pageStart,
2707
- pageStop,
2708
- isFirst,
2709
- isLast,
2710
- first,
2711
- last,
2712
- next,
2713
- prev,
2714
- select,
2715
- get itemsPerPage() {
2716
- return toValue(_itemsPerPage);
2717
- },
2718
- get size() {
2719
- return toValue(_size);
2720
- },
2721
- get pages() {
2722
- return pages.value;
2723
- }
2724
- };
2725
- }
2726
- /**
2727
- * Creates a pagination context for dependency injection.
2728
- *
2729
- * @param options The options including namespace.
2730
- * @returns A trinity: [usePagination, providePagination, defaultContext]
2731
- *
2732
- * @example
2733
- * ```ts
2734
- * // With default namespace 'v0:pagination'
2735
- * const [usePagination, providePaginationContext] = createPaginationContext({ size: 50 })
2736
- *
2737
- * // Or with custom namespace
2738
- * const [usePagination, providePaginationContext] = createPaginationContext({
2739
- * namespace: 'my-pagination',
2740
- * size: 50,
2741
- * })
2742
- *
2743
- * // Parent component
2744
- * providePaginationContext()
2745
- *
2746
- * // Child component
2747
- * const pagination = usePagination()
2748
- * pagination.next()
2749
- * ```
2750
- */
2751
- function createPaginationContext(_options = {}) {
2752
- const { namespace = "v0:pagination", ...options } = _options;
2753
- const [usePaginationContext, _providePaginationContext] = createContext(namespace);
2754
- const context = createPagination(options);
2755
- function providePaginationContext(_context = context, app) {
2756
- return _providePaginationContext(_context, app);
2757
- }
2758
- return createTrinity(usePaginationContext, providePaginationContext, context);
2759
- }
2760
- /**
2761
- * Returns the current pagination instance from context.
2762
- *
2763
- * @param namespace The namespace. @default 'v0:pagination'
2764
- * @returns The pagination context.
2765
- *
2766
- * @example
2767
- * ```vue
2768
- * <script setup lang="ts">
2769
- * import { usePagination } from '@vuetify/v0'
2770
- *
2771
- * const pagination = usePagination()
2772
- * <\/script>
2773
- *
2774
- * <template>
2775
- * <button @click="pagination.prev()" :disabled="pagination.isFirst.value">Prev</button>
2776
- * <button @click="pagination.next()" :disabled="pagination.isLast.value">Next</button>
2777
- * </template>
2778
- * ```
2779
- */
2780
- function usePagination(namespace = "v0:pagination") {
2781
- return useContext(namespace);
2782
- }
2783
-
2784
- //#endregion
2785
- //#region src/composables/useStep/index.ts
2786
- /**
2787
- * Creates a new step instance with navigation through items.
2788
- *
2789
- * Extends `createSingle` with `first()`, `last()`, `next()`, `prev()`, and `step(count)` methods
2790
- * for sequential navigation. Supports both circular (wrapping) and bounded (stopping at edges) modes.
2791
- *
2792
- * @param options The options for the step instance.
2793
- * @template Z The type of the step ticket.
2794
- * @template E The type of the step context.
2795
- * @returns A new step instance with navigation methods.
2796
- *
2797
- * @remarks
2798
- * **Key Features:**
2799
- * - **Configurable Navigation**: `circular: true` for wrapping, `false` for bounded (default: false)
2800
- * - **Disabled Item Skipping**: Automatically skips disabled items during navigation
2801
- * - **Bidirectional**: Forward (`next`, positive `step`) and backward (`prev`, negative `step`)
2802
- * - **Safe Edge Cases**: Handles empty registries and all-disabled scenarios gracefully
2803
- *
2804
- * **Navigation Methods:**
2805
- * - `first()`: Select first non-disabled item
2806
- * - `last()`: Select last non-disabled item
2807
- * - `next()`: Move to next item (wraps if circular, stops at end if bounded)
2808
- * - `prev()`: Move to previous item (wraps if circular, stops at start if bounded)
2809
- * - `step(count)`: Move by `count` positions (negative for backward)
2810
- *
2811
- * **Circular Mode (`circular: true`):**
2812
- * - Uses modulo arithmetic for wrapping: `((index % length) + length) % length`
2813
- * - Works correctly with negative indexes and large step counts
2814
- * - Perfect for carousels, theme switchers, infinite scrolling
2815
- *
2816
- * **Bounded Mode (`circular: false`, default):**
2817
- * - Navigation stops at boundaries (no wrapping)
2818
- * - `next()` on last item does nothing
2819
- * - `prev()` on first item does nothing
2820
- * - Perfect for pagination, wizards with explicit completion, forms
2821
- *
2822
- * **Inheritance Chain:**
2823
- * `useRegistry` → `createSelection` → `createSingle` → `createStep`
2824
- *
2825
- * @see https://0.vuetifyjs.com/composables/selection/use-step
2826
- *
2827
- * @example
2828
- * ```ts
2829
- * import { createStep } from '@vuetify/v0'
2830
- *
2831
- * // Bounded navigation (default) - for pagination
2832
- * const pagination = createStep({ circular: false })
2833
- * pagination.onboard([
2834
- * { id: 'page-1', value: 1 },
2835
- * { id: 'page-2', value: 2 },
2836
- * { id: 'page-3', value: 3 },
2837
- * ])
2838
- * pagination.first() // Select page 1
2839
- * pagination.prev() // Does nothing (already at first)
2840
- * pagination.next() // Select page 2
2841
- *
2842
- * // Circular navigation - for carousels
2843
- * const carousel = createStep({ circular: true })
2844
- * carousel.onboard([
2845
- * { id: 'slide-1', value: 'First' },
2846
- * { id: 'slide-2', value: 'Second' },
2847
- * { id: 'slide-3', value: 'Third' },
2848
- * ])
2849
- * carousel.first()
2850
- * carousel.prev() // Wraps to 'slide-3'
2851
- * carousel.next() // Wraps to 'slide-1'
2852
- * ```
2853
- */
2854
- function createStep(_options = {}) {
2855
- const { circular = false, ...options } = _options;
2856
- const registry = createSingle(options);
2857
- function first() {
2858
- const ticket = registry.seek("first");
2859
- if (ticket) registry.select(ticket.id);
2860
- }
2861
- function last() {
2862
- const ticket = registry.seek("last");
2863
- if (ticket) registry.select(ticket.id);
2864
- }
2865
- function next() {
2866
- step(1);
2867
- }
2868
- function prev() {
2869
- step(-1);
2870
- }
2871
- function wrapped(length, index) {
2872
- return (index % length + length) % length;
2873
- }
2874
- function step(count = 1) {
2875
- const length = registry.size;
2876
- if (!length) return;
2877
- const currentIndex = registry.selectedIndex.value;
2878
- const direction = Math.sign(count || 1);
2879
- let hops = 0;
2880
- let index = circular ? wrapped(length, currentIndex + count) : currentIndex + count;
2881
- if (!circular && (index < 0 || index >= length)) return;
2882
- let id = registry.lookup(index);
2883
- while (!/* @__PURE__ */ isUndefined(id) && toValue(registry.get(id)?.disabled) && hops < length) {
2884
- index = circular ? wrapped(length, index + direction) : index + direction;
2885
- if (!circular && (index < 0 || index >= length)) return;
2886
- id = registry.lookup(index);
2887
- hops++;
2888
- }
2889
- if (/* @__PURE__ */ isUndefined(id) || hops === length) return;
2890
- registry.selectedIds.clear();
2891
- registry.select(id);
2892
- }
2893
- return {
2894
- ...registry,
2895
- first,
2896
- last,
2897
- next,
2898
- prev,
2899
- step,
2900
- get size() {
2901
- return registry.size;
2902
- }
2903
- };
2904
- }
2905
- /**
2906
- * Creates a new step context.
2907
- *
2908
- * @param options The options for the step context.
2909
- * @template Z The type of the step ticket.
2910
- * @template E The type of the step context.
2911
- * @returns A new step context.
2912
- *
2913
- * @see https://0.vuetifyjs.com/composables/selection/use-step
2914
- *
2915
- * @example
2916
- * ```ts
2917
- * import { createStepContext } from '@vuetify/v0'
2918
- *
2919
- * // With default namespace 'v0:step'
2920
- * export const [useStep, provideStep, context] = createStepContext()
2921
- *
2922
- * // In a parent component:
2923
- * provideStep()
2924
- *
2925
- * // In a child component:
2926
- * const context = useStep()
2927
- * context.next() // Progress to next step
2928
- * ```
2929
- */
2930
- function createStepContext(_options = {}) {
2931
- const { namespace = "v0:step", ...options } = _options;
2932
- const [useStepContext, _provideStepContext] = createContext(namespace);
2933
- const context = createStep(options);
2934
- function provideStepContext(_context = context, app) {
2935
- return _provideStepContext(_context, app);
2936
- }
2937
- return createTrinity(useStepContext, provideStepContext, context);
2938
- }
2939
- /**
2940
- * Returns the current step instance.
2941
- *
2942
- * @param namespace The namespace for the step context. Defaults to `'v0:step'`.
2943
- * @returns The current step instance.
2944
- *
2945
- * @see https://0.vuetifyjs.com/composables/selection/use-step
2946
- *
2947
- * @example
2948
- * ```vue
2949
- * <script setup lang="ts">
2950
- * import { useStep } from '@vuetify/v0'
2951
- *
2952
- * const wizard = useStep()
2953
- * <\/script>
2954
- *
2955
- * <template>
2956
- * <div>
2957
- * <p>Current step: {{ wizard.selectedIndex }}</p>
2958
- * <button @click="wizard.next()">Next</button>
2959
- * </div>
2960
- * </template>
2961
- * ```
2962
- */
2963
- function useStep(namespace = "v0:step") {
2964
- return useContext(namespace);
2965
- }
2966
-
2967
- //#endregion
2968
- export { createGroupContext as A, createLogger as B, createTokensContext as C, useSingle as D, createSingleContext as E, createSelection as F, PinoLoggerAdapter as G, createLoggerPlugin as H, createSelectionContext as I, createTrinity as J, ConsolaLoggerAdapter as K, useSelection as L, useProxyRegistry as M, useProxyModel as N, Vuetify0LocaleAdapter as O, toArray as P, createRegistryContext as R, createTokens as S, createSingle as T, useLogger as U, createLoggerContext as V, Vuetify0LoggerAdapter as W, provideContext as X, createContext as Y, useContext as Z, createLocale as _, createPaginationContext as a, createLocalePlugin as b, createOverflowContext as c, useResizeObserver as d, createFallbackHydration as f, useHydration as g, createHydrationPlugin as h, createPagination as i, useGroup as j, createGroup as k, useOverflow as l, createHydrationContext as m, createStepContext as n, usePagination as o, createHydration as p, createPlugin as q, useStep as r, createOverflow as s, createStep as t, useElementSize as u, createLocaleContext as v, useTokens as w, useLocale as x, createLocaleFallback as y, useRegistry as z };