wikiparser-node 1.12.7 → 1.13.0-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 +36 -31
  3. package/config/enwiki.json +23 -830
  4. package/config/llwiki.json +21 -56
  5. package/config/moegirl.json +21 -65
  6. package/config/zhwiki.json +41 -495
  7. package/extensions/dist/base.js +163 -0
  8. package/extensions/dist/codejar.js +53 -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 +32 -25
  15. package/config/.schema.json +0 -203
  16. package/dist/addon/table.js +0 -494
  17. package/dist/addon/token.js +0 -392
  18. package/dist/addon/transclude.js +0 -184
  19. package/dist/base.d.ts +0 -82
  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 -377
  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 -55
  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 -49
  68. package/dist/src/arg.js +0 -220
  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 -482
  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 -153
  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 -51
  84. package/dist/src/gallery.js +0 -166
  85. package/dist/src/heading.d.ts +0 -44
  86. package/dist/src/heading.js +0 -222
  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 -790
  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 -345
  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 -229
  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 -146
  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,494 +0,0 @@
1
- "use strict";
2
- /* eslint @stylistic/operator-linebreak: [2, "before", {overrides: {"=": "after"}}] */
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const assert = require("assert/strict");
5
- const debug_1 = require("../util/debug");
6
- const constants_1 = require("../util/constants");
7
- const index_1 = require("../src/index");
8
- const tr_1 = require("../src/table/tr");
9
- const index_2 = require("../src/table/index");
10
- const td_1 = require("../src/table/td");
11
- const trBase_1 = require("../src/table/trBase");
12
- /**
13
- * 检查坐标形式
14
- * @param coords 坐标
15
- */
16
- const isTableCoords = (coords) => coords.x === undefined;
17
- /**
18
- * 比较两个表格坐标
19
- * @param coords1 坐标1
20
- * @param coords2 坐标2
21
- */
22
- const cmpCoords = (coords1, coords2) => {
23
- const diff = coords1.row - coords2.row;
24
- return diff === 0 ? coords1.column - coords2.column : diff;
25
- };
26
- /**
27
- * 是否是合并单元格的第一列
28
- * @param rowLayout 行布局
29
- * @param i 单元格序号
30
- * @param oneCol 是否仅有一列
31
- */
32
- const isStartCol = (rowLayout, i, oneCol) => {
33
- const coords = rowLayout[i];
34
- return rowLayout[i - 1] !== coords && (!oneCol || rowLayout[i + 1] !== coords);
35
- };
36
- /**
37
- * 起点位于第`i`行的单元格序号
38
- * @param layout 表格布局
39
- * @param i 行号
40
- * @param oneRow 是否要求单元格跨行数为1
41
- * @param cells 改行全部单元格
42
- * @throws `RangeError` 表格布局不包含第`i`行
43
- */
44
- const occupied = (layout, i, oneRow, cells) => {
45
- const rowLayout = layout[i];
46
- if (rowLayout) {
47
- return rowLayout.map(({ row, column }, j) => row === i && (!oneRow || cells[column]?.rowspan === 1) ? j : undefined).filter((j) => j !== undefined);
48
- }
49
- throw new RangeError(`The table layout does not contain row ${i}!`);
50
- };
51
- /**
52
- * 设置表格格式
53
- * @param cells 单元格
54
- * @param attr 属性
55
- * @param multi 是否对所有单元格设置,或是仅对行首单元格设置
56
- */
57
- const format = (cells, attr = {}, multi) => {
58
- for (const [token, start] of cells) {
59
- if (multi || start) {
60
- if (typeof attr === 'string') {
61
- token.setSyntax(attr);
62
- }
63
- else {
64
- token.setAttr(attr);
65
- }
66
- }
67
- }
68
- };
69
- /**
70
- * 填补缺失单元格
71
- * @param y 行号
72
- * @param rowToken 表格行
73
- * @param layout 表格布局
74
- * @param maxCol 最大列数
75
- * @param token 待填充的单元格
76
- */
77
- const fill = (y, rowToken, layout, maxCol, token) => {
78
- const rowLayout = layout[y], childNodes = [...rowToken.childNodes].reverse(), index = childNodes.findIndex(child => child instanceof td_1.TdToken && child.subtype !== 'caption'), pos = index > 0 ? childNodes.length - index : undefined;
79
- debug_1.Shadow.run(() => {
80
- for (let i = 0; i < maxCol; i++) {
81
- if (!rowLayout[i]) {
82
- rowToken.insertAt(token.cloneNode(), pos);
83
- }
84
- }
85
- });
86
- };
87
- index_2.TableToken.prototype.printLayout =
88
- /** @implements */
89
- function () {
90
- this.getLayout().print();
91
- };
92
- index_2.TableToken.prototype.toRenderedCoords =
93
- /** @implements */
94
- function ({ row, column }) {
95
- const rowLayout = this.getLayout({ row, column })[row], x = rowLayout?.findIndex(coords => cmpCoords(coords, { row, column }) === 0);
96
- return rowLayout && (x === -1 ? undefined : { y: row, x: x });
97
- };
98
- index_2.TableToken.prototype.toRawCoords =
99
- /** @implements */
100
- function ({ x, y }) {
101
- const rowLayout = this.getLayout({ x, y })[y], coords = rowLayout?.[x];
102
- if (coords) {
103
- return { ...coords, start: coords.row === y && rowLayout[x - 1] !== coords };
104
- }
105
- else if (rowLayout || y > 0) {
106
- return x === rowLayout?.length
107
- ? { row: y, column: (rowLayout.reverse().find(({ row }) => row === y)?.column ?? -1) + 1, start: true }
108
- : undefined;
109
- }
110
- return { row: 0, column: 0, start: true };
111
- };
112
- index_2.TableToken.prototype.getFullRow =
113
- /** @implements */
114
- function (y) {
115
- const rows = this.getAllRows();
116
- return new Map(this.getLayout({ y })[y]?.map(({ row, column }) => [rows[row].getNthCol(column), row === y]));
117
- };
118
- index_2.TableToken.prototype.getFullCol =
119
- /** @implements */
120
- function (x) {
121
- const layout = this.getLayout(), colLayout = layout.map(row => row[x]).filter(Boolean), rows = this.getAllRows();
122
- return new Map(colLayout.map(coords => [rows[coords.row].getNthCol(coords.column), layout[coords.row][x - 1] !== coords]));
123
- };
124
- index_2.TableToken.prototype.formatTableRow =
125
- /** @implements */
126
- function (y, attr, multiRow) {
127
- format(this.getFullRow(y), attr, multiRow);
128
- };
129
- index_2.TableToken.prototype.formatTableCol =
130
- /** @implements */
131
- function (x, attr, multiCol) {
132
- format(this.getFullCol(x), attr, multiCol);
133
- };
134
- index_2.TableToken.prototype.fillTableRow =
135
- /** @implements */
136
- function (y, inner, subtype, attr) {
137
- const rowToken = this.getNthRow(y), layout = this.getLayout({ y }), maxCol = Math.max(...layout.map(({ length }) => length)), token = (0, td_1.createTd)(inner, subtype, attr, this.getAttribute('include'), this.getAttribute('config'));
138
- fill(y, rowToken, layout, maxCol, token);
139
- };
140
- index_2.TableToken.prototype.fillTable =
141
- /** @implements */
142
- function (inner, subtype, attr) {
143
- const rowTokens = this.getAllRows(), layout = this.getLayout(), maxCol = Math.max(...layout.map(({ length }) => length)), token = (0, td_1.createTd)(inner, subtype, attr, this.getAttribute('include'), this.getAttribute('config'));
144
- for (let y = 0; y < rowTokens.length; y++) {
145
- fill(y, rowTokens[y], layout, maxCol, token);
146
- }
147
- };
148
- index_2.TableToken.prototype.insertTableCell =
149
- /** @implements */
150
- function (inner, coords, subtype, attr) {
151
- let rawCoords;
152
- if (coords.column === undefined) {
153
- const { x, y } = coords;
154
- rawCoords = this.toRawCoords(coords);
155
- if (!rawCoords?.start) {
156
- throw new RangeError(`The specified coordinates are not the starting point of any cell: (${x}, ${y})`);
157
- }
158
- }
159
- else {
160
- rawCoords = coords;
161
- }
162
- const rowToken = this.getNthRow(rawCoords.row, true);
163
- return rowToken === this
164
- ? trBase_1.TrBaseToken.prototype.insertTableCell.call(this, inner, rawCoords, subtype, attr)
165
- : rowToken.insertTableCell(inner, rawCoords, subtype, attr);
166
- };
167
- index_2.TableToken.prototype.prependTableRow =
168
- /** @implements */
169
- function () {
170
- // @ts-expect-error abstract class
171
- const row = debug_1.Shadow.run(() => new tr_1.TrToken('\n|-', undefined, this.getAttribute('config'))), { childNodes } = this, [, , plain] = childNodes, start = plain?.constructor === index_1.Token ? 3 : 2, tdChildren = childNodes.slice(start), index = tdChildren.findIndex(({ type }) => type !== 'td');
172
- this.insertAt(row, index === -1 ? -1 : index + start);
173
- debug_1.Shadow.run(() => {
174
- for (const cell of tdChildren.slice(0, index === -1 ? undefined : index)) {
175
- if (cell.subtype !== 'caption') {
176
- row.insertAt(cell);
177
- }
178
- }
179
- });
180
- return row;
181
- };
182
- index_2.TableToken.prototype.insertTableRow =
183
- /** @implements */
184
- function (y, attr = {}, inner, subtype = 'td', innerAttr = {}) {
185
- let reference = this.getNthRow(y, false, true);
186
- // @ts-expect-error abstract class
187
- const token = debug_1.Shadow.run(() => new tr_1.TrToken('\n|-', undefined, this.getAttribute('config')));
188
- token.setAttr(attr);
189
- if (reference?.type === 'table') { // `row === 0`且表格自身是有效行
190
- reference = this.prependTableRow();
191
- }
192
- this.insertBefore(token, reference);
193
- if (inner !== undefined) {
194
- const td = token.insertTableCell(inner, { row: 0, column: 0 }, subtype, innerAttr), set = new WeakSet(), layout = this.getLayout({ y }), maxCol = Math.max(...layout.map(({ length }) => length)), rowLayout = layout[y];
195
- debug_1.Shadow.run(() => {
196
- for (let i = 0; i < maxCol; i++) {
197
- const coords = rowLayout[i];
198
- if (!coords) {
199
- token.insertAt(td.cloneNode());
200
- }
201
- else if (!set.has(coords)) {
202
- set.add(coords);
203
- if (coords.row < y) {
204
- this.getNthCell(coords).rowspan++;
205
- }
206
- }
207
- }
208
- });
209
- }
210
- return token;
211
- };
212
- index_2.TableToken.prototype.insertTableCol =
213
- /** @implements */
214
- function (x, inner, subtype, attr) {
215
- const layout = this.getLayout(), rowLength = layout.map(({ length }) => length), minCol = Math.min(...rowLength);
216
- if (x > minCol) {
217
- throw new RangeError(`Row ${rowLength.indexOf(minCol)} has only ${minCol} column(s)!`);
218
- }
219
- const token = (0, td_1.createTd)(inner, subtype, attr, this.getAttribute('include'), this.getAttribute('config'));
220
- for (const [i, rowLayout] of layout.entries()) {
221
- const coords = rowLayout[x], prevCoords = x === 0 ? true : rowLayout[x - 1];
222
- if (!prevCoords) {
223
- continue;
224
- }
225
- else if (prevCoords !== coords) {
226
- const rowToken = this.getNthRow(i);
227
- rowToken.insertBefore(token.cloneNode(), rowToken.getNthCol(coords.column, true));
228
- }
229
- else if (coords.row === i) {
230
- this.getNthCell(coords).colspan++;
231
- }
232
- }
233
- };
234
- index_2.TableToken.prototype.removeTableRow =
235
- /** @implements */
236
- function (y) {
237
- const rows = this.getAllRows(), layout = this.getLayout(), rowLayout = layout[y], set = new WeakSet();
238
- for (let x = rowLayout.length - 1; x >= 0; x--) {
239
- const coords = rowLayout[x];
240
- if (set.has(coords)) {
241
- continue;
242
- }
243
- set.add(coords);
244
- const token = rows[coords.row].getNthCol(coords.column);
245
- let { rowspan } = token;
246
- if (rowspan > 1) {
247
- token.rowspan = --rowspan;
248
- if (coords.row === y) {
249
- const { colspan, subtype } = token, attr = token.getAttrs();
250
- for (let i = y + 1; rowspan && i < rows.length; i++, rowspan--) {
251
- const { column } = layout[i].slice(x + colspan).find(({ row }) => row === i) ?? {};
252
- if (column !== undefined) {
253
- rows[i].insertTableCell('', { row: 0, column }, subtype, { ...attr, rowspan });
254
- break;
255
- }
256
- }
257
- }
258
- }
259
- }
260
- const row = rows[y], rowToken = row.type === 'tr' ? row : this.prependTableRow();
261
- rowToken.remove();
262
- return rowToken;
263
- };
264
- index_2.TableToken.prototype.removeTableCol =
265
- /** @implements */
266
- function (x) {
267
- for (const [token, start] of this.getFullCol(x)) {
268
- const { colspan, lastChild } = token;
269
- if (colspan > 1) {
270
- token.colspan = colspan - 1;
271
- if (start) {
272
- lastChild.replaceChildren();
273
- }
274
- }
275
- else {
276
- token.remove();
277
- }
278
- }
279
- };
280
- index_2.TableToken.prototype.mergeCells =
281
- /** @implements */
282
- function (xlim, ylim) {
283
- const layout = this.getLayout(), maxCol = Math.max(...layout.map(({ length }) => length)), [xmin, xmax] = xlim.map(x => x < 0 ? x + maxCol : x).sort(), [ymin, ymax] = ylim.map(y => y < 0 ? y + layout.length : y).sort(), set = new Set(layout.slice(ymin, ymax).flatMap(rowLayout => rowLayout.slice(xmin, xmax)));
284
- if ([...layout[ymin - 1] ?? [], ...layout[ymax] ?? []].some(coords => set.has(coords))
285
- || layout.some(rowLayout => set.has(rowLayout[xmin - 1]) || set.has(rowLayout[xmax]))) {
286
- throw new RangeError('The area to be merged overlaps with the outer area!');
287
- }
288
- const corner = layout[ymin][xmin], rows = this.getAllRows(), cornerCell = rows[corner.row].getNthCol(corner.column);
289
- cornerCell.rowspan = ymax - ymin;
290
- cornerCell.colspan = xmax - xmin;
291
- set.delete(corner);
292
- for (const token of [...set].map(({ row, column }) => rows[row].getNthCol(column))) {
293
- token.remove();
294
- }
295
- return cornerCell;
296
- };
297
- index_2.TableToken.prototype.split =
298
- /** @implements */
299
- function (coords, dirs) {
300
- const cell = this.getNthCell(coords), attr = cell.getAttrs(), { subtype } = cell;
301
- attr.rowspan ||= 1;
302
- attr.colspan ||= 1;
303
- for (const dir of dirs) {
304
- if (attr[dir] === 1) {
305
- dirs.delete(dir);
306
- }
307
- }
308
- if (dirs.size === 0) {
309
- return;
310
- }
311
- let { x, y } = coords;
312
- const rawCoords = isTableCoords(coords) ? coords : this.toRawCoords(coords);
313
- if (rawCoords.start === false || x === undefined) {
314
- ({ x, y } = this.toRenderedCoords(rawCoords));
315
- }
316
- const splitting = { rowspan: 1, colspan: 1 };
317
- for (const dir of dirs) {
318
- cell.setAttr(dir, 1);
319
- splitting[dir] = attr[dir];
320
- delete attr[dir];
321
- }
322
- for (let j = y; j < y + splitting.rowspan; j++) {
323
- for (let i = x; i < x + splitting.colspan; i++) {
324
- if (i > x || j > y) {
325
- try {
326
- this.insertTableCell('', { x: i, y: j }, subtype, attr);
327
- }
328
- catch (e) {
329
- if (e instanceof RangeError
330
- && e.message.startsWith('The specified coordinates are not the starting point of a cell: ')) {
331
- break;
332
- }
333
- throw e;
334
- }
335
- }
336
- }
337
- }
338
- };
339
- index_2.TableToken.prototype.splitIntoRows =
340
- /** @implements */
341
- function (coords) {
342
- this.split(coords, new Set(['rowspan']));
343
- };
344
- index_2.TableToken.prototype.splitIntoCols =
345
- /** @implements */
346
- function (coords) {
347
- this.split(coords, new Set(['colspan']));
348
- };
349
- index_2.TableToken.prototype.splitIntoCells =
350
- /** @implements */
351
- function (coords) {
352
- this.split(coords, new Set(['rowspan', 'colspan']));
353
- };
354
- index_2.TableToken.prototype.replicateTableRow =
355
- /** @implements */
356
- function (row) {
357
- let rowToken = this.getNthRow(row);
358
- if (rowToken.type === 'table') {
359
- rowToken = this.prependTableRow();
360
- }
361
- const replicated = this.insertBefore(rowToken.cloneNode(), rowToken);
362
- for (const [token, start] of this.getFullRow(row)) {
363
- if (start) {
364
- token.rowspan = 1;
365
- }
366
- else {
367
- token.rowspan++;
368
- }
369
- }
370
- return replicated;
371
- };
372
- index_2.TableToken.prototype.replicateTableCol =
373
- /** @implements */
374
- function (x) {
375
- const replicated = [];
376
- for (const [token, start] of this.getFullCol(x)) {
377
- if (start) {
378
- const newToken = token.cloneNode();
379
- newToken.colspan = 1;
380
- token.before(newToken);
381
- replicated.push(newToken);
382
- }
383
- else {
384
- token.colspan++;
385
- }
386
- }
387
- return replicated;
388
- };
389
- index_2.TableToken.prototype.moveTableRowBefore =
390
- /** @implements */
391
- function (y, before) {
392
- const layout = this.getLayout();
393
- try {
394
- assert.deepEqual(occupied(layout, y), occupied(layout, before));
395
- }
396
- catch (e) {
397
- if (e instanceof assert.AssertionError) {
398
- throw new RangeError(`The structure of row ${y} is different from that of row ${before}, so it cannot be moved!`);
399
- }
400
- throw e;
401
- }
402
- const rowToken = this.removeTableRow(y);
403
- for (const coords of layout[before]) {
404
- if (coords.row < before) {
405
- this.getNthCell(coords).rowspan++;
406
- }
407
- }
408
- let beforeToken = this.getNthRow(before);
409
- if (beforeToken.type === 'table') {
410
- beforeToken = this.prependTableRow();
411
- }
412
- this.insertBefore(rowToken, beforeToken);
413
- return rowToken;
414
- };
415
- index_2.TableToken.prototype.moveTableRowAfter =
416
- /** @implements */
417
- function (y, after) {
418
- const layout = this.getLayout(), afterToken = this.getNthRow(after), cells = afterToken.childNodes.filter(child => child.type === 'td' && child.subtype !== 'caption');
419
- try {
420
- assert.deepEqual(occupied(layout, y), occupied(layout, after, true, cells));
421
- }
422
- catch (e) {
423
- if (e instanceof assert.AssertionError) {
424
- throw new RangeError(`The structure of row ${y} is different from that of row ${after}, so it cannot be moved!`);
425
- }
426
- throw e;
427
- }
428
- const rowToken = this.removeTableRow(y);
429
- for (const coords of layout[after]) {
430
- if (coords.row < after) {
431
- this.getNthCell(coords).rowspan++;
432
- }
433
- else {
434
- const cell = cells[coords.column], { rowspan } = cell;
435
- if (rowspan > 1) {
436
- cell.rowspan = rowspan + 1;
437
- }
438
- }
439
- }
440
- if (afterToken === this) {
441
- const index = this.childNodes.slice(2).findIndex(index_2.isRowEnd);
442
- this.insertAt(rowToken, index + 2);
443
- }
444
- else {
445
- this.insertBefore(rowToken, afterToken);
446
- }
447
- return rowToken;
448
- };
449
- index_2.TableToken.prototype.moveCol =
450
- /** @implements */
451
- function (x, reference, after) {
452
- const layout = this.getLayout();
453
- if (layout.some(rowLayout => isStartCol(rowLayout, x) !== isStartCol(rowLayout, reference, after))) {
454
- throw new RangeError(`The structure of column ${x} is different from that of column ${reference}, so it cannot be moved!`);
455
- }
456
- const setX = new WeakSet(), setRef = new WeakSet(), rows = this.getAllRows();
457
- for (const [i, rowLayout] of layout.entries()) {
458
- const coords = rowLayout[x], refCoords = rowLayout[reference], start = isStartCol(rowLayout, x);
459
- if (refCoords && !start && !setRef.has(refCoords)) {
460
- setRef.add(refCoords);
461
- rows[refCoords.row].getNthCol(refCoords.column).colspan++;
462
- }
463
- if (coords && !setX.has(coords)) {
464
- setX.add(coords);
465
- const rowToken = rows[i];
466
- let token = rowToken.getNthCol(coords.column);
467
- const { colspan } = token;
468
- if (colspan > 1) {
469
- token.colspan = colspan - 1;
470
- if (start) {
471
- const original = token;
472
- token = token.cloneNode();
473
- original.lastChild.replaceChildren();
474
- token.colspan = 1;
475
- }
476
- }
477
- if (start) {
478
- const col = rowLayout.slice(reference + Number(after)).find(({ row }) => row === i)?.column;
479
- rowToken.insertBefore(token, col === undefined ? rowToken.childNodes.slice(2).find(index_2.isRowEnd) : rowToken.getNthCol(col));
480
- }
481
- }
482
- }
483
- };
484
- index_2.TableToken.prototype.moveTableColBefore =
485
- /** @implements */
486
- function (x, before) {
487
- this.moveCol(x, before);
488
- };
489
- index_2.TableToken.prototype.moveTableColAfter =
490
- /** @implements */
491
- function (x, after) {
492
- this.moveCol(x, after, true);
493
- };
494
- constants_1.classes['ExtendedTableToken'] = __filename;