@ibodr/editor 0.2.17 → 0.2.19
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 +192 -103
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.mjs
CHANGED
|
@@ -4458,6 +4458,72 @@ function drawGeometryStroke(ctx, geometry) {
|
|
|
4458
4458
|
ctx.stroke();
|
|
4459
4459
|
}
|
|
4460
4460
|
|
|
4461
|
+
// src/lib/editor/lod/lodPaintCache.ts
|
|
4462
|
+
var labels = /* @__PURE__ */ new WeakMap();
|
|
4463
|
+
function getLodLabelLayout(ctx, mesh) {
|
|
4464
|
+
if (labels.has(mesh)) return labels.get(mesh);
|
|
4465
|
+
const layout = measureLabel(ctx, mesh);
|
|
4466
|
+
labels.set(mesh, layout);
|
|
4467
|
+
return layout;
|
|
4468
|
+
}
|
|
4469
|
+
function measureLabel(ctx, mesh) {
|
|
4470
|
+
const text = mesh.label?.trim();
|
|
4471
|
+
if (!text || mesh.w < 4 || mesh.h < 4) return null;
|
|
4472
|
+
const pad = Math.min(mesh.w, mesh.h) * 0.08;
|
|
4473
|
+
const maxWidth = mesh.w - pad * 2, innerH = mesh.h - pad * 2;
|
|
4474
|
+
if (maxWidth < 4 || innerH < 4) return null;
|
|
4475
|
+
const preferred = mesh.labelSize > 0 ? mesh.labelSize : innerH * 0.4;
|
|
4476
|
+
const size = Math.min(Math.max(preferred, innerH * 0.22), innerH * 0.82);
|
|
4477
|
+
if (size < 1) return null;
|
|
4478
|
+
const font = `${size}px sans-serif`;
|
|
4479
|
+
const previousFont = ctx.font;
|
|
4480
|
+
ctx.font = font;
|
|
4481
|
+
const lines = [];
|
|
4482
|
+
let line = "";
|
|
4483
|
+
try {
|
|
4484
|
+
for (const word of text.split(/\s+/)) {
|
|
4485
|
+
const next = line ? `${line} ${word}` : word;
|
|
4486
|
+
if (line && ctx.measureText(next).width > maxWidth) {
|
|
4487
|
+
lines.push(line);
|
|
4488
|
+
line = word;
|
|
4489
|
+
} else line = next;
|
|
4490
|
+
}
|
|
4491
|
+
} finally {
|
|
4492
|
+
ctx.font = previousFont;
|
|
4493
|
+
}
|
|
4494
|
+
if (line) lines.push(line);
|
|
4495
|
+
const lineHeight = size * 1.15;
|
|
4496
|
+
const maxLines = Math.max(1, Math.floor(innerH / lineHeight));
|
|
4497
|
+
const fits = lines.length <= maxLines;
|
|
4498
|
+
const visible = fits ? lines : lines.slice(0, maxLines);
|
|
4499
|
+
const blockH = visible.length * lineHeight;
|
|
4500
|
+
return {
|
|
4501
|
+
font,
|
|
4502
|
+
maxWidth,
|
|
4503
|
+
lineHeight,
|
|
4504
|
+
lines: visible,
|
|
4505
|
+
x: mesh.x + mesh.w / 2,
|
|
4506
|
+
y: fits ? mesh.y + mesh.h / 2 - blockH / 2 + lineHeight / 2 : mesh.y + pad + lineHeight / 2
|
|
4507
|
+
};
|
|
4508
|
+
}
|
|
4509
|
+
var boundsCache = /* @__PURE__ */ new WeakMap();
|
|
4510
|
+
function getTransformedLodBounds(matrix, mesh) {
|
|
4511
|
+
const { a, b, c, d, e, f } = matrix;
|
|
4512
|
+
const cached = boundsCache.get(mesh);
|
|
4513
|
+
if (cached && cached.a === a && cached.b === b && cached.c === c && cached.d === d && cached.e === e && cached.f === f)
|
|
4514
|
+
return cached.bounds;
|
|
4515
|
+
const x0 = a * mesh.x + c * mesh.y + e, y0 = b * mesh.x + d * mesh.y + f;
|
|
4516
|
+
const dx = a * mesh.w, dy = b * mesh.w, ex = c * mesh.h, ey = d * mesh.h;
|
|
4517
|
+
const bounds = new Box(
|
|
4518
|
+
x0 + Math.min(0, dx) + Math.min(0, ex),
|
|
4519
|
+
y0 + Math.min(0, dy) + Math.min(0, ey),
|
|
4520
|
+
Math.abs(dx) + Math.abs(ex),
|
|
4521
|
+
Math.abs(dy) + Math.abs(ey)
|
|
4522
|
+
);
|
|
4523
|
+
boundsCache.set(mesh, { a, b, c, d, e, f, bounds });
|
|
4524
|
+
return bounds;
|
|
4525
|
+
}
|
|
4526
|
+
|
|
4461
4527
|
// src/lib/editor/lod/shapeRenderMode.ts
|
|
4462
4528
|
var LOD_KEEP_SCREEN_PX = 36;
|
|
4463
4529
|
var LOD_KEEP_TEXT_PX = 7;
|
|
@@ -4476,8 +4542,8 @@ function getShapeRenderMode(input) {
|
|
|
4476
4542
|
if (screenMax >= LOD_KEEP_SCREEN_PX || textScreen >= LOD_KEEP_TEXT_PX) return "dom";
|
|
4477
4543
|
return "canvas";
|
|
4478
4544
|
}
|
|
4479
|
-
var SNAPSHOT_MAX_EDGE =
|
|
4480
|
-
var MAX_SNAPSHOTS =
|
|
4545
|
+
var SNAPSHOT_MAX_EDGE = 512;
|
|
4546
|
+
var MAX_SNAPSHOTS = 32;
|
|
4481
4547
|
var MAX_CAPTURE_ATTEMPTS = 8;
|
|
4482
4548
|
var snapshots = /* @__PURE__ */ new Map();
|
|
4483
4549
|
var attempts = /* @__PURE__ */ new WeakMap();
|
|
@@ -4611,9 +4677,8 @@ var MAX_LOD_POINTS = 48;
|
|
|
4611
4677
|
var meshCache = /* @__PURE__ */ new WeakMap();
|
|
4612
4678
|
var styleCache = /* @__PURE__ */ new WeakMap();
|
|
4613
4679
|
var retainedOutside = /* @__PURE__ */ new WeakMap();
|
|
4614
|
-
function lodStyleFor(editor, shape) {
|
|
4615
|
-
const theme =
|
|
4616
|
-
const colorMode = editor.getColorMode();
|
|
4680
|
+
function lodStyleFor(editor, shape, frame) {
|
|
4681
|
+
const { theme, colorMode } = frame;
|
|
4617
4682
|
const cached = styleCache.get(shape);
|
|
4618
4683
|
if (cached && cached.theme === theme && cached.colorMode === colorMode) return cached.style;
|
|
4619
4684
|
let style = null;
|
|
@@ -4671,24 +4736,13 @@ function meshFor(editor, shape, style) {
|
|
|
4671
4736
|
meshCache.set(shape, { style, mesh });
|
|
4672
4737
|
return mesh;
|
|
4673
4738
|
}
|
|
4674
|
-
function transformedBounds(matrix, mesh) {
|
|
4675
|
-
const x0 = mesh.x;
|
|
4676
|
-
const y0 = mesh.y;
|
|
4677
|
-
const x1 = mesh.x + mesh.w;
|
|
4678
|
-
const y1 = mesh.y + mesh.h;
|
|
4679
|
-
return Box.FromPoints([
|
|
4680
|
-
matrix.applyToPoint({ x: x0, y: y0 }),
|
|
4681
|
-
matrix.applyToPoint({ x: x1, y: y0 }),
|
|
4682
|
-
matrix.applyToPoint({ x: x1, y: y1 }),
|
|
4683
|
-
matrix.applyToPoint({ x: x0, y: y1 })
|
|
4684
|
-
]);
|
|
4685
|
-
}
|
|
4686
4739
|
function isInteractive(editor, shape, selected, editingId) {
|
|
4740
|
+
if (selected.size === 0 && editingId === null) return false;
|
|
4687
4741
|
let current = shape;
|
|
4688
4742
|
for (let depth = 0; depth < 32 && current; depth++) {
|
|
4689
4743
|
if (current.id === editingId || selected.has(current.id)) return true;
|
|
4690
4744
|
const parentId = current.parentId;
|
|
4691
|
-
if (!editor.store.has(parentId)) return false;
|
|
4745
|
+
if (!parentId.startsWith("shape:") || !editor.store.has(parentId)) return false;
|
|
4692
4746
|
const parent = editor.store.unsafeGetWithoutCapture(parentId);
|
|
4693
4747
|
if (!parent || parent.typeName !== "shape") return false;
|
|
4694
4748
|
current = parent;
|
|
@@ -4701,6 +4755,8 @@ function readFrame(editor) {
|
|
|
4701
4755
|
const selectedIds = editor.getSelectedShapeIds();
|
|
4702
4756
|
return {
|
|
4703
4757
|
zoom: editor.getZoomLevel(),
|
|
4758
|
+
theme: editor.getCurrentTheme(),
|
|
4759
|
+
colorMode: editor.getColorMode(),
|
|
4704
4760
|
lodZoom: editor.options.lodZoom,
|
|
4705
4761
|
debug: debugFlags.debugSvg.get() && editor.getInstanceState().isDebugMode,
|
|
4706
4762
|
moving: editor.getCameraState() === "moving",
|
|
@@ -4716,7 +4772,7 @@ function outsideSet(editor, frame, shapes) {
|
|
|
4716
4772
|
if (!frame.debug) {
|
|
4717
4773
|
for (const shape of shapes) {
|
|
4718
4774
|
if (editor.isShapeHidden(shape)) continue;
|
|
4719
|
-
const style = lodStyleFor(editor, shape);
|
|
4775
|
+
const style = lodStyleFor(editor, shape, frame);
|
|
4720
4776
|
if (!style) continue;
|
|
4721
4777
|
if (style.unmountWhenCulled) {
|
|
4722
4778
|
const bounds = editor.getShapePageBounds(shape);
|
|
@@ -4726,7 +4782,7 @@ function outsideSet(editor, frame, shapes) {
|
|
|
4726
4782
|
const mesh = meshFor(editor, shape, style);
|
|
4727
4783
|
if (!mesh) continue;
|
|
4728
4784
|
const matrix = editor.getShapePageTransform(shape);
|
|
4729
|
-
if (!frame.expanded.collides(
|
|
4785
|
+
if (!frame.expanded.collides(getTransformedLodBounds(matrix, mesh))) live.add(shape.id);
|
|
4730
4786
|
}
|
|
4731
4787
|
}
|
|
4732
4788
|
if (!frame.moving) {
|
|
@@ -4745,7 +4801,7 @@ function outsideSet(editor, frame, shapes) {
|
|
|
4745
4801
|
}
|
|
4746
4802
|
function ownRenderMode(editor, shape, frame, outsideViewport) {
|
|
4747
4803
|
if (frame.debug || editor.isShapeHidden(shape)) return "dom";
|
|
4748
|
-
const style = lodStyleFor(editor, shape);
|
|
4804
|
+
const style = lodStyleFor(editor, shape, frame);
|
|
4749
4805
|
const mesh = style && !style.unmountWhenCulled ? meshFor(editor, shape, style) : null;
|
|
4750
4806
|
const pageBounds = editor.getShapePageBounds(shape);
|
|
4751
4807
|
const pageWidth = pageBounds?.w ?? mesh?.w ?? 0;
|
|
@@ -4764,7 +4820,7 @@ function ownRenderMode(editor, shape, frame, outsideViewport) {
|
|
|
4764
4820
|
pageHeight,
|
|
4765
4821
|
labelSize: style?.labelSize ?? 0,
|
|
4766
4822
|
snapshotBelowPx: style?.snapshotBelowPx,
|
|
4767
|
-
hasSnapshot: snapshotCoversShape(shape)
|
|
4823
|
+
hasSnapshot: (style?.snapshotBelowPx ?? 0) > 0 && snapshotCoversShape(shape)
|
|
4768
4824
|
});
|
|
4769
4825
|
}
|
|
4770
4826
|
function snapshotCoversShape(shape, screenMax) {
|
|
@@ -4773,7 +4829,7 @@ function snapshotCoversShape(shape, screenMax) {
|
|
|
4773
4829
|
function coveredByDomBackground(editor, shape, frame) {
|
|
4774
4830
|
let parentId = shape.parentId;
|
|
4775
4831
|
for (let depth = 0; depth < 32; depth++) {
|
|
4776
|
-
if (!editor.store.has(parentId)) return false;
|
|
4832
|
+
if (!parentId.startsWith("shape:") || !editor.store.has(parentId)) return false;
|
|
4777
4833
|
const parent = editor.store.unsafeGetWithoutCapture(parentId);
|
|
4778
4834
|
if (!parent || parent.typeName !== "shape") return false;
|
|
4779
4835
|
const parentShape = parent;
|
|
@@ -4865,51 +4921,33 @@ function paintSnapshot(ctx, camera, dpr, matrix, mesh, bitmap, padPx = 0) {
|
|
|
4865
4921
|
ctx.restore();
|
|
4866
4922
|
}
|
|
4867
4923
|
function paintLodLabel(ctx, mesh) {
|
|
4868
|
-
const
|
|
4869
|
-
if (!
|
|
4870
|
-
const pad = Math.min(mesh.w, mesh.h) * 0.08;
|
|
4871
|
-
const maxWidth = mesh.w - pad * 2;
|
|
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;
|
|
4924
|
+
const layout = getLodLabelLayout(ctx, mesh);
|
|
4925
|
+
if (!layout) return;
|
|
4877
4926
|
ctx.save();
|
|
4878
4927
|
ctx.beginPath();
|
|
4879
4928
|
ctx.rect(mesh.x, mesh.y, mesh.w, mesh.h);
|
|
4880
4929
|
ctx.clip();
|
|
4881
4930
|
ctx.fillStyle = mesh.labelColor || "#1d1d1d";
|
|
4882
|
-
ctx.font =
|
|
4931
|
+
ctx.font = layout.font;
|
|
4883
4932
|
ctx.textAlign = "center";
|
|
4884
4933
|
ctx.textBaseline = "middle";
|
|
4885
|
-
|
|
4886
|
-
const lines
|
|
4887
|
-
|
|
4888
|
-
|
|
4889
|
-
const next = line ? `${line} ${word}` : word;
|
|
4890
|
-
if (line && ctx.measureText(next).width > maxWidth) {
|
|
4891
|
-
lines.push(line);
|
|
4892
|
-
line = word;
|
|
4893
|
-
} else {
|
|
4894
|
-
line = next;
|
|
4895
|
-
}
|
|
4896
|
-
}
|
|
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;
|
|
4934
|
+
let y = layout.y;
|
|
4935
|
+
for (const row of layout.lines) {
|
|
4936
|
+
ctx.fillText(row, layout.x, y, layout.maxWidth);
|
|
4937
|
+
y += layout.lineHeight;
|
|
4908
4938
|
}
|
|
4909
4939
|
ctx.restore();
|
|
4910
4940
|
}
|
|
4911
|
-
var LOD_OVERSCAN_SCREEN_PX = 192;
|
|
4912
4941
|
var LOD_BITMAP_MAX_PX = 8192;
|
|
4942
|
+
var isMemoryConstrained = (() => {
|
|
4943
|
+
if (typeof navigator === "undefined") return false;
|
|
4944
|
+
const ua = navigator.userAgent || "";
|
|
4945
|
+
const ios = /iPad|iPhone|iPod/.test(ua) || navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1;
|
|
4946
|
+
const memory = navigator.deviceMemory;
|
|
4947
|
+
return ios || typeof memory === "number" && memory <= 4;
|
|
4948
|
+
})();
|
|
4949
|
+
var LOD_OVERSCAN_SCREEN_PX = isMemoryConstrained ? 96 : 192;
|
|
4950
|
+
var LOD_BITMAP_MAX_AREA = isMemoryConstrained ? 8e6 : 24e6;
|
|
4913
4951
|
function lodBitmapCovers(bitmap, camera, viewport, dpr, shapes, frame, theme, colorMode) {
|
|
4914
4952
|
if (bitmap.zoom !== camera.z || bitmap.dpr !== dpr) return false;
|
|
4915
4953
|
if (bitmap.snapshotEpoch !== lodSnapshotEpoch.get()) return false;
|
|
@@ -4930,6 +4968,7 @@ function lodBitmapCovers(bitmap, camera, viewport, dpr, shapes, frame, theme, co
|
|
|
4930
4968
|
return covered.contains(viewport);
|
|
4931
4969
|
}
|
|
4932
4970
|
function blitLodBitmap(ctx, width, height, bitmap, camera) {
|
|
4971
|
+
if (!bitmap.canvas) return;
|
|
4933
4972
|
const z = camera.z || 1;
|
|
4934
4973
|
const padPx = bitmap.pad * z * bitmap.dpr;
|
|
4935
4974
|
ctx.globalAlpha = 1;
|
|
@@ -4941,28 +4980,36 @@ function blitLodBitmap(ctx, width, height, bitmap, camera) {
|
|
|
4941
4980
|
(camera.y - bitmap.cameraY) * z * bitmap.dpr - padPx
|
|
4942
4981
|
);
|
|
4943
4982
|
}
|
|
4944
|
-
function
|
|
4983
|
+
function collectLodPaintJobs(editor, camera, shapes, frame, paintBounds) {
|
|
4984
|
+
const jobs = [];
|
|
4985
|
+
if (frame.debug) return jobs;
|
|
4945
4986
|
for (const shape of shapes) {
|
|
4946
4987
|
if (editor.isShapeHidden(shape)) continue;
|
|
4947
|
-
const style = lodStyleFor(editor, shape);
|
|
4988
|
+
const style = lodStyleFor(editor, shape, frame);
|
|
4948
4989
|
if (!style) continue;
|
|
4949
4990
|
const mode = ownRenderMode(editor, shape, frame, false);
|
|
4950
|
-
if (mode === "unmounted"
|
|
4991
|
+
if (mode === "unmounted") continue;
|
|
4992
|
+
if (mode === "dom" && !(style.snapshotBelowPx && style.snapshotBelowPx > 0)) continue;
|
|
4951
4993
|
if (mode === "canvas" && coveredByDomBackground(editor, shape, frame)) continue;
|
|
4952
4994
|
const mesh = meshFor(editor, shape, style);
|
|
4953
4995
|
if (!mesh) continue;
|
|
4954
4996
|
const matrix = editor.getShapePageTransform(shape);
|
|
4955
|
-
if (!paintBounds.collides(
|
|
4997
|
+
if (!paintBounds.collides(getTransformedLodBounds(matrix, mesh))) continue;
|
|
4956
4998
|
const snapshot = getLodSnapshot(shape);
|
|
4957
|
-
const page = editor.getShapePageBounds(shape);
|
|
4999
|
+
const page = (style.snapshotBelowPx ?? 0) > 0 ? editor.getShapePageBounds(shape) : void 0;
|
|
4958
5000
|
const screenMax = page ? Math.max(page.w, page.h) * (camera.z || 1) : 0;
|
|
4959
5001
|
const nearFreeze = (style.snapshotBelowPx ?? 0) > 0 && screenMax < (style.snapshotBelowPx ?? 0) * 1.35;
|
|
4960
|
-
|
|
4961
|
-
|
|
4962
|
-
|
|
4963
|
-
}
|
|
4964
|
-
|
|
4965
|
-
|
|
5002
|
+
const useSnapshot = Boolean(snapshot) && (mode === "canvas" || nearFreeze);
|
|
5003
|
+
const paintStandIn = mode === "canvas" && !useSnapshot;
|
|
5004
|
+
if (!useSnapshot && !paintStandIn) continue;
|
|
5005
|
+
jobs.push({ matrix, mesh, snapshot: useSnapshot ? snapshot : null, paintStandIn });
|
|
5006
|
+
}
|
|
5007
|
+
return jobs;
|
|
5008
|
+
}
|
|
5009
|
+
function paintLodJobs(ctx, camera, dpr, jobs, padPx) {
|
|
5010
|
+
for (const job of jobs) {
|
|
5011
|
+
if (job.snapshot) paintSnapshot(ctx, camera, dpr, job.matrix, job.mesh, job.snapshot, padPx);
|
|
5012
|
+
if (job.paintStandIn) paintShape(ctx, camera, dpr, job.matrix, job.mesh, padPx);
|
|
4966
5013
|
}
|
|
4967
5014
|
}
|
|
4968
5015
|
function useMountedRenderingShapes() {
|
|
@@ -5013,7 +5060,7 @@ function captureDueSnapshots(editor) {
|
|
|
5013
5060
|
let changed = false;
|
|
5014
5061
|
for (const shape of editor.getCurrentPageShapesSorted()) {
|
|
5015
5062
|
if (editor.isShapeHidden(shape)) continue;
|
|
5016
|
-
const style = lodStyleFor(editor, shape);
|
|
5063
|
+
const style = lodStyleFor(editor, shape, frame);
|
|
5017
5064
|
const below = style?.snapshotBelowPx ?? 0;
|
|
5018
5065
|
if (below <= 0) continue;
|
|
5019
5066
|
if (isInteractive(editor, shape, frame.selected, frame.editingId)) continue;
|
|
@@ -5043,6 +5090,7 @@ function LodCanvas() {
|
|
|
5043
5090
|
const editor = useEditor();
|
|
5044
5091
|
const canvasRef = useRef(null);
|
|
5045
5092
|
const bitmapRef = useRef(null);
|
|
5093
|
+
const lastPaintZoom = useRef(null);
|
|
5046
5094
|
useQuickReactor(
|
|
5047
5095
|
"lod canvas",
|
|
5048
5096
|
() => {
|
|
@@ -5050,6 +5098,8 @@ function LodCanvas() {
|
|
|
5050
5098
|
const canvas = canvasRef.current;
|
|
5051
5099
|
if (!canvas) return;
|
|
5052
5100
|
const camera = editor.getCamera();
|
|
5101
|
+
const zoomChanged = lastPaintZoom.current !== null && lastPaintZoom.current !== camera.z;
|
|
5102
|
+
lastPaintZoom.current = camera.z;
|
|
5053
5103
|
const screen = editor.getViewportScreenBounds();
|
|
5054
5104
|
const shapes = editor.getCurrentPageShapesSorted();
|
|
5055
5105
|
const theme = editor.getCurrentTheme();
|
|
@@ -5058,44 +5108,40 @@ function LodCanvas() {
|
|
|
5058
5108
|
const dpr = window.devicePixelRatio || 1;
|
|
5059
5109
|
const width = Math.max(1, Math.round((screen.w || canvas.clientWidth) * dpr));
|
|
5060
5110
|
const height = Math.max(1, Math.round((screen.h || canvas.clientHeight) * dpr));
|
|
5061
|
-
if (canvas.width !== width || canvas.height !== height) {
|
|
5062
|
-
canvas.width = width;
|
|
5063
|
-
canvas.height = height;
|
|
5064
|
-
}
|
|
5065
5111
|
const ctx = canvas.getContext("2d");
|
|
5066
5112
|
if (!ctx) return;
|
|
5113
|
+
const sizeScreenCanvas = () => {
|
|
5114
|
+
if (canvas.width !== width || canvas.height !== height) {
|
|
5115
|
+
canvas.width = width;
|
|
5116
|
+
canvas.height = height;
|
|
5117
|
+
}
|
|
5118
|
+
};
|
|
5119
|
+
const releaseCanvases = (previous) => {
|
|
5120
|
+
if (previous?.canvas) {
|
|
5121
|
+
previous.canvas.width = 0;
|
|
5122
|
+
previous.canvas.height = 0;
|
|
5123
|
+
}
|
|
5124
|
+
if (canvas.width !== 1 || canvas.height !== 1) {
|
|
5125
|
+
canvas.width = 1;
|
|
5126
|
+
canvas.height = 1;
|
|
5127
|
+
}
|
|
5128
|
+
};
|
|
5067
5129
|
unsafe__withoutCapture(() => {
|
|
5068
5130
|
const cached = bitmapRef.current;
|
|
5069
5131
|
if (!frame.debug && cached && lodBitmapCovers(cached, camera, frame.viewport, dpr, shapes, frame, theme, colorMode)) {
|
|
5070
|
-
|
|
5071
|
-
|
|
5072
|
-
|
|
5073
|
-
|
|
5074
|
-
ctx.clearRect(0, 0, width, height);
|
|
5075
|
-
if (frame.debug) {
|
|
5076
|
-
bitmapRef.current = null;
|
|
5132
|
+
if (cached.canvas) {
|
|
5133
|
+
sizeScreenCanvas();
|
|
5134
|
+
blitLodBitmap(ctx, width, height, cached, camera);
|
|
5135
|
+
}
|
|
5077
5136
|
return;
|
|
5078
5137
|
}
|
|
5079
|
-
const
|
|
5138
|
+
const zoom = camera.z || 1;
|
|
5139
|
+
const pad = LOD_OVERSCAN_SCREEN_PX / zoom;
|
|
5080
5140
|
const paintBounds = frame.viewport.clone().expandBy(pad);
|
|
5081
|
-
const
|
|
5082
|
-
|
|
5083
|
-
|
|
5084
|
-
|
|
5085
|
-
if (target && (target.width !== cacheW || target.height !== cacheH)) {
|
|
5086
|
-
target.width = cacheW;
|
|
5087
|
-
target.height = cacheH;
|
|
5088
|
-
}
|
|
5089
|
-
const padPx = canCache ? pad * (camera.z || 1) * dpr : 0;
|
|
5090
|
-
const paintCtx = target?.getContext("2d") ?? ctx;
|
|
5091
|
-
if (target) {
|
|
5092
|
-
paintCtx.globalAlpha = 1;
|
|
5093
|
-
paintCtx.setTransform(1, 0, 0, 1, 0, 0);
|
|
5094
|
-
paintCtx.clearRect(0, 0, cacheW, cacheH);
|
|
5095
|
-
}
|
|
5096
|
-
paintVisibleLodShapes(paintCtx, editor, camera, dpr, shapes, frame, paintBounds, padPx);
|
|
5097
|
-
if (target) {
|
|
5098
|
-
const bitmap = {
|
|
5141
|
+
const jobs = collectLodPaintJobs(editor, camera, shapes, frame, paintBounds);
|
|
5142
|
+
if (jobs.length === 0) {
|
|
5143
|
+
releaseCanvases(cached);
|
|
5144
|
+
bitmapRef.current = frame.debug ? null : {
|
|
5099
5145
|
zoom: camera.z,
|
|
5100
5146
|
dpr,
|
|
5101
5147
|
cameraX: camera.x,
|
|
@@ -5108,12 +5154,55 @@ function LodCanvas() {
|
|
|
5108
5154
|
editingId: frame.editingId,
|
|
5109
5155
|
theme,
|
|
5110
5156
|
colorMode,
|
|
5111
|
-
canvas:
|
|
5157
|
+
canvas: null,
|
|
5112
5158
|
snapshotEpoch: lodSnapshotEpoch.get()
|
|
5113
5159
|
};
|
|
5114
|
-
|
|
5115
|
-
blitLodBitmap(ctx, width, height, bitmap, camera);
|
|
5160
|
+
return;
|
|
5116
5161
|
}
|
|
5162
|
+
sizeScreenCanvas();
|
|
5163
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
5164
|
+
ctx.clearRect(0, 0, width, height);
|
|
5165
|
+
const cacheW = Math.round((frame.viewport.w + pad * 2) * zoom * dpr);
|
|
5166
|
+
const cacheH = Math.round((frame.viewport.h + pad * 2) * zoom * dpr);
|
|
5167
|
+
const canCache = !zoomChanged && cacheW > 0 && cacheH > 0 && cacheW <= LOD_BITMAP_MAX_PX && cacheH <= LOD_BITMAP_MAX_PX && cacheW * cacheH <= LOD_BITMAP_MAX_AREA;
|
|
5168
|
+
if (!canCache) {
|
|
5169
|
+
if (cached?.canvas) {
|
|
5170
|
+
cached.canvas.width = 0;
|
|
5171
|
+
cached.canvas.height = 0;
|
|
5172
|
+
}
|
|
5173
|
+
bitmapRef.current = null;
|
|
5174
|
+
paintLodJobs(ctx, camera, dpr, jobs, 0);
|
|
5175
|
+
return;
|
|
5176
|
+
}
|
|
5177
|
+
const target = cached?.canvas ?? document.createElement("canvas");
|
|
5178
|
+
if (target.width !== cacheW || target.height !== cacheH) {
|
|
5179
|
+
target.width = cacheW;
|
|
5180
|
+
target.height = cacheH;
|
|
5181
|
+
}
|
|
5182
|
+
const paintCtx = target.getContext("2d");
|
|
5183
|
+
if (!paintCtx) return;
|
|
5184
|
+
paintCtx.globalAlpha = 1;
|
|
5185
|
+
paintCtx.setTransform(1, 0, 0, 1, 0, 0);
|
|
5186
|
+
paintCtx.clearRect(0, 0, cacheW, cacheH);
|
|
5187
|
+
paintLodJobs(paintCtx, camera, dpr, jobs, pad * zoom * dpr);
|
|
5188
|
+
const bitmap = {
|
|
5189
|
+
zoom: camera.z,
|
|
5190
|
+
dpr,
|
|
5191
|
+
cameraX: camera.x,
|
|
5192
|
+
cameraY: camera.y,
|
|
5193
|
+
pad,
|
|
5194
|
+
viewW: frame.viewport.w,
|
|
5195
|
+
viewH: frame.viewport.h,
|
|
5196
|
+
shapes,
|
|
5197
|
+
selectedIds: frame.selectedIds,
|
|
5198
|
+
editingId: frame.editingId,
|
|
5199
|
+
theme,
|
|
5200
|
+
colorMode,
|
|
5201
|
+
canvas: target,
|
|
5202
|
+
snapshotEpoch: lodSnapshotEpoch.get()
|
|
5203
|
+
};
|
|
5204
|
+
bitmapRef.current = bitmap;
|
|
5205
|
+
blitLodBitmap(ctx, width, height, bitmap, camera);
|
|
5117
5206
|
});
|
|
5118
5207
|
},
|
|
5119
5208
|
[editor]
|
|
@@ -26558,7 +26647,7 @@ function getFontsFromRichText(editor, richText, initialState2) {
|
|
|
26558
26647
|
// src/index.ts
|
|
26559
26648
|
registerDrawLibraryVersion(
|
|
26560
26649
|
"@ibodr/editor",
|
|
26561
|
-
"0.2.
|
|
26650
|
+
"0.2.19",
|
|
26562
26651
|
"esm"
|
|
26563
26652
|
);
|
|
26564
26653
|
/*!
|