@builder.io/sdk-qwik 0.18.12 → 0.18.14

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.
Files changed (69) hide show
  1. package/lib/browser/blocks/personalization-container/component-info.qwik.cjs +48 -0
  2. package/lib/browser/blocks/personalization-container/component-info.qwik.mjs +48 -0
  3. package/lib/browser/blocks/personalization-container/helpers/inlined-fns.qwik.cjs +82 -0
  4. package/lib/browser/blocks/personalization-container/helpers/inlined-fns.qwik.mjs +82 -0
  5. package/lib/browser/blocks/personalization-container/helpers.qwik.cjs +88 -0
  6. package/lib/browser/blocks/personalization-container/helpers.qwik.mjs +89 -0
  7. package/lib/browser/blocks/personalization-container/personalization-container.qwik.cjs +386 -0
  8. package/lib/browser/blocks/personalization-container/personalization-container.qwik.mjs +386 -0
  9. package/lib/browser/components/blocks/blocks.qwik.cjs +37 -34
  10. package/lib/browser/components/blocks/blocks.qwik.mjs +38 -35
  11. package/lib/browser/components/content-variants/content-variants.qwik.cjs +42 -21
  12. package/lib/browser/components/content-variants/content-variants.qwik.mjs +42 -21
  13. package/lib/browser/constants/builder-registered-components.qwik.cjs +14 -10
  14. package/lib/browser/constants/builder-registered-components.qwik.mjs +14 -10
  15. package/lib/browser/constants/sdk-version.qwik.cjs +1 -1
  16. package/lib/browser/constants/sdk-version.qwik.mjs +1 -1
  17. package/lib/browser/helpers/no-serialize-wrapper.qwik.cjs +7 -0
  18. package/lib/browser/helpers/no-serialize-wrapper.qwik.mjs +7 -0
  19. package/lib/browser/helpers/user-attributes.qwik.cjs +15 -4
  20. package/lib/browser/helpers/user-attributes.qwik.mjs +15 -4
  21. package/lib/edge/blocks/personalization-container/component-info.qwik.cjs +48 -0
  22. package/lib/edge/blocks/personalization-container/component-info.qwik.mjs +48 -0
  23. package/lib/edge/blocks/personalization-container/helpers/inlined-fns.qwik.cjs +82 -0
  24. package/lib/edge/blocks/personalization-container/helpers/inlined-fns.qwik.mjs +82 -0
  25. package/lib/edge/blocks/personalization-container/helpers.qwik.cjs +88 -0
  26. package/lib/edge/blocks/personalization-container/helpers.qwik.mjs +89 -0
  27. package/lib/edge/blocks/personalization-container/personalization-container.qwik.cjs +386 -0
  28. package/lib/edge/blocks/personalization-container/personalization-container.qwik.mjs +386 -0
  29. package/lib/edge/components/blocks/blocks.qwik.cjs +37 -34
  30. package/lib/edge/components/blocks/blocks.qwik.mjs +38 -35
  31. package/lib/edge/components/content-variants/content-variants.qwik.cjs +42 -21
  32. package/lib/edge/components/content-variants/content-variants.qwik.mjs +42 -21
  33. package/lib/edge/constants/builder-registered-components.qwik.cjs +14 -11
  34. package/lib/edge/constants/builder-registered-components.qwik.mjs +14 -11
  35. package/lib/edge/constants/sdk-version.qwik.cjs +1 -1
  36. package/lib/edge/constants/sdk-version.qwik.mjs +1 -1
  37. package/lib/edge/helpers/no-serialize-wrapper.qwik.cjs +7 -0
  38. package/lib/edge/helpers/no-serialize-wrapper.qwik.mjs +7 -0
  39. package/lib/edge/helpers/user-attributes.qwik.cjs +15 -4
  40. package/lib/edge/helpers/user-attributes.qwik.mjs +15 -4
  41. package/lib/node/blocks/personalization-container/component-info.qwik.cjs +48 -0
  42. package/lib/node/blocks/personalization-container/component-info.qwik.mjs +48 -0
  43. package/lib/node/blocks/personalization-container/helpers/inlined-fns.qwik.cjs +82 -0
  44. package/lib/node/blocks/personalization-container/helpers/inlined-fns.qwik.mjs +82 -0
  45. package/lib/node/blocks/personalization-container/helpers.qwik.cjs +88 -0
  46. package/lib/node/blocks/personalization-container/helpers.qwik.mjs +89 -0
  47. package/lib/node/blocks/personalization-container/personalization-container.qwik.cjs +386 -0
  48. package/lib/node/blocks/personalization-container/personalization-container.qwik.mjs +386 -0
  49. package/lib/node/components/blocks/blocks.qwik.cjs +37 -34
  50. package/lib/node/components/blocks/blocks.qwik.mjs +38 -35
  51. package/lib/node/components/content-variants/content-variants.qwik.cjs +42 -21
  52. package/lib/node/components/content-variants/content-variants.qwik.mjs +42 -21
  53. package/lib/node/constants/builder-registered-components.qwik.cjs +14 -11
  54. package/lib/node/constants/builder-registered-components.qwik.mjs +14 -11
  55. package/lib/node/constants/sdk-version.qwik.cjs +1 -1
  56. package/lib/node/constants/sdk-version.qwik.mjs +1 -1
  57. package/lib/node/helpers/no-serialize-wrapper.qwik.cjs +7 -0
  58. package/lib/node/helpers/no-serialize-wrapper.qwik.mjs +7 -0
  59. package/lib/node/helpers/user-attributes.qwik.cjs +15 -4
  60. package/lib/node/helpers/user-attributes.qwik.mjs +15 -4
  61. package/package.json +2 -2
  62. package/types/src/blocks/personalization-container/helpers/inlined-fns.d.ts +4 -1
  63. package/types/src/blocks/personalization-container/helpers.d.ts +24 -4
  64. package/types/src/blocks/personalization-container/personalization-container.types.d.ts +2 -2
  65. package/types/src/components/blocks/blocks-wrapper.d.ts +13 -1
  66. package/types/src/components/blocks/blocks.types.d.ts +1 -1
  67. package/types/src/constants/sdk-version.d.ts +1 -1
  68. package/types/src/helpers/no-serialize-wrapper.d.ts +1 -0
  69. package/types/src/helpers/user-attributes.d.ts +6 -2
@@ -0,0 +1,82 @@
1
+ function filterWithCustomTargeting(userAttributes, query, startDate, endDate) {
2
+ function isString(val) {
3
+ return typeof val === "string";
4
+ }
5
+ function isNumber(val) {
6
+ return typeof val === "number";
7
+ }
8
+ function objectMatchesQuery(userattr, query2) {
9
+ const result = (() => {
10
+ const property = query2.property;
11
+ const operator = query2.operator;
12
+ let testValue = query2.value;
13
+ if (query2 && query2.property === "urlPath" && query2.value && typeof query2.value === "string" && query2.value !== "/" && query2.value.endsWith("/"))
14
+ testValue = query2.value.slice(0, -1);
15
+ if (!(property && operator))
16
+ return true;
17
+ if (Array.isArray(testValue)) {
18
+ if (operator === "isNot")
19
+ return testValue.every((val) => objectMatchesQuery(userattr, {
20
+ property,
21
+ operator,
22
+ value: val
23
+ }));
24
+ return !!testValue.find((val) => objectMatchesQuery(userattr, {
25
+ property,
26
+ operator,
27
+ value: val
28
+ }));
29
+ }
30
+ const value = userattr[property];
31
+ if (Array.isArray(value))
32
+ return value.includes(testValue);
33
+ switch (operator) {
34
+ case "is":
35
+ return value === testValue;
36
+ case "isNot":
37
+ return value !== testValue;
38
+ case "contains":
39
+ return (isString(value) || Array.isArray(value)) && value.includes(String(testValue));
40
+ case "startsWith":
41
+ return isString(value) && value.startsWith(String(testValue));
42
+ case "endsWith":
43
+ return isString(value) && value.endsWith(String(testValue));
44
+ case "greaterThan":
45
+ return isNumber(value) && isNumber(testValue) && value > testValue;
46
+ case "lessThan":
47
+ return isNumber(value) && isNumber(testValue) && value < testValue;
48
+ case "greaterThanOrEqualTo":
49
+ return isNumber(value) && isNumber(testValue) && value >= testValue;
50
+ case "lessThanOrEqualTo":
51
+ return isNumber(value) && isNumber(testValue) && value <= testValue;
52
+ default:
53
+ return false;
54
+ }
55
+ })();
56
+ return result;
57
+ }
58
+ const item = {
59
+ query,
60
+ startDate,
61
+ endDate
62
+ };
63
+ const now = userAttributes.date && new Date(userAttributes.date) || /* @__PURE__ */ new Date();
64
+ if (item.startDate && new Date(item.startDate) > now)
65
+ return false;
66
+ else if (item.endDate && new Date(item.endDate) < now)
67
+ return false;
68
+ if (!item.query || !item.query.length)
69
+ return true;
70
+ return item.query.every((filter) => {
71
+ return objectMatchesQuery(userAttributes, filter);
72
+ });
73
+ }
74
+ const PERSONALIZATION_SCRIPT = "function getPersonalizedVariant(variants, blockId, isHydrationTarget, locale) {\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 attributes = JSON.parse(getCookie('builder.userAttributes') || '{}');\n if (locale) {\n attributes.locale = locale;\n }\n const winningVariantIndex = variants?.findIndex(function (variant) {\n return window.filterWithCustomTargeting(attributes, variant.query, variant.startDate, variant.endDate);\n });\n const parentDiv = document.currentScript?.parentElement;\n const variantId = parentDiv?.getAttribute('data-variant-id');\n const isDefaultVariant = variantId === `${blockId}-default`;\n const isWinningVariant = winningVariantIndex !== -1 && variantId === `${blockId}-${winningVariantIndex}` || winningVariantIndex === -1 && isDefaultVariant;\n if (isWinningVariant && !isDefaultVariant) {\n parentDiv?.removeAttribute('hidden');\n parentDiv?.removeAttribute('aria-hidden');\n } else if (!isWinningVariant && isDefaultVariant) {\n parentDiv?.setAttribute('hidden', 'true');\n parentDiv?.setAttribute('aria-hidden', 'true');\n }\n if (isHydrationTarget) {\n if (!isWinningVariant) {\n const itsStyleEl = parentDiv?.previousElementSibling;\n if (itsStyleEl) {\n itsStyleEl.remove();\n }\n parentDiv?.remove();\n }\n const thisScript = document.currentScript;\n if (thisScript) {\n thisScript.remove();\n }\n }\n}";
75
+ const FILTER_WITH_CUSTOM_TARGETING_SCRIPT = "function filterWithCustomTargeting(userAttributes, query, startDate, endDate) {\n function isString(val) {\n return typeof val === 'string';\n }\n function isNumber(val) {\n return typeof val === 'number';\n }\n function objectMatchesQuery(userattr, query) {\n const result = (() => {\n const property = query.property;\n const operator = query.operator;\n let testValue = query.value;\n if (query && query.property === 'urlPath' && query.value && typeof query.value === 'string' && query.value !== '/' && query.value.endsWith('/')) {\n testValue = query.value.slice(0, -1);\n }\n if (!(property && operator)) {\n return true;\n }\n if (Array.isArray(testValue)) {\n if (operator === 'isNot') {\n return testValue.every(val => objectMatchesQuery(userattr, {\n property,\n operator,\n value: val\n }));\n }\n return !!testValue.find(val => objectMatchesQuery(userattr, {\n property,\n operator,\n value: val\n }));\n }\n const value = userattr[property];\n if (Array.isArray(value)) {\n return value.includes(testValue);\n }\n switch (operator) {\n case 'is':\n return value === testValue;\n case 'isNot':\n return value !== testValue;\n case 'contains':\n return (isString(value) || Array.isArray(value)) && value.includes(String(testValue));\n case 'startsWith':\n return isString(value) && value.startsWith(String(testValue));\n case 'endsWith':\n return isString(value) && value.endsWith(String(testValue));\n case 'greaterThan':\n return isNumber(value) && isNumber(testValue) && value > testValue;\n case 'lessThan':\n return isNumber(value) && isNumber(testValue) && value < testValue;\n case 'greaterThanOrEqualTo':\n return isNumber(value) && isNumber(testValue) && value >= testValue;\n case 'lessThanOrEqualTo':\n return isNumber(value) && isNumber(testValue) && value <= testValue;\n default:\n return false;\n }\n })();\n return result;\n }\n const item = {\n query,\n startDate,\n endDate\n };\n const now = userAttributes.date && new Date(userAttributes.date) || new Date();\n if (item.startDate && new Date(item.startDate) > now) {\n return false;\n } else if (item.endDate && new Date(item.endDate) < now) {\n return false;\n }\n if (!item.query || !item.query.length) {\n return true;\n }\n return item.query.every(filter => {\n return objectMatchesQuery(userAttributes, filter);\n });\n}";
76
+ const UPDATE_VISIBILITY_STYLES_SCRIPT = "function updateVisibilityStylesScript(variants, blockId, isHydrationTarget, locale) {\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 visibilityStylesEl = document.currentScript?.previousElementSibling;\n if (!visibilityStylesEl) {\n return;\n }\n if (isHydrationTarget) {\n visibilityStylesEl.remove();\n const currentScript = document.currentScript;\n if (currentScript) {\n currentScript.remove();\n }\n } else {\n const attributes = JSON.parse(getCookie('builder.userAttributes') || '{}');\n if (locale) {\n attributes.locale = locale;\n }\n const winningVariantIndex = variants?.findIndex(function (variant) {\n return window.filterWithCustomTargeting(attributes, variant.query, variant.startDate, variant.endDate);\n });\n if (winningVariantIndex !== -1) {\n let newStyleStr = variants?.map((_, index) => {\n if (index === winningVariantIndex) return '';\n return `div[data-variant-id=\"${blockId}-${index}\"] { display: none !important; } `;\n }).join('') || '';\n newStyleStr += `div[data-variant-id=\"${blockId}-default\"] { display: none !important; } `;\n visibilityStylesEl.innerHTML = newStyleStr;\n }\n }\n}";
77
+ export {
78
+ FILTER_WITH_CUSTOM_TARGETING_SCRIPT,
79
+ PERSONALIZATION_SCRIPT,
80
+ UPDATE_VISIBILITY_STYLES_SCRIPT,
81
+ filterWithCustomTargeting
82
+ };
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const target = require("../../constants/target.qwik.cjs");
4
+ const isBrowser = require("../../functions/is-browser.qwik.cjs");
5
+ const isEditing = require("../../functions/is-editing.qwik.cjs");
6
+ const inlinedFns = require("./helpers/inlined-fns.qwik.cjs");
7
+ const DEFAULT_INDEX = "default";
8
+ const FILTER_WITH_CUSTOM_TARGETING_SCRIPT_FN_NAME = "filterWithCustomTargeting";
9
+ const BUILDER_IO_PERSONALIZATION_SCRIPT_FN_NAME = "builderIoPersonalization";
10
+ const UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME = "updateVisibilityStylesScript";
11
+ const SDKS_SUPPORTING_PERSONALIZATION = [
12
+ "react",
13
+ "vue",
14
+ "svelte",
15
+ "qwik"
16
+ ];
17
+ const SDKS_REQUIRING_RESET_APPROACH = [
18
+ "vue",
19
+ "svelte",
20
+ "qwik"
21
+ ];
22
+ function checkShouldRenderVariants(variants, canTrack) {
23
+ const hasVariants = variants && variants.length > 0;
24
+ if (!hasVariants)
25
+ return false;
26
+ if (!canTrack)
27
+ return false;
28
+ if (SDKS_REQUIRING_RESET_APPROACH.includes(target.TARGET))
29
+ return true;
30
+ if (isBrowser.isBrowser())
31
+ return false;
32
+ return true;
33
+ }
34
+ function getBlocksToRender({ variants, previewingIndex, isHydrated, filteredVariants, fallbackBlocks }) {
35
+ const fallback = {
36
+ blocks: fallbackBlocks ?? [],
37
+ path: "this.children",
38
+ index: DEFAULT_INDEX
39
+ };
40
+ if (isHydrated && isEditing.isEditing()) {
41
+ if (typeof previewingIndex === "number" && previewingIndex < ((variants == null ? void 0 : variants.length) ?? 0)) {
42
+ const variant = variants == null ? void 0 : variants[previewingIndex];
43
+ if (variant)
44
+ return {
45
+ blocks: variant.blocks,
46
+ path: `variants.${previewingIndex}.blocks`,
47
+ index: previewingIndex
48
+ };
49
+ }
50
+ return fallback;
51
+ }
52
+ if (isBrowser.isBrowser()) {
53
+ const winningVariant = filteredVariants == null ? void 0 : filteredVariants[0];
54
+ if (winningVariant && variants) {
55
+ const variantIndex = variants.indexOf(winningVariant);
56
+ if (variantIndex !== -1)
57
+ return {
58
+ blocks: winningVariant.blocks,
59
+ path: `variants.${variantIndex}.blocks`,
60
+ index: variantIndex
61
+ };
62
+ }
63
+ }
64
+ return fallback;
65
+ }
66
+ const getInitPersonalizationVariantsFnsScriptString = () => {
67
+ return `
68
+ window.${FILTER_WITH_CUSTOM_TARGETING_SCRIPT_FN_NAME} = ${inlinedFns.FILTER_WITH_CUSTOM_TARGETING_SCRIPT}
69
+ window.${BUILDER_IO_PERSONALIZATION_SCRIPT_FN_NAME} = ${inlinedFns.PERSONALIZATION_SCRIPT}
70
+ window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${inlinedFns.UPDATE_VISIBILITY_STYLES_SCRIPT}
71
+ `;
72
+ };
73
+ const isHydrationTarget = target.TARGET === "react";
74
+ const getPersonalizationScript = (variants, blockId, locale) => {
75
+ return `window.${BUILDER_IO_PERSONALIZATION_SCRIPT_FN_NAME}(${JSON.stringify(variants)}, "${blockId}", ${isHydrationTarget}${locale ? `, "${locale}"` : ""})`;
76
+ };
77
+ const getUpdateVisibilityStylesScript = (variants, blockId, locale) => {
78
+ return `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME}(${JSON.stringify(variants)}, "${blockId}", ${isHydrationTarget}${locale ? `, "${locale}"` : ""})`;
79
+ };
80
+ exports.filterWithCustomTargeting = inlinedFns.filterWithCustomTargeting;
81
+ exports.DEFAULT_INDEX = DEFAULT_INDEX;
82
+ exports.SDKS_REQUIRING_RESET_APPROACH = SDKS_REQUIRING_RESET_APPROACH;
83
+ exports.SDKS_SUPPORTING_PERSONALIZATION = SDKS_SUPPORTING_PERSONALIZATION;
84
+ exports.checkShouldRenderVariants = checkShouldRenderVariants;
85
+ exports.getBlocksToRender = getBlocksToRender;
86
+ exports.getInitPersonalizationVariantsFnsScriptString = getInitPersonalizationVariantsFnsScriptString;
87
+ exports.getPersonalizationScript = getPersonalizationScript;
88
+ exports.getUpdateVisibilityStylesScript = getUpdateVisibilityStylesScript;
@@ -0,0 +1,89 @@
1
+ import { TARGET } from "../../constants/target.qwik.mjs";
2
+ import { isBrowser } from "../../functions/is-browser.qwik.mjs";
3
+ import { isEditing } from "../../functions/is-editing.qwik.mjs";
4
+ import { FILTER_WITH_CUSTOM_TARGETING_SCRIPT, PERSONALIZATION_SCRIPT, UPDATE_VISIBILITY_STYLES_SCRIPT } from "./helpers/inlined-fns.qwik.mjs";
5
+ import { filterWithCustomTargeting } from "./helpers/inlined-fns.qwik.mjs";
6
+ const DEFAULT_INDEX = "default";
7
+ const FILTER_WITH_CUSTOM_TARGETING_SCRIPT_FN_NAME = "filterWithCustomTargeting";
8
+ const BUILDER_IO_PERSONALIZATION_SCRIPT_FN_NAME = "builderIoPersonalization";
9
+ const UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME = "updateVisibilityStylesScript";
10
+ const SDKS_SUPPORTING_PERSONALIZATION = [
11
+ "react",
12
+ "vue",
13
+ "svelte",
14
+ "qwik"
15
+ ];
16
+ const SDKS_REQUIRING_RESET_APPROACH = [
17
+ "vue",
18
+ "svelte",
19
+ "qwik"
20
+ ];
21
+ function checkShouldRenderVariants(variants, canTrack) {
22
+ const hasVariants = variants && variants.length > 0;
23
+ if (!hasVariants)
24
+ return false;
25
+ if (!canTrack)
26
+ return false;
27
+ if (SDKS_REQUIRING_RESET_APPROACH.includes(TARGET))
28
+ return true;
29
+ if (isBrowser())
30
+ return false;
31
+ return true;
32
+ }
33
+ function getBlocksToRender({ variants, previewingIndex, isHydrated, filteredVariants, fallbackBlocks }) {
34
+ const fallback = {
35
+ blocks: fallbackBlocks ?? [],
36
+ path: "this.children",
37
+ index: DEFAULT_INDEX
38
+ };
39
+ if (isHydrated && isEditing()) {
40
+ if (typeof previewingIndex === "number" && previewingIndex < ((variants == null ? void 0 : variants.length) ?? 0)) {
41
+ const variant = variants == null ? void 0 : variants[previewingIndex];
42
+ if (variant)
43
+ return {
44
+ blocks: variant.blocks,
45
+ path: `variants.${previewingIndex}.blocks`,
46
+ index: previewingIndex
47
+ };
48
+ }
49
+ return fallback;
50
+ }
51
+ if (isBrowser()) {
52
+ const winningVariant = filteredVariants == null ? void 0 : filteredVariants[0];
53
+ if (winningVariant && variants) {
54
+ const variantIndex = variants.indexOf(winningVariant);
55
+ if (variantIndex !== -1)
56
+ return {
57
+ blocks: winningVariant.blocks,
58
+ path: `variants.${variantIndex}.blocks`,
59
+ index: variantIndex
60
+ };
61
+ }
62
+ }
63
+ return fallback;
64
+ }
65
+ const getInitPersonalizationVariantsFnsScriptString = () => {
66
+ return `
67
+ window.${FILTER_WITH_CUSTOM_TARGETING_SCRIPT_FN_NAME} = ${FILTER_WITH_CUSTOM_TARGETING_SCRIPT}
68
+ window.${BUILDER_IO_PERSONALIZATION_SCRIPT_FN_NAME} = ${PERSONALIZATION_SCRIPT}
69
+ window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VISIBILITY_STYLES_SCRIPT}
70
+ `;
71
+ };
72
+ const isHydrationTarget = TARGET === "react";
73
+ const getPersonalizationScript = (variants, blockId, locale) => {
74
+ return `window.${BUILDER_IO_PERSONALIZATION_SCRIPT_FN_NAME}(${JSON.stringify(variants)}, "${blockId}", ${isHydrationTarget}${locale ? `, "${locale}"` : ""})`;
75
+ };
76
+ const getUpdateVisibilityStylesScript = (variants, blockId, locale) => {
77
+ return `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME}(${JSON.stringify(variants)}, "${blockId}", ${isHydrationTarget}${locale ? `, "${locale}"` : ""})`;
78
+ };
79
+ export {
80
+ DEFAULT_INDEX,
81
+ SDKS_REQUIRING_RESET_APPROACH,
82
+ SDKS_SUPPORTING_PERSONALIZATION,
83
+ checkShouldRenderVariants,
84
+ filterWithCustomTargeting,
85
+ getBlocksToRender,
86
+ getInitPersonalizationVariantsFnsScriptString,
87
+ getPersonalizationScript,
88
+ getUpdateVisibilityStylesScript
89
+ };
@@ -0,0 +1,386 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const qwik = require("@builder.io/qwik");
4
+ const jsxRuntime = require("@builder.io/qwik/jsx-runtime");
5
+ const blocks = require("../../components/blocks/blocks.qwik.cjs");
6
+ const inlinedScript = require("../../components/inlined-script.qwik.cjs");
7
+ const inlinedStyles = require("../../components/inlined-styles.qwik.cjs");
8
+ const target = require("../../constants/target.qwik.cjs");
9
+ const getClassPropName = require("../../functions/get-class-prop-name.qwik.cjs");
10
+ const isEditing = require("../../functions/is-editing.qwik.cjs");
11
+ const isPreviewing = require("../../functions/is-previewing.qwik.cjs");
12
+ const canTrack = require("../../helpers/canTrack.qwik.cjs");
13
+ const userAttributes = require("../../helpers/user-attributes.qwik.cjs");
14
+ const helpers = require("./helpers.qwik.cjs");
15
+ const inlinedFns = require("./helpers/inlined-fns.qwik.cjs");
16
+ const PersonalizationContainer = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlinedQrl((props) => {
17
+ var _a, _b, _c, _d, _e, _f, _g, _h;
18
+ qwik._jsxBranch();
19
+ const state = qwik.useStore({
20
+ scriptStr: helpers.getPersonalizationScript(props.variants, ((_a = props.builderBlock) == null ? void 0 : _a.id) || "none", (_c = (_b = props.builderContext) == null ? void 0 : _b.rootState) == null ? void 0 : _c.locale),
21
+ shouldRenderVariants: helpers.checkShouldRenderVariants(props.variants, canTrack.getDefaultCanTrack((_d = props.builderContext) == null ? void 0 : _d.canTrack)),
22
+ shouldResetVariants: false,
23
+ unsubscribers: [],
24
+ updateVisibilityStylesScript: helpers.getUpdateVisibilityStylesScript(props.variants, ((_e = props.builderBlock) == null ? void 0 : _e.id) || "none", (_g = (_f = props.builderContext) == null ? void 0 : _f.rootState) == null ? void 0 : _g.locale),
25
+ userAttributes: userAttributes.userAttributesService.getUserAttributes()
26
+ });
27
+ const attrs = qwik.useComputedQrl(/* @__PURE__ */ qwik.inlinedQrl(() => {
28
+ const [props2] = qwik.useLexicalScope();
29
+ return {
30
+ ...props2.attributes,
31
+ [getClassPropName.getClassPropName()]: `builder-personalization-container ${props2.attributes[getClassPropName.getClassPropName()] || ""}`
32
+ };
33
+ }, "PersonalizationContainer_component_attrs_useComputed_HvEf55mhkdc", [
34
+ props
35
+ ]));
36
+ const filteredVariants = qwik.useComputedQrl(/* @__PURE__ */ qwik.inlinedQrl(() => {
37
+ const [props2, state2] = qwik.useLexicalScope();
38
+ return (props2.variants || []).filter((variant) => {
39
+ var _a2, _b2, _c2, _d2;
40
+ return inlinedFns.filterWithCustomTargeting({
41
+ ...((_b2 = (_a2 = props2.builderContext) == null ? void 0 : _a2.rootState) == null ? void 0 : _b2.locale) ? {
42
+ locale: (_d2 = (_c2 = props2.builderContext) == null ? void 0 : _c2.rootState) == null ? void 0 : _d2.locale
43
+ } : {},
44
+ ...state2.userAttributes
45
+ }, variant.query, variant.startDate, variant.endDate);
46
+ });
47
+ }, "PersonalizationContainer_component_filteredVariants_useComputed_0jlgEflkxcQ", [
48
+ props,
49
+ state
50
+ ]));
51
+ const blocksToRender = qwik.useComputedQrl(/* @__PURE__ */ qwik.inlinedQrl(() => {
52
+ var _a2;
53
+ const [filteredVariants2, props2, state2] = qwik.useLexicalScope();
54
+ return helpers.getBlocksToRender({
55
+ variants: props2.variants,
56
+ fallbackBlocks: (_a2 = props2.builderBlock) == null ? void 0 : _a2.children,
57
+ isHydrated: state2.shouldResetVariants,
58
+ filteredVariants: filteredVariants2.value,
59
+ previewingIndex: props2.previewingIndex
60
+ });
61
+ }, "PersonalizationContainer_component_blocksToRender_useComputed_aZOAYVB7Svg", [
62
+ filteredVariants,
63
+ props,
64
+ state
65
+ ]));
66
+ const hideVariantsStyleString = qwik.useComputedQrl(/* @__PURE__ */ qwik.inlinedQrl(() => {
67
+ const [props2] = qwik.useLexicalScope();
68
+ return (props2.variants || []).map((_, index) => {
69
+ var _a2;
70
+ return `div[data-variant-id="${(_a2 = props2.builderBlock) == null ? void 0 : _a2.id}-${index}"] { display: none !important; } `;
71
+ }).join("");
72
+ }, "PersonalizationContainer_component_hideVariantsStyleString_useComputed_zcfmLIe0H1E", [
73
+ props
74
+ ]));
75
+ const rootRef = qwik.useSignal();
76
+ qwik.useVisibleTaskQrl(/* @__PURE__ */ qwik.inlinedQrl(() => {
77
+ var _a2;
78
+ const [filteredVariants2, props2, rootRef2, state2] = qwik.useLexicalScope();
79
+ state2.shouldResetVariants = true;
80
+ const unsub = userAttributes.userAttributesService.subscribeOnUserAttributesChange((attrs2) => {
81
+ state2.userAttributes = attrs2;
82
+ }, {
83
+ fireImmediately: target.TARGET === "qwik"
84
+ });
85
+ if (!(isEditing.isEditing() || isPreviewing.isPreviewing())) {
86
+ const variant = filteredVariants2.value[0];
87
+ if (rootRef2.value) {
88
+ rootRef2.value.dispatchEvent(new CustomEvent("builder.variantLoaded", {
89
+ detail: {
90
+ variant: variant || helpers.DEFAULT_INDEX,
91
+ content: (_a2 = props2.builderContext) == null ? void 0 : _a2.content
92
+ },
93
+ bubbles: true
94
+ }));
95
+ const observer = new IntersectionObserver((entries) => {
96
+ entries.forEach((entry) => {
97
+ var _a3;
98
+ if (entry.isIntersecting && rootRef2.value)
99
+ rootRef2.value.dispatchEvent(new CustomEvent("builder.variantDisplayed", {
100
+ detail: {
101
+ variant: variant || helpers.DEFAULT_INDEX,
102
+ content: (_a3 = props2.builderContext) == null ? void 0 : _a3.content
103
+ },
104
+ bubbles: true
105
+ }));
106
+ });
107
+ });
108
+ observer.observe(rootRef2.value);
109
+ }
110
+ }
111
+ state2.unsubscribers.push(unsub);
112
+ }, "PersonalizationContainer_component_useVisibleTask_Pr6C1pfMwDU", [
113
+ filteredVariants,
114
+ props,
115
+ rootRef,
116
+ state
117
+ ]));
118
+ return /* @__PURE__ */ qwik._jsxS("div", {
119
+ ref: rootRef,
120
+ ...attrs.value,
121
+ children: [
122
+ state.shouldResetVariants && helpers.SDKS_REQUIRING_RESET_APPROACH.includes(target.TARGET) ? /* @__PURE__ */ qwik._jsxC(blocks.Blocks, {
123
+ get blocks() {
124
+ return blocksToRender.value.blocks;
125
+ },
126
+ get parent() {
127
+ var _a2;
128
+ return (_a2 = props.builderBlock) == null ? void 0 : _a2.id;
129
+ },
130
+ get path() {
131
+ return blocksToRender.value.path;
132
+ },
133
+ get context() {
134
+ return props.builderContext;
135
+ },
136
+ get registeredComponents() {
137
+ return props.builderComponents;
138
+ },
139
+ get BlocksWrapperProps() {
140
+ var _a2, _b2;
141
+ return {
142
+ ...(_a2 = props.builderContext) == null ? void 0 : _a2.BlocksWrapperProps,
143
+ "data-variant-id": `${(_b2 = props.builderBlock) == null ? void 0 : _b2.id}-${blocksToRender.value.index}`
144
+ };
145
+ },
146
+ [qwik._IMMUTABLE]: {
147
+ BlocksWrapperProps: qwik._fnSignal((p0, p1) => {
148
+ var _a2, _b2;
149
+ return {
150
+ ...(_a2 = p1.builderContext) == null ? void 0 : _a2.BlocksWrapperProps,
151
+ "data-variant-id": `${(_b2 = p1.builderBlock) == null ? void 0 : _b2.id}-${p0.value.index}`
152
+ };
153
+ }, [
154
+ blocksToRender,
155
+ props
156
+ ], '{...p1.builderContext?.BlocksWrapperProps,"data-variant-id":`${p1.builderBlock?.id}-${p0.value.index}`}'),
157
+ blocks: qwik._fnSignal((p0) => p0.value.blocks, [
158
+ blocksToRender
159
+ ], "p0.value.blocks"),
160
+ context: qwik._fnSignal((p0) => p0.builderContext, [
161
+ props
162
+ ], "p0.builderContext"),
163
+ parent: qwik._fnSignal((p0) => {
164
+ var _a2;
165
+ return (_a2 = p0.builderBlock) == null ? void 0 : _a2.id;
166
+ }, [
167
+ props
168
+ ], "p0.builderBlock?.id"),
169
+ path: qwik._fnSignal((p0) => p0.value.path, [
170
+ blocksToRender
171
+ ], "p0.value.path"),
172
+ registeredComponents: qwik._fnSignal((p0) => p0.builderComponents, [
173
+ props
174
+ ], "p0.builderComponents")
175
+ }
176
+ }, 3, "Xk_0") : null,
177
+ !state.shouldResetVariants && helpers.SDKS_REQUIRING_RESET_APPROACH.includes(target.TARGET) || !helpers.SDKS_REQUIRING_RESET_APPROACH.includes(target.TARGET) ? /* @__PURE__ */ qwik._jsxC(jsxRuntime.Fragment, {
178
+ children: [
179
+ state.shouldRenderVariants ? /* @__PURE__ */ qwik._jsxC(jsxRuntime.Fragment, {
180
+ children: [
181
+ /* @__PURE__ */ qwik._jsxC(inlinedStyles.InlinedStyles, {
182
+ get nonce() {
183
+ var _a2;
184
+ return ((_a2 = props.builderContext) == null ? void 0 : _a2.nonce) || "";
185
+ },
186
+ get styles() {
187
+ return hideVariantsStyleString.value;
188
+ },
189
+ get id() {
190
+ var _a2;
191
+ return `variants-styles-${(_a2 = props.builderBlock) == null ? void 0 : _a2.id}`;
192
+ },
193
+ [qwik._IMMUTABLE]: {
194
+ id: qwik._fnSignal((p0) => {
195
+ var _a2;
196
+ return `variants-styles-${(_a2 = p0.builderBlock) == null ? void 0 : _a2.id}`;
197
+ }, [
198
+ props
199
+ ], "`variants-styles-${p0.builderBlock?.id}`"),
200
+ nonce: qwik._fnSignal((p0) => {
201
+ var _a2;
202
+ return ((_a2 = p0.builderContext) == null ? void 0 : _a2.nonce) || "";
203
+ }, [
204
+ props
205
+ ], 'p0.builderContext?.nonce||""'),
206
+ styles: qwik._fnSignal((p0) => p0.value, [
207
+ hideVariantsStyleString
208
+ ], "p0.value")
209
+ }
210
+ }, 3, "Xk_1"),
211
+ /* @__PURE__ */ qwik._jsxC(inlinedScript.InlinedScript, {
212
+ get nonce() {
213
+ var _a2;
214
+ return ((_a2 = props.builderContext) == null ? void 0 : _a2.nonce) || "";
215
+ },
216
+ get scriptStr() {
217
+ return state.updateVisibilityStylesScript;
218
+ },
219
+ get id() {
220
+ var _a2;
221
+ return `variants-visibility-script-${(_a2 = props.builderBlock) == null ? void 0 : _a2.id}`;
222
+ },
223
+ [qwik._IMMUTABLE]: {
224
+ id: qwik._fnSignal((p0) => {
225
+ var _a2;
226
+ return `variants-visibility-script-${(_a2 = p0.builderBlock) == null ? void 0 : _a2.id}`;
227
+ }, [
228
+ props
229
+ ], "`variants-visibility-script-${p0.builderBlock?.id}`"),
230
+ nonce: qwik._fnSignal((p0) => {
231
+ var _a2;
232
+ return ((_a2 = p0.builderContext) == null ? void 0 : _a2.nonce) || "";
233
+ }, [
234
+ props
235
+ ], 'p0.builderContext?.nonce||""'),
236
+ scriptStr: qwik._fnSignal((p0) => p0.updateVisibilityStylesScript, [
237
+ state
238
+ ], "p0.updateVisibilityStylesScript")
239
+ }
240
+ }, 3, "Xk_2"),
241
+ (props.variants || []).map((variant, index) => {
242
+ var _a2, _b2, _c2, _d2;
243
+ return /* @__PURE__ */ qwik._jsxC(blocks.Blocks, {
244
+ BlocksWrapperProps: {
245
+ ...(_a2 = props.builderContext) == null ? void 0 : _a2.BlocksWrapperProps,
246
+ "aria-hidden": true,
247
+ hidden: true,
248
+ "data-variant-id": `${(_b2 = props.builderBlock) == null ? void 0 : _b2.id}-${index}`
249
+ },
250
+ get blocks() {
251
+ return variant.blocks;
252
+ },
253
+ get parent() {
254
+ var _a3;
255
+ return (_a3 = props.builderBlock) == null ? void 0 : _a3.id;
256
+ },
257
+ path: `component.options.variants.${index}.blocks`,
258
+ get context() {
259
+ return props.builderContext;
260
+ },
261
+ get registeredComponents() {
262
+ return props.builderComponents;
263
+ },
264
+ children: /* @__PURE__ */ qwik._jsxC(inlinedScript.InlinedScript, {
265
+ get nonce() {
266
+ var _a3;
267
+ return ((_a3 = props.builderContext) == null ? void 0 : _a3.nonce) || "";
268
+ },
269
+ get scriptStr() {
270
+ return state.scriptStr;
271
+ },
272
+ id: `variants-script-${(_c2 = props.builderBlock) == null ? void 0 : _c2.id}-${index}`,
273
+ [qwik._IMMUTABLE]: {
274
+ nonce: qwik._fnSignal((p0) => {
275
+ var _a3;
276
+ return ((_a3 = p0.builderContext) == null ? void 0 : _a3.nonce) || "";
277
+ }, [
278
+ props
279
+ ], 'p0.builderContext?.nonce||""'),
280
+ scriptStr: qwik._fnSignal((p0) => p0.scriptStr, [
281
+ state
282
+ ], "p0.scriptStr")
283
+ }
284
+ }, 3, "Xk_3"),
285
+ [qwik._IMMUTABLE]: {
286
+ blocks: qwik._wrapProp(variant, "blocks"),
287
+ context: qwik._fnSignal((p0) => p0.builderContext, [
288
+ props
289
+ ], "p0.builderContext"),
290
+ parent: qwik._fnSignal((p0) => {
291
+ var _a3;
292
+ return (_a3 = p0.builderBlock) == null ? void 0 : _a3.id;
293
+ }, [
294
+ props
295
+ ], "p0.builderBlock?.id"),
296
+ registeredComponents: qwik._fnSignal((p0) => p0.builderComponents, [
297
+ props
298
+ ], "p0.builderComponents")
299
+ }
300
+ }, 1, `${(_d2 = props.builderBlock) == null ? void 0 : _d2.id}-${index}`);
301
+ })
302
+ ]
303
+ }, 1, "Xk_4") : null,
304
+ /* @__PURE__ */ qwik._jsxC(blocks.Blocks, {
305
+ get blocks() {
306
+ return blocksToRender.value.blocks;
307
+ },
308
+ get parent() {
309
+ var _a2;
310
+ return (_a2 = props.builderBlock) == null ? void 0 : _a2.id;
311
+ },
312
+ get path() {
313
+ return blocksToRender.value.path;
314
+ },
315
+ get context() {
316
+ return props.builderContext;
317
+ },
318
+ get registeredComponents() {
319
+ return props.builderComponents;
320
+ },
321
+ get BlocksWrapperProps() {
322
+ var _a2, _b2;
323
+ return {
324
+ ...(_a2 = props.builderContext) == null ? void 0 : _a2.BlocksWrapperProps,
325
+ "data-variant-id": `${(_b2 = props.builderBlock) == null ? void 0 : _b2.id}-${blocksToRender.value.index}`
326
+ };
327
+ },
328
+ children: state.shouldRenderVariants ? /* @__PURE__ */ qwik._jsxC(inlinedScript.InlinedScript, {
329
+ get nonce() {
330
+ var _a2;
331
+ return ((_a2 = props.builderContext) == null ? void 0 : _a2.nonce) || "";
332
+ },
333
+ get scriptStr() {
334
+ return state.scriptStr;
335
+ },
336
+ id: `variants-script-${(_h = props.builderBlock) == null ? void 0 : _h.id}-${helpers.DEFAULT_INDEX}`,
337
+ [qwik._IMMUTABLE]: {
338
+ nonce: qwik._fnSignal((p0) => {
339
+ var _a2;
340
+ return ((_a2 = p0.builderContext) == null ? void 0 : _a2.nonce) || "";
341
+ }, [
342
+ props
343
+ ], 'p0.builderContext?.nonce||""'),
344
+ scriptStr: qwik._fnSignal((p0) => p0.scriptStr, [
345
+ state
346
+ ], "p0.scriptStr")
347
+ }
348
+ }, 3, "Xk_5") : null,
349
+ [qwik._IMMUTABLE]: {
350
+ BlocksWrapperProps: qwik._fnSignal((p0, p1) => {
351
+ var _a2, _b2;
352
+ return {
353
+ ...(_a2 = p1.builderContext) == null ? void 0 : _a2.BlocksWrapperProps,
354
+ "data-variant-id": `${(_b2 = p1.builderBlock) == null ? void 0 : _b2.id}-${p0.value.index}`
355
+ };
356
+ }, [
357
+ blocksToRender,
358
+ props
359
+ ], '{...p1.builderContext?.BlocksWrapperProps,"data-variant-id":`${p1.builderBlock?.id}-${p0.value.index}`}'),
360
+ blocks: qwik._fnSignal((p0) => p0.value.blocks, [
361
+ blocksToRender
362
+ ], "p0.value.blocks"),
363
+ context: qwik._fnSignal((p0) => p0.builderContext, [
364
+ props
365
+ ], "p0.builderContext"),
366
+ parent: qwik._fnSignal((p0) => {
367
+ var _a2;
368
+ return (_a2 = p0.builderBlock) == null ? void 0 : _a2.id;
369
+ }, [
370
+ props
371
+ ], "p0.builderBlock?.id"),
372
+ path: qwik._fnSignal((p0) => p0.value.path, [
373
+ blocksToRender
374
+ ], "p0.value.path"),
375
+ registeredComponents: qwik._fnSignal((p0) => p0.builderComponents, [
376
+ props
377
+ ], "p0.builderComponents")
378
+ }
379
+ }, 1, "Xk_6")
380
+ ]
381
+ }, 1, "Xk_7") : null
382
+ ]
383
+ }, null, 0, "Xk_8");
384
+ }, "PersonalizationContainer_component_kIsPnu9O2Ew"));
385
+ exports.PersonalizationContainer = PersonalizationContainer;
386
+ exports.default = PersonalizationContainer;