@monkey-mini-app/panel 0.1.1 → 0.1.5
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/{chunk-X3QW77RD.js → chunk-JAWSEXOV.js} +36 -5
- package/dist/index.cjs +1916 -595
- package/dist/index.d.cts +127 -3
- package/dist/index.d.ts +127 -3
- package/dist/index.js +1451 -169
- package/dist/themes.cjs +41 -4
- package/dist/themes.d.cts +22 -1
- package/dist/themes.d.ts +22 -1
- package/dist/themes.js +1 -1
- package/package.json +2 -1
|
@@ -3,6 +3,16 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
|
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
4
|
|
|
5
5
|
// src/themes.ts
|
|
6
|
+
var LOCAL_PALETTE_ID = "__local__";
|
|
7
|
+
var GLOBAL_PALETTE_ID = "__global__";
|
|
8
|
+
function effectivePalette(stored, hasLocalTheme, hostPalette) {
|
|
9
|
+
if (stored && stored !== GLOBAL_PALETTE_ID) return stored;
|
|
10
|
+
if (!stored && hasLocalTheme) return LOCAL_PALETTE_ID;
|
|
11
|
+
return hostPalette;
|
|
12
|
+
}
|
|
13
|
+
function selectedPalette(stored, hasLocalTheme) {
|
|
14
|
+
return stored ?? (hasLocalTheme ? LOCAL_PALETTE_ID : GLOBAL_PALETTE_ID);
|
|
15
|
+
}
|
|
6
16
|
var PALETTES = [
|
|
7
17
|
{ id: "default", label: "\u9ED8\u8BA4", swatch: "#2563eb" },
|
|
8
18
|
{ id: "tokyo", label: "\u4E1C\u4EAC\u591C", swatch: "#7aa2f7" },
|
|
@@ -432,6 +442,18 @@ function clampPalette(value) {
|
|
|
432
442
|
function clampMode(value) {
|
|
433
443
|
return value === "dark" ? "dark" : "light";
|
|
434
444
|
}
|
|
445
|
+
function resolveMode(value) {
|
|
446
|
+
if (value === "system") {
|
|
447
|
+
try {
|
|
448
|
+
if (typeof window !== "undefined" && window.matchMedia("(prefers-color-scheme: dark)").matches) {
|
|
449
|
+
return "dark";
|
|
450
|
+
}
|
|
451
|
+
} catch {
|
|
452
|
+
}
|
|
453
|
+
return "light";
|
|
454
|
+
}
|
|
455
|
+
return clampMode(value);
|
|
456
|
+
}
|
|
435
457
|
function tokensOf(palette, mode) {
|
|
436
458
|
return TOKENS[clampPalette(palette)][clampMode(mode)];
|
|
437
459
|
}
|
|
@@ -482,14 +504,12 @@ function runnerThemeCss() {
|
|
|
482
504
|
blocks.push(`html[data-theme="light"] input[type="date"],html[data-theme="light"] input[type="time"],html[data-theme="light"] input[type="datetime-local"],html[data-theme="light"] input[type="month"],html[data-theme="light"] input[type="week"]{color-scheme:light}`);
|
|
483
505
|
return blocks.join("\n ");
|
|
484
506
|
}
|
|
485
|
-
function
|
|
507
|
+
function themeCssVars(theme, palette, custom) {
|
|
486
508
|
const mode = clampMode(theme);
|
|
487
509
|
const c = custom && palette ? custom[String(palette)] : void 0;
|
|
488
510
|
const pal = c ? String(palette) : clampPalette(palette);
|
|
489
511
|
const t = c && c.tokens && c.tokens[mode] || tokensOf(pal, mode);
|
|
490
|
-
|
|
491
|
-
el.setAttribute("data-palette", pal);
|
|
492
|
-
const map = {
|
|
512
|
+
return {
|
|
493
513
|
"--dsw-alias-bg": t.bg,
|
|
494
514
|
"--dsw-alias-fg": t.fg,
|
|
495
515
|
"--dsw-alias-surface": t.surface,
|
|
@@ -519,10 +539,21 @@ function applyThemeTo(el, theme, palette, custom) {
|
|
|
519
539
|
"--radius": t.radius,
|
|
520
540
|
"--shadow": t.shadow
|
|
521
541
|
};
|
|
542
|
+
}
|
|
543
|
+
function applyThemeTo(el, theme, palette, custom) {
|
|
544
|
+
const mode = resolveMode(theme);
|
|
545
|
+
const c = custom && palette ? custom[String(palette)] : void 0;
|
|
546
|
+
const pal = c ? String(palette) : clampPalette(palette);
|
|
547
|
+
const t = c && c.tokens && c.tokens[mode] || tokensOf(pal, mode);
|
|
548
|
+
el.setAttribute("data-theme", mode);
|
|
549
|
+
if (theme === "system") el.setAttribute("data-theme-pref", "system");
|
|
550
|
+
else el.removeAttribute("data-theme-pref");
|
|
551
|
+
el.setAttribute("data-palette", pal);
|
|
552
|
+
const map = themeCssVars(mode, palette, custom);
|
|
522
553
|
for (const k of Object.keys(map)) el.style.setProperty(k, map[k]);
|
|
523
554
|
el.style.background = t.bg;
|
|
524
555
|
el.style.color = t.fg;
|
|
525
556
|
return { theme: mode, palette: pal };
|
|
526
557
|
}
|
|
527
558
|
|
|
528
|
-
export { PALETTES, __publicField, applyThemeTo, clampMode, clampPalette, cssVars, parseThemeCss, runnerThemeCss, themeLabelFromCss, tokensOf };
|
|
559
|
+
export { GLOBAL_PALETTE_ID, LOCAL_PALETTE_ID, PALETTES, __publicField, applyThemeTo, clampMode, clampPalette, cssVars, effectivePalette, parseThemeCss, resolveMode, runnerThemeCss, selectedPalette, themeCssVars, themeLabelFromCss, tokensOf };
|