proto-table-wc 0.0.501 → 0.0.503

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