@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.
- package/LICENSE +201 -0
- package/NOTICE +30 -0
- package/README.md +1009 -2
- package/dist/app/application.d.ts +47 -0
- package/dist/app/application.js +115 -0
- package/dist/app/create-application.d.ts +13 -0
- package/dist/app/create-application.js +178 -0
- package/dist/app/service-registry.d.ts +44 -0
- package/dist/app/service-registry.js +116 -0
- package/dist/appearance/appearance-host.d.ts +62 -0
- package/dist/appearance/appearance-host.js +115 -0
- package/dist/appearance/appearance-preferences.d.ts +106 -0
- package/dist/appearance/appearance-preferences.js +175 -0
- package/dist/appearance/composition.d.ts +11 -0
- package/dist/appearance/composition.js +16 -0
- package/dist/appearance/custom-theme-import.d.ts +14 -0
- package/dist/appearance/custom-theme-import.js +315 -0
- package/dist/appearance/custom-theme-library.d.ts +146 -0
- package/dist/appearance/custom-theme-library.js +378 -0
- package/dist/appearance/editor.d.ts +20 -0
- package/dist/appearance/editor.js +47 -0
- package/dist/appearance/theme-file-importer.d.ts +23 -0
- package/dist/appearance/theme-file-importer.js +66 -0
- package/dist/appearance/theme-record-adapter.d.ts +26 -0
- package/dist/appearance/theme-record-adapter.js +64 -0
- package/dist/appearance/theme-registry.d.ts +10 -0
- package/dist/appearance/theme-registry.js +16 -0
- package/dist/appearance/window-surface.d.ts +5 -0
- package/dist/appearance/window-surface.js +9 -0
- package/dist/ci/toolchain-identity.d.ts +39 -0
- package/dist/ci/toolchain-identity.js +196 -0
- package/dist/cli/cef-helper-cli.d.ts +2 -0
- package/dist/cli/cef-helper-cli.js +18 -0
- package/dist/cli/cli-runner.d.ts +8 -0
- package/dist/cli/cli-runner.js +23 -0
- package/dist/cli/create-application-cli.d.ts +2 -0
- package/dist/cli/create-application-cli.js +40 -0
- package/dist/cli/electrobun-shortcut-patch-cli.d.ts +2 -0
- package/dist/cli/electrobun-shortcut-patch-cli.js +17 -0
- package/dist/cli/framework-update-cli.d.ts +2 -0
- package/dist/cli/framework-update-cli.js +40 -0
- package/dist/cli/release-assets-plan-cli.d.ts +2 -0
- package/dist/cli/release-assets-plan-cli.js +14 -0
- package/dist/cli/release-cut-cli.d.ts +2 -0
- package/dist/cli/release-cut-cli.js +27 -0
- package/dist/cli/release-descriptor-staging-cli.d.ts +2 -0
- package/dist/cli/release-descriptor-staging-cli.js +45 -0
- package/dist/cli/release-finalize-cli.d.ts +1 -0
- package/dist/cli/release-finalize-cli.js +30 -0
- package/dist/cli/release-promote-cli.d.ts +2 -0
- package/dist/cli/release-promote-cli.js +32 -0
- package/dist/cli/release-publish-cli.d.ts +2 -0
- package/dist/cli/release-publish-cli.js +48 -0
- package/dist/cli/release-sign-cli.d.ts +2 -0
- package/dist/cli/release-sign-cli.js +13 -0
- package/dist/cli/release-step-cli.d.ts +2 -0
- package/dist/cli/release-step-cli.js +44 -0
- package/dist/cli/toolchain-identity-cli.d.ts +2 -0
- package/dist/cli/toolchain-identity-cli.js +10 -0
- package/dist/cli/update-helper-cli.d.ts +1 -0
- package/dist/cli/update-helper-cli.js +10 -0
- package/dist/cli/windows-runtime-patch-cli.d.ts +2 -0
- package/dist/cli/windows-runtime-patch-cli.js +17 -0
- package/dist/desktop/application-command-client.d.ts +15 -0
- package/dist/desktop/application-command-client.js +21 -0
- package/dist/desktop/channel-handshake.d.ts +32 -0
- package/dist/desktop/channel-handshake.js +111 -0
- package/dist/desktop/channel-proof.d.ts +43 -0
- package/dist/desktop/channel-proof.js +85 -0
- package/dist/desktop/client-assets.d.ts +7 -0
- package/dist/desktop/client-assets.js +59 -0
- package/dist/desktop/desktop-client.d.ts +23 -0
- package/dist/desktop/desktop-client.js +231 -0
- package/dist/desktop/desktop-gateway.d.ts +18 -0
- package/dist/desktop/desktop-gateway.js +146 -0
- package/dist/desktop/desktop-host.d.ts +48 -0
- package/dist/desktop/desktop-host.js +208 -0
- package/dist/desktop/desktop-stream.d.ts +36 -0
- package/dist/desktop/desktop-stream.js +231 -0
- package/dist/desktop/loopback-policy.d.ts +19 -0
- package/dist/desktop/loopback-policy.js +23 -0
- package/dist/desktop/open-url-channel.d.ts +15 -0
- package/dist/desktop/open-url-channel.js +55 -0
- package/dist/desktop/string-policy.d.ts +2 -0
- package/dist/desktop/string-policy.js +11 -0
- package/dist/framework-source.json +1 -0
- package/dist/installer/archive-entry.d.ts +6 -0
- package/dist/installer/archive-entry.js +14 -0
- package/dist/installer/command-artifact.d.ts +47 -0
- package/dist/installer/command-artifact.js +261 -0
- package/dist/installer/command-qualification-command.d.ts +12 -0
- package/dist/installer/command-qualification-command.js +71 -0
- package/dist/installer/hosted-runner.d.ts +4 -0
- package/dist/installer/hosted-runner.js +10 -0
- package/dist/installer/installed-payload.d.ts +29 -0
- package/dist/installer/installed-payload.js +312 -0
- package/dist/installer/installer-ci-bootstrap.d.ts +26 -0
- package/dist/installer/installer-ci-bootstrap.js +160 -0
- package/dist/installer/installer-ci-preflight.d.ts +1 -0
- package/dist/installer/installer-ci-preflight.js +49 -0
- package/dist/installer/installer-ci-worker.d.ts +1 -0
- package/dist/installer/installer-ci-worker.js +105 -0
- package/dist/installer/installer-extraction.d.ts +14 -0
- package/dist/installer/installer-extraction.js +289 -0
- package/dist/installer/installer-fetch-guard.d.ts +15 -0
- package/dist/installer/installer-fetch-guard.js +50 -0
- package/dist/installer/installer-identity.d.ts +23 -0
- package/dist/installer/installer-identity.js +286 -0
- package/dist/installer/installer-layout.d.ts +21 -0
- package/dist/installer/installer-layout.js +89 -0
- package/dist/installer/installer-observation.d.ts +64 -0
- package/dist/installer/installer-observation.js +473 -0
- package/dist/installer/installer-process-cleanup.d.ts +18 -0
- package/dist/installer/installer-process-cleanup.js +158 -0
- package/dist/installer/installer-qualification-command.d.ts +11 -0
- package/dist/installer/installer-qualification-command.js +71 -0
- package/dist/installer/installer-renderer-evidence.d.ts +43 -0
- package/dist/installer/installer-renderer-evidence.js +136 -0
- package/dist/installer/installer-upgrade-command.d.ts +37 -0
- package/dist/installer/installer-upgrade-command.js +172 -0
- package/dist/installer/installer-worker-guard.d.ts +21 -0
- package/dist/installer/installer-worker-guard.js +72 -0
- package/dist/installer/native-executable.d.ts +5 -0
- package/dist/installer/native-executable.js +21 -0
- package/dist/installer/upgrade-asset-download.d.ts +13 -0
- package/dist/installer/upgrade-asset-download.js +41 -0
- package/dist/installer/write-all.d.ts +6 -0
- package/dist/installer/write-all.js +11 -0
- package/dist/native/app-bundle.d.ts +28 -0
- package/dist/native/app-bundle.js +60 -0
- package/dist/native/cef-helper.d.ts +28 -0
- package/dist/native/cef-helper.js +402 -0
- package/dist/native/desktop-build-hook.d.ts +7 -0
- package/dist/native/desktop-build-hook.js +20 -0
- package/dist/native/electrobun-source-patch.d.ts +25 -0
- package/dist/native/electrobun-source-patch.js +93 -0
- package/dist/native/linux-cef-links.d.ts +2 -0
- package/dist/native/linux-cef-links.js +15 -0
- package/dist/native/native-secret-store.d.ts +27 -0
- package/dist/native/native-secret-store.js +70 -0
- package/dist/native/native-utilities.d.ts +24 -0
- package/dist/native/native-utilities.js +85 -0
- package/dist/native/partitioned-window.d.ts +34 -0
- package/dist/native/partitioned-window.js +44 -0
- package/dist/native/renderer-profile.d.ts +53 -0
- package/dist/native/renderer-profile.js +30 -0
- package/dist/native/secure-window.d.ts +38 -0
- package/dist/native/secure-window.js +77 -0
- package/dist/native/sidecar-services.d.ts +23 -0
- package/dist/native/sidecar-services.js +46 -0
- package/dist/native/sidecar.d.ts +81 -0
- package/dist/native/sidecar.js +250 -0
- package/dist/native/window-bootstrap.d.ts +24 -0
- package/dist/native/window-bootstrap.js +63 -0
- package/dist/native/window-options.d.ts +32 -0
- package/dist/native/window-options.js +23 -0
- package/dist/native/windows-build-hook-internal.d.ts +2 -0
- package/dist/native/windows-build-hook-internal.js +32 -0
- package/dist/native/windows-build-hook.d.ts +2 -0
- package/dist/native/windows-build-hook.js +12 -0
- package/dist/native/windows-runtime-patch-internal.d.ts +3 -0
- package/dist/native/windows-runtime-patch-internal.js +20 -0
- package/dist/native/windows-runtime-patch.d.ts +4 -0
- package/dist/native/windows-runtime-patch.js +12 -0
- package/dist/release/feed-release-cut.d.ts +23 -0
- package/dist/release/feed-release-cut.js +93 -0
- package/dist/release/feed-state.d.ts +25 -0
- package/dist/release/feed-state.js +81 -0
- package/dist/release/framework-package-publish.d.ts +21 -0
- package/dist/release/framework-package-publish.js +127 -0
- package/dist/release/framework-update.d.ts +30 -0
- package/dist/release/framework-update.js +139 -0
- package/dist/release/github-cli.d.ts +6 -0
- package/dist/release/github-cli.js +16 -0
- package/dist/release/github-release-assets.d.ts +3 -0
- package/dist/release/github-release-assets.js +24 -0
- package/dist/release/github-release-cut.d.ts +14 -0
- package/dist/release/github-release-cut.js +174 -0
- package/dist/release/github-release-lookup.d.ts +7 -0
- package/dist/release/github-release-lookup.js +29 -0
- package/dist/release/github-release-promotion.d.ts +10 -0
- package/dist/release/github-release-promotion.js +78 -0
- package/dist/release/github-release-provenance.d.ts +9 -0
- package/dist/release/github-release-provenance.js +27 -0
- package/dist/release/github-release-publisher.d.ts +9 -0
- package/dist/release/github-release-publisher.js +63 -0
- package/dist/release/github-release-qualification.d.ts +12 -0
- package/dist/release/github-release-qualification.js +80 -0
- package/dist/release/local-provenance.d.ts +24 -0
- package/dist/release/local-provenance.js +72 -0
- package/dist/release/local-release.d.ts +133 -0
- package/dist/release/local-release.js +387 -0
- package/dist/release/macos-dmg.d.ts +22 -0
- package/dist/release/macos-dmg.js +91 -0
- package/dist/release/release-artifact.d.ts +6 -0
- package/dist/release/release-artifact.js +38 -0
- package/dist/release/release-assets-plan.d.ts +14 -0
- package/dist/release/release-assets-plan.js +65 -0
- package/dist/release/release-config.d.ts +76 -0
- package/dist/release/release-config.js +180 -0
- package/dist/release/release-cut-command.d.ts +13 -0
- package/dist/release/release-cut-command.js +39 -0
- package/dist/release/release-cut.d.ts +54 -0
- package/dist/release/release-cut.js +76 -0
- package/dist/release/release-descriptor-staging.d.ts +34 -0
- package/dist/release/release-descriptor-staging.js +147 -0
- package/dist/release/release-finalize.d.ts +16 -0
- package/dist/release/release-finalize.js +104 -0
- package/dist/release/release-promotion-command.d.ts +12 -0
- package/dist/release/release-promotion-command.js +28 -0
- package/dist/release/release-promotion.d.ts +29 -0
- package/dist/release/release-promotion.js +57 -0
- package/dist/release/release-publication.d.ts +33 -0
- package/dist/release/release-publication.js +138 -0
- package/dist/release/release-publish-command.d.ts +7 -0
- package/dist/release/release-publish-command.js +91 -0
- package/dist/release/release-qualification.d.ts +106 -0
- package/dist/release/release-qualification.js +135 -0
- package/dist/release/release-staging.d.ts +9 -0
- package/dist/release/release-staging.js +61 -0
- package/dist/release/release-steps.d.ts +38 -0
- package/dist/release/release-steps.js +147 -0
- package/dist/release/retained-release-build.d.ts +19 -0
- package/dist/release/retained-release-build.js +122 -0
- package/dist/shell/app-shell.d.ts +61 -0
- package/dist/shell/app-shell.js +306 -0
- package/dist/shell/app-utilities.d.ts +122 -0
- package/dist/shell/app-utilities.js +334 -0
- package/dist/shell/application-menu-commands.d.ts +5 -0
- package/dist/shell/application-menu-commands.js +11 -0
- package/dist/shell/application-menu.d.ts +61 -0
- package/dist/shell/application-menu.js +208 -0
- package/dist/shell/help-shortcuts.d.ts +12 -0
- package/dist/shell/help-shortcuts.js +22 -0
- package/dist/shell/navigation-drawer.d.ts +12 -0
- package/dist/shell/navigation-drawer.js +42 -0
- package/dist/shell/settings-sections.d.ts +31 -0
- package/dist/shell/settings-sections.js +50 -0
- package/dist/shell/shortcut-platform.d.ts +17 -0
- package/dist/shell/shortcut-platform.js +25 -0
- package/dist/update-helper.bundle.js +260 -0
- package/dist/updates/channel-update-manager.d.ts +46 -0
- package/dist/updates/channel-update-manager.js +114 -0
- package/dist/updates/desktop-updater.d.ts +104 -0
- package/dist/updates/desktop-updater.js +345 -0
- package/dist/updates/release-feed.d.ts +61 -0
- package/dist/updates/release-feed.js +111 -0
- package/dist/updates/release-location.d.ts +9 -0
- package/dist/updates/release-location.js +80 -0
- package/dist/updates/release-version.d.ts +12 -0
- package/dist/updates/release-version.js +43 -0
- package/dist/updates/signed-release.d.ts +63 -0
- package/dist/updates/signed-release.js +162 -0
- package/dist/updates/stable-file.d.ts +10 -0
- package/dist/updates/stable-file.js +22 -0
- package/dist/updates/update-adapter.d.ts +57 -0
- package/dist/updates/update-adapter.js +72 -0
- package/dist/updates/update-arm.d.ts +24 -0
- package/dist/updates/update-arm.js +95 -0
- package/dist/updates/update-channel-store.d.ts +8 -0
- package/dist/updates/update-channel-store.js +72 -0
- package/dist/updates/update-discovery.d.ts +13 -0
- package/dist/updates/update-discovery.js +56 -0
- package/dist/updates/update-download.d.ts +14 -0
- package/dist/updates/update-download.js +67 -0
- package/dist/updates/update-exclusive-rename.d.ts +2 -0
- package/dist/updates/update-exclusive-rename.js +52 -0
- package/dist/updates/update-extraction.d.ts +18 -0
- package/dist/updates/update-extraction.js +183 -0
- package/dist/updates/update-handoff-plan.d.ts +22 -0
- package/dist/updates/update-handoff-plan.js +28 -0
- package/dist/updates/update-helper.d.ts +24 -0
- package/dist/updates/update-helper.js +56 -0
- package/dist/updates/update-launch.d.ts +5 -0
- package/dist/updates/update-launch.js +27 -0
- package/dist/updates/update-manager.d.ts +40 -0
- package/dist/updates/update-manager.js +83 -0
- package/dist/updates/update-process-fence.d.ts +10 -0
- package/dist/updates/update-process-fence.js +114 -0
- package/dist/updates/update-resume.d.ts +13 -0
- package/dist/updates/update-resume.js +34 -0
- package/dist/updates/update-shutdown.d.ts +15 -0
- package/dist/updates/update-shutdown.js +29 -0
- package/dist/updates/update-state.d.ts +30 -0
- package/dist/updates/update-state.js +18 -0
- package/dist/updates/update-swap-stage.d.ts +27 -0
- package/dist/updates/update-swap-stage.js +58 -0
- package/dist/updates/update-swap.d.ts +10 -0
- package/dist/updates/update-swap.js +30 -0
- package/dist/views/app-about.d.ts +22 -0
- package/dist/views/app-about.js +43 -0
- package/dist/views/app-appearance.d.ts +11 -0
- package/dist/views/app-appearance.js +42 -0
- package/dist/views/app-help.d.ts +17 -0
- package/dist/views/app-help.js +42 -0
- package/dist/views/app-settings.d.ts +26 -0
- package/dist/views/app-settings.js +97 -0
- package/dist/views/appearance-surface.d.ts +9 -0
- package/dist/views/appearance-surface.js +334 -0
- package/dist/views/update-surface.d.ts +34 -0
- package/dist/views/update-surface.js +64 -0
- package/package.json +374 -4
- package/src/app/application.tsx +138 -0
- package/src/appearance/appearance-host.tsx +205 -0
- package/src/appearance/appearance-preferences.ts +287 -0
- package/src/appearance/composition.ts +29 -0
- package/src/appearance/custom-theme-import.ts +424 -0
- package/src/appearance/custom-theme-library.ts +600 -0
- package/src/appearance/editor.ts +94 -0
- package/src/appearance/theme-file-importer.ts +103 -0
- package/src/appearance/theme-record-adapter.ts +106 -0
- package/src/appearance/theme-registry.ts +20 -0
- package/src/appearance/window-surface.ts +18 -0
- package/src/desktop/client-assets.ts +75 -0
- package/src/native/electrobun-cef-main-frame-bridges.patch +63 -0
- package/src/native/electrobun-windows-shortcut-com.patch +923 -0
- package/src/native/renderer-profile.ts +27 -0
- package/src/native/window-options.ts +24 -0
- package/src/shell/app-shell.tsx +294 -0
- package/src/shell/app-utilities.tsx +437 -0
- package/src/shell/help-shortcuts.ts +24 -0
- package/src/shell/navigation-drawer.tsx +36 -0
- package/src/shell/settings-sections.ts +74 -0
- package/src/shell/shortcut-platform.ts +35 -0
- package/src/updates/release-version.ts +57 -0
- package/src/updates/update-adapter.ts +129 -0
- package/src/updates/update-state.ts +34 -0
- package/src/views/app-about.tsx +44 -0
- package/src/views/app-appearance.tsx +32 -0
- package/src/views/app-help.tsx +43 -0
- package/src/views/app-settings.tsx +88 -0
- package/src/views/appearance-surface.tsx +427 -0
- package/src/views/update-surface.tsx +85 -0
- package/templates/application/.gitattributes +1 -0
- package/templates/application/.github/workflows/release-assets.yml +29 -0
- package/templates/application/.github/workflows/release-finalize.yml +29 -0
- package/templates/application/.github/workflows/release-please.yml +19 -0
- package/templates/application/.github/workflows/release.yml +29 -0
- package/templates/application/.github/workflows/validation.yml +28 -0
- package/templates/application/.oxfmtrc.json +6 -0
- package/templates/application/.oxlintrc.json +48 -0
- package/templates/application/.release-please-manifest.json +3 -0
- package/templates/application/README.md +47 -0
- package/templates/application/electrobun.config.ts +22 -0
- package/templates/application/release-please-config.json +12 -0
- package/templates/application/scripts/app-version.ts +9 -0
- package/templates/application/scripts/build-desktop.ts +34 -0
- package/templates/application/scripts/secure-build.ts +1 -0
- package/templates/application/scripts/stage-release.ts +21 -0
- package/templates/application/src/bun/index.ts +80 -0
- package/templates/application/src/electrobun.d.ts +27 -0
- package/templates/application/src/web/index.html +12 -0
- package/templates/application/src/web/main.tsx +97 -0
- package/templates/application/src/web/public/icon.svg +1 -0
- package/templates/application/src/web/style.css +3 -0
- package/templates/application/tests/app-config.test.ts +9 -0
- package/templates/application/tsconfig.json +15 -0
- package/templates/application/vite.config.ts +10 -0
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Custom theme import: turn an uploaded theme file into a runtime variant.
|
|
3
|
+
*
|
|
4
|
+
* The import is deliberately permissive. A file may carry the published
|
|
5
|
+
* canonical schema (17 surface roles plus an ANSI ramp) or any subset of it;
|
|
6
|
+
* missing roles are filled from the default theme of the same appearance, and
|
|
7
|
+
* text roles that cannot reach a readable contrast against their own
|
|
8
|
+
* background are repaired, with every adjustment reported back to the UI
|
|
9
|
+
* instead of silently altering the palette. Nothing here enforces provenance
|
|
10
|
+
* or distribution terms: an imported theme is the user's own copy for their
|
|
11
|
+
* own machine.
|
|
12
|
+
*/
|
|
13
|
+
import {
|
|
14
|
+
colorToHex,
|
|
15
|
+
contrastRatio,
|
|
16
|
+
ensureContrast,
|
|
17
|
+
parseColor as parseHex,
|
|
18
|
+
} from '@adea-ai/ui/lib/accent-roles'
|
|
19
|
+
import {
|
|
20
|
+
defaultThemeRecord,
|
|
21
|
+
editorRolesHex,
|
|
22
|
+
oklchToHex,
|
|
23
|
+
parseOklchColor,
|
|
24
|
+
shadcnDestructiveProjection,
|
|
25
|
+
shadcnVariables,
|
|
26
|
+
syntaxRolesHex,
|
|
27
|
+
toXtermTheme,
|
|
28
|
+
} from '@adea-ai/ui/lib/theme-projection'
|
|
29
|
+
import type { AdeaTheme } from '@adea-ai/ui/lib/theme-records'
|
|
30
|
+
import {
|
|
31
|
+
flatVariantTokens,
|
|
32
|
+
setCustomThemes,
|
|
33
|
+
validateThemeRegistry,
|
|
34
|
+
type AppearanceStorage,
|
|
35
|
+
type CustomThemeStored,
|
|
36
|
+
type StoredThemeColors as ThemeColors,
|
|
37
|
+
type StoredThemeVariant as ThemeVariant,
|
|
38
|
+
} from './custom-theme-library'
|
|
39
|
+
|
|
40
|
+
const CANONICAL_COLOR_KEYS = [
|
|
41
|
+
'background',
|
|
42
|
+
'foreground',
|
|
43
|
+
'surface',
|
|
44
|
+
'surfaceElevated',
|
|
45
|
+
'surfaceHover',
|
|
46
|
+
'surfaceActive',
|
|
47
|
+
'border',
|
|
48
|
+
'borderMuted',
|
|
49
|
+
'text',
|
|
50
|
+
'textMuted',
|
|
51
|
+
'textSubtle',
|
|
52
|
+
'accent',
|
|
53
|
+
'accentForeground',
|
|
54
|
+
'success',
|
|
55
|
+
'warning',
|
|
56
|
+
'error',
|
|
57
|
+
'info',
|
|
58
|
+
] as const
|
|
59
|
+
|
|
60
|
+
const ANSI_KEYS = [
|
|
61
|
+
'black',
|
|
62
|
+
'red',
|
|
63
|
+
'green',
|
|
64
|
+
'yellow',
|
|
65
|
+
'blue',
|
|
66
|
+
'magenta',
|
|
67
|
+
'cyan',
|
|
68
|
+
'white',
|
|
69
|
+
'brightBlack',
|
|
70
|
+
'brightRed',
|
|
71
|
+
'brightGreen',
|
|
72
|
+
'brightYellow',
|
|
73
|
+
'brightBlue',
|
|
74
|
+
'brightMagenta',
|
|
75
|
+
'brightCyan',
|
|
76
|
+
'brightWhite',
|
|
77
|
+
] as const
|
|
78
|
+
|
|
79
|
+
/** The published syntax-role mapping, used when a file needs roles derived. */
|
|
80
|
+
const SYNTAX_SOURCES = {
|
|
81
|
+
keyword: 'magenta',
|
|
82
|
+
string: 'green',
|
|
83
|
+
number: 'yellow',
|
|
84
|
+
comment: 'brightBlack',
|
|
85
|
+
function: 'blue',
|
|
86
|
+
variable: 'cyan',
|
|
87
|
+
type: 'cyan',
|
|
88
|
+
tag: 'red',
|
|
89
|
+
attribute: 'yellow',
|
|
90
|
+
operator: 'foreground',
|
|
91
|
+
heading: 'magenta',
|
|
92
|
+
link: 'blue',
|
|
93
|
+
diffAdd: 'green',
|
|
94
|
+
diffDelete: 'red',
|
|
95
|
+
diffHunk: 'brightBlack',
|
|
96
|
+
searchMatch: 'yellow',
|
|
97
|
+
} as const
|
|
98
|
+
|
|
99
|
+
export type CustomThemeImportResult =
|
|
100
|
+
| { ok: true; theme: CustomThemeStored }
|
|
101
|
+
| { ok: false; error: string }
|
|
102
|
+
|
|
103
|
+
function slug(value: string): string {
|
|
104
|
+
return (
|
|
105
|
+
value
|
|
106
|
+
.toLowerCase()
|
|
107
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
108
|
+
.replace(/^-+|-+$/g, '')
|
|
109
|
+
.slice(0, 32) || 'theme'
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function normalizeHex(value: string): string {
|
|
114
|
+
const parsed = parseHex(value)
|
|
115
|
+
return parsed
|
|
116
|
+
? `#${[parsed.r, parsed.g, parsed.b].map((byte) => byte.toString(16).padStart(2, '0')).join('')}`
|
|
117
|
+
: value
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function isHex(value: unknown): value is string {
|
|
121
|
+
return typeof value === 'string' && parseHex(value) !== undefined
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Repair one foreground/background pair to the readable floor, reporting it. */
|
|
125
|
+
function repairToFloor(
|
|
126
|
+
foreground: string,
|
|
127
|
+
background: string,
|
|
128
|
+
notes: string[],
|
|
129
|
+
role: string
|
|
130
|
+
): string {
|
|
131
|
+
const front = parseHex(foreground)
|
|
132
|
+
const back = parseHex(background)
|
|
133
|
+
if (!front || !back) return foreground
|
|
134
|
+
if (contrastRatio(front, back) >= 4.5) return foreground
|
|
135
|
+
// The host repair loops contrast margins and falls back to a guaranteed
|
|
136
|
+
// foreground, so an import can never ship unreadable text.
|
|
137
|
+
const repaired = ensureContrast(front, back, 4.5)
|
|
138
|
+
notes.push(`“${role}” was adjusted for readable contrast.`)
|
|
139
|
+
return colorToHex(repaired)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function hexOf(value: string): string {
|
|
143
|
+
const parsed = parseOklchColor(value)
|
|
144
|
+
return parsed ? oklchToHex(parsed) : value
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Project a validated canonical theme into the runtime variant shape, the same
|
|
149
|
+
* adapters the generated built-in registry uses.
|
|
150
|
+
*/
|
|
151
|
+
function projectCanonical(theme: AdeaTheme): ThemeVariant {
|
|
152
|
+
const action = shadcnDestructiveProjection(theme)
|
|
153
|
+
const shadcn = {
|
|
154
|
+
...shadcnVariables(theme),
|
|
155
|
+
'--destructive-action': action.fill,
|
|
156
|
+
'--destructive-action-foreground': action.foreground,
|
|
157
|
+
}
|
|
158
|
+
const SHADCN_TO_COLOR = {
|
|
159
|
+
background: 'background',
|
|
160
|
+
foreground: 'foreground',
|
|
161
|
+
card: 'card',
|
|
162
|
+
'card-foreground': 'cardForeground',
|
|
163
|
+
popover: 'popover',
|
|
164
|
+
'popover-foreground': 'popoverForeground',
|
|
165
|
+
primary: 'primary',
|
|
166
|
+
'primary-foreground': 'primaryForeground',
|
|
167
|
+
secondary: 'secondary',
|
|
168
|
+
'secondary-foreground': 'secondaryForeground',
|
|
169
|
+
muted: 'muted',
|
|
170
|
+
'muted-foreground': 'mutedForeground',
|
|
171
|
+
accent: 'accent',
|
|
172
|
+
'accent-foreground': 'accentForeground',
|
|
173
|
+
destructive: 'destructive',
|
|
174
|
+
'destructive-action': 'destructiveAction',
|
|
175
|
+
'destructive-action-foreground': 'destructiveActionForeground',
|
|
176
|
+
success: 'success',
|
|
177
|
+
border: 'border',
|
|
178
|
+
input: 'input',
|
|
179
|
+
ring: 'ring',
|
|
180
|
+
} as const
|
|
181
|
+
const colors = Object.fromEntries(
|
|
182
|
+
Object.entries(SHADCN_TO_COLOR).map(([name, property]) => [
|
|
183
|
+
property,
|
|
184
|
+
hexOf((shadcn as Record<string, string>)[`--${name}`]!),
|
|
185
|
+
])
|
|
186
|
+
) as unknown as ThemeColors
|
|
187
|
+
const terminalSource = toXtermTheme(theme)
|
|
188
|
+
const ansi = [
|
|
189
|
+
terminalSource.black,
|
|
190
|
+
terminalSource.red,
|
|
191
|
+
terminalSource.green,
|
|
192
|
+
terminalSource.yellow,
|
|
193
|
+
terminalSource.blue,
|
|
194
|
+
terminalSource.magenta,
|
|
195
|
+
terminalSource.cyan,
|
|
196
|
+
terminalSource.white,
|
|
197
|
+
terminalSource.brightBlack,
|
|
198
|
+
terminalSource.brightRed,
|
|
199
|
+
terminalSource.brightGreen,
|
|
200
|
+
terminalSource.brightYellow,
|
|
201
|
+
terminalSource.brightBlue,
|
|
202
|
+
terminalSource.brightMagenta,
|
|
203
|
+
terminalSource.brightCyan,
|
|
204
|
+
terminalSource.brightWhite,
|
|
205
|
+
].map((value) => hexOf(value))
|
|
206
|
+
let editor: Record<string, string>
|
|
207
|
+
try {
|
|
208
|
+
editor = { ...editorRolesHex(theme) }
|
|
209
|
+
} catch {
|
|
210
|
+
// Some palettes cannot reach the 4.5:1 syntax floor from their own ramp;
|
|
211
|
+
// fall back to the raw roles repaired toward the floor.
|
|
212
|
+
const raw = syntaxRolesHex(theme)
|
|
213
|
+
editor = Object.fromEntries(
|
|
214
|
+
Object.entries(raw)
|
|
215
|
+
.filter(([role]) => role in SYNTAX_SOURCES)
|
|
216
|
+
.map(([role, value]) => [role, hexOf(value)])
|
|
217
|
+
)
|
|
218
|
+
}
|
|
219
|
+
const charts = {
|
|
220
|
+
chart1: ansi[4]!,
|
|
221
|
+
chart2: ansi[5]!,
|
|
222
|
+
chart3: ansi[6]!,
|
|
223
|
+
chart4: ansi[2]!,
|
|
224
|
+
chart5: ansi[3]!,
|
|
225
|
+
chart6: ansi[1]!,
|
|
226
|
+
}
|
|
227
|
+
return {
|
|
228
|
+
id: theme.id,
|
|
229
|
+
familyId: 'imported',
|
|
230
|
+
familyName: 'Imported',
|
|
231
|
+
name: theme.name,
|
|
232
|
+
appearance: theme.appearance,
|
|
233
|
+
colors,
|
|
234
|
+
terminal: {
|
|
235
|
+
background: hexOf(terminalSource.background),
|
|
236
|
+
foreground: hexOf(terminalSource.foreground),
|
|
237
|
+
cursor: hexOf(terminalSource.cursor),
|
|
238
|
+
selection: hexOf(terminalSource.selectionBackground),
|
|
239
|
+
ansi,
|
|
240
|
+
},
|
|
241
|
+
editor: editor as ThemeVariant['editor'],
|
|
242
|
+
charts,
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Parse and store an uploaded theme. The only hard failure is unparseable
|
|
248
|
+
* JSON: everything else normalizes, fills from the same-appearance default,
|
|
249
|
+
* and reports what it had to adjust.
|
|
250
|
+
*/
|
|
251
|
+
export function importCustomTheme(
|
|
252
|
+
text: string,
|
|
253
|
+
storage: AppearanceStorage | undefined,
|
|
254
|
+
existing: readonly CustomThemeStored[]
|
|
255
|
+
): CustomThemeImportResult {
|
|
256
|
+
let source: unknown
|
|
257
|
+
try {
|
|
258
|
+
source = JSON.parse(text)
|
|
259
|
+
} catch {
|
|
260
|
+
return { ok: false, error: 'That file is not valid JSON.' }
|
|
261
|
+
}
|
|
262
|
+
const record = (
|
|
263
|
+
typeof source === 'object' && source !== null && 'theme' in (source as Record<string, unknown>)
|
|
264
|
+
? (source as { theme: unknown }).theme
|
|
265
|
+
: source
|
|
266
|
+
) as Record<string, unknown>
|
|
267
|
+
if (typeof record !== 'object' || record === null) {
|
|
268
|
+
return { ok: false, error: 'That file does not describe a theme.' }
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const notes: string[] = []
|
|
272
|
+
const rawColors = (record.colors ?? {}) as Record<string, unknown>
|
|
273
|
+
const appearance: 'light' | 'dark' =
|
|
274
|
+
record.appearance === 'light' || record.appearance === 'dark'
|
|
275
|
+
? record.appearance
|
|
276
|
+
: rawColors.background === undefined
|
|
277
|
+
? 'dark'
|
|
278
|
+
: 'light'
|
|
279
|
+
const base = defaultThemeRecord(appearance)
|
|
280
|
+
const name =
|
|
281
|
+
typeof record.name === 'string' && record.name.trim().length > 0
|
|
282
|
+
? record.name.trim().slice(0, 64)
|
|
283
|
+
: typeof record.label === 'string' && record.label.trim().length > 0
|
|
284
|
+
? record.label.trim().slice(0, 64)
|
|
285
|
+
: 'Imported theme'
|
|
286
|
+
|
|
287
|
+
// Fill the canonical surface roles from whatever the file provides, then
|
|
288
|
+
// from the same-appearance default for anything missing.
|
|
289
|
+
const colors: Record<string, string> = {}
|
|
290
|
+
for (const key of CANONICAL_COLOR_KEYS) {
|
|
291
|
+
const value = rawColors[key]
|
|
292
|
+
if (isHex(value)) colors[key] = normalizeHex(value)
|
|
293
|
+
}
|
|
294
|
+
// Users name the main text role 'foreground'; the canonical schema calls it
|
|
295
|
+
// 'text'. Accept both before filling anything from the default theme.
|
|
296
|
+
if (colors.text === undefined && isHex(rawColors.foreground)) {
|
|
297
|
+
colors.text = normalizeHex(rawColors.foreground)
|
|
298
|
+
}
|
|
299
|
+
if (colors.textMuted === undefined && isHex(rawColors.mutedForeground)) {
|
|
300
|
+
colors.textMuted = normalizeHex(rawColors.mutedForeground)
|
|
301
|
+
}
|
|
302
|
+
const filled = CANONICAL_COLOR_KEYS.filter((key) => colors[key] === undefined)
|
|
303
|
+
if (filled.length > 0) {
|
|
304
|
+
for (const key of filled) colors[key] = base.colors[key as keyof typeof base.colors]
|
|
305
|
+
notes.push('Missing roles were filled from the default theme.')
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// Text roles must stay readable against the background we actually ship.
|
|
309
|
+
colors.text = repairToFloor(colors.text!, colors.background!, notes, 'text')
|
|
310
|
+
colors.textMuted = repairToFloor(colors.textMuted!, colors.background!, notes, 'muted text')
|
|
311
|
+
colors.textSubtle = repairToFloor(colors.textSubtle!, colors.background!, notes, 'subtle text')
|
|
312
|
+
|
|
313
|
+
const ansiRecord = (record.ansi ?? {}) as Record<string, unknown>
|
|
314
|
+
const ansi = ANSI_KEYS.map((key) => {
|
|
315
|
+
const value = ansiRecord[key]
|
|
316
|
+
return isHex(value) ? normalizeHex(value) : base.ansi[key]
|
|
317
|
+
})
|
|
318
|
+
if (Object.keys(ansiRecord).length === 0)
|
|
319
|
+
notes.push('No ANSI ramp in the file; the default ramp was kept.')
|
|
320
|
+
|
|
321
|
+
const canonical: AdeaTheme = {
|
|
322
|
+
id: 'pending',
|
|
323
|
+
name,
|
|
324
|
+
appearance,
|
|
325
|
+
colors: colors as unknown as AdeaTheme['colors'],
|
|
326
|
+
ansi: Object.fromEntries(
|
|
327
|
+
ANSI_KEYS.map((key, index) => [key, ansi[index]!])
|
|
328
|
+
) as unknown as AdeaTheme['ansi'],
|
|
329
|
+
cursor: isHex(record.cursor) ? normalizeHex(record.cursor) : base.cursor,
|
|
330
|
+
selection: isHex(record.selection) ? normalizeHex(record.selection) : base.selection,
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
let variant: ThemeVariant
|
|
334
|
+
try {
|
|
335
|
+
variant = projectCanonical(canonical)
|
|
336
|
+
} catch {
|
|
337
|
+
// The adapters refuse unencodable roles; fall back to a direct host
|
|
338
|
+
// projection so the import still succeeds with a warning.
|
|
339
|
+
variant = projectHostFallback(name, appearance, canonical.colors, ansi)
|
|
340
|
+
notes.push('Syntax roles were approximated from the ANSI ramp.')
|
|
341
|
+
}
|
|
342
|
+
variant = { ...variant, id: `custom-${slug(name)}-${Date.now().toString(36)}`, name }
|
|
343
|
+
|
|
344
|
+
const issues = validateThemeRegistry([variant]).filter((issue) => issue.severity === 'error')
|
|
345
|
+
for (const issue of issues) notes.push(`${issue.variantId}: ${issue.message}`)
|
|
346
|
+
|
|
347
|
+
const stored: CustomThemeStored = {
|
|
348
|
+
id: variant.id,
|
|
349
|
+
name: variant.name,
|
|
350
|
+
appearance,
|
|
351
|
+
importedAt: new Date().toISOString(),
|
|
352
|
+
variant,
|
|
353
|
+
flatTokens: flatVariantTokens(variant),
|
|
354
|
+
notes,
|
|
355
|
+
}
|
|
356
|
+
if (!setCustomThemes([...existing, stored], storage))
|
|
357
|
+
return { ok: false, error: 'The theme could not be saved. Check your storage and try again.' }
|
|
358
|
+
return { ok: true, theme: stored }
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/** Direct host projection for inputs the canonical adapters reject. */
|
|
362
|
+
function projectHostFallback(
|
|
363
|
+
name: string,
|
|
364
|
+
appearance: 'light' | 'dark',
|
|
365
|
+
colors: AdeaTheme['colors'],
|
|
366
|
+
ansi: readonly string[]
|
|
367
|
+
): ThemeVariant {
|
|
368
|
+
const ramp = (index: number): string => ansi[index] ?? colors.foreground
|
|
369
|
+
const editor = Object.fromEntries(
|
|
370
|
+
Object.entries(SYNTAX_SOURCES).map(([role, source]) => {
|
|
371
|
+
const value =
|
|
372
|
+
source === 'foreground'
|
|
373
|
+
? colors.foreground
|
|
374
|
+
: ramp(ANSI_KEYS.indexOf(source as (typeof ANSI_KEYS)[number]))
|
|
375
|
+
return [role, repairToFloor(value, colors.background, [], role)]
|
|
376
|
+
})
|
|
377
|
+
)
|
|
378
|
+
return {
|
|
379
|
+
id: 'pending',
|
|
380
|
+
familyId: 'imported',
|
|
381
|
+
familyName: 'Imported',
|
|
382
|
+
name,
|
|
383
|
+
appearance,
|
|
384
|
+
colors: {
|
|
385
|
+
background: colors.background,
|
|
386
|
+
foreground: colors.foreground,
|
|
387
|
+
card: colors.surface,
|
|
388
|
+
cardForeground: colors.text,
|
|
389
|
+
popover: colors.surfaceElevated,
|
|
390
|
+
popoverForeground: colors.text,
|
|
391
|
+
primary: colors.accent,
|
|
392
|
+
primaryForeground: colors.accentForeground,
|
|
393
|
+
secondary: colors.surfaceHover,
|
|
394
|
+
secondaryForeground: colors.text,
|
|
395
|
+
muted: colors.surfaceHover,
|
|
396
|
+
mutedForeground: colors.textMuted,
|
|
397
|
+
accent: colors.surfaceActive,
|
|
398
|
+
accentForeground: colors.text,
|
|
399
|
+
destructive: colors.error,
|
|
400
|
+
destructiveAction: colors.error,
|
|
401
|
+
destructiveActionForeground: colors.accentForeground,
|
|
402
|
+
success: colors.success,
|
|
403
|
+
border: colors.border,
|
|
404
|
+
input: colors.border,
|
|
405
|
+
ring: colors.accent,
|
|
406
|
+
},
|
|
407
|
+
terminal: {
|
|
408
|
+
background: colors.background,
|
|
409
|
+
foreground: colors.foreground,
|
|
410
|
+
cursor: ramp(6),
|
|
411
|
+
selection: ramp(0),
|
|
412
|
+
ansi: [...ansi],
|
|
413
|
+
},
|
|
414
|
+
editor: editor as ThemeVariant['editor'],
|
|
415
|
+
charts: {
|
|
416
|
+
chart1: ramp(4),
|
|
417
|
+
chart2: ramp(5),
|
|
418
|
+
chart3: ramp(6),
|
|
419
|
+
chart4: ramp(2),
|
|
420
|
+
chart5: ramp(3),
|
|
421
|
+
chart6: ramp(1),
|
|
422
|
+
},
|
|
423
|
+
}
|
|
424
|
+
}
|