wikiparser-node 1.26.0 → 1.28.0
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/bundle/bundle-es8.min.js +25 -25
- package/bundle/bundle-lsp.min.js +30 -30
- package/bundle/bundle.min.js +24 -25
- package/coverage/badge.svg +1 -1
- package/data/.schema.json +2 -1
- package/data/signatures.json +82 -16
- package/dist/addon/token.js +1 -1
- package/dist/base.d.mts +3 -3
- package/dist/base.d.ts +3 -3
- package/dist/bin/config.js +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -3
- package/dist/internal.d.ts +5 -5
- package/dist/lib/document.js +6 -0
- package/dist/lib/lintConfig.js +19 -12
- package/dist/lib/lsp.d.ts +1 -1
- package/dist/lib/lsp.js +1 -1
- package/dist/lib/node.js +51 -40
- package/dist/lib/text.js +3 -3
- package/dist/mixin/attributesParent.js +59 -57
- package/dist/mixin/elementLike.js +77 -75
- package/dist/mixin/hidden.js +3 -3
- package/dist/mixin/nodeLike.js +2 -2
- package/dist/mixin/padded.js +9 -7
- package/dist/mixin/singleLine.d.ts +1 -1
- package/dist/mixin/singleLine.js +10 -11
- package/dist/parser/commentAndExt.js +1 -1
- package/dist/parser/html.js +1 -1
- package/dist/parser/selector.js +2 -1
- package/dist/src/arg.js +2 -2
- package/dist/src/atom.d.ts +1 -1
- package/dist/src/atom.js +0 -1
- package/dist/src/attribute.d.ts +5 -7
- package/dist/src/attribute.js +32 -23
- package/dist/src/attributes.d.ts +7 -8
- package/dist/src/attributes.js +5 -3
- package/dist/src/commented.d.ts +3 -3
- package/dist/src/converterRule.js +1 -1
- package/dist/src/heading.js +1 -1
- package/dist/src/imageParameter.d.ts +0 -8
- package/dist/src/imageParameter.js +12 -8
- package/dist/src/imagemapLink.js +1 -1
- package/dist/src/index.d.ts +0 -5
- package/dist/src/index.js +3 -6
- package/dist/src/link/base.js +1 -2
- package/dist/src/link/category.js +1 -2
- package/dist/src/link/file.js +17 -9
- package/dist/src/link/galleryImage.d.ts +0 -3
- package/dist/src/link/galleryImage.js +3 -2
- package/dist/src/link/index.js +1 -1
- package/dist/src/magicLink.d.ts +0 -7
- package/dist/src/multiLine/gallery.d.ts +49 -0
- package/dist/src/{gallery.js → multiLine/gallery.js} +24 -37
- package/dist/src/multiLine/imagemap.d.ts +25 -0
- package/dist/src/{imagemap.js → multiLine/imagemap.js} +20 -36
- package/dist/src/multiLine/index.d.ts +17 -0
- package/dist/src/multiLine/index.js +36 -0
- package/dist/src/{paramTag → multiLine}/inputbox.d.ts +1 -1
- package/dist/src/{paramTag → multiLine}/inputbox.js +2 -2
- package/dist/src/multiLine/paramTag.d.ts +20 -0
- package/dist/src/{paramTag/index.js → multiLine/paramTag.js} +10 -24
- package/dist/src/nowiki/base.d.ts +1 -1
- package/dist/src/nowiki/comment.js +3 -1
- package/dist/src/nowiki/commentLine.d.ts +11 -0
- package/dist/src/nowiki/commentLine.js +67 -0
- package/dist/src/nowiki/listBase.js +1 -2
- package/dist/src/nowiki/noinclude.d.ts +6 -0
- package/dist/src/nowiki/noinclude.js +19 -4
- package/dist/src/nowiki/quote.js +2 -2
- package/dist/src/paramLine.d.ts +17 -0
- package/dist/src/paramLine.js +83 -0
- package/dist/src/parameter.d.ts +0 -1
- package/dist/src/parameter.js +2 -1
- package/dist/src/pre.d.ts +6 -8
- package/dist/src/pre.js +3 -2
- package/dist/src/syntax.d.ts +1 -1
- package/dist/src/table/base.d.ts +6 -1
- package/dist/src/table/base.js +96 -46
- package/dist/src/table/index.js +71 -67
- package/dist/src/table/td.d.ts +2 -2
- package/dist/src/table/td.js +8 -7
- package/dist/src/table/tr.d.ts +2 -2
- package/dist/src/table/trBase.d.ts +0 -5
- package/dist/src/table/trBase.js +4 -5
- package/dist/src/{html.d.ts → tag/html.d.ts} +6 -22
- package/dist/src/{html.js → tag/html.js} +43 -131
- package/dist/src/tag/index.d.ts +44 -0
- package/dist/src/tag/index.js +214 -0
- package/dist/src/tag/tvar.d.ts +38 -0
- package/dist/src/tag/tvar.js +169 -0
- package/dist/src/tagPair/ext.js +4 -4
- package/dist/src/tagPair/include.js +1 -1
- package/dist/src/tagPair/index.d.ts +1 -1
- package/dist/src/tagPair/index.js +1 -0
- package/dist/src/tagPair/translate.js +10 -10
- package/dist/src/transclude.d.ts +8 -9
- package/dist/src/transclude.js +8 -5
- package/dist/util/constants.js +1 -1
- package/dist/util/html.js +2 -1
- package/extensions/dist/base.js +1 -1
- package/extensions/ui.css +1 -1
- package/i18n/en.json +14 -13
- package/i18n/zh-hans.json +19 -18
- package/i18n/zh-hant.json +31 -30
- package/package.json +2 -2
- package/dist/mixin/multiLine.d.ts +0 -4
- package/dist/mixin/multiLine.js +0 -33
- package/dist/src/gallery.d.ts +0 -66
- package/dist/src/imagemap.d.ts +0 -49
- package/dist/src/paramTag/index.d.ts +0 -28
package/dist/src/nowiki/quote.js
CHANGED
|
@@ -89,7 +89,7 @@ let QuoteToken = (() => {
|
|
|
89
89
|
* @since v1.16.5
|
|
90
90
|
*/
|
|
91
91
|
get closing() {
|
|
92
|
-
return {
|
|
92
|
+
LINT: return {
|
|
93
93
|
...this.bold ? { bold: this.#closing.bold } : undefined,
|
|
94
94
|
...this.italic ? { italic: this.#closing.italic } : undefined,
|
|
95
95
|
};
|
|
@@ -147,8 +147,8 @@ let QuoteToken = (() => {
|
|
|
147
147
|
}
|
|
148
148
|
/** @private */
|
|
149
149
|
json(_, start = this.getAbsoluteIndex()) {
|
|
150
|
-
const json = super.json(undefined, start);
|
|
151
150
|
LSP: { // eslint-disable-line no-unused-labels
|
|
151
|
+
const json = super.json(undefined, start);
|
|
152
152
|
Object.assign(json, { bold: this.bold, italic: this.italic });
|
|
153
153
|
return json;
|
|
154
154
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Token } from './index';
|
|
2
|
+
import type { ParamTagToken } from '../internal';
|
|
3
|
+
/**
|
|
4
|
+
* parameter of certain extension tags
|
|
5
|
+
*
|
|
6
|
+
* 某些扩展标签的参数
|
|
7
|
+
*/
|
|
8
|
+
export declare abstract class ParamLineToken extends Token {
|
|
9
|
+
abstract get parentNode(): ParamTagToken | undefined;
|
|
10
|
+
abstract get nextSibling(): this | undefined;
|
|
11
|
+
abstract get previousSibling(): this | undefined;
|
|
12
|
+
abstract get parentElement(): ParamTagToken | undefined;
|
|
13
|
+
abstract get nextElementSibling(): this | undefined;
|
|
14
|
+
abstract get previousElementSibling(): this | undefined;
|
|
15
|
+
get type(): 'param-line';
|
|
16
|
+
cloneNode(): this;
|
|
17
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
};
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.ParamLineToken = void 0;
|
|
38
|
+
const index_1 = require("./index");
|
|
39
|
+
/* NOT FOR BROWSER */
|
|
40
|
+
const singleLine_1 = require("../mixin/singleLine");
|
|
41
|
+
const clone_1 = require("../mixin/clone");
|
|
42
|
+
/* NOT FOR BROWSER END */
|
|
43
|
+
/**
|
|
44
|
+
* parameter of certain extension tags
|
|
45
|
+
*
|
|
46
|
+
* 某些扩展标签的参数
|
|
47
|
+
*/
|
|
48
|
+
let ParamLineToken = (() => {
|
|
49
|
+
let _classDecorators = [singleLine_1.singleLine];
|
|
50
|
+
let _classDescriptor;
|
|
51
|
+
let _classExtraInitializers = [];
|
|
52
|
+
let _classThis;
|
|
53
|
+
let _classSuper = index_1.Token;
|
|
54
|
+
let _instanceExtraInitializers = [];
|
|
55
|
+
let _cloneNode_decorators;
|
|
56
|
+
var ParamLineToken = class extends _classSuper {
|
|
57
|
+
static { _classThis = this; }
|
|
58
|
+
static {
|
|
59
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
60
|
+
_cloneNode_decorators = [clone_1.clone];
|
|
61
|
+
__esDecorate(this, null, _cloneNode_decorators, { kind: "method", name: "cloneNode", static: false, private: false, access: { has: obj => "cloneNode" in obj, get: obj => obj.cloneNode }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
62
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
63
|
+
ParamLineToken = _classThis = _classDescriptor.value;
|
|
64
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
65
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
66
|
+
}
|
|
67
|
+
/* NOT FOR BROWSER END */
|
|
68
|
+
get type() {
|
|
69
|
+
return 'param-line';
|
|
70
|
+
}
|
|
71
|
+
/* NOT FOR BROWSER */
|
|
72
|
+
cloneNode() {
|
|
73
|
+
// @ts-expect-error abstract class
|
|
74
|
+
return new ParamLineToken(undefined, this.getAttribute('config'), [], this.getAcceptable());
|
|
75
|
+
}
|
|
76
|
+
constructor() {
|
|
77
|
+
super(...arguments);
|
|
78
|
+
__runInitializers(this, _instanceExtraInitializers);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
return ParamLineToken = _classThis;
|
|
82
|
+
})();
|
|
83
|
+
exports.ParamLineToken = ParamLineToken;
|
package/dist/src/parameter.d.ts
CHANGED
|
@@ -36,7 +36,6 @@ export declare abstract class ParameterToken extends Token {
|
|
|
36
36
|
* @param value 参数值
|
|
37
37
|
*/
|
|
38
38
|
constructor(key?: string | number, value?: string, config?: Config, accum?: Token[]);
|
|
39
|
-
text(): string;
|
|
40
39
|
cloneNode(): this;
|
|
41
40
|
safeReplaceWith(token: this): void;
|
|
42
41
|
/**
|
package/dist/src/parameter.js
CHANGED
|
@@ -168,6 +168,7 @@ let ParameterToken = (() => {
|
|
|
168
168
|
toString(skip) {
|
|
169
169
|
return this.anon ? this.lastChild.toString(skip) : super.toString(skip, '=');
|
|
170
170
|
}
|
|
171
|
+
/** @private */
|
|
171
172
|
text() {
|
|
172
173
|
return this.anon ? this.lastChild.text() : super.text('=');
|
|
173
174
|
}
|
|
@@ -206,8 +207,8 @@ let ParameterToken = (() => {
|
|
|
206
207
|
}
|
|
207
208
|
/** @private */
|
|
208
209
|
json(_, start = this.getAbsoluteIndex()) {
|
|
209
|
-
const json = super.json(undefined, start);
|
|
210
210
|
LSP: { // eslint-disable-line no-unused-labels
|
|
211
|
+
const json = super.json(undefined, start);
|
|
211
212
|
Object.assign(json, { anon: this.anon }, this.duplicated && { duplicated: true });
|
|
212
213
|
return json;
|
|
213
214
|
}
|
package/dist/src/pre.d.ts
CHANGED
|
@@ -2,22 +2,21 @@ import { Token } from './index';
|
|
|
2
2
|
import { NoincludeToken } from './nowiki/noinclude';
|
|
3
3
|
import type { Config, LintError } from '../base';
|
|
4
4
|
import type { AstText, AttributesToken, ExtToken, ConverterToken } from '../internal';
|
|
5
|
-
declare type Child = NoincludeToken | ConverterToken;
|
|
6
5
|
/**
|
|
7
6
|
* `<pre>`
|
|
8
7
|
* @classdesc `{childNodes: (AstText|NoincludeToken|ConverterToken)[]}`
|
|
9
8
|
*/
|
|
10
9
|
export declare abstract class PreToken extends Token {
|
|
11
10
|
readonly name: 'pre';
|
|
12
|
-
readonly childNodes: readonly (
|
|
13
|
-
abstract get firstChild():
|
|
14
|
-
abstract get lastChild():
|
|
11
|
+
readonly childNodes: readonly (NoincludeToken | ConverterToken | AstText)[];
|
|
12
|
+
abstract get firstChild(): NoincludeToken | ConverterToken | AstText | undefined;
|
|
13
|
+
abstract get lastChild(): NoincludeToken | ConverterToken | AstText | undefined;
|
|
15
14
|
abstract get nextSibling(): undefined;
|
|
16
15
|
abstract get previousSibling(): AttributesToken | undefined;
|
|
17
16
|
abstract get parentNode(): ExtToken | undefined;
|
|
18
|
-
abstract get children():
|
|
19
|
-
abstract get firstElementChild():
|
|
20
|
-
abstract get lastElementChild():
|
|
17
|
+
abstract get children(): (NoincludeToken | ConverterToken)[];
|
|
18
|
+
abstract get firstElementChild(): NoincludeToken | ConverterToken | undefined;
|
|
19
|
+
abstract get lastElementChild(): NoincludeToken | ConverterToken | undefined;
|
|
21
20
|
abstract get previousElementSibling(): AttributesToken | undefined;
|
|
22
21
|
abstract get nextElementSibling(): undefined;
|
|
23
22
|
abstract get parentElement(): ExtToken | undefined;
|
|
@@ -26,4 +25,3 @@ export declare abstract class PreToken extends Token {
|
|
|
26
25
|
constructor(wikitext?: string, config?: Config, accum?: Token[]);
|
|
27
26
|
cloneNode(): this;
|
|
28
27
|
}
|
|
29
|
-
export {};
|
package/dist/src/pre.js
CHANGED
|
@@ -40,6 +40,7 @@ const index_1 = require("./index");
|
|
|
40
40
|
const noinclude_1 = require("./nowiki/noinclude");
|
|
41
41
|
/* NOT FOR BROWSER */
|
|
42
42
|
const clone_1 = require("../mixin/clone");
|
|
43
|
+
/* NOT FOR BROWSER END */
|
|
43
44
|
/**
|
|
44
45
|
* `<pre>`
|
|
45
46
|
* @classdesc `{childNodes: (AstText|NoincludeToken|ConverterToken)[]}`
|
|
@@ -70,9 +71,9 @@ let PreToken = (() => {
|
|
|
70
71
|
let j = closing.exec(wikitext), lastIndex = 0, str = '';
|
|
71
72
|
while (i && j) {
|
|
72
73
|
// @ts-expect-error abstract class
|
|
73
|
-
new noinclude_1.NoincludeToken(i[0], config, accum);
|
|
74
|
+
new noinclude_1.NoincludeToken(i[0], config, accum, true);
|
|
74
75
|
// @ts-expect-error abstract class
|
|
75
|
-
new noinclude_1.NoincludeToken(j[0], config, accum);
|
|
76
|
+
new noinclude_1.NoincludeToken(j[0], config, accum, true);
|
|
76
77
|
str += `${wikitext.slice(lastIndex, i.index)}\0${accum.length - 1}n\x7F${wikitext.slice(i.index + length, j.index)}\0${accum.length}n\x7F`;
|
|
77
78
|
lastIndex = j.index + length + 1;
|
|
78
79
|
opening.lastIndex = lastIndex;
|
package/dist/src/syntax.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { Config, LintError } from '../base';
|
|
|
3
3
|
import type { SyntaxBase } from '../mixin/syntax';
|
|
4
4
|
export interface SyntaxToken extends SyntaxBase {
|
|
5
5
|
}
|
|
6
|
-
declare type SyntaxTypes = 'heading-trail' | 'magic-word-name' | 'table-syntax' | 'redirect-syntax' | 'translate-attr';
|
|
6
|
+
declare type SyntaxTypes = 'heading-trail' | 'magic-word-name' | 'table-syntax' | 'redirect-syntax' | 'translate-attr' | 'tvar-name';
|
|
7
7
|
/**
|
|
8
8
|
* plain token that satisfies specific grammar syntax
|
|
9
9
|
*
|
package/dist/src/table/base.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import Parser from '../../index';
|
|
2
1
|
import { Token } from '../index';
|
|
3
2
|
import { SyntaxToken } from '../syntax';
|
|
4
3
|
import { AttributesToken } from '../attributes';
|
|
@@ -7,6 +6,12 @@ import type { AttributesParentBase } from '../../mixin/attributesParent';
|
|
|
7
6
|
declare type TableTypes = 'table' | 'tr' | 'td';
|
|
8
7
|
export interface TableBaseToken extends AttributesParentBase {
|
|
9
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* table row that contains the newline at the beginning but not at the end
|
|
11
|
+
*
|
|
12
|
+
* 表格行,含开头的换行,不含结尾的换行
|
|
13
|
+
* @classdesc `{childNodes: [SyntaxToken, AttributesToken, ...Token[]]}`
|
|
14
|
+
*/
|
|
10
15
|
export declare abstract class TableBaseToken extends Token {
|
|
11
16
|
abstract get type(): TableTypes;
|
|
12
17
|
readonly childNodes: readonly [SyntaxToken, AttributesToken, ...Token[]];
|
package/dist/src/table/base.js
CHANGED
|
@@ -1,4 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
5
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
6
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
7
|
+
var _, done = false;
|
|
8
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
9
|
+
var context = {};
|
|
10
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
11
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
12
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
13
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
14
|
+
if (kind === "accessor") {
|
|
15
|
+
if (result === void 0) continue;
|
|
16
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
17
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
18
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
19
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
20
|
+
}
|
|
21
|
+
else if (_ = accept(result)) {
|
|
22
|
+
if (kind === "field") initializers.unshift(_);
|
|
23
|
+
else descriptor[key] = _;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
|
+
done = true;
|
|
28
|
+
};
|
|
29
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
30
|
+
var useValue = arguments.length > 2;
|
|
31
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
32
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
+
}
|
|
34
|
+
return useValue ? value : void 0;
|
|
35
|
+
};
|
|
2
36
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
37
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
38
|
};
|
|
@@ -30,58 +64,74 @@ const escapeTable = (syntax) => {
|
|
|
30
64
|
* 表格行,含开头的换行,不含结尾的换行
|
|
31
65
|
* @classdesc `{childNodes: [SyntaxToken, AttributesToken, ...Token[]]}`
|
|
32
66
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
67
|
+
let TableBaseToken = (() => {
|
|
68
|
+
let _classDecorators = [(0, attributesParent_1.attributesParent)(1)];
|
|
69
|
+
let _classDescriptor;
|
|
70
|
+
let _classExtraInitializers = [];
|
|
71
|
+
let _classThis;
|
|
72
|
+
let _classSuper = index_2.Token;
|
|
73
|
+
var TableBaseToken = class extends _classSuper {
|
|
74
|
+
static { _classThis = this; }
|
|
75
|
+
static {
|
|
76
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
77
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
78
|
+
TableBaseToken = _classThis = _classDescriptor.value;
|
|
79
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
80
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
81
|
+
}
|
|
82
|
+
/* NOT FOR BROWSER END */
|
|
83
|
+
/**
|
|
84
|
+
* @param pattern 表格语法正则
|
|
85
|
+
* @param syntax 表格语法
|
|
86
|
+
* @param type 节点类型
|
|
87
|
+
* @param attr 表格属性
|
|
88
|
+
*/
|
|
89
|
+
constructor(pattern, syntax, type, attr, config, accum = [], acceptable) {
|
|
90
|
+
super(undefined, config, accum, acceptable);
|
|
91
|
+
this.append(new syntax_1.SyntaxToken(syntax, pattern, 'table-syntax', config, accum, { 'Stage-1': ':', '!ExtToken': '', TranscludeToken: ':' }),
|
|
92
|
+
// @ts-expect-error abstract class
|
|
93
|
+
new attributes_1.AttributesToken(attr, 'table-attrs', type, config, accum));
|
|
94
|
+
/* NOT FOR BROWSER */
|
|
95
|
+
this.protectChildren([0, 1]);
|
|
96
|
+
}
|
|
97
|
+
escape() {
|
|
98
|
+
LSP: { // eslint-disable-line no-unused-labels
|
|
99
|
+
for (const child of this.childNodes) {
|
|
100
|
+
if (child instanceof syntax_1.SyntaxToken) {
|
|
101
|
+
escapeTable(child);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
child.escape();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
46
109
|
/* NOT FOR BROWSER */
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
110
|
+
cloneNode() {
|
|
111
|
+
const [syntax, attr, ...cloned] = this.cloneChildNodes();
|
|
112
|
+
return debug_1.Shadow.run(() => {
|
|
113
|
+
const C = this.constructor, token = new C(undefined, undefined, this.getAttribute('config'));
|
|
114
|
+
token.firstChild.safeReplaceWith(syntax);
|
|
115
|
+
token.childNodes[1].safeReplaceWith(attr);
|
|
116
|
+
if (token.is('td')) { // TdToken
|
|
117
|
+
token.childNodes[2].safeReplaceWith(cloned[0]);
|
|
54
118
|
}
|
|
55
119
|
else {
|
|
56
|
-
|
|
120
|
+
token.safeAppend(cloned);
|
|
57
121
|
}
|
|
58
|
-
|
|
122
|
+
return token;
|
|
123
|
+
});
|
|
59
124
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
token.firstChild.safeReplaceWith(syntax);
|
|
67
|
-
token.childNodes[1].safeReplaceWith(attr);
|
|
68
|
-
if (token.is('td')) { // TdToken
|
|
69
|
-
token.childNodes[2].safeReplaceWith(cloned[0]);
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
token.safeAppend(cloned);
|
|
125
|
+
/** @private */
|
|
126
|
+
setSyntax(syntax, esc) {
|
|
127
|
+
const { firstChild } = this;
|
|
128
|
+
firstChild.replaceChildren(syntax);
|
|
129
|
+
if (esc) {
|
|
130
|
+
escapeTable(firstChild);
|
|
73
131
|
}
|
|
74
|
-
return token;
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
/** @private */
|
|
78
|
-
setSyntax(syntax, esc) {
|
|
79
|
-
const { firstChild } = this;
|
|
80
|
-
firstChild.replaceChildren(syntax);
|
|
81
|
-
if (esc) {
|
|
82
|
-
escapeTable(firstChild);
|
|
83
132
|
}
|
|
84
|
-
}
|
|
85
|
-
|
|
133
|
+
};
|
|
134
|
+
return TableBaseToken = _classThis;
|
|
135
|
+
})();
|
|
86
136
|
exports.TableBaseToken = TableBaseToken;
|
|
87
137
|
constants_1.classes['TableBaseToken'] = __filename;
|
package/dist/src/table/index.js
CHANGED
|
@@ -117,7 +117,7 @@ let TableToken = (() => {
|
|
|
117
117
|
}
|
|
118
118
|
/** whether the table is closed / 表格是否闭合 */
|
|
119
119
|
get closed() {
|
|
120
|
-
return this.lastChild.is('table-syntax');
|
|
120
|
+
LINT: return this.lastChild.is('table-syntax'); // eslint-disable-line no-unused-labels
|
|
121
121
|
}
|
|
122
122
|
/* NOT FOR BROWSER */
|
|
123
123
|
set closed(closed) {
|
|
@@ -141,7 +141,7 @@ let TableToken = (() => {
|
|
|
141
141
|
LINT: { // eslint-disable-line no-unused-labels
|
|
142
142
|
const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start), rules = ['unclosed-table', 'table-layout'], s = rules.map(rule => index_1.default.lintConfig.getSeverity(rule));
|
|
143
143
|
if (s[0] && !this.closed) {
|
|
144
|
-
errors.push((0, lint_1.generateForChild)(this.firstChild, rect, rules[0],
|
|
144
|
+
errors.push((0, lint_1.generateForChild)(this.firstChild, rect, rules[0], 'unclosed-table', s[0]));
|
|
145
145
|
}
|
|
146
146
|
if (s[1]) {
|
|
147
147
|
const layout = this.getLayout(), { length } = layout;
|
|
@@ -210,50 +210,52 @@ let TableToken = (() => {
|
|
|
210
210
|
* @param stop.y stop at the column / 中止列
|
|
211
211
|
*/
|
|
212
212
|
getLayout(stop) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
if (cell.
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
if (last) {
|
|
228
|
-
const coords = { row: i, column: j }, { rowspan, colspan } = cell;
|
|
229
|
-
j++;
|
|
230
|
-
while (rowLayout[k]) {
|
|
231
|
-
k++;
|
|
232
|
-
}
|
|
233
|
-
/* NOT FOR BROWSER */
|
|
234
|
-
if (i === stop?.row && j > stop.column) {
|
|
235
|
-
rowLayout[k] = coords;
|
|
236
|
-
return layout;
|
|
213
|
+
LINT: { // eslint-disable-line no-unused-labels
|
|
214
|
+
const rows = this.getAllRows(), { length } = rows, layout = Layout.from(emptyArray(length, () => []));
|
|
215
|
+
for (let i = 0; i < layout.length; i++) {
|
|
216
|
+
const rowLayout = layout[i];
|
|
217
|
+
/* NOT FOR BROWSER */
|
|
218
|
+
if (i > (stop?.row ?? stop?.y ?? NaN)) {
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
/* NOT FOR BROWSER END */
|
|
222
|
+
let j = 0, k = 0, last;
|
|
223
|
+
for (const cell of rows[i].childNodes.slice(2)) {
|
|
224
|
+
if (cell.is('td')) {
|
|
225
|
+
if (cell.isIndependent()) {
|
|
226
|
+
last = cell.subtype !== 'caption';
|
|
237
227
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
228
|
+
if (last) {
|
|
229
|
+
const coords = { row: i, column: j }, { rowspan, colspan } = cell;
|
|
230
|
+
j++;
|
|
231
|
+
while (rowLayout[k]) {
|
|
232
|
+
k++;
|
|
233
|
+
}
|
|
234
|
+
/* NOT FOR BROWSER */
|
|
235
|
+
if (i === stop?.row && j > stop.column) {
|
|
236
|
+
rowLayout[k] = coords;
|
|
237
|
+
return layout;
|
|
238
|
+
}
|
|
239
|
+
/* NOT FOR BROWSER END */
|
|
240
|
+
for (let y = i; y < Math.min(i + rowspan, length); y++) {
|
|
241
|
+
for (let x = k; x < k + colspan; x++) {
|
|
242
|
+
layout[y][x] = coords;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
k += colspan;
|
|
246
|
+
/* NOT FOR BROWSER */
|
|
247
|
+
if (i === stop?.y && k > (stop.x ?? NaN)) {
|
|
248
|
+
return layout;
|
|
242
249
|
}
|
|
243
|
-
}
|
|
244
|
-
k += colspan;
|
|
245
|
-
/* NOT FOR BROWSER */
|
|
246
|
-
if (i === stop?.y && k > (stop.x ?? NaN)) {
|
|
247
|
-
return layout;
|
|
248
250
|
}
|
|
249
251
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
252
|
+
else if ((0, exports.isRowEnd)(cell)) {
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
253
255
|
}
|
|
254
256
|
}
|
|
257
|
+
return layout;
|
|
255
258
|
}
|
|
256
|
-
return layout;
|
|
257
259
|
}
|
|
258
260
|
/**
|
|
259
261
|
* Get all rows
|
|
@@ -261,51 +263,53 @@ let TableToken = (() => {
|
|
|
261
263
|
* 获取所有行
|
|
262
264
|
*/
|
|
263
265
|
getAllRows() {
|
|
264
|
-
return [
|
|
266
|
+
LINT: return [
|
|
265
267
|
...super.getRowCount() ? [this] : [],
|
|
266
268
|
...this.childNodes.slice(1)
|
|
267
269
|
.filter((child) => child.is('tr') && child.getRowCount() > 0),
|
|
268
270
|
];
|
|
269
271
|
}
|
|
270
272
|
getNthRow(n, force, insert) {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
const nRows = this.getRowCount();
|
|
274
|
-
n += n < 0 ? nRows : 0;
|
|
275
|
-
/* NOT FOR BROWSER END */
|
|
276
|
-
if (n === 0
|
|
277
|
-
&& (isRow
|
|
278
|
-
|| force && nRows === 0)) {
|
|
279
|
-
return this;
|
|
273
|
+
LINT: { // eslint-disable-line no-unused-labels
|
|
274
|
+
const isRow = super.getRowCount();
|
|
280
275
|
/* NOT FOR BROWSER */
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
throw new RangeError(`The table does not have row ${n}!`);
|
|
276
|
+
const nRows = this.getRowCount();
|
|
277
|
+
n += n < 0 ? nRows : 0;
|
|
284
278
|
/* NOT FOR BROWSER END */
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
for (const child of this.childNodes.slice(2)) {
|
|
290
|
-
const { type } = child;
|
|
291
|
-
if (type === 'tr' && child.getRowCount()) {
|
|
292
|
-
n--;
|
|
293
|
-
if (n < 0) {
|
|
294
|
-
return child;
|
|
295
|
-
}
|
|
279
|
+
if (n === 0
|
|
280
|
+
&& (isRow
|
|
281
|
+
|| force && nRows === 0)) {
|
|
282
|
+
return this;
|
|
296
283
|
/* NOT FOR BROWSER */
|
|
297
284
|
}
|
|
298
|
-
else if (
|
|
299
|
-
|
|
285
|
+
else /* istanbul ignore if */ if (n < 0 || n > nRows || n === nRows && !insert) {
|
|
286
|
+
throw new RangeError(`The table does not have row ${n}!`);
|
|
300
287
|
/* NOT FOR BROWSER END */
|
|
301
288
|
}
|
|
289
|
+
else if (isRow) {
|
|
290
|
+
n--;
|
|
291
|
+
}
|
|
292
|
+
for (const child of this.childNodes.slice(2)) {
|
|
293
|
+
const { type } = child;
|
|
294
|
+
if (type === 'tr' && child.getRowCount()) {
|
|
295
|
+
n--;
|
|
296
|
+
if (n < 0) {
|
|
297
|
+
return child;
|
|
298
|
+
}
|
|
299
|
+
/* NOT FOR BROWSER */
|
|
300
|
+
}
|
|
301
|
+
else if (type === 'table-syntax') {
|
|
302
|
+
return child;
|
|
303
|
+
/* NOT FOR BROWSER END */
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return undefined;
|
|
302
307
|
}
|
|
303
|
-
return undefined;
|
|
304
308
|
}
|
|
305
309
|
/** @private */
|
|
306
310
|
json(_, start = this.getAbsoluteIndex()) {
|
|
307
|
-
const json = super.json(undefined, start);
|
|
308
311
|
LSP: { // eslint-disable-line no-unused-labels
|
|
312
|
+
const json = super.json(undefined, start);
|
|
309
313
|
json['closed'] = this.closed;
|
|
310
314
|
return json;
|
|
311
315
|
}
|
package/dist/src/table/td.d.ts
CHANGED
|
@@ -21,11 +21,11 @@ export declare abstract class TdToken extends TableBaseToken {
|
|
|
21
21
|
#private;
|
|
22
22
|
readonly childNodes: readonly [SyntaxToken, AttributesToken, Token];
|
|
23
23
|
abstract get parentNode(): TrToken | TableToken | undefined;
|
|
24
|
-
abstract get nextSibling():
|
|
24
|
+
abstract get nextSibling(): TrToken | SyntaxToken | this | undefined;
|
|
25
25
|
abstract get previousSibling(): Token | undefined;
|
|
26
26
|
abstract get children(): [SyntaxToken, AttributesToken, Token];
|
|
27
27
|
abstract get parentElement(): TrToken | TableToken | undefined;
|
|
28
|
-
abstract get nextElementSibling():
|
|
28
|
+
abstract get nextElementSibling(): TrToken | SyntaxToken | this | undefined;
|
|
29
29
|
get type(): 'td';
|
|
30
30
|
/** rowspan */
|
|
31
31
|
get rowspan(): number;
|
package/dist/src/table/td.js
CHANGED
|
@@ -134,11 +134,11 @@ let TdToken = (() => {
|
|
|
134
134
|
}
|
|
135
135
|
/** rowspan */
|
|
136
136
|
get rowspan() {
|
|
137
|
-
return this.getAttr('rowspan');
|
|
137
|
+
LINT: return this.getAttr('rowspan'); // eslint-disable-line no-unused-labels
|
|
138
138
|
}
|
|
139
139
|
/** colspan */
|
|
140
140
|
get colspan() {
|
|
141
|
-
return this.getAttr('colspan');
|
|
141
|
+
LINT: return this.getAttr('colspan'); // eslint-disable-line no-unused-labels
|
|
142
142
|
}
|
|
143
143
|
/** cell type / 单元格类型 */
|
|
144
144
|
get subtype() {
|
|
@@ -253,9 +253,11 @@ let TdToken = (() => {
|
|
|
253
253
|
return this.firstChild.text().startsWith('\n');
|
|
254
254
|
}
|
|
255
255
|
getAttr(key) {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
256
|
+
LINT: { // eslint-disable-line no-unused-labels
|
|
257
|
+
const value = super.getAttr(key);
|
|
258
|
+
key = (0, string_1.trimLc)(key);
|
|
259
|
+
return (key === 'rowspan' || key === 'colspan' ? parseInt(value) || 1 : value);
|
|
260
|
+
}
|
|
259
261
|
}
|
|
260
262
|
escape() {
|
|
261
263
|
LSP: { // eslint-disable-line no-unused-labels
|
|
@@ -275,9 +277,8 @@ let TdToken = (() => {
|
|
|
275
277
|
}
|
|
276
278
|
/** @private */
|
|
277
279
|
json(_, start = this.getAbsoluteIndex()) {
|
|
278
|
-
const json = super.json(undefined, start);
|
|
279
280
|
LSP: { // eslint-disable-line no-unused-labels
|
|
280
|
-
const { rowspan, colspan } = this;
|
|
281
|
+
const json = super.json(undefined, start), { rowspan, colspan } = this;
|
|
281
282
|
Object.assign(json, { subtype: this.subtype }, rowspan !== 1 && { rowspan }, colspan !== 1 && { colspan });
|
|
282
283
|
return json;
|
|
283
284
|
}
|