koishi-plugin-chatluna-affinity 0.3.0-beta.2 → 0.3.0-beta.4

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,16 +1,20 @@
1
1
  <!--
2
2
  好感度详情加载器
3
- 根据当前插件名称决定是否显示导航组件
3
+ 根据当前插件名称决定是否显示共享导航组件
4
4
  -->
5
5
  <template>
6
- <AffinityNav v-if="isOwn" />
6
+ <SharedNav v-if="isOwn" :sections="navSections" />
7
7
  </template>
8
8
 
9
9
  <script setup lang="ts">
10
- import { ComputedRef, inject, computed } from 'vue'
11
- import AffinityNav from './components/AffinityNav.vue'
12
- import { PLUGIN_NAME } from './constants'
10
+ import { ComputedRef, computed, inject } from 'vue'
11
+ import { SharedNav } from 'shared-nav'
12
+ import { NAV_SECTIONS, PLUGIN_CANDIDATE_NAMES } from './constants'
13
13
 
14
14
  const pluginName = inject<ComputedRef<string>>('plugin:name')
15
- const isOwn = computed(() => pluginName?.value === PLUGIN_NAME)
15
+ const navSections = NAV_SECTIONS
16
+ const isOwn = computed(() => {
17
+ const name = pluginName?.value || ''
18
+ return PLUGIN_CANDIDATE_NAMES.includes(name)
19
+ })
16
20
  </script>
@@ -1,26 +1,11 @@
1
1
  /**
2
2
  * 前端常量定义
3
- * 包含导航、工具、变量的配置映射
3
+ * 包含导航分组与插件候选名称
4
4
  */
5
5
 
6
- export interface NavSection {
7
- title: string;
8
- key: string;
9
- }
6
+ import type { SharedNavSection } from "shared-nav";
10
7
 
11
- export interface ToolItem {
12
- name: string;
13
- enableKey: string;
14
- enabled: boolean;
15
- }
16
-
17
- export interface VariableItem {
18
- name: string;
19
- key: string;
20
- enabled: boolean;
21
- }
22
-
23
- export const NAV_SECTIONS: NavSection[] = [
8
+ export const NAV_SECTIONS: SharedNavSection[] = [
24
9
  { title: "好感度设置", key: "affinity" },
25
10
  { title: "黑名单设置", key: "blacklist" },
26
11
  { title: "关系设置", key: "relationship" },
@@ -29,37 +14,5 @@ export const NAV_SECTIONS: NavSection[] = [
29
14
  { title: "其他设置", key: "otherSettings" },
30
15
  ];
31
16
 
32
- export const TITLE_TO_KEY: Record<string, string> = {
33
- 好感度设置: "affinity",
34
- 黑名单设置: "blacklist",
35
- 关系设置: "relationship",
36
- 变量设置: "variables",
37
- "XML 工具设置": "xmlTools",
38
- 其他设置: "otherSettings",
39
- };
40
-
41
- export const KEY_TO_TITLE: Record<string, string> = {
42
- affinity: "好感度设置",
43
- blacklist: "黑名单设置",
44
- relationship: "关系设置",
45
- variables: "变量设置",
46
- xmlTools: "XML 工具设置",
47
- otherSettings: "其他设置",
48
- };
49
-
50
- export const VARIABLE_CONFIG: Record<
51
- string,
52
- { section: string; searchKey: string | string[] }
53
- > = {
54
- affinity: { section: "变量设置", searchKey: "affinityVariableName" },
55
- relationshipLevel: {
56
- section: "变量设置",
57
- searchKey: "relationshipLevelVariableName",
58
- },
59
- blacklistList: {
60
- section: "变量设置",
61
- searchKey: "blacklistListVariableName",
62
- },
63
- };
64
-
65
17
  export const PLUGIN_NAME = "koishi-plugin-chatluna-affinity";
18
+ export const PLUGIN_CANDIDATE_NAMES = [PLUGIN_NAME, "chatluna-affinity"];
package/dist/index.js CHANGED
@@ -1,226 +1,262 @@
1
- import { openBlock as p, createElementBlock as f, createElementVNode as _, defineComponent as k, Fragment as C, renderList as D, normalizeClass as m, toDisplayString as X, reactive as N, computed as $, onUnmounted as x, ref as L, onMounted as Y, normalizeStyle as z, unref as y, createVNode as w, withModifiers as S, inject as I, createBlock as R, createCommentVNode as A } from "vue";
2
- const v = (c, e) => {
3
- const t = c.__vccOpts || c;
4
- for (const [n, l] of e)
5
- t[n] = l;
6
- return t;
7
- }, B = {}, O = {
1
+ import { openBlock as m, createElementBlock as _, createElementVNode as v, defineComponent as $, Fragment as R, renderList as E, normalizeClass as y, toDisplayString as z, reactive as I, computed as w, onUnmounted as N, ref as T, onMounted as A, normalizeStyle as B, unref as k, createVNode as x, withModifiers as D, inject as K, createBlock as X, createCommentVNode as O } from "vue";
2
+ const M = (s, o) => {
3
+ const r = s.__vccOpts || s;
4
+ for (const [c, t] of o)
5
+ r[c] = t;
6
+ return r;
7
+ }, V = {}, Y = {
8
8
  viewBox: "0 0 1024 1024",
9
9
  xmlns: "http://www.w3.org/2000/svg",
10
10
  width: "20",
11
11
  height: "20"
12
12
  };
13
- function K(c, e) {
14
- return p(), f("svg", O, [...e[0] || (e[0] = [
15
- _("path", {
13
+ function P(s, o) {
14
+ return m(), _("svg", Y, [...o[0] || (o[0] = [
15
+ v("path", {
16
16
  d: "M288 224c0-35.3 28.7-64 64-64s64 28.7 64 64-28.7 64-64 64-64-28.7-64-64zm320 0c0-35.3 28.7-64 64-64s64 28.7 64 64-28.7 64-64 64-64-28.7-64-64zM288 512c0-35.3 28.7-64 64-64s64 28.7 64 64-28.7 64-64 64-64-28.7-64-64zm320 0c0-35.3 28.7-64 64-64s64 28.7 64 64-28.7 64-64 64-64-28.7-64-64zM352 864c-35.3 0-64-28.7-64-64s28.7-64 64-64 64 28.7 64 64-28.7 64-64 64zm320 0c-35.3 0-64-28.7-64-64s28.7-64 64-64 64 28.7 64 64-28.7 64-64 64z",
17
17
  fill: "currentColor"
18
18
  }, null, -1)
19
19
  ])]);
20
20
  }
21
- const V = /* @__PURE__ */ v(B, [["render", K]]), q = {}, W = {
21
+ const q = /* @__PURE__ */ M(V, [["render", P]]), U = {}, W = {
22
22
  viewBox: "0 0 1024 1024",
23
23
  xmlns: "http://www.w3.org/2000/svg",
24
24
  width: "20",
25
25
  height: "20"
26
26
  };
27
- function j(c, e) {
28
- return p(), f("svg", W, [...e[0] || (e[0] = [
29
- _("path", {
27
+ function j(s, o) {
28
+ return m(), _("svg", W, [...o[0] || (o[0] = [
29
+ v("path", {
30
30
  d: "M831.872 340.864 512 652.672 192.128 340.864a30.592 30.592 0 0 0-42.752 0 29.12 29.12 0 0 0 0 41.6L489.664 714.24a32 32 0 0 0 44.672 0l340.288-331.712a29.12 29.12 0 0 0 0-41.728 30.592 30.592 0 0 0-42.752 0z",
31
31
  fill: "currentColor"
32
32
  }, null, -1)
33
33
  ])]);
34
34
  }
35
- const P = /* @__PURE__ */ v(q, [["render", j]]), U = ["onClick"], F = /* @__PURE__ */ k({
35
+ const G = /* @__PURE__ */ M(U, [["render", j]]), F = ["onClick"], H = /* @__PURE__ */ $({
36
36
  __name: "NavSection",
37
37
  props: {
38
38
  sections: {},
39
39
  activeKey: {}
40
40
  },
41
41
  emits: ["select"],
42
- setup(c) {
43
- return (e, t) => (p(!0), f(C, null, D(c.sections, (n) => (p(), f("div", {
44
- key: n.key,
45
- class: m([e.$style.item, c.activeKey === n.key ? e.$style.active : ""]),
46
- onClick: (l) => e.$emit("select", n)
47
- }, X(n.title), 11, U))), 128));
42
+ setup(s) {
43
+ return (o, r) => (m(!0), _(R, null, E(s.sections, (c) => (m(), _("div", {
44
+ key: c.key,
45
+ class: y([o.$style.item, s.activeKey === c.key ? o.$style.active : ""]),
46
+ onClick: (t) => o.$emit("select", c)
47
+ }, z(c.title), 11, F))), 128));
48
48
  }
49
- }), G = "_item_1m2kp_1", H = "_active_1m2kp_16", J = {
50
- item: G,
51
- active: H
52
- }, Q = {
53
- $style: J
54
- }, Z = /* @__PURE__ */ v(F, [["__cssModules", Q]]);
55
- function tt(c = 100, e = 20) {
56
- const t = N({
49
+ }), J = "_item_1m2kp_1", Q = "_active_1m2kp_16", Z = {
50
+ item: J,
51
+ active: Q
52
+ }, tt = {
53
+ $style: Z
54
+ }, et = /* @__PURE__ */ M(H, [["__cssModules", tt]]);
55
+ function L(s) {
56
+ return s instanceof TouchEvent ? {
57
+ x: s.touches[0].clientX,
58
+ y: s.touches[0].clientY
59
+ } : {
60
+ x: s.clientX,
61
+ y: s.clientY
62
+ };
63
+ }
64
+ function ot(s = {}) {
65
+ const {
66
+ initialTop: o = 100,
67
+ initialRight: r = 20,
68
+ boundarySelector: c = ".plugin-view"
69
+ } = s, t = I({
57
70
  isDragging: !1,
58
- top: c,
59
- right: e,
71
+ top: o,
72
+ right: r,
60
73
  startTop: 0,
61
74
  startRight: 0,
62
75
  startX: 0,
63
76
  startY: 0,
64
77
  width: 0,
65
78
  height: 0
66
- }), n = $(() => ({
67
- top: t.top + "px",
68
- right: t.right + "px"
69
- })), l = (s) => {
70
- var E;
71
- if (!t.isDragging) return;
72
- const a = s instanceof TouchEvent ? s.touches[0].clientX : s.clientX, o = s instanceof TouchEvent ? s.touches[0].clientY : s.clientY;
73
- let i = t.startTop + (o - t.startY), u = t.startRight - (a - t.startX);
74
- const r = (E = document.querySelector(".plugin-view")) == null ? void 0 : E.getBoundingClientRect();
75
- let h = 0, M = window.innerHeight - t.height, T = 0, b = window.innerWidth - t.width;
76
- r && (h = r.top, M = r.bottom - t.height, T = window.innerWidth - r.right, b = window.innerWidth - r.left - t.width), t.top = Math.max(h, Math.min(M, i)), t.right = Math.max(T, Math.min(b, u));
77
- }, g = (s, a) => {
78
- const o = s instanceof TouchEvent ? s.touches[0].clientX : s.clientX, i = s instanceof TouchEvent ? s.touches[0].clientY : s.clientY, r = s.target.closest(`.${a}`), h = r == null ? void 0 : r.getBoundingClientRect();
79
- h && (t.width = h.width, t.height = h.height), t.startTop = t.top, t.startRight = t.right, t.startX = o, t.startY = i, t.isDragging = !0;
80
- }, d = () => {
79
+ }), g = w(() => ({
80
+ top: `${t.top}px`,
81
+ right: `${t.right}px`
82
+ })), i = (d) => {
83
+ var C;
84
+ if (!t.isDragging)
85
+ return;
86
+ const a = L(d), l = t.startTop + (a.y - t.startY), e = t.startRight - (a.x - t.startX), n = (C = document.querySelector(c)) == null ? void 0 : C.getBoundingClientRect();
87
+ let h = 0, f = window.innerHeight - t.height, S = 0, b = window.innerWidth - t.width;
88
+ n && (h = n.top, f = n.bottom - t.height, S = window.innerWidth - n.right, b = window.innerWidth - n.left - t.width), t.top = Math.max(h, Math.min(f, l)), t.right = Math.max(S, Math.min(b, e));
89
+ }, p = (d, a) => {
90
+ const l = L(d), e = a == null ? void 0 : a.getBoundingClientRect();
91
+ e && (t.width = e.width, t.height = e.height), t.startTop = t.top, t.startRight = t.right, t.startX = l.x, t.startY = l.y, t.isDragging = !0;
92
+ }, u = () => {
81
93
  t.isDragging = !1;
82
94
  };
83
- return window.addEventListener("mousemove", l), window.addEventListener("mouseup", d), window.addEventListener("touchmove", l), window.addEventListener("touchend", d), x(() => {
84
- window.removeEventListener("mousemove", l), window.removeEventListener("mouseup", d), window.removeEventListener("touchmove", l), window.removeEventListener("touchend", d);
95
+ return window.addEventListener("mousemove", i), window.addEventListener("mouseup", u), window.addEventListener("touchmove", i), window.addEventListener("touchend", u), N(() => {
96
+ window.removeEventListener("mousemove", i), window.removeEventListener("mouseup", u), window.removeEventListener("touchmove", i), window.removeEventListener("touchend", u);
85
97
  }), {
86
- state: t,
87
- position: n,
88
- startDrag: g,
89
- endDrag: d
98
+ position: g,
99
+ startDrag: p
90
100
  };
91
101
  }
92
- function et(c, e = {}) {
93
- const t = L("");
94
- let n = null;
95
- const l = /* @__PURE__ */ new Map(), g = () => {
96
- n && (n.disconnect(), l.clear()), n = new IntersectionObserver(
97
- (a) => {
98
- for (const o of a)
99
- if (o.isIntersecting) {
100
- const i = l.get(o.target);
101
- i && (t.value = i);
102
- }
102
+ function nt(s) {
103
+ const {
104
+ titleToKeyMap: o,
105
+ headerSelector: r = ".k-schema-header",
106
+ rootMargin: c = "-20% 0px -60% 0px",
107
+ threshold: t = 0
108
+ } = s, g = T("");
109
+ let i = null;
110
+ const p = /* @__PURE__ */ new Map(), u = () => {
111
+ i == null || i.disconnect(), p.clear(), i = new IntersectionObserver(
112
+ (l) => {
113
+ for (const e of l) {
114
+ if (!e.isIntersecting)
115
+ continue;
116
+ const n = p.get(e.target);
117
+ n && (g.value = n);
118
+ }
103
119
  },
104
120
  {
105
121
  root: null,
106
- rootMargin: e.rootMargin || "-20% 0px -60% 0px",
107
- threshold: e.threshold || 0
122
+ rootMargin: c,
123
+ threshold: t
108
124
  }
109
- ), document.querySelectorAll(".k-schema-header").forEach((a) => {
110
- const o = a.textContent || "";
111
- for (const [i, u] of Object.entries(c))
112
- if (o.includes(i)) {
113
- n == null || n.observe(a), l.set(a, u);
125
+ ), document.querySelectorAll(r).forEach((l) => {
126
+ const e = l.textContent || "";
127
+ for (const [n, h] of Object.entries(o))
128
+ if (e.includes(n)) {
129
+ i == null || i.observe(l), p.set(l, h);
114
130
  break;
115
131
  }
116
132
  });
117
133
  }, d = () => {
118
- setTimeout(g, 500);
134
+ setTimeout(u, 500);
119
135
  };
120
- return Y(() => {
121
- d();
122
- }), x(() => {
123
- n == null || n.disconnect();
136
+ return A(d), N(() => {
137
+ i == null || i.disconnect();
124
138
  }), {
125
- activeSection: t,
139
+ activeSection: g,
126
140
  refresh: d
127
141
  };
128
142
  }
129
- const ot = [
130
- { title: "好感度设置", key: "affinity" },
131
- { title: "黑名单设置", key: "blacklist" },
132
- { title: "关系设置", key: "relationship" },
133
- { title: "变量设置", key: "variables" },
134
- { title: "XML 工具设置", key: "xmlTools" },
135
- { title: "其他设置", key: "otherSettings" }
136
- ], nt = {
137
- 好感度设置: "affinity",
138
- 黑名单设置: "blacklist",
139
- 关系设置: "relationship",
140
- 变量设置: "variables",
141
- "XML 工具设置": "xmlTools",
142
- 其他设置: "otherSettings"
143
- }, st = {
144
- affinity: "好感度设置",
145
- blacklist: "黑名单设置",
146
- relationship: "关系设置",
147
- variables: "变量设置",
148
- xmlTools: "XML 工具设置",
149
- otherSettings: "其他设置"
150
- }, it = "koishi-plugin-chatluna-affinity", ct = /* @__PURE__ */ k({
151
- __name: "AffinityNav",
152
- setup(c) {
153
- const e = L(!1), t = (o) => {
154
- o.stopPropagation(), e.value = !e.value;
155
- }, { position: n, startDrag: l } = tt(100, 20), g = (o) => {
156
- l(o, "container");
157
- }, d = ot, { activeSection: s } = et(nt), a = (o) => {
158
- s.value = o.key;
159
- const i = document.querySelectorAll(".k-schema-header");
160
- for (let u = 0; u < i.length; u++) {
161
- const r = i[u];
162
- if ((r.textContent || "").includes(st[o.key])) {
163
- r.scrollIntoView({ behavior: "smooth", block: "start" });
143
+ const st = /* @__PURE__ */ $({
144
+ __name: "SharedNav",
145
+ props: {
146
+ sections: {},
147
+ headerSelector: { default: ".k-schema-header" },
148
+ boundarySelector: { default: ".plugin-view" },
149
+ initialTop: { default: 100 },
150
+ initialRight: { default: 20 },
151
+ rootMargin: { default: "-20% 0px -60% 0px" },
152
+ threshold: { default: 0 }
153
+ },
154
+ setup(s) {
155
+ const o = s, r = T(!1), c = T(null), t = w(
156
+ () => o.sections.reduce(
157
+ (e, n) => (e[n.matchText ?? n.title] = n.key, e),
158
+ {}
159
+ )
160
+ ), g = w(
161
+ () => o.sections.reduce(
162
+ (e, n) => (e[n.key] = n.matchText ?? n.title, e),
163
+ {}
164
+ )
165
+ ), i = (e) => {
166
+ e.stopPropagation(), r.value = !r.value;
167
+ }, { position: p, startDrag: u } = ot({
168
+ initialTop: o.initialTop,
169
+ initialRight: o.initialRight,
170
+ boundarySelector: o.boundarySelector
171
+ }), d = (e) => {
172
+ u(e, c.value);
173
+ }, { activeSection: a } = nt({
174
+ titleToKeyMap: t.value,
175
+ headerSelector: o.headerSelector,
176
+ rootMargin: o.rootMargin,
177
+ threshold: o.threshold
178
+ }), l = (e) => {
179
+ a.value = e.key;
180
+ const n = document.querySelectorAll(o.headerSelector);
181
+ for (let h = 0; h < n.length; h += 1) {
182
+ const f = n[h];
183
+ if ((f.textContent || "").includes(g.value[e.key])) {
184
+ f.scrollIntoView({ behavior: "smooth", block: "start" });
164
185
  return;
165
186
  }
166
187
  }
167
188
  };
168
- return (o, i) => (p(), f("div", {
169
- class: m([o.$style.container, e.value ? o.$style.collapsed : ""]),
170
- style: z(y(n))
189
+ return (e, n) => (m(), _("div", {
190
+ ref_key: "containerRef",
191
+ ref: c,
192
+ class: y([e.$style.container, r.value ? e.$style.collapsed : ""]),
193
+ style: B(k(p))
171
194
  }, [
172
- _("div", {
173
- class: m(o.$style.header),
174
- onMousedown: g,
175
- onTouchstart: g
195
+ v("div", {
196
+ class: y(e.$style.header),
197
+ onMousedown: d,
198
+ onTouchstart: d
176
199
  }, [
177
- w(V, {
178
- class: m(o.$style.move)
200
+ x(q, {
201
+ class: y(e.$style.move)
179
202
  }, null, 8, ["class"]),
180
- _("div", {
181
- class: m(o.$style.toggle),
182
- onClick: t,
183
- onMousedown: i[0] || (i[0] = S(() => {
203
+ v("div", {
204
+ class: y(e.$style.toggle),
205
+ onClick: i,
206
+ onMousedown: n[0] || (n[0] = D(() => {
184
207
  }, ["stop"])),
185
- onTouchstart: i[1] || (i[1] = S(() => {
208
+ onTouchstart: n[1] || (n[1] = D(() => {
186
209
  }, ["stop"]))
187
210
  }, [
188
- w(P)
211
+ x(G)
189
212
  ], 34)
190
213
  ], 34),
191
- _("div", {
192
- class: m(o.$style.body)
214
+ v("div", {
215
+ class: y(e.$style.body)
193
216
  }, [
194
- w(Z, {
195
- sections: y(d),
196
- "active-key": y(s),
197
- onSelect: a
217
+ x(et, {
218
+ sections: s.sections,
219
+ "active-key": k(a),
220
+ onSelect: l
198
221
  }, null, 8, ["sections", "active-key"])
199
222
  ], 2)
200
223
  ], 6));
201
224
  }
202
- }), lt = "_container_pbgsl_2", rt = "_header_pbgsl_21", at = "_move_pbgsl_36", dt = "_toggle_pbgsl_45", ut = "_body_pbgsl_56", ht = "_collapsed_pbgsl_67", gt = {
203
- container: lt,
204
- header: rt,
205
- move: at,
206
- toggle: dt,
207
- body: ut,
208
- collapsed: ht
209
- }, mt = {
210
- $style: gt
211
- }, pt = /* @__PURE__ */ v(ct, [["__cssModules", mt]]), _t = /* @__PURE__ */ k({
225
+ }), it = "_container_pbgsl_2", ct = "_header_pbgsl_21", rt = "_move_pbgsl_36", lt = "_toggle_pbgsl_45", at = "_body_pbgsl_56", dt = "_collapsed_pbgsl_67", ut = {
226
+ container: it,
227
+ header: ct,
228
+ move: rt,
229
+ toggle: lt,
230
+ body: at,
231
+ collapsed: dt
232
+ }, ht = {
233
+ $style: ut
234
+ }, gt = /* @__PURE__ */ M(st, [["__cssModules", ht]]), pt = [
235
+ { title: "好感度设置", key: "affinity" },
236
+ { title: "黑名单设置", key: "blacklist" },
237
+ { title: "关系设置", key: "relationship" },
238
+ { title: "变量设置", key: "variables" },
239
+ { title: "XML 工具设置", key: "xmlTools" },
240
+ { title: "其他设置", key: "otherSettings" }
241
+ ], yt = "koishi-plugin-chatluna-affinity", mt = [yt, "chatluna-affinity"], ft = /* @__PURE__ */ $({
212
242
  __name: "AffinityDetailsLoader",
213
- setup(c) {
214
- const e = I("plugin:name"), t = $(() => (e == null ? void 0 : e.value) === it);
215
- return (n, l) => t.value ? (p(), R(pt, { key: 0 })) : A("", !0);
243
+ setup(s) {
244
+ const o = K("plugin:name"), r = pt, c = w(() => {
245
+ const t = (o == null ? void 0 : o.value) || "";
246
+ return mt.includes(t);
247
+ });
248
+ return (t, g) => c.value ? (m(), X(k(gt), {
249
+ key: 0,
250
+ sections: k(r)
251
+ }, null, 8, ["sections"])) : O("", !0);
216
252
  }
217
- }), vt = (c) => {
218
- c.slot({
253
+ }), _t = (s) => {
254
+ s.slot({
219
255
  type: "plugin-details",
220
- component: _t,
256
+ component: ft,
221
257
  order: -999
222
258
  });
223
259
  };
224
260
  export {
225
- vt as default
261
+ _t as default
226
262
  };