@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
package/dist/themes.cjs
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
// src/themes.ts
|
|
4
|
+
var LOCAL_PALETTE_ID = "__local__";
|
|
5
|
+
var GLOBAL_PALETTE_ID = "__global__";
|
|
6
|
+
function effectivePalette(stored, hasLocalTheme, hostPalette) {
|
|
7
|
+
if (stored && stored !== GLOBAL_PALETTE_ID) return stored;
|
|
8
|
+
if (!stored && hasLocalTheme) return LOCAL_PALETTE_ID;
|
|
9
|
+
return hostPalette;
|
|
10
|
+
}
|
|
11
|
+
function selectedPalette(stored, hasLocalTheme) {
|
|
12
|
+
return stored ?? (hasLocalTheme ? LOCAL_PALETTE_ID : GLOBAL_PALETTE_ID);
|
|
13
|
+
}
|
|
4
14
|
var PALETTES = [
|
|
5
15
|
{ id: "default", label: "\u9ED8\u8BA4", swatch: "#2563eb" },
|
|
6
16
|
{ id: "tokyo", label: "\u4E1C\u4EAC\u591C", swatch: "#7aa2f7" },
|
|
@@ -430,6 +440,18 @@ function clampPalette(value) {
|
|
|
430
440
|
function clampMode(value) {
|
|
431
441
|
return value === "dark" ? "dark" : "light";
|
|
432
442
|
}
|
|
443
|
+
function resolveMode(value) {
|
|
444
|
+
if (value === "system") {
|
|
445
|
+
try {
|
|
446
|
+
if (typeof window !== "undefined" && window.matchMedia("(prefers-color-scheme: dark)").matches) {
|
|
447
|
+
return "dark";
|
|
448
|
+
}
|
|
449
|
+
} catch {
|
|
450
|
+
}
|
|
451
|
+
return "light";
|
|
452
|
+
}
|
|
453
|
+
return clampMode(value);
|
|
454
|
+
}
|
|
433
455
|
function tokensOf(palette, mode) {
|
|
434
456
|
return TOKENS[clampPalette(palette)][clampMode(mode)];
|
|
435
457
|
}
|
|
@@ -480,14 +502,12 @@ function runnerThemeCss() {
|
|
|
480
502
|
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}`);
|
|
481
503
|
return blocks.join("\n ");
|
|
482
504
|
}
|
|
483
|
-
function
|
|
505
|
+
function themeCssVars(theme, palette, custom) {
|
|
484
506
|
const mode = clampMode(theme);
|
|
485
507
|
const c = custom && palette ? custom[String(palette)] : void 0;
|
|
486
508
|
const pal = c ? String(palette) : clampPalette(palette);
|
|
487
509
|
const t = c && c.tokens && c.tokens[mode] || tokensOf(pal, mode);
|
|
488
|
-
|
|
489
|
-
el.setAttribute("data-palette", pal);
|
|
490
|
-
const map = {
|
|
510
|
+
return {
|
|
491
511
|
"--dsw-alias-bg": t.bg,
|
|
492
512
|
"--dsw-alias-fg": t.fg,
|
|
493
513
|
"--dsw-alias-surface": t.surface,
|
|
@@ -517,18 +537,35 @@ function applyThemeTo(el, theme, palette, custom) {
|
|
|
517
537
|
"--radius": t.radius,
|
|
518
538
|
"--shadow": t.shadow
|
|
519
539
|
};
|
|
540
|
+
}
|
|
541
|
+
function applyThemeTo(el, theme, palette, custom) {
|
|
542
|
+
const mode = resolveMode(theme);
|
|
543
|
+
const c = custom && palette ? custom[String(palette)] : void 0;
|
|
544
|
+
const pal = c ? String(palette) : clampPalette(palette);
|
|
545
|
+
const t = c && c.tokens && c.tokens[mode] || tokensOf(pal, mode);
|
|
546
|
+
el.setAttribute("data-theme", mode);
|
|
547
|
+
if (theme === "system") el.setAttribute("data-theme-pref", "system");
|
|
548
|
+
else el.removeAttribute("data-theme-pref");
|
|
549
|
+
el.setAttribute("data-palette", pal);
|
|
550
|
+
const map = themeCssVars(mode, palette, custom);
|
|
520
551
|
for (const k of Object.keys(map)) el.style.setProperty(k, map[k]);
|
|
521
552
|
el.style.background = t.bg;
|
|
522
553
|
el.style.color = t.fg;
|
|
523
554
|
return { theme: mode, palette: pal };
|
|
524
555
|
}
|
|
525
556
|
|
|
557
|
+
exports.GLOBAL_PALETTE_ID = GLOBAL_PALETTE_ID;
|
|
558
|
+
exports.LOCAL_PALETTE_ID = LOCAL_PALETTE_ID;
|
|
526
559
|
exports.PALETTES = PALETTES;
|
|
527
560
|
exports.applyThemeTo = applyThemeTo;
|
|
528
561
|
exports.clampMode = clampMode;
|
|
529
562
|
exports.clampPalette = clampPalette;
|
|
530
563
|
exports.cssVars = cssVars;
|
|
564
|
+
exports.effectivePalette = effectivePalette;
|
|
531
565
|
exports.parseThemeCss = parseThemeCss;
|
|
566
|
+
exports.resolveMode = resolveMode;
|
|
532
567
|
exports.runnerThemeCss = runnerThemeCss;
|
|
568
|
+
exports.selectedPalette = selectedPalette;
|
|
569
|
+
exports.themeCssVars = themeCssVars;
|
|
533
570
|
exports.themeLabelFromCss = themeLabelFromCss;
|
|
534
571
|
exports.tokensOf = tokensOf;
|
package/dist/themes.d.cts
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
/** Reserved palette id for an app's own `theme.css` (shown only in app scope). */
|
|
2
|
+
declare const LOCAL_PALETTE_ID = "__local__";
|
|
3
|
+
/** Reserved palette id meaning "ignore any `theme.css`, use the host palette". */
|
|
4
|
+
declare const GLOBAL_PALETTE_ID = "__global__";
|
|
5
|
+
/**
|
|
6
|
+
* Which palette an app actually renders with.
|
|
7
|
+
*
|
|
8
|
+
* An explicit user pick wins. With no pick, a shipped `theme.css` wins — that is what lets a
|
|
9
|
+
* facade carry its own look. `__global__` is the pick for "ignore the file": deleting
|
|
10
|
+
* `theme.json` would land back on the file, so "follow global" has to be stored, not cleared.
|
|
11
|
+
*/
|
|
12
|
+
declare function effectivePalette(stored: string | null | undefined, hasLocalTheme: boolean, hostPalette: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* What ThemePop ticks. Not the same as `effectivePalette`: following the host is one row, not a
|
|
15
|
+
* tick on whichever host palette happens to be selected — otherwise "inherit" and "pinned to
|
|
16
|
+
* 东京夜" would look identical.
|
|
17
|
+
*/
|
|
18
|
+
declare function selectedPalette(stored: string | null | undefined, hasLocalTheme: boolean): string;
|
|
1
19
|
type PaletteId = "default" | "tokyo" | "forest" | "matcha" | "yellow" | "zoro" | "hokage" | "slate";
|
|
2
20
|
type ModeId = "light" | "dark";
|
|
3
21
|
/** Full token bag for Host chrome + iframe apps (shadcn-compatible). */
|
|
@@ -42,6 +60,8 @@ declare function themeLabelFromCss(css: string, fallback: string): string;
|
|
|
42
60
|
/** Accept current ids and migrate removed palettes (ocean/violet → new families). */
|
|
43
61
|
declare function clampPalette(value: unknown): PaletteId;
|
|
44
62
|
declare function clampMode(value: unknown): ModeId;
|
|
63
|
+
/** Resolve `system` via prefers-color-scheme; otherwise clamp to light/dark. */
|
|
64
|
+
declare function resolveMode(value: unknown): ModeId;
|
|
45
65
|
declare function tokensOf(palette: PaletteId, mode: ModeId): TokenSet;
|
|
46
66
|
declare function cssVars(t: TokenSet): string;
|
|
47
67
|
/** CSS for the iframe runner: default + 5 palettes, each light/dark. */
|
|
@@ -55,9 +75,10 @@ type CustomPaletteMap = Record<string, {
|
|
|
55
75
|
dark: TokenSet;
|
|
56
76
|
};
|
|
57
77
|
}>;
|
|
78
|
+
declare function themeCssVars(theme: unknown, palette: unknown, custom?: CustomPaletteMap): Record<string, string>;
|
|
58
79
|
declare function applyThemeTo(el: HTMLElement, theme: unknown, palette: unknown, custom?: CustomPaletteMap): {
|
|
59
80
|
theme: ModeId;
|
|
60
81
|
palette: PaletteId;
|
|
61
82
|
};
|
|
62
83
|
|
|
63
|
-
export { type CustomPaletteMap, type ModeId, PALETTES, type PaletteId, type TokenSet, applyThemeTo, clampMode, clampPalette, cssVars, parseThemeCss, runnerThemeCss, themeLabelFromCss, tokensOf };
|
|
84
|
+
export { type CustomPaletteMap, GLOBAL_PALETTE_ID, LOCAL_PALETTE_ID, type ModeId, PALETTES, type PaletteId, type TokenSet, applyThemeTo, clampMode, clampPalette, cssVars, effectivePalette, parseThemeCss, resolveMode, runnerThemeCss, selectedPalette, themeCssVars, themeLabelFromCss, tokensOf };
|
package/dist/themes.d.ts
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
/** Reserved palette id for an app's own `theme.css` (shown only in app scope). */
|
|
2
|
+
declare const LOCAL_PALETTE_ID = "__local__";
|
|
3
|
+
/** Reserved palette id meaning "ignore any `theme.css`, use the host palette". */
|
|
4
|
+
declare const GLOBAL_PALETTE_ID = "__global__";
|
|
5
|
+
/**
|
|
6
|
+
* Which palette an app actually renders with.
|
|
7
|
+
*
|
|
8
|
+
* An explicit user pick wins. With no pick, a shipped `theme.css` wins — that is what lets a
|
|
9
|
+
* facade carry its own look. `__global__` is the pick for "ignore the file": deleting
|
|
10
|
+
* `theme.json` would land back on the file, so "follow global" has to be stored, not cleared.
|
|
11
|
+
*/
|
|
12
|
+
declare function effectivePalette(stored: string | null | undefined, hasLocalTheme: boolean, hostPalette: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* What ThemePop ticks. Not the same as `effectivePalette`: following the host is one row, not a
|
|
15
|
+
* tick on whichever host palette happens to be selected — otherwise "inherit" and "pinned to
|
|
16
|
+
* 东京夜" would look identical.
|
|
17
|
+
*/
|
|
18
|
+
declare function selectedPalette(stored: string | null | undefined, hasLocalTheme: boolean): string;
|
|
1
19
|
type PaletteId = "default" | "tokyo" | "forest" | "matcha" | "yellow" | "zoro" | "hokage" | "slate";
|
|
2
20
|
type ModeId = "light" | "dark";
|
|
3
21
|
/** Full token bag for Host chrome + iframe apps (shadcn-compatible). */
|
|
@@ -42,6 +60,8 @@ declare function themeLabelFromCss(css: string, fallback: string): string;
|
|
|
42
60
|
/** Accept current ids and migrate removed palettes (ocean/violet → new families). */
|
|
43
61
|
declare function clampPalette(value: unknown): PaletteId;
|
|
44
62
|
declare function clampMode(value: unknown): ModeId;
|
|
63
|
+
/** Resolve `system` via prefers-color-scheme; otherwise clamp to light/dark. */
|
|
64
|
+
declare function resolveMode(value: unknown): ModeId;
|
|
45
65
|
declare function tokensOf(palette: PaletteId, mode: ModeId): TokenSet;
|
|
46
66
|
declare function cssVars(t: TokenSet): string;
|
|
47
67
|
/** CSS for the iframe runner: default + 5 palettes, each light/dark. */
|
|
@@ -55,9 +75,10 @@ type CustomPaletteMap = Record<string, {
|
|
|
55
75
|
dark: TokenSet;
|
|
56
76
|
};
|
|
57
77
|
}>;
|
|
78
|
+
declare function themeCssVars(theme: unknown, palette: unknown, custom?: CustomPaletteMap): Record<string, string>;
|
|
58
79
|
declare function applyThemeTo(el: HTMLElement, theme: unknown, palette: unknown, custom?: CustomPaletteMap): {
|
|
59
80
|
theme: ModeId;
|
|
60
81
|
palette: PaletteId;
|
|
61
82
|
};
|
|
62
83
|
|
|
63
|
-
export { type CustomPaletteMap, type ModeId, PALETTES, type PaletteId, type TokenSet, applyThemeTo, clampMode, clampPalette, cssVars, parseThemeCss, runnerThemeCss, themeLabelFromCss, tokensOf };
|
|
84
|
+
export { type CustomPaletteMap, GLOBAL_PALETTE_ID, LOCAL_PALETTE_ID, type ModeId, PALETTES, type PaletteId, type TokenSet, applyThemeTo, clampMode, clampPalette, cssVars, effectivePalette, parseThemeCss, resolveMode, runnerThemeCss, selectedPalette, themeCssVars, themeLabelFromCss, tokensOf };
|
package/dist/themes.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { PALETTES, applyThemeTo, clampMode, clampPalette, cssVars, parseThemeCss, runnerThemeCss, themeLabelFromCss, tokensOf } from './chunk-
|
|
1
|
+
export { GLOBAL_PALETTE_ID, LOCAL_PALETTE_ID, PALETTES, applyThemeTo, clampMode, clampPalette, cssVars, effectivePalette, parseThemeCss, resolveMode, runnerThemeCss, selectedPalette, themeCssVars, themeLabelFromCss, tokensOf } from './chunk-JAWSEXOV.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monkey-mini-app/panel",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"files": [
|
|
43
43
|
"dist"
|
|
44
44
|
],
|
|
45
|
+
"license": "MIT",
|
|
45
46
|
"publishConfig": {
|
|
46
47
|
"access": "public"
|
|
47
48
|
}
|