@markuplint/ml-core 4.0.0-alpha.6 → 4.0.0-alpha.7
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/ml-dom/node/document.js +0 -3
- package/lib/ml-dom/node/element.d.ts +8 -1
- package/lib/ml-dom/node/element.js +17 -9
- package/package.json +12 -12
package/LICENSE
CHANGED
|
@@ -2141,9 +2141,6 @@ export class MLDocument extends MLParentNode {
|
|
|
2141
2141
|
if (docLog.enabled) {
|
|
2142
2142
|
docLog('Pretending: %O', pretenders);
|
|
2143
2143
|
}
|
|
2144
|
-
if (!pretenders) {
|
|
2145
|
-
return;
|
|
2146
|
-
}
|
|
2147
2144
|
for (const node of this.nodeList) {
|
|
2148
2145
|
if (node.is(node.ELEMENT_NODE)) {
|
|
2149
2146
|
node.pretending(pretenders);
|
|
@@ -12,6 +12,13 @@ import { MLParentNode } from './parent-node.js';
|
|
|
12
12
|
export declare class MLElement<T extends RuleConfigValue, O extends PlainData = undefined> extends MLParentNode<T, O, MLASTElement> implements Element, HTMLOrSVGElement, HTMLElement {
|
|
13
13
|
#private;
|
|
14
14
|
readonly closeTag: MLToken | null;
|
|
15
|
+
/**
|
|
16
|
+
* Element type
|
|
17
|
+
*
|
|
18
|
+
* - `html`: From native HTML Standard
|
|
19
|
+
* - `web-component`: As the Web Component according to HTML Standard
|
|
20
|
+
* - `authored`: Authored element (JSX Element etc.) through the view framework or the template engine.
|
|
21
|
+
*/
|
|
15
22
|
readonly elementType: ElementType;
|
|
16
23
|
readonly endSpace: MLToken | null;
|
|
17
24
|
readonly hasSpreadAttr: boolean;
|
|
@@ -1781,7 +1788,7 @@ export declare class MLElement<T extends RuleConfigValue, O extends PlainData =
|
|
|
1781
1788
|
/**
|
|
1782
1789
|
* Pretenders Initialization
|
|
1783
1790
|
*/
|
|
1784
|
-
pretending(pretenders
|
|
1791
|
+
pretending(pretenders?: readonly Pretender[]): void;
|
|
1785
1792
|
/**
|
|
1786
1793
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
1787
1794
|
*
|
|
@@ -2454,24 +2454,32 @@ export class MLElement extends MLParentNode {
|
|
|
2454
2454
|
*/
|
|
2455
2455
|
pretending(pretenders) {
|
|
2456
2456
|
const pretenderConfig = pretenders?.find(option => this.matches(option.selector));
|
|
2457
|
-
|
|
2457
|
+
const asAttrValue = this.getAttribute('as');
|
|
2458
|
+
const pretenderElement = pretenderConfig?.as ??
|
|
2459
|
+
(this.elementType === 'html' || !asAttrValue
|
|
2460
|
+
? null
|
|
2461
|
+
: {
|
|
2462
|
+
element: asAttrValue,
|
|
2463
|
+
inheritAttrs: true,
|
|
2464
|
+
});
|
|
2465
|
+
if (pretenderElement == null) {
|
|
2458
2466
|
return;
|
|
2459
2467
|
}
|
|
2460
2468
|
let nodeName;
|
|
2461
2469
|
let namespace = 'html';
|
|
2462
2470
|
const attributes = [];
|
|
2463
2471
|
let aria;
|
|
2464
|
-
if (typeof
|
|
2465
|
-
nodeName =
|
|
2472
|
+
if (typeof pretenderElement === 'string') {
|
|
2473
|
+
nodeName = pretenderElement;
|
|
2466
2474
|
}
|
|
2467
2475
|
else {
|
|
2468
|
-
nodeName =
|
|
2469
|
-
namespace =
|
|
2470
|
-
if (
|
|
2476
|
+
nodeName = pretenderElement.element;
|
|
2477
|
+
namespace = pretenderElement.namespace ?? namespace;
|
|
2478
|
+
if (pretenderElement.inheritAttrs) {
|
|
2471
2479
|
attributes.push(...this._astToken.attributes);
|
|
2472
2480
|
}
|
|
2473
|
-
if (
|
|
2474
|
-
attributes.push(...
|
|
2481
|
+
if (pretenderElement.attrs) {
|
|
2482
|
+
attributes.push(...pretenderElement.attrs.map(({ name, value }, i) => {
|
|
2475
2483
|
const _value = value == null
|
|
2476
2484
|
? ''
|
|
2477
2485
|
: typeof value === 'string'
|
|
@@ -2523,7 +2531,7 @@ export class MLElement extends MLParentNode {
|
|
|
2523
2531
|
};
|
|
2524
2532
|
}));
|
|
2525
2533
|
}
|
|
2526
|
-
aria =
|
|
2534
|
+
aria = pretenderElement.aria;
|
|
2527
2535
|
}
|
|
2528
2536
|
const as = new MLElement({
|
|
2529
2537
|
...this._astToken,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/ml-core",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.7",
|
|
4
4
|
"description": "The core module of markuplint",
|
|
5
5
|
"repository": "git@github.com:markuplint/markuplint.git",
|
|
6
6
|
"author": "Yusuke Hirao <yusukehirao@me.com>",
|
|
@@ -28,19 +28,19 @@
|
|
|
28
28
|
"./lib/configs.js": "./lib/configs.browser.js"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@markuplint/config-presets": "4.0.0-alpha.
|
|
32
|
-
"@markuplint/html-parser": "4.0.0-alpha.
|
|
33
|
-
"@markuplint/html-spec": "4.0.0-alpha.
|
|
34
|
-
"@markuplint/i18n": "4.0.0-alpha.
|
|
35
|
-
"@markuplint/ml-ast": "4.0.0-alpha.
|
|
36
|
-
"@markuplint/ml-config": "4.0.0-alpha.
|
|
37
|
-
"@markuplint/ml-spec": "4.0.0-alpha.
|
|
38
|
-
"@markuplint/parser-utils": "4.0.0-alpha.
|
|
39
|
-
"@markuplint/selector": "4.0.0-alpha.
|
|
31
|
+
"@markuplint/config-presets": "4.0.0-alpha.7",
|
|
32
|
+
"@markuplint/html-parser": "4.0.0-alpha.7",
|
|
33
|
+
"@markuplint/html-spec": "4.0.0-alpha.7",
|
|
34
|
+
"@markuplint/i18n": "4.0.0-alpha.7",
|
|
35
|
+
"@markuplint/ml-ast": "4.0.0-alpha.7",
|
|
36
|
+
"@markuplint/ml-config": "4.0.0-alpha.7",
|
|
37
|
+
"@markuplint/ml-spec": "4.0.0-alpha.7",
|
|
38
|
+
"@markuplint/parser-utils": "4.0.0-alpha.7",
|
|
39
|
+
"@markuplint/selector": "4.0.0-alpha.7",
|
|
40
40
|
"@types/debug": "^4.1.12",
|
|
41
41
|
"debug": "^4.3.4",
|
|
42
42
|
"is-plain-object": "^5.0.0",
|
|
43
|
-
"type-fest": "^4.
|
|
43
|
+
"type-fest": "^4.9.0"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "571129bf6498541125e1e7c3907d5ed9af53459a"
|
|
46
46
|
}
|