floor-editor-ts 1.1.6 → 1.1.7

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.
@@ -64737,9 +64737,8 @@ function FloorPlanCanvas($$anchor, $$props) {
64737
64737
  });
64738
64738
  user_effect(() => {
64739
64739
  if ($$props.viewOnly) {
64740
- $$props.floorMaxWidth;
64741
- $$props.floorMaxHeight;
64742
64740
  needsFitToCanvas = true;
64741
+ markDirty();
64743
64742
  }
64744
64743
  selectedCameraSerial();
64745
64744
  showCameraCones();
@@ -65086,14 +65085,42 @@ function FloorPlanCanvas($$anchor, $$props) {
65086
65085
  function resize() {
65087
65086
  const parent = canvas === null || canvas === void 0 ? void 0 : canvas.parentElement;
65088
65087
  if (!parent) return;
65089
- set(width, parent.clientWidth, true);
65090
- set(height, parent.clientHeight, true);
65088
+ if (!$$props.viewOnly) {
65089
+ set(width, parent.clientWidth, true);
65090
+ set(height, parent.clientHeight, true);
65091
+ if (canvas) {
65092
+ canvas.width = get(width);
65093
+ canvas.height = get(height);
65094
+ }
65095
+ markDirty();
65096
+ needsFitToCanvas = true;
65097
+ return;
65098
+ }
65099
+ layoutViewOnlyViewport();
65100
+ }
65101
+ /** viewOnly: fit walls to fill the entire viewport — no gray margins */
65102
+ function layoutViewOnlyViewport() {
65103
+ const parent = canvas === null || canvas === void 0 ? void 0 : canvas.parentElement;
65104
+ if (!parent || !get(currentFloor)) return;
65105
+ const bounds = getFloorWallBounds(get(currentFloor));
65106
+ if (!bounds) return;
65107
+ const domWidth = parent.clientWidth;
65108
+ const domHeight = parent.clientHeight;
65109
+ if (domWidth <= 0 || domHeight <= 0) return;
65110
+ set(width, domWidth, true);
65111
+ set(height, domHeight, true);
65091
65112
  if (canvas) {
65092
65113
  canvas.width = get(width);
65093
65114
  canvas.height = get(height);
65094
65115
  }
65116
+ const padding = 12;
65117
+ const contentW = bounds.width + padding * 2;
65118
+ const contentH = bounds.height + padding * 2;
65119
+ set(camX, (bounds.minX + bounds.maxX) / 2);
65120
+ set(camY, (bounds.minY + bounds.maxY) / 2);
65121
+ set(zoom, Math.max(get(width) / contentW, get(height) / contentH), true);
65122
+ set(zoom, Math.max(get(zoom), .1), true);
65095
65123
  markDirty();
65096
- needsFitToCanvas = true;
65097
65124
  }
65098
65125
  function drawGrid() {
65099
65126
  if (!ctx || !get(showGrid)) return;
@@ -65569,49 +65596,6 @@ function FloorPlanCanvas($$anchor, $$props) {
65569
65596
  height
65570
65597
  };
65571
65598
  }
65572
- function getFloorContentBounds(floor = get(currentFloor)) {
65573
- if (!floor) return null;
65574
- let minX = Infinity;
65575
- let maxX = -Infinity;
65576
- let minY = Infinity;
65577
- let maxY = -Infinity;
65578
- let found = false;
65579
- const expand = (x, y, pad = 0) => {
65580
- minX = Math.min(minX, x - pad);
65581
- maxX = Math.max(maxX, x + pad);
65582
- minY = Math.min(minY, y - pad);
65583
- maxY = Math.max(maxY, y + pad);
65584
- found = true;
65585
- };
65586
- for (const wall of floor.walls) {
65587
- expand(wall.start.x, wall.start.y, wall.thickness / 2);
65588
- expand(wall.end.x, wall.end.y, wall.thickness / 2);
65589
- if (wall.curvePoint) expand(wall.curvePoint.x, wall.curvePoint.y, wall.thickness / 2);
65590
- }
65591
- for (const item of floor.furniture) {
65592
- var _item$scale$x, _item$scale, _item$scale$y, _item$scale2, _ref, _item$width, _ref2, _item$depth;
65593
- const cat = getCatalogItem(item.catalogId);
65594
- const sx = Math.abs((_item$scale$x = (_item$scale = item.scale) === null || _item$scale === void 0 ? void 0 : _item$scale.x) !== null && _item$scale$x !== void 0 ? _item$scale$x : 1);
65595
- const sy = Math.abs((_item$scale$y = (_item$scale2 = item.scale) === null || _item$scale2 === void 0 ? void 0 : _item$scale2.y) !== null && _item$scale$y !== void 0 ? _item$scale$y : 1);
65596
- const w = ((_ref = (_item$width = item.width) !== null && _item$width !== void 0 ? _item$width : cat === null || cat === void 0 ? void 0 : cat.width) !== null && _ref !== void 0 ? _ref : 50) * sx;
65597
- const d = ((_ref2 = (_item$depth = item.depth) !== null && _item$depth !== void 0 ? _item$depth : cat === null || cat === void 0 ? void 0 : cat.depth) !== null && _ref2 !== void 0 ? _ref2 : 50) * sy;
65598
- const pad = Math.max(w, d) * .6;
65599
- if (item.catalogId === "camera") expand(item.position.x, item.position.y, Math.max(w, d) * 6);
65600
- else expand(item.position.x, item.position.y, pad);
65601
- }
65602
- if (!found) return getFloorWallBounds(floor);
65603
- const width = maxX - minX;
65604
- const height = maxY - minY;
65605
- if (width <= 0 || height <= 0) return null;
65606
- return {
65607
- minX,
65608
- minY,
65609
- maxX,
65610
- maxY,
65611
- width,
65612
- height
65613
- };
65614
- }
65615
65599
  function getCanvasFrameStyle() {
65616
65600
  return "width: 100%; height: 100%";
65617
65601
  }
@@ -65623,9 +65607,11 @@ function FloorPlanCanvas($$anchor, $$props) {
65623
65607
  }
65624
65608
  canvasDirty = false;
65625
65609
  ctx.clearRect(0, 0, get(width), get(height));
65626
- ctx.fillStyle = "#f8f9fa";
65627
- ctx.fillRect(0, 0, get(width), get(height));
65628
- if (!$$props.viewOnly) drawGrid();
65610
+ if (!$$props.viewOnly) {
65611
+ ctx.fillStyle = "#f8f9fa";
65612
+ ctx.fillRect(0, 0, get(width), get(height));
65613
+ drawGrid();
65614
+ }
65629
65615
  if (!$$props.viewOnly && get(layerVis).guides) drawGuides$1();
65630
65616
  drawBackgroundImage();
65631
65617
  const floor = get(currentFloor);
@@ -65634,7 +65620,8 @@ function FloorPlanCanvas($$anchor, $$props) {
65634
65620
  return;
65635
65621
  }
65636
65622
  if (needsFitToCanvas) {
65637
- zoomToFit();
65623
+ if ($$props.viewOnly) layoutViewOnlyViewport();
65624
+ else zoomToFit();
65638
65625
  needsFitToCanvas = false;
65639
65626
  }
65640
65627
  if (get(wallStart) || get(draggingFurnitureId) || get(draggingDoorId) || get(draggingWindowId) || get(draggingStairId) || get(draggingColumnId) || get(draggingWallEndpoint) || get(draggingWallParallel) || get(draggingCurveHandle) || get(draggingHandle) || get(draggingMultiSelect) || get(draggingRoomId) || get(draggingRoomLabelId) || get(draggingTextAnnotationId) || get(draggingGuideId) || get(measuring) || get(annotating) || get(currentPlacingId) || get(isPlacingStair) || get(isPlacingColumn) || get(marqueeStart) || get(isPanning)) canvasDirty = true;
@@ -67593,13 +67580,17 @@ function FloorPlanCanvas($$anchor, $$props) {
67593
67580
  set(camY, bbox.minY + (my - oy) / scale);
67594
67581
  }
67595
67582
  function zoomToFit() {
67583
+ if ($$props.viewOnly) {
67584
+ layoutViewOnlyViewport();
67585
+ return;
67586
+ }
67596
67587
  if (!get(currentFloor)) {
67597
67588
  set(camX, 0);
67598
67589
  set(camY, 0);
67599
67590
  set(zoom, 1);
67600
67591
  return;
67601
67592
  }
67602
- const bounds = $$props.viewOnly ? getFloorContentBounds(get(currentFloor)) : getFloorWallBounds(get(currentFloor));
67593
+ const bounds = getFloorWallBounds(get(currentFloor));
67603
67594
  if (!bounds) {
67604
67595
  set(camX, 0);
67605
67596
  set(camY, 0);
@@ -67616,13 +67607,12 @@ function FloorPlanCanvas($$anchor, $$props) {
67616
67607
  canvas.height = get(height);
67617
67608
  }
67618
67609
  }
67619
- const padding = $$props.viewOnly ? 24 : 0;
67610
+ const padding = 0;
67620
67611
  const contentW = bounds.width + padding * 2;
67621
67612
  const contentH = bounds.height + padding * 2;
67622
67613
  set(camX, (bounds.minX + bounds.maxX) / 2);
67623
67614
  set(camY, (bounds.minY + bounds.maxY) / 2);
67624
- if ($$props.viewOnly) set(zoom, Math.min(get(width) / contentW, get(height) / contentH), true);
67625
- else set(zoom, Math.max(get(width) / contentW, get(height) / contentH), true);
67615
+ set(zoom, Math.max(get(width) / contentW, get(height) / contentH), true);
67626
67616
  set(zoom, Math.max(get(zoom), .1), true);
67627
67617
  markDirty();
67628
67618
  }