@markuplint/ml-core 2.3.2 → 3.0.0-alpha.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/lib/configs.d.ts +1 -1
- package/lib/configs.js +29 -9
- package/lib/index.d.ts +8 -8
- package/lib/index.js +18 -10
- package/lib/ml-core.d.ts +3 -3
- package/lib/ml-core.js +41 -42
- package/lib/ml-dom/document.d.ts +79 -70
- package/lib/ml-dom/helper/accname.d.ts +2 -2
- package/lib/ml-dom/helper/accname.js +2 -3
- package/lib/ml-dom/helper/create-node.d.ts +3 -4
- package/lib/ml-dom/helper/create-node.js +11 -15
- package/lib/ml-dom/helper/debug.d.ts +2 -2
- package/lib/ml-dom/helper/debug.js +35 -21
- package/lib/ml-dom/helper/getIndent.d.ts +5 -5
- package/lib/ml-dom/helper/getIndent.js +14 -14
- package/lib/ml-dom/helper/mapped-nodes.d.ts +51 -3
- package/lib/ml-dom/helper/match-selector.d.ts +10 -6
- package/lib/ml-dom/helper/node-store.d.ts +6 -3
- package/lib/ml-dom/helper/selector.d.ts +3 -3
- package/lib/ml-dom/helper/walkers.d.ts +5 -4
- package/lib/ml-dom/helper/walkers.js +39 -3
- package/lib/ml-dom/index.d.ts +8 -3
- package/lib/ml-dom/index.js +3 -15
- package/lib/ml-dom/node/attr.d.ts +5 -0
- package/lib/ml-dom/node/attr.js +17 -4
- package/lib/ml-dom/node/document.js +1 -1
- package/lib/ml-dom/node/dom-token-list.d.ts +20 -2
- package/lib/ml-dom/node/dom-token-list.js +85 -9
- package/lib/ml-dom/node/element.d.ts +4 -11
- package/lib/ml-dom/node/element.js +13 -36
- package/lib/ml-dom/node/node.js +2 -8
- package/lib/ml-dom/rule-mapper.d.ts +7 -7
- package/lib/ml-dom/tokens/abstract-element.d.ts +47 -42
- package/lib/ml-dom/tokens/attribute.d.ts +38 -38
- package/lib/ml-dom/tokens/comment.d.ts +7 -4
- package/lib/ml-dom/tokens/doctype.d.ts +12 -9
- package/lib/ml-dom/tokens/element-close-tag.d.ts +20 -17
- package/lib/ml-dom/tokens/element.d.ts +18 -15
- package/lib/ml-dom/tokens/node.d.ts +38 -31
- package/lib/ml-dom/tokens/omitted-element.d.ts +7 -4
- package/lib/ml-dom/tokens/preprocessor-specific-attribute.d.ts +20 -20
- package/lib/ml-dom/tokens/preprocessor-specific-block.d.ts +8 -5
- package/lib/ml-dom/tokens/text.d.ts +13 -9
- package/lib/ml-dom/tokens/token.d.ts +13 -13
- package/lib/ml-dom/types.d.ts +35 -13
- package/lib/ml-rule/ml-rule-context.d.ts +13 -10
- package/lib/ml-rule/ml-rule-context.js +12 -6
- package/lib/ml-rule/ml-rule.d.ts +8 -8
- package/lib/ml-rule/ml-rule.js +62 -62
- package/lib/ml-rule/types.d.ts +11 -1
- package/lib/ruleset/index.d.ts +2 -2
- package/lib/selector/match-selector.d.ts +5 -5
- package/lib/test/index.d.ts +2 -1
- package/lib/test/index.js +7 -2
- package/package.json +10 -9
- package/tsconfig.tsbuildinfo +1 -1
- package/markuplint-recommended.json +0 -196
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _MLDOMIndentation_node, _MLDOMIndentation_parent
|
|
2
|
+
var _MLDOMIndentation_fixed, _MLDOMIndentation_node, _MLDOMIndentation_parent;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.getIndent = void 0;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
@@ -13,8 +13,8 @@ function getIndent(node) {
|
|
|
13
13
|
if (!prevToken) {
|
|
14
14
|
return null;
|
|
15
15
|
}
|
|
16
|
-
if (node.
|
|
17
|
-
if (node.
|
|
16
|
+
if (node.is(node.TEXT_NODE)) {
|
|
17
|
+
if (node.isRawTextElementContent()) {
|
|
18
18
|
return null;
|
|
19
19
|
}
|
|
20
20
|
const matched = node.raw.match(/^(\s*(?:\r?\n)+\s*)(?:[^\s]+)/);
|
|
@@ -31,7 +31,7 @@ function getIndent(node) {
|
|
|
31
31
|
}
|
|
32
32
|
return null;
|
|
33
33
|
}
|
|
34
|
-
if (prevToken.
|
|
34
|
+
if (!prevToken.is(node.TEXT_NODE)) {
|
|
35
35
|
return null;
|
|
36
36
|
}
|
|
37
37
|
// One or more newlines and zero or more spaces or tabs.
|
|
@@ -52,33 +52,33 @@ function getIndent(node) {
|
|
|
52
52
|
exports.getIndent = getIndent;
|
|
53
53
|
class MLDOMIndentation {
|
|
54
54
|
constructor(originTextNode, raw, line, parentNode) {
|
|
55
|
+
_MLDOMIndentation_fixed.set(this, void 0);
|
|
55
56
|
_MLDOMIndentation_node.set(this, void 0);
|
|
56
57
|
_MLDOMIndentation_parent.set(this, void 0);
|
|
57
|
-
_MLDOMIndentation_fixed.set(this, void 0);
|
|
58
58
|
this.line = line;
|
|
59
59
|
tslib_1.__classPrivateFieldSet(this, _MLDOMIndentation_node, originTextNode, "f");
|
|
60
60
|
tslib_1.__classPrivateFieldSet(this, _MLDOMIndentation_parent, parentNode, "f");
|
|
61
61
|
tslib_1.__classPrivateFieldSet(this, _MLDOMIndentation_fixed, raw, "f");
|
|
62
62
|
}
|
|
63
|
+
get raw() {
|
|
64
|
+
if (!tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_parent, "f").is(tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_parent, "f").TEXT_NODE) && this.line !== tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_node, "f").endLine) {
|
|
65
|
+
return '';
|
|
66
|
+
}
|
|
67
|
+
return tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_fixed, "f");
|
|
68
|
+
}
|
|
63
69
|
get type() {
|
|
64
|
-
if (tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_parent, "f").
|
|
70
|
+
if (!tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_parent, "f").is(tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_parent, "f").TEXT_NODE) && this.line !== tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_node, "f").endLine) {
|
|
65
71
|
return 'none';
|
|
66
72
|
}
|
|
67
73
|
const raw = tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_fixed, "f");
|
|
68
74
|
return raw === '' ? 'none' : /^\t+$/.test(raw) ? 'tab' : /^[^\t]+$/.test(raw) ? 'space' : 'mixed';
|
|
69
75
|
}
|
|
70
76
|
get width() {
|
|
71
|
-
if (tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_parent, "f").
|
|
77
|
+
if (!tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_parent, "f").is(tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_parent, "f").TEXT_NODE) && this.line !== tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_node, "f").endLine) {
|
|
72
78
|
return 0;
|
|
73
79
|
}
|
|
74
80
|
return tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_fixed, "f").length;
|
|
75
81
|
}
|
|
76
|
-
get raw() {
|
|
77
|
-
if (tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_parent, "f").type !== 'Text' && this.line !== tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_node, "f").endLine) {
|
|
78
|
-
return '';
|
|
79
|
-
}
|
|
80
|
-
return tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_fixed, "f");
|
|
81
|
-
}
|
|
82
82
|
fix(raw) {
|
|
83
83
|
const current = tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_fixed, "f");
|
|
84
84
|
tslib_1.__classPrivateFieldSet(this, _MLDOMIndentation_fixed, raw, "f");
|
|
@@ -94,7 +94,7 @@ class MLDOMIndentation {
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
-
|
|
97
|
+
_MLDOMIndentation_fixed = new WeakMap(), _MLDOMIndentation_node = new WeakMap(), _MLDOMIndentation_parent = new WeakMap();
|
|
98
98
|
function isFirstToken(node) {
|
|
99
99
|
return !node.prevToken;
|
|
100
100
|
}
|
|
@@ -1,4 +1,52 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type {
|
|
2
|
+
MLDOMAttribute,
|
|
3
|
+
MLDOMComment,
|
|
4
|
+
MLDOMDoctype,
|
|
5
|
+
MLDOMElement,
|
|
6
|
+
MLDOMElementCloseTag,
|
|
7
|
+
MLDOMNode,
|
|
8
|
+
MLDOMOmittedElement,
|
|
9
|
+
MLDOMPreprocessorSpecificBlock,
|
|
10
|
+
MLDOMText,
|
|
11
|
+
MLDOMToken,
|
|
12
|
+
} from '../tokens';
|
|
13
|
+
import type {
|
|
14
|
+
MLASTAbstructNode,
|
|
15
|
+
MLASTAttr,
|
|
16
|
+
MLASTComment,
|
|
17
|
+
MLASTDoctype,
|
|
18
|
+
MLASTElement,
|
|
19
|
+
MLASTElementCloseTag,
|
|
20
|
+
MLASTNode,
|
|
21
|
+
MLASTOmittedElement,
|
|
22
|
+
MLASTParentNode,
|
|
23
|
+
MLASTPreprocessorSpecificBlock,
|
|
24
|
+
MLASTText,
|
|
25
|
+
MLToken,
|
|
26
|
+
} from '@markuplint/ml-ast/';
|
|
3
27
|
import type { RuleConfigValue } from '@markuplint/ml-config';
|
|
4
|
-
export declare type MappedNode<N, T extends RuleConfigValue, O = null> = N extends MLASTElement
|
|
28
|
+
export declare type MappedNode<N, T extends RuleConfigValue, O = null> = N extends MLASTElement
|
|
29
|
+
? MLDOMElement<T, O>
|
|
30
|
+
: N extends MLASTElementCloseTag
|
|
31
|
+
? MLDOMElementCloseTag<T, O>
|
|
32
|
+
: N extends MLASTOmittedElement
|
|
33
|
+
? MLDOMOmittedElement<T, O>
|
|
34
|
+
: N extends MLASTParentNode
|
|
35
|
+
? MLDOMElement<T, O> | MLDOMOmittedElement<T, O>
|
|
36
|
+
: N extends MLASTComment
|
|
37
|
+
? MLDOMComment<T, O>
|
|
38
|
+
: N extends MLASTText
|
|
39
|
+
? MLDOMText<T, O>
|
|
40
|
+
: N extends MLASTDoctype
|
|
41
|
+
? MLDOMDoctype<T, O>
|
|
42
|
+
: N extends MLASTNode
|
|
43
|
+
? MLDOMNode<T, O, MLASTNode>
|
|
44
|
+
: N extends MLASTPreprocessorSpecificBlock
|
|
45
|
+
? MLDOMPreprocessorSpecificBlock<T, O>
|
|
46
|
+
: N extends MLASTAbstructNode
|
|
47
|
+
? MLDOMNode<T, O, MLASTAbstructNode>
|
|
48
|
+
: N extends MLASTAttr
|
|
49
|
+
? MLDOMAttribute
|
|
50
|
+
: N extends MLToken
|
|
51
|
+
? MLDOMToken<MLToken>
|
|
52
|
+
: never;
|
|
@@ -3,14 +3,18 @@ import type { Specificity } from './selector';
|
|
|
3
3
|
import type { RegexSelector } from '@markuplint/ml-config';
|
|
4
4
|
export declare type SelectorMatches = SelectorMatched | SelectorUnmatched;
|
|
5
5
|
declare type SelectorMatched = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
matched: true;
|
|
7
|
+
selector: string;
|
|
8
|
+
specificity: Specificity;
|
|
9
|
+
data?: Record<string, string>;
|
|
10
10
|
};
|
|
11
11
|
declare type SelectorUnmatched = {
|
|
12
|
-
|
|
12
|
+
matched: false;
|
|
13
13
|
};
|
|
14
14
|
declare type TargetElement = MLDOMAbstractElement<any, any>;
|
|
15
|
-
export declare function matchSelector(
|
|
15
|
+
export declare function matchSelector(
|
|
16
|
+
el: TargetElement,
|
|
17
|
+
selector: string | RegexSelector | undefined,
|
|
18
|
+
tagNameCaseSensitive?: boolean,
|
|
19
|
+
): SelectorMatches;
|
|
16
20
|
export {};
|
|
@@ -3,7 +3,10 @@ import type { MappedNode } from './mapped-nodes';
|
|
|
3
3
|
import type { MLASTAbstructNode } from '@markuplint/ml-ast';
|
|
4
4
|
import type { RuleConfigValue } from '@markuplint/ml-config';
|
|
5
5
|
export default class NodeStore {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
#private;
|
|
7
|
+
setNode<A extends MLASTAbstructNode, T extends RuleConfigValue, O = null>(
|
|
8
|
+
astNode: A,
|
|
9
|
+
node: MLDOMNode<T, O, A>,
|
|
10
|
+
): void;
|
|
11
|
+
getNode<N extends MLASTAbstructNode, T extends RuleConfigValue, O = null>(astNode: N): MappedNode<N, T, O>;
|
|
9
12
|
}
|
|
@@ -4,8 +4,8 @@ export declare function createSelector(selector: string, tagNameCaseSensitive?:
|
|
|
4
4
|
export declare function compareSpecificity(a: Specificity, b: Specificity): 0 | 1 | -1;
|
|
5
5
|
declare type TargetElement = MLDOMAbstractElement<any, any>;
|
|
6
6
|
declare class Selector {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
#private;
|
|
8
|
+
constructor(selector: string, tagNameCaseSensitive: boolean);
|
|
9
|
+
match(el: TargetElement, caller?: TargetElement | null): Specificity | false;
|
|
10
10
|
}
|
|
11
11
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { MLNode } from '../node/node';
|
|
2
2
|
import type { RuleConfigValue } from '@markuplint/ml-config';
|
|
3
|
-
export declare type Walker<T extends RuleConfigValue, O = null, N =
|
|
4
|
-
export declare type SyncWalker<T extends RuleConfigValue, O = null, N =
|
|
5
|
-
export declare function syncWalk<T extends RuleConfigValue, O = null>(nodeList:
|
|
3
|
+
export declare type Walker<T extends RuleConfigValue, O = null, N = MLNode<T, O>> = (node: N) => void | Promise<void> | Promise<void>[];
|
|
4
|
+
export declare type SyncWalker<T extends RuleConfigValue, O = null, N = MLNode<T, O>> = (node: N) => void;
|
|
5
|
+
export declare function syncWalk<T extends RuleConfigValue, O = null>(nodeList: ReadonlyArray<MLNode<T, O>>, walker: SyncWalker<T, O>): void;
|
|
6
|
+
export declare function sequentialWalker<T extends RuleConfigValue, O = null, N = MLNode<T, O>>(list: ReadonlyArray<N>, walker: Walker<T, O, N>): Promise<void>;
|
|
@@ -1,12 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.syncWalk = void 0;
|
|
3
|
+
exports.sequentialWalker = exports.syncWalk = void 0;
|
|
4
4
|
function syncWalk(nodeList, walker) {
|
|
5
5
|
for (const node of nodeList) {
|
|
6
|
-
if (node.
|
|
7
|
-
syncWalk(node.childNodes, walker);
|
|
6
|
+
if (node.is(node.ELEMENT_NODE) || node.is(node.MARKUPLINT_PREPROCESSOR_BLOCK)) {
|
|
7
|
+
syncWalk(Array.from(node.childNodes), walker);
|
|
8
8
|
}
|
|
9
9
|
walker(node);
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
exports.syncWalk = syncWalk;
|
|
13
|
+
function sequentialWalker(list, walker) {
|
|
14
|
+
if (list.length === 0) {
|
|
15
|
+
return Promise.resolve();
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The following pattern is used to ensure that all rules run sequentially,
|
|
19
|
+
* no matter it runs asynchronously or synchronously.
|
|
20
|
+
*/
|
|
21
|
+
let _resolve;
|
|
22
|
+
let _reject;
|
|
23
|
+
const promise = new Promise((resolve, reject) => {
|
|
24
|
+
_resolve = resolve;
|
|
25
|
+
_reject = reject;
|
|
26
|
+
});
|
|
27
|
+
const loop = (index = 0) => {
|
|
28
|
+
if (index >= list.length) {
|
|
29
|
+
_resolve();
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const node = list[index];
|
|
33
|
+
if (!node) {
|
|
34
|
+
_resolve();
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const result = walker(node);
|
|
38
|
+
if (result instanceof Promise) {
|
|
39
|
+
result.then(() => loop(index + 1)).catch(_reject);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
loop(index + 1);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
loop();
|
|
46
|
+
return promise;
|
|
47
|
+
}
|
|
48
|
+
exports.sequentialWalker = sequentialWalker;
|
package/lib/ml-dom/index.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
1
|
+
export type { MLAttr as Attr } from './node/attr';
|
|
2
|
+
export type { MLBlock as Block } from './node/block';
|
|
3
|
+
export type { MLComment as Comment } from './node/comment';
|
|
4
|
+
export type { MLDocumentFragment as DocumentFragment } from './node/document-fragment';
|
|
5
|
+
export type { MLDocumentType as DocumentType } from './node/document-type';
|
|
6
|
+
export type { MLElement as Element } from './node/element';
|
|
7
|
+
export type { MLText as Text } from './node/text';
|
|
8
|
+
export { MLDocument as Document } from './node/document';
|
package/lib/ml-dom/index.js
CHANGED
|
@@ -1,17 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
var document_1 = require("./document");
|
|
8
|
-
Object.defineProperty(exports, "Document", { enumerable: true, get: function () { return
|
|
9
|
-
var tokens_1 = require("./tokens");
|
|
10
|
-
Object.defineProperty(exports, "Attribute", { enumerable: true, get: function () { return tokens_1.MLDOMAttribute; } });
|
|
11
|
-
Object.defineProperty(exports, "Comment", { enumerable: true, get: function () { return tokens_1.MLDOMComment; } });
|
|
12
|
-
Object.defineProperty(exports, "Doctype", { enumerable: true, get: function () { return tokens_1.MLDOMDoctype; } });
|
|
13
|
-
Object.defineProperty(exports, "Element", { enumerable: true, get: function () { return tokens_1.MLDOMElement; } });
|
|
14
|
-
Object.defineProperty(exports, "ElementCloseTag", { enumerable: true, get: function () { return tokens_1.MLDOMElementCloseTag; } });
|
|
15
|
-
Object.defineProperty(exports, "Node", { enumerable: true, get: function () { return tokens_1.MLDOMNode; } });
|
|
16
|
-
Object.defineProperty(exports, "OmittedElement", { enumerable: true, get: function () { return tokens_1.MLDOMOmittedElement; } });
|
|
17
|
-
Object.defineProperty(exports, "Text", { enumerable: true, get: function () { return tokens_1.MLDOMText; } });
|
|
3
|
+
exports.Document = void 0;
|
|
4
|
+
var document_1 = require("./node/document");
|
|
5
|
+
Object.defineProperty(exports, "Document", { enumerable: true, get: function () { return document_1.MLDocument; } });
|
|
@@ -3,6 +3,7 @@ import type { AttributeNodeType } from './types';
|
|
|
3
3
|
import type { MLASTAttr } from '@markuplint/ml-ast';
|
|
4
4
|
import type { RuleConfigValue } from '@markuplint/ml-config';
|
|
5
5
|
import { MLToken } from '../token/token';
|
|
6
|
+
import { MLDomTokenList } from './dom-token-list';
|
|
6
7
|
import { MLNode } from './node';
|
|
7
8
|
export declare class MLAttr<T extends RuleConfigValue, O = null> extends MLNode<T, O, MLASTAttr> implements Attr {
|
|
8
9
|
#private;
|
|
@@ -85,6 +86,10 @@ export declare class MLAttr<T extends RuleConfigValue, O = null> extends MLNode<
|
|
|
85
86
|
* @see https://dom.spec.whatwg.org/#dom-attr-value
|
|
86
87
|
*/
|
|
87
88
|
get value(): string;
|
|
89
|
+
/**
|
|
90
|
+
* @implements `@markuplint/ml-core` API: `MLAttr`
|
|
91
|
+
*/
|
|
92
|
+
get tokenList(): MLDomTokenList | null;
|
|
88
93
|
constructor(astToken: MLASTAttr, ownElement: MLElement<T, O>);
|
|
89
94
|
/**
|
|
90
95
|
* @implements `@markuplint/ml-core` API: `MLAttr`
|
package/lib/ml-dom/node/attr.js
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _MLAttr_potentialName, _MLAttr_potentialValue;
|
|
2
|
+
var _MLAttr_localName, _MLAttr_namespaceURI, _MLAttr_potentialName, _MLAttr_potentialValue;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.MLAttr = void 0;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
|
+
const ml_spec_1 = require("@markuplint/ml-spec");
|
|
6
7
|
const token_1 = require("../token/token");
|
|
8
|
+
const dom_token_list_1 = require("./dom-token-list");
|
|
7
9
|
const node_1 = require("./node");
|
|
8
10
|
const unexpected_call_error_1 = tslib_1.__importDefault(require("./unexpected-call-error"));
|
|
9
11
|
class MLAttr extends node_1.MLNode {
|
|
10
12
|
constructor(astToken, ownElement) {
|
|
11
13
|
var _a;
|
|
12
14
|
super(astToken, ownElement.ownerMLDocument);
|
|
15
|
+
_MLAttr_localName.set(this, void 0);
|
|
16
|
+
_MLAttr_namespaceURI.set(this, void 0);
|
|
13
17
|
_MLAttr_potentialName.set(this, void 0);
|
|
14
18
|
_MLAttr_potentialValue.set(this, void 0);
|
|
15
19
|
this.endQuote = null;
|
|
@@ -48,6 +52,9 @@ class MLAttr extends node_1.MLNode {
|
|
|
48
52
|
tslib_1.__classPrivateFieldSet(this, _MLAttr_potentialName, this._astToken.potentialName, "f");
|
|
49
53
|
tslib_1.__classPrivateFieldSet(this, _MLAttr_potentialValue, this._astToken.potentialValue, "f");
|
|
50
54
|
}
|
|
55
|
+
const ns = (0, ml_spec_1.resolveNamespace)(tslib_1.__classPrivateFieldGet(this, _MLAttr_potentialName, "f"), ownElement.namespaceURI);
|
|
56
|
+
tslib_1.__classPrivateFieldSet(this, _MLAttr_localName, ns.localName, "f");
|
|
57
|
+
tslib_1.__classPrivateFieldSet(this, _MLAttr_namespaceURI, ns.namespaceURI, "f");
|
|
51
58
|
this.ownerElement = ownElement;
|
|
52
59
|
this.isDuplicatable = this._astToken.isDuplicatable;
|
|
53
60
|
}
|
|
@@ -59,7 +66,7 @@ class MLAttr extends node_1.MLNode {
|
|
|
59
66
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-attr-localname
|
|
60
67
|
*/
|
|
61
68
|
get localName() {
|
|
62
|
-
|
|
69
|
+
return tslib_1.__classPrivateFieldGet(this, _MLAttr_localName, "f");
|
|
63
70
|
}
|
|
64
71
|
/**
|
|
65
72
|
*
|
|
@@ -77,7 +84,7 @@ class MLAttr extends node_1.MLNode {
|
|
|
77
84
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-attr-namespaceuri
|
|
78
85
|
*/
|
|
79
86
|
get namespaceURI() {
|
|
80
|
-
|
|
87
|
+
return tslib_1.__classPrivateFieldGet(this, _MLAttr_namespaceURI, "f");
|
|
81
88
|
}
|
|
82
89
|
/**
|
|
83
90
|
* Returns a string appropriate for the type of node as `Attr`
|
|
@@ -126,6 +133,12 @@ class MLAttr extends node_1.MLNode {
|
|
|
126
133
|
get value() {
|
|
127
134
|
return tslib_1.__classPrivateFieldGet(this, _MLAttr_potentialValue, "f");
|
|
128
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* @implements `@markuplint/ml-core` API: `MLAttr`
|
|
138
|
+
*/
|
|
139
|
+
get tokenList() {
|
|
140
|
+
return this.isDynamicValue ? null : new dom_token_list_1.MLDomTokenList(this.value, [this]);
|
|
141
|
+
}
|
|
129
142
|
/**
|
|
130
143
|
* @implements `@markuplint/ml-core` API: `MLAttr`
|
|
131
144
|
*/
|
|
@@ -141,4 +154,4 @@ class MLAttr extends node_1.MLNode {
|
|
|
141
154
|
}
|
|
142
155
|
}
|
|
143
156
|
exports.MLAttr = MLAttr;
|
|
144
|
-
_MLAttr_potentialName = new WeakMap(), _MLAttr_potentialValue = new WeakMap();
|
|
157
|
+
_MLAttr_localName = new WeakMap(), _MLAttr_namespaceURI = new WeakMap(), _MLAttr_potentialName = new WeakMap(), _MLAttr_potentialValue = new WeakMap();
|
|
@@ -37,7 +37,7 @@ class MLDocument extends parent_node_1.MLParentNode {
|
|
|
37
37
|
*/
|
|
38
38
|
this.currentRule = null;
|
|
39
39
|
this.isFragment = ast.isFragment;
|
|
40
|
-
this.specs = (0, ml_spec_1.
|
|
40
|
+
this.specs = (0, ml_spec_1.schemaToSpec)(schemas);
|
|
41
41
|
this.endTag = (_a = options === null || options === void 0 ? void 0 : options.endTag) !== null && _a !== void 0 ? _a : 'omittable';
|
|
42
42
|
tslib_1.__classPrivateFieldSet(this, _MLDocument_filename, options === null || options === void 0 ? void 0 : options.filename, "f");
|
|
43
43
|
// console.log(ast.nodeList.map((n, i) => `${i}: ${n.uuid} "${n.raw.trim()}"(${n.type})`));
|
|
@@ -1,15 +1,33 @@
|
|
|
1
|
+
import type { MLAttr } from './attr';
|
|
2
|
+
import type { RuleInfo } from '@markuplint/ml-config';
|
|
3
|
+
declare type Scope = {
|
|
4
|
+
raw: string;
|
|
5
|
+
startOffset: number;
|
|
6
|
+
startLine: number;
|
|
7
|
+
startCol: number;
|
|
8
|
+
rule: RuleInfo<any, any>;
|
|
9
|
+
};
|
|
1
10
|
export declare class MLDomTokenList extends Array<string> implements DOMTokenList {
|
|
2
11
|
#private;
|
|
3
12
|
get value(): string;
|
|
4
|
-
constructor(tokens: string);
|
|
13
|
+
constructor(tokens: string, ownerAttrs: MLAttr<any, any>[]);
|
|
5
14
|
add(...tokens: string[]): void;
|
|
15
|
+
/**
|
|
16
|
+
* @implements `@markuplint/ml-core` API: `MLDomTokenList`
|
|
17
|
+
*/
|
|
18
|
+
allTokens(): Scope[];
|
|
6
19
|
contains(token: string): boolean;
|
|
7
20
|
forEach(callbackfn: (value: string, index: number, parent: any) => void, thisArg?: any): void;
|
|
8
21
|
item(index: number): string | null;
|
|
22
|
+
/**
|
|
23
|
+
* @implements `@markuplint/ml-core` API: `MLDomTokenList`
|
|
24
|
+
*/
|
|
25
|
+
pick(token: string): Scope | null;
|
|
9
26
|
remove(...tokens: string[]): void;
|
|
10
27
|
replace(token: string, newToken: string): boolean;
|
|
11
28
|
supports(token: string): boolean;
|
|
12
29
|
toggle(token: string, force?: boolean): boolean;
|
|
13
30
|
toString(): string;
|
|
31
|
+
private _pick;
|
|
14
32
|
}
|
|
15
|
-
export
|
|
33
|
+
export {};
|
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _MLDomTokenList_set;
|
|
2
|
+
var _MLDomTokenList_set, _MLDomTokenList_origin, _MLDomTokenList_ownerAttrs;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
4
|
+
exports.MLDomTokenList = void 0;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
|
+
const parser_utils_1 = require("@markuplint/parser-utils");
|
|
6
7
|
const unexpected_call_error_1 = tslib_1.__importDefault(require("./unexpected-call-error"));
|
|
7
8
|
class MLDomTokenList extends Array {
|
|
8
|
-
constructor(tokens) {
|
|
9
|
+
constructor(tokens, ownerAttrs) {
|
|
9
10
|
const list = tokens
|
|
10
11
|
.split(/\s+/)
|
|
11
12
|
.map(t => t.trim())
|
|
12
13
|
.filter(t => !!t);
|
|
13
14
|
super(...list);
|
|
14
15
|
_MLDomTokenList_set.set(this, void 0);
|
|
16
|
+
_MLDomTokenList_origin.set(this, void 0);
|
|
17
|
+
/**
|
|
18
|
+
* In some cases, an author specifies multiple attributes or directives.
|
|
19
|
+
* The reference is not always one.
|
|
20
|
+
*/
|
|
21
|
+
_MLDomTokenList_ownerAttrs.set(this, void 0);
|
|
22
|
+
tslib_1.__classPrivateFieldSet(this, _MLDomTokenList_origin, tokens, "f");
|
|
23
|
+
tslib_1.__classPrivateFieldSet(this, _MLDomTokenList_ownerAttrs, ownerAttrs, "f");
|
|
15
24
|
tslib_1.__classPrivateFieldSet(this, _MLDomTokenList_set, new Set(list), "f");
|
|
16
25
|
}
|
|
17
26
|
get value() {
|
|
@@ -25,6 +34,35 @@ class MLDomTokenList extends Array {
|
|
|
25
34
|
tslib_1.__classPrivateFieldGet(this, _MLDomTokenList_set, "f").add(token);
|
|
26
35
|
this.push(token);
|
|
27
36
|
}
|
|
37
|
+
tslib_1.__classPrivateFieldSet(this, _MLDomTokenList_origin, tslib_1.__classPrivateFieldGet(this, _MLDomTokenList_origin, "f") + tokens.join(' '), "f");
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @implements `@markuplint/ml-core` API: `MLDomTokenList`
|
|
41
|
+
*/
|
|
42
|
+
allTokens() {
|
|
43
|
+
let offset = 0;
|
|
44
|
+
const tokens = Array.from(this);
|
|
45
|
+
const locs = [];
|
|
46
|
+
while (tokens.length) {
|
|
47
|
+
const token = tokens.shift();
|
|
48
|
+
if (!token) {
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
const loc = this._pick(token, offset);
|
|
52
|
+
if (!loc) {
|
|
53
|
+
offset = 0;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
offset = loc._searchedIndex;
|
|
57
|
+
locs.push({
|
|
58
|
+
raw: loc.raw,
|
|
59
|
+
startOffset: loc.startOffset,
|
|
60
|
+
startLine: loc.startLine,
|
|
61
|
+
startCol: loc.startCol,
|
|
62
|
+
rule: loc.rule,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return locs;
|
|
28
66
|
}
|
|
29
67
|
contains(token) {
|
|
30
68
|
return tslib_1.__classPrivateFieldGet(this, _MLDomTokenList_set, "f").has(token);
|
|
@@ -36,6 +74,22 @@ class MLDomTokenList extends Array {
|
|
|
36
74
|
var _a;
|
|
37
75
|
return (_a = this[index]) !== null && _a !== void 0 ? _a : null;
|
|
38
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* @implements `@markuplint/ml-core` API: `MLDomTokenList`
|
|
79
|
+
*/
|
|
80
|
+
pick(token) {
|
|
81
|
+
const r = this._pick(token);
|
|
82
|
+
if (!r) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
raw: r.raw,
|
|
87
|
+
startOffset: r.startOffset,
|
|
88
|
+
startLine: r.startLine,
|
|
89
|
+
startCol: r.startCol,
|
|
90
|
+
rule: r.rule,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
39
93
|
remove(...tokens) {
|
|
40
94
|
throw new unexpected_call_error_1.default('Not supported "remove" method');
|
|
41
95
|
}
|
|
@@ -51,11 +105,33 @@ class MLDomTokenList extends Array {
|
|
|
51
105
|
toString() {
|
|
52
106
|
return this.value;
|
|
53
107
|
}
|
|
108
|
+
_pick(token, _offset = 0) {
|
|
109
|
+
var _a, _b, _c, _d, _e, _f;
|
|
110
|
+
token = token.trim().split(/\s+/g)[0];
|
|
111
|
+
if (!token) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
for (const ownerAttr of tslib_1.__classPrivateFieldGet(this, _MLDomTokenList_ownerAttrs, "f")) {
|
|
115
|
+
if (ownerAttr.isDynamicValue) {
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
const startOffset = tslib_1.__classPrivateFieldGet(this, _MLDomTokenList_origin, "f").indexOf(token, _offset);
|
|
119
|
+
if (startOffset === -1) {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const startLine = (0, parser_utils_1.getLine)(tslib_1.__classPrivateFieldGet(this, _MLDomTokenList_origin, "f"), startOffset);
|
|
123
|
+
const startCol = (0, parser_utils_1.getCol)(tslib_1.__classPrivateFieldGet(this, _MLDomTokenList_origin, "f"), startOffset);
|
|
124
|
+
return {
|
|
125
|
+
raw: token,
|
|
126
|
+
startOffset: ((_b = (_a = ownerAttr.valueNode) === null || _a === void 0 ? void 0 : _a.startOffset) !== null && _b !== void 0 ? _b : 0) + startOffset,
|
|
127
|
+
startLine: ((_d = (_c = ownerAttr.valueNode) === null || _c === void 0 ? void 0 : _c.startLine) !== null && _d !== void 0 ? _d : 0) + (startLine - 1),
|
|
128
|
+
startCol: ((_f = (_e = ownerAttr.valueNode) === null || _e === void 0 ? void 0 : _e.startCol) !== null && _f !== void 0 ? _f : 0) + (startCol - 1),
|
|
129
|
+
rule: ownerAttr.rule,
|
|
130
|
+
_searchedIndex: startOffset,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
54
135
|
}
|
|
55
136
|
exports.MLDomTokenList = MLDomTokenList;
|
|
56
|
-
_MLDomTokenList_set = new WeakMap();
|
|
57
|
-
function toDOMTokenList(tokens) {
|
|
58
|
-
const tokenList = new MLDomTokenList(tokens);
|
|
59
|
-
return tokenList;
|
|
60
|
-
}
|
|
61
|
-
exports.toDOMTokenList = toDOMTokenList;
|
|
137
|
+
_MLDomTokenList_set = new WeakMap(), _MLDomTokenList_origin = new WeakMap(), _MLDomTokenList_ownerAttrs = new WeakMap();
|
|
@@ -2,10 +2,11 @@ import type { MLDocument } from './document';
|
|
|
2
2
|
import type { MLNamedNodeMap } from './named-node-map';
|
|
3
3
|
import type { MLText } from './text';
|
|
4
4
|
import type { ElementNodeType } from './types';
|
|
5
|
-
import type { MLASTElement } from '@markuplint/ml-ast';
|
|
5
|
+
import type { MLASTElement, NamespaceURI } from '@markuplint/ml-ast';
|
|
6
6
|
import type { RuleConfigValue } from '@markuplint/ml-config';
|
|
7
7
|
import { MLToken } from '../token/token';
|
|
8
8
|
import { MLAttr } from './attr';
|
|
9
|
+
import { MLDomTokenList } from './dom-token-list';
|
|
9
10
|
import { MLParentNode } from './parent-node';
|
|
10
11
|
export declare class MLElement<T extends RuleConfigValue, O = null> extends MLParentNode<T, O, MLASTElement> implements Element, HTMLOrSVGElement, HTMLElement {
|
|
11
12
|
#private;
|
|
@@ -15,7 +16,7 @@ export declare class MLElement<T extends RuleConfigValue, O = null> extends MLPa
|
|
|
15
16
|
readonly isCustomElement: boolean;
|
|
16
17
|
readonly isForeignElement: boolean;
|
|
17
18
|
readonly isOmitted: boolean;
|
|
18
|
-
readonly namespaceURI:
|
|
19
|
+
readonly namespaceURI: NamespaceURI;
|
|
19
20
|
readonly ontouchcancel?: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null | undefined;
|
|
20
21
|
readonly ontouchend?: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null | undefined;
|
|
21
22
|
readonly ontouchmove?: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null | undefined;
|
|
@@ -358,7 +359,7 @@ export declare class MLElement<T extends RuleConfigValue, O = null> extends MLPa
|
|
|
358
359
|
* @implements DOM API: `Element`
|
|
359
360
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-element-classlist%E2%91%A0
|
|
360
361
|
*/
|
|
361
|
-
get classList():
|
|
362
|
+
get classList(): MLDomTokenList;
|
|
362
363
|
/**
|
|
363
364
|
* @implements DOM API: `Element`
|
|
364
365
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-element-classname%E2%91%A0
|
|
@@ -509,10 +510,6 @@ export declare class MLElement<T extends RuleConfigValue, O = null> extends MLPa
|
|
|
509
510
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-element-localname%E2%91%A0
|
|
510
511
|
*/
|
|
511
512
|
get localName(): string;
|
|
512
|
-
/**
|
|
513
|
-
* @implements `@markuplint/ml-core` API: `MLElement`
|
|
514
|
-
*/
|
|
515
|
-
get nameWithNS(): string;
|
|
516
513
|
/**
|
|
517
514
|
* The element immediately following the specified one in its parent's children list.
|
|
518
515
|
*
|
|
@@ -539,10 +536,6 @@ export declare class MLElement<T extends RuleConfigValue, O = null> extends MLPa
|
|
|
539
536
|
* @implements DOM API: `Element`
|
|
540
537
|
*/
|
|
541
538
|
get nonce(): string | undefined;
|
|
542
|
-
/**
|
|
543
|
-
* @implements `@markuplint/ml-core` API: `MLElement`
|
|
544
|
-
*/
|
|
545
|
-
get ns(): string;
|
|
546
539
|
/**
|
|
547
540
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
548
541
|
*
|