@aegis-framework/pandora 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/pandora.js CHANGED
@@ -1,806 +1,2 @@
1
- // modules are defined as an array
2
- // [ module function, map of requires ]
3
- //
4
- // map of requires is short require name -> numeric require
5
- //
6
- // anything defined in a previous bundle is accessed via the
7
- // orig method which is the require for previous bundles
8
- parcelRequire = (function (modules, cache, entry, globalName) {
9
- // Save the require from previous bundle to this closure if any
10
- var previousRequire = typeof parcelRequire === 'function' && parcelRequire;
11
- var nodeRequire = typeof require === 'function' && require;
12
-
13
- function newRequire(name, jumped) {
14
- if (!cache[name]) {
15
- if (!modules[name]) {
16
- // if we cannot find the module within our internal map or
17
- // cache jump to the current global require ie. the last bundle
18
- // that was added to the page.
19
- var currentRequire = typeof parcelRequire === 'function' && parcelRequire;
20
- if (!jumped && currentRequire) {
21
- return currentRequire(name, true);
22
- }
23
-
24
- // If there are other bundles on this page the require from the
25
- // previous one is saved to 'previousRequire'. Repeat this as
26
- // many times as there are bundles until the module is found or
27
- // we exhaust the require chain.
28
- if (previousRequire) {
29
- return previousRequire(name, true);
30
- }
31
-
32
- // Try the node require function if it exists.
33
- if (nodeRequire && typeof name === 'string') {
34
- return nodeRequire(name);
35
- }
36
-
37
- var err = new Error('Cannot find module \'' + name + '\'');
38
- err.code = 'MODULE_NOT_FOUND';
39
- throw err;
40
- }
41
-
42
- localRequire.resolve = resolve;
43
- localRequire.cache = {};
44
-
45
- var module = cache[name] = new newRequire.Module(name);
46
-
47
- modules[name][0].call(module.exports, localRequire, module, module.exports, this);
48
- }
49
-
50
- return cache[name].exports;
51
-
52
- function localRequire(x){
53
- return newRequire(localRequire.resolve(x));
54
- }
55
-
56
- function resolve(x){
57
- return modules[name][1][x] || x;
58
- }
59
- }
60
-
61
- function Module(moduleName) {
62
- this.id = moduleName;
63
- this.bundle = newRequire;
64
- this.exports = {};
65
- }
66
-
67
- newRequire.isParcelRequire = true;
68
- newRequire.Module = Module;
69
- newRequire.modules = modules;
70
- newRequire.cache = cache;
71
- newRequire.parent = previousRequire;
72
- newRequire.register = function (id, exports) {
73
- modules[id] = [function (require, module) {
74
- module.exports = exports;
75
- }, {}];
76
- };
77
-
78
- var error;
79
- for (var i = 0; i < entry.length; i++) {
80
- try {
81
- newRequire(entry[i]);
82
- } catch (e) {
83
- // Save first error but execute all entries
84
- if (!error) {
85
- error = e;
86
- }
87
- }
88
- }
89
-
90
- if (entry.length) {
91
- // Expose entry point to Node, AMD or browser globals
92
- // Based on https://github.com/ForbesLindesay/umd/blob/master/template.js
93
- var mainExports = newRequire(entry[entry.length - 1]);
94
-
95
- // CommonJS
96
- if (typeof exports === "object" && typeof module !== "undefined") {
97
- module.exports = mainExports;
98
-
99
- // RequireJS
100
- } else if (typeof define === "function" && define.amd) {
101
- define(function () {
102
- return mainExports;
103
- });
104
-
105
- // <script>
106
- } else if (globalName) {
107
- this[globalName] = mainExports;
108
- }
109
- }
110
-
111
- // Override the current require with this new one
112
- parcelRequire = newRequire;
113
-
114
- if (error) {
115
- // throw error from earlier, _after updating parcelRequire_
116
- throw error;
117
- }
118
-
119
- return newRequire;
120
- })({"yzgE":[function(require,module,exports) {
121
- "use strict";
122
-
123
- Object.defineProperty(exports, "__esModule", {
124
- value: true
125
- });
126
- exports.callAsync = callAsync;
127
- exports.deserializeCSS = deserializeCSS;
128
-
129
- /**
130
- *
131
- * @param {*} callable
132
- * @param {*} context
133
- * @param {...any} args
134
- */
135
- function callAsync(callable, context, ...args) {
136
- try {
137
- // Call the provided function using the context and arguments given
138
- const result = callable.apply(context, args); // Check if the function returned a simple value or a Promise
139
-
140
- if (result instanceof Promise) {
141
- return result;
142
- } else {
143
- return Promise.resolve(result);
144
- }
145
- } catch (e) {
146
- return Promise.reject(e);
147
- }
148
- }
149
- /**
150
- *
151
- * @param {*} object
152
- * @param {*} encapsulation
153
- * @param {*} level
154
- */
155
-
156
-
157
- function deserializeCSS(object, encapsulation = '', level = 0) {
158
- const keys = Object.keys(object);
159
- let css = '';
160
-
161
- for (const key of keys) {
162
- if (typeof object[key] === 'object') {
163
- if (encapsulation) {
164
- if (key.indexOf('&') === 0) {
165
- css += `${key.replace(/&/g, encapsulation)} {\n`;
166
- } else {
167
- css += `${encapsulation} ${key} {\n`;
168
- }
169
- } else {
170
- css += `${key} {\n`;
171
- }
172
-
173
- const properties = Object.keys(object[key]);
174
-
175
- for (const property of properties) {
176
- css += '\t'.repeat(level);
177
-
178
- if (typeof object[key][property] === 'object') {
179
- const temp = {};
180
- temp[property] = object[key][property];
181
- css += deserializeCSS(temp, encapsulation, level + 1);
182
- } else {
183
- css += `\t${property}: ${object[key][property]};\n`;
184
- }
185
- }
186
-
187
- css += '}\n';
188
- } else {
189
- css += '\t'.repeat(level);
190
- css += `\t${key}: ${object[key]};\n`;
191
- }
192
- }
193
-
194
- return css;
195
- }
196
- },{}],"Simw":[function(require,module,exports) {
197
- "use strict";
198
-
199
- Object.defineProperty(exports, "__esModule", {
200
- value: true
201
- });
202
- exports.Component = void 0;
203
-
204
- var _Util = require("./Util");
205
-
206
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
207
-
208
- /**
209
- * A component represents a custom HTML element, and has all of its functionality
210
- * as well as its general structure and representation self contained on it.
211
- *
212
- * @class Component
213
- */
214
- class Component extends HTMLElement {
215
- /**
216
- * _tag {String} - The tag name for the component
217
- *
218
- * @static
219
- */
220
- static get tag() {
221
- if (typeof this._tag === 'undefined') {
222
- let tag = this.name;
223
- const matches = tag.match(/([A-Z])/g);
224
-
225
- if (matches !== null) {
226
- for (const match of matches) {
227
- tag = tag.replace(match, `-${match}`.toLowerCase());
228
- }
229
- }
230
-
231
- this._tag = tag.slice(1);
232
- }
233
-
234
- return this._tag;
235
- }
236
-
237
- static set tag(value) {
238
- this._tag = value;
239
- }
240
- /**
241
- * These are the types that can be set as properties on the HTML code of the
242
- * element.
243
- */
244
-
245
-
246
- static template(html = null, context = null) {
247
- if (html !== null) {
248
- this._template = html;
249
- document.querySelectorAll(this.tag).forEach(instance => {
250
- if (instance._isReady) {
251
- instance.forceRender();
252
- }
253
- });
254
- } else {
255
- // Check if no parameters were set but the HTML is still a function to be called
256
- if (typeof this._template === 'function') {
257
- return this._template.call(context);
258
- } // If this is reached, the HTML was just a string
259
-
260
-
261
- return this._template;
262
- }
263
- }
264
-
265
- constructor() {
266
- super();
267
- this._children = this.innerHTML.trim(); // State Object for the component
268
-
269
- this._state = {}; // Props Object for the component
270
-
271
- this._props = {}; // List of callbacks to run once the component has been mounted successfully
272
-
273
- this._ready = [];
274
- this._connected = false;
275
- this._isReady = false;
276
- this._style = {};
277
- this._styleElement = null;
278
- }
279
- /**
280
- * width - Determines the real (computed) width of the element
281
- *
282
- * @return {int} - Computed Width of the element on pixels
283
- */
284
-
285
-
286
- get width() {
287
- return parseInt(getComputedStyle(this).width.replace('px', ''));
288
- }
289
-
290
- set width(value) {
291
- this.style.width = value;
292
- }
293
- /**
294
- * height - Determines the real (computed) height of the element
295
- *
296
- * @return {int} - Computed height of the element on pixels
297
- */
298
-
299
-
300
- get height() {
301
- return parseInt(getComputedStyle(this).height.replace('px', ''));
302
- }
303
-
304
- set height(value) {
305
- this.style.height = value;
306
- }
307
-
308
- get static() {
309
- return new Proxy(this.constructor, {});
310
- }
311
-
312
- set static(value) {
313
- throw new Error('Component static properties cannot be reassigned.');
314
- }
315
-
316
- get props() {
317
- return new Proxy(this, {
318
- get: (target, key) => {
319
- if (this.hasAttribute(key)) {
320
- let value = this.getAttribute(key);
321
-
322
- if (typeof value === 'string') {
323
- if (value === 'false') {
324
- value = false;
325
- } else if (value === 'true' || value === '') {
326
- value = true;
327
- } else if (!isNaN(value)) {
328
- if (value.indexOf('.') > 0) {
329
- value = parseFloat(value);
330
- } else {
331
- value = parseInt(value);
332
- }
333
- }
334
- }
335
-
336
- return value;
337
- } else if (key in this._props) {
338
- return this._props[key];
339
- }
340
-
341
- return null;
342
- },
343
- set: (target, key, value) => {
344
- throw new Error('Component props should be set using the `setProps` function.');
345
- }
346
- });
347
- }
348
-
349
- set props(value) {
350
- if (this._connected === false) {
351
- this._props = Object.assign({}, this._props, value);
352
- } else {
353
- throw new Error('Component props cannot be directly assigned. Use the `setProps` function instead.');
354
- }
355
- }
356
-
357
- get state() {
358
- return new Proxy(this._state, {
359
- get: (target, key) => {
360
- return target[key];
361
- },
362
- set: (target, key, value) => {
363
- if (this._connected === false) {
364
- return target[key] = value;
365
- } else {
366
- throw new Error('Component state should be set using the `setState` function instead.');
367
- }
368
- }
369
- });
370
- }
371
-
372
- set state(value) {
373
- if (this._connected === false) {
374
- this._state = Object.assign({}, this._state, value);
375
- } else {
376
- throw new Error('Component state should be set using the `setState` function instead.');
377
- }
378
- }
379
-
380
- get dom() {
381
- return this;
382
- }
383
-
384
- set dom(value) {
385
- throw new Error('Component DOM can not be overwritten.');
386
- }
387
- /**
388
- * register - Register the component as a custom HTML element
389
- * using the component's tag as the actual element tag.
390
- *
391
- * This action cannot be reverted nor the controller class for
392
- * the element can be changed.
393
- */
394
-
395
-
396
- static register() {
397
- window.customElements.define(this.tag, this);
398
- }
399
- /**
400
- * template - A simple function providing access to the basic HTML
401
- * structure of the component.
402
- *
403
- * @param {function|string} html - A string or function that renders the
404
- * component into a valid HTML structure.
405
- *
406
- * @returns {void|string} - Void or the HTML structure in a string
407
- */
408
-
409
-
410
- template(html = null) {
411
- return this.static.template(html, this);
412
- }
413
-
414
- _createStyleElement() {
415
- const sharedStyle = document.body.querySelector(`style#${this.static.tag}`);
416
-
417
- if (sharedStyle !== null) {
418
- this._styleElement = sharedStyle;
419
- }
420
-
421
- if (!(this._styleElement instanceof HTMLStyleElement)) {
422
- this._styleElement = document.createElement('style');
423
- this._styleElement.id = this.static.tag;
424
- document.body.prepend(this._styleElement);
425
- }
426
- }
427
-
428
- setStyle(style, reset = false) {
429
- this._createStyleElement();
430
-
431
- if (typeof style === 'object') {
432
- if (reset === false) {
433
- this._style = Object.assign({}, this._style, style);
434
- } else {
435
- this._style = Object.assign({}, style);
436
- }
437
-
438
- this._styleElement.innerHTML = (0, _Util.deserializeCSS)(this._style, this.static.tag);
439
- } else if (typeof style === 'string') {
440
- if (reset === false) {
441
- this._styleElement.innerHTML += style;
442
- } else {
443
- this._styleElement.innerHTML = style;
444
- }
445
- }
446
-
447
- return this._style;
448
- }
449
-
450
- setState(state) {
451
- if (typeof state === 'object') {
452
- const oldState = Object.assign({}, this._state);
453
- this._state = Object.assign({}, this._state, state);
454
-
455
- for (const key of Object.keys(state)) {
456
- this.updateCallback(key, oldState[key], this._state[key], 'state', oldState, this._state);
457
- }
458
- } else {
459
- throw new TypeError(`A state must be an object. Received ${typeof state}.`);
460
- }
461
- }
462
-
463
- setProps(props) {
464
- if (typeof props === 'object') {
465
- const oldProps = Object.assign({}, this._props);
466
- this._props = Object.assign({}, this._props, props);
467
-
468
- for (const key of Object.keys(props)) {
469
- this.updateCallback(key, oldProps[key], this._props[key], 'props', oldProps, this._props);
470
- }
471
-
472
- this._setPropAttributes(true);
473
- } else {
474
- throw new TypeError(`Props must be an object. Received ${typeof state}.`);
475
- }
476
- }
477
-
478
- _setPropAttributes(update = false) {
479
- for (const key of Object.keys(this._props)) {
480
- const value = this._props[key];
481
-
482
- if (this.static._explicitPropTypes.indexOf(typeof value) > -1) {
483
- if (update === true) {
484
- this.setAttribute(key, this._props[key]);
485
- } else {
486
- this._props[key] = this.props[key];
487
- this.setAttribute(key, this.props[key]);
488
- }
489
- }
490
- }
491
- }
492
- /*
493
- * =========================
494
- * Update Cycle
495
- * =========================
496
- */
497
-
498
-
499
- willUpdate(origin, property, oldValue, newValue, oldObject, newObject) {
500
- return Promise.resolve();
501
- }
502
-
503
- update(origin, property, oldValue, newValue, oldObject, newObject) {
504
- return Promise.resolve();
505
- }
506
-
507
- didUpdate(origin, property, oldValue, newValue, oldObject, newObject) {
508
- return Promise.resolve();
509
- }
510
-
511
- onStateUpdate(property, oldValue, newValue, oldObject, newObject) {
512
- return Promise.resolve();
513
- }
514
-
515
- onPropsUpdate(property, oldValue, newValue, oldObject, newObject) {
516
- return Promise.resolve();
517
- }
518
- /*
519
- * =========================
520
- * Mount Cycle
521
- * =========================
522
- */
523
-
524
-
525
- willMount() {
526
- return Promise.resolve();
527
- }
528
-
529
- didMount() {
530
- return Promise.resolve();
531
- }
532
- /*
533
- * =========================
534
- * Unmount Cycle
535
- * =========================
536
- */
537
-
538
-
539
- willUnmount() {
540
- return Promise.resolve();
541
- }
542
-
543
- unmount() {
544
- return Promise.resolve();
545
- }
546
-
547
- didUnmount() {
548
- return Promise.resolve();
549
- }
550
- /*
551
- * =========================
552
- * Render Cycle
553
- * =========================
554
- */
555
-
556
- /**
557
- * Forces the component to be rendered again.
558
- *
559
- * @returns {string|Promise<string>} - The HTML to render on the component
560
- */
561
-
562
-
563
- forceRender() {
564
- return this._render();
565
- }
566
- /**
567
- * This function is the one that defines the HTML that will be rendered
568
- * inside the component. Since some content may need to be loaded before the
569
- * component is rendered, this function can also return a promise.
570
- *
571
- * @returns {string|Promise<string>} - The HTML to render on the component
572
- */
573
-
574
-
575
- render() {
576
- return '';
577
- }
578
-
579
- _render() {
580
- let render = this.render; // Check if a template has been set to this component, and if that's the
581
- // case, use that instead of the render function to render the component's
582
- // HTML code.
583
-
584
- if (this.static._template !== null) {
585
- render = this.template;
586
- } // Call the render function asynchronously and set the HTML from it to the
587
- // component.
588
-
589
-
590
- return (0, _Util.callAsync)(render, this).then(html => {
591
- const slot = this.dom.querySelector('slot');
592
-
593
- if (typeof html === 'string') {
594
- html = html.trim();
595
-
596
- if (html === '') {
597
- return;
598
- }
599
- }
600
-
601
- if (html === null || typeof html === 'undefined') {
602
- return;
603
- }
604
-
605
- if (slot !== null) {
606
- slot.replaceWith(html);
607
- } else {
608
- this.innerHTML = html;
609
-
610
- if (this._children !== '' && html.indexOf(this._children) === -1) {
611
- this.innerHTML += this._children;
612
- }
613
- }
614
- });
615
- }
616
-
617
- connectedCallback() {
618
- // Set the state as connected
619
- this._connected = true; // Add a data property with the tag of the component
620
-
621
- this.dataset.component = this.static.tag; // Check if a template for this component was set. The contents on this
622
- // if block will only be run once.
623
-
624
- if (typeof this.static._template === 'undefined') {
625
- // Check if there is an HTML template for this component
626
- const template = document.querySelector(`template#${this.static.tag}`);
627
-
628
- if (template !== null) {
629
- // If there is, set is as the template for the component
630
- this.template(template.innerHTML);
631
- } else {
632
- // If not, set is as null
633
- this.static._template = null;
634
- }
635
- } // Set the initial prop attributes for the component using the given
636
- // props
637
-
638
-
639
- this._setPropAttributes(); // Start the Mount Cycle
640
-
641
-
642
- return this.willMount().then(() => {
643
- return this._render().then(() => {
644
- return this.didMount().then(() => {
645
- this._isReady = true;
646
-
647
- for (const callback of this._ready) {
648
- callback.call(this);
649
- }
650
- });
651
- });
652
- });
653
- }
654
- /**
655
- * Adds a callback to be run once the component has been mounted successfully
656
- *
657
- * @param {function} callback - Callback to run once the component is ready
658
- */
659
-
660
-
661
- ready(callback) {
662
- this._ready.push(callback);
663
- }
664
-
665
- disconnectedCallback() {
666
- return this.willUnmount().then(() => {
667
- return this.unmount().then(() => {
668
- return this.didUnmount();
669
- });
670
- });
671
- }
672
-
673
- updateCallback(property, oldValue, newValue, origin = 'props', oldObject = {}, newObject = {}) {
674
- return this.willUpdate(origin, property, oldValue, newValue, oldObject, newObject).then(() => {
675
- return this.update(origin, property, oldValue, newValue, oldObject, newObject).then(() => {
676
- let promise;
677
-
678
- if (origin === 'state') {
679
- promise = this.onStateUpdate(property, oldValue, newValue, oldObject, newObject);
680
- } else {
681
- promise = this.onPropsUpdate(property, oldValue, newValue, oldObject, newObject);
682
- }
683
-
684
- return promise.then(() => {
685
- return this.didUpdate(origin, property, oldValue, newValue, oldObject, newObject);
686
- });
687
- });
688
- }).catch(e => {
689
- console.error(e); // Component should not update
690
- });
691
- }
692
-
693
- attributeChangedCallback(property, oldValue, newValue) {}
694
-
695
- }
696
-
697
- exports.Component = Component;
698
-
699
- _defineProperty(Component, "_tag", void 0);
700
-
701
- _defineProperty(Component, "_explicitPropTypes", ['boolean', 'string', 'number']);
702
-
703
- _defineProperty(Component, "_template", undefined);
704
- },{"./Util":"yzgE"}],"Lecv":[function(require,module,exports) {
705
- "use strict";
706
-
707
- Object.defineProperty(exports, "__esModule", {
708
- value: true
709
- });
710
- exports.ShadowComponent = void 0;
711
-
712
- var _Component = require("./Component");
713
-
714
- var _Util = require("./Util");
715
-
716
- /**
717
- * @class ShadowComponent
718
- */
719
- class ShadowComponent extends _Component.Component {
720
- constructor(...props) {
721
- super(...props);
722
- this._shadowDOM = this.attachShadow({
723
- mode: 'open'
724
- });
725
- }
726
-
727
- _createStyleElement() {
728
- if (!(this._styleElement instanceof HTMLStyleElement)) {
729
- this._styleElement = document.createElement('style');
730
- this.dom.prepend(this._styleElement);
731
- }
732
- }
733
-
734
- _render() {
735
- let render = this.render; // Check if a template has been set to this component, and if that's the
736
- // case, use that instead of the render function to render the component's
737
- // HTML code.
738
-
739
- if (this.static._template !== null) {
740
- render = this.template;
741
- } // Call the render function asynchronously and set the HTML from it to the
742
- // component.
743
-
744
-
745
- return (0, _Util.callAsync)(render, this).then(html => {
746
- this._shadowDOM.innerHTML = '';
747
-
748
- if (this._styleElement instanceof HTMLStyleElement) {
749
- this._shadowDOM.appendChild(this._styleElement);
750
- }
751
-
752
- this._shadowDOM.innerHTML += html;
753
- });
754
- }
755
-
756
- get dom() {
757
- return this._shadowDOM;
758
- }
759
-
760
- }
761
-
762
- exports.ShadowComponent = ShadowComponent;
763
- },{"./Component":"Simw","./Util":"yzgE"}],"Focm":[function(require,module,exports) {
764
- "use strict";
765
-
766
- Object.defineProperty(exports, "__esModule", {
767
- value: true
768
- });
769
-
770
- var _Component = require("./src/Component");
771
-
772
- Object.keys(_Component).forEach(function (key) {
773
- if (key === "default" || key === "__esModule") return;
774
- Object.defineProperty(exports, key, {
775
- enumerable: true,
776
- get: function () {
777
- return _Component[key];
778
- }
779
- });
780
- });
781
-
782
- var _ShadowComponent = require("./src/ShadowComponent");
783
-
784
- Object.keys(_ShadowComponent).forEach(function (key) {
785
- if (key === "default" || key === "__esModule") return;
786
- Object.defineProperty(exports, key, {
787
- enumerable: true,
788
- get: function () {
789
- return _ShadowComponent[key];
790
- }
791
- });
792
- });
793
-
794
- var _Util = require("./src/Util");
795
-
796
- Object.keys(_Util).forEach(function (key) {
797
- if (key === "default" || key === "__esModule") return;
798
- Object.defineProperty(exports, key, {
799
- enumerable: true,
800
- get: function () {
801
- return _Util[key];
802
- }
803
- });
804
- });
805
- },{"./src/Component":"Simw","./src/ShadowComponent":"Lecv","./src/Util":"yzgE"}]},{},["Focm"], "Pandora")
806
- //# sourceMappingURL=pandora.js.map
1
+ function t(t,e,s,n){Object.defineProperty(t,e,{get:s,set:n,enumerable:!0,configurable:!0})}t({},"Component",(()=>i));var e={};function s(t,e,...s){try{const n=t.apply(e,s);return n instanceof Promise?n:Promise.resolve(n)}catch(t){return Promise.reject(t)}}function n(t,e="",s=0){const i=Object.keys(t);let r="";for(const o of i)if("object"==typeof t[o]){e&&0!==o.indexOf("@")?0===o.indexOf("&")?r+=`${o.replace(/&/g,e)} {\n`:r+=`${e} ${o} {\n`:r+=`${o} {\n`;const i=Object.keys(t[o]);for(const l of i)if(r+="\t".repeat(s),"object"==typeof t[o][l]){const i={};i[l]=t[o][l],r+=n(i,e,s+1)}else r+=`\t${l}: ${t[o][l]};\n`;r+="}\n"}else r+="\t".repeat(s),r+=`\t${o}: ${t[o]};\n`;return r}t(e,"callAsync",(()=>s)),t(e,"deserializeCSS",(()=>n));class i extends HTMLElement{static _tag;static get tag(){if(void 0===this._tag){let t=this.name;const e=t.match(/([A-Z])/g);if(null!==e)for(const s of e)t=t.replace(s,`-${s}`.toLowerCase());this._tag=t.slice(1)}return this._tag}static set tag(t){this._tag=t}static _explicitPropTypes=["boolean","string","number"];static _template=void 0;static template(t=null,e=null){if(null===t)return"function"==typeof this._template?this._template.call(e):this._template;this._template=t,document.querySelectorAll(this.tag).forEach((t=>{t._isReady&&t.forceRender()}))}constructor(){super(),this._children=this.innerHTML.trim(),this._state={},this._props={},this._ready=[],this._connected=!1,this._isReady=!1,this._style={},this._styleElement=null}get width(){return parseInt(getComputedStyle(this).width.replace("px",""))}set width(t){this.style.width=t}get height(){return parseInt(getComputedStyle(this).height.replace("px",""))}set height(t){this.style.height=t}get static(){return new Proxy(this.constructor,{})}set static(t){throw new Error("Component static properties cannot be reassigned.")}get props(){return new Proxy(this,{get:(t,e)=>{if(this.hasAttribute(e)){let t=this.getAttribute(e);return"string"==typeof t&&("false"===t?t=!1:"true"===t||""===t?t=!0:isNaN(t)||(t=t.indexOf(".")>0?parseFloat(t):parseInt(t))),t}return e in this._props?this._props[e]:null},set:(t,e,s)=>{throw new Error("Component props should be set using the `setProps` function.")}})}set props(t){if(!1!==this._connected)throw new Error("Component props cannot be directly assigned. Use the `setProps` function instead.");this._props=Object.assign({},this._props,t)}get state(){return new Proxy(this._state,{get:(t,e)=>t[e],set:(t,e,s)=>{if(!1===this._connected)return t[e]=s;throw new Error("Component state should be set using the `setState` function instead.")}})}set state(t){if(!1!==this._connected)throw new Error("Component state should be set using the `setState` function instead.");this._state=Object.assign({},this._state,t)}get dom(){return this}set dom(t){throw new Error("Component DOM can not be overwritten.")}static register(){window.customElements.define(this.tag,this)}template(t=null){return this.static.template(t,this)}_createStyleElement(){const t=document.body.querySelector(`style#${this.static.tag}`);null!==t&&(this._styleElement=t),this._styleElement instanceof HTMLStyleElement||(this._styleElement=document.createElement("style"),this._styleElement.id=this.static.tag,document.body.prepend(this._styleElement))}setStyle(t,e=!1){return this._createStyleElement(),"object"==typeof t?(this._style=!1===e?Object.assign({},this._style,t):Object.assign({},t),this._styleElement.innerHTML=n(this._style,this.static.tag)):"string"==typeof t&&(!1===e?this._styleElement.innerHTML+=t:this._styleElement.innerHTML=t),this._style}setState(t){if("object"!=typeof t)throw new TypeError(`A state must be an object. Received ${typeof t}.`);{const e=Object.assign({},this._state);this._state=Object.assign({},this._state,t);for(const s of Object.keys(t))this.updateCallback(s,e[s],this._state[s],"state",e,this._state)}}setProps(t){if("object"!=typeof t)throw new TypeError(`Props must be an object. Received ${typeof state}.`);{const e=Object.assign({},this._props);this._props=Object.assign({},this._props,t);for(const s of Object.keys(t))this.updateCallback(s,e[s],this._props[s],"props",e,this._props);this._setPropAttributes(!0)}}_setPropAttributes(t=!1){for(const e of Object.keys(this._props)){const s=this._props[e];this.static._explicitPropTypes.indexOf(typeof s)>-1&&(!0===t?this.setAttribute(e,this._props[e]):(this._props[e]=this.props[e],this.setAttribute(e,this.props[e])))}}willUpdate(t,e,s,n,i,r){return Promise.resolve()}update(t,e,s,n,i,r){return Promise.resolve()}didUpdate(t,e,s,n,i,r){return Promise.resolve()}onStateUpdate(t,e,s,n,i){return Promise.resolve()}onPropsUpdate(t,e,s,n,i){return Promise.resolve()}willMount(){return Promise.resolve()}didMount(){return Promise.resolve()}willUnmount(){return Promise.resolve()}unmount(){return Promise.resolve()}didUnmount(){return Promise.resolve()}forceRender(){return this._render()}render(){return""}_render(){let t=this.render;return null!==this.static._template&&(t=this.template),s(t,this).then((t=>{const e=this.dom.querySelector("slot");"string"==typeof t&&""===(t=t.trim())||null!=t&&(null!==e?e.replaceWith(t):(this.innerHTML=t,""!==this._children&&-1===t.indexOf(this._children)&&(this.innerHTML+=this._children)))}))}connectedCallback(){if(this._connected=!0,this.dataset.component=this.static.tag,void 0===this.static._template){const t=document.querySelector(`template#${this.static.tag}`);null!==t?this.template(t.innerHTML):this.static._template=null}return this._setPropAttributes(),this.willMount().then((()=>this._render().then((()=>this.didMount().then((()=>{this._isReady=!0;for(const t of this._ready)t.call(this)}))))))}ready(t){this._ready.push(t)}disconnectedCallback(){return this.willUnmount().then((()=>this.unmount().then((()=>this.didUnmount()))))}updateCallback(t,e,s,n="props",i={},r={}){return this.willUpdate(n,t,e,s,i,r).then((()=>this.update(n,t,e,s,i,r).then((()=>{let o;return o="state"===n?this.onStateUpdate(t,e,s,i,r):this.onPropsUpdate(t,e,s,i,r),o.then((()=>this.didUpdate(n,t,e,s,i,r)))})))).catch((t=>{console.error(t)}))}attributeChangedCallback(t,e,s){}}t({},"ShadowComponent",(()=>r));class r extends i{constructor(...t){super(...t),this._shadowDOM=this.attachShadow({mode:"open"})}setStyle(t,e=!1){return this._createStyleElement(),"object"==typeof t?(this._style=!1===e?Object.assign({},this._style,t):Object.assign({},t),this._styleElement.innerHTML=n(this._style)):"string"==typeof t&&(!1===e?this._styleElement.innerHTML+=t:this._styleElement.innerHTML=t),this._style}_createStyleElement(){this._styleElement instanceof HTMLStyleElement||(this._styleElement=document.createElement("style"),this.dom.prepend(this._styleElement))}_render(){let t=this.render;return null!==this.static._template&&(t=this.template),s(t,this).then((t=>{this._shadowDOM.innerHTML="",this._styleElement instanceof HTMLStyleElement&&this._shadowDOM.appendChild(this._styleElement),this._shadowDOM.innerHTML+=t}))}get dom(){return this._shadowDOM}}export{i as Component,r as ShadowComponent,s as callAsync,n as deserializeCSS};
2
+ //# sourceMappingURL=pandora.js.map