@gx-design-vue/context 0.0.5-alpha.1 → 0.0.5-alpha.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/ContextProvider.d.ts +4 -4
- package/dist/context/ContextProvider.js +1 -3
- package/dist/context/index.js +1 -3
- package/dist/context.esm.js +196 -182
- package/dist/context.js +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +2 -3
- package/dist/theme-context/ThemeContext.d.ts +4 -4
- package/dist/theme-context/ThemeContext.js +1 -4
- package/dist/theme-context/context.js +1 -3
- package/dist/theme-context/dark.d.ts +2 -2
- package/dist/theme-context/dark.js +1 -3
- package/dist/theme-context/index.js +2 -3
- package/dist/theme-context/types.js +1 -1
- package/dist/theme-context/utils.js +1 -3
- package/package.json +3 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _$vue from "vue";
|
|
2
2
|
import { PropType, SlotsType } from "vue";
|
|
3
3
|
|
|
4
4
|
//#region src/context/ContextProvider.d.ts
|
|
@@ -19,7 +19,7 @@ declare const contextProps: {
|
|
|
19
19
|
required: boolean;
|
|
20
20
|
};
|
|
21
21
|
};
|
|
22
|
-
declare const ContextProvider:
|
|
22
|
+
declare const ContextProvider: _$vue.DefineComponent<_$vue.ExtractPropTypes<{
|
|
23
23
|
contextKey: {
|
|
24
24
|
type: PropType<ContextProviderProps["contextKey"]>;
|
|
25
25
|
required: boolean;
|
|
@@ -28,7 +28,7 @@ declare const ContextProvider: vue6.DefineComponent<vue6.ExtractPropTypes<{
|
|
|
28
28
|
type: PropType<ContextProviderProps["value"]>;
|
|
29
29
|
required: boolean;
|
|
30
30
|
};
|
|
31
|
-
}>, () => any, {}, {}, {},
|
|
31
|
+
}>, () => any, {}, {}, {}, _$vue.ComponentOptionsMixin, _$vue.ComponentOptionsMixin, {}, string, _$vue.PublicProps, Readonly<_$vue.ExtractPropTypes<{
|
|
32
32
|
contextKey: {
|
|
33
33
|
type: PropType<ContextProviderProps["contextKey"]>;
|
|
34
34
|
required: boolean;
|
|
@@ -37,7 +37,7 @@ declare const ContextProvider: vue6.DefineComponent<vue6.ExtractPropTypes<{
|
|
|
37
37
|
type: PropType<ContextProviderProps["value"]>;
|
|
38
38
|
required: boolean;
|
|
39
39
|
};
|
|
40
|
-
}>> & Readonly<{}>, {}, SlotsType<ContextProviderSlots>, {}, {}, string,
|
|
40
|
+
}>> & Readonly<{}>, {}, SlotsType<ContextProviderSlots>, {}, {}, string, _$vue.ComponentProvideOptions, true, {}, any>;
|
|
41
41
|
declare function useContextProvider<T = any>(contextInjectKey: string, defaultValue?: T): T & {
|
|
42
42
|
contextId: string;
|
|
43
43
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { defineComponent, inject, provide, toRefs } from "vue";
|
|
2
2
|
import { getRandomNumber, isObject } from "@gx-design-vue/pro-utils";
|
|
3
|
-
|
|
4
3
|
//#region src/context/ContextProvider.tsx
|
|
5
4
|
let contextId = null;
|
|
6
5
|
function updateContextKey(key) {
|
|
@@ -34,6 +33,5 @@ const ContextProvider = /* @__PURE__ */ defineComponent({
|
|
|
34
33
|
function useContextProvider(contextInjectKey, defaultValue) {
|
|
35
34
|
if (typeof contextId === "symbol") return inject(updateContextKey(contextInjectKey), defaultValue || {});
|
|
36
35
|
}
|
|
37
|
-
|
|
38
36
|
//#endregion
|
|
39
|
-
export { ContextProvider, contextProps, useContextProvider };
|
|
37
|
+
export { ContextProvider, contextProps, useContextProvider };
|
package/dist/context/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { inject, provide } from "vue";
|
|
2
|
-
|
|
3
2
|
//#region src/context/index.ts
|
|
4
3
|
function useContext(key, defaultValue) {
|
|
5
4
|
const contextInjectKey = Symbol(key);
|
|
@@ -15,6 +14,5 @@ function useContext(key, defaultValue) {
|
|
|
15
14
|
contextInjectKey
|
|
16
15
|
};
|
|
17
16
|
}
|
|
18
|
-
|
|
19
17
|
//#endregion
|
|
20
|
-
export { useContext };
|
|
18
|
+
export { useContext };
|
package/dist/context.esm.js
CHANGED
|
@@ -1,46 +1,53 @@
|
|
|
1
|
-
import { computed, customRef, defineComponent, getCurrentInstance, getCurrentScope, hasInjectionContext, inject, isRef, nextTick, onMounted, provide, readonly, ref, shallowRef, toRef, toRefs, toValue, unref, watch, watchEffect } from "vue";
|
|
2
|
-
|
|
1
|
+
import { computed as e, customRef as t, defineComponent as n, getCurrentInstance as r, getCurrentScope as i, hasInjectionContext as a, inject as o, isRef as s, nextTick as c, onMounted as l, provide as u, readonly as d, ref as f, shallowReadonly as p, shallowRef as m, toRef as h, toRefs as g, toValue as _, unref as v, watch as y, watchEffect as b } from "vue";
|
|
2
|
+
//#region src/context/index.ts
|
|
3
|
+
function x(e, t) {
|
|
3
4
|
let n = Symbol(e);
|
|
4
5
|
return {
|
|
5
6
|
provideContext: (e) => {
|
|
6
|
-
|
|
7
|
+
u(n, e);
|
|
7
8
|
},
|
|
8
|
-
useInjectContext: (e) =>
|
|
9
|
+
useInjectContext: (e) => o(n, e || t || {}),
|
|
9
10
|
contextInjectKey: n
|
|
10
11
|
};
|
|
11
12
|
}
|
|
12
13
|
typeof process < "u" && process.versions != null && process.versions.node;
|
|
13
|
-
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region ../pro-utils/dist/is/type.js
|
|
16
|
+
function S(e, t) {
|
|
14
17
|
return Object.prototype.toString.call(e) === `[object ${t}]`;
|
|
15
18
|
}
|
|
16
|
-
function
|
|
17
|
-
return e !== null &&
|
|
19
|
+
function C(e) {
|
|
20
|
+
return e !== null && S(e, "Object");
|
|
18
21
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region ../pro-utils/dist/dom/raf.js
|
|
24
|
+
var w = (e) => setTimeout(e, 16), T = (e) => clearTimeout(e);
|
|
25
|
+
typeof window < "u" && "requestAnimationFrame" in window && (w = (e) => window.requestAnimationFrame(e), T = (e) => window.cancelAnimationFrame(e));
|
|
26
|
+
var E = 0, D = /* @__PURE__ */ new Map();
|
|
27
|
+
function O(e) {
|
|
28
|
+
D.delete(e);
|
|
24
29
|
}
|
|
25
|
-
function
|
|
26
|
-
|
|
27
|
-
let n =
|
|
30
|
+
function k(e, t = 1) {
|
|
31
|
+
E += 1;
|
|
32
|
+
let n = E;
|
|
28
33
|
function r(t) {
|
|
29
|
-
if (t === 0)
|
|
34
|
+
if (t === 0) O(n), e();
|
|
30
35
|
else {
|
|
31
|
-
let e =
|
|
36
|
+
let e = w(() => {
|
|
32
37
|
r(t - 1);
|
|
33
38
|
});
|
|
34
|
-
|
|
39
|
+
D.set(n, e);
|
|
35
40
|
}
|
|
36
41
|
}
|
|
37
42
|
return r(t), n;
|
|
38
43
|
}
|
|
39
|
-
|
|
40
|
-
let t =
|
|
41
|
-
return
|
|
44
|
+
k.cancel = (e) => {
|
|
45
|
+
let t = D.get(e);
|
|
46
|
+
return O(t), T(t);
|
|
42
47
|
};
|
|
43
|
-
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region ../pro-utils/dist/string/uuid.js
|
|
50
|
+
function A() {
|
|
44
51
|
let e = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");
|
|
45
52
|
return {
|
|
46
53
|
uuid(t, n) {
|
|
@@ -65,11 +72,13 @@ function getRandomNumber() {
|
|
|
65
72
|
}
|
|
66
73
|
};
|
|
67
74
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/context/ContextProvider.tsx
|
|
77
|
+
var j = null;
|
|
78
|
+
function M(e) {
|
|
79
|
+
return j || (j = Symbol(e), j);
|
|
71
80
|
}
|
|
72
|
-
var
|
|
81
|
+
var ee = /* @__PURE__ */ n({
|
|
73
82
|
name: "ContextProvider",
|
|
74
83
|
props: {
|
|
75
84
|
contextKey: {
|
|
@@ -82,31 +91,32 @@ var ContextProvider = /* @__PURE__ */ defineComponent({
|
|
|
82
91
|
}
|
|
83
92
|
},
|
|
84
93
|
slots: Object,
|
|
85
|
-
setup: (e, { slots: t }) => (e.contextKey && e.value &&
|
|
86
|
-
...
|
|
87
|
-
contextId: `${e.contextKey}-${
|
|
94
|
+
setup: (e, { slots: t }) => (e.contextKey && e.value && C(e.value) ? u(M(e.contextKey), {
|
|
95
|
+
...g(e.value),
|
|
96
|
+
contextId: `${e.contextKey}-${A().uuid(10)}`
|
|
88
97
|
}) : console.warn("[ContextProvider]: contextKey is required"), () => t.default?.())
|
|
89
98
|
});
|
|
90
|
-
function
|
|
91
|
-
if (typeof
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
+
function te(e, t) {
|
|
100
|
+
if (typeof j == "symbol") return o(M(e), t || {});
|
|
101
|
+
}
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/theme-context/context.ts
|
|
104
|
+
var { provideContext: ne, useInjectContext: re } = x("theme-provider"), N = /* @__PURE__ */ new WeakMap(), P = (...e) => {
|
|
105
|
+
let t = e[0], n = r()?.proxy ?? i();
|
|
106
|
+
if (n == null && !a()) throw Error("injectLocal must be called in setup");
|
|
107
|
+
return n && N.has(n) && t in N.get(n) ? N.get(n)[t] : o(...e);
|
|
108
|
+
}, F = typeof window < "u" && typeof document < "u";
|
|
99
109
|
typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
|
|
100
|
-
var
|
|
101
|
-
function
|
|
102
|
-
if (e.length !== 1) return
|
|
110
|
+
var I = Object.prototype.toString, ie = (e) => I.call(e) === "[object Object]", ae = () => {};
|
|
111
|
+
function L(...e) {
|
|
112
|
+
if (e.length !== 1) return h(...e);
|
|
103
113
|
let n = e[0];
|
|
104
|
-
return typeof n == "function" ?
|
|
114
|
+
return typeof n == "function" ? d(t(() => ({
|
|
105
115
|
get: n,
|
|
106
|
-
set:
|
|
107
|
-
}))) :
|
|
116
|
+
set: ae
|
|
117
|
+
}))) : f(n);
|
|
108
118
|
}
|
|
109
|
-
function
|
|
119
|
+
function R(e, t) {
|
|
110
120
|
function n(...n) {
|
|
111
121
|
return new Promise((r, i) => {
|
|
112
122
|
Promise.resolve(e(() => t.apply(this, n), {
|
|
@@ -118,9 +128,9 @@ function createFilterWrapper(e, t) {
|
|
|
118
128
|
}
|
|
119
129
|
return n;
|
|
120
130
|
}
|
|
121
|
-
var
|
|
122
|
-
function
|
|
123
|
-
let { initialState: n = "active" } = t, r =
|
|
131
|
+
var z = (e) => e();
|
|
132
|
+
function oe(e = z, t = {}) {
|
|
133
|
+
let { initialState: n = "active" } = t, r = L(n === "active");
|
|
124
134
|
function i() {
|
|
125
135
|
r.value = !1;
|
|
126
136
|
}
|
|
@@ -128,7 +138,7 @@ function pausableFilter(e = bypassFilter, t = {}) {
|
|
|
128
138
|
r.value = !0;
|
|
129
139
|
}
|
|
130
140
|
return {
|
|
131
|
-
isActive:
|
|
141
|
+
isActive: p(r),
|
|
132
142
|
pause: i,
|
|
133
143
|
resume: a,
|
|
134
144
|
eventFilter: (...t) => {
|
|
@@ -136,23 +146,23 @@ function pausableFilter(e = bypassFilter, t = {}) {
|
|
|
136
146
|
}
|
|
137
147
|
};
|
|
138
148
|
}
|
|
139
|
-
function
|
|
149
|
+
function B(e) {
|
|
140
150
|
return e.endsWith("rem") ? Number.parseFloat(e) * 16 : Number.parseFloat(e);
|
|
141
151
|
}
|
|
142
|
-
function
|
|
152
|
+
function V(e) {
|
|
143
153
|
return Array.isArray(e) ? e : [e];
|
|
144
154
|
}
|
|
145
|
-
function
|
|
146
|
-
return e ||
|
|
155
|
+
function se(e) {
|
|
156
|
+
return e || r();
|
|
147
157
|
}
|
|
148
|
-
function
|
|
149
|
-
let { eventFilter: r =
|
|
150
|
-
return
|
|
158
|
+
function ce(e, t, n = {}) {
|
|
159
|
+
let { eventFilter: r = z, ...i } = n;
|
|
160
|
+
return y(e, R(r, t), i);
|
|
151
161
|
}
|
|
152
|
-
function
|
|
153
|
-
let { eventFilter: r, initialState: i = "active", ...a } = n, { eventFilter: o, pause: s, resume: c, isActive: l } =
|
|
162
|
+
function H(e, t, n = {}) {
|
|
163
|
+
let { eventFilter: r, initialState: i = "active", ...a } = n, { eventFilter: o, pause: s, resume: c, isActive: l } = oe(r, { initialState: i });
|
|
154
164
|
return {
|
|
155
|
-
stop:
|
|
165
|
+
stop: ce(e, t, {
|
|
156
166
|
...a,
|
|
157
167
|
eventFilter: o
|
|
158
168
|
}),
|
|
@@ -161,96 +171,98 @@ function watchPausable(e, t, n = {}) {
|
|
|
161
171
|
isActive: l
|
|
162
172
|
};
|
|
163
173
|
}
|
|
164
|
-
function
|
|
165
|
-
|
|
174
|
+
function U(e, t = !0, n) {
|
|
175
|
+
se(n) ? l(e, n) : t ? e() : c(e);
|
|
166
176
|
}
|
|
167
|
-
function
|
|
168
|
-
let { truthyValue: n = !0, falsyValue: r = !1 } = t, i =
|
|
177
|
+
function W(e = !1, t = {}) {
|
|
178
|
+
let { truthyValue: n = !0, falsyValue: r = !1 } = t, i = s(e), a = m(e);
|
|
169
179
|
function o(e) {
|
|
170
180
|
if (arguments.length) return a.value = e, a.value;
|
|
171
181
|
{
|
|
172
|
-
let e =
|
|
173
|
-
return a.value = a.value === e ?
|
|
182
|
+
let e = _(n);
|
|
183
|
+
return a.value = a.value === e ? _(r) : e, a.value;
|
|
174
184
|
}
|
|
175
185
|
}
|
|
176
186
|
return i ? o : [a, o];
|
|
177
187
|
}
|
|
178
|
-
function
|
|
179
|
-
return
|
|
188
|
+
function le(e, t, n) {
|
|
189
|
+
return y(e, t, {
|
|
180
190
|
...n,
|
|
181
191
|
immediate: !0
|
|
182
192
|
});
|
|
183
193
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
194
|
+
//#endregion
|
|
195
|
+
//#region ../../node_modules/.pnpm/@vueuse+core@14.3.0_vue@3.5.27_typescript@6.0.3_/node_modules/@vueuse/core/dist/index.js
|
|
196
|
+
var G = F ? window : void 0;
|
|
197
|
+
F && window.document, F && window.navigator, F && window.location;
|
|
198
|
+
function K(e) {
|
|
199
|
+
let t = _(e);
|
|
188
200
|
return t?.$el ?? t;
|
|
189
201
|
}
|
|
190
|
-
function
|
|
191
|
-
let n = (e, t, n, r) => (e.addEventListener(t, n, r), () => e.removeEventListener(t, n, r)), r =
|
|
192
|
-
let e =
|
|
202
|
+
function q(...t) {
|
|
203
|
+
let n = (e, t, n, r) => (e.addEventListener(t, n, r), () => e.removeEventListener(t, n, r)), r = e(() => {
|
|
204
|
+
let e = V(_(t[0])).filter((e) => e != null);
|
|
193
205
|
return e.every((e) => typeof e != "string") ? e : void 0;
|
|
194
206
|
});
|
|
195
|
-
return
|
|
196
|
-
r.value?.map((e) =>
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
207
|
+
return le(() => [
|
|
208
|
+
r.value?.map((e) => K(e)) ?? [G].filter((e) => e != null),
|
|
209
|
+
V(_(r.value ? t[1] : t[0])),
|
|
210
|
+
V(v(r.value ? t[2] : t[1])),
|
|
211
|
+
_(r.value ? t[3] : t[2])
|
|
200
212
|
], ([e, t, r, i], a, o) => {
|
|
201
213
|
if (!e?.length || !t?.length || !r?.length) return;
|
|
202
|
-
let s =
|
|
214
|
+
let s = ie(i) ? { ...i } : i, c = e.flatMap((e) => t.flatMap((t) => r.map((r) => n(e, t, r, s))));
|
|
203
215
|
o(() => {
|
|
204
216
|
c.forEach((e) => e());
|
|
205
217
|
});
|
|
206
218
|
}, { flush: "post" });
|
|
207
219
|
}
|
|
208
|
-
function
|
|
209
|
-
let e =
|
|
210
|
-
return t &&
|
|
220
|
+
function ue() {
|
|
221
|
+
let e = m(!1), t = r();
|
|
222
|
+
return t && l(() => {
|
|
211
223
|
e.value = !0;
|
|
212
224
|
}, t), e;
|
|
213
225
|
}
|
|
214
226
|
/* @__NO_SIDE_EFFECTS__ */
|
|
215
|
-
function
|
|
216
|
-
let n =
|
|
217
|
-
return
|
|
227
|
+
function de(t) {
|
|
228
|
+
let n = ue();
|
|
229
|
+
return e(() => (n.value, !!t()));
|
|
218
230
|
}
|
|
219
|
-
var
|
|
231
|
+
var fe = Symbol("vueuse-ssr-width");
|
|
220
232
|
/* @__NO_SIDE_EFFECTS__ */
|
|
221
|
-
function
|
|
222
|
-
let e =
|
|
233
|
+
function pe() {
|
|
234
|
+
let e = a() ? P(fe, null) : null;
|
|
223
235
|
return typeof e == "number" ? e : void 0;
|
|
224
236
|
}
|
|
225
|
-
function
|
|
226
|
-
let { window: r =
|
|
227
|
-
return
|
|
237
|
+
function me(t, n = {}) {
|
|
238
|
+
let { window: r = G, ssrWidth: i = /* @__PURE__ */ pe() } = n, a = /* @__PURE__ */ de(() => r && "matchMedia" in r && typeof r.matchMedia == "function"), o = m(typeof i == "number"), s = m(), c = m(!1);
|
|
239
|
+
return b(() => {
|
|
228
240
|
if (o.value) {
|
|
229
|
-
o.value = !a.value, c.value =
|
|
241
|
+
o.value = !a.value, c.value = _(t).split(",").some((e) => {
|
|
230
242
|
let t = e.includes("not all"), n = e.match(/\(\s*min-width:\s*(-?\d+(?:\.\d*)?[a-z]+\s*)\)/), r = e.match(/\(\s*max-width:\s*(-?\d+(?:\.\d*)?[a-z]+\s*)\)/), a = !!(n || r);
|
|
231
|
-
return n && a && (a = i >=
|
|
243
|
+
return n && a && (a = i >= B(n[1])), r && a && (a = i <= B(r[1])), t ? !a : a;
|
|
232
244
|
});
|
|
233
245
|
return;
|
|
234
246
|
}
|
|
235
|
-
a.value && (s.value = r.matchMedia(
|
|
236
|
-
}),
|
|
247
|
+
a.value && (s.value = r.matchMedia(_(t)), c.value = s.value.matches);
|
|
248
|
+
}), q(s, "change", (e) => {
|
|
237
249
|
c.value = e.matches;
|
|
238
|
-
}, { passive: !0 }),
|
|
250
|
+
}, { passive: !0 }), e(() => c.value);
|
|
239
251
|
}
|
|
240
|
-
var
|
|
241
|
-
function
|
|
242
|
-
return
|
|
252
|
+
var J = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, Y = "__vueuse_ssr_handlers__", he = /* @__PURE__ */ ge();
|
|
253
|
+
function ge() {
|
|
254
|
+
return Y in J || (J[Y] = J[Y] || {}), J[Y];
|
|
243
255
|
}
|
|
244
|
-
function
|
|
245
|
-
return
|
|
256
|
+
function X(e, t) {
|
|
257
|
+
return he[e] || t;
|
|
246
258
|
}
|
|
247
|
-
function
|
|
248
|
-
return
|
|
259
|
+
function _e(e) {
|
|
260
|
+
return me("(prefers-color-scheme: dark)", e);
|
|
249
261
|
}
|
|
250
|
-
function
|
|
262
|
+
function ve(e) {
|
|
251
263
|
return e == null ? "any" : e instanceof Set ? "set" : e instanceof Map ? "map" : e instanceof Date ? "date" : typeof e == "boolean" ? "boolean" : typeof e == "string" ? "string" : typeof e == "object" ? "object" : Number.isNaN(e) ? "any" : "number";
|
|
252
264
|
}
|
|
253
|
-
var
|
|
265
|
+
var ye = {
|
|
254
266
|
boolean: {
|
|
255
267
|
read: (e) => e === "true",
|
|
256
268
|
write: (e) => String(e)
|
|
@@ -283,102 +295,102 @@ var StorageSerializers = {
|
|
|
283
295
|
read: (e) => new Date(e),
|
|
284
296
|
write: (e) => e.toISOString()
|
|
285
297
|
}
|
|
286
|
-
},
|
|
287
|
-
function
|
|
288
|
-
let { flush: a = "pre", deep: o = !0, listenToStorageChanges: s = !0, writeDefaults: l = !0, mergeDefaults: u = !1, shallow: d, window:
|
|
298
|
+
}, Z = "vueuse-storage";
|
|
299
|
+
function be(t, n, r, i = {}) {
|
|
300
|
+
let { flush: a = "pre", deep: o = !0, listenToStorageChanges: s = !0, writeDefaults: l = !0, mergeDefaults: u = !1, shallow: d, window: p = G, eventFilter: h, onError: g = (e) => {
|
|
289
301
|
console.error(e);
|
|
290
|
-
}, initOnMounted: v } = i,
|
|
302
|
+
}, initOnMounted: v } = i, b = (d ? m : f)(typeof n == "function" ? n() : n), x = e(() => _(t));
|
|
291
303
|
if (!r) try {
|
|
292
|
-
r =
|
|
304
|
+
r = X("getDefaultStorage", () => G?.localStorage)();
|
|
293
305
|
} catch (e) {
|
|
294
|
-
|
|
306
|
+
g(e);
|
|
295
307
|
}
|
|
296
|
-
if (!r) return
|
|
297
|
-
let
|
|
308
|
+
if (!r) return b;
|
|
309
|
+
let S = _(n), C = ve(S), w = i.serializer ?? ye[C], { pause: T, resume: E } = H(b, (e) => k(e), {
|
|
298
310
|
flush: a,
|
|
299
311
|
deep: o,
|
|
300
312
|
eventFilter: h
|
|
301
313
|
});
|
|
302
|
-
|
|
303
|
-
let
|
|
304
|
-
|
|
305
|
-
v && !
|
|
306
|
-
}, { passive: !0 }) :
|
|
307
|
-
v && !
|
|
308
|
-
})), v ?
|
|
309
|
-
|
|
310
|
-
}) :
|
|
311
|
-
function
|
|
312
|
-
if (
|
|
314
|
+
y(x, () => j(), { flush: a });
|
|
315
|
+
let D = !1;
|
|
316
|
+
p && s && (r instanceof Storage ? q(p, "storage", (e) => {
|
|
317
|
+
v && !D || j(e);
|
|
318
|
+
}, { passive: !0 }) : q(p, Z, (e) => {
|
|
319
|
+
v && !D || M(e);
|
|
320
|
+
})), v ? U(() => {
|
|
321
|
+
D = !0, j();
|
|
322
|
+
}) : j();
|
|
323
|
+
function O(e, t) {
|
|
324
|
+
if (p) {
|
|
313
325
|
let n = {
|
|
314
|
-
key:
|
|
326
|
+
key: x.value,
|
|
315
327
|
oldValue: e,
|
|
316
328
|
newValue: t,
|
|
317
329
|
storageArea: r
|
|
318
330
|
};
|
|
319
|
-
|
|
331
|
+
p.dispatchEvent(r instanceof Storage ? new StorageEvent("storage", n) : new CustomEvent(Z, { detail: n }));
|
|
320
332
|
}
|
|
321
333
|
}
|
|
322
|
-
function
|
|
334
|
+
function k(e) {
|
|
323
335
|
try {
|
|
324
|
-
let t = r.getItem(
|
|
325
|
-
if (e == null)
|
|
336
|
+
let t = r.getItem(x.value);
|
|
337
|
+
if (e == null) O(t, null), r.removeItem(x.value);
|
|
326
338
|
else {
|
|
327
|
-
let n =
|
|
328
|
-
t !== n && (r.setItem(
|
|
339
|
+
let n = w.write(e);
|
|
340
|
+
t !== n && (r.setItem(x.value, n), O(t, n));
|
|
329
341
|
}
|
|
330
342
|
} catch (e) {
|
|
331
|
-
|
|
343
|
+
g(e);
|
|
332
344
|
}
|
|
333
345
|
}
|
|
334
|
-
function
|
|
335
|
-
let t = e ? e.newValue : r.getItem(
|
|
336
|
-
if (t == null) return l &&
|
|
346
|
+
function A(e) {
|
|
347
|
+
let t = e ? e.newValue : r.getItem(x.value);
|
|
348
|
+
if (t == null) return l && S != null && r.setItem(x.value, w.write(S)), S;
|
|
337
349
|
if (!e && u) {
|
|
338
|
-
let e =
|
|
339
|
-
return typeof u == "function" ? u(e,
|
|
340
|
-
...
|
|
350
|
+
let e = w.read(t);
|
|
351
|
+
return typeof u == "function" ? u(e, S) : C === "object" && !Array.isArray(e) ? {
|
|
352
|
+
...S,
|
|
341
353
|
...e
|
|
342
354
|
} : e;
|
|
343
355
|
} else if (typeof t != "string") return t;
|
|
344
|
-
else return
|
|
356
|
+
else return w.read(t);
|
|
345
357
|
}
|
|
346
|
-
function
|
|
358
|
+
function j(e) {
|
|
347
359
|
if (!(e && e.storageArea !== r)) {
|
|
348
360
|
if (e && e.key == null) {
|
|
349
|
-
|
|
361
|
+
b.value = S;
|
|
350
362
|
return;
|
|
351
363
|
}
|
|
352
|
-
if (!(e && e.key !==
|
|
353
|
-
|
|
364
|
+
if (!(e && e.key !== x.value)) {
|
|
365
|
+
T();
|
|
354
366
|
try {
|
|
355
|
-
let t =
|
|
356
|
-
(e === void 0 || e?.newValue !== t) && (
|
|
367
|
+
let t = w.write(b.value);
|
|
368
|
+
(e === void 0 || e?.newValue !== t) && (b.value = A(e));
|
|
357
369
|
} catch (e) {
|
|
358
|
-
|
|
370
|
+
g(e);
|
|
359
371
|
} finally {
|
|
360
|
-
e ?
|
|
372
|
+
e ? c(E) : E();
|
|
361
373
|
}
|
|
362
374
|
}
|
|
363
375
|
}
|
|
364
376
|
}
|
|
365
|
-
function
|
|
366
|
-
|
|
377
|
+
function M(e) {
|
|
378
|
+
j(e.detail);
|
|
367
379
|
}
|
|
368
|
-
return
|
|
380
|
+
return b;
|
|
369
381
|
}
|
|
370
|
-
var
|
|
371
|
-
function
|
|
372
|
-
let { selector: n = "html", attribute: r = "class", initialValue: i = "auto", window: a =
|
|
382
|
+
var xe = "*,*::before,*::after{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}";
|
|
383
|
+
function Q(t = {}) {
|
|
384
|
+
let { selector: n = "html", attribute: r = "class", initialValue: i = "auto", window: a = G, storage: o, storageKey: s = "vueuse-color-scheme", listenToStorageChanges: c = !0, storageRef: l, emitAuto: u, disableTransition: d = !0 } = t, f = {
|
|
373
385
|
auto: "",
|
|
374
386
|
light: "light",
|
|
375
387
|
dark: "dark",
|
|
376
388
|
...t.modes || {}
|
|
377
|
-
}, p =
|
|
389
|
+
}, p = _e({ window: a }), m = e(() => p.value ? "dark" : "light"), h = l || (s == null ? L(i) : be(s, i, o, {
|
|
378
390
|
window: a,
|
|
379
391
|
listenToStorageChanges: c
|
|
380
|
-
})), g =
|
|
381
|
-
let r = typeof e == "string" ? a?.document.querySelector(e) :
|
|
392
|
+
})), g = e(() => h.value === "auto" ? m.value : h.value), _ = X("updateHTMLAttrs", (e, t, n) => {
|
|
393
|
+
let r = typeof e == "string" ? a?.document.querySelector(e) : K(e);
|
|
382
394
|
if (!r) return;
|
|
383
395
|
let i = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Set(), s = null;
|
|
384
396
|
if (t === "class") {
|
|
@@ -392,7 +404,7 @@ function useColorMode(t = {}) {
|
|
|
392
404
|
};
|
|
393
405
|
if (i.size === 0 && o.size === 0 && s === null) return;
|
|
394
406
|
let c;
|
|
395
|
-
d && (c = a.document.createElement("style"), c.appendChild(document.createTextNode(
|
|
407
|
+
d && (c = a.document.createElement("style"), c.appendChild(document.createTextNode(xe)), a.document.head.appendChild(c));
|
|
396
408
|
for (let e of i) r.classList.add(e);
|
|
397
409
|
for (let e of o) r.classList.remove(e);
|
|
398
410
|
s && r.setAttribute(s.key, s.value), d && (a.getComputedStyle(c).opacity, document.head.removeChild(c));
|
|
@@ -400,14 +412,14 @@ function useColorMode(t = {}) {
|
|
|
400
412
|
function v(e) {
|
|
401
413
|
_(n, r, f[e] ?? e);
|
|
402
414
|
}
|
|
403
|
-
function
|
|
415
|
+
function b(e) {
|
|
404
416
|
t.onChanged ? t.onChanged(e, v) : v(e);
|
|
405
417
|
}
|
|
406
|
-
|
|
418
|
+
y(g, b, {
|
|
407
419
|
flush: "post",
|
|
408
420
|
immediate: !0
|
|
409
|
-
}),
|
|
410
|
-
let
|
|
421
|
+
}), U(() => b(g.value));
|
|
422
|
+
let x = e({
|
|
411
423
|
get() {
|
|
412
424
|
return u ? h.value : g.value;
|
|
413
425
|
},
|
|
@@ -415,14 +427,14 @@ function useColorMode(t = {}) {
|
|
|
415
427
|
h.value = e;
|
|
416
428
|
}
|
|
417
429
|
});
|
|
418
|
-
return Object.assign(
|
|
430
|
+
return Object.assign(x, {
|
|
419
431
|
store: h,
|
|
420
432
|
system: m,
|
|
421
433
|
state: g
|
|
422
434
|
});
|
|
423
435
|
}
|
|
424
|
-
function
|
|
425
|
-
let { valueDark: n = "dark", valueLight: r = "" } = t, i =
|
|
436
|
+
function Se(t = {}) {
|
|
437
|
+
let { valueDark: n = "dark", valueLight: r = "" } = t, i = Q({
|
|
426
438
|
...t,
|
|
427
439
|
onChanged: (e, n) => {
|
|
428
440
|
var r;
|
|
@@ -432,8 +444,8 @@ function useDark(t = {}) {
|
|
|
432
444
|
dark: n,
|
|
433
445
|
light: r
|
|
434
446
|
}
|
|
435
|
-
}), a =
|
|
436
|
-
return
|
|
447
|
+
}), a = e(() => i.system.value);
|
|
448
|
+
return e({
|
|
437
449
|
get() {
|
|
438
450
|
return i.value === "dark";
|
|
439
451
|
},
|
|
@@ -443,7 +455,7 @@ function useDark(t = {}) {
|
|
|
443
455
|
}
|
|
444
456
|
});
|
|
445
457
|
}
|
|
446
|
-
|
|
458
|
+
var Ce = W(Se({ storageKey: "gx-theme-appearance" })), $ = {
|
|
447
459
|
theme: { type: String },
|
|
448
460
|
defaultTheme: {
|
|
449
461
|
type: String,
|
|
@@ -452,23 +464,22 @@ const toggleDark = useToggle(useDark({ storageKey: "gx-theme-appearance" })), th
|
|
|
452
464
|
onChange: { type: Function },
|
|
453
465
|
onChangeBase: { type: Function },
|
|
454
466
|
onUpdateTheme: { type: Function }
|
|
455
|
-
}
|
|
456
|
-
var ThemeContext = /* @__PURE__ */ defineComponent({
|
|
467
|
+
}, we = /* @__PURE__ */ n({
|
|
457
468
|
name: "ThemeContext",
|
|
458
469
|
inheritAttrs: !1,
|
|
459
|
-
props:
|
|
470
|
+
props: $,
|
|
460
471
|
slots: Object,
|
|
461
472
|
setup: (t, { slots: n, emit: r }) => {
|
|
462
|
-
let i = document.querySelector("html"), a =
|
|
463
|
-
|
|
473
|
+
let i = document.querySelector("html"), a = f(), o = f(t.theme || t.defaultTheme || "system");
|
|
474
|
+
y(() => t.theme, (e) => {
|
|
464
475
|
e && (o.value = e);
|
|
465
476
|
});
|
|
466
|
-
let { system: s, store: c } =
|
|
467
|
-
|
|
477
|
+
let { system: s, store: c } = Q();
|
|
478
|
+
y(() => s.value, () => {
|
|
468
479
|
l();
|
|
469
|
-
}, { immediate: !0 }),
|
|
480
|
+
}, { immediate: !0 }), y(() => a.value, (e) => {
|
|
470
481
|
e && t.onChangeBase?.(e);
|
|
471
|
-
}, { immediate: !0 }),
|
|
482
|
+
}, { immediate: !0 }), y(o, (e) => {
|
|
472
483
|
t.onChange?.(e), r("update:theme", e), l();
|
|
473
484
|
});
|
|
474
485
|
function l() {
|
|
@@ -477,22 +488,24 @@ var ThemeContext = /* @__PURE__ */ defineComponent({
|
|
|
477
488
|
function u(e) {
|
|
478
489
|
o.value = e, l();
|
|
479
490
|
}
|
|
480
|
-
return
|
|
491
|
+
return ne({
|
|
481
492
|
theme: o,
|
|
482
493
|
resolvedTheme: a,
|
|
483
|
-
isDark:
|
|
494
|
+
isDark: e(() => a.value === "dark"),
|
|
484
495
|
setTheme: u
|
|
485
496
|
}), () => n.default?.();
|
|
486
497
|
}
|
|
487
498
|
});
|
|
488
|
-
|
|
499
|
+
//#endregion
|
|
500
|
+
//#region src/theme-context/utils.ts
|
|
501
|
+
function Te(e, t) {
|
|
489
502
|
if (!(document.startViewTransition && !window.matchMedia("(prefers-reduced-motion: reduce)").matches)) {
|
|
490
503
|
t.setTheme?.(t.isDark ? "dark" : "light");
|
|
491
504
|
return;
|
|
492
505
|
}
|
|
493
506
|
let n = e.getBoundingClientRect(), r = n.left + n.width / 2, i = n.top + n.height / 2, a = Math.hypot(Math.max(r, innerWidth - r), Math.max(i, innerHeight - i)), o = 100 * r / innerWidth, s = 100 * i / innerHeight, l = Math.hypot(innerWidth, innerHeight) / Math.SQRT2, u = 100 * a / l;
|
|
494
507
|
document.startViewTransition(async () => {
|
|
495
|
-
t.setTheme?.(t.isDark ? "dark" : "light"), await
|
|
508
|
+
t.setTheme?.(t.isDark ? "dark" : "light"), await c();
|
|
496
509
|
}).ready.then(() => {
|
|
497
510
|
let e = [`circle(0% at ${o}% ${s}%)`, `circle(${u}% at ${o}% ${s}%)`];
|
|
498
511
|
document.documentElement.animate({ clipPath: t.isDark ? [...e].reverse() : e }, {
|
|
@@ -503,4 +516,5 @@ function toggleAnimateTheme(e, t) {
|
|
|
503
516
|
});
|
|
504
517
|
});
|
|
505
518
|
}
|
|
506
|
-
|
|
519
|
+
//#endregion
|
|
520
|
+
export { ee as ContextProvider, we as ThemeContext, $ as themeContextProps, Te as toggleAnimateTheme, Ce as toggleDark, x as useContext, te as useContextProvider, re as useThemeContext };
|
package/dist/context.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`vue`)):typeof define==`function`&&define.amd?define([`exports`,`vue`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.Context={},e.Vue))})(this,function(e,t){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function n(e,n){let r=Symbol(e);return{provideContext:e=>{(0,t.provide)(r,e)},useInjectContext:e=>(0,t.inject)(r,e||n||{}),contextInjectKey:r}}typeof process<`u`&&process.versions!=null&&process.versions.node;function r(e,t){return Object.prototype.toString.call(e)===`[object ${t}]`}function i(e){return e!==null&&r(e,`Object`)}var a=e=>setTimeout(e,16),o=e=>clearTimeout(e);typeof window<`u`&&`requestAnimationFrame`in window&&(a=e=>window.requestAnimationFrame(e),o=e=>window.cancelAnimationFrame(e));var s=0,c=new Map;function l(e){c.delete(e)}function u(e,t=1){s+=1;let n=s;function r(t){if(t===0)l(n),e();else{let e=a(()=>{r(t-1)});c.set(n,e)}}return r(t),n}u.cancel=e=>{let t=c.get(e);return l(t),o(t)};function d(){let e=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`.split(``);return{uuid(t,n){let r=e,i=[],a=n||r.length,o,s;if(t)for(o=0;o<t;o+=1)i[o]=r[Number.parseInt(String(Math.random()*a))];else for(i[8]=`-`,i[13]=`-`,i[18]=`-`,i[23]=`-`,i[14]=`4`,o=0;o<36;o+=1)i[o]||(s=Math.random()*16,i[o]=r[o===19?s&&3||8:s]);return i.join(``)},uuidFast(){let t=e,n=Array.from({length:36}),r=0,i,a;for(a=0;a<36;a+=1)a===8||a===13||a===18||a===23?n[a]=`-`:a===14?n[a]=`4`:(r<=2&&(r=33554432+Math.random()*16777216||0),i=r&&15,r=r>4,n[a]=t[a===19?i&&3||8:i]);return n.join(``)},uuidString(){return this.uuidFast().replace(/-/g,``)},uuidCompact(){return`xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`.replace(/[xy]/g,e=>{let t=Math.random()*16||0;return(e===`x`?t:t&&3||8).toString(16)})}}}var f=null;function p(e){return f||(f=Symbol(e),f)}let m={contextKey:{type:String,required:!0},value:{type:Object,required:!0}};var h=(0,t.defineComponent)({name:`ContextProvider`,props:m,slots:Object,setup:(e,{slots:n})=>(e.contextKey&&e.value&&i(e.value)?(0,t.provide)(p(e.contextKey),{...(0,t.toRefs)(e.value),contextId:`${e.contextKey}-${d().uuid(10)}`}):console.warn(`[ContextProvider]: contextKey is required`),()=>n.default?.())});function g(e,n){if(typeof f==`symbol`)return(0,t.inject)(p(e),n||{})}let{provideContext:_,useInjectContext:v}=n(`theme-provider`);var y=new WeakMap,b=(...e)=>{let n=e[0],r=(0,t.getCurrentInstance)()?.proxy??(0,t.getCurrentScope)();if(r==null&&!(0,t.hasInjectionContext)())throw Error(`injectLocal must be called in setup`);return r&&y.has(r)&&n in y.get(r)?y.get(r)[n]:(0,t.inject)(...e)},x=typeof window<`u`&&typeof document<`u`;typeof WorkerGlobalScope<`u`&&globalThis instanceof WorkerGlobalScope;var S=Object.prototype.toString,C=e=>S.call(e)===`[object Object]`,w=()=>{};function T(...e){if(e.length!==1)return(0,t.toRef)(...e);let n=e[0];return typeof n==`function`?(0,t.readonly)((0,t.customRef)(()=>({get:n,set:w}))):(0,t.ref)(n)}function E(e,t){function n(...n){return new Promise((r,i)=>{Promise.resolve(e(()=>t.apply(this,n),{fn:t,thisArg:this,args:n})).then(r).catch(i)})}return n}var D=e=>e();function O(e=D,n={}){let{initialState:r=`active`}=n,i=T(r===`active`);function a(){i.value=!1}function o(){i.value=!0}return{isActive:(0,t.readonly)(i),pause:a,resume:o,eventFilter:(...t)=>{i.value&&e(...t)}}}function k(e){return e.endsWith(`rem`)?Number.parseFloat(e)*16:Number.parseFloat(e)}function A(e){return Array.isArray(e)?e:[e]}function j(e){return e||(0,t.getCurrentInstance)()}function M(e,n,r={}){let{eventFilter:i=D,...a}=r;return(0,t.watch)(e,E(i,n),a)}function N(e,t,n={}){let{eventFilter:r,initialState:i=`active`,...a}=n,{eventFilter:o,pause:s,resume:c,isActive:l}=O(r,{initialState:i});return{stop:M(e,t,{...a,eventFilter:o}),pause:s,resume:c,isActive:l}}function P(e,n=!0,r){j(r)?(0,t.onMounted)(e,r):n?e():(0,t.nextTick)(e)}function F(e=!1,n={}){let{truthyValue:r=!0,falsyValue:i=!1}=n,a=(0,t.isRef)(e),o=(0,t.shallowRef)(e);function s(e){if(arguments.length)return o.value=e,o.value;{let e=(0,t.toValue)(r);return o.value=o.value===e?(0,t.toValue)(i):e,o.value}}return a?s:[o,s]}function I(e,n,r){return(0,t.watch)(e,n,{...r,immediate:!0})}var L=x?window:void 0;x&&window.document,x&&window.navigator,x&&window.location;function R(e){let n=(0,t.toValue)(e);return n?.$el??n}function z(...e){let n=(e,t,n,r)=>(e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r)),r=(0,t.computed)(()=>{let n=A((0,t.toValue)(e[0])).filter(e=>e!=null);return n.every(e=>typeof e!=`string`)?n:void 0});return I(()=>[r.value?.map(e=>R(e))??[L].filter(e=>e!=null),A((0,t.toValue)(r.value?e[1]:e[0])),A((0,t.unref)(r.value?e[2]:e[1])),(0,t.toValue)(r.value?e[3]:e[2])],([e,t,r,i],a,o)=>{if(!e?.length||!t?.length||!r?.length)return;let s=C(i)?{...i}:i,c=e.flatMap(e=>t.flatMap(t=>r.map(r=>n(e,t,r,s))));o(()=>{c.forEach(e=>e())})},{flush:`post`})}function B(){let e=(0,t.shallowRef)(!1),n=(0,t.getCurrentInstance)();return n&&(0,t.onMounted)(()=>{e.value=!0},n),e}function V(e){let n=B();return(0,t.computed)(()=>(n.value,!!e()))}var H=Symbol(`vueuse-ssr-width`);function U(){let e=(0,t.hasInjectionContext)()?b(H,null):null;return typeof e==`number`?e:void 0}function W(e,n={}){let{window:r=L,ssrWidth:i=U()}=n,a=V(()=>r&&`matchMedia`in r&&typeof r.matchMedia==`function`),o=(0,t.shallowRef)(typeof i==`number`),s=(0,t.shallowRef)(),c=(0,t.shallowRef)(!1);return(0,t.watchEffect)(()=>{if(o.value){o.value=!a.value,c.value=(0,t.toValue)(e).split(`,`).some(e=>{let t=e.includes(`not all`),n=e.match(/\(\s*min-width:\s*(-?\d+(?:\.\d*)?[a-z]+\s*)\)/),r=e.match(/\(\s*max-width:\s*(-?\d+(?:\.\d*)?[a-z]+\s*)\)/),a=!!(n||r);return n&&a&&(a=i>=k(n[1])),r&&a&&(a=i<=k(r[1])),t?!a:a});return}a.value&&(s.value=r.matchMedia((0,t.toValue)(e)),c.value=s.value.matches)}),z(s,`change`,e=>{c.value=e.matches},{passive:!0}),(0,t.computed)(()=>c.value)}var G=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:{},K=`__vueuse_ssr_handlers__`,q=J();function J(){return K in G||(G[K]=G[K]||{}),G[K]}function Y(e,t){return q[e]||t}function X(e){return W(`(prefers-color-scheme: dark)`,e)}function ee(e){return e==null?`any`:e instanceof Set?`set`:e instanceof Map?`map`:e instanceof Date?`date`:typeof e==`boolean`?`boolean`:typeof e==`string`?`string`:typeof e==`object`?`object`:Number.isNaN(e)?`any`:`number`}var te={boolean:{read:e=>e===`true`,write:e=>String(e)},object:{read:e=>JSON.parse(e),write:e=>JSON.stringify(e)},number:{read:e=>Number.parseFloat(e),write:e=>String(e)},any:{read:e=>e,write:e=>String(e)},string:{read:e=>e,write:e=>String(e)},map:{read:e=>new Map(JSON.parse(e)),write:e=>JSON.stringify(Array.from(e.entries()))},set:{read:e=>new Set(JSON.parse(e)),write:e=>JSON.stringify(Array.from(e))},date:{read:e=>new Date(e),write:e=>e.toISOString()}},Z=`vueuse-storage`;function ne(e,n,r,i={}){let{flush:a=`pre`,deep:o=!0,listenToStorageChanges:s=!0,writeDefaults:c=!0,mergeDefaults:l=!1,shallow:u,window:d=L,eventFilter:f,onError:p=e=>{console.error(e)},initOnMounted:m}=i,h=(u?t.shallowRef:t.ref)(typeof n==`function`?n():n),g=(0,t.computed)(()=>(0,t.toValue)(e));if(!r)try{r=Y(`getDefaultStorage`,()=>L?.localStorage)()}catch(e){p(e)}if(!r)return h;let _=(0,t.toValue)(n),v=ee(_),y=i.serializer??te[v],{pause:b,resume:x}=N(h,e=>w(e),{flush:a,deep:o,eventFilter:f});(0,t.watch)(g,()=>E(),{flush:a});let S=!1;d&&s&&(r instanceof Storage?z(d,`storage`,e=>{m&&!S||E(e)},{passive:!0}):z(d,Z,e=>{m&&!S||D(e)})),m?P(()=>{S=!0,E()}):E();function C(e,t){if(d){let n={key:g.value,oldValue:e,newValue:t,storageArea:r};d.dispatchEvent(r instanceof Storage?new StorageEvent(`storage`,n):new CustomEvent(Z,{detail:n}))}}function w(e){try{let t=r.getItem(g.value);if(e==null)C(t,null),r.removeItem(g.value);else{let n=y.write(e);t!==n&&(r.setItem(g.value,n),C(t,n))}}catch(e){p(e)}}function T(e){let t=e?e.newValue:r.getItem(g.value);if(t==null)return c&&_!=null&&r.setItem(g.value,y.write(_)),_;if(!e&&l){let e=y.read(t);return typeof l==`function`?l(e,_):v===`object`&&!Array.isArray(e)?{..._,...e}:e}else if(typeof t!=`string`)return t;else return y.read(t)}function E(e){if(!(e&&e.storageArea!==r)){if(e&&e.key==null){h.value=_;return}if(!(e&&e.key!==g.value)){b();try{let t=y.write(h.value);(e===void 0||e?.newValue!==t)&&(h.value=T(e))}catch(e){p(e)}finally{e?(0,t.nextTick)(x):x()}}}}function D(e){E(e.detail)}return h}var re=`*,*::before,*::after{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}`;function Q(e={}){let{selector:n=`html`,attribute:r=`class`,initialValue:i=`auto`,window:a=L,storage:o,storageKey:s=`vueuse-color-scheme`,listenToStorageChanges:c=!0,storageRef:l,emitAuto:u,disableTransition:d=!0}=e,f={auto:``,light:`light`,dark:`dark`,...e.modes||{}},p=X({window:a}),m=(0,t.computed)(()=>p.value?`dark`:`light`),h=l||(s==null?T(i):ne(s,i,o,{window:a,listenToStorageChanges:c})),g=(0,t.computed)(()=>h.value===`auto`?m.value:h.value),_=Y(`updateHTMLAttrs`,(e,t,n)=>{let r=typeof e==`string`?a?.document.querySelector(e):R(e);if(!r)return;let i=new Set,o=new Set,s=null;if(t===`class`){let e=n.split(/\s/g);Object.values(f).flatMap(e=>(e||``).split(/\s/g)).filter(Boolean).forEach(t=>{e.includes(t)?i.add(t):o.add(t)})}else s={key:t,value:n};if(i.size===0&&o.size===0&&s===null)return;let c;d&&(c=a.document.createElement(`style`),c.appendChild(document.createTextNode(re)),a.document.head.appendChild(c));for(let e of i)r.classList.add(e);for(let e of o)r.classList.remove(e);s&&r.setAttribute(s.key,s.value),d&&(a.getComputedStyle(c).opacity,document.head.removeChild(c))});function v(e){_(n,r,f[e]??e)}function y(t){e.onChanged?e.onChanged(t,v):v(t)}(0,t.watch)(g,y,{flush:`post`,immediate:!0}),P(()=>y(g.value));let b=(0,t.computed)({get(){return u?h.value:g.value},set(e){h.value=e}});return Object.assign(b,{store:h,system:m,state:g})}function ie(e={}){let{valueDark:n=`dark`,valueLight:r=``}=e,i=Q({...e,onChanged:(t,n)=>{var r;e.onChanged?(r=e.onChanged)==null||r.call(e,t===`dark`,n,t):n(t)},modes:{dark:n,light:r}}),a=(0,t.computed)(()=>i.system.value);return(0,t.computed)({get(){return i.value===`dark`},set(e){let t=e?`dark`:`light`;a.value===t?i.value=`auto`:i.value=t}})}let ae=F(ie({storageKey:`gx-theme-appearance`})),$={theme:{type:String},defaultTheme:{type:String,default:`system`},onChange:{type:Function},onChangeBase:{type:Function},onUpdateTheme:{type:Function}};var oe=(0,t.defineComponent)({name:`ThemeContext`,inheritAttrs:!1,props:$,slots:Object,setup:(e,{slots:n,emit:r})=>{let i=document.querySelector(`html`),a=(0,t.ref)(),o=(0,t.ref)(e.theme||e.defaultTheme||`system`);(0,t.watch)(()=>e.theme,e=>{e&&(o.value=e)});let{system:s,store:c}=Q();(0,t.watch)(()=>s.value,()=>{l()},{immediate:!0}),(0,t.watch)(()=>a.value,t=>{t&&e.onChangeBase?.(t)},{immediate:!0}),(0,t.watch)(o,t=>{e.onChange?.(t),r(`update:theme`,t),l()});function l(){i&&(o.value===`system`?(a.value=s.value,i.setAttribute(`data-theme`,a.value)):(a.value=o.value,i.setAttribute(`data-theme`,o.value)),c.value=a.value)}function u(e){o.value=e,l()}return _({theme:o,resolvedTheme:a,isDark:(0,t.computed)(()=>a.value===`dark`),setTheme:u}),()=>n.default?.()}});function se(e,n){if(!(document.startViewTransition&&!window.matchMedia(`(prefers-reduced-motion: reduce)`).matches)){n.setTheme?.(n.isDark?`dark`:`light`);return}let r=e.getBoundingClientRect(),i=r.left+r.width/2,a=r.top+r.height/2,o=Math.hypot(Math.max(i,innerWidth-i),Math.max(a,innerHeight-a)),s=100*i/innerWidth,c=100*a/innerHeight,l=Math.hypot(innerWidth,innerHeight)/Math.SQRT2,u=100*o/l;document.startViewTransition(async()=>{n.setTheme?.(n.isDark?`dark`:`light`),await(0,t.nextTick)()}).ready.then(()=>{let e=[`circle(0% at ${s}% ${c}%)`,`circle(${u}% at ${s}% ${c}%)`];document.documentElement.animate({clipPath:n.isDark?[...e].reverse():e},{duration:400,fill:`forwards`,easing:`ease-in`,pseudoElement:n.isDark?`::view-transition-old(root)`:`::view-transition-new(root)`})})}e.ContextProvider=h,e.ThemeContext=oe,e.themeContextProps=$,e.toggleAnimateTheme=se,e.toggleDark=ae,e.useContext=n,e.useContextProvider=g,e.useThemeContext=v});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`vue`)):typeof define==`function`&&define.amd?define([`exports`,`vue`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.Context={},e.Vue))})(this,function(e,t){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function n(e,n){let r=Symbol(e);return{provideContext:e=>{(0,t.provide)(r,e)},useInjectContext:e=>(0,t.inject)(r,e||n||{}),contextInjectKey:r}}typeof process<`u`&&process.versions!=null&&process.versions.node;function r(e,t){return Object.prototype.toString.call(e)===`[object ${t}]`}function i(e){return e!==null&&r(e,`Object`)}var a=e=>setTimeout(e,16),o=e=>clearTimeout(e);typeof window<`u`&&`requestAnimationFrame`in window&&(a=e=>window.requestAnimationFrame(e),o=e=>window.cancelAnimationFrame(e));var s=0,c=new Map;function l(e){c.delete(e)}function u(e,t=1){s+=1;let n=s;function r(t){if(t===0)l(n),e();else{let e=a(()=>{r(t-1)});c.set(n,e)}}return r(t),n}u.cancel=e=>{let t=c.get(e);return l(t),o(t)};function d(){let e=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`.split(``);return{uuid(t,n){let r=e,i=[],a=n||r.length,o,s;if(t)for(o=0;o<t;o+=1)i[o]=r[Number.parseInt(String(Math.random()*a))];else for(i[8]=`-`,i[13]=`-`,i[18]=`-`,i[23]=`-`,i[14]=`4`,o=0;o<36;o+=1)i[o]||(s=Math.random()*16,i[o]=r[o===19?s&&3||8:s]);return i.join(``)},uuidFast(){let t=e,n=Array.from({length:36}),r=0,i,a;for(a=0;a<36;a+=1)a===8||a===13||a===18||a===23?n[a]=`-`:a===14?n[a]=`4`:(r<=2&&(r=33554432+Math.random()*16777216||0),i=r&&15,r=r>4,n[a]=t[a===19?i&&3||8:i]);return n.join(``)},uuidString(){return this.uuidFast().replace(/-/g,``)},uuidCompact(){return`xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`.replace(/[xy]/g,e=>{let t=Math.random()*16||0;return(e===`x`?t:t&&3||8).toString(16)})}}}var f=null;function p(e){return f||(f=Symbol(e),f)}var m={contextKey:{type:String,required:!0},value:{type:Object,required:!0}},h=(0,t.defineComponent)({name:`ContextProvider`,props:m,slots:Object,setup:(e,{slots:n})=>(e.contextKey&&e.value&&i(e.value)?(0,t.provide)(p(e.contextKey),{...(0,t.toRefs)(e.value),contextId:`${e.contextKey}-${d().uuid(10)}`}):console.warn(`[ContextProvider]: contextKey is required`),()=>n.default?.())});function g(e,n){if(typeof f==`symbol`)return(0,t.inject)(p(e),n||{})}var{provideContext:_,useInjectContext:v}=n(`theme-provider`),y=new WeakMap,b=(...e)=>{let n=e[0],r=(0,t.getCurrentInstance)()?.proxy??(0,t.getCurrentScope)();if(r==null&&!(0,t.hasInjectionContext)())throw Error(`injectLocal must be called in setup`);return r&&y.has(r)&&n in y.get(r)?y.get(r)[n]:(0,t.inject)(...e)},x=typeof window<`u`&&typeof document<`u`;typeof WorkerGlobalScope<`u`&&globalThis instanceof WorkerGlobalScope;var S=Object.prototype.toString,C=e=>S.call(e)===`[object Object]`,w=()=>{};function T(...e){if(e.length!==1)return(0,t.toRef)(...e);let n=e[0];return typeof n==`function`?(0,t.readonly)((0,t.customRef)(()=>({get:n,set:w}))):(0,t.ref)(n)}function E(e,t){function n(...n){return new Promise((r,i)=>{Promise.resolve(e(()=>t.apply(this,n),{fn:t,thisArg:this,args:n})).then(r).catch(i)})}return n}var D=e=>e();function O(e=D,n={}){let{initialState:r=`active`}=n,i=T(r===`active`);function a(){i.value=!1}function o(){i.value=!0}return{isActive:(0,t.shallowReadonly)(i),pause:a,resume:o,eventFilter:(...t)=>{i.value&&e(...t)}}}function k(e){return e.endsWith(`rem`)?Number.parseFloat(e)*16:Number.parseFloat(e)}function A(e){return Array.isArray(e)?e:[e]}function j(e){return e||(0,t.getCurrentInstance)()}function M(e,n,r={}){let{eventFilter:i=D,...a}=r;return(0,t.watch)(e,E(i,n),a)}function N(e,t,n={}){let{eventFilter:r,initialState:i=`active`,...a}=n,{eventFilter:o,pause:s,resume:c,isActive:l}=O(r,{initialState:i});return{stop:M(e,t,{...a,eventFilter:o}),pause:s,resume:c,isActive:l}}function P(e,n=!0,r){j(r)?(0,t.onMounted)(e,r):n?e():(0,t.nextTick)(e)}function F(e=!1,n={}){let{truthyValue:r=!0,falsyValue:i=!1}=n,a=(0,t.isRef)(e),o=(0,t.shallowRef)(e);function s(e){if(arguments.length)return o.value=e,o.value;{let e=(0,t.toValue)(r);return o.value=o.value===e?(0,t.toValue)(i):e,o.value}}return a?s:[o,s]}function I(e,n,r){return(0,t.watch)(e,n,{...r,immediate:!0})}var L=x?window:void 0;x&&window.document,x&&window.navigator,x&&window.location;function R(e){let n=(0,t.toValue)(e);return n?.$el??n}function z(...e){let n=(e,t,n,r)=>(e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r)),r=(0,t.computed)(()=>{let n=A((0,t.toValue)(e[0])).filter(e=>e!=null);return n.every(e=>typeof e!=`string`)?n:void 0});return I(()=>[r.value?.map(e=>R(e))??[L].filter(e=>e!=null),A((0,t.toValue)(r.value?e[1]:e[0])),A((0,t.unref)(r.value?e[2]:e[1])),(0,t.toValue)(r.value?e[3]:e[2])],([e,t,r,i],a,o)=>{if(!e?.length||!t?.length||!r?.length)return;let s=C(i)?{...i}:i,c=e.flatMap(e=>t.flatMap(t=>r.map(r=>n(e,t,r,s))));o(()=>{c.forEach(e=>e())})},{flush:`post`})}function B(){let e=(0,t.shallowRef)(!1),n=(0,t.getCurrentInstance)();return n&&(0,t.onMounted)(()=>{e.value=!0},n),e}function V(e){let n=B();return(0,t.computed)(()=>(n.value,!!e()))}var H=Symbol(`vueuse-ssr-width`);function U(){let e=(0,t.hasInjectionContext)()?b(H,null):null;return typeof e==`number`?e:void 0}function W(e,n={}){let{window:r=L,ssrWidth:i=U()}=n,a=V(()=>r&&`matchMedia`in r&&typeof r.matchMedia==`function`),o=(0,t.shallowRef)(typeof i==`number`),s=(0,t.shallowRef)(),c=(0,t.shallowRef)(!1);return(0,t.watchEffect)(()=>{if(o.value){o.value=!a.value,c.value=(0,t.toValue)(e).split(`,`).some(e=>{let t=e.includes(`not all`),n=e.match(/\(\s*min-width:\s*(-?\d+(?:\.\d*)?[a-z]+\s*)\)/),r=e.match(/\(\s*max-width:\s*(-?\d+(?:\.\d*)?[a-z]+\s*)\)/),a=!!(n||r);return n&&a&&(a=i>=k(n[1])),r&&a&&(a=i<=k(r[1])),t?!a:a});return}a.value&&(s.value=r.matchMedia((0,t.toValue)(e)),c.value=s.value.matches)}),z(s,`change`,e=>{c.value=e.matches},{passive:!0}),(0,t.computed)(()=>c.value)}var G=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:{},K=`__vueuse_ssr_handlers__`,q=J();function J(){return K in G||(G[K]=G[K]||{}),G[K]}function Y(e,t){return q[e]||t}function X(e){return W(`(prefers-color-scheme: dark)`,e)}function ee(e){return e==null?`any`:e instanceof Set?`set`:e instanceof Map?`map`:e instanceof Date?`date`:typeof e==`boolean`?`boolean`:typeof e==`string`?`string`:typeof e==`object`?`object`:Number.isNaN(e)?`any`:`number`}var te={boolean:{read:e=>e===`true`,write:e=>String(e)},object:{read:e=>JSON.parse(e),write:e=>JSON.stringify(e)},number:{read:e=>Number.parseFloat(e),write:e=>String(e)},any:{read:e=>e,write:e=>String(e)},string:{read:e=>e,write:e=>String(e)},map:{read:e=>new Map(JSON.parse(e)),write:e=>JSON.stringify(Array.from(e.entries()))},set:{read:e=>new Set(JSON.parse(e)),write:e=>JSON.stringify(Array.from(e))},date:{read:e=>new Date(e),write:e=>e.toISOString()}},Z=`vueuse-storage`;function ne(e,n,r,i={}){let{flush:a=`pre`,deep:o=!0,listenToStorageChanges:s=!0,writeDefaults:c=!0,mergeDefaults:l=!1,shallow:u,window:d=L,eventFilter:f,onError:p=e=>{console.error(e)},initOnMounted:m}=i,h=(u?t.shallowRef:t.ref)(typeof n==`function`?n():n),g=(0,t.computed)(()=>(0,t.toValue)(e));if(!r)try{r=Y(`getDefaultStorage`,()=>L?.localStorage)()}catch(e){p(e)}if(!r)return h;let _=(0,t.toValue)(n),v=ee(_),y=i.serializer??te[v],{pause:b,resume:x}=N(h,e=>w(e),{flush:a,deep:o,eventFilter:f});(0,t.watch)(g,()=>E(),{flush:a});let S=!1;d&&s&&(r instanceof Storage?z(d,`storage`,e=>{m&&!S||E(e)},{passive:!0}):z(d,Z,e=>{m&&!S||D(e)})),m?P(()=>{S=!0,E()}):E();function C(e,t){if(d){let n={key:g.value,oldValue:e,newValue:t,storageArea:r};d.dispatchEvent(r instanceof Storage?new StorageEvent(`storage`,n):new CustomEvent(Z,{detail:n}))}}function w(e){try{let t=r.getItem(g.value);if(e==null)C(t,null),r.removeItem(g.value);else{let n=y.write(e);t!==n&&(r.setItem(g.value,n),C(t,n))}}catch(e){p(e)}}function T(e){let t=e?e.newValue:r.getItem(g.value);if(t==null)return c&&_!=null&&r.setItem(g.value,y.write(_)),_;if(!e&&l){let e=y.read(t);return typeof l==`function`?l(e,_):v===`object`&&!Array.isArray(e)?{..._,...e}:e}else if(typeof t!=`string`)return t;else return y.read(t)}function E(e){if(!(e&&e.storageArea!==r)){if(e&&e.key==null){h.value=_;return}if(!(e&&e.key!==g.value)){b();try{let t=y.write(h.value);(e===void 0||e?.newValue!==t)&&(h.value=T(e))}catch(e){p(e)}finally{e?(0,t.nextTick)(x):x()}}}}function D(e){E(e.detail)}return h}var re=`*,*::before,*::after{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}`;function Q(e={}){let{selector:n=`html`,attribute:r=`class`,initialValue:i=`auto`,window:a=L,storage:o,storageKey:s=`vueuse-color-scheme`,listenToStorageChanges:c=!0,storageRef:l,emitAuto:u,disableTransition:d=!0}=e,f={auto:``,light:`light`,dark:`dark`,...e.modes||{}},p=X({window:a}),m=(0,t.computed)(()=>p.value?`dark`:`light`),h=l||(s==null?T(i):ne(s,i,o,{window:a,listenToStorageChanges:c})),g=(0,t.computed)(()=>h.value===`auto`?m.value:h.value),_=Y(`updateHTMLAttrs`,(e,t,n)=>{let r=typeof e==`string`?a?.document.querySelector(e):R(e);if(!r)return;let i=new Set,o=new Set,s=null;if(t===`class`){let e=n.split(/\s/g);Object.values(f).flatMap(e=>(e||``).split(/\s/g)).filter(Boolean).forEach(t=>{e.includes(t)?i.add(t):o.add(t)})}else s={key:t,value:n};if(i.size===0&&o.size===0&&s===null)return;let c;d&&(c=a.document.createElement(`style`),c.appendChild(document.createTextNode(re)),a.document.head.appendChild(c));for(let e of i)r.classList.add(e);for(let e of o)r.classList.remove(e);s&&r.setAttribute(s.key,s.value),d&&(a.getComputedStyle(c).opacity,document.head.removeChild(c))});function v(e){_(n,r,f[e]??e)}function y(t){e.onChanged?e.onChanged(t,v):v(t)}(0,t.watch)(g,y,{flush:`post`,immediate:!0}),P(()=>y(g.value));let b=(0,t.computed)({get(){return u?h.value:g.value},set(e){h.value=e}});return Object.assign(b,{store:h,system:m,state:g})}function ie(e={}){let{valueDark:n=`dark`,valueLight:r=``}=e,i=Q({...e,onChanged:(t,n)=>{var r;e.onChanged?(r=e.onChanged)==null||r.call(e,t===`dark`,n,t):n(t)},modes:{dark:n,light:r}}),a=(0,t.computed)(()=>i.system.value);return(0,t.computed)({get(){return i.value===`dark`},set(e){let t=e?`dark`:`light`;a.value===t?i.value=`auto`:i.value=t}})}var ae=F(ie({storageKey:`gx-theme-appearance`})),$={theme:{type:String},defaultTheme:{type:String,default:`system`},onChange:{type:Function},onChangeBase:{type:Function},onUpdateTheme:{type:Function}},oe=(0,t.defineComponent)({name:`ThemeContext`,inheritAttrs:!1,props:$,slots:Object,setup:(e,{slots:n,emit:r})=>{let i=document.querySelector(`html`),a=(0,t.ref)(),o=(0,t.ref)(e.theme||e.defaultTheme||`system`);(0,t.watch)(()=>e.theme,e=>{e&&(o.value=e)});let{system:s,store:c}=Q();(0,t.watch)(()=>s.value,()=>{l()},{immediate:!0}),(0,t.watch)(()=>a.value,t=>{t&&e.onChangeBase?.(t)},{immediate:!0}),(0,t.watch)(o,t=>{e.onChange?.(t),r(`update:theme`,t),l()});function l(){i&&(o.value===`system`?(a.value=s.value,i.setAttribute(`data-theme`,a.value)):(a.value=o.value,i.setAttribute(`data-theme`,o.value)),c.value=a.value)}function u(e){o.value=e,l()}return _({theme:o,resolvedTheme:a,isDark:(0,t.computed)(()=>a.value===`dark`),setTheme:u}),()=>n.default?.()}});function se(e,n){if(!(document.startViewTransition&&!window.matchMedia(`(prefers-reduced-motion: reduce)`).matches)){n.setTheme?.(n.isDark?`dark`:`light`);return}let r=e.getBoundingClientRect(),i=r.left+r.width/2,a=r.top+r.height/2,o=Math.hypot(Math.max(i,innerWidth-i),Math.max(a,innerHeight-a)),s=100*i/innerWidth,c=100*a/innerHeight,l=Math.hypot(innerWidth,innerHeight)/Math.SQRT2,u=100*o/l;document.startViewTransition(async()=>{n.setTheme?.(n.isDark?`dark`:`light`),await(0,t.nextTick)()}).ready.then(()=>{let e=[`circle(0% at ${s}% ${c}%)`,`circle(${u}% at ${s}% ${c}%)`];document.documentElement.animate({clipPath:n.isDark?[...e].reverse():e},{duration:400,fill:`forwards`,easing:`ease-in`,pseudoElement:n.isDark?`::view-transition-old(root)`:`::view-transition-new(root)`})})}e.ContextProvider=h,e.ThemeContext=oe,e.themeContextProps=$,e.toggleAnimateTheme=se,e.toggleDark=ae,e.useContext=n,e.useContextProvider=g,e.useThemeContext=v});
|
package/dist/index.d.ts
CHANGED
|
@@ -5,5 +5,4 @@ import { useThemeContext } from "./theme-context/context.js";
|
|
|
5
5
|
import { toggleDark } from "./theme-context/dark.js";
|
|
6
6
|
import ThemeContext, { ThemeContextEmits, ThemeContextProps, ThemeContextSlots, themeContextProps } from "./theme-context/ThemeContext.js";
|
|
7
7
|
import { toggleAnimateTheme } from "./theme-context/utils.js";
|
|
8
|
-
import "./theme-context/index.js";
|
|
9
8
|
export { BaseTheme, ContextProvider, ThemeContext, ThemeContextEmits, ThemeContextProps, ThemeContextSlots, ThemeProviderContext, ThemeValue, themeContextProps, toggleAnimateTheme, toggleDark, useContext, useContextProvider, useThemeContext };
|
package/dist/index.js
CHANGED
|
@@ -2,8 +2,7 @@ import { useContext } from "./context/index.js";
|
|
|
2
2
|
import { ContextProvider, useContextProvider } from "./context/ContextProvider.js";
|
|
3
3
|
import { useThemeContext } from "./theme-context/context.js";
|
|
4
4
|
import { toggleDark } from "./theme-context/dark.js";
|
|
5
|
-
import
|
|
5
|
+
import ThemeContext, { themeContextProps } from "./theme-context/ThemeContext.js";
|
|
6
6
|
import { toggleAnimateTheme } from "./theme-context/utils.js";
|
|
7
7
|
import "./theme-context/index.js";
|
|
8
|
-
|
|
9
|
-
export { ContextProvider, ThemeContext_default as ThemeContext, themeContextProps, toggleAnimateTheme, toggleDark, useContext, useContextProvider, useThemeContext };
|
|
8
|
+
export { ContextProvider, ThemeContext, themeContextProps, toggleAnimateTheme, toggleDark, useContext, useContextProvider, useThemeContext };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseTheme, ThemeValue } from "./types.js";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _$vue from "vue";
|
|
3
3
|
import { PropType, SlotsType } from "vue";
|
|
4
4
|
|
|
5
5
|
//#region src/theme-context/ThemeContext.d.ts
|
|
@@ -36,7 +36,7 @@ declare const themeContextProps: {
|
|
|
36
36
|
type: PropType<(theme: ThemeValue) => void>;
|
|
37
37
|
};
|
|
38
38
|
};
|
|
39
|
-
declare const ThemeContext:
|
|
39
|
+
declare const ThemeContext: _$vue.DefineComponent<_$vue.ExtractPropTypes<{
|
|
40
40
|
theme: {
|
|
41
41
|
type: PropType<ThemeValue>;
|
|
42
42
|
};
|
|
@@ -53,7 +53,7 @@ declare const ThemeContext: vue0.DefineComponent<vue0.ExtractPropTypes<{
|
|
|
53
53
|
onUpdateTheme: {
|
|
54
54
|
type: PropType<(theme: ThemeValue) => void>;
|
|
55
55
|
};
|
|
56
|
-
}>, () => any, {}, {}, {},
|
|
56
|
+
}>, () => any, {}, {}, {}, _$vue.ComponentOptionsMixin, _$vue.ComponentOptionsMixin, {}, string, _$vue.PublicProps, Readonly<_$vue.ExtractPropTypes<{
|
|
57
57
|
theme: {
|
|
58
58
|
type: PropType<ThemeValue>;
|
|
59
59
|
};
|
|
@@ -72,6 +72,6 @@ declare const ThemeContext: vue0.DefineComponent<vue0.ExtractPropTypes<{
|
|
|
72
72
|
};
|
|
73
73
|
}>> & Readonly<{}>, {
|
|
74
74
|
defaultTheme: ThemeValue;
|
|
75
|
-
}, SlotsType<ThemeContextSlots>, {}, {}, string,
|
|
75
|
+
}, SlotsType<ThemeContextSlots>, {}, {}, string, _$vue.ComponentProvideOptions, true, {}, any>;
|
|
76
76
|
//#endregion
|
|
77
77
|
export { ThemeContextEmits, ThemeContextProps, ThemeContextSlots, ThemeContext as default, themeContextProps };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { createThemeContext } from "./context.js";
|
|
2
2
|
import { computed, defineComponent, ref, watch } from "vue";
|
|
3
3
|
import { useColorMode } from "@vueuse/core";
|
|
4
|
-
|
|
5
4
|
//#region src/theme-context/ThemeContext.tsx
|
|
6
5
|
const themeContextProps = {
|
|
7
6
|
theme: { type: String },
|
|
@@ -62,7 +61,5 @@ const ThemeContext = /* @__PURE__ */ defineComponent({
|
|
|
62
61
|
return () => slots.default?.();
|
|
63
62
|
}
|
|
64
63
|
});
|
|
65
|
-
var ThemeContext_default = ThemeContext;
|
|
66
|
-
|
|
67
64
|
//#endregion
|
|
68
|
-
export {
|
|
65
|
+
export { ThemeContext as default, themeContextProps };
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { useContext } from "../context/index.js";
|
|
2
|
-
|
|
3
2
|
//#region src/theme-context/context.ts
|
|
4
3
|
const { provideContext: createThemeContext, useInjectContext: useThemeContext } = useContext("theme-provider");
|
|
5
|
-
|
|
6
4
|
//#endregion
|
|
7
|
-
export { createThemeContext, useThemeContext };
|
|
5
|
+
export { createThemeContext, useThemeContext };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as _vueuse_core0 from "@vueuse/core";
|
|
1
|
+
import * as _$_vueuse_core0 from "@vueuse/core";
|
|
2
2
|
|
|
3
3
|
//#region src/theme-context/dark.d.ts
|
|
4
|
-
declare const isDark: _vueuse_core0.UseDarkReturn;
|
|
4
|
+
declare const isDark: _$_vueuse_core0.UseDarkReturn;
|
|
5
5
|
declare const toggleDark: (value?: boolean) => boolean;
|
|
6
6
|
//#endregion
|
|
7
7
|
export { isDark, toggleDark };
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { useDark, useToggle } from "@vueuse/core";
|
|
2
|
-
|
|
3
2
|
//#region src/theme-context/dark.ts
|
|
4
3
|
const isDark = useDark({ storageKey: "gx-theme-appearance" });
|
|
5
4
|
const toggleDark = useToggle(isDark);
|
|
6
|
-
|
|
7
5
|
//#endregion
|
|
8
|
-
export { isDark, toggleDark };
|
|
6
|
+
export { isDark, toggleDark };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { useThemeContext } from "./context.js";
|
|
2
2
|
import { toggleDark } from "./dark.js";
|
|
3
|
-
import
|
|
3
|
+
import ThemeContext, { themeContextProps } from "./ThemeContext.js";
|
|
4
4
|
import { toggleAnimateTheme } from "./utils.js";
|
|
5
|
-
|
|
6
|
-
export { ThemeContext_default as ThemeContext, themeContextProps, toggleAnimateTheme, toggleDark, useThemeContext };
|
|
5
|
+
export { ThemeContext, themeContextProps, toggleAnimateTheme, toggleDark, useThemeContext };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { nextTick } from "vue";
|
|
2
|
-
|
|
3
2
|
//#region src/theme-context/utils.ts
|
|
4
3
|
function toggleAnimateTheme(el, props) {
|
|
5
4
|
if (!(document.startViewTransition && !window.matchMedia("(prefers-reduced-motion: reduce)").matches)) {
|
|
@@ -27,6 +26,5 @@ function toggleAnimateTheme(el, props) {
|
|
|
27
26
|
});
|
|
28
27
|
});
|
|
29
28
|
}
|
|
30
|
-
|
|
31
29
|
//#endregion
|
|
32
|
-
export { toggleAnimateTheme };
|
|
30
|
+
export { toggleAnimateTheme };
|
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.5-alpha.
|
|
4
|
+
"version": "0.0.5-alpha.3",
|
|
5
5
|
"description": "Gx Design Context",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "gx12358",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"vue": ">=3.2.0"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@vueuse/core": "^14.
|
|
44
|
-
"@gx-design-vue/pro-utils": "0.2.0-alpha.
|
|
43
|
+
"@vueuse/core": "^14.3.0",
|
|
44
|
+
"@gx-design-vue/pro-utils": "^0.2.0-alpha.3"
|
|
45
45
|
},
|
|
46
46
|
"browserslist": [
|
|
47
47
|
"> 1%",
|