@aegis-framework/pandora 0.1.4 → 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,773 +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
- function callAsync(callable, context, ...args) {
130
- try {
131
- // Call the provided function using the context and arguments given
132
- const result = callable.apply(context, args); // Check if the function returned a simple value or a Promise
133
-
134
- if (result instanceof Promise) {
135
- return result;
136
- } else {
137
- return Promise.resolve(result);
138
- }
139
- } catch (e) {
140
- return Promise.reject(e);
141
- }
142
- }
143
-
144
- function deserializeCSS(object, encapsulation = '', level = 0) {
145
- const keys = Object.keys(object);
146
- let css = '';
147
-
148
- for (const key of keys) {
149
- if (typeof object[key] === 'object') {
150
- if (encapsulation) {
151
- if (key.indexOf('&') === 0) {
152
- css += `${key.replace(/&/g, encapsulation)} {\n`;
153
- } else {
154
- css += `${encapsulation} ${key} {\n`;
155
- }
156
- } else {
157
- css += `${key} {\n`;
158
- }
159
-
160
- const properties = Object.keys(object[key]);
161
-
162
- for (const property of properties) {
163
- css += '\t'.repeat(level);
164
-
165
- if (typeof object[key][property] === 'object') {
166
- const temp = {};
167
- temp[property] = object[key][property];
168
- css += deserializeCSS(temp, encapsulation, level + 1);
169
- } else {
170
- css += `\t${property}: ${object[key][property]};\n`;
171
- }
172
- }
173
-
174
- css += '}\n';
175
- } else {
176
- css += '\t'.repeat(level);
177
- css += `\t${key}: ${object[key]};\n`;
178
- }
179
- }
180
-
181
- return css;
182
- }
183
- },{}],"Simw":[function(require,module,exports) {
184
- "use strict";
185
-
186
- Object.defineProperty(exports, "__esModule", {
187
- value: true
188
- });
189
- exports.Component = void 0;
190
-
191
- var _Util = require("./Util");
192
-
193
- 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; }
194
-
195
- /**
196
- * A component represents a custom HTML element, and has all of its functionality
197
- * as well as its general structure and representation self contained on it.
198
- *
199
- * @class Component
200
- */
201
- class Component extends HTMLElement {
202
- /**
203
- * _tag {String} - The tag name for the component
204
- *
205
- * @static
206
- */
207
- static get tag() {
208
- if (typeof this._tag === 'undefined') {
209
- let tag = this.name;
210
- const matches = tag.match(/([A-Z])/g);
211
-
212
- if (matches !== null) {
213
- for (const match of matches) {
214
- tag = tag.replace(match, `-${match}`.toLowerCase());
215
- }
216
- }
217
-
218
- this._tag = tag.slice(1);
219
- }
220
-
221
- return this._tag;
222
- }
223
-
224
- static set tag(value) {
225
- this._tag = value;
226
- }
227
- /**
228
- * These are the types that can be set as properties on the HTML code of the
229
- * element.
230
- */
231
-
232
-
233
- static template(html = null, context = null) {
234
- if (html !== null) {
235
- this._template = html;
236
- document.querySelectorAll(this.tag).forEach(instance => {
237
- if (instance._isReady) {
238
- instance.forceRender();
239
- }
240
- });
241
- } else {
242
- // Check if no parameters were set but the HTML is still a function to be called
243
- if (typeof this._template === 'function') {
244
- return this._template.call(context);
245
- } // If this is reached, the HTML was just a string
246
-
247
-
248
- return this._template;
249
- }
250
- }
251
-
252
- constructor() {
253
- super(); // State Object for the component
254
-
255
- this._state = {}; // Props Object for the component
256
-
257
- this._props = {}; // List of callbacks to run once the component has been mounted successfully
258
-
259
- this._ready = [];
260
- this._connected = false;
261
- this._isReady = false;
262
- this._style = {};
263
- this._styleElement = null;
264
- }
265
- /**
266
- * width - Determines the real (computed) width of the element
267
- *
268
- * @return {int} - Computed Width of the element on pixels
269
- */
270
-
271
-
272
- get width() {
273
- return parseInt(getComputedStyle(this).width.replace('px', ''));
274
- }
275
-
276
- set width(value) {
277
- this.style.width = value;
278
- }
279
- /**
280
- * height - Determines the real (computed) height of the element
281
- *
282
- * @return {int} - Computed height of the element on pixels
283
- */
284
-
285
-
286
- get height() {
287
- return parseInt(getComputedStyle(this).height.replace('px', ''));
288
- }
289
-
290
- set height(value) {
291
- this.style.height = value;
292
- }
293
-
294
- get static() {
295
- return new Proxy(this.constructor, {});
296
- }
297
-
298
- set static(value) {
299
- throw new Error('Component static properties cannot be reassigned.');
300
- }
301
-
302
- get props() {
303
- return new Proxy(this, {
304
- get: (target, key) => {
305
- if (this.hasAttribute(key)) {
306
- let value = this.getAttribute(key);
307
-
308
- if (typeof value === 'string') {
309
- if (value === 'false') {
310
- value = false;
311
- } else if (value === 'true' || value === '') {
312
- value = true;
313
- } else if (!isNaN(value)) {
314
- if (value.indexOf('.') > 0) {
315
- value = parseFloat(value);
316
- } else {
317
- value = parseInt(value);
318
- }
319
- }
320
- }
321
-
322
- return value;
323
- } else if (key in this._props) {
324
- return this._props[key];
325
- }
326
-
327
- return null;
328
- },
329
- set: (target, key, value) => {
330
- throw new Error('Component props should be set using the `setProps` function.');
331
- }
332
- });
333
- }
334
-
335
- set props(value) {
336
- if (this._connected === false) {
337
- this._props = Object.assign({}, this._props, value);
338
- } else {
339
- throw new Error('Component props cannot be directly assigned. Use the `setProps` function instead.');
340
- }
341
- }
342
-
343
- get state() {
344
- return new Proxy(this._state, {
345
- get: (target, key) => {
346
- return target[key];
347
- },
348
- set: (target, key, value) => {
349
- if (this._connected === false) {
350
- return target[key] = value;
351
- } else {
352
- throw new Error('Component state should be set using the `setState` function instead.');
353
- }
354
- }
355
- });
356
- }
357
-
358
- set state(value) {
359
- if (this._connected === false) {
360
- this._state = Object.assign({}, this._state, value);
361
- } else {
362
- throw new Error('Component state should be set using the `setState` function instead.');
363
- }
364
- }
365
-
366
- get dom() {
367
- return this;
368
- }
369
-
370
- set dom(value) {
371
- throw new Error('Component DOM can not be overwritten.');
372
- }
373
- /**
374
- * register - Register the component as a custom HTML element
375
- * using the component's tag as the actual element tag.
376
- *
377
- * This action cannot be reverted nor the controller class for
378
- * the element can be changed.
379
- */
380
-
381
-
382
- static register() {
383
- window.customElements.define(this.tag, this);
384
- }
385
- /**
386
- * template - A simple function providing access to the basic HTML
387
- * structure of the component.
388
- *
389
- * @param {function|string} html - A string or function that renders the
390
- * component into a valid HTML structure.
391
- *
392
- * @returns {void|string} - Void or the HTML structure in a string
393
- */
394
-
395
-
396
- template(html = null) {
397
- return this.static.template(html, this);
398
- }
399
-
400
- _createStyleElement() {
401
- const sharedStyle = document.body.querySelector(`style#${this.static.tag}`);
402
-
403
- if (sharedStyle !== null) {
404
- this._styleElement = sharedStyle;
405
- }
406
-
407
- if (!(this._styleElement instanceof HTMLStyleElement)) {
408
- this._styleElement = document.createElement('style');
409
- this._styleElement.id = this.static.tag;
410
- document.body.prepend(this._styleElement);
411
- }
412
- }
413
-
414
- setStyle(style, reset = false) {
415
- this._createStyleElement();
416
-
417
- if (typeof style === 'object') {
418
- if (reset === false) {
419
- this._style = Object.assign({}, this._style, style);
420
- } else {
421
- this._style = Object.assign({}, style);
422
- }
423
-
424
- this._styleElement.innerHTML = (0, _Util.deserializeCSS)(this._style, this.static.tag);
425
- } else if (typeof style === 'string') {
426
- if (reset === false) {
427
- this._styleElement.innerHTML += style;
428
- } else {
429
- this._styleElement.innerHTML = style;
430
- }
431
- }
432
-
433
- return this._style;
434
- }
435
-
436
- setState(state) {
437
- if (typeof state === 'object') {
438
- const oldState = Object.assign({}, this._state);
439
- this._state = Object.assign({}, this._state, state);
440
-
441
- for (const key of Object.keys(state)) {
442
- this.updateCallback(key, oldState[key], this._state[key], 'state', oldState, this._state);
443
- }
444
- } else {
445
- throw new TypeError(`A state must be an object. Received ${typeof state}.`);
446
- }
447
- }
448
-
449
- setProps(props) {
450
- if (typeof props === 'object') {
451
- const oldProps = Object.assign({}, this._props);
452
- this._props = Object.assign({}, this._props, props);
453
-
454
- for (const key of Object.keys(props)) {
455
- this.updateCallback(key, oldProps[key], this._props[key], 'props', oldProps, this._props);
456
- }
457
-
458
- this._setPropAttributes(true);
459
- } else {
460
- throw new TypeError(`Props must be an object. Received ${typeof state}.`);
461
- }
462
- }
463
-
464
- _setPropAttributes(update = false) {
465
- for (const key of Object.keys(this._props)) {
466
- const value = this._props[key];
467
-
468
- if (this.static._explicitPropTypes.indexOf(typeof value) > -1) {
469
- if (update === true) {
470
- this.setAttribute(key, this._props[key]);
471
- } else {
472
- this._props[key] = this.props[key];
473
- this.setAttribute(key, this.props[key]);
474
- }
475
- }
476
- }
477
- }
478
- /*
479
- * =========================
480
- * Update Cycle
481
- * =========================
482
- */
483
-
484
-
485
- willUpdate(origin, property, oldValue, newValue, oldObject, newObject) {
486
- return Promise.resolve();
487
- }
488
-
489
- update(origin, property, oldValue, newValue, oldObject, newObject) {
490
- return Promise.resolve();
491
- }
492
-
493
- didUpdate(origin, property, oldValue, newValue, oldObject, newObject) {
494
- return Promise.resolve();
495
- }
496
-
497
- onStateUpdate(property, oldValue, newValue, oldObject, newObject) {
498
- return Promise.resolve();
499
- }
500
-
501
- onPropsUpdate(property, oldValue, newValue, oldObject, newObject) {
502
- return Promise.resolve();
503
- }
504
- /*
505
- * =========================
506
- * Mount Cycle
507
- * =========================
508
- */
509
-
510
-
511
- willMount() {
512
- return Promise.resolve();
513
- }
514
-
515
- didMount() {
516
- return Promise.resolve();
517
- }
518
- /*
519
- * =========================
520
- * Unmount Cycle
521
- * =========================
522
- */
523
-
524
-
525
- willUnmount() {
526
- return Promise.resolve();
527
- }
528
-
529
- unmount() {
530
- return Promise.resolve();
531
- }
532
-
533
- didUnmount() {
534
- return Promise.resolve();
535
- }
536
- /*
537
- * =========================
538
- * Render Cycle
539
- * =========================
540
- */
541
-
542
- /**
543
- * Forces the component to be rendered again.
544
- *
545
- * @returns {string|Promise<string>} - The HTML to render on the component
546
- */
547
-
548
-
549
- forceRender() {
550
- return this._render();
551
- }
552
- /**
553
- * This function is the one that defines the HTML that will be rendered
554
- * inside the component. Since some content may need to be loaded before the
555
- * component is rendered, this function can also return a promise.
556
- *
557
- * @returns {string|Promise<string>} - The HTML to render on the component
558
- */
559
-
560
-
561
- render() {
562
- return '';
563
- }
564
-
565
- _render() {
566
- let render = this.render; // Check if a template has been set to this component, and if that's the
567
- // case, use that instead of the render function to render the component's
568
- // HTML code.
569
-
570
- if (this.static._template !== null) {
571
- render = this.template;
572
- } // Call the render function asynchronously and set the HTML from it to the
573
- // component.
574
-
575
-
576
- return (0, _Util.callAsync)(render, this).then(html => {
577
- const slot = this.dom.querySelector('slot');
578
- const currentContent = this.innerHTML;
579
-
580
- if (typeof html === 'string') {
581
- html = html.trim();
582
-
583
- if (html === '') {
584
- return;
585
- }
586
- }
587
-
588
- if (html === null || typeof html === 'undefined') {
589
- return;
590
- }
591
-
592
- if (slot !== null) {
593
- slot.replaceWith(html);
594
- } else {
595
- this.innerHTML = html;
596
- this.innerHTML += currentContent;
597
- }
598
- });
599
- }
600
-
601
- connectedCallback() {
602
- // Set the state as connected
603
- this._connected = true; // Add a data property with the tag of the component
604
-
605
- this.dataset.component = this.static.tag; // Check if a template for this component was set. The contents on this
606
- // if block will only be run once.
607
-
608
- if (typeof this.static._template === 'undefined') {
609
- // Check if there is an HTML template for this component
610
- const template = document.querySelector(`template#${this.static.tag}`);
611
-
612
- if (template !== null) {
613
- // If there is, set is as the template for the component
614
- this.template(template.innerHTML);
615
- } else {
616
- // If not, set is as null
617
- this.static._template = null;
618
- }
619
- } // Set the initial prop attributes for the component using the given
620
- // props
621
-
622
-
623
- this._setPropAttributes(); // Start the Mount Cycle
624
-
625
-
626
- return this.willMount().then(() => {
627
- return this._render().then(() => {
628
- return this.didMount().then(() => {
629
- this._isReady = true;
630
-
631
- for (const callback of this._ready) {
632
- callback.call(this);
633
- }
634
- });
635
- });
636
- });
637
- }
638
- /**
639
- * Adds a callback to be run once the component has been mounted successfully
640
- *
641
- * @param {function} callback - Callback to run once the component is ready
642
- */
643
-
644
-
645
- ready(callback) {
646
- this._ready.push(callback);
647
- }
648
-
649
- disconnectedCallback() {
650
- return this.willUnmount().then(() => {
651
- return this.unmount().then(() => {
652
- return this.didUnmount();
653
- });
654
- });
655
- }
656
-
657
- updateCallback(property, oldValue, newValue, origin = 'props', oldObject = {}, newObject = {}) {
658
- return this.willUpdate(origin, property, oldValue, newValue, oldObject, newObject).then(() => {
659
- return this.update(origin, property, oldValue, newValue, oldObject, newObject).then(() => {
660
- let promise;
661
-
662
- if (origin === 'state') {
663
- promise = this.onStateUpdate(property, oldValue, newValue, oldObject, newObject);
664
- } else {
665
- promise = this.onPropsUpdate(property, oldValue, newValue, oldObject, newObject);
666
- }
667
-
668
- return promise.then(() => {
669
- return this.didUpdate(origin, property, oldValue, newValue, oldObject, newObject);
670
- });
671
- });
672
- }).catch(e => {
673
- console.error(e); // Component should not update
674
- });
675
- }
676
-
677
- attributeChangedCallback(property, oldValue, newValue) {}
678
-
679
- }
680
-
681
- exports.Component = Component;
682
-
683
- _defineProperty(Component, "_tag", void 0);
684
-
685
- _defineProperty(Component, "_explicitPropTypes", ['boolean', 'string', 'number']);
686
-
687
- _defineProperty(Component, "_template", undefined);
688
- },{"./Util":"yzgE"}],"Lecv":[function(require,module,exports) {
689
- "use strict";
690
-
691
- Object.defineProperty(exports, "__esModule", {
692
- value: true
693
- });
694
- exports.ShadowComponent = void 0;
695
-
696
- var _Component = require("./Component");
697
-
698
- var _Util = require("./Util");
699
-
700
- class ShadowComponent extends _Component.Component {
701
- constructor(...props) {
702
- super(...props);
703
- this._shadowDOM = this.attachShadow({
704
- mode: 'open'
705
- });
706
- }
707
-
708
- _createStyleElement() {
709
- if (!(this._styleElement instanceof HTMLStyleElement)) {
710
- this._styleElement = document.createElement('style');
711
- this.dom.appendChild(this._styleElement);
712
- }
713
- }
714
-
715
- _render() {
716
- let render = this.render; // Check if a template has been set to this component, and if that's the
717
- // case, use that instead of the render function to render the component's
718
- // HTML code.
719
-
720
- if (this.static._template !== null) {
721
- render = this.template;
722
- } // Call the render function asynchronously and set the HTML from it to the
723
- // component.
724
-
725
-
726
- return (0, _Util.callAsync)(render, this).then(html => {
727
- this._shadowDOM.innerHTML = '';
728
-
729
- this._shadowDOM.appendChild(this._styleElement);
730
-
731
- this._shadowDOM.innerHTML += html;
732
- });
733
- }
734
-
735
- get dom() {
736
- return this._shadowDOM;
737
- }
738
-
739
- }
740
-
741
- exports.ShadowComponent = ShadowComponent;
742
- },{"./Component":"Simw","./Util":"yzgE"}],"Focm":[function(require,module,exports) {
743
- "use strict";
744
-
745
- Object.defineProperty(exports, "__esModule", {
746
- value: true
747
- });
748
-
749
- var _Component = require("./src/Component");
750
-
751
- Object.keys(_Component).forEach(function (key) {
752
- if (key === "default" || key === "__esModule") return;
753
- Object.defineProperty(exports, key, {
754
- enumerable: true,
755
- get: function () {
756
- return _Component[key];
757
- }
758
- });
759
- });
760
-
761
- var _ShadowComponent = require("./src/ShadowComponent");
762
-
763
- Object.keys(_ShadowComponent).forEach(function (key) {
764
- if (key === "default" || key === "__esModule") return;
765
- Object.defineProperty(exports, key, {
766
- enumerable: true,
767
- get: function () {
768
- return _ShadowComponent[key];
769
- }
770
- });
771
- });
772
- },{"./src/Component":"Simw","./src/ShadowComponent":"Lecv"}]},{},["Focm"], "Pandora")
773
- //# 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