@markuplint/ml-core 3.15.0 → 4.0.0-alpha.10
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/LICENSE +1 -1
- package/lib/configs.browser.js +11 -11
- package/lib/convert-ruleset.d.ts +1 -1
- package/lib/convert-ruleset.js +3 -8
- package/lib/debug.js +9 -14
- package/lib/index.d.ts +13 -23
- package/lib/index.js +12 -29
- package/lib/ml-core.d.ts +5 -5
- package/lib/ml-core.js +94 -76
- package/lib/ml-dom/helper/accname.d.ts +1 -1
- package/lib/ml-dom/helper/accname.js +12 -19
- package/lib/ml-dom/helper/create-node.d.ts +4 -8
- package/lib/ml-dom/helper/create-node.js +38 -17
- package/lib/ml-dom/helper/debug.d.ts +1 -1
- package/lib/ml-dom/helper/debug.js +13 -22
- package/lib/ml-dom/helper/get-indent.d.ts +18 -0
- package/lib/ml-dom/helper/get-indent.js +112 -0
- package/lib/ml-dom/helper/walkers.d.ts +5 -15
- package/lib/ml-dom/helper/walkers.js +3 -8
- package/lib/ml-dom/index.d.ts +9 -9
- package/lib/ml-dom/index.js +1 -5
- package/lib/ml-dom/manipulations/child-node-methods.d.ts +7 -20
- package/lib/ml-dom/manipulations/child-node-methods.js +13 -25
- package/lib/ml-dom/manipulations/get-children.d.ts +3 -5
- package/lib/ml-dom/manipulations/get-children.js +3 -7
- package/lib/ml-dom/node/attr.d.ts +113 -98
- package/lib/ml-dom/node/attr.js +93 -50
- package/lib/ml-dom/node/block.d.ts +35 -39
- package/lib/ml-dom/node/block.js +8 -14
- package/lib/ml-dom/node/character-data.d.ts +55 -62
- package/lib/ml-dom/node/character-data.js +11 -16
- package/lib/ml-dom/node/child-node.d.ts +8 -15
- package/lib/ml-dom/node/child-node.js +1 -5
- package/lib/ml-dom/node/comment.d.ts +14 -17
- package/lib/ml-dom/node/comment.js +2 -6
- package/lib/ml-dom/node/document-fragment.d.ts +22 -25
- package/lib/ml-dom/node/document-fragment.js +4 -9
- package/lib/ml-dom/node/document-type.d.ts +35 -38
- package/lib/ml-dom/node/document-type.js +8 -14
- package/lib/ml-dom/node/document.d.ts +1598 -1614
- package/lib/ml-dom/node/document.js +330 -275
- package/lib/ml-dom/node/dom-token-list.d.ts +27 -27
- package/lib/ml-dom/node/dom-token-list.js +36 -32
- package/lib/ml-dom/node/element-close-tag.d.ts +20 -0
- package/lib/ml-dom/node/element-close-tag.js +39 -0
- package/lib/ml-dom/node/element.d.ts +1957 -1951
- package/lib/ml-dom/node/element.js +364 -348
- package/lib/ml-dom/node/named-node-map.d.ts +40 -45
- package/lib/ml-dom/node/named-node-map.js +10 -18
- package/lib/ml-dom/node/node-list.d.ts +5 -11
- package/lib/ml-dom/node/node-list.js +8 -16
- package/lib/ml-dom/node/node-store.d.ts +6 -11
- package/lib/ml-dom/node/node-store.js +14 -13
- package/lib/ml-dom/node/node.d.ts +480 -500
- package/lib/ml-dom/node/node.js +83 -73
- package/lib/ml-dom/node/parent-node.d.ts +60 -69
- package/lib/ml-dom/node/parent-node.js +32 -29
- package/lib/ml-dom/node/rule-mapper.d.ts +9 -9
- package/lib/ml-dom/node/rule-mapper.js +26 -21
- package/lib/ml-dom/node/text.d.ts +48 -51
- package/lib/ml-dom/node/text.js +8 -13
- package/lib/ml-dom/node/types.d.ts +42 -90
- package/lib/ml-dom/node/types.js +1 -2
- package/lib/ml-dom/node/unexpected-call-error.d.ts +2 -1
- package/lib/ml-dom/node/unexpected-call-error.js +1 -4
- package/lib/ml-dom/token/token.d.ts +45 -45
- package/lib/ml-dom/token/token.js +32 -26
- package/lib/ml-rule/create-rule.d.ts +2 -4
- package/lib/ml-rule/create-rule.js +1 -5
- package/lib/ml-rule/create-test-rule.d.ts +5 -7
- package/lib/ml-rule/create-test-rule.js +3 -7
- package/lib/ml-rule/index.d.ts +3 -3
- package/lib/ml-rule/index.js +3 -6
- package/lib/ml-rule/ml-rule-context.d.ts +49 -57
- package/lib/ml-rule/ml-rule-context.js +11 -11
- package/lib/ml-rule/ml-rule.d.ts +26 -36
- package/lib/ml-rule/ml-rule.js +34 -31
- package/lib/ml-rule/types.d.ts +18 -33
- package/lib/ml-rule/types.js +1 -2
- package/lib/plugin/index.d.ts +2 -2
- package/lib/plugin/index.js +2 -5
- package/lib/plugin/plugin.d.ts +2 -4
- package/lib/plugin/plugin.js +1 -5
- package/lib/plugin/types.d.ts +6 -6
- package/lib/plugin/types.js +1 -2
- package/lib/ruleset/index.d.ts +5 -5
- package/lib/ruleset/index.js +4 -8
- package/lib/test/index.d.ts +11 -21
- package/lib/test/index.js +18 -24
- package/lib/types.d.ts +11 -11
- package/lib/types.js +1 -2
- package/lib/utils/get-location-from-chars.d.ts +4 -9
- package/lib/utils/get-location-from-chars.js +4 -8
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +1 -5
- package/lib/utils/string-splice.js +1 -5
- package/package.json +19 -15
- package/lib/configs.d.ts +0 -2
- package/lib/configs.js +0 -34
- package/lib/ml-dom/helper/getIndent.d.ts +0 -18
- package/lib/ml-dom/helper/getIndent.js +0 -106
- package/test/ml-dom/helper/accname.spec.js +0 -85
- package/test/ml-dom/helper/create-node.spec.js +0 -18
- package/test/ml-dom/index.spec.js +0 -680
- package/test/ml-dom/ml-rule/create-rule.spec.js +0 -108
|
@@ -1,101 +1,116 @@
|
|
|
1
|
-
import type { MLElement } from './element';
|
|
2
|
-
import type { AttributeNodeType } from './types';
|
|
1
|
+
import type { MLElement } from './element.js';
|
|
2
|
+
import type { AttributeNodeType } from './types.js';
|
|
3
3
|
import type { MLASTAttr } from '@markuplint/ml-ast';
|
|
4
4
|
import type { PlainData, RuleConfigValue } from '@markuplint/ml-config';
|
|
5
|
-
import { MLToken } from '../token/token';
|
|
6
|
-
import { MLDomTokenList } from './dom-token-list';
|
|
7
|
-
import { MLNode } from './node';
|
|
8
|
-
export declare class MLAttr<T extends RuleConfigValue, O extends PlainData = undefined>
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
5
|
+
import { MLToken } from '../token/token.js';
|
|
6
|
+
import { MLDomTokenList } from './dom-token-list.js';
|
|
7
|
+
import { MLNode } from './node.js';
|
|
8
|
+
export declare class MLAttr<T extends RuleConfigValue, O extends PlainData = undefined> extends MLNode<T, O, MLASTAttr> implements Attr {
|
|
9
|
+
#private;
|
|
10
|
+
readonly candidate?: string;
|
|
11
|
+
readonly endQuote: MLToken | null;
|
|
12
|
+
readonly equal: MLToken | null;
|
|
13
|
+
readonly isDirective?: true;
|
|
14
|
+
readonly isDuplicatable: boolean;
|
|
15
|
+
readonly isDynamicValue?: true;
|
|
16
|
+
readonly nameNode: MLToken | null;
|
|
17
|
+
/**
|
|
18
|
+
* @implements DOM API: `Attr`
|
|
19
|
+
* @see https://dom.spec.whatwg.org/#ref-for-dom-node-previoussibling%E2%91%A0
|
|
20
|
+
*/
|
|
21
|
+
readonly ownerElement: MLElement<T, O>;
|
|
22
|
+
readonly spacesAfterEqual: MLToken | null;
|
|
23
|
+
readonly spacesBeforeEqual: MLToken | null;
|
|
24
|
+
readonly spacesBeforeName: MLToken | null;
|
|
25
|
+
readonly startQuote: MLToken | null;
|
|
26
|
+
readonly valueNode: MLToken | null;
|
|
27
|
+
/**
|
|
28
|
+
* Returns the "string" if HTML syntax. Otherwise, returns a type in its syntax.
|
|
29
|
+
*
|
|
30
|
+
* @default "string"
|
|
31
|
+
* @implements `@markuplint/ml-core` API: `MLAttr`
|
|
32
|
+
*/
|
|
33
|
+
readonly valueType: 'string' | 'number' | 'boolean' | 'code';
|
|
34
|
+
constructor(astToken: MLASTAttr, ownElement: MLElement<T, O>);
|
|
35
|
+
/**
|
|
36
|
+
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
37
|
+
*
|
|
38
|
+
* @unsupported
|
|
39
|
+
* @implements DOM API: `Attr`
|
|
40
|
+
* @see https://dom.spec.whatwg.org/#ref-for-dom-attr-localname
|
|
41
|
+
*/
|
|
42
|
+
get localName(): string;
|
|
43
|
+
/**
|
|
44
|
+
*
|
|
45
|
+
* @implements DOM API: `Attr`
|
|
46
|
+
* @see https://dom.spec.whatwg.org/#dom-attr-name
|
|
47
|
+
*/
|
|
48
|
+
get name(): string;
|
|
49
|
+
/**
|
|
50
|
+
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
51
|
+
*
|
|
52
|
+
* @unsupported
|
|
53
|
+
* @implements DOM API: `Attr`
|
|
54
|
+
* @see https://dom.spec.whatwg.org/#ref-for-dom-attr-namespaceuri
|
|
55
|
+
*/
|
|
56
|
+
get namespaceURI(): string | null;
|
|
57
|
+
/**
|
|
58
|
+
* Returns a string appropriate for the type of node as `Attr`
|
|
59
|
+
*
|
|
60
|
+
* @see https://dom.spec.whatwg.org/#ref-for-attr%E2%91%A4
|
|
61
|
+
*/
|
|
62
|
+
get nodeName(): string;
|
|
63
|
+
/**
|
|
64
|
+
* Returns a number appropriate for the type of `Attr`
|
|
65
|
+
*/
|
|
66
|
+
get nodeType(): AttributeNodeType;
|
|
67
|
+
get nodeValue(): string;
|
|
68
|
+
/**
|
|
69
|
+
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
70
|
+
*
|
|
71
|
+
* @unsupported
|
|
72
|
+
* @implements DOM API: `Attr`
|
|
73
|
+
* @see https://dom.spec.whatwg.org/#ref-for-dom-attr-prefix
|
|
74
|
+
*/
|
|
75
|
+
get prefix(): string | null;
|
|
76
|
+
/**
|
|
77
|
+
* @implements `@markuplint/ml-core` API: `MLAttr`
|
|
78
|
+
*/
|
|
79
|
+
get rule(): import("@markuplint/ml-config").RuleInfo<T, O>;
|
|
80
|
+
/**
|
|
81
|
+
* @implements DOM API: `Attr`
|
|
82
|
+
* @see https://dom.spec.whatwg.org/#dom-attr-specified
|
|
83
|
+
*/
|
|
84
|
+
get specified(): true;
|
|
85
|
+
/**
|
|
86
|
+
* @implements `@markuplint/ml-core` API: `MLAttr`
|
|
87
|
+
*/
|
|
88
|
+
get tokenList(): MLDomTokenList | null;
|
|
89
|
+
/**
|
|
90
|
+
* @implements DOM API: `Attr`
|
|
91
|
+
* @see https://dom.spec.whatwg.org/#dom-attr-value
|
|
92
|
+
*/
|
|
93
|
+
get value(): string;
|
|
94
|
+
/**
|
|
95
|
+
* Fixes the attribute value.
|
|
96
|
+
* If the attribute is not a spread attribute, it calls the `fix` method of the `valueNode`.
|
|
97
|
+
*
|
|
98
|
+
* @implements `@markuplint/ml-core` API: `MLAttr`
|
|
99
|
+
*
|
|
100
|
+
* @param raw - The raw attribute value.
|
|
101
|
+
*/
|
|
102
|
+
fix(raw: string): void;
|
|
103
|
+
/**
|
|
104
|
+
* @implements `@markuplint/ml-core` API: `MLAttr`
|
|
105
|
+
*/
|
|
106
|
+
toNormalizeString(): string;
|
|
107
|
+
/**
|
|
108
|
+
* Returns a string representation of the attribute.
|
|
109
|
+
*
|
|
110
|
+
* @implements DOM API: `Attr`
|
|
111
|
+
*
|
|
112
|
+
* @param includesSpacesBeforeName - Whether to include spaces before the attribute name.
|
|
113
|
+
* @returns The string representation of the attribute.
|
|
114
|
+
*/
|
|
115
|
+
toString(fixed?: boolean): string;
|
|
101
116
|
}
|
package/lib/ml-dom/node/attr.js
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
2
12
|
var _MLAttr_localName, _MLAttr_namespaceURI, _MLAttr_potentialName, _MLAttr_potentialValue;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const unexpected_call_error_1 = tslib_1.__importDefault(require("./unexpected-call-error"));
|
|
11
|
-
class MLAttr extends node_1.MLNode {
|
|
12
|
-
constructor(
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
14
|
-
astToken,
|
|
13
|
+
import { resolveNamespace } from '@markuplint/ml-spec';
|
|
14
|
+
import { MLToken } from '../token/token.js';
|
|
15
|
+
import { MLDomTokenList } from './dom-token-list.js';
|
|
16
|
+
import { MLNode } from './node.js';
|
|
17
|
+
import { UnexpectedCallError } from './unexpected-call-error.js';
|
|
18
|
+
export class MLAttr extends MLNode {
|
|
19
|
+
constructor(astToken,
|
|
15
20
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
16
21
|
ownElement) {
|
|
17
|
-
var _a, _b, _c, _d;
|
|
18
22
|
super(astToken, ownElement.ownerMLDocument);
|
|
19
23
|
this.endQuote = null;
|
|
20
24
|
this.equal = null;
|
|
@@ -35,32 +39,35 @@ class MLAttr extends node_1.MLNode {
|
|
|
35
39
|
* @implements `@markuplint/ml-core` API: `MLAttr`
|
|
36
40
|
*/
|
|
37
41
|
this.valueType = 'string';
|
|
38
|
-
if (this._astToken.type === 'html-attr') {
|
|
39
|
-
this.spacesBeforeName = new token_1.MLToken(this._astToken.spacesBeforeName);
|
|
40
|
-
this.nameNode = new token_1.MLToken(this._astToken.name);
|
|
41
|
-
this.spacesBeforeEqual = new token_1.MLToken(this._astToken.spacesBeforeEqual);
|
|
42
|
-
this.equal = new token_1.MLToken(this._astToken.equal);
|
|
43
|
-
this.spacesAfterEqual = new token_1.MLToken(this._astToken.spacesAfterEqual);
|
|
44
|
-
this.startQuote = new token_1.MLToken(this._astToken.startQuote);
|
|
45
|
-
this.valueNode = new token_1.MLToken(this._astToken.value);
|
|
46
|
-
this.endQuote = new token_1.MLToken(this._astToken.endQuote);
|
|
47
|
-
this.isDynamicValue = this._astToken.isDynamicValue;
|
|
48
|
-
this.isDirective = this._astToken.isDirective;
|
|
49
|
-
this.candidate = this._astToken.candidate;
|
|
50
|
-
tslib_1.__classPrivateFieldSet(this, _MLAttr_potentialName, (_c = (_a = this._astToken.potentialName) !== null && _a !== void 0 ? _a : (_b = this.nameNode) === null || _b === void 0 ? void 0 : _b.raw) !== null && _c !== void 0 ? _c : '', "f");
|
|
51
|
-
tslib_1.__classPrivateFieldSet(this, _MLAttr_potentialValue, (_d = this._astToken.value.raw) !== null && _d !== void 0 ? _d : '', "f");
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
this.valueType = this._astToken.valueType;
|
|
55
|
-
this.isDuplicatable = this._astToken.isDuplicatable;
|
|
56
|
-
tslib_1.__classPrivateFieldSet(this, _MLAttr_potentialName, this._astToken.potentialName, "f");
|
|
57
|
-
tslib_1.__classPrivateFieldSet(this, _MLAttr_potentialValue, this._astToken.potentialValue, "f");
|
|
58
|
-
}
|
|
59
|
-
const ns = (0, ml_spec_1.resolveNamespace)(tslib_1.__classPrivateFieldGet(this, _MLAttr_potentialName, "f"), ownElement.namespaceURI);
|
|
60
|
-
tslib_1.__classPrivateFieldSet(this, _MLAttr_localName, ns.localName, "f");
|
|
61
|
-
tslib_1.__classPrivateFieldSet(this, _MLAttr_namespaceURI, ns.namespaceURI, "f");
|
|
62
42
|
this.ownerElement = ownElement;
|
|
43
|
+
if (this._astToken.type === 'spread') {
|
|
44
|
+
__classPrivateFieldSet(this, _MLAttr_namespaceURI, ownElement.namespaceURI, "f");
|
|
45
|
+
this.valueType = 'code';
|
|
46
|
+
__classPrivateFieldSet(this, _MLAttr_localName, '#spread', "f");
|
|
47
|
+
__classPrivateFieldSet(this, _MLAttr_potentialName, '#spread', "f");
|
|
48
|
+
__classPrivateFieldSet(this, _MLAttr_potentialValue, this._astToken.raw, "f");
|
|
49
|
+
this.isDirective = true;
|
|
50
|
+
this.isDynamicValue = true;
|
|
51
|
+
this.isDuplicatable = true;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
this.spacesBeforeName = new MLToken(this._astToken.spacesBeforeName);
|
|
55
|
+
this.nameNode = new MLToken(this._astToken.name);
|
|
56
|
+
this.spacesBeforeEqual = new MLToken(this._astToken.spacesBeforeEqual);
|
|
57
|
+
this.equal = new MLToken(this._astToken.equal);
|
|
58
|
+
this.spacesAfterEqual = new MLToken(this._astToken.spacesAfterEqual);
|
|
59
|
+
this.startQuote = new MLToken(this._astToken.startQuote);
|
|
60
|
+
this.valueNode = new MLToken(this._astToken.value);
|
|
61
|
+
this.endQuote = new MLToken(this._astToken.endQuote);
|
|
62
|
+
this.isDynamicValue = this._astToken.isDynamicValue;
|
|
63
|
+
this.isDirective = this._astToken.isDirective;
|
|
64
|
+
this.candidate = this._astToken.candidate;
|
|
65
|
+
__classPrivateFieldSet(this, _MLAttr_potentialName, this._astToken.potentialName ?? this.nameNode?.raw ?? '', "f");
|
|
66
|
+
__classPrivateFieldSet(this, _MLAttr_potentialValue, this._astToken.potentialValue ?? this.valueNode?.raw ?? '', "f");
|
|
63
67
|
this.isDuplicatable = this._astToken.isDuplicatable;
|
|
68
|
+
const ns = resolveNamespace(__classPrivateFieldGet(this, _MLAttr_potentialName, "f"), ownElement.namespaceURI);
|
|
69
|
+
__classPrivateFieldSet(this, _MLAttr_localName, ns.localName, "f");
|
|
70
|
+
__classPrivateFieldSet(this, _MLAttr_namespaceURI, ns.namespaceURI, "f");
|
|
64
71
|
}
|
|
65
72
|
/**
|
|
66
73
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -70,7 +77,7 @@ class MLAttr extends node_1.MLNode {
|
|
|
70
77
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-attr-localname
|
|
71
78
|
*/
|
|
72
79
|
get localName() {
|
|
73
|
-
return
|
|
80
|
+
return __classPrivateFieldGet(this, _MLAttr_localName, "f");
|
|
74
81
|
}
|
|
75
82
|
/**
|
|
76
83
|
*
|
|
@@ -78,7 +85,7 @@ class MLAttr extends node_1.MLNode {
|
|
|
78
85
|
* @see https://dom.spec.whatwg.org/#dom-attr-name
|
|
79
86
|
*/
|
|
80
87
|
get name() {
|
|
81
|
-
return
|
|
88
|
+
return __classPrivateFieldGet(this, _MLAttr_potentialName, "f");
|
|
82
89
|
}
|
|
83
90
|
/**
|
|
84
91
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -88,7 +95,7 @@ class MLAttr extends node_1.MLNode {
|
|
|
88
95
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-attr-namespaceuri
|
|
89
96
|
*/
|
|
90
97
|
get namespaceURI() {
|
|
91
|
-
return
|
|
98
|
+
return __classPrivateFieldGet(this, _MLAttr_namespaceURI, "f");
|
|
92
99
|
}
|
|
93
100
|
/**
|
|
94
101
|
* Returns a string appropriate for the type of node as `Attr`
|
|
@@ -115,7 +122,7 @@ class MLAttr extends node_1.MLNode {
|
|
|
115
122
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-attr-prefix
|
|
116
123
|
*/
|
|
117
124
|
get prefix() {
|
|
118
|
-
throw new
|
|
125
|
+
throw new UnexpectedCallError('Not supported "prefix" property');
|
|
119
126
|
}
|
|
120
127
|
/**
|
|
121
128
|
* @implements `@markuplint/ml-core` API: `MLAttr`
|
|
@@ -134,28 +141,64 @@ class MLAttr extends node_1.MLNode {
|
|
|
134
141
|
* @implements `@markuplint/ml-core` API: `MLAttr`
|
|
135
142
|
*/
|
|
136
143
|
get tokenList() {
|
|
137
|
-
return this.isDynamicValue ? null : new
|
|
144
|
+
return this.isDynamicValue ? null : new MLDomTokenList(this.value, [this]);
|
|
138
145
|
}
|
|
139
146
|
/**
|
|
140
147
|
* @implements DOM API: `Attr`
|
|
141
148
|
* @see https://dom.spec.whatwg.org/#dom-attr-value
|
|
142
149
|
*/
|
|
143
150
|
get value() {
|
|
144
|
-
return
|
|
151
|
+
return __classPrivateFieldGet(this, _MLAttr_potentialValue, "f");
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Fixes the attribute value.
|
|
155
|
+
* If the attribute is not a spread attribute, it calls the `fix` method of the `valueNode`.
|
|
156
|
+
*
|
|
157
|
+
* @implements `@markuplint/ml-core` API: `MLAttr`
|
|
158
|
+
*
|
|
159
|
+
* @param raw - The raw attribute value.
|
|
160
|
+
*/
|
|
161
|
+
fix(raw) {
|
|
162
|
+
if (this.localName === '#spread') {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
// `valueNode` is not null when it is no spread.
|
|
166
|
+
this.valueNode?.fix(raw);
|
|
145
167
|
}
|
|
146
168
|
/**
|
|
147
169
|
* @implements `@markuplint/ml-core` API: `MLAttr`
|
|
148
170
|
*/
|
|
149
171
|
toNormalizeString() {
|
|
150
172
|
if (this.nameNode && this.equal && this.startQuote && this.valueNode && this.endQuote) {
|
|
151
|
-
return
|
|
152
|
-
this.equal.originRaw +
|
|
153
|
-
this.startQuote.originRaw +
|
|
154
|
-
this.valueNode.originRaw +
|
|
155
|
-
this.endQuote.originRaw);
|
|
173
|
+
return this.nameNode.raw + this.equal.raw + this.startQuote.raw + this.valueNode.raw + this.endQuote.raw;
|
|
156
174
|
}
|
|
157
175
|
return this.raw;
|
|
158
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* Returns a string representation of the attribute.
|
|
179
|
+
*
|
|
180
|
+
* @implements DOM API: `Attr`
|
|
181
|
+
*
|
|
182
|
+
* @param includesSpacesBeforeName - Whether to include spaces before the attribute name.
|
|
183
|
+
* @returns The string representation of the attribute.
|
|
184
|
+
*/
|
|
185
|
+
toString(fixed = false) {
|
|
186
|
+
if (!fixed) {
|
|
187
|
+
return this.raw;
|
|
188
|
+
}
|
|
189
|
+
if (this.localName === '#spread') {
|
|
190
|
+
return this.raw;
|
|
191
|
+
}
|
|
192
|
+
const tokens = [this.nameNode?.toString(true) ?? ''];
|
|
193
|
+
if (this.equal && this.equal.toString(true) !== '') {
|
|
194
|
+
tokens.push(this.spacesBeforeEqual?.toString(true) ?? '', this.equal?.toString(true) ?? '', this.spacesAfterEqual?.toString(true) ?? '', this.startQuote?.toString(true) ?? '', this.valueNode?.toString(true) ?? '', this.endQuote?.toString(true) ?? '');
|
|
195
|
+
}
|
|
196
|
+
else if (this.valueNode && this.valueNode.toString(true) !== '') {
|
|
197
|
+
tokens.push(
|
|
198
|
+
//
|
|
199
|
+
'=', this.startQuote?.toString(true) || '"', this.valueNode.toString(true), this.endQuote?.toString(true) || '"');
|
|
200
|
+
}
|
|
201
|
+
return tokens.join('');
|
|
202
|
+
}
|
|
159
203
|
}
|
|
160
|
-
exports.MLAttr = MLAttr;
|
|
161
204
|
_MLAttr_localName = new WeakMap(), _MLAttr_namespaceURI = new WeakMap(), _MLAttr_potentialName = new WeakMap(), _MLAttr_potentialValue = new WeakMap();
|
|
@@ -1,42 +1,38 @@
|
|
|
1
|
-
import type { MLDocument } from './document';
|
|
2
|
-
import type { MLElement } from './element';
|
|
3
|
-
import type { MarkuplintPreprocessorBlockType } from './types';
|
|
1
|
+
import type { MLDocument } from './document.js';
|
|
2
|
+
import type { MLElement } from './element.js';
|
|
3
|
+
import type { MarkuplintPreprocessorBlockType } from './types.js';
|
|
4
4
|
import type { MLASTPreprocessorSpecificBlock } from '@markuplint/ml-ast';
|
|
5
5
|
import type { PlainData, RuleConfigValue } from '@markuplint/ml-config';
|
|
6
|
-
import { MLNode } from './node';
|
|
7
|
-
export declare class MLBlock<T extends RuleConfigValue, O extends PlainData = undefined> extends MLNode<
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* @implements DOM API: `ChildNode`
|
|
40
|
-
*/
|
|
41
|
-
replaceWith(...nodes: (string | MLElement<any, any>)[]): void;
|
|
6
|
+
import { MLNode } from './node.js';
|
|
7
|
+
export declare class MLBlock<T extends RuleConfigValue, O extends PlainData = undefined> extends MLNode<T, O, MLASTPreprocessorSpecificBlock> {
|
|
8
|
+
readonly isTransparent: boolean;
|
|
9
|
+
constructor(astNode: MLASTPreprocessorSpecificBlock, document: MLDocument<T, O>);
|
|
10
|
+
/**
|
|
11
|
+
* Returns a string appropriate for the type of node as `MLBlock`
|
|
12
|
+
*
|
|
13
|
+
* @implements `@markuplint/ml-core` API: `MLBlock`
|
|
14
|
+
*/
|
|
15
|
+
get nodeName(): "#ml-block";
|
|
16
|
+
/**
|
|
17
|
+
* Returns a number appropriate for the type of `MLBlock`
|
|
18
|
+
*
|
|
19
|
+
* @implements `@markuplint/ml-core` API: `MLBlock`
|
|
20
|
+
*/
|
|
21
|
+
get nodeType(): MarkuplintPreprocessorBlockType;
|
|
22
|
+
/**
|
|
23
|
+
* @implements DOM API: `ChildNode`
|
|
24
|
+
*/
|
|
25
|
+
after(...nodes: (string | MLElement<any, any>)[]): void;
|
|
26
|
+
/**
|
|
27
|
+
* @implements DOM API: `ChildNode`
|
|
28
|
+
*/
|
|
29
|
+
before(...nodes: (string | MLElement<any, any>)[]): void;
|
|
30
|
+
/**
|
|
31
|
+
* @implements DOM API: `ChildNode`
|
|
32
|
+
*/
|
|
33
|
+
remove(): void;
|
|
34
|
+
/**
|
|
35
|
+
* @implements DOM API: `ChildNode`
|
|
36
|
+
*/
|
|
37
|
+
replaceWith(...nodes: (string | MLElement<any, any>)[]): void;
|
|
42
38
|
}
|
package/lib/ml-dom/node/block.js
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const node_1 = require("./node");
|
|
6
|
-
class MLBlock extends node_1.MLNode {
|
|
7
|
-
constructor(
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
9
|
-
astNode,
|
|
1
|
+
import { after, before, remove, replaceWith } from '../manipulations/child-node-methods.js';
|
|
2
|
+
import { MLNode } from './node.js';
|
|
3
|
+
export class MLBlock extends MLNode {
|
|
4
|
+
constructor(astNode,
|
|
10
5
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
11
6
|
document) {
|
|
12
7
|
super(astNode, document);
|
|
@@ -35,7 +30,7 @@ class MLBlock extends node_1.MLNode {
|
|
|
35
30
|
after(
|
|
36
31
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
37
32
|
...nodes) {
|
|
38
|
-
|
|
33
|
+
after(this, ...nodes);
|
|
39
34
|
}
|
|
40
35
|
/**
|
|
41
36
|
* @implements DOM API: `ChildNode`
|
|
@@ -43,13 +38,13 @@ class MLBlock extends node_1.MLNode {
|
|
|
43
38
|
before(
|
|
44
39
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
45
40
|
...nodes) {
|
|
46
|
-
|
|
41
|
+
before(this, ...nodes);
|
|
47
42
|
}
|
|
48
43
|
/**
|
|
49
44
|
* @implements DOM API: `ChildNode`
|
|
50
45
|
*/
|
|
51
46
|
remove() {
|
|
52
|
-
|
|
47
|
+
remove(this);
|
|
53
48
|
}
|
|
54
49
|
/**
|
|
55
50
|
* @implements DOM API: `ChildNode`
|
|
@@ -57,7 +52,6 @@ class MLBlock extends node_1.MLNode {
|
|
|
57
52
|
replaceWith(
|
|
58
53
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
59
54
|
...nodes) {
|
|
60
|
-
|
|
55
|
+
replaceWith(this, ...nodes);
|
|
61
56
|
}
|
|
62
57
|
}
|
|
63
|
-
exports.MLBlock = MLBlock;
|