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