@inpageedit/core 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/LICENSE +20 -20
  2. package/dist/{BasePlugin-Bf2UuIHF.js → BasePlugin-CU8beLYu.js} +17 -26
  3. package/dist/BasePlugin-CU8beLYu.js.map +1 -0
  4. package/dist/IconQuickEdit-CMCQncyj.js.map +1 -1
  5. package/dist/InputBox-nQKtiWtZ.js.map +1 -1
  6. package/dist/{PluginPrefSync-Dn1Xsiqz.js → PluginPrefSync-B-gPsC2n.js} +124 -128
  7. package/dist/PluginPrefSync-B-gPsC2n.js.map +1 -0
  8. package/dist/PluginStoreApp-CDteVCBG.js +453 -0
  9. package/dist/PluginStoreApp-CDteVCBG.js.map +1 -0
  10. package/dist/{endpoints-DgyuoRZd.js → Preferences-85Q9FAmb.js} +589 -565
  11. package/dist/Preferences-85Q9FAmb.js.map +1 -0
  12. package/dist/WatchlistAction-BbNAyryN.js.map +1 -1
  13. package/dist/components/index.js.map +1 -1
  14. package/dist/{index-BuYNq7f3.js → index-19CgGBI0.js} +1419 -921
  15. package/dist/index-19CgGBI0.js.map +1 -0
  16. package/dist/{index-B7c6jL9x.js → index-BKIf3i0I.js} +146 -137
  17. package/dist/index-BKIf3i0I.js.map +1 -0
  18. package/dist/{index-CCRMmnwk.js → index-BrtFJ-M0.js} +67 -66
  19. package/dist/index-BrtFJ-M0.js.map +1 -0
  20. package/dist/index-CG38LlAh.js.map +1 -1
  21. package/dist/index-CM_6yF2v.js.map +1 -1
  22. package/dist/index-CQr1DJ8n.js +173 -0
  23. package/dist/index-CQr1DJ8n.js.map +1 -0
  24. package/dist/{index-BQ-cHWkJ.js → index-CVTBg5O9.js} +66 -48
  25. package/dist/index-CVTBg5O9.js.map +1 -0
  26. package/dist/index-Ci82vLXg.js +179 -0
  27. package/dist/index-Ci82vLXg.js.map +1 -0
  28. package/dist/{index-BwdWyHLe.js → index-D3iZhRMJ.js} +93 -93
  29. package/dist/index-D3iZhRMJ.js.map +1 -0
  30. package/dist/index-DD5CVCfD.js.map +1 -1
  31. package/dist/{index-BJ7_Q1mB.js → index-DGtq21uW.js} +17 -16
  32. package/dist/index-DGtq21uW.js.map +1 -0
  33. package/dist/index-DXL7teb0.js +394 -0
  34. package/dist/index-DXL7teb0.js.map +1 -0
  35. package/dist/index-DjPpAyfE.js +116 -0
  36. package/dist/index-DjPpAyfE.js.map +1 -0
  37. package/dist/{index-eSlbrNqF.js → index-rpiO9fpc.js} +4 -5
  38. package/dist/{index-eSlbrNqF.js.map → index-rpiO9fpc.js.map} +1 -1
  39. package/dist/index.d.ts +327 -26
  40. package/dist/index.js +32 -26
  41. package/dist/index.js.map +1 -1
  42. package/dist/makeCallable-LDU0xZMJ.js.map +1 -1
  43. package/dist/models/index.js +174 -154
  44. package/dist/models/index.js.map +1 -1
  45. package/dist/noop-ClDc6zv4.js.map +1 -1
  46. package/dist/plugins/index.js +10 -10
  47. package/dist/services/index.js +1 -1
  48. package/dist/style.css +1 -1
  49. package/dist/vueHooks-l04s8cIl.js.map +1 -1
  50. package/lib/index.umd.js +20 -12
  51. package/lib/index.umd.js.map +1 -1
  52. package/lib/style.css +1 -1
  53. package/package.json +4 -4
  54. package/dist/BasePlugin-Bf2UuIHF.js.map +0 -1
  55. package/dist/PluginPrefSync-Dn1Xsiqz.js.map +0 -1
  56. package/dist/PluginStoreApp-CpOLArL7.js +0 -452
  57. package/dist/PluginStoreApp-CpOLArL7.js.map +0 -1
  58. package/dist/Preferences-DS4-CFWe.js +0 -9
  59. package/dist/Preferences-DS4-CFWe.js.map +0 -1
  60. package/dist/endpoints-DgyuoRZd.js.map +0 -1
  61. package/dist/index-2RfILgXm.js +0 -180
  62. package/dist/index-2RfILgXm.js.map +0 -1
  63. package/dist/index-B7c6jL9x.js.map +0 -1
  64. package/dist/index-BJ7_Q1mB.js.map +0 -1
  65. package/dist/index-BNh95-x2.js +0 -115
  66. package/dist/index-BNh95-x2.js.map +0 -1
  67. package/dist/index-BQ-cHWkJ.js.map +0 -1
  68. package/dist/index-BuYNq7f3.js.map +0 -1
  69. package/dist/index-BwdWyHLe.js.map +0 -1
  70. package/dist/index-CCRMmnwk.js.map +0 -1
  71. package/dist/index-CnIpUF9x.js +0 -173
  72. package/dist/index-CnIpUF9x.js.map +0 -1
  73. package/dist/index-CyG7_IYz.js +0 -394
  74. package/dist/index-CyG7_IYz.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"makeCallable-LDU0xZMJ.js","sources":["../src/utils/makeCallable.ts"],"sourcesContent":["export const CALLABLE_APPLY_SYMBOL = Symbol('@@apply')\r\nexport const CALLABLE_CTOR_SYMBOL = Symbol('@@ctor')\r\nexport function makeCallable<C extends object, M extends keyof C>(\r\n instance: C,\r\n method: M\r\n): C &\r\n ((\r\n ...args: C[M] extends (...a: infer P) => any ? P : never\r\n ) => C[M] extends (...a: any[]) => infer R ? R : never) {\r\n if (typeof instance !== 'object' || instance === null || Array.isArray(instance)) {\r\n throw new TypeError('instance is not an object')\r\n }\r\n\r\n const apply: any = (...args: any[]) => {\r\n const fn = (instance as any)[method]\r\n if (typeof fn !== 'function') {\r\n throw new TypeError(`Property \"${String(method)}\" is not a function`)\r\n }\r\n return fn.apply(instance, args)\r\n }\r\n apply[CALLABLE_APPLY_SYMBOL] = apply\r\n apply[CALLABLE_CTOR_SYMBOL] = instance\r\n\r\n const ctorName = (instance as any)?.constructor?.name\r\n if (ctorName) (apply as any)[Symbol.toStringTag] = ctorName\r\n\r\n const proxy = new Proxy(apply, {\r\n get(_, p, receiver) {\r\n if (p === 'prototype') return Reflect.get(apply, p, receiver)\r\n return Reflect.get(instance as any, p, instance)\r\n },\r\n set(_, p, v) {\r\n return Reflect.set(instance as any, p, v)\r\n },\r\n has(_, p) {\r\n return Reflect.has(instance as any, p)\r\n },\r\n deleteProperty(_, p) {\r\n return Reflect.deleteProperty(instance as any, p)\r\n },\r\n ownKeys() {\r\n return Reflect.ownKeys(instance as any)\r\n },\r\n getOwnPropertyDescriptor(_, p) {\r\n return Object.getOwnPropertyDescriptor(instance as any, p)\r\n },\r\n defineProperty(_, p, desc) {\r\n return Object.defineProperty(instance as any, p, desc)\r\n },\r\n })\r\n\r\n return proxy as unknown as any\r\n}\r\n"],"names":["CALLABLE_APPLY_SYMBOL","CALLABLE_CTOR_SYMBOL","makeCallable","instance","method","apply","args","fn","ctorName","_","p","receiver","v","desc"],"mappings":"AAAO,MAAMA,IAAwB,OAAO,SAAS,GACxCC,IAAuB,OAAO,QAAQ;AAC5C,SAASC,EACdC,GACAC,GAIwD;AACxD,MAAI,OAAOD,KAAa,YAAYA,MAAa,QAAQ,MAAM,QAAQA,CAAQ;AAC7E,UAAM,IAAI,UAAU,2BAA2B;AAGjD,QAAME,IAAa,IAAIC,MAAgB;AACrC,UAAMC,IAAMJ,EAAiBC,CAAM;AACnC,QAAI,OAAOG,KAAO;AAChB,YAAM,IAAI,UAAU,aAAa,OAAOH,CAAM,CAAC,qBAAqB;AAEtE,WAAOG,EAAG,MAAMJ,GAAUG,CAAI;AAAA,EAChC;AACA,EAAAD,EAAML,CAAqB,IAAIK,GAC/BA,EAAMJ,CAAoB,IAAIE;AAE9B,QAAMK,IAAYL,GAAkB,aAAa;AACjD,SAAIK,MAAWH,EAAc,OAAO,WAAW,IAAIG,IAErC,IAAI,MAAMH,GAAO;AAAA,IAC7B,IAAII,GAAGC,GAAGC,GAAU;AAClB,aAAID,MAAM,cAAoB,QAAQ,IAAIL,GAAOK,GAAGC,CAAQ,IACrD,QAAQ,IAAIR,GAAiBO,GAAGP,CAAQ;AAAA,IACjD;AAAA,IACA,IAAIM,GAAGC,GAAGE,GAAG;AACX,aAAO,QAAQ,IAAIT,GAAiBO,GAAGE,CAAC;AAAA,IAC1C;AAAA,IACA,IAAIH,GAAGC,GAAG;AACR,aAAO,QAAQ,IAAIP,GAAiBO,CAAC;AAAA,IACvC;AAAA,IACA,eAAeD,GAAGC,GAAG;AACnB,aAAO,QAAQ,eAAeP,GAAiBO,CAAC;AAAA,IAClD;AAAA,IACA,UAAU;AACR,aAAO,QAAQ,QAAQP,CAAe;AAAA,IACxC;AAAA,IACA,yBAAyBM,GAAGC,GAAG;AAC7B,aAAO,OAAO,yBAAyBP,GAAiBO,CAAC;AAAA,IAC3D;AAAA,IACA,eAAeD,GAAGC,GAAGG,GAAM;AACzB,aAAO,OAAO,eAAeV,GAAiBO,GAAGG,CAAI;AAAA,IACvD;AAAA,EAAA,CACD;AAGH;"}
1
+ {"version":3,"file":"makeCallable-LDU0xZMJ.js","sources":["../src/utils/makeCallable.ts"],"sourcesContent":["export const CALLABLE_APPLY_SYMBOL = Symbol('@@apply')\nexport const CALLABLE_CTOR_SYMBOL = Symbol('@@ctor')\nexport function makeCallable<C extends object, M extends keyof C>(\n instance: C,\n method: M\n): C &\n ((\n ...args: C[M] extends (...a: infer P) => any ? P : never\n ) => C[M] extends (...a: any[]) => infer R ? R : never) {\n if (typeof instance !== 'object' || instance === null || Array.isArray(instance)) {\n throw new TypeError('instance is not an object')\n }\n\n const apply: any = (...args: any[]) => {\n const fn = (instance as any)[method]\n if (typeof fn !== 'function') {\n throw new TypeError(`Property \"${String(method)}\" is not a function`)\n }\n return fn.apply(instance, args)\n }\n apply[CALLABLE_APPLY_SYMBOL] = apply\n apply[CALLABLE_CTOR_SYMBOL] = instance\n\n const ctorName = (instance as any)?.constructor?.name\n if (ctorName) (apply as any)[Symbol.toStringTag] = ctorName\n\n const proxy = new Proxy(apply, {\n get(_, p, receiver) {\n if (p === 'prototype') return Reflect.get(apply, p, receiver)\n return Reflect.get(instance as any, p, instance)\n },\n set(_, p, v) {\n return Reflect.set(instance as any, p, v)\n },\n has(_, p) {\n return Reflect.has(instance as any, p)\n },\n deleteProperty(_, p) {\n return Reflect.deleteProperty(instance as any, p)\n },\n ownKeys() {\n return Reflect.ownKeys(instance as any)\n },\n getOwnPropertyDescriptor(_, p) {\n return Object.getOwnPropertyDescriptor(instance as any, p)\n },\n defineProperty(_, p, desc) {\n return Object.defineProperty(instance as any, p, desc)\n },\n })\n\n return proxy as unknown as any\n}\n"],"names":["CALLABLE_APPLY_SYMBOL","CALLABLE_CTOR_SYMBOL","makeCallable","instance","method","apply","args","fn","ctorName","_","p","receiver","v","desc"],"mappings":"AAAO,MAAMA,IAAwB,OAAO,SAAS,GACxCC,IAAuB,OAAO,QAAQ;AAC5C,SAASC,EACdC,GACAC,GAIwD;AACxD,MAAI,OAAOD,KAAa,YAAYA,MAAa,QAAQ,MAAM,QAAQA,CAAQ;AAC7E,UAAM,IAAI,UAAU,2BAA2B;AAGjD,QAAME,IAAa,IAAIC,MAAgB;AACrC,UAAMC,IAAMJ,EAAiBC,CAAM;AACnC,QAAI,OAAOG,KAAO;AAChB,YAAM,IAAI,UAAU,aAAa,OAAOH,CAAM,CAAC,qBAAqB;AAEtE,WAAOG,EAAG,MAAMJ,GAAUG,CAAI;AAAA,EAChC;AACA,EAAAD,EAAML,CAAqB,IAAIK,GAC/BA,EAAMJ,CAAoB,IAAIE;AAE9B,QAAMK,IAAYL,GAAkB,aAAa;AACjD,SAAIK,MAAWH,EAAc,OAAO,WAAW,IAAIG,IAErC,IAAI,MAAMH,GAAO;AAAA,IAC7B,IAAII,GAAGC,GAAGC,GAAU;AAClB,aAAID,MAAM,cAAoB,QAAQ,IAAIL,GAAOK,GAAGC,CAAQ,IACrD,QAAQ,IAAIR,GAAiBO,GAAGP,CAAQ;AAAA,IACjD;AAAA,IACA,IAAIM,GAAGC,GAAGE,GAAG;AACX,aAAO,QAAQ,IAAIT,GAAiBO,GAAGE,CAAC;AAAA,IAC1C;AAAA,IACA,IAAIH,GAAGC,GAAG;AACR,aAAO,QAAQ,IAAIP,GAAiBO,CAAC;AAAA,IACvC;AAAA,IACA,eAAeD,GAAGC,GAAG;AACnB,aAAO,QAAQ,eAAeP,GAAiBO,CAAC;AAAA,IAClD;AAAA,IACA,UAAU;AACR,aAAO,QAAQ,QAAQP,CAAe;AAAA,IACxC;AAAA,IACA,yBAAyBM,GAAGC,GAAG;AAC7B,aAAO,OAAO,yBAAyBP,GAAiBO,CAAC;AAAA,IAC3D;AAAA,IACA,eAAeD,GAAGC,GAAGG,GAAM;AACzB,aAAO,OAAO,eAAeV,GAAiBO,GAAGG,CAAI;AAAA,IACvD;AAAA,EAAA,CACD;AAGH;"}
@@ -22,7 +22,7 @@ class y {
22
22
  return Object.keys(this.values)[s] ?? null;
23
23
  }
24
24
  }
25
- const v = () => new Proxy(new y(), {
25
+ const N = () => new Proxy(new y(), {
26
26
  set(i, s, o) {
27
27
  return typeof s == "string" && i.setItem(s, o), !0;
28
28
  },
@@ -32,12 +32,12 @@ const v = () => new Proxy(new y(), {
32
32
  });
33
33
  function b(i) {
34
34
  class s {
35
- constructor(n, t = !0) {
36
- this._loaded = t, this.api = i, n.revisions?.forEach((a) => {
37
- typeof a?.slots?.main == "object" && Object.assign(a, a.slots.main);
35
+ constructor(a, t = !0) {
36
+ this._loaded = t, this.api = i, a.revisions?.forEach((r) => {
37
+ typeof r?.slots?.main == "object" && Object.assign(r, r.slots.main);
38
38
  }), this.pageInfo = {
39
39
  ...s.DEFAULT_PAGE_INFO,
40
- ...n
40
+ ...a
41
41
  };
42
42
  }
43
43
  static {
@@ -88,47 +88,47 @@ function b(i) {
88
88
  };
89
89
  }
90
90
  // Utils
91
- static async newFromApi(n) {
91
+ static async newFromApi(a) {
92
92
  const { data: t } = await this.api.get({
93
93
  ...s.DEFAULT_QUERY_PARAMS,
94
- ...n
95
- }), a = t?.query?.pages?.[0];
96
- if (!a || !a.title)
94
+ ...a
95
+ }), r = t?.query?.pages?.[0];
96
+ if (!r || !r.title)
97
97
  throw new Error("Invalid page info", { cause: t });
98
- return new s(a, !0);
98
+ return new s(r, !0);
99
99
  }
100
- static newBlankPage(n = {}) {
101
- return new s(n, !1);
100
+ static newBlankPage(a = {}) {
101
+ return new s(a, !1);
102
102
  }
103
- static async newFromAnyKind(n) {
104
- const { title: t, pageId: a, revisionId: e } = n || {};
105
- return e ? this.newFromApi({ revids: parseInt(e.toString(), 10) }) : a ? this.newFromApi({ pageids: parseInt(a.toString(), 10) }) : t ? this.newFromApi({ titles: t.toString() }) : null;
103
+ static async newFromAnyKind(a) {
104
+ const { title: t, pageId: r, revisionId: e } = a || {};
105
+ return e ? this.newFromApi({ revids: parseInt(e.toString(), 10) }) : r ? this.newFromApi({ pageids: parseInt(r.toString(), 10) }) : t ? this.newFromApi({ titles: t.toString() }) : null;
106
106
  }
107
- static async newBatchFromApi(n) {
108
- const { titles: t, pageids: a, revids: e, ...r } = n || {}, { data: l } = await this.api.post({
107
+ static async newBatchFromApi(a) {
108
+ const { titles: t, pageids: r, revids: e, ...n } = a || {}, { data: l } = await this.api.post({
109
109
  ...s.DEFAULT_QUERY_PARAMS,
110
110
  titles: t?.join("|") ?? void 0,
111
- pageids: a?.join("|") ?? void 0,
111
+ pageids: r?.join("|") ?? void 0,
112
112
  revids: e?.join("|") ?? void 0,
113
- ...r
113
+ ...n
114
114
  });
115
115
  return l?.query?.pages?.map((c) => new s(c, !0)) || [];
116
116
  }
117
117
  // Page actions
118
- async parse(n) {
118
+ async parse(a) {
119
119
  return this.api.post({
120
120
  action: "parse",
121
121
  page: this.pageInfo.title,
122
122
  prop: "text|langlinks|categories|links|templates|images|externallinks|sections|revid|displaytitle|iwlinks|properties|parsewarnings",
123
- ...n
123
+ ...a
124
124
  });
125
125
  }
126
- async preview(n, t) {
126
+ async preview(a, t) {
127
127
  return this.parse({
128
128
  action: "parse",
129
129
  page: void 0,
130
130
  title: this.title,
131
- text: n,
131
+ text: a,
132
132
  pst: 1,
133
133
  preview: 1,
134
134
  disableeditsection: 1,
@@ -136,69 +136,69 @@ function b(i) {
136
136
  ...t
137
137
  });
138
138
  }
139
- async edit(n, t) {
139
+ async edit(a, t) {
140
140
  const {
141
- text: a,
141
+ text: r,
142
142
  prependtext: e,
143
- appendtext: r,
143
+ appendtext: n,
144
144
  summary: l = "",
145
145
  watchlist: c = I.preferences,
146
- section: h
147
- } = n;
146
+ section: u
147
+ } = a;
148
148
  return this.api.postWithEditToken({
149
149
  action: "edit",
150
150
  title: this.title,
151
151
  starttimestamp: this.pageInfo.touched,
152
152
  basetimestamp: this.revisions[0]?.timestamp,
153
- text: a,
153
+ text: r,
154
154
  prependtext: e,
155
- appendtext: r,
155
+ appendtext: n,
156
156
  summary: l,
157
157
  watchlist: c,
158
- section: h,
158
+ section: u,
159
159
  ...t
160
160
  });
161
161
  }
162
- async createOnly(n, t) {
163
- return this.edit(n, { createonly: 1, ...t });
162
+ async createOnly(a, t) {
163
+ return this.edit(a, { createonly: 1, ...t });
164
164
  }
165
- async delete(n, t) {
165
+ async delete(a, t) {
166
166
  return this.api.postWithEditToken({
167
167
  action: "delete",
168
168
  title: this.pageInfo.title || void 0,
169
169
  pageid: this.pageInfo.pageid || void 0,
170
- reason: n,
170
+ reason: a,
171
171
  deletetalk: t?.deletetalk,
172
172
  ...t
173
173
  });
174
174
  }
175
- async moveTo(n, t, a) {
175
+ async moveTo(a, t, r) {
176
176
  return this.api.postWithEditToken({
177
177
  action: "move",
178
178
  from: this.pageInfo.title,
179
- to: n,
179
+ to: a,
180
180
  reason: t,
181
181
  movetalk: 1,
182
182
  movesubpages: 1,
183
- ...a
183
+ ...r
184
184
  });
185
185
  }
186
186
  // === utilities ===
187
- userCan(n) {
188
- return !!this.pageInfo?.actions?.[n];
187
+ userCan(a) {
188
+ return !!this.pageInfo?.actions?.[a];
189
189
  }
190
190
  userCanEdit() {
191
191
  return this.userCan("edit");
192
192
  }
193
193
  async reloadSelfInfo() {
194
- const n = await s.newFromApi({
194
+ const a = await s.newFromApi({
195
195
  pageids: this.pageInfo.pageid,
196
196
  titles: this.pageInfo.title
197
- }), t = (this.pageInfo.revisions || []).concat(n.revisions || []).sort((a, e) => a.revid - e.revid).reduce(
198
- (a, e) => (a.find((r) => r.revid === e.revid) || a.push(e), a),
197
+ }), t = (this.pageInfo.revisions || []).concat(a.revisions || []).sort((r, e) => r.revid - e.revid).reduce(
198
+ (r, e) => (r.find((n) => n.revid === e.revid) || r.push(e), r),
199
199
  []
200
200
  );
201
- return this.pageInfo = n.pageInfo, this.pageInfo.revisions = t, this._loaded = !0, this;
201
+ return this.pageInfo = a.pageInfo, this.pageInfo.revisions = t, this._loaded = !0, this;
202
202
  }
203
203
  // === sugar getters ===
204
204
  get pageid() {
@@ -241,7 +241,7 @@ const m = /* @__PURE__ */ new WeakMap(), g = {
241
241
  toDBKey: (i) => i.replace(/ /g, "_"),
242
242
  toNormalText: (i) => i.replace(/_/g, " "),
243
243
  ensureCase: (i, s) => s === "first-letter" ? i.charAt(0).toUpperCase() + i.slice(1) : i
244
- }, u = {
244
+ }, h = {
245
245
  /**
246
246
  * 标准化特殊页面名称:转换为全小写
247
247
  */
@@ -250,29 +250,29 @@ const m = /* @__PURE__ */ new WeakMap(), g = {
250
250
  * 构建特殊页面别名索引
251
251
  */
252
252
  buildSpecialPageIndex: (i) => {
253
- const s = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
253
+ const s = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map();
254
254
  for (const t of i.specialpagealiases) {
255
- const a = t.realname;
256
- s.set(a, a);
257
- const e = u.normalizeSpecialPageName(a);
258
- n.set(e, a);
259
- for (const r of t.aliases) {
260
- o.set(r, a);
261
- const l = u.normalizeSpecialPageName(r);
262
- n.set(l, a);
255
+ const r = t.realname;
256
+ s.set(r, r);
257
+ const e = h.normalizeSpecialPageName(r);
258
+ a.set(e, r);
259
+ for (const n of t.aliases) {
260
+ o.set(n, r);
261
+ const l = h.normalizeSpecialPageName(n);
262
+ a.set(l, r);
263
263
  }
264
264
  }
265
- return { byRealName: s, byAlias: o, byNormalized: n };
265
+ return { byRealName: s, byAlias: o, byNormalized: a };
266
266
  },
267
267
  /**
268
268
  * 查找特殊页面的真实名称
269
269
  */
270
270
  findSpecialPageRealName: (i, s) => {
271
271
  const o = i.split("/")[0];
272
- let n = s.byRealName.get(o) ?? s.byAlias.get(o);
273
- if (n !== void 0)
274
- return n;
275
- const t = u.normalizeSpecialPageName(o);
272
+ let a = s.byRealName.get(o) ?? s.byAlias.get(o);
273
+ if (a !== void 0)
274
+ return a;
275
+ const t = h.normalizeSpecialPageName(o);
276
276
  return s.byNormalized.get(t) ?? null;
277
277
  }
278
278
  }, p = {
@@ -281,26 +281,26 @@ const m = /* @__PURE__ */ new WeakMap(), g = {
281
281
  */
282
282
  normalizeNamespaceText: (i) => i.replace(/[_\s]+/g, "_").toLowerCase().replace(/^_+|_+$/g, ""),
283
283
  buildIndex: (i) => {
284
- const s = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map();
285
- for (const [a, e] of Object.entries(i.namespaces)) {
286
- const r = parseInt(a);
287
- s.set(e.name, r), o.set(e.canonical ?? "", r);
284
+ const s = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map();
285
+ for (const [r, e] of Object.entries(i.namespaces)) {
286
+ const n = parseInt(r);
287
+ s.set(e.name, n), o.set(e.canonical ?? "", n);
288
288
  const l = p.normalizeNamespaceText(e.name), c = p.normalizeNamespaceText(e.canonical ?? "");
289
- t.set(l, r), t.set(c, r);
289
+ t.set(l, n), t.set(c, n);
290
290
  }
291
- for (const a of i.namespacealiases) {
292
- n.set(a.alias, a.id);
293
- const e = p.normalizeNamespaceText(a.alias);
294
- t.set(e, a.id);
291
+ for (const r of i.namespacealiases) {
292
+ a.set(r.alias, r.id);
293
+ const e = p.normalizeNamespaceText(r.alias);
294
+ t.set(e, r.id);
295
295
  }
296
- return { byName: s, byCanonical: o, byAlias: n, byNormalized: t };
296
+ return { byName: s, byCanonical: o, byAlias: a, byNormalized: t };
297
297
  },
298
298
  findNamespaceId: (i, s) => {
299
299
  let o = s.byName.get(i) ?? s.byCanonical.get(i) ?? s.byAlias.get(i);
300
300
  if (o !== void 0)
301
301
  return o;
302
- const n = p.normalizeNamespaceText(i);
303
- return s.byNormalized.get(n) ?? null;
302
+ const a = p.normalizeNamespaceText(i);
303
+ return s.byNormalized.get(a) ?? null;
304
304
  },
305
305
  isTalkPage: (i) => i % 2 === 1 && i > 0,
306
306
  getDefaultNamespaceInfo: (i) => ({
@@ -317,10 +317,16 @@ function w(i) {
317
317
  const s = m.get(i);
318
318
  if (s)
319
319
  return s;
320
- const o = p.buildIndex(i), n = u.buildSpecialPageIndex(i);
320
+ const o = p.buildIndex(i), a = h.buildSpecialPageIndex(i);
321
321
  class t {
322
- constructor(e, r) {
323
- if (this.newTitle = t.create.bind(t), this.toText = this.getPrefixedText.bind(this), this.toString = this.getPrefixedDBKey.bind(this), this.#e = e || "", this.#t = r ?? 0, r === void 0 ? this.fixNSByTitle() : this.stripNamespaceFromTitle(), this.getMainText() === "")
322
+ constructor(e, n) {
323
+ if (this.newTitle = t.create.bind(t), this.toText = this.getPrefixedText.bind(this), this.toString = this.getPrefixedDBKey.bind(this), this.#t = e || "", this.#e = n ?? 0, n === void 0)
324
+ this.fixNSByTitle();
325
+ else {
326
+ const l = this.parseTitlePrefix(this.#t);
327
+ l && l.namespaceId === this.#e && (this.#t = l.mainTitle);
328
+ }
329
+ if (this.getMainText() === "")
324
330
  throw new Error("Invalid title");
325
331
  }
326
332
  static {
@@ -330,85 +336,85 @@ function w(i) {
330
336
  this._namespaceIndex = o;
331
337
  }
332
338
  static {
333
- this._specialPageIndex = n;
339
+ this._specialPageIndex = a;
334
340
  }
335
341
  /** 缓存的 main title,不包含命名空间前缀,大小写和空格状态不确定 */
336
- #e;
337
- /** 缓存的 namespace ID */
338
342
  #t;
339
- static create(e, r) {
340
- return new t(e, r);
343
+ /** 缓存的 namespace ID */
344
+ #e;
345
+ static create(e, n) {
346
+ return new t(e, n);
341
347
  }
342
- fixNSByTitle() {
343
- const e = this.#e.indexOf(":");
344
- if (e === -1)
345
- return;
346
- if (e === 0) {
347
- this.#e = this.#e.substring(1);
348
- return;
349
- }
350
- const r = this.#e.substring(0, e), l = this.#e.substring(e + 1), c = p.findNamespaceId(
351
- r,
348
+ /**
349
+ * 解析标题前缀,返回匹配到的命名空间 ID 与剥离后的主标题
350
+ */
351
+ parseTitlePrefix(e) {
352
+ const n = e.indexOf(":");
353
+ if (n <= 0)
354
+ return null;
355
+ const l = e.substring(0, n), c = e.substring(n + 1), u = p.findNamespaceId(
356
+ l,
352
357
  t._namespaceIndex
353
358
  );
354
- c !== null && (this.#e = l, this.#t = c);
355
- }
356
- stripNamespaceFromTitle() {
357
- const e = this.#e.indexOf(":");
358
- if (e === -1)
359
- return;
360
- if (e === 0) {
361
- this.#e = this.#e.substring(1);
362
- return;
359
+ return u === null ? null : { namespaceId: u, mainTitle: c };
360
+ }
361
+ /**
362
+ * 如果标题包含可识别命名空间,则采用该命名空间并剥离前缀
363
+ */
364
+ adoptNamespaceFromTitle() {
365
+ const e = this.parseTitlePrefix(this.#t);
366
+ e && (this.#t = e.mainTitle, this.#e = e.namespaceId);
367
+ }
368
+ fixNSByTitle() {
369
+ const e = this.#t.indexOf(":");
370
+ if (e !== -1) {
371
+ if (e === 0) {
372
+ this.#t = this.#t.substring(1);
373
+ return;
374
+ }
375
+ this.adoptNamespaceFromTitle();
363
376
  }
364
- const r = this.#e.substring(0, e), l = this.#e.substring(e + 1);
365
- p.findNamespaceId(
366
- r,
367
- t._namespaceIndex
368
- ) !== null && (this.#e = l);
369
377
  }
370
378
  getNamespaceInfo() {
371
- return t._meta.namespaces[this.#t] ?? p.getDefaultNamespaceInfo(this.#t);
379
+ return t._meta.namespaces[this.#e] ?? p.getDefaultNamespaceInfo(this.#e);
380
+ }
381
+ /**
382
+ * 若为特殊页面,返回解析后的真实主名(含子页面);否则返回 null
383
+ */
384
+ resolveSpecialFullTitle() {
385
+ if (this.#e !== -1) return null;
386
+ const e = h.findSpecialPageRealName(
387
+ this.#t,
388
+ t._specialPageIndex
389
+ );
390
+ if (!e) return null;
391
+ const n = this.#t.includes("/") ? this.#t.substring(this.#t.indexOf("/")) : "";
392
+ return e + n;
393
+ }
394
+ /**
395
+ * 将主标题格式化为输出内容(文本或 DBKey),并做大小写规范化
396
+ */
397
+ formatMainForOutput(e) {
398
+ const n = this.getNamespaceInfo(), c = this.resolveSpecialFullTitle() ?? this.#t, u = e === "db" ? g.toDBKey(c) : g.toNormalText(c);
399
+ return g.ensureCase(u, n.case);
372
400
  }
373
401
  getMainDBKey() {
374
- const e = this.getNamespaceInfo();
375
- if (this.#t === -1) {
376
- const r = u.findSpecialPageRealName(
377
- this.#e,
378
- t._specialPageIndex
379
- );
380
- if (r) {
381
- const l = this.#e.includes("/") ? this.#e.substring(this.#e.indexOf("/")) : "", c = r + l;
382
- return g.ensureCase(g.toDBKey(c), e.case);
383
- }
384
- }
385
- return g.ensureCase(g.toDBKey(this.#e), e.case);
402
+ return this.formatMainForOutput("db");
386
403
  }
387
404
  getMainText() {
388
- const e = this.getNamespaceInfo();
389
- if (this.#t === -1) {
390
- const r = u.findSpecialPageRealName(
391
- this.#e,
392
- t._specialPageIndex
393
- );
394
- if (r) {
395
- const l = this.#e.includes("/") ? this.#e.substring(this.#e.indexOf("/")) : "", c = r + l;
396
- return g.ensureCase(g.toNormalText(c), e.case);
397
- }
398
- }
399
- return g.ensureCase(g.toNormalText(this.#e), e.case);
405
+ return this.formatMainForOutput("text");
400
406
  }
401
407
  getMainRootText() {
402
408
  return this.getMainText().split("/")[0];
403
409
  }
404
410
  getPrefixedDBKey() {
405
- return this.#t === 0 ? this.getMainDBKey() : `${this.getNamespaceDBKey()}:${this.getMainDBKey()}`;
411
+ return this.#e === 0 ? this.getMainDBKey() : `${this.getNamespaceDBKey()}:${this.getMainDBKey()}`;
406
412
  }
407
413
  getPrefixedText() {
408
- return this.#t === 0 ? this.getMainText() : `${this.getNamespaceText()}:${this.getMainText()}`;
414
+ return this.#e === 0 ? this.getMainText() : `${this.getNamespaceText()}:${this.getMainText()}`;
409
415
  }
410
416
  getNamespaceId() {
411
- return this.#t;
417
+ return this.#e;
412
418
  }
413
419
  getNamespaceText() {
414
420
  return this.getNamespaceInfo().name ?? "";
@@ -418,59 +424,73 @@ function w(i) {
418
424
  return g.ensureCase(g.toDBKey(this.getNamespaceText()), e.case);
419
425
  }
420
426
  getSubjectPage() {
421
- if (p.isTalkPage(this.#t)) {
422
- const e = this.#t - 1;
423
- return new t(this.#e, e);
427
+ if (p.isTalkPage(this.#e)) {
428
+ const e = this.#e - 1;
429
+ return new t(this.#t, e);
424
430
  }
425
431
  return this;
426
432
  }
427
433
  getTalkPage() {
428
- if (p.isTalkPage(this.#t))
434
+ if (p.isTalkPage(this.#e))
429
435
  return this;
430
- if (this.#t < 0)
436
+ if (this.#e < 0)
431
437
  return null;
432
- const e = this.#t + 1;
433
- return t._meta.namespaces[e.toString()] ? new t(this.#e, e) : null;
438
+ const e = this.#e + 1;
439
+ return t._meta.namespaces[e.toString()] ? new t(this.#t, e) : null;
434
440
  }
435
441
  getURL(e) {
436
- const r = t._meta.general.articlepath, l = this.getPrefixedDBKey(), c = r.replace("$1", l), h = new URL(c, location.origin);
437
- return e && (e instanceof URLSearchParams ? e : new URLSearchParams(e)).forEach((d, f) => {
438
- h.searchParams.set(f, d);
439
- }), h;
442
+ const n = this.getPrefixedDBKey();
443
+ return this.buildArticleURL(n, e);
444
+ }
445
+ /**
446
+ * 构建文章 URL 并附加查询参数
447
+ */
448
+ buildArticleURL(e, n) {
449
+ const c = t._meta.general.articlepath.replace("$1", e), u = new URL(c, location.origin);
450
+ return n && (n instanceof URLSearchParams ? n : new URLSearchParams(n)).forEach((d, f) => {
451
+ u.searchParams.set(f, d);
452
+ }), u;
440
453
  }
441
454
  /**
442
455
  * 设置标题,重置当前实例的 dbkey 和 ns
443
- * @param title 新的标题字符串
456
+ * 行为:
457
+ * - 如果标题包含可识别的命名空间前缀,则以该前缀为准更新 ns,并移除前缀
458
+ * - 如果标题前缀与当前 ns 相同,则仅移除冗余前缀并保留当前 ns
459
+ * - 否则(无前缀),重置为主命名空间
444
460
  */
445
461
  setTitle(e) {
446
- return this.#e = e, this.#t = 0, this.fixNSByTitle(), this;
462
+ this.#t = e;
463
+ const n = this.#e;
464
+ this.#e = 0;
465
+ const l = this.parseTitlePrefix(this.#t);
466
+ return l ? (n !== 0 && l.namespaceId === n ? (this.#t = l.mainTitle, this.#e = n) : (this.#t = l.mainTitle, this.#e = l.namespaceId), this) : this;
447
467
  }
448
468
  setMainText(e) {
449
- return this.#e = e, this;
469
+ return this.#t = e, this;
450
470
  }
451
471
  setNamespaceText(e) {
452
- const r = p.findNamespaceId(e, t._namespaceIndex);
453
- return r !== null && (this.#t = r), this;
472
+ const n = p.findNamespaceId(e, t._namespaceIndex);
473
+ return n !== null && (this.#e = n), this;
454
474
  }
455
475
  setNamespaceId(e) {
456
- return this.#t = e, this;
476
+ return this.#e = e, this;
457
477
  }
458
478
  equals(e) {
459
479
  return typeof e == "string" && (e = new t(e)), this.getPrefixedDBKey() === e.getPrefixedDBKey();
460
480
  }
461
481
  isSpecial(e) {
462
- if (this.#t !== -1)
482
+ if (this.#e !== -1)
463
483
  return !1;
464
- const r = new t(e, -1);
465
- return this.getMainRootText() === r.getMainRootText();
484
+ const n = new t(e, -1);
485
+ return this.getMainRootText() === n.getMainRootText();
466
486
  }
467
487
  toJSON() {
468
488
  return {
469
- ns: this.#t,
489
+ ns: this.#e,
470
490
  text: this.getMainText(),
471
491
  title: this.getPrefixedText(),
472
492
  url: this.getURL().toString(),
473
- isSpecial: this.#t < 0
493
+ isSpecial: this.#e < 0
474
494
  };
475
495
  }
476
496
  }
@@ -481,6 +501,6 @@ export {
481
501
  I as WatchlistAction,
482
502
  b as createWikiPageModel,
483
503
  w as createWikiTitleModel,
484
- v as useMemoryStorage
504
+ N as useMemoryStorage
485
505
  };
486
506
  //# sourceMappingURL=index.js.map