@ibodr/editor 0.2.15 → 0.2.16

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,11 +4463,13 @@ 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;
4466
4467
  function getShapeRenderMode(input) {
4467
4468
  if (!input.hasLodStyle || input.interactive) return "dom";
4468
4469
  if (input.outsideViewport) return "unmounted";
4469
4470
  const screenMax = Math.max(input.pageWidth, input.pageHeight) * input.zoom;
4470
4471
  const textScreen = (input.labelSize ?? 0) * input.zoom;
4472
+ if (input.zoom < LOD_OVERVIEW_ZOOM && !input.unmountWhenCulled) return "canvas";
4471
4473
  const snapshotBelow = input.snapshotBelowPx ?? 0;
4472
4474
  if (snapshotBelow > 0 && screenMax < snapshotBelow) {
4473
4475
  return input.hasSnapshot ? "canvas" : "dom";
@@ -4483,39 +4485,61 @@ var snapshots = /* @__PURE__ */ new Map();
4483
4485
  var attempts = /* @__PURE__ */ new WeakMap();
4484
4486
  var lodSnapshotEpoch = atom("lod-snapshot-epoch", 0);
4485
4487
  var retryTimer = 0;
4486
- function lodSnapshotCovers(shape, screenPx) {
4488
+ var notifyTimer = 0;
4489
+ function notifySnapshotEpoch() {
4490
+ if (notifyTimer !== 0 || typeof window === "undefined") return;
4491
+ notifyTimer = window.setTimeout(() => {
4492
+ notifyTimer = 0;
4493
+ lodSnapshotEpoch.set(lodSnapshotEpoch.get() + 1);
4494
+ }, 0);
4495
+ }
4496
+ function contentKey(shape) {
4497
+ const props = shape.props;
4498
+ const crop = props.crop;
4499
+ return [
4500
+ shape.type,
4501
+ props.assetId ?? "",
4502
+ props.src ?? "",
4503
+ props.w ?? "",
4504
+ props.h ?? "",
4505
+ props.currentPage ?? "",
4506
+ props.pagesVisible ?? "",
4507
+ props.currentSlide ?? "",
4508
+ props.isFlipped ?? "",
4509
+ crop ? JSON.stringify(crop) : ""
4510
+ ].join("");
4511
+ }
4512
+ function lodSnapshotCovers(shape, _screenPx) {
4487
4513
  const entry = snapshots.get(shape.id);
4488
- if (!entry || entry.shape !== shape) return false;
4489
- return entry.screenPx >= screenPx * 0.85;
4514
+ return Boolean(entry && entry.key === contentKey(shape) && entry.canvas.width > 1);
4490
4515
  }
4491
4516
  function getLodSnapshot(shape) {
4492
4517
  const entry = snapshots.get(shape.id);
4493
- if (!entry || entry.shape !== shape) return null;
4518
+ if (!entry || entry.key !== contentKey(shape) || entry.canvas.width < 2) return null;
4494
4519
  return entry.canvas;
4495
4520
  }
4496
4521
  function releaseCanvas(canvas) {
4497
4522
  canvas.width = 0;
4498
4523
  canvas.height = 0;
4499
4524
  }
4500
- function storeLodSnapshot(shape, canvas, screenPx) {
4525
+ function storeLodSnapshot(shape, canvas, _screenPx) {
4526
+ const key = contentKey(shape);
4501
4527
  const previous = snapshots.get(shape.id);
4502
4528
  if (previous && previous.canvas !== canvas) releaseCanvas(previous.canvas);
4503
- snapshots.delete(shape.id);
4504
- snapshots.set(shape.id, { shape, canvas, screenPx });
4505
- while (snapshots.size > MAX_SNAPSHOTS) {
4506
- const oldest = snapshots.keys().next().value;
4507
- if (oldest === void 0) break;
4508
- const entry = snapshots.get(oldest);
4509
- snapshots.delete(oldest);
4510
- if (entry) releaseCanvas(entry.canvas);
4529
+ if (!previous && snapshots.size >= MAX_SNAPSHOTS) {
4530
+ releaseCanvas(canvas);
4531
+ return false;
4511
4532
  }
4533
+ if (previous) snapshots.delete(shape.id);
4534
+ snapshots.set(shape.id, { key, canvas });
4512
4535
  attempts.delete(shape);
4536
+ return true;
4513
4537
  }
4514
4538
  function scheduleLodSnapshotPass() {
4515
4539
  if (retryTimer !== 0 || typeof window === "undefined") return;
4516
4540
  retryTimer = window.setTimeout(() => {
4517
4541
  retryTimer = 0;
4518
- lodSnapshotEpoch.set(lodSnapshotEpoch.get() + 1);
4542
+ notifySnapshotEpoch();
4519
4543
  }, 250);
4520
4544
  }
4521
4545
  function captureShapeSnapshot(element) {
@@ -4728,7 +4752,7 @@ function ownRenderMode(editor, shape, frame, outsideViewport) {
4728
4752
  const pageBounds = editor.getShapePageBounds(shape);
4729
4753
  const pageWidth = pageBounds?.w ?? mesh?.w ?? 0;
4730
4754
  const pageHeight = pageBounds?.h ?? mesh?.h ?? 0;
4731
- const screenMax = Math.max(pageWidth, pageHeight) * frame.zoom;
4755
+ Math.max(pageWidth, pageHeight) * frame.zoom;
4732
4756
  return getShapeRenderMode({
4733
4757
  zoom: frame.zoom,
4734
4758
  lodZoom: frame.lodZoom,
@@ -4742,11 +4766,11 @@ function ownRenderMode(editor, shape, frame, outsideViewport) {
4742
4766
  pageHeight,
4743
4767
  labelSize: style?.labelSize ?? 0,
4744
4768
  snapshotBelowPx: style?.snapshotBelowPx,
4745
- hasSnapshot: snapshotCoversShape(shape, screenMax)
4769
+ hasSnapshot: snapshotCoversShape(shape)
4746
4770
  });
4747
4771
  }
4748
4772
  function snapshotCoversShape(shape, screenMax) {
4749
- return lodSnapshotCovers(shape, screenMax);
4773
+ return lodSnapshotCovers(shape);
4750
4774
  }
4751
4775
  function coveredByDomBackground(editor, shape, frame) {
4752
4776
  let parentId = shape.parentId;
@@ -4818,6 +4842,9 @@ function paintShape(ctx, camera, dpr, matrix, mesh, padPx = 0) {
4818
4842
  Math.PI * 2
4819
4843
  );
4820
4844
  ctx.fill();
4845
+ } else {
4846
+ ctx.fillStyle = "rgba(0, 0, 0, 0.08)";
4847
+ ctx.fillRect(mesh.x, mesh.y, Math.max(mesh.w, 1), Math.max(mesh.h, 1));
4821
4848
  }
4822
4849
  paintLodLabel(ctx, mesh);
4823
4850
  }
@@ -4926,7 +4953,7 @@ function paintVisibleLodShapes(ctx, editor, camera, dpr, shapes, frame, paintBou
4926
4953
  paintSnapshot(ctx, camera, dpr, matrix, mesh, snapshot, padPx);
4927
4954
  if (mode !== "dom") continue;
4928
4955
  }
4929
- if (mode !== "canvas" || style.unmountWhenCulled) continue;
4956
+ if (mode !== "canvas") continue;
4930
4957
  paintShape(ctx, camera, dpr, matrix, mesh, padPx);
4931
4958
  }
4932
4959
  }
@@ -4966,7 +4993,7 @@ function useMountedRenderingShapes() {
4966
4993
  var CAPTURES_PER_PASS = 2;
4967
4994
  function captureDueSnapshots(editor) {
4968
4995
  const frame = readFrame(editor);
4969
- if (frame.moving || frame.debug) return;
4996
+ if (frame.moving || frame.debug || frame.zoom < LOD_OVERVIEW_ZOOM) return;
4970
4997
  let container;
4971
4998
  try {
4972
4999
  container = editor.getContainer();
@@ -4986,7 +5013,7 @@ function captureDueSnapshots(editor) {
4986
5013
  if (!bounds || !frame.expanded.collides(bounds)) continue;
4987
5014
  const screenMax = Math.max(bounds.w, bounds.h) * frame.zoom;
4988
5015
  if (screenMax < 8 || screenMax > below * 1.35) continue;
4989
- if (lodSnapshotCovers(shape, screenMax)) continue;
5016
+ if (lodSnapshotCovers(shape)) continue;
4990
5017
  if (captured >= CAPTURES_PER_PASS) {
4991
5018
  deferred = true;
4992
5019
  break;
@@ -4997,12 +5024,12 @@ function captureDueSnapshots(editor) {
4997
5024
  noteSnapshotMiss(shape);
4998
5025
  continue;
4999
5026
  }
5000
- storeLodSnapshot(shape, bitmap, screenMax);
5001
- captured += 1;
5002
- changed = true;
5027
+ if (storeLodSnapshot(shape, bitmap)) {
5028
+ captured += 1;
5029
+ changed = true;
5030
+ }
5003
5031
  }
5004
- if (changed) lodSnapshotEpoch.set(lodSnapshotEpoch.get() + 1);
5005
- if (deferred) scheduleLodSnapshotPass();
5032
+ if (changed || deferred) notifySnapshotEpoch();
5006
5033
  }
5007
5034
  function LodCanvas() {
5008
5035
  const editor = useEditor();
@@ -26523,7 +26550,7 @@ function getFontsFromRichText(editor, richText, initialState2) {
26523
26550
  // src/index.ts
26524
26551
  registerDrawLibraryVersion(
26525
26552
  "@ibodr/editor",
26526
- "0.2.15",
26553
+ "0.2.16",
26527
26554
  "esm"
26528
26555
  );
26529
26556
  /*!