@takazudo/zudo-doc 2.5.1 → 3.1.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 (43) hide show
  1. package/CHANGELOG.md +1038 -0
  2. package/README.md +4 -0
  3. package/dist/chrome/derive.d.ts +4 -1
  4. package/dist/chrome/derive.js +30 -25
  5. package/dist/color-scheme-utils.d.ts +153 -102
  6. package/dist/color-scheme-utils.js +168 -97
  7. package/dist/content.css +5 -5
  8. package/dist/design-token-panel-bootstrap.d.ts +37 -16
  9. package/dist/design-token-panel-bootstrap.js +47 -19
  10. package/dist/doc-page-renderer/index.d.ts +1 -0
  11. package/dist/doc-page-renderer/index.js +2 -0
  12. package/dist/doc-page-shell/index.d.ts +2 -0
  13. package/dist/doc-page-shell/index.js +2 -0
  14. package/dist/doclayout/doc-layout.d.ts +9 -0
  15. package/dist/doclayout/doc-layout.js +2 -0
  16. package/dist/features.css +19 -0
  17. package/dist/home-page/index.d.ts +8 -0
  18. package/dist/home-page/index.js +3 -1
  19. package/dist/integrations/changelog/emit.d.ts +2 -0
  20. package/dist/integrations/changelog/emit.js +24 -0
  21. package/dist/integrations/changelog/generate.d.ts +2 -0
  22. package/dist/integrations/changelog/generate.js +24 -0
  23. package/dist/integrations/changelog/index.d.ts +5 -0
  24. package/dist/integrations/changelog/index.js +11 -0
  25. package/dist/integrations/changelog/load.d.ts +3 -0
  26. package/dist/integrations/changelog/load.js +79 -0
  27. package/dist/integrations/changelog/sanitize.d.ts +10 -0
  28. package/dist/integrations/changelog/sanitize.js +24 -0
  29. package/dist/integrations/changelog/types.d.ts +31 -0
  30. package/dist/integrations/changelog/types.js +0 -0
  31. package/dist/plugins/changelog.d.ts +3 -0
  32. package/dist/plugins/changelog.js +17 -0
  33. package/dist/preset.d.ts +7 -0
  34. package/dist/preset.js +8 -0
  35. package/dist/safelist.css +1 -1
  36. package/dist/settings.d.ts +11 -0
  37. package/dist/theme/design-token-serde.d.ts +74 -33
  38. package/dist/theme/design-token-serde.js +187 -94
  39. package/dist/theme/design-token-types.d.ts +6 -10
  40. package/dist/theme/index.d.ts +1 -1
  41. package/dist/theme-toggle/color-scheme-sync.d.ts +22 -12
  42. package/eject/theme-toggle/color-scheme-sync.ts +22 -12
  43. package/package.json +18 -9
package/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  Framework primitives that sit on top of zfb's engine — the framework layer that zfb deliberately doesn't ship (per ADR-003).
4
4
 
5
+ Release history is shipped as `CHANGELOG.md` in the npm package. The file is
6
+ generated from the repository's changelog MDX pages; edit those source pages
7
+ instead of editing the generated markdown directly.
8
+
5
9
  This package provides the missing-by-design framework concerns:
6
10
 
7
11
  - **Sidebar tree builder** (`./sidebar-tree`) — turns collection entries + `_category_.json` into a sidebar `SidebarNode[]`.
@@ -6,7 +6,10 @@ import type { Settings } from "../settings.js";
6
6
  import { type ColorScheme } from "../color-scheme-utils.js";
7
7
  import { createBodyEndIslands } from "../doc-body-end-islands/index.js";
8
8
  /** Package-default color scheme used when `colorSchemes` is `null` or a key is
9
- * missing. Exported so `createChrome` keeps the identical fallback. */
9
+ * missing. Exported so `createChrome` keeps the identical fallback. Base roles
10
+ * follow the epic's Default Dark defaults on the minimized 5-base ramp
11
+ * (bg={base:4}, fg={base:0}, selBg={base:2}, selFg={base:0}); semantics use
12
+ * `SEMANTIC_RAMP_DEFAULTS`. */
10
13
  export declare const DEFAULT_SCHEME: ColorScheme;
11
14
  /** Package no-op DocHistory island stub — renders an empty fragment (the
12
15
  * `DocHistoryComponent` contract requires a VNode, not null). */
@@ -2,7 +2,8 @@ import { Fragment, jsx } from "preact/jsx-runtime";
2
2
  import { createComposeMetaTitle } from "../compose-meta-title/index.js";
3
3
  import {
4
4
  generateCssCustomProperties,
5
- generateLightDarkCssProperties
5
+ generateLightDarkCssProperties,
6
+ SEMANTIC_RAMP_DEFAULTS
6
7
  } from "../color-scheme-utils.js";
7
8
  import { createBodyEndIslands } from "../doc-body-end-islands/index.js";
8
9
  import { SearchWidget } from "../search-widget/index.js";
@@ -22,31 +23,35 @@ import {
22
23
  getThemeDefaultMode as getThemeDefaultModeBase
23
24
  } from "../nav-data-prep/index.js";
24
25
  import { buildSidebarForSection } from "../sidebar-utils/index.js";
25
- const GREY_RAMP = [
26
- "oklch(0.000 0.000 0.00)",
27
- "oklch(0.218 0.000 0.00)",
28
- "oklch(0.321 0.000 0.00)",
29
- "oklch(0.420 0.000 0.00)",
30
- "oklch(0.510 0.000 0.00)",
31
- "oklch(0.600 0.000 0.00)",
32
- "oklch(0.683 0.000 0.00)",
33
- "oklch(0.767 0.000 0.00)",
34
- "oklch(0.845 0.000 0.00)",
35
- "oklch(0.885 0.000 0.00)",
36
- "oklch(0.925 0.000 0.00)",
37
- "oklch(0.961 0.000 0.00)",
38
- "oklch(0.682 0.206 24.43)",
39
- "oklch(0.871 0.2195 148.02)",
40
- "oklch(0.955 0.134 112.76)",
41
- "oklch(0.883 0.0934 212.85)"
42
- ];
26
+ const GREY_RAMPS = {
27
+ base: [
28
+ "oklch(0.965 0.000 0)",
29
+ "oklch(0.705 0.000 0)",
30
+ "oklch(0.480 0.000 0)",
31
+ "oklch(0.300 0.000 0)",
32
+ "oklch(0.185 0.000 0)"
33
+ ],
34
+ accent: [
35
+ "oklch(0.755 0.000 0)",
36
+ "oklch(0.700 0.000 0)",
37
+ "oklch(0.470 0.000 0)"
38
+ ],
39
+ state: {
40
+ danger: "oklch(0.640 0.170 25)",
41
+ success: "oklch(0.680 0.145 145)",
42
+ warning: "oklch(0.760 0.135 82)",
43
+ info: "oklch(0.680 0.130 245)"
44
+ }
45
+ };
43
46
  const DEFAULT_SCHEME = {
44
- background: "oklch(0.000 0.000 0.00)",
45
- foreground: "oklch(1.000 0.000 0.00)",
46
- cursor: "oklch(1.000 0.000 0.00)",
47
- selectionBg: "oklch(0.387 0.000 0.00)",
48
- selectionFg: "oklch(1.000 0.000 0.00)",
49
- palette: GREY_RAMP
47
+ ramps: GREY_RAMPS,
48
+ map: {
49
+ bg: { base: 4 },
50
+ fg: { base: 0 },
51
+ selectionBg: { base: 2 },
52
+ selectionFg: { base: 0 },
53
+ semantic: { ...SEMANTIC_RAMP_DEFAULTS }
54
+ }
50
55
  };
51
56
  function DocHistoryStub(_props) {
52
57
  return /* @__PURE__ */ jsx(Fragment, {});
@@ -1,113 +1,161 @@
1
1
  /**
2
- * Color-scheme MECHANISM — palette → `--zd-*` CSS custom-property injection.
2
+ * Color-scheme MECHANISM — ramp → `--palette-*` / `--zd-*` CSS custom-property
3
+ * injection.
3
4
  *
4
5
  * This module ships the pure computation layer used by every project that
5
6
  * builds on @takazudo/zudo-doc. It is DATA-free: callers pass in their own
6
7
  * color-scheme manifest and settings.
7
8
  *
9
+ * Ramp-native model (Color Ramp Restructure — zudolab/zudo-doc#2584; minimized
10
+ * to 5/3 in #2602). A `ColorScheme` is `{ ramps, map }`:
11
+ * - `ramps` — the shared Tier-1 source of truth: a warm-neutral `base` ramp
12
+ * (5 stops, index 0 = lightest), an `accent` ramp (3 stops), and 4 `state`
13
+ * colors. Emitted verbatim as `--palette-{group}-{n}`.
14
+ * - `map` — the per-mode Tier-2 wiring: which ramp stop (or literal OKLCH)
15
+ * each UI role (`--zd-*`) points at, via a `RampRef`.
16
+ *
17
+ * The legacy ghostty 16-slot palette (`--zd-0..15`), `cursor`, `shikiTheme`,
18
+ * and the numeric `ColorRef` were dropped in that epic.
19
+ *
8
20
  * Moved from the host's `src/config/color-scheme-utils.ts` as part of the
9
- * package-first migration (S9a zudolab/zudo-doc#2333). The DATA (palette
10
- * values, scheme names, `colorMode` settings) stays project-side.
21
+ * package-first migration (S9a zudolab/zudo-doc#2333). The DATA (ramp values,
22
+ * scheme names, `colorMode` settings) stays project-side.
23
+ */
24
+ /** A color literal — an `oklch(…)` (or any valid CSS color) string. */
25
+ export type OKLCH = string;
26
+ /** The four semantic state colors that live on their own ramp. */
27
+ export type StateRole = "danger" | "success" | "warning" | "info";
28
+ /** Canonical order of the state ramp — used for `--palette-state-*` emit. */
29
+ export declare const STATE_ROLES: readonly StateRole[];
30
+ /**
31
+ * A reference into the shared ramps, resolved by `resolveRampRef`:
32
+ * - `{ base: n }` → `ramps.base[n]`
33
+ * - `{ accent: n }` → `ramps.accent[n]`
34
+ * - `{ state: r }` → `ramps.state[r]`
35
+ * - a bare string → a literal OKLCH value, returned as-is
11
36
  */
12
- /** A color reference: palette index (number) or direct color value (string) */
13
- export type ColorRef = number | string;
37
+ export type RampRef = {
38
+ base: number;
39
+ } | {
40
+ accent: number;
41
+ } | {
42
+ state: StateRole;
43
+ } | OKLCH;
44
+ /** The shared Tier-1 ramps. Values are identical across light/dark modes; the
45
+ * per-mode differences live in `ModeMap`, not here. */
46
+ export interface Ramps {
47
+ /** Warm-neutral base ramp — 5 entries, index 0 = lightest. */
48
+ base: OKLCH[];
49
+ /** Accent ramp — 3 entries. */
50
+ accent: OKLCH[];
51
+ /** The four state colors. */
52
+ state: Record<StateRole, OKLCH>;
53
+ }
54
+ /** The 23 semantic roles that map onto `--zd-*` custom properties. */
55
+ export type SemanticKey = "surface" | "muted" | "accent" | "accentHover" | "codeBg" | "codeFg" | "success" | "danger" | "warning" | "info" | "mermaidNodeBg" | "mermaidText" | "mermaidLine" | "mermaidLabelBg" | "mermaidNoteBg" | "chatUserBg" | "chatUserText" | "chatAssistantBg" | "chatAssistantText" | "imageOverlayBg" | "imageOverlayFg" | "matchedKeywordBg" | "matchedKeywordFg";
56
+ /** Canonical order of the 23 semantic roles — used for `--zd-*` emit. */
57
+ export declare const SEMANTIC_KEYS: readonly SemanticKey[];
58
+ /** The per-mode wiring: each UI role points at a ramp stop (or literal OKLCH)
59
+ * via a `RampRef`. Two `ColorScheme`s (light + dark) share `ramps` but carry
60
+ * their own `ModeMap`. */
61
+ export interface ModeMap {
62
+ bg: RampRef;
63
+ fg: RampRef;
64
+ selectionBg: RampRef;
65
+ selectionFg: RampRef;
66
+ semantic: Record<SemanticKey, RampRef>;
67
+ }
68
+ /** A complete color scheme — shared Tier-1 ramps + per-mode Tier-2 wiring. */
14
69
  export interface ColorScheme {
15
- background: ColorRef;
16
- foreground: ColorRef;
17
- cursor: ColorRef;
18
- selectionBg: ColorRef;
19
- selectionFg: ColorRef;
20
- palette: [
21
- string,
22
- string,
23
- string,
24
- string,
25
- string,
26
- string,
27
- string,
28
- string,
29
- string,
30
- string,
31
- string,
32
- string,
33
- string,
34
- string,
35
- string,
36
- string
37
- ];
38
- /** Optional, vestigial — no visible effect on rendering; carried only for
39
- * the zdtp design-token panel config envelope. See project CLAUDE.md. */
40
- shikiTheme?: string;
41
- /** Optional semantic overrides. When omitted, defaults from
42
- * `SEMANTIC_DEFAULTS` are used (surface=p0, muted=p8, accent=p5, …). */
43
- semantic?: {
44
- surface?: ColorRef;
45
- muted?: ColorRef;
46
- accent?: ColorRef;
47
- accentHover?: ColorRef;
48
- codeBg?: ColorRef;
49
- codeFg?: ColorRef;
50
- success?: ColorRef;
51
- danger?: ColorRef;
52
- warning?: ColorRef;
53
- info?: ColorRef;
54
- mermaidNodeBg?: ColorRef;
55
- mermaidText?: ColorRef;
56
- mermaidLine?: ColorRef;
57
- mermaidLabelBg?: ColorRef;
58
- mermaidNoteBg?: ColorRef;
59
- chatUserBg?: ColorRef;
60
- chatUserText?: ColorRef;
61
- chatAssistantBg?: ColorRef;
62
- chatAssistantText?: ColorRef;
63
- /** UI chrome over user images — enlarge/close overlay buttons */
64
- imageOverlayBg?: ColorRef;
65
- imageOverlayFg?: ColorRef;
66
- /** <mark> highlight for matched keywords in search results */
67
- matchedKeywordBg?: ColorRef;
68
- matchedKeywordFg?: ColorRef;
70
+ ramps: Ramps;
71
+ map: ModeMap;
72
+ }
73
+ /** Default per-mode semantic wiring (Default Dark reference — see epic #2584).
74
+ * Scheme authors spread this into `map.semantic` and override individual roles
75
+ * where a mode needs a different stop (or a per-mode AA-tuned literal). */
76
+ export declare const SEMANTIC_RAMP_DEFAULTS: Record<SemanticKey, RampRef>;
77
+ export declare const SEMANTIC_CSS_NAMES: Record<SemanticKey, string>;
78
+ /**
79
+ * Resolve a `RampRef` to a concrete color string against the given `ramps`.
80
+ * - `{ base: n }` → `ramps.base[n]`
81
+ * - `{ accent: n }` → `ramps.accent[n]`
82
+ * - `{ state: r }` → `ramps.state[r]`
83
+ * - a bare string → the literal OKLCH value, returned as-is
84
+ *
85
+ * Throws on an out-of-range ramp index — a ramp reference to a stop that does
86
+ * not exist is a programming/authoring error and must fail loud rather than
87
+ * silently emit an invalid CSS value.
88
+ */
89
+ export declare function resolveRampRef(ref: RampRef, ramps: Ramps): string;
90
+ /** Resolve every semantic role to a concrete color string via the scheme's
91
+ * per-mode `map.semantic` wiring. Returns all 23 keys. */
92
+ export declare function resolveSemanticColors(scheme: ColorScheme): Record<SemanticKey, string>;
93
+ export interface TierItem {
94
+ /** Stable id used as the Record key in persisted state (e.g. `surface`). */
95
+ id: string;
96
+ /** CSS custom property name written to `:root` (e.g. `--zd-surface`). */
97
+ cssVar: string;
98
+ /** Display label in the panel UI. */
99
+ label: string;
100
+ /** Default value — a panel-encoded ramp reference or literal OKLCH string. */
101
+ default: string;
102
+ /** Always the OKLCH color picker for semantic-tier rows. */
103
+ type: {
104
+ kind: "color";
105
+ format: "oklch";
69
106
  };
70
107
  }
71
- /** Default mapping: semantic token name → palette index */
72
- export declare const SEMANTIC_DEFAULTS: Record<string, number>;
73
- export declare const SEMANTIC_CSS_NAMES: Record<string, string>;
74
- /** Resolve a ColorRef to a concrete color string.
75
- * - number → palette[value]
76
- * - string → used as-is
77
- * - undefined → fallback */
78
- export declare function resolveColor(value: ColorRef | undefined, palette: string[], fallback: string): string;
79
- /** Resolve semantic colors with fallbacks to default palette slots */
80
- export declare function resolveSemanticColors(scheme: ColorScheme): {
81
- surface: string;
82
- muted: string;
83
- accent: string;
84
- accentHover: string;
85
- codeBg: string;
86
- codeFg: string;
87
- success: string;
88
- danger: string;
89
- warning: string;
90
- info: string;
91
- mermaidNodeBg: string;
92
- mermaidText: string;
93
- mermaidLine: string;
94
- mermaidLabelBg: string;
95
- mermaidNoteBg: string;
96
- chatUserBg: string;
97
- chatUserText: string;
98
- chatAssistantBg: string;
99
- chatAssistantText: string;
100
- imageOverlayBg: string;
101
- imageOverlayFg: string;
102
- matchedKeywordBg: string;
103
- matchedKeywordFg: string;
104
- };
105
- /** Convert a ColorScheme to a flat list of [cssProperty, value] pairs.
106
- * The result is the exact set of `--zd-*` custom properties that the
107
- * ColorSchemeProvider emits onto `:root`. */
108
- export declare function schemeToCssPairs(scheme: ColorScheme): [string, string][];
109
108
  /**
110
- * Generate the `:root { --zd-* }` CSS block for a single active color scheme.
109
+ * Encode a `RampRef` to the explicit `tierId:itemId` form the design-token
110
+ * panel's grouped ramp picker (`referencesRamps`) expects as an item default:
111
+ * - `{ base: n }` → `'base:base-n'`
112
+ * - `{ accent: n }` → `'accent:accent-n'`
113
+ * - `{ state: r }` → `'state:state-r'`
114
+ * - a bare string → returned as-is (a literal OKLCH/hex passthrough)
115
+ *
116
+ * Always the explicit form (independent of `referencesRamps` declaration
117
+ * order) — see item-id contract in `buildRampTiers`
118
+ * (`src/config/design-token-panel-config.ts`): tier ids `base`/`accent`/`state`,
119
+ * item ids `base-0..4`/`accent-0..2`/`state-{danger,success,warning,info}`.
120
+ */
121
+ export declare function rampRefToPanelDefault(ref: RampRef): string;
122
+ /**
123
+ * Build the 27-row mode-scoped semantic tier's `items` for the design-token
124
+ * panel, from a single (already mode-resolved) `ColorScheme`: 4 base roles
125
+ * (`bg`, `fg`, `selection-bg`, `selection-fg`) followed by the 23
126
+ * `SEMANTIC_KEYS` rows, in that order. Every row's `default` is
127
+ * `rampRefToPanelDefault` of the scheme's `map` entry for that role — never a
128
+ * resolved literal color — so the panel's grouped ramp dropdown can decode it
129
+ * back to a ramp reference (the no-snapping guarantee: a scheme with no
130
+ * persisted override always round-trips through the panel to the exact same
131
+ * ramp stop, not a resolved color that happens to match).
132
+ */
133
+ export declare function buildSemanticTierItems(scheme: ColorScheme): TierItem[];
134
+ /** Which tiers a `schemeToCssPairs` call emits:
135
+ * - `"all"` (default) — base roles + `--palette-*` + `--zd-*` semantic
136
+ * - `"palette"` — only the bare Tier-1 `--palette-*` pairs
137
+ * - `"roles"` — base roles + the 23 `--zd-*` semantic pairs
138
+ *
139
+ * The split lets `generateLightDarkCssProperties` emit the shared `--palette-*`
140
+ * once (bare) while wrapping the per-mode `--zd-*` roles in `light-dark(…)`.
141
+ * (A literal `"light"|"dark"` param would be inert here — each `ColorScheme`'s
142
+ * own `map` already encodes its mode.) */
143
+ export type CssEmitScope = "all" | "palette" | "roles";
144
+ /**
145
+ * Convert a `ColorScheme` to a flat list of `[cssProperty, value]` pairs.
146
+ *
147
+ * The full (`"all"`) set is the exact set of custom properties the
148
+ * ColorSchemeProvider emits onto `:root`:
149
+ * - base roles: `--zd-bg`, `--zd-fg`, `--zd-selection-bg`, `--zd-selection-fg`
150
+ * - Tier-1 ramps: `--palette-base-0..4`, `--palette-accent-0..2`,
151
+ * `--palette-state-{danger,success,warning,info}`
152
+ * - the 23 Tier-2 `--zd-{role}` semantic tokens
153
+ *
154
+ * It intentionally does NOT emit the retired `--zd-0..15` slots or `--zd-cursor`.
155
+ */
156
+ export declare function schemeToCssPairs(scheme: ColorScheme, scope?: CssEmitScope): [string, string][];
157
+ /**
158
+ * Generate the `:root { … }` CSS block for a single active color scheme.
111
159
  *
112
160
  * The caller passes in the active `ColorScheme` object — resolved from the
113
161
  * project's `colorSchemes` map and `settings.colorScheme`. This function is
@@ -115,11 +163,14 @@ export declare function schemeToCssPairs(scheme: ColorScheme): [string, string][
115
163
  */
116
164
  export declare function generateCssCustomProperties(scheme: ColorScheme): string;
117
165
  /**
118
- * Generate the `:root { --zd-*: light-dark(…, ); }` CSS block for a
119
- * light/dark pair.
166
+ * Generate the `:root { … }` CSS block for a light/dark pair.
167
+ *
168
+ * Tier-1 `--palette-*` properties are shared across modes (the ramps carry the
169
+ * same values in both schemes), so they are emitted ONCE, bare. The per-mode
170
+ * `--zd-*` roles (base roles + semantic) are wrapped in `light-dark(L, D)`.
120
171
  *
121
172
  * The caller passes in the `light` and `dark` `ColorScheme` objects — resolved
122
- * from the project's `colorSchemes` map and `settings.colorMode`. This
123
- * function is DATA-free.
173
+ * from the project's `colorSchemes` map and `settings.colorMode`. This function
174
+ * is DATA-free.
124
175
  */
125
176
  export declare function generateLightDarkCssProperties(light: ColorScheme, dark: ColorScheme): string;