@takazudo/zdtp 0.1.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/CHANGELOG.md +107 -0
  2. package/LICENSE +21 -0
  3. package/README.md +1044 -0
  4. package/dist/apply/apply-token-overrides.d.ts +81 -0
  5. package/dist/apply/apply-token-overrides.d.ts.map +1 -0
  6. package/dist/apply/build-apply-overrides.d.ts +71 -0
  7. package/dist/apply/build-apply-overrides.d.ts.map +1 -0
  8. package/dist/apply/route-tokens-to-files.d.ts +65 -0
  9. package/dist/apply/route-tokens-to-files.d.ts.map +1 -0
  10. package/dist/apply/tier-resolver.d.ts +75 -0
  11. package/dist/apply/tier-resolver.d.ts.map +1 -0
  12. package/dist/apply-modal.d.ts +49 -0
  13. package/dist/apply-modal.d.ts.map +1 -0
  14. package/dist/astro/DesignTokenPanelHost.astro +76 -0
  15. package/dist/astro/host-adapter.d.ts +47 -0
  16. package/dist/astro/host-adapter.d.ts.map +1 -0
  17. package/dist/astro/host-adapter.js +81 -0
  18. package/dist/astro/index.d.ts +30 -0
  19. package/dist/astro/index.d.ts.map +1 -0
  20. package/dist/astro/index.js +54 -0
  21. package/dist/bin/cors.d.ts +24 -0
  22. package/dist/bin/cors.d.ts.map +1 -0
  23. package/dist/bin/parse-args.d.ts +38 -0
  24. package/dist/bin/parse-args.d.ts.map +1 -0
  25. package/dist/bin/server.d.ts +23 -0
  26. package/dist/bin/server.d.ts.map +1 -0
  27. package/dist/bin/server.js +283 -0
  28. package/dist/color-schemes-CgzOBqGO.js +85 -0
  29. package/dist/components/color-picker/color-picker.d.ts +64 -0
  30. package/dist/components/color-picker/color-picker.d.ts.map +1 -0
  31. package/dist/components/color-picker/custom-slider.d.ts +25 -0
  32. package/dist/components/color-picker/custom-slider.d.ts.map +1 -0
  33. package/dist/components/color-picker/index.d.ts +3 -0
  34. package/dist/components/color-picker/index.d.ts.map +1 -0
  35. package/dist/config/cluster-config.d.ts +135 -0
  36. package/dist/config/cluster-config.d.ts.map +1 -0
  37. package/dist/config/color-scheme-utils.d.ts +105 -0
  38. package/dist/config/color-scheme-utils.d.ts.map +1 -0
  39. package/dist/config/color-schemes.d.ts +83 -0
  40. package/dist/config/color-schemes.d.ts.map +1 -0
  41. package/dist/config/panel-config.d.ts +258 -0
  42. package/dist/config/panel-config.d.ts.map +1 -0
  43. package/dist/controls/pill-slider-row.d.ts +37 -0
  44. package/dist/controls/pill-slider-row.d.ts.map +1 -0
  45. package/dist/controls/role-button.d.ts +18 -0
  46. package/dist/controls/role-button.d.ts.map +1 -0
  47. package/dist/controls/sanitize-css-value.d.ts +22 -0
  48. package/dist/controls/sanitize-css-value.d.ts.map +1 -0
  49. package/dist/controls/select-row.d.ts +26 -0
  50. package/dist/controls/select-row.d.ts.map +1 -0
  51. package/dist/controls/slider-row.d.ts +34 -0
  52. package/dist/controls/slider-row.d.ts.map +1 -0
  53. package/dist/controls/text-row.d.ts +28 -0
  54. package/dist/controls/text-row.d.ts.map +1 -0
  55. package/dist/controls/tier-ref-selector.d.ts +33 -0
  56. package/dist/controls/tier-ref-selector.d.ts.map +1 -0
  57. package/dist/controls/tooltip.d.ts +44 -0
  58. package/dist/controls/tooltip.d.ts.map +1 -0
  59. package/dist/export-modal.d.ts +33 -0
  60. package/dist/export-modal.d.ts.map +1 -0
  61. package/dist/highlight/find-elements.d.ts +113 -0
  62. package/dist/highlight/find-elements.d.ts.map +1 -0
  63. package/dist/highlight/highlight-orchestrator.d.ts +24 -0
  64. package/dist/highlight/highlight-orchestrator.d.ts.map +1 -0
  65. package/dist/highlight/highlight-overlay.d.ts +43 -0
  66. package/dist/highlight/highlight-overlay.d.ts.map +1 -0
  67. package/dist/highlight/highlight-settings-popover.d.ts +25 -0
  68. package/dist/highlight/highlight-settings-popover.d.ts.map +1 -0
  69. package/dist/highlight/highlight-state.d.ts +87 -0
  70. package/dist/highlight/highlight-state.d.ts.map +1 -0
  71. package/dist/highlight/highlight-toggle-button.d.ts +34 -0
  72. package/dist/highlight/highlight-toggle-button.d.ts.map +1 -0
  73. package/dist/import-modal.d.ts +33 -0
  74. package/dist/import-modal.d.ts.map +1 -0
  75. package/dist/index.d.ts +105 -0
  76. package/dist/index.d.ts.map +1 -0
  77. package/dist/index.js +5480 -0
  78. package/dist/load-routing-XyKgftpe.js +353 -0
  79. package/dist/manifest-DCReQE0k.js +24 -0
  80. package/dist/panel-config-DP2_P7dD.js +332 -0
  81. package/dist/panel.d.ts +3 -0
  82. package/dist/panel.d.ts.map +1 -0
  83. package/dist/route-tokens-to-files-1DvmWBdj.js +41 -0
  84. package/dist/server/create-apply-handler.d.ts +48 -0
  85. package/dist/server/create-apply-handler.d.ts.map +1 -0
  86. package/dist/server/index.d.ts +24 -0
  87. package/dist/server/index.d.ts.map +1 -0
  88. package/dist/server/index.js +10 -0
  89. package/dist/server/load-routing.d.ts +39 -0
  90. package/dist/server/load-routing.d.ts.map +1 -0
  91. package/dist/server/path-safety.d.ts +36 -0
  92. package/dist/server/path-safety.d.ts.map +1 -0
  93. package/dist/server/serialize-write.d.ts +7 -0
  94. package/dist/server/serialize-write.d.ts.map +1 -0
  95. package/dist/state/persist.d.ts +39 -0
  96. package/dist/state/persist.d.ts.map +1 -0
  97. package/dist/state/tweak-state.d.ts +344 -0
  98. package/dist/state/tweak-state.d.ts.map +1 -0
  99. package/dist/tabs/_generic-item-editor.d.ts +23 -0
  100. package/dist/tabs/_generic-item-editor.d.ts.map +1 -0
  101. package/dist/tabs/color-tab.d.ts +55 -0
  102. package/dist/tabs/color-tab.d.ts.map +1 -0
  103. package/dist/tabs/font-tab.d.ts +22 -0
  104. package/dist/tabs/font-tab.d.ts.map +1 -0
  105. package/dist/tabs/generic-tab.d.ts +43 -0
  106. package/dist/tabs/generic-tab.d.ts.map +1 -0
  107. package/dist/tabs/size-tab.d.ts +20 -0
  108. package/dist/tabs/size-tab.d.ts.map +1 -0
  109. package/dist/tabs/spacing-tab.d.ts +23 -0
  110. package/dist/tabs/spacing-tab.d.ts.map +1 -0
  111. package/dist/testing.d.ts +81 -0
  112. package/dist/testing.d.ts.map +1 -0
  113. package/dist/testing.js +23 -0
  114. package/dist/tokens/manifest.d.ts +148 -0
  115. package/dist/tokens/manifest.d.ts.map +1 -0
  116. package/dist/tokens/tier-model.d.ts +89 -0
  117. package/dist/tokens/tier-model.d.ts.map +1 -0
  118. package/dist/tweak-state-DSJa5csL.js +624 -0
  119. package/dist/utils/color-convert.d.ts +7 -0
  120. package/dist/utils/color-convert.d.ts.map +1 -0
  121. package/dist/utils/color-hsla.d.ts +9 -0
  122. package/dist/utils/color-hsla.d.ts.map +1 -0
  123. package/dist/utils/color-oklch.d.ts +51 -0
  124. package/dist/utils/color-oklch.d.ts.map +1 -0
  125. package/dist/utils/design-token-serde.d.ts +193 -0
  126. package/dist/utils/design-token-serde.d.ts.map +1 -0
  127. package/dist/utils/structural-equal.d.ts +22 -0
  128. package/dist/utils/structural-equal.d.ts.map +1 -0
  129. package/dist/zdtp.css +1 -0
  130. package/package.json +102 -0
@@ -0,0 +1,353 @@
1
+ import { promises as g, readFileSync as C } from "node:fs";
2
+ import { relative as R, isAbsolute as T, sep as V, resolve as J, dirname as j, join as x } from "node:path";
3
+ import { randomBytes as A } from "node:crypto";
4
+ import { r as W } from "./route-tokens-to-files-1DvmWBdj.js";
5
+ const F = /* @__PURE__ */ new Map();
6
+ async function E(e, r) {
7
+ const n = (F.get(e) ?? Promise.resolve()).then(r, r), o = n.then(
8
+ () => {
9
+ },
10
+ () => {
11
+ }
12
+ );
13
+ F.set(e, o);
14
+ try {
15
+ return await n;
16
+ } finally {
17
+ F.get(e) === o && F.delete(e);
18
+ }
19
+ }
20
+ function z(e) {
21
+ return e.replace(/[\r\n\\;{}]/g, "");
22
+ }
23
+ const M = /^--[a-zA-Z0-9_-]+$/;
24
+ function I(e) {
25
+ return typeof e == "string" && M.test(e);
26
+ }
27
+ function q(e, r) {
28
+ if (!r.endsWith(".css")) return !1;
29
+ const t = R(e, r);
30
+ return !(t === "" || t === "." || T(t) || t === ".." || t.startsWith(`..${V}`) || t.startsWith("../"));
31
+ }
32
+ function B(e) {
33
+ const r = {};
34
+ for (const [t, n] of Object.entries(e)) {
35
+ if (!I(t))
36
+ return { error: `Invalid cssVar name: ${JSON.stringify(t)}` };
37
+ if (typeof n != "string")
38
+ return { error: `Value for ${t} must be a string` };
39
+ r[t] = z(n);
40
+ }
41
+ return { sanitized: r };
42
+ }
43
+ class $ extends Error {
44
+ constructor(r = 'No top-level ":root { ... }" block found in source.') {
45
+ super(r), this.name = "NoRootBlockError", Object.setPrototypeOf(this, $.prototype);
46
+ }
47
+ }
48
+ function N(e) {
49
+ const r = e.length;
50
+ let t = 0, n = 0;
51
+ for (; t < r; ) {
52
+ const o = e[t];
53
+ if (o === "/" && e[t + 1] === "*") {
54
+ const s = e.indexOf("*/", t + 2);
55
+ if (s === -1) return null;
56
+ t = s + 2;
57
+ continue;
58
+ }
59
+ if (o === '"' || o === "'") {
60
+ const s = o;
61
+ for (t++; t < r && e[t] !== s; )
62
+ e[t] === "\\" && t + 1 < r && t++, t++;
63
+ t++;
64
+ continue;
65
+ }
66
+ if (o === "{") {
67
+ n++, t++;
68
+ continue;
69
+ }
70
+ if (o === "}") {
71
+ n > 0 && n--, t++;
72
+ continue;
73
+ }
74
+ if (n === 0 && o === ":" && e.startsWith(":root", t)) {
75
+ const s = t + 5, a = e[s] ?? "";
76
+ if (!_(a)) {
77
+ const l = Z(e, s);
78
+ if (l !== -1) {
79
+ const k = l + 1, c = D(e, k);
80
+ return c !== -1 ? { contentStart: k, contentEnd: c } : null;
81
+ }
82
+ }
83
+ }
84
+ t++;
85
+ }
86
+ return null;
87
+ }
88
+ function _(e) {
89
+ return /[A-Za-z0-9_-]/.test(e);
90
+ }
91
+ function Z(e, r) {
92
+ const t = e.length;
93
+ let n = r;
94
+ for (; n < t; ) {
95
+ const o = e[n];
96
+ if (o === " " || o === " " || o === `
97
+ ` || o === "\r" || o === "\f") {
98
+ n++;
99
+ continue;
100
+ }
101
+ if (o === "/" && e[n + 1] === "*") {
102
+ const s = e.indexOf("*/", n + 2);
103
+ if (s === -1) return -1;
104
+ n = s + 2;
105
+ continue;
106
+ }
107
+ return o === "{" ? n : -1;
108
+ }
109
+ return -1;
110
+ }
111
+ function D(e, r) {
112
+ const t = e.length;
113
+ let n = r, o = 1;
114
+ for (; n < t; ) {
115
+ const s = e[n];
116
+ if (s === "/" && e[n + 1] === "*") {
117
+ const a = e.indexOf("*/", n + 2);
118
+ if (a === -1) return -1;
119
+ n = a + 2;
120
+ continue;
121
+ }
122
+ if (s === '"' || s === "'") {
123
+ const a = s;
124
+ for (n++; n < t && e[n] !== a; )
125
+ e[n] === "\\" && n + 1 < t && n++, n++;
126
+ n++;
127
+ continue;
128
+ }
129
+ if (s === "{") {
130
+ o++, n++;
131
+ continue;
132
+ }
133
+ if (s === "}") {
134
+ if (o--, o === 0) return n;
135
+ n++;
136
+ continue;
137
+ }
138
+ n++;
139
+ }
140
+ return -1;
141
+ }
142
+ function H(e) {
143
+ return e.replace(/[\\^$.*+?()[\]{}|]/g, "\\$&");
144
+ }
145
+ function L(e) {
146
+ return e.replace(/\/\*[\s\S]*?\*\//g, (r) => " ".repeat(r.length));
147
+ }
148
+ function U(e, r, t) {
149
+ const n = r.startsWith("--") ? r.slice(2) : r, o = H(n), s = new RegExp("(--" + o + ":)(\\s*)([\\s\\S]+?);"), a = L(e), l = s.exec(a);
150
+ if (!l) return { content: e, status: "unknown" };
151
+ const [k, c, f] = l, y = l.index, w = y + k.length, v = y + c.length + f.length, p = w - 1, O = e.slice(v, p).trim(), S = t.trim();
152
+ return O === S ? { content: e, status: "unchanged" } : { content: e.slice(0, y) + c + f + t + ";" + e.slice(w), status: "changed" };
153
+ }
154
+ function G(e, r) {
155
+ const t = Object.keys(r), n = N(e);
156
+ if (!n)
157
+ return {
158
+ updated: e,
159
+ changed: [],
160
+ unchanged: [],
161
+ unknown: [...t]
162
+ };
163
+ let o = e.slice(n.contentStart, n.contentEnd);
164
+ const s = [], a = [], l = [];
165
+ for (const c of t) {
166
+ const f = U(o, c, r[c]);
167
+ o = f.content, f.status === "changed" ? s.push(c) : f.status === "unchanged" ? a.push(c) : l.push(c);
168
+ }
169
+ return { updated: e.slice(0, n.contentStart) + o + e.slice(n.contentEnd), changed: s, unchanged: a, unknown: l };
170
+ }
171
+ function K(e, r) {
172
+ if (!N(e))
173
+ throw new $();
174
+ return G(e, r);
175
+ }
176
+ function u(e, r = 200) {
177
+ return new Response(JSON.stringify(e), {
178
+ status: r,
179
+ headers: { "Content-Type": "application/json" }
180
+ });
181
+ }
182
+ async function Q(e, r, t) {
183
+ const n = await g.readFile(e, "utf-8"), o = K(n, t);
184
+ return {
185
+ absPath: e,
186
+ relPath: r,
187
+ original: n,
188
+ updated: o.updated,
189
+ changed: o.changed,
190
+ unchanged: o.unchanged,
191
+ unknown: o.unknown
192
+ };
193
+ }
194
+ async function X(e) {
195
+ if (e.changed.length !== 0)
196
+ return E(e.absPath, async () => {
197
+ const r = j(e.absPath), t = x(r, `.tmp-${A(8).toString("hex")}.css`);
198
+ try {
199
+ await g.writeFile(t, e.updated, "utf-8"), await g.rename(t, e.absPath);
200
+ } catch (n) {
201
+ try {
202
+ await g.unlink(t);
203
+ } catch {
204
+ }
205
+ throw n;
206
+ }
207
+ });
208
+ }
209
+ async function Y(e) {
210
+ return E(e.absPath, async () => {
211
+ const r = j(e.absPath), t = x(r, `.tmp-${A(8).toString("hex")}.css`);
212
+ try {
213
+ return await g.writeFile(t, e.original, "utf-8"), await g.rename(t, e.absPath), { ok: !0 };
214
+ } catch (n) {
215
+ console.error("[design-token-panel/server] Restore failed for", e.relPath, n);
216
+ try {
217
+ await g.unlink(t);
218
+ } catch {
219
+ }
220
+ return { ok: !1, error: n };
221
+ }
222
+ });
223
+ }
224
+ function se(e) {
225
+ const { rootDir: r, writeRoot: t, routing: n } = e;
226
+ return async function(s) {
227
+ let a;
228
+ try {
229
+ a = await s.json();
230
+ } catch {
231
+ return u({ ok: !1, error: "Invalid JSON in request body" }, 400);
232
+ }
233
+ if (typeof a != "object" || a === null || Array.isArray(a))
234
+ return u({ ok: !1, error: "Request body must be a JSON object" }, 400);
235
+ const { tokens: l } = a;
236
+ if (typeof l != "object" || l === null || Array.isArray(l))
237
+ return u({ ok: !1, error: "tokens must be a JSON object" }, 400);
238
+ if (Object.entries(l).length === 0)
239
+ return u({ ok: !1, error: "tokens must contain at least one entry" }, 400);
240
+ const { sanitized: c, error: f } = B(l);
241
+ if (f || !c)
242
+ return u({ ok: !1, error: f ?? "Invalid tokens" }, 400);
243
+ const { groups: y, rejected: w } = W(c, n);
244
+ if (w.length > 0)
245
+ return u({ ok: !1, error: "Unsupported cssVar prefix", rejected: w }, 400);
246
+ if (y.length === 0)
247
+ return u({ ok: !1, error: "No routable tokens supplied" }, 400);
248
+ const v = [];
249
+ for (const i of y) {
250
+ const d = J(r, i.relativePath);
251
+ if (!q(t, d))
252
+ return u({ ok: !1, error: `Path not allowed: ${i.relativePath}` }, 400);
253
+ v.push({ absPath: d, relPath: i.relativePath, groupTokens: i.tokens });
254
+ }
255
+ const p = [];
256
+ for (const { absPath: i, relPath: d, groupTokens: m } of v)
257
+ try {
258
+ p.push(await Q(i, d, m));
259
+ } catch (h) {
260
+ return h instanceof $ ? (console.error("[design-token-panel/server] No :root block in", d), u(
261
+ {
262
+ ok: !1,
263
+ error: `No top-level :root { ... } block in ${d}`
264
+ },
265
+ 409
266
+ )) : (console.error(`[design-token-panel/server] Error computing ${d}:`, h), u({ ok: !1, error: "Failed to read or parse source file" }, 500));
267
+ }
268
+ const b = [];
269
+ for (const i of p)
270
+ try {
271
+ await X(i), b.push(i);
272
+ } catch (d) {
273
+ console.error(`[design-token-panel/server] Write failed for ${i.relPath}:`, d);
274
+ const m = [];
275
+ for (let h = b.length - 1; h >= 0; h--)
276
+ (await Y(b[h])).ok || m.push(b[h].relPath);
277
+ return m.length > 0 ? u(
278
+ {
279
+ ok: !1,
280
+ error: `Failed to write file ${i.relPath}; rollback also failed for ${m.length} file(s) — disk state is inconsistent. Inspect the listed files manually.`,
281
+ failedFile: i.relPath,
282
+ restoreFailures: m
283
+ },
284
+ 500
285
+ ) : u(
286
+ {
287
+ ok: !1,
288
+ error: `Failed to write file ${i.relPath}; previously-written files were restored.`,
289
+ failedFile: i.relPath
290
+ },
291
+ 500
292
+ );
293
+ }
294
+ const O = p.flatMap((i) => i.unknown), S = p.flatMap((i) => i.unchanged), P = p.map((i) => ({
295
+ file: i.relPath.startsWith("/") ? R(r, i.relPath) : i.relPath,
296
+ changed: i.changed,
297
+ unchanged: i.unchanged,
298
+ unknown: i.unknown
299
+ }));
300
+ return u({
301
+ ok: !0,
302
+ updated: P,
303
+ unknownCssVars: O,
304
+ unchangedCssVars: S
305
+ });
306
+ };
307
+ }
308
+ function ie(e) {
309
+ let r;
310
+ try {
311
+ r = C(e, "utf-8");
312
+ } catch (s) {
313
+ throw new Error(
314
+ `[design-token-panel] loadRoutingFromFile: cannot read file at ${e}
315
+ Cause: ${s.message}`
316
+ );
317
+ }
318
+ let t;
319
+ try {
320
+ t = JSON.parse(r);
321
+ } catch (s) {
322
+ throw new Error(
323
+ `[design-token-panel] loadRoutingFromFile: invalid JSON in ${e}
324
+ Cause: ${s.message}`
325
+ );
326
+ }
327
+ if (t === null || typeof t != "object" || Array.isArray(t))
328
+ throw new Error(
329
+ `[design-token-panel] loadRoutingFromFile: root value must be a plain object, got ${t === null ? "null" : Array.isArray(t) ? "array" : typeof t} (in ${e})`
330
+ );
331
+ const n = t, o = Object.keys(n);
332
+ if (o.length === 0)
333
+ throw new Error(
334
+ `[design-token-panel] loadRoutingFromFile: routing map must not be empty (in ${e})`
335
+ );
336
+ for (const s of o) {
337
+ const a = n[s];
338
+ if (typeof a != "string" || a.trim() === "")
339
+ throw new Error(
340
+ `[design-token-panel] loadRoutingFromFile: every value must be a non-empty string, but key "${s}" has value ${JSON.stringify(a)} (in ${e})`
341
+ );
342
+ }
343
+ return n;
344
+ }
345
+ export {
346
+ M as C,
347
+ I as a,
348
+ se as c,
349
+ q as i,
350
+ ie as l,
351
+ E as s,
352
+ B as v
353
+ };
@@ -0,0 +1,24 @@
1
+ const t = {
2
+ hsp: "HORIZONTAL SPACING (HSP)",
3
+ vsp: "VERTICAL SPACING (VSP)",
4
+ icon: "ICONS",
5
+ layout: "LAYOUT",
6
+ "font-size": "FONT SIZES",
7
+ "line-height": "LINE HEIGHTS",
8
+ "font-weight": "FONT WEIGHTS",
9
+ "font-family": "FONT FAMILIES",
10
+ "font-scale": "ADVANCED — SCALE (TIER 1)",
11
+ radius: "BORDER RADIUS",
12
+ transition: "TRANSITIONS"
13
+ }, n = ["hsp", "vsp", "icon", "layout"], s = [
14
+ "font-size",
15
+ "line-height",
16
+ "font-weight",
17
+ "font-family"
18
+ ], i = ["radius", "transition"];
19
+ export {
20
+ s as F,
21
+ n as G,
22
+ i as S,
23
+ t as a
24
+ };
@@ -0,0 +1,332 @@
1
+ function k(e, n) {
2
+ return e.paletteCssVarTemplate.replace("{n}", String(n));
3
+ }
4
+ function y(e) {
5
+ const n = e.colorExtras;
6
+ if (!n) return;
7
+ const t = e.tiers.find(
8
+ (i) => !i.referencesTier && i.items.length > 0 && i.items[0].type.kind === "color"
9
+ );
10
+ if (!t)
11
+ return {
12
+ id: n.id,
13
+ label: n.label,
14
+ paletteSize: 0,
15
+ baseRoles: n.baseRoles,
16
+ paletteCssVarTemplate: "--zudo-stub-p{n}",
17
+ semanticDefaults: {},
18
+ semanticCssNames: {},
19
+ baseDefaults: n.baseDefaults,
20
+ defaultShikiTheme: n.defaultShikiTheme,
21
+ colorSchemes: n.colorSchemes,
22
+ panelSettings: n.panelSettings
23
+ };
24
+ const r = t.items, g = r.length, o = (r[0]?.cssVar ?? "--palette-{n}").replace(/\d+$/, "{n}"), a = /* @__PURE__ */ new Map();
25
+ for (let i = 0; i < r.length; i++)
26
+ a.set(r[i].id, i);
27
+ const f = e.tiers.find(
28
+ (i) => i.referencesTier === t.id
29
+ ), s = {}, c = {};
30
+ if (f)
31
+ for (const i of f.items) {
32
+ c[i.id] = i.cssVar;
33
+ const h = a.get(i.default);
34
+ s[i.id] = h ?? 0;
35
+ }
36
+ return {
37
+ id: n.id,
38
+ label: n.label,
39
+ paletteSize: g,
40
+ baseRoles: n.baseRoles,
41
+ paletteCssVarTemplate: o,
42
+ semanticDefaults: s,
43
+ semanticCssNames: c,
44
+ baseDefaults: n.baseDefaults,
45
+ defaultShikiTheme: n.defaultShikiTheme,
46
+ colorSchemes: n.colorSchemes,
47
+ panelSettings: n.panelSettings
48
+ };
49
+ }
50
+ function $(e) {
51
+ const n = e.find((t) => t.id === "color");
52
+ if (n)
53
+ return y(n);
54
+ }
55
+ function C(e) {
56
+ const n = e.find((t) => t.id === "color-secondary");
57
+ return n ? y(n) ?? null : null;
58
+ }
59
+ function d(e, n) {
60
+ if (Object.is(e, n)) return !0;
61
+ if (e === null || n === null || typeof e != typeof n || typeof e != "object") return !1;
62
+ if (Array.isArray(e)) {
63
+ if (!Array.isArray(n) || e.length !== n.length) return !1;
64
+ for (let l = 0; l < e.length; l++)
65
+ if (!d(e[l], n[l])) return !1;
66
+ return !0;
67
+ }
68
+ if (Array.isArray(n)) return !1;
69
+ const t = Object.keys(e), r = Object.keys(n);
70
+ if (t.length !== r.length) return !1;
71
+ const g = new Set(r);
72
+ for (const l of t)
73
+ if (!g.has(l) || !d(e[l], n[l]))
74
+ return !1;
75
+ return !0;
76
+ }
77
+ const w = {
78
+ storagePrefix: "zudo-design-token-panel",
79
+ consoleNamespace: "zudo",
80
+ modalClassPrefix: "zudo-design-token-panel-modal",
81
+ schemaId: "zudo-design-tokens/v1",
82
+ exportFilenameBase: "zudo-design-tokens",
83
+ // Empty tab list — hosts MUST configure real tabs via configurePanel().
84
+ tabs: [],
85
+ colorPresets: {},
86
+ // No bundled apply endpoint / routing — hosts wire their own.
87
+ applyEndpoint: void 0,
88
+ applyRouting: void 0
89
+ }, p = /* @__PURE__ */ Symbol.for("@takazudo/zdtp:singleton");
90
+ function u() {
91
+ const e = globalThis;
92
+ let n = e[p];
93
+ return n || (n = { configuredConfig: null, pendingColorPresets: null, postConfigureHooks: [] }, e[p] = n), n;
94
+ }
95
+ function E(e) {
96
+ const n = u();
97
+ if (n.configuredConfig !== null) {
98
+ if (d(n.configuredConfig, e)) return;
99
+ throw new Error(
100
+ "[design-token-panel] configurePanel() was already called with different values. Configuration is one-shot per page lifecycle."
101
+ );
102
+ }
103
+ n.configuredConfig = n.pendingColorPresets ? { ...e, colorPresets: n.pendingColorPresets } : { ...e }, n.pendingColorPresets = null;
104
+ for (const t of n.postConfigureHooks)
105
+ t();
106
+ }
107
+ function A(e) {
108
+ const n = u();
109
+ n.postConfigureHooks.includes(e) || (n.postConfigureHooks.push(e), n.configuredConfig !== null && e());
110
+ }
111
+ function m() {
112
+ return u().configuredConfig ?? w;
113
+ }
114
+ function S() {
115
+ const e = u();
116
+ e.configuredConfig = null, e.pendingColorPresets = null, e.postConfigureHooks = [];
117
+ }
118
+ function v(e = m()) {
119
+ return C(e.tabs);
120
+ }
121
+ function T(e) {
122
+ return `${e.storagePrefix}-state-v2`;
123
+ }
124
+ function x(e) {
125
+ return `${e.storagePrefix}-state-v3`;
126
+ }
127
+ function j(e) {
128
+ return `${e.storagePrefix}-state`;
129
+ }
130
+ function R(e) {
131
+ return `${e.storagePrefix}-open`;
132
+ }
133
+ function V(e) {
134
+ return `${e.storagePrefix}-position`;
135
+ }
136
+ function K(e) {
137
+ return `${e.storagePrefix}-size`;
138
+ }
139
+ function O(e) {
140
+ return `${e.storagePrefix}-density`;
141
+ }
142
+ function _(e) {
143
+ return `${e.storagePrefix}:visible`;
144
+ }
145
+ function z(e) {
146
+ return `${e.storagePrefix}-root`;
147
+ }
148
+ function I(e, n) {
149
+ return `${e.modalClassPrefix}${n}`;
150
+ }
151
+ function M(e) {
152
+ return `${e.exportFilenameBase}.json`;
153
+ }
154
+ function F(e) {
155
+ if (e === null || typeof e != "object" || Array.isArray(e))
156
+ throw new Error("[design-token-panel] PanelConfig must be a non-null object");
157
+ const n = e;
158
+ for (const t of [
159
+ "storagePrefix",
160
+ "consoleNamespace",
161
+ "modalClassPrefix",
162
+ "schemaId",
163
+ "exportFilenameBase"
164
+ ])
165
+ if (typeof n[t] != "string" || n[t].length === 0)
166
+ throw new Error(
167
+ `[design-token-panel] PanelConfig.${t} must be a non-empty string (got ${typeof n[t]})`
168
+ );
169
+ if (b(n.tabs), n.applyEndpoint !== void 0 && typeof n.applyEndpoint != "string")
170
+ throw new Error(
171
+ `[design-token-panel] PanelConfig.applyEndpoint must be a string when set (got ${typeof n.applyEndpoint})`
172
+ );
173
+ if (n.applyRouting !== void 0) {
174
+ if (n.applyRouting === null || typeof n.applyRouting != "object" || Array.isArray(n.applyRouting))
175
+ throw new Error("[design-token-panel] PanelConfig.applyRouting must be a plain object");
176
+ for (const [t, r] of Object.entries(n.applyRouting))
177
+ if (typeof r != "string")
178
+ throw new Error(
179
+ `[design-token-panel] PanelConfig.applyRouting[${JSON.stringify(t)}] must be a string`
180
+ );
181
+ }
182
+ if (n.legacyIdRenameMap !== void 0) {
183
+ if (n.legacyIdRenameMap === null || typeof n.legacyIdRenameMap != "object" || Array.isArray(n.legacyIdRenameMap))
184
+ throw new Error("[design-token-panel] PanelConfig.legacyIdRenameMap must be a plain object");
185
+ for (const [t, r] of Object.entries(n.legacyIdRenameMap))
186
+ if (r !== null && typeof r != "string")
187
+ throw new Error(
188
+ `[design-token-panel] PanelConfig.legacyIdRenameMap[${JSON.stringify(t)}] must be a string or null (got ${typeof r})`
189
+ );
190
+ }
191
+ }
192
+ function b(e) {
193
+ if (!Array.isArray(e))
194
+ throw new Error("[design-token-panel] PanelConfig.tabs must be an array");
195
+ const n = /* @__PURE__ */ new Set();
196
+ for (const t of e) {
197
+ if (t === null || typeof t != "object" || Array.isArray(t))
198
+ throw new Error("[design-token-panel] PanelConfig.tabs: each tab must be a non-null object");
199
+ const r = t;
200
+ if (typeof r.id != "string" || r.id.length === 0)
201
+ throw new Error("[design-token-panel] PanelConfig.tabs: each tab must have a non-empty string id");
202
+ if (n.has(r.id))
203
+ throw new Error(
204
+ `[design-token-panel] PanelConfig.tabs: duplicate tab id "${r.id}"`
205
+ );
206
+ n.add(r.id), P(r.id, r);
207
+ }
208
+ }
209
+ function P(e, n) {
210
+ if (!Array.isArray(n.tiers))
211
+ throw new Error(
212
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers must be an array`
213
+ );
214
+ const t = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Map();
215
+ for (const l of n.tiers) {
216
+ if (l === null || typeof l != "object" || Array.isArray(l))
217
+ throw new Error(
218
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers: each tier must be a non-null object`
219
+ );
220
+ const o = l;
221
+ if (typeof o.id != "string" || o.id.length === 0)
222
+ throw new Error(
223
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers: each tier must have a non-empty string id`
224
+ );
225
+ if (t.has(o.id))
226
+ throw new Error(
227
+ `[design-token-panel] PanelConfig.tabs["${e}"]: duplicate tier id "${o.id}"`
228
+ );
229
+ if (t.add(o.id), !Array.isArray(o.items))
230
+ throw new Error(
231
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${o.id}"].items must be an array`
232
+ );
233
+ let a;
234
+ for (const f of o.items) {
235
+ if (f === null || typeof f != "object" || Array.isArray(f)) continue;
236
+ const c = f.type;
237
+ if (c === null || typeof c != "object" || Array.isArray(c)) continue;
238
+ const i = c.kind;
239
+ if (typeof i == "string") {
240
+ if (a === void 0)
241
+ a = i;
242
+ else if (a !== i)
243
+ throw new Error(
244
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${o.id}"]: mixed item kinds — found "${a}" and "${i}" in the same tier (all items must share the same kind)`
245
+ );
246
+ }
247
+ }
248
+ a !== void 0 && r.set(o.id, a);
249
+ }
250
+ const g = /* @__PURE__ */ new Set();
251
+ for (const l of n.tiers) {
252
+ const o = l, a = o.id;
253
+ for (const f of o.items) {
254
+ if (f === null || typeof f != "object" || Array.isArray(f))
255
+ throw new Error(
256
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${a}"].items: each item must be a non-null object`
257
+ );
258
+ const s = f;
259
+ if (typeof s.id != "string" || s.id.length === 0)
260
+ throw new Error(
261
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${a}"].items: each item must have a non-empty string id`
262
+ );
263
+ if (g.has(s.id))
264
+ throw new Error(
265
+ `[design-token-panel] PanelConfig.tabs["${e}"]: duplicate item id "${s.id}" (item ids must be unique across all tiers within a tab)`
266
+ );
267
+ if (g.add(s.id), typeof s.cssVar != "string" || !s.cssVar.startsWith("--"))
268
+ throw new Error(
269
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${a}"].items["${s.id}"].cssVar must start with "--" (got ${JSON.stringify(s.cssVar)})`
270
+ );
271
+ if (s.cssVar.length <= 2)
272
+ throw new Error(
273
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${a}"].items["${s.id}"].cssVar must be non-empty after "--"`
274
+ );
275
+ }
276
+ }
277
+ for (const l of n.tiers) {
278
+ const o = l, a = o.id;
279
+ if (o.referencesTier !== void 0) {
280
+ if (typeof o.referencesTier != "string")
281
+ throw new Error(
282
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${a}"].referencesTier must be a string`
283
+ );
284
+ const f = o.referencesTier;
285
+ if (!t.has(f))
286
+ throw new Error(
287
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${a}"].referencesTier: tier "${f}" does not exist in this tab`
288
+ );
289
+ const s = r.get(a), c = r.get(f);
290
+ if (s !== void 0 && c !== void 0 && s !== "text" && s !== c)
291
+ throw new Error(
292
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${a}"].referencesTier: referencing tier has kind "${s}" but referenced tier "${f}" has kind "${c}" (cross-kind reference is only allowed when the referencing tier has kind "text")`
293
+ );
294
+ }
295
+ }
296
+ }
297
+ function N(e = m()) {
298
+ return e.applyRouting ?? {};
299
+ }
300
+ function D(e) {
301
+ const n = u();
302
+ if (n.configuredConfig === null) {
303
+ n.pendingColorPresets = e;
304
+ return;
305
+ }
306
+ n.configuredConfig = { ...n.configuredConfig, colorPresets: e };
307
+ }
308
+ export {
309
+ S as _,
310
+ _ as a,
311
+ T as b,
312
+ E as c,
313
+ x as d,
314
+ F as e,
315
+ R as f,
316
+ m as g,
317
+ V as h,
318
+ j as i,
319
+ k as j,
320
+ K as k,
321
+ O as l,
322
+ $ as m,
323
+ M as n,
324
+ I as o,
325
+ d as p,
326
+ N as q,
327
+ v as r,
328
+ D as s,
329
+ y as t,
330
+ A as u,
331
+ z as v
332
+ };
@@ -0,0 +1,3 @@
1
+ export default function DesignTokenTweakPanel(): import("preact").JSX.Element;
2
+ export type { TweakState } from './state/tweak-state';
3
+ //# sourceMappingURL=panel.d.ts.map