wikiparser-node 1.0.2-b → 1.0.3

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 (157) hide show
  1. package/README.en.md +57 -0
  2. package/README.md +5 -1
  3. package/config/.schema.json +160 -0
  4. package/config/llwiki.json +35 -1
  5. package/config/moegirl.json +44 -1
  6. package/config/zhwiki.json +466 -1
  7. package/dist/addon/table.d.ts +6 -0
  8. package/dist/addon/table.js +531 -0
  9. package/dist/bin/toc.js +18 -0
  10. package/dist/index.d.ts +60 -0
  11. package/dist/index.js +205 -0
  12. package/dist/internal.d.ts +44 -0
  13. package/dist/lib/element.d.ts +155 -0
  14. package/dist/lib/element.js +655 -0
  15. package/dist/lib/node.d.ts +143 -0
  16. package/dist/lib/node.js +419 -0
  17. package/dist/lib/range.d.ts +115 -0
  18. package/dist/lib/range.js +353 -0
  19. package/dist/lib/ranges.d.ts +28 -0
  20. package/dist/lib/ranges.js +120 -0
  21. package/dist/lib/text.d.ts +63 -0
  22. package/dist/lib/text.js +217 -0
  23. package/dist/lib/title.d.ts +26 -0
  24. package/dist/lib/title.js +125 -0
  25. package/dist/mixin/attributesParent.js +94 -0
  26. package/dist/mixin/fixed.js +32 -0
  27. package/dist/mixin/flagsParent.js +70 -0
  28. package/dist/mixin/hidden.js +22 -0
  29. package/dist/mixin/magicLinkParent.js +41 -0
  30. package/dist/mixin/singleLine.js +25 -0
  31. package/dist/mixin/sol.js +43 -0
  32. package/dist/mixin/syntax.js +56 -0
  33. package/dist/parser/braces.js +123 -0
  34. package/dist/parser/commentAndExt.js +65 -0
  35. package/dist/parser/converter.js +40 -0
  36. package/dist/parser/externalLinks.js +28 -0
  37. package/dist/parser/hrAndDoubleUnderscore.js +38 -0
  38. package/dist/parser/html.js +36 -0
  39. package/dist/parser/links.js +94 -0
  40. package/dist/parser/list.js +59 -0
  41. package/dist/parser/magicLinks.js +40 -0
  42. package/dist/parser/quotes.js +67 -0
  43. package/dist/parser/selector.js +163 -0
  44. package/dist/parser/table.js +110 -0
  45. package/dist/src/arg.d.ts +58 -0
  46. package/dist/src/arg.js +190 -0
  47. package/dist/src/atom.d.ts +12 -0
  48. package/dist/src/atom.js +27 -0
  49. package/dist/src/attribute.d.ts +86 -0
  50. package/dist/src/attribute.js +392 -0
  51. package/dist/src/attributes.d.ts +106 -0
  52. package/dist/src/attributes.js +339 -0
  53. package/dist/src/converter.d.ts +51 -0
  54. package/dist/src/converter.js +79 -0
  55. package/dist/src/converterFlags.d.ts +87 -0
  56. package/dist/src/converterFlags.js +223 -0
  57. package/dist/src/converterRule.d.ts +81 -0
  58. package/dist/src/converterRule.js +221 -0
  59. package/dist/src/extLink.d.ts +53 -0
  60. package/dist/src/extLink.js +121 -0
  61. package/dist/src/gallery.d.ts +55 -0
  62. package/dist/src/gallery.js +129 -0
  63. package/dist/src/heading.d.ts +76 -0
  64. package/dist/src/heading.js +127 -0
  65. package/dist/src/hidden.d.ts +21 -0
  66. package/dist/src/hidden.js +23 -0
  67. package/dist/src/html.d.ts +99 -0
  68. package/dist/src/html.js +230 -0
  69. package/dist/src/imageParameter.d.ts +66 -0
  70. package/dist/src/imageParameter.js +246 -0
  71. package/dist/src/imagemap.d.ts +57 -0
  72. package/dist/src/imagemap.js +148 -0
  73. package/dist/src/imagemapLink.d.ts +57 -0
  74. package/dist/src/imagemapLink.js +40 -0
  75. package/dist/src/index.d.ts +145 -0
  76. package/dist/src/index.js +766 -0
  77. package/dist/src/link/base.d.ts +52 -0
  78. package/dist/src/link/base.js +198 -0
  79. package/dist/src/link/category.d.ts +13 -0
  80. package/dist/src/link/category.js +29 -0
  81. package/dist/src/link/file.d.ts +96 -0
  82. package/dist/src/link/file.js +253 -0
  83. package/dist/src/link/galleryImage.d.ts +41 -0
  84. package/dist/src/link/galleryImage.js +98 -0
  85. package/dist/src/link/index.d.ts +53 -0
  86. package/dist/src/link/index.js +123 -0
  87. package/dist/src/magicLink.d.ts +58 -0
  88. package/dist/src/magicLink.js +122 -0
  89. package/dist/src/nested.d.ts +44 -0
  90. package/dist/src/nested.js +87 -0
  91. package/dist/src/nowiki/base.d.ts +46 -0
  92. package/dist/src/nowiki/base.js +42 -0
  93. package/dist/src/nowiki/comment.d.ts +39 -0
  94. package/dist/src/nowiki/comment.js +67 -0
  95. package/dist/src/nowiki/dd.d.ts +8 -0
  96. package/dist/src/nowiki/dd.js +25 -0
  97. package/dist/src/nowiki/doubleUnderscore.d.ts +43 -0
  98. package/dist/src/nowiki/doubleUnderscore.js +51 -0
  99. package/dist/src/nowiki/hr.d.ts +29 -0
  100. package/dist/src/nowiki/hr.js +14 -0
  101. package/dist/src/nowiki/index.d.ts +16 -0
  102. package/dist/src/nowiki/index.js +21 -0
  103. package/dist/src/nowiki/list.d.ts +29 -0
  104. package/dist/src/nowiki/list.js +47 -0
  105. package/dist/src/nowiki/listBase.d.ts +18 -0
  106. package/dist/src/nowiki/listBase.js +12 -0
  107. package/dist/src/nowiki/noinclude.d.ts +25 -0
  108. package/dist/src/nowiki/noinclude.js +25 -0
  109. package/dist/src/nowiki/quote.d.ts +22 -0
  110. package/dist/src/nowiki/quote.js +50 -0
  111. package/dist/src/onlyinclude.d.ts +16 -0
  112. package/dist/src/onlyinclude.js +57 -0
  113. package/dist/src/paramTag/index.d.ts +37 -0
  114. package/dist/src/paramTag/index.js +68 -0
  115. package/dist/src/paramTag/inputbox.d.ts +8 -0
  116. package/dist/src/paramTag/inputbox.js +23 -0
  117. package/dist/src/parameter.d.ts +82 -0
  118. package/dist/src/parameter.js +202 -0
  119. package/dist/src/pre.d.ts +28 -0
  120. package/dist/src/pre.js +51 -0
  121. package/dist/src/syntax.d.ts +25 -0
  122. package/dist/src/syntax.js +30 -0
  123. package/dist/src/table/base.d.ts +52 -0
  124. package/dist/src/table/base.js +78 -0
  125. package/dist/src/table/index.d.ts +229 -0
  126. package/dist/src/table/index.js +364 -0
  127. package/dist/src/table/td.d.ts +102 -0
  128. package/dist/src/table/td.js +261 -0
  129. package/dist/src/table/tr.d.ts +32 -0
  130. package/dist/src/table/tr.js +56 -0
  131. package/dist/src/table/trBase.d.ts +54 -0
  132. package/dist/src/table/trBase.js +151 -0
  133. package/dist/src/tagPair/ext.d.ts +55 -0
  134. package/dist/src/tagPair/ext.js +142 -0
  135. package/dist/src/tagPair/include.d.ts +52 -0
  136. package/dist/src/tagPair/include.js +58 -0
  137. package/dist/src/tagPair/index.d.ts +47 -0
  138. package/dist/src/tagPair/index.js +93 -0
  139. package/dist/src/transclude.d.ts +167 -0
  140. package/dist/src/transclude.js +694 -0
  141. package/dist/util/constants.js +108 -0
  142. package/dist/util/debug.js +63 -0
  143. package/dist/util/diff.js +72 -0
  144. package/dist/util/lint.js +48 -0
  145. package/dist/util/string.js +63 -0
  146. package/errors/README +1 -0
  147. package/i18n/zh-hans.json +2 -0
  148. package/i18n/zh-hant.json +2 -0
  149. package/package.json +12 -24
  150. package/printed/README +1 -0
  151. package/bundle/bundle.min.js +0 -37
  152. package/extensions/dist/base.js +0 -70
  153. package/extensions/dist/editor.js +0 -172
  154. package/extensions/dist/highlight.js +0 -39
  155. package/extensions/dist/lint.js +0 -48
  156. package/extensions/editor.css +0 -63
  157. package/extensions/ui.css +0 -119
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TableBaseToken = void 0;
4
+ const debug_1 = require("../../util/debug");
5
+ const constants_1 = require("../../util/constants");
6
+ const attributesParent_1 = require("../../mixin/attributesParent");
7
+ const Parser = require("../../index");
8
+ const index_1 = require("../index");
9
+ const syntax_1 = require("../syntax");
10
+ const attributes_1 = require("../attributes");
11
+ /* NOT FOR BROWSER */
12
+ /**
13
+ * 转义表格语法
14
+ * @param syntax 表格语法节点
15
+ */
16
+ const escapeTable = (syntax) => {
17
+ const wikitext = syntax.childNodes.map(child => child.type === 'text'
18
+ ? child.data.replaceAll('|', '{{!}}')
19
+ : String(child)).join(''), { childNodes } = Parser.parse(wikitext, syntax.getAttribute('include'), 2, syntax.getAttribute('config'));
20
+ syntax.replaceChildren(...childNodes);
21
+ };
22
+ /* NOT FOR BROWSER END */
23
+ /**
24
+ * 表格行,含开头的换行,不含结尾的换行
25
+ * @classdesc `{childNodes: [SyntaxToken, AttributesToken, ...Token]}`
26
+ */
27
+ class TableBaseToken extends (0, attributesParent_1.attributesParent)(index_1.Token, 1) {
28
+ /**
29
+ * @param pattern 表格语法正则
30
+ * @param syntax 表格语法
31
+ * @param attr 表格属性
32
+ */
33
+ constructor(pattern, syntax, attr, config = Parser.getConfig(), accum = [], acceptable = {}) {
34
+ super(undefined, config, accum, acceptable);
35
+ this.append(new syntax_1.SyntaxToken(syntax, pattern, 'table-syntax', config, accum, {
36
+ 'Stage-1': ':', '!ExtToken': '', TranscludeToken: ':',
37
+ }), new attributes_1.AttributesToken(attr, 'table-attrs', this.type, config, accum));
38
+ this.protectChildren(0, 1);
39
+ }
40
+ /* NOT FOR BROWSER */
41
+ /** @override */
42
+ cloneNode() {
43
+ const [syntax, attr, ...cloned] = this.cloneChildNodes();
44
+ return debug_1.Shadow.run(() => {
45
+ const { constructor } = this, token = new constructor(undefined, undefined, this.getAttribute('config'));
46
+ token.firstChild.safeReplaceWith(syntax);
47
+ token.childNodes[1].safeReplaceWith(attr);
48
+ if (token.type === 'td') { // TdToken
49
+ token.childNodes[2].safeReplaceWith(cloned[0]);
50
+ }
51
+ else {
52
+ token.append(...cloned);
53
+ }
54
+ return token;
55
+ });
56
+ }
57
+ /** 转义表格语法 */
58
+ escape() {
59
+ for (const child of this.childNodes) {
60
+ if (child instanceof syntax_1.SyntaxToken) {
61
+ escapeTable(child);
62
+ }
63
+ else if (child instanceof TableBaseToken) {
64
+ child.escape();
65
+ }
66
+ }
67
+ }
68
+ /** @private */
69
+ setSyntax(syntax, esc = false) {
70
+ const { firstChild } = this;
71
+ firstChild.replaceChildren(syntax);
72
+ if (esc) {
73
+ escapeTable(firstChild);
74
+ }
75
+ }
76
+ }
77
+ exports.TableBaseToken = TableBaseToken;
78
+ constants_1.classes['TableBaseToken'] = __filename;
@@ -0,0 +1,229 @@
1
+ import * as Parser from '../../index';
2
+ import { TrBaseToken } from './trBase';
3
+ import { SyntaxToken } from '../syntax';
4
+ import type { LintError } from '../../index';
5
+ import type { AttributesToken, TdToken, TrToken, Token } from '../../internal';
6
+ import type { TableCoords } from './trBase';
7
+ import type { TdAttrs, TdSubtypes } from './td';
8
+ import type { Layout } from '../../addon/table';
9
+ export interface TableRenderedCoords {
10
+ row?: undefined;
11
+ column?: undefined;
12
+ x: number;
13
+ y: number;
14
+ }
15
+ /**
16
+ * 表格
17
+ * @classdesc `{childNodes: [SyntaxToken, AttributesToken, ?Token, ...TdToken, ...TrToken, ?SyntaxToken]}`
18
+ */
19
+ export declare class TableToken extends TrBaseToken {
20
+ readonly type = "table";
21
+ childNodes: [SyntaxToken, AttributesToken, ...(TdToken | TrToken)[], SyntaxToken] | [SyntaxToken, AttributesToken, ...(TdToken | TrToken)[]];
22
+ abstract get children(): [SyntaxToken, AttributesToken, ...(TdToken | TrToken)[], SyntaxToken] | [SyntaxToken, AttributesToken, ...(TdToken | TrToken)[]];
23
+ abstract get lastChild(): AttributesToken | TdToken | TrToken | SyntaxToken;
24
+ abstract get lastElementChild(): AttributesToken | TdToken | TrToken | SyntaxToken;
25
+ /** 表格是否闭合 */
26
+ get closed(): boolean;
27
+ set closed(closed: boolean);
28
+ /**
29
+ * @param syntax 表格语法
30
+ * @param attr 表格属性
31
+ */
32
+ constructor(syntax: string, attr?: string, config?: Parser.Config, accum?: Token[]);
33
+ /** @override */
34
+ lint(start?: number): LintError[];
35
+ /**
36
+ * 闭合表格语法
37
+ * @param syntax 表格结尾语法
38
+ * @param halfParsed
39
+ */
40
+ close(syntax?: string, halfParsed?: boolean): void;
41
+ /**
42
+ * @override
43
+ * @param token 待插入的子节点
44
+ * @param i 插入位置
45
+ * @throws `SyntaxError` 表格的闭合部分非法
46
+ */
47
+ insertAt<T extends Token>(token: T, i?: number): T;
48
+ /** @override */
49
+ getRowCount(): number;
50
+ /** 获取下一行 */
51
+ getNextRow(): TrToken | undefined;
52
+ /**
53
+ * 获取第n行
54
+ * @param n 行号
55
+ * @param force 是否将表格自身视为第一行
56
+ * @param insert 是否用于判断插入新行的位置
57
+ * @throws `RangeError` 不存在该行
58
+ */
59
+ getNthRow(n: number, force?: boolean, insert?: false): TrToken | this | undefined;
60
+ /** @ignore */
61
+ getNthRow(n: number, force: boolean, insert: true): TrToken | this | SyntaxToken | undefined;
62
+ /** 获取所有行 */
63
+ getAllRows(): (TrToken | this)[];
64
+ /**
65
+ * 获取指定坐标的单元格
66
+ * @param coords 表格坐标
67
+ */
68
+ getNthCell(coords: TableCoords | TableRenderedCoords): TdToken | undefined;
69
+ /**
70
+ * 获取表格布局
71
+ * @param stop 中止条件
72
+ * @param stop.row 中止行
73
+ * @param stop.column 中止列
74
+ * @param stop.x 中止行
75
+ * @param stop.y 中止列
76
+ */
77
+ getLayout(stop?: {
78
+ row?: number;
79
+ column?: number;
80
+ x?: number;
81
+ y?: number;
82
+ }): Layout;
83
+ /** 打印表格布局 */
84
+ printLayout(): void;
85
+ /**
86
+ * 转换为渲染后的表格坐标
87
+ * @param {TableCoords} coord wikitext中的表格坐标
88
+ */
89
+ toRenderedCoords(coord: TableCoords): TableRenderedCoords | undefined;
90
+ /**
91
+ * 转换为wikitext中的表格坐标
92
+ * @param {TableRenderedCoords} coord 渲染后的表格坐标
93
+ */
94
+ toRawCoords(coord: TableRenderedCoords): TableCoords | undefined;
95
+ /**
96
+ * 获取完整行
97
+ * @param y 行号
98
+ */
99
+ getFullRow(y: number): Map<TdToken, boolean>;
100
+ /**
101
+ * 获取完整列
102
+ * @param x 列号
103
+ */
104
+ getFullCol(x: number): Map<TdToken, boolean>;
105
+ /**
106
+ * 设置行格式
107
+ * @param y 行号
108
+ * @param attr 表格属性
109
+ * @param multiRow 是否对所有单元格设置,或是仅对行首单元格设置
110
+ */
111
+ formatTableRow(y: number, attr?: TdAttrs | string, multiRow?: boolean): void;
112
+ /**
113
+ * 设置列格式
114
+ * @param x 列号
115
+ * @param attr 表格属性
116
+ * @param multiCol 是否对所有单元格设置,或是仅对行首单元格设置
117
+ */
118
+ formatTableCol(x: number, attr?: TdAttrs | string, multiCol?: boolean): void;
119
+ /**
120
+ * 填补表格行
121
+ * @param y 行号
122
+ * @param inner 填充内容
123
+ * @param subtype 单元格类型
124
+ * @param attr 表格属性
125
+ */
126
+ fillTableRow(y: number, inner: string | Token, subtype?: TdSubtypes, attr?: TdAttrs): void;
127
+ /**
128
+ * 填补表格
129
+ * @param inner 填充内容
130
+ * @param subtype 单元格类型
131
+ * @param attr 表格属性
132
+ */
133
+ fillTable(inner: string | Token, subtype?: TdSubtypes, attr?: TdAttrs): void;
134
+ /**
135
+ * @override
136
+ * @param inner 单元格内部wikitext
137
+ * @param coords 单元格坐标
138
+ * @param subtype 单元格类型
139
+ * @param attr 单元格属性
140
+ * @throws `RangeError` 指定的坐标不是单元格起始点
141
+ */
142
+ insertTableCell(inner: string | Token, coords: TableCoords | TableRenderedCoords, subtype?: TdSubtypes, attr?: TdAttrs): TdToken;
143
+ /**
144
+ * 插入表格行
145
+ * @param y 行号
146
+ * @param attr 表格行属性
147
+ * @param inner 内部wikitext
148
+ * @param subtype 单元格类型
149
+ * @param innerAttr 单元格属性
150
+ */
151
+ insertTableRow(y: number, attr?: Record<string, string | true>, inner?: string | Token, subtype?: TdSubtypes, innerAttr?: TdAttrs): TrToken;
152
+ /**
153
+ * 插入表格列
154
+ * @param x 列号
155
+ * @param inner 内部wikitext
156
+ * @param subtype 单元格类型
157
+ * @param attr 单元格属性
158
+ * @throws `RangeError` 列号过大
159
+ */
160
+ insertTableCol(x: number, inner: string | Token, subtype?: TdSubtypes, attr?: TdAttrs): void;
161
+ /**
162
+ * 移除表格行
163
+ * @param y 行号
164
+ */
165
+ removeTableRow(y: number): TrToken;
166
+ /**
167
+ * 移除表格列
168
+ * @param x 列号
169
+ */
170
+ removeTableCol(x: number): void;
171
+ /**
172
+ * 合并单元格
173
+ * @param xlim 列范围
174
+ * @param ylim 行范围
175
+ * @throws `RangeError` 待合并区域与外侧区域有重叠
176
+ */
177
+ mergeCells(xlim: [number, number], ylim: [number, number]): TdToken;
178
+ /**
179
+ * 分裂成多行
180
+ * @param coords 单元格坐标
181
+ */
182
+ splitIntoRows(coords: TableCoords | TableRenderedCoords): void;
183
+ /**
184
+ * 分裂成多列
185
+ * @param coords 单元格坐标
186
+ */
187
+ splitIntoCols(coords: TableCoords | TableRenderedCoords): void;
188
+ /**
189
+ * 分裂成单元格
190
+ * @param coords 单元格坐标
191
+ */
192
+ splitIntoCells(coords: TableCoords | TableRenderedCoords): void;
193
+ /**
194
+ * 复制一行并插入该行之前
195
+ * @param row 行号
196
+ */
197
+ replicateTableRow(row: number): TrToken;
198
+ /**
199
+ * 复制一列并插入该列之前
200
+ * @param x 列号
201
+ */
202
+ replicateTableCol(x: number): TdToken[];
203
+ /**
204
+ * 移动表格行
205
+ * @param y 行号
206
+ * @param before 新位置
207
+ * @throws `RangeError` 无法移动
208
+ */
209
+ moveTableRowBefore(y: number, before: number): TrToken;
210
+ /**
211
+ * 移动表格行
212
+ * @param y 行号
213
+ * @param after 新位置
214
+ * @throws `RangeError` 无法移动
215
+ */
216
+ moveTableRowAfter(y: number, after: number): TrToken;
217
+ /**
218
+ * 移动表格列
219
+ * @param x 列号
220
+ * @param before 新位置
221
+ */
222
+ moveTableColBefore(x: number, before: number): void;
223
+ /**
224
+ * 移动表格列
225
+ * @param x 列号
226
+ * @param after 新位置
227
+ */
228
+ moveTableColAfter(x: number, after: number): void;
229
+ }
@@ -0,0 +1,364 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TableToken = void 0;
4
+ const lint_1 = require("../../util/lint");
5
+ const string_1 = require("../../util/string");
6
+ const debug_1 = require("../../util/debug");
7
+ const constants_1 = require("../../util/constants");
8
+ const Parser = require("../../index");
9
+ const trBase_1 = require("./trBase");
10
+ const syntax_1 = require("../syntax");
11
+ const closingPattern = /^\n[^\S\n]*(?:\|\}|\{\{\s*!\s*\}\}\}|\{\{\s*!\)\s*\}\})$/u;
12
+ /**
13
+ * 表格
14
+ * @classdesc `{childNodes: [SyntaxToken, AttributesToken, ?Token, ...TdToken, ...TrToken, ?SyntaxToken]}`
15
+ */
16
+ // @ts-expect-error not implementing all abstract methods
17
+ class TableToken extends trBase_1.TrBaseToken {
18
+ type = 'table';
19
+ /** 表格是否闭合 */
20
+ get closed() {
21
+ return this.lastChild.type === 'table-syntax';
22
+ }
23
+ /* NOT FOR BROWSER */
24
+ set closed(closed) {
25
+ if (closed && !this.closed) {
26
+ this.close(this.closest('parameter') ? '\n{{!}}}' : '\n|}');
27
+ }
28
+ }
29
+ /* NOT FOR BROWSER END */
30
+ /**
31
+ * @param syntax 表格语法
32
+ * @param attr 表格属性
33
+ */
34
+ constructor(syntax, attr, config = Parser.getConfig(), accum = []) {
35
+ super(/^(?:\{\||\{\{\{\s*!\s*\}\}|\{\{\s*\(!\s*\}\})$/u, syntax, attr, config, accum, {
36
+ Token: 2, SyntaxToken: [0, -1], AttributesToken: 1, TdToken: '2:', TrToken: '2:',
37
+ });
38
+ }
39
+ /** @override */
40
+ lint(start = this.getAbsoluteIndex()) {
41
+ const errors = super.lint(start);
42
+ if (!this.closed) {
43
+ const { firstChild, lastChild: tr, } = this, { lastChild } = tr, error = (0, lint_1.generateForChild)(firstChild, { start }, 'unclosed table');
44
+ errors.push({ ...error, excerpt: String(lastChild?.type === 'td' ? lastChild : tr).slice(0, 50) });
45
+ }
46
+ return errors;
47
+ }
48
+ /**
49
+ * 闭合表格语法
50
+ * @param syntax 表格结尾语法
51
+ * @param halfParsed
52
+ */
53
+ close(syntax = '\n|}', halfParsed = false) {
54
+ const config = this.getAttribute('config'), accum = this.getAttribute('accum'), inner = halfParsed ? [syntax] : Parser.parse(syntax, this.getAttribute('include'), 2, config).childNodes;
55
+ if (!(this.lastChild instanceof syntax_1.SyntaxToken)) {
56
+ const token = debug_1.Shadow.run(() => super.insertAt(new syntax_1.SyntaxToken(undefined, closingPattern, 'table-syntax', config, accum, {
57
+ 'Stage-1': ':', '!ExtToken': '', TranscludeToken: ':',
58
+ })));
59
+ if (!halfParsed) {
60
+ token.afterBuild();
61
+ }
62
+ }
63
+ this.lastChild.replaceChildren(...inner);
64
+ }
65
+ /* NOT FOR BROWSER */
66
+ /**
67
+ * @override
68
+ * @param token 待插入的子节点
69
+ * @param i 插入位置
70
+ * @throws `SyntaxError` 表格的闭合部分非法
71
+ */
72
+ insertAt(token, i = this.length) {
73
+ const previous = this.childNodes.at(i - 1);
74
+ if (typeof token !== 'string' && token.type === 'td' && previous?.type === 'tr') {
75
+ Parser.warn('改为将单元格插入当前行。');
76
+ return previous.insertAt(token);
77
+ }
78
+ else if (i > 0 && token instanceof syntax_1.SyntaxToken && token.getAttribute('pattern') !== closingPattern) {
79
+ throw new SyntaxError(`表格的闭合部分不符合语法:${(0, string_1.noWrap)(String(token))}`);
80
+ }
81
+ return super.insertAt(token, i);
82
+ }
83
+ /** @override */
84
+ getRowCount() {
85
+ return super.getRowCount() + this.childNodes.filter(child => child.type === 'tr' && child.getRowCount()).length;
86
+ }
87
+ /** 获取下一行 */
88
+ getNextRow() {
89
+ return this.getNthRow(super.getRowCount() ? 1 : 0, false, false);
90
+ }
91
+ /** @ignore */
92
+ getNthRow(n, force = false, insert = false) {
93
+ const nRows = this.getRowCount(), isRow = super.getRowCount();
94
+ n += n < 0 ? nRows : 0;
95
+ if (n === 0 && (isRow || force && nRows === 0)) {
96
+ return this;
97
+ }
98
+ else if (n < 0 || n > nRows || n === nRows && !insert) {
99
+ throw new RangeError(`不存在第 ${n} 行!`);
100
+ }
101
+ else if (isRow) {
102
+ n--;
103
+ }
104
+ for (const child of this.childNodes.slice(2)) {
105
+ if (child.type === 'tr' && child.getRowCount()) {
106
+ n--;
107
+ if (n < 0) {
108
+ return child;
109
+ }
110
+ }
111
+ else if (child.type === 'table-syntax') {
112
+ return child;
113
+ }
114
+ }
115
+ return undefined;
116
+ }
117
+ /** 获取所有行 */
118
+ getAllRows() {
119
+ return [
120
+ ...super.getRowCount() ? [this] : [],
121
+ ...this.childNodes.slice(1).filter(child => child.type === 'tr' && child.getRowCount()),
122
+ ];
123
+ }
124
+ /**
125
+ * 获取指定坐标的单元格
126
+ * @param coords 表格坐标
127
+ */
128
+ getNthCell(coords) {
129
+ require('../../addon/table');
130
+ return this.getNthCell(coords);
131
+ }
132
+ /**
133
+ * 获取表格布局
134
+ * @param stop 中止条件
135
+ * @param stop.row 中止行
136
+ * @param stop.column 中止列
137
+ * @param stop.x 中止行
138
+ * @param stop.y 中止列
139
+ */
140
+ getLayout(stop) {
141
+ require('../../addon/table');
142
+ return this.getLayout(stop);
143
+ }
144
+ /** 打印表格布局 */
145
+ printLayout() {
146
+ require('../../addon/table');
147
+ this.printLayout();
148
+ }
149
+ /**
150
+ * 转换为渲染后的表格坐标
151
+ * @param {TableCoords} coord wikitext中的表格坐标
152
+ */
153
+ toRenderedCoords(coord) {
154
+ require('../../addon/table');
155
+ return this.toRenderedCoords(coord);
156
+ }
157
+ /**
158
+ * 转换为wikitext中的表格坐标
159
+ * @param {TableRenderedCoords} coord 渲染后的表格坐标
160
+ */
161
+ toRawCoords(coord) {
162
+ require('../../addon/table');
163
+ return this.toRawCoords(coord);
164
+ }
165
+ /**
166
+ * 获取完整行
167
+ * @param y 行号
168
+ */
169
+ getFullRow(y) {
170
+ require('../../addon/table');
171
+ return this.getFullRow(y);
172
+ }
173
+ /**
174
+ * 获取完整列
175
+ * @param x 列号
176
+ */
177
+ getFullCol(x) {
178
+ require('../../addon/table');
179
+ return this.getFullCol(x);
180
+ }
181
+ /**
182
+ * 设置行格式
183
+ * @param y 行号
184
+ * @param attr 表格属性
185
+ * @param multiRow 是否对所有单元格设置,或是仅对行首单元格设置
186
+ */
187
+ formatTableRow(y, attr = {}, multiRow = false) {
188
+ require('../../addon/table');
189
+ this.formatTableRow(y, attr, multiRow);
190
+ }
191
+ /**
192
+ * 设置列格式
193
+ * @param x 列号
194
+ * @param attr 表格属性
195
+ * @param multiCol 是否对所有单元格设置,或是仅对行首单元格设置
196
+ */
197
+ formatTableCol(x, attr = {}, multiCol = false) {
198
+ require('../../addon/table');
199
+ this.formatTableCol(x, attr, multiCol);
200
+ }
201
+ /**
202
+ * 填补表格行
203
+ * @param y 行号
204
+ * @param inner 填充内容
205
+ * @param subtype 单元格类型
206
+ * @param attr 表格属性
207
+ */
208
+ fillTableRow(y, inner, subtype = 'td', attr = {}) {
209
+ require('../../addon/table');
210
+ this.fillTableRow(y, inner, subtype, attr);
211
+ }
212
+ /**
213
+ * 填补表格
214
+ * @param inner 填充内容
215
+ * @param subtype 单元格类型
216
+ * @param attr 表格属性
217
+ */
218
+ fillTable(inner, subtype = 'td', attr = {}) {
219
+ require('../../addon/table');
220
+ this.fillTable(inner, subtype, attr);
221
+ }
222
+ /**
223
+ * @override
224
+ * @param inner 单元格内部wikitext
225
+ * @param coords 单元格坐标
226
+ * @param subtype 单元格类型
227
+ * @param attr 单元格属性
228
+ * @throws `RangeError` 指定的坐标不是单元格起始点
229
+ */
230
+ insertTableCell(inner, coords, subtype = 'td', attr = {}) {
231
+ require('../../addon/table');
232
+ return this.insertTableCell(inner, coords, subtype, attr);
233
+ }
234
+ /**
235
+ * 插入表格行
236
+ * @param y 行号
237
+ * @param attr 表格行属性
238
+ * @param inner 内部wikitext
239
+ * @param subtype 单元格类型
240
+ * @param innerAttr 单元格属性
241
+ */
242
+ insertTableRow(y, attr = {}, inner, subtype = 'td', innerAttr = {}) {
243
+ require('../../addon/table');
244
+ return this.insertTableRow(y, attr, inner, subtype, innerAttr);
245
+ }
246
+ /**
247
+ * 插入表格列
248
+ * @param x 列号
249
+ * @param inner 内部wikitext
250
+ * @param subtype 单元格类型
251
+ * @param attr 单元格属性
252
+ * @throws `RangeError` 列号过大
253
+ */
254
+ insertTableCol(x, inner, subtype = 'td', attr = {}) {
255
+ require('../../addon/table');
256
+ this.insertTableCol(x, inner, subtype, attr);
257
+ }
258
+ /**
259
+ * 移除表格行
260
+ * @param y 行号
261
+ */
262
+ removeTableRow(y) {
263
+ require('../../addon/table');
264
+ return this.removeTableRow(y);
265
+ }
266
+ /**
267
+ * 移除表格列
268
+ * @param x 列号
269
+ */
270
+ removeTableCol(x) {
271
+ require('../../addon/table');
272
+ this.removeTableCol(x);
273
+ }
274
+ /**
275
+ * 合并单元格
276
+ * @param xlim 列范围
277
+ * @param ylim 行范围
278
+ * @throws `RangeError` 待合并区域与外侧区域有重叠
279
+ */
280
+ mergeCells(xlim, ylim) {
281
+ require('../../addon/table');
282
+ return this.mergeCells(xlim, ylim);
283
+ }
284
+ /**
285
+ * 分裂成多行
286
+ * @param coords 单元格坐标
287
+ */
288
+ splitIntoRows(coords) {
289
+ require('../../addon/table');
290
+ this.splitIntoRows(coords);
291
+ }
292
+ /**
293
+ * 分裂成多列
294
+ * @param coords 单元格坐标
295
+ */
296
+ splitIntoCols(coords) {
297
+ require('../../addon/table');
298
+ this.splitIntoCols(coords);
299
+ }
300
+ /**
301
+ * 分裂成单元格
302
+ * @param coords 单元格坐标
303
+ */
304
+ splitIntoCells(coords) {
305
+ require('../../addon/table');
306
+ this.splitIntoCells(coords);
307
+ }
308
+ /**
309
+ * 复制一行并插入该行之前
310
+ * @param row 行号
311
+ */
312
+ replicateTableRow(row) {
313
+ require('../../addon/table');
314
+ return this.replicateTableRow(row);
315
+ }
316
+ /**
317
+ * 复制一列并插入该列之前
318
+ * @param x 列号
319
+ */
320
+ replicateTableCol(x) {
321
+ require('../../addon/table');
322
+ return this.replicateTableCol(x);
323
+ }
324
+ /**
325
+ * 移动表格行
326
+ * @param y 行号
327
+ * @param before 新位置
328
+ * @throws `RangeError` 无法移动
329
+ */
330
+ moveTableRowBefore(y, before) {
331
+ require('../../addon/table');
332
+ return this.moveTableRowBefore(y, before);
333
+ }
334
+ /**
335
+ * 移动表格行
336
+ * @param y 行号
337
+ * @param after 新位置
338
+ * @throws `RangeError` 无法移动
339
+ */
340
+ moveTableRowAfter(y, after) {
341
+ require('../../addon/table');
342
+ return this.moveTableRowAfter(y, after);
343
+ }
344
+ /**
345
+ * 移动表格列
346
+ * @param x 列号
347
+ * @param before 新位置
348
+ */
349
+ moveTableColBefore(x, before) {
350
+ require('../../addon/table');
351
+ this.moveTableColBefore(x, before);
352
+ }
353
+ /**
354
+ * 移动表格列
355
+ * @param x 列号
356
+ * @param after 新位置
357
+ */
358
+ moveTableColAfter(x, after) {
359
+ require('../../addon/table');
360
+ this.moveTableColAfter(x, after);
361
+ }
362
+ }
363
+ exports.TableToken = TableToken;
364
+ constants_1.classes['TableToken'] = __filename;