wikiparser-node 1.4.2 → 1.4.3-b

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