@useinsider/guido 3.24.0-beta.003db4c → 3.24.0-beta.0aa04e8

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.
@@ -1,239 +1,114 @@
1
- import { CURRENCY_ATTR as _, CSS_CLASS_SKIP_COMPILE as v } from "../../../extensions/Blocks/Recommendation/constants/selectors.js";
2
- const A = "You May Also Like!";
3
- function z(t) {
4
- var r;
5
- const e = t.querySelector(".ext-recommendation-title");
6
- if (!e)
7
- return A;
8
- const o = (r = e.textContent) == null ? void 0 : r.trim();
9
- return o && o.length > 0 ? o : A;
10
- }
11
- function L(t) {
12
- const e = t.querySelector(".ext-recommendation-title");
13
- return e ? !/display\s*:\s*none/i.test(e.getAttribute("style") ?? "") : !1;
14
- }
15
- function X(t) {
16
- var o;
17
- const e = t.querySelector(".ext-recommendation-title");
18
- return !!e && !((o = e == null ? void 0 : e.textContent) != null && o.trim());
19
- }
20
- function K(t) {
21
- const e = t.querySelector(".ext-product-price"), o = t.querySelector(".ext-product-original-price");
22
- return !e || !o ? !1 : e.compareDocumentPosition(o) === Node.DOCUMENT_POSITION_PRECEDING;
23
- }
24
- function E(t) {
25
- return /(?:^|;)\s*display\s*:\s*table-cell/i.test(t.getAttribute("style") ?? "");
26
- }
27
- function H(t) {
28
- var r, n;
29
- const e = (r = t.querySelector(".ext-product-price")) == null ? void 0 : r.closest("tr"), o = (n = t.querySelector(".ext-product-original-price")) == null ? void 0 : n.closest("tr");
30
- return !e || !o || e === o ? !1 : !E(e) && !E(o);
31
- }
32
- const P = ["font-family", "font-size", "font-weight", "font-style"], O = /^(#[0-9a-f]{3,8}|(rgb|hsl)a?\([\d\s.,%/]+\)|[a-z]+)$/i, q = /^(\d+(?:\.\d+)?)(px)?$/;
33
- function l(t) {
34
- const e = {};
35
- return ((t == null ? void 0 : t.getAttribute("style")) ?? "").split(";").forEach((o) => {
36
- const r = o.indexOf(":"), n = o.slice(0, r).trim().toLowerCase(), i = o.slice(r + 1).replace(/!important/i, "").trim();
37
- r > 0 && n && i && (e[n] = i);
38
- }), e;
39
- }
40
- function d(t) {
41
- const e = t == null ? void 0 : t.trim().match(q);
42
- return e ? Number(e[1]) : void 0;
43
- }
44
- function a(t) {
45
- return t && O.test(t.trim()) ? t.trim() : void 0;
46
- }
47
- const w = /* @__PURE__ */ new Map([
1
+ import { CURRENCY_ATTR as l, CSS_CLASS_SKIP_COMPILE as m } from "../../../extensions/Blocks/Recommendation/constants/selectors.js";
2
+ const a = "You May Also Like!";
3
+ function C(e) {
4
+ var n;
5
+ const r = e.querySelector(".ext-recommendation-title");
6
+ if (!r)
7
+ return a;
8
+ const t = (n = r.textContent) == null ? void 0 : n.trim();
9
+ return t && t.length > 0 ? t : a;
10
+ }
11
+ function A(e) {
12
+ const r = e.querySelector(".ext-recommendation-title");
13
+ return r ? !/display\s*:\s*none/i.test(r.getAttribute("style") ?? "") : !1;
14
+ }
15
+ function _(e) {
16
+ var t;
17
+ const r = e.querySelector(".ext-recommendation-title");
18
+ return !!r && !((t = r == null ? void 0 : r.textContent) != null && t.trim());
19
+ }
20
+ function E(e) {
21
+ const r = e.querySelector(".ext-product-price"), t = e.querySelector(".ext-product-original-price");
22
+ return !r || !t ? !1 : r.compareDocumentPosition(t) === Node.DOCUMENT_POSITION_PRECEDING;
23
+ }
24
+ function d(e) {
25
+ return /(?:^|;)\s*display\s*:\s*table-cell/i.test(e.getAttribute("style") ?? "");
26
+ }
27
+ function T(e) {
28
+ var n, o;
29
+ const r = (n = e.querySelector(".ext-product-price")) == null ? void 0 : n.closest("tr"), t = (o = e.querySelector(".ext-product-original-price")) == null ? void 0 : o.closest("tr");
30
+ return !r || !t || r === t ? !1 : !d(r) && !d(t);
31
+ }
32
+ const p = /* @__PURE__ */ new Map([
48
33
  ["p_name", ".ext-product-name p"],
49
34
  ["p_price", ".ext-product-price p"],
50
35
  ["p_original_price", ".ext-product-original-price p"]
51
36
  ]);
52
- function B(t) {
53
- return a(l(t).color);
37
+ function f(e) {
38
+ const r = ((e == null ? void 0 : e.getAttribute("style")) ?? "").match(/(?:^|;)\s*color\s*:\s*([^;]+)/i);
39
+ return (r == null ? void 0 : r[1].trim()) || void 0;
54
40
  }
55
- const I = "ins-trim-text";
56
- function J(t, e) {
57
- return t == null ? void 0 : t.map((o) => {
41
+ const x = "ins-trim-text";
42
+ function h(e, r) {
43
+ return e == null ? void 0 : e.map((t) => {
58
44
  var s, u;
59
- const r = w.get(o.variable ?? "");
60
- if (!r)
61
- return o;
62
- const n = e.querySelector(r), i = (u = (s = o.theme) == null ? void 0 : s.textColor) != null && u.color ? void 0 : B(n), c = o.variable === "p_name" && (n == null ? void 0 : n.classList.contains(I));
63
- return !i && !c ? o : {
64
- ...o,
45
+ const n = p.get(t.variable ?? "");
46
+ if (!n)
47
+ return t;
48
+ const o = r.querySelector(n), c = (u = (s = t.theme) == null ? void 0 : s.textColor) != null && u.color ? void 0 : f(o), i = t.variable === "p_name" && (o == null ? void 0 : o.classList.contains(x));
49
+ return !c && !i ? t : {
50
+ ...t,
65
51
  theme: {
66
- ...o.theme,
67
- ...i ? { textColor: { color: i } } : {},
68
- ...c ? { textTrimming: !0 } : {}
52
+ ...t.theme,
53
+ ...c ? { textColor: { color: c } } : {},
54
+ ...i ? { textTrimming: !0 } : {}
69
55
  }
70
56
  };
71
57
  });
72
58
  }
73
- function Q(t) {
74
- const e = [
75
- t,
76
- ...Array.from(t.querySelectorAll(".product-card, .ext-recommendation-card"))
59
+ function R(e) {
60
+ const r = [
61
+ e,
62
+ ...Array.from(e.querySelectorAll(".product-card, .ext-recommendation-card"))
77
63
  ];
78
- let o = "";
79
- return e.some((r) => {
80
- const n = r.getAttribute("bgcolor");
81
- if (n && n.trim())
82
- return o = n.trim(), !0;
83
- const c = (r.getAttribute("style") ?? "").match(/background-color\s*:\s*([^;]+)/i);
84
- return c && c[1] ? (o = c[1].trim(), !0) : !1;
85
- }), o;
86
- }
87
- function W(t) {
88
- const e = t.getAttribute(_.CURRENCY), o = t.getAttribute(_.SYMBOL);
64
+ let t = "";
65
+ return r.some((n) => {
66
+ const o = n.getAttribute("bgcolor");
67
+ if (o && o.trim())
68
+ return t = o.trim(), !0;
69
+ const i = (n.getAttribute("style") ?? "").match(/background-color\s*:\s*([^;]+)/i);
70
+ return i && i[1] ? (t = i[1].trim(), !0) : !1;
71
+ }), t;
72
+ }
73
+ function L(e) {
74
+ const r = e.getAttribute(l.CURRENCY), t = e.getAttribute(l.SYMBOL);
89
75
  return {
90
- ...e ? { value: e } : {},
76
+ ...r ? { value: r } : {},
91
77
  // An empty `currency-symbol` is omitted so `mapCurrency` falls back to
92
78
  // the currency code as the symbol.
93
- ...o ? { symbol: o } : {},
79
+ ...t ? { symbol: t } : {},
94
80
  alignment: 1,
95
81
  decimalCount: "2",
96
82
  decimalSeparator: ",",
97
83
  thousandSeparator: "."
98
84
  };
99
85
  }
100
- const N = /^es-p(\d+)([trbl]?)$/, D = { t: "top", r: "right", b: "bottom", l: "left" };
101
- function Z(t) {
102
- const e = t.querySelector("td.esd-structure.esd-extension-internal-block");
103
- if (!e)
86
+ const S = /^es-p(\d+)([trbl]?)$/, g = { t: "top", r: "right", b: "bottom", l: "left" };
87
+ function P(e) {
88
+ const r = e.querySelector("td.esd-structure.esd-extension-internal-block");
89
+ if (!r)
104
90
  return;
105
- const o = { top: 0, right: 0, bottom: 0, left: 0 };
106
- return e.classList.forEach((r) => {
107
- const n = r.match(N);
108
- if (!n)
91
+ const t = { top: 0, right: 0, bottom: 0, left: 0 };
92
+ return r.classList.forEach((n) => {
93
+ const o = n.match(S);
94
+ if (!o)
109
95
  return;
110
- const i = Number(n[1]), c = n[2];
111
- c ? o[D[c]] = i : Object.assign(o, { top: i, right: i, bottom: i, left: i });
112
- }), o;
113
- }
114
- function f(t) {
115
- const e = (t.padding ?? "").split(/\s+/).filter(Boolean).map(d), o = e.every((u) => u !== void 0) ? e : [], r = o[0] ?? 0, n = o[1] ?? r, i = o[2] ?? r, c = o[3] ?? n, s = {
116
- top: d(t["padding-top"]) ?? r,
117
- right: d(t["padding-right"]) ?? n,
118
- bottom: d(t["padding-bottom"]) ?? i,
119
- left: d(t["padding-left"]) ?? c
120
- };
121
- return Object.values(s).some(Boolean) ? s : void 0;
122
- }
123
- function k(t, e) {
124
- return !t || !e ? t ?? e : {
125
- top: t.top + e.top,
126
- right: t.right + e.right,
127
- bottom: t.bottom + e.bottom,
128
- left: t.left + e.left
129
- };
130
- }
131
- function h(t) {
132
- const e = Object.fromEntries(P.filter((o) => t[o]).map((o) => [o, t[o]]));
133
- return Object.keys(e).length ? e : void 0;
134
- }
135
- function g(t) {
136
- return t === void 0 ? void 0 : { top: t, right: t, bottom: t, left: t };
137
- }
138
- function x(t) {
139
- const e = Object.entries(t).filter(([, o]) => o !== void 0);
140
- return e.length ? Object.fromEntries(e) : void 0;
141
- }
142
- function p(t) {
143
- const e = t.querySelector("p"), o = l(t), r = l(e ?? t), n = a(r.color), i = a(o["background-color"]), c = k(f(o), e ? f(r) : void 0), s = t.getAttribute("align");
144
- return x({
145
- textStyle: h(r),
146
- textColor: n ? { color: n } : void 0,
147
- textBackgroundColor: i ? { color: i } : void 0,
148
- textPadding: c ? { desktop: c } : void 0,
149
- textLineSpacing: r["line-height"] ? { lineSpacing: r["line-height"] } : void 0,
150
- textAlign: s ? { align: s } : void 0
151
- });
152
- }
153
- function M(t) {
154
- const e = d(t["border-width"]), o = t["border-style"], r = a(t["border-color"]);
155
- if (!(e === void 0 && !o && !r))
156
- return { width: g(e), style: g(o), color: g(r) };
157
- }
158
- function F(t) {
159
- var C;
160
- const e = l(t.querySelector(".es-button-border")), o = t.querySelector("a"), r = l(o), n = (C = o == null ? void 0 : o.textContent) == null ? void 0 : C.trim(), i = a(e["background-color"] ?? e.background ?? r["background-color"] ?? r.background), c = a(r.color), s = d(e["border-radius"] ?? r["border-radius"]), u = f(r), S = f(l(t)), y = t.getAttribute("align"), { display: m } = e;
161
- return x({
162
- buttonText: n ? { text: n } : void 0,
163
- buttonStyle: h(r),
164
- buttonColor: i ? { color: i } : void 0,
165
- textButtonColor: c ? { color: c } : void 0,
166
- buttonBorder: M(e),
167
- buttonBorderRadius: s === void 0 ? void 0 : { radius: s },
168
- buttonInternalPadding: u ? { desktop: u } : void 0,
169
- buttonExternalPadding: S ? { desktop: S } : void 0,
170
- buttonStretch: m === "block" || m === "inline-block" ? { stretched: m === "block" } : void 0,
171
- buttonAlign: y ? { align: y } : void 0
172
- });
173
- }
174
- function Y(t) {
175
- const e = t.querySelector("img"), o = d(e == null ? void 0 : e.getAttribute("width")), r = d(e == null ? void 0 : e.getAttribute("height"));
176
- return o === void 0 && r === void 0 ? void 0 : { imageSize: { width: o, height: r } };
177
- }
178
- const j = [
179
- ["p_image", ".ext-product-image", !1, Y],
180
- ["p_name", ".ext-product-name", !1, p],
181
- ["p_original_price", ".ext-product-original-price", !1, p],
182
- ["p_price", ".ext-product-price", !1, p],
183
- ["p_omnibus_price", ".ext-product-omnibus-price", !0, p],
184
- ["p_omnibus_discount", ".ext-product-omnibus-discount", !0, p],
185
- ["p_button", ".ext-product-button", !1, F]
186
- ];
187
- function b(t, e) {
188
- return e ? { ...t, theme: e } : t;
189
- }
190
- function G(t) {
191
- const e = t.querySelector(".ext-recommendation-title");
192
- if (!e)
193
- return [];
194
- const o = l(e.querySelector("p") ?? e), r = a(o.color), n = x({ textStyle: h(o), textColor: r ? { color: r } : void 0 });
195
- return [b({ variable: "p_recommendation_title", hidden: !L(t) }, n)];
196
- }
197
- function U(t) {
198
- const e = j.flatMap(([n, i, c, s]) => {
199
- const u = t.querySelector(i);
200
- return u ? [b({ variable: n, hidden: c }, s(u))] : [];
201
- }), o = t.querySelectorAll(".ext-ins-attr p[product-attr]"), r = Array.from(o, (n, i) => b({
202
- variable: `p_attribute_${i}`,
203
- variableType: "p_attribute",
204
- value: n.getAttribute("product-attr") ?? "",
205
- hidden: !1
206
- }, p(n.closest(".ext-ins-attr") ?? n)));
207
- return [...e, ...r];
208
- }
209
- const R = "td.product-card", T = (t) => t.querySelectorAll(R).length;
210
- function V(t, e) {
211
- let o = e.parentElement;
212
- for (; o && o !== t && T(o) < 2; )
213
- o = o.parentElement;
214
- return !o || o === t ? 0 : o.tagName === "TBODY" || o.tagName === "TABLE" ? 1 : T(o);
215
- }
216
- function tt(t) {
217
- const e = t.querySelectorAll(R), [o] = e, r = o ? V(t, o) : 0, n = o ? U(o) : [];
218
- return {
219
- ...e.length ? { totalCount: e.length } : {},
220
- ...r ? { rowCount: r } : {},
221
- composition: { variables: n.length ? [...G(t), ...n] : [] }
222
- };
96
+ const c = Number(o[1]), i = o[2];
97
+ i ? t[g[i]] = c : Object.assign(t, { top: c, right: c, bottom: c, left: c });
98
+ }), t;
223
99
  }
224
- function et(t) {
225
- return t.classList.contains(v);
100
+ function I(e) {
101
+ return e.classList.contains(m);
226
102
  }
227
103
  export {
228
- Q as extractCardBgColor,
229
- W as extractCurrencyFromBlock,
230
- Z as extractRenderedBlockPadding,
231
- z as extractTitleText,
232
- X as hasEmptyTitle,
233
- L as hasVisibleTitle,
234
- tt as inferLegacyConfig,
235
- K as isOldPriceFirst,
236
- et as isPartnerManagedBlock,
237
- H as isPriceOnNextLine,
238
- J as withRenderedTextTheme
104
+ R as extractCardBgColor,
105
+ L as extractCurrencyFromBlock,
106
+ P as extractRenderedBlockPadding,
107
+ C as extractTitleText,
108
+ _ as hasEmptyTitle,
109
+ A as hasVisibleTitle,
110
+ E as isOldPriceFirst,
111
+ I as isPartnerManagedBlock,
112
+ T as isPriceOnNextLine,
113
+ h as withRenderedTextTheme
239
114
  };
@@ -1,35 +1,33 @@
1
- const s = "esd-dev-product-config";
2
- function a(t) {
3
- return t.replace(/&#x27;/g, "'").replace(/&#x2F;/g, "/").replace(/&apos;/g, "'").replace(/&quot;/g, '"').replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&");
1
+ function c(e) {
2
+ return e.replace(/&#x27;/g, "'").replace(/&#x2F;/g, "/").replace(/&apos;/g, "'").replace(/&quot;/g, '"').replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&");
4
3
  }
5
- function o(t) {
6
- const e = t.getAttribute(s);
7
- if (!e)
4
+ function s(e) {
5
+ const t = e.getAttribute("esd-dev-product-config");
6
+ if (!t)
8
7
  return null;
9
8
  try {
10
- const n = a(a(e));
9
+ const n = c(c(t));
11
10
  return JSON.parse(n);
12
11
  } catch {
13
12
  return null;
14
13
  }
15
14
  }
16
- function i(t) {
17
- const e = t.getAttribute("ins-recommendation-v3-campaign-id");
18
- if (e) {
19
- const r = parseInt(e);
15
+ function i(e) {
16
+ const t = e.getAttribute("ins-recommendation-v3-campaign-id");
17
+ if (t) {
18
+ const r = parseInt(t);
20
19
  if (!Number.isNaN(r))
21
20
  return r;
22
21
  }
23
- const c = (t.getAttribute("class") ?? "").match(/ins-recommendation-v3-block-(\d+)/);
24
- if (c) {
25
- const r = parseInt(c[1]);
22
+ const a = (e.getAttribute("class") ?? "").match(/ins-recommendation-v3-block-(\d+)/);
23
+ if (a) {
24
+ const r = parseInt(a[1]);
26
25
  if (!Number.isNaN(r))
27
26
  return r;
28
27
  }
29
28
  return null;
30
29
  }
31
30
  export {
32
- s as LEGACY_CONFIG_ATTR,
33
- o as parseLegacyConfig,
31
+ s as parseLegacyConfig,
34
32
  i as parseRecommendationId
35
33
  };
@@ -1,69 +1,59 @@
1
1
  import { BlockId as b } from "../../enums/block.js";
2
- import { DEFAULT_NODE_CONFIG as M } from "../../extensions/Blocks/Recommendation/constants/defaultConfig.js";
3
- import { ATTR_RECOMMENDATION_TITLE as u } from "../../extensions/Blocks/Recommendation/constants/selectors.js";
4
- import { useTemplateStore as x } from "../../stores/template.js";
5
- import { mapComposition as L } from "./recommendation/compositionMapper.js";
6
- import { inferLegacyConfig as A, isPriceOnNextLine as B, extractCurrencyFromBlock as E, isOldPriceFirst as S, withRenderedTextTheme as w, extractTitleText as P, hasEmptyTitle as H, hasVisibleTitle as O, extractCardBgColor as _, isPartnerManagedBlock as I, extractRenderedBlockPadding as N } from "./recommendation/extractors.js";
7
- import { buildBlockHtml as F } from "./recommendation/htmlBuilder.js";
8
- import { LEGACY_CONFIG_ATTR as m, parseRecommendationId as $, parseLegacyConfig as k } from "./recommendation/parseLegacyConfig.js";
9
- import { mapSettings as D } from "./recommendation/settingsMapper.js";
10
- import { mapBlockPadding as G } from "./recommendation/themeMapper.js";
11
- const V = [
12
- `td[${m}][class*="ins-recommendation-v3-block-"]:not(.recommendation-block-v2)`,
13
- `td.product-block[esd-handler-name*="EmailRecommendationV3"][${m}]:not(.recommendation-block-v2)`,
14
- `td.product-block[class*="ins-recommendation-v3-block-"]:not([${m}]):not([esd-ext-config]):not(.recommendation-block-v2)`
15
- ].join(", "), U = /{{\s*\d+_\d+_/, T = (i) => {
16
- var e;
17
- return !!((e = i.getAttribute(m)) != null && e.trim());
18
- };
19
- function q(i, e, s) {
20
- var g, p, f;
21
- const o = $(e);
22
- if (o === null)
2
+ import { DEFAULT_NODE_CONFIG as C } from "../../extensions/Blocks/Recommendation/constants/defaultConfig.js";
3
+ import { ATTR_RECOMMENDATION_TITLE as f } from "../../extensions/Blocks/Recommendation/constants/selectors.js";
4
+ import { useTemplateStore as M } from "../../stores/template.js";
5
+ import { mapComposition as x } from "./recommendation/compositionMapper.js";
6
+ import { isPriceOnNextLine as R, extractCurrencyFromBlock as h, isOldPriceFirst as S, withRenderedTextTheme as w, extractTitleText as E, hasEmptyTitle as L, hasVisibleTitle as B, extractCardBgColor as P, isPartnerManagedBlock as A, extractRenderedBlockPadding as H } from "./recommendation/extractors.js";
7
+ import { buildBlockHtml as N } from "./recommendation/htmlBuilder.js";
8
+ import { parseRecommendationId as O, parseLegacyConfig as F } from "./recommendation/parseLegacyConfig.js";
9
+ import { mapSettings as I } from "./recommendation/settingsMapper.js";
10
+ import { mapBlockPadding as _ } from "./recommendation/themeMapper.js";
11
+ const k = 'td[esd-dev-product-config][class*="ins-recommendation-v3-block-"]:not(.recommendation-block-v2), td.product-block[esd-handler-name*="EmailRecommendationV3"][esd-dev-product-config]:not(.recommendation-block-v2)';
12
+ function $(c, e, m) {
13
+ var l, g, p;
14
+ const t = O(e);
15
+ if (t === null)
23
16
  return console.warn(
24
17
  "[RecommendationMigrator] Skipping block — missing/invalid `ins-recommendation-v3-campaign-id`"
25
18
  ), !1;
26
- const a = T(e), r = a ? k(e) : A(e);
19
+ const r = F(e);
27
20
  if (!r)
28
21
  return console.warn(
29
- `[RecommendationMigrator] Aborting block id=${o} — \`esd-dev-product-config\` unable to be parsed`
22
+ `[RecommendationMigrator] Aborting block id=${t} — \`esd-dev-product-config\` missing or unable to be parsed`
30
23
  ), !1;
31
- a || console.info(
32
- `[RecommendationMigrator] Block id=${o} has no \`esd-dev-product-config\`, inferred from the html`
33
- );
34
- const t = s[String(o)] ?? {}, c = {
35
- ...t,
36
- currencySettings: t.currencySettings ?? E(e),
37
- isPriceMovedToNextLine: t.isPriceMovedToNextLine ?? B(e)
38
- }, y = D(c, r, o), n = L(
39
- w((g = r.composition) == null ? void 0 : g.variables, e),
24
+ const o = m[String(t)] ?? {}, n = {
25
+ ...o,
26
+ currencySettings: o.currencySettings ?? h(e),
27
+ isPriceMovedToNextLine: o.isPriceMovedToNextLine ?? R(e)
28
+ }, a = I(n, r, t), i = x(
29
+ w((l = r.composition) == null ? void 0 : l.variables, e),
40
30
  { oldPriceFirst: S(e) }
41
- ), C = P(e);
42
- H(e) ? n.visibility[u] = !1 : n.titleVariable || (n.visibility[u] = O(e));
43
- const v = _(e), h = {
44
- ...y,
31
+ ), u = E(e);
32
+ L(e) ? i.visibility[f] = !1 : i.titleVariable || (i.visibility[f] = B(e));
33
+ const y = P(e), T = {
34
+ ...a,
45
35
  strategyId: "",
46
- composition: n.composition,
47
- visibility: n.visibility,
48
- previousTitleHtml: M.previousTitleHtml,
49
- textTrimming: n.anyTextTrimming
50
- }, d = I(e), R = `
36
+ composition: i.composition,
37
+ visibility: i.visibility,
38
+ previousTitleHtml: C.previousTitleHtml,
39
+ textTrimming: i.anyTextTrimming
40
+ }, s = A(e), v = `
51
41
  <table>
52
42
  <tbody>
53
43
  <tr>
54
44
  <td class="esd-structure" align="left">
55
45
  <table width="100%" cellpadding="0" cellspacing="0">
56
46
  <tbody>
57
- <tr>${F({
58
- nodeConfig: h,
59
- composition: n,
60
- cardBg: v,
61
- titleText: C,
47
+ <tr>${N({
48
+ nodeConfig: T,
49
+ composition: i,
50
+ cardBg: y,
51
+ titleText: u,
62
52
  legacyId: e.getAttribute("id") ?? void 0,
63
53
  legacyBgColor: e.getAttribute("bgcolor") ?? void 0,
64
- preserveInnerHtml: d ? e.innerHTML : void 0,
65
- skipCompile: d,
66
- blockPadding: G(((f = (p = r.theme) == null ? void 0 : p.blockPadding) == null ? void 0 : f.desktop) ?? N(e))
54
+ preserveInnerHtml: s ? e.innerHTML : void 0,
55
+ skipCompile: s,
56
+ blockPadding: _(((p = (g = r.theme) == null ? void 0 : g.blockPadding) == null ? void 0 : p.desktop) ?? H(e))
67
57
  })}</tr>
68
58
  </tbody>
69
59
  </table>
@@ -71,40 +61,40 @@ function q(i, e, s) {
71
61
  </tr>
72
62
  </tbody>
73
63
  </table>
74
- `, l = i.parseFromString(R, "text/html").querySelector("td.esd-structure");
75
- return !l || !e.parentNode ? (console.warn(
76
- `[RecommendationMigrator] Aborting block id=${o} — failed to construct new HTML element`
77
- ), !1) : (e.parentNode.replaceChild(l, e), !0);
64
+ `, d = c.parseFromString(v, "text/html").querySelector("td.esd-structure");
65
+ return !d || !e.parentNode ? (console.warn(
66
+ `[RecommendationMigrator] Aborting block id=${t} — failed to construct new HTML element`
67
+ ), !1) : (e.parentNode.replaceChild(d, e), !0);
78
68
  }
79
- function re(i, e = {}) {
80
- const s = new DOMParser();
81
- let o;
69
+ function X(c, e = {}) {
70
+ const m = new DOMParser();
71
+ let t;
82
72
  try {
83
- o = s.parseFromString(i, "text/html");
84
- } catch (t) {
85
- return console.error("[RecommendationMigrator] Failed to parse template:", t), i;
73
+ t = m.parseFromString(c, "text/html");
74
+ } catch (n) {
75
+ return console.error("[RecommendationMigrator] Failed to parse template:", n), c;
86
76
  }
87
- const a = Array.from(o.querySelectorAll(V)).filter((t) => T(t) || U.test(t.innerHTML));
77
+ const r = Array.from(t.querySelectorAll(k));
88
78
  try {
89
- x().$patch((c) => {
90
- c.migrations = {
91
- ...c.migrations,
92
- [b.Recommendation]: a.length
79
+ M().$patch((a) => {
80
+ a.migrations = {
81
+ ...a.migrations,
82
+ [b.Recommendation]: r.length
93
83
  };
94
84
  });
95
85
  } catch {
96
86
  }
97
- if (a.length === 0)
98
- return i;
99
- let r = 0;
100
- return a.forEach((t) => {
87
+ if (r.length === 0)
88
+ return c;
89
+ let o = 0;
90
+ return r.forEach((n) => {
101
91
  try {
102
- q(s, t, e) && (r += 1);
103
- } catch (c) {
104
- console.error("[RecommendationMigrator] Unexpected error migrating block:", c);
92
+ $(m, n, e) && (o += 1);
93
+ } catch (a) {
94
+ console.error("[RecommendationMigrator] Unexpected error migrating block:", a);
105
95
  }
106
- }), r > 0 && console.info(`[RecommendationMigrator] Migrated ${r} legacy Recommendation block(s)`), o.documentElement.outerHTML;
96
+ }), o > 0 && console.info(`[RecommendationMigrator] Migrated ${o} legacy Recommendation block(s)`), t.documentElement.outerHTML;
107
97
  }
108
98
  export {
109
- re as migrateRecommendation
99
+ X as migrateRecommendation
110
100
  };
@@ -1,146 +1,142 @@
1
- var x = Object.defineProperty;
2
- var B = (c, e, r) => e in c ? x(c, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : c[e] = r;
3
- var A = (c, e, r) => B(c, typeof e != "symbol" ? e + "" : e, r);
4
- import { MERGE_TAGS as f, PAGE_TYPES as p } from "../../enums/unsubscribe.js";
5
- import { UNSUBSCRIBE_BLOCK_SELECTOR as h, DATA_ATTRIBUTES as k } from "../../extensions/Blocks/Unsubscribe/utils/constants.js";
6
- import { useUnsubscribeStore as C } from "../../stores/unsubscribe.js";
7
- class $ {
1
+ var $ = Object.defineProperty;
2
+ var _ = (f, e, t) => e in f ? $(f, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : f[e] = t;
3
+ var y = (f, e, t) => _(f, typeof e != "symbol" ? e + "" : e, t);
4
+ import { MERGE_TAGS as l, PAGE_TYPES as p } from "../../enums/unsubscribe.js";
5
+ import { UNSUBSCRIBE_BLOCK_SELECTOR as A, DATA_ATTRIBUTES as T, UNSUBSCRIBE_MERGE_TAG_REGEX as E } from "../../extensions/Blocks/Unsubscribe/utils/constants.js";
6
+ import { swapMergeTagInHref as B } from "../../extensions/Blocks/Unsubscribe/utils/swapMergeTagInHref.js";
7
+ import { useUnsubscribeStore as N } from "../../stores/unsubscribe.js";
8
+ import { escapeHtml as h } from "../../utils/htmlEscape.js";
9
+ const S = "unsubscribe", R = "You can ", M = " from our emails, if you need to.", C = "{-{-UNSUBSCRIBE-LINK-}-}";
10
+ class P {
8
11
  constructor() {
9
- A(this, "parser");
12
+ y(this, "parser");
10
13
  this.parser = new DOMParser();
11
14
  }
12
15
  async migrate(e) {
13
16
  try {
14
- const r = this.parser.parseFromString(e, "text/html"), t = r.querySelectorAll("td.unsubscribe-block");
15
- if (t.length) {
16
- const s = C();
17
- await s.fetchTemplates(), this.migrateLegacyBlocks(t, s);
17
+ const t = this.parser.parseFromString(e, "text/html"), r = t.querySelectorAll("td.unsubscribe-block");
18
+ if (r.length) {
19
+ const s = N();
20
+ await s.fetchTemplates(), this.migrateLegacyBlocks(r, s, this.collectBlockTags(t));
18
21
  }
19
- const n = this.repairUnsubscribeLinks(r);
20
- return !t.length && !n ? e : r.documentElement.outerHTML;
21
- } catch (r) {
22
- return console.error("UnsubscribeMigrator failed:", r), e;
22
+ const n = this.repairUnsubscribeLinks(t);
23
+ return !r.length && !n ? e : t.documentElement.outerHTML;
24
+ } catch (t) {
25
+ return console.error("UnsubscribeMigrator failed:", t), e;
23
26
  }
24
27
  }
25
- migrateLegacyBlocks(e, r) {
26
- e.forEach((t) => {
27
- const n = t.getAttribute("id"), s = this.extractPaddingClass(t), l = t.getAttribute("bgcolor") || "", a = this.extractUnsubscribeContent(t), o = this.getCollectionTypeFromMergeTag(a.linkHref), b = r.getSelectedUnsubscribePagesByCollection(o);
28
+ migrateLegacyBlocks(e, t, r) {
29
+ e.forEach((n) => {
30
+ const s = n.getAttribute("id"), i = this.extractPaddingClass(n), c = n.getAttribute("bgcolor") || "", a = this.extractUnsubscribeContent(n, r), b = this.getCollectionTypeFromMergeTag(a.linkHref), u = t.getSelectedUnsubscribePagesByCollection(b);
28
31
  console.debug("[UnsubscribeMigrator]", {
29
32
  mergeTag: a.linkHref,
30
- collectionType: o,
31
- pageIds: b,
32
- paddingClass: s,
33
- bgColor: l
33
+ collectionType: b,
34
+ pageIds: u,
35
+ paddingClass: i,
36
+ bgColor: c
34
37
  });
35
- const u = this.buildUnsubscribeBlock(
38
+ const o = this.buildUnsubscribeBlock(
36
39
  a,
37
- o,
38
40
  b,
39
- s,
40
- l
41
- ), i = this.parser.parseFromString(
42
- `<table id="tempDoc"><tbody><tr>${u}</tr></tbody></table>`,
41
+ u,
42
+ i,
43
+ c
44
+ ), g = this.parser.parseFromString(
45
+ `<table id="tempDoc"><tbody><tr>${o}</tr></tbody></table>`,
43
46
  "text/html"
44
- ).querySelector(h);
45
- i && t.parentNode && (i.setAttribute("id", n || ""), t.parentNode.replaceChild(i, t));
47
+ ).querySelector(A);
48
+ g && n.parentNode && (g.setAttribute("id", s || ""), n.parentNode.replaceChild(g, n));
46
49
  });
47
50
  }
51
+ collectBlockTags(e) {
52
+ const t = e.querySelectorAll(`td.unsubscribe-block, ${A}`), r = /* @__PURE__ */ new Set();
53
+ return t.forEach((n) => {
54
+ var a, b, u;
55
+ const s = Number(n.getAttribute(T.PAGE_TYPE)), i = l[s], c = (u = (b = (a = this.findLinkCandidates(n).primary) == null ? void 0 : a.getAttribute("href")) == null ? void 0 : b.match(E)) == null ? void 0 : u[0];
56
+ i ? r.add(i) : c && r.add(l[this.getCollectionTypeFromMergeTag(c)]);
57
+ }), r;
58
+ }
48
59
  // Re-derives the typed merge tag from data-unsubscribe-page-type for any v2
49
60
  // block whose anchor href is missing or the legacy default. Returns true when
50
61
  // at least one href was rewritten. Typed tags and custom URLs are left intact.
51
62
  repairUnsubscribeLinks(e) {
52
- const r = e.querySelectorAll(`${h}[${k.PAGE_TYPE}]`);
53
- let t = !1;
54
- return r.forEach((n) => {
63
+ const t = e.querySelectorAll(`${A}[${T.PAGE_TYPE}]`);
64
+ let r = !1;
65
+ return t.forEach((n) => {
55
66
  const s = n.querySelector('a[data-unsubscribe-link="true"], a.unsubscribe-link');
56
67
  if (!s)
57
68
  return;
58
- const l = s.getAttribute("href") || "";
59
- if (l && l !== f.default)
69
+ const i = s.getAttribute("href") || "";
70
+ if (i && i !== l.default)
60
71
  return;
61
- const a = Number(n.getAttribute(k.PAGE_TYPE)), o = f[a];
62
- o && (s.setAttribute("href", o), t = !0);
63
- }), t;
72
+ const c = Number(n.getAttribute(T.PAGE_TYPE)), a = l[c];
73
+ a && (s.setAttribute("href", a), r = !0);
74
+ }), r;
64
75
  }
65
76
  extractPaddingClass(e) {
66
- const t = (e.getAttribute("class") || "").match(/\bes-p\d+\b/);
67
- return t ? t[0] : "";
77
+ const r = (e.getAttribute("class") || "").match(/\bes-p\d+\b/);
78
+ return r ? r[0] : "";
79
+ }
80
+ hasVisibleContent(e) {
81
+ var t;
82
+ return !!((t = e.textContent) != null && t.trim() || e.querySelector("img"));
68
83
  }
69
- extractUnsubscribeContent(e) {
70
- var d;
71
- const r = e.querySelector("a.unsubscribe-link") || e.querySelector('a[href*="unsubscribe"]'), t = (r == null ? void 0 : r.closest("p")) || e.querySelector("p");
72
- if (!t)
73
- return {
74
- textBefore: "You can ",
75
- linkText: "unsubscribe",
76
- linkHref: "{{ins-unsubscribe-link}}",
77
- linkStyle: "",
78
- textAfter: " from our emails, if you need to.",
79
- isBold: !1,
80
- isItalic: !1,
81
- align: "center",
82
- paragraphStyle: ""
83
- };
84
- const n = e.getAttribute("align") || t.getAttribute("align") || "center", s = t.getAttribute("style") || "";
85
- if (!r)
86
- return {
87
- textBefore: "You can ",
88
- linkText: "unsubscribe",
89
- linkHref: "{{ins-unsubscribe-link}}",
90
- linkStyle: "",
91
- textAfter: " from our emails, if you need to.",
92
- isBold: !1,
93
- isItalic: !1,
94
- align: n,
95
- paragraphStyle: s
96
- };
97
- const l = ((d = r.textContent) == null ? void 0 : d.trim()) || "unsubscribe", a = r.getAttribute("href") || "{{ins-unsubscribe-link}}", o = r.getAttribute("style") || "", b = t.textContent || "", u = b.indexOf(l), g = u >= 0 ? b.substring(0, u).trim() : "You can ", i = u >= 0 ? b.substring(u + l.length).trim() : " from our emails, if you need to.", m = !!t.querySelector("b, strong"), y = !!t.querySelector("i, em");
98
- return {
99
- textBefore: g,
100
- linkText: l,
101
- linkHref: this.normalizeUnsubscribeHref(a),
102
- linkStyle: o,
103
- textAfter: i,
104
- isBold: m,
105
- isItalic: y,
106
- align: n,
107
- paragraphStyle: s
84
+ findLinkCandidates(e) {
85
+ const t = Array.from(/* @__PURE__ */ new Set([
86
+ ...Array.from(e.querySelectorAll("a.unsubscribe-link")),
87
+ ...Array.from(e.querySelectorAll('a[href*="unsubscribe"]'))
88
+ ])), r = (i) => E.test(i.getAttribute("href") || ""), n = (i) => this.hasVisibleContent(i), s = t.find((i) => n(i) && r(i)) ?? t.find((i) => n(i) && i.classList.contains("unsubscribe-link")) ?? t.find(r) ?? t.find(n) ?? t[0];
89
+ return { candidates: t, primary: s };
90
+ }
91
+ extractUnsubscribeContent(e, t) {
92
+ const r = e.cloneNode(!0), { candidates: n, primary: s } = this.findLinkCandidates(r), i = (s == null ? void 0 : s.closest("p")) ?? null, c = i || r.querySelector("p"), a = {
93
+ footerHtml: "",
94
+ linkText: S,
95
+ linkHref: l.default,
96
+ linkStyle: "",
97
+ align: "center",
98
+ paragraphStyle: ""
108
99
  };
100
+ if (!c || (a.align = e.getAttribute("align") || c.getAttribute("align") || "center", i || (a.paragraphStyle = c.getAttribute("style") || ""), !s))
101
+ return a;
102
+ if (a.linkText = this.hasVisibleContent(s) ? s.innerHTML.trim() : S, a.linkHref = this.normalizeUnsubscribeHref(s.getAttribute("href") || l.default), a.linkStyle = s.getAttribute("style") || "", i) {
103
+ const b = this.getCollectionTypeFromMergeTag(a.linkHref), u = l[b];
104
+ r.querySelectorAll("a[href]").forEach((o) => {
105
+ var m;
106
+ const d = o.getAttribute("href") || "", g = (m = d.match(E)) == null ? void 0 : m[0];
107
+ g && o.setAttribute("href", B(d, t.has(g) ? g : u));
108
+ }), n.filter((o) => o !== s && !this.hasVisibleContent(o)).forEach((o) => o.replaceWith(...Array.from(o.childNodes))), s.replaceWith(r.ownerDocument.createTextNode(C)), a.footerHtml = r.innerHTML.trim();
109
+ }
110
+ return a;
109
111
  }
110
- buildUnsubscribeBlock(e, r, t, n, s) {
111
- const l = e.linkStyle ? ` style="${e.linkStyle}"` : "", u = `<a ${`href="${Object.values(f).includes(e.linkHref) ? f[r] : e.linkHref}" class="unsubscribe-link" target="_blank" data-unsubscribe-link="true"`}${l}>${e.linkText}</a>`, g = [];
112
- e.textBefore && g.push(e.textBefore), g.push(u), e.textAfter && g.push(e.textAfter);
113
- let i = g.join(" ");
114
- e.isBold && e.isItalic ? i = `<strong path="1,0"><em path="1,0,0">${i}</em></strong>` : e.isBold ? i = `<strong path="1,0">${i}</strong>` : e.isItalic && (i = `<em path="1,0">${i}</em>`);
115
- const m = e.align ? ` align="${e.align}"` : "", y = s ? ` bgcolor="${s}"` : "", d = e.paragraphStyle ? ` style="${e.paragraphStyle}"` : "", T = t.length > 0 ? ` ${k.PAGE_LIST}="${t.join(",")}"` : "", E = ` ${k.PAGE_TYPE}="${r}"`, S = "esd-block-text unsubscribe-block-v2 esd-block-unsubscribe esd-unsubscribe-block esd-extension-block";
112
+ buildUnsubscribeBlock(e, t, r, n, s) {
113
+ const i = e.linkStyle ? ` style="${h(e.linkStyle)}"` : "", a = Object.values(l).includes(e.linkHref) ? l[t] : e.linkHref, u = `<a ${`href="${h(a)}" class="unsubscribe-link" target="_blank" data-unsubscribe-link="true"`}${i}>${e.linkText}</a>`, o = e.paragraphStyle ? ` style="${h(e.paragraphStyle)}"` : "", d = e.footerHtml ? e.footerHtml.replace(C, () => u) : `<p path="1"${o}>${R}${u}${M}</p>`, g = e.align ? ` align="${e.align}"` : "", m = s ? ` bgcolor="${s}"` : "", U = r.length > 0 ? ` ${T.PAGE_LIST}="${r.join(",")}"` : "", L = ` ${T.PAGE_TYPE}="${t}"`, k = "esd-block-text unsubscribe-block-v2 esd-block-unsubscribe esd-unsubscribe-block esd-extension-block";
116
114
  return `
117
115
  <td
118
116
  data-migration="true"
119
117
  esd-extension-block-id="unsubscribe-block"
120
- class="${n ? `${S} ${n}` : S}"
121
- ${m}${y}${E}${T}
118
+ class="${n ? `${k} ${n}` : k}"
119
+ ${g}${m}${L}${U}
122
120
  >
123
- <p path="1"${d}>
124
- ${i}
125
- </p>
121
+ ${d}
126
122
  </td>
127
123
  `;
128
124
  }
129
125
  getCollectionTypeFromMergeTag(e) {
130
- return e === f[p.SUBSCRIPTION_PREFERENCE_CENTER] ? p.SUBSCRIPTION_PREFERENCE_CENTER : e === f[p.GLOBAL_UNSUBSCRIBE] ? p.GLOBAL_UNSUBSCRIBE : p.GLOBAL_UNSUBSCRIBE;
126
+ return e === l[p.SUBSCRIPTION_PREFERENCE_CENTER] ? p.SUBSCRIPTION_PREFERENCE_CENTER : e === l[p.GLOBAL_UNSUBSCRIBE] ? p.GLOBAL_UNSUBSCRIBE : p.GLOBAL_UNSUBSCRIBE;
131
127
  }
132
128
  normalizeUnsubscribeHref(e) {
133
- if (Object.values(f).includes(e))
129
+ if (Object.values(l).includes(e))
134
130
  return e;
135
- const t = e.match(/{{ins-(?:global-)?(?:preferences-)?unsubscribe-link}}/);
136
- return t ? t[0] : e.includes("unsubscribe") || e.includes("unsub") ? (console.warn(
131
+ const r = e.match(/{{ins-(?:global-)?(?:preferences-)?unsubscribe-link}}/);
132
+ return r ? r[0] : e.includes("unsubscribe") || e.includes("unsub") ? (console.warn(
137
133
  `[UnsubscribeMigrator] Unrecognized unsubscribe href format: "${e}". Defaulting to {{ins-unsubscribe-link}}`
138
134
  ), "{{ins-unsubscribe-link}}") : e;
139
135
  }
140
136
  }
141
- async function M(c) {
142
- return new $().migrate(c);
137
+ async function q(f) {
138
+ return new P().migrate(f);
143
139
  }
144
140
  export {
145
- M as migrateUnsubscribe
141
+ q as migrateUnsubscribe
146
142
  };
@@ -1,48 +1,49 @@
1
- var y = Object.defineProperty;
2
- var I = (c, o, e) => o in c ? y(c, o, { enumerable: !0, configurable: !0, writable: !0, value: e }) : c[o] = e;
3
- var g = (c, o, e) => I(c, typeof o != "symbol" ? o + "" : o, e);
4
- import { useToaster as L } from "../../../composables/useToaster.js";
5
- import { ToasterTypeOptions as C } from "../../../enums/toaster.js";
6
- import { PAGE_TYPES as m } from "../../../enums/unsubscribe.js";
7
- import { useEditorStore as N } from "../../../stores/editor.js";
8
- import { useUnsubscribeStore as a } from "../../../stores/unsubscribe.js";
9
- import { Block as U, BlockCompositionType as R, ContextActionType as f, ModificationDescription as u, BlockType as v } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
10
- import { getDefaultTemplate as D } from "./template.js";
11
- import { UNSUBSCRIBE_BLOCK_SELECTOR as B, DATA_ATTRIBUTES as n, UNSUBSCRIBE_EVENTS as h } from "./utils/constants.js";
12
- import { parsePageList as S } from "./utils/utils.js";
13
- const w = "unsubscribe-block", E = 'a[data-unsubscribe-link="true"]', P = "{{ins-unsubscribe-link}}", x = "https://academy.insiderone.com/docs/adding-unsubscribe-pages-into-emails", G = "Removing the unsubscribe text leaves an empty block, but an active unsubscribe link is required. Undo your last action to restore the text, or delete the unsubscribe block entirely.", M = {
14
- [m.GLOBAL_UNSUBSCRIBE]: "{{ins-global-unsubscribe-link}}",
15
- [m.SUBSCRIPTION_PREFERENCE_CENTER]: "{{ins-preferences-unsubscribe-link}}"
16
- }, O = 3;
17
- let d = null, p = null;
18
- const A = () => {
19
- d && (document.removeEventListener(h.SELECT, d), d = null);
20
- }, T = () => {
21
- p && (document.removeEventListener(h.CANCEL, p), p = null);
22
- }, q = () => {
23
- A(), T();
1
+ var R = Object.defineProperty;
2
+ var v = (l, c, e) => c in l ? R(l, c, { enumerable: !0, configurable: !0, writable: !0, value: e }) : l[c] = e;
3
+ var h = (l, c, e) => v(l, typeof c != "symbol" ? c + "" : c, e);
4
+ import { useToaster as D } from "../../../composables/useToaster.js";
5
+ import { ToasterTypeOptions as w } from "../../../enums/toaster.js";
6
+ import { PAGE_TYPES as B } from "../../../enums/unsubscribe.js";
7
+ import { useEditorStore as G } from "../../../stores/editor.js";
8
+ import { useUnsubscribeStore as u } from "../../../stores/unsubscribe.js";
9
+ import { Block as P, BlockCompositionType as x, ContextActionType as y, ModificationDescription as k, BlockType as M } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
10
+ import { getDefaultTemplate as O } from "./template.js";
11
+ import { UNSUBSCRIBE_BLOCK_SELECTOR as f, DATA_ATTRIBUTES as o, UNSUBSCRIBE_EVENTS as E, UNSUBSCRIBE_MERGE_TAG_REGEX as I } from "./utils/constants.js";
12
+ import { swapMergeTagInHref as q } from "./utils/swapMergeTagInHref.js";
13
+ import { parsePageList as L } from "./utils/utils.js";
14
+ const F = "unsubscribe-block", _ = 'a[data-unsubscribe-link="true"]', C = "{{ins-unsubscribe-link}}", K = "https://academy.insiderone.com/docs/adding-unsubscribe-pages-into-emails", H = "Removing the unsubscribe text leaves an empty block, but an active unsubscribe link is required. Undo your last action to restore the text, or delete the unsubscribe block entirely.", Y = {
15
+ [B.GLOBAL_UNSUBSCRIBE]: "{{ins-global-unsubscribe-link}}",
16
+ [B.SUBSCRIPTION_PREFERENCE_CENTER]: "{{ins-preferences-unsubscribe-link}}"
17
+ }, V = 3;
18
+ let d = null, b = null;
19
+ const N = () => {
20
+ d && (document.removeEventListener(E.SELECT, d), d = null);
21
+ }, U = () => {
22
+ b && (document.removeEventListener(E.CANCEL, b), b = null);
23
+ }, W = () => {
24
+ N(), U();
24
25
  };
25
- class J extends U {
26
+ class se extends P {
26
27
  constructor() {
27
28
  super();
28
- g(this, "currentNode");
29
+ h(this, "currentNode");
29
30
  // Per-block "did this instance have a link last time we saw it?" tracking.
30
31
  // Keyed by the stable `data-unsubscribe-block-id` we assign, because
31
32
  // ImmutableHtmlNode instances are recreated on every document mutation and
32
33
  // can't be used as Map keys directly. A singleton boolean here would be
33
34
  // polluted across blocks since Stripo fires onDocumentChanged per-instance.
34
- g(this, "linkStateByBlockId", /* @__PURE__ */ new Map());
35
+ h(this, "linkStateByBlockId", /* @__PURE__ */ new Map());
35
36
  // Per-block prepend retry counter for the leading text guard (SD-143097).
36
- g(this, "guardAttemptsByBlockId", /* @__PURE__ */ new Map());
37
+ h(this, "guardAttemptsByBlockId", /* @__PURE__ */ new Map());
37
38
  }
38
39
  getId() {
39
- return w;
40
+ return F;
40
41
  }
41
42
  getIcon() {
42
43
  return "unsubscribe-icon";
43
44
  }
44
45
  getBlockCompositionType() {
45
- return R.BLOCK;
46
+ return x.BLOCK;
46
47
  }
47
48
  getName() {
48
49
  return this.api.translate("Unsubscribe Block");
@@ -51,16 +52,16 @@ class J extends U {
51
52
  return this.api.translate("Unsubscribe Block Description");
52
53
  }
53
54
  getTemplate() {
54
- return D();
55
+ return O();
55
56
  }
56
57
  getContextActionsIds() {
57
- return [f.MOVE, f.REMOVE];
58
+ return [y.MOVE, y.REMOVE];
58
59
  }
59
60
  onSelect(e) {
60
- if (this.currentNode = e, N().isPreviewModeOpen)
61
+ if (this.currentNode = e, G().isPreviewModeOpen)
61
62
  return;
62
63
  const t = this._getOrAssignBlockId(e);
63
- t && this.linkStateByBlockId.set(t, this._hasUnsubscribeLink(e)), this._setupSelectEventListener(), this._setupCancelEventListener(t), !("getAttribute" in e && e.getAttribute("data-migration")) && (this._resetStoreState(), t && (a().pendingBlockId = t), this._loadBlockState(e), this._checkExistingBlocks(), this._openDrawer());
64
+ t && this.linkStateByBlockId.set(t, this._hasUnsubscribeLink(e)), this._setupSelectEventListener(), this._setupCancelEventListener(t), !("getAttribute" in e && e.getAttribute("data-migration")) && (this._resetStoreState(), t && (u().pendingBlockId = t), this._loadBlockState(e), this._checkExistingBlocks(), this._openDrawer());
64
65
  }
65
66
  onCreated(e) {
66
67
  this._ensureLeadingTextGuard(e);
@@ -68,7 +69,7 @@ class J extends U {
68
69
  onDocumentInit() {
69
70
  try {
70
71
  const e = this.api.getDocumentRoot();
71
- e && "querySelectorAll" in e && e.querySelectorAll(B).forEach((t) => {
72
+ e && "querySelectorAll" in e && e.querySelectorAll(f).forEach((t) => {
72
73
  this._ensureLeadingTextGuard(t);
73
74
  });
74
75
  } catch {
@@ -79,11 +80,11 @@ class J extends U {
79
80
  const t = this._getOrAssignBlockId(e);
80
81
  if (!t)
81
82
  return;
82
- const s = this._hasUnsubscribeLink(e);
83
- this.linkStateByBlockId.get(t) === !0 && !s && this._warnLinkRemoved(), this.linkStateByBlockId.set(t, s);
83
+ const i = this._hasUnsubscribeLink(e);
84
+ this.linkStateByBlockId.get(t) === !0 && !i && this._warnLinkRemoved(), this.linkStateByBlockId.set(t, i);
84
85
  }
85
86
  onDelete(e) {
86
- q(), this._removeBlockTemplatesFromStore(e), this._resetStoreState();
87
+ W(), this._removeBlockTemplatesFromStore(e), this._resetStoreState();
87
88
  const t = this._readBlockId(e);
88
89
  t && (this.linkStateByBlockId.delete(t), this.guardAttemptsByBlockId.delete(t));
89
90
  }
@@ -95,38 +96,38 @@ class J extends U {
95
96
  _ensureLeadingTextGuard(e) {
96
97
  if (!("querySelector" in e))
97
98
  return;
98
- const t = e.querySelector(E);
99
+ const t = e.querySelector(_);
99
100
  if (!t)
100
101
  return;
101
- let s = t, r = s.parent();
102
+ let i = t, r = i.parent();
102
103
  for (; r && "getTagName" in r && r.getTagName().toLowerCase() !== "p"; )
103
- s = r, r = r.parent();
104
+ i = r, r = r.parent();
104
105
  if (!r || !("getTagName" in r) || r.getTagName().toLowerCase() !== "p")
105
106
  return;
106
- const i = s.previousSibling();
107
- if (!!(i && i.getType() === "text" && i.getTextContent())) {
108
- const b = this._readBlockId(e);
109
- b && this.guardAttemptsByBlockId.delete(b);
107
+ const s = i.previousSibling();
108
+ if (!!(s && s.getType() === "text" && s.getTextContent())) {
109
+ const a = this._readBlockId(e);
110
+ a && this.guardAttemptsByBlockId.delete(a);
110
111
  return;
111
112
  }
112
- const k = this._getOrAssignBlockId(e);
113
- if (!k)
113
+ const g = this._getOrAssignBlockId(e);
114
+ if (!g)
114
115
  return;
115
- const _ = this.guardAttemptsByBlockId.get(k) ?? 0;
116
- if (!(_ >= O)) {
117
- this.guardAttemptsByBlockId.set(k, _ + 1);
116
+ const p = this.guardAttemptsByBlockId.get(g) ?? 0;
117
+ if (!(p >= V)) {
118
+ this.guardAttemptsByBlockId.set(g, p + 1);
118
119
  try {
119
- this.api.getDocumentModifier().modifyHtml(r).prepend("&nbsp;").apply(new u("Ensure unsubscribe link text guard"));
120
- } catch (b) {
121
- console.warn("[UnsubscribeBlock] Failed to ensure link text guard:", b);
120
+ this.api.getDocumentModifier().modifyHtml(r).prepend("&nbsp;").apply(new k("Ensure unsubscribe link text guard"));
121
+ } catch (a) {
122
+ console.warn("[UnsubscribeBlock] Failed to ensure link text guard:", a);
122
123
  }
123
124
  }
124
125
  }
125
126
  _hasUnsubscribeLink(e) {
126
- return "querySelector" in e ? !!e.querySelector(E) : !1;
127
+ return "querySelector" in e ? !!e.querySelector(_) : !1;
127
128
  }
128
129
  _readBlockId(e) {
129
- return "getAttribute" in e ? e.getAttribute(n.BLOCK_ID) : null;
130
+ return "getAttribute" in e ? e.getAttribute(o.BLOCK_ID) : null;
130
131
  }
131
132
  /**
132
133
  * Returns the block's stable id, assigning one via the document modifier if
@@ -140,13 +141,13 @@ class J extends U {
140
141
  return t;
141
142
  if (!("getAttribute" in e))
142
143
  return null;
143
- const s = this._generateNextBlockId();
144
+ const i = this._generateNextBlockId();
144
145
  try {
145
- this.api.getDocumentModifier().modifyHtml(e).setAttribute(n.BLOCK_ID, s).apply(new u(`Assign unsubscribe block id ${s}`));
146
+ this.api.getDocumentModifier().modifyHtml(e).setAttribute(o.BLOCK_ID, i).apply(new k(`Assign unsubscribe block id ${i}`));
146
147
  } catch (r) {
147
148
  return console.warn("[UnsubscribeBlock] Failed to assign block id:", r), null;
148
149
  }
149
- return s;
150
+ return i;
150
151
  }
151
152
  /**
152
153
  * Generates a unique id by scanning the document for the highest existing
@@ -157,10 +158,10 @@ class J extends U {
157
158
  let e = 0;
158
159
  try {
159
160
  const t = this.api.getDocumentRoot();
160
- t && "querySelectorAll" in t && t.querySelectorAll(B).forEach((r) => {
161
+ t && "querySelectorAll" in t && t.querySelectorAll(f).forEach((r) => {
161
162
  if ("getAttribute" in r) {
162
- const i = r.getAttribute(n.BLOCK_ID), l = i ? parseInt(i) : 0;
163
- l > e && (e = l);
163
+ const s = r.getAttribute(o.BLOCK_ID), n = s ? parseInt(s) : 0;
164
+ n > e && (e = n);
164
165
  }
165
166
  });
166
167
  } catch {
@@ -169,14 +170,14 @@ class J extends U {
169
170
  }
170
171
  _warnLinkRemoved() {
171
172
  try {
172
- const { showToaster: e } = L();
173
+ const { showToaster: e } = D();
173
174
  e({
174
- type: C.Warning,
175
- message: this.api.translate(G),
175
+ type: w.Warning,
176
+ message: this.api.translate(H),
176
177
  actionButton: {
177
178
  text: this.api.translate("Visit Academy"),
178
179
  onClick: () => {
179
- window.open(x, "_blank", "noopener,noreferrer");
180
+ window.open(K, "_blank", "noopener,noreferrer");
180
181
  }
181
182
  }
182
183
  });
@@ -185,55 +186,62 @@ class J extends U {
185
186
  }
186
187
  }
187
188
  _setupSelectEventListener() {
188
- A(), d = (e) => {
189
- const t = e, { collectionType: s, selectedPages: r } = t.detail;
190
- this._updateBlock(s, r.join(","));
191
- }, document.addEventListener(h.SELECT, d);
189
+ N(), d = (e) => {
190
+ const t = e, { collectionType: i, selectedPages: r } = t.detail;
191
+ this._updateBlock(i, r.join(","));
192
+ }, document.addEventListener(E.SELECT, d);
192
193
  }
193
194
  _setupCancelEventListener(e) {
194
- T(), p = (t) => {
195
- const { detail: s } = t;
196
- ((s == null ? void 0 : s.blockId) ?? null) === e && this._handleCancel();
197
- }, document.addEventListener(h.CANCEL, p);
195
+ U(), b = (t) => {
196
+ const { detail: i } = t;
197
+ ((i == null ? void 0 : i.blockId) ?? null) === e && this._handleCancel();
198
+ }, document.addEventListener(E.CANCEL, b);
198
199
  }
199
200
  _handleCancel() {
200
201
  try {
201
202
  if (!this.currentNode)
202
203
  return;
203
- this.api.getDocumentModifier().modifyHtml(this.currentNode).replaceWith(`<${v.EMPTY_CONTAINER}/>`).apply(new u("Removed unsubscribe block due to cancel"));
204
+ this.api.getDocumentModifier().modifyHtml(this.currentNode).replaceWith(`<${M.EMPTY_CONTAINER}/>`).apply(new k("Removed unsubscribe block due to cancel"));
204
205
  } catch (e) {
205
206
  console.warn("[UnsubscribeBlock] Failed to remove unsubscribe block:", e);
206
207
  }
207
208
  }
208
209
  _updateBlock(e, t) {
210
+ var a;
209
211
  if (!this.currentNode || !("querySelector" in this.currentNode))
210
212
  return;
211
- const s = this.currentNode.querySelector(E);
212
- if (!s)
213
+ const i = this.currentNode.querySelector(_);
214
+ if (!i)
213
215
  return;
214
- const r = this._getMergeTag(e);
215
- this.api.getDocumentModifier().modifyHtml(s).setAttribute("href", r).apply(new u(`Updated unsubscribe link to ${r}`)), this.api.getDocumentModifier().modifyHtml(this.currentNode).setAttribute(n.PAGE_TYPE, e.toString()).setAttribute(n.PAGE_LIST, t).apply(new u("Updated unsubscribe block metadata"));
216
+ const r = this._getMergeTag(e), s = this.api.getDocumentModifier(), n = "getAttribute" in i ? i.getAttribute("href") : null, p = [(a = n == null ? void 0 : n.match(I)) == null ? void 0 : a[0], C];
217
+ s.modifyHtml(i).setAttribute("href", r), this.currentNode.querySelectorAll("a[href]").forEach((m) => {
218
+ var T;
219
+ if (!("getAttribute" in m) || m.getAttribute("data-unsubscribe-link") === "true")
220
+ return;
221
+ const S = m.getAttribute("href") ?? "", A = (T = S.match(I)) == null ? void 0 : T[0];
222
+ A && p.includes(A) && s.modifyHtml(m).setAttribute("href", q(S, r));
223
+ }), s.modifyHtml(this.currentNode).setAttribute(o.PAGE_TYPE, e.toString()).setAttribute(o.PAGE_LIST, t), s.apply(new k(`Updated unsubscribe link to ${r}`));
216
224
  }
217
225
  _getMergeTag(e) {
218
- return M[e] ?? P;
226
+ return Y[e] ?? C;
219
227
  }
220
228
  _openDrawer() {
221
229
  if (!(this.currentNode && this.currentNode.getAttribute("data-unsubscribe-page-type")))
222
230
  try {
223
- const e = a();
231
+ const e = u();
224
232
  e.typeSelectionDrawerStatus = !0;
225
233
  } catch (e) {
226
234
  console.error("[UnsubscribeBlock] Failed to open drawer:", e);
227
235
  }
228
236
  }
229
237
  _checkExistingBlocks() {
230
- const e = a();
231
- e.isGlobalUnsubscribeDisabled = !1, e.isSubscriptionPreferencesCenterDisabled = !1, this.api.getDocumentRoot().querySelectorAll(B).forEach((s) => {
232
- if ("getAttribute" in s) {
233
- const r = s.getAttribute(n.PAGE_TYPE);
238
+ const e = u();
239
+ e.isGlobalUnsubscribeDisabled = !1, e.isSubscriptionPreferencesCenterDisabled = !1, this.api.getDocumentRoot().querySelectorAll(f).forEach((i) => {
240
+ if ("getAttribute" in i) {
241
+ const r = i.getAttribute(o.PAGE_TYPE);
234
242
  if (r) {
235
- const i = Number(r);
236
- i === m.GLOBAL_UNSUBSCRIBE ? e.isGlobalUnsubscribeDisabled = !0 : i === m.SUBSCRIPTION_PREFERENCE_CENTER && (e.isSubscriptionPreferencesCenterDisabled = !0);
243
+ const s = Number(r);
244
+ s === B.GLOBAL_UNSUBSCRIBE ? e.isGlobalUnsubscribeDisabled = !0 : s === B.SUBSCRIPTION_PREFERENCE_CENTER && (e.isSubscriptionPreferencesCenterDisabled = !0);
237
245
  }
238
246
  }
239
247
  });
@@ -241,27 +249,27 @@ class J extends U {
241
249
  async _loadBlockState(e) {
242
250
  if (!("getAttribute" in e))
243
251
  return;
244
- const t = e.getAttribute(n.PAGE_TYPE), s = e.getAttribute(n.PAGE_LIST);
245
- if (!t || !s)
252
+ const t = e.getAttribute(o.PAGE_TYPE), i = e.getAttribute(o.PAGE_LIST);
253
+ if (!t || !i)
246
254
  return;
247
- const r = a(), i = Number(t), l = S(s);
248
- await r.fetchTemplates(), r.setCollectionWithoutAutoSelection(i), r.loadSelectedTemplates(l);
255
+ const r = u(), s = Number(t), n = L(i);
256
+ await r.fetchTemplates(), r.setCollectionWithoutAutoSelection(s), r.loadSelectedTemplates(n);
249
257
  }
250
258
  _resetStoreState() {
251
- a().$reset();
259
+ u().$reset();
252
260
  }
253
261
  _removeBlockTemplatesFromStore(e) {
254
262
  if (!("getAttribute" in e))
255
263
  return;
256
- const t = e.getAttribute(n.PAGE_LIST);
264
+ const t = e.getAttribute(o.PAGE_LIST);
257
265
  if (!t)
258
266
  return;
259
- const s = a(), r = S(t);
260
- s.removeUnsubscribePages(r);
267
+ const i = u(), r = L(t);
268
+ i.removeUnsubscribePages(r);
261
269
  }
262
270
  }
263
271
  export {
264
- w as UNSUBSCRIBE_BLOCK_ID,
265
- J as UnsubscribeBlock,
266
- q as disposeUnsubscribeListeners
272
+ F as UNSUBSCRIBE_BLOCK_ID,
273
+ se as UnsubscribeBlock,
274
+ W as disposeUnsubscribeListeners
267
275
  };
@@ -5,10 +5,11 @@ const s = {
5
5
  PAGE_TYPE: "data-unsubscribe-page-type",
6
6
  PAGE_LIST: "data-unsubscribe-page-list",
7
7
  BLOCK_ID: "data-unsubscribe-block-id"
8
- }, c = ".unsubscribe-block-v2", u = 'a[data-unsubscribe-link="true"], a.unsubscribe-link';
8
+ }, e = ".unsubscribe-block-v2", E = /{{ins-(?:global-)?(?:preferences-)?unsubscribe-link}}/, c = 'a[data-unsubscribe-link="true"], a.unsubscribe-link';
9
9
  export {
10
10
  b as DATA_ATTRIBUTES,
11
- c as UNSUBSCRIBE_BLOCK_SELECTOR,
11
+ e as UNSUBSCRIBE_BLOCK_SELECTOR,
12
12
  s as UNSUBSCRIBE_EVENTS,
13
- u as UNSUBSCRIBE_LINK_SELECTOR
13
+ c as UNSUBSCRIBE_LINK_SELECTOR,
14
+ E as UNSUBSCRIBE_MERGE_TAG_REGEX
14
15
  };
@@ -0,0 +1,5 @@
1
+ import { UNSUBSCRIBE_MERGE_TAG_REGEX as E } from "./constants.js";
2
+ const o = (r, p) => r.replace(E, () => p).replace(`${p}?`, () => `${p}&`);
3
+ export {
4
+ o as swapMergeTagInHref
5
+ };
@@ -1,9 +1,9 @@
1
- const o = "3.24.0-beta.003db4c", s = { stripo: { version: "2.83.1" } }, t = {
1
+ const o = "3.24.0-beta.0aa04e8", s = { stripo: { version: "2.83.1" } }, a = {
2
2
  version: o,
3
3
  guido: s
4
4
  };
5
5
  export {
6
- t as default,
6
+ a as default,
7
7
  s as guido,
8
8
  o as version
9
9
  };
@@ -1,4 +1,4 @@
1
- import type { LegacyPaddingViewport, LegacyProductConfig, LegacyVariable } from './types';
1
+ import type { LegacyPaddingViewport, LegacyVariable } from './types';
2
2
  export declare function extractTitleText(block: Element): string;
3
3
  /**
4
4
  * Fallback for legacy configs that carry no `p_recommendation_title` variable:
@@ -50,13 +50,6 @@ export declare function extractCurrencyFromBlock(block: Element): Record<string,
50
50
  * @returns The row's `es-p{n}{side}` padding, or undefined when the block has no product row
51
51
  */
52
52
  export declare function extractRenderedBlockPadding(block: Element): LegacyPaddingViewport | undefined;
53
- /**
54
- * Settings and styling as the legacy block renders them, for blocks with no `esd-dev-product-config`.
55
- * Themes come from the first card's inline CSS, in the shape the config-driven path already maps.
56
- * @param block - The legacy recommendation block element
57
- * @returns A product config holding only what the rendered markup shows; absent fields fall back to the mappers' defaults
58
- */
59
- export declare function inferLegacyConfig(block: Element): LegacyProductConfig;
60
53
  /**
61
54
  * True when a PM has manually opted the legacy block out of content
62
55
  * regeneration by adding the `ins-skip-compile` class. Detected before rebuild
@@ -1,10 +1,10 @@
1
1
  import type { LegacyProductConfig } from './types';
2
- export declare const LEGACY_CONFIG_ATTR = "esd-dev-product-config";
3
2
  /**
4
3
  * `esd-dev-product-config` is double-HTML-encoded JSON: serialization
5
4
  * escapes once to embed inside the attribute, and Stripo's templating
6
5
  * layer escapes a second time when round-tripping. Returns `null` when
7
- * the attribute is missing or unable to be parsed.
6
+ * the attribute is missing or unable to be parsed — the caller treats
7
+ * either case as an abort.
8
8
  */
9
9
  export declare function parseLegacyConfig(block: Element): LegacyProductConfig | null;
10
10
  /**
@@ -1,6 +1,7 @@
1
1
  /**
2
- * Idempotent: the selector matches only blocks that lack `recommendation-block-v2`,
3
- * so re-running on a migrated template is a no-op.
2
+ * Idempotent: the selector matches only blocks that have
3
+ * `esd-dev-product-config` AND lack `recommendation-block-v2`, so
4
+ * re-running on a migrated template is a no-op.
4
5
  */
5
6
  import type { LegacyRecommendationConfig } from '@@/Types/config';
6
7
  /**
@@ -9,4 +9,5 @@ export declare const DATA_ATTRIBUTES: {
9
9
  readonly BLOCK_ID: "data-unsubscribe-block-id";
10
10
  };
11
11
  export declare const UNSUBSCRIBE_BLOCK_SELECTOR = ".unsubscribe-block-v2";
12
+ export declare const UNSUBSCRIBE_MERGE_TAG_REGEX: RegExp;
12
13
  export declare const UNSUBSCRIBE_LINK_SELECTOR = "a[data-unsubscribe-link=\"true\"], a.unsubscribe-link";
@@ -0,0 +1 @@
1
+ export declare const swapMergeTagInHref: (href: string, mergeTag: string) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useinsider/guido",
3
- "version": "3.24.0-beta.003db4c",
3
+ "version": "3.24.0-beta.0aa04e8",
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",