@gx-design-vue/context 0.0.2 → 0.0.4

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/README.md CHANGED
@@ -6,5 +6,5 @@ pnpm add @gx-design-vue/context
6
6
 
7
7
  ```ts
8
8
  // 可全局引入,也可以单独引入
9
- import { Gcontext } from '@gx-design-vue/context'
9
+ import { useContext } from '@gx-design-vue/context'
10
10
  ```
@@ -0,0 +1,26 @@
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;
25
+ };
26
+ export { ContextProvider, useContextProvider };
@@ -0,0 +1,7 @@
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>;
7
+ };
package/dist/context.js CHANGED
@@ -1,21 +1,85 @@
1
1
  /*!
2
2
  * Gx Design Pro
3
- * Version: 0.0.1
3
+ * Version: 0.0.3
4
4
  * Author: gx12358
5
5
  * Copyright (C) 2024 gx12358
6
6
  * License: MIT License
7
- * Description: Gx Design context
8
- * Date Created: 2025-11-23
7
+ * Description: Gx Design Context
8
+ * Date Created: 2025-12-14
9
9
  * Homepage:
10
10
  * Contact: gx12358@gmail.com
11
11
  */
12
- import { useContext as d } from "@gx-design-vue/pro-provider";
13
- import { useColorMode as f } from "@vueuse/core";
14
- import { defineComponent as v, ref as h, watch as a, computed as C } from "vue";
15
- const {
16
- provideContext: p,
17
- useInjectContext: x
18
- } = d("theme-provider"), S = /* @__PURE__ */ v({
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({
19
83
  name: "ThemeContext",
20
84
  inheritAttrs: !1,
21
85
  props: {
@@ -38,43 +102,49 @@ const {
38
102
  },
39
103
  emits: ["change", "changeBase", "update:theme"],
40
104
  slots: Object,
41
- setup(m, {
42
- slots: r,
43
- emit: i
105
+ setup(e, {
106
+ slots: n,
107
+ emit: a
44
108
  }) {
45
- const o = document.querySelector("html"), t = h(), n = h(m.theme || m.defaultTheme || "system");
46
- a(() => m.theme, (e) => {
47
- e && (n.value = e);
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);
48
112
  });
49
113
  const {
50
- system: s,
51
- store: l
52
- } = f();
53
- a(() => s.value, () => {
54
- u();
114
+ system: c,
115
+ store: m
116
+ } = D();
117
+ d(() => c.value, () => {
118
+ s();
55
119
  }, {
56
120
  immediate: !0
57
- }), a(() => t.value, (e) => {
58
- e && m.onChangeBase?.(e);
121
+ }), d(() => o.value, (i) => {
122
+ i && e.onChangeBase?.(i);
59
123
  }, {
60
124
  immediate: !0
61
- }), a(n, (e) => {
62
- m.onChange?.(e), i("update:theme", e), u();
125
+ }), d(t, (i) => {
126
+ e.onChange?.(i), a("update:theme", i), s();
63
127
  });
64
- function u() {
65
- o && (n.value === "system" ? (t.value = s.value, o.setAttribute("data-theme", t.value)) : (t.value = n.value, o.setAttribute("data-theme", n.value)), l.value = t.value);
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);
66
130
  }
67
- function c(e) {
68
- n.value = e, u();
131
+ function h(i) {
132
+ t.value = i, s();
69
133
  }
70
- return p({
71
- theme: n,
72
- resolvedTheme: t,
73
- isDark: C(() => t.value === "dark"),
74
- setTheme: c
75
- }), () => r.default();
134
+ return S({
135
+ theme: t,
136
+ resolvedTheme: o,
137
+ isDark: p(() => o.value === "dark"),
138
+ setTheme: h
139
+ }), () => n.default();
76
140
  }
77
141
  });
78
142
  export {
79
- S as ThemeContext
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
80
150
  };
@@ -1,12 +1,12 @@
1
1
  /*!
2
2
  * Gx Design Pro
3
- * Version: 0.0.1
3
+ * Version: 0.0.3
4
4
  * Author: gx12358
5
5
  * Copyright (C) 2024 gx12358
6
6
  * License: MIT License
7
- * Description: Gx Design context
8
- * Date Created: 2025-11-23
7
+ * Description: Gx Design Context
8
+ * Date Created: 2025-12-14
9
9
  * Homepage:
10
10
  * Contact: gx12358@gmail.com
11
11
  */
12
- (function(t,i){typeof exports=="object"&&typeof module<"u"?i(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"],i):(t=typeof globalThis<"u"?globalThis:t||self,i(t.GContext={},t.proProvider,t.core,t.vue))})(this,(function(t,i,h,n){"use strict";const{provideContext:d,useInjectContext:y}=i.useContext("theme-provider"),c=n.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:f,emit:l}){const r=document.querySelector("html"),o=n.ref(),u=n.ref(s.theme||s.defaultTheme||"system");n.watch(()=>s.theme,e=>{e&&(u.value=e)});const{system:a,store:p}=h.useColorMode();n.watch(()=>a.value,()=>{m()},{immediate:!0}),n.watch(()=>o.value,e=>{e&&s.onChangeBase?.(e)},{immediate:!0}),n.watch(u,e=>{s.onChange?.(e),l("update:theme",e),m()});function m(){r&&(u.value==="system"?(o.value=a.value,r.setAttribute("data-theme",o.value)):(o.value=u.value,r.setAttribute("data-theme",u.value)),p.value=o.value)}function v(e){u.value=e,m()}return d({theme:u,resolvedTheme:o,isDark:n.computed(()=>o.value==="dark"),setTheme:v}),()=>f.default()}});t.ThemeContext=c,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})}));
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"})}));
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
- export { default as ThemeContext } from './theme-context';
1
+ export * from './context';
2
+ 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;
@@ -0,0 +1,2 @@
1
+ import type { ThemeProviderContext } from './types';
2
+ export declare const createThemeContext: (value: ThemeProviderContext) => void, useThemeContext: (injectDefaultValue?: ThemeProviderContext | undefined) => ThemeProviderContext;
@@ -1,54 +1,6 @@
1
- import type { ComputedRef, PropType, Ref, SlotsType } 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
- }
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
+ }
@@ -1,4 +1,4 @@
1
- import type { BaseTheme } from './index';
1
+ import type { BaseTheme } from './types';
2
2
  export declare function toggleAnimateTheme(el: HTMLElement, props: {
3
3
  isDark: boolean;
4
4
  setTheme?: (value: BaseTheme) => void;
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@gx-design-vue/context",
3
3
  "type": "module",
4
- "version": "0.0.2",
5
- "description": "Gx Design context",
4
+ "version": "0.0.4",
5
+ "description": "Gx Design Context",
6
6
  "exports": {
7
7
  ".": {
8
8
  "types": "./dist/index.d.ts",
@@ -26,12 +26,11 @@
26
26
  "lint": "TIMING=1 eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore"
27
27
  },
28
28
  "peerDependencies": {
29
- "vue": ">=3.0.0",
30
- "ant-design-vue": "^4.2.6"
29
+ "vue": ">=3.0.0"
31
30
  },
32
31
  "dependencies": {
33
32
  "@vueuse/core": "^14.0.0",
34
- "@gx-design-vue/pro-provider": "^0.1.0-beta.130"
33
+ "@gx-design-vue/pro-utils": "^0.2.0-beta.85"
35
34
  },
36
35
  "devDependencies": {
37
36
  "typescript": "^5.3.3"