@useinsider/guido 3.15.1-beta.6da4177 → 3.16.0-beta.0faee0c

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 (59) hide show
  1. package/dist/@types/config/schemas.js +108 -92
  2. package/dist/components/Guido.vue.js +1 -1
  3. package/dist/components/Guido.vue2.js +78 -75
  4. package/dist/composables/useActionsApi.js +30 -22
  5. package/dist/composables/useEmailTemplateApplier.js +25 -23
  6. package/dist/composables/useHtmlValidator.js +85 -83
  7. package/dist/composables/useStripo.js +30 -29
  8. package/dist/composables/useTimerClone.js +21 -19
  9. package/dist/config/migrator/checkboxMigrator.js +20 -19
  10. package/dist/config/migrator/radioButtonMigrator.js +26 -25
  11. package/dist/extensions/Blocks/Checkbox/constants/controlIds.js +4 -0
  12. package/dist/extensions/Blocks/Checkbox/constants/selectors.js +6 -0
  13. package/dist/extensions/Blocks/Checkbox/controls/blockBackground/index.js +10 -0
  14. package/dist/extensions/Blocks/Checkbox/extension.js +6 -5
  15. package/dist/extensions/Blocks/Checkbox/settingsPanel.js +15 -14
  16. package/dist/extensions/Blocks/Checkbox/template.js +10 -9
  17. package/dist/extensions/Blocks/Items/block.js +44 -42
  18. package/dist/extensions/Blocks/Items/template.js +86 -86
  19. package/dist/extensions/Blocks/RadioButton/constants/controlIds.js +4 -0
  20. package/dist/extensions/Blocks/RadioButton/constants/selectors.js +6 -0
  21. package/dist/extensions/Blocks/RadioButton/controls/blockBackground/index.js +10 -0
  22. package/dist/extensions/Blocks/RadioButton/extension.js +5 -4
  23. package/dist/extensions/Blocks/RadioButton/settingsPanel.js +12 -11
  24. package/dist/extensions/Blocks/RadioButton/template.js +16 -9
  25. package/dist/extensions/Blocks/Recommendation/controls/cardBackground/index.js +5 -9
  26. package/dist/extensions/Blocks/Recommendation/controls/spacing/index.js +98 -113
  27. package/dist/extensions/Blocks/Recommendation/recommendation.css.js +21 -0
  28. package/dist/extensions/Blocks/controlFactories.js +117 -115
  29. package/dist/guido.css +1 -1
  30. package/dist/library.js +11 -7
  31. package/dist/node_modules/valibot/dist/index.js +230 -216
  32. package/dist/public/trackingIds.js +8 -0
  33. package/dist/src/@types/config/schemas.d.ts +20 -0
  34. package/dist/src/composables/useActionsApi.d.ts +1 -1
  35. package/dist/src/composables/useConfig.d.ts +4 -0
  36. package/dist/src/extensions/Blocks/Checkbox/constants/controlIds.d.ts +7 -0
  37. package/dist/src/extensions/Blocks/Checkbox/constants/index.d.ts +10 -0
  38. package/dist/src/extensions/Blocks/Checkbox/constants/selectors.d.ts +16 -0
  39. package/dist/src/extensions/Blocks/Checkbox/controls/blockBackground/index.d.ts +14 -0
  40. package/dist/src/extensions/Blocks/RadioButton/constants/controlIds.d.ts +7 -0
  41. package/dist/src/extensions/Blocks/RadioButton/constants/index.d.ts +10 -0
  42. package/dist/src/extensions/Blocks/RadioButton/constants/selectors.d.ts +16 -0
  43. package/dist/src/extensions/Blocks/RadioButton/controls/blockBackground/index.d.ts +14 -0
  44. package/dist/src/extensions/Blocks/Recommendation/controls/spacing/index.d.ts +5 -0
  45. package/dist/src/extensions/Blocks/_Boilerplate/constants/controlIds.d.ts +7 -0
  46. package/dist/src/extensions/Blocks/_Boilerplate/constants/index.d.ts +10 -0
  47. package/dist/src/extensions/Blocks/_Boilerplate/constants/selectors.d.ts +16 -0
  48. package/dist/src/extensions/Blocks/_Boilerplate/controls/blockBackground/index.d.ts +14 -0
  49. package/dist/src/library.d.ts +1 -0
  50. package/dist/src/public/trackingIds.d.ts +9 -0
  51. package/dist/src/stores/config.d.ts +36 -0
  52. package/dist/src/stores/editor.d.ts +25 -0
  53. package/dist/src/utils/linkTrackingIds.d.ts +30 -0
  54. package/dist/stores/editor.js +4 -1
  55. package/dist/stores/onboarding.js +11 -7
  56. package/dist/utils/linkTrackingIds.js +56 -0
  57. package/dist/utils/pairProductVariables.js +105 -99
  58. package/dist/utils/templatePreparation.js +72 -61
  59. package/package.json +5 -1
@@ -9,6 +9,7 @@ export declare const useEditorStore: import("pinia").StoreDefinition<"guidoEdito
9
9
  isStripoInitialized: boolean;
10
10
  templateId: string;
11
11
  syncModulesEnabled: boolean;
12
+ trackIdSessionFloor: number;
12
13
  }, {
13
14
  isEditorToolbarVisible: (state: {
14
15
  loadingStatus: boolean;
@@ -21,6 +22,7 @@ export declare const useEditorStore: import("pinia").StoreDefinition<"guidoEdito
21
22
  isStripoInitialized: boolean;
22
23
  templateId: string;
23
24
  syncModulesEnabled: boolean;
25
+ trackIdSessionFloor: number;
24
26
  } & import("pinia").PiniaCustomStateProperties<{
25
27
  loadingStatus: boolean;
26
28
  isCodeEditorOpen: boolean;
@@ -32,6 +34,7 @@ export declare const useEditorStore: import("pinia").StoreDefinition<"guidoEdito
32
34
  isStripoInitialized: boolean;
33
35
  templateId: string;
34
36
  syncModulesEnabled: boolean;
37
+ trackIdSessionFloor: number;
35
38
  }>) => boolean;
36
39
  isUndoButtonDisabled: (state: {
37
40
  loadingStatus: boolean;
@@ -44,6 +47,7 @@ export declare const useEditorStore: import("pinia").StoreDefinition<"guidoEdito
44
47
  isStripoInitialized: boolean;
45
48
  templateId: string;
46
49
  syncModulesEnabled: boolean;
50
+ trackIdSessionFloor: number;
47
51
  } & import("pinia").PiniaCustomStateProperties<{
48
52
  loadingStatus: boolean;
49
53
  isCodeEditorOpen: boolean;
@@ -55,6 +59,7 @@ export declare const useEditorStore: import("pinia").StoreDefinition<"guidoEdito
55
59
  isStripoInitialized: boolean;
56
60
  templateId: string;
57
61
  syncModulesEnabled: boolean;
62
+ trackIdSessionFloor: number;
58
63
  }>) => boolean;
59
64
  isRedoButtonDisabled: (state: {
60
65
  loadingStatus: boolean;
@@ -67,6 +72,7 @@ export declare const useEditorStore: import("pinia").StoreDefinition<"guidoEdito
67
72
  isStripoInitialized: boolean;
68
73
  templateId: string;
69
74
  syncModulesEnabled: boolean;
75
+ trackIdSessionFloor: number;
70
76
  } & import("pinia").PiniaCustomStateProperties<{
71
77
  loadingStatus: boolean;
72
78
  isCodeEditorOpen: boolean;
@@ -78,6 +84,7 @@ export declare const useEditorStore: import("pinia").StoreDefinition<"guidoEdito
78
84
  isStripoInitialized: boolean;
79
85
  templateId: string;
80
86
  syncModulesEnabled: boolean;
87
+ trackIdSessionFloor: number;
81
88
  }>) => boolean;
82
89
  isCodeEditorButtonDisabled: (state: {
83
90
  loadingStatus: boolean;
@@ -90,6 +97,7 @@ export declare const useEditorStore: import("pinia").StoreDefinition<"guidoEdito
90
97
  isStripoInitialized: boolean;
91
98
  templateId: string;
92
99
  syncModulesEnabled: boolean;
100
+ trackIdSessionFloor: number;
93
101
  } & import("pinia").PiniaCustomStateProperties<{
94
102
  loadingStatus: boolean;
95
103
  isCodeEditorOpen: boolean;
@@ -101,6 +109,7 @@ export declare const useEditorStore: import("pinia").StoreDefinition<"guidoEdito
101
109
  isStripoInitialized: boolean;
102
110
  templateId: string;
103
111
  syncModulesEnabled: boolean;
112
+ trackIdSessionFloor: number;
104
113
  }>) => boolean;
105
114
  isPreviewButtonDisabled: (state: {
106
115
  loadingStatus: boolean;
@@ -113,6 +122,7 @@ export declare const useEditorStore: import("pinia").StoreDefinition<"guidoEdito
113
122
  isStripoInitialized: boolean;
114
123
  templateId: string;
115
124
  syncModulesEnabled: boolean;
125
+ trackIdSessionFloor: number;
116
126
  } & import("pinia").PiniaCustomStateProperties<{
117
127
  loadingStatus: boolean;
118
128
  isCodeEditorOpen: boolean;
@@ -124,6 +134,7 @@ export declare const useEditorStore: import("pinia").StoreDefinition<"guidoEdito
124
134
  isStripoInitialized: boolean;
125
135
  templateId: string;
126
136
  syncModulesEnabled: boolean;
137
+ trackIdSessionFloor: number;
127
138
  }>) => boolean;
128
139
  isViewOptionsDisabled: (state: {
129
140
  loadingStatus: boolean;
@@ -136,6 +147,7 @@ export declare const useEditorStore: import("pinia").StoreDefinition<"guidoEdito
136
147
  isStripoInitialized: boolean;
137
148
  templateId: string;
138
149
  syncModulesEnabled: boolean;
150
+ trackIdSessionFloor: number;
139
151
  } & import("pinia").PiniaCustomStateProperties<{
140
152
  loadingStatus: boolean;
141
153
  isCodeEditorOpen: boolean;
@@ -147,6 +159,7 @@ export declare const useEditorStore: import("pinia").StoreDefinition<"guidoEdito
147
159
  isStripoInitialized: boolean;
148
160
  templateId: string;
149
161
  syncModulesEnabled: boolean;
162
+ trackIdSessionFloor: number;
150
163
  }>) => boolean;
151
164
  isVersionHistoryButtonDisabled: (state: {
152
165
  loadingStatus: boolean;
@@ -159,6 +172,7 @@ export declare const useEditorStore: import("pinia").StoreDefinition<"guidoEdito
159
172
  isStripoInitialized: boolean;
160
173
  templateId: string;
161
174
  syncModulesEnabled: boolean;
175
+ trackIdSessionFloor: number;
162
176
  } & import("pinia").PiniaCustomStateProperties<{
163
177
  loadingStatus: boolean;
164
178
  isCodeEditorOpen: boolean;
@@ -170,6 +184,7 @@ export declare const useEditorStore: import("pinia").StoreDefinition<"guidoEdito
170
184
  isStripoInitialized: boolean;
171
185
  templateId: string;
172
186
  syncModulesEnabled: boolean;
187
+ trackIdSessionFloor: number;
173
188
  }>) => boolean;
174
189
  isExportButtonDisabled: (state: {
175
190
  loadingStatus: boolean;
@@ -182,6 +197,7 @@ export declare const useEditorStore: import("pinia").StoreDefinition<"guidoEdito
182
197
  isStripoInitialized: boolean;
183
198
  templateId: string;
184
199
  syncModulesEnabled: boolean;
200
+ trackIdSessionFloor: number;
185
201
  } & import("pinia").PiniaCustomStateProperties<{
186
202
  loadingStatus: boolean;
187
203
  isCodeEditorOpen: boolean;
@@ -193,6 +209,7 @@ export declare const useEditorStore: import("pinia").StoreDefinition<"guidoEdito
193
209
  isStripoInitialized: boolean;
194
210
  templateId: string;
195
211
  syncModulesEnabled: boolean;
212
+ trackIdSessionFloor: number;
196
213
  }>) => boolean;
197
214
  isSaveAsButtonDisabled: (state: {
198
215
  loadingStatus: boolean;
@@ -205,6 +222,7 @@ export declare const useEditorStore: import("pinia").StoreDefinition<"guidoEdito
205
222
  isStripoInitialized: boolean;
206
223
  templateId: string;
207
224
  syncModulesEnabled: boolean;
225
+ trackIdSessionFloor: number;
208
226
  } & import("pinia").PiniaCustomStateProperties<{
209
227
  loadingStatus: boolean;
210
228
  isCodeEditorOpen: boolean;
@@ -216,6 +234,7 @@ export declare const useEditorStore: import("pinia").StoreDefinition<"guidoEdito
216
234
  isStripoInitialized: boolean;
217
235
  templateId: string;
218
236
  syncModulesEnabled: boolean;
237
+ trackIdSessionFloor: number;
219
238
  }>) => boolean;
220
239
  isTestButtonDisabled: (state: {
221
240
  loadingStatus: boolean;
@@ -228,6 +247,7 @@ export declare const useEditorStore: import("pinia").StoreDefinition<"guidoEdito
228
247
  isStripoInitialized: boolean;
229
248
  templateId: string;
230
249
  syncModulesEnabled: boolean;
250
+ trackIdSessionFloor: number;
231
251
  } & import("pinia").PiniaCustomStateProperties<{
232
252
  loadingStatus: boolean;
233
253
  isCodeEditorOpen: boolean;
@@ -239,6 +259,7 @@ export declare const useEditorStore: import("pinia").StoreDefinition<"guidoEdito
239
259
  isStripoInitialized: boolean;
240
260
  templateId: string;
241
261
  syncModulesEnabled: boolean;
262
+ trackIdSessionFloor: number;
242
263
  }>) => boolean;
243
264
  isSaveButtonDisabled: (state: {
244
265
  loadingStatus: boolean;
@@ -251,6 +272,7 @@ export declare const useEditorStore: import("pinia").StoreDefinition<"guidoEdito
251
272
  isStripoInitialized: boolean;
252
273
  templateId: string;
253
274
  syncModulesEnabled: boolean;
275
+ trackIdSessionFloor: number;
254
276
  } & import("pinia").PiniaCustomStateProperties<{
255
277
  loadingStatus: boolean;
256
278
  isCodeEditorOpen: boolean;
@@ -262,6 +284,7 @@ export declare const useEditorStore: import("pinia").StoreDefinition<"guidoEdito
262
284
  isStripoInitialized: boolean;
263
285
  templateId: string;
264
286
  syncModulesEnabled: boolean;
287
+ trackIdSessionFloor: number;
265
288
  }>) => boolean;
266
289
  isInSaveableState: (state: {
267
290
  loadingStatus: boolean;
@@ -274,6 +297,7 @@ export declare const useEditorStore: import("pinia").StoreDefinition<"guidoEdito
274
297
  isStripoInitialized: boolean;
275
298
  templateId: string;
276
299
  syncModulesEnabled: boolean;
300
+ trackIdSessionFloor: number;
277
301
  } & import("pinia").PiniaCustomStateProperties<{
278
302
  loadingStatus: boolean;
279
303
  isCodeEditorOpen: boolean;
@@ -285,5 +309,6 @@ export declare const useEditorStore: import("pinia").StoreDefinition<"guidoEdito
285
309
  isStripoInitialized: boolean;
286
310
  templateId: string;
287
311
  syncModulesEnabled: boolean;
312
+ trackIdSessionFloor: number;
288
313
  }>) => boolean;
289
314
  }, {}>;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Persistent link tracking ids for the click heatmap (SD-141414).
3
+ * Pure string transforms — no DOM parse/serialize round-trip, safe for both
4
+ * Stripo raw HTML and hand-authored HTML-editor documents. Shared with email-fe.
5
+ */
6
+ export declare const TRACK_ID_ATTRIBUTE = "data-ins-track-id";
7
+ export declare const TRACK_SEQ_ATTRIBUTE = "data-ins-track-seq";
8
+ export interface TrackingIdResult {
9
+ html: string;
10
+ changed: boolean;
11
+ nextSeq: number;
12
+ }
13
+ /**
14
+ * Reads the persisted id high-water mark: <body> attr, then <html> attr,
15
+ * then the leading comment fallback. Returns 0 when absent.
16
+ */
17
+ export declare function readTrackSeq(html: string): number;
18
+ /**
19
+ * Highest id already handed out: persisted seq, live ids, consumer counter.
20
+ * Scans the document because a rewrite can strip the seq host but keep the ids.
21
+ */
22
+ export declare function readTrackFloor(html: string, persistedCounter?: number): number;
23
+ /**
24
+ * Ensures every <a> opening tag carries a unique positive-integer id and the
25
+ * document records the id high-water mark. Ids are minted above
26
+ * max(persisted seq, max id in document, floor) so deleted ids are never
27
+ * reused — even after a version restore or paste-over (floor = session floor).
28
+ * Idempotent: a document already normalized returns changed=false.
29
+ */
30
+ export declare function assignTrackingIds(html: string, floor?: number): TrackingIdResult;
@@ -10,7 +10,10 @@ const o = e("guidoEditor", {
10
10
  hasChanges: !1,
11
11
  isStripoInitialized: !1,
12
12
  templateId: "",
13
- syncModulesEnabled: !1
13
+ syncModulesEnabled: !1,
14
+ // In-session id high-water mark; floors tracking-id minting so ids
15
+ // deleted by a version restore / paste-over are never reused.
16
+ trackIdSessionFloor: 0
14
17
  }),
15
18
  getters: {
16
19
  // Middle Slot
@@ -1,4 +1,4 @@
1
- import { useOnboardingApi as r } from "../services/onboardingApi.js";
1
+ import { useOnboardingApi as s } from "../services/onboardingApi.js";
2
2
  import { defineStore as e } from "pinia";
3
3
  const t = () => ({
4
4
  cardIndex: 0,
@@ -72,8 +72,8 @@ const t = () => ({
72
72
  this.onboardings[n].cardIndex > 0 && this.onboardings[n].cardIndex--;
73
73
  },
74
74
  updateCardPosition(n, i, o) {
75
- const s = this.onboardings[n].config[i];
76
- s && (s.top = o.top, s.position = o.position);
75
+ const r = this.onboardings[n].config[i];
76
+ r && (r.top = o.top, r.position = o.position);
77
77
  },
78
78
  setConfig(n, i) {
79
79
  this.onboardings[n].config = i ?? [], this.onboardings[n].cardIndex >= this.onboardings[n].config.length && (this.onboardings[n].cardIndex = 0);
@@ -93,12 +93,16 @@ const t = () => ({
93
93
  async fetchUserModalState() {
94
94
  if (this.isFetched)
95
95
  return;
96
- const { fetchUserModalState: n } = r(), i = await n();
97
- this.userModalState = i, this.isFetched = !0;
96
+ const { fetchUserModalState: n } = s();
97
+ try {
98
+ const i = await n();
99
+ this.userModalState = i, this.isFetched = !0;
100
+ } catch {
101
+ }
98
102
  },
99
103
  async setUserModalState(n, i, o) {
100
- const { setUserModalState: s } = r();
101
- await s(n, i, o), this.isFetched = !1, await this.fetchUserModalState();
104
+ const { setUserModalState: r } = s();
105
+ await r(n, i, o), this.isFetched = !1, await this.fetchUserModalState();
102
106
  }
103
107
  }
104
108
  });
@@ -0,0 +1,56 @@
1
+ const g = "data-ins-track-id", $ = "data-ins-track-seq", E = `(?:[^>"']|"[^"]*"|'[^']*')*`, f = new RegExp(`<a\\b${E}>`, "gi"), b = new RegExp(`<body\\b${E}>`, "i"), N = new RegExp(`<html\\b${E}>`, "i"), I = new RegExp(`\\b${g}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`, "i"), S = new RegExp(`\\b${$}\\s*=\\s*(?:"(\\d+)"|'(\\d+)'|(\\d+))`, "i"), p = "ins-track-seq", _ = new RegExp(`<!--\\s*${p}:(\\d+)\\s*-->`, "i"), w = /^[1-9][0-9]{0,14}$/, k = 999999999999999;
2
+ function m(e) {
3
+ const n = Number(e);
4
+ return Number.isSafeInteger(n) && n > 0 ? n : 0;
5
+ }
6
+ function M(e) {
7
+ var a;
8
+ const n = (s) => {
9
+ var r;
10
+ const o = (r = s.exec(e)) == null ? void 0 : r[0];
11
+ return o ? S.exec(o) : null;
12
+ }, t = n(b) ?? n(N), c = (t == null ? void 0 : t[1]) ?? (t == null ? void 0 : t[2]) ?? (t == null ? void 0 : t[3]) ?? ((a = _.exec(e)) == null ? void 0 : a[1]) ?? "";
13
+ return m(c);
14
+ }
15
+ function P(e, n = 0) {
16
+ let t = 0;
17
+ [...e.matchAll(f)].forEach(([a]) => {
18
+ const s = I.exec(a), o = s ? s[1] ?? s[2] ?? s[3] ?? "" : "";
19
+ w.test(o) && (t = Math.max(t, Number(o)));
20
+ });
21
+ const c = Number.isSafeInteger(n) && n > 0 ? n : 0;
22
+ return Math.max(M(e), t, c);
23
+ }
24
+ function q(e, n) {
25
+ const t = `${$}="${n}"`, c = b.exec(e) ?? N.exec(e);
26
+ if (c) {
27
+ const [s] = c, o = S.exec(s), r = o ? s.replace(o[0], t) : s.replace(/\/?>$/, (T) => ` ${t}${T}`);
28
+ return e.slice(0, c.index) + r + e.slice(c.index + s.length);
29
+ }
30
+ const a = `<!--${p}:${n}-->`;
31
+ return _.test(e) ? e.replace(_, a) : `${a}${e}`;
32
+ }
33
+ function D(e, n, t) {
34
+ const c = `${g}="${t}"`;
35
+ return n ? e.replace(n[0], c) : e.replace(/^<a\b/i, (a) => `${a} ${c}`);
36
+ }
37
+ function C(e, n = 0) {
38
+ const t = /* @__PURE__ */ new Set();
39
+ let c = 0;
40
+ const a = [...e.matchAll(f)].map((i) => {
41
+ const [l] = i, u = I.exec(l), R = u ? u[1] ?? u[2] ?? u[3] ?? "" : "";
42
+ let x = null;
43
+ return w.test(R) && !t.has(Number(R)) && (x = Number(R), t.add(x), c = Math.max(c, x)), { index: i.index, tag: l, attrMatch: u, id: x };
44
+ }), s = M(e), o = Number.isSafeInteger(n) && n > 0 && n < k ? n : 0;
45
+ let r = Math.max(s, c, o), T = "", d = 0, A = !1;
46
+ return a.forEach((i) => {
47
+ T += e.slice(d, i.index), i.id === null ? (r += 1, T += D(i.tag, i.attrMatch, r), A = !0) : T += i.tag, d = i.index + i.tag.length;
48
+ }), T += e.slice(d), r > 0 && s !== r && (T = q(T, r), A = !0), { html: T, changed: A, nextSeq: r };
49
+ }
50
+ export {
51
+ g as TRACK_ID_ATTRIBUTE,
52
+ $ as TRACK_SEQ_ATTRIBUTE,
53
+ C as assignTrackingIds,
54
+ P as readTrackFloor,
55
+ M as readTrackSeq
56
+ };
@@ -1,88 +1,100 @@
1
- import { productPairs as q } from "../extensions/Blocks/Items/enums/productEnums.js";
2
- import { DefaultConfigValues as O } from "../extensions/Blocks/Items/enums/settingsEnums.js";
3
- import { preserveTextStyles as C } from "./preserveTextStyles.js";
4
- import { unwrapProductNameLinks as U } from "./unwrapProductNameLink.js";
5
- function Y(L) {
6
- const H = L.replaceAll("{%", "<!--{%").replaceAll("%}", "%}-->"), b = new DOMParser().parseFromString(H, "text/html");
7
- U(b);
8
- const R = q.PAIRS_FOR_EXTENSION;
9
- Object.entries(R).forEach(([r, u]) => {
10
- b.querySelectorAll(".ins-product-td").forEach((l) => {
11
- const h = l.getAttribute("data-number") || "1", $ = l.getAttribute("data-type") || "CART_ITEMS";
12
- l.querySelectorAll(`[product-attr="${r}"]`).forEach((t) => {
13
- var F, I, w;
14
- const T = t.getAttribute("data-type") || $, f = t.getAttribute("data-number") || h, d = u[T];
15
- if (d)
16
- switch (r) {
1
+ import { productPairs as L } from "../extensions/Blocks/Items/enums/productEnums.js";
2
+ import { DefaultConfigValues as V } from "../extensions/Blocks/Items/enums/settingsEnums.js";
3
+ import { escapeReplacement as G } from "../extensions/Blocks/Items/utils/nodeConfigUtils.js";
4
+ import { preserveTextStyles as F } from "./preserveTextStyles.js";
5
+ import { unwrapProductNameLinks as X } from "./unwrapProductNameLink.js";
6
+ const x = {
7
+ CART_ITEMS: "ins_apr",
8
+ BROWSED_ITEMS: "browsed_item",
9
+ PURCHASED_ITEMS: "purchased_item"
10
+ }, N = (S) => S.replaceAll("{%", "<!--{%").replaceAll("%}", "%}-->");
11
+ function v(S, H, g) {
12
+ let $ = H;
13
+ for (; $ > 0 && /\s/.test(S[$ - 1]); )
14
+ $ -= 1;
15
+ return g.some((I) => S.endsWith(I, $));
16
+ }
17
+ function J(S) {
18
+ const H = N(S), g = new DOMParser().parseFromString(H, "text/html");
19
+ X(g);
20
+ const $ = L.PAIRS_FOR_EXTENSION;
21
+ Object.entries($).forEach(([n, d]) => {
22
+ g.querySelectorAll(".ins-product-td").forEach((r) => {
23
+ const E = r.getAttribute("data-number") || "1", m = r.getAttribute("data-type") || "CART_ITEMS";
24
+ r.querySelectorAll(`[product-attr="${n}"]`).forEach((t) => {
25
+ var T, P, D;
26
+ const R = t.getAttribute("data-type") || m, o = t.getAttribute("data-number") || E, f = d[R];
27
+ if (f)
28
+ switch (n) {
17
29
  case "imageSrc": {
18
- let e = null, c = null;
19
- if (t.tagName === "IMG" ? (e = t, c = e.closest("a")) : (e = t.querySelector("img"), c = t.querySelector("a") || t.closest("a")), !e)
30
+ let e = null, s = null;
31
+ if (t.tagName === "IMG" ? (e = t, s = e.closest("a")) : (e = t.querySelector("img"), s = t.querySelector("a") || t.closest("a")), !e)
20
32
  break;
21
- const i = d.DEFAULT, a = d.ATTR;
22
- if (i && e.src) {
23
- const o = e.src;
24
- i.some((E) => {
25
- const s = E.split("/").pop() || "", g = o.split("/").pop() || "";
26
- return o.includes(E) || o.includes(s) || g === s;
27
- }) && (e.src = `{{${a}_${f}}}`);
33
+ const a = f.DEFAULT, l = f.ATTR;
34
+ if (a && e.src) {
35
+ const i = e.src;
36
+ a.some((b) => {
37
+ const u = b.split("/").pop() || "", y = i.split("/").pop() || "";
38
+ return i.includes(b) || i.includes(u) || y === u;
39
+ }) && (e.src = `{{${l}_${o}}}`);
28
40
  }
29
- const n = (I = (F = R.name) == null ? void 0 : F[T]) == null ? void 0 : I.ATTR;
30
- if (n && e.setAttribute("alt", `{{${n}_${f}}}`), c) {
31
- const o = (w = R.itemLink) == null ? void 0 : w[T];
32
- if (o) {
33
- const A = o.HREF, E = o.DEFAULT_HREF || "#!", s = c.href;
34
- (s === "#" || s === "" || s.endsWith("#!") || s.endsWith(E) || s === `${window.location.href}${E}` || !s || s === window.location.href) && (c.href = `{{${A}_${f}}}`);
41
+ const c = (P = (T = $.name) == null ? void 0 : T[R]) == null ? void 0 : P.ATTR;
42
+ if (c && e.setAttribute("alt", `{{${c}_${o}}}`), s) {
43
+ const i = (D = $.itemLink) == null ? void 0 : D[R];
44
+ if (i) {
45
+ const _ = i.HREF, b = i.DEFAULT_HREF || "#!", u = s.href;
46
+ (u === "#" || u === "" || u.endsWith("#!") || u.endsWith(b) || u === `${window.location.href}${b}` || !u || u === window.location.href) && (s.href = `{{${_}_${o}}}`);
35
47
  }
36
48
  }
37
49
  break;
38
50
  }
39
51
  case "name": {
40
- const e = d, c = e.ATTR, i = e.DEFAULT_HREF || "#!", a = e.HREF;
41
- t.textContent && (t.innerHTML = C(t, `{{${c}_${f}}}`));
42
- const n = t.closest("a") || (t.tagName === "A" ? t : null);
43
- if (n && a) {
44
- const o = n.href, A = `${window.location.href}${i}`;
45
- (o === A || o.endsWith(i)) && (n.href = `{{${a}_${f}}}`);
52
+ const e = f, s = e.ATTR, a = e.DEFAULT_HREF || "#!", l = e.HREF;
53
+ t.textContent && (t.innerHTML = F(t, `{{${s}_${o}}}`));
54
+ const c = t.closest("a") || (t.tagName === "A" ? t : null);
55
+ if (c && l) {
56
+ const i = c.href, _ = `${window.location.href}${a}`;
57
+ (i === _ || i.endsWith(a)) && (c.href = `{{${l}_${o}}}`);
46
58
  }
47
59
  break;
48
60
  }
49
61
  case "price":
50
62
  case "originalPrice": {
51
- const e = d, c = t.getAttribute("data-formated"), i = t.getAttribute("data-single_price"), a = c === "true", n = i === "true", o = t.getAttribute("data-curency") || "before";
52
- let A;
53
- n ? A = a ? e.SINGLE_PRICE_FORMATTED : e.SINGLE_PRICE : A = a ? e.PRICE_FORMATTED : e.PRICE;
54
- const E = e.CURRENCY;
55
- let s = `{{${A}_${f}}}`;
56
- const g = (t.getAttribute("data-currency_symbol") || "").trim(), N = g !== "" && g !== O.productPriceCurrencySymbolControlValue;
57
- let m = "";
58
- N ? m = g : E && (m = `{{${E}_${f}}}`), m && (s = o === "after" ? `${s} ${m}` : `${m} ${s}`), t.innerHTML = C(t, s);
63
+ const e = f, s = t.getAttribute("data-formated"), a = t.getAttribute("data-single_price"), l = s === "true", c = a === "true", i = t.getAttribute("data-curency") || "before";
64
+ let _;
65
+ c ? _ = l ? e.SINGLE_PRICE_FORMATTED : e.SINGLE_PRICE : _ = l ? e.PRICE_FORMATTED : e.PRICE;
66
+ const b = e.CURRENCY;
67
+ let u = `{{${_}_${o}}}`;
68
+ const y = (t.getAttribute("data-currency_symbol") || "").trim(), W = y !== "" && y !== V.productPriceCurrencySymbolControlValue;
69
+ let C = "";
70
+ W ? C = y : b && (C = `{{${b}_${o}}}`), C && (u = i === "after" ? `${u} ${C}` : `${C} ${u}`), t.innerHTML = F(t, u);
59
71
  break;
60
72
  }
61
73
  case "quantity": {
62
- const e = d, c = e.ATTR, i = e.DEFAULT;
63
- t.textContent && t.textContent.trim() === i && (t.innerHTML = C(t, `{{${c}_${f}}}`));
74
+ const e = f, s = e.ATTR, a = e.DEFAULT;
75
+ t.textContent && t.textContent.trim() === a && (t.innerHTML = F(t, `{{${s}_${o}}}`));
64
76
  break;
65
77
  }
66
78
  case "button": {
67
- const e = d, c = e.HREF, i = e.DEFAULT_HREF || "#!", a = t.tagName === "A" ? t : t.querySelector("a");
68
- if (a) {
69
- const n = a.href || "", o = `${window.location.href}${i}`;
70
- (n === "" || n === "#" || n === o || n.endsWith(i) || n.endsWith("#!") || n === window.location.href) && (a.href = `{{${c}_${f}}}`);
79
+ const e = f, s = e.HREF, a = e.DEFAULT_HREF || "#!", l = t.tagName === "A" ? t : t.querySelector("a");
80
+ if (l) {
81
+ const c = l.href || "", i = `${window.location.href}${a}`;
82
+ (c === "" || c === "#" || c === i || c.endsWith(a) || c.endsWith("#!") || c === window.location.href) && (l.href = `{{${s}_${o}}}`);
71
83
  }
72
84
  break;
73
85
  }
74
86
  case "itemLink": {
75
- const e = d, c = e.HREF, i = e.DEFAULT_HREF || "#!", a = t;
76
- if (a.href) {
77
- const n = a.href, o = `${window.location.href}${i}`;
78
- (n === o || n.endsWith(i)) && (a.href = `{{${c}_${f}}}`);
87
+ const e = f, s = e.HREF, a = e.DEFAULT_HREF || "#!", l = t;
88
+ if (l.href) {
89
+ const c = l.href, i = `${window.location.href}${a}`;
90
+ (c === i || c.endsWith(a)) && (l.href = `{{${s}_${o}}}`);
79
91
  }
80
92
  break;
81
93
  }
82
94
  default: {
83
- if ("ATTR" in d) {
84
- const e = d.ATTR;
85
- t.textContent && (t.innerHTML = C(t, `{{${e}_${f}}}`));
95
+ if ("ATTR" in f) {
96
+ const e = f.ATTR;
97
+ t.textContent && (t.innerHTML = F(t, `{{${e}_${o}}}`));
86
98
  }
87
99
  break;
88
100
  }
@@ -90,55 +102,49 @@ function Y(L) {
90
102
  });
91
103
  });
92
104
  });
93
- const k = H.match(/<!DOCTYPE[^>]*>/i), P = k ? `${k[0]}
94
- ` : "", D = b.querySelectorAll(".ins-product-td"), M = [];
95
- D.forEach((r) => {
96
- const u = r.getAttribute("data-type") || "CART_ITEMS", p = r.getAttribute("data-number") || "1", l = r.outerHTML;
105
+ const I = H.match(/<!DOCTYPE[^>]*>/i), O = I ? `${I[0]}
106
+ ` : "", q = g.querySelectorAll(".ins-product-td"), M = [];
107
+ q.forEach((n) => {
108
+ const d = n.getAttribute("data-type") || "CART_ITEMS", p = n.getAttribute("data-number") || "1", r = n.outerHTML;
97
109
  M.push({
98
- element: r,
99
- outerHtml: l,
100
- type: u,
110
+ element: n,
111
+ outerHtml: r,
112
+ type: d,
101
113
  number: p
102
114
  });
103
115
  });
104
- let _ = P + b.documentElement.outerHTML;
105
- M.reverse().forEach(({ outerHtml: r, type: u, number: p }) => {
106
- let l = "";
107
- switch (u) {
108
- case "CART_ITEMS":
109
- l = "ins_apr_total_product_kind";
110
- break;
111
- case "BROWSED_ITEMS":
112
- l = "browsed_item_total_product_kind";
113
- break;
114
- case "PURCHASED_ITEMS":
115
- l = "purchased_item_total_product_kind";
116
- break;
117
- }
118
- if (l) {
119
- const $ = parseInt(p) - 1, T = `${`{% if ${l} > ${$} %}`}${r}{% endif %}`;
120
- _ = _.replace(r, T);
116
+ let A = O + g.documentElement.outerHTML;
117
+ M.reverse().forEach(({ outerHtml: n, type: d, number: p }) => {
118
+ const r = x[d], E = r ? `${r}_total_product_kind` : "";
119
+ if (E) {
120
+ const h = parseInt(p) - 1, o = `${`{% if ${E} > ${h} %}`}${n}{% endif %}`;
121
+ A = A.replace(n, G(o));
121
122
  }
122
123
  });
123
- const x = b.querySelectorAll('[product-attr="originalPrice"][data-type="CART_ITEMS"]'), S = [];
124
- return x.forEach((r) => {
125
- var $;
126
- const u = r.getAttribute("data-number"), p = r.getAttribute("data-type");
127
- if (!u || p !== "CART_ITEMS" || (($ = r.closest(".ins-product-td")) == null ? void 0 : $.getAttribute("data-nodup")) === "false")
124
+ const U = g.querySelectorAll('[product-attr="originalPrice"][data-type]'), w = /* @__PURE__ */ new Map(), k = /* @__PURE__ */ new Set();
125
+ return U.forEach((n) => {
126
+ var t;
127
+ const d = n.getAttribute("data-number"), p = n.getAttribute("data-type");
128
+ if (!d || !x[p])
128
129
  return;
129
- const h = r.closest(".product-original-price-class");
130
- if (h) {
131
- const y = h.outerHTML;
132
- S.some((T) => T.tdOuterHtml === y) || S.push({ tdOuterHtml: y, number: u });
133
- }
134
- }), S.reverse().forEach(({ tdOuterHtml: r, number: u }) => {
135
- const p = `{% if ins_apr_price_${u} != ins_apr_originalprice_${u} %}`;
136
- if (!_.includes(p) && !r.includes("{% if")) {
137
- const h = `${p}${r}{% endif %}`;
138
- _ = _.replace(r, h);
130
+ const r = n.closest(".product-original-price-class");
131
+ if (!r || k.has(r))
132
+ return;
133
+ k.add(r);
134
+ const E = r.outerHTML, m = (t = n.closest(".ins-product-td")) == null ? void 0 : t.getAttribute("data-nodup"), h = w.get(E) ?? { number: d, type: p, wrap: [] };
135
+ h.wrap.push(m !== "false"), w.set(E, h);
136
+ }), w.forEach(({ number: n, type: d, wrap: p }, r) => {
137
+ if (r.includes("{% if") || !p.some(Boolean))
138
+ return;
139
+ const E = L.PAIRS_FOR_EXTENSION.price[d].PRICE, m = L.PAIRS_FOR_EXTENSION.originalPrice[d].PRICE, h = `{% if ${E}_${n} != ${m}_${n} %}`, t = [h, N(h)];
140
+ let R = "", o = 0, f = 0, T = A.indexOf(r);
141
+ for (; T !== -1; ) {
142
+ const P = p[f] === !0 && !v(A, T, t);
143
+ R += A.slice(o, T) + (P ? `${h}${r}{% endif %}` : r), o = T + r.length, f += 1, T = A.indexOf(r, o);
139
144
  }
140
- }), _.replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}").replaceAll("&lt;!--{%", "{%").replaceAll("%}--&gt;", "%}");
145
+ A = R + A.slice(o);
146
+ }), A.replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}").replaceAll("&lt;!--{%", "{%").replaceAll("%}--&gt;", "%}");
141
147
  }
142
148
  export {
143
- Y as pairProductVariables
149
+ J as pairProductVariables
144
150
  };