floor-editor-ts 1.1.7 → 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,42 +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: fit walls to fill the entire viewport no gray margins */
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;
65105
- const bounds = getFloorWallBounds(get(currentFloor));
65132
+ const container = canvasFrame === null || canvasFrame === void 0 ? void 0 : canvasFrame.parentElement;
65133
+ if (!container || !get(currentFloor)) return;
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
- const padding = 12;
65117
- const contentW = bounds.width + padding * 2;
65118
- const contentH = bounds.height + padding * 2;
65119
65157
  set(camX, (bounds.minX + bounds.maxX) / 2);
65120
65158
  set(camY, (bounds.minY + bounds.maxY) / 2);
65121
- set(zoom, Math.max(get(width) / contentW, get(height) / contentH), true);
65159
+ set(zoom, Math.min(canvasW / bounds.width, canvasH / bounds.height), true);
65122
65160
  set(zoom, Math.max(get(zoom), .1), true);
65123
65161
  markDirty();
65124
65162
  }
@@ -65596,6 +65634,20 @@ function FloorPlanCanvas($$anchor, $$props) {
65596
65634
  height
65597
65635
  };
65598
65636
  }
65637
+ /** Bounds for viewOnly fit: wall rect + margin (stable aspect ratio) */
65638
+ function getViewOnlyFitBounds(floor = get(currentFloor)) {
65639
+ const wallBounds = getFloorWallBounds(floor);
65640
+ if (!wallBounds) return null;
65641
+ const margin = 40;
65642
+ return {
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
65649
+ };
65650
+ }
65599
65651
  function getCanvasFrameStyle() {
65600
65652
  return "width: 100%; height: 100%";
65601
65653
  }
@@ -66266,7 +66318,8 @@ function FloorPlanCanvas($$anchor, $$props) {
66266
66318
  resize();
66267
66319
  setTextureLoadCallback(() => {});
66268
66320
  const resizeObs = new ResizeObserver(resize);
66269
- 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);
66270
66323
  requestAnimationFrame(draw);
66271
66324
  let initialFitDone = false;
66272
66325
  const unsub1 = activeFloor.subscribe((f) => {
@@ -69137,11 +69190,13 @@ function FloorPlanCanvas($$anchor, $$props) {
69137
69190
  var div = root$1();
69138
69191
  event("keydown", $window, onKeyDown);
69139
69192
  event("keyup", $window, onKeyUp);
69193
+ let classes;
69140
69194
  var div_1 = child(div);
69141
69195
  var canvas_1 = child(div_1);
69142
- let classes;
69196
+ let classes_1;
69143
69197
  bind_this(canvas_1, ($$value) => canvas = $$value, () => canvas);
69144
69198
  reset(div_1);
69199
+ bind_this(div_1, ($$value) => canvasFrame = $$value, () => canvasFrame);
69145
69200
  var node = sibling(div_1, 2);
69146
69201
  var consequent = ($$anchor) => {
69147
69202
  var div_2 = root_1$4();
@@ -69669,11 +69724,17 @@ function FloorPlanCanvas($$anchor, $$props) {
69669
69724
  });
69670
69725
  reset(div);
69671
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
+ });
69672
69732
  set_style(div_1, $0);
69673
- 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 });
69674
69735
  set_attribute(canvas_1, "tabindex", $$props.viewOnly ? -1 : 0);
69675
- set_style(canvas_1, `cursor: ${get(cursorStyle)};`);
69676
- }, [() => 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()]);
69677
69738
  delegated("mousedown", canvas_1, onMouseDown);
69678
69739
  delegated("mousemove", canvas_1, onMouseMove);
69679
69740
  delegated("mouseup", canvas_1, onMouseUp);