wikiparser-node 1.9.3-b → 1.9.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 (171) hide show
  1. package/config/.schema.json +181 -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.js +486 -0
  7. package/dist/addon/token.js +240 -0
  8. package/dist/addon/transclude.js +185 -0
  9. package/dist/base.d.ts +79 -0
  10. package/dist/base.js +39 -0
  11. package/dist/index.d.ts +31 -0
  12. package/dist/index.js +231 -0
  13. package/dist/internal.d.ts +46 -0
  14. package/dist/lib/element.d.ts +125 -0
  15. package/dist/lib/element.js +374 -0
  16. package/dist/lib/node.d.ts +168 -0
  17. package/dist/lib/node.js +472 -0
  18. package/dist/lib/range.d.ts +105 -0
  19. package/dist/lib/range.js +406 -0
  20. package/dist/lib/ranges.d.ts +28 -0
  21. package/dist/lib/ranges.js +126 -0
  22. package/dist/lib/rect.d.ts +18 -0
  23. package/dist/lib/rect.js +34 -0
  24. package/dist/lib/text.d.ts +55 -0
  25. package/dist/lib/text.js +351 -0
  26. package/dist/lib/title.d.ts +40 -0
  27. package/dist/lib/title.js +197 -0
  28. package/dist/mixin/attributesParent.d.ts +49 -0
  29. package/dist/mixin/attributesParent.js +82 -0
  30. package/dist/mixin/fixed.d.ts +5 -0
  31. package/dist/mixin/fixed.js +32 -0
  32. package/dist/mixin/flagsParent.d.ts +41 -0
  33. package/dist/mixin/flagsParent.js +60 -0
  34. package/dist/mixin/hidden.d.ts +6 -0
  35. package/dist/mixin/hidden.js +34 -0
  36. package/dist/mixin/magicLinkParent.d.ts +19 -0
  37. package/dist/mixin/magicLinkParent.js +43 -0
  38. package/dist/mixin/singleLine.d.ts +5 -0
  39. package/dist/mixin/singleLine.js +27 -0
  40. package/dist/mixin/sol.d.ts +5 -0
  41. package/dist/mixin/sol.js +44 -0
  42. package/dist/mixin/syntax.d.ts +8 -0
  43. package/dist/mixin/syntax.js +48 -0
  44. package/dist/parser/braces.js +150 -0
  45. package/dist/parser/commentAndExt.js +79 -0
  46. package/dist/parser/converter.js +39 -0
  47. package/dist/parser/externalLinks.js +37 -0
  48. package/dist/parser/hrAndDoubleUnderscore.js +42 -0
  49. package/dist/parser/html.js +38 -0
  50. package/dist/parser/links.js +101 -0
  51. package/dist/parser/list.js +97 -0
  52. package/dist/parser/magicLinks.js +53 -0
  53. package/dist/parser/quotes.js +67 -0
  54. package/dist/parser/redirect.js +26 -0
  55. package/dist/parser/selector.js +393 -0
  56. package/dist/parser/table.js +123 -0
  57. package/dist/src/arg.d.ts +51 -0
  58. package/dist/src/arg.js +214 -0
  59. package/dist/src/atom.d.ts +14 -0
  60. package/dist/src/atom.js +52 -0
  61. package/dist/src/attribute.d.ts +64 -0
  62. package/dist/src/attribute.js +486 -0
  63. package/dist/src/attributes.d.ts +102 -0
  64. package/dist/src/attributes.js +355 -0
  65. package/dist/src/converter.d.ts +28 -0
  66. package/dist/src/converter.js +137 -0
  67. package/dist/src/converterFlags.d.ts +80 -0
  68. package/dist/src/converterFlags.js +242 -0
  69. package/dist/src/converterRule.d.ts +71 -0
  70. package/dist/src/converterRule.js +212 -0
  71. package/dist/src/extLink.d.ts +36 -0
  72. package/dist/src/extLink.js +194 -0
  73. package/dist/src/gallery.d.ts +47 -0
  74. package/dist/src/gallery.js +142 -0
  75. package/dist/src/heading.d.ts +40 -0
  76. package/dist/src/heading.js +186 -0
  77. package/dist/src/hidden.d.ts +9 -0
  78. package/dist/src/hidden.js +80 -0
  79. package/dist/src/html.d.ts +57 -0
  80. package/dist/src/html.js +335 -0
  81. package/dist/src/imageParameter.d.ts +58 -0
  82. package/dist/src/imageParameter.js +247 -0
  83. package/dist/src/imagemap.d.ts +47 -0
  84. package/dist/src/imagemap.js +146 -0
  85. package/dist/src/imagemapLink.d.ts +31 -0
  86. package/dist/src/imagemapLink.js +97 -0
  87. package/dist/src/index.d.ts +131 -0
  88. package/dist/src/index.js +746 -0
  89. package/dist/src/link/base.d.ts +45 -0
  90. package/dist/src/link/base.js +226 -0
  91. package/dist/src/link/category.d.ts +22 -0
  92. package/dist/src/link/category.js +34 -0
  93. package/dist/src/link/file.d.ts +96 -0
  94. package/dist/src/link/file.js +276 -0
  95. package/dist/src/link/galleryImage.d.ts +29 -0
  96. package/dist/src/link/galleryImage.js +132 -0
  97. package/dist/src/link/index.d.ts +51 -0
  98. package/dist/src/link/index.js +136 -0
  99. package/dist/src/link/redirectTarget.d.ts +36 -0
  100. package/dist/src/link/redirectTarget.js +98 -0
  101. package/dist/src/magicLink.d.ts +60 -0
  102. package/dist/src/magicLink.js +273 -0
  103. package/dist/src/nested.d.ts +40 -0
  104. package/dist/src/nested.js +106 -0
  105. package/dist/src/nowiki/base.d.ts +30 -0
  106. package/dist/src/nowiki/base.js +89 -0
  107. package/dist/src/nowiki/comment.d.ts +14 -0
  108. package/dist/src/nowiki/comment.js +124 -0
  109. package/dist/src/nowiki/dd.d.ts +8 -0
  110. package/dist/src/nowiki/dd.js +26 -0
  111. package/dist/src/nowiki/doubleUnderscore.d.ts +15 -0
  112. package/dist/src/nowiki/doubleUnderscore.js +97 -0
  113. package/dist/src/nowiki/hr.d.ts +5 -0
  114. package/dist/src/nowiki/hr.js +65 -0
  115. package/dist/src/nowiki/index.d.ts +14 -0
  116. package/dist/src/nowiki/index.js +31 -0
  117. package/dist/src/nowiki/list.d.ts +16 -0
  118. package/dist/src/nowiki/list.js +111 -0
  119. package/dist/src/nowiki/listBase.d.ts +5 -0
  120. package/dist/src/nowiki/listBase.js +61 -0
  121. package/dist/src/nowiki/noinclude.d.ts +6 -0
  122. package/dist/src/nowiki/noinclude.js +71 -0
  123. package/dist/src/nowiki/quote.d.ts +14 -0
  124. package/dist/src/nowiki/quote.js +130 -0
  125. package/dist/src/onlyinclude.d.ts +13 -0
  126. package/dist/src/onlyinclude.js +58 -0
  127. package/dist/src/paramTag/index.d.ts +30 -0
  128. package/dist/src/paramTag/index.js +78 -0
  129. package/dist/src/paramTag/inputbox.d.ts +8 -0
  130. package/dist/src/paramTag/inputbox.js +22 -0
  131. package/dist/src/parameter.d.ts +60 -0
  132. package/dist/src/parameter.js +261 -0
  133. package/dist/src/pre.d.ts +28 -0
  134. package/dist/src/pre.js +60 -0
  135. package/dist/src/redirect.d.ts +30 -0
  136. package/dist/src/redirect.js +122 -0
  137. package/dist/src/syntax.d.ts +17 -0
  138. package/dist/src/syntax.js +87 -0
  139. package/dist/src/table/base.d.ts +28 -0
  140. package/dist/src/table/base.js +81 -0
  141. package/dist/src/table/index.d.ts +230 -0
  142. package/dist/src/table/index.js +495 -0
  143. package/dist/src/table/td.d.ts +72 -0
  144. package/dist/src/table/td.js +364 -0
  145. package/dist/src/table/tr.d.ts +30 -0
  146. package/dist/src/table/tr.js +59 -0
  147. package/dist/src/table/trBase.d.ts +49 -0
  148. package/dist/src/table/trBase.js +156 -0
  149. package/dist/src/tagPair/ext.d.ts +29 -0
  150. package/dist/src/tagPair/ext.js +204 -0
  151. package/dist/src/tagPair/include.d.ts +33 -0
  152. package/dist/src/tagPair/include.js +126 -0
  153. package/dist/src/tagPair/index.d.ts +23 -0
  154. package/dist/src/tagPair/index.js +128 -0
  155. package/dist/src/transclude.d.ts +159 -0
  156. package/dist/src/transclude.js +582 -0
  157. package/dist/util/constants.js +25 -0
  158. package/dist/util/debug.js +95 -0
  159. package/dist/util/diff.js +83 -0
  160. package/dist/util/lint.js +32 -0
  161. package/dist/util/string.js +60 -0
  162. package/errors/README +1 -0
  163. package/package.json +22 -32
  164. package/printed/README +1 -0
  165. package/bundle/bundle.min.js +0 -39
  166. package/extensions/dist/base.js +0 -64
  167. package/extensions/dist/editor.js +0 -159
  168. package/extensions/dist/highlight.js +0 -58
  169. package/extensions/dist/lint.js +0 -72
  170. package/extensions/editor.css +0 -64
  171. package/extensions/ui.css +0 -144
@@ -0,0 +1,276 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileToken = void 0;
4
+ const string_1 = require("../../util/string");
5
+ const lint_1 = require("../../util/lint");
6
+ const rect_1 = require("../../lib/rect");
7
+ const debug_1 = require("../../util/debug");
8
+ const constants_1 = require("../../util/constants");
9
+ const index_1 = require("../../index");
10
+ const base_1 = require("./base");
11
+ const imageParameter_1 = require("../imageParameter");
12
+ const frame = new Set(['manualthumb', 'frameless', 'framed', 'thumbnail']), horizAlign = new Set(['left', 'right', 'center', 'none']), vertAlign = new Set(['baseline', 'sub', 'super', 'top', 'text-top', 'middle', 'bottom', 'text-bottom']);
13
+ /**
14
+ * a more sophisticated string-explode function
15
+ * @param start start syntax of a nested AST node
16
+ * @param end end syntax of a nested AST node
17
+ * @param separator syntax for explosion
18
+ * @param str string to be exploded
19
+ */
20
+ const explode = (start, end, separator, str) => {
21
+ if (str === undefined) {
22
+ return [];
23
+ }
24
+ const regex = new RegExp(`${[start, end, separator].map(string_1.escapeRegExp).join('|')}`, 'gu'), exploded = [];
25
+ let mt = regex.exec(str), depth = 0, lastIndex = 0;
26
+ while (mt) {
27
+ const { 0: match, index } = mt;
28
+ if (match !== separator) {
29
+ depth += match === start ? 1 : -1;
30
+ }
31
+ else if (depth === 0) {
32
+ exploded.push(str.slice(lastIndex, index));
33
+ ({ lastIndex } = regex);
34
+ }
35
+ mt = regex.exec(str);
36
+ }
37
+ exploded.push(str.slice(lastIndex));
38
+ return exploded;
39
+ };
40
+ /**
41
+ * 图片
42
+ * @classdesc `{childNodes: [AtomToken, ...ImageParameterToken]}`
43
+ */
44
+ class FileToken extends base_1.LinkBaseToken {
45
+ /* NOT FOR BROWSER END */
46
+ get type() {
47
+ return 'file';
48
+ }
49
+ /** 扩展名 */
50
+ get extension() {
51
+ return this.getTitle().extension;
52
+ }
53
+ /* NOT FOR BROWSER */
54
+ /** 图片链接 */
55
+ get link() {
56
+ return this.getArg('link')?.link ?? super.link;
57
+ }
58
+ set link(value) {
59
+ this.setValue('link', value);
60
+ }
61
+ /** 图片大小 */
62
+ get size() {
63
+ return this.getArg('width')?.size;
64
+ }
65
+ set size(size) {
66
+ this.setValue('width', size && size.width + (size.height && 'x') + size.height);
67
+ }
68
+ /** 图片宽度 */
69
+ get width() {
70
+ return this.size?.width;
71
+ }
72
+ set width(width) {
73
+ const arg = this.getArg('width');
74
+ if (arg) {
75
+ arg.width = width;
76
+ }
77
+ else {
78
+ this.setValue('width', width);
79
+ }
80
+ }
81
+ /** 图片高度 */
82
+ get height() {
83
+ return this.size?.height;
84
+ }
85
+ set height(height) {
86
+ const arg = this.getArg('width');
87
+ if (arg) {
88
+ arg.height = height;
89
+ }
90
+ else {
91
+ this.setValue('width', height && `x${height}`);
92
+ }
93
+ }
94
+ /* NOT FOR BROWSER END */
95
+ /**
96
+ * @param link 文件名
97
+ * @param text 图片参数
98
+ * @param delimiter `|`
99
+ */
100
+ constructor(link, text, config = index_1.default.getConfig(), accum = [], delimiter = '|') {
101
+ super(link, undefined, config, accum, delimiter);
102
+ /* NOT FOR BROWSER */
103
+ this.setAttribute('acceptable', { AtomToken: 0, ImageParameterToken: '1:' });
104
+ /* NOT FOR BROWSER END */
105
+ const { extension } = this.getTitle(true);
106
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
107
+ /-\{|\}-|\|/gu;
108
+ this.append(...explode('-{', '}-', '|', text).map(
109
+ // @ts-expect-error abstract class
110
+ part => new imageParameter_1.ImageParameterToken(part, extension, config, accum)));
111
+ }
112
+ /** @private */
113
+ lint(start = this.getAbsoluteIndex(), re) {
114
+ const errors = super.lint(start, re), args = this.getAllArgs().filter(({ childNodes }) => {
115
+ const visibleNodes = childNodes.filter(node => node.text().trim());
116
+ return visibleNodes.length !== 1 || visibleNodes[0].type !== 'arg';
117
+ }), keys = [...new Set(args.map(({ name }) => name))].filter(key => key !== 'invalid'), frameKeys = keys.filter(key => frame.has(key)), horizAlignKeys = keys.filter(key => horizAlign.has(key)), vertAlignKeys = keys.filter(key => vertAlign.has(key)), rect = new rect_1.BoundingRect(this, start);
118
+ if (this.closest('ext-link-text') && this.getValue('link')?.trim() !== '') {
119
+ errors.push((0, lint_1.generateForSelf)(this, rect, 'nested-link', 'internal link in an external link'));
120
+ }
121
+ if (args.length === keys.length
122
+ && frameKeys.length < 2
123
+ && horizAlignKeys.length < 2
124
+ && vertAlignKeys.length < 2) {
125
+ return errors;
126
+ }
127
+ /**
128
+ * 图片参数到语法错误的映射
129
+ * @param msg 消息键
130
+ * @param p1 替换$1
131
+ */
132
+ const generate = (msg, p1) => (arg) => (0, lint_1.generateForChild)(arg, rect, 'no-duplicate', index_1.default.msg(`${msg} image $1 parameter`, p1));
133
+ for (const key of keys) {
134
+ let relevantArgs = args.filter(({ name }) => name === key);
135
+ if (key === 'caption') {
136
+ relevantArgs = [...relevantArgs.slice(0, -1).filter(arg => arg.text()), ...relevantArgs.slice(-1)];
137
+ }
138
+ if (relevantArgs.length > 1) {
139
+ errors.push(...relevantArgs.map(generate('duplicated', key)));
140
+ }
141
+ }
142
+ if (frameKeys.length > 1) {
143
+ errors.push(...args.filter(({ name }) => frame.has(name)).map(generate('conflicting', 'frame')));
144
+ }
145
+ if (horizAlignKeys.length > 1) {
146
+ errors.push(...args.filter(({ name }) => horizAlign.has(name)).map(generate('conflicting', 'horizontal-alignment')));
147
+ }
148
+ if (vertAlignKeys.length > 1) {
149
+ errors.push(...args.filter(({ name }) => vertAlign.has(name)).map(generate('conflicting', 'vertical-alignment')));
150
+ }
151
+ return errors;
152
+ }
153
+ /** 获取所有图片参数节点 */
154
+ getAllArgs() {
155
+ return this.childNodes.slice(1);
156
+ }
157
+ /**
158
+ * 获取指定图片参数
159
+ * @param key 参数名
160
+ */
161
+ getArgs(key) {
162
+ return this.getAllArgs().filter(({ name }) => key === name);
163
+ }
164
+ /**
165
+ * 获取特定类型的图片属性参数节点
166
+ * @param keys 接受的参数名
167
+ * @param type 类型名
168
+ */
169
+ #getTypedArgs(keys, type) {
170
+ const args = this.getAllArgs().filter(({ name }) => keys.has(name));
171
+ /* NOT FOR BROWSER */
172
+ if (args.length > 1) {
173
+ index_1.default.warn(`The image ${this.name} has ${args.length} ${type} parameters. Only the last ${args[0].name} will take effect!`);
174
+ }
175
+ /* NOT FOR BROWSER END */
176
+ return args;
177
+ }
178
+ /** 获取图片框架属性参数节点 */
179
+ getFrameArgs() {
180
+ return this.#getTypedArgs(frame, 'frame');
181
+ }
182
+ /** 获取图片水平对齐参数节点 */
183
+ getHorizAlignArgs() {
184
+ return this.#getTypedArgs(horizAlign, 'horizontal-align');
185
+ }
186
+ /** 获取图片垂直对齐参数节点 */
187
+ getVertAlignArgs() {
188
+ return this.#getTypedArgs(vertAlign, 'vertical-align');
189
+ }
190
+ /**
191
+ * 获取生效的指定图片参数
192
+ * @param key 参数名
193
+ */
194
+ getArg(key) {
195
+ const args = this.getArgs(key);
196
+ return args[args.length - 1];
197
+ }
198
+ /**
199
+ * 获取生效的指定图片参数值
200
+ * @param key 参数名
201
+ */
202
+ getValue(key) {
203
+ return this.getArg(key)?.getValue();
204
+ }
205
+ /* NOT FOR BROWSER */
206
+ /**
207
+ * 是否具有指定图片参数
208
+ * @param key 参数名
209
+ */
210
+ hasArg(key) {
211
+ return this.getArgs(key).length > 0;
212
+ }
213
+ /**
214
+ * 移除指定图片参数
215
+ * @param key 参数名
216
+ */
217
+ removeArg(key) {
218
+ for (const token of this.getArgs(key)) {
219
+ this.removeChild(token);
220
+ }
221
+ }
222
+ /** 获取图片参数名 */
223
+ getKeys() {
224
+ return new Set(this.getAllArgs().map(({ name }) => name));
225
+ }
226
+ /**
227
+ * 获取指定的图片参数值
228
+ * @param key 参数名
229
+ */
230
+ getValues(key) {
231
+ return this.getArgs(key).map(token => token.getValue());
232
+ }
233
+ /**
234
+ * 设置图片参数
235
+ * @param key 参数名
236
+ * @param value 参数值
237
+ * @throws `RangeError` 未定义的图片参数
238
+ */
239
+ setValue(key, value = false) {
240
+ if (value === false) {
241
+ this.removeArg(key);
242
+ return;
243
+ }
244
+ const token = this.getArg(key);
245
+ if (token) {
246
+ token.setValue(value);
247
+ return;
248
+ }
249
+ const config = this.getAttribute('config'), syntax = key === 'caption' ? '$1' : Object.entries(config.img).find(([, name]) => name === key)?.[0];
250
+ if (syntax === undefined) {
251
+ throw new RangeError(`Unknown image parameter: ${key}`);
252
+ }
253
+ const free = syntax.includes('$1');
254
+ if (value === true && free) {
255
+ this.typeError('setValue', 'String');
256
+ }
257
+ const parameter = debug_1.Shadow.run(
258
+ // @ts-expect-error abstract class
259
+ () => new imageParameter_1.ImageParameterToken(syntax.replace('$1', ''), this.extension, config));
260
+ if (free) {
261
+ const { childNodes } = index_1.default.parse(value, this.getAttribute('include'), undefined, config);
262
+ parameter.replaceChildren(...childNodes);
263
+ }
264
+ parameter.afterBuild();
265
+ this.insertAt(parameter);
266
+ }
267
+ /**
268
+ * @override
269
+ * @throws `Error` 不适用于图片
270
+ */
271
+ setLinkText() {
272
+ throw new Error('LinkBaseToken.setLinkText method is not applicable to images!');
273
+ }
274
+ }
275
+ exports.FileToken = FileToken;
276
+ constants_1.classes['FileToken'] = __filename;
@@ -0,0 +1,29 @@
1
+ import Parser from '../../index';
2
+ import { Token } from '../index';
3
+ import { FileToken } from './file';
4
+ import type { Title } from '../../lib/title';
5
+ import type { LintError } from '../../base';
6
+ import type { AtomToken, ImageParameterToken } from '../../internal';
7
+ declare type GalleryTypes = 'gallery' | 'imagemap';
8
+ /** 图库图片 */
9
+ export declare abstract class GalleryImageToken extends FileToken {
10
+ get type(): `${GalleryTypes}-image`;
11
+ /** 图片链接 */
12
+ get link(): string | Title;
13
+ set link(value: string);
14
+ /**
15
+ * @param type 图片类型
16
+ * @param link 图片文件名
17
+ * @param text 图片参数
18
+ */
19
+ constructor(type: GalleryTypes, link: string, text?: string, config?: Parser.Config, accum?: Token[]);
20
+ /**
21
+ * @override
22
+ * @param token 待插入的子节点
23
+ * @param i 插入位置
24
+ * @throws `RangeError` 不可插入多余子节点
25
+ * @throws `TypeError` 不可插入文本节点
26
+ */
27
+ insertAt<T extends AtomToken | ImageParameterToken>(child: T, i?: number): T;
28
+ }
29
+ export {};
@@ -0,0 +1,132 @@
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.GalleryImageToken = void 0;
38
+ const lint_1 = require("../../util/lint");
39
+ const constants_1 = require("../../util/constants");
40
+ const singleLine_1 = require("../../mixin/singleLine");
41
+ const index_1 = require("../../index");
42
+ const index_2 = require("../index");
43
+ const file_1 = require("./file");
44
+ const imageParameter_1 = require("../imageParameter");
45
+ /** 图库图片 */
46
+ let GalleryImageToken = (() => {
47
+ let _classDecorators = [singleLine_1.singleLine];
48
+ let _classDescriptor;
49
+ let _classExtraInitializers = [];
50
+ let _classThis;
51
+ let _classSuper = file_1.FileToken;
52
+ var GalleryImageToken = class extends _classSuper {
53
+ static { _classThis = this; }
54
+ static {
55
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
56
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
57
+ GalleryImageToken = _classThis = _classDescriptor.value;
58
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
59
+ __runInitializers(_classThis, _classExtraInitializers);
60
+ }
61
+ /** @private */
62
+ privateType = 'imagemap-image';
63
+ get type() {
64
+ return this.privateType;
65
+ }
66
+ /* NOT FOR BROWSER */
67
+ /** 图片链接 */
68
+ get link() {
69
+ return this.type === 'imagemap-image' ? '' : super.link;
70
+ }
71
+ set link(value) {
72
+ if (this.type !== 'imagemap-image') {
73
+ super.link = value;
74
+ }
75
+ }
76
+ /* NOT FOR BROWSER END */
77
+ /**
78
+ * @param type 图片类型
79
+ * @param link 图片文件名
80
+ * @param text 图片参数
81
+ */
82
+ constructor(type, link, text, config = index_1.default.getConfig(), accum = []) {
83
+ let token;
84
+ if (text !== undefined) {
85
+ const { length } = accum;
86
+ token = new index_2.Token(text, config, accum);
87
+ for (let n = 1; n < constants_1.MAX_STAGE; n++) {
88
+ token.parseOnce();
89
+ }
90
+ accum.splice(length, 1);
91
+ }
92
+ super(link, token?.toString(), config, accum);
93
+ this.setAttribute('bracket', false);
94
+ this.privateType = `${type}-image`;
95
+ this.seal('privateType', true);
96
+ }
97
+ /** @private */
98
+ getTitle() {
99
+ const imagemap = this.type === 'imagemap-image';
100
+ return this.normalizeTitle(this.firstChild.toString(), imagemap ? 0 : 6, true, !imagemap);
101
+ }
102
+ /** @private */
103
+ getAttribute(key) {
104
+ return key === 'padding' ? 0 : super.getAttribute(key);
105
+ }
106
+ /** @private */
107
+ lint(start = this.getAbsoluteIndex(), re) {
108
+ const errors = super.lint(start, re), { ns, interwiki } = this.getAttribute('title');
109
+ if (interwiki || ns !== 6) {
110
+ errors.push((0, lint_1.generateForSelf)(this, { start }, 'invalid-gallery', 'invalid gallery image'));
111
+ }
112
+ return errors;
113
+ }
114
+ /* NOT FOR BROWSER */
115
+ /**
116
+ * @override
117
+ * @param token 待插入的子节点
118
+ * @param i 插入位置
119
+ * @throws `RangeError` 不可插入多余子节点
120
+ * @throws `TypeError` 不可插入文本节点
121
+ */
122
+ insertAt(child, i) {
123
+ if (this.type === 'gallery-image' && child.type === 'image-parameter' && !imageParameter_1.galleryParams.has(child.name)) {
124
+ child.setAttribute('name', 'invalid');
125
+ }
126
+ return super.insertAt(child, i);
127
+ }
128
+ };
129
+ return GalleryImageToken = _classThis;
130
+ })();
131
+ exports.GalleryImageToken = GalleryImageToken;
132
+ constants_1.classes['GalleryImageToken'] = __filename;
@@ -0,0 +1,51 @@
1
+ import { LinkBaseToken } from './base';
2
+ import type { LintError } from '../../base';
3
+ import type { Title } from '../../lib/title';
4
+ import type { Token, AtomToken } from '../../internal';
5
+ /**
6
+ * 内链
7
+ * @classdesc `{childNodes: [AtomToken, ?Token]}`
8
+ */
9
+ export declare abstract class LinkToken extends LinkBaseToken {
10
+ #private;
11
+ readonly childNodes: readonly [AtomToken] | readonly [AtomToken, Token];
12
+ abstract get children(): [AtomToken] | [AtomToken, Token];
13
+ abstract get link(): Title;
14
+ abstract set link(link: string);
15
+ get type(): 'link';
16
+ /** 链接显示文字 */
17
+ get innerText(): string;
18
+ set innerText(text: string);
19
+ /** 是否链接到自身 */
20
+ get selfLink(): boolean;
21
+ set selfLink(selfLink: boolean);
22
+ get fragment(): string | undefined;
23
+ set fragment(fragment: string | undefined);
24
+ /** interwiki */
25
+ get interwiki(): string;
26
+ /** @throws `RangeError` 非法的跨维基前缀 */
27
+ set interwiki(interwiki: string);
28
+ /**
29
+ * 设置跨语言链接
30
+ * @param lang 语言前缀
31
+ * @param link 页面标题
32
+ * @throws `SyntaxError` 仅有fragment
33
+ */
34
+ setLangLink(lang: string, link: string): void;
35
+ /**
36
+ * 设置fragment
37
+ * @param fragment fragment
38
+ */
39
+ setFragment(fragment?: string): void;
40
+ /**
41
+ * 修改为到自身的链接
42
+ * @param fragment fragment
43
+ * @throws `RangeError` 空fragment
44
+ */
45
+ asSelfLink(fragment?: string | undefined): void;
46
+ /**
47
+ * 自动生成管道符后的链接文字
48
+ * @throws `Error` 带有"#"或"%"时不可用
49
+ */
50
+ pipeTrick(): void;
51
+ }
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LinkToken = void 0;
4
+ const lint_1 = require("../../util/lint");
5
+ const constants_1 = require("../../util/constants");
6
+ const base_1 = require("./base");
7
+ /**
8
+ * 内链
9
+ * @classdesc `{childNodes: [AtomToken, ?Token]}`
10
+ */
11
+ class LinkToken extends base_1.LinkBaseToken {
12
+ /* NOT FOR BROWSER END */
13
+ get type() {
14
+ return 'link';
15
+ }
16
+ /* NOT FOR BROWSER */
17
+ /** 链接显示文字 */
18
+ get innerText() {
19
+ return this.length > 1 ? this.lastChild.text() : this.firstChild.text().replace(/^\s*:?/u, '');
20
+ }
21
+ set innerText(text) {
22
+ this.setLinkText(text);
23
+ }
24
+ /** 是否链接到自身 */
25
+ get selfLink() {
26
+ const { link: { title, fragment } } = this;
27
+ return !title && Boolean(fragment);
28
+ }
29
+ set selfLink(selfLink) {
30
+ if (selfLink) {
31
+ this.asSelfLink();
32
+ }
33
+ }
34
+ get fragment() {
35
+ return super.fragment;
36
+ }
37
+ set fragment(fragment) {
38
+ this.#setFragment(fragment);
39
+ }
40
+ /** interwiki */
41
+ get interwiki() {
42
+ return this.link.interwiki;
43
+ }
44
+ /** @throws `RangeError` 非法的跨维基前缀 */
45
+ set interwiki(interwiki) {
46
+ const { link: { prefix, main, fragment } } = this, link = `${interwiki}:${prefix}${main}${fragment === undefined ? '' : `#${fragment}`}`;
47
+ if (interwiki && !this.isInterwiki(link)) {
48
+ throw new RangeError(`${interwiki} is not a valid interwiki prefix!`);
49
+ }
50
+ this.setTarget(link);
51
+ }
52
+ /* NOT FOR BROWSER END */
53
+ /** @private */
54
+ lint(start = this.getAbsoluteIndex(), re) {
55
+ const errors = super.lint(start, re);
56
+ if (this.closest('ext-link-text')) {
57
+ errors.push((0, lint_1.generateForSelf)(this, { start }, 'nested-link', 'internal link in an external link'));
58
+ }
59
+ return errors;
60
+ }
61
+ /* NOT FOR BROWSER */
62
+ /** @private */
63
+ setTarget(link) {
64
+ super.setTarget((/^\s*[:#]/u.test(link) ? '' : ':') + link);
65
+ }
66
+ /**
67
+ * 设置跨语言链接
68
+ * @param lang 语言前缀
69
+ * @param link 页面标题
70
+ * @throws `SyntaxError` 仅有fragment
71
+ */
72
+ setLangLink(lang, link) {
73
+ link = link.trim();
74
+ if (link.startsWith('#')) {
75
+ throw new SyntaxError('An interlanguage link cannot be fragment only!');
76
+ }
77
+ super.setTarget(lang + (link.startsWith(':') ? '' : ':') + link);
78
+ }
79
+ /**
80
+ * 设置fragment
81
+ * @param fragment fragment
82
+ * @param page 是否是其他页面
83
+ */
84
+ #setFragment(fragment, page = true) {
85
+ fragment &&= fragment.replace(/[<>[\]#|=]/gu, p => encodeURIComponent(p));
86
+ this.setTarget(`${page ? this.name : ''}${fragment === undefined ? '' : `#${fragment}`}`);
87
+ }
88
+ /**
89
+ * 设置fragment
90
+ * @param fragment fragment
91
+ */
92
+ setFragment(fragment) {
93
+ this.#setFragment(fragment);
94
+ }
95
+ /**
96
+ * 修改为到自身的链接
97
+ * @param fragment fragment
98
+ * @throws `RangeError` 空fragment
99
+ */
100
+ asSelfLink(fragment = this.fragment) {
101
+ if (!fragment?.trim()) {
102
+ throw new RangeError('LinkToken.asSelfLink method must specify a non-empty fragment!');
103
+ }
104
+ this.#setFragment(fragment, false);
105
+ }
106
+ /**
107
+ * 自动生成管道符后的链接文字
108
+ * @throws `Error` 带有"#"或"%"时不可用
109
+ */
110
+ pipeTrick() {
111
+ const linkText = this.firstChild.text();
112
+ if (linkText.includes('#') || linkText.includes('%')) {
113
+ throw new Error('Pipe trick cannot be used with "#" or "%"!');
114
+ }
115
+ const m1 = /^:?(?:[ \w\x80-\xFF-]+:)?([^(]+)\(.+\)$/u.exec(linkText);
116
+ if (m1) {
117
+ this.setLinkText(m1[1].trim());
118
+ return;
119
+ }
120
+ const m2 = /^:?(?:[ \w\x80-\xFF-]+:)?([^(]+)(.+)$/u.exec(linkText);
121
+ if (m2) {
122
+ this.setLinkText(m2[1].trim());
123
+ return;
124
+ }
125
+ // eslint-disable-next-line es-x/no-regexp-lookbehind-assertions
126
+ const m3 = /^:?(?:[ \w\x80-\xFF-]+:)?(.+?)(?:(?<!\()\(.+\))?(?:, |,|، )./u
127
+ .exec(linkText);
128
+ if (m3) {
129
+ this.setLinkText(m3[1].trim());
130
+ return;
131
+ }
132
+ this.setLinkText(linkText);
133
+ }
134
+ }
135
+ exports.LinkToken = LinkToken;
136
+ constants_1.classes['LinkToken'] = __filename;
@@ -0,0 +1,36 @@
1
+ import Parser from '../../index';
2
+ import { LinkBaseToken } from './base';
3
+ import { NoincludeToken } from '../nowiki/noinclude';
4
+ import type { LintError } from '../../base';
5
+ import type { Title } from '../../lib/title';
6
+ import type { Token, AtomToken } from '../../internal';
7
+ /**
8
+ * 重定向目标
9
+ * @classdesc `{childNodes: [AtomToken, ?Token]}`
10
+ */
11
+ export declare abstract class RedirectTargetToken extends LinkBaseToken {
12
+ readonly childNodes: readonly [AtomToken] | readonly [AtomToken, NoincludeToken];
13
+ abstract get lastChild(): AtomToken | NoincludeToken;
14
+ abstract get children(): [AtomToken] | [AtomToken, NoincludeToken];
15
+ abstract get lastElementChild(): AtomToken | NoincludeToken;
16
+ abstract get link(): Title;
17
+ abstract set link(link: string);
18
+ get type(): 'redirect-target';
19
+ get fragment(): string | undefined;
20
+ set fragment(fragment: string | undefined);
21
+ /** interwiki */
22
+ get interwiki(): string;
23
+ /** @throws `RangeError` 非法的跨维基前缀 */
24
+ set interwiki(interwiki: string);
25
+ /**
26
+ * @param link 链接标题
27
+ * @param linkText 链接显示文字
28
+ * @param delimiter `|`
29
+ */
30
+ constructor(link: string, linkText?: string, config?: Parser.Config, accum?: Token[]);
31
+ /**
32
+ * 设置fragment
33
+ * @param fragment fragment
34
+ */
35
+ setFragment(fragment?: string): void;
36
+ }