resonare 0.2.0 → 0.4.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 +398 -270
- package/dist/effects-core-CuoeZrRP.js +2 -0
- package/dist/effects-core-CuoeZrRP.js.map +1 -0
- package/dist/effects-core-DPJyVK-w.d.ts +14 -0
- package/dist/effects-core-DPJyVK-w.d.ts.map +1 -0
- package/dist/effects.d.ts +105 -0
- package/dist/effects.d.ts.map +1 -0
- package/dist/effects.js +2 -0
- package/dist/effects.js.map +1 -0
- package/dist/index.d.ts +233 -30
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lite-effects.d.ts +65 -0
- package/dist/lite-effects.d.ts.map +1 -0
- package/dist/lite-effects.js +2 -0
- package/dist/lite-effects.js.map +1 -0
- package/dist/lite-react.d.ts +31 -22
- package/dist/lite-react.d.ts.map +1 -1
- package/dist/lite-react.js +1 -1
- package/dist/lite-react.js.map +1 -1
- package/dist/lite-solid.d.ts +46 -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 +45 -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 +53 -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 +110 -23
- package/dist/lite.d.ts.map +1 -1
- package/dist/lite.js +1 -1
- package/dist/lite.js.map +1 -1
- package/dist/react.d.ts +62 -38
- 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 +99 -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-CsXjZKyt.d.ts +65 -0
- package/dist/storage-CsXjZKyt.d.ts.map +1 -0
- package/dist/storage-fOH2xeQ1.js +2 -0
- package/dist/storage-fOH2xeQ1.js.map +1 -0
- package/dist/svelte.d.ts +101 -0
- package/dist/svelte.d.ts.map +1 -0
- package/dist/svelte.js +2 -0
- package/dist/svelte.js.map +1 -0
- package/dist/utils-CWI4hy3w.js +2 -0
- package/dist/utils-CWI4hy3w.js.map +1 -0
- package/dist/vue.d.ts +97 -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
- package/dist/storage-B5xjLRee.js +0 -2
- package/dist/storage-B5xjLRee.js.map +0 -1
- package/dist/storage-DGYV332J.d.ts +0 -23
- package/dist/storage-DGYV332J.d.ts.map +0 -1
package/dist/svelte.d.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { ThemeStore, ThemeStoreConfig, Themes } from "./index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Returns the store's state (`themes`, `resolvedThemes`,
|
|
4
|
+
* `resolvedSystemThemes`), each read through `.current`, and its methods.
|
|
5
|
+
* `.current` is reactive in templates, `$derived` and `$effect`, and the store
|
|
6
|
+
* is subscribed only while something reads it. Hydration needs nothing extra:
|
|
7
|
+
* Svelte fixes any markup that differs from the server's.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* <script lang="ts">
|
|
11
|
+
* import { useResonare } from 'resonare/svelte'
|
|
12
|
+
*
|
|
13
|
+
* const { themes, setThemes } = useResonare(store)
|
|
14
|
+
* </script>
|
|
15
|
+
*
|
|
16
|
+
* <p>Color mode: {themes.current.colorMode}</p>
|
|
17
|
+
* <button onclick={() => setThemes({ colorMode: 'dark' })}>Dark</button>
|
|
18
|
+
*/
|
|
19
|
+
export declare function useResonare<T extends ThemeStoreConfig>(store: ThemeStore<T>): {
|
|
20
|
+
themes: {
|
|
21
|
+
readonly current: Themes<T>;
|
|
22
|
+
};
|
|
23
|
+
resolvedThemes: {
|
|
24
|
+
readonly current: Themes<T>;
|
|
25
|
+
};
|
|
26
|
+
resolvedSystemThemes: {
|
|
27
|
+
readonly current: { [K in { [K in keyof T]: T[K] extends {
|
|
28
|
+
options: ReadonlyArray<infer U>;
|
|
29
|
+
} ? U extends {
|
|
30
|
+
media: ReadonlyArray<unknown>;
|
|
31
|
+
} ? K : never : never; }[keyof T]]: T[K] extends {
|
|
32
|
+
options: ReadonlyArray<infer U>;
|
|
33
|
+
} ? U extends string | number | boolean ? U : U extends {
|
|
34
|
+
value: string;
|
|
35
|
+
media?: readonly [string, string, string] | undefined;
|
|
36
|
+
} ? U extends {
|
|
37
|
+
media: ReadonlyArray<unknown>;
|
|
38
|
+
} ? never : U["value"] : never : never; };
|
|
39
|
+
};
|
|
40
|
+
destroy: () => void;
|
|
41
|
+
restore: () => void;
|
|
42
|
+
setThemes: (themes: Partial<Themes<T>> | ((currentThemes: Themes<T>) => Partial<Themes<T>>)) => void;
|
|
43
|
+
subscribe: (callback: (value: {
|
|
44
|
+
themes: Themes<T>;
|
|
45
|
+
resolvedThemes: Themes<T>;
|
|
46
|
+
resolvedSystemThemes: { [K in { [K in keyof T]: T[K] extends {
|
|
47
|
+
options: ReadonlyArray<infer U>;
|
|
48
|
+
} ? U extends {
|
|
49
|
+
media: ReadonlyArray<unknown>;
|
|
50
|
+
} ? K : never : never; }[keyof T]]: T[K] extends {
|
|
51
|
+
options: ReadonlyArray<infer U>;
|
|
52
|
+
} ? U extends string | number | boolean ? U : U extends {
|
|
53
|
+
value: string;
|
|
54
|
+
media?: readonly [string, string, string] | undefined;
|
|
55
|
+
} ? U extends {
|
|
56
|
+
media: ReadonlyArray<unknown>;
|
|
57
|
+
} ? never : U["value"] : never : never; };
|
|
58
|
+
}, prev?: {
|
|
59
|
+
themes: Themes<T>;
|
|
60
|
+
resolvedThemes: Themes<T>;
|
|
61
|
+
resolvedSystemThemes: { [K in { [K in keyof T]: T[K] extends {
|
|
62
|
+
options: ReadonlyArray<infer U>;
|
|
63
|
+
} ? U extends {
|
|
64
|
+
media: ReadonlyArray<unknown>;
|
|
65
|
+
} ? K : never : never; }[keyof T]]: T[K] extends {
|
|
66
|
+
options: ReadonlyArray<infer U>;
|
|
67
|
+
} ? U extends string | number | boolean ? U : U extends {
|
|
68
|
+
value: string;
|
|
69
|
+
media?: readonly [string, string, string] | undefined;
|
|
70
|
+
} ? U extends {
|
|
71
|
+
media: ReadonlyArray<unknown>;
|
|
72
|
+
} ? never : U["value"] : never : never; };
|
|
73
|
+
} | undefined) => void) => () => void;
|
|
74
|
+
sync: () => (() => void) | undefined;
|
|
75
|
+
toPersist: () => {
|
|
76
|
+
themes: Partial<Themes<T>>;
|
|
77
|
+
systemOptions: {
|
|
78
|
+
[x: string]: [string, string];
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
updateSystemOption: <K extends { [K in keyof T]: T[K] extends {
|
|
82
|
+
options: ReadonlyArray<infer U>;
|
|
83
|
+
} ? U extends {
|
|
84
|
+
media: ReadonlyArray<unknown>;
|
|
85
|
+
} ? K : never : never; }[keyof T]>(themeKey: K, pair: [T[K] extends {
|
|
86
|
+
options: ReadonlyArray<infer U>;
|
|
87
|
+
} ? U extends string | number | boolean ? U : U extends {
|
|
88
|
+
value: string;
|
|
89
|
+
media?: readonly [string, string, string] | undefined;
|
|
90
|
+
} ? U extends {
|
|
91
|
+
media: ReadonlyArray<unknown>;
|
|
92
|
+
} ? never : U["value"] : never : never, T[K] extends {
|
|
93
|
+
options: ReadonlyArray<infer U>;
|
|
94
|
+
} ? U extends string | number | boolean ? U : U extends {
|
|
95
|
+
value: string;
|
|
96
|
+
media?: readonly [string, string, string] | undefined;
|
|
97
|
+
} ? U extends {
|
|
98
|
+
media: ReadonlyArray<unknown>;
|
|
99
|
+
} ? never : U["value"] : never : never]) => void;
|
|
100
|
+
};
|
|
101
|
+
//# sourceMappingURL=svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svelte.d.ts","names":["_$_0.Themes"],"sources":["../src/svelte.ts"],"mappings":";;;;;;;;;;;;;;;;;;wBAqBgB,YAAY,UAAU,kBAAkB,OAAO,WAAW;;aA0BhE,SAAOA,OAAA;;;aAKP,SAAOA,OAAA;;;aAKP,YAAO,QAAA,WAAA,IAAA,EAAA"}
|
package/dist/svelte.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{createSubscriber as e}from"svelte/reactivity";function t(t){let{destroy:n,getSnapshot:r,restore:i,setThemes:a,subscribe:o,sync:s,toPersist:c,updateSystemOption:l}=t,u=e(e=>o(()=>{e()})),d=()=>(u(),r());return{themes:{get current(){return d().themes}},resolvedThemes:{get current(){return d().resolvedThemes}},resolvedSystemThemes:{get current(){return d().resolvedSystemThemes}},destroy:n,restore:i,setThemes:a,subscribe:o,sync:s,toPersist:c,updateSystemOption:l}}export{t as useResonare};
|
|
2
|
+
//# sourceMappingURL=svelte.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svelte.js","names":["useResonare","store","track","createSubscriber","subscribe","update","read","getSnapshot"],"sources":["../src/svelte.ts"],"sourcesContent":["import { createSubscriber } from 'svelte/reactivity'\n\nimport type { ThemeStore, ThemeStoreConfig } from '.'\n\n/**\n * Returns the store's state (`themes`, `resolvedThemes`,\n * `resolvedSystemThemes`), each read through `.current`, and its methods.\n * `.current` is reactive in templates, `$derived` and `$effect`, and the store\n * is subscribed only while something reads it. Hydration needs nothing extra:\n * Svelte fixes any markup that differs from the server's.\n *\n * @example\n * <script lang=\"ts\">\n * import { useResonare } from 'resonare/svelte'\n *\n * const { themes, setThemes } = useResonare(store)\n * </script>\n *\n * <p>Color mode: {themes.current.colorMode}</p>\n * <button onclick={() => setThemes({ colorMode: 'dark' })}>Dark</button>\n */\nexport function useResonare<T extends ThemeStoreConfig>(store: ThemeStore<T>) {\n const {\n destroy,\n getSnapshot,\n restore,\n setThemes,\n subscribe,\n sync,\n toPersist,\n updateSystemOption,\n } = 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 themes: {\n get current() {\n return read().themes\n },\n },\n resolvedThemes: {\n get current() {\n return read().resolvedThemes\n },\n },\n resolvedSystemThemes: {\n get current() {\n return read().resolvedSystemThemes\n },\n },\n destroy,\n restore,\n setThemes,\n subscribe,\n sync,\n toPersist,\n updateSystemOption,\n }\n}\n"],"mappings":"A,qDAqBA,SAAgBA,EAAwC,EAAsB,CAC5E,GAAM,CACJ,UACA,cACA,UACA,YACA,YACA,OACA,YACA,sBACEC,EAEEC,EAAQC,EAAkB,GACvBC,MAAgB,CACrBC,EAAO,CACT,CAAC,CACF,EAEKC,OACJJ,EAAM,EAECK,EAAY,GAGrB,MAAO,CACL,OAAQ,CACN,IAAI,SAAU,CACZ,OAAOD,EAAK,CAAC,CAAC,MAChB,CACF,EACA,eAAgB,CACd,IAAI,SAAU,CACZ,OAAOA,EAAK,CAAC,CAAC,cAChB,CACF,EACA,qBAAsB,CACpB,IAAI,SAAU,CACZ,OAAOA,EAAK,CAAC,CAAC,oBAChB,CACF,EACA,UACA,UACA,YACA,YACA,OACA,YACA,oBACF,CACF,C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils-CWI4hy3w.js","names":["DEFAULT_KEY","DEFAULT_LITE_KEY","toScriptJson","value","toScriptFunction","source","handler"],"sources":["../src/utils.ts"],"sourcesContent":["export const DEFAULT_KEY = 'resonare'\nexport const DEFAULT_LITE_KEY = 'resonare/lite'\n\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 = (\n handler: (...args: Array<never>) => unknown\n): 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"],"mappings":"AAAA,MAAaA,EAAc,WACdC,EAAmB,gBAMnBC,EAAgB,GACpB,KAAK,UAAUC,CAAK,CAAC,CAAC,QAAQ,KAAM,SAAS,EAQzCC,EACX,GACW,CACX,IAAMC,EAAS,OAAOC,CAAO,EAE7B,MAAO,0CAA0C,KAAKD,CAAM,EACxDA,EACA,kBAAkBA,EAAO,MAC/B,E"}
|
package/dist/vue.d.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { ThemeStore, ThemeStoreConfig, Themes } from "./index.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 (`themes`, `resolvedThemes`,
|
|
14
|
+
* `resolvedSystemThemes`) 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 { useResonare } from 'resonare/vue'
|
|
21
|
+
*
|
|
22
|
+
* // hydrate: true only in server-rendered apps
|
|
23
|
+
* const { themes, setThemes } = useResonare(store, { hydrate: true })
|
|
24
|
+
* </script>
|
|
25
|
+
*
|
|
26
|
+
* <template>
|
|
27
|
+
* <p>Color mode: {{ themes.colorMode }}</p>
|
|
28
|
+
* <button @click="setThemes({ colorMode: 'dark' })">Dark</button>
|
|
29
|
+
* </template>
|
|
30
|
+
*/
|
|
31
|
+
export declare function useResonare<T extends ThemeStoreConfig>(store: ThemeStore<T>, { hydrate }?: UseResonareOptions): {
|
|
32
|
+
themes: ComputedRef<Themes<T>>;
|
|
33
|
+
resolvedThemes: ComputedRef<Themes<T>>;
|
|
34
|
+
resolvedSystemThemes: ComputedRef<ReturnType<ThemeStore<T>['getSnapshot']>['resolvedSystemThemes']>;
|
|
35
|
+
destroy: () => void;
|
|
36
|
+
restore: () => void;
|
|
37
|
+
setThemes: (themes: Partial<Themes<T>> | ((currentThemes: Themes<T>) => Partial<Themes<T>>)) => void;
|
|
38
|
+
subscribe: (callback: (value: {
|
|
39
|
+
themes: Themes<T>;
|
|
40
|
+
resolvedThemes: Themes<T>;
|
|
41
|
+
resolvedSystemThemes: { [K in { [K in keyof T]: T[K] extends {
|
|
42
|
+
options: ReadonlyArray<infer U>;
|
|
43
|
+
} ? U extends {
|
|
44
|
+
media: ReadonlyArray<unknown>;
|
|
45
|
+
} ? K : never : never; }[keyof T]]: T[K] extends {
|
|
46
|
+
options: ReadonlyArray<infer U>;
|
|
47
|
+
} ? U extends string | number | boolean ? U : U extends {
|
|
48
|
+
value: string;
|
|
49
|
+
media?: readonly [string, string, string] | undefined;
|
|
50
|
+
} ? U extends {
|
|
51
|
+
media: ReadonlyArray<unknown>;
|
|
52
|
+
} ? never : U["value"] : never : never; };
|
|
53
|
+
}, prev?: {
|
|
54
|
+
themes: Themes<T>;
|
|
55
|
+
resolvedThemes: Themes<T>;
|
|
56
|
+
resolvedSystemThemes: { [K in { [K in keyof T]: T[K] extends {
|
|
57
|
+
options: ReadonlyArray<infer U>;
|
|
58
|
+
} ? U extends {
|
|
59
|
+
media: ReadonlyArray<unknown>;
|
|
60
|
+
} ? K : never : never; }[keyof T]]: T[K] extends {
|
|
61
|
+
options: ReadonlyArray<infer U>;
|
|
62
|
+
} ? U extends string | number | boolean ? U : U extends {
|
|
63
|
+
value: string;
|
|
64
|
+
media?: readonly [string, string, string] | undefined;
|
|
65
|
+
} ? U extends {
|
|
66
|
+
media: ReadonlyArray<unknown>;
|
|
67
|
+
} ? never : U["value"] : never : never; };
|
|
68
|
+
} | undefined) => void) => () => void;
|
|
69
|
+
sync: () => (() => void) | undefined;
|
|
70
|
+
toPersist: () => {
|
|
71
|
+
themes: Partial<Themes<T>>;
|
|
72
|
+
systemOptions: {
|
|
73
|
+
[x: string]: [string, string];
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
updateSystemOption: <K extends { [K in keyof T]: T[K] extends {
|
|
77
|
+
options: ReadonlyArray<infer U>;
|
|
78
|
+
} ? U extends {
|
|
79
|
+
media: ReadonlyArray<unknown>;
|
|
80
|
+
} ? K : never : never; }[keyof T]>(themeKey: K, pair: [T[K] extends {
|
|
81
|
+
options: ReadonlyArray<infer U>;
|
|
82
|
+
} ? U extends string | number | boolean ? U : U extends {
|
|
83
|
+
value: string;
|
|
84
|
+
media?: readonly [string, string, string] | undefined;
|
|
85
|
+
} ? U extends {
|
|
86
|
+
media: ReadonlyArray<unknown>;
|
|
87
|
+
} ? never : U["value"] : never : never, T[K] extends {
|
|
88
|
+
options: ReadonlyArray<infer U>;
|
|
89
|
+
} ? U extends string | number | boolean ? U : U extends {
|
|
90
|
+
value: string;
|
|
91
|
+
media?: readonly [string, string, string] | undefined;
|
|
92
|
+
} ? U extends {
|
|
93
|
+
media: ReadonlyArray<unknown>;
|
|
94
|
+
} ? never : U["value"] : never : never]) => void;
|
|
95
|
+
};
|
|
96
|
+
export {};
|
|
97
|
+
//# sourceMappingURL=vue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vue.d.ts","names":[],"sources":["../src/vue.ts"],"mappings":";;KAYK;;;;;;;EAOH;;;;;;;;;;;;;;;;;;;;;wBAsBc,YAAY,UAAU,kBACpC,OAAO,WAAW,MAChB,YAAmB;EAkDb,QAAA,YAAY,OAAO;EAGnB,gBAAA,YAAY,OAAO;EAGnB,sBAAA,YACJ,WAAW,WAAW"}
|
package/dist/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,setThemes:f,subscribe:p,sync:m,toPersist:h,updateSystemOption:g}=o,_=t(),v=a(s&&_?l():u()),y,b=()=>{v.value=u(),y=p(e=>{v.value=e})},x=()=>{y?.()};return _?(n(b),i(x)):(b(),r(x)),{themes:e(()=>v.value.themes),resolvedThemes:e(()=>v.value.resolvedThemes),resolvedSystemThemes:e(()=>v.value.resolvedSystemThemes),destroy:c,restore:d,setThemes:f,subscribe:p,sync:m,toPersist:h,updateSystemOption:g}}export{o as useResonare};
|
|
2
|
+
//# sourceMappingURL=vue.js.map
|
package/dist/vue.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vue.js","names":["useResonare","store","instance","getCurrentInstance","snapshot","shallowRef","hydrate","getServerSnapshot","getSnapshot","unsubscribe","start","subscribe","value","stop","onMounted","onUnmounted","onScopeDispose","computed"],"sources":["../src/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, ThemeStoreConfig, Themes } from '.'\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 (`themes`, `resolvedThemes`,\n * `resolvedSystemThemes`) 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 { useResonare } from 'resonare/vue'\n *\n * // hydrate: true only in server-rendered apps\n * const { themes, setThemes } = useResonare(store, { hydrate: true })\n * </script>\n *\n * <template>\n * <p>Color mode: {{ themes.colorMode }}</p>\n * <button @click=\"setThemes({ colorMode: 'dark' })\">Dark</button>\n * </template>\n */\nexport function useResonare<T extends ThemeStoreConfig>(\n store: ThemeStore<T>,\n { hydrate = false }: UseResonareOptions = {}\n) {\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 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 themes: computed(() => {\n return snapshot.value.themes\n }) as ComputedRef<Themes<T>>,\n resolvedThemes: computed(() => {\n return snapshot.value.resolvedThemes\n }) as ComputedRef<Themes<T>>,\n resolvedSystemThemes: computed(() => {\n return snapshot.value.resolvedSystemThemes\n }) as ComputedRef<\n ReturnType<ThemeStore<T>['getSnapshot']>['resolvedSystemThemes']\n >,\n destroy,\n restore,\n setThemes,\n subscribe,\n sync,\n toPersist,\n updateSystemOption,\n }\n}\n"],"mappings":"A,2HAyCA,SAAgBA,EACd,EACA,CAAE,UAAU,IAA8B,CAAC,EAC3C,CACA,GAAM,CACJ,UACA,oBACA,cACA,UACA,YACA,YACA,OACA,YACA,sBACEC,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,OAAQI,MACCb,EAAS,MAAM,MACvB,EACD,eAAgBa,MACPb,EAAS,MAAM,cACvB,EACD,qBAAsBa,MACbb,EAAS,MAAM,oBACvB,EAGD,UACA,UACA,YACA,YACA,OACA,YACA,oBACF,CACF,C"}
|
package/package.json
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "resonare",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Resonare",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"theming",
|
|
7
6
|
"dark mode",
|
|
7
|
+
"theming",
|
|
8
8
|
"user preferences"
|
|
9
9
|
],
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"author": "Si Phuoc <phuoc317049@gmail.com>",
|
|
10
12
|
"repository": {
|
|
11
13
|
"type": "git",
|
|
12
14
|
"url": "https://github.com/phuoccss/resonare.git",
|
|
13
15
|
"directory": "resonare"
|
|
14
16
|
},
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
18
20
|
"type": "module",
|
|
21
|
+
"sideEffects": false,
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
19
23
|
"exports": {
|
|
20
24
|
".": {
|
|
21
25
|
"types": "./dist/index.d.ts",
|
|
@@ -25,6 +29,22 @@
|
|
|
25
29
|
"types": "./dist/react.d.ts",
|
|
26
30
|
"import": "./dist/react.js"
|
|
27
31
|
},
|
|
32
|
+
"./solid": {
|
|
33
|
+
"types": "./dist/solid.d.ts",
|
|
34
|
+
"import": "./dist/solid.js"
|
|
35
|
+
},
|
|
36
|
+
"./svelte": {
|
|
37
|
+
"types": "./dist/svelte.d.ts",
|
|
38
|
+
"import": "./dist/svelte.js"
|
|
39
|
+
},
|
|
40
|
+
"./vue": {
|
|
41
|
+
"types": "./dist/vue.d.ts",
|
|
42
|
+
"import": "./dist/vue.js"
|
|
43
|
+
},
|
|
44
|
+
"./effects": {
|
|
45
|
+
"types": "./dist/effects.d.ts",
|
|
46
|
+
"import": "./dist/effects.js"
|
|
47
|
+
},
|
|
28
48
|
"./lite": {
|
|
29
49
|
"types": "./dist/lite.d.ts",
|
|
30
50
|
"import": "./dist/lite.js"
|
|
@@ -32,47 +52,70 @@
|
|
|
32
52
|
"./lite/react": {
|
|
33
53
|
"types": "./dist/lite-react.d.ts",
|
|
34
54
|
"import": "./dist/lite-react.js"
|
|
55
|
+
},
|
|
56
|
+
"./lite/solid": {
|
|
57
|
+
"types": "./dist/lite-solid.d.ts",
|
|
58
|
+
"import": "./dist/lite-solid.js"
|
|
59
|
+
},
|
|
60
|
+
"./lite/svelte": {
|
|
61
|
+
"types": "./dist/lite-svelte.d.ts",
|
|
62
|
+
"import": "./dist/lite-svelte.js"
|
|
63
|
+
},
|
|
64
|
+
"./lite/vue": {
|
|
65
|
+
"types": "./dist/lite-vue.d.ts",
|
|
66
|
+
"import": "./dist/lite-vue.js"
|
|
67
|
+
},
|
|
68
|
+
"./lite/effects": {
|
|
69
|
+
"types": "./dist/lite-effects.d.ts",
|
|
70
|
+
"import": "./dist/lite-effects.js"
|
|
35
71
|
}
|
|
36
72
|
},
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
"dist"
|
|
40
|
-
],
|
|
41
|
-
"dependencies": {
|
|
42
|
-
"react-compiler-runtime": "1.0.0"
|
|
73
|
+
"publishConfig": {
|
|
74
|
+
"access": "public"
|
|
43
75
|
},
|
|
44
76
|
"devDependencies": {
|
|
45
|
-
"@
|
|
46
|
-
"@
|
|
47
|
-
"@types/
|
|
48
|
-
"@types/react": "19.
|
|
49
|
-
"@vitejs/plugin-react": "6.
|
|
50
|
-
"babel-plugin-react-compiler": "1.0.0",
|
|
77
|
+
"@size-limit/preset-small-lib": "14.3.0",
|
|
78
|
+
"@types/node": "26.6.6",
|
|
79
|
+
"@types/react": "19.3.0",
|
|
80
|
+
"@types/react-dom": "19.3.0",
|
|
81
|
+
"@vitejs/plugin-react": "6.1.2",
|
|
51
82
|
"cross-env": "10.1.0",
|
|
52
|
-
"jsdom": "
|
|
53
|
-
"react": "
|
|
54
|
-
"react
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
83
|
+
"jsdom": "30.1.3",
|
|
84
|
+
"oxc-transform-react": "0.156.0",
|
|
85
|
+
"react": "19.3.1",
|
|
86
|
+
"react-dom": "19.3.1",
|
|
87
|
+
"size-limit": "14.3.0",
|
|
88
|
+
"solid-js": "1.9.18",
|
|
89
|
+
"svelte": "5.57.3",
|
|
90
|
+
"typescript": "7.0.2",
|
|
91
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@1.4.0",
|
|
92
|
+
"vite-plus": "1.4.0",
|
|
93
|
+
"vue": "3.5.44"
|
|
60
94
|
},
|
|
61
95
|
"peerDependencies": {
|
|
62
|
-
"react": "^
|
|
96
|
+
"react": "^19.0.0",
|
|
97
|
+
"solid-js": "^1.6.0",
|
|
98
|
+
"svelte": "^5.7.0",
|
|
99
|
+
"vue": "^3.2.0"
|
|
63
100
|
},
|
|
64
101
|
"peerDependenciesMeta": {
|
|
65
102
|
"react": {
|
|
66
103
|
"optional": true
|
|
104
|
+
},
|
|
105
|
+
"solid-js": {
|
|
106
|
+
"optional": true
|
|
107
|
+
},
|
|
108
|
+
"svelte": {
|
|
109
|
+
"optional": true
|
|
110
|
+
},
|
|
111
|
+
"vue": {
|
|
112
|
+
"optional": true
|
|
67
113
|
}
|
|
68
114
|
},
|
|
69
|
-
"publishConfig": {
|
|
70
|
-
"access": "public"
|
|
71
|
-
},
|
|
72
115
|
"scripts": {
|
|
73
|
-
"build": "
|
|
74
|
-
"dev": "
|
|
116
|
+
"build": "vp pack",
|
|
117
|
+
"dev": "vp pack --watch",
|
|
75
118
|
"size": "pnpm build && size-limit",
|
|
76
|
-
"test": "
|
|
119
|
+
"test": "vp test"
|
|
77
120
|
}
|
|
78
121
|
}
|
package/dist/storage-B5xjLRee.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const e=`resonare`,t=`resonare/lite`,n=({key:e,type:t=`localStorage`})=>({abortController:n})=>({get:()=>window[t].getItem(e),set:n=>{window[t].setItem(e,n)},watch:r=>{let i=new AbortController;return window.addEventListener(`storage`,n=>{n.storageArea===window[t]&&n.key===e&&r(n.newValue)},{signal:AbortSignal.any([n.signal,i.signal])}),()=>{i.abort()}}}),r=({key:t})=>({abortController:n})=>{let r=new Map,i=new BroadcastChannel(e);return{get:()=>r.get(t)??null,set:e=>{r.set(t,e)},broadcast:e=>{i.postMessage({key:t,value:e})},watch:e=>{let r=new AbortController;return i.addEventListener(`message`,n=>{n.data.key===t&&e(n.data.value)},{signal:AbortSignal.any([n.signal,r.signal])}),()=>{r.abort()}}}};export{t as i,r as n,e as r,n as t};
|
|
2
|
-
//# sourceMappingURL=storage-B5xjLRee.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"storage-B5xjLRee.js","names":["DEFAULT_KEY","DEFAULT_LITE_KEY","DEFAULT_KEY","StorageAdapter","get","set","value","broadcast","watch","cb","StorageAdapterCreate","abortController","AbortController","StorageAdapterCreator","options","Options","localStorageAdapter","key","type","window","getItem","setItem","controller","addEventListener","e","storageArea","newValue","signal","AbortSignal","any","abort","memoryStorageAdapter","storage","Map","channel","BroadcastChannel","postMessage","data"],"sources":["../src/constants.ts","../src/storage.ts"],"sourcesContent":["export const DEFAULT_KEY = 'resonare'\nexport const DEFAULT_LITE_KEY = 'resonare/lite'\n","import { DEFAULT_KEY } from './constants'\n\nexport type StorageAdapter = {\n\tget: () => string | null\n\tset: (value: string) => void\n\tbroadcast?: (value: string) => void\n\twatch?: (cb: (value: string | null) => void) => () => void\n}\n\nexport type StorageAdapterCreate = ({\n\tabortController,\n}: {\n\tabortController: AbortController\n}) => StorageAdapter\n\nexport type StorageAdapterCreator<Options> = (\n\toptions: Options,\n) => StorageAdapterCreate\n\nexport const localStorageAdapter: StorageAdapterCreator<{\n\tkey: string\n\ttype?: 'localStorage' | 'sessionStorage'\n}> = ({ key, type = 'localStorage' }) => {\n\treturn ({ abortController }) => {\n\t\treturn {\n\t\t\tget: () => {\n\t\t\t\treturn window[type].getItem(key)\n\t\t\t},\n\n\t\t\tset: (value) => {\n\t\t\t\twindow[type].setItem(key, value)\n\t\t\t},\n\n\t\t\twatch: (cb) => {\n\t\t\t\tconst controller = new AbortController()\n\n\t\t\t\twindow.addEventListener(\n\t\t\t\t\t'storage',\n\t\t\t\t\t(e) => {\n\t\t\t\t\t\tif (e.storageArea !== window[type]) return\n\n\t\t\t\t\t\tif (e.key !== key) return\n\n\t\t\t\t\t\tcb(e.newValue)\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tsignal: AbortSignal.any([\n\t\t\t\t\t\t\tabortController.signal,\n\t\t\t\t\t\t\tcontroller.signal,\n\t\t\t\t\t\t]),\n\t\t\t\t\t},\n\t\t\t\t)\n\n\t\t\t\treturn () => {\n\t\t\t\t\tcontroller.abort()\n\t\t\t\t}\n\t\t\t},\n\t\t}\n\t}\n}\n\nexport const memoryStorageAdapter: StorageAdapterCreator<{\n\tkey: string\n}> = ({ key }) => {\n\treturn ({ abortController }) => {\n\t\tconst storage = new Map<string, string>()\n\n\t\tconst channel = new BroadcastChannel(DEFAULT_KEY)\n\n\t\treturn {\n\t\t\tget: () => {\n\t\t\t\treturn storage.get(key) ?? null\n\t\t\t},\n\n\t\t\tset: (value) => {\n\t\t\t\tstorage.set(key, value)\n\t\t\t},\n\n\t\t\tbroadcast: (value) => {\n\t\t\t\tchannel.postMessage({ key, value })\n\t\t\t},\n\n\t\t\twatch: (cb) => {\n\t\t\t\tconst controller = new AbortController()\n\n\t\t\t\tchannel.addEventListener(\n\t\t\t\t\t'message',\n\t\t\t\t\t(e) => {\n\t\t\t\t\t\tif (e.data.key !== key) return\n\n\t\t\t\t\t\tcb(e.data.value)\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tsignal: AbortSignal.any([\n\t\t\t\t\t\t\tabortController.signal,\n\t\t\t\t\t\t\tcontroller.signal,\n\t\t\t\t\t\t]),\n\t\t\t\t\t},\n\t\t\t\t)\n\n\t\t\t\treturn () => {\n\t\t\t\t\tcontroller.abort()\n\t\t\t\t}\n\t\t\t},\n\t\t}\n\t}\n}\n"],"mappings":"AAAA,MAAaA,EAAc,WACdC,EAAmB,gBCkBnBe,GAGP,CAAEC,MAAKC,OAAO,mBACX,CAAEP,sBACF,CACNP,QACQe,OAAOD,EAAK,CAACE,QAAQH,CAAG,EAGhCZ,IAAMC,GAAU,CACfa,OAAOD,EAAK,CAACG,QAAQJ,EAAKX,CAAK,CAChC,EAEAE,MAAQC,GAAO,CACd,IAAMa,EAAa,IAAIV,gBAmBvB,OAjBAO,OAAOI,iBACN,UACCC,GAAM,CACFA,EAAEC,cAAgBN,OAAOD,IAEzBM,EAAEP,MAAQA,GAEdR,EAAGe,EAAEE,QAAQ,CACd,EACA,CACCC,OAAQC,YAAYC,IAAI,CACvBlB,EAAgBgB,OAChBL,EAAWK,MAAM,CACjB,CACF,CACD,MAEa,CACZL,EAAWQ,MAAM,CAClB,CACD,CACD,GAIWC,GAEP,CAAEd,UACC,CAAEN,qBAAsB,CAC/B,IAAMqB,EAAU,IAAIC,IAEdC,EAAU,IAAIC,iBAAiBjC,CAAW,EAEhD,MAAO,CACNE,QACQ4B,EAAQ5B,IAAIa,CAAG,GAAK,KAG5BZ,IAAMC,GAAU,CACf0B,EAAQ3B,IAAIY,EAAKX,CAAK,CACvB,EAEAC,UAAYD,GAAU,CACrB4B,EAAQE,YAAY,CAAEnB,MAAKX,OAAM,CAAC,CACnC,EAEAE,MAAQC,GAAO,CACd,IAAMa,EAAa,IAAIV,gBAiBvB,OAfAsB,EAAQX,iBACP,UACCC,GAAM,CACFA,EAAEa,KAAKpB,MAAQA,GAEnBR,EAAGe,EAAEa,KAAK/B,KAAK,CAChB,EACA,CACCqB,OAAQC,YAAYC,IAAI,CACvBlB,EAAgBgB,OAChBL,EAAWK,MAAM,CACjB,CACF,CACD,MAEa,CACZL,EAAWQ,MAAM,CAClB,CACD,CACD,CACD"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
//#region src/storage.d.ts
|
|
2
|
-
type StorageAdapter = {
|
|
3
|
-
get: () => string | null;
|
|
4
|
-
set: (value: string) => void;
|
|
5
|
-
broadcast?: (value: string) => void;
|
|
6
|
-
watch?: (cb: (value: string | null) => void) => () => void;
|
|
7
|
-
};
|
|
8
|
-
type StorageAdapterCreate = ({
|
|
9
|
-
abortController
|
|
10
|
-
}: {
|
|
11
|
-
abortController: AbortController;
|
|
12
|
-
}) => StorageAdapter;
|
|
13
|
-
type StorageAdapterCreator<Options> = (options: Options) => StorageAdapterCreate;
|
|
14
|
-
declare const localStorageAdapter: StorageAdapterCreator<{
|
|
15
|
-
key: string;
|
|
16
|
-
type?: 'localStorage' | 'sessionStorage';
|
|
17
|
-
}>;
|
|
18
|
-
declare const memoryStorageAdapter: StorageAdapterCreator<{
|
|
19
|
-
key: string;
|
|
20
|
-
}>;
|
|
21
|
-
//#endregion
|
|
22
|
-
export { memoryStorageAdapter as a, localStorageAdapter as i, StorageAdapterCreate as n, StorageAdapterCreator as r, StorageAdapter as t };
|
|
23
|
-
//# sourceMappingURL=storage-DGYV332J.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"storage-DGYV332J.d.ts","names":[],"sources":["../src/storage.ts"],"mappings":";KAEY,cAAA;EACX,GAAA;EACA,GAAA,GAAM,KAAA;EACN,SAAA,IAAa,KAAA;EACb,KAAA,IAAS,EAAA,GAAK,KAAA;AAAA;AAAA,KAGH,oBAAA;EACX;AAAA;EAEA,eAAA,EAAiB,eAAA;AAAA,MACZ,cAAA;AAAA,KAEM,qBAAA,aACX,OAAA,EAAS,OAAA,KACL,oBAAoB;AAAA,cAEZ,mBAAA,EAAqB,qBAAqB;EACtD,GAAA;EACA,IAAA;AAAA;AAAA,cAwCY,oBAAA,EAAsB,qBAAqB;EACvD,GAAG;AAAA"}
|