wikiparser-node 1.13.2-b → 1.13.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 (169) hide show
  1. package/bundle/bundle.min.js +16 -16
  2. package/config/.schema.json +203 -0
  3. package/config/default.json +32 -31
  4. package/config/enwiki.json +829 -15
  5. package/config/llwiki.json +56 -21
  6. package/config/moegirl.json +65 -21
  7. package/config/zhwiki.json +498 -32
  8. package/dist/addon/table.js +494 -0
  9. package/dist/addon/token.js +392 -0
  10. package/dist/addon/transclude.js +177 -0
  11. package/dist/base.d.ts +109 -0
  12. package/dist/base.js +67 -0
  13. package/dist/index.d.ts +33 -0
  14. package/dist/index.js +284 -0
  15. package/dist/internal.d.ts +47 -0
  16. package/dist/lib/element.d.ts +125 -0
  17. package/dist/lib/element.js +364 -0
  18. package/dist/lib/node.d.ts +173 -0
  19. package/dist/lib/node.js +478 -0
  20. package/dist/lib/range.d.ts +105 -0
  21. package/dist/lib/range.js +406 -0
  22. package/dist/lib/ranges.d.ts +28 -0
  23. package/dist/lib/ranges.js +126 -0
  24. package/dist/lib/rect.d.ts +18 -0
  25. package/dist/lib/rect.js +36 -0
  26. package/dist/lib/text.d.ts +58 -0
  27. package/dist/lib/text.js +414 -0
  28. package/dist/lib/title.d.ts +49 -0
  29. package/dist/lib/title.js +251 -0
  30. package/dist/mixin/attributesParent.d.ts +49 -0
  31. package/dist/mixin/attributesParent.js +80 -0
  32. package/dist/mixin/fixed.d.ts +5 -0
  33. package/dist/mixin/fixed.js +32 -0
  34. package/dist/mixin/flagsParent.d.ts +43 -0
  35. package/dist/mixin/flagsParent.js +64 -0
  36. package/dist/mixin/hidden.d.ts +7 -0
  37. package/dist/mixin/hidden.js +39 -0
  38. package/dist/mixin/magicLinkParent.d.ts +19 -0
  39. package/dist/mixin/magicLinkParent.js +43 -0
  40. package/dist/mixin/singleLine.d.ts +6 -0
  41. package/dist/mixin/singleLine.js +33 -0
  42. package/dist/mixin/sol.d.ts +6 -0
  43. package/dist/mixin/sol.js +45 -0
  44. package/dist/mixin/syntax.d.ts +8 -0
  45. package/dist/mixin/syntax.js +46 -0
  46. package/dist/parser/braces.js +152 -0
  47. package/dist/parser/commentAndExt.js +84 -0
  48. package/dist/parser/converter.js +43 -0
  49. package/dist/parser/externalLinks.js +39 -0
  50. package/dist/parser/hrAndDoubleUnderscore.js +45 -0
  51. package/dist/parser/html.js +40 -0
  52. package/dist/parser/links.js +105 -0
  53. package/dist/parser/list.js +116 -0
  54. package/dist/parser/magicLinks.js +55 -0
  55. package/dist/parser/quotes.js +69 -0
  56. package/dist/parser/redirect.js +29 -0
  57. package/dist/parser/selector.js +443 -0
  58. package/dist/parser/table.js +125 -0
  59. package/dist/src/arg.d.ts +49 -0
  60. package/dist/src/arg.js +220 -0
  61. package/dist/src/atom.d.ts +14 -0
  62. package/dist/src/atom.js +54 -0
  63. package/dist/src/attribute.d.ts +64 -0
  64. package/dist/src/attribute.js +326 -0
  65. package/dist/src/attributes.d.ts +105 -0
  66. package/dist/src/attributes.js +379 -0
  67. package/dist/src/converter.d.ts +28 -0
  68. package/dist/src/converter.js +153 -0
  69. package/dist/src/converterFlags.d.ts +80 -0
  70. package/dist/src/converterFlags.js +241 -0
  71. package/dist/src/converterRule.d.ts +71 -0
  72. package/dist/src/converterRule.js +218 -0
  73. package/dist/src/extLink.d.ts +36 -0
  74. package/dist/src/extLink.js +223 -0
  75. package/dist/src/gallery.d.ts +53 -0
  76. package/dist/src/gallery.js +165 -0
  77. package/dist/src/heading.d.ts +44 -0
  78. package/dist/src/heading.js +222 -0
  79. package/dist/src/hidden.d.ts +9 -0
  80. package/dist/src/hidden.js +82 -0
  81. package/dist/src/html.d.ts +61 -0
  82. package/dist/src/html.js +344 -0
  83. package/dist/src/imageParameter.d.ts +60 -0
  84. package/dist/src/imageParameter.js +262 -0
  85. package/dist/src/imagemap.d.ts +49 -0
  86. package/dist/src/imagemap.js +147 -0
  87. package/dist/src/imagemapLink.d.ts +35 -0
  88. package/dist/src/imagemapLink.js +99 -0
  89. package/dist/src/index.d.ts +135 -0
  90. package/dist/src/index.js +791 -0
  91. package/dist/src/link/base.d.ts +52 -0
  92. package/dist/src/link/base.js +258 -0
  93. package/dist/src/link/category.d.ts +22 -0
  94. package/dist/src/link/category.js +36 -0
  95. package/dist/src/link/file.d.ts +102 -0
  96. package/dist/src/link/file.js +345 -0
  97. package/dist/src/link/galleryImage.d.ts +29 -0
  98. package/dist/src/link/galleryImage.js +133 -0
  99. package/dist/src/link/index.d.ts +39 -0
  100. package/dist/src/link/index.js +100 -0
  101. package/dist/src/link/redirectTarget.d.ts +27 -0
  102. package/dist/src/link/redirectTarget.js +71 -0
  103. package/dist/src/magicLink.d.ts +57 -0
  104. package/dist/src/magicLink.js +261 -0
  105. package/dist/src/nested.d.ts +41 -0
  106. package/dist/src/nested.js +113 -0
  107. package/dist/src/nowiki/base.d.ts +28 -0
  108. package/dist/src/nowiki/base.js +90 -0
  109. package/dist/src/nowiki/comment.d.ts +14 -0
  110. package/dist/src/nowiki/comment.js +123 -0
  111. package/dist/src/nowiki/dd.d.ts +8 -0
  112. package/dist/src/nowiki/dd.js +74 -0
  113. package/dist/src/nowiki/doubleUnderscore.d.ts +15 -0
  114. package/dist/src/nowiki/doubleUnderscore.js +101 -0
  115. package/dist/src/nowiki/hr.d.ts +5 -0
  116. package/dist/src/nowiki/hr.js +72 -0
  117. package/dist/src/nowiki/index.d.ts +14 -0
  118. package/dist/src/nowiki/index.js +30 -0
  119. package/dist/src/nowiki/list.d.ts +5 -0
  120. package/dist/src/nowiki/list.js +67 -0
  121. package/dist/src/nowiki/listBase.d.ts +23 -0
  122. package/dist/src/nowiki/listBase.js +100 -0
  123. package/dist/src/nowiki/noinclude.d.ts +6 -0
  124. package/dist/src/nowiki/noinclude.js +77 -0
  125. package/dist/src/nowiki/quote.d.ts +14 -0
  126. package/dist/src/nowiki/quote.js +149 -0
  127. package/dist/src/onlyinclude.d.ts +13 -0
  128. package/dist/src/onlyinclude.js +60 -0
  129. package/dist/src/paramTag/index.d.ts +28 -0
  130. package/dist/src/paramTag/index.js +97 -0
  131. package/dist/src/paramTag/inputbox.d.ts +8 -0
  132. package/dist/src/paramTag/inputbox.js +26 -0
  133. package/dist/src/parameter.d.ts +60 -0
  134. package/dist/src/parameter.js +267 -0
  135. package/dist/src/pre.d.ts +30 -0
  136. package/dist/src/pre.js +69 -0
  137. package/dist/src/redirect.d.ts +30 -0
  138. package/dist/src/redirect.js +128 -0
  139. package/dist/src/syntax.d.ts +15 -0
  140. package/dist/src/syntax.js +87 -0
  141. package/dist/src/table/base.d.ts +28 -0
  142. package/dist/src/table/base.js +81 -0
  143. package/dist/src/table/index.d.ts +231 -0
  144. package/dist/src/table/index.js +505 -0
  145. package/dist/src/table/td.d.ts +72 -0
  146. package/dist/src/table/td.js +375 -0
  147. package/dist/src/table/tr.d.ts +30 -0
  148. package/dist/src/table/tr.js +61 -0
  149. package/dist/src/table/trBase.d.ts +49 -0
  150. package/dist/src/table/trBase.js +165 -0
  151. package/dist/src/tagPair/ext.d.ts +30 -0
  152. package/dist/src/tagPair/ext.js +231 -0
  153. package/dist/src/tagPair/include.d.ts +33 -0
  154. package/dist/src/tagPair/include.js +145 -0
  155. package/dist/src/tagPair/index.d.ts +23 -0
  156. package/dist/src/tagPair/index.js +130 -0
  157. package/dist/src/transclude.d.ts +161 -0
  158. package/dist/src/transclude.js +607 -0
  159. package/dist/util/constants.js +26 -0
  160. package/dist/util/debug.js +95 -0
  161. package/dist/util/diff.js +83 -0
  162. package/dist/util/html.js +146 -0
  163. package/dist/util/lint.js +32 -0
  164. package/dist/util/sharable.js +163 -0
  165. package/dist/util/string.js +107 -0
  166. package/errors/README +3 -0
  167. package/extensions/dist/base.js +7 -4
  168. package/package.json +24 -23
  169. package/printed/README +3 -0
@@ -0,0 +1,30 @@
1
+ import Parser from '../../index';
2
+ import { Token } from '../index';
3
+ import { TagPairToken } from './index';
4
+ import { AttributesToken } from '../attributes';
5
+ import type { LintError } from '../../base';
6
+ import type { AttributesParentBase } from '../../mixin/attributesParent';
7
+ export interface ExtToken extends AttributesParentBase {
8
+ }
9
+ /**
10
+ * 扩展标签
11
+ * @classdesc `{childNodes: [AttributesToken, Token]}`
12
+ */
13
+ export declare abstract class ExtToken extends TagPairToken {
14
+ closed: true;
15
+ readonly childNodes: readonly [AttributesToken, Token];
16
+ abstract get firstChild(): AttributesToken;
17
+ abstract get lastChild(): Token;
18
+ abstract get children(): [AttributesToken, Token];
19
+ abstract get firstElementChild(): AttributesToken;
20
+ get type(): 'ext';
21
+ /**
22
+ * @param name 标签名
23
+ * @param include 是否嵌入
24
+ * @param attr 标签属性
25
+ * @param inner 内部wikitext
26
+ * @param closed 是否封闭
27
+ */
28
+ constructor(name: string, attr?: string, inner?: string, closed?: string, config?: Parser.Config, include?: boolean, accum?: Token[]);
29
+ cloneNode(): this;
30
+ }
@@ -0,0 +1,231 @@
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.ExtToken = void 0;
38
+ const lint_1 = require("../../util/lint");
39
+ const rect_1 = require("../../lib/rect");
40
+ const index_1 = require("../../index");
41
+ const index_2 = require("../index");
42
+ const index_3 = require("./index");
43
+ const attributes_1 = require("../attributes");
44
+ const pre_1 = require("../pre");
45
+ const index_4 = require("../paramTag/index");
46
+ const inputbox_1 = require("../paramTag/inputbox");
47
+ const gallery_1 = require("../gallery");
48
+ const imagemap_1 = require("../imagemap");
49
+ const index_5 = require("../nowiki/index");
50
+ /* NOT FOR BROWSER */
51
+ const debug_1 = require("../../util/debug");
52
+ const constants_1 = require("../../util/constants");
53
+ const string_1 = require("../../util/string");
54
+ const html_1 = require("../../util/html");
55
+ const attributesParent_1 = require("../../mixin/attributesParent");
56
+ /* NOT FOR BROWSER END */
57
+ /**
58
+ * 从数组中删除指定元素
59
+ * @param arr 数组
60
+ * @param ele 元素
61
+ */
62
+ const del = (arr, ele) => {
63
+ const set = new Set(arr);
64
+ set.delete(ele);
65
+ return [...set];
66
+ };
67
+ /**
68
+ * 扩展标签
69
+ * @classdesc `{childNodes: [AttributesToken, Token]}`
70
+ */
71
+ let ExtToken = (() => {
72
+ let _classDecorators = [(0, attributesParent_1.attributesParent)()];
73
+ let _classDescriptor;
74
+ let _classExtraInitializers = [];
75
+ let _classThis;
76
+ let _classSuper = index_3.TagPairToken;
77
+ var ExtToken = class extends _classSuper {
78
+ static { _classThis = this; }
79
+ static {
80
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
81
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
82
+ ExtToken = _classThis = _classDescriptor.value;
83
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
84
+ __runInitializers(_classThis, _classExtraInitializers);
85
+ }
86
+ /* NOT FOR BROWSER END */
87
+ get type() {
88
+ return 'ext';
89
+ }
90
+ /**
91
+ * @param name 标签名
92
+ * @param include 是否嵌入
93
+ * @param attr 标签属性
94
+ * @param inner 内部wikitext
95
+ * @param closed 是否封闭
96
+ */
97
+ constructor(name, attr, inner, closed, config = index_1.default.getConfig(), include = false, accum = []) {
98
+ const lcName = name.toLowerCase(),
99
+ // @ts-expect-error abstract class
100
+ attrToken = new attributes_1.AttributesToken(!attr || attr.trimStart() !== attr ? attr : ` ${attr}`, 'ext-attrs', lcName, config, accum), newConfig = { ...config, ext: del(config.ext, lcName), excludes: [...config.excludes ?? []] };
101
+ let innerToken;
102
+ switch (lcName) {
103
+ case 'tab':
104
+ newConfig.ext = del(newConfig.ext, 'tabs');
105
+ // fall through
106
+ case 'indicator':
107
+ case 'poem':
108
+ case 'ref':
109
+ case 'option':
110
+ case 'combooption':
111
+ case 'tabs':
112
+ case 'poll':
113
+ case 'seo':
114
+ if (lcName === 'poem') {
115
+ newConfig.excludes.push('heading');
116
+ }
117
+ innerToken = new index_2.Token(inner, newConfig, accum);
118
+ break;
119
+ case 'pre':
120
+ // @ts-expect-error abstract class
121
+ innerToken = new pre_1.PreToken(inner, newConfig, accum);
122
+ break;
123
+ case 'dynamicpagelist':
124
+ // @ts-expect-error abstract class
125
+ innerToken = new index_4.ParamTagToken(include, inner, newConfig, accum);
126
+ break;
127
+ case 'inputbox':
128
+ newConfig.excludes.push('heading');
129
+ // @ts-expect-error abstract class
130
+ innerToken = new inputbox_1.InputboxToken(include, inner, newConfig, accum);
131
+ break;
132
+ case 'references': {
133
+ const { NestedToken } = require('../nested');
134
+ newConfig.excludes.push('heading');
135
+ // @ts-expect-error abstract class
136
+ innerToken = new NestedToken(inner, include, ['ref'], newConfig, accum);
137
+ break;
138
+ }
139
+ case 'choose': {
140
+ const { NestedToken } = require('../nested');
141
+ // @ts-expect-error abstract class
142
+ innerToken = new NestedToken(inner, /<(option|choicetemplate)(\s[^>]*?)?(?:\/>|>(.*?)<\/(\1)>)/gsu, ['option', 'choicetemplate'], newConfig, accum);
143
+ break;
144
+ }
145
+ case 'combobox': {
146
+ const { NestedToken } = require('../nested');
147
+ // @ts-expect-error abstract class
148
+ innerToken = new NestedToken(inner, /<(combooption)(\s[^>]*?)?(?:\/>|>(.*?)<\/(combooption\s*)>)/gisu, ['combooption'], newConfig, accum);
149
+ break;
150
+ }
151
+ case 'gallery':
152
+ // @ts-expect-error abstract class
153
+ innerToken = new gallery_1.GalleryToken(inner, newConfig, accum);
154
+ break;
155
+ case 'imagemap':
156
+ // @ts-expect-error abstract class
157
+ innerToken = new imagemap_1.ImagemapToken(inner, newConfig, accum);
158
+ break;
159
+ // 更多定制扩展的代码示例:
160
+ // ```
161
+ // case 'extensionName': {
162
+ // const {ExtensionToken}: typeof import('../extension') = require('../extension');
163
+ // innerToken = new ExtensionToken(inner, newConfig, accum);
164
+ // break;
165
+ // }
166
+ // ```
167
+ default:
168
+ // @ts-expect-error abstract class
169
+ innerToken = new index_5.NowikiToken(inner, newConfig, accum);
170
+ }
171
+ innerToken.setAttribute('name', lcName);
172
+ if (innerToken.type === 'plain') {
173
+ innerToken.type = 'ext-inner';
174
+ }
175
+ super(name, attrToken, innerToken, closed, config, accum);
176
+ this.seal('closed', true);
177
+ }
178
+ /** @private */
179
+ lint(start = this.getAbsoluteIndex(), re) {
180
+ const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start);
181
+ if (this.name !== 'nowiki' && this.closest('html-attrs,table-attrs')) {
182
+ errors.push((0, lint_1.generateForSelf)(this, rect, 'parsing-order', 'extension tag in HTML tag attributes'));
183
+ }
184
+ if (this.name === 'ref' && this.closest('heading-title')) {
185
+ errors.push((0, lint_1.generateForSelf)(this, rect, 'var-anchor', 'variable anchor in a section header'));
186
+ }
187
+ return errors;
188
+ }
189
+ /* NOT FOR BROWSER */
190
+ cloneNode() {
191
+ const inner = this.lastChild.cloneNode(), tags = this.getAttribute('tags'), config = this.getAttribute('config'), include = this.getAttribute('include'), closed = this.selfClosing ? undefined : tags[1], attr = this.firstChild.toString();
192
+ return debug_1.Shadow.run(() => {
193
+ // @ts-expect-error abstract class
194
+ const token = new ExtToken(tags[0], attr, '', closed, config, include);
195
+ token.lastChild.safeReplaceWith(inner);
196
+ return token;
197
+ });
198
+ }
199
+ /** @private */
200
+ toHtmlInternal(_, nocc) {
201
+ const { name, firstChild, lastChild } = this;
202
+ switch (name) {
203
+ case 'nowiki':
204
+ return (0, html_1.font)(this, (0, string_1.newline)(lastChild.toHtmlInternal()));
205
+ case 'pre':
206
+ return (0, html_1.font)(this, `<pre${firstChild.toHtmlInternal()}>${(0, string_1.newline)(lastChild.toHtmlInternal(false, nocc))}</pre>`);
207
+ case 'poem':
208
+ firstChild.classList.add('poem');
209
+ return (0, html_1.font)(this, `<div${firstChild.toHtmlInternal()}>${lastChild.toHtmlInternal(false, nocc).replace(/(?<!^|<hr>)\n(?!$)/gu, '<br>\n')
210
+ .replace(/^ +/gmu, p => '&nbsp;'.repeat(p.length))}</div>`);
211
+ case 'gallery': {
212
+ const caption = firstChild.getAttrToken('caption'), perrow = parseInt(String(firstChild.getAttr('perrow'))), mode = firstChild.getAttr('mode'), nolines = typeof mode === 'string' && mode.toLowerCase() === 'nolines', padding = nolines ? 9 : 43;
213
+ firstChild.classList.add('gallery');
214
+ if (nolines) {
215
+ firstChild.classList.add('mw-gallery-nolines');
216
+ }
217
+ if (perrow > 0) {
218
+ const style = firstChild.getAttr('style');
219
+ firstChild.setAttr('style', `max-width: ${(lastChild.widths + padding) * perrow}px;${typeof style === 'string' ? style : ''}`);
220
+ }
221
+ return (0, html_1.font)(this, `<ul${firstChild.toHtmlInternal()}>\n${caption ? `\t<li class="gallerycaption">${caption.lastChild.toHtmlInternal(true)}</li>\n` : ''}${lastChild.toHtmlInternal()}\n</ul>`);
222
+ }
223
+ default:
224
+ return '';
225
+ }
226
+ }
227
+ };
228
+ return ExtToken = _classThis;
229
+ })();
230
+ exports.ExtToken = ExtToken;
231
+ constants_1.classes['ExtToken'] = __filename;
@@ -0,0 +1,33 @@
1
+ import { TagPairToken } from './index';
2
+ import type { LintError, Config } from '../../base';
3
+ import type { AstText, Token } from '../../internal';
4
+ /**
5
+ * `<includeonly>`或`<noinclude>`或`<onlyinclude>`
6
+ * @classdesc `{childNodes: [AstText, AstText]}`
7
+ */
8
+ export declare abstract class IncludeToken extends TagPairToken {
9
+ readonly childNodes: readonly [AstText, AstText];
10
+ abstract get firstChild(): AstText;
11
+ abstract get lastChild(): AstText;
12
+ abstract get children(): [];
13
+ abstract get firstElementChild(): undefined;
14
+ abstract get lastElementChild(): undefined;
15
+ get type(): 'include';
16
+ get innerText(): string | undefined;
17
+ set innerText(text: string | undefined);
18
+ /**
19
+ * @param name 标签名
20
+ * @param attr 标签属性
21
+ * @param inner 内部wikitext
22
+ * @param closed 是否封闭
23
+ */
24
+ constructor(name: string, attr?: string, inner?: string, closed?: string, config?: Config, accum?: Token[]);
25
+ cloneNode(): this;
26
+ /**
27
+ * @override
28
+ * @param str 新文本
29
+ */
30
+ setText(str: string): string;
31
+ /** 清除标签属性 */
32
+ removeAttr(): void;
33
+ }
@@ -0,0 +1,145 @@
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.IncludeToken = void 0;
38
+ const lint_1 = require("../../util/lint");
39
+ const rect_1 = require("../../lib/rect");
40
+ const hidden_1 = require("../../mixin/hidden");
41
+ const index_1 = require("../../index");
42
+ const index_2 = require("./index");
43
+ /* NOT FOR BROWSER */
44
+ const debug_1 = require("../../util/debug");
45
+ const constants_1 = require("../../util/constants");
46
+ /* NOT FOR BROWSER END */
47
+ /**
48
+ * `<includeonly>`或`<noinclude>`或`<onlyinclude>`
49
+ * @classdesc `{childNodes: [AstText, AstText]}`
50
+ */
51
+ let IncludeToken = (() => {
52
+ let _classDecorators = [(0, hidden_1.hiddenToken)(false)];
53
+ let _classDescriptor;
54
+ let _classExtraInitializers = [];
55
+ let _classThis;
56
+ let _classSuper = index_2.TagPairToken;
57
+ var IncludeToken = class extends _classSuper {
58
+ static { _classThis = this; }
59
+ static {
60
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
61
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
62
+ IncludeToken = _classThis = _classDescriptor.value;
63
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
64
+ __runInitializers(_classThis, _classExtraInitializers);
65
+ }
66
+ /* NOT FOR BROWSER END */
67
+ get type() {
68
+ return 'include';
69
+ }
70
+ /* NOT FOR BROWSER */
71
+ get innerText() {
72
+ return this.selfClosing ? undefined : this.lastChild.data;
73
+ }
74
+ set innerText(text) {
75
+ if (text === undefined) {
76
+ this.selfClosing = true;
77
+ }
78
+ else {
79
+ this.selfClosing = false;
80
+ this.setText(text);
81
+ }
82
+ }
83
+ /* NOT FOR BROWSER END */
84
+ /**
85
+ * @param name 标签名
86
+ * @param attr 标签属性
87
+ * @param inner 内部wikitext
88
+ * @param closed 是否封闭
89
+ */
90
+ constructor(name, attr = '', inner, closed, config, accum) {
91
+ super(name, attr, inner ?? '', inner === undefined ? closed : closed ?? '', config, accum);
92
+ }
93
+ /** @private */
94
+ toString(skip) {
95
+ return skip ? '' : super.toString();
96
+ }
97
+ /** @private */
98
+ lint(start = this.getAbsoluteIndex()) {
99
+ const errors = [], { firstChild, closed, name } = this, rect = new rect_1.BoundingRect(this, start);
100
+ if (firstChild.data.trim()) {
101
+ const e = (0, lint_1.generateForChild)(firstChild, rect, 'no-ignored', 'useless attribute', 'warning');
102
+ e.suggestions = [
103
+ {
104
+ desc: 'remove',
105
+ range: [e.startIndex, e.endIndex],
106
+ text: '',
107
+ },
108
+ ];
109
+ errors.push(e);
110
+ }
111
+ if (!closed) {
112
+ const e = (0, lint_1.generateForSelf)(this, rect, 'unclosed-comment', index_1.default.msg('unclosed $1', `<${name}>`));
113
+ e.suggestions = [
114
+ {
115
+ desc: 'close',
116
+ range: [e.endIndex, e.endIndex],
117
+ text: `</${name}>`,
118
+ },
119
+ ];
120
+ errors.push(e);
121
+ }
122
+ return errors;
123
+ }
124
+ /* NOT FOR BROWSER */
125
+ cloneNode() {
126
+ const tags = this.getAttribute('tags'), config = this.getAttribute('config'), { innerText } = this, closing = this.selfClosing || !this.closed ? undefined : tags[1];
127
+ // @ts-expect-error abstract class
128
+ return debug_1.Shadow.run(() => new IncludeToken(tags[0], this.firstChild.data, innerText, closing, config));
129
+ }
130
+ /**
131
+ * @override
132
+ * @param str 新文本
133
+ */
134
+ setText(str) {
135
+ return super.setText(str, 1);
136
+ }
137
+ /** 清除标签属性 */
138
+ removeAttr() {
139
+ super.setText('');
140
+ }
141
+ };
142
+ return IncludeToken = _classThis;
143
+ })();
144
+ exports.IncludeToken = IncludeToken;
145
+ constants_1.classes['IncludeToken'] = __filename;
@@ -0,0 +1,23 @@
1
+ import { Token } from '../index';
2
+ import type { Config } from '../../base';
3
+ import type { AstNodes } from '../../lib/node';
4
+ /** 成对标签 */
5
+ export declare abstract class TagPairToken extends Token {
6
+ #private;
7
+ readonly name: string;
8
+ closed: boolean;
9
+ selfClosing: boolean;
10
+ abstract get type(): 'ext' | 'include';
11
+ readonly childNodes: readonly [AstNodes, AstNodes];
12
+ abstract get firstChild(): AstNodes;
13
+ abstract get lastChild(): AstNodes;
14
+ /** 内部wikitext */
15
+ get innerText(): string | undefined;
16
+ /**
17
+ * @param name 标签名
18
+ * @param attr 标签属性
19
+ * @param inner 内部wikitext
20
+ * @param closed 是否封闭;约定`undefined`表示自封闭,`''`表示未闭合
21
+ */
22
+ constructor(name: string, attr: string | Token, inner: string | Token, closed?: string, config?: Config, accum?: Token[]);
23
+ }
@@ -0,0 +1,130 @@
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.TagPairToken = void 0;
38
+ const index_1 = require("../index");
39
+ /* NOT FOR BROWSER */
40
+ const constants_1 = require("../../util/constants");
41
+ const fixed_1 = require("../../mixin/fixed");
42
+ const index_2 = require("../../index");
43
+ /* NOT FOR BROWSER END */
44
+ /** 成对标签 */
45
+ let TagPairToken = (() => {
46
+ let _classDecorators = [fixed_1.fixedToken];
47
+ let _classDescriptor;
48
+ let _classExtraInitializers = [];
49
+ let _classThis;
50
+ let _classSuper = index_1.Token;
51
+ var TagPairToken = class extends _classSuper {
52
+ static { _classThis = this; }
53
+ static {
54
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
55
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
56
+ TagPairToken = _classThis = _classDescriptor.value;
57
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
58
+ __runInitializers(_classThis, _classExtraInitializers);
59
+ }
60
+ #tags;
61
+ closed;
62
+ selfClosing;
63
+ /* NOT FOR BROWSER END */
64
+ /** 内部wikitext */
65
+ get innerText() {
66
+ return this.selfClosing ? undefined : this.lastChild.text();
67
+ }
68
+ /**
69
+ * @param name 标签名
70
+ * @param attr 标签属性
71
+ * @param inner 内部wikitext
72
+ * @param closed 是否封闭;约定`undefined`表示自封闭,`''`表示未闭合
73
+ */
74
+ constructor(name, attr, inner, closed, config, accum = []) {
75
+ super(undefined, config);
76
+ this.setAttribute('name', name.toLowerCase());
77
+ this.#tags = [name, closed || name];
78
+ this.closed = closed !== '';
79
+ this.selfClosing = closed === undefined;
80
+ this.append(attr, inner);
81
+ const index = typeof attr === 'string' ? -1 : accum.indexOf(attr);
82
+ accum.splice(index === -1 ? Infinity : index, 0, this);
83
+ }
84
+ /** @private */
85
+ toString(skip) {
86
+ const { selfClosing, firstChild, lastChild,
87
+ /* NOT FOR BROWSER */
88
+ nextSibling, name, closed, } = this, [opening, closing] = this.#tags;
89
+ /* NOT FOR BROWSER */
90
+ if (!closed && nextSibling) {
91
+ index_2.default.error(`Auto-closing <${name}>`, lastChild);
92
+ this.closed = true;
93
+ }
94
+ /* NOT FOR BROWSER END */
95
+ return selfClosing
96
+ ? `<${opening}${firstChild.toString(skip)}/>`
97
+ : `<${opening}${firstChild.toString(skip)}>${lastChild.toString(skip)}${this.closed ? `</${closing}>` : ''}`;
98
+ }
99
+ /** @private */
100
+ text() {
101
+ const [opening, closing] = this.#tags;
102
+ return this.selfClosing
103
+ ? `<${opening}${this.firstChild.text()}/>`
104
+ : `<${opening}${super.text('>')}${this.closed ? `</${closing}>` : ''}`;
105
+ }
106
+ /** @private */
107
+ getAttribute(key) {
108
+ /* NOT FOR BROWSER */
109
+ if (key === 'tags') {
110
+ return this.#tags;
111
+ }
112
+ /* NOT FOR BROWSER END */
113
+ return key === 'padding' ? this.#tags[0].length + 1 : super.getAttribute(key);
114
+ }
115
+ /** @private */
116
+ getGaps() {
117
+ return 1;
118
+ }
119
+ /** @private */
120
+ print() {
121
+ const [opening, closing] = this.#tags;
122
+ return super.print(this.selfClosing
123
+ ? { pre: `&lt;${opening}`, post: '/&gt;' }
124
+ : { pre: `&lt;${opening}`, sep: '&gt;', post: this.closed ? `&lt;/${closing}&gt;` : '' });
125
+ }
126
+ };
127
+ return TagPairToken = _classThis;
128
+ })();
129
+ exports.TagPairToken = TagPairToken;
130
+ constants_1.classes['TagPairToken'] = __filename;