dash-button-web 0.0.22 → 0.0.23-beta.1

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