wikiparser-node 1.6.0-b → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/config/.schema.json +172 -0
  2. package/config/enwiki.json +814 -1
  3. package/config/llwiki.json +35 -1
  4. package/config/moegirl.json +44 -1
  5. package/config/zhwiki.json +466 -1
  6. package/dist/addon/table.d.ts +1 -0
  7. package/dist/addon/table.js +485 -0
  8. package/dist/base.d.ts +72 -0
  9. package/dist/base.js +38 -0
  10. package/dist/index.d.ts +30 -0
  11. package/dist/index.js +214 -0
  12. package/dist/internal.d.ts +44 -0
  13. package/dist/lib/element.d.ts +151 -0
  14. package/dist/lib/element.js +615 -0
  15. package/dist/lib/node.d.ts +146 -0
  16. package/dist/lib/node.js +426 -0
  17. package/dist/lib/range.d.ts +104 -0
  18. package/dist/lib/range.js +385 -0
  19. package/dist/lib/ranges.d.ts +26 -0
  20. package/dist/lib/ranges.js +118 -0
  21. package/dist/lib/text.d.ts +63 -0
  22. package/dist/lib/text.js +354 -0
  23. package/dist/lib/title.d.ts +38 -0
  24. package/dist/lib/title.js +160 -0
  25. package/dist/mixin/attributesParent.d.ts +50 -0
  26. package/dist/mixin/attributesParent.js +81 -0
  27. package/dist/mixin/fixed.d.ts +6 -0
  28. package/dist/mixin/fixed.js +30 -0
  29. package/dist/mixin/flagsParent.d.ts +72 -0
  30. package/dist/mixin/flagsParent.js +59 -0
  31. package/dist/mixin/hidden.d.ts +5 -0
  32. package/dist/mixin/hidden.js +24 -0
  33. package/dist/mixin/magicLinkParent.d.ts +40 -0
  34. package/dist/mixin/magicLinkParent.js +42 -0
  35. package/dist/mixin/singleLine.d.ts +6 -0
  36. package/dist/mixin/singleLine.js +26 -0
  37. package/dist/mixin/sol.d.ts +6 -0
  38. package/dist/mixin/sol.js +43 -0
  39. package/dist/mixin/syntax.d.ts +9 -0
  40. package/dist/mixin/syntax.js +50 -0
  41. package/dist/parser/braces.js +131 -0
  42. package/dist/parser/commentAndExt.js +90 -0
  43. package/dist/parser/converter.js +41 -0
  44. package/dist/parser/externalLinks.js +32 -0
  45. package/dist/parser/hrAndDoubleUnderscore.js +41 -0
  46. package/dist/parser/html.js +39 -0
  47. package/dist/parser/links.js +95 -0
  48. package/dist/parser/list.js +98 -0
  49. package/dist/parser/magicLinks.js +43 -0
  50. package/dist/parser/quotes.js +68 -0
  51. package/dist/parser/selector.js +162 -0
  52. package/dist/parser/table.js +124 -0
  53. package/dist/src/arg.d.ts +58 -0
  54. package/dist/src/arg.js +214 -0
  55. package/dist/src/atom.d.ts +12 -0
  56. package/dist/src/atom.js +27 -0
  57. package/dist/src/attribute.d.ts +71 -0
  58. package/dist/src/attribute.js +502 -0
  59. package/dist/src/attributes.d.ts +109 -0
  60. package/dist/src/attributes.js +356 -0
  61. package/dist/src/converter.d.ts +33 -0
  62. package/dist/src/converter.js +134 -0
  63. package/dist/src/converterFlags.d.ts +87 -0
  64. package/dist/src/converterFlags.js +242 -0
  65. package/dist/src/converterRule.d.ts +77 -0
  66. package/dist/src/converterRule.js +209 -0
  67. package/dist/src/extLink.d.ts +43 -0
  68. package/dist/src/extLink.js +188 -0
  69. package/dist/src/gallery.d.ts +54 -0
  70. package/dist/src/gallery.js +139 -0
  71. package/dist/src/heading.d.ts +47 -0
  72. package/dist/src/heading.js +190 -0
  73. package/dist/src/hidden.d.ts +7 -0
  74. package/dist/src/hidden.js +23 -0
  75. package/dist/src/html.d.ts +65 -0
  76. package/dist/src/html.js +358 -0
  77. package/dist/src/imageParameter.d.ts +65 -0
  78. package/dist/src/imageParameter.js +257 -0
  79. package/dist/src/imagemap.d.ts +54 -0
  80. package/dist/src/imagemap.js +144 -0
  81. package/dist/src/imagemapLink.d.ts +31 -0
  82. package/dist/src/imagemapLink.js +93 -0
  83. package/dist/src/index.d.ts +143 -0
  84. package/dist/src/index.js +852 -0
  85. package/dist/src/link/base.d.ts +52 -0
  86. package/dist/src/link/base.js +228 -0
  87. package/dist/src/link/category.d.ts +13 -0
  88. package/dist/src/link/category.js +28 -0
  89. package/dist/src/link/file.d.ts +98 -0
  90. package/dist/src/link/file.js +272 -0
  91. package/dist/src/link/galleryImage.d.ts +32 -0
  92. package/dist/src/link/galleryImage.js +157 -0
  93. package/dist/src/link/index.d.ts +56 -0
  94. package/dist/src/link/index.js +133 -0
  95. package/dist/src/magicLink.d.ts +59 -0
  96. package/dist/src/magicLink.js +223 -0
  97. package/dist/src/nested.d.ts +43 -0
  98. package/dist/src/nested.js +105 -0
  99. package/dist/src/nowiki/base.d.ts +31 -0
  100. package/dist/src/nowiki/base.js +93 -0
  101. package/dist/src/nowiki/comment.d.ts +25 -0
  102. package/dist/src/nowiki/comment.js +76 -0
  103. package/dist/src/nowiki/dd.d.ts +8 -0
  104. package/dist/src/nowiki/dd.js +24 -0
  105. package/dist/src/nowiki/doubleUnderscore.d.ts +18 -0
  106. package/dist/src/nowiki/doubleUnderscore.js +101 -0
  107. package/dist/src/nowiki/hr.d.ts +5 -0
  108. package/dist/src/nowiki/hr.js +63 -0
  109. package/dist/src/nowiki/index.d.ts +16 -0
  110. package/dist/src/nowiki/index.js +27 -0
  111. package/dist/src/nowiki/list.d.ts +16 -0
  112. package/dist/src/nowiki/list.js +109 -0
  113. package/dist/src/nowiki/listBase.d.ts +5 -0
  114. package/dist/src/nowiki/listBase.js +61 -0
  115. package/dist/src/nowiki/noinclude.d.ts +10 -0
  116. package/dist/src/nowiki/noinclude.js +23 -0
  117. package/dist/src/nowiki/quote.d.ts +14 -0
  118. package/dist/src/nowiki/quote.js +131 -0
  119. package/dist/src/onlyinclude.d.ts +16 -0
  120. package/dist/src/onlyinclude.js +57 -0
  121. package/dist/src/paramTag/index.d.ts +37 -0
  122. package/dist/src/paramTag/index.js +77 -0
  123. package/dist/src/paramTag/inputbox.d.ts +8 -0
  124. package/dist/src/paramTag/inputbox.js +22 -0
  125. package/dist/src/parameter.d.ts +70 -0
  126. package/dist/src/parameter.js +264 -0
  127. package/dist/src/pre.d.ts +31 -0
  128. package/dist/src/pre.js +59 -0
  129. package/dist/src/syntax.d.ts +20 -0
  130. package/dist/src/syntax.js +86 -0
  131. package/dist/src/table/base.d.ts +27 -0
  132. package/dist/src/table/base.js +81 -0
  133. package/dist/src/table/index.d.ts +242 -0
  134. package/dist/src/table/index.js +491 -0
  135. package/dist/src/table/td.d.ts +86 -0
  136. package/dist/src/table/td.js +354 -0
  137. package/dist/src/table/tr.d.ts +32 -0
  138. package/dist/src/table/tr.js +58 -0
  139. package/dist/src/table/trBase.d.ts +53 -0
  140. package/dist/src/table/trBase.js +156 -0
  141. package/dist/src/tagPair/ext.d.ts +32 -0
  142. package/dist/src/tagPair/ext.js +203 -0
  143. package/dist/src/tagPair/include.d.ts +35 -0
  144. package/dist/src/tagPair/include.js +74 -0
  145. package/dist/src/tagPair/index.d.ts +27 -0
  146. package/dist/src/tagPair/index.js +128 -0
  147. package/dist/src/transclude.d.ts +167 -0
  148. package/dist/src/transclude.js +717 -0
  149. package/dist/util/constants.js +28 -0
  150. package/dist/util/debug.js +88 -0
  151. package/dist/util/diff.js +83 -0
  152. package/dist/util/lint.js +31 -0
  153. package/dist/util/string.js +54 -0
  154. package/errors/README +1 -0
  155. package/package.json +17 -28
  156. package/printed/README +1 -0
  157. package/bundle/bundle.min.js +0 -39
  158. package/extensions/dist/base.js +0 -64
  159. package/extensions/dist/editor.js +0 -159
  160. package/extensions/dist/highlight.js +0 -59
  161. package/extensions/dist/lint.js +0 -60
  162. package/extensions/editor.css +0 -63
  163. package/extensions/ui.css +0 -141
@@ -0,0 +1,356 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AttributesToken = void 0;
4
+ const lint_1 = require("../util/lint");
5
+ const string_1 = require("../util/string");
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 attribute_1 = require("./attribute");
12
+ /* NOT FOR BROWSER */
13
+ const stages = { 'ext-attrs': 0, 'html-attrs': 2, 'table-attrs': 3 };
14
+ /**
15
+ * 将属性类型转换为单属性类型
16
+ * @param type 属性类型
17
+ */
18
+ const toAttributeType = (type) => type.slice(0, -1);
19
+ /**
20
+ * 将属性类型转换为无效属性类型
21
+ * @param type 属性类型
22
+ */
23
+ const toDirty = (type) => `${toAttributeType(type)}-dirty`;
24
+ /**
25
+ * 扩展和HTML标签属性
26
+ * @classdesc `{childNodes: ...AtomToken|AttributeToken}`
27
+ */
28
+ class AttributesToken extends index_2.Token {
29
+ /** getAttrs()方法的getter写法 */
30
+ get attributes() {
31
+ return this.getAttrs();
32
+ }
33
+ set attributes(attrs) {
34
+ this.replaceChildren();
35
+ this.setAttr(attrs);
36
+ }
37
+ /** 以字符串表示的class属性 */
38
+ get className() {
39
+ const attr = this.getAttr('class');
40
+ return typeof attr === 'string' ? attr : '';
41
+ }
42
+ set className(className) {
43
+ this.setAttr('class', className || false);
44
+ }
45
+ /** 以Set表示的class属性 */
46
+ get classList() {
47
+ return new Set(this.className.split(/\s/u));
48
+ }
49
+ set classList(classList) {
50
+ this.setAttr('class', [...classList].join(' '));
51
+ }
52
+ /** id属性 */
53
+ get id() {
54
+ const attr = this.getAttr('id');
55
+ return typeof attr === 'string' ? attr : '';
56
+ }
57
+ set id(id) {
58
+ this.setAttr('id', id || false);
59
+ }
60
+ /** 是否含有无效属性 */
61
+ get sanitized() {
62
+ return this.childNodes.filter(child => child instanceof atom_1.AtomToken && child.text().trim()).length === 0;
63
+ }
64
+ set sanitized(sanitized) {
65
+ if (sanitized) {
66
+ this.sanitize();
67
+ }
68
+ }
69
+ /* NOT FOR BROWSER END */
70
+ /**
71
+ * @param attr 标签属性
72
+ * @param type 标签类型
73
+ * @param name 标签名
74
+ */
75
+ constructor(attr, type, name, config = index_1.default.getConfig(), accum = []) {
76
+ super(undefined, config, accum, {
77
+ AtomToken: ':', AttributeToken: ':',
78
+ });
79
+ this.type = type;
80
+ this.setAttribute('name', name);
81
+ if (attr) {
82
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
83
+ /([^\s/](?:(?!\0\d+~\x7F)[^\s/=])*)(?:(\s*(?:=|\0\d+~\x7F)\s*)(?:(["'])(.*?)(\3|$)|(\S*)))?/gsu;
84
+ const regex = new RegExp('([^\\s/](?:(?!\0\\d+~\x7F)[^\\s/=])*)' // 属性名
85
+ + `(?:${'((?:\\s|\0\\d+c\x7F)*(?:=|\0\\d+~\x7F)(?:\\s|\0\\d+c\x7F)*)' // `=`和前后的空白字符
86
+ + `(?:(["'])(.*?)(\\3|$)|(\\S*))` // 属性值
87
+ })?`, 'gsu');
88
+ let out = '', mt = regex.exec(attr), lastIndex = 0;
89
+ const insertDirty = /** 插入无效属性 */ () => {
90
+ if (out) {
91
+ super.insertAt(new atom_1.AtomToken(out, toDirty(type), config, accum, {
92
+ [`Stage-${stages[type]}`]: ':',
93
+ }));
94
+ out = '';
95
+ }
96
+ };
97
+ while (mt) {
98
+ const { index, 0: full, 1: key, 2: equal, 3: quoteStart, 4: quoted, 5: quoteEnd, 6: unquoted } = mt;
99
+ out += attr.slice(lastIndex, index);
100
+ if (/^(?:[\w:]|\0\d+[t!~{}+-]\x7F)(?:[\w:.-]|\0\d+[t!~{}+-]\x7F)*$/u.test((0, string_1.removeComment)(key).trim())) {
101
+ const value = quoted ?? unquoted, quotes = [quoteStart, quoteEnd],
102
+ // @ts-expect-error abstract class
103
+ token = new attribute_1.AttributeToken(toAttributeType(type), name, key, equal, value, quotes, config, accum);
104
+ insertDirty();
105
+ super.insertAt(token);
106
+ }
107
+ else {
108
+ out += full;
109
+ }
110
+ ({ lastIndex } = regex);
111
+ mt = regex.exec(attr);
112
+ }
113
+ out += attr.slice(lastIndex);
114
+ insertDirty();
115
+ }
116
+ }
117
+ /** @private */
118
+ afterBuild() {
119
+ if (this.type === 'table-attrs') {
120
+ const { parentNode } = this;
121
+ this.setAttribute('name', parentNode?.type === 'td' && parentNode.subtype === 'caption' ? 'caption' : parentNode?.type);
122
+ }
123
+ }
124
+ /**
125
+ * 所有指定属性名的AttributeToken
126
+ * @param key 属性名
127
+ */
128
+ getAttrTokens(key) {
129
+ return this.childNodes.filter((child) => child instanceof attribute_1.AttributeToken && (!key || child.name === key.toLowerCase().trim()));
130
+ }
131
+ /**
132
+ * 指定属性名的最后一个AttributeToken
133
+ * @param key 属性名
134
+ */
135
+ getAttrToken(key) {
136
+ const tokens = this.getAttrTokens(key);
137
+ return tokens[tokens.length - 1];
138
+ }
139
+ /**
140
+ * 获取指定属性
141
+ * @param key 属性键
142
+ */
143
+ getAttr(key) {
144
+ return this.getAttrToken(key)?.getValue();
145
+ }
146
+ /** @override */
147
+ lint(start = this.getAbsoluteIndex(), re) {
148
+ const errors = super.lint(start, re), { parentNode, length, childNodes } = this, attrs = new Map(), duplicated = new Set();
149
+ let rect;
150
+ if (parentNode?.type === 'html' && parentNode.closing && this.text().trim()) {
151
+ rect = { start, ...this.getRootNode().posFromIndex(start) };
152
+ const e = (0, lint_1.generateForSelf)(this, rect, 'no-ignored', 'attributes of a closing tag');
153
+ e.fix = { range: [start, e.endIndex], text: '' };
154
+ errors.push(e);
155
+ }
156
+ for (let i = 0; i < length; i++) {
157
+ const attr = childNodes[i];
158
+ if (attr instanceof atom_1.AtomToken && attr.text().trim()) {
159
+ rect ??= { start, ...this.getRootNode().posFromIndex(start) };
160
+ const e = (0, lint_1.generateForChild)(attr, rect, 'no-ignored', 'containing invalid attribute');
161
+ e.suggestions = [
162
+ {
163
+ desc: 'remove',
164
+ range: [e.startIndex, e.endIndex],
165
+ text: ' ',
166
+ },
167
+ ];
168
+ errors.push(e);
169
+ }
170
+ else if (attr instanceof attribute_1.AttributeToken) {
171
+ const { name } = attr;
172
+ if (attrs.has(name)) {
173
+ duplicated.add(name);
174
+ attrs.get(name).push(attr);
175
+ }
176
+ else if (name !== 'class') {
177
+ attrs.set(name, [attr]);
178
+ }
179
+ }
180
+ }
181
+ if (duplicated.size > 0) {
182
+ rect ??= { start, ...this.getRootNode().posFromIndex(start) };
183
+ for (const key of duplicated) {
184
+ errors.push(...attrs.get(key).map(attr => (0, lint_1.generateForChild)(attr, rect, 'no-duplicate', index_1.default.msg('duplicated $1 attribute', key))));
185
+ }
186
+ }
187
+ return errors;
188
+ }
189
+ /** @override */
190
+ print() {
191
+ return String(this)
192
+ ? `<span class="wpb-${this.type}">${this.childNodes.map(child => child.print(child instanceof atom_1.AtomToken ? { class: 'attr-dirty' } : undefined)).join('')}</span>`
193
+ : '';
194
+ }
195
+ /* NOT FOR BROWSER */
196
+ /** 清理无效属性 */
197
+ sanitize() {
198
+ let dirty = false;
199
+ for (let i = this.length - 1; i >= 0; i--) {
200
+ const child = this.childNodes[i];
201
+ if (child instanceof atom_1.AtomToken && child.text().trim()) {
202
+ dirty = true;
203
+ this.removeAt(i);
204
+ }
205
+ }
206
+ if (!debug_1.Shadow.running && dirty) {
207
+ index_1.default.warn(`${this.constructor.name}.sanitize 方法将清理无效属性!`);
208
+ }
209
+ }
210
+ /** @override */
211
+ cloneNode() {
212
+ const cloned = this.cloneChildNodes();
213
+ return debug_1.Shadow.run(() => {
214
+ // @ts-expect-error abstract class
215
+ const token = new AttributesToken(undefined, this.type, this.name, this.getAttribute('config'));
216
+ token.append(...cloned);
217
+ token.setAttribute('name', this.name);
218
+ return token;
219
+ });
220
+ }
221
+ /**
222
+ * @override
223
+ * @param token 待插入的子节点
224
+ * @param i 插入位置
225
+ * @throws `RangeError` 标签不匹配
226
+ */
227
+ insertAt(token, i = this.length) {
228
+ if (!(token instanceof attribute_1.AttributeToken)) {
229
+ if (String(token).trim()) {
230
+ this.constructorError('只能插入 AttributeToken');
231
+ }
232
+ return super.insertAt(token, i);
233
+ }
234
+ else if (token.type !== this.type.slice(0, -1) || token.tag !== this.name) {
235
+ throw new RangeError(`待插入的AttributeToken只可用于${token.tag}标签!`);
236
+ }
237
+ else if (i === this.length) {
238
+ const { lastChild } = this;
239
+ if (lastChild instanceof attribute_1.AttributeToken) {
240
+ lastChild.close();
241
+ }
242
+ }
243
+ else {
244
+ token.close();
245
+ }
246
+ if (this.closest('parameter')) {
247
+ token.escape();
248
+ }
249
+ super.insertAt(token, i);
250
+ const { previousVisibleSibling, nextVisibleSibling } = token, type = toDirty(this.type), config = this.getAttribute('config'), acceptable = { [`Stage-${stages[this.type]}`]: ':' };
251
+ if (nextVisibleSibling && !/^\s/u.test(String(nextVisibleSibling))) {
252
+ super.insertAt(debug_1.Shadow.run(() => new atom_1.AtomToken(' ', type, config, [], acceptable)), i + 1);
253
+ }
254
+ if (previousVisibleSibling && !/\s$/u.test(String(previousVisibleSibling))) {
255
+ super.insertAt(debug_1.Shadow.run(() => new atom_1.AtomToken(' ', type, config, [], acceptable)), i);
256
+ }
257
+ return token;
258
+ }
259
+ setAttr(keyOrProp, value) {
260
+ if (typeof keyOrProp !== 'string') {
261
+ for (const [key, val] of Object.entries(keyOrProp)) {
262
+ this.setAttr(key, val);
263
+ }
264
+ return;
265
+ }
266
+ else if (this.type === 'ext-attrs' && typeof value === 'string' && value.includes('>')) {
267
+ throw new RangeError('扩展标签属性不能包含 ">"!');
268
+ }
269
+ const key = keyOrProp.toLowerCase().trim(), attr = this.getAttrToken(key);
270
+ if (attr) {
271
+ attr.setValue(value);
272
+ return;
273
+ }
274
+ else if (value === false) {
275
+ return;
276
+ }
277
+ // @ts-expect-error abstract class
278
+ const token = debug_1.Shadow.run(() => new attribute_1.AttributeToken(toAttributeType(this.type), this.name, key, value === true ? '' : '=', value === true ? '' : value, ['"', '"'], this.getAttribute('config')));
279
+ this.insertAt(token);
280
+ }
281
+ /**
282
+ * 标签是否具有某属性
283
+ * @param key 属性键
284
+ */
285
+ hasAttr(key) {
286
+ return this.getAttrTokens(key).length > 0;
287
+ }
288
+ /** 获取全部的属性名 */
289
+ getAttrNames() {
290
+ return new Set(this.getAttrTokens().map(({ name }) => name));
291
+ }
292
+ /** 获取全部属性 */
293
+ getAttrs() {
294
+ return Object.fromEntries(this.getAttrTokens().map(({ name, value }) => [name, value]));
295
+ }
296
+ /**
297
+ * 移除指定属性
298
+ * @param key 属性键
299
+ */
300
+ removeAttr(key) {
301
+ for (const attr of this.getAttrTokens(key)) {
302
+ attr.remove();
303
+ }
304
+ }
305
+ /**
306
+ * 开关指定属性
307
+ * @param key 属性键
308
+ * @param force 强制开启或关闭
309
+ * @throws `RangeError` 不为Boolean类型的属性值
310
+ */
311
+ toggleAttr(key, force) {
312
+ key = key.toLowerCase().trim();
313
+ const attr = this.getAttrToken(key);
314
+ if (attr && attr.getValue() !== true) {
315
+ throw new RangeError(`${key} 属性的值不为 Boolean!`);
316
+ }
317
+ else if (attr) {
318
+ attr.setValue(force === true);
319
+ }
320
+ else if (force !== false) {
321
+ this.setAttr(key, true);
322
+ }
323
+ }
324
+ /**
325
+ * 生成引导空格
326
+ * @param str 属性字符串
327
+ */
328
+ #leadingSpace(str) {
329
+ const { type } = this, leadingRegex = { 'ext-attrs': /^\s/u, 'html-attrs': /^[/\s]/u };
330
+ return str && type !== 'table-attrs' && !leadingRegex[type].test(str) ? ' ' : '';
331
+ }
332
+ /** @private */
333
+ toString() {
334
+ if (this.type === 'table-attrs') {
335
+ (0, string_1.normalizeSpace)(this);
336
+ }
337
+ const str = super.toString();
338
+ return `${this.#leadingSpace(str)}${str}`;
339
+ }
340
+ /** @private */
341
+ getAttribute(key) {
342
+ return key === 'padding'
343
+ ? this.#leadingSpace(super.toString()).length
344
+ : super.getAttribute(key);
345
+ }
346
+ /** @override */
347
+ text() {
348
+ if (this.type === 'table-attrs') {
349
+ (0, string_1.normalizeSpace)(this);
350
+ }
351
+ const str = (0, string_1.text)(this.childNodes.filter(child => child instanceof attribute_1.AttributeToken), ' ');
352
+ return `${this.#leadingSpace(str)}${str}`;
353
+ }
354
+ }
355
+ exports.AttributesToken = AttributesToken;
356
+ constants_1.classes['AttributesToken'] = __filename;
@@ -0,0 +1,33 @@
1
+ import Parser from '../index';
2
+ import { Token } from './index';
3
+ import { ConverterFlagsToken } from './converterFlags';
4
+ import { ConverterRuleToken } from './converterRule';
5
+ import type { FlagsParentBase } from '../mixin/flagsParent';
6
+ export interface ConverterToken extends FlagsParentBase {
7
+ }
8
+ /**
9
+ * 转换
10
+ * @classdesc `{childNodes: [ConverterFlagsToken, ...ConverterRuleToken]}`
11
+ */
12
+ export declare abstract class ConverterToken extends Token {
13
+ readonly type = "converter";
14
+ readonly childNodes: readonly [ConverterFlagsToken, ...ConverterRuleToken[]];
15
+ abstract get firstChild(): ConverterFlagsToken;
16
+ abstract get lastChild(): ConverterFlagsToken | ConverterRuleToken;
17
+ abstract get children(): [ConverterFlagsToken, ...ConverterRuleToken[]];
18
+ abstract get firstElementChild(): ConverterFlagsToken;
19
+ abstract get lastElementChild(): ConverterFlagsToken | ConverterRuleToken;
20
+ /** 是否不转换 */
21
+ get noConvert(): boolean;
22
+ /**
23
+ * @param flags 转换类型标记
24
+ * @param rules 转换规则
25
+ */
26
+ constructor(flags: readonly string[], rules: readonly [string, ...string[]], config?: Parser.Config, accum?: Token[]);
27
+ /** @override */
28
+ text(): string;
29
+ /** @override */
30
+ print(): string;
31
+ /** @override */
32
+ cloneNode(): this;
33
+ }
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
+ var _, done = false;
8
+ for (var i = decorators.length - 1; i >= 0; i--) {
9
+ var context = {};
10
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
+ if (kind === "accessor") {
15
+ if (result === void 0) continue;
16
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
+ if (_ = accept(result.get)) descriptor.get = _;
18
+ if (_ = accept(result.set)) descriptor.set = _;
19
+ if (_ = accept(result.init)) initializers.unshift(_);
20
+ }
21
+ else if (_ = accept(result)) {
22
+ if (kind === "field") initializers.unshift(_);
23
+ else descriptor[key] = _;
24
+ }
25
+ }
26
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
+ done = true;
28
+ };
29
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
+ var useValue = arguments.length > 2;
31
+ for (var i = 0; i < initializers.length; i++) {
32
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
+ }
34
+ return useValue ? value : void 0;
35
+ };
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.ConverterToken = void 0;
38
+ const string_1 = require("../util/string");
39
+ const debug_1 = require("../util/debug");
40
+ const constants_1 = require("../util/constants");
41
+ const flagsParent_1 = require("../mixin/flagsParent");
42
+ const index_1 = require("../index");
43
+ const index_2 = require("./index");
44
+ const converterFlags_1 = require("./converterFlags");
45
+ const converterRule_1 = require("./converterRule");
46
+ /**
47
+ * 转换
48
+ * @classdesc `{childNodes: [ConverterFlagsToken, ...ConverterRuleToken]}`
49
+ */
50
+ let ConverterToken = (() => {
51
+ let _classDecorators = [flagsParent_1.flagsParent];
52
+ let _classDescriptor;
53
+ let _classExtraInitializers = [];
54
+ let _classThis;
55
+ let _classSuper = index_2.Token;
56
+ var ConverterToken = class extends _classSuper {
57
+ static { _classThis = this; }
58
+ static {
59
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
60
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
61
+ ConverterToken = _classThis = _classDescriptor.value;
62
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
63
+ __runInitializers(_classThis, _classExtraInitializers);
64
+ }
65
+ type = 'converter';
66
+ /** 是否不转换 */
67
+ get noConvert() {
68
+ return this.hasFlag('R') || this.length === 2 && this.lastChild.length === 1;
69
+ }
70
+ /* NOT FOR BROWSER END */
71
+ /**
72
+ * @param flags 转换类型标记
73
+ * @param rules 转换规则
74
+ */
75
+ constructor(flags, rules, config = index_1.default.getConfig(), accum = []) {
76
+ super(undefined, config, accum);
77
+ // @ts-expect-error abstract class
78
+ this.append(new converterFlags_1.ConverterFlagsToken(flags, config, accum));
79
+ const [firstRule] = rules, hasColon = firstRule.includes(':'),
80
+ // @ts-expect-error abstract class
81
+ firstRuleToken = new converterRule_1.ConverterRuleToken(firstRule, hasColon, config, accum);
82
+ if (hasColon && firstRuleToken.length === 1) {
83
+ // @ts-expect-error abstract class
84
+ this.insertAt(new converterRule_1.ConverterRuleToken(rules.join(';'), false, config, accum));
85
+ }
86
+ else {
87
+ this.append(firstRuleToken,
88
+ // @ts-expect-error abstract class
89
+ ...rules.slice(1).map(rule => new converterRule_1.ConverterRuleToken(rule, true, config, accum)));
90
+ }
91
+ /* NOT FOR BROWSER */
92
+ this.protectChildren(0);
93
+ }
94
+ /** @private */
95
+ toString() {
96
+ const { childNodes: [flags, ...rules] } = this;
97
+ return `-{${String(flags)}${flags.length > 0 ? '|' : ''}${rules.map(String).join(';')}}-`;
98
+ }
99
+ /** @override */
100
+ text() {
101
+ const { childNodes: [flags, ...rules] } = this;
102
+ return `-{${flags.text()}|${(0, string_1.text)(rules, ';')}}-`;
103
+ }
104
+ /** @private */
105
+ getAttribute(key) {
106
+ return key === 'padding' ? 2 : super.getAttribute(key);
107
+ }
108
+ /** @private */
109
+ getGaps(i) {
110
+ return i || this.firstChild.length > 0 ? 1 : 0;
111
+ }
112
+ /** @override */
113
+ print() {
114
+ const { childNodes: [flags, ...rules] } = this;
115
+ return `<span class="wpb-converter">-{${flags.print()}${flags.length > 0 ? '|' : ''}${(0, string_1.print)(rules, { sep: ';' })}}-</span>`;
116
+ }
117
+ /* NOT FOR BROWSER */
118
+ /** @override */
119
+ cloneNode() {
120
+ const [flags, ...rules] = this.cloneChildNodes();
121
+ return debug_1.Shadow.run(() => {
122
+ // @ts-expect-error abstract class
123
+ const token = new ConverterToken([], [''], this.getAttribute('config'));
124
+ token.firstChild.safeReplaceWith(flags);
125
+ token.removeAt(1);
126
+ token.append(...rules);
127
+ return token;
128
+ });
129
+ }
130
+ };
131
+ return ConverterToken = _classThis;
132
+ })();
133
+ exports.ConverterToken = ConverterToken;
134
+ constants_1.classes['ConverterToken'] = __filename;
@@ -0,0 +1,87 @@
1
+ import Parser from '../index';
2
+ import { Token } from './index';
3
+ import { AtomToken } from './atom';
4
+ import type { LintError } from '../base';
5
+ import type { ConverterToken, ConverterRuleToken } from '../internal';
6
+ /**
7
+ * 转换flags
8
+ * @classdesc `{childNodes: ...AtomToken}`
9
+ */
10
+ export declare abstract class ConverterFlagsToken extends Token {
11
+ #private;
12
+ readonly type = "converter-flags";
13
+ readonly childNodes: readonly AtomToken[];
14
+ abstract get firstChild(): AtomToken | undefined;
15
+ abstract get lastChild(): AtomToken | undefined;
16
+ abstract get parentNode(): ConverterToken | undefined;
17
+ abstract get previousSibling(): undefined;
18
+ abstract get nextSibling(): ConverterRuleToken | undefined;
19
+ abstract get children(): AtomToken[];
20
+ abstract get firstElementChild(): AtomToken | undefined;
21
+ abstract get lastElementChild(): AtomToken | undefined;
22
+ abstract get parentElement(): ConverterToken | undefined;
23
+ abstract get previousElementSibling(): undefined;
24
+ abstract get nextElementSibling(): ConverterRuleToken | undefined;
25
+ /** 所有转换类型标记 */
26
+ get flags(): Set<string>;
27
+ set flags(value: Set<string>);
28
+ /** @param flags 转换类型标记 */
29
+ constructor(flags: readonly string[], config?: Parser.Config, accum?: Token[]);
30
+ /** @override */
31
+ text(): string;
32
+ /** 获取未知的转换类型标记 */
33
+ getUnknownFlags(): Set<string>;
34
+ /** 获取指定语言变体的转换标记 */
35
+ getVariantFlags(): Set<string>;
36
+ /** @override */
37
+ lint(start?: number, re?: RegExp): LintError[];
38
+ /** @override */
39
+ print(): string;
40
+ /** @override */
41
+ cloneNode(): this;
42
+ /**
43
+ * @override
44
+ * @param i 移除位置
45
+ */
46
+ removeAt(i: number): AtomToken;
47
+ /**
48
+ * @override
49
+ * @param token 待插入的子节点
50
+ * @param i 插入位置
51
+ */
52
+ insertAt<T extends AtomToken>(token: T, i?: number): T;
53
+ /** 获取所有转换类型标记 */
54
+ getAllFlags(): Set<string>;
55
+ /**
56
+ * 获取转换类型标记节点
57
+ * @param flag 转换类型标记
58
+ */
59
+ getFlagTokens(flag: string): AtomToken[];
60
+ /** 获取有效的转换类型标记 */
61
+ getEffectiveFlags(): Set<string>;
62
+ /**
63
+ * 是否具有某转换类型标记
64
+ * @param flag 转换类型标记
65
+ */
66
+ hasFlag(flag: string): boolean;
67
+ /**
68
+ * 是否具有某有效的转换类型标记
69
+ * @param flag 转换类型标记
70
+ */
71
+ hasEffectiveFlag(flag: string): boolean;
72
+ /**
73
+ * 移除某转换类型标记
74
+ * @param flag 转换类型标记
75
+ */
76
+ removeFlag(flag: string): void;
77
+ /**
78
+ * 设置转换类型标记
79
+ * @param flag 转换类型标记
80
+ */
81
+ setFlag(flag: string): void;
82
+ /**
83
+ * 开关转换类型标记
84
+ * @param flag 转换类型标记
85
+ */
86
+ toggleFlag(flag: string): void;
87
+ }