@markuplint/ml-core 3.0.0-canary.5 → 3.0.0-dev.176
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/README.md +1 -1
- package/lib/configs.browser.d.ts +2 -0
- package/lib/configs.browser.js +12 -0
- package/lib/configs.js +1 -2
- package/lib/index.d.ts +11 -1
- package/lib/ml-core.d.ts +23 -12
- package/lib/ml-core.js +4 -4
- package/lib/ml-dom/helper/accname.js +18 -7
- package/lib/ml-dom/helper/create-node.d.ts +6 -2
- package/lib/ml-dom/helper/create-node.js +3 -1
- package/lib/ml-dom/helper/debug.js +9 -4
- package/lib/ml-dom/helper/getIndent.d.ts +7 -7
- package/lib/ml-dom/helper/getIndent.js +18 -12
- package/lib/ml-dom/helper/walkers.d.ts +15 -5
- package/lib/ml-dom/helper/walkers.js +22 -16
- package/lib/ml-dom/manipulations/child-node-methods.d.ts +20 -7
- package/lib/ml-dom/manipulations/child-node-methods.js +24 -6
- package/lib/ml-dom/manipulations/get-children.d.ts +4 -2
- package/lib/ml-dom/manipulations/get-children.js +3 -1
- package/lib/ml-dom/node/attr.d.ts +94 -91
- package/lib/ml-dom/node/attr.js +8 -4
- package/lib/ml-dom/node/block.d.ts +36 -32
- package/lib/ml-dom/node/block.js +14 -4
- package/lib/ml-dom/node/character-data.d.ts +60 -53
- package/lib/ml-dom/node/character-data.js +9 -3
- package/lib/ml-dom/node/child-node.d.ts +10 -3
- package/lib/ml-dom/node/child-node.js +3 -1
- package/lib/ml-dom/node/comment.d.ts +16 -13
- package/lib/ml-dom/node/document-fragment.d.ts +23 -20
- package/lib/ml-dom/node/document-type.d.ts +35 -32
- package/lib/ml-dom/node/document-type.js +14 -4
- package/lib/ml-dom/node/document.d.ts +1607 -1589
- package/lib/ml-dom/node/document.js +56 -19
- package/lib/ml-dom/node/dom-token-list.d.ts +26 -26
- package/lib/ml-dom/node/dom-token-list.js +9 -7
- package/lib/ml-dom/node/element.d.ts +1903 -1889
- package/lib/ml-dom/node/element.js +76 -27
- package/lib/ml-dom/node/named-node-map.d.ts +45 -40
- package/lib/ml-dom/node/named-node-map.js +13 -5
- package/lib/ml-dom/node/node-list.d.ts +10 -4
- package/lib/ml-dom/node/node-list.js +25 -5
- package/lib/ml-dom/node/node-store.d.ts +9 -4
- package/lib/ml-dom/node/node-store.js +19 -1
- package/lib/ml-dom/node/node.d.ts +493 -473
- package/lib/ml-dom/node/node.js +52 -19
- package/lib/ml-dom/node/parent-node.d.ts +67 -58
- package/lib/ml-dom/node/parent-node.js +15 -6
- package/lib/ml-dom/node/rule-mapper.d.ts +7 -7
- package/lib/ml-dom/node/rule-mapper.js +11 -3
- package/lib/ml-dom/node/text.d.ts +50 -47
- package/lib/ml-dom/node/types.d.ts +82 -14
- package/lib/ml-dom/node/unexpected-call-error.d.ts +1 -2
- package/lib/ml-dom/token/token.d.ts +44 -44
- package/lib/ml-rule/create-rule.d.ts +4 -2
- package/lib/ml-rule/create-test-rule.d.ts +6 -4
- package/lib/ml-rule/ml-rule-context.d.ts +58 -50
- package/lib/ml-rule/ml-rule-context.js +4 -2
- package/lib/ml-rule/ml-rule.d.ts +36 -26
- package/lib/ml-rule/ml-rule.js +37 -32
- package/lib/ml-rule/types.d.ts +35 -17
- package/lib/plugin/plugin.d.ts +3 -1
- package/lib/plugin/types.d.ts +7 -7
- package/lib/ruleset/index.d.ts +4 -4
- package/lib/ruleset/index.js +4 -4
- package/lib/test/index.d.ts +20 -8
- package/lib/test/index.js +1 -1
- package/lib/types.d.ts +9 -8
- package/lib/utils/get-location-from-chars.d.ts +9 -4
- package/package.json +21 -15
- package/test/ml-dom/helper/accname.spec.js +85 -0
- package/test/ml-dom/helper/create-node.spec.js +18 -0
- package/test/ml-dom/index.spec.js +680 -0
- package/tsconfig.test.json +0 -3
- package/tsconfig.tsbuildinfo +0 -1
package/lib/plugin/types.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RuleSeed } from '../ml-rule';
|
|
2
2
|
import type { Config } from '@markuplint/ml-config';
|
|
3
3
|
export type Plugin = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly rules?: Readonly<Record<string, Readonly<RuleSeed<any, any>>>>;
|
|
6
|
+
readonly configs?: Readonly<Record<string, Config>>;
|
|
7
7
|
};
|
|
8
8
|
export type PluginCreator<S extends CreatePluginSettings> = {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
readonly name: string;
|
|
10
|
+
create(setting: S): Omit<Plugin, 'name'>;
|
|
11
11
|
};
|
|
12
|
-
export type CreatePluginSettings = Record<string, unknown
|
|
12
|
+
export type CreatePluginSettings = Readonly<Record<string, unknown>>;
|
package/lib/ruleset/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ChildNodeRule, Config, NodeRule, Rules } from '@markuplint/ml-config';
|
|
2
2
|
export default class Ruleset {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
readonly childNodeRules: readonly ChildNodeRule[];
|
|
4
|
+
readonly nodeRules: readonly NodeRule[];
|
|
5
|
+
readonly rules: Rules;
|
|
6
|
+
constructor(config: Config);
|
|
7
7
|
}
|
package/lib/ruleset/index.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
class Ruleset {
|
|
4
4
|
constructor(config) {
|
|
5
|
-
|
|
6
|
-
this.rules =
|
|
7
|
-
this.nodeRules =
|
|
8
|
-
this.childNodeRules =
|
|
5
|
+
var _a, _b, _c;
|
|
6
|
+
this.rules = (_a = config.rules) !== null && _a !== void 0 ? _a : {};
|
|
7
|
+
this.nodeRules = (_b = config.nodeRules) !== null && _b !== void 0 ? _b : [];
|
|
8
|
+
this.childNodeRules = (_c = config.childNodeRules) !== null && _c !== void 0 ? _c : [];
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
exports.default = Ruleset;
|
package/lib/test/index.d.ts
CHANGED
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
import type { MLMarkupLanguageParser } from '@markuplint/ml-ast';
|
|
2
|
-
import type { Config, RuleConfigValue } from '@markuplint/ml-config';
|
|
2
|
+
import type { Config, PlainData, RuleConfigValue } from '@markuplint/ml-config';
|
|
3
3
|
import type { ExtendedSpec, MLMLSpec } from '@markuplint/ml-spec';
|
|
4
4
|
import { Document } from '../ml-dom';
|
|
5
5
|
export type CreateTestOptions = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
readonly config?: Config;
|
|
7
|
+
readonly parser?: Readonly<MLMarkupLanguageParser>;
|
|
8
|
+
readonly specs?: MLMLSpec;
|
|
9
9
|
};
|
|
10
|
-
export declare function createTestDocument<T extends RuleConfigValue = any, O = any>(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
export declare function createTestDocument<T extends RuleConfigValue = any, O extends PlainData = any>(
|
|
11
|
+
sourceCode: string,
|
|
12
|
+
options?: CreateTestOptions,
|
|
13
|
+
): Document<T, O>;
|
|
14
|
+
export declare function createTestNodeList(
|
|
15
|
+
sourceCode: string,
|
|
16
|
+
options?: CreateTestOptions,
|
|
17
|
+
): readonly import('../ml-dom/node/node').MLNode<any, any, import('@markuplint/ml-ast').MLASTAbstractNode>[];
|
|
18
|
+
export declare function createTestTokenList(
|
|
19
|
+
sourceCode: string,
|
|
20
|
+
options?: CreateTestOptions,
|
|
21
|
+
): readonly import('../ml-dom/token/token').MLToken<import('@markuplint/ml-ast').MLToken>[];
|
|
22
|
+
export declare function createTestElement(
|
|
23
|
+
sourceCode: string,
|
|
24
|
+
options?: CreateTestOptions,
|
|
25
|
+
): import('../ml-dom').Element<any, any>;
|
|
14
26
|
/**
|
|
15
27
|
* for test suite
|
|
16
28
|
*/
|
package/lib/test/index.js
CHANGED
|
@@ -27,7 +27,7 @@ exports.createTestTokenList = createTestTokenList;
|
|
|
27
27
|
function createTestElement(sourceCode, options) {
|
|
28
28
|
const document = createTestDocument(sourceCode, options);
|
|
29
29
|
const el = document.nodeList[0];
|
|
30
|
-
if (el.is(el.ELEMENT_NODE)) {
|
|
30
|
+
if (el && el.is(el.ELEMENT_NODE)) {
|
|
31
31
|
return el;
|
|
32
32
|
}
|
|
33
33
|
throw TypeError(`Could not parse it to be an element from: ${sourceCode}`);
|
package/lib/types.d.ts
CHANGED
|
@@ -4,13 +4,14 @@ import type { LocaleSet } from '@markuplint/i18n';
|
|
|
4
4
|
import type { MLMarkupLanguageParser, ParserOptions } from '@markuplint/ml-ast';
|
|
5
5
|
import type { Pretender } from '@markuplint/ml-config';
|
|
6
6
|
import type { ExtendedSpec, MLMLSpec } from '@markuplint/ml-spec';
|
|
7
|
-
export type MLSchema =
|
|
7
|
+
export type MLSchema = readonly [MLMLSpec, ...ExtendedSpec[]];
|
|
8
8
|
export type MLFabric = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
readonly parser: Readonly<MLMarkupLanguageParser>;
|
|
10
|
+
readonly ruleset: Partial<Readonly<Ruleset>>;
|
|
11
|
+
readonly rules: readonly Readonly<AnyMLRule>[];
|
|
12
|
+
readonly locale: LocaleSet;
|
|
13
|
+
readonly schemas: MLSchema;
|
|
14
|
+
readonly parserOptions: ParserOptions;
|
|
15
|
+
readonly pretenders: readonly Pretender[];
|
|
16
|
+
readonly configErrors?: readonly Readonly<Error>[];
|
|
16
17
|
};
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
interface Location {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
line: number;
|
|
3
|
+
col: number;
|
|
4
|
+
raw: string;
|
|
5
5
|
}
|
|
6
|
-
export declare function getLocationFromChars(
|
|
6
|
+
export declare function getLocationFromChars(
|
|
7
|
+
searches: readonly string[],
|
|
8
|
+
text: string,
|
|
9
|
+
currentLine: number,
|
|
10
|
+
currentCol: number,
|
|
11
|
+
): Location[];
|
|
7
12
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/ml-core",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-dev.176+f6ad62e9",
|
|
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>",
|
|
@@ -11,26 +11,32 @@
|
|
|
11
11
|
"publishConfig": {
|
|
12
12
|
"access": "public"
|
|
13
13
|
},
|
|
14
|
+
"typedoc": {
|
|
15
|
+
"entryPoint": "./src/index.ts"
|
|
16
|
+
},
|
|
14
17
|
"scripts": {
|
|
15
18
|
"build": "tsc",
|
|
16
19
|
"dev": "tsc --build --watch",
|
|
17
20
|
"clean": "tsc --build --clean"
|
|
18
21
|
},
|
|
22
|
+
"browser": {
|
|
23
|
+
"./lib/configs.js": "./lib/configs.browser.js"
|
|
24
|
+
},
|
|
19
25
|
"dependencies": {
|
|
20
|
-
"@markuplint/config-presets": "3.0.0-
|
|
21
|
-
"@markuplint/
|
|
22
|
-
"@markuplint/
|
|
23
|
-
"@markuplint/
|
|
24
|
-
"@markuplint/ml-
|
|
25
|
-
"@markuplint/
|
|
26
|
-
"@markuplint/
|
|
26
|
+
"@markuplint/config-presets": "3.0.0-dev.176+f6ad62e9",
|
|
27
|
+
"@markuplint/html-parser": "3.0.0-dev.176+f6ad62e9",
|
|
28
|
+
"@markuplint/html-spec": "3.0.0-dev.176+f6ad62e9",
|
|
29
|
+
"@markuplint/i18n": "3.0.0-dev.176+f6ad62e9",
|
|
30
|
+
"@markuplint/ml-ast": "3.0.0-dev.176+f6ad62e9",
|
|
31
|
+
"@markuplint/ml-config": "3.0.0-dev.176+f6ad62e9",
|
|
32
|
+
"@markuplint/ml-spec": "3.0.0-dev.176+f6ad62e9",
|
|
33
|
+
"@markuplint/parser-utils": "3.0.0-dev.176+f6ad62e9",
|
|
34
|
+
"@markuplint/selector": "3.0.0-dev.176+f6ad62e9",
|
|
35
|
+
"@types/debug": "^4.1.7",
|
|
27
36
|
"debug": "^4.3.4",
|
|
28
|
-
"
|
|
29
|
-
"tslib": "^2.4.
|
|
30
|
-
|
|
31
|
-
"devDependencies": {
|
|
32
|
-
"@markuplint/html-parser": "3.0.0-canary.5+382d1365",
|
|
33
|
-
"@types/debug": "^4.1.7"
|
|
37
|
+
"is-plain-object": "^5.0.0",
|
|
38
|
+
"tslib": "^2.4.1",
|
|
39
|
+
"type-fest": "^3.8.0"
|
|
34
40
|
},
|
|
35
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "f6ad62e992e1569be4067f1e90d2d6017a658f57"
|
|
36
42
|
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const { parse } = require('@markuplint/html-parser');
|
|
2
|
+
|
|
3
|
+
const { convertRuleset } = require('../../../');
|
|
4
|
+
const { getAccname } = require('../../../lib/ml-dom/helper/accname');
|
|
5
|
+
const { createNode } = require('../../../lib/ml-dom/helper/create-node');
|
|
6
|
+
const { MLDocument } = require('../../../lib/ml-dom/node/document');
|
|
7
|
+
const { dummySchemas } = require('../../../lib/test');
|
|
8
|
+
|
|
9
|
+
function c(sourceCode) {
|
|
10
|
+
const ast = parse(sourceCode);
|
|
11
|
+
const astNode = ast.nodeList[0];
|
|
12
|
+
const ruleset = convertRuleset({});
|
|
13
|
+
const document = new MLDocument(ast, ruleset, dummySchemas());
|
|
14
|
+
const node = createNode(astNode, document);
|
|
15
|
+
if (node.is(node.ELEMENT_NODE)) {
|
|
16
|
+
return node;
|
|
17
|
+
}
|
|
18
|
+
throw new Error();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
test('Get accessible name', () => {
|
|
22
|
+
expect(getAccname(c('<button>label</button>'), '1.2')).toBe('label');
|
|
23
|
+
expect(getAccname(c('<div>text</div>'), '1.2')).toBe('');
|
|
24
|
+
expect(getAccname(c('<div aria-label="label">text</div>'), '1.2')).toBe('label');
|
|
25
|
+
expect(getAccname(c('<span aria-label="label">text</span>'), '1.2')).toBe('label');
|
|
26
|
+
expect(getAccname(c('<img alt="alternative-text" />'), '1.2')).toBe('alternative-text');
|
|
27
|
+
expect(getAccname(c('<img title="title" />'), '1.2')).toBe('title');
|
|
28
|
+
expect(getAccname(c('<div><label for="a">label</label><input id="a" /></div>').children[1], '1.2')).toBe('label');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('Invisible element', () => {
|
|
32
|
+
expect(getAccname(c('<button>label</button>'), '1.2')).toBe('label');
|
|
33
|
+
expect(getAccname(c('<button aria-disabled="true">label</button>'), '1.2')).toBe('label');
|
|
34
|
+
expect(getAccname(c('<button aria-hidden="true">label</button>'), '1.2')).toBe('');
|
|
35
|
+
expect(getAccname(c('<button hidden>label</button>'), '1.2')).toBe('');
|
|
36
|
+
expect(getAccname(c('<button style="display: none">label</button>'), '1.2')).toBe('label'); // Do not support the style attribute yet.
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @see https://www.w3.org/TR/accname-1.1/#ex-1-example-1-element1-id-el1-aria-labelledby-el3-element2-id-el2-aria-labelledby-el1-element3-id-el3-hello-element3
|
|
41
|
+
*/
|
|
42
|
+
test('accname-1.1 Example 1', () => {
|
|
43
|
+
const complex = c(`<div>
|
|
44
|
+
<input id="el1" aria-labelledby="el3" />
|
|
45
|
+
<input id="el2" aria-labelledby="el1" />
|
|
46
|
+
<h1 id="el3"> hello </h1>
|
|
47
|
+
</div>`);
|
|
48
|
+
expect(getAccname(complex.children[0], '1.2')).toBe('hello');
|
|
49
|
+
expect(getAccname(complex.children[1], '1.2')).toBe('');
|
|
50
|
+
expect(getAccname(complex.children[2], '1.2')).toBe('hello');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* https://www.w3.org/TR/accname-1.1/#ex-2-example-2-h1-files-h1-ul-li-a-id-file_row1-href-files-documentation-pdf-documentation-pdf-a-span-role-button-tabindex-0-id-del_row1-aria-label-delete-aria-labelledby-del_row1-file_row1-span-li-li-a-id-file_row2-href-files-holidayletter-pdf-holidayletter-pdf-a-span-role-button-tabindex-0-id-del_row2-aria-label-delete-aria-labelledby-del_row2-file_row2-span-li-ul
|
|
55
|
+
*/
|
|
56
|
+
test('accname-1.1 Example 2', () => {
|
|
57
|
+
const complex = c(`<ul>
|
|
58
|
+
<li>
|
|
59
|
+
<a id="file_row1" href="./files/Documentation.pdf">Documentation.pdf</a>
|
|
60
|
+
<span role="button" tabindex="0" id="del_row1" aria-label="Delete" aria-labelledby="del_row1 file_row1"></span>
|
|
61
|
+
</li>
|
|
62
|
+
<li>
|
|
63
|
+
<a id="file_row2" href="./files/HolidayLetter.pdf">HolidayLetter.pdf</a>
|
|
64
|
+
<span role="button" tabindex="0" id="del_row2" aria-label="Delete" aria-labelledby="del_row2 file_row2"></span>
|
|
65
|
+
</li>
|
|
66
|
+
</ul>`);
|
|
67
|
+
const spans = complex.querySelectorAll('span');
|
|
68
|
+
expect(getAccname(spans[0], '1.2')).toBe('Delete Documentation.pdf');
|
|
69
|
+
expect(getAccname(spans[1], '1.2')).toBe('Delete HolidayLetter.pdf');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* https://www.w3.org/TR/accname-1.1/#ex-3-example-3-div-role-checkbox-aria-checked-false-flash-the-screen-span-role-textbox-aria-multiline-false-5-span-times-div
|
|
74
|
+
*/
|
|
75
|
+
test('accname-1.1 Example 3', () => {
|
|
76
|
+
const complex = c(
|
|
77
|
+
'<div role="checkbox" aria-checked="false">Flash the screen <span role="textbox" aria-multiline="false"> 5 </span> times</div>',
|
|
78
|
+
);
|
|
79
|
+
expect(getAccname(complex, '1.2')).toBe('Flash the screen 5 times');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('with comment', () => {
|
|
83
|
+
expect(getAccname(c('<button>label</button>'), '1.2')).toBe('label');
|
|
84
|
+
expect(getAccname(c('<button>label<!-- comment --></button>'), '1.2')).toBe('label');
|
|
85
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const { parse } = require('@markuplint/html-parser');
|
|
2
|
+
|
|
3
|
+
const { convertRuleset } = require('../../../');
|
|
4
|
+
const { Document } = require('../../../lib/ml-dom/');
|
|
5
|
+
const { createNode } = require('../../../lib/ml-dom/helper/create-node');
|
|
6
|
+
const { dummySchemas } = require('../../../lib/test');
|
|
7
|
+
|
|
8
|
+
describe('create Node', () => {
|
|
9
|
+
it('Element', () => {
|
|
10
|
+
const sourceCode = '<div>text</div>';
|
|
11
|
+
const ast = parse(sourceCode);
|
|
12
|
+
const astNode = ast.nodeList[0];
|
|
13
|
+
const ruleset = convertRuleset({});
|
|
14
|
+
const document = new Document(ast, ruleset, dummySchemas());
|
|
15
|
+
const node = createNode(astNode, document);
|
|
16
|
+
expect(node.raw).toBe('<div>');
|
|
17
|
+
});
|
|
18
|
+
});
|