@builder.io/sdk-solid 0.7.3 → 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.
package/lib/node/index.js CHANGED
@@ -2743,7 +2743,9 @@ var componentInfo11 = {
2743
2743
  advanced: true
2744
2744
  }]
2745
2745
  };
2746
- var _tmpl$13 = /* @__PURE__ */ template(`<video>`);
2746
+ var _tmpl$13 = /* @__PURE__ */ template(`<source type=video/mp4>`);
2747
+ var _tmpl$23 = /* @__PURE__ */ template(`<div>`);
2748
+ var _tmpl$33 = /* @__PURE__ */ template(`<div><video class=builder-video>`);
2747
2749
  function Video(props) {
2748
2750
  function videoProps() {
2749
2751
  return {
@@ -2766,13 +2768,13 @@ function Video(props) {
2766
2768
  }
2767
2769
  function spreadProps() {
2768
2770
  return {
2769
- ...props.attributes,
2770
2771
  ...videoProps()
2771
2772
  };
2772
2773
  }
2773
2774
  return (() => {
2774
- const _el$ = _tmpl$13();
2775
- spread(_el$, mergeProps(spreadProps, {
2775
+ const _el$ = _tmpl$33(), _el$2 = _el$.firstChild;
2776
+ _el$.style.setProperty("position", "relative");
2777
+ spread(_el$2, mergeProps(spreadProps, {
2776
2778
  get preload() {
2777
2779
  return props.preload || "metadata";
2778
2780
  },
@@ -2785,7 +2787,11 @@ function Video(props) {
2785
2787
  "object-position": props.position,
2786
2788
  // Hack to get object fit to work as expected and
2787
2789
  // not have the video overflow
2788
- "border-radius": 1
2790
+ "z-index": 2,
2791
+ "border-radius": "1px",
2792
+ ...props.aspectRatio ? {
2793
+ position: "absolute"
2794
+ } : null
2789
2795
  };
2790
2796
  },
2791
2797
  get src() {
@@ -2794,7 +2800,62 @@ function Video(props) {
2794
2800
  get poster() {
2795
2801
  return props.posterImage;
2796
2802
  }
2797
- }), false, false);
2803
+ }), false, true);
2804
+ insert(_el$2, createComponent(Show, {
2805
+ get when() {
2806
+ return !props.lazyLoad;
2807
+ },
2808
+ get children() {
2809
+ const _el$3 = _tmpl$13();
2810
+ effect(() => setAttribute(_el$3, "src", props.video));
2811
+ return _el$3;
2812
+ }
2813
+ }));
2814
+ insert(_el$, createComponent(Show, {
2815
+ get when() {
2816
+ return props.aspectRatio && !(props.fitContent && props.builderBlock?.children?.length);
2817
+ },
2818
+ get children() {
2819
+ const _el$4 = _tmpl$23();
2820
+ _el$4.style.setProperty("width", "100%");
2821
+ _el$4.style.setProperty("pointer-events", "none");
2822
+ _el$4.style.setProperty("font-size", "0px");
2823
+ effect(() => props.aspectRatio * 100 + "%" != null ? _el$4.style.setProperty("padding-top", props.aspectRatio * 100 + "%") : _el$4.style.removeProperty("padding-top"));
2824
+ return _el$4;
2825
+ }
2826
+ }), null);
2827
+ insert(_el$, createComponent(Show, {
2828
+ get when() {
2829
+ return props.builderBlock?.children?.length && props.fitContent;
2830
+ },
2831
+ get children() {
2832
+ const _el$5 = _tmpl$23();
2833
+ _el$5.style.setProperty("display", "flex");
2834
+ _el$5.style.setProperty("flex-direction", "column");
2835
+ _el$5.style.setProperty("align-items", "stretch");
2836
+ insert(_el$5, () => props.children);
2837
+ return _el$5;
2838
+ }
2839
+ }), null);
2840
+ insert(_el$, createComponent(Show, {
2841
+ get when() {
2842
+ return props.builderBlock?.children?.length && !props.fitContent;
2843
+ },
2844
+ get children() {
2845
+ const _el$6 = _tmpl$23();
2846
+ _el$6.style.setProperty("pointer-events", "none");
2847
+ _el$6.style.setProperty("display", "flex");
2848
+ _el$6.style.setProperty("flex-direction", "column");
2849
+ _el$6.style.setProperty("align-items", "stretch");
2850
+ _el$6.style.setProperty("position", "absolute");
2851
+ _el$6.style.setProperty("top", "0");
2852
+ _el$6.style.setProperty("left", "0");
2853
+ _el$6.style.setProperty("width", "100%");
2854
+ _el$6.style.setProperty("height", "100%");
2855
+ insert(_el$6, () => props.children);
2856
+ return _el$6;
2857
+ }
2858
+ }), null);
2798
2859
  return _el$;
2799
2860
  })();
2800
2861
  }
@@ -2859,13 +2920,19 @@ var serializeComponentInfo = ({
2859
2920
  }), {}))
2860
2921
  });
2861
2922
 
2923
+ // src/components/content-variants/inlined-fns.ts
2924
+ 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}";
2925
+ 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}";
2926
+
2862
2927
  // src/components/content-variants/helpers.ts
2928
+ var UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME = "builderIoAbTest";
2929
+ var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME = "builderIoRenderContent";
2863
2930
  var getVariants = (content) => Object.values(content?.variations || {}).map((variant) => ({
2864
2931
  ...variant,
2865
2932
  testVariationId: variant.id,
2866
2933
  id: content?.id
2867
2934
  }));
2868
- var checkShouldRunVariants = ({
2935
+ var checkShouldRenderVariants = ({
2869
2936
  canTrack,
2870
2937
  content
2871
2938
  }) => {
@@ -2876,139 +2943,34 @@ var checkShouldRunVariants = ({
2876
2943
  return false;
2877
2944
  if (!canTrack)
2878
2945
  return false;
2879
- if (TARGET === "vue2" || TARGET === "vue3")
2946
+ if (TARGET === "vue2" || TARGET === "vue3" || TARGET === "svelte")
2880
2947
  return true;
2881
2948
  if (isBrowser())
2882
2949
  return false;
2883
2950
  return true;
2884
2951
  };
2885
- function bldrAbTest(contentId, variants, isHydrationTarget2) {
2886
- function getAndSetVariantId2() {
2887
- function setCookie2(name, value, days) {
2888
- let expires = "";
2889
- if (days) {
2890
- const date = /* @__PURE__ */ new Date();
2891
- date.setTime(date.getTime() + days * 24 * 60 * 60 * 1e3);
2892
- expires = "; expires=" + date.toUTCString();
2893
- }
2894
- document.cookie = name + "=" + (value || "") + expires + "; path=/; Secure; SameSite=None";
2895
- }
2896
- function getCookie2(name) {
2897
- const nameEQ = name + "=";
2898
- const ca = document.cookie.split(";");
2899
- for (let i = 0; i < ca.length; i++) {
2900
- let c = ca[i];
2901
- while (c.charAt(0) === " ")
2902
- c = c.substring(1, c.length);
2903
- if (c.indexOf(nameEQ) === 0)
2904
- return c.substring(nameEQ.length, c.length);
2905
- }
2906
- return null;
2907
- }
2908
- const cookieName = `builder.tests.${contentId}`;
2909
- const variantInCookie = getCookie2(cookieName);
2910
- const availableIDs = variants.map((vr) => vr.id).concat(contentId);
2911
- if (variantInCookie && availableIDs.includes(variantInCookie)) {
2912
- return variantInCookie;
2913
- }
2914
- let n = 0;
2915
- const random = Math.random();
2916
- for (let i = 0; i < variants.length; i++) {
2917
- const variant = variants[i];
2918
- const testRatio = variant.testRatio;
2919
- n += testRatio;
2920
- if (random < n) {
2921
- setCookie2(cookieName, variant.id);
2922
- return variant.id;
2923
- }
2924
- }
2925
- setCookie2(cookieName, contentId);
2926
- return contentId;
2927
- }
2928
- const winningVariantId = getAndSetVariantId2();
2929
- const styleEl = document.currentScript?.previousElementSibling;
2930
- if (isHydrationTarget2) {
2931
- styleEl.remove();
2932
- const thisScriptEl = document.currentScript;
2933
- thisScriptEl?.remove();
2934
- } else {
2935
- const newStyleStr = variants.concat({
2936
- id: contentId
2937
- }).filter((variant) => variant.id !== winningVariantId).map((value) => {
2938
- return `.variant-${value.id} { display: none; }
2939
- `;
2940
- }).join("");
2941
- styleEl.innerHTML = newStyleStr;
2942
- }
2943
- }
2944
- function bldrCntntScrpt(variantContentId, defaultContentId, isHydrationTarget2) {
2945
- if (!navigator.cookieEnabled) {
2946
- return;
2947
- }
2948
- function getCookie2(name) {
2949
- const nameEQ = name + "=";
2950
- const ca = document.cookie.split(";");
2951
- for (let i = 0; i < ca.length; i++) {
2952
- let c = ca[i];
2953
- while (c.charAt(0) === " ")
2954
- c = c.substring(1, c.length);
2955
- if (c.indexOf(nameEQ) === 0)
2956
- return c.substring(nameEQ.length, c.length);
2957
- }
2958
- return null;
2959
- }
2960
- const cookieName = `builder.tests.${defaultContentId}`;
2961
- const variantId = getCookie2(cookieName);
2962
- const parentDiv = document.currentScript?.parentElement;
2963
- const variantIsDefaultContent = variantContentId === defaultContentId;
2964
- if (variantId === variantContentId) {
2965
- if (variantIsDefaultContent) {
2966
- return;
2967
- }
2968
- parentDiv?.removeAttribute("hidden");
2969
- parentDiv?.removeAttribute("aria-hidden");
2970
- } else {
2971
- if (variantIsDefaultContent) {
2972
- if (isHydrationTarget2) {
2973
- parentDiv?.remove();
2974
- } else {
2975
- parentDiv?.setAttribute("hidden", "true");
2976
- parentDiv?.setAttribute("aria-hidden", "true");
2977
- }
2978
- }
2979
- return;
2980
- }
2981
- return;
2982
- }
2983
2952
  var getIsHydrationTarget = (target) => target === "react" || target === "reactNative";
2984
2953
  var isHydrationTarget = getIsHydrationTarget(TARGET);
2985
- var AB_TEST_FN_NAME = "builderIoAbTest";
2986
- var CONTENT_FN_NAME = "builderIoRenderContent";
2987
- var getScriptString = () => {
2988
- const fnStr = bldrAbTest.toString().replace(/\s+/g, " ");
2989
- const fnStr2 = bldrCntntScrpt.toString().replace(/\s+/g, " ");
2990
- return `
2991
- window.${AB_TEST_FN_NAME} = ${fnStr}
2992
- window.${CONTENT_FN_NAME} = ${fnStr2}
2954
+ var getScriptString = () => `
2955
+ window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
2956
+ window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
2993
2957
  `;
2994
- };
2995
- var getVariantsScriptString = (variants, contentId) => {
2996
- return `
2997
- window.${AB_TEST_FN_NAME}("${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget})`;
2998
- };
2999
- var getRenderContentScriptString = ({
2958
+ var getUpdateCookieAndStylesScript = (variants, contentId) => `
2959
+ window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME}(
2960
+ "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget}
2961
+ )`;
2962
+ var getUpdateVariantVisibilityScript = ({
3000
2963
  contentId,
3001
2964
  variationId
3002
- }) => {
3003
- return `
3004
- window.${CONTENT_FN_NAME}("${variationId}", "${contentId}", ${isHydrationTarget})`;
3005
- };
2965
+ }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME}(
2966
+ "${variationId}", "${contentId}", ${isHydrationTarget}
2967
+ )`;
3006
2968
  var _tmpl$14 = /* @__PURE__ */ template(`<script>`);
3007
2969
  function InlinedScript(props) {
3008
2970
  return (() => {
3009
2971
  const _el$ = _tmpl$14();
3010
2972
  effect((_p$) => {
3011
- const _v$ = props.scriptStr, _v$2 = props.id;
2973
+ const _v$ = props.scriptStr, _v$2 = props.id || "";
3012
2974
  _v$ !== _p$._v$ && (_el$.innerHTML = _p$._v$ = _v$);
3013
2975
  _v$2 !== _p$._v$2 && setAttribute(_el$, "id", _p$._v$2 = _v$2);
3014
2976
  return _p$;
@@ -3501,7 +3463,7 @@ var getInteractionPropertiesForEvent = (event) => {
3501
3463
  };
3502
3464
 
3503
3465
  // src/constants/sdk-version.ts
3504
- var SDK_VERSION = "0.7.3";
3466
+ var SDK_VERSION = "0.7.4";
3505
3467
 
3506
3468
  // src/functions/register.ts
3507
3469
  var registry = {};
@@ -3875,7 +3837,7 @@ function EnableEditor(props) {
3875
3837
  typeof _ref$ === "function" ? use(_ref$, _el$) : elementRef = _el$;
3876
3838
  spread(_el$, mergeProps({
3877
3839
  get ["class"]() {
3878
- return props.classNameProp;
3840
+ return `variant-${props.content?.testVariationId || props.content?.id}`;
3879
3841
  }
3880
3842
  }, {}, {
3881
3843
  get key() {
@@ -4028,7 +3990,7 @@ var getContentInitialValue = ({
4028
3990
 
4029
3991
  // src/components/content/content.tsx
4030
3992
  function ContentComponent(props) {
4031
- const [scriptStr, setScriptStr] = createSignal(getRenderContentScriptString({
3993
+ const [scriptStr, setScriptStr] = createSignal(getUpdateVariantVisibilityScript({
4032
3994
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
4033
3995
  variationId: props.content?.testVariationId,
4034
3996
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
@@ -4124,9 +4086,6 @@ function ContentComponent(props) {
4124
4086
  get enrich() {
4125
4087
  return props.enrich;
4126
4088
  },
4127
- get classNameProp() {
4128
- return props.classNameProp;
4129
- },
4130
4089
  get showContent() {
4131
4090
  return props.showContent;
4132
4091
  },
@@ -4183,12 +4142,12 @@ var content_default = ContentComponent;
4183
4142
 
4184
4143
  // src/components/content-variants/content-variants.tsx
4185
4144
  function ContentVariants(props) {
4186
- const [shouldRenderVariants, setShouldRenderVariants] = createSignal(checkShouldRunVariants({
4145
+ const [shouldRenderVariants, setShouldRenderVariants] = createSignal(checkShouldRenderVariants({
4187
4146
  canTrack: getDefaultCanTrack(props.canTrack),
4188
4147
  content: props.content
4189
4148
  }));
4190
- function variantScriptStr() {
4191
- return getVariantsScriptString(getVariants(props.content).map((value) => ({
4149
+ function updateCookieAndStylesScriptStr() {
4150
+ return getUpdateCookieAndStylesScript(getVariants(props.content).map((value) => ({
4192
4151
  id: value.testVariationId,
4193
4152
  testRatio: value.testRatio
4194
4153
  })), props.content?.id || "");
@@ -4233,7 +4192,7 @@ function ContentVariants(props) {
4233
4192
  }
4234
4193
  }), createComponent(inlined_script_default, {
4235
4194
  get scriptStr() {
4236
- return variantScriptStr();
4195
+ return updateCookieAndStylesScriptStr();
4237
4196
  }
4238
4197
  }), createComponent(For, {
4239
4198
  get each() {
@@ -4247,7 +4206,6 @@ function ContentVariants(props) {
4247
4206
  },
4248
4207
  content: variant,
4249
4208
  showContent: false,
4250
- classNameProp: void 0,
4251
4209
  get model() {
4252
4210
  return props.model;
4253
4211
  },
@@ -4289,9 +4247,6 @@ function ContentVariants(props) {
4289
4247
  get content() {
4290
4248
  return defaultContent();
4291
4249
  },
4292
- get classNameProp() {
4293
- return `variant-${props.content?.id}`;
4294
- },
4295
4250
  showContent: true,
4296
4251
  get model() {
4297
4252
  return props.model;