@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.cjs CHANGED
@@ -2620,6 +2620,10 @@ var REPLACED_ATTR = "data-ohw-ai-replaced-by";
2620
2620
  var REMOVED_ATTR2 = "data-ohw-ai-removed";
2621
2621
  var TEMPLATE_HIDDEN_ATTR = "data-ohw-ai-template-hidden";
2622
2622
  var CHROME_SECTION_IDS = /* @__PURE__ */ new Set(["navbar", "footer"]);
2623
+ function isChromeSection2(el) {
2624
+ if (CHROME_SECTION_IDS.has(el.getAttribute("data-ohw-section") ?? "")) return true;
2625
+ return el.tagName === "HEADER" || el.tagName === "FOOTER";
2626
+ }
2623
2627
  function readRootVar(name) {
2624
2628
  if (typeof document === "undefined") return "";
2625
2629
  return getComputedStyle(document.documentElement).getPropertyValue(name).trim();
@@ -2671,7 +2675,10 @@ function deriveTemplateButtonStyle() {
2671
2675
  ].map((v) => v || "0px");
2672
2676
  const radius = corners.every((v) => v === corners[0]) ? corners[0] : corners.join(" ");
2673
2677
  const px = (v) => parseFloat(v) || 0;
2674
- const padY = Math.max(px(cs.paddingTop), px(cs.paddingBottom));
2678
+ const lineHeight = px(cs.lineHeight) || px(cs.fontSize) * 1.2;
2679
+ const contentH = btn.getBoundingClientRect().height - px(cs.borderTopWidth) - px(cs.borderBottomWidth);
2680
+ const impliedY = Math.round(Math.max(0, (contentH - lineHeight) / 2));
2681
+ const padY = Math.max(px(cs.paddingTop), px(cs.paddingBottom), impliedY);
2675
2682
  const padX = Math.max(px(cs.paddingLeft), px(cs.paddingRight));
2676
2683
  return {
2677
2684
  radius: radius || "10px",
@@ -2697,6 +2704,19 @@ function findPlacementAnchor(id, exclude) {
2697
2704
  for (const el of document.querySelectorAll(`[data-ohw-section="${CSS.escape(id)}"]`)) {
2698
2705
  if (el === exclude) continue;
2699
2706
  if (el.parentElement?.closest("[data-ohw-section]")) continue;
2707
+ if (isChromeSection2(el)) return null;
2708
+ return el;
2709
+ }
2710
+ return null;
2711
+ }
2712
+ function findFooterSection() {
2713
+ const byId = findTemplateSection("footer");
2714
+ if (byId) return byId;
2715
+ for (const el of Array.from(
2716
+ document.querySelectorAll("footer[data-ohw-section]")
2717
+ ).reverse()) {
2718
+ if (el.hasAttribute(CONTAINER_ATTR)) continue;
2719
+ if (el.parentElement?.closest("[data-ohw-section]")) continue;
2700
2720
  return el;
2701
2721
  }
2702
2722
  return null;
@@ -2723,7 +2743,7 @@ function placeContainer(container, entry) {
2723
2743
  return;
2724
2744
  }
2725
2745
  }
2726
- const footer = findTemplateSection("footer");
2746
+ const footer = findFooterSection();
2727
2747
  if (footer) {
2728
2748
  footer.insertAdjacentElement("beforebegin", container);
2729
2749
  } else {
@@ -2758,7 +2778,7 @@ function syncTemplateHidden(state, pageHasSections) {
2758
2778
  if (!hide) return;
2759
2779
  for (const el of Array.from(document.querySelectorAll("[data-ohw-section]"))) {
2760
2780
  if (el.hasAttribute(CONTAINER_ATTR)) continue;
2761
- if (CHROME_SECTION_IDS.has(el.getAttribute("data-ohw-section") ?? "")) continue;
2781
+ if (isChromeSection2(el)) continue;
2762
2782
  if (el.parentElement?.closest("[data-ohw-section]")) continue;
2763
2783
  if (el.hasAttribute(REPLACED_ATTR) || el.hasAttribute(REMOVED_ATTR2)) continue;
2764
2784
  el.style.display = "none";
@@ -17218,7 +17238,26 @@ function OhhwellsBridge() {
17218
17238
  return;
17219
17239
  }
17220
17240
  const r2 = target.getBoundingClientRect();
17221
- setHoveredTextRect(new DOMRect(r2.x - TEXT_HOVER_SIDE_PAD, r2.y, r2.width + TEXT_HOVER_SIDE_PAD * 2, r2.height));
17241
+ let top = r2.top, left = r2.x - TEXT_HOVER_SIDE_PAD, bottom = r2.bottom, right = r2.x + r2.width + TEXT_HOVER_SIDE_PAD;
17242
+ let clipParent = target.parentElement;
17243
+ while (clipParent) {
17244
+ const style = getComputedStyle(clipParent);
17245
+ if (style.overflowY === "hidden" || style.overflowY === "clip" || style.overflowX === "hidden" || style.overflowX === "clip") {
17246
+ const pr = clipParent.getBoundingClientRect();
17247
+ top = Math.max(top, pr.top);
17248
+ bottom = Math.min(bottom, pr.bottom);
17249
+ left = Math.max(left, pr.left);
17250
+ right = Math.min(right, pr.right);
17251
+ }
17252
+ if (clipParent === document.documentElement) break;
17253
+ clipParent = clipParent.parentElement;
17254
+ }
17255
+ const width = right - left, height = bottom - top;
17256
+ if (width <= 0 || height <= 0) {
17257
+ setHoveredTextRect(null);
17258
+ return;
17259
+ }
17260
+ setHoveredTextRect(new DOMRect(left, top, width, height));
17222
17261
  };
17223
17262
  const observer = new MutationObserver(sync);
17224
17263
  observer.observe(document.documentElement, {
@@ -20392,12 +20431,11 @@ function OhhwellsBridge() {
20392
20431
  }
20393
20432
  const { y } = toProbeCoords(clientX, clientY, fromParentViewport);
20394
20433
  const sections = Array.from(document.querySelectorAll("[data-ohw-section]")).filter(
20395
- (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
20434
+ (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
20396
20435
  ).sort((a, b) => a.getBoundingClientRect().top - b.getBoundingClientRect().top);
20397
20436
  const ZONE = 20;
20398
20437
  for (let i = 0; i < sections.length; i++) {
20399
20438
  const a = sections[i];
20400
- if (isPageFrameSection(a)) continue;
20401
20439
  const b = sections[i + 1] ?? null;
20402
20440
  const boundaryY = a.getBoundingClientRect().bottom;
20403
20441
  if (Math.abs(y - boundaryY) <= ZONE) {
@@ -20836,6 +20874,9 @@ function OhhwellsBridge() {
20836
20874
  if (reapNodes.length > 0) postToParentRef.current({ type: "ow:change", nodes: reapNodes });
20837
20875
  const hydratedHeight = document.body.scrollHeight;
20838
20876
  if (hydratedHeight > 50) postToParentRef.current({ type: "ow:height", height: hydratedHeight });
20877
+ if (parseAiSectionsState(aiSectionsRef.current).sections.length > 0) {
20878
+ postAiSectionsChanged();
20879
+ }
20839
20880
  postToParentRef.current({ type: "ow:hydrate-done" });
20840
20881
  };
20841
20882
  const handleUpdateLogoIdentity = (e) => {
@@ -22044,7 +22085,7 @@ function OhhwellsBridge() {
22044
22085
  postToParent2({
22045
22086
  type: "ow:ready",
22046
22087
  version: "1",
22047
- bridgeVersion: "0.1.97",
22088
+ bridgeVersion: "0.1.99",
22048
22089
  path: pathname,
22049
22090
  nodes: collectEditableNodes(editContentRef.current),
22050
22091
  sections