@nonamelego/dsh-catppuccin 0.6.5-beta.0 → 0.6.6-beta.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/lib/client.js CHANGED
@@ -3449,6 +3449,46 @@ window.__ModuleLoader__.load({
3449
3449
  }
3450
3450
  ];
3451
3451
  //#endregion
3452
+ //#region src/boot-palette.ts
3453
+ /** Attribute marking the injected `<style>` so the Client can find it. */
3454
+ const BOOT_PALETTE_ATTR = "data-dsh-catppuccin-boot";
3455
+ //#endregion
3456
+ //#region src/client/boot-palette.ts
3457
+ /**
3458
+ * Client half of the pre-paint palette (issue #30 补充, 2026-10-27).
3459
+ *
3460
+ * The Host injects a `<style data-dsh-catppuccin-boot>` into the index HTML so
3461
+ * the first frame is already the persisted flavour (see `src/boot-palette.ts`).
3462
+ * That sheet is only a stand-in: its selector is `html body` (0,0,2), which
3463
+ * outranks the official `body` token block, so leaving it in place would pin
3464
+ * every token and defeat later theme switches (the user picks Light or turns the
3465
+ * flavour off and nothing changes).
3466
+ *
3467
+ * So it is removed the moment the flavour theme actually takes over — which is
3468
+ * NOT the same instant as "setTheme was called":
3469
+ * - a reload where the runtime preference already equals the flavour id never
3470
+ * calls setTheme (see `applyDesired`'s early return), and
3471
+ * - a built-in pick (Light / Dark / System) must remove it too, because the
3472
+ * sheet belongs to a flavour that is no longer wanted.
3473
+ * The restore effect therefore clears it from every one of those points plus a
3474
+ * fallback timer and the effect teardown.
3475
+ */
3476
+ /**
3477
+ * Remove every injected pre-paint sheet from this document.
3478
+ *
3479
+ * Idempotent and safe when nothing was injected (hosts without the index
3480
+ * injection seam, `flavor: off`, a document that already cleared it).
3481
+ * @returns whether an element was actually removed (diagnostics and tests).
3482
+ */
3483
+ function clearBootPalette() {
3484
+ let removed = false;
3485
+ for (const element of document.querySelectorAll(`[${BOOT_PALETTE_ATTR}]`)) {
3486
+ element.remove();
3487
+ removed = true;
3488
+ }
3489
+ return removed;
3490
+ }
3491
+ //#endregion
3452
3492
  //#region src/client/shiki-tokens.ts
3453
3493
  /**
3454
3494
  * Canonical Catppuccin syntax colours per flavour.
@@ -4271,14 +4311,22 @@ window.__ModuleLoader__.load({
4271
4311
  };
4272
4312
  const AUTO_CHECK_BOOT_DELAY_MS = 3e3;
4273
4313
  const AUTO_CHECK_INTERVAL_MS = 216e5;
4314
+ /** How long the Host's pre-paint palette may survive before it is removed
4315
+ * unconditionally (issue #30 补充). Generous on purpose: removing it EARLY
4316
+ * re-exposes the official palette for one frame, which is the bug. */
4317
+ const BOOT_PALETTE_FALLBACK_MS = 1e4;
4274
4318
  let lastAutoResult = null;
4275
4319
  let armAutoCheck;
4276
4320
  ctx.effect(() => {
4277
4321
  let liveBuiltinPick = null;
4322
+ const bootPaletteFallback = window.setTimeout(() => {
4323
+ clearBootPalette();
4324
+ }, BOOT_PALETTE_FALLBACK_MS);
4278
4325
  const originalSetTheme = theme.setTheme;
4279
4326
  const restoreGuardSetTheme = (id) => {
4280
4327
  liveBuiltinPick = isBuiltinPreference(id) ? id : null;
4281
4328
  originalSetTheme.call(theme, id);
4329
+ clearBootPalette();
4282
4330
  };
4283
4331
  theme.setTheme = restoreGuardSetTheme;
4284
4332
  let restorePending = false;
@@ -4288,7 +4336,10 @@ window.__ModuleLoader__.load({
4288
4336
  queueMicrotask(() => {
4289
4337
  restorePending = false;
4290
4338
  const preference = theme.getTheme().preference;
4291
- if (preference === desired) return;
4339
+ if (preference === desired) {
4340
+ clearBootPalette();
4341
+ return;
4342
+ }
4292
4343
  if (builtinPickWins(preference, liveBuiltinPick)) return;
4293
4344
  ensureThemeRegistered(desired);
4294
4345
  try {
@@ -4301,11 +4352,17 @@ window.__ModuleLoader__.load({
4301
4352
  const desired = readFlavor();
4302
4353
  if (desired === "off") {
4303
4354
  const preference = theme.getTheme().preference;
4304
- if (readExplicitFlavorOff() && flavorFromThemeId(preference) !== "off") scheduleRestore(readRestoredPreference());
4355
+ if (readExplicitFlavorOff()) {
4356
+ clearBootPalette();
4357
+ if (flavorFromThemeId(preference) !== "off") scheduleRestore(readRestoredPreference());
4358
+ }
4305
4359
  return;
4306
4360
  }
4307
4361
  const preference = theme.getTheme().preference;
4308
- if (preference === desired) return;
4362
+ if (preference === desired) {
4363
+ clearBootPalette();
4364
+ return;
4365
+ }
4309
4366
  if (builtinPickWins(preference, liveBuiltinPick)) return;
4310
4367
  scheduleRestore(desired);
4311
4368
  };
@@ -4402,6 +4459,8 @@ window.__ModuleLoader__.load({
4402
4459
  offGlass();
4403
4460
  disposer();
4404
4461
  window.removeEventListener("storage", onStorage);
4462
+ window.clearTimeout(bootPaletteFallback);
4463
+ clearBootPalette();
4405
4464
  window.clearTimeout(bootTimer);
4406
4465
  window.clearInterval(intervalTimer);
4407
4466
  cancelDurablePersist();