wikiparser-node 1.9.2-b → 1.9.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 (173) hide show
  1. package/README.md +18 -18
  2. package/config/.schema.json +181 -0
  3. package/config/enwiki.json +814 -1
  4. package/config/llwiki.json +35 -1
  5. package/config/moegirl.json +44 -1
  6. package/config/zhwiki.json +466 -1
  7. package/dist/addon/table.js +486 -0
  8. package/dist/addon/token.js +240 -0
  9. package/dist/addon/transclude.js +185 -0
  10. package/dist/base.d.ts +73 -0
  11. package/dist/base.js +39 -0
  12. package/dist/index.d.ts +31 -0
  13. package/dist/index.js +232 -0
  14. package/dist/internal.d.ts +46 -0
  15. package/dist/lib/element.d.ts +124 -0
  16. package/dist/lib/element.js +600 -0
  17. package/dist/lib/node.d.ts +166 -0
  18. package/dist/lib/node.js +472 -0
  19. package/dist/lib/range.d.ts +105 -0
  20. package/dist/lib/range.js +406 -0
  21. package/dist/lib/ranges.d.ts +28 -0
  22. package/dist/lib/ranges.js +126 -0
  23. package/dist/lib/rect.d.ts +18 -0
  24. package/dist/lib/rect.js +34 -0
  25. package/dist/lib/text.d.ts +54 -0
  26. package/dist/lib/text.js +345 -0
  27. package/dist/lib/title.d.ts +40 -0
  28. package/dist/lib/title.js +197 -0
  29. package/dist/mixin/attributesParent.d.ts +49 -0
  30. package/dist/mixin/attributesParent.js +82 -0
  31. package/dist/mixin/fixed.d.ts +5 -0
  32. package/dist/mixin/fixed.js +32 -0
  33. package/dist/mixin/flagsParent.d.ts +41 -0
  34. package/dist/mixin/flagsParent.js +60 -0
  35. package/dist/mixin/hidden.d.ts +6 -0
  36. package/dist/mixin/hidden.js +29 -0
  37. package/dist/mixin/magicLinkParent.d.ts +19 -0
  38. package/dist/mixin/magicLinkParent.js +43 -0
  39. package/dist/mixin/singleLine.d.ts +5 -0
  40. package/dist/mixin/singleLine.js +27 -0
  41. package/dist/mixin/sol.d.ts +5 -0
  42. package/dist/mixin/sol.js +44 -0
  43. package/dist/mixin/syntax.d.ts +8 -0
  44. package/dist/mixin/syntax.js +47 -0
  45. package/dist/parser/braces.js +150 -0
  46. package/dist/parser/commentAndExt.js +79 -0
  47. package/dist/parser/converter.js +39 -0
  48. package/dist/parser/externalLinks.js +37 -0
  49. package/dist/parser/hrAndDoubleUnderscore.js +42 -0
  50. package/dist/parser/html.js +38 -0
  51. package/dist/parser/links.js +101 -0
  52. package/dist/parser/list.js +97 -0
  53. package/dist/parser/magicLinks.js +53 -0
  54. package/dist/parser/quotes.js +67 -0
  55. package/dist/parser/redirect.js +26 -0
  56. package/dist/parser/selector.js +190 -0
  57. package/dist/parser/table.js +123 -0
  58. package/dist/src/arg.d.ts +52 -0
  59. package/dist/src/arg.js +213 -0
  60. package/dist/src/atom.d.ts +12 -0
  61. package/dist/src/atom.js +26 -0
  62. package/dist/src/attribute.d.ts +65 -0
  63. package/dist/src/attribute.js +483 -0
  64. package/dist/src/attributes.d.ts +103 -0
  65. package/dist/src/attributes.js +350 -0
  66. package/dist/src/converter.d.ts +29 -0
  67. package/dist/src/converter.js +134 -0
  68. package/dist/src/converterFlags.d.ts +81 -0
  69. package/dist/src/converterFlags.js +239 -0
  70. package/dist/src/converterRule.d.ts +73 -0
  71. package/dist/src/converterRule.js +210 -0
  72. package/dist/src/extLink.d.ts +37 -0
  73. package/dist/src/extLink.js +191 -0
  74. package/dist/src/gallery.d.ts +48 -0
  75. package/dist/src/gallery.js +139 -0
  76. package/dist/src/heading.d.ts +41 -0
  77. package/dist/src/heading.js +185 -0
  78. package/dist/src/hidden.d.ts +10 -0
  79. package/dist/src/hidden.js +79 -0
  80. package/dist/src/html.d.ts +58 -0
  81. package/dist/src/html.js +334 -0
  82. package/dist/src/imageParameter.d.ts +59 -0
  83. package/dist/src/imageParameter.js +246 -0
  84. package/dist/src/imagemap.d.ts +48 -0
  85. package/dist/src/imagemap.js +145 -0
  86. package/dist/src/imagemapLink.d.ts +31 -0
  87. package/dist/src/imagemapLink.js +93 -0
  88. package/dist/src/index.d.ts +130 -0
  89. package/dist/src/index.js +721 -0
  90. package/dist/src/link/base.d.ts +46 -0
  91. package/dist/src/link/base.js +224 -0
  92. package/dist/src/link/category.d.ts +22 -0
  93. package/dist/src/link/category.js +30 -0
  94. package/dist/src/link/file.d.ts +96 -0
  95. package/dist/src/link/file.js +274 -0
  96. package/dist/src/link/galleryImage.d.ts +30 -0
  97. package/dist/src/link/galleryImage.js +158 -0
  98. package/dist/src/link/index.d.ts +52 -0
  99. package/dist/src/link/index.js +133 -0
  100. package/dist/src/link/redirectTarget.d.ts +37 -0
  101. package/dist/src/link/redirectTarget.js +95 -0
  102. package/dist/src/magicLink.d.ts +60 -0
  103. package/dist/src/magicLink.js +270 -0
  104. package/dist/src/nested.d.ts +41 -0
  105. package/dist/src/nested.js +105 -0
  106. package/dist/src/nowiki/base.d.ts +31 -0
  107. package/dist/src/nowiki/base.js +91 -0
  108. package/dist/src/nowiki/comment.d.ts +15 -0
  109. package/dist/src/nowiki/comment.js +123 -0
  110. package/dist/src/nowiki/dd.d.ts +8 -0
  111. package/dist/src/nowiki/dd.js +24 -0
  112. package/dist/src/nowiki/doubleUnderscore.d.ts +16 -0
  113. package/dist/src/nowiki/doubleUnderscore.js +96 -0
  114. package/dist/src/nowiki/hr.d.ts +5 -0
  115. package/dist/src/nowiki/hr.js +63 -0
  116. package/dist/src/nowiki/index.d.ts +14 -0
  117. package/dist/src/nowiki/index.js +29 -0
  118. package/dist/src/nowiki/list.d.ts +16 -0
  119. package/dist/src/nowiki/list.js +109 -0
  120. package/dist/src/nowiki/listBase.d.ts +5 -0
  121. package/dist/src/nowiki/listBase.js +61 -0
  122. package/dist/src/nowiki/noinclude.d.ts +10 -0
  123. package/dist/src/nowiki/noinclude.js +73 -0
  124. package/dist/src/nowiki/quote.d.ts +17 -0
  125. package/dist/src/nowiki/quote.js +131 -0
  126. package/dist/src/onlyinclude.d.ts +14 -0
  127. package/dist/src/onlyinclude.js +57 -0
  128. package/dist/src/paramTag/index.d.ts +31 -0
  129. package/dist/src/paramTag/index.js +77 -0
  130. package/dist/src/paramTag/inputbox.d.ts +8 -0
  131. package/dist/src/paramTag/inputbox.js +22 -0
  132. package/dist/src/parameter.d.ts +66 -0
  133. package/dist/src/parameter.js +265 -0
  134. package/dist/src/pre.d.ts +29 -0
  135. package/dist/src/pre.js +59 -0
  136. package/dist/src/redirect.d.ts +31 -0
  137. package/dist/src/redirect.js +121 -0
  138. package/dist/src/syntax.d.ts +17 -0
  139. package/dist/src/syntax.js +84 -0
  140. package/dist/src/table/base.d.ts +29 -0
  141. package/dist/src/table/base.js +82 -0
  142. package/dist/src/table/index.d.ts +239 -0
  143. package/dist/src/table/index.js +502 -0
  144. package/dist/src/table/td.d.ts +78 -0
  145. package/dist/src/table/td.js +368 -0
  146. package/dist/src/table/tr.d.ts +30 -0
  147. package/dist/src/table/tr.js +57 -0
  148. package/dist/src/table/trBase.d.ts +49 -0
  149. package/dist/src/table/trBase.js +156 -0
  150. package/dist/src/tagPair/ext.d.ts +30 -0
  151. package/dist/src/tagPair/ext.js +201 -0
  152. package/dist/src/tagPair/include.d.ts +35 -0
  153. package/dist/src/tagPair/include.js +124 -0
  154. package/dist/src/tagPair/index.d.ts +23 -0
  155. package/dist/src/tagPair/index.js +128 -0
  156. package/dist/src/transclude.d.ts +160 -0
  157. package/dist/src/transclude.js +579 -0
  158. package/dist/util/constants.js +25 -0
  159. package/dist/util/debug.js +97 -0
  160. package/dist/util/diff.js +83 -0
  161. package/dist/util/lint.js +32 -0
  162. package/dist/util/string.js +60 -0
  163. package/errors/README +1 -0
  164. package/package.json +20 -30
  165. package/printed/README +1 -0
  166. package/README.en.md +0 -57
  167. package/bundle/bundle.min.js +0 -38
  168. package/extensions/dist/base.js +0 -64
  169. package/extensions/dist/editor.js +0 -159
  170. package/extensions/dist/highlight.js +0 -58
  171. package/extensions/dist/lint.js +0 -72
  172. package/extensions/editor.css +0 -64
  173. package/extensions/ui.css +0 -144
@@ -0,0 +1,239 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConverterFlagsToken = void 0;
4
+ const lint_1 = require("../util/lint");
5
+ const rect_1 = require("../lib/rect");
6
+ const debug_1 = require("../util/debug");
7
+ const constants_1 = require("../util/constants");
8
+ const index_1 = require("../index");
9
+ const index_2 = require("./index");
10
+ const atom_1 = require("./atom");
11
+ const definedFlags = new Set(['A', 'T', 'R', 'D', '-', 'H', 'N']);
12
+ /**
13
+ * 转换flags
14
+ * @classdesc `{childNodes: ...AtomToken}`
15
+ */
16
+ class ConverterFlagsToken extends index_2.Token {
17
+ type = 'converter-flags';
18
+ #flags;
19
+ /** 所有转换类型标记 */
20
+ get flags() {
21
+ return this.getAllFlags();
22
+ }
23
+ set flags(value) {
24
+ this.replaceChildren();
25
+ for (const flag of value) {
26
+ this.#newFlag(flag);
27
+ }
28
+ }
29
+ /* NOT FOR BROWSER END */
30
+ /** @param flags 转换类型标记 */
31
+ constructor(flags, config = index_1.default.getConfig(), accum = []) {
32
+ super(undefined, config, accum, {
33
+ AtomToken: ':',
34
+ });
35
+ this.append(...flags.map(flag => new atom_1.AtomToken(flag, 'converter-flag', config, accum)));
36
+ }
37
+ /** @private */
38
+ afterBuild() {
39
+ this.#flags = this.childNodes.map(child => child.text().trim());
40
+ super.afterBuild();
41
+ /* NOT FOR BROWSER */
42
+ const /** @implements */ converterFlagsListener = ({ prevTarget }) => {
43
+ if (prevTarget) {
44
+ this.#flags[this.childNodes.indexOf(prevTarget)] = prevTarget.text().trim();
45
+ }
46
+ };
47
+ this.addEventListener(['remove', 'insert', 'text', 'replace'], converterFlagsListener);
48
+ }
49
+ /** @private */
50
+ toString() {
51
+ return super.toString(';');
52
+ }
53
+ /** @private */
54
+ text() {
55
+ return super.text(';');
56
+ }
57
+ /** @private */
58
+ getGaps() {
59
+ return 1;
60
+ }
61
+ /** 获取未知的转换类型标记 */
62
+ getUnknownFlags() {
63
+ return new Set(this.#flags.filter(flag => /\{{3}[^{}]+\}{3}/u.test(flag)));
64
+ }
65
+ /** 获取指定语言变体的转换标记 */
66
+ getVariantFlags() {
67
+ const variants = new Set(this.getAttribute('config').variants);
68
+ return new Set(this.#flags.filter(flag => variants.has(flag)));
69
+ }
70
+ /** @private */
71
+ lint(start = this.getAbsoluteIndex(), re) {
72
+ const variantFlags = this.getVariantFlags(), unknownFlags = this.getUnknownFlags(), validFlags = new Set(this.#flags.filter(flag => definedFlags.has(flag))), emptyFlagCount = this.#flags.filter(flag => !flag).length, knownFlagCount = this.#flags.length - unknownFlags.size - emptyFlagCount, errors = super.lint(start, re);
73
+ if (variantFlags.size === knownFlagCount || validFlags.size === knownFlagCount) {
74
+ return errors;
75
+ }
76
+ const rect = new rect_1.BoundingRect(this, start), { childNodes, length } = this;
77
+ for (let i = 0; i < length; i++) {
78
+ const child = childNodes[i], flag = child.text().trim();
79
+ if (flag
80
+ && !variantFlags.has(flag)
81
+ && !unknownFlags.has(flag)
82
+ && (variantFlags.size > 0 || !validFlags.has(flag))) {
83
+ const e = (0, lint_1.generateForChild)(child, rect, 'no-ignored', 'invalid conversion flag');
84
+ if (variantFlags.size === 0 && definedFlags.has(flag.toUpperCase())) {
85
+ e.fix = {
86
+ range: [e.startIndex, e.endIndex],
87
+ text: flag.toUpperCase(),
88
+ };
89
+ }
90
+ else {
91
+ e.suggestions = [
92
+ {
93
+ desc: 'remove',
94
+ range: [e.startIndex, e.endIndex],
95
+ text: '',
96
+ },
97
+ ];
98
+ }
99
+ errors.push(e);
100
+ }
101
+ }
102
+ return errors;
103
+ }
104
+ /** @private */
105
+ print() {
106
+ return super.print({ sep: ';' });
107
+ }
108
+ /* NOT FOR BROWSER */
109
+ /** @override */
110
+ cloneNode() {
111
+ const cloned = this.cloneChildNodes();
112
+ return debug_1.Shadow.run(() => {
113
+ // @ts-expect-error abstract class
114
+ const token = new ConverterFlagsToken([], this.getAttribute('config'));
115
+ token.append(...cloned);
116
+ return token;
117
+ });
118
+ }
119
+ /**
120
+ * @override
121
+ * @param i 移除位置
122
+ */
123
+ removeAt(i) {
124
+ const token = super.removeAt(i);
125
+ this.#flags?.splice(i, 1);
126
+ return token;
127
+ }
128
+ /**
129
+ * @override
130
+ * @param token 待插入的子节点
131
+ * @param i 插入位置
132
+ */
133
+ insertAt(token, i = this.length) {
134
+ super.insertAt(token, i);
135
+ this.#flags?.splice(i, 0, token.text().trim());
136
+ return token;
137
+ }
138
+ /** 获取所有转换类型标记 */
139
+ getAllFlags() {
140
+ return new Set(this.#flags);
141
+ }
142
+ /**
143
+ * 获取转换类型标记节点
144
+ * @param flag 转换类型标记
145
+ */
146
+ getFlagTokens(flag) {
147
+ return this.#flags.includes(flag) ? this.childNodes.filter(child => child.text().trim() === flag) : [];
148
+ }
149
+ /** 获取有效的转换类型标记 */
150
+ getEffectiveFlags() {
151
+ const variantFlags = this.getVariantFlags(), unknownFlags = this.getUnknownFlags();
152
+ if (variantFlags.size > 0) {
153
+ return new Set([...variantFlags, ...unknownFlags]);
154
+ }
155
+ const flags = new Set([...this.#flags.filter(flag => definedFlags.has(flag)), ...unknownFlags]);
156
+ if (flags.size === 0) {
157
+ return new Set('S');
158
+ }
159
+ else if (flags.has('R')) {
160
+ return new Set('R');
161
+ }
162
+ else if (flags.has('N')) {
163
+ return new Set('N');
164
+ }
165
+ else if (flags.has('-')) {
166
+ return new Set('-');
167
+ }
168
+ else if (flags.has('H')) {
169
+ const hasT = flags.has('T'), hasD = flags.has('D');
170
+ return hasT && hasD
171
+ ? new Set(['+', 'H', 'T', 'D'])
172
+ : new Set(['+', 'H', ...hasT ? ['T'] : [], ...hasD ? ['D'] : [], ...unknownFlags]);
173
+ }
174
+ if (flags.size === 1 && flags.has('T')) {
175
+ flags.add('H');
176
+ }
177
+ if (flags.has('A')) {
178
+ flags.add('+');
179
+ flags.add('S');
180
+ }
181
+ if (flags.has('D')) {
182
+ flags.delete('S');
183
+ }
184
+ return flags;
185
+ }
186
+ /**
187
+ * 是否具有某转换类型标记
188
+ * @param flag 转换类型标记
189
+ */
190
+ hasFlag(flag) {
191
+ return this.#flags.includes(flag);
192
+ }
193
+ /**
194
+ * 是否具有某有效的转换类型标记
195
+ * @param flag 转换类型标记
196
+ */
197
+ hasEffectiveFlag(flag) {
198
+ return this.getEffectiveFlags().has(flag);
199
+ }
200
+ /**
201
+ * 移除某转换类型标记
202
+ * @param flag 转换类型标记
203
+ */
204
+ removeFlag(flag) {
205
+ for (const token of this.getFlagTokens(flag)) {
206
+ token.remove();
207
+ }
208
+ }
209
+ /**
210
+ * 添加转换类型标记
211
+ * @param flag 转换类型标记
212
+ */
213
+ #newFlag(flag) {
214
+ this.insertAt(debug_1.Shadow.run(() => new atom_1.AtomToken(flag, 'converter-flag', this.getAttribute('config'))));
215
+ }
216
+ /**
217
+ * 设置转换类型标记
218
+ * @param flag 转换类型标记
219
+ */
220
+ setFlag(flag) {
221
+ if (!this.#flags.includes(flag)) {
222
+ this.#newFlag(flag);
223
+ }
224
+ }
225
+ /**
226
+ * 开关转换类型标记
227
+ * @param flag 转换类型标记
228
+ */
229
+ toggleFlag(flag) {
230
+ if (this.#flags.includes(flag)) {
231
+ this.removeFlag(flag);
232
+ }
233
+ else {
234
+ this.#newFlag(flag);
235
+ }
236
+ }
237
+ }
238
+ exports.ConverterFlagsToken = ConverterFlagsToken;
239
+ constants_1.classes['ConverterFlagsToken'] = __filename;
@@ -0,0 +1,73 @@
1
+ import Parser from '../index';
2
+ import { Token } from './index';
3
+ import { AtomToken } from './atom';
4
+ import type { ConverterToken, ConverterFlagsToken } from '../internal';
5
+ /**
6
+ * 转换规则
7
+ * @classdesc `{childNodes: ...AtomToken}`
8
+ */
9
+ export declare abstract class ConverterRuleToken extends Token {
10
+ readonly type = "converter-rule";
11
+ readonly childNodes: readonly [AtomToken] | readonly [AtomToken, AtomToken] | readonly [AtomToken, AtomToken, AtomToken];
12
+ abstract get firstChild(): AtomToken;
13
+ abstract get lastChild(): AtomToken;
14
+ abstract get parentNode(): ConverterToken | undefined;
15
+ abstract get previousSibling(): ConverterFlagsToken | this;
16
+ abstract get nextSibling(): this | undefined;
17
+ abstract get children(): [AtomToken] | [AtomToken, AtomToken] | [AtomToken, AtomToken, AtomToken];
18
+ abstract get firstElementChild(): AtomToken;
19
+ abstract get lastElementChild(): AtomToken;
20
+ abstract get parentElement(): ConverterToken | undefined;
21
+ abstract get previousElementSibling(): ConverterFlagsToken | this;
22
+ abstract get nextElementSibling(): this | undefined;
23
+ /** 语言变体 */
24
+ get variant(): string;
25
+ set variant(variant: string);
26
+ /** 是否是单向转换 */
27
+ get unidirectional(): boolean;
28
+ /** @throws `Error` 不能用于将双向转换或不转换更改为单向转换 */
29
+ set unidirectional(flag: boolean);
30
+ /** 是否是双向转换 */
31
+ get bidirectional(): boolean;
32
+ /** @throws `Error` 不能用于将双向转换更改为单向转换或将不转换更改为双向转换 */
33
+ set bidirectional(flag: boolean);
34
+ /**
35
+ * @param rule 转换规则
36
+ * @param hasColon 是否带有":"
37
+ */
38
+ constructor(rule: string, hasColon?: boolean, config?: Parser.Config, accum?: Token[]);
39
+ /** @override */
40
+ cloneNode(): this;
41
+ /**
42
+ * @override
43
+ * @param i 移除位置
44
+ */
45
+ removeAt(i: number): AtomToken;
46
+ /** @override */
47
+ insertAt(): never;
48
+ /** 修改为不转换 */
49
+ noConvert(): void;
50
+ /**
51
+ * 设置转换目标
52
+ * @param to 转换目标
53
+ */
54
+ setTo(to: string): void;
55
+ /**
56
+ * 设置语言变体
57
+ * @param variant 语言变体
58
+ */
59
+ setVariant(variant: string): void;
60
+ /**
61
+ * 设置转换原文
62
+ * @param from 转换原文
63
+ * @throws `Error` 尚未指定语言变体
64
+ */
65
+ setFrom(from: string): void;
66
+ /**
67
+ * 修改为单向转换
68
+ * @param from 转换原文
69
+ */
70
+ makeUnidirectional(from: string): void;
71
+ /** 修改为双向转换 */
72
+ makeBidirectional(): void;
73
+ }
@@ -0,0 +1,210 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConverterRuleToken = void 0;
4
+ const debug_1 = require("../util/debug");
5
+ const constants_1 = require("../util/constants");
6
+ const index_1 = require("../index");
7
+ const index_2 = require("./index");
8
+ const atom_1 = require("./atom");
9
+ /**
10
+ * 转换规则
11
+ * @classdesc `{childNodes: ...AtomToken}`
12
+ */
13
+ class ConverterRuleToken extends index_2.Token {
14
+ type = 'converter-rule';
15
+ /** 语言变体 */
16
+ get variant() {
17
+ return this.childNodes[this.length - 2]?.text().trim() ?? '';
18
+ }
19
+ set variant(variant) {
20
+ this.setVariant(variant);
21
+ }
22
+ /** 是否是单向转换 */
23
+ get unidirectional() {
24
+ return this.length === 3;
25
+ }
26
+ /** @throws `Error` 不能用于将双向转换或不转换更改为单向转换 */
27
+ set unidirectional(flag) {
28
+ const { length } = this;
29
+ if (length === 3 && !flag) {
30
+ this.makeBidirectional();
31
+ }
32
+ else if (length === 2 && flag) {
33
+ throw new Error('If you want to change to unidirectional, please use ConverterRuleToken.makeUnidirectional method!');
34
+ }
35
+ else if (length === 1 && flag) {
36
+ throw new Error('If you want to change to unidirectional, '
37
+ + 'please use ConverterRuleToken.setVariant method to specify the language variant first!');
38
+ }
39
+ }
40
+ /** 是否是双向转换 */
41
+ get bidirectional() {
42
+ return this.length === 2;
43
+ }
44
+ /** @throws `Error` 不能用于将双向转换更改为单向转换或将不转换更改为双向转换 */
45
+ set bidirectional(flag) {
46
+ const { length } = this;
47
+ if (length === 3 && flag) {
48
+ this.makeBidirectional();
49
+ }
50
+ else if (length === 2 && !flag) {
51
+ throw new Error('If you want to change to unidirectional, please use ConverterRuleToken.makeUnidirectional method!');
52
+ }
53
+ else if (length === 1 && flag) {
54
+ throw new Error('If you want to change to bidirectional, please use ConverterRuleToken.setVariant method!');
55
+ }
56
+ }
57
+ /* NOT FOR BROWSER END */
58
+ /**
59
+ * @param rule 转换规则
60
+ * @param hasColon 是否带有":"
61
+ */
62
+ constructor(rule, hasColon = true, config = index_1.default.getConfig(), accum = []) {
63
+ super(undefined, config, accum);
64
+ const i = rule.indexOf(':'), j = rule.slice(0, i).indexOf('=>'), v = j === -1 ? rule.slice(0, i) : rule.slice(j + 2, i);
65
+ if (hasColon && config.variants.includes(v.trim())) {
66
+ super.insertAt(new atom_1.AtomToken(v, 'converter-rule-variant', config, accum));
67
+ super.insertAt(new atom_1.AtomToken(rule.slice(i + 1), 'converter-rule-to', config, accum));
68
+ if (j !== -1) {
69
+ super.insertAt(new atom_1.AtomToken(rule.slice(0, j), 'converter-rule-from', config, accum), 0);
70
+ }
71
+ }
72
+ else {
73
+ super.insertAt(new atom_1.AtomToken(rule, 'converter-rule-to', config, accum));
74
+ }
75
+ /* NOT FOR BROWSER */
76
+ this.protectChildren('1:');
77
+ }
78
+ /** @private */
79
+ toString() {
80
+ const { childNodes } = this;
81
+ if (childNodes.length === 3) {
82
+ const [from, variant, to] = childNodes;
83
+ return `${from.toString()}=>${variant.toString()}:${to.toString()}`;
84
+ }
85
+ return super.toString(':');
86
+ }
87
+ /** @private */
88
+ text() {
89
+ const { childNodes } = this;
90
+ if (childNodes.length === 3) {
91
+ const [from, variant, to] = childNodes;
92
+ return `${from.text()}=>${variant.text()}:${to.text()}`;
93
+ }
94
+ return super.text(':');
95
+ }
96
+ /** @private */
97
+ getGaps(i) {
98
+ return i === 0 && this.length === 3 ? 2 : 1;
99
+ }
100
+ /** @private */
101
+ print() {
102
+ const { childNodes } = this;
103
+ if (childNodes.length === 3) {
104
+ const [from, variant, to] = childNodes;
105
+ return `<span class="wpb-converter-rule">${from.print()}=>${variant.print()}:${to.print()}</span>`;
106
+ }
107
+ return super.print({ sep: ':' });
108
+ }
109
+ /* NOT FOR BROWSER */
110
+ /** @override */
111
+ cloneNode() {
112
+ const cloned = this.cloneChildNodes(), placeholders = ['', 'zh:', '=>zh:'], placeholder = placeholders[cloned.length - 1];
113
+ return debug_1.Shadow.run(() => {
114
+ // @ts-expect-error abstract class
115
+ const token = new ConverterRuleToken(placeholder, Boolean(placeholder), this.getAttribute('config'));
116
+ for (let i = 0; i < cloned.length; i++) {
117
+ token.childNodes[i].safeReplaceWith(cloned[i]);
118
+ }
119
+ return token;
120
+ });
121
+ }
122
+ /** @private */
123
+ afterBuild() {
124
+ super.afterBuild();
125
+ const /** @implements */ converterRuleListener = (e, data) => {
126
+ const { prevTarget } = e;
127
+ if (this.length > 1 && this.childNodes[this.length - 2] === prevTarget) {
128
+ const { variant } = this;
129
+ if (!this.getAttribute('config').variants.includes(variant)) {
130
+ (0, debug_1.undo)(e, data);
131
+ throw new Error(`Invalid language variant: ${variant}`);
132
+ }
133
+ }
134
+ };
135
+ this.addEventListener(['remove', 'insert', 'text', 'replace'], converterRuleListener);
136
+ }
137
+ /**
138
+ * @override
139
+ * @param i 移除位置
140
+ */
141
+ removeAt(i) {
142
+ if (this.length === 1) {
143
+ this.constructorError('needs at least 1 child node');
144
+ }
145
+ return super.removeAt(i);
146
+ }
147
+ /** @override */
148
+ insertAt() {
149
+ this.constructorError('has complex syntax. Do not try to insert child nodes manually');
150
+ }
151
+ /** 修改为不转换 */
152
+ noConvert() {
153
+ const { length } = this;
154
+ for (let i = 0; i < length - 1; i++) { // ConverterRuleToken只能从前往后删除子节点
155
+ this.removeAt(0);
156
+ }
157
+ }
158
+ /**
159
+ * 设置转换目标
160
+ * @param to 转换目标
161
+ */
162
+ setTo(to) {
163
+ const { childNodes } = index_1.default.parse(to, this.getAttribute('include'), undefined, this.getAttribute('config'));
164
+ this.lastChild.replaceChildren(...childNodes);
165
+ }
166
+ /**
167
+ * 设置语言变体
168
+ * @param variant 语言变体
169
+ */
170
+ setVariant(variant) {
171
+ const config = this.getAttribute('config');
172
+ if (this.length === 1) {
173
+ super.insertAt(debug_1.Shadow.run(() => new atom_1.AtomToken(variant, 'converter-rule-variant', config)), 0);
174
+ }
175
+ else {
176
+ this.childNodes[this.length - 2].setText(variant);
177
+ }
178
+ }
179
+ /**
180
+ * 设置转换原文
181
+ * @param from 转换原文
182
+ * @throws `Error` 尚未指定语言变体
183
+ */
184
+ setFrom(from) {
185
+ const { variant, unidirectional } = this;
186
+ if (!variant) {
187
+ throw new Error('Please specify the language variant first!');
188
+ }
189
+ const config = this.getAttribute('config'), { childNodes } = index_1.default.parse(from, this.getAttribute('include'), undefined, config);
190
+ if (!unidirectional) {
191
+ super.insertAt(debug_1.Shadow.run(() => new atom_1.AtomToken(undefined, 'converter-rule-from', config)), 0);
192
+ }
193
+ this.firstChild.replaceChildren(...childNodes);
194
+ }
195
+ /**
196
+ * 修改为单向转换
197
+ * @param from 转换原文
198
+ */
199
+ makeUnidirectional(from) {
200
+ this.setFrom(from);
201
+ }
202
+ /** 修改为双向转换 */
203
+ makeBidirectional() {
204
+ if (this.unidirectional) {
205
+ this.removeAt(0);
206
+ }
207
+ }
208
+ }
209
+ exports.ConverterRuleToken = ConverterRuleToken;
210
+ constants_1.classes['ConverterRuleToken'] = __filename;
@@ -0,0 +1,37 @@
1
+ import Parser from '../index';
2
+ import { Token } from './index';
3
+ import { MagicLinkToken } from './magicLink';
4
+ import type { LintError } from '../base';
5
+ import type { MagicLinkParentBase } from '../mixin/magicLinkParent';
6
+ export interface ExtLinkToken extends MagicLinkParentBase {
7
+ }
8
+ /**
9
+ * 外链
10
+ * @classdesc `{childNodes: [MagicLinkToken, ?Token]}`
11
+ */
12
+ export declare abstract class ExtLinkToken extends Token {
13
+ #private;
14
+ readonly type = "ext-link";
15
+ readonly childNodes: readonly [MagicLinkToken] | readonly [MagicLinkToken, Token];
16
+ abstract get firstChild(): MagicLinkToken;
17
+ abstract get lastChild(): Token;
18
+ abstract get children(): [MagicLinkToken] | [MagicLinkToken, Token];
19
+ abstract get firstElementChild(): MagicLinkToken;
20
+ abstract get lastElementChild(): Token;
21
+ /** 链接显示文字 */
22
+ get innerText(): string;
23
+ set innerText(text: string);
24
+ /**
25
+ * @param url 网址
26
+ * @param space 空白字符
27
+ * @param text 链接文字
28
+ */
29
+ constructor(url?: string, space?: string, text?: string, config?: Parser.Config, accum?: Token[]);
30
+ /** @override */
31
+ cloneNode(): this;
32
+ /**
33
+ * 设置链接显示文字
34
+ * @param str 链接显示文字
35
+ */
36
+ setLinkText(str: string): void;
37
+ }