@takazudo/zdtp 0.4.3 → 0.4.5

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.
@@ -86,7 +86,12 @@ export interface PanelConfig {
86
86
  consoleNamespace: string;
87
87
  /** BEM-style prefix used by every modal in the panel (export / import / apply). */
88
88
  modalClassPrefix: string;
89
- /** `$schema` value emitted into export JSON and required on import. */
89
+ /**
90
+ * Schema label surfaced in the Import modal's hint/placeholder/error text
91
+ * and the Export modal's copy. NOT enforced: `serialize()`/`deserialize()`
92
+ * always use the fixed `SCHEMA_V1`/`SCHEMA_V2`/`SCHEMA_V3` constants
93
+ * regardless of this value (#498).
94
+ */
90
95
  schemaId: string;
91
96
  /** Default filename base — exports save as `${exportFilenameBase}.json`. */
92
97
  exportFilenameBase: string;
@@ -364,6 +369,24 @@ export declare function getPanelConfigByPrefix(prefix: string): PanelConfig | nu
364
369
  * instance, parked presets, and parked pre-configure hooks.
365
370
  */
366
371
  export declare function __resetPanelConfigForTests(): void;
372
+ /**
373
+ * #501 — record that the panel instance keyed by `prefix` wrote `color-scheme`
374
+ * to its apply target. Called from the apply path (`applyColorState`) wherever
375
+ * a per-mode literal forces `color-scheme: light dark`.
376
+ */
377
+ export declare function markColorSchemeWritten(prefix: string): void;
378
+ /**
379
+ * #501 — drop the color-scheme ownership claim for `prefix`. Called from the
380
+ * clear paths after a panel-written `color-scheme` is removed (or found to have
381
+ * been overwritten by the host — the stale-ownership case).
382
+ */
383
+ export declare function clearColorSchemeOwnership(prefix: string): void;
384
+ /**
385
+ * #501 — true when the panel instance keyed by `prefix` is the recorded writer
386
+ * of the current inline `color-scheme`. Gates the clear paths so the panel
387
+ * never removes a `color-scheme` it did not write.
388
+ */
389
+ export declare function ownsColorScheme(prefix: string): boolean;
367
390
  export { resolvePrimaryColorCluster, resolveSecondaryColorClusterFromTabs, } from './cluster-config';
368
391
  import type { ColorClusterDataConfig } from './cluster-config';
369
392
  /**
@@ -391,6 +414,18 @@ export declare function storageKey_stateV2(cfg: PanelConfig): string;
391
414
  * this key, then deletes the v2 key.
392
415
  */
393
416
  export declare function storageKey_stateV3(cfg: PanelConfig): string;
417
+ /**
418
+ * Storage key for the v4 unified envelope. Upgrades the "global tweak model" to
419
+ * per-scheme color persistence (#500/#509): the `color` and `secondary` slices
420
+ * become identity-keyed sub-objects (one slot per resolved scheme/mode), so a
421
+ * per-scheme color tweak survives a scheme toggle round-trip instead of being
422
+ * clobbered by the next unrelated edit. Non-color slices stay global. Kept a
423
+ * SINGLE storage key (not one key per scheme) because the Astro bootstrap must
424
+ * existence-check persistence before cluster config loads — a per-scheme key
425
+ * would hit a chicken-and-egg there. v1/v2/v3 migrate into this key on first
426
+ * load; v4 takes precedence on every subsequent load.
427
+ */
428
+ export declare function storageKey_stateV4(cfg: PanelConfig): string;
394
429
  /** Legacy v1 key (Color-only flat state). Migrated into v2 on first load, then deleted. */
395
430
  export declare function storageKey_stateV1(cfg: PanelConfig): string;
396
431
  /** Mirror of the panel's `open` boolean (synchronous mount-time read). */
@@ -1,38 +1,82 @@
1
1
  import type { TabConfig } from '../tokens/tier-model';
2
2
  /**
3
- * Sentinel string passed to `onChange` when the user picks "Literal...".
4
- * The parent component interprets this as a request to flip the item back
5
- * into its kind-specific editor (slider / text / select) writing a literal
6
- * CSS override.
3
+ * Names one item in a (possibly cross-tab) tier. `tab` omitted means "the tab
4
+ * `TierRefSelector` itself renders in" — the intra-tab case used by the
5
+ * font/spacing/size/generic-tab consumers, whose refs never cross tabs.
7
6
  */
8
- export declare const TIER_REF_LITERAL_SIGNAL: "__literal__";
7
+ export interface TierRefTarget {
8
+ tab?: string;
9
+ tier: string;
10
+ item: string;
11
+ }
12
+ /**
13
+ * The value `TierRefSelector` reads and writes. Mirrors the `{ ref } | {
14
+ * literal }` variants of `SemanticValue` (`tokens/tier-model.ts`) — including
15
+ * the per-mode `{ literal: { light, dark } }` shape (#472/#473) — so the
16
+ * Color tab can pass a semantic mapping straight through. Flat/intra-tab
17
+ * consumers (font/spacing/size/generic-tab) wrap their bare `TokenOverrides`
18
+ * string into `{ ref: { tier, item } }` at the call site, and unwrap a
19
+ * `{ literal }` response back into "drop the override" — see those tabs'
20
+ * `onChange` handlers. Those flat consumers never produce a per-mode literal.
21
+ */
22
+ export type TierRefSelectorValue = {
23
+ ref: TierRefTarget;
24
+ } | {
25
+ literal: string;
26
+ } | {
27
+ literal: {
28
+ light: string;
29
+ dark: string;
30
+ };
31
+ };
9
32
  export interface TierRefSelectorProps {
10
- /** Full tab config — needed to look up the referenced tier and its items. */
33
+ /** The tab this row belongs to — provides the semantic/reference tier
34
+ * config and doubles as the default "current tab" for intra-tab refs. */
11
35
  tab: TabConfig;
12
- /** The tier whose item is being edited (the "semantic" / reference tier). */
36
+ /**
37
+ * Full panel tabs array, needed to resolve a grouped tier's cross-tab ramp
38
+ * sources. Defaults to `[tab]` — fine for intra-tab (flat) callers, which
39
+ * never reference another tab.
40
+ */
41
+ tabs?: readonly TabConfig[];
42
+ /** The tier whose item is being edited (the semantic / reference tier). */
13
43
  tierId: string;
14
44
  /** The item being edited within `tierId`. */
15
45
  itemId: string;
46
+ /** Current value — a ramp/ref target, or a literal color/CSS string. */
47
+ value: TierRefSelectorValue;
16
48
  /**
17
- * The current stored value for this item — an item id within the
18
- * referenced (tier-1) tier. Empty string or an unrecognised id is treated
19
- * as "pick the first item" (mirrors resolver fallback).
49
+ * Called when the user commits a selection or edits the literal value.
50
+ *
51
+ * - Picking a ramp/ref option: `onChange(itemId, { ref: {...} })`
52
+ * - Picking "Literal…" or editing the literal swatch (grouped mode only):
53
+ * `onChange(itemId, { literal: <value> })`
20
54
  */
21
- value: string;
55
+ onChange: (itemId: string, next: TierRefSelectorValue) => void;
22
56
  /**
23
- * Called when the user commits a selection.
24
- *
25
- * - Picking a tier-1 item: `onChange(itemId, selectedRefItemId)`
26
- * - Picking "Literal...": `onChange(itemId, TIER_REF_LITERAL_SIGNAL)`
57
+ * Returns the resolved (override-aware) preview string for a ramp/ref
58
+ * target. Each option label is formatted as `${item.cssVar} (${truncated
59
+ * preview})`. Falls back to the target item's manifest `default` when
60
+ * omitted.
61
+ */
62
+ previewValueFor?: (ref: TierRefTarget) => string;
63
+ /**
64
+ * Friendly label used for the literal-mode `ColorField` editor (grouped
65
+ * mode only) and the select's `aria-label`. Defaults to `itemId`.
66
+ */
67
+ label?: string;
68
+ /**
69
+ * The row's own cssVar — threaded into the literal-mode `ColorField`
70
+ * editor for its `aria-label`, matching `SemanticLiteralRow`'s convention.
27
71
  */
28
- onChange: (itemId: string, next: string) => void;
72
+ cssVar?: string;
29
73
  /**
30
- * Returns the resolved (override-aware) preview string for a tier-1 item id.
31
- * Each option label is formatted as `${item.cssVar} (${truncated preview})`.
32
- * Pass a wrapper around resolveTierItemValue using the current tweak-state map.
74
+ * The cluster's `getClusterDefaultMode()` result (#472) — used only when
75
+ * the user collapses a per-mode literal back to single-mode, to pick which
76
+ * side (`light` or `dark`) survives. Defaults to `'light'`.
33
77
  */
34
- previewValueFor: (refItemId: string) => string;
78
+ defaultMode?: 'light' | 'dark';
35
79
  }
36
- declare function TierRefSelector({ tab, tierId, itemId, value, onChange, previewValueFor }: TierRefSelectorProps): import("preact").JSX.Element;
80
+ declare function TierRefSelector({ tab, tabs, tierId, itemId, value, onChange, previewValueFor, label, cssVar, defaultMode, }: TierRefSelectorProps): import("preact").JSX.Element;
37
81
  declare const _default: typeof TierRefSelector;
38
82
  export default _default;
@@ -1,8 +1,10 @@
1
1
  /**
2
2
  * Export modal — renders the current `TweakState` as a design-tokens JSON
3
- * document (default schema: `zudo-design-tokens/v1`; configurable via
4
- * `panelConfig.schemaId`) with a diff-only toggle and a copy-to-clipboard
5
- * button.
3
+ * document (`serialize()` emits `SCHEMA_V2` or opportunistically `SCHEMA_V3`
4
+ * — see `./utils/design-token-serde`; `panelConfig.schemaId` is not read
5
+ * here or anywhere else in this package — it is a UI-label-only field on
6
+ * `PanelConfig` that hosts may read via `getDesignTokenSchema()`, #498) with
7
+ * a diff-only toggle and a copy-to-clipboard button.
6
8
  *
7
9
  * Ported verbatim from zudo-doc's
8
10
  * `src/components/design-token-tweak/export-modal.tsx`. Intentional deltas:
@@ -1,16 +1,16 @@
1
1
  /**
2
- * Import modal — accepts a pasted design-tokens JSON document (default schema:
3
- * `zudo-design-tokens/v1`; configurable via `panelConfig.schemaId`) and lifts
4
- * it into a `TweakState` via `deserialize()`. Validation and unknown-token
5
- * reporting are delegated to serde; this component only renders status
6
- * feedback and routes the parsed state up to the shell.
2
+ * Import modal — accepts a pasted design-tokens JSON document and lifts it
3
+ * into a `TweakState` via `deserialize()`. `deserialize()` validates the
4
+ * `$schema` key against the fixed `SCHEMA_V1`/`SCHEMA_V2`/`SCHEMA_V3`
5
+ * constants exported by the serde — `panelConfig.schemaId` plays no part in
6
+ * that validation; it is a UI-label-only field (#498). This component does
7
+ * not read `schemaId` at all; the hint/placeholder/error copy below names
8
+ * the actual accepted constants directly.
7
9
  *
8
10
  * Ported verbatim from zudo-doc's
9
11
  * `src/components/design-token-tweak/import-modal.tsx`. Intentional deltas:
10
- * - `deserialize` / `DesignTokenSchemaError` / `getDesignTokenSchema` come
11
- * from this package's serde (`./utils/design-token-serde`); the schema
12
- * id is read at render time from `panelConfig.schemaId` instead of
13
- * being a module-level constant.
12
+ * - `deserialize` / `DesignTokenSchemaError` come from this package's serde
13
+ * (`./utils/design-token-serde`).
14
14
  * - State types import from this package's state envelope.
15
15
  * - Modal class names are derived from `panelConfig.modalClassPrefix` via
16
16
  * `modalClass(...)` so a single config swap re-themes every dialog.
package/dist/index.d.ts CHANGED
@@ -60,6 +60,8 @@ export type { TierValueKind, PillSpec, TierItem, TierConfig, TabConfig, ColorClu
60
60
  export { isLengthKind, isNumberKind, isSelectKind, isTextKind, isColorKind, isCursorKind, isContentKind, isMaskImageKind, } from './tokens/tier-model';
61
61
  export type { TweakState } from './state/tweak-state';
62
62
  export { emptyOverrides } from './state/tweak-state';
63
+ export { SCHEMA_V1, SCHEMA_V2, SCHEMA_V3, } from './utils/design-token-serde';
64
+ export { getClusterDefaultMode, resolvePerModeLiteral, resolveSemanticPreviewColor, } from './state/tweak-state';
63
65
  export declare function showDesignTokenPanel(): void;
64
66
  export declare function hideDesignTokenPanel(): void;
65
67
  export declare function toggleDesignPanel(): void;