wikiparser-node 1.0.0-beta.0 → 1.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config/.schema.json +26 -0
- package/dist/index.d.ts +11 -9
- package/dist/index.js +22 -24
- package/dist/internal.d.ts +44 -0
- package/dist/lib/element.d.ts +42 -32
- package/dist/lib/element.js +59 -56
- package/dist/lib/node.d.ts +29 -36
- package/dist/lib/node.js +33 -48
- package/dist/lib/range.d.ts +132 -0
- package/dist/lib/range.js +387 -0
- package/dist/lib/ranges.d.ts +2 -12
- package/dist/lib/ranges.js +6 -11
- package/dist/lib/text.d.ts +11 -5
- package/dist/lib/text.js +25 -13
- package/dist/lib/title.d.ts +4 -5
- package/dist/lib/title.js +17 -7
- package/dist/mixin/attributesParent.js +6 -3
- package/dist/mixin/fixed.js +8 -5
- package/dist/mixin/hidden.js +7 -3
- package/dist/mixin/singleLine.js +6 -3
- package/dist/mixin/sol.js +6 -3
- package/dist/parser/{brackets.js → braces.js} +34 -26
- package/dist/parser/commentAndExt.js +25 -15
- package/dist/parser/converter.js +16 -9
- package/dist/parser/externalLinks.js +15 -9
- package/dist/parser/hrAndDoubleUnderscore.js +17 -10
- package/dist/parser/html.js +18 -9
- package/dist/parser/links.js +22 -14
- package/dist/parser/list.js +20 -10
- package/dist/parser/magicLinks.js +14 -7
- package/dist/parser/quotes.js +21 -11
- package/dist/parser/selector.js +19 -12
- package/dist/parser/table.js +25 -16
- package/dist/src/arg.d.ts +7 -8
- package/dist/src/arg.js +27 -24
- package/dist/src/atom.d.ts +4 -5
- package/dist/src/atom.js +9 -7
- package/dist/src/attribute.d.ts +13 -13
- package/dist/src/attribute.js +28 -25
- package/dist/src/attributes.d.ts +11 -10
- package/dist/src/attributes.js +40 -45
- package/dist/src/converter.d.ts +5 -7
- package/dist/src/converter.js +22 -16
- package/dist/src/converterFlags.d.ts +11 -12
- package/dist/src/converterFlags.js +17 -14
- package/dist/src/converterRule.d.ts +9 -10
- package/dist/src/converterRule.js +27 -27
- package/dist/src/extLink.d.ts +4 -6
- package/dist/src/extLink.js +25 -22
- package/dist/src/gallery.d.ts +9 -13
- package/dist/src/gallery.js +28 -23
- package/dist/src/heading.d.ts +11 -11
- package/dist/src/heading.js +19 -19
- package/dist/src/hidden.d.ts +4 -5
- package/dist/src/hidden.js +10 -8
- package/dist/src/html.d.ts +15 -12
- package/dist/src/html.js +18 -15
- package/dist/src/imageParameter.d.ts +11 -13
- package/dist/src/imageParameter.js +21 -16
- package/dist/src/imagemap.d.ts +11 -15
- package/dist/src/imagemap.js +26 -21
- package/dist/src/imagemapLink.d.ts +12 -17
- package/dist/src/imagemapLink.js +19 -14
- package/dist/src/index.d.ts +24 -20
- package/dist/src/index.js +65 -75
- package/dist/src/link/base.d.ts +8 -10
- package/dist/src/link/base.js +28 -22
- package/dist/src/link/category.d.ts +2 -3
- package/dist/src/link/category.js +7 -5
- package/dist/src/link/file.d.ts +9 -11
- package/dist/src/link/file.js +53 -26
- package/dist/src/link/galleryImage.d.ts +8 -8
- package/dist/src/link/galleryImage.js +18 -16
- package/dist/src/link/index.d.ts +6 -6
- package/dist/src/link/index.js +14 -16
- package/dist/src/magicLink.d.ts +9 -6
- package/dist/src/magicLink.js +23 -18
- package/dist/src/nested.d.ts +10 -10
- package/dist/src/nested.js +25 -17
- package/dist/src/nowiki/base.d.ts +7 -8
- package/dist/src/nowiki/base.js +10 -8
- package/dist/src/nowiki/comment.d.ts +7 -7
- package/dist/src/nowiki/comment.js +12 -9
- package/dist/src/nowiki/dd.d.ts +2 -3
- package/dist/src/nowiki/dd.js +7 -11
- package/dist/src/nowiki/doubleUnderscore.d.ts +5 -7
- package/dist/src/nowiki/doubleUnderscore.js +11 -8
- package/dist/src/nowiki/hr.d.ts +6 -7
- package/dist/src/nowiki/hr.js +11 -8
- package/dist/src/nowiki/index.d.ts +5 -7
- package/dist/src/nowiki/index.js +8 -6
- package/dist/src/nowiki/list.d.ts +4 -4
- package/dist/src/nowiki/list.js +8 -6
- package/dist/src/nowiki/noinclude.d.ts +3 -3
- package/dist/src/nowiki/noinclude.js +8 -6
- package/dist/src/nowiki/quote.d.ts +6 -7
- package/dist/src/nowiki/quote.js +11 -8
- package/dist/src/onlyinclude.d.ts +3 -5
- package/dist/src/onlyinclude.js +9 -7
- package/dist/src/paramTag/index.d.ts +8 -10
- package/dist/src/paramTag/index.js +15 -13
- package/dist/src/paramTag/inputbox.d.ts +4 -6
- package/dist/src/paramTag/inputbox.js +10 -8
- package/dist/src/parameter.d.ts +11 -12
- package/dist/src/parameter.js +25 -22
- package/dist/src/pre.d.ts +5 -10
- package/dist/src/pre.js +16 -11
- package/dist/src/syntax.d.ts +6 -7
- package/dist/src/syntax.js +12 -10
- package/dist/src/table/base.d.ts +14 -9
- package/dist/src/table/base.js +18 -15
- package/dist/src/table/index.d.ts +24 -17
- package/dist/src/table/index.js +39 -67
- package/dist/src/table/td.d.ts +17 -21
- package/dist/src/table/td.js +20 -28
- package/dist/src/table/tr.d.ts +6 -11
- package/dist/src/table/tr.js +8 -6
- package/dist/src/table/trBase.d.ts +12 -22
- package/dist/src/table/trBase.js +23 -19
- package/dist/src/tagPair/ext.d.ts +10 -10
- package/dist/src/tagPair/ext.js +47 -24
- package/dist/src/tagPair/include.d.ts +6 -7
- package/dist/src/tagPair/include.js +11 -8
- package/dist/src/tagPair/index.d.ts +12 -11
- package/dist/src/tagPair/index.js +13 -11
- package/dist/src/transclude.d.ts +8 -10
- package/dist/src/transclude.js +70 -77
- package/dist/util/debug.js +2 -12
- package/dist/util/diff.js +4 -2
- package/dist/util/lint.js +5 -5
- package/dist/util/string.js +2 -31
- package/package.json +13 -13
- package/dist/util/base.js +0 -26
package/dist/lib/element.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AstElement = void 0;
|
|
2
4
|
const fs = require("fs");
|
|
3
5
|
const path = require("path");
|
|
4
6
|
const string_1 = require("../util/string");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const AstNode = require("./node");
|
|
7
|
+
const selector_1 = require("../parser/selector");
|
|
8
|
+
const ranges_1 = require("./ranges");
|
|
9
|
+
const title_1 = require("./title");
|
|
10
|
+
const index_1 = require("../index");
|
|
11
|
+
const node_1 = require("./node");
|
|
11
12
|
const lintIgnoredExt = new Set([
|
|
12
13
|
'nowiki',
|
|
13
14
|
'pre',
|
|
@@ -25,8 +26,14 @@ const lintIgnoredExt = new Set([
|
|
|
25
26
|
'templatedata',
|
|
26
27
|
'timeline',
|
|
27
28
|
]);
|
|
29
|
+
/**
|
|
30
|
+
* 检查某个下标是否符合表达式
|
|
31
|
+
* @param str 表达式
|
|
32
|
+
* @param i 待检查的下标
|
|
33
|
+
*/
|
|
34
|
+
const nth = (str, i) => new ranges_1.Ranges(str.split(',')).applyTo(i + 1).includes(i);
|
|
28
35
|
/** 类似HTMLElement */
|
|
29
|
-
class AstElement extends AstNode {
|
|
36
|
+
class AstElement extends node_1.AstNode {
|
|
30
37
|
/** @browser */
|
|
31
38
|
name;
|
|
32
39
|
/**
|
|
@@ -143,16 +150,13 @@ class AstElement extends AstNode {
|
|
|
143
150
|
* @param i 插入位置
|
|
144
151
|
* @throws `RangeError` 不能插入祖先节点
|
|
145
152
|
*/
|
|
146
|
-
insertAt(node, i = this.
|
|
147
|
-
if (
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
else if (node.contains(this)) {
|
|
151
|
-
Parser.error('不能插入祖先节点!', node);
|
|
153
|
+
insertAt(node, i = this.length) {
|
|
154
|
+
if (node.contains(this)) {
|
|
155
|
+
index_1.default.error('不能插入祖先节点!', node);
|
|
152
156
|
throw new RangeError('不能插入祖先节点!');
|
|
153
157
|
}
|
|
154
158
|
this.verifyChild(i, 1);
|
|
155
|
-
const childNodes = [...this.childNodes], e = new Event('insert', { bubbles: true }), j =
|
|
159
|
+
const childNodes = [...this.childNodes], e = new Event('insert', { bubbles: true }), j = index_1.default.running ? -1 : childNodes.indexOf(node);
|
|
156
160
|
if (j === -1) {
|
|
157
161
|
node.parentNode?.removeChild(node);
|
|
158
162
|
node.setAttribute('parentNode', this);
|
|
@@ -162,16 +166,17 @@ class AstElement extends AstNode {
|
|
|
162
166
|
}
|
|
163
167
|
childNodes.splice(i, 0, node);
|
|
164
168
|
this.setAttribute('childNodes', childNodes);
|
|
165
|
-
this.dispatchEvent(e, { position: i < 0 ? i + this.
|
|
169
|
+
this.dispatchEvent(e, { position: i < 0 ? i + this.length - 1 : i, inserted: node });
|
|
166
170
|
return node;
|
|
167
171
|
}
|
|
168
172
|
/**
|
|
169
173
|
* 最近的祖先节点
|
|
170
174
|
* @browser
|
|
175
|
+
* @param selector 选择器
|
|
171
176
|
*/
|
|
172
177
|
closest(selector) {
|
|
173
178
|
let { parentNode } = this;
|
|
174
|
-
const stack = parseSelector(selector);
|
|
179
|
+
const stack = (0, selector_1.parseSelector)(selector);
|
|
175
180
|
while (parentNode) {
|
|
176
181
|
if (parentNode.#matchesStack(stack)) {
|
|
177
182
|
return parentNode;
|
|
@@ -221,6 +226,7 @@ class AstElement extends AstNode {
|
|
|
221
226
|
/**
|
|
222
227
|
* 还原为wikitext
|
|
223
228
|
* @browser
|
|
229
|
+
* @param selector
|
|
224
230
|
* @param separator 子节点间的连接符
|
|
225
231
|
*/
|
|
226
232
|
toString(selector, separator = '') {
|
|
@@ -231,9 +237,10 @@ class AstElement extends AstNode {
|
|
|
231
237
|
/**
|
|
232
238
|
* Linter
|
|
233
239
|
* @browser
|
|
240
|
+
* @param start
|
|
234
241
|
*/
|
|
235
242
|
lint(start = this.getAbsoluteIndex()) {
|
|
236
|
-
const SyntaxToken = require('../src/syntax');
|
|
243
|
+
const { SyntaxToken } = require('../src/syntax');
|
|
237
244
|
if (this instanceof SyntaxToken || this.constructor.hidden
|
|
238
245
|
|| this.type === 'ext-inner' && lintIgnoredExt.has(this.name)) {
|
|
239
246
|
return [];
|
|
@@ -264,7 +271,7 @@ class AstElement extends AstNode {
|
|
|
264
271
|
json(file) {
|
|
265
272
|
const json = {
|
|
266
273
|
...this,
|
|
267
|
-
childNodes: this.childNodes.map(child => child.type === 'text' ?
|
|
274
|
+
childNodes: this.childNodes.map(child => child.type === 'text' ? child.data : child.json()),
|
|
268
275
|
};
|
|
269
276
|
if (typeof file === 'string') {
|
|
270
277
|
fs.writeFileSync(path.join(__dirname.slice(0, -4), '..', 'printed', `${file}${file.endsWith('.json') ? '' : '.json'}`), JSON.stringify(json, null, 2));
|
|
@@ -303,7 +310,9 @@ class AstElement extends AstNode {
|
|
|
303
310
|
}
|
|
304
311
|
if (equal === '~=') {
|
|
305
312
|
const thisVals = typeof thisVal === 'string' ? thisVal.split(/\s/u) : thisVal;
|
|
313
|
+
// @ts-expect-error noImplicitAny
|
|
306
314
|
return Boolean(thisVals?.[Symbol.iterator])
|
|
315
|
+
// @ts-expect-error spread unknown
|
|
307
316
|
&& [...thisVals].some(w => typeof w === 'string' && (0, string_1.toCase)(w, i) === v);
|
|
308
317
|
}
|
|
309
318
|
else if (typeof thisVal !== 'string') {
|
|
@@ -328,6 +337,7 @@ class AstElement extends AstNode {
|
|
|
328
337
|
/**
|
|
329
338
|
* 检查是否符合解析后的选择器,不含节点关系
|
|
330
339
|
* @param step 解析后的选择器
|
|
340
|
+
* @throws `SyntaxError` 错误的正则伪选择器
|
|
331
341
|
* @throws `SyntaxError` 未定义的伪选择器
|
|
332
342
|
*/
|
|
333
343
|
#matches(step) {
|
|
@@ -352,9 +362,9 @@ class AstElement extends AstNode {
|
|
|
352
362
|
case ':only-of-type':
|
|
353
363
|
return siblingsCountOfType === 1;
|
|
354
364
|
case ':empty':
|
|
355
|
-
return !childNodes.some(child => child.type !== 'text' ||
|
|
365
|
+
return !childNodes.some(child => child.type !== 'text' || child.data);
|
|
356
366
|
case ':parent':
|
|
357
|
-
return childNodes.some(child => child.type !== 'text' ||
|
|
367
|
+
return childNodes.some(child => child.type !== 'text' || child.data);
|
|
358
368
|
case ':header':
|
|
359
369
|
return type === 'heading';
|
|
360
370
|
case ':hidden':
|
|
@@ -368,7 +378,7 @@ class AstElement extends AstNode {
|
|
|
368
378
|
|| (type === 'file' || type === 'gallery-image' && link);
|
|
369
379
|
case ':local-link':
|
|
370
380
|
return (type === 'link' || type === 'file' || type === 'gallery-image')
|
|
371
|
-
&& link instanceof Title && link.title === '';
|
|
381
|
+
&& link instanceof title_1.Title && link.title === '';
|
|
372
382
|
case ':read-only':
|
|
373
383
|
return fixed;
|
|
374
384
|
case ':read-write':
|
|
@@ -381,7 +391,7 @@ class AstElement extends AstNode {
|
|
|
381
391
|
return this.#isProtected() === false;
|
|
382
392
|
default: {
|
|
383
393
|
const [t, n] = selector.split('#');
|
|
384
|
-
return (!t || t === type || Boolean(
|
|
394
|
+
return (!t || t === type || Boolean(index_1.default.typeAliases[type]?.includes(t)))
|
|
385
395
|
&& (!n || n === name);
|
|
386
396
|
}
|
|
387
397
|
}
|
|
@@ -415,7 +425,7 @@ class AstElement extends AstNode {
|
|
|
415
425
|
case 'regex': {
|
|
416
426
|
const mt = /^([^,]+),\s*\/(.+)\/([a-z]*)$/u.exec(s);
|
|
417
427
|
if (!mt) {
|
|
418
|
-
throw new SyntaxError('错误的伪选择器用法。请使用形如 ":regex(attr, /re/i)" 的格式。');
|
|
428
|
+
throw new SyntaxError('错误的伪选择器用法。请使用形如 ":regex(\'attr, /re/i\')" 的格式。');
|
|
419
429
|
}
|
|
420
430
|
try {
|
|
421
431
|
const regex = new RegExp(mt[2], mt[3]);
|
|
@@ -465,14 +475,12 @@ class AstElement extends AstNode {
|
|
|
465
475
|
#matchesStack(stack) {
|
|
466
476
|
return stack.some(condition => this.#matchesArray([...condition]));
|
|
467
477
|
}
|
|
468
|
-
/**
|
|
478
|
+
/**
|
|
479
|
+
* 检查是否符合选择器
|
|
480
|
+
* @param selector 选择器
|
|
481
|
+
*/
|
|
469
482
|
matches(selector) {
|
|
470
|
-
|
|
471
|
-
return true;
|
|
472
|
-
}
|
|
473
|
-
return typeof selector === 'string'
|
|
474
|
-
? this.#matchesStack(parseSelector(selector))
|
|
475
|
-
: this.typeError('matches', 'String');
|
|
483
|
+
return selector === undefined || this.#matchesStack((0, selector_1.parseSelector)(selector));
|
|
476
484
|
}
|
|
477
485
|
/**
|
|
478
486
|
* 符合组合选择器的第一个后代节点
|
|
@@ -490,9 +498,12 @@ class AstElement extends AstNode {
|
|
|
490
498
|
}
|
|
491
499
|
return undefined;
|
|
492
500
|
}
|
|
493
|
-
/**
|
|
501
|
+
/**
|
|
502
|
+
* 符合选择器的第一个后代节点
|
|
503
|
+
* @param selector 选择器
|
|
504
|
+
*/
|
|
494
505
|
querySelector(selector) {
|
|
495
|
-
return this.#queryStack(parseSelector(selector));
|
|
506
|
+
return this.#queryStack((0, selector_1.parseSelector)(selector));
|
|
496
507
|
}
|
|
497
508
|
/**
|
|
498
509
|
* 符合组合选择器的所有后代节点
|
|
@@ -508,40 +519,35 @@ class AstElement extends AstNode {
|
|
|
508
519
|
}
|
|
509
520
|
return descendants;
|
|
510
521
|
}
|
|
511
|
-
/**
|
|
522
|
+
/**
|
|
523
|
+
* 符合选择器的所有后代节点
|
|
524
|
+
* @param selector 选择器
|
|
525
|
+
*/
|
|
512
526
|
querySelectorAll(selector) {
|
|
513
|
-
return this.#queryStackAll(parseSelector(selector));
|
|
527
|
+
return this.#queryStackAll((0, selector_1.parseSelector)(selector));
|
|
514
528
|
}
|
|
515
529
|
/**
|
|
516
530
|
* id选择器
|
|
517
531
|
* @param id id名
|
|
518
532
|
*/
|
|
519
533
|
getElementById(id) {
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
return this.querySelector(`ext[id="${eid}"], html[id="${eid}"]`);
|
|
523
|
-
}
|
|
524
|
-
return this.typeError('getElementById', 'String');
|
|
534
|
+
const eid = id.replace(/(?<!\\)"/gu, '\\"');
|
|
535
|
+
return this.querySelector(`ext[id="${eid}"], html[id="${eid}"]`);
|
|
525
536
|
}
|
|
526
537
|
/**
|
|
527
538
|
* 类选择器
|
|
528
539
|
* @param className 类名之一
|
|
529
540
|
*/
|
|
530
541
|
getElementsByClassName(className) {
|
|
531
|
-
return
|
|
532
|
-
? this.querySelectorAll(`[className~="${className.replace(/(?<!\\)"/gu, '\\"')}"]`)
|
|
533
|
-
: this.typeError('getElementsByClassName', 'String');
|
|
542
|
+
return this.querySelectorAll(`[className~="${className.replace(/(?<!\\)"/gu, '\\"')}"]`);
|
|
534
543
|
}
|
|
535
544
|
/**
|
|
536
545
|
* 标签名选择器
|
|
537
546
|
* @param name 标签名
|
|
538
547
|
*/
|
|
539
548
|
getElementsByTagName(name) {
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
return this.querySelectorAll(`ext[name="${ename}"], html[name="${ename}"]`);
|
|
543
|
-
}
|
|
544
|
-
return this.typeError('getElementsByTagName', 'String');
|
|
549
|
+
const ename = name.replace(/(?<!\\)"/gu, '\\"');
|
|
550
|
+
return this.querySelectorAll(`ext[name="${ename}"], html[name="${ename}"]`);
|
|
545
551
|
}
|
|
546
552
|
/**
|
|
547
553
|
* 获取某一行的wikitext
|
|
@@ -567,7 +573,7 @@ class AstElement extends AstNode {
|
|
|
567
573
|
#getChildIndex(node) {
|
|
568
574
|
const i = this.childNodes.indexOf(node);
|
|
569
575
|
if (i === -1) {
|
|
570
|
-
|
|
576
|
+
index_1.default.error('找不到子节点!', node);
|
|
571
577
|
throw new RangeError('找不到子节点!');
|
|
572
578
|
}
|
|
573
579
|
return i;
|
|
@@ -606,15 +612,12 @@ class AstElement extends AstNode {
|
|
|
606
612
|
* @param depth 当前深度
|
|
607
613
|
*/
|
|
608
614
|
echo(depth = 0) {
|
|
609
|
-
if (!Number.isInteger(depth) || depth < 0) {
|
|
610
|
-
this.typeError('print', 'Number');
|
|
611
|
-
}
|
|
612
615
|
const indent = ' '.repeat(depth), str = String(this), { childNodes, type, length } = this;
|
|
613
616
|
if (childNodes.every(child => child.type === 'text' || !String(child))) {
|
|
614
617
|
console.log(`${indent}\x1B[32m<%s>\x1B[0m${(0, string_1.noWrap)(str)}\x1B[32m</%s>\x1B[0m`, type, type);
|
|
615
618
|
return;
|
|
616
619
|
}
|
|
617
|
-
|
|
620
|
+
index_1.default.info(`${indent}<${type}>`);
|
|
618
621
|
let i = this.getPadding();
|
|
619
622
|
if (i) {
|
|
620
623
|
console.log(`${indent} ${(0, string_1.noWrap)(str.slice(0, i))}`);
|
|
@@ -625,7 +628,7 @@ class AstElement extends AstNode {
|
|
|
625
628
|
// pass
|
|
626
629
|
}
|
|
627
630
|
else if (child.type === 'text') {
|
|
628
|
-
console.log(`${indent} ${(0, string_1.noWrap)(
|
|
631
|
+
console.log(`${indent} ${(0, string_1.noWrap)(child.data)}`);
|
|
629
632
|
}
|
|
630
633
|
else {
|
|
631
634
|
child.echo(depth + 1);
|
|
@@ -639,9 +642,10 @@ class AstElement extends AstNode {
|
|
|
639
642
|
if (i < str.length) {
|
|
640
643
|
console.log(`${indent} ${(0, string_1.noWrap)(str.slice(i))}`);
|
|
641
644
|
}
|
|
642
|
-
|
|
645
|
+
index_1.default.info(`${indent}</${type}>`);
|
|
643
646
|
}
|
|
644
647
|
}
|
|
648
|
+
exports.AstElement = AstElement;
|
|
645
649
|
/**
|
|
646
650
|
* 检测:lang()伪选择器
|
|
647
651
|
* @param node 节点
|
|
@@ -652,5 +656,4 @@ const matchesLang = ({ attributes }, regex) => {
|
|
|
652
656
|
const lang = attributes?.['lang'];
|
|
653
657
|
return typeof lang === 'string' && regex.test(lang);
|
|
654
658
|
};
|
|
655
|
-
|
|
656
|
-
module.exports = AstElement;
|
|
659
|
+
index_1.default.classes['AstElement'] = __filename;
|
package/dist/lib/node.d.ts
CHANGED
|
@@ -1,53 +1,50 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
declare type TokenAttributeGetter<T extends string> = T extends 'acceptable' ? Record<string, Ranges> | undefined : TokenAttribute<T>;
|
|
6
|
-
declare type TokenAttributeSetter<T extends string> = T extends 'acceptable' ? Acceptable | undefined : TokenAttribute<T> | undefined;
|
|
7
|
-
declare interface Dimension {
|
|
1
|
+
import type { AstText, Token } from '../internal';
|
|
2
|
+
export type AstNodes = AstText | Token;
|
|
3
|
+
export type TokenTypes = 'root' | 'plain' | 'onlyinclude' | 'noinclude' | 'include' | 'comment' | 'ext' | 'ext-attrs' | 'ext-attr-dirty' | 'ext-attr' | 'attr-key' | 'attr-value' | 'ext-inner' | 'arg' | 'arg-name' | 'arg-default' | 'hidden' | 'magic-word' | 'magic-word-name' | 'invoke-function' | 'invoke-module' | 'template' | 'template-name' | 'parameter' | 'parameter-key' | 'parameter-value' | 'heading' | 'heading-title' | 'heading-trail' | 'html' | 'html-attrs' | 'html-attr-dirty' | 'html-attr' | 'table' | 'tr' | 'td' | 'table-syntax' | 'table-attrs' | 'table-attr-dirty' | 'table-attr' | 'table-inter' | 'td-inner' | 'hr' | 'double-underscore' | 'link' | 'link-target' | 'link-text' | 'category' | 'file' | 'gallery-image' | 'imagemap-image' | 'image-parameter' | 'quote' | 'ext-link' | 'ext-link-text' | 'ext-link-url' | 'free-ext-link' | 'list' | 'dd' | 'converter' | 'converter-flags' | 'converter-flag' | 'converter-rule' | 'converter-rule-noconvert' | 'converter-rule-variant' | 'converter-rule-to' | 'converter-rule-from' | 'param-line' | 'imagemap-link';
|
|
4
|
+
export interface Dimension {
|
|
8
5
|
height: number;
|
|
9
6
|
width: number;
|
|
10
7
|
}
|
|
11
|
-
|
|
8
|
+
export interface Position {
|
|
12
9
|
top: number;
|
|
13
10
|
left: number;
|
|
14
11
|
}
|
|
15
|
-
|
|
16
|
-
offsetNode:
|
|
12
|
+
export interface CaretPosition {
|
|
13
|
+
offsetNode: AstNodes;
|
|
17
14
|
offset: number;
|
|
18
15
|
}
|
|
19
16
|
/** 类似Node */
|
|
20
|
-
declare abstract class AstNode {
|
|
17
|
+
export declare abstract class AstNode {
|
|
21
18
|
#private;
|
|
22
19
|
/** @browser */
|
|
23
|
-
type:
|
|
20
|
+
type: TokenTypes | 'text';
|
|
24
21
|
/** @browser */
|
|
25
|
-
readonly childNodes:
|
|
22
|
+
readonly childNodes: AstNodes[];
|
|
26
23
|
/**
|
|
27
24
|
* 首位子节点
|
|
28
25
|
* @browser
|
|
29
26
|
*/
|
|
30
|
-
get firstChild():
|
|
27
|
+
get firstChild(): AstNodes | undefined;
|
|
31
28
|
/**
|
|
32
29
|
* 末位子节点
|
|
33
30
|
* @browser
|
|
34
31
|
*/
|
|
35
|
-
get lastChild():
|
|
32
|
+
get lastChild(): AstNodes | undefined;
|
|
36
33
|
/**
|
|
37
34
|
* 父节点
|
|
38
35
|
* @browser
|
|
39
36
|
*/
|
|
40
|
-
get parentNode():
|
|
37
|
+
get parentNode(): Token | undefined;
|
|
41
38
|
/**
|
|
42
39
|
* 后一个兄弟节点
|
|
43
40
|
* @browser
|
|
44
41
|
*/
|
|
45
|
-
get nextSibling():
|
|
42
|
+
get nextSibling(): AstNodes | undefined;
|
|
46
43
|
/**
|
|
47
44
|
* 前一个兄弟节点
|
|
48
45
|
* @browser
|
|
49
46
|
*/
|
|
50
|
-
get previousSibling():
|
|
47
|
+
get previousSibling(): AstNodes | undefined;
|
|
51
48
|
/**
|
|
52
49
|
* 行数
|
|
53
50
|
* @browser
|
|
@@ -59,13 +56,13 @@ declare abstract class AstNode {
|
|
|
59
56
|
*/
|
|
60
57
|
get offsetWidth(): number;
|
|
61
58
|
/** 后一个非文本兄弟节点 */
|
|
62
|
-
get nextElementSibling():
|
|
59
|
+
get nextElementSibling(): Token | undefined;
|
|
63
60
|
/** 前一个非文本兄弟节点 */
|
|
64
|
-
get previousElementSibling():
|
|
61
|
+
get previousElementSibling(): Token | undefined;
|
|
65
62
|
/** 是否具有根节点 */
|
|
66
63
|
get isConnected(): boolean;
|
|
67
64
|
/** 不是自身的根节点 */
|
|
68
|
-
get ownerDocument():
|
|
65
|
+
get ownerDocument(): Token | undefined;
|
|
69
66
|
/** 后方是否还有其他节点(不含后代) */
|
|
70
67
|
get eof(): boolean | undefined;
|
|
71
68
|
/** 相对于父容器的行号 */
|
|
@@ -81,7 +78,7 @@ declare abstract class AstNode {
|
|
|
81
78
|
* 获取根节点
|
|
82
79
|
* @browser
|
|
83
80
|
*/
|
|
84
|
-
getRootNode():
|
|
81
|
+
getRootNode(): Token | this;
|
|
85
82
|
/**
|
|
86
83
|
* 将字符位置转换为行列号
|
|
87
84
|
* @browser
|
|
@@ -109,12 +106,12 @@ declare abstract class AstNode {
|
|
|
109
106
|
* 在后方批量插入兄弟节点
|
|
110
107
|
* @param nodes 插入节点
|
|
111
108
|
*/
|
|
112
|
-
after(...nodes: (
|
|
109
|
+
after(...nodes: (AstNodes | string)[]): void;
|
|
113
110
|
/**
|
|
114
111
|
* 在前方批量插入兄弟节点
|
|
115
112
|
* @param nodes 插入节点
|
|
116
113
|
*/
|
|
117
|
-
before(...nodes: (
|
|
114
|
+
before(...nodes: (AstNodes | string)[]): void;
|
|
118
115
|
/**
|
|
119
116
|
* 移除当前节点
|
|
120
117
|
* @throws `Error` 不存在父节点
|
|
@@ -124,7 +121,7 @@ declare abstract class AstNode {
|
|
|
124
121
|
* 将当前节点批量替换为新的节点
|
|
125
122
|
* @param nodes 插入节点
|
|
126
123
|
*/
|
|
127
|
-
replaceWith(...nodes: (
|
|
124
|
+
replaceWith(...nodes: (AstNodes | string)[]): void;
|
|
128
125
|
/**
|
|
129
126
|
* 是自身或后代节点
|
|
130
127
|
* @param node 待检测节点
|
|
@@ -137,7 +134,7 @@ declare abstract class AstNode {
|
|
|
137
134
|
* @param options 选项
|
|
138
135
|
* @param options.once 仅执行一次
|
|
139
136
|
*/
|
|
140
|
-
addEventListener(types:
|
|
137
|
+
addEventListener(types: string | string[], listener: (...args: any[]) => void, options?: {
|
|
141
138
|
once?: boolean;
|
|
142
139
|
}): void;
|
|
143
140
|
/**
|
|
@@ -145,31 +142,31 @@ declare abstract class AstNode {
|
|
|
145
142
|
* @param types 事件类型
|
|
146
143
|
* @param listener 监听函数
|
|
147
144
|
*/
|
|
148
|
-
removeEventListener(types:
|
|
145
|
+
removeEventListener(types: string | string[], listener: (...args: any[]) => void): void;
|
|
149
146
|
/**
|
|
150
147
|
* 移除事件的所有监听
|
|
151
148
|
* @param types 事件类型
|
|
152
149
|
*/
|
|
153
|
-
removeAllEventListeners(types?:
|
|
150
|
+
removeAllEventListeners(types?: string | string[]): void;
|
|
154
151
|
/**
|
|
155
152
|
* 列举事件监听
|
|
156
153
|
* @param type 事件类型
|
|
157
154
|
*/
|
|
158
|
-
listEventListeners(type:
|
|
155
|
+
listEventListeners(type: string): Function[];
|
|
159
156
|
/**
|
|
160
157
|
* 触发事件
|
|
161
158
|
* @param e 事件对象
|
|
162
159
|
* @param data 事件数据
|
|
163
160
|
*/
|
|
164
|
-
dispatchEvent(e: Event, data:
|
|
161
|
+
dispatchEvent(e: Event, data: unknown): void;
|
|
165
162
|
/** 获取所有祖先节点 */
|
|
166
|
-
getAncestors():
|
|
163
|
+
getAncestors(): Token[];
|
|
167
164
|
/**
|
|
168
165
|
* 比较和另一个节点的相对位置
|
|
169
166
|
* @param other 待比较的节点
|
|
170
167
|
* @throws `Error` 不在同一个语法树
|
|
171
168
|
*/
|
|
172
|
-
compareDocumentPosition(other:
|
|
169
|
+
compareDocumentPosition(other: AstNodes): number;
|
|
173
170
|
/**
|
|
174
171
|
* 将行列号转换为字符位置
|
|
175
172
|
* @param top 行号
|
|
@@ -179,7 +176,3 @@ declare abstract class AstNode {
|
|
|
179
176
|
/** 获取当前节点的行列位置和大小 */
|
|
180
177
|
getBoundingClientRect(): Dimension & Position;
|
|
181
178
|
}
|
|
182
|
-
declare namespace AstNode {
|
|
183
|
-
export type { AstNodeTypes, TokenAttributeGetter, TokenAttributeSetter, Dimension, Position, CaretPosition, };
|
|
184
|
-
}
|
|
185
|
-
export = AstNode;
|