@ucdjs-internal/shared-ui 0.1.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 +21 -0
- package/README.md +27 -0
- package/dist/components/shiki-code.d.mts +50 -0
- package/dist/components/shiki-code.mjs +76 -0
- package/dist/components/theme-toggle.d.mts +6 -0
- package/dist/components/theme-toggle.mjs +75 -0
- package/dist/hooks/index.d.mts +3 -0
- package/dist/hooks/index.mjs +4 -0
- package/dist/hooks/use-mobile.d.mts +4 -0
- package/dist/hooks/use-mobile.mjs +41 -0
- package/dist/hooks/use-theme.d.mts +11 -0
- package/dist/hooks/use-theme.mjs +105 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.mjs +4 -0
- package/dist/lib/theme-script.d.mts +5 -0
- package/dist/lib/theme-script.mjs +26 -0
- package/dist/lib/utils.d.mts +6 -0
- package/dist/lib/utils.mjs +10 -0
- package/dist/styles/globals.css +219 -0
- package/dist/styles/shadcn-vendored.css +95 -0
- package/dist/ui/alert-dialog.d.mts +58 -0
- package/dist/ui/alert-dialog.mjs +387 -0
- package/dist/ui/avatar.d.mts +34 -0
- package/dist/ui/avatar.mjs +208 -0
- package/dist/ui/badge.d.mts +17 -0
- package/dist/ui/badge.mjs +76 -0
- package/dist/ui/breadcrumb.d.mts +37 -0
- package/dist/ui/breadcrumb.mjs +281 -0
- package/dist/ui/button.d.mts +18 -0
- package/dist/ui/button.mjs +82 -0
- package/dist/ui/card.d.mts +37 -0
- package/dist/ui/card.mjs +239 -0
- package/dist/ui/checkbox.d.mts +10 -0
- package/dist/ui/checkbox.mjs +52 -0
- package/dist/ui/collapsible.d.mts +15 -0
- package/dist/ui/collapsible.mjs +65 -0
- package/dist/ui/combobox.d.mts +81 -0
- package/dist/ui/combobox.mjs +641 -0
- package/dist/ui/command.d.mts +55 -0
- package/dist/ui/command.mjs +378 -0
- package/dist/ui/context-menu.d.mts +86 -0
- package/dist/ui/context-menu.mjs +520 -0
- package/dist/ui/dialog.d.mts +51 -0
- package/dist/ui/dialog.mjs +331 -0
- package/dist/ui/dropdown-menu.d.mts +84 -0
- package/dist/ui/dropdown-menu.mjs +534 -0
- package/dist/ui/field.d.mts +64 -0
- package/dist/ui/field.mjs +425 -0
- package/dist/ui/input-group.d.mts +45 -0
- package/dist/ui/input-group.mjs +254 -0
- package/dist/ui/input.d.mts +11 -0
- package/dist/ui/input.mjs +47 -0
- package/dist/ui/label.d.mts +10 -0
- package/dist/ui/label.mjs +41 -0
- package/dist/ui/scroll-area.d.mts +16 -0
- package/dist/ui/scroll-area.mjs +120 -0
- package/dist/ui/select.d.mts +55 -0
- package/dist/ui/select.mjs +414 -0
- package/dist/ui/separator.d.mts +11 -0
- package/dist/ui/separator.mjs +47 -0
- package/dist/ui/sheet.d.mts +42 -0
- package/dist/ui/sheet.mjs +318 -0
- package/dist/ui/sidebar.d.mts +160 -0
- package/dist/ui/sidebar.mjs +1258 -0
- package/dist/ui/skeleton.d.mts +9 -0
- package/dist/ui/skeleton.mjs +40 -0
- package/dist/ui/table.d.mts +38 -0
- package/dist/ui/table.mjs +269 -0
- package/dist/ui/textarea.d.mts +10 -0
- package/dist/ui/textarea.mjs +41 -0
- package/dist/ui/tooltip.d.mts +25 -0
- package/dist/ui/tooltip.mjs +149 -0
- package/package.json +111 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026-PRESENT Lucas Nørgård
|
|
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,27 @@
|
|
|
1
|
+
# @ucdjs-internal/shared-ui
|
|
2
|
+
|
|
3
|
+
[![npm version][npm-version-src]][npm-version-href]
|
|
4
|
+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
5
|
+
[![codecov][codecov-src]][codecov-href]
|
|
6
|
+
|
|
7
|
+
> [!IMPORTANT]
|
|
8
|
+
> This is an internal package. It may change without warning and is not subject to semantic versioning. Use at your own risk.
|
|
9
|
+
|
|
10
|
+
A collection of shared UI components for UCD.js projects.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @ucdjs-internal/shared-ui
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## 📄 License
|
|
19
|
+
|
|
20
|
+
Published under [MIT License](./LICENSE).
|
|
21
|
+
|
|
22
|
+
[npm-version-src]: https://img.shields.io/npm/v/@ucdjs-internal/shared-ui?style=flat&colorA=18181B&colorB=4169E1
|
|
23
|
+
[npm-version-href]: https://npmjs.com/package/@ucdjs-internal/shared-ui
|
|
24
|
+
[npm-downloads-src]: https://img.shields.io/npm/dm/@ucdjs-internal/shared-ui?style=flat&colorA=18181B&colorB=4169E1
|
|
25
|
+
[npm-downloads-href]: https://npmjs.com/package/@ucdjs-internal/shared-ui
|
|
26
|
+
[codecov-src]: https://img.shields.io/codecov/c/gh/ucdjs/ucd?style=flat&colorA=18181B&colorB=4169E1
|
|
27
|
+
[codecov-href]: https://codecov.io/gh/ucdjs/ucd
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { BundledLanguage, DecorationItem } from "shiki";
|
|
2
|
+
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
3
|
+
|
|
4
|
+
//#region src/components/shiki-code.d.ts
|
|
5
|
+
interface ShikiCodeProps {
|
|
6
|
+
/**
|
|
7
|
+
* The code to highlight
|
|
8
|
+
*/
|
|
9
|
+
code: string;
|
|
10
|
+
/**
|
|
11
|
+
* The language to use for syntax highlighting
|
|
12
|
+
* @default "typescript"
|
|
13
|
+
*/
|
|
14
|
+
language?: BundledLanguage;
|
|
15
|
+
/**
|
|
16
|
+
* Additional CSS class names
|
|
17
|
+
*/
|
|
18
|
+
className?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Additional CSS class names for the `<pre>` element.
|
|
21
|
+
*/
|
|
22
|
+
preClassName?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Additional CSS class names for the `<code>` element.
|
|
25
|
+
*/
|
|
26
|
+
codeClassName?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Shiki decorations for inline annotations/highlights.
|
|
29
|
+
*/
|
|
30
|
+
decorations?: DecorationItem[];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A syntax highlighting component powered by Shiki.
|
|
34
|
+
* Renders code to HTML with syntax highlighting.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```tsx
|
|
38
|
+
* <ShikiCode code="const x = 1;" language="typescript" />
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
declare function ShikiCode({
|
|
42
|
+
code,
|
|
43
|
+
language,
|
|
44
|
+
className,
|
|
45
|
+
preClassName,
|
|
46
|
+
codeClassName,
|
|
47
|
+
decorations
|
|
48
|
+
}: ShikiCodeProps): react_jsx_runtime0.JSX.Element;
|
|
49
|
+
//#endregion
|
|
50
|
+
export { ShikiCode, ShikiCodeProps };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { use, useMemo } from "react";
|
|
2
|
+
import { createJavaScriptRegexEngine } from "shiki";
|
|
3
|
+
import { createCssVariablesTheme, createHighlighterCore } from "shiki/core";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
|
|
6
|
+
//#region src/components/shiki-code.tsx
|
|
7
|
+
const highlighterPromise = createHighlighterCore({
|
|
8
|
+
themes: [createCssVariablesTheme({
|
|
9
|
+
name: "ucd-code",
|
|
10
|
+
variablePrefix: "--shiki-"
|
|
11
|
+
})],
|
|
12
|
+
langs: [
|
|
13
|
+
import("shiki/langs/javascript.mjs"),
|
|
14
|
+
import("shiki/langs/typescript.mjs"),
|
|
15
|
+
import("shiki/langs/json.mjs")
|
|
16
|
+
],
|
|
17
|
+
engine: createJavaScriptRegexEngine()
|
|
18
|
+
});
|
|
19
|
+
/**
|
|
20
|
+
* A syntax highlighting component powered by Shiki.
|
|
21
|
+
* Renders code to HTML with syntax highlighting.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* <ShikiCode code="const x = 1;" language="typescript" />
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
function ShikiCode({ code, language = "typescript", className, preClassName, codeClassName, decorations }) {
|
|
29
|
+
const highlighter = use(highlighterPromise);
|
|
30
|
+
const rootClassName = className ? `shiki-root ${className}` : "shiki-root";
|
|
31
|
+
const preClasses = [
|
|
32
|
+
"shiki",
|
|
33
|
+
"shiki-code",
|
|
34
|
+
preClassName
|
|
35
|
+
].filter((value) => Boolean(value));
|
|
36
|
+
const codeClasses = ["shiki-code__code", codeClassName].filter((value_0) => Boolean(value_0));
|
|
37
|
+
const html = useMemo(() => {
|
|
38
|
+
return highlighter.codeToHtml(code, {
|
|
39
|
+
lang: language,
|
|
40
|
+
theme: "ucd-code",
|
|
41
|
+
rootStyle: false,
|
|
42
|
+
transformers: [{
|
|
43
|
+
name: "shiki:code-theme",
|
|
44
|
+
pre(hast) {
|
|
45
|
+
this.addClassToHast(hast, preClasses);
|
|
46
|
+
hast.properties ||= {};
|
|
47
|
+
hast.properties["data-language"] = this.options.lang;
|
|
48
|
+
},
|
|
49
|
+
code(hast_0) {
|
|
50
|
+
this.addClassToHast(hast_0, codeClasses);
|
|
51
|
+
},
|
|
52
|
+
line(hast_1, line) {
|
|
53
|
+
this.addClassToHast(hast_1, "shiki-code__line");
|
|
54
|
+
hast_1.properties ||= {};
|
|
55
|
+
hast_1.properties["data-line"] = line;
|
|
56
|
+
}
|
|
57
|
+
}],
|
|
58
|
+
decorations
|
|
59
|
+
});
|
|
60
|
+
}, [
|
|
61
|
+
code,
|
|
62
|
+
codeClasses,
|
|
63
|
+
decorations,
|
|
64
|
+
highlighter,
|
|
65
|
+
language,
|
|
66
|
+
preClasses
|
|
67
|
+
]);
|
|
68
|
+
return /* @__PURE__ */ jsx("div", {
|
|
69
|
+
className: rootClassName,
|
|
70
|
+
"data-shiki-root": true,
|
|
71
|
+
dangerouslySetInnerHTML: { __html: html }
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
export { ShikiCode };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { useTheme } from "../hooks/use-theme.mjs";
|
|
2
|
+
import { Button } from "../ui/button.mjs";
|
|
3
|
+
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "../ui/dropdown-menu.mjs";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { c } from "react/compiler-runtime";
|
|
6
|
+
import { Moon, Sun, SunMoon } from "lucide-react";
|
|
7
|
+
|
|
8
|
+
//#region src/components/theme-toggle.tsx
|
|
9
|
+
const labelByTheme = {
|
|
10
|
+
light: "Light",
|
|
11
|
+
dark: "Dark",
|
|
12
|
+
system: "System"
|
|
13
|
+
};
|
|
14
|
+
function ThemeToggle() {
|
|
15
|
+
const $ = c(9);
|
|
16
|
+
const { theme, setTheme, resolvedTheme } = useTheme();
|
|
17
|
+
const Icon = resolvedTheme === "dark" ? Moon : Sun;
|
|
18
|
+
let t0;
|
|
19
|
+
if ($[0] !== Icon) {
|
|
20
|
+
t0 = /* @__PURE__ */ jsx(DropdownMenuTrigger, { render: (props) => /* @__PURE__ */ jsxs(Button, {
|
|
21
|
+
variant: "ghost",
|
|
22
|
+
size: "icon",
|
|
23
|
+
className: "h-7 w-7",
|
|
24
|
+
...props,
|
|
25
|
+
children: [/* @__PURE__ */ jsx(Icon, { className: "h-4 w-4" }), /* @__PURE__ */ jsx("span", {
|
|
26
|
+
className: "sr-only",
|
|
27
|
+
children: "Toggle theme"
|
|
28
|
+
})]
|
|
29
|
+
}) });
|
|
30
|
+
$[0] = Icon;
|
|
31
|
+
$[1] = t0;
|
|
32
|
+
} else t0 = $[1];
|
|
33
|
+
let t1;
|
|
34
|
+
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
|
|
35
|
+
t1 = Object.entries(labelByTheme);
|
|
36
|
+
$[2] = t1;
|
|
37
|
+
} else t1 = $[2];
|
|
38
|
+
let t2;
|
|
39
|
+
if ($[3] !== setTheme || $[4] !== theme) {
|
|
40
|
+
t2 = /* @__PURE__ */ jsx(DropdownMenuContent, {
|
|
41
|
+
align: "end",
|
|
42
|
+
className: "min-w-40",
|
|
43
|
+
children: t1.map((t3) => {
|
|
44
|
+
const [value, label] = t3;
|
|
45
|
+
return /* @__PURE__ */ jsxs(DropdownMenuItem, {
|
|
46
|
+
onClick: () => setTheme(value),
|
|
47
|
+
children: [
|
|
48
|
+
value === "system" ? /* @__PURE__ */ jsx(SunMoon, { className: "mr-2 h-4 w-4" }) : null,
|
|
49
|
+
value === "light" ? /* @__PURE__ */ jsx(Sun, { className: "mr-2 h-4 w-4" }) : null,
|
|
50
|
+
value === "dark" ? /* @__PURE__ */ jsx(Moon, { className: "mr-2 h-4 w-4" }) : null,
|
|
51
|
+
label,
|
|
52
|
+
theme === value ? /* @__PURE__ */ jsx("span", {
|
|
53
|
+
className: "ml-auto text-xs text-muted-foreground",
|
|
54
|
+
children: "Active"
|
|
55
|
+
}) : null
|
|
56
|
+
]
|
|
57
|
+
}, value);
|
|
58
|
+
})
|
|
59
|
+
});
|
|
60
|
+
$[3] = setTheme;
|
|
61
|
+
$[4] = theme;
|
|
62
|
+
$[5] = t2;
|
|
63
|
+
} else t2 = $[5];
|
|
64
|
+
let t3;
|
|
65
|
+
if ($[6] !== t0 || $[7] !== t2) {
|
|
66
|
+
t3 = /* @__PURE__ */ jsxs(DropdownMenu, { children: [t0, t2] });
|
|
67
|
+
$[6] = t0;
|
|
68
|
+
$[7] = t2;
|
|
69
|
+
$[8] = t3;
|
|
70
|
+
} else t3 = $[8];
|
|
71
|
+
return t3;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
//#endregion
|
|
75
|
+
export { ThemeToggle };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { c } from "react/compiler-runtime";
|
|
3
|
+
|
|
4
|
+
//#region src/hooks/use-mobile.ts
|
|
5
|
+
const MOBILE_BREAKPOINT = 768;
|
|
6
|
+
function useIsMobile() {
|
|
7
|
+
const $ = c(3);
|
|
8
|
+
const getIsMobile = _temp;
|
|
9
|
+
let t0;
|
|
10
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
11
|
+
t0 = () => getIsMobile();
|
|
12
|
+
$[0] = t0;
|
|
13
|
+
} else t0 = $[0];
|
|
14
|
+
const [isMobile, setIsMobile] = React.useState(t0);
|
|
15
|
+
let t1;
|
|
16
|
+
let t2;
|
|
17
|
+
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
|
|
18
|
+
t1 = () => {
|
|
19
|
+
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
|
|
20
|
+
const onChange = () => {
|
|
21
|
+
setIsMobile(getIsMobile());
|
|
22
|
+
};
|
|
23
|
+
mql.addEventListener("change", onChange);
|
|
24
|
+
return () => mql.removeEventListener("change", onChange);
|
|
25
|
+
};
|
|
26
|
+
t2 = [];
|
|
27
|
+
$[1] = t1;
|
|
28
|
+
$[2] = t2;
|
|
29
|
+
} else {
|
|
30
|
+
t1 = $[1];
|
|
31
|
+
t2 = $[2];
|
|
32
|
+
}
|
|
33
|
+
React.useEffect(t1, t2);
|
|
34
|
+
return !!isMobile;
|
|
35
|
+
}
|
|
36
|
+
function _temp() {
|
|
37
|
+
return typeof window !== "undefined" ? window.innerWidth < MOBILE_BREAKPOINT : false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
export { useIsMobile };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/hooks/use-theme.d.ts
|
|
2
|
+
type ThemeMode = "light" | "dark" | "system";
|
|
3
|
+
interface UseThemeReturn {
|
|
4
|
+
theme: ThemeMode;
|
|
5
|
+
resolvedTheme: "light" | "dark";
|
|
6
|
+
setTheme: (theme: ThemeMode) => void;
|
|
7
|
+
toggleTheme: () => void;
|
|
8
|
+
}
|
|
9
|
+
declare function useTheme(): UseThemeReturn;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { ThemeMode, UseThemeReturn, useTheme };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { c } from "react/compiler-runtime";
|
|
3
|
+
|
|
4
|
+
//#region src/hooks/use-theme.ts
|
|
5
|
+
const STORAGE_KEY = "theme";
|
|
6
|
+
const DARK_CLASS = "dark";
|
|
7
|
+
function getSystemTheme() {
|
|
8
|
+
if (typeof window === "undefined") return "light";
|
|
9
|
+
return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
10
|
+
}
|
|
11
|
+
function getStoredTheme() {
|
|
12
|
+
if (typeof window === "undefined") return "system";
|
|
13
|
+
const value = window.localStorage.getItem(STORAGE_KEY);
|
|
14
|
+
if (value === "light" || value === "dark" || value === "system") return value;
|
|
15
|
+
return "system";
|
|
16
|
+
}
|
|
17
|
+
function syncTheme(resolved) {
|
|
18
|
+
if (typeof document === "undefined") return;
|
|
19
|
+
document.documentElement.classList.toggle(DARK_CLASS, resolved === "dark");
|
|
20
|
+
document.documentElement.style.colorScheme = resolved;
|
|
21
|
+
}
|
|
22
|
+
function useTheme() {
|
|
23
|
+
const $ = c(11);
|
|
24
|
+
const [theme, setThemeState] = useState(_temp);
|
|
25
|
+
const [systemTheme, setSystemTheme] = useState(_temp2);
|
|
26
|
+
const resolvedTheme = theme === "system" ? systemTheme : theme;
|
|
27
|
+
let t0;
|
|
28
|
+
let t1;
|
|
29
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
30
|
+
t0 = () => {
|
|
31
|
+
if (typeof window === "undefined") return;
|
|
32
|
+
const media = window.matchMedia("(prefers-color-scheme: dark)");
|
|
33
|
+
const handler = () => setSystemTheme(media.matches ? "dark" : "light");
|
|
34
|
+
media.addEventListener("change", handler);
|
|
35
|
+
return () => media.removeEventListener("change", handler);
|
|
36
|
+
};
|
|
37
|
+
t1 = [];
|
|
38
|
+
$[0] = t0;
|
|
39
|
+
$[1] = t1;
|
|
40
|
+
} else {
|
|
41
|
+
t0 = $[0];
|
|
42
|
+
t1 = $[1];
|
|
43
|
+
}
|
|
44
|
+
useEffect(t0, t1);
|
|
45
|
+
let t2;
|
|
46
|
+
let t3;
|
|
47
|
+
if ($[2] !== resolvedTheme || $[3] !== theme) {
|
|
48
|
+
t2 = () => {
|
|
49
|
+
syncTheme(resolvedTheme);
|
|
50
|
+
if (typeof window !== "undefined") window.localStorage.setItem(STORAGE_KEY, theme);
|
|
51
|
+
};
|
|
52
|
+
t3 = [resolvedTheme, theme];
|
|
53
|
+
$[2] = resolvedTheme;
|
|
54
|
+
$[3] = theme;
|
|
55
|
+
$[4] = t2;
|
|
56
|
+
$[5] = t3;
|
|
57
|
+
} else {
|
|
58
|
+
t2 = $[4];
|
|
59
|
+
t3 = $[5];
|
|
60
|
+
}
|
|
61
|
+
useEffect(t2, t3);
|
|
62
|
+
let t4;
|
|
63
|
+
if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
|
|
64
|
+
t4 = (nextTheme) => {
|
|
65
|
+
setThemeState(nextTheme);
|
|
66
|
+
};
|
|
67
|
+
$[6] = t4;
|
|
68
|
+
} else t4 = $[6];
|
|
69
|
+
const setTheme = t4;
|
|
70
|
+
let t5;
|
|
71
|
+
if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
|
|
72
|
+
t5 = () => {
|
|
73
|
+
setThemeState(_temp3);
|
|
74
|
+
};
|
|
75
|
+
$[7] = t5;
|
|
76
|
+
} else t5 = $[7];
|
|
77
|
+
const toggleTheme = t5;
|
|
78
|
+
let t6;
|
|
79
|
+
if ($[8] !== resolvedTheme || $[9] !== theme) {
|
|
80
|
+
t6 = {
|
|
81
|
+
theme,
|
|
82
|
+
resolvedTheme,
|
|
83
|
+
setTheme,
|
|
84
|
+
toggleTheme
|
|
85
|
+
};
|
|
86
|
+
$[8] = resolvedTheme;
|
|
87
|
+
$[9] = theme;
|
|
88
|
+
$[10] = t6;
|
|
89
|
+
} else t6 = $[10];
|
|
90
|
+
return t6;
|
|
91
|
+
}
|
|
92
|
+
function _temp3(current) {
|
|
93
|
+
if (current === "light") return "dark";
|
|
94
|
+
if (current === "dark") return "system";
|
|
95
|
+
return "light";
|
|
96
|
+
}
|
|
97
|
+
function _temp2() {
|
|
98
|
+
return getSystemTheme();
|
|
99
|
+
}
|
|
100
|
+
function _temp() {
|
|
101
|
+
return getStoredTheme();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
//#endregion
|
|
105
|
+
export { useTheme };
|
package/dist/index.d.mts
ADDED
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/lib/theme-script.ts
|
|
2
|
+
const THEME_STORAGE_KEY = "theme";
|
|
3
|
+
function createThemeScript() {
|
|
4
|
+
return `
|
|
5
|
+
(function(){
|
|
6
|
+
try {
|
|
7
|
+
var key = "${THEME_STORAGE_KEY}";
|
|
8
|
+
var stored = localStorage.getItem(key);
|
|
9
|
+
var theme = stored === "light" || stored === "dark" || stored === "system" ? stored : "system";
|
|
10
|
+
var prefersDark = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
11
|
+
var resolved = theme === "system" ? (prefersDark ? "dark" : "light") : theme;
|
|
12
|
+
var root = document.documentElement;
|
|
13
|
+
if (resolved === "dark") {
|
|
14
|
+
root.classList.add("dark");
|
|
15
|
+
root.style.colorScheme = "dark";
|
|
16
|
+
} else {
|
|
17
|
+
root.classList.remove("dark");
|
|
18
|
+
root.style.colorScheme = "light";
|
|
19
|
+
}
|
|
20
|
+
} catch (_) {}
|
|
21
|
+
})();
|
|
22
|
+
`.trim();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
export { THEME_STORAGE_KEY, createThemeScript };
|