wikiparser-node 1.4.2 → 1.4.3-b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/bundle/bundle.min.js +36 -0
  2. package/config/enwiki.json +1 -814
  3. package/config/llwiki.json +1 -35
  4. package/config/moegirl.json +1 -44
  5. package/config/zhwiki.json +1 -466
  6. package/extensions/dist/base.js +64 -0
  7. package/extensions/dist/editor.js +159 -0
  8. package/extensions/dist/highlight.js +59 -0
  9. package/extensions/dist/lint.js +48 -0
  10. package/extensions/editor.css +63 -0
  11. package/extensions/ui.css +141 -0
  12. package/package.json +30 -15
  13. package/config/.schema.json +0 -172
  14. package/dist/addon/table.d.ts +0 -6
  15. package/dist/addon/table.js +0 -560
  16. package/dist/base.d.ts +0 -53
  17. package/dist/index.d.ts +0 -32
  18. package/dist/index.js +0 -211
  19. package/dist/internal.d.ts +0 -44
  20. package/dist/lib/element.d.ts +0 -154
  21. package/dist/lib/element.js +0 -643
  22. package/dist/lib/node.d.ts +0 -146
  23. package/dist/lib/node.js +0 -425
  24. package/dist/lib/range.d.ts +0 -104
  25. package/dist/lib/range.js +0 -385
  26. package/dist/lib/ranges.d.ts +0 -26
  27. package/dist/lib/ranges.js +0 -118
  28. package/dist/lib/text.d.ts +0 -62
  29. package/dist/lib/text.js +0 -306
  30. package/dist/lib/title.d.ts +0 -38
  31. package/dist/lib/title.js +0 -172
  32. package/dist/mixin/attributesParent.d.ts +0 -20
  33. package/dist/mixin/attributesParent.js +0 -89
  34. package/dist/mixin/fixed.d.ts +0 -5
  35. package/dist/mixin/fixed.js +0 -28
  36. package/dist/mixin/flagsParent.d.ts +0 -61
  37. package/dist/mixin/flagsParent.js +0 -72
  38. package/dist/mixin/hidden.d.ts +0 -5
  39. package/dist/mixin/hidden.js +0 -24
  40. package/dist/mixin/magicLinkParent.d.ts +0 -34
  41. package/dist/mixin/magicLinkParent.js +0 -43
  42. package/dist/mixin/singleLine.d.ts +0 -5
  43. package/dist/mixin/singleLine.js +0 -25
  44. package/dist/mixin/sol.d.ts +0 -8
  45. package/dist/mixin/sol.js +0 -41
  46. package/dist/mixin/syntax.d.ts +0 -6
  47. package/dist/mixin/syntax.js +0 -54
  48. package/dist/parser/braces.js +0 -131
  49. package/dist/parser/commentAndExt.js +0 -90
  50. package/dist/parser/converter.js +0 -41
  51. package/dist/parser/externalLinks.js +0 -32
  52. package/dist/parser/hrAndDoubleUnderscore.js +0 -41
  53. package/dist/parser/html.js +0 -39
  54. package/dist/parser/links.js +0 -97
  55. package/dist/parser/list.js +0 -68
  56. package/dist/parser/magicLinks.js +0 -43
  57. package/dist/parser/quotes.js +0 -68
  58. package/dist/parser/selector.js +0 -162
  59. package/dist/parser/table.js +0 -124
  60. package/dist/src/arg.d.ts +0 -58
  61. package/dist/src/arg.js +0 -196
  62. package/dist/src/atom.d.ts +0 -12
  63. package/dist/src/atom.js +0 -27
  64. package/dist/src/attribute.d.ts +0 -67
  65. package/dist/src/attribute.js +0 -422
  66. package/dist/src/attributes.d.ts +0 -109
  67. package/dist/src/attributes.js +0 -347
  68. package/dist/src/converter.d.ts +0 -28
  69. package/dist/src/converter.js +0 -85
  70. package/dist/src/converterFlags.d.ts +0 -87
  71. package/dist/src/converterFlags.js +0 -227
  72. package/dist/src/converterRule.d.ts +0 -77
  73. package/dist/src/converterRule.js +0 -210
  74. package/dist/src/extLink.d.ts +0 -38
  75. package/dist/src/extLink.js +0 -137
  76. package/dist/src/gallery.d.ts +0 -54
  77. package/dist/src/gallery.js +0 -127
  78. package/dist/src/heading.d.ts +0 -47
  79. package/dist/src/heading.js +0 -143
  80. package/dist/src/hidden.d.ts +0 -7
  81. package/dist/src/hidden.js +0 -23
  82. package/dist/src/html.d.ts +0 -62
  83. package/dist/src/html.js +0 -286
  84. package/dist/src/imageParameter.d.ts +0 -65
  85. package/dist/src/imageParameter.js +0 -247
  86. package/dist/src/imagemap.d.ts +0 -56
  87. package/dist/src/imagemap.js +0 -156
  88. package/dist/src/imagemapLink.d.ts +0 -28
  89. package/dist/src/imagemapLink.js +0 -44
  90. package/dist/src/index.d.ts +0 -143
  91. package/dist/src/index.js +0 -804
  92. package/dist/src/link/base.d.ts +0 -52
  93. package/dist/src/link/base.js +0 -212
  94. package/dist/src/link/category.d.ts +0 -13
  95. package/dist/src/link/category.js +0 -28
  96. package/dist/src/link/file.d.ts +0 -96
  97. package/dist/src/link/file.js +0 -266
  98. package/dist/src/link/galleryImage.d.ts +0 -31
  99. package/dist/src/link/galleryImage.js +0 -109
  100. package/dist/src/link/index.d.ts +0 -56
  101. package/dist/src/link/index.js +0 -134
  102. package/dist/src/magicLink.d.ts +0 -51
  103. package/dist/src/magicLink.js +0 -149
  104. package/dist/src/nested.d.ts +0 -43
  105. package/dist/src/nested.js +0 -91
  106. package/dist/src/nowiki/base.d.ts +0 -27
  107. package/dist/src/nowiki/base.js +0 -42
  108. package/dist/src/nowiki/comment.d.ts +0 -27
  109. package/dist/src/nowiki/comment.js +0 -77
  110. package/dist/src/nowiki/dd.d.ts +0 -8
  111. package/dist/src/nowiki/dd.js +0 -24
  112. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -18
  113. package/dist/src/nowiki/doubleUnderscore.js +0 -51
  114. package/dist/src/nowiki/hr.d.ts +0 -8
  115. package/dist/src/nowiki/hr.js +0 -14
  116. package/dist/src/nowiki/index.d.ts +0 -16
  117. package/dist/src/nowiki/index.js +0 -20
  118. package/dist/src/nowiki/list.d.ts +0 -19
  119. package/dist/src/nowiki/list.js +0 -48
  120. package/dist/src/nowiki/listBase.d.ts +0 -5
  121. package/dist/src/nowiki/listBase.js +0 -11
  122. package/dist/src/nowiki/noinclude.d.ts +0 -10
  123. package/dist/src/nowiki/noinclude.js +0 -23
  124. package/dist/src/nowiki/quote.d.ts +0 -14
  125. package/dist/src/nowiki/quote.js +0 -68
  126. package/dist/src/onlyinclude.d.ts +0 -16
  127. package/dist/src/onlyinclude.js +0 -57
  128. package/dist/src/paramTag/index.d.ts +0 -37
  129. package/dist/src/paramTag/index.js +0 -68
  130. package/dist/src/paramTag/inputbox.d.ts +0 -8
  131. package/dist/src/paramTag/inputbox.js +0 -22
  132. package/dist/src/parameter.d.ts +0 -67
  133. package/dist/src/parameter.js +0 -213
  134. package/dist/src/pre.d.ts +0 -28
  135. package/dist/src/pre.js +0 -54
  136. package/dist/src/syntax.d.ts +0 -14
  137. package/dist/src/syntax.js +0 -35
  138. package/dist/src/table/base.d.ts +0 -27
  139. package/dist/src/table/base.js +0 -81
  140. package/dist/src/table/index.d.ts +0 -230
  141. package/dist/src/table/index.js +0 -390
  142. package/dist/src/table/td.d.ts +0 -88
  143. package/dist/src/table/td.js +0 -284
  144. package/dist/src/table/tr.d.ts +0 -32
  145. package/dist/src/table/tr.js +0 -57
  146. package/dist/src/table/trBase.d.ts +0 -53
  147. package/dist/src/table/trBase.js +0 -154
  148. package/dist/src/tagPair/ext.d.ts +0 -29
  149. package/dist/src/tagPair/ext.js +0 -153
  150. package/dist/src/tagPair/include.d.ts +0 -37
  151. package/dist/src/tagPair/include.js +0 -71
  152. package/dist/src/tagPair/index.d.ts +0 -27
  153. package/dist/src/tagPair/index.js +0 -79
  154. package/dist/src/transclude.d.ts +0 -167
  155. package/dist/src/transclude.js +0 -715
  156. package/dist/util/constants.js +0 -113
  157. package/dist/util/debug.js +0 -90
  158. package/dist/util/diff.js +0 -82
  159. package/dist/util/lint.js +0 -30
  160. package/dist/util/string.js +0 -53
  161. package/errors/README +0 -1
  162. package/printed/README +0 -1
@@ -1,560 +0,0 @@
1
- "use strict";
2
- /* eslint @stylistic/operator-linebreak: [2, "before", {overrides: {"=": "after"}}] */
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.Layout = void 0;
5
- const assert = require("assert/strict");
6
- const debug_1 = require("../util/debug");
7
- const constants_1 = require("../util/constants");
8
- const src_1 = require("../src");
9
- const tr_1 = require("../src/table/tr");
10
- const table_1 = require("../src/table");
11
- const td_1 = require("../src/table/td");
12
- const trBase_1 = require("../src/table/trBase");
13
- /**
14
- * 检查坐标形式
15
- * @param coords 坐标
16
- */
17
- const isTableCoords = (coords) => coords.x === undefined;
18
- /**
19
- * 比较两个表格坐标
20
- * @param coords1 坐标1
21
- * @param coords2 坐标2
22
- */
23
- const cmpCoords = (coords1, coords2) => {
24
- const diff = coords1.row - coords2.row;
25
- return diff === 0 ? coords1.column - coords2.column : diff;
26
- };
27
- /**
28
- * 是否是行尾
29
- * @param {Token} cell 表格单元格
30
- */
31
- const isRowEnd = ({ type }) => type === 'tr' || type === 'table-syntax';
32
- /**
33
- * 是否是合并单元格的第一列
34
- * @param rowLayout 行布局
35
- * @param i 单元格序号
36
- * @param oneCol 是否仅有一列
37
- */
38
- const isStartCol = (rowLayout, i, oneCol = false) => {
39
- const coords = rowLayout[i];
40
- return rowLayout[i - 1] !== coords && (!oneCol || rowLayout[i + 1] !== coords);
41
- };
42
- function occupied(layout, i, oneRow = false, cells) {
43
- return layout[i].map(({ row, column }, j) => row === i && (!oneRow || cells[column].rowspan === 1) ? j : undefined).filter((j) => j !== undefined);
44
- }
45
- /**
46
- * 设置表格格式
47
- * @param cells 单元格
48
- * @param attr 属性
49
- * @param multi 是否对所有单元格设置,或是仅对行首单元格设置
50
- */
51
- const format = (cells, attr = {}, multi = false) => {
52
- for (const [token, start] of cells) {
53
- if (multi || start) {
54
- if (typeof attr === 'string') {
55
- token.setSyntax(attr);
56
- }
57
- else {
58
- token.setAttr(attr);
59
- }
60
- }
61
- }
62
- };
63
- /**
64
- * 填补缺失单元格
65
- * @param y 行号
66
- * @param rowToken 表格行
67
- * @param layout 表格布局
68
- * @param maxCol 最大列数
69
- * @param token 待填充的单元格
70
- */
71
- const fill = (y, rowToken, layout, maxCol, token) => {
72
- 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;
73
- debug_1.Shadow.run(() => {
74
- for (let i = 0; i < maxCol; i++) {
75
- if (!rowLayout[i]) {
76
- rowToken.insertAt(token.cloneNode(), pos);
77
- }
78
- }
79
- });
80
- };
81
- /** @extends {Array<TableCoords[]>} */
82
- class Layout extends Array {
83
- /** 打印表格布局 */
84
- print() {
85
- const hBorders = (0, debug_1.emptyArray)(this.length + 1, i => {
86
- const prev = this[i - 1] ?? [], next = this[i] ?? [];
87
- return (0, debug_1.emptyArray)(Math.max(prev.length, next.length), j => prev[j] !== next[j]);
88
- }), vBorders = this.map(cur => (0, debug_1.emptyArray)(cur.length + 1, j => cur[j - 1] !== cur[j]));
89
- let out = '';
90
- for (let i = 0; i <= this.length; i++) {
91
- const hBorder = hBorders[i].map(Number), vBorderTop = (vBorders[i - 1] ?? []).map(Number), vBorderBottom = (vBorders[i] ?? []).map(Number),
92
- // eslint-disable-next-line no-sparse-arrays
93
- border = [' ', , , '┌', , '┐', '─', '┬', , '│', '└', '├', '┘', '┤', '┴', '┼'];
94
- for (let j = 0; j <= hBorder.length; j++) {
95
- const bit = (vBorderTop[j] << 3) + (vBorderBottom[j] << 0)
96
- + (hBorder[j - 1] << 2) + (hBorder[j] << 1);
97
- out += `${border[bit]}${hBorder[j] ? '─' : ' '}`;
98
- }
99
- out += '\n';
100
- }
101
- console.log(out.slice(0, -1));
102
- }
103
- }
104
- exports.Layout = Layout;
105
- table_1.TableToken.prototype.getNthCell =
106
- /** @implements */
107
- function (coords) {
108
- const rawCoords = coords.row === undefined ? this.toRawCoords(coords) : coords;
109
- return rawCoords && this.getNthRow(rawCoords.row, false, false)?.getNthCol(rawCoords.column);
110
- };
111
- table_1.TableToken.prototype.getLayout =
112
- /** @implements */
113
- function (stop) {
114
- const rows = this.getAllRows(), { length } = rows, layout = new Layout(...(0, debug_1.emptyArray)(length, () => []));
115
- for (let i = 0; i < length; i++) {
116
- if (i > (stop?.row ?? stop?.y ?? NaN)) {
117
- break;
118
- }
119
- const rowLayout = layout[i];
120
- let j = 0, k = 0, last;
121
- for (const cell of rows[i].childNodes.slice(2)) {
122
- if (cell.type === 'td') {
123
- if (cell.isIndependent()) {
124
- last = cell.subtype !== 'caption';
125
- }
126
- if (last) {
127
- const coords = { row: i, column: j }, { rowspan, colspan } = cell;
128
- j++;
129
- while (rowLayout[k]) {
130
- k++;
131
- }
132
- if (i === stop?.row && j > (stop.column ?? NaN)) {
133
- layout[i][k] = coords;
134
- return layout;
135
- }
136
- for (let y = i; y < Math.min(i + rowspan, length); y++) {
137
- for (let x = k; x < k + colspan; x++) {
138
- layout[y][x] = coords;
139
- }
140
- }
141
- k += colspan;
142
- if (i === stop?.y && k > (stop.x ?? NaN)) {
143
- return layout;
144
- }
145
- }
146
- }
147
- else if (isRowEnd(cell)) {
148
- break;
149
- }
150
- }
151
- }
152
- return layout;
153
- };
154
- table_1.TableToken.prototype.printLayout =
155
- /** @implements */
156
- function () {
157
- this.getLayout().print();
158
- };
159
- table_1.TableToken.prototype.toRenderedCoords =
160
- /** @implements */
161
- function ({ row, column }) {
162
- const rowLayout = this.getLayout({ row, column })[row], x = rowLayout?.findIndex(coords => cmpCoords(coords, { row, column }) === 0);
163
- return rowLayout && (x === -1 ? undefined : { y: row, x: x });
164
- };
165
- table_1.TableToken.prototype.toRawCoords =
166
- /** @implements */
167
- function ({ x, y }) {
168
- const rowLayout = this.getLayout({ x, y })[y], coords = rowLayout?.[x];
169
- if (coords) {
170
- return { ...coords, start: coords.row === y && rowLayout[x - 1] !== coords };
171
- }
172
- else if (rowLayout || y > 0) {
173
- return x === rowLayout?.length
174
- ? { row: y, column: (rowLayout.reverse().find(({ row }) => row === y)?.column ?? -1) + 1, start: true }
175
- : undefined;
176
- }
177
- return { row: 0, column: 0, start: true };
178
- };
179
- table_1.TableToken.prototype.getFullRow =
180
- /** @implements */
181
- function (y) {
182
- const rows = this.getAllRows();
183
- return new Map(this.getLayout({ y })[y]?.map(({ row, column }) => [rows[row].getNthCol(column), row === y]));
184
- };
185
- table_1.TableToken.prototype.getFullCol =
186
- /** @implements */
187
- function (x) {
188
- const layout = this.getLayout(), colLayout = layout.map(row => row[x]).filter(Boolean), rows = this.getAllRows();
189
- return new Map(colLayout.map(coords => [rows[coords.row].getNthCol(coords.column), layout[coords.row][x - 1] !== coords]));
190
- };
191
- table_1.TableToken.prototype.formatTableRow =
192
- /** @implements */
193
- function (y, attr = {}, multiRow = false) {
194
- format(this.getFullRow(y), attr, multiRow);
195
- };
196
- table_1.TableToken.prototype.formatTableCol =
197
- /** @implements */
198
- function (x, attr = {}, multiCol = false) {
199
- format(this.getFullCol(x), attr, multiCol);
200
- };
201
- table_1.TableToken.prototype.fillTableRow =
202
- /** @implements */
203
- function (y, inner, subtype = 'td', attr = {}) {
204
- 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'));
205
- fill(y, rowToken, layout, maxCol, token);
206
- };
207
- table_1.TableToken.prototype.fillTable =
208
- /** @implements */
209
- function (inner, subtype = 'td', attr = {}) {
210
- 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'));
211
- for (let y = 0; y < rowTokens.length; y++) {
212
- fill(y, rowTokens[y], layout, maxCol, token);
213
- }
214
- };
215
- table_1.TableToken.prototype.insertTableCell =
216
- /** @implements */
217
- function (inner, coords, subtype = 'td', attr = {}) {
218
- let rawCoords;
219
- if (coords.column === undefined) {
220
- const { x, y } = coords;
221
- rawCoords = this.toRawCoords(coords);
222
- if (!rawCoords?.start) {
223
- throw new RangeError(`指定的坐标不是单元格起始点:(${x}, ${y})`);
224
- }
225
- }
226
- else {
227
- rawCoords = coords;
228
- }
229
- const rowToken = this.getNthRow(rawCoords.row, true);
230
- return rowToken === this
231
- ? trBase_1.TrBaseToken.prototype.insertTableCell.call(this, inner, rawCoords, subtype, attr)
232
- : rowToken.insertTableCell(inner, rawCoords, subtype, attr);
233
- };
234
- table_1.TableToken.prototype.prependTableRow =
235
- /** @implements */
236
- function () {
237
- // @ts-expect-error abstract class
238
- const row = debug_1.Shadow.run(() => new tr_1.TrToken('\n|-', undefined, this.getAttribute('config'))), { childNodes } = this, [, , plain] = childNodes, start = plain?.constructor === src_1.Token ? 3 : 2, tdChildren = childNodes.slice(start), index = tdChildren.findIndex(({ type }) => type !== 'td');
239
- this.insertAt(row, index === -1 ? -1 : index + start);
240
- debug_1.Shadow.run(() => {
241
- for (const cell of tdChildren.slice(0, index === -1 ? undefined : index)) {
242
- if (cell.subtype !== 'caption') {
243
- row.insertAt(cell);
244
- }
245
- }
246
- });
247
- return row;
248
- };
249
- table_1.TableToken.prototype.insertTableRow =
250
- /** @implements */
251
- function (y, attr = {}, inner, subtype = 'td', innerAttr = {}) {
252
- let reference = this.getNthRow(y, false, true);
253
- // @ts-expect-error abstract class
254
- const token = debug_1.Shadow.run(() => new tr_1.TrToken('\n|-', undefined, this.getAttribute('config')));
255
- token.setAttr(attr);
256
- if (reference?.type === 'table') { // `row === 0`且表格自身是有效行
257
- reference = this.prependTableRow();
258
- }
259
- this.insertBefore(token, reference);
260
- if (inner !== undefined) {
261
- 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];
262
- debug_1.Shadow.run(() => {
263
- for (let i = 0; i < maxCol; i++) {
264
- const coords = rowLayout[i];
265
- if (!coords) {
266
- token.insertAt(td.cloneNode());
267
- }
268
- else if (!set.has(coords)) {
269
- set.add(coords);
270
- if (coords.row < y) {
271
- this.getNthCell(coords).rowspan++;
272
- }
273
- }
274
- }
275
- });
276
- }
277
- return token;
278
- };
279
- table_1.TableToken.prototype.insertTableCol =
280
- /** @implements */
281
- function (x, inner, subtype = 'td', attr = {}) {
282
- const layout = this.getLayout(), rowLength = layout.map(({ length }) => length), minCol = Math.min(...rowLength);
283
- if (x > minCol) {
284
- throw new RangeError(`表格第 ${rowLength.indexOf(minCol)} 行仅有 ${minCol} 列!`);
285
- }
286
- const token = (0, td_1.createTd)(inner, subtype, attr, this.getAttribute('include'), this.getAttribute('config'));
287
- for (let i = 0; i < layout.length; i++) {
288
- const coords = layout[i][x], prevCoords = x === 0 ? true : layout[i][x - 1];
289
- if (!prevCoords) {
290
- continue;
291
- }
292
- else if (prevCoords !== coords) {
293
- const rowToken = this.getNthRow(i);
294
- rowToken.insertBefore(token.cloneNode(), rowToken.getNthCol(coords.column, true));
295
- }
296
- else if (coords.row === i) {
297
- this.getNthCell(coords).colspan++;
298
- }
299
- }
300
- };
301
- table_1.TableToken.prototype.removeTableRow =
302
- /** @implements */
303
- function (y) {
304
- const rows = this.getAllRows(), layout = this.getLayout(), rowLayout = layout[y], set = new WeakSet();
305
- for (let x = rowLayout.length - 1; x >= 0; x--) {
306
- const coords = rowLayout[x];
307
- if (set.has(coords)) {
308
- continue;
309
- }
310
- set.add(coords);
311
- const token = rows[coords.row].getNthCol(coords.column);
312
- let { rowspan } = token;
313
- if (rowspan > 1) {
314
- token.rowspan = --rowspan;
315
- if (coords.row === y) {
316
- const { colspan, subtype } = token, attr = token.getAttrs();
317
- for (let i = y + 1; rowspan && i < rows.length; i++, rowspan--) {
318
- const { column } = layout[i].slice(x + colspan).find(({ row }) => row === i) ?? {};
319
- if (column !== undefined) {
320
- rows[i].insertTableCell('', { row: 0, column }, subtype, { ...attr, rowspan });
321
- break;
322
- }
323
- }
324
- }
325
- }
326
- }
327
- const row = rows[y], rowToken = row.type === 'tr' ? row : this.prependTableRow();
328
- rowToken.remove();
329
- return rowToken;
330
- };
331
- table_1.TableToken.prototype.removeTableCol =
332
- /** @implements */
333
- function (x) {
334
- for (const [token, start] of this.getFullCol(x)) {
335
- const { colspan, lastChild } = token;
336
- if (colspan > 1) {
337
- token.colspan = colspan - 1;
338
- if (start) {
339
- lastChild.replaceChildren();
340
- }
341
- }
342
- else {
343
- token.remove();
344
- }
345
- }
346
- };
347
- table_1.TableToken.prototype.mergeCells =
348
- /** @implements */
349
- function (xlim, ylim) {
350
- 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)));
351
- if ([...layout[ymin - 1] ?? [], ...layout[ymax] ?? []].some(coords => set.has(coords))
352
- || layout.some(rowLayout => set.has(rowLayout[xmin - 1]) || set.has(rowLayout[xmax]))) {
353
- throw new RangeError('待合并区域与外侧区域有重叠!');
354
- }
355
- const corner = layout[ymin][xmin], rows = this.getAllRows(), cornerCell = rows[corner.row].getNthCol(corner.column);
356
- cornerCell.rowspan = ymax - ymin;
357
- cornerCell.colspan = xmax - xmin;
358
- set.delete(corner);
359
- for (const token of [...set].map(({ row, column }) => rows[row].getNthCol(column))) {
360
- token.remove();
361
- }
362
- return cornerCell;
363
- };
364
- table_1.TableToken.prototype.split =
365
- /** @implements */
366
- function (coords, dirs) {
367
- const cell = this.getNthCell(coords), attr = cell.getAttrs(), { subtype } = cell;
368
- attr.rowspan ||= 1;
369
- attr.colspan ||= 1;
370
- for (const dir of dirs) {
371
- if (attr[dir] === 1) {
372
- dirs.delete(dir);
373
- }
374
- }
375
- if (dirs.size === 0) {
376
- return;
377
- }
378
- let { x, y } = coords;
379
- const rawCoords = isTableCoords(coords) ? coords : this.toRawCoords(coords);
380
- if (rawCoords.start === false || x === undefined) {
381
- ({ x, y } = this.toRenderedCoords(rawCoords));
382
- }
383
- const splitting = { rowspan: 1, colspan: 1 };
384
- for (const dir of dirs) {
385
- cell.setAttr(dir, 1);
386
- splitting[dir] = attr[dir];
387
- delete attr[dir];
388
- }
389
- for (let j = y; j < y + splitting.rowspan; j++) {
390
- for (let i = x; i < x + splitting.colspan; i++) {
391
- if (i > x || j > y) {
392
- try {
393
- this.insertTableCell('', { x: i, y: j }, subtype, attr);
394
- }
395
- catch (e) {
396
- if (e instanceof RangeError && e.message.startsWith('指定的坐标不是单元格起始点:')) {
397
- break;
398
- }
399
- throw e;
400
- }
401
- }
402
- }
403
- }
404
- };
405
- table_1.TableToken.prototype.splitIntoRows =
406
- /** @implements */
407
- function (coords) {
408
- this.split(coords, new Set(['rowspan']));
409
- };
410
- table_1.TableToken.prototype.splitIntoCols =
411
- /** @implements */
412
- function (coords) {
413
- this.split(coords, new Set(['colspan']));
414
- };
415
- table_1.TableToken.prototype.splitIntoCells =
416
- /** @implements */
417
- function (coords) {
418
- this.split(coords, new Set(['rowspan', 'colspan']));
419
- };
420
- table_1.TableToken.prototype.replicateTableRow =
421
- /** @implements */
422
- function (row) {
423
- let rowToken = this.getNthRow(row);
424
- if (rowToken.type === 'table') {
425
- rowToken = this.prependTableRow();
426
- }
427
- const replicated = this.insertBefore(rowToken.cloneNode(), rowToken);
428
- for (const [token, start] of this.getFullRow(row)) {
429
- if (start) {
430
- token.rowspan = 1;
431
- }
432
- else {
433
- token.rowspan++;
434
- }
435
- }
436
- return replicated;
437
- };
438
- table_1.TableToken.prototype.replicateTableCol =
439
- /** @implements */
440
- function (x) {
441
- const replicated = [];
442
- for (const [token, start] of this.getFullCol(x)) {
443
- if (start) {
444
- const newToken = token.cloneNode();
445
- newToken.colspan = 1;
446
- token.before(newToken);
447
- replicated.push(newToken);
448
- }
449
- else {
450
- token.colspan++;
451
- }
452
- }
453
- return replicated;
454
- };
455
- table_1.TableToken.prototype.moveTableRowBefore =
456
- /** @implements */
457
- function (y, before) {
458
- const layout = this.getLayout();
459
- try {
460
- assert.deepEqual(occupied(layout, y), occupied(layout, before));
461
- }
462
- catch (e) {
463
- if (e instanceof assert.AssertionError) {
464
- throw new RangeError(`第 ${y} 行与第 ${before} 行的构造不同,无法移动!`);
465
- }
466
- throw e;
467
- }
468
- const rowToken = this.removeTableRow(y);
469
- for (const coords of layout[before]) {
470
- if (coords.row < before) {
471
- this.getNthCell(coords).rowspan++;
472
- }
473
- }
474
- let beforeToken = this.getNthRow(before);
475
- if (beforeToken.type === 'table') {
476
- beforeToken = this.prependTableRow();
477
- }
478
- this.insertBefore(rowToken, beforeToken);
479
- return rowToken;
480
- };
481
- table_1.TableToken.prototype.moveTableRowAfter =
482
- /** @implements */
483
- function (y, after) {
484
- const layout = this.getLayout(), afterToken = this.getNthRow(after), cells = afterToken.childNodes.filter(child => child.type === 'td' && child.subtype !== 'caption');
485
- try {
486
- assert.deepEqual(occupied(layout, y), occupied(layout, after, true, cells));
487
- }
488
- catch (e) {
489
- if (e instanceof assert.AssertionError) {
490
- throw new RangeError(`第 ${y} 行与第 ${after} 行的构造不同,无法移动!`);
491
- }
492
- throw e;
493
- }
494
- const rowToken = this.removeTableRow(y);
495
- for (const coords of layout[after]) {
496
- if (coords.row < after) {
497
- this.getNthCell(coords).rowspan++;
498
- }
499
- else {
500
- const cell = cells[coords.column], { rowspan } = cell;
501
- if (rowspan > 1) {
502
- cell.rowspan = rowspan + 1;
503
- }
504
- }
505
- }
506
- if (afterToken === this) {
507
- const index = this.childNodes.slice(2).findIndex(isRowEnd);
508
- this.insertAt(rowToken, index + 2);
509
- }
510
- else {
511
- this.insertBefore(rowToken, afterToken);
512
- }
513
- return rowToken;
514
- };
515
- table_1.TableToken.prototype.moveCol =
516
- /** @implements */
517
- function (x, reference, after = false) {
518
- const layout = this.getLayout();
519
- if (layout.some(rowLayout => isStartCol(rowLayout, x) !== isStartCol(rowLayout, reference, after))) {
520
- throw new RangeError(`第 ${x} 列与第 ${reference} 列的构造不同,无法移动!`);
521
- }
522
- const setX = new WeakSet(), setRef = new WeakSet(), rows = this.getAllRows();
523
- for (let i = 0; i < layout.length; i++) {
524
- const rowLayout = layout[i], coords = rowLayout[x], refCoords = rowLayout[reference], start = isStartCol(rowLayout, x);
525
- if (refCoords && !start && !setRef.has(refCoords)) {
526
- setRef.add(refCoords);
527
- rows[refCoords.row].getNthCol(refCoords.column).colspan++;
528
- }
529
- if (coords && !setX.has(coords)) {
530
- setX.add(coords);
531
- const rowToken = rows[i];
532
- let token = rowToken.getNthCol(coords.column);
533
- const { colspan } = token;
534
- if (colspan > 1) {
535
- token.colspan = colspan - 1;
536
- if (start) {
537
- const original = token;
538
- token = token.cloneNode();
539
- original.lastChild.replaceChildren();
540
- token.colspan = 1;
541
- }
542
- }
543
- if (start) {
544
- const col = rowLayout.slice(reference + Number(after)).find(({ row }) => row === i)?.column;
545
- rowToken.insertBefore(token, col === undefined ? rowToken.childNodes.slice(2).find(isRowEnd) : rowToken.getNthCol(col));
546
- }
547
- }
548
- }
549
- };
550
- table_1.TableToken.prototype.moveTableColBefore =
551
- /** @implements */
552
- function (x, before) {
553
- this.moveCol(x, before);
554
- };
555
- table_1.TableToken.prototype.moveTableColAfter =
556
- /** @implements */
557
- function (x, after) {
558
- this.moveCol(x, after, true);
559
- };
560
- constants_1.classes['ExtendTableToken'] = __filename;
package/dist/base.d.ts DELETED
@@ -1,53 +0,0 @@
1
- export interface Config {
2
- ext: string[];
3
- readonly html: [string[], string[], string[]];
4
- readonly namespaces: Record<string, string>;
5
- readonly nsid: Record<string, number>;
6
- readonly parserFunction: [Record<string, string>, string[], string[], string[]];
7
- readonly doubleUnderscore: [string[], string[]];
8
- readonly protocol: string;
9
- readonly img: Record<string, string>;
10
- readonly variants: string[];
11
- readonly excludes?: string[];
12
- readonly interwiki: string[];
13
- readonly conversionTable?: [string, string][];
14
- readonly redirects?: [string, string][];
15
- }
16
- export type Severity = 'error' | 'warning';
17
- export interface LintError {
18
- readonly message: string;
19
- readonly severity: Severity;
20
- readonly startIndex: number;
21
- readonly endIndex: number;
22
- readonly startLine: number;
23
- readonly startCol: number;
24
- readonly endLine: number;
25
- readonly endCol: number;
26
- }
27
- /** 类似Node */
28
- export interface AstNode {
29
- type: string;
30
- readonly childNodes: readonly AstNode[];
31
- /** Linter */
32
- lint(): LintError[];
33
- /** 以HTML格式打印 */
34
- print(): string;
35
- }
36
- /** 类似HTMLElement */
37
- interface AstElement extends AstNode {
38
- /** 保存为JSON */
39
- json(): object;
40
- }
41
- export interface Parser {
42
- config: string | Config;
43
- i18n: string | Record<string, string> | undefined;
44
- /** 获取解析设置 */
45
- getConfig(): Config;
46
- /**
47
- * 解析wikitext
48
- * @param include 是否嵌入
49
- * @param maxStage 最大解析层级
50
- */
51
- parse(wikitext: string, include?: boolean, maxStage?: number, config?: Config): AstElement;
52
- }
53
- export {};
package/dist/index.d.ts DELETED
@@ -1,32 +0,0 @@
1
- import { Shadow } from './util/debug';
2
- import type { log } from './util/diff';
3
- import type { Config, LintError, Parser as ParserBase } from './base';
4
- import type { Title } from './lib/title';
5
- import type { Token } from './internal';
6
- declare interface Parser extends ParserBase {
7
- readonly Shadow: typeof Shadow;
8
- conversionTable: Map<string, string>;
9
- redirects: Map<string, string>;
10
- warning: boolean;
11
- debugging: boolean;
12
- /**
13
- * 规范化页面标题
14
- * @param title 标题(含或不含命名空间前缀)
15
- * @param defaultNs 命名空间
16
- * @param include 是否嵌入
17
- * @param halfParsed 是否是半解析状态
18
- * @param decode 是否需要解码
19
- * @param selfLink 是否允许selfLink
20
- */
21
- normalizeTitle(title: string, defaultNs?: number, include?: boolean, config?: Config, halfParsed?: boolean, decode?: boolean, selfLink?: boolean): Title;
22
- parse(wikitext: string, include?: boolean, maxStage?: number, config?: Config): Token;
23
- /**
24
- * 是否是跨维基链接
25
- * @param title 链接标题
26
- */
27
- isInterwiki(title: string, config?: Config): RegExpExecArray | null;
28
- }
29
- declare const Parser: Parser;
30
- export = Parser;
31
- export type { Config, LintError };
32
- export type * from './internal';