@uoguelph/web-components 1.2.0-rc.7 → 1.2.0-rc.9

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