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