@ohhwells/bridge 0.1.98 → 0.1.100

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/index.js CHANGED
@@ -2547,6 +2547,10 @@ var REPLACED_ATTR = "data-ohw-ai-replaced-by";
2547
2547
  var REMOVED_ATTR2 = "data-ohw-ai-removed";
2548
2548
  var TEMPLATE_HIDDEN_ATTR = "data-ohw-ai-template-hidden";
2549
2549
  var CHROME_SECTION_IDS = /* @__PURE__ */ new Set(["navbar", "footer"]);
2550
+ function isChromeSection2(el) {
2551
+ if (CHROME_SECTION_IDS.has(el.getAttribute("data-ohw-section") ?? "")) return true;
2552
+ return el.tagName === "HEADER" || el.tagName === "FOOTER";
2553
+ }
2550
2554
  function readRootVar(name) {
2551
2555
  if (typeof document === "undefined") return "";
2552
2556
  return getComputedStyle(document.documentElement).getPropertyValue(name).trim();
@@ -2598,7 +2602,10 @@ function deriveTemplateButtonStyle() {
2598
2602
  ].map((v) => v || "0px");
2599
2603
  const radius = corners.every((v) => v === corners[0]) ? corners[0] : corners.join(" ");
2600
2604
  const px = (v) => parseFloat(v) || 0;
2601
- const padY = Math.max(px(cs.paddingTop), px(cs.paddingBottom));
2605
+ const lineHeight = px(cs.lineHeight) || px(cs.fontSize) * 1.2;
2606
+ const contentH = btn.getBoundingClientRect().height - px(cs.borderTopWidth) - px(cs.borderBottomWidth);
2607
+ const impliedY = Math.round(Math.max(0, (contentH - lineHeight) / 2));
2608
+ const padY = Math.max(px(cs.paddingTop), px(cs.paddingBottom), impliedY);
2602
2609
  const padX = Math.max(px(cs.paddingLeft), px(cs.paddingRight));
2603
2610
  return {
2604
2611
  radius: radius || "10px",
@@ -2624,6 +2631,19 @@ function findPlacementAnchor(id, exclude) {
2624
2631
  for (const el of document.querySelectorAll(`[data-ohw-section="${CSS.escape(id)}"]`)) {
2625
2632
  if (el === exclude) continue;
2626
2633
  if (el.parentElement?.closest("[data-ohw-section]")) continue;
2634
+ if (isChromeSection2(el)) return null;
2635
+ return el;
2636
+ }
2637
+ return null;
2638
+ }
2639
+ function findFooterSection() {
2640
+ const byId = findTemplateSection("footer");
2641
+ if (byId) return byId;
2642
+ for (const el of Array.from(
2643
+ document.querySelectorAll("footer[data-ohw-section]")
2644
+ ).reverse()) {
2645
+ if (el.hasAttribute(CONTAINER_ATTR)) continue;
2646
+ if (el.parentElement?.closest("[data-ohw-section]")) continue;
2627
2647
  return el;
2628
2648
  }
2629
2649
  return null;
@@ -2650,7 +2670,7 @@ function placeContainer(container, entry) {
2650
2670
  return;
2651
2671
  }
2652
2672
  }
2653
- const footer = findTemplateSection("footer");
2673
+ const footer = findFooterSection();
2654
2674
  if (footer) {
2655
2675
  footer.insertAdjacentElement("beforebegin", container);
2656
2676
  } else {
@@ -2685,7 +2705,7 @@ function syncTemplateHidden(state, pageHasSections) {
2685
2705
  if (!hide) return;
2686
2706
  for (const el of Array.from(document.querySelectorAll("[data-ohw-section]"))) {
2687
2707
  if (el.hasAttribute(CONTAINER_ATTR)) continue;
2688
- if (CHROME_SECTION_IDS.has(el.getAttribute("data-ohw-section") ?? "")) continue;
2708
+ if (isChromeSection2(el)) continue;
2689
2709
  if (el.parentElement?.closest("[data-ohw-section]")) continue;
2690
2710
  if (el.hasAttribute(REPLACED_ATTR) || el.hasAttribute(REMOVED_ATTR2)) continue;
2691
2711
  el.style.display = "none";
@@ -17151,7 +17171,26 @@ function OhhwellsBridge() {
17151
17171
  return;
17152
17172
  }
17153
17173
  const r2 = target.getBoundingClientRect();
17154
- setHoveredTextRect(new DOMRect(r2.x - TEXT_HOVER_SIDE_PAD, r2.y, r2.width + TEXT_HOVER_SIDE_PAD * 2, r2.height));
17174
+ let top = r2.top, left = r2.x - TEXT_HOVER_SIDE_PAD, bottom = r2.bottom, right = r2.x + r2.width + TEXT_HOVER_SIDE_PAD;
17175
+ let clipParent = target.parentElement;
17176
+ while (clipParent) {
17177
+ const style = getComputedStyle(clipParent);
17178
+ if (style.overflowY === "hidden" || style.overflowY === "clip" || style.overflowX === "hidden" || style.overflowX === "clip") {
17179
+ const pr = clipParent.getBoundingClientRect();
17180
+ top = Math.max(top, pr.top);
17181
+ bottom = Math.min(bottom, pr.bottom);
17182
+ left = Math.max(left, pr.left);
17183
+ right = Math.min(right, pr.right);
17184
+ }
17185
+ if (clipParent === document.documentElement) break;
17186
+ clipParent = clipParent.parentElement;
17187
+ }
17188
+ const width = right - left, height = bottom - top;
17189
+ if (width <= 0 || height <= 0) {
17190
+ setHoveredTextRect(null);
17191
+ return;
17192
+ }
17193
+ setHoveredTextRect(new DOMRect(left, top, width, height));
17155
17194
  };
17156
17195
  const observer = new MutationObserver(sync);
17157
17196
  observer.observe(document.documentElement, {
@@ -20325,12 +20364,11 @@ function OhhwellsBridge() {
20325
20364
  }
20326
20365
  const { y } = toProbeCoords(clientX, clientY, fromParentViewport);
20327
20366
  const sections = Array.from(document.querySelectorAll("[data-ohw-section]")).filter(
20328
- (el) => !el.hasAttribute("data-ohw-ai-template-hidden") && !el.hasAttribute("data-ohw-ai-removed") && !el.hasAttribute("data-ohw-ai-replaced-by") && el.getBoundingClientRect().height > 0
20367
+ (el) => !el.hasAttribute("data-ohw-ai-template-hidden") && !el.hasAttribute("data-ohw-ai-removed") && !el.hasAttribute("data-ohw-ai-replaced-by") && !isPageFrameSection(el) && el.getBoundingClientRect().height > 0
20329
20368
  ).sort((a, b) => a.getBoundingClientRect().top - b.getBoundingClientRect().top);
20330
20369
  const ZONE = 20;
20331
20370
  for (let i = 0; i < sections.length; i++) {
20332
20371
  const a = sections[i];
20333
- if (isPageFrameSection(a)) continue;
20334
20372
  const b = sections[i + 1] ?? null;
20335
20373
  const boundaryY = a.getBoundingClientRect().bottom;
20336
20374
  if (Math.abs(y - boundaryY) <= ZONE) {
@@ -20769,6 +20807,9 @@ function OhhwellsBridge() {
20769
20807
  if (reapNodes.length > 0) postToParentRef.current({ type: "ow:change", nodes: reapNodes });
20770
20808
  const hydratedHeight = document.body.scrollHeight;
20771
20809
  if (hydratedHeight > 50) postToParentRef.current({ type: "ow:height", height: hydratedHeight });
20810
+ if (parseAiSectionsState(aiSectionsRef.current).sections.length > 0) {
20811
+ postAiSectionsChanged();
20812
+ }
20772
20813
  postToParentRef.current({ type: "ow:hydrate-done" });
20773
20814
  };
20774
20815
  const handleUpdateLogoIdentity = (e) => {
@@ -21977,7 +22018,7 @@ function OhhwellsBridge() {
21977
22018
  postToParent2({
21978
22019
  type: "ow:ready",
21979
22020
  version: "1",
21980
- bridgeVersion: "0.1.97",
22021
+ bridgeVersion: "0.1.99",
21981
22022
  path: pathname,
21982
22023
  nodes: collectEditableNodes(editContentRef.current),
21983
22024
  sections