@takazudo/zdtp 0.4.4 → 0.4.5

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.
@@ -3,65 +3,65 @@ class w extends Error {
3
3
  super(t), this.name = "TierResolverError", Object.setPrototypeOf(this, w.prototype);
4
4
  }
5
5
  }
6
- function E(e, t) {
6
+ function A(e, t) {
7
7
  return e.tiers.find((n) => n.id === t);
8
8
  }
9
9
  function $(e, t) {
10
10
  return e.items.find((n) => n.id === t);
11
11
  }
12
- function G(e, t, n, l) {
13
- const g = E(e, t);
12
+ function W(e, t, n, a) {
13
+ const g = A(e, t);
14
14
  if (!g)
15
15
  throw new w(
16
- `Tier "${t}" not found in tab "${e.id}". Available tiers: ${e.tiers.map((a) => a.id).join(", ")}.`
16
+ `Tier "${t}" not found in tab "${e.id}". Available tiers: ${e.tiers.map((l) => l.id).join(", ")}.`
17
17
  );
18
18
  const c = $(g, n);
19
19
  if (!c)
20
20
  throw new w(
21
21
  `Item "${n}" not found in tier "${t}" of tab "${e.id}".`
22
22
  );
23
- const i = l[t]?.[n];
23
+ const s = a[t]?.[n];
24
24
  if (g.referencesTier !== void 0) {
25
- const a = g.referencesTier, f = E(e, a);
25
+ const l = g.referencesTier, f = A(e, l);
26
26
  if (!f)
27
27
  throw new w(
28
- `Tier "${t}" declares referencesTier "${a}" but that tier does not exist in tab "${e.id}".`
28
+ `Tier "${t}" declares referencesTier "${l}" but that tier does not exist in tab "${e.id}".`
29
29
  );
30
- const o = $(f, i ?? n);
30
+ const o = $(f, s ?? n);
31
31
  if (!o) {
32
- const d = $(f, c.default) ?? $(f, n) ?? f.items[0];
33
- if (!d)
32
+ const u = $(f, c.default) ?? $(f, n) ?? f.items[0];
33
+ if (!u)
34
34
  throw new w(
35
- `Referenced tier "${a}" has no items; cannot resolve fallback for item "${n}" in tier "${t}" of tab "${e.id}".`
35
+ `Referenced tier "${l}" has no items; cannot resolve fallback for item "${n}" in tier "${t}" of tab "${e.id}".`
36
36
  );
37
- return { kind: "ref", targetCssVar: d.cssVar };
37
+ return { kind: "ref", targetCssVar: u.cssVar };
38
38
  }
39
39
  return { kind: "ref", targetCssVar: o.cssVar };
40
40
  }
41
- return i !== void 0 ? c.pill && i === c.pill.value ? { kind: "literal", value: c.pill.value } : { kind: "literal", value: i } : c.pill ? { kind: "literal", value: c.pill.customDefault } : { kind: "literal", value: c.default };
41
+ return s !== void 0 ? c.pill && s === c.pill.value ? { kind: "literal", value: c.pill.value } : { kind: "literal", value: s } : c.pill ? { kind: "literal", value: c.pill.customDefault } : { kind: "literal", value: c.default };
42
42
  }
43
- function U(e) {
43
+ function Y(e) {
44
44
  return e.kind === "literal" ? e.value : `var(${e.targetCssVar})`;
45
45
  }
46
- function _(e, t, n = [t]) {
47
- const l = e.tab === void 0 || e.tab === t.id ? t : n.find((s) => s.id === e.tab);
48
- if (!l)
46
+ function D(e, t, n = [t]) {
47
+ const a = e.tab === void 0 || e.tab === t.id ? t : n.find((i) => i.id === e.tab);
48
+ if (!a)
49
49
  throw new w(
50
- `Cross-tab ref target tab "${e.tab}" not found. Available tabs: ${n.map((s) => s.id).join(", ")}.`
50
+ `Cross-tab ref target tab "${e.tab}" not found. Available tabs: ${n.map((i) => i.id).join(", ")}.`
51
51
  );
52
- const g = E(l, e.tier);
52
+ const g = A(a, e.tier);
53
53
  if (!g)
54
54
  throw new w(
55
- `Cross-tab ref target tier "${e.tier}" not found in tab "${l.id}". Available tiers: ${l.tiers.map((s) => s.id).join(", ")}.`
55
+ `Cross-tab ref target tier "${e.tier}" not found in tab "${a.id}". Available tiers: ${a.tiers.map((i) => i.id).join(", ")}.`
56
56
  );
57
57
  const c = $(g, e.item);
58
58
  if (!c)
59
59
  throw new w(
60
- `Cross-tab ref target item "${e.item}" not found in tier "${e.tier}" of tab "${l.id}". Available items: ${g.items.map((s) => s.id).join(", ")}.`
60
+ `Cross-tab ref target item "${e.item}" not found in tier "${e.tier}" of tab "${a.id}". Available items: ${g.items.map((i) => i.id).join(", ")}.`
61
61
  );
62
62
  return c.cssVar;
63
63
  }
64
- function W(e, t) {
64
+ function I(e, t) {
65
65
  return e.paletteCssVarTemplate.replace("{n}", String(t));
66
66
  }
67
67
  const M = /* @__PURE__ */ new Set([
@@ -224,36 +224,36 @@ const M = /* @__PURE__ */ new Set([
224
224
  function H(e) {
225
225
  return e.startsWith("#") || e.includes("(") || M.has(e.toLowerCase());
226
226
  }
227
- function N(e, t, n, l) {
227
+ function N(e, t, n, a) {
228
228
  const g = [], c = e.indexOf(":");
229
229
  if (c !== -1) {
230
- const i = e.slice(0, c), a = e.slice(c + 1), f = t.find((r) => r.tier === i);
231
- f && g.push({ tab: f.tab, tier: f.tier, item: a });
230
+ const s = e.slice(0, c), l = e.slice(c + 1), f = t.find((r) => r.tier === s);
231
+ f && g.push({ tab: f.tab, tier: f.tier, item: l });
232
232
  }
233
- const [s] = t;
234
- g.push({ tab: s.tab, tier: s.tier, item: e });
235
- for (const i of g)
233
+ const [i] = t;
234
+ g.push({ tab: i.tab, tier: i.tier, item: e });
235
+ for (const s of g)
236
236
  try {
237
- return _(i, n, l), { ref: i };
237
+ return D(s, n, a), { ref: s };
238
238
  } catch {
239
239
  }
240
240
  return { ref: g[0] };
241
241
  }
242
- function K(e, t, n, l, g, c) {
243
- const s = t.get(e.default);
244
- return s !== void 0 ? s : e.default === "bg" || e.default === "fg" ? e.default : n && n.length > 0 && !H(e.default) ? N(e.default, n, l, g) : c ? (console.warn(
242
+ function K(e, t, n, a, g, c) {
243
+ const i = t.get(e.default);
244
+ return i !== void 0 ? i : e.default === "bg" || e.default === "fg" ? e.default : n && n.length > 0 && !H(e.default) ? N(e.default, n, a, g) : c ? (console.warn(
245
245
  `[design-token-panel] semantic item "${e.id}" default "${e.default}" names no palette item; falling back to palette index 0`
246
246
  ), 0) : { literal: e.default };
247
247
  }
248
- function R(e, t = [e]) {
248
+ function V(e, t = [e]) {
249
249
  const n = e.colorExtras;
250
250
  if (!n) return;
251
- const l = e.tiers.find(
251
+ const a = e.tiers.find(
252
252
  (o) => !o.referencesTier && !o.semantic && o.items.length > 0 && o.items[0].type.kind === "color"
253
253
  ), g = e.tiers.find(
254
- (o) => l && o.referencesTier === l.id || o.semantic === !0
254
+ (o) => a && o.referencesTier === a.id || o.semantic === !0
255
255
  );
256
- if (!l && !g)
256
+ if (!a && !g)
257
257
  return {
258
258
  id: n.id,
259
259
  label: n.label,
@@ -267,16 +267,16 @@ function R(e, t = [e]) {
267
267
  colorSchemes: n.colorSchemes,
268
268
  panelSettings: n.panelSettings
269
269
  };
270
- const c = l?.items ?? [], s = c.length, i = c[0] ? c[0].cssVar.replace(/\d+$/, "{n}") : "--zudo-stub-p{n}", a = /* @__PURE__ */ new Map();
270
+ const c = a?.items ?? [], i = c.length, s = c[0] ? c[0].cssVar.replace(/\d+$/, "{n}") : "--zudo-stub-p{n}", l = /* @__PURE__ */ new Map();
271
271
  for (let o = 0; o < c.length; o++)
272
- a.set(c[o].id, o);
272
+ l.set(c[o].id, o);
273
273
  const f = {}, r = {};
274
274
  if (g) {
275
- const o = !g.semantic;
275
+ const o = !g.semantic, u = n.semanticDefaults;
276
276
  for (const d of g.items)
277
- r[d.id] = d.cssVar, f[d.id] = K(
277
+ r[d.id] = d.cssVar, f[d.id] = u && d.id in u ? u[d.id] : K(
278
278
  d,
279
- a,
279
+ l,
280
280
  g.referencesRamps,
281
281
  e,
282
282
  t,
@@ -286,9 +286,9 @@ function R(e, t = [e]) {
286
286
  return {
287
287
  id: n.id,
288
288
  label: n.label,
289
- paletteSize: s,
289
+ paletteSize: i,
290
290
  baseRoles: n.baseRoles,
291
- paletteCssVarTemplate: i,
291
+ paletteCssVarTemplate: s,
292
292
  semanticDefaults: f,
293
293
  semanticCssNames: r,
294
294
  baseDefaults: n.baseDefaults,
@@ -297,34 +297,34 @@ function R(e, t = [e]) {
297
297
  panelSettings: n.panelSettings
298
298
  };
299
299
  }
300
- function Y(e) {
300
+ function X(e) {
301
301
  const t = e.find((n) => n.id === "color");
302
302
  if (t)
303
- return R(t, e);
303
+ return V(t, e);
304
304
  }
305
305
  function z(e) {
306
306
  const t = e.find((n) => n.id === "color-secondary");
307
- return t ? R(t, e) ?? null : null;
307
+ return t ? V(t, e) ?? null : null;
308
308
  }
309
- function A(e, t) {
309
+ function S(e, t) {
310
310
  if (Object.is(e, t)) return !0;
311
311
  if (e === null || t === null || typeof e != typeof t || typeof e != "object") return !1;
312
312
  if (Array.isArray(e)) {
313
313
  if (!Array.isArray(t) || e.length !== t.length) return !1;
314
314
  for (let c = 0; c < e.length; c++)
315
- if (!A(e[c], t[c])) return !1;
315
+ if (!S(e[c], t[c])) return !1;
316
316
  return !0;
317
317
  }
318
318
  if (Array.isArray(t)) return !1;
319
- const n = Object.keys(e), l = Object.keys(t);
320
- if (n.length !== l.length) return !1;
321
- const g = new Set(l);
319
+ const n = Object.keys(e), a = Object.keys(t);
320
+ if (n.length !== a.length) return !1;
321
+ const g = new Set(a);
322
322
  for (const c of n)
323
- if (!g.has(c) || !A(e[c], t[c]))
323
+ if (!g.has(c) || !S(e[c], t[c]))
324
324
  return !1;
325
325
  return !0;
326
326
  }
327
- const V = {
327
+ const O = {
328
328
  storagePrefix: "zudo-design-token-panel",
329
329
  consoleNamespace: "zudo",
330
330
  modalClassPrefix: "zudo-design-token-panel-modal",
@@ -336,19 +336,20 @@ const V = {
336
336
  // No bundled apply endpoint / routing — hosts wire their own.
337
337
  applyEndpoint: void 0,
338
338
  applyRouting: void 0
339
- }, j = /* @__PURE__ */ Symbol.for("@takazudo/zdtp:singleton");
339
+ }, R = /* @__PURE__ */ Symbol.for("@takazudo/zdtp:singleton");
340
340
  function y() {
341
341
  const e = globalThis;
342
- let t = e[j];
342
+ let t = e[R];
343
343
  return t || (t = {
344
344
  instances: /* @__PURE__ */ new Map(),
345
345
  defaultPrefix: null,
346
346
  pendingColorPresets: null,
347
347
  pendingPostConfigureHooks: [],
348
- lifecycleHooks: {}
349
- }, e[j] = t), t;
348
+ lifecycleHooks: {},
349
+ colorSchemeOwners: /* @__PURE__ */ new Set()
350
+ }, e[R] = t), t;
350
351
  }
351
- function D(e) {
352
+ function F(e) {
352
353
  return {
353
354
  instanceId: e,
354
355
  open() {
@@ -370,7 +371,7 @@ function D(e) {
370
371
  }
371
372
  };
372
373
  }
373
- function I(e) {
374
+ function Q(e) {
374
375
  y().lifecycleHooks = {
375
376
  configured: e.configured,
376
377
  open: e.open,
@@ -379,40 +380,40 @@ function I(e) {
379
380
  destroy: e.destroy
380
381
  };
381
382
  }
382
- function X(e) {
383
- const t = y(), n = e.storagePrefix, l = t.instances.get(n);
384
- if (l) {
383
+ function Z(e) {
384
+ const t = y(), n = e.storagePrefix, a = t.instances.get(n);
385
+ if (a) {
385
386
  const f = (r) => ({ ...r, applySink: void 0 });
386
- if (A(f(l.suppliedConfig), f(e)))
387
- return t.defaultPrefix = n, l.handle;
387
+ if (S(f(a.suppliedConfig), f(e)))
388
+ return t.defaultPrefix = n, a.handle;
388
389
  throw new Error(
389
390
  `[design-token-panel] configurePanel() was already called with different values for storagePrefix "${n}". Configuration is one-shot per prefix per page lifecycle. To re-configure this prefix, call handle.destroy() first, then configurePanel() again. (Use a distinct storagePrefix for a second panel instance.)`
390
391
  );
391
392
  }
392
393
  const g = t.pendingColorPresets, c = g ? { ...e, colorPresets: g } : { ...e };
393
394
  t.pendingColorPresets = null;
394
- const s = t.instances.size === 0, i = s ? [...t.pendingPostConfigureHooks] : [];
395
- s && (t.pendingPostConfigureHooks.length = 0);
396
- const a = {
395
+ const i = t.instances.size === 0, s = i ? [...t.pendingPostConfigureHooks] : [];
396
+ i && (t.pendingPostConfigureHooks.length = 0);
397
+ const l = {
397
398
  config: c,
398
399
  // Snapshot the as-supplied config before any runtime merges. Used by the
399
400
  // idempotency guard so view-transition re-calls with the original inline
400
401
  // config keep passing even after setPanelColorPresets mutates `config`.
401
402
  suppliedConfig: { ...e },
402
403
  pendingColorPresets: null,
403
- postConfigureHooks: i,
404
- handle: D(n)
404
+ postConfigureHooks: s,
405
+ handle: F(n)
405
406
  };
406
- t.instances.set(n, a), t.defaultPrefix = n;
407
- for (const f of a.postConfigureHooks)
407
+ t.instances.set(n, l), t.defaultPrefix = n;
408
+ for (const f of l.postConfigureHooks)
408
409
  f();
409
- return t.lifecycleHooks.configured?.(n), a.handle;
410
+ return t.lifecycleHooks.configured?.(n), l.handle;
410
411
  }
411
412
  function x() {
412
413
  const e = y();
413
414
  return e.defaultPrefix === null ? null : e.instances.get(e.defaultPrefix) ?? null;
414
415
  }
415
- function Q(e) {
416
+ function ee(e) {
416
417
  const t = x();
417
418
  if (t === null) {
418
419
  const n = y();
@@ -422,67 +423,83 @@ function Q(e) {
422
423
  }
423
424
  t.postConfigureHooks.includes(e) || (t.postConfigureHooks.push(e), e());
424
425
  }
425
- function O() {
426
- return x()?.config ?? V;
426
+ function _() {
427
+ return x()?.config ?? O;
427
428
  }
428
- function Z() {
429
+ function te() {
429
430
  return [...y().instances.values()].map((e) => e.config);
430
431
  }
431
- function ee(e) {
432
+ function ne(e) {
432
433
  return y().instances.get(e)?.config ?? null;
433
434
  }
434
- function te() {
435
+ function re() {
436
+ const e = y();
437
+ e.instances.clear(), e.defaultPrefix = null, e.pendingColorPresets = null, e.pendingPostConfigureHooks.length = 0, v().clear();
438
+ }
439
+ function v() {
435
440
  const e = y();
436
- e.instances.clear(), e.defaultPrefix = null, e.pendingColorPresets = null, e.pendingPostConfigureHooks.length = 0;
441
+ return e.colorSchemeOwners || (e.colorSchemeOwners = /* @__PURE__ */ new Set()), e.colorSchemeOwners;
437
442
  }
438
- function ne(e = O()) {
443
+ function ie(e) {
444
+ v().add(e);
445
+ }
446
+ function oe(e) {
447
+ v().delete(e);
448
+ }
449
+ function se(e) {
450
+ return v().has(e);
451
+ }
452
+ function ae(e = _()) {
439
453
  return z(e.tabs);
440
454
  }
441
- function re(e) {
455
+ function le(e) {
442
456
  return `${e.storagePrefix}-state-v2`;
443
457
  }
444
- function ie(e) {
458
+ function fe(e) {
445
459
  return `${e.storagePrefix}-state-v3`;
446
460
  }
447
- function oe(e) {
461
+ function ce(e) {
462
+ return `${e.storagePrefix}-state-v4`;
463
+ }
464
+ function ge(e) {
448
465
  return `${e.storagePrefix}-state`;
449
466
  }
450
- function se(e) {
467
+ function ue(e) {
451
468
  return `${e.storagePrefix}-open`;
452
469
  }
453
- function ae(e) {
470
+ function de(e) {
454
471
  return `${e.storagePrefix}-position`;
455
472
  }
456
- function le(e) {
473
+ function pe(e) {
457
474
  return `${e.storagePrefix}-size`;
458
475
  }
459
- function fe(e) {
476
+ function ye(e) {
460
477
  return `${e.storagePrefix}-density`;
461
478
  }
462
- function ce(e) {
479
+ function me(e) {
463
480
  return `${e.storagePrefix}:visible`;
464
481
  }
465
- function ge(e) {
482
+ function he(e) {
466
483
  return `${e.storagePrefix}:autoload`;
467
484
  }
468
- function de(e) {
485
+ function be(e) {
469
486
  return `${e.storagePrefix}-root`;
470
487
  }
471
- const F = V.storagePrefix, q = "toggle-design-token-panel";
472
- function ue(e) {
473
- return e.storagePrefix === F ? q : e.toggleEvent ?? `toggle-${e.storagePrefix}`;
488
+ const q = O.storagePrefix, L = "toggle-design-token-panel";
489
+ function we(e) {
490
+ return e.storagePrefix === q ? L : e.toggleEvent ?? `toggle-${e.storagePrefix}`;
474
491
  }
475
- const L = "__zdtp:open-state-changed";
476
- function pe(e) {
477
- return `${L}:${e.storagePrefix}`;
492
+ const J = "__zdtp:open-state-changed";
493
+ function ke(e) {
494
+ return `${J}:${e.storagePrefix}`;
478
495
  }
479
- function ye(e, t) {
496
+ function $e(e, t) {
480
497
  return `${e.modalClassPrefix}${t}`;
481
498
  }
482
- function me(e) {
499
+ function Ce(e) {
483
500
  return `${e.exportFilenameBase}.json`;
484
501
  }
485
- function he(e) {
502
+ function Pe(e) {
486
503
  if (e === null || typeof e != "object" || Array.isArray(e))
487
504
  throw new Error("[design-token-panel] PanelConfig must be a non-null object");
488
505
  const t = e;
@@ -497,7 +514,7 @@ function he(e) {
497
514
  throw new Error(
498
515
  `[design-token-panel] PanelConfig.${n} must be a non-empty string (got ${typeof t[n]})`
499
516
  );
500
- if (J(t.tabs), t.toggleEvent !== void 0 && (typeof t.toggleEvent != "string" || t.toggleEvent.length === 0))
517
+ if (B(t.tabs), t.toggleEvent !== void 0 && (typeof t.toggleEvent != "string" || t.toggleEvent.length === 0))
501
518
  throw new Error(
502
519
  `[design-token-panel] PanelConfig.toggleEvent must be a non-empty string when set (got ${typeof t.toggleEvent})`
503
520
  );
@@ -508,8 +525,8 @@ function he(e) {
508
525
  if (t.applyRouting !== void 0) {
509
526
  if (t.applyRouting === null || typeof t.applyRouting != "object" || Array.isArray(t.applyRouting))
510
527
  throw new Error("[design-token-panel] PanelConfig.applyRouting must be a plain object");
511
- for (const [n, l] of Object.entries(t.applyRouting))
512
- if (typeof l != "string")
528
+ for (const [n, a] of Object.entries(t.applyRouting))
529
+ if (typeof a != "string")
513
530
  throw new Error(
514
531
  `[design-token-panel] PanelConfig.applyRouting[${JSON.stringify(n)}] must be a string`
515
532
  );
@@ -517,87 +534,106 @@ function he(e) {
517
534
  if (t.legacyIdRenameMap !== void 0) {
518
535
  if (t.legacyIdRenameMap === null || typeof t.legacyIdRenameMap != "object" || Array.isArray(t.legacyIdRenameMap))
519
536
  throw new Error("[design-token-panel] PanelConfig.legacyIdRenameMap must be a plain object");
520
- for (const [n, l] of Object.entries(t.legacyIdRenameMap))
521
- if (l !== null && typeof l != "string")
537
+ for (const [n, a] of Object.entries(t.legacyIdRenameMap))
538
+ if (a !== null && typeof a != "string")
522
539
  throw new Error(
523
- `[design-token-panel] PanelConfig.legacyIdRenameMap[${JSON.stringify(n)}] must be a string or null (got ${typeof l})`
540
+ `[design-token-panel] PanelConfig.legacyIdRenameMap[${JSON.stringify(n)}] must be a string or null (got ${typeof a})`
524
541
  );
525
542
  }
526
543
  }
527
- function J(e) {
544
+ function B(e) {
528
545
  if (!Array.isArray(e))
529
546
  throw new Error("[design-token-panel] PanelConfig.tabs must be an array");
530
547
  const t = /* @__PURE__ */ new Set();
531
548
  for (const n of e) {
532
549
  if (n === null || typeof n != "object" || Array.isArray(n))
533
550
  throw new Error("[design-token-panel] PanelConfig.tabs: each tab must be a non-null object");
534
- const l = n;
535
- if (typeof l.id != "string" || l.id.length === 0)
551
+ const a = n;
552
+ if (typeof a.id != "string" || a.id.length === 0)
536
553
  throw new Error("[design-token-panel] PanelConfig.tabs: each tab must have a non-empty string id");
537
- if (t.has(l.id))
554
+ if (t.has(a.id))
538
555
  throw new Error(
539
- `[design-token-panel] PanelConfig.tabs: duplicate tab id "${l.id}"`
556
+ `[design-token-panel] PanelConfig.tabs: duplicate tab id "${a.id}"`
540
557
  );
541
- t.add(l.id), B(l.id, l, e);
558
+ t.add(a.id), U(a.id, a, e);
559
+ }
560
+ }
561
+ function G(e) {
562
+ if (typeof e == "number" || e === "bg" || e === "fg") return !0;
563
+ if (e === null || typeof e != "object" || Array.isArray(e)) return !1;
564
+ const t = e;
565
+ if ("literal" in t) {
566
+ const n = t.literal;
567
+ if (typeof n == "string") return !0;
568
+ if (n === null || typeof n != "object" || Array.isArray(n)) return !1;
569
+ const a = n;
570
+ return typeof a.light == "string" && typeof a.dark == "string";
571
+ }
572
+ if ("ref" in t) {
573
+ const n = t.ref;
574
+ if (n === null || typeof n != "object" || Array.isArray(n)) return !1;
575
+ const a = n;
576
+ return !(typeof a.tier != "string" || typeof a.item != "string" || a.tab !== void 0 && typeof a.tab != "string");
542
577
  }
578
+ return !1;
543
579
  }
544
- function B(e, t, n) {
580
+ function U(e, t, n) {
545
581
  if (!Array.isArray(t.tiers))
546
582
  throw new Error(
547
583
  `[design-token-panel] PanelConfig.tabs["${e}"].tiers must be an array`
548
584
  );
549
- const l = /* @__PURE__ */ new Set(), g = /* @__PURE__ */ new Map();
550
- for (const s of t.tiers) {
551
- if (s === null || typeof s != "object" || Array.isArray(s))
585
+ const a = /* @__PURE__ */ new Set(), g = /* @__PURE__ */ new Map();
586
+ for (const i of t.tiers) {
587
+ if (i === null || typeof i != "object" || Array.isArray(i))
552
588
  throw new Error(
553
589
  `[design-token-panel] PanelConfig.tabs["${e}"].tiers: each tier must be a non-null object`
554
590
  );
555
- const i = s;
556
- if (typeof i.id != "string" || i.id.length === 0)
591
+ const s = i;
592
+ if (typeof s.id != "string" || s.id.length === 0)
557
593
  throw new Error(
558
594
  `[design-token-panel] PanelConfig.tabs["${e}"].tiers: each tier must have a non-empty string id`
559
595
  );
560
- if (l.has(i.id))
596
+ if (a.has(s.id))
561
597
  throw new Error(
562
- `[design-token-panel] PanelConfig.tabs["${e}"]: duplicate tier id "${i.id}"`
598
+ `[design-token-panel] PanelConfig.tabs["${e}"]: duplicate tier id "${s.id}"`
563
599
  );
564
- if (l.add(i.id), i.semantic !== void 0 && i.semantic !== !0)
600
+ if (a.add(s.id), s.semantic !== void 0 && s.semantic !== !0)
565
601
  throw new Error(
566
- `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${i.id}"].semantic must be exactly \`true\` when present (got ${JSON.stringify(i.semantic)})`
602
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${s.id}"].semantic must be exactly \`true\` when present (got ${JSON.stringify(s.semantic)})`
567
603
  );
568
- if (!Array.isArray(i.items))
604
+ if (!Array.isArray(s.items))
569
605
  throw new Error(
570
- `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${i.id}"].items must be an array`
606
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${s.id}"].items must be an array`
571
607
  );
572
- let a;
573
- for (const f of i.items) {
608
+ let l;
609
+ for (const f of s.items) {
574
610
  if (f === null || typeof f != "object" || Array.isArray(f)) continue;
575
611
  const o = f.type;
576
612
  if (o === null || typeof o != "object" || Array.isArray(o)) continue;
577
- const d = o.kind;
578
- if (typeof d == "string") {
579
- if (a === void 0)
580
- a = d;
581
- else if (a !== d)
613
+ const u = o.kind;
614
+ if (typeof u == "string") {
615
+ if (l === void 0)
616
+ l = u;
617
+ else if (l !== u)
582
618
  throw new Error(
583
- `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${i.id}"]: mixed item kinds — found "${a}" and "${d}" in the same tier (all items must share the same kind)`
619
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${s.id}"]: mixed item kinds — found "${l}" and "${u}" in the same tier (all items must share the same kind)`
584
620
  );
585
621
  }
586
622
  }
587
- a !== void 0 && g.set(i.id, a);
623
+ l !== void 0 && g.set(s.id, l);
588
624
  }
589
625
  const c = /* @__PURE__ */ new Set();
590
- for (const s of t.tiers) {
591
- const i = s, a = i.id;
592
- for (const f of i.items) {
626
+ for (const i of t.tiers) {
627
+ const s = i, l = s.id;
628
+ for (const f of s.items) {
593
629
  if (f === null || typeof f != "object" || Array.isArray(f))
594
630
  throw new Error(
595
- `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${a}"].items: each item must be a non-null object`
631
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${l}"].items: each item must be a non-null object`
596
632
  );
597
633
  const r = f;
598
634
  if (typeof r.id != "string" || r.id.length === 0)
599
635
  throw new Error(
600
- `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${a}"].items: each item must have a non-empty string id`
636
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${l}"].items: each item must have a non-empty string id`
601
637
  );
602
638
  if (c.has(r.id))
603
639
  throw new Error(
@@ -605,61 +641,61 @@ function B(e, t, n) {
605
641
  );
606
642
  if (c.add(r.id), typeof r.cssVar != "string" || !r.cssVar.startsWith("--"))
607
643
  throw new Error(
608
- `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${a}"].items["${r.id}"].cssVar must start with "--" (got ${JSON.stringify(r.cssVar)})`
644
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${l}"].items["${r.id}"].cssVar must start with "--" (got ${JSON.stringify(r.cssVar)})`
609
645
  );
610
646
  if (r.cssVar.length <= 2)
611
647
  throw new Error(
612
- `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${a}"].items["${r.id}"].cssVar must be non-empty after "--"`
648
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${l}"].items["${r.id}"].cssVar must be non-empty after "--"`
613
649
  );
614
650
  }
615
651
  }
616
- for (const s of t.tiers) {
617
- const i = s, a = i.id;
618
- if (i.referencesTier !== void 0) {
619
- if (typeof i.referencesTier != "string")
652
+ for (const i of t.tiers) {
653
+ const s = i, l = s.id;
654
+ if (s.referencesTier !== void 0) {
655
+ if (typeof s.referencesTier != "string")
620
656
  throw new Error(
621
- `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${a}"].referencesTier must be a string`
657
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${l}"].referencesTier must be a string`
622
658
  );
623
- const f = i.referencesTier;
624
- if (!l.has(f))
659
+ const f = s.referencesTier;
660
+ if (!a.has(f))
625
661
  throw new Error(
626
- `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${a}"].referencesTier: tier "${f}" does not exist in this tab`
662
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${l}"].referencesTier: tier "${f}" does not exist in this tab`
627
663
  );
628
- const r = g.get(a), o = g.get(f);
664
+ const r = g.get(l), o = g.get(f);
629
665
  if (r !== void 0 && o !== void 0 && r !== "text" && r !== o)
630
666
  throw new Error(
631
- `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${a}"].referencesTier: referencing tier has kind "${r}" but referenced tier "${f}" has kind "${o}" (cross-kind reference is only allowed when the referencing tier has kind "text")`
667
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${l}"].referencesTier: referencing tier has kind "${r}" but referenced tier "${f}" has kind "${o}" (cross-kind reference is only allowed when the referencing tier has kind "text")`
632
668
  );
633
669
  }
634
670
  }
635
- for (const s of t.tiers) {
636
- const i = s, a = i.id;
637
- if (i.referencesRamps === void 0) continue;
638
- if (i.semantic !== !0)
671
+ for (const i of t.tiers) {
672
+ const s = i, l = s.id;
673
+ if (s.referencesRamps === void 0) continue;
674
+ if (s.semantic !== !0)
639
675
  throw new Error(
640
- `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${a}"].referencesRamps is only valid on a tier with semantic: true`
676
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${l}"].referencesRamps is only valid on a tier with semantic: true`
641
677
  );
642
- if (!Array.isArray(i.referencesRamps))
678
+ if (!Array.isArray(s.referencesRamps))
643
679
  throw new Error(
644
- `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${a}"].referencesRamps must be an array`
680
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${l}"].referencesRamps must be an array`
645
681
  );
646
- const f = g.get(a), r = i.referencesRamps;
682
+ const f = g.get(l), r = s.referencesRamps;
647
683
  for (let o = 0; o < r.length; o++) {
648
- const d = r[o];
649
- if (d === null || typeof d != "object" || Array.isArray(d))
684
+ const u = r[o];
685
+ if (u === null || typeof u != "object" || Array.isArray(u))
650
686
  throw new Error(
651
- `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${a}"].referencesRamps[${o}] must be a non-null object`
687
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${l}"].referencesRamps[${o}] must be a non-null object`
652
688
  );
653
- const u = d;
654
- if (typeof u.tier != "string" || u.tier.length === 0)
689
+ const d = u;
690
+ if (typeof d.tier != "string" || d.tier.length === 0)
655
691
  throw new Error(
656
- `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${a}"].referencesRamps[${o}].tier must be a non-empty string`
692
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${l}"].referencesRamps[${o}].tier must be a non-empty string`
657
693
  );
658
- if (u.tab !== void 0 && (typeof u.tab != "string" || u.tab.length === 0))
694
+ if (d.tab !== void 0 && (typeof d.tab != "string" || d.tab.length === 0))
659
695
  throw new Error(
660
- `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${a}"].referencesRamps[${o}].tab must be a non-empty string when set`
696
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${l}"].referencesRamps[${o}].tab must be a non-empty string when set`
661
697
  );
662
- const m = u.tab === void 0 ? e : u.tab;
698
+ const m = d.tab === void 0 ? e : d.tab;
663
699
  let k;
664
700
  if (m === e)
665
701
  k = t;
@@ -670,30 +706,30 @@ function B(e, t, n) {
670
706
  if (!b) {
671
707
  const p = n.filter((h) => h !== null && typeof h == "object" && !Array.isArray(h)).map((h) => h.id).join(", ");
672
708
  throw new Error(
673
- `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${a}"].referencesRamps[${o}]: tab "${m}" does not exist. Available tabs: ${p}.`
709
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${l}"].referencesRamps[${o}]: tab "${m}" does not exist. Available tabs: ${p}.`
674
710
  );
675
711
  }
676
712
  k = b;
677
713
  }
678
- const P = Array.isArray(k.tiers) ? k.tiers : [], S = [];
679
- let C;
680
- for (const b of P) {
714
+ const C = Array.isArray(k.tiers) ? k.tiers : [], j = [];
715
+ let P;
716
+ for (const b of C) {
681
717
  if (b === null || typeof b != "object" || Array.isArray(b)) continue;
682
718
  const p = b;
683
- typeof p.id == "string" && (S.push(p.id), p.id === u.tier && (C = p));
719
+ typeof p.id == "string" && (j.push(p.id), p.id === d.tier && (P = p));
684
720
  }
685
- if (!C)
721
+ if (!P)
686
722
  throw new Error(
687
- `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${a}"].referencesRamps[${o}]: tier "${u.tier}" does not exist in tab "${m}". Available tiers: ${S.join(", ")}.`
723
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${l}"].referencesRamps[${o}]: tier "${d.tier}" does not exist in tab "${m}". Available tiers: ${j.join(", ")}.`
688
724
  );
689
725
  if (f !== void 0) {
690
- const b = Array.isArray(C.items) ? C.items : [];
726
+ const b = Array.isArray(P.items) ? P.items : [];
691
727
  let p;
692
728
  for (const h of b) {
693
729
  if (h === null || typeof h != "object" || Array.isArray(h)) continue;
694
- const v = h.type;
695
- if (v === null || typeof v != "object" || Array.isArray(v)) continue;
696
- const T = v.kind;
730
+ const E = h.type;
731
+ if (E === null || typeof E != "object" || Array.isArray(E)) continue;
732
+ const T = E.kind;
697
733
  if (typeof T == "string") {
698
734
  p = T;
699
735
  break;
@@ -701,42 +737,42 @@ function B(e, t, n) {
701
737
  }
702
738
  if (p !== void 0 && f !== p)
703
739
  throw new Error(
704
- `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${a}"].referencesRamps[${o}]: referencing semantic tier has kind "${f}" but target tier "${u.tier}" in tab "${m}" has kind "${p}" (cross-tab ramp sources must share the semantic tier's kind)`
740
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${l}"].referencesRamps[${o}]: referencing semantic tier has kind "${f}" but target tier "${d.tier}" in tab "${m}" has kind "${p}" (cross-tab ramp sources must share the semantic tier's kind)`
705
741
  );
706
742
  }
707
743
  }
708
744
  }
709
745
  if (t.colorExtras !== void 0) {
710
- const s = t.colorExtras;
711
- if (s === null || typeof s != "object" || Array.isArray(s))
746
+ const i = t.colorExtras;
747
+ if (i === null || typeof i != "object" || Array.isArray(i))
712
748
  throw new Error(
713
749
  `[design-token-panel] PanelConfig.tabs["${e}"].colorExtras must be a plain object`
714
750
  );
715
751
  for (const r of ["id", "defaultShikiTheme"])
716
- if (typeof s[r] != "string" || s[r].length === 0)
752
+ if (typeof i[r] != "string" || i[r].length === 0)
717
753
  throw new Error(
718
- `[design-token-panel] PanelConfig.tabs["${e}"].colorExtras.${r} must be a non-empty string (got ${typeof s[r]})`
754
+ `[design-token-panel] PanelConfig.tabs["${e}"].colorExtras.${r} must be a non-empty string (got ${typeof i[r]})`
719
755
  );
720
756
  for (const r of ["colorSchemes", "baseRoles", "baseDefaults"])
721
- if (s[r] === void 0 || s[r] === null || typeof s[r] != "object" || Array.isArray(s[r]))
757
+ if (i[r] === void 0 || i[r] === null || typeof i[r] != "object" || Array.isArray(i[r]))
722
758
  throw new Error(
723
759
  `[design-token-panel] PanelConfig.tabs["${e}"].colorExtras.${r} must be a plain object`
724
760
  );
725
- if (s.panelSettings === void 0 || s.panelSettings === null || typeof s.panelSettings != "object" || Array.isArray(s.panelSettings))
761
+ if (i.panelSettings === void 0 || i.panelSettings === null || typeof i.panelSettings != "object" || Array.isArray(i.panelSettings))
726
762
  throw new Error(
727
763
  `[design-token-panel] PanelConfig.tabs["${e}"].colorExtras.panelSettings must be a plain object`
728
764
  );
729
- const i = s.panelSettings;
730
- if (typeof i.colorScheme != "string" || i.colorScheme.length === 0)
765
+ const s = i.panelSettings;
766
+ if (typeof s.colorScheme != "string" || s.colorScheme.length === 0)
731
767
  throw new Error(
732
768
  `[design-token-panel] PanelConfig.tabs["${e}"].colorExtras.panelSettings.colorScheme must be a non-empty string`
733
769
  );
734
- if (i.colorMode !== !1) {
735
- if (i.colorMode === null || typeof i.colorMode != "object" || Array.isArray(i.colorMode))
770
+ if (s.colorMode !== !1) {
771
+ if (s.colorMode === null || typeof s.colorMode != "object" || Array.isArray(s.colorMode))
736
772
  throw new Error(
737
773
  `[design-token-panel] PanelConfig.tabs["${e}"].colorExtras.panelSettings.colorMode must be false or a plain object`
738
774
  );
739
- const r = i.colorMode;
775
+ const r = s.colorMode;
740
776
  for (const o of ["lightScheme", "darkScheme"])
741
777
  if (typeof r[o] != "string" || r[o].length === 0)
742
778
  throw new Error(
@@ -747,39 +783,51 @@ function B(e, t, n) {
747
783
  `[design-token-panel] PanelConfig.tabs["${e}"].colorExtras.panelSettings.colorMode.defaultMode must be "light" or "dark" (got ${JSON.stringify(r.defaultMode)})`
748
784
  );
749
785
  }
786
+ if (i.semanticDefaults !== void 0) {
787
+ if (i.semanticDefaults === null || typeof i.semanticDefaults != "object" || Array.isArray(i.semanticDefaults))
788
+ throw new Error(
789
+ `[design-token-panel] PanelConfig.tabs["${e}"].colorExtras.semanticDefaults must be a plain object`
790
+ );
791
+ const r = i.semanticDefaults;
792
+ for (const [o, u] of Object.entries(r))
793
+ if (!G(u))
794
+ throw new Error(
795
+ `[design-token-panel] PanelConfig.tabs["${e}"].colorExtras.semanticDefaults["${o}"] must be a valid SemanticValue (number | 'bg' | 'fg' | { literal: string } | { literal: { light, dark } } | { ref: { tier, item, tab? } }), got ${JSON.stringify(u)}`
796
+ );
797
+ }
750
798
  const f = t.tiers.find((r) => {
751
799
  if (r.referencesTier !== void 0 || r.semantic === !0) return !1;
752
800
  const o = r.items;
753
801
  if (!Array.isArray(o) || o.length === 0) return !1;
754
- const d = o[0];
755
- if (d === null || typeof d != "object" || Array.isArray(d)) return !1;
756
- const u = d.type;
757
- return u === null || typeof u != "object" || Array.isArray(u) ? !1 : u.kind === "color";
802
+ const u = o[0];
803
+ if (u === null || typeof u != "object" || Array.isArray(u)) return !1;
804
+ const d = u.type;
805
+ return d === null || typeof d != "object" || Array.isArray(d) ? !1 : d.kind === "color";
758
806
  });
759
807
  if (f) {
760
- const r = f.id, o = f.items, d = o[0]?.cssVar;
761
- if (d !== void 0) {
762
- const u = d.replace(/\d+$/, "{n}");
763
- if (u.includes("{n}"))
808
+ const r = f.id, o = f.items, u = o[0]?.cssVar;
809
+ if (u !== void 0) {
810
+ const d = u.replace(/\d+$/, "{n}");
811
+ if (d.includes("{n}"))
764
812
  for (let m = 0; m < o.length; m++) {
765
- const k = o[m], P = u.replace("{n}", String(m));
766
- if (k.cssVar !== P)
813
+ const k = o[m], C = d.replace("{n}", String(m));
814
+ if (k.cssVar !== C)
767
815
  throw new Error(
768
- `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${r}"].items[${m}].cssVar is ${JSON.stringify(k.cssVar)} but expected ${JSON.stringify(P)} — palette item cssVars must share one prefix and be numbered 0..n-1 in tier order (template derived from first item: ${JSON.stringify(u)})`
816
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${r}"].items[${m}].cssVar is ${JSON.stringify(k.cssVar)} but expected ${JSON.stringify(C)} — palette item cssVars must share one prefix and be numbered 0..n-1 in tier order (template derived from first item: ${JSON.stringify(d)})`
769
817
  );
770
818
  }
771
819
  else if (o.length > 1)
772
820
  throw new Error(
773
- `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${r}"].items[0].cssVar ${JSON.stringify(d)} has no trailing digit — palette item cssVars must share one prefix and be numbered 0..n-1 in tier order (e.g. "--pal-0" … "--pal-15")`
821
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${r}"].items[0].cssVar ${JSON.stringify(u)} has no trailing digit — palette item cssVars must share one prefix and be numbered 0..n-1 in tier order (e.g. "--pal-0" … "--pal-15")`
774
822
  );
775
823
  }
776
824
  }
777
825
  }
778
826
  }
779
- function be(e = O()) {
827
+ function Ee(e = _()) {
780
828
  return e.applyRouting ?? {};
781
829
  }
782
- function we(e) {
830
+ function ve(e) {
783
831
  const t = x();
784
832
  if (t === null) {
785
833
  y().pendingColorPresets = e;
@@ -788,37 +836,41 @@ function we(e) {
788
836
  t.config = { ...t.config, colorPresets: e };
789
837
  }
790
838
  export {
791
- ee as A,
792
- de as B,
793
- Y as C,
794
- q as D,
795
- le as E,
796
- fe as F,
797
- te as _,
798
- ce as a,
799
- re as b,
800
- X as c,
801
- ie as d,
802
- he as e,
803
- se as f,
804
- O as g,
805
- ae as h,
806
- oe as i,
839
+ te as A,
840
+ ne as B,
841
+ be as C,
842
+ L as D,
843
+ X as E,
844
+ oe as F,
845
+ pe as G,
846
+ ye as H,
847
+ ie as I,
848
+ se as J,
849
+ re as _,
850
+ me as a,
851
+ le as b,
852
+ Z as c,
853
+ fe as d,
854
+ ce as e,
855
+ Pe as f,
856
+ _ as g,
857
+ ue as h,
858
+ de as i,
807
859
  ge as j,
808
- A as k,
809
- _ as l,
810
- me as m,
811
- ye as n,
812
- G as o,
813
- U as p,
814
- ne as q,
815
- W as r,
816
- we as s,
817
- be as t,
818
- R as u,
819
- pe as v,
820
- I as w,
860
+ he as k,
861
+ S as l,
862
+ D as m,
863
+ Ce as n,
864
+ $e as o,
865
+ W as p,
866
+ Y as q,
867
+ I as r,
868
+ ve as s,
869
+ ae as t,
870
+ Ee as u,
871
+ V as v,
872
+ ke as w,
821
873
  Q as x,
822
- ue as y,
823
- Z as z
874
+ ee as y,
875
+ we as z
824
876
  };