@takazudo/zdtp 0.2.2 → 0.3.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.
@@ -65,18 +65,25 @@
65
65
  * Read-only manifest tokens are skipped in both directions.
66
66
  */
67
67
  import type { ColorTweakState, TweakState } from '../state/tweak-state';
68
+ import { type PanelConfig } from '../config/panel-config';
68
69
  /** The canonical v2 schema identifier emitted by serialize(). */
69
70
  export declare const SCHEMA_V2 = "zudo-design-tokens/v2";
70
71
  /** The legacy v1 schema identifier accepted by deserialize() for back-compat. */
71
72
  export declare const SCHEMA_V1 = "zudo-design-tokens/v1";
72
73
  /**
73
- * Read the active design-token schema id at call time.
74
+ * Read the design-token schema id at call time.
74
75
  *
75
- * Returns the host-configured schema id from `panelConfig.schemaId`. Used as
76
- * the `$schema` value in legacy v1 exports (for hosts that have not upgraded
77
- * their config to v2). The canonical v2 serialize path always emits `SCHEMA_V2`.
76
+ * Returns the host-configured schema id from `cfg.schemaId`. Used as the
77
+ * `$schema` value in legacy v1 exports (for hosts that have not upgraded their
78
+ * config to v2) and as the expected-schema label the Import modal surfaces. The
79
+ * canonical v2 serialize path always emits `SCHEMA_V2`.
80
+ *
81
+ * `cfg` defaults to the active (most-recently-configured) instance so the
82
+ * single-default path stays byte-identical. The Import modal threads its OWN
83
+ * mounted instance config (multi-instance, #361) so a non-default panel
84
+ * validates against ITS schema id, not the default's.
78
85
  */
79
- export declare function getDesignTokenSchema(): string;
86
+ export declare function getDesignTokenSchema(cfg?: PanelConfig): string;
80
87
  /** External JSON value for a base-color / semantic-color entry (v1). */
81
88
  type ColorSlotValue = number | 'bg' | 'fg';
82
89
  export interface DesignTokenJsonColorBase {
@@ -169,8 +176,14 @@ export declare class DesignTokenSchemaError extends Error {
169
176
  * defaults; set `opts.includeDefaults = true` to dump everything.
170
177
  *
171
178
  * The output `$schema` is always `SCHEMA_V2` ("zudo-design-tokens/v2").
179
+ *
180
+ * `cfg` defaults to the active (most-recently-configured) instance so the
181
+ * single-default path stays byte-identical. The Export / Apply modals thread
182
+ * their OWN mounted instance config (multi-instance, #361) so a non-default
183
+ * panel's export JSON / revert blob is built from ITS tab manifest + color
184
+ * cluster, not the default instance's.
172
185
  */
173
- export declare function serialize(state: TweakState, opts?: SerializeOptions): DesignTokenJsonV2;
186
+ export declare function serialize(state: TweakState, opts?: SerializeOptions, cfg?: PanelConfig): DesignTokenJsonV2;
174
187
  /**
175
188
  * Parse a design-token JSON document and lift it back into a tweak state.
176
189
  *
@@ -187,7 +200,13 @@ export declare function serialize(state: TweakState, opts?: SerializeOptions): D
187
200
  *
188
201
  * Missing fields fall back to `opts.colorDefaults` (or, absent that, a
189
202
  * minimal neutral default) so the result is always a valid `TweakState`.
203
+ *
204
+ * `cfg` defaults to the active (most-recently-configured) instance so the
205
+ * single-default path stays byte-identical. The Import modal threads its OWN
206
+ * mounted instance config (multi-instance, #361) so a non-default panel's
207
+ * schema-check + cssVar→id mapping use ITS tab manifest + color cluster, not
208
+ * the default instance's.
190
209
  */
191
- export declare function deserialize(input: unknown, opts?: DeserializeOptions): DeserializeResult;
210
+ export declare function deserialize(input: unknown, opts?: DeserializeOptions, cfg?: PanelConfig): DeserializeResult;
192
211
  export {};
193
212
  //# sourceMappingURL=design-token-serde.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"design-token-serde.d.ts","sourceRoot":"","sources":["../../src/utils/design-token-serde.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAkB,UAAU,EAAE,MAAM,sBAAsB,CAAC;AA4BxF,iEAAiE;AACjE,eAAO,MAAM,SAAS,0BAA0B,CAAC;AAEjD,iFAAiF;AACjF,eAAO,MAAM,SAAS,0BAA0B,CAAC;AAWjD;;;;;;GAMG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAE7C;A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;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,OAAO,EACd,IAAI,GAAE,kBAAuB,EAC7B,GAAG,GAAE,WAA8B,GAClC,iBAAiB,CA4BnB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takazudo/zdtp",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Dynamic design-token tweak panel — host-config-driven, framework-agnostic Preact UI.",
5
5
  "private": false,
6
6
  "license": "MIT",
@@ -1,624 +0,0 @@
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
- };