wikiparser-node 1.4.1-b → 1.4.1

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