@gx-design-vue/context 0.0.4 → 0.0.5-alpha.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/LICENSE +21 -0
- package/README.md +71 -5
- package/dist/context/ContextProvider.d.ts +44 -25
- package/dist/context/ContextProvider.js +39 -0
- package/dist/context/index.d.ts +9 -6
- package/dist/context/index.js +20 -0
- package/dist/context.esm.js +506 -0
- package/dist/context.js +1 -150
- package/dist/index.d.ts +9 -2
- package/dist/index.js +9 -0
- package/dist/theme-context/ThemeContext.d.ts +77 -46
- package/dist/theme-context/ThemeContext.js +68 -0
- package/dist/theme-context/context.d.ts +6 -2
- package/dist/theme-context/context.js +7 -0
- package/dist/theme-context/dark.d.ts +7 -2
- package/dist/theme-context/dark.js +8 -0
- package/dist/theme-context/index.d.ts +6 -6
- package/dist/theme-context/index.js +6 -0
- package/dist/theme-context/types.d.ts +12 -8
- package/dist/theme-context/types.js +1 -0
- package/dist/theme-context/utils.d.ts +8 -4
- package/dist/theme-context/utils.js +32 -0
- package/global.d.ts +8 -0
- package/package.json +46 -27
- package/dist/context.umd.cjs +0 -12
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useContext } from "./context/index.js";
|
|
2
|
+
import { ContextProvider, useContextProvider } from "./context/ContextProvider.js";
|
|
3
|
+
import { useThemeContext } from "./theme-context/context.js";
|
|
4
|
+
import { toggleDark } from "./theme-context/dark.js";
|
|
5
|
+
import ThemeContext_default, { themeContextProps } from "./theme-context/ThemeContext.js";
|
|
6
|
+
import { toggleAnimateTheme } from "./theme-context/utils.js";
|
|
7
|
+
import "./theme-context/index.js";
|
|
8
|
+
|
|
9
|
+
export { ContextProvider, ThemeContext_default as ThemeContext, themeContextProps, toggleAnimateTheme, toggleDark, useContext, useContextProvider, useThemeContext };
|
|
@@ -1,46 +1,77 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
1
|
+
import { BaseTheme, ThemeValue } from "./types.js";
|
|
2
|
+
import * as vue0 from "vue";
|
|
3
|
+
import { PropType, SlotsType } from "vue";
|
|
4
|
+
|
|
5
|
+
//#region src/theme-context/ThemeContext.d.ts
|
|
6
|
+
interface ThemeContextProps {
|
|
7
|
+
theme?: ThemeValue;
|
|
8
|
+
defaultTheme?: ThemeValue;
|
|
9
|
+
onChange?: (theme: ThemeValue) => void;
|
|
10
|
+
onChangeBase?: (theme: BaseTheme) => void;
|
|
11
|
+
onUpdateTheme?: (theme: ThemeValue) => void;
|
|
12
|
+
}
|
|
13
|
+
interface ThemeContextEmits {
|
|
14
|
+
change: (value: ThemeValue) => void;
|
|
15
|
+
changeBase: (value: BaseTheme) => void;
|
|
16
|
+
'update:theme': (value: ThemeValue) => void;
|
|
17
|
+
}
|
|
18
|
+
interface ThemeContextSlots {
|
|
19
|
+
default?: () => any;
|
|
20
|
+
}
|
|
21
|
+
declare const themeContextProps: {
|
|
22
|
+
theme: {
|
|
23
|
+
type: PropType<ThemeValue>;
|
|
24
|
+
};
|
|
25
|
+
defaultTheme: {
|
|
26
|
+
type: PropType<ThemeValue>;
|
|
27
|
+
default: string;
|
|
28
|
+
};
|
|
29
|
+
onChange: {
|
|
30
|
+
type: PropType<(theme: ThemeValue) => void>;
|
|
31
|
+
};
|
|
32
|
+
onChangeBase: {
|
|
33
|
+
type: PropType<(theme: BaseTheme) => void>;
|
|
34
|
+
};
|
|
35
|
+
onUpdateTheme: {
|
|
36
|
+
type: PropType<(theme: ThemeValue) => void>;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
declare const ThemeContext: vue0.DefineComponent<vue0.ExtractPropTypes<{
|
|
40
|
+
theme: {
|
|
41
|
+
type: PropType<ThemeValue>;
|
|
42
|
+
};
|
|
43
|
+
defaultTheme: {
|
|
44
|
+
type: PropType<ThemeValue>;
|
|
45
|
+
default: string;
|
|
46
|
+
};
|
|
47
|
+
onChange: {
|
|
48
|
+
type: PropType<(theme: ThemeValue) => void>;
|
|
49
|
+
};
|
|
50
|
+
onChangeBase: {
|
|
51
|
+
type: PropType<(theme: BaseTheme) => void>;
|
|
52
|
+
};
|
|
53
|
+
onUpdateTheme: {
|
|
54
|
+
type: PropType<(theme: ThemeValue) => void>;
|
|
55
|
+
};
|
|
56
|
+
}>, () => any, {}, {}, {}, vue0.ComponentOptionsMixin, vue0.ComponentOptionsMixin, {}, string, vue0.PublicProps, Readonly<vue0.ExtractPropTypes<{
|
|
57
|
+
theme: {
|
|
58
|
+
type: PropType<ThemeValue>;
|
|
59
|
+
};
|
|
60
|
+
defaultTheme: {
|
|
61
|
+
type: PropType<ThemeValue>;
|
|
62
|
+
default: string;
|
|
63
|
+
};
|
|
64
|
+
onChange: {
|
|
65
|
+
type: PropType<(theme: ThemeValue) => void>;
|
|
66
|
+
};
|
|
67
|
+
onChangeBase: {
|
|
68
|
+
type: PropType<(theme: BaseTheme) => void>;
|
|
69
|
+
};
|
|
70
|
+
onUpdateTheme: {
|
|
71
|
+
type: PropType<(theme: ThemeValue) => void>;
|
|
72
|
+
};
|
|
73
|
+
}>> & Readonly<{}>, {
|
|
74
|
+
defaultTheme: ThemeValue;
|
|
75
|
+
}, SlotsType<ThemeContextSlots>, {}, {}, string, vue0.ComponentProvideOptions, true, {}, any>;
|
|
76
|
+
//#endregion
|
|
77
|
+
export { ThemeContextEmits, ThemeContextProps, ThemeContextSlots, ThemeContext as default, themeContextProps };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { createThemeContext } from "./context.js";
|
|
2
|
+
import { computed, defineComponent, ref, watch } from "vue";
|
|
3
|
+
import { useColorMode } from "@vueuse/core";
|
|
4
|
+
|
|
5
|
+
//#region src/theme-context/ThemeContext.tsx
|
|
6
|
+
const themeContextProps = {
|
|
7
|
+
theme: { type: String },
|
|
8
|
+
defaultTheme: {
|
|
9
|
+
type: String,
|
|
10
|
+
default: "system"
|
|
11
|
+
},
|
|
12
|
+
onChange: { type: Function },
|
|
13
|
+
onChangeBase: { type: Function },
|
|
14
|
+
onUpdateTheme: { type: Function }
|
|
15
|
+
};
|
|
16
|
+
const ThemeContext = /* @__PURE__ */ defineComponent({
|
|
17
|
+
name: "ThemeContext",
|
|
18
|
+
inheritAttrs: false,
|
|
19
|
+
props: themeContextProps,
|
|
20
|
+
slots: Object,
|
|
21
|
+
setup: (props, { slots, emit }) => {
|
|
22
|
+
const html = document.querySelector("html");
|
|
23
|
+
const theme = ref();
|
|
24
|
+
const systemTheme = ref(props.theme || props.defaultTheme || "system");
|
|
25
|
+
watch(() => props.theme, (val) => {
|
|
26
|
+
if (val) systemTheme.value = val;
|
|
27
|
+
});
|
|
28
|
+
const { system, store } = useColorMode();
|
|
29
|
+
watch(() => system.value, () => {
|
|
30
|
+
updateSystemThem();
|
|
31
|
+
}, { immediate: true });
|
|
32
|
+
watch(() => theme.value, (val) => {
|
|
33
|
+
if (val) props.onChangeBase?.(val);
|
|
34
|
+
}, { immediate: true });
|
|
35
|
+
watch(systemTheme, (val) => {
|
|
36
|
+
props.onChange?.(val);
|
|
37
|
+
emit("update:theme", val);
|
|
38
|
+
updateSystemThem();
|
|
39
|
+
});
|
|
40
|
+
function updateSystemThem() {
|
|
41
|
+
if (html) {
|
|
42
|
+
if (systemTheme.value === "system") {
|
|
43
|
+
theme.value = system.value;
|
|
44
|
+
html.setAttribute("data-theme", theme.value);
|
|
45
|
+
} else {
|
|
46
|
+
theme.value = systemTheme.value;
|
|
47
|
+
html.setAttribute("data-theme", systemTheme.value);
|
|
48
|
+
}
|
|
49
|
+
store.value = theme.value;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function setTheme(val) {
|
|
53
|
+
systemTheme.value = val;
|
|
54
|
+
updateSystemThem();
|
|
55
|
+
}
|
|
56
|
+
createThemeContext({
|
|
57
|
+
theme: systemTheme,
|
|
58
|
+
resolvedTheme: theme,
|
|
59
|
+
isDark: computed(() => theme.value === "dark"),
|
|
60
|
+
setTheme
|
|
61
|
+
});
|
|
62
|
+
return () => slots.default?.();
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
var ThemeContext_default = ThemeContext;
|
|
66
|
+
|
|
67
|
+
//#endregion
|
|
68
|
+
export { ThemeContext_default as default, themeContextProps };
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { ThemeProviderContext } from "./types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/theme-context/context.d.ts
|
|
4
|
+
declare const createThemeContext: (value: ThemeProviderContext) => void, useThemeContext: (injectDefaultValue?: ThemeProviderContext) => ThemeProviderContext;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { createThemeContext, useThemeContext };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { useContext } from "../context/index.js";
|
|
2
|
+
|
|
3
|
+
//#region src/theme-context/context.ts
|
|
4
|
+
const { provideContext: createThemeContext, useInjectContext: useThemeContext } = useContext("theme-provider");
|
|
5
|
+
|
|
6
|
+
//#endregion
|
|
7
|
+
export { createThemeContext, useThemeContext };
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import * as _vueuse_core0 from "@vueuse/core";
|
|
2
|
+
|
|
3
|
+
//#region src/theme-context/dark.d.ts
|
|
4
|
+
declare const isDark: _vueuse_core0.UseDarkReturn;
|
|
5
|
+
declare const toggleDark: (value?: boolean) => boolean;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { isDark, toggleDark };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export {
|
|
1
|
+
import { BaseTheme, ThemeProviderContext, ThemeValue } from "./types.js";
|
|
2
|
+
import { useThemeContext } from "./context.js";
|
|
3
|
+
import { toggleDark } from "./dark.js";
|
|
4
|
+
import ThemeContext, { ThemeContextEmits, ThemeContextProps, ThemeContextSlots, themeContextProps } from "./ThemeContext.js";
|
|
5
|
+
import { toggleAnimateTheme } from "./utils.js";
|
|
6
|
+
export { BaseTheme, ThemeContext, ThemeContextEmits, ThemeContextProps, ThemeContextSlots, ThemeProviderContext, ThemeValue, themeContextProps, toggleAnimateTheme, toggleDark, useThemeContext };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { useThemeContext } from "./context.js";
|
|
2
|
+
import { toggleDark } from "./dark.js";
|
|
3
|
+
import ThemeContext_default, { themeContextProps } from "./ThemeContext.js";
|
|
4
|
+
import { toggleAnimateTheme } from "./utils.js";
|
|
5
|
+
|
|
6
|
+
export { ThemeContext_default as ThemeContext, themeContextProps, toggleAnimateTheme, toggleDark, useThemeContext };
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { ComputedRef, Ref } from "vue";
|
|
2
|
+
|
|
3
|
+
//#region src/theme-context/types.d.ts
|
|
4
|
+
type BaseTheme = 'light' | 'dark';
|
|
5
|
+
type ThemeValue = 'light' | 'dark' | 'system';
|
|
6
|
+
interface ThemeProviderContext {
|
|
7
|
+
theme: Ref<ThemeValue>;
|
|
8
|
+
resolvedTheme: Ref<BaseTheme>;
|
|
9
|
+
isDark: ComputedRef<boolean>;
|
|
10
|
+
setTheme: (theme: ThemeValue) => void;
|
|
9
11
|
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { BaseTheme, ThemeProviderContext, ThemeValue };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { BaseTheme } from "./types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/theme-context/utils.d.ts
|
|
4
|
+
declare function toggleAnimateTheme(el: HTMLElement, props: {
|
|
5
|
+
isDark: boolean;
|
|
6
|
+
setTheme?: (value: BaseTheme) => void;
|
|
5
7
|
}): void;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { toggleAnimateTheme };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { nextTick } from "vue";
|
|
2
|
+
|
|
3
|
+
//#region src/theme-context/utils.ts
|
|
4
|
+
function toggleAnimateTheme(el, props) {
|
|
5
|
+
if (!(document.startViewTransition && !window.matchMedia("(prefers-reduced-motion: reduce)").matches)) {
|
|
6
|
+
props.setTheme?.(props.isDark ? "dark" : "light");
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const rect = el.getBoundingClientRect();
|
|
10
|
+
const x = rect.left + rect.width / 2;
|
|
11
|
+
const y = rect.top + rect.height / 2;
|
|
12
|
+
const endRadius = Math.hypot(Math.max(x, innerWidth - x), Math.max(y, innerHeight - y));
|
|
13
|
+
const ratioX = 100 * x / innerWidth;
|
|
14
|
+
const ratioY = 100 * y / innerHeight;
|
|
15
|
+
const referR = Math.hypot(innerWidth, innerHeight) / Math.SQRT2;
|
|
16
|
+
const ratioR = 100 * endRadius / referR;
|
|
17
|
+
document.startViewTransition(async () => {
|
|
18
|
+
props.setTheme?.(props.isDark ? "dark" : "light");
|
|
19
|
+
await nextTick();
|
|
20
|
+
}).ready.then(() => {
|
|
21
|
+
const clipPath = [`circle(0% at ${ratioX}% ${ratioY}%)`, `circle(${ratioR}% at ${ratioX}% ${ratioY}%)`];
|
|
22
|
+
document.documentElement.animate({ clipPath: props.isDark ? [...clipPath].reverse() : clipPath }, {
|
|
23
|
+
duration: 400,
|
|
24
|
+
fill: "forwards",
|
|
25
|
+
easing: "ease-in",
|
|
26
|
+
pseudoElement: props.isDark ? "::view-transition-old(root)" : "::view-transition-new(root)"
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
export { toggleAnimateTheme };
|
package/global.d.ts
ADDED
package/package.json
CHANGED
|
@@ -1,41 +1,60 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gx-design-vue/context",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.5-alpha.1",
|
|
5
5
|
"description": "Gx Design Context",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "gx12358",
|
|
8
|
+
"email": "gx12358@gmail.com",
|
|
9
|
+
"url": "https://github.com/gx12358"
|
|
10
|
+
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/gx12358/pro-components-next.git",
|
|
15
|
+
"directory": "packages/context"
|
|
16
|
+
},
|
|
6
17
|
"exports": {
|
|
7
18
|
".": {
|
|
8
19
|
"types": "./dist/index.d.ts",
|
|
9
|
-
"import": "./dist/
|
|
10
|
-
"
|
|
11
|
-
}
|
|
20
|
+
"import": "./dist/index.js",
|
|
21
|
+
"default": "./dist/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./dist/*": {
|
|
24
|
+
"types": "./dist/*.d.ts",
|
|
25
|
+
"import": "./dist/*.js",
|
|
26
|
+
"default": "./dist/*.js"
|
|
27
|
+
},
|
|
28
|
+
"./global.d.ts": "./global.d.ts",
|
|
29
|
+
"./global": "./global.d.ts",
|
|
30
|
+
"./package.json": "./package.json"
|
|
12
31
|
},
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"types": "./dist",
|
|
32
|
+
"unpkg": "dist/context.js",
|
|
33
|
+
"jsdelivr": "dist/context.js",
|
|
16
34
|
"files": [
|
|
17
|
-
"dist"
|
|
35
|
+
"dist",
|
|
36
|
+
"global.d.ts",
|
|
37
|
+
"package.json"
|
|
18
38
|
],
|
|
19
|
-
"scripts": {
|
|
20
|
-
"dev": "vite",
|
|
21
|
-
"build": "vite build",
|
|
22
|
-
"types": "vue-tsc --declaration --emitDeclarationOnly",
|
|
23
|
-
"preview": "vite preview --port 5050",
|
|
24
|
-
"test:unit": "vitest --environment jsdom",
|
|
25
|
-
"typecheck": "vue-tsc --noEmit && vue-tsc --noEmit -p tsconfig.vitest.json --composite false",
|
|
26
|
-
"lint": "TIMING=1 eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore"
|
|
27
|
-
},
|
|
28
39
|
"peerDependencies": {
|
|
29
|
-
"vue": ">=3.
|
|
40
|
+
"vue": ">=3.2.0"
|
|
30
41
|
},
|
|
31
42
|
"dependencies": {
|
|
32
|
-
"@vueuse/core": "^14.
|
|
33
|
-
"@gx-design-vue/pro-utils": "
|
|
43
|
+
"@vueuse/core": "^14.2.0",
|
|
44
|
+
"@gx-design-vue/pro-utils": "0.2.0-alpha.1"
|
|
34
45
|
},
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
46
|
+
"browserslist": [
|
|
47
|
+
"> 1%",
|
|
48
|
+
"not ie 11",
|
|
49
|
+
"not op_mini all"
|
|
50
|
+
],
|
|
51
|
+
"scripts": {
|
|
52
|
+
"test": "vitest run",
|
|
53
|
+
"build": "run-s build:esm build:vite:parallel",
|
|
54
|
+
"build:esm": "tsdown",
|
|
55
|
+
"build:vite:parallel": "run-p build:umd build:full-esm",
|
|
56
|
+
"build:full-esm": "vite build --config ./vite.esm.config.ts",
|
|
57
|
+
"build:umd": "vite build",
|
|
58
|
+
"prepublish": "pnpm build"
|
|
59
|
+
}
|
|
60
|
+
}
|
package/dist/context.umd.cjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Gx Design Pro
|
|
3
|
-
* Version: 0.0.3
|
|
4
|
-
* Author: gx12358
|
|
5
|
-
* Copyright (C) 2024 gx12358
|
|
6
|
-
* License: MIT License
|
|
7
|
-
* Description: Gx Design Context
|
|
8
|
-
* Date Created: 2025-12-14
|
|
9
|
-
* Homepage:
|
|
10
|
-
* Contact: gx12358@gmail.com
|
|
11
|
-
*/
|
|
12
|
-
(function(n,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue"),require("@gx-design-vue/pro-utils"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","vue","@gx-design-vue/pro-utils","@vueuse/core"],t):(n=typeof globalThis<"u"?globalThis:n||self,t(n.GContext={},n.vue,n.proUtils,n.core))})(this,(function(n,t,y,l){"use strict";let d=null;function g(e){return d||(d=Symbol(e),d)}const T=t.defineComponent({name:"ContextProvider",inheritAttrs:!1,props:{contextKey:{type:[String],required:!0},value:{type:Object,required:!0}},slots:Object,setup(e,{slots:o}){return e.contextKey&&e.value&&y.isObject(e.value)?t.provide(g(e.contextKey),{...t.toRefs(e.value),contextId:`${e.contextKey}-${y.getRandomNumber().uuid(10)}`}):console.warn("[ContextProvider]: contextKey is required"),()=>o.default?.()}}),v=(e,o)=>{if(typeof d=="symbol")return t.inject(g(e),o||{})};function x(e,o){const u=Symbol(e);return{provideContext:i=>{t.provide(u,i)},useInjectContext:i=>t.inject(u,i||o||{}),contextInjectKey:u}}const{provideContext:p,useInjectContext:w}=x("theme-provider"),k=l.useDark({storageKey:"gx-pro-theme-appearance"}),j=l.useToggle(k);function b(e,o){if(!(document.startViewTransition&&!window.matchMedia("(prefers-reduced-motion: reduce)").matches)){o.setTheme?.(o.isDark?"dark":"light");return}const s=e.getBoundingClientRect(),r=s.left+s.width/2,i=s.top+s.height/2,m=Math.hypot(Math.max(r,innerWidth-r),Math.max(i,innerHeight-i)),h=100*r/innerWidth,c=100*i/innerHeight,f=Math.hypot(innerWidth,innerHeight)/Math.SQRT2,a=100*m/f;document.startViewTransition(async()=>{o.setTheme?.(o.isDark?"dark":"light"),await t.nextTick()}).ready.then(()=>{const C=[`circle(0% at ${h}% ${c}%)`,`circle(${a}% at ${h}% ${c}%)`];document.documentElement.animate({clipPath:o.isDark?[...C].reverse():C},{duration:400,fill:"forwards",easing:"ease-in",pseudoElement:o.isDark?"::view-transition-old(root)":"::view-transition-new(root)"})})}const S=t.defineComponent({name:"ThemeContext",inheritAttrs:!1,props:{theme:{type:String},defaultTheme:{type:String,default:"system"},onChange:{type:Function},"onUpdate:theme":{type:Function},onChangeBase:{type:Function}},emits:["change","changeBase","update:theme"],slots:Object,setup(e,{slots:o,emit:u}){const s=document.querySelector("html"),r=t.ref(),i=t.ref(e.theme||e.defaultTheme||"system");t.watch(()=>e.theme,a=>{a&&(i.value=a)});const{system:m,store:h}=l.useColorMode();t.watch(()=>m.value,()=>{c()},{immediate:!0}),t.watch(()=>r.value,a=>{a&&e.onChangeBase?.(a)},{immediate:!0}),t.watch(i,a=>{e.onChange?.(a),u("update:theme",a),c()});function c(){s&&(i.value==="system"?(r.value=m.value,s.setAttribute("data-theme",r.value)):(r.value=i.value,s.setAttribute("data-theme",i.value)),h.value=r.value)}function f(a){i.value=a,c()}return p({theme:i,resolvedTheme:r,isDark:t.computed(()=>r.value==="dark"),setTheme:f}),()=>o.default()}});n.ContextProvider=T,n.ThemeContext=S,n.toggleAnimateTheme=b,n.toggleDark=j,n.useContext=x,n.useContextProvider=v,n.useThemeContext=w,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})}));
|