vsn 0.1.24 → 0.1.28

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.
Files changed (244) hide show
  1. package/demo/demo.html +18 -7
  2. package/demo/vsn.js +1 -0
  3. package/dist/AST/ArithmeticAssignmentNode.d.ts +23 -0
  4. package/dist/AST/ArithmeticAssignmentNode.js +313 -0
  5. package/dist/AST/ArithmeticAssignmentNode.js.map +1 -0
  6. package/dist/AST/ArithmeticNode.d.ts +15 -0
  7. package/dist/AST/ArithmeticNode.js +114 -0
  8. package/dist/AST/ArithmeticNode.js.map +1 -0
  9. package/dist/AST/ArrayNode.d.ts +14 -0
  10. package/dist/AST/ArrayNode.js +114 -0
  11. package/dist/AST/ArrayNode.js.map +1 -0
  12. package/dist/AST/BlockNode.d.ts +11 -0
  13. package/dist/AST/BlockNode.js +98 -0
  14. package/dist/AST/BlockNode.js.map +1 -0
  15. package/dist/AST/BooleanLiteralNode.d.ts +5 -0
  16. package/dist/AST/BooleanLiteralNode.js +31 -0
  17. package/dist/AST/BooleanLiteralNode.js.map +1 -0
  18. package/dist/AST/ComparisonNode.d.ts +15 -0
  19. package/dist/AST/ComparisonNode.js +120 -0
  20. package/dist/AST/ComparisonNode.js.map +1 -0
  21. package/dist/AST/ConditionalNode.d.ts +13 -0
  22. package/dist/AST/ConditionalNode.js +95 -0
  23. package/dist/AST/ConditionalNode.js.map +1 -0
  24. package/dist/AST/ElementAttributeNode.d.ts +18 -0
  25. package/dist/AST/ElementAttributeNode.js +159 -0
  26. package/dist/AST/ElementAttributeNode.js.map +1 -0
  27. package/dist/AST/ElementQueryNode.d.ts +12 -0
  28. package/dist/AST/ElementQueryNode.js +111 -0
  29. package/dist/AST/ElementQueryNode.js.map +1 -0
  30. package/dist/AST/ElementStyleNode.d.ts +18 -0
  31. package/dist/AST/ElementStyleNode.js +159 -0
  32. package/dist/AST/ElementStyleNode.js.map +1 -0
  33. package/dist/AST/ForStatementNode.d.ts +17 -0
  34. package/dist/AST/ForStatementNode.js +121 -0
  35. package/dist/AST/ForStatementNode.js.map +1 -0
  36. package/dist/AST/FunctionArgumentNode.d.ts +11 -0
  37. package/dist/AST/FunctionArgumentNode.js +100 -0
  38. package/dist/AST/FunctionArgumentNode.js.map +1 -0
  39. package/dist/AST/FunctionCallNode.d.ts +13 -0
  40. package/dist/AST/FunctionCallNode.js +102 -0
  41. package/dist/AST/FunctionCallNode.js.map +1 -0
  42. package/dist/AST/IfStatementNode.d.ts +14 -0
  43. package/dist/AST/IfStatementNode.js +128 -0
  44. package/dist/AST/IfStatementNode.js.map +1 -0
  45. package/dist/AST/InNode.d.ts +15 -0
  46. package/dist/AST/InNode.js +107 -0
  47. package/dist/AST/InNode.js.map +1 -0
  48. package/dist/AST/IndexNode.d.ts +16 -0
  49. package/dist/AST/IndexNode.js +126 -0
  50. package/dist/AST/IndexNode.js.map +1 -0
  51. package/dist/AST/LiteralNode.d.ts +10 -0
  52. package/dist/AST/LiteralNode.js +74 -0
  53. package/dist/AST/LiteralNode.js.map +1 -0
  54. package/dist/AST/Node.d.ts +19 -0
  55. package/dist/AST/Node.js +117 -0
  56. package/dist/AST/Node.js.map +1 -0
  57. package/dist/AST/NotNode.d.ts +12 -0
  58. package/dist/AST/NotNode.js +103 -0
  59. package/dist/AST/NotNode.js.map +1 -0
  60. package/dist/AST/NumberLiteralNode.d.ts +5 -0
  61. package/dist/AST/NumberLiteralNode.js +36 -0
  62. package/dist/AST/NumberLiteralNode.js.map +1 -0
  63. package/dist/AST/ObjectNode.d.ts +14 -0
  64. package/dist/AST/ObjectNode.js +131 -0
  65. package/dist/AST/ObjectNode.js.map +1 -0
  66. package/dist/AST/RootScopeMemberNode.d.ts +11 -0
  67. package/dist/AST/RootScopeMemberNode.js +87 -0
  68. package/dist/AST/RootScopeMemberNode.js.map +1 -0
  69. package/dist/AST/ScopeMemberNode.d.ts +12 -0
  70. package/dist/AST/ScopeMemberNode.js +128 -0
  71. package/dist/AST/ScopeMemberNode.js.map +1 -0
  72. package/dist/AST/UnitLiteralNode.d.ts +15 -0
  73. package/dist/AST/UnitLiteralNode.js +72 -0
  74. package/dist/AST/UnitLiteralNode.js.map +1 -0
  75. package/dist/AST.d.ts +9 -61
  76. package/dist/AST.js +84 -1413
  77. package/dist/AST.js.map +1 -1
  78. package/dist/Attribute.d.ts +1 -1
  79. package/dist/Attribute.js +3 -3
  80. package/dist/Attribute.js.map +1 -1
  81. package/dist/Configuration.d.ts +1 -1
  82. package/dist/Configuration.js +4 -4
  83. package/dist/Configuration.js.map +1 -1
  84. package/dist/Controller.d.ts +12 -4
  85. package/dist/Controller.js +38 -6
  86. package/dist/Controller.js.map +1 -1
  87. package/dist/DOM/DOMObject.d.ts +1 -1
  88. package/dist/DOM/DOMObject.js +2 -2
  89. package/dist/DOM/DOMObject.js.map +1 -1
  90. package/dist/DOM.d.ts +1 -1
  91. package/dist/DOM.js +4 -4
  92. package/dist/DOM.js.map +1 -1
  93. package/dist/EventDispatcher.d.ts +29 -0
  94. package/dist/EventDispatcher.js +132 -0
  95. package/dist/EventDispatcher.js.map +1 -0
  96. package/dist/Formats.js +2 -2
  97. package/dist/Formats.js.map +1 -1
  98. package/dist/MessageList.d.ts +14 -0
  99. package/dist/MessageList.js +88 -0
  100. package/dist/MessageList.js.map +1 -0
  101. package/dist/Model/Field.d.ts +8 -0
  102. package/dist/Model/Field.js +38 -0
  103. package/dist/Model/Field.js.map +1 -0
  104. package/dist/Model.d.ts +12 -0
  105. package/dist/Model.js +61 -0
  106. package/dist/Model.js.map +1 -0
  107. package/dist/Registry.d.ts +5 -2
  108. package/dist/Registry.js +17 -16
  109. package/dist/Registry.js.map +1 -1
  110. package/dist/Scope/DynamicScopeData.d.ts +6 -0
  111. package/dist/Scope/DynamicScopeData.js +54 -0
  112. package/dist/Scope/DynamicScopeData.js.map +1 -0
  113. package/dist/Scope/QueryReference.d.ts +10 -0
  114. package/dist/Scope/QueryReference.js +103 -0
  115. package/dist/Scope/QueryReference.js.map +1 -0
  116. package/dist/Scope/ScopeData.d.ts +4 -0
  117. package/dist/Scope/ScopeData.js +40 -0
  118. package/dist/Scope/ScopeData.js.map +1 -0
  119. package/dist/Scope/ScopeDataAbstract.d.ts +22 -0
  120. package/dist/Scope/ScopeDataAbstract.js +137 -0
  121. package/dist/Scope/ScopeDataAbstract.js.map +1 -0
  122. package/dist/Scope/ScopeReference.d.ts +10 -0
  123. package/dist/Scope/ScopeReference.js +73 -0
  124. package/dist/Scope/ScopeReference.js.map +1 -0
  125. package/dist/Scope/ScopedVariableType.d.ts +6 -0
  126. package/dist/Scope/ScopedVariableType.js +14 -0
  127. package/dist/Scope/ScopedVariableType.js.map +1 -0
  128. package/dist/Scope/WrappedArray.d.ts +16 -0
  129. package/dist/Scope/WrappedArray.js +121 -0
  130. package/dist/Scope/WrappedArray.js.map +1 -0
  131. package/dist/Scope/properties/Property.d.ts +18 -0
  132. package/dist/Scope/properties/Property.js +93 -0
  133. package/dist/Scope/properties/Property.js.map +1 -0
  134. package/dist/Scope.d.ts +4 -48
  135. package/dist/Scope.js +39 -324
  136. package/dist/Scope.js.map +1 -1
  137. package/dist/SimplePromise.d.ts +42 -0
  138. package/dist/SimplePromise.js +217 -0
  139. package/dist/SimplePromise.js.map +1 -0
  140. package/dist/Tag.js +11 -5
  141. package/dist/Tag.js.map +1 -1
  142. package/dist/Types.d.ts +1 -0
  143. package/dist/Types.js +8 -1
  144. package/dist/Types.js.map +1 -1
  145. package/dist/Validators.d.ts +7 -0
  146. package/dist/Validators.js +54 -0
  147. package/dist/Validators.js.map +1 -0
  148. package/dist/attributes/Bind.js +1 -1
  149. package/dist/attributes/Bind.js.map +1 -1
  150. package/dist/attributes/JSONAttribute.js.map +1 -1
  151. package/dist/attributes/List.js +7 -7
  152. package/dist/attributes/List.js.map +1 -1
  153. package/dist/attributes/On.js +4 -1
  154. package/dist/attributes/On.js.map +1 -1
  155. package/dist/attributes/Radio.js +4 -2
  156. package/dist/attributes/Radio.js.map +1 -1
  157. package/dist/attributes/ScopeChange.js +1 -1
  158. package/dist/attributes/ScopeChange.js.map +1 -1
  159. package/dist/attributes/SetAttribute.js.map +1 -1
  160. package/dist/attributes/StandardAttribute.js +1 -1
  161. package/dist/attributes/StandardAttribute.js.map +1 -1
  162. package/dist/attributes/StyleAttribute.js +1 -1
  163. package/dist/attributes/StyleAttribute.js.map +1 -1
  164. package/dist/{Vision.d.ts → vsn.d.ts} +7 -2
  165. package/dist/{Vision.js → vsn.js} +21 -12
  166. package/dist/vsn.js.map +1 -0
  167. package/package.json +9 -13
  168. package/src/AST/ArithmeticAssignmentNode.ts +236 -0
  169. package/src/AST/ArithmeticNode.ts +52 -0
  170. package/src/AST/ArrayNode.ts +39 -0
  171. package/src/AST/BlockNode.ts +25 -0
  172. package/src/AST/BooleanLiteralNode.ts +10 -0
  173. package/src/AST/ComparisonNode.ts +57 -0
  174. package/src/AST/ConditionalNode.ts +36 -0
  175. package/src/AST/ElementAttributeNode.ts +63 -0
  176. package/src/AST/ElementQueryNode.ts +25 -0
  177. package/src/AST/ElementStyleNode.ts +63 -0
  178. package/src/AST/ForStatementNode.ts +59 -0
  179. package/src/AST/FunctionArgumentNode.ts +27 -0
  180. package/src/AST/FunctionCallNode.ts +32 -0
  181. package/src/AST/IfStatementNode.ts +67 -0
  182. package/src/AST/InNode.ts +46 -0
  183. package/src/AST/IndexNode.ts +61 -0
  184. package/src/AST/LiteralNode.ts +17 -0
  185. package/src/AST/Node.ts +71 -0
  186. package/src/AST/NotNode.ts +41 -0
  187. package/src/AST/NumberLiteralNode.ts +14 -0
  188. package/src/AST/ObjectNode.ts +55 -0
  189. package/src/AST/RootScopeMemberNode.ts +25 -0
  190. package/src/AST/ScopeMemberNode.ts +53 -0
  191. package/src/AST/UnitLiteralNode.ts +51 -0
  192. package/src/AST.ts +45 -1014
  193. package/src/Attribute.ts +2 -2
  194. package/src/Configuration.ts +3 -3
  195. package/src/Controller.ts +31 -6
  196. package/src/DOM/DOMObject.ts +1 -1
  197. package/src/DOM.ts +4 -4
  198. package/src/EventDispatcher.ts +134 -0
  199. package/src/Formats.ts +2 -2
  200. package/src/MessageList.ts +81 -0
  201. package/src/Model/Field.ts +20 -0
  202. package/src/Model.ts +43 -0
  203. package/src/Registry.ts +13 -5
  204. package/src/Scope/DynamicScopeData.ts +29 -0
  205. package/src/Scope/QueryReference.ts +29 -0
  206. package/src/Scope/ScopeData.ts +21 -0
  207. package/src/Scope/ScopeDataAbstract.ts +126 -0
  208. package/src/Scope/ScopeReference.ts +30 -0
  209. package/src/Scope/ScopedVariableType.ts +7 -0
  210. package/src/Scope/WrappedArray.ts +88 -0
  211. package/src/Scope/properties/Property.ts +79 -0
  212. package/src/Scope.ts +35 -251
  213. package/src/SimplePromise.ts +219 -0
  214. package/src/Tag.ts +9 -5
  215. package/src/Types.ts +6 -1
  216. package/src/Validators.ts +45 -0
  217. package/src/attributes/Bind.ts +3 -2
  218. package/src/attributes/JSONAttribute.ts +2 -1
  219. package/src/attributes/List.ts +4 -4
  220. package/src/attributes/On.ts +2 -0
  221. package/src/attributes/Radio.ts +5 -3
  222. package/src/attributes/ScopeChange.ts +2 -2
  223. package/src/attributes/SetAttribute.ts +2 -1
  224. package/src/attributes/StandardAttribute.ts +1 -1
  225. package/src/attributes/StyleAttribute.ts +3 -2
  226. package/src/attributes/TypeAttribute.ts +1 -1
  227. package/src/{Vision.ts → vsn.ts} +12 -5
  228. package/test/AST/ArithmeticAssignmentNode.spec.ts +47 -0
  229. package/test/AST.spec.ts +3 -2
  230. package/test/Controller.spec.ts +44 -0
  231. package/test/DOM.spec.ts +1 -1
  232. package/test/MessageList.spec.ts +101 -0
  233. package/test/Model/DataModel.spec.ts +0 -0
  234. package/test/Scope/DynamicScopeData.spec.ts +141 -0
  235. package/test/Scope.spec.ts +15 -3
  236. package/test/SimplePromise.spec.ts +271 -0
  237. package/test/Tag/TagList.spec.ts +1 -1
  238. package/test/attributes/Bind.spec.ts +5 -5
  239. package/test/attributes/JSONAttribute.spec.ts +1 -1
  240. package/test/attributes/ListItem.spec.ts +1 -1
  241. package/webpack.config.js +2 -2
  242. package/demo/vision.js +0 -1
  243. package/dist/Vision.js.map +0 -1
  244. package/main.py +0 -16
@@ -0,0 +1,55 @@
1
+ import {Scope} from "../Scope";
2
+ import {DOM} from "../DOM";
3
+ import {Tag} from "../Tag";
4
+ import {BlockType, Token, TokenType, Tree, TreeNode} from "../AST";
5
+ import {Node} from "./Node";
6
+
7
+ export class ObjectNode extends Node implements TreeNode {
8
+ constructor(
9
+ public readonly keys: Node[],
10
+ public readonly values: Node[]
11
+ ) {
12
+ super();
13
+ }
14
+
15
+ protected _getChildNodes(): Node[] {
16
+ return new Array(...this.values);
17
+ }
18
+
19
+ async evaluate(scope: Scope, dom: DOM, tag: Tag = null) {
20
+ const obj: Scope = new Scope();
21
+ for (let i = 0; i < this.values.length; i++) {
22
+ const key = this.keys[i];
23
+ const val = this.values[i];
24
+ obj.set(await key.evaluate(scope, dom, tag), await val.evaluate(scope, dom, tag));
25
+ }
26
+ return obj;
27
+ }
28
+
29
+ public static match(tokens: Token[]): boolean {
30
+ return tokens[0].type === TokenType.L_BRACE;
31
+ }
32
+
33
+ public static parse(lastNode, token, tokens: Token[]): ObjectNode {
34
+ const valueTokens: Token[] = Tree.getNextStatementTokens(tokens);
35
+ const keys: Node[] = [];
36
+ const values: Node[] = [];
37
+
38
+ while (valueTokens.length > 0) {
39
+ const key: Token[] = Tree.getTokensUntil(valueTokens, TokenType.COLON, false);
40
+ if (valueTokens[0].type !== TokenType.COLON)
41
+ throw Error('Invalid object literal syntax. Expecting :');
42
+ valueTokens.splice(0, 1); // Consume :
43
+ const val: Token[] = Tree.getTokensUntil(valueTokens, TokenType.COMMA, true, false, true, {
44
+ type: BlockType.STATEMENT,
45
+ open: null,
46
+ close: null,
47
+ openCharacter: null,
48
+ closeCharacter: null
49
+ });
50
+ keys.push(Tree.processTokens(key));
51
+ values.push(Tree.processTokens(val));
52
+ }
53
+ return new ObjectNode(keys, values);
54
+ }
55
+ }
@@ -0,0 +1,25 @@
1
+ import {Scope} from "../Scope";
2
+ import {DOM} from "../DOM";
3
+ import {Tag} from "../Tag";
4
+ import {TreeNode} from "../AST";
5
+ import {Node} from "./Node";
6
+
7
+ export class RootScopeMemberNode<T = any> extends Node implements TreeNode {
8
+ constructor(
9
+ public readonly name: TreeNode<string>
10
+ ) {
11
+ super();
12
+ }
13
+
14
+ protected _getChildNodes(): Node[] {
15
+ return [
16
+ this.name as Node
17
+ ]
18
+ }
19
+
20
+ async evaluate(scope: Scope, dom: DOM, tag: Tag = null) {
21
+ const name = await this.name.evaluate(scope, dom, tag);
22
+ const value = scope.get(name);
23
+ return value instanceof Scope && value.wrapped || value;
24
+ }
25
+ }
@@ -0,0 +1,53 @@
1
+ import {Scope} from "../Scope";
2
+ import {DOM} from "../DOM";
3
+ import {Tag} from "../Tag";
4
+ import {TagList} from "../Tag/List";
5
+ import {DOMObject} from "../DOM/DOMObject";
6
+ import {TreeNode} from "../AST";
7
+ import {Node} from "./Node";
8
+ import {ElementQueryNode} from "./ElementQueryNode";
9
+
10
+ export class ScopeMemberNode extends Node implements TreeNode {
11
+ constructor(
12
+ public readonly scope: TreeNode<Scope>,
13
+ public readonly name: TreeNode<string>
14
+ ) {
15
+ super();
16
+ }
17
+
18
+ protected _getChildNodes(): Node[] {
19
+ return [
20
+ this.scope as Node,
21
+ this.name as Node
22
+ ]
23
+ }
24
+
25
+ async evaluate(scope: Scope, dom: DOM, tag: Tag = null) {
26
+ let scopes = [];
27
+ const values = [];
28
+
29
+ if (this.scope instanceof ElementQueryNode) {
30
+ scopes = await this.scope.evaluate(scope, dom, tag);
31
+ } else {
32
+ const evalScope = await this.scope.evaluate(scope, dom, tag);
33
+ if (evalScope instanceof TagList) {
34
+ scopes = evalScope;
35
+ } else {
36
+ scopes.push(evalScope);
37
+ }
38
+ }
39
+
40
+ for (let parent of scopes) {
41
+ if (parent instanceof DOMObject)
42
+ parent = parent.scope;
43
+
44
+ if (!parent) {
45
+ throw Error(`Cannot access "${await this.name.evaluate(scope, dom, tag)}" of undefined.`);
46
+ }
47
+ const name = await this.name.evaluate(scope, dom, tag);
48
+ const value: any = parent.get(name, false);
49
+ values.push(value instanceof Scope && value.wrapped || value);
50
+ }
51
+ return values.length === 1 ? values[0] : values;
52
+ }
53
+ }
@@ -0,0 +1,51 @@
1
+ import {LiteralNode} from "./LiteralNode";
2
+
3
+ export class UnitLiteral {
4
+ protected _amount: number;
5
+ protected _unit: string;
6
+
7
+ constructor(
8
+ protected _value: any
9
+ ) {
10
+ this.value = this._value;
11
+ }
12
+
13
+ get amount(): number {
14
+ return this._amount;
15
+ }
16
+
17
+ get unit(): string {
18
+ return this._unit;
19
+ }
20
+
21
+ get value(): string {
22
+ return `${this._amount}${this._unit}`;
23
+ }
24
+
25
+ set value(value: string) {
26
+ if (value.indexOf('.') > -1) {
27
+ this._amount = parseFloat(value)
28
+ } else {
29
+ this._amount = parseInt(value);
30
+ }
31
+
32
+ if (isNaN(this._amount))
33
+ this._amount = 0;
34
+
35
+ const unit = /[^\d.]+$/.exec(value);
36
+ this._unit = unit && unit[0] || '';
37
+ }
38
+
39
+ public toString() {
40
+ return this.value;
41
+ }
42
+ }
43
+
44
+
45
+ export class UnitLiteralNode extends LiteralNode<UnitLiteral> {
46
+ constructor(
47
+ _value: any
48
+ ) {
49
+ super(new UnitLiteral(_value));
50
+ }
51
+ }