@inkandswitch/patchwork-pkg-base 0.0.32 → 0.0.33
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/package.json +1 -1
- package/packages/theming/dist/{active-theme-K27UXDBG.js → active-theme-32OB4CH6.js} +2 -2
- package/packages/theming/dist/{chunk-K4OOO2TK.js → chunk-UVXMCWBQ.js} +13 -6
- package/packages/theming/dist/chunk-UVXMCWBQ.js.map +7 -0
- package/packages/theming/dist/{datatype-UUJVIZM7.js → datatype-NY2CT6T4.js} +2 -3
- package/packages/theming/dist/datatype-NY2CT6T4.js.map +7 -0
- package/packages/theming/dist/main.js +4 -4
- package/packages/theming/dist/{theme-titlebar-P2CODQGF.js → theme-titlebar-GZMRTVWM.js} +2 -2
- package/packages/theming/dist/{theme-tray-5L2KGCGD.js → theme-tray-MSIUUA2I.js} +2 -2
- package/packages/theming/dist/tool.js +1 -1
- package/packages/theming/dist/chunk-K4OOO2TK.js.map +0 -7
- package/packages/theming/dist/datatype-UUJVIZM7.js.map +0 -7
- /package/packages/theming/dist/{active-theme-K27UXDBG.js.map → active-theme-32OB4CH6.js.map} +0 -0
- /package/packages/theming/dist/{theme-titlebar-P2CODQGF.js.map → theme-titlebar-GZMRTVWM.js.map} +0 -0
- /package/packages/theming/dist/{theme-tray-5L2KGCGD.js.map → theme-tray-MSIUUA2I.js.map} +0 -0
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
setThemeForMode,
|
|
10
10
|
startActiveTheme,
|
|
11
11
|
startActiveThemeFromProvider
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-UVXMCWBQ.js";
|
|
13
13
|
import "./chunk-RATW7VZI.js";
|
|
14
14
|
export {
|
|
15
15
|
CURRENT_THEME_SELECTOR,
|
|
@@ -23,4 +23,4 @@ export {
|
|
|
23
23
|
startActiveTheme,
|
|
24
24
|
startActiveThemeFromProvider
|
|
25
25
|
};
|
|
26
|
-
//# sourceMappingURL=active-theme-
|
|
26
|
+
//# sourceMappingURL=active-theme-32OB4CH6.js.map
|
|
@@ -11,6 +11,14 @@ var theme_default = "./theme-RC7MV6WP.css";
|
|
|
11
11
|
|
|
12
12
|
// src/active-theme.ts
|
|
13
13
|
var CURRENT_THEME_SELECTOR = "patchwork:current-theme";
|
|
14
|
+
var FALLBACK_DEFAULTS = { light: "lychee", dark: "gloom" };
|
|
15
|
+
function defaultThemeIds() {
|
|
16
|
+
const root = document.documentElement;
|
|
17
|
+
return {
|
|
18
|
+
light: root.getAttribute("data-theme-light") || FALLBACK_DEFAULTS.light,
|
|
19
|
+
dark: root.getAttribute("data-theme-dark") || FALLBACK_DEFAULTS.dark
|
|
20
|
+
};
|
|
21
|
+
}
|
|
14
22
|
var bundledStyleUrls = [theme_default, lychee_default, gloom_default].map(
|
|
15
23
|
(href) => new URL(href, import.meta.url).href
|
|
16
24
|
);
|
|
@@ -47,16 +55,17 @@ function getMode() {
|
|
|
47
55
|
function getPreferredThemeId(prefs) {
|
|
48
56
|
const mode = getMode();
|
|
49
57
|
const themeId = prefs ? mode === "dark" ? prefs.dark : prefs.light : void 0;
|
|
50
|
-
return themeId || (mode
|
|
58
|
+
return themeId || defaultThemeIds()[mode];
|
|
51
59
|
}
|
|
52
60
|
function snapshot() {
|
|
53
61
|
const prefs = currentPrefsHandle?.doc();
|
|
54
62
|
const mode = getMode();
|
|
63
|
+
const defaults = defaultThemeIds();
|
|
55
64
|
return {
|
|
56
65
|
mode,
|
|
57
66
|
themeId: getPreferredThemeId(prefs),
|
|
58
|
-
light: prefs?.light ||
|
|
59
|
-
dark: prefs?.dark ||
|
|
67
|
+
light: prefs?.light || defaults.light,
|
|
68
|
+
dark: prefs?.dark || defaults.dark,
|
|
60
69
|
preferencesUrl: currentPrefsHandle?.url
|
|
61
70
|
};
|
|
62
71
|
}
|
|
@@ -108,8 +117,6 @@ function subscribeToProvider(element, selector, onValue) {
|
|
|
108
117
|
function ensureThemePreferencesShape(prefsHandle) {
|
|
109
118
|
prefsHandle.change((doc) => {
|
|
110
119
|
doc["@patchwork"] = { type: "theme-preferences" };
|
|
111
|
-
if (!doc.light) doc.light = "lychee";
|
|
112
|
-
if (!doc.dark) doc.dark = "gloom";
|
|
113
120
|
});
|
|
114
121
|
}
|
|
115
122
|
async function useThemePreferencesHandle(prefsHandle) {
|
|
@@ -278,4 +285,4 @@ export {
|
|
|
278
285
|
hasThemePreferences,
|
|
279
286
|
onActiveThemeChange
|
|
280
287
|
};
|
|
281
|
-
//# sourceMappingURL=chunk-
|
|
288
|
+
//# sourceMappingURL=chunk-UVXMCWBQ.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/active-theme.ts"],
|
|
4
|
+
"sourcesContent": ["import {getRegistry} from \"@inkandswitch/patchwork-plugins\"\nimport themeCssUrl from \"./theme.css\"\nimport lycheeCssUrl from \"./lychee.css\"\nimport gloomCssUrl from \"./gloom.css\"\n\ntype ActiveThemeState = {\n\tmode: \"light\" | \"dark\"\n\tthemeId: string\n\tlight: string\n\tdark: string\n\tpreferencesUrl?: string\n}\n\ntype ThemePreferencesHandle = {\n\turl?: string\n\tdoc(): any\n\tchange(fn: (doc: any) => void): void\n\ton?(event: \"change\", listener: () => void): void\n\toff?(event: \"change\", listener: () => void): void\n\twhenReady?(): Promise<unknown>\n}\n\nexport const CURRENT_THEME_SELECTOR = \"patchwork:current-theme\"\n\n/**\n * Which themes an account that has not chosen one starts on. A site states\n * this on its root element \u2014 `<html data-theme-light=\"warm\" data-theme-dark=\"dark\">`\n * \u2014 so the answer comes from the site itself rather than from whichever\n * module happened to load last. `lychee`/`gloom` apply when it says nothing.\n *\n * Nothing is written to the preferences document: an unset preference resolves\n * through here at read time, so the theme a user picked explicitly is never\n * overwritten, and a site changing its defaults moves everyone who never\n * picked one.\n */\nconst FALLBACK_DEFAULTS = {light: \"lychee\", dark: \"gloom\"}\n\nfunction defaultThemeIds() {\n\tconst root = document.documentElement\n\treturn {\n\t\tlight: root.getAttribute(\"data-theme-light\") || FALLBACK_DEFAULTS.light,\n\t\tdark: root.getAttribute(\"data-theme-dark\") || FALLBACK_DEFAULTS.dark,\n\t}\n}\n\nconst bundledStyleUrls = [themeCssUrl, lycheeCssUrl, gloomCssUrl].map(\n\t(href) => new URL(href, import.meta.url).href\n)\nconst bundledStyles = new Set(bundledStyleUrls)\nconst themeLinks = new Map<string, HTMLLinkElement>()\nconst listeners = new Set<(state: ActiveThemeState) => void>()\n\nlet started = false\nlet stylesBootstrapped = false\nlet currentPrefsHandle: ThemePreferencesHandle | undefined\nlet currentState: ActiveThemeState | undefined\nlet storageStarted = false\nlet storageElement: HTMLElement | undefined\nlet unsubscribeStorage: (() => void) | undefined\nlet unsubscribePrefsChange: (() => void) | undefined\n\nconst TOOL_STORAGE_ID = \"theme-preferences\"\n\nfunction ensureThemeLink(style: string) {\n\tif (themeLinks.has(style)) return\n\tconst link = document.createElement(\"link\")\n\tlink.rel = \"stylesheet\"\n\tlink.href = style\n\tdocument.head.appendChild(link)\n\tthemeLinks.set(style, link)\n}\n\nfunction removeThemeLink(style: string) {\n\tconst link = themeLinks.get(style)\n\tif (link) {\n\t\tlink.remove()\n\t\tthemeLinks.delete(style)\n\t}\n}\n\nfunction getMode(): \"light\" | \"dark\" {\n\treturn window.matchMedia(\"(prefers-color-scheme: dark)\").matches\n\t\t? \"dark\"\n\t\t: \"light\"\n}\n\nfunction getPreferredThemeId(prefs: any): string {\n\tconst mode = getMode()\n\tconst themeId = prefs ? (mode === \"dark\" ? prefs.dark : prefs.light) : undefined\n\treturn themeId || defaultThemeIds()[mode]\n}\n\nfunction snapshot(): ActiveThemeState {\n\tconst prefs = currentPrefsHandle?.doc()\n\tconst mode = getMode()\n\tconst defaults = defaultThemeIds()\n\treturn {\n\t\tmode,\n\t\tthemeId: getPreferredThemeId(prefs),\n\t\tlight: prefs?.light || defaults.light,\n\t\tdark: prefs?.dark || defaults.dark,\n\t\tpreferencesUrl: currentPrefsHandle?.url,\n\t}\n}\n\nfunction emit() {\n\tcurrentState = snapshot()\n\tfor (const listener of listeners) listener(currentState)\n}\n\nfunction applyTheme(themeId: string) {\n\tif (themeId) document.documentElement.setAttribute(\"theme\", themeId)\n}\n\nfunction applyFromPrefs() {\n\tapplyTheme(getPreferredThemeId(currentPrefsHandle?.doc()))\n\temit()\n}\n\nfunction subscribeToProvider<T>(\n\telement: HTMLElement,\n\tselector: Record<string, unknown>,\n\tonValue: (value: T) => void\n) {\n\tconst view = element.closest(\"patchwork-view\")\n\tconst dispatchElement = (view as HTMLElement) ?? element\n\tconst channel = new MessageChannel()\n\tconst port = channel.port2\n\tconst controller = new AbortController()\n\n\tport.addEventListener(\n\t\t\"message\",\n\t\t(event: MessageEvent) => {\n\t\t\tif ((event.data as any)?.type === \"change\") onValue((event.data as any).value as T)\n\t\t},\n\t\t{signal: controller.signal}\n\t)\n\tport.start()\n\n\tdispatchElement.dispatchEvent(\n\t\tnew CustomEvent(\"patchwork:subscribe\", {\n\t\t\tdetail: {selector, port: channel.port1},\n\t\t\tbubbles: true,\n\t\t\tcomposed: true,\n\t\t})\n\t)\n\n\treturn () => {\n\t\tif (controller.signal.aborted) return\n\t\tcontroller.abort()\n\t\ttry {\n\t\t\tport.postMessage({type: \"unsubscribe\"})\n\t\t} catch {}\n\t\ttry {\n\t\t\tport.close()\n\t\t} catch {}\n\t}\n}\n\nfunction ensureThemePreferencesShape(prefsHandle: ThemePreferencesHandle) {\n\tprefsHandle.change((doc: any) => {\n\t\tdoc[\"@patchwork\"] = {type: \"theme-preferences\"}\n\t})\n}\n\nasync function useThemePreferencesHandle(prefsHandle: ThemePreferencesHandle) {\n\tawait prefsHandle.whenReady?.()\n\tensureThemePreferencesShape(prefsHandle)\n\n\tif (currentPrefsHandle === prefsHandle) return\n\tif (\n\t\tcurrentPrefsHandle?.url &&\n\t\tprefsHandle.url &&\n\t\tcurrentPrefsHandle.url === prefsHandle.url\n\t) {\n\t\treturn\n\t}\n\n\tunsubscribePrefsChange?.()\n\tcurrentPrefsHandle = prefsHandle\n\tapplyFromPrefs()\n\n\tprefsHandle.on?.(\"change\", applyFromPrefs)\n\tunsubscribePrefsChange = () => prefsHandle.off?.(\"change\", applyFromPrefs)\n}\n\nasync function useToolStoragePreferences(element: HTMLElement, storageUrl: string) {\n\tconst repo = (element as any).repo ?? (window as any).repo\n\tif (!repo) return\n\n\tconst prefsHandle = await repo.find(storageUrl)\n\tawait useThemePreferencesHandle(prefsHandle)\n}\n\nfunction connectThemePreferences(element: HTMLElement) {\n\tif (currentPrefsHandle) return\n\tif (storageStarted && storageElement === element) return\n\n\tunsubscribeStorage?.()\n\tstorageStarted = true\n\tstorageElement = element\n\n\tlet lastStorageUrl: string | undefined\n\n\tunsubscribeStorage = subscribeToProvider<string | undefined>(\n\t\telement,\n\t\t{type: \"patchwork:tool-storage\", toolId: TOOL_STORAGE_ID},\n\t\t(storageUrl) => {\n\t\t\tif (!storageUrl || storageUrl === lastStorageUrl) return\n\t\t\tlastStorageUrl = storageUrl\n\t\t\tuseToolStoragePreferences(element, storageUrl).catch(() => {\n\t\t\t\t// Theme preferences are best-effort; keep the default theme.\n\t\t\t})\n\t\t}\n\t)\n}\n\nfunction watchThemeRegistry() {\n\tconst themeRegistry = getRegistry(\"patchwork:theme\") as any\n\n\tfor (const theme of themeRegistry.all?.() || []) {\n\t\tif (theme.style) ensureThemeLink(theme.style)\n\t}\n\n\tthemeRegistry.on(\"registered\", (plugin: any) => {\n\t\tif (plugin.style) ensureThemeLink(plugin.style)\n\t})\n\tthemeRegistry.on(\"removed\", () => {\n\t\tconst knownStyles = new Set(\n\t\t\t(themeRegistry.all?.() || [])\n\t\t\t\t.map((t: any) => t.style)\n\t\t\t\t.filter(Boolean)\n\t\t)\n\t\tfor (const [style] of themeLinks) {\n\t\t\tif (!bundledStyles.has(style) && !knownStyles.has(style)) {\n\t\t\t\tremoveThemeLink(style)\n\t\t\t}\n\t\t}\n\t})\n}\n\n// Load the bundled theme stylesheets and keep the registry-provided ones in\n// sync. Idempotent \u2014 safe to call from every entry point. This is the CSS side\n// of theming, independent of where the *active* theme id is sourced from.\nfunction bootstrapThemeStyles() {\n\tif (stylesBootstrapped) return\n\tstylesBootstrapped = true\n\tfor (const href of bundledStyleUrls) ensureThemeLink(href)\n\twatchThemeRegistry()\n}\n\nexport function startActiveTheme(\n\telement?: HTMLElement,\n\tpreferencesHandle?: ThemePreferencesHandle\n) {\n\tif (preferencesHandle) {\n\t\tuseThemePreferencesHandle(preferencesHandle).catch(() => {\n\t\t\t// Theme preferences are best-effort; keep the default theme.\n\t\t})\n\t} else if (element) {\n\t\tconnectThemePreferences(element)\n\t}\n\tif (started) return\n\tstarted = true\n\n\tbootstrapThemeStyles()\n\tapplyFromPrefs()\n\n\twindow\n\t\t.matchMedia(\"(prefers-color-scheme: dark)\")\n\t\t.addEventListener(\"change\", applyFromPrefs)\n}\n\n/**\n * Drive the active theme from a `patchwork:current-theme` provider instead of\n * from local preferences. Used by the titlebar theme tool, which runs isolated\n * and mirrors whatever theme the host is showing: it applies each theme id the\n * provider emits and re-applies whenever that value changes.\n *\n * Stylesheets are still loaded locally so the referenced themes render; only\n * the *choice* of active theme comes from the provider. Deliberately does not\n * wire up preferences or the prefers-color-scheme listener \u2014 those would fight\n * the provider for control of the `theme` attribute.\n *\n * @returns an unsubscribe function.\n */\nexport function startActiveThemeFromProvider(element: HTMLElement) {\n\tbootstrapThemeStyles()\n\n\treturn subscribeToProvider<string | ActiveThemeState | undefined>(\n\t\telement,\n\t\t{type: CURRENT_THEME_SELECTOR},\n\t\t(value) => {\n\t\t\tconst themeId = typeof value === \"string\" ? value : value?.themeId\n\t\t\tif (themeId) applyTheme(themeId)\n\t\t}\n\t)\n}\n\ntype CurrentThemeSubscribeEvent = CustomEvent<{\n\tselector: {type: string; [key: string]: unknown}\n\tport: MessagePort\n}>\n\n/**\n * Answer `patchwork:current-theme` subscriptions with the active theme id,\n * pushing a fresh value whenever the theme changes. This is the host-side\n * counterpart to {@link startActiveThemeFromProvider}: it lets isolated tools\n * (the titlebar theme tool) mirror the host's active theme across the isolation\n * boundary, where the theme is relayed by the providers bridge.\n *\n * The listener is installed on the given root (the theme tray installs it on\n * `document.documentElement`) so that bridged `patchwork:subscribe` events \u2014\n * which bubble up to `<html>` \u2014 reach it. Implements the provider port protocol\n * directly to avoid a dependency on `@inkandswitch/patchwork-providers`.\n *\n * @returns an unsubscribe function that removes the listener and tears down any\n * live subscriptions.\n */\nexport function serveCurrentThemeProvider(root: HTMLElement): () => void {\n\tconst responders = new Set<() => void>()\n\n\tconst onSubscribe = (event: Event) => {\n\t\tconst detail = (event as CurrentThemeSubscribeEvent).detail\n\t\tif (!detail || detail.selector?.type !== CURRENT_THEME_SELECTOR) return\n\t\tevent.stopPropagation()\n\n\t\tconst port = detail.port\n\t\tlet alive = true\n\t\tconst emit = () => {\n\t\t\tif (!alive) return\n\t\t\tport.postMessage({type: \"change\", value: getActiveThemeState().themeId})\n\t\t}\n\t\tconst removeThemeListener = onActiveThemeChange(emit)\n\n\t\tconst stop = () => {\n\t\t\tif (!alive) return\n\t\t\talive = false\n\t\t\tremoveThemeListener()\n\t\t\tresponders.delete(stop)\n\t\t\ttry {\n\t\t\t\tport.close()\n\t\t\t} catch {}\n\t\t}\n\t\tresponders.add(stop)\n\n\t\tport.onmessage = (e: MessageEvent) => {\n\t\t\tif ((e.data as any)?.type === \"unsubscribe\") stop()\n\t\t}\n\t\tport.start?.()\n\t}\n\n\troot.addEventListener(\"patchwork:subscribe\", onSubscribe)\n\n\treturn () => {\n\t\troot.removeEventListener(\"patchwork:subscribe\", onSubscribe)\n\t\tfor (const stop of [...responders]) stop()\n\t}\n}\n\nexport function getActiveThemeState() {\n\treturn currentState || snapshot()\n}\n\n/**\n * Best-effort color scheme for a theme. Prefers the plugin's declared\n * `colorScheme`, otherwise sniffs `color-scheme: light|dark` out of the theme's\n * stylesheet. Returns `undefined` when neither is available (treated as\n * scheme-agnostic by callers). Shared by the theme tray and the theme picker\n * tool so they group light/dark themes the same way.\n */\nexport async function detectColorScheme(theme: {\n\tcolorScheme?: \"light\" | \"dark\"\n\tstyle?: string\n}): Promise<\"light\" | \"dark\" | undefined> {\n\tif (theme.colorScheme) return theme.colorScheme\n\tif (!theme.style) return undefined\n\ttry {\n\t\tconst res = await fetch(theme.style)\n\t\tconst css = await res.text()\n\t\tconst match = css.match(/color-scheme:\\s*(light|dark)/)\n\t\treturn (match?.[1] as \"light\" | \"dark\") ?? undefined\n\t} catch {\n\t\treturn undefined\n\t}\n}\n\nexport function setThemeForCurrentMode(themeId: string) {\n\tconst mode = getMode()\n\tsetThemeForMode(mode, themeId)\n}\n\nexport function setThemeForMode(mode: \"light\" | \"dark\", themeId: string) {\n\tcurrentPrefsHandle?.change((doc: any) => {\n\t\tdoc[mode] = themeId\n\t})\n}\n\nexport function hasThemePreferences() {\n\treturn Boolean(currentPrefsHandle)\n}\n\nexport function onActiveThemeChange(listener: (state: ActiveThemeState) => void) {\n\tlisteners.add(listener)\n\tlistener(getActiveThemeState())\n\treturn () => listeners.delete(listener)\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;AAAA,SAAQ,mBAAkB;;;;;;AAsBnB,IAAM,yBAAyB;AAatC,IAAM,oBAAoB,EAAC,OAAO,UAAU,MAAM,QAAO;AAEzD,SAAS,kBAAkB;AAC1B,QAAM,OAAO,SAAS;AACtB,SAAO;AAAA,IACN,OAAO,KAAK,aAAa,kBAAkB,KAAK,kBAAkB;AAAA,IAClE,MAAM,KAAK,aAAa,iBAAiB,KAAK,kBAAkB;AAAA,EACjE;AACD;AAEA,IAAM,mBAAmB,CAAC,eAAa,gBAAc,aAAW,EAAE;AAAA,EACjE,CAAC,SAAS,IAAI,IAAI,MAAM,YAAY,GAAG,EAAE;AAC1C;AACA,IAAM,gBAAgB,IAAI,IAAI,gBAAgB;AAC9C,IAAM,aAAa,oBAAI,IAA6B;AACpD,IAAM,YAAY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EACd;AAEA,OAAK,iBAAiB,uBAAuB,WAAW;AAExD,SAAO,MAAM;AACZ,SAAK,oBAAoB,uBAAuB,WAAW;AAC3D,eAAW,QAAQ,CAAC,GAAG,UAAU,EAAG,MAAK;AAAA,EAC1C;AACD;AAEO,SAAS,sBAAsB;AACrC,SAAO,gBAAgB,SAAS;AACjC;AASA,eAAsB,kBAAkB,OAGE;AACzC,MAAI,MAAM,YAAa,QAAO,MAAM;AACpC,MAAI,CAAC,MAAM,MAAO,QAAO;AACzB,MAAI;AACH,UAAM,MAAM,MAAM,MAAM,MAAM,KAAK;AACnC,UAAM,MAAM,MAAM,IAAI,KAAK;AAC3B,UAAM,QAAQ,IAAI,MAAM,8BAA8B;AACtD,WAAQ,QAAQ,CAAC,KAA0B;AAAA,EAC5C,QAAQ;AACP,WAAO;AAAA,EACR;AACD;AAEO,SAAS,uBAAuB,SAAiB;AACvD,QAAM,OAAO,QAAQ;AACrB,kBAAgB,MAAM,OAAO;AAC9B;AAEO,SAAS,gBAAgB,MAAwB,SAAiB;AACxE,sBAAoB,OAAO,CAAC,QAAa;AACxC,QAAI,IAAI,IAAI;AAAA,EACb,CAAC;AACF;AAEO,SAAS,sBAAsB;AACrC,SAAO,QAAQ,kBAAkB;AAClC;AAEO,SAAS,oBAAoB,UAA6C;AAChF,YAAU,IAAI,QAAQ;AACtB,WAAS,oBAAoB,CAAC;AAC9B,SAAO,MAAM,UAAU,OAAO,QAAQ;AACvC;",
|
|
6
|
+
"names": ["emit"]
|
|
7
|
+
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
// src/datatype.ts
|
|
2
2
|
var ThemePreferencesDatatype = {
|
|
3
3
|
init(doc) {
|
|
4
|
-
doc
|
|
5
|
-
doc.dark = "gloom";
|
|
4
|
+
doc["@patchwork"] = { type: "theme-preferences" };
|
|
6
5
|
},
|
|
7
6
|
getTitle() {
|
|
8
7
|
return "Theme Preferences";
|
|
@@ -13,4 +12,4 @@ var ThemePreferencesDatatype = {
|
|
|
13
12
|
export {
|
|
14
13
|
ThemePreferencesDatatype
|
|
15
14
|
};
|
|
16
|
-
//# sourceMappingURL=datatype-
|
|
15
|
+
//# sourceMappingURL=datatype-NY2CT6T4.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/datatype.ts"],
|
|
4
|
+
"sourcesContent": ["export const ThemePreferencesDatatype = {\n\tinit(doc: any) {\n\t\tdoc[\"@patchwork\"] = {type: \"theme-preferences\"}\n\t},\n\tgetTitle() {\n\t\treturn \"Theme Preferences\"\n\t},\n\tsetTitle() {\n\t\t// Theme preferences doc title is not user-editable\n\t},\n}\n"],
|
|
5
|
+
"mappings": ";AAAO,IAAM,2BAA2B;AAAA,EACvC,KAAK,KAAU;AACd,QAAI,YAAY,IAAI,EAAC,MAAM,oBAAmB;AAAA,EAC/C;AAAA,EACA,WAAW;AACV,WAAO;AAAA,EACR;AAAA,EACA,WAAW;AAAA,EAEX;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
|
|
6
6
|
// src/main.ts
|
|
7
7
|
(async function() {
|
|
8
|
-
(await import("./active-theme-
|
|
8
|
+
(await import("./active-theme-32OB4CH6.js")).startActiveTheme();
|
|
9
9
|
})();
|
|
10
10
|
var plugins = [
|
|
11
11
|
{
|
|
@@ -43,7 +43,7 @@ var plugins = [
|
|
|
43
43
|
icon: "Palette",
|
|
44
44
|
unlisted: true,
|
|
45
45
|
async load() {
|
|
46
|
-
const { ThemePreferencesDatatype } = await import("./datatype-
|
|
46
|
+
const { ThemePreferencesDatatype } = await import("./datatype-NY2CT6T4.js");
|
|
47
47
|
return ThemePreferencesDatatype;
|
|
48
48
|
}
|
|
49
49
|
},
|
|
@@ -57,7 +57,7 @@ var plugins = [
|
|
|
57
57
|
unlisted: true,
|
|
58
58
|
forTitleBar: true,
|
|
59
59
|
async load() {
|
|
60
|
-
const { ThemeTitlebarTool } = await import("./theme-titlebar-
|
|
60
|
+
const { ThemeTitlebarTool } = await import("./theme-titlebar-GZMRTVWM.js");
|
|
61
61
|
return ThemeTitlebarTool;
|
|
62
62
|
}
|
|
63
63
|
},
|
|
@@ -68,7 +68,7 @@ var plugins = [
|
|
|
68
68
|
icon: "Palette",
|
|
69
69
|
tags: ["system-tray"],
|
|
70
70
|
async load() {
|
|
71
|
-
const { ThemeTray } = await import("./theme-tray-
|
|
71
|
+
const { ThemeTray } = await import("./theme-tray-MSIUUA2I.js");
|
|
72
72
|
return ThemeTray;
|
|
73
73
|
}
|
|
74
74
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
startActiveThemeFromProvider
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-UVXMCWBQ.js";
|
|
4
4
|
import "./chunk-RATW7VZI.js";
|
|
5
5
|
|
|
6
6
|
// src/theme-titlebar.ts
|
|
@@ -18,4 +18,4 @@ function ThemeTitlebarTool(_handle, element) {
|
|
|
18
18
|
export {
|
|
19
19
|
ThemeTitlebarTool
|
|
20
20
|
};
|
|
21
|
-
//# sourceMappingURL=theme-titlebar-
|
|
21
|
+
//# sourceMappingURL=theme-titlebar-GZMRTVWM.js.map
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
serveCurrentThemeProvider,
|
|
6
6
|
setThemeForCurrentMode,
|
|
7
7
|
startActiveTheme
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-UVXMCWBQ.js";
|
|
9
9
|
import "./chunk-RATW7VZI.js";
|
|
10
10
|
|
|
11
11
|
// src/theme-tray.tsx
|
|
@@ -348,4 +348,4 @@ _$delegateEvents(["click", "input"]);
|
|
|
348
348
|
export {
|
|
349
349
|
ThemeTray
|
|
350
350
|
};
|
|
351
|
-
//# sourceMappingURL=theme-tray-
|
|
351
|
+
//# sourceMappingURL=theme-tray-MSIUUA2I.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/active-theme.ts"],
|
|
4
|
-
"sourcesContent": ["import {getRegistry} from \"@inkandswitch/patchwork-plugins\"\nimport themeCssUrl from \"./theme.css\"\nimport lycheeCssUrl from \"./lychee.css\"\nimport gloomCssUrl from \"./gloom.css\"\n\ntype ActiveThemeState = {\n\tmode: \"light\" | \"dark\"\n\tthemeId: string\n\tlight: string\n\tdark: string\n\tpreferencesUrl?: string\n}\n\ntype ThemePreferencesHandle = {\n\turl?: string\n\tdoc(): any\n\tchange(fn: (doc: any) => void): void\n\ton?(event: \"change\", listener: () => void): void\n\toff?(event: \"change\", listener: () => void): void\n\twhenReady?(): Promise<unknown>\n}\n\nexport const CURRENT_THEME_SELECTOR = \"patchwork:current-theme\"\n\nconst bundledStyleUrls = [themeCssUrl, lycheeCssUrl, gloomCssUrl].map(\n\t(href) => new URL(href, import.meta.url).href\n)\nconst bundledStyles = new Set(bundledStyleUrls)\nconst themeLinks = new Map<string, HTMLLinkElement>()\nconst listeners = new Set<(state: ActiveThemeState) => void>()\n\nlet started = false\nlet stylesBootstrapped = false\nlet currentPrefsHandle: ThemePreferencesHandle | undefined\nlet currentState: ActiveThemeState | undefined\nlet storageStarted = false\nlet storageElement: HTMLElement | undefined\nlet unsubscribeStorage: (() => void) | undefined\nlet unsubscribePrefsChange: (() => void) | undefined\n\nconst TOOL_STORAGE_ID = \"theme-preferences\"\n\nfunction ensureThemeLink(style: string) {\n\tif (themeLinks.has(style)) return\n\tconst link = document.createElement(\"link\")\n\tlink.rel = \"stylesheet\"\n\tlink.href = style\n\tdocument.head.appendChild(link)\n\tthemeLinks.set(style, link)\n}\n\nfunction removeThemeLink(style: string) {\n\tconst link = themeLinks.get(style)\n\tif (link) {\n\t\tlink.remove()\n\t\tthemeLinks.delete(style)\n\t}\n}\n\nfunction getMode(): \"light\" | \"dark\" {\n\treturn window.matchMedia(\"(prefers-color-scheme: dark)\").matches\n\t\t? \"dark\"\n\t\t: \"light\"\n}\n\nfunction getPreferredThemeId(prefs: any): string {\n\tconst mode = getMode()\n\tconst themeId = prefs ? (mode === \"dark\" ? prefs.dark : prefs.light) : undefined\n\treturn themeId || (mode === \"dark\" ? \"gloom\" : \"lychee\")\n}\n\nfunction snapshot(): ActiveThemeState {\n\tconst prefs = currentPrefsHandle?.doc()\n\tconst mode = getMode()\n\treturn {\n\t\tmode,\n\t\tthemeId: getPreferredThemeId(prefs),\n\t\tlight: prefs?.light || \"lychee\",\n\t\tdark: prefs?.dark || \"gloom\",\n\t\tpreferencesUrl: currentPrefsHandle?.url,\n\t}\n}\n\nfunction emit() {\n\tcurrentState = snapshot()\n\tfor (const listener of listeners) listener(currentState)\n}\n\nfunction applyTheme(themeId: string) {\n\tif (themeId) document.documentElement.setAttribute(\"theme\", themeId)\n}\n\nfunction applyFromPrefs() {\n\tapplyTheme(getPreferredThemeId(currentPrefsHandle?.doc()))\n\temit()\n}\n\nfunction subscribeToProvider<T>(\n\telement: HTMLElement,\n\tselector: Record<string, unknown>,\n\tonValue: (value: T) => void\n) {\n\tconst view = element.closest(\"patchwork-view\")\n\tconst dispatchElement = (view as HTMLElement) ?? element\n\tconst channel = new MessageChannel()\n\tconst port = channel.port2\n\tconst controller = new AbortController()\n\n\tport.addEventListener(\n\t\t\"message\",\n\t\t(event: MessageEvent) => {\n\t\t\tif ((event.data as any)?.type === \"change\") onValue((event.data as any).value as T)\n\t\t},\n\t\t{signal: controller.signal}\n\t)\n\tport.start()\n\n\tdispatchElement.dispatchEvent(\n\t\tnew CustomEvent(\"patchwork:subscribe\", {\n\t\t\tdetail: {selector, port: channel.port1},\n\t\t\tbubbles: true,\n\t\t\tcomposed: true,\n\t\t})\n\t)\n\n\treturn () => {\n\t\tif (controller.signal.aborted) return\n\t\tcontroller.abort()\n\t\ttry {\n\t\t\tport.postMessage({type: \"unsubscribe\"})\n\t\t} catch {}\n\t\ttry {\n\t\t\tport.close()\n\t\t} catch {}\n\t}\n}\n\nfunction ensureThemePreferencesShape(prefsHandle: ThemePreferencesHandle) {\n\tprefsHandle.change((doc: any) => {\n\t\tdoc[\"@patchwork\"] = {type: \"theme-preferences\"}\n\t\tif (!doc.light) doc.light = \"lychee\"\n\t\tif (!doc.dark) doc.dark = \"gloom\"\n\t})\n}\n\nasync function useThemePreferencesHandle(prefsHandle: ThemePreferencesHandle) {\n\tawait prefsHandle.whenReady?.()\n\tensureThemePreferencesShape(prefsHandle)\n\n\tif (currentPrefsHandle === prefsHandle) return\n\tif (\n\t\tcurrentPrefsHandle?.url &&\n\t\tprefsHandle.url &&\n\t\tcurrentPrefsHandle.url === prefsHandle.url\n\t) {\n\t\treturn\n\t}\n\n\tunsubscribePrefsChange?.()\n\tcurrentPrefsHandle = prefsHandle\n\tapplyFromPrefs()\n\n\tprefsHandle.on?.(\"change\", applyFromPrefs)\n\tunsubscribePrefsChange = () => prefsHandle.off?.(\"change\", applyFromPrefs)\n}\n\nasync function useToolStoragePreferences(element: HTMLElement, storageUrl: string) {\n\tconst repo = (element as any).repo ?? (window as any).repo\n\tif (!repo) return\n\n\tconst prefsHandle = await repo.find(storageUrl)\n\tawait useThemePreferencesHandle(prefsHandle)\n}\n\nfunction connectThemePreferences(element: HTMLElement) {\n\tif (currentPrefsHandle) return\n\tif (storageStarted && storageElement === element) return\n\n\tunsubscribeStorage?.()\n\tstorageStarted = true\n\tstorageElement = element\n\n\tlet lastStorageUrl: string | undefined\n\n\tunsubscribeStorage = subscribeToProvider<string | undefined>(\n\t\telement,\n\t\t{type: \"patchwork:tool-storage\", toolId: TOOL_STORAGE_ID},\n\t\t(storageUrl) => {\n\t\t\tif (!storageUrl || storageUrl === lastStorageUrl) return\n\t\t\tlastStorageUrl = storageUrl\n\t\t\tuseToolStoragePreferences(element, storageUrl).catch(() => {\n\t\t\t\t// Theme preferences are best-effort; keep the default theme.\n\t\t\t})\n\t\t}\n\t)\n}\n\nfunction watchThemeRegistry() {\n\tconst themeRegistry = getRegistry(\"patchwork:theme\") as any\n\n\tfor (const theme of themeRegistry.all?.() || []) {\n\t\tif (theme.style) ensureThemeLink(theme.style)\n\t}\n\n\tthemeRegistry.on(\"registered\", (plugin: any) => {\n\t\tif (plugin.style) ensureThemeLink(plugin.style)\n\t})\n\tthemeRegistry.on(\"removed\", () => {\n\t\tconst knownStyles = new Set(\n\t\t\t(themeRegistry.all?.() || [])\n\t\t\t\t.map((t: any) => t.style)\n\t\t\t\t.filter(Boolean)\n\t\t)\n\t\tfor (const [style] of themeLinks) {\n\t\t\tif (!bundledStyles.has(style) && !knownStyles.has(style)) {\n\t\t\t\tremoveThemeLink(style)\n\t\t\t}\n\t\t}\n\t})\n}\n\n// Load the bundled theme stylesheets and keep the registry-provided ones in\n// sync. Idempotent \u2014 safe to call from every entry point. This is the CSS side\n// of theming, independent of where the *active* theme id is sourced from.\nfunction bootstrapThemeStyles() {\n\tif (stylesBootstrapped) return\n\tstylesBootstrapped = true\n\tfor (const href of bundledStyleUrls) ensureThemeLink(href)\n\twatchThemeRegistry()\n}\n\nexport function startActiveTheme(\n\telement?: HTMLElement,\n\tpreferencesHandle?: ThemePreferencesHandle\n) {\n\tif (preferencesHandle) {\n\t\tuseThemePreferencesHandle(preferencesHandle).catch(() => {\n\t\t\t// Theme preferences are best-effort; keep the default theme.\n\t\t})\n\t} else if (element) {\n\t\tconnectThemePreferences(element)\n\t}\n\tif (started) return\n\tstarted = true\n\n\tbootstrapThemeStyles()\n\tapplyFromPrefs()\n\n\twindow\n\t\t.matchMedia(\"(prefers-color-scheme: dark)\")\n\t\t.addEventListener(\"change\", applyFromPrefs)\n}\n\n/**\n * Drive the active theme from a `patchwork:current-theme` provider instead of\n * from local preferences. Used by the titlebar theme tool, which runs isolated\n * and mirrors whatever theme the host is showing: it applies each theme id the\n * provider emits and re-applies whenever that value changes.\n *\n * Stylesheets are still loaded locally so the referenced themes render; only\n * the *choice* of active theme comes from the provider. Deliberately does not\n * wire up preferences or the prefers-color-scheme listener \u2014 those would fight\n * the provider for control of the `theme` attribute.\n *\n * @returns an unsubscribe function.\n */\nexport function startActiveThemeFromProvider(element: HTMLElement) {\n\tbootstrapThemeStyles()\n\n\treturn subscribeToProvider<string | ActiveThemeState | undefined>(\n\t\telement,\n\t\t{type: CURRENT_THEME_SELECTOR},\n\t\t(value) => {\n\t\t\tconst themeId = typeof value === \"string\" ? value : value?.themeId\n\t\t\tif (themeId) applyTheme(themeId)\n\t\t}\n\t)\n}\n\ntype CurrentThemeSubscribeEvent = CustomEvent<{\n\tselector: {type: string; [key: string]: unknown}\n\tport: MessagePort\n}>\n\n/**\n * Answer `patchwork:current-theme` subscriptions with the active theme id,\n * pushing a fresh value whenever the theme changes. This is the host-side\n * counterpart to {@link startActiveThemeFromProvider}: it lets isolated tools\n * (the titlebar theme tool) mirror the host's active theme across the isolation\n * boundary, where the theme is relayed by the providers bridge.\n *\n * The listener is installed on the given root (the theme tray installs it on\n * `document.documentElement`) so that bridged `patchwork:subscribe` events \u2014\n * which bubble up to `<html>` \u2014 reach it. Implements the provider port protocol\n * directly to avoid a dependency on `@inkandswitch/patchwork-providers`.\n *\n * @returns an unsubscribe function that removes the listener and tears down any\n * live subscriptions.\n */\nexport function serveCurrentThemeProvider(root: HTMLElement): () => void {\n\tconst responders = new Set<() => void>()\n\n\tconst onSubscribe = (event: Event) => {\n\t\tconst detail = (event as CurrentThemeSubscribeEvent).detail\n\t\tif (!detail || detail.selector?.type !== CURRENT_THEME_SELECTOR) return\n\t\tevent.stopPropagation()\n\n\t\tconst port = detail.port\n\t\tlet alive = true\n\t\tconst emit = () => {\n\t\t\tif (!alive) return\n\t\t\tport.postMessage({type: \"change\", value: getActiveThemeState().themeId})\n\t\t}\n\t\tconst removeThemeListener = onActiveThemeChange(emit)\n\n\t\tconst stop = () => {\n\t\t\tif (!alive) return\n\t\t\talive = false\n\t\t\tremoveThemeListener()\n\t\t\tresponders.delete(stop)\n\t\t\ttry {\n\t\t\t\tport.close()\n\t\t\t} catch {}\n\t\t}\n\t\tresponders.add(stop)\n\n\t\tport.onmessage = (e: MessageEvent) => {\n\t\t\tif ((e.data as any)?.type === \"unsubscribe\") stop()\n\t\t}\n\t\tport.start?.()\n\t}\n\n\troot.addEventListener(\"patchwork:subscribe\", onSubscribe)\n\n\treturn () => {\n\t\troot.removeEventListener(\"patchwork:subscribe\", onSubscribe)\n\t\tfor (const stop of [...responders]) stop()\n\t}\n}\n\nexport function getActiveThemeState() {\n\treturn currentState || snapshot()\n}\n\n/**\n * Best-effort color scheme for a theme. Prefers the plugin's declared\n * `colorScheme`, otherwise sniffs `color-scheme: light|dark` out of the theme's\n * stylesheet. Returns `undefined` when neither is available (treated as\n * scheme-agnostic by callers). Shared by the theme tray and the theme picker\n * tool so they group light/dark themes the same way.\n */\nexport async function detectColorScheme(theme: {\n\tcolorScheme?: \"light\" | \"dark\"\n\tstyle?: string\n}): Promise<\"light\" | \"dark\" | undefined> {\n\tif (theme.colorScheme) return theme.colorScheme\n\tif (!theme.style) return undefined\n\ttry {\n\t\tconst res = await fetch(theme.style)\n\t\tconst css = await res.text()\n\t\tconst match = css.match(/color-scheme:\\s*(light|dark)/)\n\t\treturn (match?.[1] as \"light\" | \"dark\") ?? undefined\n\t} catch {\n\t\treturn undefined\n\t}\n}\n\nexport function setThemeForCurrentMode(themeId: string) {\n\tconst mode = getMode()\n\tsetThemeForMode(mode, themeId)\n}\n\nexport function setThemeForMode(mode: \"light\" | \"dark\", themeId: string) {\n\tcurrentPrefsHandle?.change((doc: any) => {\n\t\tdoc[mode] = themeId\n\t})\n}\n\nexport function hasThemePreferences() {\n\treturn Boolean(currentPrefsHandle)\n}\n\nexport function onActiveThemeChange(listener: (state: ActiveThemeState) => void) {\n\tlisteners.add(listener)\n\tlistener(getActiveThemeState())\n\treturn () => listeners.delete(listener)\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;AAAA,SAAQ,mBAAkB;;;;;;AAsBnB,IAAM,yBAAyB;AAEtC,IAAM,mBAAmB,CAAC,eA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|
3
|
-
"sources": ["../src/datatype.ts"],
|
|
4
|
-
"sourcesContent": ["export const ThemePreferencesDatatype = {\n\tinit(doc: any) {\n\t\tdoc.light = \"lychee\"\n\t\tdoc.dark = \"gloom\"\n\t},\n\tgetTitle() {\n\t\treturn \"Theme Preferences\"\n\t},\n\tsetTitle() {\n\t\t// Theme preferences doc title is not user-editable\n\t},\n}\n"],
|
|
5
|
-
"mappings": ";AAAO,IAAM,2BAA2B;AAAA,EACvC,KAAK,KAAU;AACd,QAAI,QAAQ;AACZ,QAAI,OAAO;AAAA,EACZ;AAAA,EACA,WAAW;AACV,WAAO;AAAA,EACR;AAAA,EACA,WAAW;AAAA,EAEX;AACD;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
/package/packages/theming/dist/{active-theme-K27UXDBG.js.map → active-theme-32OB4CH6.js.map}
RENAMED
|
File without changes
|
/package/packages/theming/dist/{theme-titlebar-P2CODQGF.js.map → theme-titlebar-GZMRTVWM.js.map}
RENAMED
|
File without changes
|
|
File without changes
|