@ibodr/editor 0.2.17 → 0.2.18
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 +101 -45
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.mjs
CHANGED
|
@@ -4476,8 +4476,8 @@ function getShapeRenderMode(input) {
|
|
|
4476
4476
|
if (screenMax >= LOD_KEEP_SCREEN_PX || textScreen >= LOD_KEEP_TEXT_PX) return "dom";
|
|
4477
4477
|
return "canvas";
|
|
4478
4478
|
}
|
|
4479
|
-
var SNAPSHOT_MAX_EDGE =
|
|
4480
|
-
var MAX_SNAPSHOTS =
|
|
4479
|
+
var SNAPSHOT_MAX_EDGE = 512;
|
|
4480
|
+
var MAX_SNAPSHOTS = 32;
|
|
4481
4481
|
var MAX_CAPTURE_ATTEMPTS = 8;
|
|
4482
4482
|
var snapshots = /* @__PURE__ */ new Map();
|
|
4483
4483
|
var attempts = /* @__PURE__ */ new WeakMap();
|
|
@@ -4908,8 +4908,16 @@ function paintLodLabel(ctx, mesh) {
|
|
|
4908
4908
|
}
|
|
4909
4909
|
ctx.restore();
|
|
4910
4910
|
}
|
|
4911
|
-
var LOD_OVERSCAN_SCREEN_PX = 192;
|
|
4912
4911
|
var LOD_BITMAP_MAX_PX = 8192;
|
|
4912
|
+
var isMemoryConstrained = (() => {
|
|
4913
|
+
if (typeof navigator === "undefined") return false;
|
|
4914
|
+
const ua = navigator.userAgent || "";
|
|
4915
|
+
const ios = /iPad|iPhone|iPod/.test(ua) || navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1;
|
|
4916
|
+
const memory = navigator.deviceMemory;
|
|
4917
|
+
return ios || typeof memory === "number" && memory <= 4;
|
|
4918
|
+
})();
|
|
4919
|
+
var LOD_OVERSCAN_SCREEN_PX = isMemoryConstrained ? 96 : 192;
|
|
4920
|
+
var LOD_BITMAP_MAX_AREA = isMemoryConstrained ? 8e6 : 24e6;
|
|
4913
4921
|
function lodBitmapCovers(bitmap, camera, viewport, dpr, shapes, frame, theme, colorMode) {
|
|
4914
4922
|
if (bitmap.zoom !== camera.z || bitmap.dpr !== dpr) return false;
|
|
4915
4923
|
if (bitmap.snapshotEpoch !== lodSnapshotEpoch.get()) return false;
|
|
@@ -4930,6 +4938,7 @@ function lodBitmapCovers(bitmap, camera, viewport, dpr, shapes, frame, theme, co
|
|
|
4930
4938
|
return covered.contains(viewport);
|
|
4931
4939
|
}
|
|
4932
4940
|
function blitLodBitmap(ctx, width, height, bitmap, camera) {
|
|
4941
|
+
if (!bitmap.canvas) return;
|
|
4933
4942
|
const z = camera.z || 1;
|
|
4934
4943
|
const padPx = bitmap.pad * z * bitmap.dpr;
|
|
4935
4944
|
ctx.globalAlpha = 1;
|
|
@@ -4941,13 +4950,16 @@ function blitLodBitmap(ctx, width, height, bitmap, camera) {
|
|
|
4941
4950
|
(camera.y - bitmap.cameraY) * z * bitmap.dpr - padPx
|
|
4942
4951
|
);
|
|
4943
4952
|
}
|
|
4944
|
-
function
|
|
4953
|
+
function collectLodPaintJobs(editor, camera, shapes, frame, paintBounds) {
|
|
4954
|
+
const jobs = [];
|
|
4955
|
+
if (frame.debug) return jobs;
|
|
4945
4956
|
for (const shape of shapes) {
|
|
4946
4957
|
if (editor.isShapeHidden(shape)) continue;
|
|
4947
4958
|
const style = lodStyleFor(editor, shape);
|
|
4948
4959
|
if (!style) continue;
|
|
4949
4960
|
const mode = ownRenderMode(editor, shape, frame, false);
|
|
4950
|
-
if (mode === "unmounted"
|
|
4961
|
+
if (mode === "unmounted") continue;
|
|
4962
|
+
if (mode === "dom" && !(style.snapshotBelowPx && style.snapshotBelowPx > 0)) continue;
|
|
4951
4963
|
if (mode === "canvas" && coveredByDomBackground(editor, shape, frame)) continue;
|
|
4952
4964
|
const mesh = meshFor(editor, shape, style);
|
|
4953
4965
|
if (!mesh) continue;
|
|
@@ -4957,12 +4969,17 @@ function paintVisibleLodShapes(ctx, editor, camera, dpr, shapes, frame, paintBou
|
|
|
4957
4969
|
const page = editor.getShapePageBounds(shape);
|
|
4958
4970
|
const screenMax = page ? Math.max(page.w, page.h) * (camera.z || 1) : 0;
|
|
4959
4971
|
const nearFreeze = (style.snapshotBelowPx ?? 0) > 0 && screenMax < (style.snapshotBelowPx ?? 0) * 1.35;
|
|
4960
|
-
|
|
4961
|
-
|
|
4962
|
-
|
|
4963
|
-
}
|
|
4964
|
-
|
|
4965
|
-
|
|
4972
|
+
const useSnapshot = Boolean(snapshot) && (mode === "canvas" || nearFreeze);
|
|
4973
|
+
const paintStandIn = mode === "canvas" && !useSnapshot;
|
|
4974
|
+
if (!useSnapshot && !paintStandIn) continue;
|
|
4975
|
+
jobs.push({ matrix, mesh, snapshot: useSnapshot ? snapshot : null, paintStandIn });
|
|
4976
|
+
}
|
|
4977
|
+
return jobs;
|
|
4978
|
+
}
|
|
4979
|
+
function paintLodJobs(ctx, camera, dpr, jobs, padPx) {
|
|
4980
|
+
for (const job of jobs) {
|
|
4981
|
+
if (job.snapshot) paintSnapshot(ctx, camera, dpr, job.matrix, job.mesh, job.snapshot, padPx);
|
|
4982
|
+
if (job.paintStandIn) paintShape(ctx, camera, dpr, job.matrix, job.mesh, padPx);
|
|
4966
4983
|
}
|
|
4967
4984
|
}
|
|
4968
4985
|
function useMountedRenderingShapes() {
|
|
@@ -5058,44 +5075,40 @@ function LodCanvas() {
|
|
|
5058
5075
|
const dpr = window.devicePixelRatio || 1;
|
|
5059
5076
|
const width = Math.max(1, Math.round((screen.w || canvas.clientWidth) * dpr));
|
|
5060
5077
|
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
5078
|
const ctx = canvas.getContext("2d");
|
|
5066
5079
|
if (!ctx) return;
|
|
5080
|
+
const sizeScreenCanvas = () => {
|
|
5081
|
+
if (canvas.width !== width || canvas.height !== height) {
|
|
5082
|
+
canvas.width = width;
|
|
5083
|
+
canvas.height = height;
|
|
5084
|
+
}
|
|
5085
|
+
};
|
|
5086
|
+
const releaseCanvases = (previous) => {
|
|
5087
|
+
if (previous?.canvas) {
|
|
5088
|
+
previous.canvas.width = 0;
|
|
5089
|
+
previous.canvas.height = 0;
|
|
5090
|
+
}
|
|
5091
|
+
if (canvas.width !== 1 || canvas.height !== 1) {
|
|
5092
|
+
canvas.width = 1;
|
|
5093
|
+
canvas.height = 1;
|
|
5094
|
+
}
|
|
5095
|
+
};
|
|
5067
5096
|
unsafe__withoutCapture(() => {
|
|
5068
5097
|
const cached = bitmapRef.current;
|
|
5069
5098
|
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;
|
|
5099
|
+
if (cached.canvas) {
|
|
5100
|
+
sizeScreenCanvas();
|
|
5101
|
+
blitLodBitmap(ctx, width, height, cached, camera);
|
|
5102
|
+
}
|
|
5077
5103
|
return;
|
|
5078
5104
|
}
|
|
5079
|
-
const
|
|
5105
|
+
const zoom = camera.z || 1;
|
|
5106
|
+
const pad = LOD_OVERSCAN_SCREEN_PX / zoom;
|
|
5080
5107
|
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 = {
|
|
5108
|
+
const jobs = collectLodPaintJobs(editor, camera, shapes, frame, paintBounds);
|
|
5109
|
+
if (jobs.length === 0) {
|
|
5110
|
+
releaseCanvases(cached);
|
|
5111
|
+
bitmapRef.current = frame.debug ? null : {
|
|
5099
5112
|
zoom: camera.z,
|
|
5100
5113
|
dpr,
|
|
5101
5114
|
cameraX: camera.x,
|
|
@@ -5108,12 +5121,55 @@ function LodCanvas() {
|
|
|
5108
5121
|
editingId: frame.editingId,
|
|
5109
5122
|
theme,
|
|
5110
5123
|
colorMode,
|
|
5111
|
-
canvas:
|
|
5124
|
+
canvas: null,
|
|
5112
5125
|
snapshotEpoch: lodSnapshotEpoch.get()
|
|
5113
5126
|
};
|
|
5114
|
-
|
|
5115
|
-
blitLodBitmap(ctx, width, height, bitmap, camera);
|
|
5127
|
+
return;
|
|
5116
5128
|
}
|
|
5129
|
+
sizeScreenCanvas();
|
|
5130
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
5131
|
+
ctx.clearRect(0, 0, width, height);
|
|
5132
|
+
const cacheW = Math.round((frame.viewport.w + pad * 2) * zoom * dpr);
|
|
5133
|
+
const cacheH = Math.round((frame.viewport.h + pad * 2) * zoom * dpr);
|
|
5134
|
+
const canCache = cacheW > 0 && cacheH > 0 && cacheW <= LOD_BITMAP_MAX_PX && cacheH <= LOD_BITMAP_MAX_PX && cacheW * cacheH <= LOD_BITMAP_MAX_AREA;
|
|
5135
|
+
if (!canCache) {
|
|
5136
|
+
if (cached?.canvas) {
|
|
5137
|
+
cached.canvas.width = 0;
|
|
5138
|
+
cached.canvas.height = 0;
|
|
5139
|
+
}
|
|
5140
|
+
bitmapRef.current = null;
|
|
5141
|
+
paintLodJobs(ctx, camera, dpr, jobs, 0);
|
|
5142
|
+
return;
|
|
5143
|
+
}
|
|
5144
|
+
const target = cached?.canvas ?? document.createElement("canvas");
|
|
5145
|
+
if (target.width !== cacheW || target.height !== cacheH) {
|
|
5146
|
+
target.width = cacheW;
|
|
5147
|
+
target.height = cacheH;
|
|
5148
|
+
}
|
|
5149
|
+
const paintCtx = target.getContext("2d");
|
|
5150
|
+
if (!paintCtx) return;
|
|
5151
|
+
paintCtx.globalAlpha = 1;
|
|
5152
|
+
paintCtx.setTransform(1, 0, 0, 1, 0, 0);
|
|
5153
|
+
paintCtx.clearRect(0, 0, cacheW, cacheH);
|
|
5154
|
+
paintLodJobs(paintCtx, camera, dpr, jobs, pad * zoom * dpr);
|
|
5155
|
+
const bitmap = {
|
|
5156
|
+
zoom: camera.z,
|
|
5157
|
+
dpr,
|
|
5158
|
+
cameraX: camera.x,
|
|
5159
|
+
cameraY: camera.y,
|
|
5160
|
+
pad,
|
|
5161
|
+
viewW: frame.viewport.w,
|
|
5162
|
+
viewH: frame.viewport.h,
|
|
5163
|
+
shapes,
|
|
5164
|
+
selectedIds: frame.selectedIds,
|
|
5165
|
+
editingId: frame.editingId,
|
|
5166
|
+
theme,
|
|
5167
|
+
colorMode,
|
|
5168
|
+
canvas: target,
|
|
5169
|
+
snapshotEpoch: lodSnapshotEpoch.get()
|
|
5170
|
+
};
|
|
5171
|
+
bitmapRef.current = bitmap;
|
|
5172
|
+
blitLodBitmap(ctx, width, height, bitmap, camera);
|
|
5117
5173
|
});
|
|
5118
5174
|
},
|
|
5119
5175
|
[editor]
|
|
@@ -26558,7 +26614,7 @@ function getFontsFromRichText(editor, richText, initialState2) {
|
|
|
26558
26614
|
// src/index.ts
|
|
26559
26615
|
registerDrawLibraryVersion(
|
|
26560
26616
|
"@ibodr/editor",
|
|
26561
|
-
"0.2.
|
|
26617
|
+
"0.2.18",
|
|
26562
26618
|
"esm"
|
|
26563
26619
|
);
|
|
26564
26620
|
/*!
|