wikiparser-node 1.4.2 → 1.4.3

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 (103) hide show
  1. package/dist/addon/table.js +5 -1
  2. package/dist/base.d.ts +6 -1
  3. package/dist/index.d.ts +0 -2
  4. package/dist/index.js +3 -3
  5. package/dist/lib/element.d.ts +3 -2
  6. package/dist/lib/element.js +20 -13
  7. package/dist/lib/node.js +13 -10
  8. package/dist/lib/text.js +3 -3
  9. package/dist/lib/title.js +4 -12
  10. package/dist/mixin/attributesParent.d.ts +32 -2
  11. package/dist/mixin/attributesParent.js +14 -25
  12. package/dist/mixin/fixed.d.ts +2 -1
  13. package/dist/mixin/fixed.js +3 -1
  14. package/dist/mixin/flagsParent.d.ts +28 -17
  15. package/dist/mixin/flagsParent.js +12 -25
  16. package/dist/mixin/magicLinkParent.d.ts +14 -8
  17. package/dist/mixin/magicLinkParent.js +7 -8
  18. package/dist/mixin/singleLine.d.ts +2 -1
  19. package/dist/mixin/singleLine.js +3 -2
  20. package/dist/mixin/sol.d.ts +2 -4
  21. package/dist/mixin/sol.js +8 -6
  22. package/dist/mixin/syntax.d.ts +5 -2
  23. package/dist/mixin/syntax.js +14 -18
  24. package/dist/parser/links.js +1 -3
  25. package/dist/src/arg.d.ts +4 -4
  26. package/dist/src/arg.js +4 -4
  27. package/dist/src/attribute.d.ts +9 -7
  28. package/dist/src/attribute.js +271 -218
  29. package/dist/src/attributes.d.ts +3 -3
  30. package/dist/src/attributes.js +0 -1
  31. package/dist/src/converter.d.ts +7 -2
  32. package/dist/src/converter.js +113 -64
  33. package/dist/src/converterFlags.d.ts +5 -5
  34. package/dist/src/converterFlags.js +0 -1
  35. package/dist/src/converterRule.d.ts +5 -5
  36. package/dist/src/converterRule.js +0 -1
  37. package/dist/src/extLink.d.ts +7 -2
  38. package/dist/src/extLink.js +159 -110
  39. package/dist/src/gallery.d.ts +5 -5
  40. package/dist/src/gallery.js +0 -1
  41. package/dist/src/heading.d.ts +8 -8
  42. package/dist/src/heading.js +172 -125
  43. package/dist/src/html.d.ts +8 -5
  44. package/dist/src/html.js +263 -214
  45. package/dist/src/imageParameter.d.ts +2 -2
  46. package/dist/src/imageParameter.js +1 -0
  47. package/dist/src/imagemap.d.ts +5 -5
  48. package/dist/src/imagemap.js +4 -10
  49. package/dist/src/imagemapLink.d.ts +7 -4
  50. package/dist/src/imagemapLink.js +75 -26
  51. package/dist/src/index.js +3 -4
  52. package/dist/src/link/base.d.ts +2 -2
  53. package/dist/src/link/base.js +1 -4
  54. package/dist/src/link/file.d.ts +1 -1
  55. package/dist/src/link/file.js +0 -1
  56. package/dist/src/link/galleryImage.d.ts +2 -1
  57. package/dist/src/link/galleryImage.js +136 -88
  58. package/dist/src/link/index.js +0 -1
  59. package/dist/src/magicLink.d.ts +11 -3
  60. package/dist/src/magicLink.js +170 -120
  61. package/dist/src/nested.d.ts +5 -5
  62. package/dist/src/nested.js +1 -0
  63. package/dist/src/nowiki/base.d.ts +6 -2
  64. package/dist/src/nowiki/base.js +79 -28
  65. package/dist/src/nowiki/comment.d.ts +0 -2
  66. package/dist/src/nowiki/comment.js +0 -9
  67. package/dist/src/nowiki/doubleUnderscore.js +88 -38
  68. package/dist/src/nowiki/hr.d.ts +1 -4
  69. package/dist/src/nowiki/hr.js +53 -4
  70. package/dist/src/nowiki/index.d.ts +2 -2
  71. package/dist/src/nowiki/index.js +1 -0
  72. package/dist/src/nowiki/list.d.ts +1 -4
  73. package/dist/src/nowiki/list.js +88 -39
  74. package/dist/src/nowiki/listBase.d.ts +1 -1
  75. package/dist/src/nowiki/listBase.js +52 -2
  76. package/dist/src/nowiki/quote.d.ts +3 -3
  77. package/dist/src/nowiki/quote.js +102 -54
  78. package/dist/src/paramTag/index.d.ts +5 -5
  79. package/dist/src/paramTag/index.js +2 -1
  80. package/dist/src/parameter.d.ts +11 -8
  81. package/dist/src/parameter.js +225 -176
  82. package/dist/src/pre.d.ts +5 -5
  83. package/dist/src/pre.js +1 -0
  84. package/dist/src/syntax.d.ts +6 -0
  85. package/dist/src/syntax.js +74 -23
  86. package/dist/src/table/base.d.ts +6 -3
  87. package/dist/src/table/base.js +100 -49
  88. package/dist/src/table/index.d.ts +6 -3
  89. package/dist/src/table/index.js +5 -9
  90. package/dist/src/table/td.d.ts +9 -5
  91. package/dist/src/table/td.js +270 -217
  92. package/dist/src/table/tr.d.ts +4 -4
  93. package/dist/src/table/tr.js +1 -0
  94. package/dist/src/tagPair/ext.d.ts +6 -3
  95. package/dist/src/tagPair/ext.js +168 -118
  96. package/dist/src/tagPair/include.d.ts +2 -4
  97. package/dist/src/tagPair/include.js +0 -8
  98. package/dist/src/tagPair/index.d.ts +1 -1
  99. package/dist/src/tagPair/index.js +115 -66
  100. package/dist/src/transclude.d.ts +3 -3
  101. package/dist/src/transclude.js +4 -9
  102. package/dist/util/debug.js +0 -2
  103. package/package.json +3 -3
@@ -1,4 +1,38 @@
1
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
+ };
2
36
  Object.defineProperty(exports, "__esModule", { value: true });
3
37
  exports.AttributeToken = void 0;
4
38
  const lint_1 = require("../util/lint");
@@ -178,245 +212,264 @@ const commonHtmlAttrs = new Set([
178
212
  * 扩展和HTML标签属性
179
213
  * @classdesc `{childNodes: [AtomToken, Token|AtomToken]}`
180
214
  */
181
- class AttributeToken extends (0, fixed_1.fixedToken)(index_2.Token) {
182
- tag;
183
- #equal;
184
- #quotes;
185
- /** 引号是否匹配 */
186
- get balanced() {
187
- return !this.#equal || this.#quotes[0] === this.#quotes[1];
188
- }
189
- /* NOT FOR BROWSER */
190
- set balanced(value) {
191
- if (value) {
192
- this.close();
215
+ let AttributeToken = (() => {
216
+ let _classDecorators = [fixed_1.fixedToken];
217
+ let _classDescriptor;
218
+ let _classExtraInitializers = [];
219
+ let _classThis;
220
+ let _classSuper = index_2.Token;
221
+ var AttributeToken = class extends _classSuper {
222
+ static { _classThis = this; }
223
+ static {
224
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
225
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
226
+ AttributeToken = _classThis = _classDescriptor.value;
227
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
228
+ __runInitializers(_classThis, _classExtraInitializers);
193
229
  }
194
- }
195
- /** getValue()的getter */
196
- get value() {
197
- return this.getValue();
198
- }
199
- set value(value) {
200
- this.setValue(value);
201
- }
202
- /* NOT FOR BROWSER END */
203
- /**
204
- * @param type 标签类型
205
- * @param tag 标签名
206
- * @param key 属性名
207
- * @param equal 等号
208
- * @param value 属性值
209
- * @param quotes 引号
210
- */
211
- constructor(type, tag, key, equal = '', value, quotes = [], config = index_1.default.getConfig(), accum = []) {
212
- const keyToken = new atom_1.AtomToken(key, 'attr-key', config, accum, {
213
- [type === 'ext-attr' ? 'AstText' : 'Stage-1']: ':', ArgToken: ':', TranscludeToken: ':',
214
- });
215
- let valueToken;
216
- if (key === 'title' || tag === 'img' && key === 'alt') {
217
- valueToken = new index_2.Token(value, config, accum, {
218
- [`Stage-${stages[type]}`]: ':', ConverterToken: ':',
219
- });
220
- valueToken.type = 'attr-value';
221
- valueToken.setAttribute('stage', constants_1.MAX_STAGE - 1);
222
- }
223
- else if (tag === 'gallery' && key === 'caption') {
224
- const newConfig = {
225
- ...config,
226
- excludes: [...config.excludes, 'quote', 'extLink', 'magicLink', 'list'],
227
- };
228
- valueToken = new index_2.Token(value, newConfig, accum, {
229
- AstText: ':', LinkToken: ':', FileToken: ':', CategoryToken: ':', ConverterToken: ':',
230
- });
231
- valueToken.type = 'attr-value';
232
- valueToken.setAttribute('stage', 5);
233
- }
234
- else if (tag === 'choose' && (key === 'before' || key === 'after')) {
235
- const newConfig = {
236
- ...config,
237
- excludes: [...config.excludes, 'heading', 'html', 'table', 'hr', 'list'],
238
- };
239
- valueToken = new index_2.Token(value, newConfig, accum, {
240
- ArgToken: ':',
241
- TranscludeToken: ':',
242
- LinkToken: ':',
243
- FileToken: ':',
244
- CategoryToken: ':',
245
- QuoteToken: ':',
246
- ExtLinkToken: ':',
247
- MagicLinkToken: ':',
248
- ConverterToken: ':',
249
- });
250
- valueToken.type = 'attr-value';
251
- valueToken.setAttribute('stage', 1);
230
+ #tag;
231
+ #equal;
232
+ #quotes;
233
+ /* NOT FOR BROWSER END */
234
+ /** @private */
235
+ get tag() {
236
+ return this.#tag;
252
237
  }
253
- else {
254
- valueToken = new atom_1.AtomToken(value, 'attr-value', config, accum, {
255
- [`Stage-${stages[type]}`]: ':',
256
- });
238
+ /** 引号是否匹配 */
239
+ get balanced() {
240
+ return !this.#equal || this.#quotes[0] === this.#quotes[1];
257
241
  }
258
- super(undefined, config, accum);
259
- this.type = type;
260
- this.append(keyToken, valueToken);
261
- this.#equal = equal;
262
- this.#quotes = [...quotes];
263
- this.tag = tag;
264
242
  /* NOT FOR BROWSER */
265
- this.seal('tag', true);
266
- /* NOT FOR BROWSER END */
267
- this.setAttribute('name', (0, string_1.removeComment)(key).trim().toLowerCase());
268
- }
269
- /** @private */
270
- afterBuild() {
271
- if (this.#equal.includes('\0')) {
272
- this.#equal = this.buildFromStr(this.#equal, constants_1.BuildMethod.String);
243
+ set balanced(value) {
244
+ if (value) {
245
+ this.close();
246
+ }
273
247
  }
274
- if (this.parentNode) {
275
- this.setAttribute('tag', this.parentNode.name);
248
+ /** getValue()的getter */
249
+ get value() {
250
+ return this.getValue();
276
251
  }
277
- this.setAttribute('name', this.firstChild.text().trim().toLowerCase());
278
- }
279
- /** @private */
280
- toString() {
281
- const [quoteStart = '', quoteEnd = ''] = this.#quotes;
282
- return this.#equal ? `${super.toString(`${this.#equal}${quoteStart}`)}${quoteEnd}` : String(this.firstChild);
283
- }
284
- /** @override */
285
- text() {
286
- return this.#equal ? `${super.text(`${this.#equal.trim()}"`)}"` : this.firstChild.text();
287
- }
288
- /** @private */
289
- getGaps() {
290
- return this.#equal ? this.#equal.length + (this.#quotes[0]?.length ?? 0) : 0;
291
- }
292
- /** @override */
293
- lint(start = this.getAbsoluteIndex()) {
294
- const errors = super.lint(start), { balanced, firstChild, lastChild, type, name, tag } = this, value = this.getValue();
295
- let rect;
296
- if (!balanced) {
297
- const root = this.getRootNode();
298
- rect = { start, ...root.posFromIndex(start) };
299
- const e = (0, lint_1.generateForChild)(lastChild, rect, index_1.default.msg('unclosed $1', 'quotes'), 'warning');
300
- errors.push({
301
- ...e,
302
- startIndex: e.startIndex - 1,
303
- startCol: e.startCol - 1,
252
+ set value(value) {
253
+ this.setValue(value);
254
+ }
255
+ /* NOT FOR BROWSER END */
256
+ /**
257
+ * @param type 标签类型
258
+ * @param tag 标签名
259
+ * @param key 属性名
260
+ * @param equal 等号
261
+ * @param value 属性值
262
+ * @param quotes 引号
263
+ */
264
+ constructor(type, tag, key, equal = '', value, quotes = [], config = index_1.default.getConfig(), accum = []) {
265
+ const keyToken = new atom_1.AtomToken(key, 'attr-key', config, accum, {
266
+ [type === 'ext-attr' ? 'AstText' : 'Stage-1']: ':', ArgToken: ':', TranscludeToken: ':',
304
267
  });
268
+ let valueToken;
269
+ if (key === 'title' || tag === 'img' && key === 'alt') {
270
+ valueToken = new index_2.Token(value, config, accum, {
271
+ [`Stage-${stages[type]}`]: ':', ConverterToken: ':',
272
+ });
273
+ valueToken.type = 'attr-value';
274
+ valueToken.setAttribute('stage', constants_1.MAX_STAGE - 1);
275
+ }
276
+ else if (tag === 'gallery' && key === 'caption') {
277
+ const newConfig = {
278
+ ...config,
279
+ excludes: [...config.excludes, 'quote', 'extLink', 'magicLink', 'list'],
280
+ };
281
+ valueToken = new index_2.Token(value, newConfig, accum, {
282
+ AstText: ':', LinkToken: ':', FileToken: ':', CategoryToken: ':', ConverterToken: ':',
283
+ });
284
+ valueToken.type = 'attr-value';
285
+ valueToken.setAttribute('stage', 5);
286
+ }
287
+ else if (tag === 'choose' && (key === 'before' || key === 'after')) {
288
+ const newConfig = {
289
+ ...config,
290
+ excludes: [...config.excludes, 'heading', 'html', 'table', 'hr', 'list'],
291
+ };
292
+ valueToken = new index_2.Token(value, newConfig, accum, {
293
+ ArgToken: ':',
294
+ TranscludeToken: ':',
295
+ LinkToken: ':',
296
+ FileToken: ':',
297
+ CategoryToken: ':',
298
+ QuoteToken: ':',
299
+ ExtLinkToken: ':',
300
+ MagicLinkToken: ':',
301
+ ConverterToken: ':',
302
+ });
303
+ valueToken.type = 'attr-value';
304
+ valueToken.setAttribute('stage', 1);
305
+ }
306
+ else {
307
+ valueToken = new atom_1.AtomToken(value, 'attr-value', config, accum, {
308
+ [`Stage-${stages[type]}`]: ':',
309
+ });
310
+ }
311
+ super(undefined, config, accum);
312
+ this.type = type;
313
+ this.append(keyToken, valueToken);
314
+ this.#equal = equal;
315
+ this.#quotes = [...quotes];
316
+ this.#tag = tag;
317
+ this.setAttribute('name', (0, string_1.removeComment)(key).trim().toLowerCase());
305
318
  }
306
- if (extAttrs[tag] && !extAttrs[tag].has(name)
307
- || (type === 'ext-attr' ? tag in htmlAttrs : !/\{\{[^{]+\}\}/u.test(name))
308
- && !htmlAttrs[tag]?.has(name)
309
- && !/^(?:xmlns:[\w:.-]+|data-[^:]*)$/u.test(name)
310
- && (tag === 'meta' || tag === 'link' || !commonHtmlAttrs.has(name))) {
311
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
312
- errors.push((0, lint_1.generateForChild)(firstChild, rect, 'illegal attribute name'));
319
+ /** @private */
320
+ afterBuild() {
321
+ if (this.#equal.includes('\0')) {
322
+ this.#equal = this.buildFromStr(this.#equal, constants_1.BuildMethod.String);
323
+ }
324
+ if (this.parentNode) {
325
+ this.#tag = this.parentNode.name;
326
+ }
327
+ this.setAttribute('name', this.firstChild.text().trim().toLowerCase());
313
328
  }
314
- else if (obsoleteAttrs[tag]?.has(name)) {
315
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
316
- errors.push((0, lint_1.generateForChild)(firstChild, rect, 'obsolete attribute', 'warning'));
329
+ /** @private */
330
+ toString() {
331
+ const [quoteStart = '', quoteEnd = ''] = this.#quotes;
332
+ return this.#equal ? `${super.toString(`${this.#equal}${quoteStart}`)}${quoteEnd}` : String(this.firstChild);
317
333
  }
318
- else if (name === 'style' && typeof value === 'string' && insecureStyle.test(value)) {
319
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
320
- errors.push((0, lint_1.generateForChild)(lastChild, rect, 'insecure style'));
334
+ /** @override */
335
+ text() {
336
+ return this.#equal ? `${super.text(`${this.#equal.trim()}"`)}"` : this.firstChild.text();
321
337
  }
322
- else if (name === 'tabindex' && typeof value === 'string' && value.trim() !== '0') {
323
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
324
- errors.push((0, lint_1.generateForChild)(lastChild, rect, 'nonzero tabindex'));
338
+ /** @private */
339
+ getGaps() {
340
+ return this.#equal ? this.#equal.length + (this.#quotes[0]?.length ?? 0) : 0;
325
341
  }
326
- return errors;
327
- }
328
- /** 获取属性值 */
329
- getValue() {
330
- if (this.#equal) {
331
- const value = this.lastChild.text();
332
- if (this.#quotes[1]) {
333
- return value;
342
+ /** @override */
343
+ lint(start = this.getAbsoluteIndex()) {
344
+ const errors = super.lint(start), { balanced, firstChild, lastChild, type, name, tag } = this, value = this.getValue();
345
+ let rect;
346
+ if (!balanced) {
347
+ const root = this.getRootNode();
348
+ rect = { start, ...root.posFromIndex(start) };
349
+ const e = (0, lint_1.generateForChild)(lastChild, rect, index_1.default.msg('unclosed $1', 'quotes'), 'warning');
350
+ errors.push({
351
+ ...e,
352
+ startIndex: e.startIndex - 1,
353
+ startCol: e.startCol - 1,
354
+ });
334
355
  }
335
- return value[this.#quotes[0] ? 'trimEnd' : 'trim']();
336
- }
337
- return this.type === 'ext-attr' || '';
338
- }
339
- /** @override */
340
- print() {
341
- const [quoteStart = '', quoteEnd = ''] = this.#quotes;
342
- return this.#equal ? super.print({ sep: `${this.#equal}${quoteStart}`, post: quoteEnd }) : super.print();
343
- }
344
- /* NOT FOR BROWSER */
345
- /** @private */
346
- getAttribute(key) {
347
- if (key === 'equal') {
348
- return this.#equal;
349
- }
350
- return key === 'quotes' ? this.#quotes : super.getAttribute(key);
351
- }
352
- /** @override */
353
- cloneNode() {
354
- const [key, value] = this.cloneChildNodes(), config = this.getAttribute('config');
355
- return debug_1.Shadow.run(() => {
356
- // @ts-expect-error abstract class
357
- const token = new AttributeToken(this.type, this.tag, '', this.#equal, '', this.#quotes, config);
358
- token.firstChild.safeReplaceWith(key);
359
- token.lastChild.safeReplaceWith(value);
360
- token.setAttribute('name', this.name);
361
- return token;
362
- });
363
- }
364
- /** 转义等号 */
365
- escape() {
366
- this.#equal = '{{=}}';
367
- }
368
- /** 闭合引号 */
369
- close() {
370
- const [opening] = this.#quotes;
371
- if (opening) {
372
- this.#quotes[1] = opening;
356
+ const attrs = extAttrs[tag];
357
+ if (attrs && !attrs.has(name)
358
+ || (type === 'ext-attr' ? tag in htmlAttrs : !/\{\{[^{]+\}\}/u.test(name))
359
+ && !htmlAttrs[tag]?.has(name)
360
+ && !/^(?:xmlns:[\w:.-]+|data-[^:]*)$/u.test(name)
361
+ && (tag === 'meta' || tag === 'link' || !commonHtmlAttrs.has(name))) {
362
+ rect ??= { start, ...this.getRootNode().posFromIndex(start) };
363
+ errors.push((0, lint_1.generateForChild)(firstChild, rect, 'illegal attribute name'));
364
+ }
365
+ else if (obsoleteAttrs[tag]?.has(name)) {
366
+ rect ??= { start, ...this.getRootNode().posFromIndex(start) };
367
+ errors.push((0, lint_1.generateForChild)(firstChild, rect, 'obsolete attribute', 'warning'));
368
+ }
369
+ else if (name === 'style' && typeof value === 'string' && insecureStyle.test(value)) {
370
+ rect ??= { start, ...this.getRootNode().posFromIndex(start) };
371
+ errors.push((0, lint_1.generateForChild)(lastChild, rect, 'insecure style'));
372
+ }
373
+ else if (name === 'tabindex' && typeof value === 'string' && value.trim() !== '0') {
374
+ rect ??= { start, ...this.getRootNode().posFromIndex(start) };
375
+ errors.push((0, lint_1.generateForChild)(lastChild, rect, 'nonzero tabindex'));
376
+ }
377
+ return errors;
373
378
  }
374
- }
375
- /**
376
- * 设置属性值
377
- * @param value 参数值
378
- * @throws `RangeError` 扩展标签属性不能包含 ">"
379
- * @throws `RangeError` 同时包含单引号和双引号
380
- */
381
- setValue(value) {
382
- if (value === false) {
383
- this.remove();
384
- return;
379
+ /** 获取属性值 */
380
+ getValue() {
381
+ if (this.#equal) {
382
+ const value = this.lastChild.text();
383
+ if (this.#quotes[1]) {
384
+ return value;
385
+ }
386
+ return value[this.#quotes[0] ? 'trimEnd' : 'trim']();
387
+ }
388
+ return this.type === 'ext-attr' || '';
385
389
  }
386
- else if (value === true) {
387
- this.#equal = '';
388
- return;
390
+ /** @override */
391
+ print() {
392
+ const [quoteStart = '', quoteEnd = ''] = this.#quotes;
393
+ return this.#equal ? super.print({ sep: `${this.#equal}${quoteStart}`, post: quoteEnd }) : super.print();
389
394
  }
390
- else if (this.type === 'ext-attr' && value.includes('>')) {
391
- throw new RangeError('扩展标签属性不能包含 ">"!');
395
+ /* NOT FOR BROWSER */
396
+ /** @private */
397
+ getAttribute(key) {
398
+ if (key === 'equal') {
399
+ return this.#equal;
400
+ }
401
+ return key === 'quotes' ? this.#quotes : super.getAttribute(key);
392
402
  }
393
- else if (value.includes('"') && value.includes(`'`)) {
394
- throw new RangeError('属性值不能同时包含单引号和双引号!');
403
+ /** @override */
404
+ cloneNode() {
405
+ const [key, value] = this.cloneChildNodes(), config = this.getAttribute('config');
406
+ return debug_1.Shadow.run(() => {
407
+ // @ts-expect-error abstract class
408
+ const token = new AttributeToken(this.type, this.tag, '', this.#equal, '', this.#quotes, config);
409
+ token.firstChild.safeReplaceWith(key);
410
+ token.lastChild.safeReplaceWith(value);
411
+ token.setAttribute('name', this.name);
412
+ return token;
413
+ });
395
414
  }
396
- const config = this.getAttribute('config'), { childNodes } = index_1.default.parse(value, this.getAttribute('include'), stages[this.type] + 1, config);
397
- this.lastChild.replaceChildren(...childNodes);
398
- if (value.includes('"')) {
399
- this.#quotes = [`'`, `'`];
415
+ /** 转义等号 */
416
+ escape() {
417
+ this.#equal = '{{=}}';
400
418
  }
401
- else if (value.includes(`'`) || !this.#quotes[0]) {
402
- this.#quotes = ['"', '"'];
419
+ /** 闭合引号 */
420
+ close() {
421
+ const [opening] = this.#quotes;
422
+ if (opening) {
423
+ this.#quotes[1] = opening;
424
+ }
403
425
  }
404
- else {
405
- this.close();
426
+ /**
427
+ * 设置属性值
428
+ * @param value 参数值
429
+ * @throws `RangeError` 扩展标签属性不能包含 ">"
430
+ * @throws `RangeError` 同时包含单引号和双引号
431
+ */
432
+ setValue(value) {
433
+ if (value === false) {
434
+ this.remove();
435
+ return;
436
+ }
437
+ else if (value === true) {
438
+ this.#equal = '';
439
+ return;
440
+ }
441
+ else if (this.type === 'ext-attr' && value.includes('>')) {
442
+ throw new RangeError('扩展标签属性不能包含 ">"!');
443
+ }
444
+ else if (value.includes('"') && value.includes(`'`)) {
445
+ throw new RangeError('属性值不能同时包含单引号和双引号!');
446
+ }
447
+ const config = this.getAttribute('config'), { childNodes } = index_1.default.parse(value, this.getAttribute('include'), stages[this.type] + 1, config);
448
+ this.lastChild.replaceChildren(...childNodes);
449
+ if (value.includes('"')) {
450
+ this.#quotes = [`'`, `'`];
451
+ }
452
+ else if (value.includes(`'`) || !this.#quotes[0]) {
453
+ this.#quotes = ['"', '"'];
454
+ }
455
+ else {
456
+ this.close();
457
+ }
406
458
  }
407
- }
408
- /**
409
- * 修改属性名
410
- * @param key 新属性名
411
- * @throws `Error` title和alt属性不能更名
412
- */
413
- rename(key) {
414
- if (this.name === 'title' || this.name === 'alt' && this.tag === 'img') {
415
- throw new Error(`${this.name} 属性不能更名!`);
459
+ /**
460
+ * 修改属性名
461
+ * @param key 新属性名
462
+ * @throws `Error` title和alt属性不能更名
463
+ */
464
+ rename(key) {
465
+ if (this.name === 'title' || this.name === 'alt' && this.tag === 'img') {
466
+ throw new Error(`${this.name} 属性不能更名!`);
467
+ }
468
+ const config = this.getAttribute('config'), { childNodes } = index_1.default.parse(key, this.getAttribute('include'), stages[this.type] + 1, config);
469
+ this.firstChild.replaceChildren(...childNodes);
416
470
  }
417
- const config = this.getAttribute('config'), { childNodes } = index_1.default.parse(key, this.getAttribute('include'), stages[this.type] + 1, config);
418
- this.firstChild.replaceChildren(...childNodes);
419
- }
420
- }
471
+ };
472
+ return AttributeToken = _classThis;
473
+ })();
421
474
  exports.AttributeToken = AttributeToken;
422
475
  constants_1.classes['AttributeToken'] = __filename;
@@ -15,12 +15,12 @@ export declare abstract class AttributesToken extends Token {
15
15
  type: AttributesTypes;
16
16
  readonly name: string;
17
17
  readonly childNodes: readonly (AtomToken | AttributeToken)[];
18
- abstract get children(): (AtomToken | AttributeToken)[];
19
18
  abstract get firstChild(): AtomToken | AttributeToken | undefined;
20
- abstract get firstElementChild(): AtomToken | AttributeToken | undefined;
21
19
  abstract get lastChild(): AtomToken | AttributeToken | undefined;
22
- abstract get lastElementChild(): AtomToken | AttributeToken | undefined;
23
20
  abstract get parentNode(): ExtToken | HtmlToken | TableToken | TrToken | TdToken | undefined;
21
+ abstract get children(): (AtomToken | AttributeToken)[];
22
+ abstract get firstElementChild(): AtomToken | AttributeToken | undefined;
23
+ abstract get lastElementChild(): AtomToken | AttributeToken | undefined;
24
24
  abstract get parentElement(): ExtToken | HtmlToken | TableToken | TrToken | TdToken | undefined;
25
25
  /** getAttrs()方法的getter写法 */
26
26
  get attributes(): Record<string, string | true>;
@@ -26,7 +26,6 @@ const toDirty = (type) => `${toAttributeType(type)}-dirty`;
26
26
  * @classdesc `{childNodes: ...AtomToken|AttributeToken}`
27
27
  */
28
28
  class AttributesToken extends index_2.Token {
29
- /* NOT FOR BROWSER */
30
29
  /** getAttrs()方法的getter写法 */
31
30
  get attributes() {
32
31
  return this.getAttrs();
@@ -5,11 +5,17 @@ import { ConverterRuleToken } from './converterRule';
5
5
  import type { FlagsParentBase } from '../mixin/flagsParent';
6
6
  export interface ConverterToken extends FlagsParentBase {
7
7
  }
8
+ /**
9
+ * 转换
10
+ * @classdesc `{childNodes: [ConverterFlagsToken, ...ConverterRuleToken]}`
11
+ */
8
12
  export declare abstract class ConverterToken extends Token {
9
13
  readonly type = "converter";
10
14
  readonly childNodes: readonly [ConverterFlagsToken, ...ConverterRuleToken[]];
11
- abstract get children(): [ConverterFlagsToken, ...ConverterRuleToken[]];
15
+ abstract get firstChild(): ConverterFlagsToken;
12
16
  abstract get lastChild(): ConverterFlagsToken | ConverterRuleToken;
17
+ abstract get children(): [ConverterFlagsToken, ...ConverterRuleToken[]];
18
+ abstract get firstElementChild(): ConverterFlagsToken;
13
19
  abstract get lastElementChild(): ConverterFlagsToken | ConverterRuleToken;
14
20
  /** 是否不转换 */
15
21
  get noConvert(): boolean;
@@ -25,4 +31,3 @@ export declare abstract class ConverterToken extends Token {
25
31
  /** @override */
26
32
  cloneNode(): this;
27
33
  }
28
- export {};