wikiparser-node 1.9.1 → 1.9.2-b

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