@vectoriox/iox-ui 5.42.0 → 5.43.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.
@@ -1,13 +1,14 @@
1
1
  import { deriveBrandTokens } from './brand';
2
- import { SPEC_LEGACY_ALIASES } from './flavor-spec.generated';
2
+ import { FLAVOR_SPEC_VERSION, SPEC_LEGACY_ALIASES } from './flavor-spec.generated';
3
3
  import { SWISS_FLAVOR } from './flavor';
4
4
  import { buildFlavorTokens, legacyFlavorTokens } from './flavor-tokens';
5
5
  import {
6
- FlavorRevertPlan, FlavorSeedOptions, FlavorSeedPlan, planFlavorRevert, planFlavorSeed, SeedBaseline, SeedExpectation, untouchedSeedRow,
6
+ FlavorRevertPlan, FlavorRevertSnapshot, FlavorSeedOptions, FlavorSeedPlan, flavorSeedWrites, planFlavorRevert, planFlavorSeed, SeedBaseline,
7
+ SeedExpectation, untouchedSeedRow,
7
8
  } from './flavor-seed';
8
9
  import { DesignChoices, DesignTokenRow, flavorSourceStamp, StoredDesignTokenRow } from './design-token.model';
9
10
  import { fontFamilyKey, FontFamilyToken, fontRoleReferences, parseFontFamilies } from './fonts';
10
- import { flavorPackById, isRetiredFlavorId, packDesignChoices, StoredDesign } from './design-settings';
11
+ import { DesignConfigEntry, DesignConfigKey, designConfigEntries, flavorPackById, isRetiredFlavorId, packDesignChoices, StoredDesign } from './design-settings';
11
12
 
12
13
  /**
13
14
  * Applying a look (design-system DS4): the COMPLETE `buildFlavorTokens` set for the chosen
@@ -125,6 +126,58 @@ export function planDesignRevert(current: ReadonlyArray<StoredDesignTokenRow>, d
125
126
  return planFlavorRevert(current, snapshot.tokens, snapshot.wrote ?? designTokenRows(design.choices));
126
127
  }
127
128
 
129
+ /** The revert snapshot an Apply stores in `settings.design` (board F7): design-core's snapshot plus the design
130
+ * row's previous config VERBATIM, so a revert restores every choice (pair, axes, mode, fonts), not only the
131
+ * flavor id and seed. */
132
+ export interface DesignRevertSnapshot extends FlavorRevertSnapshot {
133
+ fromConfig?: DesignConfigEntry[];
134
+ }
135
+
136
+ /**
137
+ * What an Apply of `plan` stores as its revert snapshot — the ONE rule the builder's Apply and the
138
+ * server-side site build (W2) share: the whole pre-apply token set, what the apply writes into each row,
139
+ * and where a revert goes back to — never a null flavor (a studio with no design row wore its design's
140
+ * defaults, so that is what it returns to). An apply that writes nothing keeps the previous snapshot:
141
+ * clobbering a useful one with "nothing changed" would be a lie.
142
+ */
143
+ export function designApplySnapshot(
144
+ previous: StoredDesign,
145
+ previousConfig: ReadonlyArray<DesignConfigEntry> | null | undefined,
146
+ existing: ReadonlyArray<StoredDesignTokenRow>,
147
+ plan: FlavorSeedPlan,
148
+ appliedAt: number,
149
+ ): DesignRevertSnapshot | null {
150
+ if (!plan.create.length && !plan.update.length) return previous.revert;
151
+ const origin: Pick<DesignRevertSnapshot, 'from' | 'fromConfig'> = previous.storedFlavorId
152
+ ? {
153
+ from: { flavorId: previous.storedFlavorId, flavorVersion: previous.flavorVersion, brandSeed: previous.storedSeed },
154
+ fromConfig: (previousConfig ?? []).filter(kv => kv?.key !== DesignConfigKey.Revert),
155
+ }
156
+ : {
157
+ from: { flavorId: previous.choices.flavorId, flavorVersion: String(FLAVOR_SPEC_VERSION), brandSeed: previous.choices.seed },
158
+ fromConfig: designConfigEntries(previous.choices, FLAVOR_SPEC_VERSION, null),
159
+ };
160
+ return {
161
+ appliedAt,
162
+ ...origin,
163
+ tokens: (existing ?? []).map(r => ({ name: r.name, type: r.type, value: r.value, values: r.values, source: r.source, group: r.group, tier: r.tier })),
164
+ wrote: flavorSeedWrites(plan, existing),
165
+ };
166
+ }
167
+
168
+ /** The config a revert puts back: the snapshot's verbatim config, else (a snapshot older than `fromConfig`)
169
+ * the identity it recorded. */
170
+ export function designRevertConfig(snapshot: DesignRevertSnapshot): DesignConfigEntry[] {
171
+ if (snapshot.fromConfig) return snapshot.fromConfig;
172
+ return [
173
+ ...(snapshot.from.flavorId ? [
174
+ { key: DesignConfigKey.FlavorId, value: snapshot.from.flavorId },
175
+ { key: DesignConfigKey.FlavorVersion, value: snapshot.from.flavorVersion ?? '' },
176
+ ] : []),
177
+ ...(snapshot.from.brandSeed ? [{ key: DesignConfigKey.BrandSeed, value: snapshot.from.brandSeed }] : []),
178
+ ];
179
+ }
180
+
128
181
  /** The rows a design is missing by name — the builder-load top-up (never touches an existing row). */
129
182
  export function missingDesignRows(existing: ReadonlyArray<{ name: string }>, choices: DesignChoices): DesignTokenRow[] {
130
183
  const have = new Set((existing ?? []).map(r => r.name));