@snowztech/ui-js 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Lucas Neves Pereira
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # @snowztech/ui-js
2
+
3
+ Optional vanilla bindings for [@snowztech/ui-css](https://www.npmjs.com/package/@snowztech/ui-css). Wires `data-sn-*` attributes so static HTML pages get interactive components without React.
4
+
5
+ If you're using `@snowztech/ui` (React), you don't need this package.
6
+
7
+ ## CDN (auto-wires on load)
8
+
9
+ ```html
10
+ <link rel="stylesheet"
11
+ href="https://cdn.jsdelivr.net/npm/@snowztech/ui-css@0.2/dist/snowztech-ui.min.css">
12
+ <script type="module"
13
+ src="https://cdn.jsdelivr.net/npm/@snowztech/ui-js@0.2/dist/snowztech-ui.esm.js"></script>
14
+
15
+ <button class="sn-copy-btn" data-sn-copy="hello@snowz.ai" aria-label="copy email">
16
+ <svg class="sn-copy-btn__idle" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
17
+ <rect x="9" y="9" width="11" height="11" rx="1.5"/><path d="M5 15V5a1 1 0 0 1 1-1h10"/>
18
+ </svg>
19
+ <svg class="sn-copy-btn__copied" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
20
+ <path d="m4 12 5 5L20 6"/>
21
+ </svg>
22
+ </button>
23
+
24
+ <button class="sn-theme-toggle" data-sn-theme-toggle aria-label="toggle theme">
25
+ <span class="sn-theme-toggle__indicator"></span>
26
+ </button>
27
+ ```
28
+
29
+ ## npm
30
+
31
+ ```bash
32
+ npm i @snowztech/ui-js
33
+ ```
34
+
35
+ ```ts
36
+ // Side-effect import: wires every [data-sn-*] on DOMContentLoaded.
37
+ import "@snowztech/ui-js/auto";
38
+
39
+ // Or explicit:
40
+ import { init, toggleTheme } from "@snowztech/ui-js";
41
+ init();
42
+ ```
43
+
44
+ ## Attributes
45
+
46
+ | Attribute | Behavior |
47
+ |---------------------------------|---------------------------------------------------------|
48
+ | `data-sn-copy="<text>"` | Copies text to clipboard, sets `data-copied="true"` for 1.2s |
49
+ | `data-sn-theme-toggle` | Toggles `[data-theme="light"]` on `<html>`, persists to localStorage |
50
+ | `data-sn-storage-key="<key>"` | Override the localStorage key used by the theme toggle |
51
+
52
+ ## API
53
+
54
+ ```ts
55
+ init(root?: ParentNode): void
56
+ bindCopyButton(el: HTMLElement): void
57
+ bindThemeToggle(el: HTMLElement): void
58
+ getTheme(key?: string): "light" | "dark"
59
+ setTheme(theme: "light" | "dark", key?: string): void
60
+ toggleTheme(key?: string): "light" | "dark"
61
+ ```
package/dist/index.cjs ADDED
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ bindCopyButton: () => bindCopyButton,
24
+ bindThemeToggle: () => bindThemeToggle,
25
+ getTheme: () => getTheme,
26
+ init: () => init,
27
+ initCopyButtons: () => initCopyButtons,
28
+ initThemeToggles: () => initThemeToggles,
29
+ setTheme: () => setTheme,
30
+ toggleTheme: () => toggleTheme
31
+ });
32
+ module.exports = __toCommonJS(index_exports);
33
+
34
+ // src/copy-button.ts
35
+ var RESET_MS = 1200;
36
+ async function copyValue(value) {
37
+ try {
38
+ await navigator.clipboard.writeText(value);
39
+ return true;
40
+ } catch {
41
+ const ta = document.createElement("textarea");
42
+ ta.value = value;
43
+ ta.style.position = "fixed";
44
+ ta.style.opacity = "0";
45
+ document.body.appendChild(ta);
46
+ ta.select();
47
+ let ok = false;
48
+ try {
49
+ ok = document.execCommand("copy");
50
+ } catch {
51
+ }
52
+ document.body.removeChild(ta);
53
+ return ok;
54
+ }
55
+ }
56
+ function onClick() {
57
+ const value = this.getAttribute("data-sn-copy");
58
+ if (value === null) return;
59
+ void copyValue(value).then((ok) => {
60
+ if (!ok) return;
61
+ this.setAttribute("data-copied", "true");
62
+ window.setTimeout(() => this.removeAttribute("data-copied"), RESET_MS);
63
+ });
64
+ }
65
+ function bindCopyButton(el) {
66
+ if (el.dataset.snBound === "copy") return;
67
+ el.dataset.snBound = "copy";
68
+ el.addEventListener("click", onClick);
69
+ }
70
+ function initCopyButtons(root = document) {
71
+ root.querySelectorAll("[data-sn-copy]").forEach(bindCopyButton);
72
+ }
73
+
74
+ // src/theme-toggle.ts
75
+ var DEFAULT_KEY = "theme";
76
+ function getTheme(storageKey = DEFAULT_KEY) {
77
+ try {
78
+ const stored = localStorage.getItem(storageKey);
79
+ if (stored === "light" || stored === "dark") return stored;
80
+ } catch {
81
+ }
82
+ return document.documentElement.getAttribute("data-theme") === "light" ? "light" : "dark";
83
+ }
84
+ function setTheme(theme, storageKey = DEFAULT_KEY) {
85
+ if (theme === "light") document.documentElement.setAttribute("data-theme", "light");
86
+ else document.documentElement.removeAttribute("data-theme");
87
+ try {
88
+ localStorage.setItem(storageKey, theme);
89
+ } catch {
90
+ }
91
+ }
92
+ function toggleTheme(storageKey = DEFAULT_KEY) {
93
+ const next = getTheme(storageKey) === "dark" ? "light" : "dark";
94
+ setTheme(next, storageKey);
95
+ return next;
96
+ }
97
+ function onClick2() {
98
+ const key = this.getAttribute("data-sn-storage-key") || DEFAULT_KEY;
99
+ toggleTheme(key);
100
+ }
101
+ function bindThemeToggle(el) {
102
+ if (el.dataset.snBound === "theme") return;
103
+ el.dataset.snBound = "theme";
104
+ el.addEventListener("click", onClick2);
105
+ }
106
+ function initThemeToggles(root = document) {
107
+ root.querySelectorAll("[data-sn-theme-toggle]").forEach(bindThemeToggle);
108
+ }
109
+
110
+ // src/auto.ts
111
+ function init(root = document) {
112
+ initCopyButtons(root);
113
+ initThemeToggles(root);
114
+ }
115
+ if (typeof document !== "undefined") {
116
+ if (document.readyState === "loading") {
117
+ document.addEventListener("DOMContentLoaded", () => init(), { once: true });
118
+ } else {
119
+ init();
120
+ }
121
+ }
package/dist/index.js ADDED
@@ -0,0 +1,98 @@
1
+ // src/copy-button.ts
2
+ var RESET_MS = 1200;
3
+ async function copyValue(value) {
4
+ try {
5
+ await navigator.clipboard.writeText(value);
6
+ return true;
7
+ } catch {
8
+ const ta = document.createElement("textarea");
9
+ ta.value = value;
10
+ ta.style.position = "fixed";
11
+ ta.style.opacity = "0";
12
+ document.body.appendChild(ta);
13
+ ta.select();
14
+ let ok = false;
15
+ try {
16
+ ok = document.execCommand("copy");
17
+ } catch {
18
+ }
19
+ document.body.removeChild(ta);
20
+ return ok;
21
+ }
22
+ }
23
+ function onClick() {
24
+ const value = this.getAttribute("data-sn-copy");
25
+ if (value === null) return;
26
+ void copyValue(value).then((ok) => {
27
+ if (!ok) return;
28
+ this.setAttribute("data-copied", "true");
29
+ window.setTimeout(() => this.removeAttribute("data-copied"), RESET_MS);
30
+ });
31
+ }
32
+ function bindCopyButton(el) {
33
+ if (el.dataset.snBound === "copy") return;
34
+ el.dataset.snBound = "copy";
35
+ el.addEventListener("click", onClick);
36
+ }
37
+ function initCopyButtons(root = document) {
38
+ root.querySelectorAll("[data-sn-copy]").forEach(bindCopyButton);
39
+ }
40
+
41
+ // src/theme-toggle.ts
42
+ var DEFAULT_KEY = "theme";
43
+ function getTheme(storageKey = DEFAULT_KEY) {
44
+ try {
45
+ const stored = localStorage.getItem(storageKey);
46
+ if (stored === "light" || stored === "dark") return stored;
47
+ } catch {
48
+ }
49
+ return document.documentElement.getAttribute("data-theme") === "light" ? "light" : "dark";
50
+ }
51
+ function setTheme(theme, storageKey = DEFAULT_KEY) {
52
+ if (theme === "light") document.documentElement.setAttribute("data-theme", "light");
53
+ else document.documentElement.removeAttribute("data-theme");
54
+ try {
55
+ localStorage.setItem(storageKey, theme);
56
+ } catch {
57
+ }
58
+ }
59
+ function toggleTheme(storageKey = DEFAULT_KEY) {
60
+ const next = getTheme(storageKey) === "dark" ? "light" : "dark";
61
+ setTheme(next, storageKey);
62
+ return next;
63
+ }
64
+ function onClick2() {
65
+ const key = this.getAttribute("data-sn-storage-key") || DEFAULT_KEY;
66
+ toggleTheme(key);
67
+ }
68
+ function bindThemeToggle(el) {
69
+ if (el.dataset.snBound === "theme") return;
70
+ el.dataset.snBound = "theme";
71
+ el.addEventListener("click", onClick2);
72
+ }
73
+ function initThemeToggles(root = document) {
74
+ root.querySelectorAll("[data-sn-theme-toggle]").forEach(bindThemeToggle);
75
+ }
76
+
77
+ // src/auto.ts
78
+ function init(root = document) {
79
+ initCopyButtons(root);
80
+ initThemeToggles(root);
81
+ }
82
+ if (typeof document !== "undefined") {
83
+ if (document.readyState === "loading") {
84
+ document.addEventListener("DOMContentLoaded", () => init(), { once: true });
85
+ } else {
86
+ init();
87
+ }
88
+ }
89
+ export {
90
+ bindCopyButton,
91
+ bindThemeToggle,
92
+ getTheme,
93
+ init,
94
+ initCopyButtons,
95
+ initThemeToggles,
96
+ setTheme,
97
+ toggleTheme
98
+ };
@@ -0,0 +1,91 @@
1
+ // src/copy-button.ts
2
+ var RESET_MS = 1200;
3
+ async function copyValue(value) {
4
+ try {
5
+ await navigator.clipboard.writeText(value);
6
+ return true;
7
+ } catch {
8
+ const ta = document.createElement("textarea");
9
+ ta.value = value;
10
+ ta.style.position = "fixed";
11
+ ta.style.opacity = "0";
12
+ document.body.appendChild(ta);
13
+ ta.select();
14
+ let ok = false;
15
+ try {
16
+ ok = document.execCommand("copy");
17
+ } catch {
18
+ }
19
+ document.body.removeChild(ta);
20
+ return ok;
21
+ }
22
+ }
23
+ function onClick() {
24
+ const value = this.getAttribute("data-sn-copy");
25
+ if (value === null) return;
26
+ void copyValue(value).then((ok) => {
27
+ if (!ok) return;
28
+ this.setAttribute("data-copied", "true");
29
+ window.setTimeout(() => this.removeAttribute("data-copied"), RESET_MS);
30
+ });
31
+ }
32
+ function bindCopyButton(el) {
33
+ if (el.dataset.snBound === "copy") return;
34
+ el.dataset.snBound = "copy";
35
+ el.addEventListener("click", onClick);
36
+ }
37
+ function initCopyButtons(root = document) {
38
+ root.querySelectorAll("[data-sn-copy]").forEach(bindCopyButton);
39
+ }
40
+
41
+ // src/theme-toggle.ts
42
+ var DEFAULT_KEY = "theme";
43
+ function getTheme(storageKey = DEFAULT_KEY) {
44
+ try {
45
+ const stored = localStorage.getItem(storageKey);
46
+ if (stored === "light" || stored === "dark") return stored;
47
+ } catch {
48
+ }
49
+ return document.documentElement.getAttribute("data-theme") === "light" ? "light" : "dark";
50
+ }
51
+ function setTheme(theme, storageKey = DEFAULT_KEY) {
52
+ if (theme === "light") document.documentElement.setAttribute("data-theme", "light");
53
+ else document.documentElement.removeAttribute("data-theme");
54
+ try {
55
+ localStorage.setItem(storageKey, theme);
56
+ } catch {
57
+ }
58
+ }
59
+ function toggleTheme(storageKey = DEFAULT_KEY) {
60
+ const next = getTheme(storageKey) === "dark" ? "light" : "dark";
61
+ setTheme(next, storageKey);
62
+ return next;
63
+ }
64
+ function onClick2() {
65
+ const key = this.getAttribute("data-sn-storage-key") || DEFAULT_KEY;
66
+ toggleTheme(key);
67
+ }
68
+ function bindThemeToggle(el) {
69
+ if (el.dataset.snBound === "theme") return;
70
+ el.dataset.snBound = "theme";
71
+ el.addEventListener("click", onClick2);
72
+ }
73
+ function initThemeToggles(root = document) {
74
+ root.querySelectorAll("[data-sn-theme-toggle]").forEach(bindThemeToggle);
75
+ }
76
+
77
+ // src/auto.ts
78
+ function init(root = document) {
79
+ initCopyButtons(root);
80
+ initThemeToggles(root);
81
+ }
82
+ if (typeof document !== "undefined") {
83
+ if (document.readyState === "loading") {
84
+ document.addEventListener("DOMContentLoaded", () => init(), { once: true });
85
+ } else {
86
+ init();
87
+ }
88
+ }
89
+ export {
90
+ init
91
+ };
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ var SnowztechUI = (() => {
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/auto.ts
22
+ var auto_exports = {};
23
+ __export(auto_exports, {
24
+ init: () => init
25
+ });
26
+
27
+ // src/copy-button.ts
28
+ var RESET_MS = 1200;
29
+ async function copyValue(value) {
30
+ try {
31
+ await navigator.clipboard.writeText(value);
32
+ return true;
33
+ } catch {
34
+ const ta = document.createElement("textarea");
35
+ ta.value = value;
36
+ ta.style.position = "fixed";
37
+ ta.style.opacity = "0";
38
+ document.body.appendChild(ta);
39
+ ta.select();
40
+ let ok = false;
41
+ try {
42
+ ok = document.execCommand("copy");
43
+ } catch {
44
+ }
45
+ document.body.removeChild(ta);
46
+ return ok;
47
+ }
48
+ }
49
+ function onClick() {
50
+ const value = this.getAttribute("data-sn-copy");
51
+ if (value === null) return;
52
+ void copyValue(value).then((ok) => {
53
+ if (!ok) return;
54
+ this.setAttribute("data-copied", "true");
55
+ window.setTimeout(() => this.removeAttribute("data-copied"), RESET_MS);
56
+ });
57
+ }
58
+ function bindCopyButton(el) {
59
+ if (el.dataset.snBound === "copy") return;
60
+ el.dataset.snBound = "copy";
61
+ el.addEventListener("click", onClick);
62
+ }
63
+ function initCopyButtons(root = document) {
64
+ root.querySelectorAll("[data-sn-copy]").forEach(bindCopyButton);
65
+ }
66
+
67
+ // src/theme-toggle.ts
68
+ var DEFAULT_KEY = "theme";
69
+ function getTheme(storageKey = DEFAULT_KEY) {
70
+ try {
71
+ const stored = localStorage.getItem(storageKey);
72
+ if (stored === "light" || stored === "dark") return stored;
73
+ } catch {
74
+ }
75
+ return document.documentElement.getAttribute("data-theme") === "light" ? "light" : "dark";
76
+ }
77
+ function setTheme(theme, storageKey = DEFAULT_KEY) {
78
+ if (theme === "light") document.documentElement.setAttribute("data-theme", "light");
79
+ else document.documentElement.removeAttribute("data-theme");
80
+ try {
81
+ localStorage.setItem(storageKey, theme);
82
+ } catch {
83
+ }
84
+ }
85
+ function toggleTheme(storageKey = DEFAULT_KEY) {
86
+ const next = getTheme(storageKey) === "dark" ? "light" : "dark";
87
+ setTheme(next, storageKey);
88
+ return next;
89
+ }
90
+ function onClick2() {
91
+ const key = this.getAttribute("data-sn-storage-key") || DEFAULT_KEY;
92
+ toggleTheme(key);
93
+ }
94
+ function bindThemeToggle(el) {
95
+ if (el.dataset.snBound === "theme") return;
96
+ el.dataset.snBound = "theme";
97
+ el.addEventListener("click", onClick2);
98
+ }
99
+ function initThemeToggles(root = document) {
100
+ root.querySelectorAll("[data-sn-theme-toggle]").forEach(bindThemeToggle);
101
+ }
102
+
103
+ // src/auto.ts
104
+ function init(root = document) {
105
+ initCopyButtons(root);
106
+ initThemeToggles(root);
107
+ }
108
+ if (typeof document !== "undefined") {
109
+ if (document.readyState === "loading") {
110
+ document.addEventListener("DOMContentLoaded", () => init(), { once: true });
111
+ } else {
112
+ init();
113
+ }
114
+ }
115
+ return __toCommonJS(auto_exports);
116
+ })();
@@ -0,0 +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);})();
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@snowztech/ui-js",
3
+ "version": "0.2.0",
4
+ "description": "Optional vanilla bindings for @snowztech/ui-css. Wires data-sn-* attributes for static HTML.",
5
+ "license": "MIT",
6
+ "author": {
7
+ "name": "Lucas Neves Pereira",
8
+ "email": "lnevespereira@proton.me",
9
+ "url": "https://github.com/lucasnevespereira"
10
+ },
11
+ "homepage": "https://github.com/snowztech/ui#readme",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/snowztech/ui.git",
15
+ "directory": "packages/ui-js"
16
+ },
17
+ "bugs": {
18
+ "url": "https://github.com/snowztech/ui/issues"
19
+ },
20
+ "keywords": [
21
+ "snowztech",
22
+ "ui",
23
+ "vanilla",
24
+ "design-system",
25
+ "progressive-enhancement"
26
+ ],
27
+ "type": "module",
28
+ "main": "./dist/index.cjs",
29
+ "module": "./dist/index.js",
30
+ "types": "./src/index.ts",
31
+ "files": [
32
+ "dist",
33
+ "src",
34
+ "README.md",
35
+ "LICENSE"
36
+ ],
37
+ "exports": {
38
+ ".": {
39
+ "types": "./src/index.ts",
40
+ "import": "./dist/index.js",
41
+ "require": "./dist/index.cjs"
42
+ },
43
+ "./auto": "./dist/snowztech-ui.esm.js",
44
+ "./iife": "./dist/snowztech-ui.iife.js",
45
+ "./iife/min": "./dist/snowztech-ui.iife.min.js",
46
+ "./package.json": "./package.json"
47
+ },
48
+ "devDependencies": {
49
+ "esbuild": "^0.27.7",
50
+ "typescript": "^5.6.3"
51
+ },
52
+ "engines": {
53
+ "node": ">=18"
54
+ },
55
+ "publishConfig": {
56
+ "access": "public"
57
+ },
58
+ "scripts": {
59
+ "build": "node build.mjs",
60
+ "dev": "node build.mjs --watch",
61
+ "typecheck": "tsc --noEmit"
62
+ }
63
+ }
package/src/auto.ts ADDED
@@ -0,0 +1,18 @@
1
+ // Auto-wires every [data-sn-*] element on the page once the DOM is ready.
2
+ // Re-import safe (idempotent: each binder marks its element with data-sn-bound).
3
+
4
+ import { initCopyButtons } from "./copy-button";
5
+ import { initThemeToggles } from "./theme-toggle";
6
+
7
+ export function init(root: ParentNode = document): void {
8
+ initCopyButtons(root);
9
+ initThemeToggles(root);
10
+ }
11
+
12
+ if (typeof document !== "undefined") {
13
+ if (document.readyState === "loading") {
14
+ document.addEventListener("DOMContentLoaded", () => init(), { once: true });
15
+ } else {
16
+ init();
17
+ }
18
+ }
@@ -0,0 +1,44 @@
1
+ // Wires every <button data-sn-copy="…"> on the page.
2
+ // On click: copies the attr's value, flips data-copied="true" for ~1.2s.
3
+ // CSS handles the visual swap (.sn-copy-btn[data-copied="true"]).
4
+
5
+ const RESET_MS = 1200;
6
+
7
+ async function copyValue(value: string): Promise<boolean> {
8
+ try {
9
+ await navigator.clipboard.writeText(value);
10
+ return true;
11
+ } catch {
12
+ // Fallback for non-secure contexts.
13
+ const ta = document.createElement("textarea");
14
+ ta.value = value;
15
+ ta.style.position = "fixed";
16
+ ta.style.opacity = "0";
17
+ document.body.appendChild(ta);
18
+ ta.select();
19
+ let ok = false;
20
+ try { ok = document.execCommand("copy"); } catch { /* ignore */ }
21
+ document.body.removeChild(ta);
22
+ return ok;
23
+ }
24
+ }
25
+
26
+ function onClick(this: HTMLElement) {
27
+ const value = this.getAttribute("data-sn-copy");
28
+ if (value === null) return;
29
+ void copyValue(value).then((ok) => {
30
+ if (!ok) return;
31
+ this.setAttribute("data-copied", "true");
32
+ window.setTimeout(() => this.removeAttribute("data-copied"), RESET_MS);
33
+ });
34
+ }
35
+
36
+ export function bindCopyButton(el: HTMLElement): void {
37
+ if (el.dataset.snBound === "copy") return;
38
+ el.dataset.snBound = "copy";
39
+ el.addEventListener("click", onClick);
40
+ }
41
+
42
+ export function initCopyButtons(root: ParentNode = document): void {
43
+ root.querySelectorAll<HTMLElement>("[data-sn-copy]").forEach(bindCopyButton);
44
+ }
package/src/index.ts ADDED
@@ -0,0 +1,18 @@
1
+ // ESM entry. Consumers call init() themselves.
2
+ // Use ./auto for the side-effect "wire everything on load" entry.
3
+
4
+ export {
5
+ bindCopyButton,
6
+ initCopyButtons,
7
+ } from "./copy-button";
8
+
9
+ export {
10
+ bindThemeToggle,
11
+ initThemeToggles,
12
+ getTheme,
13
+ setTheme,
14
+ toggleTheme,
15
+ type Theme,
16
+ } from "./theme-toggle";
17
+
18
+ export { init } from "./auto";
@@ -0,0 +1,41 @@
1
+ // Wires every <button data-sn-theme-toggle> on the page.
2
+ // Toggles [data-theme="light"] on <html>, persists to localStorage.
3
+
4
+ export type Theme = "light" | "dark";
5
+
6
+ const DEFAULT_KEY = "theme";
7
+
8
+ export function getTheme(storageKey = DEFAULT_KEY): Theme {
9
+ try {
10
+ const stored = localStorage.getItem(storageKey) as Theme | null;
11
+ if (stored === "light" || stored === "dark") return stored;
12
+ } catch { /* ignore */ }
13
+ return document.documentElement.getAttribute("data-theme") === "light" ? "light" : "dark";
14
+ }
15
+
16
+ export function setTheme(theme: Theme, storageKey = DEFAULT_KEY): void {
17
+ if (theme === "light") document.documentElement.setAttribute("data-theme", "light");
18
+ else document.documentElement.removeAttribute("data-theme");
19
+ try { localStorage.setItem(storageKey, theme); } catch { /* ignore */ }
20
+ }
21
+
22
+ export function toggleTheme(storageKey = DEFAULT_KEY): Theme {
23
+ const next: Theme = getTheme(storageKey) === "dark" ? "light" : "dark";
24
+ setTheme(next, storageKey);
25
+ return next;
26
+ }
27
+
28
+ function onClick(this: HTMLElement) {
29
+ const key = this.getAttribute("data-sn-storage-key") || DEFAULT_KEY;
30
+ toggleTheme(key);
31
+ }
32
+
33
+ export function bindThemeToggle(el: HTMLElement): void {
34
+ if (el.dataset.snBound === "theme") return;
35
+ el.dataset.snBound = "theme";
36
+ el.addEventListener("click", onClick);
37
+ }
38
+
39
+ export function initThemeToggles(root: ParentNode = document): void {
40
+ root.querySelectorAll<HTMLElement>("[data-sn-theme-toggle]").forEach(bindThemeToggle);
41
+ }