@markuplint/ml-core 2.2.3 → 2.3.2

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 (59) hide show
  1. package/lib/ml-core.d.ts +1 -1
  2. package/lib/ml-dom/helper/accname.js +1 -0
  3. package/lib/ml-dom/helper/selector.d.ts +1 -1
  4. package/lib/ml-dom/manipulations/child-node-methods.d.ts +33 -0
  5. package/lib/ml-dom/manipulations/child-node-methods.js +73 -0
  6. package/lib/ml-dom/manipulations/get-children.d.ts +4 -0
  7. package/lib/ml-dom/manipulations/get-children.js +10 -0
  8. package/lib/ml-dom/node/attr.d.ts +93 -0
  9. package/lib/ml-dom/node/attr.js +144 -0
  10. package/lib/ml-dom/node/block.d.ts +38 -0
  11. package/lib/ml-dom/node/block.js +53 -0
  12. package/lib/ml-dom/node/character-data.d.ts +57 -0
  13. package/lib/ml-dom/node/character-data.js +87 -0
  14. package/lib/ml-dom/node/child-node.d.ts +9 -0
  15. package/lib/ml-dom/node/child-node.js +10 -0
  16. package/lib/ml-dom/node/comment.d.ts +17 -0
  17. package/lib/ml-dom/node/comment.js +24 -0
  18. package/lib/ml-dom/node/document-fragment.d.ts +24 -0
  19. package/lib/ml-dom/node/document-fragment.js +33 -0
  20. package/lib/ml-dom/node/document-type.d.ts +38 -0
  21. package/lib/ml-dom/node/document-type.js +52 -0
  22. package/lib/ml-dom/node/document.d.ts +1554 -0
  23. package/lib/ml-dom/node/document.js +2117 -0
  24. package/lib/ml-dom/node/dom-token-list.d.ts +15 -0
  25. package/lib/ml-dom/node/dom-token-list.js +61 -0
  26. package/lib/ml-dom/node/element.d.ts +1832 -0
  27. package/lib/ml-dom/node/element.js +2483 -0
  28. package/lib/ml-dom/node/named-node-map.d.ts +42 -0
  29. package/lib/ml-dom/node/named-node-map.js +64 -0
  30. package/lib/ml-dom/node/node-list.d.ts +6 -0
  31. package/lib/ml-dom/node/node-list.js +39 -0
  32. package/lib/ml-dom/node/node-store.d.ts +14 -0
  33. package/lib/ml-dom/node/node-store.js +32 -0
  34. package/lib/ml-dom/node/node.d.ts +475 -0
  35. package/lib/ml-dom/node/node.js +672 -0
  36. package/lib/ml-dom/node/parent-node.d.ts +66 -0
  37. package/lib/ml-dom/node/parent-node.js +131 -0
  38. package/lib/ml-dom/node/rule-mapper.d.ts +17 -0
  39. package/lib/ml-dom/node/rule-mapper.js +49 -0
  40. package/lib/ml-dom/node/text.d.ts +51 -0
  41. package/lib/ml-dom/node/text.js +76 -0
  42. package/lib/ml-dom/node/types.d.ts +25 -0
  43. package/lib/ml-dom/node/types.js +2 -0
  44. package/lib/ml-dom/node/unexpected-call-error.d.ts +2 -0
  45. package/lib/ml-dom/node/unexpected-call-error.js +5 -0
  46. package/lib/ml-dom/token/token.d.ts +47 -0
  47. package/lib/ml-dom/token/token.js +89 -0
  48. package/lib/ml-dom/tokens/abstract-element.d.ts +1 -2
  49. package/lib/ml-dom/tokens/abstract-element.js +0 -4
  50. package/lib/ml-dom/tokens/node.d.ts +1 -0
  51. package/lib/ml-dom/tokens/node.js +8 -0
  52. package/lib/selector/is-pure-html-element.d.ts +1 -0
  53. package/lib/selector/is-pure-html-element.js +7 -0
  54. package/lib/selector/match-selector.d.ts +14 -0
  55. package/lib/selector/match-selector.js +230 -0
  56. package/lib/selector/selector.d.ts +9 -0
  57. package/lib/selector/selector.js +561 -0
  58. package/package.json +5 -5
  59. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,66 @@
1
+ import type { MLElement } from './element';
2
+ import type { MLASTAbstructNode } from '@markuplint/ml-ast';
3
+ import type { RuleConfigValue } from '@markuplint/ml-config';
4
+ import { MLNode } from './node';
5
+ /**
6
+ *
7
+ * @see https://dom.spec.whatwg.org/#interface-parentnode
8
+ */
9
+ export declare abstract class MLParentNode<T extends RuleConfigValue, O = null, A extends MLASTAbstructNode = MLASTAbstructNode> extends MLNode<T, O, A> implements ParentNode {
10
+ #private;
11
+ /**
12
+ * @implements DOM API: `Element`, `Document`, `DocumentFragment`
13
+ * @see https://dom.spec.whatwg.org/#dom-parentnode-childelementcount
14
+ */
15
+ get childElementCount(): number;
16
+ /**
17
+ * @implements DOM API: `Element`, `Document`, `DocumentFragment`
18
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-children%E2%91%A0
19
+ */
20
+ get children(): HTMLCollectionOf<MLElement<T, O>>;
21
+ /**
22
+ * @implements DOM API: `Element`, `Document`, `DocumentFragment`
23
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-firstelementchild%E2%91%A0
24
+ */
25
+ get firstElementChild(): MLElement<T, O>;
26
+ /**
27
+ * @implements DOM API: `Element`, `Document`, `DocumentFragment`
28
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-lastelementchild%E2%91%A0
29
+ */
30
+ get lastElementChild(): MLElement<T, O>;
31
+ /**
32
+ * **IT THROWS AN ERROR WHEN CALLING THIS.**
33
+ *
34
+ * @unsupported
35
+ * @implements DOM API: `Element`, `Document`, `DocumentFragment`
36
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-append%E2%91%A0
37
+ */
38
+ append(...nodes: (string | Node)[]): void;
39
+ /**
40
+ * **IT THROWS AN ERROR WHEN CALLING THIS.**
41
+ *
42
+ * @unsupported
43
+ * @implements DOM API: `Element`, `Document`, `DocumentFragment`
44
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-prepend%E2%91%A0
45
+ */
46
+ prepend(...nodes: (string | Node)[]): void;
47
+ /**
48
+ * @implements DOM API: `Element`, `Document`, `DocumentFragment`
49
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-queryselector%E2%91%A0
50
+ */
51
+ querySelector(selectors: string): MLElement<T, O> | null;
52
+ /**
53
+ * @implements DOM API: `Element`, `Document`, `DocumentFragment`
54
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-queryselectorall%E2%91%A0
55
+ */
56
+ querySelectorAll(selectors: string): NodeListOf<MLElement<T, O>>;
57
+ /**
58
+ * **IT THROWS AN ERROR WHEN CALLING THIS.**
59
+ *
60
+ * @unsupported
61
+ * @implements DOM API: `Element`, `Document`, `DocumentFragment`
62
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-replacechildren%E2%91%A0
63
+ */
64
+ replaceChildren(...nodes: (string | Node)[]): void;
65
+ protected _descendantsToArray<N extends MLNode<T, O>>(filter?: (node: MLNode<T, O>) => N | null | void): ReadonlyArray<N>;
66
+ }
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ var _MLParentNode_children, _MLParentNode_selectedElements;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.MLParentNode = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const walkers_1 = require("../helper/walkers");
7
+ const get_children_1 = require("../manipulations/get-children");
8
+ const node_1 = require("./node");
9
+ const node_list_1 = require("./node-list");
10
+ const unexpected_call_error_1 = tslib_1.__importDefault(require("./unexpected-call-error"));
11
+ /**
12
+ *
13
+ * @see https://dom.spec.whatwg.org/#interface-parentnode
14
+ */
15
+ class MLParentNode extends node_1.MLNode {
16
+ constructor() {
17
+ super(...arguments);
18
+ /**
19
+ * Cached `children`
20
+ */
21
+ _MLParentNode_children.set(this, null);
22
+ /**
23
+ * Cached elements that created from `querySelectorAll`
24
+ */
25
+ _MLParentNode_selectedElements.set(this, new Map());
26
+ }
27
+ /**
28
+ * @implements DOM API: `Element`, `Document`, `DocumentFragment`
29
+ * @see https://dom.spec.whatwg.org/#dom-parentnode-childelementcount
30
+ */
31
+ get childElementCount() {
32
+ return this.children.length;
33
+ }
34
+ /**
35
+ * @implements DOM API: `Element`, `Document`, `DocumentFragment`
36
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-children%E2%91%A0
37
+ */
38
+ get children() {
39
+ if (tslib_1.__classPrivateFieldGet(this, _MLParentNode_children, "f")) {
40
+ return tslib_1.__classPrivateFieldGet(this, _MLParentNode_children, "f");
41
+ }
42
+ const children = (0, get_children_1.getChildren)(this);
43
+ tslib_1.__classPrivateFieldSet(this, _MLParentNode_children, children, "f");
44
+ return tslib_1.__classPrivateFieldGet(this, _MLParentNode_children, "f");
45
+ }
46
+ /**
47
+ * @implements DOM API: `Element`, `Document`, `DocumentFragment`
48
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-firstelementchild%E2%91%A0
49
+ */
50
+ get firstElementChild() {
51
+ return this.children[0] || null;
52
+ }
53
+ /**
54
+ * @implements DOM API: `Element`, `Document`, `DocumentFragment`
55
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-lastelementchild%E2%91%A0
56
+ */
57
+ get lastElementChild() {
58
+ return this.children[0] || null;
59
+ }
60
+ /**
61
+ * **IT THROWS AN ERROR WHEN CALLING THIS.**
62
+ *
63
+ * @unsupported
64
+ * @implements DOM API: `Element`, `Document`, `DocumentFragment`
65
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-append%E2%91%A0
66
+ */
67
+ append(...nodes) {
68
+ throw new unexpected_call_error_1.default('Not supported "append" method');
69
+ }
70
+ /**
71
+ * **IT THROWS AN ERROR WHEN CALLING THIS.**
72
+ *
73
+ * @unsupported
74
+ * @implements DOM API: `Element`, `Document`, `DocumentFragment`
75
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-prepend%E2%91%A0
76
+ */
77
+ prepend(...nodes) {
78
+ throw new unexpected_call_error_1.default('Not supported "prepend" method');
79
+ }
80
+ /**
81
+ * @implements DOM API: `Element`, `Document`, `DocumentFragment`
82
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-queryselector%E2%91%A0
83
+ */
84
+ querySelector(selectors) {
85
+ const selected = this.querySelectorAll(selectors);
86
+ return selected[0] || null;
87
+ }
88
+ /**
89
+ * @implements DOM API: `Element`, `Document`, `DocumentFragment`
90
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-queryselectorall%E2%91%A0
91
+ */
92
+ querySelectorAll(selectors) {
93
+ const selected = tslib_1.__classPrivateFieldGet(this, _MLParentNode_selectedElements, "f").get(selectors);
94
+ if (selected) {
95
+ return selected;
96
+ }
97
+ const elements = (0, node_list_1.toNodeList)(this._descendantsToArray(node => {
98
+ if (node.is(node.ELEMENT_NODE) && node.matches(selectors)) {
99
+ return node;
100
+ }
101
+ }));
102
+ tslib_1.__classPrivateFieldGet(this, _MLParentNode_selectedElements, "f").set(selectors, elements);
103
+ return elements;
104
+ }
105
+ /**
106
+ * **IT THROWS AN ERROR WHEN CALLING THIS.**
107
+ *
108
+ * @unsupported
109
+ * @implements DOM API: `Element`, `Document`, `DocumentFragment`
110
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-replacechildren%E2%91%A0
111
+ */
112
+ replaceChildren(...nodes) {
113
+ throw new unexpected_call_error_1.default('Not supported "replaceChildren" method');
114
+ }
115
+ _descendantsToArray(filter) {
116
+ const nodeList = [];
117
+ (0, walkers_1.syncWalk)(Array.from(this.childNodes), node => {
118
+ if (filter) {
119
+ const filtered = filter(node);
120
+ if (filtered) {
121
+ nodeList.push(filtered);
122
+ }
123
+ return;
124
+ }
125
+ return node;
126
+ });
127
+ return Object.freeze(nodeList);
128
+ }
129
+ }
130
+ exports.MLParentNode = MLParentNode;
131
+ _MLParentNode_children = new WeakMap(), _MLParentNode_selectedElements = new WeakMap();
@@ -0,0 +1,17 @@
1
+ import type { MLDocument } from './document';
2
+ import type { MLNode } from './node';
3
+ import type { AnyRule } from '@markuplint/ml-config';
4
+ import type { Specificity } from '@markuplint/selector';
5
+ declare type RuleType = 'rules' | 'nodeRules' | 'childNodeRules';
6
+ declare type MappingLayer = {
7
+ from: RuleType;
8
+ specificity: Specificity;
9
+ rule: AnyRule;
10
+ };
11
+ export declare class RuleMapper {
12
+ #private;
13
+ constructor(document: MLDocument<any, any>);
14
+ apply(): void;
15
+ set(node: MLNode<any, any>, ruleName: string, rule: MappingLayer): void;
16
+ }
17
+ export {};
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var _RuleMapper_nodeList, _RuleMapper_ruleMap;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.RuleMapper = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const selector_1 = require("@markuplint/selector");
7
+ const debug_1 = require("../../debug");
8
+ const ruleMapperLog = debug_1.log.extend('rule-mapper');
9
+ const ruleMapperNodeLog = ruleMapperLog.extend('node');
10
+ const ruleMapperNodeRuleLog = ruleMapperNodeLog.extend('rule');
11
+ class RuleMapper {
12
+ constructor(document) {
13
+ _RuleMapper_nodeList.set(this, void 0);
14
+ _RuleMapper_ruleMap.set(this, new Map());
15
+ tslib_1.__classPrivateFieldSet(this, _RuleMapper_nodeList, Object.freeze([document, ...document.nodeList]), "f");
16
+ }
17
+ apply() {
18
+ ruleMapperLog('ruleTree:');
19
+ tslib_1.__classPrivateFieldGet(this, _RuleMapper_nodeList, "f").forEach(node => {
20
+ const rules = tslib_1.__classPrivateFieldGet(this, _RuleMapper_ruleMap, "f").get(node.uuid);
21
+ if (!rules) {
22
+ return;
23
+ }
24
+ ruleMapperNodeLog('<%s>', node.nodeName);
25
+ Object.keys(rules).forEach(ruleName => {
26
+ const rule = rules[ruleName];
27
+ node.rules[ruleName] = rule.rule;
28
+ ruleMapperNodeRuleLog('[from: %s(%s)] %s: %o', rule.from, rule.specificity, ruleName, rule.rule);
29
+ });
30
+ });
31
+ }
32
+ set(node, ruleName, rule) {
33
+ const rules = tslib_1.__classPrivateFieldGet(this, _RuleMapper_ruleMap, "f").get(node.uuid) || {};
34
+ const currentRule = rules[ruleName];
35
+ if (currentRule) {
36
+ const order = (0, selector_1.compareSpecificity)(currentRule.specificity, rule.specificity);
37
+ if (order === 1) {
38
+ ruleMapperLog("Don't set %o ([%s] vs [%s])", rule, currentRule.specificity, rule.specificity);
39
+ return;
40
+ }
41
+ ruleMapperLog('Unset %o from %s', currentRule, node);
42
+ }
43
+ rules[ruleName] = rule;
44
+ tslib_1.__classPrivateFieldGet(this, _RuleMapper_ruleMap, "f").set(node.uuid, rules);
45
+ ruleMapperLog('Set to %s from %s (%o): %O', node.nodeName, rule.from, rule.specificity, rule.rule);
46
+ }
47
+ }
48
+ exports.RuleMapper = RuleMapper;
49
+ _RuleMapper_nodeList = new WeakMap(), _RuleMapper_ruleMap = new WeakMap();
@@ -0,0 +1,51 @@
1
+ import type { TextNodeType } from './types';
2
+ import type { MLASTText } from '@markuplint/ml-ast';
3
+ import type { RuleConfigValue } from '@markuplint/ml-config';
4
+ import { MLCharacterData } from './character-data';
5
+ export declare class MLText<T extends RuleConfigValue, O = null> extends MLCharacterData<T, O, MLASTText> implements Text {
6
+ /**
7
+ * **IT THROWS AN ERROR WHEN CALLING THIS.**
8
+ *
9
+ * @unsupported
10
+ * @implements DOM API: `Text`
11
+ */
12
+ get assignedSlot(): HTMLSlotElement;
13
+ /**
14
+ * Returns a string appropriate for the type of node as `Text`
15
+ *
16
+ * @see https://dom.spec.whatwg.org/#ref-for-attr%E2%91%A4
17
+ */
18
+ get nodeName(): "#text";
19
+ /**
20
+ * Returns a number appropriate for the type of `Text`
21
+ */
22
+ get nodeType(): TextNodeType;
23
+ get textContent(): string | null;
24
+ /**
25
+ * **IT THROWS AN ERROR WHEN CALLING THIS.**
26
+ *
27
+ * @unsupported
28
+ * @implements DOM API: `Text`
29
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-text-splittext%E2%91%A0
30
+ */
31
+ get wholeText(): string;
32
+ /**
33
+ * Returns `true` if a parent element is `<script>` or `<style>`
34
+ *
35
+ * @implements `@markuplint/ml-core` API: `MLText`
36
+ * @see https://html.spec.whatwg.org/multipage/syntax.html#raw-text-elements
37
+ */
38
+ isRawTextElementContent(): boolean;
39
+ /**
40
+ * @implements `@markuplint/ml-core` API: `MLText`
41
+ */
42
+ isWhitespace(): boolean;
43
+ /**
44
+ * **IT THROWS AN ERROR WHEN CALLING THIS.**
45
+ *
46
+ * @unsupported
47
+ * @implements DOM API: `Text`
48
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-text-wholetext%E2%91%A0
49
+ */
50
+ splitText(offset: number): Text;
51
+ }
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MLText = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const character_data_1 = require("./character-data");
6
+ const unexpected_call_error_1 = tslib_1.__importDefault(require("./unexpected-call-error"));
7
+ /**
8
+ * Raw text elements
9
+ *
10
+ * @see https://html.spec.whatwg.org/multipage/syntax.html#raw-text-elements
11
+ */
12
+ const rawTextElements = ['script', 'style'];
13
+ class MLText extends character_data_1.MLCharacterData {
14
+ /**
15
+ * **IT THROWS AN ERROR WHEN CALLING THIS.**
16
+ *
17
+ * @unsupported
18
+ * @implements DOM API: `Text`
19
+ */
20
+ get assignedSlot() {
21
+ throw new unexpected_call_error_1.default('Not supported "assignedSlot" property');
22
+ }
23
+ /**
24
+ * Returns a string appropriate for the type of node as `Text`
25
+ *
26
+ * @see https://dom.spec.whatwg.org/#ref-for-attr%E2%91%A4
27
+ */
28
+ get nodeName() {
29
+ return '#text';
30
+ }
31
+ /**
32
+ * Returns a number appropriate for the type of `Text`
33
+ */
34
+ get nodeType() {
35
+ return this.TEXT_NODE;
36
+ }
37
+ get textContent() {
38
+ return this.nodeValue;
39
+ }
40
+ /**
41
+ * **IT THROWS AN ERROR WHEN CALLING THIS.**
42
+ *
43
+ * @unsupported
44
+ * @implements DOM API: `Text`
45
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-text-splittext%E2%91%A0
46
+ */
47
+ get wholeText() {
48
+ throw new unexpected_call_error_1.default('Not supported "wholeText" property');
49
+ }
50
+ /**
51
+ * Returns `true` if a parent element is `<script>` or `<style>`
52
+ *
53
+ * @implements `@markuplint/ml-core` API: `MLText`
54
+ * @see https://html.spec.whatwg.org/multipage/syntax.html#raw-text-elements
55
+ */
56
+ isRawTextElementContent() {
57
+ return this.parentElement ? rawTextElements.includes(this.parentElement.nodeName.toLowerCase()) : false;
58
+ }
59
+ /**
60
+ * @implements `@markuplint/ml-core` API: `MLText`
61
+ */
62
+ isWhitespace() {
63
+ return /^\s+$/.test(this.raw);
64
+ }
65
+ /**
66
+ * **IT THROWS AN ERROR WHEN CALLING THIS.**
67
+ *
68
+ * @unsupported
69
+ * @implements DOM API: `Text`
70
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-text-wholetext%E2%91%A0
71
+ */
72
+ splitText(offset) {
73
+ throw new unexpected_call_error_1.default('Not supported "splitText" method');
74
+ }
75
+ }
76
+ exports.MLText = MLText;
@@ -0,0 +1,25 @@
1
+ import type { MLToken } from '../token/token';
2
+ import type { MLAttr } from './attr';
3
+ import type { MLBlock } from './block';
4
+ import type { MLComment } from './comment';
5
+ import type { MLDocument } from './document';
6
+ import type { MLDocumentFragment } from './document-fragment';
7
+ import type { MLDocumentType } from './document-type';
8
+ import type { MLElement } from './element';
9
+ import type { MLNode } from './node';
10
+ import type { MLText } from './text';
11
+ import type { MLASTAbstructNode, MLASTAttr, MLASTComment, MLASTDoctype, MLASTElement, MLASTParentNode, MLASTPreprocessorSpecificBlock, MLASTText, MLToken as MLASTToken } from '@markuplint/ml-ast/';
12
+ import type { RuleConfigValue } from '@markuplint/ml-config';
13
+ export declare type MappedNode<N, T extends RuleConfigValue, O = null> = N extends MLASTElement ? MLElement<T, O> : N extends MLASTParentNode ? MLElement<T, O> : N extends MLASTComment ? MLComment<T, O> : N extends MLASTText ? MLText<T, O> : N extends MLASTDoctype ? MLDocumentType<T, O> : N extends MLASTPreprocessorSpecificBlock ? MLBlock<T, O> : N extends MLASTAbstructNode ? MLNode<T, O, MLASTAbstructNode> : N extends MLASTAttr ? MLAttr<T, O> : N extends MLASTToken ? MLToken : never;
14
+ export declare type NodeTypeOf<NT extends NodeType, T extends RuleConfigValue, O = null> = NT extends ElementNodeType ? MLElement<T, O> : NT extends CommentNodeType ? MLComment<T, O> : NT extends TextNodeType ? MLText<T, O> : NT extends DocumentNodeType ? MLDocument<T, O> : NT extends DocumentTypeNodeType ? MLDocumentType<T, O> : NT extends DocumentFragmentNodeType ? MLDocumentFragment<T, O> : NT extends MarkuplintPreprocessorBlockType ? MLBlock<T, O> : NT extends AttributeNodeType ? MLAttr<T, O> : never;
15
+ export declare type ElementNodeType = 1;
16
+ export declare type AttributeNodeType = 2;
17
+ export declare type TextNodeType = 3;
18
+ export declare type CDATASectionNodeType = 4;
19
+ export declare type ProcessingInstructionNodeType = 7;
20
+ export declare type CommentNodeType = 8;
21
+ export declare type DocumentNodeType = 9;
22
+ export declare type DocumentTypeNodeType = 10;
23
+ export declare type DocumentFragmentNodeType = 11;
24
+ export declare type MarkuplintPreprocessorBlockType = 101;
25
+ export declare type NodeType = ElementNodeType | AttributeNodeType | TextNodeType | CDATASectionNodeType | ProcessingInstructionNodeType | CommentNodeType | DocumentNodeType | DocumentTypeNodeType | DocumentFragmentNodeType | MarkuplintPreprocessorBlockType;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ export default class UnexpectedCallError extends Error {
2
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class UnexpectedCallError extends Error {
4
+ }
5
+ exports.default = UnexpectedCallError;
@@ -0,0 +1,47 @@
1
+ import type { MLToken as MLASTToken } from '@markuplint/ml-ast';
2
+ export declare class MLToken<A extends MLASTToken = MLASTToken> {
3
+ #private;
4
+ readonly uuid: string;
5
+ protected readonly _astToken: A;
6
+ /**
7
+ * @implements `@markuplint/ml-core` API: `MLDOMToken`
8
+ */
9
+ get endCol(): number;
10
+ /**
11
+ * @implements `@markuplint/ml-core` API: `MLDOMToken`
12
+ */
13
+ get endLine(): number;
14
+ /**
15
+ * @implements `@markuplint/ml-core` API: `MLDOMToken`
16
+ */
17
+ get endOffset(): number;
18
+ /**
19
+ * @implements `@markuplint/ml-core` API: `MLDOMToken`
20
+ */
21
+ get originRaw(): string;
22
+ /**
23
+ * @implements `@markuplint/ml-core` API: `MLDOMToken`
24
+ */
25
+ get raw(): string;
26
+ /**
27
+ * @implements `@markuplint/ml-core` API: `MLDOMToken`
28
+ */
29
+ get startCol(): number;
30
+ /**
31
+ * @implements `@markuplint/ml-core` API: `MLDOMToken`
32
+ */
33
+ get startLine(): number;
34
+ /**
35
+ * @implements `@markuplint/ml-core` API: `MLDOMToken`
36
+ */
37
+ get startOffset(): number;
38
+ constructor(astToken: A);
39
+ /**
40
+ * @implements `@markuplint/ml-core` API: `MLDOMToken`
41
+ */
42
+ fix(raw: string): void;
43
+ /**
44
+ * @implements `@markuplint/ml-core` API: `MLDOMToken`
45
+ */
46
+ toString(): string;
47
+ }
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var _MLToken_endCol, _MLToken_endLine, _MLToken_endOffset, _MLToken_fixed, _MLToken_raw, _MLToken_startCol, _MLToken_startLine, _MLToken_startOffset;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.MLToken = void 0;
5
+ const tslib_1 = require("tslib");
6
+ class MLToken {
7
+ constructor(astToken) {
8
+ _MLToken_endCol.set(this, void 0);
9
+ _MLToken_endLine.set(this, void 0);
10
+ _MLToken_endOffset.set(this, void 0);
11
+ _MLToken_fixed.set(this, void 0);
12
+ _MLToken_raw.set(this, void 0);
13
+ _MLToken_startCol.set(this, void 0);
14
+ _MLToken_startLine.set(this, void 0);
15
+ _MLToken_startOffset.set(this, void 0);
16
+ this._astToken = astToken;
17
+ tslib_1.__classPrivateFieldSet(this, _MLToken_raw, astToken.raw, "f");
18
+ tslib_1.__classPrivateFieldSet(this, _MLToken_fixed, astToken.raw, "f");
19
+ this.uuid = astToken.uuid;
20
+ tslib_1.__classPrivateFieldSet(this, _MLToken_startLine, astToken.startLine, "f");
21
+ tslib_1.__classPrivateFieldSet(this, _MLToken_endLine, astToken.endLine, "f");
22
+ tslib_1.__classPrivateFieldSet(this, _MLToken_startCol, astToken.startCol, "f");
23
+ tslib_1.__classPrivateFieldSet(this, _MLToken_endCol, astToken.endCol, "f");
24
+ tslib_1.__classPrivateFieldSet(this, _MLToken_startOffset, astToken.startOffset, "f");
25
+ tslib_1.__classPrivateFieldSet(this, _MLToken_endOffset, astToken.endOffset, "f");
26
+ }
27
+ /**
28
+ * @implements `@markuplint/ml-core` API: `MLDOMToken`
29
+ */
30
+ get endCol() {
31
+ return tslib_1.__classPrivateFieldGet(this, _MLToken_endCol, "f");
32
+ }
33
+ /**
34
+ * @implements `@markuplint/ml-core` API: `MLDOMToken`
35
+ */
36
+ get endLine() {
37
+ return tslib_1.__classPrivateFieldGet(this, _MLToken_endLine, "f");
38
+ }
39
+ /**
40
+ * @implements `@markuplint/ml-core` API: `MLDOMToken`
41
+ */
42
+ get endOffset() {
43
+ return tslib_1.__classPrivateFieldGet(this, _MLToken_endOffset, "f");
44
+ }
45
+ /**
46
+ * @implements `@markuplint/ml-core` API: `MLDOMToken`
47
+ */
48
+ get originRaw() {
49
+ return tslib_1.__classPrivateFieldGet(this, _MLToken_raw, "f");
50
+ }
51
+ /**
52
+ * @implements `@markuplint/ml-core` API: `MLDOMToken`
53
+ */
54
+ get raw() {
55
+ return tslib_1.__classPrivateFieldGet(this, _MLToken_fixed, "f");
56
+ }
57
+ /**
58
+ * @implements `@markuplint/ml-core` API: `MLDOMToken`
59
+ */
60
+ get startCol() {
61
+ return tslib_1.__classPrivateFieldGet(this, _MLToken_startCol, "f");
62
+ }
63
+ /**
64
+ * @implements `@markuplint/ml-core` API: `MLDOMToken`
65
+ */
66
+ get startLine() {
67
+ return tslib_1.__classPrivateFieldGet(this, _MLToken_startLine, "f");
68
+ }
69
+ /**
70
+ * @implements `@markuplint/ml-core` API: `MLDOMToken`
71
+ */
72
+ get startOffset() {
73
+ return tslib_1.__classPrivateFieldGet(this, _MLToken_startOffset, "f");
74
+ }
75
+ /**
76
+ * @implements `@markuplint/ml-core` API: `MLDOMToken`
77
+ */
78
+ fix(raw) {
79
+ tslib_1.__classPrivateFieldSet(this, _MLToken_fixed, raw, "f");
80
+ }
81
+ /**
82
+ * @implements `@markuplint/ml-core` API: `MLDOMToken`
83
+ */
84
+ toString() {
85
+ return this.raw;
86
+ }
87
+ }
88
+ exports.MLToken = MLToken;
89
+ _MLToken_endCol = new WeakMap(), _MLToken_endLine = new WeakMap(), _MLToken_endOffset = new WeakMap(), _MLToken_fixed = new WeakMap(), _MLToken_raw = new WeakMap(), _MLToken_startCol = new WeakMap(), _MLToken_startLine = new WeakMap(), _MLToken_startOffset = new WeakMap();
@@ -1,4 +1,4 @@
1
- import type { AnonymousNode, Document } from '../';
1
+ import type { Document } from '../';
2
2
  import type { MLDOMAttribute, MLDOMElement, MLDOMOmittedElement, MLDOMText } from './';
3
3
  import type MLDOMPreprocessorSpecificAttribute from './preprocessor-specific-attribute';
4
4
  import type { MLASTElement, MLASTOmittedElement } from '@markuplint/ml-ast';
@@ -20,7 +20,6 @@ export default abstract class MLDOMAbstractElement<T extends RuleConfigValue, O
20
20
  readonly isInFragmentDocument: boolean;
21
21
  constructor(astNode: E, document: Document<T, O>);
22
22
  get tagName(): string;
23
- get childNodes(): AnonymousNode<T, O>[];
24
23
  get children(): (MLDOMElement<T, O> | MLDOMOmittedElement<T, O>)[];
25
24
  get nextElementSibling(): MLDOMElement<T, O> | MLDOMOmittedElement<T, O> | null;
26
25
  get previousElementSibling(): MLDOMElement<T, O> | MLDOMOmittedElement<T, O> | null;
@@ -29,10 +29,6 @@ class MLDOMAbstractElement extends node_1.default {
29
29
  get tagName() {
30
30
  return this.nodeName;
31
31
  }
32
- get childNodes() {
33
- const astChildren = this._astToken.childNodes || [];
34
- return astChildren.map(node => this.nodeStore.getNode(node));
35
- }
36
32
  get children() {
37
33
  return this.childNodes.filter((node) => {
38
34
  return node.type === 'Element' || node.type === 'OmittedElement';
@@ -24,6 +24,7 @@ export default abstract class MLDOMNode<T extends RuleConfigValue, O = null, A e
24
24
  readonly rules: Record<string, AnyRule>;
25
25
  protected _astToken: A;
26
26
  constructor(astNode: A, document: Document<T, O>);
27
+ get childNodes(): AnonymousNode<T, O>[];
27
28
  get parentNode(): MLDOMElement<T, O> | MLDOMOmittedElement<T, O> | MLDOMPreprocessorSpecificBlock<T, O> | null;
28
29
  get prevNode(): AnonymousNode<T, O> | null;
29
30
  get nextNode(): AnonymousNode<T, O> | null;
@@ -29,6 +29,14 @@ class MLDOMNode extends token_1.default {
29
29
  this.ownerDocument = document;
30
30
  this.ownerDocument.nodeStore.setNode(astNode, this);
31
31
  }
32
+ get childNodes() {
33
+ if (this._astToken.type === 'starttag' || this._astToken.type === 'omittedtag') {
34
+ // @ts-ignore
35
+ const astChildren = this._astToken.childNodes || [];
36
+ return astChildren.map(node => this.nodeStore.getNode(node));
37
+ }
38
+ return [];
39
+ }
32
40
  get parentNode() {
33
41
  if (!this._astToken.parentNode) {
34
42
  return null;
@@ -0,0 +1 @@
1
+ export declare function isPureHTMLElement(el: Element): boolean;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isPureHTMLElement = void 0;
4
+ function isPureHTMLElement(el) {
5
+ return el.localName !== el.nodeName;
6
+ }
7
+ exports.isPureHTMLElement = isPureHTMLElement;
@@ -0,0 +1,14 @@
1
+ import type { Specificity } from './selector';
2
+ import type { RegexSelector } from '@markuplint/ml-config';
3
+ export declare type SelectorMatches = SelectorMatched | SelectorUnmatched;
4
+ declare type SelectorMatched = {
5
+ matched: true;
6
+ selector: string;
7
+ specificity: Specificity;
8
+ data?: Record<string, string>;
9
+ };
10
+ declare type SelectorUnmatched = {
11
+ matched: false;
12
+ };
13
+ export declare function matchSelector(el: Element, selector: string | RegexSelector | undefined): SelectorMatches;
14
+ export {};