wikiparser-node 1.21.1 → 1.21.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.
- package/README.md +12 -6
- package/bundle/bundle-es8.min.js +25 -25
- package/bundle/bundle-lsp.min.js +26 -26
- package/bundle/bundle.min.js +25 -25
- package/coverage/badge.svg +1 -1
- package/dist/addon/table.js +5 -5
- package/dist/addon/token.js +116 -7
- package/dist/base.d.mts +6 -1
- package/dist/base.d.ts +6 -1
- package/dist/bin/config.js +3 -3
- package/dist/index.d.ts +9 -2
- package/dist/index.js +10 -1
- package/dist/lib/element.d.ts +1 -0
- package/dist/lib/element.js +3 -1
- package/dist/lib/lintConfig.d.ts +13 -0
- package/dist/lib/lintConfig.js +161 -0
- package/dist/lib/lsp.d.ts +2 -0
- package/dist/lib/lsp.js +11 -8
- package/dist/lib/node.d.ts +20 -3
- package/dist/lib/node.js +647 -585
- package/dist/lib/text.d.ts +2 -0
- package/dist/lib/text.js +21 -12
- package/dist/lib/title.d.ts +3 -1
- package/dist/lib/title.js +3 -1
- package/dist/mixin/attributesParent.d.ts +6 -6
- package/dist/mixin/attributesParent.js +4 -4
- package/dist/mixin/cached.d.ts +5 -0
- package/dist/mixin/cached.js +22 -0
- package/dist/mixin/clone.d.ts +5 -0
- package/dist/mixin/clone.js +23 -0
- package/dist/mixin/hidden.js +68 -18
- package/dist/mixin/sol.js +2 -2
- package/dist/parser/commentAndExt.js +1 -1
- package/dist/parser/html.js +3 -3
- package/dist/parser/list.js +6 -3
- package/dist/parser/table.js +4 -4
- package/dist/src/arg.js +14 -8
- package/dist/src/atom.js +76 -31
- package/dist/src/attribute.d.ts +1 -0
- package/dist/src/attribute.js +51 -20
- package/dist/src/attributes.d.ts +7 -7
- package/dist/src/attributes.js +415 -366
- package/dist/src/commented.js +81 -35
- package/dist/src/converter.js +14 -8
- package/dist/src/converterFlags.js +33 -22
- package/dist/src/converterRule.js +263 -216
- package/dist/src/extLink.js +23 -18
- package/dist/src/gallery.d.ts +12 -2
- package/dist/src/gallery.js +30 -10
- package/dist/src/heading.d.ts +6 -1
- package/dist/src/heading.js +73 -59
- package/dist/src/hidden.js +14 -9
- package/dist/src/html.js +29 -10
- package/dist/src/imageParameter.d.ts +1 -0
- package/dist/src/imageParameter.js +15 -7
- package/dist/src/imagemap.js +35 -28
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.js +66 -49
- package/dist/src/link/base.js +17 -12
- package/dist/src/link/file.d.ts +9 -1
- package/dist/src/link/file.js +401 -346
- package/dist/src/link/galleryImage.js +12 -6
- package/dist/src/link/index.js +7 -3
- package/dist/src/link/redirectTarget.d.ts +6 -1
- package/dist/src/link/redirectTarget.js +14 -5
- package/dist/src/magicLink.d.ts +6 -1
- package/dist/src/magicLink.js +30 -16
- package/dist/src/nested.js +122 -74
- package/dist/src/nowiki/base.js +5 -2
- package/dist/src/nowiki/comment.js +6 -2
- package/dist/src/nowiki/index.js +4 -4
- package/dist/src/nowiki/listBase.d.ts +6 -1
- package/dist/src/nowiki/listBase.js +7 -2
- package/dist/src/nowiki/quote.d.ts +6 -1
- package/dist/src/nowiki/quote.js +22 -10
- package/dist/src/onlyinclude.js +17 -9
- package/dist/src/paramTag/index.js +21 -14
- package/dist/src/parameter.js +26 -20
- package/dist/src/pre.js +91 -45
- package/dist/src/redirect.js +1 -1
- package/dist/src/syntax.js +14 -10
- package/dist/src/table/index.js +550 -502
- package/dist/src/table/td.js +66 -59
- package/dist/src/table/trBase.js +179 -129
- package/dist/src/tagPair/ext.js +32 -20
- package/dist/src/tagPair/include.js +5 -5
- package/dist/src/tagPair/translate.js +150 -103
- package/dist/src/transclude.d.ts +21 -8
- package/dist/src/transclude.js +56 -34
- package/dist/util/html.js +45 -43
- package/dist/util/lint.js +10 -7
- package/dist/util/string.js +13 -7
- package/extensions/dist/base.js +2 -2
- package/i18n/zh-hans.json +1 -1
- package/i18n/zh-hant.json +1 -1
- package/package.json +15 -15
package/dist/src/link/file.js
CHANGED
|
@@ -1,4 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
3
|
+
var useValue = arguments.length > 2;
|
|
4
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
5
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
6
|
+
}
|
|
7
|
+
return useValue ? value : void 0;
|
|
8
|
+
};
|
|
9
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
10
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
11
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
12
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
13
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
14
|
+
var _, done = false;
|
|
15
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
16
|
+
var context = {};
|
|
17
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
18
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
19
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
20
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
21
|
+
if (kind === "accessor") {
|
|
22
|
+
if (result === void 0) continue;
|
|
23
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
24
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
25
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
26
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
27
|
+
}
|
|
28
|
+
else if (_ = accept(result)) {
|
|
29
|
+
if (kind === "field") initializers.unshift(_);
|
|
30
|
+
else descriptor[key] = _;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
34
|
+
done = true;
|
|
35
|
+
};
|
|
2
36
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
37
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
38
|
};
|
|
@@ -14,6 +48,7 @@ const string_1 = require("../../util/string");
|
|
|
14
48
|
const debug_1 = require("../../util/debug");
|
|
15
49
|
const constants_1 = require("../../util/constants");
|
|
16
50
|
const title_1 = require("../../lib/title");
|
|
51
|
+
const cached_1 = require("../../mixin/cached");
|
|
17
52
|
const frame = new Map([
|
|
18
53
|
['manualthumb', 'Thumb'],
|
|
19
54
|
['frameless', 'Frameless'],
|
|
@@ -59,373 +94,393 @@ const filterArgs = (args, types) => args.filter(({ childNodes }) => {
|
|
|
59
94
|
* 图片
|
|
60
95
|
* @classdesc `{childNodes: [AtomToken, ...ImageParameterToken[]]}`
|
|
61
96
|
*/
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
/** image link / 图片链接 */
|
|
73
|
-
get link() {
|
|
74
|
-
return this.getArg('link')?.link ?? super.link;
|
|
75
|
-
}
|
|
76
|
-
set link(value) {
|
|
77
|
-
this.setValue('link', value);
|
|
78
|
-
}
|
|
79
|
-
/** image size / 图片大小 */
|
|
80
|
-
get size() {
|
|
81
|
-
const fr = this.getFrame();
|
|
82
|
-
return fr === 'framed' || fr instanceof title_1.Title ? undefined : this.getArg('width')?.size;
|
|
83
|
-
}
|
|
84
|
-
set size(size) {
|
|
85
|
-
this.setValue('width', size && size.width + (size.height && 'x') + size.height);
|
|
86
|
-
}
|
|
87
|
-
/** image width / 图片宽度 */
|
|
88
|
-
get width() {
|
|
89
|
-
return this.type === 'gallery-image'
|
|
90
|
-
? this.parentNode?.widths.toString()
|
|
91
|
-
: this.size?.width;
|
|
92
|
-
}
|
|
93
|
-
set width(width) {
|
|
94
|
-
const arg = this.getArg('width');
|
|
95
|
-
if (arg) {
|
|
96
|
-
arg.width = width;
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
this.setValue('width', width);
|
|
97
|
+
let FileToken = (() => {
|
|
98
|
+
let _classSuper = base_1.LinkBaseToken;
|
|
99
|
+
let _instanceExtraInitializers = [];
|
|
100
|
+
let _toHtmlInternal_decorators;
|
|
101
|
+
return class FileToken extends _classSuper {
|
|
102
|
+
static {
|
|
103
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
104
|
+
_toHtmlInternal_decorators = [(0, cached_1.cached)()];
|
|
105
|
+
__esDecorate(this, null, _toHtmlInternal_decorators, { kind: "method", name: "toHtmlInternal", static: false, private: false, access: { has: obj => "toHtmlInternal" in obj, get: obj => obj.toHtmlInternal }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
106
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
100
107
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
return this.type === 'gallery-image'
|
|
105
|
-
? this.parentNode?.heights.toString()
|
|
106
|
-
: this.size?.height;
|
|
107
|
-
}
|
|
108
|
-
set height(height) {
|
|
109
|
-
const arg = this.getArg('width');
|
|
110
|
-
if (arg) {
|
|
111
|
-
arg.height = height;
|
|
108
|
+
/* NOT FOR BROWSER END */
|
|
109
|
+
get type() {
|
|
110
|
+
return 'file';
|
|
112
111
|
}
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
/**
|
|
113
|
+
* file extension
|
|
114
|
+
*
|
|
115
|
+
* 扩展名
|
|
116
|
+
* @since v1.5.3
|
|
117
|
+
*/
|
|
118
|
+
get extension() {
|
|
119
|
+
return this.getAttribute('title').extension;
|
|
115
120
|
}
|
|
116
|
-
}
|
|
117
|
-
/* NOT FOR BROWSER END */
|
|
118
|
-
/**
|
|
119
|
-
* @param link 文件名
|
|
120
|
-
* @param text 图片参数
|
|
121
|
-
* @param delimiter `|`
|
|
122
|
-
*/
|
|
123
|
-
constructor(link, text, config, accum = [], delimiter = '|') {
|
|
124
|
-
super(link, undefined, config, accum, delimiter);
|
|
125
121
|
/* NOT FOR BROWSER */
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
122
|
+
/** image link / 图片链接 */
|
|
123
|
+
get link() {
|
|
124
|
+
return this.getArg('link')?.link ?? super.link;
|
|
125
|
+
}
|
|
126
|
+
set link(value) {
|
|
127
|
+
this.setValue('link', value);
|
|
128
|
+
}
|
|
129
|
+
/** image size / 图片大小 */
|
|
130
|
+
get size() {
|
|
131
|
+
const fr = this.getFrame();
|
|
132
|
+
return fr === 'framed' || fr instanceof title_1.Title ? undefined : this.getArg('width')?.size;
|
|
133
|
+
}
|
|
134
|
+
set size(size) {
|
|
135
|
+
this.setValue('width', size && size.width + (size.height && 'x') + size.height);
|
|
136
|
+
}
|
|
137
|
+
/** image width / 图片宽度 */
|
|
138
|
+
get width() {
|
|
139
|
+
return this.is('gallery-image')
|
|
140
|
+
? this.parentNode?.widths.toString()
|
|
141
|
+
: this.size?.width;
|
|
142
|
+
}
|
|
143
|
+
set width(width) {
|
|
144
|
+
const arg = this.getArg('width');
|
|
145
|
+
if (arg) {
|
|
146
|
+
arg.width = width;
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
this.setValue('width', width);
|
|
146
150
|
}
|
|
147
151
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
152
|
+
/** image height / 图片高度 */
|
|
153
|
+
get height() {
|
|
154
|
+
return this.is('gallery-image')
|
|
155
|
+
? this.parentNode?.heights.toString()
|
|
156
|
+
: this.size?.height;
|
|
153
157
|
}
|
|
158
|
+
set height(height) {
|
|
159
|
+
const arg = this.getArg('width');
|
|
160
|
+
if (arg) {
|
|
161
|
+
arg.height = height;
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
this.setValue('width', height && `x${height}`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/* NOT FOR BROWSER END */
|
|
154
168
|
/**
|
|
155
|
-
*
|
|
156
|
-
* @param
|
|
157
|
-
* @param
|
|
158
|
-
* @param severity 错误等级
|
|
169
|
+
* @param link 文件名
|
|
170
|
+
* @param text 图片参数
|
|
171
|
+
* @param delimiter `|`
|
|
159
172
|
*/
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
173
|
+
constructor(link, text, config, accum = [], delimiter = '|') {
|
|
174
|
+
super(link, undefined, config, accum, delimiter);
|
|
175
|
+
__runInitializers(this, _instanceExtraInitializers);
|
|
176
|
+
/* NOT FOR BROWSER */
|
|
177
|
+
this.setAttribute('acceptable', { AtomToken: 0, ImageParameterToken: '1:' });
|
|
178
|
+
/* NOT FOR BROWSER END */
|
|
179
|
+
const { extension } = this.getTitle(true, true);
|
|
180
|
+
/-\{|\}-|\|/gu; // eslint-disable-line @typescript-eslint/no-unused-expressions
|
|
181
|
+
this.safeAppend(explode(text).map(
|
|
182
|
+
// @ts-expect-error abstract class
|
|
183
|
+
(part) => new imageParameter_1.ImageParameterToken(part, extension, config, accum)));
|
|
184
|
+
}
|
|
185
|
+
/** @private */
|
|
186
|
+
lint(start = this.getAbsoluteIndex(), re) {
|
|
187
|
+
const errors = super.lint(start, re), args = filterArgs(this.getAllArgs(), argTypes), keys = [...new Set(args.map(({ name }) => name))], frameKeys = keys.filter(key => frame.has(key)), horizAlignKeys = keys.filter(key => horizAlign.has(key)), vertAlignKeys = keys.filter(key => vertAlign.has(key)), [fr] = frameKeys, unscaled = fr === 'framed' || fr === 'manualthumb', rect = new rect_1.BoundingRect(this, start);
|
|
188
|
+
if (this.closest('ext-link-text')
|
|
189
|
+
&& this.getValue('link')?.trim() !== '') {
|
|
190
|
+
errors.push((0, lint_1.generateForSelf)(this, rect, 'nested-link', 'internal link in an external link'));
|
|
191
|
+
}
|
|
192
|
+
if (unscaled) {
|
|
193
|
+
for (const arg of args.filter(({ name }) => name === 'width')) {
|
|
194
|
+
const e = (0, lint_1.generateForChild)(arg, rect, 'invalid-gallery', 'invalid image parameter');
|
|
195
|
+
e.fix = { desc: 'remove', range: [e.startIndex - 1, e.endIndex], text: '' };
|
|
196
|
+
errors.push(e);
|
|
197
|
+
}
|
|
169
198
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
...relevantArgs.slice(-1),
|
|
176
|
-
];
|
|
199
|
+
if (args.length === keys.length
|
|
200
|
+
&& frameKeys.length < 2
|
|
201
|
+
&& horizAlignKeys.length < 2
|
|
202
|
+
&& vertAlignKeys.length < 2) {
|
|
203
|
+
return errors;
|
|
177
204
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
205
|
+
/**
|
|
206
|
+
* 图片参数到语法错误的映射
|
|
207
|
+
* @param msg 消息键
|
|
208
|
+
* @param p1 替换$1
|
|
209
|
+
* @param severity 错误等级
|
|
210
|
+
*/
|
|
211
|
+
const generate = (msg, p1, severity = true) => (arg) => {
|
|
212
|
+
const isError = typeof severity === 'function' ? severity(arg) : severity, e = (0, lint_1.generateForChild)(arg, rect, 'no-duplicate', index_1.default.msg(`${msg} image $1 parameter`, p1), isError ? 'error' : 'warning');
|
|
213
|
+
e.suggestions = [{ desc: 'remove', range: [e.startIndex - 1, e.endIndex], text: '' }];
|
|
214
|
+
return e;
|
|
215
|
+
};
|
|
216
|
+
const { extension } = this;
|
|
217
|
+
for (const key of keys) {
|
|
218
|
+
if (key === 'invalid' || key === 'width' && unscaled) {
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
const isCaption = key === 'caption';
|
|
222
|
+
let relevantArgs = args.filter(({ name }) => name === key);
|
|
223
|
+
if (isCaption) {
|
|
224
|
+
relevantArgs = [
|
|
225
|
+
...relevantArgs.slice(0, -1).filter(arg => arg.text()),
|
|
226
|
+
...relevantArgs.slice(-1),
|
|
227
|
+
];
|
|
228
|
+
}
|
|
229
|
+
if (relevantArgs.length > 1) {
|
|
230
|
+
let severity = !isCaption || !extension || extensions.has(extension);
|
|
231
|
+
if (isCaption && severity) {
|
|
232
|
+
const plainArgs = filterArgs(relevantArgs, transclusion);
|
|
233
|
+
severity = plainArgs.length > 1 && ((arg) => plainArgs.includes(arg));
|
|
234
|
+
}
|
|
235
|
+
errors.push(...relevantArgs.map(generate('duplicated', key, severity)));
|
|
183
236
|
}
|
|
184
|
-
errors.push(...relevantArgs.map(generate('duplicated', key, severity)));
|
|
185
237
|
}
|
|
238
|
+
if (frameKeys.length > 1) {
|
|
239
|
+
errors.push(...args.filter(({ name }) => frame.has(name)).map(generate('conflicting', 'frame')));
|
|
240
|
+
}
|
|
241
|
+
if (horizAlignKeys.length > 1) {
|
|
242
|
+
errors.push(...args.filter(({ name }) => horizAlign.has(name))
|
|
243
|
+
.map(generate('conflicting', 'horizontal-alignment')));
|
|
244
|
+
}
|
|
245
|
+
if (vertAlignKeys.length > 1) {
|
|
246
|
+
errors.push(...args.filter(({ name }) => vertAlign.has(name))
|
|
247
|
+
.map(generate('conflicting', 'vertical-alignment')));
|
|
248
|
+
}
|
|
249
|
+
return errors;
|
|
186
250
|
}
|
|
187
|
-
|
|
188
|
-
|
|
251
|
+
/**
|
|
252
|
+
* Get all image parameter tokens
|
|
253
|
+
*
|
|
254
|
+
* 获取所有图片参数节点
|
|
255
|
+
*/
|
|
256
|
+
getAllArgs() {
|
|
257
|
+
return this.childNodes.slice(1);
|
|
189
258
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
259
|
+
/**
|
|
260
|
+
* Get image parameters with the specified name
|
|
261
|
+
*
|
|
262
|
+
* 获取指定图片参数
|
|
263
|
+
* @param key parameter name / 参数名
|
|
264
|
+
*/
|
|
265
|
+
getArgs(key) {
|
|
266
|
+
return this.getAllArgs().filter(({ name }) => key === name);
|
|
193
267
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
268
|
+
/**
|
|
269
|
+
* Get the effective image parameter with the specified name
|
|
270
|
+
*
|
|
271
|
+
* 获取生效的指定图片参数
|
|
272
|
+
* @param key parameter name / 参数名
|
|
273
|
+
*/
|
|
274
|
+
getArg(key) {
|
|
275
|
+
const args = this.getArgs(key);
|
|
276
|
+
return args[key === 'manualthumb' ? 0 : args.length - 1];
|
|
197
277
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
return this.childNodes.slice(1);
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Get image parameters with the specified name
|
|
210
|
-
*
|
|
211
|
-
* 获取指定图片参数
|
|
212
|
-
* @param key parameter name / 参数名
|
|
213
|
-
*/
|
|
214
|
-
getArgs(key) {
|
|
215
|
-
return this.getAllArgs().filter(({ name }) => key === name);
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Get the effective image parameter with the specified name
|
|
219
|
-
*
|
|
220
|
-
* 获取生效的指定图片参数
|
|
221
|
-
* @param key parameter name / 参数名
|
|
222
|
-
*/
|
|
223
|
-
getArg(key) {
|
|
224
|
-
const args = this.getArgs(key);
|
|
225
|
-
return args[key === 'manualthumb' ? 0 : args.length - 1];
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Get the effective image parameter value
|
|
229
|
-
*
|
|
230
|
-
* 获取生效的指定图片参数值
|
|
231
|
-
* @param key parameter name / 参数名
|
|
232
|
-
*/
|
|
233
|
-
getValue(key) {
|
|
234
|
-
return this.getArg(key)?.getValue();
|
|
235
|
-
}
|
|
236
|
-
/** @private */
|
|
237
|
-
json(_, start = this.getAbsoluteIndex()) {
|
|
238
|
-
const json = super.json(undefined, start), { extension } = this;
|
|
239
|
-
if (extension) {
|
|
240
|
-
json['extension'] = extension;
|
|
278
|
+
/**
|
|
279
|
+
* Get the effective image parameter value
|
|
280
|
+
*
|
|
281
|
+
* 获取生效的指定图片参数值
|
|
282
|
+
* @param key parameter name / 参数名
|
|
283
|
+
*/
|
|
284
|
+
getValue(key) {
|
|
285
|
+
return this.getArg(key)?.getValue();
|
|
241
286
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
*/
|
|
250
|
-
#getTypedArgs(keys, type) {
|
|
251
|
-
const args = this.getAllArgs().filter(({ name }) => keys.has(name));
|
|
252
|
-
if (args.length > 1) {
|
|
253
|
-
index_1.default.warn(`The image ${this.name} has ${args.length} ${type} parameters. Only the last ${args[0].name} will take effect!`);
|
|
254
|
-
}
|
|
255
|
-
return args;
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* Get image frame parameter tokens
|
|
259
|
-
*
|
|
260
|
-
* 获取图片框架属性参数节点
|
|
261
|
-
*/
|
|
262
|
-
getFrameArgs() {
|
|
263
|
-
return this.#getTypedArgs(frame, 'frame');
|
|
264
|
-
}
|
|
265
|
-
/**
|
|
266
|
-
* Get image horizontal alignment parameter tokens
|
|
267
|
-
*
|
|
268
|
-
* 获取图片水平对齐参数节点
|
|
269
|
-
*/
|
|
270
|
-
getHorizAlignArgs() {
|
|
271
|
-
return this.#getTypedArgs(horizAlign, 'horizontal-align');
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Get image vertical alignment parameter tokens
|
|
275
|
-
*
|
|
276
|
-
* 获取图片垂直对齐参数节点
|
|
277
|
-
*/
|
|
278
|
-
getVertAlignArgs() {
|
|
279
|
-
return this.#getTypedArgs(vertAlign, 'vertical-align');
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* Get the effective image frame paremter value
|
|
283
|
-
*
|
|
284
|
-
* 获取生效的图片框架属性参数
|
|
285
|
-
*/
|
|
286
|
-
getFrame() {
|
|
287
|
-
const [arg] = this.getFrameArgs(), val = arg?.name;
|
|
288
|
-
return val === 'manualthumb' ? this.normalizeTitle(arg.getValue(), 6) : val;
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* Get the effective image horizontal alignment parameter value
|
|
292
|
-
*
|
|
293
|
-
* 获取生效的图片水平对齐参数
|
|
294
|
-
*/
|
|
295
|
-
getHorizAlign() {
|
|
296
|
-
return this.getHorizAlignArgs()[0]?.name;
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* Get the effective image vertical alignment parameter value
|
|
300
|
-
*
|
|
301
|
-
* 获取生效的图片垂直对齐参数
|
|
302
|
-
*/
|
|
303
|
-
getVertAlign() {
|
|
304
|
-
return this.getVertAlignArgs()[0]?.name;
|
|
305
|
-
}
|
|
306
|
-
/**
|
|
307
|
-
* Check if the image contains the specified parameter
|
|
308
|
-
*
|
|
309
|
-
* 是否具有指定图片参数
|
|
310
|
-
* @param key parameter name / 参数名
|
|
311
|
-
*/
|
|
312
|
-
hasArg(key) {
|
|
313
|
-
return this.getArgs(key).length > 0;
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* Remove the specified image parameter
|
|
317
|
-
*
|
|
318
|
-
* 移除指定图片参数
|
|
319
|
-
* @param key parameter name / 参数名
|
|
320
|
-
*/
|
|
321
|
-
removeArg(key) {
|
|
322
|
-
for (const token of this.getArgs(key)) {
|
|
323
|
-
this.removeChild(token);
|
|
287
|
+
/** @private */
|
|
288
|
+
json(_, start = this.getAbsoluteIndex()) {
|
|
289
|
+
const json = super.json(undefined, start), { extension } = this;
|
|
290
|
+
if (extension) {
|
|
291
|
+
json['extension'] = extension;
|
|
292
|
+
}
|
|
293
|
+
return json;
|
|
324
294
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
this.
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
295
|
+
/* NOT FOR BROWSER */
|
|
296
|
+
/**
|
|
297
|
+
* 获取特定类型的图片属性参数节点
|
|
298
|
+
* @param keys 接受的参数名
|
|
299
|
+
* @param type 类型名
|
|
300
|
+
*/
|
|
301
|
+
#getTypedArgs(keys, type) {
|
|
302
|
+
const args = this.getAllArgs().filter(({ name }) => keys.has(name));
|
|
303
|
+
if (args.length > 1) {
|
|
304
|
+
index_1.default.warn(`The image ${this.name} has ${args.length} ${type} parameters. Only the last ${args[0].name} will take effect!`);
|
|
305
|
+
}
|
|
306
|
+
return args;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Get image frame parameter tokens
|
|
310
|
+
*
|
|
311
|
+
* 获取图片框架属性参数节点
|
|
312
|
+
*/
|
|
313
|
+
getFrameArgs() {
|
|
314
|
+
return this.#getTypedArgs(frame, 'frame');
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Get image horizontal alignment parameter tokens
|
|
318
|
+
*
|
|
319
|
+
* 获取图片水平对齐参数节点
|
|
320
|
+
*/
|
|
321
|
+
getHorizAlignArgs() {
|
|
322
|
+
return this.#getTypedArgs(horizAlign, 'horizontal-align');
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Get image vertical alignment parameter tokens
|
|
326
|
+
*
|
|
327
|
+
* 获取图片垂直对齐参数节点
|
|
328
|
+
*/
|
|
329
|
+
getVertAlignArgs() {
|
|
330
|
+
return this.#getTypedArgs(vertAlign, 'vertical-align');
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Get the effective image frame paremter value
|
|
334
|
+
*
|
|
335
|
+
* 获取生效的图片框架属性参数
|
|
336
|
+
* @since v1.11.0
|
|
337
|
+
*/
|
|
338
|
+
getFrame() {
|
|
339
|
+
const [arg] = this.getFrameArgs(), val = arg?.name;
|
|
340
|
+
return val === 'manualthumb' ? this.normalizeTitle(arg.getValue(), 6) : val;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Get the effective image horizontal alignment parameter value
|
|
344
|
+
*
|
|
345
|
+
* 获取生效的图片水平对齐参数
|
|
346
|
+
* @since v1.11.0
|
|
347
|
+
*/
|
|
348
|
+
getHorizAlign() {
|
|
349
|
+
return this.getHorizAlignArgs()[0]?.name;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Get the effective image vertical alignment parameter value
|
|
353
|
+
*
|
|
354
|
+
* 获取生效的图片垂直对齐参数
|
|
355
|
+
* @since v1.11.0
|
|
356
|
+
*/
|
|
357
|
+
getVertAlign() {
|
|
358
|
+
return this.getVertAlignArgs()[0]?.name;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Check if the image contains the specified parameter
|
|
362
|
+
*
|
|
363
|
+
* 是否具有指定图片参数
|
|
364
|
+
* @param key parameter name / 参数名
|
|
365
|
+
*/
|
|
366
|
+
hasArg(key) {
|
|
367
|
+
return this.getArgs(key).length > 0;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Remove the specified image parameter
|
|
371
|
+
*
|
|
372
|
+
* 移除指定图片参数
|
|
373
|
+
* @param key parameter name / 参数名
|
|
374
|
+
*/
|
|
375
|
+
removeArg(key) {
|
|
376
|
+
for (const token of this.getArgs(key)) {
|
|
377
|
+
this.removeChild(token);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Get all image parameter names
|
|
382
|
+
*
|
|
383
|
+
* 获取图片参数名
|
|
384
|
+
*/
|
|
385
|
+
getKeys() {
|
|
386
|
+
return new Set(this.getAllArgs().map(({ name }) => name));
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Get the image parameter values with the specified name
|
|
390
|
+
*
|
|
391
|
+
* 获取指定的图片参数值
|
|
392
|
+
* @param key parameter name / 参数名
|
|
393
|
+
*/
|
|
394
|
+
getValues(key) {
|
|
395
|
+
return this.getArgs(key).map(token => token.getValue());
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Set the image parameter
|
|
399
|
+
*
|
|
400
|
+
* 设置图片参数
|
|
401
|
+
* @param key parameter name / 参数名
|
|
402
|
+
* @param value parameter value / 参数值
|
|
403
|
+
* @throws `RangeError` 未定义的图片参数
|
|
404
|
+
*/
|
|
405
|
+
setValue(key, value = false) {
|
|
406
|
+
if (value === false) {
|
|
407
|
+
this.removeArg(key);
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
const token = this.getArg(key);
|
|
411
|
+
if (token) {
|
|
412
|
+
token.setValue(value);
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
const config = this.getAttribute('config'), syntax = key === 'caption' ? '$1' : Object.entries(config.img).find(([, name]) => name === key)?.[0];
|
|
416
|
+
/* istanbul ignore if */
|
|
417
|
+
if (syntax === undefined) {
|
|
418
|
+
throw new RangeError(`Unknown image parameter: ${key}`);
|
|
419
|
+
}
|
|
420
|
+
const free = syntax.includes('$1');
|
|
421
|
+
/* istanbul ignore if */
|
|
422
|
+
if (value === true && free) {
|
|
423
|
+
this.typeError('setValue', 'String');
|
|
424
|
+
}
|
|
425
|
+
const parameter = debug_1.Shadow.run(() =>
|
|
426
|
+
// @ts-expect-error abstract class
|
|
427
|
+
new imageParameter_1.ImageParameterToken(syntax.replace('$1', key === 'width' ? '1' : ''), this.extension, config));
|
|
428
|
+
if (free) {
|
|
429
|
+
const { childNodes } = index_1.default
|
|
430
|
+
.parse(value, this.getAttribute('include'), undefined, config);
|
|
431
|
+
parameter.safeReplaceChildren(childNodes);
|
|
432
|
+
}
|
|
433
|
+
this.insertAt(parameter);
|
|
434
|
+
}
|
|
435
|
+
/* istanbul ignore next */
|
|
436
|
+
/**
|
|
437
|
+
* @override
|
|
438
|
+
* @throws `Error` 不适用于图片
|
|
439
|
+
*/
|
|
440
|
+
setLinkText() {
|
|
441
|
+
throw new Error('LinkBaseToken.setLinkText method is not applicable to images!');
|
|
442
|
+
}
|
|
443
|
+
/** @private */
|
|
444
|
+
toHtmlInternal(opt) {
|
|
445
|
+
/** @ignore */
|
|
446
|
+
const isInteger = (n) => Boolean(n && !/\D/u.test(n));
|
|
447
|
+
const { link, width, height, type } = this, file = this.getAttribute('title'), fr = this.getFrame(), manual = fr instanceof title_1.Title, visibleCaption = manual || fr === 'thumbnail' || fr === 'framed' || type === 'gallery-image', caption = this.getArg('caption')?.toHtmlInternal({
|
|
448
|
+
...opt,
|
|
449
|
+
nowrap: true,
|
|
450
|
+
}) ?? '', titleFromCaption = visibleCaption && type !== 'gallery-image' ? '' : (0, string_1.sanitizeAlt)(caption), hasLink = manual || link !== file, title = titleFromCaption || (hasLink && typeof link !== 'string' ? link.getTitleAttr() : ''), titleAttr = title && ` title="${title}"`, alt = (0, string_1.sanitizeAlt)(this.getArg('alt')?.toHtmlInternal({
|
|
451
|
+
...opt,
|
|
452
|
+
nowrap: true,
|
|
453
|
+
})) ?? titleFromCaption, horiz = this.getHorizAlign() ?? '', vert = this.getVertAlign() ?? '', className = `${horiz ? `mw-halign-${horiz}` : vert && `mw-valign-${vert}`}${this.getValue('border') ? ' mw-image-border' : ''} ${(0, string_1.sanitizeAlt)(this.getValue('class')) ?? ''}`.trim(), classAttr = className && ` class="${className}"`, img = `<img${alt && ` alt="${alt}"`} src="${(manual ? fr : file).getUrl()}" decoding="async" class="mw-file-element"${isInteger(width) ? ` width="${width}"` : ''}${isInteger(height) ? ` height="${height}"` : ''}>`;
|
|
454
|
+
let href = '';
|
|
455
|
+
if (link) {
|
|
456
|
+
try {
|
|
457
|
+
href = typeof link === 'string' ? this.getArg('link').getUrl() : link.getUrl();
|
|
458
|
+
if (link === file) {
|
|
459
|
+
const lang = this.getValue('lang'), page = this.getValue('page');
|
|
460
|
+
if (lang) {
|
|
461
|
+
href += `?lang=${lang}`;
|
|
462
|
+
}
|
|
463
|
+
else if (page) {
|
|
464
|
+
href += `?page=${page}`;
|
|
465
|
+
}
|
|
411
466
|
}
|
|
412
467
|
}
|
|
468
|
+
catch { }
|
|
413
469
|
}
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
}
|
|
470
|
+
const a = link
|
|
471
|
+
? `<a${href && ` href="${href}"`}${hasLink ? '' : ' class="mw-file-description"'}${titleAttr}${typeof link === 'string' ? ' rel="nofollow"' : ''}>${img}</a>`
|
|
472
|
+
: `<span${titleAttr}>${img}</span>`;
|
|
473
|
+
if (type !== 'gallery-image') {
|
|
474
|
+
return horiz || vert || visibleCaption
|
|
475
|
+
? `<figure${classAttr} typeof="mw:File${fr ? `/${manual ? 'Thumb' : frame.get(fr)}` : ''}">${a}<figcaption>${caption}</figcaption></figure>`
|
|
476
|
+
: `<span${classAttr}>${a}</span>`;
|
|
477
|
+
}
|
|
478
|
+
const parent = this.parentNode, mode = parent?.parentNode?.getAttr('mode'), nolines = typeof mode === 'string' && mode.toLowerCase() === 'nolines', padding = nolines ? 0 : 30;
|
|
479
|
+
return `\t<li class="gallerybox" style="width: ${Number(width) + padding + 5}px">\n\t\t<div class="thumb" style="width: ${Number(width) + padding}px${nolines ? '' : `; height: ${Number(height) + padding}px`}"><span>${a}</span></div>\n\t\t<div class="gallerytext">${parent?.parentNode?.hasAttr('showfilename')
|
|
480
|
+
? `<a href="${file.getUrl()}" class="galleryfilename galleryfilename-truncate" title="${file.title}">${file.main}</a>\n`
|
|
481
|
+
: ''}${caption}</div>\n\t</li>`;
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
})();
|
|
430
485
|
exports.FileToken = FileToken;
|
|
431
486
|
constants_1.classes['FileToken'] = __filename;
|