UNPKG

107 kBJavaScriptView Raw
1/*
2 Name: oxe
3 Version: 5.2.4
4 License: MPL-2.0
5 Author: Alexander Elias
6 Email: alex.steven.elis@gmail.com
7 This Source Code Form is subject to the terms of the Mozilla Public
8 License, v. 2.0. If a copy of the MPL was not distributed with this
9 file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 */
11 function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
12
13(function (global, factory) {
14 (typeof exports === "undefined" ? "undefined" : _typeof(exports)) === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global = global || self, global.Oxe = factory());
15})(this, function () {
16 'use strict';
17
18 var Utility = {
19 PIPE: /\s?\|\s?/,
20 PIPES: /\s?,\s?|\s+/,
21 value: function value(element, model) {
22 if (!model) throw new Error('Utility.value - requires model argument');
23 if (!element) throw new Error('Utility.value - requires element argument');
24 var type = this.type(element);
25
26 if (type === 'radio' || type === 'checkbox') {
27 var name = this.name(element);
28 var query = 'input[type="' + type + '"][name="' + name + '"]';
29 var form = this.form(element);
30 var elements = form ? this.form(element).querySelectorAll(query) : [element];
31 var multiple = elements.length > 1;
32 var result = multiple ? [] : undefined;
33
34 for (var i = 0, l = elements.length; i < l; i++) {
35 var child = elements[i];
36 var checked = this.checked(child);
37 if (!checked) continue;
38 var value = this.value(child, model);
39
40 if (multiple) {
41 result.push(value);
42 } else {
43 result = value;
44 break;
45 }
46 }
47
48 return result;
49 } else if (type === 'select-one' || type === 'select-multiple') {
50 var _multiple = this.multiple(element);
51
52 var options = element.options;
53
54 var _result = _multiple ? [] : undefined;
55
56 for (var _i = 0, _l = options.length; _i < _l; _i++) {
57 var option = options[_i];
58 var selected = option.selected;
59
60 var _value = this.value(option, model);
61
62 var match = this[_multiple ? 'includes' : 'compare'](this.data, _value);
63
64 if (selected && !match) {
65 if (this.multiple) {
66 _result.push(_value);
67 } else {
68 _result = _value;
69 }
70 } else if (!selected && match) {
71 option.selected = true;
72 }
73 }
74
75 return _result;
76 } else {
77 var attribute = element.attributes['o-value'];
78
79 if (attribute) {
80 var values = this.binderValues(attribute.value);
81
82 var _value2 = this.getByPath(model, values);
83
84 return _value2 || element.value;
85 } else {
86 return element.value;
87 }
88 }
89 },
90 form: function form(element) {
91 if (element.form) {
92 return element.form;
93 } else {
94 while (element = element.parentElement) {
95 if (element.nodeName === 'FORM' || element.nodeName.indexOf('-FORM') !== -1) {
96 return element;
97 }
98 }
99 }
100 },
101 type: function type(element) {
102 if (typeof element.type === 'string') {
103 return element.type;
104 } else {
105 return element.getAttribute('type');
106 }
107 },
108 name: function name(element) {
109 if (typeof element.name === 'string') {
110 return element.name;
111 } else {
112 return element.getAttribute('name');
113 }
114 },
115 checked: function checked(element) {
116 if (typeof element.checked === 'boolean') {
117 return element.checked;
118 } else {
119 switch (element.getAttribute('checked')) {
120 case undefined:
121 return false;
122
123 case 'true':
124 return true;
125
126 case null:
127 return false;
128
129 case '':
130 return true;
131
132 default:
133 return false;
134 }
135 }
136 },
137 multiple: function multiple(element) {
138 if (typeof element.multiple === 'boolean') {
139 return element.multiple;
140 } else {
141 switch (element.getAttribute('multiple')) {
142 case undefined:
143 return false;
144
145 case 'true':
146 return true;
147
148 case null:
149 return false;
150
151 case '':
152 return true;
153
154 default:
155 return false;
156 }
157 }
158 },
159 disabled: function disabled(element) {
160 if (typeof element.disabled === 'boolean') {
161 return element.disabled;
162 } else {
163 switch (element.getAttribute('disabled')) {
164 case undefined:
165 return false;
166
167 case 'true':
168 return true;
169
170 case null:
171 return false;
172
173 case '':
174 return true;
175
176 default:
177 return false;
178 }
179 }
180 },
181 index: function index(items, item) {
182 for (var i = 0, l = items.length; i < l; i++) {
183 if (this.match(items[i], item)) {
184 return i;
185 }
186 }
187
188 return -1;
189 },
190 includes: function includes(items, item) {
191 for (var i = 0, l = items.length; i < l; i++) {
192 if (this.match(items[i], item)) {
193 return true;
194 }
195 }
196
197 return false;
198 },
199 match: function match(source, target) {
200 if (source === target) {
201 return true;
202 }
203
204 if (_typeof(source) !== _typeof(target)) {
205 return false;
206 }
207
208 if (source.constructor !== target.constructor) {
209 return false;
210 }
211
212 if (_typeof(source) !== 'object' || _typeof(target) !== 'object') {
213 return source === target;
214 }
215
216 var sourceKeys = Object.keys(source);
217 var targetKeys = Object.keys(target);
218
219 if (sourceKeys.length !== targetKeys.length) {
220 return false;
221 }
222
223 for (var i = 0, l = sourceKeys.length; i < l; i++) {
224 var name = sourceKeys[i];
225
226 if (!this.match(source[name], target[name])) {
227 return false;
228 }
229 }
230
231 return true;
232 },
233 binderNames: function binderNames(data) {
234 data = data.split('o-')[1];
235 return data ? data.split('-') : [];
236 },
237 binderValues: function binderValues(data) {
238 data = data.split(this.PIPE)[0];
239 return data ? data.split('.') : [];
240 },
241 binderPipes: function binderPipes(data) {
242 data = data.split(this.PIPE)[1];
243 return data ? data.split(this.PIPES) : [];
244 },
245 ensureElement: function ensureElement(data) {
246 data.query = data.query || '';
247 data.scope = data.scope || document.body;
248 data.position = data.position || 'beforeend';
249 var element = data.scope.querySelector("".concat(data.name).concat(data.query));
250
251 if (!element) {
252 element = document.createElement(data.name);
253 data.scope.insertAdjacentElement(data.position, element);
254 }
255
256 for (var i = 0, l = data.attributes.length; i < l; i++) {
257 var _data$attributes$i = data.attributes[i],
258 name = _data$attributes$i.name,
259 value = _data$attributes$i.value;
260 element.setAttribute(name, value);
261 }
262
263 return element;
264 },
265 setByPath: function setByPath(data, path, value) {
266 var keys = typeof path === 'string' ? path.split('.') : path;
267 var last = keys.length - 1;
268
269 for (var i = 0; i < last; i++) {
270 var key = keys[i];
271
272 if (!(key in data)) {
273 if (isNaN(keys[i + 1])) {
274 data[key] = {};
275 } else {
276 data[key] = [];
277 }
278 }
279
280 data = data[key];
281 }
282
283 return data[keys[last]] = value;
284 },
285 getByPath: function getByPath(data, path) {
286 var keys = typeof path === 'string' ? path.split('.') : path;
287 var last = keys.length - 1;
288
289 if (keys[last] === '$key' || keys[last] === '$index') {
290 return keys[last - 1];
291 }
292
293 for (var i = 0; i < last; i++) {
294 var key = keys[i];
295
296 if (key in data === false) {
297 return undefined;
298 } else {
299 data = data[key];
300 }
301 }
302
303 return data[keys[last]];
304 },
305 clone: function clone(source) {
306 if (source === null || source === undefined || source.constructor !== Array && source.constructor !== Object) {
307 return source;
308 }
309
310 var target = source.constructor();
311
312 for (var name in source) {
313 var descriptor = Object.getOwnPropertyDescriptor(source, name);
314
315 if (descriptor) {
316 if ('value' in descriptor) {
317 descriptor.value = this.clone(descriptor.value);
318 }
319
320 Object.defineProperty(target, name, descriptor);
321 }
322 }
323
324 return target;
325 }
326 };
327 var Batcher = {
328 reads: [],
329 writes: [],
330 time: 1000 / 30,
331 pending: false,
332 setup: function setup(options) {
333 options = options || {};
334 this.time = options.time || this.time;
335 },
336 tick: function tick(callback) {
337 window.requestAnimationFrame(callback.bind(this, null));
338 },
339 schedule: function schedule() {
340 if (this.pending) return;
341 this.pending = true;
342 this.tick(this.flush);
343 },
344 flush: function flush(time) {
345 time = time || performance.now();
346 var task;
347
348 if (this.writes.length === 0) {
349 while (task = this.reads.shift()) {
350 if (task) {
351 task();
352 }
353
354 if (performance.now() - time > this.time) {
355 return this.tick(this.flush);
356 }
357 }
358 }
359
360 while (task = this.writes.shift()) {
361 if (task) {
362 task();
363 }
364
365 if (performance.now() - time > this.time) {
366 return this.tick(this.flush);
367 }
368 }
369
370 if (this.reads.length === 0 && this.writes.length === 0) {
371 this.pending = false;
372 } else if (performance.now() - time > this.time) {
373 this.tick(this.flush);
374 } else {
375 this.flush(time);
376 }
377 },
378 remove: function remove(tasks, task) {
379 var index = tasks.indexOf(task);
380 return !!~index && !!tasks.splice(index, 1);
381 },
382 clear: function clear(task) {
383 return this.remove(this.reads, task) || this.remove(this.writes, task);
384 },
385 batch: function batch(data) {
386 var self = this;
387 if (!data) return;
388 if (!data.read && !data.write) return;
389 data.context = data.context || {};
390
391 var read = function read() {
392 var result;
393
394 if (data.read) {
395 result = data.read.call(data.context, data.context);
396 }
397
398 if (data.write && result !== false) {
399 var write = data.write.bind(data.context, data.context);
400 self.writes.push(write);
401 }
402 };
403
404 self.reads.push(read);
405 self.schedule();
406 }
407 };
408
409 function Piper(binder, data) {
410 if (binder.type === 'on') {
411 return data;
412 }
413
414 if (!binder.pipes.length) {
415 return data;
416 }
417
418 var methods = binder.container.methods;
419
420 if (!methods) {
421 return data;
422 }
423
424 for (var i = 0, l = binder.pipes.length; i < l; i++) {
425 var name = binder.pipes[i];
426
427 if (name in methods) {
428 var method = methods[name];
429
430 if (method && method.constructor === Function) {
431 data = methods[name].call(binder.container, data);
432 } else {
433 console.warn("Oxe.piper - pipe ".concat(name, " invalid type"));
434 }
435 } else {
436 console.warn("Oxe.piper - pipe ".concat(name, " not found"));
437 }
438 }
439
440 return data;
441 }
442
443 function Class(binder) {
444 return {
445 read: function read() {
446 this.data = binder.data;
447
448 if (binder.names.length > 1) {
449 this.name = binder.names.slice(1).join('-');
450 }
451 },
452 write: function write() {
453 if (this.name) {
454 if (this.data === undefined || this.data === null) {
455 binder.target.classList.remove(this.name);
456 } else {
457 binder.target.classList.toggle(this.name, this.data);
458 }
459 } else {
460 if (this.data === undefined || this.data === null) {
461 binder.target.setAttribute('class', '');
462 } else {
463 binder.target.setAttribute('class', this.data);
464 }
465 }
466 }
467 };
468 }
469
470 function Default(binder) {
471 return {
472 read: function read() {
473 this.data = binder.data;
474
475 if (this.data === undefined || this.data === null) {
476 this.data = '';
477 } else if (_typeof(this.data) === 'object') {
478 this.data = JSON.stringify(this.data);
479 } else if (typeof this.data !== 'string') {
480 this.data = this.data.toString();
481 }
482
483 if (this.data === binder.target[binder.type]) {
484 return false;
485 }
486 },
487 write: function write() {
488 binder.target[binder.type] = this.data;
489 }
490 };
491 }
492
493 function Disable(binder) {
494 return {
495 read: function read() {
496 this.data = binder.data;
497
498 if (this.data === binder.target.disabled) {
499 return false;
500 }
501 },
502 write: function write() {
503 binder.target.disabled = this.data;
504 }
505 };
506 }
507
508 function Each(binder) {
509 var self = this;
510 var render = {
511 read: function read() {
512 this.data = binder.data || [];
513
514 if (binder.meta.keys === undefined) {
515 binder.meta.keys = [];
516 binder.meta.pending = false;
517 binder.meta.targetLength = 0;
518 binder.meta.currentLength = 0;
519
520 if (binder.target.firstElementChild) {
521 binder.meta.template = binder.target.removeChild(binder.target.firstElementChild);
522 } else {
523 var element = document.createElement('div');
524 var text = document.createTextNode("{{$".concat(binder.names[1], "}}"));
525 element.appendChild(text);
526 binder.meta.template = element;
527 }
528 }
529
530 binder.meta.keys = Object.keys(this.data);
531 binder.meta.targetLength = binder.meta.keys.length;
532
533 if (binder.meta.currentLength === binder.meta.targetLength) {
534 return false;
535 }
536 },
537 write: function write() {
538 if (binder.meta.currentLength === binder.meta.targetLength) {
539 binder.meta.pending = false;
540 return;
541 }
542
543 if (binder.meta.currentLength > binder.meta.targetLength) {
544 var element = binder.target.lastElementChild;
545 binder.target.removeChild(element);
546 self.remove(element);
547 binder.meta.currentLength--;
548 } else if (binder.meta.currentLength < binder.meta.targetLength) {
549 var _element = binder.meta.template.cloneNode(true);
550
551 var _index = binder.meta.currentLength++;
552
553 self.add(_element, {
554 index: _index,
555 path: binder.path,
556 variable: binder.names[1],
557 container: binder.container,
558 scope: binder.container.scope,
559 key: binder.meta.keys[_index]
560 });
561 binder.target.appendChild(_element);
562 }
563
564 if (binder.meta.pending && render.read) {
565 return;
566 } else {
567 binder.meta.pending = true;
568 }
569
570 delete render.read;
571 Batcher.batch(render);
572 }
573 };
574 return render;
575 }
576
577 function Enable(binder) {
578 return {
579 read: function read() {
580 this.data = !binder.data;
581
582 if (this.data === binder.target.disabled) {
583 return false;
584 }
585 },
586 write: function write() {
587 binder.target.disabled = this.data;
588 }
589 };
590 }
591
592 function Hide(binder) {
593 return {
594 read: function read() {
595 this.data = binder.data;
596
597 if (this.data === binder.target.hidden) {
598 return false;
599 }
600 },
601 write: function write() {
602 binder.target.hidden = this.data;
603 }
604 };
605 }
606
607 function Href(binder) {
608 return {
609 read: function read() {
610 this.data = binder.data || '';
611
612 if (this.data === binder.target.href) {
613 return false;
614 }
615 },
616 write: function write() {
617 binder.target.href = this.data;
618 }
619 };
620 }
621
622 function Html(binder) {
623 var self = this;
624 return {
625 read: function read() {
626 this.data = binder.data;
627
628 if (this.data === undefined || this.data === null) {
629 this.data = '';
630 } else if (_typeof(this.data) === 'object') {
631 this.data = JSON.stringify(this.data);
632 } else if (typeof this.data !== 'string') {
633 this.data = String(this.data);
634 }
635 },
636 write: function write() {
637 while (binder.target.firstChild) {
638 var node = binder.target.removeChild(binder.target.firstChild);
639 self.remove(node);
640 }
641
642 var fragment = document.createDocumentFragment();
643 var parser = document.createElement('div');
644 parser.innerHTML = this.data;
645
646 while (parser.firstElementChild) {
647 self.add(parser.firstElementChild, {
648 container: binder.container,
649 scope: binder.container.scope
650 });
651 fragment.appendChild(parser.firstElementChild);
652 }
653
654 binder.target.appendChild(fragment);
655 }
656 };
657 }
658
659 function Label(binder) {
660 return {
661 read: function read() {
662 this.data = binder.data;
663
664 if (this.data === undefined || this.data === null) {
665 this.data = '';
666 } else if (_typeof(this.data) === 'object') {
667 this.data = JSON.stringify(this.data);
668 } else if (typeof this.data !== 'string') {
669 this.data = this.data.toString();
670 }
671
672 if (this.data === binder.target.getAttribute('label')) {
673 return false;
674 }
675 },
676 write: function write() {
677 binder.target.setAttribute('label', this.data);
678 }
679 };
680 }
681
682 function On(binder) {
683 return {
684 read: function read(context) {
685 context.data = binder.data;
686
687 if (typeof context.data !== 'function') {
688 console.warn("Oxe - binder o-on=\"".concat(binder.keys.join('.'), "\" invalid type function required"));
689 return;
690 }
691
692 if (binder.meta.method) {
693 binder.target.removeEventListener(binder.names[1], binder.meta.method);
694 } else {
695 binder.meta.method = function (events) {
696 var parameters = [];
697
698 for (var i = 0, l = binder.pipes.length; i < l; i++) {
699 var keys = binder.pipes[i].split('.');
700 var parameter = Utility.getByPath(binder.container.model, keys);
701 parameters.push(parameter);
702 }
703
704 parameters.push(events);
705 parameters.push(this);
706 Promise.resolve(context.data.bind(binder.container).apply(null, parameters));
707 };
708 }
709
710 binder.target.addEventListener(binder.names[1], binder.meta.method);
711 }
712 };
713 }
714
715 function Read(binder) {
716 return {
717 read: function read() {
718 this.data = binder.data;
719
720 if (this.data === binder.target.readOnly) {
721 return false;
722 }
723 },
724 write: function write() {
725 binder.target.readOnly = this.data;
726 }
727 };
728 }
729
730 function Require(binder) {
731 return {
732 read: function read() {
733 this.data = binder.data;
734
735 if (this.data === binder.target.required) {
736 return false;
737 }
738 },
739 write: function write() {
740 binder.target.required = this.data;
741 }
742 };
743 }
744
745 function Show(binder) {
746 return {
747 read: function read() {
748 this.data = binder.data;
749
750 if (!this.data === binder.target.hidden) {
751 return false;
752 }
753 },
754 write: function write() {
755 binder.target.hidden = !this.data;
756 }
757 };
758 }
759
760 function Style(binder) {
761 return {
762 read: function read() {
763 this.data = binder.data;
764
765 if (binder.names.length > 1) {
766 this.name = '';
767 this.names = binder.names.slice(1);
768
769 for (var i = 0, l = this.names.length; i < l; i++) {
770 if (i === 0) {
771 this.name = this.names[i].toLowerCase();
772 } else {
773 this.name += this.names[i].charAt(0).toUpperCase() + this.names[i].slice(1).toLowerCase();
774 }
775 }
776 }
777 },
778 write: function write() {
779 if (binder.names.length > 1) {
780 if (this.data) {
781 binder.target.style[this.name] = this.data;
782 } else {
783 binder.target.style[this.name] = '';
784 }
785 } else {
786 if (this.data) {
787 binder.target.style.cssText = this.data;
788 } else {
789 binder.target.style.cssText = '';
790 }
791 }
792 }
793 };
794 }
795
796 function Text(binder) {
797 return {
798 read: function read() {
799 this.data = binder.data;
800
801 if (this.data === undefined || this.data === null) {
802 this.data = '';
803 } else if (_typeof(this.data) === 'object') {
804 this.data = JSON.stringify(this.data);
805 } else if (typeof this.data !== 'string') {
806 this.data = this.data.toString();
807 }
808
809 if (this.data === binder.target.textContent) {
810 return false;
811 }
812 },
813 write: function write() {
814 binder.target.textContent = this.data;
815 }
816 };
817 }
818
819 function Value(binder, caller) {
820 var self = this;
821 var type = binder.target.type;
822 if (binder.meta.busy) return;else binder.meta.busy = true;
823
824 if (type === 'select-one' || type === 'select-multiple') {
825 return {
826 read: function read() {
827 this.data = binder.data;
828 this.model = binder.model;
829 this.options = binder.target.options;
830 this.multiple = Utility.multiple(binder.target);
831
832 if (this.multiple && (!this.data || this.data.constructor !== Array)) {
833 binder.meta.busy = false;
834 throw new Error("Oxe - invalid o-value ".concat(binder.keys.join('.'), " multiple select requires array"));
835 }
836 },
837 write: function write() {
838 var fallback = false;
839 var fallbackSelectedAtrribute = false;
840 var fallbackValue = this.multiple ? [] : null;
841 var fallbackOption = this.multiple ? [] : null;
842
843 for (var i = 0, l = this.options.length; i < l; i++) {
844 var option = this.options[i];
845 var selected = option.selected;
846 var optionBinder = self.get('attribute', option, 'o-value');
847 var optionValue = optionBinder ? optionBinder.data : option.value;
848 var selectedAtrribute = option.hasAttribute('selected');
849
850 if (this.multiple) {
851 if (selectedAtrribute) {
852 fallback = true;
853 fallbackOption.push(option);
854 fallbackValue.push(optionValue);
855 }
856 } else {
857 if (i === 0 || selectedAtrribute) {
858 fallback = true;
859 fallbackOption = option;
860 fallbackValue = optionValue;
861 fallbackSelectedAtrribute = selectedAtrribute;
862 }
863 }
864
865 if (caller === 'view') {
866 if (selected) {
867 if (this.multiple) {
868 var includes = Utility.includes(this.data, optionValue);
869
870 if (!includes) {
871 this.selected = true;
872 binder.data.push(optionValue);
873 }
874 } else if (!this.selected) {
875 this.selected = true;
876 binder.data = optionValue;
877 }
878 } else {
879 if (this.multiple) {
880 var _index2 = Utility.index(this.data, optionValue);
881
882 if (_index2 !== -1) {
883 binder.data.splice(_index2, 1);
884 }
885 } else if (!this.selected && i === l - 1) {
886 binder.data = null;
887 }
888 }
889 } else {
890 if (this.multiple) {
891 var _includes = Utility.includes(this.data, optionValue);
892
893 if (_includes) {
894 this.selected = true;
895 option.selected = true;
896 } else {
897 option.selected = false;
898 }
899 } else {
900 if (!this.selected) {
901 var match = Utility.match(this.data, optionValue);
902
903 if (match) {
904 this.selected = true;
905 option.selected = true;
906 } else {
907 option.selected = false;
908 }
909 } else {
910 option.selected = false;
911 }
912 }
913 }
914 }
915
916 if (!this.selected && fallback) {
917 if (this.multiple) {
918 for (var _i2 = 0, _l2 = fallbackOption.length; _i2 < _l2; _i2++) {
919 fallbackOption[_i2].selected = true;
920 binder.data.push(fallbackValue[_i2]);
921 }
922 } else if (fallbackSelectedAtrribute || this.nodeName === 'OPTION') {
923 binder.data = fallbackValue;
924 fallbackOption.selected = true;
925 }
926 }
927
928 binder.meta.busy = false;
929 }
930 };
931 } else if (type === 'radio') {
932 return {
933 read: function read() {
934 this.form = binder.target.form || binder.container;
935 this.query = "input[type=\"radio\"][o-value=\"".concat(binder.value, "\"]");
936 this.nodes = this.form.querySelectorAll(this.query);
937 this.radios = Array.prototype.slice.call(this.nodes);
938
939 if (caller === 'view') {
940 binder.data = this.radios.indexOf(binder.target);
941 binder.meta.busy = false;
942 return false;
943 }
944
945 this.data = binder.data;
946
947 if (typeof this.data !== 'number') {
948 binder.meta.busy = false;
949 return false;
950 }
951 },
952 write: function write() {
953 for (var i = 0, l = this.radios.length; i < l; i++) {
954 var radio = this.radios[i];
955
956 if (i === this.data) {
957 radio.checked = true;
958 } else {
959 radio.checked = false;
960 }
961 }
962
963 binder.meta.busy = false;
964 }
965 };
966 } else if (type === 'checkbox') {
967 return {
968 read: function read() {
969 if (caller === 'view') {
970 binder.data = binder.target.checked;
971 binder.meta.busy = false;
972 return false;
973 }
974
975 this.data = binder.data;
976
977 if (typeof this.data !== 'boolean') {
978 binder.meta.busy = false;
979 return false;
980 }
981 },
982 write: function write() {
983 binder.target.checked = this.data;
984 binder.meta.busy = false;
985 }
986 };
987 } else {
988 return {
989 read: function read() {
990 if (caller === 'view') {
991 binder.data = binder.target.value;
992 binder.meta.busy = false;
993 return false;
994 }
995
996 this.data = binder.data;
997
998 if (this.data === binder.target.value) {
999 binder.meta.busy = false;
1000 return false;
1001 }
1002 },
1003 write: function write() {
1004 binder.target.value = this.data === undefined || this.data === null ? '' : this.data;
1005 binder.meta.busy = false;
1006 }
1007 };
1008 }
1009 }
1010
1011 function Write(binder) {
1012 return {
1013 read: function read() {
1014 this.data = binder.data;
1015
1016 if (!this.data === binder.target.readOnly) {
1017 return false;
1018 }
1019 },
1020 write: function write() {
1021 binder.target.readOnly = !this.data;
1022 }
1023 };
1024 }
1025
1026 var DATA = new Map();
1027 var BINDERS = {
1028 class: Class,
1029 css: Style,
1030 default: Default,
1031 disable: Disable,
1032 disabled: Disable,
1033 each: Each,
1034 enable: Enable,
1035 enabled: Enable,
1036 hide: Hide,
1037 hidden: Hide,
1038 href: Href,
1039 html: Html,
1040 label: Label,
1041 on: On,
1042 read: Read,
1043 require: Require,
1044 required: Require,
1045 show: Show,
1046 showed: Show,
1047 style: Style,
1048 text: Text,
1049 value: Value,
1050 write: Write
1051 };
1052 var Binder = {
1053 get data() {
1054 return DATA;
1055 },
1056
1057 get binders() {
1058 return BINDERS;
1059 },
1060
1061 setup: function setup(options) {
1062 return new Promise(function ($return, $error) {
1063 options = options || {};
1064 this.data.set('location', new Map());
1065 this.data.set('attribute', new Map());
1066
1067 for (var name in this.binders) {
1068 this.binders[name] = this.binders[name].bind(this);
1069 }
1070
1071 if (options.binders) {
1072 for (var _name in options.binders) {
1073 if (_name in this.binders === false) {
1074 this.binders[_name] = options.binders[_name].bind(this);
1075 }
1076 }
1077 }
1078
1079 return $return();
1080 }.bind(this));
1081 },
1082 get: function get(type) {
1083 if (!type) throw new Error('Oxe.binder.get - type argument required');
1084 var result = this.data.get(type);
1085 if (!result) return result;
1086
1087 for (var i = 1, l = arguments.length; i < l; i++) {
1088 var argument = arguments[i];
1089 result = result.get(argument);
1090
1091 if (!result) {
1092 return result;
1093 }
1094 }
1095
1096 return result;
1097 },
1098 create: function create(data) {
1099 if (data.name === undefined) throw new Error('Oxe.binder.create - missing name');
1100 if (data.value === undefined) throw new Error('Oxe.binder.create - missing value');
1101 if (data.target === undefined) throw new Error('Oxe.binder.create - missing target');
1102 if (data.container === undefined) throw new Error('Oxe.binder.create - missing container');
1103 var originalValue = data.value;
1104
1105 if (data.value.slice(0, 2) === '{{' && data.value.slice(-2) === '}}') {
1106 data.value = data.value.slice(2, -2);
1107 }
1108
1109 if (data.value.indexOf('$') !== -1 && data.context && data.context.variable && data.context.path && data.context.key) {
1110 var pattern = new RegExp("\\$".concat(data.context.variable, "(,|\\s+|\\.|\\|)?(.*)?$"), 'ig');
1111 data.value = data.value.replace(pattern, "".concat(data.context.path, ".").concat(data.context.key, "$1$2"));
1112 }
1113
1114 var scope = data.container.scope;
1115 var names = data.names || Utility.binderNames(data.name);
1116 var pipes = data.pipes || Utility.binderPipes(data.value);
1117 var values = data.values || Utility.binderValues(data.value);
1118 var type = names[0];
1119 var path = values.join('.');
1120 var keys = [scope].concat(values);
1121 var location = keys.join('.');
1122 var meta = data.meta || {};
1123 var context = data.context || {};
1124 var source = type === 'on' || type === 'submit' ? data.container.methods : data.container.model;
1125 return {
1126 get location() {
1127 return location;
1128 },
1129
1130 get type() {
1131 return type;
1132 },
1133
1134 get path() {
1135 return path;
1136 },
1137
1138 get scope() {
1139 return scope;
1140 },
1141
1142 get name() {
1143 return data.name;
1144 },
1145
1146 get value() {
1147 return data.value;
1148 },
1149
1150 get target() {
1151 return data.target;
1152 },
1153
1154 get container() {
1155 return data.container;
1156 },
1157
1158 get model() {
1159 return data.container.model;
1160 },
1161
1162 get methods() {
1163 return data.container.methods;
1164 },
1165
1166 get keys() {
1167 return keys;
1168 },
1169
1170 get names() {
1171 return names;
1172 },
1173
1174 get pipes() {
1175 return pipes;
1176 },
1177
1178 get values() {
1179 return values;
1180 },
1181
1182 get meta() {
1183 return meta;
1184 },
1185
1186 get context() {
1187 return context;
1188 },
1189
1190 get originalValue() {
1191 return originalValue;
1192 },
1193
1194 get data() {
1195 var data = Utility.getByPath(source, values);
1196 return Piper(this, data);
1197 },
1198
1199 set data(value) {
1200 var data = Piper(this, value);
1201 return Utility.setByPath(source, values, data);
1202 }
1203
1204 };
1205 },
1206 render: function render(binder, caller) {
1207 if (binder.type === 'submit') return;
1208 var type = binder.type in this.binders ? binder.type : 'default';
1209 var render = this.binders[type](binder, caller);
1210 Batcher.batch(render);
1211 },
1212 unbind: function unbind(node) {
1213 this.data.get('location').forEach(function (scopes) {
1214 scopes.forEach(function (binders) {
1215 binders.forEach(function (binder, index) {
1216 if (binder.target === node) {
1217 binders.splice(index, 1);
1218 }
1219 });
1220 });
1221 });
1222 this.data.get('attribute').delete(node);
1223 },
1224 bind: function bind(node, name, value, context) {
1225 if (value === "$".concat(context.variable, ".$key") || value === "{{$".concat(context.variable, ".$key}}")) {
1226 return Batcher.batch({
1227 write: function write() {
1228 node.textContent = context.key;
1229 }
1230 });
1231 }
1232
1233 if (value === "$".concat(context.variable, ".$index") || value === "{{$".concat(context.variable, ".$index}}")) {
1234 return Batcher.batch({
1235 write: function write() {
1236 node.textContent = context.index;
1237 }
1238 });
1239 }
1240
1241 var binder = this.create({
1242 name: name,
1243 value: value,
1244 target: node,
1245 context: context,
1246 container: context.container,
1247 scope: context.container.scope
1248 });
1249
1250 if (!this.data.get('attribute').has(binder.target)) {
1251 this.data.get('attribute').set(binder.target, new Map());
1252 }
1253
1254 if (!this.data.get('location').has(binder.scope)) {
1255 this.data.get('location').set(binder.scope, new Map());
1256 }
1257
1258 if (!this.data.get('location').get(binder.scope).has(binder.path)) {
1259 this.data.get('location').get(binder.scope).set(binder.path, []);
1260 }
1261
1262 this.data.get('attribute').get(binder.target).set(binder.name, binder);
1263 this.data.get('location').get(binder.scope).get(binder.path).push(binder);
1264 this.render(binder);
1265 },
1266 remove: function remove(node) {
1267 this.unbind(node);
1268
1269 for (var i = 0; i < node.childNodes.length; i++) {
1270 this.remove(node.childNodes[i]);
1271 }
1272 },
1273 add: function add(node, context) {
1274 if (node.nodeType === Node.TEXT_NODE) {
1275 if (node.textContent.indexOf('{{') === -1 || node.textContent.indexOf('}}') === -1) {
1276 return;
1277 }
1278
1279 var start = node.textContent.indexOf('{{');
1280
1281 if (start !== -1 && start !== 0) {
1282 node = node.splitText(start);
1283 }
1284
1285 var end = node.textContent.indexOf('}}');
1286 var length = node.textContent.length;
1287
1288 if (end !== -1 && end !== length - 2) {
1289 var split = node.splitText(end + 2);
1290 this.add(split, context);
1291 }
1292
1293 this.bind(node, 'o-text', node.textContent, context);
1294 } else if (node.nodeType === Node.ELEMENT_NODE) {
1295 var skipChildren = false;
1296 var attributes = node.attributes;
1297
1298 for (var i = 0, l = attributes.length; i < l; i++) {
1299 var attribute = attributes[i];
1300
1301 if (attribute.name === 'o-html' || attribute.name === 'o-scope' || attribute.name.indexOf('o-each') === 0) {
1302 skipChildren = true;
1303 }
1304
1305 if (attribute.name === 'o-value' || attribute.name === 'o-scope' || attribute.name === 'o-reset' || attribute.name === 'o-action' || attribute.name === 'o-method' || attribute.name === 'o-enctype' || attribute.name.indexOf('o-') !== 0) {
1306 continue;
1307 }
1308
1309 this.bind(node, attribute.name, attribute.value, context);
1310 }
1311
1312 if ('o-value' in attributes) {
1313 this.bind(node, 'o-value', attributes['o-value'].value, context);
1314 }
1315
1316 if (skipChildren) return;
1317
1318 for (var _i3 = 0; _i3 < node.childNodes.length; _i3++) {
1319 this.add(node.childNodes[_i3], context);
1320 }
1321 }
1322 }
1323 };
1324
1325 function Change(event) {
1326 return new Promise(function ($return, $error) {
1327 if ('attributes' in event.target && 'o-value' in event.target.attributes) {
1328 var binder = Binder.get('attribute', event.target, 'o-value');
1329 Binder.render(binder, 'view');
1330 }
1331
1332 return $return();
1333 });
1334 }
1335
1336 var Fetcher = {
1337 headers: null,
1338 method: 'get',
1339 mime: {
1340 xml: 'text/xml; charset=utf-8',
1341 html: 'text/html; charset=utf-8',
1342 text: 'text/plain; charset=utf-8',
1343 json: 'application/json; charset=utf-8',
1344 js: 'application/javascript; charset=utf-8'
1345 },
1346 setup: function setup(options) {
1347 return new Promise(function ($return, $error) {
1348 options = options || {};
1349 this.path = options.path;
1350 this.origin = options.origin;
1351 this.request = options.request;
1352 this.response = options.response;
1353 this.acceptType = options.acceptType;
1354 this.credentials = options.credentials;
1355 this.contentType = options.contentType;
1356 this.responseType = options.responseType;
1357 this.method = options.method || this.method;
1358 this.headers = options.headers || this.headers;
1359 return $return();
1360 }.bind(this));
1361 },
1362 serialize: function serialize(data) {
1363 return new Promise(function ($return, $error) {
1364 var query = '';
1365
1366 for (var name in data) {
1367 query = query.length > 0 ? query + '&' : query;
1368 query = query + encodeURIComponent(name) + '=' + encodeURIComponent(data[name]);
1369 }
1370
1371 return $return(query);
1372 });
1373 },
1374 fetch: function fetch(options) {
1375 return new Promise(function ($return, $error) {
1376 var data, copy, result, fetched, _copy, _result2;
1377
1378 data = Object.assign({}, options);
1379 data.path = data.path || this.path;
1380 data.origin = data.origin || this.origin;
1381 if (data.path && typeof data.path === 'string' && data.path.charAt(0) === '/') data.path = data.path.slice(1);
1382 if (data.origin && typeof data.origin === 'string' && data.origin.charAt(data.origin.length - 1) === '/') data.origin = data.origin.slice(0, -1);
1383 if (data.path && data.origin && !data.url) data.url = data.origin + '/' + data.path;
1384 if (!data.method) return $error(new Error('Oxe.fetcher - requires method option'));
1385 if (!data.url) return $error(new Error('Oxe.fetcher - requires url or origin and path option'));
1386 if (!data.headers && this.headers) data.headers = this.headers;
1387 if (typeof data.method === 'string') data.method = data.method.toUpperCase() || this.method;
1388 if (!data.acceptType && this.acceptType) data.acceptType = this.acceptType;
1389 if (!data.contentType && this.contentType) data.contentType = this.contentType;
1390 if (!data.responseType && this.responseType) data.responseType = this.responseType;
1391 if (!data.credentials && this.credentials) data.credentials = this.credentials;
1392 if (!data.mode && this.mode) data.mode = this.mode;
1393 if (!data.cache && this.cache) data.cahce = this.cache;
1394 if (!data.redirect && this.redirect) data.redirect = this.redirect;
1395 if (!data.referrer && this.referrer) data.referrer = this.referrer;
1396 if (!data.referrerPolicy && this.referrerPolicy) data.referrerPolicy = this.referrerPolicy;
1397 if (!data.signal && this.signal) data.signal = this.signal;
1398 if (!data.integrity && this.integrity) data.integrity = this.integrity;
1399 if (!data.keepAlive && this.keepAlive) data.keepAlive = this.keepAlive;
1400
1401 if (data.contentType) {
1402 data.headers = data.headers || {};
1403
1404 switch (data.contentType) {
1405 case 'js':
1406 data.headers['Content-Type'] = this.mime.js;
1407 break;
1408
1409 case 'xml':
1410 data.headers['Content-Type'] = this.mime.xml;
1411 break;
1412
1413 case 'html':
1414 data.headers['Content-Type'] = this.mime.html;
1415 break;
1416
1417 case 'json':
1418 data.headers['Content-Type'] = this.mime.json;
1419 break;
1420
1421 default:
1422 data.headers['Content-Type'] = data.contentType;
1423 }
1424 }
1425
1426 if (data.acceptType) {
1427 data.headers = data.headers || {};
1428
1429 switch (data.acceptType) {
1430 case 'js':
1431 data.headers['Accept'] = this.mime.js;
1432 break;
1433
1434 case 'xml':
1435 data.headers['Accept'] = this.mime.xml;
1436 break;
1437
1438 case 'html':
1439 data.headers['Accept'] = this.mime.html;
1440 break;
1441
1442 case 'json':
1443 data.headers['Accept'] = this.mime.json;
1444 break;
1445
1446 default:
1447 data.headers['Accept'] = data.acceptType;
1448 }
1449 }
1450
1451 if (typeof this.request === 'function') {
1452 copy = Object.assign({}, data);
1453 return Promise.resolve(this.request(copy)).then(function ($await_29) {
1454 try {
1455 result = $await_29;
1456
1457 if (result === false) {
1458 return $return(data);
1459 }
1460
1461 if (_typeof(result) === 'object') {
1462 Object.assign(data, result);
1463 }
1464
1465 return $If_1.call(this);
1466 } catch ($boundEx) {
1467 return $error($boundEx);
1468 }
1469 }.bind(this), $error);
1470 }
1471
1472 function $If_1() {
1473 if (data.body) {
1474 if (data.method === 'GET') {
1475 return Promise.resolve(this.serialize(data.body)).then(function ($await_30) {
1476 try {
1477 data.url = data.url + '?' + $await_30;
1478 return $If_5.call(this);
1479 } catch ($boundEx) {
1480 return $error($boundEx);
1481 }
1482 }.bind(this), $error);
1483 } else {
1484 if (data.contentType === 'json') {
1485 data.body = JSON.stringify(data.body);
1486 }
1487
1488 return $If_5.call(this);
1489 }
1490
1491 function $If_5() {
1492 return $If_2.call(this);
1493 }
1494 }
1495
1496 function $If_2() {
1497 return Promise.resolve(window.fetch(data.url, Object.assign({}, data))).then(function ($await_31) {
1498 try {
1499 fetched = $await_31;
1500 data.code = fetched.status;
1501 data.message = fetched.statusText;
1502
1503 if (!data.responseType) {
1504 data.body = fetched.body;
1505 return $If_3.call(this);
1506 } else {
1507 return Promise.resolve(fetched[data.responseType === 'buffer' ? 'arrayBuffer' : data.responseType]()).then(function ($await_32) {
1508 try {
1509 data.body = $await_32;
1510 return $If_3.call(this);
1511 } catch ($boundEx) {
1512 return $error($boundEx);
1513 }
1514 }.bind(this), $error);
1515 }
1516
1517 function $If_3() {
1518 if (this.response) {
1519 _copy = Object.assign({}, data);
1520 return Promise.resolve(this.response(_copy)).then(function ($await_33) {
1521 try {
1522 _result2 = $await_33;
1523
1524 if (_result2 === false) {
1525 return $return(data);
1526 }
1527
1528 if (_typeof(_result2) === 'object') {
1529 Object.assign(data, _result2);
1530 }
1531
1532 return $If_4.call(this);
1533 } catch ($boundEx) {
1534 return $error($boundEx);
1535 }
1536 }.bind(this), $error);
1537 }
1538
1539 function $If_4() {
1540 return $return(data);
1541 }
1542
1543 return $If_4.call(this);
1544 }
1545 } catch ($boundEx) {
1546 return $error($boundEx);
1547 }
1548 }.bind(this), $error);
1549 }
1550
1551 return $If_2.call(this);
1552 }
1553
1554 return $If_1.call(this);
1555 }.bind(this));
1556 },
1557 post: function post(data) {
1558 return new Promise(function ($return, $error) {
1559 data = typeof data === 'string' ? {
1560 url: data
1561 } : data;
1562 data.method = 'post';
1563 return $return(this.fetch(data));
1564 }.bind(this));
1565 },
1566 get: function get(data) {
1567 return new Promise(function ($return, $error) {
1568 data = typeof data === 'string' ? {
1569 url: data
1570 } : data;
1571 data.method = 'get';
1572 return $return(this.fetch(data));
1573 }.bind(this));
1574 },
1575 put: function put(data) {
1576 return new Promise(function ($return, $error) {
1577 data = typeof data === 'string' ? {
1578 url: data
1579 } : data;
1580 data.method = 'put';
1581 return $return(this.fetch(data));
1582 }.bind(this));
1583 },
1584 head: function head(data) {
1585 return new Promise(function ($return, $error) {
1586 data = typeof data === 'string' ? {
1587 url: data
1588 } : data;
1589 data.method = 'head';
1590 return $return(this.fetch(data));
1591 }.bind(this));
1592 },
1593 patch: function patch(data) {
1594 return new Promise(function ($return, $error) {
1595 data = typeof data === 'string' ? {
1596 url: data
1597 } : data;
1598 data.method = 'patch';
1599 return $return(this.fetch(data));
1600 }.bind(this));
1601 },
1602 delete: function _delete(data) {
1603 return new Promise(function ($return, $error) {
1604 data = typeof data === 'string' ? {
1605 url: data
1606 } : data;
1607 data.method = 'delete';
1608 return $return(this.fetch(data));
1609 }.bind(this));
1610 },
1611 options: function options(data) {
1612 return new Promise(function ($return, $error) {
1613 data = typeof data === 'string' ? {
1614 url: data
1615 } : data;
1616 data.method = 'options';
1617 return $return(this.fetch(data));
1618 }.bind(this));
1619 },
1620 connect: function connect(data) {
1621 return new Promise(function ($return, $error) {
1622 data = typeof data === 'string' ? {
1623 url: data
1624 } : data;
1625 data.method = 'connect';
1626 return $return(this.fetch(data));
1627 }.bind(this));
1628 }
1629 };
1630
1631 function Submit(event) {
1632 return new Promise(function ($return, $error) {
1633 var data, elements, i, l, element, type, binder, value, name, submit, options, result;
1634
1635 if (event.target.hasAttribute('o-submit') === false) {
1636 return $return();
1637 }
1638
1639 event.preventDefault();
1640 data = {};
1641 elements = event.target.querySelectorAll('*');
1642
1643 for (i = 0, l = elements.length; i < l; i++) {
1644 element = elements[i];
1645 type = element.type;
1646
1647 if (!type && name !== 'TEXTAREA' || type === 'submit' || type === 'button' || !type) {
1648 continue;
1649 }
1650
1651 binder = Binder.get('attribute', element, 'o-value');
1652 value = binder ? binder.data : element.files ? Array.prototype.slice.call(element.files) : element.value;
1653 name = element.name || (binder ? binder.values[binder.values.length - 1] : null);
1654 if (!name) continue;
1655 data[name] = value;
1656 }
1657
1658 submit = Binder.get('attribute', event.target, 'o-submit');
1659 return Promise.resolve(submit.data.call(submit.container, data, event)).then(function ($await_34) {
1660 try {
1661 options = $await_34;
1662
1663 if (_typeof(options) === 'object') {
1664 options.url = options.url || event.target.getAttribute('o-action');
1665 options.method = options.method || event.target.getAttribute('o-method');
1666 options.contentType = options.contentType || event.target.getAttribute('o-enctype');
1667 return Promise.resolve(Fetcher.fetch(options)).then(function ($await_35) {
1668 try {
1669 result = $await_35;
1670
1671 if (options.handler) {
1672 return Promise.resolve(options.handler(result)).then(function ($await_36) {
1673 try {
1674 return $If_7.call(this);
1675 } catch ($boundEx) {
1676 return $error($boundEx);
1677 }
1678 }.bind(this), $error);
1679 }
1680
1681 function $If_7() {
1682 return $If_6.call(this);
1683 }
1684
1685 return $If_7.call(this);
1686 } catch ($boundEx) {
1687 return $error($boundEx);
1688 }
1689 }.bind(this), $error);
1690 }
1691
1692 function $If_6() {
1693 if (event.target.hasAttribute('o-reset') || _typeof(options) === 'object' && options.reset) {
1694 event.target.reset();
1695 }
1696
1697 return $return();
1698 }
1699
1700 return $If_6.call(this);
1701 } catch ($boundEx) {
1702 return $error($boundEx);
1703 }
1704 }.bind(this), $error);
1705 });
1706 }
1707
1708 function Input(event) {
1709 return new Promise(function ($return, $error) {
1710 if (event.target.type !== 'radio' && event.target.type !== 'option' && event.target.type !== 'checkbox' && event.target.type !== 'select-one' && event.target.type !== 'select-multiple' && 'attributes' in event.target && 'o-value' in event.target.attributes) {
1711 var binder = Binder.get('attribute', event.target, 'o-value');
1712 Binder.render(binder, 'view');
1713 }
1714
1715 return $return();
1716 });
1717 }
1718
1719 function Reset(event) {
1720 return new Promise(function ($return, $error) {
1721 if (event.target.hasAttribute('o-reset') === false) {
1722 return $return();
1723 }
1724
1725 event.preventDefault();
1726 var elements = event.target.querySelectorAll('*');
1727
1728 for (var i = 0, l = elements.length; i < l; i++) {
1729 var element = elements[i];
1730 var name = element.nodeName;
1731 var type = element.type;
1732
1733 if (!type && name !== 'TEXTAREA' || type === 'submit' || type === 'button' || !type) {
1734 continue;
1735 }
1736
1737 var binder = Binder.get('attribute', element, 'o-value');
1738
1739 if (!binder) {
1740 if (type === 'select-one' || type === 'select-multiple') {
1741 element.selectedIndex = null;
1742 } else if (type === 'radio' || type === 'checkbox') {
1743 element.checked = false;
1744 } else {
1745 element.value = null;
1746 }
1747 } else if (type === 'select-one') {
1748 binder.data = null;
1749 } else if (type === 'select-multiple') {
1750 binder.data = [];
1751 } else if (type === 'radio' || type === 'checkbox') {
1752 binder.data = false;
1753 } else {
1754 binder.data = '';
1755 }
1756 }
1757
1758 return $return();
1759 });
1760 }
1761
1762 var DATA$1 = {};
1763 var Methods = {
1764 get data() {
1765 return DATA$1;
1766 },
1767
1768 get: function get(path) {
1769 return Utility.getByPath(this.data, path);
1770 },
1771 set: function set(path, data) {
1772 return Utility.setByPath(this.data, path, data);
1773 }
1774 };
1775 var BASE;
1776 var Path = {
1777 get base() {
1778 if (!BASE) BASE = window.document.querySelector('base');
1779 if (BASE) return BASE.href;
1780 return window.location.origin + (window.location.pathname ? window.location.pathname : '/');
1781 },
1782
1783 setup: function setup(option) {
1784 return new Promise(function ($return, $error) {
1785 option = option || {};
1786
1787 if (option.base) {
1788 BASE = window.document.querySelector('base');
1789
1790 if (!BASE) {
1791 BASE = window.document.createElement('base');
1792 window.document.head.insertBefore(BASE, window.document.head.firstElementChild);
1793 }
1794
1795 BASE.href = option.base;
1796 }
1797
1798 return $return();
1799 });
1800 },
1801 extension: function extension(data) {
1802 var position = data.lastIndexOf('.');
1803 return position > 0 ? data.slice(position + 1) : '';
1804 },
1805 clean: function clean(data) {
1806 var hash = window.location.hash;
1807 var search = window.location.search;
1808 var origin = window.location.origin;
1809 var protocol = window.location.protocol + '//';
1810
1811 if (data.slice(0, origin.length) === origin) {
1812 data = data.slice(origin.length);
1813 }
1814
1815 if (data.slice(0, protocol.length) === protocol) {
1816 data = data.slice(protocol.length);
1817 }
1818
1819 if (data.slice(-hash.length) === hash) {
1820 data = data.slice(0, -hash.length);
1821 }
1822
1823 if (data.slice(-search.length) === search) {
1824 data = data.slice(0, -search.length);
1825 }
1826
1827 return data || '/';
1828 },
1829 normalize: function normalize(data) {
1830 var parser = window.document.createElement('a');
1831 data = this.clean(data);
1832 data = data.replace(/\/+/g, '/');
1833 parser.href = data;
1834 data = parser.pathname;
1835 data = data ? data : '/';
1836
1837 if (data !== '/' && data.slice(-1) === '/') {
1838 data = data.slice(0, -1);
1839 }
1840
1841 return data;
1842 },
1843 join: function join() {
1844 if (!arguments.length) {
1845 throw new Error('Oxe.path.join - argument required');
1846 }
1847
1848 var result = [];
1849
1850 for (var i = 0, l = arguments.length; i < l; i++) {
1851 result.push(arguments[i]);
1852 }
1853
1854 return this.normalize(result.join('/'));
1855 }
1856 };
1857 var Transformer = {
1858 innerHandler: function innerHandler(character, index, string) {
1859 if (string[index - 1] === '\\') return;
1860 if (character === '\'') return '\\\'';
1861 if (character === '\"') return '\\"';
1862 if (character === '\t') return '\\t';
1863 if (character === '\r') return '\\r';
1864 if (character === '\n') return '\\n';
1865 if (character === '\w') return '\\w';
1866 if (character === '\b') return '\\b';
1867 },
1868 updateString: function updateString(value, index, string) {
1869 return string.slice(0, index) + value + string.slice(index + 1);
1870 },
1871 updateIndex: function updateIndex(value, index) {
1872 return index + value.length - 1;
1873 },
1874 template: function template(data) {
1875 var first = data.indexOf('`');
1876 var second = data.indexOf('`', first + 1);
1877 if (first === -1 || second === -1) return data;
1878 var value;
1879 var ends = 0;
1880 var starts = 0;
1881 var string = data;
1882 var isInner = false;
1883
1884 for (var index = 0; index < string.length; index++) {
1885 var character = string[index];
1886
1887 if (character === '`' && string[index - 1] !== '\\') {
1888 if (isInner) {
1889 ends++;
1890 value = '\'';
1891 isInner = false;
1892 string = this.updateString(value, index, string);
1893 index = this.updateIndex(value, index);
1894 } else {
1895 starts++;
1896 value = '\'';
1897 isInner = true;
1898 string = this.updateString(value, index, string);
1899 index = this.updateIndex(value, index);
1900 }
1901 } else if (isInner) {
1902 if (value = this.innerHandler(character, index, string)) {
1903 string = this.updateString(value, index, string);
1904 index = this.updateIndex(value, index);
1905 }
1906 }
1907 }
1908
1909 string = string.replace(/\${(.*?)}/g, '\'+$1+\'');
1910
1911 if (starts === ends) {
1912 return string;
1913 } else {
1914 throw new Error('import transformer missing backtick');
1915 }
1916 },
1917 exp: /export\s+default\s*(var|let|const)?/,
1918 imps: /import(?:\s+(?:\*\s+as\s+)?\w+\s+from)?\s+(?:'|").*?(?:'|");?\n?/g,
1919 imp: /import(?:\s+(?:\*\s+as\s+)?(\w+)\s+from)?\s+(?:'|")(.*?)(?:'|");?\n?/,
1920 module: function module(code, url) {
1921 var before = 'return Promise.all([\n';
1922 var after = ']).then(function ($MODULES) {\n';
1923 var parentImport = url.slice(0, url.lastIndexOf('/') + 1);
1924 var imps = code.match(this.imps) || [];
1925
1926 for (var i = 0, l = imps.length; i < l; i++) {
1927 var imp = imps[i].match(this.imp);
1928 var rawImport = imp[0];
1929 var nameImport = imp[1];
1930 var pathImport = imp[2];
1931
1932 if (pathImport.slice(0, 1) !== '/') {
1933 pathImport = Path.normalize(parentImport + '/' + pathImport);
1934 } else {
1935 pathImport = Path.normalize(pathImport);
1936 }
1937
1938 before = before + '\t$LOADER.load("' + pathImport + '"),\n';
1939 after = after + 'var ' + nameImport + ' = $MODULES[' + i + '].default;\n';
1940 code = code.replace(rawImport, '');
1941 }
1942
1943 if (this.exp.test(code)) {
1944 code = code.replace(this.exp, 'var $DEFAULT = ');
1945 code = code + '\n\nreturn { default: $DEFAULT };\n';
1946 }
1947
1948 code = '"use strict";\n' + before + after + code + '}).catch(function (error) { return error; });';
1949 return code;
1950 }
1951 };
1952 var Loader = {
1953 data: {},
1954 type: 'esm',
1955 setup: function setup(options) {
1956 return new Promise(function ($return, $error) {
1957 var self = this;
1958 options = options || {};
1959 this.type = options.type || this.type;
1960
1961 if (options.loads) {
1962 return $return(Promise.all(options.loads.map(function (load) {
1963 return self.load(load);
1964 })));
1965 }
1966
1967 return $return();
1968 }.bind(this));
1969 },
1970 fetch: function fetch(url, type) {
1971 return new Promise(function ($return, $error) {
1972 var data, code, method, result;
1973 return Promise.resolve(window.fetch(url)).then(function ($await_37) {
1974 try {
1975 data = $await_37;
1976
1977 if (data.status == 404) {
1978 return $error(new Error('Oxe.loader.load - not found ' + url));
1979 }
1980
1981 if (data.status < 200 || data.status > 300 && data.status != 304) {
1982 return $error(new Error(data.statusText));
1983 }
1984
1985 return Promise.resolve(data.text()).then(function ($await_38) {
1986 try {
1987 code = $await_38;
1988
1989 if (type === 'es' || type === 'est') {
1990 code = Transformer.template(code);
1991 }
1992
1993 if (type === 'es' || type === 'esm') {
1994 code = Transformer.module(code, url);
1995 }
1996
1997 method = new Function('window', 'document', '$LOADER', code);
1998 return Promise.resolve(method(window, window.document, this)).then(function ($await_39) {
1999 try {
2000 result = $await_39;
2001
2002 if (result instanceof Error) {
2003 return $error(new result.constructor("".concat(result.message, " - ").concat(url), result.fileName, result.lineNumber));
2004 }
2005
2006 return $return(this.data[url] = result);
2007 } catch ($boundEx) {
2008 return $error($boundEx);
2009 }
2010 }.bind(this), $error);
2011 } catch ($boundEx) {
2012 return $error($boundEx);
2013 }
2014 }.bind(this), $error);
2015 } catch ($boundEx) {
2016 return $error($boundEx);
2017 }
2018 }.bind(this), $error);
2019 }.bind(this));
2020 },
2021 load: function load() {
2022 var $args = arguments;
2023 return new Promise(function ($return, $error) {
2024 var url, type;
2025
2026 if (_typeof($args[0]) === 'object') {
2027 url = $args[0]['url'];
2028 type = $args[0]['type'];
2029 } else {
2030 url = $args[0];
2031 type = $args[1] || this.type;
2032 }
2033
2034 if (!url) {
2035 return $error(new Error('Oxe.loader.load - url argument required'));
2036 }
2037
2038 url = Path.normalize(url);
2039
2040 if (url in this.data === false) {
2041 this.data[url] = this.fetch(url, type);
2042 }
2043
2044 return $return(this.data[url]);
2045 }.bind(this));
2046 }
2047 };
2048 var Observer = {
2049 splice: function splice() {
2050 var self = this;
2051 var startIndex = arguments[0];
2052 var deleteCount = arguments[1];
2053 var addCount = arguments.length > 2 ? arguments.length - 2 : 0;
2054
2055 if (typeof startIndex !== 'number' || typeof deleteCount !== 'number') {
2056 return [];
2057 }
2058
2059 if (startIndex < 0) {
2060 startIndex = self.length + startIndex;
2061 startIndex = startIndex > 0 ? startIndex : 0;
2062 } else {
2063 startIndex = startIndex < self.length ? startIndex : self.length;
2064 }
2065
2066 if (deleteCount < 0) {
2067 deleteCount = 0;
2068 } else if (deleteCount > self.length - startIndex) {
2069 deleteCount = self.length - startIndex;
2070 }
2071
2072 var totalCount = self.$meta.length;
2073 var argumentIndex = 2;
2074 var argumentsCount = arguments.length - argumentIndex;
2075 var result = self.slice(startIndex, deleteCount);
2076 var updateCount = totalCount - 1 - startIndex;
2077 var promises = [];
2078 var length = self.length + addCount - deleteCount;
2079
2080 if (self.length !== length) {
2081 promises.push(self.$meta.listener.bind(null, self, self.$meta.path.slice(0, -1), 'length'));
2082 }
2083
2084 if (updateCount > 0) {
2085 var value;
2086 var _index3 = startIndex;
2087
2088 while (updateCount--) {
2089 var key = _index3++;
2090
2091 if (argumentsCount && argumentIndex < argumentsCount) {
2092 value = arguments[argumentIndex++];
2093 } else {
2094 value = self.$meta[_index3];
2095 }
2096
2097 self.$meta[key] = Observer.create(value, self.$meta.listener, self.$meta.path + key);
2098 promises.push(self.$meta.listener.bind(null, self.$meta[key], self.$meta.path + key, key));
2099 }
2100 }
2101
2102 if (addCount > 0) {
2103 while (addCount--) {
2104 var _key = self.length;
2105
2106 if (_key in this === false) {
2107 Object.defineProperty(this, _key, Observer.descriptor(_key));
2108 }
2109
2110 self.$meta[_key] = Observer.create(arguments[argumentIndex++], self.$meta.listener, self.$meta.path + _key);
2111 promises.push(self.$meta.listener.bind(null, self.$meta[_key], self.$meta.path + _key, _key));
2112 }
2113 }
2114
2115 if (deleteCount > 0) {
2116 while (deleteCount--) {
2117 self.$meta.length--;
2118 self.length--;
2119 var _key2 = self.length;
2120 promises.push(self.$meta.listener.bind(null, undefined, self.$meta.path + _key2, _key2));
2121 }
2122 }
2123
2124 Promise.resolve().then(function () {
2125 promises.reduce(function (promise, item) {
2126 return promise.then(item);
2127 }, Promise.resolve());
2128 }).catch(console.error);
2129 return result;
2130 },
2131 arrayProperties: function arrayProperties() {
2132 var self = this;
2133 return {
2134 push: {
2135 value: function value() {
2136 if (!arguments.length) return this.length;
2137
2138 for (var i = 0, l = arguments.length; i < l; i++) {
2139 self.splice.call(this, this.length, 0, arguments[i]);
2140 }
2141
2142 return this.length;
2143 }
2144 },
2145 unshift: {
2146 value: function value() {
2147 if (!arguments.length) return this.length;
2148
2149 for (var i = 0, l = arguments.length; i < l; i++) {
2150 self.splice.call(this, 0, 0, arguments[i]);
2151 }
2152
2153 return this.length;
2154 }
2155 },
2156 pop: {
2157 value: function value() {
2158 if (!this.length) return;
2159 var result = self.splice.call(this, this.length - 1, 1);
2160 return result[0];
2161 }
2162 },
2163 shift: {
2164 value: function value() {
2165 if (!this.length) return;
2166 var result = self.splice.call(this, 0, 1);
2167 return result[0];
2168 }
2169 },
2170 splice: {
2171 value: self.splice
2172 }
2173 };
2174 },
2175 objectProperties: function objectProperties() {
2176 var self = this;
2177 return {
2178 $get: {
2179 value: function value(key) {
2180 return this.$meta[key];
2181 }
2182 },
2183 $set: {
2184 value: function value(key, _value3) {
2185 if (_value3 !== this.$meta[key]) {
2186 if (key in this === false) {
2187 Object.defineProperty(this, key, self.descriptor(key));
2188 }
2189
2190 this.$meta[key] = self.create(_value3, this.$meta.listener, this.$meta.path + key);
2191 this.$meta.listener(this.$meta[key], this.$meta.path + key, key, this);
2192 }
2193 }
2194 },
2195 $remove: {
2196 value: function value(key) {
2197 if (key in this) {
2198 if (this.constructor === Array) {
2199 return self.splice.call(this, key, 1);
2200 } else {
2201 var result = this[key];
2202 delete this.$meta[key];
2203 delete this[key];
2204 this.$meta.listener(undefined, this.$meta.path + key, key);
2205 return result;
2206 }
2207 }
2208 }
2209 }
2210 };
2211 },
2212 descriptor: function descriptor(key) {
2213 var self = this;
2214 return {
2215 enumerable: true,
2216 configurable: true,
2217 get: function get() {
2218 return this.$meta[key];
2219 },
2220 set: function set(value) {
2221 if (value !== this.$meta[key]) {
2222 this.$meta[key] = self.create(value, this.$meta.listener, this.$meta.path + key);
2223 this.$meta.listener(this.$meta[key], this.$meta.path + key, key, this);
2224 }
2225 }
2226 };
2227 },
2228 create: function create(source, listener, path) {
2229 if (!source || source.constructor !== Object && source.constructor !== Array) {
2230 return source;
2231 }
2232
2233 path = path ? path + '.' : '';
2234 var type = source.constructor;
2235 var target = source.constructor();
2236 var descriptors = {};
2237 descriptors.$meta = {
2238 value: source.constructor()
2239 };
2240 descriptors.$meta.value.path = path;
2241 descriptors.$meta.value.listener = listener;
2242
2243 if (type === Array) {
2244 for (var key = 0, length = source.length; key < length; key++) {
2245 descriptors.$meta.value[key] = this.create(source[key], listener, path + key);
2246 descriptors[key] = this.descriptor(key);
2247 }
2248 }
2249
2250 if (type === Object) {
2251 for (var _key3 in source) {
2252 descriptors.$meta.value[_key3] = this.create(source[_key3], listener, path + _key3);
2253 descriptors[_key3] = this.descriptor(_key3);
2254 }
2255 }
2256
2257 Object.defineProperties(target, descriptors);
2258 Object.defineProperties(target, this.objectProperties(source, listener, path));
2259
2260 if (type === Array) {
2261 Object.defineProperties(target, this.arrayProperties(source, listener, path));
2262 }
2263
2264 return target;
2265 }
2266 };
2267 var Model = {
2268 GET: 2,
2269 SET: 3,
2270 REMOVE: 4,
2271 data: null,
2272 tasks: [],
2273 target: {},
2274 setup: function setup(options) {
2275 return new Promise(function ($return, $error) {
2276 options = options || {};
2277 this.target = options.target || this.target;
2278 this.data = Observer.create(this.target, this.listener.bind(this));
2279 return $return();
2280 }.bind(this));
2281 },
2282 traverse: function traverse(type, keys, value) {
2283 var result;
2284
2285 if (typeof keys === 'string') {
2286 keys = keys.split('.');
2287 }
2288
2289 var data = this.data;
2290 var key = keys[keys.length - 1];
2291
2292 for (var i = 0, l = keys.length - 1; i < l; i++) {
2293 if (!(keys[i] in data)) {
2294 if (type === this.GET || type === this.REMOVE) {
2295 return undefined;
2296 } else if (type === this.SET) {
2297 data.$set(keys[i], isNaN(keys[i + 1]) ? {} : []);
2298 }
2299 }
2300
2301 data = data[keys[i]];
2302 }
2303
2304 if (type === this.SET) {
2305 result = data.$set(key, value);
2306 } else if (type === this.GET) {
2307 result = data[key];
2308 } else if (type === this.REMOVE) {
2309 result = data[key];
2310 data.$remove(key);
2311 }
2312
2313 return result;
2314 },
2315 get: function get(keys) {
2316 return this.traverse(this.GET, keys);
2317 },
2318 remove: function remove(keys) {
2319 return this.traverse(this.REMOVE, keys);
2320 },
2321 set: function set(keys, value) {
2322 return this.traverse(this.SET, keys, value);
2323 },
2324 listener: function listener(data, location, type) {
2325 var parts = location.split('.');
2326 var part = parts.slice(1).join('.');
2327 var scope = parts.slice(0, 1).join('.');
2328 var paths = Binder.get('location', scope);
2329 if (!paths) return;
2330 paths.forEach(function (binders, path) {
2331 if (part === '' || path === part || type !== 'length' && path.indexOf(part + '.') === 0) {
2332 binders.forEach(function (binder) {
2333 Binder.render(binder);
2334 });
2335 }
2336 });
2337 }
2338 };
2339 var STYLE = document.createElement('style');
2340 var SHEET = STYLE.sheet;
2341 STYLE.setAttribute('title', 'oxe');
2342 STYLE.setAttribute('type', 'text/css');
2343 var Style$1 = {
2344 get style() {
2345 return STYLE;
2346 },
2347
2348 get sheet() {
2349 return SHEET;
2350 },
2351
2352 add: function add(data) {
2353 this.sheet.insertRule(data);
2354 },
2355 append: function append(data) {
2356 this.style.appendChild(document.createTextNode(data));
2357 },
2358 setup: function setup(option) {
2359 return new Promise(function ($return, $error) {
2360 option = option || {};
2361
2362 if (option.style) {
2363 this.append(option.style);
2364 }
2365
2366 document.head.appendChild(this.style);
2367 return $return();
2368 }.bind(this));
2369 }
2370 };
2371 var Definer = {
2372 setup: function setup() {
2373 return new Promise(function ($return, $error) {
2374 if (window.Reflect === undefined) {
2375 window.Reflect = window.Reflect || {};
2376
2377 window.Reflect.construct = function (parent, args, child) {
2378 var target = child === undefined ? parent : child;
2379 var prototype = target.prototype || Object.prototype;
2380 var copy = Object.create(prototype);
2381 return Function.prototype.apply.call(parent, copy, args) || copy;
2382 };
2383 }
2384
2385 return $return();
2386 });
2387 },
2388 define: function define(name, constructor) {
2389 constructor = constructor || function () {};
2390
2391 var construct = function construct() {
2392 var instance = window.Reflect.construct(HTMLElement, [], this.constructor);
2393 constructor.call(instance);
2394 return instance;
2395 };
2396
2397 var prototypes = Object.getOwnPropertyDescriptors(constructor.prototype);
2398 construct.prototype = Object.create(HTMLElement.prototype);
2399 Object.defineProperties(construct.prototype, prototypes);
2400 Object.defineProperty(construct.prototype, 'constructor', {
2401 enumerable: false,
2402 writable: true,
2403 value: construct
2404 });
2405 window.customElements.define(name, construct);
2406 }
2407 };
2408 var Component = {
2409 data: {},
2410 setup: function setup(options) {
2411 return new Promise(function ($return, $error) {
2412 var self = this;
2413 options = options || {};
2414
2415 if (options.components) {
2416 return $return(Promise.all(options.components.map(function (component) {
2417 if (typeof component === 'string') {
2418 return Loader.load(component).then(function (load) {
2419 return self.define(load.default);
2420 });
2421 } else {
2422 return self.define(component);
2423 }
2424 })));
2425 }
2426
2427 return $return();
2428 }.bind(this));
2429 },
2430 style: function style(_style, name) {
2431 _style = _style.replace(/\n|\r|\t/g, '');
2432 _style = _style.replace(/:host/g, name);
2433
2434 if (!window.CSS || !window.CSS.supports || !window.CSS.supports('(--t: black)')) {
2435 var matches = _style.match(/--\w+(?:-+\w+)*:\s*.*?;/g) || [];
2436
2437 for (var i = 0, l = matches.length; i < l; i++) {
2438 var match = matches[i];
2439 var rule = match.match(/(--\w+(?:-+\w+)*):\s*(.*?);/);
2440 var pattern = new RegExp('var\\(' + rule[1] + '\\)', 'g');
2441 _style = _style.replace(rule[0], '');
2442 _style = _style.replace(pattern, rule[2]);
2443 }
2444 }
2445
2446 return _style;
2447 },
2448 slot: function slot(element, fragment) {
2449 var fragmentSlots = fragment.querySelectorAll('slot[name]');
2450 var defaultSlot = fragment.querySelector('slot:not([name])');
2451
2452 for (var i = 0, l = fragmentSlots.length; i < l; i++) {
2453 var fragmentSlot = fragmentSlots[i];
2454 var name = fragmentSlot.getAttribute('name');
2455 var elementSlot = element.querySelector('[slot="' + name + '"]');
2456
2457 if (elementSlot) {
2458 fragmentSlot.parentNode.replaceChild(elementSlot, fragmentSlot);
2459 } else {
2460 fragmentSlot.parentNode.removeChild(fragmentSlot);
2461 }
2462 }
2463
2464 if (defaultSlot) {
2465 if (element.children.length) {
2466 while (element.firstChild) {
2467 defaultSlot.parentNode.insertBefore(element.firstChild, defaultSlot);
2468 }
2469 }
2470
2471 defaultSlot.parentNode.removeChild(defaultSlot);
2472 }
2473 },
2474 fragment: function fragment(element, template, adopt) {
2475 var fragment = document.createDocumentFragment();
2476 var clone = template.cloneNode(true);
2477 var child = clone.firstElementChild;
2478
2479 while (child) {
2480 if (!adopt) {
2481 Binder.add(child, {
2482 container: element,
2483 scope: element.scope
2484 });
2485 }
2486
2487 fragment.appendChild(child);
2488 child = clone.firstElementChild;
2489 }
2490
2491 return fragment;
2492 },
2493 render: function render(element, template, adopt, shadow) {
2494 if (!template) {
2495 return;
2496 }
2497
2498 var fragment = this.fragment(element, template);
2499 var root;
2500
2501 if (shadow && 'attachShadow' in document.body) {
2502 root = element.attachShadow({
2503 mode: 'open'
2504 });
2505 } else if (shadow && 'createShadowRoot' in document.body) {
2506 root = element.createShadowRoot();
2507 } else {
2508 if (fragment) {
2509 this.slot(element, fragment);
2510 }
2511
2512 root = element;
2513 }
2514
2515 if (fragment) {
2516 root.appendChild(fragment);
2517 }
2518
2519 if (adopt) {
2520 var child = root.firstElementChild;
2521
2522 while (child) {
2523 Binder.add(child, {
2524 container: element,
2525 scope: element.scope
2526 });
2527 child = child.nextElementSibling;
2528 }
2529 }
2530 },
2531 define: function define(options) {
2532 var self = this;
2533
2534 if (_typeof(options) !== 'object') {
2535 return console.warn('Oxe.component.define - invalid argument type');
2536 }
2537
2538 if (options.constructor === Array) {
2539 for (var i = 0, l = options.length; i < l; i++) {
2540 self.define(options[i]);
2541 }
2542
2543 return;
2544 }
2545
2546 if (!options.name) {
2547 return console.warn('Oxe.component.define - requires name');
2548 }
2549
2550 options.name = options.name.toLowerCase();
2551
2552 if (options.name in self.data) {
2553 console.log(options.name);
2554 return console.warn('Oxe.component.define - component defined');
2555 }
2556
2557 self.data[options.name] = options;
2558 options.count = 0;
2559 options.model = options.model || {};
2560 options.adopt = options.adopt || false;
2561 options.methods = options.methods || {};
2562 options.shadow = options.shadow || false;
2563 options.attributes = options.attributes || [];
2564 options.properties = options.properties || {};
2565
2566 if (options.style) {
2567 options.style = this.style(options.style, options.name);
2568 Style$1.append(options.style);
2569 }
2570
2571 if (options.template && typeof options.template === 'string') {
2572 var data = document.createElement('div');
2573 data.innerHTML = options.template;
2574 options.template = data;
2575 }
2576
2577 var constructor = function constructor() {
2578 this._created = false;
2579 this._scope = options.name + '-' + options.count++;
2580 var properties = Utility.clone(options.properties);
2581 var methods = Utility.clone(options.methods);
2582 var model = Utility.clone(options.model);
2583 Object.defineProperties(this, properties);
2584 Methods.set(this.scope, methods);
2585 Model.set(this.scope, model);
2586 };
2587
2588 Object.defineProperties(constructor.prototype, {
2589 created: {
2590 get: function get() {
2591 return this._created;
2592 }
2593 },
2594 scope: {
2595 get: function get() {
2596 return this._scope;
2597 }
2598 },
2599 methods: {
2600 get: function get() {
2601 return Methods.get(this.scope);
2602 }
2603 },
2604 model: {
2605 get: function get() {
2606 return Model.get(this.scope);
2607 },
2608 set: function set(data) {
2609 return Model.set(this.scope, data && _typeof(data) === 'object' ? data : {});
2610 }
2611 },
2612 observedAttributes: {
2613 value: options.attributes
2614 },
2615 attributeChangedCallback: {
2616 value: function value() {
2617 if (options.attributed) options.attributed.apply(this, arguments);
2618 }
2619 },
2620 adoptedCallback: {
2621 value: function value() {
2622 if (options.adopted) options.adopted.apply(this, arguments);
2623 }
2624 },
2625 disconnectedCallback: {
2626 value: function value() {
2627 if (options.detached) options.detached.call(this);
2628 }
2629 },
2630 connectedCallback: {
2631 value: function value() {
2632 var instance = this;
2633
2634 if (instance.created) {
2635 if (options.attached) {
2636 options.attached.call(instance);
2637 }
2638 } else {
2639 instance._created = true;
2640 self.render(instance, options.template, options.adopt, options.shadow);
2641 Promise.resolve().then(function () {
2642 if (options.created) {
2643 return options.created.call(instance);
2644 }
2645 }).then(function () {
2646 if (options.attached) {
2647 return options.attached.call(instance);
2648 }
2649 });
2650 }
2651 }
2652 }
2653 });
2654 Definer.define(options.name, constructor);
2655 }
2656 };
2657
2658 function Listener(option, method, event) {
2659 var type = event.type;
2660 var before;
2661 var after;
2662
2663 if (type in option.listener) {
2664 before = typeof option.listener[type].before === 'function' ? option.listener[type].before.bind(null, event) : null;
2665 after = typeof option.listener[type].after === 'function' ? option.listener[type].after.bind(null, event) : null;
2666 }
2667
2668 Promise.resolve().then(before).then(method.bind(null, event)).then(after);
2669 }
2670
2671 var EVENTS = {};
2672 var Events = {
2673 get events() {
2674 return EVENTS;
2675 },
2676
2677 on: function on(name, method) {
2678 if (!(name in this.events)) {
2679 this.events[name] = [];
2680 }
2681
2682 this.events[name].push(method);
2683 },
2684 off: function off(name, method) {
2685 if (name in this.events) {
2686 var _index4 = this.events[name].indexOf(method);
2687
2688 if (_index4 !== -1) {
2689 this.events[name].splice(_index4, 1);
2690 }
2691 }
2692 },
2693 emit: function emit(name) {
2694 if (name in this.events) {
2695 var methods = this.events[name];
2696 var args = Array.prototype.slice.call(arguments, 2);
2697 Promise.all(methods.map(function (method) {
2698 return method.apply(this, args);
2699 })).catch(console.error);
2700 }
2701 }
2702 };
2703 var Event = Object.create(Events);
2704 var Router = {
2705 on: Event.on.bind(Event),
2706 off: Event.off.bind(Event),
2707 emit: Event.emit.bind(Event),
2708 data: [],
2709 ran: false,
2710 location: {},
2711 mode: 'push',
2712 target: null,
2713 contain: false,
2714 folder: './routes',
2715 setup: function setup(option) {
2716 return new Promise(function ($return, $error) {
2717 option = option || {};
2718 this.base = option.base === undefined ? this.base : option.base;
2719 this.mode = option.mode === undefined ? this.mode : option.mode;
2720 this.after = option.after === undefined ? this.after : option.after;
2721 this.folder = option.folder === undefined ? this.folder : option.folder;
2722 this.before = option.before === undefined ? this.before : option.before;
2723 this.change = option.change === undefined ? this.change : option.change;
2724 this.target = option.target === undefined ? this.target : option.target;
2725 this.contain = option.contain === undefined ? this.contain : option.contain;
2726 this.external = option.external === undefined ? this.external : option.external;
2727
2728 if (!this.target || typeof this.target === 'string') {
2729 this.target = document.body.querySelector(this.target || 'o-router');
2730 }
2731
2732 if (this.mode !== 'href') {
2733 window.addEventListener('popstate', this.state.bind(this), true);
2734 window.document.addEventListener('click', this.click.bind(this), true);
2735 }
2736
2737 Definer.define('o-router');
2738 return Promise.resolve(this.add(option.routes)).then(function ($await_40) {
2739 try {
2740 return Promise.resolve(this.route(window.location.href, {
2741 mode: 'replace'
2742 })).then(function ($await_41) {
2743 try {
2744 return $return();
2745 } catch ($boundEx) {
2746 return $error($boundEx);
2747 }
2748 }, $error);
2749 } catch ($boundEx) {
2750 return $error($boundEx);
2751 }
2752 }.bind(this), $error);
2753 }.bind(this));
2754 },
2755 compareParts: function compareParts(routePath, userPath, split) {
2756 var compareParts = [];
2757 var routeParts = routePath.split(split);
2758 var userParts = userPath.split(split);
2759
2760 if (userParts.length > 1 && userParts[userParts.length - 1] === '') {
2761 userParts.pop();
2762 }
2763
2764 if (routeParts.length > 1 && routeParts[routeParts.length - 1] === '') {
2765 routeParts.pop();
2766 }
2767
2768 for (var i = 0, l = routeParts.length; i < l; i++) {
2769 if (routeParts[i].slice(0, 1) === '(' && routeParts[i].slice(-1) === ')') {
2770 if (routeParts[i] === '(~)') {
2771 return true;
2772 } else if (routeParts[i].indexOf('~') !== -1) {
2773 if (userParts[i]) {
2774 compareParts.push(userParts[i]);
2775 }
2776 } else {
2777 compareParts.push(userParts[i]);
2778 }
2779 } else if (routeParts[i] !== userParts[i]) {
2780 return false;
2781 } else {
2782 compareParts.push(routeParts[i]);
2783 }
2784 }
2785
2786 if (compareParts.join(split) === userParts.join(split)) {
2787 return true;
2788 } else {
2789 return false;
2790 }
2791 },
2792 compare: function compare(routePath, userPath) {
2793 var base = Path.normalize(Path.base);
2794 userPath = Path.normalize(userPath);
2795 routePath = Path.normalize(routePath);
2796
2797 if (userPath.slice(0, base.length) !== base) {
2798 userPath = Path.join(base, userPath);
2799 }
2800
2801 if (routePath.slice(0, base.length) !== base) {
2802 routePath = Path.join(base, routePath);
2803 }
2804
2805 if (this.compareParts(routePath, userPath, '/')) {
2806 return true;
2807 }
2808
2809 if (this.compareParts(routePath, userPath, '-')) {
2810 return true;
2811 }
2812
2813 return false;
2814 },
2815 toParameterObject: function toParameterObject(routePath, userPath) {
2816 var result = {};
2817 if (!routePath || !userPath || routePath === '/' || userPath === '/') return result;
2818 var userParts = userPath.split(/\/|-/);
2819 var routeParts = routePath.split(/\/|-/);
2820
2821 for (var i = 0, l = routeParts.length; i < l; i++) {
2822 var part = routeParts[i];
2823
2824 if (part.slice(0, 1) === '(' && part.slice(-1) === ')') {
2825 var name = part.slice(1, part.length - 1).replace('~', '');
2826 result[name] = userParts[i];
2827 }
2828 }
2829
2830 return result;
2831 },
2832 toQueryString: function toQueryString(data) {
2833 var result = '?';
2834
2835 for (var key in data) {
2836 var value = data[key];
2837 result += key + '=' + value + '&';
2838 }
2839
2840 if (result.slice(-1) === '&') {
2841 result = result.slice(0, -1);
2842 }
2843
2844 return result;
2845 },
2846 toQueryObject: function toQueryObject(path) {
2847 var result = {};
2848 if (path.indexOf('?') === 0) path = path.slice(1);
2849 var queries = path.split('&');
2850
2851 for (var i = 0, l = queries.length; i < l; i++) {
2852 var query = queries[i].split('=');
2853
2854 if (query[0] && query[1]) {
2855 result[query[0]] = query[1];
2856 }
2857 }
2858
2859 return result;
2860 },
2861 toLocationObject: function toLocationObject(href) {
2862 var location = {};
2863 var parser = document.createElement('a');
2864 parser.href = href;
2865 location.href = parser.href;
2866 location.host = parser.host;
2867 location.port = parser.port;
2868 location.hash = parser.hash;
2869 location.search = parser.search;
2870 location.protocol = parser.protocol;
2871 location.hostname = parser.hostname;
2872 location.pathname = parser.pathname[0] === '/' ? parser.pathname : '/' + parser.pathname;
2873 location.path = location.pathname + location.search + location.hash;
2874 return location;
2875 },
2876 scroll: function scroll(x, y) {
2877 window.scroll(x, y);
2878 },
2879 back: function back() {
2880 window.history.back();
2881 },
2882 forward: function forward() {
2883 window.history.forward();
2884 },
2885 redirect: function redirect(path) {
2886 window.location.href = path;
2887 },
2888 add: function add(data) {
2889 return new Promise(function ($return, $error) {
2890 var path, load, i, l;
2891
2892 if (!data) {
2893 return $return();
2894 } else {
2895 if (data.constructor === String) {
2896 path = data;
2897
2898 if (path.slice(-3) === '.js') {
2899 path = path.slice(0, -3);
2900 }
2901
2902 load = path;
2903
2904 if (path.slice(-5) === 'index') {
2905 path = path.slice(0, -5);
2906 }
2907
2908 if (path.slice(-6) === 'index/') {
2909 path = path.slice(0, -6);
2910 }
2911
2912 if (path.slice(0, 2) === './') {
2913 path = path.slice(2);
2914 }
2915
2916 if (path.slice(0, 1) !== '/') {
2917 path = '/' + path;
2918 }
2919
2920 load = load + '.js';
2921 load = Path.join(this.folder, load);
2922 this.data.push({
2923 path: path,
2924 load: load
2925 });
2926 return $If_9.call(this);
2927 } else {
2928 if (data.constructor === Object) {
2929 if (!data.path) {
2930 return $error(new Error('Oxe.router.add - route path required'));
2931 }
2932
2933 if (!data.name && !data.load && !data.component) {
2934 return $error(new Error('Oxe.router.add - route requires name, load, or component property'));
2935 }
2936
2937 this.data.push(data);
2938 return $If_10.call(this);
2939 } else {
2940 if (data.constructor === Array) {
2941 i = 0, l = data.length;
2942 var $Loop_12_trampoline;
2943
2944 function $Loop_12_step() {
2945 i++;
2946 return $Loop_12;
2947 }
2948
2949 function $Loop_12() {
2950 if (i < l) {
2951 return Promise.resolve(this.add(data[i])).then(function ($await_42) {
2952 try {
2953 return $Loop_12_step;
2954 } catch ($boundEx) {
2955 return $error($boundEx);
2956 }
2957 }, $error);
2958 } else return [1];
2959 }
2960
2961 return ($Loop_12_trampoline = function (q) {
2962 while (q) {
2963 if (q.then) return void q.then($Loop_12_trampoline, $error);
2964
2965 try {
2966 if (q.pop) {
2967 if (q.length) return q.pop() ? $Loop_12_exit.call(this) : q;else q = $Loop_12_step;
2968 } else q = q.call(this);
2969 } catch (_exception) {
2970 return $error(_exception);
2971 }
2972 }
2973 }.bind(this))($Loop_12);
2974
2975 function $Loop_12_exit() {
2976 return $If_11.call(this);
2977 }
2978 }
2979
2980 function $If_11() {
2981 return $If_10.call(this);
2982 }
2983
2984 return $If_11.call(this);
2985 }
2986
2987 function $If_10() {
2988 return $If_9.call(this);
2989 }
2990 }
2991
2992 function $If_9() {
2993 return $If_8.call(this);
2994 }
2995 }
2996
2997 function $If_8() {
2998 return $return();
2999 }
3000
3001 return $If_8.call(this);
3002 }.bind(this));
3003 },
3004 load: function load(route) {
3005 return new Promise(function ($return, $error) {
3006 var load, _load;
3007
3008 if (route.load) {
3009 return Promise.resolve(Loader.load(route.load)).then(function ($await_43) {
3010 try {
3011 load = $await_43;
3012 route = Object.assign({}, load.default, route);
3013 return $If_14.call(this);
3014 } catch ($boundEx) {
3015 return $error($boundEx);
3016 }
3017 }.bind(this), $error);
3018 }
3019
3020 function $If_14() {
3021 if (typeof route.component === 'string') {
3022 route.load = route.component;
3023 return Promise.resolve(Loader.load(route.load)).then(function ($await_44) {
3024 try {
3025 _load = $await_44;
3026 route.component = _load.default;
3027 return $If_15.call(this);
3028 } catch ($boundEx) {
3029 return $error($boundEx);
3030 }
3031 }.bind(this), $error);
3032 }
3033
3034 function $If_15() {
3035 return $return(route);
3036 }
3037
3038 return $If_15.call(this);
3039 }
3040
3041 return $If_14.call(this);
3042 });
3043 },
3044 remove: function remove(path) {
3045 return new Promise(function ($return, $error) {
3046 for (var i = 0, l = this.data.length; i < l; i++) {
3047 if (this.data[i].path === path) {
3048 this.data.splice(i, 1);
3049 }
3050 }
3051
3052 return $return();
3053 }.bind(this));
3054 },
3055 get: function get(path) {
3056 return new Promise(function ($return, $error) {
3057 var i, l;
3058 i = 0, l = this.data.length;
3059 var $Loop_16_trampoline;
3060
3061 function $Loop_16_step() {
3062 i++;
3063 return $Loop_16;
3064 }
3065
3066 function $Loop_16() {
3067 if (i < l) {
3068 if (this.data[i].path === path) {
3069 return Promise.resolve(this.load(this.data[i])).then(function ($await_45) {
3070 try {
3071 this.data[i] = $await_45;
3072 return $return(this.data[i]);
3073 } catch ($boundEx) {
3074 return $error($boundEx);
3075 }
3076 }.bind(this), $error);
3077 }
3078
3079 return $Loop_16_step;
3080 } else return [1];
3081 }
3082
3083 return ($Loop_16_trampoline = function (q) {
3084 while (q) {
3085 if (q.then) return void q.then($Loop_16_trampoline, $error);
3086
3087 try {
3088 if (q.pop) {
3089 if (q.length) return q.pop() ? $Loop_16_exit.call(this) : q;else q = $Loop_16_step;
3090 } else q = q.call(this);
3091 } catch (_exception) {
3092 return $error(_exception);
3093 }
3094 }
3095 }.bind(this))($Loop_16);
3096
3097 function $Loop_16_exit() {
3098 return $return();
3099 }
3100 }.bind(this));
3101 },
3102 filter: function filter(path) {
3103 return new Promise(function ($return, $error) {
3104 var result, i, l;
3105 result = [];
3106 i = 0, l = this.data.length;
3107 var $Loop_19_trampoline;
3108
3109 function $Loop_19_step() {
3110 i++;
3111 return $Loop_19;
3112 }
3113
3114 function $Loop_19() {
3115 if (i < l) {
3116 if (this.compare(this.data[i].path, path)) {
3117 return Promise.resolve(this.load(this.data[i])).then(function ($await_46) {
3118 try {
3119 this.data[i] = $await_46;
3120 result.push(this.data[i]);
3121 return $If_21.call(this);
3122 } catch ($boundEx) {
3123 return $error($boundEx);
3124 }
3125 }.bind(this), $error);
3126 }
3127
3128 function $If_21() {
3129 return $Loop_19_step;
3130 }
3131
3132 return $If_21.call(this);
3133 } else return [1];
3134 }
3135
3136 return ($Loop_19_trampoline = function (q) {
3137 while (q) {
3138 if (q.then) return void q.then($Loop_19_trampoline, $error);
3139
3140 try {
3141 if (q.pop) {
3142 if (q.length) return q.pop() ? $Loop_19_exit.call(this) : q;else q = $Loop_19_step;
3143 } else q = q.call(this);
3144 } catch (_exception) {
3145 return $error(_exception);
3146 }
3147 }
3148 }.bind(this))($Loop_19);
3149
3150 function $Loop_19_exit() {
3151 return $return(result);
3152 }
3153 }.bind(this));
3154 },
3155 find: function find(path) {
3156 return new Promise(function ($return, $error) {
3157 var i, l;
3158 i = 0, l = this.data.length;
3159 var $Loop_22_trampoline;
3160
3161 function $Loop_22_step() {
3162 i++;
3163 return $Loop_22;
3164 }
3165
3166 function $Loop_22() {
3167 if (i < l) {
3168 if (this.compare(this.data[i].path, path)) {
3169 return Promise.resolve(this.load(this.data[i])).then(function ($await_47) {
3170 try {
3171 this.data[i] = $await_47;
3172 return $return(this.data[i]);
3173 } catch ($boundEx) {
3174 return $error($boundEx);
3175 }
3176 }.bind(this), $error);
3177 }
3178
3179 return $Loop_22_step;
3180 } else return [1];
3181 }
3182
3183 return ($Loop_22_trampoline = function (q) {
3184 while (q) {
3185 if (q.then) return void q.then($Loop_22_trampoline, $error);
3186
3187 try {
3188 if (q.pop) {
3189 if (q.length) return q.pop() ? $Loop_22_exit.call(this) : q;else q = $Loop_22_step;
3190 } else q = q.call(this);
3191 } catch (_exception) {
3192 return $error(_exception);
3193 }
3194 }
3195 }.bind(this))($Loop_22);
3196
3197 function $Loop_22_exit() {
3198 return $return();
3199 }
3200 }.bind(this));
3201 },
3202 render: function render(route) {
3203 return new Promise(function ($return, $error) {
3204 if (!route) {
3205 return $error(new Error('Oxe.render - route argument required. Missing object option.'));
3206 }
3207
3208 if (route.title) {
3209 document.title = route.title;
3210 }
3211
3212 var ensures = [];
3213
3214 if (route.keywords) {
3215 ensures.push({
3216 name: 'meta',
3217 query: '[name="keywords"]',
3218 attributes: [{
3219 name: 'name',
3220 value: 'keywords'
3221 }, {
3222 name: 'content',
3223 value: route.keywords
3224 }]
3225 });
3226 }
3227
3228 if (route.description) {
3229 ensures.push({
3230 name: 'meta',
3231 query: '[name="description"]',
3232 attributes: [{
3233 name: 'name',
3234 value: 'description'
3235 }, {
3236 name: 'content',
3237 value: route.description
3238 }]
3239 });
3240 }
3241
3242 if (route.canonical) {
3243 ensures.push({
3244 name: 'link',
3245 query: '[rel="canonical"]',
3246 attributes: [{
3247 name: 'rel',
3248 value: 'canonical'
3249 }, {
3250 name: 'href',
3251 value: route.canonical
3252 }]
3253 });
3254 }
3255
3256 if (ensures.length) {
3257 Promise.all(ensures.map(function (option) {
3258 return Promise.resolve().then(function () {
3259 option.position = 'afterbegin';
3260 option.scope = document.head;
3261 return Utility.ensureElement(option);
3262 });
3263 }));
3264 }
3265
3266 if (!route.target) {
3267 if (!route.component) {
3268 Component.define(route);
3269 route.target = window.document.createElement(route.name);
3270 } else if (route.component.constructor === String) {
3271 route.target = window.document.createElement(route.component);
3272 } else if (route.component.constructor === Object) {
3273 Component.define(route.component);
3274 route.target = window.document.createElement(route.component.name);
3275 } else {
3276 return $error(new Error('Oxe.router.render - route requires name, load, or component property'));
3277 }
3278 }
3279
3280 if (this.target) {
3281 while (this.target.firstChild) {
3282 this.target.removeChild(this.target.firstChild);
3283 }
3284
3285 this.target.appendChild(route.target);
3286 }
3287
3288 this.scroll(0, 0);
3289 return $return();
3290 }.bind(this));
3291 },
3292 route: function route(path, options) {
3293 return new Promise(function ($return, $error) {
3294 var mode, location, route;
3295 options = options || {};
3296
3297 if (options.query) {
3298 path += this.toQueryString(options.query);
3299 }
3300
3301 mode = options.mode || this.mode;
3302 location = this.toLocationObject(path);
3303 return Promise.resolve(this.find(location.pathname)).then(function ($await_48) {
3304 try {
3305 route = $await_48;
3306
3307 if (!route) {
3308 return $error(new Error("Oxe.router.route - missing route ".concat(location.pathname)));
3309 }
3310
3311 location.route = route;
3312 location.title = location.route.title;
3313 location.query = this.toQueryObject(location.search);
3314 location.parameters = this.toParameterObject(location.route.path, location.pathname);
3315
3316 if (location.route && location.route.handler) {
3317 return Promise.resolve(location.route.handler(location)).then($return, $error);
3318 }
3319
3320 if (location.route && location.route.redirect) {
3321 return Promise.resolve(this.redirect(location.route.redirect)).then($return, $error);
3322 }
3323
3324 function $If_26() {
3325 if (typeof this.before === 'function') {
3326 return Promise.resolve(this.before(location)).then(function ($await_51) {
3327 try {
3328 return $If_27.call(this);
3329 } catch ($boundEx) {
3330 return $error($boundEx);
3331 }
3332 }.bind(this), $error);
3333 }
3334
3335 function $If_27() {
3336 this.emit('route:before', location);
3337
3338 if (mode === 'href') {
3339 return $return(window.location.assign(location.path));
3340 }
3341
3342 window.history[mode + 'State']({
3343 path: location.path
3344 }, '', location.path);
3345 this.location = location;
3346 return Promise.resolve(this.render(location.route)).then(function ($await_52) {
3347 try {
3348 if (typeof this.after === 'function') {
3349 return Promise.resolve(this.after(location)).then(function ($await_53) {
3350 try {
3351 return $If_28.call(this);
3352 } catch ($boundEx) {
3353 return $error($boundEx);
3354 }
3355 }.bind(this), $error);
3356 }
3357
3358 function $If_28() {
3359 this.emit('route:after', location);
3360 return $return();
3361 }
3362
3363 return $If_28.call(this);
3364 } catch ($boundEx) {
3365 return $error($boundEx);
3366 }
3367 }.bind(this), $error);
3368 }
3369
3370 return $If_27.call(this);
3371 }
3372
3373 if (typeof this.before === 'function') {
3374 return Promise.resolve(this.before(location)).then(function ($await_51) {
3375 try {
3376 return $If_27.call(this);
3377 } catch ($boundEx) {
3378 return $error($boundEx);
3379 }
3380 }.bind(this), $error);
3381 }
3382
3383 function $If_27() {
3384 this.emit('route:before', location);
3385
3386 if (mode === 'href') {
3387 return $return(window.location.assign(location.path));
3388 }
3389
3390 window.history[mode + 'State']({
3391 path: location.path
3392 }, '', location.path);
3393 this.location = location;
3394 return Promise.resolve(this.render(location.route)).then(function ($await_52) {
3395 try {
3396 if (typeof this.after === 'function') {
3397 return Promise.resolve(this.after(location)).then(function ($await_53) {
3398 try {
3399 return $If_28.call(this);
3400 } catch ($boundEx) {
3401 return $error($boundEx);
3402 }
3403 }.bind(this), $error);
3404 }
3405
3406 function $If_28() {
3407 this.emit('route:after', location);
3408 return $return();
3409 }
3410
3411 return $If_28.call(this);
3412 } catch ($boundEx) {
3413 return $error($boundEx);
3414 }
3415 }.bind(this), $error);
3416 }
3417
3418 return $If_27.call(this);
3419 } catch ($boundEx) {
3420 return $error($boundEx);
3421 }
3422 }.bind(this), $error);
3423 }.bind(this));
3424 },
3425 state: function state(event) {
3426 return new Promise(function ($return, $error) {
3427 var path = event && event.state ? event.state.path : window.location.href;
3428 this.route(path, {
3429 mode: 'replace'
3430 });
3431 return $return();
3432 }.bind(this));
3433 },
3434 click: function click(event) {
3435 return new Promise(function ($return, $error) {
3436 if (event.target.type || event.button !== 0 || event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) {
3437 return $return();
3438 }
3439
3440 var target = event.path ? event.path[0] : event.target;
3441 var parent = target.parentElement;
3442
3443 if (this.contain) {
3444 while (parent) {
3445 if (parent.nodeName === 'O-ROUTER') {
3446 break;
3447 } else {
3448 parent = parent.parentElement;
3449 }
3450 }
3451
3452 if (parent.nodeName !== 'O-ROUTER') {
3453 return $return();
3454 }
3455 }
3456
3457 while (target && 'A' !== target.nodeName) {
3458 target = target.parentElement;
3459 }
3460
3461 if (!target || 'A' !== target.nodeName) {
3462 return $return();
3463 }
3464
3465 if (target.hasAttribute('download') || target.hasAttribute('external') || target.hasAttribute('o-external') || target.href.indexOf('tel:') === 0 || target.href.indexOf('ftp:') === 0 || target.href.indexOf('file:') === 0 || target.href.indexOf('mailto:') === 0 || target.href.indexOf(window.location.origin) !== 0 || target.hash !== '' && target.origin === window.location.origin && target.pathname === window.location.pathname) return $return();
3466 if (this.external && (this.external.constructor === RegExp && this.external.test(target.href) || this.external.constructor === Function && this.external(target.href) || this.external.constructor === String && this.external === target.href)) return $return();
3467 event.preventDefault();
3468
3469 if (this.location.href !== target.href) {
3470 this.route(target.href);
3471 }
3472
3473 return $return();
3474 }.bind(this));
3475 }
3476 };
3477 document.head.insertAdjacentHTML('afterbegin', '<style>:not(:defined){visibility:hidden;}o-router,o-router>:first-child{display:block;}</style>');
3478 var oSetup = document.querySelector('script[o-setup]');
3479
3480 if (oSetup) {
3481 Promise.resolve().then(function () {
3482 var attribute = oSetup.getAttribute('o-setup');
3483
3484 if (!attribute) {
3485 throw new Error('Oxe - attribute o-setup requires arguments');
3486 }
3487
3488 var options = attribute.split(/\s+|\s*,+\s*/);
3489 Loader.type = options[1] || 'esm';
3490 return Loader.load(options[0]);
3491 });
3492 }
3493
3494 var SETUP = false;
3495 var GLOBAL = {};
3496 var index = Object.freeze({
3497 global: GLOBAL,
3498 component: Component,
3499 batcher: Batcher,
3500 definer: Definer,
3501 fetcher: Fetcher,
3502 methods: Methods,
3503 utility: Utility,
3504 binder: Binder,
3505 loader: Loader,
3506 router: Router,
3507 model: Model,
3508 style: Style$1,
3509 path: Path,
3510 setup: function setup(options) {
3511 var self = this;
3512 if (SETUP) return;else SETUP = true;
3513 options = options || {};
3514 options.listener = options.listener || {};
3515 document.addEventListener('input', Listener.bind(null, options, Input), true);
3516 document.addEventListener('reset', Listener.bind(null, options, Reset), true);
3517 document.addEventListener('change', Listener.bind(null, options, Change), true);
3518 document.addEventListener('submit', Listener.bind(null, options, Submit), true);
3519 return Promise.all([self.path.setup(options.path), self.style.setup(options.style), self.model.setup(options.model), self.binder.setup(options.binder), self.loader.setup(options.loader), self.definer.setup(options.definer), self.fetcher.setup(options.fetcher)]).then(function () {
3520 if (options.listener.before) {
3521 return options.listener.before();
3522 }
3523 }).then(function () {
3524 if (options.component) {
3525 return self.component.setup(options.component);
3526 }
3527 }).then(function () {
3528 if (options.router) {
3529 return self.router.setup(options.router);
3530 }
3531 }).then(function () {
3532 if (options.listener.after) {
3533 return options.listener.after();
3534 }
3535 });
3536 }
3537 });
3538 return index;
3539});
\No newline at end of file