proto-sudoku-wc 0.0.774 → 0.0.776

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