@markuplint/ml-core 3.4.0 → 3.6.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/lib/configs.js +1 -2
- package/lib/ml-core.d.ts +5 -5
- package/lib/ml-core.js +4 -4
- package/lib/ml-dom/helper/accname.js +18 -7
- package/lib/ml-dom/helper/create-node.d.ts +6 -5
- package/lib/ml-dom/helper/create-node.js +3 -1
- package/lib/ml-dom/helper/debug.js +9 -4
- package/lib/ml-dom/helper/getIndent.js +18 -12
- package/lib/ml-dom/helper/walkers.d.ts +7 -5
- package/lib/ml-dom/helper/walkers.js +4 -2
- package/lib/ml-dom/manipulations/child-node-methods.d.ts +7 -7
- package/lib/ml-dom/manipulations/child-node-methods.js +24 -6
- package/lib/ml-dom/manipulations/get-children.d.ts +2 -2
- package/lib/ml-dom/manipulations/get-children.js +3 -1
- package/lib/ml-dom/node/attr.d.ts +5 -2
- package/lib/ml-dom/node/attr.js +8 -4
- package/lib/ml-dom/node/block.d.ts +6 -2
- package/lib/ml-dom/node/block.js +14 -4
- package/lib/ml-dom/node/character-data.d.ts +2 -2
- package/lib/ml-dom/node/character-data.js +9 -3
- package/lib/ml-dom/node/child-node.d.ts +5 -3
- package/lib/ml-dom/node/child-node.js +3 -1
- package/lib/ml-dom/node/comment.d.ts +2 -2
- package/lib/ml-dom/node/document-fragment.d.ts +2 -2
- package/lib/ml-dom/node/document-type.d.ts +2 -2
- package/lib/ml-dom/node/document-type.js +14 -4
- package/lib/ml-dom/node/document.d.ts +20 -16
- package/lib/ml-dom/node/document.js +44 -19
- package/lib/ml-dom/node/dom-token-list.d.ts +2 -2
- package/lib/ml-dom/node/dom-token-list.js +4 -2
- package/lib/ml-dom/node/element.d.ts +15 -7
- package/lib/ml-dom/node/element.js +76 -27
- package/lib/ml-dom/node/named-node-map.d.ts +3 -3
- package/lib/ml-dom/node/named-node-map.js +11 -4
- package/lib/ml-dom/node/node-list.d.ts +4 -4
- package/lib/ml-dom/node/node-list.js +8 -3
- package/lib/ml-dom/node/node-store.d.ts +8 -3
- package/lib/ml-dom/node/node-store.js +8 -3
- package/lib/ml-dom/node/node.d.ts +2 -2
- package/lib/ml-dom/node/node.js +48 -17
- package/lib/ml-dom/node/parent-node.d.ts +2 -2
- package/lib/ml-dom/node/parent-node.js +15 -6
- package/lib/ml-dom/node/rule-mapper.d.ts +3 -3
- package/lib/ml-dom/node/rule-mapper.js +8 -3
- package/lib/ml-dom/node/text.d.ts +2 -2
- package/lib/ml-dom/node/types.d.ts +18 -6
- package/lib/ml-rule/create-rule.d.ts +4 -2
- package/lib/ml-rule/create-test-rule.d.ts +4 -4
- package/lib/ml-rule/ml-rule-context.d.ts +2 -2
- package/lib/ml-rule/ml-rule-context.js +3 -1
- package/lib/ml-rule/ml-rule.d.ts +14 -6
- package/lib/ml-rule/ml-rule.js +33 -28
- package/lib/ml-rule/types.d.ts +24 -12
- package/lib/plugin/plugin.d.ts +3 -1
- package/lib/plugin/types.d.ts +6 -6
- package/lib/ruleset/index.d.ts +3 -3
- package/lib/ruleset/index.js +4 -4
- package/lib/test/index.d.ts +5 -5
- package/lib/types.d.ts +9 -8
- package/lib/utils/get-location-from-chars.d.ts +1 -1
- package/package.json +14 -13
|
@@ -17,7 +17,11 @@ const parent_node_1 = require("./parent-node");
|
|
|
17
17
|
const unexpected_call_error_1 = tslib_1.__importDefault(require("./unexpected-call-error"));
|
|
18
18
|
const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
|
|
19
19
|
class MLElement extends parent_node_1.MLParentNode {
|
|
20
|
-
constructor(
|
|
20
|
+
constructor(
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
22
|
+
astNode,
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
24
|
+
document) {
|
|
21
25
|
super(astNode, document);
|
|
22
26
|
_MLElement_attributes.set(this, void 0);
|
|
23
27
|
_MLElement_fixedNodeName.set(this, void 0);
|
|
@@ -635,7 +639,8 @@ class MLElement extends parent_node_1.MLParentNode {
|
|
|
635
639
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-element-id%E2%91%A0
|
|
636
640
|
*/
|
|
637
641
|
get id() {
|
|
638
|
-
|
|
642
|
+
var _a;
|
|
643
|
+
return (_a = this.getAttribute('id')) !== null && _a !== void 0 ? _a : '';
|
|
639
644
|
}
|
|
640
645
|
/**
|
|
641
646
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -1785,7 +1790,7 @@ class MLElement extends parent_node_1.MLParentNode {
|
|
|
1785
1790
|
return (0, child_node_methods_1.previousElementSibling)(this);
|
|
1786
1791
|
}
|
|
1787
1792
|
get raw() {
|
|
1788
|
-
var _a, _b;
|
|
1793
|
+
var _a, _b, _c;
|
|
1789
1794
|
if (((_a = this.pretenderContext) === null || _a === void 0 ? void 0 : _a.type) === 'pretender') {
|
|
1790
1795
|
return this.originRaw;
|
|
1791
1796
|
}
|
|
@@ -1796,7 +1801,7 @@ class MLElement extends parent_node_1.MLParentNode {
|
|
|
1796
1801
|
gap = gap + this.fixedNodeName.length - this.nodeName.length;
|
|
1797
1802
|
}
|
|
1798
1803
|
for (const attr of Array.from(this.attributes)) {
|
|
1799
|
-
const startOffset = (((_b = attr.spacesBeforeName) === null || _b === void 0 ? void 0 : _b.startOffset)
|
|
1804
|
+
const startOffset = ((_c = (_b = attr.spacesBeforeName) === null || _b === void 0 ? void 0 : _b.startOffset) !== null && _c !== void 0 ? _c : attr.startOffset) - this.startOffset;
|
|
1800
1805
|
const fixedAttr = attr.toString();
|
|
1801
1806
|
if (attr.originRaw !== fixedAttr) {
|
|
1802
1807
|
fixed = (0, string_splice_1.stringSplice)(fixed, startOffset + gap, attr.originRaw.length, fixedAttr);
|
|
@@ -1886,7 +1891,8 @@ class MLElement extends parent_node_1.MLParentNode {
|
|
|
1886
1891
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-element-slot%E2%91%A0
|
|
1887
1892
|
*/
|
|
1888
1893
|
get slot() {
|
|
1889
|
-
|
|
1894
|
+
var _a;
|
|
1895
|
+
return (_a = this.getAttribute('slot')) !== null && _a !== void 0 ? _a : '';
|
|
1890
1896
|
}
|
|
1891
1897
|
/**
|
|
1892
1898
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -1943,7 +1949,7 @@ class MLElement extends parent_node_1.MLParentNode {
|
|
|
1943
1949
|
}
|
|
1944
1950
|
get textContent() {
|
|
1945
1951
|
return Array.from(this.childNodes)
|
|
1946
|
-
.map(child => child.textContent
|
|
1952
|
+
.map(child => { var _a; return (_a = child.textContent) !== null && _a !== void 0 ? _a : ''; })
|
|
1947
1953
|
.join('');
|
|
1948
1954
|
}
|
|
1949
1955
|
/**
|
|
@@ -1969,7 +1975,9 @@ class MLElement extends parent_node_1.MLParentNode {
|
|
|
1969
1975
|
/**
|
|
1970
1976
|
* @implements DOM API: `Element`
|
|
1971
1977
|
*/
|
|
1972
|
-
after(
|
|
1978
|
+
after(
|
|
1979
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
1980
|
+
...nodes) {
|
|
1973
1981
|
(0, child_node_methods_1.after)(this, ...nodes);
|
|
1974
1982
|
}
|
|
1975
1983
|
/**
|
|
@@ -1979,7 +1987,11 @@ class MLElement extends parent_node_1.MLParentNode {
|
|
|
1979
1987
|
* @implements DOM API: `Element`
|
|
1980
1988
|
* @see https://www.w3.org/TR/web-animations-1/#dom-animatable-animate
|
|
1981
1989
|
*/
|
|
1982
|
-
animate(
|
|
1990
|
+
animate(
|
|
1991
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
1992
|
+
keyframes,
|
|
1993
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
1994
|
+
options) {
|
|
1983
1995
|
throw new unexpected_call_error_1.default('Not supported "animate" method');
|
|
1984
1996
|
}
|
|
1985
1997
|
/**
|
|
@@ -1999,13 +2011,17 @@ class MLElement extends parent_node_1.MLParentNode {
|
|
|
1999
2011
|
* @implements DOM API: `Element`
|
|
2000
2012
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-element-attachshadow%E2%91%A0
|
|
2001
2013
|
*/
|
|
2002
|
-
attachShadow(
|
|
2014
|
+
attachShadow(
|
|
2015
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
2016
|
+
init) {
|
|
2003
2017
|
throw new unexpected_call_error_1.default('Not supported "attachShadow" method');
|
|
2004
2018
|
}
|
|
2005
2019
|
/**
|
|
2006
2020
|
* @implements DOM API: `Element`
|
|
2007
2021
|
*/
|
|
2008
|
-
before(
|
|
2022
|
+
before(
|
|
2023
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
2024
|
+
...nodes) {
|
|
2009
2025
|
(0, child_node_methods_1.before)(this, ...nodes);
|
|
2010
2026
|
}
|
|
2011
2027
|
/**
|
|
@@ -2018,6 +2034,18 @@ class MLElement extends parent_node_1.MLParentNode {
|
|
|
2018
2034
|
blur() {
|
|
2019
2035
|
throw new unexpected_call_error_1.default('Not supported "blur" method');
|
|
2020
2036
|
}
|
|
2037
|
+
/**
|
|
2038
|
+
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
2039
|
+
*
|
|
2040
|
+
* @deprecated
|
|
2041
|
+
* @unsupported
|
|
2042
|
+
* @implements DOM API: `Element`
|
|
2043
|
+
*/
|
|
2044
|
+
checkVisibility(
|
|
2045
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
2046
|
+
options) {
|
|
2047
|
+
throw new unexpected_call_error_1.default('Not supported "checkVisibility" method');
|
|
2048
|
+
}
|
|
2021
2049
|
/**
|
|
2022
2050
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
2023
2051
|
*
|
|
@@ -2052,7 +2080,9 @@ class MLElement extends parent_node_1.MLParentNode {
|
|
|
2052
2080
|
* @unsupported
|
|
2053
2081
|
* @implements DOM API: `Element`
|
|
2054
2082
|
*/
|
|
2055
|
-
focus(
|
|
2083
|
+
focus(
|
|
2084
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
2085
|
+
options) {
|
|
2056
2086
|
throw new unexpected_call_error_1.default('Not supported "focus" method');
|
|
2057
2087
|
}
|
|
2058
2088
|
/**
|
|
@@ -2068,7 +2098,9 @@ class MLElement extends parent_node_1.MLParentNode {
|
|
|
2068
2098
|
* @implements DOM API: `Element`
|
|
2069
2099
|
* @see https://www.w3.org/TR/web-animations-1/#dom-animatable-getanimations
|
|
2070
2100
|
*/
|
|
2071
|
-
getAnimations(
|
|
2101
|
+
getAnimations(
|
|
2102
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
2103
|
+
options) {
|
|
2072
2104
|
throw new unexpected_call_error_1.default('Not supported "getAnimations" method');
|
|
2073
2105
|
}
|
|
2074
2106
|
/**
|
|
@@ -2105,7 +2137,8 @@ class MLElement extends parent_node_1.MLParentNode {
|
|
|
2105
2137
|
* @see https://dom.spec.whatwg.org/#dom-element-getattributenode
|
|
2106
2138
|
*/
|
|
2107
2139
|
getAttributeNode(qualifiedName) {
|
|
2108
|
-
|
|
2140
|
+
var _a;
|
|
2141
|
+
return (_a = this.getAttributeToken(qualifiedName)[0]) !== null && _a !== void 0 ? _a : null;
|
|
2109
2142
|
}
|
|
2110
2143
|
/**
|
|
2111
2144
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -2254,7 +2287,7 @@ class MLElement extends parent_node_1.MLParentNode {
|
|
|
2254
2287
|
* @see https://dom.spec.whatwg.org/#dom-element-hasattributes
|
|
2255
2288
|
*/
|
|
2256
2289
|
hasAttributes() {
|
|
2257
|
-
return
|
|
2290
|
+
return this.attributes.length > 0;
|
|
2258
2291
|
}
|
|
2259
2292
|
/**
|
|
2260
2293
|
* @implements `@markuplint/ml-core` API: `MLElement`
|
|
@@ -2308,7 +2341,9 @@ class MLElement extends parent_node_1.MLParentNode {
|
|
|
2308
2341
|
* @implements DOM API: `Element`
|
|
2309
2342
|
* @see https://dom.spec.whatwg.org/#dom-element-insertadjacentelement
|
|
2310
2343
|
*/
|
|
2311
|
-
insertAdjacentElement(where,
|
|
2344
|
+
insertAdjacentElement(where,
|
|
2345
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
2346
|
+
element) {
|
|
2312
2347
|
// TODO:
|
|
2313
2348
|
throw new unexpected_call_error_1.default('Does not implement "insertAdjacentElement" method yet');
|
|
2314
2349
|
}
|
|
@@ -2368,14 +2403,15 @@ class MLElement extends parent_node_1.MLParentNode {
|
|
|
2368
2403
|
*/
|
|
2369
2404
|
matches(selector) {
|
|
2370
2405
|
var _a;
|
|
2371
|
-
return
|
|
2406
|
+
return ((0, selector_1.createSelector)(selector, this.ownerMLDocument.specs).match(
|
|
2372
2407
|
// Prioritize the pretender
|
|
2373
|
-
((_a = this.pretenderContext) === null || _a === void 0 ? void 0 : _a.type) === 'pretender' ? this.pretenderContext.as : this);
|
|
2408
|
+
((_a = this.pretenderContext) === null || _a === void 0 ? void 0 : _a.type) === 'pretender' ? this.pretenderContext.as : this) !== false);
|
|
2374
2409
|
}
|
|
2375
2410
|
/**
|
|
2376
2411
|
* Pretenders Initialization
|
|
2377
2412
|
*/
|
|
2378
2413
|
pretending(pretenders) {
|
|
2414
|
+
var _a;
|
|
2379
2415
|
const pretenderConfig = pretenders === null || pretenders === void 0 ? void 0 : pretenders.find(option => this.matches(option.selector));
|
|
2380
2416
|
if (!pretenderConfig) {
|
|
2381
2417
|
return;
|
|
@@ -2389,16 +2425,17 @@ class MLElement extends parent_node_1.MLParentNode {
|
|
|
2389
2425
|
}
|
|
2390
2426
|
else {
|
|
2391
2427
|
nodeName = pretenderConfig.as.element;
|
|
2392
|
-
namespace = pretenderConfig.as.namespace
|
|
2428
|
+
namespace = (_a = pretenderConfig.as.namespace) !== null && _a !== void 0 ? _a : namespace;
|
|
2393
2429
|
if (pretenderConfig.as.inheritAttrs) {
|
|
2394
2430
|
attributes.push(...this._astToken.attributes);
|
|
2395
2431
|
}
|
|
2396
2432
|
if (pretenderConfig.as.attrs) {
|
|
2397
2433
|
attributes.push(...pretenderConfig.as.attrs.map(({ name, value }, i) => {
|
|
2398
|
-
|
|
2434
|
+
var _a;
|
|
2435
|
+
const _value = value != null
|
|
2399
2436
|
? typeof value === 'string'
|
|
2400
2437
|
? value
|
|
2401
|
-
: this.getAttribute(value.fromAttr)
|
|
2438
|
+
: (_a = this.getAttribute(value.fromAttr)) !== null && _a !== void 0 ? _a : ''
|
|
2402
2439
|
: '';
|
|
2403
2440
|
return {
|
|
2404
2441
|
...this._astToken,
|
|
@@ -2511,13 +2548,17 @@ class MLElement extends parent_node_1.MLParentNode {
|
|
|
2511
2548
|
* @implements DOM API: `Element`
|
|
2512
2549
|
* @see https://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-D589198
|
|
2513
2550
|
*/
|
|
2514
|
-
removeAttributeNode(
|
|
2551
|
+
removeAttributeNode(
|
|
2552
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
2553
|
+
attr) {
|
|
2515
2554
|
throw new unexpected_call_error_1.default('Not supported "removeAttributeNode" method');
|
|
2516
2555
|
}
|
|
2517
2556
|
/**
|
|
2518
2557
|
* @implements DOM API: `Element`
|
|
2519
2558
|
*/
|
|
2520
|
-
replaceWith(
|
|
2559
|
+
replaceWith(
|
|
2560
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
2561
|
+
...nodes) {
|
|
2521
2562
|
(0, child_node_methods_1.replaceWith)(this, ...nodes);
|
|
2522
2563
|
}
|
|
2523
2564
|
/**
|
|
@@ -2527,7 +2568,9 @@ class MLElement extends parent_node_1.MLParentNode {
|
|
|
2527
2568
|
* @implements DOM API: `Element`
|
|
2528
2569
|
* @see https://fullscreen.spec.whatwg.org/#dom-element-requestfullscreen
|
|
2529
2570
|
*/
|
|
2530
|
-
requestFullscreen(
|
|
2571
|
+
requestFullscreen(
|
|
2572
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
2573
|
+
options) {
|
|
2531
2574
|
throw new unexpected_call_error_1.default('Not supported "requestFullscreen" method');
|
|
2532
2575
|
}
|
|
2533
2576
|
/**
|
|
@@ -2567,7 +2610,9 @@ class MLElement extends parent_node_1.MLParentNode {
|
|
|
2567
2610
|
* @implements DOM API: `Element`
|
|
2568
2611
|
* @see https://www.w3.org/TR/cssom-view-1/#dom-element-scrollintoview
|
|
2569
2612
|
*/
|
|
2570
|
-
scrollIntoView(
|
|
2613
|
+
scrollIntoView(
|
|
2614
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
2615
|
+
arg) {
|
|
2571
2616
|
throw new unexpected_call_error_1.default('Not supported "scrollIntoView" method');
|
|
2572
2617
|
}
|
|
2573
2618
|
/**
|
|
@@ -2607,7 +2652,9 @@ class MLElement extends parent_node_1.MLParentNode {
|
|
|
2607
2652
|
* @implements DOM API: `Element`
|
|
2608
2653
|
* @see https://dom.spec.whatwg.org/#dom-element-setattributenode
|
|
2609
2654
|
*/
|
|
2610
|
-
setAttributeNode(
|
|
2655
|
+
setAttributeNode(
|
|
2656
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
2657
|
+
attr) {
|
|
2611
2658
|
throw new unexpected_call_error_1.default('Not supported "setAttributeNode" method');
|
|
2612
2659
|
}
|
|
2613
2660
|
/**
|
|
@@ -2617,7 +2664,9 @@ class MLElement extends parent_node_1.MLParentNode {
|
|
|
2617
2664
|
* @implements DOM API: `Element`
|
|
2618
2665
|
* @see https://dom.spec.whatwg.org/#dom-element-setattributenodens
|
|
2619
2666
|
*/
|
|
2620
|
-
setAttributeNodeNS(
|
|
2667
|
+
setAttributeNodeNS(
|
|
2668
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
2669
|
+
attr) {
|
|
2621
2670
|
throw new unexpected_call_error_1.default('Not supported "setAttributeNodeNS" method');
|
|
2622
2671
|
}
|
|
2623
2672
|
/**
|
|
@@ -2639,7 +2688,7 @@ class MLElement extends parent_node_1.MLParentNode {
|
|
|
2639
2688
|
}
|
|
2640
2689
|
const children = this.getChildElementsAndTextNodeWithoutWhitespaces();
|
|
2641
2690
|
const attrs = this.attributes.map(attr => attr.toNormalizeString());
|
|
2642
|
-
const attrString = attrs.length ? ' ' + attrs.join('') : '';
|
|
2691
|
+
const attrString = attrs.length > 0 ? ' ' + attrs.join('') : '';
|
|
2643
2692
|
const startTag = `<${this.nodeName}${attrString}>`;
|
|
2644
2693
|
const childNodes = children.map(node => {
|
|
2645
2694
|
if (node.is(node.ELEMENT_NODE)) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { MLAttr } from './attr';
|
|
2
|
-
import type { RuleConfigValue } from '@markuplint/ml-config';
|
|
3
|
-
export declare class MLNamedNodeMap<T extends RuleConfigValue, O =
|
|
2
|
+
import type { PlainData, RuleConfigValue } from '@markuplint/ml-config';
|
|
3
|
+
export declare class MLNamedNodeMap<T extends RuleConfigValue, O extends PlainData = undefined>
|
|
4
4
|
extends Array<MLAttr<T, O>>
|
|
5
5
|
implements NamedNodeMap
|
|
6
6
|
{
|
|
@@ -42,6 +42,6 @@ export declare class MLNamedNodeMap<T extends RuleConfigValue, O = null>
|
|
|
42
42
|
*/
|
|
43
43
|
setNamedItemNS(attr: MLAttr<T, O>): MLAttr<T, O> | null;
|
|
44
44
|
}
|
|
45
|
-
export declare function toNamedNodeMap<T extends RuleConfigValue, O =
|
|
45
|
+
export declare function toNamedNodeMap<T extends RuleConfigValue, O extends PlainData = undefined>(
|
|
46
46
|
nodes: ReadonlyArray<MLAttr<T, O>>,
|
|
47
47
|
): MLNamedNodeMap<T, O>;
|
|
@@ -5,7 +5,8 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const unexpected_call_error_1 = tslib_1.__importDefault(require("./unexpected-call-error"));
|
|
6
6
|
class MLNamedNodeMap extends Array {
|
|
7
7
|
getNamedItem(qualifiedName) {
|
|
8
|
-
|
|
8
|
+
var _a;
|
|
9
|
+
return (_a = this.find(attr => attr.name === qualifiedName)) !== null && _a !== void 0 ? _a : null;
|
|
9
10
|
}
|
|
10
11
|
/**
|
|
11
12
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -44,7 +45,9 @@ class MLNamedNodeMap extends Array {
|
|
|
44
45
|
* @unsupported
|
|
45
46
|
* @implements DOM API: `NamedNodeMap`
|
|
46
47
|
*/
|
|
47
|
-
setNamedItem(
|
|
48
|
+
setNamedItem(
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
50
|
+
attr) {
|
|
48
51
|
throw new unexpected_call_error_1.default('Not supported "setNamedItem" method');
|
|
49
52
|
}
|
|
50
53
|
/**
|
|
@@ -53,12 +56,16 @@ class MLNamedNodeMap extends Array {
|
|
|
53
56
|
* @unsupported
|
|
54
57
|
* @implements DOM API: `NamedNodeMap`
|
|
55
58
|
*/
|
|
56
|
-
setNamedItemNS(
|
|
59
|
+
setNamedItemNS(
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
61
|
+
attr) {
|
|
57
62
|
throw new unexpected_call_error_1.default('Not supported "setNamedItemNS" method');
|
|
58
63
|
}
|
|
59
64
|
}
|
|
60
65
|
exports.MLNamedNodeMap = MLNamedNodeMap;
|
|
61
|
-
function toNamedNodeMap(
|
|
66
|
+
function toNamedNodeMap(
|
|
67
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
68
|
+
nodes) {
|
|
62
69
|
const namedNodeMap = new MLNamedNodeMap(...nodes);
|
|
63
70
|
return namedNodeMap;
|
|
64
71
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { MLChildNode } from './child-node';
|
|
2
2
|
import type { MLElement } from './element';
|
|
3
|
-
import type { RuleConfigValue } from '@markuplint/ml-config';
|
|
4
|
-
export declare function toNodeList<T extends RuleConfigValue, O, N extends MLChildNode<T, O>>(
|
|
3
|
+
import type { PlainData, RuleConfigValue } from '@markuplint/ml-config';
|
|
4
|
+
export declare function toNodeList<T extends RuleConfigValue, O extends PlainData, N extends MLChildNode<T, O>>(
|
|
5
5
|
nodes: ReadonlyArray<N>,
|
|
6
6
|
): NodeListOf<N>;
|
|
7
|
-
export declare function toHTMLCollection<T extends RuleConfigValue, O =
|
|
7
|
+
export declare function toHTMLCollection<T extends RuleConfigValue, O extends PlainData = undefined>(
|
|
8
8
|
nodes: ReadonlyArray<MLElement<T, O>>,
|
|
9
9
|
): HTMLCollectionOf<MLElement<T, O>>;
|
|
10
|
-
export declare function nodeListToHTMLCollection<T extends RuleConfigValue, O =
|
|
10
|
+
export declare function nodeListToHTMLCollection<T extends RuleConfigValue, O extends PlainData = undefined>(
|
|
11
11
|
nodeList: NodeListOf<MLChildNode<T, O>>,
|
|
12
12
|
): HTMLCollectionOf<MLElement<T, O>>;
|
|
@@ -34,15 +34,20 @@ class MLHTMLCollection extends Array {
|
|
|
34
34
|
return (_a = this[index]) !== null && _a !== void 0 ? _a : null;
|
|
35
35
|
}
|
|
36
36
|
namedItem(name) {
|
|
37
|
-
|
|
37
|
+
var _a;
|
|
38
|
+
return (_a = this.find(el => el.getAttribute('name') === name)) !== null && _a !== void 0 ? _a : null;
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
|
-
function toHTMLCollection(
|
|
41
|
+
function toHTMLCollection(
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
43
|
+
nodes) {
|
|
41
44
|
const collection = new MLHTMLCollection(...nodes);
|
|
42
45
|
return collection;
|
|
43
46
|
}
|
|
44
47
|
exports.toHTMLCollection = toHTMLCollection;
|
|
45
|
-
function nodeListToHTMLCollection(
|
|
48
|
+
function nodeListToHTMLCollection(
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
50
|
+
nodeList) {
|
|
46
51
|
const collection = new MLHTMLCollection();
|
|
47
52
|
nodeList.forEach(node => {
|
|
48
53
|
if (node.is(node.ELEMENT_NODE)) {
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import type { MLNode } from './node';
|
|
2
2
|
import type { MappedNode } from './types';
|
|
3
3
|
import type { MLASTAbstractNode } from '@markuplint/ml-ast';
|
|
4
|
-
import type { RuleConfigValue } from '@markuplint/ml-config';
|
|
4
|
+
import type { PlainData, RuleConfigValue } from '@markuplint/ml-config';
|
|
5
5
|
declare class NodeStore {
|
|
6
6
|
#private;
|
|
7
|
-
getNode<N extends MLASTAbstractNode, T extends RuleConfigValue, O =
|
|
8
|
-
|
|
7
|
+
getNode<N extends MLASTAbstractNode, T extends RuleConfigValue, O extends PlainData = undefined>(
|
|
8
|
+
astNode: N,
|
|
9
|
+
): MappedNode<N, T, O>;
|
|
10
|
+
setNode<A extends MLASTAbstractNode, T extends RuleConfigValue, O extends PlainData = undefined>(
|
|
11
|
+
astNode: A,
|
|
12
|
+
node: MLNode<T, O, A>,
|
|
13
|
+
): void;
|
|
9
14
|
}
|
|
10
15
|
/**
|
|
11
16
|
* `NodeStore` Singleton
|
|
@@ -16,7 +16,10 @@ class NodeStore {
|
|
|
16
16
|
const node = tslib_1.__classPrivateFieldGet(this, _NodeStore_store, "f").get(astNode.uuid);
|
|
17
17
|
if (!node) {
|
|
18
18
|
nodeStoreError('Ref ID: %s (%s: "%s")', astNode.uuid, astNode.nodeName, astNode.raw);
|
|
19
|
-
nodeStoreError('Map: %O', tslib_1.__classPrivateFieldGet(this, _NodeStore_store, "f"))
|
|
19
|
+
nodeStoreError('Map: %O', Array.from(tslib_1.__classPrivateFieldGet(this, _NodeStore_store, "f").entries()).map(([id, node]) => ({
|
|
20
|
+
id,
|
|
21
|
+
name: node.nodeName,
|
|
22
|
+
})));
|
|
20
23
|
throw new parser_utils_1.ParserError('Broke mapping nodes.', {
|
|
21
24
|
line: astNode.startLine,
|
|
22
25
|
col: astNode.startCol,
|
|
@@ -26,7 +29,9 @@ class NodeStore {
|
|
|
26
29
|
}
|
|
27
30
|
return node;
|
|
28
31
|
}
|
|
29
|
-
setNode(astNode,
|
|
32
|
+
setNode(astNode,
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
34
|
+
node) {
|
|
30
35
|
if (node.is(node.DOCUMENT_NODE)) {
|
|
31
36
|
return;
|
|
32
37
|
}
|
|
@@ -34,7 +39,7 @@ class NodeStore {
|
|
|
34
39
|
nodeStoreError('UUID is invalid: %s (%s: "%s")', astNode.uuid, astNode.nodeName, astNode.raw);
|
|
35
40
|
nodeStoreError('Invalid node: %O', node);
|
|
36
41
|
}
|
|
37
|
-
nodeStoreLog('Mapped: %s (%s: "%s")', astNode.uuid, astNode.nodeName, astNode.raw);
|
|
42
|
+
nodeStoreLog('Mapped: %s (%s: "%s")', astNode.uuid, astNode.nodeName, astNode.raw.replace(/\n/g, '⏎').replace(/\t/g, '→'));
|
|
38
43
|
tslib_1.__classPrivateFieldGet(this, _NodeStore_store, "f").set(astNode.uuid, node);
|
|
39
44
|
}
|
|
40
45
|
}
|
|
@@ -6,11 +6,11 @@ import type { MLElement } from './element';
|
|
|
6
6
|
import type { MarkuplintPreprocessorBlockType, NodeType, NodeTypeOf } from './types';
|
|
7
7
|
import type { RuleInfo } from '../..';
|
|
8
8
|
import type { MLASTAbstractNode } from '@markuplint/ml-ast';
|
|
9
|
-
import type { AnyRule, RuleConfigValue } from '@markuplint/ml-config';
|
|
9
|
+
import type { AnyRule, PlainData, RuleConfigValue } from '@markuplint/ml-config';
|
|
10
10
|
import { MLToken } from '../token/token';
|
|
11
11
|
export declare abstract class MLNode<
|
|
12
12
|
T extends RuleConfigValue,
|
|
13
|
-
O =
|
|
13
|
+
O extends PlainData = undefined,
|
|
14
14
|
A extends MLASTAbstractNode = MLASTAbstractNode,
|
|
15
15
|
>
|
|
16
16
|
extends MLToken<A>
|
package/lib/ml-dom/node/node.js
CHANGED
|
@@ -9,7 +9,9 @@ const node_list_1 = require("./node-list");
|
|
|
9
9
|
const node_store_1 = require("./node-store");
|
|
10
10
|
const unexpected_call_error_1 = tslib_1.__importDefault(require("./unexpected-call-error"));
|
|
11
11
|
class MLNode extends token_1.MLToken {
|
|
12
|
-
constructor(astNode,
|
|
12
|
+
constructor(astNode,
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
14
|
+
document) {
|
|
13
15
|
super(astNode);
|
|
14
16
|
/**
|
|
15
17
|
* @implements DOM API: `Node`
|
|
@@ -149,6 +151,7 @@ class MLNode extends token_1.MLToken {
|
|
|
149
151
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-node-childnodes%E2%91%A0
|
|
150
152
|
*/
|
|
151
153
|
get childNodes() {
|
|
154
|
+
var _a;
|
|
152
155
|
if (tslib_1.__classPrivateFieldGet(this, _MLNode_childNodes, "f") != null) {
|
|
153
156
|
return tslib_1.__classPrivateFieldGet(this, _MLNode_childNodes, "f");
|
|
154
157
|
}
|
|
@@ -167,7 +170,7 @@ class MLNode extends token_1.MLToken {
|
|
|
167
170
|
this.is(this.ELEMENT_NODE) ||
|
|
168
171
|
this.is(this.MARKUPLINT_PREPROCESSOR_BLOCK)) {
|
|
169
172
|
// @ts-ignore
|
|
170
|
-
const astChildren = this._astToken.childNodes
|
|
173
|
+
const astChildren = (_a = this._astToken.childNodes) !== null && _a !== void 0 ? _a : [];
|
|
171
174
|
const childNodes = astChildren
|
|
172
175
|
.map(node => node_store_1.nodeStore.getNode(node))
|
|
173
176
|
.filter((node) => (0, child_node_1.isChildNode)(node));
|
|
@@ -369,6 +372,7 @@ class MLNode extends token_1.MLToken {
|
|
|
369
372
|
* @implements `@markuplint/ml-core` API: `MLNode`
|
|
370
373
|
*/
|
|
371
374
|
get prevToken() {
|
|
375
|
+
var _a, _b;
|
|
372
376
|
if (tslib_1.__classPrivateFieldGet(this, _MLNode_prevToken, "f") !== undefined) {
|
|
373
377
|
return tslib_1.__classPrivateFieldGet(this, _MLNode_prevToken, "f");
|
|
374
378
|
}
|
|
@@ -390,8 +394,8 @@ class MLNode extends token_1.MLToken {
|
|
|
390
394
|
tslib_1.__classPrivateFieldSet(this, _MLNode_prevToken, null, "f");
|
|
391
395
|
return tslib_1.__classPrivateFieldGet(this, _MLNode_prevToken, "f");
|
|
392
396
|
}
|
|
393
|
-
tslib_1.__classPrivateFieldSet(this, _MLNode_prevToken, this.ownerMLDocument.nodeList[index - 1]
|
|
394
|
-
return tslib_1.__classPrivateFieldGet(this, _MLNode_prevToken, "f")
|
|
397
|
+
tslib_1.__classPrivateFieldSet(this, _MLNode_prevToken, (_a = this.ownerMLDocument.nodeList[index - 1]) !== null && _a !== void 0 ? _a : null, "f");
|
|
398
|
+
return (_b = tslib_1.__classPrivateFieldGet(this, _MLNode_prevToken, "f")) !== null && _b !== void 0 ? _b : null;
|
|
395
399
|
}
|
|
396
400
|
/**
|
|
397
401
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -411,8 +415,13 @@ class MLNode extends token_1.MLToken {
|
|
|
411
415
|
throw new Error('Invalid call: Some rule evaluations may not be running asynchronously.');
|
|
412
416
|
}
|
|
413
417
|
const name = this.ownerMLDocument.currentRule.name;
|
|
414
|
-
const
|
|
415
|
-
|
|
418
|
+
const settingRule = this.rules[name];
|
|
419
|
+
const rule = this.ownerMLDocument.currentRule.optimizeOption(settingRule);
|
|
420
|
+
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
421
|
+
if (!rule) {
|
|
422
|
+
throw new Error(`Rule data "${name}" doesn't exist in rules ([${Object.keys(this.rules).map(name => `"${name}"`)}]) of ${this.nodeName}("${this.raw}")`);
|
|
423
|
+
}
|
|
424
|
+
return rule;
|
|
416
425
|
}
|
|
417
426
|
/**
|
|
418
427
|
* Returns a syntactical parent node
|
|
@@ -477,7 +486,9 @@ class MLNode extends token_1.MLToken {
|
|
|
477
486
|
* @implements DOM API: `EventTarget`
|
|
478
487
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-eventtarget-addeventlistener%E2%91%A2
|
|
479
488
|
*/
|
|
480
|
-
addEventListener(type,
|
|
489
|
+
addEventListener(type,
|
|
490
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
491
|
+
callback, options = {}) {
|
|
481
492
|
throw new unexpected_call_error_1.default('Not supported "addEventListener" method');
|
|
482
493
|
}
|
|
483
494
|
/**
|
|
@@ -507,7 +518,9 @@ class MLNode extends token_1.MLToken {
|
|
|
507
518
|
* @implements DOM API: `Node`
|
|
508
519
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-node-comparedocumentposition%E2%91%A0
|
|
509
520
|
*/
|
|
510
|
-
compareDocumentPosition(
|
|
521
|
+
compareDocumentPosition(
|
|
522
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
523
|
+
other) {
|
|
511
524
|
throw new unexpected_call_error_1.default('Not supported "compareDocumentPosition" method');
|
|
512
525
|
}
|
|
513
526
|
/**
|
|
@@ -517,7 +530,9 @@ class MLNode extends token_1.MLToken {
|
|
|
517
530
|
* @implements DOM API: `Node`
|
|
518
531
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-node-contains%E2%91%A0
|
|
519
532
|
*/
|
|
520
|
-
contains(
|
|
533
|
+
contains(
|
|
534
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
535
|
+
other) {
|
|
521
536
|
throw new unexpected_call_error_1.default('Not supported "contains" method');
|
|
522
537
|
}
|
|
523
538
|
/**
|
|
@@ -527,7 +542,9 @@ class MLNode extends token_1.MLToken {
|
|
|
527
542
|
* @implements DOM API: `EventTarget`
|
|
528
543
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-eventtarget-dispatchevent%E2%91%A2
|
|
529
544
|
*/
|
|
530
|
-
dispatchEvent(
|
|
545
|
+
dispatchEvent(
|
|
546
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
547
|
+
event) {
|
|
531
548
|
throw new unexpected_call_error_1.default('Not supported "dispatchEvent" method');
|
|
532
549
|
}
|
|
533
550
|
/**
|
|
@@ -537,7 +554,9 @@ class MLNode extends token_1.MLToken {
|
|
|
537
554
|
* @implements DOM API: `Node`
|
|
538
555
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-node-getrootnode%E2%91%A0
|
|
539
556
|
*/
|
|
540
|
-
getRootNode(
|
|
557
|
+
getRootNode(
|
|
558
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
559
|
+
options) {
|
|
541
560
|
if (options) {
|
|
542
561
|
throw new unexpected_call_error_1.default('Not supported options');
|
|
543
562
|
}
|
|
@@ -561,7 +580,9 @@ class MLNode extends token_1.MLToken {
|
|
|
561
580
|
* @implements DOM API: `Node`
|
|
562
581
|
* @see https://dom.spec.whatwg.org/#dom-node-insertbefore
|
|
563
582
|
*/
|
|
564
|
-
insertBefore(node,
|
|
583
|
+
insertBefore(node,
|
|
584
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
585
|
+
child) {
|
|
565
586
|
throw new unexpected_call_error_1.default('Not supported "insertBefore" method');
|
|
566
587
|
}
|
|
567
588
|
/**
|
|
@@ -587,7 +608,9 @@ class MLNode extends token_1.MLToken {
|
|
|
587
608
|
* @implements DOM API: `Node`
|
|
588
609
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-node-isequalnode%E2%91%A0
|
|
589
610
|
*/
|
|
590
|
-
isEqualNode(
|
|
611
|
+
isEqualNode(
|
|
612
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
613
|
+
otherNode) {
|
|
591
614
|
throw new unexpected_call_error_1.default('Not supported "isEqualNode" method');
|
|
592
615
|
}
|
|
593
616
|
/**
|
|
@@ -603,7 +626,9 @@ class MLNode extends token_1.MLToken {
|
|
|
603
626
|
* @implements DOM API: `Node`
|
|
604
627
|
* @see https://dom.spec.whatwg.org/#dom-node-issamenode
|
|
605
628
|
*/
|
|
606
|
-
isSameNode(
|
|
629
|
+
isSameNode(
|
|
630
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
631
|
+
otherNode) {
|
|
607
632
|
throw new unexpected_call_error_1.default('Not supported "isSameNode" method');
|
|
608
633
|
}
|
|
609
634
|
/**
|
|
@@ -653,7 +678,9 @@ class MLNode extends token_1.MLToken {
|
|
|
653
678
|
* @implements DOM API: `EventTarget`
|
|
654
679
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-eventtarget-removeeventlistener%E2%91%A1
|
|
655
680
|
*/
|
|
656
|
-
removeEventListener(type,
|
|
681
|
+
removeEventListener(type,
|
|
682
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
683
|
+
callback, options = {}) {
|
|
657
684
|
throw new unexpected_call_error_1.default('Not supported "removeEventListener" method');
|
|
658
685
|
}
|
|
659
686
|
/**
|
|
@@ -663,13 +690,17 @@ class MLNode extends token_1.MLToken {
|
|
|
663
690
|
* @implements DOM API: `Node`
|
|
664
691
|
* @see https://dom.spec.whatwg.org/#dom-node-replacechild
|
|
665
692
|
*/
|
|
666
|
-
replaceChild(
|
|
693
|
+
replaceChild(
|
|
694
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
695
|
+
node, child) {
|
|
667
696
|
throw new unexpected_call_error_1.default('Not supported "removeChild" method');
|
|
668
697
|
}
|
|
669
698
|
/**
|
|
670
699
|
* @implements `@markuplint/ml-core` API: `MLNode`
|
|
671
700
|
*/
|
|
672
|
-
resetChildren(
|
|
701
|
+
resetChildren(
|
|
702
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
703
|
+
childNodes) {
|
|
673
704
|
tslib_1.__classPrivateFieldSet(this, _MLNode_childNodes, childNodes !== null && childNodes !== void 0 ? childNodes : tslib_1.__classPrivateFieldGet(this, _MLNode_childNodes, "f"), "f");
|
|
674
705
|
}
|
|
675
706
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { MLElement } from './element';
|
|
2
2
|
import type { MLASTAbstractNode } from '@markuplint/ml-ast';
|
|
3
|
-
import type { RuleConfigValue } from '@markuplint/ml-config';
|
|
3
|
+
import type { PlainData, RuleConfigValue } from '@markuplint/ml-config';
|
|
4
4
|
import { MLNode } from './node';
|
|
5
5
|
/**
|
|
6
6
|
*
|
|
@@ -8,7 +8,7 @@ import { MLNode } from './node';
|
|
|
8
8
|
*/
|
|
9
9
|
export declare abstract class MLParentNode<
|
|
10
10
|
T extends RuleConfigValue,
|
|
11
|
-
O =
|
|
11
|
+
O extends PlainData = undefined,
|
|
12
12
|
A extends MLASTAbstractNode = MLASTAbstractNode,
|
|
13
13
|
>
|
|
14
14
|
extends MLNode<T, O, A>
|