@takazudo/zdtp 0.4.2 → 0.4.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 (173) hide show
  1. package/CHANGELOG.md +78 -0
  2. package/README.md +20 -15
  3. package/dist/apply/apply-token-overrides.d.ts +0 -1
  4. package/dist/apply/build-apply-overrides.d.ts +20 -5
  5. package/dist/apply/route-tokens-to-files.d.ts +0 -1
  6. package/dist/apply/tier-resolver.d.ts +28 -1
  7. package/dist/apply-modal.d.ts +0 -1
  8. package/dist/astro/DesignTokenPanelHost.astro +2 -4
  9. package/dist/astro/host-adapter.d.ts +0 -1
  10. package/dist/astro/host-adapter.js +16 -16
  11. package/dist/astro/index.d.ts +0 -1
  12. package/dist/astro/index.js +1 -1
  13. package/dist/{autoload-state-DsvvPDih.js → autoload-state-CmhI7q9j.js} +1 -1
  14. package/dist/bin/cors.d.ts +0 -1
  15. package/dist/bin/parse-args.d.ts +0 -1
  16. package/dist/bin/server.d.ts +0 -1
  17. package/dist/bin/server.js +1 -1
  18. package/dist/components/color-picker/color-field.d.ts +0 -1
  19. package/dist/components/color-picker/color-picker.d.ts +12 -3
  20. package/dist/components/color-picker/custom-slider.d.ts +0 -1
  21. package/dist/components/color-picker/index.d.ts +0 -1
  22. package/dist/components/palette-chart/index.d.ts +0 -1
  23. package/dist/components/palette-chart/palette-chart.d.ts +0 -1
  24. package/dist/config/cluster-config.d.ts +36 -14
  25. package/dist/config/color-scheme-utils.d.ts +0 -1
  26. package/dist/config/color-schemes.d.ts +0 -1
  27. package/dist/config/panel-config.d.ts +11 -1
  28. package/dist/controls/dismiss-layer.d.ts +55 -0
  29. package/dist/controls/pill-slider-row.d.ts +0 -1
  30. package/dist/controls/role-button.d.ts +0 -1
  31. package/dist/controls/sanitize-css-value.d.ts +0 -1
  32. package/dist/controls/select-row.d.ts +0 -1
  33. package/dist/controls/slider-row.d.ts +0 -1
  34. package/dist/controls/text-row.d.ts +0 -1
  35. package/dist/controls/tier-ref-selector.d.ts +65 -22
  36. package/dist/controls/token-label.d.ts +0 -1
  37. package/dist/controls/tooltip.d.ts +0 -1
  38. package/dist/controls/use-dialog-backdrop-close.d.ts +32 -0
  39. package/dist/element-path/build-element-path.d.ts +0 -1
  40. package/dist/element-path/element-path-context.d.ts +0 -1
  41. package/dist/element-path/element-path-orchestrator.d.ts +0 -1
  42. package/dist/element-path/element-path-state.d.ts +0 -1
  43. package/dist/element-path/element-path-toast.d.ts +0 -1
  44. package/dist/element-path/element-path-toggle-button.d.ts +0 -1
  45. package/dist/element-path/index.d.ts +0 -1
  46. package/dist/element-path/inspector-overlay.d.ts +0 -1
  47. package/dist/export-modal.d.ts +0 -1
  48. package/dist/highlight/find-elements.d.ts +0 -1
  49. package/dist/highlight/highlight-orchestrator.d.ts +0 -1
  50. package/dist/highlight/highlight-overlay.d.ts +0 -1
  51. package/dist/highlight/highlight-settings-popover.d.ts +0 -1
  52. package/dist/highlight/highlight-state.d.ts +0 -1
  53. package/dist/highlight/highlight-toggle-button.d.ts +0 -1
  54. package/dist/import-modal.d.ts +0 -1
  55. package/dist/index.d.ts +1 -1
  56. package/dist/index.js +3432 -2717
  57. package/dist/{load-routing-XyKgftpe.js → load-routing-DtNTKoLW.js} +1 -1
  58. package/dist/panel-config-CXTCcYQs.js +824 -0
  59. package/dist/panel.d.ts +0 -1
  60. package/dist/server/create-apply-handler.d.ts +0 -1
  61. package/dist/server/index.d.ts +0 -1
  62. package/dist/server/index.js +1 -1
  63. package/dist/server/load-routing.d.ts +0 -1
  64. package/dist/server/path-safety.d.ts +0 -1
  65. package/dist/server/serialize-write.d.ts +0 -1
  66. package/dist/state/autoload-state.d.ts +0 -1
  67. package/dist/state/persist.d.ts +7 -3
  68. package/dist/state/tweak-state.d.ts +146 -10
  69. package/dist/styles/z-index-tokens.d.ts +35 -0
  70. package/dist/tabs/_generic-item-editor.d.ts +0 -1
  71. package/dist/tabs/color-tab.d.ts +13 -2
  72. package/dist/tabs/font-tab.d.ts +0 -1
  73. package/dist/tabs/generic-tab.d.ts +4 -3
  74. package/dist/tabs/palette/palette-check-view.d.ts +0 -1
  75. package/dist/tabs/palette/palette-edit-view.d.ts +0 -1
  76. package/dist/tabs/palette/palette-readout.d.ts +0 -1
  77. package/dist/tabs/palette/palette-tab.d.ts +0 -1
  78. package/dist/tabs/size-tab.d.ts +0 -1
  79. package/dist/tabs/spacing-tab.d.ts +0 -1
  80. package/dist/testing.d.ts +0 -1
  81. package/dist/testing.js +2 -2
  82. package/dist/tokens/manifest.d.ts +0 -1
  83. package/dist/tokens/tier-model.d.ts +50 -1
  84. package/dist/{tweak-state-DzZVbY25.js → tweak-state-BeXkzoj8.js} +662 -583
  85. package/dist/utils/color-convert.d.ts +0 -1
  86. package/dist/utils/color-hsla.d.ts +0 -1
  87. package/dist/utils/color-oklch.d.ts +0 -1
  88. package/dist/utils/copy-to-clipboard.d.ts +0 -1
  89. package/dist/utils/design-token-serde.d.ts +78 -11
  90. package/dist/utils/palette-curve.d.ts +0 -1
  91. package/dist/utils/structural-equal.d.ts +0 -1
  92. package/dist/utils/use-portal-mount.d.ts +0 -1
  93. package/dist/utils/wcag-contrast.d.ts +0 -1
  94. package/dist/zdtp.css +1 -1
  95. package/package.json +24 -11
  96. package/dist/apply/apply-token-overrides.d.ts.map +0 -1
  97. package/dist/apply/build-apply-overrides.d.ts.map +0 -1
  98. package/dist/apply/route-tokens-to-files.d.ts.map +0 -1
  99. package/dist/apply/tier-resolver.d.ts.map +0 -1
  100. package/dist/apply-modal.d.ts.map +0 -1
  101. package/dist/astro/host-adapter.d.ts.map +0 -1
  102. package/dist/astro/index.d.ts.map +0 -1
  103. package/dist/bin/cors.d.ts.map +0 -1
  104. package/dist/bin/parse-args.d.ts.map +0 -1
  105. package/dist/bin/server.d.ts.map +0 -1
  106. package/dist/components/color-picker/color-field.d.ts.map +0 -1
  107. package/dist/components/color-picker/color-picker.d.ts.map +0 -1
  108. package/dist/components/color-picker/custom-slider.d.ts.map +0 -1
  109. package/dist/components/color-picker/index.d.ts.map +0 -1
  110. package/dist/components/palette-chart/index.d.ts.map +0 -1
  111. package/dist/components/palette-chart/palette-chart.d.ts.map +0 -1
  112. package/dist/config/cluster-config.d.ts.map +0 -1
  113. package/dist/config/color-scheme-utils.d.ts.map +0 -1
  114. package/dist/config/color-schemes.d.ts.map +0 -1
  115. package/dist/config/panel-config.d.ts.map +0 -1
  116. package/dist/controls/pill-slider-row.d.ts.map +0 -1
  117. package/dist/controls/role-button.d.ts.map +0 -1
  118. package/dist/controls/sanitize-css-value.d.ts.map +0 -1
  119. package/dist/controls/select-row.d.ts.map +0 -1
  120. package/dist/controls/slider-row.d.ts.map +0 -1
  121. package/dist/controls/text-row.d.ts.map +0 -1
  122. package/dist/controls/tier-ref-selector.d.ts.map +0 -1
  123. package/dist/controls/token-label.d.ts.map +0 -1
  124. package/dist/controls/tooltip.d.ts.map +0 -1
  125. package/dist/element-path/build-element-path.d.ts.map +0 -1
  126. package/dist/element-path/element-path-context.d.ts.map +0 -1
  127. package/dist/element-path/element-path-orchestrator.d.ts.map +0 -1
  128. package/dist/element-path/element-path-state.d.ts.map +0 -1
  129. package/dist/element-path/element-path-toast.d.ts.map +0 -1
  130. package/dist/element-path/element-path-toggle-button.d.ts.map +0 -1
  131. package/dist/element-path/index.d.ts.map +0 -1
  132. package/dist/element-path/inspector-overlay.d.ts.map +0 -1
  133. package/dist/export-modal.d.ts.map +0 -1
  134. package/dist/highlight/find-elements.d.ts.map +0 -1
  135. package/dist/highlight/highlight-orchestrator.d.ts.map +0 -1
  136. package/dist/highlight/highlight-overlay.d.ts.map +0 -1
  137. package/dist/highlight/highlight-settings-popover.d.ts.map +0 -1
  138. package/dist/highlight/highlight-state.d.ts.map +0 -1
  139. package/dist/highlight/highlight-toggle-button.d.ts.map +0 -1
  140. package/dist/import-modal.d.ts.map +0 -1
  141. package/dist/index.d.ts.map +0 -1
  142. package/dist/panel-config-DyVRQ2n1.js +0 -415
  143. package/dist/panel.d.ts.map +0 -1
  144. package/dist/server/create-apply-handler.d.ts.map +0 -1
  145. package/dist/server/index.d.ts.map +0 -1
  146. package/dist/server/load-routing.d.ts.map +0 -1
  147. package/dist/server/path-safety.d.ts.map +0 -1
  148. package/dist/server/serialize-write.d.ts.map +0 -1
  149. package/dist/state/autoload-state.d.ts.map +0 -1
  150. package/dist/state/persist.d.ts.map +0 -1
  151. package/dist/state/tweak-state.d.ts.map +0 -1
  152. package/dist/tabs/_generic-item-editor.d.ts.map +0 -1
  153. package/dist/tabs/color-tab.d.ts.map +0 -1
  154. package/dist/tabs/font-tab.d.ts.map +0 -1
  155. package/dist/tabs/generic-tab.d.ts.map +0 -1
  156. package/dist/tabs/palette/palette-check-view.d.ts.map +0 -1
  157. package/dist/tabs/palette/palette-edit-view.d.ts.map +0 -1
  158. package/dist/tabs/palette/palette-readout.d.ts.map +0 -1
  159. package/dist/tabs/palette/palette-tab.d.ts.map +0 -1
  160. package/dist/tabs/size-tab.d.ts.map +0 -1
  161. package/dist/tabs/spacing-tab.d.ts.map +0 -1
  162. package/dist/testing.d.ts.map +0 -1
  163. package/dist/tokens/manifest.d.ts.map +0 -1
  164. package/dist/tokens/tier-model.d.ts.map +0 -1
  165. package/dist/utils/color-convert.d.ts.map +0 -1
  166. package/dist/utils/color-hsla.d.ts.map +0 -1
  167. package/dist/utils/color-oklch.d.ts.map +0 -1
  168. package/dist/utils/copy-to-clipboard.d.ts.map +0 -1
  169. package/dist/utils/design-token-serde.d.ts.map +0 -1
  170. package/dist/utils/palette-curve.d.ts.map +0 -1
  171. package/dist/utils/structural-equal.d.ts.map +0 -1
  172. package/dist/utils/use-portal-mount.d.ts.map +0 -1
  173. package/dist/utils/wcag-contrast.d.ts.map +0 -1
@@ -0,0 +1,824 @@
1
+ class w extends Error {
2
+ constructor(t) {
3
+ super(t), this.name = "TierResolverError", Object.setPrototypeOf(this, w.prototype);
4
+ }
5
+ }
6
+ function E(e, t) {
7
+ return e.tiers.find((n) => n.id === t);
8
+ }
9
+ function $(e, t) {
10
+ return e.items.find((n) => n.id === t);
11
+ }
12
+ function G(e, t, n, l) {
13
+ const g = E(e, t);
14
+ if (!g)
15
+ throw new w(
16
+ `Tier "${t}" not found in tab "${e.id}". Available tiers: ${e.tiers.map((a) => a.id).join(", ")}.`
17
+ );
18
+ const c = $(g, n);
19
+ if (!c)
20
+ throw new w(
21
+ `Item "${n}" not found in tier "${t}" of tab "${e.id}".`
22
+ );
23
+ const i = l[t]?.[n];
24
+ if (g.referencesTier !== void 0) {
25
+ const a = g.referencesTier, f = E(e, a);
26
+ if (!f)
27
+ throw new w(
28
+ `Tier "${t}" declares referencesTier "${a}" but that tier does not exist in tab "${e.id}".`
29
+ );
30
+ const o = $(f, i ?? n);
31
+ if (!o) {
32
+ const d = $(f, c.default) ?? $(f, n) ?? f.items[0];
33
+ if (!d)
34
+ throw new w(
35
+ `Referenced tier "${a}" has no items; cannot resolve fallback for item "${n}" in tier "${t}" of tab "${e.id}".`
36
+ );
37
+ return { kind: "ref", targetCssVar: d.cssVar };
38
+ }
39
+ return { kind: "ref", targetCssVar: o.cssVar };
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 };
42
+ }
43
+ function U(e) {
44
+ return e.kind === "literal" ? e.value : `var(${e.targetCssVar})`;
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)
49
+ throw new w(
50
+ `Cross-tab ref target tab "${e.tab}" not found. Available tabs: ${n.map((s) => s.id).join(", ")}.`
51
+ );
52
+ const g = E(l, e.tier);
53
+ if (!g)
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(", ")}.`
56
+ );
57
+ const c = $(g, e.item);
58
+ if (!c)
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(", ")}.`
61
+ );
62
+ return c.cssVar;
63
+ }
64
+ function W(e, t) {
65
+ return e.paletteCssVarTemplate.replace("{n}", String(t));
66
+ }
67
+ const M = /* @__PURE__ */ new Set([
68
+ "aliceblue",
69
+ "antiquewhite",
70
+ "aqua",
71
+ "aquamarine",
72
+ "azure",
73
+ "beige",
74
+ "bisque",
75
+ "black",
76
+ "blanchedalmond",
77
+ "blue",
78
+ "blueviolet",
79
+ "brown",
80
+ "burlywood",
81
+ "cadetblue",
82
+ "chartreuse",
83
+ "chocolate",
84
+ "coral",
85
+ "cornflowerblue",
86
+ "cornsilk",
87
+ "crimson",
88
+ "cyan",
89
+ "darkblue",
90
+ "darkcyan",
91
+ "darkgoldenrod",
92
+ "darkgray",
93
+ "darkgreen",
94
+ "darkgrey",
95
+ "darkkhaki",
96
+ "darkmagenta",
97
+ "darkolivegreen",
98
+ "darkorange",
99
+ "darkorchid",
100
+ "darkred",
101
+ "darksalmon",
102
+ "darkseagreen",
103
+ "darkslateblue",
104
+ "darkslategray",
105
+ "darkslategrey",
106
+ "darkturquoise",
107
+ "darkviolet",
108
+ "deeppink",
109
+ "deepskyblue",
110
+ "dimgray",
111
+ "dimgrey",
112
+ "dodgerblue",
113
+ "firebrick",
114
+ "floralwhite",
115
+ "forestgreen",
116
+ "fuchsia",
117
+ "gainsboro",
118
+ "ghostwhite",
119
+ "gold",
120
+ "goldenrod",
121
+ "gray",
122
+ "green",
123
+ "greenyellow",
124
+ "grey",
125
+ "honeydew",
126
+ "hotpink",
127
+ "indianred",
128
+ "indigo",
129
+ "ivory",
130
+ "khaki",
131
+ "lavender",
132
+ "lavenderblush",
133
+ "lawngreen",
134
+ "lemonchiffon",
135
+ "lightblue",
136
+ "lightcoral",
137
+ "lightcyan",
138
+ "lightgoldenrodyellow",
139
+ "lightgray",
140
+ "lightgreen",
141
+ "lightgrey",
142
+ "lightpink",
143
+ "lightsalmon",
144
+ "lightseagreen",
145
+ "lightskyblue",
146
+ "lightslategray",
147
+ "lightslategrey",
148
+ "lightsteelblue",
149
+ "lightyellow",
150
+ "lime",
151
+ "limegreen",
152
+ "linen",
153
+ "magenta",
154
+ "maroon",
155
+ "mediumaquamarine",
156
+ "mediumblue",
157
+ "mediumorchid",
158
+ "mediumpurple",
159
+ "mediumseagreen",
160
+ "mediumslateblue",
161
+ "mediumspringgreen",
162
+ "mediumturquoise",
163
+ "mediumvioletred",
164
+ "midnightblue",
165
+ "mintcream",
166
+ "mistyrose",
167
+ "moccasin",
168
+ "navajowhite",
169
+ "navy",
170
+ "oldlace",
171
+ "olive",
172
+ "olivedrab",
173
+ "orange",
174
+ "orangered",
175
+ "orchid",
176
+ "palegoldenrod",
177
+ "palegreen",
178
+ "paleturquoise",
179
+ "palevioletred",
180
+ "papayawhip",
181
+ "peachpuff",
182
+ "peru",
183
+ "pink",
184
+ "plum",
185
+ "powderblue",
186
+ "purple",
187
+ "rebeccapurple",
188
+ "red",
189
+ "rosybrown",
190
+ "royalblue",
191
+ "saddlebrown",
192
+ "salmon",
193
+ "sandybrown",
194
+ "seagreen",
195
+ "seashell",
196
+ "sienna",
197
+ "silver",
198
+ "skyblue",
199
+ "slateblue",
200
+ "slategray",
201
+ "slategrey",
202
+ "snow",
203
+ "springgreen",
204
+ "steelblue",
205
+ "tan",
206
+ "teal",
207
+ "thistle",
208
+ "tomato",
209
+ "turquoise",
210
+ "violet",
211
+ "wheat",
212
+ "white",
213
+ "whitesmoke",
214
+ "yellow",
215
+ "yellowgreen",
216
+ "transparent",
217
+ "currentcolor",
218
+ "inherit",
219
+ "initial",
220
+ "unset",
221
+ "revert",
222
+ "revert-layer"
223
+ ]);
224
+ function H(e) {
225
+ return e.startsWith("#") || e.includes("(") || M.has(e.toLowerCase());
226
+ }
227
+ function N(e, t, n, l) {
228
+ const g = [], c = e.indexOf(":");
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 });
232
+ }
233
+ const [s] = t;
234
+ g.push({ tab: s.tab, tier: s.tier, item: e });
235
+ for (const i of g)
236
+ try {
237
+ return _(i, n, l), { ref: i };
238
+ } catch {
239
+ }
240
+ return { ref: g[0] };
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(
245
+ `[design-token-panel] semantic item "${e.id}" default "${e.default}" names no palette item; falling back to palette index 0`
246
+ ), 0) : { literal: e.default };
247
+ }
248
+ function R(e, t = [e]) {
249
+ const n = e.colorExtras;
250
+ if (!n) return;
251
+ const l = e.tiers.find(
252
+ (o) => !o.referencesTier && !o.semantic && o.items.length > 0 && o.items[0].type.kind === "color"
253
+ ), g = e.tiers.find(
254
+ (o) => l && o.referencesTier === l.id || o.semantic === !0
255
+ );
256
+ if (!l && !g)
257
+ return {
258
+ id: n.id,
259
+ label: n.label,
260
+ paletteSize: 0,
261
+ baseRoles: n.baseRoles,
262
+ paletteCssVarTemplate: "--zudo-stub-p{n}",
263
+ semanticDefaults: {},
264
+ semanticCssNames: {},
265
+ baseDefaults: n.baseDefaults,
266
+ defaultShikiTheme: n.defaultShikiTheme,
267
+ colorSchemes: n.colorSchemes,
268
+ panelSettings: n.panelSettings
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();
271
+ for (let o = 0; o < c.length; o++)
272
+ a.set(c[o].id, o);
273
+ const f = {}, r = {};
274
+ if (g) {
275
+ const o = !g.semantic;
276
+ for (const d of g.items)
277
+ r[d.id] = d.cssVar, f[d.id] = K(
278
+ d,
279
+ a,
280
+ g.referencesRamps,
281
+ e,
282
+ t,
283
+ o
284
+ );
285
+ }
286
+ return {
287
+ id: n.id,
288
+ label: n.label,
289
+ paletteSize: s,
290
+ baseRoles: n.baseRoles,
291
+ paletteCssVarTemplate: i,
292
+ semanticDefaults: f,
293
+ semanticCssNames: r,
294
+ baseDefaults: n.baseDefaults,
295
+ defaultShikiTheme: n.defaultShikiTheme,
296
+ colorSchemes: n.colorSchemes,
297
+ panelSettings: n.panelSettings
298
+ };
299
+ }
300
+ function Y(e) {
301
+ const t = e.find((n) => n.id === "color");
302
+ if (t)
303
+ return R(t, e);
304
+ }
305
+ function z(e) {
306
+ const t = e.find((n) => n.id === "color-secondary");
307
+ return t ? R(t, e) ?? null : null;
308
+ }
309
+ function A(e, t) {
310
+ if (Object.is(e, t)) return !0;
311
+ if (e === null || t === null || typeof e != typeof t || typeof e != "object") return !1;
312
+ if (Array.isArray(e)) {
313
+ if (!Array.isArray(t) || e.length !== t.length) return !1;
314
+ for (let c = 0; c < e.length; c++)
315
+ if (!A(e[c], t[c])) return !1;
316
+ return !0;
317
+ }
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);
322
+ for (const c of n)
323
+ if (!g.has(c) || !A(e[c], t[c]))
324
+ return !1;
325
+ return !0;
326
+ }
327
+ const V = {
328
+ storagePrefix: "zudo-design-token-panel",
329
+ consoleNamespace: "zudo",
330
+ modalClassPrefix: "zudo-design-token-panel-modal",
331
+ schemaId: "zudo-design-tokens/v1",
332
+ exportFilenameBase: "zudo-design-tokens",
333
+ // Empty tab list — hosts MUST configure real tabs via configurePanel().
334
+ tabs: [],
335
+ colorPresets: {},
336
+ // No bundled apply endpoint / routing — hosts wire their own.
337
+ applyEndpoint: void 0,
338
+ applyRouting: void 0
339
+ }, j = /* @__PURE__ */ Symbol.for("@takazudo/zdtp:singleton");
340
+ function y() {
341
+ const e = globalThis;
342
+ let t = e[j];
343
+ return t || (t = {
344
+ instances: /* @__PURE__ */ new Map(),
345
+ defaultPrefix: null,
346
+ pendingColorPresets: null,
347
+ pendingPostConfigureHooks: [],
348
+ lifecycleHooks: {}
349
+ }, e[j] = t), t;
350
+ }
351
+ function D(e) {
352
+ return {
353
+ instanceId: e,
354
+ open() {
355
+ y().lifecycleHooks.open?.(e);
356
+ },
357
+ close() {
358
+ y().lifecycleHooks.close?.(e);
359
+ },
360
+ toggle() {
361
+ y().lifecycleHooks.toggle?.(e);
362
+ },
363
+ destroy() {
364
+ y().lifecycleHooks.destroy?.(e);
365
+ const t = y();
366
+ if (t.instances.delete(e), t.defaultPrefix === e) {
367
+ const n = [...t.instances.keys()];
368
+ t.defaultPrefix = n.length > 0 ? n[n.length - 1] : null;
369
+ }
370
+ }
371
+ };
372
+ }
373
+ function I(e) {
374
+ y().lifecycleHooks = {
375
+ configured: e.configured,
376
+ open: e.open,
377
+ close: e.close,
378
+ toggle: e.toggle,
379
+ destroy: e.destroy
380
+ };
381
+ }
382
+ function X(e) {
383
+ const t = y(), n = e.storagePrefix, l = t.instances.get(n);
384
+ if (l) {
385
+ const f = (r) => ({ ...r, applySink: void 0 });
386
+ if (A(f(l.suppliedConfig), f(e)))
387
+ return t.defaultPrefix = n, l.handle;
388
+ throw new Error(
389
+ `[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
+ }
392
+ const g = t.pendingColorPresets, c = g ? { ...e, colorPresets: g } : { ...e };
393
+ t.pendingColorPresets = null;
394
+ const s = t.instances.size === 0, i = s ? [...t.pendingPostConfigureHooks] : [];
395
+ s && (t.pendingPostConfigureHooks.length = 0);
396
+ const a = {
397
+ config: c,
398
+ // Snapshot the as-supplied config before any runtime merges. Used by the
399
+ // idempotency guard so view-transition re-calls with the original inline
400
+ // config keep passing even after setPanelColorPresets mutates `config`.
401
+ suppliedConfig: { ...e },
402
+ pendingColorPresets: null,
403
+ postConfigureHooks: i,
404
+ handle: D(n)
405
+ };
406
+ t.instances.set(n, a), t.defaultPrefix = n;
407
+ for (const f of a.postConfigureHooks)
408
+ f();
409
+ return t.lifecycleHooks.configured?.(n), a.handle;
410
+ }
411
+ function x() {
412
+ const e = y();
413
+ return e.defaultPrefix === null ? null : e.instances.get(e.defaultPrefix) ?? null;
414
+ }
415
+ function Q(e) {
416
+ const t = x();
417
+ if (t === null) {
418
+ const n = y();
419
+ if (n.pendingPostConfigureHooks.includes(e)) return;
420
+ n.pendingPostConfigureHooks.push(e);
421
+ return;
422
+ }
423
+ t.postConfigureHooks.includes(e) || (t.postConfigureHooks.push(e), e());
424
+ }
425
+ function O() {
426
+ return x()?.config ?? V;
427
+ }
428
+ function Z() {
429
+ return [...y().instances.values()].map((e) => e.config);
430
+ }
431
+ function ee(e) {
432
+ return y().instances.get(e)?.config ?? null;
433
+ }
434
+ function te() {
435
+ const e = y();
436
+ e.instances.clear(), e.defaultPrefix = null, e.pendingColorPresets = null, e.pendingPostConfigureHooks.length = 0;
437
+ }
438
+ function ne(e = O()) {
439
+ return z(e.tabs);
440
+ }
441
+ function re(e) {
442
+ return `${e.storagePrefix}-state-v2`;
443
+ }
444
+ function ie(e) {
445
+ return `${e.storagePrefix}-state-v3`;
446
+ }
447
+ function oe(e) {
448
+ return `${e.storagePrefix}-state`;
449
+ }
450
+ function se(e) {
451
+ return `${e.storagePrefix}-open`;
452
+ }
453
+ function ae(e) {
454
+ return `${e.storagePrefix}-position`;
455
+ }
456
+ function le(e) {
457
+ return `${e.storagePrefix}-size`;
458
+ }
459
+ function fe(e) {
460
+ return `${e.storagePrefix}-density`;
461
+ }
462
+ function ce(e) {
463
+ return `${e.storagePrefix}:visible`;
464
+ }
465
+ function ge(e) {
466
+ return `${e.storagePrefix}:autoload`;
467
+ }
468
+ function de(e) {
469
+ return `${e.storagePrefix}-root`;
470
+ }
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}`;
474
+ }
475
+ const L = "__zdtp:open-state-changed";
476
+ function pe(e) {
477
+ return `${L}:${e.storagePrefix}`;
478
+ }
479
+ function ye(e, t) {
480
+ return `${e.modalClassPrefix}${t}`;
481
+ }
482
+ function me(e) {
483
+ return `${e.exportFilenameBase}.json`;
484
+ }
485
+ function he(e) {
486
+ if (e === null || typeof e != "object" || Array.isArray(e))
487
+ throw new Error("[design-token-panel] PanelConfig must be a non-null object");
488
+ const t = e;
489
+ for (const n of [
490
+ "storagePrefix",
491
+ "consoleNamespace",
492
+ "modalClassPrefix",
493
+ "schemaId",
494
+ "exportFilenameBase"
495
+ ])
496
+ if (typeof t[n] != "string" || t[n].length === 0)
497
+ throw new Error(
498
+ `[design-token-panel] PanelConfig.${n} must be a non-empty string (got ${typeof t[n]})`
499
+ );
500
+ if (J(t.tabs), t.toggleEvent !== void 0 && (typeof t.toggleEvent != "string" || t.toggleEvent.length === 0))
501
+ throw new Error(
502
+ `[design-token-panel] PanelConfig.toggleEvent must be a non-empty string when set (got ${typeof t.toggleEvent})`
503
+ );
504
+ if (t.applyEndpoint !== void 0 && typeof t.applyEndpoint != "string")
505
+ throw new Error(
506
+ `[design-token-panel] PanelConfig.applyEndpoint must be a string when set (got ${typeof t.applyEndpoint})`
507
+ );
508
+ if (t.applyRouting !== void 0) {
509
+ if (t.applyRouting === null || typeof t.applyRouting != "object" || Array.isArray(t.applyRouting))
510
+ 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")
513
+ throw new Error(
514
+ `[design-token-panel] PanelConfig.applyRouting[${JSON.stringify(n)}] must be a string`
515
+ );
516
+ }
517
+ if (t.legacyIdRenameMap !== void 0) {
518
+ if (t.legacyIdRenameMap === null || typeof t.legacyIdRenameMap != "object" || Array.isArray(t.legacyIdRenameMap))
519
+ 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")
522
+ throw new Error(
523
+ `[design-token-panel] PanelConfig.legacyIdRenameMap[${JSON.stringify(n)}] must be a string or null (got ${typeof l})`
524
+ );
525
+ }
526
+ }
527
+ function J(e) {
528
+ if (!Array.isArray(e))
529
+ throw new Error("[design-token-panel] PanelConfig.tabs must be an array");
530
+ const t = /* @__PURE__ */ new Set();
531
+ for (const n of e) {
532
+ if (n === null || typeof n != "object" || Array.isArray(n))
533
+ 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)
536
+ throw new Error("[design-token-panel] PanelConfig.tabs: each tab must have a non-empty string id");
537
+ if (t.has(l.id))
538
+ throw new Error(
539
+ `[design-token-panel] PanelConfig.tabs: duplicate tab id "${l.id}"`
540
+ );
541
+ t.add(l.id), B(l.id, l, e);
542
+ }
543
+ }
544
+ function B(e, t, n) {
545
+ if (!Array.isArray(t.tiers))
546
+ throw new Error(
547
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers must be an array`
548
+ );
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))
552
+ throw new Error(
553
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers: each tier must be a non-null object`
554
+ );
555
+ const i = s;
556
+ if (typeof i.id != "string" || i.id.length === 0)
557
+ throw new Error(
558
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers: each tier must have a non-empty string id`
559
+ );
560
+ if (l.has(i.id))
561
+ throw new Error(
562
+ `[design-token-panel] PanelConfig.tabs["${e}"]: duplicate tier id "${i.id}"`
563
+ );
564
+ if (l.add(i.id), i.semantic !== void 0 && i.semantic !== !0)
565
+ 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)})`
567
+ );
568
+ if (!Array.isArray(i.items))
569
+ throw new Error(
570
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${i.id}"].items must be an array`
571
+ );
572
+ let a;
573
+ for (const f of i.items) {
574
+ if (f === null || typeof f != "object" || Array.isArray(f)) continue;
575
+ const o = f.type;
576
+ 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)
582
+ 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)`
584
+ );
585
+ }
586
+ }
587
+ a !== void 0 && g.set(i.id, a);
588
+ }
589
+ 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) {
593
+ if (f === null || typeof f != "object" || Array.isArray(f))
594
+ throw new Error(
595
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${a}"].items: each item must be a non-null object`
596
+ );
597
+ const r = f;
598
+ if (typeof r.id != "string" || r.id.length === 0)
599
+ throw new Error(
600
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${a}"].items: each item must have a non-empty string id`
601
+ );
602
+ if (c.has(r.id))
603
+ throw new Error(
604
+ `[design-token-panel] PanelConfig.tabs["${e}"]: duplicate item id "${r.id}" (item ids must be unique across all tiers within a tab)`
605
+ );
606
+ if (c.add(r.id), typeof r.cssVar != "string" || !r.cssVar.startsWith("--"))
607
+ throw new Error(
608
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${a}"].items["${r.id}"].cssVar must start with "--" (got ${JSON.stringify(r.cssVar)})`
609
+ );
610
+ if (r.cssVar.length <= 2)
611
+ throw new Error(
612
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${a}"].items["${r.id}"].cssVar must be non-empty after "--"`
613
+ );
614
+ }
615
+ }
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")
620
+ throw new Error(
621
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${a}"].referencesTier must be a string`
622
+ );
623
+ const f = i.referencesTier;
624
+ if (!l.has(f))
625
+ throw new Error(
626
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${a}"].referencesTier: tier "${f}" does not exist in this tab`
627
+ );
628
+ const r = g.get(a), o = g.get(f);
629
+ if (r !== void 0 && o !== void 0 && r !== "text" && r !== o)
630
+ 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")`
632
+ );
633
+ }
634
+ }
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)
639
+ throw new Error(
640
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${a}"].referencesRamps is only valid on a tier with semantic: true`
641
+ );
642
+ if (!Array.isArray(i.referencesRamps))
643
+ throw new Error(
644
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${a}"].referencesRamps must be an array`
645
+ );
646
+ const f = g.get(a), r = i.referencesRamps;
647
+ for (let o = 0; o < r.length; o++) {
648
+ const d = r[o];
649
+ if (d === null || typeof d != "object" || Array.isArray(d))
650
+ throw new Error(
651
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${a}"].referencesRamps[${o}] must be a non-null object`
652
+ );
653
+ const u = d;
654
+ if (typeof u.tier != "string" || u.tier.length === 0)
655
+ throw new Error(
656
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${a}"].referencesRamps[${o}].tier must be a non-empty string`
657
+ );
658
+ if (u.tab !== void 0 && (typeof u.tab != "string" || u.tab.length === 0))
659
+ throw new Error(
660
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${a}"].referencesRamps[${o}].tab must be a non-empty string when set`
661
+ );
662
+ const m = u.tab === void 0 ? e : u.tab;
663
+ let k;
664
+ if (m === e)
665
+ k = t;
666
+ else {
667
+ const b = n.find(
668
+ (p) => p !== null && typeof p == "object" && !Array.isArray(p) && p.id === m
669
+ );
670
+ if (!b) {
671
+ const p = n.filter((h) => h !== null && typeof h == "object" && !Array.isArray(h)).map((h) => h.id).join(", ");
672
+ throw new Error(
673
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${a}"].referencesRamps[${o}]: tab "${m}" does not exist. Available tabs: ${p}.`
674
+ );
675
+ }
676
+ k = b;
677
+ }
678
+ const P = Array.isArray(k.tiers) ? k.tiers : [], S = [];
679
+ let C;
680
+ for (const b of P) {
681
+ if (b === null || typeof b != "object" || Array.isArray(b)) continue;
682
+ const p = b;
683
+ typeof p.id == "string" && (S.push(p.id), p.id === u.tier && (C = p));
684
+ }
685
+ if (!C)
686
+ 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(", ")}.`
688
+ );
689
+ if (f !== void 0) {
690
+ const b = Array.isArray(C.items) ? C.items : [];
691
+ let p;
692
+ for (const h of b) {
693
+ 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;
697
+ if (typeof T == "string") {
698
+ p = T;
699
+ break;
700
+ }
701
+ }
702
+ if (p !== void 0 && f !== p)
703
+ 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)`
705
+ );
706
+ }
707
+ }
708
+ }
709
+ if (t.colorExtras !== void 0) {
710
+ const s = t.colorExtras;
711
+ if (s === null || typeof s != "object" || Array.isArray(s))
712
+ throw new Error(
713
+ `[design-token-panel] PanelConfig.tabs["${e}"].colorExtras must be a plain object`
714
+ );
715
+ for (const r of ["id", "defaultShikiTheme"])
716
+ if (typeof s[r] != "string" || s[r].length === 0)
717
+ throw new Error(
718
+ `[design-token-panel] PanelConfig.tabs["${e}"].colorExtras.${r} must be a non-empty string (got ${typeof s[r]})`
719
+ );
720
+ for (const r of ["colorSchemes", "baseRoles", "baseDefaults"])
721
+ if (s[r] === void 0 || s[r] === null || typeof s[r] != "object" || Array.isArray(s[r]))
722
+ throw new Error(
723
+ `[design-token-panel] PanelConfig.tabs["${e}"].colorExtras.${r} must be a plain object`
724
+ );
725
+ if (s.panelSettings === void 0 || s.panelSettings === null || typeof s.panelSettings != "object" || Array.isArray(s.panelSettings))
726
+ throw new Error(
727
+ `[design-token-panel] PanelConfig.tabs["${e}"].colorExtras.panelSettings must be a plain object`
728
+ );
729
+ const i = s.panelSettings;
730
+ if (typeof i.colorScheme != "string" || i.colorScheme.length === 0)
731
+ throw new Error(
732
+ `[design-token-panel] PanelConfig.tabs["${e}"].colorExtras.panelSettings.colorScheme must be a non-empty string`
733
+ );
734
+ if (i.colorMode !== !1) {
735
+ if (i.colorMode === null || typeof i.colorMode != "object" || Array.isArray(i.colorMode))
736
+ throw new Error(
737
+ `[design-token-panel] PanelConfig.tabs["${e}"].colorExtras.panelSettings.colorMode must be false or a plain object`
738
+ );
739
+ const r = i.colorMode;
740
+ for (const o of ["lightScheme", "darkScheme"])
741
+ if (typeof r[o] != "string" || r[o].length === 0)
742
+ throw new Error(
743
+ `[design-token-panel] PanelConfig.tabs["${e}"].colorExtras.panelSettings.colorMode.${o} must be a non-empty string`
744
+ );
745
+ if (r.defaultMode !== "light" && r.defaultMode !== "dark")
746
+ throw new Error(
747
+ `[design-token-panel] PanelConfig.tabs["${e}"].colorExtras.panelSettings.colorMode.defaultMode must be "light" or "dark" (got ${JSON.stringify(r.defaultMode)})`
748
+ );
749
+ }
750
+ const f = t.tiers.find((r) => {
751
+ if (r.referencesTier !== void 0 || r.semantic === !0) return !1;
752
+ const o = r.items;
753
+ 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";
758
+ });
759
+ 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}"))
764
+ for (let m = 0; m < o.length; m++) {
765
+ const k = o[m], P = u.replace("{n}", String(m));
766
+ if (k.cssVar !== P)
767
+ 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)})`
769
+ );
770
+ }
771
+ else if (o.length > 1)
772
+ 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")`
774
+ );
775
+ }
776
+ }
777
+ }
778
+ }
779
+ function be(e = O()) {
780
+ return e.applyRouting ?? {};
781
+ }
782
+ function we(e) {
783
+ const t = x();
784
+ if (t === null) {
785
+ y().pendingColorPresets = e;
786
+ return;
787
+ }
788
+ t.config = { ...t.config, colorPresets: e };
789
+ }
790
+ 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,
807
+ 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,
821
+ Q as x,
822
+ ue as y,
823
+ Z as z
824
+ };