wikiparser-node 1.12.7-b → 1.12.7

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 (174) hide show
  1. package/config/.schema.json +203 -0
  2. package/config/default.json +30 -29
  3. package/config/enwiki.json +829 -15
  4. package/config/llwiki.json +56 -21
  5. package/config/moegirl.json +65 -21
  6. package/config/zhwiki.json +494 -28
  7. package/dist/addon/table.js +494 -0
  8. package/dist/addon/token.js +392 -0
  9. package/dist/addon/transclude.js +184 -0
  10. package/dist/base.d.ts +82 -0
  11. package/dist/base.js +40 -0
  12. package/dist/index.d.ts +33 -0
  13. package/dist/index.js +275 -0
  14. package/dist/internal.d.ts +47 -0
  15. package/dist/lib/element.d.ts +125 -0
  16. package/dist/lib/element.js +377 -0
  17. package/dist/lib/node.d.ts +173 -0
  18. package/dist/lib/node.js +478 -0
  19. package/dist/lib/range.d.ts +105 -0
  20. package/dist/lib/range.js +406 -0
  21. package/dist/lib/ranges.d.ts +28 -0
  22. package/dist/lib/ranges.js +126 -0
  23. package/dist/lib/rect.d.ts +18 -0
  24. package/dist/lib/rect.js +36 -0
  25. package/dist/lib/text.d.ts +58 -0
  26. package/dist/lib/text.js +414 -0
  27. package/dist/lib/title.d.ts +49 -0
  28. package/dist/lib/title.js +253 -0
  29. package/dist/mixin/attributesParent.d.ts +49 -0
  30. package/dist/mixin/attributesParent.js +80 -0
  31. package/dist/mixin/fixed.d.ts +5 -0
  32. package/dist/mixin/fixed.js +32 -0
  33. package/dist/mixin/flagsParent.d.ts +43 -0
  34. package/dist/mixin/flagsParent.js +64 -0
  35. package/dist/mixin/hidden.d.ts +7 -0
  36. package/dist/mixin/hidden.js +39 -0
  37. package/dist/mixin/magicLinkParent.d.ts +19 -0
  38. package/dist/mixin/magicLinkParent.js +43 -0
  39. package/dist/mixin/singleLine.d.ts +5 -0
  40. package/dist/mixin/singleLine.js +25 -0
  41. package/dist/mixin/sol.d.ts +6 -0
  42. package/dist/mixin/sol.js +45 -0
  43. package/dist/mixin/syntax.d.ts +8 -0
  44. package/dist/mixin/syntax.js +46 -0
  45. package/dist/parser/braces.js +152 -0
  46. package/dist/parser/commentAndExt.js +84 -0
  47. package/dist/parser/converter.js +41 -0
  48. package/dist/parser/externalLinks.js +39 -0
  49. package/dist/parser/hrAndDoubleUnderscore.js +44 -0
  50. package/dist/parser/html.js +40 -0
  51. package/dist/parser/links.js +103 -0
  52. package/dist/parser/list.js +116 -0
  53. package/dist/parser/magicLinks.js +55 -0
  54. package/dist/parser/quotes.js +69 -0
  55. package/dist/parser/redirect.js +28 -0
  56. package/dist/parser/selector.js +393 -0
  57. package/dist/parser/table.js +125 -0
  58. package/dist/src/arg.d.ts +49 -0
  59. package/dist/src/arg.js +220 -0
  60. package/dist/src/atom.d.ts +14 -0
  61. package/dist/src/atom.js +54 -0
  62. package/dist/src/attribute.d.ts +64 -0
  63. package/dist/src/attribute.js +482 -0
  64. package/dist/src/attributes.d.ts +103 -0
  65. package/dist/src/attributes.js +380 -0
  66. package/dist/src/converter.d.ts +28 -0
  67. package/dist/src/converter.js +153 -0
  68. package/dist/src/converterFlags.d.ts +80 -0
  69. package/dist/src/converterFlags.js +241 -0
  70. package/dist/src/converterRule.d.ts +71 -0
  71. package/dist/src/converterRule.js +218 -0
  72. package/dist/src/extLink.d.ts +36 -0
  73. package/dist/src/extLink.js +223 -0
  74. package/dist/src/gallery.d.ts +51 -0
  75. package/dist/src/gallery.js +166 -0
  76. package/dist/src/heading.d.ts +44 -0
  77. package/dist/src/heading.js +222 -0
  78. package/dist/src/hidden.d.ts +9 -0
  79. package/dist/src/hidden.js +82 -0
  80. package/dist/src/html.d.ts +61 -0
  81. package/dist/src/html.js +344 -0
  82. package/dist/src/imageParameter.d.ts +60 -0
  83. package/dist/src/imageParameter.js +262 -0
  84. package/dist/src/imagemap.d.ts +47 -0
  85. package/dist/src/imagemap.js +148 -0
  86. package/dist/src/imagemapLink.d.ts +35 -0
  87. package/dist/src/imagemapLink.js +99 -0
  88. package/dist/src/index.d.ts +136 -0
  89. package/dist/src/index.js +790 -0
  90. package/dist/src/link/base.d.ts +52 -0
  91. package/dist/src/link/base.js +258 -0
  92. package/dist/src/link/category.d.ts +22 -0
  93. package/dist/src/link/category.js +36 -0
  94. package/dist/src/link/file.d.ts +102 -0
  95. package/dist/src/link/file.js +345 -0
  96. package/dist/src/link/galleryImage.d.ts +29 -0
  97. package/dist/src/link/galleryImage.js +133 -0
  98. package/dist/src/link/index.d.ts +39 -0
  99. package/dist/src/link/index.js +100 -0
  100. package/dist/src/link/redirectTarget.d.ts +27 -0
  101. package/dist/src/link/redirectTarget.js +71 -0
  102. package/dist/src/magicLink.d.ts +57 -0
  103. package/dist/src/magicLink.js +261 -0
  104. package/dist/src/nested.d.ts +40 -0
  105. package/dist/src/nested.js +108 -0
  106. package/dist/src/nowiki/base.d.ts +28 -0
  107. package/dist/src/nowiki/base.js +90 -0
  108. package/dist/src/nowiki/comment.d.ts +14 -0
  109. package/dist/src/nowiki/comment.js +123 -0
  110. package/dist/src/nowiki/dd.d.ts +8 -0
  111. package/dist/src/nowiki/dd.js +74 -0
  112. package/dist/src/nowiki/doubleUnderscore.d.ts +15 -0
  113. package/dist/src/nowiki/doubleUnderscore.js +101 -0
  114. package/dist/src/nowiki/hr.d.ts +5 -0
  115. package/dist/src/nowiki/hr.js +72 -0
  116. package/dist/src/nowiki/index.d.ts +14 -0
  117. package/dist/src/nowiki/index.js +30 -0
  118. package/dist/src/nowiki/list.d.ts +5 -0
  119. package/dist/src/nowiki/list.js +67 -0
  120. package/dist/src/nowiki/listBase.d.ts +23 -0
  121. package/dist/src/nowiki/listBase.js +100 -0
  122. package/dist/src/nowiki/noinclude.d.ts +6 -0
  123. package/dist/src/nowiki/noinclude.js +77 -0
  124. package/dist/src/nowiki/quote.d.ts +14 -0
  125. package/dist/src/nowiki/quote.js +149 -0
  126. package/dist/src/onlyinclude.d.ts +13 -0
  127. package/dist/src/onlyinclude.js +60 -0
  128. package/dist/src/paramTag/index.d.ts +28 -0
  129. package/dist/src/paramTag/index.js +80 -0
  130. package/dist/src/paramTag/inputbox.d.ts +8 -0
  131. package/dist/src/paramTag/inputbox.js +24 -0
  132. package/dist/src/parameter.d.ts +60 -0
  133. package/dist/src/parameter.js +267 -0
  134. package/dist/src/pre.d.ts +28 -0
  135. package/dist/src/pre.js +62 -0
  136. package/dist/src/redirect.d.ts +30 -0
  137. package/dist/src/redirect.js +128 -0
  138. package/dist/src/syntax.d.ts +15 -0
  139. package/dist/src/syntax.js +87 -0
  140. package/dist/src/table/base.d.ts +28 -0
  141. package/dist/src/table/base.js +81 -0
  142. package/dist/src/table/index.d.ts +230 -0
  143. package/dist/src/table/index.js +506 -0
  144. package/dist/src/table/td.d.ts +72 -0
  145. package/dist/src/table/td.js +375 -0
  146. package/dist/src/table/tr.d.ts +30 -0
  147. package/dist/src/table/tr.js +61 -0
  148. package/dist/src/table/trBase.d.ts +49 -0
  149. package/dist/src/table/trBase.js +165 -0
  150. package/dist/src/tagPair/ext.d.ts +29 -0
  151. package/dist/src/tagPair/ext.js +229 -0
  152. package/dist/src/tagPair/include.d.ts +33 -0
  153. package/dist/src/tagPair/include.js +132 -0
  154. package/dist/src/tagPair/index.d.ts +23 -0
  155. package/dist/src/tagPair/index.js +130 -0
  156. package/dist/src/transclude.d.ts +159 -0
  157. package/dist/src/transclude.js +598 -0
  158. package/dist/util/constants.js +26 -0
  159. package/dist/util/debug.js +95 -0
  160. package/dist/util/diff.js +83 -0
  161. package/dist/util/html.js +146 -0
  162. package/dist/util/lint.js +32 -0
  163. package/dist/util/string.js +107 -0
  164. package/errors/README +3 -0
  165. package/package.json +22 -29
  166. package/printed/README +3 -0
  167. package/bundle/bundle.min.js +0 -37
  168. package/extensions/dist/base.js +0 -163
  169. package/extensions/dist/codejar.js +0 -53
  170. package/extensions/dist/editor.js +0 -159
  171. package/extensions/dist/highlight.js +0 -30
  172. package/extensions/dist/lint.js +0 -72
  173. package/extensions/editor.css +0 -59
  174. package/extensions/ui.css +0 -162
@@ -0,0 +1,598 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TranscludeToken = void 0;
4
+ const string_1 = require("../util/string");
5
+ const lint_1 = require("../util/lint");
6
+ const debug_1 = require("../util/debug");
7
+ const constants_1 = require("../util/constants");
8
+ const rect_1 = require("../lib/rect");
9
+ const index_1 = require("../index");
10
+ const index_2 = require("./index");
11
+ const parameter_1 = require("./parameter");
12
+ const atom_1 = require("./atom");
13
+ const syntax_1 = require("./syntax");
14
+ const insensitiveVars = new Set([
15
+ 'pageid',
16
+ 'articlepath',
17
+ 'server',
18
+ 'servername',
19
+ 'scriptpath',
20
+ 'stylepath',
21
+ ]);
22
+ /* NOT FOR BROWSER */
23
+ const basicMagicWords = new Map([['=', '='], ['!', '|']]);
24
+ /* NOT FOR BROWSER END */
25
+ /**
26
+ * 模板或魔术字
27
+ * @classdesc `{childNodes: [AtomToken|SyntaxToken, ...AtomToken, ...ParameterToken]}`
28
+ */
29
+ class TranscludeToken extends index_2.Token {
30
+ modifier = '';
31
+ #type = 'template';
32
+ #raw = false;
33
+ #args = new Map();
34
+ #keys = new Set();
35
+ /* NOT FOR BROWSER END */
36
+ get type() {
37
+ return this.#type;
38
+ }
39
+ /* NOT FOR BROWSER */
40
+ /** 是否存在重复参数 */
41
+ get duplication() {
42
+ return this.isTemplate() && Boolean(this.hasDuplicatedArgs());
43
+ }
44
+ set duplication(duplication) {
45
+ if (this.duplication && !duplication) {
46
+ this.fixDuplication();
47
+ }
48
+ }
49
+ /* NOT FOR BROWSER END */
50
+ /**
51
+ * @param title 模板标题或魔术字
52
+ * @param parts 参数各部分
53
+ * @throws `SyntaxError` 非法的模板名称
54
+ */
55
+ constructor(title, parts, config = index_1.default.getConfig(), accum = []) {
56
+ super(undefined, config, accum, {
57
+ AtomToken: 0, SyntaxToken: 0, ParameterToken: '1:',
58
+ });
59
+ const { parserFunction: [insensitive, sensitive] } = config, argSubst = /^(?:\s|\0\d+[cn]\x7F)*\0\d+s\x7F/u.exec(title)?.[0];
60
+ if (argSubst) {
61
+ this.setAttribute('modifier', argSubst);
62
+ title = title.slice(argSubst.length);
63
+ }
64
+ else if (title.includes(':')) {
65
+ const [modifier, ...arg] = title.split(':'), [mt] = /^(?:\s|\0\d+[cn]\x7F)*/u.exec(arg[0] ?? '');
66
+ if (this.setModifier(`${modifier}:${mt}`)) {
67
+ title = arg.join(':').slice(mt.length);
68
+ }
69
+ }
70
+ const isFunction = title.includes(':');
71
+ if (isFunction || parts.length === 0 && !this.#raw) {
72
+ const [magicWord, ...arg] = title.split(':'), cleaned = (0, string_1.removeComment)(magicWord), name = cleaned[arg.length > 0 ? 'trimStart' : 'trim'](), lcName = name.toLowerCase(), canonicalName = Object.prototype.hasOwnProperty.call(insensitive, lcName) && insensitive[lcName], isSensitive = sensitive.includes(name), isVar = isSensitive || insensitiveVars.has(canonicalName);
73
+ if (isVar || isFunction && canonicalName) {
74
+ this.setAttribute('name', canonicalName || lcName);
75
+ this.#type = 'magic-word';
76
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
77
+ /^\s*uc\s*$/iu;
78
+ const pattern = new RegExp(String.raw `^\s*${name}\s*$`, isSensitive ? 'u' : 'iu'), token = new syntax_1.SyntaxToken(magicWord, pattern, 'magic-word-name', config, accum, {
79
+ 'Stage-1': ':', '!ExtToken': '',
80
+ });
81
+ super.insertAt(token);
82
+ if (arg.length > 0) {
83
+ parts.unshift([arg.join(':')]);
84
+ }
85
+ if (this.name === 'invoke') {
86
+ /* NOT FOR BROWSER */
87
+ this.setAttribute('acceptable', { SyntaxToken: 0, AtomToken: '1:3', ParameterToken: '3:' });
88
+ this.protectChildren('1:3');
89
+ /* NOT FOR BROWSER END */
90
+ for (let i = 0; i < 2; i++) {
91
+ const part = parts.shift();
92
+ if (!part) {
93
+ break;
94
+ }
95
+ const invoke = new atom_1.AtomToken(part.join('='), `invoke-${i ? 'function' : 'module'}`, config, accum, { 'Stage-2': ':', '!ExtToken': '', '!HeadingToken': '' });
96
+ super.insertAt(invoke);
97
+ }
98
+ }
99
+ }
100
+ }
101
+ if (this.type === 'template') {
102
+ const name = (0, string_1.removeComment)(title).trim();
103
+ if (!this.normalizeTitle(name, 10, true).valid) {
104
+ accum.pop();
105
+ /* NOT FOR BROWSER */
106
+ index_1.default.debug(`Invalid template name: ${(0, string_1.noWrap)(name)}`);
107
+ /* NOT FOR BROWSER END */
108
+ throw new SyntaxError('Invalid template name');
109
+ }
110
+ const token = new atom_1.AtomToken(title, 'template-name', config, accum, {
111
+ 'Stage-2': ':', '!ExtToken': '', '!HeadingToken': '',
112
+ });
113
+ super.insertAt(token);
114
+ }
115
+ const templateLike = this.isTemplate();
116
+ let i = 1;
117
+ for (const [j, part] of parts.entries()) {
118
+ if (!templateLike && !(this.name === 'switch' && j > 0)) {
119
+ part[0] = part.join('=');
120
+ part.length = 1;
121
+ }
122
+ if (part.length === 1) {
123
+ part.unshift(i);
124
+ i++;
125
+ }
126
+ // @ts-expect-error abstract class
127
+ this.insertAt(new parameter_1.ParameterToken(...part, config, accum));
128
+ }
129
+ this.seal('modifier');
130
+ /* NOT FOR BROWSER */
131
+ this.protectChildren(0);
132
+ }
133
+ /**
134
+ * 设置引用修饰符
135
+ * @param modifier 引用修饰符
136
+ */
137
+ setModifier(modifier) {
138
+ const { parserFunction: [, , raw, subst] } = this.getAttribute('config'), lcModifier = (0, string_1.removeComment)(modifier).trim();
139
+ if (modifier && !lcModifier.endsWith(':')) {
140
+ return false;
141
+ }
142
+ const magicWord = lcModifier.slice(0, -1).toLowerCase(), isRaw = raw.includes(magicWord), isSubst = subst.includes(magicWord);
143
+ if (this.#raw && isRaw
144
+ || !this.#raw && (isSubst || modifier === '')
145
+ || (debug_1.Shadow.running || this.length > 1) && (isRaw || isSubst || modifier === '')) {
146
+ this.setAttribute('modifier', modifier);
147
+ this.#raw = isRaw;
148
+ return Boolean(modifier);
149
+ }
150
+ return false;
151
+ }
152
+ /** 是否是模板或模块 */
153
+ isTemplate() {
154
+ return this.type === 'template' || this.name === 'invoke';
155
+ }
156
+ /** 获取模板或模块名 */
157
+ #getTitle() {
158
+ const isTemplate = this.type === 'template', child = this.childNodes[isTemplate ? 0 : 1];
159
+ return this.normalizeTitle(child.toString(true), isTemplate ? 10 : 828);
160
+ }
161
+ /** @private */
162
+ afterBuild() {
163
+ if (this.modifier.includes('\0')) {
164
+ this.setAttribute('modifier', this.buildFromStr(this.modifier, constants_1.BuildMethod.String));
165
+ }
166
+ super.afterBuild();
167
+ if (this.isTemplate()) {
168
+ const isTemplate = this.type === 'template';
169
+ if (isTemplate) {
170
+ this.setAttribute('name', this.#getTitle().title);
171
+ }
172
+ /* NOT FOR BROWSER */
173
+ /**
174
+ * 当事件bubble到`parameter`时,将`oldKey`和`newKey`保存进AstEventData。
175
+ * 当继续bubble到`template`时,处理并删除`oldKey`和`newKey`。
176
+ * @implements
177
+ */
178
+ const transcludeListener = (e, data) => {
179
+ const { prevTarget } = e, { oldKey, newKey } = data;
180
+ if (typeof oldKey === 'string') {
181
+ delete data.oldKey;
182
+ delete data.newKey;
183
+ }
184
+ if (prevTarget === this.firstChild && isTemplate) {
185
+ this.setAttribute('name', this.#getTitle().title);
186
+ }
187
+ else if (oldKey !== newKey && prevTarget instanceof parameter_1.ParameterToken) {
188
+ const oldArgs = this.getArgs(oldKey, false, false);
189
+ oldArgs.delete(prevTarget);
190
+ this.getArgs(newKey, false, false).add(prevTarget);
191
+ this.#keys.add(newKey);
192
+ if (oldArgs.size === 0) {
193
+ this.#keys.delete(oldKey);
194
+ }
195
+ }
196
+ };
197
+ this.addEventListener(['remove', 'insert', 'replace', 'text'], transcludeListener);
198
+ }
199
+ }
200
+ /** @private */
201
+ toString(skip) {
202
+ return `{{${this.modifier}${this.type === 'magic-word'
203
+ ? `${this.firstChild.toString(skip)}${this.length === 1 ? '' : ':'}${this.childNodes.slice(1).map(child => child.toString(skip)).join('|')}`
204
+ : super.toString(skip, '|')}}}`;
205
+ }
206
+ /** @private */
207
+ text() {
208
+ const { childNodes, length, firstChild, modifier, type, name } = this;
209
+ return type === 'magic-word' && name === 'vardefine'
210
+ ? ''
211
+ : `{{${modifier}${type === 'magic-word'
212
+ ? firstChild.text() + (length === 1 ? '' : ':') + (0, string_1.text)(childNodes.slice(1), '|')
213
+ : super.text('|')}}}`;
214
+ }
215
+ /** @private */
216
+ getAttribute(key) {
217
+ switch (key) {
218
+ case 'padding':
219
+ return this.modifier.length + 2;
220
+ /* NOT FOR BROWSER */
221
+ case 'keys':
222
+ return this.#keys;
223
+ /* NOT FOR BROWSER END */
224
+ default:
225
+ return super.getAttribute(key);
226
+ }
227
+ }
228
+ /** @private */
229
+ getGaps() {
230
+ return 1;
231
+ }
232
+ /** @private */
233
+ lint(start = this.getAbsoluteIndex(), re) {
234
+ const errors = super.lint(start, re);
235
+ if (!this.isTemplate()) {
236
+ return errors;
237
+ }
238
+ const { type, childNodes, length } = this, rect = new rect_1.BoundingRect(this, start), invoke = type === 'magic-word';
239
+ if (invoke && !this.#getTitle().valid) {
240
+ errors.push((0, lint_1.generateForChild)(childNodes[1], rect, 'invalid-invoke', 'illegal module name'));
241
+ }
242
+ else {
243
+ const child = childNodes[invoke ? 1 : 0], textNode = child.childNodes.find((c) => c.type === 'text' && (0, string_1.decodeHtml)(c.data).includes('#'));
244
+ if (textNode) {
245
+ const e = (0, lint_1.generateForChild)(child, rect, 'no-ignored', 'useless fragment');
246
+ e.fix = {
247
+ range: [e.startIndex + textNode.getRelativeIndex() + textNode.data.indexOf('#'), e.endIndex],
248
+ text: '',
249
+ };
250
+ errors.push(e);
251
+ }
252
+ }
253
+ if (invoke && length === 2) {
254
+ errors.push((0, lint_1.generateForSelf)(this, rect, 'invalid-invoke', 'missing module function'));
255
+ return errors;
256
+ }
257
+ const duplicatedArgs = this.getDuplicatedArgs().filter(([, parameter]) => !parameter[0].querySelector('ext'));
258
+ if (duplicatedArgs.length > 0) {
259
+ errors.push(...duplicatedArgs.flatMap(([, args]) => args).map(arg => (0, lint_1.generateForChild)(arg, rect, 'no-duplicate', 'duplicated parameter')));
260
+ }
261
+ return errors;
262
+ }
263
+ /**
264
+ * 处理匿名参数更改
265
+ * @param addedToken 新增的参数
266
+ */
267
+ #handleAnonArgChange(addedToken) {
268
+ const args = this.getAnonArgs(), added = typeof addedToken !== 'number';
269
+ /* NOT FOR BROWSER */
270
+ const maxAnon = String(args.length + (added ? 0 : 1));
271
+ if (added) {
272
+ this.#keys.add(maxAnon);
273
+ }
274
+ else if (!this.hasArg(maxAnon, true)) {
275
+ this.#keys.delete(maxAnon);
276
+ }
277
+ /* NOT FOR BROWSER END */
278
+ for (let i = added ? args.indexOf(addedToken) : addedToken - 1; i < args.length; i++) {
279
+ const token = args[i], { name } = token, newName = String(i + 1);
280
+ if (name !== newName) {
281
+ token.setAttribute('name', newName);
282
+ this.getArgs(newName, false, false).add(token);
283
+ /* NOT FOR BROWSER */
284
+ if (name) {
285
+ this.getArgs(name, false, false).delete(token);
286
+ }
287
+ }
288
+ }
289
+ }
290
+ /**
291
+ * @override
292
+ * @param token 待插入的子节点
293
+ * @param i 插入位置
294
+ */
295
+ insertAt(token, i = this.length) {
296
+ super.insertAt(token, i);
297
+ if (token.anon) {
298
+ this.#handleAnonArgChange(token);
299
+ }
300
+ else if (token.name) {
301
+ this.getArgs(token.name, false, false).add(token);
302
+ /* NOT FOR BROWSER */
303
+ this.#keys.add(token.name);
304
+ }
305
+ return token;
306
+ }
307
+ /** 获取所有参数 */
308
+ getAllArgs() {
309
+ return this.childNodes.filter((0, debug_1.isToken)('parameter'));
310
+ }
311
+ /** 获取所有匿名参数 */
312
+ getAnonArgs() {
313
+ return this.getAllArgs().filter(({ anon }) => anon);
314
+ }
315
+ /**
316
+ * 获取指定参数
317
+ * @param key 参数名
318
+ * @param exact 是否匹配匿名性
319
+ * @param copy 是否返回一个备份
320
+ */
321
+ getArgs(key, exact, copy = true) {
322
+ const keyStr = String(key).replace(/^[ \t\n\0\v]+|([^ \t\n\0\v])[ \t\n\0\v]+$/gu, '$1');
323
+ let args;
324
+ if (this.#args.has(keyStr)) {
325
+ args = this.#args.get(keyStr);
326
+ }
327
+ else {
328
+ args = new Set(this.getAllArgs().filter(({ name }) => keyStr === name));
329
+ this.#args.set(keyStr, args);
330
+ }
331
+ /* NOT FOR BROWSER */
332
+ if (exact && keyStr.trim() && !isNaN(keyStr)) {
333
+ args = new Set([...args].filter(({ anon }) => typeof key === 'number' === anon));
334
+ }
335
+ else if (copy) {
336
+ args = new Set(args);
337
+ }
338
+ /* NOT FOR BROWSER END */
339
+ return args;
340
+ }
341
+ /**
342
+ * 获取重名参数
343
+ * @throws `Error` 仅用于模板
344
+ */
345
+ getDuplicatedArgs() {
346
+ if (this.isTemplate()) {
347
+ return [...this.#args].filter(([, { size }]) => size > 1).map(([key, args]) => [key, [...args]]);
348
+ }
349
+ throw new Error('TranscludeToken.getDuplicatedArgs method is only for template!');
350
+ }
351
+ /**
352
+ * 对特定魔术字获取可能的取值
353
+ * @throws `Error` 不是可接受的魔术字
354
+ */
355
+ getPossibleValues() {
356
+ const { type, name, childNodes } = this;
357
+ if (type === 'template') {
358
+ throw new Error(`TranscludeToken.getPossibleValues method is only for specific magic words!`);
359
+ }
360
+ let start;
361
+ switch (name) {
362
+ case 'if':
363
+ case 'ifexist':
364
+ case 'ifexpr':
365
+ case 'iferror':
366
+ start = 2;
367
+ break;
368
+ case 'ifeq':
369
+ start = 3;
370
+ break;
371
+ default:
372
+ throw new Error(`TranscludeToken.getPossibleValues method is only for specific magic words!`);
373
+ }
374
+ const queue = childNodes.slice(start, start + 2).map(({ childNodes: [, value] }) => value);
375
+ for (let i = 0; i < queue.length;) {
376
+ const { length, 0: first } = queue[i].childNodes.filter(child => child.text().trim());
377
+ if (length === 0) {
378
+ queue.splice(i, 1);
379
+ }
380
+ else if (length > 1 || first.type !== 'magic-word') {
381
+ i++;
382
+ }
383
+ else {
384
+ try {
385
+ const possibleValues = first.getPossibleValues();
386
+ queue.splice(i, 1, ...possibleValues);
387
+ i += possibleValues.length;
388
+ }
389
+ catch {
390
+ i++;
391
+ }
392
+ }
393
+ }
394
+ return queue;
395
+ }
396
+ /** @private */
397
+ print() {
398
+ const { childNodes, length, firstChild, modifier, type } = this;
399
+ return `<span class="wpb-${type}">{{${(0, string_1.escape)(modifier)}${type === 'magic-word'
400
+ ? firstChild.print() + (length === 1 ? '' : ':') + (0, string_1.print)(childNodes.slice(1), { sep: '|' })
401
+ : (0, string_1.print)(childNodes, { sep: '|' })}}}</span>`;
402
+ }
403
+ /* NOT FOR BROWSER */
404
+ cloneNode() {
405
+ const [first, ...cloned] = this.cloneChildNodes(), config = this.getAttribute('config');
406
+ return debug_1.Shadow.run(() => {
407
+ // @ts-expect-error abstract class
408
+ const token = new TranscludeToken(this.type === 'template' ? 'T' : first.text(), [], config);
409
+ if (this.#raw) {
410
+ token.setModifier(this.modifier);
411
+ }
412
+ else {
413
+ token.setAttribute('modifier', this.modifier);
414
+ }
415
+ token.firstChild.safeReplaceWith(first);
416
+ token.append(...cloned);
417
+ return token;
418
+ });
419
+ }
420
+ /** 替换引用 */
421
+ subst() {
422
+ this.setModifier('subst:');
423
+ }
424
+ /** 安全的替换引用 */
425
+ safesubst() {
426
+ this.setModifier('safesubst:');
427
+ }
428
+ /**
429
+ * @override
430
+ * @param i 移除位置
431
+ */
432
+ removeAt(i) {
433
+ const token = super.removeAt(i);
434
+ if (token.anon) {
435
+ this.#handleAnonArgChange(Number(token.name));
436
+ }
437
+ else {
438
+ const args = this.getArgs(token.name, false, false);
439
+ args.delete(token);
440
+ if (args.size === 0) {
441
+ this.#keys.delete(token.name);
442
+ }
443
+ }
444
+ return token;
445
+ }
446
+ /**
447
+ * 是否具有某参数
448
+ * @param key 参数名
449
+ * @param exact 是否匹配匿名性
450
+ */
451
+ hasArg(key, exact) {
452
+ return this.getArgs(key, exact, false).size > 0;
453
+ }
454
+ /**
455
+ * 获取生效的指定参数
456
+ * @param key 参数名
457
+ * @param exact 是否匹配匿名性
458
+ */
459
+ getArg(key, exact) {
460
+ const args = [...this.getArgs(key, exact, false)].sort((a, b) => a.compareDocumentPosition(b));
461
+ return args.at(-1);
462
+ }
463
+ /**
464
+ * 移除指定参数
465
+ * @param key 参数名
466
+ * @param exact 是否匹配匿名性
467
+ */
468
+ removeArg(key, exact) {
469
+ debug_1.Shadow.run(() => {
470
+ for (const token of this.getArgs(key, exact, false)) {
471
+ this.removeChild(token);
472
+ }
473
+ });
474
+ }
475
+ /** 获取所有参数名 */
476
+ getKeys() {
477
+ const args = this.getAllArgs();
478
+ if (this.#keys.size === 0 && args.length > 0) {
479
+ for (const { name } of args) {
480
+ this.#keys.add(name);
481
+ }
482
+ }
483
+ return [...this.#keys];
484
+ }
485
+ /**
486
+ * 获取参数值
487
+ * @param key 参数名
488
+ */
489
+ getValues(key) {
490
+ return [...this.getArgs(key, false, false)].map(token => token.getValue());
491
+ }
492
+ getValue(key) {
493
+ return key === undefined
494
+ ? Object.fromEntries(this.getKeys().map(k => [k, this.getValue(k)]))
495
+ : this.getArg(key)?.getValue();
496
+ }
497
+ /**
498
+ * 插入匿名参数
499
+ * @param val 参数值
500
+ */
501
+ newAnonArg(val) {
502
+ require('../addon/transclude');
503
+ return this.newAnonArg(val);
504
+ }
505
+ /**
506
+ * 设置参数值
507
+ * @param key 参数名
508
+ * @param value 参数值
509
+ * @throws `Error` 仅用于模板
510
+ */
511
+ setValue(key, value) {
512
+ require('../addon/transclude');
513
+ this.setValue(key, value);
514
+ }
515
+ /**
516
+ * 将匿名参数改写为命名参数
517
+ * @throws `Error` 仅用于模板
518
+ */
519
+ anonToNamed() {
520
+ if (!this.isTemplate()) {
521
+ throw new Error('TranscludeToken.anonToNamed method is only for template!');
522
+ }
523
+ for (const token of this.getAnonArgs()) {
524
+ token.firstChild.replaceChildren(token.name);
525
+ }
526
+ }
527
+ /**
528
+ * 替换模板名
529
+ * @param title 模板名
530
+ * @throws `Error` 仅用于模板
531
+ */
532
+ replaceTemplate(title) {
533
+ require('../addon/transclude');
534
+ this.replaceTemplate(title);
535
+ }
536
+ /**
537
+ * 替换模块名
538
+ * @param title 模块名
539
+ * @throws `Error` 仅用于模块
540
+ */
541
+ replaceModule(title) {
542
+ require('../addon/transclude');
543
+ this.replaceModule(title);
544
+ }
545
+ /**
546
+ * 替换模块函数
547
+ * @param func 模块函数名
548
+ * @throws `Error` 仅用于模块
549
+ * @throws `Error` 尚未指定模块名称
550
+ */
551
+ replaceFunction(func) {
552
+ require('../addon/transclude');
553
+ this.replaceFunction(func);
554
+ }
555
+ /**
556
+ * 重复参数计数
557
+ * @throws `Error` 仅用于模板
558
+ */
559
+ hasDuplicatedArgs() {
560
+ if (this.isTemplate()) {
561
+ return this.getAllArgs().length - this.getKeys().length;
562
+ }
563
+ throw new Error('TranscludeToken.hasDuplicatedArgs method is only for template!');
564
+ }
565
+ /**
566
+ * 修复重名参数:
567
+ * `aggressive = false`时只移除空参数和全同参数,优先保留匿名参数,否则将所有匿名参数更改为命名。
568
+ * `aggressive = true`时还会尝试处理连续的以数字编号的参数。
569
+ * @param aggressive 是否使用有更大风险的修复手段
570
+ */
571
+ fixDuplication(aggressive) {
572
+ require('../addon/transclude');
573
+ return this.fixDuplication(aggressive);
574
+ }
575
+ /**
576
+ * 转义模板内的表格
577
+ * @throws `Error` 转义失败
578
+ */
579
+ escapeTables() {
580
+ require('../addon/transclude');
581
+ return this.escapeTables();
582
+ }
583
+ /** @private */
584
+ toHtmlInternal(nowrap) {
585
+ const { type, name } = this;
586
+ if (type === 'template' && !name.startsWith('Special:')) {
587
+ if (this.normalizeTitle(name, 0, true).valid) {
588
+ const title = name.replaceAll('_', ' ');
589
+ return `<a href="${this.#getTitle().getUrl()}?action=edit&redlink=1" class="new" title="${title} (page does not exist)">${title}</a>`;
590
+ }
591
+ const str = this.toString(true);
592
+ return nowrap ? str.replaceAll('\n', ' ') : str;
593
+ }
594
+ return basicMagicWords.has(name) ? basicMagicWords.get(name) : '';
595
+ }
596
+ }
597
+ exports.TranscludeToken = TranscludeToken;
598
+ constants_1.classes['TranscludeToken'] = __filename;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.states = exports.aliases = exports.parsers = exports.mixins = exports.classes = exports.BuildMethod = exports.MAX_STAGE = void 0;
4
+ exports.MAX_STAGE = 11;
5
+ var BuildMethod;
6
+ (function (BuildMethod) {
7
+ BuildMethod[BuildMethod["String"] = 0] = "String";
8
+ BuildMethod[BuildMethod["Text"] = 1] = "Text";
9
+ })(BuildMethod || (exports.BuildMethod = BuildMethod = {}));
10
+ /* NOT FOR BROWSER */
11
+ exports.classes = {}, exports.mixins = exports.classes, exports.parsers = exports.classes;
12
+ exports.aliases = [
13
+ ['AstText'],
14
+ ['CommentToken', 'ExtToken', 'IncludeToken', 'NoincludeToken'],
15
+ ['ArgToken', 'TranscludeToken', 'HeadingToken'],
16
+ ['HtmlToken'],
17
+ ['TableToken'],
18
+ ['HrToken', 'DoubleUnderscoreToken'],
19
+ ['LinkToken', 'FileToken', 'CategoryToken'],
20
+ ['QuoteToken'],
21
+ ['ExtLinkToken'],
22
+ ['MagicLinkToken'],
23
+ ['ListToken', 'DdToken'],
24
+ ['ConverterToken'],
25
+ ];
26
+ exports.states = new WeakMap();