@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/dev.js CHANGED
@@ -5794,7 +5794,9 @@ var componentInfo11 = {
5794
5794
  advanced: true
5795
5795
  }]
5796
5796
  };
5797
- var _tmpl$13 = /* @__PURE__ */ template(`<video>`);
5797
+ var _tmpl$13 = /* @__PURE__ */ template(`<source type=video/mp4>`);
5798
+ var _tmpl$23 = /* @__PURE__ */ template(`<div>`);
5799
+ var _tmpl$33 = /* @__PURE__ */ template(`<div><video class=builder-video>`);
5798
5800
  function Video(props) {
5799
5801
  function videoProps() {
5800
5802
  return {
@@ -5817,13 +5819,13 @@ function Video(props) {
5817
5819
  }
5818
5820
  function spreadProps() {
5819
5821
  return {
5820
- ...props.attributes,
5821
5822
  ...videoProps()
5822
5823
  };
5823
5824
  }
5824
5825
  return (() => {
5825
- const _el$ = _tmpl$13();
5826
- spread(_el$, mergeProps(spreadProps, {
5826
+ const _el$ = _tmpl$33(), _el$2 = _el$.firstChild;
5827
+ _el$.style.setProperty("position", "relative");
5828
+ spread(_el$2, mergeProps(spreadProps, {
5827
5829
  get preload() {
5828
5830
  return props.preload || "metadata";
5829
5831
  },
@@ -5836,7 +5838,11 @@ function Video(props) {
5836
5838
  "object-position": props.position,
5837
5839
  // Hack to get object fit to work as expected and
5838
5840
  // not have the video overflow
5839
- "border-radius": 1
5841
+ "z-index": 2,
5842
+ "border-radius": "1px",
5843
+ ...props.aspectRatio ? {
5844
+ position: "absolute"
5845
+ } : null
5840
5846
  };
5841
5847
  },
5842
5848
  get src() {
@@ -5845,7 +5851,62 @@ function Video(props) {
5845
5851
  get poster() {
5846
5852
  return props.posterImage;
5847
5853
  }
5848
- }), false, false);
5854
+ }), false, true);
5855
+ insert(_el$2, createComponent(Show, {
5856
+ get when() {
5857
+ return !props.lazyLoad;
5858
+ },
5859
+ get children() {
5860
+ const _el$3 = _tmpl$13();
5861
+ effect(() => setAttribute(_el$3, "src", props.video));
5862
+ return _el$3;
5863
+ }
5864
+ }));
5865
+ insert(_el$, createComponent(Show, {
5866
+ get when() {
5867
+ return props.aspectRatio && !(props.fitContent && props.builderBlock?.children?.length);
5868
+ },
5869
+ get children() {
5870
+ const _el$4 = _tmpl$23();
5871
+ _el$4.style.setProperty("width", "100%");
5872
+ _el$4.style.setProperty("pointer-events", "none");
5873
+ _el$4.style.setProperty("font-size", "0px");
5874
+ effect(() => props.aspectRatio * 100 + "%" != null ? _el$4.style.setProperty("padding-top", props.aspectRatio * 100 + "%") : _el$4.style.removeProperty("padding-top"));
5875
+ return _el$4;
5876
+ }
5877
+ }), null);
5878
+ insert(_el$, createComponent(Show, {
5879
+ get when() {
5880
+ return props.builderBlock?.children?.length && props.fitContent;
5881
+ },
5882
+ get children() {
5883
+ const _el$5 = _tmpl$23();
5884
+ _el$5.style.setProperty("display", "flex");
5885
+ _el$5.style.setProperty("flex-direction", "column");
5886
+ _el$5.style.setProperty("align-items", "stretch");
5887
+ insert(_el$5, () => props.children);
5888
+ return _el$5;
5889
+ }
5890
+ }), null);
5891
+ insert(_el$, createComponent(Show, {
5892
+ get when() {
5893
+ return props.builderBlock?.children?.length && !props.fitContent;
5894
+ },
5895
+ get children() {
5896
+ const _el$6 = _tmpl$23();
5897
+ _el$6.style.setProperty("pointer-events", "none");
5898
+ _el$6.style.setProperty("display", "flex");
5899
+ _el$6.style.setProperty("flex-direction", "column");
5900
+ _el$6.style.setProperty("align-items", "stretch");
5901
+ _el$6.style.setProperty("position", "absolute");
5902
+ _el$6.style.setProperty("top", "0");
5903
+ _el$6.style.setProperty("left", "0");
5904
+ _el$6.style.setProperty("width", "100%");
5905
+ _el$6.style.setProperty("height", "100%");
5906
+ insert(_el$6, () => props.children);
5907
+ return _el$6;
5908
+ }
5909
+ }), null);
5849
5910
  return _el$;
5850
5911
  })();
5851
5912
  }
@@ -5910,13 +5971,19 @@ var serializeComponentInfo = ({
5910
5971
  }), {}))
5911
5972
  });
5912
5973
 
5974
+ // src/components/content-variants/inlined-fns.ts
5975
+ 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}";
5976
+ 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}";
5977
+
5913
5978
  // src/components/content-variants/helpers.ts
5979
+ var UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME = "builderIoAbTest";
5980
+ var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME = "builderIoRenderContent";
5914
5981
  var getVariants = (content) => Object.values(content?.variations || {}).map((variant) => ({
5915
5982
  ...variant,
5916
5983
  testVariationId: variant.id,
5917
5984
  id: content?.id
5918
5985
  }));
5919
- var checkShouldRunVariants = ({
5986
+ var checkShouldRenderVariants = ({
5920
5987
  canTrack,
5921
5988
  content
5922
5989
  }) => {
@@ -5927,139 +5994,34 @@ var checkShouldRunVariants = ({
5927
5994
  return false;
5928
5995
  if (!canTrack)
5929
5996
  return false;
5930
- if (TARGET === "vue2" || TARGET === "vue3")
5997
+ if (TARGET === "vue2" || TARGET === "vue3" || TARGET === "svelte")
5931
5998
  return true;
5932
5999
  if (isBrowser())
5933
6000
  return false;
5934
6001
  return true;
5935
6002
  };
5936
- function bldrAbTest(contentId, variants, isHydrationTarget2) {
5937
- function getAndSetVariantId2() {
5938
- function setCookie2(name, value, days) {
5939
- let expires = "";
5940
- if (days) {
5941
- const date = /* @__PURE__ */ new Date();
5942
- date.setTime(date.getTime() + days * 24 * 60 * 60 * 1e3);
5943
- expires = "; expires=" + date.toUTCString();
5944
- }
5945
- document.cookie = name + "=" + (value || "") + expires + "; path=/; Secure; SameSite=None";
5946
- }
5947
- function getCookie2(name) {
5948
- const nameEQ = name + "=";
5949
- const ca2 = document.cookie.split(";");
5950
- for (let i = 0; i < ca2.length; i++) {
5951
- let c = ca2[i];
5952
- while (c.charAt(0) === " ")
5953
- c = c.substring(1, c.length);
5954
- if (c.indexOf(nameEQ) === 0)
5955
- return c.substring(nameEQ.length, c.length);
5956
- }
5957
- return null;
5958
- }
5959
- const cookieName = `builder.tests.${contentId}`;
5960
- const variantInCookie = getCookie2(cookieName);
5961
- const availableIDs = variants.map((vr) => vr.id).concat(contentId);
5962
- if (variantInCookie && availableIDs.includes(variantInCookie)) {
5963
- return variantInCookie;
5964
- }
5965
- let n = 0;
5966
- const random = Math.random();
5967
- for (let i = 0; i < variants.length; i++) {
5968
- const variant = variants[i];
5969
- const testRatio = variant.testRatio;
5970
- n += testRatio;
5971
- if (random < n) {
5972
- setCookie2(cookieName, variant.id);
5973
- return variant.id;
5974
- }
5975
- }
5976
- setCookie2(cookieName, contentId);
5977
- return contentId;
5978
- }
5979
- const winningVariantId = getAndSetVariantId2();
5980
- const styleEl = document.currentScript?.previousElementSibling;
5981
- if (isHydrationTarget2) {
5982
- styleEl.remove();
5983
- const thisScriptEl = document.currentScript;
5984
- thisScriptEl?.remove();
5985
- } else {
5986
- const newStyleStr = variants.concat({
5987
- id: contentId
5988
- }).filter((variant) => variant.id !== winningVariantId).map((value) => {
5989
- return `.variant-${value.id} { display: none; }
5990
- `;
5991
- }).join("");
5992
- styleEl.innerHTML = newStyleStr;
5993
- }
5994
- }
5995
- function bldrCntntScrpt(variantContentId, defaultContentId, isHydrationTarget2) {
5996
- if (!navigator.cookieEnabled) {
5997
- return;
5998
- }
5999
- function getCookie2(name) {
6000
- const nameEQ = name + "=";
6001
- const ca2 = document.cookie.split(";");
6002
- for (let i = 0; i < ca2.length; i++) {
6003
- let c = ca2[i];
6004
- while (c.charAt(0) === " ")
6005
- c = c.substring(1, c.length);
6006
- if (c.indexOf(nameEQ) === 0)
6007
- return c.substring(nameEQ.length, c.length);
6008
- }
6009
- return null;
6010
- }
6011
- const cookieName = `builder.tests.${defaultContentId}`;
6012
- const variantId = getCookie2(cookieName);
6013
- const parentDiv = document.currentScript?.parentElement;
6014
- const variantIsDefaultContent = variantContentId === defaultContentId;
6015
- if (variantId === variantContentId) {
6016
- if (variantIsDefaultContent) {
6017
- return;
6018
- }
6019
- parentDiv?.removeAttribute("hidden");
6020
- parentDiv?.removeAttribute("aria-hidden");
6021
- } else {
6022
- if (variantIsDefaultContent) {
6023
- if (isHydrationTarget2) {
6024
- parentDiv?.remove();
6025
- } else {
6026
- parentDiv?.setAttribute("hidden", "true");
6027
- parentDiv?.setAttribute("aria-hidden", "true");
6028
- }
6029
- }
6030
- return;
6031
- }
6032
- return;
6033
- }
6034
6003
  var getIsHydrationTarget = (target) => target === "react" || target === "reactNative";
6035
6004
  var isHydrationTarget = getIsHydrationTarget(TARGET);
6036
- var AB_TEST_FN_NAME = "builderIoAbTest";
6037
- var CONTENT_FN_NAME = "builderIoRenderContent";
6038
- var getScriptString = () => {
6039
- const fnStr = bldrAbTest.toString().replace(/\s+/g, " ");
6040
- const fnStr2 = bldrCntntScrpt.toString().replace(/\s+/g, " ");
6041
- return `
6042
- window.${AB_TEST_FN_NAME} = ${fnStr}
6043
- window.${CONTENT_FN_NAME} = ${fnStr2}
6005
+ var getScriptString = () => `
6006
+ window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
6007
+ window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
6044
6008
  `;
6045
- };
6046
- var getVariantsScriptString = (variants, contentId) => {
6047
- return `
6048
- window.${AB_TEST_FN_NAME}("${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget})`;
6049
- };
6050
- var getRenderContentScriptString = ({
6009
+ var getUpdateCookieAndStylesScript = (variants, contentId) => `
6010
+ window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME}(
6011
+ "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget}
6012
+ )`;
6013
+ var getUpdateVariantVisibilityScript = ({
6051
6014
  contentId,
6052
6015
  variationId
6053
- }) => {
6054
- return `
6055
- window.${CONTENT_FN_NAME}("${variationId}", "${contentId}", ${isHydrationTarget})`;
6056
- };
6016
+ }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME}(
6017
+ "${variationId}", "${contentId}", ${isHydrationTarget}
6018
+ )`;
6057
6019
  var _tmpl$14 = /* @__PURE__ */ template(`<script>`);
6058
6020
  function InlinedScript(props) {
6059
6021
  return (() => {
6060
6022
  const _el$ = _tmpl$14();
6061
6023
  effect((_p$) => {
6062
- const _v$ = props.scriptStr, _v$2 = props.id;
6024
+ const _v$ = props.scriptStr, _v$2 = props.id || "";
6063
6025
  _v$ !== _p$._v$ && (_el$.innerHTML = _p$._v$ = _v$);
6064
6026
  _v$2 !== _p$._v$2 && setAttribute(_el$, "id", _p$._v$2 = _v$2);
6065
6027
  return _p$;
@@ -6557,7 +6519,7 @@ var getInteractionPropertiesForEvent = (event) => {
6557
6519
  };
6558
6520
 
6559
6521
  // src/constants/sdk-version.ts
6560
- var SDK_VERSION = "0.7.2";
6522
+ var SDK_VERSION = "0.7.4";
6561
6523
 
6562
6524
  // src/functions/register.ts
6563
6525
  var registry = {};
@@ -6933,7 +6895,7 @@ function EnableEditor(props) {
6933
6895
  typeof _ref$ === "function" ? use(_ref$, _el$) : elementRef = _el$;
6934
6896
  spread(_el$, mergeProps({
6935
6897
  get ["class"]() {
6936
- return props.classNameProp;
6898
+ return `variant-${props.content?.testVariationId || props.content?.id}`;
6937
6899
  }
6938
6900
  }, {}, {
6939
6901
  get key() {
@@ -7086,7 +7048,7 @@ var getContentInitialValue = ({
7086
7048
 
7087
7049
  // src/components/content/content.tsx
7088
7050
  function ContentComponent(props) {
7089
- const [scriptStr, setScriptStr] = createSignal(getRenderContentScriptString({
7051
+ const [scriptStr, setScriptStr] = createSignal(getUpdateVariantVisibilityScript({
7090
7052
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
7091
7053
  variationId: props.content?.testVariationId,
7092
7054
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
@@ -7182,9 +7144,6 @@ function ContentComponent(props) {
7182
7144
  get enrich() {
7183
7145
  return props.enrich;
7184
7146
  },
7185
- get classNameProp() {
7186
- return props.classNameProp;
7187
- },
7188
7147
  get showContent() {
7189
7148
  return props.showContent;
7190
7149
  },
@@ -7241,12 +7200,12 @@ var content_default = ContentComponent;
7241
7200
 
7242
7201
  // src/components/content-variants/content-variants.tsx
7243
7202
  function ContentVariants(props) {
7244
- const [shouldRenderVariants, setShouldRenderVariants] = createSignal(checkShouldRunVariants({
7203
+ const [shouldRenderVariants, setShouldRenderVariants] = createSignal(checkShouldRenderVariants({
7245
7204
  canTrack: getDefaultCanTrack(props.canTrack),
7246
7205
  content: props.content
7247
7206
  }));
7248
- function variantScriptStr() {
7249
- return getVariantsScriptString(getVariants(props.content).map((value) => ({
7207
+ function updateCookieAndStylesScriptStr() {
7208
+ return getUpdateCookieAndStylesScript(getVariants(props.content).map((value) => ({
7250
7209
  id: value.testVariationId,
7251
7210
  testRatio: value.testRatio
7252
7211
  })), props.content?.id || "");
@@ -7291,7 +7250,7 @@ function ContentVariants(props) {
7291
7250
  }
7292
7251
  }), createComponent(inlined_script_default, {
7293
7252
  get scriptStr() {
7294
- return variantScriptStr();
7253
+ return updateCookieAndStylesScriptStr();
7295
7254
  }
7296
7255
  }), createComponent(For, {
7297
7256
  get each() {
@@ -7305,7 +7264,6 @@ function ContentVariants(props) {
7305
7264
  },
7306
7265
  content: variant,
7307
7266
  showContent: false,
7308
- classNameProp: void 0,
7309
7267
  get model() {
7310
7268
  return props.model;
7311
7269
  },
@@ -7347,9 +7305,6 @@ function ContentVariants(props) {
7347
7305
  get content() {
7348
7306
  return defaultContent();
7349
7307
  },
7350
- get classNameProp() {
7351
- return `variant-${props.content?.id}`;
7352
- },
7353
7308
  showContent: true,
7354
7309
  get model() {
7355
7310
  return props.model;