@takazudo/zdtp 0.4.1 → 0.4.3

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 (173) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/README.md +78 -25
  3. package/dist/apply/apply-token-overrides.d.ts +0 -1
  4. package/dist/apply/build-apply-overrides.d.ts +4 -3
  5. package/dist/apply/route-tokens-to-files.d.ts +0 -1
  6. package/dist/apply/tier-resolver.d.ts +0 -1
  7. package/dist/apply-modal.d.ts +0 -1
  8. package/dist/astro/DesignTokenPanelHost.astro +2 -4
  9. package/dist/astro/host-adapter.d.ts +0 -1
  10. package/dist/astro/host-adapter.js +69 -46
  11. package/dist/astro/index.d.ts +0 -1
  12. package/dist/astro/index.js +1 -1
  13. package/dist/autoload-state-B1MWY_Pp.js +46 -0
  14. package/dist/bin/cors.d.ts +0 -1
  15. package/dist/bin/parse-args.d.ts +0 -1
  16. package/dist/bin/server.d.ts +0 -1
  17. package/dist/bin/server.js +1 -1
  18. package/dist/components/color-picker/color-field.d.ts +0 -1
  19. package/dist/components/color-picker/color-picker.d.ts +12 -3
  20. package/dist/components/color-picker/custom-slider.d.ts +0 -1
  21. package/dist/components/color-picker/index.d.ts +0 -1
  22. package/dist/components/palette-chart/index.d.ts +0 -1
  23. package/dist/components/palette-chart/palette-chart.d.ts +0 -1
  24. package/dist/config/cluster-config.d.ts +0 -1
  25. package/dist/config/color-scheme-utils.d.ts +0 -1
  26. package/dist/config/color-schemes.d.ts +0 -1
  27. package/dist/config/panel-config.d.ts +19 -1
  28. package/dist/controls/dismiss-layer.d.ts +55 -0
  29. package/dist/controls/pill-slider-row.d.ts +0 -1
  30. package/dist/controls/role-button.d.ts +0 -1
  31. package/dist/controls/sanitize-css-value.d.ts +0 -1
  32. package/dist/controls/select-row.d.ts +0 -1
  33. package/dist/controls/slider-row.d.ts +0 -1
  34. package/dist/controls/text-row.d.ts +0 -1
  35. package/dist/controls/tier-ref-selector.d.ts +0 -1
  36. package/dist/controls/token-label.d.ts +0 -1
  37. package/dist/controls/tooltip.d.ts +0 -1
  38. package/dist/controls/use-dialog-backdrop-close.d.ts +32 -0
  39. package/dist/element-path/build-element-path.d.ts +0 -1
  40. package/dist/element-path/element-path-context.d.ts +0 -1
  41. package/dist/element-path/element-path-orchestrator.d.ts +0 -1
  42. package/dist/element-path/element-path-state.d.ts +3 -3
  43. package/dist/element-path/element-path-toast.d.ts +0 -1
  44. package/dist/element-path/element-path-toggle-button.d.ts +0 -1
  45. package/dist/element-path/index.d.ts +0 -1
  46. package/dist/element-path/inspector-overlay.d.ts +0 -1
  47. package/dist/export-modal.d.ts +0 -1
  48. package/dist/highlight/find-elements.d.ts +0 -1
  49. package/dist/highlight/highlight-orchestrator.d.ts +0 -1
  50. package/dist/highlight/highlight-overlay.d.ts +0 -1
  51. package/dist/highlight/highlight-settings-popover.d.ts +0 -1
  52. package/dist/highlight/highlight-state.d.ts +0 -1
  53. package/dist/highlight/highlight-toggle-button.d.ts +0 -1
  54. package/dist/import-modal.d.ts +0 -1
  55. package/dist/index.d.ts +39 -1
  56. package/dist/index.js +3067 -3956
  57. package/dist/{load-routing-XyKgftpe.js → load-routing-DtNTKoLW.js} +1 -1
  58. package/dist/panel-config-3tBEHjvZ.js +493 -0
  59. package/dist/panel.d.ts +0 -1
  60. package/dist/server/create-apply-handler.d.ts +0 -1
  61. package/dist/server/index.d.ts +0 -1
  62. package/dist/server/index.js +1 -1
  63. package/dist/server/load-routing.d.ts +0 -1
  64. package/dist/server/path-safety.d.ts +0 -1
  65. package/dist/server/serialize-write.d.ts +0 -1
  66. package/dist/state/autoload-state.d.ts +91 -0
  67. package/dist/state/persist.d.ts +0 -3
  68. package/dist/state/tweak-state.d.ts +47 -7
  69. package/dist/styles/z-index-tokens.d.ts +35 -0
  70. package/dist/tabs/_generic-item-editor.d.ts +0 -1
  71. package/dist/tabs/color-tab.d.ts +7 -5
  72. package/dist/tabs/font-tab.d.ts +0 -1
  73. package/dist/tabs/generic-tab.d.ts +1 -2
  74. package/dist/tabs/palette/palette-check-view.d.ts +0 -1
  75. package/dist/tabs/palette/palette-edit-view.d.ts +0 -1
  76. package/dist/tabs/palette/palette-readout.d.ts +0 -1
  77. package/dist/tabs/palette/palette-tab.d.ts +0 -1
  78. package/dist/tabs/size-tab.d.ts +0 -1
  79. package/dist/tabs/spacing-tab.d.ts +0 -1
  80. package/dist/testing.d.ts +0 -1
  81. package/dist/testing.js +2 -2
  82. package/dist/tokens/manifest.d.ts +0 -1
  83. package/dist/tokens/tier-model.d.ts +0 -1
  84. package/dist/tweak-state-BEx1SHu7.js +1773 -0
  85. package/dist/utils/color-convert.d.ts +0 -1
  86. package/dist/utils/color-hsla.d.ts +0 -1
  87. package/dist/utils/color-oklch.d.ts +0 -1
  88. package/dist/utils/copy-to-clipboard.d.ts +0 -1
  89. package/dist/utils/design-token-serde.d.ts +2 -2
  90. package/dist/utils/palette-curve.d.ts +0 -1
  91. package/dist/utils/structural-equal.d.ts +0 -1
  92. package/dist/utils/use-portal-mount.d.ts +0 -1
  93. package/dist/utils/wcag-contrast.d.ts +0 -1
  94. package/dist/zdtp.css +1 -1
  95. package/package.json +24 -11
  96. package/dist/apply/apply-token-overrides.d.ts.map +0 -1
  97. package/dist/apply/build-apply-overrides.d.ts.map +0 -1
  98. package/dist/apply/route-tokens-to-files.d.ts.map +0 -1
  99. package/dist/apply/tier-resolver.d.ts.map +0 -1
  100. package/dist/apply-modal.d.ts.map +0 -1
  101. package/dist/astro/host-adapter.d.ts.map +0 -1
  102. package/dist/astro/index.d.ts.map +0 -1
  103. package/dist/bin/cors.d.ts.map +0 -1
  104. package/dist/bin/parse-args.d.ts.map +0 -1
  105. package/dist/bin/server.d.ts.map +0 -1
  106. package/dist/components/color-picker/color-field.d.ts.map +0 -1
  107. package/dist/components/color-picker/color-picker.d.ts.map +0 -1
  108. package/dist/components/color-picker/custom-slider.d.ts.map +0 -1
  109. package/dist/components/color-picker/index.d.ts.map +0 -1
  110. package/dist/components/palette-chart/index.d.ts.map +0 -1
  111. package/dist/components/palette-chart/palette-chart.d.ts.map +0 -1
  112. package/dist/config/cluster-config.d.ts.map +0 -1
  113. package/dist/config/color-scheme-utils.d.ts.map +0 -1
  114. package/dist/config/color-schemes.d.ts.map +0 -1
  115. package/dist/config/panel-config.d.ts.map +0 -1
  116. package/dist/controls/pill-slider-row.d.ts.map +0 -1
  117. package/dist/controls/role-button.d.ts.map +0 -1
  118. package/dist/controls/sanitize-css-value.d.ts.map +0 -1
  119. package/dist/controls/select-row.d.ts.map +0 -1
  120. package/dist/controls/slider-row.d.ts.map +0 -1
  121. package/dist/controls/text-row.d.ts.map +0 -1
  122. package/dist/controls/tier-ref-selector.d.ts.map +0 -1
  123. package/dist/controls/token-label.d.ts.map +0 -1
  124. package/dist/controls/tooltip.d.ts.map +0 -1
  125. package/dist/element-path/build-element-path.d.ts.map +0 -1
  126. package/dist/element-path/element-path-context.d.ts.map +0 -1
  127. package/dist/element-path/element-path-orchestrator.d.ts.map +0 -1
  128. package/dist/element-path/element-path-state.d.ts.map +0 -1
  129. package/dist/element-path/element-path-toast.d.ts.map +0 -1
  130. package/dist/element-path/element-path-toggle-button.d.ts.map +0 -1
  131. package/dist/element-path/index.d.ts.map +0 -1
  132. package/dist/element-path/inspector-overlay.d.ts.map +0 -1
  133. package/dist/export-modal.d.ts.map +0 -1
  134. package/dist/highlight/find-elements.d.ts.map +0 -1
  135. package/dist/highlight/highlight-orchestrator.d.ts.map +0 -1
  136. package/dist/highlight/highlight-overlay.d.ts.map +0 -1
  137. package/dist/highlight/highlight-settings-popover.d.ts.map +0 -1
  138. package/dist/highlight/highlight-state.d.ts.map +0 -1
  139. package/dist/highlight/highlight-toggle-button.d.ts.map +0 -1
  140. package/dist/import-modal.d.ts.map +0 -1
  141. package/dist/index.d.ts.map +0 -1
  142. package/dist/panel-config-066BPYJD.js +0 -411
  143. package/dist/panel.d.ts.map +0 -1
  144. package/dist/server/create-apply-handler.d.ts.map +0 -1
  145. package/dist/server/index.d.ts.map +0 -1
  146. package/dist/server/load-routing.d.ts.map +0 -1
  147. package/dist/server/path-safety.d.ts.map +0 -1
  148. package/dist/server/serialize-write.d.ts.map +0 -1
  149. package/dist/state/persist.d.ts.map +0 -1
  150. package/dist/state/tweak-state.d.ts.map +0 -1
  151. package/dist/tabs/_generic-item-editor.d.ts.map +0 -1
  152. package/dist/tabs/color-tab.d.ts.map +0 -1
  153. package/dist/tabs/font-tab.d.ts.map +0 -1
  154. package/dist/tabs/generic-tab.d.ts.map +0 -1
  155. package/dist/tabs/palette/palette-check-view.d.ts.map +0 -1
  156. package/dist/tabs/palette/palette-edit-view.d.ts.map +0 -1
  157. package/dist/tabs/palette/palette-readout.d.ts.map +0 -1
  158. package/dist/tabs/palette/palette-tab.d.ts.map +0 -1
  159. package/dist/tabs/size-tab.d.ts.map +0 -1
  160. package/dist/tabs/spacing-tab.d.ts.map +0 -1
  161. package/dist/testing.d.ts.map +0 -1
  162. package/dist/tokens/manifest.d.ts.map +0 -1
  163. package/dist/tokens/tier-model.d.ts.map +0 -1
  164. package/dist/tweak-state-Do5gj6Nw.js +0 -730
  165. package/dist/utils/color-convert.d.ts.map +0 -1
  166. package/dist/utils/color-hsla.d.ts.map +0 -1
  167. package/dist/utils/color-oklch.d.ts.map +0 -1
  168. package/dist/utils/copy-to-clipboard.d.ts.map +0 -1
  169. package/dist/utils/design-token-serde.d.ts.map +0 -1
  170. package/dist/utils/palette-curve.d.ts.map +0 -1
  171. package/dist/utils/structural-equal.d.ts.map +0 -1
  172. package/dist/utils/use-portal-mount.d.ts.map +0 -1
  173. package/dist/utils/wcag-contrast.d.ts.map +0 -1
@@ -146,7 +146,7 @@ function L(e) {
146
146
  return e.replace(/\/\*[\s\S]*?\*\//g, (r) => " ".repeat(r.length));
147
147
  }
148
148
  function U(e, r, t) {
149
- const n = r.startsWith("--") ? r.slice(2) : r, o = H(n), s = new RegExp("(--" + o + ":)(\\s*)([\\s\\S]+?);"), a = L(e), l = s.exec(a);
149
+ const n = r.startsWith("--") ? r.slice(2) : r, o = H(n), s = new RegExp("(?<![\\w-])(--" + o + ":)(\\s*)([\\s\\S]+?);"), a = L(e), l = s.exec(a);
150
150
  if (!l) return { content: e, status: "unknown" };
151
151
  const [k, c, f] = l, y = l.index, w = y + k.length, v = y + c.length + f.length, p = w - 1, O = e.slice(v, p).trim(), S = t.trim();
152
152
  return O === S ? { content: e, status: "unchanged" } : { content: e.slice(0, y) + c + f + t + ";" + e.slice(w), status: "changed" };
@@ -0,0 +1,493 @@
1
+ function j(e, t) {
2
+ return e.paletteCssVarTemplate.replace("{n}", String(t));
3
+ }
4
+ function b(e) {
5
+ const t = e.colorExtras;
6
+ if (!t) return;
7
+ const r = e.tiers.find(
8
+ (a) => !a.referencesTier && a.items.length > 0 && a.items[0].type.kind === "color"
9
+ );
10
+ if (!r)
11
+ return {
12
+ id: t.id,
13
+ label: t.label,
14
+ paletteSize: 0,
15
+ baseRoles: t.baseRoles,
16
+ paletteCssVarTemplate: "--zudo-stub-p{n}",
17
+ semanticDefaults: {},
18
+ semanticCssNames: {},
19
+ baseDefaults: t.baseDefaults,
20
+ defaultShikiTheme: t.defaultShikiTheme,
21
+ colorSchemes: t.colorSchemes,
22
+ panelSettings: t.panelSettings
23
+ };
24
+ const i = r.items, u = i.length, s = (i[0]?.cssVar ?? "--palette-{n}").replace(/\d+$/, "{n}"), c = /* @__PURE__ */ new Map();
25
+ for (let a = 0; a < i.length; a++)
26
+ c.set(i[a].id, a);
27
+ const f = e.tiers.find(
28
+ (a) => a.referencesTier === r.id
29
+ ), n = {}, l = {};
30
+ if (f)
31
+ for (const a of f.items) {
32
+ l[a.id] = a.cssVar;
33
+ const d = c.get(a.default);
34
+ n[a.id] = d ?? 0;
35
+ }
36
+ return {
37
+ id: t.id,
38
+ label: t.label,
39
+ paletteSize: u,
40
+ baseRoles: t.baseRoles,
41
+ paletteCssVarTemplate: s,
42
+ semanticDefaults: n,
43
+ semanticCssNames: l,
44
+ baseDefaults: t.baseDefaults,
45
+ defaultShikiTheme: t.defaultShikiTheme,
46
+ colorSchemes: t.colorSchemes,
47
+ panelSettings: t.panelSettings
48
+ };
49
+ }
50
+ function V(e) {
51
+ const t = e.find((r) => r.id === "color");
52
+ if (t)
53
+ return b(t);
54
+ }
55
+ function $(e) {
56
+ const t = e.find((r) => r.id === "color-secondary");
57
+ return t ? b(t) ?? null : null;
58
+ }
59
+ function y(e, t) {
60
+ if (Object.is(e, t)) return !0;
61
+ if (e === null || t === null || typeof e != typeof t || typeof e != "object") return !1;
62
+ if (Array.isArray(e)) {
63
+ if (!Array.isArray(t) || e.length !== t.length) return !1;
64
+ for (let o = 0; o < e.length; o++)
65
+ if (!y(e[o], t[o])) return !1;
66
+ return !0;
67
+ }
68
+ if (Array.isArray(t)) return !1;
69
+ const r = Object.keys(e), i = Object.keys(t);
70
+ if (r.length !== i.length) return !1;
71
+ const u = new Set(i);
72
+ for (const o of r)
73
+ if (!u.has(o) || !y(e[o], t[o]))
74
+ return !1;
75
+ return !0;
76
+ }
77
+ const k = {
78
+ storagePrefix: "zudo-design-token-panel",
79
+ consoleNamespace: "zudo",
80
+ modalClassPrefix: "zudo-design-token-panel-modal",
81
+ schemaId: "zudo-design-tokens/v1",
82
+ exportFilenameBase: "zudo-design-tokens",
83
+ // Empty tab list — hosts MUST configure real tabs via configurePanel().
84
+ tabs: [],
85
+ colorPresets: {},
86
+ // No bundled apply endpoint / routing — hosts wire their own.
87
+ applyEndpoint: void 0,
88
+ applyRouting: void 0
89
+ }, w = /* @__PURE__ */ Symbol.for("@takazudo/zdtp:singleton");
90
+ function g() {
91
+ const e = globalThis;
92
+ let t = e[w];
93
+ return t || (t = {
94
+ instances: /* @__PURE__ */ new Map(),
95
+ defaultPrefix: null,
96
+ pendingColorPresets: null,
97
+ pendingPostConfigureHooks: [],
98
+ lifecycleHooks: {}
99
+ }, e[w] = t), t;
100
+ }
101
+ function E(e) {
102
+ return {
103
+ instanceId: e,
104
+ open() {
105
+ g().lifecycleHooks.open?.(e);
106
+ },
107
+ close() {
108
+ g().lifecycleHooks.close?.(e);
109
+ },
110
+ toggle() {
111
+ g().lifecycleHooks.toggle?.(e);
112
+ },
113
+ destroy() {
114
+ g().lifecycleHooks.destroy?.(e);
115
+ const t = g();
116
+ if (t.instances.delete(e), t.defaultPrefix === e) {
117
+ const r = [...t.instances.keys()];
118
+ t.defaultPrefix = r.length > 0 ? r[r.length - 1] : null;
119
+ }
120
+ }
121
+ };
122
+ }
123
+ function R(e) {
124
+ g().lifecycleHooks = {
125
+ configured: e.configured,
126
+ open: e.open,
127
+ close: e.close,
128
+ toggle: e.toggle,
129
+ destroy: e.destroy
130
+ };
131
+ }
132
+ function _(e) {
133
+ const t = g(), r = e.storagePrefix, i = t.instances.get(r);
134
+ if (i) {
135
+ const n = (l) => ({ ...l, applySink: void 0 });
136
+ if (y(n(i.suppliedConfig), n(e)))
137
+ return t.defaultPrefix = r, i.handle;
138
+ throw new Error(
139
+ `[design-token-panel] configurePanel() was already called with different values for storagePrefix "${r}". Configuration is one-shot per prefix per page lifecycle. To re-configure this prefix, call handle.destroy() first, then configurePanel() again. (Use a distinct storagePrefix for a second panel instance.)`
140
+ );
141
+ }
142
+ const u = t.pendingColorPresets, o = u ? { ...e, colorPresets: u } : { ...e };
143
+ t.pendingColorPresets = null;
144
+ const s = t.instances.size === 0, c = s ? [...t.pendingPostConfigureHooks] : [];
145
+ s && (t.pendingPostConfigureHooks.length = 0);
146
+ const f = {
147
+ config: o,
148
+ // Snapshot the as-supplied config before any runtime merges. Used by the
149
+ // idempotency guard so view-transition re-calls with the original inline
150
+ // config keep passing even after setPanelColorPresets mutates `config`.
151
+ suppliedConfig: { ...e },
152
+ pendingColorPresets: null,
153
+ postConfigureHooks: c,
154
+ handle: E(r)
155
+ };
156
+ t.instances.set(r, f), t.defaultPrefix = r;
157
+ for (const n of f.postConfigureHooks)
158
+ n();
159
+ return t.lifecycleHooks.configured?.(r), f.handle;
160
+ }
161
+ function m() {
162
+ const e = g();
163
+ return e.defaultPrefix === null ? null : e.instances.get(e.defaultPrefix) ?? null;
164
+ }
165
+ function M(e) {
166
+ const t = m();
167
+ if (t === null) {
168
+ const r = g();
169
+ if (r.pendingPostConfigureHooks.includes(e)) return;
170
+ r.pendingPostConfigureHooks.push(e);
171
+ return;
172
+ }
173
+ t.postConfigureHooks.includes(e) || (t.postConfigureHooks.push(e), e());
174
+ }
175
+ function C() {
176
+ return m()?.config ?? k;
177
+ }
178
+ function H() {
179
+ return [...g().instances.values()].map((e) => e.config);
180
+ }
181
+ function O(e) {
182
+ return g().instances.get(e)?.config ?? null;
183
+ }
184
+ function N() {
185
+ const e = g();
186
+ e.instances.clear(), e.defaultPrefix = null, e.pendingColorPresets = null, e.pendingPostConfigureHooks.length = 0;
187
+ }
188
+ function K(e = C()) {
189
+ return $(e.tabs);
190
+ }
191
+ function z(e) {
192
+ return `${e.storagePrefix}-state-v2`;
193
+ }
194
+ function D(e) {
195
+ return `${e.storagePrefix}-state-v3`;
196
+ }
197
+ function F(e) {
198
+ return `${e.storagePrefix}-state`;
199
+ }
200
+ function J(e) {
201
+ return `${e.storagePrefix}-open`;
202
+ }
203
+ function B(e) {
204
+ return `${e.storagePrefix}-position`;
205
+ }
206
+ function L(e) {
207
+ return `${e.storagePrefix}-size`;
208
+ }
209
+ function G(e) {
210
+ return `${e.storagePrefix}-density`;
211
+ }
212
+ function I(e) {
213
+ return `${e.storagePrefix}:visible`;
214
+ }
215
+ function U(e) {
216
+ return `${e.storagePrefix}:autoload`;
217
+ }
218
+ function q(e) {
219
+ return `${e.storagePrefix}-root`;
220
+ }
221
+ const x = k.storagePrefix, S = "toggle-design-token-panel";
222
+ function Y(e) {
223
+ return e.storagePrefix === x ? S : e.toggleEvent ?? `toggle-${e.storagePrefix}`;
224
+ }
225
+ const A = "__zdtp:open-state-changed";
226
+ function W(e) {
227
+ return `${A}:${e.storagePrefix}`;
228
+ }
229
+ function X(e, t) {
230
+ return `${e.modalClassPrefix}${t}`;
231
+ }
232
+ function Q(e) {
233
+ return `${e.exportFilenameBase}.json`;
234
+ }
235
+ function Z(e) {
236
+ if (e === null || typeof e != "object" || Array.isArray(e))
237
+ throw new Error("[design-token-panel] PanelConfig must be a non-null object");
238
+ const t = e;
239
+ for (const r of [
240
+ "storagePrefix",
241
+ "consoleNamespace",
242
+ "modalClassPrefix",
243
+ "schemaId",
244
+ "exportFilenameBase"
245
+ ])
246
+ if (typeof t[r] != "string" || t[r].length === 0)
247
+ throw new Error(
248
+ `[design-token-panel] PanelConfig.${r} must be a non-empty string (got ${typeof t[r]})`
249
+ );
250
+ if (v(t.tabs), t.toggleEvent !== void 0 && (typeof t.toggleEvent != "string" || t.toggleEvent.length === 0))
251
+ throw new Error(
252
+ `[design-token-panel] PanelConfig.toggleEvent must be a non-empty string when set (got ${typeof t.toggleEvent})`
253
+ );
254
+ if (t.applyEndpoint !== void 0 && typeof t.applyEndpoint != "string")
255
+ throw new Error(
256
+ `[design-token-panel] PanelConfig.applyEndpoint must be a string when set (got ${typeof t.applyEndpoint})`
257
+ );
258
+ if (t.applyRouting !== void 0) {
259
+ if (t.applyRouting === null || typeof t.applyRouting != "object" || Array.isArray(t.applyRouting))
260
+ throw new Error("[design-token-panel] PanelConfig.applyRouting must be a plain object");
261
+ for (const [r, i] of Object.entries(t.applyRouting))
262
+ if (typeof i != "string")
263
+ throw new Error(
264
+ `[design-token-panel] PanelConfig.applyRouting[${JSON.stringify(r)}] must be a string`
265
+ );
266
+ }
267
+ if (t.legacyIdRenameMap !== void 0) {
268
+ if (t.legacyIdRenameMap === null || typeof t.legacyIdRenameMap != "object" || Array.isArray(t.legacyIdRenameMap))
269
+ throw new Error("[design-token-panel] PanelConfig.legacyIdRenameMap must be a plain object");
270
+ for (const [r, i] of Object.entries(t.legacyIdRenameMap))
271
+ if (i !== null && typeof i != "string")
272
+ throw new Error(
273
+ `[design-token-panel] PanelConfig.legacyIdRenameMap[${JSON.stringify(r)}] must be a string or null (got ${typeof i})`
274
+ );
275
+ }
276
+ }
277
+ function v(e) {
278
+ if (!Array.isArray(e))
279
+ throw new Error("[design-token-panel] PanelConfig.tabs must be an array");
280
+ const t = /* @__PURE__ */ new Set();
281
+ for (const r of e) {
282
+ if (r === null || typeof r != "object" || Array.isArray(r))
283
+ throw new Error("[design-token-panel] PanelConfig.tabs: each tab must be a non-null object");
284
+ const i = r;
285
+ if (typeof i.id != "string" || i.id.length === 0)
286
+ throw new Error("[design-token-panel] PanelConfig.tabs: each tab must have a non-empty string id");
287
+ if (t.has(i.id))
288
+ throw new Error(
289
+ `[design-token-panel] PanelConfig.tabs: duplicate tab id "${i.id}"`
290
+ );
291
+ t.add(i.id), T(i.id, i);
292
+ }
293
+ }
294
+ function T(e, t) {
295
+ if (!Array.isArray(t.tiers))
296
+ throw new Error(
297
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers must be an array`
298
+ );
299
+ const r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Map();
300
+ for (const o of t.tiers) {
301
+ if (o === null || typeof o != "object" || Array.isArray(o))
302
+ throw new Error(
303
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers: each tier must be a non-null object`
304
+ );
305
+ const s = o;
306
+ if (typeof s.id != "string" || s.id.length === 0)
307
+ throw new Error(
308
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers: each tier must have a non-empty string id`
309
+ );
310
+ if (r.has(s.id))
311
+ throw new Error(
312
+ `[design-token-panel] PanelConfig.tabs["${e}"]: duplicate tier id "${s.id}"`
313
+ );
314
+ if (r.add(s.id), !Array.isArray(s.items))
315
+ throw new Error(
316
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${s.id}"].items must be an array`
317
+ );
318
+ let c;
319
+ for (const f of s.items) {
320
+ if (f === null || typeof f != "object" || Array.isArray(f)) continue;
321
+ const l = f.type;
322
+ if (l === null || typeof l != "object" || Array.isArray(l)) continue;
323
+ const a = l.kind;
324
+ if (typeof a == "string") {
325
+ if (c === void 0)
326
+ c = a;
327
+ else if (c !== a)
328
+ throw new Error(
329
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${s.id}"]: mixed item kinds — found "${c}" and "${a}" in the same tier (all items must share the same kind)`
330
+ );
331
+ }
332
+ }
333
+ c !== void 0 && i.set(s.id, c);
334
+ }
335
+ const u = /* @__PURE__ */ new Set();
336
+ for (const o of t.tiers) {
337
+ const s = o, c = s.id;
338
+ for (const f of s.items) {
339
+ if (f === null || typeof f != "object" || Array.isArray(f))
340
+ throw new Error(
341
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${c}"].items: each item must be a non-null object`
342
+ );
343
+ const n = f;
344
+ if (typeof n.id != "string" || n.id.length === 0)
345
+ throw new Error(
346
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${c}"].items: each item must have a non-empty string id`
347
+ );
348
+ if (u.has(n.id))
349
+ throw new Error(
350
+ `[design-token-panel] PanelConfig.tabs["${e}"]: duplicate item id "${n.id}" (item ids must be unique across all tiers within a tab)`
351
+ );
352
+ if (u.add(n.id), typeof n.cssVar != "string" || !n.cssVar.startsWith("--"))
353
+ throw new Error(
354
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${c}"].items["${n.id}"].cssVar must start with "--" (got ${JSON.stringify(n.cssVar)})`
355
+ );
356
+ if (n.cssVar.length <= 2)
357
+ throw new Error(
358
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${c}"].items["${n.id}"].cssVar must be non-empty after "--"`
359
+ );
360
+ }
361
+ }
362
+ for (const o of t.tiers) {
363
+ const s = o, c = s.id;
364
+ if (s.referencesTier !== void 0) {
365
+ if (typeof s.referencesTier != "string")
366
+ throw new Error(
367
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${c}"].referencesTier must be a string`
368
+ );
369
+ const f = s.referencesTier;
370
+ if (!r.has(f))
371
+ throw new Error(
372
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${c}"].referencesTier: tier "${f}" does not exist in this tab`
373
+ );
374
+ const n = i.get(c), l = i.get(f);
375
+ if (n !== void 0 && l !== void 0 && n !== "text" && n !== l)
376
+ throw new Error(
377
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${c}"].referencesTier: referencing tier has kind "${n}" but referenced tier "${f}" has kind "${l}" (cross-kind reference is only allowed when the referencing tier has kind "text")`
378
+ );
379
+ }
380
+ }
381
+ if (t.colorExtras !== void 0) {
382
+ const o = t.colorExtras;
383
+ if (o === null || typeof o != "object" || Array.isArray(o))
384
+ throw new Error(
385
+ `[design-token-panel] PanelConfig.tabs["${e}"].colorExtras must be a plain object`
386
+ );
387
+ for (const n of ["id", "defaultShikiTheme"])
388
+ if (typeof o[n] != "string" || o[n].length === 0)
389
+ throw new Error(
390
+ `[design-token-panel] PanelConfig.tabs["${e}"].colorExtras.${n} must be a non-empty string (got ${typeof o[n]})`
391
+ );
392
+ for (const n of ["colorSchemes", "baseRoles", "baseDefaults"])
393
+ if (o[n] === void 0 || o[n] === null || typeof o[n] != "object" || Array.isArray(o[n]))
394
+ throw new Error(
395
+ `[design-token-panel] PanelConfig.tabs["${e}"].colorExtras.${n} must be a plain object`
396
+ );
397
+ if (o.panelSettings === void 0 || o.panelSettings === null || typeof o.panelSettings != "object" || Array.isArray(o.panelSettings))
398
+ throw new Error(
399
+ `[design-token-panel] PanelConfig.tabs["${e}"].colorExtras.panelSettings must be a plain object`
400
+ );
401
+ const s = o.panelSettings;
402
+ if (typeof s.colorScheme != "string" || s.colorScheme.length === 0)
403
+ throw new Error(
404
+ `[design-token-panel] PanelConfig.tabs["${e}"].colorExtras.panelSettings.colorScheme must be a non-empty string`
405
+ );
406
+ if (s.colorMode !== !1) {
407
+ if (s.colorMode === null || typeof s.colorMode != "object" || Array.isArray(s.colorMode))
408
+ throw new Error(
409
+ `[design-token-panel] PanelConfig.tabs["${e}"].colorExtras.panelSettings.colorMode must be false or a plain object`
410
+ );
411
+ const n = s.colorMode;
412
+ for (const l of ["lightScheme", "darkScheme"])
413
+ if (typeof n[l] != "string" || n[l].length === 0)
414
+ throw new Error(
415
+ `[design-token-panel] PanelConfig.tabs["${e}"].colorExtras.panelSettings.colorMode.${l} must be a non-empty string`
416
+ );
417
+ if (n.defaultMode !== "light" && n.defaultMode !== "dark")
418
+ throw new Error(
419
+ `[design-token-panel] PanelConfig.tabs["${e}"].colorExtras.panelSettings.colorMode.defaultMode must be "light" or "dark" (got ${JSON.stringify(n.defaultMode)})`
420
+ );
421
+ }
422
+ const f = t.tiers.find((n) => {
423
+ if (n.referencesTier !== void 0) return !1;
424
+ const l = n.items;
425
+ if (!Array.isArray(l) || l.length === 0) return !1;
426
+ const a = l[0];
427
+ if (a === null || typeof a != "object" || Array.isArray(a)) return !1;
428
+ const d = a.type;
429
+ return d === null || typeof d != "object" || Array.isArray(d) ? !1 : d.kind === "color";
430
+ });
431
+ if (f) {
432
+ const n = f.id, l = f.items, a = l[0]?.cssVar;
433
+ if (a !== void 0) {
434
+ const d = a.replace(/\d+$/, "{n}");
435
+ if (d.includes("{n}"))
436
+ for (let p = 0; p < l.length; p++) {
437
+ const h = l[p], P = d.replace("{n}", String(p));
438
+ if (h.cssVar !== P)
439
+ throw new Error(
440
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${n}"].items[${p}].cssVar is ${JSON.stringify(h.cssVar)} but expected ${JSON.stringify(P)} — palette item cssVars must share one prefix and be numbered 0..n-1 in tier order (template derived from first item: ${JSON.stringify(d)})`
441
+ );
442
+ }
443
+ else if (l.length > 1)
444
+ throw new Error(
445
+ `[design-token-panel] PanelConfig.tabs["${e}"].tiers["${n}"].items[0].cssVar ${JSON.stringify(a)} has no trailing digit — palette item cssVars must share one prefix and be numbered 0..n-1 in tier order (e.g. "--pal-0" … "--pal-15")`
446
+ );
447
+ }
448
+ }
449
+ }
450
+ }
451
+ function ee(e = C()) {
452
+ return e.applyRouting ?? {};
453
+ }
454
+ function te(e) {
455
+ const t = m();
456
+ if (t === null) {
457
+ g().pendingColorPresets = e;
458
+ return;
459
+ }
460
+ t.config = { ...t.config, colorPresets: e };
461
+ }
462
+ export {
463
+ L as A,
464
+ G as B,
465
+ S as D,
466
+ N as _,
467
+ I as a,
468
+ z as b,
469
+ _ as c,
470
+ D as d,
471
+ Z as e,
472
+ J as f,
473
+ C as g,
474
+ B as h,
475
+ F as i,
476
+ U as j,
477
+ Q as k,
478
+ y as l,
479
+ X as m,
480
+ K as n,
481
+ ee as o,
482
+ b as p,
483
+ W as q,
484
+ j as r,
485
+ te as s,
486
+ R as t,
487
+ M as u,
488
+ Y as v,
489
+ H as w,
490
+ O as x,
491
+ q as y,
492
+ V as z
493
+ };
package/dist/panel.d.ts CHANGED
@@ -16,4 +16,3 @@ interface DesignTokenTweakPanelProps {
16
16
  }
17
17
  export default function DesignTokenTweakPanel({ instanceConfig: instanceConfigProp, }?: DesignTokenTweakPanelProps): import("preact").JSX.Element;
18
18
  export type { TweakState } from './state/tweak-state';
19
- //# sourceMappingURL=panel.d.ts.map
@@ -45,4 +45,3 @@ export interface PerFileResult {
45
45
  * ```
46
46
  */
47
47
  export declare function createApplyHandler(options: ApplyHandlerOptions): (req: Request) => Promise<Response>;
48
- //# sourceMappingURL=create-apply-handler.d.ts.map
@@ -21,4 +21,3 @@ export type { ApplyHandlerOptions, PerFileResult } from './create-apply-handler'
21
21
  export { serializeFileWrite } from './serialize-write';
22
22
  export { CSS_VAR_NAME_RE, isPathSafe, isValidCssVarName, validateAndSanitizeTokens, } from './path-safety';
23
23
  export { loadRoutingFromFile, type ApplyRoutingMap } from './load-routing';
24
- //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,4 @@
1
- import { C as s, c as i, i as l, a as r, l as t, s as o, v as d } from "../load-routing-XyKgftpe.js";
1
+ import { C as s, c as i, i as l, a as r, l as t, s as o, v as d } from "../load-routing-DtNTKoLW.js";
2
2
  export {
3
3
  s as CSS_VAR_NAME_RE,
4
4
  i as createApplyHandler,
@@ -36,4 +36,3 @@ export type ApplyRoutingMap = Record<string, string>;
36
36
  * ```
37
37
  */
38
38
  export declare function loadRoutingFromFile(absPath: string): ApplyRoutingMap;
39
- //# sourceMappingURL=load-routing.d.ts.map
@@ -33,4 +33,3 @@ export declare function validateAndSanitizeTokens(tokens: Record<string, unknown
33
33
  sanitized?: Record<string, string>;
34
34
  error?: string;
35
35
  };
36
- //# sourceMappingURL=path-safety.d.ts.map
@@ -4,4 +4,3 @@
4
4
  * one settles (success or error). Calls for different paths run in parallel.
5
5
  */
6
6
  export declare function serializeFileWrite<T>(absPath: string, fn: () => Promise<T>): Promise<T>;
7
- //# sourceMappingURL=serialize-write.d.ts.map
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Owner-autoload — persisted feature state and feature contract.
3
+ *
4
+ * ## Flag semantics
5
+ *
6
+ * `${storagePrefix}:autoload` (written as `'1'` when armed, `'0'` or absent
7
+ * when not) is the owner-mode flag. It means:
8
+ * "This browser visited the site as the site owner — autoload the
9
+ * design-token panel on every subsequent page visit."
10
+ *
11
+ * ## General-visitor vs owner behavior
12
+ *
13
+ * - **General visitor** (flag absent or `!== '1'`): the panel bundle is NOT
14
+ * eagerly fetched. Gate #1 (`shouldAutoload`) returns false, so no bundle
15
+ * request fires on page load. The panel remains entirely invisible.
16
+ * - **Owner** (flag === `'1'`): Gate #1 fires, the host-adapter fetches the
17
+ * bundle eagerly, and Gate #2 (`reapplyFromStorage` in `index.tsx`) mounts
18
+ * the Preact shell CLOSED so the element-path inspector is available even
19
+ * while the panel UI is hidden.
20
+ *
21
+ * ## enableAutoload() / disableAutoload() contract (implemented by S2 #419)
22
+ *
23
+ * `enableAutoload()` (console API, wired by S2):
24
+ * 1. Sets `:autoload = '1'`.
25
+ * 2. Sets `-elpath-enabled = '1'` once (arms the alt+click inspector).
26
+ * 3. Loads the panel bundle (if not already loaded).
27
+ * 4. Mounts the Preact shell CLOSED via `hideInstance`.
28
+ *
29
+ * `disableAutoload()` (console API, wired by S2):
30
+ * 1. Clears `:autoload`.
31
+ * 2. Clears `:visible`.
32
+ * 3. Clears `-elpath-enabled`.
33
+ * 4. Clears the open-state key (`getOpenKey(cfg)` from `state/tweak-state`).
34
+ * 5. Unmounts the Preact shell.
35
+ *
36
+ * ## Auto-remember
37
+ *
38
+ * Any action that shows the panel (console `showDesignPanel()`, the header-
39
+ * button open event, or the `showInstance` path in `index.tsx`) MUST also
40
+ * write `:autoload = '1'`. Once an owner opens the panel the flag is set so
41
+ * subsequent page loads reload it automatically. (Wired by S2 / S3.)
42
+ *
43
+ * ## Element-path coupling
44
+ *
45
+ * `enableAutoload()` arms the element-path inspector by writing
46
+ * `-elpath-enabled = '1'` once. The user can still turn it off later via the
47
+ * in-panel toggle. The inspector overlay requires the Preact shell to be
48
+ * mounted (it runs inside `ElementPathOrchestrator`), so the CLOSED mount
49
+ * keeps the overlay functional even when the panel UI itself is hidden.
50
+ *
51
+ * ## The two gates that must consider autoload
52
+ *
53
+ * Gate #1 — host-adapter eager-load gate: the host adapter (e.g.
54
+ * `astro/host-adapter.ts`) decides whether to FETCH the panel bundle on page
55
+ * load. It MUST call `shouldAutoload(cfg)` and skip the fetch when the result
56
+ * is false. This keeps general-visitor page loads entirely free of the bundle
57
+ * request.
58
+ *
59
+ * Gate #2 — `index.tsx reapplyFromStorage`: the existing `reapplyFromStorage`
60
+ * function mounts the shell CLOSED when `hasPersistedOverrides(cfg)` or
61
+ * `loadElementPathEnabled()` is true. It MUST also trigger on
62
+ * `shouldAutoload(cfg)` so an owner-mode page load mounts the Preact shell
63
+ * (and therefore the element-path inspector) even when no token overrides
64
+ * are persisted yet.
65
+ */
66
+ import type { PanelConfig } from '../config/panel-config';
67
+ /**
68
+ * Return `true` iff this browser has the owner-autoload flag set.
69
+ *
70
+ * SSR-safe (returns `false` when `window` is not available) and quota-
71
+ * tolerant (returns `false` on any storage error). Reads exactly
72
+ * `${cfg.storagePrefix}:autoload` and matches against the literal string
73
+ * `'1'`; any other stored value (including `'0'` or an absent key) is `false`.
74
+ */
75
+ export declare function shouldAutoload(cfg: PanelConfig): boolean;
76
+ /**
77
+ * Write the owner-autoload flag. Pass `true` to arm autoload (`'1'`), `false`
78
+ * to disarm (`'0'`). SSR-safe and quota-tolerant — errors are swallowed
79
+ * silently so this never throws in restricted storage contexts.
80
+ *
81
+ * Prefer `clearAutoload` when you want to fully remove the key (e.g. on
82
+ * `disableAutoload`) rather than leave a `'0'` sentinel.
83
+ */
84
+ export declare function setAutoload(cfg: PanelConfig, on: boolean): void;
85
+ /**
86
+ * Remove the owner-autoload flag from storage entirely.
87
+ *
88
+ * Called by `disableAutoload()` (S2) as part of the full owner-mode teardown.
89
+ * SSR-safe and quota-tolerant.
90
+ */
91
+ export declare function clearAutoload(cfg: PanelConfig): void;
@@ -33,7 +33,6 @@ export declare function usePersist(setState: SetState<TweakState>, cfg?: PanelCo
33
33
  persistTypography: (updater: (prev: TokenOverrides) => TokenOverrides) => void;
34
34
  persistFont: (updater: (prev: TokenOverrides) => TokenOverrides) => void;
35
35
  persistSize: (updater: (prev: TokenOverrides) => TokenOverrides) => void;
36
- persistPanelPosition: (updater: (prev: TweakState["panelPosition"]) => TweakState["panelPosition"]) => void;
37
36
  persistSecondary: (updater: (prev: ColorTweakState | undefined) => ColorTweakState | undefined) => void;
38
37
  };
39
38
  export type Persist = ReturnType<typeof usePersist>['persist'];
@@ -44,7 +43,5 @@ export type PersistTypography = ReturnType<typeof usePersist>['persistTypography
44
43
  /** Upstream alias for `PersistTypography`. See `persistFont` above. */
45
44
  export type PersistFont = PersistTypography;
46
45
  export type PersistSize = ReturnType<typeof usePersist>['persistSize'];
47
- export type PersistPanelPosition = ReturnType<typeof usePersist>['persistPanelPosition'];
48
46
  export type PersistSecondary = ReturnType<typeof usePersist>['persistSecondary'];
49
47
  export {};
50
- //# sourceMappingURL=persist.d.ts.map