@gx-design-vue/context 0.0.3 → 0.0.5

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,6 @@
1
+ import type { InjectionKey } from 'vue';
2
+ export declare function useContext<T>(key: string, defaultValue?: T): {
3
+ provideContext: (value: T) => void;
4
+ useInjectContext: (injectDefaultValue?: T) => T;
5
+ contextInjectKey: InjectionKey<T>;
6
+ };
package/dist/context.js CHANGED
@@ -1,45 +1,84 @@
1
1
  /*!
2
2
  * Gx Design Pro
3
- * Version: 0.0.2
3
+ * Version: 0.0.4
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 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({
12
+ import { provide as y, inject as x, defineComponent as v, toRefs as C, 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
+ function K(e, n) {
16
+ const a = Symbol(e);
17
+ return {
18
+ provideContext: (t) => {
19
+ y(a, t);
20
+ },
21
+ useInjectContext: (t) => x(a, t || n || {}),
22
+ contextInjectKey: a
23
+ };
24
+ }
25
+ let u = null;
26
+ function g(e) {
27
+ return u || (u = Symbol(e), u);
28
+ }
29
+ const P = /* @__PURE__ */ v({
30
+ name: "ContextProvider",
31
+ inheritAttrs: !1,
32
+ props: {
33
+ contextKey: {
34
+ type: [String],
35
+ required: !0
36
+ },
37
+ value: {
38
+ type: Object,
39
+ required: !0
40
+ }
41
+ },
42
+ slots: Object,
43
+ setup(e, {
44
+ slots: n
45
+ }) {
46
+ return e.contextKey && e.value && k(e.value) ? y(g(e.contextKey), {
47
+ ...C(e.value),
48
+ contextId: `${e.contextKey}-${w().uuid(10)}`
49
+ }) : console.warn("[ContextProvider]: contextKey is required"), () => n.default?.();
50
+ }
51
+ }), q = (e, n) => {
52
+ if (typeof u == "symbol")
53
+ return x(g(e), n || {});
54
+ }, { provideContext: S, useInjectContext: B } = K("theme-provider"), A = b({
16
55
  storageKey: "gx-pro-theme-appearance"
17
- }), S = T(k);
18
- function $(o, a) {
56
+ }), O = j(A);
57
+ function F(e, n) {
19
58
  if (!(document.startViewTransition && !window.matchMedia("(prefers-reduced-motion: reduce)").matches)) {
20
- a.setTheme?.(a.isDark ? "dark" : "light");
59
+ n.setTheme?.(n.isDark ? "dark" : "light");
21
60
  return;
22
61
  }
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;
62
+ 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;
24
63
  document.startViewTransition(async () => {
25
- a.setTheme?.(a.isDark ? "dark" : "light"), await v();
64
+ n.setTheme?.(n.isDark ? "dark" : "light"), await T();
26
65
  }).ready.then(() => {
27
- const d = [
28
- `circle(0% at ${m}% ${r}%)`,
29
- `circle(${e}% at ${m}% ${r}%)`
66
+ const l = [
67
+ `circle(0% at ${m}% ${s}%)`,
68
+ `circle(${i}% at ${m}% ${s}%)`
30
69
  ];
31
70
  document.documentElement.animate({
32
- clipPath: a.isDark ? [...d].reverse() : d
71
+ clipPath: n.isDark ? [...l].reverse() : l
33
72
  }, {
34
73
  duration: 400,
35
74
  // 保持最终状态
36
75
  fill: "forwards",
37
76
  easing: "ease-in",
38
- pseudoElement: a.isDark ? "::view-transition-old(root)" : "::view-transition-new(root)"
77
+ pseudoElement: n.isDark ? "::view-transition-old(root)" : "::view-transition-new(root)"
39
78
  });
40
79
  });
41
80
  }
42
- const B = /* @__PURE__ */ p({
81
+ const H = /* @__PURE__ */ v({
43
82
  name: "ThemeContext",
44
83
  inheritAttrs: !1,
45
84
  props: {
@@ -62,46 +101,49 @@ const B = /* @__PURE__ */ p({
62
101
  },
63
102
  emits: ["change", "changeBase", "update:theme"],
64
103
  slots: Object,
65
- setup(o, {
66
- slots: a,
67
- emit: u
104
+ setup(e, {
105
+ slots: n,
106
+ emit: a
68
107
  }) {
69
- const i = document.querySelector("html"), t = l(), n = l(o.theme || o.defaultTheme || "system");
70
- h(() => o.theme, (e) => {
71
- e && (n.value = e);
108
+ const r = document.querySelector("html"), o = f(), t = f(e.theme || e.defaultTheme || "system");
109
+ d(() => e.theme, (i) => {
110
+ i && (t.value = i);
72
111
  });
73
112
  const {
74
- system: s,
113
+ system: c,
75
114
  store: m
76
- } = y();
77
- h(() => s.value, () => {
78
- r();
115
+ } = D();
116
+ d(() => c.value, () => {
117
+ s();
79
118
  }, {
80
119
  immediate: !0
81
- }), h(() => t.value, (e) => {
82
- e && o.onChangeBase?.(e);
120
+ }), d(() => o.value, (i) => {
121
+ i && e.onChangeBase?.(i);
83
122
  }, {
84
123
  immediate: !0
85
- }), h(n, (e) => {
86
- o.onChange?.(e), u("update:theme", e), r();
124
+ }), d(t, (i) => {
125
+ e.onChange?.(i), a("update:theme", i), s();
87
126
  });
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);
127
+ function s() {
128
+ 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);
90
129
  }
91
- function c(e) {
92
- n.value = e, r();
130
+ function h(i) {
131
+ t.value = i, s();
93
132
  }
94
- return x({
95
- theme: n,
96
- resolvedTheme: t,
97
- isDark: C(() => t.value === "dark"),
98
- setTheme: c
99
- }), () => a.default();
133
+ return S({
134
+ theme: t,
135
+ resolvedTheme: o,
136
+ isDark: p(() => o.value === "dark"),
137
+ setTheme: h
138
+ }), () => n.default();
100
139
  }
101
140
  });
102
141
  export {
103
- B as ThemeContext,
104
- $ as toggleAnimateTheme,
105
- S as toggleDark,
106
- R as useThemeContext
142
+ P as ContextProvider,
143
+ H as ThemeContext,
144
+ F as toggleAnimateTheme,
145
+ O as toggleDark,
146
+ K as useContext,
147
+ q as useContextProvider,
148
+ B as useThemeContext
107
149
  };
@@ -1,12 +1,12 @@
1
1
  /*!
2
2
  * Gx Design Pro
3
- * Version: 0.0.2
3
+ * Version: 0.0.4
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(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"})}));
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.Context={},n.vue,n.proUtils,n.core))})(this,(function(n,t,y,l){"use strict";function g(e,o){const u=Symbol(e);return{provideContext:i=>{t.provide(u,i)},useInjectContext:i=>t.inject(u,i||o||{}),contextInjectKey:u}}let d=null;function x(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(x(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(x(e),o||{})},{provideContext:p,useInjectContext:w}=g("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=g,n.useContextProvider=v,n.useThemeContext=w,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})}));
package/dist/index.d.ts CHANGED
@@ -1 +1,4 @@
1
+ import { useContext } from './context';
2
+ import { ContextProvider, useContextProvider } from './context/ContextProvider';
1
3
  export * from './theme-context';
4
+ export { ContextProvider, useContext, useContextProvider };
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.3",
5
- "description": "Gx Design context",
4
+ "version": "0.0.5",
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"