@gx-design-vue/context 0.0.2 → 0.0.3

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.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * Gx Design Pro
3
- * Version: 0.0.1
3
+ * Version: 0.0.2
4
4
  * Author: gx12358
5
5
  * Copyright (C) 2024 gx12358
6
6
  * License: MIT License
@@ -9,13 +9,37 @@
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 { 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({
16
+ storageKey: "gx-pro-theme-appearance"
17
+ }), S = T(k);
18
+ function $(o, a) {
19
+ if (!(document.startViewTransition && !window.matchMedia("(prefers-reduced-motion: reduce)").matches)) {
20
+ a.setTheme?.(a.isDark ? "dark" : "light");
21
+ return;
22
+ }
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;
24
+ document.startViewTransition(async () => {
25
+ a.setTheme?.(a.isDark ? "dark" : "light"), await v();
26
+ }).ready.then(() => {
27
+ const d = [
28
+ `circle(0% at ${m}% ${r}%)`,
29
+ `circle(${e}% at ${m}% ${r}%)`
30
+ ];
31
+ document.documentElement.animate({
32
+ clipPath: a.isDark ? [...d].reverse() : d
33
+ }, {
34
+ duration: 400,
35
+ // 保持最终状态
36
+ fill: "forwards",
37
+ easing: "ease-in",
38
+ pseudoElement: a.isDark ? "::view-transition-old(root)" : "::view-transition-new(root)"
39
+ });
40
+ });
41
+ }
42
+ const B = /* @__PURE__ */ p({
19
43
  name: "ThemeContext",
20
44
  inheritAttrs: !1,
21
45
  props: {
@@ -38,43 +62,46 @@ const {
38
62
  },
39
63
  emits: ["change", "changeBase", "update:theme"],
40
64
  slots: Object,
41
- setup(m, {
42
- slots: r,
43
- emit: i
65
+ setup(o, {
66
+ slots: a,
67
+ emit: u
44
68
  }) {
45
- const o = document.querySelector("html"), t = h(), n = h(m.theme || m.defaultTheme || "system");
46
- a(() => m.theme, (e) => {
69
+ const i = document.querySelector("html"), t = l(), n = l(o.theme || o.defaultTheme || "system");
70
+ h(() => o.theme, (e) => {
47
71
  e && (n.value = e);
48
72
  });
49
73
  const {
50
74
  system: s,
51
- store: l
52
- } = f();
53
- a(() => s.value, () => {
54
- u();
75
+ store: m
76
+ } = y();
77
+ h(() => s.value, () => {
78
+ r();
55
79
  }, {
56
80
  immediate: !0
57
- }), a(() => t.value, (e) => {
58
- e && m.onChangeBase?.(e);
81
+ }), h(() => t.value, (e) => {
82
+ e && o.onChangeBase?.(e);
59
83
  }, {
60
84
  immediate: !0
61
- }), a(n, (e) => {
62
- m.onChange?.(e), i("update:theme", e), u();
85
+ }), h(n, (e) => {
86
+ o.onChange?.(e), u("update:theme", e), r();
63
87
  });
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);
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);
66
90
  }
67
91
  function c(e) {
68
- n.value = e, u();
92
+ n.value = e, r();
69
93
  }
70
- return p({
94
+ return x({
71
95
  theme: n,
72
96
  resolvedTheme: t,
73
97
  isDark: C(() => t.value === "dark"),
74
98
  setTheme: c
75
- }), () => r.default();
99
+ }), () => a.default();
76
100
  }
77
101
  });
78
102
  export {
79
- S as ThemeContext
103
+ B as ThemeContext,
104
+ $ as toggleAnimateTheme,
105
+ S as toggleDark,
106
+ R as useThemeContext
80
107
  };
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * Gx Design Pro
3
- * Version: 0.0.1
3
+ * Version: 0.0.2
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(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(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"})}));
package/dist/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { default as ThemeContext } from './theme-context';
1
+ 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,7 +1,7 @@
1
1
  {
2
2
  "name": "@gx-design-vue/context",
3
3
  "type": "module",
4
- "version": "0.0.2",
4
+ "version": "0.0.3",
5
5
  "description": "Gx Design context",
6
6
  "exports": {
7
7
  ".": {