@snowztech/ui-js 0.2.0 → 0.2.1

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/index.cjs CHANGED
@@ -79,7 +79,9 @@ function getTheme(storageKey = DEFAULT_KEY) {
79
79
  if (stored === "light" || stored === "dark") return stored;
80
80
  } catch {
81
81
  }
82
- return document.documentElement.getAttribute("data-theme") === "light" ? "light" : "dark";
82
+ const attr = document.documentElement.getAttribute("data-theme");
83
+ if (attr === "system") return matchMedia("(prefers-color-scheme: light)").matches ? "light" : "dark";
84
+ return attr === "light" ? "light" : "dark";
83
85
  }
84
86
  function setTheme(theme, storageKey = DEFAULT_KEY) {
85
87
  if (theme === "light") document.documentElement.setAttribute("data-theme", "light");
package/dist/index.js CHANGED
@@ -46,7 +46,9 @@ function getTheme(storageKey = DEFAULT_KEY) {
46
46
  if (stored === "light" || stored === "dark") return stored;
47
47
  } catch {
48
48
  }
49
- return document.documentElement.getAttribute("data-theme") === "light" ? "light" : "dark";
49
+ const attr = document.documentElement.getAttribute("data-theme");
50
+ if (attr === "system") return matchMedia("(prefers-color-scheme: light)").matches ? "light" : "dark";
51
+ return attr === "light" ? "light" : "dark";
50
52
  }
51
53
  function setTheme(theme, storageKey = DEFAULT_KEY) {
52
54
  if (theme === "light") document.documentElement.setAttribute("data-theme", "light");
@@ -46,7 +46,9 @@ function getTheme(storageKey = DEFAULT_KEY) {
46
46
  if (stored === "light" || stored === "dark") return stored;
47
47
  } catch {
48
48
  }
49
- return document.documentElement.getAttribute("data-theme") === "light" ? "light" : "dark";
49
+ const attr = document.documentElement.getAttribute("data-theme");
50
+ if (attr === "system") return matchMedia("(prefers-color-scheme: light)").matches ? "light" : "dark";
51
+ return attr === "light" ? "light" : "dark";
50
52
  }
51
53
  function setTheme(theme, storageKey = DEFAULT_KEY) {
52
54
  if (theme === "light") document.documentElement.setAttribute("data-theme", "light");
@@ -72,7 +72,9 @@ var SnowztechUI = (() => {
72
72
  if (stored === "light" || stored === "dark") return stored;
73
73
  } catch {
74
74
  }
75
- return document.documentElement.getAttribute("data-theme") === "light" ? "light" : "dark";
75
+ const attr = document.documentElement.getAttribute("data-theme");
76
+ if (attr === "system") return matchMedia("(prefers-color-scheme: light)").matches ? "light" : "dark";
77
+ return attr === "light" ? "light" : "dark";
76
78
  }
77
79
  function setTheme(theme, storageKey = DEFAULT_KEY) {
78
80
  if (theme === "light") document.documentElement.setAttribute("data-theme", "light");
@@ -1 +1 @@
1
- "use strict";var SnowztechUI=(()=>{var r=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var s=Object.prototype.hasOwnProperty;var h=(t,e)=>{for(var n in e)r(t,n,{get:e[n],enumerable:!0})},p=(t,e,n,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of l(e))!s.call(t,o)&&o!==n&&r(t,o,{get:()=>e[o],enumerable:!(a=m(e,o))||a.enumerable});return t};var f=t=>p(r({},"__esModule",{value:!0}),t);var L={};h(L,{init:()=>d});async function g(t){try{return await navigator.clipboard.writeText(t),!0}catch{let e=document.createElement("textarea");e.value=t,e.style.position="fixed",e.style.opacity="0",document.body.appendChild(e),e.select();let n=!1;try{n=document.execCommand("copy")}catch{}return document.body.removeChild(e),n}}function T(){let t=this.getAttribute("data-sn-copy");t!==null&&g(t).then(e=>{e&&(this.setAttribute("data-copied","true"),window.setTimeout(()=>this.removeAttribute("data-copied"),1200))})}function y(t){t.dataset.snBound!=="copy"&&(t.dataset.snBound="copy",t.addEventListener("click",T))}function c(t=document){t.querySelectorAll("[data-sn-copy]").forEach(y)}var i="theme";function E(t=i){try{let e=localStorage.getItem(t);if(e==="light"||e==="dark")return e}catch{}return document.documentElement.getAttribute("data-theme")==="light"?"light":"dark"}function v(t,e=i){t==="light"?document.documentElement.setAttribute("data-theme","light"):document.documentElement.removeAttribute("data-theme");try{localStorage.setItem(e,t)}catch{}}function x(t=i){let e=E(t)==="dark"?"light":"dark";return v(e,t),e}function b(){let t=this.getAttribute("data-sn-storage-key")||i;x(t)}function k(t){t.dataset.snBound!=="theme"&&(t.dataset.snBound="theme",t.addEventListener("click",b))}function u(t=document){t.querySelectorAll("[data-sn-theme-toggle]").forEach(k)}function d(t=document){c(t),u(t)}typeof document<"u"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>d(),{once:!0}):d());return f(L);})();
1
+ "use strict";var SnowztechUI=(()=>{var r=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var h=(t,e)=>{for(var n in e)r(t,n,{get:e[n],enumerable:!0})},p=(t,e,n,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of s(e))!l.call(t,o)&&o!==n&&r(t,o,{get:()=>e[o],enumerable:!(a=m(e,o))||a.enumerable});return t};var f=t=>p(r({},"__esModule",{value:!0}),t);var L={};h(L,{init:()=>d});async function g(t){try{return await navigator.clipboard.writeText(t),!0}catch{let e=document.createElement("textarea");e.value=t,e.style.position="fixed",e.style.opacity="0",document.body.appendChild(e),e.select();let n=!1;try{n=document.execCommand("copy")}catch{}return document.body.removeChild(e),n}}function y(){let t=this.getAttribute("data-sn-copy");t!==null&&g(t).then(e=>{e&&(this.setAttribute("data-copied","true"),window.setTimeout(()=>this.removeAttribute("data-copied"),1200))})}function T(t){t.dataset.snBound!=="copy"&&(t.dataset.snBound="copy",t.addEventListener("click",y))}function c(t=document){t.querySelectorAll("[data-sn-copy]").forEach(T)}var i="theme";function E(t=i){try{let n=localStorage.getItem(t);if(n==="light"||n==="dark")return n}catch{}let e=document.documentElement.getAttribute("data-theme");return e==="system"?matchMedia("(prefers-color-scheme: light)").matches?"light":"dark":e==="light"?"light":"dark"}function v(t,e=i){t==="light"?document.documentElement.setAttribute("data-theme","light"):document.documentElement.removeAttribute("data-theme");try{localStorage.setItem(e,t)}catch{}}function x(t=i){let e=E(t)==="dark"?"light":"dark";return v(e,t),e}function b(){let t=this.getAttribute("data-sn-storage-key")||i;x(t)}function k(t){t.dataset.snBound!=="theme"&&(t.dataset.snBound="theme",t.addEventListener("click",b))}function u(t=document){t.querySelectorAll("[data-sn-theme-toggle]").forEach(k)}function d(t=document){c(t),u(t)}typeof document<"u"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>d(),{once:!0}):d());return f(L);})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowztech/ui-js",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Optional vanilla bindings for @snowztech/ui-css. Wires data-sn-* attributes for static HTML.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -10,7 +10,9 @@ export function getTheme(storageKey = DEFAULT_KEY): Theme {
10
10
  const stored = localStorage.getItem(storageKey) as Theme | null;
11
11
  if (stored === "light" || stored === "dark") return stored;
12
12
  } catch { /* ignore */ }
13
- return document.documentElement.getAttribute("data-theme") === "light" ? "light" : "dark";
13
+ const attr = document.documentElement.getAttribute("data-theme");
14
+ if (attr === "system") return matchMedia("(prefers-color-scheme: light)").matches ? "light" : "dark";
15
+ return attr === "light" ? "light" : "dark";
14
16
  }
15
17
 
16
18
  export function setTheme(theme: Theme, storageKey = DEFAULT_KEY): void {