@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/dev.js CHANGED
@@ -2760,7 +2760,9 @@ var componentInfo11 = {
2760
2760
  advanced: true
2761
2761
  }]
2762
2762
  };
2763
- var _tmpl$13 = /* @__PURE__ */ template(`<video>`);
2763
+ var _tmpl$13 = /* @__PURE__ */ template(`<source type=video/mp4>`);
2764
+ var _tmpl$23 = /* @__PURE__ */ template(`<div>`);
2765
+ var _tmpl$33 = /* @__PURE__ */ template(`<div><video class=builder-video>`);
2764
2766
  function Video(props) {
2765
2767
  function videoProps() {
2766
2768
  return {
@@ -2783,13 +2785,13 @@ function Video(props) {
2783
2785
  }
2784
2786
  function spreadProps() {
2785
2787
  return {
2786
- ...props.attributes,
2787
2788
  ...videoProps()
2788
2789
  };
2789
2790
  }
2790
2791
  return (() => {
2791
- const _el$ = _tmpl$13();
2792
- spread(_el$, mergeProps(spreadProps, {
2792
+ const _el$ = _tmpl$33(), _el$2 = _el$.firstChild;
2793
+ _el$.style.setProperty("position", "relative");
2794
+ spread(_el$2, mergeProps(spreadProps, {
2793
2795
  get preload() {
2794
2796
  return props.preload || "metadata";
2795
2797
  },
@@ -2802,7 +2804,11 @@ function Video(props) {
2802
2804
  "object-position": props.position,
2803
2805
  // Hack to get object fit to work as expected and
2804
2806
  // not have the video overflow
2805
- "border-radius": 1
2807
+ "z-index": 2,
2808
+ "border-radius": "1px",
2809
+ ...props.aspectRatio ? {
2810
+ position: "absolute"
2811
+ } : null
2806
2812
  };
2807
2813
  },
2808
2814
  get src() {
@@ -2811,7 +2817,62 @@ function Video(props) {
2811
2817
  get poster() {
2812
2818
  return props.posterImage;
2813
2819
  }
2814
- }), false, false);
2820
+ }), false, true);
2821
+ insert(_el$2, createComponent(Show, {
2822
+ get when() {
2823
+ return !props.lazyLoad;
2824
+ },
2825
+ get children() {
2826
+ const _el$3 = _tmpl$13();
2827
+ effect(() => setAttribute(_el$3, "src", props.video));
2828
+ return _el$3;
2829
+ }
2830
+ }));
2831
+ insert(_el$, createComponent(Show, {
2832
+ get when() {
2833
+ return props.aspectRatio && !(props.fitContent && props.builderBlock?.children?.length);
2834
+ },
2835
+ get children() {
2836
+ const _el$4 = _tmpl$23();
2837
+ _el$4.style.setProperty("width", "100%");
2838
+ _el$4.style.setProperty("pointer-events", "none");
2839
+ _el$4.style.setProperty("font-size", "0px");
2840
+ effect(() => props.aspectRatio * 100 + "%" != null ? _el$4.style.setProperty("padding-top", props.aspectRatio * 100 + "%") : _el$4.style.removeProperty("padding-top"));
2841
+ return _el$4;
2842
+ }
2843
+ }), null);
2844
+ insert(_el$, createComponent(Show, {
2845
+ get when() {
2846
+ return props.builderBlock?.children?.length && props.fitContent;
2847
+ },
2848
+ get children() {
2849
+ const _el$5 = _tmpl$23();
2850
+ _el$5.style.setProperty("display", "flex");
2851
+ _el$5.style.setProperty("flex-direction", "column");
2852
+ _el$5.style.setProperty("align-items", "stretch");
2853
+ insert(_el$5, () => props.children);
2854
+ return _el$5;
2855
+ }
2856
+ }), null);
2857
+ insert(_el$, createComponent(Show, {
2858
+ get when() {
2859
+ return props.builderBlock?.children?.length && !props.fitContent;
2860
+ },
2861
+ get children() {
2862
+ const _el$6 = _tmpl$23();
2863
+ _el$6.style.setProperty("pointer-events", "none");
2864
+ _el$6.style.setProperty("display", "flex");
2865
+ _el$6.style.setProperty("flex-direction", "column");
2866
+ _el$6.style.setProperty("align-items", "stretch");
2867
+ _el$6.style.setProperty("position", "absolute");
2868
+ _el$6.style.setProperty("top", "0");
2869
+ _el$6.style.setProperty("left", "0");
2870
+ _el$6.style.setProperty("width", "100%");
2871
+ _el$6.style.setProperty("height", "100%");
2872
+ insert(_el$6, () => props.children);
2873
+ return _el$6;
2874
+ }
2875
+ }), null);
2815
2876
  return _el$;
2816
2877
  })();
2817
2878
  }
@@ -2876,13 +2937,19 @@ var serializeComponentInfo = ({
2876
2937
  }), {}))
2877
2938
  });
2878
2939
 
2940
+ // src/components/content-variants/inlined-fns.ts
2941
+ 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}";
2942
+ 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}";
2943
+
2879
2944
  // src/components/content-variants/helpers.ts
2945
+ var UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME = "builderIoAbTest";
2946
+ var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME = "builderIoRenderContent";
2880
2947
  var getVariants = (content) => Object.values(content?.variations || {}).map((variant) => ({
2881
2948
  ...variant,
2882
2949
  testVariationId: variant.id,
2883
2950
  id: content?.id
2884
2951
  }));
2885
- var checkShouldRunVariants = ({
2952
+ var checkShouldRenderVariants = ({
2886
2953
  canTrack,
2887
2954
  content
2888
2955
  }) => {
@@ -2893,139 +2960,34 @@ var checkShouldRunVariants = ({
2893
2960
  return false;
2894
2961
  if (!canTrack)
2895
2962
  return false;
2896
- if (TARGET === "vue2" || TARGET === "vue3")
2963
+ if (TARGET === "vue2" || TARGET === "vue3" || TARGET === "svelte")
2897
2964
  return true;
2898
2965
  if (isBrowser())
2899
2966
  return false;
2900
2967
  return true;
2901
2968
  };
2902
- function bldrAbTest(contentId, variants, isHydrationTarget2) {
2903
- function getAndSetVariantId2() {
2904
- function setCookie2(name, value, days) {
2905
- let expires = "";
2906
- if (days) {
2907
- const date = /* @__PURE__ */ new Date();
2908
- date.setTime(date.getTime() + days * 24 * 60 * 60 * 1e3);
2909
- expires = "; expires=" + date.toUTCString();
2910
- }
2911
- document.cookie = name + "=" + (value || "") + expires + "; path=/; Secure; SameSite=None";
2912
- }
2913
- function getCookie2(name) {
2914
- const nameEQ = name + "=";
2915
- const ca = document.cookie.split(";");
2916
- for (let i = 0; i < ca.length; i++) {
2917
- let c = ca[i];
2918
- while (c.charAt(0) === " ")
2919
- c = c.substring(1, c.length);
2920
- if (c.indexOf(nameEQ) === 0)
2921
- return c.substring(nameEQ.length, c.length);
2922
- }
2923
- return null;
2924
- }
2925
- const cookieName = `builder.tests.${contentId}`;
2926
- const variantInCookie = getCookie2(cookieName);
2927
- const availableIDs = variants.map((vr) => vr.id).concat(contentId);
2928
- if (variantInCookie && availableIDs.includes(variantInCookie)) {
2929
- return variantInCookie;
2930
- }
2931
- let n = 0;
2932
- const random = Math.random();
2933
- for (let i = 0; i < variants.length; i++) {
2934
- const variant = variants[i];
2935
- const testRatio = variant.testRatio;
2936
- n += testRatio;
2937
- if (random < n) {
2938
- setCookie2(cookieName, variant.id);
2939
- return variant.id;
2940
- }
2941
- }
2942
- setCookie2(cookieName, contentId);
2943
- return contentId;
2944
- }
2945
- const winningVariantId = getAndSetVariantId2();
2946
- const styleEl = document.currentScript?.previousElementSibling;
2947
- if (isHydrationTarget2) {
2948
- styleEl.remove();
2949
- const thisScriptEl = document.currentScript;
2950
- thisScriptEl?.remove();
2951
- } else {
2952
- const newStyleStr = variants.concat({
2953
- id: contentId
2954
- }).filter((variant) => variant.id !== winningVariantId).map((value) => {
2955
- return `.variant-${value.id} { display: none; }
2956
- `;
2957
- }).join("");
2958
- styleEl.innerHTML = newStyleStr;
2959
- }
2960
- }
2961
- function bldrCntntScrpt(variantContentId, defaultContentId, isHydrationTarget2) {
2962
- if (!navigator.cookieEnabled) {
2963
- return;
2964
- }
2965
- function getCookie2(name) {
2966
- const nameEQ = name + "=";
2967
- const ca = document.cookie.split(";");
2968
- for (let i = 0; i < ca.length; i++) {
2969
- let c = ca[i];
2970
- while (c.charAt(0) === " ")
2971
- c = c.substring(1, c.length);
2972
- if (c.indexOf(nameEQ) === 0)
2973
- return c.substring(nameEQ.length, c.length);
2974
- }
2975
- return null;
2976
- }
2977
- const cookieName = `builder.tests.${defaultContentId}`;
2978
- const variantId = getCookie2(cookieName);
2979
- const parentDiv = document.currentScript?.parentElement;
2980
- const variantIsDefaultContent = variantContentId === defaultContentId;
2981
- if (variantId === variantContentId) {
2982
- if (variantIsDefaultContent) {
2983
- return;
2984
- }
2985
- parentDiv?.removeAttribute("hidden");
2986
- parentDiv?.removeAttribute("aria-hidden");
2987
- } else {
2988
- if (variantIsDefaultContent) {
2989
- if (isHydrationTarget2) {
2990
- parentDiv?.remove();
2991
- } else {
2992
- parentDiv?.setAttribute("hidden", "true");
2993
- parentDiv?.setAttribute("aria-hidden", "true");
2994
- }
2995
- }
2996
- return;
2997
- }
2998
- return;
2999
- }
3000
2969
  var getIsHydrationTarget = (target) => target === "react" || target === "reactNative";
3001
2970
  var isHydrationTarget = getIsHydrationTarget(TARGET);
3002
- var AB_TEST_FN_NAME = "builderIoAbTest";
3003
- var CONTENT_FN_NAME = "builderIoRenderContent";
3004
- var getScriptString = () => {
3005
- const fnStr = bldrAbTest.toString().replace(/\s+/g, " ");
3006
- const fnStr2 = bldrCntntScrpt.toString().replace(/\s+/g, " ");
3007
- return `
3008
- window.${AB_TEST_FN_NAME} = ${fnStr}
3009
- window.${CONTENT_FN_NAME} = ${fnStr2}
2971
+ var getScriptString = () => `
2972
+ window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
2973
+ window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
3010
2974
  `;
3011
- };
3012
- var getVariantsScriptString = (variants, contentId) => {
3013
- return `
3014
- window.${AB_TEST_FN_NAME}("${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget})`;
3015
- };
3016
- var getRenderContentScriptString = ({
2975
+ var getUpdateCookieAndStylesScript = (variants, contentId) => `
2976
+ window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME}(
2977
+ "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget}
2978
+ )`;
2979
+ var getUpdateVariantVisibilityScript = ({
3017
2980
  contentId,
3018
2981
  variationId
3019
- }) => {
3020
- return `
3021
- window.${CONTENT_FN_NAME}("${variationId}", "${contentId}", ${isHydrationTarget})`;
3022
- };
2982
+ }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME}(
2983
+ "${variationId}", "${contentId}", ${isHydrationTarget}
2984
+ )`;
3023
2985
  var _tmpl$14 = /* @__PURE__ */ template(`<script>`);
3024
2986
  function InlinedScript(props) {
3025
2987
  return (() => {
3026
2988
  const _el$ = _tmpl$14();
3027
2989
  effect((_p$) => {
3028
- const _v$ = props.scriptStr, _v$2 = props.id;
2990
+ const _v$ = props.scriptStr, _v$2 = props.id || "";
3029
2991
  _v$ !== _p$._v$ && (_el$.innerHTML = _p$._v$ = _v$);
3030
2992
  _v$2 !== _p$._v$2 && setAttribute(_el$, "id", _p$._v$2 = _v$2);
3031
2993
  return _p$;
@@ -3523,7 +3485,7 @@ var getInteractionPropertiesForEvent = (event) => {
3523
3485
  };
3524
3486
 
3525
3487
  // src/constants/sdk-version.ts
3526
- var SDK_VERSION = "0.7.3";
3488
+ var SDK_VERSION = "0.7.4";
3527
3489
 
3528
3490
  // src/functions/register.ts
3529
3491
  var registry = {};
@@ -3899,7 +3861,7 @@ function EnableEditor(props) {
3899
3861
  typeof _ref$ === "function" ? use(_ref$, _el$) : elementRef = _el$;
3900
3862
  spread(_el$, mergeProps({
3901
3863
  get ["class"]() {
3902
- return props.classNameProp;
3864
+ return `variant-${props.content?.testVariationId || props.content?.id}`;
3903
3865
  }
3904
3866
  }, {}, {
3905
3867
  get key() {
@@ -4052,7 +4014,7 @@ var getContentInitialValue = ({
4052
4014
 
4053
4015
  // src/components/content/content.tsx
4054
4016
  function ContentComponent(props) {
4055
- const [scriptStr, setScriptStr] = createSignal(getRenderContentScriptString({
4017
+ const [scriptStr, setScriptStr] = createSignal(getUpdateVariantVisibilityScript({
4056
4018
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
4057
4019
  variationId: props.content?.testVariationId,
4058
4020
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
@@ -4148,9 +4110,6 @@ function ContentComponent(props) {
4148
4110
  get enrich() {
4149
4111
  return props.enrich;
4150
4112
  },
4151
- get classNameProp() {
4152
- return props.classNameProp;
4153
- },
4154
4113
  get showContent() {
4155
4114
  return props.showContent;
4156
4115
  },
@@ -4207,12 +4166,12 @@ var content_default = ContentComponent;
4207
4166
 
4208
4167
  // src/components/content-variants/content-variants.tsx
4209
4168
  function ContentVariants(props) {
4210
- const [shouldRenderVariants, setShouldRenderVariants] = createSignal(checkShouldRunVariants({
4169
+ const [shouldRenderVariants, setShouldRenderVariants] = createSignal(checkShouldRenderVariants({
4211
4170
  canTrack: getDefaultCanTrack(props.canTrack),
4212
4171
  content: props.content
4213
4172
  }));
4214
- function variantScriptStr() {
4215
- return getVariantsScriptString(getVariants(props.content).map((value) => ({
4173
+ function updateCookieAndStylesScriptStr() {
4174
+ return getUpdateCookieAndStylesScript(getVariants(props.content).map((value) => ({
4216
4175
  id: value.testVariationId,
4217
4176
  testRatio: value.testRatio
4218
4177
  })), props.content?.id || "");
@@ -4257,7 +4216,7 @@ function ContentVariants(props) {
4257
4216
  }
4258
4217
  }), createComponent(inlined_script_default, {
4259
4218
  get scriptStr() {
4260
- return variantScriptStr();
4219
+ return updateCookieAndStylesScriptStr();
4261
4220
  }
4262
4221
  }), createComponent(For, {
4263
4222
  get each() {
@@ -4271,7 +4230,6 @@ function ContentVariants(props) {
4271
4230
  },
4272
4231
  content: variant,
4273
4232
  showContent: false,
4274
- classNameProp: void 0,
4275
4233
  get model() {
4276
4234
  return props.model;
4277
4235
  },
@@ -4313,9 +4271,6 @@ function ContentVariants(props) {
4313
4271
  get content() {
4314
4272
  return defaultContent();
4315
4273
  },
4316
- get classNameProp() {
4317
- return `variant-${props.content?.id}`;
4318
- },
4319
4274
  showContent: true,
4320
4275
  get model() {
4321
4276
  return props.model;