@delta-comic/plugin 0.0.1 → 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/index.js +80 -23
- package/dist/index.js.map +1 -1
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/plugin/index.d.ts +3 -0
- package/dist/pack.tgz +0 -0
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { SharedFunction } from "@delta-comic/core";
|
|
2
1
|
import { useNativeStore } from "@delta-comic/db";
|
|
3
2
|
import { useGlobalVar } from "@delta-comic/utils";
|
|
4
3
|
import { computed, getCurrentInstance, getCurrentScope, hasInjectionContext, inject, onMounted, shallowReactive, shallowRef, toValue, unref, watch, watchEffect } from "vue";
|
|
5
4
|
import { defineStore } from "pinia";
|
|
5
|
+
import { SourcedKeyMap } from "@delta-comic/model";
|
|
6
6
|
function isLength(e) {
|
|
7
7
|
return Number.isSafeInteger(e) && e >= 0;
|
|
8
8
|
}
|
|
@@ -27,10 +27,31 @@ function fromPairs(e) {
|
|
|
27
27
|
function isFunction(e) {
|
|
28
28
|
return typeof e == "function";
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
function mitt_default(e) {
|
|
31
|
+
return {
|
|
32
|
+
all: e ||= /* @__PURE__ */ new Map(),
|
|
33
|
+
on: function(t, n) {
|
|
34
|
+
var r = e.get(t);
|
|
35
|
+
r ? r.push(n) : e.set(t, [n]);
|
|
36
|
+
},
|
|
37
|
+
off: function(t, n) {
|
|
38
|
+
var r = e.get(t);
|
|
39
|
+
r && (n ? r.splice(r.indexOf(n) >>> 0, 1) : e.set(t, []));
|
|
40
|
+
},
|
|
41
|
+
emit: function(t, n) {
|
|
42
|
+
var r = e.get(t);
|
|
43
|
+
r && r.slice().map(function(e) {
|
|
44
|
+
e(n);
|
|
45
|
+
}), (r = e.get("*")) && r.slice().map(function(e) {
|
|
46
|
+
e(t, n);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const pluginEmitter = mitt_default(), definePlugin = async (e) => {
|
|
52
|
+
if (isFunction(e)) var t = e(window.$$safe$$);
|
|
53
|
+
else var t = e;
|
|
54
|
+
return console.log("[definePlugin] new plugin defining...", t), await pluginEmitter.emit("definedPlugin", t), t;
|
|
34
55
|
}, decodePluginMeta = (e) => ({
|
|
35
56
|
name: {
|
|
36
57
|
display: e["name:display"],
|
|
@@ -79,15 +100,15 @@ function unrefElement(e) {
|
|
|
79
100
|
return t?.$el ?? t;
|
|
80
101
|
}
|
|
81
102
|
function useEventListener(...e) {
|
|
82
|
-
let t = (e, t, n, r) => (e.addEventListener(t, n, r), () => e.removeEventListener(t, n, r)),
|
|
103
|
+
let t = (e, t, n, r) => (e.addEventListener(t, n, r), () => e.removeEventListener(t, n, r)), r = computed(() => {
|
|
83
104
|
let t = toArray(toValue(e[0])).filter((e) => e != null);
|
|
84
105
|
return t.every((e) => typeof e != "string") ? t : void 0;
|
|
85
106
|
});
|
|
86
107
|
return watchImmediate(() => [
|
|
87
|
-
|
|
88
|
-
toArray(toValue(
|
|
89
|
-
toArray(unref(
|
|
90
|
-
toValue(
|
|
108
|
+
r.value?.map((e) => unrefElement(e)) ?? [defaultWindow].filter((e) => e != null),
|
|
109
|
+
toArray(toValue(r.value ? e[1] : e[0])),
|
|
110
|
+
toArray(unref(r.value ? e[2] : e[1])),
|
|
111
|
+
toValue(r.value ? e[3] : e[2])
|
|
91
112
|
], ([e, n, r, i], a, o) => {
|
|
92
113
|
if (!e?.length || !n?.length || !r?.length) return;
|
|
93
114
|
let s = isObject(i) ? { ...i } : i, c = e.flatMap((e) => n.flatMap((n) => r.map((r) => t(e, n, r, s))));
|
|
@@ -114,7 +135,7 @@ function useSSRWidth() {
|
|
|
114
135
|
return typeof e == "number" ? e : void 0;
|
|
115
136
|
}
|
|
116
137
|
function useMediaQuery(e, t = {}) {
|
|
117
|
-
let { window:
|
|
138
|
+
let { window: r = defaultWindow, ssrWidth: i = /* @__PURE__ */ useSSRWidth() } = t, a = /* @__PURE__ */ useSupported(() => r && "matchMedia" in r && typeof r.matchMedia == "function"), o = shallowRef(typeof i == "number"), s = shallowRef(), c = shallowRef(!1);
|
|
118
139
|
return watchEffect(() => {
|
|
119
140
|
if (o.value) {
|
|
120
141
|
o.value = !a.value, c.value = toValue(e).split(",").some((e) => {
|
|
@@ -123,7 +144,7 @@ function useMediaQuery(e, t = {}) {
|
|
|
123
144
|
});
|
|
124
145
|
return;
|
|
125
146
|
}
|
|
126
|
-
a.value && (s.value =
|
|
147
|
+
a.value && (s.value = r.matchMedia(toValue(e)), c.value = s.value.matches);
|
|
127
148
|
}), useEventListener(s, "change", (e) => {
|
|
128
149
|
c.value = e.matches;
|
|
129
150
|
}, { passive: !0 }), computed(() => c.value);
|
|
@@ -179,9 +200,9 @@ const appConfig = useGlobalVar(new ConfigPointer("core", {
|
|
|
179
200
|
info: "github的token",
|
|
180
201
|
placeholder: "仅用于解除api访问限制"
|
|
181
202
|
}
|
|
182
|
-
}, "核心"), "core/plugin/config"), useConfig = defineStore("config", (
|
|
183
|
-
let
|
|
184
|
-
let t =
|
|
203
|
+
}, "核心"), "core/plugin/config"), useConfig = defineStore("config", (t) => {
|
|
204
|
+
let r = shallowReactive(/* @__PURE__ */ new Map()), i = t.action((e) => {
|
|
205
|
+
let t = r.get(e.key);
|
|
185
206
|
if (!t) throw Error(`not found config by plugin "${e.pluginName}"`);
|
|
186
207
|
return t.value;
|
|
187
208
|
}, "load"), a = usePreferredDark(), o = computed(() => {
|
|
@@ -192,21 +213,57 @@ const appConfig = useGlobalVar(new ConfigPointer("core", {
|
|
|
192
213
|
case "system": return a.value;
|
|
193
214
|
default: return !1;
|
|
194
215
|
}
|
|
195
|
-
}), s =
|
|
216
|
+
}), s = t.action((e) => r.has(e.key), "isExistConfig");
|
|
196
217
|
return {
|
|
197
218
|
isDark: o,
|
|
198
|
-
form:
|
|
219
|
+
form: r,
|
|
199
220
|
$load: i,
|
|
200
221
|
$isExistConfig: s,
|
|
201
|
-
$resignerConfig:
|
|
202
|
-
let n = useConfig(), r = useNativeStore(
|
|
203
|
-
n.form.set(
|
|
204
|
-
form:
|
|
222
|
+
$resignerConfig: t.action((t) => {
|
|
223
|
+
let n = useConfig(), r = useNativeStore(t.pluginName, "config", fromPairs(Object.entries(t.config).map(([e, t]) => [e, t.defaultValue])));
|
|
224
|
+
n.form.set(t.key, {
|
|
225
|
+
form: t.config,
|
|
205
226
|
value: r
|
|
206
227
|
});
|
|
207
228
|
}, "resignerConfig")
|
|
208
229
|
};
|
|
209
|
-
}), declareDepType = (e) => Symbol.for(`expose:${e}`), require = (e) => pluginExposes.get(e), pluginExposes = /* @__PURE__ */ new Map()
|
|
210
|
-
|
|
230
|
+
}), declareDepType = (e) => Symbol.for(`expose:${e}`), require = (e) => pluginExposes.get(e), pluginExposes = /* @__PURE__ */ new Map(), Global = useGlobalVar(new class {
|
|
231
|
+
share = shallowReactive(SourcedKeyMap.create());
|
|
232
|
+
shareToken = shallowReactive(SourcedKeyMap.create());
|
|
233
|
+
userActions = shallowReactive(SourcedKeyMap.create());
|
|
234
|
+
subscribes = shallowReactive(SourcedKeyMap.create());
|
|
235
|
+
globalNodes = shallowReactive([]);
|
|
236
|
+
tabbar = shallowReactive(/* @__PURE__ */ new Map());
|
|
237
|
+
addTabbar(e, ...t) {
|
|
238
|
+
let n = this.tabbar.get(e) ?? [];
|
|
239
|
+
this.tabbar.set(e, n.concat(t));
|
|
240
|
+
}
|
|
241
|
+
categories = shallowReactive(/* @__PURE__ */ new Map());
|
|
242
|
+
addCategories(e, ...t) {
|
|
243
|
+
let n = this.categories.get(e) ?? [];
|
|
244
|
+
this.categories.set(e, n.concat(t));
|
|
245
|
+
}
|
|
246
|
+
barcode = shallowReactive(/* @__PURE__ */ new Map());
|
|
247
|
+
addBarcode(e, ...t) {
|
|
248
|
+
let n = this.barcode.get(e) ?? [];
|
|
249
|
+
this.barcode.set(e, n.concat(t));
|
|
250
|
+
}
|
|
251
|
+
levelboard = shallowReactive(/* @__PURE__ */ new Map());
|
|
252
|
+
addLevelboard(e, ...t) {
|
|
253
|
+
let n = this.levelboard.get(e) ?? [];
|
|
254
|
+
this.levelboard.set(e, n.concat(t));
|
|
255
|
+
}
|
|
256
|
+
topButton = shallowReactive(/* @__PURE__ */ new Map());
|
|
257
|
+
addTopButton(e, ...t) {
|
|
258
|
+
let n = this.topButton.get(e) ?? [];
|
|
259
|
+
this.topButton.set(e, n.concat(t));
|
|
260
|
+
}
|
|
261
|
+
mainLists = shallowReactive(/* @__PURE__ */ new Map());
|
|
262
|
+
addMainList(e, ...t) {
|
|
263
|
+
let n = this.mainLists.get(e) ?? [];
|
|
264
|
+
this.mainLists.set(e, n.concat(t));
|
|
265
|
+
}
|
|
266
|
+
}(), "core/global");
|
|
267
|
+
export { ConfigPointer, Global, appConfig, declareDepType, decodePluginMeta, definePlugin, pluginEmitter, pluginExposes, require, useConfig };
|
|
211
268
|
|
|
212
269
|
//# sourceMappingURL=index.js.map
|