vsn 0.1.24 → 0.1.26

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 (127) hide show
  1. package/demo/demo.html +16 -7
  2. package/demo/vsn.js +1 -0
  3. package/dist/AST.d.ts +2 -1
  4. package/dist/Controller.d.ts +8 -2
  5. package/dist/Model.d.ts +0 -0
  6. package/dist/{Vision.d.ts → vsn.d.ts} +1 -0
  7. package/dist/vsn.min.js +1 -0
  8. package/package.json +8 -8
  9. package/src/AST.ts +94 -3
  10. package/src/Controller.ts +21 -4
  11. package/src/DOM.ts +1 -1
  12. package/src/Model.ts +0 -0
  13. package/src/Registry.ts +0 -2
  14. package/src/Scope.ts +6 -1
  15. package/src/Tag.ts +8 -4
  16. package/src/attributes/On.ts +2 -0
  17. package/src/attributes/Radio.ts +2 -1
  18. package/src/{Vision.ts → vsn.ts} +1 -0
  19. package/test/DOM.spec.ts +1 -1
  20. package/test/attributes/JSONAttribute.spec.ts +1 -1
  21. package/webpack.config.js +2 -2
  22. package/demo/vision.js +0 -1
  23. package/dist/AST.js +0 -2107
  24. package/dist/AST.js.map +0 -1
  25. package/dist/Attribute.js +0 -187
  26. package/dist/Attribute.js.map +0 -1
  27. package/dist/Bencmark.js +0 -179
  28. package/dist/Bencmark.js.map +0 -1
  29. package/dist/Configuration.js +0 -64
  30. package/dist/Configuration.js.map +0 -1
  31. package/dist/Controller.js +0 -30
  32. package/dist/Controller.js.map +0 -1
  33. package/dist/DOM/DOMObject.js +0 -47
  34. package/dist/DOM/DOMObject.js.map +0 -1
  35. package/dist/DOM/WrappedDocument.js +0 -34
  36. package/dist/DOM/WrappedDocument.js.map +0 -1
  37. package/dist/DOM/WrappedWindow.js +0 -45
  38. package/dist/DOM/WrappedWindow.js.map +0 -1
  39. package/dist/DOM.js +0 -547
  40. package/dist/DOM.js.map +0 -1
  41. package/dist/Formats.js +0 -44
  42. package/dist/Formats.js.map +0 -1
  43. package/dist/Query.js +0 -66
  44. package/dist/Query.js.map +0 -1
  45. package/dist/Registry.js +0 -138
  46. package/dist/Registry.js.map +0 -1
  47. package/dist/Scope.js +0 -512
  48. package/dist/Scope.js.map +0 -1
  49. package/dist/Tag/List.js +0 -85
  50. package/dist/Tag/List.js.map +0 -1
  51. package/dist/Tag.js +0 -764
  52. package/dist/Tag.js.map +0 -1
  53. package/dist/Types.js +0 -48
  54. package/dist/Types.js.map +0 -1
  55. package/dist/Vision.js +0 -162
  56. package/dist/Vision.js.map +0 -1
  57. package/dist/attributes/AddClassIf.js +0 -93
  58. package/dist/attributes/AddClassIf.js.map +0 -1
  59. package/dist/attributes/Bind.js +0 -272
  60. package/dist/attributes/Bind.js.map +0 -1
  61. package/dist/attributes/ClassConstructor.js +0 -104
  62. package/dist/attributes/ClassConstructor.js.map +0 -1
  63. package/dist/attributes/ClickRemoveClass.js +0 -114
  64. package/dist/attributes/ClickRemoveClass.js.map +0 -1
  65. package/dist/attributes/ClickToggleClass.js +0 -114
  66. package/dist/attributes/ClickToggleClass.js.map +0 -1
  67. package/dist/attributes/ControllerAttribute.js +0 -28
  68. package/dist/attributes/ControllerAttribute.js.map +0 -1
  69. package/dist/attributes/DisableIf.js +0 -94
  70. package/dist/attributes/DisableIf.js.map +0 -1
  71. package/dist/attributes/Exec.js +0 -108
  72. package/dist/attributes/Exec.js.map +0 -1
  73. package/dist/attributes/Format.js +0 -99
  74. package/dist/attributes/Format.js.map +0 -1
  75. package/dist/attributes/If.js +0 -159
  76. package/dist/attributes/If.js.map +0 -1
  77. package/dist/attributes/JSONAttribute.js +0 -118
  78. package/dist/attributes/JSONAttribute.js.map +0 -1
  79. package/dist/attributes/KeyAbstract.js +0 -117
  80. package/dist/attributes/KeyAbstract.js.map +0 -1
  81. package/dist/attributes/KeyDown.js +0 -88
  82. package/dist/attributes/KeyDown.js.map +0 -1
  83. package/dist/attributes/KeyUp.js +0 -88
  84. package/dist/attributes/KeyUp.js.map +0 -1
  85. package/dist/attributes/List.js +0 -282
  86. package/dist/attributes/List.js.map +0 -1
  87. package/dist/attributes/ListItem.js +0 -138
  88. package/dist/attributes/ListItem.js.map +0 -1
  89. package/dist/attributes/ListItemModel.js +0 -39
  90. package/dist/attributes/ListItemModel.js.map +0 -1
  91. package/dist/attributes/ModelAttribute.js +0 -29
  92. package/dist/attributes/ModelAttribute.js.map +0 -1
  93. package/dist/attributes/Name.js +0 -88
  94. package/dist/attributes/Name.js.map +0 -1
  95. package/dist/attributes/On.js +0 -132
  96. package/dist/attributes/On.js.map +0 -1
  97. package/dist/attributes/Radio.js +0 -172
  98. package/dist/attributes/Radio.js.map +0 -1
  99. package/dist/attributes/Referenced.js +0 -38
  100. package/dist/attributes/Referenced.js.map +0 -1
  101. package/dist/attributes/RootAttribute.js +0 -91
  102. package/dist/attributes/RootAttribute.js.map +0 -1
  103. package/dist/attributes/ScopeAttribute.js +0 -40
  104. package/dist/attributes/ScopeAttribute.js.map +0 -1
  105. package/dist/attributes/ScopeChange.js +0 -130
  106. package/dist/attributes/ScopeChange.js.map +0 -1
  107. package/dist/attributes/SetAttribute.js +0 -133
  108. package/dist/attributes/SetAttribute.js.map +0 -1
  109. package/dist/attributes/StandardAttribute.js +0 -186
  110. package/dist/attributes/StandardAttribute.js.map +0 -1
  111. package/dist/attributes/StyleAttribute.js +0 -183
  112. package/dist/attributes/StyleAttribute.js.map +0 -1
  113. package/dist/attributes/Template.js +0 -39
  114. package/dist/attributes/Template.js.map +0 -1
  115. package/dist/attributes/TypeAttribute.js +0 -104
  116. package/dist/attributes/TypeAttribute.js.map +0 -1
  117. package/dist/attributes/_imports.js +0 -60
  118. package/dist/attributes/_imports.js.map +0 -1
  119. package/dist/helpers/DOMHelper.js +0 -81
  120. package/dist/helpers/DOMHelper.js.map +0 -1
  121. package/dist/helpers/ElementHelper.js +0 -25
  122. package/dist/helpers/ElementHelper.js.map +0 -1
  123. package/dist/helpers/VisionHelper.js +0 -71
  124. package/dist/helpers/VisionHelper.js.map +0 -1
  125. package/dist/helpers/decorators.js +0 -38
  126. package/dist/helpers/decorators.js.map +0 -1
  127. package/main.py +0 -16
package/dist/Tag.js DELETED
@@ -1,764 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
- return new (P || (P = Promise))(function (resolve, reject) {
20
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
- step((generator = generator.apply(thisArg, _arguments || [])).next());
24
- });
25
- };
26
- var __generator = (this && this.__generator) || function (thisArg, body) {
27
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
- function verb(n) { return function (v) { return step([n, v]); }; }
30
- function step(op) {
31
- if (f) throw new TypeError("Generator is already executing.");
32
- while (_) try {
33
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
- if (y = 0, t) op = [op[0] & 2, t.value];
35
- switch (op[0]) {
36
- case 0: case 1: t = op; break;
37
- case 4: _.label++; return { value: op[1], done: false };
38
- case 5: _.label++; y = op[1]; op = [0]; continue;
39
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
- default:
41
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
- if (t[2]) _.ops.pop();
46
- _.trys.pop(); continue;
47
- }
48
- op = body.call(thisArg, _);
49
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
- }
52
- };
53
- var __spreadArray = (this && this.__spreadArray) || function (to, from) {
54
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
55
- to[j] = from[i];
56
- return to;
57
- };
58
- Object.defineProperty(exports, "__esModule", { value: true });
59
- exports.Tag = exports.TagState = void 0;
60
- var Scope_1 = require("./Scope");
61
- var Attribute_1 = require("./Attribute");
62
- var VisionHelper_1 = require("./helpers/VisionHelper");
63
- var StandardAttribute_1 = require("./attributes/StandardAttribute");
64
- var On_1 = require("./attributes/On");
65
- var Registry_1 = require("./Registry");
66
- var Bencmark_1 = require("./Bencmark");
67
- var DOMObject_1 = require("./DOM/DOMObject");
68
- var AST_1 = require("./AST");
69
- var StyleAttribute_1 = require("./attributes/StyleAttribute");
70
- var TagState;
71
- (function (TagState) {
72
- TagState[TagState["Instantiated"] = 0] = "Instantiated";
73
- TagState[TagState["AttributesBuilt"] = 1] = "AttributesBuilt";
74
- TagState[TagState["AttributesCompiled"] = 2] = "AttributesCompiled";
75
- TagState[TagState["AttributesSetup"] = 3] = "AttributesSetup";
76
- TagState[TagState["AttributesExtracted"] = 4] = "AttributesExtracted";
77
- TagState[TagState["AttributesConnected"] = 5] = "AttributesConnected";
78
- TagState[TagState["Built"] = 6] = "Built";
79
- })(TagState = exports.TagState || (exports.TagState = {}));
80
- var Tag = /** @class */ (function (_super) {
81
- __extends(Tag, _super);
82
- function Tag(element, dom) {
83
- var props = [];
84
- for (var _i = 2; _i < arguments.length; _i++) {
85
- props[_i - 2] = arguments[_i];
86
- }
87
- var _this = _super.call(this, element, props) || this;
88
- _this.dom = dom;
89
- _this.deferredAttributes = [];
90
- _this._nonDeferredAttributes = [];
91
- _this._children = [];
92
- _this.inputTags = [
93
- 'input',
94
- 'select',
95
- 'textarea'
96
- ];
97
- _this.rawAttributes = {};
98
- _this.parsedAttributes = {};
99
- _this.attributes = [];
100
- _this.onEventHandlers = {};
101
- _this.analyzeElementAttributes();
102
- _this._state = TagState.Instantiated;
103
- if (VisionHelper_1.VisionHelper.window) {
104
- if (!VisionHelper_1.VisionHelper.window['Tags']) {
105
- VisionHelper_1.VisionHelper.window['Tags'] = [];
106
- VisionHelper_1.VisionHelper.window['Attributes'] = [];
107
- }
108
- VisionHelper_1.VisionHelper.window['Tags'].push(_this);
109
- }
110
- return _this;
111
- }
112
- Object.defineProperty(Tag.prototype, "uniqueScope", {
113
- get: function () {
114
- return this._uniqueScope;
115
- },
116
- enumerable: false,
117
- configurable: true
118
- });
119
- ;
120
- Tag.prototype.onAttributeStateChange = function (event) {
121
- if (event.previouseState === Attribute_1.AttributeState.Deferred)
122
- this._nonDeferredAttributes.length = 0;
123
- };
124
- Object.defineProperty(Tag.prototype, "nonDeferredAttributes", {
125
- get: function () {
126
- if (this._nonDeferredAttributes.length > 0)
127
- return this._nonDeferredAttributes;
128
- var attrs = [];
129
- for (var _i = 0, _a = this.attributes; _i < _a.length; _i++) {
130
- var attribute = _a[_i];
131
- if (attribute.state === Attribute_1.AttributeState.Deferred)
132
- continue;
133
- attrs.push(attribute);
134
- }
135
- this._nonDeferredAttributes = attrs;
136
- return attrs;
137
- },
138
- enumerable: false,
139
- configurable: true
140
- });
141
- Object.defineProperty(Tag.prototype, "style", {
142
- get: function () {
143
- return this.element.style;
144
- },
145
- enumerable: false,
146
- configurable: true
147
- });
148
- Object.defineProperty(Tag.prototype, "computedStyle", {
149
- get: function () {
150
- return VisionHelper_1.VisionHelper.window && window.getComputedStyle(this.element) || null;
151
- },
152
- enumerable: false,
153
- configurable: true
154
- });
155
- Tag.prototype.analyzeElementAttributes = function () {
156
- if (!this.element.attributes || this.element.attributes.length <= 0)
157
- return;
158
- for (var i = 0; i < this.element.attributes.length; i++) {
159
- var a = this.element.attributes[i];
160
- this.rawAttributes[a.name] = a.value;
161
- if (a.name.indexOf(':') > -1) {
162
- var nameParts = a.name.split(':');
163
- var values = nameParts.slice(1);
164
- values.push(a.value);
165
- this.parsedAttributes[nameParts[0]] = values;
166
- }
167
- else {
168
- this.parsedAttributes[a.name] = [null, a.value];
169
- }
170
- }
171
- };
172
- Tag.prototype.eval = function (code) {
173
- return __awaiter(this, void 0, void 0, function () {
174
- var tree;
175
- return __generator(this, function (_a) {
176
- switch (_a.label) {
177
- case 0:
178
- tree = new AST_1.Tree(code);
179
- return [4 /*yield*/, tree.prepare(this.scope, this.dom, this)];
180
- case 1:
181
- _a.sent();
182
- return [4 /*yield*/, tree.evaluate(this.scope, this.dom, this)];
183
- case 2: return [2 /*return*/, _a.sent()];
184
- }
185
- });
186
- });
187
- };
188
- Tag.prototype.evaluate = function () {
189
- return __awaiter(this, void 0, void 0, function () {
190
- var _i, _a, attr;
191
- return __generator(this, function (_b) {
192
- switch (_b.label) {
193
- case 0:
194
- _i = 0, _a = this.nonDeferredAttributes;
195
- _b.label = 1;
196
- case 1:
197
- if (!(_i < _a.length)) return [3 /*break*/, 4];
198
- attr = _a[_i];
199
- return [4 /*yield*/, attr.evaluate()];
200
- case 2:
201
- _b.sent();
202
- _b.label = 3;
203
- case 3:
204
- _i++;
205
- return [3 /*break*/, 1];
206
- case 4: return [2 /*return*/];
207
- }
208
- });
209
- });
210
- };
211
- Tag.prototype.mutate = function (mutation) {
212
- for (var _i = 0, _a = this.attributes; _i < _a.length; _i++) {
213
- var attr = _a[_i];
214
- attr.mutate(mutation);
215
- }
216
- this.trigger('mutate', mutation);
217
- };
218
- Tag.prototype.get = function (attr) {
219
- this.element.getAttribute(attr);
220
- };
221
- Tag.prototype.set = function (attr, value) {
222
- this.element.setAttribute(attr, value);
223
- };
224
- Tag.prototype.getAttributeClass = function (attr) {
225
- return __awaiter(this, void 0, void 0, function () {
226
- return __generator(this, function (_a) {
227
- if (!attr.startsWith('vsn-'))
228
- return [2 /*return*/, null];
229
- attr = this.getAttributeName(attr);
230
- return [2 /*return*/, Registry_1.Registry.instance.attributes.get(attr)];
231
- });
232
- });
233
- };
234
- Tag.prototype.getAttributeName = function (attr) {
235
- attr = attr.split('|')[0];
236
- if (attr.indexOf(':') > -1) {
237
- var parts = attr.split(':');
238
- attr = parts[0];
239
- }
240
- return attr;
241
- };
242
- Tag.prototype.getAttributeBinding = function (attr) {
243
- attr = attr.split('|')[0];
244
- if (attr.indexOf(':') > -1) {
245
- var parts = attr.split(':');
246
- return parts[1];
247
- }
248
- return null;
249
- };
250
- Tag.prototype.getAttributeModifiers = function (attr) {
251
- return attr.split('|').splice(1);
252
- };
253
- Object.defineProperty(Tag.prototype, "isInput", {
254
- get: function () {
255
- return this.inputTags.indexOf(this.element.tagName.toLowerCase()) > -1;
256
- },
257
- enumerable: false,
258
- configurable: true
259
- });
260
- Object.defineProperty(Tag.prototype, "value", {
261
- get: function () {
262
- if (this.isInput) {
263
- return this.element.value;
264
- }
265
- else {
266
- return this.element.textContent;
267
- }
268
- },
269
- set: function (value) {
270
- if (this.isInput) {
271
- this.element.setAttribute('value', value);
272
- this.element.value = value;
273
- }
274
- else {
275
- this.element.innerText = value;
276
- }
277
- },
278
- enumerable: false,
279
- configurable: true
280
- });
281
- Object.defineProperty(Tag.prototype, "checked", {
282
- get: function () {
283
- if (this.isInput) {
284
- return this.element.checked;
285
- }
286
- else {
287
- return false;
288
- }
289
- },
290
- set: function (value) {
291
- if (this.isInput) {
292
- if (value) {
293
- this.element.setAttribute('checked', '');
294
- this.element.checked = true;
295
- }
296
- else {
297
- this.element.removeAttribute('checked');
298
- this.element.checked = false;
299
- }
300
- }
301
- },
302
- enumerable: false,
303
- configurable: true
304
- });
305
- Tag.prototype.addChild = function (tag) {
306
- this._children.push(tag);
307
- };
308
- Object.defineProperty(Tag.prototype, "children", {
309
- get: function () {
310
- return __spreadArray([], this._children);
311
- },
312
- enumerable: false,
313
- configurable: true
314
- });
315
- Object.defineProperty(Tag.prototype, "parentTag", {
316
- get: function () {
317
- return this._parentTag;
318
- },
319
- set: function (tag) {
320
- if (this.element === document.body)
321
- return;
322
- this._parentTag = tag;
323
- tag.addChild(this);
324
- if (this.scope !== tag.scope)
325
- this.scope.parentScope = tag.scope;
326
- },
327
- enumerable: false,
328
- configurable: true
329
- });
330
- Object.defineProperty(Tag.prototype, "scope", {
331
- get: function () {
332
- if (!!this._scope)
333
- return this._scope;
334
- if (!!this._parentTag)
335
- return this._parentTag.scope;
336
- return null;
337
- },
338
- enumerable: false,
339
- configurable: true
340
- });
341
- Object.defineProperty(Tag.prototype, "controller", {
342
- get: function () {
343
- return this._controller;
344
- },
345
- set: function (controller) {
346
- this._controller = controller;
347
- },
348
- enumerable: false,
349
- configurable: true
350
- });
351
- Tag.prototype.wrap = function (obj, triggerUpdates, updateFromWrapped) {
352
- if (triggerUpdates === void 0) { triggerUpdates = false; }
353
- if (updateFromWrapped === void 0) { updateFromWrapped = true; }
354
- if (VisionHelper_1.VisionHelper.isConstructor(obj)) {
355
- obj = new obj();
356
- }
357
- this.scope.wrap(obj, triggerUpdates, updateFromWrapped);
358
- obj['$scope'] = this.scope;
359
- obj['$tag'] = this;
360
- obj['$el'] = this.element;
361
- return obj;
362
- };
363
- Tag.prototype.unwrap = function () {
364
- this.scope.unwrap();
365
- };
366
- Tag.prototype.removeFromDOM = function () {
367
- this.element.remove();
368
- };
369
- Tag.prototype.addToParentElement = function () {
370
- this._parentTag.element.appendChild(this.element);
371
- };
372
- Tag.prototype.hide = function () {
373
- this.element.hidden = true;
374
- };
375
- Tag.prototype.show = function () {
376
- this.element.hidden = false;
377
- };
378
- Tag.prototype.findAncestorByAttribute = function (attr) {
379
- if (this.hasAttribute(attr))
380
- return this;
381
- return this.parentTag ? this.parentTag.findAncestorByAttribute(attr) : null;
382
- };
383
- Tag.prototype.hasAttribute = function (attr) {
384
- return !!this.parsedAttributes[attr];
385
- };
386
- Tag.prototype.getAttribute = function (key) {
387
- return __awaiter(this, void 0, void 0, function () {
388
- var cls, _i, _a, attr;
389
- return __generator(this, function (_b) {
390
- switch (_b.label) {
391
- case 0: return [4 /*yield*/, Registry_1.Registry.instance.attributes.get(key)];
392
- case 1:
393
- cls = _b.sent();
394
- if (!cls)
395
- return [2 /*return*/];
396
- for (_i = 0, _a = this.attributes; _i < _a.length; _i++) {
397
- attr = _a[_i];
398
- if (attr instanceof cls)
399
- return [2 /*return*/, attr];
400
- }
401
- return [2 /*return*/];
402
- }
403
- });
404
- });
405
- };
406
- Tag.prototype.getRawAttributeValue = function (key, fallback) {
407
- if (fallback === void 0) { fallback = null; }
408
- return this.rawAttributes[key] ? this.rawAttributes[key] : fallback;
409
- };
410
- Tag.prototype.hasRawAttribute = function (mod) {
411
- return this.getRawAttributeValue(mod, undefined) !== undefined;
412
- };
413
- Tag.prototype.getParsedAttributeValue = function (key, index, fallback) {
414
- if (index === void 0) { index = 0; }
415
- if (fallback === void 0) { fallback = null; }
416
- return this.parsedAttributes[key] && this.parsedAttributes[key][index] || fallback;
417
- };
418
- Tag.prototype.buildAttributes = function () {
419
- return __awaiter(this, void 0, void 0, function () {
420
- var requiresScope, defer, isMobile, _a, _b, _i, attr, attrClass, attrObj;
421
- return __generator(this, function (_c) {
422
- switch (_c.label) {
423
- case 0:
424
- requiresScope = false;
425
- defer = false;
426
- this.attributes.length = 0;
427
- isMobile = VisionHelper_1.VisionHelper.isMobile();
428
- if (this.element.offsetParent === null ||
429
- this.hasAttribute('hidden') ||
430
- this.hasAttribute('vsn-defer')) {
431
- defer = true;
432
- }
433
- _a = [];
434
- for (_b in this.rawAttributes)
435
- _a.push(_b);
436
- _i = 0;
437
- _c.label = 1;
438
- case 1:
439
- if (!(_i < _a.length)) return [3 /*break*/, 5];
440
- attr = _a[_i];
441
- if (this.hasModifier(attr, 'mobile')) {
442
- if (!isMobile) {
443
- return [3 /*break*/, 4];
444
- }
445
- }
446
- if (this.hasModifier(attr, 'desktop')) {
447
- if (isMobile) {
448
- return [3 /*break*/, 4];
449
- }
450
- }
451
- return [4 /*yield*/, this.getAttributeClass(attr)];
452
- case 2:
453
- attrClass = _c.sent();
454
- if (!attrClass) return [3 /*break*/, 4];
455
- if (attrClass.scoped)
456
- requiresScope = true;
457
- attrObj = new attrClass(this, attr);
458
- this.attributes.push(attrObj);
459
- if (!(defer && attrClass.canDefer)) return [3 /*break*/, 4];
460
- return [4 /*yield*/, attrObj.defer()];
461
- case 3:
462
- _c.sent();
463
- this.deferredAttributes.push(attrObj);
464
- attrObj.bind('state', this.onAttributeStateChange.bind(this));
465
- _c.label = 4;
466
- case 4:
467
- _i++;
468
- return [3 /*break*/, 1];
469
- case 5:
470
- if (this.element.getAttribute('id'))
471
- requiresScope = true;
472
- if (requiresScope && !this.uniqueScope) {
473
- this._uniqueScope = true;
474
- this._scope = new Scope_1.Scope();
475
- }
476
- this._state = TagState.AttributesBuilt;
477
- return [2 /*return*/];
478
- }
479
- });
480
- });
481
- };
482
- Tag.prototype.compileAttributes = function () {
483
- return __awaiter(this, void 0, void 0, function () {
484
- var _i, _a, attr;
485
- return __generator(this, function (_b) {
486
- switch (_b.label) {
487
- case 0:
488
- _i = 0, _a = this.nonDeferredAttributes;
489
- _b.label = 1;
490
- case 1:
491
- if (!(_i < _a.length)) return [3 /*break*/, 4];
492
- attr = _a[_i];
493
- return [4 /*yield*/, attr.compile()];
494
- case 2:
495
- _b.sent();
496
- _b.label = 3;
497
- case 3:
498
- _i++;
499
- return [3 /*break*/, 1];
500
- case 4:
501
- this._state = TagState.AttributesCompiled;
502
- return [2 /*return*/];
503
- }
504
- });
505
- });
506
- };
507
- Tag.prototype.setupAttributes = function () {
508
- return __awaiter(this, void 0, void 0, function () {
509
- var _i, _a, attr;
510
- return __generator(this, function (_b) {
511
- switch (_b.label) {
512
- case 0:
513
- if (VisionHelper_1.VisionHelper.doBenchmark)
514
- Bencmark_1.benchmarkStart('Tag.setupAttributes');
515
- _i = 0, _a = this.nonDeferredAttributes;
516
- _b.label = 1;
517
- case 1:
518
- if (!(_i < _a.length)) return [3 /*break*/, 4];
519
- attr = _a[_i];
520
- return [4 /*yield*/, attr.setup()];
521
- case 2:
522
- _b.sent();
523
- _b.label = 3;
524
- case 3:
525
- _i++;
526
- return [3 /*break*/, 1];
527
- case 4:
528
- if (VisionHelper_1.VisionHelper.doBenchmark)
529
- Bencmark_1.benchmarkEnd('Tag.setupAttributes', 'Attribute.setup');
530
- this.dom.registerElementInRoot(this);
531
- if (VisionHelper_1.VisionHelper.doBenchmark)
532
- Bencmark_1.benchmarkEnd('Tag.setupAttributes', 'register');
533
- this._state = TagState.AttributesSetup;
534
- this.callOnWrapped('$setup');
535
- if (VisionHelper_1.VisionHelper.doBenchmark)
536
- Bencmark_1.benchmarkEnd('Tag.setupAttributes', '$setup');
537
- return [2 /*return*/];
538
- }
539
- });
540
- });
541
- };
542
- Tag.prototype.extractAttributes = function () {
543
- return __awaiter(this, void 0, void 0, function () {
544
- var _i, _a, attr;
545
- return __generator(this, function (_b) {
546
- switch (_b.label) {
547
- case 0:
548
- _i = 0, _a = this.nonDeferredAttributes;
549
- _b.label = 1;
550
- case 1:
551
- if (!(_i < _a.length)) return [3 /*break*/, 4];
552
- attr = _a[_i];
553
- return [4 /*yield*/, attr.extract()];
554
- case 2:
555
- _b.sent();
556
- _b.label = 3;
557
- case 3:
558
- _i++;
559
- return [3 /*break*/, 1];
560
- case 4:
561
- this._state = TagState.AttributesExtracted;
562
- this.callOnWrapped('$extracted');
563
- return [2 /*return*/];
564
- }
565
- });
566
- });
567
- };
568
- Tag.prototype.connectAttributes = function () {
569
- return __awaiter(this, void 0, void 0, function () {
570
- var _i, _a, attr;
571
- return __generator(this, function (_b) {
572
- switch (_b.label) {
573
- case 0:
574
- if (this.isInput) {
575
- this.addEventHandler('input', [], this.inputMutation.bind(this));
576
- }
577
- _i = 0, _a = this.nonDeferredAttributes;
578
- _b.label = 1;
579
- case 1:
580
- if (!(_i < _a.length)) return [3 /*break*/, 4];
581
- attr = _a[_i];
582
- return [4 /*yield*/, attr.connect()];
583
- case 2:
584
- _b.sent();
585
- _b.label = 3;
586
- case 3:
587
- _i++;
588
- return [3 /*break*/, 1];
589
- case 4:
590
- this._state = TagState.AttributesConnected;
591
- this.callOnWrapped('$bound');
592
- return [2 /*return*/];
593
- }
594
- });
595
- });
596
- };
597
- Tag.prototype.inputMutation = function (e) {
598
- this.element.setAttribute('value', e.target.value);
599
- };
600
- Tag.prototype.finalize = function () {
601
- this._state = TagState.Built;
602
- this.callOnWrapped('$built', this, this.scope, this.element);
603
- VisionHelper_1.VisionHelper.nice(this.setupDeferredAttributes.bind(this));
604
- };
605
- Tag.prototype.callOnWrapped = function (method) {
606
- var _a;
607
- var args = [];
608
- for (var _i = 1; _i < arguments.length; _i++) {
609
- args[_i - 1] = arguments[_i];
610
- }
611
- if (this._uniqueScope && this.scope && this.scope.wrapped && this.scope.wrapped[method]) {
612
- (_a = this.scope.wrapped)[method].apply(_a, args);
613
- return true;
614
- }
615
- return false;
616
- };
617
- Tag.prototype.handleEvent = function (eventType, e) {
618
- if (e)
619
- e.stopPropagation();
620
- if (!this.onEventHandlers[eventType])
621
- return;
622
- this.scope.set('$event', e);
623
- this.scope.set('$value', this.value);
624
- for (var _i = 0, _a = this.onEventHandlers[eventType]; _i < _a.length; _i++) {
625
- var handler = _a[_i];
626
- handler(e);
627
- }
628
- };
629
- Tag.prototype.hasModifier = function (attribute, modifier) {
630
- return attribute.indexOf("|" + modifier) > -1;
631
- };
632
- Tag.prototype.stripModifier = function (attribute, modifier) {
633
- return attribute.replace("|" + modifier, '');
634
- };
635
- Tag.prototype.addEventHandler = function (eventType, modifiers, handler) {
636
- var passiveValue = null;
637
- if (modifiers.indexOf('active') > -1) {
638
- passiveValue = false;
639
- }
640
- else if (modifiers.indexOf('passive') > -1) {
641
- passiveValue = true;
642
- }
643
- if (!this.onEventHandlers[eventType]) {
644
- this.onEventHandlers[eventType] = [];
645
- var element = On_1.On.WindowEvents.indexOf(eventType) > -1 && window ? window : this.element;
646
- var opts = {};
647
- if (eventType.indexOf('touch') > -1 || passiveValue !== null)
648
- opts['passive'] = passiveValue === null && true || passiveValue;
649
- element.addEventListener(eventType, this.handleEvent.bind(this, eventType), opts);
650
- }
651
- this.onEventHandlers[eventType].push(handler);
652
- };
653
- Tag.prototype.watchAttribute = function (attributeName) {
654
- return __awaiter(this, void 0, void 0, function () {
655
- var _i, _a, attribute, standardAttribute;
656
- return __generator(this, function (_b) {
657
- switch (_b.label) {
658
- case 0:
659
- for (_i = 0, _a = this.attributes; _i < _a.length; _i++) {
660
- attribute = _a[_i];
661
- if (attribute instanceof StandardAttribute_1.StandardAttribute && attribute.attributeName == attributeName) {
662
- return [2 /*return*/, attribute];
663
- }
664
- }
665
- // Standard attribute requires a unique scope
666
- // @todo: Does this cause any issues with attribute bindings on the parent scope prior to having its own scope? hmm...
667
- if (!this.uniqueScope) {
668
- this._uniqueScope = true;
669
- this._scope = new Scope_1.Scope();
670
- if (this.parentTag) {
671
- this.scope.parentScope = this.parentTag.scope;
672
- }
673
- }
674
- standardAttribute = new StandardAttribute_1.StandardAttribute(this, attributeName);
675
- this.attributes.push(standardAttribute);
676
- return [4 /*yield*/, this.setupAttribute(standardAttribute)];
677
- case 1:
678
- _b.sent();
679
- return [2 /*return*/, standardAttribute];
680
- }
681
- });
682
- });
683
- };
684
- Tag.prototype.watchStyle = function (styleName) {
685
- return __awaiter(this, void 0, void 0, function () {
686
- var _i, _a, attribute, styleAttribute;
687
- return __generator(this, function (_b) {
688
- switch (_b.label) {
689
- case 0:
690
- for (_i = 0, _a = this.attributes; _i < _a.length; _i++) {
691
- attribute = _a[_i];
692
- if (attribute instanceof StyleAttribute_1.StyleAttribute) {
693
- return [2 /*return*/, attribute];
694
- }
695
- }
696
- // Standard attribute requires a unique scope
697
- // @todo: Does this cause any issues with attribute bindings on the parent scope prior to having its own scope? hmm...
698
- if (!this.uniqueScope) {
699
- this._uniqueScope = true;
700
- this._scope = new Scope_1.Scope();
701
- if (this.parentTag) {
702
- this.scope.parentScope = this.parentTag.scope;
703
- }
704
- }
705
- styleAttribute = new StyleAttribute_1.StyleAttribute(this, 'style');
706
- this.attributes.push(styleAttribute);
707
- return [4 /*yield*/, this.setupAttribute(styleAttribute)];
708
- case 1:
709
- _b.sent();
710
- return [2 /*return*/, styleAttribute];
711
- }
712
- });
713
- });
714
- };
715
- Tag.prototype.setupAttribute = function (attribute) {
716
- return __awaiter(this, void 0, void 0, function () {
717
- return __generator(this, function (_a) {
718
- switch (_a.label) {
719
- case 0: return [4 /*yield*/, attribute.compile()];
720
- case 1:
721
- _a.sent();
722
- return [4 /*yield*/, attribute.setup()];
723
- case 2:
724
- _a.sent();
725
- return [4 /*yield*/, attribute.extract()];
726
- case 3:
727
- _a.sent();
728
- return [4 /*yield*/, attribute.connect()];
729
- case 4:
730
- _a.sent();
731
- return [2 /*return*/];
732
- }
733
- });
734
- });
735
- };
736
- Tag.prototype.setupDeferredAttributes = function () {
737
- return __awaiter(this, void 0, void 0, function () {
738
- var _i, _a, attr;
739
- return __generator(this, function (_b) {
740
- switch (_b.label) {
741
- case 0:
742
- _i = 0, _a = this.deferredAttributes;
743
- _b.label = 1;
744
- case 1:
745
- if (!(_i < _a.length)) return [3 /*break*/, 4];
746
- attr = _a[_i];
747
- return [4 /*yield*/, this.setupAttribute(attr)];
748
- case 2:
749
- _b.sent();
750
- _b.label = 3;
751
- case 3:
752
- _i++;
753
- return [3 /*break*/, 1];
754
- case 4:
755
- this.deferredAttributes.length = 0;
756
- return [2 /*return*/];
757
- }
758
- });
759
- });
760
- };
761
- return Tag;
762
- }(DOMObject_1.DOMObject));
763
- exports.Tag = Tag;
764
- //# sourceMappingURL=Tag.js.map