@ibyar/elements 0.4.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -0
- package/ast/dom.d.ts +32 -24
- package/ast/dom.js +41 -30
- package/ast/dom.js.map +1 -1
- package/ast/factory.d.ts +6 -6
- package/ast/factory.js +40 -22
- package/ast/factory.js.map +1 -1
- package/attributes/attributes.d.ts +1 -0
- package/attributes/attributes.js +6 -0
- package/attributes/attributes.js.map +1 -1
- package/directives/register-directive.d.ts +37 -0
- package/directives/register-directive.js +97 -0
- package/directives/register-directive.js.map +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/index.js.map +1 -1
- package/node/html-parser.d.ts +9 -6
- package/node/html-parser.js +122 -33
- package/node/html-parser.js.map +1 -1
- package/package.json +3 -3
- package/template/template-parser.d.ts +4 -4
- package/template/template-parser.js +5 -5
- package/template/template-parser.js.map +1 -1
package/README.md
CHANGED
|
@@ -50,3 +50,64 @@ console.log(htmlNode);
|
|
|
50
50
|
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
+
`By default the parser has no registered info about structural/attributes directive.`
|
|
54
|
+
|
|
55
|
+
You need to register them with inputs and outputs.
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { directiveRegistry } from '@ibyar/elements';
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* register a structural directive, with name '*notifier' , the name must start with '*'.
|
|
63
|
+
* with inputs `message` and `color`,
|
|
64
|
+
* and output `action`.
|
|
65
|
+
*/
|
|
66
|
+
directiveRegistry.register('*notifier', {
|
|
67
|
+
inputs: ['message', 'color'],
|
|
68
|
+
outputs: ['action'],
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* register an attributes directive with name 'appConfirm'
|
|
73
|
+
*/
|
|
74
|
+
directiveRegistry.register('appConfirm', {
|
|
75
|
+
inputs: [],
|
|
76
|
+
outputs: [],
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### note:
|
|
82
|
+
|
|
83
|
+
the attributes directive has higher priority than regular element attributes,
|
|
84
|
+
so if you registered an attributes directive with a name like 'style', 'class', 'id', 'name', etc...
|
|
85
|
+
it will interpreted as an attributes directive and will be remove from the element attributes list.
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
import { directiveRegistry } from '@ibyar/elements';
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* register an attributes directive with no input and no output.
|
|
93
|
+
*/
|
|
94
|
+
directiveRegistry.register('style');
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## supported syntax for directives
|
|
99
|
+
|
|
100
|
+
```html
|
|
101
|
+
<!-- short hand -->
|
|
102
|
+
<div *for="let user of users"></div>
|
|
103
|
+
<div *if="user.name == 'ali'"></div>
|
|
104
|
+
|
|
105
|
+
<!-- full description -->
|
|
106
|
+
<div *for let-user [of]="users"></div>
|
|
107
|
+
<div *if [if]="user.name == 'ali'"></div>
|
|
108
|
+
|
|
109
|
+
<!-- tag name as directive -->
|
|
110
|
+
<for let-user [of]="user">....</for>
|
|
111
|
+
<if [if]="user.name == 'ali'">....</if>
|
|
112
|
+
|
|
113
|
+
```
|
package/ast/dom.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export declare class ElementAttribute<N, V> extends Attribute<N, V> {
|
|
|
7
7
|
}
|
|
8
8
|
export declare class LiveAttribute extends Attribute<string, string> {
|
|
9
9
|
}
|
|
10
|
+
export declare function createLiveAttribute(name: string, value: string): LiveAttribute;
|
|
10
11
|
export declare class TextContent extends Attribute<'textContent', string> {
|
|
11
12
|
static propName: 'textContent';
|
|
12
13
|
constructor(text: string);
|
|
@@ -18,42 +19,49 @@ export declare class CommentNode {
|
|
|
18
19
|
comment: string;
|
|
19
20
|
constructor(comment: string);
|
|
20
21
|
}
|
|
21
|
-
export declare class
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
export declare class BaseNode extends DOMParentNode {
|
|
30
|
-
attributes: ElementAttribute<string, string | number | boolean | object>[];
|
|
31
|
-
inputs: LiveAttribute[];
|
|
32
|
-
outputs: ElementAttribute<string, string>[];
|
|
33
|
-
twoWayBinding: LiveAttribute[];
|
|
34
|
-
templateAttrs: LiveAttribute[];
|
|
22
|
+
export declare class BaseNode {
|
|
23
|
+
attributes?: ElementAttribute<string, string | number | boolean | object>[];
|
|
24
|
+
inputs?: LiveAttribute[];
|
|
25
|
+
outputs?: ElementAttribute<string, string>[];
|
|
26
|
+
twoWayBinding?: LiveAttribute[];
|
|
27
|
+
templateAttrs?: LiveAttribute[];
|
|
28
|
+
attributeDirectives?: DomAttributeDirectiveNode[];
|
|
35
29
|
addAttribute(attrName: string, value?: string | number | boolean | object): void;
|
|
36
30
|
addInput(attrName: string, valueSource: string): void;
|
|
37
31
|
addOutput(eventName: string, handlerSource: string): void;
|
|
38
32
|
addTwoWayBinding(eventName: string, handlerSource: string): void;
|
|
39
33
|
addTemplateAttr(attrName: string, valueSource: string): void;
|
|
40
34
|
}
|
|
41
|
-
export declare class
|
|
35
|
+
export declare class DomAttributeDirectiveNode extends BaseNode {
|
|
36
|
+
name: string;
|
|
37
|
+
attributeDirectives: undefined;
|
|
38
|
+
constructor(name: string);
|
|
39
|
+
}
|
|
40
|
+
export declare class DomParentNode extends BaseNode {
|
|
41
|
+
children?: DomChild[];
|
|
42
|
+
addChild(child: DomChild): void;
|
|
43
|
+
addTextChild(text: string): void;
|
|
44
|
+
}
|
|
45
|
+
export declare class DomFragmentNode extends DomParentNode {
|
|
46
|
+
constructor(children?: DomChild[]);
|
|
47
|
+
}
|
|
48
|
+
export declare class DomElementNode extends DomParentNode {
|
|
42
49
|
tagName: string;
|
|
43
50
|
is?: string;
|
|
44
|
-
templateRefName
|
|
51
|
+
templateRefName?: Attribute<string, string | undefined>;
|
|
45
52
|
constructor(tagName: string, is?: string);
|
|
46
53
|
setTagName(tagName: string): void;
|
|
47
54
|
setTemplateRefName(name: string, value?: string): void;
|
|
48
55
|
}
|
|
49
|
-
export declare class
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
node:
|
|
53
|
-
constructor(
|
|
56
|
+
export declare class DomStructuralDirectiveNode extends BaseNode {
|
|
57
|
+
name: string;
|
|
58
|
+
value?: string;
|
|
59
|
+
node: DomNode;
|
|
60
|
+
constructor(name: string, node: DomNode, value?: string);
|
|
54
61
|
}
|
|
55
|
-
export declare
|
|
56
|
-
export declare type
|
|
57
|
-
export declare type
|
|
62
|
+
export declare function isDOMDirectiveNode(node: object): node is DomStructuralDirectiveNode;
|
|
63
|
+
export declare type DomChild = DomElementNode | DomStructuralDirectiveNode | CommentNode | TextContent | LiveTextContent;
|
|
64
|
+
export declare type DomNode = DomFragmentNode | DomElementNode | DomStructuralDirectiveNode | CommentNode | TextContent | LiveTextContent;
|
|
65
|
+
export declare type DomRenderNode<T> = (model: T) => DomNode;
|
|
58
66
|
export declare function parseTextChild(text: string): Array<TextContent | LiveTextContent>;
|
|
59
67
|
export declare function parseStringTemplate(text: string): string;
|
package/ast/dom.js
CHANGED
|
@@ -8,6 +8,9 @@ export class ElementAttribute extends Attribute {
|
|
|
8
8
|
}
|
|
9
9
|
export class LiveAttribute extends Attribute {
|
|
10
10
|
}
|
|
11
|
+
export function createLiveAttribute(name, value) {
|
|
12
|
+
return new LiveAttribute(name, value);
|
|
13
|
+
}
|
|
11
14
|
export class TextContent extends Attribute {
|
|
12
15
|
constructor(text) {
|
|
13
16
|
super(TextContent.propName, text);
|
|
@@ -24,31 +27,7 @@ export class CommentNode {
|
|
|
24
27
|
this.comment = comment;
|
|
25
28
|
}
|
|
26
29
|
}
|
|
27
|
-
export class
|
|
28
|
-
addChild(child) {
|
|
29
|
-
if (this.children) {
|
|
30
|
-
this.children.push(child);
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
this.children = [child];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
addTextChild(text) {
|
|
37
|
-
if (!this.children) {
|
|
38
|
-
this.children = [];
|
|
39
|
-
}
|
|
40
|
-
parseTextChild(text).forEach(childText => this.children.push(childText));
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
export class DOMFragmentNode extends DOMParentNode {
|
|
44
|
-
constructor(children) {
|
|
45
|
-
super();
|
|
46
|
-
if (children) {
|
|
47
|
-
this.children = children;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
export class BaseNode extends DOMParentNode {
|
|
30
|
+
export class BaseNode {
|
|
52
31
|
addAttribute(attrName, value) {
|
|
53
32
|
if (this.attributes) {
|
|
54
33
|
this.attributes.push(new ElementAttribute(attrName, value ?? true));
|
|
@@ -99,7 +78,35 @@ export class BaseNode extends DOMParentNode {
|
|
|
99
78
|
}
|
|
100
79
|
}
|
|
101
80
|
}
|
|
102
|
-
export class
|
|
81
|
+
export class DomAttributeDirectiveNode extends BaseNode {
|
|
82
|
+
constructor(name) {
|
|
83
|
+
super();
|
|
84
|
+
this.name = name;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
export class DomParentNode extends BaseNode {
|
|
88
|
+
addChild(child) {
|
|
89
|
+
if (this.children) {
|
|
90
|
+
this.children.push(child);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
this.children = [child];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
addTextChild(text) {
|
|
97
|
+
const children = (this.children ??= []);
|
|
98
|
+
parseTextChild(text).forEach(childText => children.push(childText));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
export class DomFragmentNode extends DomParentNode {
|
|
102
|
+
constructor(children) {
|
|
103
|
+
super();
|
|
104
|
+
if (children) {
|
|
105
|
+
this.children = children;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
export class DomElementNode extends DomParentNode {
|
|
103
110
|
constructor(tagName, is) {
|
|
104
111
|
super();
|
|
105
112
|
this.tagName = tagName;
|
|
@@ -114,13 +121,17 @@ export class DOMElementNode extends BaseNode {
|
|
|
114
121
|
this.templateRefName = new Attribute(name, value);
|
|
115
122
|
}
|
|
116
123
|
}
|
|
117
|
-
export class
|
|
118
|
-
constructor(
|
|
119
|
-
|
|
120
|
-
this.
|
|
124
|
+
export class DomStructuralDirectiveNode extends BaseNode {
|
|
125
|
+
constructor(name, node, value) {
|
|
126
|
+
super();
|
|
127
|
+
this.name = name;
|
|
121
128
|
this.node = node;
|
|
129
|
+
this.value = value;
|
|
122
130
|
}
|
|
123
131
|
}
|
|
132
|
+
export function isDOMDirectiveNode(node) {
|
|
133
|
+
return node instanceof DomStructuralDirectiveNode;
|
|
134
|
+
}
|
|
124
135
|
export function parseTextChild(text) {
|
|
125
136
|
let all = [];
|
|
126
137
|
let temp = text;
|
package/ast/dom.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dom.js","sourceRoot":"","sources":["../../../src/elements/ast/dom.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,SAAS;IACrB,YAAmB,IAAO,EAAS,KAAQ;QAAxB,SAAI,GAAJ,IAAI,CAAG;QAAS,UAAK,GAAL,KAAK,CAAG;IAAI,CAAC;CAChD;AAED,MAAM,OAAO,gBAAuB,SAAQ,SAAe;CAAI;AAK/D,MAAM,OAAO,aAAc,SAAQ,SAAyB;CAAI;AAKhE,MAAM,OAAO,WAAY,SAAQ,SAAgC;IAEhE,YAAY,IAAY;QACvB,KAAK,CAAC,WAAW,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC;;AAHM,oBAAQ,GAAkB,aAAa,CAAC;AAShD,MAAM,OAAO,eAAgB,SAAQ,WAAW;CAAI;AAEpD,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC7C,OAAO,IAAI,YAAY,eAAe,CAAC;AAC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CAAC,CAAC,EAAE;YACf,IAAI,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;YACxC,IAAI,QAAQ,EAAE;gBACb,GAAG,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC;aACpC;YACD,MAAM,QAAQ,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;YACtE,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACnB,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;YAChC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;SAC9B;aAAM;YACN,MAAM;SACN;KACD;IACD,IAAI,IAAI,EAAE;QACT,GAAG,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;KAChC;IACD,OAAO,GAAG,CAAC,OAAO,EAAE,CAAC;AACtB,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC/C,MAAM,IAAI,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;IAClC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,YAAY,eAAe,CAAC,CAAC,CAAC,IAAI,GAAG,GAAG,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC5G,OAAO,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AACxB,CAAC","sourcesContent":["\n/**\n * a normal attribute with its source value without any binding.\n */\nexport class Attribute<N, V> {\n\tconstructor(public name: N, public value: V) { }\n}\n\nexport class ElementAttribute<N, V> extends Attribute<N, V> { }\n\n/**\n * an attribute with its source value for binding\n */\nexport class LiveAttribute extends Attribute<string, string> { }\n\n/**\n * a normal text\n */\nexport class TextContent extends Attribute<'textContent', string> {\n\tstatic propName: 'textContent' = 'textContent';\n\tconstructor(text: string) {\n\t\tsuper(TextContent.propName, text);\n\t}\n}\n\n/**\n * a text that its content is binding to variable from the component model.\n */\nexport class LiveTextContent extends TextContent { }\n\nexport function isLiveTextContent(text: object): text is LiveTextContent {\n\treturn text instanceof LiveTextContent;\n}\n\n/**\n * to comment in dom\n */\nexport class CommentNode {\n\tconstructor(public comment: string) { }\n}\n\nexport class DOMParentNode {\n\t/**\n\t * element children list\n\t */\n\tchildren: DOMChild[];\n\n\taddChild(child: DOMChild) {\n\t\tif (this.children) {\n\t\t\tthis.children.push(child);\n\t\t} else {\n\t\t\tthis.children = [child];\n\t\t}\n\t}\n\n\taddTextChild(text: string) {\n\t\tif (!this.children) {\n\t\t\tthis.children = [];\n\t\t}\n\t\tparseTextChild(text).forEach(childText => this.children.push(childText));\n\t}\n\n}\n\n/**\n * parent for a list of elements \n */\nexport class DOMFragmentNode extends DOMParentNode {\n\tconstructor(children?: DOMChild[]) {\n\t\tsuper();\n\t\tif (children) {\n\t\t\tthis.children = children;\n\t\t}\n\t}\n}\n\nexport class BaseNode extends DOMParentNode {\n\n\t/**\n\t * hold static attr and event that will resolve normally from the global window.\n\t */\n\tattributes: ElementAttribute<string, string | number | boolean | object>[];\n\n\t/**\n\t * hold the attrs/inputs name marked as one way binding\n\t */\n\tinputs: LiveAttribute[];\n\n\t/**\n\t * hold the name of events that should be connected to a listener\n\t */\n\toutputs: ElementAttribute<string, string>[];\n\n\t/**\n\t * hold the name of attributes marked for 2 way data binding\n\t */\n\ttwoWayBinding: LiveAttribute[];\n\n\t/**\n\t * directive attribute\n\t */\n\ttemplateAttrs: LiveAttribute[];\n\n\taddAttribute(attrName: string, value?: string | number | boolean | object) {\n\t\tif (this.attributes) {\n\t\t\tthis.attributes.push(new ElementAttribute(attrName, value ?? true));\n\t\t} else {\n\t\t\tthis.attributes = [new ElementAttribute(attrName, value ?? true)];\n\t\t}\n\t}\n\n\taddInput(attrName: string, valueSource: string) {\n\t\tif (this.inputs) {\n\t\t\tthis.inputs.push(new LiveAttribute(attrName, valueSource));\n\t\t} else {\n\t\t\tthis.inputs = [new LiveAttribute(attrName, valueSource)];\n\t\t}\n\t}\n\n\taddOutput(eventName: string, handlerSource: string) {\n\t\tif (this.outputs) {\n\t\t\tthis.outputs.push(new LiveAttribute(eventName, handlerSource));\n\t\t} else {\n\t\t\tthis.outputs = [new LiveAttribute(eventName, handlerSource)];\n\t\t}\n\t}\n\n\taddTwoWayBinding(eventName: string, handlerSource: string) {\n\t\tif (this.twoWayBinding) {\n\t\t\tthis.twoWayBinding.push(new LiveAttribute(eventName, handlerSource));\n\t\t} else {\n\t\t\tthis.twoWayBinding = [new LiveAttribute(eventName, handlerSource)];\n\t\t}\n\t}\n\n\taddTemplateAttr(attrName: string, valueSource: string) {\n\t\tvalueSource = valueSource.trim();\n\t\tif (/^\\{\\{(.+)\\}\\}$/g.test(valueSource)) {\n\t\t\t// as one way binding\n\t\t\tconst substring = valueSource.substring(2, valueSource.length - 2);\n\t\t\tif (!(/\\{\\{(.+)\\}\\}/g).test(substring)) {\n\t\t\t\tthis.addInput(attrName, substring);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\t// as string \n\t\tvalueSource = parseStringTemplate(valueSource);\n\t\tif (this.templateAttrs) {\n\t\t\tthis.templateAttrs.push(new LiveAttribute(attrName, valueSource));\n\t\t} else {\n\t\t\tthis.templateAttrs = [new LiveAttribute(attrName, valueSource)];\n\t\t}\n\t}\n\n}\n\nexport class DOMElementNode extends BaseNode {\n\n\t/**\n\t * the tag name of the element \n\t */\n\ttagName: string;\n\n\t/**\n\t * used to upgrade an element to another custom-element name\n\t */\n\tis?: string;\n\n\t/**\n\t * a given name for element\n\t */\n\ttemplateRefName: Attribute<string, string | undefined>;\n\n\tconstructor(tagName: string, is?: string) {\n\t\tsuper();\n\t\tthis.tagName = tagName;\n\t\tif (is) {\n\t\t\tthis.is = is;\n\t\t}\n\t}\n\n\tsetTagName(tagName: string) {\n\t\tthis.tagName = tagName;\n\t}\n\n\tsetTemplateRefName(name: string, value?: string) {\n\t\tthis.templateRefName = new Attribute(name, value);\n\t}\n\n}\n\n\n/**\n * structural directive \n */\nexport class DOMDirectiveNode {\n\n\t/**\n\t * name of the directive \n\t */\n\tdirectiveName: string;\n\n\t/**\n\t * value of the directive \n\t */\n\tdirectiveValue: string;\n\n\t/**\n\t * the value of the template node, that this directive going to host-on \n\t */\n\tnode: DOMNode;\n\n\tconstructor(directiveName: string, directiveValue: string, node: DOMNode) {\n\t\tthis.directiveName = directiveName;\n\t\tthis.directiveValue = directiveValue;\n\t\tthis.node = node;\n\t}\n}\nexport type DOMChild = DOMElementNode | DOMDirectiveNode | CommentNode | TextContent | LiveTextContent;\n\nexport type DOMNode = DOMFragmentNode | DOMElementNode | DOMDirectiveNode | CommentNode | TextContent | LiveTextContent;\n\nexport type DOMRenderNode<T> = (model: T) => DOMNode;\n\nexport function parseTextChild(text: string): Array<TextContent | LiveTextContent> {\n\t// split from end with '}}', then search for the first '{{'\n\tlet all: (TextContent | LiveTextContent)[] = [];\n\tlet temp = text;\n\tlet last = temp.lastIndexOf('}}');\n\tlet first: number;\n\twhile (last > -1) {\n\t\tfirst = text.lastIndexOf('{{', last);\n\t\tif (first > -1) {\n\t\t\tlet lastPart = temp.substring(last + 2);\n\t\t\tif (lastPart) {\n\t\t\t\tall.push(new TextContent(lastPart));\n\t\t\t}\n\t\t\tconst liveText = new LiveTextContent(temp.substring(first + 2, last));\n\t\t\tall.push(liveText);\n\t\t\ttemp = temp.substring(0, first);\n\t\t\tlast = temp.lastIndexOf('}}');\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\tif (temp) {\n\t\tall.push(new TextContent(temp));\n\t}\n\treturn all.reverse();\n}\n\nexport function parseStringTemplate(text: string): string {\n\tconst node = parseTextChild(text);\n\tconst map = node.map(str => (str instanceof LiveTextContent ? '${' + str.value + '}' : str.value)).join('');\n\treturn '`' + map + '`';\n}\n"]}
|
|
1
|
+
{"version":3,"file":"dom.js","sourceRoot":"","sources":["../../../src/elements/ast/dom.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,SAAS;IACrB,YAAmB,IAAO,EAAS,KAAQ;QAAxB,SAAI,GAAJ,IAAI,CAAG;QAAS,UAAK,GAAL,KAAK,CAAG;IAAI,CAAC;CAChD;AAED,MAAM,OAAO,gBAAuB,SAAQ,SAAe;CAAI;AAK/D,MAAM,OAAO,aAAc,SAAQ,SAAyB;CAAI;AAQhE,MAAM,UAAU,mBAAmB,CAAC,IAAY,EAAE,KAAa;IAC9D,OAAO,IAAI,aAAa,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AACvC,CAAC;AAKD,MAAM,OAAO,WAAY,SAAQ,SAAgC;IAEhE,YAAY,IAAY;QACvB,KAAK,CAAC,WAAW,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC;;AAHM,oBAAQ,GAAkB,aAAa,CAAC;AAShD,MAAM,OAAO,eAAgB,SAAQ,WAAW;CAAI;AAEpD,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC7C,OAAO,IAAI,YAAY,eAAe,CAAC;AACxC,CAAC;AAKD,MAAM,OAAO,WAAW;IACvB,YAAmB,OAAe;QAAf,YAAO,GAAP,OAAO,CAAQ;IAAI,CAAC;CACvC;AAGD,MAAM,OAAO,QAAQ;IAgCpB,YAAY,CAAC,QAAgB,EAAE,KAA0C;QACxE,IAAI,IAAI,CAAC,UAAU,EAAE;YACpB,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,gBAAgB,CAAC,QAAQ,EAAE,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC;SACpE;aAAM;YACN,IAAI,CAAC,UAAU,GAAG,CAAC,IAAI,gBAAgB,CAAC,QAAQ,EAAE,KAAK,IAAI,IAAI,CAAC,CAAC,CAA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aACpC;YACD,MAAM,QAAQ,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;YACtE,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACnB,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;YAChC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;SAC9B;aAAM;YACN,MAAM;SACN;KACD;IACD,IAAI,IAAI,EAAE;QACT,GAAG,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;KAChC;IACD,OAAO,GAAG,CAAC,OAAO,EAAE,CAAC;AACtB,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC/C,MAAM,IAAI,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;IAClC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,YAAY,eAAe,CAAC,CAAC,CAAC,IAAI,GAAG,GAAG,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC5G,OAAO,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AACxB,CAAC","sourcesContent":["\n/**\n * a normal attribute with its source value without any binding.\n */\nexport class Attribute<N, V> {\n\tconstructor(public name: N, public value: V) { }\n}\n\nexport class ElementAttribute<N, V> extends Attribute<N, V> { }\n\n/**\n * an attribute with its source value for binding\n */\nexport class LiveAttribute extends Attribute<string, string> { }\n\n/**\n * \n * @param name \n * @param value \n * @returns LiveAttribute\n */\nexport function createLiveAttribute(name: string, value: string) {\n\treturn new LiveAttribute(name, value);\n}\n\n/**\n * a normal text\n */\nexport class TextContent extends Attribute<'textContent', string> {\n\tstatic propName: 'textContent' = 'textContent';\n\tconstructor(text: string) {\n\t\tsuper(TextContent.propName, text);\n\t}\n}\n\n/**\n * a text that its content is binding to variable from the component model.\n */\nexport class LiveTextContent extends TextContent { }\n\nexport function isLiveTextContent(text: object): text is LiveTextContent {\n\treturn text instanceof LiveTextContent;\n}\n\n/**\n * to comment in dom\n */\nexport class CommentNode {\n\tconstructor(public comment: string) { }\n}\n\n\nexport class BaseNode {\n\n\t/**\n\t * hold static attr and event that will resolve normally from the global window.\n\t */\n\tattributes?: ElementAttribute<string, string | number | boolean | object>[];\n\n\t/**\n\t * hold the attrs/inputs name marked as one way binding\n\t */\n\tinputs?: LiveAttribute[];\n\n\t/**\n\t * hold the name of events that should be connected to a listener\n\t */\n\toutputs?: ElementAttribute<string, string>[];\n\n\t/**\n\t * hold the name of attributes marked for 2 way data binding\n\t */\n\ttwoWayBinding?: LiveAttribute[];\n\n\t/**\n\t * directive attribute\n\t */\n\ttemplateAttrs?: LiveAttribute[];\n\n\t/**\n\t * attributes directive\n\t */\n\tattributeDirectives?: DomAttributeDirectiveNode[];\n\n\taddAttribute(attrName: string, value?: string | number | boolean | object) {\n\t\tif (this.attributes) {\n\t\t\tthis.attributes.push(new ElementAttribute(attrName, value ?? true));\n\t\t} else {\n\t\t\tthis.attributes = [new ElementAttribute(attrName, value ?? true)];\n\t\t}\n\t}\n\n\taddInput(attrName: string, valueSource: string) {\n\t\tif (this.inputs) {\n\t\t\tthis.inputs.push(new LiveAttribute(attrName, valueSource));\n\t\t} else {\n\t\t\tthis.inputs = [new LiveAttribute(attrName, valueSource)];\n\t\t}\n\t}\n\n\taddOutput(eventName: string, handlerSource: string) {\n\t\tif (this.outputs) {\n\t\t\tthis.outputs.push(new LiveAttribute(eventName, handlerSource));\n\t\t} else {\n\t\t\tthis.outputs = [new LiveAttribute(eventName, handlerSource)];\n\t\t}\n\t}\n\n\taddTwoWayBinding(eventName: string, handlerSource: string) {\n\t\tif (this.twoWayBinding) {\n\t\t\tthis.twoWayBinding.push(new LiveAttribute(eventName, handlerSource));\n\t\t} else {\n\t\t\tthis.twoWayBinding = [new LiveAttribute(eventName, handlerSource)];\n\t\t}\n\t}\n\n\taddTemplateAttr(attrName: string, valueSource: string) {\n\t\tvalueSource = valueSource.trim();\n\t\tif (/^\\{\\{(.+)\\}\\}$/g.test(valueSource)) {\n\t\t\t// as one way binding\n\t\t\tconst substring = valueSource.substring(2, valueSource.length - 2);\n\t\t\tif (!(/\\{\\{(.+)\\}\\}/g).test(substring)) {\n\t\t\t\tthis.addInput(attrName, substring);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\t// as string \n\t\tvalueSource = parseStringTemplate(valueSource);\n\t\tif (this.templateAttrs) {\n\t\t\tthis.templateAttrs.push(new LiveAttribute(attrName, valueSource));\n\t\t} else {\n\t\t\tthis.templateAttrs = [new LiveAttribute(attrName, valueSource)];\n\t\t}\n\t}\n\n}\nexport class DomAttributeDirectiveNode extends BaseNode {\n\n\t/**\n\t * name of the directive \n\t */\n\tname: string;\n\n\n\t/**\n\t * set to `undefined` stop, loop\n\t */\n\tattributeDirectives: undefined;\n\n\tconstructor(name: string) {\n\t\tsuper();\n\t\tthis.name = name;\n\t}\n}\n\nexport class DomParentNode extends BaseNode {\n\t/**\n\t * element children list\n\t */\n\tchildren?: DomChild[];\n\n\taddChild(child: DomChild) {\n\t\tif (this.children) {\n\t\t\tthis.children.push(child);\n\t\t} else {\n\t\t\tthis.children = [child];\n\t\t}\n\t}\n\n\taddTextChild(text: string) {\n\t\tconst children = (this.children ??= []);\n\t\tparseTextChild(text).forEach(childText => children.push(childText));\n\t}\n\n}\n\n/**\n * parent for a list of elements \n */\nexport class DomFragmentNode extends DomParentNode {\n\tconstructor(children?: DomChild[]) {\n\t\tsuper();\n\t\tif (children) {\n\t\t\tthis.children = children;\n\t\t}\n\t}\n}\nexport class DomElementNode extends DomParentNode {\n\n\t/**\n\t * the tag name of the element \n\t */\n\ttagName: string;\n\n\t/**\n\t * used to upgrade an element to another custom-element name\n\t */\n\tis?: string;\n\n\t/**\n\t * a given name for element\n\t */\n\ttemplateRefName?: Attribute<string, string | undefined>;\n\n\tconstructor(tagName: string, is?: string) {\n\t\tsuper();\n\t\tthis.tagName = tagName;\n\t\tif (is) {\n\t\t\tthis.is = is;\n\t\t}\n\t}\n\n\tsetTagName(tagName: string) {\n\t\tthis.tagName = tagName;\n\t}\n\n\tsetTemplateRefName(name: string, value?: string) {\n\t\tthis.templateRefName = new Attribute(name, value);\n\t}\n\n}\n\n/**\n * structural directive \n */\nexport class DomStructuralDirectiveNode extends BaseNode {\n\n\t/**\n\t * name of the directive \n\t */\n\tname: string;\n\n\t/**\n\t * value of the directive \n\t */\n\tvalue?: string;\n\n\t/**\n\t * the value of the template node, that this directive going to host-on \n\t */\n\tnode: DomNode;\n\n\tconstructor(name: string, node: DomNode, value?: string) {\n\t\tsuper();\n\t\tthis.name = name;\n\t\tthis.node = node;\n\t\tthis.value = value;\n\t}\n}\n\nexport function isDOMDirectiveNode(node: object): node is DomStructuralDirectiveNode {\n\treturn node instanceof DomStructuralDirectiveNode;\n}\nexport type DomChild = DomElementNode | DomStructuralDirectiveNode | CommentNode | TextContent | LiveTextContent;\n\nexport type DomNode = DomFragmentNode | DomElementNode | DomStructuralDirectiveNode | CommentNode | TextContent | LiveTextContent;\n\nexport type DomRenderNode<T> = (model: T) => DomNode;\n\nexport function parseTextChild(text: string): Array<TextContent | LiveTextContent> {\n\t// split from end with '}}', then search for the first '{{'\n\tlet all: (TextContent | LiveTextContent)[] = [];\n\tlet temp = text;\n\tlet last = temp.lastIndexOf('}}');\n\tlet first: number;\n\twhile (last > -1) {\n\t\tfirst = text.lastIndexOf('{{', last);\n\t\tif (first > -1) {\n\t\t\tlet lastPart = temp.substring(last + 2);\n\t\t\tif (lastPart) {\n\t\t\t\tall.push(new TextContent(lastPart));\n\t\t\t}\n\t\t\tconst liveText = new LiveTextContent(temp.substring(first + 2, last));\n\t\t\tall.push(liveText);\n\t\t\ttemp = temp.substring(0, first);\n\t\t\tlast = temp.lastIndexOf('}}');\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\tif (temp) {\n\t\tall.push(new TextContent(temp));\n\t}\n\treturn all.reverse();\n}\n\nexport function parseStringTemplate(text: string): string {\n\tconst node = parseTextChild(text);\n\tconst map = node.map(str => (str instanceof LiveTextContent ? '${' + str.value + '}' : str.value)).join('');\n\treturn '`' + map + '`';\n}\n"]}
|
package/ast/factory.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DomElementNode, DomStructuralDirectiveNode, DomChild, BaseNode, DomFragmentNode, DomNode, DomAttributeDirectiveNode } from './dom.js';
|
|
2
2
|
export interface NodeAttr {
|
|
3
3
|
[attr: string]: string;
|
|
4
4
|
}
|
|
@@ -6,11 +6,11 @@ export declare class NodeFactory {
|
|
|
6
6
|
static Fragment: string;
|
|
7
7
|
static CommentTag: string;
|
|
8
8
|
static DirectiveTag: string;
|
|
9
|
-
static
|
|
10
|
-
static
|
|
11
|
-
static
|
|
12
|
-
static
|
|
13
|
-
static
|
|
9
|
+
static createElement(tagName: string, attrs?: NodeAttr, ...children: (string | DomChild)[]): DomNode;
|
|
10
|
+
static createElementNode(tagName: string, attrs?: NodeAttr, ...children: (string | DomChild)[]): DomElementNode;
|
|
11
|
+
static createFragmentNode(...children: (string | DomChild)[]): DomFragmentNode;
|
|
12
|
+
static createStructuralDirectiveNode(directiveName: string, directiveValue: string, attrs?: NodeAttr, ...children: (string | DomChild)[]): DomStructuralDirectiveNode;
|
|
13
|
+
static createAttributeDirectiveNode(directiveName: string, attrs?: NodeAttr): DomAttributeDirectiveNode;
|
|
14
14
|
static initElementAttrs(element: BaseNode, attrs?: NodeAttr): void;
|
|
15
15
|
static handelAttribute(element: BaseNode, attrName: string, value: string | Function | object): void;
|
|
16
16
|
}
|
package/ast/factory.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DomElementNode, DomStructuralDirectiveNode, DomFragmentNode, parseTextChild, DomAttributeDirectiveNode } from './dom.js';
|
|
2
|
+
import { directiveRegistry } from '../directives/register-directive.js';
|
|
2
3
|
export class NodeFactory {
|
|
3
4
|
static createElement(tagName, attrs, ...children) {
|
|
4
5
|
if (NodeFactory.Fragment === tagName.toLowerCase()) {
|
|
5
6
|
return NodeFactory.createFragmentNode(...children);
|
|
6
7
|
}
|
|
7
|
-
if (
|
|
8
|
-
return NodeFactory.
|
|
8
|
+
if (directiveRegistry.has(tagName)) {
|
|
9
|
+
return NodeFactory.createStructuralDirectiveNode(tagName, '', attrs, ...children);
|
|
9
10
|
}
|
|
10
11
|
if (NodeFactory.DirectiveTag === tagName.toLocaleLowerCase() && attrs) {
|
|
11
12
|
if (attrs) {
|
|
@@ -14,9 +15,9 @@ export class NodeFactory {
|
|
|
14
15
|
if (directiveName) {
|
|
15
16
|
directiveValue = attrs[directiveName];
|
|
16
17
|
delete attrs.directiveName;
|
|
17
|
-
return NodeFactory.
|
|
18
|
+
return NodeFactory.createStructuralDirectiveNode(directiveName, directiveValue, attrs, ...children);
|
|
18
19
|
}
|
|
19
|
-
let node = new
|
|
20
|
+
let node = new DomElementNode(tagName, attrs?.is);
|
|
20
21
|
NodeFactory.initElementAttrs(node, attrs);
|
|
21
22
|
children?.forEach(child => {
|
|
22
23
|
if (typeof child === 'string') {
|
|
@@ -38,7 +39,7 @@ export class NodeFactory {
|
|
|
38
39
|
let directiveName = attrKeys.find(attrName => attrName.startsWith('*'));
|
|
39
40
|
if (directiveName) {
|
|
40
41
|
let directiveValue = attrs[directiveName];
|
|
41
|
-
return NodeFactory.
|
|
42
|
+
return NodeFactory.createStructuralDirectiveNode(directiveName, directiveValue, attrs, node);
|
|
42
43
|
}
|
|
43
44
|
return node;
|
|
44
45
|
}
|
|
@@ -47,7 +48,7 @@ export class NodeFactory {
|
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
50
|
static createElementNode(tagName, attrs, ...children) {
|
|
50
|
-
let node = new
|
|
51
|
+
let node = new DomElementNode(tagName, attrs?.is);
|
|
51
52
|
NodeFactory.initElementAttrs(node, attrs);
|
|
52
53
|
children?.forEach(child => {
|
|
53
54
|
if (typeof child === 'string') {
|
|
@@ -68,26 +69,52 @@ export class NodeFactory {
|
|
|
68
69
|
return [child];
|
|
69
70
|
}
|
|
70
71
|
});
|
|
71
|
-
return new
|
|
72
|
+
return new DomFragmentNode(childStack);
|
|
72
73
|
}
|
|
73
|
-
static
|
|
74
|
-
const fragment = new
|
|
74
|
+
static createStructuralDirectiveNode(directiveName, directiveValue, attrs, ...children) {
|
|
75
|
+
const fragment = new DomFragmentNode();
|
|
75
76
|
children?.forEach(child => (typeof child === 'string') ? fragment.addTextChild(child) : fragment.addChild(child));
|
|
76
|
-
|
|
77
|
+
!directiveName.startsWith('*') && (directiveName = '*' + directiveName);
|
|
78
|
+
const directive = new DomStructuralDirectiveNode(directiveName, fragment, directiveValue);
|
|
79
|
+
attrs && Object.keys(attrs).forEach(attr => directive.addAttribute(attr, attrs[attr]));
|
|
80
|
+
return directive;
|
|
81
|
+
}
|
|
82
|
+
static createAttributeDirectiveNode(directiveName, attrs) {
|
|
83
|
+
const directive = new DomAttributeDirectiveNode(directiveName);
|
|
84
|
+
attrs && Object.keys(attrs).forEach(attr => directive.addAttribute(attr, attrs[attr]));
|
|
85
|
+
return directive;
|
|
77
86
|
}
|
|
78
87
|
static initElementAttrs(element, attrs) {
|
|
79
88
|
if (attrs) {
|
|
80
89
|
Object.keys(attrs).forEach(key => {
|
|
81
90
|
NodeFactory.handelAttribute(element, key, attrs[key]);
|
|
82
91
|
});
|
|
92
|
+
const directives = [];
|
|
93
|
+
Object.keys(attrs).forEach(attributeName => {
|
|
94
|
+
if (directiveRegistry.has(attributeName)) {
|
|
95
|
+
Reflect.deleteProperty(attrs, attributeName);
|
|
96
|
+
const directive = new DomAttributeDirectiveNode(attributeName);
|
|
97
|
+
const directiveInfo = directiveRegistry.get(attributeName);
|
|
98
|
+
Object.keys(attrs).forEach(attr => {
|
|
99
|
+
if (directiveInfo.hasAttribute(attr)) {
|
|
100
|
+
directive.addAttribute(attr, attrs[attr]);
|
|
101
|
+
Reflect.deleteProperty(attrs, attr);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
directives.push(directive);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
if (directives.length) {
|
|
108
|
+
element.attributeDirectives = directives;
|
|
109
|
+
}
|
|
83
110
|
}
|
|
84
111
|
}
|
|
85
112
|
static handelAttribute(element, attrName, value) {
|
|
86
|
-
if (attrName.startsWith('#') && element instanceof
|
|
113
|
+
if (attrName.startsWith('#') && element instanceof DomElementNode) {
|
|
87
114
|
attrName = attrName.substring(1);
|
|
88
115
|
element.setTemplateRefName(attrName, value);
|
|
89
116
|
}
|
|
90
|
-
else if (attrName === 'is' && element instanceof
|
|
117
|
+
else if (attrName === 'is' && element instanceof DomElementNode) {
|
|
91
118
|
element.is = value;
|
|
92
119
|
return;
|
|
93
120
|
}
|
|
@@ -137,13 +164,4 @@ export class NodeFactory {
|
|
|
137
164
|
NodeFactory.Fragment = 'fragment';
|
|
138
165
|
NodeFactory.CommentTag = 'comment';
|
|
139
166
|
NodeFactory.DirectiveTag = 'directive';
|
|
140
|
-
NodeFactory.StructuralDirectives = [
|
|
141
|
-
'if',
|
|
142
|
-
'else',
|
|
143
|
-
'for',
|
|
144
|
-
'while',
|
|
145
|
-
'switch',
|
|
146
|
-
'case',
|
|
147
|
-
'default'
|
|
148
|
-
];
|
|
149
167
|
//# sourceMappingURL=factory.js.map
|
package/ast/factory.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/elements/ast/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,cAAc,EAAE,gBAAgB,EACtB,eAAe,EAAE,cAAc,EACzC,MAAM,UAAU,CAAC;AAMlB,MAAM,OAAO,WAAW;IAkBvB,MAAM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nLM,oBAAQ,GAAG,UAAU,CAAC;AAEtB,sBAAU,GAAG,SAAS,CAAC;AAEvB,wBAAY,GAAG,WAAW,CAAC;AAE3B,gCAAoB,GAAG;IAC7B,IAAI;IACJ,MAAM;IACN,KAAK;IACL,OAAO;IACP,QAAQ;IACR,MAAM;IACN,SAAS;CACT,CAAC","sourcesContent":["import {\n\tDOMElementNode, DOMDirectiveNode, DOMChild,\n\tBaseNode, DOMFragmentNode, parseTextChild, DOMNode\n} from './dom.js';\n\nexport interface NodeAttr {\n\t[attr: string]: string;\n}\n\nexport class NodeFactory {\n\n\tstatic Fragment = 'fragment';\n\n\tstatic CommentTag = 'comment';\n\n\tstatic DirectiveTag = 'directive';\n\n\tstatic StructuralDirectives = [\n\t\t'if',\n\t\t'else',\n\t\t'for',\n\t\t'while',\n\t\t'switch',\n\t\t'case',\n\t\t'default'\n\t];\n\n\tstatic createElement(tagName: string, attrs?: NodeAttr, ...children: (string | DOMChild)[]): DOMNode {\n\n\t\tif (NodeFactory.Fragment === tagName.toLowerCase()) {\n\t\t\treturn NodeFactory.createFragmentNode(...children);\n\t\t}\n\t\t/**\n\t\t * structural directive -- jsx support\n\t\t * \n\t\t * <if condition=\"element.show\"> {'{{element.name}}'} </if>\n\t\t * <div _if=\"element.show\">{'{{element.name}}'} </div>\n\t\t */\n\t\tif (NodeFactory.StructuralDirectives.includes(tagName)) {\n\t\t\treturn NodeFactory.createDirectiveNode(tagName, '', attrs, ...children);\n\t\t}\n\t\t/**\n\t\t * <directive *if=\"element.show\" >{'{{element.name}}'}</directive>\n\t\t */\n\t\tif (NodeFactory.DirectiveTag === tagName.toLocaleLowerCase() && attrs) {\n\t\t\tif (attrs) {\n\t\t\t\tlet directiveName = Object.keys(attrs).find(attrName => attrName.startsWith('*'));\n\t\t\t\tlet directiveValue: string;\n\n\t\t\t\tif (directiveName) {\n\t\t\t\t\t// is directive\n\t\t\t\t\tdirectiveValue = attrs[directiveName];\n\t\t\t\t\tdelete attrs.directiveName;\n\t\t\t\t\treturn NodeFactory.createDirectiveNode(directiveName, directiveValue, attrs, ...children);\n\t\t\t\t}\n\t\t\t\tlet node = new DOMElementNode(tagName, attrs?.is);\n\t\t\t\tNodeFactory.initElementAttrs(node, attrs);\n\t\t\t\tchildren?.forEach(child => {\n\t\t\t\t\tif (typeof child === 'string') {\n\t\t\t\t\t\tnode.addTextChild(child)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnode.addChild(child);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\treturn node;\n\t\t\t} else {\n\t\t\t\t// return new CommentNode('empty directive');\n\t\t\t\treturn NodeFactory.createFragmentNode(...children);\n\t\t\t}\n\t\t}\n\t\t// let node: ElementNode | DirectiveNode = new ElementNode(tagName, attrs?.is);\n\t\tif (attrs) {\n\t\t\tlet node = NodeFactory.createElementNode(tagName, attrs, ...children);\n\t\t\tconst attrKeys = Object.keys(attrs);\n\t\t\tlet directiveName = attrKeys.find(attrName => attrName.startsWith('*'));\n\t\t\tif (directiveName) {\n\t\t\t\tlet directiveValue = attrs[directiveName];\n\t\t\t\treturn NodeFactory.createDirectiveNode(directiveName, directiveValue, attrs, node);\n\t\t\t}\n\t\t\treturn node;\n\t\t} else {\n\t\t\treturn NodeFactory.createElementNode(tagName, attrs, ...children);\n\t\t}\n\t}\n\n\tstatic createElementNode(tagName: string, attrs?: NodeAttr, ...children: (string | DOMChild)[]) {\n\t\tlet node = new DOMElementNode(tagName, attrs?.is);\n\t\tNodeFactory.initElementAttrs(node, attrs);\n\t\tchildren?.forEach(child => {\n\t\t\tif (typeof child === 'string') {\n\t\t\t\tnode.addTextChild(child)\n\t\t\t} else {\n\t\t\t\tnode.addChild(child);\n\t\t\t}\n\t\t});\n\t\treturn node;\n\t}\n\n\tstatic createFragmentNode(...children: (string | DOMChild)[]) {\n\t\tlet childStack = children.flatMap(child => {\n\t\t\tif (typeof child === 'string') {\n\t\t\t\treturn parseTextChild(child);\n\t\t\t} else {\n\t\t\t\treturn [child];\n\t\t\t}\n\t\t});\n\t\treturn new DOMFragmentNode(childStack);\n\t}\n\n\tstatic createDirectiveNode(directiveName: string, directiveValue: string, attrs?: NodeAttr, ...children: (string | DOMChild)[]) {\n\t\tconst fragment = new DOMFragmentNode();\n\t\tchildren?.forEach(child => (typeof child === 'string') ? fragment.addTextChild(child) : fragment.addChild(child));\n\t\treturn new DOMDirectiveNode(directiveName, directiveValue, fragment);\n\t}\n\n\tstatic initElementAttrs(element: BaseNode, attrs?: NodeAttr) {\n\t\tif (attrs) {\n\t\t\tObject.keys(attrs).forEach(key => {\n\t\t\t\tNodeFactory.handelAttribute(element, key, attrs[key]);\n\t\t\t});\n\t\t}\n\t}\n\n\tstatic handelAttribute(element: BaseNode, attrName: string, value: string | Function | object): void {\n\n\t\tif (attrName.startsWith('#') && element instanceof DOMElementNode) {\n\t\t\t// <app-tag #element-name=\"directiveName?\" ></app-tag>\n\t\t\tattrName = attrName.substring(1);\n\t\t\telement.setTemplateRefName(attrName, value as string);\n\t\t}\n\t\telse if (attrName === 'is' && element instanceof DOMElementNode) {\n\t\t\telement.is = value as string;\n\t\t\treturn;\n\t\t}\n\t\telse if (attrName.startsWith('[(')) {\n\t\t\t// [(attr)]=\"modelProperty\"\n\t\t\tattrName = attrName.substring(2, attrName.length - 2);\n\t\t\telement.addTwoWayBinding(attrName, value as string);\n\t\t}\n\t\telse if (attrName.startsWith('$') && typeof value === 'string' && value.startsWith('$')) {\n\t\t\t// $attr=\"$viewProperty\" \n\t\t\tattrName = attrName.substring(1);\n\t\t\tvalue = value.substring(1);\n\t\t\telement.addTwoWayBinding(attrName, value as string);\n\t\t}\n\t\telse if (attrName.startsWith('[')) {\n\t\t\t// [attr]=\"modelProperty\"\n\t\t\tattrName = attrName.substring(1, attrName.length - 1);\n\t\t\telement.addInput(attrName, value as string);\n\t\t}\n\t\telse if (attrName.startsWith('$') && typeof value === 'string') {\n\t\t\t// $attr=\"viewProperty\" \n\t\t\tattrName = attrName.substring(1);\n\t\t\telement.addInput(attrName, value as string);\n\t\t}\n\t\telse if (attrName.startsWith('$') && typeof value === 'object') {\n\t\t\t// $attr={viewProperty} // as an object\n\t\t\tattrName = attrName.substring(1);\n\t\t\telement.addAttribute(attrName, value);\n\t\t}\n\t\telse if (typeof value === 'string' && value.startsWith('$')) {\n\t\t\t// bad practice\n\t\t\t// attr=\"$viewProperty\" // as an object\n\n\t\t\t// value = value.substring(1);\n\t\t\t// element.addAttribute(attrName, value);\n\t\t\treturn;\n\t\t}\n\t\telse if (typeof value === 'string' && (/^\\{\\{(.+\\w*)*\\}\\}/g).test(value)) {\n\t\t\t// attr=\"{{viewProperty}}\" // just pass data\n\t\t\tvalue = value.substring(2, value.length - 2);\n\t\t\telement.addInput(attrName, value);\n\t\t}\n\t\telse if (typeof value === 'string' && (/\\{\\{(.+)\\}\\}/g).test(value)) {\n\t\t\t// attr=\"any string{{viewProperty}}any text\" // just pass data\n\t\t\telement.addTemplateAttr(attrName, value);\n\t\t}\n\t\telse if (attrName.startsWith('(')) {\n\t\t\t// (elementAttr)=\"modelProperty()\"\n\t\t\tattrName = attrName.substring(1, attrName.length - 1);\n\t\t\telement.addOutput(attrName, value as string);\n\t\t}\n\t\telse if (attrName.startsWith('on')) {\n\t\t\t// onAttr=\"modelProperty()\"\n\t\t\t// onAttr={modelProperty} // as an function\n\t\t\telement.addOutput(attrName.substring(2), value as string);\n\t\t}\n\t\telse {\n\t\t\telement.addAttribute(attrName, value);\n\t\t}\n\t}\n\n}\n"]}
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/elements/ast/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,cAAc,EAAE,0BAA0B,EAChC,eAAe,EAAE,cAAc,EACzC,yBAAyB,EACzB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAMxE,MAAM,OAAO,WAAW;IAQvB,MAAM,CAAC,aAAa,CAAC,OAAe,EAAE,KAAg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,IAAI,CAAC,EAAE;YAGnC,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAe,CAAC,CAAC;SAC1D;aACI;YACJ,OAAO,CAAC,YAAY,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;SACtC;IACF,CAAC;;AArMM,oBAAQ,GAAG,UAAU,CAAC;AAEtB,sBAAU,GAAG,SAAS,CAAC;AAEvB,wBAAY,GAAG,WAAW,CAAC","sourcesContent":["import {\n\tDomElementNode, DomStructuralDirectiveNode, DomChild,\n\tBaseNode, DomFragmentNode, parseTextChild, DomNode,\n\tDomAttributeDirectiveNode\n} from './dom.js';\nimport { directiveRegistry } from '../directives/register-directive.js';\n\nexport interface NodeAttr {\n\t[attr: string]: string;\n}\n\nexport class NodeFactory {\n\n\tstatic Fragment = 'fragment';\n\n\tstatic CommentTag = 'comment';\n\n\tstatic DirectiveTag = 'directive';\n\n\tstatic createElement(tagName: string, attrs?: NodeAttr, ...children: (string | DomChild)[]): DomNode {\n\n\t\tif (NodeFactory.Fragment === tagName.toLowerCase()) {\n\t\t\treturn NodeFactory.createFragmentNode(...children);\n\t\t}\n\t\t/**\n\t\t * structural directive -- jsx support\n\t\t * \n\t\t * <if condition=\"element.show\"> {'{{element.name}}'} </if>\n\t\t * <div _if=\"element.show\">{'{{element.name}}'} </div>\n\t\t */\n\t\tif (directiveRegistry.has(tagName)) {\n\t\t\treturn NodeFactory.createStructuralDirectiveNode(tagName, '', attrs, ...children);\n\t\t}\n\t\t/**\n\t\t * <directive *if=\"element.show\" >{'{{element.name}}'}</directive>\n\t\t */\n\t\tif (NodeFactory.DirectiveTag === tagName.toLocaleLowerCase() && attrs) {\n\t\t\tif (attrs) {\n\t\t\t\tlet directiveName = Object.keys(attrs).find(attrName => attrName.startsWith('*'));\n\t\t\t\tlet directiveValue: string;\n\n\t\t\t\tif (directiveName) {\n\t\t\t\t\t// is directive\n\t\t\t\t\tdirectiveValue = attrs[directiveName];\n\t\t\t\t\tdelete attrs.directiveName;\n\t\t\t\t\treturn NodeFactory.createStructuralDirectiveNode(directiveName, directiveValue, attrs, ...children);\n\t\t\t\t}\n\t\t\t\tlet node = new DomElementNode(tagName, attrs?.is);\n\t\t\t\tNodeFactory.initElementAttrs(node, attrs);\n\t\t\t\tchildren?.forEach(child => {\n\t\t\t\t\tif (typeof child === 'string') {\n\t\t\t\t\t\tnode.addTextChild(child)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnode.addChild(child);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\treturn node;\n\t\t\t} else {\n\t\t\t\t// return new CommentNode('empty directive');\n\t\t\t\treturn NodeFactory.createFragmentNode(...children);\n\t\t\t}\n\t\t}\n\t\t// let node: ElementNode | DirectiveNode = new ElementNode(tagName, attrs?.is);\n\t\tif (attrs) {\n\t\t\tlet node = NodeFactory.createElementNode(tagName, attrs, ...children);\n\t\t\tconst attrKeys = Object.keys(attrs);\n\t\t\tlet directiveName = attrKeys.find(attrName => attrName.startsWith('*'));\n\t\t\tif (directiveName) {\n\t\t\t\tlet directiveValue = attrs[directiveName];\n\t\t\t\treturn NodeFactory.createStructuralDirectiveNode(directiveName, directiveValue, attrs, node);\n\t\t\t}\n\t\t\treturn node;\n\t\t} else {\n\t\t\treturn NodeFactory.createElementNode(tagName, attrs, ...children);\n\t\t}\n\t}\n\n\tstatic createElementNode(tagName: string, attrs?: NodeAttr, ...children: (string | DomChild)[]) {\n\t\tlet node = new DomElementNode(tagName, attrs?.is);\n\t\tNodeFactory.initElementAttrs(node, attrs);\n\t\tchildren?.forEach(child => {\n\t\t\tif (typeof child === 'string') {\n\t\t\t\tnode.addTextChild(child)\n\t\t\t} else {\n\t\t\t\tnode.addChild(child);\n\t\t\t}\n\t\t});\n\t\treturn node;\n\t}\n\n\tstatic createFragmentNode(...children: (string | DomChild)[]) {\n\t\tlet childStack = children.flatMap(child => {\n\t\t\tif (typeof child === 'string') {\n\t\t\t\treturn parseTextChild(child);\n\t\t\t} else {\n\t\t\t\treturn [child];\n\t\t\t}\n\t\t});\n\t\treturn new DomFragmentNode(childStack);\n\t}\n\n\tstatic createStructuralDirectiveNode(directiveName: string, directiveValue: string, attrs?: NodeAttr, ...children: (string | DomChild)[]) {\n\t\tconst fragment = new DomFragmentNode();\n\t\tchildren?.forEach(child => (typeof child === 'string') ? fragment.addTextChild(child) : fragment.addChild(child));\n\t\t!directiveName.startsWith('*') && (directiveName = '*' + directiveName);\n\t\tconst directive = new DomStructuralDirectiveNode(directiveName, fragment, directiveValue);\n\t\tattrs && Object.keys(attrs).forEach(attr => directive.addAttribute(attr, attrs[attr]));\n\t\treturn directive;\n\t}\n\n\tstatic createAttributeDirectiveNode(directiveName: string, attrs?: NodeAttr) {\n\t\tconst directive = new DomAttributeDirectiveNode(directiveName);\n\t\tattrs && Object.keys(attrs).forEach(attr => directive.addAttribute(attr, attrs[attr]));\n\t\treturn directive;\n\t}\n\n\tstatic initElementAttrs(element: BaseNode, attrs?: NodeAttr) {\n\t\tif (attrs) {\n\t\t\tObject.keys(attrs).forEach(key => {\n\t\t\t\tNodeFactory.handelAttribute(element, key, attrs[key]);\n\t\t\t});\n\n\t\t\tconst directives: DomAttributeDirectiveNode[] = [];\n\t\t\tObject.keys(attrs).forEach(attributeName => {\n\t\t\t\tif (directiveRegistry.has(attributeName)) {\n\t\t\t\t\tReflect.deleteProperty(attrs, attributeName);\n\t\t\t\t\tconst directive = new DomAttributeDirectiveNode(attributeName);\n\t\t\t\t\tconst directiveInfo = directiveRegistry.get(attributeName)!;\n\t\t\t\t\tObject.keys(attrs).forEach(attr => {\n\t\t\t\t\t\tif (directiveInfo.hasAttribute(attr)) {\n\t\t\t\t\t\t\tdirective.addAttribute(attr, attrs[attr]);\n\t\t\t\t\t\t\tReflect.deleteProperty(attrs, attr);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t\tdirectives.push(directive);\n\t\t\t\t}\n\t\t\t});\n\t\t\tif (directives.length) {\n\t\t\t\telement.attributeDirectives = directives;\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic handelAttribute(element: BaseNode, attrName: string, value: string | Function | object): void {\n\n\t\tif (attrName.startsWith('#') && element instanceof DomElementNode) {\n\t\t\t// <app-tag #element-name=\"directiveName?\" ></app-tag>\n\t\t\tattrName = attrName.substring(1);\n\t\t\telement.setTemplateRefName(attrName, value as string);\n\t\t}\n\t\telse if (attrName === 'is' && element instanceof DomElementNode) {\n\t\t\telement.is = value as string;\n\t\t\treturn;\n\t\t}\n\t\telse if (attrName.startsWith('[(')) {\n\t\t\t// [(attr)]=\"modelProperty\"\n\t\t\tattrName = attrName.substring(2, attrName.length - 2);\n\t\t\telement.addTwoWayBinding(attrName, value as string);\n\t\t}\n\t\telse if (attrName.startsWith('$') && typeof value === 'string' && value.startsWith('$')) {\n\t\t\t// $attr=\"$viewProperty\" \n\t\t\tattrName = attrName.substring(1);\n\t\t\tvalue = value.substring(1);\n\t\t\telement.addTwoWayBinding(attrName, value as string);\n\t\t}\n\t\telse if (attrName.startsWith('[')) {\n\t\t\t// [attr]=\"modelProperty\"\n\t\t\tattrName = attrName.substring(1, attrName.length - 1);\n\t\t\telement.addInput(attrName, value as string);\n\t\t}\n\t\telse if (attrName.startsWith('$') && typeof value === 'string') {\n\t\t\t// $attr=\"viewProperty\" \n\t\t\tattrName = attrName.substring(1);\n\t\t\telement.addInput(attrName, value as string);\n\t\t}\n\t\telse if (attrName.startsWith('$') && typeof value === 'object') {\n\t\t\t// $attr={viewProperty} // as an object\n\t\t\tattrName = attrName.substring(1);\n\t\t\telement.addAttribute(attrName, value);\n\t\t}\n\t\telse if (typeof value === 'string' && value.startsWith('$')) {\n\t\t\t// bad practice\n\t\t\t// attr=\"$viewProperty\" // as an object\n\n\t\t\t// value = value.substring(1);\n\t\t\t// element.addAttribute(attrName, value);\n\t\t\treturn;\n\t\t}\n\t\telse if (typeof value === 'string' && (/^\\{\\{(.+\\w*)*\\}\\}/g).test(value)) {\n\t\t\t// attr=\"{{viewProperty}}\" // just pass data\n\t\t\tvalue = value.substring(2, value.length - 2);\n\t\t\telement.addInput(attrName, value);\n\t\t}\n\t\telse if (typeof value === 'string' && (/\\{\\{(.+)\\}\\}/g).test(value)) {\n\t\t\t// attr=\"any string{{viewProperty}}any text\" // just pass data\n\t\t\telement.addTemplateAttr(attrName, value);\n\t\t}\n\t\telse if (attrName.startsWith('(')) {\n\t\t\t// (elementAttr)=\"modelProperty()\"\n\t\t\tattrName = attrName.substring(1, attrName.length - 1);\n\t\t\telement.addOutput(attrName, value as string);\n\t\t}\n\t\telse if (attrName.startsWith('on')) {\n\t\t\t// onAttr=\"modelProperty()\"\n\t\t\t// onAttr={modelProperty} // as an function\n\t\t\telement.addOutput(attrName.substring(2), value as string);\n\t\t}\n\t\telse {\n\t\t\telement.addAttribute(attrName, value);\n\t\t}\n\t}\n\n}\n"]}
|
|
@@ -5,3 +5,4 @@ export declare const GlobalAttributes: string[];
|
|
|
5
5
|
export declare const Attrs: AttrRef;
|
|
6
6
|
export declare function hasNativeAttr(element: string | HTMLElement, attr: string): boolean;
|
|
7
7
|
export declare function getTagsForAttr(attr: string): string[];
|
|
8
|
+
export declare function getAllAttributes(tag?: string): string[];
|
package/attributes/attributes.js
CHANGED
|
@@ -153,4 +153,10 @@ export function hasNativeAttr(element, attr) {
|
|
|
153
153
|
export function getTagsForAttr(attr) {
|
|
154
154
|
return Object.keys(Attrs).filter(tag => Attrs[tag].includes(attr));
|
|
155
155
|
}
|
|
156
|
+
export function getAllAttributes(tag) {
|
|
157
|
+
if (tag) {
|
|
158
|
+
return Attrs[tag];
|
|
159
|
+
}
|
|
160
|
+
return GlobalAttributes.slice();
|
|
161
|
+
}
|
|
156
162
|
//# sourceMappingURL=attributes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attributes.js","sourceRoot":"","sources":["../../../src/elements/attributes/attributes.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,gBAAgB,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CAAC;KACtC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,IAAY;IAC1C,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;AACpE,CAAC","sourcesContent":["\nexport interface AttrRef {\n\treadonly [attr: string]: string[];\n}\n\n/**\n * @see https://html.spec.whatwg.org/multipage/indices.html#elements-3\n */\nexport const GlobalAttributes = [\n\t'class',\n\t'id',\n\t'slot',\n\t'accesskey',\n\t'autocapitalize',\n\t'autofocus',\n\t'contenteditable',\n\t'dir',\n\t'draggable',\n\t'enterkeyhint',\n\t'hidden',\n\t'inputmode',\n\t'is',\n\t'itemid',\n\t'itemprop',\n\t'itemref',\n\t'itemscope',\n\t'itemtype',\n\t'lang',\n\t'nonce',\n\t'spellcheck',\n\t'style',\n\t'tabindex',\n\t'title',\n\t'translate'\n];\n\nexport const Attrs: AttrRef = {\n\ta: [...GlobalAttributes, 'href', 'target', 'download', 'ping', 'rel', 'hreflang', 'type', 'referrerpolicy'],\n\tabbr: GlobalAttributes,\n\taddress: GlobalAttributes,\n\tarea: [...GlobalAttributes, 'alt', 'coords', 'shape', 'href', 'target', 'download', 'ping', 'rel', 'referrerpolicy'],\n\tarticle: GlobalAttributes,\n\taside: GlobalAttributes,\n\taudio: [...GlobalAttributes, 'src', 'crossorigin', 'preload', 'autoplay', 'loop', 'muted', 'controls'],\n\tb: GlobalAttributes,\n\tbase: [...GlobalAttributes, 'href', 'targetreferrerpolicy'],\n\tbdi: GlobalAttributes,\n\tbdo: GlobalAttributes,\n\tblockquote: [...GlobalAttributes, 'cite'],\n\tbody: [...GlobalAttributes, 'onafterprint; onbeforeprint; onbeforeunload; onhashchange; onlanguagechange; onmessage; onmessageerror; onoffline; ononline; onpagehide; onpageshow; onpopstate; onrejectionhandled; onstorage; onunhandledrejection; onunload'],\n\tbr: GlobalAttributes,\n\tbutton: [...GlobalAttributes, 'disabled', 'form', 'formaction', 'formenctype', 'formmethod', 'formnovalidate', 'formtarget', 'name', 'type', 'value'],\n\tcanvas: [...GlobalAttributes, 'width', 'height'],\n\tcaption: GlobalAttributes,\n\tcite: GlobalAttributes,\n\tcode: GlobalAttributes,\n\tcol: [...GlobalAttributes, 'span'],\n\tcolgroup: [...GlobalAttributes, 'span'],\n\tdata: [...GlobalAttributes, 'value'],\n\tdatalist: GlobalAttributes,\n\tdd: GlobalAttributes,\n\tdel: [...GlobalAttributes, 'cite', 'datetime'],\n\tdetails: [...GlobalAttributes, 'open'],\n\tdfn: GlobalAttributes,\n\tdialog: [...GlobalAttributes, 'open'],\n\tdiv: GlobalAttributes,\n\tdl: GlobalAttributes,\n\tdt: GlobalAttributes,\n\tem: GlobalAttributes,\n\tembed: [...GlobalAttributes, 'src', 'type', 'width', 'height', 'any*'],\n\tfieldset: [...GlobalAttributes, 'disabled', 'form', 'name'],\n\tfigcaption: GlobalAttributes,\n\tfigure: GlobalAttributes,\n\tfooter: GlobalAttributes,\n\tform: [...GlobalAttributes, 'accept-charset', 'action', 'autocomplete', 'enctype', 'method', 'name', 'novalidate', 'target'],\n\th1: GlobalAttributes,\n\th2: GlobalAttributes,\n\th3: GlobalAttributes,\n\th4: GlobalAttributes,\n\th5: GlobalAttributes,\n\th6: GlobalAttributes,\n\thead: GlobalAttributes,\n\theader: GlobalAttributes,\n\thgroup: GlobalAttributes,\n\thr: GlobalAttributes,\n\thtml: [...GlobalAttributes, 'manifest'],\n\ti: GlobalAttributes,\n\tiframe: [...GlobalAttributes, 'src', 'srcdoc', 'name', 'sandbox', 'allow', 'allowfullscreen', 'allowpaymentrequest', 'width', 'height', 'referrerpolicy', 'loading'],\n\timg: [...GlobalAttributes, 'alt', 'src', 'srcset', 'sizes', 'crossorigin', 'usemap', 'ismap', 'width', 'height', 'referrerpolicy', 'decoding', 'loading'],\n\tinput: [...GlobalAttributes, 'accept', 'alt', 'autocomplete', 'checked', 'dirname', 'disabled', 'form', 'formaction', 'formenctype', 'formmethod', 'formnovalidate', 'formtarget', 'height', 'list', 'max', 'maxlength', 'min', 'minlength', 'multiple', 'name', 'pattern', 'placeholder', 'readonly', 'required', 'size', 'src', 'step', 'type', 'value', 'width'],\n\tins: [...GlobalAttributes, 'cite', 'datetime'],\n\tkbd: GlobalAttributes,\n\tlabel: [...GlobalAttributes, 'for'],\n\tlegend: GlobalAttributes,\n\tli: [...GlobalAttributes, 'value'],\n\tlink: [...GlobalAttributes, 'href', 'crossorigin', 'rel', 'as', 'media', 'hreflang', 'type', 'sizes', 'imagesrcset', 'imagesizes', 'referrerpolicy', 'integrity', 'color', 'disabled'],\n\tmain: GlobalAttributes,\n\tmap: [...GlobalAttributes, 'name'],\n\tmark: GlobalAttributes,\n\tmenu: GlobalAttributes,\n\tmeta: [...GlobalAttributes, 'name', 'http-equiv', 'content', 'charset'],\n\tmeter: [...GlobalAttributes, 'value', 'min', 'max', 'low', 'high', 'optimum'],\n\tnav: GlobalAttributes,\n\tnoscript: GlobalAttributes,\n\tobject: [...GlobalAttributes, 'data', 'type', 'name', 'usemap', 'form', 'width', 'height'],\n\tol: [...GlobalAttributes, 'reversed', 'start', 'type'],\n\toptgroup: [...GlobalAttributes, 'disabled', 'label'],\n\toption: [...GlobalAttributes, 'disabled', 'label', 'selected', 'value'],\n\toutput: [...GlobalAttributes, 'for', 'form', 'name'],\n\tp: GlobalAttributes,\n\tparam: [...GlobalAttributes, 'name', 'value'],\n\tpicture: GlobalAttributes,\n\tpre: GlobalAttributes,\n\tprogress: [...GlobalAttributes, 'value', 'max'],\n\tq: [...GlobalAttributes, 'cite'],\n\trp: GlobalAttributes,\n\trt: GlobalAttributes,\n\truby: GlobalAttributes,\n\ts: GlobalAttributes,\n\tsamp: GlobalAttributes,\n\tscript: [...GlobalAttributes, 'src', 'type', 'async', 'defer', 'crossorigin', 'integrity', 'referrerpolicy'],\n\tsection: GlobalAttributes,\n\tselect: [...GlobalAttributes, 'autocomplete', 'disabled', 'form', 'multiple', 'name', 'required', 'size'],\n\tslot: [...GlobalAttributes, 'name'],\n\tsmall: GlobalAttributes,\n\tsource: [...GlobalAttributes, 'src', 'type', 'srcset', 'sizes', 'media'],\n\tspan: GlobalAttributes,\n\tstrong: GlobalAttributes,\n\tstyle: [...GlobalAttributes, 'media'],\n\tsub: GlobalAttributes,\n\tsummary: GlobalAttributes,\n\tsup: GlobalAttributes,\n\ttable: GlobalAttributes,\n\ttbody: GlobalAttributes,\n\ttd: [...GlobalAttributes, 'colspan', 'rowspan', 'headers'],\n\ttemplate: GlobalAttributes,\n\ttextarea: [...GlobalAttributes, 'cols', 'dirname', 'disabled', 'form', 'maxlength', 'minlength', 'name', 'placeholder', 'readonly', 'required', 'rows', 'wrap'],\n\ttfoot: GlobalAttributes,\n\tth: [...GlobalAttributes, 'colspan', 'rowspan', 'headers', 'scope', 'abbr'],\n\tthead: GlobalAttributes,\n\ttime: [...GlobalAttributes, 'datetime'],\n\ttitle: GlobalAttributes,\n\ttr: GlobalAttributes,\n\ttrack: [...GlobalAttributes, 'default', 'kind', 'label', 'src', 'srclang'],\n\tu: GlobalAttributes,\n\tul: GlobalAttributes,\n\tvar: GlobalAttributes,\n\tvideo: [...GlobalAttributes, 'src', 'crossorigin', 'poster', 'preload', 'autoplay', 'playsinline', 'loop', 'muted', 'controls', 'width', 'height'],\n\twbr: GlobalAttributes,\n\t'virtual-scroller': GlobalAttributes\n};\n\n\nexport function hasNativeAttr(element: string | HTMLElement, attr: string): boolean {\n\tif (typeof element === 'string') {\n\t\treturn Attrs[element.toLowerCase()]?.includes(attr);\n\t} else if (element instanceof HTMLElement) {\n\t\tconst tagName = element.tagName.toLowerCase();\n\t\treturn Attrs[tagName]?.includes(attr);\n\t}\n\treturn false;\n}\n\nexport function getTagsForAttr(attr: string): string[] {\n\treturn Object.keys(Attrs).filter(tag => Attrs[tag].includes(attr));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"attributes.js","sourceRoot":"","sources":["../../../src/elements/attributes/attributes.ts"],"names":[],"mappings":"AASA,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC/B,OAAO;IACP,IAAI;IACJ,MAAM;IACN,WAAW;IACX,gBAAgB;IAChB,WAAW;IACX,iBAAiB;IACjB,KAAK;IACL,WAAW;IACX,cAAc;IACd,QAAQ;IACR,WAAW;IACX,IAAI;IACJ,QAAQ;IACR,UAAU;IACV,SAAS;IACT,WAAW;IACX,UAAU;IACV,MAAM;IACN,OAAO;IACP,YAAY;IACZ,OAAO;IACP,UAAU;IACV,OAAO;IACP,WAAW;CACX,CAAC;AAEF,MAAM,CAAC,MAAM,KAAK,GAAY;IAC7B,CAAC,EAAE,CAAC,GAAG,gBAAgB,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,gBAAgB,CAAC;IAC3G,IAAI,EAAE,gBAAgB;IACtB,OAAO,EAAE,gBAAgB;IACzB,IAAI,EAAE,CAAC,GAAG,gBAAgB,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,CAAC;IACpH,OAAO,EAAE,gBAAgB;IACzB,KAAK,EAAE,gBAAgB;IACvB,KAAK,EAAE,CAAC,GAAG,gBAAgB,EAAE,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,CAAC;IACtG,CAAC,EAAE,gBAAgB;IACnB,IAAI,EAAE,CAAC,GAAG,gBAAgB,EAAE,MAAM,EAAE,sBAAsB,CAAC;IAC3D,GAAG,EAAE,gBAAgB;IACrB,GAAG,EAAE,gBAAgB;IACrB,UAAU,EAAE,CAAC,GAAG,gBAAgB,EAAE,MAAM,CAAC;IACzC,IAAI,EAAE,CAAC,GAAG,g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AG,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;QAC9C,OAAO,KAAK,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;KACtC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,IAAY;IAC1C,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;AACpE,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,GAAY;IAC5C,IAAI,GAAG,EAAE;QACR,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC;KAClB;IACD,OAAO,gBAAgB,CAAC,KAAK,EAAE,CAAC;AACjC,CAAC","sourcesContent":["import { DefaultTag } from './tags.js';\n\nexport interface AttrRef {\n\treadonly [attr: string]: string[];\n}\n\n/**\n * @see https://html.spec.whatwg.org/multipage/indices.html#elements-3\n */\nexport const GlobalAttributes = [\n\t'class',\n\t'id',\n\t'slot',\n\t'accesskey',\n\t'autocapitalize',\n\t'autofocus',\n\t'contenteditable',\n\t'dir',\n\t'draggable',\n\t'enterkeyhint',\n\t'hidden',\n\t'inputmode',\n\t'is',\n\t'itemid',\n\t'itemprop',\n\t'itemref',\n\t'itemscope',\n\t'itemtype',\n\t'lang',\n\t'nonce',\n\t'spellcheck',\n\t'style',\n\t'tabindex',\n\t'title',\n\t'translate'\n];\n\nexport const Attrs: AttrRef = {\n\ta: [...GlobalAttributes, 'href', 'target', 'download', 'ping', 'rel', 'hreflang', 'type', 'referrerpolicy'],\n\tabbr: GlobalAttributes,\n\taddress: GlobalAttributes,\n\tarea: [...GlobalAttributes, 'alt', 'coords', 'shape', 'href', 'target', 'download', 'ping', 'rel', 'referrerpolicy'],\n\tarticle: GlobalAttributes,\n\taside: GlobalAttributes,\n\taudio: [...GlobalAttributes, 'src', 'crossorigin', 'preload', 'autoplay', 'loop', 'muted', 'controls'],\n\tb: GlobalAttributes,\n\tbase: [...GlobalAttributes, 'href', 'targetreferrerpolicy'],\n\tbdi: GlobalAttributes,\n\tbdo: GlobalAttributes,\n\tblockquote: [...GlobalAttributes, 'cite'],\n\tbody: [...GlobalAttributes, 'onafterprint; onbeforeprint; onbeforeunload; onhashchange; onlanguagechange; onmessage; onmessageerror; onoffline; ononline; onpagehide; onpageshow; onpopstate; onrejectionhandled; onstorage; onunhandledrejection; onunload'],\n\tbr: GlobalAttributes,\n\tbutton: [...GlobalAttributes, 'disabled', 'form', 'formaction', 'formenctype', 'formmethod', 'formnovalidate', 'formtarget', 'name', 'type', 'value'],\n\tcanvas: [...GlobalAttributes, 'width', 'height'],\n\tcaption: GlobalAttributes,\n\tcite: GlobalAttributes,\n\tcode: GlobalAttributes,\n\tcol: [...GlobalAttributes, 'span'],\n\tcolgroup: [...GlobalAttributes, 'span'],\n\tdata: [...GlobalAttributes, 'value'],\n\tdatalist: GlobalAttributes,\n\tdd: GlobalAttributes,\n\tdel: [...GlobalAttributes, 'cite', 'datetime'],\n\tdetails: [...GlobalAttributes, 'open'],\n\tdfn: GlobalAttributes,\n\tdialog: [...GlobalAttributes, 'open'],\n\tdiv: GlobalAttributes,\n\tdl: GlobalAttributes,\n\tdt: GlobalAttributes,\n\tem: GlobalAttributes,\n\tembed: [...GlobalAttributes, 'src', 'type', 'width', 'height', 'any*'],\n\tfieldset: [...GlobalAttributes, 'disabled', 'form', 'name'],\n\tfigcaption: GlobalAttributes,\n\tfigure: GlobalAttributes,\n\tfooter: GlobalAttributes,\n\tform: [...GlobalAttributes, 'accept-charset', 'action', 'autocomplete', 'enctype', 'method', 'name', 'novalidate', 'target'],\n\th1: GlobalAttributes,\n\th2: GlobalAttributes,\n\th3: GlobalAttributes,\n\th4: GlobalAttributes,\n\th5: GlobalAttributes,\n\th6: GlobalAttributes,\n\thead: GlobalAttributes,\n\theader: GlobalAttributes,\n\thgroup: GlobalAttributes,\n\thr: GlobalAttributes,\n\thtml: [...GlobalAttributes, 'manifest'],\n\ti: GlobalAttributes,\n\tiframe: [...GlobalAttributes, 'src', 'srcdoc', 'name', 'sandbox', 'allow', 'allowfullscreen', 'allowpaymentrequest', 'width', 'height', 'referrerpolicy', 'loading'],\n\timg: [...GlobalAttributes, 'alt', 'src', 'srcset', 'sizes', 'crossorigin', 'usemap', 'ismap', 'width', 'height', 'referrerpolicy', 'decoding', 'loading'],\n\tinput: [...GlobalAttributes, 'accept', 'alt', 'autocomplete', 'checked', 'dirname', 'disabled', 'form', 'formaction', 'formenctype', 'formmethod', 'formnovalidate', 'formtarget', 'height', 'list', 'max', 'maxlength', 'min', 'minlength', 'multiple', 'name', 'pattern', 'placeholder', 'readonly', 'required', 'size', 'src', 'step', 'type', 'value', 'width'],\n\tins: [...GlobalAttributes, 'cite', 'datetime'],\n\tkbd: GlobalAttributes,\n\tlabel: [...GlobalAttributes, 'for'],\n\tlegend: GlobalAttributes,\n\tli: [...GlobalAttributes, 'value'],\n\tlink: [...GlobalAttributes, 'href', 'crossorigin', 'rel', 'as', 'media', 'hreflang', 'type', 'sizes', 'imagesrcset', 'imagesizes', 'referrerpolicy', 'integrity', 'color', 'disabled'],\n\tmain: GlobalAttributes,\n\tmap: [...GlobalAttributes, 'name'],\n\tmark: GlobalAttributes,\n\tmenu: GlobalAttributes,\n\tmeta: [...GlobalAttributes, 'name', 'http-equiv', 'content', 'charset'],\n\tmeter: [...GlobalAttributes, 'value', 'min', 'max', 'low', 'high', 'optimum'],\n\tnav: GlobalAttributes,\n\tnoscript: GlobalAttributes,\n\tobject: [...GlobalAttributes, 'data', 'type', 'name', 'usemap', 'form', 'width', 'height'],\n\tol: [...GlobalAttributes, 'reversed', 'start', 'type'],\n\toptgroup: [...GlobalAttributes, 'disabled', 'label'],\n\toption: [...GlobalAttributes, 'disabled', 'label', 'selected', 'value'],\n\toutput: [...GlobalAttributes, 'for', 'form', 'name'],\n\tp: GlobalAttributes,\n\tparam: [...GlobalAttributes, 'name', 'value'],\n\tpicture: GlobalAttributes,\n\tpre: GlobalAttributes,\n\tprogress: [...GlobalAttributes, 'value', 'max'],\n\tq: [...GlobalAttributes, 'cite'],\n\trp: GlobalAttributes,\n\trt: GlobalAttributes,\n\truby: GlobalAttributes,\n\ts: GlobalAttributes,\n\tsamp: GlobalAttributes,\n\tscript: [...GlobalAttributes, 'src', 'type', 'async', 'defer', 'crossorigin', 'integrity', 'referrerpolicy'],\n\tsection: GlobalAttributes,\n\tselect: [...GlobalAttributes, 'autocomplete', 'disabled', 'form', 'multiple', 'name', 'required', 'size'],\n\tslot: [...GlobalAttributes, 'name'],\n\tsmall: GlobalAttributes,\n\tsource: [...GlobalAttributes, 'src', 'type', 'srcset', 'sizes', 'media'],\n\tspan: GlobalAttributes,\n\tstrong: GlobalAttributes,\n\tstyle: [...GlobalAttributes, 'media'],\n\tsub: GlobalAttributes,\n\tsummary: GlobalAttributes,\n\tsup: GlobalAttributes,\n\ttable: GlobalAttributes,\n\ttbody: GlobalAttributes,\n\ttd: [...GlobalAttributes, 'colspan', 'rowspan', 'headers'],\n\ttemplate: GlobalAttributes,\n\ttextarea: [...GlobalAttributes, 'cols', 'dirname', 'disabled', 'form', 'maxlength', 'minlength', 'name', 'placeholder', 'readonly', 'required', 'rows', 'wrap'],\n\ttfoot: GlobalAttributes,\n\tth: [...GlobalAttributes, 'colspan', 'rowspan', 'headers', 'scope', 'abbr'],\n\tthead: GlobalAttributes,\n\ttime: [...GlobalAttributes, 'datetime'],\n\ttitle: GlobalAttributes,\n\ttr: GlobalAttributes,\n\ttrack: [...GlobalAttributes, 'default', 'kind', 'label', 'src', 'srclang'],\n\tu: GlobalAttributes,\n\tul: GlobalAttributes,\n\tvar: GlobalAttributes,\n\tvideo: [...GlobalAttributes, 'src', 'crossorigin', 'poster', 'preload', 'autoplay', 'playsinline', 'loop', 'muted', 'controls', 'width', 'height'],\n\twbr: GlobalAttributes,\n\t'virtual-scroller': GlobalAttributes\n};\n\n\nexport function hasNativeAttr(element: string | HTMLElement, attr: string): boolean {\n\tif (typeof element === 'string') {\n\t\treturn Attrs[element.toLowerCase()]?.includes(attr);\n\t} else if (element instanceof HTMLElement) {\n\t\tconst tagName = element.tagName.toLowerCase();\n\t\treturn Attrs[tagName]?.includes(attr);\n\t}\n\treturn false;\n}\n\nexport function getTagsForAttr(attr: string): string[] {\n\treturn Object.keys(Attrs).filter(tag => Attrs[tag].includes(attr));\n}\n\nexport function getAllAttributes(tag?: string): string[] {\n\tif (tag) {\n\t\treturn Attrs[tag];\n\t}\n\treturn GlobalAttributes.slice();\n}"]}
|