ui.shipaid.com 0.3.135 → 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,21 @@ 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
+ }
5857
5872
  // Find a flex/grid ancestor and tag it so embed app CSS can make our widget span a full row
5858
5873
  _prepareParentContainer(btn) {
5859
5874
  if (!btn) return;
@@ -5971,7 +5986,7 @@ class ShipAidCheckoutPlus extends s$1 {
5971
5986
  }
5972
5987
  }
5973
5988
  _mountNearCheckoutButton() {
5974
- var _a, _b, _c, _d, _e;
5989
+ var _a, _b, _c, _d, _e, _f;
5975
5990
  if (!this.isConnected) return;
5976
5991
  if (!this._shouldShowWidget()) return;
5977
5992
  this._removeLegacyV1();
@@ -5980,7 +5995,38 @@ class ShipAidCheckoutPlus extends s$1 {
5980
5995
  const customStyles = ((_e = (_d = this._store) == null ? void 0 : _d.checkoutPlus) == null ? void 0 : _e.styles) || {};
5981
5996
  const provided = (dbSelector || this.dataSelector || "").trim();
5982
5997
  const selectors = provided ? provided.split(",").map((s3) => s3.trim()).filter(Boolean) : DEFAULT_CHECKOUT_SELECTORS;
5983
- 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
+ }
5984
6030
  if (!matches.length) return;
5985
6031
  if (this.isClone) {
5986
6032
  const target = matches[0];
@@ -6073,6 +6119,27 @@ class ShipAidCheckoutPlus extends s$1 {
6073
6119
  };
6074
6120
  this._observer = new MutationObserver(handler);
6075
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
+ }
6076
6143
  } catch {
6077
6144
  }
6078
6145
  }
@@ -6088,6 +6155,17 @@ class ShipAidCheckoutPlus extends s$1 {
6088
6155
  (_b = this._observer) == null ? void 0 : _b.disconnect();
6089
6156
  } catch {
6090
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
+ }
6091
6169
  if (this._remountTimer) {
6092
6170
  try {
6093
6171
  clearTimeout(this._remountTimer);