wikiparser-node 1.6.2 → 1.7.0-beta.1

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 (167) hide show
  1. package/bundle/bundle.min.js +38 -0
  2. package/config/default.json +5 -0
  3. package/config/enwiki.json +4 -814
  4. package/config/llwiki.json +5 -35
  5. package/config/minimum.json +3 -0
  6. package/config/moegirl.json +5 -44
  7. package/config/zhwiki.json +6 -466
  8. package/extensions/dist/base.js +64 -0
  9. package/extensions/dist/editor.js +159 -0
  10. package/extensions/dist/highlight.js +58 -0
  11. package/extensions/dist/lint.js +71 -0
  12. package/extensions/editor.css +64 -0
  13. package/extensions/ui.css +144 -0
  14. package/i18n/zh-hans.json +2 -1
  15. package/i18n/zh-hant.json +2 -1
  16. package/package.json +35 -19
  17. package/config/.schema.json +0 -172
  18. package/dist/addon/table.d.ts +0 -1
  19. package/dist/addon/table.js +0 -485
  20. package/dist/base.d.ts +0 -69
  21. package/dist/base.js +0 -38
  22. package/dist/index.d.ts +0 -31
  23. package/dist/index.js +0 -212
  24. package/dist/internal.d.ts +0 -44
  25. package/dist/lib/element.d.ts +0 -151
  26. package/dist/lib/element.js +0 -618
  27. package/dist/lib/node.d.ts +0 -146
  28. package/dist/lib/node.js +0 -426
  29. package/dist/lib/range.d.ts +0 -104
  30. package/dist/lib/range.js +0 -385
  31. package/dist/lib/ranges.d.ts +0 -28
  32. package/dist/lib/ranges.js +0 -126
  33. package/dist/lib/text.d.ts +0 -63
  34. package/dist/lib/text.js +0 -354
  35. package/dist/lib/title.d.ts +0 -40
  36. package/dist/lib/title.js +0 -179
  37. package/dist/mixin/attributesParent.d.ts +0 -50
  38. package/dist/mixin/attributesParent.js +0 -81
  39. package/dist/mixin/fixed.d.ts +0 -6
  40. package/dist/mixin/fixed.js +0 -30
  41. package/dist/mixin/flagsParent.d.ts +0 -72
  42. package/dist/mixin/flagsParent.js +0 -59
  43. package/dist/mixin/hidden.d.ts +0 -5
  44. package/dist/mixin/hidden.js +0 -24
  45. package/dist/mixin/magicLinkParent.d.ts +0 -40
  46. package/dist/mixin/magicLinkParent.js +0 -42
  47. package/dist/mixin/singleLine.d.ts +0 -6
  48. package/dist/mixin/singleLine.js +0 -26
  49. package/dist/mixin/sol.d.ts +0 -6
  50. package/dist/mixin/sol.js +0 -43
  51. package/dist/mixin/syntax.d.ts +0 -9
  52. package/dist/mixin/syntax.js +0 -50
  53. package/dist/parser/braces.js +0 -130
  54. package/dist/parser/commentAndExt.js +0 -89
  55. package/dist/parser/converter.js +0 -40
  56. package/dist/parser/externalLinks.js +0 -45
  57. package/dist/parser/hrAndDoubleUnderscore.js +0 -40
  58. package/dist/parser/html.js +0 -38
  59. package/dist/parser/links.js +0 -97
  60. package/dist/parser/list.js +0 -97
  61. package/dist/parser/magicLinks.js +0 -42
  62. package/dist/parser/quotes.js +0 -67
  63. package/dist/parser/selector.js +0 -190
  64. package/dist/parser/table.js +0 -123
  65. package/dist/src/arg.d.ts +0 -58
  66. package/dist/src/arg.js +0 -214
  67. package/dist/src/atom.d.ts +0 -12
  68. package/dist/src/atom.js +0 -27
  69. package/dist/src/attribute.d.ts +0 -71
  70. package/dist/src/attribute.js +0 -502
  71. package/dist/src/attributes.d.ts +0 -109
  72. package/dist/src/attributes.js +0 -356
  73. package/dist/src/converter.d.ts +0 -33
  74. package/dist/src/converter.js +0 -134
  75. package/dist/src/converterFlags.d.ts +0 -87
  76. package/dist/src/converterFlags.js +0 -242
  77. package/dist/src/converterRule.d.ts +0 -77
  78. package/dist/src/converterRule.js +0 -209
  79. package/dist/src/extLink.d.ts +0 -43
  80. package/dist/src/extLink.js +0 -191
  81. package/dist/src/gallery.d.ts +0 -54
  82. package/dist/src/gallery.js +0 -139
  83. package/dist/src/heading.d.ts +0 -47
  84. package/dist/src/heading.js +0 -190
  85. package/dist/src/hidden.d.ts +0 -7
  86. package/dist/src/hidden.js +0 -23
  87. package/dist/src/html.d.ts +0 -65
  88. package/dist/src/html.js +0 -358
  89. package/dist/src/imageParameter.d.ts +0 -65
  90. package/dist/src/imageParameter.js +0 -257
  91. package/dist/src/imagemap.d.ts +0 -54
  92. package/dist/src/imagemap.js +0 -144
  93. package/dist/src/imagemapLink.d.ts +0 -31
  94. package/dist/src/imagemapLink.js +0 -93
  95. package/dist/src/index.d.ts +0 -143
  96. package/dist/src/index.js +0 -851
  97. package/dist/src/link/base.d.ts +0 -52
  98. package/dist/src/link/base.js +0 -228
  99. package/dist/src/link/category.d.ts +0 -13
  100. package/dist/src/link/category.js +0 -28
  101. package/dist/src/link/file.d.ts +0 -98
  102. package/dist/src/link/file.js +0 -272
  103. package/dist/src/link/galleryImage.d.ts +0 -32
  104. package/dist/src/link/galleryImage.js +0 -158
  105. package/dist/src/link/index.d.ts +0 -56
  106. package/dist/src/link/index.js +0 -133
  107. package/dist/src/magicLink.d.ts +0 -59
  108. package/dist/src/magicLink.js +0 -223
  109. package/dist/src/nested.d.ts +0 -43
  110. package/dist/src/nested.js +0 -105
  111. package/dist/src/nowiki/base.d.ts +0 -31
  112. package/dist/src/nowiki/base.js +0 -93
  113. package/dist/src/nowiki/comment.d.ts +0 -25
  114. package/dist/src/nowiki/comment.js +0 -76
  115. package/dist/src/nowiki/dd.d.ts +0 -8
  116. package/dist/src/nowiki/dd.js +0 -24
  117. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -18
  118. package/dist/src/nowiki/doubleUnderscore.js +0 -101
  119. package/dist/src/nowiki/hr.d.ts +0 -5
  120. package/dist/src/nowiki/hr.js +0 -63
  121. package/dist/src/nowiki/index.d.ts +0 -16
  122. package/dist/src/nowiki/index.js +0 -27
  123. package/dist/src/nowiki/list.d.ts +0 -16
  124. package/dist/src/nowiki/list.js +0 -109
  125. package/dist/src/nowiki/listBase.d.ts +0 -5
  126. package/dist/src/nowiki/listBase.js +0 -61
  127. package/dist/src/nowiki/noinclude.d.ts +0 -10
  128. package/dist/src/nowiki/noinclude.js +0 -23
  129. package/dist/src/nowiki/quote.d.ts +0 -14
  130. package/dist/src/nowiki/quote.js +0 -131
  131. package/dist/src/onlyinclude.d.ts +0 -16
  132. package/dist/src/onlyinclude.js +0 -57
  133. package/dist/src/paramTag/index.d.ts +0 -37
  134. package/dist/src/paramTag/index.js +0 -77
  135. package/dist/src/paramTag/inputbox.d.ts +0 -8
  136. package/dist/src/paramTag/inputbox.js +0 -22
  137. package/dist/src/parameter.d.ts +0 -70
  138. package/dist/src/parameter.js +0 -264
  139. package/dist/src/pre.d.ts +0 -31
  140. package/dist/src/pre.js +0 -59
  141. package/dist/src/syntax.d.ts +0 -20
  142. package/dist/src/syntax.js +0 -86
  143. package/dist/src/table/base.d.ts +0 -27
  144. package/dist/src/table/base.js +0 -81
  145. package/dist/src/table/index.d.ts +0 -242
  146. package/dist/src/table/index.js +0 -497
  147. package/dist/src/table/td.d.ts +0 -86
  148. package/dist/src/table/td.js +0 -355
  149. package/dist/src/table/tr.d.ts +0 -32
  150. package/dist/src/table/tr.js +0 -58
  151. package/dist/src/table/trBase.d.ts +0 -53
  152. package/dist/src/table/trBase.js +0 -156
  153. package/dist/src/tagPair/ext.d.ts +0 -32
  154. package/dist/src/tagPair/ext.js +0 -203
  155. package/dist/src/tagPair/include.d.ts +0 -35
  156. package/dist/src/tagPair/include.js +0 -74
  157. package/dist/src/tagPair/index.d.ts +0 -27
  158. package/dist/src/tagPair/index.js +0 -128
  159. package/dist/src/transclude.d.ts +0 -167
  160. package/dist/src/transclude.js +0 -717
  161. package/dist/util/constants.js +0 -27
  162. package/dist/util/debug.js +0 -81
  163. package/dist/util/diff.js +0 -83
  164. package/dist/util/lint.js +0 -31
  165. package/dist/util/string.js +0 -60
  166. package/errors/README +0 -1
  167. package/printed/README +0 -1
@@ -1,356 +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
- /** 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;
@@ -1,33 +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
- /**
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
- }
@@ -1,134 +0,0 @@
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;
@@ -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 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
- }