@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.
package/lib/edge/index.js CHANGED
@@ -5778,7 +5778,9 @@ var componentInfo11 = {
5778
5778
  advanced: true
5779
5779
  }]
5780
5780
  };
5781
- var _tmpl$13 = /* @__PURE__ */ template(`<video>`);
5781
+ var _tmpl$13 = /* @__PURE__ */ template(`<source type=video/mp4>`);
5782
+ var _tmpl$23 = /* @__PURE__ */ template(`<div>`);
5783
+ var _tmpl$33 = /* @__PURE__ */ template(`<div><video class=builder-video>`);
5782
5784
  function Video(props) {
5783
5785
  function videoProps() {
5784
5786
  return {
@@ -5801,13 +5803,13 @@ function Video(props) {
5801
5803
  }
5802
5804
  function spreadProps() {
5803
5805
  return {
5804
- ...props.attributes,
5805
5806
  ...videoProps()
5806
5807
  };
5807
5808
  }
5808
5809
  return (() => {
5809
- const _el$ = _tmpl$13();
5810
- spread(_el$, mergeProps(spreadProps, {
5810
+ const _el$ = _tmpl$33(), _el$2 = _el$.firstChild;
5811
+ _el$.style.setProperty("position", "relative");
5812
+ spread(_el$2, mergeProps(spreadProps, {
5811
5813
  get preload() {
5812
5814
  return props.preload || "metadata";
5813
5815
  },
@@ -5820,7 +5822,11 @@ function Video(props) {
5820
5822
  "object-position": props.position,
5821
5823
  // Hack to get object fit to work as expected and
5822
5824
  // not have the video overflow
5823
- "border-radius": 1
5825
+ "z-index": 2,
5826
+ "border-radius": "1px",
5827
+ ...props.aspectRatio ? {
5828
+ position: "absolute"
5829
+ } : null
5824
5830
  };
5825
5831
  },
5826
5832
  get src() {
@@ -5829,7 +5835,62 @@ function Video(props) {
5829
5835
  get poster() {
5830
5836
  return props.posterImage;
5831
5837
  }
5832
- }), false, false);
5838
+ }), false, true);
5839
+ insert(_el$2, createComponent(Show, {
5840
+ get when() {
5841
+ return !props.lazyLoad;
5842
+ },
5843
+ get children() {
5844
+ const _el$3 = _tmpl$13();
5845
+ effect(() => setAttribute(_el$3, "src", props.video));
5846
+ return _el$3;
5847
+ }
5848
+ }));
5849
+ insert(_el$, createComponent(Show, {
5850
+ get when() {
5851
+ return props.aspectRatio && !(props.fitContent && props.builderBlock?.children?.length);
5852
+ },
5853
+ get children() {
5854
+ const _el$4 = _tmpl$23();
5855
+ _el$4.style.setProperty("width", "100%");
5856
+ _el$4.style.setProperty("pointer-events", "none");
5857
+ _el$4.style.setProperty("font-size", "0px");
5858
+ effect(() => props.aspectRatio * 100 + "%" != null ? _el$4.style.setProperty("padding-top", props.aspectRatio * 100 + "%") : _el$4.style.removeProperty("padding-top"));
5859
+ return _el$4;
5860
+ }
5861
+ }), null);
5862
+ insert(_el$, createComponent(Show, {
5863
+ get when() {
5864
+ return props.builderBlock?.children?.length && props.fitContent;
5865
+ },
5866
+ get children() {
5867
+ const _el$5 = _tmpl$23();
5868
+ _el$5.style.setProperty("display", "flex");
5869
+ _el$5.style.setProperty("flex-direction", "column");
5870
+ _el$5.style.setProperty("align-items", "stretch");
5871
+ insert(_el$5, () => props.children);
5872
+ return _el$5;
5873
+ }
5874
+ }), null);
5875
+ insert(_el$, createComponent(Show, {
5876
+ get when() {
5877
+ return props.builderBlock?.children?.length && !props.fitContent;
5878
+ },
5879
+ get children() {
5880
+ const _el$6 = _tmpl$23();
5881
+ _el$6.style.setProperty("pointer-events", "none");
5882
+ _el$6.style.setProperty("display", "flex");
5883
+ _el$6.style.setProperty("flex-direction", "column");
5884
+ _el$6.style.setProperty("align-items", "stretch");
5885
+ _el$6.style.setProperty("position", "absolute");
5886
+ _el$6.style.setProperty("top", "0");
5887
+ _el$6.style.setProperty("left", "0");
5888
+ _el$6.style.setProperty("width", "100%");
5889
+ _el$6.style.setProperty("height", "100%");
5890
+ insert(_el$6, () => props.children);
5891
+ return _el$6;
5892
+ }
5893
+ }), null);
5833
5894
  return _el$;
5834
5895
  })();
5835
5896
  }
@@ -5894,13 +5955,19 @@ var serializeComponentInfo = ({
5894
5955
  }), {}))
5895
5956
  });
5896
5957
 
5958
+ // src/components/content-variants/inlined-fns.ts
5959
+ 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}";
5960
+ 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}";
5961
+
5897
5962
  // src/components/content-variants/helpers.ts
5963
+ var UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME = "builderIoAbTest";
5964
+ var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME = "builderIoRenderContent";
5898
5965
  var getVariants = (content) => Object.values(content?.variations || {}).map((variant) => ({
5899
5966
  ...variant,
5900
5967
  testVariationId: variant.id,
5901
5968
  id: content?.id
5902
5969
  }));
5903
- var checkShouldRunVariants = ({
5970
+ var checkShouldRenderVariants = ({
5904
5971
  canTrack,
5905
5972
  content
5906
5973
  }) => {
@@ -5911,139 +5978,34 @@ var checkShouldRunVariants = ({
5911
5978
  return false;
5912
5979
  if (!canTrack)
5913
5980
  return false;
5914
- if (TARGET === "vue2" || TARGET === "vue3")
5981
+ if (TARGET === "vue2" || TARGET === "vue3" || TARGET === "svelte")
5915
5982
  return true;
5916
5983
  if (isBrowser())
5917
5984
  return false;
5918
5985
  return true;
5919
5986
  };
5920
- function bldrAbTest(contentId, variants, isHydrationTarget2) {
5921
- function getAndSetVariantId2() {
5922
- function setCookie2(name, value, days) {
5923
- let expires = "";
5924
- if (days) {
5925
- const date = /* @__PURE__ */ new Date();
5926
- date.setTime(date.getTime() + days * 24 * 60 * 60 * 1e3);
5927
- expires = "; expires=" + date.toUTCString();
5928
- }
5929
- document.cookie = name + "=" + (value || "") + expires + "; path=/; Secure; SameSite=None";
5930
- }
5931
- function getCookie2(name) {
5932
- const nameEQ = name + "=";
5933
- const ca2 = document.cookie.split(";");
5934
- for (let i = 0; i < ca2.length; i++) {
5935
- let c = ca2[i];
5936
- while (c.charAt(0) === " ")
5937
- c = c.substring(1, c.length);
5938
- if (c.indexOf(nameEQ) === 0)
5939
- return c.substring(nameEQ.length, c.length);
5940
- }
5941
- return null;
5942
- }
5943
- const cookieName = `builder.tests.${contentId}`;
5944
- const variantInCookie = getCookie2(cookieName);
5945
- const availableIDs = variants.map((vr) => vr.id).concat(contentId);
5946
- if (variantInCookie && availableIDs.includes(variantInCookie)) {
5947
- return variantInCookie;
5948
- }
5949
- let n = 0;
5950
- const random = Math.random();
5951
- for (let i = 0; i < variants.length; i++) {
5952
- const variant = variants[i];
5953
- const testRatio = variant.testRatio;
5954
- n += testRatio;
5955
- if (random < n) {
5956
- setCookie2(cookieName, variant.id);
5957
- return variant.id;
5958
- }
5959
- }
5960
- setCookie2(cookieName, contentId);
5961
- return contentId;
5962
- }
5963
- const winningVariantId = getAndSetVariantId2();
5964
- const styleEl = document.currentScript?.previousElementSibling;
5965
- if (isHydrationTarget2) {
5966
- styleEl.remove();
5967
- const thisScriptEl = document.currentScript;
5968
- thisScriptEl?.remove();
5969
- } else {
5970
- const newStyleStr = variants.concat({
5971
- id: contentId
5972
- }).filter((variant) => variant.id !== winningVariantId).map((value) => {
5973
- return `.variant-${value.id} { display: none; }
5974
- `;
5975
- }).join("");
5976
- styleEl.innerHTML = newStyleStr;
5977
- }
5978
- }
5979
- function bldrCntntScrpt(variantContentId, defaultContentId, isHydrationTarget2) {
5980
- if (!navigator.cookieEnabled) {
5981
- return;
5982
- }
5983
- function getCookie2(name) {
5984
- const nameEQ = name + "=";
5985
- const ca2 = document.cookie.split(";");
5986
- for (let i = 0; i < ca2.length; i++) {
5987
- let c = ca2[i];
5988
- while (c.charAt(0) === " ")
5989
- c = c.substring(1, c.length);
5990
- if (c.indexOf(nameEQ) === 0)
5991
- return c.substring(nameEQ.length, c.length);
5992
- }
5993
- return null;
5994
- }
5995
- const cookieName = `builder.tests.${defaultContentId}`;
5996
- const variantId = getCookie2(cookieName);
5997
- const parentDiv = document.currentScript?.parentElement;
5998
- const variantIsDefaultContent = variantContentId === defaultContentId;
5999
- if (variantId === variantContentId) {
6000
- if (variantIsDefaultContent) {
6001
- return;
6002
- }
6003
- parentDiv?.removeAttribute("hidden");
6004
- parentDiv?.removeAttribute("aria-hidden");
6005
- } else {
6006
- if (variantIsDefaultContent) {
6007
- if (isHydrationTarget2) {
6008
- parentDiv?.remove();
6009
- } else {
6010
- parentDiv?.setAttribute("hidden", "true");
6011
- parentDiv?.setAttribute("aria-hidden", "true");
6012
- }
6013
- }
6014
- return;
6015
- }
6016
- return;
6017
- }
6018
5987
  var getIsHydrationTarget = (target) => target === "react" || target === "reactNative";
6019
5988
  var isHydrationTarget = getIsHydrationTarget(TARGET);
6020
- var AB_TEST_FN_NAME = "builderIoAbTest";
6021
- var CONTENT_FN_NAME = "builderIoRenderContent";
6022
- var getScriptString = () => {
6023
- const fnStr = bldrAbTest.toString().replace(/\s+/g, " ");
6024
- const fnStr2 = bldrCntntScrpt.toString().replace(/\s+/g, " ");
6025
- return `
6026
- window.${AB_TEST_FN_NAME} = ${fnStr}
6027
- window.${CONTENT_FN_NAME} = ${fnStr2}
5989
+ var getScriptString = () => `
5990
+ window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
5991
+ window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
6028
5992
  `;
6029
- };
6030
- var getVariantsScriptString = (variants, contentId) => {
6031
- return `
6032
- window.${AB_TEST_FN_NAME}("${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget})`;
6033
- };
6034
- var getRenderContentScriptString = ({
5993
+ var getUpdateCookieAndStylesScript = (variants, contentId) => `
5994
+ window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME}(
5995
+ "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget}
5996
+ )`;
5997
+ var getUpdateVariantVisibilityScript = ({
6035
5998
  contentId,
6036
5999
  variationId
6037
- }) => {
6038
- return `
6039
- window.${CONTENT_FN_NAME}("${variationId}", "${contentId}", ${isHydrationTarget})`;
6040
- };
6000
+ }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME}(
6001
+ "${variationId}", "${contentId}", ${isHydrationTarget}
6002
+ )`;
6041
6003
  var _tmpl$14 = /* @__PURE__ */ template(`<script>`);
6042
6004
  function InlinedScript(props) {
6043
6005
  return (() => {
6044
6006
  const _el$ = _tmpl$14();
6045
6007
  effect((_p$) => {
6046
- const _v$ = props.scriptStr, _v$2 = props.id;
6008
+ const _v$ = props.scriptStr, _v$2 = props.id || "";
6047
6009
  _v$ !== _p$._v$ && (_el$.innerHTML = _p$._v$ = _v$);
6048
6010
  _v$2 !== _p$._v$2 && setAttribute(_el$, "id", _p$._v$2 = _v$2);
6049
6011
  return _p$;
@@ -6536,7 +6498,7 @@ var getInteractionPropertiesForEvent = (event) => {
6536
6498
  };
6537
6499
 
6538
6500
  // src/constants/sdk-version.ts
6539
- var SDK_VERSION = "0.7.2";
6501
+ var SDK_VERSION = "0.7.4";
6540
6502
 
6541
6503
  // src/functions/register.ts
6542
6504
  var registry = {};
@@ -6910,7 +6872,7 @@ function EnableEditor(props) {
6910
6872
  typeof _ref$ === "function" ? use(_ref$, _el$) : elementRef = _el$;
6911
6873
  spread(_el$, mergeProps({
6912
6874
  get ["class"]() {
6913
- return props.classNameProp;
6875
+ return `variant-${props.content?.testVariationId || props.content?.id}`;
6914
6876
  }
6915
6877
  }, {}, {
6916
6878
  get key() {
@@ -7063,7 +7025,7 @@ var getContentInitialValue = ({
7063
7025
 
7064
7026
  // src/components/content/content.tsx
7065
7027
  function ContentComponent(props) {
7066
- const [scriptStr, setScriptStr] = createSignal(getRenderContentScriptString({
7028
+ const [scriptStr, setScriptStr] = createSignal(getUpdateVariantVisibilityScript({
7067
7029
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
7068
7030
  variationId: props.content?.testVariationId,
7069
7031
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
@@ -7159,9 +7121,6 @@ function ContentComponent(props) {
7159
7121
  get enrich() {
7160
7122
  return props.enrich;
7161
7123
  },
7162
- get classNameProp() {
7163
- return props.classNameProp;
7164
- },
7165
7124
  get showContent() {
7166
7125
  return props.showContent;
7167
7126
  },
@@ -7218,12 +7177,12 @@ var content_default = ContentComponent;
7218
7177
 
7219
7178
  // src/components/content-variants/content-variants.tsx
7220
7179
  function ContentVariants(props) {
7221
- const [shouldRenderVariants, setShouldRenderVariants] = createSignal(checkShouldRunVariants({
7180
+ const [shouldRenderVariants, setShouldRenderVariants] = createSignal(checkShouldRenderVariants({
7222
7181
  canTrack: getDefaultCanTrack(props.canTrack),
7223
7182
  content: props.content
7224
7183
  }));
7225
- function variantScriptStr() {
7226
- return getVariantsScriptString(getVariants(props.content).map((value) => ({
7184
+ function updateCookieAndStylesScriptStr() {
7185
+ return getUpdateCookieAndStylesScript(getVariants(props.content).map((value) => ({
7227
7186
  id: value.testVariationId,
7228
7187
  testRatio: value.testRatio
7229
7188
  })), props.content?.id || "");
@@ -7268,7 +7227,7 @@ function ContentVariants(props) {
7268
7227
  }
7269
7228
  }), createComponent(inlined_script_default, {
7270
7229
  get scriptStr() {
7271
- return variantScriptStr();
7230
+ return updateCookieAndStylesScriptStr();
7272
7231
  }
7273
7232
  }), createComponent(For, {
7274
7233
  get each() {
@@ -7282,7 +7241,6 @@ function ContentVariants(props) {
7282
7241
  },
7283
7242
  content: variant,
7284
7243
  showContent: false,
7285
- classNameProp: void 0,
7286
7244
  get model() {
7287
7245
  return props.model;
7288
7246
  },
@@ -7324,9 +7282,6 @@ function ContentVariants(props) {
7324
7282
  get content() {
7325
7283
  return defaultContent();
7326
7284
  },
7327
- get classNameProp() {
7328
- return `variant-${props.content?.id}`;
7329
- },
7330
7285
  showContent: true,
7331
7286
  get model() {
7332
7287
  return props.model;