wikiparser-node 1.17.0 → 1.18.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 (93) hide show
  1. package/README.md +20 -0
  2. package/bin/config.js +3 -0
  3. package/bundle/{bundle.es7.js → bundle-es7.min.js} +19 -19
  4. package/bundle/bundle-lsp.min.js +38 -0
  5. package/bundle/bundle.min.js +19 -19
  6. package/config/.schema.json +7 -3
  7. package/config/default.json +86 -23
  8. package/config/enwiki.json +20 -13
  9. package/config/llwiki.json +99 -7
  10. package/config/minimum.json +6 -3
  11. package/config/moegirl.json +12 -12
  12. package/config/zhwiki.json +52 -21
  13. package/data/.schema.json +7 -0
  14. package/data/ext/mapframe.json +4 -0
  15. package/data/ext/maplink.json +4 -0
  16. package/data/ext/score.json +1033 -0
  17. package/data/ext/templatedata.json +184 -0
  18. package/dist/addon/table.js +16 -10
  19. package/dist/addon/token.js +13 -9
  20. package/dist/addon/transclude.js +6 -3
  21. package/dist/base.d.mts +4 -2
  22. package/dist/base.d.ts +4 -2
  23. package/dist/base.js +2 -0
  24. package/dist/base.mjs +3 -1
  25. package/dist/bin/config.js +112 -0
  26. package/dist/index.d.ts +2 -2
  27. package/dist/index.js +33 -21
  28. package/dist/lib/document.d.ts +54 -0
  29. package/dist/lib/document.js +126 -0
  30. package/dist/lib/element.js +6 -3
  31. package/dist/lib/lsp.d.ts +7 -7
  32. package/dist/lib/lsp.js +314 -47
  33. package/dist/lib/node.js +19 -9
  34. package/dist/lib/text.js +4 -1
  35. package/dist/lib/title.js +9 -6
  36. package/dist/mixin/attributesParent.d.ts +8 -0
  37. package/dist/mixin/attributesParent.js +4 -0
  38. package/dist/parser/links.js +4 -1
  39. package/dist/parser/redirect.js +4 -1
  40. package/dist/src/arg.js +10 -3
  41. package/dist/src/attribute.d.ts +12 -1
  42. package/dist/src/attribute.js +69 -1
  43. package/dist/src/attributes.d.ts +8 -0
  44. package/dist/src/attributes.js +14 -1
  45. package/dist/src/converter.d.ts +62 -3
  46. package/dist/src/converter.js +162 -129
  47. package/dist/src/converterFlags.js +2 -2
  48. package/dist/src/converterRule.js +4 -1
  49. package/dist/src/extLink.d.ts +19 -3
  50. package/dist/src/extLink.js +177 -194
  51. package/dist/src/gallery.js +7 -3
  52. package/dist/src/heading.js +9 -4
  53. package/dist/src/html.js +4 -1
  54. package/dist/src/imageParameter.js +9 -3
  55. package/dist/src/imagemap.js +4 -1
  56. package/dist/src/index.js +34 -4
  57. package/dist/src/link/base.js +8 -2
  58. package/dist/src/link/file.js +11 -2
  59. package/dist/src/link/galleryImage.d.ts +1 -0
  60. package/dist/src/link/galleryImage.js +15 -1
  61. package/dist/src/magicLink.js +4 -1
  62. package/dist/src/nested.js +4 -1
  63. package/dist/src/nowiki/comment.js +4 -1
  64. package/dist/src/nowiki/index.js +4 -1
  65. package/dist/src/nowiki/quote.js +4 -1
  66. package/dist/src/onlyinclude.js +4 -1
  67. package/dist/src/paramTag/index.js +5 -1
  68. package/dist/src/paramTag/inputbox.js +4 -1
  69. package/dist/src/parameter.js +4 -1
  70. package/dist/src/pre.js +4 -1
  71. package/dist/src/redirect.js +3 -1
  72. package/dist/src/table/base.js +4 -1
  73. package/dist/src/table/index.js +10 -3
  74. package/dist/src/table/td.js +4 -1
  75. package/dist/src/tagPair/ext.js +17 -5
  76. package/dist/src/tagPair/include.js +4 -1
  77. package/dist/src/tagPair/index.js +4 -1
  78. package/dist/src/transclude.js +16 -7
  79. package/dist/util/debug.js +1 -13
  80. package/dist/util/diff.js +20 -6
  81. package/dist/util/lint.js +4 -1
  82. package/dist/util/string.js +5 -2
  83. package/extensions/dist/base.js +30 -18
  84. package/extensions/dist/lsp.js +30 -22
  85. package/extensions/es7/base.js +30 -18
  86. package/extensions/typings.d.ts +6 -2
  87. package/package.json +27 -16
  88. package/bundle/bundle.lsp.js +0 -38
  89. package/dist/mixin/flagsParent.d.ts +0 -69
  90. package/dist/mixin/flagsParent.js +0 -64
  91. package/dist/mixin/magicLinkParent.d.ts +0 -25
  92. package/dist/mixin/magicLinkParent.js +0 -43
  93. package/dist/util/sharable.d.ts +0 -1
@@ -1,10 +1,13 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.FileToken = void 0;
4
7
  const string_1 = require("../../util/string");
5
8
  const lint_1 = require("../../util/lint");
6
9
  const rect_1 = require("../../lib/rect");
7
- const index_1 = require("../../index");
10
+ const index_1 = __importDefault(require("../../index"));
8
11
  const base_1 = require("./base");
9
12
  const imageParameter_1 = require("../imageParameter");
10
13
  /* NOT FOR BROWSER */
@@ -380,7 +383,13 @@ class FileToken extends base_1.LinkBaseToken {
380
383
  toHtmlInternal(opt) {
381
384
  /** @ignore */
382
385
  const isInteger = (n) => Boolean(n && !/\D/u.test(n));
383
- const { link, width, height, type } = this, file = this.getAttribute('title'), fr = this.getFrame(), manual = fr instanceof title_1.Title, visibleCaption = manual || fr === 'thumbnail' || fr === 'framed' || type === 'gallery-image', caption = this.getArg('caption')?.toHtmlInternal({ ...opt, nowrap: true }) ?? '', titleFromCaption = visibleCaption && type !== 'gallery-image' ? '' : (0, string_1.sanitizeAlt)(caption), hasLink = manual || link !== file, title = titleFromCaption || (hasLink && typeof link !== 'string' ? link.getTitleAttr() : ''), titleAttr = title && ` title="${title}"`, alt = (0, string_1.sanitizeAlt)(this.getArg('alt')?.toHtmlInternal({ ...opt, nowrap: true })) ?? titleFromCaption, horiz = this.getHorizAlign() ?? '', vert = this.getVertAlign() ?? '', className = `${horiz ? `mw-halign-${horiz}` : vert && `mw-valign-${vert}`}${this.getValue('border') ? ' mw-image-border' : ''} ${(0, string_1.sanitizeAlt)(this.getValue('class')) ?? ''}`.trim(), classAttr = className && ` class="${className}"`, img = `<img${alt && ` alt="${alt}"`} src="${(manual ? fr : file).getUrl()}" class="mw-file-element"${isInteger(width) ? ` width="${width}"` : ''}${isInteger(height) ? ` height="${height}"` : ''}>`;
386
+ const { link, width, height, type } = this, file = this.getAttribute('title'), fr = this.getFrame(), manual = fr instanceof title_1.Title, visibleCaption = manual || fr === 'thumbnail' || fr === 'framed' || type === 'gallery-image', caption = this.getArg('caption')?.toHtmlInternal({
387
+ ...opt,
388
+ nowrap: true,
389
+ }) ?? '', titleFromCaption = visibleCaption && type !== 'gallery-image' ? '' : (0, string_1.sanitizeAlt)(caption), hasLink = manual || link !== file, title = titleFromCaption || (hasLink && typeof link !== 'string' ? link.getTitleAttr() : ''), titleAttr = title && ` title="${title}"`, alt = (0, string_1.sanitizeAlt)(this.getArg('alt')?.toHtmlInternal({
390
+ ...opt,
391
+ nowrap: true,
392
+ })) ?? titleFromCaption, horiz = this.getHorizAlign() ?? '', vert = this.getVertAlign() ?? '', className = `${horiz ? `mw-halign-${horiz}` : vert && `mw-valign-${vert}`}${this.getValue('border') ? ' mw-image-border' : ''} ${(0, string_1.sanitizeAlt)(this.getValue('class')) ?? ''}`.trim(), classAttr = className && ` class="${className}"`, img = `<img${alt && ` alt="${alt}"`} src="${(manual ? fr : file).getUrl()}" class="mw-file-element"${isInteger(width) ? ` width="${width}"` : ''}${isInteger(height) ? ` height="${height}"` : ''}>`;
384
393
  let href = '';
385
394
  if (link) {
386
395
  try {
@@ -29,5 +29,6 @@ export declare abstract class GalleryImageToken extends FileToken {
29
29
  * @throws `TypeError` 不可插入文本节点
30
30
  */
31
31
  insertAt<T extends AtomToken | ImageParameterToken>(child: T, i?: number): T;
32
+ cloneNode(): this;
32
33
  }
33
34
  export {};
@@ -33,14 +33,18 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
33
33
  }
34
34
  return useValue ? value : void 0;
35
35
  };
36
+ var __importDefault = (this && this.__importDefault) || function (mod) {
37
+ return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ };
36
39
  Object.defineProperty(exports, "__esModule", { value: true });
37
40
  exports.GalleryImageToken = void 0;
38
41
  const lint_1 = require("../../util/lint");
39
42
  const constants_1 = require("../../util/constants");
40
- const index_1 = require("../../index");
43
+ const index_1 = __importDefault(require("../../index"));
41
44
  const index_2 = require("../index");
42
45
  const file_1 = require("./file");
43
46
  /* NOT FOR BROWSER */
47
+ const debug_1 = require("../../util/debug");
44
48
  const singleLine_1 = require("../../mixin/singleLine");
45
49
  const imageParameter_1 = require("../imageParameter");
46
50
  /**
@@ -135,6 +139,16 @@ let GalleryImageToken = (() => {
135
139
  }
136
140
  return super.insertAt(child, i);
137
141
  }
142
+ cloneNode() {
143
+ const [link, ...linkText] = this.cloneChildNodes();
144
+ return debug_1.Shadow.run(() => {
145
+ // @ts-expect-error abstract class
146
+ const token = new GalleryImageToken(this.type.slice(0, -6), '', undefined, this.getAttribute('config'));
147
+ token.firstChild.safeReplaceWith(link);
148
+ token.append(...linkText);
149
+ return token;
150
+ });
151
+ }
138
152
  };
139
153
  return GalleryImageToken = _classThis;
140
154
  })();
@@ -33,12 +33,15 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
33
33
  }
34
34
  return useValue ? value : void 0;
35
35
  };
36
+ var __importDefault = (this && this.__importDefault) || function (mod) {
37
+ return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ };
36
39
  Object.defineProperty(exports, "__esModule", { value: true });
37
40
  exports.MagicLinkToken = void 0;
38
41
  const lint_1 = require("../util/lint");
39
42
  const string_1 = require("../util/string");
40
43
  const rect_1 = require("../lib/rect");
41
- const index_1 = require("../index");
44
+ const index_1 = __importDefault(require("../index"));
42
45
  const index_2 = require("./index");
43
46
  /* NOT FOR BROWSER */
44
47
  const debug_1 = require("../util/debug");
@@ -1,11 +1,14 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.NestedToken = void 0;
4
7
  const lint_1 = require("../util/lint");
5
8
  const rect_1 = require("../lib/rect");
6
9
  const commentAndExt_1 = require("../parser/commentAndExt");
7
10
  const braces_1 = require("../parser/braces");
8
- const index_1 = require("../index");
11
+ const index_1 = __importDefault(require("../index"));
9
12
  const index_2 = require("./index");
10
13
  const ext_1 = require("./tagPair/ext");
11
14
  const noinclude_1 = require("./nowiki/noinclude");
@@ -33,11 +33,14 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
33
33
  }
34
34
  return useValue ? value : void 0;
35
35
  };
36
+ var __importDefault = (this && this.__importDefault) || function (mod) {
37
+ return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ };
36
39
  Object.defineProperty(exports, "__esModule", { value: true });
37
40
  exports.CommentToken = void 0;
38
41
  const lint_1 = require("../../util/lint");
39
42
  const hidden_1 = require("../../mixin/hidden");
40
- const index_1 = require("../../index");
43
+ const index_1 = __importDefault(require("../../index"));
41
44
  const base_1 = require("./base");
42
45
  /* NOT FOR BROWSER */
43
46
  const debug_1 = require("../../util/debug");
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.NowikiToken = void 0;
4
7
  const lint_1 = require("../../util/lint");
5
- const index_1 = require("../../index");
8
+ const index_1 = __importDefault(require("../../index"));
6
9
  const base_1 = require("./base");
7
10
  /* NOT FOR BROWSER */
8
11
  const constants_1 = require("../../util/constants");
@@ -33,11 +33,14 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
33
33
  }
34
34
  return useValue ? value : void 0;
35
35
  };
36
+ var __importDefault = (this && this.__importDefault) || function (mod) {
37
+ return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ };
36
39
  Object.defineProperty(exports, "__esModule", { value: true });
37
40
  exports.QuoteToken = void 0;
38
41
  const lint_1 = require("../../util/lint");
39
42
  const rect_1 = require("../../lib/rect");
40
- const index_1 = require("../../index");
43
+ const index_1 = __importDefault(require("../../index"));
41
44
  const base_1 = require("./base");
42
45
  /* NOT FOR BROWSER */
43
46
  const constants_1 = require("../../util/constants");
@@ -1,11 +1,14 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.OnlyincludeToken = void 0;
4
7
  const index_1 = require("./index");
5
8
  /* NOT FOR BROWSER */
6
9
  const debug_1 = require("../util/debug");
7
10
  const constants_1 = require("../util/constants");
8
- const index_2 = require("../index");
11
+ const index_2 = __importDefault(require("../index"));
9
12
  /* NOT FOR BROWSER END */
10
13
  /**
11
14
  * `<onlyinclude>` during transclusion
@@ -1,10 +1,13 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.ParamTagToken = void 0;
4
7
  const lint_1 = require("../../util/lint");
5
8
  const rect_1 = require("../../lib/rect");
6
9
  const commentAndExt_1 = require("../../parser/commentAndExt");
7
- const index_1 = require("../../index");
10
+ const index_1 = __importDefault(require("../../index"));
8
11
  const index_2 = require("../index");
9
12
  const atom_1 = require("../atom");
10
13
  /* NOT FOR BROWSER */
@@ -53,6 +56,7 @@ class ParamTagToken extends index_2.Token {
53
56
  lint(start = this.getAbsoluteIndex()) {
54
57
  const rect = new rect_1.BoundingRect(this, start), msg = index_1.default.msg('invalid parameter of <$1>', this.name), errors = [];
55
58
  for (const child of this.childNodes) {
59
+ child.setAttribute('aIndex', start);
56
60
  const grandChildren = child.childNodes
57
61
  .filter(({ type }) => type !== 'comment' && type !== 'include' && type !== 'noinclude');
58
62
  if (grandChildren.some(({ type }) => type === 'ext')) {
@@ -1,9 +1,12 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.InputboxToken = void 0;
4
7
  const commentAndExt_1 = require("../../parser/commentAndExt");
5
8
  const braces_1 = require("../../parser/braces");
6
- const index_1 = require("../../index");
9
+ const index_1 = __importDefault(require("../../index"));
7
10
  const index_2 = require("./index");
8
11
  /* NOT FOR BROWSER */
9
12
  const constants_1 = require("../../util/constants");
@@ -33,11 +33,14 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
33
33
  }
34
34
  return useValue ? value : void 0;
35
35
  };
36
+ var __importDefault = (this && this.__importDefault) || function (mod) {
37
+ return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ };
36
39
  Object.defineProperty(exports, "__esModule", { value: true });
37
40
  exports.ParameterToken = void 0;
38
41
  const string_1 = require("../util/string");
39
42
  const lint_1 = require("../util/lint");
40
- const index_1 = require("../index");
43
+ const index_1 = __importDefault(require("../index"));
41
44
  const index_2 = require("./index");
42
45
  /* NOT FOR BROWSER */
43
46
  const debug_1 = require("../util/debug");
package/dist/src/pre.js CHANGED
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.PreToken = void 0;
4
7
  const constants_1 = require("../util/constants");
5
- const index_1 = require("../index");
8
+ const index_1 = __importDefault(require("../index"));
6
9
  const index_2 = require("./index");
7
10
  const noinclude_1 = require("./nowiki/noinclude");
8
11
  /* NOT FOR BROWSER */
@@ -100,7 +100,9 @@ let RedirectToken = (() => {
100
100
  }
101
101
  /** @private */
102
102
  lint(start = this.getAbsoluteIndex()) {
103
- return this.lastChild.lint(start + this.#pre.length + this.firstChild.toString().length);
103
+ const index = start + this.#pre.length + this.firstChild.toString().length;
104
+ this.lastChild.setAttribute('aIndex', index);
105
+ return this.lastChild.lint(index);
104
106
  }
105
107
  /** @private */
106
108
  print() {
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.TableBaseToken = void 0;
4
7
  const attributesParent_1 = require("../../mixin/attributesParent");
5
- const index_1 = require("../../index");
8
+ const index_1 = __importDefault(require("../../index"));
6
9
  const index_2 = require("../index");
7
10
  const syntax_1 = require("../syntax");
8
11
  const attributes_1 = require("../attributes");
@@ -1,10 +1,13 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.TableToken = exports.Layout = exports.isRowEnd = void 0;
4
7
  const lint_1 = require("../../util/lint");
5
8
  const debug_1 = require("../../util/debug");
6
9
  const rect_1 = require("../../lib/rect");
7
- const index_1 = require("../../index");
10
+ const index_1 = __importDefault(require("../../index"));
8
11
  const trBase_1 = require("./trBase");
9
12
  const syntax_1 = require("../syntax");
10
13
  /* NOT FOR BROWSER */
@@ -153,7 +156,8 @@ class TableToken extends trBase_1.TrBaseToken {
153
156
  */
154
157
  getLayout(stop) {
155
158
  const rows = this.getAllRows(), { length } = rows, layout = new Layout(...emptyArray(length, () => []));
156
- for (const [i, rowLayout] of layout.entries()) {
159
+ for (let i = 0; i < layout.length; i++) {
160
+ const rowLayout = layout[i];
157
161
  /* NOT FOR BROWSER */
158
162
  if (i > (stop?.row ?? stop?.y ?? NaN)) {
159
163
  break;
@@ -573,7 +577,10 @@ class TableToken extends trBase_1.TrBaseToken {
573
577
  * @param token 表格或表格行
574
578
  */
575
579
  const filter = (token) => token.childNodes.filter((0, debug_1.isToken)('table-inter'));
576
- const { childNodes } = this, tr = childNodes.filter((0, debug_1.isToken)('tr')), newOpt = { ...opt, nowrap: true };
580
+ const { childNodes } = this, tr = childNodes.filter((0, debug_1.isToken)('tr')), newOpt = {
581
+ ...opt,
582
+ nowrap: true,
583
+ };
577
584
  return `${[this, ...tr].flatMap(filter) // eslint-disable-line es-x/no-array-prototype-flat
578
585
  .map(token => token.toHtmlInternal(newOpt).trim())
579
586
  .join(' ')}<table${childNodes[1].toHtmlInternal()}>${opt?.nowrap ? ' ' : '\n'}<tbody>${super.toHtmlInternal(opt)}${(0, html_1.html)(tr, '', opt)}</tbody></table>`;
@@ -33,12 +33,15 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
33
33
  }
34
34
  return useValue ? value : void 0;
35
35
  };
36
+ var __importDefault = (this && this.__importDefault) || function (mod) {
37
+ return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ };
36
39
  Object.defineProperty(exports, "__esModule", { value: true });
37
40
  exports.createTd = exports.TdToken = void 0;
38
41
  const lint_1 = require("../../util/lint");
39
42
  const constants_1 = require("../../util/constants");
40
43
  const rect_1 = require("../../lib/rect");
41
- const index_1 = require("../../index");
44
+ const index_1 = __importDefault(require("../../index"));
42
45
  const index_2 = require("../index");
43
46
  const base_1 = require("./base");
44
47
  /* NOT FOR BROWSER */
@@ -33,11 +33,14 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
33
33
  }
34
34
  return useValue ? value : void 0;
35
35
  };
36
+ var __importDefault = (this && this.__importDefault) || function (mod) {
37
+ return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ };
36
39
  Object.defineProperty(exports, "__esModule", { value: true });
37
40
  exports.ExtToken = void 0;
38
41
  const lint_1 = require("../../util/lint");
39
42
  const rect_1 = require("../../lib/rect");
40
- const index_1 = require("../../index");
43
+ const index_1 = __importDefault(require("../../index"));
41
44
  const attributesParent_1 = require("../../mixin/attributesParent");
42
45
  const index_2 = require("../index");
43
46
  const index_3 = require("./index");
@@ -97,7 +100,11 @@ let ExtToken = (() => {
97
100
  constructor(name, attr, inner, closed, config = index_1.default.getConfig(), include = false, accum = []) {
98
101
  const lcName = name.toLowerCase(),
99
102
  // @ts-expect-error abstract class
100
- attrToken = new attributes_1.AttributesToken(!attr || /^\s/u.test(attr) ? attr : ` ${attr}`, 'ext-attrs', lcName, config, accum), newConfig = { ...config, ext: del(config.ext, lcName), excludes: [...config.excludes ?? []] };
103
+ attrToken = new attributes_1.AttributesToken(!attr || /^\s/u.test(attr) ? attr : ` ${attr}`, 'ext-attrs', lcName, config, accum), newConfig = {
104
+ ...config,
105
+ ext: del(config.ext, lcName),
106
+ excludes: [...config.excludes ?? []],
107
+ };
101
108
  let innerToken;
102
109
  switch (lcName) {
103
110
  case 'tab':
@@ -203,11 +210,16 @@ let ExtToken = (() => {
203
210
  case 'nowiki':
204
211
  return (0, string_1.newline)(lastChild.toHtmlInternal());
205
212
  case 'pre':
206
- return `<pre${firstChild.toHtmlInternal()}>${(0, string_1.newline)(lastChild.toHtmlInternal({ ...opt, nowrap: false }))}</pre>`;
213
+ return `<pre${firstChild.toHtmlInternal()}>${(0, string_1.newline)(lastChild.toHtmlInternal({
214
+ ...opt,
215
+ nowrap: false,
216
+ }))}</pre>`;
207
217
  case 'poem':
208
218
  firstChild.classList.add('poem');
209
- return `<div${firstChild.toHtmlInternal()}>${lastChild.toHtmlInternal({ ...opt, nowrap: false })
210
- .replace(/(?<!^|<hr>)\n(?!$)/gu, '<br>\n')
219
+ return `<div${firstChild.toHtmlInternal()}>${lastChild.toHtmlInternal({
220
+ ...opt,
221
+ nowrap: false,
222
+ }).replace(/(?<!^|<hr>)\n(?!$)/gu, '<br>\n')
211
223
  .replace(/^ +/gmu, p => '&nbsp;'.repeat(p.length))}</div>`;
212
224
  case 'gallery': {
213
225
  const caption = firstChild.getAttrToken('caption'), perrow = parseInt(String(firstChild.getAttr('perrow'))), mode = firstChild.getAttr('mode'), nolines = typeof mode === 'string' && mode.toLowerCase() === 'nolines', padding = nolines ? 9 : 43;
@@ -33,12 +33,15 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
33
33
  }
34
34
  return useValue ? value : void 0;
35
35
  };
36
+ var __importDefault = (this && this.__importDefault) || function (mod) {
37
+ return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ };
36
39
  Object.defineProperty(exports, "__esModule", { value: true });
37
40
  exports.IncludeToken = void 0;
38
41
  const lint_1 = require("../../util/lint");
39
42
  const rect_1 = require("../../lib/rect");
40
43
  const hidden_1 = require("../../mixin/hidden");
41
- const index_1 = require("../../index");
44
+ const index_1 = __importDefault(require("../../index"));
42
45
  const index_2 = require("./index");
43
46
  /* NOT FOR BROWSER */
44
47
  const debug_1 = require("../../util/debug");
@@ -33,13 +33,16 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
33
33
  }
34
34
  return useValue ? value : void 0;
35
35
  };
36
+ var __importDefault = (this && this.__importDefault) || function (mod) {
37
+ return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ };
36
39
  Object.defineProperty(exports, "__esModule", { value: true });
37
40
  exports.TagPairToken = void 0;
38
41
  const index_1 = require("../index");
39
42
  /* NOT FOR BROWSER */
40
43
  const constants_1 = require("../../util/constants");
41
44
  const fixed_1 = require("../../mixin/fixed");
42
- const index_2 = require("../../index");
45
+ const index_2 = __importDefault(require("../../index"));
43
46
  /* NOT FOR BROWSER END */
44
47
  /**
45
48
  * Paired tags
@@ -1,4 +1,7 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.TranscludeToken = void 0;
4
7
  const string_1 = require("../util/string");
@@ -11,7 +14,7 @@ const parameter_1 = require("./parameter");
11
14
  const atom_1 = require("./atom");
12
15
  const syntax_1 = require("./syntax");
13
16
  /* NOT FOR BROWSER */
14
- const index_2 = require("../index");
17
+ const index_2 = __importDefault(require("../index"));
15
18
  const basicMagicWords = new Map([['=', '='], ['!', '|']]);
16
19
  /**
17
20
  * template or magic word
@@ -122,7 +125,8 @@ class TranscludeToken extends index_1.Token {
122
125
  }
123
126
  const templateLike = this.isTemplate();
124
127
  let i = 1;
125
- for (const [j, part] of parts.entries()) {
128
+ for (let j = 0; j < parts.length; j++) {
129
+ const part = parts[j];
126
130
  if (!(templateLike || this.name === 'switch' && j > 0 || this.name === 'tag' && j > 1)) {
127
131
  part[0] = part.join('=');
128
132
  part.length = 1;
@@ -169,8 +173,9 @@ class TranscludeToken extends index_1.Token {
169
173
  }
170
174
  /** 获取模板或模块名 */
171
175
  #getTitle() {
172
- const isTemplate = this.type === 'template';
173
- return this.normalizeTitle(this.childNodes[isTemplate ? 0 : 1].toString(true), isTemplate ? 10 : 828, true);
176
+ const isTemplate = this.type === 'template', title = this.normalizeTitle(this.childNodes[isTemplate ? 0 : 1].toString(true), isTemplate ? 10 : 828, true);
177
+ title.fragment = undefined;
178
+ return title;
174
179
  }
175
180
  /**
176
181
  * Get the module name and module function name
@@ -328,11 +333,11 @@ class TranscludeToken extends index_1.Token {
328
333
  /* NOT FOR BROWSER END */
329
334
  for (let i = added ? args.indexOf(addedToken) : addedToken - 1; i < args.length; i++) {
330
335
  const token = args[i], { name } = token, newName = String(i + 1);
331
- if (name !== newName) {
336
+ if (name !== newName || token === addedToken) {
332
337
  token.setAttribute('name', newName);
333
338
  this.getArgs(newName, false, false).add(token);
334
339
  /* NOT FOR BROWSER */
335
- if (name) {
340
+ if (name && token !== addedToken) {
336
341
  this.getArgs(name, false, false).delete(token);
337
342
  }
338
343
  }
@@ -471,7 +476,7 @@ class TranscludeToken extends index_1.Token {
471
476
  const [first, ...cloned] = this.cloneChildNodes(), config = this.getAttribute('config');
472
477
  return debug_1.Shadow.run(() => {
473
478
  // @ts-expect-error abstract class
474
- const token = new TranscludeToken(this.type === 'template' ? 'T' : first.text(), [], config);
479
+ const token = new TranscludeToken(this.type === 'template' ? 'T' : `${first.text()}:`, [], config);
475
480
  if (this.#raw) {
476
481
  token.setModifier(this.modifier);
477
482
  }
@@ -479,7 +484,11 @@ class TranscludeToken extends index_1.Token {
479
484
  token.setAttribute('modifier', this.modifier);
480
485
  }
481
486
  token.firstChild.safeReplaceWith(first);
487
+ if (this.type === 'magic-word') {
488
+ token.removeAt(1);
489
+ }
482
490
  token.append(...cloned);
491
+ token.afterBuild();
483
492
  return token;
484
493
  });
485
494
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.undo = exports.typeError = exports.mixin = exports.setChildNodes = exports.isToken = exports.Shadow = void 0;
3
+ exports.undo = exports.mixin = exports.setChildNodes = exports.isToken = exports.Shadow = void 0;
4
4
  exports.Shadow = {
5
5
  running: false,
6
6
  /** @private */
@@ -65,18 +65,6 @@ const mixin = (target, source) => {
65
65
  };
66
66
  exports.mixin = mixin;
67
67
  /* NOT FOR BROWSER */
68
- /* istanbul ignore next */
69
- /**
70
- * 定制TypeError消息
71
- * @param {Function} Constructor 类
72
- * @param method
73
- * @param args 可接受的参数类型
74
- * @throws `TypeError`
75
- */
76
- const typeError = ({ name }, method, ...args) => {
77
- throw new TypeError(`${name}.${method} method only accepts ${args.join('、')} as input parameters!`);
78
- };
79
- exports.typeError = typeError;
80
68
  /**
81
69
  * 撤销最近一次Mutation
82
70
  * @param e 事件
package/dist/util/diff.js CHANGED
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.info = exports.error = exports.diff = exports.cmd = void 0;
4
- const fs = require("fs/promises");
7
+ const promises_1 = __importDefault(require("fs/promises"));
5
8
  const child_process_1 = require("child_process");
6
- const chalk = require("chalk");
7
9
  /* istanbul ignore next */
8
10
  process.on('unhandledRejection', e => {
9
11
  console.error(e);
@@ -61,7 +63,7 @@ const diff = async (oldStr, newStr, uid) => {
61
63
  return;
62
64
  }
63
65
  const oldFile = `diffOld${uid}`, newFile = `diffNew${uid}`;
64
- await Promise.all([fs.writeFile(oldFile, oldStr), fs.writeFile(newFile, newStr)]);
66
+ await Promise.all([promises_1.default.writeFile(oldFile, oldStr), promises_1.default.writeFile(newFile, newStr)]);
65
67
  const stdout = await (0, exports.cmd)('git', [
66
68
  'diff',
67
69
  '--color-words=[\xC0-\xFF][\x80-\xBF]+|<?/?\\w+/?>?|[^[:space:]]',
@@ -71,18 +73,30 @@ const diff = async (oldStr, newStr, uid) => {
71
73
  newFile,
72
74
  ]);
73
75
  console.log(stdout?.split('\n').slice(4).join('\n'));
74
- await Promise.all([fs.unlink(oldFile), fs.unlink(newFile)]);
76
+ await Promise.all([promises_1.default.unlink(oldFile), promises_1.default.unlink(newFile)]);
75
77
  };
76
78
  exports.diff = diff;
77
79
  /* istanbul ignore next */
78
80
  /** @implements */
79
81
  const error = (msg, ...args) => {
80
- console.error(chalk.red(msg), ...args);
82
+ try {
83
+ const chalk = require('chalk');
84
+ console.error(chalk.red(msg), ...args);
85
+ }
86
+ catch {
87
+ console.error(msg, ...args);
88
+ }
81
89
  };
82
90
  exports.error = error;
83
91
  /* istanbul ignore next */
84
92
  /** @implements */
85
93
  const info = (msg, ...args) => {
86
- console.info(chalk.green(msg), ...args);
94
+ try {
95
+ const chalk = require('chalk');
96
+ console.info(chalk.green(msg), ...args);
97
+ }
98
+ catch {
99
+ console.info(msg, ...args);
100
+ }
87
101
  };
88
102
  exports.info = info;
package/dist/util/lint.js CHANGED
@@ -1,9 +1,12 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.cache = exports.generateForSelf = exports.generateForChild = exports.getEndPos = void 0;
4
7
  const debug_1 = require("./debug");
5
8
  const rect_1 = require("../lib/rect");
6
- const index_1 = require("../index");
9
+ const index_1 = __importDefault(require("../index"));
7
10
  /**
8
11
  * 计算结束位置
9
12
  * @param top 起始行
@@ -40,8 +40,11 @@ const decodeHtml = (str) => {
40
40
  /* NOT FOR BROWSER ONLY */
41
41
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
42
42
  if (typeof process === 'object' && typeof process.versions?.node === 'string') {
43
- const { decodeHTMLStrict } = require('entities');
44
- return decodeHTMLStrict(str).replace(/\xA0/gu, ' ');
43
+ try {
44
+ const { decodeHTMLStrict } = require('entities');
45
+ return decodeHTMLStrict(str).replace(/\xA0/gu, ' ');
46
+ }
47
+ catch { }
45
48
  }
46
49
  /* istanbul ignore next */
47
50
  /* NOT FOR BROWSER ONLY END */