@adea-ai/app-framework 0.30.0 → 0.31.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/dist/app/application.js +4 -2
  2. package/dist/appearance/appearance-host.js +6 -0
  3. package/dist/appearance/appearance-preferences.js +6 -2
  4. package/dist/appearance/composition.d.ts +1 -1
  5. package/dist/appearance/custom-theme-import.js +12 -19
  6. package/dist/appearance/custom-theme-library.d.ts +5 -4
  7. package/dist/appearance/custom-theme-library.js +20 -2
  8. package/dist/appearance/editor.js +4 -1
  9. package/dist/appearance/legacy-imported-theme-token-projection.d.ts +84 -0
  10. package/dist/appearance/legacy-imported-theme-token-projection.js +142 -0
  11. package/dist/appearance/theme-record-adapter.js +37 -9
  12. package/dist/framework-source.json +1 -1
  13. package/dist/shell/app-shell.js +76 -48
  14. package/dist/shell/app-utilities.d.ts +5 -3
  15. package/dist/shell/app-utilities.js +15 -7
  16. package/dist/shell/help-shortcuts.d.ts +4 -0
  17. package/dist/shell/help-shortcuts.js +38 -7
  18. package/dist/shell/keyboard-target.d.ts +2 -0
  19. package/dist/shell/keyboard-target.js +54 -0
  20. package/dist/shell/settings-sections.d.ts +5 -0
  21. package/dist/shell/settings-shortcuts.d.ts +10 -0
  22. package/dist/shell/settings-shortcuts.js +67 -0
  23. package/dist/views/app-help.js +2 -1
  24. package/dist/views/app-settings.js +5 -2
  25. package/dist/views/appearance-surface.js +33 -19
  26. package/package.json +6 -4
  27. package/src/app/application.tsx +3 -1
  28. package/src/appearance/appearance-host.tsx +6 -0
  29. package/src/appearance/appearance-preferences.ts +7 -1
  30. package/src/appearance/composition.ts +3 -1
  31. package/src/appearance/custom-theme-import.ts +21 -37
  32. package/src/appearance/custom-theme-library.ts +21 -5
  33. package/src/appearance/editor.ts +7 -6
  34. package/src/appearance/legacy-imported-theme-token-projection.ts +51 -0
  35. package/src/appearance/theme-record-adapter.ts +58 -11
  36. package/src/shell/app-shell.tsx +88 -58
  37. package/src/shell/app-utilities.tsx +29 -17
  38. package/src/shell/help-shortcuts.ts +77 -6
  39. package/src/shell/keyboard-target.ts +74 -0
  40. package/src/shell/settings-sections.ts +5 -0
  41. package/src/shell/settings-shortcuts.ts +116 -0
  42. package/src/views/app-settings.tsx +5 -3
  43. package/src/views/appearance-surface.tsx +63 -27
@@ -37,7 +37,8 @@ function Application(props) {
37
37
  });
38
38
  const view = createMemo(() => {
39
39
  routerRevision();
40
- return props.definition.views.find((item) => item.id === (props.router?.current() ?? localView())) ?? props.definition.views.find((item) => item.id === props.definition.initialView);
40
+ const selected = props.router?.current() ?? localView();
41
+ return props.definition.views.find((item) => item.id === selected) ?? props.definition.views.find((item) => item.id === props.definition.initialView);
41
42
  });
42
43
  const navigate = (id) => {
43
44
  if (!props.definition.views.some((item) => item.id === id)) return;
@@ -118,7 +119,8 @@ function Application(props) {
118
119
  get help() {
119
120
  return memo(() => !!props.utilities?.help)() && {
120
121
  search: Boolean(props.onSearch),
121
- ...props.utilities.help
122
+ ...props.utilities.help,
123
+ searchBinding: Boolean(props.onSearch)
122
124
  };
123
125
  },
124
126
  get identity() {
@@ -1,8 +1,10 @@
1
+ import { LEGACY_IMPORTED_THEME_TOKEN_PROJECTION } from "./legacy-imported-theme-token-projection.js";
1
2
  import { appearanceThemeScript, createAppearancePersistence, selectionFromPreferences } from "./appearance-preferences.js";
2
3
  import { customUiVariants, readCustomThemeLibrary, subscribeCustomThemes } from "./custom-theme-library.js";
3
4
  import { createComponent, effect, mergeProps, template } from "solid-js/web";
4
5
  import { createContext, createEffect, createSignal, useContext } from "solid-js";
5
6
  import { ThemeProvider as ThemeProvider$1, useOptionalTheme } from "@adea-ai/ui/components/theme/lazy";
7
+ import { projectThemeTokens } from "@adea-ai/ui/components/theme/token-projection";
6
8
  import { defaultPreferenceStorage } from "@adea-ai/ui/lib/preference-store";
7
9
  import { tokensAsHex } from "@adea-ai/ui/lib/themes";
8
10
  // src/appearance/appearance-host.tsx
@@ -30,6 +32,10 @@ function appearanceProviderProps(options = {}) {
30
32
  palette: "stylesheet",
31
33
  accentContrastFloor: 3,
32
34
  editorRoles: "floor",
35
+ tokenProjection: {
36
+ rules: LEGACY_IMPORTED_THEME_TOKEN_PROJECTION,
37
+ project: projectThemeTokens
38
+ },
33
39
  transformTokens: tokensAsHex,
34
40
  disableTransitionOnChange: true,
35
41
  fontZoom: true
@@ -1,6 +1,8 @@
1
- import { createVersionedPersistence, themeScript } from "@adea-ai/ui/components/theme/lazy";
1
+ import { LEGACY_IMPORTED_THEME_TOKEN_PROJECTION, LEGACY_IMPORTED_THEME_TOKEN_PROJECTION_FALLBACKS } from "./legacy-imported-theme-token-projection.js";
2
+ import { createVersionedPersistence } from "@adea-ai/ui/components/theme/lazy";
2
3
  import { isThemeAccentId } from "@adea-ai/ui/lib/themes";
3
4
  import { getAccent } from "@adea-ai/ui/lib/accent-presets";
5
+ import { themeScript } from "@adea-ai/ui/components/theme/script-projection";
4
6
  import { colorToHex, parseColor } from "@adea-ai/ui/lib/accent-roles";
5
7
  import { DEFAULT_APPEARANCE_EDITOR_FONT_SETTINGS, normalizeAppearanceEditorFontSettings } from "@adea-ai/ui/lib/appearance-font-settings";
6
8
  import { normalizeSurface } from "@adea-ai/ui/lib/theme-surface";
@@ -169,7 +171,9 @@ function appearanceThemeScript() {
169
171
  ...appearanceSchema,
170
172
  defaultAccent: DEFAULT_ACCENT_PRESET_ID,
171
173
  surface: true,
172
- palette: "stylesheet"
174
+ palette: "stylesheet",
175
+ tokenProjection: LEGACY_IMPORTED_THEME_TOKEN_PROJECTION,
176
+ tokenProjectionFallbacks: LEGACY_IMPORTED_THEME_TOKEN_PROJECTION_FALLBACKS
173
177
  });
174
178
  }
175
179
  export { APPEARANCE_ACCENT_CONTRAST_FLOOR, APPEARANCE_LIBRARY_STORAGE_KEY, APPEARANCE_RECOVERY_STORAGE_KEY, APPEARANCE_STORAGE_KEY, DEFAULT_ACCENT_PRESET_ID, adeaV2Codec, appearanceDocument, appearanceSchema, appearanceThemeScript, createAppearancePersistence, defaultAppearancePreferences, normalizeAppearancePreferences, preferencesFromSelection, selectionFromPreferences };
@@ -5,7 +5,7 @@ import type { AppearancePreferencesV2 } from './appearance-preferences';
5
5
  * draft so the System split, Light, and Dark cards track unsaved theme picks
6
6
  * the same instant the real chrome does.
7
7
  */
8
- export declare function draftVariants(preferences: AppearancePreferencesV2): {
8
+ export declare function draftVariants(preferences: Pick<AppearancePreferencesV2, 'lightThemeId' | 'darkThemeId'>): {
9
9
  light: ThemeVariant;
10
10
  dark: ThemeVariant;
11
11
  };
@@ -1,4 +1,6 @@
1
+ import { LEGACY_IMPORTED_THEME_TOKEN_PROJECTION } from "./legacy-imported-theme-token-projection.js";
1
2
  import { flatVariantTokens, mutateCustomThemeLibrary, validateThemeRegistry } from "./custom-theme-library.js";
3
+ import { projectThemeTokens } from "@adea-ai/ui/components/theme/token-projection";
2
4
  import { colorToHex, contrastRatio, ensureContrast, parseColor } from "@adea-ai/ui/lib/accent-roles";
3
5
  import { defaultThemeRecord, editorRolesHex, oklchToHex, parseOklchColor, shadcnDestructiveProjection, shadcnVariables, syntaxRolesHex, toXtermTheme } from "@adea-ai/ui/lib/theme-projection";
4
6
  // src/appearance/custom-theme-import.ts
@@ -121,21 +123,6 @@ function repairComponentContrast(variant, notes) {
121
123
  }
122
124
  };
123
125
  }
124
- /** Preserve accessible sidebar pairs that the catalogue record would otherwise re-derive. */
125
- function sidebarTokens(variant, notes) {
126
- const colors = variant.colors;
127
- return {
128
- "--sidebar": colors.card,
129
- "--sidebar-foreground": repairToFloor(colors.cardForeground, colors.card, notes, "sidebar foreground"),
130
- "--sidebar-muted-foreground": repairToFloor(colors.mutedForeground, colors.card, notes, "sidebar muted foreground"),
131
- "--sidebar-accent": colors.accent,
132
- "--sidebar-accent-foreground": repairToFloor(colors.accentForeground, colors.accent, notes, "sidebar accent foreground"),
133
- "--sidebar-border": colors.border,
134
- "--sidebar-primary": colors.primary,
135
- "--sidebar-primary-foreground": repairToFloor(colors.primaryForeground, colors.primary, notes, "sidebar primary foreground"),
136
- "--sidebar-ring": colors.ring
137
- };
138
- }
139
126
  function hexOf(value) {
140
127
  const parsed = parseOklchColor(value);
141
128
  return parsed ? oklchToHex(parsed) : value;
@@ -299,6 +286,15 @@ function prepareCustomTheme(text, existing) {
299
286
  };
300
287
  const issues = validateThemeRegistry([variant]).filter((issue) => issue.severity === "error");
301
288
  for (const issue of issues) notes.push(`${issue.variantId}: ${issue.message}`);
289
+ const flatTokens = flatVariantTokens(variant);
290
+ const projectedTokens = projectThemeTokens(flatTokens, LEGACY_IMPORTED_THEME_TOKEN_PROJECTION);
291
+ for (const rule of LEGACY_IMPORTED_THEME_TOKEN_PROJECTION) {
292
+ const sourceValue = flatTokens[rule.source];
293
+ const projectedValue = projectedTokens[rule.target];
294
+ if (!("contrast" in rule) || flatTokens[rule.target] !== void 0 || sourceValue === void 0 || projectedValue === void 0 || projectedValue === sourceValue) continue;
295
+ const role = rule.target.slice(2).replaceAll("-", " ");
296
+ notes.push(`“${role}” was adjusted for readable contrast.`);
297
+ }
302
298
  return {
303
299
  ok: true,
304
300
  theme: {
@@ -307,10 +303,7 @@ function prepareCustomTheme(text, existing) {
307
303
  appearance,
308
304
  importedAt: (/* @__PURE__ */ new Date()).toISOString(),
309
305
  variant,
310
- flatTokens: {
311
- ...flatVariantTokens(variant),
312
- ...sidebarTokens(variant, notes)
313
- },
306
+ flatTokens,
314
307
  notes
315
308
  }
316
309
  };
@@ -9,8 +9,8 @@ import type { ThemeVariant as UiThemeVariant } from '@adea-ai/ui/lib/themes';
9
9
  *
10
10
  * The stored shape is a compatibility surface. Imported themes written by any
11
11
  * earlier build keep resolving: `variant` stays in the host shape below and
12
- * `flatTokens` stays the verbatim token map, so what a user imported is what is
13
- * painted.
12
+ * `flatTokens` stays the verbatim token map. Explicit entries remain authoritative;
13
+ * the sidebar projection recovers only absent source entries from `variant`.
14
14
  */
15
15
  export type StoredThemeAppearance = 'light' | 'dark';
16
16
  export type StoredThemeTerminal = Readonly<{
@@ -89,7 +89,7 @@ export type CustomThemeStored = Readonly<{
89
89
  appearance: StoredThemeAppearance;
90
90
  importedAt: string;
91
91
  variant: StoredThemeVariant;
92
- /** The flat token map the no-flash script applies for a stored selection. */
92
+ /** The verbatim imported map; projection may supply absent sources from `variant`. */
93
93
  flatTokens: Readonly<Record<string, string>>;
94
94
  /** Non-fatal adjustments made while normalizing the file, for the UI. */
95
95
  notes: readonly string[];
@@ -146,7 +146,8 @@ export declare function flatVariantTokens(variant: StoredThemeVariant): Record<s
146
146
  export declare function storedVariantRecord(variant: StoredThemeVariant): AdeaThemeRecord;
147
147
  /**
148
148
  * The shared-provider variant for a stored theme: derived roles from the
149
- * reconstructed record, then `flatTokens` verbatim.
149
+ * reconstructed record, missing sidebar projection sources from the stored variant,
150
+ * then every stored flat token verbatim.
150
151
  *
151
152
  * A record the shared projection cannot map falls back to the default theme of the
152
153
  * same appearance under the stored identity, so an import that the projection
@@ -1,3 +1,4 @@
1
+ import { LEGACY_IMPORTED_THEME_TOKEN_PROJECTION_FALLBACKS } from "./legacy-imported-theme-token-projection.js";
1
2
  import { defaultPreferenceStorage, quarantineRecord } from "@adea-ai/ui/lib/preference-store";
2
3
  import { contrastRatio } from "@adea-ai/ui/lib/accent-roles";
3
4
  import { defaultVariantFor } from "@adea-ai/ui/lib/theme-defaults";
@@ -160,7 +161,8 @@ function storedVariantRecord(variant) {
160
161
  }
161
162
  /**
162
163
  * The shared-provider variant for a stored theme: derived roles from the
163
- * reconstructed record, then `flatTokens` verbatim.
164
+ * reconstructed record, missing sidebar projection sources from the stored variant,
165
+ * then every stored flat token verbatim.
164
166
  *
165
167
  * A record the shared projection cannot map falls back to the default theme of the
166
168
  * same appearance under the stored identity, so an import that the projection
@@ -186,9 +188,25 @@ function toUiVariant(stored) {
186
188
  }
187
189
  };
188
190
  }
191
+ const projectionSources = {};
192
+ for (const fallback of LEGACY_IMPORTED_THEME_TOKEN_PROJECTION_FALLBACKS) {
193
+ if (Object.hasOwn(stored.flatTokens, fallback.token)) continue;
194
+ let value = stored;
195
+ for (const key of fallback.path) {
196
+ if (!value || typeof value !== "object" || !Object.hasOwn(value, key)) {
197
+ value = void 0;
198
+ break;
199
+ }
200
+ value = value[key];
201
+ }
202
+ if (typeof value === "string") projectionSources[fallback.token] = value;
203
+ }
189
204
  return {
190
205
  ...base,
191
- tokens: stored.flatTokens
206
+ tokens: {
207
+ ...projectionSources,
208
+ ...stored.flatTokens
209
+ }
192
210
  };
193
211
  }
194
212
  var libraryHost = globalThis;
@@ -12,13 +12,16 @@ var scalarFields = Object.keys({
12
12
  reduceTransparency: true
13
13
  });
14
14
  function samePreferences(left, right) {
15
+ if (left === right) return true;
16
+ if (!scalarFields.every((field) => left[field] === right[field])) return false;
17
+ if (left.fonts === right.fonts) return true;
15
18
  const leftFonts = normalizeAppearanceEditorFontSettings(left.fonts).settings;
16
19
  const rightFonts = normalizeAppearanceEditorFontSettings(right.fonts).settings;
17
20
  return [
18
21
  "ui",
19
22
  "content",
20
23
  "code"
21
- ].every((axis) => leftFonts[axis].family === rightFonts[axis].family && leftFonts[axis].size === rightFonts[axis].size) && scalarFields.every((field) => left[field] === right[field]);
24
+ ].every((axis) => leftFonts[axis].family === rightFonts[axis].family && leftFonts[axis].size === rightFonts[axis].size);
22
25
  }
23
26
  function createAppearanceEditor(committed = defaultAppearancePreferences) {
24
27
  const [draft, setDraft] = createSignal(committed);
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Sidebar roles added after Framework first persisted imported theme records.
3
+ *
4
+ * Keep this as serializable data so the shared provider and its pre-paint script
5
+ * apply the same rules when they restore a legacy v1 record. The projection fills
6
+ * only absent sidebar tokens; values already stored in the user's library win.
7
+ */
8
+ export declare const LEGACY_IMPORTED_THEME_TOKEN_PROJECTION: readonly [{
9
+ readonly target: '--sidebar';
10
+ readonly source: '--card';
11
+ }, {
12
+ readonly target: '--sidebar-foreground';
13
+ readonly source: '--card-foreground';
14
+ readonly contrast: {
15
+ readonly against: '--sidebar';
16
+ readonly minimum: 4.5;
17
+ };
18
+ }, {
19
+ readonly target: '--sidebar-muted-foreground';
20
+ readonly source: '--muted-foreground';
21
+ readonly contrast: {
22
+ readonly against: '--sidebar';
23
+ readonly minimum: 4.5;
24
+ };
25
+ }, {
26
+ readonly target: '--sidebar-accent';
27
+ readonly source: '--accent';
28
+ }, {
29
+ readonly target: '--sidebar-accent-foreground';
30
+ readonly source: '--accent-foreground';
31
+ readonly contrast: {
32
+ readonly against: '--sidebar-accent';
33
+ readonly minimum: 4.5;
34
+ };
35
+ }, {
36
+ readonly target: '--sidebar-border';
37
+ readonly source: '--border';
38
+ }, {
39
+ readonly target: '--sidebar-primary';
40
+ readonly source: '--primary';
41
+ }, {
42
+ readonly target: '--sidebar-primary-foreground';
43
+ readonly source: '--primary-foreground';
44
+ readonly contrast: {
45
+ readonly against: '--sidebar-primary';
46
+ readonly minimum: 4.5;
47
+ };
48
+ }, {
49
+ readonly target: '--sidebar-ring';
50
+ readonly source: '--ring';
51
+ }];
52
+ /**
53
+ * Older accepted v1 records can omit base flat tokens while retaining their full
54
+ * variant. Both the provider adapter and opt-in prepaint script use these declared
55
+ * paths to recover only those absent projection sources from the unchanged record.
56
+ */
57
+ export declare const LEGACY_IMPORTED_THEME_TOKEN_PROJECTION_FALLBACKS: readonly [{
58
+ readonly token: '--card';
59
+ readonly path: readonly ['variant', 'colors', 'card'];
60
+ }, {
61
+ readonly token: '--card-foreground';
62
+ readonly path: readonly ['variant', 'colors', 'cardForeground'];
63
+ }, {
64
+ readonly token: '--muted-foreground';
65
+ readonly path: readonly ['variant', 'colors', 'mutedForeground'];
66
+ }, {
67
+ readonly token: '--accent';
68
+ readonly path: readonly ['variant', 'colors', 'accent'];
69
+ }, {
70
+ readonly token: '--accent-foreground';
71
+ readonly path: readonly ['variant', 'colors', 'accentForeground'];
72
+ }, {
73
+ readonly token: '--border';
74
+ readonly path: readonly ['variant', 'colors', 'border'];
75
+ }, {
76
+ readonly token: '--primary';
77
+ readonly path: readonly ['variant', 'colors', 'primary'];
78
+ }, {
79
+ readonly token: '--primary-foreground';
80
+ readonly path: readonly ['variant', 'colors', 'primaryForeground'];
81
+ }, {
82
+ readonly token: '--ring';
83
+ readonly path: readonly ['variant', 'colors', 'ring'];
84
+ }];
@@ -0,0 +1,142 @@
1
+ // src/appearance/legacy-imported-theme-token-projection.ts
2
+ /**
3
+ * Sidebar roles added after Framework first persisted imported theme records.
4
+ *
5
+ * Keep this as serializable data so the shared provider and its pre-paint script
6
+ * apply the same rules when they restore a legacy v1 record. The projection fills
7
+ * only absent sidebar tokens; values already stored in the user's library win.
8
+ */
9
+ var LEGACY_IMPORTED_THEME_TOKEN_PROJECTION = [
10
+ {
11
+ target: "--sidebar",
12
+ source: "--card"
13
+ },
14
+ {
15
+ target: "--sidebar-foreground",
16
+ source: "--card-foreground",
17
+ contrast: {
18
+ against: "--sidebar",
19
+ minimum: 4.5
20
+ }
21
+ },
22
+ {
23
+ target: "--sidebar-muted-foreground",
24
+ source: "--muted-foreground",
25
+ contrast: {
26
+ against: "--sidebar",
27
+ minimum: 4.5
28
+ }
29
+ },
30
+ {
31
+ target: "--sidebar-accent",
32
+ source: "--accent"
33
+ },
34
+ {
35
+ target: "--sidebar-accent-foreground",
36
+ source: "--accent-foreground",
37
+ contrast: {
38
+ against: "--sidebar-accent",
39
+ minimum: 4.5
40
+ }
41
+ },
42
+ {
43
+ target: "--sidebar-border",
44
+ source: "--border"
45
+ },
46
+ {
47
+ target: "--sidebar-primary",
48
+ source: "--primary"
49
+ },
50
+ {
51
+ target: "--sidebar-primary-foreground",
52
+ source: "--primary-foreground",
53
+ contrast: {
54
+ against: "--sidebar-primary",
55
+ minimum: 4.5
56
+ }
57
+ },
58
+ {
59
+ target: "--sidebar-ring",
60
+ source: "--ring"
61
+ }
62
+ ];
63
+ /**
64
+ * Older accepted v1 records can omit base flat tokens while retaining their full
65
+ * variant. Both the provider adapter and opt-in prepaint script use these declared
66
+ * paths to recover only those absent projection sources from the unchanged record.
67
+ */
68
+ var LEGACY_IMPORTED_THEME_TOKEN_PROJECTION_FALLBACKS = [
69
+ {
70
+ token: "--card",
71
+ path: [
72
+ "variant",
73
+ "colors",
74
+ "card"
75
+ ]
76
+ },
77
+ {
78
+ token: "--card-foreground",
79
+ path: [
80
+ "variant",
81
+ "colors",
82
+ "cardForeground"
83
+ ]
84
+ },
85
+ {
86
+ token: "--muted-foreground",
87
+ path: [
88
+ "variant",
89
+ "colors",
90
+ "mutedForeground"
91
+ ]
92
+ },
93
+ {
94
+ token: "--accent",
95
+ path: [
96
+ "variant",
97
+ "colors",
98
+ "accent"
99
+ ]
100
+ },
101
+ {
102
+ token: "--accent-foreground",
103
+ path: [
104
+ "variant",
105
+ "colors",
106
+ "accentForeground"
107
+ ]
108
+ },
109
+ {
110
+ token: "--border",
111
+ path: [
112
+ "variant",
113
+ "colors",
114
+ "border"
115
+ ]
116
+ },
117
+ {
118
+ token: "--primary",
119
+ path: [
120
+ "variant",
121
+ "colors",
122
+ "primary"
123
+ ]
124
+ },
125
+ {
126
+ token: "--primary-foreground",
127
+ path: [
128
+ "variant",
129
+ "colors",
130
+ "primaryForeground"
131
+ ]
132
+ },
133
+ {
134
+ token: "--ring",
135
+ path: [
136
+ "variant",
137
+ "colors",
138
+ "ring"
139
+ ]
140
+ }
141
+ ];
142
+ export { LEGACY_IMPORTED_THEME_TOKEN_PROJECTION, LEGACY_IMPORTED_THEME_TOKEN_PROJECTION_FALLBACKS };
@@ -1,19 +1,44 @@
1
1
  import "./appearance-preferences.js";
2
2
  import { customThemeVariantById, customThemeVariants, storedVariantRecord } from "./custom-theme-library.js";
3
3
  import { themeRegistry } from "./theme-registry.js";
4
- import { accentRolesForSelection, themeRecordById, themeRecords } from "@adea-ai/ui/lib/themes";
4
+ import { accentRolesForSelection, themeRecordById, themeRecords, tokensAsHex } from "@adea-ai/ui/lib/themes";
5
5
  import { getAccent } from "@adea-ai/ui/lib/accent-presets";
6
6
  import { colorToHex, normalizeAccentValue, parseColor } from "@adea-ai/ui/lib/accent-roles";
7
7
  import { defaultThemeRecord } from "@adea-ai/ui/lib/theme-projection";
8
8
  // src/appearance/theme-record-adapter.ts
9
9
  var adeaLight = defaultThemeRecord("light");
10
10
  var adeaDark = defaultThemeRecord("dark");
11
+ var MAX_ACCENT_PREVIEWS_PER_THEME = 16;
12
+ var accentRolesByTheme = /* @__PURE__ */ new WeakMap();
13
+ var importedRecordsByVariant = /* @__PURE__ */ new WeakMap();
11
14
  /** The published blue preset is the host's default custom accent. */
12
15
  var DEFAULT_CUSTOM_ACCENT = getAccent("blue")?.light ?? adeaLight.colors.accent;
13
16
  /** Imported themes, re-projected on every registry change. */
14
17
  function customThemeRecords() {
15
18
  return customThemeVariants().map(storedVariantRecord);
16
19
  }
20
+ function importedRecordForPreview(variant) {
21
+ const cached = importedRecordsByVariant.get(variant);
22
+ if (cached) return cached;
23
+ const record = storedVariantRecord(variant);
24
+ importedRecordsByVariant.set(variant, record);
25
+ return record;
26
+ }
27
+ function accentRolesForPreview(theme, key, resolve) {
28
+ if (!key) return resolve();
29
+ const cached = accentRolesByTheme.get(theme);
30
+ if (cached?.has(key)) return cached.get(key) ?? void 0;
31
+ const roles = resolve();
32
+ const byKey = cached ?? /* @__PURE__ */ new Map();
33
+ byKey.delete(key);
34
+ byKey.set(key, roles ?? null);
35
+ if (byKey.size > MAX_ACCENT_PREVIEWS_PER_THEME) {
36
+ const oldest = byKey.keys().next().value;
37
+ if (oldest !== void 0) byKey.delete(oldest);
38
+ }
39
+ accentRolesByTheme.set(theme, byKey);
40
+ return roles;
41
+ }
17
42
  /** The built-in catalogue led by the published pair; import lives separately. */
18
43
  var appearanceThemeRecords = Object.freeze([
19
44
  adeaLight,
@@ -26,12 +51,14 @@ function allThemeRecords() {
26
51
  }
27
52
  function withAccent(theme, accent, pair) {
28
53
  if (accent === "theme") return theme;
29
- const variant = themeRegistry().find((candidate) => candidate.id === theme.id);
30
- if (!variant) return theme;
31
- const roles = accentRolesForSelection(accent, theme.appearance, pair, {
32
- background: variant.colors.background,
33
- floor: 3,
34
- variantId: variant.id
54
+ const roles = accentRolesForPreview(theme, getAccent(accent) ? accent : void 0, () => {
55
+ const variant = themeRegistry().find((candidate) => candidate.id === theme.id);
56
+ if (!variant) return void 0;
57
+ return accentRolesForSelection(accent, theme.appearance, pair, {
58
+ background: variant.colors.background,
59
+ floor: 3,
60
+ variantId: variant.id
61
+ });
35
62
  });
36
63
  if (!roles) return theme;
37
64
  return {
@@ -51,11 +78,12 @@ function withAccent(theme, accent, pair) {
51
78
  function appearanceThemeForPreview(variant, accent, pair) {
52
79
  const catalogueRecord = themeRecordById(variant.id);
53
80
  const importedVariant = catalogueRecord ? void 0 : customThemeVariantById(variant.id);
54
- return withAccent(catalogueRecord ?? (importedVariant ? storedVariantRecord(importedVariant) : variant.appearance === "dark" ? adeaDark : adeaLight), accent, pair);
81
+ return withAccent(catalogueRecord ?? (importedVariant ? importedRecordForPreview(importedVariant) : variant.appearance === "dark" ? adeaDark : adeaLight), accent, pair);
55
82
  }
56
83
  /** Preserve the host's invalid-input behavior while feeding the pure editor. */
57
84
  function normalizeCustomAccent(value, background) {
58
- const normalized = normalizeAccentValue(value, background);
85
+ const canvas = tokensAsHex({ background }).background ?? background;
86
+ const normalized = normalizeAccentValue(value, canvas);
59
87
  if (normalized === void 0) return { error: `“${value}” is not a hex color such as ${DEFAULT_CUSTOM_ACCENT}.` };
60
88
  const parsed = parseColor(normalized);
61
89
  return { value: parsed ? colorToHex({
@@ -1 +1 @@
1
- {"version":"0.30.0","commit":"3c39a8178b5d816c9a5d52eef959c871a2820ce6"}
1
+ {"version":"0.31.0","commit":"970131b382d646d07de21bdd58359188bf171df4"}