1 | (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.armature = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
2 | 'use strict';
|
3 |
|
4 | var hasOwnProperty = Object.prototype.hasOwnProperty;
|
5 | var propIsEnumerable = Object.prototype.propertyIsEnumerable;
|
6 | function toObject(val) {
|
7 | if (val === null || val === undefined) {
|
8 | throw new TypeError('Object.assign cannot be called with null or undefined');
|
9 | }
|
10 | return Object(val);
|
11 | }
|
12 | function shouldUseNative() {
|
13 | try {
|
14 | if (!Object.assign) {
|
15 | return false;
|
16 | }
|
17 |
|
18 |
|
19 | var test1 = new String('abc');
|
20 | test1[5] = 'de';
|
21 | if (Object.getOwnPropertyNames(test1)[0] === '5') {
|
22 | return false;
|
23 | }
|
24 |
|
25 | var test2 = {};
|
26 | for (var i = 0; i < 10; i++) {
|
27 | test2['_' + String.fromCharCode(i)] = i;
|
28 | }
|
29 | var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
|
30 | return test2[n];
|
31 | });
|
32 | if (order2.join('') !== '0123456789') {
|
33 | return false;
|
34 | }
|
35 |
|
36 | var test3 = {};
|
37 | 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
|
38 | test3[letter] = letter;
|
39 | });
|
40 | if (Object.keys(Object.assign({}, test3)).join('') !==
|
41 | 'abcdefghijklmnopqrst') {
|
42 | return false;
|
43 | }
|
44 | return true;
|
45 | }
|
46 | catch (e) {
|
47 |
|
48 | return false;
|
49 | }
|
50 | }
|
51 | module.exports = shouldUseNative() ? Object.assign : function (target, source) {
|
52 | var from;
|
53 | var to = toObject(target);
|
54 | var symbols;
|
55 | for (var s = 1; s < arguments.length; s++) {
|
56 | from = Object(arguments[s]);
|
57 | for (var key in from) {
|
58 | if (hasOwnProperty.call(from, key)) {
|
59 | to[key] = from[key];
|
60 | }
|
61 | }
|
62 | if (Object.getOwnPropertySymbols) {
|
63 | symbols = Object.getOwnPropertySymbols(from);
|
64 | for (var i = 0; i < symbols.length; i++) {
|
65 | if (propIsEnumerable.call(from, symbols[i])) {
|
66 | to[symbols[i]] = from[symbols[i]];
|
67 | }
|
68 | }
|
69 | }
|
70 | }
|
71 | return to;
|
72 | };
|
73 |
|
74 | },{}],2:[function(require,module,exports){
|
75 |
|
76 | },{}],3:[function(require,module,exports){
|
77 | "use strict";
|
78 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
79 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
80 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
81 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
82 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
83 | };
|
84 | var UUID_1 = require("./UUID");
|
85 | var Decorators_1 = require("./Decorators");
|
86 | var ComponentStore_1 = require("./ComponentStore");
|
87 | var assign = require("object-assign");
|
88 |
|
89 |
|
90 |
|
91 | var Component = (function () {
|
92 | |
93 |
|
94 |
|
95 |
|
96 |
|
97 | function Component(data) {
|
98 | |
99 |
|
100 |
|
101 | this.$children = [];
|
102 | this.$data = data;
|
103 | this.$id = UUID_1.default.get();
|
104 | }
|
105 | |
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 | Component.$for = function (parent, label, data) {
|
115 | var identifier = this.$getIdentifier(label);
|
116 | var existing = parent.$children.find(function (v) { return v.$getIdentifier() === identifier; });
|
117 | if (existing) {
|
118 | return existing;
|
119 | }
|
120 | if (data === null) {
|
121 | throw new Error("Subcomponent was created with no data!");
|
122 | }
|
123 | var inst = new this(data);
|
124 | inst.$label = label;
|
125 | inst.$parent = parent;
|
126 | parent.$children.push(inst);
|
127 | return inst;
|
128 | };
|
129 | |
130 |
|
131 |
|
132 | Component.prototype.$serializeData = function () {
|
133 | return assign({}, this.$data);
|
134 | };
|
135 | |
136 |
|
137 |
|
138 | Component.$getTypeName = function () {
|
139 | var classString = this.$classNames.map(function (v) { return "." + v; }).join("");
|
140 | return this.$tagName + classString;
|
141 | };
|
142 | |
143 |
|
144 |
|
145 | Component.prototype.$deflate = function () {
|
146 | var thisClass = this.constructor;
|
147 | return {
|
148 | type: thisClass.$getTypeName(),
|
149 | data: this.$serializeData(),
|
150 | id: this.$id,
|
151 | label: this.$label,
|
152 | children: this.$children.map(function (v) { return v.$deflate(); })
|
153 | };
|
154 | };
|
155 | |
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 | Component.$inflate = function (deflated, inst) {
|
162 | if (!inst) {
|
163 | inst = new this(deflated.data);
|
164 | }
|
165 | inst.$id = deflated.id;
|
166 | inst.$label = deflated.label;
|
167 | if (deflated.children) {
|
168 | for (var _i = 0, _a = deflated.children; _i < _a.length; _i++) {
|
169 | var child = _a[_i];
|
170 | var thatClass = ComponentStore_1.default.get(child.type);
|
171 | var childInst = thatClass.$for(inst, child.label, child.data);
|
172 | thatClass.$inflate(child, childInst);
|
173 | }
|
174 | }
|
175 | return inst;
|
176 | };
|
177 | |
178 |
|
179 |
|
180 |
|
181 |
|
182 | Component.$getIdentifier = function (label) {
|
183 | return this.$getTypeName() + "__" + label;
|
184 | };
|
185 | |
186 |
|
187 |
|
188 | Component.prototype.$getIdentifier = function () {
|
189 | var thisClass = this.constructor;
|
190 | return thisClass.$getIdentifier(this.$label);
|
191 | };
|
192 | Component.prototype.toString = function () {
|
193 | return this.$getHTML();
|
194 | };
|
195 | |
196 |
|
197 |
|
198 | Component.prototype.$getHTML = function () {
|
199 | var thisClass = this.constructor;
|
200 | return "<" + thisClass.$tagName + "\n\t\t\tclass=\"" + thisClass.$classNames.join(" ") + "\"\n\t\t\tdata-armid=\"" + this.$id + "\"\n\t\t\t" + (this.$label ? "data-label=\"" + this.$label + "\"" : "") + "\n\t\t\t>" + this.$template(this) + "</" + thisClass.$tagName + ">";
|
201 | };
|
202 | |
203 |
|
204 |
|
205 | Component.prototype.$ensureElement = function () {
|
206 | if (!this.$element) {
|
207 | var thisClass = this.constructor;
|
208 | var el = document.createElement(thisClass.$tagName);
|
209 | (_a = el.classList).add.apply(_a, thisClass.$classNames);
|
210 | this.$attachTo(el);
|
211 | }
|
212 | var _a;
|
213 | };
|
214 | |
215 |
|
216 |
|
217 |
|
218 |
|
219 | Component.prototype.$attachTo = function (element) {
|
220 | this.$element = element;
|
221 | element.setAttribute("data-armid", this.$id.toString());
|
222 | if (this.$label) {
|
223 | element.setAttribute("data-label", this.$label);
|
224 | }
|
225 | };
|
226 | |
227 |
|
228 |
|
229 |
|
230 |
|
231 | Component.prototype.$locate = function (parent) {
|
232 | if (parent === void 0) { parent = document.body; }
|
233 | var thisClass = this.constructor;
|
234 | var el = parent.querySelector(thisClass.$tagName + "[data-armid=\"" + this.$id + "\"]");
|
235 | if (el) {
|
236 | this.$element = el;
|
237 | this.$children.forEach(function (child) {
|
238 | child.$locate(el);
|
239 | });
|
240 | return el;
|
241 | }
|
242 | };
|
243 | |
244 |
|
245 |
|
246 | Component.prototype.$render = function () {
|
247 | this.$element.innerHTML = this.$template(this);
|
248 | };
|
249 | |
250 |
|
251 |
|
252 |
|
253 | Component.prototype.$hydrate = function () {
|
254 | for (var _i = 0, _a = this.$children; _i < _a.length; _i++) {
|
255 | var child = _a[_i];
|
256 | if (child.$locate(this.$element)) {
|
257 | child.$hydrate();
|
258 | }
|
259 | }
|
260 | };
|
261 | |
262 |
|
263 |
|
264 | Component.prototype.$reify = function () {
|
265 | this.$ensureElement();
|
266 | this.$render();
|
267 | this.$hydrate();
|
268 | };
|
269 | |
270 |
|
271 |
|
272 | Component.$classNames = [];
|
273 | Component = __decorate([
|
274 | Decorators_1.TagName("arm-component"),
|
275 | Decorators_1.Template(function () { return ""; })
|
276 | ], Component);
|
277 | return Component;
|
278 | }());
|
279 | exports.Component = Component;
|
280 |
|
281 | },{"./ComponentStore":4,"./Decorators":5,"./UUID":7,"object-assign":1}],4:[function(require,module,exports){
|
282 | "use strict";
|
283 | var ComponentStore = {
|
284 | store: new Map(),
|
285 | register: function (componentType) {
|
286 | this.store.set(componentType.$getTypeName(), componentType);
|
287 | },
|
288 | get: function (typeName) {
|
289 | return this.store.get(typeName);
|
290 | }
|
291 | };
|
292 | Object.defineProperty(exports, "__esModule", { value: true });
|
293 | exports.default = ComponentStore;
|
294 |
|
295 | },{}],5:[function(require,module,exports){
|
296 | "use strict";
|
297 |
|
298 |
|
299 |
|
300 |
|
301 | function Template(template) {
|
302 | return function (target) {
|
303 | target.prototype.$template = template;
|
304 | };
|
305 | }
|
306 | exports.Template = Template;
|
307 |
|
308 |
|
309 |
|
310 |
|
311 | function TagName(name) {
|
312 | return function (target) {
|
313 | target.$tagName = name;
|
314 | };
|
315 | }
|
316 | exports.TagName = TagName;
|
317 |
|
318 |
|
319 |
|
320 |
|
321 | function ClassNames() {
|
322 | var names = [];
|
323 | for (var _i = 0; _i < arguments.length; _i++) {
|
324 | names[_i - 0] = arguments[_i];
|
325 | }
|
326 | return function (target) {
|
327 | (_a = target.$classNames).push.apply(_a, names);
|
328 | var _a;
|
329 | };
|
330 | }
|
331 | exports.ClassNames = ClassNames;
|
332 |
|
333 | },{}],6:[function(require,module,exports){
|
334 | "use strict";
|
335 | var ComponentStore_1 = require("./ComponentStore");
|
336 | function Properties(data) {
|
337 | return function (target) {
|
338 | target.prototype.$template = data.template;
|
339 | target.$tagName = data.tag;
|
340 | if (data.classes) {
|
341 | target.$classNames = target.$classNames.concat(data.classes);
|
342 | }
|
343 | ComponentStore_1.default.register(target);
|
344 | };
|
345 | }
|
346 | exports.Properties = Properties;
|
347 |
|
348 | },{"./ComponentStore":4}],7:[function(require,module,exports){
|
349 | "use strict";
|
350 | var randomBuffer = new Uint16Array(1);
|
351 |
|
352 |
|
353 |
|
354 |
|
355 | function rand() {
|
356 | if (typeof crypto !== "undefined") {
|
357 | crypto.getRandomValues(randomBuffer);
|
358 | return randomBuffer[0] / Math.pow(2, 16);
|
359 | }
|
360 | else {
|
361 | return Math.random();
|
362 | }
|
363 | }
|
364 | var UUID = {
|
365 | |
366 |
|
367 |
|
368 | get: function () {
|
369 | var template = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
|
370 | var value = template.replace(/[xy]/g, function (c) {
|
371 | var v = Math.floor(rand() * 16);
|
372 | if (c !== "x") {
|
373 | v = v & 0x3 | 0x8;
|
374 | }
|
375 | return v.toString(16);
|
376 | });
|
377 | return value;
|
378 | }
|
379 | };
|
380 | Object.defineProperty(exports, "__esModule", { value: true });
|
381 | exports.default = UUID;
|
382 |
|
383 | },{}],8:[function(require,module,exports){
|
384 | "use strict";
|
385 | function __export(m) {
|
386 | for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
387 | }
|
388 | __export(require("./Component"));
|
389 | var ComponentStore_1 = require("./ComponentStore");
|
390 | exports.ComponentStore = ComponentStore_1.default;
|
391 | var UUID_1 = require("./UUID");
|
392 | exports.UUID = UUID_1.default;
|
393 | __export(require("./Decorators"));
|
394 | __export(require("./Properties"));
|
395 |
|
396 | },{"./Component":3,"./ComponentStore":4,"./Decorators":5,"./Properties":6,"./UUID":7}],9:[function(require,module,exports){
|
397 | arguments[4][2][0].apply(exports,arguments)
|
398 | },{"dup":2}]},{},[8,2,9])(9)
|
399 | });
|
400 |
|
401 |
|
402 |
|