@ibyar/elements 0.5.6 → 0.6.1

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/ast/dom.d.ts CHANGED
@@ -1,3 +1,6 @@
1
+ /**
2
+ * a normal attribute with its source value without any binding.
3
+ */
1
4
  export declare class Attribute<N, V> {
2
5
  name: N;
3
6
  value: V;
@@ -5,26 +8,62 @@ export declare class Attribute<N, V> {
5
8
  }
6
9
  export declare class ElementAttribute<N, V> extends Attribute<N, V> {
7
10
  }
11
+ /**
12
+ * an attribute with its source value for binding
13
+ */
8
14
  export declare class LiveAttribute extends Attribute<string, string> {
9
15
  }
16
+ /**
17
+ *
18
+ * @param name
19
+ * @param value
20
+ * @returns LiveAttribute
21
+ */
10
22
  export declare function createLiveAttribute(name: string, value: string): LiveAttribute;
23
+ /**
24
+ * a normal text
25
+ */
11
26
  export declare class TextContent extends Attribute<'textContent', string> {
12
27
  static propName: 'textContent';
13
28
  constructor(text: string);
14
29
  }
30
+ /**
31
+ * a text that its content is binding to variable from the component model.
32
+ */
15
33
  export declare class LiveTextContent extends TextContent {
16
34
  }
17
35
  export declare function isLiveTextContent(text: object): text is LiveTextContent;
36
+ /**
37
+ * to comment in dom
38
+ */
18
39
  export declare class CommentNode {
19
40
  comment: string;
20
41
  constructor(comment: string);
21
42
  }
22
43
  export declare class BaseNode {
44
+ /**
45
+ * hold static attr and event that will resolve normally from the global window.
46
+ */
23
47
  attributes?: ElementAttribute<string, string | number | boolean | object>[];
48
+ /**
49
+ * hold the attrs/inputs name marked as one way binding
50
+ */
24
51
  inputs?: LiveAttribute[];
52
+ /**
53
+ * hold the name of events that should be connected to a listener
54
+ */
25
55
  outputs?: ElementAttribute<string, string>[];
56
+ /**
57
+ * hold the name of attributes marked for 2 way data binding
58
+ */
26
59
  twoWayBinding?: LiveAttribute[];
60
+ /**
61
+ * directive attribute
62
+ */
27
63
  templateAttrs?: LiveAttribute[];
64
+ /**
65
+ * attributes directive
66
+ */
28
67
  attributeDirectives?: DomAttributeDirectiveNode[];
29
68
  addAttribute(attrName: string, value?: string | number | boolean | object): void;
30
69
  addInput(attrName: string, valueSource: string): void;
@@ -33,29 +72,62 @@ export declare class BaseNode {
33
72
  addTemplateAttr(attrName: string, valueSource: string): void;
34
73
  }
35
74
  export declare class DomAttributeDirectiveNode extends BaseNode {
75
+ /**
76
+ * name of the directive
77
+ */
36
78
  name: string;
79
+ /**
80
+ * set to `undefined` stop, loop
81
+ */
37
82
  attributeDirectives: undefined;
38
83
  constructor(name: string);
39
84
  }
40
85
  export declare class DomParentNode extends BaseNode {
86
+ /**
87
+ * element children list
88
+ */
41
89
  children?: DomChild[];
42
90
  addChild(child: DomChild): void;
43
91
  addTextChild(text: string): void;
44
92
  }
93
+ /**
94
+ * parent for a list of elements
95
+ */
45
96
  export declare class DomFragmentNode extends DomParentNode {
46
97
  constructor(children?: DomChild[]);
47
98
  }
48
99
  export declare class DomElementNode extends DomParentNode {
100
+ /**
101
+ * the tag name of the element
102
+ */
49
103
  tagName: string;
104
+ /**
105
+ * used to upgrade an element to another custom-element name
106
+ */
50
107
  is?: string;
108
+ /**
109
+ * a given name for element
110
+ */
51
111
  templateRefName?: Attribute<string, string | undefined>;
52
112
  constructor(tagName: string, is?: string);
53
113
  setTagName(tagName: string): void;
54
114
  setTemplateRefName(name: string, value?: string): void;
55
115
  }
116
+ /**
117
+ * structural directive
118
+ */
56
119
  export declare class DomStructuralDirectiveNode extends BaseNode {
120
+ /**
121
+ * name of the directive
122
+ */
57
123
  name: string;
124
+ /**
125
+ * value of the directive
126
+ */
58
127
  value?: string;
128
+ /**
129
+ * the value of the template node, that this directive going to host-on
130
+ */
59
131
  node: DomNode;
60
132
  constructor(name: string, node: DomNode, value?: string);
61
133
  }
package/ast/dom.js CHANGED
@@ -1,3 +1,6 @@
1
+ /**
2
+ * a normal attribute with its source value without any binding.
3
+ */
1
4
  export class Attribute {
2
5
  constructor(name, value) {
3
6
  this.name = name;
@@ -6,22 +9,40 @@ export class Attribute {
6
9
  }
7
10
  export class ElementAttribute extends Attribute {
8
11
  }
12
+ /**
13
+ * an attribute with its source value for binding
14
+ */
9
15
  export class LiveAttribute extends Attribute {
10
16
  }
17
+ /**
18
+ *
19
+ * @param name
20
+ * @param value
21
+ * @returns LiveAttribute
22
+ */
11
23
  export function createLiveAttribute(name, value) {
12
24
  return new LiveAttribute(name, value);
13
25
  }
26
+ /**
27
+ * a normal text
28
+ */
14
29
  export class TextContent extends Attribute {
15
30
  constructor(text) {
16
31
  super(TextContent.propName, text);
17
32
  }
18
33
  }
19
34
  TextContent.propName = 'textContent';
35
+ /**
36
+ * a text that its content is binding to variable from the component model.
37
+ */
20
38
  export class LiveTextContent extends TextContent {
21
39
  }
22
40
  export function isLiveTextContent(text) {
23
41
  return text instanceof LiveTextContent;
24
42
  }
43
+ /**
44
+ * to comment in dom
45
+ */
25
46
  export class CommentNode {
26
47
  constructor(comment) {
27
48
  this.comment = comment;
@@ -63,12 +84,14 @@ export class BaseNode {
63
84
  addTemplateAttr(attrName, valueSource) {
64
85
  valueSource = valueSource.trim();
65
86
  if (/^\{\{(.+)\}\}$/g.test(valueSource)) {
87
+ // as one way binding
66
88
  const substring = valueSource.substring(2, valueSource.length - 2);
67
89
  if (!(/\{\{(.+)\}\}/g).test(substring)) {
68
90
  this.addInput(attrName, substring);
69
91
  return;
70
92
  }
71
93
  }
94
+ // as string
72
95
  valueSource = parseStringTemplate(valueSource);
73
96
  if (this.templateAttrs) {
74
97
  this.templateAttrs.push(new LiveAttribute(attrName, valueSource));
@@ -98,6 +121,9 @@ export class DomParentNode extends BaseNode {
98
121
  parseTextChild(text).forEach(childText => children.push(childText));
99
122
  }
100
123
  }
124
+ /**
125
+ * parent for a list of elements
126
+ */
101
127
  export class DomFragmentNode extends DomParentNode {
102
128
  constructor(children) {
103
129
  super();
@@ -121,6 +147,9 @@ export class DomElementNode extends DomParentNode {
121
147
  this.templateRefName = new Attribute(name, value);
122
148
  }
123
149
  }
150
+ /**
151
+ * structural directive
152
+ */
124
153
  export class DomStructuralDirectiveNode extends BaseNode {
125
154
  constructor(name, node, value) {
126
155
  super();
@@ -133,6 +162,7 @@ export function isDOMDirectiveNode(node) {
133
162
  return node instanceof DomStructuralDirectiveNode;
134
163
  }
135
164
  export function parseTextChild(text) {
165
+ // split from end with '}}', then search for the first '{{'
136
166
  let all = [];
137
167
  let temp = text;
138
168
  let last = temp.lastIndexOf('}}');
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;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,E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,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACrC,IAAI,KAAK,GAAG,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 * \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}\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\tdeclare attributeDirectives: 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"]}
1
+ {"version":3,"file":"dom.js","sourceRoot":"","sources":["../../../src/elements/ast/dom.ts"],"names":[],"mappings":"AACA;;GAEG;AACH,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;AAE/D;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,SAAyB;CAAI;AAEhE;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAY,EAAE,KAAa;IAC9D,OAAO,IAAI,aAAa,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AACvC,CAAC;AAED;;GAEG;AACH,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;AAMhD;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,WAAW;CAAI;AA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AC,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}\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\tdeclare attributeDirectives: 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.js CHANGED
@@ -5,14 +5,24 @@ export class NodeFactory {
5
5
  if (NodeFactory.Fragment === tagName.toLowerCase()) {
6
6
  return NodeFactory.createFragmentNode(...children);
7
7
  }
8
+ /**
9
+ * structural directive -- jsx support
10
+ *
11
+ * <if condition="element.show"> {'{{element.name}}'} </if>
12
+ * <div _if="element.show">{'{{element.name}}'} </div>
13
+ */
8
14
  if (directiveRegistry.has(tagName)) {
9
15
  return NodeFactory.createStructuralDirectiveNode(tagName, '', attrs, ...children);
10
16
  }
17
+ /**
18
+ * <directive *if="element.show" >{'{{element.name}}'}</directive>
19
+ */
11
20
  if (NodeFactory.DirectiveTag === tagName.toLocaleLowerCase() && attrs) {
12
21
  if (attrs) {
13
22
  let directiveName = Object.keys(attrs).find(attrName => attrName.startsWith('*'));
14
23
  let directiveValue;
15
24
  if (directiveName) {
25
+ // is directive
16
26
  directiveValue = attrs[directiveName];
17
27
  delete attrs.directiveName;
18
28
  return NodeFactory.createStructuralDirectiveNode(directiveName, directiveValue, attrs, ...children);
@@ -30,9 +40,11 @@ export class NodeFactory {
30
40
  return node;
31
41
  }
32
42
  else {
43
+ // return new CommentNode('empty directive');
33
44
  return NodeFactory.createFragmentNode(...children);
34
45
  }
35
46
  }
47
+ // let node: ElementNode | DirectiveNode = new ElementNode(tagName, attrs?.is);
36
48
  if (attrs) {
37
49
  let node = NodeFactory.createElementNode(tagName, attrs, ...children);
38
50
  const attrKeys = Object.keys(attrs);
@@ -111,6 +123,7 @@ export class NodeFactory {
111
123
  }
112
124
  static handelAttribute(element, attrName, value) {
113
125
  if (attrName.startsWith('#') && element instanceof DomElementNode) {
126
+ // <app-tag #element-name="directiveName?" ></app-tag>
114
127
  attrName = attrName.substring(1);
115
128
  element.setTemplateRefName(attrName, value);
116
129
  }
@@ -119,41 +132,55 @@ export class NodeFactory {
119
132
  return;
120
133
  }
121
134
  else if (attrName.startsWith('[(')) {
135
+ // [(attr)]="modelProperty"
122
136
  attrName = attrName.substring(2, attrName.length - 2);
123
137
  element.addTwoWayBinding(attrName, value);
124
138
  }
125
139
  else if (attrName.startsWith('$') && typeof value === 'string' && value.startsWith('$')) {
140
+ // $attr="$viewProperty"
126
141
  attrName = attrName.substring(1);
127
142
  value = value.substring(1);
128
143
  element.addTwoWayBinding(attrName, value);
129
144
  }
130
145
  else if (attrName.startsWith('[')) {
146
+ // [attr]="modelProperty"
131
147
  attrName = attrName.substring(1, attrName.length - 1);
132
148
  element.addInput(attrName, value);
133
149
  }
134
150
  else if (attrName.startsWith('$') && typeof value === 'string') {
151
+ // $attr="viewProperty"
135
152
  attrName = attrName.substring(1);
136
153
  element.addInput(attrName, value);
137
154
  }
138
155
  else if (attrName.startsWith('$') && typeof value === 'object') {
156
+ // $attr={viewProperty} // as an object
139
157
  attrName = attrName.substring(1);
140
158
  element.addAttribute(attrName, value);
141
159
  }
142
160
  else if (typeof value === 'string' && value.startsWith('$')) {
161
+ // bad practice
162
+ // attr="$viewProperty" // as an object
163
+ // value = value.substring(1);
164
+ // element.addAttribute(attrName, value);
143
165
  return;
144
166
  }
145
167
  else if (typeof value === 'string' && (/^\{\{(.+\w*)*\}\}/g).test(value)) {
168
+ // attr="{{viewProperty}}" // just pass data
146
169
  value = value.substring(2, value.length - 2);
147
170
  element.addInput(attrName, value);
148
171
  }
149
172
  else if (typeof value === 'string' && (/\{\{(.+)\}\}/g).test(value)) {
173
+ // attr="any string{{viewProperty}}any text" // just pass data
150
174
  element.addTemplateAttr(attrName, value);
151
175
  }
152
176
  else if (attrName.startsWith('(')) {
177
+ // (elementAttr)="modelProperty()"
153
178
  attrName = attrName.substring(1, attrName.length - 1);
154
179
  element.addOutput(attrName, value);
155
180
  }
156
181
  else if (attrName.startsWith('on')) {
182
+ // onAttr="modelProperty()"
183
+ // onAttr={modelProperty} // as an function
157
184
  element.addOutput(attrName.substring(2), value);
158
185
  }
159
186
  else {
@@ -1 +1 @@
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,KAAgB,EAAE,GAAG,QAA+B;QAEzF,IAAI,WAAW,CAAC,QAAQ,KAAK,OAAO,CAAC,WAAW,EAAE,EAAE;YACnD,OAAO,WAAW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AAC;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"]}
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,KAAgB,EAAE,GAAG,QAA+B;QAEzF,IAAI,WAAW,CAAC,QAAQ,KAAK,OAAO,CAAC,WAAW,EAAE,EAAE;YACnD,OAAO,WAAW,CAAC,kBAAkB,CAAC,GAAG,QAAQ,CAAC,CAAC;SACnD;QACD;;;;;WAKG;QACH,IAAI,iBAAiB,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;YACnC,OAAO,WAAW,CAAC,6BAA6B,CAAC,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,GAAG,QAAQ,CAAC,CAAC;SAClF;QACD;;WAEG;QACH,IAAI,WAAW,CAAC,YAAY,KAAK,OAAO,CAAC,iBAAiB,EAAE,IAAI,KAAK,EAAE;YACtE,IAAI,KAAK,EAAE;gBACV,IAAI,aAAa,GAAG,MAAM,CAAC,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;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"]}
@@ -1,6 +1,9 @@
1
1
  export interface AttrRef {
2
2
  readonly [attr: string]: string[];
3
3
  }
4
+ /**
5
+ * @see https://html.spec.whatwg.org/multipage/indices.html#elements-3
6
+ */
4
7
  export declare const GlobalAttributes: string[];
5
8
  export declare const Attrs: AttrRef;
6
9
  export declare function hasNativeAttr(element: string | HTMLElement, attr: string): boolean;
@@ -1,3 +1,6 @@
1
+ /**
2
+ * @see https://html.spec.whatwg.org/multipage/indices.html#elements-3
3
+ */
1
4
  export const GlobalAttributes = [
2
5
  'class',
3
6
  'id',
@@ -1 +1 @@
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,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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}"]}
1
+ {"version":3,"file":"attributes.js","sourceRoot":"","sources":["../../../src/elements/attributes/attributes.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC/B,OAAO;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AO,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":["export 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}"]}
@@ -1,5 +1,32 @@
1
+ /**
2
+ * form-associated elements
3
+ * A number of the elements are form-associated elements, which means they can have a form owner.
4
+ * @param tagName
5
+ */
1
6
  export declare function isFormElement(tagName: string): boolean;
7
+ /**
8
+ * submittable elements
9
+ * Denotes elements that can be used for constructing the entry list when a form element is submitted.
10
+ * @param tagName
11
+ */
2
12
  export declare function isSubmittableElement(tagName: string): boolean;
13
+ /**
14
+ * Resettable elements
15
+ * @param tagName
16
+ */
3
17
  export declare function isResettableElement(tagName: string): boolean;
18
+ /**
19
+ * Autocapitalize-inheriting elements
20
+ * Denotes elements that inherit the autocapitalize attribute from their form owner.
21
+ * @param tagName
22
+ */
4
23
  export declare function isAutocapitalizeInheritingElement(tagName: string): boolean;
24
+ /**
25
+ * Labelable Elements
26
+ * Some elements, not all of them form-associated, are categorized as labelable elements.
27
+ * These are elements that can be associated with a label element.
28
+ *
29
+ * this function ignore the 'type' attribute of 'input' tage as '<input type="hidden" />' is consdered as not labled element
30
+ * @param tagName the tested tag name
31
+ */
5
32
  export declare function isFormLabelableElement(tagName: string): boolean;
@@ -1,3 +1,8 @@
1
+ /**
2
+ * form-associated elements
3
+ * A number of the elements are form-associated elements, which means they can have a form owner.
4
+ * @param tagName
5
+ */
1
6
  export function isFormElement(tagName) {
2
7
  switch (tagName) {
3
8
  case 'button':
@@ -17,6 +22,11 @@ export function isFormElement(tagName) {
17
22
  default: return false;
18
23
  }
19
24
  }
25
+ /**
26
+ * submittable elements
27
+ * Denotes elements that can be used for constructing the entry list when a form element is submitted.
28
+ * @param tagName
29
+ */
20
30
  export function isSubmittableElement(tagName) {
21
31
  switch (tagName) {
22
32
  case 'button':
@@ -28,6 +38,10 @@ export function isSubmittableElement(tagName) {
28
38
  default: return false;
29
39
  }
30
40
  }
41
+ /**
42
+ * Resettable elements
43
+ * @param tagName
44
+ */
31
45
  export function isResettableElement(tagName) {
32
46
  switch (tagName) {
33
47
  case 'input':
@@ -38,6 +52,11 @@ export function isResettableElement(tagName) {
38
52
  default: return false;
39
53
  }
40
54
  }
55
+ /**
56
+ * Autocapitalize-inheriting elements
57
+ * Denotes elements that inherit the autocapitalize attribute from their form owner.
58
+ * @param tagName
59
+ */
41
60
  export function isAutocapitalizeInheritingElement(tagName) {
42
61
  switch (tagName) {
43
62
  case 'button':
@@ -50,6 +69,14 @@ export function isAutocapitalizeInheritingElement(tagName) {
50
69
  default: return false;
51
70
  }
52
71
  }
72
+ /**
73
+ * Labelable Elements
74
+ * Some elements, not all of them form-associated, are categorized as labelable elements.
75
+ * These are elements that can be associated with a label element.
76
+ *
77
+ * this function ignore the 'type' attribute of 'input' tage as '<input type="hidden" />' is consdered as not labled element
78
+ * @param tagName the tested tag name
79
+ */
53
80
  export function isFormLabelableElement(tagName) {
54
81
  switch (tagName) {
55
82
  case 'button':