@ibodr/editor 0.2.16 → 0.2.17

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.mjs CHANGED
@@ -4463,13 +4463,11 @@ var LOD_KEEP_SCREEN_PX = 36;
4463
4463
  var LOD_KEEP_TEXT_PX = 7;
4464
4464
  var LOD_CULL_MARGIN = 0.75;
4465
4465
  var LOD_SNAPSHOT_SCREEN_PX = 180;
4466
- var LOD_OVERVIEW_ZOOM = 0.2;
4467
4466
  function getShapeRenderMode(input) {
4468
4467
  if (!input.hasLodStyle || input.interactive) return "dom";
4469
4468
  if (input.outsideViewport) return "unmounted";
4470
4469
  const screenMax = Math.max(input.pageWidth, input.pageHeight) * input.zoom;
4471
4470
  const textScreen = (input.labelSize ?? 0) * input.zoom;
4472
- if (input.zoom < LOD_OVERVIEW_ZOOM && !input.unmountWhenCulled) return "canvas";
4473
4471
  const snapshotBelow = input.snapshotBelowPx ?? 0;
4474
4472
  if (snapshotBelow > 0 && screenMax < snapshotBelow) {
4475
4473
  return input.hasSnapshot ? "canvas" : "dom";
@@ -4868,36 +4866,46 @@ function paintSnapshot(ctx, camera, dpr, matrix, mesh, bitmap, padPx = 0) {
4868
4866
  }
4869
4867
  function paintLodLabel(ctx, mesh) {
4870
4868
  const text = mesh.label?.trim();
4871
- if (!text) return;
4872
- const size = Math.max(10, mesh.labelSize || 16);
4873
- const pad = Math.max(8, size * 0.45);
4869
+ if (!text || mesh.w < 4 || mesh.h < 4) return;
4870
+ const pad = Math.min(mesh.w, mesh.h) * 0.08;
4874
4871
  const maxWidth = mesh.w - pad * 2;
4875
- const maxY = mesh.y + mesh.h - pad;
4876
- if (maxWidth < 8 || maxY <= mesh.y + pad) return;
4872
+ const innerH = mesh.h - pad * 2;
4873
+ if (maxWidth < 4 || innerH < 4) return;
4874
+ const preferred = mesh.labelSize > 0 ? mesh.labelSize : innerH * 0.4;
4875
+ const size = Math.min(Math.max(preferred, innerH * 0.22), innerH * 0.82);
4876
+ if (size < 1) return;
4877
4877
  ctx.save();
4878
4878
  ctx.beginPath();
4879
4879
  ctx.rect(mesh.x, mesh.y, mesh.w, mesh.h);
4880
4880
  ctx.clip();
4881
4881
  ctx.fillStyle = mesh.labelColor || "#1d1d1d";
4882
4882
  ctx.font = `${size}px sans-serif`;
4883
- ctx.textAlign = "left";
4884
- ctx.textBaseline = "top";
4883
+ ctx.textAlign = "center";
4884
+ ctx.textBaseline = "middle";
4885
4885
  const words = text.split(/\s+/);
4886
+ const lines = [];
4886
4887
  let line = "";
4887
- let y = mesh.y + pad;
4888
- const lineHeight = size * 1.25;
4889
4888
  for (const word of words) {
4890
- if (y > maxY) break;
4891
4889
  const next = line ? `${line} ${word}` : word;
4892
4890
  if (line && ctx.measureText(next).width > maxWidth) {
4893
- ctx.fillText(line, mesh.x + pad, y, maxWidth);
4891
+ lines.push(line);
4894
4892
  line = word;
4895
- y += lineHeight;
4896
4893
  } else {
4897
4894
  line = next;
4898
4895
  }
4899
4896
  }
4900
- if (line && y <= maxY) ctx.fillText(line, mesh.x + pad, y, maxWidth);
4897
+ if (line) lines.push(line);
4898
+ const lineHeight = size * 1.15;
4899
+ const maxLines = Math.max(1, Math.floor(innerH / lineHeight));
4900
+ const fits = lines.length <= maxLines;
4901
+ const visible = fits ? lines : lines.slice(0, maxLines);
4902
+ const blockH = visible.length * lineHeight;
4903
+ let y = fits ? mesh.y + mesh.h / 2 - blockH / 2 + lineHeight / 2 : mesh.y + pad + lineHeight / 2;
4904
+ const x = mesh.x + mesh.w / 2;
4905
+ for (const row of visible) {
4906
+ ctx.fillText(row, x, y, maxWidth);
4907
+ y += lineHeight;
4908
+ }
4901
4909
  ctx.restore();
4902
4910
  }
4903
4911
  var LOD_OVERSCAN_SCREEN_PX = 192;
@@ -4993,7 +5001,7 @@ function useMountedRenderingShapes() {
4993
5001
  var CAPTURES_PER_PASS = 2;
4994
5002
  function captureDueSnapshots(editor) {
4995
5003
  const frame = readFrame(editor);
4996
- if (frame.moving || frame.debug || frame.zoom < LOD_OVERVIEW_ZOOM) return;
5004
+ if (frame.moving || frame.debug) return;
4997
5005
  let container;
4998
5006
  try {
4999
5007
  container = editor.getContainer();
@@ -26550,7 +26558,7 @@ function getFontsFromRichText(editor, richText, initialState2) {
26550
26558
  // src/index.ts
26551
26559
  registerDrawLibraryVersion(
26552
26560
  "@ibodr/editor",
26553
- "0.2.16",
26561
+ "0.2.17",
26554
26562
  "esm"
26555
26563
  );
26556
26564
  /*!