wikilint 2.22.1 → 2.23.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.
package/dist/index.d.ts CHANGED
@@ -48,4 +48,4 @@ export = Parser;
48
48
  export default Parser;
49
49
  export type { Config, ConfigData, LintError, TokenTypes, LanguageService, QuickFixData, };
50
50
  export type * from './internal';
51
- declare global { type Acceptable = Record<string, any>; }
51
+ declare global { type WikiParserAcceptable = Record<string, any>; }
@@ -1,17 +1,19 @@
1
1
  import { AstNode } from './node';
2
2
  import type { LintError } from '../base';
3
+ import type { ElementLike } from '../mixin/elementLike';
3
4
  import type { AstNodes, Token } from '../internal';
4
5
  export interface CaretPosition {
5
6
  readonly offsetNode: AstNodes;
6
7
  readonly offset: number;
7
8
  }
9
+ export interface AstElement extends AstNode, ElementLike {
10
+ }
8
11
  /**
9
12
  * HTMLElement-like
10
13
  *
11
14
  * 类似HTMLElement
12
15
  */
13
16
  export declare abstract class AstElement extends AstNode {
14
- #private;
15
17
  readonly name?: string;
16
18
  readonly data: undefined;
17
19
  /** number of child nodes / 子节点总数 */
@@ -44,20 +46,6 @@ export declare abstract class AstElement extends AstNode {
44
46
  * @param selector selector / 选择器
45
47
  */
46
48
  closest<T = Token>(selector: string): T | undefined;
47
- /**
48
- * Get the first descendant that matches the selector
49
- *
50
- * 符合选择器的第一个后代节点
51
- * @param selector selector / 选择器
52
- */
53
- querySelector<T = Token>(selector: string): T | undefined;
54
- /**
55
- * Get all descendants that match the selector
56
- *
57
- * 符合选择器的所有后代节点
58
- * @param selector selector / 选择器
59
- */
60
- querySelectorAll<T = Token>(selector: string): T[];
61
49
  /**
62
50
  * Insert a batch of child nodes at the end
63
51
  *
@@ -1,272 +1,267 @@
1
1
  "use strict";
2
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
+ var _, done = false;
8
+ for (var i = decorators.length - 1; i >= 0; i--) {
9
+ var context = {};
10
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
+ if (kind === "accessor") {
15
+ if (result === void 0) continue;
16
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
+ if (_ = accept(result.get)) descriptor.get = _;
18
+ if (_ = accept(result.set)) descriptor.set = _;
19
+ if (_ = accept(result.init)) initializers.unshift(_);
20
+ }
21
+ else if (_ = accept(result)) {
22
+ if (kind === "field") initializers.unshift(_);
23
+ else descriptor[key] = _;
24
+ }
25
+ }
26
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
+ done = true;
28
+ };
29
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
+ var useValue = arguments.length > 2;
31
+ for (var i = 0; i < initializers.length; i++) {
32
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
+ }
34
+ return useValue ? value : void 0;
35
+ };
2
36
  Object.defineProperty(exports, "__esModule", { value: true });
3
37
  exports.AstElement = void 0;
4
38
  const string_1 = require("../util/string");
5
39
  const debug_1 = require("../util/debug");
6
40
  const selector_1 = require("../parser/selector");
7
41
  const node_1 = require("./node");
42
+ const elementLike_1 = require("../mixin/elementLike");
8
43
  /**
9
44
  * HTMLElement-like
10
45
  *
11
46
  * 类似HTMLElement
12
47
  */
13
- class AstElement extends node_1.AstNode {
14
- /** number of child nodes / 子节点总数 */
15
- get length() {
16
- return this.childNodes.length;
17
- }
18
- /** @private */
19
- text(separator) {
20
- return (0, string_1.text)(this.childNodes, separator);
21
- }
22
- /**
23
- * Merge adjacent text child nodes
24
- *
25
- * 合并相邻的文本子节点
26
- */
27
- normalize() {
28
- const childNodes = this.getChildNodes();
48
+ let AstElement = (() => {
49
+ let _classDecorators = [elementLike_1.elementLike];
50
+ let _classDescriptor;
51
+ let _classExtraInitializers = [];
52
+ let _classThis;
53
+ let _classSuper = node_1.AstNode;
54
+ var AstElement = class extends _classSuper {
55
+ static { _classThis = this; }
56
+ static {
57
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
58
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
59
+ AstElement = _classThis = _classDescriptor.value;
60
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
61
+ __runInitializers(_classThis, _classExtraInitializers);
62
+ }
63
+ /** number of child nodes / 子节点总数 */
64
+ get length() {
65
+ return this.childNodes.length;
66
+ }
67
+ /** @private */
68
+ text(separator) {
69
+ return (0, string_1.text)(this.childNodes, separator);
70
+ }
29
71
  /**
30
- * 移除子节点
31
- * @param i 移除位置
72
+ * Merge adjacent text child nodes
73
+ *
74
+ * 合并相邻的文本子节点
32
75
  */
33
- const remove = (i) => {
34
- childNodes.splice(i, 1);
35
- childNodes[i - 1]?.setAttribute('nextSibling', childNodes[i]);
36
- childNodes[i]?.setAttribute('previousSibling', childNodes[i - 1]);
37
- };
38
- for (let i = childNodes.length - 1; i >= 0; i--) {
39
- const { type, data } = childNodes[i];
40
- if (type !== 'text' || childNodes.length === 1 || this.getGaps(i - (i && 1))) {
41
- //
42
- }
43
- else if (data === '') {
44
- remove(i);
76
+ normalize() {
77
+ const childNodes = this.getChildNodes();
78
+ /**
79
+ * 移除子节点
80
+ * @param i 移除位置
81
+ */
82
+ const remove = (i) => {
83
+ childNodes.splice(i, 1);
84
+ childNodes[i - 1]?.setAttribute('nextSibling', childNodes[i]);
85
+ childNodes[i]?.setAttribute('previousSibling', childNodes[i - 1]);
86
+ };
87
+ for (let i = childNodes.length - 1; i >= 0; i--) {
88
+ const { type, data } = childNodes[i];
89
+ if (type !== 'text' || childNodes.length === 1 || this.getGaps(i - (i && 1))) {
90
+ //
91
+ }
92
+ else if (data === '') {
93
+ remove(i);
94
+ }
45
95
  }
96
+ this.setAttribute('childNodes', childNodes);
46
97
  }
47
- this.setAttribute('childNodes', childNodes);
48
- }
49
- /**
50
- * Remove a child node
51
- *
52
- * 移除子节点
53
- * @param i position of the child node / 移除位置
54
- */
55
- removeAt(i) {
56
- return (0, debug_1.setChildNodes)(this, i, 1)[0];
57
- }
58
- /**
59
- * Insert a child node
60
- *
61
- * 插入子节点
62
- * @param node node to be inserted / 待插入的子节点
63
- * @param i position to be inserted at / 插入位置
64
- */
65
- insertAt(node, i = this.length) {
66
- (0, debug_1.setChildNodes)(this, i, 0, [node]);
67
- return node;
68
- }
69
- /**
70
- * Get the closest ancestor node that matches the selector
71
- *
72
- * 最近的符合选择器的祖先节点
73
- * @param selector selector / 选择器
74
- */
75
- closest(selector) {
76
- const condition = (0, selector_1.getCondition)(selector, this);
77
- let { parentNode } = this;
78
- while (parentNode) {
79
- if (condition(parentNode)) {
80
- return parentNode;
81
- }
82
- ({ parentNode } = parentNode);
98
+ /**
99
+ * Remove a child node
100
+ *
101
+ * 移除子节点
102
+ * @param i position of the child node / 移除位置
103
+ */
104
+ removeAt(i) {
105
+ return (0, debug_1.setChildNodes)(this, i, 1)[0];
83
106
  }
84
- return undefined;
85
- }
86
- /**
87
- * 符合条件的第一个后代节点
88
- * @param condition 条件
89
- */
90
- #getElementBy(condition) {
91
- for (const child of this.childNodes) {
92
- if (child.type === 'text') {
93
- continue;
94
- }
95
- else if (condition(child)) {
96
- return child;
97
- }
98
- const descendant = child.#getElementBy(condition);
99
- if (descendant) {
100
- return descendant;
107
+ /**
108
+ * Insert a child node
109
+ *
110
+ * 插入子节点
111
+ * @param node node to be inserted / 待插入的子节点
112
+ * @param i position to be inserted at / 插入位置
113
+ */
114
+ insertAt(node, i = this.length) {
115
+ (0, debug_1.setChildNodes)(this, i, 0, [node]);
116
+ return node;
117
+ }
118
+ /**
119
+ * Get the closest ancestor node that matches the selector
120
+ *
121
+ * 最近的符合选择器的祖先节点
122
+ * @param selector selector / 选择器
123
+ */
124
+ closest(selector) {
125
+ const condition = (0, selector_1.getCondition)(selector, this);
126
+ let { parentNode } = this;
127
+ while (parentNode) {
128
+ if (condition(parentNode)) {
129
+ return parentNode;
130
+ }
131
+ ({ parentNode } = parentNode);
101
132
  }
133
+ return undefined;
102
134
  }
103
- return undefined;
104
- }
105
- /**
106
- * Get the first descendant that matches the selector
107
- *
108
- * 符合选择器的第一个后代节点
109
- * @param selector selector / 选择器
110
- */
111
- querySelector(selector) {
112
- const condition = (0, selector_1.getCondition)(selector, this);
113
- return this.#getElementBy(condition);
114
- }
115
- /**
116
- * 符合条件的所有后代节点
117
- * @param condition 条件
118
- * @param descendants 已经找到的后代节点
119
- */
120
- #getElementsBy(condition, descendants = []) {
121
- for (const child of this.childNodes) {
122
- if (child.type === 'text') {
123
- continue;
135
+ /**
136
+ * Insert a batch of child nodes at the end
137
+ *
138
+ * 在末尾批量插入子节点
139
+ * @param elements nodes to be inserted / 插入节点
140
+ */
141
+ append(...elements) {
142
+ this.safeAppend(elements);
143
+ }
144
+ /** @private */
145
+ safeAppend(elements) {
146
+ for (const element of elements) {
147
+ this.insertAt(element);
124
148
  }
125
- else if (condition(child)) {
126
- descendants.push(child);
149
+ }
150
+ /**
151
+ * Replace all child nodes
152
+ *
153
+ * 批量替换子节点
154
+ * @param elements nodes to be inserted / 新的子节点
155
+ */
156
+ replaceChildren(...elements) {
157
+ this.safeReplaceChildren(elements);
158
+ }
159
+ /** @private */
160
+ safeReplaceChildren(elements) {
161
+ for (let i = this.length - 1; i >= 0; i--) {
162
+ this.removeAt(i);
127
163
  }
128
- child.#getElementsBy(condition, descendants);
164
+ this.safeAppend(elements);
129
165
  }
130
- return descendants;
131
- }
132
- /**
133
- * Get all descendants that match the selector
134
- *
135
- * 符合选择器的所有后代节点
136
- * @param selector selector / 选择器
137
- */
138
- querySelectorAll(selector) {
139
- const condition = (0, selector_1.getCondition)(selector, this);
140
- return this.#getElementsBy(condition);
141
- }
142
- /**
143
- * Insert a batch of child nodes at the end
144
- *
145
- * 在末尾批量插入子节点
146
- * @param elements nodes to be inserted / 插入节点
147
- */
148
- append(...elements) {
149
- this.safeAppend(elements);
150
- }
151
- /** @private */
152
- safeAppend(elements) {
153
- for (const element of elements) {
154
- this.insertAt(element);
166
+ /**
167
+ * Modify the text child node
168
+ *
169
+ * 修改文本子节点
170
+ * @param str new text / 新文本
171
+ * @param i position of the text child node / 子节点位置
172
+ */
173
+ setText(str, i = 0) {
174
+ i += i < 0 ? this.length : 0;
175
+ const oldText = this.childNodes[i];
176
+ const { data } = oldText;
177
+ oldText.replaceData(str);
178
+ return data;
155
179
  }
156
- }
157
- /**
158
- * Replace all child nodes
159
- *
160
- * 批量替换子节点
161
- * @param elements nodes to be inserted / 新的子节点
162
- */
163
- replaceChildren(...elements) {
164
- this.safeReplaceChildren(elements);
165
- }
166
- /** @private */
167
- safeReplaceChildren(elements) {
168
- for (let i = this.length - 1; i >= 0; i--) {
169
- this.removeAt(i);
180
+ /** @private */
181
+ toString(skip, separator = '') {
182
+ return this.childNodes.map(child => child.toString(skip)).join(separator);
170
183
  }
171
- this.safeAppend(elements);
172
- }
173
- /**
174
- * Modify the text child node
175
- *
176
- * 修改文本子节点
177
- * @param str new text / 新文本
178
- * @param i position of the text child node / 子节点位置
179
- */
180
- setText(str, i = 0) {
181
- i += i < 0 ? this.length : 0;
182
- const oldText = this.childNodes[i];
183
- const { data } = oldText;
184
- oldText.replaceData(str);
185
- return data;
186
- }
187
- /** @private */
188
- toString(skip, separator = '') {
189
- return this.childNodes.map(child => child.toString(skip)).join(separator);
190
- }
191
- /**
192
- * Get the caret position from the character index
193
- *
194
- * 找到给定位置
195
- * @param index character index / 位置
196
- */
197
- caretPositionFromIndex(index) {
198
- LSP: { // eslint-disable-line no-unused-labels
199
- if (index === undefined) {
200
- return undefined;
201
- }
202
- const { length } = this.toString();
203
- if (index > length || index < -length) {
204
- return undefined;
205
- }
206
- index += index < 0 ? length : 0;
207
- let self = this, acc = 0, start = 0;
208
- while (self.type !== 'text') {
209
- const { childNodes } = self;
210
- acc += self.getAttribute('padding');
211
- for (let i = 0; acc <= index && i < childNodes.length; i++) {
212
- const cur = childNodes[i], { nextSibling } = cur, str = cur.toString(), l = str.length;
213
- cur.setAttribute('aIndex', acc);
214
- acc += l;
215
- // 优先选择靠前的非文本兄弟节点,但永不进入假节点
216
- if (acc > index
217
- || acc === index && l > 0 && (!nextSibling
218
- || nextSibling.type === 'text'
219
- || cur.type !== 'text' && (str.trim() || !nextSibling.toString().trim()))) {
220
- self = cur;
221
- acc -= l;
222
- start = acc;
223
- break;
224
- }
225
- acc += self.getGaps(i);
184
+ /**
185
+ * Get the caret position from the character index
186
+ *
187
+ * 找到给定位置
188
+ * @param index character index / 位置
189
+ */
190
+ caretPositionFromIndex(index) {
191
+ LSP: { // eslint-disable-line no-unused-labels
192
+ if (index === undefined) {
193
+ return undefined;
226
194
  }
227
- if (self.childNodes === childNodes) {
228
- return { offsetNode: self, offset: index - start };
195
+ const { length } = this.toString();
196
+ if (index > length || index < -length) {
197
+ return undefined;
198
+ }
199
+ index += index < 0 ? length : 0;
200
+ let self = this, acc = 0, start = 0;
201
+ while (self.type !== 'text') {
202
+ const { childNodes } = self;
203
+ acc += self.getAttribute('padding');
204
+ for (let i = 0; acc <= index && i < childNodes.length; i++) {
205
+ const cur = childNodes[i], { nextSibling } = cur, str = cur.toString(), l = str.length;
206
+ cur.setAttribute('aIndex', acc);
207
+ acc += l;
208
+ // 优先选择靠前的非文本兄弟节点,但永不进入假节点
209
+ if (acc > index
210
+ || acc === index && l > 0 && (!nextSibling
211
+ || nextSibling.type === 'text'
212
+ || cur.type !== 'text' && (str.trim() || !nextSibling.toString().trim()))) {
213
+ self = cur;
214
+ acc -= l;
215
+ start = acc;
216
+ break;
217
+ }
218
+ acc += self.getGaps(i);
219
+ }
220
+ if (self.childNodes === childNodes) {
221
+ return { offsetNode: self, offset: index - start };
222
+ }
229
223
  }
224
+ return { offsetNode: self, offset: index - start };
230
225
  }
231
- return { offsetNode: self, offset: index - start };
232
226
  }
233
- }
234
- /**
235
- * Get the closest ancestor element from the character index
236
- *
237
- * 找到给定位置所在的最内层非文本节点
238
- * @param index character index / 位置
239
- */
240
- elementFromIndex(index) {
241
- LSP: { // eslint-disable-line no-unused-labels
242
- const node = this.caretPositionFromIndex(index)?.offsetNode;
243
- return node?.type === 'text' ? node.parentNode : node;
227
+ /**
228
+ * Get the closest ancestor element from the character index
229
+ *
230
+ * 找到给定位置所在的最内层非文本节点
231
+ * @param index character index / 位置
232
+ */
233
+ elementFromIndex(index) {
234
+ LSP: { // eslint-disable-line no-unused-labels
235
+ const node = this.caretPositionFromIndex(index)?.offsetNode;
236
+ return node?.type === 'text' ? node.parentNode : node;
237
+ }
244
238
  }
245
- }
246
- /**
247
- * Get the closest ancestor element from the position
248
- *
249
- * 找到给定位置所在的最内层非文本节点
250
- * @param x column number / 列数
251
- * @param y line number / 行数
252
- */
253
- elementFromPoint(x, y) {
254
- // eslint-disable-next-line no-unused-labels
255
- LSP: return this.elementFromIndex(this.indexFromPos(y, x));
256
- }
257
- /** @private */
258
- lint(start = this.getAbsoluteIndex(), re) {
259
- const errors = [];
260
- for (let i = 0, cur = start + this.getAttribute('padding'); i < this.length; i++) {
261
- const child = this.childNodes[i];
262
- child.setAttribute('aIndex', cur);
263
- const childErrors = child.lint(cur, re);
264
- if (childErrors.length > 0) {
265
- errors.push(...childErrors);
239
+ /**
240
+ * Get the closest ancestor element from the position
241
+ *
242
+ * 找到给定位置所在的最内层非文本节点
243
+ * @param x column number / 列数
244
+ * @param y line number / 行数
245
+ */
246
+ elementFromPoint(x, y) {
247
+ // eslint-disable-next-line no-unused-labels
248
+ LSP: return this.elementFromIndex(this.indexFromPos(y, x));
249
+ }
250
+ /** @private */
251
+ lint(start = this.getAbsoluteIndex(), re) {
252
+ const errors = [];
253
+ for (let i = 0, cur = start + this.getAttribute('padding'); i < this.length; i++) {
254
+ const child = this.childNodes[i];
255
+ child.setAttribute('aIndex', cur);
256
+ const childErrors = child.lint(cur, re);
257
+ if (childErrors.length > 0) {
258
+ errors.push(...childErrors);
259
+ }
260
+ cur += child.toString().length + this.getGaps(i);
266
261
  }
267
- cur += child.toString().length + this.getGaps(i);
262
+ return errors;
268
263
  }
269
- return errors;
270
- }
271
- }
264
+ };
265
+ return AstElement = _classThis;
266
+ })();
272
267
  exports.AstElement = AstElement;
package/dist/lib/lsp.js CHANGED
@@ -25,7 +25,7 @@ const cssRules = {
25
25
  let colors;
26
26
  /* NOT FOR BROWSER ONLY END */
27
27
  exports.tasks = new WeakMap();
28
- const refTags = new Set(['ref']), referencesTags = new Set(['ref', 'references']), nameAttrs = new Set(['name', 'extends', 'follow']), groupAttrs = new Set(['group']), renameTypes = new Set([
28
+ const refTags = new Set(['ref']), referencesTags = new Set(['ref', 'references']), nameAttrs = new Set(['name', 'follow']), groupAttrs = new Set(['group']), renameTypes = new Set([
29
29
  'arg-name',
30
30
  'template-name',
31
31
  'link-target',
@@ -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
  *
@@ -37,20 +40,12 @@ export declare abstract class AstNode implements AstNodeBase {
37
40
  lint(): LintError[] & {
38
41
  output?: string;
39
42
  };
40
- /** first child node / 首位子节点 */
41
- get firstChild(): AstNodes | undefined;
42
- /** last child node / 末位子节点 */
43
- get lastChild(): AstNodes | undefined;
44
43
  /** parent node / 父节点 */
45
44
  get parentNode(): Token | undefined;
46
45
  /** next sibling node / 后一个兄弟节点 */
47
46
  get nextSibling(): AstNodes | undefined;
48
47
  /** previous sibling node / 前一个兄弟节点 */
49
48
  get previousSibling(): AstNodes | undefined;
50
- /** number of lines / 行数 */
51
- get offsetHeight(): number;
52
- /** number of columns of the last line / 最后一行的列数 */
53
- get offsetWidth(): number;
54
49
  /**
55
50
  * Get the root node
56
51
  *
package/dist/lib/node.js CHANGED
@@ -39,20 +39,29 @@ exports.AstNode = void 0;
39
39
  const lint_1 = require("../util/lint");
40
40
  const debug_1 = require("../util/debug");
41
41
  const cached_1 = require("../mixin/cached");
42
+ const nodeLike_1 = require("../mixin/nodeLike");
42
43
  /**
43
44
  * Node-like
44
45
  *
45
46
  * 类似Node
46
47
  */
47
48
  let AstNode = (() => {
49
+ let _classDecorators = [nodeLike_1.nodeLike];
50
+ let _classDescriptor;
51
+ let _classExtraInitializers = [];
52
+ let _classThis;
48
53
  let _instanceExtraInitializers = [];
49
54
  let _getLines_decorators;
50
- return class AstNode {
55
+ var AstNode = class {
56
+ static { _classThis = this; }
51
57
  static {
52
58
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
53
59
  _getLines_decorators = [(0, cached_1.cached)(false)];
54
60
  __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);
55
- if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
61
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
62
+ AstNode = _classThis = _classDescriptor.value;
63
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
64
+ __runInitializers(_classThis, _classExtraInitializers);
56
65
  }
57
66
  childNodes = (__runInitializers(this, _instanceExtraInitializers), []);
58
67
  #parentNode;
@@ -61,14 +70,6 @@ let AstNode = (() => {
61
70
  #root;
62
71
  #aIndex;
63
72
  #rIndex = {};
64
- /** first child node / 首位子节点 */
65
- get firstChild() {
66
- return this.childNodes[0];
67
- }
68
- /** last child node / 末位子节点 */
69
- get lastChild() {
70
- return this.childNodes[this.childNodes.length - 1];
71
- }
72
73
  /** parent node / 父节点 */
73
74
  get parentNode() {
74
75
  return this.#parentNode;
@@ -81,14 +82,6 @@ let AstNode = (() => {
81
82
  get previousSibling() {
82
83
  return this.#previousSibling;
83
84
  }
84
- /** number of lines / 行数 */
85
- get offsetHeight() {
86
- return this.#getDimension().height;
87
- }
88
- /** number of columns of the last line / 最后一行的列数 */
89
- get offsetWidth() {
90
- return this.#getDimension().width;
91
- }
92
85
  /** @private */
93
86
  getChildNodes() {
94
87
  const { childNodes } = this;
@@ -169,8 +162,8 @@ let AstNode = (() => {
169
162
  }
170
163
  return undefined;
171
164
  }
172
- /** 获取行数和最后一行的列数 */
173
- #getDimension() {
165
+ /** @private */
166
+ getDimension() {
174
167
  const lines = this.getLines(), last = lines[lines.length - 1];
175
168
  return { height: lines.length, width: last[2] - last[1] };
176
169
  }
@@ -224,7 +217,7 @@ let AstNode = (() => {
224
217
  getBoundingClientRect() {
225
218
  // eslint-disable-next-line no-unused-labels
226
219
  LSP: return {
227
- ...this.#getDimension(),
220
+ ...this.getDimension(),
228
221
  ...this.getRootNode().posFromIndex(this.getAbsoluteIndex()),
229
222
  };
230
223
  }
@@ -255,5 +248,6 @@ let AstNode = (() => {
255
248
  return results;
256
249
  }
257
250
  };
251
+ return AstNode = _classThis;
258
252
  })();
259
253
  exports.AstNode = AstNode;
package/dist/lib/text.js CHANGED
@@ -86,7 +86,7 @@ class AstText extends node_1.AstNode {
86
86
  const { type, name, parentNode: grandparent } = parentNode;
87
87
  if (type === 'attr-value') {
88
88
  const { name: grandName, tag } = grandparent;
89
- if (tag === 'ref' && (grandName === 'name' || grandName === 'extends' || grandName === 'follow')
89
+ if (tag === 'ref' && (grandName === 'name' || grandName === 'follow')
90
90
  || grandName === 'group' && (tag === 'ref' || tag === 'references')
91
91
  || tag === 'choose' && (grandName === 'before' || grandName === 'after')) {
92
92
  return [];
@@ -7,21 +7,20 @@ const debug_1 = require("../util/debug");
7
7
  * @param i AttributesToken子节点的位置
8
8
  */
9
9
  const attributesParent = (i = 0) => (constructor) => {
10
- /** 子节点含有AttributesToken的类 */
10
+ /* eslint-disable jsdoc/require-jsdoc */
11
11
  class AttributesParent extends constructor {
12
12
  /** AttributesToken子节点 */
13
13
  #getAttributesChild() {
14
14
  return this.childNodes[i];
15
15
  }
16
- /** @implements */
17
16
  hasAttr(key) {
18
17
  return this.#getAttributesChild().hasAttr(key);
19
18
  }
20
- /** @implements */
21
19
  getAttr(key) {
22
20
  return this.#getAttributesChild().getAttr(key);
23
21
  }
24
22
  }
23
+ /* eslint-enable jsdoc/require-jsdoc */
25
24
  (0, debug_1.mixin)(AttributesParent, constructor);
26
25
  return AttributesParent;
27
26
  };
@@ -0,0 +1,21 @@
1
+ import type { AstNodes, Token } from '../internal';
2
+ declare type ElementConstructor = abstract new (...args: any[]) => {
3
+ readonly childNodes: readonly AstNodes[];
4
+ };
5
+ export interface ElementLike {
6
+ /**
7
+ * Get the first descendant that matches the selector
8
+ *
9
+ * 符合选择器的第一个后代节点
10
+ * @param selector selector / 选择器
11
+ */
12
+ querySelector<T = Token>(selector: string): T | undefined;
13
+ /**
14
+ * Get all descendants that match the selector
15
+ *
16
+ * 符合选择器的所有后代节点
17
+ * @param selector selector / 选择器
18
+ */
19
+ querySelectorAll<T = Token>(selector: string): T[];
20
+ }
21
+ /** @ignore */
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.elementLike = void 0;
4
+ const debug_1 = require("../util/debug");
5
+ const selector_1 = require("../parser/selector");
6
+ /** @ignore */
7
+ const elementLike = (constructor) => {
8
+ /* eslint-disable jsdoc/require-jsdoc */
9
+ class ElementLike extends constructor {
10
+ #getCondition(selector) {
11
+ return (0, selector_1.getCondition)(selector,
12
+ // @ts-expect-error only AstElement
13
+ this);
14
+ }
15
+ getElementBy(condition) {
16
+ for (const child of this.childNodes) {
17
+ if (child.type === 'text') {
18
+ continue;
19
+ }
20
+ else if (condition(child)) {
21
+ return child;
22
+ }
23
+ const descendant = child.getElementBy(condition);
24
+ if (descendant) {
25
+ return descendant;
26
+ }
27
+ }
28
+ return undefined;
29
+ }
30
+ querySelector(selector) {
31
+ return this.getElementBy(this.#getCondition(selector));
32
+ }
33
+ getElementsBy(condition, descendants = []) {
34
+ for (const child of this.childNodes) {
35
+ if (child.type === 'text') {
36
+ continue;
37
+ }
38
+ else if (condition(child)) {
39
+ descendants.push(child);
40
+ }
41
+ child.getElementsBy(condition, descendants);
42
+ }
43
+ return descendants;
44
+ }
45
+ querySelectorAll(selector) {
46
+ return this.getElementsBy(this.#getCondition(selector));
47
+ }
48
+ }
49
+ /* eslint-enable jsdoc/require-jsdoc */
50
+ (0, debug_1.mixin)(ElementLike, constructor);
51
+ return ElementLike;
52
+ };
53
+ exports.elementLike = elementLike;
@@ -7,13 +7,13 @@ const debug_1 = require("../util/debug");
7
7
  * @param gap
8
8
  */
9
9
  const gapped = (gap = 1) => (constructor) => {
10
- /** 不可增删子节点的类 */
10
+ /* eslint-disable jsdoc/require-jsdoc */
11
11
  class GappedToken extends constructor {
12
- /** @private */
13
12
  getGaps() {
14
13
  return gap;
15
14
  }
16
15
  }
16
+ /* eslint-enable jsdoc/require-jsdoc */
17
17
  (0, debug_1.mixin)(GappedToken, constructor);
18
18
  return GappedToken;
19
19
  };
@@ -8,7 +8,7 @@ const debug_1 = require("../util/debug");
8
8
  * @param html 是否覆写 toHtml 方法
9
9
  */
10
10
  const hiddenToken = (linter = true, html = true) => (constructor) => {
11
- /** 解析后不可见的类 */
11
+ /* eslint-disable jsdoc/require-jsdoc */
12
12
  class AnyHiddenToken extends constructor {
13
13
  /** 没有可见部分 */
14
14
  text() {
@@ -19,6 +19,7 @@ const hiddenToken = (linter = true, html = true) => (constructor) => {
19
19
  return linter ? [] : super.lint(start);
20
20
  }
21
21
  }
22
+ /* eslint-enable jsdoc/require-jsdoc */
22
23
  (0, debug_1.mixin)(AnyHiddenToken, constructor);
23
24
  return AnyHiddenToken;
24
25
  };
@@ -7,7 +7,7 @@ const debug_1 = require("../util/debug");
7
7
  * @ignore
8
8
  */
9
9
  const multiLine = (constructor) => {
10
- /** 不可包含换行符的类 */
10
+ /* eslint-disable jsdoc/require-jsdoc */
11
11
  class MultiLineToken extends constructor {
12
12
  toString(skip) {
13
13
  return super.toString(skip, '\n');
@@ -15,11 +15,11 @@ const multiLine = (constructor) => {
15
15
  text() {
16
16
  return super.text('\n').replace(/\n\s*\n/gu, '\n');
17
17
  }
18
- /** @private */
19
18
  getGaps() {
20
19
  return 1;
21
20
  }
22
21
  }
22
+ /* eslint-enable jsdoc/require-jsdoc */
23
23
  (0, debug_1.mixin)(MultiLineToken, constructor);
24
24
  return MultiLineToken;
25
25
  };
@@ -0,0 +1,17 @@
1
+ import type { Dimension } from '../lib/node';
2
+ import type { AstNodes } from '../internal';
3
+ declare type NodeConstructor = abstract new (...args: any[]) => {
4
+ readonly childNodes: readonly AstNodes[];
5
+ getDimension(): Dimension;
6
+ };
7
+ export interface NodeLike {
8
+ /** first child node / 首位子节点 */
9
+ readonly firstChild: AstNodes | undefined;
10
+ /** last child node / 末位子节点 */
11
+ readonly lastChild: AstNodes | undefined;
12
+ /** number of lines / 行数 */
13
+ readonly offsetHeight: number;
14
+ /** number of columns of the last line / 最后一行的列数 */
15
+ readonly offsetWidth: number;
16
+ }
17
+ /** @ignore */
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nodeLike = void 0;
4
+ const debug_1 = require("../util/debug");
5
+ /** @ignore */
6
+ const nodeLike = (constructor) => {
7
+ /* eslint-disable jsdoc/require-jsdoc */
8
+ class NodeLike extends constructor {
9
+ get firstChild() {
10
+ return this.childNodes[0];
11
+ }
12
+ get lastChild() {
13
+ return this.childNodes[this.childNodes.length - 1];
14
+ }
15
+ get offsetHeight() {
16
+ return this.getDimension().height;
17
+ }
18
+ get offsetWidth() {
19
+ return this.getDimension().width;
20
+ }
21
+ }
22
+ /* eslint-enable jsdoc/require-jsdoc */
23
+ (0, debug_1.mixin)(NodeLike, constructor);
24
+ return NodeLike;
25
+ };
26
+ exports.nodeLike = nodeLike;
@@ -8,12 +8,13 @@ const debug_1 = require("../util/debug");
8
8
  * @param padding.length
9
9
  */
10
10
  const padded = ({ length }) => (constructor) => {
11
- /** 不可增删子节点的类 */
11
+ /* eslint-disable jsdoc/require-jsdoc */
12
12
  class PaddedToken extends constructor {
13
13
  getAttribute(key) {
14
14
  return key === 'padding' ? length : super.getAttribute(key);
15
15
  }
16
16
  }
17
+ /* eslint-enable jsdoc/require-jsdoc */
17
18
  (0, debug_1.mixin)(PaddedToken, constructor);
18
19
  return PaddedToken;
19
20
  };
@@ -12,6 +12,6 @@ export declare class AtomToken extends Token {
12
12
  get type(): AtomTypes;
13
13
  set type(value: AtomTypes);
14
14
  /** @class */
15
- constructor(wikitext: string | undefined, type: AtomTypes, config?: Config, accum?: Token[], acceptable?: Acceptable);
15
+ constructor(wikitext: string | undefined, type: AtomTypes, config?: Config, accum?: Token[], acceptable?: WikiParserAcceptable);
16
16
  }
17
17
  export {};
@@ -15,7 +15,7 @@ export declare class Token extends AstElement {
15
15
  get type(): TokenTypes;
16
16
  set type(value: TokenTypes);
17
17
  /** @class */
18
- constructor(wikitext?: string, config?: Parser.Config, accum?: Token[], acceptable?: Acceptable);
18
+ constructor(wikitext?: string, config?: Parser.Config, accum?: Token[], acceptable?: WikiParserAcceptable);
19
19
  /**
20
20
  * @override
21
21
  * @param child node to be inserted / 待插入的子节点
@@ -79,7 +79,7 @@ let GalleryImageToken = (() => {
79
79
  if (text !== undefined) {
80
80
  const { length } = accum;
81
81
  token = new index_2.Token(text, config, accum);
82
- for (let n = 1; n < constants_1.MAX_STAGE; n++) {
82
+ for (let n = 0; n < constants_1.MAX_STAGE - 1; n++) {
83
83
  token.parseOnce();
84
84
  }
85
85
  accum.splice(length, 1);
@@ -34,7 +34,7 @@ class NestedToken extends index_2.Token {
34
34
  */
35
35
  constructor(wikitext, regex, tags, config, accum = []) {
36
36
  if (typeof regex === 'boolean') {
37
- const placeholder = Symbol('InputboxToken'), { length } = accum;
37
+ const placeholder = Symbol('NestedToken'), { length } = accum;
38
38
  accum.push(placeholder);
39
39
  wikitext &&= (0, commentAndExt_1.parseCommentAndExt)(wikitext, config, accum, regex);
40
40
  wikitext &&= (0, braces_1.parseBraces)(wikitext, config, accum);
@@ -17,5 +17,5 @@ export declare abstract class ParamTagToken extends Token {
17
17
  abstract get parentNode(): ExtToken | undefined;
18
18
  get type(): 'ext-inner';
19
19
  /** @class */
20
- constructor(include: boolean, wikitext?: string, config?: Parser.Config, accum?: Token[], acceptable?: Acceptable);
20
+ constructor(include: boolean, wikitext?: string, config?: Parser.Config, accum?: Token[], acceptable?: WikiParserAcceptable);
21
21
  }
@@ -12,6 +12,6 @@ export declare class SyntaxToken extends Token {
12
12
  /**
13
13
  * @class
14
14
  */
15
- constructor(wikitext: string | undefined, type: SyntaxTypes, config?: Config, accum?: Token[], acceptable?: Acceptable);
15
+ constructor(wikitext: string | undefined, type: SyntaxTypes, config?: Config, accum?: Token[], acceptable?: WikiParserAcceptable);
16
16
  }
17
17
  export {};
@@ -17,6 +17,6 @@ export declare abstract class TableBaseToken extends Token {
17
17
  * @param type 节点类型
18
18
  * @param attr 表格属性
19
19
  */
20
- constructor(pattern: RegExp, syntax: string, type: TableTypes, attr?: string, config?: Config, accum?: Token[], acceptable?: Acceptable);
20
+ constructor(pattern: RegExp, syntax: string, type: TableTypes, attr?: string, config?: Config, accum?: Token[], acceptable?: WikiParserAcceptable);
21
21
  }
22
22
  export {};
@@ -35,18 +35,12 @@ export declare abstract class TableToken extends TrBaseToken {
35
35
  *
36
36
  * 闭合表格语法
37
37
  * @param syntax syntax of the table end / 表格结尾语法
38
- * @param halfParsed
39
38
  */
40
39
  close(syntax?: string, halfParsed?: boolean): void;
41
40
  /**
42
41
  * Get the table layout
43
42
  *
44
43
  * 获取表格布局
45
- * @param stop stop condition / 中止条件
46
- * @param stop.row stop at the row / 中止行
47
- * @param stop.column stop at the column / 中止列
48
- * @param stop.x stop at the row / 中止行
49
- * @param stop.y stop at the column / 中止列
50
44
  */
51
45
  getLayout(stop?: {
52
46
  row?: number;
@@ -65,9 +59,6 @@ export declare abstract class TableToken extends TrBaseToken {
65
59
  *
66
60
  * 获取第n行
67
61
  * @param n row number / 行号
68
- * @param force whether to regard the table itself as the first row / 是否将表格自身视为第一行
69
- * @param insert whether to be used to insert a new row / 是否用于判断插入新行的位置
70
- * @throws `RangeError` 不存在该行
71
62
  */
72
63
  getNthRow(n: number, force?: boolean, insert?: false): TrToken | this | undefined;
73
64
  }
@@ -130,12 +130,12 @@ let TableToken = (() => {
130
130
  }
131
131
  return errors;
132
132
  }
133
+ // eslint-disable-next-line jsdoc/require-param
133
134
  /**
134
135
  * Close the table syntax
135
136
  *
136
137
  * 闭合表格语法
137
138
  * @param syntax syntax of the table end / 表格结尾语法
138
- * @param halfParsed
139
139
  */
140
140
  close(syntax = '\n|}', halfParsed) {
141
141
  const config = this.getAttribute('config'), accum = this.getAttribute('accum'), inner = [syntax];
@@ -145,15 +145,11 @@ let TableToken = (() => {
145
145
  });
146
146
  this.lastChild.safeReplaceChildren(inner);
147
147
  }
148
+ // eslint-disable-next-line jsdoc/require-param
148
149
  /**
149
150
  * Get the table layout
150
151
  *
151
152
  * 获取表格布局
152
- * @param stop stop condition / 中止条件
153
- * @param stop.row stop at the row / 中止行
154
- * @param stop.column stop at the column / 中止列
155
- * @param stop.x stop at the row / 中止行
156
- * @param stop.y stop at the column / 中止列
157
153
  */
158
154
  getLayout(stop) {
159
155
  const rows = this.getAllRows(), { length } = rows, layout = Layout.from(emptyArray(length, () => []));
@@ -74,8 +74,6 @@ export declare abstract class TranscludeToken extends Token {
74
74
  *
75
75
  * 获取指定参数
76
76
  * @param key parameter name / 参数名
77
- * @param exact whether to match anonymosity / 是否匹配匿名性
78
- * @param copy whether to return a copy / 是否返回一个备份
79
77
  */
80
78
  getArgs(key: string | number, exact?: boolean, copy?: boolean): Set<ParameterToken>;
81
79
  /**
@@ -364,13 +364,12 @@ let TranscludeToken = (() => {
364
364
  getAnonArgs() {
365
365
  return this.getAllArgs().filter(({ anon }) => anon);
366
366
  }
367
+ // eslint-disable-next-line jsdoc/require-param
367
368
  /**
368
369
  * Get parameters with the specified name
369
370
  *
370
371
  * 获取指定参数
371
372
  * @param key parameter name / 参数名
372
- * @param exact whether to match anonymosity / 是否匹配匿名性
373
- * @param copy whether to return a copy / 是否返回一个备份
374
373
  */
375
374
  getArgs(key, exact, copy = true) {
376
375
  const keyStr = String(key)
@@ -59,6 +59,7 @@ const setChildNodes = (parent, position, deleteCount, inserted = []) => {
59
59
  return removed;
60
60
  };
61
61
  exports.setChildNodes = setChildNodes;
62
+ /* NOT FOR BROWSER ONLY */
62
63
  /**
63
64
  * 同步混入的类名
64
65
  * @param target 混入的目标
@@ -96,7 +96,7 @@ exports.commonHtmlAttrs = new Set([
96
96
  nowiki: empty,
97
97
  indicator: new Set(['name']),
98
98
  langconvert: new Set(['from', 'to']),
99
- ref: new Set(['group', 'name', 'extends', 'follow', 'dir']),
99
+ ref: new Set(['group', 'name', 'follow', 'dir', 'details']),
100
100
  references: new Set(['group', 'responsive']),
101
101
  charinsert: new Set(['label']),
102
102
  choose: new Set(['uncached', 'before', 'after']),
@@ -94,7 +94,7 @@ const commonHtmlAttrs = /* @__PURE__ */ new Set([
94
94
  nowiki: empty,
95
95
  indicator: /* @__PURE__ */ new Set(["name"]),
96
96
  langconvert: /* @__PURE__ */ new Set(["from", "to"]),
97
- ref: /* @__PURE__ */ new Set(["group", "name", "extends", "follow", "dir"]),
97
+ ref: /* @__PURE__ */ new Set(["group", "name", "follow", "dir", "details"]),
98
98
  references: /* @__PURE__ */ new Set(["group", "responsive"]),
99
99
  charinsert: /* @__PURE__ */ new Set(["label"]),
100
100
  choose: /* @__PURE__ */ new Set(["uncached", "before", "after"]),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wikilint",
3
- "version": "2.22.1",
3
+ "version": "2.23.0",
4
4
  "description": "A Node.js linter for MediaWiki markup",
5
5
  "keywords": [
6
6
  "mediawiki",
@@ -39,7 +39,6 @@
39
39
  "url": "git+https://github.com/bhsd-harry/wikiparser-node.git"
40
40
  },
41
41
  "scripts": {
42
- "declaration": "grep -rl --include='*.d.ts' '@private' dist/ | xargs bash sed.sh -i -E '/^\\s+\\/\\*\\* @private/,+1d'; grep -rl --include='*.d.ts' '/util/' dist/ | xargs bash sed.sh -i -E '/^import .+\\/util\\//d'; bash sed.sh -i -E 's/abstract (lint|print|text)\\b/\\1/' dist/lib/node.d.ts; node dist/script/declaration.js",
43
42
  "prepublishOnly": "npm run build:core",
44
43
  "build:core": "bash build.sh",
45
44
  "build": "npm run build:core",