ui.shipaid.com 0.3.134 → 0.3.136

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.
package/dist/widget.es.js CHANGED
@@ -5854,6 +5854,42 @@ class ShipAidCheckoutPlus extends s$1 {
5854
5854
  } catch {
5855
5855
  }
5856
5856
  }
5857
+ // Collect shadow roots from store config (string or string[])
5858
+ _getConfiguredShadowRoots() {
5859
+ var _a, _b;
5860
+ const roots = [];
5861
+ try {
5862
+ const raw = (_b = (_a = this._store) == null ? void 0 : _a.checkoutPlus) == null ? void 0 : _b.shadowRootSelector;
5863
+ const selectors = Array.isArray(raw) ? raw.filter(Boolean) : typeof raw === "string" && raw.trim() ? [raw.trim()] : [];
5864
+ for (const sel of selectors) {
5865
+ const host = document.querySelector(sel);
5866
+ if (host == null ? void 0 : host.shadowRoot) roots.push(host.shadowRoot);
5867
+ }
5868
+ } catch {
5869
+ }
5870
+ return roots;
5871
+ }
5872
+ // Find a flex/grid ancestor and tag it so embed app CSS can make our widget span a full row
5873
+ _prepareParentContainer(btn) {
5874
+ if (!btn) return;
5875
+ try {
5876
+ let el = btn.parentElement;
5877
+ let depth = 0;
5878
+ while (el && depth < 3) {
5879
+ const cs = window.getComputedStyle(el);
5880
+ const display = (cs.display || "").toLowerCase();
5881
+ const isFlex = display === "flex" || display === "inline-flex";
5882
+ const isGrid = display === "grid" || display === "inline-grid";
5883
+ if (isFlex && cs.flexDirection !== "column" || isGrid) {
5884
+ el.setAttribute("shipaid-parent-container", "");
5885
+ return;
5886
+ }
5887
+ el = el.parentElement;
5888
+ depth++;
5889
+ }
5890
+ } catch {
5891
+ }
5892
+ }
5857
5893
  // Copy visual styles from the original checkout button so our primary button matches
5858
5894
  _applyButtonStylesFrom(btn, customStyles = {}) {
5859
5895
  if (!btn) return;
@@ -5950,7 +5986,7 @@ class ShipAidCheckoutPlus extends s$1 {
5950
5986
  }
5951
5987
  }
5952
5988
  _mountNearCheckoutButton() {
5953
- var _a, _b, _c, _d, _e;
5989
+ var _a, _b, _c, _d, _e, _f;
5954
5990
  if (!this.isConnected) return;
5955
5991
  if (!this._shouldShowWidget()) return;
5956
5992
  this._removeLegacyV1();
@@ -5959,7 +5995,38 @@ class ShipAidCheckoutPlus extends s$1 {
5959
5995
  const customStyles = ((_e = (_d = this._store) == null ? void 0 : _d.checkoutPlus) == null ? void 0 : _e.styles) || {};
5960
5996
  const provided = (dbSelector || this.dataSelector || "").trim();
5961
5997
  const selectors = provided ? provided.split(",").map((s3) => s3.trim()).filter(Boolean) : DEFAULT_CHECKOUT_SELECTORS;
5962
- const matches = Array.from(document.querySelectorAll(selectors.join(", ")));
5998
+ const localRoot = this.getRootNode() || document;
5999
+ const rootsSet = /* @__PURE__ */ new Set([document]);
6000
+ if (localRoot) rootsSet.add(localRoot);
6001
+ for (const sr of this._getConfiguredShadowRoots()) rootsSet.add(sr);
6002
+ for (const root of Array.from(rootsSet)) {
6003
+ if (root.host) {
6004
+ try {
6005
+ const STYLE_ID = "shipaid-styles";
6006
+ const existing = (_f = root.querySelector) == null ? void 0 : _f.call(root, `#${STYLE_ID}`);
6007
+ if (!existing) {
6008
+ const styleEl = document.createElement("style");
6009
+ styleEl.id = STYLE_ID;
6010
+ styleEl.textContent = `
6011
+ [shipaid-hidden] { display: none !important; }
6012
+ [shipaid-parent-container] { flex-wrap: wrap !important; }
6013
+ [shipaid-parent-container] > shipaid-widget-v2,
6014
+ [shipaid-parent-container] > shipaid-checkout-plus { flex: 1 0 100% !important; max-width: 100% !important; grid-column: 1 / -1 !important; }
6015
+ `;
6016
+ root.appendChild(styleEl);
6017
+ }
6018
+ } catch {
6019
+ }
6020
+ }
6021
+ }
6022
+ const matches = [];
6023
+ for (const root of Array.from(rootsSet)) {
6024
+ try {
6025
+ const list = Array.from(root.querySelectorAll(selectors.join(", ")));
6026
+ matches.push(...list);
6027
+ } catch {
6028
+ }
6029
+ }
5963
6030
  if (!matches.length) return;
5964
6031
  if (this.isClone) {
5965
6032
  const target = matches[0];
@@ -5967,8 +6034,9 @@ class ShipAidCheckoutPlus extends s$1 {
5967
6034
  this._applyButtonStylesFrom(target, customStyles || {});
5968
6035
  target.setAttribute("data-shipaid-replaced", "true");
5969
6036
  if (!target.hasAttribute("shipaid-hidden")) target.setAttribute("shipaid-hidden", "");
6037
+ this._prepareParentContainer(target);
5970
6038
  if (this.previousElementSibling !== target && this.nextElementSibling !== target) {
5971
- target.insertAdjacentElement("afterend", this);
6039
+ target.insertAdjacentElement("beforebegin", this);
5972
6040
  }
5973
6041
  return;
5974
6042
  }
@@ -5978,8 +6046,9 @@ class ShipAidCheckoutPlus extends s$1 {
5978
6046
  this._applyButtonStylesFrom(first, customStyles || {});
5979
6047
  first.setAttribute("data-shipaid-replaced", "true");
5980
6048
  if (!first.hasAttribute("shipaid-hidden")) first.setAttribute("shipaid-hidden", "");
6049
+ this._prepareParentContainer(first);
5981
6050
  if (this.previousElementSibling !== first && this.nextElementSibling !== first) {
5982
- first.insertAdjacentElement("afterend", this);
6051
+ first.insertAdjacentElement("beforebegin", this);
5983
6052
  }
5984
6053
  }
5985
6054
  for (const btn of rest) {
@@ -5999,7 +6068,8 @@ class ShipAidCheckoutPlus extends s$1 {
5999
6068
  clone.setAttribute("lang", this.lang);
6000
6069
  } catch {
6001
6070
  }
6002
- btn.insertAdjacentElement("afterend", clone);
6071
+ this._prepareParentContainer(btn);
6072
+ btn.insertAdjacentElement("beforebegin", clone);
6003
6073
  }
6004
6074
  } catch {
6005
6075
  }
@@ -6037,6 +6107,7 @@ class ShipAidCheckoutPlus extends s$1 {
6037
6107
  if (!this._originalCheckoutButton && firstEl) {
6038
6108
  this._applyButtonStylesFrom(firstEl, customStyles || {});
6039
6109
  }
6110
+ if (firstEl) this._prepareParentContainer(firstEl);
6040
6111
  const anyMatch = nodeList.length > 0;
6041
6112
  if (!hasOriginal || anyMatch) {
6042
6113
  this._mountNearCheckoutButton();
@@ -6048,6 +6119,27 @@ class ShipAidCheckoutPlus extends s$1 {
6048
6119
  };
6049
6120
  this._observer = new MutationObserver(handler);
6050
6121
  this._observer.observe(document.body, { childList: true, subtree: true });
6122
+ try {
6123
+ const extraObservers = [];
6124
+ for (const root of this._getConfiguredShadowRoots()) {
6125
+ const shadowHandler = () => {
6126
+ if (this._remountTimer) {
6127
+ try {
6128
+ clearTimeout(this._remountTimer);
6129
+ } catch {
6130
+ }
6131
+ }
6132
+ this._remountTimer = window.setTimeout(() => {
6133
+ this._mountNearCheckoutButton();
6134
+ }, 150);
6135
+ };
6136
+ const obs = new MutationObserver(shadowHandler);
6137
+ obs.observe(root, { childList: true, subtree: true });
6138
+ extraObservers.push(obs);
6139
+ }
6140
+ this._shadowObservers = extraObservers;
6141
+ } catch {
6142
+ }
6051
6143
  } catch {
6052
6144
  }
6053
6145
  }
@@ -6063,6 +6155,17 @@ class ShipAidCheckoutPlus extends s$1 {
6063
6155
  (_b = this._observer) == null ? void 0 : _b.disconnect();
6064
6156
  } catch {
6065
6157
  }
6158
+ try {
6159
+ const list = this._shadowObservers;
6160
+ if (Array.isArray(list)) list.forEach((o3) => {
6161
+ try {
6162
+ o3.disconnect();
6163
+ } catch {
6164
+ }
6165
+ });
6166
+ this._shadowObservers = [];
6167
+ } catch {
6168
+ }
6066
6169
  if (this._remountTimer) {
6067
6170
  try {
6068
6171
  clearTimeout(this._remountTimer);
@@ -6479,7 +6582,7 @@ class ShipAidCheckoutPlus extends s$1 {
6479
6582
  border-style: var(--cp-primary-border-style, none);
6480
6583
  border-color: var(--cp-primary-border-color, transparent);
6481
6584
  border-width: var(--cp-primary-border-width, 0);
6482
- border-radius:20px;
6585
+ border-radius: var(--cp-radius);;
6483
6586
  padding:14px 12px;
6484
6587
  font-size: var(--cp-primary-size);
6485
6588
  font-weight:800;
@@ -6497,7 +6600,7 @@ class ShipAidCheckoutPlus extends s$1 {
6497
6600
  background:#fff;
6498
6601
  color:var(--cp-text);
6499
6602
  border:1px solid var(--cp-border);
6500
- border-radius:20px;
6603
+ border-radius: var(--cp-radius);;
6501
6604
  padding:12px 12px;
6502
6605
  font-size: var(--cp-secondary-size);
6503
6606
  font-weight:600;
@@ -7356,7 +7459,7 @@ const _ShipAidAddToCartPlus = class _ShipAidAddToCartPlus extends s$1 {
7356
7459
  if (document.getElementById(styleId)) return;
7357
7460
  const style = document.createElement("style");
7358
7461
  style.id = styleId;
7359
- style.textContent = `.${ATC_ORIGINAL_BTN_CLASS} { background: #fff !important; color: #111 !important; border: 1px solid #111 !important; border-radius: 9999px !important; text-transform: none !important; }
7462
+ style.textContent = `.${ATC_ORIGINAL_BTN_CLASS} { background: #fff !important; color: #111 !important; border: 1px solid #111 !important; border-radius: 12px !important; text-transform: none !important; }
7360
7463
  .${ATC_ORIGINAL_BTN_CLASS}:hover, .${ATC_ORIGINAL_BTN_CLASS}:focus { background: #f7f7f7 !important; color: #111 !important; border-color: #111 !important; }
7361
7464
  .${ATC_ORIGINAL_BTN_CLASS}[disabled] { opacity: 0.6 !important; cursor: not-allowed !important; }
7362
7465
  .${ATC_ORIGINAL_BTN_CLASS}:after { position: unset !important; opacity: 0 !important; }
@@ -7575,7 +7678,7 @@ _ShipAidAddToCartPlus.styles = i2`
7575
7678
  }
7576
7679
  .cp-primary {
7577
7680
  width: 100%;
7578
- border-radius: 20px;
7681
+ border-radius: 12px;
7579
7682
  padding: 14px 12px;
7580
7683
  font-size: 13px;
7581
7684
  font-weight: 700;