wikiparser-node 1.0.0-beta.0 → 1.0.0-beta.2

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 (133) hide show
  1. package/config/.schema.json +26 -0
  2. package/dist/index.d.ts +11 -9
  3. package/dist/index.js +22 -24
  4. package/dist/internal.d.ts +44 -0
  5. package/dist/lib/element.d.ts +42 -32
  6. package/dist/lib/element.js +59 -56
  7. package/dist/lib/node.d.ts +29 -36
  8. package/dist/lib/node.js +33 -48
  9. package/dist/lib/range.d.ts +132 -0
  10. package/dist/lib/range.js +387 -0
  11. package/dist/lib/ranges.d.ts +2 -12
  12. package/dist/lib/ranges.js +6 -11
  13. package/dist/lib/text.d.ts +11 -5
  14. package/dist/lib/text.js +25 -13
  15. package/dist/lib/title.d.ts +4 -5
  16. package/dist/lib/title.js +17 -7
  17. package/dist/mixin/attributesParent.js +6 -3
  18. package/dist/mixin/fixed.js +8 -5
  19. package/dist/mixin/hidden.js +7 -3
  20. package/dist/mixin/singleLine.js +6 -3
  21. package/dist/mixin/sol.js +6 -3
  22. package/dist/parser/{brackets.js → braces.js} +34 -26
  23. package/dist/parser/commentAndExt.js +25 -15
  24. package/dist/parser/converter.js +16 -9
  25. package/dist/parser/externalLinks.js +15 -9
  26. package/dist/parser/hrAndDoubleUnderscore.js +17 -10
  27. package/dist/parser/html.js +18 -9
  28. package/dist/parser/links.js +22 -14
  29. package/dist/parser/list.js +20 -10
  30. package/dist/parser/magicLinks.js +14 -7
  31. package/dist/parser/quotes.js +21 -11
  32. package/dist/parser/selector.js +19 -12
  33. package/dist/parser/table.js +25 -16
  34. package/dist/src/arg.d.ts +7 -8
  35. package/dist/src/arg.js +27 -24
  36. package/dist/src/atom.d.ts +4 -5
  37. package/dist/src/atom.js +9 -7
  38. package/dist/src/attribute.d.ts +13 -13
  39. package/dist/src/attribute.js +28 -25
  40. package/dist/src/attributes.d.ts +11 -10
  41. package/dist/src/attributes.js +40 -45
  42. package/dist/src/converter.d.ts +5 -7
  43. package/dist/src/converter.js +22 -16
  44. package/dist/src/converterFlags.d.ts +11 -12
  45. package/dist/src/converterFlags.js +17 -14
  46. package/dist/src/converterRule.d.ts +9 -10
  47. package/dist/src/converterRule.js +27 -27
  48. package/dist/src/extLink.d.ts +4 -6
  49. package/dist/src/extLink.js +25 -22
  50. package/dist/src/gallery.d.ts +9 -13
  51. package/dist/src/gallery.js +28 -23
  52. package/dist/src/heading.d.ts +11 -11
  53. package/dist/src/heading.js +19 -19
  54. package/dist/src/hidden.d.ts +4 -5
  55. package/dist/src/hidden.js +10 -8
  56. package/dist/src/html.d.ts +15 -12
  57. package/dist/src/html.js +18 -15
  58. package/dist/src/imageParameter.d.ts +11 -13
  59. package/dist/src/imageParameter.js +21 -16
  60. package/dist/src/imagemap.d.ts +11 -15
  61. package/dist/src/imagemap.js +26 -21
  62. package/dist/src/imagemapLink.d.ts +12 -17
  63. package/dist/src/imagemapLink.js +19 -14
  64. package/dist/src/index.d.ts +24 -20
  65. package/dist/src/index.js +65 -75
  66. package/dist/src/link/base.d.ts +8 -10
  67. package/dist/src/link/base.js +28 -22
  68. package/dist/src/link/category.d.ts +2 -3
  69. package/dist/src/link/category.js +7 -5
  70. package/dist/src/link/file.d.ts +9 -11
  71. package/dist/src/link/file.js +53 -26
  72. package/dist/src/link/galleryImage.d.ts +8 -8
  73. package/dist/src/link/galleryImage.js +18 -16
  74. package/dist/src/link/index.d.ts +6 -6
  75. package/dist/src/link/index.js +14 -16
  76. package/dist/src/magicLink.d.ts +9 -6
  77. package/dist/src/magicLink.js +23 -18
  78. package/dist/src/nested.d.ts +10 -10
  79. package/dist/src/nested.js +25 -17
  80. package/dist/src/nowiki/base.d.ts +7 -8
  81. package/dist/src/nowiki/base.js +10 -8
  82. package/dist/src/nowiki/comment.d.ts +7 -7
  83. package/dist/src/nowiki/comment.js +12 -9
  84. package/dist/src/nowiki/dd.d.ts +2 -3
  85. package/dist/src/nowiki/dd.js +7 -11
  86. package/dist/src/nowiki/doubleUnderscore.d.ts +5 -7
  87. package/dist/src/nowiki/doubleUnderscore.js +11 -8
  88. package/dist/src/nowiki/hr.d.ts +6 -7
  89. package/dist/src/nowiki/hr.js +11 -8
  90. package/dist/src/nowiki/index.d.ts +5 -7
  91. package/dist/src/nowiki/index.js +8 -6
  92. package/dist/src/nowiki/list.d.ts +4 -4
  93. package/dist/src/nowiki/list.js +8 -6
  94. package/dist/src/nowiki/noinclude.d.ts +3 -3
  95. package/dist/src/nowiki/noinclude.js +8 -6
  96. package/dist/src/nowiki/quote.d.ts +6 -7
  97. package/dist/src/nowiki/quote.js +11 -8
  98. package/dist/src/onlyinclude.d.ts +3 -5
  99. package/dist/src/onlyinclude.js +9 -7
  100. package/dist/src/paramTag/index.d.ts +8 -10
  101. package/dist/src/paramTag/index.js +15 -13
  102. package/dist/src/paramTag/inputbox.d.ts +4 -6
  103. package/dist/src/paramTag/inputbox.js +10 -8
  104. package/dist/src/parameter.d.ts +11 -12
  105. package/dist/src/parameter.js +25 -22
  106. package/dist/src/pre.d.ts +5 -10
  107. package/dist/src/pre.js +16 -11
  108. package/dist/src/syntax.d.ts +6 -7
  109. package/dist/src/syntax.js +12 -10
  110. package/dist/src/table/base.d.ts +14 -9
  111. package/dist/src/table/base.js +18 -15
  112. package/dist/src/table/index.d.ts +24 -17
  113. package/dist/src/table/index.js +39 -67
  114. package/dist/src/table/td.d.ts +17 -21
  115. package/dist/src/table/td.js +20 -28
  116. package/dist/src/table/tr.d.ts +6 -11
  117. package/dist/src/table/tr.js +8 -6
  118. package/dist/src/table/trBase.d.ts +12 -22
  119. package/dist/src/table/trBase.js +23 -19
  120. package/dist/src/tagPair/ext.d.ts +10 -10
  121. package/dist/src/tagPair/ext.js +47 -24
  122. package/dist/src/tagPair/include.d.ts +6 -7
  123. package/dist/src/tagPair/include.js +11 -8
  124. package/dist/src/tagPair/index.d.ts +12 -11
  125. package/dist/src/tagPair/index.js +13 -11
  126. package/dist/src/transclude.d.ts +8 -10
  127. package/dist/src/transclude.js +70 -77
  128. package/dist/util/debug.js +2 -12
  129. package/dist/util/diff.js +4 -2
  130. package/dist/util/lint.js +5 -5
  131. package/dist/util/string.js +2 -31
  132. package/package.json +13 -13
  133. package/dist/util/base.js +0 -26
@@ -1,9 +1,8 @@
1
- import * as Parser from '../../index';
2
- import NowikiBaseToken = require('./base');
3
- import AttributesToken = require('../attributes');
4
- import ExtToken = require('../tagPair/ext');
1
+ import { NowikiBaseToken } from './base';
2
+ import type { LintError } from '../../index';
3
+ import type { AttributesToken, ExtToken } from '../../internal';
5
4
  /** 扩展标签内的纯文字Token */
6
- declare abstract class NowikiToken extends NowikiBaseToken {
5
+ export declare abstract class NowikiToken extends NowikiBaseToken {
7
6
  /** @browser */
8
7
  readonly type = "ext-inner";
9
8
  abstract get nextSibling(): undefined;
@@ -16,6 +15,5 @@ declare abstract class NowikiToken extends NowikiBaseToken {
16
15
  * @override
17
16
  * @browser
18
17
  */
19
- lint(start?: number): Parser.LintError[];
18
+ lint(start?: number): LintError[];
20
19
  }
21
- export = NowikiToken;
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NowikiToken = void 0;
2
4
  const lint_1 = require("../../util/lint");
3
- const Parser = require("../../index");
4
- const NowikiBaseToken = require("./base");
5
+ const index_1 = require("../../index");
6
+ const base_1 = require("./base");
5
7
  /** 扩展标签内的纯文字Token */
6
- class NowikiToken extends NowikiBaseToken {
8
+ class NowikiToken extends base_1.NowikiBaseToken {
7
9
  /** @browser */
8
10
  type = 'ext-inner';
9
11
  /**
@@ -13,9 +15,9 @@ class NowikiToken extends NowikiBaseToken {
13
15
  lint(start = this.getAbsoluteIndex()) {
14
16
  const { name } = this;
15
17
  return (name === 'templatestyles' || name === 'section') && this.firstChild.data
16
- ? [(0, lint_1.generateForSelf)(this, { start }, Parser.msg('nothing should be in <$1>', name))]
18
+ ? [(0, lint_1.generateForSelf)(this, { start }, index_1.default.msg('nothing should be in <$1>', name))]
17
19
  : super.lint(start);
18
20
  }
19
21
  }
20
- Parser.classes['NowikiToken'] = __filename;
21
- module.exports = NowikiToken;
22
+ exports.NowikiToken = NowikiToken;
23
+ index_1.default.classes['NowikiToken'] = __filename;
@@ -1,6 +1,6 @@
1
- import DdToken = require('./dd');
1
+ import { DdToken } from './dd';
2
2
  declare const ListToken_base: (abstract new (...args: any[]) => {
3
- "__#14@#isRoot"(): boolean;
3
+ "__#7@#isRoot"(): boolean;
4
4
  prependNewLine(): string;
5
5
  toString(selector?: string | undefined): string;
6
6
  getPadding(): number;
@@ -9,8 +9,8 @@ declare const ListToken_base: (abstract new (...args: any[]) => {
9
9
  insertAt(token: unknown, i?: number | undefined): unknown;
10
10
  }) & typeof DdToken;
11
11
  /** 位于行首的`;:*#` */
12
- declare abstract class ListToken extends ListToken_base {
12
+ export declare abstract class ListToken extends ListToken_base {
13
13
  /** @browser */
14
14
  readonly type = "list";
15
15
  }
16
- export = ListToken;
16
+ export {};
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
- const sol = require("../../mixin/sol");
3
- const Parser = require("../../index");
4
- const DdToken = require("./dd");
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ListToken = void 0;
4
+ const sol_1 = require("../../mixin/sol");
5
+ const index_1 = require("../../index");
6
+ const dd_1 = require("./dd");
5
7
  /** 位于行首的`;:*#` */
6
- class ListToken extends sol(DdToken) {
8
+ class ListToken extends (0, sol_1.sol)(dd_1.DdToken) {
7
9
  /** @browser */
8
10
  type = 'list';
9
11
  }
10
- Parser.classes['ListToken'] = __filename;
11
- module.exports = ListToken;
12
+ exports.ListToken = ListToken;
13
+ index_1.default.classes['ListToken'] = __filename;
@@ -1,4 +1,4 @@
1
- import NowikiBaseToken = require('./base');
1
+ import { NowikiBaseToken } from './base';
2
2
  declare const NoincludeToken_base: ((abstract new (...args: any[]) => {
3
3
  text(): string;
4
4
  length: number;
@@ -8,7 +8,7 @@ declare const NoincludeToken_base: ((abstract new (...args: any[]) => {
8
8
  readonly hidden: true;
9
9
  }) & typeof NowikiBaseToken;
10
10
  /** `<noinclude>`和`</noinclude>`,不可进行任何更改 */
11
- declare abstract class NoincludeToken extends NoincludeToken_base {
11
+ export declare abstract class NoincludeToken extends NoincludeToken_base {
12
12
  /** @browser */
13
13
  readonly type = "noinclude";
14
14
  /**
@@ -18,4 +18,4 @@ declare abstract class NoincludeToken extends NoincludeToken_base {
18
18
  */
19
19
  setText(str: string): string;
20
20
  }
21
- export = NoincludeToken;
21
+ export {};
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
- const hidden = require("../../mixin/hidden");
3
- const Parser = require("../../index");
4
- const NowikiBaseToken = require("./base");
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NoincludeToken = void 0;
4
+ const hidden_1 = require("../../mixin/hidden");
5
+ const index_1 = require("../../index");
6
+ const base_1 = require("./base");
5
7
  /** `<noinclude>`和`</noinclude>`,不可进行任何更改 */
6
- class NoincludeToken extends hidden(NowikiBaseToken) {
8
+ class NoincludeToken extends (0, hidden_1.hidden)(base_1.NowikiBaseToken) {
7
9
  /** @browser */
8
10
  type = 'noinclude';
9
11
  /**
@@ -18,5 +20,5 @@ class NoincludeToken extends hidden(NowikiBaseToken) {
18
20
  return super.setText(str);
19
21
  }
20
22
  }
21
- Parser.classes['NoincludeToken'] = __filename;
22
- module.exports = NoincludeToken;
23
+ exports.NoincludeToken = NoincludeToken;
24
+ index_1.default.classes['NoincludeToken'] = __filename;
@@ -1,8 +1,8 @@
1
- import * as Parser from '../../index';
2
- import NowikiBaseToken = require('./base');
3
- import Token = require('..');
1
+ import { NowikiBaseToken } from './base';
2
+ import type { LintError } from '../../index';
3
+ import type { Token } from '..';
4
4
  /** `''`和`'''` */
5
- declare abstract class QuoteToken extends NowikiBaseToken {
5
+ export declare abstract class QuoteToken extends NowikiBaseToken {
6
6
  /** @browser */
7
7
  readonly type = "quote";
8
8
  name: string;
@@ -10,12 +10,12 @@ declare abstract class QuoteToken extends NowikiBaseToken {
10
10
  * @browser
11
11
  * @param n 字符串长度
12
12
  */
13
- constructor(n: number, config?: Parser.Config, accum?: Token[]);
13
+ constructor(n: number, config?: import("../../index").Config, accum?: Token[]);
14
14
  /**
15
15
  * @override
16
16
  * @browser
17
17
  */
18
- lint(start?: number): Parser.LintError[];
18
+ lint(start?: number): LintError[];
19
19
  /** @override */
20
20
  cloneNode(): this;
21
21
  /**
@@ -25,4 +25,3 @@ declare abstract class QuoteToken extends NowikiBaseToken {
25
25
  */
26
26
  setText(str: string): string;
27
27
  }
28
- export = QuoteToken;
@@ -1,16 +1,18 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QuoteToken = void 0;
2
4
  const lint_1 = require("../../util/lint");
3
- const Parser = require("../../index");
4
- const NowikiBaseToken = require("./base");
5
+ const index_1 = require("../../index");
6
+ const base_1 = require("./base");
5
7
  /** `''`和`'''` */
6
- class QuoteToken extends NowikiBaseToken {
8
+ class QuoteToken extends base_1.NowikiBaseToken {
7
9
  /** @browser */
8
10
  type = 'quote';
9
11
  /**
10
12
  * @browser
11
13
  * @param n 字符串长度
12
14
  */
13
- constructor(n, config = Parser.getConfig(), accum = []) {
15
+ constructor(n, config = index_1.default.getConfig(), accum = []) {
14
16
  super(`'`.repeat(n), config, accum);
15
17
  this.setAttribute('name', String(n));
16
18
  }
@@ -19,7 +21,7 @@ class QuoteToken extends NowikiBaseToken {
19
21
  * @browser
20
22
  */
21
23
  lint(start = this.getAbsoluteIndex()) {
22
- const { previousSibling, nextSibling } = this, message = Parser.msg('lonely "$1"', `'`), errors = [];
24
+ const { previousSibling, nextSibling } = this, message = index_1.default.msg('lonely "$1"', `'`), errors = [];
23
25
  let refError, wikitext;
24
26
  if (previousSibling?.type === 'text' && previousSibling.data.endsWith(`'`)) {
25
27
  refError = (0, lint_1.generateForSelf)(this, { start }, message);
@@ -37,7 +39,8 @@ class QuoteToken extends NowikiBaseToken {
37
39
  }
38
40
  /** @override */
39
41
  cloneNode() {
40
- return Parser.run(() => new QuoteToken(Number(this.name), this.getAttribute('config')));
42
+ // @ts-expect-error abstract class
43
+ return index_1.default.run(() => new QuoteToken(Number(this.name), this.getAttribute('config')));
41
44
  }
42
45
  /**
43
46
  * @override
@@ -51,5 +54,5 @@ class QuoteToken extends NowikiBaseToken {
51
54
  throw new RangeError(`${this.constructor.name} 的内部文本只能为连续 2/3/5 个"'"!`);
52
55
  }
53
56
  }
54
- Parser.classes['QuoteToken'] = __filename;
55
- module.exports = QuoteToken;
57
+ exports.QuoteToken = QuoteToken;
58
+ index_1.default.classes['QuoteToken'] = __filename;
@@ -1,10 +1,9 @@
1
- import * as Parser from '../index';
2
- import Token = require('.');
1
+ import { Token } from '.';
3
2
  /**
4
3
  * 嵌入时的`<onlyinclude>`
5
4
  * @classdesc `{childNodes: ...AstText|Token}`
6
5
  */
7
- declare class OnlyincludeToken extends Token {
6
+ export declare class OnlyincludeToken extends Token {
8
7
  /** @browser */
9
8
  readonly type = "onlyinclude";
10
9
  /** 内部wikitext */
@@ -13,7 +12,7 @@ declare class OnlyincludeToken extends Token {
13
12
  * @browser
14
13
  * @param inner 标签内部wikitext
15
14
  */
16
- constructor(inner?: string, config?: Parser.Config, accum?: Token[]);
15
+ constructor(inner?: string, config?: import("../index").Config, accum?: Token[]);
17
16
  /**
18
17
  * @override
19
18
  * @browser
@@ -37,4 +36,3 @@ declare class OnlyincludeToken extends Token {
37
36
  /** @override */
38
37
  cloneNode(): this;
39
38
  }
40
- export = OnlyincludeToken;
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
- const Parser = require("../index");
3
- const Token = require(".");
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OnlyincludeToken = void 0;
4
+ const index_1 = require("../index");
5
+ const _1 = require(".");
4
6
  /**
5
7
  * 嵌入时的`<onlyinclude>`
6
8
  * @classdesc `{childNodes: ...AstText|Token}`
7
9
  */
8
- class OnlyincludeToken extends Token {
10
+ class OnlyincludeToken extends _1.Token {
9
11
  /** @browser */
10
12
  type = 'onlyinclude';
11
13
  /** 内部wikitext */
@@ -16,7 +18,7 @@ class OnlyincludeToken extends Token {
16
18
  * @browser
17
19
  * @param inner 标签内部wikitext
18
20
  */
19
- constructor(inner, config = Parser.getConfig(), accum = []) {
21
+ constructor(inner, config = index_1.default.getConfig(), accum = []) {
20
22
  super(inner, config, true, accum);
21
23
  }
22
24
  /**
@@ -53,12 +55,12 @@ class OnlyincludeToken extends Token {
53
55
  /** @override */
54
56
  cloneNode() {
55
57
  const cloned = this.cloneChildNodes();
56
- return Parser.run(() => {
58
+ return index_1.default.run(() => {
57
59
  const token = new OnlyincludeToken(undefined, this.getAttribute('config'));
58
60
  token.append(...cloned);
59
61
  return token;
60
62
  });
61
63
  }
62
64
  }
63
- Parser.classes['OnlyincludeToken'] = __filename;
64
- module.exports = OnlyincludeToken;
65
+ exports.OnlyincludeToken = OnlyincludeToken;
66
+ index_1.default.classes['OnlyincludeToken'] = __filename;
@@ -1,13 +1,12 @@
1
- import * as Parser from '../../index';
2
- import Token = require('..');
3
- import AtomToken = require('../atom');
4
- import AttributesToken = require('../attributes');
5
- import ExtToken = require('../tagPair/ext');
1
+ import { Token } from '..';
2
+ import { AtomToken } from '../atom';
3
+ import type { LintError } from '../../index';
4
+ import type { AttributesToken, ExtToken } from '../../internal';
6
5
  /**
7
6
  * `<dynamicpagelist>`
8
7
  * @classdesc `{childNodes: ...AtomToken}`
9
8
  */
10
- declare abstract class ParamTagToken extends Token {
9
+ export declare abstract class ParamTagToken extends Token {
11
10
  /** @browser */
12
11
  readonly type = "ext-inner";
13
12
  childNodes: AtomToken[];
@@ -23,7 +22,7 @@ declare abstract class ParamTagToken extends Token {
23
22
  abstract get parentNode(): ExtToken | undefined;
24
23
  abstract get parentElement(): ExtToken | undefined;
25
24
  /** @browser */
26
- constructor(wikitext?: string, config?: Parser.Config, accum?: Token[], acceptable?: Acceptable);
25
+ constructor(wikitext?: string, config?: import("../../index").Config, accum?: Token[], acceptable?: Acceptable);
27
26
  /**
28
27
  * @override
29
28
  * @browser
@@ -43,10 +42,9 @@ declare abstract class ParamTagToken extends Token {
43
42
  * @override
44
43
  * @browser
45
44
  */
46
- lint(start?: number): Parser.LintError[];
45
+ lint(start?: number): LintError[];
47
46
  /** @override */
48
47
  cloneNode(this: this & {
49
- constructor: new (...args: unknown[]) => unknown;
48
+ constructor: new (...args: any[]) => unknown;
50
49
  }): this;
51
50
  }
52
- export = ParamTagToken;
@@ -1,23 +1,25 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ParamTagToken = void 0;
2
4
  const lint_1 = require("../../util/lint");
3
- const singleLine = require("../../mixin/singleLine");
4
- const Parser = require("../../index");
5
- const Token = require("..");
6
- const AtomToken = require("../atom");
5
+ const singleLine_1 = require("../../mixin/singleLine");
6
+ const index_1 = require("../../index");
7
+ const __1 = require("..");
8
+ const atom_1 = require("../atom");
7
9
  /**
8
10
  * `<dynamicpagelist>`
9
11
  * @classdesc `{childNodes: ...AtomToken}`
10
12
  */
11
- class ParamTagToken extends Token {
13
+ class ParamTagToken extends __1.Token {
12
14
  /** @browser */
13
15
  type = 'ext-inner';
14
16
  /** @browser */
15
- constructor(wikitext, config = Parser.getConfig(), accum = [], acceptable = {}) {
17
+ constructor(wikitext, config = index_1.default.getConfig(), accum = [], acceptable = {}) {
16
18
  super(undefined, config, true, accum, {
17
19
  SingleLineAtomToken: ':',
18
20
  });
19
21
  if (wikitext) {
20
- const SingleLineAtomToken = singleLine(AtomToken);
22
+ const SingleLineAtomToken = (0, singleLine_1.singleLine)(atom_1.AtomToken);
21
23
  this.append(...wikitext.split('\n').map(line => new SingleLineAtomToken(line, 'param-line', config, accum, {
22
24
  AstText: ':', ...acceptable,
23
25
  })));
@@ -38,8 +40,8 @@ class ParamTagToken extends Token {
38
40
  return super.text('\n');
39
41
  }
40
42
  /** @private */
41
- getGaps() {
42
- return 1;
43
+ getGaps(i) {
44
+ return i < this.length - 1 ? 1 : 0;
43
45
  }
44
46
  /**
45
47
  * @override
@@ -59,18 +61,18 @@ class ParamTagToken extends Token {
59
61
  return str && !(i >= 0 ? /^[a-z]+(?:\[\])?\s*(?:=|$)/iu : /^[a-z]+(?:\[\])?\s*=/iu).test(str);
60
62
  }).map(child => {
61
63
  rect ??= { start, ...this.getRootNode().posFromIndex(start) };
62
- return (0, lint_1.generateForChild)(child, rect, Parser.msg('invalid parameter of $1', this.name));
64
+ return (0, lint_1.generateForChild)(child, rect, index_1.default.msg('invalid parameter of $1', this.name));
63
65
  });
64
66
  }
65
67
  /** @override */
66
68
  cloneNode() {
67
69
  const cloned = this.cloneChildNodes();
68
- return Parser.run(() => {
70
+ return index_1.default.run(() => {
69
71
  const token = new this.constructor(undefined, this.getAttribute('config'));
70
72
  token.append(...cloned);
71
73
  return token;
72
74
  });
73
75
  }
74
76
  }
75
- Parser.classes['ParamTagToken'] = __filename;
76
- module.exports = ParamTagToken;
77
+ exports.ParamTagToken = ParamTagToken;
78
+ index_1.default.classes['ParamTagToken'] = __filename;
@@ -1,9 +1,7 @@
1
- import * as Parser from '../../index';
2
- import ParamTagToken = require('.');
3
- import Token = require('..');
1
+ import { ParamTagToken } from '.';
2
+ import type { Token } from '..';
4
3
  /** `<inputbox>` */
5
- declare abstract class InputboxToken extends ParamTagToken {
4
+ export declare abstract class InputboxToken extends ParamTagToken {
6
5
  /** @browser */
7
- constructor(wikitext?: string, config?: Parser.Config, accum?: Token[]);
6
+ constructor(wikitext?: string, config?: import("../../index").Config, accum?: Token[]);
8
7
  }
9
- export = InputboxToken;
@@ -1,19 +1,21 @@
1
1
  "use strict";
2
- const parseBrackets = require("../../parser/brackets");
3
- const Parser = require("../../index");
4
- const ParamTagToken = require(".");
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InputboxToken = void 0;
4
+ const braces_1 = require("../../parser/braces");
5
+ const index_1 = require("../../index");
6
+ const _1 = require(".");
5
7
  /** `<inputbox>` */
6
- class InputboxToken extends ParamTagToken {
8
+ class InputboxToken extends _1.ParamTagToken {
7
9
  /** @browser */
8
- constructor(wikitext, config = Parser.getConfig(), accum = []) {
10
+ constructor(wikitext, config = index_1.default.getConfig(), accum = []) {
9
11
  const placeholder = Symbol('InputboxToken');
10
12
  accum.push(placeholder);
11
- const text = wikitext && parseBrackets(wikitext, config, accum);
13
+ const text = wikitext && (0, braces_1.parseBraces)(wikitext, config, accum);
12
14
  accum.splice(accum.indexOf(placeholder), 1);
13
15
  super(text, config, accum, {
14
16
  ArgToken: ':', TranscludeToken: ':',
15
17
  });
16
18
  }
17
19
  }
18
- Parser.classes['InputboxToken'] = __filename;
19
- module.exports = InputboxToken;
20
+ exports.InputboxToken = InputboxToken;
21
+ index_1.default.classes['InputboxToken'] = __filename;
@@ -1,11 +1,10 @@
1
- import * as Parser from '../index';
2
- import Token = require('.');
3
- import AtomToken = require('./atom');
4
- import SyntaxToken = require('./syntax');
1
+ import { Token } from '.';
2
+ import type { LintError } from '../index';
3
+ import type { AtomToken, SyntaxToken, TranscludeToken } from '../internal';
5
4
  declare const ParameterToken_base: ((abstract new (...args: any[]) => {
6
5
  removeAt(): never;
7
- insertAt(token: string, i?: number | undefined): import("../lib/text");
8
- insertAt<T extends import("../lib/node").AstNodeTypes>(token: T, i?: number | undefined): T;
6
+ insertAt(token: string, i?: number | undefined): import("../index").AstText;
7
+ insertAt<T extends import("../index").AstNodes>(token: T, i?: number | undefined): T;
9
8
  length: number;
10
9
  toString(selector?: string | undefined, separator?: string | undefined): string;
11
10
  text(separator?: string | undefined): string;
@@ -16,7 +15,7 @@ declare const ParameterToken_base: ((abstract new (...args: any[]) => {
16
15
  * 模板或魔术字参数
17
16
  * @classdesc `{childNodes: [Token, Token]}`
18
17
  */
19
- declare abstract class ParameterToken extends ParameterToken_base {
18
+ export declare abstract class ParameterToken extends ParameterToken_base {
20
19
  /** @browser */
21
20
  readonly type = "parameter";
22
21
  name: string;
@@ -26,8 +25,8 @@ declare abstract class ParameterToken extends ParameterToken_base {
26
25
  abstract get firstElementChild(): Token;
27
26
  abstract get lastChild(): Token;
28
27
  abstract get lastElementChild(): Token;
29
- abstract get parentNode(): import('./transclude') | undefined;
30
- abstract get parentElement(): import('./transclude') | undefined;
28
+ abstract get parentNode(): TranscludeToken | undefined;
29
+ abstract get parentElement(): TranscludeToken | undefined;
31
30
  abstract get nextSibling(): this | undefined;
32
31
  abstract get nextElementSibling(): this | undefined;
33
32
  abstract get previousSibling(): AtomToken | SyntaxToken | this;
@@ -47,7 +46,7 @@ declare abstract class ParameterToken extends ParameterToken_base {
47
46
  * @param key 参数名
48
47
  * @param value 参数值
49
48
  */
50
- constructor(key?: string | number, value?: string, config?: Parser.Config, accum?: Token[]);
49
+ constructor(key?: string | number, value?: string, config?: import("../index").Config, accum?: Token[]);
51
50
  /**
52
51
  * @override
53
52
  * @browser
@@ -67,7 +66,7 @@ declare abstract class ParameterToken extends ParameterToken_base {
67
66
  * @override
68
67
  * @browser
69
68
  */
70
- lint(start?: number): Parser.LintError[];
69
+ lint(start?: number): LintError[];
71
70
  /** @override */
72
71
  cloneNode(): this;
73
72
  /**
@@ -93,4 +92,4 @@ declare abstract class ParameterToken extends ParameterToken_base {
93
92
  */
94
93
  rename(key: string, force?: boolean): void;
95
94
  }
96
- export = ParameterToken;
95
+ export {};
@@ -1,14 +1,16 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ParameterToken = void 0;
2
4
  const string_1 = require("../util/string");
3
5
  const lint_1 = require("../util/lint");
4
- const fixed = require("../mixin/fixed");
5
- const Parser = require("../index");
6
- const Token = require(".");
6
+ const fixed_1 = require("../mixin/fixed");
7
+ const index_1 = require("../index");
8
+ const _1 = require(".");
7
9
  /**
8
10
  * 模板或魔术字参数
9
11
  * @classdesc `{childNodes: [Token, Token]}`
10
12
  */
11
- class ParameterToken extends fixed(Token) {
13
+ class ParameterToken extends (0, fixed_1.fixed)(_1.Token) {
12
14
  /** @browser */
13
15
  type = 'parameter';
14
16
  /**
@@ -39,11 +41,11 @@ class ParameterToken extends fixed(Token) {
39
41
  * @param key 参数名
40
42
  * @param value 参数值
41
43
  */
42
- constructor(key, value, config = Parser.getConfig(), accum = []) {
44
+ constructor(key, value, config = index_1.default.getConfig(), accum = []) {
43
45
  super(undefined, config, true, accum);
44
- const keyToken = new Token(typeof key === 'number' ? undefined : key, config, true, accum, {
46
+ const keyToken = new _1.Token(typeof key === 'number' ? undefined : key, config, true, accum, {
45
47
  'Stage-11': ':', '!HeadingToken': '',
46
- }), token = new Token(value, config, true, accum);
48
+ }), token = new _1.Token(value, config, true, accum);
47
49
  keyToken.type = 'parameter-key';
48
50
  token.type = 'parameter-value';
49
51
  this.append(keyToken, token.setAttribute('stage', 2));
@@ -90,8 +92,8 @@ class ParameterToken extends fixed(Token) {
90
92
  return this.anon ? this.lastChild.text() : super.text('=');
91
93
  }
92
94
  /** @private */
93
- getGaps() {
94
- return this.anon ? 0 : 1;
95
+ getGaps(i) {
96
+ return this.anon || i === 1 ? 0 : 1;
95
97
  }
96
98
  /**
97
99
  * @override
@@ -124,7 +126,8 @@ class ParameterToken extends fixed(Token) {
124
126
  /** @override */
125
127
  cloneNode() {
126
128
  const [key, value] = this.cloneChildNodes(), config = this.getAttribute('config');
127
- return Parser.run(() => {
129
+ return index_1.default.run(() => {
130
+ // @ts-expect-error abstract class
128
131
  const token = new ParameterToken(this.anon ? Number(this.name) : undefined, undefined, config);
129
132
  token.firstChild.safeReplaceWith(key);
130
133
  token.lastChild.safeReplaceWith(value);
@@ -137,7 +140,7 @@ class ParameterToken extends fixed(Token) {
137
140
  * @param token 待替换的节点
138
141
  */
139
142
  safeReplaceWith(token) {
140
- Parser.warn(`${this.constructor.name}.safeReplaceWith 方法退化到 replaceWith。`);
143
+ index_1.default.warn(`${this.constructor.name}.safeReplaceWith 方法退化到 replaceWith。`);
141
144
  this.replaceWith(token);
142
145
  }
143
146
  /** 获取参数值 */
@@ -151,17 +154,17 @@ class ParameterToken extends fixed(Token) {
151
154
  * @throws `SyntaxError` 非法的模板参数
152
155
  */
153
156
  setValue(value) {
154
- const templateLike = this.parentNode?.isTemplate() !== false, wikitext = `{{${templateLike ? ':T|' : 'lc:'}${this.anon ? '' : '1='}${value}}}`, root = Parser.parse(wikitext, this.getAttribute('include'), 2, this.getAttribute('config')), { length, firstChild: transclude } = root, targetType = templateLike ? 'template' : 'magic-word';
157
+ const templateLike = this.parentNode?.isTemplate() !== false, wikitext = `{{${templateLike ? ':T|' : 'lc:'}${this.anon ? '' : '1='}${value}}}`, root = index_1.default.parse(wikitext, this.getAttribute('include'), 2, this.getAttribute('config')), { length, firstChild: transclude } = root, targetType = templateLike ? 'template' : 'magic-word';
155
158
  if (length !== 1 || transclude.type !== targetType) {
156
159
  throw new SyntaxError(`非法的模板参数:${(0, string_1.noWrap)(value)}`);
157
160
  }
158
161
  const { lastChild: parameter, name } = transclude, targetName = templateLike ? 'T' : 'lc';
159
- if (name !== targetName || transclude.length !== 2 || parameter.anon !== this.anon || parameter.name !== '1') {
160
- throw new SyntaxError(`非法的模板参数:${(0, string_1.noWrap)(value)}`);
162
+ if (name === targetName && transclude.length === 2 && parameter.anon === this.anon && parameter.name === '1') {
163
+ const { lastChild } = parameter;
164
+ parameter.destroy();
165
+ this.lastChild.safeReplaceWith(lastChild);
161
166
  }
162
- const { lastChild } = parameter;
163
- parameter.destroy();
164
- this.lastChild.safeReplaceWith(lastChild);
167
+ throw new SyntaxError(`非法的模板参数:${(0, string_1.noWrap)(value)}`);
165
168
  }
166
169
  /**
167
170
  * 修改参数名
@@ -177,17 +180,17 @@ class ParameterToken extends fixed(Token) {
177
180
  if (parentNode?.isTemplate() === false) {
178
181
  throw new Error(`${this.constructor.name}.rename 方法仅用于模板参数!`);
179
182
  }
180
- const root = Parser.parse(`{{:T|${key}=}}`, this.getAttribute('include'), 2, this.getAttribute('config')), { length, firstChild: template } = root;
183
+ const root = index_1.default.parse(`{{:T|${key}=}}`, this.getAttribute('include'), 2, this.getAttribute('config')), { length, firstChild: template } = root;
181
184
  if (length !== 1 || template.type !== 'template' || template.name !== 'T' || template.length !== 2) {
182
185
  throw new SyntaxError(`非法的模板参数名:${key}`);
183
186
  }
184
187
  const { lastChild: parameter } = template, { name, firstChild } = parameter;
185
188
  if (this.name === name) {
186
- Parser.warn('未改变实际参数名', name);
189
+ index_1.default.warn('未改变实际参数名', name);
187
190
  }
188
191
  else if (parentNode?.hasArg(name)) {
189
192
  if (force) {
190
- Parser.warn('参数更名造成重复参数', name);
193
+ index_1.default.warn('参数更名造成重复参数', name);
191
194
  }
192
195
  else {
193
196
  throw new RangeError(`参数更名造成重复参数:${name}`);
@@ -197,5 +200,5 @@ class ParameterToken extends fixed(Token) {
197
200
  this.firstChild.safeReplaceWith(firstChild);
198
201
  }
199
202
  }
200
- Parser.classes['ParameterToken'] = __filename;
201
- module.exports = ParameterToken;
203
+ exports.ParameterToken = ParameterToken;
204
+ index_1.default.classes['ParameterToken'] = __filename;