@nonamelego/dsh-catppuccin 0.6.7 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +6 -1
- package/README.md +14 -6
- package/lib/client.js +327 -15
- package/lib/client.js.map +1 -1
- package/lib/index.js +233 -152
- package/lib/index.js.map +1 -1
- package/package.json +9 -2
package/lib/index.js
CHANGED
|
@@ -797,6 +797,180 @@ const CATPPUCCIN_FLAVORS = [
|
|
|
797
797
|
}
|
|
798
798
|
}
|
|
799
799
|
];
|
|
800
|
+
/** Legacy settings namespace (DSH <= 0.1.6-alpha.2): the Host registers it
|
|
801
|
+
* through `settings.installSection`, the Client binds it through
|
|
802
|
+
* `ctx.settingsScope` (see `src/settings-catppuccin.ts`). */
|
|
803
|
+
const CATPPUCCIN_SETTINGS_NS = "catppuccin";
|
|
804
|
+
/**
|
|
805
|
+
* Profile entry id carrying the plugin (DSH >= 0.1.7-alpha.1): the settings
|
|
806
|
+
* service projects our volatile `Config` into a form named by the ACTIVE
|
|
807
|
+
* PROFILE ENTRY's id, so this constant is the new seam's namespace.
|
|
808
|
+
*
|
|
809
|
+
* It is a CONTRACT with `cordis.patch.yml`: the `insert` row whose `name` is
|
|
810
|
+
* `@nonamelego/dsh-catppuccin` must keep `id: dsh-catppuccin`, because the
|
|
811
|
+
* Client can only address the form by that id (asserted by
|
|
812
|
+
* `tests/settings-seam.spec.ts`). A user who renames the entry loses the new
|
|
813
|
+
* seam and degrades to localStorage-only — the legacy seam is unaffected,
|
|
814
|
+
* since that namespace is registered by the plugin itself.
|
|
815
|
+
*/
|
|
816
|
+
const CATPPUCCIN_ENTRY_ID = "dsh-catppuccin";
|
|
817
|
+
/** State file name under the DSH home (kept next to the Desktop-managed
|
|
818
|
+
* `cordis.patch.yml` so it survives the Desktop's per-launch port churn). */
|
|
819
|
+
const STATE_FILENAME = "catppuccin-state.json";
|
|
820
|
+
/**
|
|
821
|
+
* Whether a raw settings view carries a user layer at all.
|
|
822
|
+
*
|
|
823
|
+
* The two seams answer this differently and the difference is load-bearing
|
|
824
|
+
* (issue #15): the NEW form's `user` is the profile patch's `override`, which
|
|
825
|
+
* `configEditor.configuration()` defaults to `{}` — so "absent" arrives as an
|
|
826
|
+
* EMPTY OBJECT, and `!== undefined` would be true forever. The LEGACY
|
|
827
|
+
* document omits the field entirely when the document holds no such section,
|
|
828
|
+
* so the old `!== undefined` test stays correct there. Callers must use the
|
|
829
|
+
* predicate their channel defines (see `src/client/state-sync.ts`).
|
|
830
|
+
* @param user - a snapshot's raw user layer.
|
|
831
|
+
* @returns whether it holds at least one entry.
|
|
832
|
+
*/
|
|
833
|
+
function hasUserLayerSection(user) {
|
|
834
|
+
return typeof user === "object" && user !== null && !Array.isArray(user) && Object.keys(user).length > 0;
|
|
835
|
+
}
|
|
836
|
+
/** The four registered Catppuccin theme ids. MUST stay in sync with the
|
|
837
|
+
* `themeId` of `CATPPUCCIN_FLAVORS` in `src/client/palettes.ts` — guarded by
|
|
838
|
+
* `tests/state.spec.ts` — because the persisted flavour value IS the theme id. */
|
|
839
|
+
const CATPPUCCIN_THEME_IDS = [
|
|
840
|
+
"catppuccin-latte",
|
|
841
|
+
"catppuccin-frappe",
|
|
842
|
+
"catppuccin-macchiato",
|
|
843
|
+
"catppuccin-mocha"
|
|
844
|
+
];
|
|
845
|
+
/**
|
|
846
|
+
* The LIGHT end of "follow the OS" (issue #36). Latte is the only light
|
|
847
|
+
* flavour Catppuccin ships, so the light half is a constant instead of a
|
|
848
|
+
* setting — a picker here would offer exactly one real option.
|
|
849
|
+
*/
|
|
850
|
+
const FOLLOW_LIGHT_FLAVOR = "catppuccin-latte";
|
|
851
|
+
/** The flavours the follow mode may use for its DARK end. Only the three dark
|
|
852
|
+
* flavours: Latte here would paint a light palette into the dark half. */
|
|
853
|
+
const FOLLOW_DARK_FLAVORS = [
|
|
854
|
+
"catppuccin-frappe",
|
|
855
|
+
"catppuccin-macchiato",
|
|
856
|
+
"catppuccin-mocha"
|
|
857
|
+
];
|
|
858
|
+
/** Shipped follow-mode dark end: Mocha, Catppuccin's most common dark pick. */
|
|
859
|
+
const DEFAULT_FOLLOW_DARK = "catppuccin-mocha";
|
|
860
|
+
/** Shipped glass defaults — the single source of truth; the client glass layer
|
|
861
|
+
* (`src/client/glass/glass-layer.ts`) derives its knob defaults from here. */
|
|
862
|
+
const DEFAULT_GLASS = {
|
|
863
|
+
enabled: false,
|
|
864
|
+
mode: "mica",
|
|
865
|
+
blur: 5,
|
|
866
|
+
frost: 20,
|
|
867
|
+
brightness: 50,
|
|
868
|
+
gap: 12,
|
|
869
|
+
glowStrength: 100,
|
|
870
|
+
glowSize: 100,
|
|
871
|
+
glow: false
|
|
872
|
+
};
|
|
873
|
+
/** Shipped update-check channel: chase the stable `latest` tag. */
|
|
874
|
+
const DEFAULT_UPDATE_CHANNEL = "latest";
|
|
875
|
+
/** Shipped syntax-highlighting style. */
|
|
876
|
+
const DEFAULT_SHIKI_STYLE = "default";
|
|
877
|
+
/** A fully default state: no Catppuccin flavour and no glass. */
|
|
878
|
+
function defaultState() {
|
|
879
|
+
return {
|
|
880
|
+
version: 1,
|
|
881
|
+
flavor: "off",
|
|
882
|
+
followSystem: false,
|
|
883
|
+
followDark: DEFAULT_FOLLOW_DARK,
|
|
884
|
+
glass: { ...DEFAULT_GLASS },
|
|
885
|
+
autoCheck: true,
|
|
886
|
+
updateChannel: DEFAULT_UPDATE_CHANNEL,
|
|
887
|
+
overrides: {},
|
|
888
|
+
shikiStyle: DEFAULT_SHIKI_STYLE
|
|
889
|
+
};
|
|
890
|
+
}
|
|
891
|
+
/**
|
|
892
|
+
* Keep only well-formed custom token overrides: string values under a `--`
|
|
893
|
+
* key (the token shape `--dsw-*` names). Everything else is dropped so a
|
|
894
|
+
* hand-edited document can never smuggle junk into the theme registration.
|
|
895
|
+
*/
|
|
896
|
+
function sanitizeOverrides(input) {
|
|
897
|
+
const out = {};
|
|
898
|
+
if (typeof input !== "object" || input === null) return out;
|
|
899
|
+
for (const [key, value] of Object.entries(input)) if (typeof value === "string" && key.startsWith("--")) out[key] = value;
|
|
900
|
+
return out;
|
|
901
|
+
}
|
|
902
|
+
/** Clamp a finite number into [min, max]; non-finite values fall back. */
|
|
903
|
+
function clampFinite(value, min, max, fallback) {
|
|
904
|
+
return typeof value === "number" && Number.isFinite(value) ? Math.min(max, Math.max(min, value)) : fallback;
|
|
905
|
+
}
|
|
906
|
+
/**
|
|
907
|
+
* Normalize arbitrary input (JSON from disk or the wire) into a valid state:
|
|
908
|
+
* unknown/missing fields fall back to defaults, out-of-range numbers clamp,
|
|
909
|
+
* and unknown flavours/invalid enums fall back too. The Host applies this on
|
|
910
|
+
* both read and write so a corrupt file or a hand-crafted payload can never
|
|
911
|
+
* poison the plugin's settings.
|
|
912
|
+
*/
|
|
913
|
+
function sanitizeState(input) {
|
|
914
|
+
const state = defaultState();
|
|
915
|
+
if (typeof input !== "object" || input === null) return state;
|
|
916
|
+
const raw = input;
|
|
917
|
+
const flavor = raw.flavor;
|
|
918
|
+
if (typeof flavor === "string" && CATPPUCCIN_THEME_IDS.includes(flavor)) state.flavor = flavor;
|
|
919
|
+
else if (flavor === "off") state.flavor = "off";
|
|
920
|
+
const followDark = raw.followDark;
|
|
921
|
+
state.followDark = typeof followDark === "string" && FOLLOW_DARK_FLAVORS.includes(followDark) ? followDark : DEFAULT_FOLLOW_DARK;
|
|
922
|
+
state.followSystem = raw.followSystem === true;
|
|
923
|
+
if (state.flavor === "off") state.followSystem = false;
|
|
924
|
+
const glass = typeof raw.glass === "object" && raw.glass !== null ? raw.glass : {};
|
|
925
|
+
state.glass.enabled = glass.enabled === true;
|
|
926
|
+
state.glass.mode = glass.mode === "compat" ? "compat" : "mica";
|
|
927
|
+
state.glass.blur = clampFinite(glass.blur, 0, 40, DEFAULT_GLASS.blur);
|
|
928
|
+
state.glass.frost = clampFinite(glass.frost, 0, 100, DEFAULT_GLASS.frost);
|
|
929
|
+
state.glass.brightness = clampFinite(glass.brightness, 0, 100, DEFAULT_GLASS.brightness);
|
|
930
|
+
state.glass.gap = clampFinite(glass.gap, 4, 24, DEFAULT_GLASS.gap);
|
|
931
|
+
state.glass.glowStrength = clampFinite(glass.glowStrength, 0, 200, DEFAULT_GLASS.glowStrength);
|
|
932
|
+
state.glass.glowSize = clampFinite(glass.glowSize, 100, 250, DEFAULT_GLASS.glowSize);
|
|
933
|
+
state.glass.glow = glass.glow === true;
|
|
934
|
+
state.autoCheck = raw.autoCheck !== false;
|
|
935
|
+
state.updateChannel = raw.updateChannel === "beta" ? "beta" : "latest";
|
|
936
|
+
state.overrides = sanitizeOverrides(raw.overrides);
|
|
937
|
+
state.shikiStyle = raw.shikiStyle === "italic-comments" ? "italic-comments" : "default";
|
|
938
|
+
return state;
|
|
939
|
+
}
|
|
940
|
+
/** Whether a normalized state carries nothing beyond the shipped defaults —
|
|
941
|
+
* i.e. the user never actually chose anything worth persisting. Used to tell
|
|
942
|
+
* "no durable state yet" apart from "an explicit default choice". */
|
|
943
|
+
function isDefaultState(state) {
|
|
944
|
+
const expected = defaultState();
|
|
945
|
+
return state.flavor === expected.flavor && state.followSystem === expected.followSystem && state.followDark === expected.followDark && state.glass.enabled === expected.glass.enabled && state.glass.mode === expected.glass.mode && state.glass.blur === expected.glass.blur && state.glass.frost === expected.glass.frost && state.glass.brightness === expected.glass.brightness && state.glass.gap === expected.glass.gap && state.glass.glowStrength === expected.glass.glowStrength && state.glass.glowSize === expected.glass.glowSize && state.glass.glow === expected.glass.glow && state.autoCheck === expected.autoCheck && state.updateChannel === expected.updateChannel && Object.keys(state.overrides).length === 0 && state.shikiStyle === expected.shikiStyle;
|
|
946
|
+
}
|
|
947
|
+
/** Default settings-document section: no flavour and no glass (mirrors
|
|
948
|
+
* `defaultState()` minus the synthetic `version`). */
|
|
949
|
+
function defaultSettingsSection() {
|
|
950
|
+
return {
|
|
951
|
+
flavor: "off",
|
|
952
|
+
followSystem: false,
|
|
953
|
+
followDark: DEFAULT_FOLLOW_DARK,
|
|
954
|
+
glass: { ...DEFAULT_GLASS },
|
|
955
|
+
autoCheck: true,
|
|
956
|
+
updateChannel: DEFAULT_UPDATE_CHANNEL,
|
|
957
|
+
overrides: {},
|
|
958
|
+
shikiStyle: DEFAULT_SHIKI_STYLE
|
|
959
|
+
};
|
|
960
|
+
}
|
|
961
|
+
/** Drop the synthetic `version` field: full state → settings-document section. */
|
|
962
|
+
function settingsSectionFromState(state) {
|
|
963
|
+
return {
|
|
964
|
+
flavor: state.flavor,
|
|
965
|
+
followSystem: state.followSystem,
|
|
966
|
+
followDark: state.followDark,
|
|
967
|
+
glass: { ...state.glass },
|
|
968
|
+
autoCheck: state.autoCheck,
|
|
969
|
+
updateChannel: state.updateChannel,
|
|
970
|
+
overrides: { ...state.overrides },
|
|
971
|
+
shikiStyle: state.shikiStyle
|
|
972
|
+
};
|
|
973
|
+
}
|
|
800
974
|
//#endregion
|
|
801
975
|
//#region src/boot-palette.ts
|
|
802
976
|
/**
|
|
@@ -914,9 +1088,47 @@ function bootPaletteScript(flavor) {
|
|
|
914
1088
|
return `(()=>{document.body.toggleAttribute('data-ds-dark-theme',${flavor.colorScheme === "dark"})})()`;
|
|
915
1089
|
}
|
|
916
1090
|
/**
|
|
1091
|
+
* The pre-paint sheet for FOLLOW mode (issue #36): the light half (Latte) is
|
|
1092
|
+
* the default block and the dark half sits behind `prefers-color-scheme`.
|
|
1093
|
+
*
|
|
1094
|
+
* Why a media query works here and NOT in the Client: this sheet is plain CSS
|
|
1095
|
+
* evaluated by the renderer before any script decides a preference, so it
|
|
1096
|
+
* tracks the OS by itself. The Client cannot do the same (see
|
|
1097
|
+
* `docs/issue-36-follow-system.md` §2) — which is exactly why follow mode keeps
|
|
1098
|
+
* the runtime preference on `system` and stacks a token layer.
|
|
1099
|
+
*
|
|
1100
|
+
* The dark block is emitted AFTER the light one so it wins on equal
|
|
1101
|
+
* specificity, and it also matches `[data-ds-dark-theme]` so a stale official
|
|
1102
|
+
* body script cannot leave the light table in force on a dark OS.
|
|
1103
|
+
* @param light - the light flavour (Latte).
|
|
1104
|
+
* @param dark - the persisted follow-mode dark flavour.
|
|
1105
|
+
* @param overrides - already filtered by {@link cssSafeOverrides}; applied to
|
|
1106
|
+
* BOTH halves (a user override is scheme-agnostic by contract).
|
|
1107
|
+
* @returns a complete `<style>…</style>` fragment for a `kind: 'html'` row.
|
|
1108
|
+
*/
|
|
1109
|
+
function followPaletteStyle(light, dark, overrides = {}) {
|
|
1110
|
+
const lightBlock = declarationBlock(light, overrides);
|
|
1111
|
+
const darkBlock = declarationBlock(dark, overrides);
|
|
1112
|
+
return `<style ${BOOT_PALETTE_ATTR}>:root{color-scheme:light dark}html body,html body:not([data-ds-dark-theme]){${lightBlock}}@media (prefers-color-scheme: dark){html body,html body[data-ds-dark-theme]{${darkBlock}}}</style>`;
|
|
1113
|
+
}
|
|
1114
|
+
/**
|
|
1115
|
+
* The body script for follow mode: align `data-ds-dark-theme` with the OS
|
|
1116
|
+
* instead of a fixed flavour scheme, so the attribute-keyed rules (ours and
|
|
1117
|
+
* the host's) are right on the first frame.
|
|
1118
|
+
* @returns the script text for a `kind: 'script'` row.
|
|
1119
|
+
*/
|
|
1120
|
+
function followPaletteScript() {
|
|
1121
|
+
return "(()=>{document.body.toggleAttribute('data-ds-dark-theme',matchMedia('(prefers-color-scheme: dark)').matches)})()";
|
|
1122
|
+
}
|
|
1123
|
+
/**
|
|
917
1124
|
* The boot rows for the current Host state: empty when no flavour is persisted
|
|
918
1125
|
* (`off`), when the config carries no volatile ref (legacy seam — see the
|
|
919
1126
|
* module header), or when the value names no known flavour.
|
|
1127
|
+
*
|
|
1128
|
+
* Follow mode (issue #36) replaces the fixed-flavour rows with the two-half
|
|
1129
|
+
* sheet; it still requires a persisted flavour, because follow mode is a
|
|
1130
|
+
* modifier on a Catppuccin choice, never a way to paint Catppuccin while the
|
|
1131
|
+
* document says `off`.
|
|
920
1132
|
* @param config - the plugin config the Loader hands `apply`.
|
|
921
1133
|
* @returns rows to `push` into the `webserver/index-inject` table.
|
|
922
1134
|
*/
|
|
@@ -925,10 +1137,25 @@ function bootPaletteRows(config) {
|
|
|
925
1137
|
if (typeof flavorId !== "string") return [];
|
|
926
1138
|
const flavor = CATPPUCCIN_FLAVORS.find((candidate) => candidate.themeId === flavorId);
|
|
927
1139
|
if (flavor === void 0) return [];
|
|
1140
|
+
const overrides = cssSafeOverrides(readVolatile(config?.overrides));
|
|
1141
|
+
if (readVolatile(config?.followSystem) === true) {
|
|
1142
|
+
const light = CATPPUCCIN_FLAVORS.find((candidate) => candidate.themeId === FOLLOW_LIGHT_FLAVOR);
|
|
1143
|
+
const darkId = readVolatile(config?.followDark);
|
|
1144
|
+
const dark = CATPPUCCIN_FLAVORS.find((candidate) => candidate.themeId === darkId && candidate.colorScheme === "dark");
|
|
1145
|
+
if (light !== void 0 && dark !== void 0) return [{
|
|
1146
|
+
kind: "html",
|
|
1147
|
+
placement: "head",
|
|
1148
|
+
html: followPaletteStyle(light, dark, overrides)
|
|
1149
|
+
}, {
|
|
1150
|
+
kind: "script",
|
|
1151
|
+
placement: "body",
|
|
1152
|
+
text: followPaletteScript()
|
|
1153
|
+
}];
|
|
1154
|
+
}
|
|
928
1155
|
return [{
|
|
929
1156
|
kind: "html",
|
|
930
1157
|
placement: "head",
|
|
931
|
-
html: bootPaletteStyle(flavor,
|
|
1158
|
+
html: bootPaletteStyle(flavor, overrides)
|
|
932
1159
|
}, {
|
|
933
1160
|
kind: "script",
|
|
934
1161
|
placement: "body",
|
|
@@ -937,7 +1164,7 @@ function bootPaletteRows(config) {
|
|
|
937
1164
|
}
|
|
938
1165
|
//#endregion
|
|
939
1166
|
//#region package.json
|
|
940
|
-
var version = "0.
|
|
1167
|
+
var version = "0.7.0";
|
|
941
1168
|
//#endregion
|
|
942
1169
|
//#region src/registration-tolerance.ts
|
|
943
1170
|
/**
|
|
@@ -1467,155 +1694,6 @@ function registerUpdateCheckRoute(ctx) {
|
|
|
1467
1694
|
}
|
|
1468
1695
|
})), "dsh-catppuccin: update-check route");
|
|
1469
1696
|
}
|
|
1470
|
-
/** Legacy settings namespace (DSH <= 0.1.6-alpha.2): the Host registers it
|
|
1471
|
-
* through `settings.installSection`, the Client binds it through
|
|
1472
|
-
* `ctx.settingsScope` (see `src/settings-catppuccin.ts`). */
|
|
1473
|
-
const CATPPUCCIN_SETTINGS_NS = "catppuccin";
|
|
1474
|
-
/**
|
|
1475
|
-
* Profile entry id carrying the plugin (DSH >= 0.1.7-alpha.1): the settings
|
|
1476
|
-
* service projects our volatile `Config` into a form named by the ACTIVE
|
|
1477
|
-
* PROFILE ENTRY's id, so this constant is the new seam's namespace.
|
|
1478
|
-
*
|
|
1479
|
-
* It is a CONTRACT with `cordis.patch.yml`: the `insert` row whose `name` is
|
|
1480
|
-
* `@nonamelego/dsh-catppuccin` must keep `id: dsh-catppuccin`, because the
|
|
1481
|
-
* Client can only address the form by that id (asserted by
|
|
1482
|
-
* `tests/settings-seam.spec.ts`). A user who renames the entry loses the new
|
|
1483
|
-
* seam and degrades to localStorage-only — the legacy seam is unaffected,
|
|
1484
|
-
* since that namespace is registered by the plugin itself.
|
|
1485
|
-
*/
|
|
1486
|
-
const CATPPUCCIN_ENTRY_ID = "dsh-catppuccin";
|
|
1487
|
-
/** State file name under the DSH home (kept next to the Desktop-managed
|
|
1488
|
-
* `cordis.patch.yml` so it survives the Desktop's per-launch port churn). */
|
|
1489
|
-
const STATE_FILENAME = "catppuccin-state.json";
|
|
1490
|
-
/**
|
|
1491
|
-
* Whether a raw settings view carries a user layer at all.
|
|
1492
|
-
*
|
|
1493
|
-
* The two seams answer this differently and the difference is load-bearing
|
|
1494
|
-
* (issue #15): the NEW form's `user` is the profile patch's `override`, which
|
|
1495
|
-
* `configEditor.configuration()` defaults to `{}` — so "absent" arrives as an
|
|
1496
|
-
* EMPTY OBJECT, and `!== undefined` would be true forever. The LEGACY
|
|
1497
|
-
* document omits the field entirely when the document holds no such section,
|
|
1498
|
-
* so the old `!== undefined` test stays correct there. Callers must use the
|
|
1499
|
-
* predicate their channel defines (see `src/client/state-sync.ts`).
|
|
1500
|
-
* @param user - a snapshot's raw user layer.
|
|
1501
|
-
* @returns whether it holds at least one entry.
|
|
1502
|
-
*/
|
|
1503
|
-
function hasUserLayerSection(user) {
|
|
1504
|
-
return typeof user === "object" && user !== null && !Array.isArray(user) && Object.keys(user).length > 0;
|
|
1505
|
-
}
|
|
1506
|
-
/** The four registered Catppuccin theme ids. MUST stay in sync with the
|
|
1507
|
-
* `themeId` of `CATPPUCCIN_FLAVORS` in `src/client/palettes.ts` — guarded by
|
|
1508
|
-
* `tests/state.spec.ts` — because the persisted flavour value IS the theme id. */
|
|
1509
|
-
const CATPPUCCIN_THEME_IDS = [
|
|
1510
|
-
"catppuccin-latte",
|
|
1511
|
-
"catppuccin-frappe",
|
|
1512
|
-
"catppuccin-macchiato",
|
|
1513
|
-
"catppuccin-mocha"
|
|
1514
|
-
];
|
|
1515
|
-
/** Shipped glass defaults — the single source of truth; the client glass layer
|
|
1516
|
-
* (`src/client/glass/glass-layer.ts`) derives its knob defaults from here. */
|
|
1517
|
-
const DEFAULT_GLASS = {
|
|
1518
|
-
enabled: false,
|
|
1519
|
-
mode: "mica",
|
|
1520
|
-
blur: 5,
|
|
1521
|
-
frost: 20,
|
|
1522
|
-
brightness: 50,
|
|
1523
|
-
gap: 12,
|
|
1524
|
-
glowStrength: 100,
|
|
1525
|
-
glowSize: 100,
|
|
1526
|
-
glow: false
|
|
1527
|
-
};
|
|
1528
|
-
/** Shipped update-check channel: chase the stable `latest` tag. */
|
|
1529
|
-
const DEFAULT_UPDATE_CHANNEL = "latest";
|
|
1530
|
-
/** Shipped syntax-highlighting style. */
|
|
1531
|
-
const DEFAULT_SHIKI_STYLE = "default";
|
|
1532
|
-
/** A fully default state: no Catppuccin flavour and no glass. */
|
|
1533
|
-
function defaultState() {
|
|
1534
|
-
return {
|
|
1535
|
-
version: 1,
|
|
1536
|
-
flavor: "off",
|
|
1537
|
-
glass: { ...DEFAULT_GLASS },
|
|
1538
|
-
autoCheck: true,
|
|
1539
|
-
updateChannel: DEFAULT_UPDATE_CHANNEL,
|
|
1540
|
-
overrides: {},
|
|
1541
|
-
shikiStyle: DEFAULT_SHIKI_STYLE
|
|
1542
|
-
};
|
|
1543
|
-
}
|
|
1544
|
-
/**
|
|
1545
|
-
* Keep only well-formed custom token overrides: string values under a `--`
|
|
1546
|
-
* key (the token shape `--dsw-*` names). Everything else is dropped so a
|
|
1547
|
-
* hand-edited document can never smuggle junk into the theme registration.
|
|
1548
|
-
*/
|
|
1549
|
-
function sanitizeOverrides(input) {
|
|
1550
|
-
const out = {};
|
|
1551
|
-
if (typeof input !== "object" || input === null) return out;
|
|
1552
|
-
for (const [key, value] of Object.entries(input)) if (typeof value === "string" && key.startsWith("--")) out[key] = value;
|
|
1553
|
-
return out;
|
|
1554
|
-
}
|
|
1555
|
-
/** Clamp a finite number into [min, max]; non-finite values fall back. */
|
|
1556
|
-
function clampFinite(value, min, max, fallback) {
|
|
1557
|
-
return typeof value === "number" && Number.isFinite(value) ? Math.min(max, Math.max(min, value)) : fallback;
|
|
1558
|
-
}
|
|
1559
|
-
/**
|
|
1560
|
-
* Normalize arbitrary input (JSON from disk or the wire) into a valid state:
|
|
1561
|
-
* unknown/missing fields fall back to defaults, out-of-range numbers clamp,
|
|
1562
|
-
* and unknown flavours/invalid enums fall back too. The Host applies this on
|
|
1563
|
-
* both read and write so a corrupt file or a hand-crafted payload can never
|
|
1564
|
-
* poison the plugin's settings.
|
|
1565
|
-
*/
|
|
1566
|
-
function sanitizeState(input) {
|
|
1567
|
-
const state = defaultState();
|
|
1568
|
-
if (typeof input !== "object" || input === null) return state;
|
|
1569
|
-
const raw = input;
|
|
1570
|
-
const flavor = raw.flavor;
|
|
1571
|
-
if (typeof flavor === "string" && CATPPUCCIN_THEME_IDS.includes(flavor)) state.flavor = flavor;
|
|
1572
|
-
else if (flavor === "off") state.flavor = "off";
|
|
1573
|
-
const glass = typeof raw.glass === "object" && raw.glass !== null ? raw.glass : {};
|
|
1574
|
-
state.glass.enabled = glass.enabled === true;
|
|
1575
|
-
state.glass.mode = glass.mode === "compat" ? "compat" : "mica";
|
|
1576
|
-
state.glass.blur = clampFinite(glass.blur, 0, 40, DEFAULT_GLASS.blur);
|
|
1577
|
-
state.glass.frost = clampFinite(glass.frost, 0, 100, DEFAULT_GLASS.frost);
|
|
1578
|
-
state.glass.brightness = clampFinite(glass.brightness, 0, 100, DEFAULT_GLASS.brightness);
|
|
1579
|
-
state.glass.gap = clampFinite(glass.gap, 4, 24, DEFAULT_GLASS.gap);
|
|
1580
|
-
state.glass.glowStrength = clampFinite(glass.glowStrength, 0, 200, DEFAULT_GLASS.glowStrength);
|
|
1581
|
-
state.glass.glowSize = clampFinite(glass.glowSize, 100, 250, DEFAULT_GLASS.glowSize);
|
|
1582
|
-
state.glass.glow = glass.glow === true;
|
|
1583
|
-
state.autoCheck = raw.autoCheck !== false;
|
|
1584
|
-
state.updateChannel = raw.updateChannel === "beta" ? "beta" : "latest";
|
|
1585
|
-
state.overrides = sanitizeOverrides(raw.overrides);
|
|
1586
|
-
state.shikiStyle = raw.shikiStyle === "italic-comments" ? "italic-comments" : "default";
|
|
1587
|
-
return state;
|
|
1588
|
-
}
|
|
1589
|
-
/** Whether a normalized state carries nothing beyond the shipped defaults —
|
|
1590
|
-
* i.e. the user never actually chose anything worth persisting. Used to tell
|
|
1591
|
-
* "no durable state yet" apart from "an explicit default choice". */
|
|
1592
|
-
function isDefaultState(state) {
|
|
1593
|
-
const expected = defaultState();
|
|
1594
|
-
return state.flavor === expected.flavor && state.glass.enabled === expected.glass.enabled && state.glass.mode === expected.glass.mode && state.glass.blur === expected.glass.blur && state.glass.frost === expected.glass.frost && state.glass.brightness === expected.glass.brightness && state.glass.gap === expected.glass.gap && state.glass.glowStrength === expected.glass.glowStrength && state.glass.glowSize === expected.glass.glowSize && state.glass.glow === expected.glass.glow && state.autoCheck === expected.autoCheck && state.updateChannel === expected.updateChannel && Object.keys(state.overrides).length === 0 && state.shikiStyle === expected.shikiStyle;
|
|
1595
|
-
}
|
|
1596
|
-
/** Default settings-document section: no flavour and no glass (mirrors
|
|
1597
|
-
* `defaultState()` minus the synthetic `version`). */
|
|
1598
|
-
function defaultSettingsSection() {
|
|
1599
|
-
return {
|
|
1600
|
-
flavor: "off",
|
|
1601
|
-
glass: { ...DEFAULT_GLASS },
|
|
1602
|
-
autoCheck: true,
|
|
1603
|
-
updateChannel: DEFAULT_UPDATE_CHANNEL,
|
|
1604
|
-
overrides: {},
|
|
1605
|
-
shikiStyle: DEFAULT_SHIKI_STYLE
|
|
1606
|
-
};
|
|
1607
|
-
}
|
|
1608
|
-
/** Drop the synthetic `version` field: full state → settings-document section. */
|
|
1609
|
-
function settingsSectionFromState(state) {
|
|
1610
|
-
return {
|
|
1611
|
-
flavor: state.flavor,
|
|
1612
|
-
glass: { ...state.glass },
|
|
1613
|
-
autoCheck: state.autoCheck,
|
|
1614
|
-
updateChannel: state.updateChannel,
|
|
1615
|
-
overrides: { ...state.overrides },
|
|
1616
|
-
shikiStyle: state.shikiStyle
|
|
1617
|
-
};
|
|
1618
|
-
}
|
|
1619
1697
|
//#endregion
|
|
1620
1698
|
//#region src/legacy-state.ts
|
|
1621
1699
|
/**
|
|
@@ -1690,7 +1768,6 @@ function scheduleLegacyMigration(ctx, settings, ns, hasUserLayer) {
|
|
|
1690
1768
|
return;
|
|
1691
1769
|
}
|
|
1692
1770
|
settled = true;
|
|
1693
|
-
if (outcome === "migrated") console.info(`[dsh-catppuccin] migrated the legacy state file into "${ns}"`);
|
|
1694
1771
|
}).catch((error) => {
|
|
1695
1772
|
settled = true;
|
|
1696
1773
|
console.warn(`[dsh-catppuccin] legacy state migration failed: ${String(error)}`);
|
|
@@ -1775,6 +1852,8 @@ function maybeVolatile(node) {
|
|
|
1775
1852
|
function catppuccinSchemaFields() {
|
|
1776
1853
|
return {
|
|
1777
1854
|
flavor: Schema.union([...CATPPUCCIN_THEME_IDS, "off"]).default("off"),
|
|
1855
|
+
followSystem: Schema.boolean().default(false),
|
|
1856
|
+
followDark: Schema.union([...FOLLOW_DARK_FLAVORS]).default(DEFAULT_FOLLOW_DARK),
|
|
1778
1857
|
glass: Schema.object({
|
|
1779
1858
|
enabled: Schema.boolean().default(DEFAULT_GLASS.enabled),
|
|
1780
1859
|
mode: Schema.union(["mica", "compat"]).default(DEFAULT_GLASS.mode),
|
|
@@ -1801,6 +1880,8 @@ function volatileFields() {
|
|
|
1801
1880
|
const glassFields = fields.glass.dict ?? {};
|
|
1802
1881
|
return {
|
|
1803
1882
|
flavor: maybeVolatile(fields.flavor),
|
|
1883
|
+
followSystem: maybeVolatile(fields.followSystem),
|
|
1884
|
+
followDark: maybeVolatile(fields.followDark),
|
|
1804
1885
|
glass: Schema.object(Object.fromEntries(Object.entries(glassFields).map(([key, node]) => [key, maybeVolatile(node)]))),
|
|
1805
1886
|
autoCheck: maybeVolatile(fields.autoCheck),
|
|
1806
1887
|
updateChannel: maybeVolatile(fields.updateChannel),
|