@ibodr/editor 0.2.9 → 0.2.10
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.d.ts +6 -2
- package/dist/index.mjs +71 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
|
@@ -2283,6 +2283,10 @@ interface DrLodStyle {
|
|
|
2283
2283
|
strokeWidth: number;
|
|
2284
2284
|
/** Multiplied by the shape's own opacity. Defaults to 1. */
|
|
2285
2285
|
opacity?: number;
|
|
2286
|
+
/** Plain label drawn inside the stand-in, in local pixels. */
|
|
2287
|
+
label?: string | null;
|
|
2288
|
+
labelColor?: string | null;
|
|
2289
|
+
labelSize?: number;
|
|
2286
2290
|
/**
|
|
2287
2291
|
* Unmount the shape when it is far outside the viewport, but keep the real DOM
|
|
2288
2292
|
* whenever it is on screen. Used for images so a pan back does not replace the
|
|
@@ -3065,7 +3069,7 @@ interface DrawOptions {
|
|
|
3065
3069
|
/**
|
|
3066
3070
|
* Zoom level below which shapes that implement {@link ShapeUtil.getLodStyle} are painted into
|
|
3067
3071
|
* one canvas instead of a DOM node each. Shapes whose on-screen size is still large stay in
|
|
3068
|
-
* the DOM. Defaults to 0.
|
|
3072
|
+
* the DOM. Defaults to 0.35 so a normal working zoom keeps real text and strokes.
|
|
3069
3073
|
*/
|
|
3070
3074
|
readonly lodZoom: number;
|
|
3071
3075
|
/**
|
|
@@ -3267,7 +3271,7 @@ declare const defaultDrawOptions: {
|
|
|
3267
3271
|
readonly nonce: undefined;
|
|
3268
3272
|
readonly debouncedZoom: true;
|
|
3269
3273
|
readonly debouncedZoomThreshold: 500;
|
|
3270
|
-
readonly lodZoom: 0.
|
|
3274
|
+
readonly lodZoom: 0.35;
|
|
3271
3275
|
readonly spacebarPanning: true;
|
|
3272
3276
|
readonly rightClickPanning: true;
|
|
3273
3277
|
readonly zoomToFitPadding: 128;
|
package/dist/index.mjs
CHANGED
|
@@ -4459,7 +4459,7 @@ function drawGeometryStroke(ctx, geometry) {
|
|
|
4459
4459
|
}
|
|
4460
4460
|
|
|
4461
4461
|
// src/lib/editor/lod/shapeRenderMode.ts
|
|
4462
|
-
var LOD_SMALL_SCREEN_PX =
|
|
4462
|
+
var LOD_SMALL_SCREEN_PX = 28;
|
|
4463
4463
|
var LOD_CULL_MARGIN = 0.75;
|
|
4464
4464
|
function getShapeRenderMode(input) {
|
|
4465
4465
|
if (!input.hasLodStyle || input.interactive) return "dom";
|
|
@@ -4522,7 +4522,10 @@ function meshFor(editor, shape, style) {
|
|
|
4522
4522
|
w: bounds.w,
|
|
4523
4523
|
h: bounds.h,
|
|
4524
4524
|
points: fillOnly || !needsPath ? null : decimate(geometry.vertices),
|
|
4525
|
-
closed: geometry.isClosed
|
|
4525
|
+
closed: geometry.isClosed,
|
|
4526
|
+
label: style.label?.trim() ? style.label : null,
|
|
4527
|
+
labelColor: style.labelColor ?? null,
|
|
4528
|
+
labelSize: style.labelSize ?? 0
|
|
4526
4529
|
};
|
|
4527
4530
|
} catch {
|
|
4528
4531
|
mesh = null;
|
|
@@ -4543,10 +4546,9 @@ function transformedBounds(matrix, mesh) {
|
|
|
4543
4546
|
]);
|
|
4544
4547
|
}
|
|
4545
4548
|
function isInteractive(editor, shape, selected, editingId) {
|
|
4546
|
-
const soleId = selected.size === 1 ? selected.values().next().value : void 0;
|
|
4547
4549
|
let current = shape;
|
|
4548
4550
|
for (let depth = 0; depth < 32 && current; depth++) {
|
|
4549
|
-
if (current.id === editingId ||
|
|
4551
|
+
if (current.id === editingId || selected.has(current.id)) return true;
|
|
4550
4552
|
const parentId = current.parentId;
|
|
4551
4553
|
if (!editor.store.has(parentId)) return false;
|
|
4552
4554
|
const parent = editor.store.unsafeGetWithoutCapture(parentId);
|
|
@@ -4603,21 +4605,42 @@ function outsideSet(editor, frame, shapes) {
|
|
|
4603
4605
|
}
|
|
4604
4606
|
return retained;
|
|
4605
4607
|
}
|
|
4606
|
-
function
|
|
4608
|
+
function ownRenderMode(editor, shape, frame, outsideViewport) {
|
|
4607
4609
|
if (frame.debug || editor.isShapeHidden(shape)) return "dom";
|
|
4608
4610
|
const style = lodStyleFor(editor, shape);
|
|
4609
|
-
const mesh = style ? meshFor(editor, shape, style) : null;
|
|
4611
|
+
const mesh = style && !style.unmountWhenCulled ? meshFor(editor, shape, style) : null;
|
|
4610
4612
|
return getShapeRenderMode({
|
|
4611
4613
|
zoom: frame.zoom,
|
|
4612
4614
|
lodZoom: frame.lodZoom,
|
|
4613
4615
|
hasLodStyle: Boolean(style && (mesh || style.unmountWhenCulled)),
|
|
4614
4616
|
interactive: isInteractive(editor, shape, frame.selected, frame.editingId),
|
|
4615
|
-
outsideViewport
|
|
4617
|
+
outsideViewport,
|
|
4616
4618
|
unmountWhenCulled: Boolean(style?.unmountWhenCulled),
|
|
4617
4619
|
pageWidth: mesh?.w ?? 0,
|
|
4618
4620
|
pageHeight: mesh?.h ?? 0
|
|
4619
4621
|
});
|
|
4620
4622
|
}
|
|
4623
|
+
function coveredByDomBackground(editor, shape, frame) {
|
|
4624
|
+
let parentId = shape.parentId;
|
|
4625
|
+
for (let depth = 0; depth < 32; depth++) {
|
|
4626
|
+
if (!editor.store.has(parentId)) return false;
|
|
4627
|
+
const parent = editor.store.unsafeGetWithoutCapture(parentId);
|
|
4628
|
+
if (!parent || parent.typeName !== "shape") return false;
|
|
4629
|
+
const parentShape = parent;
|
|
4630
|
+
const util = editor.getShapeUtil(parentShape);
|
|
4631
|
+
if (util.providesBackgroundForChildren(parentShape) && ownRenderMode(editor, parentShape, frame, false) === "dom") {
|
|
4632
|
+
return true;
|
|
4633
|
+
}
|
|
4634
|
+
parentId = parentShape.parentId;
|
|
4635
|
+
}
|
|
4636
|
+
return false;
|
|
4637
|
+
}
|
|
4638
|
+
function modeFor(editor, shape, frame, outside) {
|
|
4639
|
+
const mode = ownRenderMode(editor, shape, frame, outside.has(shape.id));
|
|
4640
|
+
if (mode !== "canvas") return mode;
|
|
4641
|
+
if (coveredByDomBackground(editor, shape, frame)) return "dom";
|
|
4642
|
+
return mode;
|
|
4643
|
+
}
|
|
4621
4644
|
function trace(ctx, points) {
|
|
4622
4645
|
ctx.beginPath();
|
|
4623
4646
|
ctx.moveTo(points[0], points[1]);
|
|
@@ -4653,6 +4676,7 @@ function paintShape(ctx, camera, dpr, matrix, mesh, padPx = 0) {
|
|
|
4653
4676
|
ctx.lineCap = "round";
|
|
4654
4677
|
ctx.lineJoin = "round";
|
|
4655
4678
|
trace(ctx, mesh.points);
|
|
4679
|
+
if (mesh.closed) ctx.closePath();
|
|
4656
4680
|
ctx.stroke();
|
|
4657
4681
|
}
|
|
4658
4682
|
} else if (mesh.fill) {
|
|
@@ -4667,6 +4691,41 @@ function paintShape(ctx, camera, dpr, matrix, mesh, padPx = 0) {
|
|
|
4667
4691
|
);
|
|
4668
4692
|
ctx.fill();
|
|
4669
4693
|
}
|
|
4694
|
+
paintLodLabel(ctx, mesh);
|
|
4695
|
+
}
|
|
4696
|
+
function paintLodLabel(ctx, mesh) {
|
|
4697
|
+
const text = mesh.label?.trim();
|
|
4698
|
+
if (!text) return;
|
|
4699
|
+
const size = Math.max(10, mesh.labelSize || 16);
|
|
4700
|
+
const pad = Math.max(8, size * 0.45);
|
|
4701
|
+
const maxWidth = mesh.w - pad * 2;
|
|
4702
|
+
const maxY = mesh.y + mesh.h - pad;
|
|
4703
|
+
if (maxWidth < 8 || maxY <= mesh.y + pad) return;
|
|
4704
|
+
ctx.save();
|
|
4705
|
+
ctx.beginPath();
|
|
4706
|
+
ctx.rect(mesh.x, mesh.y, mesh.w, mesh.h);
|
|
4707
|
+
ctx.clip();
|
|
4708
|
+
ctx.fillStyle = mesh.labelColor || "#1d1d1d";
|
|
4709
|
+
ctx.font = `${size}px sans-serif`;
|
|
4710
|
+
ctx.textAlign = "left";
|
|
4711
|
+
ctx.textBaseline = "top";
|
|
4712
|
+
const words = text.split(/\s+/);
|
|
4713
|
+
let line = "";
|
|
4714
|
+
let y = mesh.y + pad;
|
|
4715
|
+
const lineHeight = size * 1.25;
|
|
4716
|
+
for (const word of words) {
|
|
4717
|
+
if (y > maxY) break;
|
|
4718
|
+
const next = line ? `${line} ${word}` : word;
|
|
4719
|
+
if (line && ctx.measureText(next).width > maxWidth) {
|
|
4720
|
+
ctx.fillText(line, mesh.x + pad, y, maxWidth);
|
|
4721
|
+
line = word;
|
|
4722
|
+
y += lineHeight;
|
|
4723
|
+
} else {
|
|
4724
|
+
line = next;
|
|
4725
|
+
}
|
|
4726
|
+
}
|
|
4727
|
+
if (line && y <= maxY) ctx.fillText(line, mesh.x + pad, y, maxWidth);
|
|
4728
|
+
ctx.restore();
|
|
4670
4729
|
}
|
|
4671
4730
|
var LOD_OVERSCAN_SCREEN_PX = 192;
|
|
4672
4731
|
var LOD_BITMAP_MAX_PX = 8192;
|
|
@@ -4707,16 +4766,9 @@ function paintVisibleLodShapes(ctx, editor, camera, dpr, shapes, frame, paintBou
|
|
|
4707
4766
|
if (!style || style.unmountWhenCulled) continue;
|
|
4708
4767
|
const mesh = meshFor(editor, shape, style);
|
|
4709
4768
|
if (!mesh) continue;
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
hasLodStyle: true,
|
|
4714
|
-
interactive: isInteractive(editor, shape, frame.selected, frame.editingId),
|
|
4715
|
-
outsideViewport: false,
|
|
4716
|
-
pageWidth: mesh.w,
|
|
4717
|
-
pageHeight: mesh.h
|
|
4718
|
-
});
|
|
4719
|
-
if (mode !== "canvas" || frame.debug) continue;
|
|
4769
|
+
if (ownRenderMode(editor, shape, frame, false) !== "canvas") continue;
|
|
4770
|
+
if (coveredByDomBackground(editor, shape, frame)) continue;
|
|
4771
|
+
if (frame.debug) continue;
|
|
4720
4772
|
const matrix = editor.getShapePageTransform(shape);
|
|
4721
4773
|
if (!paintBounds.collides(transformedBounds(matrix, mesh))) continue;
|
|
4722
4774
|
paintShape(ctx, camera, dpr, matrix, mesh, padPx);
|
|
@@ -9499,7 +9551,7 @@ var defaultDrawOptions = {
|
|
|
9499
9551
|
nonce: void 0,
|
|
9500
9552
|
debouncedZoom: true,
|
|
9501
9553
|
debouncedZoomThreshold: 500,
|
|
9502
|
-
lodZoom: 0.
|
|
9554
|
+
lodZoom: 0.35,
|
|
9503
9555
|
spacebarPanning: true,
|
|
9504
9556
|
rightClickPanning: true,
|
|
9505
9557
|
zoomToFitPadding: 128,
|
|
@@ -26259,7 +26311,7 @@ function getFontsFromRichText(editor, richText, initialState2) {
|
|
|
26259
26311
|
// src/index.ts
|
|
26260
26312
|
registerDrawLibraryVersion(
|
|
26261
26313
|
"@ibodr/editor",
|
|
26262
|
-
"0.2.
|
|
26314
|
+
"0.2.10",
|
|
26263
26315
|
"esm"
|
|
26264
26316
|
);
|
|
26265
26317
|
/*!
|