@takazudo/zdtp 0.4.13 → 0.4.15

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 (113) hide show
  1. package/CHANGELOG.md +143 -0
  2. package/PORTABLE-CONTRACT.md +366 -94
  3. package/README.md +218 -96
  4. package/dist/apply/build-apply-overrides.d.ts +2 -2
  5. package/dist/apply/compute-hunks.d.ts +23 -0
  6. package/dist/apply/last-applied.d.ts +5 -0
  7. package/dist/apply/reconcile-applied.d.ts +19 -0
  8. package/dist/apply-modal.d.ts +2 -48
  9. package/dist/astro/host-adapter.js +3 -3
  10. package/dist/astro/index.js +2 -2
  11. package/dist/{autoload-state-CfL2VUe1.js → autoload-state-7BQYXI7Y.js} +1 -1
  12. package/dist/bin/server.js +52 -50
  13. package/dist/bulk/bulk-actions.d.ts +45 -0
  14. package/dist/bulk/index.d.ts +2 -0
  15. package/dist/chain/index.d.ts +2 -0
  16. package/dist/chain/token-chain-context.d.ts +19 -0
  17. package/dist/chain/token-chain-popover.d.ts +22 -0
  18. package/dist/changed/contribution.d.ts +32 -0
  19. package/dist/changed/footer-content.d.ts +16 -0
  20. package/dist/changed/index.d.ts +4 -0
  21. package/dist/changed/tab-badge.d.ts +8 -0
  22. package/dist/changed/tab-filter.d.ts +8 -0
  23. package/dist/config/panel-config.d.ts +22 -25
  24. package/dist/controls/actions-menu-popover.d.ts +2 -0
  25. package/dist/controls/role-button.d.ts +5 -2
  26. package/dist/controls/tooltip.d.ts +8 -4
  27. package/dist/element-inspect/element-inspect-context.d.ts +22 -0
  28. package/dist/element-inspect/element-inspect-orchestrator.d.ts +17 -0
  29. package/dist/element-inspect/element-inspect-overlay.d.ts +16 -0
  30. package/dist/element-inspect/element-inspect-toggle-button.d.ts +3 -0
  31. package/dist/element-inspect/element-inspect-view.d.ts +6 -0
  32. package/dist/element-inspect/find-tokens-for-element.d.ts +23 -0
  33. package/dist/element-inspect/index.d.ts +8 -0
  34. package/dist/highlight/find-elements.d.ts +14 -3
  35. package/dist/highlight/highlight-orchestrator.d.ts +7 -3
  36. package/dist/highlight/highlight-state.d.ts +3 -2
  37. package/dist/highlight/highlight-toggle-button.d.ts +3 -0
  38. package/dist/highlight/walk-css-rules.d.ts +2 -0
  39. package/dist/history/buttons.d.ts +28 -0
  40. package/dist/history/index.d.ts +3 -0
  41. package/dist/history/rail.d.ts +13 -0
  42. package/dist/history/snapshots.d.ts +57 -0
  43. package/dist/host/host-mutations.d.ts +23 -0
  44. package/dist/index-BOOmFtJh.js +12165 -0
  45. package/dist/{index-BAY1JOUl.js → index-C2DIYD0d.js} +2 -2
  46. package/dist/index.js +14 -14
  47. package/dist/load-routing-BtCE1hGI.js +547 -0
  48. package/dist/{manifest-DCReQE0k.js → manifest-DvuKi7I4.js} +11 -7
  49. package/dist/{panel-config-COHesW2B.js → panel-config-CRf-ONSV.js} +404 -308
  50. package/dist/picker/alt-click-picker.d.ts +10 -2
  51. package/dist/picker/arming-coordinator.d.ts +2 -0
  52. package/dist/picker/index.d.ts +2 -2
  53. package/dist/search/command-palette.d.ts +21 -0
  54. package/dist/search/contribution.d.ts +7 -0
  55. package/dist/search/fuzzy.d.ts +10 -0
  56. package/dist/search/index.d.ts +4 -0
  57. package/dist/search/match-bar.d.ts +14 -0
  58. package/dist/search/search-header.d.ts +7 -0
  59. package/dist/search/token-search.d.ts +36 -0
  60. package/dist/server/create-apply-handler.d.ts +33 -0
  61. package/dist/server/index.d.ts +2 -1
  62. package/dist/server/index.js +1 -1
  63. package/dist/shell/dock-mode-switch.d.ts +6 -0
  64. package/dist/shell/footer.d.ts +1 -0
  65. package/dist/shell/ghost-idle.d.ts +24 -0
  66. package/dist/shell/header.d.ts +5 -0
  67. package/dist/shell/layer-activity.d.ts +6 -0
  68. package/dist/shell/mini-pill.d.ts +21 -0
  69. package/dist/shell/regions.d.ts +26 -0
  70. package/dist/shell/shortcut-dispatcher.d.ts +17 -0
  71. package/dist/shell/tab-bar.d.ts +17 -0
  72. package/dist/shell/tab-overflow-popover.d.ts +13 -0
  73. package/dist/specimen/on-page-specimen.d.ts +19 -0
  74. package/dist/specimen/preview-glyphs.d.ts +2 -0
  75. package/dist/specimen/specimen-state.d.ts +12 -0
  76. package/dist/specimen/specimen-tab-body.d.ts +18 -0
  77. package/dist/specimen/specimen-toolbar.d.ts +10 -0
  78. package/dist/specimen/specimen-values.d.ts +9 -0
  79. package/dist/state/history.d.ts +64 -0
  80. package/dist/state/persist.d.ts +10 -14
  81. package/dist/state/transaction.d.ts +24 -0
  82. package/dist/state/tweak-state.d.ts +16 -0
  83. package/dist/styles/z-index-tokens.d.ts +2 -0
  84. package/dist/tabs/color-tab.d.ts +10 -1
  85. package/dist/tabs/flat/flat-tab.d.ts +27 -0
  86. package/dist/tabs/flat/index.d.ts +8 -0
  87. package/dist/tabs/flat/scroll-to-token-row.d.ts +3 -0
  88. package/dist/tabs/flat/tier-section.d.ts +17 -0
  89. package/dist/tabs/flat/token-controller.d.ts +23 -0
  90. package/dist/tabs/flat/token-row.d.ts +12 -0
  91. package/dist/tabs/flat/types.d.ts +25 -0
  92. package/dist/tabs/font-tab.d.ts +13 -12
  93. package/dist/tabs/generic-tab.d.ts +8 -38
  94. package/dist/tabs/palette/palette-check-view.d.ts +5 -1
  95. package/dist/tabs/palette/palette-edit-view.d.ts +9 -1
  96. package/dist/tabs/palette/palette-tab.d.ts +12 -1
  97. package/dist/tabs/size-tab.d.ts +7 -10
  98. package/dist/tabs/spacing-tab.d.ts +7 -13
  99. package/dist/testing.js +3 -3
  100. package/dist/tokens/tier-model.d.ts +6 -0
  101. package/dist/{tweak-state-BKNxtHzb.js → tweak-state-BGp_7Tfh.js} +473 -423
  102. package/dist/utils/numeric-transform.d.ts +32 -0
  103. package/dist/utils/token-diff.d.ts +25 -0
  104. package/dist/utils/token-graph.d.ts +23 -0
  105. package/dist/utils/token-index.d.ts +30 -0
  106. package/dist/zdtp.css +1 -1
  107. package/package.json +3 -1
  108. package/dist/controls/pill-slider-row.d.ts +0 -36
  109. package/dist/controls/select-row.d.ts +0 -25
  110. package/dist/controls/slider-row.d.ts +0 -29
  111. package/dist/controls/text-row.d.ts +0 -27
  112. package/dist/index-U7Ol7tgA.js +0 -7591
  113. package/dist/load-routing-D4H2VOl5.js +0 -426
@@ -1,7 +1,7 @@
1
1
  import { jsx as y, jsxs as K, Fragment as kt } from "preact/jsx-runtime";
2
2
  import { useEffect as P, useState as Y, useRef as O, useMemo as J, useCallback as X } from "preact/hooks";
3
- import { b as ft, p as wt, u as ht, a as Ne, A as bt, Z as gt } from "./index-U7Ol7tgA.js";
4
- import { g as vt, m as j } from "./panel-config-COHesW2B.js";
3
+ import { b as ft, p as wt, u as ht, a as Ne, A as bt, Z as gt } from "./index-BOOmFtJh.js";
4
+ import { g as vt, m as j } from "./panel-config-CRf-ONSV.js";
5
5
  const xt = (e, o) => {
6
6
  const t = new Array(e.length + o.length);
7
7
  for (let r = 0; r < e.length; r++)
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import "preact/jsx-runtime";
2
2
  import "preact";
3
- import { S as t, c as i, d as n, _ as l, e as d, f as _, g as p, h as g, i as m, j as P, k as u, l as A, m as C, n as S, o as T, q as c, r as f, s as K, t as M, v, w as E, x as F, y as h, z as w } from "./index-U7Ol7tgA.js";
4
- import { Z as y, V as D, v as k, u as H, Y as L } from "./tweak-state-BKNxtHzb.js";
5
- import { c as Y, s as b } from "./panel-config-COHesW2B.js";
6
- import "./autoload-state-CfL2VUe1.js";
3
+ import { S as t, c as i, d as n, _ as l, e as d, f as _, g as p, h as g, i as m, j as P, k as A, l as C, m as S, n as u, o as T, q as c, r as f, s as K, t as M, v, w, x, y as E, z as F } from "./index-BOOmFtJh.js";
4
+ import { Z as y, a2 as D, x as k, w as H, a5 as L } from "./tweak-state-BGp_7Tfh.js";
5
+ import { c as O, s as V } from "./panel-config-CRf-ONSV.js";
6
+ import "./autoload-state-7BQYXI7Y.js";
7
7
  export {
8
8
  t as SCHEMA_V1,
9
9
  i as SCHEMA_V2,
@@ -14,15 +14,15 @@ export {
14
14
  _ as __reapplyFromStorageForTests,
15
15
  p as __resetInstanceBindingsForTests,
16
16
  g as __resetSpawnSlotsForTests,
17
- Y as configurePanel,
17
+ O as configurePanel,
18
18
  m as disableAutoload,
19
19
  D as emptyOverrides,
20
20
  P as enableAutoload,
21
21
  k as getClusterDefaultMode,
22
- u as hideDesignTokenPanel,
23
- A as isColorKind,
24
- C as isContentKind,
25
- S as isCursorKind,
22
+ A as hideDesignTokenPanel,
23
+ C as isColorKind,
24
+ S as isContentKind,
25
+ u as isCursorKind,
26
26
  T as isLengthKind,
27
27
  c as isMaskImageKind,
28
28
  f as isNumberKind,
@@ -31,9 +31,9 @@ export {
31
31
  v as reapplyPersistedOverrides,
32
32
  H as resolvePerModeLiteral,
33
33
  L as resolveSemanticPreviewColor,
34
- E as setLifecycleAdapter,
35
- b as setPanelColorPresets,
36
- F as shouldAutoload,
37
- h as showDesignTokenPanel,
38
- w as toggleDesignPanel
34
+ w as setLifecycleAdapter,
35
+ V as setPanelColorPresets,
36
+ x as shouldAutoload,
37
+ E as showDesignTokenPanel,
38
+ F as toggleDesignPanel
39
39
  };
@@ -0,0 +1,547 @@
1
+ import { promises as v, readFileSync as X } from "node:fs";
2
+ import { relative as D, isAbsolute as G, sep as Q, resolve as T, dirname as z, join as J } from "node:path";
3
+ import { createHash as Y, randomBytes as V } from "node:crypto";
4
+ import { r as ee } from "./route-tokens-to-files-1DvmWBdj.js";
5
+ const A = /* @__PURE__ */ new Map();
6
+ async function E(e, t) {
7
+ const n = (A.get(e) ?? Promise.resolve()).then(t, t), o = n.then(
8
+ () => {
9
+ },
10
+ () => {
11
+ }
12
+ );
13
+ A.set(e, o);
14
+ try {
15
+ return await n;
16
+ } finally {
17
+ A.get(e) === o && A.delete(e);
18
+ }
19
+ }
20
+ function ne(e) {
21
+ return e.replace(/[\r\n\\;{}]/g, "");
22
+ }
23
+ const te = /^--[a-zA-Z0-9_-]+$/;
24
+ function re(e) {
25
+ return typeof e == "string" && te.test(e);
26
+ }
27
+ function oe(e, t) {
28
+ if (!t.endsWith(".css")) return !1;
29
+ const r = D(e, t);
30
+ return !(r === "" || r === "." || G(r) || r === ".." || r.startsWith(`..${Q}`) || r.startsWith("../"));
31
+ }
32
+ function se(e) {
33
+ const t = {};
34
+ for (const [r, n] of Object.entries(e)) {
35
+ if (!re(r))
36
+ return { error: `Invalid cssVar name: ${JSON.stringify(r)}` };
37
+ if (typeof n != "string")
38
+ return { error: `Value for ${r} must be a string` };
39
+ t[r] = ne(n);
40
+ }
41
+ return { sanitized: t };
42
+ }
43
+ class B extends Error {
44
+ constructor(t = 'No top-level ":root { ... }" or "@theme { ... }" block found in source.') {
45
+ super(t), this.name = "NoTokenBlockError", Object.setPrototypeOf(this, B.prototype);
46
+ }
47
+ }
48
+ function W(e, t, r) {
49
+ const n = e.length, o = t.length, i = t[0];
50
+ let s = 0, c = 0;
51
+ for (; s < n; ) {
52
+ const l = e[s];
53
+ if (l === "/" && e[s + 1] === "*") {
54
+ const a = e.indexOf("*/", s + 2);
55
+ if (a === -1) return null;
56
+ s = a + 2;
57
+ continue;
58
+ }
59
+ if (l === '"' || l === "'") {
60
+ const a = l;
61
+ for (s++; s < n && e[s] !== a; )
62
+ e[s] === "\\" && s + 1 < n && s++, s++;
63
+ s++;
64
+ continue;
65
+ }
66
+ if (l === "{") {
67
+ c++, s++;
68
+ continue;
69
+ }
70
+ if (l === "}") {
71
+ c > 0 && c--, s++;
72
+ continue;
73
+ }
74
+ if (c === 0 && l === i && e.startsWith(t, s)) {
75
+ const a = s + o, h = e[a] ?? "";
76
+ if (!I(h)) {
77
+ const k = r ? ae(e, a) : ie(e, a);
78
+ if (k !== -1) {
79
+ const m = k + 1, f = le(e, m);
80
+ return f !== -1 ? { contentStart: m, contentEnd: f } : null;
81
+ }
82
+ }
83
+ }
84
+ s++;
85
+ }
86
+ return null;
87
+ }
88
+ function C(e) {
89
+ return W(e, ":root", !1);
90
+ }
91
+ function P(e) {
92
+ return W(e, "@theme", !0);
93
+ }
94
+ function I(e) {
95
+ return /[A-Za-z0-9_-]/.test(e);
96
+ }
97
+ function ie(e, t) {
98
+ const r = e.length;
99
+ let n = t;
100
+ for (; n < r; ) {
101
+ const o = e[n];
102
+ if (o === " " || o === " " || o === `
103
+ ` || o === "\r" || o === "\f") {
104
+ n++;
105
+ continue;
106
+ }
107
+ if (o === "/" && e[n + 1] === "*") {
108
+ const i = e.indexOf("*/", n + 2);
109
+ if (i === -1) return -1;
110
+ n = i + 2;
111
+ continue;
112
+ }
113
+ return o === "{" ? n : -1;
114
+ }
115
+ return -1;
116
+ }
117
+ function ae(e, t) {
118
+ const r = e.length;
119
+ let n = t;
120
+ for (; n < r; ) {
121
+ const o = e[n];
122
+ if (o === " " || o === " " || o === `
123
+ ` || o === "\r" || o === "\f") {
124
+ n++;
125
+ continue;
126
+ }
127
+ if (o === "/" && e[n + 1] === "*") {
128
+ const i = e.indexOf("*/", n + 2);
129
+ if (i === -1) return -1;
130
+ n = i + 2;
131
+ continue;
132
+ }
133
+ if (o === "{") return n;
134
+ if (I(o)) {
135
+ for (n++; n < r && I(e[n]); ) n++;
136
+ continue;
137
+ }
138
+ return -1;
139
+ }
140
+ return -1;
141
+ }
142
+ function le(e, t) {
143
+ const r = e.length;
144
+ let n = t, o = 1;
145
+ for (; n < r; ) {
146
+ const i = e[n];
147
+ if (i === "/" && e[n + 1] === "*") {
148
+ const s = e.indexOf("*/", n + 2);
149
+ if (s === -1) return -1;
150
+ n = s + 2;
151
+ continue;
152
+ }
153
+ if (i === '"' || i === "'") {
154
+ const s = i;
155
+ for (n++; n < r && e[n] !== s; )
156
+ e[n] === "\\" && n + 1 < r && n++, n++;
157
+ n++;
158
+ continue;
159
+ }
160
+ if (i === "{") {
161
+ o++, n++;
162
+ continue;
163
+ }
164
+ if (i === "}") {
165
+ if (o--, o === 0) return n;
166
+ n++;
167
+ continue;
168
+ }
169
+ n++;
170
+ }
171
+ return -1;
172
+ }
173
+ function ce(e) {
174
+ return e.replace(/[\\^$.*+?()[\]{}|]/g, "\\$&");
175
+ }
176
+ function _(e) {
177
+ return e.replace(/\/\*[\s\S]*?\*\//g, (t) => " ".repeat(t.length));
178
+ }
179
+ function q(e) {
180
+ const t = e.startsWith("--") ? e.slice(2) : e, r = ce(t);
181
+ return new RegExp("(?<![\\w-])(--" + r + ":)(\\s*)([\\s\\S]+?);");
182
+ }
183
+ function L(e, t) {
184
+ return q(t).test(_(e));
185
+ }
186
+ function j(e, t, r) {
187
+ const n = q(t), o = _(e), i = n.exec(o);
188
+ if (!i) return { content: e, status: "unknown" };
189
+ const [s, c, l] = i, a = i.index, h = a + s.length, k = a + c.length + l.length, m = h - 1, p = e.slice(k, m).trim(), b = r.trim();
190
+ return p === b ? { content: e, status: "unchanged" } : { content: e.slice(0, a) + c + l + r + ";" + e.slice(h), status: "changed" };
191
+ }
192
+ function ue(e, t) {
193
+ const r = Object.keys(t), n = C(e), o = P(e);
194
+ if (!n && !o)
195
+ return {
196
+ updated: e,
197
+ changed: [],
198
+ unchanged: [],
199
+ unknown: [...r],
200
+ unknownOutsideBlock: r.filter((f) => L(e, f))
201
+ };
202
+ let i = n ? e.slice(n.contentStart, n.contentEnd) : null, s = o ? e.slice(o.contentStart, o.contentEnd) : null;
203
+ const c = [], l = [], a = [];
204
+ for (const f of r) {
205
+ if (i !== null) {
206
+ const p = j(i, f, t[f]);
207
+ if (p.status !== "unknown") {
208
+ i = p.content, p.status === "changed" ? c.push(f) : l.push(f);
209
+ continue;
210
+ }
211
+ }
212
+ if (s !== null) {
213
+ const p = j(s, f, t[f]);
214
+ if (p.status !== "unknown") {
215
+ s = p.content, p.status === "changed" ? c.push(f) : l.push(f);
216
+ continue;
217
+ }
218
+ }
219
+ a.push(f);
220
+ }
221
+ const h = [];
222
+ n && i !== null && h.push({ start: n.contentStart, end: n.contentEnd, content: i }), o && s !== null && h.push({
223
+ start: o.contentStart,
224
+ end: o.contentEnd,
225
+ content: s
226
+ }), h.sort((f, p) => p.start - f.start);
227
+ let k = e;
228
+ for (const f of h)
229
+ k = k.slice(0, f.start) + f.content + k.slice(f.end);
230
+ const m = a.filter((f) => L(e, f));
231
+ return { updated: k, changed: c, unchanged: l, unknown: a, unknownOutsideBlock: m };
232
+ }
233
+ function fe(e, t) {
234
+ if (!de(e))
235
+ throw new B();
236
+ return ue(e, t);
237
+ }
238
+ function de(e) {
239
+ return C(e) !== null || P(e) !== null;
240
+ }
241
+ const he = 4e6;
242
+ function pe(e) {
243
+ return e.replace(/[\\^$.*+?()[\]{}|]/g, "\\$&");
244
+ }
245
+ function ge(e, t) {
246
+ return new RegExp(`(?:^|[;{])\\s*${pe(t)}\\s*:`).test(e);
247
+ }
248
+ function M(e) {
249
+ return e.replace(/\/\*[\s\S]*?\*\//g, (t) => t.replace(/[^\r\n]/g, " "));
250
+ }
251
+ function ke(e, t) {
252
+ if (e.length === t.length)
253
+ return e.map((l, a) => ({ beforeIndex: a, afterIndex: a }));
254
+ const r = e.length + 1, n = t.length + 1;
255
+ if (r * n > he) return [];
256
+ const o = Array.from({ length: r }, () => new Uint32Array(n));
257
+ for (let l = e.length - 1; l >= 0; l--)
258
+ for (let a = t.length - 1; a >= 0; a--)
259
+ o[l][a] = e[l] === t[a] ? o[l + 1][a + 1] + 1 : Math.max(o[l + 1][a], o[l][a + 1]);
260
+ const i = [];
261
+ let s = 0, c = 0;
262
+ for (; s < e.length || c < t.length; )
263
+ s < e.length && c < t.length && e[s] === t[c] ? i.push({ beforeIndex: s++, afterIndex: c++ }) : c < t.length && (s === e.length || o[s][c + 1] >= o[s + 1][c]) ? i.push({ beforeIndex: null, afterIndex: c++ }) : i.push({ beforeIndex: s++, afterIndex: null });
264
+ return i;
265
+ }
266
+ function N(e, t, r) {
267
+ return t.findIndex(
268
+ (n, o) => ge(n, r) && e[o] !== void 0
269
+ );
270
+ }
271
+ function me(e, t, r, n = 1) {
272
+ const o = e.split(`
273
+ `), i = t.split(`
274
+ `), s = M(e).split(`
275
+ `), c = M(t).split(`
276
+ `), l = ke(o, i), a = Math.max(0, Math.floor(n));
277
+ return r.flatMap((h) => {
278
+ const k = N(o, s, h), m = N(i, c, h);
279
+ if (k === -1 || m === -1) return [];
280
+ const p = l.find(
281
+ (b) => b.beforeIndex === k && b.afterIndex !== null
282
+ )?.afterIndex ?? m;
283
+ return [
284
+ {
285
+ cssVar: h,
286
+ line: p + 1,
287
+ before: o[k],
288
+ after: i[m],
289
+ context: {
290
+ before: i.slice(Math.max(0, p - a), p),
291
+ after: i.slice(p + 1, p + 1 + a)
292
+ }
293
+ }
294
+ ];
295
+ });
296
+ }
297
+ function g(e, t = 200) {
298
+ return new Response(JSON.stringify(e), {
299
+ status: t,
300
+ headers: { "Content-Type": "application/json" }
301
+ });
302
+ }
303
+ async function ye(e, t, r) {
304
+ const n = await v.readFile(e), o = n.toString("utf-8"), i = fe(o, r), s = C(o), c = P(o), l = s && Object.entries(r).some(
305
+ ([k, m]) => j(o.slice(s.contentStart, s.contentEnd), k, m).status !== "unknown"
306
+ ), a = c && Object.entries(r).some(
307
+ ([k, m]) => j(o.slice(c.contentStart, c.contentEnd), k, m).status !== "unknown"
308
+ ), h = l ? "root" : a ? "theme" : s ? "root" : "theme";
309
+ return {
310
+ absPath: e,
311
+ relPath: t,
312
+ original: o,
313
+ updated: i.updated,
314
+ changed: i.changed,
315
+ unchanged: i.unchanged,
316
+ unknown: i.unknown,
317
+ unknownOutsideBlock: i.unknownOutsideBlock,
318
+ digest: Y("sha256").update(n).digest("hex"),
319
+ // applyTokenOverrides uses :root first and @theme as its fallback. Report
320
+ // the block that contains a requested declaration (root wins for a mixed
321
+ // request, matching the rewriter). NoTokenBlockError above guarantees at
322
+ // least one of the two block kinds exists.
323
+ blockKind: h
324
+ };
325
+ }
326
+ function F(e, t) {
327
+ return t.startsWith("/") ? D(e, t) : t;
328
+ }
329
+ async function we(e) {
330
+ if (e.changed.length !== 0)
331
+ return E(e.absPath, async () => {
332
+ const t = z(e.absPath), r = J(t, `.tmp-${V(8).toString("hex")}.css`);
333
+ try {
334
+ await v.writeFile(r, e.updated, "utf-8"), await v.rename(r, e.absPath);
335
+ } catch (n) {
336
+ try {
337
+ await v.unlink(r);
338
+ } catch {
339
+ }
340
+ throw n;
341
+ }
342
+ });
343
+ }
344
+ async function be(e) {
345
+ return E(e.absPath, async () => {
346
+ const t = z(e.absPath), r = J(t, `.tmp-${V(8).toString("hex")}.css`);
347
+ try {
348
+ return await v.writeFile(r, e.original, "utf-8"), await v.rename(r, e.absPath), { ok: !0 };
349
+ } catch (n) {
350
+ console.error("[design-token-panel/server] Restore failed for", e.relPath, n);
351
+ try {
352
+ await v.unlink(r);
353
+ } catch {
354
+ }
355
+ return { ok: !1, error: n };
356
+ }
357
+ });
358
+ }
359
+ function $e(e) {
360
+ const { rootDir: t, writeRoot: r, routing: n } = e, o = `\0zdtp-apply-batch:${T(r)}`;
361
+ return async function(s) {
362
+ let c;
363
+ try {
364
+ c = await s.json();
365
+ } catch {
366
+ return g({ ok: !1, error: "Invalid JSON in request body" }, 400);
367
+ }
368
+ if (typeof c != "object" || c === null || Array.isArray(c))
369
+ return g({ ok: !1, error: "Request body must be a JSON object" }, 400);
370
+ const { tokens: l, dryRun: a, expectDigests: h } = c;
371
+ if (a !== void 0 && a !== !0)
372
+ return g({ ok: !1, error: "dryRun, when supplied, must be true" }, 400);
373
+ if (h !== void 0 && (typeof h != "object" || h === null || Array.isArray(h)))
374
+ return g({ ok: !1, error: "expectDigests must be a JSON object" }, 400);
375
+ if (h !== void 0 && Object.entries(h).some(
376
+ ([O, S]) => O.length === 0 || typeof S != "string" || !/^[a-f0-9]{64}$/i.test(S)
377
+ ))
378
+ return g(
379
+ { ok: !1, error: "expectDigests values must be SHA-256 hex digests" },
380
+ 400
381
+ );
382
+ if (typeof l != "object" || l === null || Array.isArray(l))
383
+ return g({ ok: !1, error: "tokens must be a JSON object" }, 400);
384
+ if (Object.entries(l).length === 0)
385
+ return g({ ok: !1, error: "tokens must contain at least one entry" }, 400);
386
+ const { sanitized: m, error: f } = se(l);
387
+ if (f || !m)
388
+ return g({ ok: !1, error: f ?? "Invalid tokens" }, 400);
389
+ const { groups: p, rejected: b, rejectedReasons: R } = ee(m, n);
390
+ return b.length > 0 && a !== !0 ? g(
391
+ { ok: !1, error: "Unsupported cssVar prefix", rejected: b, rejectedReasons: R },
392
+ 400
393
+ ) : p.length === 0 ? a === !0 ? g({
394
+ ok: !0,
395
+ dryRun: !0,
396
+ files: [],
397
+ rejected: b,
398
+ rejectedReasons: R
399
+ }) : g({ ok: !1, error: "No routable tokens supplied" }, 400) : E(o, async () => {
400
+ const O = /* @__PURE__ */ new Map();
401
+ for (const u of p) {
402
+ const d = T(t, u.relativePath);
403
+ if (!oe(r, d))
404
+ return g({ ok: !1, error: `Path not allowed: ${u.relativePath}` }, 400);
405
+ const y = O.get(d);
406
+ y ? Object.assign(y.groupTokens, u.tokens) : O.set(d, {
407
+ absPath: d,
408
+ relPath: u.relativePath,
409
+ groupTokens: { ...u.tokens }
410
+ });
411
+ }
412
+ const S = Array.from(O.values()), x = [];
413
+ for (const { absPath: u, relPath: d, groupTokens: y } of S)
414
+ try {
415
+ x.push(await ye(u, d, y));
416
+ } catch (w) {
417
+ return w instanceof B ? (console.error("[design-token-panel/server] No :root or @theme block in", d), g(
418
+ {
419
+ ok: !1,
420
+ error: `No top-level :root { ... } or @theme { ... } block in ${d}`
421
+ },
422
+ 409
423
+ )) : (console.error(`[design-token-panel/server] Error computing ${d}:`, w), g({ ok: !1, error: "Failed to read or parse source file" }, 500));
424
+ }
425
+ if (a === !0) {
426
+ const u = x.map((d) => ({
427
+ file: F(t, d.relPath),
428
+ blockKind: d.blockKind,
429
+ digest: d.digest,
430
+ changed: d.changed,
431
+ unchanged: d.unchanged,
432
+ unknown: d.unknown,
433
+ unknownOutsideBlock: d.unknownOutsideBlock,
434
+ hunks: me(d.original, d.updated, d.changed)
435
+ }));
436
+ return g({
437
+ ok: !0,
438
+ dryRun: !0,
439
+ files: u,
440
+ rejected: b,
441
+ rejectedReasons: R
442
+ });
443
+ }
444
+ if (h !== void 0) {
445
+ const u = h, d = x.filter((y) => {
446
+ const w = F(t, y.relPath);
447
+ return Object.hasOwn(u, w) && u[w].toLowerCase() !== y.digest;
448
+ }).map((y) => F(t, y.relPath));
449
+ if (d.length > 0)
450
+ return g(
451
+ { ok: !1, reason: "stale-file", files: d },
452
+ 409
453
+ );
454
+ }
455
+ const $ = [];
456
+ for (const u of x)
457
+ try {
458
+ await we(u), $.push(u);
459
+ } catch (d) {
460
+ console.error(`[design-token-panel/server] Write failed for ${u.relPath}:`, d);
461
+ const y = [];
462
+ for (let w = $.length - 1; w >= 0; w--)
463
+ (await be($[w])).ok || y.push($[w].relPath);
464
+ if (y.length > 0) {
465
+ const w = y.length === 1 ? "file" : "files";
466
+ return g(
467
+ {
468
+ ok: !1,
469
+ error: `Failed to write file ${u.relPath}; rollback also failed for ${y.length} ${w} — disk state is inconsistent. Inspect the listed files manually.`,
470
+ failedFile: u.relPath,
471
+ restoreFailures: y
472
+ },
473
+ 500
474
+ );
475
+ }
476
+ return g(
477
+ {
478
+ ok: !1,
479
+ error: `Failed to write file ${u.relPath}; previously-written files were restored.`,
480
+ failedFile: u.relPath
481
+ },
482
+ 500
483
+ );
484
+ }
485
+ const H = x.flatMap((u) => u.unknown), K = x.flatMap((u) => u.unchanged), U = x.flatMap((u) => u.unknownOutsideBlock), Z = x.map((u) => ({
486
+ file: F(t, u.relPath),
487
+ changed: u.changed,
488
+ unchanged: u.unchanged,
489
+ unknown: u.unknown,
490
+ unknownOutsideBlock: u.unknownOutsideBlock
491
+ }));
492
+ return g({
493
+ ok: !0,
494
+ updated: Z,
495
+ unknownCssVars: H,
496
+ unchangedCssVars: K,
497
+ unknownOutsideBlockCssVars: U
498
+ });
499
+ });
500
+ };
501
+ }
502
+ function Ae(e) {
503
+ let t;
504
+ try {
505
+ t = X(e, "utf-8");
506
+ } catch (i) {
507
+ throw new Error(
508
+ `[design-token-panel] loadRoutingFromFile: cannot read file at ${e}
509
+ Cause: ${i.message}`
510
+ );
511
+ }
512
+ let r;
513
+ try {
514
+ r = JSON.parse(t);
515
+ } catch (i) {
516
+ throw new Error(
517
+ `[design-token-panel] loadRoutingFromFile: invalid JSON in ${e}
518
+ Cause: ${i.message}`
519
+ );
520
+ }
521
+ if (r === null || typeof r != "object" || Array.isArray(r))
522
+ throw new Error(
523
+ `[design-token-panel] loadRoutingFromFile: root value must be a plain object, got ${r === null ? "null" : Array.isArray(r) ? "array" : typeof r} (in ${e})`
524
+ );
525
+ const n = r, o = Object.keys(n);
526
+ if (o.length === 0)
527
+ throw new Error(
528
+ `[design-token-panel] loadRoutingFromFile: routing map must not be empty (in ${e})`
529
+ );
530
+ for (const i of o) {
531
+ const s = n[i];
532
+ if (typeof s != "string" || s.trim() === "")
533
+ throw new Error(
534
+ `[design-token-panel] loadRoutingFromFile: every value must be a non-empty string, but key "${i}" has value ${JSON.stringify(s)} (in ${e})`
535
+ );
536
+ }
537
+ return n;
538
+ }
539
+ export {
540
+ te as C,
541
+ re as a,
542
+ $e as c,
543
+ oe as i,
544
+ Ae as l,
545
+ E as s,
546
+ se as v
547
+ };
@@ -1,4 +1,4 @@
1
- const t = {
1
+ const o = {
2
2
  hsp: "HORIZONTAL SPACING (HSP)",
3
3
  vsp: "VERTICAL SPACING (VSP)",
4
4
  icon: "ICONS",
@@ -10,15 +10,19 @@ const t = {
10
10
  "font-scale": "ADVANCED — SCALE (TIER 1)",
11
11
  radius: "BORDER RADIUS",
12
12
  transition: "TRANSITIONS"
13
- }, n = ["hsp", "vsp", "icon", "layout"], s = [
13
+ }, s = ["hsp", "vsp", "icon", "layout"], i = [
14
14
  "font-size",
15
15
  "line-height",
16
16
  "font-weight",
17
17
  "font-family"
18
- ], i = ["radius", "transition"];
18
+ ], a = ["radius", "transition"];
19
+ function I(t, n) {
20
+ return `${t}${n}`;
21
+ }
19
22
  export {
20
- s as F,
21
- n as G,
22
- i as S,
23
- t as a
23
+ i as F,
24
+ s as G,
25
+ a as S,
26
+ o as a,
27
+ I as f
24
28
  };