@adea-ai/app-framework 0.36.1 → 0.37.1

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 (175) hide show
  1. package/README.md +2 -0
  2. package/dist/appearance/appearance-host.js +2 -1
  3. package/dist/appearance/custom-theme-import.js +3 -1
  4. package/dist/appearance/custom-theme-library.d.ts +6 -185
  5. package/dist/appearance/custom-theme-library.js +3 -621
  6. package/dist/appearance/theme-library-mutation.d.ts +42 -0
  7. package/dist/appearance/theme-library-mutation.js +172 -0
  8. package/dist/appearance/theme-library-schema.d.ts +108 -0
  9. package/dist/appearance/theme-library-schema.js +189 -0
  10. package/dist/appearance/theme-library-store.d.ts +61 -0
  11. package/dist/appearance/theme-library-store.js +268 -0
  12. package/dist/appearance/theme-record-adapter.js +3 -1
  13. package/dist/appearance/theme-registry.js +2 -1
  14. package/dist/appearance/window-surface.d.ts +19 -0
  15. package/dist/appearance/window-surface.js +68 -1
  16. package/dist/cli/update-helper-cli.js +1 -1
  17. package/dist/cli/windows-installer-build-cli.d.ts +2 -0
  18. package/dist/cli/windows-installer-build-cli.js +14 -0
  19. package/dist/desktop/desktop-client.d.ts +1 -1
  20. package/dist/framework-source.json +1 -1
  21. package/dist/installer/installed-payload.js +2 -2
  22. package/dist/installer/{installer-archive.js → installer-archive-members.js} +2 -2
  23. package/dist/installer/installer-extraction.js +2 -2
  24. package/dist/installer/installer-fetch-guard.d.ts +1 -1
  25. package/dist/installer/installer-identity.js +2 -2
  26. package/dist/installer/installer-observation.d.ts +1 -1
  27. package/dist/installer/installer-observation.js +2 -2
  28. package/dist/installer/installer-upgrade-command.d.ts +2 -2
  29. package/dist/installer/installer-upgrade-command.js +5 -5
  30. package/dist/installer/linux-process-group.js +1 -1
  31. package/dist/installer/upgrade-asset-download.d.ts +1 -1
  32. package/dist/installer/upgrade-asset-download.js +2 -2
  33. package/dist/native/installer-archive.d.ts +42 -0
  34. package/dist/native/installer-archive.js +172 -0
  35. package/dist/native/posix-tree-removal.d.ts +1 -1
  36. package/dist/native/window-surface-store.d.ts +16 -0
  37. package/dist/native/window-surface-store.js +69 -0
  38. package/dist/native/windows-extractor-build.d.ts +95 -0
  39. package/dist/native/windows-extractor-build.js +326 -0
  40. package/dist/release/feed-release-cut.d.ts +1 -1
  41. package/dist/release/feed-state.d.ts +2 -2
  42. package/dist/release/feed-state.js +3 -3
  43. package/dist/release/github-release-cut.js +1 -1
  44. package/dist/release/github-release-promotion.js +1 -1
  45. package/dist/release/github-release-publisher.js +1 -1
  46. package/dist/release/github-release-qualification.js +1 -1
  47. package/dist/release/local-release.d.ts +2 -2
  48. package/dist/release/local-release.js +3 -3
  49. package/dist/release/release-artifact.d.ts +1 -1
  50. package/dist/release/release-artifact.js +2 -2
  51. package/dist/release/release-assets-plan.js +1 -1
  52. package/dist/release/release-config.d.ts +1 -1
  53. package/dist/release/release-config.js +1 -1
  54. package/dist/release/release-descriptor-staging.js +3 -3
  55. package/dist/release/release-finalize.js +1 -1
  56. package/dist/release/release-promotion.js +1 -1
  57. package/dist/release/release-publication.d.ts +1 -1
  58. package/dist/release/release-publication.js +2 -2
  59. package/dist/release/release-publish-command.js +2 -2
  60. package/dist/update-helper.bundle.js +18 -18
  61. package/dist/updates/channel-update-manager.d.ts +3 -3
  62. package/dist/updates/channel-update-manager.js +2 -2
  63. package/dist/updates/desktop-updater.d.ts +10 -83
  64. package/dist/updates/desktop-updater.js +14 -217
  65. package/dist/updates/{packaged-release-config.js → feed/packaged-release-config.js} +5 -5
  66. package/dist/updates/{release-feed.js → feed/release-feed.js} +2 -2
  67. package/dist/updates/{release-location.js → feed/release-location.js} +2 -2
  68. package/dist/updates/{release-version.js → feed/release-version.js} +1 -1
  69. package/dist/updates/{signed-release.js → feed/signed-release.js} +2 -2
  70. package/dist/updates/{update-discovery.js → feed/update-discovery.js} +1 -1
  71. package/dist/updates/helper/launch-gate-recovery.d.ts +8 -0
  72. package/dist/updates/{update-resume.js → helper/launch-gate-recovery.js} +13 -423
  73. package/dist/updates/helper/resume-staging.d.ts +22 -0
  74. package/dist/updates/helper/resume-staging.js +180 -0
  75. package/dist/updates/{update-helper.d.ts → helper/update-helper.d.ts} +1 -1
  76. package/dist/updates/{update-helper.js → helper/update-helper.js} +9 -9
  77. package/dist/updates/{update-resume.d.ts → helper/update-resume.d.ts} +4 -10
  78. package/dist/updates/helper/update-resume.js +252 -0
  79. package/dist/updates/{update-shutdown.js → helper/update-shutdown.js} +2 -2
  80. package/dist/updates/{update-arm.d.ts → install/update-arm.d.ts} +2 -2
  81. package/dist/updates/{update-arm.js → install/update-arm.js} +9 -9
  82. package/dist/updates/{update-download-cleanup.d.ts → install/update-download-cleanup.d.ts} +1 -1
  83. package/dist/updates/{update-download-cleanup.js → install/update-download-cleanup.js} +3 -3
  84. package/dist/updates/{update-download.d.ts → install/update-download.d.ts} +2 -2
  85. package/dist/updates/{update-download.js → install/update-download.js} +3 -3
  86. package/dist/updates/{update-extraction.d.ts → install/update-extraction.d.ts} +2 -2
  87. package/dist/updates/{update-extraction.js → install/update-extraction.js} +6 -6
  88. package/dist/updates/{update-handoff-plan.d.ts → install/update-handoff-plan.d.ts} +2 -2
  89. package/dist/updates/{update-handoff-plan.js → install/update-handoff-plan.js} +5 -5
  90. package/dist/updates/{update-marker.js → install/update-marker.js} +2 -2
  91. package/dist/updates/{update-swap-stage.d.ts → install/update-swap-stage.d.ts} +2 -2
  92. package/dist/updates/{update-swap-stage.js → install/update-swap-stage.js} +7 -6
  93. package/dist/updates/{update-swap.d.ts → install/update-swap.d.ts} +1 -1
  94. package/dist/updates/{update-swap.js → install/update-swap.js} +5 -5
  95. package/dist/updates/install-target.d.ts +8 -0
  96. package/dist/updates/install-target.js +27 -0
  97. package/dist/updates/{launch-environment.js → launch/launch-environment.js} +1 -1
  98. package/dist/updates/{packaged-launch-admission.js → launch/packaged-launch-admission.js} +4 -4
  99. package/dist/updates/{packaged-update-startup.d.ts → launch/packaged-update-startup.d.ts} +3 -3
  100. package/dist/updates/{packaged-update-startup.js → launch/packaged-update-startup.js} +10 -7
  101. package/dist/updates/{update-launch-gate.d.ts → launch/update-launch-gate.d.ts} +1 -1
  102. package/dist/updates/{update-launch-gate.js → launch/update-launch-gate.js} +9 -9
  103. package/dist/updates/{update-launch.d.ts → launch/update-launch.d.ts} +1 -1
  104. package/dist/updates/{update-launch.js → launch/update-launch.js} +2 -2
  105. package/dist/updates/{linux-process-state.js → locks/linux-process-state.js} +1 -1
  106. package/dist/updates/{native-file-lock.js → locks/native-file-lock.js} +1 -1
  107. package/dist/updates/{stable-file.js → locks/stable-file.js} +2 -2
  108. package/dist/updates/{update-download-lock.js → locks/update-download-lock.js} +1 -1
  109. package/dist/updates/{update-generation-lease.js → locks/update-generation-lease.js} +3 -3
  110. package/dist/updates/{update-inherited-launch-lease.d.ts → locks/update-inherited-launch-lease.d.ts} +1 -1
  111. package/dist/updates/{update-inherited-launch-lease.js → locks/update-inherited-launch-lease.js} +2 -2
  112. package/dist/updates/{update-instance-lease.js → locks/update-instance-lease.js} +2 -2
  113. package/dist/updates/{update-lock.js → locks/update-lock.js} +2 -2
  114. package/dist/updates/{update-process-fence.js → locks/update-process-fence.js} +3 -3
  115. package/dist/updates/{update-process-liveness.js → locks/update-process-liveness.js} +2 -2
  116. package/dist/updates/retained-client-assets.d.ts +60 -0
  117. package/dist/updates/retained-client-assets.js +116 -0
  118. package/dist/updates/retention/retention-cleanup.d.ts +103 -0
  119. package/dist/updates/retention/retention-cleanup.js +439 -0
  120. package/dist/updates/retention/retention-prune-progress.d.ts +27 -0
  121. package/dist/updates/retention/retention-prune-progress.js +203 -0
  122. package/dist/updates/retention/retirement-inventory.d.ts +93 -0
  123. package/dist/updates/retention/retirement-inventory.js +373 -0
  124. package/dist/updates/retention/retirement-records.d.ts +75 -0
  125. package/dist/updates/retention/retirement-records.js +309 -0
  126. package/dist/updates/{update-retention-marker.d.ts → retention/update-retention-marker.d.ts} +1 -1
  127. package/dist/updates/{update-retention-marker.js → retention/update-retention-marker.js} +3 -3
  128. package/dist/updates/{update-retention-plan.d.ts → retention/update-retention-plan.d.ts} +1 -1
  129. package/dist/updates/{update-retention-plan.js → retention/update-retention-plan.js} +2 -2
  130. package/dist/updates/{update-retention-sync.d.ts → retention/update-retention-sync.d.ts} +1 -1
  131. package/dist/updates/{update-retention-sync.js → retention/update-retention-sync.js} +2 -2
  132. package/dist/updates/retention/update-retirement.d.ts +26 -0
  133. package/dist/updates/retention/update-retirement.js +205 -0
  134. package/dist/updates/update-adapter.js +1 -1
  135. package/dist/updates/update-channel-store.d.ts +1 -1
  136. package/dist/updates/update-channel-store.js +2 -2
  137. package/dist/updates/update-manager.d.ts +4 -4
  138. package/dist/updates/update-manager.js +5 -5
  139. package/dist/updates/update-services.d.ts +15 -0
  140. package/dist/updates/update-services.js +77 -0
  141. package/dist/updates/update-state-store.d.ts +2 -2
  142. package/dist/updates/update-state-store.js +2 -2
  143. package/dist/views/appearance-surface.js +3 -1
  144. package/package.json +42 -29
  145. package/src/appearance/custom-theme-library.ts +42 -956
  146. package/src/appearance/theme-library-mutation.ts +288 -0
  147. package/src/appearance/theme-library-schema.ts +347 -0
  148. package/src/appearance/theme-library-store.ts +379 -0
  149. package/src/appearance/window-surface.ts +91 -5
  150. package/src/updates/update-adapter.ts +1 -1
  151. package/templates/application/src/bun/index.ts +15 -0
  152. package/templates/application/src/web/main.tsx +13 -1
  153. package/dist/updates/update-retirement.d.ts +0 -205
  154. package/dist/updates/update-retirement.js +0 -1485
  155. /package/dist/installer/{installer-archive.d.ts → installer-archive-members.d.ts} +0 -0
  156. /package/dist/updates/{packaged-release-config.d.ts → feed/packaged-release-config.d.ts} +0 -0
  157. /package/dist/updates/{release-feed.d.ts → feed/release-feed.d.ts} +0 -0
  158. /package/dist/updates/{release-location.d.ts → feed/release-location.d.ts} +0 -0
  159. /package/dist/updates/{release-version.d.ts → feed/release-version.d.ts} +0 -0
  160. /package/dist/updates/{signed-release.d.ts → feed/signed-release.d.ts} +0 -0
  161. /package/dist/updates/{update-discovery.d.ts → feed/update-discovery.d.ts} +0 -0
  162. /package/dist/updates/{update-shutdown.d.ts → helper/update-shutdown.d.ts} +0 -0
  163. /package/dist/updates/{update-marker.d.ts → install/update-marker.d.ts} +0 -0
  164. /package/dist/updates/{launch-environment.d.ts → launch/launch-environment.d.ts} +0 -0
  165. /package/dist/updates/{packaged-launch-admission.d.ts → launch/packaged-launch-admission.d.ts} +0 -0
  166. /package/dist/updates/{linux-process-state.d.ts → locks/linux-process-state.d.ts} +0 -0
  167. /package/dist/updates/{native-file-lock.d.ts → locks/native-file-lock.d.ts} +0 -0
  168. /package/dist/updates/{stable-file.d.ts → locks/stable-file.d.ts} +0 -0
  169. /package/dist/updates/{update-download-lock.d.ts → locks/update-download-lock.d.ts} +0 -0
  170. /package/dist/updates/{update-generation-lease.d.ts → locks/update-generation-lease.d.ts} +0 -0
  171. /package/dist/updates/{update-instance-lease.d.ts → locks/update-instance-lease.d.ts} +0 -0
  172. /package/dist/updates/{update-lock.d.ts → locks/update-lock.d.ts} +0 -0
  173. /package/dist/updates/{update-process-fence.d.ts → locks/update-process-fence.d.ts} +0 -0
  174. /package/dist/updates/{update-process-liveness.d.ts → locks/update-process-liveness.d.ts} +0 -0
  175. /package/src/updates/{release-version.ts → feed/release-version.ts} +0 -0
@@ -0,0 +1,172 @@
1
+ import { CUSTOM_THEME_LIBRARY_STORAGE_KEY, library, namespaceCustomThemes, notifyCustomThemes, parseLibrary, preserveLibrary, replaceThemes, setCustomThemes } from "./theme-library-store.js";
2
+ // src/appearance/theme-library-mutation.ts
3
+ /** Origin-wide lock name shared by all cooperating framework builds. */
4
+ var CUSTOM_THEME_LIBRARY_LOCK_NAME = "adea:appearance.library:mutation:v1";
5
+ var CUSTOM_THEME_LIBRARY_LOCK_DB = "adea:appearance-library-coordination:v1";
6
+ var CUSTOM_THEME_LIBRARY_LOCK_STORE = "locks";
7
+ var CUSTOM_THEME_ATOMIC_STORAGE_UNAVAILABLE = "This app cannot safely save theme changes in this environment. Your library was not changed.";
8
+ var CUSTOM_THEME_LIBRARY_MUTATION_FAILED = "The theme could not be saved. Check your storage and try again.";
9
+ function withIndexedDbMutationLock(name, operation) {
10
+ const factory = globalThis.indexedDB;
11
+ if (!factory) return Promise.reject(/* @__PURE__ */ new Error("IndexedDB is unavailable"));
12
+ return new Promise((resolve, reject) => {
13
+ const open = factory.open(CUSTOM_THEME_LIBRARY_LOCK_DB, 1);
14
+ open.addEventListener("upgradeneeded", () => {
15
+ if (!open.result.objectStoreNames.contains(CUSTOM_THEME_LIBRARY_LOCK_STORE)) open.result.createObjectStore(CUSTOM_THEME_LIBRARY_LOCK_STORE);
16
+ });
17
+ open.addEventListener("error", () => reject(open.error ?? /* @__PURE__ */ new Error("Could not open theme coordination database")));
18
+ open.addEventListener("success", () => {
19
+ const database = open.result;
20
+ database.addEventListener("versionchange", () => database.close());
21
+ let transaction;
22
+ try {
23
+ transaction = database.transaction(CUSTOM_THEME_LIBRARY_LOCK_STORE, "readwrite");
24
+ } catch (error) {
25
+ database.close();
26
+ reject(error);
27
+ return;
28
+ }
29
+ let result;
30
+ let ran = false;
31
+ let operationError;
32
+ const close = () => database.close();
33
+ transaction.addEventListener("complete", () => {
34
+ close();
35
+ if (operationError !== void 0) reject(operationError);
36
+ else if (ran) resolve(result);
37
+ else reject(/* @__PURE__ */ new Error("Theme library lock transaction did not run"));
38
+ });
39
+ transaction.addEventListener("abort", () => {
40
+ close();
41
+ if (ran) {
42
+ resolve(result);
43
+ return;
44
+ }
45
+ reject(operationError ?? transaction.error ?? /* @__PURE__ */ new Error("Theme library lock transaction aborted"));
46
+ });
47
+ try {
48
+ transaction.objectStore(CUSTOM_THEME_LIBRARY_LOCK_STORE).get(name).addEventListener("success", () => {
49
+ try {
50
+ result = operation();
51
+ ran = true;
52
+ } catch (error) {
53
+ operationError = error;
54
+ transaction.abort();
55
+ }
56
+ });
57
+ } catch (error) {
58
+ operationError = error;
59
+ transaction.abort();
60
+ }
61
+ });
62
+ });
63
+ }
64
+ function browserThemeLibraryAtomicLock() {
65
+ if (!globalThis.indexedDB) return void 0;
66
+ const locks = globalThis.navigator?.locks;
67
+ return { withExclusiveLock: (name, operation) => locks && typeof locks.request === "function" ? locks.request(name, { mode: "exclusive" }, () => withIndexedDbMutationLock(name, operation)) : withIndexedDbMutationLock(name, operation) };
68
+ }
69
+ function mutationFailure(reason, error) {
70
+ return {
71
+ ok: false,
72
+ reason,
73
+ error
74
+ };
75
+ }
76
+ /**
77
+ * Coordinate a storage-backed library read/modify/write across cooperating contexts.
78
+ * The callback reads the current v1 record while holding an origin-wide IndexedDB
79
+ * read/write transaction (and a Web Lock where available), then writes and verifies
80
+ * the v1 record before updating this tab's in-memory registry. Older builds and
81
+ * direct `setCustomThemes` storage writes do not acquire these locks and can still
82
+ * race; this API does not claim cross-version atomicity. If IndexedDB is unavailable,
83
+ * durable mutations fail closed.
84
+ */
85
+ async function mutateCustomThemeLibrary(storage, update, options = {}) {
86
+ if (!storage) try {
87
+ const mutation = update(library().themes);
88
+ if (mutation.commit === false) return {
89
+ ok: true,
90
+ committed: false,
91
+ value: mutation.value
92
+ };
93
+ const safe = namespaceCustomThemes(mutation.themes);
94
+ if (!setCustomThemes(safe, void 0)) return mutationFailure("storage_failed", CUSTOM_THEME_LIBRARY_MUTATION_FAILED);
95
+ return {
96
+ ok: true,
97
+ committed: true,
98
+ value: mutation.value
99
+ };
100
+ } catch {
101
+ return mutationFailure("storage_failed", CUSTOM_THEME_LIBRARY_MUTATION_FAILED);
102
+ }
103
+ const lock = options.lock === void 0 ? browserThemeLibraryAtomicLock() : options.lock;
104
+ if (!lock) return mutationFailure("atomic_unavailable", CUSTOM_THEME_ATOMIC_STORAGE_UNAVAILABLE);
105
+ let enteredLock = false;
106
+ try {
107
+ return await lock.withExclusiveLock(CUSTOM_THEME_LIBRARY_LOCK_NAME, () => {
108
+ enteredLock = true;
109
+ const state = library();
110
+ state.atomicMutationDepth = (state.atomicMutationDepth ?? 0) + 1;
111
+ try {
112
+ let raw;
113
+ let themes;
114
+ try {
115
+ raw = storage.getItem(CUSTOM_THEME_LIBRARY_STORAGE_KEY);
116
+ const parsed = raw ? parseLibrary(raw) : { themes: [] };
117
+ themes = parsed.themes;
118
+ if (raw && parsed.reason && !preserveLibrary(storage, raw, parsed.reason)) return mutationFailure("recovery_unavailable", "The stored theme library could not be preserved, so this change was not saved.");
119
+ if (storage.getItem("appearance.library") !== raw) return mutationFailure("changed_during_mutation", "The theme library changed while it was being read. Try again.");
120
+ } catch {
121
+ return mutationFailure("storage_failed", CUSTOM_THEME_LIBRARY_MUTATION_FAILED);
122
+ }
123
+ let mutation;
124
+ try {
125
+ mutation = update(themes);
126
+ if (storage.getItem("appearance.library") !== raw) return mutationFailure("changed_during_mutation", "The theme library changed while this change was being prepared. Try again.");
127
+ } catch {
128
+ return mutationFailure("storage_failed", CUSTOM_THEME_LIBRARY_MUTATION_FAILED);
129
+ }
130
+ if (mutation.commit === false) return {
131
+ ok: true,
132
+ committed: false,
133
+ value: mutation.value
134
+ };
135
+ const safe = namespaceCustomThemes(mutation.themes);
136
+ const serialized = JSON.stringify({
137
+ version: 1,
138
+ themes: safe
139
+ });
140
+ try {
141
+ storage.setItem(CUSTOM_THEME_LIBRARY_STORAGE_KEY, serialized);
142
+ if (storage.getItem("appearance.library") !== serialized) return mutationFailure("changed_during_mutation", "The theme library changed while it was being saved. Try again.");
143
+ } catch {
144
+ return mutationFailure("storage_failed", CUSTOM_THEME_LIBRARY_MUTATION_FAILED);
145
+ }
146
+ replaceThemes(safe);
147
+ notifyCustomThemes();
148
+ return {
149
+ ok: true,
150
+ committed: true,
151
+ value: mutation.value
152
+ };
153
+ } finally {
154
+ state.atomicMutationDepth = Math.max(0, (state.atomicMutationDepth ?? 1) - 1);
155
+ }
156
+ });
157
+ } catch {
158
+ return mutationFailure(enteredLock ? "storage_failed" : "atomic_unavailable", enteredLock ? CUSTOM_THEME_LIBRARY_MUTATION_FAILED : CUSTOM_THEME_ATOMIC_STORAGE_UNAVAILABLE);
159
+ }
160
+ }
161
+ /** Remove from the latest persisted snapshot, not a possibly stale UI snapshot. */
162
+ async function removeCustomThemeAtomically(id, storage, options = {}) {
163
+ return mutateCustomThemeLibrary(storage, (themes) => {
164
+ const remaining = themes.filter((theme) => theme.id !== id);
165
+ return {
166
+ themes: remaining,
167
+ value: true,
168
+ commit: remaining.length !== themes.length
169
+ };
170
+ }, options);
171
+ }
172
+ export { CUSTOM_THEME_ATOMIC_STORAGE_UNAVAILABLE, CUSTOM_THEME_LIBRARY_LOCK_NAME, CUSTOM_THEME_LIBRARY_MUTATION_FAILED, mutateCustomThemeLibrary, removeCustomThemeAtomically };
@@ -0,0 +1,108 @@
1
+ import type { AdeaThemeRecord } from '@adea-ai/ui/lib/theme-records';
2
+ import type { ThemeVariant as UiThemeVariant } from '@adea-ai/ui/lib/themes';
3
+ export type StoredThemeAppearance = 'light' | 'dark';
4
+ export type StoredThemeTerminal = Readonly<{
5
+ background: string;
6
+ foreground: string;
7
+ cursor: string;
8
+ selection: string;
9
+ /** The 16 xterm ANSI slots, in protocol order. */
10
+ ansi: readonly string[];
11
+ }>;
12
+ export type StoredThemeEditorRoles = Readonly<{
13
+ keyword: string;
14
+ string: string;
15
+ number: string;
16
+ comment: string;
17
+ function: string;
18
+ variable: string;
19
+ type: string;
20
+ tag: string;
21
+ attribute: string;
22
+ operator: string;
23
+ heading: string;
24
+ link: string;
25
+ diffAdd: string;
26
+ diffDelete: string;
27
+ diffHunk: string;
28
+ searchMatch: string;
29
+ }>;
30
+ export type StoredThemeChartRoles = Readonly<{
31
+ chart1: string;
32
+ chart2: string;
33
+ chart3: string;
34
+ chart4: string;
35
+ chart5: string;
36
+ chart6: string;
37
+ }>;
38
+ export type StoredThemeColors = Readonly<{
39
+ background: string;
40
+ foreground: string;
41
+ card: string;
42
+ cardForeground: string;
43
+ popover: string;
44
+ popoverForeground: string;
45
+ primary: string;
46
+ primaryForeground: string;
47
+ secondary: string;
48
+ secondaryForeground: string;
49
+ muted: string;
50
+ mutedForeground: string;
51
+ accent: string;
52
+ accentForeground: string;
53
+ destructive: string;
54
+ destructiveAction: string;
55
+ destructiveActionForeground: string;
56
+ success: string;
57
+ border: string;
58
+ input: string;
59
+ ring: string;
60
+ }>;
61
+ /** The variant shape the library has always stored for an imported theme. */
62
+ export type StoredThemeVariant = Readonly<{
63
+ id: string;
64
+ familyId: string;
65
+ familyName: string;
66
+ name: string;
67
+ appearance: StoredThemeAppearance;
68
+ colors: StoredThemeColors;
69
+ terminal: StoredThemeTerminal;
70
+ editor: StoredThemeEditorRoles;
71
+ charts: StoredThemeChartRoles;
72
+ }>;
73
+ export type CustomThemeStored = Readonly<{
74
+ /** Stable id, namespaced so it can never collide with a catalogue id. */
75
+ id: string;
76
+ name: string;
77
+ appearance: StoredThemeAppearance;
78
+ importedAt: string;
79
+ variant: StoredThemeVariant;
80
+ /** The verbatim imported map; projection may supply absent sources from `variant`. */
81
+ flatTokens: Readonly<Record<string, string>>;
82
+ /** Non-fatal adjustments made while normalizing the file, for the UI. */
83
+ notes: readonly string[];
84
+ }>;
85
+ export type ValidationIssue = Readonly<{
86
+ variantId: string;
87
+ severity: 'error' | 'warning';
88
+ message: string;
89
+ }>;
90
+ export declare function validateThemeRegistry(registry: readonly StoredThemeVariant[]): ValidationIssue[];
91
+ /** The custom properties an imported variant owns, as a flat map. */
92
+ export declare function flatVariantTokens(variant: StoredThemeVariant): Record<string, string>;
93
+ /**
94
+ * The catalogue-shaped record for an imported variant. The editor reads only its
95
+ * surface, text, border and accent roles; warning and info are the ANSI yellow and
96
+ * blue because the stored variant has no such roles.
97
+ */
98
+ export declare function storedVariantRecord(variant: StoredThemeVariant): AdeaThemeRecord;
99
+ /**
100
+ * The shared-provider variant for a stored theme: derived roles from the
101
+ * reconstructed record, missing sidebar projection sources from the stored variant,
102
+ * then every stored flat token verbatim.
103
+ *
104
+ * A record the shared projection cannot map falls back to the default theme of the
105
+ * same appearance under the stored identity, so an import that the projection
106
+ * rejects still paints from its tokens instead of vanishing.
107
+ */
108
+ export declare function toUiVariant(stored: CustomThemeStored): UiThemeVariant;
@@ -0,0 +1,189 @@
1
+ import { LEGACY_IMPORTED_THEME_TOKEN_PROJECTION_FALLBACKS } from "./legacy-imported-theme-token-projection.js";
2
+ import { contrastRatio } from "@adea-ai/ui/lib/accent-roles";
3
+ import { defaultVariantFor } from "@adea-ai/ui/lib/theme-defaults";
4
+ import { variantFromRecord } from "@adea-ai/ui/lib/theme-records";
5
+ // src/appearance/theme-library-schema.ts
6
+ function validateThemeRegistry(registry) {
7
+ const issues = [];
8
+ const seen = /* @__PURE__ */ new Set();
9
+ for (const variant of registry) {
10
+ if (variant.id.trim().length === 0 || seen.has(variant.id)) issues.push({
11
+ variantId: variant.id,
12
+ severity: "error",
13
+ message: "variant id must be unique"
14
+ });
15
+ seen.add(variant.id);
16
+ const check = (role, foreground, background, minimum) => {
17
+ const actual = contrastRatio(foreground, background);
18
+ if (actual < minimum) issues.push({
19
+ variantId: variant.id,
20
+ severity: "error",
21
+ message: `${role} contrast is ${actual.toFixed(2)}:1; expected ${minimum.toFixed(1)}:1`
22
+ });
23
+ };
24
+ check("text", variant.colors.foreground, variant.colors.background, 4.5);
25
+ check("muted text", variant.colors.mutedForeground, variant.colors.background, 4.5);
26
+ check("primary", variant.colors.primary, variant.colors.background, 3);
27
+ check("on-primary", variant.colors.primaryForeground, variant.colors.primary, 4.5);
28
+ check("terminal foreground", variant.terminal.foreground, variant.terminal.background, 4.5);
29
+ for (const [index, color] of variant.terminal.ansi.entries()) {
30
+ if (index % 8 === 0) continue;
31
+ if (contrastRatio(color, variant.terminal.background) < 3) issues.push({
32
+ variantId: variant.id,
33
+ severity: "warning",
34
+ message: `terminal ANSI slot ${index} is below 3:1`
35
+ });
36
+ }
37
+ check("editor comment", variant.editor.comment, variant.colors.background, 4.5);
38
+ check("diff delete", variant.editor.diffDelete, variant.colors.background, 3);
39
+ check("diff add", variant.editor.diffAdd, variant.colors.background, 3);
40
+ }
41
+ return issues;
42
+ }
43
+ var ANSI_NAMES = [
44
+ "black",
45
+ "red",
46
+ "green",
47
+ "yellow",
48
+ "blue",
49
+ "magenta",
50
+ "cyan",
51
+ "white"
52
+ ];
53
+ function kebabCase(value) {
54
+ return value.replaceAll(/[A-Z]/g, (character) => `-${character.toLocaleLowerCase()}`);
55
+ }
56
+ function terminalTokens(palette) {
57
+ const tokens = {
58
+ "--terminal-background": palette.background,
59
+ "--terminal-foreground": palette.foreground,
60
+ "--terminal-cursor": palette.cursor,
61
+ "--terminal-selection": palette.selection
62
+ };
63
+ for (const [index, color] of palette.ansi.entries()) {
64
+ const name = ANSI_NAMES[index % 8];
65
+ tokens[index < 8 ? `--terminal-ansi-${name}` : `--terminal-ansi-bright-${name}`] = color;
66
+ }
67
+ return tokens;
68
+ }
69
+ /** The custom properties an imported variant owns, as a flat map. */
70
+ function flatVariantTokens(variant) {
71
+ const tokens = {};
72
+ for (const [role, value] of Object.entries(variant.colors)) tokens[`--${kebabCase(role)}`] = value;
73
+ Object.assign(tokens, terminalTokens(variant.terminal));
74
+ for (const [role, value] of Object.entries(variant.editor)) tokens[`--editor-${kebabCase(role)}`] = value;
75
+ for (const [index, value] of Object.values(variant.charts).entries()) tokens[`--chart-${index + 1}`] = value;
76
+ return tokens;
77
+ }
78
+ var IMPORTED_PROVENANCE = {
79
+ project: "Adea themes catalogue",
80
+ url: "https://github.com/adea-ai/themes",
81
+ license: "Apache-2.0"
82
+ };
83
+ function ansiRamp(variant) {
84
+ const [black, red, green, yellow, blue, magenta, cyan, white, brightBlack, brightRed, brightGreen, brightYellow, brightBlue, brightMagenta, brightCyan, brightWhite] = variant.terminal.ansi;
85
+ return {
86
+ black,
87
+ red,
88
+ green,
89
+ yellow,
90
+ blue,
91
+ magenta,
92
+ cyan,
93
+ white,
94
+ brightBlack,
95
+ brightRed,
96
+ brightGreen,
97
+ brightYellow,
98
+ brightBlue,
99
+ brightMagenta,
100
+ brightCyan,
101
+ brightWhite
102
+ };
103
+ }
104
+ /**
105
+ * The catalogue-shaped record for an imported variant. The editor reads only its
106
+ * surface, text, border and accent roles; warning and info are the ANSI yellow and
107
+ * blue because the stored variant has no such roles.
108
+ */
109
+ function storedVariantRecord(variant) {
110
+ const colors = variant.colors;
111
+ const ansi = ansiRamp(variant);
112
+ return {
113
+ id: variant.id,
114
+ name: variant.name,
115
+ appearance: variant.appearance,
116
+ colors: {
117
+ background: colors.background,
118
+ foreground: colors.foreground,
119
+ surface: colors.card,
120
+ surfaceElevated: colors.popover,
121
+ surfaceHover: colors.accent,
122
+ surfaceActive: colors.border,
123
+ border: colors.border,
124
+ borderMuted: colors.border,
125
+ text: colors.foreground,
126
+ textMuted: colors.mutedForeground,
127
+ textSubtle: colors.mutedForeground,
128
+ accent: colors.primary,
129
+ accentForeground: colors.primaryForeground,
130
+ success: colors.success,
131
+ warning: ansi.yellow,
132
+ error: colors.destructive,
133
+ info: ansi.blue
134
+ },
135
+ ansi,
136
+ cursor: variant.terminal.cursor,
137
+ selection: variant.terminal.selection,
138
+ family: variant.familyId,
139
+ familyLabel: variant.familyName,
140
+ label: variant.name,
141
+ description: `${variant.name}, imported into your library.`,
142
+ provenance: IMPORTED_PROVENANCE,
143
+ tags: ["imported", variant.appearance]
144
+ };
145
+ }
146
+ /**
147
+ * The shared-provider variant for a stored theme: derived roles from the
148
+ * reconstructed record, missing sidebar projection sources from the stored variant,
149
+ * then every stored flat token verbatim.
150
+ *
151
+ * A record the shared projection cannot map falls back to the default theme of the
152
+ * same appearance under the stored identity, so an import that the projection
153
+ * rejects still paints from its tokens instead of vanishing.
154
+ */
155
+ function toUiVariant(stored) {
156
+ const { variant } = stored;
157
+ let base;
158
+ try {
159
+ base = variantFromRecord(storedVariantRecord(variant));
160
+ } catch {
161
+ base = {
162
+ ...defaultVariantFor(variant.appearance),
163
+ id: variant.id,
164
+ family: variant.familyId,
165
+ familyLabel: variant.familyName,
166
+ label: variant.name,
167
+ description: `${variant.name}, imported into your library.`,
168
+ provenance: {
169
+ source: IMPORTED_PROVENANCE.project,
170
+ url: IMPORTED_PROVENANCE.url,
171
+ license: IMPORTED_PROVENANCE.license
172
+ }
173
+ };
174
+ }
175
+ const projectionSources = {};
176
+ for (const fallback of LEGACY_IMPORTED_THEME_TOKEN_PROJECTION_FALLBACKS) {
177
+ if (Object.hasOwn(stored.flatTokens, fallback.token)) continue;
178
+ const value = fallback.path.reduce((node, key) => node && typeof node === "object" && Object.hasOwn(node, key) ? node[key] : void 0, stored);
179
+ if (typeof value === "string") projectionSources[fallback.token] = value;
180
+ }
181
+ return {
182
+ ...base,
183
+ tokens: {
184
+ ...projectionSources,
185
+ ...stored.flatTokens
186
+ }
187
+ };
188
+ }
189
+ export { flatVariantTokens, storedVariantRecord, toUiVariant, validateThemeRegistry };
@@ -0,0 +1,61 @@
1
+ import type { ThemeVariant as UiThemeVariant } from '@adea-ai/ui/lib/themes';
2
+ import { type CustomThemeStored, type StoredThemeVariant } from './theme-library-schema';
3
+ export type AppearanceStorage = Pick<Storage, 'getItem' | 'setItem'>;
4
+ export declare const CUSTOM_THEME_LIBRARY_STORAGE_KEY = "appearance.library";
5
+ /**
6
+ * Where an unreadable library is quarantined. It is its own key: the library and
7
+ * the appearance preference used to share `appearance.recovery`, so one could
8
+ * overwrite the other's capture.
9
+ */
10
+ export declare const CUSTOM_THEME_LIBRARY_RECOVERY_KEY = "appearance.library.recovery";
11
+ export declare const CUSTOM_THEME_LIBRARY_VERSION = 1;
12
+ type LibraryState = {
13
+ themes: readonly CustomThemeStored[];
14
+ /** Derived from `themes`; rebuilt on first read after each change. */
15
+ uiVariants?: readonly UiThemeVariant[];
16
+ listeners: Set<() => void>;
17
+ /** Blocks legacy synchronous writes while a coordinated mutation is committing. */
18
+ atomicMutationDepth?: number;
19
+ /** One storage observer per shared host, even if source and package graphs load twice. */
20
+ storageEventTarget?: Window;
21
+ storageEventListener?: (event: StorageEvent) => void;
22
+ };
23
+ export declare function library(): LibraryState;
24
+ export declare function replaceThemes(themes: readonly CustomThemeStored[]): void;
25
+ /** The imported themes' stored variants, in import order. */
26
+ export declare function customThemeVariants(): readonly StoredThemeVariant[];
27
+ /** Find one stored variant without projecting the rest of the imported library. */
28
+ export declare function customThemeVariantById(id: string): StoredThemeVariant | undefined;
29
+ /** The imported themes as shared-provider variants: what the provider's `themes` takes. */
30
+ export declare function customUiVariants(): readonly UiThemeVariant[];
31
+ export declare function subscribeCustomThemes(listener: () => void): () => void;
32
+ export declare function notifyCustomThemes(): void;
33
+ /**
34
+ * Replace the in-memory imported-theme set and tell subscribers. Durable mutations
35
+ * must use `mutateCustomThemeLibrary`; this deprecated synchronous API fails closed
36
+ * when a storage adapter is supplied because it cannot acquire the shared lock.
37
+ *
38
+ * @deprecated Use `mutateCustomThemeLibrary` for persisted read/modify/write operations.
39
+ */
40
+ export declare function setCustomThemes(themes: readonly CustomThemeStored[], storage: AppearanceStorage | undefined): boolean;
41
+ export declare function namespaceCustomThemes(themes: readonly CustomThemeStored[]): CustomThemeStored[];
42
+ export declare function parseLibrary(raw: string): {
43
+ themes: CustomThemeStored[];
44
+ reason?: 'corrupt_json' | 'unsupported_record';
45
+ };
46
+ export declare function preserveLibrary(storage: AppearanceStorage, raw: string, reason: 'corrupt_json' | 'unsupported_record'): boolean;
47
+ /**
48
+ * Read the stored library. A malformed document starts an empty library and
49
+ * quarantines the raw bytes into the library's own recovery key, mirroring the
50
+ * appearance-preference recovery contract; individual invalid records are dropped,
51
+ * not fatal.
52
+ */
53
+ export declare function readCustomThemeLibrary(storage: AppearanceStorage | undefined): readonly CustomThemeStored[];
54
+ /**
55
+ * Synchronous legacy removal for the in-memory library. Passing storage fails closed;
56
+ * use `removeCustomThemeAtomically` for persisted removals.
57
+ *
58
+ * @deprecated Use `removeCustomThemeAtomically` for persisted removals.
59
+ */
60
+ export declare function removeCustomTheme(id: string, storage: AppearanceStorage | undefined): boolean;
61
+ export {};