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.
Files changed (96) hide show
  1. package/README.md +12 -6
  2. package/bundle/bundle-es8.min.js +25 -25
  3. package/bundle/bundle-lsp.min.js +26 -26
  4. package/bundle/bundle.min.js +25 -25
  5. package/coverage/badge.svg +1 -1
  6. package/dist/addon/table.js +5 -5
  7. package/dist/addon/token.js +116 -7
  8. package/dist/base.d.mts +6 -1
  9. package/dist/base.d.ts +6 -1
  10. package/dist/bin/config.js +3 -3
  11. package/dist/index.d.ts +9 -2
  12. package/dist/index.js +10 -1
  13. package/dist/lib/element.d.ts +1 -0
  14. package/dist/lib/element.js +3 -1
  15. package/dist/lib/lintConfig.d.ts +13 -0
  16. package/dist/lib/lintConfig.js +161 -0
  17. package/dist/lib/lsp.d.ts +2 -0
  18. package/dist/lib/lsp.js +11 -8
  19. package/dist/lib/node.d.ts +20 -3
  20. package/dist/lib/node.js +647 -585
  21. package/dist/lib/text.d.ts +2 -0
  22. package/dist/lib/text.js +21 -12
  23. package/dist/lib/title.d.ts +3 -1
  24. package/dist/lib/title.js +3 -1
  25. package/dist/mixin/attributesParent.d.ts +6 -6
  26. package/dist/mixin/attributesParent.js +4 -4
  27. package/dist/mixin/cached.d.ts +5 -0
  28. package/dist/mixin/cached.js +22 -0
  29. package/dist/mixin/clone.d.ts +5 -0
  30. package/dist/mixin/clone.js +23 -0
  31. package/dist/mixin/hidden.js +68 -18
  32. package/dist/mixin/sol.js +2 -2
  33. package/dist/parser/commentAndExt.js +1 -1
  34. package/dist/parser/html.js +3 -3
  35. package/dist/parser/list.js +6 -3
  36. package/dist/parser/table.js +4 -4
  37. package/dist/src/arg.js +14 -8
  38. package/dist/src/atom.js +76 -31
  39. package/dist/src/attribute.d.ts +1 -0
  40. package/dist/src/attribute.js +51 -20
  41. package/dist/src/attributes.d.ts +7 -7
  42. package/dist/src/attributes.js +415 -366
  43. package/dist/src/commented.js +81 -35
  44. package/dist/src/converter.js +14 -8
  45. package/dist/src/converterFlags.js +33 -22
  46. package/dist/src/converterRule.js +263 -216
  47. package/dist/src/extLink.js +23 -18
  48. package/dist/src/gallery.d.ts +12 -2
  49. package/dist/src/gallery.js +30 -10
  50. package/dist/src/heading.d.ts +6 -1
  51. package/dist/src/heading.js +73 -59
  52. package/dist/src/hidden.js +14 -9
  53. package/dist/src/html.js +29 -10
  54. package/dist/src/imageParameter.d.ts +1 -0
  55. package/dist/src/imageParameter.js +15 -7
  56. package/dist/src/imagemap.js +35 -28
  57. package/dist/src/index.d.ts +3 -0
  58. package/dist/src/index.js +66 -49
  59. package/dist/src/link/base.js +17 -12
  60. package/dist/src/link/file.d.ts +9 -1
  61. package/dist/src/link/file.js +401 -346
  62. package/dist/src/link/galleryImage.js +12 -6
  63. package/dist/src/link/index.js +7 -3
  64. package/dist/src/link/redirectTarget.d.ts +6 -1
  65. package/dist/src/link/redirectTarget.js +14 -5
  66. package/dist/src/magicLink.d.ts +6 -1
  67. package/dist/src/magicLink.js +30 -16
  68. package/dist/src/nested.js +122 -74
  69. package/dist/src/nowiki/base.js +5 -2
  70. package/dist/src/nowiki/comment.js +6 -2
  71. package/dist/src/nowiki/index.js +4 -4
  72. package/dist/src/nowiki/listBase.d.ts +6 -1
  73. package/dist/src/nowiki/listBase.js +7 -2
  74. package/dist/src/nowiki/quote.d.ts +6 -1
  75. package/dist/src/nowiki/quote.js +22 -10
  76. package/dist/src/onlyinclude.js +17 -9
  77. package/dist/src/paramTag/index.js +21 -14
  78. package/dist/src/parameter.js +26 -20
  79. package/dist/src/pre.js +91 -45
  80. package/dist/src/redirect.js +1 -1
  81. package/dist/src/syntax.js +14 -10
  82. package/dist/src/table/index.js +550 -502
  83. package/dist/src/table/td.js +66 -59
  84. package/dist/src/table/trBase.js +179 -129
  85. package/dist/src/tagPair/ext.js +32 -20
  86. package/dist/src/tagPair/include.js +5 -5
  87. package/dist/src/tagPair/translate.js +150 -103
  88. package/dist/src/transclude.d.ts +21 -8
  89. package/dist/src/transclude.js +56 -34
  90. package/dist/util/html.js +45 -43
  91. package/dist/util/lint.js +10 -7
  92. package/dist/util/string.js +13 -7
  93. package/extensions/dist/base.js +2 -2
  94. package/i18n/zh-hans.json +1 -1
  95. package/i18n/zh-hant.json +1 -1
  96. package/package.json +15 -15
@@ -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
- class FileToken extends base_1.LinkBaseToken {
63
- /* NOT FOR BROWSER END */
64
- get type() {
65
- return 'file';
66
- }
67
- /** file extension / 扩展名 */
68
- get extension() {
69
- return this.getAttribute('title').extension;
70
- }
71
- /* NOT FOR BROWSER */
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
- /** image height / 图片高度 */
103
- get height() {
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
- else {
114
- this.setValue('width', height && `x${height}`);
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
- this.setAttribute('acceptable', { AtomToken: 0, ImageParameterToken: '1:' });
127
- /* NOT FOR BROWSER END */
128
- const { extension } = this.getTitle(true, true);
129
- /-\{|\}-|\|/gu; // eslint-disable-line @typescript-eslint/no-unused-expressions
130
- this.safeAppend(explode(text).map(
131
- // @ts-expect-error abstract class
132
- (part) => new imageParameter_1.ImageParameterToken(part, extension, config, accum)));
133
- }
134
- /** @private */
135
- lint(start = this.getAbsoluteIndex(), re) {
136
- 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);
137
- if (this.closest('ext-link-text')
138
- && this.getValue('link')?.trim() !== '') {
139
- errors.push((0, lint_1.generateForSelf)(this, rect, 'nested-link', 'internal link in an external link'));
140
- }
141
- if (unscaled) {
142
- for (const arg of args.filter(({ name }) => name === 'width')) {
143
- const e = (0, lint_1.generateForChild)(arg, rect, 'invalid-gallery', 'invalid image parameter');
144
- e.fix = { range: [e.startIndex - 1, e.endIndex], text: '', desc: 'remove' };
145
- errors.push(e);
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
- if (args.length === keys.length
149
- && frameKeys.length < 2
150
- && horizAlignKeys.length < 2
151
- && vertAlignKeys.length < 2) {
152
- return errors;
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 msg 消息键
157
- * @param p1 替换$1
158
- * @param severity 错误等级
169
+ * @param link 文件名
170
+ * @param text 图片参数
171
+ * @param delimiter `|`
159
172
  */
160
- const generate = (msg, p1, severity = true) => (arg) => {
161
- 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');
162
- e.suggestions = [{ desc: 'remove', range: [e.startIndex - 1, e.endIndex], text: '' }];
163
- return e;
164
- };
165
- const { extension } = this;
166
- for (const key of keys) {
167
- if (key === 'invalid' || key === 'width' && unscaled) {
168
- continue;
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
- const isCaption = key === 'caption';
171
- let relevantArgs = args.filter(({ name }) => name === key);
172
- if (isCaption) {
173
- relevantArgs = [
174
- ...relevantArgs.slice(0, -1).filter(arg => arg.text()),
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
- if (relevantArgs.length > 1) {
179
- let severity = !isCaption || !extension || extensions.has(extension);
180
- if (isCaption && severity) {
181
- const plainArgs = filterArgs(relevantArgs, transclusion);
182
- severity = plainArgs.length > 1 && ((arg) => plainArgs.includes(arg));
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
- if (frameKeys.length > 1) {
188
- errors.push(...args.filter(({ name }) => frame.has(name)).map(generate('conflicting', 'frame')));
251
+ /**
252
+ * Get all image parameter tokens
253
+ *
254
+ * 获取所有图片参数节点
255
+ */
256
+ getAllArgs() {
257
+ return this.childNodes.slice(1);
189
258
  }
190
- if (horizAlignKeys.length > 1) {
191
- errors.push(...args.filter(({ name }) => horizAlign.has(name))
192
- .map(generate('conflicting', 'horizontal-alignment')));
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
- if (vertAlignKeys.length > 1) {
195
- errors.push(...args.filter(({ name }) => vertAlign.has(name))
196
- .map(generate('conflicting', 'vertical-alignment')));
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
- return errors;
199
- }
200
- /**
201
- * Get all image parameter tokens
202
- *
203
- * 获取所有图片参数节点
204
- */
205
- getAllArgs() {
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
- return json;
243
- }
244
- /* NOT FOR BROWSER */
245
- /**
246
- * 获取特定类型的图片属性参数节点
247
- * @param keys 接受的参数名
248
- * @param type 类型名
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
- * Get all image parameter names
328
- *
329
- * 获取图片参数名
330
- */
331
- getKeys() {
332
- return new Set(this.getAllArgs().map(({ name }) => name));
333
- }
334
- /**
335
- * Get the image parameter values with the specified name
336
- *
337
- * 获取指定的图片参数值
338
- * @param key parameter name / 参数名
339
- */
340
- getValues(key) {
341
- return this.getArgs(key).map(token => token.getValue());
342
- }
343
- /**
344
- * Set the image parameter
345
- *
346
- * 设置图片参数
347
- * @param key parameter name / 参数名
348
- * @param value parameter value / 参数值
349
- * @throws `RangeError` 未定义的图片参数
350
- */
351
- setValue(key, value = false) {
352
- if (value === false) {
353
- this.removeArg(key);
354
- return;
355
- }
356
- const token = this.getArg(key);
357
- if (token) {
358
- token.setValue(value);
359
- return;
360
- }
361
- const config = this.getAttribute('config'), syntax = key === 'caption' ? '$1' : Object.entries(config.img).find(([, name]) => name === key)?.[0];
362
- /* istanbul ignore if */
363
- if (syntax === undefined) {
364
- throw new RangeError(`Unknown image parameter: ${key}`);
365
- }
366
- const free = syntax.includes('$1');
367
- /* istanbul ignore if */
368
- if (value === true && free) {
369
- this.typeError('setValue', 'String');
370
- }
371
- const parameter = debug_1.Shadow.run(() =>
372
- // @ts-expect-error abstract class
373
- new imageParameter_1.ImageParameterToken(syntax.replace('$1', key === 'width' ? '1' : ''), this.extension, config));
374
- if (free) {
375
- const { childNodes } = index_1.default
376
- .parse(value, this.getAttribute('include'), undefined, config);
377
- parameter.safeReplaceChildren(childNodes);
378
- }
379
- this.insertAt(parameter);
380
- }
381
- /* istanbul ignore next */
382
- /**
383
- * @override
384
- * @throws `Error` 不适用于图片
385
- */
386
- setLinkText() {
387
- throw new Error('LinkBaseToken.setLinkText method is not applicable to images!');
388
- }
389
- /** @private */
390
- toHtmlInternal(opt) {
391
- /** @ignore */
392
- const isInteger = (n) => Boolean(n && !/\D/u.test(n));
393
- 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({
394
- ...opt,
395
- nowrap: true,
396
- }) ?? '', 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({
397
- ...opt,
398
- nowrap: true,
399
- })) ?? 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()}" class="mw-file-element"${isInteger(width) ? ` width="${width}"` : ''}${isInteger(height) ? ` height="${height}"` : ''}>`;
400
- let href = '';
401
- if (link) {
402
- try {
403
- href = typeof link === 'string' ? this.getArg('link').getUrl() : link.getUrl();
404
- if (link === file) {
405
- const lang = this.getValue('lang'), page = this.getValue('page');
406
- if (lang) {
407
- href += `?lang=${lang}`;
408
- }
409
- else if (page) {
410
- href += `?page=${page}`;
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
- catch { }
415
- }
416
- const a = link
417
- ? `<a${href && ` href="${href}"`}${hasLink ? '' : ' class="mw-file-description"'}${titleAttr}${typeof link === 'string' ? ' rel="nofollow"' : ''}>${img}</a>`
418
- : `<span${titleAttr}>${img}</span>`;
419
- if (type !== 'gallery-image') {
420
- return horiz || vert || visibleCaption
421
- ? `<figure${classAttr} typeof="mw:File${fr ? `/${manual ? 'Thumb' : frame.get(fr)}` : ''}">${a}<figcaption>${caption}</figcaption></figure>`
422
- : `<span${classAttr}>${a}</span>`;
423
- }
424
- const parent = this.parentNode, mode = parent?.parentNode?.getAttr('mode'), nolines = typeof mode === 'string' && mode.toLowerCase() === 'nolines', padding = nolines ? 0 : 30;
425
- 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?.getAttr('showfilename') === undefined
426
- ? ''
427
- : `<a href="${file.getUrl()}" class="galleryfilename galleryfilename-truncate" title="${file.title}">${file.main}</a>\n`}${caption}</div>\n\t</li>`;
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;