@ibodr/editor 0.2.15 → 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 +73 -38
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.mjs
CHANGED
|
@@ -4483,39 +4483,61 @@ var snapshots = /* @__PURE__ */ new Map();
|
|
|
4483
4483
|
var attempts = /* @__PURE__ */ new WeakMap();
|
|
4484
4484
|
var lodSnapshotEpoch = atom("lod-snapshot-epoch", 0);
|
|
4485
4485
|
var retryTimer = 0;
|
|
4486
|
-
|
|
4486
|
+
var notifyTimer = 0;
|
|
4487
|
+
function notifySnapshotEpoch() {
|
|
4488
|
+
if (notifyTimer !== 0 || typeof window === "undefined") return;
|
|
4489
|
+
notifyTimer = window.setTimeout(() => {
|
|
4490
|
+
notifyTimer = 0;
|
|
4491
|
+
lodSnapshotEpoch.set(lodSnapshotEpoch.get() + 1);
|
|
4492
|
+
}, 0);
|
|
4493
|
+
}
|
|
4494
|
+
function contentKey(shape) {
|
|
4495
|
+
const props = shape.props;
|
|
4496
|
+
const crop = props.crop;
|
|
4497
|
+
return [
|
|
4498
|
+
shape.type,
|
|
4499
|
+
props.assetId ?? "",
|
|
4500
|
+
props.src ?? "",
|
|
4501
|
+
props.w ?? "",
|
|
4502
|
+
props.h ?? "",
|
|
4503
|
+
props.currentPage ?? "",
|
|
4504
|
+
props.pagesVisible ?? "",
|
|
4505
|
+
props.currentSlide ?? "",
|
|
4506
|
+
props.isFlipped ?? "",
|
|
4507
|
+
crop ? JSON.stringify(crop) : ""
|
|
4508
|
+
].join("");
|
|
4509
|
+
}
|
|
4510
|
+
function lodSnapshotCovers(shape, _screenPx) {
|
|
4487
4511
|
const entry = snapshots.get(shape.id);
|
|
4488
|
-
|
|
4489
|
-
return entry.screenPx >= screenPx * 0.85;
|
|
4512
|
+
return Boolean(entry && entry.key === contentKey(shape) && entry.canvas.width > 1);
|
|
4490
4513
|
}
|
|
4491
4514
|
function getLodSnapshot(shape) {
|
|
4492
4515
|
const entry = snapshots.get(shape.id);
|
|
4493
|
-
if (!entry || entry.
|
|
4516
|
+
if (!entry || entry.key !== contentKey(shape) || entry.canvas.width < 2) return null;
|
|
4494
4517
|
return entry.canvas;
|
|
4495
4518
|
}
|
|
4496
4519
|
function releaseCanvas(canvas) {
|
|
4497
4520
|
canvas.width = 0;
|
|
4498
4521
|
canvas.height = 0;
|
|
4499
4522
|
}
|
|
4500
|
-
function storeLodSnapshot(shape, canvas,
|
|
4523
|
+
function storeLodSnapshot(shape, canvas, _screenPx) {
|
|
4524
|
+
const key = contentKey(shape);
|
|
4501
4525
|
const previous = snapshots.get(shape.id);
|
|
4502
4526
|
if (previous && previous.canvas !== canvas) releaseCanvas(previous.canvas);
|
|
4503
|
-
snapshots.
|
|
4504
|
-
|
|
4505
|
-
|
|
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);
|
|
4527
|
+
if (!previous && snapshots.size >= MAX_SNAPSHOTS) {
|
|
4528
|
+
releaseCanvas(canvas);
|
|
4529
|
+
return false;
|
|
4511
4530
|
}
|
|
4531
|
+
if (previous) snapshots.delete(shape.id);
|
|
4532
|
+
snapshots.set(shape.id, { key, canvas });
|
|
4512
4533
|
attempts.delete(shape);
|
|
4534
|
+
return true;
|
|
4513
4535
|
}
|
|
4514
4536
|
function scheduleLodSnapshotPass() {
|
|
4515
4537
|
if (retryTimer !== 0 || typeof window === "undefined") return;
|
|
4516
4538
|
retryTimer = window.setTimeout(() => {
|
|
4517
4539
|
retryTimer = 0;
|
|
4518
|
-
|
|
4540
|
+
notifySnapshotEpoch();
|
|
4519
4541
|
}, 250);
|
|
4520
4542
|
}
|
|
4521
4543
|
function captureShapeSnapshot(element) {
|
|
@@ -4728,7 +4750,7 @@ function ownRenderMode(editor, shape, frame, outsideViewport) {
|
|
|
4728
4750
|
const pageBounds = editor.getShapePageBounds(shape);
|
|
4729
4751
|
const pageWidth = pageBounds?.w ?? mesh?.w ?? 0;
|
|
4730
4752
|
const pageHeight = pageBounds?.h ?? mesh?.h ?? 0;
|
|
4731
|
-
|
|
4753
|
+
Math.max(pageWidth, pageHeight) * frame.zoom;
|
|
4732
4754
|
return getShapeRenderMode({
|
|
4733
4755
|
zoom: frame.zoom,
|
|
4734
4756
|
lodZoom: frame.lodZoom,
|
|
@@ -4742,11 +4764,11 @@ function ownRenderMode(editor, shape, frame, outsideViewport) {
|
|
|
4742
4764
|
pageHeight,
|
|
4743
4765
|
labelSize: style?.labelSize ?? 0,
|
|
4744
4766
|
snapshotBelowPx: style?.snapshotBelowPx,
|
|
4745
|
-
hasSnapshot: snapshotCoversShape(shape
|
|
4767
|
+
hasSnapshot: snapshotCoversShape(shape)
|
|
4746
4768
|
});
|
|
4747
4769
|
}
|
|
4748
4770
|
function snapshotCoversShape(shape, screenMax) {
|
|
4749
|
-
return lodSnapshotCovers(shape
|
|
4771
|
+
return lodSnapshotCovers(shape);
|
|
4750
4772
|
}
|
|
4751
4773
|
function coveredByDomBackground(editor, shape, frame) {
|
|
4752
4774
|
let parentId = shape.parentId;
|
|
@@ -4818,6 +4840,9 @@ function paintShape(ctx, camera, dpr, matrix, mesh, padPx = 0) {
|
|
|
4818
4840
|
Math.PI * 2
|
|
4819
4841
|
);
|
|
4820
4842
|
ctx.fill();
|
|
4843
|
+
} else {
|
|
4844
|
+
ctx.fillStyle = "rgba(0, 0, 0, 0.08)";
|
|
4845
|
+
ctx.fillRect(mesh.x, mesh.y, Math.max(mesh.w, 1), Math.max(mesh.h, 1));
|
|
4821
4846
|
}
|
|
4822
4847
|
paintLodLabel(ctx, mesh);
|
|
4823
4848
|
}
|
|
@@ -4841,36 +4866,46 @@ function paintSnapshot(ctx, camera, dpr, matrix, mesh, bitmap, padPx = 0) {
|
|
|
4841
4866
|
}
|
|
4842
4867
|
function paintLodLabel(ctx, mesh) {
|
|
4843
4868
|
const text = mesh.label?.trim();
|
|
4844
|
-
if (!text) return;
|
|
4845
|
-
const
|
|
4846
|
-
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;
|
|
4847
4871
|
const maxWidth = mesh.w - pad * 2;
|
|
4848
|
-
const
|
|
4849
|
-
if (maxWidth <
|
|
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;
|
|
4850
4877
|
ctx.save();
|
|
4851
4878
|
ctx.beginPath();
|
|
4852
4879
|
ctx.rect(mesh.x, mesh.y, mesh.w, mesh.h);
|
|
4853
4880
|
ctx.clip();
|
|
4854
4881
|
ctx.fillStyle = mesh.labelColor || "#1d1d1d";
|
|
4855
4882
|
ctx.font = `${size}px sans-serif`;
|
|
4856
|
-
ctx.textAlign = "
|
|
4857
|
-
ctx.textBaseline = "
|
|
4883
|
+
ctx.textAlign = "center";
|
|
4884
|
+
ctx.textBaseline = "middle";
|
|
4858
4885
|
const words = text.split(/\s+/);
|
|
4886
|
+
const lines = [];
|
|
4859
4887
|
let line = "";
|
|
4860
|
-
let y = mesh.y + pad;
|
|
4861
|
-
const lineHeight = size * 1.25;
|
|
4862
4888
|
for (const word of words) {
|
|
4863
|
-
if (y > maxY) break;
|
|
4864
4889
|
const next = line ? `${line} ${word}` : word;
|
|
4865
4890
|
if (line && ctx.measureText(next).width > maxWidth) {
|
|
4866
|
-
|
|
4891
|
+
lines.push(line);
|
|
4867
4892
|
line = word;
|
|
4868
|
-
y += lineHeight;
|
|
4869
4893
|
} else {
|
|
4870
4894
|
line = next;
|
|
4871
4895
|
}
|
|
4872
4896
|
}
|
|
4873
|
-
if (line
|
|
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
|
+
}
|
|
4874
4909
|
ctx.restore();
|
|
4875
4910
|
}
|
|
4876
4911
|
var LOD_OVERSCAN_SCREEN_PX = 192;
|
|
@@ -4926,7 +4961,7 @@ function paintVisibleLodShapes(ctx, editor, camera, dpr, shapes, frame, paintBou
|
|
|
4926
4961
|
paintSnapshot(ctx, camera, dpr, matrix, mesh, snapshot, padPx);
|
|
4927
4962
|
if (mode !== "dom") continue;
|
|
4928
4963
|
}
|
|
4929
|
-
if (mode !== "canvas"
|
|
4964
|
+
if (mode !== "canvas") continue;
|
|
4930
4965
|
paintShape(ctx, camera, dpr, matrix, mesh, padPx);
|
|
4931
4966
|
}
|
|
4932
4967
|
}
|
|
@@ -4986,7 +5021,7 @@ function captureDueSnapshots(editor) {
|
|
|
4986
5021
|
if (!bounds || !frame.expanded.collides(bounds)) continue;
|
|
4987
5022
|
const screenMax = Math.max(bounds.w, bounds.h) * frame.zoom;
|
|
4988
5023
|
if (screenMax < 8 || screenMax > below * 1.35) continue;
|
|
4989
|
-
if (lodSnapshotCovers(shape
|
|
5024
|
+
if (lodSnapshotCovers(shape)) continue;
|
|
4990
5025
|
if (captured >= CAPTURES_PER_PASS) {
|
|
4991
5026
|
deferred = true;
|
|
4992
5027
|
break;
|
|
@@ -4997,12 +5032,12 @@ function captureDueSnapshots(editor) {
|
|
|
4997
5032
|
noteSnapshotMiss(shape);
|
|
4998
5033
|
continue;
|
|
4999
5034
|
}
|
|
5000
|
-
storeLodSnapshot(shape, bitmap
|
|
5001
|
-
|
|
5002
|
-
|
|
5035
|
+
if (storeLodSnapshot(shape, bitmap)) {
|
|
5036
|
+
captured += 1;
|
|
5037
|
+
changed = true;
|
|
5038
|
+
}
|
|
5003
5039
|
}
|
|
5004
|
-
if (changed)
|
|
5005
|
-
if (deferred) scheduleLodSnapshotPass();
|
|
5040
|
+
if (changed || deferred) notifySnapshotEpoch();
|
|
5006
5041
|
}
|
|
5007
5042
|
function LodCanvas() {
|
|
5008
5043
|
const editor = useEditor();
|
|
@@ -26523,7 +26558,7 @@ function getFontsFromRichText(editor, richText, initialState2) {
|
|
|
26523
26558
|
// src/index.ts
|
|
26524
26559
|
registerDrawLibraryVersion(
|
|
26525
26560
|
"@ibodr/editor",
|
|
26526
|
-
"0.2.
|
|
26561
|
+
"0.2.17",
|
|
26527
26562
|
"esm"
|
|
26528
26563
|
);
|
|
26529
26564
|
/*!
|