@gx-design-vue/context 0.0.2 → 0.0.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/dist/context.js +54 -27
- package/dist/context.umd.cjs +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/theme-context/ThemeContext.d.ts +46 -0
- package/dist/theme-context/context.d.ts +2 -0
- package/dist/theme-context/index.d.ts +6 -54
- package/dist/theme-context/types.d.ts +9 -0
- package/dist/theme-context/utils.d.ts +1 -1
- package/package.json +1 -1
package/dist/context.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* Gx Design Pro
|
|
3
|
-
* Version: 0.0.
|
|
3
|
+
* Version: 0.0.2
|
|
4
4
|
* Author: gx12358
|
|
5
5
|
* Copyright (C) 2024 gx12358
|
|
6
6
|
* License: MIT License
|
|
@@ -9,13 +9,37 @@
|
|
|
9
9
|
* Homepage:
|
|
10
10
|
* Contact: gx12358@gmail.com
|
|
11
11
|
*/
|
|
12
|
-
import { useContext as
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
const {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
import { useContext as g } from "@gx-design-vue/pro-provider";
|
|
13
|
+
import { useDark as f, useToggle as T, useColorMode as y } from "@vueuse/core";
|
|
14
|
+
import { nextTick as v, defineComponent as p, ref as l, watch as h, computed as C } from "vue";
|
|
15
|
+
const { provideContext: x, useInjectContext: R } = g("theme-provider"), k = f({
|
|
16
|
+
storageKey: "gx-pro-theme-appearance"
|
|
17
|
+
}), S = T(k);
|
|
18
|
+
function $(o, a) {
|
|
19
|
+
if (!(document.startViewTransition && !window.matchMedia("(prefers-reduced-motion: reduce)").matches)) {
|
|
20
|
+
a.setTheme?.(a.isDark ? "dark" : "light");
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const i = o.getBoundingClientRect(), t = i.left + i.width / 2, n = i.top + i.height / 2, s = Math.hypot(Math.max(t, innerWidth - t), Math.max(n, innerHeight - n)), m = 100 * t / innerWidth, r = 100 * n / innerHeight, c = Math.hypot(innerWidth, innerHeight) / Math.SQRT2, e = 100 * s / c;
|
|
24
|
+
document.startViewTransition(async () => {
|
|
25
|
+
a.setTheme?.(a.isDark ? "dark" : "light"), await v();
|
|
26
|
+
}).ready.then(() => {
|
|
27
|
+
const d = [
|
|
28
|
+
`circle(0% at ${m}% ${r}%)`,
|
|
29
|
+
`circle(${e}% at ${m}% ${r}%)`
|
|
30
|
+
];
|
|
31
|
+
document.documentElement.animate({
|
|
32
|
+
clipPath: a.isDark ? [...d].reverse() : d
|
|
33
|
+
}, {
|
|
34
|
+
duration: 400,
|
|
35
|
+
// 保持最终状态
|
|
36
|
+
fill: "forwards",
|
|
37
|
+
easing: "ease-in",
|
|
38
|
+
pseudoElement: a.isDark ? "::view-transition-old(root)" : "::view-transition-new(root)"
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
const B = /* @__PURE__ */ p({
|
|
19
43
|
name: "ThemeContext",
|
|
20
44
|
inheritAttrs: !1,
|
|
21
45
|
props: {
|
|
@@ -38,43 +62,46 @@ const {
|
|
|
38
62
|
},
|
|
39
63
|
emits: ["change", "changeBase", "update:theme"],
|
|
40
64
|
slots: Object,
|
|
41
|
-
setup(
|
|
42
|
-
slots:
|
|
43
|
-
emit:
|
|
65
|
+
setup(o, {
|
|
66
|
+
slots: a,
|
|
67
|
+
emit: u
|
|
44
68
|
}) {
|
|
45
|
-
const
|
|
46
|
-
|
|
69
|
+
const i = document.querySelector("html"), t = l(), n = l(o.theme || o.defaultTheme || "system");
|
|
70
|
+
h(() => o.theme, (e) => {
|
|
47
71
|
e && (n.value = e);
|
|
48
72
|
});
|
|
49
73
|
const {
|
|
50
74
|
system: s,
|
|
51
|
-
store:
|
|
52
|
-
} =
|
|
53
|
-
|
|
54
|
-
|
|
75
|
+
store: m
|
|
76
|
+
} = y();
|
|
77
|
+
h(() => s.value, () => {
|
|
78
|
+
r();
|
|
55
79
|
}, {
|
|
56
80
|
immediate: !0
|
|
57
|
-
}),
|
|
58
|
-
e &&
|
|
81
|
+
}), h(() => t.value, (e) => {
|
|
82
|
+
e && o.onChangeBase?.(e);
|
|
59
83
|
}, {
|
|
60
84
|
immediate: !0
|
|
61
|
-
}),
|
|
62
|
-
|
|
85
|
+
}), h(n, (e) => {
|
|
86
|
+
o.onChange?.(e), u("update:theme", e), r();
|
|
63
87
|
});
|
|
64
|
-
function
|
|
65
|
-
|
|
88
|
+
function r() {
|
|
89
|
+
i && (n.value === "system" ? (t.value = s.value, i.setAttribute("data-theme", t.value)) : (t.value = n.value, i.setAttribute("data-theme", n.value)), m.value = t.value);
|
|
66
90
|
}
|
|
67
91
|
function c(e) {
|
|
68
|
-
n.value = e,
|
|
92
|
+
n.value = e, r();
|
|
69
93
|
}
|
|
70
|
-
return
|
|
94
|
+
return x({
|
|
71
95
|
theme: n,
|
|
72
96
|
resolvedTheme: t,
|
|
73
97
|
isDark: C(() => t.value === "dark"),
|
|
74
98
|
setTheme: c
|
|
75
|
-
}), () =>
|
|
99
|
+
}), () => a.default();
|
|
76
100
|
}
|
|
77
101
|
});
|
|
78
102
|
export {
|
|
79
|
-
|
|
103
|
+
B as ThemeContext,
|
|
104
|
+
$ as toggleAnimateTheme,
|
|
105
|
+
S as toggleDark,
|
|
106
|
+
R as useThemeContext
|
|
80
107
|
};
|
package/dist/context.umd.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* Gx Design Pro
|
|
3
|
-
* Version: 0.0.
|
|
3
|
+
* Version: 0.0.2
|
|
4
4
|
* Author: gx12358
|
|
5
5
|
* Copyright (C) 2024 gx12358
|
|
6
6
|
* License: MIT License
|
|
@@ -9,4 +9,4 @@
|
|
|
9
9
|
* Homepage:
|
|
10
10
|
* Contact: gx12358@gmail.com
|
|
11
11
|
*/
|
|
12
|
-
(function(
|
|
12
|
+
(function(e,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("@gx-design-vue/pro-provider"),require("@vueuse/core"),require("vue")):typeof define=="function"&&define.amd?define(["exports","@gx-design-vue/pro-provider","@vueuse/core","vue"],h):(e=typeof globalThis<"u"?globalThis:e||self,h(e.GContext={},e.proProvider,e.core,e.vue))})(this,(function(e,h,d,a){"use strict";const{provideContext:T,useInjectContext:y}=h.useContext("theme-provider"),p=d.useDark({storageKey:"gx-pro-theme-appearance"}),v=d.useToggle(p);function C(s,o){if(!(document.startViewTransition&&!window.matchMedia("(prefers-reduced-motion: reduce)").matches)){o.setTheme?.(o.isDark?"dark":"light");return}const r=s.getBoundingClientRect(),n=r.left+r.width/2,i=r.top+r.height/2,c=Math.hypot(Math.max(n,innerWidth-n),Math.max(i,innerHeight-i)),m=100*n/innerWidth,u=100*i/innerHeight,l=Math.hypot(innerWidth,innerHeight)/Math.SQRT2,t=100*c/l;document.startViewTransition(async()=>{o.setTheme?.(o.isDark?"dark":"light"),await a.nextTick()}).ready.then(()=>{const g=[`circle(0% at ${m}% ${u}%)`,`circle(${t}% at ${m}% ${u}%)`];document.documentElement.animate({clipPath:o.isDark?[...g].reverse():g},{duration:400,fill:"forwards",easing:"ease-in",pseudoElement:o.isDark?"::view-transition-old(root)":"::view-transition-new(root)"})})}const x=a.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(s,{slots:o,emit:f}){const r=document.querySelector("html"),n=a.ref(),i=a.ref(s.theme||s.defaultTheme||"system");a.watch(()=>s.theme,t=>{t&&(i.value=t)});const{system:c,store:m}=d.useColorMode();a.watch(()=>c.value,()=>{u()},{immediate:!0}),a.watch(()=>n.value,t=>{t&&s.onChangeBase?.(t)},{immediate:!0}),a.watch(i,t=>{s.onChange?.(t),f("update:theme",t),u()});function u(){r&&(i.value==="system"?(n.value=c.value,r.setAttribute("data-theme",n.value)):(n.value=i.value,r.setAttribute("data-theme",i.value)),m.value=n.value)}function l(t){i.value=t,u()}return T({theme:i,resolvedTheme:n,isDark:a.computed(()=>n.value==="dark"),setTheme:l}),()=>o.default()}});e.ThemeContext=x,e.toggleAnimateTheme=C,e.toggleDark=v,e.useThemeContext=y,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './theme-context';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { PropType, SlotsType } from 'vue';
|
|
2
|
+
import type { BaseTheme, ThemeValue } from './types';
|
|
3
|
+
declare const ThemeContext: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
4
|
+
theme: {
|
|
5
|
+
type: PropType<ThemeValue>;
|
|
6
|
+
};
|
|
7
|
+
defaultTheme: {
|
|
8
|
+
type: PropType<ThemeValue>;
|
|
9
|
+
default: string;
|
|
10
|
+
};
|
|
11
|
+
onChange: {
|
|
12
|
+
type: PropType<(theme: ThemeValue) => void>;
|
|
13
|
+
};
|
|
14
|
+
'onUpdate:theme': {
|
|
15
|
+
type: PropType<(theme: ThemeValue) => void>;
|
|
16
|
+
};
|
|
17
|
+
onChangeBase: {
|
|
18
|
+
type: PropType<(theme: BaseTheme) => void>;
|
|
19
|
+
};
|
|
20
|
+
}>, () => void, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("change" | "changeBase" | "update:theme")[], "change" | "changeBase" | "update:theme", import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
21
|
+
theme: {
|
|
22
|
+
type: PropType<ThemeValue>;
|
|
23
|
+
};
|
|
24
|
+
defaultTheme: {
|
|
25
|
+
type: PropType<ThemeValue>;
|
|
26
|
+
default: string;
|
|
27
|
+
};
|
|
28
|
+
onChange: {
|
|
29
|
+
type: PropType<(theme: ThemeValue) => void>;
|
|
30
|
+
};
|
|
31
|
+
'onUpdate:theme': {
|
|
32
|
+
type: PropType<(theme: ThemeValue) => void>;
|
|
33
|
+
};
|
|
34
|
+
onChangeBase: {
|
|
35
|
+
type: PropType<(theme: BaseTheme) => void>;
|
|
36
|
+
};
|
|
37
|
+
}>> & Readonly<{
|
|
38
|
+
onChange?: ((...args: any[]) => any) | undefined;
|
|
39
|
+
"onUpdate:theme"?: ((...args: any[]) => any) | undefined;
|
|
40
|
+
onChangeBase?: ((...args: any[]) => any) | undefined;
|
|
41
|
+
}>, {
|
|
42
|
+
defaultTheme: ThemeValue;
|
|
43
|
+
}, SlotsType<{
|
|
44
|
+
default(): void;
|
|
45
|
+
}>, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
46
|
+
export default ThemeContext;
|
|
@@ -1,54 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
isDark: ComputedRef<boolean>;
|
|
8
|
-
setTheme: (theme: ThemeValue) => void;
|
|
9
|
-
}
|
|
10
|
-
export declare const createThemeContext: (value: ThemeProviderContext) => void, useThemeContext: (injectDefaultValue?: ThemeProviderContext | undefined) => ThemeProviderContext;
|
|
11
|
-
declare const ThemeContext: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
12
|
-
theme: {
|
|
13
|
-
type: PropType<ThemeValue>;
|
|
14
|
-
};
|
|
15
|
-
defaultTheme: {
|
|
16
|
-
type: PropType<ThemeValue>;
|
|
17
|
-
default: string;
|
|
18
|
-
};
|
|
19
|
-
onChange: {
|
|
20
|
-
type: PropType<(theme: ThemeValue) => void>;
|
|
21
|
-
};
|
|
22
|
-
'onUpdate:theme': {
|
|
23
|
-
type: PropType<(theme: ThemeValue) => void>;
|
|
24
|
-
};
|
|
25
|
-
onChangeBase: {
|
|
26
|
-
type: PropType<(theme: BaseTheme) => void>;
|
|
27
|
-
};
|
|
28
|
-
}>, () => void, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("change" | "changeBase" | "update:theme")[], "change" | "changeBase" | "update:theme", import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
29
|
-
theme: {
|
|
30
|
-
type: PropType<ThemeValue>;
|
|
31
|
-
};
|
|
32
|
-
defaultTheme: {
|
|
33
|
-
type: PropType<ThemeValue>;
|
|
34
|
-
default: string;
|
|
35
|
-
};
|
|
36
|
-
onChange: {
|
|
37
|
-
type: PropType<(theme: ThemeValue) => void>;
|
|
38
|
-
};
|
|
39
|
-
'onUpdate:theme': {
|
|
40
|
-
type: PropType<(theme: ThemeValue) => void>;
|
|
41
|
-
};
|
|
42
|
-
onChangeBase: {
|
|
43
|
-
type: PropType<(theme: BaseTheme) => void>;
|
|
44
|
-
};
|
|
45
|
-
}>> & Readonly<{
|
|
46
|
-
onChange?: ((...args: any[]) => any) | undefined;
|
|
47
|
-
"onUpdate:theme"?: ((...args: any[]) => any) | undefined;
|
|
48
|
-
onChangeBase?: ((...args: any[]) => any) | undefined;
|
|
49
|
-
}>, {
|
|
50
|
-
defaultTheme: ThemeValue;
|
|
51
|
-
}, SlotsType<{
|
|
52
|
-
default(): void;
|
|
53
|
-
}>, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
54
|
-
export default ThemeContext;
|
|
1
|
+
import { useThemeContext } from './context';
|
|
2
|
+
import { toggleDark } from './dark';
|
|
3
|
+
export { toggleDark, useThemeContext };
|
|
4
|
+
export * from './utils';
|
|
5
|
+
export * from './types';
|
|
6
|
+
export { default as ThemeContext } from './ThemeContext';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ComputedRef, Ref } from 'vue';
|
|
2
|
+
export type BaseTheme = 'light' | 'dark';
|
|
3
|
+
export type ThemeValue = 'light' | 'dark' | 'system';
|
|
4
|
+
export interface ThemeProviderContext {
|
|
5
|
+
theme: Ref<ThemeValue>;
|
|
6
|
+
resolvedTheme: Ref<BaseTheme>;
|
|
7
|
+
isDark: ComputedRef<boolean>;
|
|
8
|
+
setTheme: (theme: ThemeValue) => void;
|
|
9
|
+
}
|