@useinsider/guido 3.9.0-beta.f67c6c8 → 3.9.0-beta.fcaa08b

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,185 +1,201 @@
1
- import { useConfig as _ } from "../../../composables/useConfig.js";
1
+ import { useConfig as C } from "../../../composables/useConfig.js";
2
2
  import { useRecommendation as g } from "../../../composables/useRecommendation.js";
3
3
  import { CSS_CLASS_RECO_BUTTON as q } from "../../../extensions/Blocks/Recommendation/constants/selectors.js";
4
- import { useRecommendationExtensionStore as C } from "../../../extensions/Blocks/Recommendation/store/recommendation.js";
4
+ import { useRecommendationExtensionStore as E } from "../../../extensions/Blocks/Recommendation/store/recommendation.js";
5
5
  import { isIgnoredRecommendationBlock as w } from "./recommendationIgnoreUtils.js";
6
- function f(t, o, e, n, s = "") {
7
- const i = `{{${s}${t}_${o}_${e}}}`, r = `{{${s}${t}_${o}_currency}}`;
8
- return n === "before" ? `${r} ${i}` : `${i} ${r}`;
6
+ function b(t, n, e, o, c = "") {
7
+ const i = `{{${c}${t}_${n}_${e}}}`, r = `{{${c}${t}_${n}_currency}}`;
8
+ return o === "before" ? `${r} ${i}` : `${i} ${r}`;
9
9
  }
10
10
  function m(t) {
11
- let o = t;
12
- for (; o.children.length === 1; )
13
- [o] = o.children;
14
- return o;
11
+ let n = t;
12
+ for (; n.children.length === 1; )
13
+ [n] = n.children;
14
+ return n;
15
15
  }
16
- function h(t, o, e, n, s, i) {
17
- switch (o) {
16
+ function y(t, n, e, o, c, i) {
17
+ switch (n) {
18
18
  case "productImage": {
19
19
  const r = t.querySelector("img");
20
- r && (r.setAttribute("src", `{{${i}${e}_${n}_image_url}}`), r.setAttribute("alt", `{{${i}${e}_${n}_name}}`));
21
- const c = t.querySelector("a");
22
- c && (c.setAttribute("href", `{{${i}${e}_${n}_url}}`), c.classList.add(q));
20
+ r && (r.setAttribute("src", `{{${i}${e}_${o}_image_url}}`), r.setAttribute("alt", `{{${i}${e}_${o}_name}}`));
21
+ const s = t.querySelector("a");
22
+ s && (s.setAttribute("href", `{{${i}${e}_${o}_url}}`), s.classList.add(q));
23
23
  break;
24
24
  }
25
25
  case "productName": {
26
26
  const r = t.querySelector("p");
27
- r && (m(r).textContent = `{{${i}${e}_${n}_name}}`);
27
+ r && (m(r).textContent = `{{${i}${e}_${o}_name}}`);
28
28
  break;
29
29
  }
30
30
  case "productPrice": {
31
31
  const r = t.querySelector(".product-price p") ?? t.querySelector("p");
32
- r && (m(r).textContent = f(
32
+ r && (m(r).textContent = b(
33
33
  e,
34
- n,
34
+ o,
35
35
  "price",
36
- s,
36
+ c,
37
37
  i
38
38
  ));
39
- const c = t.querySelector(".product-old-price p");
40
- c && (m(c).textContent = f(
39
+ const s = t.querySelector(".product-old-price p");
40
+ s && (m(s).textContent = b(
41
41
  e,
42
- n,
42
+ o,
43
43
  "original_price",
44
- s,
44
+ c,
45
45
  i
46
46
  ));
47
47
  break;
48
48
  }
49
49
  case "productOldPrice": {
50
50
  const r = t.querySelector("p");
51
- r && (m(r).textContent = f(
51
+ r && (m(r).textContent = b(
52
52
  e,
53
- n,
53
+ o,
54
54
  "original_price",
55
- s,
55
+ c,
56
56
  i
57
57
  ));
58
58
  break;
59
59
  }
60
60
  case "productButton": {
61
61
  const r = t.querySelector("a");
62
- r && r.setAttribute("href", `{{${i}${e}_${n}_url}}`);
62
+ r && r.setAttribute("href", `{{${i}${e}_${o}_url}}`);
63
63
  break;
64
64
  }
65
65
  case "productOmnibusPrice": {
66
66
  const r = t.querySelector(".omnibus-price-value");
67
67
  if (r) {
68
- r.textContent = `{{${i}${e}_${n}_omnibus_price}}`;
69
- const c = r.closest("p");
70
- c && (c.setAttribute("product-attr", "omnibus_price"), c.setAttribute("composition", "true"));
68
+ r.textContent = `{{${i}${e}_${o}_omnibus_price}}`;
69
+ const s = r.closest("p");
70
+ s && (s.setAttribute("product-attr", "omnibus_price"), s.setAttribute("composition", "true"));
71
71
  }
72
72
  break;
73
73
  }
74
74
  case "productOmnibusDiscount": {
75
75
  const r = t.querySelector(".omnibus-discount-value");
76
76
  if (r) {
77
- r.textContent = `{{${i}${e}_${n}_omnibus_discount}}`;
78
- const c = r.closest("p");
79
- c && (c.setAttribute("product-attr", "omnibus_discount"), c.setAttribute("composition", "true"));
77
+ r.textContent = `{{${i}${e}_${o}_omnibus_discount}}`;
78
+ const s = r.closest("p");
79
+ s && (s.setAttribute("product-attr", "omnibus_discount"), s.setAttribute("composition", "true"));
80
80
  }
81
81
  break;
82
82
  }
83
83
  default: {
84
84
  const r = t.getAttribute("product-attr") ? t : t.querySelector("[product-attr]");
85
85
  if (r) {
86
- const c = r.getAttribute("product-attr"), l = r.querySelector("p");
87
- l && (m(l).textContent = `{{${i}${e}_${n}_${c}}}`);
86
+ const s = r.getAttribute("product-attr"), a = r.querySelector("p");
87
+ a && (m(a).textContent = `{{${i}${e}_${o}_${s}}}`);
88
88
  }
89
89
  break;
90
90
  }
91
91
  }
92
92
  }
93
- function E(t, o, e, n) {
93
+ const R = "name";
94
+ function S(t, n, e, o) {
95
+ const c = `${o}${n}_${e}_${R}`;
96
+ return {
97
+ open: t.createComment(`{% if ${c} and ${c} != "" %}`),
98
+ close: t.createComment("{% endif %}")
99
+ };
100
+ }
101
+ function P(t, n, e, o) {
102
+ if (!t.innerHTML.includes("{{"))
103
+ return;
104
+ const { open: c, close: i } = S(t.ownerDocument, n, e, o);
105
+ t.insertBefore(c, t.firstChild), t.appendChild(i);
106
+ }
107
+ function T(t, n, e, o) {
108
+ if (!t.innerHTML.includes("{{"))
109
+ return;
110
+ const { open: c, close: i } = S(t.ownerDocument, n, e, o), r = t.parentNode;
111
+ r.insertBefore(c, t), r.insertBefore(i, t.nextSibling);
112
+ }
113
+ function L(t, n, e, o) {
94
114
  t.querySelectorAll(".recommendation-product-row").forEach((i, r) => {
95
- i.querySelectorAll("[data-attribute-type]").forEach((l) => {
96
- const u = l.getAttribute("data-attribute-type") || "", p = l.querySelectorAll(".attribute-cell");
97
- p.length > 0 ? p.forEach((a) => {
98
- h(a, u, o, r, e, n);
99
- }) : h(l, u, o, r, e, n);
100
- });
115
+ i.querySelectorAll("[data-attribute-type]").forEach((a) => {
116
+ const u = a.getAttribute("data-attribute-type") || "", p = a.querySelectorAll(".attribute-cell");
117
+ p.length > 0 ? p.forEach((l) => {
118
+ y(l, u, n, r, e, o);
119
+ }) : y(a, u, n, r, e, o);
120
+ }), T(i, n, r, o);
101
121
  });
102
122
  }
103
- function P(t, o, e, n) {
104
- const s = t.querySelectorAll(".recommendation-product-row");
105
- if (!s.length)
123
+ function O(t, n, e, o) {
124
+ const c = t.querySelectorAll(".recommendation-product-row");
125
+ if (!c.length)
106
126
  return;
107
- const [i] = s, r = i.querySelector("[data-attribute-type]"), c = r ? r.querySelectorAll(".attribute-cell").length : 1;
108
- s.forEach((l, u) => {
109
- l.querySelectorAll("[data-attribute-type]").forEach((a) => {
110
- const d = a.getAttribute("data-attribute-type") || "";
111
- a.querySelectorAll(".attribute-cell").forEach((A, $) => {
112
- const S = u * c + $;
113
- h(A, d, o, S, e, n);
127
+ const [i] = c, r = i.querySelector("[data-attribute-type]"), s = r ? r.querySelectorAll(".attribute-cell").length : 1;
128
+ c.forEach((a, u) => {
129
+ a.querySelectorAll("[data-attribute-type]").forEach((l) => {
130
+ const d = l.getAttribute("data-attribute-type") || "";
131
+ l.querySelectorAll(".attribute-cell").forEach(($, _) => {
132
+ const A = u * s + _;
133
+ y($, d, n, A, e, o), P($, n, A, o);
114
134
  });
115
135
  });
116
136
  });
117
137
  }
118
- function R(t, o, e, n) {
138
+ function v(t, n, e, o) {
119
139
  t.querySelectorAll(".ins-recommendation-product-container").forEach((i) => {
120
- P(i, o, e, n);
140
+ O(i, n, e, o);
121
141
  });
122
142
  }
123
- function v(t, o, e) {
124
- const n = t.getAttribute("data-layout") || "grid", s = t.getAttribute("currency-alignment") || "after";
125
- n === "list" ? E(t, o, s, e) : R(t, o, s, e);
126
- }
127
- function b(t, o, e) {
128
- const n = new RegExp(`${o}\\s*:\\s*(\\d+)\\s*px`, "i"), s = t.match(n);
129
- return s ? parseInt(s[1]) : e;
143
+ function B(t, n, e) {
144
+ const o = t.getAttribute("data-layout") || "grid", c = t.getAttribute("currency-alignment") || "after";
145
+ o === "list" ? L(t, n, c, e) : v(t, n, c, e);
130
146
  }
131
- function O(t) {
132
- const o = t.trim();
133
- return o.endsWith("%") ? parseFloat(o) < 100 : /^\d+(?:px)?$/.test(o) && parseInt(o) > 0;
147
+ function h(t, n, e) {
148
+ const o = new RegExp(`${n}\\s*:\\s*(\\d+)\\s*px`, "i"), c = t.match(o);
149
+ return c ? parseInt(c[1]) : e;
134
150
  }
135
- function T(t, o) {
151
+ function D(t, n) {
136
152
  let e = t.parentElement;
137
- for (; e && e !== o; ) {
153
+ for (; e && e !== n; ) {
138
154
  if (e.tagName === "TD") {
139
- const n = e.getAttribute("width");
140
- if (n && O(n))
155
+ const o = e.getAttribute("width");
156
+ if (o && o.endsWith("%") && parseFloat(o) < 100)
141
157
  return e;
142
158
  }
143
159
  e = e.parentElement;
144
160
  }
145
161
  return null;
146
162
  }
147
- function W(t) {
148
- const o = t.getAttribute("style") || "", e = b(o, "width", 600), n = b(o, "padding", 0) * 2, s = Math.max(0, e - n);
149
- s !== 0 && t.querySelectorAll("img.adapt-img").forEach((i) => {
163
+ function M(t) {
164
+ const n = t.getAttribute("style") || "", e = h(n, "width", 600), o = h(n, "padding", 0) * 2, c = Math.max(0, e - o);
165
+ c !== 0 && t.querySelectorAll("img.adapt-img").forEach((i) => {
150
166
  if (i.hasAttribute("width"))
151
167
  return;
152
- const r = T(i, t);
168
+ const r = D(i, t);
153
169
  if (!r)
154
170
  return;
155
- const c = r.getAttribute("width"), l = b(r.getAttribute("style") || "", "padding", 0) * 2, u = c.trim().endsWith("%") ? Math.floor(s * parseFloat(c) / 100) : parseInt(c), p = Math.max(1, u - l);
156
- i.setAttribute("width", String(p));
157
- const a = i.getAttribute("style") || "";
158
- if (!/\bwidth\s*:\s*\d/i.test(a)) {
159
- const d = a && !a.trim().endsWith(";") ? "; " : "";
160
- i.setAttribute("style", `${a}${d}width: ${p}px`);
171
+ const s = r.getAttribute("width"), a = parseFloat(s), u = h(r.getAttribute("style") || "", "padding", 0) * 2, p = Math.floor(c * a / 100), l = Math.max(1, p - u);
172
+ i.setAttribute("width", String(l));
173
+ const d = i.getAttribute("style") || "";
174
+ if (!/\bwidth\s*:\s*\d/i.test(d)) {
175
+ const f = d && !d.trim().endsWith(";") ? "; " : "";
176
+ i.setAttribute("style", `${d}${f}width: ${l}px`);
161
177
  }
162
178
  });
163
179
  }
164
- function B(t, o) {
180
+ function N(t, n) {
165
181
  const e = t.match(/<!DOCTYPE[^>]*>/i);
166
182
  return (e ? `${e[0]}
167
- ` : "") + o.documentElement.outerHTML;
183
+ ` : "") + n.documentElement.outerHTML;
168
184
  }
169
- function G(t) {
170
- const o = t.replaceAll("{%", "<!--{%").replaceAll("%}", "%}-->"), e = new DOMParser().parseFromString(o, "text/html"), n = e.querySelectorAll(".recommendation-block-v2");
171
- if (!n.length)
185
+ function k(t) {
186
+ const n = t.replaceAll("{%", "<!--{%").replaceAll("%}", "%}-->"), e = new DOMParser().parseFromString(n, "text/html"), o = e.querySelectorAll(".recommendation-block-v2");
187
+ if (!o.length)
172
188
  return t;
173
- const { buildCampaignUrl: s } = g(), i = C();
189
+ const { buildCampaignUrl: c } = g(), i = E();
174
190
  i.recommendationCampaignUrls = {};
175
- const { isFeatureEnabled: r } = _(), c = r("liquidSyntax") ? "reco_" : "";
176
- return n.forEach((u) => {
177
- var a, d;
191
+ const { isFeatureEnabled: r } = C(), s = r("liquidSyntax") ? "reco_" : "";
192
+ return o.forEach((u) => {
193
+ var l, d;
178
194
  const p = u.getAttribute("recommendation-id");
179
- p && ((a = u.parentNode) == null || a.insertBefore(e.createComment("REC_START"), u), (d = u.parentNode) == null || d.insertBefore(e.createComment("REC_END"), u.nextSibling), u.querySelectorAll('[data-visibility="0"]').forEach((y) => y.remove()), s(p), w(u) || v(u, p, c), W(u));
180
- }), B(o, e).replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}").replaceAll("&lt;!--{%", "{%").replaceAll("%}--&gt;", "%}");
195
+ p && ((l = u.parentNode) == null || l.insertBefore(e.createComment("REC_START"), u), (d = u.parentNode) == null || d.insertBefore(e.createComment("REC_END"), u.nextSibling), u.querySelectorAll('[data-visibility="0"]').forEach((f) => f.remove()), c(p), w(u) || B(u, p, s), M(u));
196
+ }), N(n, e).replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}").replaceAll("&lt;!--{%", "{%").replaceAll("%}--&gt;", "%}");
181
197
  }
182
198
  export {
183
- f as formatPriceVariable,
184
- G as prepareRecommendationBlocks
199
+ b as formatPriceVariable,
200
+ k as prepareRecommendationBlocks
185
201
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useinsider/guido",
3
- "version": "3.9.0-beta.f67c6c8",
3
+ "version": "3.9.0-beta.fcaa08b",
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",