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,14 +1,18 @@
1
- import * as Parser from '../index';
2
- import Token = require('.');
1
+ import { Token } from '.';
2
+ import type { LintError } from '../index';
3
3
  /**
4
4
  * 自由外链
5
5
  * @classdesc `{childNodes: ...AstText|CommentToken|IncludeToken|NoincludeToken}`
6
6
  */
7
- declare class MagicLinkToken extends Token {
7
+ export declare class MagicLinkToken extends Token {
8
8
  #private;
9
9
  type: 'free-ext-link' | 'ext-link-url';
10
10
  /** 协议 */
11
11
  get protocol(): string | undefined;
12
+ /**
13
+ * @throws `RangeError` 非法协议
14
+ * @throws `Error` 特殊外链无法更改协议
15
+ */
12
16
  set protocol(value: string | undefined);
13
17
  /** 和内链保持一致 */
14
18
  get link(): string;
@@ -18,12 +22,12 @@ declare class MagicLinkToken extends Token {
18
22
  * @param url 网址
19
23
  * @param doubleSlash 是否接受"//"作为协议
20
24
  */
21
- constructor(url: string | undefined, doubleSlash: boolean, config?: Parser.Config, accum?: Token[]);
25
+ constructor(url: string | undefined, doubleSlash: boolean, config?: import("../index").Config, accum?: Token[]);
22
26
  /**
23
27
  * @override
24
28
  * @browser
25
29
  */
26
- lint(start?: number): Parser.LintError[];
30
+ lint(start?: number): LintError[];
27
31
  /** @override */
28
32
  cloneNode(): this;
29
33
  /**
@@ -40,4 +44,3 @@ declare class MagicLinkToken extends Token {
40
44
  /** 是否是模板或魔术字参数 */
41
45
  isParamValue(): boolean;
42
46
  }
43
- export = MagicLinkToken;
@@ -1,17 +1,23 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MagicLinkToken = void 0;
2
4
  const lint_1 = require("../util/lint");
3
- const Parser = require("../index");
4
- const Token = require(".");
5
+ const index_1 = require("../index");
6
+ const _1 = require(".");
5
7
  /**
6
8
  * 自由外链
7
9
  * @classdesc `{childNodes: ...AstText|CommentToken|IncludeToken|NoincludeToken}`
8
10
  */
9
- class MagicLinkToken extends Token {
11
+ class MagicLinkToken extends _1.Token {
10
12
  #protocolRegex;
11
13
  /** 协议 */
12
14
  get protocol() {
13
15
  return this.#protocolRegex.exec(this.text())?.[0];
14
16
  }
17
+ /**
18
+ * @throws `RangeError` 非法协议
19
+ * @throws `Error` 特殊外链无法更改协议
20
+ */
15
21
  set protocol(value) {
16
22
  if (typeof value !== 'string') {
17
23
  this.typeError('protocol', 'String');
@@ -37,7 +43,7 @@ class MagicLinkToken extends Token {
37
43
  * @param url 网址
38
44
  * @param doubleSlash 是否接受"//"作为协议
39
45
  */
40
- constructor(url, doubleSlash, config = Parser.getConfig(), accum = []) {
46
+ constructor(url, doubleSlash, config = index_1.default.getConfig(), accum = []) {
41
47
  super(url, config, true, accum, {
42
48
  'Stage-1': ':', '!ExtToken': '',
43
49
  });
@@ -52,24 +58,23 @@ class MagicLinkToken extends Token {
52
58
  const errors = super.lint(start), source = `[,;。:!?()]+${this.type === 'ext-link-url' ? '|\\|+' : ''}`, regex = new RegExp(source, 'u'), regexGlobal = new RegExp(source, 'gu');
53
59
  let rect;
54
60
  for (const child of this.childNodes) {
55
- const str = String(child);
56
- if (child.type !== 'text' || !regex.test(str)) {
61
+ if (child.type !== 'text' || !regex.test(child.data)) {
57
62
  continue;
58
63
  }
59
64
  rect ??= { start, ...this.getRootNode().posFromIndex(start) };
60
- const refError = (0, lint_1.generateForChild)(child, rect, '', 'warning');
61
- errors.push(...[...str.matchAll(regexGlobal)].map(({ index, 0: s }) => {
62
- const lines = str.slice(0, index).split('\n'), { length: top } = lines, { length: left } = lines.at(-1), startIndex = start + index, startLine = refError.startLine + top - 1, startCol = (top > 1 ? 0 : refError.startCol) + left;
65
+ const { data } = child, refError = (0, lint_1.generateForChild)(child, rect, '', 'warning');
66
+ errors.push(...[...data.matchAll(regexGlobal)].map(({ index, 0: s }) => {
67
+ const lines = data.slice(0, index).split('\n'), { length: top } = lines, { length: left } = lines.at(-1), startIndex = start + index, startLine = refError.startLine + top - 1, startCol = top === 1 ? refError.startCol + left : left;
63
68
  return {
64
69
  ...refError,
65
- message: Parser.msg('$1 in URL', s.startsWith('|') ? '"|"' : Parser.msg('full-width punctuation')),
70
+ message: index_1.default.msg('$1 in URL', s.startsWith('|') ? '"|"' : index_1.default.msg('full-width punctuation')),
66
71
  startIndex,
67
72
  endIndex: startIndex + s.length,
68
73
  startLine,
69
74
  endLine: startLine,
70
75
  startCol,
71
76
  endCol: startCol + s.length,
72
- excerpt: str.slice(Math.max(0, index - 25), index + 25),
77
+ excerpt: data.slice(Math.max(0, index - 25), index + 25),
73
78
  };
74
79
  }));
75
80
  }
@@ -78,7 +83,7 @@ class MagicLinkToken extends Token {
78
83
  /** @override */
79
84
  cloneNode() {
80
85
  const cloned = this.cloneChildNodes();
81
- return Parser.run(() => {
86
+ return index_1.default.run(() => {
82
87
  const token = new MagicLinkToken(undefined, this.type === 'ext-link-url', this.getAttribute('config'));
83
88
  token.append(...cloned);
84
89
  token.afterBuild();
@@ -110,11 +115,11 @@ class MagicLinkToken extends Token {
110
115
  * @throws `SyntaxError` 非法的自由外链目标
111
116
  */
112
117
  setTarget(url) {
113
- const strUrl = String(url), root = Parser.parse(strUrl, this.getAttribute('include'), 9, this.getAttribute('config')), { length, firstChild: freeExtLink } = root;
114
- if (length !== 1 || freeExtLink.type !== 'free-ext-link') {
115
- throw new SyntaxError(`非法的自由外链目标:${strUrl}`);
118
+ const strUrl = String(url), root = index_1.default.parse(strUrl, this.getAttribute('include'), 9, this.getAttribute('config')), { length, firstChild: freeExtLink } = root;
119
+ if (length === 1 && freeExtLink.type === 'free-ext-link') {
120
+ this.replaceChildren(...freeExtLink.childNodes);
116
121
  }
117
- this.replaceChildren(...freeExtLink.childNodes);
122
+ throw new SyntaxError(`非法的自由外链目标:${strUrl}`);
118
123
  }
119
124
  /** 是否是模板或魔术字参数 */
120
125
  isParamValue() {
@@ -122,5 +127,5 @@ class MagicLinkToken extends Token {
122
127
  return parameter?.getValue() === this.text();
123
128
  }
124
129
  }
125
- Parser.classes['MagicLinkToken'] = __filename;
126
- module.exports = MagicLinkToken;
130
+ exports.MagicLinkToken = MagicLinkToken;
131
+ index_1.default.classes['MagicLinkToken'] = __filename;
@@ -1,14 +1,14 @@
1
- import * as Parser from '../index';
2
- import Token = require('.');
3
- import ExtToken = require('./tagPair/ext');
4
- import NoincludeToken = require('./nowiki/noinclude');
5
- import CommentToken = require('./nowiki/comment');
6
- import AttributesToken = require('./attributes');
1
+ import { Token } from '.';
2
+ import { ExtToken } from './tagPair/ext';
3
+ import { NoincludeToken } from './nowiki/noinclude';
4
+ import { CommentToken } from './nowiki/comment';
5
+ import type { LintError } from '../index';
6
+ import type { AttributesToken } from './attributes';
7
7
  /**
8
8
  * 嵌套式的扩展标签
9
9
  * @classdesc `{childNodes: ...ExtToken|NoincludeToken|CommentToken}`
10
10
  */
11
- declare abstract class NestedToken extends Token {
11
+ export declare abstract class NestedToken extends Token {
12
12
  #private;
13
13
  /** @browser */
14
14
  readonly type = "ext-inner";
@@ -29,19 +29,19 @@ declare abstract class NestedToken extends Token {
29
29
  * @param regex 内层正则
30
30
  * @param tags 内层标签名
31
31
  */
32
- constructor(wikitext: string | undefined, regex: RegExp, tags: string[], config?: Parser.Config, accum?: Token[]);
32
+ constructor(wikitext: string | undefined, regex: RegExp, tags: string[], config?: import("../index").Config, accum?: Token[]);
33
33
  /**
34
34
  * @override
35
35
  * @browser
36
36
  */
37
- lint(start?: number): Parser.LintError[];
37
+ lint(start?: number): LintError[];
38
38
  /**
39
39
  * @override
40
40
  * @param token 待插入的子节点
41
41
  * @param i 插入位置
42
+ * @throws `TypeError` 不是许可的标签
42
43
  */
43
44
  insertAt<T extends Token>(token: T, i?: number): T;
44
45
  /** @override */
45
46
  cloneNode(): this;
46
47
  }
47
- export = NestedToken;
@@ -1,15 +1,17 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NestedToken = void 0;
2
4
  const lint_1 = require("../util/lint");
3
- const Parser = require("../index");
4
- const Token = require(".");
5
- const ExtToken = require("./tagPair/ext");
6
- const NoincludeToken = require("./nowiki/noinclude");
7
- const CommentToken = require("./nowiki/comment");
5
+ const index_1 = require("../index");
6
+ const _1 = require(".");
7
+ const ext_1 = require("./tagPair/ext");
8
+ const noinclude_1 = require("./nowiki/noinclude");
9
+ const comment_1 = require("./nowiki/comment");
8
10
  /**
9
11
  * 嵌套式的扩展标签
10
12
  * @classdesc `{childNodes: ...ExtToken|NoincludeToken|CommentToken}`
11
13
  */
12
- class NestedToken extends Token {
14
+ class NestedToken extends _1.Token {
13
15
  /** @browser */
14
16
  type = 'ext-inner';
15
17
  #tags;
@@ -19,19 +21,22 @@ class NestedToken extends Token {
19
21
  * @param regex 内层正则
20
22
  * @param tags 内层标签名
21
23
  */
22
- constructor(wikitext, regex, tags, config = Parser.getConfig(), accum = []) {
24
+ constructor(wikitext, regex, tags, config = index_1.default.getConfig(), accum = []) {
23
25
  const text = wikitext?.replace(regex, (comment, name, attr, inner, closing) => {
24
26
  const str = `\0${accum.length + 1}${name ? 'e' : 'c'}\x7F`;
25
27
  if (name) {
26
- new ExtToken(name, attr, inner, closing, config, accum);
28
+ // @ts-expect-error abstract class
29
+ new ext_1.ExtToken(name, attr, inner, closing, config, accum);
27
30
  }
28
31
  else {
29
32
  const closed = comment.endsWith('-->');
30
- new CommentToken(comment.slice(4, closed ? -3 : undefined), closed, config, accum);
33
+ // @ts-expect-error abstract class
34
+ new comment_1.CommentToken(comment.slice(4, closed ? -3 : undefined), closed, config, accum);
31
35
  }
32
36
  return str;
33
37
  })?.replace(/(?<=^|\0\d+[ce]\x7F)[^\0]+(?=$|\0\d+[ce]\x7F)/gu, substr => {
34
- new NoincludeToken(substr, config, accum);
38
+ // @ts-expect-error abstract class
39
+ new noinclude_1.NoincludeToken(substr, config, accum);
35
40
  return `\0${accum.length}c\x7F`;
36
41
  });
37
42
  super(text, config, true, accum, {
@@ -56,7 +61,7 @@ class NestedToken extends Token {
56
61
  return str && !/^<!--.*-->$/su.test(str);
57
62
  }).map(child => {
58
63
  rect ??= { start, ...this.getRootNode().posFromIndex(start) };
59
- return (0, lint_1.generateForChild)(child, rect, Parser.msg('invalid content in <$1>', this.name));
64
+ return (0, lint_1.generateForChild)(child, rect, index_1.default.msg('invalid content in <$1>', this.name));
60
65
  }),
61
66
  ];
62
67
  }
@@ -64,21 +69,24 @@ class NestedToken extends Token {
64
69
  * @override
65
70
  * @param token 待插入的子节点
66
71
  * @param i 插入位置
72
+ * @throws `TypeError` 不是许可的标签
67
73
  */
68
74
  insertAt(token, i = this.length) {
69
- return typeof token !== 'string' && token.type === 'ext' && !this.#tags.includes(token.name)
70
- ? this.typeError(`${this.constructor.name}只能以${this.#tags.join('或')}标签作为子节点!`)
71
- : super.insertAt(token, i);
75
+ if (typeof token !== 'string' && token.type === 'ext' && !this.#tags.includes(token.name)) {
76
+ throw new TypeError(`${this.constructor.name}只能以${this.#tags.join('或')}标签作为子节点!`);
77
+ }
78
+ return super.insertAt(token, i);
72
79
  }
73
80
  /** @override */
74
81
  cloneNode() {
75
82
  const cloned = this.cloneChildNodes(), config = this.getAttribute('config');
76
- return Parser.run(() => {
83
+ return index_1.default.run(() => {
84
+ // @ts-expect-error abstract class
77
85
  const token = new NestedToken(undefined, this.#regex, this.#tags, config);
78
86
  token.append(...cloned);
79
87
  return token;
80
88
  });
81
89
  }
82
90
  }
83
- Parser.classes['NestedToken'] = __filename;
84
- module.exports = NestedToken;
91
+ exports.NestedToken = NestedToken;
92
+ index_1.default.classes['NestedToken'] = __filename;
@@ -1,11 +1,10 @@
1
- import * as Parser from '../../index';
2
- import Token = require('..');
3
- import AstText = require('../../lib/text');
1
+ import { Token } from '..';
2
+ import type { AstText } from '../../lib/text';
4
3
  declare type NowikiTypes = 'ext-inner' | 'comment' | 'dd' | 'double-underscore' | 'hr' | 'list' | 'noinclude' | 'quote';
5
4
  declare const NowikiBaseToken_base: ((abstract new (...args: any[]) => {
6
5
  removeAt(): never;
7
6
  insertAt(token: string, i?: number | undefined): AstText;
8
- insertAt<T extends import("../../lib/node").AstNodeTypes>(token: T, i?: number | undefined): T;
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 NowikiBaseToken_base: ((abstract new (...args: any[]) => {
16
15
  * 纯文字Token,不会被解析
17
16
  * @classdesc `{childNodes: [AstText]}`
18
17
  */
19
- declare abstract class NowikiBaseToken extends NowikiBaseToken_base {
18
+ export declare abstract class NowikiBaseToken extends NowikiBaseToken_base {
20
19
  type: NowikiTypes;
21
20
  childNodes: [AstText];
22
21
  abstract get children(): [];
@@ -25,10 +24,10 @@ declare abstract class NowikiBaseToken extends NowikiBaseToken_base {
25
24
  abstract get lastChild(): AstText;
26
25
  abstract get lastElementChild(): undefined;
27
26
  /** @browser */
28
- constructor(wikitext: string, config?: Parser.Config, accum?: Token[]);
27
+ constructor(wikitext: string, config?: import("../../index").Config, accum?: Token[]);
29
28
  /** @override */
30
29
  cloneNode(this: this & {
31
- constructor: new (...args: unknown[]) => unknown;
30
+ constructor: new (...args: any[]) => unknown;
32
31
  }): this;
33
32
  /**
34
33
  * @override
@@ -36,4 +35,4 @@ declare abstract class NowikiBaseToken extends NowikiBaseToken_base {
36
35
  */
37
36
  setText(str: string): string;
38
37
  }
39
- export = NowikiBaseToken;
38
+ export {};
@@ -1,19 +1,21 @@
1
1
  "use strict";
2
- const fixed = require("../../mixin/fixed");
3
- const Parser = require("../../index");
4
- const Token = require("..");
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NowikiBaseToken = void 0;
4
+ const fixed_1 = require("../../mixin/fixed");
5
+ const index_1 = require("../../index");
6
+ const __1 = require("..");
5
7
  /**
6
8
  * 纯文字Token,不会被解析
7
9
  * @classdesc `{childNodes: [AstText]}`
8
10
  */
9
- class NowikiBaseToken extends fixed(Token) {
11
+ class NowikiBaseToken extends (0, fixed_1.fixed)(__1.Token) {
10
12
  /** @browser */
11
- constructor(wikitext, config = Parser.getConfig(), accum = []) {
13
+ constructor(wikitext, config = index_1.default.getConfig(), accum = []) {
12
14
  super(wikitext, config, true, accum);
13
15
  }
14
16
  /** @override */
15
17
  cloneNode() {
16
- const { constructor, firstChild: { data }, type } = this, token = Parser.run(() => new constructor(data, this.getAttribute('config')));
18
+ const { constructor, firstChild: { data }, type } = this, token = index_1.default.run(() => new constructor(data, this.getAttribute('config')));
17
19
  token.type = type;
18
20
  return token;
19
21
  }
@@ -25,5 +27,5 @@ class NowikiBaseToken extends fixed(Token) {
25
27
  return super.setText(str, 0);
26
28
  }
27
29
  }
28
- Parser.classes['NowikiBaseToken'] = __filename;
29
- module.exports = NowikiBaseToken;
30
+ exports.NowikiBaseToken = NowikiBaseToken;
31
+ index_1.default.classes['NowikiBaseToken'] = __filename;
@@ -1,6 +1,6 @@
1
- import * as Parser from '../../index';
2
- import Token = require('..');
3
- import NowikiBaseToken = require('./base');
1
+ import { NowikiBaseToken } from './base';
2
+ import type { LintError } from '../../index';
3
+ import type { Token } from '..';
4
4
  declare const CommentToken_base: ((abstract new (...args: any[]) => {
5
5
  text(): string;
6
6
  length: number;
@@ -10,7 +10,7 @@ declare const CommentToken_base: ((abstract new (...args: any[]) => {
10
10
  readonly hidden: true;
11
11
  }) & typeof NowikiBaseToken;
12
12
  /** HTML注释,不可见 */
13
- declare abstract class CommentToken extends CommentToken_base {
13
+ export declare abstract class CommentToken extends CommentToken_base {
14
14
  /** @browser */
15
15
  readonly type = "comment";
16
16
  closed: boolean;
@@ -20,7 +20,7 @@ declare abstract class CommentToken extends CommentToken_base {
20
20
  * @browser
21
21
  * @param closed 是否闭合
22
22
  */
23
- constructor(wikitext: string, closed?: boolean, config?: Parser.Config, accum?: Token[]);
23
+ constructor(wikitext: string, closed?: boolean, config?: import("../../index").Config, accum?: Token[]);
24
24
  /**
25
25
  * @override
26
26
  * @browser
@@ -30,7 +30,7 @@ declare abstract class CommentToken extends CommentToken_base {
30
30
  * @override
31
31
  * @browser
32
32
  */
33
- lint(start?: number): Parser.LintError[];
33
+ lint(start?: number): LintError[];
34
34
  /**
35
35
  * @override
36
36
  * @browser
@@ -39,4 +39,4 @@ declare abstract class CommentToken extends CommentToken_base {
39
39
  /** @override */
40
40
  cloneNode(): this;
41
41
  }
42
- export = CommentToken;
42
+ export {};
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
- const hidden = require("../../mixin/hidden");
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommentToken = void 0;
3
4
  const lint_1 = require("../../util/lint");
4
- const Parser = require("../../index");
5
- const NowikiBaseToken = require("./base");
5
+ const hidden_1 = require("../../mixin/hidden");
6
+ const index_1 = require("../../index");
7
+ const base_1 = require("./base");
6
8
  /** HTML注释,不可见 */
7
- class CommentToken extends hidden(NowikiBaseToken) {
9
+ class CommentToken extends (0, hidden_1.hidden)(base_1.NowikiBaseToken) {
8
10
  /** @browser */
9
11
  type = 'comment';
10
12
  closed;
@@ -16,7 +18,7 @@ class CommentToken extends hidden(NowikiBaseToken) {
16
18
  * @browser
17
19
  * @param closed 是否闭合
18
20
  */
19
- constructor(wikitext, closed = true, config = Parser.getConfig(), accum = []) {
21
+ constructor(wikitext, closed = true, config = index_1.default.getConfig(), accum = []) {
20
22
  super(wikitext, config, accum);
21
23
  this.closed = closed;
22
24
  Object.defineProperty(this, 'closed', { enumerable: false });
@@ -45,7 +47,7 @@ class CommentToken extends hidden(NowikiBaseToken) {
45
47
  */
46
48
  toString(selector) {
47
49
  if (!this.closed && this.nextSibling) {
48
- Parser.error('自动闭合HTML注释', this);
50
+ index_1.default.error('自动闭合HTML注释', this);
49
51
  this.closed = true;
50
52
  }
51
53
  return selector && this.matches(selector)
@@ -54,8 +56,9 @@ class CommentToken extends hidden(NowikiBaseToken) {
54
56
  }
55
57
  /** @override */
56
58
  cloneNode() {
57
- return Parser.run(() => new CommentToken(this.firstChild.data, this.closed, this.getAttribute('config')));
59
+ // @ts-expect-error abstract class
60
+ return index_1.default.run(() => new CommentToken(this.firstChild.data, this.closed, this.getAttribute('config')));
58
61
  }
59
62
  }
60
- Parser.classes['CommentToken'] = __filename;
61
- module.exports = CommentToken;
63
+ exports.CommentToken = CommentToken;
64
+ index_1.default.classes['CommentToken'] = __filename;
@@ -1,6 +1,6 @@
1
- import NowikiBaseToken = require('./base');
1
+ import { NowikiBaseToken } from './base';
2
2
  /** `:` */
3
- declare abstract class DdToken extends NowikiBaseToken {
3
+ export declare abstract class DdToken extends NowikiBaseToken {
4
4
  /** @browser */
5
5
  readonly type: 'dd' | 'list';
6
6
  /** 是否包含`;` */
@@ -20,4 +20,3 @@ declare abstract class DdToken extends NowikiBaseToken {
20
20
  */
21
21
  setText(str: string): string;
22
22
  }
23
- export = DdToken;
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
- const Parser = require("../../index");
3
- const NowikiBaseToken = require("./base");
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DdToken = void 0;
4
+ const index_1 = require("../../index");
5
+ const base_1 = require("./base");
4
6
  /** `:` */
5
- class DdToken extends NowikiBaseToken {
7
+ class DdToken extends base_1.NowikiBaseToken {
6
8
  /** @browser */
7
9
  type = 'dd';
8
10
  /** 是否包含`;` */
@@ -24,12 +26,6 @@ class DdToken extends NowikiBaseToken {
24
26
  /** @throws `RangeError` indent不是自然数 */
25
27
  set indent(indent) {
26
28
  if (this.type === 'dd') {
27
- if (!Number.isInteger(indent)) {
28
- this.typeError('indent setter', 'Number');
29
- }
30
- else if (indent < 0) {
31
- throw new RangeError('indent 应为自然数!');
32
- }
33
29
  this.setText(':'.repeat(indent));
34
30
  }
35
31
  }
@@ -46,5 +42,5 @@ class DdToken extends NowikiBaseToken {
46
42
  return super.setText(str);
47
43
  }
48
44
  }
49
- Parser.classes['DdToken'] = __filename;
50
- module.exports = DdToken;
45
+ exports.DdToken = DdToken;
46
+ index_1.default.classes['DdToken'] = __filename;
@@ -1,8 +1,6 @@
1
- import * as Parser from '../../index';
2
- import NowikiBaseToken = require('./base');
3
- import Token = require('..');
1
+ import { NowikiBaseToken } from './base';
2
+ import type { Token } from '..';
4
3
  declare const DoubleUnderscoreToken_base: ((abstract new (...args: any[]) => {
5
- text(): string;
6
4
  length: number;
7
5
  toString(selector?: string | undefined, separator?: string | undefined): string;
8
6
  insertAt(token: unknown, i?: number | undefined): unknown;
@@ -10,7 +8,7 @@ declare const DoubleUnderscoreToken_base: ((abstract new (...args: any[]) => {
10
8
  readonly hidden: true;
11
9
  }) & typeof NowikiBaseToken;
12
10
  /** 状态开关 */
13
- declare abstract class DoubleUnderscoreToken extends DoubleUnderscoreToken_base {
11
+ export declare abstract class DoubleUnderscoreToken extends DoubleUnderscoreToken_base {
14
12
  /** @browser */
15
13
  readonly type = "double-underscore";
16
14
  name: string;
@@ -25,7 +23,7 @@ declare abstract class DoubleUnderscoreToken extends DoubleUnderscoreToken_base
25
23
  */
26
24
  toString(selector?: string): string;
27
25
  /** @param word 状态开关名 */
28
- constructor(word: string, config?: Parser.Config, accum?: Token[]);
26
+ constructor(word: string, config?: import("../../index").Config, accum?: Token[]);
29
27
  /** @override */
30
28
  cloneNode(): this;
31
29
  /**
@@ -34,4 +32,4 @@ declare abstract class DoubleUnderscoreToken extends DoubleUnderscoreToken_base
34
32
  */
35
33
  setText(): never;
36
34
  }
37
- export = DoubleUnderscoreToken;
35
+ 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.DoubleUnderscoreToken = void 0;
4
+ const hidden_1 = require("../../mixin/hidden");
5
+ const index_1 = require("../../index");
6
+ const base_1 = require("./base");
5
7
  /** 状态开关 */
6
- class DoubleUnderscoreToken extends hidden(NowikiBaseToken) {
8
+ class DoubleUnderscoreToken extends (0, hidden_1.hidden)(base_1.NowikiBaseToken) {
7
9
  /** @browser */
8
10
  type = 'double-underscore';
9
11
  /** @private */
@@ -25,13 +27,14 @@ class DoubleUnderscoreToken extends hidden(NowikiBaseToken) {
25
27
  return selector && this.matches(selector) ? '' : `__${this.firstChild.data}__`;
26
28
  }
27
29
  /** @param word 状态开关名 */
28
- constructor(word, config = Parser.getConfig(), accum = []) {
30
+ constructor(word, config = index_1.default.getConfig(), accum = []) {
29
31
  super(word, config, accum);
30
32
  this.setAttribute('name', word.toLowerCase());
31
33
  }
32
34
  /** @override */
33
35
  cloneNode() {
34
- return Parser.run(() => new DoubleUnderscoreToken(this.firstChild.data, this.getAttribute('config')));
36
+ // @ts-expect-error abstract class
37
+ return index_1.default.run(() => new DoubleUnderscoreToken(this.firstChild.data, this.getAttribute('config')));
35
38
  }
36
39
  /**
37
40
  * @override
@@ -41,5 +44,5 @@ class DoubleUnderscoreToken extends hidden(NowikiBaseToken) {
41
44
  throw new Error(`禁止修改 ${this.constructor.name}!`);
42
45
  }
43
46
  }
44
- Parser.classes['DoubleUnderscoreToken'] = __filename;
45
- module.exports = DoubleUnderscoreToken;
47
+ exports.DoubleUnderscoreToken = DoubleUnderscoreToken;
48
+ index_1.default.classes['DoubleUnderscoreToken'] = __filename;
@@ -1,8 +1,7 @@
1
- import * as Parser from '../../index';
2
- import NowikiBaseToken = require('./base');
3
- import Token = require('..');
1
+ import { NowikiBaseToken } from './base';
2
+ import type { Token } from '..';
4
3
  declare const HrToken_base: (abstract new (...args: any[]) => {
5
- "__#14@#isRoot"(): boolean;
4
+ "__#7@#isRoot"(): boolean;
6
5
  prependNewLine(): string;
7
6
  toString(selector?: string | undefined): string;
8
7
  getPadding(): number;
@@ -11,14 +10,14 @@ declare const HrToken_base: (abstract new (...args: any[]) => {
11
10
  insertAt(token: unknown, i?: number | undefined): unknown;
12
11
  }) & typeof NowikiBaseToken;
13
12
  /** `<hr>` */
14
- declare abstract class HrToken extends HrToken_base {
13
+ export declare abstract class HrToken extends HrToken_base {
15
14
  /** @browser */
16
15
  readonly type = "hr";
17
16
  /**
18
17
  * @browser
19
18
  * @param n 字符串长度
20
19
  */
21
- constructor(n: number, config?: Parser.Config, accum?: Token[]);
20
+ constructor(n: number, config?: import("../../index").Config, accum?: Token[]);
22
21
  /** @override */
23
22
  cloneNode(): this;
24
23
  /**
@@ -28,4 +27,4 @@ declare abstract class HrToken extends HrToken_base {
28
27
  */
29
28
  setText(str: string): string;
30
29
  }
31
- export = HrToken;
30
+ export {};
@@ -1,21 +1,24 @@
1
1
  "use strict";
2
- const sol = require("../../mixin/sol");
3
- const Parser = require("../../index");
4
- const NowikiBaseToken = require("./base");
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HrToken = void 0;
4
+ const sol_1 = require("../../mixin/sol");
5
+ const index_1 = require("../../index");
6
+ const base_1 = require("./base");
5
7
  /** `<hr>` */
6
- class HrToken extends sol(NowikiBaseToken) {
8
+ class HrToken extends (0, sol_1.sol)(base_1.NowikiBaseToken) {
7
9
  /** @browser */
8
10
  type = 'hr';
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
  }
16
18
  /** @override */
17
19
  cloneNode() {
18
- return Parser.run(() => new HrToken(this.firstChild.data.length, this.getAttribute('config')));
20
+ // @ts-expect-error abstract class
21
+ return index_1.default.run(() => new HrToken(this.firstChild.data.length, this.getAttribute('config')));
19
22
  }
20
23
  /**
21
24
  * @override
@@ -29,5 +32,5 @@ class HrToken extends sol(NowikiBaseToken) {
29
32
  return super.setText(str);
30
33
  }
31
34
  }
32
- Parser.classes['HrToken'] = __filename;
33
- module.exports = HrToken;
35
+ exports.HrToken = HrToken;
36
+ index_1.default.classes['HrToken'] = __filename;