@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.
- package/dist/context/index.d.ts +0 -1
- package/dist/context.js +17 -18
- package/dist/context.umd.cjs +2 -2
- package/dist/index.d.ts +3 -1
- package/package.json +1 -1
package/dist/context/index.d.ts
CHANGED
package/dist/context.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* Gx Design Pro
|
|
3
|
-
* Version: 0.0.
|
|
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 {
|
|
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__ */
|
|
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) ?
|
|
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
|
|
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__ */
|
|
81
|
+
const H = /* @__PURE__ */ v({
|
|
83
82
|
name: "ThemeContext",
|
|
84
83
|
inheritAttrs: !1,
|
|
85
84
|
props: {
|
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.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.
|
|
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