@markuplint/ml-core 3.15.0 → 4.0.0-alpha.10
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/LICENSE +1 -1
- package/lib/configs.browser.js +11 -11
- package/lib/convert-ruleset.d.ts +1 -1
- package/lib/convert-ruleset.js +3 -8
- package/lib/debug.js +9 -14
- package/lib/index.d.ts +13 -23
- package/lib/index.js +12 -29
- package/lib/ml-core.d.ts +5 -5
- package/lib/ml-core.js +94 -76
- package/lib/ml-dom/helper/accname.d.ts +1 -1
- package/lib/ml-dom/helper/accname.js +12 -19
- package/lib/ml-dom/helper/create-node.d.ts +4 -8
- package/lib/ml-dom/helper/create-node.js +38 -17
- package/lib/ml-dom/helper/debug.d.ts +1 -1
- package/lib/ml-dom/helper/debug.js +13 -22
- package/lib/ml-dom/helper/get-indent.d.ts +18 -0
- package/lib/ml-dom/helper/get-indent.js +112 -0
- package/lib/ml-dom/helper/walkers.d.ts +5 -15
- package/lib/ml-dom/helper/walkers.js +3 -8
- package/lib/ml-dom/index.d.ts +9 -9
- package/lib/ml-dom/index.js +1 -5
- package/lib/ml-dom/manipulations/child-node-methods.d.ts +7 -20
- package/lib/ml-dom/manipulations/child-node-methods.js +13 -25
- package/lib/ml-dom/manipulations/get-children.d.ts +3 -5
- package/lib/ml-dom/manipulations/get-children.js +3 -7
- package/lib/ml-dom/node/attr.d.ts +113 -98
- package/lib/ml-dom/node/attr.js +93 -50
- package/lib/ml-dom/node/block.d.ts +35 -39
- package/lib/ml-dom/node/block.js +8 -14
- package/lib/ml-dom/node/character-data.d.ts +55 -62
- package/lib/ml-dom/node/character-data.js +11 -16
- package/lib/ml-dom/node/child-node.d.ts +8 -15
- package/lib/ml-dom/node/child-node.js +1 -5
- package/lib/ml-dom/node/comment.d.ts +14 -17
- package/lib/ml-dom/node/comment.js +2 -6
- package/lib/ml-dom/node/document-fragment.d.ts +22 -25
- package/lib/ml-dom/node/document-fragment.js +4 -9
- package/lib/ml-dom/node/document-type.d.ts +35 -38
- package/lib/ml-dom/node/document-type.js +8 -14
- package/lib/ml-dom/node/document.d.ts +1598 -1614
- package/lib/ml-dom/node/document.js +330 -275
- package/lib/ml-dom/node/dom-token-list.d.ts +27 -27
- package/lib/ml-dom/node/dom-token-list.js +36 -32
- package/lib/ml-dom/node/element-close-tag.d.ts +20 -0
- package/lib/ml-dom/node/element-close-tag.js +39 -0
- package/lib/ml-dom/node/element.d.ts +1957 -1951
- package/lib/ml-dom/node/element.js +364 -348
- package/lib/ml-dom/node/named-node-map.d.ts +40 -45
- package/lib/ml-dom/node/named-node-map.js +10 -18
- package/lib/ml-dom/node/node-list.d.ts +5 -11
- package/lib/ml-dom/node/node-list.js +8 -16
- package/lib/ml-dom/node/node-store.d.ts +6 -11
- package/lib/ml-dom/node/node-store.js +14 -13
- package/lib/ml-dom/node/node.d.ts +480 -500
- package/lib/ml-dom/node/node.js +83 -73
- package/lib/ml-dom/node/parent-node.d.ts +60 -69
- package/lib/ml-dom/node/parent-node.js +32 -29
- package/lib/ml-dom/node/rule-mapper.d.ts +9 -9
- package/lib/ml-dom/node/rule-mapper.js +26 -21
- package/lib/ml-dom/node/text.d.ts +48 -51
- package/lib/ml-dom/node/text.js +8 -13
- package/lib/ml-dom/node/types.d.ts +42 -90
- package/lib/ml-dom/node/types.js +1 -2
- package/lib/ml-dom/node/unexpected-call-error.d.ts +2 -1
- package/lib/ml-dom/node/unexpected-call-error.js +1 -4
- package/lib/ml-dom/token/token.d.ts +45 -45
- package/lib/ml-dom/token/token.js +32 -26
- package/lib/ml-rule/create-rule.d.ts +2 -4
- package/lib/ml-rule/create-rule.js +1 -5
- package/lib/ml-rule/create-test-rule.d.ts +5 -7
- package/lib/ml-rule/create-test-rule.js +3 -7
- package/lib/ml-rule/index.d.ts +3 -3
- package/lib/ml-rule/index.js +3 -6
- package/lib/ml-rule/ml-rule-context.d.ts +49 -57
- package/lib/ml-rule/ml-rule-context.js +11 -11
- package/lib/ml-rule/ml-rule.d.ts +26 -36
- package/lib/ml-rule/ml-rule.js +34 -31
- package/lib/ml-rule/types.d.ts +18 -33
- package/lib/ml-rule/types.js +1 -2
- package/lib/plugin/index.d.ts +2 -2
- package/lib/plugin/index.js +2 -5
- package/lib/plugin/plugin.d.ts +2 -4
- package/lib/plugin/plugin.js +1 -5
- package/lib/plugin/types.d.ts +6 -6
- package/lib/plugin/types.js +1 -2
- package/lib/ruleset/index.d.ts +5 -5
- package/lib/ruleset/index.js +4 -8
- package/lib/test/index.d.ts +11 -21
- package/lib/test/index.js +18 -24
- package/lib/types.d.ts +11 -11
- package/lib/types.js +1 -2
- package/lib/utils/get-location-from-chars.d.ts +4 -9
- package/lib/utils/get-location-from-chars.js +4 -8
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +1 -5
- package/lib/utils/string-splice.js +1 -5
- package/package.json +19 -15
- package/lib/configs.d.ts +0 -2
- package/lib/configs.js +0 -34
- package/lib/ml-dom/helper/getIndent.d.ts +0 -18
- package/lib/ml-dom/helper/getIndent.js +0 -106
- package/test/ml-dom/helper/accname.spec.js +0 -85
- package/test/ml-dom/helper/create-node.spec.js +0 -18
- package/test/ml-dom/index.spec.js +0 -680
- package/test/ml-dom/ml-rule/create-rule.spec.js +0 -108
|
@@ -1,18 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
+
};
|
|
6
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
7
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
|
+
};
|
|
2
12
|
var _MLParentNode_children, _MLParentNode_selectedElements;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const node_1 = require("./node");
|
|
9
|
-
const node_list_1 = require("./node-list");
|
|
10
|
-
const unexpected_call_error_1 = tslib_1.__importDefault(require("./unexpected-call-error"));
|
|
13
|
+
import { syncWalk } from '../helper/walkers.js';
|
|
14
|
+
import { getChildren } from '../manipulations/get-children.js';
|
|
15
|
+
import { toNodeList } from './node-list.js';
|
|
16
|
+
import { MLNode } from './node.js';
|
|
17
|
+
import { UnexpectedCallError } from './unexpected-call-error.js';
|
|
11
18
|
/**
|
|
12
19
|
*
|
|
13
20
|
* @see https://dom.spec.whatwg.org/#interface-parentnode
|
|
14
21
|
*/
|
|
15
|
-
class MLParentNode extends
|
|
22
|
+
export class MLParentNode extends MLNode {
|
|
16
23
|
constructor() {
|
|
17
24
|
super(...arguments);
|
|
18
25
|
/**
|
|
@@ -36,28 +43,26 @@ class MLParentNode extends node_1.MLNode {
|
|
|
36
43
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-children%E2%91%A0
|
|
37
44
|
*/
|
|
38
45
|
get children() {
|
|
39
|
-
if (
|
|
40
|
-
return
|
|
46
|
+
if (__classPrivateFieldGet(this, _MLParentNode_children, "f")) {
|
|
47
|
+
return __classPrivateFieldGet(this, _MLParentNode_children, "f");
|
|
41
48
|
}
|
|
42
|
-
const children =
|
|
43
|
-
|
|
44
|
-
return
|
|
49
|
+
const children = getChildren(this);
|
|
50
|
+
__classPrivateFieldSet(this, _MLParentNode_children, children, "f");
|
|
51
|
+
return __classPrivateFieldGet(this, _MLParentNode_children, "f");
|
|
45
52
|
}
|
|
46
53
|
/**
|
|
47
54
|
* @implements DOM API: `Element`, `Document`, `DocumentFragment`
|
|
48
55
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-firstelementchild%E2%91%A0
|
|
49
56
|
*/
|
|
50
57
|
get firstElementChild() {
|
|
51
|
-
|
|
52
|
-
return (_a = this.children[0]) !== null && _a !== void 0 ? _a : null;
|
|
58
|
+
return this.children[0] ?? null;
|
|
53
59
|
}
|
|
54
60
|
/**
|
|
55
61
|
* @implements DOM API: `Element`, `Document`, `DocumentFragment`
|
|
56
62
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-lastelementchild%E2%91%A0
|
|
57
63
|
*/
|
|
58
64
|
get lastElementChild() {
|
|
59
|
-
|
|
60
|
-
return (_a = this.children[0]) !== null && _a !== void 0 ? _a : null;
|
|
65
|
+
return this.children[0] ?? null;
|
|
61
66
|
}
|
|
62
67
|
/**
|
|
63
68
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -69,7 +74,7 @@ class MLParentNode extends node_1.MLNode {
|
|
|
69
74
|
append(
|
|
70
75
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
71
76
|
...nodes) {
|
|
72
|
-
throw new
|
|
77
|
+
throw new UnexpectedCallError('Not supported "append" method');
|
|
73
78
|
}
|
|
74
79
|
/**
|
|
75
80
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -81,32 +86,31 @@ class MLParentNode extends node_1.MLNode {
|
|
|
81
86
|
prepend(
|
|
82
87
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
83
88
|
...nodes) {
|
|
84
|
-
throw new
|
|
89
|
+
throw new UnexpectedCallError('Not supported "prepend" method');
|
|
85
90
|
}
|
|
86
91
|
/**
|
|
87
92
|
* @implements DOM API: `Element`, `Document`, `DocumentFragment`
|
|
88
93
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-queryselector%E2%91%A0
|
|
89
94
|
*/
|
|
90
95
|
querySelector(selectors) {
|
|
91
|
-
var _a;
|
|
92
96
|
const selected = this.querySelectorAll(selectors);
|
|
93
|
-
return
|
|
97
|
+
return selected[0] ?? null;
|
|
94
98
|
}
|
|
95
99
|
/**
|
|
96
100
|
* @implements DOM API: `Element`, `Document`, `DocumentFragment`
|
|
97
101
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-queryselectorall%E2%91%A0
|
|
98
102
|
*/
|
|
99
103
|
querySelectorAll(selectors) {
|
|
100
|
-
const selected =
|
|
104
|
+
const selected = __classPrivateFieldGet(this, _MLParentNode_selectedElements, "f").get(selectors);
|
|
101
105
|
if (selected) {
|
|
102
106
|
return selected;
|
|
103
107
|
}
|
|
104
|
-
const elements =
|
|
108
|
+
const elements = toNodeList(this._descendantsToArray(node => {
|
|
105
109
|
if (node.is(node.ELEMENT_NODE) && node.matches(selectors)) {
|
|
106
110
|
return node;
|
|
107
111
|
}
|
|
108
112
|
}));
|
|
109
|
-
|
|
113
|
+
__classPrivateFieldGet(this, _MLParentNode_selectedElements, "f").set(selectors, elements);
|
|
110
114
|
return elements;
|
|
111
115
|
}
|
|
112
116
|
/**
|
|
@@ -119,11 +123,11 @@ class MLParentNode extends node_1.MLNode {
|
|
|
119
123
|
replaceChildren(
|
|
120
124
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
121
125
|
...nodes) {
|
|
122
|
-
throw new
|
|
126
|
+
throw new UnexpectedCallError('Not supported "replaceChildren" method');
|
|
123
127
|
}
|
|
124
128
|
_descendantsToArray(filter) {
|
|
125
129
|
const nodeList = [];
|
|
126
|
-
|
|
130
|
+
syncWalk([...this.childNodes], node => {
|
|
127
131
|
if (filter) {
|
|
128
132
|
const filtered = filter(node);
|
|
129
133
|
if (filtered) {
|
|
@@ -136,5 +140,4 @@ class MLParentNode extends node_1.MLNode {
|
|
|
136
140
|
return Object.freeze(nodeList);
|
|
137
141
|
}
|
|
138
142
|
}
|
|
139
|
-
exports.MLParentNode = MLParentNode;
|
|
140
143
|
_MLParentNode_children = new WeakMap(), _MLParentNode_selectedElements = new WeakMap();
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import type { MLDocument } from './document';
|
|
2
|
-
import type { MLNode } from './node';
|
|
1
|
+
import type { MLDocument } from './document.js';
|
|
2
|
+
import type { MLNode } from './node.js';
|
|
3
3
|
import type { AnyRule } from '@markuplint/ml-config';
|
|
4
4
|
import type { Specificity } from '@markuplint/selector';
|
|
5
5
|
type RuleType = 'rules' | 'nodeRules' | 'childNodeRules';
|
|
6
6
|
type MappingLayer = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
readonly from: RuleType;
|
|
8
|
+
readonly specificity: Specificity;
|
|
9
|
+
readonly rule: AnyRule;
|
|
10
10
|
};
|
|
11
11
|
export declare class RuleMapper {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
#private;
|
|
13
|
+
constructor(document: MLDocument<any, any>);
|
|
14
|
+
apply(): void;
|
|
15
|
+
set(node: MLNode<any, any>, ruleName: string, rule: MappingLayer): void;
|
|
16
16
|
}
|
|
17
17
|
export {};
|
|
@@ -1,47 +1,53 @@
|
|
|
1
|
-
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
2
12
|
var _RuleMapper_nodeList, _RuleMapper_ruleMap;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const selector_1 = require("@markuplint/selector");
|
|
7
|
-
const debug_1 = require("../../debug");
|
|
8
|
-
const ruleMapperLog = debug_1.log.extend('rule-mapper');
|
|
13
|
+
import { compareSpecificity } from '@markuplint/selector';
|
|
14
|
+
import { log as coreLog } from '../../debug.js';
|
|
15
|
+
const ruleMapperLog = coreLog.extend('rule-mapper');
|
|
9
16
|
const ruleMapperNodeLog = ruleMapperLog.extend('node');
|
|
10
17
|
const ruleMapperNodeRuleLog = ruleMapperNodeLog.extend('rule');
|
|
11
|
-
class RuleMapper {
|
|
18
|
+
export class RuleMapper {
|
|
12
19
|
constructor(
|
|
13
20
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
14
21
|
document) {
|
|
15
22
|
_RuleMapper_nodeList.set(this, void 0);
|
|
16
23
|
_RuleMapper_ruleMap.set(this, new Map());
|
|
17
|
-
|
|
24
|
+
__classPrivateFieldSet(this, _RuleMapper_nodeList, Object.freeze([document, ...document.nodeList]), "f");
|
|
18
25
|
}
|
|
19
26
|
apply() {
|
|
20
27
|
ruleMapperLog('ruleTree:');
|
|
21
|
-
|
|
22
|
-
const rules =
|
|
28
|
+
for (const node of __classPrivateFieldGet(this, _RuleMapper_nodeList, "f")) {
|
|
29
|
+
const rules = __classPrivateFieldGet(this, _RuleMapper_ruleMap, "f").get(node.uuid);
|
|
23
30
|
if (!rules) {
|
|
24
|
-
|
|
31
|
+
continue;
|
|
25
32
|
}
|
|
26
33
|
ruleMapperNodeLog('<%s>', node.nodeName);
|
|
27
|
-
Object.keys(rules)
|
|
34
|
+
for (const ruleName of Object.keys(rules)) {
|
|
28
35
|
const rule = rules[ruleName];
|
|
29
36
|
if (!rule) {
|
|
30
|
-
|
|
37
|
+
continue;
|
|
31
38
|
}
|
|
32
39
|
node.rules[ruleName] = rule.rule;
|
|
33
40
|
ruleMapperNodeRuleLog('[from: %s(%s)] %s: %o', rule.from, rule.specificity, ruleName, rule.rule);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
36
43
|
}
|
|
37
44
|
set(
|
|
38
45
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
39
46
|
node, ruleName, rule) {
|
|
40
|
-
|
|
41
|
-
const rules = (_a = tslib_1.__classPrivateFieldGet(this, _RuleMapper_ruleMap, "f").get(node.uuid)) !== null && _a !== void 0 ? _a : {};
|
|
47
|
+
const rules = __classPrivateFieldGet(this, _RuleMapper_ruleMap, "f").get(node.uuid) ?? {};
|
|
42
48
|
const currentRule = rules[ruleName];
|
|
43
49
|
if (currentRule) {
|
|
44
|
-
const order =
|
|
50
|
+
const order = compareSpecificity(currentRule.specificity, rule.specificity);
|
|
45
51
|
if (order === 1) {
|
|
46
52
|
ruleMapperLog("Don't set %o ([%s] vs [%s])", rule, currentRule.specificity, rule.specificity);
|
|
47
53
|
return;
|
|
@@ -49,9 +55,8 @@ class RuleMapper {
|
|
|
49
55
|
ruleMapperLog('Unset %o from %s', currentRule, node);
|
|
50
56
|
}
|
|
51
57
|
rules[ruleName] = rule;
|
|
52
|
-
|
|
58
|
+
__classPrivateFieldGet(this, _RuleMapper_ruleMap, "f").set(node.uuid, rules);
|
|
53
59
|
ruleMapperLog('Set to %s from %s (%o): %O', node.nodeName, rule.from, rule.specificity, rule.rule);
|
|
54
60
|
}
|
|
55
61
|
}
|
|
56
|
-
exports.RuleMapper = RuleMapper;
|
|
57
62
|
_RuleMapper_nodeList = new WeakMap(), _RuleMapper_ruleMap = new WeakMap();
|
|
@@ -1,54 +1,51 @@
|
|
|
1
|
-
import type { TextNodeType } from './types';
|
|
1
|
+
import type { TextNodeType } from './types.js';
|
|
2
2
|
import type { MLASTText } from '@markuplint/ml-ast';
|
|
3
3
|
import type { PlainData, RuleConfigValue } from '@markuplint/ml-config';
|
|
4
|
-
import { MLCharacterData } from './character-data';
|
|
5
|
-
export declare class MLText<T extends RuleConfigValue, O extends PlainData = undefined>
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
* @see https://dom.spec.whatwg.org/#ref-for-dom-text-wholetext%E2%91%A0
|
|
52
|
-
*/
|
|
53
|
-
splitText(offset: number): Text;
|
|
4
|
+
import { MLCharacterData } from './character-data.js';
|
|
5
|
+
export declare class MLText<T extends RuleConfigValue, O extends PlainData = undefined> extends MLCharacterData<T, O, MLASTText> implements Text {
|
|
6
|
+
/**
|
|
7
|
+
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
8
|
+
*
|
|
9
|
+
* @unsupported
|
|
10
|
+
* @implements DOM API: `Text`
|
|
11
|
+
*/
|
|
12
|
+
get assignedSlot(): HTMLSlotElement;
|
|
13
|
+
/**
|
|
14
|
+
* Returns a string appropriate for the type of node as `Text`
|
|
15
|
+
*
|
|
16
|
+
* @see https://dom.spec.whatwg.org/#ref-for-attr%E2%91%A4
|
|
17
|
+
*/
|
|
18
|
+
get nodeName(): "#text";
|
|
19
|
+
/**
|
|
20
|
+
* Returns a number appropriate for the type of `Text`
|
|
21
|
+
*/
|
|
22
|
+
get nodeType(): TextNodeType;
|
|
23
|
+
get textContent(): string | null;
|
|
24
|
+
/**
|
|
25
|
+
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
26
|
+
*
|
|
27
|
+
* @unsupported
|
|
28
|
+
* @implements DOM API: `Text`
|
|
29
|
+
* @see https://dom.spec.whatwg.org/#ref-for-dom-text-splittext%E2%91%A0
|
|
30
|
+
*/
|
|
31
|
+
get wholeText(): string;
|
|
32
|
+
/**
|
|
33
|
+
* Returns `true` if a parent element is `<script>` or `<style>`
|
|
34
|
+
*
|
|
35
|
+
* @implements `@markuplint/ml-core` API: `MLText`
|
|
36
|
+
* @see https://html.spec.whatwg.org/multipage/syntax.html#raw-text-elements
|
|
37
|
+
*/
|
|
38
|
+
isRawTextElementContent(): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* @implements `@markuplint/ml-core` API: `MLText`
|
|
41
|
+
*/
|
|
42
|
+
isWhitespace(): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
45
|
+
*
|
|
46
|
+
* @unsupported
|
|
47
|
+
* @implements DOM API: `Text`
|
|
48
|
+
* @see https://dom.spec.whatwg.org/#ref-for-dom-text-wholetext%E2%91%A0
|
|
49
|
+
*/
|
|
50
|
+
splitText(offset: number): Text;
|
|
54
51
|
}
|
package/lib/ml-dom/node/text.js
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.MLText = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const character_data_1 = require("./character-data");
|
|
6
|
-
const unexpected_call_error_1 = tslib_1.__importDefault(require("./unexpected-call-error"));
|
|
1
|
+
import { MLCharacterData } from './character-data.js';
|
|
2
|
+
import { UnexpectedCallError } from './unexpected-call-error.js';
|
|
7
3
|
/**
|
|
8
4
|
* Raw text elements
|
|
9
5
|
*
|
|
10
6
|
* @see https://html.spec.whatwg.org/multipage/syntax.html#raw-text-elements
|
|
11
7
|
*/
|
|
12
|
-
const rawTextElements = ['script', 'style'];
|
|
13
|
-
class MLText extends
|
|
8
|
+
const rawTextElements = new Set(['script', 'style']);
|
|
9
|
+
export class MLText extends MLCharacterData {
|
|
14
10
|
/**
|
|
15
11
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
16
12
|
*
|
|
@@ -18,7 +14,7 @@ class MLText extends character_data_1.MLCharacterData {
|
|
|
18
14
|
* @implements DOM API: `Text`
|
|
19
15
|
*/
|
|
20
16
|
get assignedSlot() {
|
|
21
|
-
throw new
|
|
17
|
+
throw new UnexpectedCallError('Not supported "assignedSlot" property');
|
|
22
18
|
}
|
|
23
19
|
/**
|
|
24
20
|
* Returns a string appropriate for the type of node as `Text`
|
|
@@ -45,7 +41,7 @@ class MLText extends character_data_1.MLCharacterData {
|
|
|
45
41
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-text-splittext%E2%91%A0
|
|
46
42
|
*/
|
|
47
43
|
get wholeText() {
|
|
48
|
-
throw new
|
|
44
|
+
throw new UnexpectedCallError('Not supported "wholeText" property');
|
|
49
45
|
}
|
|
50
46
|
/**
|
|
51
47
|
* Returns `true` if a parent element is `<script>` or `<style>`
|
|
@@ -54,7 +50,7 @@ class MLText extends character_data_1.MLCharacterData {
|
|
|
54
50
|
* @see https://html.spec.whatwg.org/multipage/syntax.html#raw-text-elements
|
|
55
51
|
*/
|
|
56
52
|
isRawTextElementContent() {
|
|
57
|
-
return this.parentElement ? rawTextElements.
|
|
53
|
+
return this.parentElement ? rawTextElements.has(this.parentElement.nodeName.toLowerCase()) : false;
|
|
58
54
|
}
|
|
59
55
|
/**
|
|
60
56
|
* @implements `@markuplint/ml-core` API: `MLText`
|
|
@@ -70,7 +66,6 @@ class MLText extends character_data_1.MLCharacterData {
|
|
|
70
66
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-text-wholetext%E2%91%A0
|
|
71
67
|
*/
|
|
72
68
|
splitText(offset) {
|
|
73
|
-
throw new
|
|
69
|
+
throw new UnexpectedCallError('Not supported "splitText" method');
|
|
74
70
|
}
|
|
75
71
|
}
|
|
76
|
-
exports.MLText = MLText;
|
|
@@ -1,65 +1,16 @@
|
|
|
1
|
-
import type { MLAttr } from './attr';
|
|
2
|
-
import type { MLBlock } from './block';
|
|
3
|
-
import type { MLComment } from './comment';
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
import type { MLElement } from './element';
|
|
8
|
-
import type {
|
|
9
|
-
import type {
|
|
10
|
-
import type {
|
|
11
|
-
import type {
|
|
12
|
-
MLASTAbstractNode,
|
|
13
|
-
MLASTAttr,
|
|
14
|
-
MLASTComment,
|
|
15
|
-
MLASTDoctype,
|
|
16
|
-
MLASTElement,
|
|
17
|
-
MLASTParentNode,
|
|
18
|
-
MLASTPreprocessorSpecificBlock,
|
|
19
|
-
MLASTText,
|
|
20
|
-
MLToken as MLASTToken,
|
|
21
|
-
} from '@markuplint/ml-ast/';
|
|
1
|
+
import type { MLAttr } from './attr.js';
|
|
2
|
+
import type { MLBlock } from './block.js';
|
|
3
|
+
import type { MLComment } from './comment.js';
|
|
4
|
+
import type { MLDocumentFragment } from './document-fragment.js';
|
|
5
|
+
import type { MLDocumentType } from './document-type.js';
|
|
6
|
+
import type { MLDocument } from './document.js';
|
|
7
|
+
import type { MLElement } from './element.js';
|
|
8
|
+
import type { MLText } from './text.js';
|
|
9
|
+
import type { MLToken } from '../token/token.js';
|
|
10
|
+
import type { MLASTAttr, MLASTComment, MLASTDoctype, MLASTElement, MLASTInvalid, MLASTParentNode, MLASTPreprocessorSpecificBlock, MLASTText, MLASTToken as MLASTToken } from '@markuplint/ml-ast/';
|
|
22
11
|
import type { PlainData, PretenderARIA, RuleConfigValue } from '@markuplint/ml-config';
|
|
23
|
-
export type MappedNode<N, T extends RuleConfigValue, O extends PlainData = undefined> = N extends MLASTElement
|
|
24
|
-
|
|
25
|
-
: N extends MLASTParentNode
|
|
26
|
-
? MLElement<T, O>
|
|
27
|
-
: N extends MLASTComment
|
|
28
|
-
? MLComment<T, O>
|
|
29
|
-
: N extends MLASTText
|
|
30
|
-
? MLText<T, O>
|
|
31
|
-
: N extends MLASTDoctype
|
|
32
|
-
? MLDocumentType<T, O>
|
|
33
|
-
: N extends MLASTPreprocessorSpecificBlock
|
|
34
|
-
? MLBlock<T, O>
|
|
35
|
-
: N extends MLASTAbstractNode
|
|
36
|
-
? MLNode<T, O, MLASTAbstractNode>
|
|
37
|
-
: N extends MLASTAttr
|
|
38
|
-
? MLAttr<T, O>
|
|
39
|
-
: N extends MLASTToken
|
|
40
|
-
? MLToken
|
|
41
|
-
: never;
|
|
42
|
-
export type NodeTypeOf<
|
|
43
|
-
NT extends NodeType,
|
|
44
|
-
T extends RuleConfigValue,
|
|
45
|
-
O extends PlainData = undefined,
|
|
46
|
-
> = NT extends ElementNodeType
|
|
47
|
-
? MLElement<T, O>
|
|
48
|
-
: NT extends CommentNodeType
|
|
49
|
-
? MLComment<T, O>
|
|
50
|
-
: NT extends TextNodeType
|
|
51
|
-
? MLText<T, O>
|
|
52
|
-
: NT extends DocumentNodeType
|
|
53
|
-
? MLDocument<T, O>
|
|
54
|
-
: NT extends DocumentTypeNodeType
|
|
55
|
-
? MLDocumentType<T, O>
|
|
56
|
-
: NT extends DocumentFragmentNodeType
|
|
57
|
-
? MLDocumentFragment<T, O>
|
|
58
|
-
: NT extends MarkuplintPreprocessorBlockType
|
|
59
|
-
? MLBlock<T, O>
|
|
60
|
-
: NT extends AttributeNodeType
|
|
61
|
-
? MLAttr<T, O>
|
|
62
|
-
: never;
|
|
12
|
+
export type MappedNode<N, T extends RuleConfigValue, O extends PlainData = undefined> = N extends MLASTElement ? MLElement<T, O> : N extends MLASTParentNode ? MLElement<T, O> : N extends MLASTComment ? MLComment<T, O> : N extends MLASTText ? MLText<T, O> : N extends MLASTDoctype ? MLDocumentType<T, O> : N extends MLASTPreprocessorSpecificBlock ? MLBlock<T, O> : N extends MLASTAttr ? MLAttr<T, O> : N extends MLASTInvalid ? MLText<T, O> : N extends MLASTToken ? MLToken : never;
|
|
13
|
+
export type NodeTypeOf<NT extends NodeType, T extends RuleConfigValue, O extends PlainData = undefined> = NT extends ElementNodeType ? MLElement<T, O> : NT extends CommentNodeType ? MLComment<T, O> : NT extends TextNodeType ? MLText<T, O> : NT extends DocumentNodeType ? MLDocument<T, O> : NT extends DocumentTypeNodeType ? MLDocumentType<T, O> : NT extends DocumentFragmentNodeType ? MLDocumentFragment<T, O> : NT extends MarkuplintPreprocessorBlockType ? MLBlock<T, O> : NT extends AttributeNodeType ? MLAttr<T, O> : never;
|
|
63
14
|
export type ElementNodeType = 1;
|
|
64
15
|
export type AttributeNodeType = 2;
|
|
65
16
|
export type TextNodeType = 3;
|
|
@@ -70,34 +21,35 @@ export type DocumentNodeType = 9;
|
|
|
70
21
|
export type DocumentTypeNodeType = 10;
|
|
71
22
|
export type DocumentFragmentNodeType = 11;
|
|
72
23
|
export type MarkuplintPreprocessorBlockType = 101;
|
|
73
|
-
export type NodeType =
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
| CommentNodeType
|
|
80
|
-
| DocumentNodeType
|
|
81
|
-
| DocumentTypeNodeType
|
|
82
|
-
| DocumentFragmentNodeType
|
|
83
|
-
| MarkuplintPreprocessorBlockType;
|
|
84
|
-
export type PretenderContext<N extends MLElement<T, O>, T extends RuleConfigValue, O extends PlainData = undefined> =
|
|
85
|
-
| PretenderContextPretender<N, T, O>
|
|
86
|
-
| PretenderContextPretended<N, T, O>;
|
|
87
|
-
export type PretenderContextPretender<
|
|
88
|
-
N extends MLElement<T, O>,
|
|
89
|
-
T extends RuleConfigValue,
|
|
90
|
-
O extends PlainData = undefined,
|
|
91
|
-
> = {
|
|
92
|
-
readonly type: 'pretender';
|
|
93
|
-
readonly as: N;
|
|
94
|
-
readonly aria?: PretenderARIA;
|
|
24
|
+
export type NodeType = ElementNodeType | AttributeNodeType | TextNodeType | CDATASectionNodeType | ProcessingInstructionNodeType | CommentNodeType | DocumentNodeType | DocumentTypeNodeType | DocumentFragmentNodeType | MarkuplintPreprocessorBlockType;
|
|
25
|
+
export type PretenderContext<N extends MLElement<T, O>, T extends RuleConfigValue, O extends PlainData = undefined> = PretenderContextPretender<N, T, O> | PretenderContextPretended<N, T, O>;
|
|
26
|
+
export type PretenderContextPretender<N extends MLElement<T, O>, T extends RuleConfigValue, O extends PlainData = undefined> = {
|
|
27
|
+
readonly type: 'pretender';
|
|
28
|
+
readonly as: N;
|
|
29
|
+
readonly aria?: PretenderARIA;
|
|
95
30
|
};
|
|
96
|
-
export type PretenderContextPretended<
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
31
|
+
export type PretenderContextPretended<N extends MLElement<T, O>, T extends RuleConfigValue, O extends PlainData = undefined> = {
|
|
32
|
+
readonly type: 'origin';
|
|
33
|
+
readonly origin: N;
|
|
34
|
+
};
|
|
35
|
+
export type AccessibilityProperties = ClearlyAccessibilityProperties | UnknownAccessibilityProperties;
|
|
36
|
+
export type ClearlyAccessibilityProperties = {
|
|
37
|
+
unknown: false;
|
|
38
|
+
exposedToTree: boolean;
|
|
39
|
+
role?: string;
|
|
40
|
+
roleDescription?: string;
|
|
41
|
+
name?: string | {
|
|
42
|
+
unknown: true;
|
|
43
|
+
};
|
|
44
|
+
nameRequired?: boolean;
|
|
45
|
+
nameProhibited?: boolean;
|
|
46
|
+
focusable?: boolean;
|
|
47
|
+
props?: Record<string, AccessibilityProperty>;
|
|
48
|
+
};
|
|
49
|
+
export type UnknownAccessibilityProperties = {
|
|
50
|
+
unknown: true;
|
|
51
|
+
};
|
|
52
|
+
export type AccessibilityProperty = {
|
|
53
|
+
value: string | null;
|
|
54
|
+
required: boolean;
|
|
103
55
|
};
|
package/lib/ml-dom/node/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare class UnexpectedCallError extends Error {
|
|
2
|
+
}
|