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