sproutjs-core 2.0.1 → 2.5.0

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/sprout_core.js ADDED
@@ -0,0 +1,2575 @@
1
+ (function webpackUniversalModuleDefinition(root, factory) {
2
+ if(typeof exports === 'object' && typeof module === 'object')
3
+ module.exports = factory();
4
+ else if(typeof define === 'function' && define.amd)
5
+ define([], factory);
6
+ else if(typeof exports === 'object')
7
+ exports["sprout_core"] = factory();
8
+ else
9
+ root["sprout_core"] = factory();
10
+ })(self, () => {
11
+ return /******/ (() => { // webpackBootstrap
12
+ /******/ "use strict";
13
+ var __webpack_exports__ = {};
14
+ /*!****************************************!*\
15
+ !*** ./src/core/index.js + 16 modules ***!
16
+ \****************************************/
17
+
18
+ ;// ./src/core/consts.js
19
+
20
+ var BOOLEAN_ATTRIBUTES = ['hidden', 'checked'];
21
+ var SUPPORTED_ATTRIBUTES_FOR_BINDING = ['hidden', 'value', 'checked'];
22
+
23
+ // Some elements like inputs has certain properties that can be used in _bind command, like: 'value', or 'checked
24
+ var SUPPORTED_PROPERTIES_FOR_BINDING = ['value', 'checked'];
25
+ var SUPPORTED_INPUT_TYPES_FOR_VALUE_BINDING = [null,
26
+ // If no type is specified - defaults to 'text' -
27
+ // getAttribute('type') returns null
28
+ 'text', 'color', 'date', 'datetime-local', 'email', 'month', 'number', 'password', 'range', 'search', 'tel', 'time', 'url', 'week'];
29
+
30
+ // These are "built-in" state props that are automatically added to state objects,
31
+ // and should not be included in the normal state change/check flow
32
+ var BUILT_IN_STATE_PROPS = ['_global', '_gettingDependenciesFor', '_localStateManager', '_stateManager', '_binding', '_populate'];
33
+ var GLOBAL_STATE_VAR_NAME = "SproutGlobalState";
34
+ var GLOBAL_STATE_FUNCTION_NAME = "getGlobalState";
35
+ var ERROR_MESSAGES = {
36
+ NO_DEPENDENCIES_ARRAY_IN_SET_HOOK: function NO_DEPENDENCIES_ARRAY_IN_SET_HOOK(stateProp) {
37
+ return "State set hook, must include a dependencies array! None was found for ".concat(stateProp);
38
+ }
39
+ };
40
+ var HTML_ELEMENTS_CLASSES_MAP = [{
41
+ "class": HTMLAnchorElement,
42
+ element: "a"
43
+ }, {
44
+ "class": HTMLAreaElement,
45
+ element: "area"
46
+ }, {
47
+ "class": HTMLAudioElement,
48
+ element: "audio"
49
+ },
50
+ // { class: HTMLBaseElement, element: "base" },
51
+ {
52
+ "class": HTMLBodyElement,
53
+ element: "body"
54
+ }, {
55
+ "class": HTMLBRElement,
56
+ element: "br"
57
+ }, {
58
+ "class": HTMLButtonElement,
59
+ element: "button"
60
+ }, {
61
+ "class": HTMLCanvasElement,
62
+ element: "canvas"
63
+ }, {
64
+ "class": HTMLDataElement,
65
+ element: "data"
66
+ }, {
67
+ "class": HTMLDataListElement,
68
+ element: "datalist"
69
+ }, {
70
+ "class": HTMLDetailsElement,
71
+ element: "details"
72
+ }, {
73
+ "class": HTMLDialogElement,
74
+ element: "dialog"
75
+ }, {
76
+ "class": HTMLDivElement,
77
+ element: "div"
78
+ }, {
79
+ "class": HTMLDListElement,
80
+ element: "dl"
81
+ }, {
82
+ "class": HTMLEmbedElement,
83
+ element: "embed"
84
+ }, {
85
+ "class": HTMLFieldSetElement,
86
+ element: "fieldset"
87
+ }, {
88
+ "class": HTMLFormElement,
89
+ element: "form"
90
+ },
91
+ /*
92
+ { class: HTMLHeadingElement, element: "h1" },
93
+ { class: HTMLHeadingElement, element: "h2" },
94
+ { class: HTMLHeadingElement, element: "h3" },
95
+ { class: HTMLHeadingElement, element: "h4" },
96
+ { class: HTMLHeadingElement, element: "h5" },
97
+ { class: HTMLHeadingElement, element: "h6" },
98
+ */
99
+ {
100
+ "class": HTMLHRElement,
101
+ element: "hr"
102
+ }, {
103
+ "class": HTMLHtmlElement,
104
+ element: "html"
105
+ }, {
106
+ "class": HTMLIFrameElement,
107
+ element: "iframe"
108
+ }, {
109
+ "class": HTMLImageElement,
110
+ element: "img"
111
+ }, {
112
+ "class": HTMLInputElement,
113
+ element: "input"
114
+ }, {
115
+ "class": HTMLLabelElement,
116
+ element: "label"
117
+ }, {
118
+ "class": HTMLLegendElement,
119
+ element: "legend"
120
+ }, {
121
+ "class": HTMLLIElement,
122
+ element: "li"
123
+ }, {
124
+ "class": HTMLLinkElement,
125
+ element: "link"
126
+ }, {
127
+ "class": HTMLMapElement,
128
+ element: "map"
129
+ }, {
130
+ "class": HTMLMetaElement,
131
+ element: "meta"
132
+ }, {
133
+ "class": HTMLMeterElement,
134
+ element: "meter"
135
+ }, {
136
+ "class": HTMLObjectElement,
137
+ element: "object"
138
+ }, {
139
+ "class": HTMLOListElement,
140
+ element: "ol"
141
+ }, {
142
+ "class": HTMLOptGroupElement,
143
+ element: "optgroup"
144
+ }, {
145
+ "class": HTMLOptionElement,
146
+ element: "option"
147
+ },
148
+ // { class: HTMLOutputElement, element: "output" },
149
+ {
150
+ "class": HTMLParagraphElement,
151
+ element: "p"
152
+ },
153
+ // { class: HTMLParamElement, element: "param" },
154
+ {
155
+ "class": HTMLPictureElement,
156
+ element: "picture"
157
+ }, {
158
+ "class": HTMLPreElement,
159
+ element: "pre"
160
+ }, {
161
+ "class": HTMLProgressElement,
162
+ element: "progress"
163
+ }, {
164
+ "class": HTMLQuoteElement,
165
+ element: "blockquote"
166
+ }, {
167
+ "class": HTMLQuoteElement,
168
+ element: "q"
169
+ },
170
+ // { class: HTMLScriptElement, element: "script" },
171
+ {
172
+ "class": HTMLSelectElement,
173
+ element: "select"
174
+ }, {
175
+ "class": HTMLSourceElement,
176
+ element: "source"
177
+ }, {
178
+ "class": HTMLSpanElement,
179
+ element: "span"
180
+ },
181
+ // { class: HTMLStyleElement, element: "style" },
182
+ {
183
+ "class": HTMLTableElement,
184
+ element: "table"
185
+ }, {
186
+ "class": HTMLTableCellElement,
187
+ element: "td"
188
+ }, {
189
+ "class": HTMLTableCellElement,
190
+ element: "th"
191
+ }, {
192
+ "class": HTMLTableRowElement,
193
+ element: "tr"
194
+ }, {
195
+ "class": HTMLTableSectionElement,
196
+ element: "thead"
197
+ }, {
198
+ "class": HTMLTableSectionElement,
199
+ element: "tbody"
200
+ }, {
201
+ "class": HTMLTableSectionElement,
202
+ element: "tfoot"
203
+ }, {
204
+ "class": HTMLTextAreaElement,
205
+ element: "textarea"
206
+ }, {
207
+ "class": HTMLTimeElement,
208
+ element: "time"
209
+ }, {
210
+ "class": HTMLTitleElement,
211
+ element: "title"
212
+ }, {
213
+ "class": HTMLTrackElement,
214
+ element: "track"
215
+ }, {
216
+ "class": HTMLUListElement,
217
+ element: "ul"
218
+ }, {
219
+ "class": HTMLVideoElement,
220
+ element: "video"
221
+ }, {
222
+ "class": HTMLSlotElement,
223
+ element: "slot"
224
+ }
225
+ // We can't use HTMLElement more than once, so we will use a class extending it
226
+ // { class: class extends HTMLElement{}, element: "code" }
227
+ ];
228
+
229
+ // For development purposes only,
230
+ // turn this on to see exactly which functions in each entity are called and when.
231
+ var DEBUG_MODE = false;
232
+ var DEFAULT_TEMPLATE_DOM = document.createElement('div');
233
+ var NODES_STATE = {
234
+ // This is a global object that maps abstract "DOM actions" to nodes (the nodes can be elements, text nodes, attribute nodes)
235
+ // It is resolved to actual DOM API functions on RequestAnimationFrame calls, and then is RESET.
236
+ // it is a "singleton" object
237
+ nodeActionsMap: new Map(),
238
+ // Maps events binding functions to (custom) elements
239
+ eventBindingFunctions: new Map(),
240
+ conditionalRenders: new Map(),
241
+ // Save requestAnimationFrame Id, to cancel if the rAF wasn't called yet on the same frame, so DOM operations will be batched to a single frame,
242
+ // preventing several rAFs running for the same frame
243
+ paintRafId: null,
244
+ // Similar as above but for event bindings
245
+ eventBindRafId: null,
246
+ // Same for conditional renders
247
+ conditionalRenderRafId: null
248
+ };
249
+ var CONDITIONAL_OPERATORS = ['=', '==', '!=', '!==', '<', '<=', '>', '>='];
250
+ var MAX_OPERATIONS_PER_ANIMATION_FRAME = 100;
251
+ ;// ./src/core/DOM_utils.js
252
+ function isElementAList(element) {
253
+ return element.tagName === "OL" || element.tagName === "UL";
254
+ }
255
+ ;// ./src/core/paint_utils.js
256
+
257
+
258
+ var paintRafId = NODES_STATE.paintRafId,
259
+ eventBindingFunctions = NODES_STATE.eventBindingFunctions,
260
+ eventBindRafId = NODES_STATE.eventBindRafId,
261
+ conditionalRenderRafId = NODES_STATE.conditionalRenderRafId,
262
+ conditionalRenders = NODES_STATE.conditionalRenders,
263
+ nodeActionsMap = NODES_STATE.nodeActionsMap;
264
+ function queueBindEvents(element, bindFunction) {
265
+ eventBindingFunctions.set(element, bindFunction);
266
+ if (eventBindingFunctions.size > MAX_OPERATIONS_PER_ANIMATION_FRAME) return;
267
+ if (eventBindRafId) cancelAnimationFrame(eventBindRafId);
268
+ eventBindRafId = requestAnimationFrame(function () {
269
+ eventBindRafId = null;
270
+ eventBindingFunctions.forEach(function (bindFn) {
271
+ return bindFn();
272
+ });
273
+ eventBindingFunctions = new Map();
274
+ });
275
+ }
276
+ function queuePaint() {
277
+ if (nodeActionsMap.size > MAX_OPERATIONS_PER_ANIMATION_FRAME) return;
278
+ if (paintRafId) cancelAnimationFrame(paintRafId);
279
+ paintRafId = requestAnimationFrame(function () {
280
+ doUpdateDOM();
281
+ paintRafId = null;
282
+ });
283
+ }
284
+ function queueConditionalRender(element, renderFunction) {
285
+ conditionalRenders.set(element, renderFunction);
286
+ if (conditionalRenders.size > MAX_OPERATIONS_PER_ANIMATION_FRAME) return;
287
+ if (conditionalRenderRafId) cancelAnimationFrame(conditionalRenderRafId);
288
+ conditionalRenderRafId = requestAnimationFrame(function () {
289
+ conditionalRenderRafId = null;
290
+ conditionalRenders.forEach(function (renderFn) {
291
+ return renderFn();
292
+ });
293
+ conditionalRenders = new Map();
294
+ });
295
+ }
296
+ ;// ./src/core/node_actions.js
297
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
298
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
299
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
300
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
301
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
302
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
303
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
304
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
305
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
306
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
307
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
308
+
309
+
310
+
311
+
312
+
313
+ // Also, if doesn't exist - create it
314
+ function getNodeActionsForNode(node) {
315
+ var nodeActionsMap = NODES_STATE.nodeActionsMap;
316
+ if (!nodeActionsMap.has(node)) nodeActionsMap.set(node, getNewNodeActionsObject());
317
+ var nodeActions = nodeActionsMap.get(node);
318
+ return nodeActions;
319
+ }
320
+ function setStateNodeAction(node, nodeActionsObject, value) {
321
+ if (node.nodeType === Node.ATTRIBUTE_NODE) nodeActionsObject["setAttribute"] = value;else if (node.nodeType === Node.TEXT_NODE) nodeActionsObject["textContent"] = value;
322
+ }
323
+ function addRemoveAction(nodeActions, elementToRemove, stateIdentifier) {
324
+ if (!nodeActions.remove.has(stateIdentifier)) {
325
+ nodeActions.remove.set(stateIdentifier, new Set());
326
+ }
327
+ nodeActions.remove.get(stateIdentifier).add(elementToRemove);
328
+ }
329
+ function addReplaceAction(nodeActions, oldElement, newElement) {
330
+ nodeActions.replace.set(oldElement, newElement);
331
+ }
332
+ function addSwitchAction(nodeActions, newElement) {
333
+ nodeActions["switch"] = newElement;
334
+ }
335
+ // stateIdentifier can be a State object (for state maps),
336
+ // or a State property (for conditionally rendered elements)
337
+ function addAppendAction(nodeActions, nodeToAppend, stateIdentifier) {
338
+ if (!nodeActions.append.has(stateIdentifier)) {
339
+ nodeActions.append.set(stateIdentifier, new Set());
340
+ }
341
+ nodeActions.append.get(stateIdentifier).add(nodeToAppend);
342
+ }
343
+ function addStateAttributeToNode(attributeNode, value) {
344
+ var nodeActions = getNodeActionsForNode(attributeNode);
345
+ setStateNodeAction(attributeNode, nodeActions, value);
346
+ }
347
+ function addAppendActionToNode(node, nodeToAppend, stateIdentifier) {
348
+ var nodeActions = getNodeActionsForNode(node);
349
+ addAppendAction(nodeActions, nodeToAppend, stateIdentifier);
350
+ }
351
+
352
+ // This is an object used to represent pending node actions,
353
+ // that are batched and executed in reflows (requestAnimationFrame)
354
+ function getNewNodeActionsObject() {
355
+ return {
356
+ // Nodes to append to the end of node's children,
357
+ // keys are state objects, or state props (string)
358
+ // to prevent duplicate pending
359
+ append: new Map(),
360
+ // Replace each key node on Map, with value node
361
+ replace: new Map(),
362
+ // Insert value node after key node in parent node's children
363
+ after: new Map(),
364
+ // Remove these nodes from the DOM
365
+ // keys are state objects, or state props (string)
366
+ // to prevent duplicate pending
367
+ remove: new Map(),
368
+ "switch": null,
369
+ get hasPendingActions() {
370
+ return this["switch"] !== null || this.append.size || this.replace.size || this.after.size || this.remove.size;
371
+ }
372
+ };
373
+ }
374
+
375
+ // This *updates*/*"fills"* the nodeActionsMap!
376
+ function generateStateNodeActions(stateManager, stateProp) {
377
+ var _this = this;
378
+ var nodeActionsMap = NODES_STATE.nodeActionsMap;
379
+ var value = stateManager.state[stateProp];
380
+ var stateNodes = stateManager.stateNodes[stateProp];
381
+ // This is a map, where keys are "parent elements" containing
382
+ // custom element instanced created from a state array ("state map").
383
+ // The values are the custom element name.
384
+ // The actual array of state objects is in state[stateProp]
385
+ var stateMapElements = stateManager.stateArrayMaps[stateProp];
386
+ var conditionallyRenderingElements = stateManager.conditionallyRenderingElements[stateProp];
387
+
388
+ // Note, since the value change is handled by a custom setter - that setter checks if the set value is the same -
389
+ // if it is - it won't call handleStateChange, and it won't reach here.
390
+ if (stateNodes) {
391
+ stateNodes.forEach(function (node) {
392
+ if (!nodeActionsMap.has(node)) nodeActionsMap.set(node, {});
393
+ var nodeActionsObject = nodeActionsMap.get(node);
394
+ setStateNodeAction(node, nodeActionsObject, value);
395
+ });
396
+ }
397
+ if (stateMapElements) {
398
+ // An array of state objects
399
+ var stateMapArray = value;
400
+ console.log("Has ".concat(stateMapElements.size, " stateMapElements"));
401
+ stateMapElements.forEach(function (customElementName, parentElement) {
402
+ //const newMappedElement = parentElement.cloneNode(true);
403
+ var stateMapNodeActions = getNewNodeActionsObject();
404
+ var currentStateMapArrayIndex = -1;
405
+ var isParentAList = isElementAList(parentElement);
406
+ // Compares state map arrays to actual DOM elements (by comparing state objects)
407
+ if (parentElement.children.length) {
408
+ Array.prototype.forEach.call(parentElement.children, function (childElement, currentIndex) {
409
+ var _stateItem;
410
+ var customElement = childElement;
411
+ // State map elements inside Lists are wrapped with a <li>
412
+ if (isParentAList) customElement = childElement.firstElementChild;
413
+ var stateItem = stateMapArray[currentIndex];
414
+ if ((_stateItem = stateItem) !== null && _stateItem !== void 0 && _stateItem.hasOwnProperty('state')) stateItem = stateItem.state;
415
+ if (!stateItem) {
416
+ addRemoveAction(stateMapNodeActions, childElement);
417
+ // newMappedElement.removeChild(newMappedElement.children[currentIndex]);
418
+ } else if (customElement.state !== stateItem) {
419
+ var replaceWithChild = stateToElement(stateItem, customElementName, isElementAList(parentElement) ? "li" : undefined);
420
+ // newMappedElement.replaceChild(replaceWithChild, newMappedElement.children[currentIndex]);
421
+ addReplaceAction(stateMapNodeActions, childElement, replaceWithChild);
422
+ }
423
+ currentStateMapArrayIndex = currentIndex;
424
+ });
425
+ }
426
+
427
+ // If there are more state objects in the stateMapArray - append equivalent child elements
428
+ currentStateMapArrayIndex++;
429
+ for (var i = currentStateMapArrayIndex, len = stateMapArray.length; i < len; i++) {
430
+ var stateItem = stateMapArray[i];
431
+ // New state item === new child element to append
432
+ if (stateItem) {
433
+ var newChild = stateToElement(stateItem, customElementName, isElementAList(parentElement) ? "li" : undefined);
434
+ // newMappedElement.appendChild(newChild);
435
+ addAppendAction(stateMapNodeActions, newChild, stateItem);
436
+ }
437
+ }
438
+
439
+ // addSwitchAction(stateMapNodeActions, newMappedElement);
440
+ if (stateMapNodeActions.hasPendingActions) {
441
+ nodeActionsMap.set(parentElement, stateMapNodeActions);
442
+ }
443
+ });
444
+ }
445
+ if (conditionallyRenderingElements) {
446
+ // Should be slot element
447
+ conditionallyRenderingElements.forEach(function (element) {
448
+ queueConditionalRender(_this, function () {
449
+ return element.render();
450
+ });
451
+ });
452
+ }
453
+ if (nodeActionsMap.size) queuePaint();
454
+ }
455
+ function resolveNodeActionsMapToDOMActions() {
456
+ var batchActions = [];
457
+ var attributeActions = [];
458
+ var elementActions = [];
459
+ var nodeActionsMap = NODES_STATE.nodeActionsMap;
460
+ nodeActionsMap.forEach(function (nodeActions, node) {
461
+ // Attribute change
462
+ if (nodeActions.hasOwnProperty("setAttribute")) {
463
+ var value = nodeActions.setAttribute;
464
+ if (typeof value === "boolean") {
465
+ if (!node.hasOwnProperty("originalOwnerElement")) {
466
+ console.error("originalOwnerElement not found on boolean attribute node! Should never happen!");
467
+ }
468
+ if (value === false) {
469
+ // Remove attribute if it exists, otherwise - do nothing
470
+ if (node.originalOwnerElement.hasAttribute(node.name)) {
471
+ attributeActions.push(function () {
472
+ node.originalOwnerElement.removeAttributeNode(node);
473
+ });
474
+ }
475
+ }
476
+ // state changed to true
477
+ else {
478
+ if (!node.originalOwnerElement.hasAttribute(node.name)) {
479
+ attributeActions.push(function () {
480
+ node.originalOwnerElement.setAttributeNode(node);
481
+ });
482
+ }
483
+ }
484
+ } else {
485
+ if (typeof value === "string" && node.nodeValue !== value) {
486
+ attributeActions.push(function () {
487
+ return node.nodeValue = value;
488
+ });
489
+ }
490
+ }
491
+ }
492
+
493
+ // Text change
494
+ else if (nodeActions.hasOwnProperty("textContent")) {
495
+ var _value = String(nodeActions.textContent);
496
+ if (node.nodeValue === _value) return;
497
+ elementActions.push(function () {
498
+ return node.nodeValue = _value;
499
+ });
500
+ }
501
+
502
+ // DOM change
503
+ else if (nodeActions["switch"]) {
504
+ elementActions.push(function () {
505
+ return node.replaceWith(nodeActions["switch"]);
506
+ });
507
+ } else {
508
+ nodeActions.replace.forEach(function (newNode, oldNode) {
509
+ elementActions.push(function () {
510
+ return (
511
+ //oldNode.replaceWith(newNode));
512
+ node.replaceChild(newNode, oldNode)
513
+ );
514
+ });
515
+ });
516
+ var _iterator = _createForOfIteratorHelper(nodeActions.remove.values()),
517
+ _step;
518
+ try {
519
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
520
+ var removes = _step.value;
521
+ var _iterator3 = _createForOfIteratorHelper(removes),
522
+ _step3;
523
+ try {
524
+ var _loop = function _loop() {
525
+ var nodeToRemove = _step3.value;
526
+ if (nodeToRemove.parentNode && nodeToRemove.parentNode === node) {
527
+ elementActions.push(function () {
528
+ return node.removeChild(nodeToRemove);
529
+ });
530
+ }
531
+ };
532
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
533
+ _loop();
534
+ }
535
+ } catch (err) {
536
+ _iterator3.e(err);
537
+ } finally {
538
+ _iterator3.f();
539
+ }
540
+ }
541
+ } catch (err) {
542
+ _iterator.e(err);
543
+ } finally {
544
+ _iterator.f();
545
+ }
546
+ var _iterator2 = _createForOfIteratorHelper(nodeActions.append.values()),
547
+ _step2;
548
+ try {
549
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
550
+ var appends = _step2.value;
551
+ var _iterator4 = _createForOfIteratorHelper(appends),
552
+ _step4;
553
+ try {
554
+ var _loop2 = function _loop2() {
555
+ var newChildElement = _step4.value;
556
+ elementActions.push(function () {
557
+ return node.appendChild(newChildElement);
558
+ });
559
+ };
560
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
561
+ _loop2();
562
+ }
563
+ } catch (err) {
564
+ _iterator4.e(err);
565
+ } finally {
566
+ _iterator4.f();
567
+ }
568
+ }
569
+ } catch (err) {
570
+ _iterator2.e(err);
571
+ } finally {
572
+ _iterator2.f();
573
+ }
574
+ }
575
+ });
576
+ return [].concat(attributeActions, elementActions);
577
+ }
578
+
579
+ // For debugging purposes
580
+ function logNodeActions() {
581
+ var nodeActionsMap = NODES_STATE.nodeActionsMap;
582
+ _toConsumableArray(nodeActionsMap.entries()).map(function (_ref) {
583
+ var _ref2 = _slicedToArray(_ref, 2),
584
+ node = _ref2[0],
585
+ actions = _ref2[1];
586
+ switch (node.nodeType) {
587
+ case Node.ELEMENT_NODE:
588
+ {
589
+ console.log("Actions for", node);
590
+ var appendElements = _toConsumableArray(actions.append.values());
591
+ if (appendElements.length) {
592
+ console.log("Append", appendElements);
593
+ }
594
+ var replaceElements = _toConsumableArray(actions.replace.entries());
595
+ if (replaceElements.length) {
596
+ console.log("Append", replaceElements);
597
+ }
598
+ if (actions.remove.size) {
599
+ console.log("Remove", actions.remove);
600
+ }
601
+ break;
602
+ }
603
+ case Node.ATTRIBUTE_NODE:
604
+ {
605
+ console.log("Set Attribute", node.nodeName, "on", node.originalOwnerElement, "to", actions.setAttribute);
606
+ break;
607
+ }
608
+ case Node.TEXT_NODE:
609
+ {
610
+ console.log("Set text content for", node.parentNode, "to", actions.textContent);
611
+ break;
612
+ }
613
+ }
614
+ });
615
+ }
616
+ // This function runs on requestAnimationFrame to run pending Node actions
617
+ function doUpdateDOM() {
618
+ var nodeActionsMap = NODES_STATE.nodeActionsMap;
619
+ if (nodeActionsMap.size) {
620
+ // logNodeActions();
621
+ var DOMActions = resolveNodeActionsMapToDOMActions(nodeActionsMap);
622
+ DOMActions.forEach(function (DOMAction) {
623
+ return DOMAction();
624
+ });
625
+ NODES_STATE.nodeActionsMap = new Map();
626
+ }
627
+ }
628
+ ;// ./src/core/prop_utils.js
629
+ // Sets an internal read-only "hidden" property on an object:
630
+ function setHiddenProperty(obj, propName, propValue) {
631
+ var enumerable = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
632
+ Object.defineProperty(obj, propName, {
633
+ value: propValue,
634
+ configurable: false,
635
+ writable: false,
636
+ enumerable: enumerable
637
+ });
638
+ }
639
+ ;// ./src/core/state_utils.js
640
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
641
+ function state_utils_slicedToArray(r, e) { return state_utils_arrayWithHoles(r) || state_utils_iterableToArrayLimit(r, e) || state_utils_unsupportedIterableToArray(r, e) || state_utils_nonIterableRest(); }
642
+ function state_utils_nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
643
+ function state_utils_unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return state_utils_arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? state_utils_arrayLikeToArray(r, a) : void 0; } }
644
+ function state_utils_arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
645
+ function state_utils_iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
646
+ function state_utils_arrayWithHoles(r) { if (Array.isArray(r)) return r; }
647
+
648
+
649
+
650
+ var handleStatesRAFId = null;
651
+ if (typeof HTMLElement === 'undefined') {
652
+ console.warn("HTMLElement was not found! This probably means you are running in a non-browser environment, and can lead to unexpected results");
653
+ } else {
654
+ // Make sure "setAttribute" is not overridable
655
+ Object.defineProperty(globalThis, "elementSetAttribute", {
656
+ value: HTMLElement.prototype.setAttribute,
657
+ writable: false,
658
+ configurable: false
659
+ });
660
+ }
661
+ var setAttribute = function setAttribute(attrName, attrValue) {
662
+ if (BOOLEAN_ATTRIBUTES.includes(attrName)) {
663
+ if (attrValue === "false") {
664
+ this.removeAttribute(attrName);
665
+ } else {
666
+ elementSetAttribute.call(this, attrName, "");
667
+ }
668
+ } else {
669
+ elementSetAttribute.call(this, attrName, attrValue);
670
+ }
671
+ };
672
+
673
+ // This creates the binding to state props on "State attributes".
674
+ // This function is called when a custom element instance ic connected to the DOM
675
+ var setStateAttribute = function setStateAttribute(attrName, stateProp) {
676
+ var equalityValue = null;
677
+ if (stateProp.indexOf(':') !== -1) {
678
+ if (stateProp.indexOf('is_') === 0) {
679
+ var colonIndex = stateProp.indexOf(':');
680
+ if (colonIndex === -1) {
681
+ throw Error("When using conditional equality state attribute, you must include a colon character followed by an equality value!");
682
+ }
683
+ equalityValue = stateProp.substring(colonIndex + 1);
684
+ stateProp = stateProp.substring(3, colonIndex);
685
+ }
686
+ }
687
+ var _this$getState = this.getState(stateProp, true),
688
+ _this$getState2 = state_utils_slicedToArray(_this$getState, 2),
689
+ stateVal = _this$getState2[0],
690
+ theState = _this$getState2[1];
691
+ if (stateVal === undefined) {
692
+ console.warn("State value for ".concat(stateProp, " is undefined. State values should never be undefined."));
693
+ return;
694
+ }
695
+ if (!theState) {
696
+ console.warn("No State object with state prop: " + stateProp);
697
+ return;
698
+ }
699
+ if (equalityValue) {
700
+ var conditionalStateProp = "is_" + stateProp + equalityValue;
701
+ var originalStateProp = stateProp;
702
+ Object.defineProperty(theState, conditionalStateProp, {
703
+ get: function get() {
704
+ return this[originalStateProp] === equalityValue;
705
+ },
706
+ enumerable: false
707
+ });
708
+ theState._stateManager.addStateDependency(stateProp, conditionalStateProp);
709
+ stateVal = theState[conditionalStateProp];
710
+ stateProp = conditionalStateProp;
711
+ }
712
+ var valueToSet = stateVal;
713
+ this.removeAttribute(attrName);
714
+ // Create an "Attribute Node"
715
+ var stateAttrNode = document.createAttribute(attrName);
716
+ stateAttrNode.nodeValue = valueToSet;
717
+ // Saves a readonly boolean that marks this as a "state attribute node"
718
+ setHiddenProperty(stateAttrNode, "isStateAttribute", true);
719
+ // Save ownerElement to a different property,
720
+ // so if the attribute is removed (in case of a boolean attribute),
721
+ // and later re-attached, we would know which element to add it back to.
722
+ setHiddenProperty(stateAttrNode, "originalOwnerElement", this);
723
+ /*
724
+ Object.defineProperty(stateAttrNode, "stateValue", {
725
+ value: valueToSet,
726
+ writeable: true,
727
+ configurable: false,
728
+ enumerable: true
729
+ });
730
+ */
731
+ if (typeof valueToSet === "boolean") {
732
+ // A boolean attribute value should ALWAYS be an empty string,
733
+ // the value itself never changes, it is removed fron the element if false,
734
+ // and added if true
735
+ stateAttrNode.nodeValue = "";
736
+ }
737
+
738
+ // Adds the attribute to the element
739
+ if (valueToSet !== false) {
740
+ this.setAttributeNode(stateAttrNode);
741
+ }
742
+ theState._stateManager.addStateNode(stateProp, stateAttrNode, typeof valueToSet === "boolean");
743
+ };
744
+ var setStateText = function setStateText(stateProp) {
745
+ var _this$getState3 = this.getState(stateProp, true),
746
+ _this$getState4 = state_utils_slicedToArray(_this$getState3, 2),
747
+ stateVal = _this$getState4[0],
748
+ theState = _this$getState4[1];
749
+ if (stateVal === undefined || stateVal === null) {
750
+ console.warn("State value for ".concat(stateProp, " is undefined or null for _text command"));
751
+ return;
752
+ }
753
+ if (!theState) {
754
+ console.warn("No State object with state prop: " + stateProp);
755
+ return;
756
+ }
757
+ var valueToSet = stateVal;
758
+ var textNode = document.createTextNode(valueToSet);
759
+ setHiddenProperty(textNode, "isStateAttribute", true);
760
+ this.appendChild(textNode);
761
+ theState._stateManager.addStateNode(stateProp, textNode);
762
+ };
763
+
764
+ // Convert a stateObject to a custom element, used in State Map Arrays
765
+ function stateToElement(stateObject, elemName, wrapInElement) {
766
+ var customElementInstance = document.createElement(elemName);
767
+ customElementInstance.setInitialState(stateObject);
768
+ var returnElement;
769
+ if (wrapInElement) {
770
+ returnElement = document.createElement(wrapInElement);
771
+ returnElement.appendChild(customElementInstance);
772
+ } else {
773
+ returnElement = customElementInstance;
774
+ }
775
+ return returnElement;
776
+ }
777
+ function mapStateArrayToElements(stateItems, elemName, wrapInElement) {
778
+ // Each state item should be a stateManager
779
+ return stateItems.map(function (stateItem) {
780
+ if (stateItem.hasOwnProperty('state')) stateItem = stateItem.state;
781
+ if (_typeof(stateItem) !== 'object') {
782
+ console.warn("item in State array for _map is not an object: ", stateItem);
783
+ return {};
784
+ }
785
+ return stateToElement(stateItem, elemName, wrapInElement);
786
+ });
787
+ }
788
+
789
+ // Main function that handles all state changes in a state object
790
+ function handleStateChange(stateManager, stateProp) {
791
+ console.log("handleStateChange:", stateProp);
792
+ if (BUILT_IN_STATE_PROPS.includes(stateProp)) return;
793
+ // Populate the next Node Actions to perform
794
+ generateStateNodeActions(stateManager, stateProp);
795
+ var state = stateManager.state;
796
+ // Run on[stateProp]Change hooks
797
+ if (state.hasOwnProperty("on_".concat(stateProp, "Change"))) {
798
+ if (typeof state["on_".concat(stateProp, "Change")] === "function") state["on_".concat(stateProp, "Change")].call(state);
799
+ }
800
+ var stateDependencies = stateManager.stateDependencies[stateProp];
801
+ if (stateDependencies) {
802
+ stateDependencies.forEach(function (depStateProp) {
803
+ // A "Setter" hook
804
+ if (depStateProp.indexOf('set_') === 0) {
805
+ var setStateProp = depStateProp.substring(4);
806
+ var func = state[depStateProp][0];
807
+ if (func && typeof func === "function") {
808
+ state[setStateProp] = func.call(state);
809
+ return;
810
+ }
811
+ }
812
+ generateStateNodeActions(stateManager, depStateProp);
813
+ if (state.hasOwnProperty("on".concat(depStateProp, "Change"))) {
814
+ if (typeof state["on".concat(depStateProp, "Change")] === "function") state["on".concat(depStateProp, "Change")].call(state);
815
+ }
816
+ });
817
+ }
818
+
819
+ // Global state
820
+ if (!state._global) {
821
+ var globalStateDependencies = stateManager.globalStateDependencies[stateProp];
822
+ globalStateDependencies === null || globalStateDependencies === void 0 || globalStateDependencies.forEach(function (depStateProps, depStateManager) {
823
+ var depState = depStateManager.state;
824
+ depStateProps.forEach(function (depStateProp) {
825
+ // A "Setter" hook
826
+ if (depStateProp.indexOf('set_') === 0) {
827
+ var setStateProp = depStateProp.substring(4);
828
+ var func = state[depStateProp][0];
829
+ if (func && typeof func === "function") {
830
+ depState[setStateProp] = func.call(depState);
831
+ return;
832
+ }
833
+ }
834
+ generateStateNodeActions(depStateManager, depStateProp);
835
+ if (state.hasOwnProperty("on".concat(depStateProp, "Change"))) {
836
+ if (typeof state["on".concat(depStateProp, "Change")] === "function") depState["on".concat(depStateProp, "Change")].call(depState);
837
+ }
838
+ });
839
+ });
840
+ }
841
+ }
842
+ function populateStateFromInitialState(state, initialState) {
843
+ state._populate = true;
844
+ var descriptors = Object.getOwnPropertyDescriptors(initialState);
845
+ var descrp;
846
+ for (var key in descriptors) {
847
+ if (BUILT_IN_STATE_PROPS.includes(key)) {
848
+ delete descriptors[key];
849
+ continue;
850
+ }
851
+ descrp = descriptors[key];
852
+ if (descrp.hasOwnProperty('get') && typeof descrp.get === "function") {
853
+ descrp.get.bind(state);
854
+ }
855
+ if (descrp.hasOwnProperty('value')) {
856
+ var value = descrp.value;
857
+ if (typeof value === "function") {
858
+ descrp.value.bind(state);
859
+ } else if (Array.isArray(value) && key.indexOf("set_") === 0) {
860
+ var func = value === null || value === void 0 ? void 0 : value[0];
861
+ if (func && typeof func === "function") {
862
+ func.bind(state);
863
+ }
864
+ }
865
+ }
866
+ }
867
+
868
+ // If state set hooks should run on initialization -
869
+ // they should run by the proxy handler for "defineProperty"
870
+ Object.defineProperties(state, descriptors);
871
+ delete state._populate;
872
+ }
873
+
874
+ /* Experimental rendering of state maps using DocumentFragment. Not stable */
875
+ /*
876
+ export function resolveStateMapToDocumentFragment({ customElementName, parentElement}, stateMapArray) {
877
+ const resolvedDocumentFragment = new DocumentFragment();
878
+ // const stateMapNodeActions = getNewNodeActionsObject();
879
+ let currentStateMapArrayIndex = -1;
880
+ const isParentAList = isElementAList(parentElement);
881
+ // Compares state map arrays to actual DOM elements (by comparing state objects)
882
+ if (parentElement.children.length) {
883
+ Array.prototype.forEach.call(parentElement.children, (childElement, currentIndex)=> {
884
+ let customElementChild = childElement;
885
+ // State map elements inside Lists are wrapped with a <li>
886
+ if (isParentAList) customElementChild = childElement.firstElementChild;
887
+ let stateItem = stateMapArray[currentIndex];
888
+ if (stateItem?.hasOwnProperty('state')) stateItem = stateItem.state;
889
+ if (stateItem && customElementChild.state !== stateItem) {
890
+ const newCustomElementChild = stateToElement(stateItem, customElementName, isElementAList(parentElement) ? "li" : undefined);
891
+ resolvedDocumentFragment.appendChild(newCustomElementChild);
892
+ }
893
+ else {
894
+ resolvedDocumentFragment.append(childElement)
895
+ }
896
+ currentStateMapArrayIndex = currentIndex;
897
+ });
898
+ }
899
+
900
+ // If there are more state objects in the stateMapArray - append equivalent child elements
901
+ currentStateMapArrayIndex++;
902
+ for (let i = currentStateMapArrayIndex, len=stateMapArray.length; i<len; i++) {
903
+ const stateItem = stateMapArray[i];
904
+ // New state item === new child element to append
905
+ if (stateItem) {
906
+ // Make sure we don't already have a pending append action for the same state object
907
+ const newChild = stateToElement(stateItem, customElementName, isElementAList(parentElement) ? "li" : undefined);
908
+ resolvedDocumentFragment.appendChild(newChild);
909
+ }
910
+ }
911
+
912
+ return resolvedDocumentFragment;
913
+ if (resolvedDocumentFragment.children.length) {
914
+ parentElement.innerHTML = '';
915
+ //addReplaceAction(stateMapNodeActions, childElement, replaceWithChild);
916
+ //nodeActionsMap.set(parentElement, stateMapNodeActions);
917
+ }
918
+ }
919
+ */
920
+ ;// ./src/core/commands.js
921
+ function commands_toConsumableArray(r) { return commands_arrayWithoutHoles(r) || commands_iterableToArray(r) || commands_unsupportedIterableToArray(r) || commands_nonIterableSpread(); }
922
+ function commands_nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
923
+ function commands_iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
924
+ function commands_arrayWithoutHoles(r) { if (Array.isArray(r)) return commands_arrayLikeToArray(r); }
925
+ function commands_slicedToArray(r, e) { return commands_arrayWithHoles(r) || commands_iterableToArrayLimit(r, e) || commands_unsupportedIterableToArray(r, e) || commands_nonIterableRest(); }
926
+ function commands_nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
927
+ function commands_unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return commands_arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? commands_arrayLikeToArray(r, a) : void 0; } }
928
+ function commands_arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
929
+ function commands_iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
930
+ function commands_arrayWithHoles(r) { if (Array.isArray(r)) return r; }
931
+
932
+
933
+
934
+
935
+
936
+ function mapStateToElements(stateItemsPropertyName, customElementName, parentElement) {
937
+ var _parentElement$getSta = parentElement.getState(stateItemsPropertyName, true),
938
+ _parentElement$getSta2 = commands_slicedToArray(_parentElement$getSta, 2),
939
+ stateItemsArray = _parentElement$getSta2[0],
940
+ theState = _parentElement$getSta2[1];
941
+ if (!stateItemsArray || !Array.isArray(stateItemsArray)) {
942
+ console.warn("state value for _map is not an array, in state property: " + stateItemsPropertyName);
943
+ return null;
944
+ }
945
+ var wrapInElement = isElementAList(parentElement) ? "li" : undefined;
946
+ var elements = mapStateArrayToElements(stateItemsArray, customElementName, wrapInElement);
947
+ parentElement.innerHTML = "";
948
+ if (elements.length) {
949
+ parentElement.append.apply(parentElement, commands_toConsumableArray(elements));
950
+ }
951
+ return theState;
952
+ }
953
+
954
+ // Functions that run and handles "Command" attributes. Note, they should always be called
955
+ // with the "this" context set to the custom element the command is defined on
956
+ var COMMANDS = {
957
+ map: function map(commandValue) {
958
+ // The command value ("argument") is "<stateProp>:<custom element name>"
959
+ var _commandValue$split = commandValue.split(':'),
960
+ _commandValue$split2 = commands_slicedToArray(_commandValue$split, 2),
961
+ stateItemsPropertyName = _commandValue$split2[0],
962
+ customElementName = _commandValue$split2[1];
963
+ var thiselement = this;
964
+ var theState = mapStateToElements(stateItemsPropertyName, customElementName, thiselement);
965
+ if (!theState) {
966
+ console.warn("Mapping ".concat(stateItemsPropertyName, " to ").concat(customElementName, " failed!"));
967
+ return;
968
+ }
969
+ theState._stateManager.addStateMap(stateItemsPropertyName, customElementName, thiselement);
970
+ },
971
+ text: function text(commandValue) {
972
+ var stateProp = commandValue;
973
+ this.initialSetText(stateProp);
974
+ // DO NOT CALL .normalize()! It might change the Text Nodes!
975
+ },
976
+ bind: function bind(commandValue) {
977
+ var _this = this;
978
+ var _commandValue$split3 = commandValue.split(':'),
979
+ _commandValue$split4 = commands_slicedToArray(_commandValue$split3, 2),
980
+ attributeName = _commandValue$split4[0],
981
+ statePropName = _commandValue$split4[1];
982
+ if (!attributeName || !statePropName) {
983
+ console.warn("Incorrect usage of _bind command! Please pass <attribute-name>:<state-prop-name>");
984
+ return;
985
+ }
986
+ if (!attributeName in SUPPORTED_ATTRIBUTES_FOR_BINDING) {
987
+ console.warn("Attribute ".concat(attributeName, " is not supported for _bind command!"));
988
+ return;
989
+ }
990
+ this.bindAttributeToState(attributeName, statePropName);
991
+ if (SUPPORTED_PROPERTIES_FOR_BINDING.includes(attributeName)) {
992
+ if (attributeName === "value" && this.tagName === "INPUT" && SUPPORTED_INPUT_TYPES_FOR_VALUE_BINDING.includes(this.getAttribute('type'))) {
993
+ this.addEventListener("input", function () {
994
+ return _this.updateStateFromProperty("value");
995
+ });
996
+ } else if (attributeName === "checked" && this.tagName === "INPUT" && this.getAttribute('type') === "checkbox") {
997
+ this.addEventListener("change", function () {
998
+ return _this.updateStateFromProperty("checked");
999
+ });
1000
+ }
1001
+ }
1002
+ }
1003
+ };
1004
+ ;// ./src/core/ReactiveElement.js
1005
+ function ReactiveElement_typeof(o) { "@babel/helpers - typeof"; return ReactiveElement_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, ReactiveElement_typeof(o); }
1006
+ function ReactiveElement_createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = ReactiveElement_unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
1007
+ function ReactiveElement_slicedToArray(r, e) { return ReactiveElement_arrayWithHoles(r) || ReactiveElement_iterableToArrayLimit(r, e) || ReactiveElement_unsupportedIterableToArray(r, e) || ReactiveElement_nonIterableRest(); }
1008
+ function ReactiveElement_nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
1009
+ function ReactiveElement_unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return ReactiveElement_arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? ReactiveElement_arrayLikeToArray(r, a) : void 0; } }
1010
+ function ReactiveElement_arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
1011
+ function ReactiveElement_iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
1012
+ function ReactiveElement_arrayWithHoles(r) { if (Array.isArray(r)) return r; }
1013
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
1014
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
1015
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
1016
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
1017
+ function _possibleConstructorReturn(t, e) { if (e && ("object" == ReactiveElement_typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
1018
+ function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
1019
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
1020
+ function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
1021
+ function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
1022
+ function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
1023
+ function _classPrivateMethodInitSpec(e, a) { _checkPrivateRedeclaration(e, a), a.add(e); }
1024
+ function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
1025
+ function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
1026
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
1027
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == ReactiveElement_typeof(i) ? i : i + ""; }
1028
+ function _toPrimitive(t, r) { if ("object" != ReactiveElement_typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != ReactiveElement_typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
1029
+ function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
1030
+ function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
1031
+ function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
1032
+
1033
+
1034
+
1035
+ function extendElementClassWithReactiveElementClass(elementClass) {
1036
+ var appScope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : window;
1037
+ var _changeEventHandler = /*#__PURE__*/new WeakMap();
1038
+ var _wasMounted = /*#__PURE__*/new WeakMap();
1039
+ var _boundAttributesToState = /*#__PURE__*/new WeakMap();
1040
+ var _ReactiveElement_brand = /*#__PURE__*/new WeakSet();
1041
+ var ReactiveElement = /*#__PURE__*/function (_elementClass) {
1042
+ function ReactiveElement() {
1043
+ var _this;
1044
+ _classCallCheck(this, ReactiveElement);
1045
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1046
+ args[_key] = arguments[_key];
1047
+ }
1048
+ _this = _callSuper(this, ReactiveElement, [].concat(args));
1049
+ _classPrivateMethodInitSpec(_this, _ReactiveElement_brand);
1050
+ // Should contain the "root" DOM element containing this element
1051
+ _defineProperty(_this, "host", null);
1052
+ // For input elements - to force bubble-up of change events
1053
+ _classPrivateFieldInitSpec(_this, _changeEventHandler, void 0);
1054
+ _classPrivateFieldInitSpec(_this, _wasMounted, false);
1055
+ // Used for the _bind command, which allows "reverse-binding" attribute values to state props,
1056
+ // keys are attribute names, values are state prop names
1057
+ _classPrivateFieldInitSpec(_this, _boundAttributesToState, {});
1058
+ return _this;
1059
+ }
1060
+ _inherits(ReactiveElement, _elementClass);
1061
+ return _createClass(ReactiveElement, [{
1062
+ key: "bindAttributeToState",
1063
+ value: function bindAttributeToState(attrName, statePropName) {
1064
+ _classPrivateFieldGet(_boundAttributesToState, this)[attrName] = statePropName;
1065
+ }
1066
+ }, {
1067
+ key: "unbindAttributeToState",
1068
+ value: function unbindAttributeToState(attrName) {
1069
+ delete _classPrivateFieldGet(_boundAttributesToState, this)[attrName];
1070
+ }
1071
+
1072
+ // For input elements
1073
+ }, {
1074
+ key: "updateStateFromProperty",
1075
+ value: function updateStateFromProperty(propertyName) {
1076
+ var newValue = this[propertyName];
1077
+ var stateProp = _classPrivateFieldGet(_boundAttributesToState, this)[propertyName];
1078
+ var _this$getState = this.getState(stateProp, true),
1079
+ _this$getState2 = ReactiveElement_slicedToArray(_this$getState, 2),
1080
+ stateValue = _this$getState2[0],
1081
+ theState = _this$getState2[1];
1082
+ if (stateValue !== newValue) theState[stateProp] = newValue;
1083
+ }
1084
+ }, {
1085
+ key: "disconnectedCallback",
1086
+ value: function disconnectedCallback() {
1087
+ var _this$host;
1088
+ if (_classPrivateFieldGet(_changeEventHandler, this)) this.removeEventListener('change', _classPrivateFieldGet(_changeEventHandler, this));
1089
+ var host = (_this$host = this.host) !== null && _this$host !== void 0 ? _this$host : this;
1090
+ if (host.ref) {
1091
+ var thisRefName = this.getAttribute('ref');
1092
+ if (thisRefName) {
1093
+ delete host.ref[thisRefName];
1094
+ delete host.events[thisRefName];
1095
+ }
1096
+ }
1097
+ _classPrivateFieldSet(_boundAttributesToState, this, {});
1098
+ }
1099
+ }, {
1100
+ key: "connectedCallback",
1101
+ value: function connectedCallback() {
1102
+ var _this2 = this;
1103
+ if (_classPrivateFieldGet(_wasMounted, this)) return;
1104
+ // IMPORTANT: THIS *CAN* be NULL, DO NOT CHANGE IT!
1105
+ // It is part of the way a check is made to see if an element is part of ShadowDOM!
1106
+ // host will be null if the element is part of the DOM === the "root" custom element will have null in .host
1107
+ // THIS SHOULD BE THE FIRST THING THAT HAPPENS!
1108
+ this.host = this.getRootNode().host;
1109
+
1110
+ // Keep it here and not in bindEvents!
1111
+ if ((this === null || this === void 0 ? void 0 : this.tagName) === "INPUT") {
1112
+ _classPrivateFieldSet(_changeEventHandler, this, function () {
1113
+ var changeEvent = new Event('inputChange', {
1114
+ bubbles: true,
1115
+ composed: true
1116
+ });
1117
+ this.dispatchEvent(changeEvent);
1118
+ });
1119
+ // Change events does not automatically bubbles, we need to listen and bubble up a new event
1120
+ this.addEventListener('change', _classPrivateFieldGet(_changeEventHandler, this), false);
1121
+ }
1122
+ var commands = [];
1123
+ var attributeNames = this.getAttributeNames();
1124
+ var _iterator = ReactiveElement_createForOfIteratorHelper(attributeNames),
1125
+ _step;
1126
+ try {
1127
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
1128
+ var attrName = _step.value;
1129
+ var attrValue = this.getAttribute(attrName);
1130
+ // This also resolves "State attributes"
1131
+ this.initialSetAttribute(attrName, attrValue);
1132
+
1133
+ // Save "Command attributes"
1134
+ if (attrName.indexOf('_') === 0) {
1135
+ var command = attrName.substring(1);
1136
+ commands.push({
1137
+ command: command,
1138
+ args: attrValue
1139
+ });
1140
+ }
1141
+ }
1142
+ } catch (err) {
1143
+ _iterator.e(err);
1144
+ } finally {
1145
+ _iterator.f();
1146
+ }
1147
+ commands.forEach(function (_ref) {
1148
+ var _COMMAND_ATTRIBUTES$c;
1149
+ var command = _ref.command,
1150
+ args = _ref.args;
1151
+ (_COMMAND_ATTRIBUTES$c = COMMANDS[command]) === null || _COMMAND_ATTRIBUTES$c === void 0 || _COMMAND_ATTRIBUTES$c.call(_this2, args);
1152
+ });
1153
+ _classPrivateFieldSet(_wasMounted, this, true);
1154
+ }
1155
+ }, {
1156
+ key: "attributeChangedCallback",
1157
+ value: function attributeChangedCallback(attributeName, oldValue, newValue) {
1158
+ if (oldValue === newValue) return;
1159
+ if (!this.isConnected) return;
1160
+ if (attributeName === "ref") {
1161
+ var host = this.isNativeElement ? this.host : this;
1162
+ var refValue = newValue;
1163
+ host.ref[refValue] = this;
1164
+ }
1165
+ if (attributeName in _classPrivateFieldGet(_boundAttributesToState, this)) {
1166
+ _assertClassBrand(_ReactiveElement_brand, this, _updateStateFromAttribute).call(this, attributeName);
1167
+ }
1168
+ }
1169
+
1170
+ // Gets state value of stateProp,
1171
+ // tries to resolve from local state(s) first,
1172
+ // and then from global. If the second argument is true, returns both the state value and the state objec
1173
+ }, {
1174
+ key: "getState",
1175
+ value: function getState(stateProp) {
1176
+ var returnStateObject = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1177
+ var theState;
1178
+ // If this is a reactive element inside a reactive web component - the host should be the containing web component -
1179
+ // we should reference its state, if host is null - it is most likely the host web component
1180
+ var thisInstance = this.isNativeElement && this.host ? this.host : this;
1181
+ // if (!thisInstance) return returnStateObject ? [undefined, undefined] : undefined;
1182
+ var stateVal;
1183
+ if (thisInstance && thisInstance.state) {
1184
+ var _thisInstance$state;
1185
+ stateVal = (_thisInstance$state = thisInstance.state) === null || _thisInstance$state === void 0 ? void 0 : _thisInstance$state[stateProp];
1186
+ }
1187
+ var globalState = false;
1188
+ while (stateVal === undefined && typeof thisInstance.host !== 'undefined' && thisInstance.host !== null) {
1189
+ var _thisInstance$state2;
1190
+ thisInstance = thisInstance.host;
1191
+ stateVal = (_thisInstance$state2 = thisInstance.state) === null || _thisInstance$state2 === void 0 ? void 0 : _thisInstance$state2[stateProp];
1192
+ }
1193
+ if (stateVal !== undefined) theState = thisInstance.state;else {
1194
+ var _globalState;
1195
+ globalState = appScope[GLOBAL_STATE_FUNCTION_NAME]();
1196
+ stateVal = (_globalState = globalState) === null || _globalState === void 0 ? void 0 : _globalState[stateProp];
1197
+ if (stateVal !== undefined) theState = globalState;
1198
+ }
1199
+ if (returnStateObject) {
1200
+ return [stateVal, theState];
1201
+ }
1202
+ return stateVal;
1203
+ }
1204
+ }, {
1205
+ key: "findElement",
1206
+ value: function findElement(refName) {
1207
+ var host = this.host || this;
1208
+ // if Shadow DOM is used, the "root" element is shadowRoot, otherwise it is the
1209
+ // web component itself
1210
+ var root = host;
1211
+ if (appScope.SPROUT_CONFIG.useShadow) {
1212
+ root = host.shadowRoot;
1213
+ }
1214
+ return host.ref.hasOwnProperty(refName) ? host.ref[refName] : root.querySelector("[ref=\"".concat(refName, "\"]"));
1215
+ }
1216
+
1217
+ // The "initialSetX" functions are called:
1218
+ // 1. When a custom element instance is first created (before it's connected) -
1219
+ // state attribute values are set to their state prop names (e.g: '$name').
1220
+ // 2. When a custom element instance becomes connected (added to the DOM) - state attribute values are actually resolved to the
1221
+ // value of their respective state prop values, and binding between them occurs.
1222
+ }, {
1223
+ key: "initialSetText",
1224
+ value: function initialSetText(stateProp) {
1225
+ setStateText.call(this, stateProp);
1226
+ }
1227
+ }, {
1228
+ key: "initialSetAttribute",
1229
+ value: function initialSetAttribute(attributeName, attributeValue) {
1230
+ attributeValue = String(attributeValue);
1231
+ var valueToSet = attributeValue;
1232
+ /*
1233
+ // "Property Attribute"
1234
+ if (attributeValue.indexOf('@') === 0 && this.host && this.isConnected) {
1235
+ valueToSet = this.host.getAttribute(attributeValue.substring(1));
1236
+ }
1237
+ */
1238
+
1239
+ // "State attribute"
1240
+ if (attributeValue.indexOf('$') === 0 && this.isConnected) {
1241
+ var stateProp = attributeValue.substring(1);
1242
+ setStateAttribute.call(this, attributeName, stateProp);
1243
+ }
1244
+ // normal attribute
1245
+ else {
1246
+ setAttribute.call(this, attributeName, valueToSet);
1247
+ }
1248
+ }
1249
+ }]);
1250
+ }(elementClass);
1251
+ /*
1252
+ if (DEBUG_MODE) {
1253
+ const descriptors = Object.getOwnPropertyDescriptors(ReactiveElement.prototype);
1254
+ for (const key in descriptors) {
1255
+ const descrp = descriptors[key];
1256
+ Object.defineProperty(ReactiveElement.prototype, key, {
1257
+ writable: descrp.writable,
1258
+ configurable: descrp.configurable,
1259
+ enumerable: descrp.enumerable,
1260
+ value: ()=> {
1261
+ `Calling ${key} on ReactiveElement for ${elementClass.toString()}`;
1262
+ descrp.value();
1263
+ }
1264
+ });
1265
+ }
1266
+ }
1267
+ */
1268
+ function _updateStateFromAttribute(attributeName) {
1269
+ var newValue = this.getAttribute(attributeName);
1270
+ if (BOOLEAN_ATTRIBUTES.includes(attributeName)) {
1271
+ if (newValue === null) newValue = false;else newValue = true;
1272
+ }
1273
+ var stateProp = _classPrivateFieldGet(_boundAttributesToState, this)[attributeName];
1274
+ var _this$getState3 = this.getState(stateProp, true),
1275
+ _this$getState4 = ReactiveElement_slicedToArray(_this$getState3, 2),
1276
+ stateValue = _this$getState4[0],
1277
+ theState = _this$getState4[1];
1278
+ if (stateValue !== newValue) theState[stateProp] = newValue;
1279
+ }
1280
+ _defineProperty(ReactiveElement, "observedAttributes", ["ref"].concat(SUPPORTED_ATTRIBUTES_FOR_BINDING).concat(Object.keys(COMMANDS).map(function (command) {
1281
+ return '_' + command.toLowerCase();
1282
+ })));
1283
+ return ReactiveElement;
1284
+ }
1285
+ ;// ./src/core/debug_utils.js
1286
+ function debug_utils_typeof(o) { "@babel/helpers - typeof"; return debug_utils_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, debug_utils_typeof(o); }
1287
+ function debugGetProxyHandler(scopeName, originalObject) {
1288
+ return {
1289
+ get: function get(target, property, receiver) {
1290
+ if (debug_utils_typeof(property) === "symbol") return Reflect.get.apply(Reflect, arguments);
1291
+ console.debug("Property ".concat(property, " called on ").concat(scopeName));
1292
+ if (property === "prototype") {
1293
+ // return Object.getPrototypeOf(originalObject.prototype);
1294
+ return originalObject.prototype;
1295
+ }
1296
+ if (typeof target[property] === "function") {
1297
+ return new Proxy(target[property], debugApplyProxyHandler(property, "".concat(scopeName, ".").concat(property)));
1298
+ } else if (debug_utils_typeof(target[property]) === "object") {
1299
+ if (!target[property].hasOwnProperty("_stateManager")) {
1300
+ return new Proxy(target[property], debugGetProxyHandler("".concat(scopeName, ".").concat(property)));
1301
+ }
1302
+ }
1303
+ return Reflect.get.apply(Reflect, arguments);
1304
+ }
1305
+ };
1306
+ }
1307
+ function debugApplyProxyHandler(funcName, scopeName) {
1308
+ return {
1309
+ construct: function construct(target, args, newTarget) {
1310
+ console.debug("Constructing ".concat(funcName));
1311
+ return Reflect.construct(target, args, newTarget);
1312
+ },
1313
+ apply: function apply(target, thisArg, argumentsList) {
1314
+ console.debug("Function: ".concat(funcName, " with arguments: ").concat(argumentsList, " called on ").concat(scopeName));
1315
+ return Reflect.apply.apply(Reflect, arguments);
1316
+ }
1317
+ };
1318
+ }
1319
+ function putObjectInDebugMode(obj, name) {
1320
+ return new Proxy(obj, debugGetProxyHandler(name, obj));
1321
+ }
1322
+ ;// ./src/core/StatefulArray.js
1323
+ function StatefulArray_toConsumableArray(r) { return StatefulArray_arrayWithoutHoles(r) || StatefulArray_iterableToArray(r) || StatefulArray_unsupportedIterableToArray(r) || StatefulArray_nonIterableSpread(); }
1324
+ function StatefulArray_nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
1325
+ function StatefulArray_unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return StatefulArray_arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? StatefulArray_arrayLikeToArray(r, a) : void 0; } }
1326
+ function StatefulArray_iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
1327
+ function StatefulArray_arrayWithoutHoles(r) { if (Array.isArray(r)) return StatefulArray_arrayLikeToArray(r); }
1328
+ function StatefulArray_arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
1329
+ function StatefulArray_typeof(o) { "@babel/helpers - typeof"; return StatefulArray_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, StatefulArray_typeof(o); }
1330
+ function StatefulArray_classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
1331
+ function StatefulArray_defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, StatefulArray_toPropertyKey(o.key), o); } }
1332
+ function StatefulArray_createClass(e, r, t) { return r && StatefulArray_defineProperties(e.prototype, r), t && StatefulArray_defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
1333
+ function StatefulArray_callSuper(t, o, e) { return o = StatefulArray_getPrototypeOf(o), StatefulArray_possibleConstructorReturn(t, StatefulArray_isNativeReflectConstruct() ? Reflect.construct(o, e || [], StatefulArray_getPrototypeOf(t).constructor) : o.apply(t, e)); }
1334
+ function StatefulArray_possibleConstructorReturn(t, e) { if (e && ("object" == StatefulArray_typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return StatefulArray_assertThisInitialized(t); }
1335
+ function StatefulArray_assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
1336
+ function StatefulArray_inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && StatefulArray_setPrototypeOf(t, e); }
1337
+ function _get() { return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) { var p = _superPropBase(e, t); if (p) { var n = Object.getOwnPropertyDescriptor(p, t); return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value; } }, _get.apply(null, arguments); }
1338
+ function _superPropBase(t, o) { for (; !{}.hasOwnProperty.call(t, o) && null !== (t = StatefulArray_getPrototypeOf(t));); return t; }
1339
+ function _wrapNativeSuper(t) { var r = "function" == typeof Map ? new Map() : void 0; return _wrapNativeSuper = function _wrapNativeSuper(t) { if (null === t || !_isNativeFunction(t)) return t; if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function"); if (void 0 !== r) { if (r.has(t)) return r.get(t); r.set(t, Wrapper); } function Wrapper() { return _construct(t, arguments, StatefulArray_getPrototypeOf(this).constructor); } return Wrapper.prototype = Object.create(t.prototype, { constructor: { value: Wrapper, enumerable: !1, writable: !0, configurable: !0 } }), StatefulArray_setPrototypeOf(Wrapper, t); }, _wrapNativeSuper(t); }
1340
+ function _construct(t, e, r) { if (StatefulArray_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments); var o = [null]; o.push.apply(o, e); var p = new (t.bind.apply(t, o))(); return r && StatefulArray_setPrototypeOf(p, r.prototype), p; }
1341
+ function StatefulArray_isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (StatefulArray_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
1342
+ function _isNativeFunction(t) { try { return -1 !== Function.toString.call(t).indexOf("[native code]"); } catch (n) { return "function" == typeof t; } }
1343
+ function StatefulArray_setPrototypeOf(t, e) { return StatefulArray_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, StatefulArray_setPrototypeOf(t, e); }
1344
+ function StatefulArray_getPrototypeOf(t) { return StatefulArray_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, StatefulArray_getPrototypeOf(t); }
1345
+ function StatefulArray_defineProperty(e, r, t) { return (r = StatefulArray_toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
1346
+ function StatefulArray_toPropertyKey(t) { var i = StatefulArray_toPrimitive(t, "string"); return "symbol" == StatefulArray_typeof(i) ? i : i + ""; }
1347
+ function StatefulArray_toPrimitive(t, r) { if ("object" != StatefulArray_typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != StatefulArray_typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
1348
+
1349
+
1350
+
1351
+
1352
+
1353
+ var StatefulArray = /*#__PURE__*/function (_Array) {
1354
+ // noConvertToStateItems can be used in internal methods where a normal array is returned and you just want to recreate a StatefulArray,
1355
+ // with the same state items
1356
+
1357
+ // NOTE: original Array constructor can get a series of arguments to build an array from, OR a single number,
1358
+ // to create an array with that number as a length
1359
+ function StatefulArray(initialArray, parentStateObject, arrayStateProp) {
1360
+ var _this;
1361
+ var noConvertToStateItems = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
1362
+ var appScope = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : window;
1363
+ StatefulArray_classCallCheck(this, StatefulArray);
1364
+ if (!Array.isArray(initialArray)) {
1365
+ throw Error("Argument for StateFulArray constructor must be an array!");
1366
+ }
1367
+ var rawArray = initialArray;
1368
+ var statefulArray;
1369
+ if (!noConvertToStateItems) {
1370
+ statefulArray = rawArray.map(function (item, index) {
1371
+ if (item !== null && item !== void 0 && item.hasOwnProperty('state')) return item;
1372
+ if (Array.isArray(item)) return item; // return new StatefulArray(item, this[index].state, index, false, appScope);
1373
+ if (StatefulArray_typeof(item) === 'object') return new core_StateManager(item, arrayStateProp, parentStateObject._stateManager, false, appScope);
1374
+ return item;
1375
+ });
1376
+ }
1377
+ _this = StatefulArray_callSuper(this, StatefulArray, StatefulArray_toConsumableArray(statefulArray));
1378
+ // If any of these are "set" - handle state change in the value
1379
+ StatefulArray_defineProperty(_this, "dependencyProps", new Map());
1380
+ _this.parentStateObject = parentStateObject;
1381
+ _this.arrayStateProp = arrayStateProp;
1382
+ _this.rawArray = rawArray;
1383
+ statefulArray = new Proxy(_this, StatefulArrayHandler(parentStateObject === null || parentStateObject === void 0 ? void 0 : parentStateObject._stateManager, arrayStateProp, appScope));
1384
+ return StatefulArray_possibleConstructorReturn(_this, statefulArray);
1385
+ }
1386
+ StatefulArray_inherits(StatefulArray, _Array);
1387
+ return StatefulArray_createClass(StatefulArray, [{
1388
+ key: "splice",
1389
+ value:
1390
+ // We set the $$operation property on functions that manipulates the array in a way that can change its length,
1391
+ // to prevent redundant calls for handleStateChange.
1392
+ // The call will be made when the "length" property of the array will be changed
1393
+ function splice() {
1394
+ var _get2;
1395
+ this.$$operation = "splice";
1396
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1397
+ args[_key] = arguments[_key];
1398
+ }
1399
+ var result = (_get2 = _get(StatefulArray_getPrototypeOf(StatefulArray.prototype), "splice", this)).call.apply(_get2, [this].concat(args));
1400
+ delete this.$$operation;
1401
+ return result;
1402
+ }
1403
+ }, {
1404
+ key: "shift",
1405
+ value: function shift() {
1406
+ var _get3;
1407
+ this.$$operation = "shift";
1408
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
1409
+ args[_key2] = arguments[_key2];
1410
+ }
1411
+ var result = (_get3 = _get(StatefulArray_getPrototypeOf(StatefulArray.prototype), "shift", this)).call.apply(_get3, [this].concat(args));
1412
+ delete this.$$operation;
1413
+ return result;
1414
+ }
1415
+ }, {
1416
+ key: "unshift",
1417
+ value: function unshift() {
1418
+ var _get4;
1419
+ this.$$operation = "splice";
1420
+ for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
1421
+ args[_key3] = arguments[_key3];
1422
+ }
1423
+ var result = (_get4 = _get(StatefulArray_getPrototypeOf(StatefulArray.prototype), "unshift", this)).call.apply(_get4, [this].concat(args));
1424
+ delete this.$$operation;
1425
+ return result;
1426
+ }
1427
+ }, {
1428
+ key: "sort",
1429
+ value: function sort() {
1430
+ var _get5;
1431
+ this.$$operation = "sort";
1432
+ for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
1433
+ args[_key4] = arguments[_key4];
1434
+ }
1435
+ var result = (_get5 = _get(StatefulArray_getPrototypeOf(StatefulArray.prototype), "sort", this)).call.apply(_get5, [this].concat(args));
1436
+ delete this.$$operation;
1437
+ handleStateChange(this.parentStateObject._stateManager, this.arrayStateProp);
1438
+ return result;
1439
+ }
1440
+ }, {
1441
+ key: "reverse",
1442
+ value: function reverse() {
1443
+ var _get6;
1444
+ this.$$operation = "reverse";
1445
+ for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
1446
+ args[_key5] = arguments[_key5];
1447
+ }
1448
+ var result = (_get6 = _get(StatefulArray_getPrototypeOf(StatefulArray.prototype), "reverse", this)).call.apply(_get6, [this].concat(args));
1449
+ delete this.$$operation;
1450
+ handleStateChange(this.parentStateObject._stateManager, this.arrayStateProp);
1451
+ return result;
1452
+ }
1453
+ }, {
1454
+ key: "fill",
1455
+ value: function fill() {
1456
+ var _get7;
1457
+ this.$$operation = "fill";
1458
+ for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
1459
+ args[_key6] = arguments[_key6];
1460
+ }
1461
+ var result = (_get7 = _get(StatefulArray_getPrototypeOf(StatefulArray.prototype), "fill", this)).call.apply(_get7, [this].concat(args));
1462
+ delete this.$$operation;
1463
+ handleStateChange(this.parentStateObject._stateManager, this.arrayStateProp);
1464
+ return result;
1465
+ }
1466
+ }, {
1467
+ key: "copyWithin",
1468
+ value: function copyWithin() {
1469
+ var _get8;
1470
+ this.$$operation = "copyWithin";
1471
+ for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
1472
+ args[_key7] = arguments[_key7];
1473
+ }
1474
+ var result = (_get8 = _get(StatefulArray_getPrototypeOf(StatefulArray.prototype), "sort", this)).call.apply(_get8, [this].concat(args));
1475
+ delete this.$$operation;
1476
+ handleStateChange(this.parentStateObject._stateManager, this.arrayStateProp);
1477
+ return result;
1478
+ }
1479
+ }, {
1480
+ key: "slice",
1481
+ value: function slice() {
1482
+ var _get9;
1483
+ this.$$operation = "slice";
1484
+ for (var _len8 = arguments.length, args = new Array(_len8), _key8 = 0; _key8 < _len8; _key8++) {
1485
+ args[_key8] = arguments[_key8];
1486
+ }
1487
+ var result = (_get9 = _get(StatefulArray_getPrototypeOf(StatefulArray.prototype), "slice", this)).call.apply(_get9, [this].concat(args));
1488
+ delete this.$$operation;
1489
+ return result;
1490
+ }
1491
+
1492
+ /*
1493
+ clone() {
1494
+ this.$$operation = "clone";
1495
+ const result = this.map(item=> item);
1496
+ delete this.$$operation;
1497
+ return result;
1498
+ }
1499
+ */
1500
+ }, {
1501
+ key: "toArray",
1502
+ value: function toArray() {
1503
+ this.$$operation = "toArray";
1504
+ /*
1505
+ const result = [];
1506
+ for (let i = 0, len=this.length; i<len; i++) {
1507
+ result.push(Object.assign({}, this[i]));
1508
+ }
1509
+ */
1510
+ var result = this.rawArray;
1511
+ delete this.$$operation;
1512
+ return result;
1513
+ }
1514
+ }], [{
1515
+ key: Symbol.species,
1516
+ get:
1517
+ // This will define which "constructor" JS calls whenever it needs to construct a new array while calling some Array native functions
1518
+ function get() {
1519
+ return Array;
1520
+ }
1521
+ }]);
1522
+ }( /*#__PURE__*/_wrapNativeSuper(Array));
1523
+ if (DEBUG_MODE) {
1524
+ StatefulArray = putObjectInDebugMode(StatefulArray, "StatefulArray");
1525
+ }
1526
+ /* harmony default export */ const core_StatefulArray = (StatefulArray);
1527
+ ;// ./src/core/proxy_handlers.js
1528
+ function proxy_handlers_typeof(o) { "@babel/helpers - typeof"; return proxy_handlers_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, proxy_handlers_typeof(o); }
1529
+
1530
+
1531
+
1532
+
1533
+ var StatefulArrayHandler = function StatefulArrayHandler(parentStateManager, arrayStateProp) {
1534
+ var appScope = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : window;
1535
+ return {
1536
+ set: function set(targetArray, property, value) {
1537
+ // A change in array length triggers state change in the array state prop
1538
+ if (property === "length") {
1539
+ var setResult = Reflect.set(targetArray, property, value);
1540
+ parentStateManager.setDirtyProp(arrayStateProp);
1541
+ // queueMicrotask(()=> handleStateChange(parentStateManager, arrayStateProp));
1542
+ return setResult;
1543
+ }
1544
+
1545
+ // Return if the value is the same
1546
+ if (targetArray[property] === value) return true;
1547
+ var index = Number(property);
1548
+ if (!isNaN(index)) {
1549
+ // Check if the property is a numeric index
1550
+ // If we set it to a new object, convert it to a state object
1551
+ if (proxy_handlers_typeof(value) === 'object' && !value.hasOwnProperty('_stateManager') && !value.hasOwnProperty('state')) {
1552
+ value = new core_StateManager(value, arrayStateProp, parentStateManager, false, appScope);
1553
+ }
1554
+ // Make sure state values are always state manager values
1555
+ // Sometimes they can be state objects (because of the custom get handler in the Proxy)
1556
+ if (value.hasOwnProperty('_stateManager')) {
1557
+ value = value._stateManager;
1558
+ }
1559
+ // This means the object actions are part of a native array function ('splice' etc.), and that we should NOT
1560
+ // mark $$mapAction on values
1561
+ if (!targetArray.hasOwnProperty('$$operation')) {
1562
+ var doStateChangeHandle = false;
1563
+ if (index < targetArray.length) {
1564
+ doStateChangeHandle = true;
1565
+ }
1566
+ var _setResult = Reflect.set(targetArray, property, value);
1567
+ // Only handle state change if this is a change for an existing array item,
1568
+ // if it's a new item, it will already be handled on the "length" property set
1569
+ // Without this check we will have a redundant state check
1570
+ if (doStateChangeHandle) {
1571
+ parentStateManager.setDirtyProp(arrayStateProp);
1572
+ //queueMicrotask(()=> handleStateChange(parentStateManager, arrayStateProp));
1573
+ }
1574
+ return _setResult;
1575
+ }
1576
+ }
1577
+ return Reflect.set(targetArray, property, value);
1578
+ },
1579
+ get: function get(targetArray, property, receiver) {
1580
+ // if (typeof property === 'symbol') return Reflect.get(...arguments);
1581
+ // if (property === 'hasOwnProperty') return Reflect.get(...arguments);
1582
+ var index = Number(property);
1583
+ if (!isNaN(index)) {
1584
+ if (!targetArray[index]) return undefined;
1585
+ if (targetArray[index].hasOwnProperty('state')) return targetArray[index].state;
1586
+ // Could be another array
1587
+ return targetArray[index];
1588
+ }
1589
+
1590
+ /*
1591
+ // If this property is set on the array, it means the get is part of a "dependency check"
1592
+ if (targetArray.hasOwnProperty("_gettingDependenciesFor")) {
1593
+ targetArray.dependencyProps.set(property, targetArray._gettingDependenciesFor);
1594
+ delete targetArray._gettingDependenciesFor;
1595
+ }
1596
+ */
1597
+
1598
+ return Reflect.get.apply(Reflect, arguments);
1599
+ }
1600
+ };
1601
+ };
1602
+ var StateObjectValueHandler = function StateObjectValueHandler(rootStateObj, objPropertyName) {
1603
+ var appScope = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : window;
1604
+ return {
1605
+ defineProperty: function defineProperty(targetObj, property, descriptor) {
1606
+ if (typeof (descriptor === null || descriptor === void 0 ? void 0 : descriptor.value) !== "undefined") {
1607
+ var value = descriptor.value;
1608
+ // Could already be a StatefulArray (needs to find better way to detect this)
1609
+ if (Array.isArray(value)) {
1610
+ var _value$;
1611
+ if (!(value !== null && value !== void 0 && (_value$ = value[0]) !== null && _value$ !== void 0 && _value$._stateManager)) {
1612
+ descriptor.value = new core_StatefulArray(descriptor.value, rootStateObj, objPropertyName, false, appScope);
1613
+ }
1614
+ } else if (proxy_handlers_typeof(value) === "object") {
1615
+ descriptor.value = new Proxy(descriptor.value, StateObjectValueHandler(rootStateObj, objPropertyName, appScope));
1616
+ }
1617
+ } else if (typeof (descriptor === null || descriptor === void 0 ? void 0 : descriptor.get) === "function") {
1618
+ descriptor.get.call(targetObj);
1619
+ }
1620
+ // Don't use "arguments" here - they are not linked to argument changes in 'strict'
1621
+ var definePropertyResult = Reflect.defineProperty(targetObj, property, descriptor);
1622
+ var stateManager = rootStateObj._stateManager;
1623
+ stateManager.setDirtyProp(objPropertyName);
1624
+ // queueMicrotask(()=> handleStateChange(stateManager, objPropertyName));
1625
+ return definePropertyResult;
1626
+ }
1627
+ };
1628
+ };
1629
+ var StateHandler = function StateHandler(stateObj) {
1630
+ var appScope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : window;
1631
+ return {
1632
+ defineProperty: function defineProperty(targetState, stateProp, descriptor) {
1633
+ var _targetState;
1634
+ if (BUILT_IN_STATE_PROPS.includes(stateProp) || (_targetState = targetState) !== null && _targetState !== void 0 && _targetState._binding) {
1635
+ return Reflect.defineProperty.apply(Reflect, arguments);
1636
+ }
1637
+ var origTargetState = targetState;
1638
+ var dependencies = new Set();
1639
+ // Will be the actual prop name if this is a state hook setter
1640
+ var setStateProp;
1641
+ targetState = new Proxy(targetState, {
1642
+ get: function get(target, property, receiver) {
1643
+ if (property === "_global") {
1644
+ target._global._gettingDependenciesFor = stateProp;
1645
+ target._global._localStateManager = target._stateManager;
1646
+ }
1647
+ if (BUILT_IN_STATE_PROPS.includes(property)) {
1648
+ return Reflect.get.apply(Reflect, arguments);
1649
+ }
1650
+ if (Array.isArray(target[property])) {
1651
+ target[property]._gettingDependenciesFor = stateProp;
1652
+ }
1653
+ dependencies.add(property);
1654
+ return Reflect.get.apply(Reflect, arguments);
1655
+ }
1656
+ });
1657
+ if (typeof (descriptor === null || descriptor === void 0 ? void 0 : descriptor.value) !== "undefined") {
1658
+ var value = descriptor.value;
1659
+ // Could already be a StatefulArray (needs to find better way to detect this)
1660
+ if (Array.isArray(value)) {
1661
+ var _value$2;
1662
+ // Setter Hook
1663
+ if (stateProp.indexOf('set_') === 0) {
1664
+ var deps = value === null || value === void 0 ? void 0 : value[1];
1665
+ if (!deps) throw Error(ERROR_MESSAGES.NO_DEPENDENCIES_ARRAY_IN_SET_HOOK(stateProp));
1666
+ // Second item should be an array of dependencies
1667
+ value === null || value === void 0 || value[1].forEach(function (depProp) {
1668
+ dependencies.add(depProp);
1669
+ });
1670
+ // Third item can be a boolean stating if to run the setter on initialization
1671
+ if ((value === null || value === void 0 ? void 0 : value[2]) === true) {
1672
+ setStateProp = stateProp.substring(4);
1673
+ var func = value === null || value === void 0 ? void 0 : value[0];
1674
+ if (func && typeof func === "function") {
1675
+ stateObj[setStateProp] = func.call(stateObj);
1676
+ }
1677
+ } else {
1678
+ if (value !== null && value !== void 0 && value[3]) {
1679
+ stateObj[setStateProp] = value[3];
1680
+ }
1681
+ }
1682
+ } else if (!(value !== null && value !== void 0 && (_value$2 = value[0]) !== null && _value$2 !== void 0 && _value$2._stateManager)) {
1683
+ descriptor.value = new core_StatefulArray(descriptor.value, stateObj, stateProp, false, appScope);
1684
+ }
1685
+ } else if (proxy_handlers_typeof(value) === 'object') {
1686
+ descriptor.value = new Proxy(descriptor.value, StateObjectValueHandler(stateObj, stateProp, appScope));
1687
+ }
1688
+ } else if (typeof (descriptor === null || descriptor === void 0 ? void 0 : descriptor.get) === "function") {
1689
+ descriptor.get.call(targetState);
1690
+ }
1691
+ if (dependencies.size) {
1692
+ dependencies.forEach(function (dep) {
1693
+ return stateObj._stateManager.addStateDependency(dep, stateProp);
1694
+ });
1695
+ }
1696
+
1697
+ // Don't use "arguments" here - they are not linked to argument changes in 'strict'
1698
+ var definePropertyResult = Reflect.defineProperty(origTargetState, stateProp, descriptor);
1699
+ var stateManager = stateObj._stateManager;
1700
+ if (setStateProp) stateProp = setStateProp;
1701
+ if (!origTargetState.hasOwnProperty("_populate")) stateManager.setDirtyProp(stateProp);
1702
+ // queueMicrotask(()=> handleStateChange(stateManager, stateProp));
1703
+ return definePropertyResult;
1704
+ },
1705
+ get: function get(targetState, property, receiver) {
1706
+ if (property === 'hasOwnProperty') return Reflect.get.apply(Reflect, arguments);
1707
+ // Global state access
1708
+ if (!targetState.hasOwnProperty('_global')) {
1709
+ if (targetState.hasOwnProperty("_gettingDependenciesFor")) {
1710
+ targetState._stateManager.addGlobalStateDependency(property, targetState._gettingDependenciesFor, targetState._localStateManager);
1711
+ delete targetState._gettingDependenciesFor;
1712
+ delete targetState._localStateManager;
1713
+ return Reflect.get.apply(Reflect, arguments);
1714
+ }
1715
+ }
1716
+ // property can be a Symbol on rare occasions, then indexOf will be undefined (that's the reason for the question mark)
1717
+ // This handles using the negate operator on state properties
1718
+ if (typeof (property === null || property === void 0 ? void 0 : property.indexOf) === 'function' && (property === null || property === void 0 ? void 0 : property.indexOf('!')) === 0) {
1719
+ var originalProperty = property.substring(1);
1720
+ if (targetState.hasOwnProperty(originalProperty)) {
1721
+ return !targetState[originalProperty];
1722
+ }
1723
+ }
1724
+ return Reflect.get.apply(Reflect, arguments);
1725
+ }
1726
+ };
1727
+ };
1728
+ ;// ./src/core/StateManager.js
1729
+ function StateManager_typeof(o) { "@babel/helpers - typeof"; return StateManager_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, StateManager_typeof(o); }
1730
+ function StateManager_toConsumableArray(r) { return StateManager_arrayWithoutHoles(r) || StateManager_iterableToArray(r) || StateManager_unsupportedIterableToArray(r) || StateManager_nonIterableSpread(); }
1731
+ function StateManager_nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
1732
+ function StateManager_unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return StateManager_arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? StateManager_arrayLikeToArray(r, a) : void 0; } }
1733
+ function StateManager_iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
1734
+ function StateManager_arrayWithoutHoles(r) { if (Array.isArray(r)) return StateManager_arrayLikeToArray(r); }
1735
+ function StateManager_arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
1736
+ function StateManager_classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
1737
+ function StateManager_defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, StateManager_toPropertyKey(o.key), o); } }
1738
+ function StateManager_createClass(e, r, t) { return r && StateManager_defineProperties(e.prototype, r), t && StateManager_defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
1739
+ function StateManager_classPrivateFieldInitSpec(e, t, a) { StateManager_checkPrivateRedeclaration(e, t), t.set(e, a); }
1740
+ function StateManager_checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
1741
+ function StateManager_defineProperty(e, r, t) { return (r = StateManager_toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
1742
+ function StateManager_toPropertyKey(t) { var i = StateManager_toPrimitive(t, "string"); return "symbol" == StateManager_typeof(i) ? i : i + ""; }
1743
+ function StateManager_toPrimitive(t, r) { if ("object" != StateManager_typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != StateManager_typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
1744
+ function StateManager_classPrivateFieldSet(s, a, r) { return s.set(StateManager_assertClassBrand(s, a), r), r; }
1745
+ function StateManager_classPrivateFieldGet(s, a) { return s.get(StateManager_assertClassBrand(s, a)); }
1746
+ function StateManager_assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
1747
+
1748
+
1749
+
1750
+
1751
+
1752
+
1753
+
1754
+ // This class actually handles "State". It returns a proxied "state" object,
1755
+ // while handling all state changes and triggers behind the scenes
1756
+ var _handleStateChangeRAF_ID = /*#__PURE__*/new WeakMap();
1757
+ var StateManager = /*#__PURE__*/function () {
1758
+ function StateManager(initialState, parentStateProp, parentStateManager) {
1759
+ var _this = this;
1760
+ var isGlobal = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
1761
+ var appScope = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : window;
1762
+ StateManager_classCallCheck(this, StateManager);
1763
+ // The privateState is used to actually contain values to read from,
1764
+ // as custom getters and setters are defined
1765
+ StateManager_defineProperty(this, "privateState", {});
1766
+ // This represents the "publicly" exposed state object
1767
+ StateManager_defineProperty(this, "state", {});
1768
+ // Saves "map" connections between a state array value and a custom element name,
1769
+ // this will enable creating/removing new custom elements when items of a state array change
1770
+ StateManager_defineProperty(this, "stateArrayMaps", {});
1771
+ // conditionallyRenderingElements = {};
1772
+ // A map that maps state props to "dependencies", each time a stateProp which is a key here,
1773
+ // is changed, a state change is triggered for its dependencies as well
1774
+ StateManager_defineProperty(this, "stateDependencies", {});
1775
+ StateManager_defineProperty(this, "conditionallyRenderingElements", {});
1776
+ // Maps state props to state nodes,
1777
+ // Keys are state props, and values are sets of Nodes
1778
+ StateManager_defineProperty(this, "stateNodes", {});
1779
+ // These are used when the state object is part of Stateful Array
1780
+ StateManager_defineProperty(this, "parentStateProp", void 0);
1781
+ StateManager_defineProperty(this, "parentStateManager", void 0);
1782
+ // parentStatePropName is used if the state object is e.g. an item of an array on a state object,
1783
+ // or a value in an object on a state object - any change on the child state object should trigger state
1784
+ // changes on the parentStateProp
1785
+ // host is the host element that the state is attached to
1786
+ StateManager_defineProperty(this, "dirtyProps", new Set());
1787
+ StateManager_classPrivateFieldInitSpec(this, _handleStateChangeRAF_ID, null);
1788
+ this.parentStateProp = parentStateProp;
1789
+ this.parentStateManager = parentStateManager;
1790
+
1791
+ // Saves the actual state manager instance to a readonly _stateManager
1792
+ setHiddenProperty(this.state, "_stateManager", this, true);
1793
+
1794
+ // Initialize a proxy on the "public state"
1795
+ this.state = new Proxy(this.state, StateHandler(this.state, appScope));
1796
+ if (!isGlobal) setHiddenProperty(this.state, "_global", appScope[GLOBAL_STATE_FUNCTION_NAME](), true);else {
1797
+ // This maps depencdies between "local" state properties to global state changes
1798
+ // The difference between the normal dependencies object, is that each depenency
1799
+ // also includes a state object (which is the state context of the property),
1800
+ // in other words, if a local state "relies" on a global state change - we save this
1801
+ // mapping here.
1802
+ // The keys are global state properties, where each value is a Map,
1803
+ // in the map, the keys are local state manager objects, and the values are sets with
1804
+ // local property names
1805
+ this.globalStateDependencies = {};
1806
+ this.addGlobalStateDependency = function (stateProp, depStateProp, stateManager) {
1807
+ if (!_this.globalStateDependencies.hasOwnProperty(stateProp)) {
1808
+ _this.globalStateDependencies[stateProp] = new Map();
1809
+ }
1810
+ if (!_this.globalStateDependencies[stateProp].has(stateManager)) {
1811
+ _this.globalStateDependencies[stateProp].set(stateManager, new Set());
1812
+ }
1813
+ _this.globalStateDependencies[stateProp].get(stateManager).add(depStateProp);
1814
+ };
1815
+ }
1816
+ if (initialState) {
1817
+ populateStateFromInitialState(this.state, initialState);
1818
+ }
1819
+ }
1820
+ return StateManager_createClass(StateManager, [{
1821
+ key: "setDirtyProp",
1822
+ value: function setDirtyProp(prop) {
1823
+ var _this2 = this;
1824
+ this.dirtyProps.add(prop);
1825
+ if (StateManager_classPrivateFieldGet(_handleStateChangeRAF_ID, this)) {
1826
+ cancelAnimationFrame(StateManager_classPrivateFieldGet(_handleStateChangeRAF_ID, this));
1827
+ // clearTimeout(this.#handleStateChangeRAF_ID);
1828
+ }
1829
+ StateManager_classPrivateFieldSet(_handleStateChangeRAF_ID, this, requestAnimationFrame(function () {
1830
+ StateManager_classPrivateFieldSet(_handleStateChangeRAF_ID, _this2, null);
1831
+ if (_this2.dirtyProps.size > 0) {
1832
+ _this2.handleStateChanges();
1833
+ }
1834
+ }));
1835
+ }
1836
+ }, {
1837
+ key: "handleStateChanges",
1838
+ value: function handleStateChanges() {
1839
+ var _this3 = this;
1840
+ console.log("Handling state changes for", this);
1841
+ var stateProps = StateManager_toConsumableArray(this.dirtyProps);
1842
+ this.dirtyProps.clear();
1843
+ stateProps.forEach(function (prop) {
1844
+ handleStateChange(_this3, prop);
1845
+ });
1846
+ }
1847
+ }, {
1848
+ key: "addStateDependency",
1849
+ value: function addStateDependency(stateProp, depStateProp) {
1850
+ if (!this.stateDependencies.hasOwnProperty(stateProp)) {
1851
+ this.stateDependencies[stateProp] = new Set();
1852
+ }
1853
+ this.stateDependencies[stateProp].add(depStateProp);
1854
+ }
1855
+ }, {
1856
+ key: "addStateMap",
1857
+ value: function addStateMap(stateProp, customElementName, parentElement) {
1858
+ if (!this.stateArrayMaps.hasOwnProperty(stateProp)) {
1859
+ this.stateArrayMaps[stateProp] = new Map();
1860
+ }
1861
+ this.stateArrayMaps[stateProp].set(parentElement, customElementName);
1862
+ }
1863
+ }, {
1864
+ key: "addConditionallyRenderingElements",
1865
+ value: function addConditionallyRenderingElements(stateProp, element) {
1866
+ var _element$host;
1867
+ if (!this.conditionallyRenderingElements.hasOwnProperty(stateProp)) {
1868
+ this.conditionallyRenderingElements[stateProp] = new Set();
1869
+ }
1870
+ element.originalParentElement = element.parentElement || ((_element$host = element.host) === null || _element$host === void 0 ? void 0 : _element$host.shadowRoot);
1871
+ this.conditionallyRenderingElements[stateProp].add(element);
1872
+ }
1873
+
1874
+ // Node here is either an Attribute Node or a Text Node
1875
+ }, {
1876
+ key: "addStateNode",
1877
+ value: function addStateNode(stateProp, stateNode) {
1878
+ var isBooleanStateProp = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1879
+ if (!this.stateNodes.hasOwnProperty(stateProp)) {
1880
+ this.stateNodes[stateProp] = new Set();
1881
+ this.setAndBindStateProperty(stateProp, isBooleanStateProp);
1882
+ }
1883
+ this.stateNodes[stateProp].add(stateNode);
1884
+ }
1885
+ }, {
1886
+ key: "setAndBindStateProperty",
1887
+ value: function setAndBindStateProperty(stateProp) {
1888
+ var stateObj = this.state;
1889
+ var originalStateProp = stateProp;
1890
+ var isNegationProp = stateProp.indexOf('!') === 0;
1891
+ if (isNegationProp) {
1892
+ originalStateProp = stateProp.substring(1);
1893
+ }
1894
+ var descriptor = Object.getOwnPropertyDescriptor(stateObj, originalStateProp);
1895
+ if (!descriptor) {
1896
+ stateObj = stateObj._global;
1897
+ descriptor = Object.getOwnPropertyDescriptor(stateObj, originalStateProp);
1898
+ if (!descriptor) {
1899
+ throw Error("Could not bind state prop ".concat(stateProp, ". State prop ").concat(originalStateProp, " not defined!"));
1900
+ }
1901
+ }
1902
+ stateObj._binding = true;
1903
+
1904
+ // Some state props can be getters (which usually references other state values)
1905
+ // These should be treated differently: should not be saved in privateState, and should not have a setter defined
1906
+ var isValueProp = descriptor.hasOwnProperty('value');
1907
+ var stateManager = stateObj._stateManager;
1908
+ if (isNegationProp) {
1909
+ var negateStateProp = stateProp;
1910
+ if (isValueProp) {
1911
+ if (!stateManager.privateState.hasOwnProperty(negateStateProp)) {
1912
+ Object.defineProperty(stateObj, negateStateProp, {
1913
+ get: function get() {
1914
+ return !stateManager.privateState[originalStateProp];
1915
+ },
1916
+ set: function set() {
1917
+ throw Error("Cannot directly set a negation State property!");
1918
+ },
1919
+ enumerable: true
1920
+ });
1921
+ stateManager.addStateDependency(originalStateProp, negateStateProp);
1922
+ }
1923
+ } else {
1924
+ if (!stateManager.state.hasOwnProperty(negateStateProp)) {
1925
+ Object.defineProperty(stateObj, negateStateProp, {
1926
+ get: function get() {
1927
+ return !stateManager.state[originalStateProp];
1928
+ },
1929
+ set: function set() {
1930
+ throw Error("Cannot directly set a negation State property!");
1931
+ },
1932
+ enumerable: true
1933
+ });
1934
+ stateManager.addStateDependency(originalStateProp, negateStateProp);
1935
+ }
1936
+ }
1937
+ } else {
1938
+ if (isValueProp) {
1939
+ if (!stateManager.privateState.hasOwnProperty(stateProp)) {
1940
+ stateManager.privateState[stateProp] = stateObj[stateProp];
1941
+ }
1942
+ Object.defineProperty(stateObj, stateProp, {
1943
+ set: function set(value) {
1944
+ var currentVal = stateManager.privateState[stateProp];
1945
+ if (value === currentVal) return;
1946
+ // Sets value to "private state"
1947
+ stateManager.privateState[stateProp] = value;
1948
+ handleStateChange(stateManager, stateProp);
1949
+ // If this is an item in a Stateful Array, also trigger a state change for the state prop that contains the array
1950
+ if (stateManager.parentStateManager) {
1951
+ handleStateChange(stateManager.parentStateManager, stateManager.parentStateProp);
1952
+ }
1953
+ },
1954
+ get: function get() {
1955
+ // Value is always retrieved from the "private" state
1956
+ return stateManager.privateState[stateProp];
1957
+ }
1958
+ });
1959
+ }
1960
+ // If is a getter then - it can't be set, and the getter will return the value.
1961
+ }
1962
+ delete this.state._binding;
1963
+ }
1964
+ }]);
1965
+ }();
1966
+ if (DEBUG_MODE) {
1967
+ StateManager = putObjectInDebugMode(StateManager, 'StateManager');
1968
+ }
1969
+ /* harmony default export */ const core_StateManager = (StateManager);
1970
+ ;// ./src/build/index.js
1971
+ function build_typeof(o) { "@babel/helpers - typeof"; return build_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, build_typeof(o); }
1972
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == build_typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(build_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
1973
+ function build_defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, build_toPropertyKey(o.key), o); } }
1974
+ function build_createClass(e, r, t) { return r && build_defineProperties(e.prototype, r), t && build_defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
1975
+ function build_toPropertyKey(t) { var i = build_toPrimitive(t, "string"); return "symbol" == build_typeof(i) ? i : i + ""; }
1976
+ function build_toPrimitive(t, r) { if ("object" != build_typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != build_typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
1977
+ function build_classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
1978
+ function build_callSuper(t, o, e) { return o = build_getPrototypeOf(o), build_possibleConstructorReturn(t, build_isNativeReflectConstruct() ? Reflect.construct(o, e || [], build_getPrototypeOf(t).constructor) : o.apply(t, e)); }
1979
+ function build_possibleConstructorReturn(t, e) { if (e && ("object" == build_typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return build_assertThisInitialized(t); }
1980
+ function build_assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
1981
+ function build_isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (build_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
1982
+ function build_getPrototypeOf(t) { return build_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, build_getPrototypeOf(t); }
1983
+ function build_inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && build_setPrototypeOf(t, e); }
1984
+ function build_setPrototypeOf(t, e) { return build_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, build_setPrototypeOf(t, e); }
1985
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
1986
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
1987
+ // This is the script that takes Template elements from the page and defines Reactive Custom Elements
1988
+ /* harmony default export */ function build(appScope, appName) {
1989
+ // Create custom elements from templates
1990
+ function defineCustomElementFromTemplate(_x, _x2, _x3) {
1991
+ return _defineCustomElementFromTemplate.apply(this, arguments);
1992
+ }
1993
+ function _defineCustomElementFromTemplate() {
1994
+ _defineCustomElementFromTemplate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(template, elemName, globalStylesheet) {
1995
+ var templateContent, style, runtime;
1996
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1997
+ while (1) switch (_context.prev = _context.next) {
1998
+ case 0:
1999
+ templateContent = document.importNode(template.content, true);
2000
+ style = templateContent.querySelector('style');
2001
+ if (style) templateContent.removeChild(style);
2002
+ runtime = templateContent.querySelector('script');
2003
+ if (runtime) templateContent.removeChild(runtime);
2004
+ customElements.define(elemName, /*#__PURE__*/function (_appScope$ReactiveCus) {
2005
+ function _class() {
2006
+ build_classCallCheck(this, _class);
2007
+ return build_callSuper(this, _class, [templateContent, runtime, style === null || style === void 0 ? void 0 : style.textContent, globalStylesheet]);
2008
+ }
2009
+ build_inherits(_class, _appScope$ReactiveCus);
2010
+ return build_createClass(_class);
2011
+ }(appScope.ReactiveCustomElement));
2012
+ case 6:
2013
+ case "end":
2014
+ return _context.stop();
2015
+ }
2016
+ }, _callee);
2017
+ }));
2018
+ return _defineCustomElementFromTemplate.apply(this, arguments);
2019
+ }
2020
+ function build() {
2021
+ var globalStylesheet;
2022
+ var globalStyle = document.querySelector("head > style[app=\"".concat(appName, "\"]"));
2023
+ if (globalStyle) {
2024
+ globalStylesheet = new CSSStyleSheet();
2025
+ globalStylesheet.replaceSync(globalStyle.textContent);
2026
+ }
2027
+ Array.prototype.forEach.call(document.querySelectorAll("template[app=\"".concat(appName, "\"]")), function (template) {
2028
+ defineCustomElementFromTemplate(template, template.getAttribute('for'), globalStylesheet);
2029
+ });
2030
+ if (typeof globalThis["".concat(appName, "_runtime")] === 'function') {
2031
+ var globalRuntimeFunction = globalThis["".concat(appName, "_runtime")];
2032
+ globalRuntimeFunction.call(appScope);
2033
+ }
2034
+ }
2035
+ build();
2036
+ }
2037
+ ;// ./src/core/attr_utils.js
2038
+ function attr_utils_typeof(o) { "@babel/helpers - typeof"; return attr_utils_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, attr_utils_typeof(o); }
2039
+ // Convert attribute values to "typed" values
2040
+ function attributeValueToTypedValue(attrValue) {
2041
+ var typedValue = attrValue;
2042
+ if (attrValue === "true") typedValue = true;else if (attrValue === "false") typedValue = false;else if (!isNaN(Number(attrValue))) typedValue = Number(attrValue);
2043
+ return typedValue;
2044
+ }
2045
+
2046
+ // Check if attribute node is a "Command" or a "State Attribute"
2047
+ function isSpecialAttribute(attrNode) {
2048
+ if (attr_utils_typeof(attrNode) !== "object" && attrNode.constructor.name !== "Attr") throw Error("Passed non Attribute to isSpecialAttribute!");
2049
+ return attrNode.nodeName.indexOf('_') === 0 || attrNode.nodeValue.indexOf('$') === 0;
2050
+ }
2051
+ ;// ./src/core/ConditionalElement.js
2052
+ function ConditionalElement_slicedToArray(r, e) { return ConditionalElement_arrayWithHoles(r) || ConditionalElement_iterableToArrayLimit(r, e) || ConditionalElement_unsupportedIterableToArray(r, e) || ConditionalElement_nonIterableRest(); }
2053
+ function ConditionalElement_nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
2054
+ function ConditionalElement_iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
2055
+ function ConditionalElement_arrayWithHoles(r) { if (Array.isArray(r)) return r; }
2056
+ function ConditionalElement_toConsumableArray(r) { return ConditionalElement_arrayWithoutHoles(r) || ConditionalElement_iterableToArray(r) || ConditionalElement_unsupportedIterableToArray(r) || ConditionalElement_nonIterableSpread(); }
2057
+ function ConditionalElement_nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
2058
+ function ConditionalElement_unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return ConditionalElement_arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? ConditionalElement_arrayLikeToArray(r, a) : void 0; } }
2059
+ function ConditionalElement_iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
2060
+ function ConditionalElement_arrayWithoutHoles(r) { if (Array.isArray(r)) return ConditionalElement_arrayLikeToArray(r); }
2061
+ function ConditionalElement_arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
2062
+ function ConditionalElement_classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
2063
+ function ConditionalElement_defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, ConditionalElement_toPropertyKey(o.key), o); } }
2064
+ function ConditionalElement_createClass(e, r, t) { return r && ConditionalElement_defineProperties(e.prototype, r), t && ConditionalElement_defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
2065
+ function ConditionalElement_toPropertyKey(t) { var i = ConditionalElement_toPrimitive(t, "string"); return "symbol" == ConditionalElement_typeof(i) ? i : i + ""; }
2066
+ function ConditionalElement_toPrimitive(t, r) { if ("object" != ConditionalElement_typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != ConditionalElement_typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
2067
+ function ConditionalElement_callSuper(t, o, e) { return o = ConditionalElement_getPrototypeOf(o), ConditionalElement_possibleConstructorReturn(t, ConditionalElement_isNativeReflectConstruct() ? Reflect.construct(o, e || [], ConditionalElement_getPrototypeOf(t).constructor) : o.apply(t, e)); }
2068
+ function ConditionalElement_possibleConstructorReturn(t, e) { if (e && ("object" == ConditionalElement_typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return ConditionalElement_assertThisInitialized(t); }
2069
+ function ConditionalElement_assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
2070
+ function ConditionalElement_isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (ConditionalElement_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
2071
+ function ConditionalElement_getPrototypeOf(t) { return ConditionalElement_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, ConditionalElement_getPrototypeOf(t); }
2072
+ function ConditionalElement_inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && ConditionalElement_setPrototypeOf(t, e); }
2073
+ function ConditionalElement_setPrototypeOf(t, e) { return ConditionalElement_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, ConditionalElement_setPrototypeOf(t, e); }
2074
+ function ConditionalElement_classPrivateFieldInitSpec(e, t, a) { ConditionalElement_checkPrivateRedeclaration(e, t), t.set(e, a); }
2075
+ function ConditionalElement_checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
2076
+ function ConditionalElement_classPrivateFieldSet(s, a, r) { return s.set(ConditionalElement_assertClassBrand(s, a), r), r; }
2077
+ function ConditionalElement_classPrivateFieldGet(s, a) { return s.get(ConditionalElement_assertClassBrand(s, a)); }
2078
+ function ConditionalElement_assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
2079
+ function ConditionalElement_typeof(o) { "@babel/helpers - typeof"; return ConditionalElement_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, ConditionalElement_typeof(o); }
2080
+
2081
+
2082
+
2083
+
2084
+ // returns a Boolean according to the conditional equality of conditional to conditionStateValue
2085
+ function resolveConditional(conditional, conditionStateValue) {
2086
+ var typeOf = ConditionalElement_typeof(conditional);
2087
+ if (typeOf !== 'string') {
2088
+ return conditionStateValue === conditional;
2089
+ } else {
2090
+ if (conditional === "always") return true;
2091
+ if (CONDITIONAL_OPERATORS.includes(conditional[0])) {
2092
+ var conditionFn = new Function("return ".concat(conditionStateValue).concat(conditional));
2093
+ return conditionFn();
2094
+ } else {
2095
+ return conditionStateValue === conditional;
2096
+ }
2097
+ }
2098
+ }
2099
+ function getConditionalElementClass(ReactiveElementClass) {
2100
+ var _conditionStateProp = /*#__PURE__*/new WeakMap();
2101
+ var _renderMap = /*#__PURE__*/new WeakMap();
2102
+ var _wasMounted = /*#__PURE__*/new WeakMap();
2103
+ var ConditionalElement = /*#__PURE__*/function (_ReactiveElementClass) {
2104
+ function ConditionalElement() {
2105
+ var _this;
2106
+ ConditionalElement_classCallCheck(this, ConditionalElement);
2107
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2108
+ args[_key] = arguments[_key];
2109
+ }
2110
+ _this = ConditionalElement_callSuper(this, ConditionalElement, [].concat(args));
2111
+ ConditionalElement_classPrivateFieldInitSpec(_this, _conditionStateProp, void 0);
2112
+ ConditionalElement_classPrivateFieldInitSpec(_this, _renderMap, void 0);
2113
+ ConditionalElement_classPrivateFieldInitSpec(_this, _wasMounted, false);
2114
+ return _this;
2115
+ }
2116
+ ConditionalElement_inherits(ConditionalElement, _ReactiveElementClass);
2117
+ return ConditionalElement_createClass(ConditionalElement, [{
2118
+ key: "render",
2119
+ value: function render() {
2120
+ var _this2 = this;
2121
+ var isFirstRender = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
2122
+ var stateValue;
2123
+ if (ConditionalElement_classPrivateFieldGet(_conditionStateProp, this).indexOf('@') === 0) {
2124
+ stateValue = this.host.getAttribute(ConditionalElement_classPrivateFieldGet(_conditionStateProp, this).substring(1));
2125
+ } else {
2126
+ stateValue = this.getState(ConditionalElement_classPrivateFieldGet(_conditionStateProp, this));
2127
+ }
2128
+ if (stateValue === undefined) {
2129
+ throw Error("State value for ".concat(ConditionalElement_classPrivateFieldGet(_conditionStateProp, this), " not found while rendering conditional-render element:"), this);
2130
+ }
2131
+ var elementsToRender = [];
2132
+ ConditionalElement_classPrivateFieldGet(_renderMap, this).forEach(function (elements, conditional) {
2133
+ if (resolveConditional(conditional, stateValue)) {
2134
+ elementsToRender.push.apply(elementsToRender, ConditionalElement_toConsumableArray(elements));
2135
+ }
2136
+ });
2137
+ if (isFirstRender) {
2138
+ this.innerHTML = "";
2139
+ this.append.apply(this, elementsToRender);
2140
+ } else if (elementsToRender.length) {
2141
+ queueConditionalRender(this, function () {
2142
+ _this2.innerHTML = "";
2143
+ _this2.append.apply(_this2, elementsToRender);
2144
+ });
2145
+ }
2146
+ }
2147
+ }, {
2148
+ key: "connectedCallback",
2149
+ value: function connectedCallback() {
2150
+ this.host = this.getRootNode().host;
2151
+ if (!this.host) {
2152
+ throw Error("<conditional-render> must be used as part of a custom element template! Cannot be used outside of a custom element.");
2153
+ }
2154
+ if (ConditionalElement_classPrivateFieldGet(_wasMounted, this)) return;
2155
+ var conditionAttributeValue = this.getAttribute("_condition");
2156
+ if (!conditionAttributeValue) {
2157
+ throw Error("conditional-render elements must have a _condition command attribute");
2158
+ }
2159
+ if (!this.children || !this.children.length) {
2160
+ throw Error("Conditional element must have children!");
2161
+ }
2162
+ var statePropName = conditionAttributeValue;
2163
+ ConditionalElement_classPrivateFieldSet(_conditionStateProp, this, statePropName);
2164
+ var isConditionStatic = ConditionalElement_classPrivateFieldGet(_conditionStateProp, this).indexOf('@') === 0;
2165
+ var stateValue, stateObject;
2166
+ if (!isConditionStatic) {
2167
+ var _this$getState = this.getState(statePropName, true);
2168
+ var _this$getState2 = ConditionalElement_slicedToArray(_this$getState, 2);
2169
+ stateValue = _this$getState2[0];
2170
+ stateObject = _this$getState2[1];
2171
+ if (typeof stateValue === "undefined") {
2172
+ throw Error("State property ".concat(statePropName, " not defined for _condition command!"));
2173
+ }
2174
+ }
2175
+ var renderMap = new Map();
2176
+ renderMap.set("always", []);
2177
+ var children = ConditionalElement_toConsumableArray(this.children);
2178
+ children.forEach(function (conditionalChild) {
2179
+ var _if = conditionalChild.getAttribute('_if');
2180
+ if (_if) {
2181
+ var expectedValue = attributeValueToTypedValue(_if);
2182
+ if (!renderMap.has(expectedValue)) renderMap.set(expectedValue, []);
2183
+ renderMap.get(expectedValue).push(conditionalChild);
2184
+ } else {
2185
+ renderMap.get("always").push(conditionalChild);
2186
+ }
2187
+ });
2188
+ ConditionalElement_classPrivateFieldSet(_renderMap, this, renderMap);
2189
+ if (!isConditionStatic) {
2190
+ stateObject._stateManager.addConditionallyRenderingElements(statePropName, this);
2191
+ }
2192
+ this.render(true);
2193
+ ConditionalElement_classPrivateFieldSet(_wasMounted, this, true);
2194
+ }
2195
+ }]);
2196
+ }(ReactiveElementClass);
2197
+ return ConditionalElement;
2198
+ }
2199
+ ;// ./src/core/ReactiveCustomElement.js
2200
+ function ReactiveCustomElement_typeof(o) { "@babel/helpers - typeof"; return ReactiveCustomElement_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, ReactiveCustomElement_typeof(o); }
2201
+ function ReactiveCustomElement_createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = ReactiveCustomElement_unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
2202
+ function ReactiveCustomElement_unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return ReactiveCustomElement_arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? ReactiveCustomElement_arrayLikeToArray(r, a) : void 0; } }
2203
+ function ReactiveCustomElement_arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
2204
+ function ReactiveCustomElement_classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
2205
+ function ReactiveCustomElement_defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, ReactiveCustomElement_toPropertyKey(o.key), o); } }
2206
+ function ReactiveCustomElement_createClass(e, r, t) { return r && ReactiveCustomElement_defineProperties(e.prototype, r), t && ReactiveCustomElement_defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
2207
+ function ReactiveCustomElement_callSuper(t, o, e) { return o = ReactiveCustomElement_getPrototypeOf(o), ReactiveCustomElement_possibleConstructorReturn(t, ReactiveCustomElement_isNativeReflectConstruct() ? Reflect.construct(o, e || [], ReactiveCustomElement_getPrototypeOf(t).constructor) : o.apply(t, e)); }
2208
+ function ReactiveCustomElement_possibleConstructorReturn(t, e) { if (e && ("object" == ReactiveCustomElement_typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return ReactiveCustomElement_assertThisInitialized(t); }
2209
+ function ReactiveCustomElement_assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
2210
+ function ReactiveCustomElement_isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (ReactiveCustomElement_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
2211
+ function ReactiveCustomElement_getPrototypeOf(t) { return ReactiveCustomElement_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, ReactiveCustomElement_getPrototypeOf(t); }
2212
+ function ReactiveCustomElement_inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && ReactiveCustomElement_setPrototypeOf(t, e); }
2213
+ function ReactiveCustomElement_setPrototypeOf(t, e) { return ReactiveCustomElement_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, ReactiveCustomElement_setPrototypeOf(t, e); }
2214
+ function ReactiveCustomElement_classPrivateMethodInitSpec(e, a) { ReactiveCustomElement_checkPrivateRedeclaration(e, a), a.add(e); }
2215
+ function ReactiveCustomElement_classPrivateFieldInitSpec(e, t, a) { ReactiveCustomElement_checkPrivateRedeclaration(e, t), t.set(e, a); }
2216
+ function ReactiveCustomElement_checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
2217
+ function ReactiveCustomElement_defineProperty(e, r, t) { return (r = ReactiveCustomElement_toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
2218
+ function ReactiveCustomElement_toPropertyKey(t) { var i = ReactiveCustomElement_toPrimitive(t, "string"); return "symbol" == ReactiveCustomElement_typeof(i) ? i : i + ""; }
2219
+ function ReactiveCustomElement_toPrimitive(t, r) { if ("object" != ReactiveCustomElement_typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != ReactiveCustomElement_typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
2220
+ function ReactiveCustomElement_classPrivateFieldGet(s, a) { return s.get(ReactiveCustomElement_assertClassBrand(s, a)); }
2221
+ function ReactiveCustomElement_classPrivateFieldSet(s, a, r) { return s.set(ReactiveCustomElement_assertClassBrand(s, a), r), r; }
2222
+ function ReactiveCustomElement_assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
2223
+
2224
+
2225
+
2226
+
2227
+
2228
+
2229
+ function getReactiveCustomElementClass() {
2230
+ var appScope = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window;
2231
+ var ReactiveHTMLElement = extendElementClassWithReactiveElementClass(HTMLElement, appScope);
2232
+ var _wasMounted = /*#__PURE__*/new WeakMap();
2233
+ var _onMount = /*#__PURE__*/new WeakMap();
2234
+ var _beforeRender = /*#__PURE__*/new WeakMap();
2235
+ var _templateContent = /*#__PURE__*/new WeakMap();
2236
+ var _stylesheet = /*#__PURE__*/new WeakMap();
2237
+ var _globalStylesheet = /*#__PURE__*/new WeakMap();
2238
+ var _boundEventNames = /*#__PURE__*/new WeakMap();
2239
+ var _eventHandler = /*#__PURE__*/new WeakMap();
2240
+ var _ReactiveCustomElement_brand = /*#__PURE__*/new WeakSet();
2241
+ var ReactiveCustomElement = /*#__PURE__*/function (_ReactiveHTMLElement) {
2242
+ function ReactiveCustomElement() {
2243
+ var _this;
2244
+ var template = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
2245
+ var runtimeScript = arguments.length > 1 ? arguments[1] : undefined;
2246
+ var style = arguments.length > 2 ? arguments[2] : undefined;
2247
+ var globalStylesheet = arguments.length > 3 ? arguments[3] : undefined;
2248
+ ReactiveCustomElement_classCallCheck(this, ReactiveCustomElement);
2249
+ _this = ReactiveCustomElement_callSuper(this, ReactiveCustomElement);
2250
+ ReactiveCustomElement_classPrivateMethodInitSpec(_this, _ReactiveCustomElement_brand);
2251
+ // Should contain the "root" DOM element containing this element
2252
+ ReactiveCustomElement_defineProperty(_this, "host", null);
2253
+ ReactiveCustomElement_classPrivateFieldInitSpec(_this, _wasMounted, false);
2254
+ // Callback function for when the element is connected to a DOM tree on the page and rendered
2255
+ ReactiveCustomElement_classPrivateFieldInitSpec(_this, _onMount, void 0);
2256
+ // Callback function for when the element is connected to a DOM tree on the page, just before render
2257
+ ReactiveCustomElement_classPrivateFieldInitSpec(_this, _beforeRender, void 0);
2258
+ // Should only be used on non native custom elements
2259
+ ReactiveCustomElement_classPrivateFieldInitSpec(_this, _templateContent, void 0);
2260
+ ReactiveCustomElement_classPrivateFieldInitSpec(_this, _stylesheet, void 0);
2261
+ ReactiveCustomElement_classPrivateFieldInitSpec(_this, _globalStylesheet, void 0);
2262
+ // This will be an object where keys are element "ref" names,
2263
+ // and the value is either a "click" event handler (if it's a function),
2264
+ // or an object with DOM event names as keys and event handlers as functions.
2265
+ // Only relevant for non native custom elements - event bubbling from child elements will be used
2266
+ ReactiveCustomElement_defineProperty(_this, "events", void 0);
2267
+ // Name of events that are bound to the main event handler function
2268
+ ReactiveCustomElement_classPrivateFieldInitSpec(_this, _boundEventNames, []);
2269
+ // Main event handler function
2270
+ ReactiveCustomElement_classPrivateFieldInitSpec(_this, _eventHandler, void 0);
2271
+ var isFrameworkElement = _this.tagName === "CONDITIONAL-ELEMENT";
2272
+ if (isFrameworkElement) return ReactiveCustomElement_possibleConstructorReturn(_this);
2273
+ if (runtimeScript) {
2274
+ var dynamicRuntimeFn = new Function(runtimeScript.textContent);
2275
+ var runtime = dynamicRuntimeFn();
2276
+ ReactiveCustomElement_assertClassBrand(_ReactiveCustomElement_brand, _this, _setRuntime).call(_this, runtime);
2277
+ }
2278
+ if (style) {
2279
+ var stylesheet = new CSSStyleSheet();
2280
+ stylesheet.replaceSync(style);
2281
+ ReactiveCustomElement_classPrivateFieldSet(_stylesheet, _this, stylesheet);
2282
+ }
2283
+ if (globalStylesheet) {
2284
+ ReactiveCustomElement_classPrivateFieldSet(_globalStylesheet, _this, globalStylesheet);
2285
+ }
2286
+ ReactiveCustomElement_classPrivateFieldSet(_templateContent, _this, (template === null || template === void 0 ? void 0 : template.cloneNode(true)) || DEFAULT_TEMPLATE_DOM.cloneNode());
2287
+
2288
+ // Maps "ref names" to actual elements in the component DOM tree,
2289
+ // for fast access.
2290
+ _this.ref = {};
2291
+ return _this;
2292
+ }
2293
+ ReactiveCustomElement_inherits(ReactiveCustomElement, _ReactiveHTMLElement);
2294
+ return ReactiveCustomElement_createClass(ReactiveCustomElement, [{
2295
+ key: "setInitialState",
2296
+ value: function setInitialState(initState) {
2297
+ if (this.initialState) {
2298
+ Object.assign(this.initialState, initState);
2299
+ } else {
2300
+ this.initialState = initState;
2301
+ }
2302
+ }
2303
+ }, {
2304
+ key: "disconnectedCallback",
2305
+ value: function disconnectedCallback() {
2306
+ ReactiveCustomElement_assertClassBrand(_ReactiveCustomElement_brand, this, _unbindEvents).call(this);
2307
+ this.state = undefined;
2308
+ }
2309
+ }, {
2310
+ key: "connectedCallback",
2311
+ value: function connectedCallback() {
2312
+ var _this2 = this;
2313
+ if (ReactiveCustomElement_classPrivateFieldGet(_wasMounted, this)) return;
2314
+ // IMPORTANT: THIS *CAN* be NULL, DO NOT CHANGE IT!
2315
+ // It is part of the way a check is made to see if an element is part of ShadowDOM!
2316
+ // host will be null if the element is part of the DOM === the "root" custom element will have null in .host
2317
+ // THIS SHOULD BE THE FIRST THING THAT HAPPENS!
2318
+ this.host = this.getRootNode().host;
2319
+ ReactiveCustomElement_assertClassBrand(_ReactiveCustomElement_brand, this, _setActiveStateFromInitialState).call(this);
2320
+ ReactiveCustomElement_assertClassBrand(_ReactiveCustomElement_brand, this, _renderTemplate).call(this);
2321
+ var attributeNames = this.getAttributeNames();
2322
+ var _iterator = ReactiveCustomElement_createForOfIteratorHelper(attributeNames),
2323
+ _step;
2324
+ try {
2325
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
2326
+ var attrName = _step.value;
2327
+ var attrValue = this.getAttribute(attrName);
2328
+ // This also resolves "State attributes"
2329
+ this.initialSetAttribute(attrName, attrValue);
2330
+ }
2331
+ } catch (err) {
2332
+ _iterator.e(err);
2333
+ } finally {
2334
+ _iterator.f();
2335
+ }
2336
+ queueBindEvents(this, function () {
2337
+ return ReactiveCustomElement_assertClassBrand(_ReactiveCustomElement_brand, _this2, _bindEvents).call(_this2);
2338
+ });
2339
+ if (ReactiveCustomElement_classPrivateFieldGet(_beforeRender, this)) ReactiveCustomElement_classPrivateFieldGet(_beforeRender, this).call(this, appScope[GLOBAL_STATE_FUNCTION_NAME]());
2340
+ if (ReactiveCustomElement_classPrivateFieldGet(_onMount, this)) queueMicrotask(function () {
2341
+ return ReactiveCustomElement_classPrivateFieldGet(_onMount, _this2).call(_this2, appScope[GLOBAL_STATE_FUNCTION_NAME]());
2342
+ });
2343
+ ReactiveCustomElement_classPrivateFieldSet(_wasMounted, this, true);
2344
+ }
2345
+ }]);
2346
+ }(ReactiveHTMLElement);
2347
+ function _setRuntime(runtime) {
2348
+ var _this3 = this;
2349
+ if (runtime.events) {
2350
+ this.events = runtime.events;
2351
+ if (this.isConnected) {
2352
+ queueBindEvents(this, function () {
2353
+ return ReactiveCustomElement_assertClassBrand(_ReactiveCustomElement_brand, _this3, _bindEvents).call(_this3);
2354
+ });
2355
+ }
2356
+ }
2357
+ if (runtime.state) {
2358
+ this.setInitialState(runtime.state);
2359
+ // If this is not mounted yet, #setStateFromInitialState will be called from onConnected callback
2360
+ if (this.isConnected) ReactiveCustomElement_assertClassBrand(_ReactiveCustomElement_brand, this, _setActiveStateFromInitialState).call(this);
2361
+ }
2362
+ if (runtime.onMount) {
2363
+ ReactiveCustomElement_classPrivateFieldSet(_onMount, this, runtime.onMount);
2364
+ }
2365
+ if (runtime.beforeRender) {
2366
+ ReactiveCustomElement_classPrivateFieldSet(_beforeRender, this, runtime.beforeRender);
2367
+ }
2368
+ }
2369
+ function _setActiveStateFromInitialState() {
2370
+ if (!this.initialState) return;
2371
+ var initialState = this.initialState;
2372
+ if (initialState._stateManager) {
2373
+ this.state = initialState._stateManager.state;
2374
+ } else {
2375
+ this.state = new core_StateManager(initialState, undefined, undefined, false, appScope).state;
2376
+ }
2377
+ delete this.initialState;
2378
+ }
2379
+ function _renderTemplate() {
2380
+ if (appScope.SPROUT_CONFIG.useShadow) {
2381
+ var shadowRoot = this.attachShadow({
2382
+ mode: "open"
2383
+ });
2384
+ this.shadowRoot.adoptedStyleSheets = [];
2385
+ if (ReactiveCustomElement_classPrivateFieldGet(_globalStylesheet, this)) this.shadowRoot.adoptedStyleSheets.push(ReactiveCustomElement_classPrivateFieldGet(_globalStylesheet, this));
2386
+ if (ReactiveCustomElement_classPrivateFieldGet(_stylesheet, this)) this.shadowRoot.adoptedStyleSheets.push(ReactiveCustomElement_classPrivateFieldGet(_stylesheet, this));
2387
+ shadowRoot.appendChild(ReactiveCustomElement_classPrivateFieldGet(_templateContent, this));
2388
+ } else {
2389
+ var fragment = new DocumentFragment();
2390
+ fragment.appendChild(ReactiveCustomElement_classPrivateFieldGet(_templateContent, this));
2391
+ this.appendChild(fragment);
2392
+ }
2393
+ }
2394
+ function _unbindEvents() {
2395
+ var _this4 = this;
2396
+ if (!ReactiveCustomElement_classPrivateFieldGet(_boundEventNames, this).length) return;
2397
+ var thiselement = this;
2398
+ ReactiveCustomElement_classPrivateFieldGet(_boundEventNames, this).forEach(function (eventName) {
2399
+ thiselement.removeEventListener(eventName, ReactiveCustomElement_classPrivateFieldGet(_eventHandler, _this4), false);
2400
+ });
2401
+ }
2402
+ function _bindEvents() {
2403
+ var _this5 = this,
2404
+ _classPrivateFieldGet2;
2405
+ if (!this.events) return;
2406
+ var eventRefNames = Object.keys(this.events);
2407
+ var clickActions = {};
2408
+ var otherActions = {};
2409
+ eventRefNames.forEach(function (refName) {
2410
+ var value = _this5.events[refName];
2411
+ if (typeof value === 'function') {
2412
+ clickActions[refName] = value;
2413
+ } else if (ReactiveCustomElement_typeof(value) === 'object') {
2414
+ var _eventNames = Object.keys(value);
2415
+ _eventNames.forEach(function (eventName) {
2416
+ if (eventName === 'click') {
2417
+ clickActions[refName] = value[eventName];
2418
+ } else {
2419
+ if (!otherActions[eventName]) otherActions[eventName] = {};
2420
+ otherActions[eventName][refName] = value[eventName];
2421
+ }
2422
+ });
2423
+ }
2424
+ });
2425
+ var globalState = appScope[GLOBAL_STATE_FUNCTION_NAME]();
2426
+ ReactiveCustomElement_classPrivateFieldSet(_eventHandler, this, function (event) {
2427
+ var _this6 = this;
2428
+ var start = performance.now();
2429
+ var elementsPath = event.composedPath();
2430
+ var target;
2431
+ if (elementsPath) {
2432
+ target = elementsPath.find(function (element) {
2433
+ return element.hasAttribute && element.hasAttribute('ref') && element.getAttribute('ref') in _this6.events;
2434
+ });
2435
+ } else {
2436
+ target = event.target.hasAttribute && event.target.hasAttribute('ref') && event.target.getAttribute('ref') in this.events ? event.target : null;
2437
+ }
2438
+ if (target) {
2439
+ var ref = target.getAttribute('ref');
2440
+ var eventName = event.type;
2441
+ if (eventName === "click") {
2442
+ var clickEvent = typeof this.events[ref] === "function" ? this.events[ref] : null;
2443
+ clickEvent === null || clickEvent === void 0 || clickEvent.call(target, event, event.target, globalState);
2444
+ } else {
2445
+ var _this$events$ref$even;
2446
+ (_this$events$ref$even = this.events[ref][eventName]) === null || _this$events$ref$even === void 0 || _this$events$ref$even.call(target, event, event.target, globalState);
2447
+ }
2448
+ }
2449
+ console.log("Event ".concat(event.type, " took ").concat(performance.now() - start));
2450
+ });
2451
+ var thiselement = this;
2452
+ if (Object.keys(clickActions).length) {
2453
+ thiselement.addEventListener('click', ReactiveCustomElement_classPrivateFieldGet(_eventHandler, this));
2454
+ ReactiveCustomElement_classPrivateFieldGet(_boundEventNames, this).push('click');
2455
+ }
2456
+ var eventNames = Object.keys(otherActions);
2457
+ for (var _i = 0, _eventNames2 = eventNames; _i < _eventNames2.length; _i++) {
2458
+ var eventName = _eventNames2[_i];
2459
+ thiselement.addEventListener(eventName, ReactiveCustomElement_classPrivateFieldGet(_eventHandler, this));
2460
+ }
2461
+ (_classPrivateFieldGet2 = ReactiveCustomElement_classPrivateFieldGet(_boundEventNames, this)).push.apply(_classPrivateFieldGet2, eventNames);
2462
+ }
2463
+ return ReactiveCustomElement;
2464
+ }
2465
+ ;// ./src/core/index.js
2466
+ function core_typeof(o) { "@babel/helpers - typeof"; return core_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, core_typeof(o); }
2467
+ function core_defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, core_toPropertyKey(o.key), o); } }
2468
+ function core_createClass(e, r, t) { return r && core_defineProperties(e.prototype, r), t && core_defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
2469
+ function core_toPropertyKey(t) { var i = core_toPrimitive(t, "string"); return "symbol" == core_typeof(i) ? i : i + ""; }
2470
+ function core_toPrimitive(t, r) { if ("object" != core_typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != core_typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
2471
+ function core_classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
2472
+ function core_callSuper(t, o, e) { return o = core_getPrototypeOf(o), core_possibleConstructorReturn(t, core_isNativeReflectConstruct() ? Reflect.construct(o, e || [], core_getPrototypeOf(t).constructor) : o.apply(t, e)); }
2473
+ function core_possibleConstructorReturn(t, e) { if (e && ("object" == core_typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return core_assertThisInitialized(t); }
2474
+ function core_assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
2475
+ function core_isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (core_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
2476
+ function core_getPrototypeOf(t) { return core_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, core_getPrototypeOf(t); }
2477
+ function core_inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && core_setPrototypeOf(t, e); }
2478
+ function core_setPrototypeOf(t, e) { return core_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, core_setPrototypeOf(t, e); }
2479
+
2480
+
2481
+
2482
+
2483
+
2484
+
2485
+
2486
+
2487
+
2488
+ var allowAppScopeAccess = document.currentScript.hasAttribute("allowappscopeaccess");
2489
+ var stateClass = window.StateManager;
2490
+ globalThis.SproutInitApp = function (appName) {
2491
+ var appScope = function () {
2492
+ var _window;
2493
+ return {
2494
+ window: window,
2495
+ document: (_window = window) === null || _window === void 0 ? void 0 : _window.document
2496
+ };
2497
+ }(window);
2498
+ var config = {
2499
+ useShadow: true,
2500
+ // Always use shadow DOM for now, may add configurability later
2501
+ allowAppScopeAccess: allowAppScopeAccess
2502
+ };
2503
+ if (config.allowAppScopeAccess) {
2504
+ Object.defineProperty(globalThis, "sproutApps", {
2505
+ value: {},
2506
+ writable: false
2507
+ });
2508
+ Object.defineProperty(globalThis.sproutApps, appName, {
2509
+ value: appScope,
2510
+ writable: false
2511
+ });
2512
+ }
2513
+ appScope.SPROUT_CONFIG = Object.seal(config);
2514
+
2515
+ // Prevent "hasOwnProperty" shenanigans
2516
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
2517
+ setHiddenProperty(Object.prototype, "hasOwnProperty", hasOwnProperty);
2518
+ appScope[GLOBAL_STATE_FUNCTION_NAME] = function () {
2519
+ return {};
2520
+ };
2521
+ // If initialState is passed - also sets it to global state
2522
+ appScope.setGlobalState = function () {
2523
+ var initialState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2524
+ var globalState = new core_StateManager(initialState, undefined, undefined, true, appScope).state;
2525
+ var globalStateVarName = GLOBAL_STATE_VAR_NAME;
2526
+ Object.defineProperty(appScope, globalStateVarName, {
2527
+ value: globalState,
2528
+ writable: DEBUG_MODE ? true : false,
2529
+ configurable: false
2530
+ });
2531
+ Object.defineProperty(appScope, GLOBAL_STATE_FUNCTION_NAME, {
2532
+ value: function value() {
2533
+ return appScope[globalStateVarName];
2534
+ }
2535
+ });
2536
+ };
2537
+ var HTML_REACTIVE_ELEMENT_CLASSES = {};
2538
+ HTML_ELEMENTS_CLASSES_MAP.forEach(function (elementDefinition) {
2539
+ return HTML_REACTIVE_ELEMENT_CLASSES[elementDefinition.element] = extendElementClassWithReactiveElementClass(elementDefinition["class"], appScope, true);
2540
+ });
2541
+ appScope.ReactiveCustomElement = getReactiveCustomElementClass(appScope);
2542
+
2543
+ // Extend specific HTMLElement classes to enable reactivity (use it by adding an "is" attribute to an element)
2544
+ HTML_ELEMENTS_CLASSES_MAP.forEach(function (itemDefinition) {
2545
+ customElements.define("reactive-".concat(itemDefinition.element),
2546
+ // extendElementClassWithReactiveElementClass(itemDefinition.class, appScope, true),
2547
+ HTML_REACTIVE_ELEMENT_CLASSES[itemDefinition.element], {
2548
+ "extends": itemDefinition.element
2549
+ });
2550
+ });
2551
+ var ReactiveHeadingClass = extendElementClassWithReactiveElementClass(HTMLHeadingElement, appScope);
2552
+ ["h1", "h2", "h3", "h4", "h5", "h6"].forEach(function (hTag) {
2553
+ customElements.define("reactive-".concat(hTag), /*#__PURE__*/function (_ReactiveHeadingClass) {
2554
+ function _class() {
2555
+ core_classCallCheck(this, _class);
2556
+ return core_callSuper(this, _class, arguments);
2557
+ }
2558
+ core_inherits(_class, _ReactiveHeadingClass);
2559
+ return core_createClass(_class);
2560
+ }(ReactiveHeadingClass), {
2561
+ "extends": hTag
2562
+ });
2563
+ });
2564
+ var ReactiveConditionalElementClass = extendElementClassWithReactiveElementClass(HTMLElement, appScope);
2565
+ var ConditionalElementClass = getConditionalElementClass(ReactiveConditionalElementClass);
2566
+ customElements.define('conditional-render', ConditionalElementClass);
2567
+ return function () {
2568
+ build(appScope, appName);
2569
+ }.bind(appScope);
2570
+ };
2571
+ /******/ return __webpack_exports__;
2572
+ /******/ })()
2573
+ ;
2574
+ });
2575
+ //# sourceMappingURL=sprout_core.js.map