qstd 0.2.2 → 0.2.3
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 +8 -0
- package/dist/react/index.cjs +7 -10
- package/dist/react/index.d.cts +2 -2
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.js +7 -10
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.2.3] - 2025-11-24
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Updated `useTheme` hook to automatically set `data-theme` attribute on `document.documentElement`
|
|
15
|
+
- Renamed internal store property from `theme` to `value` for better clarity
|
|
16
|
+
- Code cleanup in theme utility functions
|
|
17
|
+
|
|
10
18
|
## [0.2.2] - 2025-11-24
|
|
11
19
|
|
|
12
20
|
### Added
|
package/dist/react/index.cjs
CHANGED
|
@@ -3554,34 +3554,29 @@ var THEME_CHANGE_EVENT = "qstd:theme-change";
|
|
|
3554
3554
|
|
|
3555
3555
|
// src/react/use-theme/fns.ts
|
|
3556
3556
|
var getInitialTheme = () => {
|
|
3557
|
-
if (typeof window === "undefined") return "light";
|
|
3558
3557
|
const stored = localStorage.getItem(THEME_STORAGE_KEY);
|
|
3559
3558
|
return stored === "light" || stored === "dark" ? stored : "light";
|
|
3560
3559
|
};
|
|
3561
3560
|
var getInitialStore = () => {
|
|
3562
|
-
if (typeof window === "undefined") {
|
|
3563
|
-
return { theme: "light", isManual: false };
|
|
3564
|
-
}
|
|
3565
3561
|
try {
|
|
3566
3562
|
const stored = localStorage.getItem(THEME_STORE_STORAGE_KEY);
|
|
3567
3563
|
if (stored) {
|
|
3568
3564
|
const parsed = JSON.parse(stored);
|
|
3569
3565
|
return {
|
|
3570
|
-
|
|
3566
|
+
value: parsed.theme ?? getInitialTheme(),
|
|
3571
3567
|
isManual: parsed.isManual ?? false
|
|
3572
3568
|
};
|
|
3573
3569
|
}
|
|
3574
3570
|
} catch {
|
|
3575
3571
|
}
|
|
3576
3572
|
return {
|
|
3577
|
-
|
|
3573
|
+
value: getInitialTheme(),
|
|
3578
3574
|
isManual: false
|
|
3579
3575
|
};
|
|
3580
3576
|
};
|
|
3581
3577
|
var saveStore = (store) => {
|
|
3582
|
-
if (typeof window === "undefined") return;
|
|
3583
3578
|
try {
|
|
3584
|
-
localStorage.setItem(THEME_STORAGE_KEY, store.
|
|
3579
|
+
localStorage.setItem(THEME_STORAGE_KEY, store.value);
|
|
3585
3580
|
localStorage.setItem(THEME_STORE_STORAGE_KEY, JSON.stringify(store));
|
|
3586
3581
|
window.dispatchEvent(
|
|
3587
3582
|
new CustomEvent(THEME_CHANGE_EVENT, { detail: store })
|
|
@@ -3594,7 +3589,9 @@ var saveStore = (store) => {
|
|
|
3594
3589
|
function useTheme() {
|
|
3595
3590
|
const [store, setStore] = React11__namespace.default.useState(getInitialStore);
|
|
3596
3591
|
React11__namespace.default.useEffect(() => {
|
|
3597
|
-
|
|
3592
|
+
document.documentElement.setAttribute("data-theme", store.value);
|
|
3593
|
+
}, [store.value]);
|
|
3594
|
+
React11__namespace.default.useEffect(() => {
|
|
3598
3595
|
const handleStorageChange = (e) => {
|
|
3599
3596
|
if (e.key === THEME_STORAGE_KEY || e.key === THEME_STORE_STORAGE_KEY) {
|
|
3600
3597
|
setStore(getInitialStore());
|
|
@@ -3623,7 +3620,7 @@ function useTheme() {
|
|
|
3623
3620
|
const toggleTheme = (theme) => {
|
|
3624
3621
|
setStore((prev) => {
|
|
3625
3622
|
const next = {
|
|
3626
|
-
|
|
3623
|
+
value: theme ?? (prev.value === "light" ? "dark" : "light"),
|
|
3627
3624
|
isManual: true
|
|
3628
3625
|
};
|
|
3629
3626
|
saveStore(next);
|
package/dist/react/index.d.cts
CHANGED
|
@@ -20993,7 +20993,7 @@ declare const CompoundBlock: BlockComponent;
|
|
|
20993
20993
|
|
|
20994
20994
|
type Theme = "light" | "dark";
|
|
20995
20995
|
type ThemeStore = {
|
|
20996
|
-
|
|
20996
|
+
value: Theme;
|
|
20997
20997
|
isManual: boolean;
|
|
20998
20998
|
};
|
|
20999
20999
|
|
|
@@ -21004,7 +21004,7 @@ type ThemeStore = {
|
|
|
21004
21004
|
declare function useTheme(): {
|
|
21005
21005
|
update: (updates: Partial<ThemeStore>) => void;
|
|
21006
21006
|
toggleTheme: (theme?: "light" | "dark") => void;
|
|
21007
|
-
|
|
21007
|
+
value: Theme;
|
|
21008
21008
|
isManual: boolean;
|
|
21009
21009
|
};
|
|
21010
21010
|
|
package/dist/react/index.d.ts
CHANGED
|
@@ -20993,7 +20993,7 @@ declare const CompoundBlock: BlockComponent;
|
|
|
20993
20993
|
|
|
20994
20994
|
type Theme = "light" | "dark";
|
|
20995
20995
|
type ThemeStore = {
|
|
20996
|
-
|
|
20996
|
+
value: Theme;
|
|
20997
20997
|
isManual: boolean;
|
|
20998
20998
|
};
|
|
20999
20999
|
|
|
@@ -21004,7 +21004,7 @@ type ThemeStore = {
|
|
|
21004
21004
|
declare function useTheme(): {
|
|
21005
21005
|
update: (updates: Partial<ThemeStore>) => void;
|
|
21006
21006
|
toggleTheme: (theme?: "light" | "dark") => void;
|
|
21007
|
-
|
|
21007
|
+
value: Theme;
|
|
21008
21008
|
isManual: boolean;
|
|
21009
21009
|
};
|
|
21010
21010
|
|
package/dist/react/index.js
CHANGED
|
@@ -3531,34 +3531,29 @@ var THEME_CHANGE_EVENT = "qstd:theme-change";
|
|
|
3531
3531
|
|
|
3532
3532
|
// src/react/use-theme/fns.ts
|
|
3533
3533
|
var getInitialTheme = () => {
|
|
3534
|
-
if (typeof window === "undefined") return "light";
|
|
3535
3534
|
const stored = localStorage.getItem(THEME_STORAGE_KEY);
|
|
3536
3535
|
return stored === "light" || stored === "dark" ? stored : "light";
|
|
3537
3536
|
};
|
|
3538
3537
|
var getInitialStore = () => {
|
|
3539
|
-
if (typeof window === "undefined") {
|
|
3540
|
-
return { theme: "light", isManual: false };
|
|
3541
|
-
}
|
|
3542
3538
|
try {
|
|
3543
3539
|
const stored = localStorage.getItem(THEME_STORE_STORAGE_KEY);
|
|
3544
3540
|
if (stored) {
|
|
3545
3541
|
const parsed = JSON.parse(stored);
|
|
3546
3542
|
return {
|
|
3547
|
-
|
|
3543
|
+
value: parsed.theme ?? getInitialTheme(),
|
|
3548
3544
|
isManual: parsed.isManual ?? false
|
|
3549
3545
|
};
|
|
3550
3546
|
}
|
|
3551
3547
|
} catch {
|
|
3552
3548
|
}
|
|
3553
3549
|
return {
|
|
3554
|
-
|
|
3550
|
+
value: getInitialTheme(),
|
|
3555
3551
|
isManual: false
|
|
3556
3552
|
};
|
|
3557
3553
|
};
|
|
3558
3554
|
var saveStore = (store) => {
|
|
3559
|
-
if (typeof window === "undefined") return;
|
|
3560
3555
|
try {
|
|
3561
|
-
localStorage.setItem(THEME_STORAGE_KEY, store.
|
|
3556
|
+
localStorage.setItem(THEME_STORAGE_KEY, store.value);
|
|
3562
3557
|
localStorage.setItem(THEME_STORE_STORAGE_KEY, JSON.stringify(store));
|
|
3563
3558
|
window.dispatchEvent(
|
|
3564
3559
|
new CustomEvent(THEME_CHANGE_EVENT, { detail: store })
|
|
@@ -3571,7 +3566,9 @@ var saveStore = (store) => {
|
|
|
3571
3566
|
function useTheme() {
|
|
3572
3567
|
const [store, setStore] = React11__default.useState(getInitialStore);
|
|
3573
3568
|
React11__default.useEffect(() => {
|
|
3574
|
-
|
|
3569
|
+
document.documentElement.setAttribute("data-theme", store.value);
|
|
3570
|
+
}, [store.value]);
|
|
3571
|
+
React11__default.useEffect(() => {
|
|
3575
3572
|
const handleStorageChange = (e) => {
|
|
3576
3573
|
if (e.key === THEME_STORAGE_KEY || e.key === THEME_STORE_STORAGE_KEY) {
|
|
3577
3574
|
setStore(getInitialStore());
|
|
@@ -3600,7 +3597,7 @@ function useTheme() {
|
|
|
3600
3597
|
const toggleTheme = (theme) => {
|
|
3601
3598
|
setStore((prev) => {
|
|
3602
3599
|
const next = {
|
|
3603
|
-
|
|
3600
|
+
value: theme ?? (prev.value === "light" ? "dark" : "light"),
|
|
3604
3601
|
isManual: true
|
|
3605
3602
|
};
|
|
3606
3603
|
saveStore(next);
|