@gx-design-vue/context 0.0.3 → 0.0.5-alpha.0

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,46 +1,77 @@
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;
1
+ import { BaseTheme, ThemeValue } from "./types.js";
2
+ import * as vue6 from "vue";
3
+ import { PropType, SlotsType } from "vue";
4
+
5
+ //#region src/theme-context/ThemeContext.d.ts
6
+ interface ThemeContextProps {
7
+ theme?: ThemeValue;
8
+ defaultTheme?: ThemeValue;
9
+ onChange?: (theme: ThemeValue) => void;
10
+ onChangeBase?: (theme: BaseTheme) => void;
11
+ onUpdateTheme?: (theme: ThemeValue) => void;
12
+ }
13
+ interface ThemeContextEmits {
14
+ change: (value: ThemeValue) => void;
15
+ changeBase: (value: BaseTheme) => void;
16
+ 'update:theme': (value: ThemeValue) => void;
17
+ }
18
+ interface ThemeContextSlots {
19
+ default?: () => any;
20
+ }
21
+ declare const themeContextProps: {
22
+ theme: {
23
+ type: PropType<ThemeValue>;
24
+ };
25
+ defaultTheme: {
26
+ type: PropType<ThemeValue>;
27
+ default: string;
28
+ };
29
+ onChange: {
30
+ type: PropType<(theme: ThemeValue) => void>;
31
+ };
32
+ onChangeBase: {
33
+ type: PropType<(theme: BaseTheme) => void>;
34
+ };
35
+ onUpdateTheme: {
36
+ type: PropType<(theme: ThemeValue) => void>;
37
+ };
38
+ };
39
+ declare const ThemeContext: vue6.DefineComponent<vue6.ExtractPropTypes<{
40
+ theme: {
41
+ type: PropType<ThemeValue>;
42
+ };
43
+ defaultTheme: {
44
+ type: PropType<ThemeValue>;
45
+ default: string;
46
+ };
47
+ onChange: {
48
+ type: PropType<(theme: ThemeValue) => void>;
49
+ };
50
+ onChangeBase: {
51
+ type: PropType<(theme: BaseTheme) => void>;
52
+ };
53
+ onUpdateTheme: {
54
+ type: PropType<(theme: ThemeValue) => void>;
55
+ };
56
+ }>, () => any, {}, {}, {}, vue6.ComponentOptionsMixin, vue6.ComponentOptionsMixin, {}, string, vue6.PublicProps, Readonly<vue6.ExtractPropTypes<{
57
+ theme: {
58
+ type: PropType<ThemeValue>;
59
+ };
60
+ defaultTheme: {
61
+ type: PropType<ThemeValue>;
62
+ default: string;
63
+ };
64
+ onChange: {
65
+ type: PropType<(theme: ThemeValue) => void>;
66
+ };
67
+ onChangeBase: {
68
+ type: PropType<(theme: BaseTheme) => void>;
69
+ };
70
+ onUpdateTheme: {
71
+ type: PropType<(theme: ThemeValue) => void>;
72
+ };
73
+ }>> & Readonly<{}>, {
74
+ defaultTheme: ThemeValue;
75
+ }, SlotsType<ThemeContextSlots>, {}, {}, string, vue6.ComponentProvideOptions, true, {}, any>;
76
+ //#endregion
77
+ export { ThemeContextEmits, ThemeContextProps, ThemeContextSlots, ThemeContext as default, themeContextProps };
@@ -0,0 +1,68 @@
1
+ import { createThemeContext } from "./context.js";
2
+ import { computed, defineComponent, ref, watch } from "vue";
3
+ import { useColorMode } from "@vueuse/core";
4
+
5
+ //#region src/theme-context/ThemeContext.tsx
6
+ const themeContextProps = {
7
+ theme: { type: String },
8
+ defaultTheme: {
9
+ type: String,
10
+ default: "system"
11
+ },
12
+ onChange: { type: Function },
13
+ onChangeBase: { type: Function },
14
+ onUpdateTheme: { type: Function }
15
+ };
16
+ const ThemeContext = /* @__PURE__ */ defineComponent({
17
+ name: "ThemeContext",
18
+ inheritAttrs: false,
19
+ props: themeContextProps,
20
+ slots: Object,
21
+ setup: (props, { slots, emit }) => {
22
+ const html = document.querySelector("html");
23
+ const theme = ref();
24
+ const systemTheme = ref(props.theme || props.defaultTheme || "system");
25
+ watch(() => props.theme, (val) => {
26
+ if (val) systemTheme.value = val;
27
+ });
28
+ const { system, store } = useColorMode();
29
+ watch(() => system.value, () => {
30
+ updateSystemThem();
31
+ }, { immediate: true });
32
+ watch(() => theme.value, (val) => {
33
+ if (val) props.onChangeBase?.(val);
34
+ }, { immediate: true });
35
+ watch(systemTheme, (val) => {
36
+ props.onChange?.(val);
37
+ emit("update:theme", val);
38
+ updateSystemThem();
39
+ });
40
+ function updateSystemThem() {
41
+ if (html) {
42
+ if (systemTheme.value === "system") {
43
+ theme.value = system.value;
44
+ html.setAttribute("data-theme", theme.value);
45
+ } else {
46
+ theme.value = systemTheme.value;
47
+ html.setAttribute("data-theme", systemTheme.value);
48
+ }
49
+ store.value = theme.value;
50
+ }
51
+ }
52
+ function setTheme(val) {
53
+ systemTheme.value = val;
54
+ updateSystemThem();
55
+ }
56
+ createThemeContext({
57
+ theme: systemTheme,
58
+ resolvedTheme: theme,
59
+ isDark: computed(() => theme.value === "dark"),
60
+ setTheme
61
+ });
62
+ return () => slots.default?.();
63
+ }
64
+ });
65
+ var ThemeContext_default = ThemeContext;
66
+
67
+ //#endregion
68
+ export { ThemeContext_default as default, themeContextProps };
@@ -1,2 +1,6 @@
1
- import type { ThemeProviderContext } from './types';
2
- export declare const createThemeContext: (value: ThemeProviderContext) => void, useThemeContext: (injectDefaultValue?: ThemeProviderContext | undefined) => ThemeProviderContext;
1
+ import { ThemeProviderContext } from "./types.js";
2
+
3
+ //#region src/theme-context/context.d.ts
4
+ declare const createThemeContext: (value: ThemeProviderContext) => void, useThemeContext: (injectDefaultValue?: ThemeProviderContext | undefined) => ThemeProviderContext;
5
+ //#endregion
6
+ export { createThemeContext, useThemeContext };
@@ -0,0 +1,7 @@
1
+ import { useContext } from "../context/index.js";
2
+
3
+ //#region src/theme-context/context.ts
4
+ const { provideContext: createThemeContext, useInjectContext: useThemeContext } = useContext("theme-provider");
5
+
6
+ //#endregion
7
+ export { createThemeContext, useThemeContext };
@@ -1,2 +1,7 @@
1
- export declare const isDark: import("vue").WritableComputedRef<boolean, boolean>;
2
- export declare const toggleDark: (value?: boolean | undefined) => boolean;
1
+ import * as _vueuse_core0 from "@vueuse/core";
2
+
3
+ //#region src/theme-context/dark.d.ts
4
+ declare const isDark: _vueuse_core0.UseDarkReturn;
5
+ declare const toggleDark: (value?: boolean | undefined) => boolean;
6
+ //#endregion
7
+ export { isDark, toggleDark };
@@ -0,0 +1,8 @@
1
+ import { useDark, useToggle } from "@vueuse/core";
2
+
3
+ //#region src/theme-context/dark.ts
4
+ const isDark = useDark({ storageKey: "gx-theme-appearance" });
5
+ const toggleDark = useToggle(isDark);
6
+
7
+ //#endregion
8
+ export { isDark, toggleDark };
@@ -1,6 +1,6 @@
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';
1
+ import { BaseTheme, ThemeProviderContext, ThemeValue } from "./types.js";
2
+ import { useThemeContext } from "./context.js";
3
+ import { toggleDark } from "./dark.js";
4
+ import ThemeContext, { ThemeContextEmits, ThemeContextProps, ThemeContextSlots, themeContextProps } from "./ThemeContext.js";
5
+ import { toggleAnimateTheme } from "./utils.js";
6
+ export { BaseTheme, ThemeContext, ThemeContextEmits, ThemeContextProps, ThemeContextSlots, ThemeProviderContext, ThemeValue, themeContextProps, toggleAnimateTheme, toggleDark, useThemeContext };
@@ -0,0 +1,6 @@
1
+ import { useThemeContext } from "./context.js";
2
+ import { toggleDark } from "./dark.js";
3
+ import ThemeContext_default, { themeContextProps } from "./ThemeContext.js";
4
+ import { toggleAnimateTheme } from "./utils.js";
5
+
6
+ export { ThemeContext_default as ThemeContext, themeContextProps, toggleAnimateTheme, toggleDark, useThemeContext };
@@ -1,9 +1,13 @@
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;
1
+ import { ComputedRef, Ref } from "vue";
2
+
3
+ //#region src/theme-context/types.d.ts
4
+ type BaseTheme = 'light' | 'dark';
5
+ type ThemeValue = 'light' | 'dark' | 'system';
6
+ interface ThemeProviderContext {
7
+ theme: Ref<ThemeValue>;
8
+ resolvedTheme: Ref<BaseTheme>;
9
+ isDark: ComputedRef<boolean>;
10
+ setTheme: (theme: ThemeValue) => void;
9
11
  }
12
+ //#endregion
13
+ export { BaseTheme, ThemeProviderContext, ThemeValue };
@@ -0,0 +1 @@
1
+ export { };
@@ -1,5 +1,9 @@
1
- import type { BaseTheme } from './types';
2
- export declare function toggleAnimateTheme(el: HTMLElement, props: {
3
- isDark: boolean;
4
- setTheme?: (value: BaseTheme) => void;
1
+ import { BaseTheme } from "./types.js";
2
+
3
+ //#region src/theme-context/utils.d.ts
4
+ declare function toggleAnimateTheme(el: HTMLElement, props: {
5
+ isDark: boolean;
6
+ setTheme?: (value: BaseTheme) => void;
5
7
  }): void;
8
+ //#endregion
9
+ export { toggleAnimateTheme };
@@ -0,0 +1,32 @@
1
+ import { nextTick } from "vue";
2
+
3
+ //#region src/theme-context/utils.ts
4
+ function toggleAnimateTheme(el, props) {
5
+ if (!(document.startViewTransition && !window.matchMedia("(prefers-reduced-motion: reduce)").matches)) {
6
+ props.setTheme?.(props.isDark ? "dark" : "light");
7
+ return;
8
+ }
9
+ const rect = el.getBoundingClientRect();
10
+ const x = rect.left + rect.width / 2;
11
+ const y = rect.top + rect.height / 2;
12
+ const endRadius = Math.hypot(Math.max(x, innerWidth - x), Math.max(y, innerHeight - y));
13
+ const ratioX = 100 * x / innerWidth;
14
+ const ratioY = 100 * y / innerHeight;
15
+ const referR = Math.hypot(innerWidth, innerHeight) / Math.SQRT2;
16
+ const ratioR = 100 * endRadius / referR;
17
+ document.startViewTransition(async () => {
18
+ props.setTheme?.(props.isDark ? "dark" : "light");
19
+ await nextTick();
20
+ }).ready.then(() => {
21
+ const clipPath = [`circle(0% at ${ratioX}% ${ratioY}%)`, `circle(${ratioR}% at ${ratioX}% ${ratioY}%)`];
22
+ document.documentElement.animate({ clipPath: props.isDark ? [...clipPath].reverse() : clipPath }, {
23
+ duration: 400,
24
+ fill: "forwards",
25
+ easing: "ease-in",
26
+ pseudoElement: props.isDark ? "::view-transition-old(root)" : "::view-transition-new(root)"
27
+ });
28
+ });
29
+ }
30
+
31
+ //#endregion
32
+ export { toggleAnimateTheme };
package/global.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export {}
2
+
3
+ declare module 'vue' {
4
+ export interface GlobalComponents {
5
+ ThemeContext: typeof import('@gx-design-vue/context')['ThemeContext']
6
+ ContextProvider: typeof import('@gx-design-vue/context')['ContextProvider']
7
+ }
8
+ }
package/package.json CHANGED
@@ -1,42 +1,60 @@
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-alpha.0",
5
+ "description": "Gx Design Context",
6
+ "author": {
7
+ "name": "gx12358",
8
+ "email": "gx12358@gmail.com",
9
+ "url": "https://github.com/gx12358"
10
+ },
11
+ "license": "MIT",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/gx12358/pro-components-next.git",
15
+ "directory": "packages/context"
16
+ },
6
17
  "exports": {
7
18
  ".": {
8
19
  "types": "./dist/index.d.ts",
9
- "import": "./dist/context.js",
10
- "require": "./dist/context.umd.cjs"
11
- }
20
+ "import": "./dist/index.js",
21
+ "default": "./dist/index.js"
22
+ },
23
+ "./dist/*": {
24
+ "types": "./dist/*.d.ts",
25
+ "import": "./dist/*.js",
26
+ "default": "./dist/*.js"
27
+ },
28
+ "./global.d.ts": "./global.d.ts",
29
+ "./global": "./global.d.ts",
30
+ "./package.json": "./package.json"
12
31
  },
13
- "main": "./dist/context.umd.cjs",
14
- "module": "./dist/context.js",
15
- "types": "./dist",
32
+ "unpkg": "dist/context.js",
33
+ "jsdelivr": "dist/context.js",
16
34
  "files": [
17
- "dist"
35
+ "dist",
36
+ "global.d.ts",
37
+ "package.json"
18
38
  ],
19
- "scripts": {
20
- "dev": "vite",
21
- "build": "vite build",
22
- "types": "vue-tsc --declaration --emitDeclarationOnly",
23
- "preview": "vite preview --port 5050",
24
- "test:unit": "vitest --environment jsdom",
25
- "typecheck": "vue-tsc --noEmit && vue-tsc --noEmit -p tsconfig.vitest.json --composite false",
26
- "lint": "TIMING=1 eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore"
27
- },
28
39
  "peerDependencies": {
29
- "vue": ">=3.0.0",
30
- "ant-design-vue": "^4.2.6"
40
+ "vue": ">=3.2.0"
31
41
  },
32
42
  "dependencies": {
33
- "@vueuse/core": "^14.0.0",
34
- "@gx-design-vue/pro-provider": "^0.1.0-beta.130"
43
+ "@vueuse/core": "^14.2.0",
44
+ "@gx-design-vue/pro-utils": "0.2.0-alpha.0"
35
45
  },
36
- "devDependencies": {
37
- "typescript": "^5.3.3"
38
- },
39
- "authors": [
40
- "gx12358 <gx12358@gmail.com> (https://github.com/gx12358)"
41
- ]
42
- }
46
+ "browserslist": [
47
+ "> 1%",
48
+ "not ie 11",
49
+ "not op_mini all"
50
+ ],
51
+ "scripts": {
52
+ "test": "vitest run",
53
+ "build": "run-s build:esm build:vite:parallel",
54
+ "build:esm": "tsdown",
55
+ "build:vite:parallel": "run-p build:umd build:full-esm",
56
+ "build:full-esm": "vite build --config ./vite.esm.config.ts",
57
+ "build:umd": "vite build",
58
+ "prepublish": "pnpm build"
59
+ }
60
+ }
@@ -1,12 +0,0 @@
1
- /*!
2
- * Gx Design Pro
3
- * Version: 0.0.2
4
- * Author: gx12358
5
- * Copyright (C) 2024 gx12358
6
- * License: MIT License
7
- * Description: Gx Design context
8
- * Date Created: 2025-11-23
9
- * Homepage:
10
- * Contact: gx12358@gmail.com
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"})}));