wikiparser-node 1.4.2-b → 1.4.2

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 +211 -0
  11. package/dist/internal.d.ts +44 -0
  12. package/dist/lib/element.d.ts +154 -0
  13. package/dist/lib/element.js +643 -0
  14. package/dist/lib/node.d.ts +146 -0
  15. package/dist/lib/node.js +425 -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 +306 -0
  22. package/dist/lib/title.d.ts +38 -0
  23. package/dist/lib/title.js +172 -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 +72 -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 +43 -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 +41 -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 +97 -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 +196 -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 +422 -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 +85 -0
  62. package/dist/src/converterFlags.d.ts +87 -0
  63. package/dist/src/converterFlags.js +227 -0
  64. package/dist/src/converterRule.d.ts +77 -0
  65. package/dist/src/converterRule.js +210 -0
  66. package/dist/src/extLink.d.ts +38 -0
  67. package/dist/src/extLink.js +137 -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 +143 -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 +286 -0
  76. package/dist/src/imageParameter.d.ts +65 -0
  77. package/dist/src/imageParameter.js +247 -0
  78. package/dist/src/imagemap.d.ts +56 -0
  79. package/dist/src/imagemap.js +156 -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 +804 -0
  84. package/dist/src/link/base.d.ts +52 -0
  85. package/dist/src/link/base.js +212 -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 +266 -0
  90. package/dist/src/link/galleryImage.d.ts +31 -0
  91. package/dist/src/link/galleryImage.js +109 -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 +149 -0
  96. package/dist/src/nested.d.ts +43 -0
  97. package/dist/src/nested.js +91 -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 +77 -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 +51 -0
  106. package/dist/src/nowiki/hr.d.ts +8 -0
  107. package/dist/src/nowiki/hr.js +14 -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 +48 -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 +213 -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 +35 -0
  130. package/dist/src/table/base.d.ts +27 -0
  131. package/dist/src/table/base.js +81 -0
  132. package/dist/src/table/index.d.ts +230 -0
  133. package/dist/src/table/index.js +390 -0
  134. package/dist/src/table/td.d.ts +88 -0
  135. package/dist/src/table/td.js +284 -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 +153 -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 +79 -0
  146. package/dist/src/transclude.d.ts +167 -0
  147. package/dist/src/transclude.js +715 -0
  148. package/dist/util/constants.js +113 -0
  149. package/dist/util/debug.js +90 -0
  150. package/dist/util/diff.js +82 -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 +15 -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 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,390 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TableToken = void 0;
4
+ const lint_1 = require("../../util/lint");
5
+ const debug_1 = require("../../util/debug");
6
+ const string_1 = require("../../util/string");
7
+ const constants_1 = require("../../util/constants");
8
+ const index_1 = require("../../index");
9
+ const trBase_1 = require("./trBase");
10
+ const syntax_1 = require("../syntax");
11
+ /* NOT FOR BROWSER END */
12
+ const closingPattern = /^\n[^\S\n]*(?:\|\}|\{\{\s*!\s*\}\}\}|\{\{\s*!\)\s*\}\})$/u;
13
+ /**
14
+ * 表格
15
+ * @classdesc `{childNodes: [SyntaxToken, AttributesToken, ?Token, ...TdToken, ...TrToken, ?SyntaxToken]}`
16
+ */
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-value') ? '\n{{!}}}' : '\n|}');
27
+ }
28
+ }
29
+ /* NOT FOR BROWSER END */
30
+ /**
31
+ * @param syntax 表格语法
32
+ * @param attr 表格属性
33
+ */
34
+ constructor(syntax, attr, config = index_1.default.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
+ errors.push((0, lint_1.generateForChild)(this.firstChild, { start }, index_1.default.msg('unclosed $1', 'table')));
44
+ }
45
+ return errors;
46
+ }
47
+ /**
48
+ * 闭合表格语法
49
+ * @param syntax 表格结尾语法
50
+ * @param halfParsed
51
+ */
52
+ close(syntax = '\n|}', halfParsed = false) {
53
+ const config = this.getAttribute('config'), accum = this.getAttribute('accum'), inner = halfParsed ? [syntax] : index_1.default.parse(syntax, this.getAttribute('include'), 2, config).childNodes;
54
+ /* NOT FOR BROWSER */
55
+ if (this.lastChild.type !== 'table-syntax') {
56
+ /* NOT FOR BROWSER END */
57
+ const token = debug_1.Shadow.run(() => super.insertAt(new syntax_1.SyntaxToken(undefined, closingPattern, 'table-syntax', config, accum, {
58
+ 'Stage-1': ':', '!ExtToken': '', TranscludeToken: ':',
59
+ })));
60
+ /* NOT FOR BROWSER */
61
+ if (!halfParsed) {
62
+ token.afterBuild();
63
+ }
64
+ /* NOT FOR BROWSER END */
65
+ }
66
+ this.lastChild.replaceChildren(...inner);
67
+ }
68
+ /** @override */
69
+ json() {
70
+ return {
71
+ ...super.json(),
72
+ closed: this.closed,
73
+ };
74
+ }
75
+ /* NOT FOR BROWSER */
76
+ /**
77
+ * @override
78
+ * @param token 待插入的子节点
79
+ * @param i 插入位置
80
+ * @throws `SyntaxError` 表格的闭合部分非法
81
+ */
82
+ insertAt(token, i = this.length) {
83
+ i += i < 0 ? this.length : 0;
84
+ const previous = this.childNodes[i - 1];
85
+ if (typeof token !== 'string' && token.type === 'td' && previous?.type === 'tr') {
86
+ index_1.default.warn('改为将单元格插入当前行。');
87
+ return previous.insertAt(token);
88
+ }
89
+ else if (i > 0 && token instanceof syntax_1.SyntaxToken && token.getAttribute('pattern') !== closingPattern) {
90
+ throw new SyntaxError(`表格的闭合部分不符合语法:${(0, string_1.noWrap)(String(token))}`);
91
+ }
92
+ return super.insertAt(token, i);
93
+ }
94
+ /** @override */
95
+ getRowCount() {
96
+ return super.getRowCount() + this.childNodes.filter(child => child.type === 'tr' && child.getRowCount()).length;
97
+ }
98
+ /** 获取下一行 */
99
+ getNextRow() {
100
+ return this.getNthRow(super.getRowCount() ? 1 : 0, false, false);
101
+ }
102
+ getNthRow(n, force = false, insert = false) {
103
+ const nRows = this.getRowCount(), isRow = super.getRowCount();
104
+ n += n < 0 ? nRows : 0;
105
+ if (n === 0 && (isRow || force && nRows === 0)) {
106
+ return this;
107
+ }
108
+ else if (n < 0 || n > nRows || n === nRows && !insert) {
109
+ throw new RangeError(`不存在第 ${n} 行!`);
110
+ }
111
+ else if (isRow) {
112
+ n--;
113
+ }
114
+ for (const child of this.childNodes.slice(2)) {
115
+ if (child.type === 'tr' && child.getRowCount()) {
116
+ n--;
117
+ if (n < 0) {
118
+ return child;
119
+ }
120
+ }
121
+ else if (child.type === 'table-syntax') {
122
+ return child;
123
+ }
124
+ }
125
+ return undefined;
126
+ }
127
+ /** 获取所有行 */
128
+ getAllRows() {
129
+ return [
130
+ ...super.getRowCount() ? [this] : [],
131
+ ...this.childNodes.slice(1)
132
+ .filter((child) => child.type === 'tr' && child.getRowCount() > 0),
133
+ ];
134
+ }
135
+ /**
136
+ * 获取指定坐标的单元格
137
+ * @param coords 表格坐标
138
+ */
139
+ getNthCell(coords) {
140
+ require('../../addon/table');
141
+ return this.getNthCell(coords);
142
+ }
143
+ /**
144
+ * 获取表格布局
145
+ * @param stop 中止条件
146
+ * @param stop.row 中止行
147
+ * @param stop.column 中止列
148
+ * @param stop.x 中止行
149
+ * @param stop.y 中止列
150
+ */
151
+ getLayout(stop) {
152
+ require('../../addon/table');
153
+ return this.getLayout(stop);
154
+ }
155
+ /** 打印表格布局 */
156
+ printLayout() {
157
+ require('../../addon/table');
158
+ this.printLayout();
159
+ }
160
+ /**
161
+ * 转换为渲染后的表格坐标
162
+ * @param {TableCoords} coord wikitext中的表格坐标
163
+ */
164
+ toRenderedCoords(coord) {
165
+ require('../../addon/table');
166
+ return this.toRenderedCoords(coord);
167
+ }
168
+ /**
169
+ * 转换为wikitext中的表格坐标
170
+ * @param {TableRenderedCoords} coord 渲染后的表格坐标
171
+ */
172
+ toRawCoords(coord) {
173
+ require('../../addon/table');
174
+ return this.toRawCoords(coord);
175
+ }
176
+ /**
177
+ * 获取完整行
178
+ * @param y 行号
179
+ */
180
+ getFullRow(y) {
181
+ require('../../addon/table');
182
+ return this.getFullRow(y);
183
+ }
184
+ /**
185
+ * 获取完整列
186
+ * @param x 列号
187
+ */
188
+ getFullCol(x) {
189
+ require('../../addon/table');
190
+ return this.getFullCol(x);
191
+ }
192
+ /**
193
+ * 设置行格式
194
+ * @param y 行号
195
+ * @param attr 表格属性
196
+ * @param multiRow 是否对所有单元格设置,或是仅对行首单元格设置
197
+ */
198
+ formatTableRow(y, attr = {}, multiRow = false) {
199
+ require('../../addon/table');
200
+ this.formatTableRow(y, attr, multiRow);
201
+ }
202
+ /**
203
+ * 设置列格式
204
+ * @param x 列号
205
+ * @param attr 表格属性
206
+ * @param multiCol 是否对所有单元格设置,或是仅对行首单元格设置
207
+ */
208
+ formatTableCol(x, attr = {}, multiCol = false) {
209
+ require('../../addon/table');
210
+ this.formatTableCol(x, attr, multiCol);
211
+ }
212
+ /**
213
+ * 填补表格行
214
+ * @param y 行号
215
+ * @param inner 填充内容
216
+ * @param subtype 单元格类型
217
+ * @param attr 表格属性
218
+ */
219
+ fillTableRow(y, inner, subtype = 'td', attr = {}) {
220
+ require('../../addon/table');
221
+ this.fillTableRow(y, inner, subtype, attr);
222
+ }
223
+ /**
224
+ * 填补表格
225
+ * @param inner 填充内容
226
+ * @param subtype 单元格类型
227
+ * @param attr 表格属性
228
+ */
229
+ fillTable(inner, subtype = 'td', attr = {}) {
230
+ require('../../addon/table');
231
+ this.fillTable(inner, subtype, attr);
232
+ }
233
+ /**
234
+ * @override
235
+ * @param inner 单元格内部wikitext
236
+ * @param coords 单元格坐标
237
+ * @param subtype 单元格类型
238
+ * @param attr 单元格属性
239
+ * @throws `RangeError` 指定的坐标不是单元格起始点
240
+ */
241
+ insertTableCell(inner, coords, subtype = 'td', attr = {}) {
242
+ require('../../addon/table');
243
+ return this.insertTableCell(inner, coords, subtype, attr);
244
+ }
245
+ /** @private */
246
+ prependTableRow() {
247
+ require('../../addon/table');
248
+ return this.prependTableRow();
249
+ }
250
+ /**
251
+ * 插入表格行
252
+ * @param y 行号
253
+ * @param attr 表格行属性
254
+ * @param inner 内部wikitext
255
+ * @param subtype 单元格类型
256
+ * @param innerAttr 单元格属性
257
+ */
258
+ insertTableRow(y, attr = {}, inner, subtype = 'td', innerAttr = {}) {
259
+ require('../../addon/table');
260
+ return this.insertTableRow(y, attr, inner, subtype, innerAttr);
261
+ }
262
+ /**
263
+ * 插入表格列
264
+ * @param x 列号
265
+ * @param inner 内部wikitext
266
+ * @param subtype 单元格类型
267
+ * @param attr 单元格属性
268
+ * @throws `RangeError` 列号过大
269
+ */
270
+ insertTableCol(x, inner, subtype = 'td', attr = {}) {
271
+ require('../../addon/table');
272
+ this.insertTableCol(x, inner, subtype, attr);
273
+ }
274
+ /**
275
+ * 移除表格行
276
+ * @param y 行号
277
+ */
278
+ removeTableRow(y) {
279
+ require('../../addon/table');
280
+ return this.removeTableRow(y);
281
+ }
282
+ /**
283
+ * 移除表格列
284
+ * @param x 列号
285
+ */
286
+ removeTableCol(x) {
287
+ require('../../addon/table');
288
+ this.removeTableCol(x);
289
+ }
290
+ /**
291
+ * 合并单元格
292
+ * @param xlim 列范围
293
+ * @param ylim 行范围
294
+ * @throws `RangeError` 待合并区域与外侧区域有重叠
295
+ */
296
+ mergeCells(xlim, ylim) {
297
+ require('../../addon/table');
298
+ return this.mergeCells(xlim, ylim);
299
+ }
300
+ /** @private */
301
+ split(coords, dirs) {
302
+ require('../../addon/table');
303
+ this.split(coords, dirs);
304
+ }
305
+ /**
306
+ * 分裂成多行
307
+ * @param coords 单元格坐标
308
+ */
309
+ splitIntoRows(coords) {
310
+ require('../../addon/table');
311
+ this.splitIntoRows(coords);
312
+ }
313
+ /**
314
+ * 分裂成多列
315
+ * @param coords 单元格坐标
316
+ */
317
+ splitIntoCols(coords) {
318
+ require('../../addon/table');
319
+ this.splitIntoCols(coords);
320
+ }
321
+ /**
322
+ * 分裂成单元格
323
+ * @param coords 单元格坐标
324
+ */
325
+ splitIntoCells(coords) {
326
+ require('../../addon/table');
327
+ this.splitIntoCells(coords);
328
+ }
329
+ /**
330
+ * 复制一行并插入该行之前
331
+ * @param row 行号
332
+ */
333
+ replicateTableRow(row) {
334
+ require('../../addon/table');
335
+ return this.replicateTableRow(row);
336
+ }
337
+ /**
338
+ * 复制一列并插入该列之前
339
+ * @param x 列号
340
+ */
341
+ replicateTableCol(x) {
342
+ require('../../addon/table');
343
+ return this.replicateTableCol(x);
344
+ }
345
+ /** @private */
346
+ moveCol(x, reference, after) {
347
+ require('../../addon/table');
348
+ this.moveCol(x, reference, after);
349
+ }
350
+ /**
351
+ * 移动表格行
352
+ * @param y 行号
353
+ * @param before 新位置
354
+ * @throws `RangeError` 无法移动
355
+ */
356
+ moveTableRowBefore(y, before) {
357
+ require('../../addon/table');
358
+ return this.moveTableRowBefore(y, before);
359
+ }
360
+ /**
361
+ * 移动表格行
362
+ * @param y 行号
363
+ * @param after 新位置
364
+ * @throws `RangeError` 无法移动
365
+ */
366
+ moveTableRowAfter(y, after) {
367
+ require('../../addon/table');
368
+ return this.moveTableRowAfter(y, after);
369
+ }
370
+ /**
371
+ * 移动表格列
372
+ * @param x 列号
373
+ * @param before 新位置
374
+ */
375
+ moveTableColBefore(x, before) {
376
+ require('../../addon/table');
377
+ this.moveTableColBefore(x, before);
378
+ }
379
+ /**
380
+ * 移动表格列
381
+ * @param x 列号
382
+ * @param after 新位置
383
+ */
384
+ moveTableColAfter(x, after) {
385
+ require('../../addon/table');
386
+ this.moveTableColAfter(x, after);
387
+ }
388
+ }
389
+ exports.TableToken = TableToken;
390
+ constants_1.classes['TableToken'] = __filename;
@@ -0,0 +1,88 @@
1
+ import 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 {};