@gx-design-vue/context 0.0.4 β†’ 0.0.5-beta.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 gx12358
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 CHANGED
@@ -1,10 +1,76 @@
1
- # context
1
+ <div align="center"><a name="readme-top"></a>
2
2
 
3
- ```shell
3
+ <img height="180" src="https://gx12358.cn/resource/img/favicon.ico">
4
+
5
+ <h1>Context</h1>
6
+
7
+ </div>
8
+
9
+ ## ✨ Features
10
+
11
+ - 🌈 Enterprise-class UI designed for web applications.
12
+ - πŸ“¦ A set of high-quality Vue3 components out of the box.
13
+ - πŸ›‘ Written in TypeScript with predictable static types.
14
+ - βš™οΈ Whole package of design resources and development tools.
15
+ - 🌍 Internationalization support for dozens of languages.
16
+ - 🎨 Powerful theme customization based on CSS-in-JS.
17
+
18
+ ## πŸ–₯ Environment Support
19
+
20
+ - Modern browsers
21
+ - Server-side Rendering
22
+ - [Electron](https://www.electronjs.org/)
23
+
24
+ | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/edge/edge_48x48.png" alt="Edge" width="24px" height="24px" />](https://godban.github.io/browsers-support-badges/)<br>Edge | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png" alt="Firefox" width="24px" height="24px" />](https://godban.github.io/browsers-support-badges/)<br>Firefox | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png" alt="Chrome" width="24px" height="24px" />](https://godban.github.io/browsers-support-badges/)<br>Chrome | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/safari/safari_48x48.png" alt="Safari" width="24px" height="24px" />](https://godban.github.io/browsers-support-badges/)<br>Safari | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/electron/electron_48x48.png" alt="Electron" width="24px" height="24px" />](https://godban.github.io/browsers-support-badges/)<br>Electron |
25
+ | --- | --- | --- | --- | --- |
26
+ | Edge | last 2 versions | last 2 versions | last 2 versions | last 2 versions |
27
+
28
+ ## πŸ“¦ Install
29
+
30
+ ```bash
31
+ npm install @gx-design-vue/context
32
+ ```
33
+
34
+ ```bash
35
+ yarn add @gx-design-vue/context
36
+ ```
37
+
38
+ ```bash
4
39
  pnpm add @gx-design-vue/context
5
40
  ```
6
41
 
7
- ```ts
8
- // 可全局引ε…₯,也可δ»₯单独引ε…₯
9
- import { useContext } from '@gx-design-vue/context'
42
+ ```bash
43
+ bun add @gx-design-vue/context
10
44
  ```
45
+
46
+ ## Acknowledgements
47
+
48
+ Antdv Next is inspired by and built upon the following open-source projects.
49
+
50
+ - [Ant Design](https://ant.design/)
51
+ - [Vue.js](https://vuejs.org/)
52
+ - [Vite](https://vitejs.dev/)
53
+
54
+ ## Maintainer
55
+
56
+ [@gx12358](https://github.com/gx12358/vue3-antd-admin)
57
+
58
+ ## Contributors
59
+
60
+ <a href="https://github.com/gx12358/vue3-antd-admin/graphs/contributors">
61
+ <img alt="Contributors" src="https://contrib.rocks/image?repo=gx12358/vue3-antd-admin" />
62
+ </a>
63
+
64
+ ## Special Thanks
65
+
66
+ Thanks to the [vbenjs/vue-vben-admin](https://github.com/gx12358/vue3-antd-admin) project for providing inspiration and reference implementation.
67
+
68
+ ## License
69
+
70
+ [MIT Β© gx12358-2021](./LICENSE)
71
+
72
+ ## `Star`
73
+
74
+ Thank you very much for the stars from kind-hearted people, thank you for your support :heart:
75
+
76
+ [![Stargazers repo roster for @gx12358/vue3-antd-admin](https://bytecrank.com/nastyox/reporoster/php/stargazersSVG.php?user=gx12358&repo=vue3-antd-admin)](https://github.com/gx12358/vue3-antd-admin/stargazers)
@@ -1,26 +1,18 @@
1
- import type { PropType, SlotsType } from 'vue';
2
- declare const ContextProvider: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
3
- contextKey: {
4
- type: PropType<string>;
5
- required: true;
6
- };
7
- value: {
8
- type: PropType<any>;
9
- required: true;
10
- };
11
- }>, () => any, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
12
- contextKey: {
13
- type: PropType<string>;
14
- required: true;
15
- };
16
- value: {
17
- type: PropType<any>;
18
- required: true;
19
- };
20
- }>> & Readonly<{}>, {}, SlotsType<{
21
- default: any;
22
- }>, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
23
- declare const useContextProvider: <T = any>(contextInjectKey: string, defaultValue?: T) => T & {
24
- contextId: string;
1
+ import * as vue0 from "vue";
2
+ import { SlotsType } from "vue";
3
+ import { EmptyEmit } from "@gx-design-vue/pro-utils";
4
+
5
+ //#region src/context/ContextProvider.d.ts
6
+ interface ContextProviderProps {
7
+ contextKey: string;
8
+ value: any;
9
+ }
10
+ interface ContextProviderSlots {
11
+ default?: () => any;
12
+ }
13
+ declare const ContextProvider: vue0.DefineSetupFnComponent<ContextProviderProps, EmptyEmit, SlotsType<ContextProviderSlots>, ContextProviderProps, vue0.PublicProps>;
14
+ declare function useContextProvider<T = any>(contextInjectKey: string, defaultValue?: T): T & {
15
+ contextId: string;
25
16
  };
26
- export { ContextProvider, useContextProvider };
17
+ //#endregion
18
+ export { ContextProvider, ContextProviderSlots, useContextProvider };
@@ -0,0 +1,34 @@
1
+ import { defineComponent, inject, provide, toRefs } from "vue";
2
+ import { getRandomNumber, isObject } from "@gx-design-vue/pro-utils";
3
+
4
+ //#region src/context/ContextProvider.tsx
5
+ let contextId = null;
6
+ function updateContextKey(key) {
7
+ if (contextId) return contextId;
8
+ contextId = Symbol(key);
9
+ return contextId;
10
+ }
11
+ const ContextProvider = /* @__PURE__ */ defineComponent((props, { slots }) => {
12
+ if (props.contextKey && props.value && isObject(props.value)) provide(updateContextKey(props.contextKey), {
13
+ ...toRefs(props.value),
14
+ contextId: `${props.contextKey}-${getRandomNumber().uuid(10)}`
15
+ });
16
+ else console.warn("[ContextProvider]: contextKey is required");
17
+ return () => slots.default?.();
18
+ }, { props: {
19
+ contextKey: {
20
+ type: String,
21
+ required: true,
22
+ default: void 0
23
+ },
24
+ value: {
25
+ required: true,
26
+ default: void 0
27
+ }
28
+ } });
29
+ function useContextProvider(contextInjectKey, defaultValue) {
30
+ if (typeof contextId === "symbol") return inject(updateContextKey(contextInjectKey), defaultValue || {});
31
+ }
32
+
33
+ //#endregion
34
+ export { ContextProvider, useContextProvider };
@@ -1,7 +1,10 @@
1
- import type { InjectionKey } from 'vue';
2
- export * from './ContextProvider';
3
- export declare function useContext<T>(key: string, defaultValue?: T): {
4
- provideContext: (value: T) => void;
5
- useInjectContext: (injectDefaultValue?: T) => T;
6
- contextInjectKey: InjectionKey<T>;
1
+ import { InjectionKey } from "vue";
2
+
3
+ //#region src/context/index.d.ts
4
+ declare function useContext<T>(key: string, defaultValue?: T): {
5
+ provideContext: (value: T) => void;
6
+ useInjectContext: (injectDefaultValue?: T) => T;
7
+ contextInjectKey: InjectionKey<T>;
7
8
  };
9
+ //#endregion
10
+ export { useContext };
@@ -0,0 +1,20 @@
1
+ import { inject, provide } from "vue";
2
+
3
+ //#region src/context/index.ts
4
+ function useContext(key, defaultValue) {
5
+ const contextInjectKey = Symbol(key);
6
+ const provideContext = (value) => {
7
+ provide(contextInjectKey, value);
8
+ };
9
+ const useInjectContext = (injectDefaultValue) => {
10
+ return inject(contextInjectKey, injectDefaultValue || defaultValue || {});
11
+ };
12
+ return {
13
+ provideContext,
14
+ useInjectContext,
15
+ contextInjectKey
16
+ };
17
+ }
18
+
19
+ //#endregion
20
+ export { useContext };
package/dist/context.js CHANGED
@@ -1,150 +1 @@
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
- import { defineComponent as y, provide as x, toRefs as C, inject as v, nextTick as T, ref as f, watch as d, computed as p } from "vue";
13
- import { isObject as k, getRandomNumber as w } from "@gx-design-vue/pro-utils";
14
- import { useDark as b, useToggle as j, useColorMode as D } from "@vueuse/core";
15
- let u = null;
16
- function g(e) {
17
- return u || (u = Symbol(e), u);
18
- }
19
- const P = /* @__PURE__ */ y({
20
- name: "ContextProvider",
21
- inheritAttrs: !1,
22
- props: {
23
- contextKey: {
24
- type: [String],
25
- required: !0
26
- },
27
- value: {
28
- type: Object,
29
- required: !0
30
- }
31
- },
32
- slots: Object,
33
- setup(e, {
34
- slots: n
35
- }) {
36
- return e.contextKey && e.value && k(e.value) ? x(g(e.contextKey), {
37
- ...C(e.value),
38
- contextId: `${e.contextKey}-${w().uuid(10)}`
39
- }) : console.warn("[ContextProvider]: contextKey is required"), () => n.default?.();
40
- }
41
- }), q = (e, n) => {
42
- if (typeof u == "symbol")
43
- return v(g(e), n || {});
44
- };
45
- function K(e, n) {
46
- const a = Symbol(e);
47
- return {
48
- provideContext: (t) => {
49
- x(a, t);
50
- },
51
- useInjectContext: (t) => v(a, t || n || {}),
52
- contextInjectKey: a
53
- };
54
- }
55
- const { provideContext: S, useInjectContext: B } = K("theme-provider"), A = b({
56
- storageKey: "gx-pro-theme-appearance"
57
- }), O = j(A);
58
- function F(e, n) {
59
- if (!(document.startViewTransition && !window.matchMedia("(prefers-reduced-motion: reduce)").matches)) {
60
- n.setTheme?.(n.isDark ? "dark" : "light");
61
- return;
62
- }
63
- const r = e.getBoundingClientRect(), o = r.left + r.width / 2, t = r.top + r.height / 2, c = Math.hypot(Math.max(o, innerWidth - o), Math.max(t, innerHeight - t)), m = 100 * o / innerWidth, s = 100 * t / innerHeight, h = Math.hypot(innerWidth, innerHeight) / Math.SQRT2, i = 100 * c / h;
64
- document.startViewTransition(async () => {
65
- n.setTheme?.(n.isDark ? "dark" : "light"), await T();
66
- }).ready.then(() => {
67
- const l = [
68
- `circle(0% at ${m}% ${s}%)`,
69
- `circle(${i}% at ${m}% ${s}%)`
70
- ];
71
- document.documentElement.animate({
72
- clipPath: n.isDark ? [...l].reverse() : l
73
- }, {
74
- duration: 400,
75
- // δΏζŒζœ€η»ˆηŠΆζ€
76
- fill: "forwards",
77
- easing: "ease-in",
78
- pseudoElement: n.isDark ? "::view-transition-old(root)" : "::view-transition-new(root)"
79
- });
80
- });
81
- }
82
- const H = /* @__PURE__ */ y({
83
- name: "ThemeContext",
84
- inheritAttrs: !1,
85
- props: {
86
- theme: {
87
- type: String
88
- },
89
- defaultTheme: {
90
- type: String,
91
- default: "system"
92
- },
93
- onChange: {
94
- type: Function
95
- },
96
- "onUpdate:theme": {
97
- type: Function
98
- },
99
- onChangeBase: {
100
- type: Function
101
- }
102
- },
103
- emits: ["change", "changeBase", "update:theme"],
104
- slots: Object,
105
- setup(e, {
106
- slots: n,
107
- emit: a
108
- }) {
109
- const r = document.querySelector("html"), o = f(), t = f(e.theme || e.defaultTheme || "system");
110
- d(() => e.theme, (i) => {
111
- i && (t.value = i);
112
- });
113
- const {
114
- system: c,
115
- store: m
116
- } = D();
117
- d(() => c.value, () => {
118
- s();
119
- }, {
120
- immediate: !0
121
- }), d(() => o.value, (i) => {
122
- i && e.onChangeBase?.(i);
123
- }, {
124
- immediate: !0
125
- }), d(t, (i) => {
126
- e.onChange?.(i), a("update:theme", i), s();
127
- });
128
- function s() {
129
- r && (t.value === "system" ? (o.value = c.value, r.setAttribute("data-theme", o.value)) : (o.value = t.value, r.setAttribute("data-theme", t.value)), m.value = o.value);
130
- }
131
- function h(i) {
132
- t.value = i, s();
133
- }
134
- return S({
135
- theme: t,
136
- resolvedTheme: o,
137
- isDark: p(() => o.value === "dark"),
138
- setTheme: h
139
- }), () => n.default();
140
- }
141
- });
142
- export {
143
- P as ContextProvider,
144
- H as ThemeContext,
145
- F as toggleAnimateTheme,
146
- O as toggleDark,
147
- K as useContext,
148
- q as useContextProvider,
149
- B as useThemeContext
150
- };
1
+ (function(e,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):(e=typeof globalThis<`u`?globalThis:e||self,t(e.Context={},e.vue,e._gx_design_vue_pro_utils,e._vueuse_core))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function i(e,n){let r=Symbol(e);return{provideContext:e=>{(0,t.provide)(r,e)},useInjectContext:e=>(0,t.inject)(r,e||n||{}),contextInjectKey:r}}var a=null;function o(e){return a||(a=Symbol(e),a)}var s=(0,t.defineComponent)((e,{slots:r})=>(e.contextKey&&e.value&&(0,n.isObject)(e.value)?(0,t.provide)(o(e.contextKey),{...(0,t.toRefs)(e.value),contextId:`${e.contextKey}-${(0,n.getRandomNumber)().uuid(10)}`}):console.warn(`[ContextProvider]: contextKey is required`),()=>r.default?.()),{props:{contextKey:{type:String,required:!0,default:void 0},value:{required:!0,default:void 0}}});function c(e,n){if(typeof a==`symbol`)return(0,t.inject)(o(e),n||{})}let{provideContext:l,useInjectContext:u}=i(`theme-provider`),d=(0,r.useDark)({storageKey:`gx-pro-theme-appearance`}),f=(0,r.useToggle)(d);var p=(0,t.defineComponent)((e,{slots:n,emit:i})=>{let a=document.querySelector(`html`),o=(0,t.ref)(),s=(0,t.ref)(e.theme||e.defaultTheme||`system`);(0,t.watch)(()=>e.theme,e=>{e&&(s.value=e)});let{system:c,store:u}=(0,r.useColorMode)();(0,t.watch)(()=>c.value,()=>{d()},{immediate:!0}),(0,t.watch)(()=>o.value,t=>{t&&e.onChangeBase?.(t)},{immediate:!0}),(0,t.watch)(s,t=>{e.onChange?.(t),i(`update:theme`,t),d()});function d(){a&&(s.value===`system`?(o.value=c.value,a.setAttribute(`data-theme`,o.value)):(o.value=s.value,a.setAttribute(`data-theme`,s.value)),u.value=o.value)}function f(e){s.value=e,d()}return l({theme:s,resolvedTheme:o,isDark:(0,t.computed)(()=>o.value===`dark`),setTheme:f}),()=>n.default?.()},{emits:[`change`,`changeBase`,`update:theme`],props:(0,t.mergeDefaults)({theme:{type:String,required:!1,default:void 0},defaultTheme:{type:String,required:!1,default:void 0},onChange:{type:Function,required:!1,default:void 0},onChangeBase:{type:Function,required:!1,default:void 0},onUpdateTheme:{type:Function,required:!1,default:void 0}},{defaultTheme:`system`}),name:`ThemeContext`,inheritAttrs:!1});function m(e,n){if(!(document.startViewTransition&&!window.matchMedia(`(prefers-reduced-motion: reduce)`).matches)){n.setTheme?.(n.isDark?`dark`:`light`);return}let r=e.getBoundingClientRect(),i=r.left+r.width/2,a=r.top+r.height/2,o=Math.hypot(Math.max(i,innerWidth-i),Math.max(a,innerHeight-a)),s=100*i/innerWidth,c=100*a/innerHeight,l=Math.hypot(innerWidth,innerHeight)/Math.SQRT2,u=100*o/l;document.startViewTransition(async()=>{n.setTheme?.(n.isDark?`dark`:`light`),await(0,t.nextTick)()}).ready.then(()=>{let e=[`circle(0% at ${s}% ${c}%)`,`circle(${u}% at ${s}% ${c}%)`];document.documentElement.animate({clipPath:n.isDark?[...e].reverse():e},{duration:400,fill:`forwards`,easing:`ease-in`,pseudoElement:n.isDark?`::view-transition-old(root)`:`::view-transition-new(root)`})})}e.ContextProvider=s,e.ThemeContext=p,e.toggleAnimateTheme=m,e.toggleDark=f,e.useContext=i,e.useContextProvider=c,e.useThemeContext=u});
package/dist/index.d.ts CHANGED
@@ -1,2 +1,9 @@
1
- export * from './context';
2
- export * from './theme-context';
1
+ import { ContextProvider, useContextProvider } from "./context/ContextProvider.js";
2
+ import { useContext } from "./context/index.js";
3
+ import { BaseTheme, ThemeProviderContext, ThemeValue } from "./theme-context/types.js";
4
+ import { useThemeContext } from "./theme-context/context.js";
5
+ import { toggleDark } from "./theme-context/dark.js";
6
+ import ThemeContext from "./theme-context/ThemeContext.js";
7
+ import { toggleAnimateTheme } from "./theme-context/utils.js";
8
+ import "./theme-context/index.js";
9
+ export { BaseTheme, ContextProvider, ThemeContext, ThemeProviderContext, ThemeValue, toggleAnimateTheme, toggleDark, useContext, useContextProvider, useThemeContext };
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 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, toggleAnimateTheme, toggleDark, useContext, useContextProvider, useThemeContext };
@@ -1,46 +1,23 @@
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
+ import { BaseTheme, ThemeValue } from "./types.js";
2
+ import * as vue1 from "vue";
3
+ import { 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 ThemeContext: vue1.DefineSetupFnComponent<ThemeContextProps, ThemeContextEmits, SlotsType<ThemeContextSlots>, ThemeContextProps, vue1.PublicProps>;
22
+ //#endregion
23
+ export { ThemeContextEmits, ThemeContextSlots, ThemeContext as default };
@@ -0,0 +1,87 @@
1
+ import { createThemeContext } from "./context.js";
2
+ import { computed, defineComponent, mergeDefaults, ref, watch } from "vue";
3
+ import { useColorMode } from "@vueuse/core";
4
+
5
+ //#region src/theme-context/ThemeContext.tsx
6
+ const ThemeContext = /* @__PURE__ */ defineComponent((props, { slots, emit }) => {
7
+ const html = document.querySelector("html");
8
+ const theme = ref();
9
+ const systemTheme = ref(props.theme || props.defaultTheme || "system");
10
+ watch(() => props.theme, (val) => {
11
+ if (val) systemTheme.value = val;
12
+ });
13
+ const { system, store } = useColorMode();
14
+ watch(() => system.value, () => {
15
+ updateSystemThem();
16
+ }, { immediate: true });
17
+ watch(() => theme.value, (val) => {
18
+ if (val) props.onChangeBase?.(val);
19
+ }, { immediate: true });
20
+ watch(systemTheme, (val) => {
21
+ props.onChange?.(val);
22
+ emit("update:theme", val);
23
+ updateSystemThem();
24
+ });
25
+ function updateSystemThem() {
26
+ if (html) {
27
+ if (systemTheme.value === "system") {
28
+ theme.value = system.value;
29
+ html.setAttribute("data-theme", theme.value);
30
+ } else {
31
+ theme.value = systemTheme.value;
32
+ html.setAttribute("data-theme", systemTheme.value);
33
+ }
34
+ store.value = theme.value;
35
+ }
36
+ }
37
+ function setTheme(val) {
38
+ systemTheme.value = val;
39
+ updateSystemThem();
40
+ }
41
+ createThemeContext({
42
+ theme: systemTheme,
43
+ resolvedTheme: theme,
44
+ isDark: computed(() => theme.value === "dark"),
45
+ setTheme
46
+ });
47
+ return () => slots.default?.();
48
+ }, {
49
+ emits: [
50
+ "change",
51
+ "changeBase",
52
+ "update:theme"
53
+ ],
54
+ props: /* @__PURE__ */ mergeDefaults({
55
+ theme: {
56
+ type: String,
57
+ required: false,
58
+ default: void 0
59
+ },
60
+ defaultTheme: {
61
+ type: String,
62
+ required: false,
63
+ default: void 0
64
+ },
65
+ onChange: {
66
+ type: Function,
67
+ required: false,
68
+ default: void 0
69
+ },
70
+ onChangeBase: {
71
+ type: Function,
72
+ required: false,
73
+ default: void 0
74
+ },
75
+ onUpdateTheme: {
76
+ type: Function,
77
+ required: false,
78
+ default: void 0
79
+ }
80
+ }, { defaultTheme: "system" }),
81
+ name: "ThemeContext",
82
+ inheritAttrs: false
83
+ });
84
+ var ThemeContext_default = ThemeContext;
85
+
86
+ //#endregion
87
+ export { ThemeContext_default as default };
@@ -1,2 +1,6 @@
1
- import type { ThemeProviderContext } from './types';
2
- export declare const createThemeContext: (value: ThemeProviderContext) => void, useThemeContext: (injectDefaultValue?: ThemeProviderContext | undefined) => ThemeProviderContext;
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 | undefined) => 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
- export declare const isDark: import("vue").WritableComputedRef<boolean, boolean>;
2
- export declare const toggleDark: (value?: boolean | undefined) => boolean;
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 | undefined) => boolean;
6
+ //#endregion
7
+ export { isDark, toggleDark };
@@ -0,0 +1,8 @@
1
+ import { useDark, useToggle } from "@vueuse/core";
2
+
3
+ //#region src/theme-context/dark.ts
4
+ const isDark = useDark({ storageKey: "gx-pro-theme-appearance" });
5
+ const toggleDark = useToggle(isDark);
6
+
7
+ //#endregion
8
+ export { isDark, toggleDark };
@@ -1,6 +1,6 @@
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';
1
+ import { BaseTheme, ThemeProviderContext, ThemeValue } from "./types.js";
2
+ import { useThemeContext } from "./context.js";
3
+ import { toggleDark } from "./dark.js";
4
+ import ThemeContext from "./ThemeContext.js";
5
+ import { toggleAnimateTheme } from "./utils.js";
6
+ export { BaseTheme, ThemeContext, ThemeProviderContext, ThemeValue, toggleAnimateTheme, toggleDark, useThemeContext };
@@ -0,0 +1,6 @@
1
+ import { useThemeContext } from "./context.js";
2
+ import { toggleDark } from "./dark.js";
3
+ import ThemeContext_default from "./ThemeContext.js";
4
+ import { toggleAnimateTheme } from "./utils.js";
5
+
6
+ export { ThemeContext_default as ThemeContext, toggleAnimateTheme, toggleDark, useThemeContext };
@@ -1,9 +1,13 @@
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;
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 type { BaseTheme } from './types';
2
- export declare function toggleAnimateTheme(el: HTMLElement, props: {
3
- isDark: boolean;
4
- setTheme?: (value: BaseTheme) => void;
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
@@ -0,0 +1,8 @@
1
+ export {}
2
+
3
+ declare module 'vue' {
4
+ export interface GlobalComponents {
5
+ ThemeContext: typeof import('@gx-design-vue/context')['ThemeContext']
6
+ ContextProvider: typeof import('@gx-design-vue/context')['ContextProvider']
7
+ }
8
+ }
package/package.json CHANGED
@@ -1,41 +1,66 @@
1
1
  {
2
2
  "name": "@gx-design-vue/context",
3
3
  "type": "module",
4
- "version": "0.0.4",
4
+ "version": "0.0.5-beta.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/context.js",
10
- "require": "./dist/context.umd.cjs"
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
- "main": "./dist/context.umd.cjs",
14
- "module": "./dist/context.js",
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"
39
+ "contributes": {
40
+ "html": {
41
+ "customData": [
42
+ "./web-tags.json"
43
+ ]
44
+ }
27
45
  },
28
46
  "peerDependencies": {
29
- "vue": ">=3.0.0"
47
+ "vue": ">=3.2.0"
30
48
  },
31
49
  "dependencies": {
32
- "@vueuse/core": "^14.0.0",
33
- "@gx-design-vue/pro-utils": "^0.2.0-beta.85"
34
- },
35
- "devDependencies": {
36
- "typescript": "^5.3.3"
50
+ "@vueuse/core": "^14.2.0",
51
+ "@gx-design-vue/pro-utils": "0.2.0-beta.90"
37
52
  },
38
- "authors": [
39
- "gx12358 <gx12358@gmail.com> (https://github.com/gx12358)"
40
- ]
41
- }
53
+ "web-types": "web-types.json",
54
+ "browserslist": [
55
+ "> 1%",
56
+ "not ie 11",
57
+ "not op_mini all"
58
+ ],
59
+ "scripts": {
60
+ "test": "vitest run",
61
+ "build": "run-s build:esm build:umd",
62
+ "build:esm": "tsdown",
63
+ "build:umd": "vite build",
64
+ "prepublish": "pnpm build"
65
+ }
66
+ }
@@ -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"})}));