@adea-ai/app-framework 0.0.0-stage → 0.24.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 (358) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +30 -0
  3. package/README.md +1009 -2
  4. package/dist/app/application.d.ts +47 -0
  5. package/dist/app/application.js +115 -0
  6. package/dist/app/create-application.d.ts +13 -0
  7. package/dist/app/create-application.js +178 -0
  8. package/dist/app/service-registry.d.ts +44 -0
  9. package/dist/app/service-registry.js +116 -0
  10. package/dist/appearance/appearance-host.d.ts +62 -0
  11. package/dist/appearance/appearance-host.js +115 -0
  12. package/dist/appearance/appearance-preferences.d.ts +106 -0
  13. package/dist/appearance/appearance-preferences.js +175 -0
  14. package/dist/appearance/composition.d.ts +11 -0
  15. package/dist/appearance/composition.js +16 -0
  16. package/dist/appearance/custom-theme-import.d.ts +14 -0
  17. package/dist/appearance/custom-theme-import.js +315 -0
  18. package/dist/appearance/custom-theme-library.d.ts +146 -0
  19. package/dist/appearance/custom-theme-library.js +378 -0
  20. package/dist/appearance/editor.d.ts +20 -0
  21. package/dist/appearance/editor.js +47 -0
  22. package/dist/appearance/theme-file-importer.d.ts +23 -0
  23. package/dist/appearance/theme-file-importer.js +66 -0
  24. package/dist/appearance/theme-record-adapter.d.ts +26 -0
  25. package/dist/appearance/theme-record-adapter.js +64 -0
  26. package/dist/appearance/theme-registry.d.ts +10 -0
  27. package/dist/appearance/theme-registry.js +16 -0
  28. package/dist/appearance/window-surface.d.ts +5 -0
  29. package/dist/appearance/window-surface.js +9 -0
  30. package/dist/ci/toolchain-identity.d.ts +39 -0
  31. package/dist/ci/toolchain-identity.js +196 -0
  32. package/dist/cli/cef-helper-cli.d.ts +2 -0
  33. package/dist/cli/cef-helper-cli.js +18 -0
  34. package/dist/cli/cli-runner.d.ts +8 -0
  35. package/dist/cli/cli-runner.js +23 -0
  36. package/dist/cli/create-application-cli.d.ts +2 -0
  37. package/dist/cli/create-application-cli.js +40 -0
  38. package/dist/cli/electrobun-shortcut-patch-cli.d.ts +2 -0
  39. package/dist/cli/electrobun-shortcut-patch-cli.js +17 -0
  40. package/dist/cli/framework-update-cli.d.ts +2 -0
  41. package/dist/cli/framework-update-cli.js +40 -0
  42. package/dist/cli/release-assets-plan-cli.d.ts +2 -0
  43. package/dist/cli/release-assets-plan-cli.js +14 -0
  44. package/dist/cli/release-cut-cli.d.ts +2 -0
  45. package/dist/cli/release-cut-cli.js +27 -0
  46. package/dist/cli/release-descriptor-staging-cli.d.ts +2 -0
  47. package/dist/cli/release-descriptor-staging-cli.js +45 -0
  48. package/dist/cli/release-finalize-cli.d.ts +1 -0
  49. package/dist/cli/release-finalize-cli.js +30 -0
  50. package/dist/cli/release-promote-cli.d.ts +2 -0
  51. package/dist/cli/release-promote-cli.js +32 -0
  52. package/dist/cli/release-publish-cli.d.ts +2 -0
  53. package/dist/cli/release-publish-cli.js +48 -0
  54. package/dist/cli/release-sign-cli.d.ts +2 -0
  55. package/dist/cli/release-sign-cli.js +13 -0
  56. package/dist/cli/release-step-cli.d.ts +2 -0
  57. package/dist/cli/release-step-cli.js +44 -0
  58. package/dist/cli/toolchain-identity-cli.d.ts +2 -0
  59. package/dist/cli/toolchain-identity-cli.js +10 -0
  60. package/dist/cli/update-helper-cli.d.ts +1 -0
  61. package/dist/cli/update-helper-cli.js +10 -0
  62. package/dist/cli/windows-runtime-patch-cli.d.ts +2 -0
  63. package/dist/cli/windows-runtime-patch-cli.js +17 -0
  64. package/dist/desktop/application-command-client.d.ts +15 -0
  65. package/dist/desktop/application-command-client.js +21 -0
  66. package/dist/desktop/channel-handshake.d.ts +32 -0
  67. package/dist/desktop/channel-handshake.js +111 -0
  68. package/dist/desktop/channel-proof.d.ts +43 -0
  69. package/dist/desktop/channel-proof.js +85 -0
  70. package/dist/desktop/client-assets.d.ts +7 -0
  71. package/dist/desktop/client-assets.js +59 -0
  72. package/dist/desktop/desktop-client.d.ts +23 -0
  73. package/dist/desktop/desktop-client.js +231 -0
  74. package/dist/desktop/desktop-gateway.d.ts +18 -0
  75. package/dist/desktop/desktop-gateway.js +146 -0
  76. package/dist/desktop/desktop-host.d.ts +48 -0
  77. package/dist/desktop/desktop-host.js +208 -0
  78. package/dist/desktop/desktop-stream.d.ts +36 -0
  79. package/dist/desktop/desktop-stream.js +231 -0
  80. package/dist/desktop/loopback-policy.d.ts +19 -0
  81. package/dist/desktop/loopback-policy.js +23 -0
  82. package/dist/desktop/open-url-channel.d.ts +15 -0
  83. package/dist/desktop/open-url-channel.js +55 -0
  84. package/dist/desktop/string-policy.d.ts +2 -0
  85. package/dist/desktop/string-policy.js +11 -0
  86. package/dist/framework-source.json +1 -0
  87. package/dist/installer/archive-entry.d.ts +6 -0
  88. package/dist/installer/archive-entry.js +14 -0
  89. package/dist/installer/command-artifact.d.ts +47 -0
  90. package/dist/installer/command-artifact.js +261 -0
  91. package/dist/installer/command-qualification-command.d.ts +12 -0
  92. package/dist/installer/command-qualification-command.js +71 -0
  93. package/dist/installer/hosted-runner.d.ts +4 -0
  94. package/dist/installer/hosted-runner.js +10 -0
  95. package/dist/installer/installed-payload.d.ts +29 -0
  96. package/dist/installer/installed-payload.js +312 -0
  97. package/dist/installer/installer-ci-bootstrap.d.ts +26 -0
  98. package/dist/installer/installer-ci-bootstrap.js +160 -0
  99. package/dist/installer/installer-ci-preflight.d.ts +1 -0
  100. package/dist/installer/installer-ci-preflight.js +49 -0
  101. package/dist/installer/installer-ci-worker.d.ts +1 -0
  102. package/dist/installer/installer-ci-worker.js +105 -0
  103. package/dist/installer/installer-extraction.d.ts +14 -0
  104. package/dist/installer/installer-extraction.js +289 -0
  105. package/dist/installer/installer-fetch-guard.d.ts +15 -0
  106. package/dist/installer/installer-fetch-guard.js +50 -0
  107. package/dist/installer/installer-identity.d.ts +23 -0
  108. package/dist/installer/installer-identity.js +286 -0
  109. package/dist/installer/installer-layout.d.ts +21 -0
  110. package/dist/installer/installer-layout.js +89 -0
  111. package/dist/installer/installer-observation.d.ts +64 -0
  112. package/dist/installer/installer-observation.js +473 -0
  113. package/dist/installer/installer-process-cleanup.d.ts +18 -0
  114. package/dist/installer/installer-process-cleanup.js +158 -0
  115. package/dist/installer/installer-qualification-command.d.ts +11 -0
  116. package/dist/installer/installer-qualification-command.js +71 -0
  117. package/dist/installer/installer-renderer-evidence.d.ts +43 -0
  118. package/dist/installer/installer-renderer-evidence.js +136 -0
  119. package/dist/installer/installer-upgrade-command.d.ts +37 -0
  120. package/dist/installer/installer-upgrade-command.js +172 -0
  121. package/dist/installer/installer-worker-guard.d.ts +21 -0
  122. package/dist/installer/installer-worker-guard.js +72 -0
  123. package/dist/installer/native-executable.d.ts +5 -0
  124. package/dist/installer/native-executable.js +21 -0
  125. package/dist/installer/upgrade-asset-download.d.ts +13 -0
  126. package/dist/installer/upgrade-asset-download.js +41 -0
  127. package/dist/installer/write-all.d.ts +6 -0
  128. package/dist/installer/write-all.js +11 -0
  129. package/dist/native/app-bundle.d.ts +28 -0
  130. package/dist/native/app-bundle.js +60 -0
  131. package/dist/native/cef-helper.d.ts +28 -0
  132. package/dist/native/cef-helper.js +402 -0
  133. package/dist/native/desktop-build-hook.d.ts +7 -0
  134. package/dist/native/desktop-build-hook.js +20 -0
  135. package/dist/native/electrobun-source-patch.d.ts +25 -0
  136. package/dist/native/electrobun-source-patch.js +93 -0
  137. package/dist/native/linux-cef-links.d.ts +2 -0
  138. package/dist/native/linux-cef-links.js +15 -0
  139. package/dist/native/native-secret-store.d.ts +27 -0
  140. package/dist/native/native-secret-store.js +70 -0
  141. package/dist/native/native-utilities.d.ts +24 -0
  142. package/dist/native/native-utilities.js +85 -0
  143. package/dist/native/partitioned-window.d.ts +34 -0
  144. package/dist/native/partitioned-window.js +44 -0
  145. package/dist/native/renderer-profile.d.ts +53 -0
  146. package/dist/native/renderer-profile.js +30 -0
  147. package/dist/native/secure-window.d.ts +38 -0
  148. package/dist/native/secure-window.js +77 -0
  149. package/dist/native/sidecar-services.d.ts +23 -0
  150. package/dist/native/sidecar-services.js +46 -0
  151. package/dist/native/sidecar.d.ts +81 -0
  152. package/dist/native/sidecar.js +250 -0
  153. package/dist/native/window-bootstrap.d.ts +24 -0
  154. package/dist/native/window-bootstrap.js +63 -0
  155. package/dist/native/window-options.d.ts +32 -0
  156. package/dist/native/window-options.js +23 -0
  157. package/dist/native/windows-build-hook-internal.d.ts +2 -0
  158. package/dist/native/windows-build-hook-internal.js +32 -0
  159. package/dist/native/windows-build-hook.d.ts +2 -0
  160. package/dist/native/windows-build-hook.js +12 -0
  161. package/dist/native/windows-runtime-patch-internal.d.ts +3 -0
  162. package/dist/native/windows-runtime-patch-internal.js +20 -0
  163. package/dist/native/windows-runtime-patch.d.ts +4 -0
  164. package/dist/native/windows-runtime-patch.js +12 -0
  165. package/dist/release/feed-release-cut.d.ts +23 -0
  166. package/dist/release/feed-release-cut.js +93 -0
  167. package/dist/release/feed-state.d.ts +25 -0
  168. package/dist/release/feed-state.js +81 -0
  169. package/dist/release/framework-package-publish.d.ts +21 -0
  170. package/dist/release/framework-package-publish.js +127 -0
  171. package/dist/release/framework-update.d.ts +30 -0
  172. package/dist/release/framework-update.js +139 -0
  173. package/dist/release/github-cli.d.ts +6 -0
  174. package/dist/release/github-cli.js +16 -0
  175. package/dist/release/github-release-assets.d.ts +3 -0
  176. package/dist/release/github-release-assets.js +24 -0
  177. package/dist/release/github-release-cut.d.ts +14 -0
  178. package/dist/release/github-release-cut.js +174 -0
  179. package/dist/release/github-release-lookup.d.ts +7 -0
  180. package/dist/release/github-release-lookup.js +29 -0
  181. package/dist/release/github-release-promotion.d.ts +10 -0
  182. package/dist/release/github-release-promotion.js +78 -0
  183. package/dist/release/github-release-provenance.d.ts +9 -0
  184. package/dist/release/github-release-provenance.js +27 -0
  185. package/dist/release/github-release-publisher.d.ts +9 -0
  186. package/dist/release/github-release-publisher.js +63 -0
  187. package/dist/release/github-release-qualification.d.ts +12 -0
  188. package/dist/release/github-release-qualification.js +80 -0
  189. package/dist/release/local-provenance.d.ts +24 -0
  190. package/dist/release/local-provenance.js +72 -0
  191. package/dist/release/local-release.d.ts +133 -0
  192. package/dist/release/local-release.js +387 -0
  193. package/dist/release/macos-dmg.d.ts +22 -0
  194. package/dist/release/macos-dmg.js +91 -0
  195. package/dist/release/release-artifact.d.ts +6 -0
  196. package/dist/release/release-artifact.js +38 -0
  197. package/dist/release/release-assets-plan.d.ts +14 -0
  198. package/dist/release/release-assets-plan.js +65 -0
  199. package/dist/release/release-config.d.ts +76 -0
  200. package/dist/release/release-config.js +180 -0
  201. package/dist/release/release-cut-command.d.ts +13 -0
  202. package/dist/release/release-cut-command.js +39 -0
  203. package/dist/release/release-cut.d.ts +54 -0
  204. package/dist/release/release-cut.js +76 -0
  205. package/dist/release/release-descriptor-staging.d.ts +34 -0
  206. package/dist/release/release-descriptor-staging.js +147 -0
  207. package/dist/release/release-finalize.d.ts +16 -0
  208. package/dist/release/release-finalize.js +104 -0
  209. package/dist/release/release-promotion-command.d.ts +12 -0
  210. package/dist/release/release-promotion-command.js +28 -0
  211. package/dist/release/release-promotion.d.ts +29 -0
  212. package/dist/release/release-promotion.js +57 -0
  213. package/dist/release/release-publication.d.ts +33 -0
  214. package/dist/release/release-publication.js +138 -0
  215. package/dist/release/release-publish-command.d.ts +7 -0
  216. package/dist/release/release-publish-command.js +91 -0
  217. package/dist/release/release-qualification.d.ts +106 -0
  218. package/dist/release/release-qualification.js +135 -0
  219. package/dist/release/release-staging.d.ts +9 -0
  220. package/dist/release/release-staging.js +61 -0
  221. package/dist/release/release-steps.d.ts +38 -0
  222. package/dist/release/release-steps.js +147 -0
  223. package/dist/release/retained-release-build.d.ts +19 -0
  224. package/dist/release/retained-release-build.js +122 -0
  225. package/dist/shell/app-shell.d.ts +61 -0
  226. package/dist/shell/app-shell.js +306 -0
  227. package/dist/shell/app-utilities.d.ts +122 -0
  228. package/dist/shell/app-utilities.js +334 -0
  229. package/dist/shell/application-menu-commands.d.ts +5 -0
  230. package/dist/shell/application-menu-commands.js +11 -0
  231. package/dist/shell/application-menu.d.ts +61 -0
  232. package/dist/shell/application-menu.js +208 -0
  233. package/dist/shell/help-shortcuts.d.ts +12 -0
  234. package/dist/shell/help-shortcuts.js +22 -0
  235. package/dist/shell/navigation-drawer.d.ts +12 -0
  236. package/dist/shell/navigation-drawer.js +42 -0
  237. package/dist/shell/settings-sections.d.ts +31 -0
  238. package/dist/shell/settings-sections.js +50 -0
  239. package/dist/shell/shortcut-platform.d.ts +17 -0
  240. package/dist/shell/shortcut-platform.js +25 -0
  241. package/dist/update-helper.bundle.js +260 -0
  242. package/dist/updates/channel-update-manager.d.ts +46 -0
  243. package/dist/updates/channel-update-manager.js +114 -0
  244. package/dist/updates/desktop-updater.d.ts +104 -0
  245. package/dist/updates/desktop-updater.js +345 -0
  246. package/dist/updates/release-feed.d.ts +61 -0
  247. package/dist/updates/release-feed.js +111 -0
  248. package/dist/updates/release-location.d.ts +9 -0
  249. package/dist/updates/release-location.js +80 -0
  250. package/dist/updates/release-version.d.ts +12 -0
  251. package/dist/updates/release-version.js +43 -0
  252. package/dist/updates/signed-release.d.ts +63 -0
  253. package/dist/updates/signed-release.js +162 -0
  254. package/dist/updates/stable-file.d.ts +10 -0
  255. package/dist/updates/stable-file.js +22 -0
  256. package/dist/updates/update-adapter.d.ts +57 -0
  257. package/dist/updates/update-adapter.js +72 -0
  258. package/dist/updates/update-arm.d.ts +24 -0
  259. package/dist/updates/update-arm.js +95 -0
  260. package/dist/updates/update-channel-store.d.ts +8 -0
  261. package/dist/updates/update-channel-store.js +72 -0
  262. package/dist/updates/update-discovery.d.ts +13 -0
  263. package/dist/updates/update-discovery.js +56 -0
  264. package/dist/updates/update-download.d.ts +14 -0
  265. package/dist/updates/update-download.js +67 -0
  266. package/dist/updates/update-exclusive-rename.d.ts +2 -0
  267. package/dist/updates/update-exclusive-rename.js +52 -0
  268. package/dist/updates/update-extraction.d.ts +18 -0
  269. package/dist/updates/update-extraction.js +183 -0
  270. package/dist/updates/update-handoff-plan.d.ts +22 -0
  271. package/dist/updates/update-handoff-plan.js +28 -0
  272. package/dist/updates/update-helper.d.ts +24 -0
  273. package/dist/updates/update-helper.js +56 -0
  274. package/dist/updates/update-launch.d.ts +5 -0
  275. package/dist/updates/update-launch.js +27 -0
  276. package/dist/updates/update-manager.d.ts +40 -0
  277. package/dist/updates/update-manager.js +83 -0
  278. package/dist/updates/update-process-fence.d.ts +10 -0
  279. package/dist/updates/update-process-fence.js +114 -0
  280. package/dist/updates/update-resume.d.ts +13 -0
  281. package/dist/updates/update-resume.js +34 -0
  282. package/dist/updates/update-shutdown.d.ts +15 -0
  283. package/dist/updates/update-shutdown.js +29 -0
  284. package/dist/updates/update-state.d.ts +30 -0
  285. package/dist/updates/update-state.js +18 -0
  286. package/dist/updates/update-swap-stage.d.ts +27 -0
  287. package/dist/updates/update-swap-stage.js +58 -0
  288. package/dist/updates/update-swap.d.ts +10 -0
  289. package/dist/updates/update-swap.js +30 -0
  290. package/dist/views/app-about.d.ts +22 -0
  291. package/dist/views/app-about.js +43 -0
  292. package/dist/views/app-appearance.d.ts +11 -0
  293. package/dist/views/app-appearance.js +42 -0
  294. package/dist/views/app-help.d.ts +17 -0
  295. package/dist/views/app-help.js +42 -0
  296. package/dist/views/app-settings.d.ts +26 -0
  297. package/dist/views/app-settings.js +97 -0
  298. package/dist/views/appearance-surface.d.ts +9 -0
  299. package/dist/views/appearance-surface.js +334 -0
  300. package/dist/views/update-surface.d.ts +34 -0
  301. package/dist/views/update-surface.js +64 -0
  302. package/package.json +374 -4
  303. package/src/app/application.tsx +138 -0
  304. package/src/appearance/appearance-host.tsx +205 -0
  305. package/src/appearance/appearance-preferences.ts +287 -0
  306. package/src/appearance/composition.ts +29 -0
  307. package/src/appearance/custom-theme-import.ts +424 -0
  308. package/src/appearance/custom-theme-library.ts +600 -0
  309. package/src/appearance/editor.ts +94 -0
  310. package/src/appearance/theme-file-importer.ts +103 -0
  311. package/src/appearance/theme-record-adapter.ts +106 -0
  312. package/src/appearance/theme-registry.ts +20 -0
  313. package/src/appearance/window-surface.ts +18 -0
  314. package/src/desktop/client-assets.ts +75 -0
  315. package/src/native/electrobun-cef-main-frame-bridges.patch +63 -0
  316. package/src/native/electrobun-windows-shortcut-com.patch +923 -0
  317. package/src/native/renderer-profile.ts +27 -0
  318. package/src/native/window-options.ts +24 -0
  319. package/src/shell/app-shell.tsx +294 -0
  320. package/src/shell/app-utilities.tsx +437 -0
  321. package/src/shell/help-shortcuts.ts +24 -0
  322. package/src/shell/navigation-drawer.tsx +36 -0
  323. package/src/shell/settings-sections.ts +74 -0
  324. package/src/shell/shortcut-platform.ts +35 -0
  325. package/src/updates/release-version.ts +57 -0
  326. package/src/updates/update-adapter.ts +129 -0
  327. package/src/updates/update-state.ts +34 -0
  328. package/src/views/app-about.tsx +44 -0
  329. package/src/views/app-appearance.tsx +32 -0
  330. package/src/views/app-help.tsx +43 -0
  331. package/src/views/app-settings.tsx +88 -0
  332. package/src/views/appearance-surface.tsx +427 -0
  333. package/src/views/update-surface.tsx +85 -0
  334. package/templates/application/.gitattributes +1 -0
  335. package/templates/application/.github/workflows/release-assets.yml +29 -0
  336. package/templates/application/.github/workflows/release-finalize.yml +29 -0
  337. package/templates/application/.github/workflows/release-please.yml +19 -0
  338. package/templates/application/.github/workflows/release.yml +29 -0
  339. package/templates/application/.github/workflows/validation.yml +28 -0
  340. package/templates/application/.oxfmtrc.json +6 -0
  341. package/templates/application/.oxlintrc.json +48 -0
  342. package/templates/application/.release-please-manifest.json +3 -0
  343. package/templates/application/README.md +47 -0
  344. package/templates/application/electrobun.config.ts +22 -0
  345. package/templates/application/release-please-config.json +12 -0
  346. package/templates/application/scripts/app-version.ts +9 -0
  347. package/templates/application/scripts/build-desktop.ts +34 -0
  348. package/templates/application/scripts/secure-build.ts +1 -0
  349. package/templates/application/scripts/stage-release.ts +21 -0
  350. package/templates/application/src/bun/index.ts +80 -0
  351. package/templates/application/src/electrobun.d.ts +27 -0
  352. package/templates/application/src/web/index.html +12 -0
  353. package/templates/application/src/web/main.tsx +97 -0
  354. package/templates/application/src/web/public/icon.svg +1 -0
  355. package/templates/application/src/web/style.css +3 -0
  356. package/templates/application/tests/app-config.test.ts +9 -0
  357. package/templates/application/tsconfig.json +15 -0
  358. package/templates/application/vite.config.ts +10 -0
@@ -0,0 +1,600 @@
1
+ /*
2
+ * Copyright (c) 2026 Wing
3
+ * Licensed under the MIT License.
4
+ *
5
+ * The custom theme library keeps the registry-validation rules of Adea's accepted
6
+ * port of Zeron's theme registry (https://github.com/zeronsh/zeron). The library is
7
+ * Adea's own product schema (declared-license imports, a stored `variant` per
8
+ * theme); the shared ThemeProvider receives it as extra variants. See NOTICE and
9
+ * the repository history for source and behavior provenance.
10
+ */
11
+ import type { AdeaTheme, AdeaThemeRecord } from '@adea-ai/ui/lib/theme-records'
12
+
13
+ import { contrastRatio } from '@adea-ai/ui/lib/accent-roles'
14
+ import { quarantineRecord } from '@adea-ai/ui/lib/preference-store'
15
+ import { defaultVariantFor } from '@adea-ai/ui/lib/theme-defaults'
16
+ import { variantFromRecord } from '@adea-ai/ui/lib/theme-records'
17
+ import type { ThemeVariant as UiThemeVariant } from '@adea-ai/ui/lib/themes'
18
+
19
+ /**
20
+ * The custom theme library: themes the user imported from a file, stored in
21
+ * `localStorage` and handed to the provider as extra variants. Import and
22
+ * projection live in dev-view (the lazy appearance chunk); this module owns the
23
+ * stored shape, the in-memory view, validation and the translation to the shared
24
+ * variant shape.
25
+ *
26
+ * The stored shape is a compatibility surface. Imported themes written by any
27
+ * earlier build keep resolving: `variant` stays in the host shape below and
28
+ * `flatTokens` stays the verbatim token map, so what a user imported is what is
29
+ * painted.
30
+ */
31
+
32
+ export type StoredThemeAppearance = 'light' | 'dark'
33
+
34
+ export type StoredThemeTerminal = Readonly<{
35
+ background: string
36
+ foreground: string
37
+ cursor: string
38
+ selection: string
39
+ /** The 16 xterm ANSI slots, in protocol order. */
40
+ ansi: readonly string[]
41
+ }>
42
+
43
+ export type StoredThemeEditorRoles = Readonly<{
44
+ keyword: string
45
+ string: string
46
+ number: string
47
+ comment: string
48
+ function: string
49
+ variable: string
50
+ type: string
51
+ tag: string
52
+ attribute: string
53
+ operator: string
54
+ heading: string
55
+ link: string
56
+ diffAdd: string
57
+ diffDelete: string
58
+ diffHunk: string
59
+ searchMatch: string
60
+ }>
61
+
62
+ export type StoredThemeChartRoles = Readonly<{
63
+ chart1: string
64
+ chart2: string
65
+ chart3: string
66
+ chart4: string
67
+ chart5: string
68
+ chart6: string
69
+ }>
70
+
71
+ export type StoredThemeColors = Readonly<{
72
+ background: string
73
+ foreground: string
74
+ card: string
75
+ cardForeground: string
76
+ popover: string
77
+ popoverForeground: string
78
+ primary: string
79
+ primaryForeground: string
80
+ secondary: string
81
+ secondaryForeground: string
82
+ muted: string
83
+ mutedForeground: string
84
+ accent: string
85
+ accentForeground: string
86
+ destructive: string
87
+ destructiveAction: string
88
+ destructiveActionForeground: string
89
+ success: string
90
+ border: string
91
+ input: string
92
+ ring: string
93
+ }>
94
+
95
+ /** The variant shape the library has always stored for an imported theme. */
96
+ export type StoredThemeVariant = Readonly<{
97
+ id: string
98
+ familyId: string
99
+ familyName: string
100
+ name: string
101
+ appearance: StoredThemeAppearance
102
+ colors: StoredThemeColors
103
+ terminal: StoredThemeTerminal
104
+ editor: StoredThemeEditorRoles
105
+ charts: StoredThemeChartRoles
106
+ }>
107
+
108
+ export type CustomThemeStored = Readonly<{
109
+ /** Stable id, namespaced so it can never collide with a catalogue id. */
110
+ id: string
111
+ name: string
112
+ appearance: StoredThemeAppearance
113
+ importedAt: string
114
+ variant: StoredThemeVariant
115
+ /** The flat token map the no-flash script applies for a stored selection. */
116
+ flatTokens: Readonly<Record<string, string>>
117
+ /** Non-fatal adjustments made while normalizing the file, for the UI. */
118
+ notes: readonly string[]
119
+ }>
120
+
121
+ export type AppearanceStorage = Pick<Storage, 'getItem' | 'setItem'>
122
+
123
+ export const CUSTOM_THEME_LIBRARY_STORAGE_KEY = 'appearance.library'
124
+ /**
125
+ * Where an unreadable library is quarantined. It is its own key: the library and
126
+ * the appearance preference used to share `appearance.recovery`, so one could
127
+ * overwrite the other's capture.
128
+ */
129
+ export const CUSTOM_THEME_LIBRARY_RECOVERY_KEY = 'appearance.library.recovery'
130
+ const CUSTOM_THEME_LIBRARY_VERSION = 1
131
+ const CUSTOM_THEME_ID_PREFIX = 'custom-'
132
+
133
+ /*
134
+ * Registry validation, ported from Zeron `ThemeRegistry::validate`: core text and
135
+ * muted text must reach 4.5:1, the accent 3:1, on-accent 4.5:1, the terminal
136
+ * foreground 4.5:1, and every chromatic ANSI slot 3:1 (slots 0 and 8 are
137
+ * structural black/dim colors). Import runs it over the one variant it just built.
138
+ */
139
+
140
+ export type ValidationIssue = Readonly<{
141
+ variantId: string
142
+ severity: 'error' | 'warning'
143
+ message: string
144
+ }>
145
+
146
+ export function validateThemeRegistry(registry: readonly StoredThemeVariant[]): ValidationIssue[] {
147
+ const issues: ValidationIssue[] = []
148
+ const seen = new Set<string>()
149
+ for (const variant of registry) {
150
+ if (variant.id.trim().length === 0 || seen.has(variant.id)) {
151
+ issues.push({
152
+ variantId: variant.id,
153
+ severity: 'error',
154
+ message: 'variant id must be unique',
155
+ })
156
+ }
157
+ seen.add(variant.id)
158
+ const check = (role: string, foreground: string, background: string, minimum: number) => {
159
+ const actual = contrastRatio(foreground, background)
160
+ if (actual < minimum) {
161
+ issues.push({
162
+ variantId: variant.id,
163
+ severity: 'error',
164
+ message: `${role} contrast is ${actual.toFixed(2)}:1; expected ${minimum.toFixed(1)}:1`,
165
+ })
166
+ }
167
+ }
168
+ check('text', variant.colors.foreground, variant.colors.background, 4.5)
169
+ check('muted text', variant.colors.mutedForeground, variant.colors.background, 4.5)
170
+ check('primary', variant.colors.primary, variant.colors.background, 3)
171
+ check('on-primary', variant.colors.primaryForeground, variant.colors.primary, 4.5)
172
+ check('terminal foreground', variant.terminal.foreground, variant.terminal.background, 4.5)
173
+ for (const [index, color] of variant.terminal.ansi.entries()) {
174
+ if (index % 8 === 0) continue
175
+ const actual = contrastRatio(color, variant.terminal.background)
176
+ if (actual < 3) {
177
+ issues.push({
178
+ variantId: variant.id,
179
+ severity: 'warning',
180
+ message: `terminal ANSI slot ${index} is below 3:1`,
181
+ })
182
+ }
183
+ }
184
+ check('editor comment', variant.editor.comment, variant.colors.background, 4.5)
185
+ check('diff delete', variant.editor.diffDelete, variant.colors.background, 3)
186
+ check('diff add', variant.editor.diffAdd, variant.colors.background, 3)
187
+ }
188
+ return issues
189
+ }
190
+
191
+ /*
192
+ * The flat token map: the custom properties an imported theme owns. It is stored
193
+ * with the theme (`flatTokens`) so the pre-paint script can apply it without the
194
+ * library's code, and the provider writes it verbatim over everything it derives.
195
+ */
196
+
197
+ const ANSI_NAMES = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white']
198
+
199
+ function kebabCase(value: string): string {
200
+ return value.replaceAll(/[A-Z]/g, (character) => `-${character.toLocaleLowerCase()}`)
201
+ }
202
+
203
+ function terminalTokens(palette: StoredThemeTerminal): Record<string, string> {
204
+ const tokens: Record<string, string> = {
205
+ '--terminal-background': palette.background,
206
+ '--terminal-foreground': palette.foreground,
207
+ '--terminal-cursor': palette.cursor,
208
+ '--terminal-selection': palette.selection,
209
+ }
210
+ for (const [index, color] of palette.ansi.entries()) {
211
+ const name = ANSI_NAMES[index % 8]!
212
+ tokens[index < 8 ? `--terminal-ansi-${name}` : `--terminal-ansi-bright-${name}`] = color
213
+ }
214
+ return tokens
215
+ }
216
+
217
+ /** The custom properties an imported variant owns, as a flat map. */
218
+ export function flatVariantTokens(variant: StoredThemeVariant): Record<string, string> {
219
+ const tokens: Record<string, string> = {}
220
+ for (const [role, value] of Object.entries(variant.colors)) {
221
+ tokens[`--${kebabCase(role)}`] = value
222
+ }
223
+ Object.assign(tokens, terminalTokens(variant.terminal))
224
+ for (const [role, value] of Object.entries(variant.editor)) {
225
+ tokens[`--editor-${kebabCase(role)}`] = value
226
+ }
227
+ for (const [index, value] of Object.values(variant.charts).entries()) {
228
+ tokens[`--chart-${index + 1}`] = value
229
+ }
230
+ return tokens
231
+ }
232
+
233
+ /*
234
+ * The shared variant for a stored theme.
235
+ *
236
+ * The stored variant is lossy against the catalogue's record shape (it has no
237
+ * warning, info or hover roles), so the record is reconstructed from it, the same
238
+ * reconstruction the appearance editor previews. The shared provider derives what
239
+ * the import never stored (status hues, sidebar, hover) from that record, and then
240
+ * writes `flatTokens` verbatim over the derivation: every stored key paints exactly
241
+ * what the user imported.
242
+ */
243
+
244
+ const IMPORTED_PROVENANCE = {
245
+ project: 'Adea themes catalogue',
246
+ url: 'https://github.com/adea-ai/themes',
247
+ license: 'Apache-2.0',
248
+ } as const
249
+
250
+ function ansiRamp(variant: StoredThemeVariant): AdeaTheme['ansi'] {
251
+ const [
252
+ black,
253
+ red,
254
+ green,
255
+ yellow,
256
+ blue,
257
+ magenta,
258
+ cyan,
259
+ white,
260
+ brightBlack,
261
+ brightRed,
262
+ brightGreen,
263
+ brightYellow,
264
+ brightBlue,
265
+ brightMagenta,
266
+ brightCyan,
267
+ brightWhite,
268
+ ] = variant.terminal.ansi
269
+ return {
270
+ black: black!,
271
+ red: red!,
272
+ green: green!,
273
+ yellow: yellow!,
274
+ blue: blue!,
275
+ magenta: magenta!,
276
+ cyan: cyan!,
277
+ white: white!,
278
+ brightBlack: brightBlack!,
279
+ brightRed: brightRed!,
280
+ brightGreen: brightGreen!,
281
+ brightYellow: brightYellow!,
282
+ brightBlue: brightBlue!,
283
+ brightMagenta: brightMagenta!,
284
+ brightCyan: brightCyan!,
285
+ brightWhite: brightWhite!,
286
+ }
287
+ }
288
+
289
+ /**
290
+ * The catalogue-shaped record for an imported variant. The editor reads only its
291
+ * surface, text, border and accent roles; warning and info are the ANSI yellow and
292
+ * blue because the stored variant has no such roles.
293
+ */
294
+ export function storedVariantRecord(variant: StoredThemeVariant): AdeaThemeRecord {
295
+ const colors = variant.colors
296
+ const ansi = ansiRamp(variant)
297
+ const theme: AdeaTheme = {
298
+ id: variant.id,
299
+ name: variant.name,
300
+ appearance: variant.appearance,
301
+ colors: {
302
+ background: colors.background,
303
+ foreground: colors.foreground,
304
+ surface: colors.card,
305
+ surfaceElevated: colors.popover,
306
+ surfaceHover: colors.accent,
307
+ surfaceActive: colors.border,
308
+ border: colors.border,
309
+ borderMuted: colors.border,
310
+ text: colors.foreground,
311
+ textMuted: colors.mutedForeground,
312
+ textSubtle: colors.mutedForeground,
313
+ accent: colors.primary,
314
+ accentForeground: colors.primaryForeground,
315
+ success: colors.success,
316
+ warning: ansi.yellow,
317
+ error: colors.destructive,
318
+ info: ansi.blue,
319
+ },
320
+ ansi,
321
+ cursor: variant.terminal.cursor,
322
+ selection: variant.terminal.selection,
323
+ }
324
+ return {
325
+ ...theme,
326
+ family: variant.familyId,
327
+ familyLabel: variant.familyName,
328
+ label: variant.name,
329
+ description: `${variant.name}, imported into your library.`,
330
+ provenance: IMPORTED_PROVENANCE,
331
+ tags: ['imported', variant.appearance],
332
+ }
333
+ }
334
+
335
+ /**
336
+ * The shared-provider variant for a stored theme: derived roles from the
337
+ * reconstructed record, then `flatTokens` verbatim.
338
+ *
339
+ * A record the shared projection cannot map falls back to the default theme of the
340
+ * same appearance under the stored identity, so an import that the projection
341
+ * rejects still paints from its tokens instead of vanishing.
342
+ */
343
+ export function toUiVariant(stored: CustomThemeStored): UiThemeVariant {
344
+ const { variant } = stored
345
+ let base: UiThemeVariant
346
+ try {
347
+ base = variantFromRecord(storedVariantRecord(variant))
348
+ } catch {
349
+ // The shipped default of the appearance: the provider's own start-up data, so the
350
+ // shell never imports the themes catalogue to repair an import.
351
+ base = {
352
+ ...defaultVariantFor(variant.appearance),
353
+ id: variant.id,
354
+ family: variant.familyId,
355
+ familyLabel: variant.familyName,
356
+ label: variant.name,
357
+ description: `${variant.name}, imported into your library.`,
358
+ provenance: {
359
+ source: IMPORTED_PROVENANCE.project,
360
+ url: IMPORTED_PROVENANCE.url,
361
+ license: IMPORTED_PROVENANCE.license,
362
+ },
363
+ }
364
+ }
365
+ return { ...base, tokens: stored.flatTokens }
366
+ }
367
+
368
+ /*
369
+ * The in-memory library.
370
+ *
371
+ * It lives on the host object, not in module state: the dev graph (and any consumer
372
+ * graph) can legitimately load this module twice (a relative import and the
373
+ * components subpath are distinct module records), and a singleton array would fork
374
+ * the registry. The listeners live there too, so a change made through one instance
375
+ * reaches a subscriber registered through the other.
376
+ */
377
+ type LibraryState = {
378
+ themes: readonly CustomThemeStored[]
379
+ /** Derived from `themes`; rebuilt on first read after each change. */
380
+ uiVariants?: readonly UiThemeVariant[]
381
+ listeners: Set<() => void>
382
+ }
383
+ type LibraryHost = typeof globalThis & { __ADEA_THEME_LIBRARY__?: Partial<LibraryState> }
384
+ const libraryHost = globalThis as LibraryHost
385
+
386
+ function library(): LibraryState {
387
+ const existing = libraryHost.__ADEA_THEME_LIBRARY__
388
+ if (existing && Array.isArray(existing.themes) && existing.listeners) {
389
+ return existing as LibraryState
390
+ }
391
+ // A host object written by an older module instance has another shape.
392
+ const created: LibraryState = { themes: [], listeners: existing?.listeners ?? new Set() }
393
+ libraryHost.__ADEA_THEME_LIBRARY__ = created
394
+ return created
395
+ }
396
+
397
+ function replaceThemes(themes: readonly CustomThemeStored[]): void {
398
+ const state = library()
399
+ state.themes = Object.freeze([...themes])
400
+ state.uiVariants = undefined
401
+ }
402
+
403
+ /** The imported themes' stored variants, in import order. */
404
+ export function customThemeVariants(): readonly StoredThemeVariant[] {
405
+ return library().themes.map((theme) => theme.variant)
406
+ }
407
+
408
+ /** The imported themes as shared-provider variants: what the provider's `themes` takes. */
409
+ export function customUiVariants(): readonly UiThemeVariant[] {
410
+ const state = library()
411
+ state.uiVariants ??= Object.freeze(state.themes.map(toUiVariant))
412
+ return state.uiVariants
413
+ }
414
+
415
+ export function subscribeCustomThemes(listener: () => void): () => void {
416
+ const { listeners } = library()
417
+ listeners.add(listener)
418
+ return () => listeners.delete(listener)
419
+ }
420
+
421
+ function notifyCustomThemes(): void {
422
+ for (const listener of library().listeners) listener()
423
+ }
424
+
425
+ function isCustomThemeId(id: string): boolean {
426
+ return id.startsWith(CUSTOM_THEME_ID_PREFIX)
427
+ }
428
+
429
+ /**
430
+ * Replace the imported-theme set, persist it, and tell subscribers. A theme whose id
431
+ * is not custom-namespaced is namespaced here, so a library file can never shadow a
432
+ * catalogue id.
433
+ */
434
+ export function setCustomThemes(
435
+ themes: readonly CustomThemeStored[],
436
+ storage: AppearanceStorage | undefined
437
+ ): boolean {
438
+ const safe = themes.map((theme) => {
439
+ if (isCustomThemeId(theme.id)) return theme
440
+ const id = `${CUSTOM_THEME_ID_PREFIX}${theme.id}`
441
+ return { ...theme, id, variant: { ...theme.variant, id } }
442
+ })
443
+ try {
444
+ if (storage) {
445
+ const raw = storage.getItem(CUSTOM_THEME_LIBRARY_STORAGE_KEY)
446
+ if (raw) {
447
+ const result = parseLibrary(raw)
448
+ if (result.reason && !preserveLibrary(storage, raw, result.reason))
449
+ throw new Error('Library recovery unavailable')
450
+ }
451
+ }
452
+ storage?.setItem(
453
+ CUSTOM_THEME_LIBRARY_STORAGE_KEY,
454
+ JSON.stringify({ version: CUSTOM_THEME_LIBRARY_VERSION, themes: safe })
455
+ )
456
+ } catch {
457
+ return false
458
+ }
459
+ replaceThemes(safe)
460
+ notifyCustomThemes()
461
+ return true
462
+ }
463
+
464
+ const object = (value: unknown): value is Record<string, unknown> =>
465
+ typeof value === 'object' && value !== null && !Array.isArray(value)
466
+ const fields = (value: unknown, names: readonly string[]) =>
467
+ object(value) && names.every((name) => typeof value[name] === 'string')
468
+
469
+ function isStoredTheme(entry: unknown): entry is CustomThemeStored {
470
+ if (!object(entry) || !object(entry.variant)) return false
471
+ const theme = entry
472
+ const variant = entry.variant
473
+ return (
474
+ typeof theme.id === 'string' &&
475
+ typeof theme.name === 'string' &&
476
+ (theme.appearance === 'light' || theme.appearance === 'dark') &&
477
+ typeof theme.importedAt === 'string' &&
478
+ fields(variant, ['id', 'familyId', 'familyName', 'name']) &&
479
+ (variant.appearance === 'light' || variant.appearance === 'dark') &&
480
+ fields(variant.colors, [
481
+ 'background',
482
+ 'foreground',
483
+ 'card',
484
+ 'cardForeground',
485
+ 'popover',
486
+ 'popoverForeground',
487
+ 'primary',
488
+ 'primaryForeground',
489
+ 'secondary',
490
+ 'secondaryForeground',
491
+ 'muted',
492
+ 'mutedForeground',
493
+ 'accent',
494
+ 'accentForeground',
495
+ 'destructive',
496
+ 'destructiveAction',
497
+ 'destructiveActionForeground',
498
+ 'success',
499
+ 'border',
500
+ 'input',
501
+ 'ring',
502
+ ]) &&
503
+ fields(variant.terminal, ['background', 'foreground', 'cursor', 'selection']) &&
504
+ object(variant.terminal) &&
505
+ Array.isArray(variant.terminal.ansi) &&
506
+ variant.terminal.ansi.length === 16 &&
507
+ variant.terminal.ansi.every((color) => typeof color === 'string') &&
508
+ fields(variant.editor, [
509
+ 'keyword',
510
+ 'string',
511
+ 'number',
512
+ 'comment',
513
+ 'function',
514
+ 'variable',
515
+ 'type',
516
+ 'tag',
517
+ 'attribute',
518
+ 'operator',
519
+ 'heading',
520
+ 'link',
521
+ 'diffAdd',
522
+ 'diffDelete',
523
+ 'diffHunk',
524
+ 'searchMatch',
525
+ ]) &&
526
+ fields(variant.charts, ['chart1', 'chart2', 'chart3', 'chart4', 'chart5', 'chart6']) &&
527
+ object(theme.flatTokens) &&
528
+ Object.values(theme.flatTokens).every((value) => typeof value === 'string') &&
529
+ Array.isArray(theme.notes) &&
530
+ theme.notes.every((note) => typeof note === 'string')
531
+ )
532
+ }
533
+
534
+ function parseLibrary(raw: string): {
535
+ themes: CustomThemeStored[]
536
+ reason?: 'corrupt_json' | 'unsupported_record'
537
+ } {
538
+ let value: unknown
539
+ try {
540
+ value = JSON.parse(raw)
541
+ } catch {
542
+ return { themes: [], reason: 'corrupt_json' }
543
+ }
544
+ if (
545
+ !object(value) ||
546
+ value.version !== CUSTOM_THEME_LIBRARY_VERSION ||
547
+ !Array.isArray(value.themes)
548
+ )
549
+ return { themes: [], reason: 'unsupported_record' }
550
+ const themes = value.themes.filter(isStoredTheme)
551
+ return themes.length === value.themes.length
552
+ ? { themes }
553
+ : { themes, reason: 'unsupported_record' }
554
+ }
555
+
556
+ function preserveLibrary(
557
+ storage: AppearanceStorage,
558
+ raw: string,
559
+ reason: 'corrupt_json' | 'unsupported_record'
560
+ ): boolean {
561
+ const existing = storage.getItem(CUSTOM_THEME_LIBRARY_RECOVERY_KEY)
562
+ if (!existing) quarantineRecord(storage, CUSTOM_THEME_LIBRARY_RECOVERY_KEY, raw, reason)
563
+ const saved = storage.getItem(CUSTOM_THEME_LIBRARY_RECOVERY_KEY)
564
+ try {
565
+ const capture: unknown = saved && JSON.parse(saved)
566
+ return object(capture) && capture.schemaVersion === 1 && capture.raw === raw
567
+ } catch {
568
+ return false
569
+ }
570
+ }
571
+
572
+ /**
573
+ * Read the stored library. A malformed document starts an empty library and
574
+ * quarantines the raw bytes into the library's own recovery key, mirroring the
575
+ * appearance-preference recovery contract; individual invalid records are dropped,
576
+ * not fatal.
577
+ */
578
+ export function readCustomThemeLibrary(
579
+ storage: AppearanceStorage | undefined
580
+ ): readonly CustomThemeStored[] {
581
+ if (!storage) return []
582
+ try {
583
+ // An empty value is no library, not a corrupt one.
584
+ const raw = storage.getItem(CUSTOM_THEME_LIBRARY_STORAGE_KEY)
585
+ if (!raw) return []
586
+ const { themes, reason } = parseLibrary(raw)
587
+ if (reason) preserveLibrary(storage, raw, reason)
588
+ replaceThemes(themes)
589
+ return themes
590
+ } catch {
591
+ return []
592
+ }
593
+ }
594
+
595
+ export function removeCustomTheme(id: string, storage: AppearanceStorage | undefined): boolean {
596
+ return setCustomThemes(
597
+ readCustomThemeLibrary(storage).filter((theme) => theme.id !== id),
598
+ storage
599
+ )
600
+ }
@@ -0,0 +1,94 @@
1
+ /*
2
+ * Copyright (c) 2026 Wing
3
+ * Licensed under the MIT License.
4
+ *
5
+ * Draft/snapshot editing semantics substantially translated from Zeron
6
+ * crates/ui/src/appearance.rs (the `set_mode`/`set_theme`/`set_accent`/
7
+ * `set_surface` setter block), revision
8
+ * 30a9a9537c5ec96226c87f4bf349b6f77c5dfb59: unchanged values no-op, and every
9
+ * change resolves against the live palette immediately. Modified for Adea's
10
+ * explicit save/revert popover contract: an open snapshot, draft preview,
11
+ * Reset to defaults, Cancel back to the snapshot, Save to commit.
12
+ * See NOTICE for source and license provenance.
13
+ */
14
+ import { createSignal } from 'solid-js'
15
+ import { normalizeAppearanceEditorFontSettings } from '@adea-ai/ui/lib/appearance-font-settings'
16
+
17
+ import {
18
+ defaultAppearancePreferences,
19
+ normalizeAppearancePreferences,
20
+ type AppearancePreferencesV2,
21
+ } from './appearance-preferences'
22
+
23
+ export type AppearanceEditor = Readonly<{
24
+ /** The edited draft, reactive so dialog UI tracks every change. */
25
+ draft: () => AppearancePreferencesV2
26
+ /** True when the draft differs from the snapshot the editor opened with. */
27
+ dirty: () => boolean
28
+ /** True when the draft differs from the shipped defaults. */
29
+ differsFromDefaults: () => boolean
30
+ /** Begin editing: snapshot the committed preferences. */
31
+ open: (committed: AppearancePreferencesV2) => void
32
+ /** Set one or more draft fields; unchanged values no-op like Zeron's setters. */
33
+ set: (patch: Partial<AppearancePreferencesV2>) => void
34
+ /** Draft becomes the shipped defaults (still reversible until Save). */
35
+ reset: () => void
36
+ /** Discard the draft; the committed snapshot is authoritative again. */
37
+ revert: () => AppearancePreferencesV2
38
+ /** Commit the draft and clear the snapshot. */
39
+ save: () => AppearancePreferencesV2
40
+ }>
41
+
42
+ function samePreferences(left: AppearancePreferencesV2, right: AppearancePreferencesV2): boolean {
43
+ const leftFonts = normalizeAppearanceEditorFontSettings(left.fonts).settings
44
+ const rightFonts = normalizeAppearanceEditorFontSettings(right.fonts).settings
45
+ return (
46
+ (['ui', 'content', 'code'] as const).every(
47
+ (axis) =>
48
+ leftFonts[axis].family === rightFonts[axis].family &&
49
+ leftFonts[axis].size === rightFonts[axis].size
50
+ ) &&
51
+ left.mode === right.mode &&
52
+ left.lightThemeId === right.lightThemeId &&
53
+ left.darkThemeId === right.darkThemeId &&
54
+ left.terminalThemeId === right.terminalThemeId &&
55
+ left.accent === right.accent &&
56
+ left.surface === right.surface &&
57
+ left.reduceTransparency === right.reduceTransparency
58
+ )
59
+ }
60
+
61
+ export function createAppearanceEditor(
62
+ committed: AppearancePreferencesV2 = defaultAppearancePreferences
63
+ ): AppearanceEditor {
64
+ const [draft, setDraft] = createSignal<AppearancePreferencesV2>(committed)
65
+ const [snapshot, setSnapshot] = createSignal<AppearancePreferencesV2>(committed)
66
+
67
+ return {
68
+ draft,
69
+ dirty: () => !samePreferences(draft(), snapshot()),
70
+ differsFromDefaults: () => !samePreferences(draft(), defaultAppearancePreferences),
71
+ open: (value) => {
72
+ const normalized = normalizeAppearancePreferences(value).value
73
+ setSnapshot(normalized)
74
+ setDraft(normalized)
75
+ },
76
+ set: (patch) => {
77
+ const next = { ...draft(), ...patch }
78
+ // Zeron's setters return early when the value did not change.
79
+ if (samePreferences(next, draft())) return
80
+ setDraft(next)
81
+ },
82
+ reset: () => {
83
+ setDraft(defaultAppearancePreferences)
84
+ },
85
+ revert: () => {
86
+ setDraft(snapshot())
87
+ return snapshot()
88
+ },
89
+ save: () => {
90
+ setSnapshot(draft())
91
+ return draft()
92
+ },
93
+ }
94
+ }