darkify-js 1.1.7 → 1.1.8
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/darkify.esm.js +1 -1
- package/dist/darkify.min.js +1 -1
- package/dist/darkify.umd.js +1 -1
- package/package.json +1 -1
package/dist/darkify.esm.js
CHANGED
package/dist/darkify.min.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
*
|
|
3
3
|
* @author Emilio Romero <emrocode@gmail.com>
|
|
4
|
-
* @version 1.1.
|
|
4
|
+
* @version 1.1.8
|
|
5
5
|
* @license MIT
|
|
6
6
|
*/
|
|
7
7
|
var Darkify=function(){"use strict";const e="undefined"!=typeof window,t={autoMatchTheme:!0,useLocalStorage:!0,useSessionStorage:!1,useColorScheme:["#ffffff","#000000"]};class s{constructor(s,o){this.options={},this.theme="light",e&&((null==o?void 0:o.useLocalStorage)&&(o.useSessionStorage=!1),(null==o?void 0:o.useSessionStorage)&&(o.useLocalStorage=!1),o=Object.assign(Object.assign({},t),o),this.options=o,this.init(s),this.theme=this.getOsPreference(o),this._style=document.createElement("style"),this._meta=document.createElement("meta"),this.createAttribute(),this.syncThemeBetweenTabs())}init(e){window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",({matches:e})=>{this.theme=e?"dark":"light",this.savePreference()}),document.addEventListener("DOMContentLoaded",()=>{const t=document.querySelector(e);null==t||t.addEventListener("click",()=>this.toggleTheme())})}getOsPreference(e){const{autoMatchTheme:t,useLocalStorage:o,useSessionStorage:a}=e;return o&&window.localStorage.getItem(s.storageKey)||a&&window.sessionStorage.getItem(s.storageKey)||(t&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light")}createAttribute(){const e=document.getElementsByTagName("html")[0],{useColorScheme:t}=this.options;let s=`/**! Darkify / A simple dark mode toggle library **/\n:root:is([data-theme="${this.theme}"]),[data-theme="${this.theme}"]{color-scheme:${this.theme}}`;e.setAttribute("data-theme",this.theme),this.updateTags(s,null!=t?t:[]),this.savePreference()}updateTags(e,t){const s=document.head||document.getElementsByTagName("head")[0];this._meta.setAttribute("name","theme-color"),this._meta.setAttribute("content","light"===this.theme?t[0]:t[1]),this._style.setAttribute("type","text/css"),this._style.innerHTML=e,s.appendChild(this._meta),s.appendChild(this._style)}savePreference(){const{useLocalStorage:e}=this.options,t=e?window.localStorage:window.sessionStorage;(e?window.sessionStorage:window.localStorage).removeItem(s.storageKey),t.setItem(s.storageKey,this.theme)}syncThemeBetweenTabs(){window.addEventListener("storage",e=>{e.key===s.storageKey&&e.newValue&&(this.theme=e.newValue,this.createAttribute())})}toggleTheme(){this.theme="light"===this.theme?"dark":"light",this.createAttribute()}getCurrentTheme(){return this.theme}}return s.storageKey="theme",s}();
|
package/dist/darkify.umd.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
*
|
|
3
3
|
* @author Emilio Romero <emrocode@gmail.com>
|
|
4
|
-
* @version 1.1.
|
|
4
|
+
* @version 1.1.8
|
|
5
5
|
* @license MIT
|
|
6
6
|
*/
|
|
7
7
|
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).Darkify=t()}(this,function(){"use strict";const e="undefined"!=typeof window,t={autoMatchTheme:!0,useLocalStorage:!0,useSessionStorage:!1,useColorScheme:["#ffffff","#000000"]};class s{constructor(s,o){this.options={},this.theme="light",e&&((null==o?void 0:o.useLocalStorage)&&(o.useSessionStorage=!1),(null==o?void 0:o.useSessionStorage)&&(o.useLocalStorage=!1),o=Object.assign(Object.assign({},t),o),this.options=o,this.init(s),this.theme=this.getOsPreference(o),this._style=document.createElement("style"),this._meta=document.createElement("meta"),this.createAttribute(),this.syncThemeBetweenTabs())}init(e){window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",({matches:e})=>{this.theme=e?"dark":"light",this.savePreference()}),document.addEventListener("DOMContentLoaded",()=>{const t=document.querySelector(e);null==t||t.addEventListener("click",()=>this.toggleTheme())})}getOsPreference(e){const{autoMatchTheme:t,useLocalStorage:o,useSessionStorage:i}=e;return o&&window.localStorage.getItem(s.storageKey)||i&&window.sessionStorage.getItem(s.storageKey)||(t&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light")}createAttribute(){const e=document.getElementsByTagName("html")[0],{useColorScheme:t}=this.options;let s=`/**! Darkify / A simple dark mode toggle library **/\n:root:is([data-theme="${this.theme}"]),[data-theme="${this.theme}"]{color-scheme:${this.theme}}`;e.setAttribute("data-theme",this.theme),this.updateTags(s,null!=t?t:[]),this.savePreference()}updateTags(e,t){const s=document.head||document.getElementsByTagName("head")[0];this._meta.setAttribute("name","theme-color"),this._meta.setAttribute("content","light"===this.theme?t[0]:t[1]),this._style.setAttribute("type","text/css"),this._style.innerHTML=e,s.appendChild(this._meta),s.appendChild(this._style)}savePreference(){const{useLocalStorage:e}=this.options,t=e?window.localStorage:window.sessionStorage;(e?window.sessionStorage:window.localStorage).removeItem(s.storageKey),t.setItem(s.storageKey,this.theme)}syncThemeBetweenTabs(){window.addEventListener("storage",e=>{e.key===s.storageKey&&e.newValue&&(this.theme=e.newValue,this.createAttribute())})}toggleTheme(){this.theme="light"===this.theme?"dark":"light",this.createAttribute()}getCurrentTheme(){return this.theme}}return s.storageKey="theme",s});
|