wikilint 2.21.2 → 2.22.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 (66) hide show
  1. package/config/default.json +15 -11
  2. package/config/enwiki.json +1 -1
  3. package/config/jawiki.json +1 -1
  4. package/config/minimum.json +2 -3
  5. package/config/moegirl.json +152 -15
  6. package/config/zhwiki.json +1 -1
  7. package/dist/base.d.mts +16 -9
  8. package/dist/base.d.ts +16 -9
  9. package/dist/bin/config.js +23 -11
  10. package/dist/index.d.ts +11 -2
  11. package/dist/index.js +25 -2
  12. package/dist/lib/element.d.ts +3 -3
  13. package/dist/lib/element.js +3 -3
  14. package/dist/lib/lintConfig.d.ts +13 -0
  15. package/dist/lib/lintConfig.js +274 -0
  16. package/dist/lib/lsp.d.ts +7 -7
  17. package/dist/lib/lsp.js +18 -20
  18. package/dist/lib/node.js +233 -193
  19. package/dist/lib/text.js +72 -62
  20. package/dist/mixin/attributesParent.d.ts +7 -0
  21. package/dist/mixin/attributesParent.js +4 -0
  22. package/dist/mixin/cached.d.ts +5 -0
  23. package/dist/mixin/cached.js +18 -0
  24. package/dist/parser/commentAndExt.js +6 -4
  25. package/dist/parser/converter.js +1 -1
  26. package/dist/parser/html.js +3 -3
  27. package/dist/parser/table.js +2 -2
  28. package/dist/src/arg.js +12 -7
  29. package/dist/src/attribute.js +53 -21
  30. package/dist/src/attributes.d.ts +7 -0
  31. package/dist/src/attributes.js +19 -8
  32. package/dist/src/commented.js +1 -1
  33. package/dist/src/converterFlags.js +20 -13
  34. package/dist/src/converterRule.js +1 -1
  35. package/dist/src/extLink.js +10 -6
  36. package/dist/src/gallery.js +26 -19
  37. package/dist/src/heading.js +32 -27
  38. package/dist/src/html.js +63 -44
  39. package/dist/src/imageParameter.js +13 -6
  40. package/dist/src/imagemap.js +18 -16
  41. package/dist/src/index.js +54 -47
  42. package/dist/src/link/base.js +22 -11
  43. package/dist/src/link/file.js +22 -14
  44. package/dist/src/link/galleryImage.js +9 -5
  45. package/dist/src/link/index.js +7 -3
  46. package/dist/src/link/redirectTarget.js +7 -3
  47. package/dist/src/magicLink.js +16 -12
  48. package/dist/src/nested.js +6 -2
  49. package/dist/src/nowiki/comment.js +5 -1
  50. package/dist/src/nowiki/index.js +4 -4
  51. package/dist/src/nowiki/quote.js +19 -38
  52. package/dist/src/paramTag/index.js +6 -2
  53. package/dist/src/parameter.js +23 -13
  54. package/dist/src/table/index.js +173 -124
  55. package/dist/src/table/td.js +171 -118
  56. package/dist/src/table/trBase.js +11 -8
  57. package/dist/src/tagPair/ext.js +6 -5
  58. package/dist/src/tagPair/include.js +5 -5
  59. package/dist/src/transclude.js +24 -11
  60. package/dist/util/lint.js +5 -6
  61. package/dist/util/sharable.js +1 -1
  62. package/dist/util/sharable.mjs +2 -2
  63. package/dist/util/string.js +1 -5
  64. package/i18n/zh-hans.json +1 -1
  65. package/i18n/zh-hant.json +1 -1
  66. package/package.json +20 -15
package/dist/lib/lsp.js CHANGED
@@ -15,7 +15,7 @@ const path_1 = __importDefault(require("path"));
15
15
  const util_1 = __importDefault(require("util"));
16
16
  const child_process_1 = require("child_process");
17
17
  const crypto_1 = require("crypto");
18
- const stylelint_1 = require("@bhsd/common/dist/stylelint");
18
+ const stylelint_util_1 = require("@bhsd/stylelint-util");
19
19
  const document_1 = require("./document");
20
20
  /** @see https://www.npmjs.com/package/stylelint-config-recommended */
21
21
  const cssRules = {
@@ -472,7 +472,9 @@ class LanguageService {
472
472
  */
473
473
  // eslint-disable-next-line @typescript-eslint/class-methods-use-this
474
474
  provideColorPresentations(color) {
475
- const { color: { red, green, blue, alpha }, range } = color, newText = `#${(0, common_1.numToHex)(red)}${(0, common_1.numToHex)(green)}${(0, common_1.numToHex)(blue)}${alpha < 1 ? (0, common_1.numToHex)(alpha) : ''}`;
475
+ const { color: { red, green, blue, alpha }, range } = color, rgb = [red, green, blue], newText = alpha < 1
476
+ ? `rgba(${rgb.map(c => Math.round(c * 255)).join()},${alpha})`
477
+ : `#${rgb.map(common_1.numToHex).join('')}`;
476
478
  return [
477
479
  {
478
480
  label: newText,
@@ -526,7 +528,7 @@ class LanguageService {
526
528
  *
527
529
  * 提供自动补全
528
530
  * @param text source Wikitext / 源代码
529
- * @param position 位置
531
+ * @param position position / 位置
530
532
  */
531
533
  async provideCompletionItems(text, position) {
532
534
  const { re, allTags, functions, switches, protocols, params, tags, ext } = this.#prepareCompletionConfig(), { line, character } = position, curLine = text.split(/\r?\n/u, line + 1)[line], mt = re.exec(curLine?.slice(0, character) ?? ''), [, , iAlias = {}, sAlias = {}] = this.config.doubleUnderscore;
@@ -701,7 +703,7 @@ class LanguageService {
701
703
  const word = /\\\w+$/u.exec(curLine.slice(0, character))?.[0];
702
704
  if (word) {
703
705
  const data = this.#mathData;
704
- return getCompletion(cur.name === 'math' && parentNode.getAttr('chem') !== undefined
706
+ return getCompletion(cur.name === 'math' && parentNode.hasAttr('chem')
705
707
  ? [...data, String.raw `\ce`]
706
708
  : data, 'Function', word, position);
707
709
  }
@@ -754,7 +756,7 @@ class LanguageService {
754
756
  if (tokens.length === 0) {
755
757
  return [];
756
758
  }
757
- const cssErrors = await (0, stylelint_1.styleLint)((await document_1.stylelint), tokens.map(({ type, tag, lastChild }, i) => `${type === 'ext-attr' ? 'div' : tag}#${i}{\n${(0, common_1.sanitizeInlineStyle)(lastChild.toString())}\n}`).join('\n'), cssRules);
759
+ const cssErrors = await (0, stylelint_util_1.styleLint)((await document_1.stylelint), tokens.map(({ type, tag, lastChild }, i) => `${type === 'ext-attr' ? 'div' : tag}#${i}{\n${(0, common_1.sanitizeInlineStyle)(lastChild.toString())}\n}`).join('\n'), cssRules);
758
760
  if (cssErrors.length === 0) {
759
761
  return [];
760
762
  }
@@ -807,7 +809,7 @@ class LanguageService {
807
809
  fs_1.default.mkdirSync(dir);
808
810
  }
809
811
  lilypondDiagnostics = await Promise.all(tokens.map(async (token) => {
810
- const { innerText } = token, score = `showLastLength = R1${token.getAttr('raw') === undefined ? ` \\score {\n${innerText}\n}` : `\n${innerText}`}`;
812
+ const { innerText } = token, score = `showLastLength = R1${token.hasAttr('raw') ? `\n${innerText}` : ` \\score {\n${innerText}\n}`}`;
811
813
  if (scores.has(score)) {
812
814
  return getLilyPondDiagnostics(root, token, scores.get(score));
813
815
  }
@@ -844,7 +846,7 @@ class LanguageService {
844
846
  if (selfClosing) {
845
847
  return [];
846
848
  }
847
- const hasCe = name === 'math' && token.getAttr('chem') !== undefined, mathErrors = [...innerText.matchAll(/\\\w+/gu)]
849
+ const hasCe = name === 'math' && token.hasAttr('chem'), mathErrors = [...innerText.matchAll(/\\\w+/gu)]
848
850
  .filter(([macro]) => !(hasCe && macro === String.raw `\ce` || data.has(macro)))
849
851
  .map(({ 0: macro, index }) => {
850
852
  const aIndex = lastChild.getAbsoluteIndex() + index;
@@ -1048,7 +1050,7 @@ class LanguageService {
1048
1050
  *
1049
1051
  * 提供引用
1050
1052
  * @param text source Wikitext / 源代码
1051
- * @param position 位置
1053
+ * @param position position / 位置
1052
1054
  */
1053
1055
  async provideReferences(text, position) {
1054
1056
  const root = await this.#queue(text), { offsetNode, offset } = caretPositionFromWord(root, this.#text, position), element = offsetNode.type === 'text' ? offsetNode.parentNode : offsetNode, node = offset === 0 && (element.type === 'ext-attr-dirty' || element.type === 'html-attr-dirty')
@@ -1069,7 +1071,7 @@ class LanguageService {
1069
1071
  *
1070
1072
  * 提供定义
1071
1073
  * @param text source Wikitext / 源代码
1072
- * @param position 位置
1074
+ * @param position position / 位置
1073
1075
  */
1074
1076
  async provideDefinition(text, position) {
1075
1077
  const root = await this.#queue(text), node = root.elementFromPoint(position.character, position.line), ext = node.is('ext') && node.name === 'ref'
@@ -1090,7 +1092,7 @@ class LanguageService {
1090
1092
  *
1091
1093
  * 提供变量更名准备
1092
1094
  * @param text source Wikitext / 源代码
1093
- * @param position 位置
1095
+ * @param position position / 位置
1094
1096
  */
1095
1097
  async resolveRenameLocation(text, position) {
1096
1098
  const root = await this.#queue(text), node = root.elementFromPoint(position.character, position.line), { type } = node, refName = getRefName(node), refGroup = getRefGroup(node);
@@ -1105,7 +1107,7 @@ class LanguageService {
1105
1107
  *
1106
1108
  * 变量更名
1107
1109
  * @param text source Wikitext / 源代码
1108
- * @param position 位置
1110
+ * @param position position / 位置
1109
1111
  * @param newName new name / 新名称
1110
1112
  */
1111
1113
  async provideRenameEdits(text, position, newName) {
@@ -1151,7 +1153,7 @@ class LanguageService {
1151
1153
  *
1152
1154
  * 提供悬停信息
1153
1155
  * @param text source Wikitext / 源代码
1154
- * @param position 位置
1156
+ * @param position position / 位置
1155
1157
  */
1156
1158
  async provideHover(text, position) {
1157
1159
  /* istanbul ignore next */
@@ -1247,7 +1249,7 @@ class LanguageService {
1247
1249
  *
1248
1250
  * 提供魔术字帮助
1249
1251
  * @param text source Wikitext / 源代码
1250
- * @param position 位置
1252
+ * @param position position / 位置
1251
1253
  */
1252
1254
  async provideSignatureHelp(text, position) {
1253
1255
  /* istanbul ignore next */
@@ -1388,19 +1390,15 @@ class LanguageService {
1388
1390
  * @since v1.18.1
1389
1391
  */
1390
1392
  async setTargetWikipedia(wiki) {
1391
- const mt = /^https?:\/\/([^./]+)\.wikipedia\.org/iu.exec(wiki);
1392
- if (!mt) {
1393
- throw new RangeError('Invalid Wikipedia URL!');
1394
- }
1395
- const site = `${mt[1].toLowerCase()}wiki`;
1393
+ const [site, host] = index_1.default.getWMFSite(wiki);
1396
1394
  try {
1397
1395
  const config = require(path_1.default.join('..', '..', 'config', site));
1398
1396
  this.config = index_1.default.getConfig(config);
1399
1397
  }
1400
1398
  catch {
1401
- this.config = await index_1.default.fetchConfig(site, `${mt[0]}/w`);
1399
+ this.config = await index_1.default.fetchConfig(site, `${host}/w`);
1402
1400
  }
1403
- Object.assign(this.config, { articlePath: `${mt[0]}/wiki/` });
1401
+ Object.assign(this.config, { articlePath: `${host}/wiki/` });
1404
1402
  }
1405
1403
  }
1406
1404
  exports.LanguageService = LanguageService;
package/dist/lib/node.js CHANGED
@@ -1,208 +1,250 @@
1
1
  "use strict";
2
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
3
+ var useValue = arguments.length > 2;
4
+ for (var i = 0; i < initializers.length; i++) {
5
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
6
+ }
7
+ return useValue ? value : void 0;
8
+ };
9
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
10
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
11
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
12
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
13
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
14
+ var _, done = false;
15
+ for (var i = decorators.length - 1; i >= 0; i--) {
16
+ var context = {};
17
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
18
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
19
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
20
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
21
+ if (kind === "accessor") {
22
+ if (result === void 0) continue;
23
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
24
+ if (_ = accept(result.get)) descriptor.get = _;
25
+ if (_ = accept(result.set)) descriptor.set = _;
26
+ if (_ = accept(result.init)) initializers.unshift(_);
27
+ }
28
+ else if (_ = accept(result)) {
29
+ if (kind === "field") initializers.unshift(_);
30
+ else descriptor[key] = _;
31
+ }
32
+ }
33
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
34
+ done = true;
35
+ };
2
36
  Object.defineProperty(exports, "__esModule", { value: true });
3
37
  exports.AstNode = void 0;
4
38
  /* eslint-disable @typescript-eslint/no-base-to-string */
5
39
  const lint_1 = require("../util/lint");
6
40
  const debug_1 = require("../util/debug");
41
+ const cached_1 = require("../mixin/cached");
7
42
  /**
8
43
  * Node-like
9
44
  *
10
45
  * 类似Node
11
46
  */
12
- class AstNode {
13
- childNodes = [];
14
- #parentNode;
15
- #nextSibling;
16
- #previousSibling;
17
- #lines;
18
- #root;
19
- #aIndex;
20
- #rIndex = {};
21
- /** first child node / 首位子节点 */
22
- get firstChild() {
23
- return this.childNodes[0];
24
- }
25
- /** last child node / 末位子节点 */
26
- get lastChild() {
27
- return this.childNodes[this.childNodes.length - 1];
28
- }
29
- /** parent node / 父节点 */
30
- get parentNode() {
31
- return this.#parentNode;
32
- }
33
- /** next sibling node / 后一个兄弟节点 */
34
- get nextSibling() {
35
- return this.#nextSibling;
36
- }
37
- /** previous sibling node / 前一个兄弟节点 */
38
- get previousSibling() {
39
- return this.#previousSibling;
40
- }
41
- /** number of lines / 行数 */
42
- get offsetHeight() {
43
- return this.#getDimension().height;
44
- }
45
- /** number of columns of the last line / 最后一行的列数 */
46
- get offsetWidth() {
47
- return this.#getDimension().width;
48
- }
49
- /** @private */
50
- getChildNodes() {
51
- const { childNodes } = this;
52
- return Object.isFrozen(childNodes) ? [...childNodes] : childNodes;
53
- }
54
- /** @private */
55
- getAttribute(key) {
56
- return (key === 'padding' ? 0 : this[key]);
57
- }
58
- /** @private */
59
- setAttribute(key, value) {
60
- switch (key) {
61
- case 'parentNode':
62
- this.#parentNode = value;
63
- if (!value) {
64
- this.#nextSibling = undefined;
65
- this.#previousSibling = undefined;
66
- }
67
- break;
68
- case 'nextSibling':
69
- this.#nextSibling = value;
70
- break;
71
- case 'previousSibling':
72
- this.#previousSibling = value;
73
- break;
74
- case 'aIndex':
75
- this.#aIndex = [debug_1.Shadow.rev, value];
76
- break;
77
- default:
78
- this[key] = value; // eslint-disable-line @typescript-eslint/no-explicit-any
47
+ let AstNode = (() => {
48
+ let _instanceExtraInitializers = [];
49
+ let _getLines_decorators;
50
+ return class AstNode {
51
+ static {
52
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
53
+ _getLines_decorators = [(0, cached_1.cached)(false)];
54
+ __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 });
79
56
  }
80
- }
81
- /**
82
- * Get the root node
83
- *
84
- * 获取根节点
85
- */
86
- getRootNode() {
87
- return (0, lint_1.cache)(this.#root, () => this.parentNode?.getRootNode() ?? this, value => {
88
- const [, root] = value;
89
- if (root.type === 'root') {
90
- this.#root = value;
57
+ childNodes = (__runInitializers(this, _instanceExtraInitializers), []);
58
+ #parentNode;
59
+ #nextSibling;
60
+ #previousSibling;
61
+ #root;
62
+ #aIndex;
63
+ #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
+ /** parent node / 父节点 */
73
+ get parentNode() {
74
+ return this.#parentNode;
75
+ }
76
+ /** next sibling node / 后一个兄弟节点 */
77
+ get nextSibling() {
78
+ return this.#nextSibling;
79
+ }
80
+ /** previous sibling node / 前一个兄弟节点 */
81
+ get previousSibling() {
82
+ return this.#previousSibling;
83
+ }
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
+ /** @private */
93
+ getChildNodes() {
94
+ const { childNodes } = this;
95
+ return Object.isFrozen(childNodes) ? [...childNodes] : childNodes;
96
+ }
97
+ /** @private */
98
+ getAttribute(key) {
99
+ return (key === 'padding' ? 0 : this[key]);
100
+ }
101
+ /** @private */
102
+ setAttribute(key, value) {
103
+ switch (key) {
104
+ case 'parentNode':
105
+ this.#parentNode = value;
106
+ if (!value) {
107
+ this.#nextSibling = undefined;
108
+ this.#previousSibling = undefined;
109
+ }
110
+ break;
111
+ case 'nextSibling':
112
+ this.#nextSibling = value;
113
+ break;
114
+ case 'previousSibling':
115
+ this.#previousSibling = value;
116
+ break;
117
+ case 'aIndex':
118
+ this.#aIndex = [debug_1.Shadow.rev, value];
119
+ break;
120
+ default:
121
+ this[key] = value; // eslint-disable-line @typescript-eslint/no-explicit-any
91
122
  }
92
- });
93
- }
94
- /**
95
- * Convert the position to the character index
96
- *
97
- * 将行列号转换为字符位置
98
- * @param top line number / 行号
99
- * @param left column number / 列号
100
- */
101
- indexFromPos(top, left) {
102
- LSP: { // eslint-disable-line no-unused-labels
103
- if (top < 0 || left < 0) {
104
- return undefined;
123
+ }
124
+ /**
125
+ * Get the root node
126
+ *
127
+ * 获取根节点
128
+ */
129
+ getRootNode() {
130
+ return (0, lint_1.cache)(this.#root, () => this.parentNode?.getRootNode() ?? this, value => {
131
+ const [, root] = value;
132
+ if (root.type === 'root') {
133
+ this.#root = value;
134
+ }
135
+ });
136
+ }
137
+ /**
138
+ * Convert the position to the character index
139
+ *
140
+ * 将行列号转换为字符位置
141
+ * @param top line number / 行号
142
+ * @param left column number / 列号
143
+ */
144
+ indexFromPos(top, left) {
145
+ LSP: { // eslint-disable-line no-unused-labels
146
+ if (top < 0 || left < 0) {
147
+ return undefined;
148
+ }
149
+ const lines = this.getLines();
150
+ if (top >= lines.length) {
151
+ return undefined;
152
+ }
153
+ const [, start, end] = lines[top], index = start + left;
154
+ return index > end ? undefined : index;
105
155
  }
106
- const lines = this.getLines();
107
- if (top >= lines.length) {
108
- return undefined;
156
+ }
157
+ /**
158
+ * Convert the character indenx to the position
159
+ *
160
+ * 将字符位置转换为行列号
161
+ * @param index character index / 字符位置
162
+ */
163
+ posFromIndex(index) {
164
+ const { length } = String(this);
165
+ index += index < 0 ? length : 0;
166
+ if (index >= 0 && index <= length) {
167
+ const lines = this.getLines(), top = lines.findIndex(([, , end]) => index <= end);
168
+ return { top, left: index - lines[top][1] };
109
169
  }
110
- const [, start, end] = lines[top], index = start + left;
111
- return index > end ? undefined : index;
170
+ return undefined;
112
171
  }
113
- }
114
- /**
115
- * Convert the character indenx to the position
116
- *
117
- * 将字符位置转换为行列号
118
- * @param index character index / 字符位置
119
- */
120
- posFromIndex(index) {
121
- const { length } = String(this);
122
- index += index < 0 ? length : 0;
123
- if (index >= 0 && index <= length) {
124
- const lines = this.getLines(), top = lines.findIndex(([, , end]) => index <= end);
125
- return { top, left: index - lines[top][1] };
126
- }
127
- return undefined;
128
- }
129
- /** 获取行数和最后一行的列数 */
130
- #getDimension() {
131
- const lines = this.getLines(), last = lines[lines.length - 1];
132
- return { height: lines.length, width: last[2] - last[1] };
133
- }
134
- /** @private */
135
- getGaps(_) {
136
- return 0;
137
- }
138
- /**
139
- * Get the relative character index of the current node, or its `j`-th child node
140
- *
141
- * 获取当前节点的相对字符位置,或其第`j`个子节点的相对字符位置
142
- * @param j rank of the child node / 子节点序号
143
- */
144
- getRelativeIndex(j) {
145
- if (j === undefined) {
146
- const { parentNode } = this;
147
- return parentNode
148
- ? parentNode.getRelativeIndex(parentNode.childNodes.indexOf(this))
149
- : 0;
150
- }
151
- return (0, lint_1.cache)(this.#rIndex[j], () => {
152
- const { childNodes } = this, n = j + (j < 0 ? childNodes.length : 0);
153
- let acc = this.getAttribute('padding');
154
- for (let i = 0; i < n; i++) {
155
- this.#rIndex[i] = [debug_1.Shadow.rev, acc];
156
- acc += childNodes[i].toString().length + this.getGaps(i);
172
+ /** 获取行数和最后一行的列数 */
173
+ #getDimension() {
174
+ const lines = this.getLines(), last = lines[lines.length - 1];
175
+ return { height: lines.length, width: last[2] - last[1] };
176
+ }
177
+ /** @private */
178
+ getGaps(_) {
179
+ return 0;
180
+ }
181
+ /**
182
+ * Get the relative character index of the current node, or its `j`-th child node
183
+ *
184
+ * 获取当前节点的相对字符位置,或其第`j`个子节点的相对字符位置
185
+ * @param j rank of the child node / 子节点序号
186
+ */
187
+ getRelativeIndex(j) {
188
+ if (j === undefined) {
189
+ const { parentNode } = this;
190
+ return parentNode
191
+ ? parentNode.getRelativeIndex(parentNode.childNodes.indexOf(this))
192
+ : 0;
157
193
  }
158
- return acc;
159
- }, value => {
160
- this.#rIndex[j] = value;
161
- });
162
- }
163
- /**
164
- * Get the absolute character index of the current node
165
- *
166
- * 获取当前节点的绝对位置
167
- */
168
- getAbsoluteIndex() {
169
- return (0, lint_1.cache)(this.#aIndex, () => {
170
- const { parentNode } = this;
171
- return parentNode ? parentNode.getAbsoluteIndex() + this.getRelativeIndex() : 0;
172
- }, value => {
173
- this.#aIndex = value;
174
- });
175
- }
176
- /**
177
- * Get the position and dimension of the current node
178
- *
179
- * 获取当前节点的行列位置和大小
180
- */
181
- getBoundingClientRect() {
182
- // eslint-disable-next-line no-unused-labels
183
- LSP: return {
184
- ...this.#getDimension(),
185
- ...this.getRootNode().posFromIndex(this.getAbsoluteIndex()),
186
- };
187
- }
188
- /**
189
- * Whether to be of a certain type
190
- *
191
- * 是否是某种类型的节点
192
- * @param type token type / 节点类型
193
- * @since v1.10.0
194
- */
195
- is(type) {
196
- return this.type === type;
197
- }
198
- /**
199
- * Get the text and the start/end positions of all lines
200
- *
201
- * 获取所有行的wikitext和起止位置
202
- * @since v1.16.3
203
- */
204
- getLines() {
205
- return (0, lint_1.cache)(this.#lines, () => {
194
+ return (0, lint_1.cache)(this.#rIndex[j], () => {
195
+ const { childNodes } = this, n = j + (j < 0 ? childNodes.length : 0);
196
+ let acc = this.getAttribute('padding');
197
+ for (let i = 0; i < n; i++) {
198
+ this.#rIndex[i] = [debug_1.Shadow.rev, acc];
199
+ acc += childNodes[i].toString().length + this.getGaps(i);
200
+ }
201
+ return acc;
202
+ }, value => {
203
+ this.#rIndex[j] = value;
204
+ });
205
+ }
206
+ /**
207
+ * Get the absolute character index of the current node
208
+ *
209
+ * 获取当前节点的绝对位置
210
+ */
211
+ getAbsoluteIndex() {
212
+ return (0, lint_1.cache)(this.#aIndex, () => {
213
+ const { parentNode } = this;
214
+ return parentNode ? parentNode.getAbsoluteIndex() + this.getRelativeIndex() : 0;
215
+ }, value => {
216
+ this.#aIndex = value;
217
+ });
218
+ }
219
+ /**
220
+ * Get the position and dimension of the current node
221
+ *
222
+ * 获取当前节点的行列位置和大小
223
+ */
224
+ getBoundingClientRect() {
225
+ // eslint-disable-next-line no-unused-labels
226
+ LSP: return {
227
+ ...this.#getDimension(),
228
+ ...this.getRootNode().posFromIndex(this.getAbsoluteIndex()),
229
+ };
230
+ }
231
+ /**
232
+ * Whether to be of a certain type
233
+ *
234
+ * 是否是某种类型的节点
235
+ * @param type token type / 节点类型
236
+ * @since v1.10.0
237
+ */
238
+ is(type) {
239
+ return this.type === type;
240
+ }
241
+ /**
242
+ * Get the text and the start/end positions of all lines
243
+ *
244
+ * 获取所有行的wikitext和起止位置
245
+ * @since v1.16.3
246
+ */
247
+ getLines() {
206
248
  const results = [];
207
249
  let start = 0;
208
250
  for (const line of String(this).split('\n')) {
@@ -211,9 +253,7 @@ class AstNode {
211
253
  start = end + 1;
212
254
  }
213
255
  return results;
214
- }, value => {
215
- this.#lines = value;
216
- });
217
- }
218
- }
256
+ }
257
+ };
258
+ })();
219
259
  exports.AstNode = AstNode;