@uniweb/runtime 1.4.5 → 1.5.0

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/ssr.js CHANGED
@@ -436,6 +436,31 @@ function areaWrapperProps(region, transitions, layers, sticky = null) {
436
436
  if (!style) return null;
437
437
  return sticky ? { style, "data-uw-sticky": "area" } : { style };
438
438
  }
439
+ const HEADER_HEIGHT = "--uw-header-height";
440
+ const MEASURED_HEADER_HEIGHT = "--uw-header-measured";
441
+ function headerOverlay(page) {
442
+ const first = page?.getBodyBlocks?.()?.[0];
443
+ if (!first?.underHeader) return null;
444
+ const header = page.getLayoutAreas?.()?.header;
445
+ if (!Array.isArray(header) || header.length === 0) return null;
446
+ const heights = header.map((block) => block?.height).filter(Boolean);
447
+ const height = heights.length === 0 ? "0px" : heights.length === 1 ? heights[0] : `calc(${heights.join(" + ")})`;
448
+ return { height };
449
+ }
450
+ function overlayBoxProps(props) {
451
+ return { ...props || {}, style: { ...props?.style || {}, height: 0, minHeight: 0 }, "data-uw-header": "over" };
452
+ }
453
+ function underHeaderProps(overlay) {
454
+ return {
455
+ style: { [HEADER_HEIGHT]: `var(${MEASURED_HEADER_HEIGHT}, ${overlay.height})` },
456
+ "data-uw-under-header": ""
457
+ };
458
+ }
459
+ function openingUnderHeader(block) {
460
+ const page = block?.page;
461
+ if (!page || page.getBodyBlocks?.()?.[0] !== block) return null;
462
+ return headerOverlay(page);
463
+ }
439
464
  const COLUMN = { display: "flex", flexDirection: "column", minHeight: "100vh" };
440
465
  const GROW = { flex: 1 };
441
466
  function DefaultLayout({ header, body, footer, zones }) {
@@ -567,12 +592,19 @@ function renderBlock(block, { as = "section", stickySelf = false } = {}) {
567
592
  }
568
593
  const margin = sectionScrollMargin(block, stickySelf);
569
594
  if (margin) wrapperProps.style = { ...wrapperProps.style, ...margin };
595
+ const overlay = stickySelf === "section" || stickySelf === true ? openingUnderHeader(block) : null;
596
+ if (overlay) {
597
+ const under = underHeaderProps(overlay);
598
+ wrapperProps.style = { ...wrapperProps.style, ...under.style };
599
+ wrapperProps["data-uw-under-header"] = under["data-uw-under-header"];
600
+ }
570
601
  const componentClassName = Component.className;
571
602
  if (componentClassName) {
572
603
  wrapperProps.className = wrapperProps.className ? `${wrapperProps.className} ${componentClassName}` : componentClassName;
573
604
  }
574
605
  const hasBackground = background?.mode && meta?.background !== "self";
575
606
  block.hasBackground = hasBackground;
607
+ if (meta?.background === "self") wrapperProps["data-uw-background"] = "self";
576
608
  const wrapperTag = as !== "section" ? as : Component.as || "section";
577
609
  if (hasBackground) {
578
610
  return React.createElement(
@@ -615,8 +647,10 @@ function renderLayout(page, website) {
615
647
  const transitions = website.viewTransitions ? resolveLayoutTransitions(layoutMeta?.transitions) : null;
616
648
  const sticky = layoutStickiness(areas);
617
649
  const layers = resolveLayoutLayers(areaNames, layoutMeta?.layers, sticky);
650
+ const overlay = headerOverlay(page);
618
651
  const wrapArea = (name, element) => {
619
- const props = areaWrapperProps(name, transitions, layers, RemoteLayout ? sticky[name] : null);
652
+ let props = areaWrapperProps(name, transitions, layers, RemoteLayout ? sticky[name] : null);
653
+ if (overlay && RemoteLayout && name === "header") props = overlayBoxProps(props);
620
654
  return props ? React.createElement("div", props, element) : element;
621
655
  };
622
656
  const bodyElement = bodyBlocks ? wrapArea("body", renderBlocks(bodyBlocks, { stickySelf: "section" })) : null;
@@ -638,7 +672,7 @@ function renderLayout(page, website) {
638
672
  return React.createElement(DefaultLayout, {
639
673
  body: bodyElement,
640
674
  ...areaElements,
641
- zones: { header: zone("header"), footer: zone("footer") }
675
+ zones: { header: overlay ? overlayBoxProps(zone("header")) : zone("header"), footer: zone("footer") }
642
676
  });
643
677
  }
644
678
  function initPrerenderForLocale(content, foundation, locale, extensionsOrOptions, maybeOptions) {