wikiparser-node 1.9.2-b → 1.9.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.
Files changed (173) hide show
  1. package/README.md +18 -18
  2. package/config/.schema.json +181 -0
  3. package/config/enwiki.json +814 -1
  4. package/config/llwiki.json +35 -1
  5. package/config/moegirl.json +44 -1
  6. package/config/zhwiki.json +466 -1
  7. package/dist/addon/table.js +486 -0
  8. package/dist/addon/token.js +240 -0
  9. package/dist/addon/transclude.js +185 -0
  10. package/dist/base.d.ts +73 -0
  11. package/dist/base.js +39 -0
  12. package/dist/index.d.ts +31 -0
  13. package/dist/index.js +232 -0
  14. package/dist/internal.d.ts +46 -0
  15. package/dist/lib/element.d.ts +124 -0
  16. package/dist/lib/element.js +600 -0
  17. package/dist/lib/node.d.ts +166 -0
  18. package/dist/lib/node.js +472 -0
  19. package/dist/lib/range.d.ts +105 -0
  20. package/dist/lib/range.js +406 -0
  21. package/dist/lib/ranges.d.ts +28 -0
  22. package/dist/lib/ranges.js +126 -0
  23. package/dist/lib/rect.d.ts +18 -0
  24. package/dist/lib/rect.js +34 -0
  25. package/dist/lib/text.d.ts +54 -0
  26. package/dist/lib/text.js +345 -0
  27. package/dist/lib/title.d.ts +40 -0
  28. package/dist/lib/title.js +197 -0
  29. package/dist/mixin/attributesParent.d.ts +49 -0
  30. package/dist/mixin/attributesParent.js +82 -0
  31. package/dist/mixin/fixed.d.ts +5 -0
  32. package/dist/mixin/fixed.js +32 -0
  33. package/dist/mixin/flagsParent.d.ts +41 -0
  34. package/dist/mixin/flagsParent.js +60 -0
  35. package/dist/mixin/hidden.d.ts +6 -0
  36. package/dist/mixin/hidden.js +29 -0
  37. package/dist/mixin/magicLinkParent.d.ts +19 -0
  38. package/dist/mixin/magicLinkParent.js +43 -0
  39. package/dist/mixin/singleLine.d.ts +5 -0
  40. package/dist/mixin/singleLine.js +27 -0
  41. package/dist/mixin/sol.d.ts +5 -0
  42. package/dist/mixin/sol.js +44 -0
  43. package/dist/mixin/syntax.d.ts +8 -0
  44. package/dist/mixin/syntax.js +47 -0
  45. package/dist/parser/braces.js +150 -0
  46. package/dist/parser/commentAndExt.js +79 -0
  47. package/dist/parser/converter.js +39 -0
  48. package/dist/parser/externalLinks.js +37 -0
  49. package/dist/parser/hrAndDoubleUnderscore.js +42 -0
  50. package/dist/parser/html.js +38 -0
  51. package/dist/parser/links.js +101 -0
  52. package/dist/parser/list.js +97 -0
  53. package/dist/parser/magicLinks.js +53 -0
  54. package/dist/parser/quotes.js +67 -0
  55. package/dist/parser/redirect.js +26 -0
  56. package/dist/parser/selector.js +190 -0
  57. package/dist/parser/table.js +123 -0
  58. package/dist/src/arg.d.ts +52 -0
  59. package/dist/src/arg.js +213 -0
  60. package/dist/src/atom.d.ts +12 -0
  61. package/dist/src/atom.js +26 -0
  62. package/dist/src/attribute.d.ts +65 -0
  63. package/dist/src/attribute.js +483 -0
  64. package/dist/src/attributes.d.ts +103 -0
  65. package/dist/src/attributes.js +350 -0
  66. package/dist/src/converter.d.ts +29 -0
  67. package/dist/src/converter.js +134 -0
  68. package/dist/src/converterFlags.d.ts +81 -0
  69. package/dist/src/converterFlags.js +239 -0
  70. package/dist/src/converterRule.d.ts +73 -0
  71. package/dist/src/converterRule.js +210 -0
  72. package/dist/src/extLink.d.ts +37 -0
  73. package/dist/src/extLink.js +191 -0
  74. package/dist/src/gallery.d.ts +48 -0
  75. package/dist/src/gallery.js +139 -0
  76. package/dist/src/heading.d.ts +41 -0
  77. package/dist/src/heading.js +185 -0
  78. package/dist/src/hidden.d.ts +10 -0
  79. package/dist/src/hidden.js +79 -0
  80. package/dist/src/html.d.ts +58 -0
  81. package/dist/src/html.js +334 -0
  82. package/dist/src/imageParameter.d.ts +59 -0
  83. package/dist/src/imageParameter.js +246 -0
  84. package/dist/src/imagemap.d.ts +48 -0
  85. package/dist/src/imagemap.js +145 -0
  86. package/dist/src/imagemapLink.d.ts +31 -0
  87. package/dist/src/imagemapLink.js +93 -0
  88. package/dist/src/index.d.ts +130 -0
  89. package/dist/src/index.js +721 -0
  90. package/dist/src/link/base.d.ts +46 -0
  91. package/dist/src/link/base.js +224 -0
  92. package/dist/src/link/category.d.ts +22 -0
  93. package/dist/src/link/category.js +30 -0
  94. package/dist/src/link/file.d.ts +96 -0
  95. package/dist/src/link/file.js +274 -0
  96. package/dist/src/link/galleryImage.d.ts +30 -0
  97. package/dist/src/link/galleryImage.js +158 -0
  98. package/dist/src/link/index.d.ts +52 -0
  99. package/dist/src/link/index.js +133 -0
  100. package/dist/src/link/redirectTarget.d.ts +37 -0
  101. package/dist/src/link/redirectTarget.js +95 -0
  102. package/dist/src/magicLink.d.ts +60 -0
  103. package/dist/src/magicLink.js +270 -0
  104. package/dist/src/nested.d.ts +41 -0
  105. package/dist/src/nested.js +105 -0
  106. package/dist/src/nowiki/base.d.ts +31 -0
  107. package/dist/src/nowiki/base.js +91 -0
  108. package/dist/src/nowiki/comment.d.ts +15 -0
  109. package/dist/src/nowiki/comment.js +123 -0
  110. package/dist/src/nowiki/dd.d.ts +8 -0
  111. package/dist/src/nowiki/dd.js +24 -0
  112. package/dist/src/nowiki/doubleUnderscore.d.ts +16 -0
  113. package/dist/src/nowiki/doubleUnderscore.js +96 -0
  114. package/dist/src/nowiki/hr.d.ts +5 -0
  115. package/dist/src/nowiki/hr.js +63 -0
  116. package/dist/src/nowiki/index.d.ts +14 -0
  117. package/dist/src/nowiki/index.js +29 -0
  118. package/dist/src/nowiki/list.d.ts +16 -0
  119. package/dist/src/nowiki/list.js +109 -0
  120. package/dist/src/nowiki/listBase.d.ts +5 -0
  121. package/dist/src/nowiki/listBase.js +61 -0
  122. package/dist/src/nowiki/noinclude.d.ts +10 -0
  123. package/dist/src/nowiki/noinclude.js +73 -0
  124. package/dist/src/nowiki/quote.d.ts +17 -0
  125. package/dist/src/nowiki/quote.js +131 -0
  126. package/dist/src/onlyinclude.d.ts +14 -0
  127. package/dist/src/onlyinclude.js +57 -0
  128. package/dist/src/paramTag/index.d.ts +31 -0
  129. package/dist/src/paramTag/index.js +77 -0
  130. package/dist/src/paramTag/inputbox.d.ts +8 -0
  131. package/dist/src/paramTag/inputbox.js +22 -0
  132. package/dist/src/parameter.d.ts +66 -0
  133. package/dist/src/parameter.js +265 -0
  134. package/dist/src/pre.d.ts +29 -0
  135. package/dist/src/pre.js +59 -0
  136. package/dist/src/redirect.d.ts +31 -0
  137. package/dist/src/redirect.js +121 -0
  138. package/dist/src/syntax.d.ts +17 -0
  139. package/dist/src/syntax.js +84 -0
  140. package/dist/src/table/base.d.ts +29 -0
  141. package/dist/src/table/base.js +82 -0
  142. package/dist/src/table/index.d.ts +239 -0
  143. package/dist/src/table/index.js +502 -0
  144. package/dist/src/table/td.d.ts +78 -0
  145. package/dist/src/table/td.js +368 -0
  146. package/dist/src/table/tr.d.ts +30 -0
  147. package/dist/src/table/tr.js +57 -0
  148. package/dist/src/table/trBase.d.ts +49 -0
  149. package/dist/src/table/trBase.js +156 -0
  150. package/dist/src/tagPair/ext.d.ts +30 -0
  151. package/dist/src/tagPair/ext.js +201 -0
  152. package/dist/src/tagPair/include.d.ts +35 -0
  153. package/dist/src/tagPair/include.js +124 -0
  154. package/dist/src/tagPair/index.d.ts +23 -0
  155. package/dist/src/tagPair/index.js +128 -0
  156. package/dist/src/transclude.d.ts +160 -0
  157. package/dist/src/transclude.js +579 -0
  158. package/dist/util/constants.js +25 -0
  159. package/dist/util/debug.js +97 -0
  160. package/dist/util/diff.js +83 -0
  161. package/dist/util/lint.js +32 -0
  162. package/dist/util/string.js +60 -0
  163. package/errors/README +1 -0
  164. package/package.json +20 -30
  165. package/printed/README +1 -0
  166. package/README.en.md +0 -57
  167. package/bundle/bundle.min.js +0 -38
  168. package/extensions/dist/base.js +0 -64
  169. package/extensions/dist/editor.js +0 -159
  170. package/extensions/dist/highlight.js +0 -58
  171. package/extensions/dist/lint.js +0 -72
  172. package/extensions/editor.css +0 -64
  173. package/extensions/ui.css +0 -144
package/dist/index.js ADDED
@@ -0,0 +1,232 @@
1
+ "use strict";
2
+ /* eslint n/exports-style: 0 */
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const chalk = require("chalk");
6
+ const base_1 = require("./base");
7
+ const debug_1 = require("./util/debug");
8
+ const constants_1 = require("./util/constants");
9
+ const string_1 = require("./util/string");
10
+ const diff_1 = require("./util/diff");
11
+ /**
12
+ * 从根路径require
13
+ * @param file 文件名
14
+ * @param dir 子路径
15
+ */
16
+ const rootRequire = (file, dir) => require(file.startsWith('/') ? file : `../${file.includes('/') ? '' : dir}${file}`);
17
+ /* NOT FOR BROWSER */
18
+ const promises = [Promise.resolve()];
19
+ let viewOnly = false;
20
+ /* NOT FOR BROWSER END */
21
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
22
+ const Parser = {
23
+ config: 'default',
24
+ i18n: undefined,
25
+ rules: base_1.rules,
26
+ /* NOT FOR BROWSER */
27
+ /** @implements */
28
+ get viewOnly() {
29
+ return viewOnly;
30
+ },
31
+ set viewOnly(value) {
32
+ if (viewOnly && !value) {
33
+ debug_1.Shadow.rev++;
34
+ }
35
+ viewOnly = value;
36
+ },
37
+ conversionTable: new Map(),
38
+ redirects: new Map(),
39
+ warning: true,
40
+ debugging: false,
41
+ /* NOT FOR BROWSER END */
42
+ /** @implements */
43
+ getConfig() {
44
+ if (typeof this.config === 'string') {
45
+ this.config = rootRequire(this.config, 'config/');
46
+ /* NOT FOR BROWSER */
47
+ const { config: { conversionTable, redirects } } = this;
48
+ if (conversionTable) {
49
+ this.conversionTable = new Map(conversionTable);
50
+ }
51
+ if (redirects) {
52
+ this.redirects = new Map(redirects);
53
+ }
54
+ /* NOT FOR BROWSER END */
55
+ return this.getConfig();
56
+ }
57
+ return {
58
+ ...this.config,
59
+ excludes: [],
60
+ };
61
+ },
62
+ /** @implements */
63
+ msg(msg, arg = '') {
64
+ if (typeof this.i18n === 'string') {
65
+ this.i18n = rootRequire(this.i18n, 'i18n/');
66
+ return this.msg(msg, arg);
67
+ }
68
+ return msg && (this.i18n?.[msg] ?? msg).replace('$1', this.msg(arg));
69
+ },
70
+ /** @implements */
71
+ normalizeTitle(title, defaultNs = 0, include, config = Parser.getConfig(), halfParsed, decode = false, selfLink = false) {
72
+ const { Title } = require('./lib/title');
73
+ if (halfParsed) {
74
+ return new Title(title, defaultNs, config, decode, selfLink);
75
+ }
76
+ const { Token } = require('./src/index');
77
+ return debug_1.Shadow.run(() => {
78
+ const root = new Token(title, config);
79
+ root.type = 'root';
80
+ root.parseOnce(0, include).parseOnce();
81
+ const titleObj = new Title(root.toString(), defaultNs, config, decode, selfLink);
82
+ for (const key of ['main', 'fragment']) {
83
+ const str = titleObj[key];
84
+ if (str?.includes('\0')) {
85
+ titleObj[key] = root.buildFromStr(str, constants_1.BuildMethod.Text);
86
+ }
87
+ }
88
+ /* NOT FOR BROWSER */
89
+ titleObj.conversionTable = this.conversionTable;
90
+ titleObj.redirects = this.redirects;
91
+ /* NOT FOR BROWSER END */
92
+ return titleObj;
93
+ });
94
+ },
95
+ /** @implements */
96
+ parse(wikitext, include, maxStage = constants_1.MAX_STAGE, config = Parser.getConfig()) {
97
+ wikitext = (0, string_1.tidy)(wikitext);
98
+ const { Token } = require('./src/index');
99
+ const root = debug_1.Shadow.run(() => {
100
+ const token = new Token(wikitext, config);
101
+ token.type = 'root';
102
+ try {
103
+ return token.parse(maxStage, include);
104
+ }
105
+ catch (e) {
106
+ if (e instanceof Error) {
107
+ const file = path.join(__dirname, '..', 'errors', new Date().toISOString()), stage = token.getAttribute('stage');
108
+ fs.writeFileSync(file, stage === constants_1.MAX_STAGE ? wikitext : token.toString());
109
+ fs.writeFileSync(`${file}.err`, e.stack);
110
+ fs.writeFileSync(`${file}.json`, JSON.stringify({ stage, include, config }, null, '\t'));
111
+ }
112
+ throw e;
113
+ }
114
+ });
115
+ /* NOT FOR BROWSER */
116
+ if (this.debugging) {
117
+ let restored = root.toString(), process = 'parsing';
118
+ if (restored === wikitext) {
119
+ const entities = { lt: '<', gt: '>', amp: '&' };
120
+ restored = root.print().replace(/<[^<]+?>|&([lg]t|amp);/gu, (_, s) => s ? entities[s] : '');
121
+ process = 'printing';
122
+ }
123
+ if (restored !== wikitext) {
124
+ const { 0: cur, length } = promises;
125
+ promises.unshift((async () => {
126
+ await cur;
127
+ this.error(`Original wikitext is altered when ${process}!`);
128
+ return (0, diff_1.diff)(wikitext, restored, length);
129
+ })());
130
+ }
131
+ }
132
+ /* NOT FOR BROWSER END */
133
+ return root;
134
+ },
135
+ /* NOT FOR BROWSER */
136
+ /** @implements */
137
+ warn(msg, ...args) {
138
+ if (this.warning) {
139
+ console.warn(chalk.yellow(msg), ...args);
140
+ }
141
+ },
142
+ /** @implements */
143
+ debug(msg, ...args) {
144
+ if (this.debugging) {
145
+ console.debug(chalk.blue(msg), ...args);
146
+ }
147
+ },
148
+ error: diff_1.error,
149
+ info: diff_1.info,
150
+ /** @implements */
151
+ log(f) {
152
+ if (typeof f === 'function') {
153
+ console.log(String(f));
154
+ }
155
+ },
156
+ /** @implements */
157
+ async clearCache() {
158
+ const promise = (0, diff_1.cmd)('npm', ['run', 'build:core']), entries = [
159
+ ...Object.entries(constants_1.classes),
160
+ ...Object.entries(constants_1.mixins),
161
+ ...Object.entries(constants_1.parsers),
162
+ ...Object.entries(constants_1.constants),
163
+ ];
164
+ for (const [, filePath] of entries) {
165
+ try {
166
+ delete require.cache[require.resolve(filePath)];
167
+ }
168
+ catch { }
169
+ }
170
+ await promise;
171
+ for (const [name, filePath] of entries) {
172
+ if (name in global) {
173
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
174
+ Object.assign(global, { [name]: require(filePath)[name] });
175
+ }
176
+ }
177
+ this.info('已重新加载Parser');
178
+ },
179
+ /** @implements */
180
+ isInterwiki(title, { interwiki } = Parser.getConfig()) {
181
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
182
+ /^(zh|en)\s*:/diu;
183
+ return interwiki.length > 0
184
+ ? new RegExp(String.raw `^(${interwiki.join('|')})\s*:`, 'diu')
185
+ .exec(title.replace(/_/gu, ' ').replace(/^\s*:?\s*/u, ''))
186
+ : null;
187
+ },
188
+ /** @implements */
189
+ reparse(date = '') {
190
+ const main = fs.readdirSync(path.join(__dirname, '..', 'errors'))
191
+ .find(name => name.startsWith(date) && name.endsWith('Z'));
192
+ if (!main) {
193
+ throw new RangeError(`找不到对应时间戳的错误记录:${date}`);
194
+ }
195
+ const file = path.join(__dirname, '..', 'errors', main), wikitext = fs.readFileSync(file, 'utf8');
196
+ const { stage, include, config } = require(`${file}.json`), { Token } = require('./src/index');
197
+ debug_1.Shadow.run(() => {
198
+ const halfParsed = stage < constants_1.MAX_STAGE, token = new Token(halfParsed ? wikitext : (0, string_1.tidy)(wikitext), config);
199
+ token.type = 'root';
200
+ if (halfParsed) {
201
+ token.setAttribute('stage', stage);
202
+ token.parseOnce(stage, include);
203
+ }
204
+ else {
205
+ token.parse(undefined, include);
206
+ }
207
+ fs.unlinkSync(file);
208
+ fs.unlinkSync(`${file}.err`);
209
+ fs.unlinkSync(`${file}.json`);
210
+ });
211
+ },
212
+ };
213
+ const def = {
214
+ default: { value: Parser },
215
+ }, enumerable = new Set([
216
+ 'normalizeTitle',
217
+ 'parse',
218
+ /* NOT FOR BROWSER */
219
+ 'conversionTable',
220
+ 'redirects',
221
+ 'warning',
222
+ 'debugging',
223
+ 'isInterwiki',
224
+ ]);
225
+ for (const key in Parser) {
226
+ if (!enumerable.has(key)) {
227
+ def[key] = { enumerable: false };
228
+ }
229
+ }
230
+ Object.defineProperties(Parser, def);
231
+ exports.default = Parser;
232
+ module.exports = Parser;
@@ -0,0 +1,46 @@
1
+ export type { AstNodes, } from './lib/node';
2
+ export type * from './lib/text';
3
+ export type { Token } from './src/index';
4
+ export type * from './src/redirect';
5
+ export type * from './src/link/redirectTarget';
6
+ export type * from './src/onlyinclude';
7
+ export type * from './src/nowiki/noinclude';
8
+ export type * from './src/tagPair/include';
9
+ export type * from './src/nowiki/comment';
10
+ export type * from './src/atom';
11
+ export type { AttributeToken } from './src/attribute';
12
+ export type * from './src/attributes';
13
+ export type * from './src/tagPair/ext';
14
+ export type * from './src/hidden';
15
+ export type * from './src/arg';
16
+ export type * from './src/syntax';
17
+ export type * from './src/parameter';
18
+ export type * from './src/transclude';
19
+ export type * from './src/heading';
20
+ export type * from './src/html';
21
+ export type { TdToken } from './src/table/td';
22
+ export type * from './src/table/tr';
23
+ export type { TableToken } from './src/table/index';
24
+ export type * from './src/nowiki/hr';
25
+ export type * from './src/nowiki/doubleUnderscore';
26
+ export type * from './src/link/index';
27
+ export type * from './src/link/category';
28
+ export type { ImageParameterToken } from './src/imageParameter';
29
+ export type * from './src/link/file';
30
+ export type * from './src/link/galleryImage';
31
+ export type * from './src/nowiki/quote';
32
+ export type * from './src/magicLink';
33
+ export type * from './src/extLink';
34
+ export type * from './src/nowiki/dd';
35
+ export type * from './src/nowiki/list';
36
+ export type * from './src/converterFlags';
37
+ export type * from './src/converterRule';
38
+ export type * from './src/converter';
39
+ export type * from './src/nowiki/index';
40
+ export type * from './src/pre';
41
+ export type * from './src/paramTag/index';
42
+ export type * from './src/paramTag/inputbox';
43
+ export type * from './src/nested';
44
+ export type * from './src/gallery';
45
+ export type * from './src/imagemapLink';
46
+ export type * from './src/imagemap';
@@ -0,0 +1,124 @@
1
+ import { AstNode } from './node';
2
+ import type { LintError, AST } from '../base';
3
+ import type { AstNodes, AstText, Token } from '../internal';
4
+ /** 类似HTMLElement */
5
+ export declare abstract class AstElement extends AstNode {
6
+ #private;
7
+ readonly name?: string;
8
+ readonly data: undefined;
9
+ /** 子节点总数 */
10
+ get length(): number;
11
+ /** 全部非文本子节点 */
12
+ get children(): Token[];
13
+ /** 首位非文本子节点 */
14
+ get firstElementChild(): Token | undefined;
15
+ /** 末位非文本子节点 */
16
+ get lastElementChild(): Token | undefined;
17
+ /** 非文本子节点总数 */
18
+ get childElementCount(): number;
19
+ /** 父节点 */
20
+ get parentElement(): Token | undefined;
21
+ /** AstElement.prototype.text()的getter写法 */
22
+ get outerText(): string;
23
+ /** 不可见 */
24
+ get hidden(): boolean;
25
+ /** 内部高度 */
26
+ get clientHeight(): number | undefined;
27
+ /** 内部宽度 */
28
+ get clientWidth(): number | undefined;
29
+ constructor();
30
+ /** 合并相邻的文本子节点 */
31
+ normalize(): void;
32
+ /**
33
+ * 移除子节点
34
+ * @param i 移除位置
35
+ */
36
+ removeAt(i: number): AstNodes;
37
+ /**
38
+ * 插入子节点
39
+ * @param node 待插入的子节点
40
+ * @param i 插入位置
41
+ * @throws `RangeError` 不能插入祖先或子节点
42
+ */
43
+ insertAt<T extends AstNodes>(node: T, i?: number): T;
44
+ /**
45
+ * 最近的祖先节点
46
+ * @param selector 选择器
47
+ */
48
+ closest<T = Token>(selector: string): T | undefined;
49
+ /**
50
+ * 符合选择器的第一个后代节点
51
+ * @param selector 选择器
52
+ */
53
+ querySelector<T = Token>(selector: string): T | undefined;
54
+ /**
55
+ * 符合选择器的所有后代节点
56
+ * @param selector 选择器
57
+ */
58
+ querySelectorAll<T = Token>(selector: string): T[];
59
+ /**
60
+ * 在末尾批量插入子节点
61
+ * @param elements 插入节点
62
+ */
63
+ append(...elements: (AstNodes | string)[]): void;
64
+ /**
65
+ * 批量替换子节点
66
+ * @param elements 新的子节点
67
+ */
68
+ replaceChildren(...elements: (AstNodes | string)[]): void;
69
+ /**
70
+ * 修改文本子节点
71
+ * @param str 新文本
72
+ * @param i 子节点位置
73
+ * @throws `RangeError` 对应位置的子节点不是文本节点
74
+ */
75
+ setText(str: string, i?: number): string;
76
+ /**
77
+ * 保存为JSON
78
+ * @param file 文件名
79
+ * @param start
80
+ */
81
+ json(file?: string, start?: number): AST;
82
+ /**
83
+ * 检查是否符合选择器
84
+ * @param selector 选择器
85
+ */
86
+ matches<T>(selector?: string): this is T;
87
+ /**
88
+ * 类型选择器
89
+ * @param types
90
+ */
91
+ getElementByTypes<T = Token>(types: string): T | undefined;
92
+ /**
93
+ * id选择器
94
+ * @param id id名
95
+ */
96
+ getElementById<T = Token>(id: string): T | undefined;
97
+ /**
98
+ * 类选择器
99
+ * @param className 类名之一
100
+ */
101
+ getElementsByClassName<T = Token>(className: string): T[];
102
+ /**
103
+ * 标签名选择器
104
+ * @param tag 标签名
105
+ */
106
+ getElementsByTagName<T = Token>(tag: string): T[];
107
+ /**
108
+ * 在开头批量插入子节点
109
+ * @param elements 插入节点
110
+ */
111
+ prepend(...elements: (AstNodes | string)[]): void;
112
+ /**
113
+ * 移除子节点
114
+ * @param node 子节点
115
+ */
116
+ removeChild<T extends AstNodes>(node: T): T;
117
+ /**
118
+ * 在指定位置前插入子节点
119
+ * @param child 插入节点
120
+ * @param reference 指定位置处的子节点
121
+ */
122
+ insertBefore(child: string, reference?: AstNodes): AstText;
123
+ insertBefore<T extends AstNodes>(child: T, reference?: AstNodes): T;
124
+ }