floor-editor-ts 1.1.0 → 1.1.2

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.
@@ -61678,27 +61678,32 @@ var persons = [];
61678
61678
  var lastSpawnTime = 0;
61679
61679
  var SPAWN_INTERVAL = 1e3;
61680
61680
  var MAX_PERSONS = 20;
61681
- var getHeatmapColor = (t, alpha = 1) => {
61681
+ function getHeatmapColor(t, alpha = 1) {
61682
61682
  t = Math.max(0, Math.min(t, 1));
61683
61683
  let r, g, b;
61684
- if (t < .35) {
61685
- const k = t / .35;
61684
+ if (t < .25) {
61685
+ const k = t / .25;
61686
61686
  r = 0;
61687
- g = Math.round(120 + 135 * k);
61688
- b = Math.round(255 - 180 * k);
61689
- } else if (t < .7) {
61690
- const k = (t - .35) / .35;
61687
+ g = Math.round(100 * k);
61688
+ b = 255;
61689
+ } else if (t < .5) {
61690
+ const k = (t - .25) / .25;
61691
+ r = 0;
61692
+ g = Math.round(100 + 155 * k);
61693
+ b = Math.round(255 * (1 - k));
61694
+ } else if (t < .75) {
61695
+ const k = (t - .5) / .25;
61691
61696
  r = Math.round(255 * k);
61692
61697
  g = 255;
61693
61698
  b = 0;
61694
61699
  } else {
61695
- const k = (t - .7) / .3;
61700
+ const k = (t - .75) / .25;
61696
61701
  r = 255;
61697
- g = Math.round(255 - 255 * k);
61702
+ g = Math.round(255 * (1 - k));
61698
61703
  b = 0;
61699
61704
  }
61700
61705
  return `rgba(${r}, ${g}, ${b}, ${alpha})`;
61701
- };
61706
+ }
61702
61707
  var drawCamera = (ctx, w, d, color, heatmapMatrix, hasPerson = false, showHeatmap = false) => {
61703
61708
  const bodyRadius = 4;
61704
61709
  const lensR = Math.min(w, d) * .25;
@@ -63867,15 +63872,15 @@ function drawAnnotations(cs, floor, selectedAnnotationId, dimSettings) {
63867
63872
  }
63868
63873
  var ROOM_FILLS_BY_TYPE = {
63869
63874
  "Living Room": "rgba(96, 165, 250, 0.08)",
63870
- "Bedroom": "rgba(167, 139, 250, 0.08)",
63871
- "Kitchen": "rgba(251, 191, 36, 0.08)",
63872
- "Bathroom": "rgba(45, 212, 191, 0.08)",
63875
+ Bedroom: "rgba(167, 139, 250, 0.08)",
63876
+ Kitchen: "rgba(251, 191, 36, 0.08)",
63877
+ Bathroom: "rgba(45, 212, 191, 0.08)",
63873
63878
  "Dining Room": "rgba(251, 146, 60, 0.08)",
63874
- "Office": "rgba(52, 211, 153, 0.08)",
63875
- "Hallway": "rgba(156, 163, 175, 0.06)",
63876
- "Closet": "rgba(244, 114, 182, 0.06)",
63877
- "Laundry": "rgba(129, 140, 248, 0.08)",
63878
- "Garage": "rgba(163, 163, 163, 0.08)"
63879
+ Office: "rgba(52, 211, 153, 0.08)",
63880
+ Hallway: "rgba(156, 163, 175, 0.06)",
63881
+ Closet: "rgba(244, 114, 182, 0.06)",
63882
+ Laundry: "rgba(129, 140, 248, 0.08)",
63883
+ Garage: "rgba(163, 163, 163, 0.08)"
63879
63884
  };
63880
63885
  var ROOM_FILLS_DEFAULT = [
63881
63886
  "rgba(167, 139, 250, 0.07)",
@@ -63897,15 +63902,15 @@ function getRoomFill(room, index) {
63897
63902
  }
63898
63903
  var ROOM_FLOOR_PATTERN = {
63899
63904
  "Living Room": "wood",
63900
- "Bedroom": "wood",
63901
- "Office": "wood",
63905
+ Bedroom: "wood",
63906
+ Office: "wood",
63902
63907
  "Dining Room": "wood",
63903
- "Hallway": "wood",
63904
- "Kitchen": "tile",
63905
- "Bathroom": "tile",
63906
- "Laundry": "tile",
63907
- "Garage": "stone",
63908
- "Closet": "none"
63908
+ Hallway: "wood",
63909
+ Kitchen: "tile",
63910
+ Bathroom: "tile",
63911
+ Laundry: "tile",
63912
+ Garage: "stone",
63913
+ Closet: "none"
63909
63914
  };
63910
63915
  function drawRoomFloorPattern(cs, room, screenPoly) {
63911
63916
  var _ROOM_FLOOR_PATTERN$r;
@@ -64175,13 +64180,19 @@ function drawMinimap(cs, minimapCanvas, floor, getWorldBBox) {
64175
64180
  mctx.lineWidth = 1;
64176
64181
  mctx.strokeRect(0, 0, mw, mh);
64177
64182
  }
64183
+ var heatmapCache = null;
64184
+ function getMatrixKey(matrix) {
64185
+ const flat = matrix.flat();
64186
+ const step = Math.max(1, Math.floor(flat.length / 20));
64187
+ return flat.filter((_, i) => i % step === 0).join(",");
64188
+ }
64178
64189
  function drawFloorHeatmap(cs, floor, heatmapMatrix, detectedRooms) {
64179
64190
  var _heatmapMatrix$;
64180
- const { ctx, zoom } = cs;
64191
+ const { ctx } = cs;
64181
64192
  const rows = heatmapMatrix.length;
64182
64193
  const cols = ((_heatmapMatrix$ = heatmapMatrix[0]) === null || _heatmapMatrix$ === void 0 ? void 0 : _heatmapMatrix$.length) || 0;
64183
64194
  if (rows === 0 || cols === 0) return;
64184
- const maxValue = Math.max(...heatmapMatrix.flat());
64195
+ const maxValue = heatmapMatrix.reduce((max, row) => row.reduce((m, v) => v > m ? v : m, max), 0);
64185
64196
  if (maxValue <= 0) return;
64186
64197
  const bounds = getFloorBounds(floor);
64187
64198
  if (!bounds) return;
@@ -64189,14 +64200,73 @@ function drawFloorHeatmap(cs, floor, heatmapMatrix, detectedRooms) {
64189
64200
  const boxW = bounds.width;
64190
64201
  const boxH = bounds.height;
64191
64202
  if (boxW <= 0 || boxH <= 0) return;
64192
- const cellW = boxW / cols;
64193
- const cellH = boxH / rows;
64203
+ const matrixKey = getMatrixKey(heatmapMatrix);
64204
+ const floorId = floor.id;
64205
+ const needsRedraw = !heatmapCache || heatmapCache.matrixKey !== matrixKey || heatmapCache.floorId !== floorId;
64206
+ const OFFSCREEN_W = 512;
64207
+ const OFFSCREEN_H = 512;
64208
+ if (needsRedraw) {
64209
+ const offCellW = OFFSCREEN_W / cols;
64210
+ const offCellH = OFFSCREEN_H / rows;
64211
+ const radius = Math.max(offCellW, offCellH) * 1.3;
64212
+ const blobCanvas = document.createElement("canvas");
64213
+ blobCanvas.width = OFFSCREEN_W;
64214
+ blobCanvas.height = OFFSCREEN_H;
64215
+ const blobCtx = blobCanvas.getContext("2d");
64216
+ blobCtx.filter = `blur(${Math.min(10, Math.max(2, radius * .2))}px)`;
64217
+ for (let y = 0; y < rows; y++) for (let x = 0; x < cols; x++) {
64218
+ const value = heatmapMatrix[y][x];
64219
+ if (!value || value <= 0) continue;
64220
+ const intensity = Math.min(value / maxValue, 1);
64221
+ const px = (x + .5) * offCellW;
64222
+ const py = (y + .5) * offCellH;
64223
+ const alpha = .5 + intensity * .45;
64224
+ const gradient = blobCtx.createRadialGradient(px, py, 0, px, py, radius);
64225
+ gradient.addColorStop(0, getHeatmapColor(intensity, alpha));
64226
+ gradient.addColorStop(.2, getHeatmapColor(intensity, alpha * .75));
64227
+ gradient.addColorStop(.5, getHeatmapColor(intensity, alpha * .25));
64228
+ gradient.addColorStop(1, getHeatmapColor(intensity, 0));
64229
+ blobCtx.fillStyle = gradient;
64230
+ blobCtx.beginPath();
64231
+ blobCtx.arc(px, py, radius, 0, Math.PI * 2);
64232
+ blobCtx.fill();
64233
+ }
64234
+ const finalCanvas = document.createElement("canvas");
64235
+ finalCanvas.width = OFFSCREEN_W;
64236
+ finalCanvas.height = OFFSCREEN_H;
64237
+ const finalCtx = finalCanvas.getContext("2d");
64238
+ finalCtx.drawImage(blobCanvas, 0, 0);
64239
+ finalCtx.filter = "none";
64240
+ finalCtx.strokeStyle = "rgba(255, 255, 255, 0.18)";
64241
+ finalCtx.lineWidth = .5;
64242
+ finalCtx.beginPath();
64243
+ for (let x = 0; x <= cols; x++) {
64244
+ const px = x * offCellW;
64245
+ finalCtx.moveTo(px, 0);
64246
+ finalCtx.lineTo(px, OFFSCREEN_H);
64247
+ }
64248
+ for (let y = 0; y <= rows; y++) {
64249
+ const py = y * offCellH;
64250
+ finalCtx.moveTo(0, py);
64251
+ finalCtx.lineTo(OFFSCREEN_W, py);
64252
+ }
64253
+ finalCtx.stroke();
64254
+ heatmapCache = {
64255
+ canvas: finalCanvas,
64256
+ matrixKey,
64257
+ floorId
64258
+ };
64259
+ }
64260
+ const p1 = wts(cs, minX, minY);
64261
+ const p2 = wts(cs, maxX, maxY);
64262
+ const destX = Math.min(p1.x, p2.x);
64263
+ const destY = Math.min(p1.y, p2.y);
64264
+ const destW = Math.abs(p2.x - p1.x);
64265
+ const destH = Math.abs(p2.y - p1.y);
64266
+ const canvasW = ctx.canvas.width;
64267
+ const canvasH = ctx.canvas.height;
64268
+ if (destX > canvasW || destY > canvasH || destX + destW < 0 || destY + destH < 0) return;
64194
64269
  ctx.save();
64195
- const boundP1 = wts(cs, minX, minY);
64196
- const boundP2 = wts(cs, maxX, maxY);
64197
- ctx.beginPath();
64198
- ctx.rect(Math.min(boundP1.x, boundP2.x), Math.min(boundP1.y, boundP2.y), Math.abs(boundP2.x - boundP1.x), Math.abs(boundP2.y - boundP1.y));
64199
- ctx.clip();
64200
64270
  let hasRoomClip = false;
64201
64271
  ctx.beginPath();
64202
64272
  for (const room of detectedRooms) {
@@ -64208,45 +64278,10 @@ function drawFloorHeatmap(cs, floor, heatmapMatrix, detectedRooms) {
64208
64278
  ctx.closePath();
64209
64279
  hasRoomClip = true;
64210
64280
  }
64211
- if (hasRoomClip) ctx.clip();
64212
- ctx.globalCompositeOperation = "source-over";
64213
- ctx.filter = `blur(${Math.min(14, Math.max(3, 5 * zoom))}px)`;
64214
- const radius = Math.max(cellW, cellH) * zoom * 1.15;
64215
- for (let y = 0; y < rows; y++) for (let x = 0; x < cols; x++) {
64216
- const value = heatmapMatrix[y][x];
64217
- if (!value || value <= 0) continue;
64218
- const intensity = Math.min(value / maxValue, 1);
64219
- const s = wts(cs, minX + (x + .5) * cellW, minY + (y + .5) * cellH);
64220
- const gradient = ctx.createRadialGradient(s.x, s.y, 0, s.x, s.y, radius);
64221
- const alpha = .08 + intensity * .45;
64222
- gradient.addColorStop(0, getHeatmapColor(intensity, alpha));
64223
- gradient.addColorStop(.35, getHeatmapColor(intensity, alpha * .35));
64224
- gradient.addColorStop(1, getHeatmapColor(intensity, 0));
64225
- ctx.fillStyle = gradient;
64226
- ctx.beginPath();
64227
- ctx.arc(s.x, s.y, radius, 0, Math.PI * 2);
64228
- ctx.fill();
64229
- }
64230
- ctx.filter = "none";
64231
- ctx.globalCompositeOperation = "source-over";
64232
- ctx.strokeStyle = "rgba(255, 255, 255, 0.22)";
64233
- ctx.lineWidth = Math.max(.5, 1 / zoom);
64234
- ctx.beginPath();
64235
- for (let x = 0; x <= cols; x++) {
64236
- const wx = minX + x * cellW;
64237
- const p1 = wts(cs, wx, minY);
64238
- const p2 = wts(cs, wx, maxY);
64239
- ctx.moveTo(p1.x, p1.y);
64240
- ctx.lineTo(p2.x, p2.y);
64241
- }
64242
- for (let y = 0; y <= rows; y++) {
64243
- const wy = minY + y * cellH;
64244
- const p1 = wts(cs, minX, wy);
64245
- const p2 = wts(cs, maxX, wy);
64246
- ctx.moveTo(p1.x, p1.y);
64247
- ctx.lineTo(p2.x, p2.y);
64248
- }
64249
- ctx.stroke();
64281
+ if (hasRoomClip) ctx.clip("evenodd");
64282
+ ctx.globalAlpha = .92;
64283
+ ctx.drawImage(heatmapCache.canvas, destX, destY, destW, destH);
64284
+ ctx.globalAlpha = 1;
64250
64285
  ctx.restore();
64251
64286
  }
64252
64287
  //#endregion
@@ -65412,7 +65447,7 @@ function FloorPlanCanvas($$anchor, $$props) {
65412
65447
  canvasDirty = false;
65413
65448
  ctx.clearRect(0, 0, get(width), get(height));
65414
65449
  ctx.fillStyle = "#f8f9fa";
65415
- ctx.fillRect(0, 0, $$props.floorMaxWidth, $$props.floorMaxHeight);
65450
+ ctx.fillRect(0, 0, $$props.viewOnly ? $$props.floorMaxWidth : get(width), $$props.viewOnly ? $$props.floorMaxHeight : get(height));
65416
65451
  drawGrid();
65417
65452
  if (!$$props.viewOnly && get(layerVis).guides) drawGuides$1();
65418
65453
  drawBackgroundImage();
@@ -65433,7 +65468,10 @@ function FloorPlanCanvas($$anchor, $$props) {
65433
65468
  return id === selId || multiIds.has(id);
65434
65469
  }
65435
65470
  drawRooms$1();
65436
- if (floor && $$props.heatmapEnabled) drawFloorHeatmap(getCS(), floor, $$props.heatmapMatrix || [], get(detectedRooms));
65471
+ if (floor && $$props.heatmapEnabled && $$props.heatmapMatrix && $$props.heatmapMatrix.length > 0) {
65472
+ var _$$props$heatmapMatri;
65473
+ drawFloorHeatmap(getCS(), floor, (_$$props$heatmapMatri = $$props.heatmapMatrix) !== null && _$$props$heatmapMatri !== void 0 ? _$$props$heatmapMatri : [], get(detectedRooms));
65474
+ }
65437
65475
  if (!$$props.viewOnly) drawSnapPoints$1();
65438
65476
  if (get(layerVis).walls) {
65439
65477
  for (const w of floor.walls) drawWall$1(w, isSelected(w.id));