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
package/dist/lib/node.js DELETED
@@ -1,477 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AstNode = void 0;
4
- const assert = require("assert/strict");
5
- const EventEmitter = require("events");
6
- const constants_1 = require("../util/constants");
7
- /**
8
- * 计算字符串的行列数
9
- * @param str 字符串
10
- */
11
- const getDimension = (str) => {
12
- const lines = str.split('\n'), height = lines.length;
13
- return { height, width: lines[height - 1].length };
14
- };
15
- /**
16
- * 获取子节点相对于父节点的字符位置
17
- * @param j 子节点序号
18
- * @param parent 父节点
19
- */
20
- const getIndex = (j, parent) => parent.childNodes.slice(0, j).reduce((acc, cur, i) => acc + cur.toString().length + parent.getGaps(i), 0)
21
- + parent.getAttribute('padding');
22
- /* NOT FOR BROWSER */
23
- /**
24
- * 定制TypeError消息
25
- * @param {Function} Constructor 类
26
- * @param method
27
- * @param args 可接受的参数类型
28
- * @throws `TypeError`
29
- */
30
- const typeError = ({ name }, method, ...args) => {
31
- throw new TypeError(`${name}.${method} method only accepts ${args.join('、')} as input parameters!`);
32
- };
33
- /* NOT FOR BROWSER END */
34
- /** 类似Node */
35
- class AstNode {
36
- childNodes = [];
37
- #parentNode;
38
- /* NOT FOR BROWSER */
39
- #optional = new Set();
40
- #events = new EventEmitter();
41
- /** 首位子节点 */
42
- get firstChild() {
43
- return this.childNodes[0];
44
- }
45
- /** 末位子节点 */
46
- get lastChild() {
47
- return this.childNodes[this.childNodes.length - 1];
48
- }
49
- /** 父节点 */
50
- get parentNode() {
51
- return this.#parentNode;
52
- }
53
- /** 后一个兄弟节点 */
54
- get nextSibling() {
55
- const childNodes = this.parentNode?.childNodes;
56
- return childNodes && childNodes[childNodes.indexOf(this) + 1];
57
- }
58
- /** 前一个兄弟节点 */
59
- get previousSibling() {
60
- const childNodes = this.parentNode?.childNodes;
61
- return childNodes && childNodes[childNodes.indexOf(this) - 1];
62
- }
63
- /** 行数 */
64
- get offsetHeight() {
65
- return this.#getDimension().height;
66
- }
67
- /** 最后一行的列数 */
68
- get offsetWidth() {
69
- return this.#getDimension().width;
70
- }
71
- /* NOT FOR BROWSER */
72
- /** 后一个非文本兄弟节点 */
73
- get nextElementSibling() {
74
- const childNodes = this.parentNode?.childNodes, i = childNodes?.indexOf(this);
75
- return childNodes?.slice(i + 1).find((child) => child.type !== 'text');
76
- }
77
- /** 前一个非文本兄弟节点 */
78
- get previousElementSibling() {
79
- const childNodes = this.parentNode?.childNodes, i = childNodes?.indexOf(this);
80
- return childNodes?.slice(0, i).reverse().find((child) => child.type !== 'text');
81
- }
82
- /** 后一个可见的兄弟节点 */
83
- get nextVisibleSibling() {
84
- let { nextSibling } = this;
85
- while (nextSibling?.text() === '') {
86
- ({ nextSibling } = nextSibling);
87
- }
88
- return nextSibling;
89
- }
90
- /** 前一个可见的兄弟节点 */
91
- get previousVisibleSibling() {
92
- let { previousSibling } = this;
93
- while (previousSibling?.text() === '') {
94
- ({ previousSibling } = previousSibling);
95
- }
96
- return previousSibling;
97
- }
98
- /** 是否具有根节点 */
99
- get isConnected() {
100
- return this.getRootNode().type === 'root';
101
- }
102
- /** 后方是否还有其他节点(不含后代) */
103
- get eof() {
104
- const { parentNode } = this;
105
- if (!parentNode) {
106
- return true;
107
- }
108
- let { nextSibling } = this;
109
- while (nextSibling?.type === 'text' && nextSibling.data.trim() === '') {
110
- ({ nextSibling } = nextSibling);
111
- }
112
- return nextSibling === undefined && parentNode.eof;
113
- }
114
- /** 相对于父容器的行号 */
115
- get offsetTop() {
116
- return this.#getPosition().top;
117
- }
118
- /** 相对于父容器的列号 */
119
- get offsetLeft() {
120
- return this.#getPosition().left;
121
- }
122
- /** 位置、大小和padding */
123
- get style() {
124
- return { ...this.#getPosition(), ...this.#getDimension(), padding: this.getAttribute('padding') };
125
- }
126
- /** @private */
127
- get fixed() {
128
- return false;
129
- }
130
- /** 字体样式 */
131
- get font() {
132
- const { parentNode } = this, acceptable = parentNode?.getAcceptable();
133
- if (!parentNode || acceptable && !('QuoteToken' in acceptable)) {
134
- return { bold: false, italic: false };
135
- }
136
- const { childNodes, type } = parentNode;
137
- let { bold = false, italic = false } = type === 'ext-link-text' && parentNode.parentNode || {};
138
- for (let i = childNodes.indexOf(this) - 1; i >= 0; i--) {
139
- const child = childNodes[i];
140
- if (child.is('quote')) {
141
- bold = child.bold !== bold;
142
- italic = child.italic !== italic;
143
- }
144
- else if (child.type === 'text' && child.data.includes('\n')) {
145
- break;
146
- }
147
- }
148
- return { bold, italic };
149
- }
150
- /** 是否粗体 */
151
- get bold() {
152
- return this.font.bold;
153
- }
154
- /** 是否斜体 */
155
- get italic() {
156
- return this.font.italic;
157
- }
158
- constructor() {
159
- Object.defineProperty(this, 'childNodes', { writable: false });
160
- Object.freeze(this.childNodes);
161
- }
162
- /* NOT FOR BROWSER END */
163
- /** @private */
164
- getAttribute(key) {
165
- return (key === 'padding' ? 0 : this[key]);
166
- }
167
- /** @private */
168
- setAttribute(key, value) {
169
- if (key === 'parentNode') {
170
- this.#parentNode = value;
171
- /* NOT FOR BROWSER */
172
- }
173
- else if (Object.hasOwn(this, key)) {
174
- const descriptor = Object.getOwnPropertyDescriptor(this, key);
175
- if (this.#optional.has(key)) {
176
- descriptor.enumerable = Boolean(value);
177
- }
178
- const oldValue = this[key], frozen = typeof oldValue === 'object' && Object.isFrozen(oldValue);
179
- Object.defineProperty(this, key, { ...descriptor, value });
180
- if (frozen && typeof value === 'object') {
181
- Object.freeze(value);
182
- }
183
- /* NOT FOR BROWSER END */
184
- }
185
- else {
186
- this[key] = value; // eslint-disable-line @typescript-eslint/no-explicit-any
187
- }
188
- }
189
- /** 获取根节点 */
190
- getRootNode() {
191
- let { parentNode } = this;
192
- while (parentNode?.parentNode) {
193
- ({ parentNode } = parentNode);
194
- }
195
- return parentNode ?? this;
196
- }
197
- /**
198
- * 将字符位置转换为行列号
199
- * @param index 字符位置
200
- */
201
- posFromIndex(index) {
202
- const str = String(this);
203
- if (index >= -str.length && index <= str.length) {
204
- const { height, width } = getDimension(str.slice(0, index));
205
- return { top: height - 1, left: width };
206
- }
207
- return undefined;
208
- }
209
- /** 获取行数和最后一行的列数 */
210
- #getDimension() {
211
- return getDimension(String(this));
212
- }
213
- /** @private */
214
- getGaps(_) {
215
- return 0;
216
- }
217
- /**
218
- * 获取当前节点的相对字符位置,或其第`j`个子节点的相对字符位置
219
- * @param j 子节点序号
220
- */
221
- getRelativeIndex(j) {
222
- if (j === undefined) {
223
- const { parentNode } = this;
224
- return parentNode ? getIndex(parentNode.childNodes.indexOf(this), parentNode) : 0;
225
- }
226
- /* NOT FOR BROWSER */
227
- this.verifyChild(j, 1);
228
- /* NOT FOR BROWSER END */
229
- return getIndex(j, this);
230
- }
231
- /** 获取当前节点的绝对位置 */
232
- getAbsoluteIndex() {
233
- const { parentNode } = this;
234
- return parentNode ? parentNode.getAbsoluteIndex() + this.getRelativeIndex() : 0;
235
- }
236
- /** @private */
237
- seal(key, permanent) {
238
- /* NOT FOR BROWSER */
239
- if (!permanent) {
240
- this.#optional.add(key);
241
- }
242
- /* NOT FOR BROWSER END */
243
- Object.defineProperty(this, key, {
244
- enumerable: !permanent && Boolean(this[key]),
245
- configurable: true,
246
- /* NOT FOR BROWSER */
247
- writable: false,
248
- });
249
- }
250
- /**
251
- * 是否是某种类型的节点
252
- * @param type 节点类型
253
- */
254
- is(type) {
255
- return this.type === type;
256
- }
257
- /* NOT FOR BROWSER */
258
- /** @private */
259
- typeError(method, ...types) {
260
- return typeError(this.constructor, method, ...types);
261
- }
262
- /** @private */
263
- constructorError(msg) {
264
- throw new Error(`${this.constructor.name} ${msg}!`);
265
- }
266
- /**
267
- * 是否是全同节点
268
- * @param node 待比较的节点
269
- * @throws `assert.AssertionError`
270
- */
271
- isEqualNode(node) {
272
- try {
273
- assert.deepEqual(this, node);
274
- }
275
- catch (e) {
276
- if (e instanceof assert.AssertionError) {
277
- return false;
278
- }
279
- throw e;
280
- }
281
- return true;
282
- }
283
- /**
284
- * 在当前节点前后插入兄弟节点
285
- * @param nodes 插入节点
286
- * @param offset 插入的相对位置
287
- * @throws `Error` 不存在父节点
288
- */
289
- #insertAdjacent(nodes, offset) {
290
- const { parentNode } = this;
291
- if (!parentNode) {
292
- throw new Error('There is no parent node!');
293
- }
294
- const i = parentNode.childNodes.indexOf(this) + offset;
295
- for (let j = 0; j < nodes.length; j++) {
296
- parentNode.insertAt(nodes[j], i + j);
297
- }
298
- }
299
- /**
300
- * 在后方批量插入兄弟节点
301
- * @param nodes 插入节点
302
- */
303
- after(...nodes) {
304
- this.#insertAdjacent(nodes, 1);
305
- }
306
- /**
307
- * 在前方批量插入兄弟节点
308
- * @param nodes 插入节点
309
- */
310
- before(...nodes) {
311
- this.#insertAdjacent(nodes, 0);
312
- }
313
- /** 移除当前节点 */
314
- remove() {
315
- this.parentNode?.removeChild(this);
316
- }
317
- /**
318
- * 将当前节点批量替换为新的节点
319
- * @param nodes 插入节点
320
- */
321
- replaceWith(...nodes) {
322
- this.after(...nodes);
323
- this.remove();
324
- }
325
- /**
326
- * 是自身或后代节点
327
- * @param node 待检测节点
328
- */
329
- contains(node) {
330
- return node === this || this.childNodes.some(child => child.contains(node));
331
- }
332
- /** @private */
333
- verifyChild(i, addition = 0) {
334
- const { childNodes: { length } } = this;
335
- if (i < -length || i >= length + addition) {
336
- throw new RangeError(`The child node at position ${i} does not exist!`);
337
- }
338
- }
339
- /**
340
- * 添加事件监听
341
- * @param types 事件类型
342
- * @param listener 监听函数
343
- * @param options 选项
344
- * @param options.once 仅执行一次
345
- */
346
- addEventListener(types, listener, options) {
347
- if (Array.isArray(types)) {
348
- for (const type of types) {
349
- this.addEventListener(type, listener, options);
350
- }
351
- }
352
- else {
353
- this.#events[options?.once ? 'once' : 'on'](types, listener);
354
- }
355
- }
356
- /**
357
- * 移除事件监听
358
- * @param types 事件类型
359
- * @param listener 监听函数
360
- */
361
- removeEventListener(types, listener) {
362
- if (Array.isArray(types)) {
363
- for (const type of types) {
364
- this.removeEventListener(type, listener);
365
- }
366
- }
367
- else {
368
- this.#events.off(types, listener);
369
- }
370
- }
371
- /**
372
- * 移除事件的所有监听
373
- * @param types 事件类型
374
- */
375
- removeAllEventListeners(types) {
376
- if (Array.isArray(types)) {
377
- for (const type of types) {
378
- this.removeAllEventListeners(type);
379
- }
380
- }
381
- else if (typeof types === 'string') {
382
- this.#events.removeAllListeners(types);
383
- }
384
- }
385
- /**
386
- * 列举事件监听
387
- * @param type 事件类型
388
- */
389
- listEventListeners(type) {
390
- return this.#events.listeners(type);
391
- }
392
- /**
393
- * 触发事件
394
- * @param e 事件对象
395
- * @param data 事件数据
396
- */
397
- dispatchEvent(e, data) {
398
- if (!e.target) { // 初始化
399
- Object.defineProperty(e, 'target', { value: this, enumerable: true });
400
- }
401
- Object.defineProperties(e, {
402
- prevTarget: { value: e.currentTarget, enumerable: true, configurable: true },
403
- currentTarget: { value: this, enumerable: true, configurable: true },
404
- });
405
- this.#events.emit(e.type, e, data);
406
- if (e.bubbles && !e.cancelBubble && this.parentNode) {
407
- this.parentNode.dispatchEvent(e, data);
408
- }
409
- }
410
- /** 获取所有祖先节点 */
411
- getAncestors() {
412
- const ancestors = [];
413
- let { parentNode } = this;
414
- while (parentNode) {
415
- ancestors.push(parentNode);
416
- ({ parentNode } = parentNode);
417
- }
418
- return ancestors;
419
- }
420
- /**
421
- * 比较和另一个节点的相对位置
422
- * @param other 待比较的节点
423
- * @throws `RangeError` 不在同一个语法树
424
- */
425
- compareDocumentPosition(other) {
426
- if (this === other) {
427
- return 0;
428
- }
429
- else if (this.contains(other)) {
430
- return -1;
431
- }
432
- else if (other.contains(this)) {
433
- return 1;
434
- }
435
- else if (this.getRootNode() !== other.getRootNode()) {
436
- throw new RangeError('Nodes to be compared are not in the same document!');
437
- }
438
- const aAncestors = [...this.getAncestors().reverse(), this], bAncestors = [...other.getAncestors().reverse(), other], depth = aAncestors.findIndex((ancestor, i) => bAncestors[i] !== ancestor), { childNodes } = aAncestors[depth - 1];
439
- return childNodes.indexOf(aAncestors[depth]) - childNodes.indexOf(bAncestors[depth]);
440
- }
441
- /**
442
- * 将行列号转换为字符位置
443
- * @param top 行号
444
- * @param left 列号
445
- */
446
- indexFromPos(top, left) {
447
- const lines = String(this).split('\n');
448
- return top >= 0 && left >= 0 && top <= lines.length - 1 && left <= lines[top].length
449
- ? lines.slice(0, top).reduce((acc, cur) => acc + cur.length + 1, 0) + left
450
- : undefined;
451
- }
452
- /** 获取当前节点的相对位置 */
453
- #getPosition() {
454
- return this.parentNode?.posFromIndex(this.getRelativeIndex()) ?? { top: 0, left: 0 };
455
- }
456
- /** 获取当前节点的行列位置和大小 */
457
- getBoundingClientRect() {
458
- return { ...this.#getDimension(), ...this.getRootNode().posFromIndex(this.getAbsoluteIndex()) };
459
- }
460
- /** 销毁 */
461
- destroy() {
462
- this.parentNode?.destroy();
463
- for (const child of this.childNodes) {
464
- child.setAttribute('parentNode', undefined);
465
- }
466
- Object.setPrototypeOf(this, null);
467
- }
468
- /**
469
- * 获取某一行的wikitext
470
- * @param n 行号
471
- */
472
- getLine(n) {
473
- return String(this).split('\n', n + 1)[n];
474
- }
475
- }
476
- exports.AstNode = AstNode;
477
- constants_1.classes['AstNode'] = __filename;
@@ -1,105 +0,0 @@
1
- import type { AstNodes } from '../internal';
2
- import type { Dimension, Position } from './node';
3
- /** 模拟Range对象 */
4
- export declare class AstRange {
5
- #private;
6
- /** 起点容器 */
7
- get startContainer(): AstNodes;
8
- /** 起点位置 */
9
- get startOffset(): number;
10
- /** 起点绝对位置 */
11
- get startIndex(): number;
12
- /** 起点行列位置 */
13
- get startPos(): Position;
14
- /** 终点容器 */
15
- get endContainer(): AstNodes;
16
- /** 终点位置 */
17
- get endOffset(): number;
18
- /** 终点绝对位置 */
19
- get endIndex(): number;
20
- /** 终点行列位置 */
21
- get endPos(): Position;
22
- /** 起始和终止位置是否重合 */
23
- get collapsed(): boolean;
24
- /** 最近的公共祖先 */
25
- get commonAncestorContainer(): AstNodes;
26
- /**
27
- * 设置起点
28
- * @param startNode 起点容器
29
- * @param offset 起点位置
30
- * @throws `RangeError` offset取值超出范围
31
- */
32
- setStart(startNode: AstNodes, offset: number): void;
33
- /**
34
- * 设置终点
35
- * @param endNode 终点容器
36
- * @param offset 终点位置
37
- * @throws `RangeError` offset取值超出范围
38
- */
39
- setEnd(endNode: AstNodes, offset: number): void;
40
- /**
41
- * 在节点后设置起点
42
- * @param referenceNode 节点
43
- */
44
- setStartAfter(referenceNode: AstNodes): void;
45
- /**
46
- * 在节点后设置终点
47
- * @param referenceNode 节点
48
- */
49
- setEndAfter(referenceNode: AstNodes): void;
50
- /**
51
- * 在节点前设置起点
52
- * @param referenceNode 节点
53
- */
54
- setStartBefore(referenceNode: AstNodes): void;
55
- /**
56
- * 在节点前设置终点
57
- * @param referenceNode 节点
58
- */
59
- setEndBefore(referenceNode: AstNodes): void;
60
- /**
61
- * 设置Range包含整个节点的内容
62
- * @param referenceNode 节点
63
- */
64
- selectNodeContents(referenceNode: AstNodes): void;
65
- /**
66
- * 设置Range包含整个节点
67
- * @param referenceNode 节点
68
- */
69
- selectNode(referenceNode: AstNodes): void;
70
- /**
71
- * 使起始和终止位置重合
72
- * @param toStart 重合至起始位置
73
- */
74
- collapse(toStart?: boolean): void;
75
- /**
76
- * 比较端点和Range的位置
77
- * @param referenceNode 端点容器
78
- * @param offset 端点位置
79
- * @throws `RangeError` 不在同一个文档
80
- */
81
- comparePoint(referenceNode: AstNodes, offset: number): -1 | 0 | 1;
82
- /**
83
- * 端点是否在Range中
84
- * @param referenceNode 端点容器
85
- * @param offset 端点位置
86
- */
87
- isPointInRange(referenceNode: AstNodes, offset: number): boolean;
88
- /** 复制AstRange对象 */
89
- cloneRange(): AstRange;
90
- /** 清空Range */
91
- detach(): void;
92
- /** 删除Range中的内容 */
93
- deleteContents(): void;
94
- /** 获取行列位置和大小 */
95
- getBoundingClientRect(): Dimension & Position;
96
- /**
97
- * 在起始位置插入节点
98
- * @param newNode 插入的节点
99
- */
100
- insertNode(newNode: AstNodes | string): void;
101
- /** 获取范围内的全部节点 */
102
- extractContents(): AstNodes[];
103
- /** 拷贝范围内的全部节点 */
104
- cloneContents(): AstNodes[];
105
- }