proto-float-wc 0.1.0

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