wikiparser-node 1.22.1 → 1.24.0

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 (100) hide show
  1. package/README.md +3 -3
  2. package/bin/config.js +2 -2
  3. package/bundle/bundle-es8.min.js +24 -24
  4. package/config/default.json +6 -0
  5. package/config/enwiki.json +2 -2
  6. package/config/llwiki.json +382 -261
  7. package/config/moegirl.json +325 -325
  8. package/coverage/badge.svg +1 -1
  9. package/dist/base.d.mts +18 -2
  10. package/dist/base.d.ts +18 -2
  11. package/dist/bin/config.js +17 -5
  12. package/dist/index.d.ts +3 -2
  13. package/dist/index.js +3 -6
  14. package/dist/lib/element.d.ts +10 -64
  15. package/dist/lib/element.js +28 -135
  16. package/dist/lib/lsp.d.ts +19 -1
  17. package/dist/lib/lsp.js +131 -16
  18. package/dist/lib/node.d.ts +5 -9
  19. package/dist/lib/node.js +26 -24
  20. package/dist/lib/range.d.ts +90 -4
  21. package/dist/lib/range.js +596 -391
  22. package/dist/lib/text.d.ts +17 -16
  23. package/dist/lib/text.js +78 -62
  24. package/dist/lib/title.js +5 -4
  25. package/dist/mixin/attributesParent.js +3 -13
  26. package/dist/mixin/elementLike.d.ts +65 -0
  27. package/dist/mixin/elementLike.js +96 -0
  28. package/dist/mixin/fixed.js +2 -3
  29. package/dist/mixin/gapped.js +2 -2
  30. package/dist/mixin/hidden.js +2 -2
  31. package/dist/mixin/multiLine.js +2 -2
  32. package/dist/mixin/noEscape.js +4 -2
  33. package/dist/mixin/nodeLike.d.ts +17 -0
  34. package/dist/mixin/nodeLike.js +29 -0
  35. package/dist/mixin/padded.js +2 -1
  36. package/dist/mixin/singleLine.js +2 -1
  37. package/dist/mixin/sol.js +2 -2
  38. package/dist/mixin/syntax.js +2 -2
  39. package/dist/parser/commentAndExt.js +7 -8
  40. package/dist/parser/externalLinks.js +2 -2
  41. package/dist/parser/hrAndDoubleUnderscore.js +8 -5
  42. package/dist/parser/selector.js +3 -0
  43. package/dist/src/arg.js +4 -4
  44. package/dist/src/atom.d.ts +1 -1
  45. package/dist/src/attribute.d.ts +1 -1
  46. package/dist/src/attribute.js +11 -10
  47. package/dist/src/attributes.js +4 -4
  48. package/dist/src/converter.js +1 -1
  49. package/dist/src/converterFlags.js +2 -2
  50. package/dist/src/gallery.js +8 -7
  51. package/dist/src/heading.js +16 -7
  52. package/dist/src/html.d.ts +8 -0
  53. package/dist/src/html.js +36 -14
  54. package/dist/src/imageParameter.js +2 -2
  55. package/dist/src/imagemap.js +2 -2
  56. package/dist/src/index.d.ts +5 -1
  57. package/dist/src/index.js +3 -2
  58. package/dist/src/link/base.js +5 -18
  59. package/dist/src/link/file.js +14 -5
  60. package/dist/src/link/galleryImage.js +2 -2
  61. package/dist/src/link/index.js +6 -3
  62. package/dist/src/link/redirectTarget.js +1 -1
  63. package/dist/src/magicLink.js +4 -4
  64. package/dist/src/nested.js +3 -3
  65. package/dist/src/nowiki/base.js +1 -1
  66. package/dist/src/nowiki/comment.js +1 -1
  67. package/dist/src/nowiki/index.js +2 -2
  68. package/dist/src/nowiki/quote.js +10 -10
  69. package/dist/src/onlyinclude.js +1 -1
  70. package/dist/src/paramTag/index.d.ts +1 -1
  71. package/dist/src/paramTag/index.js +1 -1
  72. package/dist/src/parameter.js +1 -1
  73. package/dist/src/redirect.js +2 -2
  74. package/dist/src/syntax.d.ts +1 -1
  75. package/dist/src/table/base.d.ts +3 -2
  76. package/dist/src/table/base.js +18 -15
  77. package/dist/src/table/index.d.ts +0 -1
  78. package/dist/src/table/index.js +7 -9
  79. package/dist/src/table/td.d.ts +1 -1
  80. package/dist/src/table/td.js +13 -21
  81. package/dist/src/tagPair/include.js +2 -2
  82. package/dist/src/tagPair/index.js +2 -2
  83. package/dist/src/transclude.js +9 -15
  84. package/dist/util/debug.js +2 -0
  85. package/dist/util/lint.js +89 -4
  86. package/dist/util/sharable.js +2 -2
  87. package/dist/util/sharable.mjs +2 -2
  88. package/dist/util/string.js +11 -10
  89. package/extensions/typings.d.ts +3 -1
  90. package/package.json +8 -9
  91. package/bundle/bundle-lsp.min.js +0 -32
  92. package/bundle/bundle.min.js +0 -29
  93. package/extensions/dist/base.js +0 -353
  94. package/extensions/dist/codejar.js +0 -57
  95. package/extensions/dist/editor.js +0 -159
  96. package/extensions/dist/highlight.js +0 -30
  97. package/extensions/dist/lint.js +0 -80
  98. package/extensions/dist/lsp.js +0 -83
  99. package/extensions/editor.css +0 -59
  100. package/extensions/ui.css +0 -1
package/dist/lib/lsp.js CHANGED
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.LanguageService = exports.isAttr = exports.tasks = void 0;
7
7
  const common_1 = require("@bhsd/common");
8
+ const base_1 = require("../base");
8
9
  const sharable_1 = require("../util/sharable");
9
10
  const lint_1 = require("../util/lint");
10
11
  const string_1 = require("../util/string");
@@ -21,14 +22,11 @@ const crypto_1 = require("crypto");
21
22
  const stylelint_util_1 = require("@bhsd/stylelint-util");
22
23
  const document_1 = require("./document");
23
24
  /** @see https://www.npmjs.com/package/stylelint-config-recommended */
24
- const cssRules = {
25
- 'block-no-empty': null,
26
- 'property-no-unknown': null,
27
- }, jsonSelector = document_1.jsonTags.map(s => `ext#${s}`).join(), mathTags = ['math', 'chem', 'ce'], mathSelector = mathTags.map(s => `ext#${s}`).join(), scores = new Map();
25
+ const cssRules = { 'block-no-empty': null }, jsonSelector = document_1.jsonTags.map(s => `ext#${s}`).join(), mathTags = ['math', 'chem', 'ce'], mathSelector = mathTags.map(s => `ext#${s}`).join(), scores = new Map();
28
26
  let colors;
29
27
  /* NOT FOR BROWSER ONLY END */
30
28
  exports.tasks = new WeakMap();
31
- const refTags = new Set(['ref']), referencesTags = new Set(['ref', 'references']), nameAttrs = new Set(['name', 'extends', 'follow']), groupAttrs = new Set(['group']), renameTypes = new Set([
29
+ const refTags = new Set(['ref']), referencesTags = new Set(['ref', 'references']), nameAttrs = new Set(['name', 'follow']), groupAttrs = new Set(['group']), renameTypes = new Set([
32
30
  'arg-name',
33
31
  'template-name',
34
32
  'link-target',
@@ -204,6 +202,32 @@ const getQuickFix = (root, fix, preferred = false) => ({
204
202
  title: `${preferred ? 'Fix' : 'Suggestion'}: ${fix.desc}`,
205
203
  fix: preferred,
206
204
  });
205
+ /**
206
+ * Get the fix-all data.
207
+ * @param root root token
208
+ * @param rule rule to be fixed
209
+ */
210
+ const getFixAll = (root, rule) => {
211
+ const { lintConfig } = index_1.default;
212
+ if (rule) {
213
+ index_1.default.lintConfig = {};
214
+ for (const key of base_1.rules) {
215
+ index_1.default.lintConfig[key] = key === rule ? lintConfig[key] : 0;
216
+ }
217
+ }
218
+ const { output } = root.lint();
219
+ if (rule) {
220
+ index_1.default.lintConfig = lintConfig;
221
+ }
222
+ return output === undefined
223
+ ? []
224
+ : [
225
+ {
226
+ range: createNodeRange(root),
227
+ newText: output,
228
+ },
229
+ ];
230
+ };
207
231
  /* NOT FOR BROWSER ONLY */
208
232
  /**
209
233
  * Correct the position of an error.
@@ -909,6 +933,27 @@ class LanguageService {
909
933
  mathDiagnostics,
910
934
  ].flat(2);
911
935
  }
936
+ /**
937
+ * Resolve fix-all code action
938
+ *
939
+ * 实现修复全部代码的操作
940
+ * @param action code action / 代码操作
941
+ * @since v1.24.0
942
+ */
943
+ resolveCodeAction(action) {
944
+ if (action.kind !== 'source.fixAll') {
945
+ return action;
946
+ }
947
+ const { rule } = action.data;
948
+ return {
949
+ ...action,
950
+ edit: {
951
+ changes: {
952
+ '': getFixAll(this.#done, rule),
953
+ },
954
+ },
955
+ };
956
+ }
912
957
  /**
913
958
  * Provide folding ranges
914
959
  *
@@ -1344,6 +1389,54 @@ class LanguageService {
1344
1389
  findStyleTokens() {
1345
1390
  return this.#done.querySelectorAll(cssSelector).filter(({ lastChild }) => (0, exports.isAttr)(lastChild));
1346
1391
  }
1392
+ /**
1393
+ * Provide refactoring actions
1394
+ *
1395
+ * 提供重构操作
1396
+ * @param text source Wikitext / 源代码
1397
+ * @param range range of the refactoring / 重构范围
1398
+ * @since v1.24.0
1399
+ */
1400
+ async provideRefactoringAction(text, range) {
1401
+ let lines, selected;
1402
+ if (range) {
1403
+ const { start, end } = range;
1404
+ if (start.line === end.line && start.character === end.character) {
1405
+ return [];
1406
+ }
1407
+ lines = text.split(/\r?\n/u, end.line + 1);
1408
+ selected = start.line === end.line
1409
+ ? lines[end.line].slice(start.character, end.character)
1410
+ : `${lines[start.line].slice(start.character)}\n${lines.slice(start.line + 1, end.line).join('\n')}${lines.length === 2 ? '' : '\n'}${lines[end.line].slice(0, end.character)}`;
1411
+ }
1412
+ else if (text) {
1413
+ lines = text.split(/\r?\n/u);
1414
+ selected = lines.join('\n');
1415
+ range = {
1416
+ start: { line: 0, character: 0 },
1417
+ end: { line: lines.length - 1, character: lines[lines.length - 1].length },
1418
+ };
1419
+ }
1420
+ else {
1421
+ return [];
1422
+ }
1423
+ const root = await this.#queueSignature(selected);
1424
+ const { viewOnly } = index_1.default;
1425
+ index_1.default.viewOnly = false;
1426
+ root.escape();
1427
+ index_1.default.viewOnly = viewOnly;
1428
+ return [
1429
+ {
1430
+ title: 'Escape with magic words',
1431
+ kind: 'refactor.rewrite',
1432
+ edit: {
1433
+ changes: {
1434
+ '': [{ range, newText: root.toString() }],
1435
+ },
1436
+ },
1437
+ },
1438
+ ];
1439
+ }
1347
1440
  /* NOT FOR BROWSER ONLY */
1348
1441
  /**
1349
1442
  * Provide quick fixes
@@ -1353,15 +1446,36 @@ class LanguageService {
1353
1446
  */
1354
1447
  // eslint-disable-next-line @typescript-eslint/class-methods-use-this
1355
1448
  provideCodeAction(diagnostics) {
1356
- return diagnostics.filter((diagnostic) => diagnostic.data).flatMap(diagnostic => diagnostic.data.map((data) => ({
1357
- title: data.title,
1358
- kind: 'quickfix',
1359
- diagnostics: [diagnostic],
1360
- isPreferred: data.fix,
1361
- edit: {
1362
- changes: { '': [data] },
1363
- },
1364
- })));
1449
+ const actionable = diagnostics.filter((diagnostic) => diagnostic.data), fixable = actionable.filter(({ source, data }) => source === 'WikiLint' && data.some(({ fix }) => fix)), fixableRules = [...new Set(fixable.map(({ code }) => code))];
1450
+ return [
1451
+ ...actionable.flatMap(diagnostic => diagnostic.data.map((data) => ({
1452
+ title: data.title,
1453
+ kind: 'quickfix',
1454
+ diagnostics: [diagnostic],
1455
+ isPreferred: data.fix,
1456
+ edit: {
1457
+ changes: { '': [data] },
1458
+ },
1459
+ }))),
1460
+ ...fixable.length === 0
1461
+ ? []
1462
+ : [
1463
+ ...fixableRules.map((rule) => ({
1464
+ title: `Fix all: ${rule}`,
1465
+ kind: 'source.fixAll',
1466
+ diagnostics: fixable.filter(({ code }) => code === rule),
1467
+ isPreferred: true,
1468
+ data: { rule },
1469
+ })),
1470
+ {
1471
+ title: 'Fix all: WikiLint',
1472
+ kind: 'source.fixAll',
1473
+ diagnostics: fixable,
1474
+ isPreferred: true,
1475
+ data: {},
1476
+ },
1477
+ ],
1478
+ ];
1365
1479
  }
1366
1480
  /**
1367
1481
  * Provide document sections
@@ -1409,17 +1523,18 @@ class LanguageService {
1409
1523
  *
1410
1524
  * 设置目标维基百科
1411
1525
  * @param wiki Wikipedia URL / 维基百科网址
1526
+ * @param user URI for wiki userpage or email address of the user / 维基用户页面地址或用户的电子邮件地址
1412
1527
  * @throws `RangeError` 不是有效的维基百科网址
1413
1528
  * @since v1.18.1
1414
1529
  */
1415
- async setTargetWikipedia(wiki) {
1530
+ async setTargetWikipedia(wiki, user) {
1416
1531
  const [site, host] = index_1.default.getWMFSite(wiki);
1417
1532
  try {
1418
1533
  const config = require(path_1.default.join('..', '..', 'config', site));
1419
1534
  this.config = index_1.default.getConfig(config);
1420
1535
  }
1421
1536
  catch {
1422
- this.config = await index_1.default.fetchConfig(site, `${host}/w`);
1537
+ this.config = await index_1.default.fetchConfig(site, `${host}/w`, user);
1423
1538
  }
1424
1539
  Object.assign(this.config, { articlePath: `${host}/wiki/` });
1425
1540
  }
@@ -1,4 +1,5 @@
1
1
  import type { LintError, AstNode as AstNodeBase, TokenTypes } from '../base';
2
+ import type { NodeLike } from '../mixin/nodeLike';
2
3
  import type { AstText, Token } from '../internal';
3
4
  export type AstNodes = AstText | Token;
4
5
  export interface Dimension {
@@ -17,6 +18,8 @@ export interface Font {
17
18
  bold: boolean;
18
19
  italic: boolean;
19
20
  }
21
+ export interface AstNode extends NodeLike {
22
+ }
20
23
  /**
21
24
  * Node-like
22
25
  *
@@ -38,20 +41,12 @@ export declare abstract class AstNode implements AstNodeBase {
38
41
  output?: string;
39
42
  };
40
43
  print(): string;
41
- /** first child node / 首位子节点 */
42
- get firstChild(): AstNodes | undefined;
43
- /** last child node / 末位子节点 */
44
- get lastChild(): AstNodes | undefined;
45
44
  /** parent node / 父节点 */
46
45
  get parentNode(): Token | undefined;
47
46
  /** next sibling node / 后一个兄弟节点 */
48
47
  get nextSibling(): AstNodes | undefined;
49
48
  /** previous sibling node / 前一个兄弟节点 */
50
49
  get previousSibling(): AstNodes | undefined;
51
- /** number of lines / 行数 */
52
- get offsetHeight(): number;
53
- /** number of columns of the last line / 最后一行的列数 */
54
- get offsetWidth(): number;
55
50
  /** next sibling element / 后一个非文本兄弟节点 */
56
51
  get nextElementSibling(): Token | undefined;
57
52
  /** previous sibling element / 前一个非文本兄弟节点 */
@@ -175,8 +170,9 @@ export declare abstract class AstNode implements AstNodeBase {
175
170
  * Remove the current node
176
171
  *
177
172
  * 移除当前节点
173
+ * @param ownLine whether to remove the current line if it is empty / 是否删除所在的空行
178
174
  */
179
- remove(): void;
175
+ remove(ownLine?: boolean): void;
180
176
  /**
181
177
  * Replace the current node with new nodes
182
178
  *
package/dist/lib/node.js CHANGED
@@ -42,6 +42,7 @@ exports.AstNode = void 0;
42
42
  const lint_1 = require("../util/lint");
43
43
  const debug_1 = require("../util/debug");
44
44
  const cached_1 = require("../mixin/cached");
45
+ const nodeLike_1 = require("../mixin/nodeLike");
45
46
  /* PRINT ONLY */
46
47
  const index_1 = __importDefault(require("../index"));
47
48
  /* PRINT ONLY END */
@@ -55,14 +56,22 @@ const constants_1 = require("../util/constants");
55
56
  * 类似Node
56
57
  */
57
58
  let AstNode = (() => {
59
+ let _classDecorators = [nodeLike_1.nodeLike];
60
+ let _classDescriptor;
61
+ let _classExtraInitializers = [];
62
+ let _classThis;
58
63
  let _instanceExtraInitializers = [];
59
64
  let _getLines_decorators;
60
- return class AstNode {
65
+ var AstNode = class {
66
+ static { _classThis = this; }
61
67
  static {
62
68
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
63
69
  _getLines_decorators = [(0, cached_1.cached)(false)];
64
70
  __esDecorate(this, null, _getLines_decorators, { kind: "method", name: "getLines", static: false, private: false, access: { has: obj => "getLines" in obj, get: obj => obj.getLines }, metadata: _metadata }, null, _instanceExtraInitializers);
65
- if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
71
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
72
+ AstNode = _classThis = _classDescriptor.value;
73
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
74
+ __runInitializers(_classThis, _classExtraInitializers);
66
75
  }
67
76
  childNodes = (__runInitializers(this, _instanceExtraInitializers), []);
68
77
  #parentNode;
@@ -74,14 +83,6 @@ let AstNode = (() => {
74
83
  /* NOT FOR BROWSER */
75
84
  #optional = new Set();
76
85
  #events = new events_1.EventEmitter();
77
- /** first child node / 首位子节点 */
78
- get firstChild() {
79
- return this.childNodes[0];
80
- }
81
- /** last child node / 末位子节点 */
82
- get lastChild() {
83
- return this.childNodes[this.childNodes.length - 1];
84
- }
85
86
  /** parent node / 父节点 */
86
87
  get parentNode() {
87
88
  return this.#parentNode;
@@ -94,14 +95,6 @@ let AstNode = (() => {
94
95
  get previousSibling() {
95
96
  return this.#previousSibling;
96
97
  }
97
- /** number of lines / 行数 */
98
- get offsetHeight() {
99
- return this.#getDimension().height;
100
- }
101
- /** number of columns of the last line / 最后一行的列数 */
102
- get offsetWidth() {
103
- return this.#getDimension().width;
104
- }
105
98
  /* NOT FOR BROWSER */
106
99
  /** next sibling element / 后一个非文本兄弟节点 */
107
100
  get nextElementSibling() {
@@ -159,7 +152,7 @@ let AstNode = (() => {
159
152
  get style() {
160
153
  return {
161
154
  ...this.#getPosition(),
162
- ...this.#getDimension(),
155
+ ...this.getDimension(),
163
156
  padding: this.getAttribute('padding'),
164
157
  };
165
158
  }
@@ -300,8 +293,8 @@ let AstNode = (() => {
300
293
  }
301
294
  return undefined;
302
295
  }
303
- /** 获取行数和最后一行的列数 */
304
- #getDimension() {
296
+ /** @private */
297
+ getDimension() {
305
298
  const lines = this.getLines(), last = lines[lines.length - 1];
306
299
  return { height: lines.length, width: last[2] - last[1] };
307
300
  }
@@ -360,7 +353,7 @@ let AstNode = (() => {
360
353
  getBoundingClientRect() {
361
354
  // eslint-disable-next-line no-unused-labels
362
355
  LSP: return {
363
- ...this.#getDimension(),
356
+ ...this.getDimension(),
364
357
  ...this.getRootNode().posFromIndex(this.getAbsoluteIndex()),
365
358
  };
366
359
  }
@@ -473,9 +466,17 @@ let AstNode = (() => {
473
466
  * Remove the current node
474
467
  *
475
468
  * 移除当前节点
469
+ * @param ownLine whether to remove the current line if it is empty / 是否删除所在的空行
476
470
  */
477
- remove() {
478
- this.parentNode?.removeChild(this);
471
+ remove(ownLine) {
472
+ const { parentNode, nextSibling, previousSibling } = this, i = parentNode?.childNodes.indexOf(this);
473
+ parentNode?.removeAt(i);
474
+ if (ownLine
475
+ && parentNode?.getGaps(i - 1) === 0
476
+ && nextSibling?.type === 'text' && previousSibling?.type === 'text'
477
+ && nextSibling.data.startsWith('\n') && previousSibling.data.endsWith('\n')) {
478
+ nextSibling.deleteData(0, 1);
479
+ }
479
480
  }
480
481
  /**
481
482
  * Replace the current node with new nodes
@@ -709,6 +710,7 @@ let AstNode = (() => {
709
710
  return { bold: Boolean(bold), italic: Boolean(italic), b, i };
710
711
  }
711
712
  };
713
+ return AstNode = _classThis;
712
714
  })();
713
715
  exports.AstNode = AstNode;
714
716
  constants_1.classes['AstNode'] = __filename;
@@ -1,5 +1,9 @@
1
- import type { AstNodes } from '../internal';
1
+ import type { NodeLike } from '../mixin/nodeLike';
2
+ import type { ElementLike } from '../mixin/elementLike';
3
+ import type { AstNodes, Token } from '../internal';
2
4
  import type { Dimension, Position } from './node';
5
+ export interface AstRange extends NodeLike, ElementLike {
6
+ }
3
7
  /**
4
8
  * Range-like
5
9
  *
@@ -27,6 +31,13 @@ export declare class AstRange {
27
31
  get collapsed(): boolean;
28
32
  /** closest common ancestor / 最近的公共祖先 */
29
33
  get commonAncestorContainer(): AstNodes;
34
+ /**
35
+ * nodes in the Range
36
+ *
37
+ * 范围内的节点
38
+ * @since v1.23.0
39
+ */
40
+ get childNodes(): AstNodes[];
30
41
  /**
31
42
  * Set the start
32
43
  *
@@ -129,6 +140,13 @@ export declare class AstRange {
129
140
  * 删除Range中的内容
130
141
  */
131
142
  deleteContents(): void;
143
+ /**
144
+ * Remove the contents of the Range
145
+ *
146
+ * 删除Range中的内容
147
+ * @since v1.23.0
148
+ */
149
+ remove(): void;
132
150
  /**
133
151
  * Get the position and dimension
134
152
  *
@@ -136,12 +154,44 @@ export declare class AstRange {
136
154
  */
137
155
  getBoundingClientRect(): Dimension & Position;
138
156
  /**
139
- * Insert a node at the start
157
+ * Get the client rects of all nodes in the Range
140
158
  *
141
- * 在起始位置插入节点
159
+ * 获取范围内所有节点的行列位置和大小
160
+ * @since v1.23.0
161
+ */
162
+ getClientRects(): (Dimension & Position)[];
163
+ /**
164
+ * Insert a node before or after the Range
165
+ *
166
+ * 在范围前或后插入节点
142
167
  * @param newNode node to be inserted / 插入的节点
168
+ * @param after whether to insert after the Range / 是否在范围后插入
169
+ */
170
+ insertNode(newNode: AstNodes | string, after?: boolean): void;
171
+ /**
172
+ * Insert nodes before the Range
173
+ *
174
+ * 在范围前插入节点
175
+ * @param nodes nodes to be inserted / 插入节点
176
+ * @since v1.23.0
177
+ */
178
+ before(...nodes: (AstNodes | string)[]): void;
179
+ /**
180
+ * Insert nodes after the Range
181
+ *
182
+ * 在范围后插入节点
183
+ * @param nodes nodes to be inserted / 插入节点
184
+ * @since v1.23.0
143
185
  */
144
- insertNode(newNode: AstNodes | string): void;
186
+ after(...nodes: (AstNodes | string)[]): void;
187
+ /**
188
+ * Replace the Range with new nodes
189
+ *
190
+ * 将当前范围批量替换为新的节点
191
+ * @param nodes nodes to be inserted / 插入节点
192
+ * @since v1.23.0
193
+ */
194
+ replaceWith(...nodes: (AstNodes | string)[]): void;
145
195
  /**
146
196
  * Get the contents of the Range
147
197
  *
@@ -154,4 +204,40 @@ export declare class AstRange {
154
204
  * 拷贝范围内的全部节点
155
205
  */
156
206
  cloneContents(): AstNodes[];
207
+ /**
208
+ * Get the root node
209
+ *
210
+ * 获取根节点
211
+ * @since v1.23.0
212
+ */
213
+ getRootNode(): AstNodes;
214
+ /**
215
+ * Get the closest ancestor node that matches the selector
216
+ *
217
+ * 最近的符合选择器的祖先节点
218
+ * @param selector selector / 选择器
219
+ */
220
+ closest<T = Token>(selector: string): T | undefined;
221
+ /**
222
+ * Insert a batch of child nodes at the end
223
+ *
224
+ * 在末尾批量插入子节点
225
+ * @param elements nodes to be inserted / 插入节点
226
+ */
227
+ append(...elements: (AstNodes | string)[]): void;
228
+ /**
229
+ * Insert a batch of child nodes at the start
230
+ *
231
+ * 在开头批量插入子节点
232
+ * @param elements nodes to be inserted / 插入节点
233
+ */
234
+ prepend(...elements: (AstNodes | string)[]): void;
235
+ /**
236
+ * Remove a child node
237
+ *
238
+ * 移除子节点
239
+ * @param node child node to be removed / 子节点
240
+ * @throws `RangeError` 不是子节点
241
+ */
242
+ removeChild<T extends AstNodes>(node: T): T;
157
243
  }