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