@useinsider/guido 3.24.0 → 3.25.0

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 (63) hide show
  1. package/README.md +7 -1
  2. package/dist/@types/config/schemas.js +9 -7
  3. package/dist/components/Guido.vue.js +1 -1
  4. package/dist/components/Guido.vue2.js +79 -77
  5. package/dist/composables/useActionsApi.js +2 -2
  6. package/dist/composables/useEditorTrackingIds.js +49 -0
  7. package/dist/composables/useHtmlCompiler.js +2 -0
  8. package/dist/composables/useModuleRepair.js +14 -12
  9. package/dist/composables/useStripo.js +70 -70
  10. package/dist/config/compiler/htmlCompilerRules.js +14 -6
  11. package/dist/config/migrator/index.js +16 -15
  12. package/dist/config/migrator/itemsPriceFormatMigrator.js +20 -0
  13. package/dist/extensions/Blocks/Items/block.js +115 -77
  14. package/dist/extensions/Blocks/Items/constants/currency.js +59 -14
  15. package/dist/extensions/Blocks/Items/controls/blockBackground/index.js +11 -0
  16. package/dist/extensions/Blocks/Items/controls/price/currencyLocation.js +34 -23
  17. package/dist/extensions/Blocks/Items/controls/price/currencySymbol.js +62 -51
  18. package/dist/extensions/Blocks/Items/controls/price/formattedPrice.js +18 -17
  19. package/dist/extensions/Blocks/Items/controls/price/singlePrice.js +42 -31
  20. package/dist/extensions/Blocks/Items/controls/priceFormat.js +135 -0
  21. package/dist/extensions/Blocks/Items/controls/settingsControl.js +141 -120
  22. package/dist/extensions/Blocks/Items/enums/controlEnums.js +2 -2
  23. package/dist/extensions/Blocks/Items/extension.js +15 -13
  24. package/dist/extensions/Blocks/Items/items.css.js +19 -0
  25. package/dist/extensions/Blocks/Items/settingsPanel.js +35 -25
  26. package/dist/extensions/Blocks/Items/template.js +250 -212
  27. package/dist/extensions/Blocks/Items/utils/priceFormatOps.js +185 -0
  28. package/dist/extensions/Blocks/Recommendation/controls/main/index.js +10 -8
  29. package/dist/extensions/Blocks/Recommendation/store/recommendation.js +28 -24
  30. package/dist/extensions/Blocks/Recommendation/utils/nodeConfigWriter.js +23 -22
  31. package/dist/extensions/Blocks/Recommendation/utils/priceFormatter.js +1 -0
  32. package/dist/extensions/Blocks/controlFactories.js +104 -104
  33. package/dist/guido.css +1 -1
  34. package/dist/package.json.js +1 -1
  35. package/dist/services/templateLibraryApi.js +39 -36
  36. package/dist/src/@types/config/schemas.d.ts +4 -0
  37. package/dist/src/composables/useConfig.d.ts +2 -0
  38. package/dist/src/composables/useEditorTrackingIds.d.ts +7 -0
  39. package/dist/src/composables/useStripo.d.ts +1 -1
  40. package/dist/src/config/migrator/index.d.ts +4 -1
  41. package/dist/src/config/migrator/itemsPriceFormatMigrator.d.ts +1 -0
  42. package/dist/src/extensions/Blocks/Items/block.d.ts +6 -9
  43. package/dist/src/extensions/Blocks/Items/constants/currency.d.ts +32 -0
  44. package/dist/src/extensions/Blocks/Items/controls/blockBackground/index.d.ts +15 -0
  45. package/dist/src/extensions/Blocks/Items/controls/priceFormat.d.ts +24 -0
  46. package/dist/src/extensions/Blocks/Items/controls/settingsControl.d.ts +1 -0
  47. package/dist/src/extensions/Blocks/Items/enums/controlEnums.d.ts +2 -0
  48. package/dist/src/extensions/Blocks/Items/template.d.ts +4 -1
  49. package/dist/src/extensions/Blocks/Items/utils/nodeConfigUtils.d.ts +3 -0
  50. package/dist/src/extensions/Blocks/Items/utils/priceFormatOps.d.ts +66 -0
  51. package/dist/src/extensions/Blocks/Recommendation/store/recommendation.d.ts +2 -0
  52. package/dist/src/extensions/Blocks/Recommendation/utils/priceFormatter.d.ts +12 -0
  53. package/dist/src/extensions/Blocks/controlFactories.d.ts +1 -1
  54. package/dist/src/stores/config.d.ts +20 -0
  55. package/dist/src/utils/itemsCurrencyRepair.d.ts +5 -1
  56. package/dist/src/utils/linkTrackingIds.d.ts +19 -0
  57. package/dist/src/utils/trimHrefWhitespace.d.ts +5 -0
  58. package/dist/utils/itemsCurrencyRepair.js +29 -24
  59. package/dist/utils/linkTrackingIds.js +82 -48
  60. package/dist/utils/pairProductVariables.js +119 -99
  61. package/dist/utils/templatePreparation.js +30 -33
  62. package/dist/utils/trimHrefWhitespace.js +10 -0
  63. package/package.json +1 -1
@@ -1,56 +1,90 @@
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)));
1
+ const l = "data-ins-track-id", E = "data-ins-track-seq", A = `(?:[^>"']|"[^"]*"|'[^']*')*`, k = new RegExp(`<a\\b${A}>`, "gi"), R = new RegExp(`<body\\b${A}>`, "i"), _ = new RegExp(`<html\\b${A}>`, "i"), m = new RegExp(`\\b${l}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`, "i"), f = new RegExp(`\\b${E}\\s*=\\s*(?:"(\\d+)"|'(\\d+)'|(\\d+))`, "i"), p = "ins-track-seq", x = new RegExp(`<!--\\s*${p}:(\\d+)\\s*-->`, "i"), $ = /^[1-9][0-9]{0,14}$/, q = 999999999999999;
2
+ function I(e) {
3
+ const c = Number(e);
4
+ return Number.isSafeInteger(c) && c > 0 ? c : 0;
5
+ }
6
+ function T(e) {
7
+ return [...e.matchAll(k)].map((c) => {
8
+ const [n] = c, t = m.exec(n), r = t ? t[1] ?? t[2] ?? t[3] ?? "" : "";
9
+ return { index: c.index, tag: n, attrMatch: t, rawValue: r };
20
10
  });
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);
11
+ }
12
+ function b(e) {
13
+ var r;
14
+ const c = (s) => {
15
+ var a;
16
+ const o = (a = s.exec(e)) == null ? void 0 : a[0];
17
+ return o ? f.exec(o) : null;
18
+ }, n = c(R) ?? c(_), t = (n == null ? void 0 : n[1]) ?? (n == null ? void 0 : n[2]) ?? (n == null ? void 0 : n[3]) ?? ((r = x.exec(e)) == null ? void 0 : r[1]) ?? "";
19
+ return I(t);
20
+ }
21
+ function h(e, c = 0) {
22
+ let n = 0;
23
+ T(e).forEach(({ rawValue: r }) => {
24
+ $.test(r) && (n = Math.max(n, Number(r)));
25
+ });
26
+ const t = Number.isSafeInteger(c) && c > 0 ? c : 0;
27
+ return Math.max(b(e), n, t);
28
+ }
29
+ function w(e, c) {
30
+ const n = `${E}="${c}"`, t = R.exec(e) ?? _.exec(e);
31
+ if (t) {
32
+ const [s] = t, o = f.exec(s), a = o ? s.replace(o[0], n) : s.replace(/\/?>$/, (u) => ` ${n}${u}`);
33
+ return e.slice(0, t.index) + a + e.slice(t.index + s.length);
29
34
  }
30
- const a = `<!--${p}:${n}-->`;
31
- return _.test(e) ? e.replace(_, a) : `${a}${e}`;
35
+ const r = `<!--${p}:${c}-->`;
36
+ return x.test(e) ? e.replace(x, r) : `${r}${e}`;
32
37
  }
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}`);
38
+ function M(e, c, n) {
39
+ const t = `${l}="${n}"`;
40
+ return c ? e.replace(c[0], t) : e.replace(/^<a\b/i, (r) => `${r} ${t}`);
36
41
  }
37
- function C(e, n = 0) {
42
+ function C(e, c, n = 0) {
38
43
  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 };
44
+ let r = 0;
45
+ const s = e.map((i) => {
46
+ if (!$.test(i) || t.has(Number(i)))
47
+ return null;
48
+ const d = Number(i);
49
+ return t.add(d), r = Math.max(r, d), d;
50
+ }), o = Number.isSafeInteger(n) && n > 0 && n < q ? n : 0;
51
+ let a = Math.max(c, r, o);
52
+ const u = s.map((i) => i === null), S = s.map((i) => i !== null ? i : (a += 1, a)), g = a > 0 && c !== a;
53
+ return { ids: S, reassigned: u, nextSeq: a, seqChanged: g, changed: g || u.includes(!0) };
54
+ }
55
+ function D(e) {
56
+ return e !== null && /^\d+$/.test(e) ? I(e) : 0;
57
+ }
58
+ function N(e, c, n) {
59
+ let t = "", r = 0;
60
+ return c.forEach((s, o) => {
61
+ const a = n[o] ?? null;
62
+ t += e.slice(r, s.index), t += a === null ? s.tag : M(s.tag, s.attrMatch, a), r = s.index + s.tag.length;
63
+ }), t + e.slice(r);
64
+ }
65
+ function P(e) {
66
+ return T(e).map((c) => c.rawValue);
67
+ }
68
+ function K(e, c) {
69
+ return N(e, T(e), c);
70
+ }
71
+ function O(e, c = 0) {
72
+ const n = T(e), t = C(n.map((s) => s.rawValue), b(e), c);
73
+ let r = N(
74
+ e,
75
+ n,
76
+ t.ids.map((s, o) => t.reassigned[o] ? s : null)
77
+ );
78
+ return t.seqChanged && (r = w(r, t.nextSeq)), { html: r, changed: t.changed, nextSeq: t.nextSeq };
49
79
  }
50
80
  export {
51
- g as TRACK_ID_ATTRIBUTE,
52
- $ as TRACK_SEQ_ATTRIBUTE,
53
- C as assignTrackingIds,
54
- P as readTrackFloor,
55
- M as readTrackSeq
81
+ l as TRACK_ID_ATTRIBUTE,
82
+ E as TRACK_SEQ_ATTRIBUTE,
83
+ O as assignTrackingIds,
84
+ D as parseTrackSeq,
85
+ C as planTrackingIds,
86
+ P as readAnchorTrackIds,
87
+ h as readTrackFloor,
88
+ b as readTrackSeq,
89
+ K as writeAnchorTrackIds
56
90
  };
@@ -1,108 +1,128 @@
1
- import { ITEMS_CURRENCY_ATTR as U, isCustomCurrencySymbol as Y } from "../extensions/Blocks/Items/constants/currency.js";
2
- import { productPairs as M } from "../extensions/Blocks/Items/enums/productEnums.js";
3
- import { escapeReplacement as B } from "../extensions/Blocks/Items/utils/nodeConfigUtils.js";
4
- import { preserveTextStyles as L } from "./preserveTextStyles.js";
1
+ import { isNewPriceFormatRoot as G, ITEMS_PRICE_FORMAT_ATTR as N, currencyPositionFromLocation as Y, ITEMS_CURRENCY_ATTR as U, isCustomCurrencySymbol as B } from "../extensions/Blocks/Items/constants/currency.js";
2
+ import { productPairs as k } from "../extensions/Blocks/Items/enums/productEnums.js";
3
+ import { escapeReplacement as v } from "../extensions/Blocks/Items/utils/nodeConfigUtils.js";
4
+ import { preserveTextStyles as w } from "./preserveTextStyles.js";
5
5
  import { unwrapProductNameLinks as X } from "./unwrapProductNameLink.js";
6
6
  const q = {
7
7
  CART_ITEMS: "ins_apr",
8
8
  BROWSED_ITEMS: "browsed_item",
9
9
  PURCHASED_ITEMS: "purchased_item"
10
- }, W = ($) => $.replaceAll("{%", "<!--{%").replaceAll("%}", "%}-->");
11
- function v($, C, A) {
12
- let d = C;
13
- for (; d > 0 && /\s/.test($[d - 1]); )
14
- d -= 1;
15
- return A.some((E) => $.endsWith(E, d));
10
+ }, W = (r) => r.replaceAll("{%", "<!--{%").replaceAll("%}", "%}-->");
11
+ function j(r, h, p) {
12
+ let u = h;
13
+ for (; u > 0 && /\s/.test(r[u - 1]); )
14
+ u -= 1;
15
+ return p.some((A) => r.endsWith(A, u));
16
16
  }
17
- const j = /(\s)href=(["'])(?:[^"']*#!|#)?\2/gi;
18
- function Q($, C) {
19
- var d;
20
- const A = $.ownerDocument.createTreeWalker($, NodeFilter.SHOW_COMMENT);
21
- for (let E = A.nextNode(); E; E = A.nextNode())
22
- (d = E.nodeValue) != null && d.includes("[if mso]") && (E.nodeValue = E.nodeValue.replace(j, (k, P) => `${P}href="${C}"`));
17
+ const Q = /(\s)href=(["'])(?:[^"']*#!|#)?\2/gi;
18
+ function z(r, h) {
19
+ var u;
20
+ const p = r.ownerDocument.createTreeWalker(r, NodeFilter.SHOW_COMMENT);
21
+ for (let A = p.nextNode(); A; A = p.nextNode())
22
+ (u = A.nodeValue) != null && u.includes("[if mso]") && (A.nodeValue = A.nodeValue.replace(Q, (L, P) => `${P}href="${h}"`));
23
23
  }
24
- function et($) {
25
- const C = W($), A = new DOMParser().parseFromString(C, "text/html");
26
- X(A);
27
- const d = M.PAIRS_FOR_EXTENSION;
28
- Object.entries(d).forEach(([o, p]) => {
29
- A.querySelectorAll(".ins-product-td").forEach((r) => {
30
- const _ = r.getAttribute("data-number") || "1", y = r.getAttribute("data-type") || "CART_ITEMS";
31
- r.querySelectorAll(`[product-attr="${o}"]`).forEach((t) => {
32
- var S, I, O, x;
33
- const m = t.getAttribute("data-type") || y, n = t.getAttribute("data-number") || _, f = p[m];
24
+ function J(r) {
25
+ return {
26
+ isFormatted: r.getAttribute("data-formated") === "true",
27
+ isSinglePrice: r.getAttribute("data-single_price") === "true",
28
+ currencyPosition: r.getAttribute(U.POSITION) || "before",
29
+ configuredSymbol: (r.getAttribute(U.SYMBOL) || "").trim()
30
+ };
31
+ }
32
+ function K(r) {
33
+ return {
34
+ isFormatted: !1,
35
+ isSinglePrice: r.getAttribute(N.SINGLE_PRICE) === "true",
36
+ currencyPosition: Y(
37
+ r.getAttribute(N.ALIGNMENT) ?? void 0
38
+ ),
39
+ configuredSymbol: (r.getAttribute(N.SYMBOL) || "").trim()
40
+ };
41
+ }
42
+ function Z(r, h, p) {
43
+ const { isFormatted: u, isSinglePrice: A, currencyPosition: L, configuredSymbol: P } = p;
44
+ let y;
45
+ A ? y = u ? r.SINGLE_PRICE_FORMATTED : r.SINGLE_PRICE : y = u ? r.PRICE_FORMATTED : r.PRICE;
46
+ const E = r.CURRENCY;
47
+ let F = `{{${y}_${h}}}`, R = "";
48
+ return B(P) ? R = P : E && (R = `{{${E}_${h}}}`), R && (F = L === "after" ? `${F} ${R}` : `${R} ${F}`), F;
49
+ }
50
+ function ct(r) {
51
+ const h = W(r), p = new DOMParser().parseFromString(h, "text/html");
52
+ X(p);
53
+ const u = k.PAIRS_FOR_EXTENSION;
54
+ Object.entries(u).forEach(([o, T]) => {
55
+ p.querySelectorAll(".ins-product-td").forEach((n) => {
56
+ const S = n.getAttribute("data-number") || "1", I = n.getAttribute("data-type") || "CART_ITEMS";
57
+ n.querySelectorAll(`[product-attr="${o}"]`).forEach((t) => {
58
+ var b, M, D, x;
59
+ const m = t.getAttribute("data-type") || I, c = t.getAttribute("data-number") || S, f = T[m];
34
60
  if (f)
35
61
  switch (o) {
36
62
  case "imageSrc": {
37
- let e = null, s = null;
38
- if (t.tagName === "IMG" ? (e = t, s = e.closest("a")) : (e = t.querySelector("img"), s = t.querySelector("a") || t.closest("a")), !e)
63
+ let e = null, i = null;
64
+ if (t.tagName === "IMG" ? (e = t, i = e.closest("a")) : (e = t.querySelector("img"), i = t.querySelector("a") || t.closest("a")), !e)
39
65
  break;
40
- const l = f.DEFAULT, c = f.ATTR;
41
- if (l && e.src) {
42
- const a = e.src;
43
- l.some((g) => {
44
- const u = g.split("/").pop() || "", H = a.split("/").pop() || "";
45
- return a.includes(g) || a.includes(u) || H === u;
46
- }) && (e.src = `{{${c}_${n}}}`);
66
+ const d = f.DEFAULT, a = f.ATTR;
67
+ if (d && e.src) {
68
+ const l = e.src;
69
+ d.some((C) => {
70
+ const $ = C.split("/").pop() || "", V = l.split("/").pop() || "";
71
+ return l.includes(C) || l.includes($) || V === $;
72
+ }) && (e.src = `{{${a}_${c}}}`);
47
73
  }
48
- const i = (I = (S = d.name) == null ? void 0 : S[m]) == null ? void 0 : I.ATTR;
49
- if (i && e.setAttribute("alt", `{{${i}_${n}}}`), s) {
50
- const a = (O = d.itemLink) == null ? void 0 : O[m];
51
- if (a) {
52
- const b = a.HREF, g = a.DEFAULT_HREF || "#!", u = s.href;
53
- (u === "#" || u === "" || u.endsWith("#!") || u.endsWith(g) || u === `${window.location.href}${g}` || !u || u === window.location.href) && (s.href = `{{${b}_${n}}}`);
74
+ const s = (M = (b = u.name) == null ? void 0 : b[m]) == null ? void 0 : M.ATTR;
75
+ if (s && e.setAttribute("alt", `{{${s}_${c}}}`), i) {
76
+ const l = (D = u.itemLink) == null ? void 0 : D[m];
77
+ if (l) {
78
+ const H = l.HREF, C = l.DEFAULT_HREF || "#!", $ = i.href;
79
+ ($ === "#" || $ === "" || $.endsWith("#!") || $.endsWith(C) || $ === `${window.location.href}${C}` || !$ || $ === window.location.href) && (i.href = `{{${H}_${c}}}`);
54
80
  }
55
81
  }
56
82
  break;
57
83
  }
58
84
  case "name": {
59
- const e = f, s = e.ATTR, l = e.DEFAULT_HREF || "#!", c = e.HREF;
60
- t.textContent && (t.innerHTML = L(t, `{{${s}_${n}}}`));
61
- const i = t.closest("a") || (t.tagName === "A" ? t : null);
62
- if (i && c) {
63
- const a = i.href, b = `${window.location.href}${l}`;
64
- (a === b || a.endsWith(l)) && (i.href = `{{${c}_${n}}}`);
85
+ const e = f, i = e.ATTR, d = e.DEFAULT_HREF || "#!", a = e.HREF;
86
+ t.textContent && (t.innerHTML = w(t, `{{${i}_${c}}}`));
87
+ const s = t.closest("a") || (t.tagName === "A" ? t : null);
88
+ if (s && a) {
89
+ const l = s.href, H = `${window.location.href}${d}`;
90
+ (l === H || l.endsWith(d)) && (s.href = `{{${a}_${c}}}`);
65
91
  }
66
92
  break;
67
93
  }
68
94
  case "price":
69
95
  case "originalPrice": {
70
- const e = f, s = t.getAttribute("data-formated"), l = t.getAttribute("data-single_price"), c = s === "true", i = l === "true", a = t.getAttribute(U.POSITION) || "before";
71
- let b;
72
- i ? b = c ? e.SINGLE_PRICE_FORMATTED : e.SINGLE_PRICE : b = c ? e.PRICE_FORMATTED : e.PRICE;
73
- const g = e.CURRENCY;
74
- let u = `{{${b}_${n}}}`;
75
- const H = (t.getAttribute(U.SYMBOL) || "").trim(), G = Y(H);
76
- let F = "";
77
- G ? F = H : g && (F = `{{${g}_${n}}}`), F && (u = a === "after" ? `${u} ${F}` : `${F} ${u}`), t.innerHTML = L(t, u);
96
+ const e = f, i = G(n) ? K(n) : J(t);
97
+ t.innerHTML = w(t, Z(e, c, i));
78
98
  break;
79
99
  }
80
100
  case "quantity": {
81
- const e = f, s = e.ATTR, l = [e.DEFAULT, ...e.LEGACY_DEFAULTS], c = (x = t.textContent) == null ? void 0 : x.trim();
82
- c && l.includes(c) && (t.innerHTML = L(t, `{{${s}_${n}}}`));
101
+ const e = f, i = e.ATTR, d = [e.DEFAULT, ...e.LEGACY_DEFAULTS], a = (x = t.textContent) == null ? void 0 : x.trim();
102
+ a && d.includes(a) && (t.innerHTML = w(t, `{{${i}_${c}}}`));
83
103
  break;
84
104
  }
85
105
  case "button": {
86
- const e = f, s = e.HREF, l = e.DEFAULT_HREF || "#!", c = t.tagName === "A" ? t : t.querySelector("a");
87
- if (c) {
88
- const i = c.href || "", a = `${window.location.href}${l}`;
89
- (i === "" || i === "#" || i === a || i.endsWith(l) || i.endsWith("#!") || i === window.location.href) && (c.href = `{{${s}_${n}}}`);
106
+ const e = f, i = e.HREF, d = e.DEFAULT_HREF || "#!", a = t.tagName === "A" ? t : t.querySelector("a");
107
+ if (a) {
108
+ const s = a.href || "", l = `${window.location.href}${d}`;
109
+ (s === "" || s === "#" || s === l || s.endsWith(d) || s.endsWith("#!") || s === window.location.href) && (a.href = `{{${i}_${c}}}`);
90
110
  }
91
- Q(t, `{{${s}_${n}}}`);
111
+ z(t, `{{${i}_${c}}}`);
92
112
  break;
93
113
  }
94
114
  case "itemLink": {
95
- const e = f, s = e.HREF, l = e.DEFAULT_HREF || "#!", c = t;
96
- if (c.href) {
97
- const i = c.href, a = `${window.location.href}${l}`;
98
- (i === a || i.endsWith(l)) && (c.href = `{{${s}_${n}}}`);
115
+ const e = f, i = e.HREF, d = e.DEFAULT_HREF || "#!", a = t;
116
+ if (a.href) {
117
+ const s = a.href, l = `${window.location.href}${d}`;
118
+ (s === l || s.endsWith(d)) && (a.href = `{{${i}_${c}}}`);
99
119
  }
100
120
  break;
101
121
  }
102
122
  default: {
103
123
  if ("ATTR" in f) {
104
124
  const e = f.ATTR;
105
- t.textContent && (t.innerHTML = L(t, `{{${e}_${n}}}`));
125
+ t.textContent && (t.innerHTML = w(t, `{{${e}_${c}}}`));
106
126
  }
107
127
  break;
108
128
  }
@@ -110,49 +130,49 @@ function et($) {
110
130
  });
111
131
  });
112
132
  });
113
- const E = C.match(/<!DOCTYPE[^>]*>/i), k = E ? `${E[0]}
114
- ` : "", P = A.querySelectorAll(".ins-product-td"), N = [];
133
+ const A = h.match(/<!DOCTYPE[^>]*>/i), L = A ? `${A[0]}
134
+ ` : "", P = p.querySelectorAll(".ins-product-td"), y = [];
115
135
  P.forEach((o) => {
116
- const p = o.getAttribute("data-type") || "CART_ITEMS", T = o.getAttribute("data-number") || "1", r = o.outerHTML;
117
- N.push({
136
+ const T = o.getAttribute("data-type") || "CART_ITEMS", _ = o.getAttribute("data-number") || "1", n = o.outerHTML;
137
+ y.push({
118
138
  element: o,
119
- outerHtml: r,
120
- type: p,
121
- number: T
139
+ outerHtml: n,
140
+ type: T,
141
+ number: _
122
142
  });
123
143
  });
124
- let h = k + A.documentElement.outerHTML;
125
- N.reverse().forEach(({ outerHtml: o, type: p, number: T }) => {
126
- const r = q[p], _ = r ? `${r}_total_product_kind` : "";
127
- if (_) {
128
- const R = parseInt(T) - 1, n = `${`{% if ${_} > ${R} %}`}${o}{% endif %}`;
129
- h = h.replace(o, B(n));
144
+ let E = L + p.documentElement.outerHTML;
145
+ y.reverse().forEach(({ outerHtml: o, type: T, number: _ }) => {
146
+ const n = q[T], S = n ? `${n}_total_product_kind` : "";
147
+ if (S) {
148
+ const g = parseInt(_) - 1, c = `${`{% if ${S} > ${g} %}`}${o}{% endif %}`;
149
+ E = E.replace(o, v(c));
130
150
  }
131
151
  });
132
- const V = A.querySelectorAll('[product-attr="originalPrice"][data-type]'), w = /* @__PURE__ */ new Map(), D = /* @__PURE__ */ new Set();
133
- return V.forEach((o) => {
152
+ const F = p.querySelectorAll('[product-attr="originalPrice"][data-type]'), R = /* @__PURE__ */ new Map(), O = /* @__PURE__ */ new Set();
153
+ return F.forEach((o) => {
134
154
  var t;
135
- const p = o.getAttribute("data-number"), T = o.getAttribute("data-type");
136
- if (!p || !q[T])
155
+ const T = o.getAttribute("data-number"), _ = o.getAttribute("data-type");
156
+ if (!T || !q[_])
137
157
  return;
138
- const r = o.closest(".product-original-price-class");
139
- if (!r || D.has(r))
158
+ const n = o.closest(".product-original-price-class");
159
+ if (!n || O.has(n))
140
160
  return;
141
- D.add(r);
142
- const _ = r.outerHTML, y = (t = o.closest(".ins-product-td")) == null ? void 0 : t.getAttribute("data-nodup"), R = w.get(_) ?? { number: p, type: T, wrap: [] };
143
- R.wrap.push(y !== "false"), w.set(_, R);
144
- }), w.forEach(({ number: o, type: p, wrap: T }, r) => {
145
- if (r.includes("{% if") || !T.some(Boolean))
161
+ O.add(n);
162
+ const S = n.outerHTML, I = (t = o.closest(".ins-product-td")) == null ? void 0 : t.getAttribute("data-nodup"), g = R.get(S) ?? { number: T, type: _, wrap: [] };
163
+ g.wrap.push(I !== "false"), R.set(S, g);
164
+ }), R.forEach(({ number: o, type: T, wrap: _ }, n) => {
165
+ if (n.includes("{% if") || !_.some(Boolean))
146
166
  return;
147
- const _ = M.PAIRS_FOR_EXTENSION.price[p].PRICE, y = M.PAIRS_FOR_EXTENSION.originalPrice[p].PRICE, R = `{% if ${_}_${o} != ${y}_${o} %}`, t = [R, W(R)];
148
- let m = "", n = 0, f = 0, S = h.indexOf(r);
149
- for (; S !== -1; ) {
150
- const I = T[f] === !0 && !v(h, S, t);
151
- m += h.slice(n, S) + (I ? `${R}${r}{% endif %}` : r), n = S + r.length, f += 1, S = h.indexOf(r, n);
167
+ const S = k.PAIRS_FOR_EXTENSION.price[T].PRICE, I = k.PAIRS_FOR_EXTENSION.originalPrice[T].PRICE, g = `{% if ${S}_${o} != ${I}_${o} %}`, t = [g, W(g)];
168
+ let m = "", c = 0, f = 0, b = E.indexOf(n);
169
+ for (; b !== -1; ) {
170
+ const M = _[f] === !0 && !j(E, b, t);
171
+ m += E.slice(c, b) + (M ? `${g}${n}{% endif %}` : n), c = b + n.length, f += 1, b = E.indexOf(n, c);
152
172
  }
153
- h = m + h.slice(n);
154
- }), h.replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}").replaceAll("&lt;!--{%", "{%").replaceAll("%}--&gt;", "%}");
173
+ E = m + E.slice(c);
174
+ }), E.replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}").replaceAll("&lt;!--{%", "{%").replaceAll("%}--&gt;", "%}");
155
175
  }
156
176
  export {
157
- et as pairProductVariables
177
+ ct as pairProductVariables
158
178
  };
@@ -1,5 +1,6 @@
1
- import { useActionsApi as E } from "../composables/useActionsApi.js";
2
- import { useConfig as F } from "../composables/useConfig.js";
1
+ import { useActionsApi as x } from "../composables/useActionsApi.js";
2
+ import { useConfig as D } from "../composables/useConfig.js";
3
+ import { useEditorTrackingIds as F } from "../composables/useEditorTrackingIds.js";
3
4
  import { useHtmlCompiler as I } from "../composables/useHtmlCompiler.js";
4
5
  import { useRecommendationExtensionStore as b } from "../extensions/Blocks/Recommendation/store/recommendation.js";
5
6
  import { toBlockUrlConfig as R } from "../extensions/Blocks/Recommendation/utils/blockUrlConfig.js";
@@ -7,10 +8,9 @@ import { DATA_ATTRIBUTES as g } from "../extensions/Blocks/Unsubscribe/utils/con
7
8
  import { parsePageList as U } from "../extensions/Blocks/Unsubscribe/utils/utils.js";
8
9
  import { useDynamicContentStore as L } from "../stores/dynamic-content.js";
9
10
  import { useEditorStore as N } from "../stores/editor.js";
10
- import { useUnsubscribeStore as v } from "../stores/unsubscribe.js";
11
- import { isPlainObject as z } from "./genericUtil.js";
12
- import { assignTrackingIds as M } from "./linkTrackingIds.js";
13
- function O(n) {
11
+ import { useUnsubscribeStore as z } from "../stores/unsubscribe.js";
12
+ import { isPlainObject as v } from "./genericUtil.js";
13
+ function M(n) {
14
14
  const r = new DOMParser().parseFromString(n, "text/html").querySelectorAll(`[${g.PAGE_LIST}]`), e = [];
15
15
  return r.forEach((i) => {
16
16
  const t = i.getAttribute(g.PAGE_LIST);
@@ -26,16 +26,16 @@ async function S(n) {
26
26
  const i = e.getAttribute("recommendation-id"), t = i ? Number(i) : NaN;
27
27
  if (!Number.isFinite(t))
28
28
  return;
29
- const m = e.getAttribute("esd-ext-config");
30
- if (!m)
29
+ const c = e.getAttribute("esd-ext-config");
30
+ if (!c)
31
31
  return;
32
32
  let a;
33
33
  try {
34
- a = JSON.parse(m);
34
+ a = JSON.parse(c);
35
35
  } catch {
36
36
  return;
37
37
  }
38
- z(a) && r.seedBlockUrlConfig(t, R(a));
38
+ v(a) && r.seedBlockUrlConfig(t, R(a));
39
39
  });
40
40
  try {
41
41
  await r.fetchRecommendationCreateData();
@@ -46,40 +46,37 @@ async function S(n) {
46
46
  );
47
47
  }
48
48
  }
49
- const Z = () => {
50
- const n = L(), c = N(), o = v(), { getCompiledEmail: r, getTemplateData: e, updateHtmlAndCss: i } = E(), { compileHtml: t, compileAmpHtml: m } = I(), { isFeatureEnabled: a } = F();
49
+ const Y = () => {
50
+ const n = L(), s = N(), o = z(), { getCompiledEmail: r, getTemplateData: e } = x(), { writeTrackingIds: i } = F(), { compileHtml: t, compileAmpHtml: c } = I(), { isFeatureEnabled: a } = D();
51
51
  return {
52
52
  prepareTemplateDetails: async (h) => {
53
- let { html: s, css: u, syncModulesIds: y = [] } = h ?? await e();
54
- if (a("linkTrackingIds"))
55
- try {
56
- const { html: d, changed: x, nextSeq: D } = M(s, c.trackIdSessionFloor);
57
- c.trackIdSessionFloor = D, x && (s = d, await i(d, u));
58
- } catch (d) {
59
- console.error("Tracking-id step failed, saving anyway:", d);
60
- }
61
- const { html: T, ampHtml: p = "", ampErrors: A = [] } = await r({
53
+ let { html: m, css: p, syncModulesIds: u = [] } = h ?? await e();
54
+ if (a("linkTrackingIds")) {
55
+ const { changed: P, nextSeq: E } = i(s.trackIdSessionFloor);
56
+ s.trackIdSessionFloor = E, P && ({ html: m, css: p, syncModulesIds: u = [] } = await e());
57
+ }
58
+ const { html: T, ampHtml: d = "", ampErrors: w = [] } = await r({
62
59
  minimize: !0,
63
60
  resetDataSavedFlag: !1
64
61
  });
65
- o.selectedUnsubscribePages.length && await o.fetchTemplates(), await S(s);
66
- const { compiledHtml: w, stats: l, appliedRules: C } = t(T), H = p && m(p).compiledHtml, k = n.getSelectedDynamicContentList, P = b(), f = O(s);
62
+ o.selectedUnsubscribePages.length && await o.fetchTemplates(), await S(m);
63
+ const { compiledHtml: A, stats: l, appliedRules: y } = t(T), C = d && c(d).compiledHtml, k = n.getSelectedDynamicContentList, H = b(), f = M(m);
67
64
  return console.debug("HTML Compilation Stats:", {
68
65
  originalSize: l.originalSize,
69
66
  compiledSize: l.compiledSize,
70
67
  reduction: `${l.reductionPercentage.toFixed(2)}%`,
71
- appliedRules: C,
68
+ appliedRules: y,
72
69
  executionTime: `${l.executionTime.toFixed(2)}ms`
73
70
  }), {
74
71
  dynamicContentList: k,
75
- compiledHtml: w,
76
- rawHtml: s,
77
- css: u,
78
- ampHtml: H,
79
- ampErrors: A,
80
- modules: y.map(Number),
72
+ compiledHtml: A,
73
+ rawHtml: m,
74
+ css: p,
75
+ ampHtml: C,
76
+ ampErrors: w,
77
+ modules: u.map(Number),
81
78
  recommendation: {
82
- campaignUrls: P.recommendationCampaignUrls,
79
+ campaignUrls: H.recommendationCampaignUrls,
83
80
  configs: {}
84
81
  },
85
82
  unsubscribe: {
@@ -94,6 +91,6 @@ const Z = () => {
94
91
  };
95
92
  };
96
93
  export {
97
- O as getHtmlReferencedUnsubscribePages,
98
- Z as useTemplatePreparation
94
+ M as getHtmlReferencedUnsubscribePages,
95
+ Y as useTemplatePreparation
99
96
  };
@@ -0,0 +1,10 @@
1
+ const E = /(<[a-z][\w:-]*(?:\s[^>]*?)?\shref\s*=\s*)(["'])([\s\S]*?)\2/gi, c = /^(?:\s|&nbsp;|&#160;|&#xa0;)+|(?:\s|&nbsp;|&#160;|&#xa0;)+$/gi;
2
+ function a(e) {
3
+ return !e || !/href/i.test(e) ? e : e.replace(E, (i, s, r, n) => {
4
+ const t = n.replace(c, "");
5
+ return `${s}${r}${t}${r}`;
6
+ });
7
+ }
8
+ export {
9
+ a as trimHrefWhitespace
10
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useinsider/guido",
3
- "version": "3.24.0",
3
+ "version": "3.25.0",
4
4
  "description": "Guido is a Vue + TypeScript wrapper for Email Plugin. Easily embed the email editor in your Vue applications.",
5
5
  "main": "./dist/guido.umd.cjs",
6
6
  "module": "./dist/library.js",