@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,624 @@
1
+ import { f as Z, g as d, r as T, j as K, h as X, k as q, l as Q, i as ee, b as te, d as ne, m as oe } from "./panel-config-DP2_P7dD.js";
2
+ class h extends Error {
3
+ constructor(t) {
4
+ super(t), this.name = "TierResolverError", Object.setPrototypeOf(this, h.prototype);
5
+ }
6
+ }
7
+ function P(e, t) {
8
+ return e.tiers.find((n) => n.id === t);
9
+ }
10
+ function b(e, t) {
11
+ return e.items.find((n) => n.id === t);
12
+ }
13
+ function re(e, t, n, o) {
14
+ const r = P(e, t);
15
+ if (!r)
16
+ throw new h(
17
+ `Tier "${t}" not found in tab "${e.id}". Available tiers: ${e.tiers.map((f) => f.id).join(", ")}.`
18
+ );
19
+ const i = b(r, n);
20
+ if (!i)
21
+ throw new h(
22
+ `Item "${n}" not found in tier "${t}" of tab "${e.id}".`
23
+ );
24
+ const a = o[t]?.[n];
25
+ if (r.referencesTier !== void 0) {
26
+ const f = r.referencesTier, c = P(e, f);
27
+ if (!c)
28
+ throw new h(
29
+ `Tier "${t}" declares referencesTier "${f}" but that tier does not exist in tab "${e.id}".`
30
+ );
31
+ const l = b(c, a ?? n);
32
+ if (!l) {
33
+ const m = b(c, i.default) ?? b(c, n) ?? c.items[0];
34
+ if (!m)
35
+ throw new h(
36
+ `Referenced tier "${f}" has no items; cannot resolve fallback for item "${n}" in tier "${t}" of tab "${e.id}".`
37
+ );
38
+ return { kind: "ref", targetCssVar: m.cssVar };
39
+ }
40
+ return { kind: "ref", targetCssVar: l.cssVar };
41
+ }
42
+ return a !== void 0 ? i.pill && a === i.pill.value ? { kind: "literal", value: i.pill.value } : { kind: "literal", value: a } : i.pill ? { kind: "literal", value: i.pill.customDefault } : { kind: "literal", value: i.default };
43
+ }
44
+ function ie(e) {
45
+ return e.kind === "literal" ? e.value : `var(${e.targetCssVar})`;
46
+ }
47
+ function L() {
48
+ return ee(d());
49
+ }
50
+ function J() {
51
+ return te(d());
52
+ }
53
+ function V() {
54
+ return ne(d());
55
+ }
56
+ function Ie() {
57
+ return Z(d());
58
+ }
59
+ function G() {
60
+ return X(d());
61
+ }
62
+ function W() {
63
+ return q(d());
64
+ }
65
+ function Y() {
66
+ return Q(d());
67
+ }
68
+ const se = { top: 60, left: 20 };
69
+ function ae() {
70
+ if (typeof window > "u") return se;
71
+ const e = Math.min(1200, 0.8 * window.innerWidth), t = Math.min(800, 0.8 * window.innerHeight), n = Math.max(0, Math.round((window.innerHeight - t) / 2)), o = Math.max(0, Math.round((window.innerWidth - e) / 2));
72
+ return { top: n, left: o };
73
+ }
74
+ function we() {
75
+ try {
76
+ const e = localStorage.getItem(G());
77
+ if (e) {
78
+ const t = JSON.parse(e);
79
+ if (typeof t.top == "number" && typeof t.left == "number")
80
+ return t;
81
+ }
82
+ } catch {
83
+ }
84
+ return ae();
85
+ }
86
+ function Oe(e) {
87
+ try {
88
+ localStorage.setItem(G(), JSON.stringify(e));
89
+ } catch {
90
+ }
91
+ }
92
+ const M = 60, C = 320, D = 240, E = 1600, F = 1200, ce = { width: 1024 * 0.8, height: 768 * 0.8 };
93
+ function fe() {
94
+ return typeof window > "u" ? ce : {
95
+ width: Math.min(1200, 0.8 * window.innerWidth),
96
+ height: Math.min(800, 0.8 * window.innerHeight)
97
+ };
98
+ }
99
+ const R = 32;
100
+ function le(e, t) {
101
+ const n = typeof window < "u" ? window.innerWidth : E, o = typeof window < "u" ? window.innerHeight : F, r = Math.max(C, Math.min(E, n - R)), i = Math.max(D, Math.min(F, o - R));
102
+ return {
103
+ width: Math.max(C, Math.min(e, r)),
104
+ height: Math.max(D, Math.min(t, i))
105
+ };
106
+ }
107
+ function $e() {
108
+ try {
109
+ const e = localStorage.getItem(W());
110
+ if (e) {
111
+ const t = JSON.parse(e);
112
+ if (typeof t.width == "number" && typeof t.height == "number" && Number.isFinite(t.width) && Number.isFinite(t.height))
113
+ return le(t.width, t.height);
114
+ }
115
+ } catch {
116
+ }
117
+ return fe();
118
+ }
119
+ function Ae(e) {
120
+ try {
121
+ localStorage.setItem(W(), JSON.stringify(e));
122
+ } catch {
123
+ }
124
+ }
125
+ const ue = 1;
126
+ function _e(e) {
127
+ return e === 0 ? "12rem" : e === 2 ? "100%" : "18rem";
128
+ }
129
+ function Ve() {
130
+ try {
131
+ const e = localStorage.getItem(Y());
132
+ if (e === "0" || e === "1" || e === "2")
133
+ return Number(e);
134
+ } catch {
135
+ }
136
+ return ue;
137
+ }
138
+ function Ne(e) {
139
+ try {
140
+ localStorage.setItem(Y(), String(e));
141
+ } catch {
142
+ }
143
+ }
144
+ function Pe(e, t, n, o) {
145
+ const r = -(n - M), i = window.innerWidth - M, s = -30, a = window.innerHeight - M, f = Math.max(a, s), c = Math.max(i, r);
146
+ return {
147
+ top: Math.max(s, Math.min(e, f)),
148
+ left: Math.max(r, Math.min(t, c))
149
+ };
150
+ }
151
+ async function Ce(e) {
152
+ }
153
+ function k() {
154
+ return {};
155
+ }
156
+ const de = {
157
+ id: "stub",
158
+ label: "STUB",
159
+ paletteSize: 0,
160
+ baseRoles: {},
161
+ paletteCssVarTemplate: "--zudo-stub-p{n}",
162
+ semanticDefaults: {},
163
+ semanticCssNames: {},
164
+ baseDefaults: {},
165
+ defaultShikiTheme: "dracula",
166
+ colorSchemes: {},
167
+ panelSettings: { colorScheme: "", colorMode: !1 }
168
+ };
169
+ function p(e = d()) {
170
+ return oe(e.tabs) ?? de;
171
+ }
172
+ function N(e) {
173
+ const t = Math.max(1, e.paletteSize);
174
+ return {
175
+ palette: Array.from({ length: t }, (o, r) => {
176
+ if (t === 1) return "#808080";
177
+ const s = Math.round(r / (t - 1) * 255).toString(16).padStart(2, "0");
178
+ return `#${s}${s}${s}`;
179
+ }),
180
+ background: e.baseDefaults.background ?? 0,
181
+ foreground: e.baseDefaults.foreground ?? 0,
182
+ cursor: e.baseDefaults.cursor ?? 0,
183
+ selectionBg: e.baseDefaults.selectionBg ?? 0,
184
+ selectionFg: e.baseDefaults.selectionFg ?? 0,
185
+ semanticMappings: { ...e.semanticDefaults },
186
+ shikiTheme: e.defaultShikiTheme
187
+ };
188
+ }
189
+ function De() {
190
+ const e = T();
191
+ return e ? N(e) : void 0;
192
+ }
193
+ function me() {
194
+ try {
195
+ const e = document.createElement("canvas").getContext("2d");
196
+ return e ? (e.fillStyle = "#ffffff", e.fillStyle === "#ffffff") : !1;
197
+ } catch {
198
+ return !1;
199
+ }
200
+ }
201
+ const ge = me();
202
+ function pe(e) {
203
+ const t = e.match(/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)(?:\s*,\s*([\d.]+))?/);
204
+ if (!t) return null;
205
+ const n = parseInt(t[1], 10), o = parseInt(t[2], 10), r = parseInt(t[3], 10), i = `#${(1 << 24 | n << 16 | o << 8 | r).toString(16).slice(1)}`;
206
+ if (t[4] !== void 0) {
207
+ const s = parseFloat(t[4]);
208
+ if (s < 1) {
209
+ const a = Math.round(s * 255).toString(16).padStart(2, "0");
210
+ return `${i}${a}`;
211
+ }
212
+ }
213
+ return i;
214
+ }
215
+ function ye(e, t, n, o) {
216
+ const r = (s) => s.toString(16).padStart(2, "0"), i = `#${r(e)}${r(t)}${r(n)}`;
217
+ return o < 255 ? `${i}${r(o)}` : i;
218
+ }
219
+ let g = null;
220
+ function $(e) {
221
+ if (!e || e === "initial" || e === "inherit") return "#000000";
222
+ const t = e.trim();
223
+ if (/^#[0-9a-fA-F]{6}$/.test(t) || /^#[0-9a-fA-F]{8}$/.test(t)) return t;
224
+ if (/^#[0-9a-fA-F]{3}$/.test(t))
225
+ return `#${t[1]}${t[1]}${t[2]}${t[2]}${t[3]}${t[3]}`;
226
+ if (/^#[0-9a-fA-F]{4}$/.test(t))
227
+ return `#${t[1]}${t[1]}${t[2]}${t[2]}${t[3]}${t[3]}${t[4]}${t[4]}`;
228
+ const n = pe(t);
229
+ if (n) return n;
230
+ if (!ge) return "#000000";
231
+ try {
232
+ if (g || (g = document.createElement("canvas").getContext("2d")), !g) return "#000000";
233
+ g.fillStyle = "#000000", g.fillStyle = t, g.clearRect(0, 0, 1, 1), g.fillRect(0, 0, 1, 1);
234
+ const [o, r, i, s] = g.getImageData(0, 0, 1, 1).data;
235
+ return ye(o, r, i, s);
236
+ } catch {
237
+ return "#000000";
238
+ }
239
+ }
240
+ function S(e, t) {
241
+ document.documentElement.style.setProperty(e, t);
242
+ }
243
+ function y(e, t, n) {
244
+ if (e === void 0) return n;
245
+ if (typeof e == "number") return e;
246
+ const o = $(e), r = t.map((u) => $(u)), i = t.indexOf(e);
247
+ if (i >= 0) return i;
248
+ const s = r.indexOf(o);
249
+ if (s >= 0) return s;
250
+ const a = j(o);
251
+ let f = n, c = 1 / 0;
252
+ for (let u = 0; u < r.length; u++) {
253
+ const l = j(r[u]), m = (a.r - l.r) ** 2 + (a.g - l.g) ** 2 + (a.b - l.b) ** 2;
254
+ m < c && (c = m, f = u);
255
+ }
256
+ return f;
257
+ }
258
+ function j(e) {
259
+ const t = e.replace("#", "");
260
+ return {
261
+ r: parseInt(t.substring(0, 2), 16) || 0,
262
+ g: parseInt(t.substring(2, 4), 16) || 0,
263
+ b: parseInt(t.substring(4, 6), 16) || 0,
264
+ aa: t.length >= 8 ? parseInt(t.substring(6, 8), 16) || 0 : 255
265
+ };
266
+ }
267
+ function he(e = p()) {
268
+ const t = e.panelSettings;
269
+ if (t.colorMode) {
270
+ const n = document.documentElement.getAttribute("data-theme");
271
+ if (n === "light") return t.colorMode.lightScheme;
272
+ if (n === "dark") return t.colorMode.darkScheme;
273
+ }
274
+ return t.colorScheme;
275
+ }
276
+ function be(e = p()) {
277
+ const t = e.colorSchemes;
278
+ if (Object.keys(t).length === 0)
279
+ return N(e);
280
+ const n = he(e), o = t[n] ?? Object.values(t)[0];
281
+ return Se(o, e);
282
+ }
283
+ function Se(e, t = p()) {
284
+ const n = e.palette.map((r) => $(r)), o = {};
285
+ for (const [r, i] of Object.entries(t.semanticDefaults)) {
286
+ const s = e.semantic?.[r];
287
+ s === void 0 ? o[r] = i : typeof s == "number" ? o[r] = s : o[r] = y(s, e.palette, i);
288
+ }
289
+ return {
290
+ palette: n,
291
+ background: y(
292
+ e.background,
293
+ e.palette,
294
+ t.baseDefaults.background ?? 0
295
+ ),
296
+ foreground: y(
297
+ e.foreground,
298
+ e.palette,
299
+ t.baseDefaults.foreground ?? 0
300
+ ),
301
+ cursor: y(e.cursor, e.palette, t.baseDefaults.cursor ?? 0),
302
+ selectionBg: y(
303
+ e.selectionBg,
304
+ e.palette,
305
+ t.baseDefaults.selectionBg ?? 0
306
+ ),
307
+ selectionFg: y(
308
+ e.selectionFg,
309
+ e.palette,
310
+ t.baseDefaults.selectionFg ?? 0
311
+ ),
312
+ semanticMappings: o,
313
+ shikiTheme: String(e.shikiTheme ?? t.defaultShikiTheme)
314
+ };
315
+ }
316
+ function ve(e, t, n, o) {
317
+ const r = t.length;
318
+ return e === "bg" ? t[v(n, r)] ?? "#000000" : e === "fg" ? t[v(o, r)] ?? "#ffffff" : t[v(e, r)] ?? "#000000";
319
+ }
320
+ function v(e, t) {
321
+ return e >= 0 && e < t ? e : 0;
322
+ }
323
+ function z(e, t = p()) {
324
+ const n = e.palette.length;
325
+ for (let o = 0; o < n; o++)
326
+ S(K(t, o), e.palette[o]);
327
+ for (const [o, r] of Object.entries(t.baseRoles)) {
328
+ if (typeof r != "string" || r.length === 0) continue;
329
+ const i = e[o];
330
+ typeof i == "number" && S(r, e.palette[v(i, n)]);
331
+ }
332
+ for (const [o, r] of Object.entries(t.semanticCssNames)) {
333
+ const i = e.semanticMappings[o] ?? t.semanticDefaults[o];
334
+ S(r, ve(i, e.palette, e.background, e.foreground));
335
+ }
336
+ }
337
+ function Ee(e) {
338
+ const t = d();
339
+ z(e.color, p(t)), I(t.tabs, "spacing", e.spacing), I(t.tabs, "font", e.typography), I(t.tabs, "size", e.size);
340
+ const n = T(t);
341
+ n && e.secondary && z(e.secondary, n);
342
+ }
343
+ function I(e, t, n) {
344
+ const o = e.find((s) => s.id === t);
345
+ if (!o) return;
346
+ const r = {};
347
+ for (const s of o.tiers) {
348
+ const a = {};
349
+ for (const f of s.items) {
350
+ const c = n[f.id];
351
+ typeof c == "string" && c.length > 0 && (a[f.id] = c);
352
+ }
353
+ r[s.id] = a;
354
+ }
355
+ const i = document.documentElement;
356
+ for (const s of o.tiers)
357
+ for (const a of s.items)
358
+ if (!a.readonly)
359
+ try {
360
+ const f = re(o, s.id, a.id, r), c = ie(f);
361
+ typeof n[a.id] == "string" && n[a.id].length > 0 || s.referencesTier !== void 0 ? S(a.cssVar, c) : i.style.removeProperty(a.cssVar);
362
+ } catch {
363
+ i.style.removeProperty(a.cssVar);
364
+ }
365
+ }
366
+ function Fe(e = (() => {
367
+ const t = d(), n = p(t), o = T(t);
368
+ return o ? [n, o] : [n];
369
+ })()) {
370
+ const t = document.documentElement;
371
+ for (const n of e) {
372
+ for (let o = 0; o < n.paletteSize; o++)
373
+ t.style.removeProperty(K(n, o));
374
+ for (const o of Object.values(n.baseRoles))
375
+ t.style.removeProperty(o);
376
+ for (const o of Object.values(n.semanticCssNames))
377
+ t.style.removeProperty(o);
378
+ }
379
+ for (const n of d().tabs)
380
+ if (n.id !== "color")
381
+ for (const o of n.tiers)
382
+ for (const r of o.items)
383
+ r.readonly || t.style.removeProperty(r.cssVar);
384
+ }
385
+ function A(e, t) {
386
+ if (!e || typeof e != "object") return !1;
387
+ const n = e;
388
+ return Array.isArray(n.palette) && n.palette.length === t && typeof n.background == "number" && typeof n.foreground == "number" && typeof n.cursor == "number" && typeof n.selectionBg == "number" && typeof n.selectionFg == "number" && typeof n.semanticMappings == "object" && n.semanticMappings !== null;
389
+ }
390
+ function _(e, t) {
391
+ const n = Array.isArray(e.palette) ? e.palette : null;
392
+ let o;
393
+ return n && n.length === t.palette.length && n.every((r) => typeof r == "string") ? o = n : (n && n.some((r) => typeof r != "string") && console.error(
394
+ "[design-token-panel] Persisted palette contained non-string elements; falling back to defaults."
395
+ ), o = t.palette), {
396
+ palette: o,
397
+ background: typeof e.background == "number" ? e.background : t.background,
398
+ foreground: typeof e.foreground == "number" ? e.foreground : t.foreground,
399
+ cursor: typeof e.cursor == "number" ? e.cursor : t.cursor,
400
+ selectionBg: typeof e.selectionBg == "number" ? e.selectionBg : t.selectionBg,
401
+ selectionFg: typeof e.selectionFg == "number" ? e.selectionFg : t.selectionFg,
402
+ semanticMappings: e.semanticMappings && typeof e.semanticMappings == "object" ? { ...t.semanticMappings, ...e.semanticMappings } : t.semanticMappings,
403
+ shikiTheme: typeof e.shikiTheme == "string" && e.shikiTheme.length > 0 ? e.shikiTheme : t.shikiTheme
404
+ };
405
+ }
406
+ const Re = {
407
+ "text-caption": "text-xs",
408
+ "text-small": "text-sm",
409
+ "text-body": "text-base",
410
+ "text-subheading": "text-lg",
411
+ "text-heading": "text-3xl",
412
+ "text-display": "text-5xl",
413
+ // Dropped — no main-site equivalent. `null` signals "discard".
414
+ "text-micro": null
415
+ };
416
+ function H(e) {
417
+ if (!e || typeof e != "object") return {};
418
+ const t = {};
419
+ for (const [n, o] of Object.entries(e))
420
+ typeof o == "string" && (t[n] = o);
421
+ return t;
422
+ }
423
+ function Te(e, t = {}) {
424
+ if (!e || typeof e != "object") return {};
425
+ const n = {};
426
+ for (const [o, r] of Object.entries(e))
427
+ if (typeof r == "string")
428
+ if (Object.hasOwn(t, o)) {
429
+ const i = t[o];
430
+ if (i === null) continue;
431
+ Object.hasOwn(n, i) || (n[i] = r);
432
+ } else
433
+ n[o] = r;
434
+ return n;
435
+ }
436
+ function xe(e) {
437
+ if (!e || typeof e != "object") return;
438
+ const t = e;
439
+ if (typeof t.top == "number" && typeof t.left == "number" && Number.isFinite(t.top) && Number.isFinite(t.left))
440
+ return { top: t.top, left: t.left };
441
+ }
442
+ function Me(e) {
443
+ if (!e || typeof e != "object" || Array.isArray(e)) return {};
444
+ const t = {};
445
+ for (const [n, o] of Object.entries(e)) {
446
+ if (!o || typeof o != "object" || Array.isArray(o)) continue;
447
+ const r = {};
448
+ for (const [i, s] of Object.entries(o)) {
449
+ if (!s || typeof s != "object" || Array.isArray(s)) continue;
450
+ const a = {};
451
+ for (const [f, c] of Object.entries(s))
452
+ typeof c == "string" && (a[f] = c);
453
+ r[i] = a;
454
+ }
455
+ t[n] = r;
456
+ }
457
+ return t;
458
+ }
459
+ function B(e, t, n) {
460
+ if (!e.color || !A(e.color, t.paletteSize)) return null;
461
+ const o = n ?? U(t), r = e.typography !== void 0 ? e.typography : e.font, i = d().legacyIdRenameMap ?? {}, s = {
462
+ color: _(e.color, o),
463
+ // New sections added after v1 migration — tolerate their absence so
464
+ // older v2 payloads (Color-only) still load cleanly.
465
+ spacing: H(e.spacing),
466
+ // Typography slice: apply the host-configured rename map (if any)
467
+ // so payloads persisted under the host's "old" ids survive a
468
+ // host-driven id rename without losing the user's tweaks.
469
+ typography: Te(r, i),
470
+ size: H(e.size),
471
+ panelPosition: xe(e.panelPosition)
472
+ }, a = T();
473
+ a && e.secondary && A(e.secondary, a.paletteSize) && (s.secondary = _(
474
+ e.secondary,
475
+ N(a)
476
+ ));
477
+ const f = Me(e.tabs);
478
+ return Object.keys(f).length > 0 && (s.tabs = f), s;
479
+ }
480
+ function je(e = localStorage, t, n = p()) {
481
+ const o = L(), r = J(), i = V(), s = w(e, i);
482
+ if (s !== null) {
483
+ const c = O(s);
484
+ if (c && typeof c == "object") {
485
+ const u = c, l = B(u, n, t);
486
+ if (l !== null) {
487
+ const m = u.typography !== void 0 ? u.typography : u.font;
488
+ if (JSON.stringify(m ?? {}) !== JSON.stringify(l.typography) || u.typography === void 0)
489
+ try {
490
+ e.setItem(i, JSON.stringify(l));
491
+ } catch {
492
+ }
493
+ return l;
494
+ }
495
+ }
496
+ console.warn(`[tweak] Malformed ${i}, attempting v2 migration`);
497
+ }
498
+ const a = w(e, r);
499
+ if (a !== null) {
500
+ const c = O(a);
501
+ if (c && typeof c == "object") {
502
+ const l = B(c, n, t);
503
+ if (l !== null) {
504
+ try {
505
+ e.setItem(i, JSON.stringify(l)), e.removeItem(r);
506
+ } catch {
507
+ }
508
+ return l;
509
+ }
510
+ }
511
+ console.warn(`[tweak] Malformed ${r}, attempting v1 migration`);
512
+ }
513
+ const f = w(e, o);
514
+ if (f !== null) {
515
+ const c = O(f);
516
+ if (c && typeof c == "object" && A(c, n.paletteSize)) {
517
+ const u = t ?? U(n), l = c;
518
+ l.shikiTheme || (l.shikiTheme = u.shikiTheme);
519
+ const x = {
520
+ color: _(l, u),
521
+ spacing: k(),
522
+ typography: k(),
523
+ size: k()
524
+ };
525
+ try {
526
+ e.setItem(i, JSON.stringify(x)), e.removeItem(o);
527
+ } catch {
528
+ }
529
+ return x;
530
+ }
531
+ console.warn(`[tweak] Malformed ${o}; discarding and using fresh defaults`);
532
+ try {
533
+ e.removeItem(o);
534
+ } catch {
535
+ }
536
+ }
537
+ return null;
538
+ }
539
+ function ze(e, t = localStorage) {
540
+ try {
541
+ t.setItem(V(), JSON.stringify(e));
542
+ } catch {
543
+ }
544
+ }
545
+ function He(e = localStorage) {
546
+ try {
547
+ e.removeItem(V());
548
+ } catch {
549
+ }
550
+ try {
551
+ e.removeItem(J());
552
+ } catch {
553
+ }
554
+ try {
555
+ e.removeItem(L());
556
+ } catch {
557
+ }
558
+ }
559
+ function w(e, t) {
560
+ try {
561
+ return e.getItem(t);
562
+ } catch {
563
+ return null;
564
+ }
565
+ }
566
+ function O(e) {
567
+ try {
568
+ return JSON.parse(e);
569
+ } catch {
570
+ return null;
571
+ }
572
+ }
573
+ function U(e) {
574
+ try {
575
+ return be(e);
576
+ } catch {
577
+ return {
578
+ palette: Array.from(
579
+ { length: e.paletteSize },
580
+ (n, o) => o === 0 ? "#000000" : o === e.paletteSize - 1 ? "#ffffff" : "#808080"
581
+ ),
582
+ background: e.baseDefaults.background ?? 0,
583
+ foreground: e.baseDefaults.foreground ?? 0,
584
+ cursor: e.baseDefaults.cursor ?? 0,
585
+ selectionBg: e.baseDefaults.selectionBg ?? 0,
586
+ selectionFg: e.baseDefaults.selectionFg ?? 0,
587
+ semanticMappings: { ...e.semanticDefaults },
588
+ shikiTheme: e.defaultShikiTheme
589
+ };
590
+ }
591
+ }
592
+ export {
593
+ le as A,
594
+ k as B,
595
+ V as C,
596
+ se as D,
597
+ Re as Z,
598
+ J as a,
599
+ p as b,
600
+ Ce as c,
601
+ Ee as d,
602
+ ie as e,
603
+ ze as f,
604
+ L as g,
605
+ fe as h,
606
+ Se as i,
607
+ ue as j,
608
+ Ie as k,
609
+ je as l,
610
+ we as m,
611
+ $e as n,
612
+ Ve as o,
613
+ Ne as p,
614
+ He as q,
615
+ re as r,
616
+ v as s,
617
+ Fe as t,
618
+ De as u,
619
+ _e as v,
620
+ be as w,
621
+ Oe as x,
622
+ Ae as y,
623
+ Pe as z
624
+ };
@@ -0,0 +1,7 @@
1
+ export declare function hexToHsl(hex: string): {
2
+ h: number;
3
+ s: number;
4
+ l: number;
5
+ };
6
+ export declare function hslToHex(h: number, s: number, l: number): string;
7
+ //# sourceMappingURL=color-convert.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color-convert.d.ts","sourceRoot":"","sources":["../../src/utils/color-convert.ts"],"names":[],"mappings":"AAkBA,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAgBzE;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAkChE"}
@@ -0,0 +1,9 @@
1
+ export interface Hsla {
2
+ h: number;
3
+ s: number;
4
+ l: number;
5
+ a: number;
6
+ }
7
+ export declare function hexToHsla(hex: string): Hsla;
8
+ export declare function hslaToHex(h: number, s: number, l: number, a: number): string;
9
+ //# sourceMappingURL=color-hsla.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color-hsla.d.ts","sourceRoot":"","sources":["../../src/utils/color-hsla.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,IAAI;IACnB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAkBD,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CA4B3C;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAgD5E"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * OKLCH ↔ sRGB ↔ HSL math primitives for the design-token panel.
3
+ *
4
+ * Alpha convention: all alpha values in this module are expressed on a
5
+ * 0–100 scale (0 = fully transparent, 100 = fully opaque). This matches
6
+ * the HSL convention used elsewhere in the panel and differs from culori's
7
+ * internal 0–1 range; conversion happens at the boundary.
8
+ *
9
+ * OKLCH CSS gradient browser baseline: Chromium 111+ / Safari 16+ / Firefox 113+.
10
+ * Consumers targeting older browsers should clamp to sRGB before emitting CSS.
11
+ */
12
+ import type { Hsla } from './color-hsla';
13
+ export type { Hsla } from './color-hsla';
14
+ /** All four components use the panel's 0–100 scale for alpha. */
15
+ export interface Oklcha {
16
+ l: number;
17
+ c: number;
18
+ h: number;
19
+ a: number;
20
+ }
21
+ /** Practical upper bound for chroma in the sRGB gamut. */
22
+ export declare const MAX_OKLCH_CHROMA = 0.37;
23
+ /**
24
+ * Emit an `oklch()` CSS string. The alpha component is omitted when a===100.
25
+ */
26
+ export declare function oklchaToCss(o: Oklcha): string;
27
+ /**
28
+ * Parse a hex string (#RGB / #RGBA / #RRGGBB / #RRGGBBAA) to Oklcha.
29
+ * Returns `{l:0, c:0, h:0, a:100}` for invalid input — never throws.
30
+ */
31
+ export declare function hexToOklcha(hex: string): Oklcha;
32
+ /**
33
+ * Convert an Oklcha to a hex string.
34
+ * Emits 6-digit hex when a===100 (unless alwaysAlpha is set).
35
+ * Emits 8-digit hex when a<100 or alwaysAlpha is true.
36
+ */
37
+ export declare function oklchaToHex(o: Oklcha, opts?: {
38
+ alwaysAlpha?: boolean;
39
+ }): string;
40
+ /** Convert Oklcha to Hsla. Alpha is preserved on the 0–100 scale. */
41
+ export declare function oklchaToHsla(o: Oklcha): Hsla;
42
+ /** Convert Hsla to Oklcha. Alpha is preserved on the 0–100 scale. */
43
+ export declare function hslaToOklcha(h: Hsla): Oklcha;
44
+ /**
45
+ * Clamp an Oklcha value into the sRGB gamut while preserving L and H.
46
+ * Uses culori's `clampChroma` which reduces chroma until the color fits.
47
+ */
48
+ export declare function clampToSrgbGamut(o: Oklcha): Oklcha;
49
+ /** Return true if the Oklcha value is within the sRGB gamut. */
50
+ export declare function isInSrgbGamut(o: Oklcha): boolean;
51
+ //# sourceMappingURL=color-oklch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color-oklch.d.ts","sourceRoot":"","sources":["../../src/utils/color-oklch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAiBH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AASzC,YAAY,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEzC,iEAAiE;AACjE,MAAM,WAAW,MAAM;IACrB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,0DAA0D;AAC1D,eAAO,MAAM,gBAAgB,OAAO,CAAC;AAkDrC;;GAEG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAS7C;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAiB/C;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,CAAC,EAAE,MAAM,EACT,IAAI,CAAC,EAAE;IAAE,WAAW,CAAC,EAAE,OAAO,CAAA;CAAE,GAC/B,MAAM,CAQR;AAED,sEAAsE;AACtE,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAU5C;AAED,sEAAsE;AACtE,wBAAgB,YAAY,CAAC,CAAC,EAAE,IAAI,GAAG,MAAM,CAW5C;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAclD;AAED,gEAAgE;AAChE,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAIhD"}