@adea-ai/app-framework 0.37.0 → 0.37.2
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/dist/app/create-application.js +1 -1
- package/dist/appearance/appearance-host.js +3 -2
- package/dist/appearance/custom-theme-import.js +3 -1
- package/dist/appearance/custom-theme-library.d.ts +6 -185
- package/dist/appearance/custom-theme-library.js +3 -621
- package/dist/appearance/theme-library-mutation.d.ts +42 -0
- package/dist/appearance/theme-library-mutation.js +172 -0
- package/dist/appearance/theme-library-schema.d.ts +108 -0
- package/dist/appearance/theme-library-schema.js +189 -0
- package/dist/appearance/theme-library-store.d.ts +61 -0
- package/dist/appearance/theme-library-store.js +268 -0
- package/dist/appearance/theme-record-adapter.js +3 -1
- package/dist/appearance/theme-registry.js +2 -1
- package/dist/cli/framework-update-cli.js +1 -1
- package/dist/cli/macos-signing-cli.js +1 -1
- package/dist/cli/release-assets-plan-cli.js +1 -1
- package/dist/cli/release-cut-cli.js +2 -2
- package/dist/cli/release-descriptor-staging-cli.js +2 -2
- package/dist/cli/release-promote-cli.js +1 -1
- package/dist/cli/release-publish-cli.js +1 -1
- package/dist/cli/release-sign-cli.js +1 -1
- package/dist/cli/release-step-cli.js +1 -1
- package/dist/cli/update-helper-cli.js +1 -1
- package/dist/cli/windows-installer-build-cli.js +1 -1
- package/dist/cli/windows-runtime-patch-cli.js +1 -1
- package/dist/desktop/client-assets.js +1 -1
- package/dist/desktop/desktop-client.d.ts +1 -1
- package/dist/desktop/desktop-gateway.js +2 -2
- package/dist/desktop/desktop-host.js +6 -6
- package/dist/desktop/desktop-stream.js +1 -1
- package/dist/framework-source.json +1 -1
- package/dist/installer/command-qualification-command.js +2 -2
- package/dist/installer/installed-payload.js +4 -4
- package/dist/installer/{installer-archive.js → installer-archive-members.js} +2 -2
- package/dist/installer/installer-ci-worker.js +2 -2
- package/dist/installer/installer-extraction.js +3 -3
- package/dist/installer/installer-fetch-guard.d.ts +1 -1
- package/dist/installer/installer-identity.js +2 -2
- package/dist/installer/installer-observation.d.ts +1 -1
- package/dist/installer/installer-observation.js +5 -5
- package/dist/installer/installer-process-cleanup.js +1 -1
- package/dist/installer/installer-qualification-command.js +3 -3
- package/dist/installer/installer-renderer-evidence.js +1 -1
- package/dist/installer/installer-upgrade-command.d.ts +2 -2
- package/dist/installer/installer-upgrade-command.js +7 -7
- package/dist/installer/linux-process-group.js +1 -1
- package/dist/installer/upgrade-asset-download.d.ts +1 -1
- package/dist/installer/upgrade-asset-download.js +2 -2
- package/dist/native/desktop-build.js +1 -1
- package/dist/native/posix-tree-removal.d.ts +1 -1
- package/dist/native/secure-window.js +1 -1
- package/dist/native/windows-build-hook.js +1 -1
- package/dist/native/windows-extractor-build.js +1 -1
- package/dist/release/feed-release-cut.d.ts +1 -1
- package/dist/release/feed-state.d.ts +2 -2
- package/dist/release/feed-state.js +4 -4
- package/dist/release/github-release-cut.js +3 -3
- package/dist/release/github-release-promotion.js +2 -2
- package/dist/release/github-release-publisher.js +1 -1
- package/dist/release/github-release-qualification.js +1 -1
- package/dist/release/local-release.d.ts +2 -2
- package/dist/release/local-release.js +7 -7
- package/dist/release/qualification-run.js +1 -1
- package/dist/release/release-artifact.d.ts +1 -1
- package/dist/release/release-artifact.js +2 -2
- package/dist/release/release-assets-plan.js +2 -2
- package/dist/release/release-config.d.ts +1 -1
- package/dist/release/release-config.js +3 -3
- package/dist/release/release-cut-command.js +1 -1
- package/dist/release/release-descriptor-staging.js +5 -5
- package/dist/release/release-finalize.js +3 -3
- package/dist/release/release-promotion-command.js +2 -2
- package/dist/release/release-promotion.js +1 -1
- package/dist/release/release-publication.d.ts +1 -1
- package/dist/release/release-publication.js +3 -3
- package/dist/release/release-publish-command.js +4 -4
- package/dist/release/release-steps.js +2 -2
- package/dist/release/retained-release-build.js +2 -2
- package/dist/shell/app-utilities.js +2 -2
- package/dist/update-helper.bundle.js +18 -18
- package/dist/updates/channel-update-manager.d.ts +3 -3
- package/dist/updates/channel-update-manager.js +2 -2
- package/dist/updates/desktop-updater.d.ts +10 -83
- package/dist/updates/desktop-updater.js +16 -219
- package/dist/updates/{packaged-release-config.js → feed/packaged-release-config.js} +5 -5
- package/dist/updates/{release-feed.js → feed/release-feed.js} +2 -2
- package/dist/updates/{release-location.js → feed/release-location.js} +2 -2
- package/dist/updates/{release-version.js → feed/release-version.js} +1 -1
- package/dist/updates/{signed-release.js → feed/signed-release.js} +2 -2
- package/dist/updates/{update-discovery.js → feed/update-discovery.js} +3 -3
- package/dist/updates/helper/launch-gate-recovery.d.ts +8 -0
- package/dist/updates/{update-resume.js → helper/launch-gate-recovery.js} +13 -423
- package/dist/updates/helper/resume-staging.d.ts +22 -0
- package/dist/updates/helper/resume-staging.js +180 -0
- package/dist/updates/{update-helper.d.ts → helper/update-helper.d.ts} +1 -1
- package/dist/updates/{update-helper.js → helper/update-helper.js} +9 -9
- package/dist/updates/{update-resume.d.ts → helper/update-resume.d.ts} +4 -10
- package/dist/updates/helper/update-resume.js +252 -0
- package/dist/updates/{update-shutdown.js → helper/update-shutdown.js} +2 -2
- package/dist/updates/{update-arm.d.ts → install/update-arm.d.ts} +2 -2
- package/dist/updates/{update-arm.js → install/update-arm.js} +10 -10
- package/dist/updates/{update-download-cleanup.d.ts → install/update-download-cleanup.d.ts} +1 -1
- package/dist/updates/{update-download-cleanup.js → install/update-download-cleanup.js} +3 -3
- package/dist/updates/{update-download.d.ts → install/update-download.d.ts} +2 -2
- package/dist/updates/{update-download.js → install/update-download.js} +3 -3
- package/dist/updates/{update-extraction.d.ts → install/update-extraction.d.ts} +2 -2
- package/dist/updates/{update-extraction.js → install/update-extraction.js} +6 -6
- package/dist/updates/{update-handoff-plan.d.ts → install/update-handoff-plan.d.ts} +2 -2
- package/dist/updates/{update-handoff-plan.js → install/update-handoff-plan.js} +5 -5
- package/dist/updates/{update-marker.js → install/update-marker.js} +2 -2
- package/dist/updates/{update-swap-stage.d.ts → install/update-swap-stage.d.ts} +2 -2
- package/dist/updates/{update-swap-stage.js → install/update-swap-stage.js} +7 -6
- package/dist/updates/{update-swap.d.ts → install/update-swap.d.ts} +1 -1
- package/dist/updates/{update-swap.js → install/update-swap.js} +5 -5
- package/dist/updates/install-target.d.ts +8 -0
- package/dist/updates/install-target.js +27 -0
- package/dist/updates/{launch-environment.js → launch/launch-environment.js} +1 -1
- package/dist/updates/{packaged-launch-admission.js → launch/packaged-launch-admission.js} +4 -4
- package/dist/updates/{packaged-update-startup.d.ts → launch/packaged-update-startup.d.ts} +3 -3
- package/dist/updates/{packaged-update-startup.js → launch/packaged-update-startup.js} +10 -7
- package/dist/updates/{update-launch-gate.d.ts → launch/update-launch-gate.d.ts} +1 -1
- package/dist/updates/{update-launch-gate.js → launch/update-launch-gate.js} +9 -9
- package/dist/updates/{update-launch.d.ts → launch/update-launch.d.ts} +1 -1
- package/dist/updates/{update-launch.js → launch/update-launch.js} +2 -2
- package/dist/updates/{linux-process-state.js → locks/linux-process-state.js} +1 -1
- package/dist/updates/{native-file-lock.js → locks/native-file-lock.js} +1 -1
- package/dist/updates/{stable-file.js → locks/stable-file.js} +2 -2
- package/dist/updates/{update-download-lock.js → locks/update-download-lock.js} +1 -1
- package/dist/updates/{update-generation-lease.js → locks/update-generation-lease.js} +3 -3
- package/dist/updates/{update-inherited-launch-lease.d.ts → locks/update-inherited-launch-lease.d.ts} +1 -1
- package/dist/updates/{update-inherited-launch-lease.js → locks/update-inherited-launch-lease.js} +2 -2
- package/dist/updates/{update-instance-lease.js → locks/update-instance-lease.js} +2 -2
- package/dist/updates/{update-lock.js → locks/update-lock.js} +2 -2
- package/dist/updates/{update-process-fence.js → locks/update-process-fence.js} +3 -3
- package/dist/updates/{update-process-liveness.js → locks/update-process-liveness.js} +2 -2
- package/dist/updates/retained-client-assets.d.ts +60 -0
- package/dist/updates/retained-client-assets.js +116 -0
- package/dist/updates/retention/retention-cleanup.d.ts +103 -0
- package/dist/updates/retention/retention-cleanup.js +439 -0
- package/dist/updates/retention/retention-prune-progress.d.ts +27 -0
- package/dist/updates/retention/retention-prune-progress.js +203 -0
- package/dist/updates/retention/retirement-inventory.d.ts +93 -0
- package/dist/updates/retention/retirement-inventory.js +373 -0
- package/dist/updates/retention/retirement-records.d.ts +75 -0
- package/dist/updates/retention/retirement-records.js +309 -0
- package/dist/updates/{update-retention-marker.d.ts → retention/update-retention-marker.d.ts} +1 -1
- package/dist/updates/{update-retention-marker.js → retention/update-retention-marker.js} +3 -3
- package/dist/updates/{update-retention-plan.d.ts → retention/update-retention-plan.d.ts} +1 -1
- package/dist/updates/{update-retention-plan.js → retention/update-retention-plan.js} +2 -2
- package/dist/updates/{update-retention-sync.d.ts → retention/update-retention-sync.d.ts} +1 -1
- package/dist/updates/{update-retention-sync.js → retention/update-retention-sync.js} +2 -2
- package/dist/updates/retention/update-retirement.d.ts +26 -0
- package/dist/updates/retention/update-retirement.js +205 -0
- package/dist/updates/update-adapter.js +1 -1
- package/dist/updates/update-channel-store.d.ts +1 -1
- package/dist/updates/update-channel-store.js +3 -3
- package/dist/updates/update-manager.d.ts +4 -4
- package/dist/updates/update-manager.js +5 -5
- package/dist/updates/update-services.d.ts +15 -0
- package/dist/updates/update-services.js +77 -0
- package/dist/updates/update-state-store.d.ts +2 -2
- package/dist/updates/update-state-store.js +2 -2
- package/dist/views/appearance-surface.js +4 -2
- package/package.json +47 -47
- package/src/appearance/custom-theme-library.ts +42 -956
- package/src/appearance/theme-library-mutation.ts +288 -0
- package/src/appearance/theme-library-schema.ts +347 -0
- package/src/appearance/theme-library-store.ts +379 -0
- package/src/updates/update-adapter.ts +1 -1
- package/dist/updates/update-retirement.d.ts +0 -205
- package/dist/updates/update-retirement.js +0 -1485
- /package/dist/installer/{installer-archive.d.ts → installer-archive-members.d.ts} +0 -0
- /package/dist/updates/{packaged-release-config.d.ts → feed/packaged-release-config.d.ts} +0 -0
- /package/dist/updates/{release-feed.d.ts → feed/release-feed.d.ts} +0 -0
- /package/dist/updates/{release-location.d.ts → feed/release-location.d.ts} +0 -0
- /package/dist/updates/{release-version.d.ts → feed/release-version.d.ts} +0 -0
- /package/dist/updates/{signed-release.d.ts → feed/signed-release.d.ts} +0 -0
- /package/dist/updates/{update-discovery.d.ts → feed/update-discovery.d.ts} +0 -0
- /package/dist/updates/{update-shutdown.d.ts → helper/update-shutdown.d.ts} +0 -0
- /package/dist/updates/{update-marker.d.ts → install/update-marker.d.ts} +0 -0
- /package/dist/updates/{launch-environment.d.ts → launch/launch-environment.d.ts} +0 -0
- /package/dist/updates/{packaged-launch-admission.d.ts → launch/packaged-launch-admission.d.ts} +0 -0
- /package/dist/updates/{linux-process-state.d.ts → locks/linux-process-state.d.ts} +0 -0
- /package/dist/updates/{native-file-lock.d.ts → locks/native-file-lock.d.ts} +0 -0
- /package/dist/updates/{stable-file.d.ts → locks/stable-file.d.ts} +0 -0
- /package/dist/updates/{update-download-lock.d.ts → locks/update-download-lock.d.ts} +0 -0
- /package/dist/updates/{update-generation-lease.d.ts → locks/update-generation-lease.d.ts} +0 -0
- /package/dist/updates/{update-instance-lease.d.ts → locks/update-instance-lease.d.ts} +0 -0
- /package/dist/updates/{update-lock.d.ts → locks/update-lock.d.ts} +0 -0
- /package/dist/updates/{update-process-fence.d.ts → locks/update-process-fence.d.ts} +0 -0
- /package/dist/updates/{update-process-liveness.d.ts → locks/update-process-liveness.d.ts} +0 -0
- /package/src/updates/{release-version.ts → feed/release-version.ts} +0 -0
|
@@ -1,622 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { defaultVariantFor } from "@adea-ai/ui/lib/theme-defaults";
|
|
5
|
-
import { variantFromRecord } from "@adea-ai/ui/lib/theme-records";
|
|
6
|
-
// src/appearance/custom-theme-library.ts
|
|
7
|
-
var CUSTOM_THEME_LIBRARY_STORAGE_KEY = "appearance.library";
|
|
8
|
-
/**
|
|
9
|
-
* Where an unreadable library is quarantined. It is its own key: the library and
|
|
10
|
-
* the appearance preference used to share `appearance.recovery`, so one could
|
|
11
|
-
* overwrite the other's capture.
|
|
12
|
-
*/
|
|
13
|
-
var CUSTOM_THEME_LIBRARY_RECOVERY_KEY = "appearance.library.recovery";
|
|
14
|
-
var CUSTOM_THEME_LIBRARY_VERSION = 1;
|
|
15
|
-
var CUSTOM_THEME_ID_PREFIX = "custom-";
|
|
16
|
-
/** Origin-wide lock name shared by all cooperating framework builds. */
|
|
17
|
-
var CUSTOM_THEME_LIBRARY_LOCK_NAME = "adea:appearance.library:mutation:v1";
|
|
18
|
-
var CUSTOM_THEME_LIBRARY_LOCK_DB = "adea:appearance-library-coordination:v1";
|
|
19
|
-
var CUSTOM_THEME_LIBRARY_LOCK_STORE = "locks";
|
|
20
|
-
var CUSTOM_THEME_ATOMIC_STORAGE_UNAVAILABLE = "This app cannot safely save theme changes in this environment. Your library was not changed.";
|
|
21
|
-
var CUSTOM_THEME_LIBRARY_MUTATION_FAILED = "The theme could not be saved. Check your storage and try again.";
|
|
22
|
-
function validateThemeRegistry(registry) {
|
|
23
|
-
const issues = [];
|
|
24
|
-
const seen = /* @__PURE__ */ new Set();
|
|
25
|
-
for (const variant of registry) {
|
|
26
|
-
if (variant.id.trim().length === 0 || seen.has(variant.id)) issues.push({
|
|
27
|
-
variantId: variant.id,
|
|
28
|
-
severity: "error",
|
|
29
|
-
message: "variant id must be unique"
|
|
30
|
-
});
|
|
31
|
-
seen.add(variant.id);
|
|
32
|
-
const check = (role, foreground, background, minimum) => {
|
|
33
|
-
const actual = contrastRatio(foreground, background);
|
|
34
|
-
if (actual < minimum) issues.push({
|
|
35
|
-
variantId: variant.id,
|
|
36
|
-
severity: "error",
|
|
37
|
-
message: `${role} contrast is ${actual.toFixed(2)}:1; expected ${minimum.toFixed(1)}:1`
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
check("text", variant.colors.foreground, variant.colors.background, 4.5);
|
|
41
|
-
check("muted text", variant.colors.mutedForeground, variant.colors.background, 4.5);
|
|
42
|
-
check("primary", variant.colors.primary, variant.colors.background, 3);
|
|
43
|
-
check("on-primary", variant.colors.primaryForeground, variant.colors.primary, 4.5);
|
|
44
|
-
check("terminal foreground", variant.terminal.foreground, variant.terminal.background, 4.5);
|
|
45
|
-
for (const [index, color] of variant.terminal.ansi.entries()) {
|
|
46
|
-
if (index % 8 === 0) continue;
|
|
47
|
-
if (contrastRatio(color, variant.terminal.background) < 3) issues.push({
|
|
48
|
-
variantId: variant.id,
|
|
49
|
-
severity: "warning",
|
|
50
|
-
message: `terminal ANSI slot ${index} is below 3:1`
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
check("editor comment", variant.editor.comment, variant.colors.background, 4.5);
|
|
54
|
-
check("diff delete", variant.editor.diffDelete, variant.colors.background, 3);
|
|
55
|
-
check("diff add", variant.editor.diffAdd, variant.colors.background, 3);
|
|
56
|
-
}
|
|
57
|
-
return issues;
|
|
58
|
-
}
|
|
59
|
-
var ANSI_NAMES = [
|
|
60
|
-
"black",
|
|
61
|
-
"red",
|
|
62
|
-
"green",
|
|
63
|
-
"yellow",
|
|
64
|
-
"blue",
|
|
65
|
-
"magenta",
|
|
66
|
-
"cyan",
|
|
67
|
-
"white"
|
|
68
|
-
];
|
|
69
|
-
function kebabCase(value) {
|
|
70
|
-
return value.replaceAll(/[A-Z]/g, (character) => `-${character.toLocaleLowerCase()}`);
|
|
71
|
-
}
|
|
72
|
-
function terminalTokens(palette) {
|
|
73
|
-
const tokens = {
|
|
74
|
-
"--terminal-background": palette.background,
|
|
75
|
-
"--terminal-foreground": palette.foreground,
|
|
76
|
-
"--terminal-cursor": palette.cursor,
|
|
77
|
-
"--terminal-selection": palette.selection
|
|
78
|
-
};
|
|
79
|
-
for (const [index, color] of palette.ansi.entries()) {
|
|
80
|
-
const name = ANSI_NAMES[index % 8];
|
|
81
|
-
tokens[index < 8 ? `--terminal-ansi-${name}` : `--terminal-ansi-bright-${name}`] = color;
|
|
82
|
-
}
|
|
83
|
-
return tokens;
|
|
84
|
-
}
|
|
85
|
-
/** The custom properties an imported variant owns, as a flat map. */
|
|
86
|
-
function flatVariantTokens(variant) {
|
|
87
|
-
const tokens = {};
|
|
88
|
-
for (const [role, value] of Object.entries(variant.colors)) tokens[`--${kebabCase(role)}`] = value;
|
|
89
|
-
Object.assign(tokens, terminalTokens(variant.terminal));
|
|
90
|
-
for (const [role, value] of Object.entries(variant.editor)) tokens[`--editor-${kebabCase(role)}`] = value;
|
|
91
|
-
for (const [index, value] of Object.values(variant.charts).entries()) tokens[`--chart-${index + 1}`] = value;
|
|
92
|
-
return tokens;
|
|
93
|
-
}
|
|
94
|
-
var IMPORTED_PROVENANCE = {
|
|
95
|
-
project: "Adea themes catalogue",
|
|
96
|
-
url: "https://github.com/adea-ai/themes",
|
|
97
|
-
license: "Apache-2.0"
|
|
98
|
-
};
|
|
99
|
-
function ansiRamp(variant) {
|
|
100
|
-
const [black, red, green, yellow, blue, magenta, cyan, white, brightBlack, brightRed, brightGreen, brightYellow, brightBlue, brightMagenta, brightCyan, brightWhite] = variant.terminal.ansi;
|
|
101
|
-
return {
|
|
102
|
-
black,
|
|
103
|
-
red,
|
|
104
|
-
green,
|
|
105
|
-
yellow,
|
|
106
|
-
blue,
|
|
107
|
-
magenta,
|
|
108
|
-
cyan,
|
|
109
|
-
white,
|
|
110
|
-
brightBlack,
|
|
111
|
-
brightRed,
|
|
112
|
-
brightGreen,
|
|
113
|
-
brightYellow,
|
|
114
|
-
brightBlue,
|
|
115
|
-
brightMagenta,
|
|
116
|
-
brightCyan,
|
|
117
|
-
brightWhite
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* The catalogue-shaped record for an imported variant. The editor reads only its
|
|
122
|
-
* surface, text, border and accent roles; warning and info are the ANSI yellow and
|
|
123
|
-
* blue because the stored variant has no such roles.
|
|
124
|
-
*/
|
|
125
|
-
function storedVariantRecord(variant) {
|
|
126
|
-
const colors = variant.colors;
|
|
127
|
-
const ansi = ansiRamp(variant);
|
|
128
|
-
return {
|
|
129
|
-
id: variant.id,
|
|
130
|
-
name: variant.name,
|
|
131
|
-
appearance: variant.appearance,
|
|
132
|
-
colors: {
|
|
133
|
-
background: colors.background,
|
|
134
|
-
foreground: colors.foreground,
|
|
135
|
-
surface: colors.card,
|
|
136
|
-
surfaceElevated: colors.popover,
|
|
137
|
-
surfaceHover: colors.accent,
|
|
138
|
-
surfaceActive: colors.border,
|
|
139
|
-
border: colors.border,
|
|
140
|
-
borderMuted: colors.border,
|
|
141
|
-
text: colors.foreground,
|
|
142
|
-
textMuted: colors.mutedForeground,
|
|
143
|
-
textSubtle: colors.mutedForeground,
|
|
144
|
-
accent: colors.primary,
|
|
145
|
-
accentForeground: colors.primaryForeground,
|
|
146
|
-
success: colors.success,
|
|
147
|
-
warning: ansi.yellow,
|
|
148
|
-
error: colors.destructive,
|
|
149
|
-
info: ansi.blue
|
|
150
|
-
},
|
|
151
|
-
ansi,
|
|
152
|
-
cursor: variant.terminal.cursor,
|
|
153
|
-
selection: variant.terminal.selection,
|
|
154
|
-
family: variant.familyId,
|
|
155
|
-
familyLabel: variant.familyName,
|
|
156
|
-
label: variant.name,
|
|
157
|
-
description: `${variant.name}, imported into your library.`,
|
|
158
|
-
provenance: IMPORTED_PROVENANCE,
|
|
159
|
-
tags: ["imported", variant.appearance]
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* The shared-provider variant for a stored theme: derived roles from the
|
|
164
|
-
* reconstructed record, missing sidebar projection sources from the stored variant,
|
|
165
|
-
* then every stored flat token verbatim.
|
|
166
|
-
*
|
|
167
|
-
* A record the shared projection cannot map falls back to the default theme of the
|
|
168
|
-
* same appearance under the stored identity, so an import that the projection
|
|
169
|
-
* rejects still paints from its tokens instead of vanishing.
|
|
170
|
-
*/
|
|
171
|
-
function toUiVariant(stored) {
|
|
172
|
-
const { variant } = stored;
|
|
173
|
-
let base;
|
|
174
|
-
try {
|
|
175
|
-
base = variantFromRecord(storedVariantRecord(variant));
|
|
176
|
-
} catch {
|
|
177
|
-
base = {
|
|
178
|
-
...defaultVariantFor(variant.appearance),
|
|
179
|
-
id: variant.id,
|
|
180
|
-
family: variant.familyId,
|
|
181
|
-
familyLabel: variant.familyName,
|
|
182
|
-
label: variant.name,
|
|
183
|
-
description: `${variant.name}, imported into your library.`,
|
|
184
|
-
provenance: {
|
|
185
|
-
source: IMPORTED_PROVENANCE.project,
|
|
186
|
-
url: IMPORTED_PROVENANCE.url,
|
|
187
|
-
license: IMPORTED_PROVENANCE.license
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
const projectionSources = {};
|
|
192
|
-
for (const fallback of LEGACY_IMPORTED_THEME_TOKEN_PROJECTION_FALLBACKS) {
|
|
193
|
-
if (Object.hasOwn(stored.flatTokens, fallback.token)) continue;
|
|
194
|
-
const value = fallback.path.reduce((node, key) => node && typeof node === "object" && Object.hasOwn(node, key) ? node[key] : void 0, stored);
|
|
195
|
-
if (typeof value === "string") projectionSources[fallback.token] = value;
|
|
196
|
-
}
|
|
197
|
-
return {
|
|
198
|
-
...base,
|
|
199
|
-
tokens: {
|
|
200
|
-
...projectionSources,
|
|
201
|
-
...stored.flatTokens
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
var libraryHost = globalThis;
|
|
206
|
-
function library() {
|
|
207
|
-
const existing = libraryHost.__ADEA_THEME_LIBRARY__;
|
|
208
|
-
if (existing && Array.isArray(existing.themes) && existing.listeners) return existing;
|
|
209
|
-
const created = {
|
|
210
|
-
themes: [],
|
|
211
|
-
listeners: existing?.listeners ?? /* @__PURE__ */ new Set(),
|
|
212
|
-
atomicMutationDepth: 0
|
|
213
|
-
};
|
|
214
|
-
libraryHost.__ADEA_THEME_LIBRARY__ = created;
|
|
215
|
-
return created;
|
|
216
|
-
}
|
|
217
|
-
function replaceThemes(themes) {
|
|
218
|
-
const state = library();
|
|
219
|
-
state.themes = Object.freeze([...themes]);
|
|
220
|
-
state.uiVariants = void 0;
|
|
221
|
-
}
|
|
222
|
-
/** The imported themes' stored variants, in import order. */
|
|
223
|
-
function customThemeVariants() {
|
|
224
|
-
return library().themes.map((theme) => theme.variant);
|
|
225
|
-
}
|
|
226
|
-
/** Find one stored variant without projecting the rest of the imported library. */
|
|
227
|
-
function customThemeVariantById(id) {
|
|
228
|
-
return library().themes.find((theme) => theme.variant.id === id)?.variant;
|
|
229
|
-
}
|
|
230
|
-
/** The imported themes as shared-provider variants: what the provider's `themes` takes. */
|
|
231
|
-
function customUiVariants() {
|
|
232
|
-
const state = library();
|
|
233
|
-
state.uiVariants ??= Object.freeze(state.themes.map(toUiVariant));
|
|
234
|
-
return state.uiVariants;
|
|
235
|
-
}
|
|
236
|
-
function handlePersistentLibraryChange(event) {
|
|
237
|
-
if (event.key !== "appearance.library" && event.key !== null) return;
|
|
238
|
-
const storage = defaultPreferenceStorage();
|
|
239
|
-
if (!storage || event.storageArea !== storage) return;
|
|
240
|
-
readCustomThemeLibrary(storage);
|
|
241
|
-
}
|
|
242
|
-
function observePersistentLibraryChanges() {
|
|
243
|
-
const state = library();
|
|
244
|
-
if (state.storageEventTarget || typeof window === "undefined") return;
|
|
245
|
-
const target = window;
|
|
246
|
-
const listener = handlePersistentLibraryChange;
|
|
247
|
-
state.storageEventTarget = target;
|
|
248
|
-
state.storageEventListener = listener;
|
|
249
|
-
target.addEventListener("storage", listener);
|
|
250
|
-
}
|
|
251
|
-
function subscribeCustomThemes(listener) {
|
|
252
|
-
observePersistentLibraryChanges();
|
|
253
|
-
const { listeners } = library();
|
|
254
|
-
listeners.add(listener);
|
|
255
|
-
return () => listeners.delete(listener);
|
|
256
|
-
}
|
|
257
|
-
function notifyCustomThemes() {
|
|
258
|
-
const { listeners } = library();
|
|
259
|
-
for (const listener of [...listeners]) {
|
|
260
|
-
if (!listeners.has(listener)) continue;
|
|
261
|
-
try {
|
|
262
|
-
Promise.resolve(listener()).catch(() => {});
|
|
263
|
-
} catch {}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
function isCustomThemeId(id) {
|
|
267
|
-
return id.startsWith(CUSTOM_THEME_ID_PREFIX);
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Replace the in-memory imported-theme set and tell subscribers. Durable mutations
|
|
271
|
-
* must use `mutateCustomThemeLibrary`; this deprecated synchronous API fails closed
|
|
272
|
-
* when a storage adapter is supplied because it cannot acquire the shared lock.
|
|
273
|
-
*
|
|
274
|
-
* @deprecated Use `mutateCustomThemeLibrary` for persisted read/modify/write operations.
|
|
275
|
-
*/
|
|
276
|
-
function setCustomThemes(themes, storage) {
|
|
277
|
-
if ((library().atomicMutationDepth ?? 0) > 0) return false;
|
|
278
|
-
if (storage) return false;
|
|
279
|
-
replaceThemes(namespaceCustomThemes(themes));
|
|
280
|
-
notifyCustomThemes();
|
|
281
|
-
return true;
|
|
282
|
-
}
|
|
283
|
-
function namespaceCustomThemes(themes) {
|
|
284
|
-
return themes.map((theme) => {
|
|
285
|
-
if (isCustomThemeId(theme.id)) return theme;
|
|
286
|
-
const id = `${CUSTOM_THEME_ID_PREFIX}${theme.id}`;
|
|
287
|
-
return {
|
|
288
|
-
...theme,
|
|
289
|
-
id,
|
|
290
|
-
variant: {
|
|
291
|
-
...theme.variant,
|
|
292
|
-
id
|
|
293
|
-
}
|
|
294
|
-
};
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
var object = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
298
|
-
var fields = (value, names) => object(value) && names.every((name) => typeof value[name] === "string");
|
|
299
|
-
function isStoredTheme(entry) {
|
|
300
|
-
if (!object(entry) || !object(entry.variant)) return false;
|
|
301
|
-
const theme = entry;
|
|
302
|
-
const variant = entry.variant;
|
|
303
|
-
return typeof theme.id === "string" && typeof theme.name === "string" && (theme.appearance === "light" || theme.appearance === "dark") && typeof theme.importedAt === "string" && fields(variant, [
|
|
304
|
-
"id",
|
|
305
|
-
"familyId",
|
|
306
|
-
"familyName",
|
|
307
|
-
"name"
|
|
308
|
-
]) && (variant.appearance === "light" || variant.appearance === "dark") && fields(variant.colors, [
|
|
309
|
-
"background",
|
|
310
|
-
"foreground",
|
|
311
|
-
"card",
|
|
312
|
-
"cardForeground",
|
|
313
|
-
"popover",
|
|
314
|
-
"popoverForeground",
|
|
315
|
-
"primary",
|
|
316
|
-
"primaryForeground",
|
|
317
|
-
"secondary",
|
|
318
|
-
"secondaryForeground",
|
|
319
|
-
"muted",
|
|
320
|
-
"mutedForeground",
|
|
321
|
-
"accent",
|
|
322
|
-
"accentForeground",
|
|
323
|
-
"destructive",
|
|
324
|
-
"destructiveAction",
|
|
325
|
-
"destructiveActionForeground",
|
|
326
|
-
"success",
|
|
327
|
-
"border",
|
|
328
|
-
"input",
|
|
329
|
-
"ring"
|
|
330
|
-
]) && fields(variant.terminal, [
|
|
331
|
-
"background",
|
|
332
|
-
"foreground",
|
|
333
|
-
"cursor",
|
|
334
|
-
"selection"
|
|
335
|
-
]) && object(variant.terminal) && Array.isArray(variant.terminal.ansi) && variant.terminal.ansi.length === 16 && variant.terminal.ansi.every((color) => typeof color === "string") && fields(variant.editor, [
|
|
336
|
-
"keyword",
|
|
337
|
-
"string",
|
|
338
|
-
"number",
|
|
339
|
-
"comment",
|
|
340
|
-
"function",
|
|
341
|
-
"variable",
|
|
342
|
-
"type",
|
|
343
|
-
"tag",
|
|
344
|
-
"attribute",
|
|
345
|
-
"operator",
|
|
346
|
-
"heading",
|
|
347
|
-
"link",
|
|
348
|
-
"diffAdd",
|
|
349
|
-
"diffDelete",
|
|
350
|
-
"diffHunk",
|
|
351
|
-
"searchMatch"
|
|
352
|
-
]) && fields(variant.charts, [
|
|
353
|
-
"chart1",
|
|
354
|
-
"chart2",
|
|
355
|
-
"chart3",
|
|
356
|
-
"chart4",
|
|
357
|
-
"chart5",
|
|
358
|
-
"chart6"
|
|
359
|
-
]) && object(theme.flatTokens) && Object.values(theme.flatTokens).every((value) => typeof value === "string") && Array.isArray(theme.notes) && theme.notes.every((note) => typeof note === "string");
|
|
360
|
-
}
|
|
361
|
-
function parseLibrary(raw) {
|
|
362
|
-
let value;
|
|
363
|
-
try {
|
|
364
|
-
value = JSON.parse(raw);
|
|
365
|
-
} catch {
|
|
366
|
-
return {
|
|
367
|
-
themes: [],
|
|
368
|
-
reason: "corrupt_json"
|
|
369
|
-
};
|
|
370
|
-
}
|
|
371
|
-
if (!object(value) || value.version !== CUSTOM_THEME_LIBRARY_VERSION || !Array.isArray(value.themes)) return {
|
|
372
|
-
themes: [],
|
|
373
|
-
reason: "unsupported_record"
|
|
374
|
-
};
|
|
375
|
-
const themes = value.themes.filter(isStoredTheme);
|
|
376
|
-
return themes.length === value.themes.length ? { themes } : {
|
|
377
|
-
themes,
|
|
378
|
-
reason: "unsupported_record"
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
function preserveLibrary(storage, raw, reason) {
|
|
382
|
-
if (!storage.getItem("appearance.library.recovery")) quarantineRecord(storage, CUSTOM_THEME_LIBRARY_RECOVERY_KEY, raw, reason);
|
|
383
|
-
const saved = storage.getItem(CUSTOM_THEME_LIBRARY_RECOVERY_KEY);
|
|
384
|
-
try {
|
|
385
|
-
const capture = saved && JSON.parse(saved);
|
|
386
|
-
return object(capture) && capture.schemaVersion === 1 && capture.raw === raw;
|
|
387
|
-
} catch {
|
|
388
|
-
return false;
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
/**
|
|
392
|
-
* Read the stored library. A malformed document starts an empty library and
|
|
393
|
-
* quarantines the raw bytes into the library's own recovery key, mirroring the
|
|
394
|
-
* appearance-preference recovery contract; individual invalid records are dropped,
|
|
395
|
-
* not fatal.
|
|
396
|
-
*/
|
|
397
|
-
function readCustomThemeLibrary(storage) {
|
|
398
|
-
if (!storage) return [];
|
|
399
|
-
const result = tryReadCustomThemeLibrary(storage);
|
|
400
|
-
if (result?.changed) notifyCustomThemes();
|
|
401
|
-
return result?.themes ?? [];
|
|
402
|
-
}
|
|
403
|
-
function sameThemeValue(left, right) {
|
|
404
|
-
if (Object.is(left, right)) return true;
|
|
405
|
-
if (!left || !right || typeof left !== "object" || typeof right !== "object") return false;
|
|
406
|
-
if (Array.isArray(left) || Array.isArray(right)) {
|
|
407
|
-
if (!Array.isArray(left) || !Array.isArray(right) || left.length !== right.length) return false;
|
|
408
|
-
if (Object.getPrototypeOf(left) !== Array.prototype) return false;
|
|
409
|
-
if (Reflect.ownKeys(left).length !== left.length + 1) return false;
|
|
410
|
-
for (let index = 0; index < left.length; index++) {
|
|
411
|
-
const entry = Object.getOwnPropertyDescriptor(left, index);
|
|
412
|
-
if (!entry || !entry.enumerable || !("value" in entry)) return false;
|
|
413
|
-
if (!sameThemeValue(entry.value, right[index])) return false;
|
|
414
|
-
}
|
|
415
|
-
return true;
|
|
416
|
-
}
|
|
417
|
-
if (Object.getPrototypeOf(left) !== Object.prototype) return false;
|
|
418
|
-
const leftKeys = Object.keys(left);
|
|
419
|
-
const rightKeys = Object.keys(right);
|
|
420
|
-
if (leftKeys.length !== rightKeys.length || Reflect.ownKeys(left).length !== leftKeys.length) return false;
|
|
421
|
-
const rightRecord = right;
|
|
422
|
-
return leftKeys.every((key) => {
|
|
423
|
-
const entry = Object.getOwnPropertyDescriptor(left, key);
|
|
424
|
-
return !!entry && "value" in entry && Object.hasOwn(rightRecord, key) && sameThemeValue(entry.value, rightRecord[key]);
|
|
425
|
-
});
|
|
426
|
-
}
|
|
427
|
-
/** A failed read must not be confused with a successfully read empty library. */
|
|
428
|
-
function tryReadCustomThemeLibrary(storage) {
|
|
429
|
-
const state = library();
|
|
430
|
-
const previousThemes = state.themes;
|
|
431
|
-
try {
|
|
432
|
-
const raw = storage.getItem(CUSTOM_THEME_LIBRARY_STORAGE_KEY);
|
|
433
|
-
const { themes, reason } = raw ? parseLibrary(raw) : { themes: [] };
|
|
434
|
-
if (raw && reason) preserveLibrary(storage, raw, reason);
|
|
435
|
-
let changed = true;
|
|
436
|
-
try {
|
|
437
|
-
changed = !sameThemeValue(previousThemes, themes);
|
|
438
|
-
} catch {}
|
|
439
|
-
if (storage.getItem("appearance.library") !== raw || library() !== state || state.themes !== previousThemes) return void 0;
|
|
440
|
-
if (changed) replaceThemes(themes);
|
|
441
|
-
return {
|
|
442
|
-
themes: changed ? themes : previousThemes,
|
|
443
|
-
changed
|
|
444
|
-
};
|
|
445
|
-
} catch {
|
|
446
|
-
return;
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
function withIndexedDbMutationLock(name, operation) {
|
|
450
|
-
const factory = globalThis.indexedDB;
|
|
451
|
-
if (!factory) return Promise.reject(/* @__PURE__ */ new Error("IndexedDB is unavailable"));
|
|
452
|
-
return new Promise((resolve, reject) => {
|
|
453
|
-
const open = factory.open(CUSTOM_THEME_LIBRARY_LOCK_DB, 1);
|
|
454
|
-
open.addEventListener("upgradeneeded", () => {
|
|
455
|
-
if (!open.result.objectStoreNames.contains(CUSTOM_THEME_LIBRARY_LOCK_STORE)) open.result.createObjectStore(CUSTOM_THEME_LIBRARY_LOCK_STORE);
|
|
456
|
-
});
|
|
457
|
-
open.addEventListener("error", () => reject(open.error ?? /* @__PURE__ */ new Error("Could not open theme coordination database")));
|
|
458
|
-
open.addEventListener("success", () => {
|
|
459
|
-
const database = open.result;
|
|
460
|
-
database.addEventListener("versionchange", () => database.close());
|
|
461
|
-
let transaction;
|
|
462
|
-
try {
|
|
463
|
-
transaction = database.transaction(CUSTOM_THEME_LIBRARY_LOCK_STORE, "readwrite");
|
|
464
|
-
} catch (error) {
|
|
465
|
-
database.close();
|
|
466
|
-
reject(error);
|
|
467
|
-
return;
|
|
468
|
-
}
|
|
469
|
-
let result;
|
|
470
|
-
let ran = false;
|
|
471
|
-
let operationError;
|
|
472
|
-
const close = () => database.close();
|
|
473
|
-
transaction.addEventListener("complete", () => {
|
|
474
|
-
close();
|
|
475
|
-
if (operationError !== void 0) reject(operationError);
|
|
476
|
-
else if (ran) resolve(result);
|
|
477
|
-
else reject(/* @__PURE__ */ new Error("Theme library lock transaction did not run"));
|
|
478
|
-
});
|
|
479
|
-
transaction.addEventListener("abort", () => {
|
|
480
|
-
close();
|
|
481
|
-
if (ran) {
|
|
482
|
-
resolve(result);
|
|
483
|
-
return;
|
|
484
|
-
}
|
|
485
|
-
reject(operationError ?? transaction.error ?? /* @__PURE__ */ new Error("Theme library lock transaction aborted"));
|
|
486
|
-
});
|
|
487
|
-
try {
|
|
488
|
-
transaction.objectStore(CUSTOM_THEME_LIBRARY_LOCK_STORE).get(name).addEventListener("success", () => {
|
|
489
|
-
try {
|
|
490
|
-
result = operation();
|
|
491
|
-
ran = true;
|
|
492
|
-
} catch (error) {
|
|
493
|
-
operationError = error;
|
|
494
|
-
transaction.abort();
|
|
495
|
-
}
|
|
496
|
-
});
|
|
497
|
-
} catch (error) {
|
|
498
|
-
operationError = error;
|
|
499
|
-
transaction.abort();
|
|
500
|
-
}
|
|
501
|
-
});
|
|
502
|
-
});
|
|
503
|
-
}
|
|
504
|
-
function browserThemeLibraryAtomicLock() {
|
|
505
|
-
if (!globalThis.indexedDB) return void 0;
|
|
506
|
-
const locks = globalThis.navigator?.locks;
|
|
507
|
-
return { withExclusiveLock: (name, operation) => locks && typeof locks.request === "function" ? locks.request(name, { mode: "exclusive" }, () => withIndexedDbMutationLock(name, operation)) : withIndexedDbMutationLock(name, operation) };
|
|
508
|
-
}
|
|
509
|
-
function mutationFailure(reason, error) {
|
|
510
|
-
return {
|
|
511
|
-
ok: false,
|
|
512
|
-
reason,
|
|
513
|
-
error
|
|
514
|
-
};
|
|
515
|
-
}
|
|
516
|
-
/**
|
|
517
|
-
* Coordinate a storage-backed library read/modify/write across cooperating contexts.
|
|
518
|
-
* The callback reads the current v1 record while holding an origin-wide IndexedDB
|
|
519
|
-
* read/write transaction (and a Web Lock where available), then writes and verifies
|
|
520
|
-
* the v1 record before updating this tab's in-memory registry. Older builds and
|
|
521
|
-
* direct `setCustomThemes` storage writes do not acquire these locks and can still
|
|
522
|
-
* race; this API does not claim cross-version atomicity. If IndexedDB is unavailable,
|
|
523
|
-
* durable mutations fail closed.
|
|
524
|
-
*/
|
|
525
|
-
async function mutateCustomThemeLibrary(storage, update, options = {}) {
|
|
526
|
-
if (!storage) try {
|
|
527
|
-
const mutation = update(library().themes);
|
|
528
|
-
if (mutation.commit === false) return {
|
|
529
|
-
ok: true,
|
|
530
|
-
committed: false,
|
|
531
|
-
value: mutation.value
|
|
532
|
-
};
|
|
533
|
-
if (!setCustomThemes(namespaceCustomThemes(mutation.themes), void 0)) return mutationFailure("storage_failed", CUSTOM_THEME_LIBRARY_MUTATION_FAILED);
|
|
534
|
-
return {
|
|
535
|
-
ok: true,
|
|
536
|
-
committed: true,
|
|
537
|
-
value: mutation.value
|
|
538
|
-
};
|
|
539
|
-
} catch {
|
|
540
|
-
return mutationFailure("storage_failed", CUSTOM_THEME_LIBRARY_MUTATION_FAILED);
|
|
541
|
-
}
|
|
542
|
-
const lock = options.lock === void 0 ? browserThemeLibraryAtomicLock() : options.lock;
|
|
543
|
-
if (!lock) return mutationFailure("atomic_unavailable", CUSTOM_THEME_ATOMIC_STORAGE_UNAVAILABLE);
|
|
544
|
-
let enteredLock = false;
|
|
545
|
-
try {
|
|
546
|
-
return await lock.withExclusiveLock(CUSTOM_THEME_LIBRARY_LOCK_NAME, () => {
|
|
547
|
-
enteredLock = true;
|
|
548
|
-
const state = library();
|
|
549
|
-
state.atomicMutationDepth = (state.atomicMutationDepth ?? 0) + 1;
|
|
550
|
-
try {
|
|
551
|
-
let raw;
|
|
552
|
-
let themes;
|
|
553
|
-
try {
|
|
554
|
-
raw = storage.getItem(CUSTOM_THEME_LIBRARY_STORAGE_KEY);
|
|
555
|
-
const parsed = raw ? parseLibrary(raw) : { themes: [] };
|
|
556
|
-
themes = parsed.themes;
|
|
557
|
-
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.");
|
|
558
|
-
if (storage.getItem("appearance.library") !== raw) return mutationFailure("changed_during_mutation", "The theme library changed while it was being read. Try again.");
|
|
559
|
-
} catch {
|
|
560
|
-
return mutationFailure("storage_failed", CUSTOM_THEME_LIBRARY_MUTATION_FAILED);
|
|
561
|
-
}
|
|
562
|
-
let mutation;
|
|
563
|
-
try {
|
|
564
|
-
mutation = update(themes);
|
|
565
|
-
if (storage.getItem("appearance.library") !== raw) return mutationFailure("changed_during_mutation", "The theme library changed while this change was being prepared. Try again.");
|
|
566
|
-
} catch {
|
|
567
|
-
return mutationFailure("storage_failed", CUSTOM_THEME_LIBRARY_MUTATION_FAILED);
|
|
568
|
-
}
|
|
569
|
-
if (mutation.commit === false) return {
|
|
570
|
-
ok: true,
|
|
571
|
-
committed: false,
|
|
572
|
-
value: mutation.value
|
|
573
|
-
};
|
|
574
|
-
const safe = namespaceCustomThemes(mutation.themes);
|
|
575
|
-
const serialized = JSON.stringify({
|
|
576
|
-
version: CUSTOM_THEME_LIBRARY_VERSION,
|
|
577
|
-
themes: safe
|
|
578
|
-
});
|
|
579
|
-
try {
|
|
580
|
-
storage.setItem(CUSTOM_THEME_LIBRARY_STORAGE_KEY, serialized);
|
|
581
|
-
if (storage.getItem("appearance.library") !== serialized) return mutationFailure("changed_during_mutation", "The theme library changed while it was being saved. Try again.");
|
|
582
|
-
} catch {
|
|
583
|
-
return mutationFailure("storage_failed", CUSTOM_THEME_LIBRARY_MUTATION_FAILED);
|
|
584
|
-
}
|
|
585
|
-
replaceThemes(safe);
|
|
586
|
-
notifyCustomThemes();
|
|
587
|
-
return {
|
|
588
|
-
ok: true,
|
|
589
|
-
committed: true,
|
|
590
|
-
value: mutation.value
|
|
591
|
-
};
|
|
592
|
-
} finally {
|
|
593
|
-
state.atomicMutationDepth = Math.max(0, (state.atomicMutationDepth ?? 1) - 1);
|
|
594
|
-
}
|
|
595
|
-
});
|
|
596
|
-
} catch {
|
|
597
|
-
return mutationFailure(enteredLock ? "storage_failed" : "atomic_unavailable", enteredLock ? CUSTOM_THEME_LIBRARY_MUTATION_FAILED : CUSTOM_THEME_ATOMIC_STORAGE_UNAVAILABLE);
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
/** Remove from the latest persisted snapshot, not a possibly stale UI snapshot. */
|
|
601
|
-
async function removeCustomThemeAtomically(id, storage, options = {}) {
|
|
602
|
-
return mutateCustomThemeLibrary(storage, (themes) => {
|
|
603
|
-
const remaining = themes.filter((theme) => theme.id !== id);
|
|
604
|
-
return {
|
|
605
|
-
themes: remaining,
|
|
606
|
-
value: true,
|
|
607
|
-
commit: remaining.length !== themes.length
|
|
608
|
-
};
|
|
609
|
-
}, options);
|
|
610
|
-
}
|
|
611
|
-
/**
|
|
612
|
-
* Synchronous legacy removal for the in-memory library. Passing storage fails closed;
|
|
613
|
-
* use `removeCustomThemeAtomically` for persisted removals.
|
|
614
|
-
*
|
|
615
|
-
* @deprecated Use `removeCustomThemeAtomically` for persisted removals.
|
|
616
|
-
*/
|
|
617
|
-
function removeCustomTheme(id, storage) {
|
|
618
|
-
if (storage) return false;
|
|
619
|
-
const themes = library().themes;
|
|
620
|
-
return setCustomThemes(themes.filter((theme) => theme.id !== id), storage);
|
|
621
|
-
}
|
|
1
|
+
import { CUSTOM_THEME_ATOMIC_STORAGE_UNAVAILABLE, CUSTOM_THEME_LIBRARY_LOCK_NAME, CUSTOM_THEME_LIBRARY_MUTATION_FAILED, mutateCustomThemeLibrary, removeCustomThemeAtomically } from "./theme-library-mutation.js";
|
|
2
|
+
import { flatVariantTokens, storedVariantRecord, toUiVariant, validateThemeRegistry } from "./theme-library-schema.js";
|
|
3
|
+
import { CUSTOM_THEME_LIBRARY_RECOVERY_KEY, CUSTOM_THEME_LIBRARY_STORAGE_KEY, customThemeVariantById, customThemeVariants, customUiVariants, readCustomThemeLibrary, removeCustomTheme, setCustomThemes, subscribeCustomThemes } from "./theme-library-store.js";
|
|
622
4
|
export { CUSTOM_THEME_ATOMIC_STORAGE_UNAVAILABLE, CUSTOM_THEME_LIBRARY_LOCK_NAME, CUSTOM_THEME_LIBRARY_MUTATION_FAILED, CUSTOM_THEME_LIBRARY_RECOVERY_KEY, CUSTOM_THEME_LIBRARY_STORAGE_KEY, customThemeVariantById, customThemeVariants, customUiVariants, flatVariantTokens, mutateCustomThemeLibrary, readCustomThemeLibrary, removeCustomTheme, removeCustomThemeAtomically, setCustomThemes, storedVariantRecord, subscribeCustomThemes, toUiVariant, validateThemeRegistry };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { CustomThemeStored } from './theme-library-schema';
|
|
2
|
+
import { type AppearanceStorage } from './theme-library-store';
|
|
3
|
+
/** A cross-context lock used to serialize theme-library read/modify/write operations. */
|
|
4
|
+
export type ThemeLibraryAtomicLock = Readonly<{
|
|
5
|
+
withExclusiveLock<T>(name: string, operation: () => T): Promise<T>;
|
|
6
|
+
}>;
|
|
7
|
+
export type ThemeLibraryMutationOptions = Readonly<{
|
|
8
|
+
/** Override the browser lock provider in tests or embedder adapters. `null` means unavailable. */
|
|
9
|
+
lock?: ThemeLibraryAtomicLock | null;
|
|
10
|
+
}>;
|
|
11
|
+
export type ThemeLibraryMutation<T> = Readonly<{
|
|
12
|
+
themes: readonly CustomThemeStored[];
|
|
13
|
+
value: T;
|
|
14
|
+
/** Leave storage and subscribers untouched for rejected or idempotent operations. */
|
|
15
|
+
commit?: boolean;
|
|
16
|
+
}>;
|
|
17
|
+
export type ThemeLibraryMutationFailureReason = 'atomic_unavailable' | 'storage_failed' | 'recovery_unavailable' | 'changed_during_mutation';
|
|
18
|
+
export type ThemeLibraryMutationResult<T> = {
|
|
19
|
+
ok: true;
|
|
20
|
+
committed: boolean;
|
|
21
|
+
value: T;
|
|
22
|
+
} | {
|
|
23
|
+
ok: false;
|
|
24
|
+
reason: ThemeLibraryMutationFailureReason;
|
|
25
|
+
error: string;
|
|
26
|
+
};
|
|
27
|
+
/** Origin-wide lock name shared by all cooperating framework builds. */
|
|
28
|
+
export declare const CUSTOM_THEME_LIBRARY_LOCK_NAME = "adea:appearance.library:mutation:v1";
|
|
29
|
+
export declare const CUSTOM_THEME_ATOMIC_STORAGE_UNAVAILABLE = "This app cannot safely save theme changes in this environment. Your library was not changed.";
|
|
30
|
+
export declare const CUSTOM_THEME_LIBRARY_MUTATION_FAILED = "The theme could not be saved. Check your storage and try again.";
|
|
31
|
+
/**
|
|
32
|
+
* Coordinate a storage-backed library read/modify/write across cooperating contexts.
|
|
33
|
+
* The callback reads the current v1 record while holding an origin-wide IndexedDB
|
|
34
|
+
* read/write transaction (and a Web Lock where available), then writes and verifies
|
|
35
|
+
* the v1 record before updating this tab's in-memory registry. Older builds and
|
|
36
|
+
* direct `setCustomThemes` storage writes do not acquire these locks and can still
|
|
37
|
+
* race; this API does not claim cross-version atomicity. If IndexedDB is unavailable,
|
|
38
|
+
* durable mutations fail closed.
|
|
39
|
+
*/
|
|
40
|
+
export declare function mutateCustomThemeLibrary<T>(storage: AppearanceStorage | undefined, update: (themes: readonly CustomThemeStored[]) => ThemeLibraryMutation<T>, options?: ThemeLibraryMutationOptions): Promise<ThemeLibraryMutationResult<T>>;
|
|
41
|
+
/** Remove from the latest persisted snapshot, not a possibly stale UI snapshot. */
|
|
42
|
+
export declare function removeCustomThemeAtomically(id: string, storage: AppearanceStorage | undefined, options?: ThemeLibraryMutationOptions): Promise<ThemeLibraryMutationResult<boolean>>;
|