@markuplint/ml-core 2.3.0 → 3.0.0-alpha.66

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.
Files changed (98) hide show
  1. package/lib/configs.d.ts +1 -1
  2. package/lib/configs.js +29 -9
  3. package/lib/index.d.ts +8 -8
  4. package/lib/index.js +18 -10
  5. package/lib/ml-core.d.ts +3 -3
  6. package/lib/ml-core.js +41 -42
  7. package/lib/ml-dom/document.d.ts +79 -70
  8. package/lib/ml-dom/helper/accname.d.ts +2 -2
  9. package/lib/ml-dom/helper/accname.js +2 -3
  10. package/lib/ml-dom/helper/create-node.d.ts +3 -4
  11. package/lib/ml-dom/helper/create-node.js +11 -15
  12. package/lib/ml-dom/helper/debug.d.ts +2 -2
  13. package/lib/ml-dom/helper/debug.js +35 -21
  14. package/lib/ml-dom/helper/getIndent.d.ts +5 -5
  15. package/lib/ml-dom/helper/getIndent.js +14 -14
  16. package/lib/ml-dom/helper/mapped-nodes.d.ts +51 -3
  17. package/lib/ml-dom/helper/match-selector.d.ts +10 -6
  18. package/lib/ml-dom/helper/node-store.d.ts +6 -3
  19. package/lib/ml-dom/helper/selector.d.ts +4 -4
  20. package/lib/ml-dom/helper/walkers.d.ts +5 -4
  21. package/lib/ml-dom/helper/walkers.js +39 -3
  22. package/lib/ml-dom/index.d.ts +8 -3
  23. package/lib/ml-dom/index.js +3 -15
  24. package/lib/ml-dom/manipulations/child-node-methods.d.ts +33 -0
  25. package/lib/ml-dom/manipulations/child-node-methods.js +73 -0
  26. package/lib/ml-dom/manipulations/get-children.d.ts +4 -0
  27. package/lib/ml-dom/manipulations/get-children.js +10 -0
  28. package/lib/ml-dom/node/attr.d.ts +98 -0
  29. package/lib/ml-dom/node/attr.js +151 -0
  30. package/lib/ml-dom/node/block.d.ts +38 -0
  31. package/lib/ml-dom/node/block.js +53 -0
  32. package/lib/ml-dom/node/character-data.d.ts +57 -0
  33. package/lib/ml-dom/node/character-data.js +87 -0
  34. package/lib/ml-dom/node/child-node.d.ts +9 -0
  35. package/lib/ml-dom/node/child-node.js +10 -0
  36. package/lib/ml-dom/node/comment.d.ts +17 -0
  37. package/lib/ml-dom/node/comment.js +24 -0
  38. package/lib/ml-dom/node/document-fragment.d.ts +24 -0
  39. package/lib/ml-dom/node/document-fragment.js +33 -0
  40. package/lib/ml-dom/node/document-type.d.ts +38 -0
  41. package/lib/ml-dom/node/document-type.js +52 -0
  42. package/lib/ml-dom/node/document.d.ts +1554 -0
  43. package/lib/ml-dom/node/document.js +2117 -0
  44. package/lib/ml-dom/node/dom-token-list.d.ts +33 -0
  45. package/lib/ml-dom/node/dom-token-list.js +137 -0
  46. package/lib/ml-dom/node/element.d.ts +1825 -0
  47. package/lib/ml-dom/node/element.js +2462 -0
  48. package/lib/ml-dom/node/named-node-map.d.ts +42 -0
  49. package/lib/ml-dom/node/named-node-map.js +64 -0
  50. package/lib/ml-dom/node/node-list.d.ts +6 -0
  51. package/lib/ml-dom/node/node-list.js +39 -0
  52. package/lib/ml-dom/node/node-store.d.ts +14 -0
  53. package/lib/ml-dom/node/node-store.js +32 -0
  54. package/lib/ml-dom/node/node.d.ts +475 -0
  55. package/lib/ml-dom/node/node.js +666 -0
  56. package/lib/ml-dom/node/parent-node.d.ts +66 -0
  57. package/lib/ml-dom/node/parent-node.js +131 -0
  58. package/lib/ml-dom/node/rule-mapper.d.ts +17 -0
  59. package/lib/ml-dom/node/rule-mapper.js +49 -0
  60. package/lib/ml-dom/node/text.d.ts +51 -0
  61. package/lib/ml-dom/node/text.js +76 -0
  62. package/lib/ml-dom/node/types.d.ts +25 -0
  63. package/lib/ml-dom/node/types.js +2 -0
  64. package/lib/ml-dom/node/unexpected-call-error.d.ts +2 -0
  65. package/lib/ml-dom/node/unexpected-call-error.js +5 -0
  66. package/lib/ml-dom/rule-mapper.d.ts +7 -7
  67. package/lib/ml-dom/token/token.d.ts +47 -0
  68. package/lib/ml-dom/token/token.js +89 -0
  69. package/lib/ml-dom/tokens/abstract-element.d.ts +47 -42
  70. package/lib/ml-dom/tokens/attribute.d.ts +38 -38
  71. package/lib/ml-dom/tokens/comment.d.ts +7 -4
  72. package/lib/ml-dom/tokens/doctype.d.ts +12 -9
  73. package/lib/ml-dom/tokens/element-close-tag.d.ts +20 -17
  74. package/lib/ml-dom/tokens/element.d.ts +18 -15
  75. package/lib/ml-dom/tokens/node.d.ts +38 -31
  76. package/lib/ml-dom/tokens/omitted-element.d.ts +7 -4
  77. package/lib/ml-dom/tokens/preprocessor-specific-attribute.d.ts +20 -20
  78. package/lib/ml-dom/tokens/preprocessor-specific-block.d.ts +8 -5
  79. package/lib/ml-dom/tokens/text.d.ts +13 -9
  80. package/lib/ml-dom/tokens/token.d.ts +13 -13
  81. package/lib/ml-dom/types.d.ts +35 -13
  82. package/lib/ml-rule/ml-rule-context.d.ts +13 -10
  83. package/lib/ml-rule/ml-rule-context.js +12 -6
  84. package/lib/ml-rule/ml-rule.d.ts +8 -8
  85. package/lib/ml-rule/ml-rule.js +62 -62
  86. package/lib/ml-rule/types.d.ts +11 -1
  87. package/lib/ruleset/index.d.ts +2 -2
  88. package/lib/selector/is-pure-html-element.d.ts +1 -0
  89. package/lib/selector/is-pure-html-element.js +7 -0
  90. package/lib/selector/match-selector.d.ts +14 -0
  91. package/lib/selector/match-selector.js +230 -0
  92. package/lib/selector/selector.d.ts +9 -0
  93. package/lib/selector/selector.js +561 -0
  94. package/lib/test/index.d.ts +2 -1
  95. package/lib/test/index.js +7 -2
  96. package/package.json +8 -7
  97. package/tsconfig.tsbuildinfo +1 -1
  98. package/markuplint-recommended.json +0 -196
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- var _MLDOMIndentation_node, _MLDOMIndentation_parent, _MLDOMIndentation_fixed;
2
+ var _MLDOMIndentation_fixed, _MLDOMIndentation_node, _MLDOMIndentation_parent;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.getIndent = void 0;
5
5
  const tslib_1 = require("tslib");
@@ -13,8 +13,8 @@ function getIndent(node) {
13
13
  if (!prevToken) {
14
14
  return null;
15
15
  }
16
- if (node.type === 'Text') {
17
- if (node.isRawText) {
16
+ if (node.is(node.TEXT_NODE)) {
17
+ if (node.isRawTextElementContent()) {
18
18
  return null;
19
19
  }
20
20
  const matched = node.raw.match(/^(\s*(?:\r?\n)+\s*)(?:[^\s]+)/);
@@ -31,7 +31,7 @@ function getIndent(node) {
31
31
  }
32
32
  return null;
33
33
  }
34
- if (prevToken.type !== 'Text') {
34
+ if (!prevToken.is(node.TEXT_NODE)) {
35
35
  return null;
36
36
  }
37
37
  // One or more newlines and zero or more spaces or tabs.
@@ -52,33 +52,33 @@ function getIndent(node) {
52
52
  exports.getIndent = getIndent;
53
53
  class MLDOMIndentation {
54
54
  constructor(originTextNode, raw, line, parentNode) {
55
+ _MLDOMIndentation_fixed.set(this, void 0);
55
56
  _MLDOMIndentation_node.set(this, void 0);
56
57
  _MLDOMIndentation_parent.set(this, void 0);
57
- _MLDOMIndentation_fixed.set(this, void 0);
58
58
  this.line = line;
59
59
  tslib_1.__classPrivateFieldSet(this, _MLDOMIndentation_node, originTextNode, "f");
60
60
  tslib_1.__classPrivateFieldSet(this, _MLDOMIndentation_parent, parentNode, "f");
61
61
  tslib_1.__classPrivateFieldSet(this, _MLDOMIndentation_fixed, raw, "f");
62
62
  }
63
+ get raw() {
64
+ if (!tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_parent, "f").is(tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_parent, "f").TEXT_NODE) && this.line !== tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_node, "f").endLine) {
65
+ return '';
66
+ }
67
+ return tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_fixed, "f");
68
+ }
63
69
  get type() {
64
- if (tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_parent, "f").type !== 'Text' && this.line !== tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_node, "f").endLine) {
70
+ if (!tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_parent, "f").is(tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_parent, "f").TEXT_NODE) && this.line !== tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_node, "f").endLine) {
65
71
  return 'none';
66
72
  }
67
73
  const raw = tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_fixed, "f");
68
74
  return raw === '' ? 'none' : /^\t+$/.test(raw) ? 'tab' : /^[^\t]+$/.test(raw) ? 'space' : 'mixed';
69
75
  }
70
76
  get width() {
71
- if (tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_parent, "f").type !== 'Text' && this.line !== tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_node, "f").endLine) {
77
+ if (!tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_parent, "f").is(tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_parent, "f").TEXT_NODE) && this.line !== tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_node, "f").endLine) {
72
78
  return 0;
73
79
  }
74
80
  return tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_fixed, "f").length;
75
81
  }
76
- get raw() {
77
- if (tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_parent, "f").type !== 'Text' && this.line !== tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_node, "f").endLine) {
78
- return '';
79
- }
80
- return tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_fixed, "f");
81
- }
82
82
  fix(raw) {
83
83
  const current = tslib_1.__classPrivateFieldGet(this, _MLDOMIndentation_fixed, "f");
84
84
  tslib_1.__classPrivateFieldSet(this, _MLDOMIndentation_fixed, raw, "f");
@@ -94,7 +94,7 @@ class MLDOMIndentation {
94
94
  }
95
95
  }
96
96
  }
97
- _MLDOMIndentation_node = new WeakMap(), _MLDOMIndentation_parent = new WeakMap(), _MLDOMIndentation_fixed = new WeakMap();
97
+ _MLDOMIndentation_fixed = new WeakMap(), _MLDOMIndentation_node = new WeakMap(), _MLDOMIndentation_parent = new WeakMap();
98
98
  function isFirstToken(node) {
99
99
  return !node.prevToken;
100
100
  }
@@ -1,4 +1,52 @@
1
- import type { MLDOMAttribute, MLDOMComment, MLDOMDoctype, MLDOMElement, MLDOMElementCloseTag, MLDOMNode, MLDOMOmittedElement, MLDOMPreprocessorSpecificBlock, MLDOMText, MLDOMToken } from '../tokens';
2
- import type { MLASTAbstructNode, MLASTAttr, MLASTComment, MLASTDoctype, MLASTElement, MLASTElementCloseTag, MLASTNode, MLASTOmittedElement, MLASTParentNode, MLASTPreprocessorSpecificBlock, MLASTText, MLToken } from '@markuplint/ml-ast/';
1
+ import type {
2
+ MLDOMAttribute,
3
+ MLDOMComment,
4
+ MLDOMDoctype,
5
+ MLDOMElement,
6
+ MLDOMElementCloseTag,
7
+ MLDOMNode,
8
+ MLDOMOmittedElement,
9
+ MLDOMPreprocessorSpecificBlock,
10
+ MLDOMText,
11
+ MLDOMToken,
12
+ } from '../tokens';
13
+ import type {
14
+ MLASTAbstructNode,
15
+ MLASTAttr,
16
+ MLASTComment,
17
+ MLASTDoctype,
18
+ MLASTElement,
19
+ MLASTElementCloseTag,
20
+ MLASTNode,
21
+ MLASTOmittedElement,
22
+ MLASTParentNode,
23
+ MLASTPreprocessorSpecificBlock,
24
+ MLASTText,
25
+ MLToken,
26
+ } from '@markuplint/ml-ast/';
3
27
  import type { RuleConfigValue } from '@markuplint/ml-config';
4
- export declare type MappedNode<N, T extends RuleConfigValue, O = null> = N extends MLASTElement ? MLDOMElement<T, O> : N extends MLASTElementCloseTag ? MLDOMElementCloseTag<T, O> : N extends MLASTOmittedElement ? MLDOMOmittedElement<T, O> : N extends MLASTParentNode ? (MLDOMElement<T, O> | MLDOMOmittedElement<T, O>) : N extends MLASTComment ? MLDOMComment<T, O> : N extends MLASTText ? MLDOMText<T, O> : N extends MLASTDoctype ? MLDOMDoctype<T, O> : N extends MLASTNode ? MLDOMNode<T, O, MLASTNode> : N extends MLASTPreprocessorSpecificBlock ? MLDOMPreprocessorSpecificBlock<T, O> : N extends MLASTAbstructNode ? MLDOMNode<T, O, MLASTAbstructNode> : N extends MLASTAttr ? MLDOMAttribute : N extends MLToken ? MLDOMToken<MLToken> : never;
28
+ export declare type MappedNode<N, T extends RuleConfigValue, O = null> = N extends MLASTElement
29
+ ? MLDOMElement<T, O>
30
+ : N extends MLASTElementCloseTag
31
+ ? MLDOMElementCloseTag<T, O>
32
+ : N extends MLASTOmittedElement
33
+ ? MLDOMOmittedElement<T, O>
34
+ : N extends MLASTParentNode
35
+ ? MLDOMElement<T, O> | MLDOMOmittedElement<T, O>
36
+ : N extends MLASTComment
37
+ ? MLDOMComment<T, O>
38
+ : N extends MLASTText
39
+ ? MLDOMText<T, O>
40
+ : N extends MLASTDoctype
41
+ ? MLDOMDoctype<T, O>
42
+ : N extends MLASTNode
43
+ ? MLDOMNode<T, O, MLASTNode>
44
+ : N extends MLASTPreprocessorSpecificBlock
45
+ ? MLDOMPreprocessorSpecificBlock<T, O>
46
+ : N extends MLASTAbstructNode
47
+ ? MLDOMNode<T, O, MLASTAbstructNode>
48
+ : N extends MLASTAttr
49
+ ? MLDOMAttribute
50
+ : N extends MLToken
51
+ ? MLDOMToken<MLToken>
52
+ : never;
@@ -3,14 +3,18 @@ import type { Specificity } from './selector';
3
3
  import type { RegexSelector } from '@markuplint/ml-config';
4
4
  export declare type SelectorMatches = SelectorMatched | SelectorUnmatched;
5
5
  declare type SelectorMatched = {
6
- matched: true;
7
- selector: string;
8
- specificity: Specificity;
9
- data?: Record<string, string>;
6
+ matched: true;
7
+ selector: string;
8
+ specificity: Specificity;
9
+ data?: Record<string, string>;
10
10
  };
11
11
  declare type SelectorUnmatched = {
12
- matched: false;
12
+ matched: false;
13
13
  };
14
14
  declare type TargetElement = MLDOMAbstractElement<any, any>;
15
- export declare function matchSelector(el: TargetElement, selector: string | RegexSelector | undefined, tagNameCaseSensitive?: boolean): SelectorMatches;
15
+ export declare function matchSelector(
16
+ el: TargetElement,
17
+ selector: string | RegexSelector | undefined,
18
+ tagNameCaseSensitive?: boolean,
19
+ ): SelectorMatches;
16
20
  export {};
@@ -3,7 +3,10 @@ import type { MappedNode } from './mapped-nodes';
3
3
  import type { MLASTAbstructNode } from '@markuplint/ml-ast';
4
4
  import type { RuleConfigValue } from '@markuplint/ml-config';
5
5
  export default class NodeStore {
6
- #private;
7
- setNode<A extends MLASTAbstructNode, T extends RuleConfigValue, O = null>(astNode: A, node: MLDOMNode<T, O, A>): void;
8
- getNode<N extends MLASTAbstructNode, T extends RuleConfigValue, O = null>(astNode: N): MappedNode<N, T, O>;
6
+ #private;
7
+ setNode<A extends MLASTAbstructNode, T extends RuleConfigValue, O = null>(
8
+ astNode: A,
9
+ node: MLDOMNode<T, O, A>,
10
+ ): void;
11
+ getNode<N extends MLASTAbstructNode, T extends RuleConfigValue, O = null>(astNode: N): MappedNode<N, T, O>;
9
12
  }
@@ -1,11 +1,11 @@
1
1
  import type MLDOMAbstractElement from '../tokens/abstract-element';
2
2
  export declare type Specificity = [number, number, number];
3
3
  export declare function createSelector(selector: string, tagNameCaseSensitive?: boolean): Selector;
4
- export declare function compareSpecificity(a: Specificity, b: Specificity): 1 | 0 | -1;
4
+ export declare function compareSpecificity(a: Specificity, b: Specificity): 0 | 1 | -1;
5
5
  declare type TargetElement = MLDOMAbstractElement<any, any>;
6
6
  declare class Selector {
7
- #private;
8
- constructor(selector: string, tagNameCaseSensitive: boolean);
9
- match(el: TargetElement, caller?: TargetElement | null): Specificity | false;
7
+ #private;
8
+ constructor(selector: string, tagNameCaseSensitive: boolean);
9
+ match(el: TargetElement, caller?: TargetElement | null): Specificity | false;
10
10
  }
11
11
  export {};
@@ -1,5 +1,6 @@
1
- import type { AnonymousNode } from '../types';
1
+ import type { MLNode } from '../node/node';
2
2
  import type { RuleConfigValue } from '@markuplint/ml-config';
3
- export declare type Walker<T extends RuleConfigValue, O = null, N = AnonymousNode<T, O>> = (node: N) => void | Promise<void>;
4
- export declare type SyncWalker<T extends RuleConfigValue, O = null, N = AnonymousNode<T, O>> = (node: N) => void;
5
- export declare function syncWalk<T extends RuleConfigValue, O = null>(nodeList: AnonymousNode<T, O>[], walker: SyncWalker<T, O>): void;
3
+ export declare type Walker<T extends RuleConfigValue, O = null, N = MLNode<T, O>> = (node: N) => void | Promise<void> | Promise<void>[];
4
+ export declare type SyncWalker<T extends RuleConfigValue, O = null, N = MLNode<T, O>> = (node: N) => void;
5
+ export declare function syncWalk<T extends RuleConfigValue, O = null>(nodeList: ReadonlyArray<MLNode<T, O>>, walker: SyncWalker<T, O>): void;
6
+ export declare function sequentialWalker<T extends RuleConfigValue, O = null, N = MLNode<T, O>>(list: ReadonlyArray<N>, walker: Walker<T, O, N>): Promise<void>;
@@ -1,12 +1,48 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.syncWalk = void 0;
3
+ exports.sequentialWalker = exports.syncWalk = void 0;
4
4
  function syncWalk(nodeList, walker) {
5
5
  for (const node of nodeList) {
6
- if (node.type === 'Element' || node.type === 'OmittedElement' || node.type === 'PSBlock') {
7
- syncWalk(node.childNodes, walker);
6
+ if (node.is(node.ELEMENT_NODE) || node.is(node.MARKUPLINT_PREPROCESSOR_BLOCK)) {
7
+ syncWalk(Array.from(node.childNodes), walker);
8
8
  }
9
9
  walker(node);
10
10
  }
11
11
  }
12
12
  exports.syncWalk = syncWalk;
13
+ function sequentialWalker(list, walker) {
14
+ if (list.length === 0) {
15
+ return Promise.resolve();
16
+ }
17
+ /**
18
+ * The following pattern is used to ensure that all rules run sequentially,
19
+ * no matter it runs asynchronously or synchronously.
20
+ */
21
+ let _resolve;
22
+ let _reject;
23
+ const promise = new Promise((resolve, reject) => {
24
+ _resolve = resolve;
25
+ _reject = reject;
26
+ });
27
+ const loop = (index = 0) => {
28
+ if (index >= list.length) {
29
+ _resolve();
30
+ return;
31
+ }
32
+ const node = list[index];
33
+ if (!node) {
34
+ _resolve();
35
+ return;
36
+ }
37
+ const result = walker(node);
38
+ if (result instanceof Promise) {
39
+ result.then(() => loop(index + 1)).catch(_reject);
40
+ }
41
+ else {
42
+ loop(index + 1);
43
+ }
44
+ };
45
+ loop();
46
+ return promise;
47
+ }
48
+ exports.sequentialWalker = sequentialWalker;
@@ -1,3 +1,8 @@
1
- export { default as Document } from './document';
2
- export { AnonymousNode, NodeType } from './types';
3
- export { MLDOMAttribute as Attribute, MLDOMComment as Comment, MLDOMDoctype as Doctype, MLDOMElement as Element, MLDOMElementCloseTag as ElementCloseTag, MLDOMNode as Node, MLDOMOmittedElement as OmittedElement, MLDOMText as Text, } from './tokens';
1
+ export type { MLAttr as Attr } from './node/attr';
2
+ export type { MLBlock as Block } from './node/block';
3
+ export type { MLComment as Comment } from './node/comment';
4
+ export type { MLDocumentFragment as DocumentFragment } from './node/document-fragment';
5
+ export type { MLDocumentType as DocumentType } from './node/document-type';
6
+ export type { MLElement as Element } from './node/element';
7
+ export type { MLText as Text } from './node/text';
8
+ export { MLDocument as Document } from './node/document';
@@ -1,17 +1,5 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Text = exports.OmittedElement = exports.Node = exports.ElementCloseTag = exports.Element = exports.Doctype = exports.Comment = exports.Attribute = exports.Document = void 0;
7
- var document_1 = require("./document");
8
- Object.defineProperty(exports, "Document", { enumerable: true, get: function () { return __importDefault(document_1).default; } });
9
- var tokens_1 = require("./tokens");
10
- Object.defineProperty(exports, "Attribute", { enumerable: true, get: function () { return tokens_1.MLDOMAttribute; } });
11
- Object.defineProperty(exports, "Comment", { enumerable: true, get: function () { return tokens_1.MLDOMComment; } });
12
- Object.defineProperty(exports, "Doctype", { enumerable: true, get: function () { return tokens_1.MLDOMDoctype; } });
13
- Object.defineProperty(exports, "Element", { enumerable: true, get: function () { return tokens_1.MLDOMElement; } });
14
- Object.defineProperty(exports, "ElementCloseTag", { enumerable: true, get: function () { return tokens_1.MLDOMElementCloseTag; } });
15
- Object.defineProperty(exports, "Node", { enumerable: true, get: function () { return tokens_1.MLDOMNode; } });
16
- Object.defineProperty(exports, "OmittedElement", { enumerable: true, get: function () { return tokens_1.MLDOMOmittedElement; } });
17
- Object.defineProperty(exports, "Text", { enumerable: true, get: function () { return tokens_1.MLDOMText; } });
3
+ exports.Document = void 0;
4
+ var document_1 = require("./node/document");
5
+ Object.defineProperty(exports, "Document", { enumerable: true, get: function () { return document_1.MLDocument; } });
@@ -0,0 +1,33 @@
1
+ import type { MLElement } from '../node/element';
2
+ import type { MLNode } from '../node/node';
3
+ import type { RuleConfigValue } from '@markuplint/ml-config';
4
+ /**
5
+ *
6
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-childnode-before%E2%91%A0
7
+ */
8
+ export declare function before<T extends RuleConfigValue, O = null>(node: MLNode<T, O>, ...additionalNodes: ReadonlyArray<MLNode<T, O> | string>): void;
9
+ /**
10
+ *
11
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-childnode-after%E2%91%A0
12
+ */
13
+ export declare function after<T extends RuleConfigValue, O = null>(node: MLNode<T, O>, ...additionalNodes: ReadonlyArray<MLNode<T, O> | string>): void;
14
+ /**
15
+ *
16
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-childnode-replacewith%E2%91%A0
17
+ */
18
+ export declare function replaceWith<T extends RuleConfigValue, O = null>(node: MLNode<T, O>, ...additionalNodes: ReadonlyArray<MLNode<T, O> | string>): void;
19
+ /**
20
+ *
21
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-childnode-remove%E2%91%A0
22
+ */
23
+ export declare function remove<T extends RuleConfigValue, O = null>(node: MLNode<T, O>): void;
24
+ /**
25
+ *
26
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-nondocumenttypechildnode-previouselementsibling%E2%91%A0
27
+ */
28
+ export declare function previousElementSibling<T extends RuleConfigValue, O = null>(node: MLNode<T, O>): MLElement<T, O> | null;
29
+ /**
30
+ *
31
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-nondocumenttypechildnode-nextelementsibling%E2%91%A0
32
+ */
33
+ export declare function nextElementSibling<T extends RuleConfigValue, O = null>(node: MLNode<T, O>): MLElement<T, O> | null;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nextElementSibling = exports.previousElementSibling = exports.remove = exports.replaceWith = exports.after = exports.before = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const unexpected_call_error_1 = tslib_1.__importDefault(require("../node/unexpected-call-error"));
6
+ /**
7
+ *
8
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-childnode-before%E2%91%A0
9
+ */
10
+ function before(node, ...additionalNodes) {
11
+ throw new unexpected_call_error_1.default('Not supported "before" method');
12
+ }
13
+ exports.before = before;
14
+ /**
15
+ *
16
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-childnode-after%E2%91%A0
17
+ */
18
+ function after(node, ...additionalNodes) {
19
+ throw new unexpected_call_error_1.default('Not supported "after" method');
20
+ }
21
+ exports.after = after;
22
+ /**
23
+ *
24
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-childnode-replacewith%E2%91%A0
25
+ */
26
+ function replaceWith(node, ...additionalNodes) {
27
+ throw new unexpected_call_error_1.default('Not supported "replaceWith" method');
28
+ }
29
+ exports.replaceWith = replaceWith;
30
+ /**
31
+ *
32
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-childnode-remove%E2%91%A0
33
+ */
34
+ function remove(node) {
35
+ throw new unexpected_call_error_1.default('Not supported "remove" method');
36
+ }
37
+ exports.remove = remove;
38
+ /**
39
+ *
40
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-nondocumenttypechildnode-previouselementsibling%E2%91%A0
41
+ */
42
+ function previousElementSibling(node) {
43
+ var _a, _b;
44
+ let prevNode = node.prevNode;
45
+ while (prevNode) {
46
+ if (((node.parentNode === null && prevNode.parentNode === null) ||
47
+ ((_a = node.parentNode) === null || _a === void 0 ? void 0 : _a.uuid) === ((_b = prevNode.parentNode) === null || _b === void 0 ? void 0 : _b.uuid)) &&
48
+ prevNode.is(prevNode.ELEMENT_NODE)) {
49
+ return prevNode;
50
+ }
51
+ prevNode = prevNode.prevNode;
52
+ }
53
+ return null;
54
+ }
55
+ exports.previousElementSibling = previousElementSibling;
56
+ /**
57
+ *
58
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-nondocumenttypechildnode-nextelementsibling%E2%91%A0
59
+ */
60
+ function nextElementSibling(node) {
61
+ var _a, _b;
62
+ let nextNode = node.nextNode;
63
+ while (nextNode) {
64
+ if (((node.parentNode === null && nextNode.parentNode === null) ||
65
+ ((_a = node.parentNode) === null || _a === void 0 ? void 0 : _a.uuid) === ((_b = nextNode.parentNode) === null || _b === void 0 ? void 0 : _b.uuid)) &&
66
+ nextNode.is(nextNode.ELEMENT_NODE)) {
67
+ return nextNode;
68
+ }
69
+ nextNode = nextNode.nextNode;
70
+ }
71
+ return null;
72
+ }
73
+ exports.nextElementSibling = nextElementSibling;
@@ -0,0 +1,4 @@
1
+ import type { MLElement } from '../node/element';
2
+ import type { MLNode } from '../node/node';
3
+ import type { RuleConfigValue } from '@markuplint/ml-config';
4
+ export declare function getChildren<T extends RuleConfigValue, O = null>(node: MLNode<T, O>): HTMLCollectionOf<MLElement<T, O>>;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getChildren = void 0;
4
+ const node_list_1 = require("../node/node-list");
5
+ function getChildren(node) {
6
+ return (0, node_list_1.toHTMLCollection)(Array.from(node.childNodes).filter((child) => {
7
+ return child.nodeType === child.ELEMENT_NODE;
8
+ }));
9
+ }
10
+ exports.getChildren = getChildren;
@@ -0,0 +1,98 @@
1
+ import type { MLElement } from './element';
2
+ import type { AttributeNodeType } from './types';
3
+ import type { MLASTAttr } from '@markuplint/ml-ast';
4
+ import type { RuleConfigValue } from '@markuplint/ml-config';
5
+ import { MLToken } from '../token/token';
6
+ import { MLDomTokenList } from './dom-token-list';
7
+ import { MLNode } from './node';
8
+ export declare class MLAttr<T extends RuleConfigValue, O = null> extends MLNode<T, O, MLASTAttr> implements Attr {
9
+ #private;
10
+ readonly candidate?: string;
11
+ readonly endQuote: MLToken | null;
12
+ readonly equal: MLToken | null;
13
+ readonly isDirective?: true;
14
+ readonly isDuplicatable: boolean;
15
+ readonly isDynamicValue?: true;
16
+ readonly nameNode: MLToken | null;
17
+ /**
18
+ * @implements DOM API: `Attr`
19
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-node-previoussibling%E2%91%A0
20
+ */
21
+ readonly ownerElement: MLElement<T, O>;
22
+ readonly spacesAfterEqual: MLToken | null;
23
+ readonly spacesBeforeEqual: MLToken | null;
24
+ readonly spacesBeforeName: MLToken | null;
25
+ readonly startQuote: MLToken | null;
26
+ readonly valueNode: MLToken | null;
27
+ /**
28
+ * Returns the "string" if HTML syntax. Otherwise, returns a type in its syntax.
29
+ *
30
+ * @default "string"
31
+ * @implements `@markuplint/ml-core` API: `MLAttr`
32
+ */
33
+ readonly valueType: 'string' | 'number' | 'boolean' | 'code';
34
+ /**
35
+ * **IT THROWS AN ERROR WHEN CALLING THIS.**
36
+ *
37
+ * @unsupported
38
+ * @implements DOM API: `Attr`
39
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-attr-localname
40
+ */
41
+ get localName(): string;
42
+ /**
43
+ *
44
+ * @implements DOM API: `Attr`
45
+ * @see https://dom.spec.whatwg.org/#dom-attr-name
46
+ */
47
+ get name(): string;
48
+ /**
49
+ * **IT THROWS AN ERROR WHEN CALLING THIS.**
50
+ *
51
+ * @unsupported
52
+ * @implements DOM API: `Attr`
53
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-attr-namespaceuri
54
+ */
55
+ get namespaceURI(): string | null;
56
+ /**
57
+ * Returns a string appropriate for the type of node as `Attr`
58
+ *
59
+ * @see https://dom.spec.whatwg.org/#ref-for-attr%E2%91%A4
60
+ */
61
+ get nodeName(): string;
62
+ /**
63
+ * Returns a number appropriate for the type of `Attr`
64
+ */
65
+ get nodeType(): AttributeNodeType;
66
+ get nodeValue(): string;
67
+ /**
68
+ * **IT THROWS AN ERROR WHEN CALLING THIS.**
69
+ *
70
+ * @unsupported
71
+ * @implements DOM API: `Attr`
72
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-attr-prefix
73
+ */
74
+ get prefix(): string | null;
75
+ /**
76
+ * @implements `@markuplint/ml-core` API: `MLAttr`
77
+ */
78
+ get rule(): import("@markuplint/ml-config").RuleInfo<T, O>;
79
+ /**
80
+ * @implements DOM API: `Attr`
81
+ * @see https://dom.spec.whatwg.org/#dom-attr-specified
82
+ */
83
+ get specified(): true;
84
+ /**
85
+ * @implements DOM API: `Attr`
86
+ * @see https://dom.spec.whatwg.org/#dom-attr-value
87
+ */
88
+ get value(): string;
89
+ /**
90
+ * @implements `@markuplint/ml-core` API: `MLAttr`
91
+ */
92
+ get tokenList(): MLDomTokenList | null;
93
+ constructor(astToken: MLASTAttr, ownElement: MLElement<T, O>);
94
+ /**
95
+ * @implements `@markuplint/ml-core` API: `MLAttr`
96
+ */
97
+ toNormalizeString(): string;
98
+ }
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ var _MLAttr_potentialName, _MLAttr_potentialValue;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.MLAttr = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const token_1 = require("../token/token");
7
+ const dom_token_list_1 = require("./dom-token-list");
8
+ const node_1 = require("./node");
9
+ const unexpected_call_error_1 = tslib_1.__importDefault(require("./unexpected-call-error"));
10
+ class MLAttr extends node_1.MLNode {
11
+ constructor(astToken, ownElement) {
12
+ var _a;
13
+ super(astToken, ownElement.ownerMLDocument);
14
+ _MLAttr_potentialName.set(this, void 0);
15
+ _MLAttr_potentialValue.set(this, void 0);
16
+ this.endQuote = null;
17
+ this.equal = null;
18
+ this.nameNode = null;
19
+ this.spacesAfterEqual = null;
20
+ this.spacesBeforeEqual = null;
21
+ this.spacesBeforeName = null;
22
+ this.startQuote = null;
23
+ this.valueNode = null;
24
+ /**
25
+ * Returns the "string" if HTML syntax. Otherwise, returns a type in its syntax.
26
+ *
27
+ * @default "string"
28
+ * @implements `@markuplint/ml-core` API: `MLAttr`
29
+ */
30
+ this.valueType = 'string';
31
+ if (this._astToken.type === 'html-attr') {
32
+ this.spacesBeforeName = new token_1.MLToken(this._astToken.spacesBeforeName);
33
+ this.nameNode = new token_1.MLToken(this._astToken.name);
34
+ this.spacesBeforeEqual = new token_1.MLToken(this._astToken.spacesBeforeEqual);
35
+ this.equal = new token_1.MLToken(this._astToken.equal);
36
+ this.spacesAfterEqual = new token_1.MLToken(this._astToken.spacesAfterEqual);
37
+ this.startQuote = new token_1.MLToken(this._astToken.startQuote);
38
+ this.valueNode = new token_1.MLToken(this._astToken.value);
39
+ this.endQuote = new token_1.MLToken(this._astToken.endQuote);
40
+ this.isDynamicValue = this._astToken.isDynamicValue;
41
+ this.isDirective = this._astToken.isDirective;
42
+ this.candidate = this._astToken.candidate;
43
+ tslib_1.__classPrivateFieldSet(this, _MLAttr_potentialName, this._astToken.potentialName || ((_a = this.nameNode) === null || _a === void 0 ? void 0 : _a.raw) || '', "f");
44
+ tslib_1.__classPrivateFieldSet(this, _MLAttr_potentialValue, this._astToken.value.raw || '', "f");
45
+ }
46
+ else {
47
+ this.valueType = this._astToken.valueType;
48
+ this.isDuplicatable = this._astToken.isDuplicatable;
49
+ tslib_1.__classPrivateFieldSet(this, _MLAttr_potentialName, this._astToken.potentialName, "f");
50
+ tslib_1.__classPrivateFieldSet(this, _MLAttr_potentialValue, this._astToken.potentialValue, "f");
51
+ }
52
+ this.ownerElement = ownElement;
53
+ this.isDuplicatable = this._astToken.isDuplicatable;
54
+ }
55
+ /**
56
+ * **IT THROWS AN ERROR WHEN CALLING THIS.**
57
+ *
58
+ * @unsupported
59
+ * @implements DOM API: `Attr`
60
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-attr-localname
61
+ */
62
+ get localName() {
63
+ throw new unexpected_call_error_1.default('Not supported "localname" property');
64
+ }
65
+ /**
66
+ *
67
+ * @implements DOM API: `Attr`
68
+ * @see https://dom.spec.whatwg.org/#dom-attr-name
69
+ */
70
+ get name() {
71
+ return tslib_1.__classPrivateFieldGet(this, _MLAttr_potentialName, "f");
72
+ }
73
+ /**
74
+ * **IT THROWS AN ERROR WHEN CALLING THIS.**
75
+ *
76
+ * @unsupported
77
+ * @implements DOM API: `Attr`
78
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-attr-namespaceuri
79
+ */
80
+ get namespaceURI() {
81
+ throw new unexpected_call_error_1.default('Not supported "namespaceURI" property');
82
+ }
83
+ /**
84
+ * Returns a string appropriate for the type of node as `Attr`
85
+ *
86
+ * @see https://dom.spec.whatwg.org/#ref-for-attr%E2%91%A4
87
+ */
88
+ get nodeName() {
89
+ return this.name;
90
+ }
91
+ /**
92
+ * Returns a number appropriate for the type of `Attr`
93
+ */
94
+ get nodeType() {
95
+ return this.ATTRIBUTE_NODE;
96
+ }
97
+ get nodeValue() {
98
+ return this.value;
99
+ }
100
+ /**
101
+ * **IT THROWS AN ERROR WHEN CALLING THIS.**
102
+ *
103
+ * @unsupported
104
+ * @implements DOM API: `Attr`
105
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-attr-prefix
106
+ */
107
+ get prefix() {
108
+ throw new unexpected_call_error_1.default('Not supported "prefix" property');
109
+ }
110
+ /**
111
+ * @implements `@markuplint/ml-core` API: `MLAttr`
112
+ */
113
+ get rule() {
114
+ return this.ownerElement.rule;
115
+ }
116
+ /**
117
+ * @implements DOM API: `Attr`
118
+ * @see https://dom.spec.whatwg.org/#dom-attr-specified
119
+ */
120
+ get specified() {
121
+ return true;
122
+ }
123
+ /**
124
+ * @implements DOM API: `Attr`
125
+ * @see https://dom.spec.whatwg.org/#dom-attr-value
126
+ */
127
+ get value() {
128
+ return tslib_1.__classPrivateFieldGet(this, _MLAttr_potentialValue, "f");
129
+ }
130
+ /**
131
+ * @implements `@markuplint/ml-core` API: `MLAttr`
132
+ */
133
+ get tokenList() {
134
+ return this.isDynamicValue ? null : new dom_token_list_1.MLDomTokenList(this.value, [this]);
135
+ }
136
+ /**
137
+ * @implements `@markuplint/ml-core` API: `MLAttr`
138
+ */
139
+ toNormalizeString() {
140
+ if (this.nameNode && this.equal && this.startQuote && this.valueNode && this.endQuote) {
141
+ return (this.nameNode.originRaw +
142
+ this.equal.originRaw +
143
+ this.startQuote.originRaw +
144
+ this.valueNode.originRaw +
145
+ this.endQuote.originRaw);
146
+ }
147
+ return this.raw;
148
+ }
149
+ }
150
+ exports.MLAttr = MLAttr;
151
+ _MLAttr_potentialName = new WeakMap(), _MLAttr_potentialValue = new WeakMap();