wikiparser-node 1.5.6 → 1.5.7-b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/bundle/bundle.min.js +38 -0
  2. package/config/enwiki.json +1 -814
  3. package/config/llwiki.json +1 -35
  4. package/config/moegirl.json +1 -44
  5. package/config/zhwiki.json +1 -466
  6. package/extensions/dist/base.js +64 -0
  7. package/extensions/dist/editor.js +159 -0
  8. package/extensions/dist/highlight.js +59 -0
  9. package/extensions/dist/lint.js +60 -0
  10. package/extensions/editor.css +63 -0
  11. package/extensions/ui.css +141 -0
  12. package/package.json +28 -17
  13. package/config/.schema.json +0 -172
  14. package/dist/addon/table.d.ts +0 -6
  15. package/dist/addon/table.js +0 -564
  16. package/dist/base.d.ts +0 -72
  17. package/dist/base.js +0 -38
  18. package/dist/index.d.ts +0 -30
  19. package/dist/index.js +0 -214
  20. package/dist/internal.d.ts +0 -44
  21. package/dist/lib/element.d.ts +0 -151
  22. package/dist/lib/element.js +0 -615
  23. package/dist/lib/node.d.ts +0 -146
  24. package/dist/lib/node.js +0 -426
  25. package/dist/lib/range.d.ts +0 -104
  26. package/dist/lib/range.js +0 -385
  27. package/dist/lib/ranges.d.ts +0 -26
  28. package/dist/lib/ranges.js +0 -118
  29. package/dist/lib/text.d.ts +0 -63
  30. package/dist/lib/text.js +0 -354
  31. package/dist/lib/title.d.ts +0 -38
  32. package/dist/lib/title.js +0 -160
  33. package/dist/mixin/attributesParent.d.ts +0 -50
  34. package/dist/mixin/attributesParent.js +0 -78
  35. package/dist/mixin/fixed.d.ts +0 -6
  36. package/dist/mixin/fixed.js +0 -30
  37. package/dist/mixin/flagsParent.d.ts +0 -72
  38. package/dist/mixin/flagsParent.js +0 -59
  39. package/dist/mixin/hidden.d.ts +0 -5
  40. package/dist/mixin/hidden.js +0 -24
  41. package/dist/mixin/magicLinkParent.d.ts +0 -40
  42. package/dist/mixin/magicLinkParent.js +0 -42
  43. package/dist/mixin/singleLine.d.ts +0 -6
  44. package/dist/mixin/singleLine.js +0 -26
  45. package/dist/mixin/sol.d.ts +0 -6
  46. package/dist/mixin/sol.js +0 -43
  47. package/dist/mixin/syntax.d.ts +0 -9
  48. package/dist/mixin/syntax.js +0 -50
  49. package/dist/parser/braces.js +0 -131
  50. package/dist/parser/commentAndExt.js +0 -90
  51. package/dist/parser/converter.js +0 -41
  52. package/dist/parser/externalLinks.js +0 -32
  53. package/dist/parser/hrAndDoubleUnderscore.js +0 -41
  54. package/dist/parser/html.js +0 -39
  55. package/dist/parser/links.js +0 -95
  56. package/dist/parser/list.js +0 -98
  57. package/dist/parser/magicLinks.js +0 -43
  58. package/dist/parser/quotes.js +0 -68
  59. package/dist/parser/selector.js +0 -162
  60. package/dist/parser/table.js +0 -124
  61. package/dist/src/arg.d.ts +0 -58
  62. package/dist/src/arg.js +0 -214
  63. package/dist/src/atom.d.ts +0 -12
  64. package/dist/src/atom.js +0 -27
  65. package/dist/src/attribute.d.ts +0 -71
  66. package/dist/src/attribute.js +0 -502
  67. package/dist/src/attributes.d.ts +0 -109
  68. package/dist/src/attributes.js +0 -356
  69. package/dist/src/converter.d.ts +0 -33
  70. package/dist/src/converter.js +0 -134
  71. package/dist/src/converterFlags.d.ts +0 -87
  72. package/dist/src/converterFlags.js +0 -242
  73. package/dist/src/converterRule.d.ts +0 -77
  74. package/dist/src/converterRule.js +0 -209
  75. package/dist/src/extLink.d.ts +0 -43
  76. package/dist/src/extLink.js +0 -188
  77. package/dist/src/gallery.d.ts +0 -54
  78. package/dist/src/gallery.js +0 -139
  79. package/dist/src/heading.d.ts +0 -47
  80. package/dist/src/heading.js +0 -190
  81. package/dist/src/hidden.d.ts +0 -7
  82. package/dist/src/hidden.js +0 -23
  83. package/dist/src/html.d.ts +0 -65
  84. package/dist/src/html.js +0 -358
  85. package/dist/src/imageParameter.d.ts +0 -65
  86. package/dist/src/imageParameter.js +0 -257
  87. package/dist/src/imagemap.d.ts +0 -54
  88. package/dist/src/imagemap.js +0 -144
  89. package/dist/src/imagemapLink.d.ts +0 -31
  90. package/dist/src/imagemapLink.js +0 -93
  91. package/dist/src/index.d.ts +0 -143
  92. package/dist/src/index.js +0 -813
  93. package/dist/src/link/base.d.ts +0 -52
  94. package/dist/src/link/base.js +0 -229
  95. package/dist/src/link/category.d.ts +0 -13
  96. package/dist/src/link/category.js +0 -28
  97. package/dist/src/link/file.d.ts +0 -98
  98. package/dist/src/link/file.js +0 -272
  99. package/dist/src/link/galleryImage.d.ts +0 -32
  100. package/dist/src/link/galleryImage.js +0 -157
  101. package/dist/src/link/index.d.ts +0 -56
  102. package/dist/src/link/index.js +0 -133
  103. package/dist/src/magicLink.d.ts +0 -59
  104. package/dist/src/magicLink.js +0 -223
  105. package/dist/src/nested.d.ts +0 -43
  106. package/dist/src/nested.js +0 -105
  107. package/dist/src/nowiki/base.d.ts +0 -31
  108. package/dist/src/nowiki/base.js +0 -93
  109. package/dist/src/nowiki/comment.d.ts +0 -25
  110. package/dist/src/nowiki/comment.js +0 -76
  111. package/dist/src/nowiki/dd.d.ts +0 -8
  112. package/dist/src/nowiki/dd.js +0 -24
  113. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -18
  114. package/dist/src/nowiki/doubleUnderscore.js +0 -101
  115. package/dist/src/nowiki/hr.d.ts +0 -5
  116. package/dist/src/nowiki/hr.js +0 -63
  117. package/dist/src/nowiki/index.d.ts +0 -16
  118. package/dist/src/nowiki/index.js +0 -27
  119. package/dist/src/nowiki/list.d.ts +0 -16
  120. package/dist/src/nowiki/list.js +0 -109
  121. package/dist/src/nowiki/listBase.d.ts +0 -5
  122. package/dist/src/nowiki/listBase.js +0 -61
  123. package/dist/src/nowiki/noinclude.d.ts +0 -10
  124. package/dist/src/nowiki/noinclude.js +0 -23
  125. package/dist/src/nowiki/quote.d.ts +0 -14
  126. package/dist/src/nowiki/quote.js +0 -131
  127. package/dist/src/onlyinclude.d.ts +0 -16
  128. package/dist/src/onlyinclude.js +0 -57
  129. package/dist/src/paramTag/index.d.ts +0 -37
  130. package/dist/src/paramTag/index.js +0 -77
  131. package/dist/src/paramTag/inputbox.d.ts +0 -8
  132. package/dist/src/paramTag/inputbox.js +0 -22
  133. package/dist/src/parameter.d.ts +0 -70
  134. package/dist/src/parameter.js +0 -264
  135. package/dist/src/pre.d.ts +0 -31
  136. package/dist/src/pre.js +0 -59
  137. package/dist/src/syntax.d.ts +0 -20
  138. package/dist/src/syntax.js +0 -86
  139. package/dist/src/table/base.d.ts +0 -30
  140. package/dist/src/table/base.js +0 -132
  141. package/dist/src/table/index.d.ts +0 -233
  142. package/dist/src/table/index.js +0 -396
  143. package/dist/src/table/td.d.ts +0 -86
  144. package/dist/src/table/td.js +0 -350
  145. package/dist/src/table/tr.d.ts +0 -32
  146. package/dist/src/table/tr.js +0 -58
  147. package/dist/src/table/trBase.d.ts +0 -53
  148. package/dist/src/table/trBase.js +0 -152
  149. package/dist/src/tagPair/ext.d.ts +0 -32
  150. package/dist/src/tagPair/ext.js +0 -203
  151. package/dist/src/tagPair/include.d.ts +0 -35
  152. package/dist/src/tagPair/include.js +0 -74
  153. package/dist/src/tagPair/index.d.ts +0 -27
  154. package/dist/src/tagPair/index.js +0 -128
  155. package/dist/src/transclude.d.ts +0 -167
  156. package/dist/src/transclude.js +0 -717
  157. package/dist/util/constants.js +0 -28
  158. package/dist/util/debug.js +0 -88
  159. package/dist/util/diff.js +0 -83
  160. package/dist/util/lint.js +0 -31
  161. package/dist/util/string.js +0 -54
  162. package/errors/README +0 -1
  163. package/printed/README +0 -1
@@ -1,52 +0,0 @@
1
- import Parser from '../../index';
2
- import { Token } from '../index';
3
- import { AtomToken } from '../atom';
4
- import type { LintError } from '../../base';
5
- import type { Title } from '../../lib/title';
6
- /**
7
- * 内链
8
- * @classdesc `{childNodes: [AtomToken, ...Token]}`
9
- */
10
- export declare abstract class LinkBaseToken extends Token {
11
- #private;
12
- type: 'link' | 'category' | 'file' | 'gallery-image' | 'imagemap-image';
13
- readonly name: string;
14
- readonly childNodes: readonly [AtomToken, ...Token[]];
15
- abstract get firstChild(): AtomToken;
16
- abstract get lastChild(): Token;
17
- abstract get children(): [AtomToken, ...Token[]];
18
- abstract get firstElementChild(): AtomToken;
19
- abstract get lastElementChild(): Token;
20
- /** 完整链接 */
21
- get link(): string | Title;
22
- set link(link: string);
23
- /** fragment */
24
- get fragment(): string | undefined;
25
- set fragment(fragment: string | undefined);
26
- /**
27
- * @param link 链接标题
28
- * @param linkText 链接显示文字
29
- * @param delimiter `|`
30
- */
31
- constructor(link: string, linkText?: string, config?: Parser.Config, accum?: Token[], delimiter?: string);
32
- /** @override */
33
- text(): string;
34
- /** @override */
35
- lint(start?: number, re?: RegExp): LintError[];
36
- /** @override */
37
- print(): string;
38
- /** @override */
39
- cloneNode(this: this & {
40
- constructor: new (...args: any[]) => unknown;
41
- }): this;
42
- /**
43
- * 设置链接目标
44
- * @param link 链接目标
45
- */
46
- setTarget(link: string): void;
47
- /**
48
- * 设置链接显示文字
49
- * @param linkStr 链接显示文字
50
- */
51
- setLinkText(linkStr?: string): void;
52
- }
@@ -1,229 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LinkBaseToken = void 0;
4
- const lint_1 = require("../../util/lint");
5
- const constants_1 = require("../../util/constants");
6
- const debug_1 = require("../../util/debug");
7
- const index_1 = require("../../index");
8
- const index_2 = require("../index");
9
- const atom_1 = require("../atom");
10
- /**
11
- * 内链
12
- * @classdesc `{childNodes: [AtomToken, ...Token]}`
13
- */
14
- class LinkBaseToken extends index_2.Token {
15
- /* NOT FOR BROWSER END */
16
- #bracket = true;
17
- #delimiter;
18
- #title;
19
- /** 完整链接 */
20
- get link() {
21
- return this.#title;
22
- }
23
- set link(link) {
24
- this.setTarget(link);
25
- }
26
- /** fragment */
27
- get fragment() {
28
- return this.#title.fragment;
29
- }
30
- set fragment(fragment) {
31
- if (fragment === undefined) {
32
- this.setTarget(this.name);
33
- }
34
- }
35
- /* NOT FOR BROWSER END */
36
- /**
37
- * @param link 链接标题
38
- * @param linkText 链接显示文字
39
- * @param delimiter `|`
40
- */
41
- constructor(link, linkText, config = index_1.default.getConfig(), accum = [], delimiter = '|') {
42
- super(undefined, config, accum, {
43
- AtomToken: 0, Token: 1,
44
- });
45
- this.insertAt(new atom_1.AtomToken(link, 'link-target', config, accum, {
46
- 'Stage-2': ':', '!ExtToken': '', '!HeadingToken': '',
47
- }));
48
- if (linkText !== undefined) {
49
- const inner = new index_2.Token(linkText, config, accum, {
50
- 'Stage-5': ':', QuoteToken: ':', ConverterToken: ':',
51
- });
52
- inner.type = 'link-text';
53
- inner.setAttribute('stage', constants_1.MAX_STAGE - 1);
54
- this.insertAt(inner);
55
- }
56
- this.#delimiter = delimiter;
57
- /* NOT FOR BROWSER */
58
- this.protectChildren(0);
59
- }
60
- /** @private */
61
- afterBuild() {
62
- this.#title = this.getTitle();
63
- if (this.#delimiter.includes('\0')) {
64
- this.#delimiter = this.buildFromStr(this.#delimiter, constants_1.BuildMethod.String);
65
- }
66
- /* NOT FOR BROWSER */
67
- this.setAttribute('name', this.#title.title);
68
- const /** @implements */ linkListener = (e, data) => {
69
- const { prevTarget } = e;
70
- if (prevTarget?.type === 'link-target') {
71
- const name = prevTarget.text(), titleObj = this.getTitle(), { title, interwiki, ns, valid } = titleObj;
72
- if (!valid) {
73
- (0, debug_1.undo)(e, data);
74
- throw new Error(`非法的内链目标:${name}`);
75
- }
76
- else if (this.type === 'category' && (interwiki || ns !== 14)
77
- || this.type === 'file' && (interwiki || ns !== 6)) {
78
- (0, debug_1.undo)(e, data);
79
- throw new Error(`${this.type === 'file' ? '文件' : '分类'}链接不可更改命名空间:${name}`);
80
- }
81
- else if (this.type === 'link'
82
- && !interwiki
83
- && (ns === 6 || ns === 14)
84
- && !name.trim().startsWith(':')) {
85
- const { firstChild } = prevTarget;
86
- if (firstChild?.type === 'text') {
87
- firstChild.insertData(0, ':');
88
- }
89
- else {
90
- prevTarget.prepend(':');
91
- }
92
- }
93
- this.#title = titleObj;
94
- this.setAttribute('name', title);
95
- }
96
- };
97
- this.addEventListener(['remove', 'insert', 'replace', 'text'], linkListener);
98
- }
99
- /** @private */
100
- setAttribute(key, value) {
101
- if (key === 'bracket') {
102
- this.#bracket = Boolean(value);
103
- }
104
- else if (key === 'title') {
105
- this.#title = value;
106
- }
107
- else {
108
- super.setAttribute(key, value);
109
- }
110
- }
111
- /** @private */
112
- toString() {
113
- const str = super.toString(this.#delimiter);
114
- return this.#bracket ? `[[${str}]]` : str;
115
- }
116
- /** @override */
117
- text() {
118
- const str = super.text('|');
119
- return this.#bracket ? `[[${str}]]` : str;
120
- }
121
- /** @private */
122
- getAttribute(key) {
123
- if (key === 'title') {
124
- return this.#title;
125
- }
126
- return key === 'padding' ? 2 : super.getAttribute(key);
127
- }
128
- /** @private */
129
- getGaps(i) {
130
- return i === 0 ? this.#delimiter.length : 1;
131
- }
132
- /** @override */
133
- lint(start = this.getAbsoluteIndex(), re) {
134
- const errors = super.lint(start, re), { childNodes: [target, linkText], type: linkType } = this, { encoded, fragment } = this.#title;
135
- let rect;
136
- if (target.childNodes.some(({ type }) => type === 'template')) {
137
- rect = { start, ...this.getRootNode().posFromIndex(start) };
138
- errors.push((0, lint_1.generateForChild)(target, rect, 'unknown-page', 'template in an internal link target', 'warning'));
139
- }
140
- if (encoded) {
141
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
142
- errors.push((0, lint_1.generateForChild)(target, rect, 'url-encoding', 'unnecessary URL encoding in an internal link'));
143
- }
144
- if (linkType === 'link' || linkType === 'category') {
145
- const textNode = linkText?.childNodes.find((c) => c.type === 'text' && c.data.includes('|'));
146
- if (textNode) {
147
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
148
- const e = (0, lint_1.generateForChild)(linkText, rect, 'pipe-like', 'additional "|" in the link text', 'warning');
149
- e.suggestions = [
150
- {
151
- desc: 'escape',
152
- range: [
153
- e.startIndex + textNode.getRelativeIndex(),
154
- e.startIndex + textNode.getRelativeIndex() + textNode.data.length,
155
- ],
156
- text: textNode.data.replace(/\|/gu, '|'),
157
- },
158
- ];
159
- errors.push(e);
160
- }
161
- }
162
- if (linkType !== 'link' && fragment !== undefined) {
163
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
164
- const e = (0, lint_1.generateForChild)(target, rect, 'no-ignored', 'useless fragment'), textNode = target.childNodes.find((c) => c.type === 'text' && c.data.includes('#'));
165
- if (textNode) {
166
- e.fix = {
167
- range: [e.startIndex + textNode.getRelativeIndex() + textNode.data.indexOf('#'), e.endIndex],
168
- text: '',
169
- };
170
- }
171
- errors.push(e);
172
- }
173
- return errors;
174
- }
175
- /** @private */
176
- getTitle(halfParsed = false) {
177
- return this.normalizeTitle(this.firstChild.text(), 0, halfParsed, true, true);
178
- }
179
- /** @override */
180
- print() {
181
- return super.print(this.#bracket ? { pre: '[[', post: ']]', sep: this.#delimiter } : { sep: this.#delimiter });
182
- }
183
- /* NOT FOR BROWSER */
184
- /** @override */
185
- cloneNode() {
186
- const [link, ...linkText] = this.cloneChildNodes();
187
- return debug_1.Shadow.run(() => {
188
- const token = new this.constructor('', undefined, this.getAttribute('config'));
189
- token.firstChild.safeReplaceWith(link);
190
- token.append(...linkText);
191
- token.afterBuild();
192
- return token;
193
- });
194
- }
195
- /**
196
- * 设置链接目标
197
- * @param link 链接目标
198
- */
199
- setTarget(link) {
200
- const config = this.getAttribute('config'), { childNodes } = index_1.default.parse(String(link), this.getAttribute('include'), 2, config), token = debug_1.Shadow.run(() => new atom_1.AtomToken(undefined, 'link-target', config, [], {
201
- 'Stage-2': ':', '!ExtToken': '', '!HeadingToken': '',
202
- }));
203
- token.append(...childNodes);
204
- this.firstChild.safeReplaceWith(token);
205
- }
206
- /**
207
- * 设置链接显示文字
208
- * @param linkStr 链接显示文字
209
- */
210
- setLinkText(linkStr) {
211
- if (linkStr === undefined) {
212
- this.childNodes[1]?.remove();
213
- return;
214
- }
215
- const root = index_1.default.parse(linkStr, this.getAttribute('include'), undefined, this.getAttribute('config'));
216
- if (this.length === 1) {
217
- root.type = 'link-text';
218
- root.setAttribute('acceptable', {
219
- 'Stage-5': ':', QuoteToken: ':', ConverterToken: ':',
220
- });
221
- this.insertAt(root);
222
- }
223
- else {
224
- this.lastChild.replaceChildren(...root.childNodes);
225
- }
226
- }
227
- }
228
- exports.LinkBaseToken = LinkBaseToken;
229
- constants_1.classes['LinkBaseToken'] = __filename;
@@ -1,13 +0,0 @@
1
- import { LinkBaseToken } from './base';
2
- /** 分类 */
3
- export declare abstract class CategoryToken extends LinkBaseToken {
4
- readonly type = "category";
5
- /** 分类排序关键字 */
6
- get sortkey(): string | undefined;
7
- set sortkey(text: string | undefined);
8
- /**
9
- * 设置排序关键字
10
- * @param text 排序关键字
11
- */
12
- setSortkey(text?: string): void;
13
- }
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CategoryToken = void 0;
4
- const string_1 = require("../../util/string");
5
- const constants_1 = require("../../util/constants");
6
- const base_1 = require("./base");
7
- /** 分类 */
8
- class CategoryToken extends base_1.LinkBaseToken {
9
- type = 'category';
10
- /* NOT FOR BROWSER */
11
- /** 分类排序关键字 */
12
- get sortkey() {
13
- const { childNodes: [, child] } = this;
14
- return child && (0, string_1.decodeHtml)(child.text());
15
- }
16
- set sortkey(text) {
17
- this.setSortkey(text);
18
- }
19
- /**
20
- * 设置排序关键字
21
- * @param text 排序关键字
22
- */
23
- setSortkey(text) {
24
- this.setLinkText(text);
25
- }
26
- }
27
- exports.CategoryToken = CategoryToken;
28
- constants_1.classes['CategoryToken'] = __filename;
@@ -1,98 +0,0 @@
1
- import Parser from '../../index';
2
- import { LinkBaseToken } from './base';
3
- import { ImageParameterToken } from '../imageParameter';
4
- import type { Title } from '../../lib/title';
5
- import type { LintError } from '../../base';
6
- import type { Token, AtomToken } from '../../internal';
7
- /**
8
- * 图片
9
- * @classdesc `{childNodes: [AtomToken, ...ImageParameterToken]}`
10
- */
11
- export declare abstract class FileToken extends LinkBaseToken {
12
- #private;
13
- readonly type: 'file' | 'gallery-image' | 'imagemap-image';
14
- readonly childNodes: readonly [AtomToken, ...ImageParameterToken[]];
15
- abstract get lastChild(): AtomToken | ImageParameterToken;
16
- abstract get children(): [AtomToken, ...ImageParameterToken[]];
17
- abstract get lastElementChild(): AtomToken | ImageParameterToken;
18
- /** 扩展名 */
19
- get extension(): string | undefined;
20
- /** 图片链接 */
21
- get link(): string | Title;
22
- set link(value: string);
23
- /** 图片大小 */
24
- get size(): {
25
- width: string;
26
- height: string;
27
- } | undefined;
28
- set size(size: {
29
- width: string;
30
- height: string;
31
- } | undefined);
32
- /** 图片宽度 */
33
- get width(): string | undefined;
34
- set width(width: string | undefined);
35
- /** 图片高度 */
36
- get height(): string | undefined;
37
- set height(height: string | undefined);
38
- /**
39
- * @param link 文件名
40
- * @param text 图片参数
41
- * @param delimiter `|`
42
- */
43
- constructor(link: string, text?: string, config?: Parser.Config, accum?: Token[], delimiter?: string);
44
- /** @override */
45
- lint(start?: number, re?: RegExp): LintError[];
46
- /** 获取所有图片参数节点 */
47
- getAllArgs(): ImageParameterToken[];
48
- /**
49
- * 获取指定图片参数
50
- * @param key 参数名
51
- */
52
- getArgs(key: string): ImageParameterToken[];
53
- /** 获取图片框架属性参数节点 */
54
- getFrameArgs(): ImageParameterToken[];
55
- /** 获取图片水平对齐参数节点 */
56
- getHorizAlignArgs(): ImageParameterToken[];
57
- /** 获取图片垂直对齐参数节点 */
58
- getVertAlignArgs(): ImageParameterToken[];
59
- /**
60
- * 获取生效的指定图片参数
61
- * @param key 参数名
62
- */
63
- getArg(key: string): ImageParameterToken | undefined;
64
- /**
65
- * 获取生效的指定图片参数值
66
- * @param key 参数名
67
- */
68
- getValue(key: string): string | true | undefined;
69
- /**
70
- * 是否具有指定图片参数
71
- * @param key 参数名
72
- */
73
- hasArg(key: string): boolean;
74
- /**
75
- * 移除指定图片参数
76
- * @param key 参数名
77
- */
78
- removeArg(key: string): void;
79
- /** 获取图片参数名 */
80
- getKeys(): Set<string>;
81
- /**
82
- * 获取指定的图片参数值
83
- * @param key 参数名
84
- */
85
- getValues(key: string): (string | true)[];
86
- /**
87
- * 设置图片参数
88
- * @param key 参数名
89
- * @param value 参数值
90
- * @throws `RangeError` 未定义的图片参数
91
- */
92
- setValue(key: string, value?: string | boolean): void;
93
- /**
94
- * @override
95
- * @throws `Error` 不适用于图片
96
- */
97
- setLinkText(): never;
98
- }
@@ -1,272 +0,0 @@
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 debug_1 = require("../../util/debug");
7
- const constants_1 = require("../../util/constants");
8
- const index_1 = require("../../index");
9
- const base_1 = require("./base");
10
- const imageParameter_1 = require("../imageParameter");
11
- 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']);
12
- /**
13
- * a more sophisticated string-explode function
14
- * @param start start syntax of a nested AST node
15
- * @param end end syntax of a nested AST node
16
- * @param separator syntax for explosion
17
- * @param str string to be exploded
18
- */
19
- const explode = (start, end, separator, str) => {
20
- if (str === undefined) {
21
- return [];
22
- }
23
- const regex = new RegExp(`${[start, end, separator].map(string_1.escapeRegExp).join('|')}`, 'gu'), exploded = [];
24
- let mt = regex.exec(str), depth = 0, lastIndex = 0;
25
- while (mt) {
26
- const { 0: match, index } = mt;
27
- if (match !== separator) {
28
- depth += match === start ? 1 : -1;
29
- }
30
- else if (depth === 0) {
31
- exploded.push(str.slice(lastIndex, index));
32
- ({ lastIndex } = regex);
33
- }
34
- mt = regex.exec(str);
35
- }
36
- exploded.push(str.slice(lastIndex));
37
- return exploded;
38
- };
39
- /**
40
- * 图片
41
- * @classdesc `{childNodes: [AtomToken, ...ImageParameterToken]}`
42
- */
43
- class FileToken extends base_1.LinkBaseToken {
44
- type = 'file';
45
- /* NOT FOR BROWSER END */
46
- /** 扩展名 */
47
- get extension() {
48
- return this.getTitle().extension;
49
- }
50
- /* NOT FOR BROWSER */
51
- /** 图片链接 */
52
- get link() {
53
- return this.getArg('link')?.link ?? super.link;
54
- }
55
- set link(value) {
56
- this.setValue('link', value);
57
- }
58
- /** 图片大小 */
59
- get size() {
60
- return this.getArg('width')?.size;
61
- }
62
- set size(size) {
63
- this.setValue('width', size && `${size.width}${size.height && 'x'}${size.height}`);
64
- }
65
- /** 图片宽度 */
66
- get width() {
67
- return this.size?.width;
68
- }
69
- set width(width) {
70
- const arg = this.getArg('width');
71
- if (arg) {
72
- arg.width = width;
73
- }
74
- else {
75
- this.setValue('width', width);
76
- }
77
- }
78
- /** 图片高度 */
79
- get height() {
80
- return this.size?.height;
81
- }
82
- set height(height) {
83
- const arg = this.getArg('width');
84
- if (arg) {
85
- arg.height = height;
86
- }
87
- else {
88
- this.setValue('width', height && `x${height}`);
89
- }
90
- }
91
- /* NOT FOR BROWSER END */
92
- /**
93
- * @param link 文件名
94
- * @param text 图片参数
95
- * @param delimiter `|`
96
- */
97
- constructor(link, text, config = index_1.default.getConfig(), accum = [], delimiter = '|') {
98
- super(link, undefined, config, accum, delimiter);
99
- /* NOT FOR BROWSER */
100
- this.setAttribute('acceptable', { AtomToken: 0, ImageParameterToken: '1:' });
101
- /* NOT FOR BROWSER END */
102
- const { extension } = this.getTitle(true);
103
- this.append(...explode('-{', '}-', '|', text).map(
104
- // @ts-expect-error abstract class
105
- part => new imageParameter_1.ImageParameterToken(part, extension, config, accum)));
106
- }
107
- /** @override */
108
- lint(start = this.getAbsoluteIndex(), re) {
109
- const errors = super.lint(start, re), args = this.getAllArgs().filter(({ childNodes }) => {
110
- const visibleNodes = childNodes.filter(node => node.text().trim());
111
- return visibleNodes.length !== 1 || visibleNodes[0].type !== 'arg';
112
- }), 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));
113
- if (this.closest('ext-link-text') && this.getValue('link')?.trim() !== '') {
114
- errors.push((0, lint_1.generateForSelf)(this, { start }, 'nested-link', 'internal link in an external link'));
115
- }
116
- if (args.length === keys.length
117
- && frameKeys.length < 2
118
- && horizAlignKeys.length < 2
119
- && vertAlignKeys.length < 2) {
120
- return errors;
121
- }
122
- const rect = { start, ...this.getRootNode().posFromIndex(start) };
123
- /**
124
- * 图片参数到语法错误的映射
125
- * @param msg 消息键
126
- * @param p1 替换$1
127
- */
128
- const generate = (msg, p1) => (arg) => (0, lint_1.generateForChild)(arg, rect, 'no-duplicate', index_1.default.msg(`${msg} image $1 parameter`, p1));
129
- for (const key of keys) {
130
- let relevantArgs = args.filter(({ name }) => name === key);
131
- if (key === 'caption') {
132
- relevantArgs = [...relevantArgs.slice(0, -1).filter(arg => arg.text()), ...relevantArgs.slice(-1)];
133
- }
134
- if (relevantArgs.length > 1) {
135
- errors.push(...relevantArgs.map(generate('duplicated', key)));
136
- }
137
- }
138
- if (frameKeys.length > 1) {
139
- errors.push(...args.filter(({ name }) => frame.has(name)).map(generate('conflicting', 'frame')));
140
- }
141
- if (horizAlignKeys.length > 1) {
142
- errors.push(...args.filter(({ name }) => horizAlign.has(name)).map(generate('conflicting', 'horizontal-alignment')));
143
- }
144
- if (vertAlignKeys.length > 1) {
145
- errors.push(...args.filter(({ name }) => vertAlign.has(name)).map(generate('conflicting', 'vertical-alignment')));
146
- }
147
- return errors;
148
- }
149
- /** 获取所有图片参数节点 */
150
- getAllArgs() {
151
- return this.childNodes.slice(1);
152
- }
153
- /**
154
- * 获取指定图片参数
155
- * @param key 参数名
156
- */
157
- getArgs(key) {
158
- return this.getAllArgs().filter(({ name }) => key === name);
159
- }
160
- /**
161
- * 获取特定类型的图片属性参数节点
162
- * @param keys 接受的参数名
163
- * @param type 类型名
164
- */
165
- #getTypedArgs(keys, type) {
166
- const args = this.getAllArgs().filter(({ name }) => keys.has(name));
167
- /* NOT FOR BROWSER */
168
- if (args.length > 1) {
169
- index_1.default.warn(`图片 ${this.name} 带有 ${args.length} 个${type}参数,只有最后 1 个 ${args[0].name} 会生效!`);
170
- }
171
- /* NOT FOR BROWSER END */
172
- return args;
173
- }
174
- /** 获取图片框架属性参数节点 */
175
- getFrameArgs() {
176
- return this.#getTypedArgs(frame, '框架');
177
- }
178
- /** 获取图片水平对齐参数节点 */
179
- getHorizAlignArgs() {
180
- return this.#getTypedArgs(horizAlign, '水平对齐');
181
- }
182
- /** 获取图片垂直对齐参数节点 */
183
- getVertAlignArgs() {
184
- return this.#getTypedArgs(vertAlign, '垂直对齐');
185
- }
186
- /**
187
- * 获取生效的指定图片参数
188
- * @param key 参数名
189
- */
190
- getArg(key) {
191
- const args = this.getArgs(key);
192
- return args[args.length - 1];
193
- }
194
- /**
195
- * 获取生效的指定图片参数值
196
- * @param key 参数名
197
- */
198
- getValue(key) {
199
- return this.getArg(key)?.getValue();
200
- }
201
- /* NOT FOR BROWSER */
202
- /**
203
- * 是否具有指定图片参数
204
- * @param key 参数名
205
- */
206
- hasArg(key) {
207
- return this.getArgs(key).length > 0;
208
- }
209
- /**
210
- * 移除指定图片参数
211
- * @param key 参数名
212
- */
213
- removeArg(key) {
214
- for (const token of this.getArgs(key)) {
215
- this.removeChild(token);
216
- }
217
- }
218
- /** 获取图片参数名 */
219
- getKeys() {
220
- return new Set(this.getAllArgs().map(({ name }) => name));
221
- }
222
- /**
223
- * 获取指定的图片参数值
224
- * @param key 参数名
225
- */
226
- getValues(key) {
227
- return this.getArgs(key).map(token => token.getValue());
228
- }
229
- /**
230
- * 设置图片参数
231
- * @param key 参数名
232
- * @param value 参数值
233
- * @throws `RangeError` 未定义的图片参数
234
- */
235
- setValue(key, value = false) {
236
- if (value === false) {
237
- this.removeArg(key);
238
- return;
239
- }
240
- const token = this.getArg(key);
241
- if (token) {
242
- token.setValue(value);
243
- return;
244
- }
245
- const config = this.getAttribute('config'), syntax = key === 'caption' ? '$1' : Object.entries(config.img).find(([, name]) => name === key)?.[0];
246
- if (syntax === undefined) {
247
- throw new RangeError(`未定义的图片参数: ${key}`);
248
- }
249
- const free = syntax.includes('$1');
250
- if (value === true && free) {
251
- this.typeError('setValue', 'Boolean');
252
- }
253
- const parameter = debug_1.Shadow.run(
254
- // @ts-expect-error abstract class
255
- () => new imageParameter_1.ImageParameterToken(syntax.replace('$1', ''), this.extension, config));
256
- if (free) {
257
- const { childNodes } = index_1.default.parse(value, this.getAttribute('include'), undefined, config);
258
- parameter.replaceChildren(...childNodes);
259
- }
260
- parameter.afterBuild();
261
- this.insertAt(parameter);
262
- }
263
- /**
264
- * @override
265
- * @throws `Error` 不适用于图片
266
- */
267
- setLinkText() {
268
- throw new Error('setLinkText 方法不适用于图片!');
269
- }
270
- }
271
- exports.FileToken = FileToken;
272
- constants_1.classes['FileToken'] = __filename;