wikiparser-node 1.9.2-b → 1.9.2

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/README.md +18 -18
  2. package/config/.schema.json +181 -0
  3. package/config/enwiki.json +814 -1
  4. package/config/llwiki.json +35 -1
  5. package/config/moegirl.json +44 -1
  6. package/config/zhwiki.json +466 -1
  7. package/dist/addon/table.js +486 -0
  8. package/dist/addon/token.js +240 -0
  9. package/dist/addon/transclude.js +185 -0
  10. package/dist/base.d.ts +73 -0
  11. package/dist/base.js +39 -0
  12. package/dist/index.d.ts +31 -0
  13. package/dist/index.js +232 -0
  14. package/dist/internal.d.ts +46 -0
  15. package/dist/lib/element.d.ts +124 -0
  16. package/dist/lib/element.js +600 -0
  17. package/dist/lib/node.d.ts +166 -0
  18. package/dist/lib/node.js +472 -0
  19. package/dist/lib/range.d.ts +105 -0
  20. package/dist/lib/range.js +406 -0
  21. package/dist/lib/ranges.d.ts +28 -0
  22. package/dist/lib/ranges.js +126 -0
  23. package/dist/lib/rect.d.ts +18 -0
  24. package/dist/lib/rect.js +34 -0
  25. package/dist/lib/text.d.ts +54 -0
  26. package/dist/lib/text.js +345 -0
  27. package/dist/lib/title.d.ts +40 -0
  28. package/dist/lib/title.js +197 -0
  29. package/dist/mixin/attributesParent.d.ts +49 -0
  30. package/dist/mixin/attributesParent.js +82 -0
  31. package/dist/mixin/fixed.d.ts +5 -0
  32. package/dist/mixin/fixed.js +32 -0
  33. package/dist/mixin/flagsParent.d.ts +41 -0
  34. package/dist/mixin/flagsParent.js +60 -0
  35. package/dist/mixin/hidden.d.ts +6 -0
  36. package/dist/mixin/hidden.js +29 -0
  37. package/dist/mixin/magicLinkParent.d.ts +19 -0
  38. package/dist/mixin/magicLinkParent.js +43 -0
  39. package/dist/mixin/singleLine.d.ts +5 -0
  40. package/dist/mixin/singleLine.js +27 -0
  41. package/dist/mixin/sol.d.ts +5 -0
  42. package/dist/mixin/sol.js +44 -0
  43. package/dist/mixin/syntax.d.ts +8 -0
  44. package/dist/mixin/syntax.js +47 -0
  45. package/dist/parser/braces.js +150 -0
  46. package/dist/parser/commentAndExt.js +79 -0
  47. package/dist/parser/converter.js +39 -0
  48. package/dist/parser/externalLinks.js +37 -0
  49. package/dist/parser/hrAndDoubleUnderscore.js +42 -0
  50. package/dist/parser/html.js +38 -0
  51. package/dist/parser/links.js +101 -0
  52. package/dist/parser/list.js +97 -0
  53. package/dist/parser/magicLinks.js +53 -0
  54. package/dist/parser/quotes.js +67 -0
  55. package/dist/parser/redirect.js +26 -0
  56. package/dist/parser/selector.js +190 -0
  57. package/dist/parser/table.js +123 -0
  58. package/dist/src/arg.d.ts +52 -0
  59. package/dist/src/arg.js +213 -0
  60. package/dist/src/atom.d.ts +12 -0
  61. package/dist/src/atom.js +26 -0
  62. package/dist/src/attribute.d.ts +65 -0
  63. package/dist/src/attribute.js +483 -0
  64. package/dist/src/attributes.d.ts +103 -0
  65. package/dist/src/attributes.js +350 -0
  66. package/dist/src/converter.d.ts +29 -0
  67. package/dist/src/converter.js +134 -0
  68. package/dist/src/converterFlags.d.ts +81 -0
  69. package/dist/src/converterFlags.js +239 -0
  70. package/dist/src/converterRule.d.ts +73 -0
  71. package/dist/src/converterRule.js +210 -0
  72. package/dist/src/extLink.d.ts +37 -0
  73. package/dist/src/extLink.js +191 -0
  74. package/dist/src/gallery.d.ts +48 -0
  75. package/dist/src/gallery.js +139 -0
  76. package/dist/src/heading.d.ts +41 -0
  77. package/dist/src/heading.js +185 -0
  78. package/dist/src/hidden.d.ts +10 -0
  79. package/dist/src/hidden.js +79 -0
  80. package/dist/src/html.d.ts +58 -0
  81. package/dist/src/html.js +334 -0
  82. package/dist/src/imageParameter.d.ts +59 -0
  83. package/dist/src/imageParameter.js +246 -0
  84. package/dist/src/imagemap.d.ts +48 -0
  85. package/dist/src/imagemap.js +145 -0
  86. package/dist/src/imagemapLink.d.ts +31 -0
  87. package/dist/src/imagemapLink.js +93 -0
  88. package/dist/src/index.d.ts +130 -0
  89. package/dist/src/index.js +721 -0
  90. package/dist/src/link/base.d.ts +46 -0
  91. package/dist/src/link/base.js +224 -0
  92. package/dist/src/link/category.d.ts +22 -0
  93. package/dist/src/link/category.js +30 -0
  94. package/dist/src/link/file.d.ts +96 -0
  95. package/dist/src/link/file.js +274 -0
  96. package/dist/src/link/galleryImage.d.ts +30 -0
  97. package/dist/src/link/galleryImage.js +158 -0
  98. package/dist/src/link/index.d.ts +52 -0
  99. package/dist/src/link/index.js +133 -0
  100. package/dist/src/link/redirectTarget.d.ts +37 -0
  101. package/dist/src/link/redirectTarget.js +95 -0
  102. package/dist/src/magicLink.d.ts +60 -0
  103. package/dist/src/magicLink.js +270 -0
  104. package/dist/src/nested.d.ts +41 -0
  105. package/dist/src/nested.js +105 -0
  106. package/dist/src/nowiki/base.d.ts +31 -0
  107. package/dist/src/nowiki/base.js +91 -0
  108. package/dist/src/nowiki/comment.d.ts +15 -0
  109. package/dist/src/nowiki/comment.js +123 -0
  110. package/dist/src/nowiki/dd.d.ts +8 -0
  111. package/dist/src/nowiki/dd.js +24 -0
  112. package/dist/src/nowiki/doubleUnderscore.d.ts +16 -0
  113. package/dist/src/nowiki/doubleUnderscore.js +96 -0
  114. package/dist/src/nowiki/hr.d.ts +5 -0
  115. package/dist/src/nowiki/hr.js +63 -0
  116. package/dist/src/nowiki/index.d.ts +14 -0
  117. package/dist/src/nowiki/index.js +29 -0
  118. package/dist/src/nowiki/list.d.ts +16 -0
  119. package/dist/src/nowiki/list.js +109 -0
  120. package/dist/src/nowiki/listBase.d.ts +5 -0
  121. package/dist/src/nowiki/listBase.js +61 -0
  122. package/dist/src/nowiki/noinclude.d.ts +10 -0
  123. package/dist/src/nowiki/noinclude.js +73 -0
  124. package/dist/src/nowiki/quote.d.ts +17 -0
  125. package/dist/src/nowiki/quote.js +131 -0
  126. package/dist/src/onlyinclude.d.ts +14 -0
  127. package/dist/src/onlyinclude.js +57 -0
  128. package/dist/src/paramTag/index.d.ts +31 -0
  129. package/dist/src/paramTag/index.js +77 -0
  130. package/dist/src/paramTag/inputbox.d.ts +8 -0
  131. package/dist/src/paramTag/inputbox.js +22 -0
  132. package/dist/src/parameter.d.ts +66 -0
  133. package/dist/src/parameter.js +265 -0
  134. package/dist/src/pre.d.ts +29 -0
  135. package/dist/src/pre.js +59 -0
  136. package/dist/src/redirect.d.ts +31 -0
  137. package/dist/src/redirect.js +121 -0
  138. package/dist/src/syntax.d.ts +17 -0
  139. package/dist/src/syntax.js +84 -0
  140. package/dist/src/table/base.d.ts +29 -0
  141. package/dist/src/table/base.js +82 -0
  142. package/dist/src/table/index.d.ts +239 -0
  143. package/dist/src/table/index.js +502 -0
  144. package/dist/src/table/td.d.ts +78 -0
  145. package/dist/src/table/td.js +368 -0
  146. package/dist/src/table/tr.d.ts +30 -0
  147. package/dist/src/table/tr.js +57 -0
  148. package/dist/src/table/trBase.d.ts +49 -0
  149. package/dist/src/table/trBase.js +156 -0
  150. package/dist/src/tagPair/ext.d.ts +30 -0
  151. package/dist/src/tagPair/ext.js +201 -0
  152. package/dist/src/tagPair/include.d.ts +35 -0
  153. package/dist/src/tagPair/include.js +124 -0
  154. package/dist/src/tagPair/index.d.ts +23 -0
  155. package/dist/src/tagPair/index.js +128 -0
  156. package/dist/src/transclude.d.ts +160 -0
  157. package/dist/src/transclude.js +579 -0
  158. package/dist/util/constants.js +25 -0
  159. package/dist/util/debug.js +97 -0
  160. package/dist/util/diff.js +83 -0
  161. package/dist/util/lint.js +32 -0
  162. package/dist/util/string.js +60 -0
  163. package/errors/README +1 -0
  164. package/package.json +20 -30
  165. package/printed/README +1 -0
  166. package/README.en.md +0 -57
  167. package/bundle/bundle.min.js +0 -38
  168. package/extensions/dist/base.js +0 -64
  169. package/extensions/dist/editor.js +0 -159
  170. package/extensions/dist/highlight.js +0 -58
  171. package/extensions/dist/lint.js +0 -72
  172. package/extensions/editor.css +0 -64
  173. package/extensions/ui.css +0 -144
@@ -0,0 +1,483 @@
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.AttributeToken = void 0;
38
+ const lint_1 = require("../util/lint");
39
+ const rect_1 = require("../lib/rect");
40
+ const string_1 = require("../util/string");
41
+ const debug_1 = require("../util/debug");
42
+ const constants_1 = require("../util/constants");
43
+ const fixed_1 = require("../mixin/fixed");
44
+ const index_1 = require("../index");
45
+ const index_2 = require("./index");
46
+ const atom_1 = require("./atom");
47
+ /* NOT FOR BROWSER */
48
+ const stages = { 'ext-attr': 0, 'html-attr': 2, 'table-attr': 3 };
49
+ /* NOT FOR BROWSER END */
50
+ const commonHtmlAttrs = new Set([
51
+ 'id',
52
+ 'class',
53
+ 'style',
54
+ 'lang',
55
+ 'dir',
56
+ 'title',
57
+ 'tabindex',
58
+ 'aria-describedby',
59
+ 'aria-flowto',
60
+ 'aria-hidden',
61
+ 'aria-label',
62
+ 'aria-labelledby',
63
+ 'aria-level',
64
+ 'aria-owns',
65
+ 'role',
66
+ 'about',
67
+ 'property',
68
+ 'resource',
69
+ 'datatype',
70
+ 'typeof',
71
+ 'itemid',
72
+ 'itemprop',
73
+ 'itemref',
74
+ 'itemscope',
75
+ 'itemtype',
76
+ ]), blockAttrs = new Set(['align']), citeAttrs = new Set(['cite']), citeAndAttrs = new Set(['cite', 'datetime']), widthAttrs = new Set(['width']), obsoleteTdAttrs = new Set(['axis', 'align', 'bgcolor', 'height', 'width', 'valign']), tdAttrs = new Set([...obsoleteTdAttrs, 'abbr', 'headers', 'scope', 'rowspan', 'colspan']), typeAttrs = new Set(['type']), obsoleteTableAttrs = new Set(['summary', 'align', 'bgcolor', 'cellpadding', 'cellspacing', 'frame', 'rules', 'width']), brAttrs = new Set(['clear']), trAttrs = new Set(['bgcolor', 'align', 'valign']), htmlAttrs = {
77
+ div: blockAttrs,
78
+ h1: blockAttrs,
79
+ h2: blockAttrs,
80
+ h3: blockAttrs,
81
+ h4: blockAttrs,
82
+ h5: blockAttrs,
83
+ h6: blockAttrs,
84
+ blockquote: citeAttrs,
85
+ q: citeAttrs,
86
+ p: blockAttrs,
87
+ br: brAttrs,
88
+ pre: widthAttrs,
89
+ ins: citeAndAttrs,
90
+ del: citeAndAttrs,
91
+ ul: typeAttrs,
92
+ ol: new Set(['type', 'start', 'reversed']),
93
+ li: new Set(['type', 'value']),
94
+ table: new Set([...obsoleteTableAttrs, 'border']),
95
+ caption: blockAttrs,
96
+ tr: trAttrs,
97
+ td: tdAttrs,
98
+ th: tdAttrs,
99
+ img: new Set(['alt', 'src', 'width', 'height', 'srcset']),
100
+ font: new Set(['size', 'color', 'face']),
101
+ hr: widthAttrs,
102
+ rt: new Set(['rbspan']),
103
+ data: new Set(['value']),
104
+ time: new Set(['datetime']),
105
+ meta: new Set(['itemprop', 'content']),
106
+ link: new Set(['itemprop', 'href', 'title']),
107
+ gallery: new Set(['mode', 'showfilename', 'caption', 'perrow', 'widths', 'heights', 'showthumbnails', 'type']),
108
+ poem: new Set(['compact', 'align']),
109
+ categorytree: new Set([
110
+ 'align',
111
+ 'hideroot',
112
+ 'onlyroot',
113
+ 'depth',
114
+ 'mode',
115
+ 'hideprefix',
116
+ 'namespaces',
117
+ 'showcount',
118
+ 'notranslations',
119
+ ]),
120
+ combooption: new Set(['name', 'for', 'inline', 'align']),
121
+ }, empty = new Set(), extAttrs = {
122
+ nowiki: empty,
123
+ indicator: new Set(['name']),
124
+ langconvert: new Set(['from', 'to']),
125
+ ref: new Set(['group', 'name', 'extends', 'follow', 'dir']),
126
+ references: new Set(['group', 'responsive']),
127
+ charinsert: new Set(['label']),
128
+ choose: new Set(['uncached', 'before', 'after']),
129
+ option: new Set(['weight']),
130
+ imagemap: empty,
131
+ inputbox: empty,
132
+ templatestyles: new Set(['src', 'wrapper']),
133
+ dynamicpagelist: empty,
134
+ poll: new Set(['id', 'show-results-before-voting']),
135
+ sm2: typeAttrs,
136
+ flashmp3: typeAttrs,
137
+ score: new Set([
138
+ 'line_width_inches',
139
+ 'lang',
140
+ 'override_midi',
141
+ 'raw',
142
+ 'note-language',
143
+ 'override_audio',
144
+ 'override_ogg',
145
+ 'sound',
146
+ 'vorbis',
147
+ ]),
148
+ seo: new Set([
149
+ 'title',
150
+ 'title_mode',
151
+ 'title_separator',
152
+ 'keywords',
153
+ 'description',
154
+ 'robots',
155
+ 'google_bot',
156
+ 'image',
157
+ 'image_width',
158
+ 'image_height',
159
+ 'image_alt',
160
+ 'type',
161
+ 'site_name',
162
+ 'locale',
163
+ 'section',
164
+ 'author',
165
+ 'published_time',
166
+ 'twitter_site',
167
+ ]),
168
+ tab: new Set([
169
+ 'nested',
170
+ 'name',
171
+ 'index',
172
+ 'class',
173
+ 'block',
174
+ 'inline',
175
+ 'openname',
176
+ 'closename',
177
+ 'collapsed',
178
+ 'dropdown',
179
+ 'style',
180
+ 'bgcolor',
181
+ 'container',
182
+ 'id',
183
+ 'title',
184
+ ]),
185
+ tabs: new Set(['plain', 'class', 'container', 'id', 'title', 'style']),
186
+ combobox: new Set(['placeholder', 'value', 'id', 'class', 'text', 'dropdown', 'style']),
187
+ }, insecureStyle = /expression|(?:accelerator|-o-link(?:-source)?|-o-replace)\s*:|(?:url|image(?:-set)?)\s*\(|attr\s*\([^)]+[\s,]url/u, obsoleteAttrs = {
188
+ table: obsoleteTableAttrs,
189
+ td: new Set([...obsoleteTdAttrs, 'scope']),
190
+ th: obsoleteTdAttrs,
191
+ br: brAttrs,
192
+ caption: blockAttrs,
193
+ div: blockAttrs,
194
+ hr: widthAttrs,
195
+ h1: blockAttrs,
196
+ h2: blockAttrs,
197
+ h3: blockAttrs,
198
+ h4: blockAttrs,
199
+ h5: blockAttrs,
200
+ h6: blockAttrs,
201
+ li: typeAttrs,
202
+ p: blockAttrs,
203
+ pre: widthAttrs,
204
+ tr: trAttrs,
205
+ ul: typeAttrs,
206
+ };
207
+ /**
208
+ * 扩展和HTML标签属性
209
+ * @classdesc `{childNodes: [AtomToken, Token|AtomToken]}`
210
+ */
211
+ let AttributeToken = (() => {
212
+ let _classDecorators = [fixed_1.fixedToken];
213
+ let _classDescriptor;
214
+ let _classExtraInitializers = [];
215
+ let _classThis;
216
+ let _classSuper = index_2.Token;
217
+ var AttributeToken = class extends _classSuper {
218
+ static { _classThis = this; }
219
+ static {
220
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
221
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
222
+ AttributeToken = _classThis = _classDescriptor.value;
223
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
224
+ __runInitializers(_classThis, _classExtraInitializers);
225
+ }
226
+ #tag;
227
+ #equal;
228
+ #quotes;
229
+ /* NOT FOR BROWSER END */
230
+ /** 标签名 */
231
+ get tag() {
232
+ return this.#tag;
233
+ }
234
+ /** 引号是否匹配 */
235
+ get balanced() {
236
+ return !this.#equal || this.#quotes[0] === this.#quotes[1];
237
+ }
238
+ /* NOT FOR BROWSER */
239
+ set balanced(value) {
240
+ if (value) {
241
+ this.close();
242
+ }
243
+ }
244
+ /** getValue()的getter */
245
+ get value() {
246
+ return this.getValue();
247
+ }
248
+ set value(value) {
249
+ this.setValue(value);
250
+ }
251
+ /* NOT FOR BROWSER END */
252
+ /**
253
+ * @param type 标签类型
254
+ * @param tag 标签名
255
+ * @param key 属性名
256
+ * @param equal 等号
257
+ * @param value 属性值
258
+ * @param quotes 引号
259
+ */
260
+ constructor(type, tag, key, equal = '', value, quotes = [], config = index_1.default.getConfig(), accum = []) {
261
+ const keyToken = new atom_1.AtomToken(key, 'attr-key', config, accum, {
262
+ [type === 'ext-attr' ? 'AstText' : 'Stage-1']: ':', ArgToken: ':', TranscludeToken: ':',
263
+ });
264
+ let valueToken;
265
+ if (key === 'title' || tag === 'img' && key === 'alt') {
266
+ valueToken = new index_2.Token(value, config, accum, {
267
+ [`Stage-${stages[type]}`]: ':', ConverterToken: ':',
268
+ });
269
+ valueToken.type = 'attr-value';
270
+ valueToken.setAttribute('stage', constants_1.MAX_STAGE - 1);
271
+ }
272
+ else if (tag === 'gallery' && key === 'caption') {
273
+ const newConfig = {
274
+ ...config,
275
+ excludes: [...config.excludes, 'quote', 'extLink', 'magicLink', 'list'],
276
+ };
277
+ valueToken = new index_2.Token(value, newConfig, accum, {
278
+ AstText: ':', LinkToken: ':', FileToken: ':', CategoryToken: ':', ConverterToken: ':',
279
+ });
280
+ valueToken.type = 'attr-value';
281
+ valueToken.setAttribute('stage', 5);
282
+ }
283
+ else if (tag === 'choose' && (key === 'before' || key === 'after')) {
284
+ const newConfig = {
285
+ ...config,
286
+ excludes: [...config.excludes, 'heading', 'html', 'table', 'hr', 'list'],
287
+ };
288
+ valueToken = new index_2.Token(value, newConfig, accum, {
289
+ ArgToken: ':',
290
+ TranscludeToken: ':',
291
+ LinkToken: ':',
292
+ FileToken: ':',
293
+ CategoryToken: ':',
294
+ QuoteToken: ':',
295
+ ExtLinkToken: ':',
296
+ MagicLinkToken: ':',
297
+ ConverterToken: ':',
298
+ });
299
+ valueToken.type = 'attr-value';
300
+ valueToken.setAttribute('stage', 1);
301
+ }
302
+ else {
303
+ valueToken = new atom_1.AtomToken(value, 'attr-value', config, accum, {
304
+ [`Stage-${stages[type]}`]: ':',
305
+ });
306
+ }
307
+ super(undefined, config, accum);
308
+ this.type = type;
309
+ this.append(keyToken, valueToken);
310
+ this.#equal = equal;
311
+ this.#quotes = [...quotes];
312
+ this.#tag = tag;
313
+ this.setAttribute('name', (0, string_1.removeComment)(key).trim().toLowerCase());
314
+ }
315
+ /** @private */
316
+ afterBuild() {
317
+ if (this.#equal.includes('\0')) {
318
+ this.#equal = this.buildFromStr(this.#equal, constants_1.BuildMethod.String);
319
+ }
320
+ if (this.parentNode) {
321
+ this.#tag = this.parentNode.name;
322
+ }
323
+ this.setAttribute('name', this.firstChild.text().trim().toLowerCase());
324
+ super.afterBuild();
325
+ }
326
+ /** @private */
327
+ toString() {
328
+ const [quoteStart = '', quoteEnd = ''] = this.#quotes;
329
+ return this.#equal ? super.toString(this.#equal + quoteStart) + quoteEnd : this.firstChild.toString();
330
+ }
331
+ /** @private */
332
+ text() {
333
+ return this.#equal ? `${super.text(`${this.#equal.trim()}"`)}"` : this.firstChild.text();
334
+ }
335
+ /** @private */
336
+ getGaps() {
337
+ return this.#equal ? this.#equal.length + (this.#quotes[0]?.length ?? 0) : 0;
338
+ }
339
+ /** @private */
340
+ lint(start = this.getAbsoluteIndex(), re) {
341
+ const errors = super.lint(start, re), { balanced, firstChild, lastChild, type, name, tag } = this, value = this.getValue(), rect = new rect_1.BoundingRect(this, start);
342
+ if (!balanced) {
343
+ const e = (0, lint_1.generateForChild)(lastChild, rect, 'unclosed-quote', index_1.default.msg('unclosed $1', 'quotes'), 'warning');
344
+ e.startIndex--;
345
+ e.startCol--;
346
+ const fix = {
347
+ range: [e.endIndex, e.endIndex],
348
+ text: this.#quotes[0],
349
+ };
350
+ if (lastChild.childNodes.some(({ type: t, data }) => t === 'text' && /\s/u.test(data))) {
351
+ e.suggestions = [
352
+ {
353
+ desc: 'close',
354
+ ...fix,
355
+ },
356
+ ];
357
+ }
358
+ else {
359
+ e.fix = fix;
360
+ }
361
+ errors.push(e);
362
+ }
363
+ const attrs = extAttrs[tag];
364
+ if (attrs && !attrs.has(name)
365
+ || (type === 'ext-attr' ? tag in htmlAttrs : !/\{\{[^{]+\}\}/u.test(name))
366
+ && !htmlAttrs[tag]?.has(name)
367
+ && !/^(?:xmlns:[\w:.-]+|data-[^:]*)$/u.test(name)
368
+ && (tag === 'meta' || tag === 'link' || !commonHtmlAttrs.has(name))) {
369
+ errors.push((0, lint_1.generateForChild)(firstChild, rect, 'illegal-attr', 'illegal attribute name'));
370
+ }
371
+ else if (obsoleteAttrs[tag]?.has(name)) {
372
+ errors.push((0, lint_1.generateForChild)(firstChild, rect, 'obsolete-attr', 'obsolete attribute', 'warning'));
373
+ }
374
+ else if (name === 'style' && typeof value === 'string' && insecureStyle.test(value)) {
375
+ errors.push((0, lint_1.generateForChild)(lastChild, rect, 'insecure-style', 'insecure style'));
376
+ }
377
+ else if (name === 'tabindex' && typeof value === 'string' && value.trim() !== '0') {
378
+ const e = (0, lint_1.generateForChild)(lastChild, rect, 'illegal-attr', 'nonzero tabindex');
379
+ e.suggestions = [
380
+ {
381
+ desc: 'remove',
382
+ range: [start, e.endIndex],
383
+ text: '',
384
+ },
385
+ {
386
+ desc: '0 tabindex',
387
+ range: [e.startIndex, e.endIndex],
388
+ text: '0',
389
+ },
390
+ ];
391
+ errors.push(e);
392
+ }
393
+ return errors;
394
+ }
395
+ /** 获取属性值 */
396
+ getValue() {
397
+ if (this.#equal) {
398
+ const value = this.lastChild.text();
399
+ if (this.#quotes[1]) {
400
+ return value;
401
+ }
402
+ return value[this.#quotes[0] ? 'trimEnd' : 'trim']();
403
+ }
404
+ return this.type === 'ext-attr' || '';
405
+ }
406
+ /** @private */
407
+ print() {
408
+ const [quoteStart = '', quoteEnd = ''] = this.#quotes;
409
+ return this.#equal ? super.print({ sep: (0, string_1.escape)(this.#equal) + quoteStart, post: quoteEnd }) : super.print();
410
+ }
411
+ /* NOT FOR BROWSER */
412
+ /** @override */
413
+ cloneNode() {
414
+ const [key, value] = this.cloneChildNodes(), config = this.getAttribute('config');
415
+ return debug_1.Shadow.run(() => {
416
+ // @ts-expect-error abstract class
417
+ const token = new AttributeToken(this.type, this.tag, '', this.#equal, '', this.#quotes, config);
418
+ token.firstChild.safeReplaceWith(key);
419
+ token.lastChild.safeReplaceWith(value);
420
+ return token;
421
+ });
422
+ }
423
+ /** 转义等号 */
424
+ escape() {
425
+ this.#equal = '{{=}}';
426
+ }
427
+ /** 闭合引号 */
428
+ close() {
429
+ const [opening] = this.#quotes;
430
+ if (opening) {
431
+ this.#quotes[1] = opening;
432
+ }
433
+ }
434
+ /**
435
+ * 设置属性值
436
+ * @param value 参数值
437
+ * @throws `RangeError` 扩展标签属性不能包含 ">"
438
+ * @throws `RangeError` 同时包含单引号和双引号
439
+ */
440
+ setValue(value) {
441
+ if (value === false) {
442
+ this.remove();
443
+ return;
444
+ }
445
+ else if (value === true) {
446
+ this.#equal = '';
447
+ return;
448
+ }
449
+ else if (this.type === 'ext-attr' && value.includes('>')) {
450
+ throw new RangeError('Attributes of an extension tag cannot contain ">"!');
451
+ }
452
+ else if (value.includes('"') && value.includes(`'`)) {
453
+ throw new RangeError('Attribute values cannot contain single and double quotes simultaneously!');
454
+ }
455
+ const config = this.getAttribute('config'), { childNodes } = index_1.default.parse(value, this.getAttribute('include'), stages[this.type] + 1, config);
456
+ this.lastChild.replaceChildren(...childNodes);
457
+ if (value.includes('"')) {
458
+ this.#quotes = [`'`, `'`];
459
+ }
460
+ else if (value.includes(`'`) || !this.#quotes[0]) {
461
+ this.#quotes = ['"', '"'];
462
+ }
463
+ else {
464
+ this.close();
465
+ }
466
+ }
467
+ /**
468
+ * 修改属性名
469
+ * @param key 新属性名
470
+ * @throws `Error` title和alt属性不能更名
471
+ */
472
+ rename(key) {
473
+ if (this.name === 'title' || this.name === 'alt' && this.tag === 'img') {
474
+ throw new Error(`${this.name} attribute cannot be renamed!`);
475
+ }
476
+ const config = this.getAttribute('config'), { childNodes } = index_1.default.parse(key, this.getAttribute('include'), stages[this.type] + 1, config);
477
+ this.firstChild.replaceChildren(...childNodes);
478
+ }
479
+ };
480
+ return AttributeToken = _classThis;
481
+ })();
482
+ exports.AttributeToken = AttributeToken;
483
+ constants_1.classes['AttributeToken'] = __filename;
@@ -0,0 +1,103 @@
1
+ import Parser from '../index';
2
+ import { Token } from './index';
3
+ import { AtomToken } from './atom';
4
+ import { AttributeToken } from './attribute';
5
+ import type { LintError } from '../base';
6
+ import type { ExtToken, HtmlToken, TdToken, TrToken, TableToken } from '../internal';
7
+ import type { AttributeTypes } from './attribute';
8
+ declare type AttributesTypes = `${AttributeTypes}s`;
9
+ /**
10
+ * 扩展和HTML标签属性
11
+ * @classdesc `{childNodes: ...AtomToken|AttributeToken}`
12
+ */
13
+ export declare abstract class AttributesToken extends Token {
14
+ #private;
15
+ type: AttributesTypes;
16
+ readonly name: string;
17
+ readonly childNodes: readonly (AtomToken | AttributeToken)[];
18
+ abstract get firstChild(): AtomToken | AttributeToken | undefined;
19
+ abstract get lastChild(): AtomToken | AttributeToken | undefined;
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
+ abstract get parentElement(): ExtToken | HtmlToken | TableToken | TrToken | TdToken | undefined;
25
+ /** getAttrs()方法的getter写法 */
26
+ get attributes(): Record<string, string | true>;
27
+ set attributes(attrs: Record<string, string | true>);
28
+ /** 以字符串表示的class属性 */
29
+ get className(): string;
30
+ set className(className: string);
31
+ /** 以Set表示的class属性 */
32
+ get classList(): Set<string>;
33
+ set classList(classList: Set<string>);
34
+ /** id属性 */
35
+ get id(): string;
36
+ set id(id: string);
37
+ /** 是否含有无效属性 */
38
+ get sanitized(): boolean;
39
+ set sanitized(sanitized: boolean);
40
+ /**
41
+ * @param attr 标签属性
42
+ * @param type 标签类型
43
+ * @param name 标签名
44
+ */
45
+ constructor(attr: string | undefined, type: AttributesTypes, name: string, config?: Parser.Config, accum?: Token[]);
46
+ /**
47
+ * 所有指定属性名的AttributeToken
48
+ * @param key 属性名
49
+ */
50
+ getAttrTokens(key?: string): AttributeToken[];
51
+ /**
52
+ * 指定属性名的最后一个AttributeToken
53
+ * @param key 属性名
54
+ */
55
+ getAttrToken(key: string): AttributeToken | undefined;
56
+ /**
57
+ * 获取指定属性
58
+ * @param key 属性键
59
+ */
60
+ getAttr(key: string): string | true | undefined;
61
+ /** 清理无效属性 */
62
+ sanitize(): void;
63
+ /** @override */
64
+ cloneNode(): this;
65
+ /**
66
+ * @override
67
+ * @param token 待插入的子节点
68
+ * @param i 插入位置
69
+ * @throws `RangeError` 标签不匹配
70
+ */
71
+ insertAt<T extends AttributeToken | AtomToken>(token: T, i?: number): T;
72
+ /**
73
+ * 设置指定属性
74
+ * @param key 属性键
75
+ * @param value 属性值
76
+ * @param prop 属性对象
77
+ * @throws `RangeError` 扩展标签属性不能包含">"
78
+ */
79
+ setAttr(key: string, value: string | boolean): void;
80
+ setAttr(prop: Record<string, string | boolean>): void;
81
+ /**
82
+ * 标签是否具有某属性
83
+ * @param key 属性键
84
+ */
85
+ hasAttr(key: string): boolean;
86
+ /** 获取全部的属性名 */
87
+ getAttrNames(): Set<string>;
88
+ /** 获取全部属性 */
89
+ getAttrs(): Record<string, string | true>;
90
+ /**
91
+ * 移除指定属性
92
+ * @param key 属性键
93
+ */
94
+ removeAttr(key: string): void;
95
+ /**
96
+ * 开关指定属性
97
+ * @param key 属性键
98
+ * @param force 强制开启或关闭
99
+ * @throws `RangeError` 不为Boolean类型的属性值
100
+ */
101
+ toggleAttr(key: string, force?: boolean): void;
102
+ }
103
+ export {};