@biela.dev/core 1.7.1 → 1.7.3

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
@@ -91,6 +91,10 @@ interface ContainerSize {
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
93
  * Uses the actual canvas div, not the window, so it's panel-independent.
94
+ *
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
98
  */
95
99
  declare function useContainerSize(ref: RefObject<HTMLElement | null>): ContainerSize;
96
100
 
package/dist/index.d.ts CHANGED
@@ -91,6 +91,10 @@ interface ContainerSize {
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
93
  * Uses the actual canvas div, not the window, so it's panel-independent.
94
+ *
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
98
  */
95
99
  declare function useContainerSize(ref: RefObject<HTMLElement | null>): ContainerSize;
96
100
 
package/dist/index.js CHANGED
@@ -10,7 +10,11 @@ function useContainerSize(ref) {
10
10
  if (!el) return;
11
11
  const observer = new ResizeObserver(([entry]) => {
12
12
  if (!entry) return;
13
- const { width, height } = entry.contentRect;
13
+ let { width, height } = entry.contentRect;
14
+ if (typeof window !== "undefined") {
15
+ width = Math.min(width, window.innerWidth);
16
+ height = Math.min(height, window.innerHeight);
17
+ }
14
18
  setSize((prev) => {
15
19
  if (prev.width === width && prev.height === height) return prev;
16
20
  return { width, height };
@@ -470,6 +474,31 @@ function registerCustomDeviceSVG(deviceId, svgString, frame, cropViewBox, screen
470
474
  });
471
475
  processedSVG = bodySVG.replace(defsPlaceholder, defsContent);
472
476
  }
477
+ let correctedFrame = frame;
478
+ if (screenRect && screenRect.width > 0 && screenRect.height > 0) {
479
+ const finalVBMatch = processedSVG.match(/viewBox\s*=\s*["']([^"']+)["']/i);
480
+ if (finalVBMatch) {
481
+ const vbParts = finalVBMatch[1].split(/[\s,]+/).map(Number);
482
+ if (vbParts.length >= 4) {
483
+ const vbW = vbParts[2];
484
+ const vbH = vbParts[3];
485
+ if (vbW > 0 && vbH > 0) {
486
+ const sx = frame.screenWidth / screenRect.width;
487
+ const sy = frame.screenHeight / screenRect.height;
488
+ const s = Math.min(sx, sy);
489
+ correctedFrame = {
490
+ ...frame,
491
+ bezelLeft: Math.round(screenRect.x * s),
492
+ bezelTop: Math.round(screenRect.y * s),
493
+ bezelRight: Math.round((vbW - screenRect.x - screenRect.width) * s),
494
+ bezelBottom: Math.round((vbH - screenRect.y - screenRect.height) * s),
495
+ totalWidth: Math.round(vbW * s),
496
+ totalHeight: Math.round(vbH * s)
497
+ };
498
+ }
499
+ }
500
+ }
501
+ }
473
502
  const CustomSVGComponent = ({ style }) => /* @__PURE__ */ jsx(
474
503
  "div",
475
504
  {
@@ -477,7 +506,7 @@ function registerCustomDeviceSVG(deviceId, svgString, frame, cropViewBox, screen
477
506
  dangerouslySetInnerHTML: { __html: processedSVG }
478
507
  }
479
508
  );
480
- SVG_REGISTRY[deviceId] = { component: CustomSVGComponent, frame };
509
+ SVG_REGISTRY[deviceId] = { component: CustomSVGComponent, frame: correctedFrame };
481
510
  }
482
511
  function DeviceFrame({
483
512
  device: deviceProp,