@takazudo/zdtp 0.4.0 → 0.4.2
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.
- package/CHANGELOG.md +37 -0
- package/README.md +58 -10
- package/dist/apply/build-apply-overrides.d.ts +4 -2
- package/dist/apply/build-apply-overrides.d.ts.map +1 -1
- package/dist/astro/host-adapter.js +67 -44
- package/dist/astro/index.js +1 -1
- package/dist/autoload-state-DsvvPDih.js +46 -0
- package/dist/components/palette-chart/palette-chart.d.ts +0 -1
- package/dist/components/palette-chart/palette-chart.d.ts.map +1 -1
- package/dist/config/panel-config.d.ts +8 -0
- package/dist/config/panel-config.d.ts.map +1 -1
- package/dist/element-path/element-path-state.d.ts +3 -2
- package/dist/element-path/element-path-state.d.ts.map +1 -1
- package/dist/index.d.ts +39 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2596 -3626
- package/dist/{panel-config-066BPYJD.js → panel-config-DyVRQ2n1.js} +37 -33
- package/dist/panel.d.ts.map +1 -1
- package/dist/state/autoload-state.d.ts +92 -0
- package/dist/state/autoload-state.d.ts.map +1 -0
- package/dist/state/tweak-state.d.ts +18 -1
- package/dist/state/tweak-state.d.ts.map +1 -1
- package/dist/tabs/color-tab.d.ts +7 -4
- package/dist/tabs/color-tab.d.ts.map +1 -1
- package/dist/tabs/generic-tab.d.ts +1 -1
- package/dist/tabs/palette/palette-edit-view.d.ts +0 -1
- package/dist/tabs/palette/palette-edit-view.d.ts.map +1 -1
- package/dist/testing.js +2 -2
- package/dist/tweak-state-DzZVbY25.js +1779 -0
- package/dist/utils/design-token-serde.d.ts +2 -1
- package/dist/utils/design-token-serde.d.ts.map +1 -1
- package/dist/zdtp.css +1 -1
- package/package.json +1 -1
- package/dist/tweak-state-Do5gj6Nw.js +0 -730
|
@@ -1,730 +0,0 @@
|
|
|
1
|
-
import { g as d, r as w, d as ne, b as oe, f as re, j as se, i as ie, k as O, h as ae, l as ce, m as fe } from "./panel-config-066BPYJD.js";
|
|
2
|
-
class h extends Error {
|
|
3
|
-
constructor(t) {
|
|
4
|
-
super(t), this.name = "TierResolverError", Object.setPrototypeOf(this, h.prototype);
|
|
5
|
-
}
|
|
6
|
-
}
|
|
7
|
-
function D(e, t) {
|
|
8
|
-
return e.tiers.find((n) => n.id === t);
|
|
9
|
-
}
|
|
10
|
-
function S(e, t) {
|
|
11
|
-
return e.items.find((n) => n.id === t);
|
|
12
|
-
}
|
|
13
|
-
function E(e, t, n, r) {
|
|
14
|
-
const o = D(e, t);
|
|
15
|
-
if (!o)
|
|
16
|
-
throw new h(
|
|
17
|
-
`Tier "${t}" not found in tab "${e.id}". Available tiers: ${e.tiers.map((c) => c.id).join(", ")}.`
|
|
18
|
-
);
|
|
19
|
-
const s = S(o, n);
|
|
20
|
-
if (!s)
|
|
21
|
-
throw new h(
|
|
22
|
-
`Item "${n}" not found in tier "${t}" of tab "${e.id}".`
|
|
23
|
-
);
|
|
24
|
-
const a = r[t]?.[n];
|
|
25
|
-
if (o.referencesTier !== void 0) {
|
|
26
|
-
const c = o.referencesTier, l = D(e, c);
|
|
27
|
-
if (!l)
|
|
28
|
-
throw new h(
|
|
29
|
-
`Tier "${t}" declares referencesTier "${c}" but that tier does not exist in tab "${e.id}".`
|
|
30
|
-
);
|
|
31
|
-
const p = S(l, a ?? n);
|
|
32
|
-
if (!p) {
|
|
33
|
-
const u = S(l, s.default) ?? S(l, n) ?? l.items[0];
|
|
34
|
-
if (!u)
|
|
35
|
-
throw new h(
|
|
36
|
-
`Referenced tier "${c}" has no items; cannot resolve fallback for item "${n}" in tier "${t}" of tab "${e.id}".`
|
|
37
|
-
);
|
|
38
|
-
return { kind: "ref", targetCssVar: u.cssVar };
|
|
39
|
-
}
|
|
40
|
-
return { kind: "ref", targetCssVar: p.cssVar };
|
|
41
|
-
}
|
|
42
|
-
return a !== void 0 ? s.pill && a === s.pill.value ? { kind: "literal", value: s.pill.value } : { kind: "literal", value: a } : s.pill ? { kind: "literal", value: s.pill.customDefault } : { kind: "literal", value: s.default };
|
|
43
|
-
}
|
|
44
|
-
function j(e) {
|
|
45
|
-
return e.kind === "literal" ? e.value : `var(${e.targetCssVar})`;
|
|
46
|
-
}
|
|
47
|
-
function Y(e = d()) {
|
|
48
|
-
return ie(e);
|
|
49
|
-
}
|
|
50
|
-
function U(e = d()) {
|
|
51
|
-
return oe(e);
|
|
52
|
-
}
|
|
53
|
-
function _(e = d()) {
|
|
54
|
-
return ne(e);
|
|
55
|
-
}
|
|
56
|
-
function Ce(e = d()) {
|
|
57
|
-
return re(e);
|
|
58
|
-
}
|
|
59
|
-
function Z(e = d()) {
|
|
60
|
-
return ae(e);
|
|
61
|
-
}
|
|
62
|
-
function X(e = d()) {
|
|
63
|
-
return ce(e);
|
|
64
|
-
}
|
|
65
|
-
function q(e = d()) {
|
|
66
|
-
return fe(e);
|
|
67
|
-
}
|
|
68
|
-
const le = { top: 60, left: 20 };
|
|
69
|
-
function ue() {
|
|
70
|
-
if (typeof window > "u") return le;
|
|
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)), r = Math.max(0, Math.round((window.innerWidth - e) / 2));
|
|
72
|
-
return { top: n, left: r };
|
|
73
|
-
}
|
|
74
|
-
function Ae(e) {
|
|
75
|
-
try {
|
|
76
|
-
const t = localStorage.getItem(Z(e));
|
|
77
|
-
if (t) {
|
|
78
|
-
const n = JSON.parse(t);
|
|
79
|
-
if (typeof n.top == "number" && typeof n.left == "number")
|
|
80
|
-
return n;
|
|
81
|
-
}
|
|
82
|
-
} catch {
|
|
83
|
-
}
|
|
84
|
-
return ue();
|
|
85
|
-
}
|
|
86
|
-
function _e(e, t) {
|
|
87
|
-
try {
|
|
88
|
-
localStorage.setItem(Z(t), JSON.stringify(e));
|
|
89
|
-
} catch {
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
const I = 60, F = 320, R = 240, z = 1600, H = 1200, pe = { width: 1024 * 0.8, height: 768 * 0.8 };
|
|
93
|
-
function de() {
|
|
94
|
-
return typeof window > "u" ? pe : {
|
|
95
|
-
width: Math.min(1200, 0.8 * window.innerWidth),
|
|
96
|
-
height: Math.min(800, 0.8 * window.innerHeight)
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
const B = 32;
|
|
100
|
-
function me(e, t) {
|
|
101
|
-
const n = typeof window < "u" ? window.innerWidth : z, r = typeof window < "u" ? window.innerHeight : H, o = Math.max(F, Math.min(z, n - B)), s = Math.max(R, Math.min(H, r - B));
|
|
102
|
-
return {
|
|
103
|
-
width: Math.max(F, Math.min(e, o)),
|
|
104
|
-
height: Math.max(R, Math.min(t, s))
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
function Pe(e) {
|
|
108
|
-
try {
|
|
109
|
-
const t = localStorage.getItem(X(e));
|
|
110
|
-
if (t) {
|
|
111
|
-
const n = JSON.parse(t);
|
|
112
|
-
if (typeof n.width == "number" && typeof n.height == "number" && Number.isFinite(n.width) && Number.isFinite(n.height))
|
|
113
|
-
return me(n.width, n.height);
|
|
114
|
-
}
|
|
115
|
-
} catch {
|
|
116
|
-
}
|
|
117
|
-
return de();
|
|
118
|
-
}
|
|
119
|
-
function De(e, t) {
|
|
120
|
-
try {
|
|
121
|
-
localStorage.setItem(X(t), JSON.stringify(e));
|
|
122
|
-
} catch {
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
const ye = 1;
|
|
126
|
-
function Ee(e) {
|
|
127
|
-
return e === 0 ? "12rem" : e === 2 ? "100%" : "18rem";
|
|
128
|
-
}
|
|
129
|
-
function je(e) {
|
|
130
|
-
try {
|
|
131
|
-
const t = localStorage.getItem(q(e));
|
|
132
|
-
if (t === "0" || t === "1" || t === "2")
|
|
133
|
-
return Number(t);
|
|
134
|
-
} catch {
|
|
135
|
-
}
|
|
136
|
-
return ye;
|
|
137
|
-
}
|
|
138
|
-
function Fe(e, t) {
|
|
139
|
-
try {
|
|
140
|
-
localStorage.setItem(q(t), String(e));
|
|
141
|
-
} catch {
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
function Re(e, t, n, r) {
|
|
145
|
-
const o = -(n - I), s = window.innerWidth - I, i = -30, a = window.innerHeight - I, c = Math.max(a, i), l = Math.max(s, o);
|
|
146
|
-
return {
|
|
147
|
-
top: Math.max(i, Math.min(e, c)),
|
|
148
|
-
left: Math.max(o, Math.min(t, l))
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
async function ze(e) {
|
|
152
|
-
}
|
|
153
|
-
function M() {
|
|
154
|
-
return {};
|
|
155
|
-
}
|
|
156
|
-
const ge = {
|
|
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 y(e = d()) {
|
|
170
|
-
return se(e.tabs) ?? ge;
|
|
171
|
-
}
|
|
172
|
-
function P(e) {
|
|
173
|
-
const t = Math.max(1, e.paletteSize);
|
|
174
|
-
return {
|
|
175
|
-
palette: Array.from({ length: t }, (r, o) => {
|
|
176
|
-
if (t === 1) return "#808080";
|
|
177
|
-
const i = Math.round(o / (t - 1) * 255).toString(16).padStart(2, "0");
|
|
178
|
-
return `#${i}${i}${i}`;
|
|
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 He(e) {
|
|
190
|
-
const t = w(e);
|
|
191
|
-
return t ? P(t) : void 0;
|
|
192
|
-
}
|
|
193
|
-
function he() {
|
|
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 be = he();
|
|
202
|
-
function Se(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), r = parseInt(t[2], 10), o = parseInt(t[3], 10), s = `#${(1 << 24 | n << 16 | r << 8 | o).toString(16).slice(1)}`;
|
|
206
|
-
if (t[4] !== void 0) {
|
|
207
|
-
const i = parseFloat(t[4]);
|
|
208
|
-
if (i < 1) {
|
|
209
|
-
const a = Math.round(i * 255).toString(16).padStart(2, "0");
|
|
210
|
-
return `${s}${a}`;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
return s;
|
|
214
|
-
}
|
|
215
|
-
function ve(e, t, n, r) {
|
|
216
|
-
const o = (i) => i.toString(16).padStart(2, "0"), s = `#${o(e)}${o(t)}${o(n)}`;
|
|
217
|
-
return r < 255 ? `${s}${o(r)}` : s;
|
|
218
|
-
}
|
|
219
|
-
let m = null;
|
|
220
|
-
function N(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 = Se(t);
|
|
229
|
-
if (n) return n;
|
|
230
|
-
if (!be) return "#000000";
|
|
231
|
-
try {
|
|
232
|
-
if (m || (m = document.createElement("canvas").getContext("2d")), !m) return "#000000";
|
|
233
|
-
m.fillStyle = "#000000", m.fillStyle = t, m.clearRect(0, 0, 1, 1), m.fillRect(0, 0, 1, 1);
|
|
234
|
-
const [r, o, s, i] = m.getImageData(0, 0, 1, 1).data;
|
|
235
|
-
return ve(r, o, s, i);
|
|
236
|
-
} catch {
|
|
237
|
-
return "#000000";
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
function k(e, t) {
|
|
241
|
-
document.documentElement.style.setProperty(e, t);
|
|
242
|
-
}
|
|
243
|
-
function g(e, t, n) {
|
|
244
|
-
if (e === void 0) return n;
|
|
245
|
-
if (typeof e == "number") return e;
|
|
246
|
-
const r = N(e), o = t.map((f) => N(f)), s = t.indexOf(e);
|
|
247
|
-
if (s >= 0) return s;
|
|
248
|
-
const i = o.indexOf(r);
|
|
249
|
-
if (i >= 0) return i;
|
|
250
|
-
const a = K(r);
|
|
251
|
-
let c = n, l = 1 / 0;
|
|
252
|
-
for (let f = 0; f < o.length; f++) {
|
|
253
|
-
const p = K(o[f]), u = (a.r - p.r) ** 2 + (a.g - p.g) ** 2 + (a.b - p.b) ** 2;
|
|
254
|
-
u < l && (l = u, c = f);
|
|
255
|
-
}
|
|
256
|
-
return c;
|
|
257
|
-
}
|
|
258
|
-
function K(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 ke(e = y(), t) {
|
|
268
|
-
const n = e.panelSettings;
|
|
269
|
-
if (n.colorMode) {
|
|
270
|
-
const r = document.documentElement.getAttribute("data-theme");
|
|
271
|
-
if (r === "light") return n.colorMode.lightScheme;
|
|
272
|
-
if (r === "dark") return n.colorMode.darkScheme;
|
|
273
|
-
}
|
|
274
|
-
return n.colorScheme;
|
|
275
|
-
}
|
|
276
|
-
function Oe(e = y()) {
|
|
277
|
-
const t = e.colorSchemes;
|
|
278
|
-
if (Object.keys(t).length === 0)
|
|
279
|
-
return P(e);
|
|
280
|
-
const n = ke(e), r = t[n] ?? Object.values(t)[0];
|
|
281
|
-
return we(r, e);
|
|
282
|
-
}
|
|
283
|
-
function we(e, t = y()) {
|
|
284
|
-
const n = e.palette.map((o) => N(o)), r = {};
|
|
285
|
-
for (const [o, s] of Object.entries(t.semanticDefaults)) {
|
|
286
|
-
const i = e.semantic?.[o];
|
|
287
|
-
i === void 0 ? r[o] = s : typeof i == "number" ? r[o] = i : r[o] = g(i, e.palette, s);
|
|
288
|
-
}
|
|
289
|
-
return {
|
|
290
|
-
palette: n,
|
|
291
|
-
background: g(
|
|
292
|
-
e.background,
|
|
293
|
-
e.palette,
|
|
294
|
-
t.baseDefaults.background ?? 0
|
|
295
|
-
),
|
|
296
|
-
foreground: g(
|
|
297
|
-
e.foreground,
|
|
298
|
-
e.palette,
|
|
299
|
-
t.baseDefaults.foreground ?? 0
|
|
300
|
-
),
|
|
301
|
-
cursor: g(e.cursor, e.palette, t.baseDefaults.cursor ?? 0),
|
|
302
|
-
selectionBg: g(
|
|
303
|
-
e.selectionBg,
|
|
304
|
-
e.palette,
|
|
305
|
-
t.baseDefaults.selectionBg ?? 0
|
|
306
|
-
),
|
|
307
|
-
selectionFg: g(
|
|
308
|
-
e.selectionFg,
|
|
309
|
-
e.palette,
|
|
310
|
-
t.baseDefaults.selectionFg ?? 0
|
|
311
|
-
),
|
|
312
|
-
semanticMappings: r,
|
|
313
|
-
shikiTheme: String(e.shikiTheme ?? t.defaultShikiTheme)
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
function L(e, t, n, r) {
|
|
317
|
-
const o = t.length;
|
|
318
|
-
return e === "bg" ? t[b(n, o)] ?? "#000000" : e === "fg" ? t[b(r, o)] ?? "#ffffff" : t[b(e, o)] ?? "#000000";
|
|
319
|
-
}
|
|
320
|
-
function b(e, t) {
|
|
321
|
-
return e >= 0 && e < t ? e : 0;
|
|
322
|
-
}
|
|
323
|
-
function J(e, t = y(), n) {
|
|
324
|
-
const r = e.palette.length;
|
|
325
|
-
if (n) {
|
|
326
|
-
const o = [];
|
|
327
|
-
for (let s = 0; s < r; s++)
|
|
328
|
-
o.push([O(t, s), e.palette[s]]);
|
|
329
|
-
for (const [s, i] of Object.entries(t.baseRoles)) {
|
|
330
|
-
if (typeof i != "string" || i.length === 0) continue;
|
|
331
|
-
const a = e[s];
|
|
332
|
-
typeof a == "number" && o.push([i, e.palette[b(a, r)]]);
|
|
333
|
-
}
|
|
334
|
-
for (const [s, i] of Object.entries(t.semanticCssNames)) {
|
|
335
|
-
const a = e.semanticMappings[s] ?? t.semanticDefaults[s];
|
|
336
|
-
o.push([i, L(a, e.palette, e.background, e.foreground)]);
|
|
337
|
-
}
|
|
338
|
-
try {
|
|
339
|
-
n.apply(o);
|
|
340
|
-
} catch (s) {
|
|
341
|
-
console.warn("[design-token-panel] applySink.apply threw; falling back silently.", s);
|
|
342
|
-
}
|
|
343
|
-
return;
|
|
344
|
-
}
|
|
345
|
-
for (let o = 0; o < r; o++)
|
|
346
|
-
k(O(t, o), e.palette[o]);
|
|
347
|
-
for (const [o, s] of Object.entries(t.baseRoles)) {
|
|
348
|
-
if (typeof s != "string" || s.length === 0) continue;
|
|
349
|
-
const i = e[o];
|
|
350
|
-
typeof i == "number" && k(s, e.palette[b(i, r)]);
|
|
351
|
-
}
|
|
352
|
-
for (const [o, s] of Object.entries(t.semanticCssNames)) {
|
|
353
|
-
const i = e.semanticMappings[o] ?? t.semanticDefaults[o];
|
|
354
|
-
k(s, L(i, e.palette, e.background, e.foreground));
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
function Be(e, t) {
|
|
358
|
-
const n = t ?? d(), r = n.applySink;
|
|
359
|
-
J(e.color, y(n), r), v(n.tabs, "spacing", e.spacing, r), v(n.tabs, "font", e.typography, r), v(n.tabs, "size", e.size, r);
|
|
360
|
-
const o = w(n);
|
|
361
|
-
if (o && e.secondary && J(e.secondary, o, r), e.tabs)
|
|
362
|
-
for (const [s, i] of Object.entries(e.tabs)) {
|
|
363
|
-
const a = {};
|
|
364
|
-
for (const c of Object.values(i))
|
|
365
|
-
for (const [l, f] of Object.entries(c))
|
|
366
|
-
a[l] = f;
|
|
367
|
-
v(n.tabs, s, a, r);
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
function v(e, t, n, r) {
|
|
371
|
-
const o = e.find((a) => a.id === t);
|
|
372
|
-
if (!o) return;
|
|
373
|
-
const s = {};
|
|
374
|
-
for (const a of o.tiers) {
|
|
375
|
-
const c = {};
|
|
376
|
-
for (const l of a.items) {
|
|
377
|
-
const f = n[l.id];
|
|
378
|
-
typeof f == "string" && f.length > 0 && (c[l.id] = f);
|
|
379
|
-
}
|
|
380
|
-
s[a.id] = c;
|
|
381
|
-
}
|
|
382
|
-
if (r) {
|
|
383
|
-
const a = [], c = [];
|
|
384
|
-
for (const l of o.tiers)
|
|
385
|
-
for (const f of l.items)
|
|
386
|
-
if (!f.readonly)
|
|
387
|
-
try {
|
|
388
|
-
const p = E(o, l.id, f.id, s), u = j(p);
|
|
389
|
-
typeof n[f.id] == "string" && n[f.id].length > 0 || l.referencesTier !== void 0 ? a.push([f.cssVar, u]) : c.push(f.cssVar);
|
|
390
|
-
} catch {
|
|
391
|
-
c.push(f.cssVar);
|
|
392
|
-
}
|
|
393
|
-
if (a.length > 0)
|
|
394
|
-
try {
|
|
395
|
-
r.apply(a);
|
|
396
|
-
} catch (l) {
|
|
397
|
-
console.warn("[design-token-panel] applySink.apply threw; falling back silently.", l);
|
|
398
|
-
}
|
|
399
|
-
if (c.length > 0)
|
|
400
|
-
try {
|
|
401
|
-
r.clear(c);
|
|
402
|
-
} catch (l) {
|
|
403
|
-
console.warn("[design-token-panel] applySink.clear threw; falling back silently.", l);
|
|
404
|
-
}
|
|
405
|
-
return;
|
|
406
|
-
}
|
|
407
|
-
const i = document.documentElement;
|
|
408
|
-
for (const a of o.tiers)
|
|
409
|
-
for (const c of a.items)
|
|
410
|
-
if (!c.readonly)
|
|
411
|
-
try {
|
|
412
|
-
const l = E(o, a.id, c.id, s), f = j(l);
|
|
413
|
-
typeof n[c.id] == "string" && n[c.id].length > 0 || a.referencesTier !== void 0 ? k(c.cssVar, f) : i.style.removeProperty(c.cssVar);
|
|
414
|
-
} catch {
|
|
415
|
-
i.style.removeProperty(c.cssVar);
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
function Q(e) {
|
|
419
|
-
const t = e ?? d(), n = y(t), r = w(t);
|
|
420
|
-
return r ? [n, r] : [n];
|
|
421
|
-
}
|
|
422
|
-
function ee(e) {
|
|
423
|
-
const t = [];
|
|
424
|
-
for (let n = 0; n < e.paletteSize; n++)
|
|
425
|
-
t.push(O(e, n));
|
|
426
|
-
for (const n of Object.values(e.baseRoles))
|
|
427
|
-
typeof n == "string" && n.length > 0 && t.push(n);
|
|
428
|
-
for (const n of Object.values(e.semanticCssNames))
|
|
429
|
-
t.push(n);
|
|
430
|
-
return t;
|
|
431
|
-
}
|
|
432
|
-
function Te(e) {
|
|
433
|
-
const t = [];
|
|
434
|
-
for (const n of e.tabs)
|
|
435
|
-
if (!(n.id === "color" || n.id === "color-secondary"))
|
|
436
|
-
for (const r of n.tiers)
|
|
437
|
-
for (const o of r.items)
|
|
438
|
-
o.readonly || t.push(o.cssVar);
|
|
439
|
-
return t;
|
|
440
|
-
}
|
|
441
|
-
function xe(e, t, n) {
|
|
442
|
-
const r = e ?? Q(n), o = n?.applySink;
|
|
443
|
-
return Ie(r, o);
|
|
444
|
-
}
|
|
445
|
-
function Ie(e, t) {
|
|
446
|
-
if (t) {
|
|
447
|
-
const r = [];
|
|
448
|
-
for (const o of e)
|
|
449
|
-
r.push(...ee(o));
|
|
450
|
-
if (r.length > 0)
|
|
451
|
-
try {
|
|
452
|
-
t.clear(r);
|
|
453
|
-
} catch (o) {
|
|
454
|
-
console.warn("[design-token-panel] applySink.clear threw; falling back silently.", o);
|
|
455
|
-
}
|
|
456
|
-
return;
|
|
457
|
-
}
|
|
458
|
-
const n = document.documentElement;
|
|
459
|
-
for (const r of e) {
|
|
460
|
-
for (let o = 0; o < r.paletteSize; o++)
|
|
461
|
-
n.style.removeProperty(O(r, o));
|
|
462
|
-
for (const o of Object.values(r.baseRoles))
|
|
463
|
-
n.style.removeProperty(o);
|
|
464
|
-
for (const o of Object.values(r.semanticCssNames))
|
|
465
|
-
n.style.removeProperty(o);
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
function Ke(e, t) {
|
|
469
|
-
const n = t ?? d(), r = n.applySink, o = Q(n);
|
|
470
|
-
if (r) {
|
|
471
|
-
const i = [];
|
|
472
|
-
for (const a of o)
|
|
473
|
-
i.push(...ee(a));
|
|
474
|
-
if (i.push(...Te(n)), i.length > 0)
|
|
475
|
-
try {
|
|
476
|
-
r.clear(i);
|
|
477
|
-
} catch (a) {
|
|
478
|
-
console.warn("[design-token-panel] applySink.clear threw; falling back silently.", a);
|
|
479
|
-
}
|
|
480
|
-
return;
|
|
481
|
-
}
|
|
482
|
-
xe(o);
|
|
483
|
-
const s = document.documentElement;
|
|
484
|
-
for (const i of n.tabs)
|
|
485
|
-
if (!(i.id === "color" || i.id === "color-secondary"))
|
|
486
|
-
for (const a of i.tiers)
|
|
487
|
-
for (const c of a.items)
|
|
488
|
-
c.readonly || s.style.removeProperty(c.cssVar);
|
|
489
|
-
}
|
|
490
|
-
function C(e, t) {
|
|
491
|
-
if (!e || typeof e != "object") return !1;
|
|
492
|
-
const n = e;
|
|
493
|
-
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;
|
|
494
|
-
}
|
|
495
|
-
function A(e, t) {
|
|
496
|
-
const n = Array.isArray(e.palette) ? e.palette : null;
|
|
497
|
-
let r;
|
|
498
|
-
return n && n.length === t.palette.length && n.every((o) => typeof o == "string") ? r = n : (n && n.some((o) => typeof o != "string") && console.error(
|
|
499
|
-
"[design-token-panel] Persisted palette contained non-string elements; falling back to defaults."
|
|
500
|
-
), r = t.palette), {
|
|
501
|
-
palette: r,
|
|
502
|
-
background: typeof e.background == "number" ? e.background : t.background,
|
|
503
|
-
foreground: typeof e.foreground == "number" ? e.foreground : t.foreground,
|
|
504
|
-
cursor: typeof e.cursor == "number" ? e.cursor : t.cursor,
|
|
505
|
-
selectionBg: typeof e.selectionBg == "number" ? e.selectionBg : t.selectionBg,
|
|
506
|
-
selectionFg: typeof e.selectionFg == "number" ? e.selectionFg : t.selectionFg,
|
|
507
|
-
semanticMappings: e.semanticMappings && typeof e.semanticMappings == "object" ? { ...t.semanticMappings, ...e.semanticMappings } : t.semanticMappings,
|
|
508
|
-
shikiTheme: typeof e.shikiTheme == "string" && e.shikiTheme.length > 0 ? e.shikiTheme : t.shikiTheme
|
|
509
|
-
};
|
|
510
|
-
}
|
|
511
|
-
const Le = {
|
|
512
|
-
"text-caption": "text-xs",
|
|
513
|
-
"text-small": "text-sm",
|
|
514
|
-
"text-body": "text-base",
|
|
515
|
-
"text-subheading": "text-lg",
|
|
516
|
-
"text-heading": "text-3xl",
|
|
517
|
-
"text-display": "text-5xl",
|
|
518
|
-
// Dropped — no main-site equivalent. `null` signals "discard".
|
|
519
|
-
"text-micro": null
|
|
520
|
-
};
|
|
521
|
-
function W(e) {
|
|
522
|
-
if (!e || typeof e != "object") return {};
|
|
523
|
-
const t = {};
|
|
524
|
-
for (const [n, r] of Object.entries(e))
|
|
525
|
-
typeof r == "string" && (t[n] = r);
|
|
526
|
-
return t;
|
|
527
|
-
}
|
|
528
|
-
function Me(e, t = {}) {
|
|
529
|
-
if (!e || typeof e != "object") return {};
|
|
530
|
-
const n = {};
|
|
531
|
-
for (const [r, o] of Object.entries(e))
|
|
532
|
-
if (typeof o == "string")
|
|
533
|
-
if (Object.hasOwn(t, r)) {
|
|
534
|
-
const s = t[r];
|
|
535
|
-
if (s === null) continue;
|
|
536
|
-
Object.hasOwn(n, s) || (n[s] = o);
|
|
537
|
-
} else
|
|
538
|
-
n[r] = o;
|
|
539
|
-
return n;
|
|
540
|
-
}
|
|
541
|
-
function $e(e) {
|
|
542
|
-
if (!e || typeof e != "object") return;
|
|
543
|
-
const t = e;
|
|
544
|
-
if (typeof t.top == "number" && typeof t.left == "number" && Number.isFinite(t.top) && Number.isFinite(t.left))
|
|
545
|
-
return { top: t.top, left: t.left };
|
|
546
|
-
}
|
|
547
|
-
function Ve(e) {
|
|
548
|
-
if (!e || typeof e != "object" || Array.isArray(e)) return {};
|
|
549
|
-
const t = {};
|
|
550
|
-
for (const [n, r] of Object.entries(e)) {
|
|
551
|
-
if (!r || typeof r != "object" || Array.isArray(r)) continue;
|
|
552
|
-
const o = {};
|
|
553
|
-
for (const [s, i] of Object.entries(r)) {
|
|
554
|
-
if (!i || typeof i != "object" || Array.isArray(i)) continue;
|
|
555
|
-
const a = {};
|
|
556
|
-
for (const [c, l] of Object.entries(i))
|
|
557
|
-
typeof l == "string" && (a[c] = l);
|
|
558
|
-
o[s] = a;
|
|
559
|
-
}
|
|
560
|
-
t[n] = o;
|
|
561
|
-
}
|
|
562
|
-
return t;
|
|
563
|
-
}
|
|
564
|
-
function G(e, t, n, r = d()) {
|
|
565
|
-
if (!e.color || !C(e.color, t.paletteSize)) return null;
|
|
566
|
-
const o = n ?? te(t), s = e.typography !== void 0 ? e.typography : e.font, i = r.legacyIdRenameMap ?? {}, a = {
|
|
567
|
-
color: A(e.color, o),
|
|
568
|
-
// New sections added after v1 migration — tolerate their absence so
|
|
569
|
-
// older v2 payloads (Color-only) still load cleanly.
|
|
570
|
-
spacing: W(e.spacing),
|
|
571
|
-
// Typography slice: apply the host-configured rename map (if any)
|
|
572
|
-
// so payloads persisted under the host's "old" ids survive a
|
|
573
|
-
// host-driven id rename without losing the user's tweaks.
|
|
574
|
-
typography: Me(s, i),
|
|
575
|
-
size: W(e.size),
|
|
576
|
-
panelPosition: $e(e.panelPosition)
|
|
577
|
-
}, c = w(r);
|
|
578
|
-
c && e.secondary && C(e.secondary, c.paletteSize) && (a.secondary = A(
|
|
579
|
-
e.secondary,
|
|
580
|
-
P(c)
|
|
581
|
-
));
|
|
582
|
-
const l = Ve(e.tabs);
|
|
583
|
-
return Object.keys(l).length > 0 && (a.tabs = l), a;
|
|
584
|
-
}
|
|
585
|
-
function Je(e = localStorage, t, n = y(), r = d()) {
|
|
586
|
-
const o = Y(r), s = U(r), i = _(r), a = $(e, i);
|
|
587
|
-
if (a !== null) {
|
|
588
|
-
const f = V(a);
|
|
589
|
-
if (f && typeof f == "object") {
|
|
590
|
-
const p = f, u = G(p, n, t, r);
|
|
591
|
-
if (u !== null) {
|
|
592
|
-
const T = p.typography !== void 0 ? p.typography : p.font;
|
|
593
|
-
if (JSON.stringify(T ?? {}) !== JSON.stringify(u.typography) || p.typography === void 0)
|
|
594
|
-
try {
|
|
595
|
-
e.setItem(i, JSON.stringify(u));
|
|
596
|
-
} catch {
|
|
597
|
-
}
|
|
598
|
-
return u;
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
console.warn(`[tweak] Malformed ${i}, attempting v2 migration`);
|
|
602
|
-
}
|
|
603
|
-
const c = $(e, s);
|
|
604
|
-
if (c !== null) {
|
|
605
|
-
const f = V(c);
|
|
606
|
-
if (f && typeof f == "object") {
|
|
607
|
-
const u = G(f, n, t, r);
|
|
608
|
-
if (u !== null) {
|
|
609
|
-
try {
|
|
610
|
-
e.setItem(i, JSON.stringify(u)), e.removeItem(s);
|
|
611
|
-
} catch {
|
|
612
|
-
}
|
|
613
|
-
return u;
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
console.warn(`[tweak] Malformed ${s}, attempting v1 migration`);
|
|
617
|
-
}
|
|
618
|
-
const l = $(e, o);
|
|
619
|
-
if (l !== null) {
|
|
620
|
-
const f = V(l);
|
|
621
|
-
if (f && typeof f == "object" && C(f, n.paletteSize)) {
|
|
622
|
-
const p = t ?? te(n), u = f;
|
|
623
|
-
u.shikiTheme || (u.shikiTheme = p.shikiTheme);
|
|
624
|
-
const x = {
|
|
625
|
-
color: A(u, p),
|
|
626
|
-
spacing: M(),
|
|
627
|
-
typography: M(),
|
|
628
|
-
size: M()
|
|
629
|
-
};
|
|
630
|
-
try {
|
|
631
|
-
e.setItem(i, JSON.stringify(x)), e.removeItem(o);
|
|
632
|
-
} catch {
|
|
633
|
-
}
|
|
634
|
-
return x;
|
|
635
|
-
}
|
|
636
|
-
console.warn(`[tweak] Malformed ${o}; discarding and using fresh defaults`);
|
|
637
|
-
try {
|
|
638
|
-
e.removeItem(o);
|
|
639
|
-
} catch {
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
return null;
|
|
643
|
-
}
|
|
644
|
-
function We(e, t = localStorage, n = d()) {
|
|
645
|
-
try {
|
|
646
|
-
t.setItem(_(n), JSON.stringify(e));
|
|
647
|
-
} catch {
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
function Ge(e = localStorage, t = d()) {
|
|
651
|
-
try {
|
|
652
|
-
e.removeItem(_(t));
|
|
653
|
-
} catch {
|
|
654
|
-
}
|
|
655
|
-
try {
|
|
656
|
-
e.removeItem(U(t));
|
|
657
|
-
} catch {
|
|
658
|
-
}
|
|
659
|
-
try {
|
|
660
|
-
e.removeItem(Y(t));
|
|
661
|
-
} catch {
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
function $(e, t) {
|
|
665
|
-
try {
|
|
666
|
-
return e.getItem(t);
|
|
667
|
-
} catch {
|
|
668
|
-
return null;
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
function V(e) {
|
|
672
|
-
try {
|
|
673
|
-
return JSON.parse(e);
|
|
674
|
-
} catch {
|
|
675
|
-
return null;
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
function te(e) {
|
|
679
|
-
try {
|
|
680
|
-
return Oe(e);
|
|
681
|
-
} catch {
|
|
682
|
-
return {
|
|
683
|
-
palette: Array.from(
|
|
684
|
-
{ length: e.paletteSize },
|
|
685
|
-
(n, r) => r === 0 ? "#000000" : r === e.paletteSize - 1 ? "#ffffff" : "#808080"
|
|
686
|
-
),
|
|
687
|
-
background: e.baseDefaults.background ?? 0,
|
|
688
|
-
foreground: e.baseDefaults.foreground ?? 0,
|
|
689
|
-
cursor: e.baseDefaults.cursor ?? 0,
|
|
690
|
-
selectionBg: e.baseDefaults.selectionBg ?? 0,
|
|
691
|
-
selectionFg: e.baseDefaults.selectionFg ?? 0,
|
|
692
|
-
semanticMappings: { ...e.semanticDefaults },
|
|
693
|
-
shikiTheme: e.defaultShikiTheme
|
|
694
|
-
};
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
export {
|
|
698
|
-
Re as A,
|
|
699
|
-
me as B,
|
|
700
|
-
M as C,
|
|
701
|
-
le as D,
|
|
702
|
-
_ as E,
|
|
703
|
-
Le as Z,
|
|
704
|
-
U as a,
|
|
705
|
-
y as b,
|
|
706
|
-
ze as c,
|
|
707
|
-
Be as d,
|
|
708
|
-
j as e,
|
|
709
|
-
We as f,
|
|
710
|
-
Y as g,
|
|
711
|
-
de as h,
|
|
712
|
-
we as i,
|
|
713
|
-
ye as j,
|
|
714
|
-
Ce as k,
|
|
715
|
-
Je as l,
|
|
716
|
-
Ae as m,
|
|
717
|
-
Pe as n,
|
|
718
|
-
je as o,
|
|
719
|
-
Fe as p,
|
|
720
|
-
Ge as q,
|
|
721
|
-
E as r,
|
|
722
|
-
b as s,
|
|
723
|
-
Ke as t,
|
|
724
|
-
He as u,
|
|
725
|
-
Ee as v,
|
|
726
|
-
Oe as w,
|
|
727
|
-
xe as x,
|
|
728
|
-
_e as y,
|
|
729
|
-
De as z
|
|
730
|
-
};
|