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,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a store saves its state. Values are strings: the full store saves
|
|
3
|
+
* JSON, the lite store saves the theme name.
|
|
4
|
+
*/
|
|
5
|
+
type StorageAdapter = {
|
|
6
|
+
/** Returns the saved value, or `null` when nothing is saved. */
|
|
7
|
+
get: () => string | null;
|
|
8
|
+
/** Saves a value. */
|
|
9
|
+
set: (value: string) => void;
|
|
10
|
+
/** Optional: tells other tabs about a value just saved with `set`. */
|
|
11
|
+
broadcast?: (value: string) => void;
|
|
12
|
+
/**
|
|
13
|
+
* Optional: calls `cb` when another tab saves a value (`null` when it clears
|
|
14
|
+
* it). Returns a function that stops watching. Used by `store.sync()`.
|
|
15
|
+
*/
|
|
16
|
+
watch?: (cb: (value: string | null) => void) => () => void;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* What a store's `storage` option takes: a function that creates the adapter.
|
|
20
|
+
* `abortController` is aborted when the store is destroyed; use it to remove
|
|
21
|
+
* listeners.
|
|
22
|
+
*/
|
|
23
|
+
type StorageAdapterCreate = ({ abortController }: {
|
|
24
|
+
abortController: AbortController;
|
|
25
|
+
}) => StorageAdapter;
|
|
26
|
+
/**
|
|
27
|
+
* Shape of the built-in adapters such as `localStorageAdapter`: takes options
|
|
28
|
+
* (like the key) and returns a {@link StorageAdapterCreate}.
|
|
29
|
+
*/
|
|
30
|
+
type StorageAdapterCreator<Options> = (options: Options) => StorageAdapterCreate;
|
|
31
|
+
/**
|
|
32
|
+
* Saves the store in `localStorage` (default) or `sessionStorage` under `key`,
|
|
33
|
+
* and supports `store.sync()` across tabs. If storage is blocked or full,
|
|
34
|
+
* reads return nothing and writes are skipped.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* import { createThemeStore, localStorageAdapter } from 'resonare'
|
|
38
|
+
*
|
|
39
|
+
* const store = createThemeStore(
|
|
40
|
+
* { colorMode: { options: ['light', 'dark'] } },
|
|
41
|
+
* { storage: localStorageAdapter({ key: 'app', type: 'localStorage' }) }
|
|
42
|
+
* )
|
|
43
|
+
*/
|
|
44
|
+
declare const localStorageAdapter: StorageAdapterCreator<{
|
|
45
|
+
key: string;
|
|
46
|
+
type?: 'localStorage' | 'sessionStorage';
|
|
47
|
+
}>;
|
|
48
|
+
/**
|
|
49
|
+
* Keeps the store in memory only, and supports `store.sync()` across tabs
|
|
50
|
+
* through `BroadcastChannel`. Use it when you save the state yourself (e.g.
|
|
51
|
+
* `toPersist()` to a database) and don't want it in `localStorage`.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* import { createThemeStore, memoryStorageAdapter } from 'resonare'
|
|
55
|
+
*
|
|
56
|
+
* const store = createThemeStore(
|
|
57
|
+
* { colorMode: { options: ['light', 'dark'] } },
|
|
58
|
+
* { storage: memoryStorageAdapter({ key: 'app' }) }
|
|
59
|
+
* )
|
|
60
|
+
*/
|
|
61
|
+
declare const memoryStorageAdapter: StorageAdapterCreator<{
|
|
62
|
+
key: string;
|
|
63
|
+
}>;
|
|
64
|
+
export { memoryStorageAdapter as a, localStorageAdapter as i, StorageAdapterCreate as n, StorageAdapterCreator as r, StorageAdapter as t };
|
|
65
|
+
//# sourceMappingURL=storage-CsXjZKyt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-CsXjZKyt.d.ts","names":[],"sources":["../src/storage.ts"],"mappings":";;;;KAMY;;EAEV;;EAEA,MAAM;;EAEN,aAAa;;;;;EAKb,SAAS,KAAK;;;;;;;KAQJ,0BACV;EAEA,iBAAiB;MACb;;;;;KAMM,sBAAsB,YAChC,SAAS,YACN;;;;;;;;;;;;;;cAeQ,qBAAqB;EAChC;EACA;;;;;;;;;;;;;;;cAoDW,sBAAsB;EACjC"}
|
package/dist/svelte.d.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
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
|
+
}) => void) => () => void;
|
|
59
|
+
sync: () => (() => void) | undefined;
|
|
60
|
+
toPersist: () => {
|
|
61
|
+
themes: Partial<Themes<T>>;
|
|
62
|
+
systemOptions: {
|
|
63
|
+
[x: string]: [string, string];
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
updateSystemOption: <K extends { [K in keyof T]: T[K] extends {
|
|
67
|
+
options: ReadonlyArray<infer U>;
|
|
68
|
+
} ? U extends {
|
|
69
|
+
media: ReadonlyArray<unknown>;
|
|
70
|
+
} ? K : never : never; }[keyof T]>(themeKey: K, pair: [T[K] extends {
|
|
71
|
+
options: ReadonlyArray<infer U>;
|
|
72
|
+
} ? U extends string | number | boolean ? U : U extends {
|
|
73
|
+
value: string;
|
|
74
|
+
media?: readonly [string, string, string] | undefined;
|
|
75
|
+
} ? U extends {
|
|
76
|
+
media: ReadonlyArray<unknown>;
|
|
77
|
+
} ? never : U["value"] : never : never, T[K] extends {
|
|
78
|
+
options: ReadonlyArray<infer U>;
|
|
79
|
+
} ? U extends string | number | boolean ? U : U extends {
|
|
80
|
+
value: string;
|
|
81
|
+
media?: readonly [string, string, string] | undefined;
|
|
82
|
+
} ? U extends {
|
|
83
|
+
media: ReadonlyArray<unknown>;
|
|
84
|
+
} ? never : U["value"] : never : never]) => void;
|
|
85
|
+
};
|
|
86
|
+
//# 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"}
|
package/dist/vue.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
}) => void) => () => void;
|
|
54
|
+
sync: () => (() => void) | undefined;
|
|
55
|
+
toPersist: () => {
|
|
56
|
+
themes: Partial<Themes<T>>;
|
|
57
|
+
systemOptions: {
|
|
58
|
+
[x: string]: [string, string];
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
updateSystemOption: <K extends { [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]>(themeKey: K, pair: [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, T[K] extends {
|
|
73
|
+
options: ReadonlyArray<infer U>;
|
|
74
|
+
} ? U extends string | number | boolean ? U : U extends {
|
|
75
|
+
value: string;
|
|
76
|
+
media?: readonly [string, string, string] | undefined;
|
|
77
|
+
} ? U extends {
|
|
78
|
+
media: ReadonlyArray<unknown>;
|
|
79
|
+
} ? never : U["value"] : never : never]) => void;
|
|
80
|
+
};
|
|
81
|
+
export {};
|
|
82
|
+
//# 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.3.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",
|
|
@@ -24,47 +28,86 @@
|
|
|
24
28
|
"./react": {
|
|
25
29
|
"types": "./dist/react.d.ts",
|
|
26
30
|
"import": "./dist/react.js"
|
|
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
|
+
"./lite": {
|
|
45
|
+
"types": "./dist/lite.d.ts",
|
|
46
|
+
"import": "./dist/lite.js"
|
|
47
|
+
},
|
|
48
|
+
"./lite/react": {
|
|
49
|
+
"types": "./dist/lite-react.d.ts",
|
|
50
|
+
"import": "./dist/lite-react.js"
|
|
51
|
+
},
|
|
52
|
+
"./lite/solid": {
|
|
53
|
+
"types": "./dist/lite-solid.d.ts",
|
|
54
|
+
"import": "./dist/lite-solid.js"
|
|
55
|
+
},
|
|
56
|
+
"./lite/svelte": {
|
|
57
|
+
"types": "./dist/lite-svelte.d.ts",
|
|
58
|
+
"import": "./dist/lite-svelte.js"
|
|
59
|
+
},
|
|
60
|
+
"./lite/vue": {
|
|
61
|
+
"types": "./dist/lite-vue.d.ts",
|
|
62
|
+
"import": "./dist/lite-vue.js"
|
|
27
63
|
}
|
|
28
64
|
},
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
"dist"
|
|
32
|
-
],
|
|
33
|
-
"dependencies": {
|
|
34
|
-
"react-compiler-runtime": "1.0.0"
|
|
65
|
+
"publishConfig": {
|
|
66
|
+
"access": "public"
|
|
35
67
|
},
|
|
36
68
|
"devDependencies": {
|
|
37
|
-
"@
|
|
38
|
-
"@
|
|
39
|
-
"@types/
|
|
40
|
-
"@types/react": "19.
|
|
41
|
-
"@vitejs/plugin-react": "6.
|
|
42
|
-
"babel-plugin-react-compiler": "1.0.0",
|
|
69
|
+
"@size-limit/preset-small-lib": "14.3.0",
|
|
70
|
+
"@types/node": "26.6.6",
|
|
71
|
+
"@types/react": "19.3.0",
|
|
72
|
+
"@types/react-dom": "19.3.0",
|
|
73
|
+
"@vitejs/plugin-react": "6.1.2",
|
|
43
74
|
"cross-env": "10.1.0",
|
|
44
|
-
"jsdom": "
|
|
45
|
-
"react": "
|
|
46
|
-
"react
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
75
|
+
"jsdom": "30.1.3",
|
|
76
|
+
"oxc-transform-react": "0.156.0",
|
|
77
|
+
"react": "19.3.1",
|
|
78
|
+
"react-dom": "19.3.1",
|
|
79
|
+
"size-limit": "14.3.0",
|
|
80
|
+
"solid-js": "1.9.18",
|
|
81
|
+
"svelte": "5.57.3",
|
|
82
|
+
"typescript": "7.0.2",
|
|
83
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@1.4.0",
|
|
84
|
+
"vite-plus": "1.4.0",
|
|
85
|
+
"vue": "3.5.44"
|
|
52
86
|
},
|
|
53
87
|
"peerDependencies": {
|
|
54
|
-
"react": "^
|
|
88
|
+
"react": "^19.0.0",
|
|
89
|
+
"solid-js": "^1.6.0",
|
|
90
|
+
"svelte": "^5.7.0",
|
|
91
|
+
"vue": "^3.2.0"
|
|
55
92
|
},
|
|
56
93
|
"peerDependenciesMeta": {
|
|
57
94
|
"react": {
|
|
58
95
|
"optional": true
|
|
96
|
+
},
|
|
97
|
+
"solid-js": {
|
|
98
|
+
"optional": true
|
|
99
|
+
},
|
|
100
|
+
"svelte": {
|
|
101
|
+
"optional": true
|
|
102
|
+
},
|
|
103
|
+
"vue": {
|
|
104
|
+
"optional": true
|
|
59
105
|
}
|
|
60
106
|
},
|
|
61
|
-
"publishConfig": {
|
|
62
|
-
"access": "public"
|
|
63
|
-
},
|
|
64
107
|
"scripts": {
|
|
65
|
-
"build": "
|
|
66
|
-
"dev": "
|
|
108
|
+
"build": "vp pack",
|
|
109
|
+
"dev": "vp pack --watch",
|
|
67
110
|
"size": "pnpm build && size-limit",
|
|
68
|
-
"test": "
|
|
111
|
+
"test": "vp test"
|
|
69
112
|
}
|
|
70
113
|
}
|