@ibodr/editor 0.2.7 → 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 +42 -1
- package/dist/index.mjs +445 -3
- package/dist/index.mjs.map +1 -1
- package/editor.css +9 -0
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
|
@@ -1682,6 +1682,16 @@ declare abstract class ShapeUtil<Shape extends DrShape = DrShape> {
|
|
|
1682
1682
|
* @param shape - The shape.
|
|
1683
1683
|
*/
|
|
1684
1684
|
canCull(shape: Shape): boolean;
|
|
1685
|
+
/**
|
|
1686
|
+
* Cheap canvas stand-in used when this shape is zoomed out or far outside the viewport.
|
|
1687
|
+
* Return null to keep the regular DOM node (media, in-progress strokes, anything stateful).
|
|
1688
|
+
* Selected and edited shapes always stay in the DOM.
|
|
1689
|
+
*
|
|
1690
|
+
* Coordinates consumed by the canvas are the shape's local geometry.
|
|
1691
|
+
*
|
|
1692
|
+
* @param shape - The shape.
|
|
1693
|
+
*/
|
|
1694
|
+
getLodStyle(_shape: Shape): DrLodStyle | null;
|
|
1685
1695
|
/**
|
|
1686
1696
|
* Does this shape provide a background for its children? If this is true,
|
|
1687
1697
|
* then any children with a `renderBackground` method will have their
|
|
@@ -2260,6 +2270,30 @@ declare abstract class ShapeUtil<Shape extends DrShape = DrShape> {
|
|
|
2260
2270
|
* @param initialShape - The shape at the start of the resize.
|
|
2261
2271
|
* @public
|
|
2262
2272
|
*/
|
|
2273
|
+
/**
|
|
2274
|
+
* How to paint a shape into the shared low-detail canvas.
|
|
2275
|
+
* `fill` with no `stroke` paints the geometry bounds.
|
|
2276
|
+
* `stroke` paints a decimated polyline of the geometry vertices.
|
|
2277
|
+
*
|
|
2278
|
+
* @public
|
|
2279
|
+
*/
|
|
2280
|
+
interface DrLodStyle {
|
|
2281
|
+
fill: string | null;
|
|
2282
|
+
stroke: string | null;
|
|
2283
|
+
strokeWidth: number;
|
|
2284
|
+
/** Multiplied by the shape's own opacity. Defaults to 1. */
|
|
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;
|
|
2290
|
+
/**
|
|
2291
|
+
* Unmount the shape when it is far outside the viewport, but keep the real DOM
|
|
2292
|
+
* whenever it is on screen. Used for images so a pan back does not replace the
|
|
2293
|
+
* picture with a flat stand-in.
|
|
2294
|
+
*/
|
|
2295
|
+
unmountWhenCulled?: boolean;
|
|
2296
|
+
}
|
|
2263
2297
|
interface DrCropInfo<T extends DrShape> {
|
|
2264
2298
|
handle: SelectionHandle;
|
|
2265
2299
|
change: Vec;
|
|
@@ -3032,6 +3066,12 @@ interface DrawOptions {
|
|
|
3032
3066
|
* Defaults to 500 shapes.
|
|
3033
3067
|
*/
|
|
3034
3068
|
readonly debouncedZoomThreshold: number;
|
|
3069
|
+
/**
|
|
3070
|
+
* Zoom level below which shapes that implement {@link ShapeUtil.getLodStyle} are painted into
|
|
3071
|
+
* one canvas instead of a DOM node each. Shapes whose on-screen size is still large stay in
|
|
3072
|
+
* the DOM. Defaults to 0.35 so a normal working zoom keeps real text and strokes.
|
|
3073
|
+
*/
|
|
3074
|
+
readonly lodZoom: number;
|
|
3035
3075
|
/**
|
|
3036
3076
|
* Whether to allow spacebar panning. When true, the spacebar will pan the camera when held down.
|
|
3037
3077
|
* When false, the spacebar will not pan the camera.
|
|
@@ -3231,6 +3271,7 @@ declare const defaultDrawOptions: {
|
|
|
3231
3271
|
readonly nonce: undefined;
|
|
3232
3272
|
readonly debouncedZoom: true;
|
|
3233
3273
|
readonly debouncedZoomThreshold: 500;
|
|
3274
|
+
readonly lodZoom: 0.35;
|
|
3234
3275
|
readonly spacebarPanning: true;
|
|
3235
3276
|
readonly rightClickPanning: true;
|
|
3236
3277
|
readonly zoomToFitPadding: 128;
|
|
@@ -10881,4 +10922,4 @@ declare function uniq<T>(array: {
|
|
|
10881
10922
|
readonly [n: number]: T;
|
|
10882
10923
|
} | null | undefined): T[];
|
|
10883
10924
|
|
|
10884
|
-
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 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, 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 };
|
|
10925
|
+
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, 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
|
@@ -4457,6 +4457,434 @@ function drawGeometryStroke(ctx, geometry) {
|
|
|
4457
4457
|
if (geometry.isClosed) ctx.closePath();
|
|
4458
4458
|
ctx.stroke();
|
|
4459
4459
|
}
|
|
4460
|
+
|
|
4461
|
+
// src/lib/editor/lod/shapeRenderMode.ts
|
|
4462
|
+
var LOD_SMALL_SCREEN_PX = 28;
|
|
4463
|
+
var LOD_CULL_MARGIN = 0.75;
|
|
4464
|
+
function getShapeRenderMode(input) {
|
|
4465
|
+
if (!input.hasLodStyle || input.interactive) return "dom";
|
|
4466
|
+
if (input.outsideViewport) return "unmounted";
|
|
4467
|
+
if (input.unmountWhenCulled) return "dom";
|
|
4468
|
+
const maxSide = Math.max(input.pageWidth, input.pageHeight) * input.zoom;
|
|
4469
|
+
if (input.zoom < input.lodZoom || maxSide < LOD_SMALL_SCREEN_PX) return "canvas";
|
|
4470
|
+
return "dom";
|
|
4471
|
+
}
|
|
4472
|
+
var MAX_LOD_POINTS = 48;
|
|
4473
|
+
var meshCache = /* @__PURE__ */ new WeakMap();
|
|
4474
|
+
var styleCache = /* @__PURE__ */ new WeakMap();
|
|
4475
|
+
var retainedOutside = /* @__PURE__ */ new WeakMap();
|
|
4476
|
+
function lodStyleFor(editor, shape) {
|
|
4477
|
+
const theme = editor.getCurrentTheme();
|
|
4478
|
+
const colorMode = editor.getColorMode();
|
|
4479
|
+
const cached = styleCache.get(shape);
|
|
4480
|
+
if (cached && cached.theme === theme && cached.colorMode === colorMode) return cached.style;
|
|
4481
|
+
let style = null;
|
|
4482
|
+
try {
|
|
4483
|
+
style = editor.getShapeUtil(shape).getLodStyle(shape);
|
|
4484
|
+
} catch {
|
|
4485
|
+
style = null;
|
|
4486
|
+
}
|
|
4487
|
+
styleCache.set(shape, { theme, colorMode, style });
|
|
4488
|
+
return style;
|
|
4489
|
+
}
|
|
4490
|
+
function decimate(vertices) {
|
|
4491
|
+
const count = vertices.length;
|
|
4492
|
+
if (count === 0) return new Float32Array(0);
|
|
4493
|
+
const step = count <= MAX_LOD_POINTS ? 1 : Math.ceil((count - 1) / (MAX_LOD_POINTS - 1));
|
|
4494
|
+
const indexes = [];
|
|
4495
|
+
for (let i = 0; i < count - 1; i += step) indexes.push(i);
|
|
4496
|
+
indexes.push(count - 1);
|
|
4497
|
+
const points = new Float32Array(indexes.length * 2);
|
|
4498
|
+
for (let i = 0; i < indexes.length; i++) {
|
|
4499
|
+
const vertex = vertices[indexes[i]];
|
|
4500
|
+
points[i * 2] = vertex.x;
|
|
4501
|
+
points[i * 2 + 1] = vertex.y;
|
|
4502
|
+
}
|
|
4503
|
+
return points;
|
|
4504
|
+
}
|
|
4505
|
+
function meshFor(editor, shape, style) {
|
|
4506
|
+
const cached = meshCache.get(shape);
|
|
4507
|
+
if (cached && cached.style === style) return cached.mesh;
|
|
4508
|
+
let mesh = null;
|
|
4509
|
+
try {
|
|
4510
|
+
const geometry = editor.getShapeGeometry(shape);
|
|
4511
|
+
const bounds = geometry.bounds;
|
|
4512
|
+
const stroke = style.stroke;
|
|
4513
|
+
const needsPath = Boolean(stroke) || Boolean(style.fill) && geometry.vertices.length > 1;
|
|
4514
|
+
const fillOnly = Boolean(style.fill) && !stroke;
|
|
4515
|
+
mesh = {
|
|
4516
|
+
fill: style.fill,
|
|
4517
|
+
stroke,
|
|
4518
|
+
strokeWidth: style.strokeWidth,
|
|
4519
|
+
opacity: (shape.opacity ?? 1) * (style.opacity ?? 1),
|
|
4520
|
+
x: bounds.x,
|
|
4521
|
+
y: bounds.y,
|
|
4522
|
+
w: bounds.w,
|
|
4523
|
+
h: bounds.h,
|
|
4524
|
+
points: fillOnly || !needsPath ? null : decimate(geometry.vertices),
|
|
4525
|
+
closed: geometry.isClosed,
|
|
4526
|
+
label: style.label?.trim() ? style.label : null,
|
|
4527
|
+
labelColor: style.labelColor ?? null,
|
|
4528
|
+
labelSize: style.labelSize ?? 0
|
|
4529
|
+
};
|
|
4530
|
+
} catch {
|
|
4531
|
+
mesh = null;
|
|
4532
|
+
}
|
|
4533
|
+
meshCache.set(shape, { style, mesh });
|
|
4534
|
+
return mesh;
|
|
4535
|
+
}
|
|
4536
|
+
function transformedBounds(matrix, mesh) {
|
|
4537
|
+
const x0 = mesh.x;
|
|
4538
|
+
const y0 = mesh.y;
|
|
4539
|
+
const x1 = mesh.x + mesh.w;
|
|
4540
|
+
const y1 = mesh.y + mesh.h;
|
|
4541
|
+
return Box.FromPoints([
|
|
4542
|
+
matrix.applyToPoint({ x: x0, y: y0 }),
|
|
4543
|
+
matrix.applyToPoint({ x: x1, y: y0 }),
|
|
4544
|
+
matrix.applyToPoint({ x: x1, y: y1 }),
|
|
4545
|
+
matrix.applyToPoint({ x: x0, y: y1 })
|
|
4546
|
+
]);
|
|
4547
|
+
}
|
|
4548
|
+
function isInteractive(editor, shape, selected, editingId) {
|
|
4549
|
+
let current = shape;
|
|
4550
|
+
for (let depth = 0; depth < 32 && current; depth++) {
|
|
4551
|
+
if (current.id === editingId || selected.has(current.id)) return true;
|
|
4552
|
+
const parentId = current.parentId;
|
|
4553
|
+
if (!editor.store.has(parentId)) return false;
|
|
4554
|
+
const parent = editor.store.unsafeGetWithoutCapture(parentId);
|
|
4555
|
+
if (!parent || parent.typeName !== "shape") return false;
|
|
4556
|
+
current = parent;
|
|
4557
|
+
}
|
|
4558
|
+
return false;
|
|
4559
|
+
}
|
|
4560
|
+
function readFrame(editor) {
|
|
4561
|
+
const viewport = editor.getViewportPageBounds();
|
|
4562
|
+
const pad = Math.max(viewport.w, viewport.h) * LOD_CULL_MARGIN;
|
|
4563
|
+
const selectedIds = editor.getSelectedShapeIds();
|
|
4564
|
+
return {
|
|
4565
|
+
zoom: editor.getZoomLevel(),
|
|
4566
|
+
lodZoom: editor.options.lodZoom,
|
|
4567
|
+
debug: debugFlags.debugSvg.get() && editor.getInstanceState().isDebugMode,
|
|
4568
|
+
moving: editor.getCameraState() === "moving",
|
|
4569
|
+
selectedIds,
|
|
4570
|
+
selected: new Set(selectedIds),
|
|
4571
|
+
editingId: editor.getEditingShapeId(),
|
|
4572
|
+
viewport,
|
|
4573
|
+
expanded: viewport.clone().expandBy(pad)
|
|
4574
|
+
};
|
|
4575
|
+
}
|
|
4576
|
+
function outsideSet(editor, frame, shapes) {
|
|
4577
|
+
const live = /* @__PURE__ */ new Set();
|
|
4578
|
+
if (!frame.debug) {
|
|
4579
|
+
for (const shape of shapes) {
|
|
4580
|
+
if (editor.isShapeHidden(shape)) continue;
|
|
4581
|
+
const style = lodStyleFor(editor, shape);
|
|
4582
|
+
if (!style) continue;
|
|
4583
|
+
if (style.unmountWhenCulled) {
|
|
4584
|
+
const bounds = editor.getShapePageBounds(shape);
|
|
4585
|
+
if (bounds && !frame.expanded.collides(bounds)) live.add(shape.id);
|
|
4586
|
+
continue;
|
|
4587
|
+
}
|
|
4588
|
+
const mesh = meshFor(editor, shape, style);
|
|
4589
|
+
if (!mesh) continue;
|
|
4590
|
+
const matrix = editor.getShapePageTransform(shape);
|
|
4591
|
+
if (!frame.expanded.collides(transformedBounds(matrix, mesh))) live.add(shape.id);
|
|
4592
|
+
}
|
|
4593
|
+
}
|
|
4594
|
+
if (!frame.moving) {
|
|
4595
|
+
retainedOutside.set(editor, live);
|
|
4596
|
+
return live;
|
|
4597
|
+
}
|
|
4598
|
+
const retained = retainedOutside.get(editor);
|
|
4599
|
+
if (!retained) {
|
|
4600
|
+
retainedOutside.set(editor, live);
|
|
4601
|
+
return live;
|
|
4602
|
+
}
|
|
4603
|
+
for (const id of retained) {
|
|
4604
|
+
if (!live.has(id)) retained.delete(id);
|
|
4605
|
+
}
|
|
4606
|
+
return retained;
|
|
4607
|
+
}
|
|
4608
|
+
function ownRenderMode(editor, shape, frame, outsideViewport) {
|
|
4609
|
+
if (frame.debug || editor.isShapeHidden(shape)) return "dom";
|
|
4610
|
+
const style = lodStyleFor(editor, shape);
|
|
4611
|
+
const mesh = style && !style.unmountWhenCulled ? meshFor(editor, shape, style) : null;
|
|
4612
|
+
return getShapeRenderMode({
|
|
4613
|
+
zoom: frame.zoom,
|
|
4614
|
+
lodZoom: frame.lodZoom,
|
|
4615
|
+
hasLodStyle: Boolean(style && (mesh || style.unmountWhenCulled)),
|
|
4616
|
+
interactive: isInteractive(editor, shape, frame.selected, frame.editingId),
|
|
4617
|
+
outsideViewport,
|
|
4618
|
+
unmountWhenCulled: Boolean(style?.unmountWhenCulled),
|
|
4619
|
+
pageWidth: mesh?.w ?? 0,
|
|
4620
|
+
pageHeight: mesh?.h ?? 0
|
|
4621
|
+
});
|
|
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
|
+
}
|
|
4644
|
+
function trace(ctx, points) {
|
|
4645
|
+
ctx.beginPath();
|
|
4646
|
+
ctx.moveTo(points[0], points[1]);
|
|
4647
|
+
for (let i = 2; i < points.length; i += 2) {
|
|
4648
|
+
ctx.lineTo(points[i], points[i + 1]);
|
|
4649
|
+
}
|
|
4650
|
+
}
|
|
4651
|
+
function paintShape(ctx, camera, dpr, matrix, mesh, padPx = 0) {
|
|
4652
|
+
if (mesh.opacity <= 0) return;
|
|
4653
|
+
const z = camera.z || 1;
|
|
4654
|
+
ctx.globalAlpha = mesh.opacity;
|
|
4655
|
+
ctx.setTransform(
|
|
4656
|
+
dpr * z * matrix.a,
|
|
4657
|
+
dpr * z * matrix.b,
|
|
4658
|
+
dpr * z * matrix.c,
|
|
4659
|
+
dpr * z * matrix.d,
|
|
4660
|
+
dpr * z * (matrix.e + camera.x) + padPx,
|
|
4661
|
+
dpr * z * (matrix.f + camera.y) + padPx
|
|
4662
|
+
);
|
|
4663
|
+
if (mesh.fill && !mesh.points) {
|
|
4664
|
+
ctx.fillStyle = mesh.fill;
|
|
4665
|
+
ctx.fillRect(mesh.x, mesh.y, Math.max(mesh.w, 1), Math.max(mesh.h, 1));
|
|
4666
|
+
} else if (mesh.points && mesh.points.length >= 4) {
|
|
4667
|
+
if (mesh.fill) {
|
|
4668
|
+
ctx.fillStyle = mesh.fill;
|
|
4669
|
+
trace(ctx, mesh.points);
|
|
4670
|
+
if (mesh.closed) ctx.closePath();
|
|
4671
|
+
ctx.fill();
|
|
4672
|
+
}
|
|
4673
|
+
if (mesh.stroke) {
|
|
4674
|
+
ctx.strokeStyle = mesh.stroke;
|
|
4675
|
+
ctx.lineWidth = Math.max(mesh.strokeWidth, 1 / z);
|
|
4676
|
+
ctx.lineCap = "round";
|
|
4677
|
+
ctx.lineJoin = "round";
|
|
4678
|
+
trace(ctx, mesh.points);
|
|
4679
|
+
if (mesh.closed) ctx.closePath();
|
|
4680
|
+
ctx.stroke();
|
|
4681
|
+
}
|
|
4682
|
+
} else if (mesh.fill) {
|
|
4683
|
+
ctx.fillStyle = mesh.fill;
|
|
4684
|
+
ctx.beginPath();
|
|
4685
|
+
ctx.arc(
|
|
4686
|
+
mesh.x + mesh.w / 2,
|
|
4687
|
+
mesh.y + mesh.h / 2,
|
|
4688
|
+
Math.max(mesh.w, mesh.h, mesh.strokeWidth) / 2,
|
|
4689
|
+
0,
|
|
4690
|
+
Math.PI * 2
|
|
4691
|
+
);
|
|
4692
|
+
ctx.fill();
|
|
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();
|
|
4729
|
+
}
|
|
4730
|
+
var LOD_OVERSCAN_SCREEN_PX = 192;
|
|
4731
|
+
var LOD_BITMAP_MAX_PX = 8192;
|
|
4732
|
+
function lodBitmapCovers(bitmap, camera, viewport, dpr, shapes, frame, theme, colorMode) {
|
|
4733
|
+
if (bitmap.zoom !== camera.z || bitmap.dpr !== dpr) return false;
|
|
4734
|
+
if (bitmap.shapes !== shapes || bitmap.selectedIds !== frame.selectedIds) return false;
|
|
4735
|
+
if (bitmap.editingId !== frame.editingId || bitmap.theme !== theme || bitmap.colorMode !== colorMode) {
|
|
4736
|
+
return false;
|
|
4737
|
+
}
|
|
4738
|
+
if (Math.abs(bitmap.viewW - viewport.w) > 0.5 || Math.abs(bitmap.viewH - viewport.h) > 0.5) {
|
|
4739
|
+
return false;
|
|
4740
|
+
}
|
|
4741
|
+
const inset = 8 / (camera.z || 1);
|
|
4742
|
+
const covered = new Box(
|
|
4743
|
+
-bitmap.cameraX - bitmap.pad + inset,
|
|
4744
|
+
-bitmap.cameraY - bitmap.pad + inset,
|
|
4745
|
+
bitmap.viewW + bitmap.pad * 2 - inset * 2,
|
|
4746
|
+
bitmap.viewH + bitmap.pad * 2 - inset * 2
|
|
4747
|
+
);
|
|
4748
|
+
return covered.contains(viewport);
|
|
4749
|
+
}
|
|
4750
|
+
function blitLodBitmap(ctx, width, height, bitmap, camera) {
|
|
4751
|
+
const z = camera.z || 1;
|
|
4752
|
+
const padPx = bitmap.pad * z * bitmap.dpr;
|
|
4753
|
+
ctx.globalAlpha = 1;
|
|
4754
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
4755
|
+
ctx.clearRect(0, 0, width, height);
|
|
4756
|
+
ctx.drawImage(
|
|
4757
|
+
bitmap.canvas,
|
|
4758
|
+
(camera.x - bitmap.cameraX) * z * bitmap.dpr - padPx,
|
|
4759
|
+
(camera.y - bitmap.cameraY) * z * bitmap.dpr - padPx
|
|
4760
|
+
);
|
|
4761
|
+
}
|
|
4762
|
+
function paintVisibleLodShapes(ctx, editor, camera, dpr, shapes, frame, paintBounds, padPx) {
|
|
4763
|
+
for (const shape of shapes) {
|
|
4764
|
+
if (editor.isShapeHidden(shape)) continue;
|
|
4765
|
+
const style = lodStyleFor(editor, shape);
|
|
4766
|
+
if (!style || style.unmountWhenCulled) continue;
|
|
4767
|
+
const mesh = meshFor(editor, shape, style);
|
|
4768
|
+
if (!mesh) continue;
|
|
4769
|
+
if (ownRenderMode(editor, shape, frame, false) !== "canvas") continue;
|
|
4770
|
+
if (coveredByDomBackground(editor, shape, frame)) continue;
|
|
4771
|
+
if (frame.debug) continue;
|
|
4772
|
+
const matrix = editor.getShapePageTransform(shape);
|
|
4773
|
+
if (!paintBounds.collides(transformedBounds(matrix, mesh))) continue;
|
|
4774
|
+
paintShape(ctx, camera, dpr, matrix, mesh, padPx);
|
|
4775
|
+
}
|
|
4776
|
+
}
|
|
4777
|
+
function useMountedRenderingShapes() {
|
|
4778
|
+
const editor = useEditor();
|
|
4779
|
+
const mountedRef = useRef([]);
|
|
4780
|
+
return useValue(
|
|
4781
|
+
"mounted rendering shapes",
|
|
4782
|
+
() => {
|
|
4783
|
+
const rendering = editor.getRenderingShapes();
|
|
4784
|
+
const shapes = editor.getCurrentPageShapesSorted();
|
|
4785
|
+
editor.getCurrentTheme();
|
|
4786
|
+
editor.getColorMode();
|
|
4787
|
+
const frame = readFrame(editor);
|
|
4788
|
+
const outside = unsafe__withoutCapture(() => outsideSet(editor, frame, shapes));
|
|
4789
|
+
const next = [];
|
|
4790
|
+
for (const renderingShape of rendering) {
|
|
4791
|
+
const mode = unsafe__withoutCapture(
|
|
4792
|
+
() => modeFor(editor, renderingShape.shape, frame, outside)
|
|
4793
|
+
);
|
|
4794
|
+
if (mode === "dom") next.push(renderingShape);
|
|
4795
|
+
}
|
|
4796
|
+
const prev = mountedRef.current;
|
|
4797
|
+
if (prev.length === next.length && prev.every((entry, index) => {
|
|
4798
|
+
const other = next[index];
|
|
4799
|
+
return entry.id === other.id && entry.shape === other.shape && entry.index === other.index && entry.backgroundIndex === other.backgroundIndex && entry.opacity === other.opacity;
|
|
4800
|
+
})) {
|
|
4801
|
+
return prev;
|
|
4802
|
+
}
|
|
4803
|
+
mountedRef.current = next;
|
|
4804
|
+
return next;
|
|
4805
|
+
},
|
|
4806
|
+
[editor]
|
|
4807
|
+
);
|
|
4808
|
+
}
|
|
4809
|
+
function LodCanvas() {
|
|
4810
|
+
const editor = useEditor();
|
|
4811
|
+
const canvasRef = useRef(null);
|
|
4812
|
+
const bitmapRef = useRef(null);
|
|
4813
|
+
useQuickReactor(
|
|
4814
|
+
"lod canvas",
|
|
4815
|
+
() => {
|
|
4816
|
+
const canvas = canvasRef.current;
|
|
4817
|
+
if (!canvas) return;
|
|
4818
|
+
const camera = editor.getCamera();
|
|
4819
|
+
const screen = editor.getViewportScreenBounds();
|
|
4820
|
+
const shapes = editor.getCurrentPageShapesSorted();
|
|
4821
|
+
const theme = editor.getCurrentTheme();
|
|
4822
|
+
const colorMode = editor.getColorMode();
|
|
4823
|
+
const frame = readFrame(editor);
|
|
4824
|
+
const dpr = window.devicePixelRatio || 1;
|
|
4825
|
+
const width = Math.max(1, Math.round((screen.w || canvas.clientWidth) * dpr));
|
|
4826
|
+
const height = Math.max(1, Math.round((screen.h || canvas.clientHeight) * dpr));
|
|
4827
|
+
if (canvas.width !== width || canvas.height !== height) {
|
|
4828
|
+
canvas.width = width;
|
|
4829
|
+
canvas.height = height;
|
|
4830
|
+
}
|
|
4831
|
+
const ctx = canvas.getContext("2d");
|
|
4832
|
+
if (!ctx) return;
|
|
4833
|
+
unsafe__withoutCapture(() => {
|
|
4834
|
+
const cached = bitmapRef.current;
|
|
4835
|
+
if (!frame.debug && cached && lodBitmapCovers(cached, camera, frame.viewport, dpr, shapes, frame, theme, colorMode)) {
|
|
4836
|
+
blitLodBitmap(ctx, width, height, cached, camera);
|
|
4837
|
+
return;
|
|
4838
|
+
}
|
|
4839
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
4840
|
+
ctx.clearRect(0, 0, width, height);
|
|
4841
|
+
if (frame.debug) {
|
|
4842
|
+
bitmapRef.current = null;
|
|
4843
|
+
return;
|
|
4844
|
+
}
|
|
4845
|
+
const pad = LOD_OVERSCAN_SCREEN_PX / (camera.z || 1);
|
|
4846
|
+
const paintBounds = frame.viewport.clone().expandBy(pad);
|
|
4847
|
+
const cacheW = Math.round((frame.viewport.w + pad * 2) * (camera.z || 1) * dpr);
|
|
4848
|
+
const cacheH = Math.round((frame.viewport.h + pad * 2) * (camera.z || 1) * dpr);
|
|
4849
|
+
const canCache = cacheW > 0 && cacheH > 0 && cacheW <= LOD_BITMAP_MAX_PX && cacheH <= LOD_BITMAP_MAX_PX;
|
|
4850
|
+
const target = canCache ? cached?.canvas ?? document.createElement("canvas") : null;
|
|
4851
|
+
if (target && (target.width !== cacheW || target.height !== cacheH)) {
|
|
4852
|
+
target.width = cacheW;
|
|
4853
|
+
target.height = cacheH;
|
|
4854
|
+
}
|
|
4855
|
+
const padPx = canCache ? pad * (camera.z || 1) * dpr : 0;
|
|
4856
|
+
const paintCtx = target?.getContext("2d") ?? ctx;
|
|
4857
|
+
if (target) {
|
|
4858
|
+
paintCtx.globalAlpha = 1;
|
|
4859
|
+
paintCtx.setTransform(1, 0, 0, 1, 0, 0);
|
|
4860
|
+
paintCtx.clearRect(0, 0, cacheW, cacheH);
|
|
4861
|
+
}
|
|
4862
|
+
paintVisibleLodShapes(paintCtx, editor, camera, dpr, shapes, frame, paintBounds, padPx);
|
|
4863
|
+
if (target) {
|
|
4864
|
+
const bitmap = {
|
|
4865
|
+
zoom: camera.z,
|
|
4866
|
+
dpr,
|
|
4867
|
+
cameraX: camera.x,
|
|
4868
|
+
cameraY: camera.y,
|
|
4869
|
+
pad,
|
|
4870
|
+
viewW: frame.viewport.w,
|
|
4871
|
+
viewH: frame.viewport.h,
|
|
4872
|
+
shapes,
|
|
4873
|
+
selectedIds: frame.selectedIds,
|
|
4874
|
+
editingId: frame.editingId,
|
|
4875
|
+
theme,
|
|
4876
|
+
colorMode,
|
|
4877
|
+
canvas: target
|
|
4878
|
+
};
|
|
4879
|
+
bitmapRef.current = bitmap;
|
|
4880
|
+
blitLodBitmap(ctx, width, height, bitmap, camera);
|
|
4881
|
+
}
|
|
4882
|
+
});
|
|
4883
|
+
},
|
|
4884
|
+
[editor]
|
|
4885
|
+
);
|
|
4886
|
+
return /* @__PURE__ */ jsx("canvas", { ref: canvasRef, className: "dr-lod-canvas", "aria-hidden": "true" });
|
|
4887
|
+
}
|
|
4460
4888
|
function DefaultCanvas({ className }) {
|
|
4461
4889
|
const editor = useEditor();
|
|
4462
4890
|
const { Background, SvgDefs } = useEditorComponents();
|
|
@@ -4559,6 +4987,7 @@ function DefaultCanvas({ className }) {
|
|
|
4559
4987
|
] }) }),
|
|
4560
4988
|
Background && /* @__PURE__ */ jsx("div", { className: "dr-background__wrapper", children: /* @__PURE__ */ jsx(BackgroundWrapper, {}) }),
|
|
4561
4989
|
isGridMode && backgroundType === "none" && Grid && /* @__PURE__ */ jsx(GridWrapper, {}),
|
|
4990
|
+
hideShapes ? null : /* @__PURE__ */ jsx(LodCanvas, {}),
|
|
4562
4991
|
/* @__PURE__ */ jsxs("div", { ref: rHtmlLayer, className: "dr-html-layer dr-shapes", draggable: false, children: [
|
|
4563
4992
|
/* @__PURE__ */ jsx(OnTheCanvasWrapper, {}),
|
|
4564
4993
|
hideShapes ? null : /* @__PURE__ */ jsx(ShapesLayer, { canvasRef: rCanvas })
|
|
@@ -4605,9 +5034,9 @@ function BackgroundWrapper() {
|
|
|
4605
5034
|
return /* @__PURE__ */ jsx(Background, { x, y, z });
|
|
4606
5035
|
}
|
|
4607
5036
|
function ShapesLayer({ canvasRef }) {
|
|
4608
|
-
|
|
5037
|
+
useEditor();
|
|
4609
5038
|
const debugSvg = useValue("debug svg", () => debugFlags.debugSvg.get(), [debugFlags]);
|
|
4610
|
-
const renderingShapes =
|
|
5039
|
+
const renderingShapes = useMountedRenderingShapes();
|
|
4611
5040
|
return /* @__PURE__ */ jsxs(ShapeCullingProvider, { children: [
|
|
4612
5041
|
renderingShapes.map(
|
|
4613
5042
|
(result) => debugSvg ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
@@ -6025,6 +6454,18 @@ var ShapeUtil = class {
|
|
|
6025
6454
|
canCull(shape) {
|
|
6026
6455
|
return true;
|
|
6027
6456
|
}
|
|
6457
|
+
/**
|
|
6458
|
+
* Cheap canvas stand-in used when this shape is zoomed out or far outside the viewport.
|
|
6459
|
+
* Return null to keep the regular DOM node (media, in-progress strokes, anything stateful).
|
|
6460
|
+
* Selected and edited shapes always stay in the DOM.
|
|
6461
|
+
*
|
|
6462
|
+
* Coordinates consumed by the canvas are the shape's local geometry.
|
|
6463
|
+
*
|
|
6464
|
+
* @param shape - The shape.
|
|
6465
|
+
*/
|
|
6466
|
+
getLodStyle(_shape) {
|
|
6467
|
+
return null;
|
|
6468
|
+
}
|
|
6028
6469
|
/**
|
|
6029
6470
|
* Does this shape provide a background for its children? If this is true,
|
|
6030
6471
|
* then any children with a `renderBackground` method will have their
|
|
@@ -9110,6 +9551,7 @@ var defaultDrawOptions = {
|
|
|
9110
9551
|
nonce: void 0,
|
|
9111
9552
|
debouncedZoom: true,
|
|
9112
9553
|
debouncedZoomThreshold: 500,
|
|
9554
|
+
lodZoom: 0.35,
|
|
9113
9555
|
spacebarPanning: true,
|
|
9114
9556
|
rightClickPanning: true,
|
|
9115
9557
|
zoomToFitPadding: 128,
|
|
@@ -25869,7 +26311,7 @@ function getFontsFromRichText(editor, richText, initialState2) {
|
|
|
25869
26311
|
// src/index.ts
|
|
25870
26312
|
registerDrawLibraryVersion(
|
|
25871
26313
|
"@ibodr/editor",
|
|
25872
|
-
"0.2.
|
|
26314
|
+
"0.2.10",
|
|
25873
26315
|
"esm"
|
|
25874
26316
|
);
|
|
25875
26317
|
/*!
|