@ibodr/editor 0.2.14 → 0.2.15
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 +13 -1
- package/dist/index.mjs +220 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
|
@@ -2293,6 +2293,12 @@ interface DrLodStyle {
|
|
|
2293
2293
|
* picture with a flat stand-in.
|
|
2294
2294
|
*/
|
|
2295
2295
|
unmountWhenCulled?: boolean;
|
|
2296
|
+
/**
|
|
2297
|
+
* Below this screen size (CSS pixels on the longer side), if the shape is not
|
|
2298
|
+
* selected, the editor paints a captured bitmap on the lod canvas and unmounts
|
|
2299
|
+
* the DOM. Zooming in or selecting the shape mounts the real component again.
|
|
2300
|
+
*/
|
|
2301
|
+
snapshotBelowPx?: number;
|
|
2296
2302
|
}
|
|
2297
2303
|
interface DrCropInfo<T extends DrShape> {
|
|
2298
2304
|
handle: SelectionHandle;
|
|
@@ -10921,4 +10927,10 @@ declare function uniq<T>(array: {
|
|
|
10921
10927
|
readonly [n: number]: T;
|
|
10922
10928
|
} | null | undefined): T[];
|
|
10923
10929
|
|
|
10924
|
-
|
|
10930
|
+
/**
|
|
10931
|
+
* Heavy HTML shapes (images, PDF, decks) that opt in via `snapshotBelowPx`
|
|
10932
|
+
* leave the DOM below this screen size and are painted from a captured bitmap.
|
|
10933
|
+
*/
|
|
10934
|
+
declare const LOD_SNAPSHOT_SCREEN_PX = 180;
|
|
10935
|
+
|
|
10936
|
+
export { Arc2d, AssetUtil, BaseBoxShapeTool, BaseBoxShapeUtil, BaseFrameLikeShapeUtil, type BatchMeasurementRequest, type BindingOnChangeOptions, type BindingOnCreateOptions, type BindingOnDeleteOptions, type BindingOnShapeChangeOptions, type BindingOnShapeDeleteOptions, type BindingOnShapeIsolateOptions, BindingUtil, type BoundsSnapGeometry, type BoundsSnapPoint, BoundsSnaps, Box, type BoxLike, type CanvasMaxSize, Circle2d, ClickManager, CollaboratorsManager, ContainerProvider, type ContainerProviderProps, CubicBezier2d, CubicSpline2d, DEFAULT_ANIMATION_OPTIONS, DEFAULT_CAMERA_OPTIONS, DEFAULT_THEME, type DebugFlag, type DebugFlagDef, type DebugFlagDefaults, DefaultBackground, DefaultCanvas, DefaultCursor, DefaultErrorFallback, DefaultGrid, DefaultShapeWrapper, DefaultSpinner, DefaultSvgDefs, type DrAdjacentDirection, type DrAnyAssetUtilConstructor, type DrAnyBindingUtilConstructor, type DrAnyOverlayUtilConstructor, type DrAnyShapeUtilConstructor, type DrAssetUtilConstructor, type DrBackgroundProps, type DrBaseBoxShape, type DrBaseEventInfo, type DrBaseExternalContent, type DrBindingUtilConstructor, type DrCLickEventName, type DrCameraConstraints, type DrCameraEndPerfEvent, type DrCameraMoveOptions, type DrCameraOptions, type DrCameraStartPerfEvent, type DrCancelEvent, type DrCancelEventInfo, type DrCanvasComponentProps, type DrClickEvent, type DrClickEventInfo, type DrClickState, type DrClipboardPasteRawInfo, type DrClipboardWriteInfo, type DrCollaboratorCursorLayout, type DrCollaboratorCursorProps, type DrCompleteEvent, type DrCompleteEventInfo, type DrContent, type DrCropInfo, type DrCurrentUser, type DrCursorProps, type DrDeepLink, type DrDeepLinkOptions, type DrDragShapesInInfo, type DrDragShapesOutInfo, type DrDragShapesOverInfo, type DrDrawExternalContent, type DrDrawExternalContentSource, type DrDropShapesOverInfo, type DrEditStartInfo, type DrEditorComponents, type DrEditorOptions, type DrEditorRunOptions, type DrEditorSnapshot, type DrEmbedExternalContent, type DrEnterEventHandler, type DrErrorBoundaryProps, type DrErrorExternalContentSource, type DrErrorFallbackComponent, type DrErrorFallbackProps, type DrEventHandlers, type DrEventInfo, type DrEventMap, type DrEventMapHandler, type DrEventName, type DrExcalidrawExternalContent, type DrExcalidrawExternalContentSource, type DrExitEventHandler, type DrExportType, type DrExternalAsset, type DrExternalContent, type DrExternalContentSource, type DrFileExternalAsset, type DrFileReplaceExternalContent, type DrFilesExternalContent, type DrFramePerfEvent, type DrGeometryOpts, type DrGetShapeAtPointOptions, type DrGridProps, type DrHandleDragInfo, type DrHistoryBatchOptions, type DrHistoryDiff, type DrHistoryEntry, type DrHistoryMark, type DrImageExportOptions, type DrIndicatorPath, type DrInteractionEndPerfEvent, type DrInteractionStartPerfEvent, type DrInterruptEvent, type DrInterruptEventInfo, type DrKeyboardEvent, type DrKeyboardEventInfo, type DrKeyboardEventName, type DrLoadSessionStateSnapshotOptions, type DrLoadSnapshotOptions, type DrLodStyle, type DrMeasureTextOpts, type DrMeasureTextSpanOpts, type DrMeasuredTextSize, type DrMiroExternalContent, type DrMiroExternalContentSource, type DrOnMountHandler, type DrOverlay, type DrOverlayEntry, type DrOverlayUtilConstructor, type DrPerfEventMap, type DrPerfFrameTimeStats, type DrPerfLongAnimationFrame, type DrPerfLongAnimationFrameScript, type DrPinchEvent, type DrPinchEventInfo, type DrPinchEventName, type DrPointerEvent, type DrPointerEventInfo, type DrPointerEventName, type DrPointerEventTarget, type DrRenderingShape, type DrResizeHandle, type DrResizeInfo, type DrResizeMode, type DrResizeShapeOptions, type DrRotationSnapshot, type DrSelectionHandle, type DrSessionStateSnapshot, type DrShapeErrorFallbackComponent, type DrShapeOperationPerfEvent, type DrShapeUtilCanBeLaidOutOpts, type DrShapeUtilCanBindOpts, type DrShapeUtilCanvasSvgDef, type DrShapeUtilConstructor, type DrShapeWrapperProps, type DrSpinnerProps, type DrStateNodeConstructor, type DrStoreBaseOptions, type DrStoreEventInfo, type DrStoreOptions, type DrStoreSchemaOptions, type DrStoreWithStatus, type DrSvgExportOptions, type DrSvgTextExternalContent, type DrTextExternalContent, type DrTextExternalContentSource, type DrTextOptions, type DrTickEvent, type DrTickEventInfo, type DrUndoRedoPerfEvent, type DrUpdatePointerOptions, type DrUrlExternalAsset, type DrUrlExternalContent, type DrUserPreferences, type DrWheelEvent, type DrWheelEventInfo, DrawEditor, type DrawEditorBaseProps, type DrawEditorProps, type DrawEditorStoreProps, type DrawEditorWithStoreProps, type DrawEditorWithoutStoreProps, type DrawOptions, EASINGS, EVENT_NAME_MAP, Edge2d, EdgeScrollManager, Editor, EditorAtom, EditorContext, EditorManager, EditorPortal, type EditorPortalProps, EditorProvider, type EditorProviderProps, Ellipse2d, ErrorBoundary, ErrorScreen, FontManager, type GapsSnapIndicator, Geometry2d, Geometry2dFilters, type Geometry2dOptions, Group2d, GroupShapeUtil, HALF_PI, HTMLContainer, type HTMLContainerProps, type HandleSnapGeometry, HandleSnaps, HistoryManager, InputsManager, LOD_SNAPSHOT_SCREEN_PX, LoadingScreen, type LoadingScreenProps, LocalIndexedDb, Mat, type MatLike, type MatModel, MenuClickCapture, OptionalErrorBoundary, type OptionalKeys, OverlayManager, type OverlayOptionsWithDisplayValues, OverlayUtil, PI, PI2, type PerfectDashTerminal, PerformanceApiAdapter, PerformanceManager, Point2d, type PointsSnapIndicator, Polygon2d, Polyline2d, ROTATE_CORNER_TO_SELECTION_CORNER, ReadonlySharedStyleMap, Rectangle2d, type RequiredKeys, type ResizeBoxOptions, type RichTextFontVisitor, type RichTextFontVisitorState, type RotateCorner, SIDES, SIN, SVGContainer, type SVGContainerProps, type SafeId, type ScribbleItem, ScribbleManager, type ScribbleSessionOptions, type SelectionCorner, type SelectionEdge, type SelectionHandle, ShapeUtil, type SharedStyle, SharedStyleMap, type SnapData, type SnapIndicator, SnapManager, SpatialIndexManager, Stadium2d, StateNode, type StoreName, type SvgExportContext, type SvgExportDef, TAB_ID, Table, TextManager, ThemeManager, TickManager, type TiptapEditor, type TiptapNode, TransformedGeometry2d, type TransformedGeometry2dOptions, USER_COLORS, type UiEvent, type UiEventType, UserPreferencesManager, Vec, type VecLike, activeElementShouldCaptureKeys, angleDistance, applyRotationToSnapshotShapes, approximately, areAnglesCompatible, average, canonicalizeRotation, centerOfCircleFromThreePoints, clamp, clampRadians, clampToBrowserMaxCanvasSize, clockwiseAngleDist, coreShapes, counterClockwiseAngleDist, createDebugValue, createDeepLinkString, createDrCurrentUser, createDrSchemaFromUtils, createDrStore, createSessionStateSnapshotSignal, dataUrlToFile, debugFlags, defaultDrawOptions, defaultUserPreferences, defaultUserStore, degreesToRadians, elementShouldCaptureKeys, extractSessionStateFromLegacySnapshot, featureFlags, getArcMeasure, getColorValue, getCursor, getDefaultCdnBaseUrl, getDroppedShapesToNewParents, getFontsFromRichText, getFreshUserPreferences, getGlobalDocument, getGlobalWindow, getIncrementedName, getOverlayDisplayValues, getOwnerDocument, getOwnerWindow, getPerfectDashProps, getPointInArcT, getPointOnCircle, getPointerInfo, getPointsOnArc, getPolygonVertices, getRotationSnapshot, getSnapshot, getSvgAsImage, getSvgPathFromPoints, getUserPreferences, getVerticesCountForArcLength, hardReset, hardResetEditor, inlineBase64AssetStore, intersectCircleCircle, intersectCirclePolygon, intersectCirclePolyline, intersectLineSegmentCircle, intersectLineSegmentLineSegment, intersectLineSegmentPolygon, intersectLineSegmentPolyline, intersectPolygonBounds, intersectPolygonPolygon, isAccelKey, isCursorInViewport, isSafeFloat, kickoutOccludedShapes, linesIntersect, loadSessionStateSnapshotIntoStore, loadSnapshot, loopToHtmlElement, maybeSnapToGrid, moveElementInto, normalizeWheel, openWindow, parseDeepLinkString, perimeterOfEllipse, pointInPolygon, polygonIntersectsPolyline, polygonsIntersect, precise, preventDefault, radiansToDegrees, rangeIntersection, refreshPage, releasePointerCapture, resizeBox, resizeScaled, resolveLineHeightPx, resolveThemes, rotateSelectionHandle, runtime, sanitizeId, setPointerCapture, setRuntimeOverrides, setUserPreferences, shortAngleDist, snapAngle, stopEventPropagation, strokeShapeIndicators, suffixSafeId, tleditors, tlenv, tlenvReactive, tlmenus, tltime, toDomPrecision, toFixed, toPrecision, uniq, useColorMode, useContainer, useContainerIfExists, useDelaySvgExport, useDrSchemaFromUtils, useDrStore, useDrawCurrentUser, useEditor, useEditorComponents, useEditorPortalHost, useEvent, useGlobalMenuIsOpen, useIsCropping, useIsEditing, useLocalStore, useMaybeEditor, useOnMount, usePassThroughWheelEvents, usePeerIds, usePresence, useReactiveEvent, useRefState, useShallowArrayIdentity, useShallowObjectIdentity, useSharedSafeId, useSvgExportContext, useTransform, useUniqueSafeId, useViewportHeight, userTypeValidator };
|
package/dist/index.mjs
CHANGED
|
@@ -4462,15 +4462,129 @@ function drawGeometryStroke(ctx, geometry) {
|
|
|
4462
4462
|
var LOD_KEEP_SCREEN_PX = 36;
|
|
4463
4463
|
var LOD_KEEP_TEXT_PX = 7;
|
|
4464
4464
|
var LOD_CULL_MARGIN = 0.75;
|
|
4465
|
+
var LOD_SNAPSHOT_SCREEN_PX = 180;
|
|
4465
4466
|
function getShapeRenderMode(input) {
|
|
4466
4467
|
if (!input.hasLodStyle || input.interactive) return "dom";
|
|
4467
4468
|
if (input.outsideViewport) return "unmounted";
|
|
4468
|
-
if (input.unmountWhenCulled) return "dom";
|
|
4469
4469
|
const screenMax = Math.max(input.pageWidth, input.pageHeight) * input.zoom;
|
|
4470
4470
|
const textScreen = (input.labelSize ?? 0) * input.zoom;
|
|
4471
|
+
const snapshotBelow = input.snapshotBelowPx ?? 0;
|
|
4472
|
+
if (snapshotBelow > 0 && screenMax < snapshotBelow) {
|
|
4473
|
+
return input.hasSnapshot ? "canvas" : "dom";
|
|
4474
|
+
}
|
|
4475
|
+
if (input.unmountWhenCulled) return "dom";
|
|
4471
4476
|
if (screenMax >= LOD_KEEP_SCREEN_PX || textScreen >= LOD_KEEP_TEXT_PX) return "dom";
|
|
4472
4477
|
return "canvas";
|
|
4473
4478
|
}
|
|
4479
|
+
var SNAPSHOT_MAX_EDGE = 768;
|
|
4480
|
+
var MAX_SNAPSHOTS = 48;
|
|
4481
|
+
var MAX_CAPTURE_ATTEMPTS = 8;
|
|
4482
|
+
var snapshots = /* @__PURE__ */ new Map();
|
|
4483
|
+
var attempts = /* @__PURE__ */ new WeakMap();
|
|
4484
|
+
var lodSnapshotEpoch = atom("lod-snapshot-epoch", 0);
|
|
4485
|
+
var retryTimer = 0;
|
|
4486
|
+
function lodSnapshotCovers(shape, screenPx) {
|
|
4487
|
+
const entry = snapshots.get(shape.id);
|
|
4488
|
+
if (!entry || entry.shape !== shape) return false;
|
|
4489
|
+
return entry.screenPx >= screenPx * 0.85;
|
|
4490
|
+
}
|
|
4491
|
+
function getLodSnapshot(shape) {
|
|
4492
|
+
const entry = snapshots.get(shape.id);
|
|
4493
|
+
if (!entry || entry.shape !== shape) return null;
|
|
4494
|
+
return entry.canvas;
|
|
4495
|
+
}
|
|
4496
|
+
function releaseCanvas(canvas) {
|
|
4497
|
+
canvas.width = 0;
|
|
4498
|
+
canvas.height = 0;
|
|
4499
|
+
}
|
|
4500
|
+
function storeLodSnapshot(shape, canvas, screenPx) {
|
|
4501
|
+
const previous = snapshots.get(shape.id);
|
|
4502
|
+
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);
|
|
4511
|
+
}
|
|
4512
|
+
attempts.delete(shape);
|
|
4513
|
+
}
|
|
4514
|
+
function scheduleLodSnapshotPass() {
|
|
4515
|
+
if (retryTimer !== 0 || typeof window === "undefined") return;
|
|
4516
|
+
retryTimer = window.setTimeout(() => {
|
|
4517
|
+
retryTimer = 0;
|
|
4518
|
+
lodSnapshotEpoch.set(lodSnapshotEpoch.get() + 1);
|
|
4519
|
+
}, 250);
|
|
4520
|
+
}
|
|
4521
|
+
function captureShapeSnapshot(element) {
|
|
4522
|
+
const rect = element.getBoundingClientRect();
|
|
4523
|
+
if (rect.width < 2 || rect.height < 2) return null;
|
|
4524
|
+
const sources = [];
|
|
4525
|
+
for (const node of element.querySelectorAll("canvas, img")) {
|
|
4526
|
+
if (node instanceof HTMLCanvasElement) {
|
|
4527
|
+
if (node.width < 2 || node.height < 2) continue;
|
|
4528
|
+
sources.push(node);
|
|
4529
|
+
} else if (node instanceof HTMLImageElement) {
|
|
4530
|
+
if (!node.complete || node.naturalWidth < 2) continue;
|
|
4531
|
+
sources.push(node);
|
|
4532
|
+
}
|
|
4533
|
+
}
|
|
4534
|
+
if (sources.length === 0) return null;
|
|
4535
|
+
const long = Math.max(rect.width, rect.height);
|
|
4536
|
+
const scale = Math.min(SNAPSHOT_MAX_EDGE / long, (window.devicePixelRatio || 1) * 2);
|
|
4537
|
+
const width = Math.max(1, Math.round(rect.width * scale));
|
|
4538
|
+
const height = Math.max(1, Math.round(rect.height * scale));
|
|
4539
|
+
const canvas = document.createElement("canvas");
|
|
4540
|
+
canvas.width = width;
|
|
4541
|
+
canvas.height = height;
|
|
4542
|
+
const ctx = canvas.getContext("2d");
|
|
4543
|
+
if (!ctx) return null;
|
|
4544
|
+
ctx.imageSmoothingEnabled = true;
|
|
4545
|
+
ctx.imageSmoothingQuality = "high";
|
|
4546
|
+
const sx = width / rect.width;
|
|
4547
|
+
const sy = height / rect.height;
|
|
4548
|
+
let drew = false;
|
|
4549
|
+
for (const source of sources) {
|
|
4550
|
+
const box = source.getBoundingClientRect();
|
|
4551
|
+
if (box.width < 1 || box.height < 1) continue;
|
|
4552
|
+
try {
|
|
4553
|
+
ctx.drawImage(
|
|
4554
|
+
source,
|
|
4555
|
+
(box.left - rect.left) * sx,
|
|
4556
|
+
(box.top - rect.top) * sy,
|
|
4557
|
+
box.width * sx,
|
|
4558
|
+
box.height * sy
|
|
4559
|
+
);
|
|
4560
|
+
drew = true;
|
|
4561
|
+
} catch {
|
|
4562
|
+
}
|
|
4563
|
+
}
|
|
4564
|
+
if (!drew) {
|
|
4565
|
+
releaseCanvas(canvas);
|
|
4566
|
+
return null;
|
|
4567
|
+
}
|
|
4568
|
+
return canvas;
|
|
4569
|
+
}
|
|
4570
|
+
function findShapeElement(container, shapeId) {
|
|
4571
|
+
const selector = `[data-shape-id="${CSS.escape(shapeId)}"]`;
|
|
4572
|
+
const nodes = container.querySelectorAll(selector);
|
|
4573
|
+
let fallback = null;
|
|
4574
|
+
for (const node of nodes) {
|
|
4575
|
+
if (!(node instanceof HTMLElement)) continue;
|
|
4576
|
+
if (node.querySelector("canvas, img")) return node;
|
|
4577
|
+
fallback = fallback ?? node;
|
|
4578
|
+
}
|
|
4579
|
+
return fallback;
|
|
4580
|
+
}
|
|
4581
|
+
function noteSnapshotMiss(shape) {
|
|
4582
|
+
const count = (attempts.get(shape) ?? 0) + 1;
|
|
4583
|
+
attempts.set(shape, count);
|
|
4584
|
+
if (count > MAX_CAPTURE_ATTEMPTS) return false;
|
|
4585
|
+
scheduleLodSnapshotPass();
|
|
4586
|
+
return true;
|
|
4587
|
+
}
|
|
4474
4588
|
var MAX_LOD_POINTS = 48;
|
|
4475
4589
|
var meshCache = /* @__PURE__ */ new WeakMap();
|
|
4476
4590
|
var styleCache = /* @__PURE__ */ new WeakMap();
|
|
@@ -4612,18 +4726,28 @@ function ownRenderMode(editor, shape, frame, outsideViewport) {
|
|
|
4612
4726
|
const style = lodStyleFor(editor, shape);
|
|
4613
4727
|
const mesh = style && !style.unmountWhenCulled ? meshFor(editor, shape, style) : null;
|
|
4614
4728
|
const pageBounds = editor.getShapePageBounds(shape);
|
|
4729
|
+
const pageWidth = pageBounds?.w ?? mesh?.w ?? 0;
|
|
4730
|
+
const pageHeight = pageBounds?.h ?? mesh?.h ?? 0;
|
|
4731
|
+
const screenMax = Math.max(pageWidth, pageHeight) * frame.zoom;
|
|
4615
4732
|
return getShapeRenderMode({
|
|
4616
4733
|
zoom: frame.zoom,
|
|
4617
4734
|
lodZoom: frame.lodZoom,
|
|
4618
|
-
hasLodStyle: Boolean(
|
|
4735
|
+
hasLodStyle: Boolean(
|
|
4736
|
+
style && (mesh || style.unmountWhenCulled || (style.snapshotBelowPx ?? 0) > 0)
|
|
4737
|
+
),
|
|
4619
4738
|
interactive: isInteractive(editor, shape, frame.selected, frame.editingId),
|
|
4620
4739
|
outsideViewport,
|
|
4621
4740
|
unmountWhenCulled: Boolean(style?.unmountWhenCulled),
|
|
4622
|
-
pageWidth
|
|
4623
|
-
pageHeight
|
|
4624
|
-
labelSize: style?.labelSize ?? 0
|
|
4741
|
+
pageWidth,
|
|
4742
|
+
pageHeight,
|
|
4743
|
+
labelSize: style?.labelSize ?? 0,
|
|
4744
|
+
snapshotBelowPx: style?.snapshotBelowPx,
|
|
4745
|
+
hasSnapshot: snapshotCoversShape(shape, screenMax)
|
|
4625
4746
|
});
|
|
4626
4747
|
}
|
|
4748
|
+
function snapshotCoversShape(shape, screenMax) {
|
|
4749
|
+
return lodSnapshotCovers(shape, screenMax);
|
|
4750
|
+
}
|
|
4627
4751
|
function coveredByDomBackground(editor, shape, frame) {
|
|
4628
4752
|
let parentId = shape.parentId;
|
|
4629
4753
|
for (let depth = 0; depth < 32; depth++) {
|
|
@@ -4697,6 +4821,24 @@ function paintShape(ctx, camera, dpr, matrix, mesh, padPx = 0) {
|
|
|
4697
4821
|
}
|
|
4698
4822
|
paintLodLabel(ctx, mesh);
|
|
4699
4823
|
}
|
|
4824
|
+
function paintSnapshot(ctx, camera, dpr, matrix, mesh, bitmap, padPx = 0) {
|
|
4825
|
+
if (mesh.opacity <= 0 || bitmap.width < 1 || bitmap.height < 1) return;
|
|
4826
|
+
const z = camera.z || 1;
|
|
4827
|
+
ctx.save();
|
|
4828
|
+
ctx.globalAlpha = mesh.opacity;
|
|
4829
|
+
ctx.imageSmoothingEnabled = true;
|
|
4830
|
+
ctx.imageSmoothingQuality = "high";
|
|
4831
|
+
ctx.setTransform(
|
|
4832
|
+
dpr * z * matrix.a,
|
|
4833
|
+
dpr * z * matrix.b,
|
|
4834
|
+
dpr * z * matrix.c,
|
|
4835
|
+
dpr * z * matrix.d,
|
|
4836
|
+
dpr * z * (matrix.e + camera.x) + padPx,
|
|
4837
|
+
dpr * z * (matrix.f + camera.y) + padPx
|
|
4838
|
+
);
|
|
4839
|
+
ctx.drawImage(bitmap, mesh.x, mesh.y, Math.max(mesh.w, 1), Math.max(mesh.h, 1));
|
|
4840
|
+
ctx.restore();
|
|
4841
|
+
}
|
|
4700
4842
|
function paintLodLabel(ctx, mesh) {
|
|
4701
4843
|
const text = mesh.label?.trim();
|
|
4702
4844
|
if (!text) return;
|
|
@@ -4735,6 +4877,7 @@ var LOD_OVERSCAN_SCREEN_PX = 192;
|
|
|
4735
4877
|
var LOD_BITMAP_MAX_PX = 8192;
|
|
4736
4878
|
function lodBitmapCovers(bitmap, camera, viewport, dpr, shapes, frame, theme, colorMode) {
|
|
4737
4879
|
if (bitmap.zoom !== camera.z || bitmap.dpr !== dpr) return false;
|
|
4880
|
+
if (bitmap.snapshotEpoch !== lodSnapshotEpoch.get()) return false;
|
|
4738
4881
|
if (bitmap.shapes !== shapes || bitmap.selectedIds !== frame.selectedIds) return false;
|
|
4739
4882
|
if (bitmap.editingId !== frame.editingId || bitmap.theme !== theme || bitmap.colorMode !== colorMode) {
|
|
4740
4883
|
return false;
|
|
@@ -4767,14 +4910,23 @@ function paintVisibleLodShapes(ctx, editor, camera, dpr, shapes, frame, paintBou
|
|
|
4767
4910
|
for (const shape of shapes) {
|
|
4768
4911
|
if (editor.isShapeHidden(shape)) continue;
|
|
4769
4912
|
const style = lodStyleFor(editor, shape);
|
|
4770
|
-
if (!style
|
|
4913
|
+
if (!style) continue;
|
|
4914
|
+
const mode = ownRenderMode(editor, shape, frame, false);
|
|
4915
|
+
if (mode === "unmounted" || frame.debug) continue;
|
|
4916
|
+
if (mode === "canvas" && coveredByDomBackground(editor, shape, frame)) continue;
|
|
4771
4917
|
const mesh = meshFor(editor, shape, style);
|
|
4772
4918
|
if (!mesh) continue;
|
|
4773
|
-
if (ownRenderMode(editor, shape, frame, false) !== "canvas") continue;
|
|
4774
|
-
if (coveredByDomBackground(editor, shape, frame)) continue;
|
|
4775
|
-
if (frame.debug) continue;
|
|
4776
4919
|
const matrix = editor.getShapePageTransform(shape);
|
|
4777
4920
|
if (!paintBounds.collides(transformedBounds(matrix, mesh))) continue;
|
|
4921
|
+
const snapshot = getLodSnapshot(shape);
|
|
4922
|
+
const page = editor.getShapePageBounds(shape);
|
|
4923
|
+
const screenMax = page ? Math.max(page.w, page.h) * (camera.z || 1) : 0;
|
|
4924
|
+
const nearFreeze = (style.snapshotBelowPx ?? 0) > 0 && screenMax < (style.snapshotBelowPx ?? 0) * 1.35;
|
|
4925
|
+
if (snapshot && (mode === "canvas" || nearFreeze)) {
|
|
4926
|
+
paintSnapshot(ctx, camera, dpr, matrix, mesh, snapshot, padPx);
|
|
4927
|
+
if (mode !== "dom") continue;
|
|
4928
|
+
}
|
|
4929
|
+
if (mode !== "canvas" || style.unmountWhenCulled) continue;
|
|
4778
4930
|
paintShape(ctx, camera, dpr, matrix, mesh, padPx);
|
|
4779
4931
|
}
|
|
4780
4932
|
}
|
|
@@ -4784,6 +4936,7 @@ function useMountedRenderingShapes() {
|
|
|
4784
4936
|
return useValue(
|
|
4785
4937
|
"mounted rendering shapes",
|
|
4786
4938
|
() => {
|
|
4939
|
+
lodSnapshotEpoch.get();
|
|
4787
4940
|
const rendering = editor.getRenderingShapes();
|
|
4788
4941
|
const shapes = editor.getCurrentPageShapesSorted();
|
|
4789
4942
|
editor.getCurrentTheme();
|
|
@@ -4810,6 +4963,47 @@ function useMountedRenderingShapes() {
|
|
|
4810
4963
|
[editor]
|
|
4811
4964
|
);
|
|
4812
4965
|
}
|
|
4966
|
+
var CAPTURES_PER_PASS = 2;
|
|
4967
|
+
function captureDueSnapshots(editor) {
|
|
4968
|
+
const frame = readFrame(editor);
|
|
4969
|
+
if (frame.moving || frame.debug) return;
|
|
4970
|
+
let container;
|
|
4971
|
+
try {
|
|
4972
|
+
container = editor.getContainer();
|
|
4973
|
+
} catch {
|
|
4974
|
+
return;
|
|
4975
|
+
}
|
|
4976
|
+
let captured = 0;
|
|
4977
|
+
let deferred = false;
|
|
4978
|
+
let changed = false;
|
|
4979
|
+
for (const shape of editor.getCurrentPageShapesSorted()) {
|
|
4980
|
+
if (editor.isShapeHidden(shape)) continue;
|
|
4981
|
+
const style = lodStyleFor(editor, shape);
|
|
4982
|
+
const below = style?.snapshotBelowPx ?? 0;
|
|
4983
|
+
if (below <= 0) continue;
|
|
4984
|
+
if (isInteractive(editor, shape, frame.selected, frame.editingId)) continue;
|
|
4985
|
+
const bounds = editor.getShapePageBounds(shape);
|
|
4986
|
+
if (!bounds || !frame.expanded.collides(bounds)) continue;
|
|
4987
|
+
const screenMax = Math.max(bounds.w, bounds.h) * frame.zoom;
|
|
4988
|
+
if (screenMax < 8 || screenMax > below * 1.35) continue;
|
|
4989
|
+
if (lodSnapshotCovers(shape, screenMax)) continue;
|
|
4990
|
+
if (captured >= CAPTURES_PER_PASS) {
|
|
4991
|
+
deferred = true;
|
|
4992
|
+
break;
|
|
4993
|
+
}
|
|
4994
|
+
const element = findShapeElement(container, shape.id);
|
|
4995
|
+
const bitmap = element ? captureShapeSnapshot(element) : null;
|
|
4996
|
+
if (!bitmap) {
|
|
4997
|
+
noteSnapshotMiss(shape);
|
|
4998
|
+
continue;
|
|
4999
|
+
}
|
|
5000
|
+
storeLodSnapshot(shape, bitmap, screenMax);
|
|
5001
|
+
captured += 1;
|
|
5002
|
+
changed = true;
|
|
5003
|
+
}
|
|
5004
|
+
if (changed) lodSnapshotEpoch.set(lodSnapshotEpoch.get() + 1);
|
|
5005
|
+
if (deferred) scheduleLodSnapshotPass();
|
|
5006
|
+
}
|
|
4813
5007
|
function LodCanvas() {
|
|
4814
5008
|
const editor = useEditor();
|
|
4815
5009
|
const canvasRef = useRef(null);
|
|
@@ -4817,6 +5011,7 @@ function LodCanvas() {
|
|
|
4817
5011
|
useQuickReactor(
|
|
4818
5012
|
"lod canvas",
|
|
4819
5013
|
() => {
|
|
5014
|
+
lodSnapshotEpoch.get();
|
|
4820
5015
|
const canvas = canvasRef.current;
|
|
4821
5016
|
if (!canvas) return;
|
|
4822
5017
|
const camera = editor.getCamera();
|
|
@@ -4878,7 +5073,8 @@ function LodCanvas() {
|
|
|
4878
5073
|
editingId: frame.editingId,
|
|
4879
5074
|
theme,
|
|
4880
5075
|
colorMode,
|
|
4881
|
-
canvas: target
|
|
5076
|
+
canvas: target,
|
|
5077
|
+
snapshotEpoch: lodSnapshotEpoch.get()
|
|
4882
5078
|
};
|
|
4883
5079
|
bitmapRef.current = bitmap;
|
|
4884
5080
|
blitLodBitmap(ctx, width, height, bitmap, camera);
|
|
@@ -4887,6 +5083,18 @@ function LodCanvas() {
|
|
|
4887
5083
|
},
|
|
4888
5084
|
[editor]
|
|
4889
5085
|
);
|
|
5086
|
+
useQuickReactor(
|
|
5087
|
+
"capture lod snapshots",
|
|
5088
|
+
() => {
|
|
5089
|
+
lodSnapshotEpoch.get();
|
|
5090
|
+
editor.getCamera();
|
|
5091
|
+
editor.getCameraState();
|
|
5092
|
+
editor.getSelectedShapeIds();
|
|
5093
|
+
editor.getEditingShapeId();
|
|
5094
|
+
unsafe__withoutCapture(() => captureDueSnapshots(editor));
|
|
5095
|
+
},
|
|
5096
|
+
[editor]
|
|
5097
|
+
);
|
|
4890
5098
|
return /* @__PURE__ */ jsx("canvas", { ref: canvasRef, className: "dr-lod-canvas", "aria-hidden": "true" });
|
|
4891
5099
|
}
|
|
4892
5100
|
function DefaultCanvas({ className }) {
|
|
@@ -26315,7 +26523,7 @@ function getFontsFromRichText(editor, richText, initialState2) {
|
|
|
26315
26523
|
// src/index.ts
|
|
26316
26524
|
registerDrawLibraryVersion(
|
|
26317
26525
|
"@ibodr/editor",
|
|
26318
|
-
"0.2.
|
|
26526
|
+
"0.2.15",
|
|
26319
26527
|
"esm"
|
|
26320
26528
|
);
|
|
26321
26529
|
/*!
|
|
@@ -26339,6 +26547,6 @@ registerDrawLibraryVersion(
|
|
|
26339
26547
|
* while using the virtual keyboard.
|
|
26340
26548
|
*/
|
|
26341
26549
|
|
|
26342
|
-
export { Arc2d, AssetUtil, BaseBoxShapeTool, BaseBoxShapeUtil, BaseFrameLikeShapeUtil, BindingUtil, BoundsSnaps, Box, Circle2d, ClickManager, CollaboratorsManager, ContainerProvider, CubicBezier2d, CubicSpline2d, DEFAULT_ANIMATION_OPTIONS, DEFAULT_CAMERA_OPTIONS, DEFAULT_THEME, DefaultBackground, DefaultCanvas, DefaultCursor, DefaultErrorFallback, DefaultGrid, DefaultShapeWrapper, DefaultSpinner, DefaultSvgDefs, DrawEditor, EASINGS, EVENT_NAME_MAP, Edge2d, EdgeScrollManager, Editor, EditorAtom, EditorContext, EditorManager, EditorPortal, EditorProvider, Ellipse2d, ErrorBoundary, ErrorScreen, FontManager, Geometry2d, Geometry2dFilters, Group2d, GroupShapeUtil, HALF_PI, HTMLContainer, HandleSnaps, HistoryManager, InputsManager, LoadingScreen, LocalIndexedDb, Mat, MenuClickCapture, OptionalErrorBoundary, OverlayManager, OverlayUtil, PI, PI2, PerformanceApiAdapter, PerformanceManager, Point2d, Polygon2d, Polyline2d, ROTATE_CORNER_TO_SELECTION_CORNER, ReadonlySharedStyleMap, Rectangle2d, SIDES, SIN, SVGContainer, ScribbleManager, ShapeUtil, SharedStyleMap, SnapManager, SpatialIndexManager, Stadium2d, StateNode, TAB_ID, Table, TextManager, ThemeManager, TickManager, TransformedGeometry2d, USER_COLORS, UserPreferencesManager, Vec, activeElementShouldCaptureKeys, angleDistance, applyRotationToSnapshotShapes, approximately, areAnglesCompatible, average, canonicalizeRotation, centerOfCircleFromThreePoints, clamp2 as clamp, clampRadians, clampToBrowserMaxCanvasSize, clockwiseAngleDist, coreShapes, counterClockwiseAngleDist, createDebugValue, createDeepLinkString, createDrCurrentUser, createDrSchemaFromUtils, createDrStore, createSessionStateSnapshotSignal, dataUrlToFile, debugFlags, defaultDrawOptions, defaultUserPreferences, defaultUserStore, degreesToRadians, elementShouldCaptureKeys, extractSessionStateFromLegacySnapshot, featureFlags, getArcMeasure, getColorValue, getCursor, getDefaultCdnBaseUrl, getDroppedShapesToNewParents, getFontsFromRichText, getFreshUserPreferences, getGlobalDocument, getGlobalWindow, getIncrementedName, getOverlayDisplayValues, getOwnerDocument, getOwnerWindow, getPerfectDashProps, getPointInArcT, getPointOnCircle, getPointerInfo, getPointsOnArc, getPolygonVertices, getRotationSnapshot, getSnapshot, getSvgAsImage, getSvgPathFromPoints, getUserPreferences, getVerticesCountForArcLength, hardReset, hardResetEditor, inlineBase64AssetStore, intersectCircleCircle, intersectCirclePolygon, intersectCirclePolyline, intersectLineSegmentCircle, intersectLineSegmentLineSegment, intersectLineSegmentPolygon, intersectLineSegmentPolyline, intersectPolygonBounds, intersectPolygonPolygon, isAccelKey, isCursorInViewport, isSafeFloat, kickoutOccludedShapes, linesIntersect, loadSessionStateSnapshotIntoStore, loadSnapshot, loopToHtmlElement, maybeSnapToGrid, moveElementInto, normalizeWheel, openWindow, parseDeepLinkString, perimeterOfEllipse, pointInPolygon, polygonIntersectsPolyline, polygonsIntersect, precise, preventDefault, radiansToDegrees, rangeIntersection, refreshPage, releasePointerCapture, resizeBox, resizeScaled, resolveLineHeightPx, resolveThemes, rotateSelectionHandle, runtime, sanitizeId, setPointerCapture, setRuntimeOverrides, setUserPreferences, shortAngleDist, snapAngle, stopEventPropagation, strokeShapeIndicators, suffixSafeId, tleditors, tlenv, tlenvReactive, tlmenus, tltime, toDomPrecision, toFixed2 as toFixed, toPrecision, uniq, useColorMode, useContainer, useContainerIfExists, useDelaySvgExport, useDrSchemaFromUtils, useDrStore, useDrawCurrentUser, useEditor, useEditorComponents, useEditorPortalHost, useEvent, useGlobalMenuIsOpen, useIsCropping, useIsEditing, useLocalStore, useMaybeEditor, useOnMount, usePassThroughWheelEvents, usePeerIds, usePresence, useReactiveEvent, useRefState, useShallowArrayIdentity, useShallowObjectIdentity, useSharedSafeId, useSvgExportContext, useTransform, useUniqueSafeId, useViewportHeight, userTypeValidator };
|
|
26550
|
+
export { Arc2d, AssetUtil, BaseBoxShapeTool, BaseBoxShapeUtil, BaseFrameLikeShapeUtil, BindingUtil, BoundsSnaps, Box, Circle2d, ClickManager, CollaboratorsManager, ContainerProvider, CubicBezier2d, CubicSpline2d, DEFAULT_ANIMATION_OPTIONS, DEFAULT_CAMERA_OPTIONS, DEFAULT_THEME, DefaultBackground, DefaultCanvas, DefaultCursor, DefaultErrorFallback, DefaultGrid, DefaultShapeWrapper, DefaultSpinner, DefaultSvgDefs, DrawEditor, EASINGS, EVENT_NAME_MAP, Edge2d, EdgeScrollManager, Editor, EditorAtom, EditorContext, EditorManager, EditorPortal, EditorProvider, Ellipse2d, ErrorBoundary, ErrorScreen, FontManager, Geometry2d, Geometry2dFilters, Group2d, GroupShapeUtil, HALF_PI, HTMLContainer, HandleSnaps, HistoryManager, InputsManager, LOD_SNAPSHOT_SCREEN_PX, LoadingScreen, LocalIndexedDb, Mat, MenuClickCapture, OptionalErrorBoundary, OverlayManager, OverlayUtil, PI, PI2, PerformanceApiAdapter, PerformanceManager, Point2d, Polygon2d, Polyline2d, ROTATE_CORNER_TO_SELECTION_CORNER, ReadonlySharedStyleMap, Rectangle2d, SIDES, SIN, SVGContainer, ScribbleManager, ShapeUtil, SharedStyleMap, SnapManager, SpatialIndexManager, Stadium2d, StateNode, TAB_ID, Table, TextManager, ThemeManager, TickManager, TransformedGeometry2d, USER_COLORS, UserPreferencesManager, Vec, activeElementShouldCaptureKeys, angleDistance, applyRotationToSnapshotShapes, approximately, areAnglesCompatible, average, canonicalizeRotation, centerOfCircleFromThreePoints, clamp2 as clamp, clampRadians, clampToBrowserMaxCanvasSize, clockwiseAngleDist, coreShapes, counterClockwiseAngleDist, createDebugValue, createDeepLinkString, createDrCurrentUser, createDrSchemaFromUtils, createDrStore, createSessionStateSnapshotSignal, dataUrlToFile, debugFlags, defaultDrawOptions, defaultUserPreferences, defaultUserStore, degreesToRadians, elementShouldCaptureKeys, extractSessionStateFromLegacySnapshot, featureFlags, getArcMeasure, getColorValue, getCursor, getDefaultCdnBaseUrl, getDroppedShapesToNewParents, getFontsFromRichText, getFreshUserPreferences, getGlobalDocument, getGlobalWindow, getIncrementedName, getOverlayDisplayValues, getOwnerDocument, getOwnerWindow, getPerfectDashProps, getPointInArcT, getPointOnCircle, getPointerInfo, getPointsOnArc, getPolygonVertices, getRotationSnapshot, getSnapshot, getSvgAsImage, getSvgPathFromPoints, getUserPreferences, getVerticesCountForArcLength, hardReset, hardResetEditor, inlineBase64AssetStore, intersectCircleCircle, intersectCirclePolygon, intersectCirclePolyline, intersectLineSegmentCircle, intersectLineSegmentLineSegment, intersectLineSegmentPolygon, intersectLineSegmentPolyline, intersectPolygonBounds, intersectPolygonPolygon, isAccelKey, isCursorInViewport, isSafeFloat, kickoutOccludedShapes, linesIntersect, loadSessionStateSnapshotIntoStore, loadSnapshot, loopToHtmlElement, maybeSnapToGrid, moveElementInto, normalizeWheel, openWindow, parseDeepLinkString, perimeterOfEllipse, pointInPolygon, polygonIntersectsPolyline, polygonsIntersect, precise, preventDefault, radiansToDegrees, rangeIntersection, refreshPage, releasePointerCapture, resizeBox, resizeScaled, resolveLineHeightPx, resolveThemes, rotateSelectionHandle, runtime, sanitizeId, setPointerCapture, setRuntimeOverrides, setUserPreferences, shortAngleDist, snapAngle, stopEventPropagation, strokeShapeIndicators, suffixSafeId, tleditors, tlenv, tlenvReactive, tlmenus, tltime, toDomPrecision, toFixed2 as toFixed, toPrecision, uniq, useColorMode, useContainer, useContainerIfExists, useDelaySvgExport, useDrSchemaFromUtils, useDrStore, useDrawCurrentUser, useEditor, useEditorComponents, useEditorPortalHost, useEvent, useGlobalMenuIsOpen, useIsCropping, useIsEditing, useLocalStore, useMaybeEditor, useOnMount, usePassThroughWheelEvents, usePeerIds, usePresence, useReactiveEvent, useRefState, useShallowArrayIdentity, useShallowObjectIdentity, useSharedSafeId, useSvgExportContext, useTransform, useUniqueSafeId, useViewportHeight, userTypeValidator };
|
|
26343
26551
|
//# sourceMappingURL=index.mjs.map
|
|
26344
26552
|
//# sourceMappingURL=index.mjs.map
|