@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
@@ -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) {
@@ -468,13 +451,36 @@ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
468
451
  let i = 0;
469
452
  let elm;
470
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
+ }
471
470
  if (newVNode.$text$ !== null) {
472
471
  // create text node
473
472
  elm = newVNode.$elm$ = doc.createTextNode(newVNode.$text$);
474
473
  }
474
+ else if (newVNode.$flags$ & 1 /* VNODE_FLAGS.isSlotReference */) {
475
+ // create a slot reference node
476
+ elm = newVNode.$elm$ =
477
+ doc.createTextNode('');
478
+ }
475
479
  else {
476
480
  // create element
477
- 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$));
478
484
  // add css classes, attrs, props, listeners, etc.
479
485
  {
480
486
  updateElement(null, newVNode, isSvgMode);
@@ -487,7 +493,7 @@ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
487
493
  if (newVNode.$children$) {
488
494
  for (i = 0; i < newVNode.$children$.length; ++i) {
489
495
  // create the node
490
- childNode = createElm(oldParentVNode, newVNode, i);
496
+ childNode = createElm(oldParentVNode, newVNode, i, elm);
491
497
  // return node could have been null
492
498
  if (childNode) {
493
499
  // append our new node
@@ -496,57 +502,85 @@ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
496
502
  }
497
503
  }
498
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
+ }
499
523
  return elm;
500
524
  };
501
- /**
502
- * Create DOM nodes corresponding to a list of {@link d.Vnode} objects and
503
- * add them to the DOM in the appropriate place.
504
- *
505
- * @param parentElm the DOM node which should be used as a parent for the new
506
- * DOM nodes
507
- * @param before a child of the `parentElm` which the new children should be
508
- * inserted before (optional)
509
- * @param parentVNode the parent virtual DOM node
510
- * @param vnodes the new child virtual DOM nodes to produce DOM nodes for
511
- * @param startIdx the index in the child virtual DOM nodes at which to start
512
- * creating DOM nodes (inclusive)
513
- * @param endIdx the index in the child virtual DOM nodes at which to stop
514
- * creating DOM nodes (inclusive)
515
- */
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
+ };
516
549
  const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) => {
517
- let containerElm = (parentElm);
550
+ let containerElm = ((parentElm['s-cr'] && parentElm['s-cr'].parentNode) || parentElm);
518
551
  let childNode;
519
552
  if (containerElm.shadowRoot && containerElm.tagName === hostTagName) {
520
553
  containerElm = containerElm.shadowRoot;
521
554
  }
522
555
  for (; startIdx <= endIdx; ++startIdx) {
523
556
  if (vnodes[startIdx]) {
524
- childNode = createElm(null, parentVNode, startIdx);
557
+ childNode = createElm(null, parentVNode, startIdx, parentElm);
525
558
  if (childNode) {
526
559
  vnodes[startIdx].$elm$ = childNode;
527
- containerElm.insertBefore(childNode, before);
560
+ containerElm.insertBefore(childNode, referenceNode(before) );
528
561
  }
529
562
  }
530
563
  }
531
564
  };
532
- /**
533
- * Remove the DOM elements corresponding to a list of {@link d.VNode} objects.
534
- * This can be used to, for instance, clean up after a list of children which
535
- * should no longer be shown.
536
- *
537
- * This function also handles some of Stencil's slot relocation logic.
538
- *
539
- * @param vnodes a list of virtual DOM nodes to remove
540
- * @param startIdx the index at which to start removing nodes (inclusive)
541
- * @param endIdx the index at which to stop removing nodes (inclusive)
542
- * @param vnode a VNode
543
- * @param elm an element
544
- */
545
565
  const removeVnodes = (vnodes, startIdx, endIdx, vnode, elm) => {
546
566
  for (; startIdx <= endIdx; ++startIdx) {
547
567
  if ((vnode = vnodes[startIdx])) {
548
568
  elm = vnode.$elm$;
549
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
+ }
550
584
  // remove the vnode's element from the dom
551
585
  elm.remove();
552
586
  }
@@ -662,6 +696,23 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
662
696
  newEndVnode = newCh[--newEndIdx];
663
697
  }
664
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
+ }
665
716
  patch(oldStartVnode, newEndVnode);
666
717
  // We need to move the element for `oldStartVnode` into a position which
667
718
  // will be appropriate for `newEndVnode`. For this we can use
@@ -685,6 +736,24 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
685
736
  newEndVnode = newCh[--newEndIdx];
686
737
  }
687
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
+ }
688
757
  patch(oldEndVnode, newStartVnode);
689
758
  // We've already checked above if `oldStartVnode` and `newStartVnode` are
690
759
  // the same node, so since we're here we know that they are not. Thus we
@@ -701,13 +770,13 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
701
770
  // the key of the first new child OR the build is not using `key`
702
771
  // attributes at all. In either case we need to create a new element
703
772
  // for the new node.
704
- node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx);
773
+ node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx, parentElm);
705
774
  newStartVnode = newCh[++newStartIdx];
706
775
  }
707
776
  if (node) {
708
777
  // if we created a new node then handle inserting it to the DOM
709
778
  {
710
- oldStartVnode.$elm$.parentNode.insertBefore(node, oldStartVnode.$elm$);
779
+ parentReferenceNode(oldStartVnode.$elm$).insertBefore(node, referenceNode(oldStartVnode.$elm$));
711
780
  }
712
781
  }
713
782
  }
@@ -734,8 +803,7 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
734
803
  *
735
804
  * So, in other words, if `key` attrs are not set on VNodes which may be
736
805
  * changing order within a `children` array or something along those lines then
737
- * we could obtain a false negative and then have to do needless re-rendering
738
- * (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.
739
807
  *
740
808
  * @param leftVNode the first VNode to check
741
809
  * @param rightVNode the second VNode to check
@@ -745,10 +813,21 @@ const isSameVnode = (leftVNode, rightVNode) => {
745
813
  // compare if two vnode to see if they're "technically" the same
746
814
  // need to have the same element tag, and same key to be the same
747
815
  if (leftVNode.$tag$ === rightVNode.$tag$) {
816
+ if (leftVNode.$tag$ === 'slot') {
817
+ return leftVNode.$name$ === rightVNode.$name$;
818
+ }
748
819
  return true;
749
820
  }
750
821
  return false;
751
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;
752
831
  /**
753
832
  * Handle reconciling an outdated VNode with a new one which corresponds to
754
833
  * it. This function handles flushing updates to the DOM and reconciling the
@@ -761,10 +840,14 @@ const patch = (oldVNode, newVNode) => {
761
840
  const elm = (newVNode.$elm$ = oldVNode.$elm$);
762
841
  const oldChildren = oldVNode.$children$;
763
842
  const newChildren = newVNode.$children$;
843
+ const tag = newVNode.$tag$;
764
844
  const text = newVNode.$text$;
845
+ let defaultHolder;
765
846
  if (text === null) {
766
847
  {
767
- {
848
+ if (tag === 'slot')
849
+ ;
850
+ else {
768
851
  // either this is the first render of an element OR it's an update
769
852
  // AND we already know it's possible it could have changed
770
853
  // this updates the element's css classes, attrs, props, listeners, etc.
@@ -790,32 +873,156 @@ const patch = (oldVNode, newVNode) => {
790
873
  removeVnodes(oldChildren, 0, oldChildren.length - 1);
791
874
  }
792
875
  }
876
+ else if ((defaultHolder = elm['s-cr'])) {
877
+ // this element has slotted content
878
+ defaultHolder.parentNode.textContent = text;
879
+ }
793
880
  else if (oldVNode.$text$ !== text) {
794
881
  // update the text content for the text only vnode
795
882
  // and also only if the text is different than before
796
883
  elm.data = text;
797
884
  }
798
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
+ };
799
1017
  const callNodeRefs = (vNode) => {
800
1018
  {
801
1019
  vNode.$attrs$ && vNode.$attrs$.ref && vNode.$attrs$.ref(null);
802
1020
  vNode.$children$ && vNode.$children$.map(callNodeRefs);
803
1021
  }
804
1022
  };
805
- /**
806
- * The main entry point for Stencil's virtual DOM-based rendering engine
807
- *
808
- * Given a {@link d.HostRef} container and some virtual DOM nodes, this
809
- * function will handle creating a virtual DOM tree with a single root, patching
810
- * the current virtual DOM tree onto an old one (if any), dealing with slot
811
- * relocation, and reflecting attributes.
812
- *
813
- * @param hostRef data needed to root and render the virtual DOM tree, such as
814
- * the DOM node into which it should be rendered.
815
- * @param renderFnResults the virtual DOM nodes to be rendered
816
- */
817
1023
  const renderVdom = (hostRef, renderFnResults) => {
818
1024
  const hostElm = hostRef.$hostElement$;
1025
+ const cmpMeta = hostRef.$cmpMeta$;
819
1026
  const oldVNode = hostRef.$vnode$ || newVNode(null, null);
820
1027
  const rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
821
1028
  hostTagName = hostElm.tagName;
@@ -826,8 +1033,90 @@ const renderVdom = (hostRef, renderFnResults) => {
826
1033
  {
827
1034
  scopeId = hostElm['s-sc'];
828
1035
  }
1036
+ {
1037
+ contentRef = hostElm['s-cr'];
1038
+ useNativeShadowDom = (cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) !== 0;
1039
+ // always reset
1040
+ checkSlotFallbackVisibility = false;
1041
+ }
829
1042
  // synchronous patch
830
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
+ }
831
1120
  };
832
1121
  const attachToAncestor = (hostRef, ancestorComponent) => {
833
1122
  if (ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
@@ -1245,6 +1534,15 @@ const connectedCallback = (elm) => {
1245
1534
  if (!(hostRef.$flags$ & 1 /* HOST_FLAGS.hasConnected */)) {
1246
1535
  // first time this component has connected
1247
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
+ }
1248
1546
  {
1249
1547
  // find the first ancestor component (if there is one) and register
1250
1548
  // this component as one of the actively loading child components for its ancestor
@@ -1286,6 +1584,17 @@ const connectedCallback = (elm) => {
1286
1584
  endConnected();
1287
1585
  }
1288
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
+ };
1289
1598
  const disconnectedCallback = (elm) => {
1290
1599
  if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
1291
1600
  const hostRef = getHostRef(elm);
@@ -1302,7 +1611,6 @@ const disconnectedCallback = (elm) => {
1302
1611
  }
1303
1612
  };
1304
1613
  const bootstrapLazy = (lazyBundles, options = {}) => {
1305
- var _a;
1306
1614
  const endBootstrap = createTime();
1307
1615
  const cmpTags = [];
1308
1616
  const exclude = options.exclude || [];
@@ -1382,11 +1690,6 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
1382
1690
  {
1383
1691
  visibilityStyle.innerHTML = cmpTags + HYDRATED_CSS;
1384
1692
  visibilityStyle.setAttribute('data-styles', '');
1385
- // Apply CSP nonce to the style tag if it exists
1386
- const nonce = (_a = plt.$nonce$) !== null && _a !== void 0 ? _a : queryNonceMetaTagContent(doc);
1387
- if (nonce != null) {
1388
- visibilityStyle.setAttribute('nonce', nonce);
1389
- }
1390
1693
  head.insertBefore(visibilityStyle, metaCharset ? metaCharset.nextSibling : head.firstChild);
1391
1694
  }
1392
1695
  // Process deferred connectedCallbacks now all components have been registered
@@ -1431,13 +1734,6 @@ const hostListenerProxy = (hostRef, methodName) => (ev) => {
1431
1734
  };
1432
1735
  // prettier-ignore
1433
1736
  const hostListenerOpts = (flags) => (flags & 2 /* LISTENER_FLAGS.Capture */) !== 0;
1434
- /**
1435
- * Assigns the given value to the nonce property on the runtime platform object.
1436
- * During runtime, this value is used to set the nonce attribute on all dynamically created script and style tags.
1437
- * @param nonce The value to be assigned to the platform nonce property.
1438
- * @returns void
1439
- */
1440
- const setNonce = (nonce) => (plt.$nonce$ = nonce);
1441
1737
  const hostRefs = /*@__PURE__*/ new WeakMap();
1442
1738
  const getHostRef = (ref) => hostRefs.get(ref);
1443
1739
  const registerInstance = (lazyInstance, hostRef) => hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef);
@@ -1554,4 +1850,3 @@ exports.createEvent = createEvent;
1554
1850
  exports.h = h;
1555
1851
  exports.promiseResolve = promiseResolve;
1556
1852
  exports.registerInstance = registerInstance;
1557
- exports.setNonce = setNonce;