@anmiles/theme-switcher 2.0.0 → 2.0.2
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/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [2.0.2](../../tags/v2.0.2) - 2025-09-19
|
|
9
|
+
### Changed
|
|
10
|
+
- Fix npm vulnerabilities
|
|
11
|
+
|
|
12
|
+
## [2.0.1](../../tags/v2.0.1) - 2025-07-24
|
|
13
|
+
### Changed
|
|
14
|
+
- Fix vulnerable dependencies
|
|
15
|
+
|
|
8
16
|
## [2.0.0](../../tags/v2.0.0) - 2025-05-18
|
|
9
17
|
__(BREAKING) Dropped support for NodeJS 18 (EOL). Minimum required version is now NodeJS 20.__
|
|
10
18
|
|
package/LICENSE.md
CHANGED
|
@@ -61,18 +61,15 @@ var ThemeSwitcher = function(exports, require$$0, require$$0$1) {
|
|
|
61
61
|
this.listeners = {};
|
|
62
62
|
}
|
|
63
63
|
on(event, listener) {
|
|
64
|
-
|
|
65
|
-
const listeners = (_a = this.listeners)[event] ?? (_a[event] = []);
|
|
64
|
+
const listeners = this.listeners[event] ??= [];
|
|
66
65
|
listeners.push(listener);
|
|
67
66
|
}
|
|
68
67
|
off(event, listener) {
|
|
69
|
-
|
|
70
|
-
const listeners = (_a = this.listeners)[event] ?? (_a[event] = []);
|
|
68
|
+
const listeners = this.listeners[event] ??= [];
|
|
71
69
|
listeners.splice(listeners.indexOf(listener), 1);
|
|
72
70
|
}
|
|
73
71
|
emit(event, ...data) {
|
|
74
|
-
|
|
75
|
-
(_a = this.listeners[event]) == null ? void 0 : _a.forEach((listener) => {
|
|
72
|
+
this.listeners[event]?.forEach((listener) => {
|
|
76
73
|
listener(...data);
|
|
77
74
|
});
|
|
78
75
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
var ThemeSwitcher=function(m,a,T){"use strict";var y=document.createElement("style");y.textContent=`.themeSwitcher{cursor:pointer;position:relative}.themeSwitcher>svg:hover,.themeSwitcher li:hover{filter:brightness(1.5)}.themeSwitcher svg{width:2em;height:2em;stroke:currentColor;display:block}.themeSwitcher ul{list-style-type:none;position:absolute;left:0;margin:.5em 0;padding:0;gap:0;overflow-y:visible;z-index:1}.themeSwitcher li{padding:.5em 1em}.themeSwitcher[data-float=right] ul{left:auto;right:0}.themeSwitcher li{display:flex;align-items:center;gap:.5em}.themeSwitcher li svg{width:1.5em;height:1.5em}.themeSwitcher svg.checked{width:16px;height:13.5px}
|
|
2
|
+
/*$vite$:1*/`,document.head.appendChild(y);var x={exports:{}},l={};/**
|
|
3
|
+
* @license React
|
|
4
|
+
* react-jsx-runtime.production.min.js
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
7
|
+
*
|
|
8
|
+
* This source code is licensed under the MIT license found in the
|
|
9
|
+
* LICENSE file in the root directory of this source tree.
|
|
10
|
+
*/var j;function C(){if(j)return l;j=1;var s=a,t=Symbol.for("react.element"),r=Symbol.for("react.fragment"),n=Object.prototype.hasOwnProperty,v=s.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,w={key:!0,ref:!0,__self:!0,__source:!0};function f(c,o,h){var i,p={},g=null,E=null;h!==void 0&&(g=""+h),o.key!==void 0&&(g=""+o.key),o.ref!==void 0&&(E=o.ref);for(i in o)n.call(o,i)&&!w.hasOwnProperty(i)&&(p[i]=o[i]);if(c&&c.defaultProps)for(i in o=c.defaultProps,o)p[i]===void 0&&(p[i]=o[i]);return{$$typeof:t,type:c,key:g,ref:E,props:p,_owner:v.current}}return l.Fragment=r,l.jsx=f,l.jsxs=f,l}var S;function b(){return S||(S=1,x.exports=C()),x.exports}var e=b(),d={},k;function O(){if(k)return d;k=1;var s=T;return d.createRoot=s.createRoot,d.hydrateRoot=s.hydrateRoot,d}var N=O();class _{constructor(){this.listeners={}}on(t,r){(this.listeners[t]??=[]).push(r)}off(t,r){const n=this.listeners[t]??=[];n.splice(n.indexOf(r),1)}emit(t,...r){this.listeners[t]?.forEach(n=>{n(...r)})}}const u=["light","dark"],R="light";function P(s){return typeof s=="string"&&u.map(String).includes(s)}function I(s){switch(s){case"light":return"Light";case"dark":return"Dark";case void 0:default:return"System"}}class D extends _{get(){if(!("matchMedia"in window))return R;for(const t of u)if(window.matchMedia(`(prefers-color-scheme: ${t})`).matches)return t;return R}watch(){if("matchMedia"in window)for(const t of u)window.matchMedia(`(prefers-color-scheme: ${t})`).addEventListener("change",n=>{n.matches&&this.emit("change",t)})}}class B extends _{constructor(){super(...arguments),this.storageKey="theme"}get(){const t=localStorage.getItem(this.storageKey);return P(t)?t:void 0}set(t){t?localStorage.setItem(this.storageKey,t):localStorage.removeItem(this.storageKey),this.emit("change",t)}}function J(){return e.jsxs("svg",{viewBox:"0 0 100 100",xmlns:"http://www.w3.org/2000/svg",className:"dark",strokeWidth:"8",strokeLinecap:"round",fill:"none",children:[e.jsx("circle",{cx:"50",cy:"50",r:"46",strokeDasharray:"180",transform:"rotate(22.5 50 50)"}),e.jsx("circle",{cx:"75",cy:"25",r:"46",strokeDasharray:"108 200",transform:"rotate(67.5 75 25)"})]})}function U(){return e.jsxs("svg",{viewBox:"0 0 100 100",xmlns:"http://www.w3.org/2000/svg",className:"light",strokeWidth:"8",strokeLinecap:"round",fill:"none",children:[e.jsx("circle",{cx:"50",cy:"50",r:"20"}),e.jsx("path",{d:"M 50 86 v 10",transform:"rotate(0 50 50)"}),e.jsx("path",{d:"M 50 86 v 10",transform:"rotate(90 50 50)"}),e.jsx("path",{d:"M 50 86 v 10",transform:"rotate(180 50 50)"}),e.jsx("path",{d:"M 50 86 v 10",transform:"rotate(270 50 50)"}),e.jsx("path",{d:"M 50 86 v 15",transform:"rotate(45 50 50)"}),e.jsx("path",{d:"M 50 86 v 15",transform:"rotate(135 50 50)"}),e.jsx("path",{d:"M 50 86 v 15",transform:"rotate(225 50 50)"}),e.jsx("path",{d:"M 50 86 v 15",transform:"rotate(315 50 50)"})]})}function W(){return e.jsxs("svg",{viewBox:"0 0 100 100",xmlns:"http://www.w3.org/2000/svg",className:"system",strokeWidth:"8",strokeLinecap:"round",fill:"none",children:[e.jsx("circle",{cx:"50",cy:"50",r:"46"}),e.jsx("path",{strokeWidth:"0",fill:"currentColor",d:`
|
|
11
|
+
M 50,0
|
|
12
|
+
a 50,50,0,1,1,0,100
|
|
13
|
+
Z`})]})}function M({theme:s}){switch(s){case"light":return e.jsx(U,{});case"dark":return e.jsx(J,{});case void 0:default:return e.jsx(W,{})}}function K(){return e.jsx("svg",{viewBox:"0 0 640 540",xmlns:"http://www.w3.org/2000/svg",className:"checked",children:e.jsx("path",{fill:"currentColor",d:`
|
|
14
|
+
M 12,370
|
|
15
|
+
a 40,40,0,0,1,56.56,-56.56
|
|
16
|
+
l 130,130
|
|
17
|
+
l 370,-430
|
|
18
|
+
a 40,40,0,0,1,56.56,56.56
|
|
19
|
+
l -398.28,458.28
|
|
20
|
+
a 40,40,0,0,1,-56.56,0
|
|
21
|
+
l -140,-140
|
|
22
|
+
Z`})})}function Q({currentUserTheme:s,onListItemClick:t}){return e.jsx("ul",{"data-testid":"theme-selector",children:[...u,void 0].map(r=>{const n=I(r);return e.jsxs("li",{"data-testid":`theme-item-${n.toLowerCase()}`,onClick:()=>{t(r)},children:[e.jsx(M,{theme:r}),e.jsx("span",{children:n}),s===r&&e.jsx(K,{})]},n)})})}function L({float:s}){const t=a.useMemo(()=>new B,[]),r=a.useMemo(()=>new D,[]),[n,v]=a.useState(t.get()),[w,f]=a.useState(r.get()),[c,o]=a.useState(!1),h=n??w;return a.useEffect(()=>{document.body.setAttribute("data-theme",h),t.on("change",v),r.on("change",f),r.watch()},[h,t,r]),e.jsxs("div",{className:"themeSwitcher","data-testid":"theme-switcher","data-float":s,onClick:()=>{o(!c)},children:[e.jsx(M,{theme:h}),c?e.jsx(Q,{currentUserTheme:n,onListItemClick:i=>{t.set(i),o(!1)}}):null]})}class A{constructor(t){this.props=t}render(t){N.createRoot(t).render(e.jsx(a.StrictMode,{children:e.jsx(L,{...this.props})}))}}return m.Element=A,m.ThemeSwitcher=L,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"}),m}({},React,ReactDOM);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anmiles/theme-switcher",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Theme switcher for websites",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"theme",
|
|
@@ -35,57 +35,57 @@
|
|
|
35
35
|
"start:prod": "npm start production"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@anmiles/express-tools": "^
|
|
39
|
-
"@anmiles/logger": "^8.0.
|
|
38
|
+
"@anmiles/express-tools": "^2.0.3",
|
|
39
|
+
"@anmiles/logger": "^8.0.1",
|
|
40
40
|
"express": "^5.1.0",
|
|
41
41
|
"npm-run-all": "^4.1.5",
|
|
42
42
|
"react": "^18.3.1",
|
|
43
43
|
"react-dom": "^18.3.1"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@anmiles/eslint-config": "^9.0.
|
|
46
|
+
"@anmiles/eslint-config": "^9.0.3",
|
|
47
47
|
"@anmiles/tsconfig": "^4.0.0",
|
|
48
|
-
"@eslint/compat": "^1.
|
|
49
|
-
"@eslint/css": "^0.
|
|
50
|
-
"@eslint/js": "^9.
|
|
51
|
-
"@eslint/json": "^0.
|
|
52
|
-
"@eslint/markdown": "^
|
|
53
|
-
"@stylistic/eslint-plugin": "^
|
|
48
|
+
"@eslint/compat": "^1.3.1",
|
|
49
|
+
"@eslint/css": "^0.10.0",
|
|
50
|
+
"@eslint/js": "^9.31.0",
|
|
51
|
+
"@eslint/json": "^0.13.1",
|
|
52
|
+
"@eslint/markdown": "^7.1.0",
|
|
53
|
+
"@stylistic/eslint-plugin": "^5.2.2",
|
|
54
54
|
"@testing-library/dom": "^10.4.0",
|
|
55
55
|
"@testing-library/jest-dom": "^6.6.3",
|
|
56
56
|
"@testing-library/react": "^16.3.0",
|
|
57
|
-
"@types/jest": "^
|
|
57
|
+
"@types/jest": "^30.0.0",
|
|
58
58
|
"@types/react": "^18.3.20",
|
|
59
59
|
"@types/react-dom": "^18.3.6",
|
|
60
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
61
|
-
"@typescript-eslint/parser": "^8.
|
|
62
|
-
"@vitejs/plugin-react": "^4.
|
|
63
|
-
"cspell": "^9.0
|
|
60
|
+
"@typescript-eslint/eslint-plugin": "^8.38.0",
|
|
61
|
+
"@typescript-eslint/parser": "^8.38.0",
|
|
62
|
+
"@vitejs/plugin-react": "^4.7.0",
|
|
63
|
+
"cspell": "^9.2.0",
|
|
64
64
|
"css-loader": "^7.1.2",
|
|
65
|
-
"eslint": "^9.
|
|
66
|
-
"eslint-import-resolver-typescript": "^4.
|
|
65
|
+
"eslint": "^9.31.0",
|
|
66
|
+
"eslint-import-resolver-typescript": "^4.4.4",
|
|
67
67
|
"eslint-plugin-align-assignments": "^1.1.2",
|
|
68
|
-
"eslint-plugin-i18next": "^6.1.
|
|
69
|
-
"eslint-plugin-import": "^2.
|
|
70
|
-
"eslint-plugin-jest": "^
|
|
71
|
-
"eslint-plugin-n": "^17.
|
|
68
|
+
"eslint-plugin-i18next": "^6.1.3",
|
|
69
|
+
"eslint-plugin-import": "^2.32.0",
|
|
70
|
+
"eslint-plugin-jest": "^29.0.1",
|
|
71
|
+
"eslint-plugin-n": "^17.21.0",
|
|
72
72
|
"eslint-plugin-promise": "^7.2.1",
|
|
73
73
|
"eslint-plugin-react": "^7.37.5",
|
|
74
74
|
"eslint-plugin-react-hooks": "^5.2.0",
|
|
75
75
|
"eslint-plugin-react-redux": "^4.2.2",
|
|
76
76
|
"eslint-plugin-react-refresh": "^0.4.20",
|
|
77
|
-
"jest": "^
|
|
78
|
-
"jest-environment-jsdom": "^
|
|
79
|
-
"jiti": "^2.
|
|
77
|
+
"jest": "^30.0.5",
|
|
78
|
+
"jest-environment-jsdom": "^30.0.5",
|
|
79
|
+
"jiti": "^2.5.0",
|
|
80
80
|
"nyc": "^17.1.0",
|
|
81
81
|
"react-refresh": "^0.17.0",
|
|
82
82
|
"react-refresh-typescript": "^2.0.10",
|
|
83
83
|
"rimraf": "^6.0.1",
|
|
84
84
|
"style-loader": "^4.0.0",
|
|
85
|
-
"ts-jest": "^29.
|
|
85
|
+
"ts-jest": "^29.4.0",
|
|
86
86
|
"ts-loader": "^9.5.2",
|
|
87
87
|
"typescript": "^5.8.3",
|
|
88
|
-
"vite": "^
|
|
88
|
+
"vite": "^7.0.6",
|
|
89
89
|
"vite-plugin-lib-inject-css": "^2.2.2"
|
|
90
90
|
}
|
|
91
91
|
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
var ThemeSwitcher=function(d,c,T){"use strict";var y=document.createElement("style");y.textContent=`.themeSwitcher{cursor:pointer;position:relative}.themeSwitcher>svg:hover,.themeSwitcher li:hover{filter:brightness(1.5)}.themeSwitcher svg{width:2em;height:2em;stroke:currentColor;display:block}.themeSwitcher ul{list-style-type:none;position:absolute;left:0;margin:.5em 0;padding:0;gap:0;overflow-y:visible;z-index:1}.themeSwitcher li{padding:.5em 1em}.themeSwitcher[data-float=right] ul{left:auto;right:0}.themeSwitcher li{display:flex;align-items:center;gap:.5em}.themeSwitcher li svg{width:1.5em;height:1.5em}.themeSwitcher svg.checked{width:16px;height:13.5px}
|
|
2
|
-
/*$vite$:1*/`,document.head.appendChild(y);var w={exports:{}},m={};/**
|
|
3
|
-
* @license React
|
|
4
|
-
* react-jsx-runtime.production.min.js
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
7
|
-
*
|
|
8
|
-
* This source code is licensed under the MIT license found in the
|
|
9
|
-
* LICENSE file in the root directory of this source tree.
|
|
10
|
-
*/var j;function C(){if(j)return m;j=1;var s=c,e=Symbol.for("react.element"),r=Symbol.for("react.fragment"),n=Object.prototype.hasOwnProperty,i=s.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,g={key:!0,ref:!0,__self:!0,__source:!0};function p(h,o,l){var a,x={},v=null,E=null;l!==void 0&&(v=""+l),o.key!==void 0&&(v=""+o.key),o.ref!==void 0&&(E=o.ref);for(a in o)n.call(o,a)&&!g.hasOwnProperty(a)&&(x[a]=o[a]);if(h&&h.defaultProps)for(a in o=h.defaultProps,o)x[a]===void 0&&(x[a]=o[a]);return{$$typeof:e,type:h,key:v,ref:E,props:x,_owner:i.current}}return m.Fragment=r,m.jsx=p,m.jsxs=p,m}var S;function b(){return S||(S=1,w.exports=C()),w.exports}var t=b(),u={},k;function O(){if(k)return u;k=1;var s=T;return u.createRoot=s.createRoot,u.hydrateRoot=s.hydrateRoot,u}var N=O();class _{constructor(){this.listeners={}}on(e,r){var i;((i=this.listeners)[e]??(i[e]=[])).push(r)}off(e,r){var i;const n=(i=this.listeners)[e]??(i[e]=[]);n.splice(n.indexOf(r),1)}emit(e,...r){var n;(n=this.listeners[e])==null||n.forEach(i=>{i(...r)})}}const f=["light","dark"],R="light";function P(s){return typeof s=="string"&&f.map(String).includes(s)}function I(s){switch(s){case"light":return"Light";case"dark":return"Dark";case void 0:default:return"System"}}class D extends _{get(){if(!("matchMedia"in window))return R;for(const e of f)if(window.matchMedia(`(prefers-color-scheme: ${e})`).matches)return e;return R}watch(){if("matchMedia"in window)for(const e of f)window.matchMedia(`(prefers-color-scheme: ${e})`).addEventListener("change",n=>{n.matches&&this.emit("change",e)})}}class B extends _{constructor(){super(...arguments),this.storageKey="theme"}get(){const e=localStorage.getItem(this.storageKey);return P(e)?e:void 0}set(e){e?localStorage.setItem(this.storageKey,e):localStorage.removeItem(this.storageKey),this.emit("change",e)}}function J(){return t.jsxs("svg",{viewBox:"0 0 100 100",xmlns:"http://www.w3.org/2000/svg",className:"dark",strokeWidth:"8",strokeLinecap:"round",fill:"none",children:[t.jsx("circle",{cx:"50",cy:"50",r:"46",strokeDasharray:"180",transform:"rotate(22.5 50 50)"}),t.jsx("circle",{cx:"75",cy:"25",r:"46",strokeDasharray:"108 200",transform:"rotate(67.5 75 25)"})]})}function U(){return t.jsxs("svg",{viewBox:"0 0 100 100",xmlns:"http://www.w3.org/2000/svg",className:"light",strokeWidth:"8",strokeLinecap:"round",fill:"none",children:[t.jsx("circle",{cx:"50",cy:"50",r:"20"}),t.jsx("path",{d:"M 50 86 v 10",transform:"rotate(0 50 50)"}),t.jsx("path",{d:"M 50 86 v 10",transform:"rotate(90 50 50)"}),t.jsx("path",{d:"M 50 86 v 10",transform:"rotate(180 50 50)"}),t.jsx("path",{d:"M 50 86 v 10",transform:"rotate(270 50 50)"}),t.jsx("path",{d:"M 50 86 v 15",transform:"rotate(45 50 50)"}),t.jsx("path",{d:"M 50 86 v 15",transform:"rotate(135 50 50)"}),t.jsx("path",{d:"M 50 86 v 15",transform:"rotate(225 50 50)"}),t.jsx("path",{d:"M 50 86 v 15",transform:"rotate(315 50 50)"})]})}function W(){return t.jsxs("svg",{viewBox:"0 0 100 100",xmlns:"http://www.w3.org/2000/svg",className:"system",strokeWidth:"8",strokeLinecap:"round",fill:"none",children:[t.jsx("circle",{cx:"50",cy:"50",r:"46"}),t.jsx("path",{strokeWidth:"0",fill:"currentColor",d:`
|
|
11
|
-
M 50,0
|
|
12
|
-
a 50,50,0,1,1,0,100
|
|
13
|
-
Z`})]})}function M({theme:s}){switch(s){case"light":return t.jsx(U,{});case"dark":return t.jsx(J,{});case void 0:default:return t.jsx(W,{})}}function K(){return t.jsx("svg",{viewBox:"0 0 640 540",xmlns:"http://www.w3.org/2000/svg",className:"checked",children:t.jsx("path",{fill:"currentColor",d:`
|
|
14
|
-
M 12,370
|
|
15
|
-
a 40,40,0,0,1,56.56,-56.56
|
|
16
|
-
l 130,130
|
|
17
|
-
l 370,-430
|
|
18
|
-
a 40,40,0,0,1,56.56,56.56
|
|
19
|
-
l -398.28,458.28
|
|
20
|
-
a 40,40,0,0,1,-56.56,0
|
|
21
|
-
l -140,-140
|
|
22
|
-
Z`})})}function Q({currentUserTheme:s,onListItemClick:e}){return t.jsx("ul",{"data-testid":"theme-selector",children:[...f,void 0].map(r=>{const n=I(r);return t.jsxs("li",{"data-testid":`theme-item-${n.toLowerCase()}`,onClick:()=>{e(r)},children:[t.jsx(M,{theme:r}),t.jsx("span",{children:n}),s===r&&t.jsx(K,{})]},n)})})}function L({float:s}){const e=c.useMemo(()=>new B,[]),r=c.useMemo(()=>new D,[]),[n,i]=c.useState(e.get()),[g,p]=c.useState(r.get()),[h,o]=c.useState(!1),l=n??g;return c.useEffect(()=>{document.body.setAttribute("data-theme",l),e.on("change",i),r.on("change",p),r.watch()},[l,e,r]),t.jsxs("div",{className:"themeSwitcher","data-testid":"theme-switcher","data-float":s,onClick:()=>{o(!h)},children:[t.jsx(M,{theme:l}),h?t.jsx(Q,{currentUserTheme:n,onListItemClick:a=>{e.set(a),o(!1)}}):null]})}class A{constructor(e){this.props=e}render(e){N.createRoot(e).render(t.jsx(c.StrictMode,{children:t.jsx(L,{...this.props})}))}}return d.Element=A,d.ThemeSwitcher=L,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"}),d}({},React,ReactDOM);
|