@markuplint/ml-core 4.0.0-alpha.2 → 4.0.0-dev.28
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.browser.js +3 -1
- package/lib/configs.js +4 -4
- package/lib/index.d.ts +2 -1
- package/lib/index.js +1 -1
- package/lib/ml-core.d.ts +2 -2
- package/lib/ml-core.js +44 -20
- package/lib/ml-dom/helper/accname.js +3 -3
- package/lib/ml-dom/helper/debug.js +11 -15
- package/lib/ml-dom/helper/{getIndent.js → get-indent.js} +14 -4
- package/lib/ml-dom/helper/walkers.js +1 -1
- package/lib/ml-dom/manipulations/get-children.js +1 -1
- package/lib/ml-dom/node/attr.js +11 -1
- package/lib/ml-dom/node/document.d.ts +2 -1
- package/lib/ml-dom/node/document.js +90 -28
- package/lib/ml-dom/node/dom-token-list.js +12 -2
- package/lib/ml-dom/node/element.d.ts +4 -0
- package/lib/ml-dom/node/element.js +35 -17
- package/lib/ml-dom/node/node-list.js +2 -2
- package/lib/ml-dom/node/node-store.js +7 -3
- package/lib/ml-dom/node/node.js +13 -2
- package/lib/ml-dom/node/parent-node.js +12 -2
- package/lib/ml-dom/node/rule-mapper.js +17 -7
- package/lib/ml-dom/node/text.js +2 -2
- package/lib/ml-dom/node/types.d.ts +21 -0
- package/lib/ml-dom/token/token.js +11 -1
- package/lib/ml-rule/ml-rule-context.js +6 -2
- package/lib/ml-rule/ml-rule.js +12 -2
- package/lib/test/index.js +1 -1
- package/lib/utils/get-location-from-chars.js +2 -2
- package/package.json +13 -14
- /package/lib/ml-dom/helper/{getIndent.d.ts → get-indent.d.ts} +0 -0
package/lib/configs.browser.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export async function getPreset(name) {
|
|
2
|
-
const res = await fetch(`@markuplint/config-presets/preset.${name}.json`).catch(() =>
|
|
2
|
+
const res = await fetch(`@markuplint/config-presets/preset.${name}.json`).catch(() =>
|
|
3
|
+
// eslint-disable-next-line unicorn/error-message
|
|
4
|
+
new Error());
|
|
3
5
|
if (res instanceof Error) {
|
|
4
6
|
throw new ReferenceError(`Preset markuplint:${name} is not found`);
|
|
5
7
|
}
|
package/lib/configs.js
CHANGED
|
@@ -18,7 +18,7 @@ async function forceImportJsonInModule(modPath) {
|
|
|
18
18
|
if (error.code !== 'ERR_IMPORT_ASSERTION_TYPE_MISSING') {
|
|
19
19
|
throw error;
|
|
20
20
|
}
|
|
21
|
-
const searchPath = /
|
|
21
|
+
const searchPath = /module\s"([^"]+)"\sneeds/i.exec(error.message);
|
|
22
22
|
const absPath = searchPath?.[1] ?? null;
|
|
23
23
|
log('Extract path: %s', absPath);
|
|
24
24
|
if (!absPath) {
|
|
@@ -26,12 +26,12 @@ async function forceImportJsonInModule(modPath) {
|
|
|
26
26
|
}
|
|
27
27
|
const normalizePath = absPath
|
|
28
28
|
.replace(/^file:\/\//, '')
|
|
29
|
-
.
|
|
29
|
+
.replaceAll('/', path.sep)
|
|
30
30
|
// Windows
|
|
31
|
-
.replace(/^[
|
|
31
|
+
.replace(/^[/\\][a-z]:/i, '');
|
|
32
32
|
log('Find JSON file path: %s', normalizePath);
|
|
33
33
|
const fileContent = await readFile(normalizePath, { encoding: 'utf8' });
|
|
34
34
|
return JSON.parse(fileContent);
|
|
35
35
|
}
|
|
36
|
-
return error.default
|
|
36
|
+
return error.default ?? error;
|
|
37
37
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { RuleInfo, RuleConfig, RuleConfigValue } from '@markuplint/ml-config';
|
|
|
2
2
|
export { ariaSpecs, contentModelCategoryToTagNames, getAttrSpecs, getComputedRole, getImplicitRole, getPermittedRoles, getRoleSpec, getSpec, resolveNamespace, } from '@markuplint/ml-spec';
|
|
3
3
|
export { default as Ruleset } from './ruleset/index.js';
|
|
4
4
|
export { enableDebug } from './debug.js';
|
|
5
|
-
export { getIndent } from './ml-dom/helper/
|
|
5
|
+
export { getIndent } from './ml-dom/helper/get-indent.js';
|
|
6
6
|
export * from './configs.js';
|
|
7
7
|
export * from './convert-ruleset.js';
|
|
8
8
|
export * from './ml-core.js';
|
|
@@ -12,3 +12,4 @@ export * from './plugin/index.js';
|
|
|
12
12
|
export * from './test/index.js';
|
|
13
13
|
export * from './types.js';
|
|
14
14
|
export * from './utils/index.js';
|
|
15
|
+
export { AccessibilityProperties } from './ml-dom/node/types.js';
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { ariaSpecs, contentModelCategoryToTagNames, getAttrSpecs, getComputedRole, getImplicitRole, getPermittedRoles, getRoleSpec, getSpec, resolveNamespace, } from '@markuplint/ml-spec';
|
|
2
2
|
export { default as Ruleset } from './ruleset/index.js';
|
|
3
3
|
export { enableDebug } from './debug.js';
|
|
4
|
-
export { getIndent } from './ml-dom/helper/
|
|
4
|
+
export { getIndent } from './ml-dom/helper/get-indent.js';
|
|
5
5
|
export * from './configs.js';
|
|
6
6
|
export * from './convert-ruleset.js';
|
|
7
7
|
export * from './ml-core.js';
|
package/lib/ml-core.d.ts
CHANGED
|
@@ -9,10 +9,10 @@ export type MLCoreParams = {
|
|
|
9
9
|
} & MLFabric;
|
|
10
10
|
export declare class MLCore {
|
|
11
11
|
#private;
|
|
12
|
-
constructor({ parser, sourceCode, ruleset, rules, locale, schemas, parserOptions, pretenders, filename, debug, }: MLCoreParams);
|
|
12
|
+
constructor({ parser, sourceCode, ruleset, rules, locale, schemas, parserOptions, pretenders, filename, debug, configErrors, }: MLCoreParams);
|
|
13
13
|
get document(): ParserError | Document<RuleConfigValue, PlainData>;
|
|
14
14
|
setCode(sourceCode: string): void;
|
|
15
|
-
update({ parser, ruleset, rules, locale, schemas, parserOptions }: Partial<MLFabric>): void;
|
|
15
|
+
update({ parser, ruleset, rules, locale, schemas, parserOptions, configErrors }: Partial<MLFabric>): void;
|
|
16
16
|
verify(fix?: boolean): Promise<Violation[]>;
|
|
17
17
|
private _createDocument;
|
|
18
18
|
private _parse;
|
package/lib/ml-core.js
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
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
|
+
};
|
|
12
|
+
var _MLCore_ast, _MLCore_document, _MLCore_filename, _MLCore_locale, _MLCore_parser, _MLCore_parserOptions, _MLCore_pretenders, _MLCore_rules, _MLCore_ruleset, _MLCore_schemas, _MLCore_sourceCode, _MLCore_configErrors;
|
|
3
13
|
import { ParserError } from '@markuplint/parser-utils';
|
|
4
14
|
import { log, enableDebug } from './debug.js';
|
|
5
15
|
import { Document } from './ml-dom/index.js';
|
|
6
16
|
const resultLog = log.extend('result');
|
|
7
17
|
export class MLCore {
|
|
8
|
-
constructor({ parser, sourceCode, ruleset, rules, locale, schemas, parserOptions, pretenders, filename, debug, }) {
|
|
18
|
+
constructor({ parser, sourceCode, ruleset, rules, locale, schemas, parserOptions, pretenders, filename, debug, configErrors, }) {
|
|
9
19
|
_MLCore_ast.set(this, null);
|
|
10
20
|
_MLCore_document.set(this, void 0);
|
|
11
21
|
_MLCore_filename.set(this, void 0);
|
|
@@ -17,6 +27,7 @@ export class MLCore {
|
|
|
17
27
|
_MLCore_ruleset.set(this, void 0);
|
|
18
28
|
_MLCore_schemas.set(this, void 0);
|
|
19
29
|
_MLCore_sourceCode.set(this, void 0);
|
|
30
|
+
_MLCore_configErrors.set(this, void 0);
|
|
20
31
|
if (debug) {
|
|
21
32
|
enableDebug();
|
|
22
33
|
}
|
|
@@ -31,8 +42,9 @@ export class MLCore {
|
|
|
31
42
|
__classPrivateFieldSet(this, _MLCore_locale, locale, "f");
|
|
32
43
|
__classPrivateFieldSet(this, _MLCore_schemas, schemas, "f");
|
|
33
44
|
__classPrivateFieldSet(this, _MLCore_filename, filename, "f");
|
|
34
|
-
__classPrivateFieldSet(this, _MLCore_rules, rules
|
|
35
|
-
__classPrivateFieldSet(this, _MLCore_pretenders, pretenders
|
|
45
|
+
__classPrivateFieldSet(this, _MLCore_rules, [...rules], "f");
|
|
46
|
+
__classPrivateFieldSet(this, _MLCore_pretenders, [...pretenders], "f");
|
|
47
|
+
__classPrivateFieldSet(this, _MLCore_configErrors, [...(configErrors ?? [])], "f");
|
|
36
48
|
this._parse();
|
|
37
49
|
this._createDocument();
|
|
38
50
|
}
|
|
@@ -44,7 +56,7 @@ export class MLCore {
|
|
|
44
56
|
this._parse();
|
|
45
57
|
this._createDocument();
|
|
46
58
|
}
|
|
47
|
-
update({ parser, ruleset, rules, locale, schemas, parserOptions }) {
|
|
59
|
+
update({ parser, ruleset, rules, locale, schemas, parserOptions, configErrors }) {
|
|
48
60
|
__classPrivateFieldSet(this, _MLCore_parser, parser ?? __classPrivateFieldGet(this, _MLCore_parser, "f"), "f");
|
|
49
61
|
__classPrivateFieldSet(this, _MLCore_ruleset, {
|
|
50
62
|
rules: ruleset?.rules ?? __classPrivateFieldGet(this, _MLCore_ruleset, "f").rules,
|
|
@@ -54,6 +66,7 @@ export class MLCore {
|
|
|
54
66
|
__classPrivateFieldSet(this, _MLCore_rules, rules?.slice() ?? __classPrivateFieldGet(this, _MLCore_rules, "f"), "f");
|
|
55
67
|
__classPrivateFieldSet(this, _MLCore_locale, locale ?? __classPrivateFieldGet(this, _MLCore_locale, "f"), "f");
|
|
56
68
|
__classPrivateFieldSet(this, _MLCore_schemas, schemas ?? __classPrivateFieldGet(this, _MLCore_schemas, "f"), "f");
|
|
69
|
+
__classPrivateFieldSet(this, _MLCore_configErrors, [...(configErrors ?? [])], "f");
|
|
57
70
|
if (parserOptions &&
|
|
58
71
|
(parserOptions.ignoreFrontMatter !== __classPrivateFieldGet(this, _MLCore_parserOptions, "f").ignoreFrontMatter ||
|
|
59
72
|
parserOptions.authoredElementName !== __classPrivateFieldGet(this, _MLCore_parserOptions, "f").authoredElementName)) {
|
|
@@ -76,17 +89,27 @@ export class MLCore {
|
|
|
76
89
|
log('verify: error %o', __classPrivateFieldGet(this, _MLCore_document, "f").message);
|
|
77
90
|
return violations;
|
|
78
91
|
}
|
|
92
|
+
for (const error of __classPrivateFieldGet(this, _MLCore_configErrors, "f")) {
|
|
93
|
+
violations.push({
|
|
94
|
+
ruleId: 'config-error',
|
|
95
|
+
severity: 'warning',
|
|
96
|
+
message: error.message,
|
|
97
|
+
col: 1,
|
|
98
|
+
line: 1,
|
|
99
|
+
raw: '',
|
|
100
|
+
});
|
|
101
|
+
}
|
|
79
102
|
for (const rule of __classPrivateFieldGet(this, _MLCore_rules, "f")) {
|
|
80
103
|
const ruleInfo = rule.getRuleInfo(__classPrivateFieldGet(this, _MLCore_ruleset, "f"), rule.name);
|
|
81
104
|
if (ruleInfo.disabled && ruleInfo.nodeRules.length === 0 && ruleInfo.childNodeRules.length === 0) {
|
|
82
105
|
continue;
|
|
83
106
|
}
|
|
84
107
|
log('%s Rule: verify', rule.name);
|
|
85
|
-
const results = await rule.verify(__classPrivateFieldGet(this, _MLCore_document, "f"), __classPrivateFieldGet(this, _MLCore_locale, "f"), fix).catch(
|
|
86
|
-
if (
|
|
87
|
-
return
|
|
108
|
+
const results = await rule.verify(__classPrivateFieldGet(this, _MLCore_document, "f"), __classPrivateFieldGet(this, _MLCore_locale, "f"), fix).catch(error => {
|
|
109
|
+
if (error instanceof ParserError) {
|
|
110
|
+
return error;
|
|
88
111
|
}
|
|
89
|
-
throw
|
|
112
|
+
throw error;
|
|
90
113
|
});
|
|
91
114
|
if (results instanceof ParserError) {
|
|
92
115
|
log('%s Rule: verify error %o', rule.name, results.message);
|
|
@@ -105,6 +128,7 @@ export class MLCore {
|
|
|
105
128
|
log('%s Rule: verify end', rule.name);
|
|
106
129
|
}
|
|
107
130
|
if (resultLog.enabled) {
|
|
131
|
+
// eslint-disable-next-line unicorn/no-array-reduce
|
|
108
132
|
const { e, w, i } = violations.reduce((c, v) => {
|
|
109
133
|
if (v.severity === 'error')
|
|
110
134
|
c.e += 1;
|
|
@@ -133,12 +157,12 @@ export class MLCore {
|
|
|
133
157
|
pretenders: __classPrivateFieldGet(this, _MLCore_pretenders, "f"),
|
|
134
158
|
}), "f");
|
|
135
159
|
}
|
|
136
|
-
catch (
|
|
137
|
-
if (
|
|
138
|
-
__classPrivateFieldSet(this, _MLCore_document,
|
|
160
|
+
catch (error) {
|
|
161
|
+
if (error instanceof ParserError) {
|
|
162
|
+
__classPrivateFieldSet(this, _MLCore_document, error, "f");
|
|
139
163
|
}
|
|
140
164
|
else {
|
|
141
|
-
throw
|
|
165
|
+
throw error;
|
|
142
166
|
}
|
|
143
167
|
}
|
|
144
168
|
}
|
|
@@ -146,16 +170,16 @@ export class MLCore {
|
|
|
146
170
|
try {
|
|
147
171
|
__classPrivateFieldSet(this, _MLCore_ast, __classPrivateFieldGet(this, _MLCore_parser, "f").parse(__classPrivateFieldGet(this, _MLCore_sourceCode, "f"), __classPrivateFieldGet(this, _MLCore_parserOptions, "f")), "f");
|
|
148
172
|
}
|
|
149
|
-
catch (
|
|
150
|
-
log('Caught the parse error: %O',
|
|
173
|
+
catch (error) {
|
|
174
|
+
log('Caught the parse error: %O', error);
|
|
151
175
|
__classPrivateFieldSet(this, _MLCore_ast, null, "f");
|
|
152
|
-
if (
|
|
153
|
-
__classPrivateFieldSet(this, _MLCore_document,
|
|
176
|
+
if (error instanceof ParserError) {
|
|
177
|
+
__classPrivateFieldSet(this, _MLCore_document, error, "f");
|
|
154
178
|
}
|
|
155
179
|
else {
|
|
156
|
-
throw
|
|
180
|
+
throw error;
|
|
157
181
|
}
|
|
158
182
|
}
|
|
159
183
|
}
|
|
160
184
|
}
|
|
161
|
-
_MLCore_ast = new WeakMap(), _MLCore_document = new WeakMap(), _MLCore_filename = new WeakMap(), _MLCore_locale = new WeakMap(), _MLCore_parser = new WeakMap(), _MLCore_parserOptions = new WeakMap(), _MLCore_pretenders = new WeakMap(), _MLCore_rules = new WeakMap(), _MLCore_ruleset = new WeakMap(), _MLCore_schemas = new WeakMap(), _MLCore_sourceCode = new WeakMap();
|
|
185
|
+
_MLCore_ast = new WeakMap(), _MLCore_document = new WeakMap(), _MLCore_filename = new WeakMap(), _MLCore_locale = new WeakMap(), _MLCore_parser = new WeakMap(), _MLCore_parserOptions = new WeakMap(), _MLCore_pretenders = new WeakMap(), _MLCore_rules = new WeakMap(), _MLCore_ruleset = new WeakMap(), _MLCore_schemas = new WeakMap(), _MLCore_sourceCode = new WeakMap(), _MLCore_configErrors = new WeakMap();
|
|
@@ -16,7 +16,7 @@ el, version) {
|
|
|
16
16
|
return '';
|
|
17
17
|
}
|
|
18
18
|
if (isFromContent(el, version)) {
|
|
19
|
-
return
|
|
19
|
+
return [...el.childNodes]
|
|
20
20
|
.map(child => {
|
|
21
21
|
if (child.is(child.ELEMENT_NODE)) {
|
|
22
22
|
return getAccname(child, version);
|
|
@@ -37,9 +37,9 @@ el) {
|
|
|
37
37
|
const name = get(el);
|
|
38
38
|
return name;
|
|
39
39
|
}
|
|
40
|
-
catch (
|
|
40
|
+
catch (error) {
|
|
41
41
|
accnameLog('Raw: %s', el.raw);
|
|
42
|
-
accnameLog('Error: %O',
|
|
42
|
+
accnameLog('Error: %O', error);
|
|
43
43
|
return '';
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
export function nodeListToDebugMaps(
|
|
2
2
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
3
3
|
nodeList, withAttr = false) {
|
|
4
|
-
return nodeList
|
|
5
|
-
.map(n => {
|
|
4
|
+
return nodeList.flatMap(n => {
|
|
6
5
|
const r = [];
|
|
7
6
|
if (n.is(n.ELEMENT_NODE) && n.isOmitted) {
|
|
8
7
|
r.push(`[N/A]>[N/A](N/A)${n.nodeName}: ${visibleWhiteSpace(n.raw)}`);
|
|
@@ -10,10 +9,9 @@ nodeList, withAttr = false) {
|
|
|
10
9
|
}
|
|
11
10
|
r.push(tokenDebug(n));
|
|
12
11
|
if (n.is(n.ELEMENT_NODE)) {
|
|
13
|
-
r.push(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
r.push(` isForeignElement: ${!!n.isForeignElement}`);
|
|
12
|
+
r.push(
|
|
13
|
+
//
|
|
14
|
+
` namespaceURI: ${!!n.namespaceURI}`, ` elementType: ${n.elementType}`, ` isInFragmentDocument: ${n.isInFragmentDocument()}`, ` isForeignElement: ${!!n.isForeignElement}`);
|
|
17
15
|
if (withAttr) {
|
|
18
16
|
r.push(...attributesToDebugMaps(n.attributes)
|
|
19
17
|
.flat()
|
|
@@ -21,14 +19,12 @@ nodeList, withAttr = false) {
|
|
|
21
19
|
}
|
|
22
20
|
}
|
|
23
21
|
return r;
|
|
24
|
-
})
|
|
25
|
-
.flat();
|
|
22
|
+
});
|
|
26
23
|
}
|
|
27
24
|
function attributesToDebugMaps(
|
|
28
25
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
29
26
|
attributes) {
|
|
30
|
-
return attributes
|
|
31
|
-
.map(n => {
|
|
27
|
+
return attributes.flatMap(n => {
|
|
32
28
|
const r = [
|
|
33
29
|
tokenDebug({
|
|
34
30
|
name: n.name,
|
|
@@ -66,19 +62,19 @@ attributes) {
|
|
|
66
62
|
r.push(` ${tokenDebug(n.endQuote, 'eQ')}`);
|
|
67
63
|
}
|
|
68
64
|
if (n.spacesBeforeName) {
|
|
69
|
-
r.push(
|
|
70
|
-
|
|
65
|
+
r.push(
|
|
66
|
+
//
|
|
67
|
+
` isDirective: ${!!n.isDirective}`, ` isDynamicValue: ${!!n.isDynamicValue}`);
|
|
71
68
|
}
|
|
72
69
|
if (n.candidate) {
|
|
73
70
|
r.push(` candidate: ${visibleWhiteSpace(n.candidate)}`);
|
|
74
71
|
}
|
|
75
72
|
return r;
|
|
76
|
-
})
|
|
77
|
-
.flat();
|
|
73
|
+
});
|
|
78
74
|
}
|
|
79
75
|
function tokenDebug(n, type = '') {
|
|
80
76
|
return `[${n.startLine}:${n.startCol}]>[${n.endLine}:${n.endCol}](${n.startOffset},${n.endOffset})${n.nodeName ?? n.potentialName ?? n.name ?? n.type ?? type}: ${visibleWhiteSpace(n.raw)}`;
|
|
81
77
|
}
|
|
82
78
|
function visibleWhiteSpace(chars) {
|
|
83
|
-
return chars.
|
|
79
|
+
return chars.replaceAll('\n', '⏎').replaceAll('\t', '→').replaceAll(/\s/g, '␣');
|
|
84
80
|
}
|
|
@@ -1,5 +1,15 @@
|
|
|
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
|
+
};
|
|
1
12
|
var _MLDOMIndentation_fixed, _MLDOMIndentation_node, _MLDOMIndentation_parent;
|
|
2
|
-
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
13
|
/**
|
|
4
14
|
*
|
|
5
15
|
* @deprecated
|
|
@@ -16,7 +26,7 @@ node) {
|
|
|
16
26
|
if (node.isRawTextElementContent()) {
|
|
17
27
|
return null;
|
|
18
28
|
}
|
|
19
|
-
const matched = node.raw.match(/^(\s*(?:\r?\n)+\s*)
|
|
29
|
+
const matched = node.raw.match(/^(\s*(?:\r?\n)+\s*)\S+/);
|
|
20
30
|
if (matched) {
|
|
21
31
|
const spaces = matched[1];
|
|
22
32
|
if (spaces) {
|
|
@@ -36,8 +46,8 @@ node) {
|
|
|
36
46
|
// One or more newlines and zero or more spaces or tabs.
|
|
37
47
|
// Or, If textNode is first token and that is filled spaces, tabs and newlines only.
|
|
38
48
|
const matched = isFirstToken(prevToken)
|
|
39
|
-
? prevToken.raw.match(/^(?:[
|
|
40
|
-
: prevToken.raw.match(/\r?\n([
|
|
49
|
+
? prevToken.raw.match(/^(?:[\t ]*\r?\n)*([\t ]*)$/)
|
|
50
|
+
: prevToken.raw.match(/\r?\n([\t ]*)$/);
|
|
41
51
|
// console.log({ [`${this}`]: matched, _: prevToken.raw, f: prevToken._isFirstToken() });
|
|
42
52
|
if (matched) {
|
|
43
53
|
// Spaces will include empty string.
|
|
@@ -3,7 +3,7 @@ export function syncWalk(
|
|
|
3
3
|
nodeList, walker) {
|
|
4
4
|
for (const node of nodeList) {
|
|
5
5
|
if (node.is(node.ELEMENT_NODE) || node.is(node.MARKUPLINT_PREPROCESSOR_BLOCK)) {
|
|
6
|
-
syncWalk(
|
|
6
|
+
syncWalk([...node.childNodes], walker);
|
|
7
7
|
}
|
|
8
8
|
walker(node);
|
|
9
9
|
}
|
|
@@ -2,7 +2,7 @@ import { toHTMLCollection } from '../node/node-list.js';
|
|
|
2
2
|
export function getChildren(
|
|
3
3
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
4
4
|
node) {
|
|
5
|
-
return toHTMLCollection(
|
|
5
|
+
return toHTMLCollection([...node.childNodes].filter((child) => {
|
|
6
6
|
return child.nodeType === child.ELEMENT_NODE;
|
|
7
7
|
}));
|
|
8
8
|
}
|
package/lib/ml-dom/node/attr.js
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
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
|
+
};
|
|
1
12
|
var _MLAttr_localName, _MLAttr_namespaceURI, _MLAttr_potentialName, _MLAttr_potentialValue;
|
|
2
|
-
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
13
|
import { resolveNamespace } from '@markuplint/ml-spec';
|
|
4
14
|
import { MLToken } from '../token/token.js';
|
|
5
15
|
import { MLDomTokenList } from './dom-token-list.js';
|
|
@@ -4,7 +4,7 @@ import type { MLDocumentType } from './document-type.js';
|
|
|
4
4
|
import type { MLElement } from './element.js';
|
|
5
5
|
import type { MLNode } from './node.js';
|
|
6
6
|
import type { MLText } from './text.js';
|
|
7
|
-
import type { DocumentNodeType } from './types.js';
|
|
7
|
+
import type { AccessibilityProperties, DocumentNodeType } from './types.js';
|
|
8
8
|
import type { MLRule } from '../../ml-rule/index.js';
|
|
9
9
|
import type Ruleset from '../../ruleset/index.js';
|
|
10
10
|
import type { MLSchema } from '../../types.js';
|
|
@@ -1429,6 +1429,7 @@ export declare class MLDocument<T extends RuleConfigValue, O extends PlainData =
|
|
|
1429
1429
|
* @implements DOM API: `Document`
|
|
1430
1430
|
*/
|
|
1431
1431
|
exitPointerLock(): void;
|
|
1432
|
+
getAccessibilityProp(node: MLNode<T, O>, ariaVersion?: "1.2"): AccessibilityProperties | null;
|
|
1432
1433
|
/**
|
|
1433
1434
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
1434
1435
|
*
|
|
@@ -1,7 +1,17 @@
|
|
|
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
|
+
};
|
|
1
12
|
var _MLDocument_filename, _MLDocument_tokenList;
|
|
2
|
-
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
13
|
import { exchangeValueOnRule, mergeRule } from '@markuplint/ml-config';
|
|
4
|
-
import { schemaToSpec } from '@markuplint/ml-spec';
|
|
14
|
+
import { schemaToSpec, getAccname, getComputedRole, mayBeFocusable, getComputedAriaProps, isExposed, ARIA_RECOMMENDED_VERSION, } from '@markuplint/ml-spec';
|
|
5
15
|
import { ConfigParserError } from '@markuplint/parser-utils';
|
|
6
16
|
import { InvalidSelectorError, matchSelector } from '@markuplint/selector';
|
|
7
17
|
import { log as coreLog } from '../../debug.js';
|
|
@@ -1824,6 +1834,58 @@ export class MLDocument extends MLParentNode {
|
|
|
1824
1834
|
exitPointerLock() {
|
|
1825
1835
|
throw new UnexpectedCallError('Not supported "exitPointerLock" method');
|
|
1826
1836
|
}
|
|
1837
|
+
getAccessibilityProp(
|
|
1838
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
1839
|
+
node, ariaVersion = ARIA_RECOMMENDED_VERSION) {
|
|
1840
|
+
if (!node.is(node.ELEMENT_NODE)) {
|
|
1841
|
+
return null;
|
|
1842
|
+
}
|
|
1843
|
+
if (['slot'].includes(node.localName)) {
|
|
1844
|
+
return {
|
|
1845
|
+
unknown: true,
|
|
1846
|
+
};
|
|
1847
|
+
}
|
|
1848
|
+
const exposed = isExposed(node, node.ownerMLDocument.specs, ariaVersion);
|
|
1849
|
+
if (!exposed) {
|
|
1850
|
+
return {
|
|
1851
|
+
unknown: false,
|
|
1852
|
+
exposedToTree: false,
|
|
1853
|
+
};
|
|
1854
|
+
}
|
|
1855
|
+
const aria = {
|
|
1856
|
+
unknown: false,
|
|
1857
|
+
exposedToTree: true,
|
|
1858
|
+
};
|
|
1859
|
+
const role = getComputedRole(node.ownerMLDocument.specs, node, ariaVersion);
|
|
1860
|
+
const name = getAccname(node).trim();
|
|
1861
|
+
const focusable = mayBeFocusable(node, node.ownerMLDocument.specs);
|
|
1862
|
+
const nameRequired = role.role?.accessibleNameRequired ?? false;
|
|
1863
|
+
const nameProhibited = role.role?.accessibleNameProhibited ?? false;
|
|
1864
|
+
const hasSlot = !!node.querySelector('slot');
|
|
1865
|
+
aria.role = role.role?.name;
|
|
1866
|
+
aria.nameRequired = nameRequired;
|
|
1867
|
+
aria.nameProhibited = nameProhibited;
|
|
1868
|
+
aria.name =
|
|
1869
|
+
name ||
|
|
1870
|
+
(hasSlot
|
|
1871
|
+
? {
|
|
1872
|
+
unknown: true,
|
|
1873
|
+
}
|
|
1874
|
+
: '');
|
|
1875
|
+
aria.focusable = focusable;
|
|
1876
|
+
for (const prop of Object.values(getComputedAriaProps(node.ownerMLDocument.specs, node, ariaVersion))) {
|
|
1877
|
+
if (!prop.required && prop.from === 'default') {
|
|
1878
|
+
continue;
|
|
1879
|
+
}
|
|
1880
|
+
aria.props = aria.props || {};
|
|
1881
|
+
const propName = prop.name.replace('aria-', '');
|
|
1882
|
+
aria.props[propName] = {
|
|
1883
|
+
value: prop.value ?? null,
|
|
1884
|
+
required: prop.required,
|
|
1885
|
+
};
|
|
1886
|
+
}
|
|
1887
|
+
return aria;
|
|
1888
|
+
}
|
|
1827
1889
|
/**
|
|
1828
1890
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
1829
1891
|
*
|
|
@@ -2050,7 +2112,7 @@ export class MLDocument extends MLParentNode {
|
|
|
2050
2112
|
return walker(node);
|
|
2051
2113
|
}
|
|
2052
2114
|
if (type === 'Attr' && node.is(node.ELEMENT_NODE)) {
|
|
2053
|
-
return sequentialWalker(
|
|
2115
|
+
return sequentialWalker([...node.attributes], attr => walker(attr));
|
|
2054
2116
|
}
|
|
2055
2117
|
if (type === 'ElementCloseTag' && node.is(node.ELEMENT_NODE) && node.closeTag) {
|
|
2056
2118
|
return walker(node.closeTag);
|
|
@@ -2094,50 +2156,50 @@ export class MLDocument extends MLParentNode {
|
|
|
2094
2156
|
}
|
|
2095
2157
|
const ruleMapper = new RuleMapper(this);
|
|
2096
2158
|
// global rules to #document
|
|
2097
|
-
Object.keys(ruleset.rules)
|
|
2159
|
+
for (const ruleName of Object.keys(ruleset.rules)) {
|
|
2098
2160
|
const rule = ruleset.rules[ruleName];
|
|
2099
2161
|
if (rule == null) {
|
|
2100
|
-
|
|
2162
|
+
continue;
|
|
2101
2163
|
}
|
|
2102
2164
|
ruleMapper.set(this, ruleName, {
|
|
2103
2165
|
from: 'rules',
|
|
2104
2166
|
specificity: [0, 0, 0],
|
|
2105
2167
|
rule,
|
|
2106
2168
|
});
|
|
2107
|
-
}
|
|
2169
|
+
}
|
|
2108
2170
|
// add rules to node
|
|
2109
2171
|
for (const node of this.nodeList) {
|
|
2110
2172
|
if (docLog.enabled) {
|
|
2111
2173
|
docLog('Add rules to node <%s>', node.nodeName);
|
|
2112
2174
|
}
|
|
2113
2175
|
// global rules to each element
|
|
2114
|
-
Object.keys(ruleset.rules)
|
|
2176
|
+
for (const ruleName of Object.keys(ruleset.rules)) {
|
|
2115
2177
|
const rule = ruleset.rules[ruleName];
|
|
2116
2178
|
if (rule == null) {
|
|
2117
|
-
|
|
2179
|
+
continue;
|
|
2118
2180
|
}
|
|
2119
2181
|
ruleMapper.set(node, ruleName, {
|
|
2120
2182
|
from: 'rules',
|
|
2121
2183
|
specificity: [0, 0, 0],
|
|
2122
2184
|
rule,
|
|
2123
2185
|
});
|
|
2124
|
-
}
|
|
2186
|
+
}
|
|
2125
2187
|
if (!node.is(node.ELEMENT_NODE) && !node.is(node.TEXT_NODE)) {
|
|
2126
2188
|
continue;
|
|
2127
2189
|
}
|
|
2128
2190
|
const selectorTarget = node.is(node.ELEMENT_NODE) ? node : null;
|
|
2129
2191
|
// node specs and special rules for node by selector
|
|
2130
|
-
ruleset.nodeRules
|
|
2192
|
+
for (const nodeRule of ruleset.nodeRules) {
|
|
2131
2193
|
if (!nodeRule.rules) {
|
|
2132
|
-
|
|
2194
|
+
continue;
|
|
2133
2195
|
}
|
|
2134
2196
|
if (!selectorTarget) {
|
|
2135
|
-
|
|
2197
|
+
continue;
|
|
2136
2198
|
}
|
|
2137
2199
|
const selector = nodeRule.selector ?? nodeRule.regexSelector;
|
|
2138
2200
|
const matches = matchSelector(selectorTarget, selector);
|
|
2139
2201
|
if (!matches.matched) {
|
|
2140
|
-
|
|
2202
|
+
continue;
|
|
2141
2203
|
}
|
|
2142
2204
|
if (docLog.enabled) {
|
|
2143
2205
|
docLog('Matched nodeRule: <%s>(%s)', node.nodeName, matches.selector || '*');
|
|
@@ -2153,7 +2215,7 @@ export class MLDocument extends MLParentNode {
|
|
|
2153
2215
|
continue;
|
|
2154
2216
|
}
|
|
2155
2217
|
const globalRule = ruleset.rules[ruleName];
|
|
2156
|
-
const mergedRule = globalRule
|
|
2218
|
+
const mergedRule = globalRule == null ? convertedRule : mergeRule(globalRule, convertedRule);
|
|
2157
2219
|
ruleLog('↑ nodeRule (%s): %O', ruleName, mergedRule);
|
|
2158
2220
|
ruleMapper.set(node, ruleName, {
|
|
2159
2221
|
from: 'nodeRules',
|
|
@@ -2161,52 +2223,52 @@ export class MLDocument extends MLParentNode {
|
|
|
2161
2223
|
rule: mergedRule,
|
|
2162
2224
|
});
|
|
2163
2225
|
}
|
|
2164
|
-
}
|
|
2226
|
+
}
|
|
2165
2227
|
// overwrite rule to child node
|
|
2166
2228
|
if (selectorTarget && ruleset.childNodeRules.length > 0) {
|
|
2167
2229
|
const descendants = [];
|
|
2168
|
-
const children =
|
|
2230
|
+
const children = [...selectorTarget.childNodes];
|
|
2169
2231
|
syncWalk(children, childNode => {
|
|
2170
2232
|
descendants.push(childNode);
|
|
2171
2233
|
});
|
|
2172
|
-
ruleset.childNodeRules
|
|
2234
|
+
for (const nodeRule of ruleset.childNodeRules) {
|
|
2173
2235
|
if (!nodeRule.rules) {
|
|
2174
|
-
|
|
2236
|
+
continue;
|
|
2175
2237
|
}
|
|
2176
2238
|
const nodeRuleRules = nodeRule.rules;
|
|
2177
2239
|
const selector = nodeRule.selector ?? nodeRule.regexSelector;
|
|
2178
2240
|
if (selector == null) {
|
|
2179
|
-
|
|
2241
|
+
continue;
|
|
2180
2242
|
}
|
|
2181
2243
|
const matches = matchSelector(selectorTarget, selector);
|
|
2182
2244
|
if (!matches.matched) {
|
|
2183
|
-
|
|
2245
|
+
continue;
|
|
2184
2246
|
}
|
|
2185
2247
|
if (docLog.enabled) {
|
|
2186
2248
|
docLog('Matched childNodeRule: <%s>(%s), inheritance: %o', selectorTarget.nodeName, matches.selector || '*', !!nodeRule.inheritance);
|
|
2187
2249
|
}
|
|
2188
2250
|
const targetDescendants = nodeRule.inheritance ? descendants : children;
|
|
2189
|
-
Object.keys(nodeRuleRules)
|
|
2251
|
+
for (const ruleName of Object.keys(nodeRuleRules)) {
|
|
2190
2252
|
const rule = nodeRuleRules[ruleName];
|
|
2191
2253
|
if (rule == null) {
|
|
2192
|
-
|
|
2254
|
+
continue;
|
|
2193
2255
|
}
|
|
2194
2256
|
const convertedRule = exchangeValueOnRule(rule, matches.data ?? {});
|
|
2195
2257
|
if (convertedRule === undefined) {
|
|
2196
|
-
|
|
2258
|
+
continue;
|
|
2197
2259
|
}
|
|
2198
2260
|
const globalRule = ruleset.rules[ruleName];
|
|
2199
|
-
const mergedRule = globalRule
|
|
2261
|
+
const mergedRule = globalRule == null ? convertedRule : mergeRule(globalRule, convertedRule);
|
|
2200
2262
|
ruleLog('↑ childNodeRule (%s): %O', ruleName, mergedRule);
|
|
2201
|
-
|
|
2263
|
+
for (const descendant of targetDescendants) {
|
|
2202
2264
|
ruleMapper.set(descendant, ruleName, {
|
|
2203
2265
|
from: 'childNodeRules',
|
|
2204
2266
|
specificity: matches.specificity,
|
|
2205
2267
|
rule: mergedRule,
|
|
2206
2268
|
});
|
|
2207
|
-
}
|
|
2208
|
-
}
|
|
2209
|
-
}
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
2271
|
+
}
|
|
2210
2272
|
}
|
|
2211
2273
|
}
|
|
2212
2274
|
ruleMapper.apply();
|
|
@@ -1,5 +1,15 @@
|
|
|
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
|
+
};
|
|
1
12
|
var _MLDomTokenList_origin, _MLDomTokenList_ownerAttrs, _MLDomTokenList_set;
|
|
2
|
-
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
13
|
import { getCol, getLine } from '@markuplint/parser-utils';
|
|
4
14
|
import UnexpectedCallError from './unexpected-call-error.js';
|
|
5
15
|
export class MLDomTokenList extends Array {
|
|
@@ -40,7 +50,7 @@ export class MLDomTokenList extends Array {
|
|
|
40
50
|
*/
|
|
41
51
|
allTokens() {
|
|
42
52
|
let offset = 0;
|
|
43
|
-
const tokens =
|
|
53
|
+
const tokens = [...this];
|
|
44
54
|
const locs = [];
|
|
45
55
|
while (tokens.length > 0) {
|
|
46
56
|
const token = tokens.shift();
|
|
@@ -1530,6 +1530,10 @@ export declare class MLElement<T extends RuleConfigValue, O extends PlainData =
|
|
|
1530
1530
|
* @see https://www.w3.org/TR/web-animations-1/#dom-animatable-animate
|
|
1531
1531
|
*/
|
|
1532
1532
|
animate(keyframes: Keyframe[] | PropertyIndexedKeyframes | null, options?: number | KeyframeAnimationOptions): Animation;
|
|
1533
|
+
/**
|
|
1534
|
+
* @see https://html.spec.whatwg.org/multipage/scripting.html#dom-slot-assignednodes
|
|
1535
|
+
*/
|
|
1536
|
+
assignedNodes(): never[];
|
|
1533
1537
|
/**
|
|
1534
1538
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
1535
1539
|
*
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
/* global StylePropertyMap, StylePropertyMapReadOnly */
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
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");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
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");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
2
13
|
var _MLElement_attributes, _MLElement_fixedNodeName, _MLElement_getChildElementsAndTextNodeWithoutWhitespacesCache, _MLElement_localName, _MLElement_normalizedAttrs, _MLElement_normalizedString, _MLElement_tagOpenChar;
|
|
3
|
-
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
4
14
|
import { resolveNamespace } from '@markuplint/ml-spec';
|
|
5
15
|
import { createSelector } from '@markuplint/selector';
|
|
6
16
|
import { stringSplice } from '../../utils/string-splice.js';
|
|
@@ -1809,7 +1819,7 @@ export class MLElement extends MLParentNode {
|
|
|
1809
1819
|
fixed = stringSplice(fixed, __classPrivateFieldGet(this, _MLElement_tagOpenChar, "f").length, this.nodeName.length, this.fixedNodeName);
|
|
1810
1820
|
gap = gap + this.fixedNodeName.length - this.nodeName.length;
|
|
1811
1821
|
}
|
|
1812
|
-
for (const attr of
|
|
1822
|
+
for (const attr of this.attributes) {
|
|
1813
1823
|
const startOffset = (attr.spacesBeforeName?.startOffset ?? attr.startOffset) - this.startOffset;
|
|
1814
1824
|
const fixedAttr = attr.toString();
|
|
1815
1825
|
if (attr.originRaw !== fixedAttr) {
|
|
@@ -1954,9 +1964,7 @@ export class MLElement extends MLParentNode {
|
|
|
1954
1964
|
return this.nodeName;
|
|
1955
1965
|
}
|
|
1956
1966
|
get textContent() {
|
|
1957
|
-
return
|
|
1958
|
-
.map(child => child.textContent ?? '')
|
|
1959
|
-
.join('');
|
|
1967
|
+
return [...this.childNodes].map(child => child.textContent ?? '').join('');
|
|
1960
1968
|
}
|
|
1961
1969
|
/**
|
|
1962
1970
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -2000,6 +2008,15 @@ export class MLElement extends MLParentNode {
|
|
|
2000
2008
|
options) {
|
|
2001
2009
|
throw new UnexpectedCallError('Not supported "animate" method');
|
|
2002
2010
|
}
|
|
2011
|
+
/**
|
|
2012
|
+
* @see https://html.spec.whatwg.org/multipage/scripting.html#dom-slot-assignednodes
|
|
2013
|
+
*/
|
|
2014
|
+
assignedNodes() {
|
|
2015
|
+
if (this.localName !== 'slot') {
|
|
2016
|
+
throw new TypeError('assignedNodes is not a function');
|
|
2017
|
+
}
|
|
2018
|
+
return [];
|
|
2019
|
+
}
|
|
2003
2020
|
/**
|
|
2004
2021
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
2005
2022
|
*
|
|
@@ -2067,6 +2084,7 @@ export class MLElement extends MLParentNode {
|
|
|
2067
2084
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-element-closest%E2%91%A0
|
|
2068
2085
|
*/
|
|
2069
2086
|
closest(selectors) {
|
|
2087
|
+
// eslint-disable-next-line unicorn/no-this-assignment
|
|
2070
2088
|
let el = this;
|
|
2071
2089
|
do {
|
|
2072
2090
|
if (el.matches(selectors)) {
|
|
@@ -2123,7 +2141,7 @@ export class MLElement extends MLParentNode {
|
|
|
2123
2141
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-element-getattribute%E2%91%A0
|
|
2124
2142
|
*/
|
|
2125
2143
|
getAttribute(attrName) {
|
|
2126
|
-
for (const attr of
|
|
2144
|
+
for (const attr of this.attributes) {
|
|
2127
2145
|
if (attr.name.toLowerCase() === attrName.toLowerCase()) {
|
|
2128
2146
|
return attr.value;
|
|
2129
2147
|
}
|
|
@@ -2145,7 +2163,7 @@ export class MLElement extends MLParentNode {
|
|
|
2145
2163
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-element-getattributenames%E2%91%A0
|
|
2146
2164
|
*/
|
|
2147
2165
|
getAttributeNames() {
|
|
2148
|
-
return
|
|
2166
|
+
return [...this.attributes].map(attr => attr.name);
|
|
2149
2167
|
}
|
|
2150
2168
|
/**
|
|
2151
2169
|
* @implements DOM API: `Element`
|
|
@@ -2168,7 +2186,7 @@ export class MLElement extends MLParentNode {
|
|
|
2168
2186
|
* @implements `@markuplint/ml-core` API: `MLElement`
|
|
2169
2187
|
*/
|
|
2170
2188
|
getAttributePretended(attrName) {
|
|
2171
|
-
for (const attr of
|
|
2189
|
+
for (const attr of __classPrivateFieldGet(this, _MLElement_attributes, "f")) {
|
|
2172
2190
|
if (attr.name.toLowerCase() === attrName.toLowerCase()) {
|
|
2173
2191
|
return attr.value;
|
|
2174
2192
|
}
|
|
@@ -2209,7 +2227,7 @@ export class MLElement extends MLParentNode {
|
|
|
2209
2227
|
return __classPrivateFieldGet(this, _MLElement_getChildElementsAndTextNodeWithoutWhitespacesCache, "f");
|
|
2210
2228
|
}
|
|
2211
2229
|
const filteredNodes = [];
|
|
2212
|
-
this.childNodes
|
|
2230
|
+
for (const node of this.childNodes) {
|
|
2213
2231
|
if (node.is(node.ELEMENT_NODE)) {
|
|
2214
2232
|
if (node.isOmitted) {
|
|
2215
2233
|
const children = node.getChildElementsAndTextNodeWithoutWhitespaces();
|
|
@@ -2222,7 +2240,7 @@ export class MLElement extends MLParentNode {
|
|
|
2222
2240
|
if (node.is(node.TEXT_NODE) && !node.isWhitespace()) {
|
|
2223
2241
|
filteredNodes.push(node);
|
|
2224
2242
|
}
|
|
2225
|
-
}
|
|
2243
|
+
}
|
|
2226
2244
|
__classPrivateFieldSet(this, _MLElement_getChildElementsAndTextNodeWithoutWhitespacesCache, filteredNodes, "f");
|
|
2227
2245
|
return filteredNodes;
|
|
2228
2246
|
}
|
|
@@ -2306,7 +2324,7 @@ export class MLElement extends MLParentNode {
|
|
|
2306
2324
|
* @implements `@markuplint/ml-core` API: `MLElement`
|
|
2307
2325
|
*/
|
|
2308
2326
|
hasMutableAttributes() {
|
|
2309
|
-
for (const attr of
|
|
2327
|
+
for (const attr of this.attributes) {
|
|
2310
2328
|
if (!attr.nameNode) {
|
|
2311
2329
|
return true;
|
|
2312
2330
|
}
|
|
@@ -2322,7 +2340,7 @@ export class MLElement extends MLParentNode {
|
|
|
2322
2340
|
* @implements `@markuplint/ml-core` API: `MLElement`
|
|
2323
2341
|
*/
|
|
2324
2342
|
hasMutableChildren(attr = false) {
|
|
2325
|
-
for (const child of
|
|
2343
|
+
for (const child of this.childNodes) {
|
|
2326
2344
|
if (child.is(child.MARKUPLINT_PREPROCESSOR_BLOCK)) {
|
|
2327
2345
|
return true;
|
|
2328
2346
|
}
|
|
@@ -2415,7 +2433,7 @@ export class MLElement extends MLParentNode {
|
|
|
2415
2433
|
* @implements `@markuplint/ml-core` API: `MLElement`
|
|
2416
2434
|
*/
|
|
2417
2435
|
isEmpty() {
|
|
2418
|
-
for (const childNode of
|
|
2436
|
+
for (const childNode of this.childNodes) {
|
|
2419
2437
|
if (!(childNode.is(childNode.TEXT_NODE) && childNode.textContent?.trim() === '')) {
|
|
2420
2438
|
return false;
|
|
2421
2439
|
}
|
|
@@ -2454,11 +2472,11 @@ export class MLElement extends MLParentNode {
|
|
|
2454
2472
|
}
|
|
2455
2473
|
if (pretenderConfig.as.attrs) {
|
|
2456
2474
|
attributes.push(...pretenderConfig.as.attrs.map(({ name, value }, i) => {
|
|
2457
|
-
const _value = value
|
|
2458
|
-
?
|
|
2475
|
+
const _value = value == null
|
|
2476
|
+
? ''
|
|
2477
|
+
: typeof value === 'string'
|
|
2459
2478
|
? value
|
|
2460
|
-
: this.getAttribute(value.fromAttr) ?? ''
|
|
2461
|
-
: '';
|
|
2479
|
+
: this.getAttribute(value.fromAttr) ?? '';
|
|
2462
2480
|
return {
|
|
2463
2481
|
...this._astToken,
|
|
2464
2482
|
uuid: `${this.uuid}_attr_${i}`,
|
|
@@ -42,10 +42,10 @@ export function nodeListToHTMLCollection(
|
|
|
42
42
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
43
43
|
nodeList) {
|
|
44
44
|
const collection = new MLHTMLCollection();
|
|
45
|
-
|
|
45
|
+
for (const node of nodeList) {
|
|
46
46
|
if (node.is(node.ELEMENT_NODE)) {
|
|
47
47
|
collection.push(node);
|
|
48
48
|
}
|
|
49
|
-
}
|
|
49
|
+
}
|
|
50
50
|
return collection;
|
|
51
51
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
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
|
+
};
|
|
1
6
|
var _NodeStore_store;
|
|
2
|
-
import { __classPrivateFieldGet } from "tslib";
|
|
3
7
|
import { TargetParserError } from '@markuplint/parser-utils';
|
|
4
8
|
import { log } from '../../debug.js';
|
|
5
9
|
const nodeStoreLog = log.extend('node-store');
|
|
@@ -13,7 +17,7 @@ class NodeStore {
|
|
|
13
17
|
const node = __classPrivateFieldGet(this, _NodeStore_store, "f").get(astNode.uuid);
|
|
14
18
|
if (!node) {
|
|
15
19
|
nodeStoreError('Ref ID: %s (%s: "%s")', astNode.uuid, astNode.nodeName, astNode.raw);
|
|
16
|
-
nodeStoreError('Map: %O',
|
|
20
|
+
nodeStoreError('Map: %O', [...__classPrivateFieldGet(this, _NodeStore_store, "f").entries()].map(([id, node]) => ({
|
|
17
21
|
id,
|
|
18
22
|
name: node.nodeName,
|
|
19
23
|
})));
|
|
@@ -36,7 +40,7 @@ class NodeStore {
|
|
|
36
40
|
nodeStoreError('UUID is invalid: %s (%s: "%s")', astNode.uuid, astNode.nodeName, astNode.raw);
|
|
37
41
|
nodeStoreError('Invalid node: %O', node);
|
|
38
42
|
}
|
|
39
|
-
nodeStoreLog('Mapped: %s (%s: "%s")', astNode.uuid, astNode.nodeName, astNode.raw.
|
|
43
|
+
nodeStoreLog('Mapped: %s (%s: "%s")', astNode.uuid, astNode.nodeName, astNode.raw.replaceAll('\n', '⏎').replaceAll('\t', '→'));
|
|
40
44
|
__classPrivateFieldGet(this, _NodeStore_store, "f").set(astNode.uuid, node);
|
|
41
45
|
}
|
|
42
46
|
}
|
package/lib/ml-dom/node/node.js
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
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
|
+
};
|
|
1
12
|
var _MLNode_childNodes, _MLNode_ownerDocument, _MLNode_prevToken;
|
|
2
|
-
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
13
|
import { MLToken } from '../token/token.js';
|
|
4
14
|
import { isChildNode } from './child-node.js';
|
|
5
15
|
import { toNodeList } from './node-list.js';
|
|
@@ -44,7 +54,7 @@ export class MLNode extends MLToken {
|
|
|
44
54
|
* @implements DOM API: `Node`
|
|
45
55
|
* @see https://dom.spec.whatwg.org/#dom-node-document_position_contains
|
|
46
56
|
*/
|
|
47
|
-
this.DOCUMENT_POSITION_CONTAINS =
|
|
57
|
+
this.DOCUMENT_POSITION_CONTAINS = 0b1000;
|
|
48
58
|
/**
|
|
49
59
|
* @implements DOM API: `Node`
|
|
50
60
|
* @see https://dom.spec.whatwg.org/#dom-node-document_position_disconnected
|
|
@@ -206,6 +216,7 @@ export class MLNode extends MLToken {
|
|
|
206
216
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-node-lastchild%E2%91%A0
|
|
207
217
|
*/
|
|
208
218
|
get lastChild() {
|
|
219
|
+
// eslint-disable-next-line unicorn/prefer-at
|
|
209
220
|
return this.childNodes[this.childNodes.length - 1] ?? null;
|
|
210
221
|
}
|
|
211
222
|
/**
|
|
@@ -1,5 +1,15 @@
|
|
|
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
|
+
};
|
|
1
12
|
var _MLParentNode_children, _MLParentNode_selectedElements;
|
|
2
|
-
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
13
|
import { syncWalk } from '../helper/walkers.js';
|
|
4
14
|
import { getChildren } from '../manipulations/get-children.js';
|
|
5
15
|
import { toNodeList } from './node-list.js';
|
|
@@ -117,7 +127,7 @@ export class MLParentNode extends MLNode {
|
|
|
117
127
|
}
|
|
118
128
|
_descendantsToArray(filter) {
|
|
119
129
|
const nodeList = [];
|
|
120
|
-
syncWalk(
|
|
130
|
+
syncWalk([...this.childNodes], node => {
|
|
121
131
|
if (filter) {
|
|
122
132
|
const filtered = filter(node);
|
|
123
133
|
if (filtered) {
|
|
@@ -1,5 +1,15 @@
|
|
|
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
|
+
};
|
|
1
12
|
var _RuleMapper_nodeList, _RuleMapper_ruleMap;
|
|
2
|
-
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
13
|
import { compareSpecificity } from '@markuplint/selector';
|
|
4
14
|
import { log as coreLog } from '../../debug.js';
|
|
5
15
|
const ruleMapperLog = coreLog.extend('rule-mapper');
|
|
@@ -15,21 +25,21 @@ export class RuleMapper {
|
|
|
15
25
|
}
|
|
16
26
|
apply() {
|
|
17
27
|
ruleMapperLog('ruleTree:');
|
|
18
|
-
__classPrivateFieldGet(this, _RuleMapper_nodeList, "f")
|
|
28
|
+
for (const node of __classPrivateFieldGet(this, _RuleMapper_nodeList, "f")) {
|
|
19
29
|
const rules = __classPrivateFieldGet(this, _RuleMapper_ruleMap, "f").get(node.uuid);
|
|
20
30
|
if (!rules) {
|
|
21
|
-
|
|
31
|
+
continue;
|
|
22
32
|
}
|
|
23
33
|
ruleMapperNodeLog('<%s>', node.nodeName);
|
|
24
|
-
Object.keys(rules)
|
|
34
|
+
for (const ruleName of Object.keys(rules)) {
|
|
25
35
|
const rule = rules[ruleName];
|
|
26
36
|
if (!rule) {
|
|
27
|
-
|
|
37
|
+
continue;
|
|
28
38
|
}
|
|
29
39
|
node.rules[ruleName] = rule.rule;
|
|
30
40
|
ruleMapperNodeRuleLog('[from: %s(%s)] %s: %o', rule.from, rule.specificity, ruleName, rule.rule);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
33
43
|
}
|
|
34
44
|
set(
|
|
35
45
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
package/lib/ml-dom/node/text.js
CHANGED
|
@@ -5,7 +5,7 @@ import UnexpectedCallError from './unexpected-call-error.js';
|
|
|
5
5
|
*
|
|
6
6
|
* @see https://html.spec.whatwg.org/multipage/syntax.html#raw-text-elements
|
|
7
7
|
*/
|
|
8
|
-
const rawTextElements = ['script', 'style'];
|
|
8
|
+
const rawTextElements = new Set(['script', 'style']);
|
|
9
9
|
export class MLText extends MLCharacterData {
|
|
10
10
|
/**
|
|
11
11
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -50,7 +50,7 @@ export class MLText extends MLCharacterData {
|
|
|
50
50
|
* @see https://html.spec.whatwg.org/multipage/syntax.html#raw-text-elements
|
|
51
51
|
*/
|
|
52
52
|
isRawTextElementContent() {
|
|
53
|
-
return this.parentElement ? rawTextElements.
|
|
53
|
+
return this.parentElement ? rawTextElements.has(this.parentElement.nodeName.toLowerCase()) : false;
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
56
56
|
* @implements `@markuplint/ml-core` API: `MLText`
|
|
@@ -33,3 +33,24 @@ export type PretenderContextPretended<N extends MLElement<T, O>, T extends RuleC
|
|
|
33
33
|
readonly type: 'origin';
|
|
34
34
|
readonly origin: N;
|
|
35
35
|
};
|
|
36
|
+
export type AccessibilityProperties = ClearlyAccessibilityProperties | UnknownAccessibilityProperties;
|
|
37
|
+
export type ClearlyAccessibilityProperties = {
|
|
38
|
+
unknown: false;
|
|
39
|
+
exposedToTree: boolean;
|
|
40
|
+
role?: string;
|
|
41
|
+
roleDescription?: string;
|
|
42
|
+
name?: string | {
|
|
43
|
+
unknown: true;
|
|
44
|
+
};
|
|
45
|
+
nameRequired?: boolean;
|
|
46
|
+
nameProhibited?: boolean;
|
|
47
|
+
focusable?: boolean;
|
|
48
|
+
props?: Record<string, AccessibilityProperty>;
|
|
49
|
+
};
|
|
50
|
+
export type UnknownAccessibilityProperties = {
|
|
51
|
+
unknown: true;
|
|
52
|
+
};
|
|
53
|
+
export type AccessibilityProperty = {
|
|
54
|
+
value: string | null;
|
|
55
|
+
required: boolean;
|
|
56
|
+
};
|
|
@@ -1,5 +1,15 @@
|
|
|
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
|
+
};
|
|
1
12
|
var _MLToken_endCol, _MLToken_endLine, _MLToken_endOffset, _MLToken_fixed, _MLToken_raw, _MLToken_startCol, _MLToken_startLine, _MLToken_startOffset;
|
|
2
|
-
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
13
|
export class MLToken {
|
|
4
14
|
constructor(astToken) {
|
|
5
15
|
_MLToken_endCol.set(this, void 0);
|
|
@@ -1,5 +1,9 @@
|
|
|
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
|
+
};
|
|
1
6
|
var _MLRuleContext_reports;
|
|
2
|
-
import { __classPrivateFieldGet } from "tslib";
|
|
3
7
|
import { translator } from '@markuplint/i18n';
|
|
4
8
|
export class MLRuleContext {
|
|
5
9
|
constructor(
|
|
@@ -37,7 +41,7 @@ export class MLRuleContext {
|
|
|
37
41
|
this._push(report);
|
|
38
42
|
}
|
|
39
43
|
_push(report) {
|
|
40
|
-
if (!__classPrivateFieldGet(this, _MLRuleContext_reports, "f").
|
|
44
|
+
if (!__classPrivateFieldGet(this, _MLRuleContext_reports, "f").some(r => is(r, report))) {
|
|
41
45
|
__classPrivateFieldGet(this, _MLRuleContext_reports, "f").push(report);
|
|
42
46
|
}
|
|
43
47
|
}
|
package/lib/ml-rule/ml-rule.js
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
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
|
+
};
|
|
1
12
|
var _MLRule_f, _MLRule_v;
|
|
2
|
-
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
13
|
import { deleteUndefProp } from '@markuplint/ml-config';
|
|
4
14
|
// @ts-ignore
|
|
5
15
|
import { isPlainObject } from 'is-plain-object';
|
|
@@ -11,7 +21,7 @@ export class MLRule {
|
|
|
11
21
|
this.name = o.name;
|
|
12
22
|
this.defaultSeverity = o.defaultSeverity ?? 'error';
|
|
13
23
|
// TODO: https://github.com/markuplint/markuplint/issues/808
|
|
14
|
-
this.defaultValue = (o.defaultValue
|
|
24
|
+
this.defaultValue = (o.defaultValue === undefined ? true : o.defaultValue);
|
|
15
25
|
this.defaultOptions = o.defaultOptions;
|
|
16
26
|
__classPrivateFieldSet(this, _MLRule_v, o.verify, "f");
|
|
17
27
|
__classPrivateFieldSet(this, _MLRule_f, o.fix, "f");
|
package/lib/test/index.js
CHANGED
|
@@ -22,7 +22,7 @@ export function createTestElement(sourceCode, options) {
|
|
|
22
22
|
if (el && el.is(el.ELEMENT_NODE)) {
|
|
23
23
|
return el;
|
|
24
24
|
}
|
|
25
|
-
throw TypeError(`Could not parse it to be an element from: ${sourceCode}`);
|
|
25
|
+
throw new TypeError(`Could not parse it to be an element from: ${sourceCode}`);
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* for test suite
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export function getLocationFromChars(searches, text, currentLine, currentCol) {
|
|
2
2
|
const lines = text.split(/\r?\n/g);
|
|
3
3
|
const foundLocations = [];
|
|
4
|
-
lines.
|
|
4
|
+
for (const [i, lineText] of lines.entries()) {
|
|
5
5
|
let offset = 0;
|
|
6
6
|
for (const char of lineText) {
|
|
7
7
|
if (searches.includes(char)) {
|
|
@@ -19,6 +19,6 @@ export function getLocationFromChars(searches, text, currentLine, currentCol) {
|
|
|
19
19
|
}
|
|
20
20
|
offset++;
|
|
21
21
|
}
|
|
22
|
-
}
|
|
22
|
+
}
|
|
23
23
|
return foundLocations;
|
|
24
24
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/ml-core",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-dev.28+0131de5e",
|
|
4
4
|
"description": "The core module of markuplint",
|
|
5
5
|
"repository": "git@github.com:markuplint/markuplint.git",
|
|
6
6
|
"author": "Yusuke Hirao <yusukehirao@me.com>",
|
|
@@ -28,20 +28,19 @@
|
|
|
28
28
|
"./lib/configs.js": "./lib/configs.browser.js"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@markuplint/config-presets": "4.0.0-
|
|
32
|
-
"@markuplint/html-parser": "4.0.0-
|
|
33
|
-
"@markuplint/html-spec": "4.0.0-
|
|
34
|
-
"@markuplint/i18n": "4.0.0-
|
|
35
|
-
"@markuplint/ml-ast": "4.0.0-
|
|
36
|
-
"@markuplint/ml-config": "4.0.0-
|
|
37
|
-
"@markuplint/ml-spec": "4.0.0-
|
|
38
|
-
"@markuplint/parser-utils": "4.0.0-
|
|
39
|
-
"@markuplint/selector": "4.0.0-
|
|
40
|
-
"@types/debug": "^4.1.
|
|
31
|
+
"@markuplint/config-presets": "4.0.0-dev.28+0131de5e",
|
|
32
|
+
"@markuplint/html-parser": "4.0.0-dev.28+0131de5e",
|
|
33
|
+
"@markuplint/html-spec": "4.0.0-dev.28+0131de5e",
|
|
34
|
+
"@markuplint/i18n": "4.0.0-dev.28+0131de5e",
|
|
35
|
+
"@markuplint/ml-ast": "4.0.0-dev.28+0131de5e",
|
|
36
|
+
"@markuplint/ml-config": "4.0.0-dev.28+0131de5e",
|
|
37
|
+
"@markuplint/ml-spec": "4.0.0-dev.28+0131de5e",
|
|
38
|
+
"@markuplint/parser-utils": "4.0.0-dev.28+0131de5e",
|
|
39
|
+
"@markuplint/selector": "4.0.0-dev.28+0131de5e",
|
|
40
|
+
"@types/debug": "^4.1.10",
|
|
41
41
|
"debug": "^4.3.4",
|
|
42
42
|
"is-plain-object": "^5.0.0",
|
|
43
|
-
"
|
|
44
|
-
"type-fest": "^4.3.1"
|
|
43
|
+
"type-fest": "^4.5.0"
|
|
45
44
|
},
|
|
46
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "0131de5ea9dd6d3fd5472d7b414b66644c758881"
|
|
47
46
|
}
|
|
File without changes
|