@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,426 +0,0 @@
1
- import { promises as b, readFileSync as q } from "node:fs";
2
- import { relative as P, isAbsolute as L, sep as _, resolve as D, dirname as T, join as j } from "node:path";
3
- import { randomBytes as x } from "node:crypto";
4
- import { r as Z } from "./route-tokens-to-files-1DvmWBdj.js";
5
- const F = /* @__PURE__ */ new Map();
6
- async function B(t, r) {
7
- const e = (F.get(t) ?? Promise.resolve()).then(r, r), o = e.then(
8
- () => {
9
- },
10
- () => {
11
- }
12
- );
13
- F.set(t, o);
14
- try {
15
- return await e;
16
- } finally {
17
- F.get(t) === o && F.delete(t);
18
- }
19
- }
20
- function H(t) {
21
- return t.replace(/[\r\n\\;{}]/g, "");
22
- }
23
- const U = /^--[a-zA-Z0-9_-]+$/;
24
- function G(t) {
25
- return typeof t == "string" && U.test(t);
26
- }
27
- function K(t, r) {
28
- if (!r.endsWith(".css")) return !1;
29
- const n = P(t, r);
30
- return !(n === "" || n === "." || L(n) || n === ".." || n.startsWith(`..${_}`) || n.startsWith("../"));
31
- }
32
- function Q(t) {
33
- const r = {};
34
- for (const [n, e] of Object.entries(t)) {
35
- if (!G(n))
36
- return { error: `Invalid cssVar name: ${JSON.stringify(n)}` };
37
- if (typeof e != "string")
38
- return { error: `Value for ${n} must be a string` };
39
- r[n] = H(e);
40
- }
41
- return { sanitized: r };
42
- }
43
- class S extends Error {
44
- constructor(r = 'No top-level ":root { ... }" or "@theme { ... }" block found in source.') {
45
- super(r), this.name = "NoTokenBlockError", Object.setPrototypeOf(this, S.prototype);
46
- }
47
- }
48
- function E(t, r, n) {
49
- const e = t.length, o = r.length, i = r[0];
50
- let s = 0, u = 0;
51
- for (; s < e; ) {
52
- const f = t[s];
53
- if (f === "/" && t[s + 1] === "*") {
54
- const c = t.indexOf("*/", s + 2);
55
- if (c === -1) return null;
56
- s = c + 2;
57
- continue;
58
- }
59
- if (f === '"' || f === "'") {
60
- const c = f;
61
- for (s++; s < e && t[s] !== c; )
62
- t[s] === "\\" && s + 1 < e && s++, s++;
63
- s++;
64
- continue;
65
- }
66
- if (f === "{") {
67
- u++, s++;
68
- continue;
69
- }
70
- if (f === "}") {
71
- u > 0 && u--, s++;
72
- continue;
73
- }
74
- if (u === 0 && f === i && t.startsWith(r, s)) {
75
- const c = s + o, p = t[c] ?? "";
76
- if (!$(p)) {
77
- const k = n ? Y(t, c) : X(t, c);
78
- if (k !== -1) {
79
- const m = k + 1, l = tt(t, m);
80
- return l !== -1 ? { contentStart: m, contentEnd: l } : null;
81
- }
82
- }
83
- }
84
- s++;
85
- }
86
- return null;
87
- }
88
- function C(t) {
89
- return E(t, ":root", !1);
90
- }
91
- function N(t) {
92
- return E(t, "@theme", !0);
93
- }
94
- function $(t) {
95
- return /[A-Za-z0-9_-]/.test(t);
96
- }
97
- function X(t, r) {
98
- const n = t.length;
99
- let e = r;
100
- for (; e < n; ) {
101
- const o = t[e];
102
- if (o === " " || o === " " || o === `
103
- ` || o === "\r" || o === "\f") {
104
- e++;
105
- continue;
106
- }
107
- if (o === "/" && t[e + 1] === "*") {
108
- const i = t.indexOf("*/", e + 2);
109
- if (i === -1) return -1;
110
- e = i + 2;
111
- continue;
112
- }
113
- return o === "{" ? e : -1;
114
- }
115
- return -1;
116
- }
117
- function Y(t, r) {
118
- const n = t.length;
119
- let e = r;
120
- for (; e < n; ) {
121
- const o = t[e];
122
- if (o === " " || o === " " || o === `
123
- ` || o === "\r" || o === "\f") {
124
- e++;
125
- continue;
126
- }
127
- if (o === "/" && t[e + 1] === "*") {
128
- const i = t.indexOf("*/", e + 2);
129
- if (i === -1) return -1;
130
- e = i + 2;
131
- continue;
132
- }
133
- if (o === "{") return e;
134
- if ($(o)) {
135
- for (e++; e < n && $(t[e]); ) e++;
136
- continue;
137
- }
138
- return -1;
139
- }
140
- return -1;
141
- }
142
- function tt(t, r) {
143
- const n = t.length;
144
- let e = r, o = 1;
145
- for (; e < n; ) {
146
- const i = t[e];
147
- if (i === "/" && t[e + 1] === "*") {
148
- const s = t.indexOf("*/", e + 2);
149
- if (s === -1) return -1;
150
- e = s + 2;
151
- continue;
152
- }
153
- if (i === '"' || i === "'") {
154
- const s = i;
155
- for (e++; e < n && t[e] !== s; )
156
- t[e] === "\\" && e + 1 < n && e++, e++;
157
- e++;
158
- continue;
159
- }
160
- if (i === "{") {
161
- o++, e++;
162
- continue;
163
- }
164
- if (i === "}") {
165
- if (o--, o === 0) return e;
166
- e++;
167
- continue;
168
- }
169
- e++;
170
- }
171
- return -1;
172
- }
173
- function et(t) {
174
- return t.replace(/[\\^$.*+?()[\]{}|]/g, "\\$&");
175
- }
176
- function M(t) {
177
- return t.replace(/\/\*[\s\S]*?\*\//g, (r) => " ".repeat(r.length));
178
- }
179
- function V(t) {
180
- const r = t.startsWith("--") ? t.slice(2) : t, n = et(r);
181
- return new RegExp("(?<![\\w-])(--" + n + ":)(\\s*)([\\s\\S]+?);");
182
- }
183
- function R(t, r) {
184
- return V(r).test(M(t));
185
- }
186
- function A(t, r, n) {
187
- const e = V(r), o = M(t), i = e.exec(o);
188
- if (!i) return { content: t, status: "unknown" };
189
- const [s, u, f] = i, c = i.index, p = c + s.length, k = c + u.length + f.length, m = p - 1, d = t.slice(k, m).trim(), y = n.trim();
190
- return d === y ? { content: t, status: "unchanged" } : { content: t.slice(0, c) + u + f + n + ";" + t.slice(p), status: "changed" };
191
- }
192
- function nt(t, r) {
193
- const n = Object.keys(r), e = C(t), o = N(t);
194
- if (!e && !o)
195
- return {
196
- updated: t,
197
- changed: [],
198
- unchanged: [],
199
- unknown: [...n],
200
- unknownOutsideBlock: n.filter((l) => R(t, l))
201
- };
202
- let i = e ? t.slice(e.contentStart, e.contentEnd) : null, s = o ? t.slice(o.contentStart, o.contentEnd) : null;
203
- const u = [], f = [], c = [];
204
- for (const l of n) {
205
- if (i !== null) {
206
- const d = A(i, l, r[l]);
207
- if (d.status !== "unknown") {
208
- i = d.content, d.status === "changed" ? u.push(l) : f.push(l);
209
- continue;
210
- }
211
- }
212
- if (s !== null) {
213
- const d = A(s, l, r[l]);
214
- if (d.status !== "unknown") {
215
- s = d.content, d.status === "changed" ? u.push(l) : f.push(l);
216
- continue;
217
- }
218
- }
219
- c.push(l);
220
- }
221
- const p = [];
222
- e && i !== null && p.push({ start: e.contentStart, end: e.contentEnd, content: i }), o && s !== null && p.push({
223
- start: o.contentStart,
224
- end: o.contentEnd,
225
- content: s
226
- }), p.sort((l, d) => d.start - l.start);
227
- let k = t;
228
- for (const l of p)
229
- k = k.slice(0, l.start) + l.content + k.slice(l.end);
230
- const m = c.filter((l) => R(t, l));
231
- return { updated: k, changed: u, unchanged: f, unknown: c, unknownOutsideBlock: m };
232
- }
233
- function rt(t, r) {
234
- if (!ot(t))
235
- throw new S();
236
- return nt(t, r);
237
- }
238
- function ot(t) {
239
- return C(t) !== null || N(t) !== null;
240
- }
241
- function h(t, r = 200) {
242
- return new Response(JSON.stringify(t), {
243
- status: r,
244
- headers: { "Content-Type": "application/json" }
245
- });
246
- }
247
- async function st(t, r, n) {
248
- const e = await b.readFile(t, "utf-8"), o = rt(e, n);
249
- return {
250
- absPath: t,
251
- relPath: r,
252
- original: e,
253
- updated: o.updated,
254
- changed: o.changed,
255
- unchanged: o.unchanged,
256
- unknown: o.unknown,
257
- unknownOutsideBlock: o.unknownOutsideBlock
258
- };
259
- }
260
- async function it(t) {
261
- if (t.changed.length !== 0)
262
- return B(t.absPath, async () => {
263
- const r = T(t.absPath), n = j(r, `.tmp-${x(8).toString("hex")}.css`);
264
- try {
265
- await b.writeFile(n, t.updated, "utf-8"), await b.rename(n, t.absPath);
266
- } catch (e) {
267
- try {
268
- await b.unlink(n);
269
- } catch {
270
- }
271
- throw e;
272
- }
273
- });
274
- }
275
- async function at(t) {
276
- return B(t.absPath, async () => {
277
- const r = T(t.absPath), n = j(r, `.tmp-${x(8).toString("hex")}.css`);
278
- try {
279
- return await b.writeFile(n, t.original, "utf-8"), await b.rename(n, t.absPath), { ok: !0 };
280
- } catch (e) {
281
- console.error("[design-token-panel/server] Restore failed for", t.relPath, e);
282
- try {
283
- await b.unlink(n);
284
- } catch {
285
- }
286
- return { ok: !1, error: e };
287
- }
288
- });
289
- }
290
- function ht(t) {
291
- const { rootDir: r, writeRoot: n, routing: e } = t;
292
- return async function(i) {
293
- let s;
294
- try {
295
- s = await i.json();
296
- } catch {
297
- return h({ ok: !1, error: "Invalid JSON in request body" }, 400);
298
- }
299
- if (typeof s != "object" || s === null || Array.isArray(s))
300
- return h({ ok: !1, error: "Request body must be a JSON object" }, 400);
301
- const { tokens: u } = s;
302
- if (typeof u != "object" || u === null || Array.isArray(u))
303
- return h({ ok: !1, error: "tokens must be a JSON object" }, 400);
304
- if (Object.entries(u).length === 0)
305
- return h({ ok: !1, error: "tokens must contain at least one entry" }, 400);
306
- const { sanitized: c, error: p } = Q(u);
307
- if (p || !c)
308
- return h({ ok: !1, error: p ?? "Invalid tokens" }, 400);
309
- const { groups: k, rejected: m } = Z(c, e);
310
- if (m.length > 0)
311
- return h({ ok: !1, error: "Unsupported cssVar prefix", rejected: m }, 400);
312
- if (k.length === 0)
313
- return h({ ok: !1, error: "No routable tokens supplied" }, 400);
314
- const l = /* @__PURE__ */ new Map();
315
- for (const a of k) {
316
- const g = D(r, a.relativePath);
317
- if (!K(n, g))
318
- return h({ ok: !1, error: `Path not allowed: ${a.relativePath}` }, 400);
319
- const w = l.get(g);
320
- w ? Object.assign(w.groupTokens, a.tokens) : l.set(g, {
321
- absPath: g,
322
- relPath: a.relativePath,
323
- groupTokens: { ...a.tokens }
324
- });
325
- }
326
- const d = Array.from(l.values()), y = [];
327
- for (const { absPath: a, relPath: g, groupTokens: w } of d)
328
- try {
329
- y.push(await st(a, g, w));
330
- } catch (v) {
331
- return v instanceof S ? (console.error("[design-token-panel/server] No :root or @theme block in", g), h(
332
- {
333
- ok: !1,
334
- error: `No top-level :root { ... } or @theme { ... } block in ${g}`
335
- },
336
- 409
337
- )) : (console.error(`[design-token-panel/server] Error computing ${g}:`, v), h({ ok: !1, error: "Failed to read or parse source file" }, 500));
338
- }
339
- const O = [];
340
- for (const a of y)
341
- try {
342
- await it(a), O.push(a);
343
- } catch (g) {
344
- console.error(`[design-token-panel/server] Write failed for ${a.relPath}:`, g);
345
- const w = [];
346
- for (let v = O.length - 1; v >= 0; v--)
347
- (await at(O[v])).ok || w.push(O[v].relPath);
348
- return w.length > 0 ? h(
349
- {
350
- ok: !1,
351
- error: `Failed to write file ${a.relPath}; rollback also failed for ${w.length} file(s) — disk state is inconsistent. Inspect the listed files manually.`,
352
- failedFile: a.relPath,
353
- restoreFailures: w
354
- },
355
- 500
356
- ) : h(
357
- {
358
- ok: !1,
359
- error: `Failed to write file ${a.relPath}; previously-written files were restored.`,
360
- failedFile: a.relPath
361
- },
362
- 500
363
- );
364
- }
365
- const J = y.flatMap((a) => a.unknown), W = y.flatMap((a) => a.unchanged), z = y.flatMap((a) => a.unknownOutsideBlock), I = y.map((a) => ({
366
- file: a.relPath.startsWith("/") ? P(r, a.relPath) : a.relPath,
367
- changed: a.changed,
368
- unchanged: a.unchanged,
369
- unknown: a.unknown,
370
- unknownOutsideBlock: a.unknownOutsideBlock
371
- }));
372
- return h({
373
- ok: !0,
374
- updated: I,
375
- unknownCssVars: J,
376
- unchangedCssVars: W,
377
- unknownOutsideBlockCssVars: z
378
- });
379
- };
380
- }
381
- function pt(t) {
382
- let r;
383
- try {
384
- r = q(t, "utf-8");
385
- } catch (i) {
386
- throw new Error(
387
- `[design-token-panel] loadRoutingFromFile: cannot read file at ${t}
388
- Cause: ${i.message}`
389
- );
390
- }
391
- let n;
392
- try {
393
- n = JSON.parse(r);
394
- } catch (i) {
395
- throw new Error(
396
- `[design-token-panel] loadRoutingFromFile: invalid JSON in ${t}
397
- Cause: ${i.message}`
398
- );
399
- }
400
- if (n === null || typeof n != "object" || Array.isArray(n))
401
- throw new Error(
402
- `[design-token-panel] loadRoutingFromFile: root value must be a plain object, got ${n === null ? "null" : Array.isArray(n) ? "array" : typeof n} (in ${t})`
403
- );
404
- const e = n, o = Object.keys(e);
405
- if (o.length === 0)
406
- throw new Error(
407
- `[design-token-panel] loadRoutingFromFile: routing map must not be empty (in ${t})`
408
- );
409
- for (const i of o) {
410
- const s = e[i];
411
- if (typeof s != "string" || s.trim() === "")
412
- throw new Error(
413
- `[design-token-panel] loadRoutingFromFile: every value must be a non-empty string, but key "${i}" has value ${JSON.stringify(s)} (in ${t})`
414
- );
415
- }
416
- return e;
417
- }
418
- export {
419
- U as C,
420
- G as a,
421
- ht as c,
422
- K as i,
423
- pt as l,
424
- B as s,
425
- Q as v
426
- };