@inpageedit/core 0.12.1 → 0.13.0-alpha.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 (113) hide show
  1. package/dist/BasePlugin-Bf2UuIHF.js +64 -0
  2. package/dist/BasePlugin-Bf2UuIHF.js.map +1 -0
  3. package/dist/{PluginPrefSync-Ziogy_o-.js → PluginPrefSync-Dn1Xsiqz.js} +6 -4
  4. package/dist/PluginPrefSync-Dn1Xsiqz.js.map +1 -0
  5. package/dist/{PluginStoreApp-Bnvyl-Oc.js → PluginStoreApp-CpOLArL7.js} +2 -2
  6. package/dist/{PluginStoreApp-Bnvyl-Oc.js.map → PluginStoreApp-CpOLArL7.js.map} +1 -1
  7. package/dist/WatchlistAction-BbNAyryN.js +5 -0
  8. package/dist/WatchlistAction-BbNAyryN.js.map +1 -0
  9. package/dist/endpoints-DgyuoRZd.js +1507 -0
  10. package/dist/endpoints-DgyuoRZd.js.map +1 -0
  11. package/dist/{index-BvuaLEFc.js → index-2RfILgXm.js} +11 -10
  12. package/dist/{index-BvuaLEFc.js.map → index-2RfILgXm.js.map} +1 -1
  13. package/dist/{index-eARjMi7f.js → index-BCdABp0e.js} +23 -22
  14. package/dist/{index-eARjMi7f.js.map → index-BCdABp0e.js.map} +1 -1
  15. package/dist/{index-zHTGCjfF.js → index-BJ7_Q1mB.js} +8 -7
  16. package/dist/{index-zHTGCjfF.js.map → index-BJ7_Q1mB.js.map} +1 -1
  17. package/dist/{index-Dnmv-xDn.js → index-BNh95-x2.js} +37 -49
  18. package/dist/index-BNh95-x2.js.map +1 -0
  19. package/dist/{index-B3FUDhxl.js → index-BQ-cHWkJ.js} +15 -16
  20. package/dist/{index-B3FUDhxl.js.map → index-BQ-cHWkJ.js.map} +1 -1
  21. package/dist/{index-B3YJdjxo.js → index-BwdWyHLe.js} +77 -76
  22. package/dist/{index-B3YJdjxo.js.map → index-BwdWyHLe.js.map} +1 -1
  23. package/dist/{index-Ccr3YhkP.js → index-CCRMmnwk.js} +10 -9
  24. package/dist/{index-Ccr3YhkP.js.map → index-CCRMmnwk.js.map} +1 -1
  25. package/dist/{index-Bd70aDMT.js → index-CnIpUF9x.js} +7 -6
  26. package/dist/{index-Bd70aDMT.js.map → index-CnIpUF9x.js.map} +1 -1
  27. package/dist/{index-D5zX93bn.js → index-CyG7_IYz.js} +47 -45
  28. package/dist/{index-D5zX93bn.js.map → index-CyG7_IYz.js.map} +1 -1
  29. package/dist/index-DdTiZqwt.js +3744 -0
  30. package/dist/index-DdTiZqwt.js.map +1 -0
  31. package/dist/{index-BRjEc8b8.js → index-eSlbrNqF.js} +6 -6
  32. package/dist/{index-BRjEc8b8.js.map → index-eSlbrNqF.js.map} +1 -1
  33. package/dist/index.d.ts +1723 -31
  34. package/dist/index.js +73 -9
  35. package/dist/index.js.map +1 -1
  36. package/dist/models/index.js +486 -0
  37. package/dist/models/index.js.map +1 -0
  38. package/dist/plugins/index.js +23 -0
  39. package/dist/plugins/index.js.map +1 -0
  40. package/dist/services/index.js +16 -0
  41. package/dist/services/index.js.map +1 -0
  42. package/dist/style.css +1 -1
  43. package/lib/index.umd.js +10 -10
  44. package/lib/index.umd.js.map +1 -1
  45. package/package.json +22 -25
  46. package/dist/InPageEdit.d.ts +0 -42
  47. package/dist/PluginPrefSync-Ziogy_o-.js.map +0 -1
  48. package/dist/__test__/utils/constants.d.ts +0 -3
  49. package/dist/components/ActionButton.d.ts +0 -6
  50. package/dist/components/CheckBox.d.ts +0 -10
  51. package/dist/components/Icon/IconEdit.d.ts +0 -2
  52. package/dist/components/Icon/IconQuickEdit.d.ts +0 -2
  53. package/dist/components/InputBox.d.ts +0 -11
  54. package/dist/components/MBox/index.d.ts +0 -14
  55. package/dist/components/MwUserLinks.d.ts +0 -6
  56. package/dist/components/ProgressBar/index.d.ts +0 -7
  57. package/dist/components/RadioBox.d.ts +0 -10
  58. package/dist/components/TabView/index.d.ts +0 -19
  59. package/dist/components/TwinSwapInput/index.d.ts +0 -19
  60. package/dist/components/index.d.ts +0 -8
  61. package/dist/components/utils.d.ts +0 -4
  62. package/dist/constants/endpoints.d.ts +0 -8
  63. package/dist/decorators/Preferences.d.ts +0 -35
  64. package/dist/index-DgQNTfPR.js +0 -5829
  65. package/dist/index-DgQNTfPR.js.map +0 -1
  66. package/dist/index-Dnmv-xDn.js.map +0 -1
  67. package/dist/models/MemoryStorage.d.ts +0 -10
  68. package/dist/models/WikiPage/index.d.ts +0 -76
  69. package/dist/models/WikiPage/types/PageInfo.d.ts +0 -58
  70. package/dist/models/WikiPage/types/PageParseData.d.ts +0 -17
  71. package/dist/models/WikiPage/types/WatchlistAction.d.ts +0 -6
  72. package/dist/models/WikiTitle/index.d.ts +0 -89
  73. package/dist/models/WikiTitle/index.spec.d.ts +0 -1
  74. package/dist/plugins/BasePlugin.d.ts +0 -25
  75. package/dist/plugins/_debug/index.d.ts +0 -8
  76. package/dist/plugins/analytics/index.d.ts +0 -41
  77. package/dist/plugins/in-article-links/index.d.ts +0 -44
  78. package/dist/plugins/plugin-store/index.d.ts +0 -56
  79. package/dist/plugins/plugin-store/schema.d.ts +0 -41
  80. package/dist/plugins/preferences-ui/PluginPrefSync.d.ts +0 -28
  81. package/dist/plugins/preferences-ui/index.d.ts +0 -48
  82. package/dist/plugins/quick-diff/components/DiffTable.d.ts +0 -23
  83. package/dist/plugins/quick-diff/index.d.ts +0 -85
  84. package/dist/plugins/quick-edit/index.d.ts +0 -79
  85. package/dist/plugins/quick-move/index.d.ts +0 -47
  86. package/dist/plugins/quick-preview/index.d.ts +0 -37
  87. package/dist/plugins/quick-redirect/index.d.ts +0 -48
  88. package/dist/plugins/toolbox/index.d.ts +0 -65
  89. package/dist/polyfills/Promise.withResolvers.d.ts +0 -5
  90. package/dist/polyfills/index.d.ts +0 -0
  91. package/dist/services/ApiService.d.ts +0 -14
  92. package/dist/services/CurrentPageService.d.ts +0 -28
  93. package/dist/services/ModalService.d.ts +0 -27
  94. package/dist/services/PreferencesService.d.ts +0 -94
  95. package/dist/services/ResourceLoaderService.d.ts +0 -17
  96. package/dist/services/WikiMetadataService.d.ts +0 -108
  97. package/dist/services/WikiPageService.d.ts +0 -20
  98. package/dist/services/WikiTitleService.d.ts +0 -70
  99. package/dist/services/storage/index.d.ts +0 -40
  100. package/dist/services/storage/managers/IDBStorageManager.d.ts +0 -28
  101. package/dist/services/storage/managers/LocalStorageManager.d.ts +0 -27
  102. package/dist/types/WikiMetadata.d.ts +0 -131
  103. package/dist/utils/computeable.d.ts +0 -2
  104. package/dist/utils/defineAsyncPlugin.d.ts +0 -2
  105. package/dist/utils/interpolate.d.ts +0 -20
  106. package/dist/utils/interpolate.spec.d.ts +0 -1
  107. package/dist/utils/makeCallable.d.ts +0 -3
  108. package/dist/utils/noop.d.ts +0 -1
  109. package/dist/utils/sleep.d.ts +0 -1
  110. package/dist/utils/string.d.ts +0 -7
  111. package/dist/utils/url.d.ts +0 -24
  112. package/dist/utils/vueHooks.d.ts +0 -6
  113. package/dist/utils/vueReactivity.d.ts +0 -2
package/dist/index.js CHANGED
@@ -1,12 +1,76 @@
1
- import { B as s, c as g, I as r, m as c, $ as o, S as t, b as L, d as i } from "./index-DgQNTfPR.js";
1
+ import { I as s } from "./index-DdTiZqwt.js";
2
+ import { m as l, $ as g, S as m } from "./index-DdTiZqwt.js";
3
+ import { E as r } from "./endpoints-DgyuoRZd.js";
4
+ import { I as L, S as P, a as U } from "./endpoints-DgyuoRZd.js";
5
+ import { B as S } from "./BasePlugin-Bf2UuIHF.js";
6
+ import { R as M } from "./Preferences-DS4-CFWe.js";
7
+ window.RLQ ||= [];
8
+ window.__IPE_MODULES__ ||= [];
9
+ w("InPageEdit#autoload", () => {
10
+ const _ = a();
11
+ _ && c({
12
+ baseURL: _,
13
+ InPageEdit: s
14
+ });
15
+ });
16
+ async function c(_ = { baseURL: a(), InPageEdit: s }) {
17
+ const { baseURL: o, InPageEdit: i } = _;
18
+ typeof window?.ipe?.stop == "function" && await window.ipe.stop();
19
+ const d = window.InPageEdit || {}, e = new i({
20
+ apiConfigs: {
21
+ baseURL: o
22
+ },
23
+ legacyPreferences: d?.myPreferences || {}
24
+ });
25
+ if (window.ipe = e, await e.start(), window.RLQ.push(() => {
26
+ mw.hook("InPageEdit.ready").fire(e);
27
+ }), Array.isArray(window.__IPE_MODULES__)) {
28
+ const t = [];
29
+ for (; window.__IPE_MODULES__.length; )
30
+ try {
31
+ const n = window.__IPE_MODULES__.shift();
32
+ typeof n == "function" && n?.(e), t.push(n);
33
+ } catch {
34
+ }
35
+ window.__IPE_MODULES__ = {
36
+ push: (n) => {
37
+ typeof n == "function" && n(e), t.push(n);
38
+ }
39
+ }, e.on("dispose", () => {
40
+ window.__IPE_MODULES__ = t;
41
+ });
42
+ }
43
+ e.logger("AUTOLOAD").info(
44
+ `
45
+ ____ ____ ______ ___ __
46
+ / _/___ / __ \\____ _____ ____ / ____/___/ (_) /_
47
+ / // __ \\/ /_/ / __ \`/ __ \`/ _ \\/ __/ / __ / / __/
48
+ _/ // / / / ____/ /_/ / /_/ / __/ /___/ /_/ / / /_
49
+ /___/_/ /_/_/ \\__,_/\\__, /\\___/_____/\\__,_/_/\\__/
50
+ /____/ v` + e.version + `
51
+ - Wiki API Endpoint: ${o}
52
+ - Documentation: ${r.HOME_URL}
53
+ - Bug Reports: ${r.GITHUB_URL}`
54
+ );
55
+ }
56
+ function a() {
57
+ const _ = document.querySelector('meta[name="generator"][content^="MediaWiki"]') !== null, o = document.querySelector('link[rel="EditURI"]')?.href?.split("?")[0];
58
+ return _ && o ? o : void 0;
59
+ }
60
+ function w(_, o) {
61
+ const i = Symbol.for(_);
62
+ return window[i] ? !1 : (window[i] = !0, o(), !0);
63
+ }
2
64
  export {
3
- s as BasePlugin,
4
- g as InPageEdit,
5
- r as Inject,
6
- c as Logger,
7
- o as LoggerLevel,
8
- t as Schema,
9
- L as Service,
10
- i as createLogger
65
+ S as BasePlugin,
66
+ r as Endpoints,
67
+ s as InPageEdit,
68
+ L as Inject,
69
+ l as Logger,
70
+ g as LoggerLevel,
71
+ M as RegisterPreferences,
72
+ P as Schema,
73
+ U as Service,
74
+ m as createLogger
11
75
  };
12
76
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
1
+ {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import './polyfills/index.js'\nimport { InPageEdit } from './InPageEdit.js'\nimport { Endpoints } from './constants/endpoints.js'\n\n// 模块重导出\nexport * from './InPageEdit.js'\nexport { default as BasePlugin } from './plugins/BasePlugin.js'\nexport { Endpoints }\nexport { RegisterPreferences } from './decorators/Preferences.js'\n\n// Safe guard\nwindow.RLQ ||= []\nwindow.__IPE_MODULES__ ||= []\n\n// Auto load if the site is MediaWiki\nrunOnce('InPageEdit#autoload', () => {\n const baseURL = detectMediaWikiApiEndpoint()\n if (baseURL) {\n autoload({\n baseURL,\n InPageEdit,\n })\n }\n})\nasync function autoload(\n _overload: {\n baseURL?: string\n InPageEdit: typeof InPageEdit\n } = { baseURL: detectMediaWikiApiEndpoint(), InPageEdit: InPageEdit }\n) {\n const { baseURL, InPageEdit: IPE } = _overload\n\n // 防止多次运行\n if (typeof window?.ipe?.stop === 'function') {\n console.warn('[InPageEdit] Already loaded, disposing...')\n await window.ipe.stop()\n }\n\n const oldGlobalVar: any = (window as any).InPageEdit || {}\n const ipe = new IPE({\n apiConfigs: {\n baseURL,\n },\n legacyPreferences: oldGlobalVar?.myPreferences || {},\n })\n\n // Merge into global variables\n window.ipe = ipe\n\n // Start the App\n await ipe.start()\n\n // Trigger the mw.hook\n window.RLQ.push(() => {\n mw.hook('InPageEdit.ready').fire(ipe)\n })\n\n // Initialize global modules\n if (Array.isArray(window.__IPE_MODULES__)) {\n const installedModules = [] as any[]\n while (window.__IPE_MODULES__.length) {\n try {\n const payload = window.__IPE_MODULES__.shift()\n typeof payload === 'function' && payload?.(ipe)\n installedModules.push(payload)\n } catch (error) {\n console.error('[InPageEdit] Failed to initialize module:', error)\n }\n }\n window.__IPE_MODULES__ = {\n push: (payload) => {\n typeof payload === 'function' && payload(ipe)\n installedModules.push(payload)\n },\n }\n ipe.on('dispose', () => {\n window.__IPE_MODULES__ = installedModules\n })\n }\n\n // 花里胡哨的加载提示\n ipe.logger('AUTOLOAD').info(\n '\\n' +\n ' ____ ____ ______ ___ __ \\n / _/___ / __ \\\\____ _____ ____ / ____/___/ (_) /_\\n / // __ \\\\/ /_/ / __ `/ __ `/ _ \\\\/ __/ / __ / / __/\\n _/ // / / / ____/ /_/ / /_/ / __/ /___/ /_/ / / /_ \\n/___/_/ /_/_/ \\\\__,_/\\\\__, /\\\\___/_____/\\\\__,_/_/\\\\__/ \\n /____/ v' +\n ipe.version +\n `\n- Wiki API Endpoint: ${baseURL}\n- Documentation: ${Endpoints.HOME_URL}\n- Bug Reports: ${Endpoints.GITHUB_URL}`\n )\n}\n\nfunction detectMediaWikiApiEndpoint(): string | undefined {\n const isMediaWiki =\n document.querySelector('meta[name=\"generator\"][content^=\"MediaWiki\"]') !== null\n const apiBase = document\n .querySelector<HTMLLinkElement>('link[rel=\"EditURI\"]')\n ?.href?.split('?')[0]\n return isMediaWiki && apiBase ? apiBase : undefined\n}\n\nfunction runOnce(key: string, fn: Function) {\n const sym = Symbol.for(key)\n if ((window as any)[sym]) {\n return false\n }\n ;(window as any)[sym] = true\n fn()\n return true\n}\n\n// HMR\nif (import.meta.hot) {\n const SEPARATOR = `\\n${'='.repeat(20)} [InPageEdit] HMR ${'='.repeat(20)}\\n`\n import.meta.hot.accept(async (modules) => {\n const apiBase = detectMediaWikiApiEndpoint()!\n const IPE = modules?.InPageEdit as unknown as typeof InPageEdit\n if (!apiBase || !IPE) {\n console.warn(SEPARATOR.trimStart(), 'missing modules', SEPARATOR.trimEnd())\n location.reload()\n return\n }\n\n console.info(SEPARATOR.trimStart(), \"I'm so hot!\", modules, SEPARATOR.trimEnd())\n await window?.ipe?.stop()\n window.ipe = undefined as any\n autoload({\n baseURL: apiBase,\n InPageEdit: IPE,\n })\n })\n}\n\n// 类型定义\n\n// Global types declaration\ndeclare global {\n const ipe: InPageEdit\n interface Window {\n ipe: InPageEdit\n __IPE_MODULES__: {\n push(payload: (ipe: InPageEdit) => void): void\n }\n }\n}\n\n// MediaWiki ResourceLoader Queue\ndeclare global {\n interface Window {\n RLQ: {\n push(callback: () => void): void\n push(depAndCallback: [string, () => void]): void\n push(depsAndCallback: [string[], () => void]): void\n }\n }\n}\n\n// declare mw.hook\ndeclare global {\n namespace mw {\n /**\n * @see https://doc.wikimedia.org/mediawiki-core/master/js/Hook.html\n * @see https://github.com/wikimedia-gadgets/types-mediawiki/blob/9b4e7c3b9034d64a44a0667229a6d9585fe09b30/mw/hook.d.ts\n */\n interface Hook<T extends any[] = any[]> {\n add(...handler: Array<(...data: T) => any>): this\n deprecate(msg: string): this\n fire(...data: T): this\n remove(...handler: Array<(...data: T) => any>): this\n }\n function hook(name: 'InPageEdit.ready'): Hook<[InPageEdit]>\n }\n}\n\n// 类型重导出\n\n// expose all types\nexport type * from './components/index.js'\nexport type * from './models/index.js'\nexport type * from './plugins/index.js'\nexport type * from './services/index.js'\nexport type * from './types/index.js'\n"],"names":["runOnce","baseURL","detectMediaWikiApiEndpoint","autoload","InPageEdit","_overload","IPE","oldGlobalVar","ipe","installedModules","payload","Endpoints","isMediaWiki","apiBase","key","fn","sym"],"mappings":";;;;;;AAWA,OAAO,QAAQ,CAAA;AACf,OAAO,oBAAoB,CAAA;AAG3BA,EAAQ,uBAAuB,MAAM;AACnC,QAAMC,IAAUC,EAAA;AAChB,EAAID,KACFE,EAAS;AAAA,IACP,SAAAF;AAAA,IACA,YAAAG;AAAA,EAAA,CACD;AAEL,CAAC;AACD,eAAeD,EACbE,IAGI,EAAE,SAASH,EAAA,GAA8B,YAAAE,KAC7C;AACA,QAAM,EAAE,SAAAH,GAAS,YAAYK,EAAA,IAAQD;AAGrC,EAAI,OAAO,QAAQ,KAAK,QAAS,cAE/B,MAAM,OAAO,IAAI,KAAA;AAGnB,QAAME,IAAqB,OAAe,cAAc,CAAA,GAClDC,IAAM,IAAIF,EAAI;AAAA,IAClB,YAAY;AAAA,MACV,SAAAL;AAAA,IAAA;AAAA,IAEF,mBAAmBM,GAAc,iBAAiB,CAAA;AAAA,EAAC,CACpD;AAcD,MAXA,OAAO,MAAMC,GAGb,MAAMA,EAAI,MAAA,GAGV,OAAO,IAAI,KAAK,MAAM;AACpB,OAAG,KAAK,kBAAkB,EAAE,KAAKA,CAAG;AAAA,EACtC,CAAC,GAGG,MAAM,QAAQ,OAAO,eAAe,GAAG;AACzC,UAAMC,IAAmB,CAAA;AACzB,WAAO,OAAO,gBAAgB;AAC5B,UAAI;AACF,cAAMC,IAAU,OAAO,gBAAgB,MAAA;AACvC,eAAOA,KAAY,cAAcA,IAAUF,CAAG,GAC9CC,EAAiB,KAAKC,CAAO;AAAA,MAC/B,QAAgB;AAAA,MAEhB;AAEF,WAAO,kBAAkB;AAAA,MACvB,MAAM,CAACA,MAAY;AACjB,eAAOA,KAAY,cAAcA,EAAQF,CAAG,GAC5CC,EAAiB,KAAKC,CAAO;AAAA,MAC/B;AAAA,IAAA,GAEFF,EAAI,GAAG,WAAW,MAAM;AACtB,aAAO,kBAAkBC;AAAA,IAC3B,CAAC;AAAA,EACH;AAGA,EAAAD,EAAI,OAAO,UAAU,EAAE;AAAA,IACrB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iDAEEA,EAAI,UACJ;AAAA,uBACiBP,CAAO;AAAA,uBACPU,EAAU,QAAQ;AAAA,uBAClBA,EAAU,UAAU;AAAA,EAAA;AAE3C;AAEA,SAAST,IAAiD;AACxD,QAAMU,IACJ,SAAS,cAAc,8CAA8C,MAAM,MACvEC,IAAU,SACb,cAA+B,qBAAqB,GACnD,MAAM,MAAM,GAAG,EAAE,CAAC;AACtB,SAAOD,KAAeC,IAAUA,IAAU;AAC5C;AAEA,SAASb,EAAQc,GAAaC,GAAc;AAC1C,QAAMC,IAAM,OAAO,IAAIF,CAAG;AAC1B,SAAK,OAAeE,CAAG,IACd,MAEP,OAAeA,CAAG,IAAI,IACxBD,EAAA,GACO;AACT;"}
@@ -0,0 +1,486 @@
1
+ import { W as I } from "../WatchlistAction-BbNAyryN.js";
2
+ class y {
3
+ constructor() {
4
+ this.values = {};
5
+ }
6
+ get length() {
7
+ return Object.keys(this.values).length;
8
+ }
9
+ clear() {
10
+ this.values = {};
11
+ }
12
+ getItem(s) {
13
+ return this.values[s] ?? null;
14
+ }
15
+ setItem(s, o) {
16
+ this.values[s] = typeof o == "string" ? o : String(o);
17
+ }
18
+ removeItem(s) {
19
+ delete this.values[s];
20
+ }
21
+ key(s) {
22
+ return Object.keys(this.values)[s] ?? null;
23
+ }
24
+ }
25
+ const v = () => new Proxy(new y(), {
26
+ set(i, s, o) {
27
+ return typeof s == "string" && i.setItem(s, o), !0;
28
+ },
29
+ get(i, s) {
30
+ return typeof s == "string" && !(s in i) ? i.getItem(s) : Reflect.get(i, s);
31
+ }
32
+ });
33
+ function b(i) {
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);
38
+ }), this.pageInfo = {
39
+ ...s.DEFAULT_PAGE_INFO,
40
+ ...n
41
+ };
42
+ }
43
+ static {
44
+ this.api = i;
45
+ }
46
+ static {
47
+ this.DEFAULT_QUERY_PARAMS = {
48
+ action: "query",
49
+ prop: "info|templates|transcludedin|images|pageimages|revisions",
50
+ inprop: "protection|url|varianttitles",
51
+ intestactions: "edit|move|delete",
52
+ tllimit: "max",
53
+ tilimit: "max",
54
+ imlimit: "max",
55
+ piprop: "thumbnail|name|original",
56
+ pithumbsize: "200",
57
+ pilimit: "max",
58
+ rvprop: "ids|timestamp|flags|comment|user|content",
59
+ rvslots: "main"
60
+ };
61
+ }
62
+ static {
63
+ this.DEFAULT_PAGE_INFO = {
64
+ pageid: 0,
65
+ ns: 0,
66
+ title: "",
67
+ contentmodel: "wikitext",
68
+ pagelanguage: "",
69
+ pagelanguagehtmlcode: "",
70
+ pagelanguagedir: "ltr",
71
+ touched: (/* @__PURE__ */ new Date()).toISOString(),
72
+ lastrevid: 0,
73
+ length: 0,
74
+ protection: [],
75
+ restrictiontypes: [],
76
+ fullurl: "",
77
+ canonicalurl: "",
78
+ editurl: "",
79
+ varianttitles: {},
80
+ actions: {
81
+ edit: !0,
82
+ move: !1,
83
+ delete: !1
84
+ },
85
+ revisions: [],
86
+ templates: [],
87
+ images: []
88
+ };
89
+ }
90
+ // Utils
91
+ static async newFromApi(n) {
92
+ const { data: t } = await this.api.get({
93
+ ...s.DEFAULT_QUERY_PARAMS,
94
+ ...n
95
+ }), a = t?.query?.pages?.[0];
96
+ if (!a || !a.title)
97
+ throw new Error("Invalid page info", { cause: t });
98
+ return new s(a, !0);
99
+ }
100
+ static newBlankPage(n = {}) {
101
+ return new s(n, !1);
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;
106
+ }
107
+ static async newBatchFromApi(n) {
108
+ const { titles: t, pageids: a, revids: e, ...r } = n || {}, { data: l } = await this.api.post({
109
+ ...s.DEFAULT_QUERY_PARAMS,
110
+ titles: t?.join("|") ?? void 0,
111
+ pageids: a?.join("|") ?? void 0,
112
+ revids: e?.join("|") ?? void 0,
113
+ ...r
114
+ });
115
+ return l?.query?.pages?.map((c) => new s(c, !0)) || [];
116
+ }
117
+ // Page actions
118
+ async parse(n) {
119
+ return this.api.post({
120
+ action: "parse",
121
+ page: this.pageInfo.title,
122
+ prop: "text|langlinks|categories|links|templates|images|externallinks|sections|revid|displaytitle|iwlinks|properties|parsewarnings",
123
+ ...n
124
+ });
125
+ }
126
+ async preview(n, t) {
127
+ return this.parse({
128
+ action: "parse",
129
+ page: void 0,
130
+ title: this.title,
131
+ text: n,
132
+ pst: 1,
133
+ preview: 1,
134
+ disableeditsection: 1,
135
+ disablelimitreport: 1,
136
+ ...t
137
+ });
138
+ }
139
+ async edit(n, t) {
140
+ const {
141
+ text: a,
142
+ prependtext: e,
143
+ appendtext: r,
144
+ summary: l = "",
145
+ watchlist: c = I.preferences,
146
+ section: h
147
+ } = n;
148
+ return this.api.postWithEditToken({
149
+ action: "edit",
150
+ title: this.title,
151
+ starttimestamp: this.pageInfo.touched,
152
+ basetimestamp: this.revisions[0]?.timestamp,
153
+ text: a,
154
+ prependtext: e,
155
+ appendtext: r,
156
+ summary: l,
157
+ watchlist: c,
158
+ section: h,
159
+ ...t
160
+ });
161
+ }
162
+ async createOnly(n, t) {
163
+ return this.edit(n, { createonly: 1, ...t });
164
+ }
165
+ async delete(n, t) {
166
+ return this.api.postWithEditToken({
167
+ action: "delete",
168
+ title: this.pageInfo.title || void 0,
169
+ pageid: this.pageInfo.pageid || void 0,
170
+ reason: n,
171
+ deletetalk: t?.deletetalk,
172
+ ...t
173
+ });
174
+ }
175
+ async moveTo(n, t, a) {
176
+ return this.api.postWithEditToken({
177
+ action: "move",
178
+ from: this.pageInfo.title,
179
+ to: n,
180
+ reason: t,
181
+ movetalk: 1,
182
+ movesubpages: 1,
183
+ ...a
184
+ });
185
+ }
186
+ // === utilities ===
187
+ userCan(n) {
188
+ return !!this.pageInfo?.actions?.[n];
189
+ }
190
+ userCanEdit() {
191
+ return this.userCan("edit");
192
+ }
193
+ async reloadSelfInfo() {
194
+ const n = await s.newFromApi({
195
+ pageids: this.pageInfo.pageid,
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),
199
+ []
200
+ );
201
+ return this.pageInfo = n.pageInfo, this.pageInfo.revisions = t, this._loaded = !0, this;
202
+ }
203
+ // === sugar getters ===
204
+ get pageid() {
205
+ return this.pageInfo.pageid;
206
+ }
207
+ get title() {
208
+ return this.pageInfo.title;
209
+ }
210
+ get ns() {
211
+ return this.pageInfo.ns;
212
+ }
213
+ get contentmodel() {
214
+ return this.pageInfo.contentmodel;
215
+ }
216
+ get fullurl() {
217
+ return this.pageInfo.fullurl;
218
+ }
219
+ get canonicalurl() {
220
+ return this.pageInfo.canonicalurl;
221
+ }
222
+ get editurl() {
223
+ return this.pageInfo.editurl;
224
+ }
225
+ get revisions() {
226
+ return this.pageInfo.revisions || [];
227
+ }
228
+ get lastrevid() {
229
+ return this.pageInfo.lastrevid;
230
+ }
231
+ get templates() {
232
+ return this.pageInfo.templates || [];
233
+ }
234
+ get images() {
235
+ return this.pageInfo.images || [];
236
+ }
237
+ }
238
+ return s;
239
+ }
240
+ const m = /* @__PURE__ */ new WeakMap(), g = {
241
+ toDBKey: (i) => i.replace(/ /g, "_"),
242
+ toNormalText: (i) => i.replace(/_/g, " "),
243
+ ensureCase: (i, s) => s === "first-letter" ? i.charAt(0).toUpperCase() + i.slice(1) : i
244
+ }, u = {
245
+ /**
246
+ * 标准化特殊页面名称:转换为全小写
247
+ */
248
+ normalizeSpecialPageName: (i) => i.toLowerCase(),
249
+ /**
250
+ * 构建特殊页面别名索引
251
+ */
252
+ buildSpecialPageIndex: (i) => {
253
+ const s = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
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);
263
+ }
264
+ }
265
+ return { byRealName: s, byAlias: o, byNormalized: n };
266
+ },
267
+ /**
268
+ * 查找特殊页面的真实名称
269
+ */
270
+ findSpecialPageRealName: (i, s) => {
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);
276
+ return s.byNormalized.get(t) ?? null;
277
+ }
278
+ }, p = {
279
+ /**
280
+ * 标准化命名空间文本:转换为全小写+下划线格式
281
+ */
282
+ normalizeNamespaceText: (i) => i.replace(/[_\s]+/g, "_").toLowerCase().replace(/^_+|_+$/g, ""),
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);
288
+ const l = p.normalizeNamespaceText(e.name), c = p.normalizeNamespaceText(e.canonical ?? "");
289
+ t.set(l, r), t.set(c, r);
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);
295
+ }
296
+ return { byName: s, byCanonical: o, byAlias: n, byNormalized: t };
297
+ },
298
+ findNamespaceId: (i, s) => {
299
+ let o = s.byName.get(i) ?? s.byCanonical.get(i) ?? s.byAlias.get(i);
300
+ if (o !== void 0)
301
+ return o;
302
+ const n = p.normalizeNamespaceText(i);
303
+ return s.byNormalized.get(n) ?? null;
304
+ },
305
+ isTalkPage: (i) => i % 2 === 1 && i > 0,
306
+ getDefaultNamespaceInfo: (i) => ({
307
+ id: i,
308
+ name: "",
309
+ canonical: "",
310
+ case: "first-letter",
311
+ content: !1,
312
+ nonincludable: !1,
313
+ subpages: !1
314
+ })
315
+ };
316
+ function w(i) {
317
+ const s = m.get(i);
318
+ if (s)
319
+ return s;
320
+ const o = p.buildIndex(i), n = u.buildSpecialPageIndex(i);
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() === "")
324
+ throw new Error("Invalid title");
325
+ }
326
+ static {
327
+ this._meta = i;
328
+ }
329
+ static {
330
+ this._namespaceIndex = o;
331
+ }
332
+ static {
333
+ this._specialPageIndex = n;
334
+ }
335
+ /** 缓存的 main title,不包含命名空间前缀,大小写和空格状态不确定 */
336
+ #e;
337
+ /** 缓存的 namespace ID */
338
+ #t;
339
+ static create(e, r) {
340
+ return new t(e, r);
341
+ }
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,
352
+ t._namespaceIndex
353
+ );
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;
363
+ }
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
+ }
370
+ getNamespaceInfo() {
371
+ return t._meta.namespaces[this.#t] ?? p.getDefaultNamespaceInfo(this.#t);
372
+ }
373
+ 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);
386
+ }
387
+ 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);
400
+ }
401
+ getMainRootText() {
402
+ return this.getMainText().split("/")[0];
403
+ }
404
+ getPrefixedDBKey() {
405
+ return this.#t === 0 ? this.getMainDBKey() : `${this.getNamespaceDBKey()}:${this.getMainDBKey()}`;
406
+ }
407
+ getPrefixedText() {
408
+ return this.#t === 0 ? this.getMainText() : `${this.getNamespaceText()}:${this.getMainText()}`;
409
+ }
410
+ getNamespaceId() {
411
+ return this.#t;
412
+ }
413
+ getNamespaceText() {
414
+ return this.getNamespaceInfo().name ?? "";
415
+ }
416
+ getNamespaceDBKey() {
417
+ const e = this.getNamespaceInfo();
418
+ return g.ensureCase(g.toDBKey(this.getNamespaceText()), e.case);
419
+ }
420
+ getSubjectPage() {
421
+ if (p.isTalkPage(this.#t)) {
422
+ const e = this.#t - 1;
423
+ return new t(this.#e, e);
424
+ }
425
+ return this;
426
+ }
427
+ getTalkPage() {
428
+ if (p.isTalkPage(this.#t))
429
+ return this;
430
+ if (this.#t < 0)
431
+ return null;
432
+ const e = this.#t + 1;
433
+ return t._meta.namespaces[e.toString()] ? new t(this.#e, e) : null;
434
+ }
435
+ 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;
440
+ }
441
+ /**
442
+ * 设置标题,重置当前实例的 dbkey 和 ns
443
+ * @param title 新的标题字符串
444
+ */
445
+ setTitle(e) {
446
+ return this.#e = e, this.#t = 0, this.fixNSByTitle(), this;
447
+ }
448
+ setMainText(e) {
449
+ return this.#e = e, this;
450
+ }
451
+ setNamespaceText(e) {
452
+ const r = p.findNamespaceId(e, t._namespaceIndex);
453
+ return r !== null && (this.#t = r), this;
454
+ }
455
+ setNamespaceId(e) {
456
+ return this.#t = e, this;
457
+ }
458
+ equals(e) {
459
+ return typeof e == "string" && (e = new t(e)), this.getPrefixedDBKey() === e.getPrefixedDBKey();
460
+ }
461
+ isSpecial(e) {
462
+ if (this.#t !== -1)
463
+ return !1;
464
+ const r = new t(e, -1);
465
+ return this.getMainRootText() === r.getMainRootText();
466
+ }
467
+ toJSON() {
468
+ return {
469
+ ns: this.#t,
470
+ text: this.getMainText(),
471
+ title: this.getPrefixedText(),
472
+ url: this.getURL().toString(),
473
+ isSpecial: this.#t < 0
474
+ };
475
+ }
476
+ }
477
+ return m.set(i, t), t;
478
+ }
479
+ export {
480
+ y as MemoryStorage,
481
+ I as WatchlistAction,
482
+ b as createWikiPageModel,
483
+ w as createWikiTitleModel,
484
+ v as useMemoryStorage
485
+ };
486
+ //# sourceMappingURL=index.js.map