floor-editor-ts 1.1.8 → 1.1.9

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.
@@ -4970,8 +4970,33 @@ var init_attachments = __esmMin((() => {
4970
4970
  init_effects();
4971
4971
  }));
4972
4972
  //#endregion
4973
+ //#region node_modules/clsx/dist/clsx.mjs
4974
+ function r$1(e) {
4975
+ var t, f, n = "";
4976
+ if ("string" == typeof e || "number" == typeof e) n += e;
4977
+ else if ("object" == typeof e) if (Array.isArray(e)) {
4978
+ var o = e.length;
4979
+ for (t = 0; t < o; t++) e[t] && (f = r$1(e[t])) && (n && (n += " "), n += f);
4980
+ } else for (f in e) e[f] && (n && (n += " "), n += f);
4981
+ return n;
4982
+ }
4983
+ function clsx$1() {
4984
+ for (var e, t, f = 0, n = "", o = arguments.length; f < o; f++) (e = arguments[f]) && (t = r$1(e)) && (n && (n += " "), n += t);
4985
+ return n;
4986
+ }
4987
+ var init_clsx = __esmMin((() => {}));
4988
+ //#endregion
4973
4989
  //#region node_modules/svelte/src/internal/shared/attributes.js
4974
4990
  /**
4991
+ * Small wrapper around clsx to preserve Svelte's (weird) handling of falsy values.
4992
+ * TODO Svelte 6 revisit this, and likely turn all falsy values into the empty string (what clsx also does)
4993
+ * @param {any} value
4994
+ */
4995
+ function clsx(value) {
4996
+ if (typeof value === "object") return clsx$1(value);
4997
+ else return value !== null && value !== void 0 ? value : "";
4998
+ }
4999
+ /**
4975
5000
  * @param {any} value
4976
5001
  * @param {string | null} [hash]
4977
5002
  * @param {Record<string, boolean>} [directives]
@@ -5080,6 +5105,7 @@ function to_style(value, styles) {
5080
5105
  }
5081
5106
  var whitespace;
5082
5107
  var init_attributes$1 = __esmMin((() => {
5108
+ init_clsx();
5083
5109
  init_utils$3();
5084
5110
  whitespace = [..." \n\r\f\xA0\v"];
5085
5111
  }));
@@ -64640,7 +64666,7 @@ var root_22 = /* @__PURE__ */ from_html(`<div class="absolute top-2 left-1/2 -tr
64640
64666
  var root_23 = /* @__PURE__ */ from_html(`<div class="absolute top-2 left-1/2 -translate-x-1/2 bg-emerald-600 text-white px-3 py-1 rounded-full text-xs shadow">Click to place text label · Esc to cancel</div>`);
64641
64667
  var root_24 = /* @__PURE__ */ from_html(`<div class="absolute top-2 left-1/2 -translate-x-1/2 bg-indigo-600 text-white px-3 py-1 rounded-full text-xs shadow"> </div>`);
64642
64668
  var root_2$3 = /* @__PURE__ */ from_html(`<!> <!> <!> <!> <!> <!> <!> <!> <!> <!> <!> <!> <div class="absolute bottom-3 left-3 z-20 flex items-center gap-1 bg-white rounded-lg shadow-lg border border-gray-200 px-1 py-0.5"><button class="w-7 h-7 flex items-center justify-center rounded hover:bg-gray-100 text-gray-600 hover:text-gray-800 font-bold text-lg" title="Zoom Out (−)" aria-label="Zoom out">−</button> <button class="min-w-[3.5rem] h-7 flex items-center justify-center rounded hover:bg-gray-100 text-xs font-medium text-gray-600 hover:text-gray-800 tabular-nums" title="Reset to 100%" aria-label="Zoom to 100%"> </button> <button class="w-7 h-7 flex items-center justify-center rounded hover:bg-gray-100 text-gray-600 hover:text-gray-800 font-bold text-lg" title="Zoom In (+)" aria-label="Zoom in">+</button> <div class="w-px h-5 bg-gray-200"></div> <button class="w-7 h-7 flex items-center justify-center rounded hover:bg-gray-100 text-gray-500 hover:text-gray-700 text-sm" title="Zoom to Fit (F)" aria-label="Zoom to fit">⊞</button></div> <!>`, 1);
64643
- var root$1 = /* @__PURE__ */ from_html(`<div class="w-full h-full relative overflow-hidden" role="application"><div><canvas aria-label="Floor plan editor canvas"></canvas></div> <!> <!></div>`);
64669
+ var root$1 = /* @__PURE__ */ from_html(`<div role="application"><div><canvas aria-label="Floor plan editor canvas"></canvas></div> <!> <!></div>`);
64644
64670
  function FloorPlanCanvas($$anchor, $$props) {
64645
64671
  push($$props, true);
64646
64672
  const $panMode = () => store_get(panMode, "$panMode", $$stores);
@@ -64651,6 +64677,9 @@ function FloorPlanCanvas($$anchor, $$props) {
64651
64677
  let ctx;
64652
64678
  let width = /* @__PURE__ */ state(800);
64653
64679
  let height = /* @__PURE__ */ state(600);
64680
+ let viewOnlyCanvasW = /* @__PURE__ */ state(0);
64681
+ let viewOnlyCanvasH = /* @__PURE__ */ state(0);
64682
+ let canvasFrame;
64654
64683
  let camX = /* @__PURE__ */ state(0);
64655
64684
  let camY = /* @__PURE__ */ state(0);
64656
64685
  let zoom = /* @__PURE__ */ state(1);
@@ -65083,39 +65112,51 @@ function FloorPlanCanvas($$anchor, $$props) {
65083
65112
  return end;
65084
65113
  }
65085
65114
  function resize() {
65115
+ if ($$props.viewOnly) {
65116
+ layoutViewOnlyViewport();
65117
+ return;
65118
+ }
65086
65119
  const parent = canvas === null || canvas === void 0 ? void 0 : canvas.parentElement;
65087
65120
  if (!parent) return;
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;
65121
+ set(width, parent.clientWidth, true);
65122
+ set(height, parent.clientHeight, true);
65123
+ if (canvas) {
65124
+ canvas.width = get(width);
65125
+ canvas.height = get(height);
65098
65126
  }
65099
- layoutViewOnlyViewport();
65127
+ markDirty();
65128
+ needsFitToCanvas = true;
65100
65129
  }
65101
- /** viewOnly: show full floor contain fit, nothing clipped */
65130
+ /** viewOnly: canvas pixel size = floor aspect ratio, drawing fills canvas exactly */
65102
65131
  function layoutViewOnlyViewport() {
65103
- const parent = canvas === null || canvas === void 0 ? void 0 : canvas.parentElement;
65104
- if (!parent || !get(currentFloor)) return;
65132
+ const container = canvasFrame === null || canvasFrame === void 0 ? void 0 : canvasFrame.parentElement;
65133
+ if (!container || !get(currentFloor)) return;
65105
65134
  const bounds = getViewOnlyFitBounds(get(currentFloor));
65106
65135
  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);
65136
+ const maxW = container.clientWidth;
65137
+ const maxH = container.clientHeight;
65138
+ if (maxW <= 0 || maxH <= 0) return;
65139
+ const contentAspect = bounds.width / bounds.height;
65140
+ let canvasW;
65141
+ let canvasH;
65142
+ if (maxW / maxH > contentAspect) {
65143
+ canvasH = maxH;
65144
+ canvasW = Math.floor(maxH * contentAspect);
65145
+ } else {
65146
+ canvasW = maxW;
65147
+ canvasH = Math.floor(maxW / contentAspect);
65148
+ }
65149
+ set(viewOnlyCanvasW, canvasW, true);
65150
+ set(viewOnlyCanvasH, canvasH, true);
65151
+ set(width, canvasW, true);
65152
+ set(height, canvasH, true);
65112
65153
  if (canvas) {
65113
- canvas.width = get(width);
65114
- canvas.height = get(height);
65154
+ canvas.width = canvasW;
65155
+ canvas.height = canvasH;
65115
65156
  }
65116
65157
  set(camX, (bounds.minX + bounds.maxX) / 2);
65117
65158
  set(camY, (bounds.minY + bounds.maxY) / 2);
65118
- set(zoom, Math.min(get(width) / bounds.width, get(height) / bounds.height), true);
65159
+ set(zoom, Math.min(canvasW / bounds.width, canvasH / bounds.height), true);
65119
65160
  set(zoom, Math.max(get(zoom), .1), true);
65120
65161
  markDirty();
65121
65162
  }
@@ -65593,65 +65634,18 @@ function FloorPlanCanvas($$anchor, $$props) {
65593
65634
  height
65594
65635
  };
65595
65636
  }
65596
- function getFloorContentBounds(floor = get(currentFloor)) {
65597
- if (!floor) return null;
65598
- let minX = Infinity;
65599
- let maxX = -Infinity;
65600
- let minY = Infinity;
65601
- let maxY = -Infinity;
65602
- let found = false;
65603
- const expand = (x, y, pad = 0) => {
65604
- minX = Math.min(minX, x - pad);
65605
- maxX = Math.max(maxX, x + pad);
65606
- minY = Math.min(minY, y - pad);
65607
- maxY = Math.max(maxY, y + pad);
65608
- found = true;
65609
- };
65610
- for (const wall of floor.walls) {
65611
- expand(wall.start.x, wall.start.y, wall.thickness / 2);
65612
- expand(wall.end.x, wall.end.y, wall.thickness / 2);
65613
- if (wall.curvePoint) expand(wall.curvePoint.x, wall.curvePoint.y, wall.thickness / 2);
65614
- }
65615
- for (const item of floor.furniture) {
65616
- var _item$scale$x, _item$scale, _item$scale$y, _item$scale2, _ref, _item$width, _ref2, _item$depth;
65617
- const cat = getCatalogItem(item.catalogId);
65618
- 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);
65619
- 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);
65620
- 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;
65621
- 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;
65622
- const half = Math.max(w, d) / 2;
65623
- expand(item.position.x, item.position.y, half);
65624
- if (item.catalogId === "camera" && showCameraCones()) {
65625
- const angle = item.rotation * Math.PI / 180;
65626
- const range = Math.max(w, d) * 6;
65627
- expand(item.position.x + Math.cos(angle) * range, item.position.y + Math.sin(angle) * range, half);
65628
- }
65629
- }
65630
- if (!found) return getFloorWallBounds(floor);
65631
- const width = maxX - minX;
65632
- const height = maxY - minY;
65633
- if (width <= 0 || height <= 0) return null;
65634
- return {
65635
- minX,
65636
- minY,
65637
- maxX,
65638
- maxY,
65639
- width,
65640
- height
65641
- };
65642
- }
65643
- /** Bounds for viewOnly fit: walls + furniture bodies + margin, never crops content */
65637
+ /** Bounds for viewOnly fit: wall rect + margin (stable aspect ratio) */
65644
65638
  function getViewOnlyFitBounds(floor = get(currentFloor)) {
65645
- const bounds = getFloorContentBounds(floor);
65646
- if (!bounds) return null;
65639
+ const wallBounds = getFloorWallBounds(floor);
65640
+ if (!wallBounds) return null;
65647
65641
  const margin = 40;
65648
65642
  return {
65649
- minX: bounds.minX - margin,
65650
- minY: bounds.minY - margin,
65651
- maxX: bounds.maxX + margin,
65652
- maxY: bounds.maxY + margin,
65653
- width: bounds.width + margin * 2,
65654
- height: bounds.height + margin * 2
65643
+ minX: wallBounds.minX - margin,
65644
+ minY: wallBounds.minY - margin,
65645
+ maxX: wallBounds.maxX + margin,
65646
+ maxY: wallBounds.maxY + margin,
65647
+ width: wallBounds.width + margin * 2,
65648
+ height: wallBounds.height + margin * 2
65655
65649
  };
65656
65650
  }
65657
65651
  function getCanvasFrameStyle() {
@@ -66324,7 +66318,8 @@ function FloorPlanCanvas($$anchor, $$props) {
66324
66318
  resize();
66325
66319
  setTextureLoadCallback(() => {});
66326
66320
  const resizeObs = new ResizeObserver(resize);
66327
- resizeObs.observe(canvas.parentElement);
66321
+ const resizeTarget = $$props.viewOnly ? canvasFrame === null || canvasFrame === void 0 ? void 0 : canvasFrame.parentElement : canvasFrame;
66322
+ if (resizeTarget) resizeObs.observe(resizeTarget);
66328
66323
  requestAnimationFrame(draw);
66329
66324
  let initialFitDone = false;
66330
66325
  const unsub1 = activeFloor.subscribe((f) => {
@@ -69195,11 +69190,13 @@ function FloorPlanCanvas($$anchor, $$props) {
69195
69190
  var div = root$1();
69196
69191
  event("keydown", $window, onKeyDown);
69197
69192
  event("keyup", $window, onKeyUp);
69193
+ let classes;
69198
69194
  var div_1 = child(div);
69199
69195
  var canvas_1 = child(div_1);
69200
- let classes;
69196
+ let classes_1;
69201
69197
  bind_this(canvas_1, ($$value) => canvas = $$value, () => canvas);
69202
69198
  reset(div_1);
69199
+ bind_this(div_1, ($$value) => canvasFrame = $$value, () => canvasFrame);
69203
69200
  var node = sibling(div_1, 2);
69204
69201
  var consequent = ($$anchor) => {
69205
69202
  var div_2 = root_1$4();
@@ -69727,11 +69724,17 @@ function FloorPlanCanvas($$anchor, $$props) {
69727
69724
  });
69728
69725
  reset(div);
69729
69726
  template_effect(($0) => {
69727
+ classes = set_class(div, 1, "w-full h-full relative overflow-hidden", null, classes, {
69728
+ flex: $$props.viewOnly,
69729
+ "items-center": $$props.viewOnly,
69730
+ "justify-center": $$props.viewOnly
69731
+ });
69730
69732
  set_style(div_1, $0);
69731
- classes = set_class(canvas_1, 1, "block w-full h-full", null, classes, { "pointer-events-none": $$props.viewOnly });
69733
+ set_class(div_1, 1, clsx($$props.viewOnly ? "" : "w-full h-full"));
69734
+ classes_1 = set_class(canvas_1, 1, clsx($$props.viewOnly ? "block" : "block w-full h-full"), null, classes_1, { "pointer-events-none": $$props.viewOnly });
69732
69735
  set_attribute(canvas_1, "tabindex", $$props.viewOnly ? -1 : 0);
69733
- set_style(canvas_1, `cursor: ${get(cursorStyle)};`);
69734
- }, [() => getCanvasFrameStyle()]);
69736
+ set_style(canvas_1, $$props.viewOnly ? `width:${get(viewOnlyCanvasW)}px;height:${get(viewOnlyCanvasH)}px;cursor:${get(cursorStyle)};` : `cursor: ${get(cursorStyle)};`);
69737
+ }, [() => $$props.viewOnly ? `width:${get(viewOnlyCanvasW)}px;height:${get(viewOnlyCanvasH)}px;flex-shrink:0;line-height:0;` : getCanvasFrameStyle()]);
69735
69738
  delegated("mousedown", canvas_1, onMouseDown);
69736
69739
  delegated("mousemove", canvas_1, onMouseMove);
69737
69740
  delegated("mouseup", canvas_1, onMouseUp);