@markuplint/ml-core 4.0.0-alpha.2 → 4.0.0-alpha.3

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.js CHANGED
@@ -31,6 +31,7 @@ async function forceImportJsonInModule(modPath) {
31
31
  .replace(/^[\\/][a-z]:/i, '');
32
32
  log('Find JSON file path: %s', normalizePath);
33
33
  const fileContent = await readFile(normalizePath, { encoding: 'utf8' });
34
+ log('Success to read JSON file path: %s', normalizePath);
34
35
  return JSON.parse(fileContent);
35
36
  }
36
37
  return error.default ? error.default : error;
package/lib/index.d.ts CHANGED
@@ -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';
@@ -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,7 @@
1
1
  var _MLDocument_filename, _MLDocument_tokenList;
2
2
  import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
3
3
  import { exchangeValueOnRule, mergeRule } from '@markuplint/ml-config';
4
- import { schemaToSpec } from '@markuplint/ml-spec';
4
+ import { schemaToSpec, getAccname, getComputedRole, mayBeFocusable, getComputedAriaProps, isExposed, ARIA_RECOMMENDED_VERSION, } from '@markuplint/ml-spec';
5
5
  import { ConfigParserError } from '@markuplint/parser-utils';
6
6
  import { InvalidSelectorError, matchSelector } from '@markuplint/selector';
7
7
  import { log as coreLog } from '../../debug.js';
@@ -1824,6 +1824,46 @@ export class MLDocument extends MLParentNode {
1824
1824
  exitPointerLock() {
1825
1825
  throw new UnexpectedCallError('Not supported "exitPointerLock" method');
1826
1826
  }
1827
+ getAccessibilityProp(
1828
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
1829
+ node, ariaVersion = ARIA_RECOMMENDED_VERSION) {
1830
+ if (!node.is(node.ELEMENT_NODE)) {
1831
+ return null;
1832
+ }
1833
+ const exposed = isExposed(node, node.ownerMLDocument.specs, ariaVersion);
1834
+ if (!exposed) {
1835
+ return {
1836
+ exposedToTree: false,
1837
+ };
1838
+ }
1839
+ const aria = {
1840
+ exposedToTree: true,
1841
+ };
1842
+ const role = getComputedRole(node.ownerMLDocument.specs, node, ariaVersion);
1843
+ const name = getAccname(node).trim();
1844
+ const focusable = mayBeFocusable(node, node.ownerMLDocument.specs);
1845
+ const nameRequired = role.role?.accessibleNameRequired ?? false;
1846
+ const nameProhibited = role.role?.accessibleNameProhibited ?? false;
1847
+ aria.role = role.role?.name;
1848
+ aria.nameRequired = nameRequired;
1849
+ aria.nameProhibited = nameProhibited;
1850
+ aria.name = name;
1851
+ aria.focusable = focusable;
1852
+ Object.values(getComputedAriaProps(node.ownerMLDocument.specs, node, ariaVersion)).forEach(prop => {
1853
+ if (!prop.required) {
1854
+ if (prop.from === 'default') {
1855
+ return;
1856
+ }
1857
+ }
1858
+ aria.props = aria.props || {};
1859
+ const propName = prop.name.replace('aria-', '');
1860
+ aria.props[propName] = {
1861
+ value: prop.value ?? null,
1862
+ required: prop.required,
1863
+ };
1864
+ });
1865
+ return aria;
1866
+ }
1827
1867
  /**
1828
1868
  * **IT THROWS AN ERROR WHEN CALLING THIS.**
1829
1869
  *
@@ -33,3 +33,17 @@ 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 = {
37
+ exposedToTree: boolean;
38
+ role?: string;
39
+ roleDescription?: string;
40
+ name?: string;
41
+ nameRequired?: boolean;
42
+ nameProhibited?: boolean;
43
+ focusable?: boolean;
44
+ props?: Record<string, AccessibilityProperty>;
45
+ };
46
+ export type AccessibilityProperty = {
47
+ value: string | null;
48
+ required: boolean;
49
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/ml-core",
3
- "version": "4.0.0-alpha.2",
3
+ "version": "4.0.0-alpha.3",
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,20 @@
28
28
  "./lib/configs.js": "./lib/configs.browser.js"
29
29
  },
30
30
  "dependencies": {
31
- "@markuplint/config-presets": "4.0.0-alpha.2",
32
- "@markuplint/html-parser": "4.0.0-alpha.2",
33
- "@markuplint/html-spec": "4.0.0-alpha.2",
34
- "@markuplint/i18n": "4.0.0-alpha.2",
35
- "@markuplint/ml-ast": "4.0.0-alpha.2",
36
- "@markuplint/ml-config": "4.0.0-alpha.2",
37
- "@markuplint/ml-spec": "4.0.0-alpha.2",
38
- "@markuplint/parser-utils": "4.0.0-alpha.2",
39
- "@markuplint/selector": "4.0.0-alpha.2",
31
+ "@markuplint/config-presets": "4.0.0-alpha.3",
32
+ "@markuplint/html-parser": "4.0.0-alpha.3",
33
+ "@markuplint/html-spec": "4.0.0-alpha.3",
34
+ "@markuplint/i18n": "4.0.0-alpha.3",
35
+ "@markuplint/ml-ast": "4.0.0-alpha.3",
36
+ "@markuplint/ml-config": "4.0.0-alpha.3",
37
+ "@markuplint/ml-spec": "4.0.0-alpha.3",
38
+ "@markuplint/parser-utils": "4.0.0-alpha.3",
39
+ "@markuplint/selector": "4.0.0-alpha.3",
40
40
  "@types/debug": "^4.1.9",
41
41
  "debug": "^4.3.4",
42
42
  "is-plain-object": "^5.0.0",
43
43
  "tslib": "^2.6.2",
44
44
  "type-fest": "^4.3.1"
45
45
  },
46
- "gitHead": "51ad52c760435641f9bff8685707d8178b0787eb"
46
+ "gitHead": "380836f7adc1ff7e8eaf9d869e68d29eee8f3b7e"
47
47
  }