@useinsider/guido 3.20.0-beta.12889e0 → 3.20.0-beta.30c96fc

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,6 +1,15 @@
1
1
  import { pairProductVariables as o } from "../../utils/pairProductVariables.js";
2
- import { wrapHiddenPriceTdsForOutlook as r, MSO_ITEMS_HIDE_START as e, MSO_ITEMS_HIDE_END as t } from "./utils/itemsCompilerUtils.js";
3
- const a = [
2
+ import { normalizeItemsBlockWidths as r, wrapHiddenPriceTdsForOutlook as e, MSO_ITEMS_HIDE_START as t, MSO_ITEMS_HIDE_END as s } from "./utils/itemsCompilerUtils.js";
3
+ const d = [
4
+ {
5
+ id: "normalize-items-block-widths",
6
+ // Runs before the other items rules so they see non-zero widths; not AMP-safe.
7
+ description: "Normalize zero Items card widths in the compiled email",
8
+ type: "custom",
9
+ processor: r,
10
+ priority: 55
11
+ // Before pair-product-variables (60)
12
+ },
4
13
  {
5
14
  id: "pair-product-variables",
6
15
  description: "Replace product default values with template variables",
@@ -16,7 +25,7 @@ const a = [
16
25
  // with safe placeholder comments and collapse them inline for web-engine Outlook.
17
26
  description: "Mark hidden Items price tds for Outlook conditional hiding",
18
27
  type: "custom",
19
- processor: r,
28
+ processor: e,
20
29
  priority: 65
21
30
  // After pair-product-variables (60), before outlook rules (70+)
22
31
  },
@@ -26,10 +35,10 @@ const a = [
26
35
  // and reco swap P100) keeps it out of every whitespace/comment-mangling pass.
27
36
  description: "Swap Items MSO markers into [if !mso] conditional comments",
28
37
  type: "custom",
29
- processor: (i) => i.replaceAll(`<!--${e}-->`, "<!--[if !mso]><!-- -->").replaceAll(`<!--${t}-->`, "<!--<![endif]-->"),
38
+ processor: (i) => i.replaceAll(`<!--${t}-->`, "<!--[if !mso]><!-- -->").replaceAll(`<!--${s}-->`, "<!--<![endif]-->"),
30
39
  priority: 101
31
40
  }
32
41
  ];
33
42
  export {
34
- a as itemsCompilerRules
43
+ d as itemsCompilerRules
35
44
  };
@@ -1,28 +1,55 @@
1
- const p = "MSO_ITEMS_HIDE_START", E = "MSO_ITEMS_HIDE_END", u = "mso-hide:all; max-height:0; overflow:hidden; font-size:0; line-height:0;", _ = ".ins-product-cart td.horizontal-price, .ins-product-cart td.vertical-price";
2
- function T(t) {
3
- if (!t.includes("vertical-price") || !t.includes("ins-product-cart"))
4
- return t;
5
- const i = t.replaceAll("{%", "<!--{%").replaceAll("%}", "%}-->"), r = new DOMParser().parseFromString(i, "text/html");
6
- let n = !1;
7
- if (r.querySelectorAll(_).forEach((e) => {
8
- var s, a;
9
- const o = e.getAttribute("style") || "";
1
+ import { PRODUCT_WRAPPER_SELECTOR as A, hasZeroWidthDeclaration as E, isZeroWidthValue as u, withWidthPin as h, PRODUCT_TD_SELECTOR as S, withoutZeroWidth as _ } from "../../../extensions/Blocks/Items/constants/cardWidth.js";
2
+ import { protectLiquid as m, restoreLiquid as y } from "../../../utils/liquidProtection.js";
3
+ const f = "MSO_ITEMS_HIDE_START", D = "MSO_ITEMS_HIDE_END", T = "mso-hide:all; max-height:0; overflow:hidden; font-size:0; line-height:0;", M = ".ins-product-cart td.horizontal-price, .ins-product-cart td.vertical-price";
4
+ function g(e) {
5
+ if (!e.includes("vertical-price") || !e.includes("ins-product-cart"))
6
+ return e;
7
+ const n = e.replaceAll("{%", "<!--{%").replaceAll("%}", "%}-->"), r = new DOMParser().parseFromString(n, "text/html");
8
+ let s = !1;
9
+ if (r.querySelectorAll(M).forEach((t) => {
10
+ var d, a;
11
+ const o = t.getAttribute("style") || "";
10
12
  if (!/display\s*:\s*none/i.test(o))
11
13
  return;
12
- const c = e.previousSibling;
13
- if (((c == null ? void 0 : c.nodeType) !== Node.COMMENT_NODE || c.data !== p) && ((s = e.parentNode) == null || s.insertBefore(r.createComment(p), e), (a = e.parentNode) == null || a.insertBefore(r.createComment(E), e.nextSibling)), !/mso-hide/i.test(o)) {
14
- const d = o.trim().endsWith(";") ? " " : "; ";
15
- e.setAttribute("style", `${o}${d}${u}`);
14
+ const l = t.previousSibling;
15
+ if (((l == null ? void 0 : l.nodeType) !== Node.COMMENT_NODE || l.data !== f) && ((d = t.parentNode) == null || d.insertBefore(r.createComment(f), t), (a = t.parentNode) == null || a.insertBefore(r.createComment(D), t.nextSibling)), !/mso-hide/i.test(o)) {
16
+ const p = o.trim().endsWith(";") ? " " : "; ";
17
+ t.setAttribute("style", `${o}${p}${T}`);
16
18
  }
17
- n = !0;
18
- }), !n)
19
- return t;
20
- const l = i.match(/<!DOCTYPE[^>]*>/i);
21
- return ((l ? `${l[0]}
19
+ s = !0;
20
+ }), !s)
21
+ return e;
22
+ const c = n.match(/<!DOCTYPE[^>]*>/i);
23
+ return ((c ? `${c[0]}
22
24
  ` : "") + r.documentElement.outerHTML).replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}").replaceAll("&lt;!--{%", "{%").replaceAll("%}--&gt;", "%}");
23
25
  }
26
+ function I(e) {
27
+ if (!e.includes("ins-product-wrapper") && !e.includes("ins-product-td"))
28
+ return e;
29
+ const n = new DOMParser().parseFromString(m(e), "text/html");
30
+ let r = !1;
31
+ if (n.querySelectorAll(A).forEach((i) => {
32
+ const t = i.getAttribute("style") || "";
33
+ if (!E(t) && !u(i.getAttribute("width")))
34
+ return;
35
+ const o = h(t);
36
+ o !== t && (i.setAttribute("style", o), r = !0), u(i.getAttribute("width")) && (i.setAttribute("width", "100%"), r = !0);
37
+ }), n.querySelectorAll(S).forEach((i) => {
38
+ const t = i.getAttribute("style") || "";
39
+ if (E(t)) {
40
+ const o = _(t);
41
+ o ? i.setAttribute("style", o) : i.removeAttribute("style"), r = !0;
42
+ }
43
+ u(i.getAttribute("width")) && (i.removeAttribute("width"), r = !0);
44
+ }), !r)
45
+ return e;
46
+ const s = e.match(/<!DOCTYPE[^>]*>/i), c = s ? `${s[0]}
47
+ ` : "";
48
+ return y(c + n.documentElement.outerHTML);
49
+ }
24
50
  export {
25
- E as MSO_ITEMS_HIDE_END,
26
- p as MSO_ITEMS_HIDE_START,
27
- T as wrapHiddenPriceTdsForOutlook
51
+ D as MSO_ITEMS_HIDE_END,
52
+ f as MSO_ITEMS_HIDE_START,
53
+ I as normalizeItemsBlockWidths,
54
+ g as wrapHiddenPriceTdsForOutlook
28
55
  };
@@ -1,10 +1,9 @@
1
- import { useConfig as O } from "../../../composables/useConfig.js";
2
- import { useRecommendation as q } from "../../../composables/useRecommendation.js";
3
- import { MOBILE_ROW_SELECTOR as L, MOBILE_CONTAINER_SELECTOR as M, CSS_CLASS_RECO_BUTTON as P } from "../../../extensions/Blocks/Recommendation/constants/selectors.js";
4
- import { useRecommendationExtensionStore as R } from "../../../extensions/Blocks/Recommendation/store/recommendation.js";
5
- import { FLUID_IMAGE_MOBILE_RULE as T, getFluidImageStyleChanges as B } from "../../../utils/fluidImageStyle.js";
6
- import { isIgnoredRecommendationBlock as N } from "./recommendationIgnoreUtils.js";
7
- function D(t, r, e, o, c = "") {
1
+ import { useConfig as g } from "../../../composables/useConfig.js";
2
+ import { useRecommendation as O } from "../../../composables/useRecommendation.js";
3
+ import { MOBILE_ROW_SELECTOR as q, MOBILE_CONTAINER_SELECTOR as M, CSS_CLASS_RECO_BUTTON as B } from "../../../extensions/Blocks/Recommendation/constants/selectors.js";
4
+ import { useRecommendationExtensionStore as N } from "../../../extensions/Blocks/Recommendation/store/recommendation.js";
5
+ import { isIgnoredRecommendationBlock as T } from "./recommendationIgnoreUtils.js";
6
+ function L(t, r, e, o, c = "") {
8
7
  const i = `{{${c}${t}_${r}_${e}}}`, n = `{{${c}${t}_${r}_currency}}`;
9
8
  return o === "before" ? `${n} ${i}` : `${i} ${n}`;
10
9
  }
@@ -14,13 +13,13 @@ function _(t) {
14
13
  [r] = r.children;
15
14
  return r;
16
15
  }
17
- function E(t, r, e, o, c, i) {
16
+ function A(t, r, e, o, c, i) {
18
17
  switch (r) {
19
18
  case "productImage": {
20
19
  const n = t.querySelector("img");
21
20
  n && (n.setAttribute("src", `{{${i}${e}_${o}_image_url}}`), n.setAttribute("alt", `{{${i}${e}_${o}_name}}`));
22
21
  const s = t.querySelector("a");
23
- s && (s.setAttribute("href", `{{${i}${e}_${o}_url}}`), s.classList.add(P));
22
+ s && (s.setAttribute("href", `{{${i}${e}_${o}_url}}`), s.classList.add(B));
24
23
  break;
25
24
  }
26
25
  case "productName": {
@@ -34,7 +33,7 @@ function E(t, r, e, o, c, i) {
34
33
  case "productPrice":
35
34
  case "productOldPrice": {
36
35
  const n = (l, d) => {
37
- l && (_(l).textContent = D(
36
+ l && (_(l).textContent = L(
38
37
  e,
39
38
  o,
40
39
  d,
@@ -78,24 +77,24 @@ function E(t, r, e, o, c, i) {
78
77
  }
79
78
  }
80
79
  }
81
- const w = "name";
80
+ const P = "name";
82
81
  function b(t, r, e, o) {
83
- const c = `${o}${r}_${e}_${w}`;
82
+ const c = `${o}${r}_${e}_${P}`;
84
83
  return {
85
84
  open: t.createComment(`{% if ${c} and ${c} != "" %}`),
86
85
  close: t.createComment("{% endif %}")
87
86
  };
88
87
  }
89
- function F(t, r, e) {
88
+ function R(t, r, e) {
90
89
  return b(t, r, 0, e);
91
90
  }
92
- function v(t, r, e, o) {
91
+ function D(t, r, e, o) {
93
92
  if (!t.innerHTML.includes("{{"))
94
93
  return;
95
94
  const { open: c, close: i } = b(t.ownerDocument, r, e, o);
96
95
  t.insertBefore(c, t.firstChild), t.appendChild(i);
97
96
  }
98
- function H(t, r, e, o) {
97
+ function w(t, r, e, o) {
99
98
  var n, s;
100
99
  if (!t.innerHTML.includes("{{"))
101
100
  return;
@@ -107,36 +106,36 @@ function W(t, r, e, o) {
107
106
  i.querySelectorAll("[data-attribute-type]").forEach((a) => {
108
107
  const u = a.getAttribute("data-attribute-type") || "", l = a.querySelectorAll(".attribute-cell");
109
108
  l.length > 0 ? l.forEach((d) => {
110
- E(d, u, r, n, e, o);
111
- }) : E(a, u, r, n, e, o);
112
- }), H(i, r, n, o);
109
+ A(d, u, r, n, e, o);
110
+ }) : A(a, u, r, n, e, o);
111
+ }), w(i, r, n, o);
113
112
  });
114
113
  }
115
- function G(t, r, e, o) {
114
+ function v(t, r, e, o) {
116
115
  const c = t.querySelectorAll(".recommendation-product-row");
117
116
  if (!c.length)
118
117
  return;
119
118
  const [i] = c, n = i.querySelector("[data-attribute-type]"), s = n ? n.querySelectorAll(".attribute-cell").length : 1;
120
119
  c.forEach((a, u) => {
121
120
  a.querySelectorAll("[data-attribute-type]").forEach((d) => {
122
- const f = d.getAttribute("data-attribute-type") || "";
123
- d.querySelectorAll(".attribute-cell").forEach((p, m) => {
124
- const y = u * s + m;
125
- E(p, f, r, y, e, o), v(p, r, y, o);
121
+ const p = d.getAttribute("data-attribute-type") || "";
122
+ d.querySelectorAll(".attribute-cell").forEach((f, m) => {
123
+ const h = u * s + m;
124
+ A(f, p, r, h, e, o), D(f, r, h, o);
126
125
  });
127
126
  });
128
127
  });
129
128
  }
130
- function U(t, r, e, o) {
129
+ function H(t, r, e, o) {
131
130
  t.querySelectorAll(".ins-recommendation-product-container").forEach((i) => {
132
- G(i, r, e, o);
131
+ v(i, r, e, o);
133
132
  });
134
133
  }
135
- function I(t, r, e) {
134
+ function F(t, r, e) {
136
135
  const o = t.getAttribute("data-layout") || "grid", c = t.getAttribute("currency-alignment") || "after";
137
- o === "list" ? W(t, r, c, e) : U(t, r, c, e);
136
+ o === "list" ? W(t, r, c, e) : H(t, r, c, e);
138
137
  }
139
- function S(t, r, e) {
138
+ function y(t, r, e) {
140
139
  const o = new RegExp(`${r}\\s*:\\s*(\\d+)\\s*px`, "i"), c = t.match(o);
141
140
  return c ? parseInt(c[1]) : e;
142
141
  }
@@ -151,7 +150,7 @@ function C(t) {
151
150
  const e = (t.getAttribute("style") || "").match(/(?:^|[;\s])width\s*:\s*(\d+(?:\.\d+)?(?:px|%))/i);
152
151
  return e && $(e[1]) ? e[1] : null;
153
152
  }
154
- function V(t, r) {
153
+ function G(t, r) {
155
154
  let e = t.parentElement;
156
155
  for (; e && e !== r; ) {
157
156
  if (e.tagName === "TD" && C(e))
@@ -160,74 +159,60 @@ function V(t, r) {
160
159
  }
161
160
  return null;
162
161
  }
163
- function A(t) {
164
- const r = B(
165
- (e) => t.style.getPropertyValue(e),
166
- t.getAttribute("width")
167
- );
168
- Object.entries(r).forEach(([e, o]) => t.style.setProperty(e, o));
169
- }
170
- function X(t) {
171
- const r = t.getAttribute("style") || "", e = S(r, "width", 600), o = S(r, "padding", 0) * 2, c = Math.max(0, e - o);
172
- t.querySelectorAll("img.adapt-img").forEach((i) => {
173
- if (i.hasAttribute("width") || c === 0) {
174
- A(i);
162
+ function V(t) {
163
+ const r = t.getAttribute("style") || "", e = y(r, "width", 600), o = y(r, "padding", 0) * 2, c = Math.max(0, e - o);
164
+ c !== 0 && t.querySelectorAll("img.adapt-img").forEach((i) => {
165
+ if (i.hasAttribute("width"))
175
166
  return;
176
- }
177
- const n = V(i, t);
178
- if (!n) {
179
- A(i);
167
+ const n = G(i, t);
168
+ if (!n)
180
169
  return;
170
+ const s = C(n), a = y(n.getAttribute("style") || "", "padding", 0) * 2, u = s.endsWith("%") ? Math.floor(c * parseFloat(s) / 100) : parseInt(s), l = Math.max(1, u - a);
171
+ i.setAttribute("width", String(l));
172
+ const d = i.getAttribute("style") || "";
173
+ if (!/\bwidth\s*:\s*\d/i.test(d)) {
174
+ const p = d && !d.trim().endsWith(";") ? "; " : "";
175
+ i.setAttribute("style", `${d}${p}width: ${l}px`);
181
176
  }
182
- const s = C(n), a = S(n.getAttribute("style") || "", "padding", 0) * 2, u = s.endsWith("%") ? Math.floor(c * parseFloat(s) / 100) : parseInt(s), l = Math.max(1, u - a);
183
- i.setAttribute("width", String(l)), A(i);
184
177
  });
185
178
  }
186
- const j = /\.recommendation-block-v2\s+\.adapt-img/;
187
- function x(t, r) {
188
- const e = r.some((i) => i.querySelector("img.adapt-img")), o = Array.from(t.querySelectorAll("style")).some((i) => j.test(i.textContent ?? ""));
189
- if (!e || o || !t.head)
190
- return;
191
- const c = t.createElement("style");
192
- c.setAttribute("type", "text/css"), c.textContent = T, t.head.appendChild(c);
193
- }
194
- const g = "MSO_MOBILE_HIDE_START", Y = "MSO_MOBILE_HIDE_END";
195
- function k(t, r) {
196
- t.querySelectorAll(L).forEach((e) => {
179
+ const E = "MSO_MOBILE_HIDE_START", U = "MSO_MOBILE_HIDE_END";
180
+ function X(t, r) {
181
+ t.querySelectorAll(q).forEach((e) => {
197
182
  var i, n;
198
183
  const o = e.querySelector(M);
199
184
  if (!o || o.children.length === 0)
200
185
  return;
201
186
  const c = e.previousSibling;
202
- (c == null ? void 0 : c.nodeType) === Node.COMMENT_NODE && c.data === g || ((i = e.parentNode) == null || i.insertBefore(r.createComment(g), e), (n = e.parentNode) == null || n.insertBefore(r.createComment(Y), e.nextSibling));
187
+ (c == null ? void 0 : c.nodeType) === Node.COMMENT_NODE && c.data === E || ((i = e.parentNode) == null || i.insertBefore(r.createComment(E), e), (n = e.parentNode) == null || n.insertBefore(r.createComment(U), e.nextSibling));
203
188
  });
204
189
  }
205
- function z(t, r) {
190
+ function j(t, r) {
206
191
  const e = t.match(/<!DOCTYPE[^>]*>/i);
207
192
  return (e ? `${e[0]}
208
193
  ` : "") + r.documentElement.outerHTML;
209
194
  }
210
- function rt(t) {
195
+ function Q(t) {
211
196
  const r = t.replaceAll("{%", "<!--{%").replaceAll("%}", "%}-->"), e = new DOMParser().parseFromString(r, "text/html"), o = e.querySelectorAll(".recommendation-block-v2");
212
197
  if (!o.length)
213
198
  return t;
214
- const { buildCampaignUrl: c } = q(), i = R();
199
+ const { buildCampaignUrl: c } = O(), i = N();
215
200
  i.recommendationCampaignUrls = {};
216
- const { isFeatureEnabled: n } = O(), s = n("liquidSyntax") ? "reco_" : "";
201
+ const { isFeatureEnabled: n } = g(), s = n("liquidSyntax") ? "reco_" : "";
217
202
  return o.forEach((u) => {
218
- var d, f, h, p;
203
+ var d, p, S, f;
219
204
  const l = u.getAttribute("recommendation-id");
220
205
  if (l) {
221
- if ((d = u.parentNode) == null || d.insertBefore(e.createComment("REC_START"), u), (f = u.parentNode) == null || f.insertBefore(e.createComment("REC_END"), u.nextSibling), u.querySelectorAll('[data-visibility="0"]').forEach((m) => m.remove()), c(l), k(u, e), !N(u)) {
222
- I(u, l, s);
223
- const { open: m, close: y } = F(e, l, s);
224
- (h = u.parentNode) == null || h.insertBefore(m, u), (p = u.parentNode) == null || p.insertBefore(y, u.nextSibling);
206
+ if ((d = u.parentNode) == null || d.insertBefore(e.createComment("REC_START"), u), (p = u.parentNode) == null || p.insertBefore(e.createComment("REC_END"), u.nextSibling), u.querySelectorAll('[data-visibility="0"]').forEach((m) => m.remove()), c(l), X(u, e), !T(u)) {
207
+ F(u, l, s);
208
+ const { open: m, close: h } = R(e, l, s);
209
+ (S = u.parentNode) == null || S.insertBefore(m, u), (f = u.parentNode) == null || f.insertBefore(h, u.nextSibling);
225
210
  }
226
- X(u);
211
+ V(u);
227
212
  }
228
- }), x(e, Array.from(o)), z(r, e).replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}").replaceAll("&lt;!--{%", "{%").replaceAll("%}--&gt;", "%}");
213
+ }), j(r, e).replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}").replaceAll("&lt;!--{%", "{%").replaceAll("%}--&gt;", "%}");
229
214
  }
230
215
  export {
231
- D as formatPriceVariable,
232
- rt as prepareRecommendationBlocks
216
+ L as formatPriceVariable,
217
+ Q as prepareRecommendationBlocks
233
218
  };