resonare 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/inline-script.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const resonareInlineScript = "
|
|
1
|
+
export const resonareInlineScript = "/**\n\t* resonare v0.0.9\n\t*\n\t* This source code is licensed under the MIT license found in the\n\t* LICENSE file in the root directory of this source tree.\n*/\nvar resonare=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=`resonare`;let n=({storageType:e=`localStorage`}={})=>({abortController:t})=>({getItem:t=>JSON.parse(window[e].getItem(t)||`null`),setItem:(t,n)=>{window[e].setItem(t,JSON.stringify(n))},watch:n=>{let r=new AbortController;return window.addEventListener(`storage`,t=>{t.storageArea===window[e]&&n(t.key,JSON.parse(t.newValue))},{signal:AbortSignal.any([t.signal,r.signal])}),()=>{r.abort()}}}),r=()=>({abortController:e})=>{let n=new Map,r=new BroadcastChannel(t);return{getItem:e=>n.get(e)||null,setItem:(e,t)=>{n.set(e,t)},broadcast:(e,t)=>{r.postMessage({key:e,value:t})},watch:t=>{let n=new AbortController;return r.addEventListener(`message`,e=>{t(e.data.key,e.data.value)},{signal:AbortSignal.any([e.signal,n.signal])}),()=>{n.abort()}}}};function i(e){return Object.entries(e).map(([e,t])=>[e,`options`in t?t.options.map(e=>typeof e==`string`?e:e.value):[]])}function a(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t.initialValue??(typeof t.options[0]==`object`?t.options[0].value:t.options[0])]))}let o=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0;var s=class{#e;#t;#n;#r;#i;#a=new Set;#o;#s=new AbortController;constructor({key:e=t,config:r,initialState:i={},storage:o=n()}){let s={},c={...i.systemOptions};Object.entries(r).forEach(([e,t])=>{s[e]={},`options`in t&&t.options.forEach(t=>{typeof t==`object`?(t.media&&!Object.hasOwn(c,e)&&(c[e]=[t.media[1],t.media[2]]),s[e][String(t.value)]=t):s[e][String(t)]={value:t}})}),this.#n={key:e,config:s,storage:o},this.#r=c,this.#e=a(r),this.#t={...this.#e,...i.themes},this.#i=this.#n.storage({abortController:this.#s}),this.#o={}}getThemes=()=>this.#t;getResolvedThemes=()=>this.#l();setThemes=async e=>{let t=typeof e==`function`?e(this.#t):e;this.#c({...this.#t,...t});let n=this.getStateToPersist();await this.#i.setItem(this.#n.key,n),this.#i.broadcast?.(this.#n.key,n)};updateSystemOption=(e,[t,n])=>{this.#r[e]=[t,n],this.setThemes({...this.#t})};getStateToPersist=()=>({version:1,themes:this.#t,systemOptions:this.#r});restore=async()=>{let e=await this.#i.getItem(this.#n.key);if(!e){this.#c({...this.#e});return}Object.hasOwn(e,`version`)||(e={version:1,themes:e,systemOptions:this.#r}),this.#r={...this.#r,...e.systemOptions},this.#c({...this.#e,...e.themes})};subscribe=(e,{immediate:t=!1}={})=>(t&&e({themes:this.#t,resolvedThemes:this.#l()}),this.#a.add(e),()=>{this.#a.delete(e)});sync=()=>{if(!this.#i.watch){console.warn(`[${t}] No watch method was provided for storage.`);return}return this.#i.watch((e,t)=>{e===this.#n.key&&(this.#r=t.systemOptions,this.#c(t.themes))})};___destroy=()=>{this.#a.clear(),this.#s.abort()};#c=e=>{this.#t=e,this.#d()};#l=()=>Object.fromEntries(Object.entries(this.#t).map(([e,t])=>{let n=this.#n.config[e]?.[t];return[e,n?this.#u({themeKey:e,option:n}):t]}));#u=({themeKey:e,option:n})=>{if(!n.media)return n.value;if(!o)return console.warn(`[${t}] Option with key \"media\" cannot be resolved in server environment.`),n.value;let[r]=n.media;if(!this.#o[r]){let t=window.matchMedia(r);this.#o[r]=t,t.addEventListener(`change`,()=>{this.#t[e]===n.value&&this.#c({...this.#t})},{signal:this.#s.signal})}let[i,a]=this.#r[e];return this.#o[r].matches?i:a};#d=()=>{for(let e of this.#a)e({themes:this.#t,resolvedThemes:this.#l()})}};let c=new class{#e=new Map;create=e=>{let n=e.key||t,r=this.#e.get(n);return r||(r=new s(e),this.#e.set(n,r)),r};get=e=>{let n=e||t;if(!this.#e.has(n))throw Error(`[${t}] Theme store with key '${n}' could not be found. Please run \\`createThemeStore\\` with key '${n}' first.`);return this.#e.get(n)};destroy=e=>{let n=e||t;this.#e.has(n)&&(this.#e.get(n).___destroy(),this.#e.delete(n))}},l=c.create,u=c.get,d=c.destroy;return e.createThemeStore=l,e.destroyThemeStore=d,e.getDefaultThemes=a,e.getThemeStore=u,e.getThemesAndOptions=i,e.localStorageAdapter=n,e.memoryStorageAdapter=r,e})({});"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "resonare",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "Resonare",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"theming"
|
|
@@ -22,9 +22,6 @@
|
|
|
22
22
|
"./inline-script": {
|
|
23
23
|
"import": "./dist/inline-script.ts"
|
|
24
24
|
},
|
|
25
|
-
"./raw": {
|
|
26
|
-
"import": "./dist/resonare.iife.min.js"
|
|
27
|
-
},
|
|
28
25
|
"./react": {
|
|
29
26
|
"types": "./dist/react.d.ts",
|
|
30
27
|
"import": "./dist/react.js"
|