wikiparser-node 1.11.1 → 1.12.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 (175) hide show
  1. package/bundle/bundle.min.js +37 -0
  2. package/config/default.json +28 -28
  3. package/config/enwiki.json +14 -827
  4. package/config/llwiki.json +20 -54
  5. package/config/minimum.json +1 -1
  6. package/config/moegirl.json +20 -63
  7. package/config/zhwiki.json +27 -492
  8. package/extensions/dist/base.js +162 -0
  9. package/extensions/dist/codejar.js +52 -0
  10. package/extensions/dist/editor.js +159 -0
  11. package/extensions/dist/highlight.js +30 -0
  12. package/extensions/dist/lint.js +72 -0
  13. package/extensions/editor.css +59 -0
  14. package/extensions/ui.css +159 -0
  15. package/package.json +29 -21
  16. package/config/.schema.json +0 -186
  17. package/dist/addon/table.js +0 -486
  18. package/dist/addon/token.js +0 -304
  19. package/dist/addon/transclude.js +0 -184
  20. package/dist/base.d.ts +0 -81
  21. package/dist/base.js +0 -39
  22. package/dist/index.d.ts +0 -33
  23. package/dist/index.js +0 -235
  24. package/dist/internal.d.ts +0 -46
  25. package/dist/lib/element.d.ts +0 -125
  26. package/dist/lib/element.js +0 -375
  27. package/dist/lib/node.d.ts +0 -173
  28. package/dist/lib/node.js +0 -477
  29. package/dist/lib/range.d.ts +0 -105
  30. package/dist/lib/range.js +0 -406
  31. package/dist/lib/ranges.d.ts +0 -28
  32. package/dist/lib/ranges.js +0 -126
  33. package/dist/lib/rect.d.ts +0 -18
  34. package/dist/lib/rect.js +0 -34
  35. package/dist/lib/text.d.ts +0 -58
  36. package/dist/lib/text.js +0 -400
  37. package/dist/lib/title.d.ts +0 -42
  38. package/dist/lib/title.js +0 -208
  39. package/dist/mixin/attributesParent.d.ts +0 -49
  40. package/dist/mixin/attributesParent.js +0 -79
  41. package/dist/mixin/fixed.d.ts +0 -5
  42. package/dist/mixin/fixed.js +0 -32
  43. package/dist/mixin/flagsParent.d.ts +0 -43
  44. package/dist/mixin/flagsParent.js +0 -64
  45. package/dist/mixin/hidden.d.ts +0 -7
  46. package/dist/mixin/hidden.js +0 -37
  47. package/dist/mixin/magicLinkParent.d.ts +0 -19
  48. package/dist/mixin/magicLinkParent.js +0 -43
  49. package/dist/mixin/singleLine.d.ts +0 -5
  50. package/dist/mixin/singleLine.js +0 -25
  51. package/dist/mixin/sol.d.ts +0 -6
  52. package/dist/mixin/sol.js +0 -45
  53. package/dist/mixin/syntax.d.ts +0 -8
  54. package/dist/mixin/syntax.js +0 -46
  55. package/dist/parser/braces.js +0 -150
  56. package/dist/parser/commentAndExt.js +0 -79
  57. package/dist/parser/converter.js +0 -39
  58. package/dist/parser/externalLinks.js +0 -37
  59. package/dist/parser/hrAndDoubleUnderscore.js +0 -42
  60. package/dist/parser/html.js +0 -38
  61. package/dist/parser/links.js +0 -101
  62. package/dist/parser/list.js +0 -114
  63. package/dist/parser/magicLinks.js +0 -52
  64. package/dist/parser/quotes.js +0 -67
  65. package/dist/parser/redirect.js +0 -26
  66. package/dist/parser/selector.js +0 -394
  67. package/dist/parser/table.js +0 -123
  68. package/dist/src/arg.d.ts +0 -51
  69. package/dist/src/arg.js +0 -214
  70. package/dist/src/atom.d.ts +0 -14
  71. package/dist/src/atom.js +0 -52
  72. package/dist/src/attribute.d.ts +0 -64
  73. package/dist/src/attribute.js +0 -480
  74. package/dist/src/attributes.d.ts +0 -101
  75. package/dist/src/attributes.js +0 -381
  76. package/dist/src/converter.d.ts +0 -28
  77. package/dist/src/converter.js +0 -148
  78. package/dist/src/converterFlags.d.ts +0 -80
  79. package/dist/src/converterFlags.js +0 -239
  80. package/dist/src/converterRule.d.ts +0 -71
  81. package/dist/src/converterRule.js +0 -216
  82. package/dist/src/extLink.d.ts +0 -36
  83. package/dist/src/extLink.js +0 -218
  84. package/dist/src/gallery.d.ts +0 -47
  85. package/dist/src/gallery.js +0 -143
  86. package/dist/src/heading.d.ts +0 -40
  87. package/dist/src/heading.js +0 -192
  88. package/dist/src/hidden.d.ts +0 -9
  89. package/dist/src/hidden.js +0 -80
  90. package/dist/src/html.d.ts +0 -61
  91. package/dist/src/html.js +0 -343
  92. package/dist/src/imageParameter.d.ts +0 -60
  93. package/dist/src/imageParameter.js +0 -260
  94. package/dist/src/imagemap.d.ts +0 -47
  95. package/dist/src/imagemap.js +0 -146
  96. package/dist/src/imagemapLink.d.ts +0 -31
  97. package/dist/src/imagemapLink.js +0 -97
  98. package/dist/src/index.d.ts +0 -136
  99. package/dist/src/index.js +0 -834
  100. package/dist/src/link/base.d.ts +0 -52
  101. package/dist/src/link/base.js +0 -256
  102. package/dist/src/link/category.d.ts +0 -22
  103. package/dist/src/link/category.js +0 -34
  104. package/dist/src/link/file.d.ts +0 -102
  105. package/dist/src/link/file.js +0 -333
  106. package/dist/src/link/galleryImage.d.ts +0 -29
  107. package/dist/src/link/galleryImage.js +0 -132
  108. package/dist/src/link/index.d.ts +0 -39
  109. package/dist/src/link/index.js +0 -98
  110. package/dist/src/link/redirectTarget.d.ts +0 -27
  111. package/dist/src/link/redirectTarget.js +0 -69
  112. package/dist/src/magicLink.d.ts +0 -58
  113. package/dist/src/magicLink.js +0 -256
  114. package/dist/src/nested.d.ts +0 -40
  115. package/dist/src/nested.js +0 -106
  116. package/dist/src/nowiki/base.d.ts +0 -28
  117. package/dist/src/nowiki/base.js +0 -89
  118. package/dist/src/nowiki/comment.d.ts +0 -14
  119. package/dist/src/nowiki/comment.js +0 -121
  120. package/dist/src/nowiki/dd.d.ts +0 -8
  121. package/dist/src/nowiki/dd.js +0 -72
  122. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -15
  123. package/dist/src/nowiki/doubleUnderscore.js +0 -97
  124. package/dist/src/nowiki/hr.d.ts +0 -5
  125. package/dist/src/nowiki/hr.js +0 -70
  126. package/dist/src/nowiki/index.d.ts +0 -14
  127. package/dist/src/nowiki/index.js +0 -28
  128. package/dist/src/nowiki/list.d.ts +0 -5
  129. package/dist/src/nowiki/list.js +0 -65
  130. package/dist/src/nowiki/listBase.d.ts +0 -23
  131. package/dist/src/nowiki/listBase.js +0 -99
  132. package/dist/src/nowiki/noinclude.d.ts +0 -6
  133. package/dist/src/nowiki/noinclude.js +0 -75
  134. package/dist/src/nowiki/quote.d.ts +0 -14
  135. package/dist/src/nowiki/quote.js +0 -140
  136. package/dist/src/onlyinclude.d.ts +0 -13
  137. package/dist/src/onlyinclude.js +0 -58
  138. package/dist/src/paramTag/index.d.ts +0 -28
  139. package/dist/src/paramTag/index.js +0 -78
  140. package/dist/src/paramTag/inputbox.d.ts +0 -8
  141. package/dist/src/paramTag/inputbox.js +0 -22
  142. package/dist/src/parameter.d.ts +0 -60
  143. package/dist/src/parameter.js +0 -264
  144. package/dist/src/pre.d.ts +0 -28
  145. package/dist/src/pre.js +0 -60
  146. package/dist/src/redirect.d.ts +0 -30
  147. package/dist/src/redirect.js +0 -126
  148. package/dist/src/syntax.d.ts +0 -17
  149. package/dist/src/syntax.js +0 -87
  150. package/dist/src/table/base.d.ts +0 -28
  151. package/dist/src/table/base.js +0 -81
  152. package/dist/src/table/index.d.ts +0 -230
  153. package/dist/src/table/index.js +0 -506
  154. package/dist/src/table/td.d.ts +0 -72
  155. package/dist/src/table/td.js +0 -370
  156. package/dist/src/table/tr.d.ts +0 -30
  157. package/dist/src/table/tr.js +0 -59
  158. package/dist/src/table/trBase.d.ts +0 -49
  159. package/dist/src/table/trBase.js +0 -164
  160. package/dist/src/tagPair/ext.d.ts +0 -29
  161. package/dist/src/tagPair/ext.js +0 -220
  162. package/dist/src/tagPair/include.d.ts +0 -33
  163. package/dist/src/tagPair/include.js +0 -130
  164. package/dist/src/tagPair/index.d.ts +0 -23
  165. package/dist/src/tagPair/index.js +0 -128
  166. package/dist/src/transclude.d.ts +0 -159
  167. package/dist/src/transclude.js +0 -587
  168. package/dist/util/constants.js +0 -25
  169. package/dist/util/debug.js +0 -95
  170. package/dist/util/diff.js +0 -83
  171. package/dist/util/html.js +0 -143
  172. package/dist/util/lint.js +0 -32
  173. package/dist/util/string.js +0 -87
  174. package/errors/README +0 -3
  175. package/printed/README +0 -3
@@ -1,186 +0,0 @@
1
- {
2
- "type": "object",
3
- "properties": {
4
- "ext": {
5
- "description": "extension tags",
6
- "type": "array",
7
- "items": {
8
- "type": "string",
9
- "pattern": "^[a-z\\d_]+$"
10
- }
11
- },
12
- "html": {
13
- "description": "valid HTML tags",
14
- "type": "array",
15
- "items": {
16
- "type": "array",
17
- "items": {
18
- "type": "string",
19
- "pattern": "^[a-z\\d]+$"
20
- }
21
- },
22
- "minItems": 3,
23
- "maxItems": 3
24
- },
25
- "namespaces": {
26
- "description": "formatted namespaces",
27
- "type": "object",
28
- "patternProperties": {
29
- "^-?\\d+$": {
30
- "type": "string"
31
- }
32
- },
33
- "additionalProperties": false
34
- },
35
- "nsid": {
36
- "description": "namespace IDs",
37
- "type": "object",
38
- "required": [
39
- "file",
40
- "category"
41
- ],
42
- "additionalProperties": {
43
- "type": "integer"
44
- }
45
- },
46
- "parserFunction": {
47
- "type": "array",
48
- "items": [
49
- {
50
- "description": "case-insensitive parser functions",
51
- "type": "object",
52
- "additionalProperties": {
53
- "type": "string"
54
- }
55
- },
56
- {
57
- "description": "case-sensitive parser functions",
58
- "type": "array",
59
- "allOf": [
60
- {
61
- "contains": {
62
- "const": "!"
63
- }
64
- },
65
- {
66
- "contains": {
67
- "const": "="
68
- }
69
- }
70
- ],
71
- "items": {
72
- "type": "string"
73
- }
74
- },
75
- {
76
- "description": "msg and raw",
77
- "type": "array",
78
- "items": {
79
- "type": "string"
80
- }
81
- },
82
- {
83
- "description": "subst and safesubst",
84
- "type": "array",
85
- "items": {
86
- "type": "string"
87
- }
88
- }
89
- ],
90
- "minItems": 4,
91
- "maxItems": 4
92
- },
93
- "doubleUnderscore": {
94
- "description": "behavior switches",
95
- "type": "array",
96
- "items": {
97
- "type": "array",
98
- "items": {
99
- "type": "string"
100
- }
101
- },
102
- "minItems": 2,
103
- "maxItems": 2
104
- },
105
- "protocol": {
106
- "description": "external link protocols",
107
- "type": "string",
108
- "pattern": "^[a-z:/]+(?:\\|[a-z:/]+)*$"
109
- },
110
- "interwiki": {
111
- "type": "array",
112
- "items": {
113
- "type": "string"
114
- }
115
- },
116
- "img": {
117
- "description": "image-related magic words",
118
- "type": "object",
119
- "additionalProperties": {
120
- "type": "string",
121
- "pattern": "^[-a-z]+$"
122
- }
123
- },
124
- "redirection": {
125
- "description": "magic words for redirection",
126
- "type": "array",
127
- "items": {
128
- "type": "string",
129
- "pattern": "^#.+$"
130
- }
131
- },
132
- "variants": {
133
- "description": "variants for language conversion",
134
- "type": "array",
135
- "items": {
136
- "type": "string",
137
- "pattern": "^[-a-z]+$"
138
- }
139
- },
140
- "conversionTable": {
141
- "description": "table of unidirectional conversions",
142
- "type": "array",
143
- "items": {
144
- "type": "array",
145
- "items": {
146
- "type": "string",
147
- "pattern": "^[^ <>[\\]{}|]+$"
148
- },
149
- "minItems": 2,
150
- "maxItems": 2
151
- }
152
- },
153
- "redirects": {
154
- "description": "table of redirects",
155
- "type": "array",
156
- "items": {
157
- "type": "array",
158
- "items": {
159
- "type": "string",
160
- "pattern": "^[^ <>[\\]{}|]+$"
161
- },
162
- "minItems": 2,
163
- "maxItems": 2
164
- }
165
- },
166
- "articlePath": {
167
- "description": "base URL of internal links",
168
- "type": "string",
169
- "pattern": "\\$1"
170
- }
171
- },
172
- "required": [
173
- "ext",
174
- "html",
175
- "namespaces",
176
- "nsid",
177
- "parserFunction",
178
- "doubleUnderscore",
179
- "protocol",
180
- "interwiki",
181
- "img",
182
- "redirection",
183
- "variants"
184
- ],
185
- "additionalProperties": false
186
- }
@@ -1,486 +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
- function occupied(layout, i, oneRow, cells) {
37
- const rowLayout = layout[i];
38
- if (rowLayout) {
39
- return rowLayout.map(({ row, column }, j) => row === i && (!oneRow || cells[column]?.rowspan === 1) ? j : undefined).filter((j) => j !== undefined);
40
- }
41
- throw new RangeError(`The table layout does not contain row ${i}!`);
42
- }
43
- /**
44
- * 设置表格格式
45
- * @param cells 单元格
46
- * @param attr 属性
47
- * @param multi 是否对所有单元格设置,或是仅对行首单元格设置
48
- */
49
- const format = (cells, attr = {}, multi) => {
50
- for (const [token, start] of cells) {
51
- if (multi || start) {
52
- if (typeof attr === 'string') {
53
- token.setSyntax(attr);
54
- }
55
- else {
56
- token.setAttr(attr);
57
- }
58
- }
59
- }
60
- };
61
- /**
62
- * 填补缺失单元格
63
- * @param y 行号
64
- * @param rowToken 表格行
65
- * @param layout 表格布局
66
- * @param maxCol 最大列数
67
- * @param token 待填充的单元格
68
- */
69
- const fill = (y, rowToken, layout, maxCol, token) => {
70
- 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;
71
- debug_1.Shadow.run(() => {
72
- for (let i = 0; i < maxCol; i++) {
73
- if (!rowLayout[i]) {
74
- rowToken.insertAt(token.cloneNode(), pos);
75
- }
76
- }
77
- });
78
- };
79
- index_2.TableToken.prototype.printLayout =
80
- /** @implements */
81
- function () {
82
- this.getLayout().print();
83
- };
84
- index_2.TableToken.prototype.toRenderedCoords =
85
- /** @implements */
86
- function ({ row, column }) {
87
- const rowLayout = this.getLayout({ row, column })[row], x = rowLayout?.findIndex(coords => cmpCoords(coords, { row, column }) === 0);
88
- return rowLayout && (x === -1 ? undefined : { y: row, x: x });
89
- };
90
- index_2.TableToken.prototype.toRawCoords =
91
- /** @implements */
92
- function ({ x, y }) {
93
- const rowLayout = this.getLayout({ x, y })[y], coords = rowLayout?.[x];
94
- if (coords) {
95
- return { ...coords, start: coords.row === y && rowLayout[x - 1] !== coords };
96
- }
97
- else if (rowLayout || y > 0) {
98
- return x === rowLayout?.length
99
- ? { row: y, column: (rowLayout.reverse().find(({ row }) => row === y)?.column ?? -1) + 1, start: true }
100
- : undefined;
101
- }
102
- return { row: 0, column: 0, start: true };
103
- };
104
- index_2.TableToken.prototype.getFullRow =
105
- /** @implements */
106
- function (y) {
107
- const rows = this.getAllRows();
108
- return new Map(this.getLayout({ y })[y]?.map(({ row, column }) => [rows[row].getNthCol(column), row === y]));
109
- };
110
- index_2.TableToken.prototype.getFullCol =
111
- /** @implements */
112
- function (x) {
113
- const layout = this.getLayout(), colLayout = layout.map(row => row[x]).filter(Boolean), rows = this.getAllRows();
114
- return new Map(colLayout.map(coords => [rows[coords.row].getNthCol(coords.column), layout[coords.row][x - 1] !== coords]));
115
- };
116
- index_2.TableToken.prototype.formatTableRow =
117
- /** @implements */
118
- function (y, attr, multiRow) {
119
- format(this.getFullRow(y), attr, multiRow);
120
- };
121
- index_2.TableToken.prototype.formatTableCol =
122
- /** @implements */
123
- function (x, attr, multiCol) {
124
- format(this.getFullCol(x), attr, multiCol);
125
- };
126
- index_2.TableToken.prototype.fillTableRow =
127
- /** @implements */
128
- function (y, inner, subtype, attr) {
129
- 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'));
130
- fill(y, rowToken, layout, maxCol, token);
131
- };
132
- index_2.TableToken.prototype.fillTable =
133
- /** @implements */
134
- function (inner, subtype, attr) {
135
- 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'));
136
- for (let y = 0; y < rowTokens.length; y++) {
137
- fill(y, rowTokens[y], layout, maxCol, token);
138
- }
139
- };
140
- index_2.TableToken.prototype.insertTableCell =
141
- /** @implements */
142
- function (inner, coords, subtype, attr) {
143
- let rawCoords;
144
- if (coords.column === undefined) {
145
- const { x, y } = coords;
146
- rawCoords = this.toRawCoords(coords);
147
- if (!rawCoords?.start) {
148
- throw new RangeError(`The specified coordinates are not the starting point of any cell: (${x}, ${y})`);
149
- }
150
- }
151
- else {
152
- rawCoords = coords;
153
- }
154
- const rowToken = this.getNthRow(rawCoords.row, true);
155
- return rowToken === this
156
- ? trBase_1.TrBaseToken.prototype.insertTableCell.call(this, inner, rawCoords, subtype, attr)
157
- : rowToken.insertTableCell(inner, rawCoords, subtype, attr);
158
- };
159
- index_2.TableToken.prototype.prependTableRow =
160
- /** @implements */
161
- function () {
162
- // @ts-expect-error abstract class
163
- 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');
164
- this.insertAt(row, index === -1 ? -1 : index + start);
165
- debug_1.Shadow.run(() => {
166
- for (const cell of tdChildren.slice(0, index === -1 ? undefined : index)) {
167
- if (cell.subtype !== 'caption') {
168
- row.insertAt(cell);
169
- }
170
- }
171
- });
172
- return row;
173
- };
174
- index_2.TableToken.prototype.insertTableRow =
175
- /** @implements */
176
- function (y, attr = {}, inner, subtype = 'td', innerAttr = {}) {
177
- let reference = this.getNthRow(y, false, true);
178
- // @ts-expect-error abstract class
179
- const token = debug_1.Shadow.run(() => new tr_1.TrToken('\n|-', undefined, this.getAttribute('config')));
180
- token.setAttr(attr);
181
- if (reference?.type === 'table') { // `row === 0`且表格自身是有效行
182
- reference = this.prependTableRow();
183
- }
184
- this.insertBefore(token, reference);
185
- if (inner !== undefined) {
186
- 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];
187
- debug_1.Shadow.run(() => {
188
- for (let i = 0; i < maxCol; i++) {
189
- const coords = rowLayout[i];
190
- if (!coords) {
191
- token.insertAt(td.cloneNode());
192
- }
193
- else if (!set.has(coords)) {
194
- set.add(coords);
195
- if (coords.row < y) {
196
- this.getNthCell(coords).rowspan++;
197
- }
198
- }
199
- }
200
- });
201
- }
202
- return token;
203
- };
204
- index_2.TableToken.prototype.insertTableCol =
205
- /** @implements */
206
- function (x, inner, subtype, attr) {
207
- const layout = this.getLayout(), rowLength = layout.map(({ length }) => length), minCol = Math.min(...rowLength);
208
- if (x > minCol) {
209
- throw new RangeError(`Row ${rowLength.indexOf(minCol)} has only ${minCol} column(s)!`);
210
- }
211
- const token = (0, td_1.createTd)(inner, subtype, attr, this.getAttribute('include'), this.getAttribute('config'));
212
- for (let i = 0; i < layout.length; i++) {
213
- const coords = layout[i][x], prevCoords = x === 0 ? true : layout[i][x - 1];
214
- if (!prevCoords) {
215
- continue;
216
- }
217
- else if (prevCoords !== coords) {
218
- const rowToken = this.getNthRow(i);
219
- rowToken.insertBefore(token.cloneNode(), rowToken.getNthCol(coords.column, true));
220
- }
221
- else if (coords.row === i) {
222
- this.getNthCell(coords).colspan++;
223
- }
224
- }
225
- };
226
- index_2.TableToken.prototype.removeTableRow =
227
- /** @implements */
228
- function (y) {
229
- const rows = this.getAllRows(), layout = this.getLayout(), rowLayout = layout[y], set = new WeakSet();
230
- for (let x = rowLayout.length - 1; x >= 0; x--) {
231
- const coords = rowLayout[x];
232
- if (set.has(coords)) {
233
- continue;
234
- }
235
- set.add(coords);
236
- const token = rows[coords.row].getNthCol(coords.column);
237
- let { rowspan } = token;
238
- if (rowspan > 1) {
239
- token.rowspan = --rowspan;
240
- if (coords.row === y) {
241
- const { colspan, subtype } = token, attr = token.getAttrs();
242
- for (let i = y + 1; rowspan && i < rows.length; i++, rowspan--) {
243
- const { column } = layout[i].slice(x + colspan).find(({ row }) => row === i) ?? {};
244
- if (column !== undefined) {
245
- rows[i].insertTableCell('', { row: 0, column }, subtype, { ...attr, rowspan });
246
- break;
247
- }
248
- }
249
- }
250
- }
251
- }
252
- const row = rows[y], rowToken = row.type === 'tr' ? row : this.prependTableRow();
253
- rowToken.remove();
254
- return rowToken;
255
- };
256
- index_2.TableToken.prototype.removeTableCol =
257
- /** @implements */
258
- function (x) {
259
- for (const [token, start] of this.getFullCol(x)) {
260
- const { colspan, lastChild } = token;
261
- if (colspan > 1) {
262
- token.colspan = colspan - 1;
263
- if (start) {
264
- lastChild.replaceChildren();
265
- }
266
- }
267
- else {
268
- token.remove();
269
- }
270
- }
271
- };
272
- index_2.TableToken.prototype.mergeCells =
273
- /** @implements */
274
- function (xlim, ylim) {
275
- 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)));
276
- if ([...layout[ymin - 1] ?? [], ...layout[ymax] ?? []].some(coords => set.has(coords))
277
- || layout.some(rowLayout => set.has(rowLayout[xmin - 1]) || set.has(rowLayout[xmax]))) {
278
- throw new RangeError('The area to be merged overlaps with the outer area!');
279
- }
280
- const corner = layout[ymin][xmin], rows = this.getAllRows(), cornerCell = rows[corner.row].getNthCol(corner.column);
281
- cornerCell.rowspan = ymax - ymin;
282
- cornerCell.colspan = xmax - xmin;
283
- set.delete(corner);
284
- for (const token of [...set].map(({ row, column }) => rows[row].getNthCol(column))) {
285
- token.remove();
286
- }
287
- return cornerCell;
288
- };
289
- index_2.TableToken.prototype.split =
290
- /** @implements */
291
- function (coords, dirs) {
292
- const cell = this.getNthCell(coords), attr = cell.getAttrs(), { subtype } = cell;
293
- attr.rowspan ||= 1;
294
- attr.colspan ||= 1;
295
- for (const dir of dirs) {
296
- if (attr[dir] === 1) {
297
- dirs.delete(dir);
298
- }
299
- }
300
- if (dirs.size === 0) {
301
- return;
302
- }
303
- let { x, y } = coords;
304
- const rawCoords = isTableCoords(coords) ? coords : this.toRawCoords(coords);
305
- if (rawCoords.start === false || x === undefined) {
306
- ({ x, y } = this.toRenderedCoords(rawCoords));
307
- }
308
- const splitting = { rowspan: 1, colspan: 1 };
309
- for (const dir of dirs) {
310
- cell.setAttr(dir, 1);
311
- splitting[dir] = attr[dir];
312
- delete attr[dir];
313
- }
314
- for (let j = y; j < y + splitting.rowspan; j++) {
315
- for (let i = x; i < x + splitting.colspan; i++) {
316
- if (i > x || j > y) {
317
- try {
318
- this.insertTableCell('', { x: i, y: j }, subtype, attr);
319
- }
320
- catch (e) {
321
- if (e instanceof RangeError
322
- && e.message.startsWith('The specified coordinates are not the starting point of a cell: ')) {
323
- break;
324
- }
325
- throw e;
326
- }
327
- }
328
- }
329
- }
330
- };
331
- index_2.TableToken.prototype.splitIntoRows =
332
- /** @implements */
333
- function (coords) {
334
- this.split(coords, new Set(['rowspan']));
335
- };
336
- index_2.TableToken.prototype.splitIntoCols =
337
- /** @implements */
338
- function (coords) {
339
- this.split(coords, new Set(['colspan']));
340
- };
341
- index_2.TableToken.prototype.splitIntoCells =
342
- /** @implements */
343
- function (coords) {
344
- this.split(coords, new Set(['rowspan', 'colspan']));
345
- };
346
- index_2.TableToken.prototype.replicateTableRow =
347
- /** @implements */
348
- function (row) {
349
- let rowToken = this.getNthRow(row);
350
- if (rowToken.type === 'table') {
351
- rowToken = this.prependTableRow();
352
- }
353
- const replicated = this.insertBefore(rowToken.cloneNode(), rowToken);
354
- for (const [token, start] of this.getFullRow(row)) {
355
- if (start) {
356
- token.rowspan = 1;
357
- }
358
- else {
359
- token.rowspan++;
360
- }
361
- }
362
- return replicated;
363
- };
364
- index_2.TableToken.prototype.replicateTableCol =
365
- /** @implements */
366
- function (x) {
367
- const replicated = [];
368
- for (const [token, start] of this.getFullCol(x)) {
369
- if (start) {
370
- const newToken = token.cloneNode();
371
- newToken.colspan = 1;
372
- token.before(newToken);
373
- replicated.push(newToken);
374
- }
375
- else {
376
- token.colspan++;
377
- }
378
- }
379
- return replicated;
380
- };
381
- index_2.TableToken.prototype.moveTableRowBefore =
382
- /** @implements */
383
- function (y, before) {
384
- const layout = this.getLayout();
385
- try {
386
- assert.deepEqual(occupied(layout, y), occupied(layout, before));
387
- }
388
- catch (e) {
389
- if (e instanceof assert.AssertionError) {
390
- throw new RangeError(`The structure of row ${y} is different from that of row ${before}, so it cannot be moved!`);
391
- }
392
- throw e;
393
- }
394
- const rowToken = this.removeTableRow(y);
395
- for (const coords of layout[before]) {
396
- if (coords.row < before) {
397
- this.getNthCell(coords).rowspan++;
398
- }
399
- }
400
- let beforeToken = this.getNthRow(before);
401
- if (beforeToken.type === 'table') {
402
- beforeToken = this.prependTableRow();
403
- }
404
- this.insertBefore(rowToken, beforeToken);
405
- return rowToken;
406
- };
407
- index_2.TableToken.prototype.moveTableRowAfter =
408
- /** @implements */
409
- function (y, after) {
410
- const layout = this.getLayout(), afterToken = this.getNthRow(after), cells = afterToken.childNodes.filter(child => child.type === 'td' && child.subtype !== 'caption');
411
- try {
412
- assert.deepEqual(occupied(layout, y), occupied(layout, after, true, cells));
413
- }
414
- catch (e) {
415
- if (e instanceof assert.AssertionError) {
416
- throw new RangeError(`The structure of row ${y} is different from that of row ${after}, so it cannot be moved!`);
417
- }
418
- throw e;
419
- }
420
- const rowToken = this.removeTableRow(y);
421
- for (const coords of layout[after]) {
422
- if (coords.row < after) {
423
- this.getNthCell(coords).rowspan++;
424
- }
425
- else {
426
- const cell = cells[coords.column], { rowspan } = cell;
427
- if (rowspan > 1) {
428
- cell.rowspan = rowspan + 1;
429
- }
430
- }
431
- }
432
- if (afterToken === this) {
433
- const index = this.childNodes.slice(2).findIndex(index_2.isRowEnd);
434
- this.insertAt(rowToken, index + 2);
435
- }
436
- else {
437
- this.insertBefore(rowToken, afterToken);
438
- }
439
- return rowToken;
440
- };
441
- index_2.TableToken.prototype.moveCol =
442
- /** @implements */
443
- function (x, reference, after) {
444
- const layout = this.getLayout();
445
- if (layout.some(rowLayout => isStartCol(rowLayout, x) !== isStartCol(rowLayout, reference, after))) {
446
- throw new RangeError(`The structure of column ${x} is different from that of column ${reference}, so it cannot be moved!`);
447
- }
448
- const setX = new WeakSet(), setRef = new WeakSet(), rows = this.getAllRows();
449
- for (let i = 0; i < layout.length; i++) {
450
- const rowLayout = layout[i], coords = rowLayout[x], refCoords = rowLayout[reference], start = isStartCol(rowLayout, x);
451
- if (refCoords && !start && !setRef.has(refCoords)) {
452
- setRef.add(refCoords);
453
- rows[refCoords.row].getNthCol(refCoords.column).colspan++;
454
- }
455
- if (coords && !setX.has(coords)) {
456
- setX.add(coords);
457
- const rowToken = rows[i];
458
- let token = rowToken.getNthCol(coords.column);
459
- const { colspan } = token;
460
- if (colspan > 1) {
461
- token.colspan = colspan - 1;
462
- if (start) {
463
- const original = token;
464
- token = token.cloneNode();
465
- original.lastChild.replaceChildren();
466
- token.colspan = 1;
467
- }
468
- }
469
- if (start) {
470
- const col = rowLayout.slice(reference + Number(after)).find(({ row }) => row === i)?.column;
471
- rowToken.insertBefore(token, col === undefined ? rowToken.childNodes.slice(2).find(index_2.isRowEnd) : rowToken.getNthCol(col));
472
- }
473
- }
474
- }
475
- };
476
- index_2.TableToken.prototype.moveTableColBefore =
477
- /** @implements */
478
- function (x, before) {
479
- this.moveCol(x, before);
480
- };
481
- index_2.TableToken.prototype.moveTableColAfter =
482
- /** @implements */
483
- function (x, after) {
484
- this.moveCol(x, after, true);
485
- };
486
- constants_1.classes['ExtendedTableToken'] = __filename;