@biela.dev/core 1.7.4 → 1.7.6

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.d.cts CHANGED
@@ -90,11 +90,14 @@ interface ContainerSize {
90
90
  /**
91
91
  * Observes an element's content box dimensions via ResizeObserver.
92
92
  * Foundation of adaptive scaling — same mechanism as Xcode's window resize detection.
93
- * Uses the actual canvas div, not the window, so it's panel-independent.
94
93
  *
95
- * Safety: clamps reported size to the visual viewport so that a mis-sized
96
- * parent (e.g. height: auto or height: 100% with no fixed ancestor) can never
97
- * cause the device frame to render larger than the screen.
94
+ * Safety features:
95
+ * 1. Clamps reported size to the visual viewport so a mis-sized parent
96
+ * can never cause the device frame to render larger than the screen.
97
+ * 2. When the element has 0 height (common AI-generated code mistake:
98
+ * height: auto or height: 100% without explicit ancestor height),
99
+ * uses a viewport-based fallback so the device still renders.
100
+ * 3. Listens for window resize to stay in sync.
98
101
  */
99
102
  declare function useContainerSize(ref: RefObject<HTMLElement | null>): ContainerSize;
100
103
 
package/dist/index.d.ts CHANGED
@@ -90,11 +90,14 @@ interface ContainerSize {
90
90
  /**
91
91
  * Observes an element's content box dimensions via ResizeObserver.
92
92
  * Foundation of adaptive scaling — same mechanism as Xcode's window resize detection.
93
- * Uses the actual canvas div, not the window, so it's panel-independent.
94
93
  *
95
- * Safety: clamps reported size to the visual viewport so that a mis-sized
96
- * parent (e.g. height: auto or height: 100% with no fixed ancestor) can never
97
- * cause the device frame to render larger than the screen.
94
+ * Safety features:
95
+ * 1. Clamps reported size to the visual viewport so a mis-sized parent
96
+ * can never cause the device frame to render larger than the screen.
97
+ * 2. When the element has 0 height (common AI-generated code mistake:
98
+ * height: auto or height: 100% without explicit ancestor height),
99
+ * uses a viewport-based fallback so the device still renders.
100
+ * 3. Listens for window resize to stay in sync.
98
101
  */
99
102
  declare function useContainerSize(ref: RefObject<HTMLElement | null>): ContainerSize;
100
103
 
package/dist/index.js CHANGED
@@ -8,10 +8,17 @@ function useContainerSize(ref) {
8
8
  useEffect(() => {
9
9
  const el = ref.current;
10
10
  if (!el) return;
11
- const observer = new ResizeObserver(([entry]) => {
12
- if (!entry) return;
13
- let { width, height } = entry.contentRect;
11
+ const update = () => {
12
+ const rect = el.getBoundingClientRect();
13
+ let width = rect.width;
14
+ let height = rect.height;
14
15
  if (typeof window !== "undefined") {
16
+ if (height <= 0) {
17
+ height = Math.max(200, window.innerHeight - Math.max(0, rect.top));
18
+ }
19
+ if (width <= 0) {
20
+ width = window.innerWidth;
21
+ }
15
22
  width = Math.min(width, window.innerWidth);
16
23
  height = Math.min(height, window.innerHeight);
17
24
  }
@@ -19,9 +26,15 @@ function useContainerSize(ref) {
19
26
  if (prev.width === width && prev.height === height) return prev;
20
27
  return { width, height };
21
28
  });
22
- });
29
+ };
30
+ const observer = new ResizeObserver(() => update());
23
31
  observer.observe(el);
24
- return () => observer.disconnect();
32
+ update();
33
+ window.addEventListener("resize", update);
34
+ return () => {
35
+ observer.disconnect();
36
+ window.removeEventListener("resize", update);
37
+ };
25
38
  }, [ref]);
26
39
  return size;
27
40
  }
@@ -630,9 +643,8 @@ function DeviceFrame({
630
643
  className: "bielaframe-sentinel",
631
644
  style: {
632
645
  width: "100%",
633
- height: "100%",
646
+ height: containerH > 0 ? containerH : "100%",
634
647
  minHeight: 0,
635
- maxHeight: "100%",
636
648
  display: "flex",
637
649
  flexDirection: "column",
638
650
  alignItems: "center",