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