@justifi/webcomponents 0.2.0 → 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 (50) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/dist/cjs/{index-3947d225.js → index-ca2cd154.js} +391 -96
  3. package/dist/cjs/justifi-bank-account-form.cjs.entry.js +1 -1
  4. package/dist/cjs/justifi-billing-form.cjs.entry.js +1 -1
  5. package/dist/cjs/justifi-card-form.cjs.entry.js +1 -1
  6. package/dist/cjs/justifi-payment-form.cjs.entry.js +17 -0
  7. package/dist/cjs/justifi-payment-method-form.cjs.entry.js +84 -2
  8. package/dist/cjs/justifi-payments-list.cjs.entry.js +1 -1
  9. package/dist/cjs/loader.cjs.js +3 -4
  10. package/dist/cjs/select-input_2.cjs.entry.js +1 -1
  11. package/dist/cjs/webcomponents.cjs.js +3 -7
  12. package/dist/collection/collection-manifest.json +3 -2
  13. package/dist/collection/components/card-form/card-form.stories.js +132 -0
  14. package/dist/collection/components/payment-form/payment-form.js +31 -0
  15. package/dist/collection/components/payment-method-form/payment-method-form.js +3 -1
  16. package/dist/components/index.d.ts +1 -9
  17. package/dist/components/index.js +2 -1
  18. package/dist/components/justifi-payment-form.d.ts +11 -0
  19. package/dist/components/justifi-payment-form.js +32 -0
  20. package/dist/components/payment-method-form.js +83 -1
  21. package/dist/esm/{index-0bcf33c4.js → index-05706eb5.js} +392 -96
  22. package/dist/esm/justifi-bank-account-form.entry.js +1 -1
  23. package/dist/esm/justifi-billing-form.entry.js +1 -1
  24. package/dist/esm/justifi-card-form.entry.js +1 -1
  25. package/dist/esm/justifi-payment-form.entry.js +13 -0
  26. package/dist/esm/justifi-payment-method-form.entry.js +84 -2
  27. package/dist/esm/justifi-payments-list.entry.js +1 -1
  28. package/dist/esm/loader.js +3 -4
  29. package/dist/esm/polyfills/css-shim.js +1 -1
  30. package/dist/esm/select-input_2.entry.js +1 -1
  31. package/dist/esm/webcomponents.js +3 -4
  32. package/dist/types/api/Api.d.ts +1 -1
  33. package/dist/types/api/Payment.d.ts +1 -1
  34. package/dist/types/components/card-form/card-form.stories.d.ts +14 -0
  35. package/dist/types/components/payment-form/payment-form.d.ts +4 -0
  36. package/dist/types/components.d.ts +15 -0
  37. package/dist/types/stencil-public-runtime.d.ts +3 -59
  38. package/dist/webcomponents/{p-0cddfd4f.entry.js → p-3809130a.entry.js} +1 -1
  39. package/dist/webcomponents/{p-17badb93.entry.js → p-67be9585.entry.js} +1 -1
  40. package/dist/webcomponents/{p-d3dc4e0a.entry.js → p-787671b9.entry.js} +1 -1
  41. package/dist/webcomponents/{p-864e32fd.entry.js → p-87654bf4.entry.js} +1 -1
  42. package/dist/webcomponents/p-8ee06fd1.js +2 -0
  43. package/dist/webcomponents/p-94ef2d0e.entry.js +1 -0
  44. package/dist/webcomponents/p-c07191dc.entry.js +1 -0
  45. package/dist/webcomponents/{p-7fd07095.entry.js → p-e5b0f047.entry.js} +1 -1
  46. package/dist/webcomponents/webcomponents.esm.js +1 -1
  47. package/loader/index.d.ts +0 -9
  48. package/package.json +16 -3
  49. package/dist/webcomponents/p-cecf0fe8.entry.js +0 -1
  50. package/dist/webcomponents/p-e82c9746.js +0 -2
@@ -9,7 +9,11 @@ const NAMESPACE = 'webcomponents';
9
9
  * Modified for Stencil's renderer and slot projection
10
10
  */
11
11
  let scopeId;
12
+ let contentRef;
12
13
  let hostTagName;
14
+ let useNativeShadowDom = false;
15
+ let checkSlotFallbackVisibility = false;
16
+ let checkSlotRelocate = false;
13
17
  let isSvgMode = false;
14
18
  let queuePending = false;
15
19
  const createTime = (fnName, tagName = '') => {
@@ -41,18 +45,6 @@ const isComplexType = (o) => {
41
45
  o = typeof o;
42
46
  return o === 'object' || o === 'function';
43
47
  };
44
- /**
45
- * Helper method for querying a `meta` tag that contains a nonce value
46
- * out of a DOM's head.
47
- *
48
- * @param doc The DOM containing the `head` to query against
49
- * @returns The content of the meta tag representing the nonce value, or `undefined` if no tag
50
- * exists or the tag has no content.
51
- */
52
- function queryNonceMetaTagContent(doc) {
53
- var _a, _b, _c;
54
- 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;
55
- }
56
48
  /**
57
49
  * Production h() function based on Preact by
58
50
  * Jason Miller (@developit)
@@ -61,10 +53,12 @@ function queryNonceMetaTagContent(doc) {
61
53
  *
62
54
  * Modified for Stencil's compiler and vdom
63
55
  */
56
+ // const stack: any[] = [];
64
57
  // export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, child?: d.ChildType): d.VNode;
65
58
  // export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, ...children: d.ChildType[]): d.VNode;
66
59
  const h = (nodeName, vnodeData, ...children) => {
67
60
  let child = null;
61
+ let slotName = null;
68
62
  let simple = false;
69
63
  let lastSimple = false;
70
64
  const vNodeChildren = [];
@@ -92,6 +86,9 @@ const h = (nodeName, vnodeData, ...children) => {
92
86
  };
93
87
  walk(children);
94
88
  if (vnodeData) {
89
+ if (vnodeData.name) {
90
+ slotName = vnodeData.name;
91
+ }
95
92
  {
96
93
  const classData = vnodeData.className || vnodeData.class;
97
94
  if (classData) {
@@ -109,16 +106,11 @@ const h = (nodeName, vnodeData, ...children) => {
109
106
  if (vNodeChildren.length > 0) {
110
107
  vnode.$children$ = vNodeChildren;
111
108
  }
109
+ {
110
+ vnode.$name$ = slotName;
111
+ }
112
112
  return vnode;
113
113
  };
114
- /**
115
- * A utility function for creating a virtual DOM node from a tag and some
116
- * possible text content.
117
- *
118
- * @param tag the tag for this element
119
- * @param text possible text content for the node
120
- * @returns a newly-minted virtual DOM node
121
- */
122
114
  const newVNode = (tag, text) => {
123
115
  const vnode = {
124
116
  $flags$: 0,
@@ -130,15 +122,12 @@ const newVNode = (tag, text) => {
130
122
  {
131
123
  vnode.$attrs$ = null;
132
124
  }
125
+ {
126
+ vnode.$name$ = null;
127
+ }
133
128
  return vnode;
134
129
  };
135
130
  const Host = {};
136
- /**
137
- * Check whether a given node is a Host node or not
138
- *
139
- * @param node the virtual DOM node to check
140
- * @returns whether it's a Host node or not
141
- */
142
131
  const isHost = (node) => node && node.$tag$ === Host;
143
132
  /**
144
133
  * Parse a new property value for a given property type.
@@ -222,7 +211,6 @@ const registerStyle = (scopeId, cssText, allowCS) => {
222
211
  styles.set(scopeId, style);
223
212
  };
224
213
  const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
225
- var _a;
226
214
  let scopeId = getScopeId(cmpMeta);
227
215
  const style = styles.get(scopeId);
228
216
  // if an element is NOT connected then getRootNode() will return the wrong root node
@@ -242,11 +230,6 @@ const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
242
230
  styleElm = doc.createElement('style');
243
231
  styleElm.innerHTML = style;
244
232
  }
245
- // Apply CSP nonce to the style tag if it exists
246
- const nonce = (_a = plt.$nonce$) !== null && _a !== void 0 ? _a : queryNonceMetaTagContent(doc);
247
- if (nonce != null) {
248
- styleElm.setAttribute('nonce', nonce);
249
- }
250
233
  styleContainerNode.insertBefore(styleElm, styleContainerNode.querySelector('link'));
251
234
  }
252
235
  if (appliedStyles) {
@@ -446,13 +429,36 @@ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
446
429
  let i = 0;
447
430
  let elm;
448
431
  let childNode;
432
+ let oldVNode;
433
+ if (!useNativeShadowDom) {
434
+ // remember for later we need to check to relocate nodes
435
+ checkSlotRelocate = true;
436
+ if (newVNode.$tag$ === 'slot') {
437
+ if (scopeId) {
438
+ // scoped css needs to add its scoped id to the parent element
439
+ parentElm.classList.add(scopeId + '-s');
440
+ }
441
+ newVNode.$flags$ |= newVNode.$children$
442
+ ? // slot element has fallback content
443
+ 2 /* VNODE_FLAGS.isSlotFallback */
444
+ : // slot element does not have fallback content
445
+ 1 /* VNODE_FLAGS.isSlotReference */;
446
+ }
447
+ }
449
448
  if (newVNode.$text$ !== null) {
450
449
  // create text node
451
450
  elm = newVNode.$elm$ = doc.createTextNode(newVNode.$text$);
452
451
  }
452
+ else if (newVNode.$flags$ & 1 /* VNODE_FLAGS.isSlotReference */) {
453
+ // create a slot reference node
454
+ elm = newVNode.$elm$ =
455
+ doc.createTextNode('');
456
+ }
453
457
  else {
454
458
  // create element
455
- elm = newVNode.$elm$ = (doc.createElement(newVNode.$tag$));
459
+ elm = newVNode.$elm$ = (doc.createElement(newVNode.$flags$ & 2 /* VNODE_FLAGS.isSlotFallback */
460
+ ? 'slot-fb'
461
+ : newVNode.$tag$));
456
462
  // add css classes, attrs, props, listeners, etc.
457
463
  {
458
464
  updateElement(null, newVNode, isSvgMode);
@@ -465,7 +471,7 @@ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
465
471
  if (newVNode.$children$) {
466
472
  for (i = 0; i < newVNode.$children$.length; ++i) {
467
473
  // create the node
468
- childNode = createElm(oldParentVNode, newVNode, i);
474
+ childNode = createElm(oldParentVNode, newVNode, i, elm);
469
475
  // return node could have been null
470
476
  if (childNode) {
471
477
  // append our new node
@@ -474,57 +480,85 @@ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
474
480
  }
475
481
  }
476
482
  }
483
+ {
484
+ elm['s-hn'] = hostTagName;
485
+ if (newVNode.$flags$ & (2 /* VNODE_FLAGS.isSlotFallback */ | 1 /* VNODE_FLAGS.isSlotReference */)) {
486
+ // remember the content reference comment
487
+ elm['s-sr'] = true;
488
+ // remember the content reference comment
489
+ elm['s-cr'] = contentRef;
490
+ // remember the slot name, or empty string for default slot
491
+ elm['s-sn'] = newVNode.$name$ || '';
492
+ // check if we've got an old vnode for this slot
493
+ oldVNode = oldParentVNode && oldParentVNode.$children$ && oldParentVNode.$children$[childIndex];
494
+ if (oldVNode && oldVNode.$tag$ === newVNode.$tag$ && oldParentVNode.$elm$) {
495
+ // we've got an old slot vnode and the wrapper is being replaced
496
+ // so let's move the old slot content back to it's original location
497
+ putBackInOriginalLocation(oldParentVNode.$elm$, false);
498
+ }
499
+ }
500
+ }
477
501
  return elm;
478
502
  };
479
- /**
480
- * Create DOM nodes corresponding to a list of {@link d.Vnode} objects and
481
- * add them to the DOM in the appropriate place.
482
- *
483
- * @param parentElm the DOM node which should be used as a parent for the new
484
- * DOM nodes
485
- * @param before a child of the `parentElm` which the new children should be
486
- * inserted before (optional)
487
- * @param parentVNode the parent virtual DOM node
488
- * @param vnodes the new child virtual DOM nodes to produce DOM nodes for
489
- * @param startIdx the index in the child virtual DOM nodes at which to start
490
- * creating DOM nodes (inclusive)
491
- * @param endIdx the index in the child virtual DOM nodes at which to stop
492
- * creating DOM nodes (inclusive)
493
- */
503
+ const putBackInOriginalLocation = (parentElm, recursive) => {
504
+ plt.$flags$ |= 1 /* PLATFORM_FLAGS.isTmpDisconnected */;
505
+ const oldSlotChildNodes = parentElm.childNodes;
506
+ for (let i = oldSlotChildNodes.length - 1; i >= 0; i--) {
507
+ const childNode = oldSlotChildNodes[i];
508
+ if (childNode['s-hn'] !== hostTagName && childNode['s-ol']) {
509
+ // // this child node in the old element is from another component
510
+ // // remove this node from the old slot's parent
511
+ // childNode.remove();
512
+ // and relocate it back to it's original location
513
+ parentReferenceNode(childNode).insertBefore(childNode, referenceNode(childNode));
514
+ // remove the old original location comment entirely
515
+ // later on the patch function will know what to do
516
+ // and move this to the correct spot in need be
517
+ childNode['s-ol'].remove();
518
+ childNode['s-ol'] = undefined;
519
+ checkSlotRelocate = true;
520
+ }
521
+ if (recursive) {
522
+ putBackInOriginalLocation(childNode, recursive);
523
+ }
524
+ }
525
+ plt.$flags$ &= ~1 /* PLATFORM_FLAGS.isTmpDisconnected */;
526
+ };
494
527
  const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) => {
495
- let containerElm = (parentElm);
528
+ let containerElm = ((parentElm['s-cr'] && parentElm['s-cr'].parentNode) || parentElm);
496
529
  let childNode;
497
530
  if (containerElm.shadowRoot && containerElm.tagName === hostTagName) {
498
531
  containerElm = containerElm.shadowRoot;
499
532
  }
500
533
  for (; startIdx <= endIdx; ++startIdx) {
501
534
  if (vnodes[startIdx]) {
502
- childNode = createElm(null, parentVNode, startIdx);
535
+ childNode = createElm(null, parentVNode, startIdx, parentElm);
503
536
  if (childNode) {
504
537
  vnodes[startIdx].$elm$ = childNode;
505
- containerElm.insertBefore(childNode, before);
538
+ containerElm.insertBefore(childNode, referenceNode(before) );
506
539
  }
507
540
  }
508
541
  }
509
542
  };
510
- /**
511
- * Remove the DOM elements corresponding to a list of {@link d.VNode} objects.
512
- * This can be used to, for instance, clean up after a list of children which
513
- * should no longer be shown.
514
- *
515
- * This function also handles some of Stencil's slot relocation logic.
516
- *
517
- * @param vnodes a list of virtual DOM nodes to remove
518
- * @param startIdx the index at which to start removing nodes (inclusive)
519
- * @param endIdx the index at which to stop removing nodes (inclusive)
520
- * @param vnode a VNode
521
- * @param elm an element
522
- */
523
543
  const removeVnodes = (vnodes, startIdx, endIdx, vnode, elm) => {
524
544
  for (; startIdx <= endIdx; ++startIdx) {
525
545
  if ((vnode = vnodes[startIdx])) {
526
546
  elm = vnode.$elm$;
527
547
  callNodeRefs(vnode);
548
+ {
549
+ // we're removing this element
550
+ // so it's possible we need to show slot fallback content now
551
+ checkSlotFallbackVisibility = true;
552
+ if (elm['s-ol']) {
553
+ // remove the original location comment
554
+ elm['s-ol'].remove();
555
+ }
556
+ else {
557
+ // it's possible that child nodes of the node
558
+ // that's being removed are slot nodes
559
+ putBackInOriginalLocation(elm, true);
560
+ }
561
+ }
528
562
  // remove the vnode's element from the dom
529
563
  elm.remove();
530
564
  }
@@ -640,6 +674,23 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
640
674
  newEndVnode = newCh[--newEndIdx];
641
675
  }
642
676
  else if (isSameVnode(oldStartVnode, newEndVnode)) {
677
+ // case: "Vnode moved right"
678
+ //
679
+ // We've found that the last node in our window on the new children is
680
+ // the same VNode as the _first_ node in our window on the old children
681
+ // we're dealing with now. Visually, this is the layout of these two
682
+ // nodes:
683
+ //
684
+ // newCh: [..., newStartVnode , ... , newEndVnode , ...]
685
+ // ^^^^^^^^^^^
686
+ // oldCh: [..., oldStartVnode , ... , oldEndVnode , ...]
687
+ // ^^^^^^^^^^^^^
688
+ //
689
+ // In this situation we need to patch `newEndVnode` onto `oldStartVnode`
690
+ // and move the DOM element for `oldStartVnode`.
691
+ if ((oldStartVnode.$tag$ === 'slot' || newEndVnode.$tag$ === 'slot')) {
692
+ putBackInOriginalLocation(oldStartVnode.$elm$.parentNode, false);
693
+ }
643
694
  patch(oldStartVnode, newEndVnode);
644
695
  // We need to move the element for `oldStartVnode` into a position which
645
696
  // will be appropriate for `newEndVnode`. For this we can use
@@ -663,6 +714,24 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
663
714
  newEndVnode = newCh[--newEndIdx];
664
715
  }
665
716
  else if (isSameVnode(oldEndVnode, newStartVnode)) {
717
+ // case: "Vnode moved left"
718
+ //
719
+ // We've found that the first node in our window on the new children is
720
+ // the same VNode as the _last_ node in our window on the old children.
721
+ // Visually, this is the layout of these two nodes:
722
+ //
723
+ // newCh: [..., newStartVnode , ... , newEndVnode , ...]
724
+ // ^^^^^^^^^^^^^
725
+ // oldCh: [..., oldStartVnode , ... , oldEndVnode , ...]
726
+ // ^^^^^^^^^^^
727
+ //
728
+ // In this situation we need to patch `newStartVnode` onto `oldEndVnode`
729
+ // (which will handle updating any changed attributes, reconciling their
730
+ // children etc) but we also need to move the DOM node to which
731
+ // `oldEndVnode` corresponds.
732
+ if ((oldStartVnode.$tag$ === 'slot' || newEndVnode.$tag$ === 'slot')) {
733
+ putBackInOriginalLocation(oldEndVnode.$elm$.parentNode, false);
734
+ }
666
735
  patch(oldEndVnode, newStartVnode);
667
736
  // We've already checked above if `oldStartVnode` and `newStartVnode` are
668
737
  // the same node, so since we're here we know that they are not. Thus we
@@ -679,13 +748,13 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
679
748
  // the key of the first new child OR the build is not using `key`
680
749
  // attributes at all. In either case we need to create a new element
681
750
  // for the new node.
682
- node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx);
751
+ node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx, parentElm);
683
752
  newStartVnode = newCh[++newStartIdx];
684
753
  }
685
754
  if (node) {
686
755
  // if we created a new node then handle inserting it to the DOM
687
756
  {
688
- oldStartVnode.$elm$.parentNode.insertBefore(node, oldStartVnode.$elm$);
757
+ parentReferenceNode(oldStartVnode.$elm$).insertBefore(node, referenceNode(oldStartVnode.$elm$));
689
758
  }
690
759
  }
691
760
  }
@@ -712,8 +781,7 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
712
781
  *
713
782
  * So, in other words, if `key` attrs are not set on VNodes which may be
714
783
  * changing order within a `children` array or something along those lines then
715
- * we could obtain a false negative and then have to do needless re-rendering
716
- * (i.e. we'd say two VNodes aren't equal when in fact they should be).
784
+ * we could obtain a false positive and then have to do needless re-rendering.
717
785
  *
718
786
  * @param leftVNode the first VNode to check
719
787
  * @param rightVNode the second VNode to check
@@ -723,10 +791,21 @@ const isSameVnode = (leftVNode, rightVNode) => {
723
791
  // compare if two vnode to see if they're "technically" the same
724
792
  // need to have the same element tag, and same key to be the same
725
793
  if (leftVNode.$tag$ === rightVNode.$tag$) {
794
+ if (leftVNode.$tag$ === 'slot') {
795
+ return leftVNode.$name$ === rightVNode.$name$;
796
+ }
726
797
  return true;
727
798
  }
728
799
  return false;
729
800
  };
801
+ const referenceNode = (node) => {
802
+ // this node was relocated to a new location in the dom
803
+ // because of some other component's slot
804
+ // but we still have an html comment in place of where
805
+ // it's original location was according to it's original vdom
806
+ return (node && node['s-ol']) || node;
807
+ };
808
+ const parentReferenceNode = (node) => (node['s-ol'] ? node['s-ol'] : node).parentNode;
730
809
  /**
731
810
  * Handle reconciling an outdated VNode with a new one which corresponds to
732
811
  * it. This function handles flushing updates to the DOM and reconciling the
@@ -739,10 +818,14 @@ const patch = (oldVNode, newVNode) => {
739
818
  const elm = (newVNode.$elm$ = oldVNode.$elm$);
740
819
  const oldChildren = oldVNode.$children$;
741
820
  const newChildren = newVNode.$children$;
821
+ const tag = newVNode.$tag$;
742
822
  const text = newVNode.$text$;
823
+ let defaultHolder;
743
824
  if (text === null) {
744
825
  {
745
- {
826
+ if (tag === 'slot')
827
+ ;
828
+ else {
746
829
  // either this is the first render of an element OR it's an update
747
830
  // AND we already know it's possible it could have changed
748
831
  // this updates the element's css classes, attrs, props, listeners, etc.
@@ -768,32 +851,156 @@ const patch = (oldVNode, newVNode) => {
768
851
  removeVnodes(oldChildren, 0, oldChildren.length - 1);
769
852
  }
770
853
  }
854
+ else if ((defaultHolder = elm['s-cr'])) {
855
+ // this element has slotted content
856
+ defaultHolder.parentNode.textContent = text;
857
+ }
771
858
  else if (oldVNode.$text$ !== text) {
772
859
  // update the text content for the text only vnode
773
860
  // and also only if the text is different than before
774
861
  elm.data = text;
775
862
  }
776
863
  };
864
+ const updateFallbackSlotVisibility = (elm) => {
865
+ // tslint:disable-next-line: prefer-const
866
+ const childNodes = elm.childNodes;
867
+ let childNode;
868
+ let i;
869
+ let ilen;
870
+ let j;
871
+ let slotNameAttr;
872
+ let nodeType;
873
+ for (i = 0, ilen = childNodes.length; i < ilen; i++) {
874
+ childNode = childNodes[i];
875
+ if (childNode.nodeType === 1 /* NODE_TYPE.ElementNode */) {
876
+ if (childNode['s-sr']) {
877
+ // this is a slot fallback node
878
+ // get the slot name for this slot reference node
879
+ slotNameAttr = childNode['s-sn'];
880
+ // by default always show a fallback slot node
881
+ // then hide it if there are other slots in the light dom
882
+ childNode.hidden = false;
883
+ for (j = 0; j < ilen; j++) {
884
+ nodeType = childNodes[j].nodeType;
885
+ if (childNodes[j]['s-hn'] !== childNode['s-hn'] || slotNameAttr !== '') {
886
+ // this sibling node is from a different component OR is a named fallback slot node
887
+ if (nodeType === 1 /* NODE_TYPE.ElementNode */ && slotNameAttr === childNodes[j].getAttribute('slot')) {
888
+ childNode.hidden = true;
889
+ break;
890
+ }
891
+ }
892
+ else {
893
+ // this is a default fallback slot node
894
+ // any element or text node (with content)
895
+ // should hide the default fallback slot node
896
+ if (nodeType === 1 /* NODE_TYPE.ElementNode */ ||
897
+ (nodeType === 3 /* NODE_TYPE.TextNode */ && childNodes[j].textContent.trim() !== '')) {
898
+ childNode.hidden = true;
899
+ break;
900
+ }
901
+ }
902
+ }
903
+ }
904
+ // keep drilling down
905
+ updateFallbackSlotVisibility(childNode);
906
+ }
907
+ }
908
+ };
909
+ const relocateNodes = [];
910
+ const relocateSlotContent = (elm) => {
911
+ // tslint:disable-next-line: prefer-const
912
+ let childNode;
913
+ let node;
914
+ let hostContentNodes;
915
+ let slotNameAttr;
916
+ let relocateNodeData;
917
+ let j;
918
+ let i = 0;
919
+ const childNodes = elm.childNodes;
920
+ const ilen = childNodes.length;
921
+ for (; i < ilen; i++) {
922
+ childNode = childNodes[i];
923
+ if (childNode['s-sr'] && (node = childNode['s-cr']) && node.parentNode) {
924
+ // first got the content reference comment node
925
+ // then we got it's parent, which is where all the host content is in now
926
+ hostContentNodes = node.parentNode.childNodes;
927
+ slotNameAttr = childNode['s-sn'];
928
+ for (j = hostContentNodes.length - 1; j >= 0; j--) {
929
+ node = hostContentNodes[j];
930
+ if (!node['s-cn'] && !node['s-nr'] && node['s-hn'] !== childNode['s-hn']) {
931
+ // let's do some relocating to its new home
932
+ // but never relocate a content reference node
933
+ // that is suppose to always represent the original content location
934
+ if (isNodeLocatedInSlot(node, slotNameAttr)) {
935
+ // it's possible we've already decided to relocate this node
936
+ relocateNodeData = relocateNodes.find((r) => r.$nodeToRelocate$ === node);
937
+ // made some changes to slots
938
+ // let's make sure we also double check
939
+ // fallbacks are correctly hidden or shown
940
+ checkSlotFallbackVisibility = true;
941
+ node['s-sn'] = node['s-sn'] || slotNameAttr;
942
+ if (relocateNodeData) {
943
+ // previously we never found a slot home for this node
944
+ // but turns out we did, so let's remember it now
945
+ relocateNodeData.$slotRefNode$ = childNode;
946
+ }
947
+ else {
948
+ // add to our list of nodes to relocate
949
+ relocateNodes.push({
950
+ $slotRefNode$: childNode,
951
+ $nodeToRelocate$: node,
952
+ });
953
+ }
954
+ if (node['s-sr']) {
955
+ relocateNodes.map((relocateNode) => {
956
+ if (isNodeLocatedInSlot(relocateNode.$nodeToRelocate$, node['s-sn'])) {
957
+ relocateNodeData = relocateNodes.find((r) => r.$nodeToRelocate$ === node);
958
+ if (relocateNodeData && !relocateNode.$slotRefNode$) {
959
+ relocateNode.$slotRefNode$ = relocateNodeData.$slotRefNode$;
960
+ }
961
+ }
962
+ });
963
+ }
964
+ }
965
+ else if (!relocateNodes.some((r) => r.$nodeToRelocate$ === node)) {
966
+ // so far this element does not have a slot home, not setting slotRefNode on purpose
967
+ // if we never find a home for this element then we'll need to hide it
968
+ relocateNodes.push({
969
+ $nodeToRelocate$: node,
970
+ });
971
+ }
972
+ }
973
+ }
974
+ }
975
+ if (childNode.nodeType === 1 /* NODE_TYPE.ElementNode */) {
976
+ relocateSlotContent(childNode);
977
+ }
978
+ }
979
+ };
980
+ const isNodeLocatedInSlot = (nodeToRelocate, slotNameAttr) => {
981
+ if (nodeToRelocate.nodeType === 1 /* NODE_TYPE.ElementNode */) {
982
+ if (nodeToRelocate.getAttribute('slot') === null && slotNameAttr === '') {
983
+ return true;
984
+ }
985
+ if (nodeToRelocate.getAttribute('slot') === slotNameAttr) {
986
+ return true;
987
+ }
988
+ return false;
989
+ }
990
+ if (nodeToRelocate['s-sn'] === slotNameAttr) {
991
+ return true;
992
+ }
993
+ return slotNameAttr === '';
994
+ };
777
995
  const callNodeRefs = (vNode) => {
778
996
  {
779
997
  vNode.$attrs$ && vNode.$attrs$.ref && vNode.$attrs$.ref(null);
780
998
  vNode.$children$ && vNode.$children$.map(callNodeRefs);
781
999
  }
782
1000
  };
783
- /**
784
- * The main entry point for Stencil's virtual DOM-based rendering engine
785
- *
786
- * Given a {@link d.HostRef} container and some virtual DOM nodes, this
787
- * function will handle creating a virtual DOM tree with a single root, patching
788
- * the current virtual DOM tree onto an old one (if any), dealing with slot
789
- * relocation, and reflecting attributes.
790
- *
791
- * @param hostRef data needed to root and render the virtual DOM tree, such as
792
- * the DOM node into which it should be rendered.
793
- * @param renderFnResults the virtual DOM nodes to be rendered
794
- */
795
1001
  const renderVdom = (hostRef, renderFnResults) => {
796
1002
  const hostElm = hostRef.$hostElement$;
1003
+ const cmpMeta = hostRef.$cmpMeta$;
797
1004
  const oldVNode = hostRef.$vnode$ || newVNode(null, null);
798
1005
  const rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
799
1006
  hostTagName = hostElm.tagName;
@@ -804,8 +1011,90 @@ const renderVdom = (hostRef, renderFnResults) => {
804
1011
  {
805
1012
  scopeId = hostElm['s-sc'];
806
1013
  }
1014
+ {
1015
+ contentRef = hostElm['s-cr'];
1016
+ useNativeShadowDom = (cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) !== 0;
1017
+ // always reset
1018
+ checkSlotFallbackVisibility = false;
1019
+ }
807
1020
  // synchronous patch
808
1021
  patch(oldVNode, rootVnode);
1022
+ {
1023
+ // while we're moving nodes around existing nodes, temporarily disable
1024
+ // the disconnectCallback from working
1025
+ plt.$flags$ |= 1 /* PLATFORM_FLAGS.isTmpDisconnected */;
1026
+ if (checkSlotRelocate) {
1027
+ relocateSlotContent(rootVnode.$elm$);
1028
+ let relocateData;
1029
+ let nodeToRelocate;
1030
+ let orgLocationNode;
1031
+ let parentNodeRef;
1032
+ let insertBeforeNode;
1033
+ let refNode;
1034
+ let i = 0;
1035
+ for (; i < relocateNodes.length; i++) {
1036
+ relocateData = relocateNodes[i];
1037
+ nodeToRelocate = relocateData.$nodeToRelocate$;
1038
+ if (!nodeToRelocate['s-ol']) {
1039
+ // add a reference node marking this node's original location
1040
+ // keep a reference to this node for later lookups
1041
+ orgLocationNode =
1042
+ doc.createTextNode('');
1043
+ orgLocationNode['s-nr'] = nodeToRelocate;
1044
+ nodeToRelocate.parentNode.insertBefore((nodeToRelocate['s-ol'] = orgLocationNode), nodeToRelocate);
1045
+ }
1046
+ }
1047
+ for (i = 0; i < relocateNodes.length; i++) {
1048
+ relocateData = relocateNodes[i];
1049
+ nodeToRelocate = relocateData.$nodeToRelocate$;
1050
+ if (relocateData.$slotRefNode$) {
1051
+ // by default we're just going to insert it directly
1052
+ // after the slot reference node
1053
+ parentNodeRef = relocateData.$slotRefNode$.parentNode;
1054
+ insertBeforeNode = relocateData.$slotRefNode$.nextSibling;
1055
+ orgLocationNode = nodeToRelocate['s-ol'];
1056
+ while ((orgLocationNode = orgLocationNode.previousSibling)) {
1057
+ refNode = orgLocationNode['s-nr'];
1058
+ if (refNode && refNode['s-sn'] === nodeToRelocate['s-sn'] && parentNodeRef === refNode.parentNode) {
1059
+ refNode = refNode.nextSibling;
1060
+ if (!refNode || !refNode['s-nr']) {
1061
+ insertBeforeNode = refNode;
1062
+ break;
1063
+ }
1064
+ }
1065
+ }
1066
+ if ((!insertBeforeNode && parentNodeRef !== nodeToRelocate.parentNode) ||
1067
+ nodeToRelocate.nextSibling !== insertBeforeNode) {
1068
+ // we've checked that it's worth while to relocate
1069
+ // since that the node to relocate
1070
+ // has a different next sibling or parent relocated
1071
+ if (nodeToRelocate !== insertBeforeNode) {
1072
+ if (!nodeToRelocate['s-hn'] && nodeToRelocate['s-ol']) {
1073
+ // probably a component in the index.html that doesn't have it's hostname set
1074
+ nodeToRelocate['s-hn'] = nodeToRelocate['s-ol'].parentNode.nodeName;
1075
+ }
1076
+ // add it back to the dom but in its new home
1077
+ parentNodeRef.insertBefore(nodeToRelocate, insertBeforeNode);
1078
+ }
1079
+ }
1080
+ }
1081
+ else {
1082
+ // this node doesn't have a slot home to go to, so let's hide it
1083
+ if (nodeToRelocate.nodeType === 1 /* NODE_TYPE.ElementNode */) {
1084
+ nodeToRelocate.hidden = true;
1085
+ }
1086
+ }
1087
+ }
1088
+ }
1089
+ if (checkSlotFallbackVisibility) {
1090
+ updateFallbackSlotVisibility(rootVnode.$elm$);
1091
+ }
1092
+ // done moving nodes around
1093
+ // allow the disconnect callback to work again
1094
+ plt.$flags$ &= ~1 /* PLATFORM_FLAGS.isTmpDisconnected */;
1095
+ // always reset
1096
+ relocateNodes.length = 0;
1097
+ }
809
1098
  };
810
1099
  const attachToAncestor = (hostRef, ancestorComponent) => {
811
1100
  if (ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
@@ -1223,6 +1512,15 @@ const connectedCallback = (elm) => {
1223
1512
  if (!(hostRef.$flags$ & 1 /* HOST_FLAGS.hasConnected */)) {
1224
1513
  // first time this component has connected
1225
1514
  hostRef.$flags$ |= 1 /* HOST_FLAGS.hasConnected */;
1515
+ {
1516
+ // initUpdate
1517
+ // if the slot polyfill is required we'll need to put some nodes
1518
+ // in here to act as original content anchors as we move nodes around
1519
+ // host element has been connected to the DOM
1520
+ if ((cmpMeta.$flags$ & (4 /* CMP_FLAGS.hasSlotRelocation */ | 8 /* CMP_FLAGS.needsShadowDomShim */))) {
1521
+ setContentReference(elm);
1522
+ }
1523
+ }
1226
1524
  {
1227
1525
  // find the first ancestor component (if there is one) and register
1228
1526
  // this component as one of the actively loading child components for its ancestor
@@ -1264,6 +1562,17 @@ const connectedCallback = (elm) => {
1264
1562
  endConnected();
1265
1563
  }
1266
1564
  };
1565
+ const setContentReference = (elm) => {
1566
+ // only required when we're NOT using native shadow dom (slot)
1567
+ // or this browser doesn't support native shadow dom
1568
+ // and this host element was NOT created with SSR
1569
+ // let's pick out the inner content for slot projection
1570
+ // create a node to represent where the original
1571
+ // content was first placed, which is useful later on
1572
+ const contentRefElm = (elm['s-cr'] = doc.createComment(''));
1573
+ contentRefElm['s-cn'] = true;
1574
+ elm.insertBefore(contentRefElm, elm.firstChild);
1575
+ };
1267
1576
  const disconnectedCallback = (elm) => {
1268
1577
  if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
1269
1578
  const hostRef = getHostRef(elm);
@@ -1280,7 +1589,6 @@ const disconnectedCallback = (elm) => {
1280
1589
  }
1281
1590
  };
1282
1591
  const bootstrapLazy = (lazyBundles, options = {}) => {
1283
- var _a;
1284
1592
  const endBootstrap = createTime();
1285
1593
  const cmpTags = [];
1286
1594
  const exclude = options.exclude || [];
@@ -1360,11 +1668,6 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
1360
1668
  {
1361
1669
  visibilityStyle.innerHTML = cmpTags + HYDRATED_CSS;
1362
1670
  visibilityStyle.setAttribute('data-styles', '');
1363
- // Apply CSP nonce to the style tag if it exists
1364
- const nonce = (_a = plt.$nonce$) !== null && _a !== void 0 ? _a : queryNonceMetaTagContent(doc);
1365
- if (nonce != null) {
1366
- visibilityStyle.setAttribute('nonce', nonce);
1367
- }
1368
1671
  head.insertBefore(visibilityStyle, metaCharset ? metaCharset.nextSibling : head.firstChild);
1369
1672
  }
1370
1673
  // Process deferred connectedCallbacks now all components have been registered
@@ -1409,13 +1712,6 @@ const hostListenerProxy = (hostRef, methodName) => (ev) => {
1409
1712
  };
1410
1713
  // prettier-ignore
1411
1714
  const hostListenerOpts = (flags) => (flags & 2 /* LISTENER_FLAGS.Capture */) !== 0;
1412
- /**
1413
- * Assigns the given value to the nonce property on the runtime platform object.
1414
- * During runtime, this value is used to set the nonce attribute on all dynamically created script and style tags.
1415
- * @param nonce The value to be assigned to the platform nonce property.
1416
- * @returns void
1417
- */
1418
- const setNonce = (nonce) => (plt.$nonce$ = nonce);
1419
1715
  const hostRefs = /*@__PURE__*/ new WeakMap();
1420
1716
  const getHostRef = (ref) => hostRefs.get(ref);
1421
1717
  const registerInstance = (lazyInstance, hostRef) => hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef);
@@ -1526,4 +1822,4 @@ const flush = () => {
1526
1822
  const nextTick = /*@__PURE__*/ (cb) => promiseResolve().then(cb);
1527
1823
  const writeTask = /*@__PURE__*/ queueTask(queueDomWrites, true);
1528
1824
 
1529
- export { Host as H, bootstrapLazy as b, createEvent as c, h, promiseResolve as p, registerInstance as r, setNonce as s };
1825
+ export { Host as H, bootstrapLazy as b, createEvent as c, h, promiseResolve as p, registerInstance as r };