@justifi/webcomponents 0.0.15 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/changelog-template.hbs +41 -0
  3. package/dist/cjs/{index-e1b45289.js → index-ca2cd154.js} +456 -97
  4. package/dist/cjs/justifi-bank-account-form.cjs.entry.js +59 -0
  5. package/dist/cjs/justifi-billing-form.cjs.entry.js +2150 -0
  6. package/dist/cjs/justifi-card-form.cjs.entry.js +59 -0
  7. package/dist/cjs/justifi-payment-form.cjs.entry.js +17 -0
  8. package/dist/cjs/{justifi-bank-account-form_3.cjs.entry.js → justifi-payment-method-form.cjs.entry.js} +86 -110
  9. package/dist/cjs/justifi-payments-list.cjs.entry.js +1 -1
  10. package/dist/cjs/loader.cjs.js +3 -4
  11. package/dist/cjs/select-input_2.cjs.entry.js +59 -0
  12. package/dist/cjs/webcomponents.cjs.js +3 -7
  13. package/dist/collection/collection-manifest.json +7 -3
  14. package/dist/collection/components/bank-account-form/bank-account-form.js +1 -1
  15. package/dist/collection/components/billing-form/billing-form-schema.js +14 -0
  16. package/dist/collection/components/billing-form/billing-form.css +11 -0
  17. package/dist/collection/components/billing-form/billing-form.js +92 -0
  18. package/dist/collection/components/billing-form/state-options.js +243 -0
  19. package/dist/collection/components/card-form/card-form.js +1 -1
  20. package/dist/collection/components/card-form/card-form.stories.js +132 -0
  21. package/dist/collection/components/payment-form/payment-form.js +31 -0
  22. package/dist/collection/components/payment-method-form/payment-method-form.js +6 -4
  23. package/dist/collection/components/select-input/select-input.css +7 -0
  24. package/dist/collection/components/select-input/select-input.js +144 -0
  25. package/dist/collection/components/text-input/text-input.css +7 -0
  26. package/dist/collection/components/text-input/text-input.js +126 -0
  27. package/dist/components/index.d.ts +4 -9
  28. package/dist/components/index.js +5 -1
  29. package/dist/components/justifi-billing-form.d.ts +11 -0
  30. package/dist/components/justifi-billing-form.js +2180 -0
  31. package/dist/components/justifi-payment-form.d.ts +11 -0
  32. package/dist/components/justifi-payment-form.js +32 -0
  33. package/dist/components/payment-method-form.js +85 -3
  34. package/dist/components/select-input.d.ts +11 -0
  35. package/dist/components/select-input.js +6 -0
  36. package/dist/components/select-input2.js +52 -0
  37. package/dist/components/text-input.d.ts +11 -0
  38. package/dist/components/text-input.js +6 -0
  39. package/dist/components/text-input2.js +48 -0
  40. package/dist/esm/{index-c1f569bd.js → index-05706eb5.js} +457 -97
  41. package/dist/esm/justifi-bank-account-form.entry.js +55 -0
  42. package/dist/esm/justifi-billing-form.entry.js +2146 -0
  43. package/dist/esm/justifi-card-form.entry.js +55 -0
  44. package/dist/esm/justifi-payment-form.entry.js +13 -0
  45. package/dist/esm/justifi-payment-method-form.entry.js +187 -0
  46. package/dist/esm/justifi-payments-list.entry.js +1 -1
  47. package/dist/esm/loader.js +3 -4
  48. package/dist/esm/polyfills/css-shim.js +1 -1
  49. package/dist/esm/select-input_2.entry.js +54 -0
  50. package/dist/esm/webcomponents.js +3 -4
  51. package/dist/types/api/Api.d.ts +1 -1
  52. package/dist/types/api/Payment.d.ts +1 -1
  53. package/dist/types/components/billing-form/billing-form-schema.d.ts +15 -0
  54. package/dist/types/components/billing-form/billing-form.d.ts +17 -0
  55. package/dist/types/components/billing-form/state-options.d.ts +5 -0
  56. package/dist/types/components/card-form/card-form.stories.d.ts +14 -0
  57. package/dist/types/components/payment-form/payment-form.d.ts +4 -0
  58. package/dist/types/components/payment-method-form/payment-method-form.d.ts +1 -1
  59. package/dist/types/components/payment-method-form/theme.d.ts +3 -1
  60. package/dist/types/components/select-input/select-input.d.ts +18 -0
  61. package/dist/types/components/text-input/text-input.d.ts +14 -0
  62. package/dist/types/components.d.ts +87 -3
  63. package/dist/types/stencil-public-runtime.d.ts +3 -59
  64. package/dist/webcomponents/p-3809130a.entry.js +1 -0
  65. package/dist/webcomponents/p-67be9585.entry.js +1 -0
  66. package/dist/webcomponents/p-787671b9.entry.js +1 -0
  67. package/dist/webcomponents/p-87654bf4.entry.js +1 -0
  68. package/dist/webcomponents/p-8ee06fd1.js +2 -0
  69. package/dist/webcomponents/p-94ef2d0e.entry.js +1 -0
  70. package/dist/webcomponents/p-c07191dc.entry.js +1 -0
  71. package/dist/webcomponents/p-e5b0f047.entry.js +1 -0
  72. package/dist/webcomponents/webcomponents.esm.js +1 -1
  73. package/loader/index.d.ts +0 -9
  74. package/package.json +23 -5
  75. package/LICENSE +0 -21
  76. package/dist/esm/justifi-bank-account-form_3.entry.js +0 -209
  77. package/dist/webcomponents/p-1de39730.js +0 -2
  78. package/dist/webcomponents/p-f0eb5ed0.entry.js +0 -1
  79. package/dist/webcomponents/p-f91b7b05.entry.js +0 -1
@@ -31,7 +31,11 @@ const NAMESPACE = 'webcomponents';
31
31
  * Modified for Stencil's renderer and slot projection
32
32
  */
33
33
  let scopeId;
34
+ let contentRef;
34
35
  let hostTagName;
36
+ let useNativeShadowDom = false;
37
+ let checkSlotFallbackVisibility = false;
38
+ let checkSlotRelocate = false;
35
39
  let isSvgMode = false;
36
40
  let queuePending = false;
37
41
  const createTime = (fnName, tagName = '') => {
@@ -63,18 +67,6 @@ const isComplexType = (o) => {
63
67
  o = typeof o;
64
68
  return o === 'object' || o === 'function';
65
69
  };
66
- /**
67
- * Helper method for querying a `meta` tag that contains a nonce value
68
- * out of a DOM's head.
69
- *
70
- * @param doc The DOM containing the `head` to query against
71
- * @returns The content of the meta tag representing the nonce value, or `undefined` if no tag
72
- * exists or the tag has no content.
73
- */
74
- function queryNonceMetaTagContent(doc) {
75
- var _a, _b, _c;
76
- 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;
77
- }
78
70
  /**
79
71
  * Production h() function based on Preact by
80
72
  * Jason Miller (@developit)
@@ -83,10 +75,12 @@ function queryNonceMetaTagContent(doc) {
83
75
  *
84
76
  * Modified for Stencil's compiler and vdom
85
77
  */
78
+ // const stack: any[] = [];
86
79
  // export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, child?: d.ChildType): d.VNode;
87
80
  // export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, ...children: d.ChildType[]): d.VNode;
88
81
  const h = (nodeName, vnodeData, ...children) => {
89
82
  let child = null;
83
+ let slotName = null;
90
84
  let simple = false;
91
85
  let lastSimple = false;
92
86
  const vNodeChildren = [];
@@ -114,6 +108,9 @@ const h = (nodeName, vnodeData, ...children) => {
114
108
  };
115
109
  walk(children);
116
110
  if (vnodeData) {
111
+ if (vnodeData.name) {
112
+ slotName = vnodeData.name;
113
+ }
117
114
  {
118
115
  const classData = vnodeData.className || vnodeData.class;
119
116
  if (classData) {
@@ -131,16 +128,11 @@ const h = (nodeName, vnodeData, ...children) => {
131
128
  if (vNodeChildren.length > 0) {
132
129
  vnode.$children$ = vNodeChildren;
133
130
  }
131
+ {
132
+ vnode.$name$ = slotName;
133
+ }
134
134
  return vnode;
135
135
  };
136
- /**
137
- * A utility function for creating a virtual DOM node from a tag and some
138
- * possible text content.
139
- *
140
- * @param tag the tag for this element
141
- * @param text possible text content for the node
142
- * @returns a newly-minted virtual DOM node
143
- */
144
136
  const newVNode = (tag, text) => {
145
137
  const vnode = {
146
138
  $flags$: 0,
@@ -152,15 +144,12 @@ const newVNode = (tag, text) => {
152
144
  {
153
145
  vnode.$attrs$ = null;
154
146
  }
147
+ {
148
+ vnode.$name$ = null;
149
+ }
155
150
  return vnode;
156
151
  };
157
152
  const Host = {};
158
- /**
159
- * Check whether a given node is a Host node or not
160
- *
161
- * @param node the virtual DOM node to check
162
- * @returns whether it's a Host node or not
163
- */
164
153
  const isHost = (node) => node && node.$tag$ === Host;
165
154
  /**
166
155
  * Parse a new property value for a given property type.
@@ -244,7 +233,6 @@ const registerStyle = (scopeId, cssText, allowCS) => {
244
233
  styles.set(scopeId, style);
245
234
  };
246
235
  const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
247
- var _a;
248
236
  let scopeId = getScopeId(cmpMeta);
249
237
  const style = styles.get(scopeId);
250
238
  // if an element is NOT connected then getRootNode() will return the wrong root node
@@ -264,11 +252,6 @@ const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
264
252
  styleElm = doc.createElement('style');
265
253
  styleElm.innerHTML = style;
266
254
  }
267
- // Apply CSP nonce to the style tag if it exists
268
- const nonce = (_a = plt.$nonce$) !== null && _a !== void 0 ? _a : queryNonceMetaTagContent(doc);
269
- if (nonce != null) {
270
- styleElm.setAttribute('nonce', nonce);
271
- }
272
255
  styleContainerNode.insertBefore(styleElm, styleContainerNode.querySelector('link'));
273
256
  }
274
257
  if (appliedStyles) {
@@ -313,7 +296,7 @@ const getScopeId = (cmp, mode) => 'sc-' + (cmp.$tagName$);
313
296
  const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
314
297
  if (oldValue !== newValue) {
315
298
  let isProp = isMemberInElement(elm, memberName);
316
- memberName.toLowerCase();
299
+ let ln = memberName.toLowerCase();
317
300
  if (memberName === 'class') {
318
301
  const classList = elm.classList;
319
302
  const oldClasses = parseClassList(oldValue);
@@ -321,12 +304,76 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
321
304
  classList.remove(...oldClasses.filter((c) => c && !newClasses.includes(c)));
322
305
  classList.add(...newClasses.filter((c) => c && !oldClasses.includes(c)));
323
306
  }
307
+ else if (memberName === 'style') {
308
+ // update style attribute, css properties and values
309
+ {
310
+ for (const prop in oldValue) {
311
+ if (!newValue || newValue[prop] == null) {
312
+ if (prop.includes('-')) {
313
+ elm.style.removeProperty(prop);
314
+ }
315
+ else {
316
+ elm.style[prop] = '';
317
+ }
318
+ }
319
+ }
320
+ }
321
+ for (const prop in newValue) {
322
+ if (!oldValue || newValue[prop] !== oldValue[prop]) {
323
+ if (prop.includes('-')) {
324
+ elm.style.setProperty(prop, newValue[prop]);
325
+ }
326
+ else {
327
+ elm.style[prop] = newValue[prop];
328
+ }
329
+ }
330
+ }
331
+ }
324
332
  else if (memberName === 'ref') {
325
333
  // minifier will clean this up
326
334
  if (newValue) {
327
335
  newValue(elm);
328
336
  }
329
337
  }
338
+ else if ((!isProp ) &&
339
+ memberName[0] === 'o' &&
340
+ memberName[1] === 'n') {
341
+ // Event Handlers
342
+ // so if the member name starts with "on" and the 3rd characters is
343
+ // a capital letter, and it's not already a member on the element,
344
+ // then we're assuming it's an event listener
345
+ if (memberName[2] === '-') {
346
+ // on- prefixed events
347
+ // allows to be explicit about the dom event to listen without any magic
348
+ // under the hood:
349
+ // <my-cmp on-click> // listens for "click"
350
+ // <my-cmp on-Click> // listens for "Click"
351
+ // <my-cmp on-ionChange> // listens for "ionChange"
352
+ // <my-cmp on-EVENTS> // listens for "EVENTS"
353
+ memberName = memberName.slice(3);
354
+ }
355
+ else if (isMemberInElement(win, ln)) {
356
+ // standard event
357
+ // the JSX attribute could have been "onMouseOver" and the
358
+ // member name "onmouseover" is on the window's prototype
359
+ // so let's add the listener "mouseover", which is all lowercased
360
+ memberName = ln.slice(2);
361
+ }
362
+ else {
363
+ // custom event
364
+ // the JSX attribute could have been "onMyCustomEvent"
365
+ // so let's trim off the "on" prefix and lowercase the first character
366
+ // and add the listener "myCustomEvent"
367
+ // except for the first character, we keep the event name case
368
+ memberName = ln[2] + memberName.slice(3);
369
+ }
370
+ if (oldValue) {
371
+ plt.rel(elm, memberName, oldValue, false);
372
+ }
373
+ if (newValue) {
374
+ plt.ael(elm, memberName, newValue, false);
375
+ }
376
+ }
330
377
  else {
331
378
  // Set property if it exists and it's not a SVG
332
379
  const isComplex = isComplexType(newValue);
@@ -404,13 +451,36 @@ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
404
451
  let i = 0;
405
452
  let elm;
406
453
  let childNode;
454
+ let oldVNode;
455
+ if (!useNativeShadowDom) {
456
+ // remember for later we need to check to relocate nodes
457
+ checkSlotRelocate = true;
458
+ if (newVNode.$tag$ === 'slot') {
459
+ if (scopeId) {
460
+ // scoped css needs to add its scoped id to the parent element
461
+ parentElm.classList.add(scopeId + '-s');
462
+ }
463
+ newVNode.$flags$ |= newVNode.$children$
464
+ ? // slot element has fallback content
465
+ 2 /* VNODE_FLAGS.isSlotFallback */
466
+ : // slot element does not have fallback content
467
+ 1 /* VNODE_FLAGS.isSlotReference */;
468
+ }
469
+ }
407
470
  if (newVNode.$text$ !== null) {
408
471
  // create text node
409
472
  elm = newVNode.$elm$ = doc.createTextNode(newVNode.$text$);
410
473
  }
474
+ else if (newVNode.$flags$ & 1 /* VNODE_FLAGS.isSlotReference */) {
475
+ // create a slot reference node
476
+ elm = newVNode.$elm$ =
477
+ doc.createTextNode('');
478
+ }
411
479
  else {
412
480
  // create element
413
- elm = newVNode.$elm$ = (doc.createElement(newVNode.$tag$));
481
+ elm = newVNode.$elm$ = (doc.createElement(newVNode.$flags$ & 2 /* VNODE_FLAGS.isSlotFallback */
482
+ ? 'slot-fb'
483
+ : newVNode.$tag$));
414
484
  // add css classes, attrs, props, listeners, etc.
415
485
  {
416
486
  updateElement(null, newVNode, isSvgMode);
@@ -423,7 +493,7 @@ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
423
493
  if (newVNode.$children$) {
424
494
  for (i = 0; i < newVNode.$children$.length; ++i) {
425
495
  // create the node
426
- childNode = createElm(oldParentVNode, newVNode, i);
496
+ childNode = createElm(oldParentVNode, newVNode, i, elm);
427
497
  // return node could have been null
428
498
  if (childNode) {
429
499
  // append our new node
@@ -432,57 +502,85 @@ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
432
502
  }
433
503
  }
434
504
  }
505
+ {
506
+ elm['s-hn'] = hostTagName;
507
+ if (newVNode.$flags$ & (2 /* VNODE_FLAGS.isSlotFallback */ | 1 /* VNODE_FLAGS.isSlotReference */)) {
508
+ // remember the content reference comment
509
+ elm['s-sr'] = true;
510
+ // remember the content reference comment
511
+ elm['s-cr'] = contentRef;
512
+ // remember the slot name, or empty string for default slot
513
+ elm['s-sn'] = newVNode.$name$ || '';
514
+ // check if we've got an old vnode for this slot
515
+ oldVNode = oldParentVNode && oldParentVNode.$children$ && oldParentVNode.$children$[childIndex];
516
+ if (oldVNode && oldVNode.$tag$ === newVNode.$tag$ && oldParentVNode.$elm$) {
517
+ // we've got an old slot vnode and the wrapper is being replaced
518
+ // so let's move the old slot content back to it's original location
519
+ putBackInOriginalLocation(oldParentVNode.$elm$, false);
520
+ }
521
+ }
522
+ }
435
523
  return elm;
436
524
  };
437
- /**
438
- * Create DOM nodes corresponding to a list of {@link d.Vnode} objects and
439
- * add them to the DOM in the appropriate place.
440
- *
441
- * @param parentElm the DOM node which should be used as a parent for the new
442
- * DOM nodes
443
- * @param before a child of the `parentElm` which the new children should be
444
- * inserted before (optional)
445
- * @param parentVNode the parent virtual DOM node
446
- * @param vnodes the new child virtual DOM nodes to produce DOM nodes for
447
- * @param startIdx the index in the child virtual DOM nodes at which to start
448
- * creating DOM nodes (inclusive)
449
- * @param endIdx the index in the child virtual DOM nodes at which to stop
450
- * creating DOM nodes (inclusive)
451
- */
525
+ const putBackInOriginalLocation = (parentElm, recursive) => {
526
+ plt.$flags$ |= 1 /* PLATFORM_FLAGS.isTmpDisconnected */;
527
+ const oldSlotChildNodes = parentElm.childNodes;
528
+ for (let i = oldSlotChildNodes.length - 1; i >= 0; i--) {
529
+ const childNode = oldSlotChildNodes[i];
530
+ if (childNode['s-hn'] !== hostTagName && childNode['s-ol']) {
531
+ // // this child node in the old element is from another component
532
+ // // remove this node from the old slot's parent
533
+ // childNode.remove();
534
+ // and relocate it back to it's original location
535
+ parentReferenceNode(childNode).insertBefore(childNode, referenceNode(childNode));
536
+ // remove the old original location comment entirely
537
+ // later on the patch function will know what to do
538
+ // and move this to the correct spot in need be
539
+ childNode['s-ol'].remove();
540
+ childNode['s-ol'] = undefined;
541
+ checkSlotRelocate = true;
542
+ }
543
+ if (recursive) {
544
+ putBackInOriginalLocation(childNode, recursive);
545
+ }
546
+ }
547
+ plt.$flags$ &= ~1 /* PLATFORM_FLAGS.isTmpDisconnected */;
548
+ };
452
549
  const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) => {
453
- let containerElm = (parentElm);
550
+ let containerElm = ((parentElm['s-cr'] && parentElm['s-cr'].parentNode) || parentElm);
454
551
  let childNode;
455
552
  if (containerElm.shadowRoot && containerElm.tagName === hostTagName) {
456
553
  containerElm = containerElm.shadowRoot;
457
554
  }
458
555
  for (; startIdx <= endIdx; ++startIdx) {
459
556
  if (vnodes[startIdx]) {
460
- childNode = createElm(null, parentVNode, startIdx);
557
+ childNode = createElm(null, parentVNode, startIdx, parentElm);
461
558
  if (childNode) {
462
559
  vnodes[startIdx].$elm$ = childNode;
463
- containerElm.insertBefore(childNode, before);
560
+ containerElm.insertBefore(childNode, referenceNode(before) );
464
561
  }
465
562
  }
466
563
  }
467
564
  };
468
- /**
469
- * Remove the DOM elements corresponding to a list of {@link d.VNode} objects.
470
- * This can be used to, for instance, clean up after a list of children which
471
- * should no longer be shown.
472
- *
473
- * This function also handles some of Stencil's slot relocation logic.
474
- *
475
- * @param vnodes a list of virtual DOM nodes to remove
476
- * @param startIdx the index at which to start removing nodes (inclusive)
477
- * @param endIdx the index at which to stop removing nodes (inclusive)
478
- * @param vnode a VNode
479
- * @param elm an element
480
- */
481
565
  const removeVnodes = (vnodes, startIdx, endIdx, vnode, elm) => {
482
566
  for (; startIdx <= endIdx; ++startIdx) {
483
567
  if ((vnode = vnodes[startIdx])) {
484
568
  elm = vnode.$elm$;
485
569
  callNodeRefs(vnode);
570
+ {
571
+ // we're removing this element
572
+ // so it's possible we need to show slot fallback content now
573
+ checkSlotFallbackVisibility = true;
574
+ if (elm['s-ol']) {
575
+ // remove the original location comment
576
+ elm['s-ol'].remove();
577
+ }
578
+ else {
579
+ // it's possible that child nodes of the node
580
+ // that's being removed are slot nodes
581
+ putBackInOriginalLocation(elm, true);
582
+ }
583
+ }
486
584
  // remove the vnode's element from the dom
487
585
  elm.remove();
488
586
  }
@@ -598,6 +696,23 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
598
696
  newEndVnode = newCh[--newEndIdx];
599
697
  }
600
698
  else if (isSameVnode(oldStartVnode, newEndVnode)) {
699
+ // case: "Vnode moved right"
700
+ //
701
+ // We've found that the last node in our window on the new children is
702
+ // the same VNode as the _first_ node in our window on the old children
703
+ // we're dealing with now. Visually, this is the layout of these two
704
+ // nodes:
705
+ //
706
+ // newCh: [..., newStartVnode , ... , newEndVnode , ...]
707
+ // ^^^^^^^^^^^
708
+ // oldCh: [..., oldStartVnode , ... , oldEndVnode , ...]
709
+ // ^^^^^^^^^^^^^
710
+ //
711
+ // In this situation we need to patch `newEndVnode` onto `oldStartVnode`
712
+ // and move the DOM element for `oldStartVnode`.
713
+ if ((oldStartVnode.$tag$ === 'slot' || newEndVnode.$tag$ === 'slot')) {
714
+ putBackInOriginalLocation(oldStartVnode.$elm$.parentNode, false);
715
+ }
601
716
  patch(oldStartVnode, newEndVnode);
602
717
  // We need to move the element for `oldStartVnode` into a position which
603
718
  // will be appropriate for `newEndVnode`. For this we can use
@@ -621,6 +736,24 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
621
736
  newEndVnode = newCh[--newEndIdx];
622
737
  }
623
738
  else if (isSameVnode(oldEndVnode, newStartVnode)) {
739
+ // case: "Vnode moved left"
740
+ //
741
+ // We've found that the first node in our window on the new children is
742
+ // the same VNode as the _last_ node in our window on the old children.
743
+ // Visually, this is the layout of these two nodes:
744
+ //
745
+ // newCh: [..., newStartVnode , ... , newEndVnode , ...]
746
+ // ^^^^^^^^^^^^^
747
+ // oldCh: [..., oldStartVnode , ... , oldEndVnode , ...]
748
+ // ^^^^^^^^^^^
749
+ //
750
+ // In this situation we need to patch `newStartVnode` onto `oldEndVnode`
751
+ // (which will handle updating any changed attributes, reconciling their
752
+ // children etc) but we also need to move the DOM node to which
753
+ // `oldEndVnode` corresponds.
754
+ if ((oldStartVnode.$tag$ === 'slot' || newEndVnode.$tag$ === 'slot')) {
755
+ putBackInOriginalLocation(oldEndVnode.$elm$.parentNode, false);
756
+ }
624
757
  patch(oldEndVnode, newStartVnode);
625
758
  // We've already checked above if `oldStartVnode` and `newStartVnode` are
626
759
  // the same node, so since we're here we know that they are not. Thus we
@@ -637,13 +770,13 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
637
770
  // the key of the first new child OR the build is not using `key`
638
771
  // attributes at all. In either case we need to create a new element
639
772
  // for the new node.
640
- node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx);
773
+ node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx, parentElm);
641
774
  newStartVnode = newCh[++newStartIdx];
642
775
  }
643
776
  if (node) {
644
777
  // if we created a new node then handle inserting it to the DOM
645
778
  {
646
- oldStartVnode.$elm$.parentNode.insertBefore(node, oldStartVnode.$elm$);
779
+ parentReferenceNode(oldStartVnode.$elm$).insertBefore(node, referenceNode(oldStartVnode.$elm$));
647
780
  }
648
781
  }
649
782
  }
@@ -670,8 +803,7 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
670
803
  *
671
804
  * So, in other words, if `key` attrs are not set on VNodes which may be
672
805
  * changing order within a `children` array or something along those lines then
673
- * we could obtain a false negative and then have to do needless re-rendering
674
- * (i.e. we'd say two VNodes aren't equal when in fact they should be).
806
+ * we could obtain a false positive and then have to do needless re-rendering.
675
807
  *
676
808
  * @param leftVNode the first VNode to check
677
809
  * @param rightVNode the second VNode to check
@@ -681,10 +813,21 @@ const isSameVnode = (leftVNode, rightVNode) => {
681
813
  // compare if two vnode to see if they're "technically" the same
682
814
  // need to have the same element tag, and same key to be the same
683
815
  if (leftVNode.$tag$ === rightVNode.$tag$) {
816
+ if (leftVNode.$tag$ === 'slot') {
817
+ return leftVNode.$name$ === rightVNode.$name$;
818
+ }
684
819
  return true;
685
820
  }
686
821
  return false;
687
822
  };
823
+ const referenceNode = (node) => {
824
+ // this node was relocated to a new location in the dom
825
+ // because of some other component's slot
826
+ // but we still have an html comment in place of where
827
+ // it's original location was according to it's original vdom
828
+ return (node && node['s-ol']) || node;
829
+ };
830
+ const parentReferenceNode = (node) => (node['s-ol'] ? node['s-ol'] : node).parentNode;
688
831
  /**
689
832
  * Handle reconciling an outdated VNode with a new one which corresponds to
690
833
  * it. This function handles flushing updates to the DOM and reconciling the
@@ -697,10 +840,14 @@ const patch = (oldVNode, newVNode) => {
697
840
  const elm = (newVNode.$elm$ = oldVNode.$elm$);
698
841
  const oldChildren = oldVNode.$children$;
699
842
  const newChildren = newVNode.$children$;
843
+ const tag = newVNode.$tag$;
700
844
  const text = newVNode.$text$;
845
+ let defaultHolder;
701
846
  if (text === null) {
702
847
  {
703
- {
848
+ if (tag === 'slot')
849
+ ;
850
+ else {
704
851
  // either this is the first render of an element OR it's an update
705
852
  // AND we already know it's possible it could have changed
706
853
  // this updates the element's css classes, attrs, props, listeners, etc.
@@ -726,32 +873,156 @@ const patch = (oldVNode, newVNode) => {
726
873
  removeVnodes(oldChildren, 0, oldChildren.length - 1);
727
874
  }
728
875
  }
876
+ else if ((defaultHolder = elm['s-cr'])) {
877
+ // this element has slotted content
878
+ defaultHolder.parentNode.textContent = text;
879
+ }
729
880
  else if (oldVNode.$text$ !== text) {
730
881
  // update the text content for the text only vnode
731
882
  // and also only if the text is different than before
732
883
  elm.data = text;
733
884
  }
734
885
  };
886
+ const updateFallbackSlotVisibility = (elm) => {
887
+ // tslint:disable-next-line: prefer-const
888
+ const childNodes = elm.childNodes;
889
+ let childNode;
890
+ let i;
891
+ let ilen;
892
+ let j;
893
+ let slotNameAttr;
894
+ let nodeType;
895
+ for (i = 0, ilen = childNodes.length; i < ilen; i++) {
896
+ childNode = childNodes[i];
897
+ if (childNode.nodeType === 1 /* NODE_TYPE.ElementNode */) {
898
+ if (childNode['s-sr']) {
899
+ // this is a slot fallback node
900
+ // get the slot name for this slot reference node
901
+ slotNameAttr = childNode['s-sn'];
902
+ // by default always show a fallback slot node
903
+ // then hide it if there are other slots in the light dom
904
+ childNode.hidden = false;
905
+ for (j = 0; j < ilen; j++) {
906
+ nodeType = childNodes[j].nodeType;
907
+ if (childNodes[j]['s-hn'] !== childNode['s-hn'] || slotNameAttr !== '') {
908
+ // this sibling node is from a different component OR is a named fallback slot node
909
+ if (nodeType === 1 /* NODE_TYPE.ElementNode */ && slotNameAttr === childNodes[j].getAttribute('slot')) {
910
+ childNode.hidden = true;
911
+ break;
912
+ }
913
+ }
914
+ else {
915
+ // this is a default fallback slot node
916
+ // any element or text node (with content)
917
+ // should hide the default fallback slot node
918
+ if (nodeType === 1 /* NODE_TYPE.ElementNode */ ||
919
+ (nodeType === 3 /* NODE_TYPE.TextNode */ && childNodes[j].textContent.trim() !== '')) {
920
+ childNode.hidden = true;
921
+ break;
922
+ }
923
+ }
924
+ }
925
+ }
926
+ // keep drilling down
927
+ updateFallbackSlotVisibility(childNode);
928
+ }
929
+ }
930
+ };
931
+ const relocateNodes = [];
932
+ const relocateSlotContent = (elm) => {
933
+ // tslint:disable-next-line: prefer-const
934
+ let childNode;
935
+ let node;
936
+ let hostContentNodes;
937
+ let slotNameAttr;
938
+ let relocateNodeData;
939
+ let j;
940
+ let i = 0;
941
+ const childNodes = elm.childNodes;
942
+ const ilen = childNodes.length;
943
+ for (; i < ilen; i++) {
944
+ childNode = childNodes[i];
945
+ if (childNode['s-sr'] && (node = childNode['s-cr']) && node.parentNode) {
946
+ // first got the content reference comment node
947
+ // then we got it's parent, which is where all the host content is in now
948
+ hostContentNodes = node.parentNode.childNodes;
949
+ slotNameAttr = childNode['s-sn'];
950
+ for (j = hostContentNodes.length - 1; j >= 0; j--) {
951
+ node = hostContentNodes[j];
952
+ if (!node['s-cn'] && !node['s-nr'] && node['s-hn'] !== childNode['s-hn']) {
953
+ // let's do some relocating to its new home
954
+ // but never relocate a content reference node
955
+ // that is suppose to always represent the original content location
956
+ if (isNodeLocatedInSlot(node, slotNameAttr)) {
957
+ // it's possible we've already decided to relocate this node
958
+ relocateNodeData = relocateNodes.find((r) => r.$nodeToRelocate$ === node);
959
+ // made some changes to slots
960
+ // let's make sure we also double check
961
+ // fallbacks are correctly hidden or shown
962
+ checkSlotFallbackVisibility = true;
963
+ node['s-sn'] = node['s-sn'] || slotNameAttr;
964
+ if (relocateNodeData) {
965
+ // previously we never found a slot home for this node
966
+ // but turns out we did, so let's remember it now
967
+ relocateNodeData.$slotRefNode$ = childNode;
968
+ }
969
+ else {
970
+ // add to our list of nodes to relocate
971
+ relocateNodes.push({
972
+ $slotRefNode$: childNode,
973
+ $nodeToRelocate$: node,
974
+ });
975
+ }
976
+ if (node['s-sr']) {
977
+ relocateNodes.map((relocateNode) => {
978
+ if (isNodeLocatedInSlot(relocateNode.$nodeToRelocate$, node['s-sn'])) {
979
+ relocateNodeData = relocateNodes.find((r) => r.$nodeToRelocate$ === node);
980
+ if (relocateNodeData && !relocateNode.$slotRefNode$) {
981
+ relocateNode.$slotRefNode$ = relocateNodeData.$slotRefNode$;
982
+ }
983
+ }
984
+ });
985
+ }
986
+ }
987
+ else if (!relocateNodes.some((r) => r.$nodeToRelocate$ === node)) {
988
+ // so far this element does not have a slot home, not setting slotRefNode on purpose
989
+ // if we never find a home for this element then we'll need to hide it
990
+ relocateNodes.push({
991
+ $nodeToRelocate$: node,
992
+ });
993
+ }
994
+ }
995
+ }
996
+ }
997
+ if (childNode.nodeType === 1 /* NODE_TYPE.ElementNode */) {
998
+ relocateSlotContent(childNode);
999
+ }
1000
+ }
1001
+ };
1002
+ const isNodeLocatedInSlot = (nodeToRelocate, slotNameAttr) => {
1003
+ if (nodeToRelocate.nodeType === 1 /* NODE_TYPE.ElementNode */) {
1004
+ if (nodeToRelocate.getAttribute('slot') === null && slotNameAttr === '') {
1005
+ return true;
1006
+ }
1007
+ if (nodeToRelocate.getAttribute('slot') === slotNameAttr) {
1008
+ return true;
1009
+ }
1010
+ return false;
1011
+ }
1012
+ if (nodeToRelocate['s-sn'] === slotNameAttr) {
1013
+ return true;
1014
+ }
1015
+ return slotNameAttr === '';
1016
+ };
735
1017
  const callNodeRefs = (vNode) => {
736
1018
  {
737
1019
  vNode.$attrs$ && vNode.$attrs$.ref && vNode.$attrs$.ref(null);
738
1020
  vNode.$children$ && vNode.$children$.map(callNodeRefs);
739
1021
  }
740
1022
  };
741
- /**
742
- * The main entry point for Stencil's virtual DOM-based rendering engine
743
- *
744
- * Given a {@link d.HostRef} container and some virtual DOM nodes, this
745
- * function will handle creating a virtual DOM tree with a single root, patching
746
- * the current virtual DOM tree onto an old one (if any), dealing with slot
747
- * relocation, and reflecting attributes.
748
- *
749
- * @param hostRef data needed to root and render the virtual DOM tree, such as
750
- * the DOM node into which it should be rendered.
751
- * @param renderFnResults the virtual DOM nodes to be rendered
752
- */
753
1023
  const renderVdom = (hostRef, renderFnResults) => {
754
1024
  const hostElm = hostRef.$hostElement$;
1025
+ const cmpMeta = hostRef.$cmpMeta$;
755
1026
  const oldVNode = hostRef.$vnode$ || newVNode(null, null);
756
1027
  const rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
757
1028
  hostTagName = hostElm.tagName;
@@ -762,8 +1033,90 @@ const renderVdom = (hostRef, renderFnResults) => {
762
1033
  {
763
1034
  scopeId = hostElm['s-sc'];
764
1035
  }
1036
+ {
1037
+ contentRef = hostElm['s-cr'];
1038
+ useNativeShadowDom = (cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) !== 0;
1039
+ // always reset
1040
+ checkSlotFallbackVisibility = false;
1041
+ }
765
1042
  // synchronous patch
766
1043
  patch(oldVNode, rootVnode);
1044
+ {
1045
+ // while we're moving nodes around existing nodes, temporarily disable
1046
+ // the disconnectCallback from working
1047
+ plt.$flags$ |= 1 /* PLATFORM_FLAGS.isTmpDisconnected */;
1048
+ if (checkSlotRelocate) {
1049
+ relocateSlotContent(rootVnode.$elm$);
1050
+ let relocateData;
1051
+ let nodeToRelocate;
1052
+ let orgLocationNode;
1053
+ let parentNodeRef;
1054
+ let insertBeforeNode;
1055
+ let refNode;
1056
+ let i = 0;
1057
+ for (; i < relocateNodes.length; i++) {
1058
+ relocateData = relocateNodes[i];
1059
+ nodeToRelocate = relocateData.$nodeToRelocate$;
1060
+ if (!nodeToRelocate['s-ol']) {
1061
+ // add a reference node marking this node's original location
1062
+ // keep a reference to this node for later lookups
1063
+ orgLocationNode =
1064
+ doc.createTextNode('');
1065
+ orgLocationNode['s-nr'] = nodeToRelocate;
1066
+ nodeToRelocate.parentNode.insertBefore((nodeToRelocate['s-ol'] = orgLocationNode), nodeToRelocate);
1067
+ }
1068
+ }
1069
+ for (i = 0; i < relocateNodes.length; i++) {
1070
+ relocateData = relocateNodes[i];
1071
+ nodeToRelocate = relocateData.$nodeToRelocate$;
1072
+ if (relocateData.$slotRefNode$) {
1073
+ // by default we're just going to insert it directly
1074
+ // after the slot reference node
1075
+ parentNodeRef = relocateData.$slotRefNode$.parentNode;
1076
+ insertBeforeNode = relocateData.$slotRefNode$.nextSibling;
1077
+ orgLocationNode = nodeToRelocate['s-ol'];
1078
+ while ((orgLocationNode = orgLocationNode.previousSibling)) {
1079
+ refNode = orgLocationNode['s-nr'];
1080
+ if (refNode && refNode['s-sn'] === nodeToRelocate['s-sn'] && parentNodeRef === refNode.parentNode) {
1081
+ refNode = refNode.nextSibling;
1082
+ if (!refNode || !refNode['s-nr']) {
1083
+ insertBeforeNode = refNode;
1084
+ break;
1085
+ }
1086
+ }
1087
+ }
1088
+ if ((!insertBeforeNode && parentNodeRef !== nodeToRelocate.parentNode) ||
1089
+ nodeToRelocate.nextSibling !== insertBeforeNode) {
1090
+ // we've checked that it's worth while to relocate
1091
+ // since that the node to relocate
1092
+ // has a different next sibling or parent relocated
1093
+ if (nodeToRelocate !== insertBeforeNode) {
1094
+ if (!nodeToRelocate['s-hn'] && nodeToRelocate['s-ol']) {
1095
+ // probably a component in the index.html that doesn't have it's hostname set
1096
+ nodeToRelocate['s-hn'] = nodeToRelocate['s-ol'].parentNode.nodeName;
1097
+ }
1098
+ // add it back to the dom but in its new home
1099
+ parentNodeRef.insertBefore(nodeToRelocate, insertBeforeNode);
1100
+ }
1101
+ }
1102
+ }
1103
+ else {
1104
+ // this node doesn't have a slot home to go to, so let's hide it
1105
+ if (nodeToRelocate.nodeType === 1 /* NODE_TYPE.ElementNode */) {
1106
+ nodeToRelocate.hidden = true;
1107
+ }
1108
+ }
1109
+ }
1110
+ }
1111
+ if (checkSlotFallbackVisibility) {
1112
+ updateFallbackSlotVisibility(rootVnode.$elm$);
1113
+ }
1114
+ // done moving nodes around
1115
+ // allow the disconnect callback to work again
1116
+ plt.$flags$ &= ~1 /* PLATFORM_FLAGS.isTmpDisconnected */;
1117
+ // always reset
1118
+ relocateNodes.length = 0;
1119
+ }
767
1120
  };
768
1121
  const attachToAncestor = (hostRef, ancestorComponent) => {
769
1122
  if (ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
@@ -1181,6 +1534,15 @@ const connectedCallback = (elm) => {
1181
1534
  if (!(hostRef.$flags$ & 1 /* HOST_FLAGS.hasConnected */)) {
1182
1535
  // first time this component has connected
1183
1536
  hostRef.$flags$ |= 1 /* HOST_FLAGS.hasConnected */;
1537
+ {
1538
+ // initUpdate
1539
+ // if the slot polyfill is required we'll need to put some nodes
1540
+ // in here to act as original content anchors as we move nodes around
1541
+ // host element has been connected to the DOM
1542
+ if ((cmpMeta.$flags$ & (4 /* CMP_FLAGS.hasSlotRelocation */ | 8 /* CMP_FLAGS.needsShadowDomShim */))) {
1543
+ setContentReference(elm);
1544
+ }
1545
+ }
1184
1546
  {
1185
1547
  // find the first ancestor component (if there is one) and register
1186
1548
  // this component as one of the actively loading child components for its ancestor
@@ -1222,6 +1584,17 @@ const connectedCallback = (elm) => {
1222
1584
  endConnected();
1223
1585
  }
1224
1586
  };
1587
+ const setContentReference = (elm) => {
1588
+ // only required when we're NOT using native shadow dom (slot)
1589
+ // or this browser doesn't support native shadow dom
1590
+ // and this host element was NOT created with SSR
1591
+ // let's pick out the inner content for slot projection
1592
+ // create a node to represent where the original
1593
+ // content was first placed, which is useful later on
1594
+ const contentRefElm = (elm['s-cr'] = doc.createComment(''));
1595
+ contentRefElm['s-cn'] = true;
1596
+ elm.insertBefore(contentRefElm, elm.firstChild);
1597
+ };
1225
1598
  const disconnectedCallback = (elm) => {
1226
1599
  if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
1227
1600
  const hostRef = getHostRef(elm);
@@ -1238,7 +1611,6 @@ const disconnectedCallback = (elm) => {
1238
1611
  }
1239
1612
  };
1240
1613
  const bootstrapLazy = (lazyBundles, options = {}) => {
1241
- var _a;
1242
1614
  const endBootstrap = createTime();
1243
1615
  const cmpTags = [];
1244
1616
  const exclude = options.exclude || [];
@@ -1318,11 +1690,6 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
1318
1690
  {
1319
1691
  visibilityStyle.innerHTML = cmpTags + HYDRATED_CSS;
1320
1692
  visibilityStyle.setAttribute('data-styles', '');
1321
- // Apply CSP nonce to the style tag if it exists
1322
- const nonce = (_a = plt.$nonce$) !== null && _a !== void 0 ? _a : queryNonceMetaTagContent(doc);
1323
- if (nonce != null) {
1324
- visibilityStyle.setAttribute('nonce', nonce);
1325
- }
1326
1693
  head.insertBefore(visibilityStyle, metaCharset ? metaCharset.nextSibling : head.firstChild);
1327
1694
  }
1328
1695
  // Process deferred connectedCallbacks now all components have been registered
@@ -1367,13 +1734,6 @@ const hostListenerProxy = (hostRef, methodName) => (ev) => {
1367
1734
  };
1368
1735
  // prettier-ignore
1369
1736
  const hostListenerOpts = (flags) => (flags & 2 /* LISTENER_FLAGS.Capture */) !== 0;
1370
- /**
1371
- * Assigns the given value to the nonce property on the runtime platform object.
1372
- * During runtime, this value is used to set the nonce attribute on all dynamically created script and style tags.
1373
- * @param nonce The value to be assigned to the platform nonce property.
1374
- * @returns void
1375
- */
1376
- const setNonce = (nonce) => (plt.$nonce$ = nonce);
1377
1737
  const hostRefs = /*@__PURE__*/ new WeakMap();
1378
1738
  const getHostRef = (ref) => hostRefs.get(ref);
1379
1739
  const registerInstance = (lazyInstance, hostRef) => hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef);
@@ -1490,4 +1850,3 @@ exports.createEvent = createEvent;
1490
1850
  exports.h = h;
1491
1851
  exports.promiseResolve = promiseResolve;
1492
1852
  exports.registerInstance = registerInstance;
1493
- exports.setNonce = setNonce;