@yuzhouu/canvas-kit 0.1.2 → 0.1.4
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/README.md +80 -78
- package/_vendor/canvas-core/bindings/bindingUtil.d.ts +45 -0
- package/_vendor/canvas-core/bindings/bindingUtilRegistry.d.ts +8 -0
- package/_vendor/canvas-core/bindings/terminalBinding.d.ts +28 -0
- package/_vendor/canvas-core/editor/camera.d.ts +3 -0
- package/_vendor/canvas-core/editor/clipboard.d.ts +43 -0
- package/_vendor/canvas-core/editor/commands.d.ts +131 -0
- package/_vendor/canvas-core/editor/createEditorWithPlugins.d.ts +6 -0
- package/_vendor/canvas-core/editor/edgeScroll.d.ts +5 -0
- package/_vendor/canvas-core/editor/editor.d.ts +559 -0
- package/_vendor/canvas-core/editor/editorComputedHelpers.d.ts +21 -0
- package/_vendor/canvas-core/editor/editorSelectionTransforms.d.ts +6 -0
- package/_vendor/canvas-core/editor/events.d.ts +71 -0
- package/_vendor/canvas-core/editor/historyManager.d.ts +18 -0
- package/_vendor/canvas-core/editor/index.d.ts +11 -0
- package/_vendor/canvas-core/editor/interactions.d.ts +51 -0
- package/_vendor/canvas-core/editor/internal.d.ts +7 -0
- package/_vendor/canvas-core/editor/managers/bindingManager.d.ts +27 -0
- package/_vendor/canvas-core/editor/managers/cameraManager.d.ts +39 -0
- package/_vendor/canvas-core/editor/managers/clipboardManager.d.ts +14 -0
- package/_vendor/canvas-core/editor/managers/documentSnapshotManager.d.ts +28 -0
- package/_vendor/canvas-core/editor/managers/inputsManager.d.ts +44 -0
- package/_vendor/canvas-core/editor/managers/interactionTransientManager.d.ts +55 -0
- package/_vendor/canvas-core/editor/managers/queryManager.d.ts +77 -0
- package/_vendor/canvas-core/editor/managers/queryState.d.ts +18 -0
- package/_vendor/canvas-core/editor/managers/renderWindowManager.d.ts +25 -0
- package/_vendor/canvas-core/editor/managers/selectionGeometry.d.ts +28 -0
- package/_vendor/canvas-core/editor/managers/selectionLayoutManager.d.ts +29 -0
- package/_vendor/canvas-core/editor/managers/selectionManager.d.ts +21 -0
- package/_vendor/canvas-core/editor/managers/selectionOverlayManager.d.ts +24 -0
- package/_vendor/canvas-core/editor/managers/shapeEditingManager.d.ts +29 -0
- package/_vendor/canvas-core/editor/managers/shapeGeometryManager.d.ts +42 -0
- package/_vendor/canvas-core/editor/managers/shapeHierarchyManager.d.ts +55 -0
- package/_vendor/canvas-core/editor/managers/shapeOrder.d.ts +14 -0
- package/_vendor/canvas-core/editor/managers/shapeReparenting.d.ts +6 -0
- package/_vendor/canvas-core/editor/managers/shortcutManager.d.ts +56 -0
- package/_vendor/canvas-core/editor/managers/sideEffectManager.d.ts +23 -0
- package/_vendor/canvas-core/editor/managers/snapCalculations.d.ts +40 -0
- package/_vendor/canvas-core/editor/managers/snapGeometry.d.ts +26 -0
- package/_vendor/canvas-core/editor/managers/snapIndicators.d.ts +22 -0
- package/_vendor/canvas-core/editor/managers/snapManager.d.ts +29 -0
- package/_vendor/canvas-core/editor/managers/snapSnapshotBuilder.d.ts +22 -0
- package/_vendor/canvas-core/editor/managers/snapTypes.d.ts +98 -0
- package/_vendor/canvas-core/editor/managers/spatialIndexManager.d.ts +30 -0
- package/_vendor/canvas-core/editor/managers/toolManager.d.ts +24 -0
- package/_vendor/canvas-core/editor/queries/shapeTransforms.d.ts +27 -0
- package/_vendor/canvas-core/editor/renderWindow.d.ts +30 -0
- package/_vendor/canvas-core/editor/resizeGeometry.d.ts +97 -0
- package/_vendor/canvas-core/editor/selection.d.ts +231 -0
- package/_vendor/canvas-core/editor/selectionHandleInteractions.d.ts +11 -0
- package/_vendor/canvas-core/editor/selectionOverlay.d.ts +33 -0
- package/_vendor/canvas-core/editor/stateNode.d.ts +31 -0
- package/_vendor/canvas-core/exports/integrity.d.ts +32 -0
- package/_vendor/canvas-core/exports/svg.d.ts +52 -0
- package/_vendor/canvas-core/geometry/box.d.ts +19 -0
- package/_vendor/canvas-core/geometry/ellipse2d.d.ts +16 -0
- package/_vendor/canvas-core/geometry/geometry2d.d.ts +15 -0
- package/_vendor/canvas-core/geometry/index.d.ts +8 -0
- package/_vendor/canvas-core/geometry/mat.d.ts +28 -0
- package/_vendor/canvas-core/geometry/polyline2d.d.ts +14 -0
- package/_vendor/canvas-core/geometry/rectangle2d.d.ts +16 -0
- package/_vendor/canvas-core/geometry/segments.d.ts +5 -0
- package/_vendor/canvas-core/geometry/vec.d.ts +37 -0
- package/_vendor/canvas-core/index.d.ts +59 -0
- package/_vendor/canvas-core/plugins/editorPlugin.d.ts +28 -0
- package/_vendor/canvas-core/plugins/index.d.ts +1 -0
- package/_vendor/canvas-core/reactivity.d.ts +4 -0
- package/_vendor/canvas-core/schema/records.d.ts +112 -0
- package/_vendor/canvas-core/schema/snapshotSupport.d.ts +43 -0
- package/_vendor/canvas-core/schema/snapshots.d.ts +31 -0
- package/_vendor/canvas-core/shapes/capabilities.d.ts +25 -0
- package/_vendor/canvas-core/shapes/colors.d.ts +26 -0
- package/_vendor/canvas-core/shapes/shapeUtil.d.ts +146 -0
- package/_vendor/canvas-core/shapes/shapeUtilRegistry.d.ts +9 -0
- package/_vendor/canvas-core/shapes/types.d.ts +2 -0
- package/_vendor/canvas-core/surfaces/actions.d.ts +35 -0
- package/_vendor/canvas-core/surfaces/contextMenu.d.ts +64 -0
- package/_vendor/canvas-core/surfaces/toolbar.d.ts +96 -0
- package/_vendor/canvas-core/tools/hand/handTool.d.ts +5 -0
- package/_vendor/canvas-core/tools/index.d.ts +2 -0
- package/_vendor/canvas-core/tools/select/selectContainment.d.ts +12 -0
- package/_vendor/canvas-core/tools/select/selectTool.d.ts +5 -0
- package/_vendor/canvas-core/tools/select/selectToolHelpers.d.ts +161 -0
- package/_vendor/canvas-core/tools/select/states/brushingState.d.ts +19 -0
- package/_vendor/canvas-core/tools/select/states/draggingSelectionHandleInteractionState.d.ts +15 -0
- package/_vendor/canvas-core/tools/select/states/idleState.d.ts +8 -0
- package/_vendor/canvas-core/tools/select/states/index.d.ts +11 -0
- package/_vendor/canvas-core/tools/select/states/pointingCanvasState.d.ts +11 -0
- package/_vendor/canvas-core/tools/select/states/pointingResizeHandleState.d.ts +10 -0
- package/_vendor/canvas-core/tools/select/states/pointingRotateHandleState.d.ts +10 -0
- package/_vendor/canvas-core/tools/select/states/pointingSelectionHandleInteractionState.d.ts +10 -0
- package/_vendor/canvas-core/tools/select/states/pointingShapeState.d.ts +12 -0
- package/_vendor/canvas-core/tools/select/states/resizingState.d.ts +16 -0
- package/_vendor/canvas-core/tools/select/states/rotatingState.d.ts +14 -0
- package/_vendor/canvas-core/tools/select/states/selectStateNode.d.ts +60 -0
- package/_vendor/canvas-core/tools/select/states/translatingState.d.ts +17 -0
- package/_vendor/canvas-react/components/CanvasView.d.ts +14 -0
- package/_vendor/canvas-react/components/OverlayLayer.d.ts +1 -0
- package/_vendor/canvas-react/components/PageSpace.d.ts +6 -0
- package/_vendor/canvas-react/components/ShapeLayer.d.ts +4 -0
- package/_vendor/canvas-react/components/index.d.ts +2 -0
- package/_vendor/canvas-react/components/overlays/BindingGuide.d.ts +24 -0
- package/_vendor/canvas-react/components/overlays/BindingPreviewOverlay.d.ts +1 -0
- package/_vendor/canvas-react/components/overlays/BrushBoxOverlay.d.ts +1 -0
- package/_vendor/canvas-react/components/overlays/OverlaySvgRoot.d.ts +1 -0
- package/_vendor/canvas-react/components/overlays/SelectionFrameOverlay.d.ts +1 -0
- package/_vendor/canvas-react/components/overlays/SelectionHandlesOverlay.d.ts +1 -0
- package/_vendor/canvas-react/components/overlays/SelectionOverlaySvg.d.ts +1 -0
- package/_vendor/canvas-react/components/overlays/SelectionPathOverlay.d.ts +1 -0
- package/_vendor/canvas-react/components/overlays/ShapeOutlineOverlay.d.ts +8 -0
- package/_vendor/canvas-react/components/overlays/SnapIndicatorsOverlay.d.ts +1 -0
- package/_vendor/canvas-react/components/useCanvasDomEvents.d.ts +21 -0
- package/_vendor/canvas-react/dom.d.ts +10 -0
- package/_vendor/canvas-react/hooks/useEditor.d.ts +3 -0
- package/_vendor/canvas-react/hooks/useValue.d.ts +2 -0
- package/_vendor/canvas-react/host/canvasOverlayRegistryContext.d.ts +3 -0
- package/_vendor/canvas-react/host/canvasPlugin.d.ts +73 -0
- package/_vendor/canvas-react/host/canvasRendererRegistryContext.d.ts +3 -0
- package/_vendor/canvas-react/host/contextMenuRegistry.d.ts +12 -0
- package/_vendor/canvas-react/host/domEventGuards.d.ts +11 -0
- package/_vendor/canvas-react/host/extension.d.ts +37 -0
- package/_vendor/canvas-react/host/index.d.ts +13 -0
- package/_vendor/canvas-react/host/overlayRegistry.d.ts +18 -0
- package/_vendor/canvas-react/host/pluginHost.d.ts +2 -0
- package/_vendor/canvas-react/host/pluginHostManifest.d.ts +2 -0
- package/_vendor/canvas-react/host/pluginHostRuntime.d.ts +3 -0
- package/_vendor/canvas-react/host/pluginHostTypes.d.ts +102 -0
- package/_vendor/canvas-react/host/pluginHostValidation.d.ts +11 -0
- package/_vendor/canvas-react/host/rendererRegistry.d.ts +12 -0
- package/_vendor/canvas-react/host/toolbarRegistry.d.ts +24 -0
- package/_vendor/canvas-react/index.d.ts +4 -0
- package/_vendor/plugin-arrow/arrowBindingAnchors.d.ts +5 -0
- package/_vendor/plugin-arrow/arrowBindingGeometry.d.ts +28 -0
- package/_vendor/plugin-arrow/arrowBindingUtil.d.ts +27 -0
- package/_vendor/plugin-arrow/arrowGeometry.d.ts +74 -0
- package/_vendor/plugin-arrow/arrowShapeUtil.d.ts +21 -0
- package/_vendor/plugin-arrow/arrowTerminalBindingResolver.d.ts +20 -0
- package/_vendor/plugin-arrow/arrowTerminalCommands.d.ts +12 -0
- package/_vendor/plugin-arrow/arrowTool.d.ts +4 -0
- package/_vendor/plugin-arrow/canvas.d.ts +2 -0
- package/_vendor/plugin-arrow/editor.d.ts +7 -0
- package/_vendor/plugin-arrow/feature.d.ts +3 -0
- package/_vendor/plugin-arrow/index.d.ts +12 -0
- package/_vendor/plugin-arrow/selectionHandleInteractions.d.ts +3 -0
- package/_vendor/plugin-arrow/types.d.ts +31 -0
- package/_vendor/plugin-draw/DrawShapeRenderer.d.ts +10 -0
- package/_vendor/plugin-draw/canvas.d.ts +2 -0
- package/_vendor/plugin-draw/drawGeometry.d.ts +45 -0
- package/_vendor/plugin-draw/drawHitTest.d.ts +11 -0
- package/_vendor/plugin-draw/drawInterpolation.d.ts +5 -0
- package/_vendor/plugin-draw/drawPath.d.ts +37 -0
- package/_vendor/plugin-draw/drawSegments.d.ts +11 -0
- package/_vendor/plugin-draw/drawSelectionTransform.d.ts +18 -0
- package/_vendor/plugin-draw/drawShapeGeometry.d.ts +33 -0
- package/_vendor/plugin-draw/drawShapeUtil.d.ts +21 -0
- package/_vendor/plugin-draw/drawStrokeGeometry.d.ts +17 -0
- package/_vendor/plugin-draw/drawTool.d.ts +6 -0
- package/_vendor/plugin-draw/editor.d.ts +7 -0
- package/_vendor/plugin-draw/feature.d.ts +3 -0
- package/_vendor/plugin-draw/index.d.ts +13 -0
- package/_vendor/plugin-draw/types.d.ts +23 -0
- package/_vendor/plugin-eraser/canvas.d.ts +2 -0
- package/_vendor/plugin-eraser/editor.d.ts +2 -0
- package/_vendor/plugin-eraser/eraserTool.d.ts +5 -0
- package/_vendor/plugin-eraser/feature.d.ts +3 -0
- package/_vendor/plugin-eraser/{index.ts → index.d.ts} +2 -2
- package/_vendor/plugin-frame/canvas.d.ts +9 -0
- package/_vendor/plugin-frame/editor.d.ts +7 -0
- package/_vendor/plugin-frame/feature.d.ts +3 -0
- package/_vendor/plugin-frame/frameShapeUtil.d.ts +23 -0
- package/_vendor/plugin-frame/frameTool.d.ts +6 -0
- package/_vendor/plugin-frame/index.d.ts +6 -0
- package/_vendor/plugin-geo/canvas.d.ts +13 -0
- package/_vendor/plugin-geo/editor.d.ts +7 -0
- package/_vendor/plugin-geo/feature.d.ts +3 -0
- package/_vendor/plugin-geo/geoGeometry.d.ts +8 -0
- package/_vendor/plugin-geo/geoShapeUtil.d.ts +13 -0
- package/_vendor/plugin-geo/geoTools.d.ts +26 -0
- package/_vendor/plugin-geo/index.d.ts +7 -0
- package/_vendor/plugin-geo/types.d.ts +17 -0
- package/_vendor/plugin-group/canvas.d.ts +10 -0
- package/_vendor/plugin-group/editor.d.ts +7 -0
- package/_vendor/plugin-group/feature.d.ts +3 -0
- package/_vendor/plugin-group/groupShapeUtil.d.ts +15 -0
- package/_vendor/plugin-group/index.d.ts +5 -0
- package/_vendor/plugin-image/canvas.d.ts +2 -0
- package/_vendor/plugin-image/crop.d.ts +112 -0
- package/_vendor/plugin-image/cropInteractions.d.ts +3 -0
- package/_vendor/plugin-image/cropSession.d.ts +4 -0
- package/_vendor/plugin-image/editor.d.ts +16 -0
- package/_vendor/plugin-image/feature.d.ts +3 -0
- package/_vendor/plugin-image/imageShapeUtil.d.ts +11 -0
- package/_vendor/plugin-image/index.d.ts +8 -0
- package/_vendor/plugin-image/types.d.ts +37 -0
- package/_vendor/plugin-laser/canvas.d.ts +2 -0
- package/_vendor/plugin-laser/editor.d.ts +2 -0
- package/_vendor/plugin-laser/feature.d.ts +3 -0
- package/_vendor/plugin-laser/{index.ts → index.d.ts} +2 -2
- package/_vendor/plugin-laser/laserTool.d.ts +4 -0
- package/_vendor/plugin-text/arrowLabelBindingUtil.d.ts +42 -0
- package/_vendor/plugin-text/canvas.d.ts +2 -0
- package/_vendor/plugin-text/editor.d.ts +2 -0
- package/_vendor/plugin-text/feature.d.ts +3 -0
- package/_vendor/plugin-text/geoLabelBindingUtil.d.ts +45 -0
- package/_vendor/plugin-text/host/RichTextEditingBox.d.ts +5 -0
- package/_vendor/plugin-text/host/RichTextToolbar.d.ts +8 -0
- package/_vendor/plugin-text/host/TiptapTextEditor.d.ts +24 -0
- package/_vendor/plugin-text/host/richTextBubbleMenuPositionSync.d.ts +7 -0
- package/_vendor/plugin-text/host/richTextRendering.d.ts +3 -0
- package/_vendor/plugin-text/host/textDomSelection.d.ts +7 -0
- package/_vendor/plugin-text/host/textEditingBoxStyle.d.ts +3 -0
- package/_vendor/plugin-text/host/textEntryFocus.d.ts +22 -0
- package/_vendor/plugin-text/host/textFontLoader.d.ts +2 -0
- package/_vendor/plugin-text/host/textMeasurement.d.ts +12 -0
- package/_vendor/plugin-text/host/textMeasurementSync.d.ts +10 -0
- package/_vendor/plugin-text/host/textRangeSelection.d.ts +14 -0
- package/_vendor/plugin-text/host/textShapeRendererRuntime.d.ts +8 -0
- package/_vendor/plugin-text/host/textShapeSync.d.ts +17 -0
- package/_vendor/plugin-text/host/tiptapTextEditorController.d.ts +33 -0
- package/_vendor/plugin-text/index.d.ts +4 -0
- package/_vendor/plugin-text/richTextUtils.d.ts +18 -0
- package/_vendor/plugin-text/textInteractions.d.ts +2 -0
- package/_vendor/plugin-text/textLabelHelpers.d.ts +44 -0
- package/_vendor/plugin-text/textShapeHelpers.d.ts +21 -0
- package/_vendor/plugin-text/textShapeSvgExporter.d.ts +6 -0
- package/_vendor/plugin-text/textShapeUtil.d.ts +19 -0
- package/_vendor/plugin-text/textStyle.d.ts +9 -0
- package/_vendor/plugin-text/textTool.d.ts +4 -0
- package/_vendor/plugin-text/textTypes.d.ts +28 -0
- package/_vendor/signals/atom.d.ts +9 -0
- package/_vendor/signals/computed.d.ts +11 -0
- package/_vendor/signals/core.d.ts +17 -0
- package/_vendor/signals/effect.d.ts +29 -0
- package/_vendor/signals/types.d.ts +15 -0
- package/_vendor/store/diff.d.ts +9 -0
- package/_vendor/store/history.d.ts +37 -0
- package/_vendor/store/index.d.ts +5 -0
- package/_vendor/store/store.d.ts +32 -0
- package/_vendor/store/types.d.ts +27 -0
- package/browser/localSnapshotRestore.d.ts +13 -0
- package/browser/persistence.d.ts +46 -0
- package/builtins/controller/createBuiltInCanvasController.d.ts +16 -0
- package/builtins/controller/layerController.d.ts +9 -0
- package/builtins/controller/shapeCreationController.d.ts +74 -0
- package/builtins/extensions.d.ts +15 -0
- package/builtins/index.d.ts +5 -0
- package/chrome/CanvasKitFloatingToolbarLayer.d.ts +6 -0
- package/chrome/FloatingSelectionToolbarPageSpace.d.ts +9 -0
- package/chrome/bindings/useCanvasKitChromeControls.d.ts +27 -0
- package/chrome/bindings/useContextMenuSurface.d.ts +12 -0
- package/chrome/bindings/useSvgExport.d.ts +15 -0
- package/chrome/bindings/useToolbarSurfaces.d.ts +26 -0
- package/chrome/types.d.ts +66 -0
- package/chrome/useCanvasKitChromeContext.d.ts +19 -0
- package/controller/canvasKitController.d.ts +36 -0
- package/core/controller/canvasProductController.d.ts +114 -0
- package/core/controller/featureControllerRegistry.d.ts +12 -0
- package/core/controller/index.d.ts +4 -0
- package/core/controller/productLayerTree.d.ts +10 -0
- package/core/features/actions/canvasActionContext.d.ts +15 -0
- package/core/features/actions/canvasActions.d.ts +26 -0
- package/core/features/clipboard/clipboardContextMenuContributions.d.ts +2 -0
- package/core/features/clipboard/clipboardContribution.d.ts +19 -0
- package/core/features/clipboard/clipboardService.d.ts +10 -0
- package/core/features/context-menu/contextMenuActions.d.ts +12 -0
- package/core/features/context-menu/contextMenuContext.d.ts +6 -0
- package/core/features/context-menu/contextMenuContribution.d.ts +4 -0
- package/core/features/context-menu/viewContextMenuContributions.d.ts +2 -0
- package/core/features/export/svgExport.d.ts +33 -0
- package/core/features/hostActionIds.d.ts +1 -0
- package/core/features/toolbar/selectionContextMenuContributions.d.ts +2 -0
- package/core/features/toolbar/toolContextMenuContributions.d.ts +2 -0
- package/core/features/toolbar/toolbarContribution.d.ts +4 -0
- package/core/features/toolbar/toolbarLabels.d.ts +8 -0
- package/core/index.d.ts +23 -0
- package/core/runtime/productAssets.d.ts +18 -0
- package/core/runtime/productContributions.d.ts +9 -0
- package/core/runtime/productDefinition.d.ts +32 -0
- package/core/runtime/productEditor.d.ts +3 -0
- package/core/runtime/productHost.d.ts +17 -0
- package/core/runtime/productServices.d.ts +30 -0
- package/features/image/ImageImportController.d.ts +9 -0
- package/features/image/imageAssetService.d.ts +7 -0
- package/features/image/imageBlobStore.d.ts +25 -0
- package/features/image/imageFileHelpers.d.ts +35 -0
- package/features/image/imageHostActions.d.ts +36 -0
- package/features/image/imageHostExtension.d.ts +5 -0
- package/features/image/imageProductController.d.ts +22 -0
- package/features/image/imageProductToolbarActions.d.ts +2 -0
- package/features/image/imageToolbarHostBridge.d.ts +14 -0
- package/features/image/index.d.ts +15 -0
- package/features/image/svgImageAssetInliner.d.ts +3 -0
- package/features/image/useImageImport.d.ts +17 -0
- package/index.css +1 -2
- package/index.d.ts +12 -15
- package/index.mjs +66 -1
- package/package.json +1 -11
- package/product/canvasKitProduct.d.ts +59 -0
- package/react/CanvasKitPersistenceNotice.d.ts +4 -0
- package/react/CanvasKitRoot.d.ts +5 -0
- package/react/useCanvasKitController.d.ts +5 -0
- package/react/useCanvasKitKeyboardShortcuts.d.ts +6 -0
- package/react/useCanvasKitRuntime.d.ts +4 -0
- package/react/useCanvasKitStartup.d.ts +9 -0
- package/runtime/canvasKitHostExtensions.d.ts +19 -0
- package/runtime/canvasKitRuntime.d.ts +19 -0
- package/runtime/canvasKitRuntimeInitializer.d.ts +11 -0
- package/_vendor/canvas-core/bindings/BindingUtil.ts +0 -92
- package/_vendor/canvas-core/bindings/BindingUtilRegistry.ts +0 -22
- package/_vendor/canvas-core/bindings/arrow/arrowBindingHelpers.ts +0 -52
- package/_vendor/canvas-core/contextMenu.ts +0 -85
- package/_vendor/canvas-core/editor/Editor.ts +0 -2614
- package/_vendor/canvas-core/editor/HistoryManager.ts +0 -83
- package/_vendor/canvas-core/editor/StateNode.ts +0 -162
- package/_vendor/canvas-core/editor/camera.ts +0 -6
- package/_vendor/canvas-core/editor/clipboard.ts +0 -478
- package/_vendor/canvas-core/editor/commands.ts +0 -833
- package/_vendor/canvas-core/editor/edgeScroll.ts +0 -37
- package/_vendor/canvas-core/editor/editorComputedHelpers.ts +0 -257
- package/_vendor/canvas-core/editor/editorSelectionTransforms.ts +0 -116
- package/_vendor/canvas-core/editor/events.ts +0 -93
- package/_vendor/canvas-core/editor/index.ts +0 -12
- package/_vendor/canvas-core/editor/interactions.ts +0 -101
- package/_vendor/canvas-core/editor/internal.ts +0 -22
- package/_vendor/canvas-core/editor/managers/BindingManager.ts +0 -262
- package/_vendor/canvas-core/editor/managers/CameraManager.ts +0 -147
- package/_vendor/canvas-core/editor/managers/ClipboardManager.ts +0 -32
- package/_vendor/canvas-core/editor/managers/DocumentSnapshotManager.ts +0 -256
- package/_vendor/canvas-core/editor/managers/InputsManager.ts +0 -319
- package/_vendor/canvas-core/editor/managers/InteractionTransientManager.ts +0 -218
- package/_vendor/canvas-core/editor/managers/QueryManager.ts +0 -837
- package/_vendor/canvas-core/editor/managers/RenderWindowManager.ts +0 -347
- package/_vendor/canvas-core/editor/managers/SelectionLayoutManager.ts +0 -196
- package/_vendor/canvas-core/editor/managers/SelectionManager.ts +0 -98
- package/_vendor/canvas-core/editor/managers/SelectionOverlayManager.ts +0 -308
- package/_vendor/canvas-core/editor/managers/ShapeEditingManager.ts +0 -226
- package/_vendor/canvas-core/editor/managers/ShapeGeometryManager.ts +0 -162
- package/_vendor/canvas-core/editor/managers/ShapeHierarchyManager.ts +0 -797
- package/_vendor/canvas-core/editor/managers/SideEffectManager.ts +0 -83
- package/_vendor/canvas-core/editor/managers/SnapManager.ts +0 -433
- package/_vendor/canvas-core/editor/managers/SnapSnapshotBuilder.ts +0 -430
- package/_vendor/canvas-core/editor/managers/SpatialIndexManager.ts +0 -354
- package/_vendor/canvas-core/editor/managers/ToolManager.ts +0 -81
- package/_vendor/canvas-core/editor/managers/queryState.ts +0 -583
- package/_vendor/canvas-core/editor/managers/selectionGeometry.ts +0 -287
- package/_vendor/canvas-core/editor/managers/shapeOrder.ts +0 -350
- package/_vendor/canvas-core/editor/managers/shapeReparenting.ts +0 -160
- package/_vendor/canvas-core/editor/managers/snapCalculations.ts +0 -412
- package/_vendor/canvas-core/editor/managers/snapGeometry.ts +0 -202
- package/_vendor/canvas-core/editor/managers/snapIndicators.ts +0 -403
- package/_vendor/canvas-core/editor/managers/snapTypes.ts +0 -122
- package/_vendor/canvas-core/editor/queries/shapeTransforms.ts +0 -171
- package/_vendor/canvas-core/editor/renderWindow.ts +0 -439
- package/_vendor/canvas-core/editor/resizeGeometry.ts +0 -654
- package/_vendor/canvas-core/editor/selection.ts +0 -489
- package/_vendor/canvas-core/editor/selectionHandleInteractions.ts +0 -43
- package/_vendor/canvas-core/editor/selectionOverlay.ts +0 -567
- package/_vendor/canvas-core/exports/integrity.ts +0 -174
- package/_vendor/canvas-core/exports/svg.ts +0 -494
- package/_vendor/canvas-core/geometry/Box.ts +0 -80
- package/_vendor/canvas-core/geometry/Ellipse2d.ts +0 -67
- package/_vendor/canvas-core/geometry/Geometry2d.ts +0 -52
- package/_vendor/canvas-core/geometry/Mat.ts +0 -92
- package/_vendor/canvas-core/geometry/Polyline2d.ts +0 -63
- package/_vendor/canvas-core/geometry/Rectangle2d.ts +0 -64
- package/_vendor/canvas-core/geometry/Vec.ts +0 -123
- package/_vendor/canvas-core/geometry/index.ts +0 -13
- package/_vendor/canvas-core/geometry/segments.ts +0 -65
- package/_vendor/canvas-core/index.ts +0 -391
- package/_vendor/canvas-core/plugins/index.ts +0 -5
- package/_vendor/canvas-core/plugins/types.ts +0 -53
- package/_vendor/canvas-core/reactivity.ts +0 -16
- package/_vendor/canvas-core/schema/records.ts +0 -221
- package/_vendor/canvas-core/schema/snapshots.ts +0 -527
- package/_vendor/canvas-core/shapes/ShapeUtil.ts +0 -516
- package/_vendor/canvas-core/shapes/ShapeUtilRegistry.ts +0 -26
- package/_vendor/canvas-core/shapes/capabilities.ts +0 -67
- package/_vendor/canvas-core/shapes/types.ts +0 -20
- package/_vendor/canvas-core/toolbar.ts +0 -148
- package/_vendor/canvas-core/tools/hand/HandTool.ts +0 -75
- package/_vendor/canvas-core/tools/index.ts +0 -2
- package/_vendor/canvas-core/tools/select/SelectTool.ts +0 -33
- package/_vendor/canvas-core/tools/select/selectContainment.ts +0 -104
- package/_vendor/canvas-core/tools/select/selectToolHelpers.ts +0 -801
- package/_vendor/canvas-core/tools/select/states/BrushingState.ts +0 -145
- package/_vendor/canvas-core/tools/select/states/DraggingSelectionHandleInteractionState.ts +0 -116
- package/_vendor/canvas-core/tools/select/states/IdleState.ts +0 -159
- package/_vendor/canvas-core/tools/select/states/PointingCanvasState.ts +0 -41
- package/_vendor/canvas-core/tools/select/states/PointingResizeHandleState.ts +0 -78
- package/_vendor/canvas-core/tools/select/states/PointingRotateHandleState.ts +0 -64
- package/_vendor/canvas-core/tools/select/states/PointingSelectionHandleInteractionState.ts +0 -34
- package/_vendor/canvas-core/tools/select/states/PointingShapeState.ts +0 -140
- package/_vendor/canvas-core/tools/select/states/ResizingState.ts +0 -171
- package/_vendor/canvas-core/tools/select/states/RotatingState.ts +0 -124
- package/_vendor/canvas-core/tools/select/states/SelectStateNode.ts +0 -128
- package/_vendor/canvas-core/tools/select/states/TranslatingState.ts +0 -139
- package/_vendor/canvas-core/tools/select/states/index.ts +0 -11
- package/_vendor/canvas-plugin-api/feature.ts +0 -204
- package/_vendor/canvas-plugin-api/index.ts +0 -142
- package/_vendor/canvas-product-react/api/apiRegistry.ts +0 -35
- package/_vendor/canvas-product-react/api/canvasProductApi.ts +0 -422
- package/_vendor/canvas-product-react/api/index.ts +0 -31
- package/_vendor/canvas-product-react/capabilities/clipboard/clipboardService.ts +0 -36
- package/_vendor/canvas-product-react/capabilities/clipboard/systemClipboard.ts +0 -245
- package/_vendor/canvas-product-react/capabilities/context-menu/systemContextMenu.ts +0 -396
- package/_vendor/canvas-product-react/capabilities/context-menu/useContextMenuSurface.ts +0 -59
- package/_vendor/canvas-product-react/capabilities/export/useSvgExport.ts +0 -156
- package/_vendor/canvas-product-react/capabilities/history/useHistoryControls.ts +0 -23
- package/_vendor/canvas-product-react/capabilities/pages/usePageControls.ts +0 -41
- package/_vendor/canvas-product-react/capabilities/toolbar/systemToolbar.ts +0 -490
- package/_vendor/canvas-product-react/capabilities/toolbar/useToolbarSurfaces.ts +0 -92
- package/_vendor/canvas-product-react/capabilities/zoom/useZoomControls.ts +0 -27
- package/_vendor/canvas-product-react/index.ts +0 -84
- package/_vendor/canvas-product-react/persistence/index.ts +0 -18
- package/_vendor/canvas-product-react/persistence/localSnapshotPersistence.ts +0 -294
- package/_vendor/canvas-product-react/runtime/CanvasProductRoot.tsx +0 -250
- package/_vendor/canvas-product-react/runtime/productDefinition.ts +0 -72
- package/_vendor/canvas-product-react/runtime/productServices.ts +0 -96
- package/_vendor/canvas-react/components/CanvasView.tsx +0 -796
- package/_vendor/canvas-react/components/OverlayLayer.tsx +0 -879
- package/_vendor/canvas-react/components/PageSpace.tsx +0 -34
- package/_vendor/canvas-react/components/ShapeLayer.tsx +0 -428
- package/_vendor/canvas-react/components/index.ts +0 -4
- package/_vendor/canvas-react/hooks/useEditor.ts +0 -11
- package/_vendor/canvas-react/hooks/useValue.ts +0 -14
- package/_vendor/canvas-react/host/CanvasRendererRegistryContext.tsx +0 -14
- package/_vendor/canvas-react/host/contextMenuRegistry.ts +0 -61
- package/_vendor/canvas-react/host/domEventGuards.ts +0 -61
- package/_vendor/canvas-react/host/index.ts +0 -38
- package/_vendor/canvas-react/host/pluginHost.ts +0 -635
- package/_vendor/canvas-react/host/rendererRegistry.tsx +0 -58
- package/_vendor/canvas-react/host/toolbarRegistry.ts +0 -100
- package/_vendor/canvas-react/index.ts +0 -3
- package/_vendor/plugin-arrow/ArrowBindingUtil.ts +0 -239
- package/_vendor/plugin-arrow/ArrowShapeUtil.ts +0 -311
- package/_vendor/plugin-arrow/ArrowTool.ts +0 -208
- package/_vendor/plugin-arrow/arrowGeometry.ts +0 -441
- package/_vendor/plugin-arrow/arrowTerminalBindingResolver.ts +0 -253
- package/_vendor/plugin-arrow/arrowTerminalCommands.ts +0 -230
- package/_vendor/plugin-arrow/canvas.tsx +0 -92
- package/_vendor/plugin-arrow/core.ts +0 -409
- package/_vendor/plugin-arrow/feature.ts +0 -20
- package/_vendor/plugin-arrow/index.ts +0 -28
- package/_vendor/plugin-arrow/selectionHandleInteractions.ts +0 -154
- package/_vendor/plugin-arrow/types.ts +0 -63
- package/_vendor/plugin-draw/DrawShapeRenderer.tsx +0 -60
- package/_vendor/plugin-draw/DrawShapeUtil.ts +0 -372
- package/_vendor/plugin-draw/DrawTool.ts +0 -444
- package/_vendor/plugin-draw/canvas.tsx +0 -24
- package/_vendor/plugin-draw/core.ts +0 -515
- package/_vendor/plugin-draw/drawGeometry.ts +0 -491
- package/_vendor/plugin-draw/drawHitTest.ts +0 -271
- package/_vendor/plugin-draw/drawInterpolation.ts +0 -250
- package/_vendor/plugin-draw/drawPath.ts +0 -550
- package/_vendor/plugin-draw/drawSegments.ts +0 -106
- package/_vendor/plugin-draw/drawSelectionTransform.ts +0 -67
- package/_vendor/plugin-draw/drawShapeGeometry.ts +0 -307
- package/_vendor/plugin-draw/drawStrokeGeometry.ts +0 -454
- package/_vendor/plugin-draw/feature.ts +0 -20
- package/_vendor/plugin-draw/index.ts +0 -31
- package/_vendor/plugin-draw/types.ts +0 -36
- package/_vendor/plugin-eraser/EraserTool.ts +0 -297
- package/_vendor/plugin-eraser/canvas.tsx +0 -616
- package/_vendor/plugin-eraser/core.ts +0 -49
- package/_vendor/plugin-eraser/feature.ts +0 -20
- package/_vendor/plugin-frame/FrameShapeUtil.ts +0 -173
- package/_vendor/plugin-frame/FrameTool.ts +0 -225
- package/_vendor/plugin-frame/canvas.tsx +0 -75
- package/_vendor/plugin-frame/core.ts +0 -534
- package/_vendor/plugin-frame/feature.ts +0 -20
- package/_vendor/plugin-frame/index.ts +0 -6
- package/_vendor/plugin-geo/GeoShapeUtil.ts +0 -463
- package/_vendor/plugin-geo/GeoTools.ts +0 -247
- package/_vendor/plugin-geo/canvas.tsx +0 -90
- package/_vendor/plugin-geo/core.ts +0 -495
- package/_vendor/plugin-geo/feature.ts +0 -20
- package/_vendor/plugin-geo/index.ts +0 -7
- package/_vendor/plugin-geo/types.ts +0 -27
- package/_vendor/plugin-group/GroupShapeUtil.ts +0 -59
- package/_vendor/plugin-group/canvas.tsx +0 -59
- package/_vendor/plugin-group/core.ts +0 -40
- package/_vendor/plugin-group/feature.ts +0 -20
- package/_vendor/plugin-group/index.ts +0 -5
- package/_vendor/plugin-image/ImageShapeUtil.ts +0 -95
- package/_vendor/plugin-image/canvas.tsx +0 -212
- package/_vendor/plugin-image/core.ts +0 -542
- package/_vendor/plugin-image/crop.ts +0 -770
- package/_vendor/plugin-image/cropInteractions.ts +0 -350
- package/_vendor/plugin-image/cropSession.ts +0 -38
- package/_vendor/plugin-image/feature.ts +0 -20
- package/_vendor/plugin-image/index.ts +0 -29
- package/_vendor/plugin-image/types.ts +0 -55
- package/_vendor/plugin-image-product-react/ImageImportController.tsx +0 -143
- package/_vendor/plugin-image-product-react/imageAssetService.ts +0 -52
- package/_vendor/plugin-image-product-react/imageBlobStore.ts +0 -315
- package/_vendor/plugin-image-product-react/imageHostActions.ts +0 -438
- package/_vendor/plugin-image-product-react/imageProductApi.ts +0 -88
- package/_vendor/plugin-image-product-react/imageToolbarHostBridge.ts +0 -48
- package/_vendor/plugin-image-product-react/imageToolbarRuntime.ts +0 -21
- package/_vendor/plugin-image-product-react/index.ts +0 -60
- package/_vendor/plugin-image-product-react/snapshotGuards.ts +0 -33
- package/_vendor/plugin-image-product-react/svgImageAssetInliner.ts +0 -54
- package/_vendor/plugin-image-product-react/useImageImport.ts +0 -64
- package/_vendor/plugin-laser/LaserTool.ts +0 -154
- package/_vendor/plugin-laser/canvas.tsx +0 -645
- package/_vendor/plugin-laser/core.ts +0 -49
- package/_vendor/plugin-laser/feature.ts +0 -20
- package/_vendor/plugin-text/ArrowLabelBindingUtil.ts +0 -336
- package/_vendor/plugin-text/GeoLabelBindingUtil.ts +0 -391
- package/_vendor/plugin-text/TextShapeSvgExporter.ts +0 -101
- package/_vendor/plugin-text/TextShapeUtil.ts +0 -284
- package/_vendor/plugin-text/TextTool.ts +0 -228
- package/_vendor/plugin-text/canvas.tsx +0 -115
- package/_vendor/plugin-text/core.ts +0 -422
- package/_vendor/plugin-text/feature.ts +0 -20
- package/_vendor/plugin-text/host/RichTextEditingBox.tsx +0 -144
- package/_vendor/plugin-text/host/RichTextToolbar.tsx +0 -266
- package/_vendor/plugin-text/host/TiptapTextEditor.tsx +0 -191
- package/_vendor/plugin-text/host/richTextRendering.tsx +0 -49
- package/_vendor/plugin-text/host/textDomSelection.ts +0 -93
- package/_vendor/plugin-text/host/textEditingBoxStyle.ts +0 -36
- package/_vendor/plugin-text/host/textEntryFocus.ts +0 -307
- package/_vendor/plugin-text/host/textFontLoader.ts +0 -149
- package/_vendor/plugin-text/host/textMeasurement.ts +0 -258
- package/_vendor/plugin-text/host/textMeasurementSync.ts +0 -77
- package/_vendor/plugin-text/host/textRangeSelection.ts +0 -134
- package/_vendor/plugin-text/host/textShapeRendererRuntime.tsx +0 -89
- package/_vendor/plugin-text/host/textShapeSync.ts +0 -173
- package/_vendor/plugin-text/host/tiptapTextEditorController.ts +0 -148
- package/_vendor/plugin-text/index.ts +0 -18
- package/_vendor/plugin-text/richTextUtils.ts +0 -259
- package/_vendor/plugin-text/textInteractions.ts +0 -366
- package/_vendor/plugin-text/textLabelHelpers.ts +0 -235
- package/_vendor/plugin-text/textShapeHelpers.ts +0 -123
- package/_vendor/plugin-text/textStyle.ts +0 -96
- package/_vendor/plugin-text/textTypes.ts +0 -48
- package/_vendor/signals/atom.ts +0 -74
- package/_vendor/signals/computed.ts +0 -132
- package/_vendor/signals/core.ts +0 -130
- package/_vendor/signals/effect.ts +0 -117
- package/_vendor/signals/types.ts +0 -17
- package/_vendor/store/Store.ts +0 -171
- package/_vendor/store/diff.ts +0 -229
- package/_vendor/store/history.ts +0 -177
- package/_vendor/store/index.ts +0 -32
- package/_vendor/store/types.ts +0 -37
- package/api/canvasKitApi.d.ts +0 -29
- package/internal-modules.d.ts +0 -187
- package/product/Shell.d.ts +0 -19
- package/product/chromeContext.d.ts +0 -70
- package/product/createCanvasKitEditor.d.ts +0 -6
- package/product/index.d.ts +0 -7
- package/product/persistence.d.ts +0 -3
- package/product/product.d.ts +0 -22
- package/product/useCanvasClipboardShortcuts.d.ts +0 -6
- package/product-iyBbEPIs.mjs +0 -4
- package/product.mjs +0 -1
- package/standard/extensions.d.ts +0 -1
- package/standard/index.d.ts +0 -3
- package/standard/standardApi.d.ts +0 -91
- package/standard-BmrxwqpJ.mjs +0 -44
- package/standard.mjs +0 -1
- /package/_vendor/signals/{index.ts → index.d.ts} +0 -0
|
@@ -1,770 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Vec,
|
|
3
|
-
type SelectionResizeHandleId,
|
|
4
|
-
type ShapeUpdate,
|
|
5
|
-
} from "@land/canvas-core";
|
|
6
|
-
import type { ImageShapeCrop, ImageShapeRecord } from "./types";
|
|
7
|
-
|
|
8
|
-
const MIN_NORMALIZED_CROP_SIZE = 0.0001;
|
|
9
|
-
const MIN_CROP_SIZE = 8;
|
|
10
|
-
const IMAGE_CROP_ZOOM_FACTOR = 0.8;
|
|
11
|
-
const IMAGE_CROP_EPSILON = 0.0001;
|
|
12
|
-
export const IMAGE_CROP_HANDLE_TYPE = "image.crop";
|
|
13
|
-
export const IMAGE_CROP_HISTORY_MARK_PREFIX = "image.crop:";
|
|
14
|
-
export const IMAGE_CROP_HANDLE_HISTORY_MARK = "image.crop.handle";
|
|
15
|
-
export const IMAGE_CROP_TRANSLATE_HISTORY_MARK = "image.crop.translate";
|
|
16
|
-
export const IMAGE_CROP_MODE_ENTRY_MARK_PREFIX = `${IMAGE_CROP_HISTORY_MARK_PREFIX}edit:`;
|
|
17
|
-
export const IMAGE_CROP_ASPECT_RATIO_PRESETS = [
|
|
18
|
-
{ label: "1:1", value: "1:1", ratio: 1 },
|
|
19
|
-
{ label: "4:3", value: "4:3", ratio: 4 / 3 },
|
|
20
|
-
{ label: "16:9", value: "16:9", ratio: 16 / 9 },
|
|
21
|
-
] as const;
|
|
22
|
-
|
|
23
|
-
export type ImageCropAspectRatioPresetValue =
|
|
24
|
-
(typeof IMAGE_CROP_ASPECT_RATIO_PRESETS)[number]["value"];
|
|
25
|
-
|
|
26
|
-
const IMAGE_CROP_HANDLE_CURSORS: Record<SelectionResizeHandleId, string> = {
|
|
27
|
-
top_left: "nwse-resize",
|
|
28
|
-
top: "ns-resize",
|
|
29
|
-
top_right: "nesw-resize",
|
|
30
|
-
right: "ew-resize",
|
|
31
|
-
bottom_right: "nwse-resize",
|
|
32
|
-
bottom: "ns-resize",
|
|
33
|
-
bottom_left: "nesw-resize",
|
|
34
|
-
left: "ew-resize",
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const IMAGE_CROP_HANDLE_IDS = [
|
|
38
|
-
"top_left",
|
|
39
|
-
"top",
|
|
40
|
-
"top_right",
|
|
41
|
-
"right",
|
|
42
|
-
"bottom_right",
|
|
43
|
-
"bottom",
|
|
44
|
-
"bottom_left",
|
|
45
|
-
"left",
|
|
46
|
-
] as const satisfies readonly SelectionResizeHandleId[];
|
|
47
|
-
|
|
48
|
-
export interface ImageCropRect {
|
|
49
|
-
left: number;
|
|
50
|
-
top: number;
|
|
51
|
-
right: number;
|
|
52
|
-
bottom: number;
|
|
53
|
-
width: number;
|
|
54
|
-
height: number;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export interface ImageCropPlacement {
|
|
58
|
-
imageX: number;
|
|
59
|
-
imageY: number;
|
|
60
|
-
imageWidth: number;
|
|
61
|
-
imageHeight: number;
|
|
62
|
-
rect: ImageCropRect;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export interface ImageCropCustomHandleAnchor {
|
|
66
|
-
kind: "custom";
|
|
67
|
-
type: typeof IMAGE_CROP_HANDLE_TYPE;
|
|
68
|
-
id: SelectionResizeHandleId;
|
|
69
|
-
point: Vec;
|
|
70
|
-
cursor: string;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
interface UncroppedImageSpace {
|
|
74
|
-
w: number;
|
|
75
|
-
h: number;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function clamp01(value: number): number {
|
|
79
|
-
return Math.min(1, Math.max(0, value));
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function clamp(value: number, min: number, max: number): number {
|
|
83
|
-
return Math.min(max, Math.max(min, value));
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function isCropPoint(value: unknown): value is { x: number; y: number } {
|
|
87
|
-
return (
|
|
88
|
-
!!value &&
|
|
89
|
-
typeof value === "object" &&
|
|
90
|
-
typeof (value as { x?: unknown }).x === "number" &&
|
|
91
|
-
Number.isFinite((value as { x: number }).x) &&
|
|
92
|
-
typeof (value as { y?: unknown }).y === "number" &&
|
|
93
|
-
Number.isFinite((value as { y: number }).y)
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function normalizeRange(
|
|
98
|
-
first: number,
|
|
99
|
-
second: number,
|
|
100
|
-
): { min: number; max: number } {
|
|
101
|
-
const clampedFirst = clamp01(first);
|
|
102
|
-
const clampedSecond = clamp01(second);
|
|
103
|
-
let min = Math.min(clampedFirst, clampedSecond);
|
|
104
|
-
let max = Math.max(clampedFirst, clampedSecond);
|
|
105
|
-
|
|
106
|
-
if (max - min < MIN_NORMALIZED_CROP_SIZE) {
|
|
107
|
-
const center = (min + max) / 2;
|
|
108
|
-
min = Math.max(
|
|
109
|
-
0,
|
|
110
|
-
Math.min(
|
|
111
|
-
1 - MIN_NORMALIZED_CROP_SIZE,
|
|
112
|
-
center - MIN_NORMALIZED_CROP_SIZE / 2,
|
|
113
|
-
),
|
|
114
|
-
);
|
|
115
|
-
max = min + MIN_NORMALIZED_CROP_SIZE;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return { min, max };
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export function normalizeImageShapeCrop(value: unknown): ImageShapeCrop | null {
|
|
122
|
-
if (!value || typeof value !== "object") {
|
|
123
|
-
return null;
|
|
124
|
-
}
|
|
125
|
-
const candidate = value as {
|
|
126
|
-
bottomRight?: unknown;
|
|
127
|
-
topLeft?: unknown;
|
|
128
|
-
};
|
|
129
|
-
if (!isCropPoint(candidate.topLeft) || !isCropPoint(candidate.bottomRight)) {
|
|
130
|
-
return null;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const x = normalizeRange(candidate.topLeft.x, candidate.bottomRight.x);
|
|
134
|
-
const y = normalizeRange(candidate.topLeft.y, candidate.bottomRight.y);
|
|
135
|
-
return {
|
|
136
|
-
topLeft: { x: x.min, y: y.min },
|
|
137
|
-
bottomRight: { x: x.max, y: y.max },
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export function getImageCropRect(
|
|
142
|
-
crop: ImageShapeCrop | null | undefined,
|
|
143
|
-
): ImageCropRect | null {
|
|
144
|
-
const normalized = normalizeImageShapeCrop(crop);
|
|
145
|
-
if (!normalized) {
|
|
146
|
-
return null;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const left = normalized.topLeft.x;
|
|
150
|
-
const top = normalized.topLeft.y;
|
|
151
|
-
const right = normalized.bottomRight.x;
|
|
152
|
-
const bottom = normalized.bottomRight.y;
|
|
153
|
-
return {
|
|
154
|
-
left,
|
|
155
|
-
top,
|
|
156
|
-
right,
|
|
157
|
-
bottom,
|
|
158
|
-
width: right - left,
|
|
159
|
-
height: bottom - top,
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export function getDefaultImageCrop(): ImageShapeCrop {
|
|
164
|
-
return {
|
|
165
|
-
topLeft: { x: 0, y: 0 },
|
|
166
|
-
bottomRight: { x: 1, y: 1 },
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export function getImageCropRectOrDefault(
|
|
171
|
-
crop: ImageShapeCrop | null | undefined,
|
|
172
|
-
): ImageCropRect {
|
|
173
|
-
return getImageCropRect(crop) ?? {
|
|
174
|
-
left: 0,
|
|
175
|
-
top: 0,
|
|
176
|
-
right: 1,
|
|
177
|
-
bottom: 1,
|
|
178
|
-
width: 1,
|
|
179
|
-
height: 1,
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
function isCropRectApproximatelyFull(rect: ImageCropRect): boolean {
|
|
184
|
-
return (
|
|
185
|
-
Math.abs(rect.left) <= IMAGE_CROP_EPSILON &&
|
|
186
|
-
Math.abs(rect.top) <= IMAGE_CROP_EPSILON &&
|
|
187
|
-
Math.abs(1 - rect.right) <= IMAGE_CROP_EPSILON &&
|
|
188
|
-
Math.abs(1 - rect.bottom) <= IMAGE_CROP_EPSILON
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
function areCropRectsEqual(left: ImageCropRect, right: ImageCropRect): boolean {
|
|
193
|
-
return (
|
|
194
|
-
Math.abs(left.left - right.left) <= IMAGE_CROP_EPSILON &&
|
|
195
|
-
Math.abs(left.top - right.top) <= IMAGE_CROP_EPSILON &&
|
|
196
|
-
Math.abs(left.right - right.right) <= IMAGE_CROP_EPSILON &&
|
|
197
|
-
Math.abs(left.bottom - right.bottom) <= IMAGE_CROP_EPSILON
|
|
198
|
-
);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
function getImageCropFromRect(
|
|
202
|
-
rect: ImageCropRect,
|
|
203
|
-
): ImageShapeCrop | null {
|
|
204
|
-
if (isCropRectApproximatelyFull(rect)) {
|
|
205
|
-
return null;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
return normalizeImageShapeCrop({
|
|
209
|
-
topLeft: {
|
|
210
|
-
x: rect.left,
|
|
211
|
-
y: rect.top,
|
|
212
|
-
},
|
|
213
|
-
bottomRight: {
|
|
214
|
-
x: rect.right,
|
|
215
|
-
y: rect.bottom,
|
|
216
|
-
},
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
function getCenteredCropRect({
|
|
221
|
-
centerX,
|
|
222
|
-
centerY,
|
|
223
|
-
height,
|
|
224
|
-
width,
|
|
225
|
-
}: {
|
|
226
|
-
centerX: number;
|
|
227
|
-
centerY: number;
|
|
228
|
-
height: number;
|
|
229
|
-
width: number;
|
|
230
|
-
}): ImageCropRect {
|
|
231
|
-
const nextWidth = clamp(width, MIN_NORMALIZED_CROP_SIZE, 1);
|
|
232
|
-
const nextHeight = clamp(height, MIN_NORMALIZED_CROP_SIZE, 1);
|
|
233
|
-
const left = clamp(centerX - nextWidth / 2, 0, 1 - nextWidth);
|
|
234
|
-
const top = clamp(centerY - nextHeight / 2, 0, 1 - nextHeight);
|
|
235
|
-
return {
|
|
236
|
-
left,
|
|
237
|
-
top,
|
|
238
|
-
right: left + nextWidth,
|
|
239
|
-
bottom: top + nextHeight,
|
|
240
|
-
width: nextWidth,
|
|
241
|
-
height: nextHeight,
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
function getImageCropRectCenter(rect: ImageCropRect): { x: number; y: number } {
|
|
246
|
-
return {
|
|
247
|
-
x: rect.left + rect.width / 2,
|
|
248
|
-
y: rect.top + rect.height / 2,
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
export function getUncroppedImageSize({
|
|
253
|
-
crop,
|
|
254
|
-
shape,
|
|
255
|
-
}: {
|
|
256
|
-
crop: ImageShapeCrop | null | undefined;
|
|
257
|
-
shape: ImageShapeRecord;
|
|
258
|
-
}): UncroppedImageSpace {
|
|
259
|
-
const rect = getImageCropRectOrDefault(crop);
|
|
260
|
-
return {
|
|
261
|
-
w: shape.props.w / rect.width,
|
|
262
|
-
h: shape.props.h / rect.height,
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
export function getImageCropAspectRatioPresetValue(
|
|
267
|
-
shape: ImageShapeRecord,
|
|
268
|
-
): ImageCropAspectRatioPresetValue | null {
|
|
269
|
-
const shapeAspectRatio = shape.props.w / shape.props.h;
|
|
270
|
-
for (const preset of IMAGE_CROP_ASPECT_RATIO_PRESETS) {
|
|
271
|
-
if (Math.abs(shapeAspectRatio - preset.ratio) <= 0.01) {
|
|
272
|
-
return preset.value;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
return null;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
export function isImageCropModeForShape(
|
|
279
|
-
shape: ImageShapeRecord,
|
|
280
|
-
markId: string | null | undefined,
|
|
281
|
-
): boolean {
|
|
282
|
-
return markId === getImageCropModeMarkId(shape.id);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
export function getImageCropModeMarkId(shapeId: ImageShapeRecord["id"]): string {
|
|
286
|
-
return `${IMAGE_CROP_MODE_ENTRY_MARK_PREFIX}${shapeId}`;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
export function getImageCropHandleIds(): readonly SelectionResizeHandleId[] {
|
|
290
|
-
return IMAGE_CROP_HANDLE_IDS;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
export function isImageCropHandleId(
|
|
294
|
-
value: string,
|
|
295
|
-
): value is SelectionResizeHandleId {
|
|
296
|
-
return IMAGE_CROP_HANDLE_IDS.some((id) => id === value);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
export function getImageCropHandleCursor(
|
|
300
|
-
handleId: SelectionResizeHandleId,
|
|
301
|
-
): string {
|
|
302
|
-
return IMAGE_CROP_HANDLE_CURSORS[handleId];
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
function movesLeftCropEdge(handleId: SelectionResizeHandleId): boolean {
|
|
306
|
-
return (
|
|
307
|
-
handleId === "top_left" ||
|
|
308
|
-
handleId === "left" ||
|
|
309
|
-
handleId === "bottom_left"
|
|
310
|
-
);
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
function movesRightCropEdge(handleId: SelectionResizeHandleId): boolean {
|
|
314
|
-
return (
|
|
315
|
-
handleId === "top_right" ||
|
|
316
|
-
handleId === "right" ||
|
|
317
|
-
handleId === "bottom_right"
|
|
318
|
-
);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
function movesTopCropEdge(handleId: SelectionResizeHandleId): boolean {
|
|
322
|
-
return (
|
|
323
|
-
handleId === "top_left" ||
|
|
324
|
-
handleId === "top" ||
|
|
325
|
-
handleId === "top_right"
|
|
326
|
-
);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
function movesBottomCropEdge(handleId: SelectionResizeHandleId): boolean {
|
|
330
|
-
return (
|
|
331
|
-
handleId === "bottom_left" ||
|
|
332
|
-
handleId === "bottom" ||
|
|
333
|
-
handleId === "bottom_right"
|
|
334
|
-
);
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
export function getImageCropHandleAnchors({
|
|
338
|
-
localToPage,
|
|
339
|
-
shape,
|
|
340
|
-
}: {
|
|
341
|
-
crop: ImageShapeCrop | null | undefined;
|
|
342
|
-
localToPage: { applyToPoint(point: Vec): Vec };
|
|
343
|
-
shape: ImageShapeRecord;
|
|
344
|
-
}): ImageCropCustomHandleAnchor[] {
|
|
345
|
-
const left = 0;
|
|
346
|
-
const right = shape.props.w;
|
|
347
|
-
const top = 0;
|
|
348
|
-
const bottom = shape.props.h;
|
|
349
|
-
const centerX = (left + right) / 2;
|
|
350
|
-
const centerY = (top + bottom) / 2;
|
|
351
|
-
const points: Record<SelectionResizeHandleId, Vec> = {
|
|
352
|
-
top_left: new Vec(left, top),
|
|
353
|
-
top: new Vec(centerX, top),
|
|
354
|
-
top_right: new Vec(right, top),
|
|
355
|
-
right: new Vec(right, centerY),
|
|
356
|
-
bottom_right: new Vec(right, bottom),
|
|
357
|
-
bottom: new Vec(centerX, bottom),
|
|
358
|
-
bottom_left: new Vec(left, bottom),
|
|
359
|
-
left: new Vec(left, centerY),
|
|
360
|
-
};
|
|
361
|
-
|
|
362
|
-
return IMAGE_CROP_HANDLE_IDS.map((id) => ({
|
|
363
|
-
kind: "custom" as const,
|
|
364
|
-
type: IMAGE_CROP_HANDLE_TYPE,
|
|
365
|
-
id,
|
|
366
|
-
point: localToPage.applyToPoint(points[id]),
|
|
367
|
-
cursor: getImageCropHandleCursor(id),
|
|
368
|
-
}));
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
export function getImageCropUpdateFromHandleDrag({
|
|
372
|
-
handleId,
|
|
373
|
-
pageToLocal,
|
|
374
|
-
shape,
|
|
375
|
-
startCrop,
|
|
376
|
-
startPagePoint,
|
|
377
|
-
currentPagePoint,
|
|
378
|
-
}: {
|
|
379
|
-
handleId: SelectionResizeHandleId;
|
|
380
|
-
pageToLocal: { applyToPoint(point: Vec): Vec };
|
|
381
|
-
shape: ImageShapeRecord;
|
|
382
|
-
startCrop: ImageShapeCrop | null | undefined;
|
|
383
|
-
startPagePoint: Vec;
|
|
384
|
-
currentPagePoint: Vec;
|
|
385
|
-
}): ShapeUpdate | null {
|
|
386
|
-
const crop = normalizeImageShapeCrop(startCrop) ?? getDefaultImageCrop();
|
|
387
|
-
const uncroppedSize = getUncroppedImageSize({ crop, shape });
|
|
388
|
-
if (
|
|
389
|
-
uncroppedSize.w < MIN_CROP_SIZE ||
|
|
390
|
-
uncroppedSize.h < MIN_CROP_SIZE
|
|
391
|
-
) {
|
|
392
|
-
return null;
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
const originLocalPoint = pageToLocal.applyToPoint(startPagePoint);
|
|
396
|
-
const currentLocalPoint = pageToLocal.applyToPoint(currentPagePoint);
|
|
397
|
-
const change = currentLocalPoint.sub(originLocalPoint);
|
|
398
|
-
if (change.x === 0 && change.y === 0) {
|
|
399
|
-
return null;
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
const previousCropBox = {
|
|
403
|
-
x: crop.topLeft.x * uncroppedSize.w,
|
|
404
|
-
y: crop.topLeft.y * uncroppedSize.h,
|
|
405
|
-
w: (crop.bottomRight.x - crop.topLeft.x) * uncroppedSize.w,
|
|
406
|
-
h: (crop.bottomRight.y - crop.topLeft.y) * uncroppedSize.h,
|
|
407
|
-
};
|
|
408
|
-
const previousMaxX = previousCropBox.x + previousCropBox.w;
|
|
409
|
-
const previousMaxY = previousCropBox.y + previousCropBox.h;
|
|
410
|
-
let nextX = previousCropBox.x;
|
|
411
|
-
let nextY = previousCropBox.y;
|
|
412
|
-
let nextW = previousCropBox.w;
|
|
413
|
-
let nextH = previousCropBox.h;
|
|
414
|
-
|
|
415
|
-
if (movesLeftCropEdge(handleId)) {
|
|
416
|
-
nextX = clamp(nextX + change.x, 0, previousMaxX - MIN_CROP_SIZE);
|
|
417
|
-
nextW = previousMaxX - nextX;
|
|
418
|
-
} else if (movesRightCropEdge(handleId)) {
|
|
419
|
-
const nextRight = clamp(
|
|
420
|
-
previousMaxX + change.x,
|
|
421
|
-
previousCropBox.x + MIN_CROP_SIZE,
|
|
422
|
-
uncroppedSize.w,
|
|
423
|
-
);
|
|
424
|
-
nextW = nextRight - nextX;
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
if (movesTopCropEdge(handleId)) {
|
|
428
|
-
nextY = clamp(nextY + change.y, 0, previousMaxY - MIN_CROP_SIZE);
|
|
429
|
-
nextH = previousMaxY - nextY;
|
|
430
|
-
} else if (movesBottomCropEdge(handleId)) {
|
|
431
|
-
const nextBottom = clamp(
|
|
432
|
-
previousMaxY + change.y,
|
|
433
|
-
previousCropBox.y + MIN_CROP_SIZE,
|
|
434
|
-
uncroppedSize.h,
|
|
435
|
-
);
|
|
436
|
-
nextH = nextBottom - nextY;
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
const nextCrop = normalizeImageShapeCrop({
|
|
440
|
-
topLeft: {
|
|
441
|
-
x: nextX / uncroppedSize.w,
|
|
442
|
-
y: nextY / uncroppedSize.h,
|
|
443
|
-
},
|
|
444
|
-
bottomRight: {
|
|
445
|
-
x: (nextX + nextW) / uncroppedSize.w,
|
|
446
|
-
y: (nextY + nextH) / uncroppedSize.h,
|
|
447
|
-
},
|
|
448
|
-
});
|
|
449
|
-
if (!nextCrop) {
|
|
450
|
-
return null;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
const delta = new Vec(
|
|
454
|
-
nextX - crop.topLeft.x * uncroppedSize.w,
|
|
455
|
-
nextY - crop.topLeft.y * uncroppedSize.h,
|
|
456
|
-
);
|
|
457
|
-
const pageDelta = delta.rot(shape.rotation);
|
|
458
|
-
|
|
459
|
-
return {
|
|
460
|
-
id: shape.id,
|
|
461
|
-
x: shape.x + pageDelta.x,
|
|
462
|
-
y: shape.y + pageDelta.y,
|
|
463
|
-
props: {
|
|
464
|
-
w: nextW,
|
|
465
|
-
h: nextH,
|
|
466
|
-
crop: nextCrop,
|
|
467
|
-
},
|
|
468
|
-
};
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
export function getImageCropUpdateFromContentDrag({
|
|
472
|
-
currentPagePoint,
|
|
473
|
-
pageToLocal,
|
|
474
|
-
shape,
|
|
475
|
-
startCrop,
|
|
476
|
-
startPagePoint,
|
|
477
|
-
shiftKey,
|
|
478
|
-
}: {
|
|
479
|
-
currentPagePoint: Vec;
|
|
480
|
-
pageToLocal: { applyToPoint(point: Vec): Vec };
|
|
481
|
-
shape: ImageShapeRecord;
|
|
482
|
-
startCrop: ImageShapeCrop | null | undefined;
|
|
483
|
-
startPagePoint: Vec;
|
|
484
|
-
shiftKey: boolean;
|
|
485
|
-
}): ShapeUpdate | null {
|
|
486
|
-
const crop = normalizeImageShapeCrop(startCrop);
|
|
487
|
-
if (!crop) {
|
|
488
|
-
return null;
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
const originLocalPoint = pageToLocal.applyToPoint(startPagePoint);
|
|
492
|
-
const currentLocalPoint = pageToLocal.applyToPoint(currentPagePoint);
|
|
493
|
-
let change = currentLocalPoint.sub(originLocalPoint);
|
|
494
|
-
if (shiftKey) {
|
|
495
|
-
change =
|
|
496
|
-
Math.abs(change.x) < Math.abs(change.y)
|
|
497
|
-
? new Vec(0, change.y)
|
|
498
|
-
: new Vec(change.x, 0);
|
|
499
|
-
}
|
|
500
|
-
if (change.x === 0 && change.y === 0) {
|
|
501
|
-
return null;
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
return getImageCropUpdateFromContentLocalChange({
|
|
505
|
-
change,
|
|
506
|
-
crop,
|
|
507
|
-
shape,
|
|
508
|
-
});
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
export function getImageCropUpdateFromContentNudge({
|
|
512
|
-
pageDelta,
|
|
513
|
-
shape,
|
|
514
|
-
startCrop,
|
|
515
|
-
}: {
|
|
516
|
-
pageDelta: Vec;
|
|
517
|
-
shape: ImageShapeRecord;
|
|
518
|
-
startCrop: ImageShapeCrop | null | undefined;
|
|
519
|
-
}): ShapeUpdate | null {
|
|
520
|
-
const crop = normalizeImageShapeCrop(startCrop);
|
|
521
|
-
if (!crop || pageDelta.equals(Vec.Zero())) {
|
|
522
|
-
return null;
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
return getImageCropUpdateFromContentLocalChange({
|
|
526
|
-
change: pageDelta.rot(-shape.rotation),
|
|
527
|
-
crop,
|
|
528
|
-
shape,
|
|
529
|
-
});
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
function getImageCropUpdateFromContentLocalChange({
|
|
533
|
-
change,
|
|
534
|
-
crop,
|
|
535
|
-
shape,
|
|
536
|
-
}: {
|
|
537
|
-
change: Vec;
|
|
538
|
-
crop: ImageShapeCrop;
|
|
539
|
-
shape: ImageShapeRecord;
|
|
540
|
-
}): ShapeUpdate | null {
|
|
541
|
-
const uncroppedSize = getUncroppedImageSize({ crop, shape });
|
|
542
|
-
const cropWidth = crop.bottomRight.x - crop.topLeft.x;
|
|
543
|
-
const cropHeight = crop.bottomRight.y - crop.topLeft.y;
|
|
544
|
-
const nextTopLeftX = clamp(
|
|
545
|
-
crop.topLeft.x - change.x / uncroppedSize.w,
|
|
546
|
-
0,
|
|
547
|
-
1 - cropWidth,
|
|
548
|
-
);
|
|
549
|
-
const nextTopLeftY = clamp(
|
|
550
|
-
crop.topLeft.y - change.y / uncroppedSize.h,
|
|
551
|
-
0,
|
|
552
|
-
1 - cropHeight,
|
|
553
|
-
);
|
|
554
|
-
|
|
555
|
-
const nextCrop = normalizeImageShapeCrop({
|
|
556
|
-
topLeft: {
|
|
557
|
-
x: nextTopLeftX,
|
|
558
|
-
y: nextTopLeftY,
|
|
559
|
-
},
|
|
560
|
-
bottomRight: {
|
|
561
|
-
x: nextTopLeftX + cropWidth,
|
|
562
|
-
y: nextTopLeftY + cropHeight,
|
|
563
|
-
},
|
|
564
|
-
});
|
|
565
|
-
if (!nextCrop) {
|
|
566
|
-
return null;
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
return {
|
|
570
|
-
id: shape.id,
|
|
571
|
-
props: {
|
|
572
|
-
crop: nextCrop,
|
|
573
|
-
},
|
|
574
|
-
};
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
export function getImageCropUpdateFromZoom({
|
|
578
|
-
direction,
|
|
579
|
-
shape,
|
|
580
|
-
}: {
|
|
581
|
-
direction: "in" | "out";
|
|
582
|
-
shape: ImageShapeRecord;
|
|
583
|
-
}): ShapeUpdate | null {
|
|
584
|
-
const rect = getImageCropRectOrDefault(shape.props.crop);
|
|
585
|
-
const center = getImageCropRectCenter(rect);
|
|
586
|
-
const rawFactor =
|
|
587
|
-
direction === "in" ? IMAGE_CROP_ZOOM_FACTOR : 1 / IMAGE_CROP_ZOOM_FACTOR;
|
|
588
|
-
const minFactor = Math.max(
|
|
589
|
-
MIN_NORMALIZED_CROP_SIZE / rect.width,
|
|
590
|
-
MIN_NORMALIZED_CROP_SIZE / rect.height,
|
|
591
|
-
);
|
|
592
|
-
const maxFactor = Math.min(1 / rect.width, 1 / rect.height);
|
|
593
|
-
const factor = clamp(rawFactor, minFactor, maxFactor);
|
|
594
|
-
const nextRect = getCenteredCropRect({
|
|
595
|
-
centerX: center.x,
|
|
596
|
-
centerY: center.y,
|
|
597
|
-
width: rect.width * factor,
|
|
598
|
-
height: rect.height * factor,
|
|
599
|
-
});
|
|
600
|
-
if (areCropRectsEqual(rect, nextRect)) {
|
|
601
|
-
return null;
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
return {
|
|
605
|
-
id: shape.id,
|
|
606
|
-
props: {
|
|
607
|
-
crop: getImageCropFromRect(nextRect),
|
|
608
|
-
},
|
|
609
|
-
};
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
function getImageCropUpdateWithLockedImagePlacement({
|
|
613
|
-
nextRect,
|
|
614
|
-
shape,
|
|
615
|
-
}: {
|
|
616
|
-
nextRect: ImageCropRect;
|
|
617
|
-
shape: ImageShapeRecord;
|
|
618
|
-
}): ShapeUpdate | null {
|
|
619
|
-
const currentRect = getImageCropRectOrDefault(shape.props.crop);
|
|
620
|
-
if (areCropRectsEqual(currentRect, nextRect)) {
|
|
621
|
-
return null;
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
const uncroppedSize = getUncroppedImageSize({
|
|
625
|
-
crop: shape.props.crop,
|
|
626
|
-
shape,
|
|
627
|
-
});
|
|
628
|
-
const localDelta = new Vec(
|
|
629
|
-
(nextRect.left - currentRect.left) * uncroppedSize.w,
|
|
630
|
-
(nextRect.top - currentRect.top) * uncroppedSize.h,
|
|
631
|
-
);
|
|
632
|
-
const pageDelta = localDelta.rot(shape.rotation);
|
|
633
|
-
|
|
634
|
-
return {
|
|
635
|
-
id: shape.id,
|
|
636
|
-
x: shape.x + pageDelta.x,
|
|
637
|
-
y: shape.y + pageDelta.y,
|
|
638
|
-
props: {
|
|
639
|
-
w: nextRect.width * uncroppedSize.w,
|
|
640
|
-
h: nextRect.height * uncroppedSize.h,
|
|
641
|
-
crop: getImageCropFromRect(nextRect),
|
|
642
|
-
},
|
|
643
|
-
};
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
export function getImageCropUpdateFromAspectRatioPreset({
|
|
647
|
-
preset,
|
|
648
|
-
shape,
|
|
649
|
-
}: {
|
|
650
|
-
preset: ImageCropAspectRatioPresetValue;
|
|
651
|
-
shape: ImageShapeRecord;
|
|
652
|
-
}): ShapeUpdate | null {
|
|
653
|
-
const currentRect = getImageCropRectOrDefault(shape.props.crop);
|
|
654
|
-
const center = getImageCropRectCenter(currentRect);
|
|
655
|
-
const uncroppedSize = getUncroppedImageSize({
|
|
656
|
-
crop: shape.props.crop,
|
|
657
|
-
shape,
|
|
658
|
-
});
|
|
659
|
-
const presetRatio =
|
|
660
|
-
IMAGE_CROP_ASPECT_RATIO_PRESETS.find((candidate) => candidate.value === preset)
|
|
661
|
-
?.ratio ?? null;
|
|
662
|
-
if (!presetRatio) {
|
|
663
|
-
return null;
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
const normalizedCropAspectRatio =
|
|
667
|
-
presetRatio * (uncroppedSize.h / uncroppedSize.w);
|
|
668
|
-
let nextWidth = currentRect.width;
|
|
669
|
-
let nextHeight = nextWidth / normalizedCropAspectRatio;
|
|
670
|
-
if (nextHeight > currentRect.height) {
|
|
671
|
-
nextHeight = currentRect.height;
|
|
672
|
-
nextWidth = nextHeight * normalizedCropAspectRatio;
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
const nextRect = getCenteredCropRect({
|
|
676
|
-
centerX: center.x,
|
|
677
|
-
centerY: center.y,
|
|
678
|
-
width: nextWidth,
|
|
679
|
-
height: nextHeight,
|
|
680
|
-
});
|
|
681
|
-
return getImageCropUpdateWithLockedImagePlacement({
|
|
682
|
-
nextRect,
|
|
683
|
-
shape,
|
|
684
|
-
});
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
export function getImageCropResetUpdate({
|
|
688
|
-
baselineShape,
|
|
689
|
-
shape,
|
|
690
|
-
}: {
|
|
691
|
-
baselineShape: ImageShapeRecord;
|
|
692
|
-
shape: ImageShapeRecord;
|
|
693
|
-
}): ShapeUpdate | null {
|
|
694
|
-
const nextX = baselineShape.x;
|
|
695
|
-
const nextY = baselineShape.y;
|
|
696
|
-
const nextW = baselineShape.props.w;
|
|
697
|
-
const nextH = baselineShape.props.h;
|
|
698
|
-
const nextCrop = normalizeImageShapeCrop(baselineShape.props.crop);
|
|
699
|
-
if (
|
|
700
|
-
Math.abs(shape.x - nextX) <= IMAGE_CROP_EPSILON &&
|
|
701
|
-
Math.abs(shape.y - nextY) <= IMAGE_CROP_EPSILON &&
|
|
702
|
-
Math.abs(shape.props.w - nextW) <= IMAGE_CROP_EPSILON &&
|
|
703
|
-
Math.abs(shape.props.h - nextH) <= IMAGE_CROP_EPSILON &&
|
|
704
|
-
((shape.props.crop === null && nextCrop === null) ||
|
|
705
|
-
(shape.props.crop !== null &&
|
|
706
|
-
nextCrop !== null &&
|
|
707
|
-
Math.abs(shape.props.crop.topLeft.x - nextCrop.topLeft.x) <=
|
|
708
|
-
IMAGE_CROP_EPSILON &&
|
|
709
|
-
Math.abs(shape.props.crop.topLeft.y - nextCrop.topLeft.y) <=
|
|
710
|
-
IMAGE_CROP_EPSILON &&
|
|
711
|
-
Math.abs(shape.props.crop.bottomRight.x - nextCrop.bottomRight.x) <=
|
|
712
|
-
IMAGE_CROP_EPSILON &&
|
|
713
|
-
Math.abs(shape.props.crop.bottomRight.y - nextCrop.bottomRight.y) <=
|
|
714
|
-
IMAGE_CROP_EPSILON))
|
|
715
|
-
) {
|
|
716
|
-
return null;
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
return {
|
|
720
|
-
id: shape.id,
|
|
721
|
-
x: nextX,
|
|
722
|
-
y: nextY,
|
|
723
|
-
props: {
|
|
724
|
-
w: nextW,
|
|
725
|
-
h: nextH,
|
|
726
|
-
crop: nextCrop,
|
|
727
|
-
},
|
|
728
|
-
};
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
export function getImageCropPlacement({
|
|
732
|
-
crop,
|
|
733
|
-
shapeHeight,
|
|
734
|
-
shapeWidth,
|
|
735
|
-
}: {
|
|
736
|
-
crop: ImageShapeCrop | null | undefined;
|
|
737
|
-
shapeHeight: number;
|
|
738
|
-
shapeWidth: number;
|
|
739
|
-
}): ImageCropPlacement | null {
|
|
740
|
-
const rect = getImageCropRect(crop);
|
|
741
|
-
if (!rect) {
|
|
742
|
-
return null;
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
const imageWidth = shapeWidth / rect.width;
|
|
746
|
-
const imageHeight = shapeHeight / rect.height;
|
|
747
|
-
return {
|
|
748
|
-
imageX: -rect.left * imageWidth,
|
|
749
|
-
imageY: -rect.top * imageHeight,
|
|
750
|
-
imageWidth,
|
|
751
|
-
imageHeight,
|
|
752
|
-
rect,
|
|
753
|
-
};
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
export function formatImageCropViewBox(rect: ImageCropRect): string {
|
|
757
|
-
return [
|
|
758
|
-
formatCropNumber(rect.left),
|
|
759
|
-
formatCropNumber(rect.top),
|
|
760
|
-
formatCropNumber(rect.width),
|
|
761
|
-
formatCropNumber(rect.height),
|
|
762
|
-
].join(" ");
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
function formatCropNumber(value: number): string {
|
|
766
|
-
if (!Number.isFinite(value)) {
|
|
767
|
-
return "0";
|
|
768
|
-
}
|
|
769
|
-
return Number(value.toFixed(4)).toString();
|
|
770
|
-
}
|