@markuplint/ml-core 2.0.0 → 2.1.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/ml-core.d.ts +11 -11
- package/lib/ml-dom/document.d.ts +70 -66
- package/lib/ml-dom/document.js +23 -0
- package/lib/ml-dom/helper/accname.d.ts +2 -0
- package/lib/ml-dom/helper/accname.js +18 -0
- package/lib/ml-dom/helper/create-node.d.ts +1 -5
- package/lib/ml-dom/helper/debug.d.ts +1 -4
- package/lib/ml-dom/helper/debug.js +1 -1
- package/lib/ml-dom/helper/getIndent.d.ts +7 -7
- package/lib/ml-dom/helper/mapped-nodes.d.ts +3 -51
- package/lib/ml-dom/helper/match-selector.d.ts +6 -10
- package/lib/ml-dom/helper/node-store.d.ts +3 -6
- package/lib/ml-dom/helper/selector.d.ts +4 -4
- package/lib/ml-dom/helper/walkers.d.ts +2 -7
- package/lib/ml-dom/index.d.ts +1 -10
- package/lib/ml-dom/rule-mapper.d.ts +7 -7
- package/lib/ml-dom/tokens/abstract-element.d.ts +41 -40
- package/lib/ml-dom/tokens/abstract-element.js +16 -2
- package/lib/ml-dom/tokens/attribute.d.ts +38 -36
- package/lib/ml-dom/tokens/attribute.js +12 -7
- package/lib/ml-dom/tokens/comment.d.ts +4 -5
- package/lib/ml-dom/tokens/comment.js +4 -0
- package/lib/ml-dom/tokens/doctype.d.ts +9 -10
- package/lib/ml-dom/tokens/doctype.js +4 -0
- package/lib/ml-dom/tokens/element-close-tag.d.ts +17 -19
- package/lib/ml-dom/tokens/element-close-tag.js +1 -0
- package/lib/ml-dom/tokens/element.d.ts +15 -18
- package/lib/ml-dom/tokens/node.d.ts +30 -23
- package/lib/ml-dom/tokens/node.js +30 -15
- package/lib/ml-dom/tokens/omitted-element.d.ts +4 -7
- package/lib/ml-dom/tokens/preprocessor-specific-attribute.d.ts +20 -20
- package/lib/ml-dom/tokens/preprocessor-specific-block.d.ts +5 -8
- package/lib/ml-dom/tokens/text.d.ts +8 -9
- package/lib/ml-dom/tokens/text.js +4 -0
- package/lib/ml-dom/tokens/token.d.ts +13 -13
- package/lib/ml-dom/types.d.ts +13 -35
- package/lib/ml-rule/create-test-rule.d.ts +3 -5
- package/lib/ml-rule/ml-rule-context.d.ts +44 -52
- package/lib/ml-rule/ml-rule.d.ts +23 -33
- package/lib/ml-rule/types.d.ts +5 -5
- package/lib/plugin/types.d.ts +5 -5
- package/lib/ruleset/index.d.ts +4 -4
- package/lib/test/index.d.ts +5 -14
- package/lib/types.d.ts +6 -6
- package/lib/utils/get-location-from-chars.d.ts +4 -9
- package/markuplint-recommended.json +1 -0
- package/package.json +3 -2
- package/tsconfig.tsbuildinfo +1 -1
package/lib/ml-core.d.ts
CHANGED
|
@@ -3,17 +3,17 @@ import type { RuleConfigValue, Violation } from '@markuplint/ml-config';
|
|
|
3
3
|
import { ParserError } from '@markuplint/parser-utils';
|
|
4
4
|
import { Document } from './ml-dom';
|
|
5
5
|
export declare type MLCoreParams = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
sourceCode: string;
|
|
7
|
+
filename: string;
|
|
8
|
+
debug?: boolean;
|
|
9
9
|
} & MLFabric;
|
|
10
10
|
export declare class MLCore {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
#private;
|
|
12
|
+
constructor({ parser, sourceCode, ruleset, rules, locale, schemas, parserOptions, filename, debug }: MLCoreParams);
|
|
13
|
+
get document(): Document<RuleConfigValue, unknown> | ParserError;
|
|
14
|
+
verify(fix?: boolean): Promise<Violation[]>;
|
|
15
|
+
setCode(sourceCode: string): void;
|
|
16
|
+
update({ parser, ruleset, rules, locale, schemas, parserOptions }: Partial<MLFabric>): void;
|
|
17
|
+
private _parse;
|
|
18
|
+
private _createDocument;
|
|
19
19
|
}
|
package/lib/ml-dom/document.d.ts
CHANGED
|
@@ -12,70 +12,74 @@ import { MLDOMDoctype } from './tokens';
|
|
|
12
12
|
* markuplint DOM Document
|
|
13
13
|
*/
|
|
14
14
|
export default class MLDOMDocument<T extends RuleConfigValue, O = null> {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
15
|
+
#private;
|
|
16
|
+
/**
|
|
17
|
+
* An array of markuplint DOM nodes
|
|
18
|
+
*/
|
|
19
|
+
nodeList: ReadonlyArray<AnonymousNode<T, O>>;
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
23
|
+
currentRule: MLRule<T, O> | null;
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
*/
|
|
27
|
+
isFragment: boolean;
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
*/
|
|
31
|
+
specs: Readonly<MLMLSpec>;
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
*/
|
|
35
|
+
readonly endTag: 'xml' | 'omittable' | 'never';
|
|
36
|
+
/**
|
|
37
|
+
*
|
|
38
|
+
*/
|
|
39
|
+
readonly nodeStore: NodeStore;
|
|
40
|
+
/**
|
|
41
|
+
* Window object for calling the `getComputedStyle` and the `getPropertyValue` that are needed by **Accessible Name and Description Computation**.
|
|
42
|
+
* But it always returns the empty object.
|
|
43
|
+
* (It may improve to possible to compute the name from the `style` attribute in the future.)
|
|
44
|
+
*/
|
|
45
|
+
readonly defaultView: {
|
|
46
|
+
getComputedStyle(_el: MLDOMElement<any, any>): {
|
|
47
|
+
getPropertyValue(_propName: string): {};
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* It could be used in rule, make sure it is immutable
|
|
52
|
+
*/
|
|
53
|
+
get filename(): string | undefined;
|
|
54
|
+
/**
|
|
55
|
+
*
|
|
56
|
+
* @param ast node list of markuplint AST
|
|
57
|
+
* @param ruleset ruleset object
|
|
58
|
+
*/
|
|
59
|
+
constructor(ast: MLASTDocument, ruleset: Ruleset, schemas: readonly [MLMLSpec, ...ExtendedSpec[]], options?: {
|
|
60
|
+
filename?: string;
|
|
61
|
+
tagNameCaseSensitive?: boolean;
|
|
62
|
+
endTag?: 'xml' | 'omittable' | 'never';
|
|
63
|
+
});
|
|
64
|
+
get doctype(): MLDOMDoctype<T, O> | null;
|
|
65
|
+
get tree(): AnonymousNode<T, O>[];
|
|
66
|
+
walk(walker: Walker<T, O>): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
*
|
|
69
|
+
* @param type
|
|
70
|
+
* @param walker
|
|
71
|
+
* @param skipWhenRuleIsDisabled
|
|
72
|
+
*/
|
|
73
|
+
walkOn(type: 'Element', walker: Walker<T, O, MLDOMElement<T, O>>, skipWhenRuleIsDisabled?: boolean): Promise<void>;
|
|
74
|
+
walkOn(type: 'Text', walker: Walker<T, O, MLDOMText<T, O>>, skipWhenRuleIsDisabled?: boolean): Promise<void>;
|
|
75
|
+
walkOn(type: 'Comment', walker: Walker<T, O, MLDOMComment<T, O>>, skipWhenRuleIsDisabled?: boolean): Promise<void>;
|
|
76
|
+
walkOn(type: 'ElementCloseTag', walker: Walker<T, O, MLDOMElementCloseTag<T, O>>, skipWhenRuleIsDisabled?: boolean): Promise<void>;
|
|
77
|
+
setRule(rule: MLRule<T, O> | null): void;
|
|
78
|
+
matchNodes(query: string): MLDOMElement<T, O>[];
|
|
79
|
+
querySelectorAll(query: string): MLDOMElement<T, O>[];
|
|
80
|
+
querySelector(query: string): MLDOMElement<T, O>;
|
|
81
|
+
getElementById(id: string): MLDOMElement<T, O>;
|
|
82
|
+
toString(): string;
|
|
83
|
+
debugMap(): string[];
|
|
84
|
+
private _ruleMapping;
|
|
81
85
|
}
|
package/lib/ml-dom/document.js
CHANGED
|
@@ -33,6 +33,20 @@ class MLDOMDocument {
|
|
|
33
33
|
*
|
|
34
34
|
*/
|
|
35
35
|
this.nodeStore = new helper_1.NodeStore();
|
|
36
|
+
/**
|
|
37
|
+
* Window object for calling the `getComputedStyle` and the `getPropertyValue` that are needed by **Accessible Name and Description Computation**.
|
|
38
|
+
* But it always returns the empty object.
|
|
39
|
+
* (It may improve to possible to compute the name from the `style` attribute in the future.)
|
|
40
|
+
*/
|
|
41
|
+
this.defaultView = {
|
|
42
|
+
getComputedStyle(_el) {
|
|
43
|
+
return {
|
|
44
|
+
getPropertyValue(_propName) {
|
|
45
|
+
return {};
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
};
|
|
36
50
|
_MLDOMDocument_filename.set(this, void 0);
|
|
37
51
|
this.isFragment = ast.isFragment;
|
|
38
52
|
this.specs = (0, ml_spec_1.getSpec)(schemas);
|
|
@@ -116,6 +130,15 @@ class MLDOMDocument {
|
|
|
116
130
|
matchNodes(query) {
|
|
117
131
|
return this.nodeList.filter((node) => node.type === 'Element' && node.matches(query));
|
|
118
132
|
}
|
|
133
|
+
querySelectorAll(query) {
|
|
134
|
+
return this.matchNodes(query);
|
|
135
|
+
}
|
|
136
|
+
querySelector(query) {
|
|
137
|
+
return this.querySelectorAll(query)[0] || null;
|
|
138
|
+
}
|
|
139
|
+
getElementById(id) {
|
|
140
|
+
return this.querySelector(`#${id}`);
|
|
141
|
+
}
|
|
119
142
|
toString() {
|
|
120
143
|
const html = [];
|
|
121
144
|
for (const node of this.nodeList) {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAccname = void 0;
|
|
4
|
+
const dom_accessibility_api_1 = require("dom-accessibility-api");
|
|
5
|
+
const debug_1 = require("../../debug");
|
|
6
|
+
const accnameLog = debug_1.log.extend('accname');
|
|
7
|
+
function getAccname(el) {
|
|
8
|
+
try {
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
const name = (0, dom_accessibility_api_1.computeAccessibleName)(el);
|
|
11
|
+
return name;
|
|
12
|
+
}
|
|
13
|
+
catch (err) {
|
|
14
|
+
accnameLog('Error: %O', err);
|
|
15
|
+
return '';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.getAccname = getAccname;
|
|
@@ -3,8 +3,4 @@ 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
|
import { MLDOMElement } from '../tokens';
|
|
6
|
-
export declare function createNode<N extends MLASTAbstructNode, T extends RuleConfigValue, O = null>(
|
|
7
|
-
astNode: N,
|
|
8
|
-
document: Document<T, O>,
|
|
9
|
-
pearNode?: MLDOMElement<T, O>,
|
|
10
|
-
): MappedNode<N, T, O>;
|
|
6
|
+
export declare function createNode<N extends MLASTAbstructNode, T extends RuleConfigValue, O = null>(astNode: N, document: Document<T, O>, pearNode?: MLDOMElement<T, O>): MappedNode<N, T, O>;
|
|
@@ -1,5 +1,2 @@
|
|
|
1
1
|
import type { AnonymousNode } from '@markuplint/ml-core';
|
|
2
|
-
export declare function nodeListToDebugMaps(
|
|
3
|
-
nodeList: Readonly<AnonymousNode<any, any>[]>,
|
|
4
|
-
withAttr?: boolean,
|
|
5
|
-
): string[];
|
|
2
|
+
export declare function nodeListToDebugMaps(nodeList: Readonly<AnonymousNode<any, any>[]>, withAttr?: boolean): string[];
|
|
@@ -48,7 +48,7 @@ function attributesToDebugMaps(attributes) {
|
|
|
48
48
|
r.push(` ${tokenDebug(n.equal, 'equal')}`);
|
|
49
49
|
r.push(` ${tokenDebug(n.spacesAfterEqual, 'aE')}`);
|
|
50
50
|
r.push(` ${tokenDebug(n.startQuote, 'sQ')}`);
|
|
51
|
-
r.push(` ${tokenDebug(n.
|
|
51
|
+
r.push(` ${tokenDebug(n.valueNode, 'value')}`);
|
|
52
52
|
r.push(` ${tokenDebug(n.endQuote, 'eQ')}`);
|
|
53
53
|
r.push(` isDirective: ${!!n.isDirective}`);
|
|
54
54
|
r.push(` isDynamicValue: ${!!n.isDynamicValue}`);
|
|
@@ -7,12 +7,12 @@ import type { AnonymousNode } from '../types';
|
|
|
7
7
|
*/
|
|
8
8
|
export declare function getIndent(node: AnonymousNode<any, any>): MLDOMIndentation | null;
|
|
9
9
|
declare class MLDOMIndentation {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
#private;
|
|
11
|
+
readonly line: number;
|
|
12
|
+
constructor(originTextNode: MLDOMText<any, any>, raw: string, line: number, parentNode: MLDOMNode<any, any>);
|
|
13
|
+
get type(): 'tab' | 'space' | 'mixed' | 'none';
|
|
14
|
+
get width(): number;
|
|
15
|
+
get raw(): string;
|
|
16
|
+
fix(raw: string): void;
|
|
17
17
|
}
|
|
18
18
|
export {};
|
|
@@ -1,52 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
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/';
|
|
1
|
+
import type { MLDOMAttribute, MLDOMComment, MLDOMDoctype, MLDOMElement, MLDOMElementCloseTag, MLDOMNode, MLDOMOmittedElement, MLDOMPreprocessorSpecificBlock, MLDOMText, MLDOMToken } from '../tokens';
|
|
2
|
+
import type { MLASTAbstructNode, MLASTAttr, MLASTComment, MLASTDoctype, MLASTElement, MLASTElementCloseTag, MLASTNode, MLASTOmittedElement, MLASTParentNode, MLASTPreprocessorSpecificBlock, MLASTText, MLToken } from '@markuplint/ml-ast/';
|
|
27
3
|
import type { RuleConfigValue } from '@markuplint/ml-config';
|
|
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;
|
|
4
|
+
export declare type MappedNode<N, T extends RuleConfigValue, O = null> = N extends MLASTElement ? MLDOMElement<T, O> : N extends MLASTElementCloseTag ? MLDOMElementCloseTag<T, O> : N extends MLASTOmittedElement ? MLDOMOmittedElement<T, O> : N extends MLASTParentNode ? (MLDOMElement<T, O> | MLDOMOmittedElement<T, O>) : N extends MLASTComment ? MLDOMComment<T, O> : N extends MLASTText ? MLDOMText<T, O> : N extends MLASTDoctype ? MLDOMDoctype<T, O> : N extends MLASTNode ? MLDOMNode<T, O, MLASTNode> : N extends MLASTPreprocessorSpecificBlock ? MLDOMPreprocessorSpecificBlock<T, O> : N extends MLASTAbstructNode ? MLDOMNode<T, O, MLASTAbstructNode> : N extends MLASTAttr ? MLDOMAttribute : N extends MLToken ? MLDOMToken<MLToken> : never;
|
|
@@ -3,18 +3,14 @@ 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(
|
|
16
|
-
el: TargetElement,
|
|
17
|
-
selector: string | RegexSelector | undefined,
|
|
18
|
-
tagNameCaseSensitive?: boolean,
|
|
19
|
-
): SelectorMatches;
|
|
15
|
+
export declare function matchSelector(el: TargetElement, selector: string | RegexSelector | undefined, tagNameCaseSensitive?: boolean): SelectorMatches;
|
|
20
16
|
export {};
|
|
@@ -3,10 +3,7 @@ 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
|
-
|
|
9
|
-
node: MLDOMNode<T, O, A>,
|
|
10
|
-
): void;
|
|
11
|
-
getNode<N extends MLASTAbstructNode, T extends RuleConfigValue, O = null>(astNode: N): MappedNode<N, T, O>;
|
|
6
|
+
#private;
|
|
7
|
+
setNode<A extends MLASTAbstructNode, T extends RuleConfigValue, O = null>(astNode: A, node: MLDOMNode<T, O, A>): void;
|
|
8
|
+
getNode<N extends MLASTAbstructNode, T extends RuleConfigValue, O = null>(astNode: N): MappedNode<N, T, O>;
|
|
12
9
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type MLDOMAbstractElement from '../tokens/abstract-element';
|
|
2
2
|
export declare type Specificity = [number, number, number];
|
|
3
3
|
export declare function createSelector(selector: string, tagNameCaseSensitive?: boolean): Selector;
|
|
4
|
-
export declare function compareSpecificity(a: Specificity, b: Specificity):
|
|
4
|
+
export declare function compareSpecificity(a: Specificity, b: Specificity): 1 | -1 | 0;
|
|
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,10 +1,5 @@
|
|
|
1
1
|
import type { AnonymousNode } from '../types';
|
|
2
2
|
import type { RuleConfigValue } from '@markuplint/ml-config';
|
|
3
|
-
export declare type Walker<T extends RuleConfigValue, O = null, N = AnonymousNode<T, O>> = (
|
|
4
|
-
node: N,
|
|
5
|
-
) => void | Promise<void>;
|
|
3
|
+
export declare type Walker<T extends RuleConfigValue, O = null, N = AnonymousNode<T, O>> = (node: N) => void | Promise<void>;
|
|
6
4
|
export declare type SyncWalker<T extends RuleConfigValue, O = null, N = AnonymousNode<T, O>> = (node: N) => void;
|
|
7
|
-
export declare function syncWalk<T extends RuleConfigValue, O = null>(
|
|
8
|
-
nodeList: AnonymousNode<T, O>[],
|
|
9
|
-
walker: SyncWalker<T, O>,
|
|
10
|
-
): void;
|
|
5
|
+
export declare function syncWalk<T extends RuleConfigValue, O = null>(nodeList: AnonymousNode<T, O>[], walker: SyncWalker<T, O>): void;
|
package/lib/ml-dom/index.d.ts
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
1
|
export { default as Document } from './document';
|
|
2
2
|
export { AnonymousNode, NodeType } from './types';
|
|
3
|
-
export {
|
|
4
|
-
MLDOMAttribute as Attribute,
|
|
5
|
-
MLDOMComment as Comment,
|
|
6
|
-
MLDOMDoctype as Doctype,
|
|
7
|
-
MLDOMElement as Element,
|
|
8
|
-
MLDOMElementCloseTag as ElementCloseTag,
|
|
9
|
-
MLDOMNode as Node,
|
|
10
|
-
MLDOMOmittedElement as OmittedElement,
|
|
11
|
-
MLDOMText as Text,
|
|
12
|
-
} from './tokens';
|
|
3
|
+
export { MLDOMAttribute as Attribute, MLDOMComment as Comment, MLDOMDoctype as Doctype, MLDOMElement as Element, MLDOMElementCloseTag as ElementCloseTag, MLDOMNode as Node, MLDOMOmittedElement as OmittedElement, MLDOMText as Text, } from './tokens';
|
|
@@ -3,14 +3,14 @@ import type { AnonymousNode } from './types';
|
|
|
3
3
|
import type { AnyRule } from '@markuplint/ml-config';
|
|
4
4
|
declare type RuleType = 'rules' | 'nodeRules' | 'childNodeRules';
|
|
5
5
|
declare type MappingLayer = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
from: RuleType;
|
|
7
|
+
specificity: Specificity;
|
|
8
|
+
rule: AnyRule;
|
|
9
9
|
};
|
|
10
10
|
export declare class RuleMapper<N extends AnonymousNode<any, any> = AnonymousNode<any, any>> {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
#private;
|
|
12
|
+
constructor(nodeList: ReadonlyArray<N>);
|
|
13
|
+
set(node: N, ruleName: string, rule: MappingLayer): void;
|
|
14
|
+
apply(): void;
|
|
15
15
|
}
|
|
16
16
|
export {};
|
|
@@ -5,44 +5,45 @@ import type { MLASTElement, MLASTOmittedElement } from '@markuplint/ml-ast';
|
|
|
5
5
|
import type { RuleConfigValue } from '@markuplint/ml-config';
|
|
6
6
|
import type { ContentModel } from '@markuplint/ml-spec';
|
|
7
7
|
import MLDOMNode from './node';
|
|
8
|
-
export default abstract class MLDOMAbstractElement<
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
8
|
+
export default abstract class MLDOMAbstractElement<T extends RuleConfigValue, O = null, E extends MLASTElement | MLASTOmittedElement = MLASTElement | MLASTOmittedElement> extends MLDOMNode<T, O, E> {
|
|
9
|
+
#private;
|
|
10
|
+
readonly nodeType = 1;
|
|
11
|
+
readonly nodeName: string;
|
|
12
|
+
readonly attributes: (MLDOMAttribute | MLDOMPreprocessorSpecificAttribute)[];
|
|
13
|
+
readonly hasSpreadAttr: boolean;
|
|
14
|
+
readonly namespaceURI: string;
|
|
15
|
+
readonly isForeignElement: boolean;
|
|
16
|
+
readonly ownModels: Set<ContentModel>;
|
|
17
|
+
readonly childModels: Set<ContentModel>;
|
|
18
|
+
readonly descendantModels: Set<ContentModel>;
|
|
19
|
+
readonly isCustomElement: boolean;
|
|
20
|
+
readonly isInFragmentDocument: boolean;
|
|
21
|
+
constructor(astNode: E, document: Document<T, O>);
|
|
22
|
+
get tagName(): string;
|
|
23
|
+
get childNodes(): AnonymousNode<T, O>[];
|
|
24
|
+
get children(): (MLDOMElement<T, O> | MLDOMOmittedElement<T, O>)[];
|
|
25
|
+
get nextElementSibling(): MLDOMElement<T, O> | MLDOMOmittedElement<T, O> | null;
|
|
26
|
+
get previousElementSibling(): MLDOMElement<T, O> | MLDOMOmittedElement<T, O> | null;
|
|
27
|
+
get ns(): string;
|
|
28
|
+
get nameWithNS(): string;
|
|
29
|
+
get classList(): string[];
|
|
30
|
+
get id(): string;
|
|
31
|
+
get fixedNodeName(): string;
|
|
32
|
+
get textContent(): string;
|
|
33
|
+
querySelectorAll(selector: string): (MLDOMElement<T, O> | MLDOMText<T, O>)[];
|
|
34
|
+
closest(selector: string): MLDOMAbstractElement<T, O> | null;
|
|
35
|
+
getAttributeToken(attrName: string): (MLDOMAttribute | MLDOMPreprocessorSpecificAttribute)[];
|
|
36
|
+
getAttributeNode(attrName: string): MLDOMAttribute | MLDOMPreprocessorSpecificAttribute;
|
|
37
|
+
getAttribute(attrName: string): string | null;
|
|
38
|
+
hasAttribute(attrName: string): boolean;
|
|
39
|
+
matches(selector: string): boolean;
|
|
40
|
+
fixNodeName(name: string): void;
|
|
41
|
+
getChildElementsAndTextNodeWithoutWhitespaces(): (MLDOMElement<T, O> | MLDOMText<T, O>)[];
|
|
42
|
+
/**
|
|
43
|
+
* This element has "Preprocessor Specific Block". In other words, Its children are potentially mutable.
|
|
44
|
+
*/
|
|
45
|
+
hasMutableChildren(): boolean;
|
|
46
|
+
isDescendantByUUIDList(uuidList: string[]): boolean;
|
|
47
|
+
getAccessibleName(): string;
|
|
48
|
+
toNormalizeString(): string;
|
|
48
49
|
}
|
|
@@ -4,11 +4,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const ml_spec_1 = require("@markuplint/ml-spec");
|
|
6
6
|
const helper_1 = require("../helper");
|
|
7
|
+
const accname_1 = require("../helper/accname");
|
|
7
8
|
const walkers_1 = require("../helper/walkers");
|
|
8
9
|
const node_1 = (0, tslib_1.__importDefault)(require("./node"));
|
|
9
10
|
class MLDOMAbstractElement extends node_1.default {
|
|
10
11
|
constructor(astNode, document) {
|
|
11
12
|
super(astNode, document);
|
|
13
|
+
this.nodeType = 1;
|
|
12
14
|
this.attributes = [];
|
|
13
15
|
this.hasSpreadAttr = false;
|
|
14
16
|
this.ownModels = new Set();
|
|
@@ -24,6 +26,9 @@ class MLDOMAbstractElement extends node_1.default {
|
|
|
24
26
|
this.isCustomElement = astNode.isCustomElement;
|
|
25
27
|
this.isInFragmentDocument = document.isFragment;
|
|
26
28
|
}
|
|
29
|
+
get tagName() {
|
|
30
|
+
return this.nodeName;
|
|
31
|
+
}
|
|
27
32
|
get childNodes() {
|
|
28
33
|
const astChildren = this._astToken.childNodes || [];
|
|
29
34
|
return astChildren.map(node => this.nodeStore.getNode(node));
|
|
@@ -81,7 +86,7 @@ class MLDOMAbstractElement extends node_1.default {
|
|
|
81
86
|
const classList = [];
|
|
82
87
|
const classAttrs = this.getAttributeToken('class');
|
|
83
88
|
for (const classAttr of classAttrs) {
|
|
84
|
-
const value = classAttr.attrType === 'html-attr' ? classAttr.value
|
|
89
|
+
const value = classAttr.attrType === 'html-attr' ? classAttr.value : classAttr.potentialValue;
|
|
85
90
|
classList.push(...value
|
|
86
91
|
.split(/\s+/g)
|
|
87
92
|
.map(c => c.trim())
|
|
@@ -95,6 +100,9 @@ class MLDOMAbstractElement extends node_1.default {
|
|
|
95
100
|
get fixedNodeName() {
|
|
96
101
|
return (0, tslib_1.__classPrivateFieldGet)(this, _MLDOMAbstractElement_fixedNodeName, "f");
|
|
97
102
|
}
|
|
103
|
+
get textContent() {
|
|
104
|
+
return this.childNodes.map(child => child.textContent || '').join('');
|
|
105
|
+
}
|
|
98
106
|
querySelectorAll(selector) {
|
|
99
107
|
const matchedNodes = [];
|
|
100
108
|
const selecor = (0, helper_1.createSelector)(selector);
|
|
@@ -129,12 +137,15 @@ class MLDOMAbstractElement extends node_1.default {
|
|
|
129
137
|
}
|
|
130
138
|
return attrs;
|
|
131
139
|
}
|
|
140
|
+
getAttributeNode(attrName) {
|
|
141
|
+
return this.getAttributeToken(attrName)[0] || null;
|
|
142
|
+
}
|
|
132
143
|
getAttribute(attrName) {
|
|
133
144
|
attrName = attrName.toLowerCase();
|
|
134
145
|
for (const attr of this.attributes) {
|
|
135
146
|
if (attr.potentialName === attrName) {
|
|
136
147
|
if (attr.attrType === 'html-attr') {
|
|
137
|
-
return attr.value ? attr.value
|
|
148
|
+
return attr.value ? attr.value : null;
|
|
138
149
|
}
|
|
139
150
|
else {
|
|
140
151
|
return attr.potentialValue;
|
|
@@ -191,6 +202,9 @@ class MLDOMAbstractElement extends node_1.default {
|
|
|
191
202
|
} while (el !== null && el.type === 'Element');
|
|
192
203
|
return false;
|
|
193
204
|
}
|
|
205
|
+
getAccessibleName() {
|
|
206
|
+
return (0, accname_1.getAccname)(this);
|
|
207
|
+
}
|
|
194
208
|
toNormalizeString() {
|
|
195
209
|
if ((0, tslib_1.__classPrivateFieldGet)(this, _MLDOMAbstractElement_normalizedString, "f")) {
|
|
196
210
|
return (0, tslib_1.__classPrivateFieldGet)(this, _MLDOMAbstractElement_normalizedString, "f");
|