resonare 0.1.7 → 0.3.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.md +329 -270
- package/dist/index.d.ts +220 -102
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lite-react.d.ts +41 -0
- package/dist/lite-react.d.ts.map +1 -0
- package/dist/lite-react.js +2 -0
- package/dist/lite-react.js.map +1 -0
- package/dist/lite-solid.d.ts +42 -0
- package/dist/lite-solid.d.ts.map +1 -0
- package/dist/lite-solid.js +2 -0
- package/dist/lite-solid.js.map +1 -0
- package/dist/lite-svelte.d.ts +41 -0
- package/dist/lite-svelte.d.ts.map +1 -0
- package/dist/lite-svelte.js +2 -0
- package/dist/lite-svelte.js.map +1 -0
- package/dist/lite-vue.d.ts +49 -0
- package/dist/lite-vue.d.ts.map +1 -0
- package/dist/lite-vue.js +2 -0
- package/dist/lite-vue.js.map +1 -0
- package/dist/lite.d.ts +124 -0
- package/dist/lite.d.ts.map +1 -0
- package/dist/lite.js +2 -0
- package/dist/lite.js.map +1 -0
- package/dist/react.d.ts +39 -30
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +1 -1
- package/dist/react.js.map +1 -1
- package/dist/solid.d.ts +84 -0
- package/dist/solid.d.ts.map +1 -0
- package/dist/solid.js +2 -0
- package/dist/solid.js.map +1 -0
- package/dist/storage-BqWA8jeP.js +2 -0
- package/dist/storage-BqWA8jeP.js.map +1 -0
- package/dist/storage-CsXjZKyt.d.ts +65 -0
- package/dist/storage-CsXjZKyt.d.ts.map +1 -0
- package/dist/svelte.d.ts +86 -0
- package/dist/svelte.d.ts.map +1 -0
- package/dist/svelte.js +2 -0
- package/dist/svelte.js.map +1 -0
- package/dist/vue.d.ts +82 -0
- package/dist/vue.d.ts.map +1 -0
- package/dist/vue.js +2 -0
- package/dist/vue.js.map +1 -0
- package/package.json +75 -32
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ThemeStore } from "./lite.js";
|
|
2
|
+
/**
|
|
3
|
+
* Returns the store's state as signals (`theme()`, `resolvedTheme()`,
|
|
4
|
+
* `systemTheme()`) and its methods. Call it inside a component (or
|
|
5
|
+
* `createRoot`); the subscription ends when that owner is cleaned up. Server
|
|
6
|
+
* rendering and hydration are handled automatically.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* import { createThemeStore } from 'resonare/lite'
|
|
10
|
+
* import { useResonare } from 'resonare/lite/solid'
|
|
11
|
+
*
|
|
12
|
+
* const store = createThemeStore()
|
|
13
|
+
*
|
|
14
|
+
* function ThemeToggle() {
|
|
15
|
+
* const { resolvedTheme, setTheme } = useResonare(store)
|
|
16
|
+
*
|
|
17
|
+
* return (
|
|
18
|
+
* <button
|
|
19
|
+
* onClick={() => {
|
|
20
|
+
* setTheme(resolvedTheme() === 'dark' ? 'light' : 'dark')
|
|
21
|
+
* }}
|
|
22
|
+
* >
|
|
23
|
+
* {resolvedTheme()}
|
|
24
|
+
* </button>
|
|
25
|
+
* )
|
|
26
|
+
* }
|
|
27
|
+
*/
|
|
28
|
+
export declare function useResonare(store: ThemeStore): {
|
|
29
|
+
theme: () => "dark" | "light" | "system";
|
|
30
|
+
resolvedTheme: () => "dark" | "light";
|
|
31
|
+
systemTheme: () => "dark" | "light";
|
|
32
|
+
destroy: () => void;
|
|
33
|
+
restore: () => void;
|
|
34
|
+
setTheme: (next: ("dark" | "light" | "system") | ((current: "dark" | "light" | "system") => "dark" | "light" | "system")) => void;
|
|
35
|
+
subscribe: (callback: (value: {
|
|
36
|
+
theme: "dark" | "light" | "system";
|
|
37
|
+
resolvedTheme: "dark" | "light";
|
|
38
|
+
systemTheme: "dark" | "light";
|
|
39
|
+
}) => void) => (() => void);
|
|
40
|
+
sync: () => (() => void) | undefined;
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=lite-solid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lite-solid.d.ts","names":[],"sources":["../src/lite-solid.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;wBA8BgB,YAAY,OAAO"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{createSignal as e,onCleanup as t,onMount as n,sharedConfig as r}from"solid-js";function i(i){let{destroy:a,getServerSnapshot:o,getSnapshot:s,restore:c,setTheme:l,subscribe:u,sync:d}=i,f=!!r.context,[p,m]=e(f?o():s()),h=u(e=>{m(()=>e)});return t(h),f&&n(()=>{m(()=>s())}),{theme:()=>p().theme,resolvedTheme:()=>p().resolvedTheme,systemTheme:()=>p().systemTheme,destroy:a,restore:c,setTheme:l,subscribe:u,sync:d}}export{i as useResonare};
|
|
2
|
+
//# sourceMappingURL=lite-solid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lite-solid.js","names":["useResonare","store","hydrating","sharedConfig","snapshot","setSnapshot","createSignal","getServerSnapshot","getSnapshot","unsubscribe","subscribe","value","onCleanup","onMount"],"sources":["../src/lite-solid.ts"],"sourcesContent":["import { createSignal, onCleanup, onMount, sharedConfig } from 'solid-js'\n\nimport type { ThemeStore } from './lite'\n\n/**\n * Returns the store's state as signals (`theme()`, `resolvedTheme()`,\n * `systemTheme()`) and its methods. Call it inside a component (or\n * `createRoot`); the subscription ends when that owner is cleaned up. Server\n * rendering and hydration are handled automatically.\n *\n * @example\n * import { createThemeStore } from 'resonare/lite'\n * import { useResonare } from 'resonare/lite/solid'\n *\n * const store = createThemeStore()\n *\n * function ThemeToggle() {\n * const { resolvedTheme, setTheme } = useResonare(store)\n *\n * return (\n * <button\n * onClick={() => {\n * setTheme(resolvedTheme() === 'dark' ? 'light' : 'dark')\n * }}\n * >\n * {resolvedTheme()}\n * </button>\n * )\n * }\n */\nexport function useResonare(store: ThemeStore) {\n const {\n destroy,\n getServerSnapshot,\n getSnapshot,\n restore,\n setTheme,\n subscribe,\n sync,\n } = store\n\n // Match the server HTML while rendering on the server or hydrating, then\n // switch to the live snapshot once mounted.\n const hydrating = !!sharedConfig.context\n\n const [snapshot, setSnapshot] = createSignal(\n hydrating ? getServerSnapshot() : getSnapshot()\n )\n\n const unsubscribe = subscribe((value) => {\n setSnapshot(() => {\n return value\n })\n })\n\n onCleanup(unsubscribe)\n\n if (hydrating) {\n onMount(() => {\n setSnapshot(() => {\n return getSnapshot()\n })\n })\n }\n\n return {\n theme: () => {\n return snapshot().theme\n },\n resolvedTheme: () => {\n return snapshot().resolvedTheme\n },\n systemTheme: () => {\n return snapshot().systemTheme\n },\n destroy,\n restore,\n setTheme,\n subscribe,\n sync,\n }\n}\n"],"mappings":"A,sFA8BA,SAAgBA,EAAY,EAAmB,CAC7C,GAAM,CACJ,UACA,oBACA,cACA,UACA,WACA,YACA,QACEC,EAIEC,EAAY,CAAC,CAACC,EAAa,QAE3B,CAACC,EAAUC,GAAeC,EAC9BJ,EAAYK,EAAkB,EAAIC,EAAY,CAChD,EAEMC,EAAcC,EAAW,GAAU,CACvCL,MACSM,CACR,CACH,CAAC,EAYD,OAVAC,EAAUH,CAAW,EAEjBP,GACFW,MAAc,CACZR,MACSG,EAAY,CACpB,CACH,CAAC,EAGI,CACL,UACSJ,EAAS,CAAC,CAAC,MAEpB,kBACSA,EAAS,CAAC,CAAC,cAEpB,gBACSA,EAAS,CAAC,CAAC,YAEpB,UACA,UACA,WACA,YACA,MACF,CACF,C"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ThemeStore } from "./lite.js";
|
|
2
|
+
/**
|
|
3
|
+
* Returns the store's state (`theme`, `resolvedTheme`, `systemTheme`), each
|
|
4
|
+
* read through `.current`, and its methods. `.current` is reactive in
|
|
5
|
+
* templates, `$derived` and `$effect`, and the store is subscribed only while
|
|
6
|
+
* something reads it. Hydration needs nothing extra: Svelte fixes any markup
|
|
7
|
+
* that differs from the server's.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* <script lang="ts">
|
|
11
|
+
* import { createThemeStore } from 'resonare/lite'
|
|
12
|
+
* import { useResonare } from 'resonare/lite/svelte'
|
|
13
|
+
*
|
|
14
|
+
* const store = createThemeStore()
|
|
15
|
+
* const { resolvedTheme, setTheme } = useResonare(store)
|
|
16
|
+
* </script>
|
|
17
|
+
*
|
|
18
|
+
* <p>Theme: {resolvedTheme.current}</p>
|
|
19
|
+
* <button onclick={() => setTheme('dark')}>Dark</button>
|
|
20
|
+
*/
|
|
21
|
+
export declare function useResonare(store: ThemeStore): {
|
|
22
|
+
theme: {
|
|
23
|
+
readonly current: "dark" | "light" | "system";
|
|
24
|
+
};
|
|
25
|
+
resolvedTheme: {
|
|
26
|
+
readonly current: "dark" | "light";
|
|
27
|
+
};
|
|
28
|
+
systemTheme: {
|
|
29
|
+
readonly current: "dark" | "light";
|
|
30
|
+
};
|
|
31
|
+
destroy: () => void;
|
|
32
|
+
restore: () => void;
|
|
33
|
+
setTheme: (next: ("dark" | "light" | "system") | ((current: "dark" | "light" | "system") => "dark" | "light" | "system")) => void;
|
|
34
|
+
subscribe: (callback: (value: {
|
|
35
|
+
theme: "dark" | "light" | "system";
|
|
36
|
+
resolvedTheme: "dark" | "light";
|
|
37
|
+
systemTheme: "dark" | "light";
|
|
38
|
+
}) => void) => (() => void);
|
|
39
|
+
sync: () => (() => void) | undefined;
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=lite-svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lite-svelte.d.ts","names":[],"sources":["../src/lite-svelte.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;wBAuBgB,YAAY,OAAO;;aAiBzB;;;aAKA;;;aAKA"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{createSubscriber as e}from"svelte/reactivity";function t(t){let{destroy:n,getSnapshot:r,restore:i,setTheme:a,subscribe:o,sync:s}=t,c=e(e=>o(()=>{e()})),l=()=>(c(),r());return{theme:{get current(){return l().theme}},resolvedTheme:{get current(){return l().resolvedTheme}},systemTheme:{get current(){return l().systemTheme}},destroy:n,restore:i,setTheme:a,subscribe:o,sync:s}}export{t as useResonare};
|
|
2
|
+
//# sourceMappingURL=lite-svelte.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lite-svelte.js","names":["useResonare","store","track","createSubscriber","subscribe","update","read","getSnapshot"],"sources":["../src/lite-svelte.ts"],"sourcesContent":["import { createSubscriber } from 'svelte/reactivity'\n\nimport type { ThemeStore } from './lite'\n\n/**\n * Returns the store's state (`theme`, `resolvedTheme`, `systemTheme`), each\n * read through `.current`, and its methods. `.current` is reactive in\n * templates, `$derived` and `$effect`, and the store is subscribed only while\n * something reads it. Hydration needs nothing extra: Svelte fixes any markup\n * that differs from the server's.\n *\n * @example\n * <script lang=\"ts\">\n * import { createThemeStore } from 'resonare/lite'\n * import { useResonare } from 'resonare/lite/svelte'\n *\n * const store = createThemeStore()\n * const { resolvedTheme, setTheme } = useResonare(store)\n * </script>\n *\n * <p>Theme: {resolvedTheme.current}</p>\n * <button onclick={() => setTheme('dark')}>Dark</button>\n */\nexport function useResonare(store: ThemeStore) {\n const { destroy, getSnapshot, restore, setTheme, subscribe, sync } = store\n\n const track = createSubscriber((update) => {\n return subscribe(() => {\n update()\n })\n })\n\n const read = () => {\n track()\n\n return getSnapshot()\n }\n\n return {\n theme: {\n get current() {\n return read().theme\n },\n },\n resolvedTheme: {\n get current() {\n return read().resolvedTheme\n },\n },\n systemTheme: {\n get current() {\n return read().systemTheme\n },\n },\n destroy,\n restore,\n setTheme,\n subscribe,\n sync,\n }\n}\n"],"mappings":"A,qDAuBA,SAAgBA,EAAY,EAAmB,CAC7C,GAAM,CAAE,UAAS,cAAa,UAAS,WAAU,YAAW,QAASC,EAE/DC,EAAQC,EAAkB,GACvBC,MAAgB,CACrBC,EAAO,CACT,CAAC,CACF,EAEKC,OACJJ,EAAM,EAECK,EAAY,GAGrB,MAAO,CACL,MAAO,CACL,IAAI,SAAU,CACZ,OAAOD,EAAK,CAAC,CAAC,KAChB,CACF,EACA,cAAe,CACb,IAAI,SAAU,CACZ,OAAOA,EAAK,CAAC,CAAC,aAChB,CACF,EACA,YAAa,CACX,IAAI,SAAU,CACZ,OAAOA,EAAK,CAAC,CAAC,WAChB,CACF,EACA,UACA,UACA,WACA,YACA,MACF,CACF,C"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ThemeStore } from "./lite.js";
|
|
2
|
+
import { ComputedRef } from "vue";
|
|
3
|
+
type UseResonareOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* Set this in server-rendered apps. The first render then uses the server
|
|
6
|
+
* state so hydration matches the server HTML, and switches to the live state
|
|
7
|
+
* once mounted. Leave it off in client-only apps, where it would show the
|
|
8
|
+
* server state for one frame.
|
|
9
|
+
*/
|
|
10
|
+
hydrate?: boolean;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Returns the store's state as computed refs (`theme`, `resolvedTheme`,
|
|
14
|
+
* `systemTheme`) and its methods. Call it in `setup` (or inside an
|
|
15
|
+
* `effectScope`); the subscription ends when the component unmounts or the
|
|
16
|
+
* scope stops.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* <script setup lang="ts">
|
|
20
|
+
* import { createThemeStore } from 'resonare/lite'
|
|
21
|
+
* import { useResonare } from 'resonare/lite/vue'
|
|
22
|
+
*
|
|
23
|
+
* const store = createThemeStore()
|
|
24
|
+
*
|
|
25
|
+
* // hydrate: true only in server-rendered apps
|
|
26
|
+
* const { resolvedTheme, setTheme } = useResonare(store, { hydrate: true })
|
|
27
|
+
* </script>
|
|
28
|
+
*
|
|
29
|
+
* <template>
|
|
30
|
+
* <p>Theme: {{ resolvedTheme }}</p>
|
|
31
|
+
* <button @click="setTheme('dark')">Dark</button>
|
|
32
|
+
* </template>
|
|
33
|
+
*/
|
|
34
|
+
export declare function useResonare(store: ThemeStore, { hydrate }?: UseResonareOptions): {
|
|
35
|
+
theme: ComputedRef<ReturnType<ThemeStore['getSnapshot']>['theme']>;
|
|
36
|
+
resolvedTheme: ComputedRef<ReturnType<ThemeStore['getSnapshot']>['resolvedTheme']>;
|
|
37
|
+
systemTheme: ComputedRef<ReturnType<ThemeStore['getSnapshot']>['systemTheme']>;
|
|
38
|
+
destroy: () => void;
|
|
39
|
+
restore: () => void;
|
|
40
|
+
setTheme: (next: ("dark" | "light" | "system") | ((current: "dark" | "light" | "system") => "dark" | "light" | "system")) => void;
|
|
41
|
+
subscribe: (callback: (value: {
|
|
42
|
+
theme: "dark" | "light" | "system";
|
|
43
|
+
resolvedTheme: "dark" | "light";
|
|
44
|
+
systemTheme: "dark" | "light";
|
|
45
|
+
}) => void) => (() => void);
|
|
46
|
+
sync: () => (() => void) | undefined;
|
|
47
|
+
};
|
|
48
|
+
export {};
|
|
49
|
+
//# sourceMappingURL=lite-vue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lite-vue.d.ts","names":[],"sources":["../src/lite-vue.ts"],"mappings":";;KAYK;;;;;;;EAOH;;;;;;;;;;;;;;;;;;;;;;;;wBAyBc,YACd,OAAO,cACL,YAAmB;EAgDb,OAAA,YAAY,WAAW;EAGvB,eAAA,YAAY,WAAW;EAGvB,aAAA,YAAY,WAAW"}
|
package/dist/lite-vue.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{computed as e,getCurrentInstance as t,onMounted as n,onScopeDispose as r,onUnmounted as i,shallowRef as a}from"vue";function o(o,{hydrate:s=!1}={}){let{destroy:c,getServerSnapshot:l,getSnapshot:u,restore:d,setTheme:f,subscribe:p,sync:m}=o,h=t(),g=a(s&&h?l():u()),_,v=()=>{g.value=u(),_=p(e=>{g.value=e})},y=()=>{_?.()};return h?(n(v),i(y)):(v(),r(y)),{theme:e(()=>g.value.theme),resolvedTheme:e(()=>g.value.resolvedTheme),systemTheme:e(()=>g.value.systemTheme),destroy:c,restore:d,setTheme:f,subscribe:p,sync:m}}export{o as useResonare};
|
|
2
|
+
//# sourceMappingURL=lite-vue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lite-vue.js","names":["useResonare","store","instance","getCurrentInstance","snapshot","shallowRef","hydrate","getServerSnapshot","getSnapshot","unsubscribe","start","subscribe","value","stop","onMounted","onUnmounted","onScopeDispose","computed"],"sources":["../src/lite-vue.ts"],"sourcesContent":["import {\n type ComputedRef,\n computed,\n getCurrentInstance,\n onMounted,\n onScopeDispose,\n onUnmounted,\n shallowRef,\n} from 'vue'\n\nimport type { ThemeStore } from './lite'\n\ntype UseResonareOptions = {\n /**\n * Set this in server-rendered apps. The first render then uses the server\n * state so hydration matches the server HTML, and switches to the live state\n * once mounted. Leave it off in client-only apps, where it would show the\n * server state for one frame.\n */\n hydrate?: boolean\n}\n\n/**\n * Returns the store's state as computed refs (`theme`, `resolvedTheme`,\n * `systemTheme`) and its methods. Call it in `setup` (or inside an\n * `effectScope`); the subscription ends when the component unmounts or the\n * scope stops.\n *\n * @example\n * <script setup lang=\"ts\">\n * import { createThemeStore } from 'resonare/lite'\n * import { useResonare } from 'resonare/lite/vue'\n *\n * const store = createThemeStore()\n *\n * // hydrate: true only in server-rendered apps\n * const { resolvedTheme, setTheme } = useResonare(store, { hydrate: true })\n * </script>\n *\n * <template>\n * <p>Theme: {{ resolvedTheme }}</p>\n * <button @click=\"setTheme('dark')\">Dark</button>\n * </template>\n */\nexport function useResonare(\n store: ThemeStore,\n { hydrate = false }: UseResonareOptions = {}\n) {\n const {\n destroy,\n getServerSnapshot,\n getSnapshot,\n restore,\n setTheme,\n subscribe,\n sync,\n } = store\n\n const instance = getCurrentInstance()\n\n const snapshot = shallowRef(\n hydrate && instance ? getServerSnapshot() : getSnapshot()\n )\n\n let unsubscribe: (() => unknown) | undefined\n\n const start = () => {\n snapshot.value = getSnapshot()\n\n unsubscribe = subscribe((value) => {\n snapshot.value = value\n })\n }\n\n const stop = () => {\n unsubscribe?.()\n }\n\n // Components subscribe on mount, which never runs during server rendering,\n // so the server never holds a subscription. Lifecycle hooks are used because\n // server rendering may set up components without an active effect scope.\n if (instance) {\n onMounted(start)\n\n onUnmounted(stop)\n } else {\n start()\n\n onScopeDispose(stop)\n }\n\n return {\n theme: computed(() => {\n return snapshot.value.theme\n }) as ComputedRef<ReturnType<ThemeStore['getSnapshot']>['theme']>,\n resolvedTheme: computed(() => {\n return snapshot.value.resolvedTheme\n }) as ComputedRef<ReturnType<ThemeStore['getSnapshot']>['resolvedTheme']>,\n systemTheme: computed(() => {\n return snapshot.value.systemTheme\n }) as ComputedRef<ReturnType<ThemeStore['getSnapshot']>['systemTheme']>,\n destroy,\n restore,\n setTheme,\n subscribe,\n sync,\n }\n}\n"],"mappings":"A,2HA4CA,SAAgBA,EACd,EACA,CAAE,UAAU,IAA8B,CAAC,EAC3C,CACA,GAAM,CACJ,UACA,oBACA,cACA,UACA,WACA,YACA,QACEC,EAEEC,EAAWC,EAAmB,EAE9BC,EAAWC,EACfC,GAAWJ,EAAWK,EAAkB,EAAIC,EAAY,CAC1D,EAEIC,EAEEC,MAAc,CAClB,EAAS,MAAQF,EAAY,EAE7B,EAAcG,EAAW,GAAU,CACjC,EAAS,MAAQC,CACnB,CAAC,CACH,EAEMC,MAAa,CACjBJ,IAAc,CAChB,EAeA,OAVIP,GACFY,EAAUJ,CAAK,EAEfK,EAAYF,CAAI,IAEhBH,EAAM,EAENM,EAAeH,CAAI,GAGd,CACL,MAAOI,MACEb,EAAS,MAAM,KACvB,EACD,cAAea,MACNb,EAAS,MAAM,aACvB,EACD,YAAaa,MACJb,EAAS,MAAM,WACvB,EACD,UACA,UACA,WACA,YACA,MACF,CACF,C"}
|
package/dist/lite.d.ts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { a as memoryStorageAdapter, i as localStorageAdapter, n as StorageAdapterCreate, r as StorageAdapterCreator, t as StorageAdapter } from "./storage-CsXjZKyt.js";
|
|
2
|
+
type Theme = 'system' | 'light' | 'dark';
|
|
3
|
+
type ResolvedTheme = 'light' | 'dark';
|
|
4
|
+
type Snapshot = {
|
|
5
|
+
theme: Theme;
|
|
6
|
+
resolvedTheme: ResolvedTheme;
|
|
7
|
+
systemTheme: ResolvedTheme;
|
|
8
|
+
};
|
|
9
|
+
type Listener = (value: Snapshot) => void;
|
|
10
|
+
type ThemeStoreOptions = {
|
|
11
|
+
persisted?: Theme;
|
|
12
|
+
storage?: StorageAdapterCreate | null;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Creates a store for a single light / dark / system preference. It saves
|
|
16
|
+
* changes through `storage` (`localStorage` under the key `'resonare/lite'` by
|
|
17
|
+
* default; `null` disables saving), follows `prefers-color-scheme` while the
|
|
18
|
+
* preference is `system`, and notifies subscribers.
|
|
19
|
+
*
|
|
20
|
+
* Read state with `getSnapshot()` or `subscribe`.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* import { createThemeStore, localStorageAdapter } from 'resonare/lite'
|
|
24
|
+
*
|
|
25
|
+
* const store = createThemeStore({
|
|
26
|
+
* storage: localStorageAdapter({ key: 'my-app' }),
|
|
27
|
+
* })
|
|
28
|
+
*
|
|
29
|
+
* // In the browser: load the saved choice and follow other tabs.
|
|
30
|
+
* store.restore()
|
|
31
|
+
* store.sync()
|
|
32
|
+
*
|
|
33
|
+
* store.subscribe(({ resolvedTheme }) => {
|
|
34
|
+
* document.documentElement.dataset.theme = resolvedTheme
|
|
35
|
+
* })
|
|
36
|
+
*
|
|
37
|
+
* store.setTheme('dark')
|
|
38
|
+
*/
|
|
39
|
+
export declare function createThemeStore({ persisted, storage: createStorage }?: ThemeStoreOptions): {
|
|
40
|
+
/**
|
|
41
|
+
* Current state:
|
|
42
|
+
*
|
|
43
|
+
* - `theme`: the selected preference (`'system'`, `'light'` or `'dark'`).
|
|
44
|
+
* - `resolvedTheme`: `'light'` or `'dark'`, with `system` resolved.
|
|
45
|
+
* - `systemTheme`: the OS preference, even when `system` isn't selected.
|
|
46
|
+
*
|
|
47
|
+
* Returns the same object until the next change.
|
|
48
|
+
*/
|
|
49
|
+
getSnapshot: () => Snapshot;
|
|
50
|
+
/**
|
|
51
|
+
* The state as rendered on the server: `persisted` (or `system`), with the
|
|
52
|
+
* OS preference taken as `light`. It never changes, so hydration can match
|
|
53
|
+
* the server HTML even after `restore()`.
|
|
54
|
+
*/
|
|
55
|
+
getServerSnapshot: () => Snapshot;
|
|
56
|
+
/**
|
|
57
|
+
* Sets the preference, saves it to storage, and notifies subscribers.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* store.setTheme('dark')
|
|
61
|
+
* store.setTheme((current) => (current === 'dark' ? 'light' : 'dark'))
|
|
62
|
+
*/
|
|
63
|
+
setTheme: (next: Theme | ((current: Theme) => Theme)) => void;
|
|
64
|
+
/**
|
|
65
|
+
* Loads the saved preference from storage. Does nothing when nothing is
|
|
66
|
+
* saved. Call it in the browser, e.g. after hydration.
|
|
67
|
+
*/
|
|
68
|
+
restore: () => void;
|
|
69
|
+
/**
|
|
70
|
+
* Calls `callback` with the new state (see `getSnapshot`) after every
|
|
71
|
+
* change, including OS preference changes. Returns an unsubscribe
|
|
72
|
+
* function.
|
|
73
|
+
*/
|
|
74
|
+
subscribe: (callback: Listener) => (() => void);
|
|
75
|
+
/**
|
|
76
|
+
* Applies changes saved by other tabs (if the storage adapter supports
|
|
77
|
+
* it); when another tab clears the saved value, resets to `system`.
|
|
78
|
+
* Returns a function that stops syncing, or `undefined` when the adapter
|
|
79
|
+
* can't sync.
|
|
80
|
+
*/
|
|
81
|
+
sync: () => (() => void) | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* Removes all subscribers and stops listening to the OS preference and
|
|
84
|
+
* storage. The store doesn't update after this.
|
|
85
|
+
*/
|
|
86
|
+
destroy: () => void;
|
|
87
|
+
};
|
|
88
|
+
export type ThemeStore = ReturnType<typeof createThemeStore>;
|
|
89
|
+
/** Options for `createInlineThemeScript`. */
|
|
90
|
+
export type ThemeScriptParameter = {
|
|
91
|
+
/** The store's `localStorage` key; defaults to `'resonare/lite'`. */
|
|
92
|
+
key?: string;
|
|
93
|
+
/**
|
|
94
|
+
* Applies the state to the page; receives the same value as `subscribe`.
|
|
95
|
+
* It is copied into the script as source code, so it can't use variables
|
|
96
|
+
* from outside the function.
|
|
97
|
+
*/
|
|
98
|
+
handler: Listener;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Returns the source of a small script that reads the saved preference from
|
|
102
|
+
* `localStorage` and runs `handler` with it. Put it in an inline `<script>` in
|
|
103
|
+
* the `<head>` so the page has the right theme before first paint.
|
|
104
|
+
*
|
|
105
|
+
* Use the same handler with `store.subscribe` to keep the page updated after
|
|
106
|
+
* that.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* import { createInlineThemeScript, createThemeStore } from 'resonare/lite'
|
|
110
|
+
*
|
|
111
|
+
* const handler = ({ resolvedTheme }) => {
|
|
112
|
+
* document.documentElement.dataset.theme = resolvedTheme
|
|
113
|
+
* }
|
|
114
|
+
*
|
|
115
|
+
* const themeScript = createInlineThemeScript({ key: 'my-app', handler })
|
|
116
|
+
* // In <head>:
|
|
117
|
+
* // <script dangerouslySetInnerHTML={{ __html: themeScript }} />
|
|
118
|
+
*
|
|
119
|
+
* const store = createThemeStore()
|
|
120
|
+
* store.subscribe(handler)
|
|
121
|
+
*/
|
|
122
|
+
export declare function createInlineThemeScript({ key, handler }: ThemeScriptParameter): string;
|
|
123
|
+
export { StorageAdapter, StorageAdapterCreate, StorageAdapterCreator, localStorageAdapter, memoryStorageAdapter };
|
|
124
|
+
//# sourceMappingURL=lite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lite.d.ts","names":[],"sources":["../src/lite.ts"],"mappings":";KAMK;KAEA;KAEA;EACH,OAAO;EACP,eAAe;EACf,aAAa;;KAGV,YAAY,OAAO;KAEnB;EACH,YAAY;EACZ,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA4BI,mBACd,WACA,SAAS,kBACR;;;;;;;;;;EAkEC,mBAAiB;;;;;;EASjB,yBAAuB;;;;;;;;EAWvB,WAAQ,MAAS,UAAU,SAAS,UAAU;;;;;EAY9C;;;;;;EAaA,YAAS,UAAa;;;;;;;EActB;;;;;EAUA;;YAQQ,aAAa,kBAAkB;;YAoB/B;;EAEV;;;;;;EAMA,SAAS;;;;;;;;;;;;;;;;;;;;;;;;wBAyBK,0BACd,KACA,WACC"}
|
package/dist/lite.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{i as e,n as t,o as n,r,t as i}from"./storage-BqWA8jeP.js";function a({persisted:e,storage:t=i({key:n})}={}){let r=e??`system`,a,o=/* @__PURE__ */ new Set,s=new AbortController,c=t?.({abortController:s}),l=e=>e||typeof matchMedia>`u`?`light`:(a||(a=matchMedia(`(prefers-color-scheme: dark)`),a.addEventListener(`change`,()=>{p(r)},s)),a.matches?`dark`:`light`),u=e=>{let t=l(e);return{theme:r,resolvedTheme:r===`system`?t:r,systemTheme:t}},d=u(!0),f=u(),p=e=>{r=e,f=u();for(let e of o)e(f)};return{getSnapshot:()=>f,getServerSnapshot:()=>d,setTheme:e=>{p(typeof e==`function`?e(r):e),c?.set(r),c?.broadcast?.(r)},restore:()=>{let e=c?.get();e&&p(e)},subscribe:e=>(o.add(e),()=>{o.delete(e)}),sync:()=>c?.watch?.(e=>{p(e??`system`)}),destroy:()=>{o.clear(),s.abort()}}}const o=(e,t)=>{let n=`system`;try{n=localStorage.getItem(e)??n}catch{}let r=matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`;t({theme:n,resolvedTheme:n===`system`?r:n,systemTheme:r})};function s({key:t=n,handler:i}){return`(${o})(${e(t)},${r(i)})`}export{s as createInlineThemeScript,a as createThemeStore,i as localStorageAdapter,t as memoryStorageAdapter};
|
|
2
|
+
//# sourceMappingURL=lite.js.map
|
package/dist/lite.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lite.js","names":["toScriptJson","memoryStorageAdapter","DEFAULT_LITE_KEY","localStorageAdapter","createThemeStore","createStorage","theme","persisted","mediaQuery","listeners","abortController","storage","resolveSystemTheme","server","setThemeAndNotify","createSnapshot","systemTheme","serverSnapshot","snapshot","next","listener","stored","callback","restoreScript","key","handler","createInlineThemeScript","toScriptFunction"],"sources":["../src/lite.ts"],"sourcesContent":["import { DEFAULT_LITE_KEY } from './constants'\nimport { toScriptFunction, toScriptJson } from './script'\nimport { type StorageAdapterCreate, localStorageAdapter } from './storage'\n\nexport * from './storage'\n\ntype Theme = 'system' | 'light' | 'dark'\n\ntype ResolvedTheme = 'light' | 'dark'\n\ntype Snapshot = {\n theme: Theme\n resolvedTheme: ResolvedTheme\n systemTheme: ResolvedTheme\n}\n\ntype Listener = (value: Snapshot) => void\n\ntype ThemeStoreOptions = {\n persisted?: Theme\n storage?: StorageAdapterCreate | null\n}\n\n/**\n * Creates a store for a single light / dark / system preference. It saves\n * changes through `storage` (`localStorage` under the key `'resonare/lite'` by\n * default; `null` disables saving), follows `prefers-color-scheme` while the\n * preference is `system`, and notifies subscribers.\n *\n * Read state with `getSnapshot()` or `subscribe`.\n *\n * @example\n * import { createThemeStore, localStorageAdapter } from 'resonare/lite'\n *\n * const store = createThemeStore({\n * storage: localStorageAdapter({ key: 'my-app' }),\n * })\n *\n * // In the browser: load the saved choice and follow other tabs.\n * store.restore()\n * store.sync()\n *\n * store.subscribe(({ resolvedTheme }) => {\n * document.documentElement.dataset.theme = resolvedTheme\n * })\n *\n * store.setTheme('dark')\n */\nexport function createThemeStore({\n persisted,\n storage: createStorage = localStorageAdapter({ key: DEFAULT_LITE_KEY }),\n}: ThemeStoreOptions = {}) {\n let theme: Theme = persisted ?? 'system'\n\n let mediaQuery: MediaQueryList | undefined\n\n const listeners = new Set<Listener>()\n\n const abortController = new AbortController()\n\n const storage = createStorage?.({ abortController })\n\n // No media support (e.g. on the server): `system` is `light`.\n const resolveSystemTheme = (server?: boolean): ResolvedTheme => {\n if (server || typeof matchMedia === 'undefined') {\n return 'light'\n }\n\n if (!mediaQuery) {\n mediaQuery = matchMedia('(prefers-color-scheme: dark)')\n\n mediaQuery.addEventListener(\n 'change',\n () => {\n setThemeAndNotify(theme)\n },\n abortController\n )\n }\n\n return mediaQuery.matches ? 'dark' : 'light'\n }\n\n const createSnapshot = (server?: boolean): Snapshot => {\n const systemTheme = resolveSystemTheme(server)\n\n return {\n theme,\n resolvedTheme: theme === 'system' ? systemTheme : theme,\n systemTheme,\n }\n }\n\n const serverSnapshot = createSnapshot(true)\n\n let snapshot = createSnapshot()\n\n const setThemeAndNotify = (next: Theme): void => {\n theme = next\n\n snapshot = createSnapshot()\n\n for (const listener of listeners) {\n listener(snapshot)\n }\n }\n\n return {\n /**\n * Current state:\n *\n * - `theme`: the selected preference (`'system'`, `'light'` or `'dark'`).\n * - `resolvedTheme`: `'light'` or `'dark'`, with `system` resolved.\n * - `systemTheme`: the OS preference, even when `system` isn't selected.\n *\n * Returns the same object until the next change.\n */\n getSnapshot: (): Snapshot => {\n return snapshot\n },\n\n /**\n * The state as rendered on the server: `persisted` (or `system`), with the\n * OS preference taken as `light`. It never changes, so hydration can match\n * the server HTML even after `restore()`.\n */\n getServerSnapshot: (): Snapshot => {\n return serverSnapshot\n },\n\n /**\n * Sets the preference, saves it to storage, and notifies subscribers.\n *\n * @example\n * store.setTheme('dark')\n * store.setTheme((current) => (current === 'dark' ? 'light' : 'dark'))\n */\n setTheme: (next: Theme | ((current: Theme) => Theme)): void => {\n setThemeAndNotify(typeof next === 'function' ? next(theme) : next)\n\n storage?.set(theme)\n\n storage?.broadcast?.(theme)\n },\n\n /**\n * Loads the saved preference from storage. Does nothing when nothing is\n * saved. Call it in the browser, e.g. after hydration.\n */\n restore: (): void => {\n const stored = storage?.get() as Theme | null | undefined\n\n if (stored) {\n setThemeAndNotify(stored)\n }\n },\n\n /**\n * Calls `callback` with the new state (see `getSnapshot`) after every\n * change, including OS preference changes. Returns an unsubscribe\n * function.\n */\n subscribe: (callback: Listener): (() => void) => {\n listeners.add(callback)\n\n return () => {\n listeners.delete(callback)\n }\n },\n\n /**\n * Applies changes saved by other tabs (if the storage adapter supports\n * it); when another tab clears the saved value, resets to `system`.\n * Returns a function that stops syncing, or `undefined` when the adapter\n * can't sync.\n */\n sync: (): (() => void) | undefined => {\n return storage?.watch?.((stored) => {\n setThemeAndNotify((stored ?? 'system') as Theme)\n })\n },\n\n /**\n * Removes all subscribers and stops listening to the OS preference and\n * storage. The store doesn't update after this.\n */\n destroy: (): void => {\n listeners.clear()\n\n abortController.abort()\n },\n }\n}\n\nexport type ThemeStore = ReturnType<typeof createThemeStore>\n\nconst restoreScript = (key: string, handler: Listener) => {\n let theme: Theme = 'system'\n\n // Blocked storage must not stop the handler from running.\n try {\n theme = (localStorage.getItem(key) ?? theme) as Theme\n } catch {}\n\n const systemTheme = matchMedia('(prefers-color-scheme: dark)').matches\n ? 'dark'\n : 'light'\n\n const resolvedTheme = theme === 'system' ? systemTheme : theme\n\n handler({ theme, resolvedTheme, systemTheme })\n}\n\n/** Options for `createInlineThemeScript`. */\nexport type ThemeScriptParameter = {\n /** The store's `localStorage` key; defaults to `'resonare/lite'`. */\n key?: string\n /**\n * Applies the state to the page; receives the same value as `subscribe`.\n * It is copied into the script as source code, so it can't use variables\n * from outside the function.\n */\n handler: Listener\n}\n\n/**\n * Returns the source of a small script that reads the saved preference from\n * `localStorage` and runs `handler` with it. Put it in an inline `<script>` in\n * the `<head>` so the page has the right theme before first paint.\n *\n * Use the same handler with `store.subscribe` to keep the page updated after\n * that.\n *\n * @example\n * import { createInlineThemeScript, createThemeStore } from 'resonare/lite'\n *\n * const handler = ({ resolvedTheme }) => {\n * document.documentElement.dataset.theme = resolvedTheme\n * }\n *\n * const themeScript = createInlineThemeScript({ key: 'my-app', handler })\n * // In <head>:\n * // <script dangerouslySetInnerHTML={{ __html: themeScript }} />\n *\n * const store = createThemeStore()\n * store.subscribe(handler)\n */\nexport function createInlineThemeScript({\n key = DEFAULT_LITE_KEY,\n handler,\n}: ThemeScriptParameter) {\n return `(${restoreScript})(${toScriptJson(key)},${toScriptFunction(handler)})`\n}\n"],"mappings":"A,iEAgDA,SAAgBI,EAAiB,CAC/B,YACA,QAASC,EAAgBF,EAAoB,CAAE,IAAKD,CAAiB,CAAC,GACjD,CAAC,EAAG,CACzB,IAAII,EAAeC,GAAa,SAE5BC,EAEEC,kBAAY,IAAI,IAEhBC,EAAkB,IAAI,gBAEtBC,EAAUN,IAAgB,CAAE,iBAAgB,CAAC,EAG7CO,EAAsB,GACtBC,GAAU,OAAO,WAAe,IAC3B,SAGJL,IACH,EAAa,WAAW,8BAA8B,EAEtDA,EAAW,iBACT,aACM,CACJM,EAAkBR,CAAK,CACzB,EACAI,CACF,GAGKF,EAAW,QAAU,OAAS,SAGjCO,EAAkB,GAA+B,CACrD,IAAMC,EAAcJ,EAAmBC,CAAM,EAE7C,MAAO,CACL,QACA,cAAeP,IAAU,SAAWU,EAAcV,EAClD,aACF,CACF,EAEMW,EAAiBF,EAAe,EAAI,EAEtCG,EAAWH,EAAe,EAExBD,EAAqB,GAAsB,CAC/C,EAAQK,EAER,EAAWJ,EAAe,EAE1B,IAAK,IAAMK,KAAYX,EACrBW,EAASF,CAAQ,CAErB,EAEA,MAAO,CAUL,gBACSA,EAQT,sBACSD,EAUT,SAAW,GAAoD,CAC7DH,EAAkB,OAAOK,GAAS,WAAaA,EAAKb,CAAK,EAAIa,CAAI,EAEjER,GAAS,IAAIL,CAAK,EAElBK,GAAS,YAAYL,CAAK,CAC5B,EAMA,YAAqB,CACnB,IAAMe,EAASV,GAAS,IAAI,EAExBU,GACFP,EAAkBO,CAAM,CAE5B,EAOA,UAAY,IACVZ,EAAU,IAAIa,CAAQ,MAET,CACXb,EAAU,OAAOa,CAAQ,CAC3B,GASF,SACSX,GAAS,QAAS,GAAW,CAClCG,EAAmBO,GAAU,QAAkB,CACjD,CAAC,EAOH,YAAqB,CACnBZ,EAAU,MAAM,EAEhBC,EAAgB,MAAM,CACxB,CACF,CACF,CAIA,MAAMa,GAAiB,EAAa,IAAsB,CACxD,IAAIjB,EAAe,SAGnB,GAAI,CACF,EAAS,aAAa,QAAQkB,CAAG,GAAKlB,CACxC,MAAQ,CAAC,CAET,IAAMU,EAAc,WAAW,8BAA8B,CAAC,CAAC,QAC3D,OACA,QAIJS,EAAQ,CAAE,QAAO,cAFKnB,IAAU,SAAWU,EAAcV,EAEzB,aAAY,CAAC,CAC/C,EAoCA,SAAgBoB,EAAwB,CACtC,MAAMxB,EACN,WACuB,CACvB,MAAO,IAAIqB,EAAc,IAAIvB,EAAawB,CAAG,EAAE,GAAGG,EAAiBF,CAAO,EAAE,EAC9E,C"}
|
package/dist/react.d.ts
CHANGED
|
@@ -1,51 +1,62 @@
|
|
|
1
1
|
import { ThemeStore, ThemeStoreConfig, Themes } from "./index.js";
|
|
2
|
-
|
|
3
|
-
//#region src/react.d.ts
|
|
4
2
|
/**
|
|
5
|
-
*
|
|
3
|
+
* Returns the store's current state (see `store.getSnapshot()`) and its
|
|
4
|
+
* methods, and re-renders the component when the state changes. Server
|
|
5
|
+
* rendering and hydration are handled automatically.
|
|
6
|
+
*
|
|
6
7
|
* @example
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* import { useResonare } from 'resonare/react'
|
|
9
|
+
*
|
|
10
|
+
* function ColorModeToggle() {
|
|
11
|
+
* const { themes, setThemes } = useResonare(store)
|
|
10
12
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
13
|
+
* const next = themes.colorMode === 'dark' ? 'light' : 'dark'
|
|
14
|
+
*
|
|
15
|
+
* return (
|
|
16
|
+
* <button
|
|
17
|
+
* onClick={() => {
|
|
18
|
+
* setThemes({ colorMode: next })
|
|
19
|
+
* }}
|
|
20
|
+
* >
|
|
21
|
+
* {themes.colorMode}
|
|
22
|
+
* </button>
|
|
23
|
+
* )
|
|
24
|
+
* }
|
|
14
25
|
*/
|
|
15
|
-
declare function useResonare<T extends ThemeStoreConfig>(store: ThemeStore<T>): {
|
|
26
|
+
export declare function useResonare<T extends ThemeStoreConfig>(store: ThemeStore<T>): {
|
|
16
27
|
themes: Themes<T>;
|
|
17
28
|
resolvedThemes: Themes<T>;
|
|
18
|
-
resolvedSystemThemes: { [
|
|
29
|
+
resolvedSystemThemes: { [K in { [K in keyof T]: T[K] extends {
|
|
19
30
|
options: ReadonlyArray<infer U>;
|
|
20
31
|
} ? U extends {
|
|
21
32
|
media: ReadonlyArray<unknown>;
|
|
22
|
-
} ? K : never : never }[keyof T]]: T[
|
|
33
|
+
} ? K : never : never; }[keyof T]]: T[K] extends {
|
|
23
34
|
options: ReadonlyArray<infer U>;
|
|
24
35
|
} ? U extends string | number | boolean ? U : U extends {
|
|
25
36
|
value: string;
|
|
26
|
-
media?: [string, string, string];
|
|
37
|
+
media?: readonly [string, string, string] | undefined;
|
|
27
38
|
} ? U extends {
|
|
28
|
-
media:
|
|
29
|
-
} ? never : U["value"] : never : never };
|
|
39
|
+
media: ReadonlyArray<unknown>;
|
|
40
|
+
} ? never : U["value"] : never : never; };
|
|
30
41
|
destroy: () => void;
|
|
31
42
|
restore: () => void;
|
|
32
43
|
setThemes: (themes: Partial<Themes<T>> | ((currentThemes: Themes<T>) => Partial<Themes<T>>)) => void;
|
|
33
44
|
subscribe: (callback: (value: {
|
|
34
45
|
themes: Themes<T>;
|
|
35
46
|
resolvedThemes: Themes<T>;
|
|
36
|
-
resolvedSystemThemes: { [
|
|
47
|
+
resolvedSystemThemes: { [K in { [K in keyof T]: T[K] extends {
|
|
37
48
|
options: ReadonlyArray<infer U>;
|
|
38
49
|
} ? U extends {
|
|
39
50
|
media: ReadonlyArray<unknown>;
|
|
40
|
-
} ? K : never : never }[keyof T]]: T[
|
|
51
|
+
} ? K : never : never; }[keyof T]]: T[K] extends {
|
|
41
52
|
options: ReadonlyArray<infer U>;
|
|
42
53
|
} ? U extends string | number | boolean ? U : U extends {
|
|
43
54
|
value: string;
|
|
44
|
-
media?: [string, string, string];
|
|
55
|
+
media?: readonly [string, string, string] | undefined;
|
|
45
56
|
} ? U extends {
|
|
46
|
-
media:
|
|
47
|
-
} ? never : U["value"] : never : never };
|
|
48
|
-
}) => void) => (
|
|
57
|
+
media: ReadonlyArray<unknown>;
|
|
58
|
+
} ? never : U["value"] : never : never; };
|
|
59
|
+
}) => void) => () => void;
|
|
49
60
|
sync: () => (() => void) | undefined;
|
|
50
61
|
toPersist: () => {
|
|
51
62
|
themes: Partial<Themes<T>>;
|
|
@@ -53,26 +64,24 @@ declare function useResonare<T extends ThemeStoreConfig>(store: ThemeStore<T>):
|
|
|
53
64
|
[x: string]: [string, string];
|
|
54
65
|
};
|
|
55
66
|
};
|
|
56
|
-
updateSystemOption: <
|
|
67
|
+
updateSystemOption: <K extends { [K in keyof T]: T[K] extends {
|
|
57
68
|
options: ReadonlyArray<infer U>;
|
|
58
69
|
} ? U extends {
|
|
59
70
|
media: ReadonlyArray<unknown>;
|
|
60
|
-
} ? K : never : never }[keyof T]>(themeKey:
|
|
71
|
+
} ? K : never : never; }[keyof T]>(themeKey: K, pair: [T[K] extends {
|
|
61
72
|
options: ReadonlyArray<infer U>;
|
|
62
73
|
} ? U extends string | number | boolean ? U : U extends {
|
|
63
74
|
value: string;
|
|
64
|
-
media?: [string, string, string];
|
|
75
|
+
media?: readonly [string, string, string] | undefined;
|
|
65
76
|
} ? U extends {
|
|
66
|
-
media:
|
|
67
|
-
} ? never : U["value"] : never : never, T[
|
|
77
|
+
media: ReadonlyArray<unknown>;
|
|
78
|
+
} ? never : U["value"] : never : never, T[K] extends {
|
|
68
79
|
options: ReadonlyArray<infer U>;
|
|
69
80
|
} ? U extends string | number | boolean ? U : U extends {
|
|
70
81
|
value: string;
|
|
71
|
-
media?: [string, string, string];
|
|
82
|
+
media?: readonly [string, string, string] | undefined;
|
|
72
83
|
} ? U extends {
|
|
73
|
-
media:
|
|
84
|
+
media: ReadonlyArray<unknown>;
|
|
74
85
|
} ? never : U["value"] : never : never]) => void;
|
|
75
86
|
};
|
|
76
|
-
//#endregion
|
|
77
|
-
export { useResonare };
|
|
78
87
|
//# sourceMappingURL=react.d.ts.map
|
package/dist/react.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.d.ts","names":[],"sources":["../src/react.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"react.d.ts","names":["_$_0.Themes"],"sources":["../src/react.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;wBA4BgB,YAAY,UAAU,kBAAkB,OAAO,WAAW"}
|
package/dist/react.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{c as e}from"react
|
|
1
|
+
import{c as e}from"react/compiler-runtime";import*as t from"react";function n(n){let r=e(9),{destroy:i,getServerSnapshot:a,getSnapshot:o,restore:s,setThemes:c,subscribe:l,sync:u,toPersist:d,updateSystemOption:f}=n,p=t.useSyncExternalStore(l,o,a),m;return r[0]!==i||r[1]!==s||r[2]!==c||r[3]!==p||r[4]!==l||r[5]!==u||r[6]!==d||r[7]!==f?(m={...p,destroy:i,restore:s,setThemes:c,subscribe:l,sync:u,toPersist:d,updateSystemOption:f},r[0]=i,r[1]=s,r[2]=c,r[3]=p,r[4]=l,r[5]=u,r[6]=d,r[7]=f,r[8]=m):m=r[8],m}export{n as useResonare};
|
|
2
2
|
//# sourceMappingURL=react.js.map
|
package/dist/react.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.js","names":["
|
|
1
|
+
{"version":3,"file":"react.js","names":["{\n ...snapshot,\n destroy,\n restore,\n setThemes,\n subscribe,\n sync,\n toPersist,\n updateSystemOption,\n }","_c","React","useResonare","$","c","store","snapshot","subscribe","getSnapshot","getServerSnapshot","t0","destroy","restore","setThemes","sync","toPersist","updateSystemOption"],"sources":["../src/react.ts"],"sourcesContent":["import * as React from 'react'\n\nimport type { ThemeStore, ThemeStoreConfig } from '.'\n\n/**\n * Returns the store's current state (see `store.getSnapshot()`) and its\n * methods, and re-renders the component when the state changes. Server\n * rendering and hydration are handled automatically.\n *\n * @example\n * import { useResonare } from 'resonare/react'\n *\n * function ColorModeToggle() {\n * const { themes, setThemes } = useResonare(store)\n *\n * const next = themes.colorMode === 'dark' ? 'light' : 'dark'\n *\n * return (\n * <button\n * onClick={() => {\n * setThemes({ colorMode: next })\n * }}\n * >\n * {themes.colorMode}\n * </button>\n * )\n * }\n */\nexport function useResonare<T extends ThemeStoreConfig>(store: ThemeStore<T>) {\n const {\n destroy,\n getServerSnapshot,\n getSnapshot,\n restore,\n setThemes,\n subscribe,\n sync,\n toPersist,\n updateSystemOption,\n } = store\n\n const snapshot = React.useSyncExternalStore(\n subscribe,\n getSnapshot,\n getServerSnapshot\n )\n\n return {\n ...snapshot,\n destroy,\n restore,\n setThemes,\n subscribe,\n sync,\n toPersist,\n updateSystemOption,\n }\n}\n"],"mappings":"A,mEA4BA,SAAgBG,EAAwC,EAAsB,C,WACtE,CACJ,UACA,oBACA,cACA,UACA,YACA,YACA,OACA,YACA,sBACEG,EAEEC,EAAWL,EAAM,qBACrBM,EACAC,EACAC,CACF,EAEOV,EAAP,OAEEI,EAAA,KAAAQ,GAAAR,EAAA,KACAS,GAAAT,EAAA,KACAU,GAAAV,EAAA,KAHGG,GAAAH,EAAA,KAIHI,GAAAJ,EAAA,KACAW,GAAAX,EAAA,KACAY,GAAAZ,EAAA,KACAa,GARK,EAAA,CACL,GAAGV,EACH,UACA,UACA,YACA,YACA,OACA,YACA,oBACF,EAPE,EAAA,GAAAK,EACA,EAAA,GAAAC,EACA,EAAA,GAAAC,EAHG,EAAA,GAAAP,EAIH,EAAA,GAAAC,EACA,EAAA,GAAAO,EACA,EAAA,GAAAC,EACA,EAAA,GAAAC,E,eARKjB,CAUT,C"}
|
package/dist/solid.d.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { ThemeStore, ThemeStoreConfig, Themes } from "./index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Returns the store's state as signals (`themes()`, `resolvedThemes()`,
|
|
4
|
+
* `resolvedSystemThemes()`) and its methods. Call it inside a component (or
|
|
5
|
+
* `createRoot`); the subscription ends when that owner is cleaned up. Server
|
|
6
|
+
* rendering and hydration are handled automatically.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* import { useResonare } from 'resonare/solid'
|
|
10
|
+
*
|
|
11
|
+
* function ColorModeToggle() {
|
|
12
|
+
* const { themes, setThemes } = useResonare(store)
|
|
13
|
+
*
|
|
14
|
+
* const toggle = () => {
|
|
15
|
+
* const isDark = themes().colorMode === 'dark'
|
|
16
|
+
*
|
|
17
|
+
* setThemes({ colorMode: isDark ? 'light' : 'dark' })
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* return <button onClick={toggle}>{themes().colorMode}</button>
|
|
21
|
+
* }
|
|
22
|
+
*/
|
|
23
|
+
export declare function useResonare<T extends ThemeStoreConfig>(store: ThemeStore<T>): {
|
|
24
|
+
themes: () => Themes<T>;
|
|
25
|
+
resolvedThemes: () => Themes<T>;
|
|
26
|
+
resolvedSystemThemes: () => { [K in { [K in keyof T]: T[K] extends {
|
|
27
|
+
options: ReadonlyArray<infer U>;
|
|
28
|
+
} ? U extends {
|
|
29
|
+
media: ReadonlyArray<unknown>;
|
|
30
|
+
} ? K : never : never; }[keyof T]]: T[K] extends {
|
|
31
|
+
options: ReadonlyArray<infer U>;
|
|
32
|
+
} ? U extends string | number | boolean ? U : U extends {
|
|
33
|
+
value: string;
|
|
34
|
+
media?: readonly [string, string, string] | undefined;
|
|
35
|
+
} ? U extends {
|
|
36
|
+
media: ReadonlyArray<unknown>;
|
|
37
|
+
} ? never : U["value"] : never : never; };
|
|
38
|
+
destroy: () => void;
|
|
39
|
+
restore: () => void;
|
|
40
|
+
setThemes: (themes: Partial<Themes<T>> | ((currentThemes: Themes<T>) => Partial<Themes<T>>)) => void;
|
|
41
|
+
subscribe: (callback: (value: {
|
|
42
|
+
themes: Themes<T>;
|
|
43
|
+
resolvedThemes: Themes<T>;
|
|
44
|
+
resolvedSystemThemes: { [K in { [K in keyof T]: T[K] extends {
|
|
45
|
+
options: ReadonlyArray<infer U>;
|
|
46
|
+
} ? U extends {
|
|
47
|
+
media: ReadonlyArray<unknown>;
|
|
48
|
+
} ? K : never : never; }[keyof T]]: T[K] extends {
|
|
49
|
+
options: ReadonlyArray<infer U>;
|
|
50
|
+
} ? U extends string | number | boolean ? U : U extends {
|
|
51
|
+
value: string;
|
|
52
|
+
media?: readonly [string, string, string] | undefined;
|
|
53
|
+
} ? U extends {
|
|
54
|
+
media: ReadonlyArray<unknown>;
|
|
55
|
+
} ? never : U["value"] : never : never; };
|
|
56
|
+
}) => void) => () => void;
|
|
57
|
+
sync: () => (() => void) | undefined;
|
|
58
|
+
toPersist: () => {
|
|
59
|
+
themes: Partial<Themes<T>>;
|
|
60
|
+
systemOptions: {
|
|
61
|
+
[x: string]: [string, string];
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
updateSystemOption: <K extends { [K in keyof T]: T[K] extends {
|
|
65
|
+
options: ReadonlyArray<infer U>;
|
|
66
|
+
} ? U extends {
|
|
67
|
+
media: ReadonlyArray<unknown>;
|
|
68
|
+
} ? K : never : never; }[keyof T]>(themeKey: K, pair: [T[K] extends {
|
|
69
|
+
options: ReadonlyArray<infer U>;
|
|
70
|
+
} ? U extends string | number | boolean ? U : U extends {
|
|
71
|
+
value: string;
|
|
72
|
+
media?: readonly [string, string, string] | undefined;
|
|
73
|
+
} ? U extends {
|
|
74
|
+
media: ReadonlyArray<unknown>;
|
|
75
|
+
} ? never : U["value"] : never : never, T[K] extends {
|
|
76
|
+
options: ReadonlyArray<infer U>;
|
|
77
|
+
} ? U extends string | number | boolean ? U : U extends {
|
|
78
|
+
value: string;
|
|
79
|
+
media?: readonly [string, string, string] | undefined;
|
|
80
|
+
} ? U extends {
|
|
81
|
+
media: ReadonlyArray<unknown>;
|
|
82
|
+
} ? never : U["value"] : never : never]) => void;
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=solid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solid.d.ts","names":["_$_0.Themes"],"sources":["../src/solid.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;wBAyBgB,YAAY,UAAU,kBAAkB,OAAO,WAAW"}
|
package/dist/solid.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{createSignal as e,onCleanup as t,onMount as n,sharedConfig as r}from"solid-js";function i(i){let{destroy:a,getServerSnapshot:o,getSnapshot:s,restore:c,setThemes:l,subscribe:u,sync:d,toPersist:f,updateSystemOption:p}=i,m=!!r.context,[h,g]=e(m?o():s()),_=u(e=>{g(()=>e)});return t(_),m&&n(()=>{g(()=>s())}),{themes:()=>h().themes,resolvedThemes:()=>h().resolvedThemes,resolvedSystemThemes:()=>h().resolvedSystemThemes,destroy:a,restore:c,setThemes:l,subscribe:u,sync:d,toPersist:f,updateSystemOption:p}}export{i as useResonare};
|
|
2
|
+
//# sourceMappingURL=solid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solid.js","names":["useResonare","store","hydrating","sharedConfig","snapshot","setSnapshot","createSignal","getServerSnapshot","getSnapshot","unsubscribe","subscribe","value","onCleanup","onMount"],"sources":["../src/solid.ts"],"sourcesContent":["import { createSignal, onCleanup, onMount, sharedConfig } from 'solid-js'\n\nimport type { ThemeStore, ThemeStoreConfig } from '.'\n\n/**\n * Returns the store's state as signals (`themes()`, `resolvedThemes()`,\n * `resolvedSystemThemes()`) and its methods. Call it inside a component (or\n * `createRoot`); the subscription ends when that owner is cleaned up. Server\n * rendering and hydration are handled automatically.\n *\n * @example\n * import { useResonare } from 'resonare/solid'\n *\n * function ColorModeToggle() {\n * const { themes, setThemes } = useResonare(store)\n *\n * const toggle = () => {\n * const isDark = themes().colorMode === 'dark'\n *\n * setThemes({ colorMode: isDark ? 'light' : 'dark' })\n * }\n *\n * return <button onClick={toggle}>{themes().colorMode}</button>\n * }\n */\nexport function useResonare<T extends ThemeStoreConfig>(store: ThemeStore<T>) {\n const {\n destroy,\n getServerSnapshot,\n getSnapshot,\n restore,\n setThemes,\n subscribe,\n sync,\n toPersist,\n updateSystemOption,\n } = store\n\n // Match the server HTML while rendering on the server or hydrating, then\n // switch to the live snapshot once mounted.\n const hydrating = !!sharedConfig.context\n\n const [snapshot, setSnapshot] = createSignal(\n hydrating ? getServerSnapshot() : getSnapshot()\n )\n\n const unsubscribe = subscribe((value) => {\n setSnapshot(() => {\n return value\n })\n })\n\n onCleanup(unsubscribe)\n\n if (hydrating) {\n onMount(() => {\n setSnapshot(() => {\n return getSnapshot()\n })\n })\n }\n\n return {\n themes: () => {\n return snapshot().themes\n },\n resolvedThemes: () => {\n return snapshot().resolvedThemes\n },\n resolvedSystemThemes: () => {\n return snapshot().resolvedSystemThemes\n },\n destroy,\n restore,\n setThemes,\n subscribe,\n sync,\n toPersist,\n updateSystemOption,\n }\n}\n"],"mappings":"A,sFAyBA,SAAgBA,EAAwC,EAAsB,CAC5E,GAAM,CACJ,UACA,oBACA,cACA,UACA,YACA,YACA,OACA,YACA,sBACEC,EAIEC,EAAY,CAAC,CAACC,EAAa,QAE3B,CAACC,EAAUC,GAAeC,EAC9BJ,EAAYK,EAAkB,EAAIC,EAAY,CAChD,EAEMC,EAAcC,EAAW,GAAU,CACvCL,MACSM,CACR,CACH,CAAC,EAYD,OAVAC,EAAUH,CAAW,EAEjBP,GACFW,MAAc,CACZR,MACSG,EAAY,CACpB,CACH,CAAC,EAGI,CACL,WACSJ,EAAS,CAAC,CAAC,OAEpB,mBACSA,EAAS,CAAC,CAAC,eAEpB,yBACSA,EAAS,CAAC,CAAC,qBAEpB,UACA,UACA,YACA,YACA,OACA,YACA,oBACF,CACF,C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=`resonare`,t=`resonare/lite`,n=e=>JSON.stringify(e).replace(/</g,`\\u003c`),r=e=>{let t=String(e);return/^(async\s*)?(function\b|\(|[\w$]+\s*=>)/.test(t)?t:`Object.values({${t}})[0]`},i=({key:e,type:t=`localStorage`})=>({abortController:n})=>({get:()=>{try{return window[t].getItem(e)}catch{return null}},set:n=>{try{window[t].setItem(e,n)}catch{}},watch:r=>{let i=n=>{n.storageArea===window[t]&&n.key===e&&r(n.newValue)};return addEventListener(`storage`,i,n),()=>{removeEventListener(`storage`,i)}}}),a=({key:t})=>({abortController:n})=>{let r=/* @__PURE__ */ new Map,i=new BroadcastChannel(e);return n.signal.addEventListener(`abort`,()=>{i.close()}),{get:()=>r.get(t)??null,set:e=>{r.set(t,e)},broadcast:e=>{i.postMessage({key:t,value:e})},watch:e=>{let n=n=>{n.data.key===t&&(r.set(t,n.data.value),e(n.data.value))};return i.addEventListener(`message`,n),()=>{i.removeEventListener(`message`,n)}}}};export{e as a,n as i,a as n,t as o,r,i as t};
|
|
2
|
+
//# sourceMappingURL=storage-BqWA8jeP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-BqWA8jeP.js","names":["DEFAULT_KEY","DEFAULT_LITE_KEY","toScriptJson","value","toScriptFunction","source","handler","localStorageAdapter","type","key","listener","e","cb","abortController","memoryStorageAdapter","storage","channel"],"sources":["../src/constants.ts","../src/script.ts","../src/storage.ts"],"sourcesContent":["export const DEFAULT_KEY = 'resonare'\nexport const DEFAULT_LITE_KEY = 'resonare/lite'\n","/**\n * `JSON.stringify` for embedding in an inline `<script>`: `<` is escaped so a\n * value containing `</script>` cannot close the tag.\n */\nexport const toScriptJson = (value: unknown): string => {\n return JSON.stringify(value).replace(/</g, '\\\\u003c')\n}\n\n/**\n * Source of `handler` as a JavaScript expression. Object-method shorthand\n * (`handler() {}`) stringifies to something that is not an expression on its\n * own, so it is wrapped back into an object literal.\n */\nexport const toScriptFunction = (handler: Function): string => {\n const source = String(handler)\n\n return /^(async\\s*)?(function\\b|\\(|[\\w$]+\\s*=>)/.test(source)\n ? source\n : `Object.values({${source}})[0]`\n}\n","import { DEFAULT_KEY } from './constants'\n\n/**\n * Where a store saves its state. Values are strings: the full store saves\n * JSON, the lite store saves the theme name.\n */\nexport type StorageAdapter = {\n /** Returns the saved value, or `null` when nothing is saved. */\n get: () => string | null\n /** Saves a value. */\n set: (value: string) => void\n /** Optional: tells other tabs about a value just saved with `set`. */\n broadcast?: (value: string) => void\n /**\n * Optional: calls `cb` when another tab saves a value (`null` when it clears\n * it). Returns a function that stops watching. Used by `store.sync()`.\n */\n watch?: (cb: (value: string | null) => void) => () => void\n}\n\n/**\n * What a store's `storage` option takes: a function that creates the adapter.\n * `abortController` is aborted when the store is destroyed; use it to remove\n * listeners.\n */\nexport type StorageAdapterCreate = ({\n abortController,\n}: {\n abortController: AbortController\n}) => StorageAdapter\n\n/**\n * Shape of the built-in adapters such as `localStorageAdapter`: takes options\n * (like the key) and returns a {@link StorageAdapterCreate}.\n */\nexport type StorageAdapterCreator<Options> = (\n options: Options\n) => StorageAdapterCreate\n\n/**\n * Saves the store in `localStorage` (default) or `sessionStorage` under `key`,\n * and supports `store.sync()` across tabs. If storage is blocked or full,\n * reads return nothing and writes are skipped.\n *\n * @example\n * import { createThemeStore, localStorageAdapter } from 'resonare'\n *\n * const store = createThemeStore(\n * { colorMode: { options: ['light', 'dark'] } },\n * { storage: localStorageAdapter({ key: 'app', type: 'localStorage' }) }\n * )\n */\nexport const localStorageAdapter: StorageAdapterCreator<{\n key: string\n type?: 'localStorage' | 'sessionStorage'\n}> = ({ key, type = 'localStorage' }) => {\n return ({ abortController }) => {\n return {\n // Storage access throws when it is blocked (e.g. cookies disabled,\n // sandboxed iframes) or full.\n get: () => {\n try {\n return window[type].getItem(key)\n } catch {\n return null\n }\n },\n\n set: (value) => {\n try {\n window[type].setItem(key, value)\n } catch {}\n },\n\n watch: (cb) => {\n const listener = (e: StorageEvent) => {\n if (e.storageArea === window[type] && e.key === key) {\n cb(e.newValue)\n }\n }\n\n // Passing the controller as options (it has `signal`) removes the\n // listener when the store is destroyed.\n addEventListener('storage', listener, abortController)\n\n return () => {\n removeEventListener('storage', listener)\n }\n },\n }\n }\n}\n\n/**\n * Keeps the store in memory only, and supports `store.sync()` across tabs\n * through `BroadcastChannel`. Use it when you save the state yourself (e.g.\n * `toPersist()` to a database) and don't want it in `localStorage`.\n *\n * @example\n * import { createThemeStore, memoryStorageAdapter } from 'resonare'\n *\n * const store = createThemeStore(\n * { colorMode: { options: ['light', 'dark'] } },\n * { storage: memoryStorageAdapter({ key: 'app' }) }\n * )\n */\nexport const memoryStorageAdapter: StorageAdapterCreator<{\n key: string\n}> = ({ key }) => {\n return ({ abortController }) => {\n const storage = new Map<string, string>()\n\n const channel = new BroadcastChannel(DEFAULT_KEY)\n\n // An open channel keeps a Node process alive.\n abortController.signal.addEventListener('abort', () => {\n channel.close()\n })\n\n return {\n get: () => {\n return storage.get(key) ?? null\n },\n\n set: (value) => {\n storage.set(key, value)\n },\n\n broadcast: (value) => {\n channel.postMessage({ key, value })\n },\n\n watch: (cb) => {\n const listener = (e: MessageEvent) => {\n if (e.data.key === key) {\n storage.set(key, e.data.value)\n\n cb(e.data.value)\n }\n }\n\n channel.addEventListener('message', listener)\n\n return () => {\n channel.removeEventListener('message', listener)\n }\n },\n }\n }\n}\n"],"mappings":"AAAA,MAAaA,EAAc,WACdC,EAAmB,gBCGnBC,EAAgB,GACpB,KAAK,UAAUC,CAAK,CAAC,CAAC,QAAQ,KAAM,SAAS,EAQzCC,EAAoB,GAA8B,CAC7D,IAAMC,EAAS,OAAOC,CAAO,EAE7B,MAAO,0CAA0C,KAAKD,CAAM,EACxDA,EACA,kBAAkBA,EAAO,MAC/B,ECiCaE,GAGP,CAAE,MAAK,OAAO,mBACV,CAAE,sBACD,CAGL,QAAW,CACT,GAAI,CACF,OAAO,OAAOC,EAAK,CAAC,QAAQC,CAAG,CACjC,MAAQ,CACN,OAAO,IACT,CACF,EAEA,IAAM,GAAU,CACd,GAAI,CACF,OAAOD,EAAK,CAAC,QAAQC,EAAKN,CAAK,CACjC,MAAQ,CAAC,CACX,EAEA,MAAQ,GAAO,CACb,IAAMO,EAAY,GAAoB,CAChCC,EAAE,cAAgB,OAAOH,IAASG,EAAE,MAAQF,GAC9CG,EAAGD,EAAE,QAAQ,CAEjB,EAMA,OAFA,iBAAiB,UAAWD,EAAUG,CAAe,MAExC,CACX,oBAAoB,UAAWH,CAAQ,CACzC,CACF,CACF,GAiBSI,GAEP,CAAE,UACE,CAAE,qBAAsB,CAC9B,IAAMC,kBAAU,IAAI,IAEdC,EAAU,IAAI,iBAAiBhB,CAAW,EAOhD,OAJAa,EAAgB,OAAO,iBAAiB,YAAe,CACrDG,EAAQ,MAAM,CAChB,CAAC,EAEM,CACL,QACSD,EAAQ,IAAIN,CAAG,GAAK,KAG7B,IAAM,GAAU,CACdM,EAAQ,IAAIN,EAAKN,CAAK,CACxB,EAEA,UAAY,GAAU,CACpBa,EAAQ,YAAY,CAAE,MAAK,OAAM,CAAC,CACpC,EAEA,MAAQ,GAAO,CACb,IAAMN,EAAY,GAAoB,CAChCC,EAAE,KAAK,MAAQF,IACjBM,EAAQ,IAAIN,EAAKE,EAAE,KAAK,KAAK,EAE7BC,EAAGD,EAAE,KAAK,KAAK,EAEnB,EAIA,OAFAK,EAAQ,iBAAiB,UAAWN,CAAQ,MAE/B,CACXM,EAAQ,oBAAoB,UAAWN,CAAQ,CACjD,CACF,CACF,CACF,E"}
|