@delta-comic/plugin 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/index.js CHANGED
@@ -1,4 +1,3 @@
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";
@@ -28,10 +27,31 @@ function fromPairs(e) {
28
27
  function isFunction(e) {
29
28
  return typeof e == "function";
30
29
  }
31
- const definePlugin = async (t) => {
32
- if (isFunction(t)) var n = t(window.$$safe$$);
33
- else var n = t;
34
- return console.log("[definePlugin] new plugin defining...", n), await SharedFunction.call("addPlugin", n), n;
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;
35
55
  }, decodePluginMeta = (e) => ({
36
56
  name: {
37
57
  display: e["name:display"],
@@ -80,15 +100,15 @@ function unrefElement(e) {
80
100
  return t?.$el ?? t;
81
101
  }
82
102
  function useEventListener(...e) {
83
- let t = (e, t, n, r) => (e.addEventListener(t, n, r), () => e.removeEventListener(t, n, r)), n = computed(() => {
103
+ let t = (e, t, n, r) => (e.addEventListener(t, n, r), () => e.removeEventListener(t, n, r)), r = computed(() => {
84
104
  let t = toArray(toValue(e[0])).filter((e) => e != null);
85
105
  return t.every((e) => typeof e != "string") ? t : void 0;
86
106
  });
87
107
  return watchImmediate(() => [
88
- n.value?.map((e) => unrefElement(e)) ?? [defaultWindow].filter((e) => e != null),
89
- toArray(toValue(n.value ? e[1] : e[0])),
90
- toArray(unref(n.value ? e[2] : e[1])),
91
- toValue(n.value ? e[3] : e[2])
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])
92
112
  ], ([e, n, r, i], a, o) => {
93
113
  if (!e?.length || !n?.length || !r?.length) return;
94
114
  let s = isObject(i) ? { ...i } : i, c = e.flatMap((e) => n.flatMap((n) => r.map((r) => t(e, n, r, s))));
@@ -115,7 +135,7 @@ function useSSRWidth() {
115
135
  return typeof e == "number" ? e : void 0;
116
136
  }
117
137
  function useMediaQuery(e, t = {}) {
118
- let { window: n = defaultWindow, ssrWidth: i = /* @__PURE__ */ useSSRWidth() } = t, a = /* @__PURE__ */ useSupported(() => n && "matchMedia" in n && typeof n.matchMedia == "function"), o = shallowRef(typeof i == "number"), s = shallowRef(), c = shallowRef(!1);
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);
119
139
  return watchEffect(() => {
120
140
  if (o.value) {
121
141
  o.value = !a.value, c.value = toValue(e).split(",").some((e) => {
@@ -124,7 +144,7 @@ function useMediaQuery(e, t = {}) {
124
144
  });
125
145
  return;
126
146
  }
127
- a.value && (s.value = n.matchMedia(toValue(e)), c.value = s.value.matches);
147
+ a.value && (s.value = r.matchMedia(toValue(e)), c.value = s.value.matches);
128
148
  }), useEventListener(s, "change", (e) => {
129
149
  c.value = e.matches;
130
150
  }, { passive: !0 }), computed(() => c.value);
@@ -180,9 +200,9 @@ const appConfig = useGlobalVar(new ConfigPointer("core", {
180
200
  info: "github的token",
181
201
  placeholder: "仅用于解除api访问限制"
182
202
  }
183
- }, "核心"), "core/plugin/config"), useConfig = defineStore("config", (e) => {
184
- let n = shallowReactive(/* @__PURE__ */ new Map()), i = e.action((e) => {
185
- let t = n.get(e.key);
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);
186
206
  if (!t) throw Error(`not found config by plugin "${e.pluginName}"`);
187
207
  return t.value;
188
208
  }, "load"), a = usePreferredDark(), o = computed(() => {
@@ -193,16 +213,16 @@ const appConfig = useGlobalVar(new ConfigPointer("core", {
193
213
  case "system": return a.value;
194
214
  default: return !1;
195
215
  }
196
- }), s = e.action((e) => n.has(e.key), "isExistConfig");
216
+ }), s = t.action((e) => r.has(e.key), "isExistConfig");
197
217
  return {
198
218
  isDark: o,
199
- form: n,
219
+ form: r,
200
220
  $load: i,
201
221
  $isExistConfig: s,
202
- $resignerConfig: e.action((e) => {
203
- let n = useConfig(), r = useNativeStore(e.pluginName, "config", fromPairs(Object.entries(e.config).map(([e, t]) => [e, t.defaultValue])));
204
- n.form.set(e.key, {
205
- form: e.config,
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,
206
226
  value: r
207
227
  });
208
228
  }, "resignerConfig")
@@ -244,6 +264,6 @@ const appConfig = useGlobalVar(new ConfigPointer("core", {
244
264
  this.mainLists.set(e, n.concat(t));
245
265
  }
246
266
  }(), "core/global");
247
- export { ConfigPointer, Global, appConfig, declareDepType, decodePluginMeta, definePlugin, pluginExposes, require, useConfig };
267
+ export { ConfigPointer, Global, appConfig, declareDepType, decodePluginMeta, definePlugin, pluginEmitter, pluginExposes, require, useConfig };
248
268
 
249
269
  //# sourceMappingURL=index.js.map