@builder.io/sdk-solid 0.7.2 → 0.7.4

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.
@@ -2625,7 +2625,9 @@ var componentInfo11 = {
2625
2625
  advanced: true
2626
2626
  }]
2627
2627
  };
2628
- var _tmpl$13 = /* @__PURE__ */ template(`<video>`);
2628
+ var _tmpl$13 = /* @__PURE__ */ template(`<source type=video/mp4>`);
2629
+ var _tmpl$23 = /* @__PURE__ */ template(`<div>`);
2630
+ var _tmpl$33 = /* @__PURE__ */ template(`<div><video class=builder-video>`);
2629
2631
  function Video(props) {
2630
2632
  function videoProps() {
2631
2633
  return {
@@ -2648,13 +2650,13 @@ function Video(props) {
2648
2650
  }
2649
2651
  function spreadProps() {
2650
2652
  return {
2651
- ...props.attributes,
2652
2653
  ...videoProps()
2653
2654
  };
2654
2655
  }
2655
2656
  return (() => {
2656
- const _el$ = _tmpl$13();
2657
- spread(_el$, mergeProps(spreadProps, {
2657
+ const _el$ = _tmpl$33(), _el$2 = _el$.firstChild;
2658
+ _el$.style.setProperty("position", "relative");
2659
+ spread(_el$2, mergeProps(spreadProps, {
2658
2660
  get preload() {
2659
2661
  return props.preload || "metadata";
2660
2662
  },
@@ -2667,7 +2669,11 @@ function Video(props) {
2667
2669
  "object-position": props.position,
2668
2670
  // Hack to get object fit to work as expected and
2669
2671
  // not have the video overflow
2670
- "border-radius": 1
2672
+ "z-index": 2,
2673
+ "border-radius": "1px",
2674
+ ...props.aspectRatio ? {
2675
+ position: "absolute"
2676
+ } : null
2671
2677
  };
2672
2678
  },
2673
2679
  get src() {
@@ -2676,7 +2682,62 @@ function Video(props) {
2676
2682
  get poster() {
2677
2683
  return props.posterImage;
2678
2684
  }
2679
- }), false, false);
2685
+ }), false, true);
2686
+ insert(_el$2, createComponent(Show, {
2687
+ get when() {
2688
+ return !props.lazyLoad;
2689
+ },
2690
+ get children() {
2691
+ const _el$3 = _tmpl$13();
2692
+ effect(() => setAttribute(_el$3, "src", props.video));
2693
+ return _el$3;
2694
+ }
2695
+ }));
2696
+ insert(_el$, createComponent(Show, {
2697
+ get when() {
2698
+ return props.aspectRatio && !(props.fitContent && props.builderBlock?.children?.length);
2699
+ },
2700
+ get children() {
2701
+ const _el$4 = _tmpl$23();
2702
+ _el$4.style.setProperty("width", "100%");
2703
+ _el$4.style.setProperty("pointer-events", "none");
2704
+ _el$4.style.setProperty("font-size", "0px");
2705
+ effect(() => props.aspectRatio * 100 + "%" != null ? _el$4.style.setProperty("padding-top", props.aspectRatio * 100 + "%") : _el$4.style.removeProperty("padding-top"));
2706
+ return _el$4;
2707
+ }
2708
+ }), null);
2709
+ insert(_el$, createComponent(Show, {
2710
+ get when() {
2711
+ return props.builderBlock?.children?.length && props.fitContent;
2712
+ },
2713
+ get children() {
2714
+ const _el$5 = _tmpl$23();
2715
+ _el$5.style.setProperty("display", "flex");
2716
+ _el$5.style.setProperty("flex-direction", "column");
2717
+ _el$5.style.setProperty("align-items", "stretch");
2718
+ insert(_el$5, () => props.children);
2719
+ return _el$5;
2720
+ }
2721
+ }), null);
2722
+ insert(_el$, createComponent(Show, {
2723
+ get when() {
2724
+ return props.builderBlock?.children?.length && !props.fitContent;
2725
+ },
2726
+ get children() {
2727
+ const _el$6 = _tmpl$23();
2728
+ _el$6.style.setProperty("pointer-events", "none");
2729
+ _el$6.style.setProperty("display", "flex");
2730
+ _el$6.style.setProperty("flex-direction", "column");
2731
+ _el$6.style.setProperty("align-items", "stretch");
2732
+ _el$6.style.setProperty("position", "absolute");
2733
+ _el$6.style.setProperty("top", "0");
2734
+ _el$6.style.setProperty("left", "0");
2735
+ _el$6.style.setProperty("width", "100%");
2736
+ _el$6.style.setProperty("height", "100%");
2737
+ insert(_el$6, () => props.children);
2738
+ return _el$6;
2739
+ }
2740
+ }), null);
2680
2741
  return _el$;
2681
2742
  })();
2682
2743
  }
@@ -2741,13 +2802,19 @@ var serializeComponentInfo = ({
2741
2802
  }), {}))
2742
2803
  });
2743
2804
 
2805
+ // src/components/content-variants/inlined-fns.ts
2806
+ var UPDATE_COOKIES_AND_STYLES_SCRIPT = "function updateCookiesAndStyles(contentId, variants, isHydrationTarget) {\n function getAndSetVariantId() {\n function setCookie(name, value, days) {\n let expires = '';\n if (days) {\n const date = new Date();\n date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);\n expires = '; expires=' + date.toUTCString();\n }\n document.cookie = name + '=' + (value || '') + expires + '; path=/' + '; Secure; SameSite=None';\n }\n function getCookie(name) {\n const nameEQ = name + '=';\n const ca = document.cookie.split(';');\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i];\n while (c.charAt(0) === ' ') c = c.substring(1, c.length);\n if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);\n }\n return null;\n }\n const cookieName = `builder.tests.${contentId}`;\n const variantInCookie = getCookie(cookieName);\n const availableIDs = variants.map(vr => vr.id).concat(contentId);\n if (variantInCookie && availableIDs.includes(variantInCookie)) {\n return variantInCookie;\n }\n let n = 0;\n const random = Math.random();\n for (let i = 0; i < variants.length; i++) {\n const variant = variants[i];\n const testRatio = variant.testRatio;\n n += testRatio;\n if (random < n) {\n setCookie(cookieName, variant.id);\n return variant.id;\n }\n }\n setCookie(cookieName, contentId);\n return contentId;\n }\n const winningVariantId = getAndSetVariantId();\n const styleEl = document.currentScript?.previousElementSibling;\n if (isHydrationTarget) {\n styleEl.remove();\n const thisScriptEl = document.currentScript;\n thisScriptEl?.remove();\n } else {\n const newStyleStr = variants.concat({\n id: contentId\n }).filter(variant => variant.id !== winningVariantId).map(value => {\n return `.variant-${value.id} { display: none; }\n `;\n }).join('');\n styleEl.innerHTML = newStyleStr;\n }\n}";
2807
+ var UPDATE_VARIANT_VISIBILITY_SCRIPT = "function updateVariantVisibility(variantContentId, defaultContentId, isHydrationTarget) {\n if (!navigator.cookieEnabled) {\n return;\n }\n function getCookie(name) {\n const nameEQ = name + '=';\n const ca = document.cookie.split(';');\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i];\n while (c.charAt(0) === ' ') c = c.substring(1, c.length);\n if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);\n }\n return null;\n }\n const cookieName = `builder.tests.${defaultContentId}`;\n const winningVariant = getCookie(cookieName);\n const parentDiv = document.currentScript?.parentElement;\n const isDefaultContent = variantContentId === defaultContentId;\n const isWinningVariant = winningVariant === variantContentId;\n if (isWinningVariant && !isDefaultContent) {\n parentDiv?.removeAttribute('hidden');\n parentDiv?.removeAttribute('aria-hidden');\n } else if (!isWinningVariant && isDefaultContent) {\n parentDiv?.setAttribute('hidden', 'true');\n parentDiv?.setAttribute('aria-hidden', 'true');\n }\n if (isHydrationTarget) {\n if (!isWinningVariant) {\n parentDiv?.remove();\n }\n const thisScriptEl = document.currentScript;\n thisScriptEl?.remove();\n }\n return;\n}";
2808
+
2744
2809
  // src/components/content-variants/helpers.ts
2810
+ var UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME = "builderIoAbTest";
2811
+ var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME = "builderIoRenderContent";
2745
2812
  var getVariants = (content) => Object.values(content?.variations || {}).map((variant) => ({
2746
2813
  ...variant,
2747
2814
  testVariationId: variant.id,
2748
2815
  id: content?.id
2749
2816
  }));
2750
- var checkShouldRunVariants = ({
2817
+ var checkShouldRenderVariants = ({
2751
2818
  canTrack,
2752
2819
  content
2753
2820
  }) => {
@@ -2758,139 +2825,34 @@ var checkShouldRunVariants = ({
2758
2825
  return false;
2759
2826
  if (!canTrack)
2760
2827
  return false;
2761
- if (TARGET === "vue2" || TARGET === "vue3")
2828
+ if (TARGET === "vue2" || TARGET === "vue3" || TARGET === "svelte")
2762
2829
  return true;
2763
2830
  if (isBrowser())
2764
2831
  return false;
2765
2832
  return true;
2766
2833
  };
2767
- function bldrAbTest(contentId, variants, isHydrationTarget2) {
2768
- function getAndSetVariantId2() {
2769
- function setCookie2(name, value, days) {
2770
- let expires = "";
2771
- if (days) {
2772
- const date = /* @__PURE__ */ new Date();
2773
- date.setTime(date.getTime() + days * 24 * 60 * 60 * 1e3);
2774
- expires = "; expires=" + date.toUTCString();
2775
- }
2776
- document.cookie = name + "=" + (value || "") + expires + "; path=/; Secure; SameSite=None";
2777
- }
2778
- function getCookie2(name) {
2779
- const nameEQ = name + "=";
2780
- const ca = document.cookie.split(";");
2781
- for (let i = 0; i < ca.length; i++) {
2782
- let c = ca[i];
2783
- while (c.charAt(0) === " ")
2784
- c = c.substring(1, c.length);
2785
- if (c.indexOf(nameEQ) === 0)
2786
- return c.substring(nameEQ.length, c.length);
2787
- }
2788
- return null;
2789
- }
2790
- const cookieName = `builder.tests.${contentId}`;
2791
- const variantInCookie = getCookie2(cookieName);
2792
- const availableIDs = variants.map((vr) => vr.id).concat(contentId);
2793
- if (variantInCookie && availableIDs.includes(variantInCookie)) {
2794
- return variantInCookie;
2795
- }
2796
- let n = 0;
2797
- const random = Math.random();
2798
- for (let i = 0; i < variants.length; i++) {
2799
- const variant = variants[i];
2800
- const testRatio = variant.testRatio;
2801
- n += testRatio;
2802
- if (random < n) {
2803
- setCookie2(cookieName, variant.id);
2804
- return variant.id;
2805
- }
2806
- }
2807
- setCookie2(cookieName, contentId);
2808
- return contentId;
2809
- }
2810
- const winningVariantId = getAndSetVariantId2();
2811
- const styleEl = document.currentScript?.previousElementSibling;
2812
- if (isHydrationTarget2) {
2813
- styleEl.remove();
2814
- const thisScriptEl = document.currentScript;
2815
- thisScriptEl?.remove();
2816
- } else {
2817
- const newStyleStr = variants.concat({
2818
- id: contentId
2819
- }).filter((variant) => variant.id !== winningVariantId).map((value) => {
2820
- return `.variant-${value.id} { display: none; }
2821
- `;
2822
- }).join("");
2823
- styleEl.innerHTML = newStyleStr;
2824
- }
2825
- }
2826
- function bldrCntntScrpt(variantContentId, defaultContentId, isHydrationTarget2) {
2827
- if (!navigator.cookieEnabled) {
2828
- return;
2829
- }
2830
- function getCookie2(name) {
2831
- const nameEQ = name + "=";
2832
- const ca = document.cookie.split(";");
2833
- for (let i = 0; i < ca.length; i++) {
2834
- let c = ca[i];
2835
- while (c.charAt(0) === " ")
2836
- c = c.substring(1, c.length);
2837
- if (c.indexOf(nameEQ) === 0)
2838
- return c.substring(nameEQ.length, c.length);
2839
- }
2840
- return null;
2841
- }
2842
- const cookieName = `builder.tests.${defaultContentId}`;
2843
- const variantId = getCookie2(cookieName);
2844
- const parentDiv = document.currentScript?.parentElement;
2845
- const variantIsDefaultContent = variantContentId === defaultContentId;
2846
- if (variantId === variantContentId) {
2847
- if (variantIsDefaultContent) {
2848
- return;
2849
- }
2850
- parentDiv?.removeAttribute("hidden");
2851
- parentDiv?.removeAttribute("aria-hidden");
2852
- } else {
2853
- if (variantIsDefaultContent) {
2854
- if (isHydrationTarget2) {
2855
- parentDiv?.remove();
2856
- } else {
2857
- parentDiv?.setAttribute("hidden", "true");
2858
- parentDiv?.setAttribute("aria-hidden", "true");
2859
- }
2860
- }
2861
- return;
2862
- }
2863
- return;
2864
- }
2865
2834
  var getIsHydrationTarget = (target) => target === "react" || target === "reactNative";
2866
2835
  var isHydrationTarget = getIsHydrationTarget(TARGET);
2867
- var AB_TEST_FN_NAME = "builderIoAbTest";
2868
- var CONTENT_FN_NAME = "builderIoRenderContent";
2869
- var getScriptString = () => {
2870
- const fnStr = bldrAbTest.toString().replace(/\s+/g, " ");
2871
- const fnStr2 = bldrCntntScrpt.toString().replace(/\s+/g, " ");
2872
- return `
2873
- window.${AB_TEST_FN_NAME} = ${fnStr}
2874
- window.${CONTENT_FN_NAME} = ${fnStr2}
2836
+ var getScriptString = () => `
2837
+ window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
2838
+ window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
2875
2839
  `;
2876
- };
2877
- var getVariantsScriptString = (variants, contentId) => {
2878
- return `
2879
- window.${AB_TEST_FN_NAME}("${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget})`;
2880
- };
2881
- var getRenderContentScriptString = ({
2840
+ var getUpdateCookieAndStylesScript = (variants, contentId) => `
2841
+ window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME}(
2842
+ "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget}
2843
+ )`;
2844
+ var getUpdateVariantVisibilityScript = ({
2882
2845
  contentId,
2883
2846
  variationId
2884
- }) => {
2885
- return `
2886
- window.${CONTENT_FN_NAME}("${variationId}", "${contentId}", ${isHydrationTarget})`;
2887
- };
2847
+ }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME}(
2848
+ "${variationId}", "${contentId}", ${isHydrationTarget}
2849
+ )`;
2888
2850
  var _tmpl$14 = /* @__PURE__ */ template(`<script>`);
2889
2851
  function InlinedScript(props) {
2890
2852
  return (() => {
2891
2853
  const _el$ = _tmpl$14();
2892
2854
  effect((_p$) => {
2893
- const _v$ = props.scriptStr, _v$2 = props.id;
2855
+ const _v$ = props.scriptStr, _v$2 = props.id || "";
2894
2856
  _v$ !== _p$._v$ && (_el$.innerHTML = _p$._v$ = _v$);
2895
2857
  _v$2 !== _p$._v$2 && setAttribute(_el$, "id", _p$._v$2 = _v$2);
2896
2858
  return _p$;
@@ -3383,7 +3345,7 @@ var getInteractionPropertiesForEvent = (event) => {
3383
3345
  };
3384
3346
 
3385
3347
  // src/constants/sdk-version.ts
3386
- var SDK_VERSION = "0.7.2";
3348
+ var SDK_VERSION = "0.7.4";
3387
3349
 
3388
3350
  // src/functions/register.ts
3389
3351
  var registry = {};
@@ -3757,7 +3719,7 @@ function EnableEditor(props) {
3757
3719
  typeof _ref$ === "function" ? use(_ref$, _el$) : elementRef = _el$;
3758
3720
  spread(_el$, mergeProps({
3759
3721
  get ["class"]() {
3760
- return props.classNameProp;
3722
+ return `variant-${props.content?.testVariationId || props.content?.id}`;
3761
3723
  }
3762
3724
  }, {}, {
3763
3725
  get key() {
@@ -3910,7 +3872,7 @@ var getContentInitialValue = ({
3910
3872
 
3911
3873
  // src/components/content/content.tsx
3912
3874
  function ContentComponent(props) {
3913
- const [scriptStr, setScriptStr] = createSignal(getRenderContentScriptString({
3875
+ const [scriptStr, setScriptStr] = createSignal(getUpdateVariantVisibilityScript({
3914
3876
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
3915
3877
  variationId: props.content?.testVariationId,
3916
3878
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
@@ -4006,9 +3968,6 @@ function ContentComponent(props) {
4006
3968
  get enrich() {
4007
3969
  return props.enrich;
4008
3970
  },
4009
- get classNameProp() {
4010
- return props.classNameProp;
4011
- },
4012
3971
  get showContent() {
4013
3972
  return props.showContent;
4014
3973
  },
@@ -4065,12 +4024,12 @@ var content_default = ContentComponent;
4065
4024
 
4066
4025
  // src/components/content-variants/content-variants.tsx
4067
4026
  function ContentVariants(props) {
4068
- const [shouldRenderVariants, setShouldRenderVariants] = createSignal(checkShouldRunVariants({
4027
+ const [shouldRenderVariants, setShouldRenderVariants] = createSignal(checkShouldRenderVariants({
4069
4028
  canTrack: getDefaultCanTrack(props.canTrack),
4070
4029
  content: props.content
4071
4030
  }));
4072
- function variantScriptStr() {
4073
- return getVariantsScriptString(getVariants(props.content).map((value) => ({
4031
+ function updateCookieAndStylesScriptStr() {
4032
+ return getUpdateCookieAndStylesScript(getVariants(props.content).map((value) => ({
4074
4033
  id: value.testVariationId,
4075
4034
  testRatio: value.testRatio
4076
4035
  })), props.content?.id || "");
@@ -4115,7 +4074,7 @@ function ContentVariants(props) {
4115
4074
  }
4116
4075
  }), createComponent(inlined_script_default, {
4117
4076
  get scriptStr() {
4118
- return variantScriptStr();
4077
+ return updateCookieAndStylesScriptStr();
4119
4078
  }
4120
4079
  }), createComponent(For, {
4121
4080
  get each() {
@@ -4129,7 +4088,6 @@ function ContentVariants(props) {
4129
4088
  },
4130
4089
  content: variant,
4131
4090
  showContent: false,
4132
- classNameProp: void 0,
4133
4091
  get model() {
4134
4092
  return props.model;
4135
4093
  },
@@ -4171,9 +4129,6 @@ function ContentVariants(props) {
4171
4129
  get content() {
4172
4130
  return defaultContent();
4173
4131
  },
4174
- get classNameProp() {
4175
- return `variant-${props.content?.id}`;
4176
- },
4177
4132
  showContent: true,
4178
4133
  get model() {
4179
4134
  return props.model;