wikiparser-node 1.31.0 → 1.32.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 (90) hide show
  1. package/README.md +1 -0
  2. package/bundle/bundle-es8.min.js +29 -30
  3. package/bundle/bundle-lsp.min.js +29 -29
  4. package/bundle/bundle.min.js +23 -23
  5. package/dist/addon/attribute.js +166 -0
  6. package/dist/addon/link.js +92 -0
  7. package/dist/addon/table.js +12 -3
  8. package/dist/addon/token.js +5 -303
  9. package/dist/addon/transclude.js +9 -6
  10. package/dist/base.d.mts +9 -1
  11. package/dist/base.d.ts +9 -1
  12. package/dist/bin/config.js +1 -1
  13. package/dist/index.d.ts +24 -5
  14. package/dist/index.js +69 -89
  15. package/dist/internal.d.ts +4 -0
  16. package/dist/lib/document.d.ts +9 -7
  17. package/dist/lib/document.js +91 -66
  18. package/dist/lib/element.d.ts +7 -7
  19. package/dist/lib/element.js +48 -50
  20. package/dist/lib/lintConfig.js +1 -1
  21. package/dist/lib/lsp.js +120 -56
  22. package/dist/lib/node.js +20 -14
  23. package/dist/lib/text.js +2 -2
  24. package/dist/lib/title.d.ts +11 -0
  25. package/dist/lib/title.js +37 -13
  26. package/dist/mixin/elementLike.js +2 -3
  27. package/dist/mixin/syntax.js +13 -7
  28. package/dist/parser/commentAndExt.js +3 -3
  29. package/dist/parser/selector.js +16 -41
  30. package/dist/render/expand.js +216 -0
  31. package/dist/render/extension.js +141 -0
  32. package/dist/render/html.js +91 -0
  33. package/dist/{addon → render}/magicWords.js +35 -1
  34. package/dist/render/syntaxhighlight.js +415 -0
  35. package/dist/src/arg.js +1 -1
  36. package/dist/src/attribute.d.ts +5 -0
  37. package/dist/src/attribute.js +58 -103
  38. package/dist/src/attributes.d.ts +5 -0
  39. package/dist/src/attributes.js +15 -50
  40. package/dist/src/converter.js +4 -2
  41. package/dist/src/converterFlags.js +8 -6
  42. package/dist/src/converterRule.js +19 -15
  43. package/dist/src/extLink.js +1 -1
  44. package/dist/src/heading.d.ts +1 -1
  45. package/dist/src/heading.js +5 -3
  46. package/dist/src/imageParameter.d.ts +0 -1
  47. package/dist/src/imageParameter.js +33 -24
  48. package/dist/src/index.d.ts +5 -5
  49. package/dist/src/index.js +33 -21
  50. package/dist/src/link/base.js +16 -34
  51. package/dist/src/link/category.d.ts +7 -0
  52. package/dist/src/link/category.js +101 -37
  53. package/dist/src/link/file.js +19 -6
  54. package/dist/src/link/galleryImage.js +1 -2
  55. package/dist/src/link/index.d.ts +1 -1
  56. package/dist/src/link/index.js +10 -31
  57. package/dist/src/multiLine/index.js +1 -1
  58. package/dist/src/nowiki/comment.js +1 -1
  59. package/dist/src/nowiki/doubleUnderscore.js +4 -2
  60. package/dist/src/nowiki/index.js +34 -31
  61. package/dist/src/nowiki/listBase.d.ts +2 -1
  62. package/dist/src/nowiki/listBase.js +22 -8
  63. package/dist/src/nowiki/quote.d.ts +1 -1
  64. package/dist/src/nowiki/quote.js +1 -1
  65. package/dist/src/onlyinclude.js +1 -1
  66. package/dist/src/parameter.js +1 -1
  67. package/dist/src/redirect.js +1 -1
  68. package/dist/src/table/base.js +4 -2
  69. package/dist/src/table/index.d.ts +0 -5
  70. package/dist/src/table/index.js +6 -15
  71. package/dist/src/table/td.js +9 -5
  72. package/dist/src/tag/index.js +1 -1
  73. package/dist/src/tagPair/ext.js +14 -38
  74. package/dist/src/tagPair/index.js +6 -4
  75. package/dist/src/tagPair/translate.js +2 -2
  76. package/dist/src/transclude.d.ts +0 -6
  77. package/dist/src/transclude.js +16 -33
  78. package/dist/util/constants.js +5 -1
  79. package/dist/util/debug.js +72 -5
  80. package/dist/util/diff.js +17 -15
  81. package/dist/util/html.js +4 -3
  82. package/dist/util/selector.js +37 -0
  83. package/dist/util/sharable.d.mts +4 -1
  84. package/dist/util/sharable.js +7 -7
  85. package/dist/util/sharable.mjs +7 -7
  86. package/dist/util/string.js +31 -12
  87. package/extensions/dist/base.js +1 -1
  88. package/i18n/zh-hans.json +29 -29
  89. package/i18n/zh-hant.json +30 -30
  90. package/package.json +16 -13
@@ -38,12 +38,6 @@ export declare abstract class AstElement extends AstNode {
38
38
  /** all templates and modules / 所有模板和模块 */
39
39
  get embeds(): TranscludeToken[];
40
40
  constructor();
41
- /**
42
- * Merge adjacent text child nodes
43
- *
44
- * 合并相邻的文本子节点
45
- */
46
- normalize(): void;
47
41
  /**
48
42
  * Remove a child node
49
43
  *
@@ -113,13 +107,19 @@ export declare abstract class AstElement extends AstNode {
113
107
  * @param start
114
108
  */
115
109
  json(file?: string, start?: number): AST;
110
+ /**
111
+ * Merge adjacent text child nodes
112
+ *
113
+ * 合并相邻的文本子节点
114
+ */
115
+ normalize(): void;
116
116
  /**
117
117
  * Check if the current element matches the selector
118
118
  *
119
119
  * 检查是否符合选择器
120
120
  * @param selector selector / 选择器
121
121
  */
122
- matches<T>(selector?: string): this is T;
122
+ matches<T>(selector: string): this is T;
123
123
  /**
124
124
  * Insert a batch of child nodes at the start
125
125
  *
@@ -40,7 +40,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
40
40
  exports.AstElement = void 0;
41
41
  const string_1 = require("../util/string");
42
42
  const debug_1 = require("../util/debug");
43
- const selector_1 = require("../parser/selector");
43
+ const selector_1 = require("../util/selector");
44
44
  const node_1 = require("./node");
45
45
  const elementLike_1 = require("../mixin/elementLike");
46
46
  /* NOT FOR BROWSER */
@@ -130,45 +130,6 @@ let AstElement = (() => {
130
130
  text(separator) {
131
131
  return (0, string_1.text)(this.childNodes, separator);
132
132
  }
133
- /**
134
- * Merge adjacent text child nodes
135
- *
136
- * 合并相邻的文本子节点
137
- */
138
- normalize() {
139
- const childNodes = this.getChildNodes();
140
- /**
141
- * 移除子节点
142
- * @param i 移除位置
143
- */
144
- const remove = (i) => {
145
- /* NOT FOR BROWSER */
146
- childNodes[i].setAttribute('parentNode', undefined);
147
- /* NOT FOR BROWSER END */
148
- childNodes.splice(i, 1);
149
- childNodes[i - 1]?.setAttribute('nextSibling', childNodes[i]);
150
- childNodes[i]?.setAttribute('previousSibling', childNodes[i - 1]);
151
- };
152
- for (let i = childNodes.length - 1; i >= 0; i--) {
153
- const { type, data } = childNodes[i];
154
- if (type !== 'text' || childNodes.length === 1 || this.getGaps(i - (i && 1))) {
155
- //
156
- }
157
- else if (data === '') {
158
- remove(i);
159
- /* NOT FOR BROWSER */
160
- }
161
- else {
162
- const prev = childNodes[i - 1];
163
- if (prev?.type === 'text') {
164
- prev.setAttribute('data', prev.data + data);
165
- remove(i);
166
- }
167
- /* NOT FOR BROWSER END */
168
- }
169
- }
170
- this.setAttribute('childNodes', childNodes);
171
- }
172
133
  /**
173
134
  * Remove a child node
174
135
  *
@@ -246,7 +207,7 @@ let AstElement = (() => {
246
207
  for (let i = this.length - 1; i >= 0; i--) {
247
208
  this.removeAt(i);
248
209
  }
249
- this.safeAppend(elements);
210
+ this.safeAppend([...elements]);
250
211
  }
251
212
  }
252
213
  /**
@@ -359,15 +320,17 @@ let AstElement = (() => {
359
320
  }
360
321
  /** @private */
361
322
  print(opt = {}) {
362
- const cl = opt.class;
363
- if (this.toString()) {
364
- return (cl === ''
365
- ? ''
366
- : `<span class="wpb-${cl ?? this.type}${this.getAttribute('invalid') ? ' wpb-invalid' : ''}">`)
367
- + (0, string_1.print)(this.childNodes, opt)
368
- + (cl === '' ? '' : '</span>');
323
+ PRINT: {
324
+ const cl = opt.class;
325
+ if (this.toString()) {
326
+ return (cl === ''
327
+ ? ''
328
+ : `<span class="wpb-${cl ?? this.type}${this.getAttribute('invalid') ? ' wpb-invalid' : ''}">`)
329
+ + (0, string_1.print)(this.childNodes, opt)
330
+ + (cl === '' ? '' : '</span>');
331
+ }
332
+ return '';
369
333
  }
370
- return '';
371
334
  }
372
335
  /**
373
336
  * Save in JSON format
@@ -402,6 +365,41 @@ let AstElement = (() => {
402
365
  }
403
366
  }
404
367
  /* NOT FOR BROWSER */
368
+ /**
369
+ * Merge adjacent text child nodes
370
+ *
371
+ * 合并相邻的文本子节点
372
+ */
373
+ normalize() {
374
+ const childNodes = this.getChildNodes();
375
+ /**
376
+ * 移除子节点
377
+ * @param i 移除位置
378
+ */
379
+ const remove = (i) => {
380
+ childNodes[i].setAttribute('parentNode', undefined);
381
+ childNodes.splice(i, 1);
382
+ childNodes[i - 1]?.setAttribute('nextSibling', childNodes[i]);
383
+ childNodes[i]?.setAttribute('previousSibling', childNodes[i - 1]);
384
+ };
385
+ for (let i = childNodes.length - 1; i >= 0; i--) {
386
+ const { type, data } = childNodes[i];
387
+ if (type !== 'text' || childNodes.length === 1 || this.getGaps(i - (i && 1))) {
388
+ //
389
+ }
390
+ else if (data === '') {
391
+ remove(i);
392
+ }
393
+ else {
394
+ const prev = childNodes[i - 1];
395
+ if (prev?.type === 'text') {
396
+ prev.setAttribute('data', prev.data + data);
397
+ remove(i);
398
+ }
399
+ }
400
+ }
401
+ this.setAttribute('childNodes', childNodes);
402
+ }
405
403
  /**
406
404
  * Check if the current element matches the selector
407
405
  *
@@ -409,7 +407,7 @@ let AstElement = (() => {
409
407
  * @param selector selector / 选择器
410
408
  */
411
409
  matches(selector) {
412
- return selector === undefined || (0, selector_1.getCondition)(selector, this)(this);
410
+ return (0, selector_1.getCondition)(selector, this)(this);
413
411
  }
414
412
  /**
415
413
  * Insert a batch of child nodes at the start
@@ -306,9 +306,9 @@ class LintConfiguration {
306
306
  set rules(config) {
307
307
  this.#rules = new Proxy(new LintRuleConfiguration(config), {
308
308
  set,
309
+ /* istanbul ignore next */
309
310
  /** @ignore */
310
311
  deleteProperty() {
311
- /* istanbul ignore next */
312
312
  return false;
313
313
  },
314
314
  });
package/dist/lib/lsp.js CHANGED
@@ -10,7 +10,10 @@ const base_1 = require("../base");
10
10
  const sharable_1 = require("../util/sharable");
11
11
  const lint_1 = require("../util/lint");
12
12
  const string_1 = require("../util/string");
13
+ const debug_1 = require("../util/debug");
14
+ const constants_1 = require("../util/constants");
13
15
  const index_1 = __importDefault(require("../index"));
16
+ const index_2 = require("../src/index");
14
17
  /* NOT FOR BROWSER ONLY */
15
18
  const fs_1 = __importDefault(require("fs"));
16
19
  const path_1 = __importDefault(require("path"));
@@ -19,7 +22,6 @@ const child_process_1 = require("child_process");
19
22
  const crypto_1 = require("crypto");
20
23
  const stylelint_util_1 = require("@bhsd/stylelint-util");
21
24
  const search_1 = __importDefault(require("../util/search"));
22
- const constants_1 = require("../util/constants");
23
25
  const document_1 = require("./document");
24
26
  exports.tasks = new WeakMap();
25
27
  const refTags = new Set(['ref']), referencesTags = new Set(['ref', 'references']), nameAttrs = new Set(['name', 'follow']), groupAttrs = new Set(['group']), renameTypes = new Set([
@@ -51,7 +53,7 @@ const getLinkRegex = (0, common_1.getRegex)(protocol => new RegExp(`^(?:${protoc
51
53
  const isAttr = ({ type, parentNode, length, firstChild }, style) => type === 'attr-value' && length === 1 && firstChild.type === 'text'
52
54
  && (!style
53
55
  || parentNode.name === 'style'
54
- && Boolean(document_1.cssLSP));
56
+ && Boolean((0, document_1.loadCssLSP)()));
55
57
  /**
56
58
  * Check if a token is an HTML attribute.
57
59
  * @param token
@@ -227,6 +229,60 @@ const getFixAll = (root, rule) => {
227
229
  },
228
230
  ];
229
231
  };
232
+ /**
233
+ * Partially parse wikitext.
234
+ * @param wikitext
235
+ * @param watch function to watch for changes
236
+ * @param include
237
+ * @param config
238
+ */
239
+ const partialParse = async (wikitext, watch, include, config = index_1.default.getConfig()) => {
240
+ const set = typeof setImmediate === 'function' ? setImmediate : /* istanbul ignore next */ setTimeout, { running } = debug_1.Shadow;
241
+ debug_1.Shadow.running = true;
242
+ /* PRINT ONLY */
243
+ const { internal } = index_1.default;
244
+ index_1.default.internal = true;
245
+ /* PRINT ONLY END */
246
+ /** restore state before exit */
247
+ const finish = () => {
248
+ debug_1.Shadow.running = running;
249
+ /* PRINT ONLY */
250
+ index_1.default.internal = internal;
251
+ };
252
+ const token = new index_2.Token((0, string_1.tidy)(wikitext), config);
253
+ token.type = 'root';
254
+ let i = 0;
255
+ try {
256
+ await new Promise(resolve => {
257
+ const /** @ignore */ check = () => {
258
+ if (watch() === wikitext) {
259
+ i++;
260
+ set(parseOnce, 0);
261
+ }
262
+ else {
263
+ resolve();
264
+ }
265
+ },
266
+ /** @ignore */ parseOnce = () => {
267
+ if (i === constants_1.MAX_STAGE + 1) {
268
+ token.afterBuild();
269
+ resolve();
270
+ }
271
+ else {
272
+ token[i === constants_1.MAX_STAGE ? 'build' : 'parseOnce'](i, include);
273
+ check();
274
+ }
275
+ };
276
+ set(parseOnce, 0);
277
+ });
278
+ }
279
+ catch (e) /* istanbul ignore next */ {
280
+ finish();
281
+ throw e;
282
+ }
283
+ finish();
284
+ return token;
285
+ };
230
286
  /* NOT FOR BROWSER ONLY */
231
287
  /** @see https://www.npmjs.com/package/stylelint-config-recommended */
232
288
  const cssRules = { 'block-no-empty': null }, sources = { 'invalid-css': 'css', 'invalid-math': 'texvc' }, jsonSelector = document_1.jsonTags.map(s => `ext#${s}`).join(), scores = new Map();
@@ -381,7 +437,7 @@ class LanguageService {
381
437
  this.config ??= index_1.default.getConfig();
382
438
  this.#config = this.config;
383
439
  this.#include = this.include;
384
- const text = this.#text, root = await index_1.default.partialParse(text, () => this.#text, this.include, this.config);
440
+ const text = this.#text, root = await partialParse(text, () => this.#text, this.include, this.config);
385
441
  if (this.#checkConfig() && this.#text === text) {
386
442
  this.#done = root;
387
443
  this.#running = undefined;
@@ -419,7 +475,7 @@ class LanguageService {
419
475
  this.config ??= index_1.default.getConfig();
420
476
  this.#config = this.config;
421
477
  this.#include = this.include;
422
- const text = this.#text2, root = await index_1.default.partialParse(text, () => this.#text2, this.include, this.config);
478
+ const text = this.#text2, root = await partialParse(text, () => this.#text2, this.include, this.config);
423
479
  if (this.#checkConfig() && this.#text2 === text) {
424
480
  this.#done2 = root;
425
481
  this.#running2 = undefined;
@@ -461,7 +517,7 @@ class LanguageService {
461
517
  }
462
518
  else if (isAttr(token, true)) {
463
519
  const textDoc = new document_1.EmbeddedCSSDocument(root, token);
464
- return document_1.cssLSP.findDocumentColors(textDoc, textDoc.styleSheet);
520
+ return (0, document_1.loadCssLSP)().findDocumentColors(textDoc, textDoc.styleSheet);
465
521
  /* NOT FOR BROWSER ONLY END */
466
522
  }
467
523
  /* NOT FOR BROWSER ONLY */
@@ -489,7 +545,7 @@ class LanguageService {
489
545
  },
490
546
  range: createRange(root, start + from, start + to),
491
547
  };
492
- }).filter(Boolean);
548
+ }).filter(info => info !== false);
493
549
  });
494
550
  });
495
551
  }
@@ -539,11 +595,7 @@ class LanguageService {
539
595
  ext,
540
596
  tags,
541
597
  allTags: [...tags, 'onlyinclude', 'includeonly', 'noinclude'],
542
- functions: [
543
- Object.keys(insensitive),
544
- Array.isArray(sensitive) ? /* istanbul ignore next */ sensitive : Object.keys(sensitive),
545
- other,
546
- ].flat(2),
598
+ functions: [Object.keys(insensitive), Object.keys(sensitive), other].flat(2),
547
599
  switches: allSwitches.filter(cm_util_1.isUnderscore).map(w => `__${w}__`),
548
600
  jaSwitches: allSwitches.filter(w => !(0, cm_util_1.isUnderscore)(w)),
549
601
  protocols: protocol.split('|'),
@@ -599,7 +651,7 @@ class LanguageService {
599
651
  return getCompletion(root.querySelectorAll('arg').filter(token => token.name && token !== cur)
600
652
  .map(({ name }) => name), 'Variable', match, position);
601
653
  }
602
- const [insensitive, sensitive] = this.config.parserFunction, isOld = Array.isArray(sensitive), next = curLine.charAt(character), colon = match.startsWith(':'), str = colon ? match.slice(1).trimStart() : match;
654
+ const [insensitive, sensitive] = this.config.parserFunction, next = curLine.charAt(character), colon = match.startsWith(':'), str = colon ? match.slice(1).trimStart() : match;
603
655
  if (mt[2] === '[[') { // link
604
656
  return getCompletion(root.querySelectorAll('link,file,category,redirect-target').filter(token => token !== cur).map(({ name }) => name), 'Folder', str, position);
605
657
  }
@@ -619,7 +671,7 @@ class LanguageService {
619
671
  else if (name in insensitive) {
620
672
  name = insensitive[name];
621
673
  }
622
- else if (!isOld && name in sensitive) {
674
+ else if (name in sensitive) {
623
675
  name = sensitive[name];
624
676
  }
625
677
  return this.#getParserFunction(name.toLowerCase());
@@ -702,7 +754,8 @@ class LanguageService {
702
754
  }
703
755
  else if (isAttr(cur, true)) {
704
756
  const textDoc = new document_1.EmbeddedCSSDocument(root, cur);
705
- return document_1.cssLSP.doComplete(textDoc, position, textDoc.styleSheet).items.map((item) => ({
757
+ return (0, document_1.loadCssLSP)().doComplete(textDoc, position, textDoc.styleSheet).items
758
+ .map((item) => ({
706
759
  ...item,
707
760
  textEdit: {
708
761
  range: item.textEdit.range,
@@ -710,9 +763,13 @@ class LanguageService {
710
763
  },
711
764
  }));
712
765
  }
713
- else if (document_1.jsonLSP && type === 'ext-inner' && document_1.jsonTags.includes(cur.name)) {
766
+ else if (type === 'ext-inner' && document_1.jsonTags.includes(cur.name)) {
767
+ const jsonLSP = (0, document_1.loadJsonLSP)();
768
+ if (!jsonLSP) {
769
+ return undefined;
770
+ }
714
771
  const textDoc = new document_1.EmbeddedJSONDocument(root, cur);
715
- return (await document_1.jsonLSP.doComplete(textDoc, position, textDoc.jsonDoc))?.items;
772
+ return (await jsonLSP.doComplete(textDoc, position, textDoc.jsonDoc))?.items;
716
773
  }
717
774
  else if (type === 'ext-inner' && cur.name === 'score') {
718
775
  const lang = parentNode.getAttr('lang');
@@ -788,15 +845,18 @@ class LanguageService {
788
845
  ...suggestions ? suggestions.map(suggestion => getQuickFix(root, suggestion)) : [],
789
846
  ],
790
847
  })),
848
+ /* NOT FOR BROWSER ONLY */
849
+ stylelint = await (0, document_1.loadStylelint)(), jsonLSP = (0, document_1.loadJsonLSP)(),
850
+ /* NOT FOR BROWSER ONLY END */
791
851
  /* eslint-disable @stylistic/operator-linebreak */
792
- cssDiagnostics = await document_1.stylelint ?
852
+ cssDiagnostics = stylelint ?
793
853
  await (async () => {
794
854
  NPM: {
795
855
  const tokens = this.findStyleTokens();
796
856
  if (tokens.length === 0) {
797
857
  return [];
798
858
  }
799
- const code = tokens.map(({ type, tag, lastChild }, i) => `${type === 'ext-attr' ? 'div' : tag}#${i}{\n${(0, common_1.sanitizeInlineStyle)(lastChild.toString())}\n}`).join('\n'), cssErrors = await (0, stylelint_util_1.styleLint)((await document_1.stylelint), code, cssRules);
859
+ const code = tokens.map(({ type, tag, lastChild }, i) => `${type === 'ext-attr' ? 'div' : tag}#${i}{\n${(0, common_1.sanitizeInlineStyle)(lastChild.toString())}\n}`).join('\n'), cssErrors = await (0, stylelint_util_1.styleLint)(stylelint, code, cssRules);
800
860
  if (cssErrors.length === 0) {
801
861
  return [];
802
862
  }
@@ -833,12 +893,12 @@ class LanguageService {
833
893
  });
834
894
  }
835
895
  })() :
836
- [], jsonDiagnostics = document_1.jsonLSP ?
896
+ [], jsonDiagnostics = jsonLSP ?
837
897
  await Promise.all(root.querySelectorAll(jsonSelector).map(async ({ name, lastChild, selfClosing }) => {
838
898
  if (selfClosing) {
839
899
  return [];
840
900
  }
841
- const textDoc = new document_1.EmbeddedJSONDocument(root, lastChild), severityLevel = name === 'templatedata' ? 'error' : 'ignore', e = (await document_1.jsonLSP.doValidation(textDoc, textDoc.jsonDoc, {
901
+ const textDoc = new document_1.EmbeddedJSONDocument(root, lastChild), severityLevel = name === 'templatedata' ? 'error' : 'ignore', e = (await jsonLSP.doValidation(textDoc, textDoc.jsonDoc, {
842
902
  comments: severityLevel,
843
903
  trailingCommas: severityLevel,
844
904
  })).map((error) => ({
@@ -972,10 +1032,11 @@ class LanguageService {
972
1032
  }
973
1033
  }
974
1034
  /* NOT FOR BROWSER ONLY */
975
- if (document_1.jsonLSP) {
1035
+ const jsonLSP = (0, document_1.loadJsonLSP)();
1036
+ if (jsonLSP) {
976
1037
  for (const { selfClosing, lastChild } of root.querySelectorAll(jsonSelector)) {
977
1038
  if (!selfClosing) {
978
- const foldingRanges = document_1.jsonLSP.getFoldingRanges(new document_1.EmbeddedJSONDocument(root, lastChild));
1039
+ const foldingRanges = jsonLSP.getFoldingRanges(new document_1.EmbeddedJSONDocument(root, lastChild));
979
1040
  if (foldingRanges.length > 0) {
980
1041
  Array.prototype.push.apply(ranges, foldingRanges);
981
1042
  }
@@ -1085,7 +1146,7 @@ class LanguageService {
1085
1146
  return false;
1086
1147
  }
1087
1148
  })
1088
- .filter(Boolean);
1149
+ .filter(link => link !== false);
1089
1150
  }
1090
1151
  /**
1091
1152
  * Provide references
@@ -1241,41 +1302,43 @@ class LanguageService {
1241
1302
  }
1242
1303
  else if (isAttr(offsetNode, true)) {
1243
1304
  const textDoc = new document_1.EmbeddedCSSDocument(root, offsetNode);
1244
- return document_1.cssLSP.doHover(textDoc, position, textDoc.styleSheet) ?? undefined;
1305
+ return (0, document_1.loadCssLSP)().doHover(textDoc, position, textDoc.styleSheet) ?? undefined;
1245
1306
  }
1246
- else if (document_1.jsonLSP && type === 'ext-inner' && document_1.jsonTags.includes(name)) {
1307
+ else if (type === 'ext-inner' && document_1.jsonTags.includes(name)) {
1308
+ const jsonLSP = (0, document_1.loadJsonLSP)();
1309
+ if (!jsonLSP) {
1310
+ return undefined;
1311
+ }
1247
1312
  const textDoc = new document_1.EmbeddedJSONDocument(root, offsetNode);
1248
- return await document_1.jsonLSP.doHover(textDoc, position, textDoc.jsonDoc) ?? undefined;
1313
+ return await jsonLSP.doHover(textDoc, position, textDoc.jsonDoc) ?? undefined;
1249
1314
  }
1250
- else if (document_1.htmlData) {
1251
- if (type === 'html' && offset <= offsetNode.getRelativeIndex(0)
1252
- || type === 'html-attr-dirty' && offset === 0 && parentNode.firstChild === offsetNode) {
1253
- const token = type === 'html' ? offsetNode : parentNode.parentNode, data = document_1.htmlData.provideTags().find(({ name: n }) => n === token.name);
1254
- if (data?.description) {
1255
- const start = positionAt(root, token.getAbsoluteIndex());
1256
- return {
1257
- contents: data.description,
1258
- range: {
1259
- start,
1260
- end: {
1261
- line: start.line,
1262
- character: start.character + token.getRelativeIndex(0),
1263
- },
1315
+ else if (type === 'html' && offset <= offsetNode.getRelativeIndex(0)
1316
+ || type === 'html-attr-dirty' && offset === 0 && parentNode.firstChild === offsetNode) {
1317
+ const token = type === 'html' ? offsetNode : parentNode.parentNode, data = (0, document_1.loadHtmlData)()?.provideTags().find(({ name: n }) => n === token.name);
1318
+ if (data?.description) {
1319
+ const start = positionAt(root, token.getAbsoluteIndex());
1320
+ return {
1321
+ contents: data.description,
1322
+ range: {
1323
+ start,
1324
+ end: {
1325
+ line: start.line,
1326
+ character: start.character + token.getRelativeIndex(0),
1264
1327
  },
1265
- };
1266
- }
1328
+ },
1329
+ };
1267
1330
  }
1268
- else if (type === 'attr-key' && isHtmlAttr(parentNode)) {
1269
- const data = document_1.htmlData.provideAttributes(parentNode.tag).find(({ name: n }) => n === parentNode.name);
1270
- if (data?.description) {
1271
- return {
1272
- contents: data.description,
1273
- range: createNodeRange(offsetNode),
1274
- };
1275
- }
1331
+ }
1332
+ else if (type === 'attr-key' && isHtmlAttr(parentNode)) {
1333
+ const data = (0, document_1.loadHtmlData)()?.provideAttributes(parentNode.tag).find(({ name: n }) => n === parentNode.name);
1334
+ if (data?.description) {
1335
+ return {
1336
+ contents: data.description,
1337
+ range: createNodeRange(offsetNode),
1338
+ };
1276
1339
  }
1277
- /* NOT FOR BROWSER ONLY END */
1278
1340
  }
1341
+ /* NOT FOR BROWSER ONLY END */
1279
1342
  return info && {
1280
1343
  contents: {
1281
1344
  kind: 'markdown',
@@ -1395,10 +1458,11 @@ class LanguageService {
1395
1458
  else {
1396
1459
  return [];
1397
1460
  }
1398
- const root = await this.#queueSignature(selected);
1399
- const { viewOnly } = index_1.default;
1461
+ const root = await this.#queueSignature(selected), { viewOnly } = index_1.default;
1400
1462
  index_1.default.viewOnly = false;
1401
- root.escape();
1463
+ debug_1.Shadow.internal(() => {
1464
+ root.escape();
1465
+ }, index_1.default);
1402
1466
  index_1.default.viewOnly = viewOnly;
1403
1467
  return [
1404
1468
  {
@@ -1466,9 +1530,9 @@ class LanguageService {
1466
1530
  sections[i] = undefined;
1467
1531
  }
1468
1532
  const section = token.text().trim() || ' ', name = names.has(section)
1469
- ? new Array(names.size).fill('').map((_, i) => `${section.trim()}_${i + 2}`)
1533
+ ? Array.from({ length: names.size }, (_, i) => `${section.trim()}_${i + 2}`)
1470
1534
  .find(s => !names.has(s))
1471
- : section, container = sections.slice(0, level - 1).reverse().find(Boolean), selectionRange = {
1535
+ : section, container = sections.slice(0, level - 1).reverse().find(symbol => symbol !== undefined), selectionRange = {
1472
1536
  start: { line: top, character: left - level },
1473
1537
  end: (0, lint_1.getEndPos)(top, left, height, width + level),
1474
1538
  }, info = {
package/dist/lib/node.js CHANGED
@@ -190,7 +190,7 @@ let AstNode = (() => {
190
190
  return this.font.italic;
191
191
  }
192
192
  constructor() {
193
- if (!index_1.default.viewOnly) {
193
+ if (!index_1.default.viewOnly && !index_1.default.internal) {
194
194
  Object.defineProperty(this, 'childNodes', { writable: false });
195
195
  Object.freeze(this.childNodes);
196
196
  }
@@ -203,7 +203,7 @@ let AstNode = (() => {
203
203
  }
204
204
  /** @private */
205
205
  getAttribute(key) {
206
- return (key === 'padding' ? 0 : this[key]);
206
+ return (key === 'padding' ? 0 : /* istanbul ignore next */ this[key]);
207
207
  }
208
208
  /** @private */
209
209
  setAttribute(key, value) {
@@ -395,19 +395,25 @@ let AstNode = (() => {
395
395
  /* PRINT ONLY */
396
396
  /** @private */
397
397
  seal(key, permanent) {
398
- /* NOT FOR BROWSER */
399
- if (!permanent) {
400
- this.#optional.add(key);
401
- }
402
- /* NOT FOR BROWSER END */
403
- const enumerable = !permanent && Boolean(this[key]);
404
- if (!enumerable || !index_1.default.viewOnly) {
405
- Object.defineProperty(this, key, {
406
- enumerable,
407
- configurable: true,
398
+ LSP: {
399
+ if (index_1.default.internal) {
400
+ return;
408
401
  /* NOT FOR BROWSER */
409
- writable: index_1.default.viewOnly,
410
- });
402
+ }
403
+ else if (!permanent) {
404
+ this.#optional.add(key);
405
+ /* NOT FOR BROWSER END */
406
+ }
407
+ const enumerable = !permanent && Boolean(this[key]);
408
+ if (!enumerable
409
+ || !index_1.default.viewOnly) {
410
+ Object.defineProperty(this, key, {
411
+ enumerable,
412
+ configurable: true,
413
+ /* NOT FOR BROWSER */
414
+ writable: index_1.default.viewOnly,
415
+ });
416
+ }
411
417
  }
412
418
  }
413
419
  /* PRINT ONLY END */
package/dist/lib/text.js CHANGED
@@ -172,7 +172,7 @@ let AstText = (() => {
172
172
  /** @param text 包含文本 */
173
173
  constructor(text) {
174
174
  super();
175
- if (index_1.default.viewOnly) {
175
+ if (index_1.default.viewOnly || index_1.default.internal) {
176
176
  this.data = text;
177
177
  /* NOT FOR BROWSER */
178
178
  }
@@ -489,7 +489,7 @@ let AstText = (() => {
489
489
  }
490
490
  /** @private */
491
491
  print() {
492
- return (0, string_1.escape)(this.data);
492
+ PRINT: return (0, string_1.escape)(this.data);
493
493
  }
494
494
  /* NOT FOR BROWSER */
495
495
  /**
@@ -72,6 +72,17 @@ export declare class Title {
72
72
  * @since v1.10.0
73
73
  */
74
74
  getUrl(articlePath?: string): string;
75
+ /**
76
+ * Get the URL of the file
77
+ *
78
+ * 生成文件URL
79
+ * @param width width / 宽度
80
+ * @param height height / 高度
81
+ * @since v1.32.0
82
+ * @throws `RangeError` invalid width or height
83
+ * @throws `Error` not a file
84
+ */
85
+ getFileUrl(width?: number | false, height?: number | false): string;
75
86
  /**
76
87
  * Perform unidirectional language conversion
77
88
  *