wikiparser-node 1.4.3-b → 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 (162) 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 +58 -0
  9. package/dist/index.d.ts +30 -0
  10. package/dist/index.js +211 -0
  11. package/dist/internal.d.ts +44 -0
  12. package/dist/lib/element.d.ts +155 -0
  13. package/dist/lib/element.js +650 -0
  14. package/dist/lib/node.d.ts +146 -0
  15. package/dist/lib/node.js +428 -0
  16. package/dist/lib/range.d.ts +104 -0
  17. package/dist/lib/range.js +385 -0
  18. package/dist/lib/ranges.d.ts +26 -0
  19. package/dist/lib/ranges.js +118 -0
  20. package/dist/lib/text.d.ts +62 -0
  21. package/dist/lib/text.js +306 -0
  22. package/dist/lib/title.d.ts +38 -0
  23. package/dist/lib/title.js +164 -0
  24. package/dist/mixin/attributesParent.d.ts +50 -0
  25. package/dist/mixin/attributesParent.js +78 -0
  26. package/dist/mixin/fixed.d.ts +6 -0
  27. package/dist/mixin/fixed.js +30 -0
  28. package/dist/mixin/flagsParent.d.ts +72 -0
  29. package/dist/mixin/flagsParent.js +59 -0
  30. package/dist/mixin/hidden.d.ts +5 -0
  31. package/dist/mixin/hidden.js +24 -0
  32. package/dist/mixin/magicLinkParent.d.ts +40 -0
  33. package/dist/mixin/magicLinkParent.js +42 -0
  34. package/dist/mixin/singleLine.d.ts +6 -0
  35. package/dist/mixin/singleLine.js +26 -0
  36. package/dist/mixin/sol.d.ts +6 -0
  37. package/dist/mixin/sol.js +43 -0
  38. package/dist/mixin/syntax.d.ts +9 -0
  39. package/dist/mixin/syntax.js +50 -0
  40. package/dist/parser/braces.js +131 -0
  41. package/dist/parser/commentAndExt.js +90 -0
  42. package/dist/parser/converter.js +41 -0
  43. package/dist/parser/externalLinks.js +32 -0
  44. package/dist/parser/hrAndDoubleUnderscore.js +41 -0
  45. package/dist/parser/html.js +39 -0
  46. package/dist/parser/links.js +95 -0
  47. package/dist/parser/list.js +68 -0
  48. package/dist/parser/magicLinks.js +43 -0
  49. package/dist/parser/quotes.js +68 -0
  50. package/dist/parser/selector.js +162 -0
  51. package/dist/parser/table.js +124 -0
  52. package/dist/src/arg.d.ts +58 -0
  53. package/dist/src/arg.js +196 -0
  54. package/dist/src/atom.d.ts +12 -0
  55. package/dist/src/atom.js +27 -0
  56. package/dist/src/attribute.d.ts +69 -0
  57. package/dist/src/attribute.js +475 -0
  58. package/dist/src/attributes.d.ts +109 -0
  59. package/dist/src/attributes.js +346 -0
  60. package/dist/src/converter.d.ts +33 -0
  61. package/dist/src/converter.js +134 -0
  62. package/dist/src/converterFlags.d.ts +87 -0
  63. package/dist/src/converterFlags.js +226 -0
  64. package/dist/src/converterRule.d.ts +77 -0
  65. package/dist/src/converterRule.js +209 -0
  66. package/dist/src/extLink.d.ts +43 -0
  67. package/dist/src/extLink.js +186 -0
  68. package/dist/src/gallery.d.ts +54 -0
  69. package/dist/src/gallery.js +126 -0
  70. package/dist/src/heading.d.ts +47 -0
  71. package/dist/src/heading.js +190 -0
  72. package/dist/src/hidden.d.ts +7 -0
  73. package/dist/src/hidden.js +23 -0
  74. package/dist/src/html.d.ts +65 -0
  75. package/dist/src/html.js +335 -0
  76. package/dist/src/imageParameter.d.ts +65 -0
  77. package/dist/src/imageParameter.js +248 -0
  78. package/dist/src/imagemap.d.ts +56 -0
  79. package/dist/src/imagemap.js +150 -0
  80. package/dist/src/imagemapLink.d.ts +31 -0
  81. package/dist/src/imagemapLink.js +93 -0
  82. package/dist/src/index.d.ts +143 -0
  83. package/dist/src/index.js +803 -0
  84. package/dist/src/link/base.d.ts +52 -0
  85. package/dist/src/link/base.js +209 -0
  86. package/dist/src/link/category.d.ts +13 -0
  87. package/dist/src/link/category.js +28 -0
  88. package/dist/src/link/file.d.ts +96 -0
  89. package/dist/src/link/file.js +265 -0
  90. package/dist/src/link/galleryImage.d.ts +32 -0
  91. package/dist/src/link/galleryImage.js +157 -0
  92. package/dist/src/link/index.d.ts +56 -0
  93. package/dist/src/link/index.js +133 -0
  94. package/dist/src/magicLink.d.ts +59 -0
  95. package/dist/src/magicLink.js +199 -0
  96. package/dist/src/nested.d.ts +43 -0
  97. package/dist/src/nested.js +92 -0
  98. package/dist/src/nowiki/base.d.ts +31 -0
  99. package/dist/src/nowiki/base.js +93 -0
  100. package/dist/src/nowiki/comment.d.ts +25 -0
  101. package/dist/src/nowiki/comment.js +68 -0
  102. package/dist/src/nowiki/dd.d.ts +8 -0
  103. package/dist/src/nowiki/dd.js +24 -0
  104. package/dist/src/nowiki/doubleUnderscore.d.ts +18 -0
  105. package/dist/src/nowiki/doubleUnderscore.js +101 -0
  106. package/dist/src/nowiki/hr.d.ts +5 -0
  107. package/dist/src/nowiki/hr.js +63 -0
  108. package/dist/src/nowiki/index.d.ts +16 -0
  109. package/dist/src/nowiki/index.js +21 -0
  110. package/dist/src/nowiki/list.d.ts +16 -0
  111. package/dist/src/nowiki/list.js +97 -0
  112. package/dist/src/nowiki/listBase.d.ts +5 -0
  113. package/dist/src/nowiki/listBase.js +61 -0
  114. package/dist/src/nowiki/noinclude.d.ts +10 -0
  115. package/dist/src/nowiki/noinclude.js +23 -0
  116. package/dist/src/nowiki/quote.d.ts +14 -0
  117. package/dist/src/nowiki/quote.js +116 -0
  118. package/dist/src/onlyinclude.d.ts +16 -0
  119. package/dist/src/onlyinclude.js +57 -0
  120. package/dist/src/paramTag/index.d.ts +37 -0
  121. package/dist/src/paramTag/index.js +69 -0
  122. package/dist/src/paramTag/inputbox.d.ts +8 -0
  123. package/dist/src/paramTag/inputbox.js +22 -0
  124. package/dist/src/parameter.d.ts +70 -0
  125. package/dist/src/parameter.js +262 -0
  126. package/dist/src/pre.d.ts +28 -0
  127. package/dist/src/pre.js +55 -0
  128. package/dist/src/syntax.d.ts +20 -0
  129. package/dist/src/syntax.js +86 -0
  130. package/dist/src/table/base.d.ts +30 -0
  131. package/dist/src/table/base.js +132 -0
  132. package/dist/src/table/index.d.ts +233 -0
  133. package/dist/src/table/index.js +386 -0
  134. package/dist/src/table/td.d.ts +92 -0
  135. package/dist/src/table/td.js +337 -0
  136. package/dist/src/table/tr.d.ts +32 -0
  137. package/dist/src/table/tr.js +58 -0
  138. package/dist/src/table/trBase.d.ts +53 -0
  139. package/dist/src/table/trBase.js +154 -0
  140. package/dist/src/tagPair/ext.d.ts +32 -0
  141. package/dist/src/tagPair/ext.js +203 -0
  142. package/dist/src/tagPair/include.d.ts +35 -0
  143. package/dist/src/tagPair/include.js +63 -0
  144. package/dist/src/tagPair/index.d.ts +27 -0
  145. package/dist/src/tagPair/index.js +128 -0
  146. package/dist/src/transclude.d.ts +167 -0
  147. package/dist/src/transclude.js +710 -0
  148. package/dist/util/constants.js +113 -0
  149. package/dist/util/debug.js +88 -0
  150. package/dist/util/diff.js +82 -0
  151. package/dist/util/lint.js +30 -0
  152. package/dist/util/string.js +53 -0
  153. package/errors/README +1 -0
  154. package/package.json +14 -29
  155. package/printed/README +1 -0
  156. package/bundle/bundle.min.js +0 -36
  157. package/extensions/dist/base.js +0 -64
  158. package/extensions/dist/editor.js +0 -159
  159. package/extensions/dist/highlight.js +0 -59
  160. package/extensions/dist/lint.js +0 -48
  161. package/extensions/editor.css +0 -63
  162. package/extensions/ui.css +0 -141
@@ -0,0 +1,248 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ImageParameterToken = exports.galleryParams = void 0;
4
+ const string_1 = require("../util/string");
5
+ const lint_1 = require("../util/lint");
6
+ const debug_1 = require("../util/debug");
7
+ const constants_1 = require("../util/constants");
8
+ const index_1 = require("../index");
9
+ const index_2 = require("./index");
10
+ exports.galleryParams = new Set(['alt', 'link', 'lang', 'page', 'caption']);
11
+ function validate(key, val, config = index_1.default.getConfig(), halfParsed = false) {
12
+ val = val.trim();
13
+ let value = val.replace(/\0\d+t\x7F/gu, '').trim();
14
+ switch (key) {
15
+ case 'width':
16
+ return !value || /^(?:\d+x?|\d*x\d+)$/u.test(value);
17
+ case 'link': {
18
+ if (!value) {
19
+ return val;
20
+ }
21
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
22
+ /^(?:\/\/(?:\[[\da-f:.]+\]|[^[\]<>"\t\n\p{Zs}])|\0\d+m\x7F)(?:[^[\]<>"\0\t\n\p{Zs}]|\0\d+c\x7F)*$/iu;
23
+ const regex = new RegExp(`^(?:(?:${config.protocol}|//)${string_1.extUrlCharFirst}|\0\\d+m\x7F)${string_1.extUrlChar}$`, 'iu');
24
+ if (regex.test(value)) {
25
+ return val;
26
+ }
27
+ else if (value.startsWith('[[') && value.endsWith(']]')) {
28
+ value = value.slice(2, -2);
29
+ }
30
+ const title = index_1.default.normalizeTitle(value, 0, false, config, halfParsed, true, true);
31
+ return title.valid && title;
32
+ }
33
+ case 'lang':
34
+ return !value || config.variants.includes(value);
35
+ case 'alt':
36
+ case 'class':
37
+ case 'manualthumb':
38
+ return true;
39
+ default:
40
+ return !Number.isNaN(Number(value));
41
+ }
42
+ }
43
+ /** 图片参数 */
44
+ class ImageParameterToken extends index_2.Token {
45
+ type = 'image-parameter';
46
+ #syntax = '';
47
+ /* NOT FOR BROWSER END */
48
+ /** 图片链接 */
49
+ get link() {
50
+ return this.name === 'link' ? validate('link', super.text(), this.getAttribute('config')) : undefined;
51
+ }
52
+ /* NOT FOR BROWSER */
53
+ set link(value) {
54
+ if (this.name === 'link') {
55
+ this.setValue(value);
56
+ }
57
+ }
58
+ /** getValue()的getter */
59
+ get value() {
60
+ return this.getValue();
61
+ }
62
+ set value(value) {
63
+ this.setValue(value);
64
+ }
65
+ /** 图片大小 */
66
+ get size() {
67
+ if (this.name === 'width') {
68
+ const size = this.getValue().trim();
69
+ if (!size.includes('{{')) {
70
+ const [width, height = ''] = size.split('x');
71
+ return { width, height };
72
+ }
73
+ const token = index_1.default.parse(size, false, 2, this.getAttribute('config')), i = token.childNodes.findIndex(({ type, data }) => type === 'text' && data.includes('x'));
74
+ if (i === -1) {
75
+ return { width: size, height: '' };
76
+ }
77
+ const str = token.childNodes[i];
78
+ str.splitText(str.data.indexOf('x')).splitText(1);
79
+ return { width: (0, string_1.text)(token.childNodes.slice(0, i + 1)), height: (0, string_1.text)(token.childNodes.slice(i + 2)) };
80
+ }
81
+ return undefined;
82
+ }
83
+ set size(size) {
84
+ if (this.name === 'width') {
85
+ this.setValue(size && `${size.width}${size.height && 'x'}${size.height}`);
86
+ }
87
+ }
88
+ /** 图片宽度 */
89
+ get width() {
90
+ return this.size?.width;
91
+ }
92
+ set width(width) {
93
+ if (this.name === 'width') {
94
+ const { height } = this;
95
+ this.setValue(`${width || ''}${height && 'x'}${height}`);
96
+ }
97
+ }
98
+ /** 图片高度 */
99
+ get height() {
100
+ return this.size?.height;
101
+ }
102
+ set height(height) {
103
+ if (this.name === 'width') {
104
+ this.setValue(`${this.width}${height ? `x${height}` : ''}`);
105
+ }
106
+ }
107
+ /* NOT FOR BROWSER END */
108
+ /** @param str 图片参数 */
109
+ constructor(str, config = index_1.default.getConfig(), accum = []) {
110
+ let mt;
111
+ const regexes = Object.entries(config.img).map(([syntax, param]) => [
112
+ syntax,
113
+ param,
114
+ new RegExp(`^(\\s*)${syntax.replace('$1', '(.*)')}(\\s*)$`, 'u'),
115
+ ]), param = regexes.find(([, key, regex]) => {
116
+ mt = regex.exec(str);
117
+ return mt
118
+ && (mt.length !== 4 || validate(key, mt[2], config, true) !== false);
119
+ });
120
+ // @ts-expect-error mt already assigned
121
+ if (param && mt) {
122
+ if (mt.length === 3) {
123
+ super(undefined, config, accum);
124
+ this.#syntax = str;
125
+ }
126
+ else {
127
+ super(mt[2], config, accum, {
128
+ 'Stage-2': ':', '!HeadingToken': ':',
129
+ });
130
+ this.#syntax = `${mt[1]}${param[0]}${mt[3]}`;
131
+ }
132
+ this.setAttribute('name', param[1]);
133
+ return;
134
+ }
135
+ super(str, { ...config, excludes: [...config.excludes ?? [], 'list'] }, accum);
136
+ this.setAttribute('name', 'caption');
137
+ this.setAttribute('stage', 7);
138
+ }
139
+ /** @private */
140
+ afterBuild() {
141
+ if (this.parentNode?.type === 'gallery-image' && !exports.galleryParams.has(this.name)) {
142
+ this.setAttribute('name', 'invalid');
143
+ }
144
+ }
145
+ /** @private */
146
+ toString() {
147
+ return this.#syntax ? this.#syntax.replace('$1', super.toString()) : super.toString();
148
+ }
149
+ /** @override */
150
+ text() {
151
+ return this.#syntax ? this.#syntax.replace('$1', super.text()).trim() : super.text().trim();
152
+ }
153
+ /** @private */
154
+ getAttribute(key) {
155
+ if (key === 'plain') {
156
+ return (this.name === 'caption');
157
+ /* NOT FOR BROWSER */
158
+ }
159
+ else if (key === 'syntax') {
160
+ return this.#syntax;
161
+ /* NOT FOR BROWSER END */
162
+ }
163
+ return key === 'padding'
164
+ ? Math.max(0, this.#syntax.indexOf('$1'))
165
+ : super.getAttribute(key);
166
+ }
167
+ /** @override */
168
+ lint(start = this.getAbsoluteIndex()) {
169
+ const errors = super.lint(start), { link, name } = this;
170
+ if (name === 'invalid') {
171
+ errors.push((0, lint_1.generateForSelf)(this, { start }, 'invalid gallery image parameter'));
172
+ }
173
+ else if (typeof link === 'object' && link.encoded) {
174
+ errors.push((0, lint_1.generateForSelf)(this, { start }, 'unnecessary URL encoding in an internal link'));
175
+ }
176
+ return errors;
177
+ }
178
+ /** 是否是不可变参数 */
179
+ #isVoid() {
180
+ return this.#syntax && !this.#syntax.includes('$1');
181
+ }
182
+ /** 获取参数值 */
183
+ getValue() {
184
+ return this.name === 'invalid' ? this.text() : this.#isVoid() || super.text();
185
+ }
186
+ /** @override */
187
+ print() {
188
+ if (this.#syntax) {
189
+ return this.name === 'invalid'
190
+ ? `<span class="wpb-image-invalid">${this.#syntax.replace('$1', (0, string_1.print)(this.childNodes))}</span>`
191
+ : `<span class="wpb-image-parameter">${this.#syntax.replace('$1', `<span class="wpb-image-caption">${(0, string_1.print)(this.childNodes)}</span>`)}</span>`;
192
+ }
193
+ return super.print({ class: 'image-caption' });
194
+ }
195
+ /* NOT FOR BROWSER */
196
+ /** @override */
197
+ cloneNode() {
198
+ const cloned = this.cloneChildNodes(), config = this.getAttribute('config');
199
+ return debug_1.Shadow.run(() => {
200
+ // @ts-expect-error abstract class
201
+ const token = new ImageParameterToken(this.#syntax.replace('$1', ''), config);
202
+ token.replaceChildren(...cloned);
203
+ token.setAttribute('name', this.name);
204
+ token.setAttribute('syntax', this.#syntax);
205
+ return token;
206
+ });
207
+ }
208
+ /** @private */
209
+ setAttribute(key, value) {
210
+ if (key === 'syntax') {
211
+ this.#syntax = value;
212
+ }
213
+ else {
214
+ super.setAttribute(key, value);
215
+ }
216
+ }
217
+ insertAt(token, i) {
218
+ if (!debug_1.Shadow.running && this.#isVoid()) {
219
+ throw new Error(`图片参数 ${this.name} 不接受自定义输入!`);
220
+ }
221
+ return super.insertAt(token, i);
222
+ }
223
+ /**
224
+ * 设置参数值
225
+ * @param value 参数值
226
+ * @throws `Error` 无效参数
227
+ */
228
+ setValue(value = false) {
229
+ const { name } = this;
230
+ if (value === false) {
231
+ this.remove();
232
+ return;
233
+ }
234
+ else if (name === 'invalid') {
235
+ throw new Error('当前节点是一个无效的图片参数!');
236
+ }
237
+ const type = this.#isVoid() ? 'Boolean' : 'String';
238
+ if (typeof value !== type.toLowerCase()) { // eslint-disable-line valid-typeof
239
+ this.typeError('setValue', type);
240
+ }
241
+ else if (value !== true) {
242
+ const include = this.getAttribute('include'), config = this.getAttribute('config'), { childNodes } = index_1.default.parse(value, include, name === 'caption' ? undefined : 5, config);
243
+ this.replaceChildren(...childNodes);
244
+ }
245
+ }
246
+ }
247
+ exports.ImageParameterToken = ImageParameterToken;
248
+ constants_1.classes['ImageParameterToken'] = __filename;
@@ -0,0 +1,56 @@
1
+ import Parser from '../index';
2
+ import { Token } from './index';
3
+ import { NoincludeToken } from './nowiki/noinclude';
4
+ import { GalleryImageToken } from './link/galleryImage';
5
+ import { ImagemapLinkToken } from './imagemapLink';
6
+ import type { LintError } from '../base';
7
+ import type { AstText, AttributesToken, ExtToken, AstNodes } from '../internal';
8
+ /**
9
+ * `<imagemap>`
10
+ * @classdesc `{childNodes: ...NoincludeToken, GalleryImageToken, ...(NoincludeToken|ImagemapLinkToken|AstText)}`
11
+ */
12
+ export declare abstract class ImagemapToken extends Token {
13
+ readonly type = "ext-inner";
14
+ readonly name: 'imagemap';
15
+ readonly childNodes: readonly (GalleryImageToken | NoincludeToken | ImagemapLinkToken | AstText)[];
16
+ abstract get firstChild(): NoincludeToken | GalleryImageToken | undefined;
17
+ abstract get lastChild(): GalleryImageToken | NoincludeToken | ImagemapLinkToken | AstText | undefined;
18
+ abstract get nextSibling(): undefined;
19
+ abstract get previousSibling(): AttributesToken;
20
+ abstract get parentNode(): ExtToken | undefined;
21
+ abstract get children(): (GalleryImageToken | NoincludeToken | ImagemapLinkToken)[];
22
+ abstract get firstElementChild(): NoincludeToken | GalleryImageToken | undefined;
23
+ abstract get lastElementChild(): GalleryImageToken | NoincludeToken | ImagemapLinkToken | undefined;
24
+ abstract get nextElementSibling(): undefined;
25
+ abstract get previousElementSibling(): AttributesToken;
26
+ abstract get parentElement(): ExtToken | undefined;
27
+ /** 图片 */
28
+ get image(): GalleryImageToken | undefined;
29
+ /** 链接 */
30
+ get links(): ImagemapLinkToken[];
31
+ /** @param inner 标签内部wikitext */
32
+ constructor(inner?: string, config?: Parser.Config, accum?: Token[]);
33
+ /** @override */
34
+ text(): string;
35
+ /** @override */
36
+ lint(start?: number): LintError[];
37
+ /** @override */
38
+ print(): string;
39
+ /**
40
+ * @override
41
+ * @param token 待插入的节点
42
+ * @param i 插入位置
43
+ * @throws `Error` 当前缺少合法图片
44
+ * @throws `RangeError` 已有一张合法图片
45
+ */
46
+ insertAt(token: string, i?: number): AstText;
47
+ insertAt<T extends AstNodes>(token: T, i?: number): T;
48
+ /**
49
+ * @override
50
+ * @param i 移除位置
51
+ * @throws `Error` 禁止移除图片
52
+ */
53
+ removeAt(i: number): AstNodes;
54
+ /** @override */
55
+ cloneNode(): this;
56
+ }
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ImagemapToken = void 0;
4
+ const lint_1 = require("../util/lint");
5
+ const debug_1 = require("../util/debug");
6
+ const constants_1 = require("../util/constants");
7
+ const singleLine_1 = require("../mixin/singleLine");
8
+ const index_1 = require("../index");
9
+ const index_2 = require("./index");
10
+ const noinclude_1 = require("./nowiki/noinclude");
11
+ const galleryImage_1 = require("./link/galleryImage");
12
+ const imagemapLink_1 = require("./imagemapLink");
13
+ /**
14
+ * `<imagemap>`
15
+ * @classdesc `{childNodes: ...NoincludeToken, GalleryImageToken, ...(NoincludeToken|ImagemapLinkToken|AstText)}`
16
+ */
17
+ class ImagemapToken extends index_2.Token {
18
+ type = 'ext-inner';
19
+ /* NOT FOR BROWSER END */
20
+ /** 图片 */
21
+ get image() {
22
+ return this.childNodes.find((0, debug_1.isToken)('imagemap-image'));
23
+ }
24
+ /* NOT FOR BROWSER */
25
+ /** 链接 */
26
+ get links() {
27
+ return this.childNodes.filter((0, debug_1.isToken)('imagemap-link'));
28
+ }
29
+ /* NOT FOR BROWSER END */
30
+ /** @param inner 标签内部wikitext */
31
+ constructor(inner, config = index_1.default.getConfig(), accum = []) {
32
+ super(undefined, config, accum, {
33
+ GalleryImageToken: ':', ImagemapLinkToken: ':', NoincludeToken: ':', AstText: ':',
34
+ });
35
+ if (!inner) {
36
+ return;
37
+ }
38
+ const lines = inner.split('\n'), protocols = new Set(config.protocol.split('|')), SingleLineNoincludeToken = (0, singleLine_1.singleLine)(noinclude_1.NoincludeToken);
39
+ let first = true, error = false;
40
+ for (const line of lines) {
41
+ const trimmed = line.trim();
42
+ if (error || !trimmed || trimmed.startsWith('#')) {
43
+ //
44
+ }
45
+ else if (first) {
46
+ const [file, ...options] = line.split('|'), title = this.normalizeTitle(file, 0, true);
47
+ if (title.valid && !title.interwiki && title.ns === 6) {
48
+ // @ts-expect-error abstract class
49
+ const token = new galleryImage_1.GalleryImageToken('imagemap', file, options.length > 0 ? options.join('|') : undefined, config, accum);
50
+ super.insertAt(token);
51
+ first = false;
52
+ continue;
53
+ }
54
+ else {
55
+ error = true;
56
+ }
57
+ }
58
+ else if (line.trim().split(/[\t ]/u)[0] === 'desc') {
59
+ super.insertAt(line);
60
+ continue;
61
+ }
62
+ else if (line.includes('[')) {
63
+ const i = line.indexOf('['), substr = line.slice(i), mtIn = /^\[{2}([^|]+)(?:\|([^\]]+))?\]{2}[\w\s]*$/u
64
+ .exec(substr);
65
+ if (mtIn) {
66
+ if (this.normalizeTitle(mtIn[1], 0, true, false, true).valid) {
67
+ // @ts-expect-error abstract class
68
+ super.insertAt(new imagemapLink_1.ImagemapLinkToken(line.slice(0, i), mtIn.slice(1), substr.slice(substr.indexOf(']]') + 2), config, accum));
69
+ continue;
70
+ }
71
+ }
72
+ else if (protocols.has(substr.slice(1, substr.indexOf(':') + 1))
73
+ || protocols.has(substr.slice(1, substr.indexOf('//') + 2))) {
74
+ const mtEx = /^\[([^\]\s]+)(?:(\s+(?=\S))([^\]]*))?\][\w\s]*$/u
75
+ .exec(substr);
76
+ if (mtEx) {
77
+ // @ts-expect-error abstract class
78
+ super.insertAt(new imagemapLink_1.ImagemapLinkToken(line.slice(0, i), mtEx.slice(1), substr.slice(substr.indexOf(']') + 1), config, accum));
79
+ continue;
80
+ }
81
+ }
82
+ }
83
+ // @ts-expect-error abstract class
84
+ super.insertAt(new SingleLineNoincludeToken(line, config, accum));
85
+ }
86
+ }
87
+ /** @private */
88
+ toString() {
89
+ return super.toString('\n');
90
+ }
91
+ /** @override */
92
+ text() {
93
+ return super.text('\n').replace(/\n{2,}/gu, '\n');
94
+ }
95
+ /** @private */
96
+ getGaps() {
97
+ return 1;
98
+ }
99
+ /** @override */
100
+ lint(start = this.getAbsoluteIndex()) {
101
+ const errors = super.lint(start), rect = { start, ...this.getRootNode().posFromIndex(start) };
102
+ if (this.image) {
103
+ errors.push(...this.childNodes.filter(child => {
104
+ const str = String(child).trim();
105
+ return child.type === 'noinclude' && str && !str.startsWith('#');
106
+ }).map(child => (0, lint_1.generateForChild)(child, rect, 'invalid link in <imagemap>')));
107
+ }
108
+ else {
109
+ errors.push((0, lint_1.generateForSelf)(this, rect, '<imagemap> without an image'));
110
+ }
111
+ return errors;
112
+ }
113
+ /** @override */
114
+ print() {
115
+ return super.print({ sep: '\n' });
116
+ }
117
+ insertAt(token, i) {
118
+ const { image } = this;
119
+ if (!image && (typeof token === 'string' || token.type === 'imagemap-link' || token.type === 'text')) {
120
+ throw new Error('当前缺少一张合法图片!');
121
+ }
122
+ else if (image && typeof token !== 'string' && token.type === 'imagemap-image') {
123
+ throw new RangeError('已有一张合法图片!');
124
+ }
125
+ return super.insertAt(token, i);
126
+ }
127
+ /**
128
+ * @override
129
+ * @param i 移除位置
130
+ * @throws `Error` 禁止移除图片
131
+ */
132
+ removeAt(i) {
133
+ if (this.childNodes[i]?.type === 'imagemap-image') {
134
+ throw new Error('禁止移除<imagemap>内的图片!');
135
+ }
136
+ return super.removeAt(i);
137
+ }
138
+ /** @override */
139
+ cloneNode() {
140
+ const cloned = this.cloneChildNodes();
141
+ return debug_1.Shadow.run(() => {
142
+ // @ts-expect-error abstract class
143
+ const token = new ImagemapToken(undefined, this.getAttribute('config'));
144
+ token.append(...cloned);
145
+ return token;
146
+ });
147
+ }
148
+ }
149
+ exports.ImagemapToken = ImagemapToken;
150
+ constants_1.classes['ImagemapToken'] = __filename;
@@ -0,0 +1,31 @@
1
+ import Parser from '../index';
2
+ import { Token } from './index';
3
+ import { NoincludeToken } from './nowiki/noinclude';
4
+ import { LinkToken } from './link/index';
5
+ import { ExtLinkToken } from './extLink';
6
+ import type { Title } from '../lib/title';
7
+ import type { AstText, ImagemapToken } from '../internal';
8
+ /**
9
+ * `<imagemap>`内的链接
10
+ * @classdesc `{childNodes: [AstText, LinkToken|ExtLinkToken, NoincludeToken]}`
11
+ */
12
+ export declare abstract class ImagemapLinkToken extends Token {
13
+ readonly type = "imagemap-link";
14
+ readonly childNodes: readonly [AstText, LinkToken | ExtLinkToken, NoincludeToken];
15
+ abstract get firstChild(): AstText;
16
+ abstract get lastChild(): NoincludeToken;
17
+ abstract get parentNode(): ImagemapToken | undefined;
18
+ abstract get children(): [LinkToken | ExtLinkToken, NoincludeToken];
19
+ abstract get firstElementChild(): LinkToken | ExtLinkToken;
20
+ abstract get lastElementChild(): NoincludeToken;
21
+ abstract get parentElement(): ImagemapToken | undefined;
22
+ /** 内外链接 */
23
+ get link(): string | Title;
24
+ set link(link: string);
25
+ /**
26
+ * @param pre 链接前的文本
27
+ * @param linkStuff 内外链接
28
+ * @param post 链接后的文本
29
+ */
30
+ constructor(pre: string, linkStuff: readonly [string, string | undefined, string | undefined] | readonly [string, string | undefined], post: string, config?: Parser.Config, accum?: Token[]);
31
+ }
@@ -0,0 +1,93 @@
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.ImagemapLinkToken = void 0;
38
+ const constants_1 = require("../util/constants");
39
+ const fixed_1 = require("../mixin/fixed");
40
+ const singleLine_1 = require("../mixin/singleLine");
41
+ const index_1 = require("../index");
42
+ const index_2 = require("./index");
43
+ const noinclude_1 = require("./nowiki/noinclude");
44
+ const index_3 = require("./link/index");
45
+ const extLink_1 = require("./extLink");
46
+ /**
47
+ * `<imagemap>`内的链接
48
+ * @classdesc `{childNodes: [AstText, LinkToken|ExtLinkToken, NoincludeToken]}`
49
+ */
50
+ let ImagemapLinkToken = (() => {
51
+ let _classDecorators = [fixed_1.fixedToken, singleLine_1.singleLine];
52
+ let _classDescriptor;
53
+ let _classExtraInitializers = [];
54
+ let _classThis;
55
+ let _classSuper = index_2.Token;
56
+ var ImagemapLinkToken = class extends _classSuper {
57
+ static { _classThis = this; }
58
+ static {
59
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
60
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
61
+ ImagemapLinkToken = _classThis = _classDescriptor.value;
62
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
63
+ __runInitializers(_classThis, _classExtraInitializers);
64
+ }
65
+ type = 'imagemap-link';
66
+ /** 内外链接 */
67
+ get link() {
68
+ return this.childNodes[1].link;
69
+ }
70
+ set link(link) {
71
+ this.childNodes[1].link = link;
72
+ }
73
+ /* NOT FOR BROWSER END */
74
+ /**
75
+ * @param pre 链接前的文本
76
+ * @param linkStuff 内外链接
77
+ * @param post 链接后的文本
78
+ */
79
+ constructor(pre, linkStuff, post, config = index_1.default.getConfig(), accum = []) {
80
+ super(undefined, config, accum);
81
+ this.append(pre, linkStuff.length === 2
82
+ // @ts-expect-error abstract class
83
+ ? new index_3.LinkToken(...linkStuff, config, accum)
84
+ // @ts-expect-error abstract class
85
+ : new extLink_1.ExtLinkToken(...linkStuff, config, accum),
86
+ // @ts-expect-error abstract class
87
+ new noinclude_1.NoincludeToken(post, config, accum));
88
+ }
89
+ };
90
+ return ImagemapLinkToken = _classThis;
91
+ })();
92
+ exports.ImagemapLinkToken = ImagemapLinkToken;
93
+ constants_1.classes['ImagemapLinkToken'] = __filename;