wikiparser-node 1.12.2 → 1.12.3-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 (174) hide show
  1. package/bundle/bundle.min.js +37 -0
  2. package/config/default.json +29 -30
  3. package/config/enwiki.json +15 -829
  4. package/config/llwiki.json +21 -56
  5. package/config/moegirl.json +21 -65
  6. package/config/zhwiki.json +28 -494
  7. package/extensions/dist/base.js +163 -0
  8. package/extensions/dist/codejar.js +52 -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/package.json +28 -21
  15. package/config/.schema.json +0 -203
  16. package/dist/addon/table.js +0 -486
  17. package/dist/addon/token.js +0 -391
  18. package/dist/addon/transclude.js +0 -184
  19. package/dist/base.d.ts +0 -81
  20. package/dist/base.js +0 -40
  21. package/dist/index.d.ts +0 -33
  22. package/dist/index.js +0 -275
  23. package/dist/internal.d.ts +0 -47
  24. package/dist/lib/element.d.ts +0 -125
  25. package/dist/lib/element.js +0 -376
  26. package/dist/lib/node.d.ts +0 -173
  27. package/dist/lib/node.js +0 -478
  28. package/dist/lib/range.d.ts +0 -105
  29. package/dist/lib/range.js +0 -406
  30. package/dist/lib/ranges.d.ts +0 -28
  31. package/dist/lib/ranges.js +0 -126
  32. package/dist/lib/rect.d.ts +0 -18
  33. package/dist/lib/rect.js +0 -36
  34. package/dist/lib/text.d.ts +0 -58
  35. package/dist/lib/text.js +0 -414
  36. package/dist/lib/title.d.ts +0 -49
  37. package/dist/lib/title.js +0 -253
  38. package/dist/mixin/attributesParent.d.ts +0 -49
  39. package/dist/mixin/attributesParent.js +0 -80
  40. package/dist/mixin/fixed.d.ts +0 -5
  41. package/dist/mixin/fixed.js +0 -32
  42. package/dist/mixin/flagsParent.d.ts +0 -43
  43. package/dist/mixin/flagsParent.js +0 -64
  44. package/dist/mixin/hidden.d.ts +0 -7
  45. package/dist/mixin/hidden.js +0 -39
  46. package/dist/mixin/magicLinkParent.d.ts +0 -19
  47. package/dist/mixin/magicLinkParent.js +0 -43
  48. package/dist/mixin/singleLine.d.ts +0 -5
  49. package/dist/mixin/singleLine.js +0 -25
  50. package/dist/mixin/sol.d.ts +0 -6
  51. package/dist/mixin/sol.js +0 -45
  52. package/dist/mixin/syntax.d.ts +0 -8
  53. package/dist/mixin/syntax.js +0 -46
  54. package/dist/parser/braces.js +0 -152
  55. package/dist/parser/commentAndExt.js +0 -84
  56. package/dist/parser/converter.js +0 -41
  57. package/dist/parser/externalLinks.js +0 -39
  58. package/dist/parser/hrAndDoubleUnderscore.js +0 -44
  59. package/dist/parser/html.js +0 -40
  60. package/dist/parser/links.js +0 -103
  61. package/dist/parser/list.js +0 -116
  62. package/dist/parser/magicLinks.js +0 -54
  63. package/dist/parser/quotes.js +0 -69
  64. package/dist/parser/redirect.js +0 -28
  65. package/dist/parser/selector.js +0 -393
  66. package/dist/parser/table.js +0 -125
  67. package/dist/src/arg.d.ts +0 -51
  68. package/dist/src/arg.js +0 -225
  69. package/dist/src/atom.d.ts +0 -14
  70. package/dist/src/atom.js +0 -54
  71. package/dist/src/attribute.d.ts +0 -64
  72. package/dist/src/attribute.js +0 -478
  73. package/dist/src/attributes.d.ts +0 -103
  74. package/dist/src/attributes.js +0 -380
  75. package/dist/src/converter.d.ts +0 -28
  76. package/dist/src/converter.js +0 -150
  77. package/dist/src/converterFlags.d.ts +0 -80
  78. package/dist/src/converterFlags.js +0 -241
  79. package/dist/src/converterRule.d.ts +0 -71
  80. package/dist/src/converterRule.js +0 -218
  81. package/dist/src/extLink.d.ts +0 -36
  82. package/dist/src/extLink.js +0 -223
  83. package/dist/src/gallery.d.ts +0 -47
  84. package/dist/src/gallery.js +0 -145
  85. package/dist/src/heading.d.ts +0 -42
  86. package/dist/src/heading.js +0 -209
  87. package/dist/src/hidden.d.ts +0 -9
  88. package/dist/src/hidden.js +0 -82
  89. package/dist/src/html.d.ts +0 -61
  90. package/dist/src/html.js +0 -344
  91. package/dist/src/imageParameter.d.ts +0 -60
  92. package/dist/src/imageParameter.js +0 -262
  93. package/dist/src/imagemap.d.ts +0 -47
  94. package/dist/src/imagemap.js +0 -148
  95. package/dist/src/imagemapLink.d.ts +0 -35
  96. package/dist/src/imagemapLink.js +0 -99
  97. package/dist/src/index.d.ts +0 -136
  98. package/dist/src/index.js +0 -779
  99. package/dist/src/link/base.d.ts +0 -52
  100. package/dist/src/link/base.js +0 -258
  101. package/dist/src/link/category.d.ts +0 -22
  102. package/dist/src/link/category.js +0 -36
  103. package/dist/src/link/file.d.ts +0 -102
  104. package/dist/src/link/file.js +0 -335
  105. package/dist/src/link/galleryImage.d.ts +0 -29
  106. package/dist/src/link/galleryImage.js +0 -133
  107. package/dist/src/link/index.d.ts +0 -39
  108. package/dist/src/link/index.js +0 -100
  109. package/dist/src/link/redirectTarget.d.ts +0 -27
  110. package/dist/src/link/redirectTarget.js +0 -71
  111. package/dist/src/magicLink.d.ts +0 -57
  112. package/dist/src/magicLink.js +0 -261
  113. package/dist/src/nested.d.ts +0 -40
  114. package/dist/src/nested.js +0 -108
  115. package/dist/src/nowiki/base.d.ts +0 -28
  116. package/dist/src/nowiki/base.js +0 -90
  117. package/dist/src/nowiki/comment.d.ts +0 -14
  118. package/dist/src/nowiki/comment.js +0 -123
  119. package/dist/src/nowiki/dd.d.ts +0 -8
  120. package/dist/src/nowiki/dd.js +0 -74
  121. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -15
  122. package/dist/src/nowiki/doubleUnderscore.js +0 -101
  123. package/dist/src/nowiki/hr.d.ts +0 -5
  124. package/dist/src/nowiki/hr.js +0 -72
  125. package/dist/src/nowiki/index.d.ts +0 -14
  126. package/dist/src/nowiki/index.js +0 -30
  127. package/dist/src/nowiki/list.d.ts +0 -5
  128. package/dist/src/nowiki/list.js +0 -67
  129. package/dist/src/nowiki/listBase.d.ts +0 -23
  130. package/dist/src/nowiki/listBase.js +0 -100
  131. package/dist/src/nowiki/noinclude.d.ts +0 -6
  132. package/dist/src/nowiki/noinclude.js +0 -77
  133. package/dist/src/nowiki/quote.d.ts +0 -14
  134. package/dist/src/nowiki/quote.js +0 -149
  135. package/dist/src/onlyinclude.d.ts +0 -13
  136. package/dist/src/onlyinclude.js +0 -60
  137. package/dist/src/paramTag/index.d.ts +0 -28
  138. package/dist/src/paramTag/index.js +0 -80
  139. package/dist/src/paramTag/inputbox.d.ts +0 -8
  140. package/dist/src/paramTag/inputbox.js +0 -24
  141. package/dist/src/parameter.d.ts +0 -60
  142. package/dist/src/parameter.js +0 -267
  143. package/dist/src/pre.d.ts +0 -28
  144. package/dist/src/pre.js +0 -62
  145. package/dist/src/redirect.d.ts +0 -30
  146. package/dist/src/redirect.js +0 -128
  147. package/dist/src/syntax.d.ts +0 -15
  148. package/dist/src/syntax.js +0 -87
  149. package/dist/src/table/base.d.ts +0 -28
  150. package/dist/src/table/base.js +0 -81
  151. package/dist/src/table/index.d.ts +0 -230
  152. package/dist/src/table/index.js +0 -506
  153. package/dist/src/table/td.d.ts +0 -72
  154. package/dist/src/table/td.js +0 -375
  155. package/dist/src/table/tr.d.ts +0 -30
  156. package/dist/src/table/tr.js +0 -61
  157. package/dist/src/table/trBase.d.ts +0 -49
  158. package/dist/src/table/trBase.js +0 -165
  159. package/dist/src/tagPair/ext.d.ts +0 -29
  160. package/dist/src/tagPair/ext.js +0 -217
  161. package/dist/src/tagPair/include.d.ts +0 -33
  162. package/dist/src/tagPair/include.js +0 -132
  163. package/dist/src/tagPair/index.d.ts +0 -23
  164. package/dist/src/tagPair/index.js +0 -130
  165. package/dist/src/transclude.d.ts +0 -159
  166. package/dist/src/transclude.js +0 -598
  167. package/dist/util/constants.js +0 -26
  168. package/dist/util/debug.js +0 -95
  169. package/dist/util/diff.js +0 -83
  170. package/dist/util/html.js +0 -145
  171. package/dist/util/lint.js +0 -32
  172. package/dist/util/string.js +0 -107
  173. package/errors/README +0 -3
  174. package/printed/README +0 -3
@@ -1,375 +0,0 @@
1
- "use strict";
2
- var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
- function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
- var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
- var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
- var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
- var _, done = false;
8
- for (var i = decorators.length - 1; i >= 0; i--) {
9
- var context = {};
10
- for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
- for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
- context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
- var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
- if (kind === "accessor") {
15
- if (result === void 0) continue;
16
- if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
- if (_ = accept(result.get)) descriptor.get = _;
18
- if (_ = accept(result.set)) descriptor.set = _;
19
- if (_ = accept(result.init)) initializers.unshift(_);
20
- }
21
- else if (_ = accept(result)) {
22
- if (kind === "field") initializers.unshift(_);
23
- else descriptor[key] = _;
24
- }
25
- }
26
- if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
- done = true;
28
- };
29
- var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
- var useValue = arguments.length > 2;
31
- for (var i = 0; i < initializers.length; i++) {
32
- value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
- }
34
- return useValue ? value : void 0;
35
- };
36
- Object.defineProperty(exports, "__esModule", { value: true });
37
- exports.createTd = exports.TdToken = void 0;
38
- const lint_1 = require("../../util/lint");
39
- const constants_1 = require("../../util/constants");
40
- const debug_1 = require("../../util/debug");
41
- const rect_1 = require("../../lib/rect");
42
- const index_1 = require("../../index");
43
- const index_2 = require("../index");
44
- const base_1 = require("./base");
45
- /* NOT FOR BROWSER */
46
- const string_1 = require("../../util/string");
47
- const fixed_1 = require("../../mixin/fixed");
48
- /* NOT FOR BROWSER END */
49
- /**
50
- * `<td>`、`<th>`和`<caption>`
51
- * @classdesc `{childNodes: [SyntaxToken, AttributesToken, Token]}`
52
- */
53
- let TdToken = (() => {
54
- var _a;
55
- let _classDecorators = [fixed_1.fixedToken];
56
- let _classDescriptor;
57
- let _classExtraInitializers = [];
58
- let _classThis;
59
- let _classSuper = base_1.TableBaseToken;
60
- var TdToken = class extends _classSuper {
61
- static { _classThis = this; }
62
- static {
63
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
64
- __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
65
- TdToken = _classThis = _classDescriptor.value;
66
- if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
67
- __runInitializers(_classThis, _classExtraInitializers);
68
- }
69
- #innerSyntax = '';
70
- #syntax;
71
- /* NOT FOR BROWSER END */
72
- get type() {
73
- return 'td';
74
- }
75
- /** rowspan */
76
- get rowspan() {
77
- return this.getAttr('rowspan');
78
- }
79
- /** colspan */
80
- get colspan() {
81
- return this.getAttr('colspan');
82
- }
83
- /** 单元格类型 */
84
- get subtype() {
85
- return this.#getSyntax().subtype;
86
- }
87
- /* NOT FOR BROWSER */
88
- set subtype(subtype) {
89
- this.setSyntax(subtype);
90
- }
91
- set rowspan(rowspan) {
92
- this.setAttr('rowspan', rowspan);
93
- }
94
- set colspan(colspan) {
95
- this.setAttr('colspan', colspan);
96
- }
97
- /** 内部wikitext */
98
- get innerText() {
99
- return this.lastChild.text().trim();
100
- }
101
- set innerText(text) {
102
- this.lastChild.replaceChildren(...index_1.default.parse(text, true, undefined, this.getAttribute('config')).childNodes);
103
- }
104
- /* NOT FOR BROWSER END */
105
- /**
106
- * @param syntax 单元格语法
107
- * @param inner 内部wikitext
108
- */
109
- constructor(syntax, inner, config = index_1.default.getConfig(), accum = []) {
110
- let innerSyntax = /\||\0\d+!\x7F/u.exec(inner ?? ''), attr = innerSyntax ? inner.slice(0, innerSyntax.index) : '';
111
- if (/\[\[|-\{/u.test(attr)) {
112
- innerSyntax = null;
113
- attr = '';
114
- }
115
- super(/^(?:\n[^\S\n]*(?:[|!]|\|\+|\{\{\s*!\s*\}\}\+?)|(?:\||\{\{\s*!\s*\}\}){2}|!!|\{\{\s*!!\s*\}\})$/u, syntax, 'td', attr, config, accum, { SyntaxToken: 0, AttributesToken: 1, Token: 2 });
116
- if (innerSyntax) {
117
- [this.#innerSyntax] = innerSyntax;
118
- }
119
- const innerToken = new index_2.Token(inner?.slice((innerSyntax?.index ?? NaN) + this.#innerSyntax.length), config, accum);
120
- innerToken.type = 'td-inner';
121
- innerToken.setAttribute('stage', 4);
122
- this.insertAt(innerToken);
123
- }
124
- /** 表格语法信息 */
125
- #getSyntax() {
126
- const { rev } = debug_1.Shadow;
127
- if (this.#syntax && this.#syntax[0] !== rev) {
128
- this.#syntax = undefined;
129
- }
130
- if (index_1.default.viewOnly) {
131
- this.#syntax ??= [rev, this.#computeSyntax()];
132
- return this.#syntax[1];
133
- }
134
- return this.#computeSyntax();
135
- }
136
- /** 表格语法信息 */
137
- #computeSyntax() {
138
- const syntax = this.firstChild.text(),
139
- /* NOT FOR BROWSER */
140
- esc = syntax.includes('{{'),
141
- /* NOT FOR BROWSER END */
142
- char = syntax.slice(-1);
143
- let subtype = 'td';
144
- if (char === '!') {
145
- subtype = 'th';
146
- }
147
- else if (char === '+') {
148
- subtype = 'caption';
149
- }
150
- if (this.isIndependent()) {
151
- return {
152
- subtype,
153
- /* NOT FOR BROWSER */
154
- escape: esc,
155
- correction: false,
156
- };
157
- }
158
- const { previousSibling } = this;
159
- /* NOT FOR BROWSER */
160
- if (!(previousSibling instanceof TdToken)) {
161
- return { subtype, escape: esc, correction: true };
162
- }
163
- /* NOT FOR BROWSER END */
164
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
165
- const result = { ...previousSibling.#getSyntax() };
166
- /* NOT FOR BROWSER */
167
- const str = previousSibling.lastChild.toString();
168
- result.escape ||= esc;
169
- result.correction = str.includes('\n') && debug_1.Shadow.run(() => {
170
- const config = this.getAttribute('config'), include = this.getAttribute('include');
171
- return new index_2.Token(str, config).parseOnce(0, include).parseOnce().parseOnce()
172
- .toString()
173
- .includes('\n');
174
- });
175
- if (subtype === 'th' && result.subtype !== 'th') {
176
- result.subtype = 'th';
177
- result.correction = true;
178
- }
179
- /* NOT FOR BROWSER END */
180
- return result;
181
- }
182
- /** @private */
183
- afterBuild() {
184
- if (this.#innerSyntax.includes('\0')) {
185
- this.#innerSyntax = this.buildFromStr(this.#innerSyntax, constants_1.BuildMethod.String);
186
- }
187
- super.afterBuild();
188
- }
189
- /** @private */
190
- toString(skip) {
191
- /* NOT FOR BROWSER */
192
- this.#correct();
193
- /* NOT FOR BROWSER END */
194
- const { childNodes: [syntax, attr, inner] } = this;
195
- return syntax.toString(skip) + attr.toString(skip) + this.#innerSyntax + inner.toString(skip);
196
- }
197
- /** @private */
198
- text() {
199
- /* NOT FOR BROWSER */
200
- this.#correct();
201
- /* NOT FOR BROWSER END */
202
- const { childNodes: [syntax, attr, inner] } = this;
203
- return syntax.text() + attr.text() + this.#innerSyntax + inner.text();
204
- }
205
- /** @private */
206
- getGaps(i) {
207
- if (i === 1) {
208
- /* NOT FOR BROWSER */
209
- this.#correct();
210
- /* NOT FOR BROWSER END */
211
- return this.#innerSyntax.length;
212
- }
213
- return 0;
214
- }
215
- /** @private */
216
- lint(start = this.getAbsoluteIndex(), re) {
217
- const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start + this.getRelativeIndex(this.length - 1));
218
- for (const child of this.lastChild.childNodes) {
219
- if (child.type === 'text') {
220
- const { data } = child;
221
- if (data.includes('|')) {
222
- const isError = data.includes('||'), e = (0, lint_1.generateForChild)(child, rect, 'pipe-like', 'additional "|" in a table cell', isError ? 'error' : 'warning');
223
- if (isError) {
224
- const syntax = { caption: '|+', td: '|', th: '!' }[this.subtype];
225
- e.fix = {
226
- range: [e.startIndex, e.endIndex],
227
- text: data.replace(/\|\|/gu, `\n${syntax}`),
228
- };
229
- }
230
- else {
231
- e.suggestions = [
232
- {
233
- desc: 'escape',
234
- range: [e.startIndex, e.endIndex],
235
- text: data.replace(/\|/gu, '&#124;'),
236
- },
237
- ];
238
- }
239
- errors.push(e);
240
- }
241
- }
242
- }
243
- return errors;
244
- }
245
- /** 是否位于行首 */
246
- isIndependent() {
247
- return this.firstChild.text().startsWith('\n');
248
- }
249
- getAttr(key) {
250
- const value = super.getAttr(key);
251
- key = key.toLowerCase().trim();
252
- return (key === 'rowspan' || key === 'colspan' ? parseInt(value) || 1 : value);
253
- }
254
- /** @private */
255
- print() {
256
- const { childNodes: [syntax, attr, inner] } = this;
257
- return `<span class="wpb-td">${syntax.print()}${attr.print()}${this.#innerSyntax}${inner.print()}</span>`;
258
- }
259
- /** @override */
260
- json() {
261
- const json = super.json();
262
- json['subtype'] = this.subtype;
263
- return json;
264
- }
265
- /* NOT FOR BROWSER */
266
- cloneNode() {
267
- const token = super.cloneNode();
268
- token.setAttribute('innerSyntax', this.#innerSyntax);
269
- return token;
270
- }
271
- /** @private */
272
- setAttribute(key, value) {
273
- if (key === 'innerSyntax') {
274
- this.#innerSyntax = (value ?? '');
275
- }
276
- else {
277
- super.setAttribute(key, value);
278
- }
279
- }
280
- /** @private */
281
- setSyntax(syntax, esc) {
282
- const aliases = { td: '\n|', th: '\n!', caption: '\n|+' };
283
- super.setSyntax(aliases[syntax] ?? syntax, esc);
284
- }
285
- /** 修复\<td\>语法 */
286
- #correct() {
287
- if (this.childNodes[1].toString()) {
288
- this.#innerSyntax ||= '|';
289
- }
290
- const { subtype, escape, correction } = this.#getSyntax();
291
- if (correction) {
292
- this.setSyntax(subtype, escape);
293
- }
294
- }
295
- /** 改为独占一行 */
296
- independence() {
297
- if (!this.isIndependent()) {
298
- const { subtype, escape } = this.#getSyntax();
299
- this.setSyntax(subtype, escape);
300
- }
301
- }
302
- getAttrs() {
303
- const attr = super.getAttrs();
304
- if ('rowspan' in attr) {
305
- attr.rowspan = parseInt(attr.rowspan);
306
- }
307
- if ('colspan' in attr) {
308
- attr.colspan = parseInt(attr.colspan);
309
- }
310
- return attr;
311
- }
312
- setAttr(keyOrProp, value) {
313
- if (typeof keyOrProp !== 'string') {
314
- for (const [key, val] of Object.entries(keyOrProp)) {
315
- this.setAttr(key, val);
316
- }
317
- return;
318
- }
319
- const key = keyOrProp.toLowerCase().trim();
320
- let v;
321
- if (typeof value === 'number' && (key === 'rowspan' || key === 'colspan')) {
322
- v = value === 1 ? false : String(value);
323
- }
324
- else {
325
- v = String(value);
326
- }
327
- super.setAttr(key, v);
328
- if (!this.childNodes[1].toString()) {
329
- this.#innerSyntax = '';
330
- }
331
- }
332
- /** @private */
333
- escape() {
334
- super.escape();
335
- if (this.childNodes[1].toString()) {
336
- this.#innerSyntax ||= '{{!}}';
337
- }
338
- if (this.#innerSyntax === '|') {
339
- this.#innerSyntax = '{{!}}';
340
- }
341
- }
342
- /** @private */
343
- toHtmlInternal(nowrap) {
344
- const { subtype, childNodes: [, attr, inner], nextSibling } = this, notEOL = nextSibling?.toString().startsWith('\n') === false, lf = nowrap ? ' ' : '\n';
345
- let html = inner.toHtmlInternal(nowrap).replace(/^[^\S\n]*/u, '');
346
- if (notEOL) {
347
- html = html.replace(/(?<=[\S\n])[^\S\n]*$/u, '');
348
- }
349
- return `${lf}<${subtype}${attr.toHtmlInternal()}>${subtype === 'caption' ? (0, string_1.newline)(html) : html + (notEOL ? '' : lf)}</${subtype}>`;
350
- }
351
- };
352
- return TdToken = _classThis;
353
- })();
354
- exports.TdToken = TdToken;
355
- /* NOT FOR BROWSER */
356
- /**
357
- * 创建新的单元格
358
- * @param inner 内部wikitext
359
- * @param subtype 单元格类型
360
- * @param attr 单元格属性
361
- * @param include 是否嵌入
362
- * @param config
363
- */
364
- const createTd = (inner, subtype = 'td', attr = {}, include, config = index_1.default.getConfig()) => {
365
- const innerToken = typeof inner === 'string' ? index_1.default.parse(inner, include, undefined, config) : inner,
366
- // @ts-expect-error abstract class
367
- token = debug_1.Shadow.run(() => new TdToken('\n|', undefined, config));
368
- token.setSyntax(subtype);
369
- token.lastChild.safeReplaceWith(innerToken);
370
- token.setAttr(attr);
371
- return token;
372
- };
373
- exports.createTd = createTd;
374
- /* NOT FOR BROWSER END */
375
- constants_1.classes['TdToken'] = __filename;
@@ -1,30 +0,0 @@
1
- import { TrBaseToken } from './trBase';
2
- import type { Config } from '../../base';
3
- import type { Token, TdToken, TableToken, SyntaxToken, AttributesToken } from '../../internal';
4
- /**
5
- * 表格行,含开头的换行,不含结尾的换行
6
- * @classdesc `{childNodes: [SyntaxToken, AttributesToken, ?Token, ...TdToken]}`
7
- */
8
- export declare abstract class TrToken extends TrBaseToken {
9
- #private;
10
- readonly childNodes: readonly [SyntaxToken, AttributesToken, ...TdToken[]];
11
- abstract get lastChild(): AttributesToken | TdToken;
12
- abstract get parentNode(): TableToken | undefined;
13
- abstract get nextSibling(): this | SyntaxToken | undefined;
14
- abstract get previousSibling(): Token;
15
- abstract get children(): [SyntaxToken, AttributesToken, ...TdToken[]];
16
- abstract get lastElementChild(): AttributesToken | TdToken;
17
- abstract get parentElement(): TableToken | undefined;
18
- abstract get nextElementSibling(): this | SyntaxToken | undefined;
19
- abstract get previousElementSibling(): Token;
20
- get type(): 'tr';
21
- /**
22
- * @param syntax 表格语法
23
- * @param attr 表格属性
24
- */
25
- constructor(syntax: string, attr?: string, config?: Config, accum?: Token[]);
26
- /** 获取下一行 */
27
- getNextRow(): TrToken | undefined;
28
- /** 获取前一行 */
29
- getPreviousRow(): TrToken | undefined;
30
- }
@@ -1,61 +0,0 @@
1
- "use strict";
2
- var _a;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.TrToken = void 0;
5
- const trBase_1 = require("./trBase");
6
- /* NOT FOR BROWSER */
7
- const constants_1 = require("../../util/constants");
8
- /* NOT FOR BROWSER END */
9
- /**
10
- * 表格行,含开头的换行,不含结尾的换行
11
- * @classdesc `{childNodes: [SyntaxToken, AttributesToken, ?Token, ...TdToken]}`
12
- */
13
- class TrToken extends trBase_1.TrBaseToken {
14
- /* NOT FOR BROWSER END */
15
- get type() {
16
- return 'tr';
17
- }
18
- /**
19
- * @param syntax 表格语法
20
- * @param attr 表格属性
21
- */
22
- constructor(syntax, attr, config, accum) {
23
- super(/^\n[^\S\n]*(?:\|-+|\{\{\s*!\s*\}\}-+|\{\{\s*!-\s*\}\}-*)$/u, syntax, 'tr', attr, config, accum, {
24
- Token: 2, SyntaxToken: 0, AttributesToken: 1, TdToken: '2:',
25
- });
26
- }
27
- /* NOT FOR BROWSER */
28
- /** @private */
29
- text() {
30
- const str = super.text();
31
- return str.trim().includes('\n') ? str : '';
32
- }
33
- /**
34
- * 获取相邻行
35
- * @param subset 筛选兄弟节点的方法
36
- */
37
- #getSiblingRow(subset) {
38
- const { parentNode } = this;
39
- if (!parentNode) {
40
- return undefined;
41
- }
42
- const { childNodes } = parentNode, index = childNodes.indexOf(this);
43
- for (const child of subset(childNodes, index)) {
44
- if (child instanceof _a && child.getRowCount()) {
45
- return child;
46
- }
47
- }
48
- return undefined;
49
- }
50
- /** 获取下一行 */
51
- getNextRow() {
52
- return this.#getSiblingRow((childNodes, index) => childNodes.slice(index + 1));
53
- }
54
- /** 获取前一行 */
55
- getPreviousRow() {
56
- return this.#getSiblingRow((childNodes, index) => childNodes.slice(0, index).reverse());
57
- }
58
- }
59
- exports.TrToken = TrToken;
60
- _a = TrToken;
61
- constants_1.classes['TrToken'] = __filename;
@@ -1,49 +0,0 @@
1
- import { TableBaseToken } from './base';
2
- import { TdToken } from './td';
3
- import type { LintError } from '../../base';
4
- import type { AstNodes, SyntaxToken, TrToken } from '../../internal';
5
- import { Token } from '../index';
6
- import type { TdAttrs, TdSubtypes } from './td';
7
- export interface TableCoords {
8
- readonly row: number;
9
- readonly column: number;
10
- readonly x?: undefined;
11
- readonly y?: undefined;
12
- readonly start?: boolean;
13
- }
14
- /** 表格行或表格 */
15
- export declare abstract class TrBaseToken extends TableBaseToken {
16
- #private;
17
- abstract get type(): 'table' | 'tr';
18
- /** 获取行数 */
19
- getRowCount(): number;
20
- /**
21
- * 获取第n列
22
- * @param n 列号
23
- * @param insert 是否用于判断插入新列的位置
24
- * @throws `RangeError` 不存在对应单元格
25
- */
26
- getNthCol(n: number, insert?: false): TdToken | undefined;
27
- getNthCol(n: number, insert: true): TdToken | TrToken | SyntaxToken | undefined;
28
- /**
29
- * @override
30
- * @param i 移除位置
31
- */
32
- removeAt(i: number): AstNodes;
33
- /**
34
- * @override
35
- * @param token 待插入的子节点
36
- * @param i 插入位置
37
- */
38
- insertAt<T extends Token>(token: T, i?: number): T;
39
- /** 获取列数 */
40
- getColCount(): number;
41
- /**
42
- * 插入新的单元格
43
- * @param inner 单元格内部wikitext
44
- * @param {TableCoords} coord 单元格坐标
45
- * @param subtype 单元格类型
46
- * @param attr 单元格属性
47
- */
48
- insertTableCell(inner: string | Token, { column }: TableCoords, subtype?: TdSubtypes, attr?: TdAttrs): TdToken;
49
- }
@@ -1,165 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TrBaseToken = void 0;
4
- const lint_1 = require("../../util/lint");
5
- const base_1 = require("./base");
6
- const td_1 = require("./td");
7
- /* NOT FOR BROWSER */
8
- const debug_1 = require("../../util/debug");
9
- const constants_1 = require("../../util/constants");
10
- const html_1 = require("../../util/html");
11
- const debug_2 = require("../../util/debug");
12
- const index_1 = require("../index");
13
- /** 表格行或表格 */
14
- class TrBaseToken extends base_1.TableBaseToken {
15
- /** @private */
16
- lint(start = this.getAbsoluteIndex(), re) {
17
- const errors = super.lint(start, re), inter = this.childNodes.find(({ type }) => type === 'table-inter');
18
- if (!inter) {
19
- return errors;
20
- }
21
- const first = inter.childNodes.find(child => child.text().trim()), tdPattern = /^\s*(?:!|\{\{\s*![!-]?\s*\}\})/u;
22
- if (!first
23
- || tdPattern.test(first.toString())
24
- || first.is('arg') && tdPattern.test(first.default || '')) {
25
- return errors;
26
- }
27
- else if (first.is('magic-word')) {
28
- try {
29
- if (first.getPossibleValues().every(token => tdPattern.test(token.text()))) {
30
- return errors;
31
- }
32
- }
33
- catch { }
34
- }
35
- const error = (0, lint_1.generateForChild)(inter, { start }, 'fostered-content', 'content to be moved out from the table');
36
- error.severity = first.type === 'template' ? 'warning' : 'error';
37
- error.startIndex++;
38
- error.startLine++;
39
- error.startCol = 0;
40
- errors.push(error);
41
- return errors;
42
- }
43
- /** 获取行数 */
44
- getRowCount() {
45
- return Number(this.childNodes.some(child => child instanceof td_1.TdToken && child.isIndependent() && !child.firstChild.text().endsWith('+')));
46
- }
47
- getNthCol(n, insert) {
48
- /* NOT FOR BROWSER */
49
- const nCols = this.getColCount();
50
- n += n < 0 ? nCols : 0;
51
- if (n < 0 || n > nCols || n === nCols && !insert) {
52
- throw new RangeError(`There is no cell at position ${n}!`);
53
- }
54
- /* NOT FOR BROWSER END */
55
- let last = 0;
56
- for (const child of this.childNodes.slice(2)) {
57
- if (child instanceof td_1.TdToken) {
58
- if (child.isIndependent()) {
59
- last = Number(child.subtype !== 'caption');
60
- }
61
- n -= last;
62
- if (n < 0) {
63
- return child;
64
- }
65
- /* NOT FOR BROWSER */
66
- }
67
- else if (child.is('tr') || child.is('table-syntax')) {
68
- return child;
69
- /* NOT FOR BROWSER END */
70
- }
71
- }
72
- return undefined;
73
- }
74
- /* NOT FOR BROWSER */
75
- /** 修复简单的表格语法错误 */
76
- #correct() {
77
- const { childNodes: [, , child] } = this;
78
- if (child?.constructor === index_1.Token) {
79
- const { firstChild } = child;
80
- if (firstChild?.type !== 'text') {
81
- child.prepend('\n');
82
- }
83
- else if (!firstChild.data.startsWith('\n')) {
84
- firstChild.insertData(0, '\n');
85
- }
86
- }
87
- }
88
- /** @private */
89
- text() {
90
- this.#correct();
91
- return super.text();
92
- }
93
- /** @private */
94
- toString(skip) {
95
- this.#correct();
96
- return super.toString(skip);
97
- }
98
- /**
99
- * @override
100
- * @param i 移除位置
101
- */
102
- removeAt(i) {
103
- i += i < 0 ? this.length : 0;
104
- const child = this.childNodes[i];
105
- if (child instanceof td_1.TdToken && child.isIndependent()) {
106
- const { nextSibling } = child;
107
- if (nextSibling?.type === 'td') {
108
- nextSibling.independence();
109
- }
110
- }
111
- return super.removeAt(i);
112
- }
113
- /**
114
- * @override
115
- * @param token 待插入的子节点
116
- * @param i 插入位置
117
- */
118
- insertAt(token, i = this.length) {
119
- if (!debug_1.Shadow.running && token.type !== 'td') {
120
- if (this.type === 'tr') {
121
- this.typeError('insertAt', 'TdToken');
122
- }
123
- else if (token.type !== 'tr') {
124
- this.typeError('insertAt', 'TrToken', 'TdToken');
125
- }
126
- }
127
- i += i < 0 ? this.length : 0;
128
- const child = this.childNodes[i];
129
- if (token instanceof td_1.TdToken && token.isIndependent() && child instanceof td_1.TdToken) {
130
- child.independence();
131
- }
132
- return super.insertAt(token, i);
133
- }
134
- /** 获取列数 */
135
- getColCount() {
136
- let count = 0, last = 0;
137
- for (const child of this.childNodes) {
138
- if (child instanceof td_1.TdToken) {
139
- last = child.isIndependent() ? Number(child.subtype !== 'caption') : last;
140
- count += last;
141
- }
142
- }
143
- return count;
144
- }
145
- /**
146
- * 插入新的单元格
147
- * @param inner 单元格内部wikitext
148
- * @param {TableCoords} coord 单元格坐标
149
- * @param subtype 单元格类型
150
- * @param attr 单元格属性
151
- */
152
- insertTableCell(inner, { column }, subtype = 'td', attr = {}) {
153
- const token = (0, td_1.createTd)(inner, subtype, attr, this.getAttribute('include'), this.getAttribute('config'));
154
- return this.insertBefore(token, this.getNthCol(column, true));
155
- }
156
- /** @private */
157
- toHtmlInternal(nowrap) {
158
- const { childNodes, type } = this, td = childNodes.filter((0, debug_2.isToken)('td'));
159
- return td.some(({ subtype }) => subtype !== 'caption')
160
- ? `<tr${type === 'tr' ? childNodes[1].toHtmlInternal() : ''}>${(0, html_1.html)(td, '', nowrap)}</tr>`
161
- : (0, html_1.html)(td, '', nowrap);
162
- }
163
- }
164
- exports.TrBaseToken = TrBaseToken;
165
- constants_1.classes['TrBaseToken'] = __filename;