wikiparser-node 1.13.0 → 1.13.1-b

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 (176) hide show
  1. package/bundle/bundle.min.js +37 -0
  2. package/config/default.json +32 -41
  3. package/config/enwiki.json +17 -839
  4. package/config/llwiki.json +21 -56
  5. package/config/moegirl.json +21 -65
  6. package/config/zhwiki.json +32 -498
  7. package/extensions/dist/base.js +163 -0
  8. package/extensions/dist/codejar.js +53 -0
  9. package/extensions/dist/editor.js +159 -0
  10. package/extensions/dist/highlight.js +30 -0
  11. package/extensions/dist/lint.js +72 -0
  12. package/extensions/editor.css +59 -0
  13. package/extensions/ui.css +162 -0
  14. package/i18n/zh-hans.json +1 -0
  15. package/i18n/zh-hant.json +1 -0
  16. package/package.json +29 -22
  17. package/config/.schema.json +0 -203
  18. package/dist/addon/table.js +0 -494
  19. package/dist/addon/token.js +0 -392
  20. package/dist/addon/transclude.js +0 -184
  21. package/dist/base.d.ts +0 -109
  22. package/dist/base.js +0 -67
  23. package/dist/index.d.ts +0 -33
  24. package/dist/index.js +0 -279
  25. package/dist/internal.d.ts +0 -47
  26. package/dist/lib/element.d.ts +0 -125
  27. package/dist/lib/element.js +0 -364
  28. package/dist/lib/node.d.ts +0 -173
  29. package/dist/lib/node.js +0 -478
  30. package/dist/lib/range.d.ts +0 -105
  31. package/dist/lib/range.js +0 -406
  32. package/dist/lib/ranges.d.ts +0 -28
  33. package/dist/lib/ranges.js +0 -126
  34. package/dist/lib/rect.d.ts +0 -18
  35. package/dist/lib/rect.js +0 -36
  36. package/dist/lib/text.d.ts +0 -58
  37. package/dist/lib/text.js +0 -414
  38. package/dist/lib/title.d.ts +0 -49
  39. package/dist/lib/title.js +0 -251
  40. package/dist/mixin/attributesParent.d.ts +0 -49
  41. package/dist/mixin/attributesParent.js +0 -80
  42. package/dist/mixin/fixed.d.ts +0 -5
  43. package/dist/mixin/fixed.js +0 -32
  44. package/dist/mixin/flagsParent.d.ts +0 -43
  45. package/dist/mixin/flagsParent.js +0 -64
  46. package/dist/mixin/hidden.d.ts +0 -7
  47. package/dist/mixin/hidden.js +0 -39
  48. package/dist/mixin/magicLinkParent.d.ts +0 -19
  49. package/dist/mixin/magicLinkParent.js +0 -43
  50. package/dist/mixin/singleLine.d.ts +0 -5
  51. package/dist/mixin/singleLine.js +0 -25
  52. package/dist/mixin/sol.d.ts +0 -6
  53. package/dist/mixin/sol.js +0 -45
  54. package/dist/mixin/syntax.d.ts +0 -8
  55. package/dist/mixin/syntax.js +0 -46
  56. package/dist/parser/braces.js +0 -152
  57. package/dist/parser/commentAndExt.js +0 -84
  58. package/dist/parser/converter.js +0 -41
  59. package/dist/parser/externalLinks.js +0 -39
  60. package/dist/parser/hrAndDoubleUnderscore.js +0 -44
  61. package/dist/parser/html.js +0 -40
  62. package/dist/parser/links.js +0 -103
  63. package/dist/parser/list.js +0 -116
  64. package/dist/parser/magicLinks.js +0 -55
  65. package/dist/parser/quotes.js +0 -69
  66. package/dist/parser/redirect.js +0 -28
  67. package/dist/parser/selector.js +0 -443
  68. package/dist/parser/table.js +0 -125
  69. package/dist/src/arg.d.ts +0 -49
  70. package/dist/src/arg.js +0 -220
  71. package/dist/src/atom.d.ts +0 -14
  72. package/dist/src/atom.js +0 -54
  73. package/dist/src/attribute.d.ts +0 -64
  74. package/dist/src/attribute.js +0 -482
  75. package/dist/src/attributes.d.ts +0 -103
  76. package/dist/src/attributes.js +0 -383
  77. package/dist/src/converter.d.ts +0 -28
  78. package/dist/src/converter.js +0 -153
  79. package/dist/src/converterFlags.d.ts +0 -80
  80. package/dist/src/converterFlags.js +0 -241
  81. package/dist/src/converterRule.d.ts +0 -71
  82. package/dist/src/converterRule.js +0 -218
  83. package/dist/src/extLink.d.ts +0 -36
  84. package/dist/src/extLink.js +0 -223
  85. package/dist/src/gallery.d.ts +0 -51
  86. package/dist/src/gallery.js +0 -166
  87. package/dist/src/heading.d.ts +0 -44
  88. package/dist/src/heading.js +0 -222
  89. package/dist/src/hidden.d.ts +0 -9
  90. package/dist/src/hidden.js +0 -82
  91. package/dist/src/html.d.ts +0 -61
  92. package/dist/src/html.js +0 -344
  93. package/dist/src/imageParameter.d.ts +0 -60
  94. package/dist/src/imageParameter.js +0 -262
  95. package/dist/src/imagemap.d.ts +0 -47
  96. package/dist/src/imagemap.js +0 -148
  97. package/dist/src/imagemapLink.d.ts +0 -35
  98. package/dist/src/imagemapLink.js +0 -99
  99. package/dist/src/index.d.ts +0 -136
  100. package/dist/src/index.js +0 -790
  101. package/dist/src/link/base.d.ts +0 -52
  102. package/dist/src/link/base.js +0 -258
  103. package/dist/src/link/category.d.ts +0 -22
  104. package/dist/src/link/category.js +0 -36
  105. package/dist/src/link/file.d.ts +0 -102
  106. package/dist/src/link/file.js +0 -345
  107. package/dist/src/link/galleryImage.d.ts +0 -29
  108. package/dist/src/link/galleryImage.js +0 -133
  109. package/dist/src/link/index.d.ts +0 -39
  110. package/dist/src/link/index.js +0 -100
  111. package/dist/src/link/redirectTarget.d.ts +0 -27
  112. package/dist/src/link/redirectTarget.js +0 -71
  113. package/dist/src/magicLink.d.ts +0 -57
  114. package/dist/src/magicLink.js +0 -261
  115. package/dist/src/nested.d.ts +0 -40
  116. package/dist/src/nested.js +0 -108
  117. package/dist/src/nowiki/base.d.ts +0 -28
  118. package/dist/src/nowiki/base.js +0 -90
  119. package/dist/src/nowiki/comment.d.ts +0 -14
  120. package/dist/src/nowiki/comment.js +0 -123
  121. package/dist/src/nowiki/dd.d.ts +0 -8
  122. package/dist/src/nowiki/dd.js +0 -74
  123. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -15
  124. package/dist/src/nowiki/doubleUnderscore.js +0 -101
  125. package/dist/src/nowiki/hr.d.ts +0 -5
  126. package/dist/src/nowiki/hr.js +0 -72
  127. package/dist/src/nowiki/index.d.ts +0 -14
  128. package/dist/src/nowiki/index.js +0 -30
  129. package/dist/src/nowiki/list.d.ts +0 -5
  130. package/dist/src/nowiki/list.js +0 -67
  131. package/dist/src/nowiki/listBase.d.ts +0 -23
  132. package/dist/src/nowiki/listBase.js +0 -100
  133. package/dist/src/nowiki/noinclude.d.ts +0 -6
  134. package/dist/src/nowiki/noinclude.js +0 -77
  135. package/dist/src/nowiki/quote.d.ts +0 -14
  136. package/dist/src/nowiki/quote.js +0 -149
  137. package/dist/src/onlyinclude.d.ts +0 -13
  138. package/dist/src/onlyinclude.js +0 -60
  139. package/dist/src/paramTag/index.d.ts +0 -28
  140. package/dist/src/paramTag/index.js +0 -80
  141. package/dist/src/paramTag/inputbox.d.ts +0 -8
  142. package/dist/src/paramTag/inputbox.js +0 -24
  143. package/dist/src/parameter.d.ts +0 -60
  144. package/dist/src/parameter.js +0 -267
  145. package/dist/src/pre.d.ts +0 -28
  146. package/dist/src/pre.js +0 -62
  147. package/dist/src/redirect.d.ts +0 -30
  148. package/dist/src/redirect.js +0 -128
  149. package/dist/src/syntax.d.ts +0 -15
  150. package/dist/src/syntax.js +0 -87
  151. package/dist/src/table/base.d.ts +0 -28
  152. package/dist/src/table/base.js +0 -81
  153. package/dist/src/table/index.d.ts +0 -230
  154. package/dist/src/table/index.js +0 -506
  155. package/dist/src/table/td.d.ts +0 -72
  156. package/dist/src/table/td.js +0 -375
  157. package/dist/src/table/tr.d.ts +0 -30
  158. package/dist/src/table/tr.js +0 -61
  159. package/dist/src/table/trBase.d.ts +0 -49
  160. package/dist/src/table/trBase.js +0 -165
  161. package/dist/src/tagPair/ext.d.ts +0 -29
  162. package/dist/src/tagPair/ext.js +0 -229
  163. package/dist/src/tagPair/include.d.ts +0 -33
  164. package/dist/src/tagPair/include.js +0 -132
  165. package/dist/src/tagPair/index.d.ts +0 -23
  166. package/dist/src/tagPair/index.js +0 -130
  167. package/dist/src/transclude.d.ts +0 -159
  168. package/dist/src/transclude.js +0 -598
  169. package/dist/util/constants.js +0 -26
  170. package/dist/util/debug.js +0 -95
  171. package/dist/util/diff.js +0 -83
  172. package/dist/util/html.js +0 -146
  173. package/dist/util/lint.js +0 -32
  174. package/dist/util/string.js +0 -107
  175. package/errors/README +0 -3
  176. package/printed/README +0 -3
@@ -1,598 +0,0 @@
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;
@@ -1,26 +0,0 @@
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();