@gx-design-vue/context 0.0.4 → 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.
@@ -1,5 +1,4 @@
1
1
  import type { InjectionKey } from 'vue';
2
- export * from './ContextProvider';
3
2
  export declare function useContext<T>(key: string, defaultValue?: T): {
4
3
  provideContext: (value: T) => void;
5
4
  useInjectContext: (injectDefaultValue?: T) => T;
package/dist/context.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * Gx Design Pro
3
- * Version: 0.0.3
3
+ * Version: 0.0.4
4
4
  * Author: gx12358
5
5
  * Copyright (C) 2024 gx12358
6
6
  * License: MIT License
@@ -9,14 +9,24 @@
9
9
  * Homepage:
10
10
  * Contact: gx12358@gmail.com
11
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";
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
13
  import { isObject as k, getRandomNumber as w } from "@gx-design-vue/pro-utils";
14
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
+ }
15
25
  let u = null;
16
26
  function g(e) {
17
27
  return u || (u = Symbol(e), u);
18
28
  }
19
- const P = /* @__PURE__ */ y({
29
+ const P = /* @__PURE__ */ v({
20
30
  name: "ContextProvider",
21
31
  inheritAttrs: !1,
22
32
  props: {
@@ -33,26 +43,15 @@ const P = /* @__PURE__ */ y({
33
43
  setup(e, {
34
44
  slots: n
35
45
  }) {
36
- return e.contextKey && e.value && k(e.value) ? x(g(e.contextKey), {
46
+ return e.contextKey && e.value && k(e.value) ? y(g(e.contextKey), {
37
47
  ...C(e.value),
38
48
  contextId: `${e.contextKey}-${w().uuid(10)}`
39
49
  }) : console.warn("[ContextProvider]: contextKey is required"), () => n.default?.();
40
50
  }
41
51
  }), q = (e, n) => {
42
52
  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({
53
+ return x(g(e), n || {});
54
+ }, { provideContext: S, useInjectContext: B } = K("theme-provider"), A = b({
56
55
  storageKey: "gx-pro-theme-appearance"
57
56
  }), O = j(A);
58
57
  function F(e, n) {
@@ -79,7 +78,7 @@ function F(e, n) {
79
78
  });
80
79
  });
81
80
  }
82
- const H = /* @__PURE__ */ y({
81
+ const H = /* @__PURE__ */ v({
83
82
  name: "ThemeContext",
84
83
  inheritAttrs: !1,
85
84
  props: {
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * Gx Design Pro
3
- * Version: 0.0.3
3
+ * Version: 0.0.4
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(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"})}));
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,2 +1,4 @@
1
- export * from './context';
1
+ import { useContext } from './context';
2
+ import { ContextProvider, useContextProvider } from './context/ContextProvider';
2
3
  export * from './theme-context';
4
+ export { ContextProvider, useContext, useContextProvider };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gx-design-vue/context",
3
3
  "type": "module",
4
- "version": "0.0.4",
4
+ "version": "0.0.5",
5
5
  "description": "Gx Design Context",
6
6
  "exports": {
7
7
  ".": {