wikiparser-node 1.0.0-beta.3 → 1.0.1-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 (146) hide show
  1. package/README.md +10 -9
  2. package/bundle/bundle.min.js +37 -0
  3. package/config/llwiki.json +1 -35
  4. package/config/minimum.json +136 -0
  5. package/config/moegirl.json +1 -44
  6. package/config/zhwiki.json +1 -466
  7. package/extensions/dist/base.js +105 -0
  8. package/extensions/dist/editor.js +172 -0
  9. package/extensions/dist/highlight.js +46 -0
  10. package/extensions/dist/lint.js +43 -0
  11. package/extensions/editor.css +63 -0
  12. package/extensions/ui.css +119 -0
  13. package/package.json +35 -20
  14. package/config/.schema.json +0 -160
  15. package/dist/index.d.ts +0 -62
  16. package/dist/index.js +0 -305
  17. package/dist/internal.d.ts +0 -44
  18. package/dist/lib/element.d.ts +0 -186
  19. package/dist/lib/element.js +0 -659
  20. package/dist/lib/node.d.ts +0 -178
  21. package/dist/lib/node.js +0 -458
  22. package/dist/lib/range.d.ts +0 -132
  23. package/dist/lib/range.js +0 -387
  24. package/dist/lib/ranges.d.ts +0 -28
  25. package/dist/lib/ranges.js +0 -125
  26. package/dist/lib/text.d.ts +0 -78
  27. package/dist/lib/text.js +0 -227
  28. package/dist/lib/title.d.ts +0 -33
  29. package/dist/lib/title.js +0 -110
  30. package/dist/mixin/attributesParent.js +0 -93
  31. package/dist/mixin/fixed.js +0 -32
  32. package/dist/mixin/hidden.js +0 -23
  33. package/dist/mixin/singleLine.js +0 -26
  34. package/dist/mixin/sol.js +0 -44
  35. package/dist/parser/braces.js +0 -125
  36. package/dist/parser/commentAndExt.js +0 -58
  37. package/dist/parser/converter.js +0 -38
  38. package/dist/parser/externalLinks.js +0 -28
  39. package/dist/parser/hrAndDoubleUnderscore.js +0 -40
  40. package/dist/parser/html.js +0 -38
  41. package/dist/parser/links.js +0 -94
  42. package/dist/parser/list.js +0 -61
  43. package/dist/parser/magicLinks.js +0 -39
  44. package/dist/parser/quotes.js +0 -67
  45. package/dist/parser/selector.js +0 -165
  46. package/dist/parser/table.js +0 -117
  47. package/dist/src/arg.d.ts +0 -77
  48. package/dist/src/arg.js +0 -199
  49. package/dist/src/atom.d.ts +0 -11
  50. package/dist/src/atom.js +0 -24
  51. package/dist/src/attribute.d.ts +0 -106
  52. package/dist/src/attribute.js +0 -436
  53. package/dist/src/attributes.d.ts +0 -119
  54. package/dist/src/attributes.js +0 -366
  55. package/dist/src/converter.d.ts +0 -75
  56. package/dist/src/converter.js +0 -141
  57. package/dist/src/converterFlags.d.ts +0 -107
  58. package/dist/src/converterFlags.js +0 -238
  59. package/dist/src/converterRule.d.ts +0 -96
  60. package/dist/src/converterRule.js +0 -255
  61. package/dist/src/extLink.d.ts +0 -63
  62. package/dist/src/extLink.js +0 -157
  63. package/dist/src/gallery.d.ts +0 -70
  64. package/dist/src/gallery.js +0 -137
  65. package/dist/src/heading.d.ts +0 -82
  66. package/dist/src/heading.js +0 -135
  67. package/dist/src/hidden.d.ts +0 -19
  68. package/dist/src/hidden.js +0 -26
  69. package/dist/src/html.d.ts +0 -113
  70. package/dist/src/html.js +0 -245
  71. package/dist/src/imageParameter.d.ts +0 -82
  72. package/dist/src/imageParameter.js +0 -256
  73. package/dist/src/imagemap.d.ts +0 -77
  74. package/dist/src/imagemap.js +0 -169
  75. package/dist/src/imagemapLink.d.ts +0 -48
  76. package/dist/src/imagemapLink.js +0 -43
  77. package/dist/src/index.d.ts +0 -156
  78. package/dist/src/index.js +0 -819
  79. package/dist/src/link/base.d.ts +0 -69
  80. package/dist/src/link/base.js +0 -231
  81. package/dist/src/link/category.d.ts +0 -14
  82. package/dist/src/link/category.js +0 -28
  83. package/dist/src/link/file.d.ts +0 -105
  84. package/dist/src/link/file.js +0 -269
  85. package/dist/src/link/galleryImage.d.ts +0 -37
  86. package/dist/src/link/galleryImage.js +0 -100
  87. package/dist/src/link/index.d.ts +0 -50
  88. package/dist/src/link/index.js +0 -134
  89. package/dist/src/magicLink.d.ts +0 -46
  90. package/dist/src/magicLink.js +0 -131
  91. package/dist/src/nested.d.ts +0 -47
  92. package/dist/src/nested.js +0 -92
  93. package/dist/src/nowiki/base.d.ts +0 -38
  94. package/dist/src/nowiki/base.js +0 -31
  95. package/dist/src/nowiki/comment.d.ts +0 -42
  96. package/dist/src/nowiki/comment.js +0 -64
  97. package/dist/src/nowiki/dd.d.ts +0 -22
  98. package/dist/src/nowiki/dd.js +0 -46
  99. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -35
  100. package/dist/src/nowiki/doubleUnderscore.js +0 -48
  101. package/dist/src/nowiki/hr.d.ts +0 -30
  102. package/dist/src/nowiki/hr.js +0 -36
  103. package/dist/src/nowiki/index.d.ts +0 -19
  104. package/dist/src/nowiki/index.js +0 -23
  105. package/dist/src/nowiki/list.d.ts +0 -16
  106. package/dist/src/nowiki/list.js +0 -13
  107. package/dist/src/nowiki/noinclude.d.ts +0 -21
  108. package/dist/src/nowiki/noinclude.js +0 -24
  109. package/dist/src/nowiki/quote.d.ts +0 -27
  110. package/dist/src/nowiki/quote.js +0 -58
  111. package/dist/src/onlyinclude.d.ts +0 -38
  112. package/dist/src/onlyinclude.js +0 -66
  113. package/dist/src/paramTag/index.d.ts +0 -50
  114. package/dist/src/paramTag/index.js +0 -78
  115. package/dist/src/paramTag/inputbox.d.ts +0 -7
  116. package/dist/src/paramTag/inputbox.js +0 -21
  117. package/dist/src/parameter.d.ts +0 -95
  118. package/dist/src/parameter.js +0 -204
  119. package/dist/src/pre.d.ts +0 -27
  120. package/dist/src/pre.js +0 -44
  121. package/dist/src/syntax.d.ts +0 -22
  122. package/dist/src/syntax.js +0 -67
  123. package/dist/src/table/base.d.ts +0 -60
  124. package/dist/src/table/base.js +0 -80
  125. package/dist/src/table/index.d.ts +0 -247
  126. package/dist/src/table/index.js +0 -783
  127. package/dist/src/table/td.d.ts +0 -119
  128. package/dist/src/table/td.js +0 -268
  129. package/dist/src/table/tr.d.ts +0 -31
  130. package/dist/src/table/tr.js +0 -50
  131. package/dist/src/table/trBase.d.ts +0 -62
  132. package/dist/src/table/trBase.js +0 -157
  133. package/dist/src/tagPair/ext.d.ts +0 -54
  134. package/dist/src/tagPair/ext.js +0 -150
  135. package/dist/src/tagPair/include.d.ts +0 -43
  136. package/dist/src/tagPair/include.js +0 -43
  137. package/dist/src/tagPair/index.d.ts +0 -57
  138. package/dist/src/tagPair/index.js +0 -113
  139. package/dist/src/transclude.d.ts +0 -200
  140. package/dist/src/transclude.js +0 -732
  141. package/dist/util/debug.js +0 -42
  142. package/dist/util/diff.js +0 -71
  143. package/dist/util/lint.js +0 -38
  144. package/dist/util/string.js +0 -74
  145. package/errors/README +0 -1
  146. package/printed/README +0 -1
@@ -1,78 +0,0 @@
1
- import { AstNode } from './node';
2
- import type { LintError } from '../index';
3
- /** 文本节点 */
4
- export declare class AstText extends AstNode {
5
- #private;
6
- /** @browser */
7
- readonly type = "text";
8
- name: undefined;
9
- /** @browser */
10
- data: string;
11
- /** 文本长度 */
12
- get length(): number;
13
- /**
14
- * @browser
15
- * @param text 包含文本
16
- */
17
- constructor(text?: string);
18
- /**
19
- * 输出字符串
20
- * @browser
21
- */
22
- toString(): string;
23
- /**
24
- * 可见部分
25
- * @browser
26
- */
27
- text(): string;
28
- /**
29
- * Linter
30
- * @browser
31
- * @param start
32
- */
33
- lint(start?: number): LintError[];
34
- /**
35
- * 替换字符串
36
- * @browser
37
- * @param text 替换的字符串
38
- */
39
- replaceData(text?: string): void;
40
- /** 复制 */
41
- cloneNode(): AstText;
42
- /**
43
- * 在后方添加字符串
44
- * @param text 添加的字符串
45
- */
46
- appendData(text: string): void;
47
- /**
48
- * 删减字符串
49
- * @param offset 起始位置
50
- * @param count 删减字符数
51
- */
52
- deleteData(offset: number, count: number): void;
53
- /**
54
- * 插入字符串
55
- * @param offset 插入位置
56
- * @param text 待插入的字符串
57
- */
58
- insertData(offset: number, text: string): void;
59
- /**
60
- * 提取子串
61
- * @param offset 起始位置
62
- * @param count 字符数
63
- */
64
- substringData(offset: number, count: number): string;
65
- /**
66
- * 将文本子节点分裂为两部分
67
- * @param offset 分裂位置
68
- * @throws `RangeError` 错误的断开位置
69
- * @throws `Error` 没有父节点
70
- */
71
- splitText(offset: number): AstText;
72
- /**
73
- * @override
74
- * @param j 字符位置
75
- * @throws `RangeError` 超出文本长度范围
76
- */
77
- getRelativeIndex(j?: number): number;
78
- }
package/dist/lib/text.js DELETED
@@ -1,227 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AstText = void 0;
4
- const index_1 = require("../index");
5
- const node_1 = require("./node");
6
- const errorSyntax = /https?:\/\/|\{+|\}+|\[{2,}|\[(?![^[]*\])|(?<=^|\])([^[]*?)\]+|\]{2,}|<\s*\/?([a-z]\w*)/giu, errorSyntaxUrl = /\{+|\}+|\[{2,}|\[(?![^[]*\])|(?<=^|\])([^[]*?)\]+|\]{2,}|<\s*\/?([a-z]\w*)/giu, disallowedTags = [
7
- 'html',
8
- 'base',
9
- 'head',
10
- 'style',
11
- 'title',
12
- 'body',
13
- 'menu',
14
- 'a',
15
- 'area',
16
- 'audio',
17
- 'img',
18
- 'map',
19
- 'track',
20
- 'video',
21
- 'embed',
22
- 'iframe',
23
- 'object',
24
- 'picture',
25
- 'source',
26
- 'canvas',
27
- 'script',
28
- 'col',
29
- 'colgroup',
30
- 'tbody',
31
- 'tfoot',
32
- 'thead',
33
- 'button',
34
- 'datalist',
35
- 'fieldset',
36
- 'form',
37
- 'input',
38
- 'label',
39
- 'legend',
40
- 'meter',
41
- 'optgroup',
42
- 'option',
43
- 'output',
44
- 'progress',
45
- 'select',
46
- 'textarea',
47
- 'details',
48
- 'dialog',
49
- 'slot',
50
- 'template',
51
- 'dir',
52
- 'frame',
53
- 'frameset',
54
- 'marquee',
55
- 'param',
56
- 'xmp',
57
- ];
58
- /** 文本节点 */
59
- class AstText extends node_1.AstNode {
60
- /** @browser */
61
- type = 'text';
62
- /** @browser */
63
- data;
64
- /** 文本长度 */
65
- get length() {
66
- return this.data.length;
67
- }
68
- /**
69
- * @browser
70
- * @param text 包含文本
71
- */
72
- constructor(text = '') {
73
- super();
74
- Object.defineProperties(this, {
75
- data: { value: text, writable: false },
76
- childNodes: { enumerable: false, configurable: false },
77
- type: { enumerable: false, writable: false, configurable: false },
78
- });
79
- }
80
- /**
81
- * 输出字符串
82
- * @browser
83
- */
84
- toString() {
85
- return this.data;
86
- }
87
- /**
88
- * 可见部分
89
- * @browser
90
- */
91
- text() {
92
- return this.data;
93
- }
94
- /**
95
- * Linter
96
- * @browser
97
- * @param start
98
- */
99
- lint(start = this.getAbsoluteIndex()) {
100
- const { data, parentNode, nextSibling, previousSibling } = this, type = parentNode?.type, name = parentNode?.name, nextType = nextSibling?.type, previousType = previousSibling?.type, errorRegex = type === 'free-ext-link' || type === 'ext-link-url' || type === 'image-parameter' && name === 'link'
101
- ? errorSyntaxUrl
102
- : errorSyntax, errors = [...data.matchAll(errorRegex)], { ext, html } = this.getRootNode().getAttribute('config');
103
- if (errors.length > 0) {
104
- const root = this.getRootNode(), { top, left } = root.posFromIndex(start), tags = new Set([ext, html, disallowedTags].flat(2));
105
- return errors
106
- .map(({ 0: error, 1: prefix, 2: tag, index }) => {
107
- if (prefix) {
108
- index += prefix.length;
109
- error = error.slice(prefix.length);
110
- }
111
- const startIndex = start + index, lines = data.slice(0, index).split('\n'), startLine = lines.length + top - 1, line = lines.at(-1), startCol = lines.length === 1 ? left + line.length : line.length, { 0: char, length } = error, endIndex = startIndex + length, end = char === '}' || char === ']' ? endIndex + 1 : startIndex + 49, rootStr = String(root), nextChar = rootStr[endIndex], previousChar = rootStr[startIndex - 1], severity = length > 1 && (char !== '<' || /[\s/>]/u.test(nextChar ?? ''))
112
- || char === '{' && (nextChar === char || previousChar === '-')
113
- || char === '}' && (previousChar === char || nextChar === '-')
114
- || char === '[' && (nextChar === char || type === 'ext-link-text'
115
- || !data.slice(index + 1).trim() && nextType === 'free-ext-link')
116
- || char === ']' && (previousChar === char
117
- || !data.slice(0, index).trim() && previousType === 'free-ext-link')
118
- ? 'error'
119
- : 'warning';
120
- return (char !== 'h' || index > 0) && (char !== '<' || tags.has(tag.toLowerCase())) && {
121
- message: index_1.default.msg('lonely "$1"', char === 'h' ? error : char),
122
- severity,
123
- startIndex,
124
- endIndex,
125
- startLine,
126
- endLine: startLine,
127
- startCol,
128
- endCol: startCol + length,
129
- excerpt: rootStr.slice(Math.max(0, end - 50), end),
130
- };
131
- }).filter(Boolean);
132
- }
133
- return [];
134
- }
135
- /**
136
- * 修改内容
137
- * @browser
138
- * @param text 新内容
139
- */
140
- #setData(text) {
141
- const { data } = this, e = new Event('text', { bubbles: true });
142
- this.setAttribute('data', text);
143
- if (data !== text) {
144
- this.dispatchEvent(e, { oldText: data, newText: text });
145
- }
146
- }
147
- /**
148
- * 替换字符串
149
- * @browser
150
- * @param text 替换的字符串
151
- */
152
- replaceData(text = '') {
153
- this.#setData(text);
154
- }
155
- /** 复制 */
156
- cloneNode() {
157
- return new AstText(this.data);
158
- }
159
- /**
160
- * 在后方添加字符串
161
- * @param text 添加的字符串
162
- */
163
- appendData(text) {
164
- this.#setData(this.data + text);
165
- }
166
- /**
167
- * 删减字符串
168
- * @param offset 起始位置
169
- * @param count 删减字符数
170
- */
171
- deleteData(offset, count) {
172
- this.#setData(this.data.slice(0, offset) + (offset < 0 && offset + count >= 0 ? '' : this.data.slice(offset + count)));
173
- }
174
- /**
175
- * 插入字符串
176
- * @param offset 插入位置
177
- * @param text 待插入的字符串
178
- */
179
- insertData(offset, text) {
180
- this.#setData(this.data.slice(0, offset) + text + this.data.slice(offset));
181
- }
182
- /**
183
- * 提取子串
184
- * @param offset 起始位置
185
- * @param count 字符数
186
- */
187
- substringData(offset, count) {
188
- return this.data.substr(offset, count);
189
- }
190
- /**
191
- * 将文本子节点分裂为两部分
192
- * @param offset 分裂位置
193
- * @throws `RangeError` 错误的断开位置
194
- * @throws `Error` 没有父节点
195
- */
196
- splitText(offset) {
197
- if (offset > this.length || offset < -this.length) {
198
- throw new RangeError(`错误的断开位置:${offset}`);
199
- }
200
- const { parentNode, data } = this;
201
- if (!parentNode) {
202
- throw new Error('待分裂的文本节点没有父节点!');
203
- }
204
- const newText = new AstText(data.slice(offset)), childNodes = [...parentNode.childNodes];
205
- this.setAttribute('data', data.slice(0, offset));
206
- childNodes.splice(childNodes.indexOf(this) + 1, 0, newText);
207
- newText.setAttribute('parentNode', parentNode);
208
- parentNode.setAttribute('childNodes', childNodes);
209
- return newText;
210
- }
211
- /**
212
- * @override
213
- * @param j 字符位置
214
- * @throws `RangeError` 超出文本长度范围
215
- */
216
- getRelativeIndex(j) {
217
- if (j === undefined) {
218
- return super.getRelativeIndex();
219
- }
220
- else if (j < 0 || j > this.length) {
221
- throw new RangeError(`超出文本长度范围!`);
222
- }
223
- return j;
224
- }
225
- }
226
- exports.AstText = AstText;
227
- index_1.default.classes['AstText'] = __filename;
@@ -1,33 +0,0 @@
1
- /** MediaWiki页面标题对象 */
2
- export declare class Title {
3
- /** @browser */
4
- valid: boolean;
5
- /** @browser */
6
- ns: number;
7
- /** @browser */
8
- fragment: string | undefined;
9
- /** @browser */
10
- encoded: boolean;
11
- main: string;
12
- prefix: string;
13
- interwiki: string;
14
- conversionTable: Map<string, string>;
15
- redirects: Map<string, string>;
16
- /** 完整标题 */
17
- get title(): string;
18
- /**
19
- * @browser
20
- * @param str 标题(含或不含命名空间前缀)
21
- * @param defaultNs 命名空间
22
- * @param decode 是否需要解码
23
- * @param selfLink 是否允许selfLink
24
- */
25
- constructor(str: string, defaultNs?: number, config?: import("../index").Config, decode?: boolean, selfLink?: boolean);
26
- /** 完整链接 */
27
- toString(): string;
28
- /**
29
- * 转换
30
- * @param conversionTable 单向转换表
31
- */
32
- autoConvert(): void;
33
- }
package/dist/lib/title.js DELETED
@@ -1,110 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Title = void 0;
4
- const string_1 = require("../util/string");
5
- const index_1 = require("../index");
6
- /** MediaWiki页面标题对象 */
7
- class Title {
8
- /** @browser */
9
- valid = true;
10
- /** @browser */
11
- ns = 0;
12
- /** @browser */
13
- fragment;
14
- /** @browser */
15
- encoded = false;
16
- main = '';
17
- prefix = '';
18
- interwiki = '';
19
- conversionTable = new Map();
20
- redirects = new Map();
21
- /** 完整标题 */
22
- get title() {
23
- let title = `${this.interwiki && `${this.interwiki}:`}${this.prefix}${this.main.replaceAll(' ', '_')}`;
24
- const redirected = this.redirects.get(title);
25
- if (redirected) {
26
- return redirected;
27
- }
28
- this.autoConvert();
29
- title = `${this.interwiki && `${this.interwiki}:`}${this.prefix}${this.main.replaceAll(' ', '_')}`;
30
- return this.redirects.get(title) ?? title;
31
- }
32
- /**
33
- * @browser
34
- * @param str 标题(含或不含命名空间前缀)
35
- * @param defaultNs 命名空间
36
- * @param decode 是否需要解码
37
- * @param selfLink 是否允许selfLink
38
- */
39
- constructor(str, defaultNs = 0, config = index_1.default.getConfig(), decode = false, selfLink = false) {
40
- const { namespaces, nsid } = config;
41
- let namespace = namespaces[defaultNs], title = (0, string_1.decodeHtml)(str);
42
- if (decode && title.includes('%')) {
43
- try {
44
- const encoded = /%(?!21|3[ce]|5[bd]|7[b-d])[\da-f]{2}/iu.test(title);
45
- title = decodeURIComponent(title);
46
- this.encoded = encoded;
47
- }
48
- catch { }
49
- }
50
- title = title.replaceAll('_', ' ').trim();
51
- if (title.startsWith(':')) {
52
- namespace = '';
53
- title = title.slice(1).trim();
54
- }
55
- const iw = defaultNs ? undefined : index_1.default.isInterwiki(title, config);
56
- if (iw) {
57
- this.interwiki = iw[1].toLowerCase();
58
- title = title.slice(iw[0].length);
59
- }
60
- const m = title.split(':');
61
- if (m.length > 1) {
62
- const ns = nsid[m[0].trim().toLowerCase()], id = ns === undefined ? undefined : namespaces[ns];
63
- if (id !== undefined) {
64
- namespace = id;
65
- title = m.slice(1).join(':').trim();
66
- }
67
- }
68
- this.ns = nsid[namespace.toLowerCase()];
69
- const i = title.indexOf('#');
70
- let fragment;
71
- if (i !== -1) {
72
- fragment = title.slice(i + 1).trimEnd();
73
- if (fragment.includes('%')) {
74
- try {
75
- fragment = decodeURIComponent(fragment);
76
- }
77
- catch { }
78
- }
79
- else if (fragment.includes('.')) {
80
- try {
81
- fragment = decodeURIComponent(fragment.replaceAll('.', '%'));
82
- }
83
- catch { }
84
- }
85
- title = title.slice(0, i).trim();
86
- }
87
- this.valid = Boolean(title || selfLink && fragment !== undefined || this.interwiki)
88
- && !/\0\d+[eh!+-]\x7F|[<>[\]{}|]|%[\da-f]{2}/iu.test(title);
89
- this.fragment = fragment;
90
- this.main = title && `${title[0].toUpperCase()}${title.slice(1)}`;
91
- this.prefix = `${namespace}${namespace && ':'}`;
92
- }
93
- /** 完整链接 */
94
- toString() {
95
- return `${this.title}${this.fragment === undefined ? '' : `#${this.fragment}`}`;
96
- }
97
- /**
98
- * 转换
99
- * @param conversionTable 单向转换表
100
- */
101
- autoConvert() {
102
- const { conversionTable } = this;
103
- if (conversionTable.size > 0) {
104
- const regex = new RegExp([...conversionTable.keys()].sort().reverse().map(string_1.escapeRegExp).join('|'), 'gu');
105
- this.main = this.main.replace(regex, p => conversionTable.get(p));
106
- }
107
- }
108
- }
109
- exports.Title = Title;
110
- index_1.default.classes['Title'] = __filename;
@@ -1,93 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.attributesParent = void 0;
4
- const index_1 = require("../index");
5
- /**
6
- * 子节点含有AttributesToken的类
7
- * @param constructor 基类
8
- * @param i AttributesToken子节点的位置
9
- */
10
- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
11
- const attributesParent = (constructor, i = 0) => {
12
- /** 子节点含有AttributesToken的类 */
13
- class AttributesParent extends constructor {
14
- /** AttributesToken子节点 */
15
- get #attributesChild() {
16
- return this.childNodes.at(i);
17
- }
18
- /** getAttrs()方法的getter写法 */
19
- get attributes() {
20
- return this.#attributesChild.attributes;
21
- }
22
- /** 以字符串表示的class属性 */
23
- get className() {
24
- return this.#attributesChild.className;
25
- }
26
- set className(className) {
27
- this.#attributesChild.className = className;
28
- }
29
- /** 以Set表示的class属性 */
30
- get classList() {
31
- return this.#attributesChild.classList;
32
- }
33
- /** id属性 */
34
- get id() {
35
- return this.#attributesChild.id;
36
- }
37
- set id(id) {
38
- this.#attributesChild.id = id;
39
- }
40
- /**
41
- * AttributesToken子节点是否具有某属性
42
- * @param key 属性键
43
- */
44
- hasAttr(key) {
45
- return this.#attributesChild.hasAttr(key);
46
- }
47
- /**
48
- * 获取AttributesToken子节点的属性
49
- * @param key 属性键
50
- */
51
- getAttr(key) {
52
- return this.#attributesChild.getAttr(key);
53
- }
54
- /** 列举AttributesToken子节点的属性键 */
55
- getAttrNames() {
56
- return this.#attributesChild.getAttrNames();
57
- }
58
- /** AttributesToken子节点是否具有任意属性 */
59
- hasAttrs() {
60
- return this.#attributesChild.hasAttrs();
61
- }
62
- /** 获取AttributesToken子节点的全部标签属性 */
63
- getAttrs() {
64
- return this.#attributesChild.getAttrs();
65
- }
66
- /**
67
- * 对AttributesToken子节点设置属性
68
- * @param key 属性键
69
- * @param value 属性值
70
- */
71
- setAttr(key, value) {
72
- this.#attributesChild.setAttr(key, value);
73
- }
74
- /**
75
- * 移除AttributesToken子节点的某属性
76
- * @param key 属性键
77
- */
78
- removeAttr(key) {
79
- this.#attributesChild.removeAttr(key);
80
- }
81
- /**
82
- * 开关AttributesToken子节点的某属性
83
- * @param key 属性键
84
- * @param force 强制开启或关闭
85
- */
86
- toggleAttr(key, force) {
87
- this.#attributesChild.toggleAttr(key, force);
88
- }
89
- }
90
- return AttributesParent;
91
- };
92
- exports.attributesParent = attributesParent;
93
- index_1.default.mixins['attributesParent'] = __filename;
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fixed = void 0;
4
- const index_1 = require("../index");
5
- /**
6
- * 不可增删子节点的类
7
- * @param constructor 基类
8
- */
9
- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
10
- const fixed = (constructor) => {
11
- /** 不可增删子节点的类 */
12
- class FixedToken extends constructor {
13
- static fixed = true;
14
- /**
15
- * @override
16
- * @throws `Error` 不可用
17
- */
18
- removeAt() {
19
- throw new Error(`${this.constructor.name} 不可删除元素!`);
20
- }
21
- /** @ignore */
22
- insertAt(token, i = this.length) {
23
- if (index_1.default.running) {
24
- return super.insertAt(token, i);
25
- }
26
- throw new Error(`${this.constructor.name} 不可插入元素!`);
27
- }
28
- }
29
- return FixedToken;
30
- };
31
- exports.fixed = fixed;
32
- index_1.default.mixins['fixed'] = __filename;
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hidden = void 0;
4
- const index_1 = require("../index");
5
- /**
6
- * 解析后不可见的类
7
- * @param constructor 基类
8
- */
9
- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
10
- const hidden = (constructor) => {
11
- /** 解析后不可见的类 */
12
- class AnyHiddenToken extends constructor {
13
- static hidden = true;
14
- /** 没有可见部分 */
15
- // eslint-disable-next-line class-methods-use-this
16
- text() {
17
- return '';
18
- }
19
- }
20
- return AnyHiddenToken;
21
- };
22
- exports.hidden = hidden;
23
- index_1.default.mixins['hidden'] = __filename;
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.singleLine = void 0;
4
- const index_1 = require("../index");
5
- /**
6
- * 不可包含换行符的类
7
- * @param constructor 基类
8
- */
9
- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
10
- const singleLine = (constructor) => {
11
- /** 不可包含换行符的类 */
12
- class SingleLineToken extends constructor {
13
- /** @override */
14
- toString(selector) {
15
- return super.toString(selector).replaceAll('\n', ' ');
16
- }
17
- /** @override */
18
- text() {
19
- return super.text().replaceAll('\n', ' ');
20
- }
21
- }
22
- Object.defineProperty(SingleLineToken, 'name', { value: `SingleLine${constructor.name}` });
23
- return SingleLineToken;
24
- };
25
- exports.singleLine = singleLine;
26
- index_1.default.mixins['singleLine'] = __filename;
package/dist/mixin/sol.js DELETED
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sol = void 0;
4
- const index_1 = require("../index");
5
- /**
6
- * 只能位于行首的类
7
- * @param constructor 基类
8
- */
9
- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
10
- const sol = (constructor) => {
11
- /** 只能位于行首的类 */
12
- class SolToken extends constructor {
13
- /** 是否可以视为root节点 */
14
- #isRoot() {
15
- const { parentNode, type } = this;
16
- return parentNode?.type === 'root'
17
- || type !== 'heading' && parentNode?.type === 'ext-inner' && parentNode.name === 'poem';
18
- }
19
- /** 在前方插入newline */
20
- prependNewLine() {
21
- const { previousVisibleSibling } = this;
22
- return (previousVisibleSibling ?? !this.#isRoot()) && !String(previousVisibleSibling).endsWith('\n')
23
- ? '\n'
24
- : '';
25
- }
26
- /** @override */
27
- toString(selector) {
28
- return selector && this.matches(selector)
29
- ? ''
30
- : `${this.prependNewLine()}${super.toString(selector)}`;
31
- }
32
- /** @override */
33
- getPadding() {
34
- return this.prependNewLine().length;
35
- }
36
- /** @override */
37
- text() {
38
- return `${this.prependNewLine()}${super.text()}`;
39
- }
40
- }
41
- return SolToken;
42
- };
43
- exports.sol = sol;
44
- index_1.default.mixins['sol'] = __filename;