@builder.io/sdk-react 4.0.8 → 4.0.10

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 (83) hide show
  1. package/lib/browser/blocks-exports.cjs +92 -64
  2. package/lib/browser/blocks-exports.mjs +1765 -1650
  3. package/lib/browser/index.cjs +1 -1
  4. package/lib/browser/index.mjs +1 -1
  5. package/lib/browser/server-entry-6a0d3985.cjs +2 -0
  6. package/lib/{edge/server-entry-e9974799.js → browser/server-entry-a97b474c.js} +272 -265
  7. package/lib/browser/server-entry.cjs +1 -1
  8. package/lib/browser/server-entry.mjs +1 -1
  9. package/lib/edge/{accordion-8ef468e5.js → accordion-39aaa10f.js} +1 -1
  10. package/lib/edge/{accordion-94839d7d.cjs → accordion-f19408f1.cjs} +1 -1
  11. package/lib/edge/{blocks-548ec8c2.js → blocks-204bcb03.js} +179 -176
  12. package/lib/edge/{blocks-7e8837dc.cjs → blocks-bd4d19a4.cjs} +3 -3
  13. package/lib/edge/blocks-exports.cjs +1 -1
  14. package/lib/edge/blocks-exports.mjs +2 -2
  15. package/lib/edge/{button-66c37b9c.cjs → button-39adadab.cjs} +1 -1
  16. package/lib/edge/{button-09f38c2e.js → button-eb4a1fce.js} +2 -2
  17. package/lib/edge/{columns-67ded4b4.cjs → columns-3954e4e2.cjs} +3 -3
  18. package/lib/edge/{columns-42cbe467.js → columns-d3cef236.js} +9 -9
  19. package/lib/edge/content-variants-0c41aa3b.cjs +302 -0
  20. package/lib/edge/{content-variants-5a4eecaf.js → content-variants-68bbb30c.js} +650 -367
  21. package/lib/edge/{custom-code-ea534e98.cjs → custom-code-eded3b35.cjs} +1 -1
  22. package/lib/edge/{custom-code-cf216b27.js → custom-code-f8374f7b.js} +1 -1
  23. package/lib/edge/{embed-12b85639.js → embed-2b4ce9d5.js} +1 -1
  24. package/lib/edge/{embed-7ca4af6e.cjs → embed-44dee332.cjs} +1 -1
  25. package/lib/edge/form-1493caf1.cjs +1 -0
  26. package/lib/edge/form-9faf63c9.js +178 -0
  27. package/lib/edge/{get-class-prop-name-316a93c9.cjs → get-class-prop-name-a9265175.cjs} +1 -1
  28. package/lib/edge/{get-class-prop-name-90df5962.js → get-class-prop-name-cc48fc17.js} +1 -1
  29. package/lib/edge/{image-e38bd9e0.cjs → image-cce92f6c.cjs} +2 -2
  30. package/lib/edge/{image-acc1c00c.js → image-d87761af.js} +18 -18
  31. package/lib/edge/{img-ee2838af.js → img-58c08dd4.js} +1 -1
  32. package/lib/edge/{img-81a7f4d7.cjs → img-b8d85bad.cjs} +1 -1
  33. package/lib/edge/index.cjs +1 -1
  34. package/lib/edge/index.mjs +1 -1
  35. package/lib/edge/{input-b8907c7d.js → input-a7c01b3a.js} +1 -1
  36. package/lib/edge/{input-231ec63f.cjs → input-d988f887.cjs} +1 -1
  37. package/lib/edge/personalization-container-2f2bfa1b.cjs +1 -0
  38. package/lib/edge/personalization-container-9ae00624.js +208 -0
  39. package/lib/edge/{select-b1650a75.cjs → select-03b307f2.cjs} +1 -1
  40. package/lib/edge/{select-ffee7a69.js → select-4f03decc.js} +1 -1
  41. package/lib/{node/server-entry-2b91f2d9.js → edge/server-entry-0fe1fd76.js} +306 -303
  42. package/lib/edge/server-entry-e13b9b35.cjs +2 -0
  43. package/lib/edge/server-entry.cjs +1 -1
  44. package/lib/edge/server-entry.mjs +1 -1
  45. package/lib/edge/{slot-ddddba8d.cjs → slot-125b0593.cjs} +1 -1
  46. package/lib/edge/{slot-fe93ec42.js → slot-ff90c844.js} +3 -3
  47. package/lib/edge/{symbol-c266ba83.js → symbol-7558aa24.js} +2 -2
  48. package/lib/edge/{symbol-d9175a66.cjs → symbol-da3ec542.cjs} +1 -1
  49. package/lib/edge/{tabs-f76f757a.cjs → tabs-3cf7cfd3.cjs} +1 -1
  50. package/lib/edge/{tabs-3481a6f6.js → tabs-a9e56d82.js} +3 -3
  51. package/lib/node/blocks-exports.cjs +92 -64
  52. package/lib/node/blocks-exports.mjs +1675 -1560
  53. package/lib/node/index.cjs +1 -1
  54. package/lib/node/index.mjs +3 -3
  55. package/lib/node/init.cjs +1 -1
  56. package/lib/node/init.mjs +3 -3
  57. package/lib/{browser/server-entry-d0b98fb0.js → node/server-entry-23f9b44b.js} +205 -199
  58. package/lib/node/server-entry-ceef853b.cjs +2 -0
  59. package/lib/node/server-entry.cjs +1 -1
  60. package/lib/node/server-entry.mjs +1 -1
  61. package/lib/node/{setIvm-26e766c5.cjs → setIvm-71bce8c3.cjs} +1 -1
  62. package/lib/node/{setIvm-419a94e0.js → setIvm-b29cbc40.js} +1 -1
  63. package/lib/node/setIvm.cjs +1 -1
  64. package/lib/node/setIvm.mjs +2 -2
  65. package/lib/node/{should-force-browser-runtime-in-node-67506521.js → should-force-browser-runtime-in-node-5a2ea9eb.js} +1 -1
  66. package/lib/node/{should-force-browser-runtime-in-node-fe3d9cb0.cjs → should-force-browser-runtime-in-node-e0147364.cjs} +1 -1
  67. package/package.json +2 -2
  68. package/types/blocks/personalization-container/helpers/inlined-fns.d.ts +4 -1
  69. package/types/blocks/personalization-container/helpers.d.ts +24 -4
  70. package/types/blocks/personalization-container/personalization-container.types.d.ts +2 -2
  71. package/types/components/blocks/blocks-wrapper.d.ts +13 -1
  72. package/types/components/blocks/blocks.types.d.ts +1 -1
  73. package/types/constants/sdk-version.d.ts +1 -1
  74. package/types/helpers/no-serialize-wrapper.d.ts +1 -0
  75. package/types/helpers/user-attributes.d.ts +6 -2
  76. package/lib/browser/server-entry-8ea5d047.cjs +0 -2
  77. package/lib/edge/content-variants-cf107f82.cjs +0 -137
  78. package/lib/edge/form-85ea06df.cjs +0 -1
  79. package/lib/edge/form-f1188ad2.js +0 -166
  80. package/lib/edge/personalization-container-896a298a.js +0 -384
  81. package/lib/edge/personalization-container-95cba946.cjs +0 -138
  82. package/lib/edge/server-entry-1b560ddb.cjs +0 -2
  83. package/lib/node/server-entry-03fc1c6d.cjs +0 -2
@@ -1,120 +1,77 @@
1
+ const y = "react", v = "[Builder.io]: ", f = {
2
+ log: (...t) => console.log(v, ...t),
3
+ error: (...t) => console.error(v, ...t),
4
+ warn: (...t) => console.warn(v, ...t),
5
+ debug: (...t) => console.debug(v, ...t)
6
+ };
1
7
  function c() {
2
8
  return typeof window != "undefined" && typeof document != "undefined";
3
9
  }
4
- const k = "[Builder.io]: ", f = {
5
- log: (...t) => console.log(k, ...t),
6
- error: (...t) => console.error(k, ...t),
7
- warn: (...t) => console.warn(k, ...t),
8
- debug: (...t) => console.debug(k, ...t)
9
- }, y = (t) => t != null, ot = (t) => {
10
- if (t === "localhost" || t === "127.0.0.1")
11
- return t;
12
- const e = t.split(".");
13
- return e.length > 2 ? e.slice(1).join(".") : t;
14
- }, O = ({
15
- name: t,
16
- canTrack: e
17
- }) => {
18
- var n;
19
- try {
20
- return e ? (n = document.cookie.split("; ").find((r) => r.startsWith(`${t}=`))) == null ? void 0 : n.split("=")[1] : void 0;
21
- } catch (r) {
22
- f.warn("[COOKIE] GET error: ", (r == null ? void 0 : r.message) || r);
23
- return;
24
- }
25
- }, M = async (t) => O(t), it = (t) => t.map(([e, n]) => n ? `${e}=${n}` : e).filter(y).join("; "), at = [["secure", ""], ["SameSite", "None"]], ct = ({
26
- name: t,
27
- value: e,
28
- expires: n
29
- }) => {
30
- const s = (c() ? location.protocol === "https:" : !0) ? at : [[]], o = n ? [["expires", n.toUTCString()]] : [[]], i = [[t, e], ...o, ["path", "/"], ["domain", ot(window.location.hostname)], ...s];
31
- return it(i);
32
- }, P = async ({
33
- name: t,
34
- value: e,
35
- expires: n,
36
- canTrack: r
37
- }) => {
38
- try {
39
- if (!r)
40
- return;
41
- const s = ct({
42
- name: t,
43
- value: e,
44
- expires: n
45
- });
46
- document.cookie = s;
47
- } catch (s) {
48
- f.warn("[COOKIE] SET error: ", (s == null ? void 0 : s.message) || s);
49
- }
50
- }, R = "builder.userAttributes";
51
- function ut() {
52
- let t = !0;
53
- const e = /* @__PURE__ */ new Set();
54
- return {
55
- setUserAttributes(n) {
56
- if (!c())
57
- return;
58
- const r = {
59
- ...this.getUserAttributes(),
60
- ...n
61
- };
62
- P({
63
- name: R,
64
- value: JSON.stringify(r),
65
- canTrack: t
66
- }), e.forEach((s) => s(r));
67
- },
68
- getUserAttributes() {
69
- return c() ? JSON.parse(O({
70
- name: R,
71
- canTrack: t
72
- }) || "{}") : {};
73
- },
74
- subscribeOnUserAttributesChange(n) {
75
- return e.add(n), () => {
76
- e.delete(n);
77
- };
78
- },
79
- setCanTrack(n) {
80
- t = n;
81
- }
82
- };
83
- }
84
- const K = ut(), ee = (t) => {
85
- K.setUserAttributes(t);
86
- }, I = "react", lt = (t) => {
10
+ const at = (t) => {
87
11
  const e = {};
88
12
  return t.forEach((n, r) => {
89
13
  e[r] = n;
90
14
  }), e;
91
- }, j = (t) => t instanceof URLSearchParams ? lt(t) : t, W = (t) => typeof t == "string" ? t : t instanceof URLSearchParams ? t.toString() : new URLSearchParams(t).toString();
92
- function dt() {
15
+ }, K = (t) => t instanceof URLSearchParams ? at(t) : t, W = (t) => typeof t == "string" ? t : t instanceof URLSearchParams ? t.toString() : new URLSearchParams(t).toString();
16
+ function ct() {
93
17
  return c() && window.self !== window.top;
94
18
  }
95
- function ft(t) {
96
- return dt() && // accessing window.location.search is safe here because `isIframe()` is only `true` if we're in a browser.
19
+ function ut(t) {
20
+ return ct() && // accessing window.location.search is safe here because `isIframe()` is only `true` if we're in a browser.
97
21
  W(t || window.location.search).indexOf("builder.frameEditing=") !== -1;
98
22
  }
23
+ const lt = () => {
24
+ if (c()) {
25
+ const t = new URL(location.href);
26
+ return t.pathname === "" && (t.pathname = "/"), t;
27
+ } else
28
+ return console.warn("Cannot get location for tracking in non-browser environment"), null;
29
+ }, dt = () => typeof navigator == "object" && navigator.userAgent || "", ft = () => {
30
+ const t = dt(), e = {
31
+ Android() {
32
+ return t.match(/Android/i);
33
+ },
34
+ BlackBerry() {
35
+ return t.match(/BlackBerry/i);
36
+ },
37
+ iOS() {
38
+ return t.match(/iPhone|iPod/i);
39
+ },
40
+ Opera() {
41
+ return t.match(/Opera Mini/i);
42
+ },
43
+ Windows() {
44
+ return t.match(/IEMobile/i) || t.match(/WPDesktop/i);
45
+ },
46
+ any() {
47
+ return e.Android() || e.BlackBerry() || e.iOS() || e.Opera() || e.Windows() || y === "reactNative";
48
+ }
49
+ }, n = t.match(/Tablet|iPad/i), r = lt();
50
+ return {
51
+ urlPath: r == null ? void 0 : r.pathname,
52
+ host: (r == null ? void 0 : r.host) || (r == null ? void 0 : r.hostname),
53
+ device: n ? "tablet" : e.any() ? "mobile" : "desktop"
54
+ };
55
+ }, S = (t) => t != null;
99
56
  function ne(t) {
100
57
  const e = t || (c() ? window.location.search : void 0);
101
58
  return e ? W(e).indexOf("builder.preview=") !== -1 : !1;
102
59
  }
103
60
  const re = (t) => ({
104
61
  type: "builder.registerComponent",
105
- data: _(t)
62
+ data: j(t)
106
63
  }), ht = (t) => {
107
64
  const e = t.toString().trim(), n = /^[a-zA-Z0-9_]+\s*=>/i.test(e);
108
65
  return `return (${!e.startsWith("function") && !e.startsWith("async") && !e.startsWith("(") && !n ? "function " : ""}${e}).apply(this, arguments)`;
109
66
  };
110
- function _(t) {
67
+ function j(t) {
111
68
  return JSON.parse(JSON.stringify(t, (e, n) => typeof n == "function" ? ht(n) : n));
112
69
  }
113
- const L = {};
70
+ const _ = {};
114
71
  function gt(t, e) {
115
- t === "plugin" && (e = _(e));
116
- let n = L[t];
117
- if (n || (n = L[t] = []), n.push(e), c()) {
72
+ t === "plugin" && (e = j(e));
73
+ let n = _[t];
74
+ if (n || (n = _[t] = []), n.push(e), c()) {
118
75
  const r = {
119
76
  type: "builder.register",
120
77
  data: {
@@ -129,24 +86,24 @@ function gt(t, e) {
129
86
  }
130
87
  }
131
88
  }
132
- const N = {};
89
+ const L = {};
133
90
  function se(t) {
134
91
  if (c()) {
135
- Object.assign(N, t);
92
+ Object.assign(L, t);
136
93
  const e = {
137
94
  type: "builder.settingsChange",
138
- data: N
95
+ data: L
139
96
  };
140
97
  parent.postMessage(e, "*");
141
98
  }
142
99
  }
143
- const V = "builder.", pt = "options.", $ = (t) => {
100
+ const N = "builder.", pt = "options.", $ = (t) => {
144
101
  if (!t)
145
102
  return {};
146
- const e = j(t), n = {};
103
+ const e = K(t), n = {};
147
104
  return Object.keys(e).forEach((r) => {
148
- if (r.startsWith(V)) {
149
- const s = r.replace(V, "").replace(pt, "");
105
+ if (r.startsWith(N)) {
106
+ const s = r.replace(N, "").replace(pt, "");
150
107
  n[s] = e[r];
151
108
  }
152
109
  }), n;
@@ -155,130 +112,139 @@ const V = "builder.", pt = "options.", $ = (t) => {
155
112
  return {};
156
113
  const t = new URLSearchParams(window.location.search);
157
114
  return $(t);
158
- }, G = "4.0.8", J = () => ({
159
- "X-Builder-SDK": I,
115
+ }, G = "4.0.10", J = () => ({
116
+ "X-Builder-SDK": y,
160
117
  "X-Builder-SDK-GEN": "2",
161
118
  "X-Builder-SDK-Version": G
162
- });
163
- function yt() {
119
+ }), St = (t) => {
120
+ if (t === "localhost" || t === "127.0.0.1")
121
+ return t;
122
+ const e = t.split(".");
123
+ return e.length > 2 ? e.slice(1).join(".") : t;
124
+ }, O = ({
125
+ name: t,
126
+ canTrack: e
127
+ }) => {
128
+ var n;
129
+ try {
130
+ return e ? (n = document.cookie.split("; ").find((r) => r.startsWith(`${t}=`))) == null ? void 0 : n.split("=")[1] : void 0;
131
+ } catch (r) {
132
+ f.warn("[COOKIE] GET error: ", (r == null ? void 0 : r.message) || r);
133
+ return;
134
+ }
135
+ }, z = async (t) => O(t), yt = (t) => t.map(([e, n]) => n ? `${e}=${n}` : e).filter(S).join("; "), bt = [["secure", ""], ["SameSite", "None"]], wt = ({
136
+ name: t,
137
+ value: e,
138
+ expires: n
139
+ }) => {
140
+ const s = (c() ? location.protocol === "https:" : !0) ? bt : [[]], o = n ? [["expires", n.toUTCString()]] : [[]], i = [[t, e], ...o, ["path", "/"], ["domain", St(window.location.hostname)], ...s];
141
+ return yt(i);
142
+ }, T = async ({
143
+ name: t,
144
+ value: e,
145
+ expires: n,
146
+ canTrack: r
147
+ }) => {
148
+ try {
149
+ if (!r)
150
+ return;
151
+ const s = wt({
152
+ name: t,
153
+ value: e,
154
+ expires: n
155
+ });
156
+ document.cookie = s;
157
+ } catch (s) {
158
+ f.warn("[COOKIE] SET error: ", (s == null ? void 0 : s.message) || s);
159
+ }
160
+ };
161
+ function Et() {
164
162
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(t) {
165
163
  const e = Math.random() * 16 | 0;
166
164
  return (t == "x" ? e : e & 3 | 8).toString(16);
167
165
  });
168
166
  }
169
167
  function X() {
170
- return yt().replace(/-/g, "");
168
+ return Et().replace(/-/g, "");
171
169
  }
172
- const z = "builderSessionId", bt = async ({
170
+ const H = "builderSessionId", It = async ({
173
171
  canTrack: t
174
172
  }) => {
175
173
  if (!t)
176
174
  return;
177
- const e = await M({
178
- name: z,
175
+ const e = await z({
176
+ name: H,
179
177
  canTrack: t
180
178
  });
181
- if (y(e))
179
+ if (S(e))
182
180
  return e;
183
181
  {
184
- const n = St();
185
- return wt({
182
+ const n = vt();
183
+ return At({
186
184
  id: n,
187
185
  canTrack: t
188
186
  }), n;
189
187
  }
190
- }, St = () => X(), wt = ({
188
+ }, vt = () => X(), At = ({
191
189
  id: t,
192
190
  canTrack: e
193
- }) => P({
194
- name: z,
191
+ }) => T({
192
+ name: H,
195
193
  value: t,
196
194
  canTrack: e
197
- }), H = () => c() && typeof localStorage != "undefined" ? localStorage : void 0, vt = ({
195
+ }), Q = () => c() && typeof localStorage != "undefined" ? localStorage : void 0, kt = ({
198
196
  key: t,
199
197
  canTrack: e
200
198
  }) => {
201
199
  var n;
202
200
  try {
203
- return e ? (n = H()) == null ? void 0 : n.getItem(t) : void 0;
201
+ return e ? (n = Q()) == null ? void 0 : n.getItem(t) : void 0;
204
202
  } catch (r) {
205
203
  console.debug("[LocalStorage] GET error: ", r);
206
204
  return;
207
205
  }
208
- }, It = ({
206
+ }, Ut = ({
209
207
  key: t,
210
208
  canTrack: e,
211
209
  value: n
212
210
  }) => {
213
211
  var r;
214
212
  try {
215
- e && ((r = H()) == null || r.setItem(t, n));
213
+ e && ((r = Q()) == null || r.setItem(t, n));
216
214
  } catch (s) {
217
215
  console.debug("[LocalStorage] SET error: ", s);
218
216
  }
219
- }, Q = "builderVisitorId", kt = ({
217
+ }, Y = "builderVisitorId", Ot = ({
220
218
  canTrack: t
221
219
  }) => {
222
220
  if (!t)
223
221
  return;
224
- const e = vt({
225
- key: Q,
222
+ const e = kt({
223
+ key: Y,
226
224
  canTrack: t
227
225
  });
228
- if (y(e))
226
+ if (S(e))
229
227
  return e;
230
228
  {
231
- const n = At();
232
- return Et({
229
+ const n = Tt();
230
+ return Ct({
233
231
  id: n,
234
232
  canTrack: t
235
233
  }), n;
236
234
  }
237
- }, At = () => X(), Et = ({
235
+ }, Tt = () => X(), Ct = ({
238
236
  id: t,
239
237
  canTrack: e
240
- }) => It({
241
- key: Q,
238
+ }) => Ut({
239
+ key: Y,
242
240
  value: t,
243
241
  canTrack: e
244
242
  });
245
- function Ot(t) {
243
+ function Pt(t) {
246
244
  var e;
247
245
  typeof process != "undefined" && ((e = process.env) != null && e.DEBUG) && String(process.env.DEBUG) == "true" && f.log(t);
248
246
  }
249
- const Pt = () => {
250
- if (c()) {
251
- const t = new URL(location.href);
252
- return t.pathname === "" && (t.pathname = "/"), t;
253
- } else
254
- return console.warn("Cannot get location for tracking in non-browser environment"), null;
255
- }, Ct = () => typeof navigator == "object" && navigator.userAgent || "", Ut = () => {
256
- const t = Ct(), e = {
257
- Android() {
258
- return t.match(/Android/i);
259
- },
260
- BlackBerry() {
261
- return t.match(/BlackBerry/i);
262
- },
263
- iOS() {
264
- return t.match(/iPhone|iPod/i);
265
- },
266
- Opera() {
267
- return t.match(/Opera Mini/i);
268
- },
269
- Windows() {
270
- return t.match(/IEMobile/i) || t.match(/WPDesktop/i);
271
- },
272
- any() {
273
- return e.Android() || e.BlackBerry() || e.iOS() || e.Opera() || e.Windows() || I === "reactNative";
274
- }
275
- }, n = t.match(/Tablet|iPad/i), r = Pt();
276
- return {
277
- urlPath: r == null ? void 0 : r.pathname,
278
- host: (r == null ? void 0 : r.host) || (r == null ? void 0 : r.hostname),
279
- device: n ? "tablet" : e.any() ? "mobile" : "desktop"
280
- };
281
- }, Tt = async ({
247
+ const Rt = async ({
282
248
  canTrack: t
283
249
  }) => {
284
250
  if (!t)
@@ -286,16 +252,16 @@ const Pt = () => {
286
252
  visitorId: void 0,
287
253
  sessionId: void 0
288
254
  };
289
- const e = await bt({
255
+ const e = await It({
290
256
  canTrack: t
291
- }), n = kt({
257
+ }), n = Ot({
292
258
  canTrack: t
293
259
  });
294
260
  return {
295
261
  sessionId: e,
296
262
  visitorId: n
297
263
  };
298
- }, xt = async ({
264
+ }, Bt = async ({
299
265
  type: t,
300
266
  canTrack: e,
301
267
  apiKey: n,
@@ -309,14 +275,14 @@ const Pt = () => {
309
275
  url: location.href,
310
276
  ...r
311
277
  },
312
- ...await Tt({
278
+ ...await Rt({
313
279
  canTrack: e
314
280
  }),
315
- userAttributes: Ut(),
281
+ userAttributes: ft(),
316
282
  ownerId: n
317
283
  }
318
284
  });
319
- async function Bt({
285
+ async function xt({
320
286
  apiHost: t,
321
287
  ...e
322
288
  }) {
@@ -324,13 +290,13 @@ async function Bt({
324
290
  f.error("Missing API key for track call. Please provide your API key.");
325
291
  return;
326
292
  }
327
- if (!e.canTrack || ft() || !(c() || I === "reactNative"))
293
+ if (!e.canTrack || ut() || !(c() || y === "reactNative"))
328
294
  return;
329
295
  const r = `${t || "https://cdn.builder.io"}/api/v1/track`;
330
- return Ot(r), fetch(r, {
296
+ return Pt(r), fetch(r, {
331
297
  method: "POST",
332
298
  body: JSON.stringify({
333
- events: [await xt(e)]
299
+ events: [await Bt(e)]
334
300
  }),
335
301
  headers: {
336
302
  "content-type": "application/json",
@@ -341,15 +307,15 @@ async function Bt({
341
307
  console.error("Failed to track: ", s);
342
308
  });
343
309
  }
344
- const oe = (t) => Bt({
310
+ const oe = (t) => xt({
345
311
  ...t,
346
312
  canTrack: !0
347
- }), Rt = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
348
- function Y(t, e) {
313
+ }), _t = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
314
+ function Z(t, e) {
349
315
  if (!e.origin.startsWith("http") && !e.origin.startsWith("https"))
350
316
  return !1;
351
317
  const n = new URL(e.origin), r = n.hostname;
352
- return (t || Rt).findIndex((s) => s.startsWith("*.") ? r.endsWith(s.slice(1)) : s === r) > -1;
318
+ return (t || _t).findIndex((s) => s.startsWith("*.") ? r.endsWith(s.slice(1)) : s === r) > -1;
353
319
  }
354
320
  const ie = () => {
355
321
  gt("insertMenu", {
@@ -374,13 +340,13 @@ const ie = () => {
374
340
  }]
375
341
  });
376
342
  };
377
- let F = !1;
343
+ let V = !1;
378
344
  const Lt = (t) => {
379
345
  var e, n;
380
- F || (F = !0, c() && ((e = window.parent) == null || e.postMessage({
346
+ V || (V = !0, c() && ((e = window.parent) == null || e.postMessage({
381
347
  type: "builder.sdkInfo",
382
348
  data: {
383
- target: I,
349
+ target: y,
384
350
  version: G,
385
351
  supportsPatchUpdates: !1,
386
352
  // Supports builder-model="..." attribute which is needed to
@@ -399,7 +365,7 @@ const Lt = (t) => {
399
365
  }
400
366
  }, "*"), window.addEventListener("message", (r) => {
401
367
  var o, i;
402
- if (!Y(t.trustedHosts, r))
368
+ if (!Z(t.trustedHosts, r))
403
369
  return;
404
370
  const {
405
371
  data: s
@@ -407,10 +373,10 @@ const Lt = (t) => {
407
373
  if (s != null && s.type)
408
374
  switch (s.type) {
409
375
  case "builder.evaluate": {
410
- const u = s.data.text, b = s.data.arguments || [], p = s.data.id, S = new Function(u);
376
+ const u = s.data.text, b = s.data.arguments || [], p = s.data.id, w = new Function(u);
411
377
  let l, h = null;
412
378
  try {
413
- l = S.apply(null, b);
379
+ l = w.apply(null, b);
414
380
  } catch (g) {
415
381
  h = g;
416
382
  }
@@ -421,8 +387,8 @@ const Lt = (t) => {
421
387
  error: h.message
422
388
  }
423
389
  }, "*") : l && typeof l.then == "function" ? l.then((g) => {
424
- var w;
425
- (w = window.parent) == null || w.postMessage({
390
+ var E;
391
+ (E = window.parent) == null || E.postMessage({
426
392
  type: "builder.evaluateResult",
427
393
  data: {
428
394
  id: p,
@@ -445,7 +411,7 @@ const Lt = (t) => {
445
411
  trustedHosts: e,
446
412
  callbacks: n
447
413
  }) => (r) => {
448
- if (!Y(e, r))
414
+ if (!Z(e, r))
449
415
  return;
450
416
  const {
451
417
  data: s
@@ -500,12 +466,12 @@ const Lt = (t) => {
500
466
  return window.addEventListener("message", s), () => {
501
467
  window.removeEventListener("message", s);
502
468
  };
503
- }, Vt = "builder.tests", C = (t) => `${Vt}.${t}`, Ft = ({
469
+ }, Vt = "builder.tests", C = (t) => `${Vt}.${t}`, Dt = ({
504
470
  contentId: t
505
- }) => M({
471
+ }) => z({
506
472
  name: C(t),
507
473
  canTrack: !0
508
- }), Dt = ({
474
+ }), Ft = ({
509
475
  contentId: t
510
476
  }) => O({
511
477
  name: C(t),
@@ -513,11 +479,11 @@ const Lt = (t) => {
513
479
  }), Mt = ({
514
480
  contentId: t,
515
481
  value: e
516
- }) => P({
482
+ }) => T({
517
483
  name: C(t),
518
484
  value: e,
519
485
  canTrack: !0
520
- }), Z = (t) => y(t.id) && y(t.variations) && Object.keys(t.variations).length > 0, Kt = ({
486
+ }), q = (t) => S(t.id) && S(t.variations) && Object.keys(t.variations).length > 0, Kt = ({
521
487
  id: t,
522
488
  variations: e
523
489
  }) => {
@@ -530,7 +496,7 @@ const Lt = (t) => {
530
496
  return o;
531
497
  }
532
498
  return t;
533
- }, q = (t) => {
499
+ }, tt = (t) => {
534
500
  const e = Kt(t);
535
501
  return Mt({
536
502
  contentId: t.id,
@@ -538,7 +504,7 @@ const Lt = (t) => {
538
504
  }).catch((n) => {
539
505
  f.error("could not store A/B test variation: ", n);
540
506
  }), e;
541
- }, tt = ({
507
+ }, et = ({
542
508
  item: t,
543
509
  testGroupId: e
544
510
  }) => {
@@ -560,14 +526,14 @@ const Lt = (t) => {
560
526
  return t;
561
527
  if (!t)
562
528
  return;
563
- if (!Z(t))
529
+ if (!q(t))
564
530
  return t;
565
- const n = Dt({
531
+ const n = Ft({
566
532
  contentId: t.id
567
- }) || q({
533
+ }) || tt({
568
534
  variations: t.variations,
569
535
  id: t.id
570
- }), r = tt({
536
+ }), r = et({
571
537
  item: t,
572
538
  testGroupId: n
573
539
  });
@@ -575,18 +541,18 @@ const Lt = (t) => {
575
541
  ...t,
576
542
  ...r
577
543
  };
578
- }, jt = async ({
544
+ }, Wt = async ({
579
545
  item: t,
580
546
  canTrack: e
581
547
  }) => {
582
- if (!e || !Z(t))
548
+ if (!e || !q(t))
583
549
  return t;
584
- const r = await Ft({
550
+ const r = await Dt({
585
551
  contentId: t.id
586
- }) || q({
552
+ }) || tt({
587
553
  variations: t.variations,
588
554
  id: t.id
589
- }), s = tt({
555
+ }), s = et({
590
556
  item: t,
591
557
  testGroupId: r
592
558
  });
@@ -594,41 +560,82 @@ const Lt = (t) => {
594
560
  ...t,
595
561
  ...s
596
562
  };
597
- }, Wt = (t) => {
598
- const e = y(t) ? t : !0;
599
- return K.setCanTrack(e), e;
600
563
  };
601
- function _t() {
602
- return typeof globalThis != "undefined" ? globalThis : typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : globalThis;
564
+ const D = "builder.userAttributes";
565
+ function F() {
566
+ let t = !0;
567
+ const e = /* @__PURE__ */ new Set();
568
+ return {
569
+ setUserAttributes(n) {
570
+ if (!c())
571
+ return;
572
+ const r = {
573
+ ...this.getUserAttributes(),
574
+ ...n
575
+ };
576
+ T({
577
+ name: D,
578
+ value: JSON.stringify(r),
579
+ canTrack: t
580
+ }), e.forEach((s) => s(r));
581
+ },
582
+ getUserAttributes() {
583
+ return c() ? JSON.parse(O({
584
+ name: D,
585
+ canTrack: t
586
+ }) || "{}") : {};
587
+ },
588
+ subscribeOnUserAttributesChange(n, {
589
+ fireImmediately: r
590
+ } = {}) {
591
+ return e.add(n), r && n(this.getUserAttributes()), function() {
592
+ e.delete(n);
593
+ };
594
+ },
595
+ setCanTrack(n) {
596
+ t = n;
597
+ }
598
+ };
603
599
  }
600
+ let k;
601
+ c() && y === "qwik" ? (window.__BUILDER_USER_ATTRIBUTES_SERVICE__ || (window.__BUILDER_USER_ATTRIBUTES_SERVICE__ = F()), k = window.__BUILDER_USER_ATTRIBUTES_SERVICE__) : k = F();
602
+ const nt = k, ue = (t) => {
603
+ nt.setUserAttributes(t);
604
+ }, jt = (t) => {
605
+ const e = S(t) ? t : !0;
606
+ return nt.setCanTrack(e), e;
607
+ };
604
608
  function $t() {
605
- const t = _t().fetch;
609
+ return typeof globalThis != "undefined" ? globalThis : typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : globalThis;
610
+ }
611
+ function Gt() {
612
+ const t = $t().fetch;
606
613
  if (typeof t == "undefined")
607
614
  throw console.warn(`Builder SDK could not find a global fetch function. Make sure you have a polyfill for fetch in your project.
608
615
  For more information, read https://github.com/BuilderIO/this-package-uses-fetch`), new Error("Builder SDK could not find a global `fetch` function");
609
616
  return t;
610
617
  }
611
- const Gt = $t();
612
- function E(t, e = null, n = ".") {
618
+ const Jt = Gt();
619
+ function U(t, e = null, n = ".") {
613
620
  return Object.keys(t).reduce((r, s) => {
614
621
  const o = t[s], i = [e, s].filter(Boolean).join(n);
615
622
  return [typeof o == "object", o !== null, !(Array.isArray(o) && o.length === 0)].every(Boolean) ? {
616
623
  ...r,
617
- ...E(o, i, n)
624
+ ...U(o, i, n)
618
625
  } : {
619
626
  ...r,
620
627
  [i]: o
621
628
  };
622
629
  }, {});
623
630
  }
624
- function et(t, e, n = {}) {
631
+ function rt(t, e, n = {}) {
625
632
  for (const r in t) {
626
633
  const s = t[r], o = e ? e + "." + r : r;
627
- s && typeof s == "object" && !Array.isArray(s) && !Object.keys(s).find((i) => i.startsWith("$")) ? et(s, o, n) : n[o] = s;
634
+ s && typeof s == "object" && !Array.isArray(s) && !Object.keys(s).find((i) => i.startsWith("$")) ? rt(s, o, n) : n[o] = s;
628
635
  }
629
636
  return n;
630
637
  }
631
- function Jt(t) {
638
+ function zt(t) {
632
639
  const e = {};
633
640
  for (const n in t) {
634
641
  const r = n.split(".");
@@ -640,7 +647,7 @@ function Jt(t) {
640
647
  }
641
648
  return e;
642
649
  }
643
- const Xt = "v3", D = (t) => typeof t == "number" && !isNaN(t) && t >= 0, U = (t) => {
650
+ const Xt = "v3", M = (t) => typeof t == "number" && !isNaN(t) && t >= 0, P = (t) => {
644
651
  const {
645
652
  limit: e = 30,
646
653
  userAttributes: n,
@@ -651,76 +658,76 @@ const Xt = "v3", D = (t) => typeof t == "number" && !isNaN(t) && t >= 0, U = (t)
651
658
  locale: u,
652
659
  apiVersion: b = Xt,
653
660
  fields: p,
654
- omit: S,
661
+ omit: w,
655
662
  offset: l,
656
663
  cacheSeconds: h,
657
664
  staleCacheSeconds: g,
658
- sort: w,
659
- includeUnpublished: T,
660
- apiHost: nt
665
+ sort: E,
666
+ includeUnpublished: R,
667
+ apiHost: st
661
668
  } = t;
662
669
  if (!o)
663
670
  throw new Error("Missing API key");
664
671
  if (!["v3"].includes(b))
665
672
  throw new Error(`Invalid apiVersion: expected 'v3', received '${b}'`);
666
- const rt = e !== 1, st = nt || "https://cdn.builder.io", a = new URL(`${st}/api/${b}/content/${s}`);
667
- a.searchParams.set("apiKey", o), a.searchParams.set("limit", String(e)), a.searchParams.set("noTraverse", String(rt)), a.searchParams.set("includeRefs", String(!0));
673
+ const ot = e !== 1, it = st || "https://cdn.builder.io", a = new URL(`${it}/api/${b}/content/${s}`);
674
+ a.searchParams.set("apiKey", o), a.searchParams.set("limit", String(e)), a.searchParams.set("noTraverse", String(ot)), a.searchParams.set("includeRefs", String(!0));
668
675
  const A = u || (n == null ? void 0 : n.locale);
669
676
  let m = n || {};
670
677
  if (A && (a.searchParams.set("locale", A), m = {
671
678
  locale: A,
672
679
  ...m
673
- }), i && a.searchParams.set("enrich", String(i)), a.searchParams.set("omit", S != null ? S : "meta.componentsUsed"), p && a.searchParams.set("fields", p), Number.isFinite(l) && l > -1 && a.searchParams.set("offset", String(Math.floor(l))), typeof T == "boolean" && a.searchParams.set("includeUnpublished", String(T)), h && D(h) && a.searchParams.set("cacheSeconds", String(h)), g && D(g) && a.searchParams.set("staleCacheSeconds", String(g)), w) {
674
- const d = E({
675
- sort: w
680
+ }), i && a.searchParams.set("enrich", String(i)), a.searchParams.set("omit", w != null ? w : "meta.componentsUsed"), p && a.searchParams.set("fields", p), Number.isFinite(l) && l > -1 && a.searchParams.set("offset", String(Math.floor(l))), typeof R == "boolean" && a.searchParams.set("includeUnpublished", String(R)), h && M(h) && a.searchParams.set("cacheSeconds", String(h)), g && M(g) && a.searchParams.set("staleCacheSeconds", String(g)), E) {
681
+ const d = U({
682
+ sort: E
676
683
  });
677
- for (const v in d)
678
- a.searchParams.set(v, JSON.stringify(d[v]));
684
+ for (const I in d)
685
+ a.searchParams.set(I, JSON.stringify(d[I]));
679
686
  }
680
- const x = {
687
+ const B = {
681
688
  ...mt(),
682
- ...j(t.options || {})
689
+ ...K(t.options || {})
683
690
  };
684
691
  m = {
685
692
  ...m,
686
- ...Ht(x)
693
+ ...Qt(B)
687
694
  };
688
- const B = E(x);
689
- for (const d in B)
690
- a.searchParams.set(d, String(B[d]));
695
+ const x = U(B);
696
+ for (const d in x)
697
+ a.searchParams.set(d, String(x[d]));
691
698
  if (Object.keys(m).length > 0 && a.searchParams.set("userAttributes", JSON.stringify(m)), r) {
692
- const d = et({
699
+ const d = rt({
693
700
  query: r
694
701
  });
695
- for (const v in d)
696
- a.searchParams.set(v, JSON.stringify(d[v]));
702
+ for (const I in d)
703
+ a.searchParams.set(I, JSON.stringify(d[I]));
697
704
  }
698
705
  return a;
699
- }, zt = (t) => {
706
+ }, Ht = (t) => {
700
707
  const e = {};
701
708
  for (const n in t)
702
709
  n.startsWith("userAttributes.") && (e[n] = t[n], delete t[n]);
703
710
  return e;
704
- }, Ht = (t) => {
711
+ }, Qt = (t) => {
705
712
  if (c() && t.preview === "BUILDER_STUDIO") {
706
713
  t["userAttributes.urlPath"] = window.location.pathname, t["userAttributes.host"] = window.location.host;
707
- const e = zt(t), {
714
+ const e = Ht(t), {
708
715
  userAttributes: n
709
- } = Jt(e);
716
+ } = zt(e);
710
717
  return n;
711
718
  }
712
719
  return {};
713
- }, Qt = (t) => "results" in t;
714
- async function Yt(t) {
715
- const e = await te({
720
+ }, Yt = (t) => "results" in t;
721
+ async function Zt(t) {
722
+ const e = await ee({
716
723
  ...t,
717
724
  limit: 1
718
725
  });
719
726
  return e && e[0] || null;
720
727
  }
721
- const Zt = async (t) => {
728
+ const qt = async (t) => {
722
729
  var i, u;
723
- const e = U(t), n = (i = t.fetch) != null ? i : Gt, r = {
730
+ const e = P(t), n = (i = t.fetch) != null ? i : Jt, r = {
724
731
  ...t.fetchOptions,
725
732
  headers: {
726
733
  ...(u = t.fetchOptions) == null ? void 0 : u.headers,
@@ -728,14 +735,14 @@ const Zt = async (t) => {
728
735
  }
729
736
  };
730
737
  return await (await n(e.href, r)).json();
731
- }, qt = async (t, e, n = U(t)) => {
732
- const r = Wt(t.canTrack);
733
- if (n.search.includes("preview="), !r || !(c() || I === "reactNative"))
738
+ }, te = async (t, e, n = P(t)) => {
739
+ const r = jt(t.canTrack);
740
+ if (n.search.includes("preview="), !r || !(c() || y === "reactNative"))
734
741
  return e.results;
735
742
  try {
736
743
  const s = [];
737
744
  for (const o of e.results)
738
- s.push(await jt({
745
+ s.push(await Wt({
739
746
  item: o,
740
747
  canTrack: r
741
748
  }));
@@ -745,17 +752,17 @@ const Zt = async (t) => {
745
752
  }
746
753
  return e.results;
747
754
  };
748
- async function te(t) {
749
- const e = U(t), n = await Zt(t);
750
- if (!Qt(n))
755
+ async function ee(t) {
756
+ const e = P(t), n = await qt(t);
757
+ if (!Yt(n))
751
758
  throw f.error("Error fetching data. ", {
752
759
  url: e,
753
760
  content: n,
754
761
  options: t
755
762
  }), n;
756
- return qt(t, n);
763
+ return te(t, n);
757
764
  }
758
- const ue = async (t) => {
765
+ const le = async (t) => {
759
766
  var r, s, o;
760
767
  const e = t.path || ((r = t.url) == null ? void 0 : r.pathname) || ((s = t.userAttributes) == null ? void 0 : s.urlPath), n = {
761
768
  ...t,
@@ -772,36 +779,36 @@ const ue = async (t) => {
772
779
  return {
773
780
  apiKey: n.apiKey,
774
781
  model: n.model,
775
- content: await Yt(n)
782
+ content: await Zt(n)
776
783
  };
777
784
  };
778
785
  export {
779
- I as TARGET,
780
- qt as _processContentResult,
781
- Bt as _track,
782
- y as checkIsDefined,
786
+ y as TARGET,
787
+ te as _processContentResult,
788
+ xt as _track,
789
+ S as checkIsDefined,
783
790
  Nt as createEditorListener,
784
791
  re as createRegisterComponentMessage,
785
- ue as fetchBuilderProps,
786
- te as fetchEntries,
787
- Yt as fetchOneEntry,
792
+ le as fetchBuilderProps,
793
+ ee as fetchEntries,
794
+ Zt as fetchOneEntry,
788
795
  $ as getBuilderSearchParams,
789
796
  O as getCookieSync,
790
- Wt as getDefaultCanTrack,
791
- Ut as getUserAttributes,
797
+ jt as getDefaultCanTrack,
798
+ ft as getUserAttributes,
792
799
  ce as handleABTestingSync,
793
800
  c as isBrowser,
794
- ft as isEditing,
801
+ ut as isEditing,
795
802
  ne as isPreviewing,
796
- Ot as logFetch,
803
+ Pt as logFetch,
797
804
  f as logger,
798
805
  gt as register,
799
806
  ie as registerInsertMenu,
800
- _ as serializeIncludingFunctions,
801
- ee as setClientUserAttributes,
807
+ j as serializeIncludingFunctions,
808
+ ue as setClientUserAttributes,
802
809
  se as setEditorSettings,
803
810
  Lt as setupBrowserForEditing,
804
811
  ae as subscribeToEditor,
805
812
  oe as track,
806
- K as userAttributesService
813
+ nt as userAttributesService
807
814
  };