wikiparser-node 1.3.3 → 1.3.4-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 (156) hide show
  1. package/README.en.md +1 -1
  2. package/README.md +1 -1
  3. package/bundle/bundle.min.js +36 -0
  4. package/config/llwiki.json +1 -35
  5. package/config/moegirl.json +1 -44
  6. package/config/zhwiki.json +1 -466
  7. package/extensions/dist/base.js +68 -0
  8. package/extensions/dist/editor.js +159 -0
  9. package/extensions/dist/highlight.js +30 -0
  10. package/extensions/dist/lint.js +48 -0
  11. package/extensions/editor.css +63 -0
  12. package/extensions/ui.css +114 -0
  13. package/package.json +32 -12
  14. package/config/.schema.json +0 -172
  15. package/dist/addon/table.d.ts +0 -6
  16. package/dist/addon/table.js +0 -564
  17. package/dist/base.d.ts +0 -45
  18. package/dist/bin/toc.js +0 -18
  19. package/dist/index.d.ts +0 -31
  20. package/dist/index.js +0 -209
  21. package/dist/internal.d.ts +0 -44
  22. package/dist/lib/element.d.ts +0 -155
  23. package/dist/lib/element.js +0 -634
  24. package/dist/lib/node.d.ts +0 -146
  25. package/dist/lib/node.js +0 -419
  26. package/dist/lib/range.d.ts +0 -104
  27. package/dist/lib/range.js +0 -385
  28. package/dist/lib/ranges.d.ts +0 -26
  29. package/dist/lib/ranges.js +0 -117
  30. package/dist/lib/text.d.ts +0 -62
  31. package/dist/lib/text.js +0 -248
  32. package/dist/lib/title.d.ts +0 -38
  33. package/dist/lib/title.js +0 -162
  34. package/dist/mixin/attributesParent.js +0 -94
  35. package/dist/mixin/fixed.js +0 -32
  36. package/dist/mixin/flagsParent.js +0 -70
  37. package/dist/mixin/hidden.js +0 -26
  38. package/dist/mixin/magicLinkParent.js +0 -41
  39. package/dist/mixin/singleLine.js +0 -25
  40. package/dist/mixin/sol.js +0 -43
  41. package/dist/mixin/syntax.js +0 -56
  42. package/dist/parser/braces.js +0 -121
  43. package/dist/parser/commentAndExt.js +0 -69
  44. package/dist/parser/converter.js +0 -40
  45. package/dist/parser/externalLinks.js +0 -28
  46. package/dist/parser/hrAndDoubleUnderscore.js +0 -38
  47. package/dist/parser/html.js +0 -36
  48. package/dist/parser/links.js +0 -94
  49. package/dist/parser/list.js +0 -59
  50. package/dist/parser/magicLinks.js +0 -40
  51. package/dist/parser/quotes.js +0 -67
  52. package/dist/parser/selector.js +0 -162
  53. package/dist/parser/table.js +0 -112
  54. package/dist/src/arg.d.ts +0 -58
  55. package/dist/src/arg.js +0 -189
  56. package/dist/src/atom.d.ts +0 -12
  57. package/dist/src/atom.js +0 -27
  58. package/dist/src/attribute.d.ts +0 -87
  59. package/dist/src/attribute.js +0 -392
  60. package/dist/src/attributes.d.ts +0 -107
  61. package/dist/src/attributes.js +0 -341
  62. package/dist/src/converter.d.ts +0 -52
  63. package/dist/src/converter.js +0 -79
  64. package/dist/src/converterFlags.d.ts +0 -87
  65. package/dist/src/converterFlags.js +0 -224
  66. package/dist/src/converterRule.d.ts +0 -81
  67. package/dist/src/converterRule.js +0 -212
  68. package/dist/src/extLink.d.ts +0 -54
  69. package/dist/src/extLink.js +0 -122
  70. package/dist/src/gallery.d.ts +0 -55
  71. package/dist/src/gallery.js +0 -122
  72. package/dist/src/heading.d.ts +0 -74
  73. package/dist/src/heading.js +0 -127
  74. package/dist/src/hidden.d.ts +0 -22
  75. package/dist/src/hidden.js +0 -23
  76. package/dist/src/html.d.ts +0 -101
  77. package/dist/src/html.js +0 -227
  78. package/dist/src/imageParameter.d.ts +0 -66
  79. package/dist/src/imageParameter.js +0 -247
  80. package/dist/src/imagemap.d.ts +0 -57
  81. package/dist/src/imagemap.js +0 -148
  82. package/dist/src/imagemapLink.d.ts +0 -59
  83. package/dist/src/imagemapLink.js +0 -40
  84. package/dist/src/index.d.ts +0 -146
  85. package/dist/src/index.js +0 -777
  86. package/dist/src/link/base.d.ts +0 -52
  87. package/dist/src/link/base.js +0 -209
  88. package/dist/src/link/category.d.ts +0 -13
  89. package/dist/src/link/category.js +0 -29
  90. package/dist/src/link/file.d.ts +0 -96
  91. package/dist/src/link/file.js +0 -255
  92. package/dist/src/link/galleryImage.d.ts +0 -44
  93. package/dist/src/link/galleryImage.js +0 -106
  94. package/dist/src/link/index.d.ts +0 -53
  95. package/dist/src/link/index.js +0 -123
  96. package/dist/src/magicLink.d.ts +0 -70
  97. package/dist/src/magicLink.js +0 -147
  98. package/dist/src/nested.d.ts +0 -44
  99. package/dist/src/nested.js +0 -87
  100. package/dist/src/nowiki/base.d.ts +0 -47
  101. package/dist/src/nowiki/base.js +0 -42
  102. package/dist/src/nowiki/comment.d.ts +0 -40
  103. package/dist/src/nowiki/comment.js +0 -67
  104. package/dist/src/nowiki/dd.d.ts +0 -8
  105. package/dist/src/nowiki/dd.js +0 -25
  106. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -45
  107. package/dist/src/nowiki/doubleUnderscore.js +0 -50
  108. package/dist/src/nowiki/hr.d.ts +0 -31
  109. package/dist/src/nowiki/hr.js +0 -14
  110. package/dist/src/nowiki/index.d.ts +0 -16
  111. package/dist/src/nowiki/index.js +0 -21
  112. package/dist/src/nowiki/list.d.ts +0 -30
  113. package/dist/src/nowiki/list.js +0 -48
  114. package/dist/src/nowiki/listBase.d.ts +0 -19
  115. package/dist/src/nowiki/listBase.js +0 -12
  116. package/dist/src/nowiki/noinclude.d.ts +0 -26
  117. package/dist/src/nowiki/noinclude.js +0 -25
  118. package/dist/src/nowiki/quote.d.ts +0 -23
  119. package/dist/src/nowiki/quote.js +0 -45
  120. package/dist/src/onlyinclude.d.ts +0 -16
  121. package/dist/src/onlyinclude.js +0 -57
  122. package/dist/src/paramTag/index.d.ts +0 -37
  123. package/dist/src/paramTag/index.js +0 -68
  124. package/dist/src/paramTag/inputbox.d.ts +0 -8
  125. package/dist/src/paramTag/inputbox.js +0 -23
  126. package/dist/src/parameter.d.ts +0 -85
  127. package/dist/src/parameter.js +0 -205
  128. package/dist/src/pre.d.ts +0 -28
  129. package/dist/src/pre.js +0 -51
  130. package/dist/src/syntax.d.ts +0 -28
  131. package/dist/src/syntax.js +0 -34
  132. package/dist/src/table/base.d.ts +0 -53
  133. package/dist/src/table/base.js +0 -78
  134. package/dist/src/table/index.d.ts +0 -229
  135. package/dist/src/table/index.js +0 -379
  136. package/dist/src/table/td.d.ts +0 -104
  137. package/dist/src/table/td.js +0 -261
  138. package/dist/src/table/tr.d.ts +0 -32
  139. package/dist/src/table/tr.js +0 -56
  140. package/dist/src/table/trBase.d.ts +0 -54
  141. package/dist/src/table/trBase.js +0 -159
  142. package/dist/src/tagPair/ext.d.ts +0 -56
  143. package/dist/src/tagPair/ext.js +0 -142
  144. package/dist/src/tagPair/include.d.ts +0 -53
  145. package/dist/src/tagPair/include.js +0 -63
  146. package/dist/src/tagPair/index.d.ts +0 -48
  147. package/dist/src/tagPair/index.js +0 -93
  148. package/dist/src/transclude.d.ts +0 -167
  149. package/dist/src/transclude.js +0 -690
  150. package/dist/util/constants.js +0 -108
  151. package/dist/util/debug.js +0 -64
  152. package/dist/util/diff.js +0 -72
  153. package/dist/util/lint.js +0 -46
  154. package/dist/util/string.js +0 -61
  155. package/errors/README +0 -1
  156. package/printed/README +0 -1
@@ -1,146 +0,0 @@
1
- import type { LintError, AstNode as AstNodeBase } from '../base';
2
- import type { AstText, Token } from '../internal';
3
- import type { TokenTypes } from '../util/constants';
4
- export type AstNodes = AstText | Token;
5
- export interface Dimension {
6
- readonly height: number;
7
- readonly width: number;
8
- }
9
- export interface Position {
10
- readonly top: number;
11
- readonly left: number;
12
- }
13
- export interface CaretPosition {
14
- readonly offsetNode: AstNodes;
15
- readonly offset: number;
16
- }
17
- /** 类似Node */
18
- export declare abstract class AstNode implements AstNodeBase {
19
- #private;
20
- type: TokenTypes | 'text';
21
- data?: string | undefined;
22
- readonly childNodes: AstNodes[];
23
- abstract lint(): LintError[];
24
- abstract print(): string;
25
- /** 首位子节点 */
26
- get firstChild(): AstNodes | undefined;
27
- /** 末位子节点 */
28
- get lastChild(): AstNodes | undefined;
29
- /** 父节点 */
30
- get parentNode(): Token | undefined;
31
- /** 后一个兄弟节点 */
32
- get nextSibling(): AstNodes | undefined;
33
- /** 前一个兄弟节点 */
34
- get previousSibling(): AstNodes | undefined;
35
- /** 行数 */
36
- get offsetHeight(): number;
37
- /** 最后一行的列数 */
38
- get offsetWidth(): number;
39
- /** 后一个非文本兄弟节点 */
40
- get nextElementSibling(): Token | undefined;
41
- /** 前一个非文本兄弟节点 */
42
- get previousElementSibling(): Token | undefined;
43
- /** 是否具有根节点 */
44
- get isConnected(): boolean;
45
- /** 后方是否还有其他节点(不含后代) */
46
- get eof(): boolean | undefined;
47
- /** 相对于父容器的行号 */
48
- get offsetTop(): number;
49
- /** 相对于父容器的列号 */
50
- get offsetLeft(): number;
51
- /** 位置、大小和padding */
52
- get style(): Position & Dimension & {
53
- padding: number;
54
- };
55
- constructor();
56
- /** 获取根节点 */
57
- getRootNode(): Token | this;
58
- /**
59
- * 将字符位置转换为行列号
60
- * @param index 字符位置
61
- */
62
- posFromIndex(index: number): Position | undefined;
63
- /**
64
- * 获取当前节点的相对字符位置,或其第`j`个子节点的相对字符位置
65
- * @param j 子节点序号
66
- */
67
- getRelativeIndex(j?: number): number;
68
- /** 获取当前节点的绝对位置 */
69
- getAbsoluteIndex(): number;
70
- /**
71
- * 是否是全同节点
72
- * @param node 待比较的节点
73
- * @throws `assert.AssertionError`
74
- */
75
- isEqualNode(node: AstNode): boolean;
76
- /**
77
- * 在后方批量插入兄弟节点
78
- * @param nodes 插入节点
79
- */
80
- after(...nodes: (AstNodes | string)[]): void;
81
- /**
82
- * 在前方批量插入兄弟节点
83
- * @param nodes 插入节点
84
- */
85
- before(...nodes: (AstNodes | string)[]): void;
86
- /** 移除当前节点 */
87
- remove(): void;
88
- /**
89
- * 将当前节点批量替换为新的节点
90
- * @param nodes 插入节点
91
- */
92
- replaceWith(...nodes: (AstNodes | string)[]): void;
93
- /**
94
- * 是自身或后代节点
95
- * @param node 待检测节点
96
- */
97
- contains(node: AstNode): boolean;
98
- /**
99
- * 添加事件监听
100
- * @param types 事件类型
101
- * @param listener 监听函数
102
- * @param options 选项
103
- * @param options.once 仅执行一次
104
- */
105
- addEventListener(types: string | string[], listener: (...args: any[]) => void, options?: {
106
- once?: boolean;
107
- }): void;
108
- /**
109
- * 移除事件监听
110
- * @param types 事件类型
111
- * @param listener 监听函数
112
- */
113
- removeEventListener(types: string | string[], listener: (...args: any[]) => void): void;
114
- /**
115
- * 移除事件的所有监听
116
- * @param types 事件类型
117
- */
118
- removeAllEventListeners(types?: string | string[]): void;
119
- /**
120
- * 列举事件监听
121
- * @param type 事件类型
122
- */
123
- listEventListeners(type: string): readonly Function[];
124
- /**
125
- * 触发事件
126
- * @param e 事件对象
127
- * @param data 事件数据
128
- */
129
- dispatchEvent(e: Event, data: AstEventData): void;
130
- /** 获取所有祖先节点 */
131
- getAncestors(): Token[];
132
- /**
133
- * 比较和另一个节点的相对位置
134
- * @param other 待比较的节点
135
- * @throws `RangeError` 不在同一个语法树
136
- */
137
- compareDocumentPosition(other: AstNodes): number;
138
- /**
139
- * 将行列号转换为字符位置
140
- * @param top 行号
141
- * @param left 列号
142
- */
143
- indexFromPos(top: number, left: number): number | undefined;
144
- /** 获取当前节点的行列位置和大小 */
145
- getBoundingClientRect(): Dimension & Position;
146
- }
package/dist/lib/node.js DELETED
@@ -1,419 +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
- /* NOT FOR BROWSER */
8
- /**
9
- * 定制TypeError消息
10
- * @param {Function} Constructor 类
11
- * @param method
12
- * @param args 可接受的参数类型
13
- * @throws `TypeError`
14
- */
15
- const typeError = ({ name }, method, ...args) => {
16
- throw new TypeError(`${name}.${method} 方法仅接受 ${args.join('、')} 作为输入参数!`);
17
- };
18
- /* NOT FOR BROWSER END */
19
- /** 类似Node */
20
- class AstNode {
21
- childNodes = [];
22
- #parentNode;
23
- /* NOT FOR BROWSER */
24
- #optional = new Set();
25
- #events = new EventEmitter();
26
- /** 首位子节点 */
27
- get firstChild() {
28
- return this.childNodes[0];
29
- }
30
- /** 末位子节点 */
31
- get lastChild() {
32
- return this.childNodes.at(-1);
33
- }
34
- /** 父节点 */
35
- get parentNode() {
36
- return this.#parentNode;
37
- }
38
- /** 后一个兄弟节点 */
39
- get nextSibling() {
40
- const childNodes = this.parentNode?.childNodes;
41
- return childNodes && childNodes[childNodes.indexOf(this) + 1];
42
- }
43
- /** 前一个兄弟节点 */
44
- get previousSibling() {
45
- const childNodes = this.parentNode?.childNodes;
46
- return childNodes && childNodes[childNodes.indexOf(this) - 1];
47
- }
48
- /** 行数 */
49
- get offsetHeight() {
50
- return this.#getDimension().height;
51
- }
52
- /** 最后一行的列数 */
53
- get offsetWidth() {
54
- return this.#getDimension().width;
55
- }
56
- /* NOT FOR BROWSER */
57
- /** 后一个非文本兄弟节点 */
58
- get nextElementSibling() {
59
- const childNodes = this.parentNode?.childNodes, i = childNodes?.indexOf(this);
60
- return childNodes?.slice(i + 1).find((child) => child.type !== 'text');
61
- }
62
- /** 前一个非文本兄弟节点 */
63
- get previousElementSibling() {
64
- const childNodes = this.parentNode?.childNodes, i = childNodes?.indexOf(this);
65
- return childNodes?.slice(0, i).findLast((child) => child.type !== 'text');
66
- }
67
- /** 是否具有根节点 */
68
- get isConnected() {
69
- return this.getRootNode().type === 'root';
70
- }
71
- /** 后方是否还有其他节点(不含后代) */
72
- get eof() {
73
- const { parentNode } = this;
74
- if (!parentNode) {
75
- return true;
76
- }
77
- let { nextSibling } = this;
78
- while (nextSibling?.type === 'text' && nextSibling.data.trim() === '') {
79
- ({ nextSibling } = nextSibling);
80
- }
81
- return nextSibling === undefined && parentNode.eof;
82
- }
83
- /** 相对于父容器的行号 */
84
- get offsetTop() {
85
- return this.#getPosition().top;
86
- }
87
- /** 相对于父容器的列号 */
88
- get offsetLeft() {
89
- return this.#getPosition().left;
90
- }
91
- /** 位置、大小和padding */
92
- get style() {
93
- return { ...this.#getPosition(), ...this.#getDimension(), padding: this.getAttribute('padding') };
94
- }
95
- /** @private */
96
- get fixed() {
97
- return 'fixed' in this.constructor;
98
- }
99
- constructor() {
100
- Object.defineProperty(this, 'childNodes', { writable: false });
101
- Object.freeze(this.childNodes);
102
- }
103
- /* NOT FOR BROWSER END */
104
- /** @private */
105
- getAttribute(key) {
106
- if (key === 'padding') {
107
- return 0;
108
- }
109
- else if (key === 'optional') {
110
- return new Set(this.#optional);
111
- }
112
- return key in this
113
- ? String(this[key])
114
- : undefined;
115
- }
116
- /** @private */
117
- setAttribute(key, value) {
118
- if (key === 'parentNode') {
119
- this.#parentNode = value;
120
- }
121
- else if (Object.hasOwn(this, key)) {
122
- const descriptor = Object.getOwnPropertyDescriptor(this, key);
123
- if (this.#optional.has(key)) {
124
- descriptor.enumerable = Boolean(value);
125
- }
126
- const oldValue = this[key], frozen = typeof oldValue === 'object' && Object.isFrozen(oldValue);
127
- Object.defineProperty(this, key, { ...descriptor, value });
128
- if (frozen && typeof value === 'object') {
129
- Object.freeze(value);
130
- }
131
- }
132
- else {
133
- this[key] = value; // eslint-disable-line @typescript-eslint/no-explicit-any
134
- }
135
- }
136
- /** 获取根节点 */
137
- getRootNode() {
138
- let { parentNode } = this;
139
- while (parentNode?.parentNode) {
140
- ({ parentNode } = parentNode);
141
- }
142
- return parentNode ?? this;
143
- }
144
- /**
145
- * 将字符位置转换为行列号
146
- * @param index 字符位置
147
- */
148
- posFromIndex(index) {
149
- const str = String(this);
150
- if (index >= -str.length && index <= str.length) {
151
- const lines = str.slice(0, index).split('\n');
152
- return {
153
- top: lines.length - 1,
154
- left: lines.at(-1).length,
155
- };
156
- }
157
- return undefined;
158
- }
159
- /** 获取行数和最后一行的列数 */
160
- #getDimension() {
161
- const lines = String(this).split('\n');
162
- return {
163
- height: lines.length,
164
- width: lines.at(-1).length,
165
- };
166
- }
167
- /** @private */
168
- // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
169
- getGaps(i) {
170
- return 0;
171
- }
172
- /**
173
- * 获取当前节点的相对字符位置,或其第`j`个子节点的相对字符位置
174
- * @param j 子节点序号
175
- */
176
- getRelativeIndex(j) {
177
- let childNodes;
178
- /**
179
- * 获取子节点相对于父节点的字符位置,使用前需要先给`childNodes`赋值
180
- * @param end 子节点序号
181
- * @param parent 父节点
182
- */
183
- const getIndex = (end, parent) => childNodes.slice(0, end).reduce((acc, cur, i) => acc + String(cur).length + parent.getGaps(i), 0)
184
- + parent.getAttribute('padding');
185
- if (j === undefined) {
186
- const { parentNode } = this;
187
- if (parentNode) {
188
- ({ childNodes } = parentNode);
189
- return getIndex(childNodes.indexOf(this), parentNode);
190
- }
191
- return 0;
192
- }
193
- this.verifyChild(j, 1);
194
- ({ childNodes } = this);
195
- return getIndex(j, this);
196
- }
197
- /** 获取当前节点的绝对位置 */
198
- getAbsoluteIndex() {
199
- const { parentNode } = this;
200
- return parentNode ? parentNode.getAbsoluteIndex() + this.getRelativeIndex() : 0;
201
- }
202
- /* NOT FOR BROWSER */
203
- /** @private */
204
- typeError(method, ...types) {
205
- return typeError(this.constructor, method, ...types);
206
- }
207
- /** @private */
208
- seal(key) {
209
- this.#optional.add(key);
210
- Object.defineProperty(this, key, {
211
- writable: false,
212
- enumerable: Boolean(this[key]),
213
- configurable: true,
214
- });
215
- }
216
- /**
217
- * 是否是全同节点
218
- * @param node 待比较的节点
219
- * @throws `assert.AssertionError`
220
- */
221
- isEqualNode(node) {
222
- try {
223
- assert.deepEqual(this, node);
224
- }
225
- catch (e) {
226
- if (e instanceof assert.AssertionError) {
227
- return false;
228
- }
229
- throw e;
230
- }
231
- return true;
232
- }
233
- /**
234
- * 在当前节点前后插入兄弟节点
235
- * @param nodes 插入节点
236
- * @param offset 插入的相对位置
237
- * @throws `Error` 不存在父节点
238
- */
239
- #insertAdjacent(nodes, offset) {
240
- const { parentNode } = this;
241
- if (!parentNode) {
242
- throw new Error('不存在父节点!');
243
- }
244
- const i = parentNode.childNodes.indexOf(this) + offset;
245
- for (let j = 0; j < nodes.length; j++) {
246
- parentNode.insertAt(nodes[j], i + j);
247
- }
248
- }
249
- /**
250
- * 在后方批量插入兄弟节点
251
- * @param nodes 插入节点
252
- */
253
- after(...nodes) {
254
- this.#insertAdjacent(nodes, 1);
255
- }
256
- /**
257
- * 在前方批量插入兄弟节点
258
- * @param nodes 插入节点
259
- */
260
- before(...nodes) {
261
- this.#insertAdjacent(nodes, 0);
262
- }
263
- /** 移除当前节点 */
264
- remove() {
265
- const { parentNode } = this;
266
- if (parentNode) {
267
- parentNode.removeChild(this);
268
- }
269
- }
270
- /**
271
- * 将当前节点批量替换为新的节点
272
- * @param nodes 插入节点
273
- */
274
- replaceWith(...nodes) {
275
- this.after(...nodes);
276
- this.remove();
277
- }
278
- /**
279
- * 是自身或后代节点
280
- * @param node 待检测节点
281
- */
282
- contains(node) {
283
- return node === this || this.childNodes.some(child => child.contains(node));
284
- }
285
- /** @private */
286
- verifyChild(i, addition = 0) {
287
- const { childNodes: { length } } = this;
288
- if (i < -length || i >= length + addition) {
289
- throw new RangeError(`不存在第 ${i} 个子节点!`);
290
- }
291
- }
292
- /**
293
- * 添加事件监听
294
- * @param types 事件类型
295
- * @param listener 监听函数
296
- * @param options 选项
297
- * @param options.once 仅执行一次
298
- */
299
- addEventListener(types, listener, options) {
300
- if (Array.isArray(types)) {
301
- for (const type of types) {
302
- this.addEventListener(type, listener, options);
303
- }
304
- }
305
- else {
306
- this.#events[options?.once ? 'once' : 'on'](types, listener);
307
- }
308
- }
309
- /**
310
- * 移除事件监听
311
- * @param types 事件类型
312
- * @param listener 监听函数
313
- */
314
- removeEventListener(types, listener) {
315
- if (Array.isArray(types)) {
316
- for (const type of types) {
317
- this.removeEventListener(type, listener);
318
- }
319
- }
320
- else {
321
- this.#events.off(types, listener);
322
- }
323
- }
324
- /**
325
- * 移除事件的所有监听
326
- * @param types 事件类型
327
- */
328
- removeAllEventListeners(types) {
329
- if (Array.isArray(types)) {
330
- for (const type of types) {
331
- this.removeAllEventListeners(type);
332
- }
333
- }
334
- else {
335
- this.#events.removeAllListeners(types);
336
- }
337
- }
338
- /**
339
- * 列举事件监听
340
- * @param type 事件类型
341
- */
342
- listEventListeners(type) {
343
- return this.#events.listeners(type);
344
- }
345
- /**
346
- * 触发事件
347
- * @param e 事件对象
348
- * @param data 事件数据
349
- */
350
- dispatchEvent(e, data) {
351
- if (!e.target) { // 初始化
352
- Object.defineProperty(e, 'target', { value: this, enumerable: true });
353
- /** 终止冒泡 */
354
- e.stopPropagation = function () {
355
- Object.defineProperty(this, 'bubbles', { value: false });
356
- };
357
- }
358
- Object.defineProperties(e, {
359
- prevTarget: { value: e.currentTarget, enumerable: true, configurable: true },
360
- currentTarget: { value: this, enumerable: true, configurable: true },
361
- });
362
- this.#events.emit(e.type, e, data);
363
- if (e.bubbles && this.parentNode) {
364
- this.parentNode.dispatchEvent(e, data);
365
- }
366
- }
367
- /** 获取所有祖先节点 */
368
- getAncestors() {
369
- const ancestors = [];
370
- let { parentNode } = this;
371
- while (parentNode) {
372
- ancestors.push(parentNode);
373
- ({ parentNode } = parentNode);
374
- }
375
- return ancestors;
376
- }
377
- /**
378
- * 比较和另一个节点的相对位置
379
- * @param other 待比较的节点
380
- * @throws `RangeError` 不在同一个语法树
381
- */
382
- compareDocumentPosition(other) {
383
- if (this === other) {
384
- return 0;
385
- }
386
- else if (this.contains(other)) {
387
- return -1;
388
- }
389
- else if (other.contains(this)) {
390
- return 1;
391
- }
392
- else if (this.getRootNode() !== other.getRootNode()) {
393
- throw new RangeError('不在同一个语法树!');
394
- }
395
- const aAncestors = [...this.getAncestors().reverse(), this], bAncestors = [...other.getAncestors().reverse(), other], depth = aAncestors.findIndex((ancestor, i) => bAncestors[i] !== ancestor), commonAncestor = aAncestors[depth - 1], { childNodes } = commonAncestor;
396
- return childNodes.indexOf(aAncestors[depth]) - childNodes.indexOf(bAncestors[depth]);
397
- }
398
- /**
399
- * 将行列号转换为字符位置
400
- * @param top 行号
401
- * @param left 列号
402
- */
403
- indexFromPos(top, left) {
404
- const lines = String(this).split('\n');
405
- return top >= 0 && left >= 0 && lines.length >= top + 1 && lines[top].length >= left
406
- ? lines.slice(0, top).reduce((acc, curLine) => acc + curLine.length + 1, 0) + left
407
- : undefined;
408
- }
409
- /** 获取当前节点的相对位置 */
410
- #getPosition() {
411
- return this.parentNode?.posFromIndex(this.getRelativeIndex()) ?? { top: 0, left: 0 };
412
- }
413
- /** 获取当前节点的行列位置和大小 */
414
- getBoundingClientRect() {
415
- return { ...this.#getDimension(), ...this.getRootNode().posFromIndex(this.getAbsoluteIndex()) };
416
- }
417
- }
418
- exports.AstNode = AstNode;
419
- constants_1.classes['AstNode'] = __filename;
@@ -1,104 +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 startOffset 起点位置
30
- * @throws `RangeError` offset取值超出范围
31
- */
32
- setStart(startNode: AstNodes, startOffset: number): void;
33
- /**
34
- * 设置终点
35
- * @param endNode 终点容器
36
- * @param endOffset 终点位置
37
- * @throws `RangeError` offset取值超出范围
38
- */
39
- setEnd(endNode: AstNodes, endOffset: 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
- * @throws `RangeError` 参考节点没有父节点
69
- */
70
- selectNode(referenceNode: AstNodes): void;
71
- /**
72
- * 使起始和终止位置重合
73
- * @param toStart 重合至起始位置
74
- */
75
- collapse(toStart?: boolean): void;
76
- /**
77
- * 比较端点和Range的位置
78
- * @param referenceNode 端点容器
79
- * @param offset 端点位置
80
- * @throws `RangeError` 不在同一个文档
81
- */
82
- comparePoint(referenceNode: AstNodes, offset: number): -1 | 0 | 1;
83
- /**
84
- * 端点是否在Range中
85
- * @param referenceNode 端点容器
86
- * @param offset 端点位置
87
- */
88
- isPointInRange(referenceNode: AstNodes, offset: number): boolean;
89
- /** 复制AstRange对象 */
90
- cloneRange(): AstRange;
91
- /** 删除Range中的内容 */
92
- deleteContents(): void;
93
- /** 获取行列位置和大小 */
94
- getBoundingClientRect(): Dimension & Position;
95
- /**
96
- * 在起始位置插入节点
97
- * @param newNode 插入的节点
98
- */
99
- insertNode(newNode: AstNodes | string): void;
100
- /** 获取范围内的全部节点 */
101
- extractContents(): readonly AstNodes[];
102
- /** 在满足条件时拷贝范围内的全部节点 */
103
- cloneContents(): readonly AstNodes[];
104
- }