@penn-libraries/web 0.1.3 → 0.1.4

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