@markuplint/ml-core 4.13.2 → 4.18.0
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/ARCHITECTURE.ja.md +467 -0
- package/ARCHITECTURE.md +467 -0
- package/CHANGELOG.md +14 -2
- package/README.md +5 -0
- package/SKILL.md +61 -0
- package/docs/linting-pipeline.ja.md +303 -0
- package/docs/linting-pipeline.md +303 -0
- package/docs/maintenance.ja.md +210 -0
- package/docs/maintenance.md +210 -0
- package/docs/ml-dom/attr.ja.md +95 -0
- package/docs/ml-dom/attr.md +95 -0
- package/docs/ml-dom/block.ja.md +272 -0
- package/docs/ml-dom/block.md +272 -0
- package/docs/ml-dom/document.ja.md +141 -0
- package/docs/ml-dom/document.md +141 -0
- package/docs/ml-dom/element.ja.md +176 -0
- package/docs/ml-dom/element.md +176 -0
- package/docs/ml-dom/helpers.ja.md +203 -0
- package/docs/ml-dom/helpers.md +203 -0
- package/docs/ml-dom/node.ja.md +200 -0
- package/docs/ml-dom/node.md +200 -0
- package/docs/ml-dom/others.ja.md +119 -0
- package/docs/ml-dom/others.md +119 -0
- package/docs/ml-dom/overview.ja.md +102 -0
- package/docs/ml-dom/overview.md +102 -0
- package/docs/ml-dom/pretender.ja.md +269 -0
- package/docs/ml-dom/pretender.md +269 -0
- package/docs/ml-dom/rule-mapping.ja.md +371 -0
- package/docs/ml-dom/rule-mapping.md +371 -0
- package/docs/ml-dom.ja.md +18 -0
- package/docs/ml-dom.md +18 -0
- package/docs/rule-system.ja.md +270 -0
- package/docs/rule-system.md +270 -0
- package/lib/convert-ruleset.d.ts +7 -0
- package/lib/convert-ruleset.js +7 -0
- package/lib/debug.d.ts +4 -0
- package/lib/debug.js +4 -0
- package/lib/ml-core.d.ts +36 -0
- package/lib/ml-core.js +29 -0
- package/lib/ml-dom/helper/get-indent.d.ts +4 -1
- package/lib/ml-dom/helper/get-indent.js +4 -1
- package/lib/ml-dom/node/attr.d.ts +65 -4
- package/lib/ml-dom/node/attr.js +53 -4
- package/lib/ml-dom/node/block.d.ts +21 -0
- package/lib/ml-dom/node/block.js +14 -0
- package/lib/ml-dom/node/child-node.d.ts +9 -0
- package/lib/ml-dom/node/child-node.js +9 -0
- package/lib/ml-dom/node/comment.d.ts +7 -0
- package/lib/ml-dom/node/comment.js +7 -0
- package/lib/ml-dom/node/document-fragment.d.ts +8 -0
- package/lib/ml-dom/node/document-fragment.js +8 -0
- package/lib/ml-dom/node/document-type.d.ts +22 -0
- package/lib/ml-dom/node/document-type.js +13 -0
- package/lib/ml-dom/node/document.d.ts +98 -4
- package/lib/ml-dom/node/document.js +87 -2
- package/lib/ml-dom/node/element.d.ts +164 -11
- package/lib/ml-dom/node/element.js +135 -6
- package/lib/ml-dom/node/node.d.ts +23 -0
- package/lib/ml-dom/node/node.js +29 -0
- package/lib/ml-dom/node/text.d.ts +12 -0
- package/lib/ml-dom/node/text.js +12 -0
- package/lib/ml-dom/node/types.d.ts +68 -0
- package/lib/ml-dom/token/token.d.ts +42 -0
- package/lib/ml-dom/token/token.js +36 -0
- package/lib/ml-rule/create-rule.d.ts +9 -0
- package/lib/ml-rule/create-rule.js +9 -0
- package/lib/ml-rule/ml-rule.d.ts +33 -0
- package/lib/ml-rule/ml-rule.js +30 -0
- package/lib/ml-rule/types.d.ts +41 -0
- package/lib/plugin/plugin.d.ts +8 -0
- package/lib/plugin/plugin.js +8 -0
- package/lib/plugin/types.d.ts +21 -0
- package/lib/ruleset/index.d.ts +10 -0
- package/lib/ruleset/index.js +7 -0
- package/lib/test/index.d.ts +42 -1
- package/lib/test/index.js +35 -1
- package/lib/types.d.ts +8 -0
- package/lib/violation-collector.d.ts +33 -0
- package/lib/violation-collector.js +33 -0
- package/package.json +14 -14
|
@@ -24,7 +24,22 @@ import { toHTMLCollection } from './node-list.js';
|
|
|
24
24
|
import { MLParentNode } from './parent-node.js';
|
|
25
25
|
import { UnexpectedCallError } from './unexpected-call-error.js';
|
|
26
26
|
const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
|
|
27
|
+
/**
|
|
28
|
+
* Represents a DOM Element node wrapper in the markuplint DOM tree.
|
|
29
|
+
* Provides access to element attributes, tag names, namespace, ARIA properties,
|
|
30
|
+
* accessibility information, pretender context, and CSS selector matching.
|
|
31
|
+
* This is the primary class used for linting HTML elements.
|
|
32
|
+
*
|
|
33
|
+
* @template T - The rule configuration value type
|
|
34
|
+
* @template O - The rule options type
|
|
35
|
+
*/
|
|
27
36
|
export class MLElement extends MLParentNode {
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new MLElement instance from an AST element node.
|
|
39
|
+
*
|
|
40
|
+
* @param astNode - The AST element node to wrap
|
|
41
|
+
* @param document - The owning document
|
|
42
|
+
*/
|
|
28
43
|
constructor(astNode,
|
|
29
44
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
30
45
|
document) {
|
|
@@ -35,6 +50,10 @@ export class MLElement extends MLParentNode {
|
|
|
35
50
|
_MLElement_localName.set(this, void 0);
|
|
36
51
|
_MLElement_normalizedAttrs.set(this, new Map());
|
|
37
52
|
_MLElement_normalizedString.set(this, null);
|
|
53
|
+
/**
|
|
54
|
+
* The pretender context if this element is participating in pretender behavior,
|
|
55
|
+
* or null if it is not a pretender or pretended element.
|
|
56
|
+
*/
|
|
38
57
|
this.pretenderContext = null;
|
|
39
58
|
__classPrivateFieldSet(this, _MLElement_attributes, astNode.attributes.map(attr => new MLAttr(attr, this)), "f");
|
|
40
59
|
this.selfClosingSolidus = astNode.selfClosingSolidus ? new MLToken(astNode.selfClosingSolidus) : null;
|
|
@@ -589,6 +608,12 @@ export class MLElement extends MLParentNode {
|
|
|
589
608
|
get assignedSlot() {
|
|
590
609
|
throw new UnexpectedCallError('Not supported "assignedSlot" property');
|
|
591
610
|
}
|
|
611
|
+
/**
|
|
612
|
+
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
613
|
+
*
|
|
614
|
+
* @unsupported
|
|
615
|
+
* @implements DOM API: `Element`
|
|
616
|
+
*/
|
|
592
617
|
get attributeStyleMap() {
|
|
593
618
|
throw new UnexpectedCallError('Not supported "attributeStyleMap" property');
|
|
594
619
|
}
|
|
@@ -724,6 +749,16 @@ export class MLElement extends MLParentNode {
|
|
|
724
749
|
get currentCSSZoom() {
|
|
725
750
|
throw new UnexpectedCallError('Not supported "currentCSSZoom" property');
|
|
726
751
|
}
|
|
752
|
+
/**
|
|
753
|
+
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
754
|
+
*
|
|
755
|
+
* @deprecated
|
|
756
|
+
* @unsupported
|
|
757
|
+
* @implements DOM API: `Element`
|
|
758
|
+
*/
|
|
759
|
+
get customElementRegistry() {
|
|
760
|
+
throw new UnexpectedCallError('Not supported "customElementRegistry" property');
|
|
761
|
+
}
|
|
727
762
|
/**
|
|
728
763
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
729
764
|
*
|
|
@@ -765,11 +800,17 @@ export class MLElement extends MLParentNode {
|
|
|
765
800
|
throw new UnexpectedCallError('Not supported "enterKeyHint" property');
|
|
766
801
|
}
|
|
767
802
|
/**
|
|
803
|
+
* Returns the fixed (potentially corrected) node name, which may differ from the
|
|
804
|
+
* original node name after lint fixes such as case normalization.
|
|
805
|
+
*
|
|
768
806
|
* @implements `@markuplint/ml-core` API: `MLElement`
|
|
769
807
|
*/
|
|
770
808
|
get fixedNodeName() {
|
|
771
809
|
return __classPrivateFieldGet(this, _MLElement_fixedNodeName, "f");
|
|
772
810
|
}
|
|
811
|
+
/**
|
|
812
|
+
* Whether this element has any spread attributes (e.g., `{...props}` in JSX).
|
|
813
|
+
*/
|
|
773
814
|
get hasSpreadAttr() {
|
|
774
815
|
return __classPrivateFieldGet(this, _MLElement_attributes, "f").some(attr => attr.localName === '#spread');
|
|
775
816
|
}
|
|
@@ -1128,6 +1169,16 @@ export class MLElement extends MLParentNode {
|
|
|
1128
1169
|
get onclose() {
|
|
1129
1170
|
throw new UnexpectedCallError('Not supported "onclose" property');
|
|
1130
1171
|
}
|
|
1172
|
+
/**
|
|
1173
|
+
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
1174
|
+
*
|
|
1175
|
+
* @deprecated
|
|
1176
|
+
* @unsupported
|
|
1177
|
+
* @implements DOM API: `Element`
|
|
1178
|
+
*/
|
|
1179
|
+
get oncommand() {
|
|
1180
|
+
throw new UnexpectedCallError('Not supported "oncommand" property');
|
|
1181
|
+
}
|
|
1131
1182
|
/**
|
|
1132
1183
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
1133
1184
|
*
|
|
@@ -2000,6 +2051,9 @@ export class MLElement extends MLParentNode {
|
|
|
2000
2051
|
return previousElementSibling(this);
|
|
2001
2052
|
}
|
|
2002
2053
|
/**
|
|
2054
|
+
* Returns the original raw element name exactly as it appears in the AST,
|
|
2055
|
+
* without any case normalization or pretender resolution.
|
|
2056
|
+
*
|
|
2003
2057
|
* @implements `@markuplint/ml-core` API: `MLElement`
|
|
2004
2058
|
*/
|
|
2005
2059
|
get rawName() {
|
|
@@ -2016,6 +2070,9 @@ export class MLElement extends MLParentNode {
|
|
|
2016
2070
|
throw new UnexpectedCallError('Not supported "role" property');
|
|
2017
2071
|
}
|
|
2018
2072
|
/**
|
|
2073
|
+
* Returns the rule configuration for this element, respecting the pretender context.
|
|
2074
|
+
* If the element is a pretended origin, returns the rule from the pretending element.
|
|
2075
|
+
*
|
|
2019
2076
|
* @implements `@markuplint/ml-core` API: `MLNode`
|
|
2020
2077
|
*/
|
|
2021
2078
|
get rule() {
|
|
@@ -2287,6 +2344,12 @@ export class MLElement extends MLParentNode {
|
|
|
2287
2344
|
computedStyleMap() {
|
|
2288
2345
|
throw new UnexpectedCallError('Not supported "computedStyleMap" method');
|
|
2289
2346
|
}
|
|
2347
|
+
/**
|
|
2348
|
+
* Overrides the fixed node name for this element, used when the element's
|
|
2349
|
+
* tag name needs to be corrected during linting (e.g., case normalization).
|
|
2350
|
+
*
|
|
2351
|
+
* @param name - The new node name to set
|
|
2352
|
+
*/
|
|
2290
2353
|
fixNodeName(name) {
|
|
2291
2354
|
__classPrivateFieldSet(this, _MLElement_fixedNodeName, name, "f");
|
|
2292
2355
|
}
|
|
@@ -2303,7 +2366,12 @@ export class MLElement extends MLParentNode {
|
|
|
2303
2366
|
throw new UnexpectedCallError('Not supported "focus" method');
|
|
2304
2367
|
}
|
|
2305
2368
|
/**
|
|
2369
|
+
* Computes the accessible name of this element according to the
|
|
2370
|
+
* Accessible Name and Description Computation algorithm.
|
|
2371
|
+
*
|
|
2306
2372
|
* @implements `@markuplint/ml-core` API: `MLElement`
|
|
2373
|
+
* @param version - The ARIA specification version to use for computation
|
|
2374
|
+
* @returns The computed accessible name string
|
|
2307
2375
|
*/
|
|
2308
2376
|
getAccessibleName(version) {
|
|
2309
2377
|
return getAccname(this, version);
|
|
@@ -2367,7 +2435,12 @@ export class MLElement extends MLParentNode {
|
|
|
2367
2435
|
throw new UnexpectedCallError('Not supported "getAttributeNodeNS" method');
|
|
2368
2436
|
}
|
|
2369
2437
|
/**
|
|
2438
|
+
* Gets the attribute value from the original (non-pretended) attributes list,
|
|
2439
|
+
* bypassing any pretender context that might be active.
|
|
2440
|
+
*
|
|
2370
2441
|
* @implements `@markuplint/ml-core` API: `MLElement`
|
|
2442
|
+
* @param attrName - The attribute name to look up (case-insensitive)
|
|
2443
|
+
* @returns The attribute value, or null if the attribute is not found
|
|
2371
2444
|
*/
|
|
2372
2445
|
getAttributePretended(attrName) {
|
|
2373
2446
|
for (const attr of __classPrivateFieldGet(this, _MLElement_attributes, "f")) {
|
|
@@ -2378,7 +2451,12 @@ export class MLElement extends MLParentNode {
|
|
|
2378
2451
|
return null;
|
|
2379
2452
|
}
|
|
2380
2453
|
/**
|
|
2454
|
+
* Returns all attribute tokens matching the given name, including duplicates.
|
|
2455
|
+
* Unlike `getAttribute`, this returns the full `MLAttr` token objects.
|
|
2456
|
+
*
|
|
2381
2457
|
* @implements `@markuplint/ml-core` API: `MLElement`
|
|
2458
|
+
* @param attrName - The attribute name to look up (case-insensitive)
|
|
2459
|
+
* @returns An array of matching attribute tokens
|
|
2382
2460
|
*/
|
|
2383
2461
|
getAttributeToken(attrName) {
|
|
2384
2462
|
const attrs = [];
|
|
@@ -2391,7 +2469,11 @@ export class MLElement extends MLParentNode {
|
|
|
2391
2469
|
return attrs;
|
|
2392
2470
|
}
|
|
2393
2471
|
/**
|
|
2472
|
+
* Returns all attribute tokens for this element, respecting the pretender context.
|
|
2473
|
+
* If the element is pretending to be another, returns the pretender's attributes.
|
|
2474
|
+
*
|
|
2394
2475
|
* @implements `@markuplint/ml-core` API: `MLElement`
|
|
2476
|
+
* @returns A frozen array of all attribute tokens
|
|
2395
2477
|
*/
|
|
2396
2478
|
getAttributeTokens() {
|
|
2397
2479
|
return Object.freeze(this.pretenderContext?.type === 'pretender' ? __classPrivateFieldGet(this.pretenderContext.as, _MLElement_attributes, "f") : __classPrivateFieldGet(this, _MLElement_attributes, "f"));
|
|
@@ -2406,6 +2488,13 @@ export class MLElement extends MLParentNode {
|
|
|
2406
2488
|
getBoundingClientRect() {
|
|
2407
2489
|
throw new UnexpectedCallError('Not supported "getBoundingClientRect" method');
|
|
2408
2490
|
}
|
|
2491
|
+
/**
|
|
2492
|
+
* Returns child elements and non-whitespace text nodes, skipping omitted elements
|
|
2493
|
+
* by flattening their children into the result. Results are cached for performance.
|
|
2494
|
+
*
|
|
2495
|
+
* @implements `@markuplint/ml-core` API: `MLElement`
|
|
2496
|
+
* @returns An array of child elements and non-whitespace text nodes
|
|
2497
|
+
*/
|
|
2409
2498
|
getChildElementsAndTextNodeWithoutWhitespaces() {
|
|
2410
2499
|
if (__classPrivateFieldGet(this, _MLElement_getChildElementsAndTextNodeWithoutWhitespacesCache, "f")) {
|
|
2411
2500
|
return __classPrivateFieldGet(this, _MLElement_getChildElementsAndTextNodeWithoutWhitespacesCache, "f");
|
|
@@ -2481,7 +2570,10 @@ export class MLElement extends MLParentNode {
|
|
|
2481
2570
|
throw new UnexpectedCallError('Does not implement "getHTML" method yet');
|
|
2482
2571
|
}
|
|
2483
2572
|
/**
|
|
2573
|
+
* Returns the source location of the element's tag name (excluding the opening `<` character).
|
|
2574
|
+
*
|
|
2484
2575
|
* @implements `@markuplint/ml-core` API: `MLElement`
|
|
2576
|
+
* @returns An object with `offset`, `line`, and `col` properties indicating where the name starts
|
|
2485
2577
|
*/
|
|
2486
2578
|
getNameLocation() {
|
|
2487
2579
|
return {
|
|
@@ -2515,7 +2607,11 @@ export class MLElement extends MLParentNode {
|
|
|
2515
2607
|
return this.attributes.length > 0;
|
|
2516
2608
|
}
|
|
2517
2609
|
/**
|
|
2610
|
+
* Checks whether this element has any mutable attributes, such as spread
|
|
2611
|
+
* attributes or attributes with dynamic values from template expressions.
|
|
2612
|
+
*
|
|
2518
2613
|
* @implements `@markuplint/ml-core` API: `MLElement`
|
|
2614
|
+
* @returns True if any attribute is dynamic or lacks a name node (spread)
|
|
2519
2615
|
*/
|
|
2520
2616
|
hasMutableAttributes() {
|
|
2521
2617
|
for (const attr of this.attributes) {
|
|
@@ -2529,9 +2625,13 @@ export class MLElement extends MLParentNode {
|
|
|
2529
2625
|
return false;
|
|
2530
2626
|
}
|
|
2531
2627
|
/**
|
|
2532
|
-
*
|
|
2628
|
+
* Checks whether this element has children that are potentially mutable,
|
|
2629
|
+
* such as preprocessor-specific blocks, slot elements, or (optionally) elements
|
|
2630
|
+
* with dynamic attributes.
|
|
2533
2631
|
*
|
|
2534
2632
|
* @implements `@markuplint/ml-core` API: `MLElement`
|
|
2633
|
+
* @param attr - When true, also considers children with mutable attributes as mutable
|
|
2634
|
+
* @returns True if this element has potentially mutable children
|
|
2535
2635
|
*/
|
|
2536
2636
|
hasMutableChildren(attr = false) {
|
|
2537
2637
|
for (const child of this.getPureChildNodes()) {
|
|
@@ -2611,7 +2711,12 @@ export class MLElement extends MLParentNode {
|
|
|
2611
2711
|
throw new UnexpectedCallError('Does not implement "insertAdjacentText" method yet');
|
|
2612
2712
|
}
|
|
2613
2713
|
/**
|
|
2714
|
+
* Checks whether this element is a descendant of any element whose UUID
|
|
2715
|
+
* is in the given list, by walking up the parent element chain.
|
|
2716
|
+
*
|
|
2614
2717
|
* @implements `@markuplint/ml-core` API: `MLElement`
|
|
2718
|
+
* @param uuidList - A list of element UUIDs to check against
|
|
2719
|
+
* @returns True if any ancestor element's UUID is in the list
|
|
2615
2720
|
*/
|
|
2616
2721
|
isDescendantByUUIDList(uuidList) {
|
|
2617
2722
|
let el = this.parentElement;
|
|
@@ -2627,7 +2732,11 @@ export class MLElement extends MLParentNode {
|
|
|
2627
2732
|
return false;
|
|
2628
2733
|
}
|
|
2629
2734
|
/**
|
|
2735
|
+
* Checks whether this element has no meaningful child content
|
|
2736
|
+
* (only whitespace-only text nodes or no children at all).
|
|
2737
|
+
*
|
|
2630
2738
|
* @implements `@markuplint/ml-core` API: `MLElement`
|
|
2739
|
+
* @returns True if the element has no non-whitespace child content
|
|
2631
2740
|
*/
|
|
2632
2741
|
isEmpty() {
|
|
2633
2742
|
for (const childNode of this.childNodes) {
|
|
@@ -2637,15 +2746,20 @@ export class MLElement extends MLParentNode {
|
|
|
2637
2746
|
}
|
|
2638
2747
|
return true;
|
|
2639
2748
|
}
|
|
2640
|
-
/**
|
|
2641
|
-
* @implements DOM API: `Element`
|
|
2642
|
-
* @see https://dom.spec.whatwg.org/#ref-for-dom-element-matches%E2%91%A0
|
|
2643
|
-
*/
|
|
2644
2749
|
matches(selector,
|
|
2645
2750
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
2646
2751
|
scope) {
|
|
2647
2752
|
return this.matchMLSelector(selector, scope).matched;
|
|
2648
2753
|
}
|
|
2754
|
+
/**
|
|
2755
|
+
* Matches this element against a CSS selector or regex selector pattern,
|
|
2756
|
+
* returning detailed match results. When the element is a pretender,
|
|
2757
|
+
* it attempts to match both as the pretender and as the original element.
|
|
2758
|
+
*
|
|
2759
|
+
* @param selector - The CSS selector string or regex selector to match against
|
|
2760
|
+
* @param scope - An optional scope node for scoped selector matching
|
|
2761
|
+
* @returns The detailed match result including captured groups from regex selectors
|
|
2762
|
+
*/
|
|
2649
2763
|
matchMLSelector(selector,
|
|
2650
2764
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
2651
2765
|
scope) {
|
|
@@ -2669,7 +2783,11 @@ export class MLElement extends MLParentNode {
|
|
|
2669
2783
|
return matched;
|
|
2670
2784
|
}
|
|
2671
2785
|
/**
|
|
2672
|
-
*
|
|
2786
|
+
* Initializes the pretender context for this element based on the given pretender
|
|
2787
|
+
* configurations. If a matching pretender is found or the element has an `as` attribute,
|
|
2788
|
+
* sets up the pretender/pretended relationship between elements.
|
|
2789
|
+
*
|
|
2790
|
+
* @param pretenders - Optional array of pretender configurations to match against
|
|
2673
2791
|
*/
|
|
2674
2792
|
pretending(pretenders) {
|
|
2675
2793
|
const pretenderConfig = pretenders?.find(option => this.matches(option.selector));
|
|
@@ -2967,7 +3085,12 @@ export class MLElement extends MLParentNode {
|
|
|
2967
3085
|
throw new UnexpectedCallError('Not supported "showPopover" method');
|
|
2968
3086
|
}
|
|
2969
3087
|
/**
|
|
3088
|
+
* Returns a normalized string representation of this element including its tag name,
|
|
3089
|
+
* attributes, and child content. Whitespace-only text nodes are excluded.
|
|
3090
|
+
* The result is cached for repeated calls.
|
|
3091
|
+
*
|
|
2970
3092
|
* @implements `@markuplint/ml-core` API: `MLElement`
|
|
3093
|
+
* @returns The normalized HTML string of this element
|
|
2971
3094
|
*/
|
|
2972
3095
|
toNormalizeString() {
|
|
2973
3096
|
if (__classPrivateFieldGet(this, _MLElement_normalizedString, "f")) {
|
|
@@ -2989,7 +3112,13 @@ export class MLElement extends MLParentNode {
|
|
|
2989
3112
|
return normalizedString;
|
|
2990
3113
|
}
|
|
2991
3114
|
/**
|
|
3115
|
+
* Returns a string representation of this element. When `fixed` is true,
|
|
3116
|
+
* returns the element with any lint fixes applied to the tag name,
|
|
3117
|
+
* attributes, and embedded comment nodes.
|
|
3118
|
+
*
|
|
2992
3119
|
* @implements `@markuplint/ml-core` API: `MLElement`
|
|
3120
|
+
* @param fixed - When true, returns the fixed content; otherwise returns the original raw content
|
|
3121
|
+
* @returns The string content of this element
|
|
2993
3122
|
*/
|
|
2994
3123
|
toString(fixed = false) {
|
|
2995
3124
|
if (!fixed) {
|
|
@@ -8,6 +8,15 @@ import type { RuleInfo } from '../../index.js';
|
|
|
8
8
|
import type { MLASTNode } from '@markuplint/ml-ast';
|
|
9
9
|
import type { AnyRule, PlainData, RuleConfigValue } from '@markuplint/ml-config';
|
|
10
10
|
import { MLToken } from '../token/token.js';
|
|
11
|
+
/**
|
|
12
|
+
* Abstract base class for all markuplint DOM node wrappers.
|
|
13
|
+
* Extends `MLToken` with DOM `Node` interface compliance, tree traversal,
|
|
14
|
+
* rule configuration access, and child node management.
|
|
15
|
+
*
|
|
16
|
+
* @template T - The rule configuration value type
|
|
17
|
+
* @template O - The rule options type
|
|
18
|
+
* @template A - The underlying AST node type
|
|
19
|
+
*/
|
|
11
20
|
export declare abstract class MLNode<T extends RuleConfigValue, O extends PlainData = undefined, A extends MLASTNode = MLASTNode> extends MLToken<A> implements Node {
|
|
12
21
|
#private;
|
|
13
22
|
/**
|
|
@@ -201,6 +210,13 @@ export declare abstract class MLNode<T extends RuleConfigValue, O extends PlainD
|
|
|
201
210
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-node-ownerdocument%E2%91%A0
|
|
202
211
|
*/
|
|
203
212
|
get ownerDocument(): any;
|
|
213
|
+
/**
|
|
214
|
+
* The owning `MLDocument` instance with proper generic types,
|
|
215
|
+
* providing type-safe access to the document without the `any` type
|
|
216
|
+
* used by the DOM-compatible `ownerDocument`.
|
|
217
|
+
*
|
|
218
|
+
* @implements `@markuplint/ml-core` API: `MLNode`
|
|
219
|
+
*/
|
|
204
220
|
get ownerMLDocument(): MLDocument<T, O>;
|
|
205
221
|
/**
|
|
206
222
|
* The parent element.
|
|
@@ -423,6 +439,13 @@ export declare abstract class MLNode<T extends RuleConfigValue, O extends PlainD
|
|
|
423
439
|
* @see https://dom.spec.whatwg.org/#dom-node-insertbefore
|
|
424
440
|
*/
|
|
425
441
|
insertBefore<T extends Node>(node: T, child: Node | null): T;
|
|
442
|
+
/**
|
|
443
|
+
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
444
|
+
*
|
|
445
|
+
* @unsupported
|
|
446
|
+
* @implements DOM API: `Node`
|
|
447
|
+
*/
|
|
448
|
+
moveBefore(node: Node, child: Node | null): Node;
|
|
426
449
|
/**
|
|
427
450
|
* @implements `@markuplint/ml-core` API: `MLNode`
|
|
428
451
|
*/
|
package/lib/ml-dom/node/node.js
CHANGED
|
@@ -16,6 +16,15 @@ import { isChildNode } from './child-node.js';
|
|
|
16
16
|
import { toNodeList } from './node-list.js';
|
|
17
17
|
import { nodeStore } from './node-store.js';
|
|
18
18
|
import { UnexpectedCallError } from './unexpected-call-error.js';
|
|
19
|
+
/**
|
|
20
|
+
* Abstract base class for all markuplint DOM node wrappers.
|
|
21
|
+
* Extends `MLToken` with DOM `Node` interface compliance, tree traversal,
|
|
22
|
+
* rule configuration access, and child node management.
|
|
23
|
+
*
|
|
24
|
+
* @template T - The rule configuration value type
|
|
25
|
+
* @template O - The rule options type
|
|
26
|
+
* @template A - The underlying AST node type
|
|
27
|
+
*/
|
|
19
28
|
export class MLNode extends MLToken {
|
|
20
29
|
constructor(astNode,
|
|
21
30
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
@@ -271,6 +280,13 @@ export class MLNode extends MLToken {
|
|
|
271
280
|
get ownerDocument() {
|
|
272
281
|
return __classPrivateFieldGet(this, _MLNode_ownerDocument, "f");
|
|
273
282
|
}
|
|
283
|
+
/**
|
|
284
|
+
* The owning `MLDocument` instance with proper generic types,
|
|
285
|
+
* providing type-safe access to the document without the `any` type
|
|
286
|
+
* used by the DOM-compatible `ownerDocument`.
|
|
287
|
+
*
|
|
288
|
+
* @implements `@markuplint/ml-core` API: `MLNode`
|
|
289
|
+
*/
|
|
274
290
|
get ownerMLDocument() {
|
|
275
291
|
return __classPrivateFieldGet(this, _MLNode_ownerDocument, "f");
|
|
276
292
|
}
|
|
@@ -743,6 +759,19 @@ export class MLNode extends MLToken {
|
|
|
743
759
|
child) {
|
|
744
760
|
throw new UnexpectedCallError('Not supported "insertBefore" method');
|
|
745
761
|
}
|
|
762
|
+
/**
|
|
763
|
+
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
764
|
+
*
|
|
765
|
+
* @unsupported
|
|
766
|
+
* @implements DOM API: `Node`
|
|
767
|
+
*/
|
|
768
|
+
moveBefore(
|
|
769
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
770
|
+
node,
|
|
771
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
772
|
+
child) {
|
|
773
|
+
throw new UnexpectedCallError('Not supported "moveBefore" method');
|
|
774
|
+
}
|
|
746
775
|
/**
|
|
747
776
|
* @implements `@markuplint/ml-core` API: `MLNode`
|
|
748
777
|
*/
|
|
@@ -2,6 +2,14 @@ import type { TextNodeType } from './types.js';
|
|
|
2
2
|
import type { MLASTText } from '@markuplint/ml-ast';
|
|
3
3
|
import type { PlainData, RuleConfigValue } from '@markuplint/ml-config';
|
|
4
4
|
import { MLCharacterData } from './character-data.js';
|
|
5
|
+
/**
|
|
6
|
+
* Represents a DOM Text node wrapper in the markuplint DOM tree.
|
|
7
|
+
* Wraps an AST text token and provides text-specific operations such as
|
|
8
|
+
* detecting raw text element content and whitespace-only nodes.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The rule configuration value type
|
|
11
|
+
* @template O - The rule options type
|
|
12
|
+
*/
|
|
5
13
|
export declare class MLText<T extends RuleConfigValue, O extends PlainData = undefined> extends MLCharacterData<T, O, MLASTText> implements Text {
|
|
6
14
|
/**
|
|
7
15
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -33,10 +41,14 @@ export declare class MLText<T extends RuleConfigValue, O extends PlainData = und
|
|
|
33
41
|
*
|
|
34
42
|
* @implements `@markuplint/ml-core` API: `MLText`
|
|
35
43
|
* @see https://html.spec.whatwg.org/multipage/syntax.html#raw-text-elements
|
|
44
|
+
* @returns True if this text node is the content of a raw text element
|
|
36
45
|
*/
|
|
37
46
|
isRawTextElementContent(): boolean;
|
|
38
47
|
/**
|
|
48
|
+
* Checks whether this text node contains only whitespace characters.
|
|
49
|
+
*
|
|
39
50
|
* @implements `@markuplint/ml-core` API: `MLText`
|
|
51
|
+
* @returns True if the raw content is composed entirely of whitespace
|
|
40
52
|
*/
|
|
41
53
|
isWhitespace(): boolean;
|
|
42
54
|
/**
|
package/lib/ml-dom/node/text.js
CHANGED
|
@@ -6,6 +6,14 @@ import { UnexpectedCallError } from './unexpected-call-error.js';
|
|
|
6
6
|
* @see https://html.spec.whatwg.org/multipage/syntax.html#raw-text-elements
|
|
7
7
|
*/
|
|
8
8
|
const rawTextElements = new Set(['script', 'style']);
|
|
9
|
+
/**
|
|
10
|
+
* Represents a DOM Text node wrapper in the markuplint DOM tree.
|
|
11
|
+
* Wraps an AST text token and provides text-specific operations such as
|
|
12
|
+
* detecting raw text element content and whitespace-only nodes.
|
|
13
|
+
*
|
|
14
|
+
* @template T - The rule configuration value type
|
|
15
|
+
* @template O - The rule options type
|
|
16
|
+
*/
|
|
9
17
|
export class MLText extends MLCharacterData {
|
|
10
18
|
/**
|
|
11
19
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -45,12 +53,16 @@ export class MLText extends MLCharacterData {
|
|
|
45
53
|
*
|
|
46
54
|
* @implements `@markuplint/ml-core` API: `MLText`
|
|
47
55
|
* @see https://html.spec.whatwg.org/multipage/syntax.html#raw-text-elements
|
|
56
|
+
* @returns True if this text node is the content of a raw text element
|
|
48
57
|
*/
|
|
49
58
|
isRawTextElementContent() {
|
|
50
59
|
return this.parentElement ? rawTextElements.has(this.parentElement.nodeName.toLowerCase()) : false;
|
|
51
60
|
}
|
|
52
61
|
/**
|
|
62
|
+
* Checks whether this text node contains only whitespace characters.
|
|
63
|
+
*
|
|
53
64
|
* @implements `@markuplint/ml-core` API: `MLText`
|
|
65
|
+
* @returns True if the raw content is composed entirely of whitespace
|
|
54
66
|
*/
|
|
55
67
|
isWhitespace() {
|
|
56
68
|
return /^\s+$/.test(this.raw);
|
|
@@ -9,30 +9,91 @@ import type { MLText } from './text.js';
|
|
|
9
9
|
import type { MLToken } from '../token/token.js';
|
|
10
10
|
import type { MLASTAttr, MLASTComment, MLASTDoctype, MLASTElement, MLASTInvalid, MLASTParentNode, MLASTPreprocessorSpecificBlock, MLASTText, MLASTToken as MLASTToken } from '@markuplint/ml-ast/';
|
|
11
11
|
import type { PlainData, PretenderARIA, RuleConfigValue } from '@markuplint/ml-config';
|
|
12
|
+
/**
|
|
13
|
+
* Maps an AST node type to its corresponding markuplint DOM node wrapper type.
|
|
14
|
+
*
|
|
15
|
+
* @template N - The AST node type to map from
|
|
16
|
+
* @template T - The rule configuration value type
|
|
17
|
+
* @template O - The rule options type
|
|
18
|
+
*/
|
|
12
19
|
export type MappedNode<N, T extends RuleConfigValue, O extends PlainData = undefined> = 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 MLASTAttr ? MLAttr<T, O> : N extends MLASTInvalid ? MLText<T, O> : N extends MLASTToken ? MLToken : never;
|
|
20
|
+
/**
|
|
21
|
+
* Resolves a numeric node type constant to its corresponding markuplint DOM node class type.
|
|
22
|
+
* Used for type narrowing via the `is()` method on nodes.
|
|
23
|
+
*
|
|
24
|
+
* @template NT - The numeric node type constant
|
|
25
|
+
* @template T - The rule configuration value type
|
|
26
|
+
* @template O - The rule options type
|
|
27
|
+
*/
|
|
13
28
|
export type NodeTypeOf<NT extends NodeType, T extends RuleConfigValue, O extends PlainData = undefined> = 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;
|
|
29
|
+
/** Numeric constant representing an Element node (corresponds to DOM `Node.ELEMENT_NODE`). */
|
|
14
30
|
export type ElementNodeType = 1;
|
|
31
|
+
/** Numeric constant representing an Attribute node (corresponds to DOM `Node.ATTRIBUTE_NODE`). */
|
|
15
32
|
export type AttributeNodeType = 2;
|
|
33
|
+
/** Numeric constant representing a Text node (corresponds to DOM `Node.TEXT_NODE`). */
|
|
16
34
|
export type TextNodeType = 3;
|
|
35
|
+
/** Numeric constant representing a CDATA Section node (corresponds to DOM `Node.CDATA_SECTION_NODE`). */
|
|
17
36
|
export type CDATASectionNodeType = 4;
|
|
37
|
+
/** Numeric constant representing a Processing Instruction node (corresponds to DOM `Node.PROCESSING_INSTRUCTION_NODE`). */
|
|
18
38
|
export type ProcessingInstructionNodeType = 7;
|
|
39
|
+
/** Numeric constant representing a Comment node (corresponds to DOM `Node.COMMENT_NODE`). */
|
|
19
40
|
export type CommentNodeType = 8;
|
|
41
|
+
/** Numeric constant representing a Document node (corresponds to DOM `Node.DOCUMENT_NODE`). */
|
|
20
42
|
export type DocumentNodeType = 9;
|
|
43
|
+
/** Numeric constant representing a DocumentType node (corresponds to DOM `Node.DOCUMENT_TYPE_NODE`). */
|
|
21
44
|
export type DocumentTypeNodeType = 10;
|
|
45
|
+
/** Numeric constant representing a DocumentFragment node (corresponds to DOM `Node.DOCUMENT_FRAGMENT_NODE`). */
|
|
22
46
|
export type DocumentFragmentNodeType = 11;
|
|
47
|
+
/** Numeric constant representing a markuplint preprocessor block node, used for template engine constructs. */
|
|
23
48
|
export type MarkuplintPreprocessorBlockType = 101;
|
|
49
|
+
/**
|
|
50
|
+
* Union of all supported node type constants in the markuplint DOM,
|
|
51
|
+
* including standard DOM node types and the markuplint-specific preprocessor block type.
|
|
52
|
+
*/
|
|
24
53
|
export type NodeType = ElementNodeType | AttributeNodeType | TextNodeType | CDATASectionNodeType | ProcessingInstructionNodeType | CommentNodeType | DocumentNodeType | DocumentTypeNodeType | DocumentFragmentNodeType | MarkuplintPreprocessorBlockType;
|
|
54
|
+
/**
|
|
55
|
+
* Represents the pretender context for an element, which can be either
|
|
56
|
+
* a pretender (an element acting as another) or a pretended element (the original).
|
|
57
|
+
*
|
|
58
|
+
* @template N - The element type
|
|
59
|
+
* @template T - The rule configuration value type
|
|
60
|
+
* @template O - The rule options type
|
|
61
|
+
*/
|
|
25
62
|
export type PretenderContext<N extends MLElement<T, O>, T extends RuleConfigValue, O extends PlainData = undefined> = PretenderContextPretender<N, T, O> | PretenderContextPretended<N, T, O>;
|
|
63
|
+
/**
|
|
64
|
+
* Context for an element that is pretending to be another element.
|
|
65
|
+
* Contains the target element it is pretending to be and optional ARIA overrides.
|
|
66
|
+
*
|
|
67
|
+
* @template N - The element type
|
|
68
|
+
* @template T - The rule configuration value type
|
|
69
|
+
* @template O - The rule options type
|
|
70
|
+
*/
|
|
26
71
|
export type PretenderContextPretender<N extends MLElement<T, O>, T extends RuleConfigValue, O extends PlainData = undefined> = {
|
|
27
72
|
readonly type: 'pretender';
|
|
28
73
|
readonly as: N;
|
|
29
74
|
readonly aria?: PretenderARIA;
|
|
30
75
|
};
|
|
76
|
+
/**
|
|
77
|
+
* Context for the original element that has been pretended by another element.
|
|
78
|
+
* Contains a reference back to the pretending origin element.
|
|
79
|
+
*
|
|
80
|
+
* @template N - The element type
|
|
81
|
+
* @template T - The rule configuration value type
|
|
82
|
+
* @template O - The rule options type
|
|
83
|
+
*/
|
|
31
84
|
export type PretenderContextPretended<N extends MLElement<T, O>, T extends RuleConfigValue, O extends PlainData = undefined> = {
|
|
32
85
|
readonly type: 'origin';
|
|
33
86
|
readonly origin: N;
|
|
34
87
|
};
|
|
88
|
+
/**
|
|
89
|
+
* Represents the computed accessibility properties for a node,
|
|
90
|
+
* which may be clearly resolved or unknown.
|
|
91
|
+
*/
|
|
35
92
|
export type AccessibilityProperties = ClearlyAccessibilityProperties | UnknownAccessibilityProperties;
|
|
93
|
+
/**
|
|
94
|
+
* Resolved accessibility properties for a node, including its ARIA role,
|
|
95
|
+
* accessible name, focusability, and related ARIA property values.
|
|
96
|
+
*/
|
|
36
97
|
export type ClearlyAccessibilityProperties = {
|
|
37
98
|
unknown: false;
|
|
38
99
|
exposedToTree: boolean;
|
|
@@ -46,9 +107,16 @@ export type ClearlyAccessibilityProperties = {
|
|
|
46
107
|
focusable?: boolean;
|
|
47
108
|
props?: Record<string, AccessibilityProperty>;
|
|
48
109
|
};
|
|
110
|
+
/**
|
|
111
|
+
* Represents accessibility properties that could not be resolved,
|
|
112
|
+
* typically when the element or its role is not recognized.
|
|
113
|
+
*/
|
|
49
114
|
export type UnknownAccessibilityProperties = {
|
|
50
115
|
unknown: true;
|
|
51
116
|
};
|
|
117
|
+
/**
|
|
118
|
+
* A single ARIA property with its computed value and whether it is required for the role.
|
|
119
|
+
*/
|
|
52
120
|
export type AccessibilityProperty = {
|
|
53
121
|
value: string | null;
|
|
54
122
|
required: boolean;
|
|
@@ -1,47 +1,89 @@
|
|
|
1
1
|
import type { MLASTToken } from '@markuplint/ml-ast';
|
|
2
|
+
/**
|
|
3
|
+
* Represents a single token in the markuplint AST.
|
|
4
|
+
* Wraps an AST token with positional information (line, column, offset)
|
|
5
|
+
* and provides both raw and fixed string representations.
|
|
6
|
+
*
|
|
7
|
+
* @template A - The AST token type this token wraps
|
|
8
|
+
*/
|
|
2
9
|
export declare class MLToken<A extends MLASTToken = MLASTToken> {
|
|
3
10
|
#private;
|
|
11
|
+
/**
|
|
12
|
+
* The unique identifier for this token.
|
|
13
|
+
*/
|
|
4
14
|
readonly uuid: string;
|
|
15
|
+
/**
|
|
16
|
+
* The underlying AST token that this token wraps.
|
|
17
|
+
*/
|
|
5
18
|
protected readonly _astToken: A;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new MLToken instance from an AST token.
|
|
21
|
+
*
|
|
22
|
+
* @param astToken - The AST token to wrap
|
|
23
|
+
*/
|
|
6
24
|
constructor(astToken: A);
|
|
7
25
|
/**
|
|
26
|
+
* The ending column number (1-based) of this token in the source.
|
|
27
|
+
*
|
|
8
28
|
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
9
29
|
*/
|
|
10
30
|
get endCol(): number;
|
|
11
31
|
/**
|
|
32
|
+
* The ending line number (1-based) of this token in the source.
|
|
33
|
+
*
|
|
12
34
|
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
13
35
|
*/
|
|
14
36
|
get endLine(): number;
|
|
15
37
|
/**
|
|
38
|
+
* The ending character offset (0-based) of this token in the source.
|
|
39
|
+
*
|
|
16
40
|
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
17
41
|
*/
|
|
18
42
|
get endOffset(): number;
|
|
19
43
|
/**
|
|
44
|
+
* The fixed (potentially modified) string content of this token.
|
|
45
|
+
*
|
|
20
46
|
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
21
47
|
*/
|
|
22
48
|
get fixed(): string;
|
|
23
49
|
/**
|
|
50
|
+
* The original raw string content of this token from the source.
|
|
51
|
+
*
|
|
24
52
|
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
25
53
|
*/
|
|
26
54
|
get raw(): string;
|
|
27
55
|
/**
|
|
56
|
+
* The starting column number (1-based) of this token in the source.
|
|
57
|
+
*
|
|
28
58
|
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
29
59
|
*/
|
|
30
60
|
get startCol(): number;
|
|
31
61
|
/**
|
|
62
|
+
* The starting line number (1-based) of this token in the source.
|
|
63
|
+
*
|
|
32
64
|
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
33
65
|
*/
|
|
34
66
|
get startLine(): number;
|
|
35
67
|
/**
|
|
68
|
+
* The starting character offset (0-based) of this token in the source.
|
|
69
|
+
*
|
|
36
70
|
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
37
71
|
*/
|
|
38
72
|
get startOffset(): number;
|
|
39
73
|
/**
|
|
74
|
+
* Replaces the fixed content of this token with the given string,
|
|
75
|
+
* used when applying lint fixes.
|
|
76
|
+
*
|
|
40
77
|
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
78
|
+
* @param raw - The new string content to set as the fixed value
|
|
41
79
|
*/
|
|
42
80
|
fix(raw: string): void;
|
|
43
81
|
/**
|
|
82
|
+
* Returns the string representation of this token.
|
|
83
|
+
*
|
|
44
84
|
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
85
|
+
* @param fixed - When true, returns the fixed content; otherwise returns the original raw content
|
|
86
|
+
* @returns The string content of this token
|
|
45
87
|
*/
|
|
46
88
|
toString(fixed?: boolean): string;
|
|
47
89
|
}
|