proto-ikons-wc 0.0.146 → 0.0.148

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.
@@ -1,1704 +0,0 @@
1
- 'use strict';
2
-
3
- function _interopNamespace(e) {
4
- if (e && e.__esModule) return e;
5
- var n = Object.create(null);
6
- if (e) {
7
- Object.keys(e).forEach(function (k) {
8
- if (k !== 'default') {
9
- var d = Object.getOwnPropertyDescriptor(e, k);
10
- Object.defineProperty(n, k, d.get ? d : {
11
- enumerable: true,
12
- get: function () {
13
- return e[k];
14
- }
15
- });
16
- }
17
- });
18
- }
19
- n['default'] = e;
20
- return Object.freeze(n);
21
- }
22
-
23
- const NAMESPACE = 'proto-ikons-wc';
24
-
25
- /**
26
- * Virtual DOM patching algorithm based on Snabbdom by
27
- * Simon Friis Vindum (@paldepind)
28
- * Licensed under the MIT License
29
- * https://github.com/snabbdom/snabbdom/blob/master/LICENSE
30
- *
31
- * Modified for Stencil's renderer and slot projection
32
- */
33
- let hostTagName;
34
- let isSvgMode = false;
35
- let queuePending = false;
36
- const createTime = (fnName, tagName = '') => {
37
- {
38
- return () => {
39
- return;
40
- };
41
- }
42
- };
43
- const uniqueTime = (key, measureText) => {
44
- {
45
- return () => {
46
- return;
47
- };
48
- }
49
- };
50
- const HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
51
- /**
52
- * Constant for styles to be globally applied to `slot-fb` elements for pseudo-slot behavior.
53
- *
54
- * Two cascading rules must be used instead of a `:not()` selector due to Stencil browser
55
- * support as of Stencil v4.
56
- */
57
- const SLOT_FB_CSS = 'slot-fb{display:contents}slot-fb[hidden]{display:none}';
58
- const XLINK_NS = 'http://www.w3.org/1999/xlink';
59
- /**
60
- * Default style mode id
61
- */
62
- /**
63
- * Reusable empty obj/array
64
- * Don't add values to these!!
65
- */
66
- const EMPTY_OBJ = {};
67
- /**
68
- * Namespaces
69
- */
70
- const SVG_NS = 'http://www.w3.org/2000/svg';
71
- const HTML_NS = 'http://www.w3.org/1999/xhtml';
72
- /**
73
- * Check whether a value is a 'complex type', defined here as an object or a
74
- * function.
75
- *
76
- * @param o the value to check
77
- * @returns whether it's a complex type or not
78
- */
79
- const isComplexType = (o) => {
80
- // https://jsperf.com/typeof-fn-object/5
81
- o = typeof o;
82
- return o === 'object' || o === 'function';
83
- };
84
- /**
85
- * Helper method for querying a `meta` tag that contains a nonce value
86
- * out of a DOM's head.
87
- *
88
- * @param doc The DOM containing the `head` to query against
89
- * @returns The content of the meta tag representing the nonce value, or `undefined` if no tag
90
- * exists or the tag has no content.
91
- */
92
- function queryNonceMetaTagContent(doc) {
93
- var _a, _b, _c;
94
- return (_c = (_b = (_a = doc.head) === null || _a === void 0 ? void 0 : _a.querySelector('meta[name="csp-nonce"]')) === null || _b === void 0 ? void 0 : _b.getAttribute('content')) !== null && _c !== void 0 ? _c : undefined;
95
- }
96
- /**
97
- * Production h() function based on Preact by
98
- * Jason Miller (@developit)
99
- * Licensed under the MIT License
100
- * https://github.com/developit/preact/blob/master/LICENSE
101
- *
102
- * Modified for Stencil's compiler and vdom
103
- */
104
- // export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, child?: d.ChildType): d.VNode;
105
- // export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, ...children: d.ChildType[]): d.VNode;
106
- const h = (nodeName, vnodeData, ...children) => {
107
- let child = null;
108
- let key = null;
109
- let simple = false;
110
- let lastSimple = false;
111
- const vNodeChildren = [];
112
- const walk = (c) => {
113
- for (let i = 0; i < c.length; i++) {
114
- child = c[i];
115
- if (Array.isArray(child)) {
116
- walk(child);
117
- }
118
- else if (child != null && typeof child !== 'boolean') {
119
- if ((simple = typeof nodeName !== 'function' && !isComplexType(child))) {
120
- child = String(child);
121
- }
122
- if (simple && lastSimple) {
123
- // If the previous child was simple (string), we merge both
124
- vNodeChildren[vNodeChildren.length - 1].$text$ += child;
125
- }
126
- else {
127
- // Append a new vNode, if it's text, we create a text vNode
128
- vNodeChildren.push(simple ? newVNode(null, child) : child);
129
- }
130
- lastSimple = simple;
131
- }
132
- }
133
- };
134
- walk(children);
135
- if (vnodeData) {
136
- if (vnodeData.key) {
137
- key = vnodeData.key;
138
- }
139
- // normalize class / className attributes
140
- {
141
- const classData = vnodeData.className || vnodeData.class;
142
- if (classData) {
143
- vnodeData.class =
144
- typeof classData !== 'object'
145
- ? classData
146
- : Object.keys(classData)
147
- .filter((k) => classData[k])
148
- .join(' ');
149
- }
150
- }
151
- }
152
- const vnode = newVNode(nodeName, null);
153
- vnode.$attrs$ = vnodeData;
154
- if (vNodeChildren.length > 0) {
155
- vnode.$children$ = vNodeChildren;
156
- }
157
- {
158
- vnode.$key$ = key;
159
- }
160
- return vnode;
161
- };
162
- /**
163
- * A utility function for creating a virtual DOM node from a tag and some
164
- * possible text content.
165
- *
166
- * @param tag the tag for this element
167
- * @param text possible text content for the node
168
- * @returns a newly-minted virtual DOM node
169
- */
170
- const newVNode = (tag, text) => {
171
- const vnode = {
172
- $flags$: 0,
173
- $tag$: tag,
174
- $text$: text,
175
- $elm$: null,
176
- $children$: null,
177
- };
178
- {
179
- vnode.$attrs$ = null;
180
- }
181
- {
182
- vnode.$key$ = null;
183
- }
184
- return vnode;
185
- };
186
- const Host = {};
187
- /**
188
- * Check whether a given node is a Host node or not
189
- *
190
- * @param node the virtual DOM node to check
191
- * @returns whether it's a Host node or not
192
- */
193
- const isHost = (node) => node && node.$tag$ === Host;
194
- /**
195
- * Parse a new property value for a given property type.
196
- *
197
- * While the prop value can reasonably be expected to be of `any` type as far as TypeScript's type checker is concerned,
198
- * it is not safe to assume that the string returned by evaluating `typeof propValue` matches:
199
- * 1. `any`, the type given to `propValue` in the function signature
200
- * 2. the type stored from `propType`.
201
- *
202
- * This function provides the capability to parse/coerce a property's value to potentially any other JavaScript type.
203
- *
204
- * Property values represented in TSX preserve their type information. In the example below, the number 0 is passed to
205
- * a component. This `propValue` will preserve its type information (`typeof propValue === 'number'`). Note that is
206
- * based on the type of the value being passed in, not the type declared of the class member decorated with `@Prop`.
207
- * ```tsx
208
- * <my-cmp prop-val={0}></my-cmp>
209
- * ```
210
- *
211
- * HTML prop values on the other hand, will always a string
212
- *
213
- * @param propValue the new value to coerce to some type
214
- * @param propType the type of the prop, expressed as a binary number
215
- * @returns the parsed/coerced value
216
- */
217
- const parsePropertyValue = (propValue, propType) => {
218
- // ensure this value is of the correct prop type
219
- if (propValue != null && !isComplexType(propValue)) {
220
- if (propType & 4 /* MEMBER_FLAGS.Boolean */) {
221
- // per the HTML spec, any string value means it is a boolean true value
222
- // but we'll cheat here and say that the string "false" is the boolean false
223
- return propValue === 'false' ? false : propValue === '' || !!propValue;
224
- }
225
- if (propType & 2 /* MEMBER_FLAGS.Number */) {
226
- // force it to be a number
227
- return parseFloat(propValue);
228
- }
229
- if (propType & 1 /* MEMBER_FLAGS.String */) {
230
- // could have been passed as a number or boolean
231
- // but we still want it as a string
232
- return String(propValue);
233
- }
234
- // redundant return here for better minification
235
- return propValue;
236
- }
237
- // not sure exactly what type we want
238
- // so no need to change to a different type
239
- return propValue;
240
- };
241
- /**
242
- * Helper function to create & dispatch a custom Event on a provided target
243
- * @param elm the target of the Event
244
- * @param name the name to give the custom Event
245
- * @param opts options for configuring a custom Event
246
- * @returns the custom Event
247
- */
248
- const emitEvent = (elm, name, opts) => {
249
- const ev = plt.ce(name, opts);
250
- elm.dispatchEvent(ev);
251
- return ev;
252
- };
253
- const rootAppliedStyles = /*@__PURE__*/ new WeakMap();
254
- const registerStyle = (scopeId, cssText, allowCS) => {
255
- let style = styles.get(scopeId);
256
- if (supportsConstructableStylesheets && allowCS) {
257
- style = (style || new CSSStyleSheet());
258
- if (typeof style === 'string') {
259
- style = cssText;
260
- }
261
- else {
262
- style.replaceSync(cssText);
263
- }
264
- }
265
- else {
266
- style = cssText;
267
- }
268
- styles.set(scopeId, style);
269
- };
270
- const addStyle = (styleContainerNode, cmpMeta, mode) => {
271
- var _a;
272
- const scopeId = getScopeId(cmpMeta);
273
- const style = styles.get(scopeId);
274
- // if an element is NOT connected then getRootNode() will return the wrong root node
275
- // so the fallback is to always use the document for the root node in those cases
276
- styleContainerNode = styleContainerNode.nodeType === 11 /* NODE_TYPE.DocumentFragment */ ? styleContainerNode : doc;
277
- if (style) {
278
- if (typeof style === 'string') {
279
- styleContainerNode = styleContainerNode.head || styleContainerNode;
280
- let appliedStyles = rootAppliedStyles.get(styleContainerNode);
281
- let styleElm;
282
- if (!appliedStyles) {
283
- rootAppliedStyles.set(styleContainerNode, (appliedStyles = new Set()));
284
- }
285
- if (!appliedStyles.has(scopeId)) {
286
- {
287
- styleElm = doc.createElement('style');
288
- styleElm.innerHTML = style;
289
- // Apply CSP nonce to the style tag if it exists
290
- const nonce = (_a = plt.$nonce$) !== null && _a !== void 0 ? _a : queryNonceMetaTagContent(doc);
291
- if (nonce != null) {
292
- styleElm.setAttribute('nonce', nonce);
293
- }
294
- styleContainerNode.insertBefore(styleElm, styleContainerNode.querySelector('link'));
295
- }
296
- // Add styles for `slot-fb` elements if we're using slots outside the Shadow DOM
297
- if (cmpMeta.$flags$ & 4 /* CMP_FLAGS.hasSlotRelocation */) {
298
- styleElm.innerHTML += SLOT_FB_CSS;
299
- }
300
- if (appliedStyles) {
301
- appliedStyles.add(scopeId);
302
- }
303
- }
304
- }
305
- else if (!styleContainerNode.adoptedStyleSheets.includes(style)) {
306
- styleContainerNode.adoptedStyleSheets = [...styleContainerNode.adoptedStyleSheets, style];
307
- }
308
- }
309
- return scopeId;
310
- };
311
- const attachStyles = (hostRef) => {
312
- const cmpMeta = hostRef.$cmpMeta$;
313
- const elm = hostRef.$hostElement$;
314
- const endAttachStyles = createTime('attachStyles', cmpMeta.$tagName$);
315
- addStyle(elm.getRootNode(), cmpMeta);
316
- endAttachStyles();
317
- };
318
- const getScopeId = (cmp, mode) => 'sc-' + (cmp.$tagName$);
319
- /**
320
- * Production setAccessor() function based on Preact by
321
- * Jason Miller (@developit)
322
- * Licensed under the MIT License
323
- * https://github.com/developit/preact/blob/master/LICENSE
324
- *
325
- * Modified for Stencil's compiler and vdom
326
- */
327
- /**
328
- * When running a VDom render set properties present on a VDom node onto the
329
- * corresponding HTML element.
330
- *
331
- * Note that this function has special functionality for the `class`,
332
- * `style`, `key`, and `ref` attributes, as well as event handlers (like
333
- * `onClick`, etc). All others are just passed through as-is.
334
- *
335
- * @param elm the HTMLElement onto which attributes should be set
336
- * @param memberName the name of the attribute to set
337
- * @param oldValue the old value for the attribute
338
- * @param newValue the new value for the attribute
339
- * @param isSvg whether we're in an svg context or not
340
- * @param flags bitflags for Vdom variables
341
- */
342
- const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
343
- if (oldValue !== newValue) {
344
- let isProp = isMemberInElement(elm, memberName);
345
- let ln = memberName.toLowerCase();
346
- if (memberName === 'class') {
347
- const classList = elm.classList;
348
- const oldClasses = parseClassList(oldValue);
349
- const newClasses = parseClassList(newValue);
350
- classList.remove(...oldClasses.filter((c) => c && !newClasses.includes(c)));
351
- classList.add(...newClasses.filter((c) => c && !oldClasses.includes(c)));
352
- }
353
- else if (memberName === 'key')
354
- ;
355
- else {
356
- // Set property if it exists and it's not a SVG
357
- const isComplex = isComplexType(newValue);
358
- if ((isProp || (isComplex && newValue !== null)) && !isSvg) {
359
- try {
360
- if (!elm.tagName.includes('-')) {
361
- const n = newValue == null ? '' : newValue;
362
- // Workaround for Safari, moving the <input> caret when re-assigning the same valued
363
- if (memberName === 'list') {
364
- isProp = false;
365
- }
366
- else if (oldValue == null || elm[memberName] != n) {
367
- elm[memberName] = n;
368
- }
369
- }
370
- else {
371
- elm[memberName] = newValue;
372
- }
373
- }
374
- catch (e) {
375
- /**
376
- * in case someone tries to set a read-only property, e.g. "namespaceURI", we just ignore it
377
- */
378
- }
379
- }
380
- /**
381
- * Need to manually update attribute if:
382
- * - memberName is not an attribute
383
- * - if we are rendering the host element in order to reflect attribute
384
- * - if it's a SVG, since properties might not work in <svg>
385
- * - if the newValue is null/undefined or 'false'.
386
- */
387
- let xlink = false;
388
- {
389
- if (ln !== (ln = ln.replace(/^xlink\:?/, ''))) {
390
- memberName = ln;
391
- xlink = true;
392
- }
393
- }
394
- if (newValue == null || newValue === false) {
395
- if (newValue !== false || elm.getAttribute(memberName) === '') {
396
- if (xlink) {
397
- elm.removeAttributeNS(XLINK_NS, memberName);
398
- }
399
- else {
400
- elm.removeAttribute(memberName);
401
- }
402
- }
403
- }
404
- else if ((!isProp || flags & 4 /* VNODE_FLAGS.isHost */ || isSvg) && !isComplex) {
405
- newValue = newValue === true ? '' : newValue;
406
- if (xlink) {
407
- elm.setAttributeNS(XLINK_NS, memberName, newValue);
408
- }
409
- else {
410
- elm.setAttribute(memberName, newValue);
411
- }
412
- }
413
- }
414
- }
415
- };
416
- const parseClassListRegex = /\s/;
417
- /**
418
- * Parsed a string of classnames into an array
419
- * @param value className string, e.g. "foo bar baz"
420
- * @returns list of classes, e.g. ["foo", "bar", "baz"]
421
- */
422
- const parseClassList = (value) => (!value ? [] : value.split(parseClassListRegex));
423
- const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
424
- // if the element passed in is a shadow root, which is a document fragment
425
- // then we want to be adding attrs/props to the shadow root's "host" element
426
- // if it's not a shadow root, then we add attrs/props to the same element
427
- const elm = newVnode.$elm$.nodeType === 11 /* NODE_TYPE.DocumentFragment */ && newVnode.$elm$.host
428
- ? newVnode.$elm$.host
429
- : newVnode.$elm$;
430
- const oldVnodeAttrs = (oldVnode && oldVnode.$attrs$) || EMPTY_OBJ;
431
- const newVnodeAttrs = newVnode.$attrs$ || EMPTY_OBJ;
432
- {
433
- // remove attributes no longer present on the vnode by setting them to undefined
434
- for (memberName of sortedAttrNames(Object.keys(oldVnodeAttrs))) {
435
- if (!(memberName in newVnodeAttrs)) {
436
- setAccessor(elm, memberName, oldVnodeAttrs[memberName], undefined, isSvgMode, newVnode.$flags$);
437
- }
438
- }
439
- }
440
- // add new & update changed attributes
441
- for (memberName of sortedAttrNames(Object.keys(newVnodeAttrs))) {
442
- setAccessor(elm, memberName, oldVnodeAttrs[memberName], newVnodeAttrs[memberName], isSvgMode, newVnode.$flags$);
443
- }
444
- };
445
- /**
446
- * Sort a list of attribute names to ensure that all the attribute names which
447
- * are _not_ `"ref"` come before `"ref"`. Preserve the order of the non-ref
448
- * attributes.
449
- *
450
- * **Note**: if the supplied attributes do not include `'ref'` then the same
451
- * (by reference) array will be returned without modification.
452
- *
453
- * @param attrNames attribute names to sort
454
- * @returns a list of attribute names, sorted if they include `"ref"`
455
- */
456
- function sortedAttrNames(attrNames) {
457
- return attrNames.includes('ref')
458
- ? // we need to sort these to ensure that `'ref'` is the last attr
459
- [...attrNames.filter((attr) => attr !== 'ref'), 'ref']
460
- : // no need to sort, return the original array
461
- attrNames;
462
- }
463
- /**
464
- * Create a DOM Node corresponding to one of the children of a given VNode.
465
- *
466
- * @param oldParentVNode the parent VNode from the previous render
467
- * @param newParentVNode the parent VNode from the current render
468
- * @param childIndex the index of the VNode, in the _new_ parent node's
469
- * children, for which we will create a new DOM node
470
- * @param parentElm the parent DOM node which our new node will be a child of
471
- * @returns the newly created node
472
- */
473
- const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
474
- // tslint:disable-next-line: prefer-const
475
- const newVNode = newParentVNode.$children$[childIndex];
476
- let i = 0;
477
- let elm;
478
- let childNode;
479
- if (newVNode.$text$ !== null) {
480
- // create text node
481
- elm = newVNode.$elm$ = doc.createTextNode(newVNode.$text$);
482
- }
483
- else {
484
- if (!isSvgMode) {
485
- isSvgMode = newVNode.$tag$ === 'svg';
486
- }
487
- // create element
488
- elm = newVNode.$elm$ = (doc.createElementNS(isSvgMode ? SVG_NS : HTML_NS, newVNode.$tag$)
489
- );
490
- if (isSvgMode && newVNode.$tag$ === 'foreignObject') {
491
- isSvgMode = false;
492
- }
493
- // add css classes, attrs, props, listeners, etc.
494
- {
495
- updateElement(null, newVNode, isSvgMode);
496
- }
497
- if (newVNode.$children$) {
498
- for (i = 0; i < newVNode.$children$.length; ++i) {
499
- // create the node
500
- childNode = createElm(oldParentVNode, newVNode, i);
501
- // return node could have been null
502
- if (childNode) {
503
- // append our new node
504
- elm.appendChild(childNode);
505
- }
506
- }
507
- }
508
- {
509
- if (newVNode.$tag$ === 'svg') {
510
- // Only reset the SVG context when we're exiting <svg> element
511
- isSvgMode = false;
512
- }
513
- else if (elm.tagName === 'foreignObject') {
514
- // Reenter SVG context when we're exiting <foreignObject> element
515
- isSvgMode = true;
516
- }
517
- }
518
- }
519
- // This needs to always happen so we can hide nodes that are projected
520
- // to another component but don't end up in a slot
521
- elm['s-hn'] = hostTagName;
522
- return elm;
523
- };
524
- /**
525
- * Create DOM nodes corresponding to a list of {@link d.Vnode} objects and
526
- * add them to the DOM in the appropriate place.
527
- *
528
- * @param parentElm the DOM node which should be used as a parent for the new
529
- * DOM nodes
530
- * @param before a child of the `parentElm` which the new children should be
531
- * inserted before (optional)
532
- * @param parentVNode the parent virtual DOM node
533
- * @param vnodes the new child virtual DOM nodes to produce DOM nodes for
534
- * @param startIdx the index in the child virtual DOM nodes at which to start
535
- * creating DOM nodes (inclusive)
536
- * @param endIdx the index in the child virtual DOM nodes at which to stop
537
- * creating DOM nodes (inclusive)
538
- */
539
- const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) => {
540
- let containerElm = (parentElm);
541
- let childNode;
542
- for (; startIdx <= endIdx; ++startIdx) {
543
- if (vnodes[startIdx]) {
544
- childNode = createElm(null, parentVNode, startIdx);
545
- if (childNode) {
546
- vnodes[startIdx].$elm$ = childNode;
547
- containerElm.insertBefore(childNode, before);
548
- }
549
- }
550
- }
551
- };
552
- /**
553
- * Remove the DOM elements corresponding to a list of {@link d.VNode} objects.
554
- * This can be used to, for instance, clean up after a list of children which
555
- * should no longer be shown.
556
- *
557
- * This function also handles some of Stencil's slot relocation logic.
558
- *
559
- * @param vnodes a list of virtual DOM nodes to remove
560
- * @param startIdx the index at which to start removing nodes (inclusive)
561
- * @param endIdx the index at which to stop removing nodes (inclusive)
562
- */
563
- const removeVnodes = (vnodes, startIdx, endIdx) => {
564
- for (let index = startIdx; index <= endIdx; ++index) {
565
- const vnode = vnodes[index];
566
- if (vnode) {
567
- const elm = vnode.$elm$;
568
- if (elm) {
569
- // remove the vnode's element from the dom
570
- elm.remove();
571
- }
572
- }
573
- }
574
- };
575
- /**
576
- * Reconcile the children of a new VNode with the children of an old VNode by
577
- * traversing the two collections of children, identifying nodes that are
578
- * conserved or changed, calling out to `patch` to make any necessary
579
- * updates to the DOM, and rearranging DOM nodes as needed.
580
- *
581
- * The algorithm for reconciling children works by analyzing two 'windows' onto
582
- * the two arrays of children (`oldCh` and `newCh`). We keep track of the
583
- * 'windows' by storing start and end indices and references to the
584
- * corresponding array entries. Initially the two 'windows' are basically equal
585
- * to the entire array, but we progressively narrow the windows until there are
586
- * no children left to update by doing the following:
587
- *
588
- * 1. Skip any `null` entries at the beginning or end of the two arrays, so
589
- * that if we have an initial array like the following we'll end up dealing
590
- * only with a window bounded by the highlighted elements:
591
- *
592
- * [null, null, VNode1 , ... , VNode2, null, null]
593
- * ^^^^^^ ^^^^^^
594
- *
595
- * 2. Check to see if the elements at the head and tail positions are equal
596
- * across the windows. This will basically detect elements which haven't
597
- * been added, removed, or changed position, i.e. if you had the following
598
- * VNode elements (represented as HTML):
599
- *
600
- * oldVNode: `<div><p><span>HEY</span></p></div>`
601
- * newVNode: `<div><p><span>THERE</span></p></div>`
602
- *
603
- * Then when comparing the children of the `<div>` tag we check the equality
604
- * of the VNodes corresponding to the `<p>` tags and, since they are the
605
- * same tag in the same position, we'd be able to avoid completely
606
- * re-rendering the subtree under them with a new DOM element and would just
607
- * call out to `patch` to handle reconciling their children and so on.
608
- *
609
- * 3. Check, for both windows, to see if the element at the beginning of the
610
- * window corresponds to the element at the end of the other window. This is
611
- * a heuristic which will let us identify _some_ situations in which
612
- * elements have changed position, for instance it _should_ detect that the
613
- * children nodes themselves have not changed but merely moved in the
614
- * following example:
615
- *
616
- * oldVNode: `<div><element-one /><element-two /></div>`
617
- * newVNode: `<div><element-two /><element-one /></div>`
618
- *
619
- * If we find cases like this then we also need to move the concrete DOM
620
- * elements corresponding to the moved children to write the re-order to the
621
- * DOM.
622
- *
623
- * 4. Finally, if VNodes have the `key` attribute set on them we check for any
624
- * nodes in the old children which have the same key as the first element in
625
- * our window on the new children. If we find such a node we handle calling
626
- * out to `patch`, moving relevant DOM nodes, and so on, in accordance with
627
- * what we find.
628
- *
629
- * Finally, once we've narrowed our 'windows' to the point that either of them
630
- * collapse (i.e. they have length 0) we then handle any remaining VNode
631
- * insertion or deletion that needs to happen to get a DOM state that correctly
632
- * reflects the new child VNodes. If, for instance, after our window on the old
633
- * children has collapsed we still have more nodes on the new children that
634
- * we haven't dealt with yet then we need to add them, or if the new children
635
- * collapse but we still have unhandled _old_ children then we need to make
636
- * sure the corresponding DOM nodes are removed.
637
- *
638
- * @param parentElm the node into which the parent VNode is rendered
639
- * @param oldCh the old children of the parent node
640
- * @param newVNode the new VNode which will replace the parent
641
- * @param newCh the new children of the parent node
642
- * @param isInitialRender whether or not this is the first render of the vdom
643
- */
644
- const updateChildren = (parentElm, oldCh, newVNode, newCh, isInitialRender = false) => {
645
- let oldStartIdx = 0;
646
- let newStartIdx = 0;
647
- let idxInOld = 0;
648
- let i = 0;
649
- let oldEndIdx = oldCh.length - 1;
650
- let oldStartVnode = oldCh[0];
651
- let oldEndVnode = oldCh[oldEndIdx];
652
- let newEndIdx = newCh.length - 1;
653
- let newStartVnode = newCh[0];
654
- let newEndVnode = newCh[newEndIdx];
655
- let node;
656
- let elmToMove;
657
- while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
658
- if (oldStartVnode == null) {
659
- // VNode might have been moved left
660
- oldStartVnode = oldCh[++oldStartIdx];
661
- }
662
- else if (oldEndVnode == null) {
663
- oldEndVnode = oldCh[--oldEndIdx];
664
- }
665
- else if (newStartVnode == null) {
666
- newStartVnode = newCh[++newStartIdx];
667
- }
668
- else if (newEndVnode == null) {
669
- newEndVnode = newCh[--newEndIdx];
670
- }
671
- else if (isSameVnode(oldStartVnode, newStartVnode, isInitialRender)) {
672
- // if the start nodes are the same then we should patch the new VNode
673
- // onto the old one, and increment our `newStartIdx` and `oldStartIdx`
674
- // indices to reflect that. We don't need to move any DOM Nodes around
675
- // since things are matched up in order.
676
- patch(oldStartVnode, newStartVnode, isInitialRender);
677
- oldStartVnode = oldCh[++oldStartIdx];
678
- newStartVnode = newCh[++newStartIdx];
679
- }
680
- else if (isSameVnode(oldEndVnode, newEndVnode, isInitialRender)) {
681
- // likewise, if the end nodes are the same we patch new onto old and
682
- // decrement our end indices, and also likewise in this case we don't
683
- // need to move any DOM Nodes.
684
- patch(oldEndVnode, newEndVnode, isInitialRender);
685
- oldEndVnode = oldCh[--oldEndIdx];
686
- newEndVnode = newCh[--newEndIdx];
687
- }
688
- else if (isSameVnode(oldStartVnode, newEndVnode, isInitialRender)) {
689
- patch(oldStartVnode, newEndVnode, isInitialRender);
690
- // We need to move the element for `oldStartVnode` into a position which
691
- // will be appropriate for `newEndVnode`. For this we can use
692
- // `.insertBefore` and `oldEndVnode.$elm$.nextSibling`. If there is a
693
- // sibling for `oldEndVnode.$elm$` then we want to move the DOM node for
694
- // `oldStartVnode` between `oldEndVnode` and it's sibling, like so:
695
- //
696
- // <old-start-node />
697
- // <some-intervening-node />
698
- // <old-end-node />
699
- // <!-- -> <-- `oldStartVnode.$elm$` should be inserted here
700
- // <next-sibling />
701
- //
702
- // If instead `oldEndVnode.$elm$` has no sibling then we just want to put
703
- // the node for `oldStartVnode` at the end of the children of
704
- // `parentElm`. Luckily, `Node.nextSibling` will return `null` if there
705
- // aren't any siblings, and passing `null` to `Node.insertBefore` will
706
- // append it to the children of the parent element.
707
- parentElm.insertBefore(oldStartVnode.$elm$, oldEndVnode.$elm$.nextSibling);
708
- oldStartVnode = oldCh[++oldStartIdx];
709
- newEndVnode = newCh[--newEndIdx];
710
- }
711
- else if (isSameVnode(oldEndVnode, newStartVnode, isInitialRender)) {
712
- patch(oldEndVnode, newStartVnode, isInitialRender);
713
- // We've already checked above if `oldStartVnode` and `newStartVnode` are
714
- // the same node, so since we're here we know that they are not. Thus we
715
- // can move the element for `oldEndVnode` _before_ the element for
716
- // `oldStartVnode`, leaving `oldStartVnode` to be reconciled in the
717
- // future.
718
- parentElm.insertBefore(oldEndVnode.$elm$, oldStartVnode.$elm$);
719
- oldEndVnode = oldCh[--oldEndIdx];
720
- newStartVnode = newCh[++newStartIdx];
721
- }
722
- else {
723
- // Here we do some checks to match up old and new nodes based on the
724
- // `$key$` attribute, which is set by putting a `key="my-key"` attribute
725
- // in the JSX for a DOM element in the implementation of a Stencil
726
- // component.
727
- //
728
- // First we check to see if there are any nodes in the array of old
729
- // children which have the same key as the first node in the new
730
- // children.
731
- idxInOld = -1;
732
- {
733
- for (i = oldStartIdx; i <= oldEndIdx; ++i) {
734
- if (oldCh[i] && oldCh[i].$key$ !== null && oldCh[i].$key$ === newStartVnode.$key$) {
735
- idxInOld = i;
736
- break;
737
- }
738
- }
739
- }
740
- if (idxInOld >= 0) {
741
- // We found a node in the old children which matches up with the first
742
- // node in the new children! So let's deal with that
743
- elmToMove = oldCh[idxInOld];
744
- if (elmToMove.$tag$ !== newStartVnode.$tag$) {
745
- // the tag doesn't match so we'll need a new DOM element
746
- node = createElm(oldCh && oldCh[newStartIdx], newVNode, idxInOld);
747
- }
748
- else {
749
- patch(elmToMove, newStartVnode, isInitialRender);
750
- // invalidate the matching old node so that we won't try to update it
751
- // again later on
752
- oldCh[idxInOld] = undefined;
753
- node = elmToMove.$elm$;
754
- }
755
- newStartVnode = newCh[++newStartIdx];
756
- }
757
- else {
758
- // We either didn't find an element in the old children that matches
759
- // the key of the first new child OR the build is not using `key`
760
- // attributes at all. In either case we need to create a new element
761
- // for the new node.
762
- node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx);
763
- newStartVnode = newCh[++newStartIdx];
764
- }
765
- if (node) {
766
- // if we created a new node then handle inserting it to the DOM
767
- {
768
- oldStartVnode.$elm$.parentNode.insertBefore(node, oldStartVnode.$elm$);
769
- }
770
- }
771
- }
772
- }
773
- if (oldStartIdx > oldEndIdx) {
774
- // we have some more new nodes to add which don't match up with old nodes
775
- addVnodes(parentElm, newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].$elm$, newVNode, newCh, newStartIdx, newEndIdx);
776
- }
777
- else if (newStartIdx > newEndIdx) {
778
- // there are nodes in the `oldCh` array which no longer correspond to nodes
779
- // in the new array, so lets remove them (which entails cleaning up the
780
- // relevant DOM nodes)
781
- removeVnodes(oldCh, oldStartIdx, oldEndIdx);
782
- }
783
- };
784
- /**
785
- * Compare two VNodes to determine if they are the same
786
- *
787
- * **NB**: This function is an equality _heuristic_ based on the available
788
- * information set on the two VNodes and can be misleading under certain
789
- * circumstances. In particular, if the two nodes do not have `key` attrs
790
- * (available under `$key$` on VNodes) then the function falls back on merely
791
- * checking that they have the same tag.
792
- *
793
- * So, in other words, if `key` attrs are not set on VNodes which may be
794
- * changing order within a `children` array or something along those lines then
795
- * we could obtain a false negative and then have to do needless re-rendering
796
- * (i.e. we'd say two VNodes aren't equal when in fact they should be).
797
- *
798
- * @param leftVNode the first VNode to check
799
- * @param rightVNode the second VNode to check
800
- * @param isInitialRender whether or not this is the first render of the vdom
801
- * @returns whether they're equal or not
802
- */
803
- const isSameVnode = (leftVNode, rightVNode, isInitialRender = false) => {
804
- // compare if two vnode to see if they're "technically" the same
805
- // need to have the same element tag, and same key to be the same
806
- if (leftVNode.$tag$ === rightVNode.$tag$) {
807
- // this will be set if JSX tags in the build have `key` attrs set on them
808
- // we only want to check this if we're not on the first render since on
809
- // first render `leftVNode.$key$` will always be `null`, so we can be led
810
- // astray and, for instance, accidentally delete a DOM node that we want to
811
- // keep around.
812
- if (!isInitialRender) {
813
- return leftVNode.$key$ === rightVNode.$key$;
814
- }
815
- return true;
816
- }
817
- return false;
818
- };
819
- /**
820
- * Handle reconciling an outdated VNode with a new one which corresponds to
821
- * it. This function handles flushing updates to the DOM and reconciling the
822
- * children of the two nodes (if any).
823
- *
824
- * @param oldVNode an old VNode whose DOM element and children we want to update
825
- * @param newVNode a new VNode representing an updated version of the old one
826
- * @param isInitialRender whether or not this is the first render of the vdom
827
- */
828
- const patch = (oldVNode, newVNode, isInitialRender = false) => {
829
- const elm = (newVNode.$elm$ = oldVNode.$elm$);
830
- const oldChildren = oldVNode.$children$;
831
- const newChildren = newVNode.$children$;
832
- const tag = newVNode.$tag$;
833
- const text = newVNode.$text$;
834
- if (text === null) {
835
- {
836
- // test if we're rendering an svg element, or still rendering nodes inside of one
837
- // only add this to the when the compiler sees we're using an svg somewhere
838
- isSvgMode = tag === 'svg' ? true : tag === 'foreignObject' ? false : isSvgMode;
839
- }
840
- {
841
- {
842
- // either this is the first render of an element OR it's an update
843
- // AND we already know it's possible it could have changed
844
- // this updates the element's css classes, attrs, props, listeners, etc.
845
- updateElement(oldVNode, newVNode, isSvgMode);
846
- }
847
- }
848
- if (oldChildren !== null && newChildren !== null) {
849
- // looks like there's child vnodes for both the old and new vnodes
850
- // so we need to call `updateChildren` to reconcile them
851
- updateChildren(elm, oldChildren, newVNode, newChildren, isInitialRender);
852
- }
853
- else if (newChildren !== null) {
854
- // no old child vnodes, but there are new child vnodes to add
855
- if (oldVNode.$text$ !== null) {
856
- // the old vnode was text, so be sure to clear it out
857
- elm.textContent = '';
858
- }
859
- // add the new vnode children
860
- addVnodes(elm, null, newVNode, newChildren, 0, newChildren.length - 1);
861
- }
862
- else if (oldChildren !== null) {
863
- // no new child vnodes, but there are old child vnodes to remove
864
- removeVnodes(oldChildren, 0, oldChildren.length - 1);
865
- }
866
- if (isSvgMode && tag === 'svg') {
867
- isSvgMode = false;
868
- }
869
- }
870
- else if (oldVNode.$text$ !== text) {
871
- // update the text content for the text only vnode
872
- // and also only if the text is different than before
873
- elm.data = text;
874
- }
875
- };
876
- /**
877
- * The main entry point for Stencil's virtual DOM-based rendering engine
878
- *
879
- * Given a {@link d.HostRef} container and some virtual DOM nodes, this
880
- * function will handle creating a virtual DOM tree with a single root, patching
881
- * the current virtual DOM tree onto an old one (if any), dealing with slot
882
- * relocation, and reflecting attributes.
883
- *
884
- * @param hostRef data needed to root and render the virtual DOM tree, such as
885
- * the DOM node into which it should be rendered.
886
- * @param renderFnResults the virtual DOM nodes to be rendered
887
- * @param isInitialLoad whether or not this is the first call after page load
888
- */
889
- const renderVdom = (hostRef, renderFnResults, isInitialLoad = false) => {
890
- const hostElm = hostRef.$hostElement$;
891
- const oldVNode = hostRef.$vnode$ || newVNode(null, null);
892
- // if `renderFnResults` is a Host node then we can use it directly. If not,
893
- // we need to call `h` again to wrap the children of our component in a
894
- // 'dummy' Host node (well, an empty vnode) since `renderVdom` assumes
895
- // implicitly that the top-level vdom node is 1) an only child and 2)
896
- // contains attrs that need to be set on the host element.
897
- const rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
898
- hostTagName = hostElm.tagName;
899
- // On the first render and *only* on the first render we want to check for
900
- // any attributes set on the host element which are also set on the vdom
901
- // node. If we find them, we override the value on the VDom node attrs with
902
- // the value from the host element, which allows developers building apps
903
- // with Stencil components to override e.g. the `role` attribute on a
904
- // component even if it's already set on the `Host`.
905
- if (isInitialLoad && rootVnode.$attrs$) {
906
- for (const key of Object.keys(rootVnode.$attrs$)) {
907
- // We have a special implementation in `setAccessor` for `style` and
908
- // `class` which reconciles values coming from the VDom with values
909
- // already present on the DOM element, so we don't want to override those
910
- // attributes on the VDom tree with values from the host element if they
911
- // are present.
912
- //
913
- // Likewise, `ref` and `key` are special internal values for the Stencil
914
- // runtime and we don't want to override those either.
915
- if (hostElm.hasAttribute(key) && !['key', 'ref', 'style', 'class'].includes(key)) {
916
- rootVnode.$attrs$[key] = hostElm[key];
917
- }
918
- }
919
- }
920
- rootVnode.$tag$ = null;
921
- rootVnode.$flags$ |= 4 /* VNODE_FLAGS.isHost */;
922
- hostRef.$vnode$ = rootVnode;
923
- rootVnode.$elm$ = oldVNode.$elm$ = (hostElm);
924
- // synchronous patch
925
- patch(oldVNode, rootVnode, isInitialLoad);
926
- };
927
- const attachToAncestor = (hostRef, ancestorComponent) => {
928
- if (ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
929
- ancestorComponent['s-p'].push(new Promise((r) => (hostRef.$onRenderResolve$ = r)));
930
- }
931
- };
932
- const scheduleUpdate = (hostRef, isInitialLoad) => {
933
- {
934
- hostRef.$flags$ |= 16 /* HOST_FLAGS.isQueuedForUpdate */;
935
- }
936
- if (hostRef.$flags$ & 4 /* HOST_FLAGS.isWaitingForChildren */) {
937
- hostRef.$flags$ |= 512 /* HOST_FLAGS.needsRerender */;
938
- return;
939
- }
940
- attachToAncestor(hostRef, hostRef.$ancestorComponent$);
941
- // there is no ancestor component or the ancestor component
942
- // has already fired off its lifecycle update then
943
- // fire off the initial update
944
- const dispatch = () => dispatchHooks(hostRef, isInitialLoad);
945
- return writeTask(dispatch) ;
946
- };
947
- /**
948
- * Dispatch initial-render and update lifecycle hooks, enqueuing calls to
949
- * component lifecycle methods like `componentWillLoad` as well as
950
- * {@link updateComponent}, which will kick off the virtual DOM re-render.
951
- *
952
- * @param hostRef a reference to a host DOM node
953
- * @param isInitialLoad whether we're on the initial load or not
954
- * @returns an empty Promise which is used to enqueue a series of operations for
955
- * the component
956
- */
957
- const dispatchHooks = (hostRef, isInitialLoad) => {
958
- const endSchedule = createTime('scheduleUpdate', hostRef.$cmpMeta$.$tagName$);
959
- const instance = hostRef.$lazyInstance$ ;
960
- // We're going to use this variable together with `enqueue` to implement a
961
- // little promise-based queue. We start out with it `undefined`. When we add
962
- // the first function to the queue we'll set this variable to be that
963
- // function's return value. When we attempt to add subsequent values to the
964
- // queue we'll check that value and, if it was a `Promise`, we'll then chain
965
- // the new function off of that `Promise` using `.then()`. This will give our
966
- // queue two nice properties:
967
- //
968
- // 1. If all functions added to the queue are synchronous they'll be called
969
- // synchronously right away.
970
- // 2. If all functions added to the queue are asynchronous they'll all be
971
- // called in order after `dispatchHooks` exits.
972
- let maybePromise;
973
- endSchedule();
974
- return enqueue(maybePromise, () => updateComponent(hostRef, instance, isInitialLoad));
975
- };
976
- /**
977
- * This function uses a Promise to implement a simple first-in, first-out queue
978
- * of functions to be called.
979
- *
980
- * The queue is ordered on the basis of the first argument. If it's
981
- * `undefined`, then nothing is on the queue yet, so the provided function can
982
- * be called synchronously (although note that this function may return a
983
- * `Promise`). The idea is that then the return value of that enqueueing
984
- * operation is kept around, so that if it was a `Promise` then subsequent
985
- * functions can be enqueued by calling this function again with that `Promise`
986
- * as the first argument.
987
- *
988
- * @param maybePromise either a `Promise` which should resolve before the next function is called or an 'empty' sentinel
989
- * @param fn a function to enqueue
990
- * @returns either a `Promise` or the return value of the provided function
991
- */
992
- const enqueue = (maybePromise, fn) => isPromisey(maybePromise) ? maybePromise.then(fn) : fn();
993
- /**
994
- * Check that a value is a `Promise`. To check, we first see if the value is an
995
- * instance of the `Promise` global. In a few circumstances, in particular if
996
- * the global has been overwritten, this is could be misleading, so we also do
997
- * a little 'duck typing' check to see if the `.then` property of the value is
998
- * defined and a function.
999
- *
1000
- * @param maybePromise it might be a promise!
1001
- * @returns whether it is or not
1002
- */
1003
- const isPromisey = (maybePromise) => maybePromise instanceof Promise ||
1004
- (maybePromise && maybePromise.then && typeof maybePromise.then === 'function');
1005
- /**
1006
- * Update a component given reference to its host elements and so on.
1007
- *
1008
- * @param hostRef an object containing references to the element's host node,
1009
- * VDom nodes, and other metadata
1010
- * @param instance a reference to the underlying host element where it will be
1011
- * rendered
1012
- * @param isInitialLoad whether or not this function is being called as part of
1013
- * the first render cycle
1014
- */
1015
- const updateComponent = async (hostRef, instance, isInitialLoad) => {
1016
- var _a;
1017
- const elm = hostRef.$hostElement$;
1018
- const endUpdate = createTime('update', hostRef.$cmpMeta$.$tagName$);
1019
- const rc = elm['s-rc'];
1020
- if (isInitialLoad) {
1021
- // DOM WRITE!
1022
- attachStyles(hostRef);
1023
- }
1024
- const endRender = createTime('render', hostRef.$cmpMeta$.$tagName$);
1025
- {
1026
- callRender(hostRef, instance, elm, isInitialLoad);
1027
- }
1028
- if (rc) {
1029
- // ok, so turns out there are some child host elements
1030
- // waiting on this parent element to load
1031
- // let's fire off all update callbacks waiting
1032
- rc.map((cb) => cb());
1033
- elm['s-rc'] = undefined;
1034
- }
1035
- endRender();
1036
- endUpdate();
1037
- {
1038
- const childrenPromises = (_a = elm['s-p']) !== null && _a !== void 0 ? _a : [];
1039
- const postUpdate = () => postUpdateComponent(hostRef);
1040
- if (childrenPromises.length === 0) {
1041
- postUpdate();
1042
- }
1043
- else {
1044
- Promise.all(childrenPromises).then(postUpdate);
1045
- hostRef.$flags$ |= 4 /* HOST_FLAGS.isWaitingForChildren */;
1046
- childrenPromises.length = 0;
1047
- }
1048
- }
1049
- };
1050
- /**
1051
- * Handle making the call to the VDom renderer with the proper context given
1052
- * various build variables
1053
- *
1054
- * @param hostRef an object containing references to the element's host node,
1055
- * VDom nodes, and other metadata
1056
- * @param instance a reference to the underlying host element where it will be
1057
- * rendered
1058
- * @param elm the Host element for the component
1059
- * @param isInitialLoad whether or not this function is being called as part of
1060
- * @returns an empty promise
1061
- */
1062
- const callRender = (hostRef, instance, elm, isInitialLoad) => {
1063
- try {
1064
- /**
1065
- * minification optimization: `allRenderFn` is `true` if all components have a `render`
1066
- * method, so we can call the method immediately. If not, check before calling it.
1067
- */
1068
- instance = instance.render() ;
1069
- {
1070
- hostRef.$flags$ &= ~16 /* HOST_FLAGS.isQueuedForUpdate */;
1071
- }
1072
- {
1073
- hostRef.$flags$ |= 2 /* HOST_FLAGS.hasRendered */;
1074
- }
1075
- {
1076
- {
1077
- // looks like we've got child nodes to render into this host element
1078
- // or we need to update the css class/attrs on the host element
1079
- // DOM WRITE!
1080
- {
1081
- renderVdom(hostRef, instance, isInitialLoad);
1082
- }
1083
- }
1084
- }
1085
- }
1086
- catch (e) {
1087
- consoleError(e, hostRef.$hostElement$);
1088
- }
1089
- return null;
1090
- };
1091
- const postUpdateComponent = (hostRef) => {
1092
- const tagName = hostRef.$cmpMeta$.$tagName$;
1093
- const elm = hostRef.$hostElement$;
1094
- const endPostUpdate = createTime('postUpdate', tagName);
1095
- const ancestorComponent = hostRef.$ancestorComponent$;
1096
- if (!(hostRef.$flags$ & 64 /* HOST_FLAGS.hasLoadedComponent */)) {
1097
- hostRef.$flags$ |= 64 /* HOST_FLAGS.hasLoadedComponent */;
1098
- {
1099
- // DOM WRITE!
1100
- addHydratedFlag(elm);
1101
- }
1102
- endPostUpdate();
1103
- {
1104
- hostRef.$onReadyResolve$(elm);
1105
- if (!ancestorComponent) {
1106
- appDidLoad();
1107
- }
1108
- }
1109
- }
1110
- else {
1111
- endPostUpdate();
1112
- }
1113
- // load events fire from bottom to top
1114
- // the deepest elements load first then bubbles up
1115
- {
1116
- if (hostRef.$onRenderResolve$) {
1117
- hostRef.$onRenderResolve$();
1118
- hostRef.$onRenderResolve$ = undefined;
1119
- }
1120
- if (hostRef.$flags$ & 512 /* HOST_FLAGS.needsRerender */) {
1121
- nextTick(() => scheduleUpdate(hostRef, false));
1122
- }
1123
- hostRef.$flags$ &= ~(4 /* HOST_FLAGS.isWaitingForChildren */ | 512 /* HOST_FLAGS.needsRerender */);
1124
- }
1125
- // ( •_•)
1126
- // ( •_•)>⌐■-■
1127
- // (⌐■_■)
1128
- };
1129
- const appDidLoad = (who) => {
1130
- // on appload
1131
- // we have finish the first big initial render
1132
- {
1133
- addHydratedFlag(doc.documentElement);
1134
- }
1135
- nextTick(() => emitEvent(win, 'appload', { detail: { namespace: NAMESPACE } }));
1136
- };
1137
- const addHydratedFlag = (elm) => elm.classList.add('hydrated')
1138
- ;
1139
- const getValue = (ref, propName) => getHostRef(ref).$instanceValues$.get(propName);
1140
- const setValue = (ref, propName, newVal, cmpMeta) => {
1141
- // check our new property value against our internal value
1142
- const hostRef = getHostRef(ref);
1143
- const oldVal = hostRef.$instanceValues$.get(propName);
1144
- const flags = hostRef.$flags$;
1145
- const instance = hostRef.$lazyInstance$ ;
1146
- newVal = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
1147
- // explicitly check for NaN on both sides, as `NaN === NaN` is always false
1148
- const areBothNaN = Number.isNaN(oldVal) && Number.isNaN(newVal);
1149
- const didValueChange = newVal !== oldVal && !areBothNaN;
1150
- if ((!(flags & 8 /* HOST_FLAGS.isConstructingInstance */) || oldVal === undefined) && didValueChange) {
1151
- // gadzooks! the property's value has changed!!
1152
- // set our new value!
1153
- hostRef.$instanceValues$.set(propName, newVal);
1154
- if (instance) {
1155
- if ((flags & (2 /* HOST_FLAGS.hasRendered */ | 16 /* HOST_FLAGS.isQueuedForUpdate */)) === 2 /* HOST_FLAGS.hasRendered */) {
1156
- // looks like this value actually changed, so we've got work to do!
1157
- // but only if we've already rendered, otherwise just chill out
1158
- // queue that we need to do an update, but don't worry about queuing
1159
- // up millions cuz this function ensures it only runs once
1160
- scheduleUpdate(hostRef, false);
1161
- }
1162
- }
1163
- }
1164
- };
1165
- /**
1166
- * Attach a series of runtime constructs to a compiled Stencil component
1167
- * constructor, including getters and setters for the `@Prop` and `@State`
1168
- * decorators, callbacks for when attributes change, and so on.
1169
- *
1170
- * @param Cstr the constructor for a component that we need to process
1171
- * @param cmpMeta metadata collected previously about the component
1172
- * @param flags a number used to store a series of bit flags
1173
- * @returns a reference to the same constructor passed in (but now mutated)
1174
- */
1175
- const proxyComponent = (Cstr, cmpMeta, flags) => {
1176
- var _a;
1177
- const prototype = Cstr.prototype;
1178
- if (cmpMeta.$members$) {
1179
- // It's better to have a const than two Object.entries()
1180
- const members = Object.entries(cmpMeta.$members$);
1181
- members.map(([memberName, [memberFlags]]) => {
1182
- if ((memberFlags & 31 /* MEMBER_FLAGS.Prop */ ||
1183
- ((flags & 2 /* PROXY_FLAGS.proxyState */) && memberFlags & 32 /* MEMBER_FLAGS.State */))) {
1184
- // proxyComponent - prop
1185
- Object.defineProperty(prototype, memberName, {
1186
- get() {
1187
- // proxyComponent, get value
1188
- return getValue(this, memberName);
1189
- },
1190
- set(newValue) {
1191
- // proxyComponent, set value
1192
- setValue(this, memberName, newValue, cmpMeta);
1193
- },
1194
- configurable: true,
1195
- enumerable: true,
1196
- });
1197
- }
1198
- });
1199
- if ((flags & 1 /* PROXY_FLAGS.isElementConstructor */)) {
1200
- const attrNameToPropName = new Map();
1201
- prototype.attributeChangedCallback = function (attrName, oldValue, newValue) {
1202
- plt.jmp(() => {
1203
- var _a;
1204
- const propName = attrNameToPropName.get(attrName);
1205
- // In a web component lifecycle the attributeChangedCallback runs prior to connectedCallback
1206
- // in the case where an attribute was set inline.
1207
- // ```html
1208
- // <my-component some-attribute="some-value"></my-component>
1209
- // ```
1210
- //
1211
- // There is an edge case where a developer sets the attribute inline on a custom element and then
1212
- // programmatically changes it before it has been upgraded as shown below:
1213
- //
1214
- // ```html
1215
- // <!-- this component has _not_ been upgraded yet -->
1216
- // <my-component id="test" some-attribute="some-value"></my-component>
1217
- // <script>
1218
- // // grab non-upgraded component
1219
- // el = document.querySelector("#test");
1220
- // el.someAttribute = "another-value";
1221
- // // upgrade component
1222
- // customElements.define('my-component', MyComponent);
1223
- // </script>
1224
- // ```
1225
- // In this case if we do not un-shadow here and use the value of the shadowing property, attributeChangedCallback
1226
- // will be called with `newValue = "some-value"` and will set the shadowed property (this.someAttribute = "another-value")
1227
- // to the value that was set inline i.e. "some-value" from above example. When
1228
- // the connectedCallback attempts to un-shadow it will use "some-value" as the initial value rather than "another-value"
1229
- //
1230
- // The case where the attribute was NOT set inline but was not set programmatically shall be handled/un-shadowed
1231
- // by connectedCallback as this attributeChangedCallback will not fire.
1232
- //
1233
- // https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
1234
- //
1235
- // TODO(STENCIL-16) we should think about whether or not we actually want to be reflecting the attributes to
1236
- // properties here given that this goes against best practices outlined here
1237
- // https://developers.google.com/web/fundamentals/web-components/best-practices#avoid-reentrancy
1238
- if (this.hasOwnProperty(propName)) {
1239
- newValue = this[propName];
1240
- delete this[propName];
1241
- }
1242
- else if (prototype.hasOwnProperty(propName) &&
1243
- typeof this[propName] === 'number' &&
1244
- this[propName] == newValue) {
1245
- // if the propName exists on the prototype of `Cstr`, this update may be a result of Stencil using native
1246
- // APIs to reflect props as attributes. Calls to `setAttribute(someElement, propName)` will result in
1247
- // `propName` to be converted to a `DOMString`, which may not be what we want for other primitive props.
1248
- return;
1249
- }
1250
- else if (propName == null) {
1251
- // At this point we should know this is not a "member", so we can treat it like watching an attribute
1252
- // on a vanilla web component
1253
- const hostRef = getHostRef(this);
1254
- const flags = hostRef === null || hostRef === void 0 ? void 0 : hostRef.$flags$;
1255
- // We only want to trigger the callback(s) if:
1256
- // 1. The instance is ready
1257
- // 2. The watchers are ready
1258
- // 3. The value has changed
1259
- if (flags &&
1260
- !(flags & 8 /* HOST_FLAGS.isConstructingInstance */) &&
1261
- flags & 128 /* HOST_FLAGS.isWatchReady */ &&
1262
- newValue !== oldValue) {
1263
- const instance = hostRef.$lazyInstance$ ;
1264
- const entry = (_a = cmpMeta.$watchers$) === null || _a === void 0 ? void 0 : _a[attrName];
1265
- entry === null || entry === void 0 ? void 0 : entry.forEach((callbackName) => {
1266
- if (instance[callbackName] != null) {
1267
- instance[callbackName].call(instance, newValue, oldValue, attrName);
1268
- }
1269
- });
1270
- }
1271
- return;
1272
- }
1273
- this[propName] = newValue === null && typeof this[propName] === 'boolean' ? false : newValue;
1274
- });
1275
- };
1276
- // Create an array of attributes to observe
1277
- // This list in comprised of all strings used within a `@Watch()` decorator
1278
- // on a component as well as any Stencil-specific "members" (`@Prop()`s and `@State()`s).
1279
- // As such, there is no way to guarantee type-safety here that a user hasn't entered
1280
- // an invalid attribute.
1281
- Cstr.observedAttributes = Array.from(new Set([
1282
- ...Object.keys((_a = cmpMeta.$watchers$) !== null && _a !== void 0 ? _a : {}),
1283
- ...members
1284
- .filter(([_, m]) => m[0] & 15 /* MEMBER_FLAGS.HasAttribute */)
1285
- .map(([propName, m]) => {
1286
- const attrName = m[1] || propName;
1287
- attrNameToPropName.set(attrName, propName);
1288
- return attrName;
1289
- }),
1290
- ]));
1291
- }
1292
- }
1293
- return Cstr;
1294
- };
1295
- /**
1296
- * Initialize a Stencil component given a reference to its host element, its
1297
- * runtime bookkeeping data structure, runtime metadata about the component,
1298
- * and (optionally) an HMR version ID.
1299
- *
1300
- * @param elm a host element
1301
- * @param hostRef the element's runtime bookkeeping object
1302
- * @param cmpMeta runtime metadata for the Stencil component
1303
- * @param hmrVersionId an (optional) HMR version ID
1304
- */
1305
- const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId) => {
1306
- let Cstr;
1307
- // initializeComponent
1308
- if ((hostRef.$flags$ & 32 /* HOST_FLAGS.hasInitializedComponent */) === 0) {
1309
- // Let the runtime know that the component has been initialized
1310
- hostRef.$flags$ |= 32 /* HOST_FLAGS.hasInitializedComponent */;
1311
- const bundleId = cmpMeta.$lazyBundleId$;
1312
- if (bundleId) {
1313
- // lazy loaded components
1314
- // request the component's implementation to be
1315
- // wired up with the host element
1316
- Cstr = loadModule(cmpMeta);
1317
- if (Cstr.then) {
1318
- // Await creates a micro-task avoid if possible
1319
- const endLoad = uniqueTime();
1320
- Cstr = await Cstr;
1321
- endLoad();
1322
- }
1323
- if (!Cstr.isProxied) {
1324
- proxyComponent(Cstr, cmpMeta, 2 /* PROXY_FLAGS.proxyState */);
1325
- Cstr.isProxied = true;
1326
- }
1327
- const endNewInstance = createTime('createInstance', cmpMeta.$tagName$);
1328
- // ok, time to construct the instance
1329
- // but let's keep track of when we start and stop
1330
- // so that the getters/setters don't incorrectly step on data
1331
- {
1332
- hostRef.$flags$ |= 8 /* HOST_FLAGS.isConstructingInstance */;
1333
- }
1334
- // construct the lazy-loaded component implementation
1335
- // passing the hostRef is very important during
1336
- // construction in order to directly wire together the
1337
- // host element and the lazy-loaded instance
1338
- try {
1339
- new Cstr(hostRef);
1340
- }
1341
- catch (e) {
1342
- consoleError(e);
1343
- }
1344
- {
1345
- hostRef.$flags$ &= ~8 /* HOST_FLAGS.isConstructingInstance */;
1346
- }
1347
- endNewInstance();
1348
- }
1349
- else {
1350
- // sync constructor component
1351
- Cstr = elm.constructor;
1352
- // wait for the CustomElementRegistry to mark the component as ready before setting `isWatchReady`. Otherwise,
1353
- // watchers may fire prematurely if `customElements.get()`/`customElements.whenDefined()` resolves _before_
1354
- // Stencil has completed instantiating the component.
1355
- customElements.whenDefined(cmpMeta.$tagName$).then(() => (hostRef.$flags$ |= 128 /* HOST_FLAGS.isWatchReady */));
1356
- }
1357
- if (Cstr.style) {
1358
- // this component has styles but we haven't registered them yet
1359
- let style = Cstr.style;
1360
- const scopeId = getScopeId(cmpMeta);
1361
- if (!styles.has(scopeId)) {
1362
- const endRegisterStyles = createTime('registerStyles', cmpMeta.$tagName$);
1363
- registerStyle(scopeId, style, !!(cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */));
1364
- endRegisterStyles();
1365
- }
1366
- }
1367
- }
1368
- // we've successfully created a lazy instance
1369
- const ancestorComponent = hostRef.$ancestorComponent$;
1370
- const schedule = () => scheduleUpdate(hostRef, true);
1371
- if (ancestorComponent && ancestorComponent['s-rc']) {
1372
- // this is the initial load and this component it has an ancestor component
1373
- // but the ancestor component has NOT fired its will update lifecycle yet
1374
- // so let's just cool our jets and wait for the ancestor to continue first
1375
- // this will get fired off when the ancestor component
1376
- // finally gets around to rendering its lazy self
1377
- // fire off the initial update
1378
- ancestorComponent['s-rc'].push(schedule);
1379
- }
1380
- else {
1381
- schedule();
1382
- }
1383
- };
1384
- const fireConnectedCallback = (instance) => {
1385
- };
1386
- const connectedCallback = (elm) => {
1387
- if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
1388
- const hostRef = getHostRef(elm);
1389
- const cmpMeta = hostRef.$cmpMeta$;
1390
- const endConnected = createTime('connectedCallback', cmpMeta.$tagName$);
1391
- if (!(hostRef.$flags$ & 1 /* HOST_FLAGS.hasConnected */)) {
1392
- // first time this component has connected
1393
- hostRef.$flags$ |= 1 /* HOST_FLAGS.hasConnected */;
1394
- {
1395
- // find the first ancestor component (if there is one) and register
1396
- // this component as one of the actively loading child components for its ancestor
1397
- let ancestorComponent = elm;
1398
- while ((ancestorComponent = ancestorComponent.parentNode || ancestorComponent.host)) {
1399
- // climb up the ancestors looking for the first
1400
- // component that hasn't finished its lifecycle update yet
1401
- if (ancestorComponent['s-p']) {
1402
- // we found this components first ancestor component
1403
- // keep a reference to this component's ancestor component
1404
- attachToAncestor(hostRef, (hostRef.$ancestorComponent$ = ancestorComponent));
1405
- break;
1406
- }
1407
- }
1408
- }
1409
- // Lazy properties
1410
- // https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
1411
- if (cmpMeta.$members$) {
1412
- Object.entries(cmpMeta.$members$).map(([memberName, [memberFlags]]) => {
1413
- if (memberFlags & 31 /* MEMBER_FLAGS.Prop */ && elm.hasOwnProperty(memberName)) {
1414
- const value = elm[memberName];
1415
- delete elm[memberName];
1416
- elm[memberName] = value;
1417
- }
1418
- });
1419
- }
1420
- {
1421
- initializeComponent(elm, hostRef, cmpMeta);
1422
- }
1423
- }
1424
- else {
1425
- // fire off connectedCallback() on component instance
1426
- if (hostRef === null || hostRef === void 0 ? void 0 : hostRef.$lazyInstance$) ;
1427
- else if (hostRef === null || hostRef === void 0 ? void 0 : hostRef.$onReadyPromise$) {
1428
- hostRef.$onReadyPromise$.then(() => fireConnectedCallback());
1429
- }
1430
- }
1431
- endConnected();
1432
- }
1433
- };
1434
- const disconnectInstance = (instance) => {
1435
- };
1436
- const disconnectedCallback = async (elm) => {
1437
- if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
1438
- const hostRef = getHostRef(elm);
1439
- if (hostRef === null || hostRef === void 0 ? void 0 : hostRef.$lazyInstance$) ;
1440
- else if (hostRef === null || hostRef === void 0 ? void 0 : hostRef.$onReadyPromise$) {
1441
- hostRef.$onReadyPromise$.then(() => disconnectInstance());
1442
- }
1443
- }
1444
- };
1445
- const bootstrapLazy = (lazyBundles, options = {}) => {
1446
- var _a;
1447
- const endBootstrap = createTime();
1448
- const cmpTags = [];
1449
- const exclude = options.exclude || [];
1450
- const customElements = win.customElements;
1451
- const head = doc.head;
1452
- const metaCharset = /*@__PURE__*/ head.querySelector('meta[charset]');
1453
- const dataStyles = /*@__PURE__*/ doc.createElement('style');
1454
- const deferredConnectedCallbacks = [];
1455
- let appLoadFallback;
1456
- let isBootstrapping = true;
1457
- Object.assign(plt, options);
1458
- plt.$resourcesUrl$ = new URL(options.resourcesUrl || './', doc.baseURI).href;
1459
- let hasSlotRelocation = false;
1460
- lazyBundles.map((lazyBundle) => {
1461
- lazyBundle[1].map((compactMeta) => {
1462
- const cmpMeta = {
1463
- $flags$: compactMeta[0],
1464
- $tagName$: compactMeta[1],
1465
- $members$: compactMeta[2],
1466
- $listeners$: compactMeta[3],
1467
- };
1468
- // Check if we are using slots outside the shadow DOM in this component.
1469
- // We'll use this information later to add styles for `slot-fb` elements
1470
- if (cmpMeta.$flags$ & 4 /* CMP_FLAGS.hasSlotRelocation */) {
1471
- hasSlotRelocation = true;
1472
- }
1473
- {
1474
- cmpMeta.$members$ = compactMeta[2];
1475
- }
1476
- const tagName = cmpMeta.$tagName$;
1477
- const HostElement = class extends HTMLElement {
1478
- // StencilLazyHost
1479
- constructor(self) {
1480
- // @ts-ignore
1481
- super(self);
1482
- self = this;
1483
- registerHost(self, cmpMeta);
1484
- }
1485
- connectedCallback() {
1486
- if (appLoadFallback) {
1487
- clearTimeout(appLoadFallback);
1488
- appLoadFallback = null;
1489
- }
1490
- if (isBootstrapping) {
1491
- // connectedCallback will be processed once all components have been registered
1492
- deferredConnectedCallbacks.push(this);
1493
- }
1494
- else {
1495
- plt.jmp(() => connectedCallback(this));
1496
- }
1497
- }
1498
- disconnectedCallback() {
1499
- plt.jmp(() => disconnectedCallback(this));
1500
- }
1501
- componentOnReady() {
1502
- return getHostRef(this).$onReadyPromise$;
1503
- }
1504
- };
1505
- cmpMeta.$lazyBundleId$ = lazyBundle[0];
1506
- if (!exclude.includes(tagName) && !customElements.get(tagName)) {
1507
- cmpTags.push(tagName);
1508
- customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* PROXY_FLAGS.isElementConstructor */));
1509
- }
1510
- });
1511
- });
1512
- // Only bother generating CSS if we have components
1513
- // TODO(STENCIL-1118): Add test cases for CSS content based on conditionals
1514
- if (cmpTags.length > 0) {
1515
- // Add styles for `slot-fb` elements if any of our components are using slots outside the Shadow DOM
1516
- if (hasSlotRelocation) {
1517
- dataStyles.textContent += SLOT_FB_CSS;
1518
- }
1519
- // Add hydration styles
1520
- {
1521
- dataStyles.textContent += cmpTags + HYDRATED_CSS;
1522
- }
1523
- // If we have styles, add them to the DOM
1524
- if (dataStyles.innerHTML.length) {
1525
- dataStyles.setAttribute('data-styles', '');
1526
- // Apply CSP nonce to the style tag if it exists
1527
- const nonce = (_a = plt.$nonce$) !== null && _a !== void 0 ? _a : queryNonceMetaTagContent(doc);
1528
- if (nonce != null) {
1529
- dataStyles.setAttribute('nonce', nonce);
1530
- }
1531
- // Insert the styles into the document head
1532
- // NOTE: this _needs_ to happen last so we can ensure the nonce (and other attributes) are applied
1533
- head.insertBefore(dataStyles, metaCharset ? metaCharset.nextSibling : head.firstChild);
1534
- }
1535
- }
1536
- // Process deferred connectedCallbacks now all components have been registered
1537
- isBootstrapping = false;
1538
- if (deferredConnectedCallbacks.length) {
1539
- deferredConnectedCallbacks.map((host) => host.connectedCallback());
1540
- }
1541
- else {
1542
- {
1543
- plt.jmp(() => (appLoadFallback = setTimeout(appDidLoad, 30)));
1544
- }
1545
- }
1546
- // Fallback appLoad event
1547
- endBootstrap();
1548
- };
1549
- /**
1550
- * Assigns the given value to the nonce property on the runtime platform object.
1551
- * During runtime, this value is used to set the nonce attribute on all dynamically created script and style tags.
1552
- * @param nonce The value to be assigned to the platform nonce property.
1553
- * @returns void
1554
- */
1555
- const setNonce = (nonce) => (plt.$nonce$ = nonce);
1556
- /**
1557
- * A WeakMap mapping runtime component references to their corresponding host reference
1558
- * instances.
1559
- *
1560
- * **Note**: If we're in an HMR context we need to store a reference to this
1561
- * value on `window` in order to maintain the mapping of {@link d.RuntimeRef}
1562
- * to {@link d.HostRef} across HMR updates.
1563
- *
1564
- * This is necessary because when HMR updates for a component are processed by
1565
- * the browser-side dev server client the JS bundle for that component is
1566
- * re-fetched. Since the module containing {@link hostRefs} is included in
1567
- * that bundle, if we do not store a reference to it the new iteration of the
1568
- * component will not have access to the previous hostRef map, leading to a
1569
- * bug where the new version of the component cannot properly initialize.
1570
- */
1571
- const hostRefs = new WeakMap();
1572
- /**
1573
- * Given a {@link d.RuntimeRef} retrieve the corresponding {@link d.HostRef}
1574
- *
1575
- * @param ref the runtime ref of interest
1576
- * @returns the Host reference (if found) or undefined
1577
- */
1578
- const getHostRef = (ref) => hostRefs.get(ref);
1579
- /**
1580
- * Register a lazy instance with the {@link hostRefs} object so it's
1581
- * corresponding {@link d.HostRef} can be retrieved later.
1582
- *
1583
- * @param lazyInstance the lazy instance of interest
1584
- * @param hostRef that instances `HostRef` object
1585
- * @returns a reference to the host ref WeakMap
1586
- */
1587
- const registerInstance = (lazyInstance, hostRef) => hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef);
1588
- /**
1589
- * Register a host element for a Stencil component, setting up various metadata
1590
- * and callbacks based on {@link BUILD} flags as well as the component's runtime
1591
- * metadata.
1592
- *
1593
- * @param hostElement the host element to register
1594
- * @param cmpMeta runtime metadata for that component
1595
- * @returns a reference to the host ref WeakMap
1596
- */
1597
- const registerHost = (hostElement, cmpMeta) => {
1598
- const hostRef = {
1599
- $flags$: 0,
1600
- $hostElement$: hostElement,
1601
- $cmpMeta$: cmpMeta,
1602
- $instanceValues$: new Map(),
1603
- };
1604
- {
1605
- hostRef.$onReadyPromise$ = new Promise((r) => (hostRef.$onReadyResolve$ = r));
1606
- hostElement['s-p'] = [];
1607
- hostElement['s-rc'] = [];
1608
- }
1609
- return hostRefs.set(hostElement, hostRef);
1610
- };
1611
- const isMemberInElement = (elm, memberName) => memberName in elm;
1612
- const consoleError = (e, el) => (0, console.error)(e, el);
1613
- const cmpModules = /*@__PURE__*/ new Map();
1614
- const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
1615
- // loadModuleImport
1616
- const exportName = cmpMeta.$tagName$.replace(/-/g, '_');
1617
- const bundleId = cmpMeta.$lazyBundleId$;
1618
- const module = cmpModules.get(bundleId) ;
1619
- if (module) {
1620
- return module[exportName];
1621
- }
1622
- /*!__STENCIL_STATIC_IMPORT_SWITCH__*/
1623
- return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(
1624
- /* @vite-ignore */
1625
- /* webpackInclude: /\.entry\.js$/ */
1626
- /* webpackExclude: /\.system\.entry\.js$/ */
1627
- /* webpackMode: "lazy" */
1628
- `./${bundleId}.entry.js${''}`)); }).then((importedModule) => {
1629
- {
1630
- cmpModules.set(bundleId, importedModule);
1631
- }
1632
- return importedModule[exportName];
1633
- }, consoleError);
1634
- };
1635
- const styles = /*@__PURE__*/ new Map();
1636
- const win = typeof window !== 'undefined' ? window : {};
1637
- const doc = win.document || { head: {} };
1638
- const plt = {
1639
- $flags$: 0,
1640
- $resourcesUrl$: '',
1641
- jmp: (h) => h(),
1642
- raf: (h) => requestAnimationFrame(h),
1643
- ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
1644
- rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
1645
- ce: (eventName, opts) => new CustomEvent(eventName, opts),
1646
- };
1647
- const promiseResolve = (v) => Promise.resolve(v);
1648
- const supportsConstructableStylesheets = /*@__PURE__*/ (() => {
1649
- try {
1650
- new CSSStyleSheet();
1651
- return typeof new CSSStyleSheet().replaceSync === 'function';
1652
- }
1653
- catch (e) { }
1654
- return false;
1655
- })()
1656
- ;
1657
- const queueDomReads = [];
1658
- const queueDomWrites = [];
1659
- const queueTask = (queue, write) => (cb) => {
1660
- queue.push(cb);
1661
- if (!queuePending) {
1662
- queuePending = true;
1663
- if (write && plt.$flags$ & 4 /* PLATFORM_FLAGS.queueSync */) {
1664
- nextTick(flush);
1665
- }
1666
- else {
1667
- plt.raf(flush);
1668
- }
1669
- }
1670
- };
1671
- const consume = (queue) => {
1672
- for (let i = 0; i < queue.length; i++) {
1673
- try {
1674
- queue[i](performance.now());
1675
- }
1676
- catch (e) {
1677
- consoleError(e);
1678
- }
1679
- }
1680
- queue.length = 0;
1681
- };
1682
- const flush = () => {
1683
- // always force a bunch of medium callbacks to run, but still have
1684
- // a throttle on how many can run in a certain time
1685
- // DOM READS!!!
1686
- consume(queueDomReads);
1687
- // DOM WRITES!!!
1688
- {
1689
- consume(queueDomWrites);
1690
- if ((queuePending = queueDomReads.length > 0)) {
1691
- // still more to do yet, but we've run out of time
1692
- // let's let this thing cool off and try again in the next tick
1693
- plt.raf(flush);
1694
- }
1695
- }
1696
- };
1697
- const nextTick = (cb) => promiseResolve().then(cb);
1698
- const writeTask = /*@__PURE__*/ queueTask(queueDomWrites, true);
1699
-
1700
- exports.bootstrapLazy = bootstrapLazy;
1701
- exports.h = h;
1702
- exports.promiseResolve = promiseResolve;
1703
- exports.registerInstance = registerInstance;
1704
- exports.setNonce = setNonce;