@takazudo/zdtp 0.1.0-next.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.
Files changed (130) hide show
  1. package/CHANGELOG.md +107 -0
  2. package/LICENSE +21 -0
  3. package/README.md +1044 -0
  4. package/dist/apply/apply-token-overrides.d.ts +81 -0
  5. package/dist/apply/apply-token-overrides.d.ts.map +1 -0
  6. package/dist/apply/build-apply-overrides.d.ts +71 -0
  7. package/dist/apply/build-apply-overrides.d.ts.map +1 -0
  8. package/dist/apply/route-tokens-to-files.d.ts +65 -0
  9. package/dist/apply/route-tokens-to-files.d.ts.map +1 -0
  10. package/dist/apply/tier-resolver.d.ts +75 -0
  11. package/dist/apply/tier-resolver.d.ts.map +1 -0
  12. package/dist/apply-modal.d.ts +49 -0
  13. package/dist/apply-modal.d.ts.map +1 -0
  14. package/dist/astro/DesignTokenPanelHost.astro +76 -0
  15. package/dist/astro/host-adapter.d.ts +47 -0
  16. package/dist/astro/host-adapter.d.ts.map +1 -0
  17. package/dist/astro/host-adapter.js +81 -0
  18. package/dist/astro/index.d.ts +30 -0
  19. package/dist/astro/index.d.ts.map +1 -0
  20. package/dist/astro/index.js +54 -0
  21. package/dist/bin/cors.d.ts +24 -0
  22. package/dist/bin/cors.d.ts.map +1 -0
  23. package/dist/bin/parse-args.d.ts +38 -0
  24. package/dist/bin/parse-args.d.ts.map +1 -0
  25. package/dist/bin/server.d.ts +23 -0
  26. package/dist/bin/server.d.ts.map +1 -0
  27. package/dist/bin/server.js +283 -0
  28. package/dist/color-schemes-CgzOBqGO.js +85 -0
  29. package/dist/components/color-picker/color-picker.d.ts +64 -0
  30. package/dist/components/color-picker/color-picker.d.ts.map +1 -0
  31. package/dist/components/color-picker/custom-slider.d.ts +25 -0
  32. package/dist/components/color-picker/custom-slider.d.ts.map +1 -0
  33. package/dist/components/color-picker/index.d.ts +3 -0
  34. package/dist/components/color-picker/index.d.ts.map +1 -0
  35. package/dist/config/cluster-config.d.ts +135 -0
  36. package/dist/config/cluster-config.d.ts.map +1 -0
  37. package/dist/config/color-scheme-utils.d.ts +105 -0
  38. package/dist/config/color-scheme-utils.d.ts.map +1 -0
  39. package/dist/config/color-schemes.d.ts +83 -0
  40. package/dist/config/color-schemes.d.ts.map +1 -0
  41. package/dist/config/panel-config.d.ts +258 -0
  42. package/dist/config/panel-config.d.ts.map +1 -0
  43. package/dist/controls/pill-slider-row.d.ts +37 -0
  44. package/dist/controls/pill-slider-row.d.ts.map +1 -0
  45. package/dist/controls/role-button.d.ts +18 -0
  46. package/dist/controls/role-button.d.ts.map +1 -0
  47. package/dist/controls/sanitize-css-value.d.ts +22 -0
  48. package/dist/controls/sanitize-css-value.d.ts.map +1 -0
  49. package/dist/controls/select-row.d.ts +26 -0
  50. package/dist/controls/select-row.d.ts.map +1 -0
  51. package/dist/controls/slider-row.d.ts +34 -0
  52. package/dist/controls/slider-row.d.ts.map +1 -0
  53. package/dist/controls/text-row.d.ts +28 -0
  54. package/dist/controls/text-row.d.ts.map +1 -0
  55. package/dist/controls/tier-ref-selector.d.ts +33 -0
  56. package/dist/controls/tier-ref-selector.d.ts.map +1 -0
  57. package/dist/controls/tooltip.d.ts +44 -0
  58. package/dist/controls/tooltip.d.ts.map +1 -0
  59. package/dist/export-modal.d.ts +33 -0
  60. package/dist/export-modal.d.ts.map +1 -0
  61. package/dist/highlight/find-elements.d.ts +113 -0
  62. package/dist/highlight/find-elements.d.ts.map +1 -0
  63. package/dist/highlight/highlight-orchestrator.d.ts +24 -0
  64. package/dist/highlight/highlight-orchestrator.d.ts.map +1 -0
  65. package/dist/highlight/highlight-overlay.d.ts +43 -0
  66. package/dist/highlight/highlight-overlay.d.ts.map +1 -0
  67. package/dist/highlight/highlight-settings-popover.d.ts +25 -0
  68. package/dist/highlight/highlight-settings-popover.d.ts.map +1 -0
  69. package/dist/highlight/highlight-state.d.ts +87 -0
  70. package/dist/highlight/highlight-state.d.ts.map +1 -0
  71. package/dist/highlight/highlight-toggle-button.d.ts +34 -0
  72. package/dist/highlight/highlight-toggle-button.d.ts.map +1 -0
  73. package/dist/import-modal.d.ts +33 -0
  74. package/dist/import-modal.d.ts.map +1 -0
  75. package/dist/index.d.ts +105 -0
  76. package/dist/index.d.ts.map +1 -0
  77. package/dist/index.js +5480 -0
  78. package/dist/load-routing-XyKgftpe.js +353 -0
  79. package/dist/manifest-DCReQE0k.js +24 -0
  80. package/dist/panel-config-DP2_P7dD.js +332 -0
  81. package/dist/panel.d.ts +3 -0
  82. package/dist/panel.d.ts.map +1 -0
  83. package/dist/route-tokens-to-files-1DvmWBdj.js +41 -0
  84. package/dist/server/create-apply-handler.d.ts +48 -0
  85. package/dist/server/create-apply-handler.d.ts.map +1 -0
  86. package/dist/server/index.d.ts +24 -0
  87. package/dist/server/index.d.ts.map +1 -0
  88. package/dist/server/index.js +10 -0
  89. package/dist/server/load-routing.d.ts +39 -0
  90. package/dist/server/load-routing.d.ts.map +1 -0
  91. package/dist/server/path-safety.d.ts +36 -0
  92. package/dist/server/path-safety.d.ts.map +1 -0
  93. package/dist/server/serialize-write.d.ts +7 -0
  94. package/dist/server/serialize-write.d.ts.map +1 -0
  95. package/dist/state/persist.d.ts +39 -0
  96. package/dist/state/persist.d.ts.map +1 -0
  97. package/dist/state/tweak-state.d.ts +344 -0
  98. package/dist/state/tweak-state.d.ts.map +1 -0
  99. package/dist/tabs/_generic-item-editor.d.ts +23 -0
  100. package/dist/tabs/_generic-item-editor.d.ts.map +1 -0
  101. package/dist/tabs/color-tab.d.ts +55 -0
  102. package/dist/tabs/color-tab.d.ts.map +1 -0
  103. package/dist/tabs/font-tab.d.ts +22 -0
  104. package/dist/tabs/font-tab.d.ts.map +1 -0
  105. package/dist/tabs/generic-tab.d.ts +43 -0
  106. package/dist/tabs/generic-tab.d.ts.map +1 -0
  107. package/dist/tabs/size-tab.d.ts +20 -0
  108. package/dist/tabs/size-tab.d.ts.map +1 -0
  109. package/dist/tabs/spacing-tab.d.ts +23 -0
  110. package/dist/tabs/spacing-tab.d.ts.map +1 -0
  111. package/dist/testing.d.ts +81 -0
  112. package/dist/testing.d.ts.map +1 -0
  113. package/dist/testing.js +23 -0
  114. package/dist/tokens/manifest.d.ts +148 -0
  115. package/dist/tokens/manifest.d.ts.map +1 -0
  116. package/dist/tokens/tier-model.d.ts +89 -0
  117. package/dist/tokens/tier-model.d.ts.map +1 -0
  118. package/dist/tweak-state-DSJa5csL.js +624 -0
  119. package/dist/utils/color-convert.d.ts +7 -0
  120. package/dist/utils/color-convert.d.ts.map +1 -0
  121. package/dist/utils/color-hsla.d.ts +9 -0
  122. package/dist/utils/color-hsla.d.ts.map +1 -0
  123. package/dist/utils/color-oklch.d.ts +51 -0
  124. package/dist/utils/color-oklch.d.ts.map +1 -0
  125. package/dist/utils/design-token-serde.d.ts +193 -0
  126. package/dist/utils/design-token-serde.d.ts.map +1 -0
  127. package/dist/utils/structural-equal.d.ts +22 -0
  128. package/dist/utils/structural-equal.d.ts.map +1 -0
  129. package/dist/zdtp.css +1 -0
  130. package/package.json +102 -0
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Pure, IO-free CSS custom-property value replacement.
3
+ *
4
+ * `applyTokenOverrides(source, overrides)` rewrites the values of one or more
5
+ * CSS custom properties inside the FIRST top-level `:root { ... }` block of a
6
+ * CSS file, preserving surrounding whitespace and trailing inline comments.
7
+ * The module is the regex foundation that the dev-API endpoint
8
+ * wraps; it performs no IO, no DOM access, and is safe to import in any
9
+ * environment.
10
+ *
11
+ * Behavior summary
12
+ * ----------------
13
+ * - Only the FIRST top-level `:root { ... }` block is modified. Tokens inside
14
+ * `@media`, `@layer`, `@supports`, or nested `:root` blocks are IGNORED.
15
+ * - Per-cssVar regex: `(--name:)\s*([\s\S]+?);` with the name regex-escaped.
16
+ * The non-greedy value capture stops at the first `;`, which preserves any
17
+ * trailing `/​* ... *​/` inline comment on the same logical line.
18
+ * - A whitespace-trimmed comparison between the old value and the override
19
+ * decides whether the cssVar lands in `changed` or `unchanged`.
20
+ * - Idempotent: applying the same overrides twice in a row reports every key
21
+ * as `unchanged` on the second call and produces byte-identical output.
22
+ *
23
+ * Known limitations (if a richer transform is ever needed, swap this module
24
+ * for a real CSS parser such as postcss):
25
+ * - Only `:root` as a bare selector is recognized. Grouped selectors such as
26
+ * `:root, html { ... }` are NOT treated as a `:root` block.
27
+ * - Nested `:root` under `@media` / `@layer` / `@supports` is intentionally
28
+ * skipped; see the test matrix in the companion `__tests__` file.
29
+ * - Values containing a literal `;` inside a string or comment would confuse
30
+ * the non-greedy regex. Not supported.
31
+ * - If the same cssVar is declared multiple times in the top-level `:root`
32
+ * block, only the FIRST occurrence is rewritten.
33
+ */
34
+ export interface ApplyResult {
35
+ /** The new CSS file contents (byte-identical to `source` when nothing
36
+ * changed, including the "no :root block" case). */
37
+ updated: string;
38
+ /** cssVar names actually rewritten (trimmed new value differs from old). */
39
+ changed: string[];
40
+ /** cssVar names present in the file whose trimmed value already matched
41
+ * the override. */
42
+ unchanged: string[];
43
+ /** cssVar names in `overrides` that were not found in the first top-level
44
+ * `:root` block (either because the name is absent, or because no
45
+ * top-level `:root` block exists). */
46
+ unknown: string[];
47
+ }
48
+ /**
49
+ * Thrown by {@link applyTokenOverridesOrThrow} when the source has no
50
+ * top-level `:root { ... }` block. Lets the dev-API handler surface a
51
+ * diagnostic message without having to probe the result shape.
52
+ */
53
+ export declare class NoRootBlockError extends Error {
54
+ constructor(message?: string);
55
+ }
56
+ /**
57
+ * Rewrite `overrides` into the first top-level `:root { ... }` block of
58
+ * `source` and return an {@link ApplyResult} describing the outcome.
59
+ *
60
+ * If `source` has no top-level `:root` block, the function returns
61
+ * `source` unchanged with every key routed to `unknown` — the companion
62
+ * {@link applyTokenOverridesOrThrow} raises {@link NoRootBlockError} in
63
+ * that case so callers that need a hard failure can distinguish it from a
64
+ * block where merely none of the overrides matched.
65
+ */
66
+ export declare function applyTokenOverrides(source: string, overrides: Record<string, string>): ApplyResult;
67
+ /**
68
+ * Throwing variant. Same shape as {@link applyTokenOverrides} except it
69
+ * raises {@link NoRootBlockError} when no top-level `:root { ... }` block
70
+ * exists, instead of returning every override under `unknown`. Use this from
71
+ * server-side handlers where "no :root block" is a fatal configuration
72
+ * problem rather than an expected state.
73
+ */
74
+ export declare function applyTokenOverridesOrThrow(source: string, overrides: Record<string, string>): ApplyResult;
75
+ /**
76
+ * Low-level predicate exposed primarily for callers that want to report a
77
+ * precise diagnostic without running a full rewrite. Returns `true` iff the
78
+ * source contains at least one top-level `:root { ... }` block.
79
+ */
80
+ export declare function hasTopLevelRootBlock(source: string): boolean;
81
+ //# sourceMappingURL=apply-token-overrides.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply-token-overrides.d.ts","sourceRoot":"","sources":["../../src/apply/apply-token-overrides.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,MAAM,WAAW,WAAW;IAC1B;yDACqD;IACrD,OAAO,EAAE,MAAM,CAAC;IAChB,4EAA4E;IAC5E,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB;wBACoB;IACpB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB;;2CAEuC;IACvC,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;;;GAIG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;gBAC7B,OAAO,SAAwD;CAK5E;AAyOD;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAChC,WAAW,CA4Bb;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAChC,WAAW,CAMb;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAE5D"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Build the flat `{ cssVarName: cssValue }` diff consumed by the host's
3
+ * Apply endpoint (e.g. a dev-API route that POSTs the diff to the panel
4
+ * server).
5
+ *
6
+ * Consumes the `TweakState` shape directly:
7
+ *
8
+ * Color tokens:
9
+ * - `state.color.palette: string[]` — palette hex values
10
+ * - `state.color.semanticMappings: Record<string, number | 'bg' | 'fg'>` —
11
+ * semantic-token → palette-index map
12
+ * - `state.color.background` / `foreground` — palette indices used when a
13
+ * semantic mapping is `"bg"` / `"fg"` respectively
14
+ *
15
+ * Non-color tokens (spacing / typography / size including radius):
16
+ * - `state.spacing: TokenOverrides` — keyed by token id (e.g. `hsp-md`)
17
+ * - `state.typography: TokenOverrides` — keyed by token id (e.g. `text-base`)
18
+ * - `state.size: TokenOverrides` — keyed by token id (e.g. `radius-lg`)
19
+ *
20
+ * The routing layer (`route-tokens-to-files.ts`) then splits the map into
21
+ * per-file groups. The host (or the deferred bin) applies each group to
22
+ * its target `.css` file.
23
+ *
24
+ * Scope
25
+ * -----
26
+ * Only cssVars that the cluster's or tabs' CSS files actually declare are emitted.
27
+ * Specifically:
28
+ *
29
+ * - Palette slots (resolved via `resolvePaletteCssVar(cluster, i)`) —
30
+ * EMITTED as hex values.
31
+ * - Semantic tokens (`cluster.semanticCssNames` entries) — EMITTED as
32
+ * `var(--<paletteSlotName>)` so the rewrite preserves the indirection
33
+ * that the hand-authored CSS relies on.
34
+ * - Base roles (`cluster.baseRoles` entries) — NOT emitted. They do not
35
+ * belong to the apply pipeline's rewrite scope.
36
+ * - Spacing / typography / size — EMITTED when the corresponding
37
+ * `TokenOverrides` map is non-empty. Values are resolved through the
38
+ * tier resolver so reference tiers emit `var(--targetCssVar)` rather
39
+ * than the raw item id string. Readonly items are skipped.
40
+ *
41
+ * Diff-only output
42
+ * ----------------
43
+ * For color tokens, a cssVar is emitted ONLY when the current state differs
44
+ * from the provided baseline. Callers without a baseline (tests,
45
+ * degraded-init paths) can pass `colorDefaults: undefined`; in that case the
46
+ * whole color block is treated as changed.
47
+ *
48
+ * For non-color tokens, `TokenOverrides` is already a sparse diff (only
49
+ * overridden tokens appear in the map) — no baseline comparison is needed.
50
+ *
51
+ * Pure / no IO — safe to import anywhere (browser, Node, tests).
52
+ */
53
+ import type { ColorTweakState, TweakState, ColorClusterConfig } from '../state/tweak-state';
54
+ import type { TabConfig } from '../tokens/tier-model';
55
+ /**
56
+ * Produce the flat cssVar → value map for the dev-API handler.
57
+ *
58
+ * `colorDefaults` should be the scheme baseline the UI diffs against (the
59
+ * same baseline the panel passes to the Export / Import modals). Pass
60
+ * `undefined` to force the whole color block into the output.
61
+ *
62
+ * `cluster` defaults to the primary color cluster derived from the active
63
+ * panel config's color TabConfig so primary-cluster callers do not have to
64
+ * thread the active cluster through every layer. Secondary-cluster callers
65
+ * MUST pass an explicit cluster argument.
66
+ *
67
+ * `tabs` defaults to the active panel config's tab list. Injected by tests so
68
+ * non-color token resolution works without a live panel config singleton.
69
+ */
70
+ export declare function buildApplyOverrides(state: TweakState, colorDefaults: ColorTweakState | undefined, cluster?: ColorClusterConfig, tabs?: readonly TabConfig[]): Record<string, string>;
71
+ //# sourceMappingURL=build-apply-overrides.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-apply-overrides.d.ts","sourceRoot":"","sources":["../../src/apply/build-apply-overrides.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE5F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAItD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,UAAU,EACjB,aAAa,EAAE,eAAe,GAAG,SAAS,EAC1C,OAAO,GAAE,kBAA8C,EACvD,IAAI,GAAE,SAAS,SAAS,EAA0B,GACjD,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA2DxB"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Token-to-file routing — pure grouping module.
3
+ *
4
+ * Given a map of cssVar overrides (e.g. from the tweak state's serialized
5
+ * form), split the entries by target source file so the dev-API handler can
6
+ * call the rewriter once per file. The prefix → file map is supplied by the
7
+ * caller (typically read from `panelConfig.applyRouting`) — the package
8
+ * ships zero baked-in routing defaults; hosts MUST configure their own.
9
+ *
10
+ * Anything that does NOT look like a `--<prefix>-...` cssVar, OR whose prefix
11
+ * has no entry in the supplied routing map, lands in `rejected`. The caller
12
+ * surfaces those (e.g. as a non-empty `rejected[]` field on the apply
13
+ * response) so silent drops become visible.
14
+ *
15
+ * No IO, no DOM, no Node-specific imports — safe to bundle for the browser.
16
+ */
17
+ import type { ApplyRoutingMap } from '../config/panel-config';
18
+ /**
19
+ * Prefix-family identifier. Plain string — the routing map is host-supplied.
20
+ */
21
+ export type TokenPrefix = string;
22
+ export interface RouteGroup {
23
+ /** Which prefix family these tokens belong to. */
24
+ prefix: string;
25
+ /** Repo-relative path of the source CSS file the rewriter should edit. */
26
+ relativePath: string;
27
+ /** Ordered map of cssVar → value. Insertion order follows the input. */
28
+ tokens: Record<string, string>;
29
+ }
30
+ export interface RouteResult {
31
+ /** At most one group per prefix. Empty when every entry was rejected. */
32
+ groups: RouteGroup[];
33
+ /** cssVar names whose prefix is not supported. */
34
+ rejected: string[];
35
+ /**
36
+ * Diagnostic messages explaining each rejection. Same length as `rejected`,
37
+ * indexed in lockstep. Hosts surface these in the UI so silent drops
38
+ * become visible.
39
+ */
40
+ rejectedReasons: string[];
41
+ }
42
+ /**
43
+ * Empty default routing — the package ships no baked-in prefix → file map.
44
+ * Hosts MUST supply `panelConfig.applyRouting` (or pass an explicit map to
45
+ * `routeTokensToFiles`) for the apply pipeline to do anything; without it,
46
+ * every entry lands in `rejected` with a clear diagnostic.
47
+ */
48
+ export declare const TOKEN_SOURCE_FILES: Readonly<ApplyRoutingMap>;
49
+ /**
50
+ * Split `overrides` into per-file groups plus a rejected list.
51
+ *
52
+ * - Groups are emitted in `Object.keys(routing)` order.
53
+ * - Tokens within a group preserve the input's insertion order.
54
+ * - A group is only emitted when it has at least one token.
55
+ * - `rejected` preserves the input's insertion order, with a parallel
56
+ * `rejectedReasons` array describing why each entry failed.
57
+ *
58
+ * @param overrides - Flat cssVar → value map.
59
+ * @param routing - Prefix → repo-relative path map (typically from
60
+ * `panelConfig.applyRouting`). When omitted or empty, every entry lands in
61
+ * `rejected` so callers surface a clear "apply not configured" error
62
+ * instead of silently no-oping.
63
+ */
64
+ export declare function routeTokensToFiles(overrides: Record<string, string>, routing?: ApplyRoutingMap): RouteResult;
65
+ //# sourceMappingURL=route-tokens-to-files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route-tokens-to-files.d.ts","sourceRoot":"","sources":["../../src/apply/route-tokens-to-files.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC;AAEjC,MAAM,WAAW,UAAU;IACzB,kDAAkD;IAClD,MAAM,EAAE,MAAM,CAAC;IACf,0EAA0E;IAC1E,YAAY,EAAE,MAAM,CAAC;IACrB,wEAAwE;IACxE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,WAAW;IAC1B,yEAAyE;IACzE,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB,kDAAkD;IAClD,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB;;;;OAIG;IACH,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC,eAAe,CAAqB,CAAC;AAyB/E;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACjC,OAAO,GAAE,eAAoC,GAC5C,WAAW,CAyCb"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Cross-tier reference resolver and CSS value emitter.
3
+ *
4
+ * Pure module — no DOM, no Preact, no IO. Safe to import in any environment.
5
+ *
6
+ * ## TabOverrides shape
7
+ *
8
+ * `TabOverrides` is a two-level nested map:
9
+ *
10
+ * tierId → itemId → overrideValue (CSS string)
11
+ *
12
+ * Example:
13
+ * {
14
+ * raw: { 'ease-in': 'cubic-bezier(0.42,0,1,1)' },
15
+ * semantic: { 'tab-open': 'ease-in' }, // ref value — points at a raw item id
16
+ * }
17
+ *
18
+ * For a literal tier (no referencesTier) the value is the CSS string to emit.
19
+ * For a reference tier (referencesTier is set) the value is the id of a target
20
+ * item in the named tier.
21
+ */
22
+ import type { TabConfig } from '../tokens/tier-model';
23
+ export type TabOverrides = Readonly<Record<string, Readonly<Record<string, string>>>>;
24
+ export declare class TierResolverError extends Error {
25
+ constructor(message: string);
26
+ }
27
+ export type ResolvedLiteral = {
28
+ kind: 'literal';
29
+ value: string;
30
+ };
31
+ export type ResolvedRef = {
32
+ kind: 'ref';
33
+ targetCssVar: string;
34
+ };
35
+ export type ResolvedTierItem = ResolvedLiteral | ResolvedRef;
36
+ /**
37
+ * Resolve the effective CSS value for a single tier item.
38
+ *
39
+ * For literal tiers (no `referencesTier`):
40
+ * Returns { kind: 'literal', value } where value is the override string
41
+ * or the item's `default`.
42
+ *
43
+ * For reference tiers (`referencesTier` is set):
44
+ * The override value is interpreted as an item id in the referenced tier.
45
+ * Returns { kind: 'ref', targetCssVar } pointing at the referenced item's
46
+ * cssVar so callers can emit `var(--targetCssVar)`.
47
+ *
48
+ * Pill semantics:
49
+ * When a literal-tier item has a `pill` spec and the override value equals
50
+ * `pill.value`, the pill value is returned verbatim (the pill toggle is ON).
51
+ * When the override is absent but the item has a pill, `pill.customDefault`
52
+ * is used as the baseline (not the item's `default`). The item's `default`
53
+ * is used only when neither an override nor a pill customDefault apply.
54
+ *
55
+ * Error cases (throw TierResolverError):
56
+ * - tierId not found in tab.tiers
57
+ * - referencesTier id not found in tab.tiers
58
+ * - ref override points at a tier other than the one declared in referencesTier
59
+ * (guarded by design: the resolver validates the target tier id)
60
+ *
61
+ * Fallback case (no error):
62
+ * - ref override id not found in the target tier → falls back to the target
63
+ * tier's item whose id matches itemId; if that also doesn't exist, falls
64
+ * back to the first item's default.
65
+ */
66
+ export declare function resolveTierItemValue(tab: TabConfig, tierId: string, itemId: string, overrides: TabOverrides): ResolvedTierItem;
67
+ /**
68
+ * Convert a resolved tier item into the final CSS value string to write into
69
+ * a CSS custom property.
70
+ *
71
+ * - Literal → returns the value as-is (e.g. `1.25rem`).
72
+ * - Ref → returns `var(--targetCssVar)` (e.g. `var(--zfb-easing-ease-in)`).
73
+ */
74
+ export declare function emitTierItemCssValue(resolved: ResolvedTierItem): string;
75
+ //# sourceMappingURL=tier-resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tier-resolver.d.ts","sourceRoot":"","sources":["../../src/apply/tier-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAwB,MAAM,sBAAsB,CAAC;AAE5E,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAMtF,qBAAa,iBAAkB,SAAQ,KAAK;gBAC9B,OAAO,EAAE,MAAM;CAK5B;AAMD,MAAM,MAAM,eAAe,GAAG;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AACjE,MAAM,MAAM,WAAW,GAAG;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC;AAChE,MAAM,MAAM,gBAAgB,GAAG,eAAe,GAAG,WAAW,CAAC;AAkB7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,SAAS,EACd,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,YAAY,GACtB,gBAAgB,CAwElB;AAMD;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,gBAAgB,GAAG,MAAM,CAGvE"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Apply modal — previews the diff between the current `TweakState` and the
3
+ * scheme defaults, then POSTs the diff to the dev-only
4
+ * `/api/dev/design-tokens-apply` endpoint so the tweaks are written back
5
+ * into the host's design-system CSS files on disk.
6
+ *
7
+ * Wiring summary
8
+ * --------------
9
+ * - Diff building is delegated to `./apply/build-apply-overrides`, which
10
+ * consumes the new `ColorTweakState` shape (palette + semanticMappings) and
11
+ * emits the flat `{ cssVar: value }` map using `SEMANTIC_CSS_NAMES`.
12
+ * - Per-file grouping (for the preview and for the success view) uses
13
+ * `./apply/route-tokens-to-files` — the exact same routing the dev-API
14
+ * handler runs server-side, so the preview matches the server's view of
15
+ * the world byte-for-byte.
16
+ * - Styling uses bundled BEM classes derived from
17
+ * `panelConfig.modalClassPrefix` via `modalClass(...)`. The matching CSS
18
+ * lives in `styles/panel.css` keyed on the default modal class prefix;
19
+ * consumers that override the prefix opt out of bundled CSS and ship
20
+ * their own. No Tailwind classes remain.
21
+ *
22
+ * Dialog lifecycle (unchanged)
23
+ * ----------------------------
24
+ * Uses the native `<dialog>` element. Every dismissal path (× / backdrop /
25
+ * Escape / programmatic close) routes through `dialog.close()`, which fires
26
+ * the native `close` event exactly once; `onClose` then fires exactly once
27
+ * per dismissal regardless of the path taken.
28
+ */
29
+ import { type ColorTweakState, type TweakState } from './state/tweak-state';
30
+ export interface ApplyModalProps {
31
+ state: TweakState;
32
+ open: boolean;
33
+ onClose: () => void;
34
+ /**
35
+ * Scheme baseline used to diff the current `state.color` against when
36
+ * computing the flat cssVar overrides. When absent, the entire color block
37
+ * is treated as changed — useful for tests, but real callers (the panel
38
+ * itself) always pass the active scheme's initial `ColorTweakState`.
39
+ */
40
+ colorDefaults?: ColorTweakState;
41
+ /**
42
+ * Fired exactly once after the user confirms a successful apply by clicking
43
+ * "Done". The parent is expected to clear the persisted state envelope,
44
+ * clear any inline-applied styles, and reset in-memory state to empty.
45
+ */
46
+ onApplied: () => void;
47
+ }
48
+ export declare function ApplyModal(props: ApplyModalProps): import("preact").JSX.Element;
49
+ //# sourceMappingURL=apply-modal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply-modal.d.ts","sourceRoot":"","sources":["../src/apply-modal.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAWH,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAK5E,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,UAAU,CAAC;IAClB,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,eAAe,CAAC;IAChC;;;;OAIG;IACH,SAAS,EAAE,MAAM,IAAI,CAAC;CACvB;AAmJD,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,gCA0YhD"}
@@ -0,0 +1,76 @@
1
+ ---
2
+ /**
3
+ * Astro entry point for the design-token panel.
4
+ *
5
+ * Drop into a layout once. The component AND the host-adapter side-effect
6
+ * import are a paired unit — both lines are required, always together:
7
+ *
8
+ * ```astro
9
+ * ---
10
+ * import { DesignTokenPanelHost } from '@takazudo/zdtp/astro';
11
+ * import { panelConfig } from './my-design-token-config';
12
+ * // Required side-effect import for the package's bundled chrome CSS —
13
+ * // Vite library mode strips the source CSS import from the emitted JS,
14
+ * // so consumers must re-pull the extracted stylesheet explicitly.
15
+ * import '@takazudo/zdtp/styles';
16
+ * ---
17
+ * <DesignTokenPanelHost config={panelConfig} />
18
+ * <script>
19
+ * // Required side-effect import for the host adapter. The package's
20
+ * // distributed Astro surface ships built `dist/astro/*` files, and the
21
+ * // package-side hoisted <script> from those built files does not reliably
22
+ * // reach production page bundles. Owning the script import in the
23
+ * // consumer wrapper sidesteps that pipeline issue. The package's
24
+ * // `package.json` lists `dist/astro/host-adapter.js` in `sideEffects` so
25
+ * // Rollup preserves the consumer-side import regardless of whether its
26
+ * // result is used. The dynamic `void import(...)` form is the recommended
27
+ * // canonical wiring because it loads the host-adapter chunk off the
28
+ * // critical path.
29
+ * void import('@takazudo/zdtp/astro/host-adapter');
30
+ * </script>
31
+ * ```
32
+ *
33
+ * The component renders ONE inline `<script type="application/json">` block
34
+ * carrying the serialised `PanelConfig`; the host adapter (loaded via the
35
+ * consumer-owned import above) reads it by id at module init.
36
+ *
37
+ * History — why the host-adapter import lives in the consumer wrapper:
38
+ * a previous shape emitted a sibling `<script>import './host-adapter';</script>`
39
+ * block. Vite/Rollup processed that block, recognised the import as
40
+ * resolving to a sibling JS file outside the consumer's source tree,
41
+ * emitted an empty chunk, and never linked it from any page entry. The
42
+ * result was a silent runtime ReferenceError on production builds. Moving
43
+ * the import into the consumer wrapper hands bundling responsibility to
44
+ * the consumer's own Astro toolchain, which produces a real chunk that
45
+ * lands in the page entry.
46
+ *
47
+ * Why inline JSON instead of `define:vars` or `set:html` of a JS literal?
48
+ * `<script type="application/json">` is not parsed as JavaScript by the HTML
49
+ * parser, so we can serialise arbitrary user-supplied data without an XSS
50
+ * surface or escaping gymnastics — provided we close-tag-escape strings
51
+ * (`</` → `<\/`) defensively.
52
+ */
53
+
54
+ import type { PanelConfig } from '../config/panel-config';
55
+
56
+ export interface Props {
57
+ config: PanelConfig;
58
+ }
59
+
60
+ const { config } = Astro.props;
61
+
62
+ // Defensive escape: any literal `<` inside a string field could let the HTML
63
+ // parser see `</script>` or `<!--` and either close the surrounding script
64
+ // element or enter the script-data-escaped state. JSON.stringify does not
65
+ // escape `<` — so we replace every `<` with the JSON unicode escape
66
+ // `<`. The browser's HTML parser sees only the literal characters
67
+ // `\`, `u`, `0`, `0`, `3`, `c` (no `<`), and JSON.parse on the consumer side
68
+ // decodes `<` back to `<`. Targeted replacements like
69
+ // `</script` → `<\/script` work for the close-tag case but `<!--` → `<\!--`
70
+ // produces an invalid JSON escape (`\!` is not in the JSON spec) and
71
+ // JSON.parse rejects it. The unicode-escape sweep is robust against both.
72
+ // See https://html.spec.whatwg.org/multipage/scripting.html#restrictions-for-contents-of-script-elements
73
+ const configJson = JSON.stringify(config).replace(/</g, '\\u003c');
74
+ ---
75
+
76
+ <script type="application/json" id="tokenpanel-config" set:html={configJson} />
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Astro host adapter.
3
+ *
4
+ * Loaded by `DesignTokenPanelHost.astro` via a per-page `<script>` block.
5
+ * Responsibilities:
6
+ *
7
+ * 1. Read the JSON config inlined by the Astro component (a
8
+ * `<script type="application/json" id="tokenpanel-config">` element).
9
+ * 2. Call `configurePanel(parsedConfig)` BEFORE the lazy-load probes run, so
10
+ * every downstream `getPanelConfig()` reader (storage keys, console
11
+ * namespace, modal class prefix, …) sees the host's intended values.
12
+ * 3. Install the console API on `window[config.consoleNamespace]`
13
+ * (`showDesignPanel` / `hideDesignPanel` / `toggleDesignPanel`). The
14
+ * namespace is a configured field — different consumers can pick
15
+ * distinct values to prove the contract is host-agnostic.
16
+ * 4. Gate the panel module's dynamic import on the same probes the legacy
17
+ * host script used: an existing `wasVisible()` flag or any persisted v2
18
+ * overrides. When neither is set, the panel module stays out of the
19
+ * initial bundle and only loads when the user calls a `window.<ns>.*`
20
+ * helper from the console.
21
+ *
22
+ * Idempotency
23
+ * -----------
24
+ * The Astro `<script>` re-executes on view-transition (`astro:before-swap` /
25
+ * `astro:page-load`) — the consumer-side bundler emits one script per page
26
+ * and Astro's view-transition runtime re-runs it. We pin a window-scoped
27
+ * flag derived from the configured `storagePrefix` so subsequent runs short-
28
+ * circuit. (The panel module owns its own view-transition listener
29
+ * lifecycle internally; this flag is only about *adapter*-level state.)
30
+ *
31
+ * Singleton sharing
32
+ * -----------------
33
+ * `configurePanel` mutates a module-level singleton in
34
+ * `../config/panel-config.ts`. The dynamic import below resolves through the
35
+ * package's exports map back to the lib bundle's `dist/index.js`, which
36
+ * imports from the same `panel-config` chunk that this adapter imports —
37
+ * Vite's multi-entry build code-splits shared modules into a single chunk so
38
+ * both surfaces observe one and the same singleton. Without that property,
39
+ * the adapter's `configurePanel` call would not be visible to the panel.
40
+ *
41
+ * NOTE: This file is a sibling of `index.ts`; both compile under the
42
+ * `astro/*` entry tree of `vite.config.ts`. It is consumed only by the
43
+ * Astro toolchain on the consumer side (via the `<script>` import in
44
+ * `DesignTokenPanelHost.astro`), never by the lib bundle's `index.ts`.
45
+ */
46
+ export {};
47
+ //# sourceMappingURL=host-adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host-adapter.d.ts","sourceRoot":"","sources":["../../src/astro/host-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG"}
@@ -0,0 +1,81 @@
1
+ import { c as u, g as l, a as f, b as p, d as h, e as m } from "../panel-config-DP2_P7dD.js";
2
+ import { Z as w } from "../tweak-state-DSJa5csL.js";
3
+ const r = "tokenpanel-config";
4
+ function P() {
5
+ if (typeof document > "u")
6
+ throw new Error(
7
+ "[design-token-panel] host-adapter loaded without a document; expected to run in a browser context."
8
+ );
9
+ const e = document.getElementById(r);
10
+ if (!e)
11
+ throw new Error(
12
+ `[design-token-panel] Inline config script #${r} not found. Ensure <DesignTokenPanelHost config={...} /> is rendered on this page before the host script runs.`
13
+ );
14
+ const o = e.textContent ?? "";
15
+ let n;
16
+ try {
17
+ n = JSON.parse(o);
18
+ } catch (t) {
19
+ throw new Error(
20
+ `[design-token-panel] Failed to parse inline config from #${r}: ${t.message}`
21
+ );
22
+ }
23
+ return m(n), n;
24
+ }
25
+ function y(e) {
26
+ return e.__zudoDesignTokenPanelAdapter || (e.__zudoDesignTokenPanelAdapter = {}), e.__zudoDesignTokenPanelAdapter;
27
+ }
28
+ function _(e, o) {
29
+ const n = y(e);
30
+ let t = n[o];
31
+ return t || (t = { bound: !1, modulePromise: null }, n[o] = t), t;
32
+ }
33
+ function k(e) {
34
+ try {
35
+ return window.localStorage.getItem(e) === "1";
36
+ } catch {
37
+ return !1;
38
+ }
39
+ }
40
+ function b(e, o) {
41
+ try {
42
+ const n = window.localStorage;
43
+ return n.getItem(o) !== null || n.getItem(e) !== null;
44
+ } catch {
45
+ return !1;
46
+ }
47
+ }
48
+ async function i(e) {
49
+ return e.modulePromise === null && (e.modulePromise = import("@takazudo/zdtp").then((o) => {
50
+ try {
51
+ const n = l(), t = o.__panelConfigForTest();
52
+ n !== t && console.warn(
53
+ "[design-token-panel] Singleton-sharing check failed: the host adapter and the panel module observed different PanelConfig singletons. This indicates the package's `config/panel-config` module is no longer code-split into a single shared chunk. The panel may behave correctly today, but storage keys / namespaces / branding could diverge between the two surfaces in future bundles."
54
+ );
55
+ } catch (n) {
56
+ console.warn(
57
+ "[design-token-panel] Singleton-sharing check could not run (likely an older dist without the __panelConfigForTest accessor): " + n.message
58
+ );
59
+ }
60
+ return o;
61
+ })), e.modulePromise;
62
+ }
63
+ function T(e, o, n) {
64
+ const t = e[o] ?? {};
65
+ t.showDesignPanel = async () => {
66
+ (await i(n)).showDesignTokenPanel();
67
+ }, t.hideDesignPanel = async () => {
68
+ (await i(n)).hideDesignTokenPanel();
69
+ }, t.toggleDesignPanel = async () => {
70
+ (await i(n)).toggleDesignPanel();
71
+ }, e[o] = t;
72
+ }
73
+ (function() {
74
+ const o = P(), n = o.legacyIdRenameMap ? o : { ...o, legacyIdRenameMap: { ...w } };
75
+ u(n);
76
+ const t = l(), a = window, s = _(a, t.storagePrefix);
77
+ if (T(a, t.consoleNamespace, s), s.bound) return;
78
+ s.bound = !0;
79
+ const c = f(t), d = p(t), g = h(t);
80
+ (k(c) || b(d, g)) && i(s);
81
+ })();
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Astro sub-export entry.
3
+ *
4
+ * Consumers import the host component via:
5
+ *
6
+ * ```astro
7
+ * import { DesignTokenPanelHost } from '@takazudo/zdtp/astro';
8
+ * ```
9
+ *
10
+ * The named-export pattern is preserved verbatim through the lib build:
11
+ * `vite.config.ts` marks `*.astro` external (regex) so Vite leaves the
12
+ * `from './DesignTokenPanelHost.astro'` literal in `dist/astro/index.js`,
13
+ * and a postbuild copy step (`scripts/copy-astro-assets.mjs`) places the
14
+ * raw `.astro` file alongside it. The consumer's own Astro toolchain then
15
+ * resolves the relative path at build time.
16
+ *
17
+ * `PanelConfig` is re-exported here so callers don't need a deep
18
+ * `@takazudo/zdtp/dist/config/panel-config` import to
19
+ * type their config object.
20
+ */
21
+ export { default as DesignTokenPanelHost } from './DesignTokenPanelHost.astro';
22
+ export type { PanelConfig } from '../config/panel-config';
23
+ export type { ColorScheme, ColorRef } from '../config/color-schemes';
24
+ export type { ColorClusterConfig } from '../state/tweak-state';
25
+ export { setPanelColorPresets } from '../config/panel-config';
26
+ export { colorSchemes } from '../config/color-schemes';
27
+ export { panelSettings, SEMANTIC_CSS_NAMES, SEMANTIC_DEFAULTS_ZD } from '../config/color-scheme-utils';
28
+ export { GROUP_ORDER, FONT_GROUP_ORDER, SIZE_GROUP_ORDER, GROUP_TITLES } from '../tokens/manifest';
29
+ export type { TokenDef, TokenManifest } from '../tokens/manifest';
30
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/astro/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAC/E,YAAY,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAG1D,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAGrE,YAAY,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAI/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAK9D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAKvD,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAKvG,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACnG,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC"}