@vuetify/v0 0.1.3 → 0.1.4

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.
Files changed (127) hide show
  1. package/dist/adapter-BN-h5JbD.d.mts +344 -0
  2. package/dist/adapter-CJIj5ySf.d.mts +11 -0
  3. package/dist/adapter-D_0ptsPm.mjs +229 -0
  4. package/dist/adapters-BQ-Lr3PW.mjs +1 -0
  5. package/dist/adapters-DEXpW9If.mjs +1 -0
  6. package/dist/adapters-Q9WaOsJp.mjs +1 -0
  7. package/dist/adapters-SSDVth5e.mjs +1 -0
  8. package/dist/browser/index.js +359 -933
  9. package/dist/components/index.d.mts +19 -6
  10. package/dist/components/index.mjs +37 -5
  11. package/dist/{components-C0zEvP7w.mjs → components-CMuzTJdK.mjs} +11 -4
  12. package/dist/composables/index.d.mts +17 -4
  13. package/dist/composables/index.mjs +36 -4
  14. package/dist/consola-DiUk9j3y.d.mts +15 -0
  15. package/dist/consola-GBy8XRuL.mjs +31 -0
  16. package/dist/constants/index.d.mts +1 -1
  17. package/dist/constants/index.mjs +3 -3
  18. package/dist/constants-B8pMSkcW.mjs +1 -0
  19. package/dist/createDataTable-BJnmvxfb.mjs +387 -0
  20. package/dist/createGroup-CPhp6FUh.mjs +363 -0
  21. package/dist/createPagination-cyOWlpfH.mjs +234 -0
  22. package/dist/createSelection-uqEbFgha.mjs +261 -0
  23. package/dist/createSingle-B59ya3aa.mjs +179 -0
  24. package/dist/createTokens-BlhLdHXE.mjs +682 -0
  25. package/dist/createTrinity-EeHQSsb6.mjs +149 -0
  26. package/dist/data-table/adapters/client/index.d.mts +3 -0
  27. package/dist/data-table/adapters/client/index.mjs +9 -0
  28. package/dist/data-table/adapters/index.d.mts +5 -0
  29. package/dist/data-table/adapters/index.mjs +12 -0
  30. package/dist/data-table/adapters/server/index.d.mts +3 -0
  31. package/dist/data-table/adapters/server/index.mjs +7 -0
  32. package/dist/data-table/adapters/virtual/index.d.mts +3 -0
  33. package/dist/data-table/adapters/virtual/index.mjs +9 -0
  34. package/dist/data-table/index.d.mts +7 -0
  35. package/dist/data-table/index.mjs +25 -0
  36. package/dist/date/index.d.mts +1 -1
  37. package/dist/date/index.mjs +2 -2
  38. package/dist/features/adapters/flagsmith/index.d.mts +16 -0
  39. package/dist/features/adapters/flagsmith/index.mjs +3 -0
  40. package/dist/features/adapters/launchdarkly/index.d.mts +15 -0
  41. package/dist/features/adapters/launchdarkly/index.mjs +3 -0
  42. package/dist/features/adapters/posthog/index.d.mts +15 -0
  43. package/dist/features/adapters/posthog/index.mjs +4 -0
  44. package/dist/features/index.d.mts +17 -0
  45. package/dist/features/index.mjs +18 -0
  46. package/dist/flagsmith-CHmpPGR7.mjs +40 -0
  47. package/dist/{globals-BwYsH-rt.mjs → globals-B_GVfG06.mjs} +2 -2
  48. package/dist/index-7mWYFHA6.d.mts +251 -0
  49. package/dist/index-BDTbJClL.d.mts +11 -0
  50. package/dist/index-BuOz3Rgm.d.mts +32 -0
  51. package/dist/{index-Bmem4l8m.d.mts → index-Bv1VN_j5.d.mts} +1 -1
  52. package/dist/{index-DFM5iBqh.d.mts → index-CQrDeqsK.d.mts} +280 -279
  53. package/dist/{index-2wh69fk5.d.mts → index-Dd0m0LIJ.d.mts} +135 -1407
  54. package/dist/{index-DBZTizq2.d.mts → index-UNwEBkQT.d.mts} +16 -2
  55. package/dist/index.d.mts +20 -7
  56. package/dist/index.mjs +39 -7
  57. package/dist/json/web-types.json +1 -1
  58. package/dist/launchdarkly-W8t8ZANX.mjs +28 -0
  59. package/dist/locale/adapters/index.d.mts +3 -0
  60. package/dist/locale/adapters/index.mjs +6 -0
  61. package/dist/locale/adapters/v0/index.d.mts +3 -0
  62. package/dist/locale/adapters/v0/index.mjs +5 -0
  63. package/dist/locale/index.d.mts +17 -0
  64. package/dist/locale/index.mjs +17 -0
  65. package/dist/logger/adapters/consola/index.d.mts +3 -0
  66. package/dist/logger/adapters/consola/index.mjs +3 -0
  67. package/dist/logger/adapters/index.d.mts +5 -0
  68. package/dist/logger/adapters/index.mjs +8 -0
  69. package/dist/logger/adapters/pino/index.d.mts +3 -0
  70. package/dist/logger/adapters/pino/index.mjs +5 -0
  71. package/dist/logger/adapters/v0/index.d.mts +3 -0
  72. package/dist/logger/adapters/v0/index.mjs +5 -0
  73. package/dist/logger/index.d.mts +17 -0
  74. package/dist/logger/index.mjs +10 -0
  75. package/dist/memory-BsZGbGnG.mjs +27 -0
  76. package/dist/memory-DVjquu_v.d.mts +25 -0
  77. package/dist/permissions/adapters/index.d.mts +18 -0
  78. package/dist/permissions/adapters/index.mjs +6 -0
  79. package/dist/permissions/adapters/v0/index.d.mts +18 -0
  80. package/dist/permissions/adapters/v0/index.mjs +5 -0
  81. package/dist/permissions/index.d.mts +17 -0
  82. package/dist/permissions/index.mjs +15 -0
  83. package/dist/pino-01x_NmWp.mjs +49 -0
  84. package/dist/pino-p-jDkNQd.d.mts +24 -0
  85. package/dist/posthog-BrGBPPir.mjs +50 -0
  86. package/dist/server-6cs14bj1.d.mts +20 -0
  87. package/dist/server-ClCwiLMA.mjs +45 -0
  88. package/dist/storage/adapters/index.d.mts +3 -0
  89. package/dist/storage/adapters/index.mjs +3 -0
  90. package/dist/storage/adapters/memory/index.d.mts +2 -0
  91. package/dist/storage/adapters/memory/index.mjs +3 -0
  92. package/dist/storage/index.d.mts +17 -0
  93. package/dist/storage/index.mjs +37 -0
  94. package/dist/theme/adapters/index.d.mts +17 -0
  95. package/dist/theme/adapters/index.mjs +6 -0
  96. package/dist/theme/adapters/v0/index.d.mts +17 -0
  97. package/dist/theme/adapters/v0/index.mjs +5 -0
  98. package/dist/theme/index.d.mts +17 -0
  99. package/dist/theme/index.mjs +16 -0
  100. package/dist/toArray-DIeXVX1C.mjs +38 -0
  101. package/dist/types/index.d.mts +1 -1
  102. package/dist/useClickOutside-p8HP07At.mjs +4680 -0
  103. package/dist/useFeatures-C4JF3Hgr.mjs +122 -0
  104. package/dist/useLocale-DlbShzF-.mjs +85 -0
  105. package/dist/useLogger-CO9JwbSJ.mjs +283 -0
  106. package/dist/usePermissions-DQVT_4nD.mjs +128 -0
  107. package/dist/useTheme-Bcw1Ebyt.mjs +135 -0
  108. package/dist/utilities/index.d.mts +3 -3
  109. package/dist/utilities/index.mjs +3 -3
  110. package/dist/{utilities-BbKjbXTx.mjs → utilities-BqS1sC1W.mjs} +20 -3
  111. package/dist/v0-B40YkIQ-.mjs +21 -0
  112. package/dist/v0-BOxb3nD1.d.mts +33 -0
  113. package/dist/v0-BogbIzpM.mjs +41 -0
  114. package/dist/v0-BtQCSBOG.mjs +37 -0
  115. package/dist/v0-C-9dv_1S.d.mts +10 -0
  116. package/dist/v0-CtjuUUPl.mjs +73 -0
  117. package/dist/v0-DHMoZ7dS.d.mts +22 -0
  118. package/dist/v0-ONBWyQYQ.mjs +83 -0
  119. package/dist/v0-RepwEY1F.d.mts +9 -0
  120. package/dist/virtual-B3IPkHC0.d.mts +9 -0
  121. package/dist/virtual-BP9WXRzN.mjs +44 -0
  122. package/package.json +34 -2
  123. package/dist/useClickOutside-DrkNYxDe.mjs +0 -8871
  124. /package/dist/{adapter-D95FHAtt.d.mts → adapter-DcwxFryd.d.mts} +0 -0
  125. /package/dist/{constants-DHKqjdjH.mjs → adapters-BGJKsBrw.mjs} +0 -0
  126. /package/dist/{htmlElements-DO9n35bD.mjs → htmlElements-d8iBCGpO.mjs} +0 -0
  127. /package/dist/{index-BLK67J_-.d.mts → index-BFBN5Zl3.d.mts} +0 -0
@@ -0,0 +1,682 @@
1
+ import { d as isObject, h as isUndefined, p as isString, t as clamp, v as useId$1 } from "./utilities-BqS1sC1W.mjs";
2
+ import { i as useContext, n as createContext, t as createTrinity } from "./createTrinity-EeHQSsb6.mjs";
3
+ import { i as useLogger } from "./useLogger-CO9JwbSJ.mjs";
4
+ import { shallowReactive } from "vue";
5
+
6
+ //#region src/composables/createRegistry/index.ts
7
+ /**
8
+ * @module createRegistry
9
+ *
10
+ * @see https://0.vuetifyjs.com/composables/registration/create-registry
11
+ *
12
+ * @remarks
13
+ * A foundational composable for managing collections of items (tickets) with:
14
+ * - Unique ID-based access
15
+ * - Index-based ordering
16
+ * - Value-based reverse lookup
17
+ * - Automatic reindexing
18
+ * - Optional event emission
19
+ * - Performance-optimized caching
20
+ *
21
+ * The registry serves as the base for many other composables in the system,
22
+ * including useSelection, useForm, useTimeline, and more.
23
+ */
24
+ /**
25
+ * Creates a new registry instance.
26
+ *
27
+ * @param options The options for the registry instance.
28
+ * @template Z The type of registry ticket that extends RegistryTicket. Use this to add custom properties to tickets.
29
+ * @template E The type of registry context that extends RegistryContext<Z>. Use this when extending the registry with additional methods.
30
+ * @returns A new registry instance.
31
+ *
32
+ * @see https://0.vuetifyjs.com/composables/registration/create-registry#create-registry
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * import { createRegistry } from '@vuetify/v0'
37
+ *
38
+ * const registry = createRegistry()
39
+ *
40
+ * const ticket1 = registry.register({ id: 'user-1', value: { name: 'John' } })
41
+ * const ticket2 = registry.register({ id: 'user-2', value: { name: 'Jane' } })
42
+ *
43
+ * console.log(registry.size) // 2
44
+ * console.log(registry.get('user-1')) // { id: 'user-1', index: 0, value: { name: 'John' }, ... }
45
+ * ```
46
+ */
47
+ function createRegistry(options) {
48
+ const logger = useLogger();
49
+ const events = options?.events ?? false;
50
+ const reactive$1 = options?.reactive ?? false;
51
+ const collection = reactive$1 ? shallowReactive(/* @__PURE__ */ new Map()) : /* @__PURE__ */ new Map();
52
+ const catalog = /* @__PURE__ */ new Map();
53
+ const directory = /* @__PURE__ */ new Map();
54
+ const cache = /* @__PURE__ */ new Map();
55
+ const listeners = /* @__PURE__ */ new Map();
56
+ let indexDependentCount = 0;
57
+ let needsReindex = false;
58
+ let minDirtyIndex = Infinity;
59
+ let batching = false;
60
+ let batched = [];
61
+ function dispatch(event, data) {
62
+ const cbs = listeners.get(event);
63
+ if (!cbs) return;
64
+ for (const cb of cbs) cb(data);
65
+ }
66
+ function emit(event, data = void 0) {
67
+ if (!events) return;
68
+ if (batching) {
69
+ batched.push({
70
+ event,
71
+ data
72
+ });
73
+ return;
74
+ }
75
+ dispatch(event, data);
76
+ }
77
+ function on(event, cb) {
78
+ if (!events) {
79
+ logger.warn(`Events are disabled. Initialize with \`createRegistry({ events: true })\` to enable.`);
80
+ return;
81
+ }
82
+ if (!listeners.has(event)) listeners.set(event, /* @__PURE__ */ new Set());
83
+ listeners.get(event).add(cb);
84
+ }
85
+ function off(event, cb) {
86
+ if (!events) {
87
+ logger.warn(`Events are disabled. Initialize with \`createRegistry({ events: true })\` to enable.`);
88
+ return;
89
+ }
90
+ listeners.get(event)?.delete(cb);
91
+ }
92
+ function dispose() {
93
+ listeners.clear();
94
+ clear();
95
+ }
96
+ function get(id) {
97
+ return collection.get(id);
98
+ }
99
+ function upsert(id, patch = {}) {
100
+ const existing = get(id);
101
+ if (!existing) return register({
102
+ ...patch,
103
+ id
104
+ });
105
+ const hasValue = Object.prototype.hasOwnProperty.call(patch, "value");
106
+ let value = existing.value;
107
+ let valueIsIndex = existing.valueIsIndex;
108
+ if (hasValue) {
109
+ if (/* @__PURE__ */ isUndefined(patch.value)) {
110
+ value = existing.index;
111
+ valueIsIndex = true;
112
+ } else {
113
+ value = patch.value;
114
+ valueIsIndex = false;
115
+ }
116
+ if (valueIsIndex !== existing.valueIsIndex) if (valueIsIndex) indexDependentCount++;
117
+ else indexDependentCount--;
118
+ if (!Object.is(value, existing.value)) {
119
+ unassign(existing.value, id);
120
+ assign(value, id);
121
+ }
122
+ }
123
+ const updated = {
124
+ ...existing,
125
+ ...patch,
126
+ id,
127
+ index: existing.index,
128
+ value,
129
+ valueIsIndex
130
+ };
131
+ collection.set(id, updated);
132
+ invalidate();
133
+ emit("update:ticket", updated);
134
+ return updated;
135
+ }
136
+ function browse(value) {
137
+ if (needsReindex) reindex();
138
+ return catalog.get(value);
139
+ }
140
+ function lookup(index) {
141
+ if (needsReindex) reindex();
142
+ return directory.get(index);
143
+ }
144
+ function has(id) {
145
+ return collection.has(id);
146
+ }
147
+ function assign(value, id) {
148
+ const bucket = catalog.get(value);
149
+ if (bucket) {
150
+ if (!bucket.includes(id)) bucket.push(id);
151
+ } else catalog.set(value, [id]);
152
+ }
153
+ function unassign(value, id) {
154
+ const bucket = catalog.get(value);
155
+ if (!bucket) return;
156
+ const next = bucket.filter((v) => v !== id);
157
+ if (next.length === 0) catalog.delete(value);
158
+ else catalog.set(value, next);
159
+ }
160
+ function keys() {
161
+ const cached = cache.get("keys");
162
+ if (!/* @__PURE__ */ isUndefined(cached)) return cached;
163
+ const keys$1 = Array.from(collection.keys());
164
+ cache.set("keys", keys$1);
165
+ return keys$1;
166
+ }
167
+ function values() {
168
+ const cached = cache.get("values");
169
+ if (!/* @__PURE__ */ isUndefined(cached)) return cached;
170
+ const values$1 = Array.from(collection.values());
171
+ cache.set("values", values$1);
172
+ return values$1;
173
+ }
174
+ function entries() {
175
+ const cached = cache.get("entries");
176
+ if (!/* @__PURE__ */ isUndefined(cached)) return cached;
177
+ const entries$1 = Array.from(collection.entries());
178
+ cache.set("entries", entries$1);
179
+ return entries$1;
180
+ }
181
+ function clear() {
182
+ collection.clear();
183
+ catalog.clear();
184
+ directory.clear();
185
+ invalidate();
186
+ indexDependentCount = 0;
187
+ needsReindex = false;
188
+ minDirtyIndex = Infinity;
189
+ emit("clear:registry");
190
+ }
191
+ function invalidate() {
192
+ if (batching) return;
193
+ cache.clear();
194
+ }
195
+ function batch(fn) {
196
+ if (batching) return fn();
197
+ batching = true;
198
+ batched = [];
199
+ try {
200
+ const result = fn();
201
+ cache.clear();
202
+ for (const { event, data } of batched) dispatch(event, data);
203
+ return result;
204
+ } finally {
205
+ batching = false;
206
+ batched = [];
207
+ }
208
+ }
209
+ function reindex() {
210
+ const startIndex = minDirtyIndex === Infinity ? 0 : minDirtyIndex;
211
+ if (startIndex === 0) {
212
+ catalog.clear();
213
+ directory.clear();
214
+ }
215
+ invalidate();
216
+ let index = 0;
217
+ for (const ticket of collection.values()) {
218
+ if (index < startIndex) {
219
+ index++;
220
+ continue;
221
+ }
222
+ if (startIndex > 0) directory.delete(ticket.index);
223
+ if (ticket.valueIsIndex) {
224
+ if (startIndex > 0) unassign(ticket.value, ticket.id);
225
+ ticket.value = index;
226
+ assign(ticket.value, ticket.id);
227
+ } else if (startIndex === 0) assign(ticket.value, ticket.id);
228
+ ticket.index = index;
229
+ directory.set(index, ticket.id);
230
+ index++;
231
+ }
232
+ needsReindex = false;
233
+ minDirtyIndex = Infinity;
234
+ emit("reindex:registry");
235
+ }
236
+ function register(registration = {}) {
237
+ const size = collection.size;
238
+ const id = registration.id ?? /* @__PURE__ */ useId$1();
239
+ if (has(id)) {
240
+ logger.warn(`Ticket "${id}" already exists. Use \`upsert()\` to update or check \`has()\` before registering.`);
241
+ return get(id);
242
+ }
243
+ const valueIsUndefined = /* @__PURE__ */ isUndefined(registration.value);
244
+ const index = registration.index ?? size;
245
+ const value = valueIsUndefined ? index : registration.value;
246
+ const valueIsIndex = valueIsUndefined;
247
+ if (valueIsIndex) indexDependentCount++;
248
+ const rawTicket = {
249
+ ...registration,
250
+ id,
251
+ index,
252
+ value,
253
+ valueIsIndex
254
+ };
255
+ const ticket = reactive$1 ? shallowReactive(rawTicket) : rawTicket;
256
+ collection.set(ticket.id, ticket);
257
+ directory.set(ticket.index, ticket.id);
258
+ assign(ticket.value, ticket.id);
259
+ invalidate();
260
+ emit("register:ticket", ticket);
261
+ return ticket;
262
+ }
263
+ function unregister(id) {
264
+ const ticket = collection.get(id);
265
+ if (!ticket) return;
266
+ if (ticket.valueIsIndex) indexDependentCount--;
267
+ collection.delete(ticket.id);
268
+ directory.delete(ticket.index);
269
+ unassign(ticket.value, ticket.id);
270
+ const willReindex = indexDependentCount > 0 && ticket.index < collection.size;
271
+ if (!willReindex) invalidate();
272
+ emit("unregister:ticket", ticket);
273
+ minDirtyIndex = Math.min(minDirtyIndex, ticket.index);
274
+ if (willReindex) reindex();
275
+ else needsReindex = true;
276
+ }
277
+ function offboard(ids) {
278
+ batch(() => {
279
+ const removed = [];
280
+ for (const id of ids) {
281
+ const ticket = collection.get(id);
282
+ if (!ticket) continue;
283
+ if (ticket.valueIsIndex) indexDependentCount--;
284
+ minDirtyIndex = Math.min(minDirtyIndex, ticket.index);
285
+ collection.delete(ticket.id);
286
+ directory.delete(ticket.index);
287
+ unassign(ticket.value, ticket.id);
288
+ removed.push(ticket);
289
+ }
290
+ if (removed.length === 0) return;
291
+ for (const ticket of removed) emit("unregister:ticket", ticket);
292
+ needsReindex = true;
293
+ });
294
+ }
295
+ function seek(direction = "first", from, predicate) {
296
+ if (collection.size === 0) return void 0;
297
+ if (needsReindex) reindex();
298
+ if (!predicate && /* @__PURE__ */ isUndefined(from)) {
299
+ const tickets$1 = values();
300
+ return direction === "first" ? tickets$1[0] : tickets$1.at(-1);
301
+ }
302
+ const tickets = values();
303
+ const index = /* @__PURE__ */ isUndefined(from) ? void 0 : /* @__PURE__ */ clamp(from, 0, tickets.length - 1);
304
+ if (direction === "last") {
305
+ const start = /* @__PURE__ */ isUndefined(index) ? tickets.length - 1 : index;
306
+ for (let i = start; i >= 0; i--) {
307
+ const ticket = tickets[i];
308
+ if (!predicate || predicate(ticket)) return ticket;
309
+ }
310
+ } else {
311
+ const start = /* @__PURE__ */ isUndefined(index) ? 0 : index;
312
+ for (let i = start; i < tickets.length; i++) {
313
+ const ticket = tickets[i];
314
+ if (!predicate || predicate(ticket)) return ticket;
315
+ }
316
+ }
317
+ }
318
+ return {
319
+ collection,
320
+ emit,
321
+ on,
322
+ off,
323
+ dispose,
324
+ has,
325
+ keys,
326
+ clear,
327
+ browse,
328
+ entries,
329
+ values,
330
+ lookup,
331
+ get,
332
+ upsert,
333
+ register,
334
+ unregister,
335
+ reindex,
336
+ seek,
337
+ batch,
338
+ onboard(registrations) {
339
+ return batch(() => registrations.map((registration) => register(registration)));
340
+ },
341
+ offboard,
342
+ get size() {
343
+ return collection.size;
344
+ }
345
+ };
346
+ }
347
+ /**
348
+ * Creates a new registry context.
349
+ *
350
+ * @param options The options for the registry context, including `namespace` (defaults to `'v0:registry'`) and `events`.
351
+ * @template Z The type of registry ticket that extends RegistryTicket. Use this to add custom properties to tickets.
352
+ * @template E The type of registry context that extends RegistryContext<Z>. Use this when extending the registry with additional methods.
353
+ * @returns A new registry context.
354
+ *
355
+ * @see https://0.vuetifyjs.com/composables/registration/create-registry#create-registry-context
356
+ *
357
+ * @example
358
+ * ```ts
359
+ * import { createRegistryContext } from '@vuetify/v0'
360
+ *
361
+ * // With default namespace 'v0:registry'
362
+ * export const [useItems, provideItems, items] = createRegistryContext()
363
+ *
364
+ * // Or with custom namespace
365
+ * export const [useItems, provideItems, items] = createRegistryContext({ namespace: 'my-items' })
366
+ *
367
+ * // In a parent component:
368
+ * provideItems()
369
+ *
370
+ * // In a child component:
371
+ * const items = useItems()
372
+ * items.register({ id: 'item-1', value: 'Value 1' })
373
+ * ```
374
+ */
375
+ function createRegistryContext(_options = {}) {
376
+ const { namespace = "v0:registry", ...options } = _options;
377
+ const [useRegistryContext, _provideRegistryContext] = createContext(namespace);
378
+ const context = createRegistry(options);
379
+ function provideRegistryContext(_context = context, app) {
380
+ return _provideRegistryContext(_context, app);
381
+ }
382
+ return createTrinity(useRegistryContext, provideRegistryContext, context);
383
+ }
384
+ /**
385
+ * Uses an existing registry from context.
386
+ *
387
+ * @param namespace The namespace for the registry context. Defaults to `'v0:registry'`.
388
+ * @template Z The type of registry ticket that extends RegistryTicket.
389
+ * @template E The type of registry context that extends RegistryContext<Z>.
390
+ * @returns The registry instance.
391
+ *
392
+ * @see https://0.vuetifyjs.com/composables/registration/create-registry#use-registry
393
+ *
394
+ * @example
395
+ * ```ts
396
+ * import { useRegistry } from '@vuetify/v0'
397
+ *
398
+ * // In a child component (after provideRegistry was called by an ancestor):
399
+ * const registry = useRegistry()
400
+ *
401
+ * registry.register({ id: 'item-1', value: 'Value 1' })
402
+ * ```
403
+ */
404
+ function useRegistry(namespace = "v0:registry") {
405
+ return useContext(namespace);
406
+ }
407
+
408
+ //#endregion
409
+ //#region src/composables/createTokens/index.ts
410
+ /**
411
+ * @module createTokens
412
+ *
413
+ * @see https://0.vuetifyjs.com/composables/registration/create-tokens
414
+ *
415
+ * @remarks
416
+ * Design token registry with alias resolution and W3C Design Tokens format support.
417
+ *
418
+ * Key features:
419
+ * - Alias resolution with circular reference detection
420
+ * - Nested token flattening with dot notation
421
+ * - W3C Design Tokens format ($value, $type, $description, $extensions)
422
+ * - Path-based resolution (e.g., {colors}.blue.500)
423
+ * - Resolution caching for performance (~28,590 ops/sec)
424
+ *
425
+ * Used by useTheme, useLocale, and useFeatures for token-based configuration.
426
+ */
427
+ /**
428
+ * Creates a new token instance.
429
+ *
430
+ * @param tokens The tokens to use.
431
+ * @param options The options for the token instance.
432
+ * @template Z The type of the token ticket.
433
+ * @template E The type of the token context.
434
+ * @returns A new token instance.
435
+ *
436
+ * @see https://www.designtokens.org/tr/drafts/format/
437
+ * @see https://0.vuetifyjs.com/composables/registration/create-tokens
438
+ *
439
+ * @example
440
+ * ```ts
441
+ * import { createTokens } from '@vuetify/v0'
442
+ *
443
+ * const tokens = createTokens({
444
+ * colors: {
445
+ * primary: '#3b82f6',
446
+ * secondary: '{colors.primary}', // Alias reference
447
+ * },
448
+ * })
449
+ *
450
+ * console.log(tokens.resolve('{colors.primary}')) // '#3b82f6'
451
+ * console.log(tokens.resolve('{colors.secondary}')) // '#3b82f6'
452
+ * ```
453
+ */
454
+ function createTokens(tokens = {}, options = {}) {
455
+ const logger = useLogger();
456
+ const registry = createRegistry(options);
457
+ const cache = /* @__PURE__ */ new Map();
458
+ registry.onboard(flatten(tokens, options.prefix, !!options.flat));
459
+ function isAlias(token) {
460
+ return /* @__PURE__ */ isString(token) && token.length > 2 && token[0] === "{" && token.at(-1) === "}";
461
+ }
462
+ function isTokenAlias(value) {
463
+ return /* @__PURE__ */ isObject(value) && "$value" in value;
464
+ }
465
+ function resolve(token, visited = /* @__PURE__ */ new Set()) {
466
+ const cacheKey = /* @__PURE__ */ isString(token) ? token : JSON.stringify(token);
467
+ const cached = cache.get(cacheKey);
468
+ if (!/* @__PURE__ */ isUndefined(cached)) return cached;
469
+ const reference = isTokenAlias(token) ? token.$value : token;
470
+ const isAliasReference = /* @__PURE__ */ isString(reference) && isAlias(reference);
471
+ const clean = isAliasReference ? reference.slice(1, -1) : String(reference);
472
+ if (visited.has(clean)) {
473
+ logger.warn(`Circular alias detected for "${clean}"`);
474
+ cache.set(cacheKey, void 0);
475
+ return;
476
+ }
477
+ visited.add(clean);
478
+ let found = registry.get(clean);
479
+ let segments = [];
480
+ if (!found && clean.includes(".")) {
481
+ const parts = clean.split(".");
482
+ for (let i = parts.length - 1; i > 0; i--) {
483
+ const prefix = parts.slice(0, i).join(".");
484
+ const suffix = parts.slice(i);
485
+ const candidate = registry.get(prefix);
486
+ if (!/* @__PURE__ */ isUndefined(candidate?.value)) {
487
+ found = candidate;
488
+ segments = suffix;
489
+ break;
490
+ }
491
+ }
492
+ }
493
+ if (/* @__PURE__ */ isUndefined(found?.value)) {
494
+ if (isAliasReference) logger.warn(`Alias not found for "${String(reference)}"`);
495
+ cache.set(cacheKey, void 0);
496
+ return;
497
+ }
498
+ let result;
499
+ let current = found.value;
500
+ if (segments.length > 0) {
501
+ if (isTokenAlias(current)) current = current.$value;
502
+ for (const segment of segments) {
503
+ if (!/* @__PURE__ */ isObject(current) || !(segment in current)) {
504
+ current = void 0;
505
+ break;
506
+ }
507
+ current = current[segment];
508
+ if (isTokenAlias(current)) current = current.$value;
509
+ }
510
+ if (/* @__PURE__ */ isUndefined(current)) {
511
+ logger.warn(`Path not found inside "${clean}": ${segments.join(".")}`);
512
+ cache.set(cacheKey, void 0);
513
+ return;
514
+ }
515
+ result = current;
516
+ } else if (isTokenAlias(current)) {
517
+ const inner = current.$value;
518
+ if (/* @__PURE__ */ isString(inner) && isAlias(inner)) return resolve(inner, visited);
519
+ result = inner;
520
+ } else if (/* @__PURE__ */ isString(current) && isAlias(current)) return resolve(current, visited);
521
+ else result = current;
522
+ cache.set(cacheKey, result);
523
+ return result;
524
+ }
525
+ const { register: _register, upsert: _upsert, unregister: _unregister } = registry;
526
+ function register(registration) {
527
+ cache.clear();
528
+ return _register(registration);
529
+ }
530
+ function upsert(id, registration) {
531
+ cache.clear();
532
+ return _upsert(id, registration);
533
+ }
534
+ function unregister(id) {
535
+ cache.clear();
536
+ return _unregister(id);
537
+ }
538
+ return {
539
+ ...registry,
540
+ register,
541
+ upsert,
542
+ unregister,
543
+ resolve,
544
+ isAlias,
545
+ get size() {
546
+ return registry.size;
547
+ }
548
+ };
549
+ }
550
+ /**
551
+ * Creates a new token context.
552
+ *
553
+ * @param namespace The namespace for the token context.
554
+ * @param tokens The tokens to use.
555
+ * @template Z The type of the token ticket.
556
+ * @template E The type of the token context.
557
+ * @returns A new token context.
558
+ *
559
+ * @see https://0.vuetifyjs.com/composables/registration/create-tokens
560
+ *
561
+ * @example
562
+ * ```ts
563
+ * import { createTokensContext } from '@vuetify/v0'
564
+ *
565
+ * export const [useTokens, provideTokens, context] = createTokensContext({
566
+ * namespace: 'v0:tokens',
567
+ * tokens: {
568
+ * colors: {
569
+ * primary: '#3b82f6',
570
+ * secondary: '{colors.primary}', // Alias reference
571
+ * },
572
+ * },
573
+ * })
574
+ * ```
575
+ */
576
+ function createTokensContext(_options) {
577
+ const { namespace = "v0:tokens", tokens = {}, ...options } = _options;
578
+ const [useTokensContext, _provideTokensContext] = createContext(namespace);
579
+ const context = createTokens(tokens, options);
580
+ function provideTokensContext(_context = context, app) {
581
+ return _provideTokensContext(_context, app);
582
+ }
583
+ return createTrinity(useTokensContext, provideTokensContext, context);
584
+ }
585
+ /**
586
+ * Returns the current tokens instance.
587
+ *
588
+ * @param namespace The namespace for the tokens context. Defaults to `'v0:tokens'`.
589
+ * @returns The current tokens instance.
590
+ *
591
+ * @see https://0.vuetifyjs.com/composables/registration/create-tokens
592
+ *
593
+ * @example
594
+ * ```vue
595
+ * <script setup lang="ts">
596
+ * import { useTokens } from '@vuetify/v0'
597
+ *
598
+ * const tokens = useTokens()
599
+ * <\/script>
600
+ * ```
601
+ */
602
+ function useTokens(namespace = "v0:tokens") {
603
+ return useContext(namespace);
604
+ }
605
+ /**
606
+ * Flattens a nested collection of tokens into a flat array of tokens.
607
+ * Each token is represented by an object containing its ID & value.
608
+ * @param tokens The collection of tokens to flatten.
609
+ * @param prefix An optional prefix to prepend to each token ID.
610
+ * @returns An array of flattened tokens, each with an ID and value.
611
+ */
612
+ function flatten(tokens, prefix = "", flat = false) {
613
+ const flattened = [];
614
+ const stack = [{
615
+ tokens,
616
+ prefix,
617
+ flat
618
+ }];
619
+ while (stack.length > 0) {
620
+ const { tokens: currentTokens, prefix: currentPrefix, flat: flat$1 } = stack.pop();
621
+ const meta = {};
622
+ for (const k in currentTokens) if (k.startsWith("$")) meta[k] = currentTokens[k];
623
+ if (Object.keys(meta).length > 0 && currentPrefix) flattened.push({
624
+ id: currentPrefix,
625
+ value: meta
626
+ });
627
+ for (const key in currentTokens) {
628
+ if (key.startsWith("$")) continue;
629
+ const value = currentTokens[key];
630
+ const id = currentPrefix ? `${currentPrefix}.${key}` : key;
631
+ if (!/* @__PURE__ */ isObject(value)) {
632
+ flattened.push({
633
+ id,
634
+ value
635
+ });
636
+ continue;
637
+ }
638
+ if ("$value" in value) {
639
+ flattened.push({
640
+ id,
641
+ value
642
+ });
643
+ const inner = value.$value;
644
+ if (/* @__PURE__ */ isObject(inner) && !flat$1) for (const innerKey in inner) {
645
+ if (innerKey.startsWith("$")) continue;
646
+ const child = inner[innerKey];
647
+ const childId = `${id}.${innerKey}`;
648
+ if (!/* @__PURE__ */ isObject(child)) flattened.push({
649
+ id: childId,
650
+ value: child
651
+ });
652
+ else if ("$value" in child) flattened.push({
653
+ id: childId,
654
+ value: child
655
+ });
656
+ else stack.push({
657
+ tokens: child,
658
+ prefix: childId,
659
+ flat: flat$1
660
+ });
661
+ }
662
+ continue;
663
+ }
664
+ if (flat$1) {
665
+ flattened.push({
666
+ id,
667
+ value
668
+ });
669
+ continue;
670
+ }
671
+ stack.push({
672
+ tokens: value,
673
+ prefix: id,
674
+ flat: flat$1
675
+ });
676
+ }
677
+ }
678
+ return flattened;
679
+ }
680
+
681
+ //#endregion
682
+ export { createRegistryContext as a, createRegistry as i, createTokensContext as n, useRegistry as o, useTokens as r, createTokens as t };