@excalidraw/excalidraw 0.17.1-88812e0 → 0.17.1-96eeec5
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/CHANGELOG.md +2 -0
- package/dist/browser/dev/excalidraw-assets-dev/{chunk-47LVF2XL.js → chunk-DEYXWPUO.js} +4933 -1520
- package/dist/browser/dev/excalidraw-assets-dev/chunk-DEYXWPUO.js.map +7 -0
- package/dist/browser/dev/excalidraw-assets-dev/{chunk-XOM7LNOU.js → chunk-EM6LVGFW.js} +27 -4
- package/dist/browser/dev/excalidraw-assets-dev/chunk-EM6LVGFW.js.map +7 -0
- package/dist/browser/dev/excalidraw-assets-dev/{dist-ITJNUBZF.js → dist-6QVAH5JA.js} +36 -14
- package/dist/browser/dev/excalidraw-assets-dev/dist-6QVAH5JA.js.map +7 -0
- package/dist/browser/dev/excalidraw-assets-dev/{en-TR4QLF5E.js → en-AZFA5HJJ.js} +4 -2
- package/dist/browser/dev/excalidraw-assets-dev/{image-LHMGJWTI.js → image-5XCR4WHS.js} +2 -2
- package/dist/browser/dev/index.css +157 -62
- package/dist/browser/dev/index.css.map +3 -3
- package/dist/browser/dev/index.js +12016 -7663
- package/dist/browser/dev/index.js.map +4 -4
- package/dist/browser/prod/excalidraw-assets/{chunk-5SYIAZGL.js → chunk-7DXALCB2.js} +5 -5
- package/dist/browser/prod/excalidraw-assets/chunk-ODWTVSS7.js +68 -0
- package/dist/browser/prod/excalidraw-assets/dist-567JAXHK.js +7 -0
- package/dist/browser/prod/excalidraw-assets/en-6E7MYLWO.js +1 -0
- package/dist/browser/prod/excalidraw-assets/image-LQAMCFQI.js +1 -0
- package/dist/browser/prod/index.css +1 -1
- package/dist/browser/prod/index.js +69 -51
- package/dist/dev/{en-XW4JO6VX.json → en-EB2MBPAV.json} +24 -3
- package/dist/dev/index.css +157 -62
- package/dist/dev/index.css.map +3 -3
- package/dist/dev/index.js +18250 -16114
- package/dist/dev/index.js.map +4 -4
- package/dist/excalidraw/actions/actionAddToLibrary.d.ts +15 -6
- package/dist/excalidraw/actions/actionAlign.d.ts +8 -8
- package/dist/excalidraw/actions/actionBoundText.d.ts +14 -8
- package/dist/excalidraw/actions/actionBoundText.js +3 -1
- package/dist/excalidraw/actions/actionCanvas.d.ts +64 -28
- package/dist/excalidraw/actions/actionCanvas.js +1 -1
- package/dist/excalidraw/actions/actionClipboard.d.ts +40 -19
- package/dist/excalidraw/actions/actionDeleteSelected.d.ts +17 -8
- package/dist/excalidraw/actions/actionDistribute.d.ts +4 -4
- package/dist/excalidraw/actions/actionDuplicateSelection.d.ts +3 -3
- package/dist/excalidraw/actions/actionElementLock.d.ts +11 -5
- package/dist/excalidraw/actions/actionExport.d.ts +48 -21
- package/dist/excalidraw/actions/actionFinalize.d.ts +11 -5
- package/dist/excalidraw/actions/actionFinalize.js +1 -1
- package/dist/excalidraw/actions/actionFlip.d.ts +4 -4
- package/dist/excalidraw/actions/actionFlip.js +5 -6
- package/dist/excalidraw/actions/actionFrame.d.ts +328 -8
- package/dist/excalidraw/actions/actionGroup.d.ts +320 -4
- package/dist/excalidraw/actions/actionHistory.d.ts +3 -3
- package/dist/excalidraw/actions/actionHistory.js +4 -4
- package/dist/excalidraw/actions/actionLinearEditor.d.ts +9 -4
- package/dist/excalidraw/actions/actionLinearEditor.js +19 -4
- package/dist/excalidraw/actions/actionLink.d.ts +5 -2
- package/dist/excalidraw/actions/actionMenu.d.ts +15 -6
- package/dist/excalidraw/actions/actionNavigate.d.ts +11 -5
- package/dist/excalidraw/actions/actionProperties.d.ts +67 -28
- package/dist/excalidraw/actions/actionProperties.js +1 -1
- package/dist/excalidraw/actions/actionSelectAll.d.ts +6 -3
- package/dist/excalidraw/actions/actionStyles.d.ts +9 -3
- package/dist/excalidraw/actions/actionTextAutoResize.d.ts +17 -0
- package/dist/excalidraw/actions/actionTextAutoResize.js +38 -0
- package/dist/excalidraw/actions/actionToggleGridMode.d.ts +6 -3
- package/dist/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +5 -2
- package/dist/excalidraw/actions/actionToggleStats.d.ts +6 -2
- package/dist/excalidraw/actions/actionToggleStats.js +4 -3
- package/dist/excalidraw/actions/actionToggleViewMode.d.ts +5 -2
- package/dist/excalidraw/actions/actionToggleZenMode.d.ts +5 -2
- package/dist/excalidraw/actions/actionZindex.d.ts +8 -4
- package/dist/excalidraw/actions/actionZindex.js +4 -0
- package/dist/excalidraw/actions/manager.d.ts +3 -3
- package/dist/excalidraw/actions/register.d.ts +1 -1
- package/dist/excalidraw/actions/shortcuts.d.ts +2 -2
- package/dist/excalidraw/actions/types.d.ts +6 -6
- package/dist/excalidraw/align.d.ts +1 -1
- package/dist/excalidraw/animated-trail.d.ts +2 -2
- package/dist/excalidraw/appState.d.ts +5 -2
- package/dist/excalidraw/appState.js +6 -3
- package/dist/excalidraw/change.d.ts +4 -4
- package/dist/excalidraw/change.js +14 -7
- package/dist/excalidraw/charts.d.ts +1 -1
- package/dist/excalidraw/clients.d.ts +2 -2
- package/dist/excalidraw/clients.js +1 -1
- package/dist/excalidraw/clipboard.d.ts +3 -3
- package/dist/excalidraw/colors.d.ts +1 -1
- package/dist/excalidraw/components/Actions.d.ts +3 -3
- package/dist/excalidraw/components/Actions.js +9 -6
- package/dist/excalidraw/components/App.d.ts +10 -16
- package/dist/excalidraw/components/App.js +190 -142
- package/dist/excalidraw/components/ButtonIconSelect.js +1 -1
- package/dist/excalidraw/components/CheckboxItem.js +1 -1
- package/dist/excalidraw/components/ColorPicker/ColorInput.d.ts +1 -1
- package/dist/excalidraw/components/ColorPicker/ColorInput.js +1 -1
- package/dist/excalidraw/components/ColorPicker/ColorPicker.d.ts +4 -4
- package/dist/excalidraw/components/ColorPicker/ColorPicker.js +1 -1
- package/dist/excalidraw/components/ColorPicker/Picker.d.ts +3 -3
- package/dist/excalidraw/components/ColorPicker/PickerColorList.d.ts +1 -1
- package/dist/excalidraw/components/ColorPicker/PickerHeading.d.ts +1 -1
- package/dist/excalidraw/components/ColorPicker/ShadeList.d.ts +1 -1
- package/dist/excalidraw/components/ColorPicker/TopPicks.d.ts +1 -1
- package/dist/excalidraw/components/ColorPicker/colorPickerUtils.d.ts +2 -2
- package/dist/excalidraw/components/ColorPicker/colorPickerUtils.js +1 -1
- package/dist/excalidraw/components/ColorPicker/keyboardNavHandlers.d.ts +2 -2
- package/dist/excalidraw/components/ColorPicker/keyboardNavHandlers.js +1 -1
- package/dist/excalidraw/components/CommandPalette/CommandPalette.d.ts +1 -1
- package/dist/excalidraw/components/CommandPalette/CommandPalette.js +5 -5
- package/dist/excalidraw/components/CommandPalette/defaultCommandPaletteItems.d.ts +1 -1
- package/dist/excalidraw/components/CommandPalette/types.d.ts +3 -3
- package/dist/excalidraw/components/ConfirmDialog.d.ts +1 -1
- package/dist/excalidraw/components/ContextMenu.d.ts +2 -2
- package/dist/excalidraw/components/ContextMenu.js +2 -2
- package/dist/excalidraw/components/DarkModeToggle.d.ts +1 -1
- package/dist/excalidraw/components/DefaultSidebar.d.ts +2 -2
- package/dist/excalidraw/components/Dialog.js +1 -1
- package/dist/excalidraw/components/DialogActionButton.d.ts +1 -1
- package/dist/excalidraw/components/EyeDropper.d.ts +2 -2
- package/dist/excalidraw/components/FollowMode/FollowMode.d.ts +1 -1
- package/dist/excalidraw/components/FollowMode/FollowMode.js +1 -1
- package/dist/excalidraw/components/HelpDialog.js +1 -1
- package/dist/excalidraw/components/HintViewer.d.ts +1 -1
- package/dist/excalidraw/components/IconPicker.js +2 -2
- package/dist/excalidraw/components/ImageExportDialog.d.ts +1 -1
- package/dist/excalidraw/components/InitializeApp.d.ts +2 -2
- package/dist/excalidraw/components/JSONExportDialog.d.ts +3 -3
- package/dist/excalidraw/components/LayerUI.d.ts +4 -4
- package/dist/excalidraw/components/LayerUI.js +10 -7
- package/dist/excalidraw/components/LibraryMenu.d.ts +2 -2
- package/dist/excalidraw/components/LibraryMenuBrowseButton.d.ts +1 -1
- package/dist/excalidraw/components/LibraryMenuControlButtons.d.ts +1 -1
- package/dist/excalidraw/components/LibraryMenuHeaderContent.d.ts +2 -2
- package/dist/excalidraw/components/LibraryMenuItems.d.ts +1 -1
- package/dist/excalidraw/components/LibraryMenuSection.d.ts +5 -4
- package/dist/excalidraw/components/LibraryUnit.d.ts +2 -2
- package/dist/excalidraw/components/LoadingMessage.d.ts +1 -1
- package/dist/excalidraw/components/MagicSettings.js +2 -2
- package/dist/excalidraw/components/MobileMenu.d.ts +3 -3
- package/dist/excalidraw/components/MobileMenu.js +2 -6
- package/dist/excalidraw/components/Modal.d.ts +1 -1
- package/dist/excalidraw/components/OverwriteConfirm/OverwriteConfirmState.d.ts +1 -1
- package/dist/excalidraw/components/PasteChartDialog.d.ts +1 -1
- package/dist/excalidraw/components/PasteChartDialog.js +1 -1
- package/dist/excalidraw/components/PublishLibrary.d.ts +1 -1
- package/dist/excalidraw/components/SVGLayer.d.ts +1 -1
- package/dist/excalidraw/components/Sidebar/Sidebar.js +1 -1
- package/dist/excalidraw/components/Sidebar/SidebarTab.d.ts +1 -1
- package/dist/excalidraw/components/Sidebar/SidebarTabTrigger.d.ts +1 -1
- package/dist/excalidraw/components/Sidebar/SidebarTrigger.d.ts +1 -1
- package/dist/excalidraw/components/Sidebar/common.d.ts +1 -1
- package/dist/excalidraw/components/Stats/Angle.d.ts +12 -0
- package/dist/excalidraw/components/Stats/Angle.js +52 -0
- package/dist/excalidraw/components/Stats/Collapsible.d.ts +9 -0
- package/dist/excalidraw/components/Stats/Collapsible.js +12 -0
- package/dist/excalidraw/components/Stats/Dimension.d.ts +12 -0
- package/dist/excalidraw/components/Stats/Dimension.js +67 -0
- package/dist/excalidraw/components/Stats/DragInput.d.ts +32 -0
- package/dist/excalidraw/components/Stats/DragInput.js +174 -0
- package/dist/excalidraw/components/Stats/FontSize.d.ts +12 -0
- package/dist/excalidraw/components/Stats/FontSize.js +50 -0
- package/dist/excalidraw/components/Stats/MultiAngle.d.ts +12 -0
- package/dist/excalidraw/components/Stats/MultiAngle.js +66 -0
- package/dist/excalidraw/components/Stats/MultiDimension.d.ts +15 -0
- package/dist/excalidraw/components/Stats/MultiDimension.js +197 -0
- package/dist/excalidraw/components/Stats/MultiFontSize.d.ts +13 -0
- package/dist/excalidraw/components/Stats/MultiFontSize.js +72 -0
- package/dist/excalidraw/components/Stats/MultiPosition.d.ts +15 -0
- package/dist/excalidraw/components/Stats/MultiPosition.js +100 -0
- package/dist/excalidraw/components/Stats/Position.d.ts +13 -0
- package/dist/excalidraw/components/Stats/Position.js +39 -0
- package/dist/excalidraw/components/Stats/index.d.ts +16 -0
- package/dist/excalidraw/components/Stats/index.js +78 -0
- package/dist/excalidraw/components/Stats/utils.d.ts +25 -0
- package/dist/excalidraw/components/Stats/utils.js +158 -0
- package/dist/excalidraw/components/TTDDialog/MermaidToExcalidraw.d.ts +1 -1
- package/dist/excalidraw/components/TTDDialog/TTDDialog.js +2 -2
- package/dist/excalidraw/components/TTDDialog/TTDDialogInput.d.ts +1 -1
- package/dist/excalidraw/components/TTDDialog/TTDDialogPanel.d.ts +1 -1
- package/dist/excalidraw/components/TTDDialog/TTDDialogPanels.d.ts +1 -1
- package/dist/excalidraw/components/TTDDialog/TTDDialogTabs.d.ts +1 -1
- package/dist/excalidraw/components/TTDDialog/TTDDialogTrigger.d.ts +1 -1
- package/dist/excalidraw/components/TTDDialog/common.d.ts +4 -4
- package/dist/excalidraw/components/TextField.d.ts +1 -1
- package/dist/excalidraw/components/Toast.d.ts +1 -1
- package/dist/excalidraw/components/ToolButton.d.ts +3 -2
- package/dist/excalidraw/components/Trans.d.ts +1 -1
- package/dist/excalidraw/components/UserList.d.ts +1 -1
- package/dist/excalidraw/components/canvases/InteractiveCanvas.d.ts +3 -2
- package/dist/excalidraw/components/canvases/InteractiveCanvas.js +4 -2
- package/dist/excalidraw/components/canvases/StaticCanvas.d.ts +2 -2
- package/dist/excalidraw/components/canvases/StaticCanvas.js +2 -2
- package/dist/excalidraw/components/dropdownMenu/DropdownMenuItem.js +2 -2
- package/dist/excalidraw/components/footer/Footer.d.ts +2 -2
- package/dist/excalidraw/components/hyperlink/Hyperlink.d.ts +2 -2
- package/dist/excalidraw/components/hyperlink/helpers.d.ts +3 -3
- package/dist/excalidraw/components/icons.d.ts +6 -2
- package/dist/excalidraw/components/icons.js +22 -6
- package/dist/excalidraw/constants.d.ts +8 -2
- package/dist/excalidraw/constants.js +8 -1
- package/dist/excalidraw/context/ui-appState.d.ts +1 -1
- package/dist/excalidraw/cursor.d.ts +1 -1
- package/dist/excalidraw/data/EditorLocalStorage.d.ts +2 -2
- package/dist/excalidraw/data/blob.d.ts +5 -5
- package/dist/excalidraw/data/filesystem.d.ts +2 -1
- package/dist/excalidraw/data/index.d.ts +4 -4
- package/dist/excalidraw/data/json.d.ts +3 -3
- package/dist/excalidraw/data/library.d.ts +3 -3
- package/dist/excalidraw/data/magic.d.ts +3 -3
- package/dist/excalidraw/data/reconcile.d.ts +3 -3
- package/dist/excalidraw/data/resave.d.ts +2 -2
- package/dist/excalidraw/data/restore.d.ts +3 -3
- package/dist/excalidraw/data/restore.js +16 -1
- package/dist/excalidraw/data/transform.d.ts +3 -3
- package/dist/excalidraw/data/types.d.ts +3 -3
- package/dist/excalidraw/element/ElementCanvasButtons.d.ts +1 -1
- package/dist/excalidraw/element/binding.d.ts +7 -21
- package/dist/excalidraw/element/binding.js +127 -102
- package/dist/excalidraw/element/bounds.d.ts +3 -3
- package/dist/excalidraw/element/collision.d.ts +3 -3
- package/dist/excalidraw/element/collision.js +1 -1
- package/dist/excalidraw/element/containerCache.d.ts +1 -1
- package/dist/excalidraw/element/dragElements.d.ts +4 -4
- package/dist/excalidraw/element/dragElements.js +27 -3
- package/dist/excalidraw/element/embeddable.d.ts +8 -5
- package/dist/excalidraw/element/image.d.ts +2 -2
- package/dist/excalidraw/element/index.d.ts +2 -2
- package/dist/excalidraw/element/index.js +1 -1
- package/dist/excalidraw/element/linearElementEditor.d.ts +8 -5
- package/dist/excalidraw/element/linearElementEditor.js +7 -4
- package/dist/excalidraw/element/mutateElement.d.ts +2 -2
- package/dist/excalidraw/element/mutateElement.js +1 -1
- package/dist/excalidraw/element/newElement.d.ts +5 -8
- package/dist/excalidraw/element/newElement.js +16 -14
- package/dist/excalidraw/element/resizeElements.d.ts +11 -3
- package/dist/excalidraw/element/resizeElements.js +75 -23
- package/dist/excalidraw/element/resizeTest.d.ts +4 -4
- package/dist/excalidraw/element/resizeTest.js +2 -4
- package/dist/excalidraw/element/showSelectedShapeActions.d.ts +2 -2
- package/dist/excalidraw/element/sizeHelpers.d.ts +2 -2
- package/dist/excalidraw/element/sortElements.d.ts +1 -1
- package/dist/excalidraw/element/textElement.d.ts +5 -4
- package/dist/excalidraw/element/textElement.js +11 -3
- package/dist/excalidraw/element/textWysiwyg.d.ts +12 -6
- package/dist/excalidraw/element/textWysiwyg.js +38 -17
- package/dist/excalidraw/element/transformHandles.d.ts +3 -3
- package/dist/excalidraw/element/transformHandles.js +0 -10
- package/dist/excalidraw/element/typeChecks.d.ts +4 -4
- package/dist/excalidraw/element/types.d.ts +11 -4
- package/dist/excalidraw/emitter.d.ts +1 -1
- package/dist/excalidraw/fractionalIndex.d.ts +1 -1
- package/dist/excalidraw/fractionalIndex.js +2 -4
- package/dist/excalidraw/frame.d.ts +3 -3
- package/dist/excalidraw/gatransforms.d.ts +1 -1
- package/dist/excalidraw/gesture.d.ts +1 -1
- package/dist/excalidraw/groups.d.ts +4 -4
- package/dist/excalidraw/history.d.ts +4 -4
- package/dist/excalidraw/hooks/useEmitter.d.ts +1 -1
- package/dist/excalidraw/hooks/useLibraryItemSvg.d.ts +1 -1
- package/dist/excalidraw/i18n.d.ts +1 -1
- package/dist/excalidraw/index.d.ts +1 -1
- package/dist/excalidraw/jotai.d.ts +1 -1
- package/dist/excalidraw/laser-trails.d.ts +3 -2
- package/dist/excalidraw/locales/en.json +24 -3
- package/dist/excalidraw/math.d.ts +4 -2
- package/dist/excalidraw/math.js +6 -0
- package/dist/excalidraw/mermaid.d.ts +2 -0
- package/dist/excalidraw/mermaid.js +28 -0
- package/dist/excalidraw/points.d.ts +1 -1
- package/dist/excalidraw/queue.d.ts +1 -1
- package/dist/excalidraw/renderer/helpers.d.ts +2 -2
- package/dist/excalidraw/renderer/interactiveScene.d.ts +2 -2
- package/dist/excalidraw/renderer/interactiveScene.js +32 -6
- package/dist/excalidraw/renderer/renderElement.d.ts +4 -4
- package/dist/excalidraw/renderer/renderElement.js +5 -5
- package/dist/excalidraw/renderer/renderSnaps.d.ts +1 -1
- package/dist/excalidraw/renderer/staticScene.d.ts +1 -1
- package/dist/excalidraw/renderer/staticSvgScene.d.ts +4 -4
- package/dist/excalidraw/scene/Fonts.d.ts +2 -4
- package/dist/excalidraw/scene/Fonts.js +12 -15
- package/dist/excalidraw/scene/Renderer.d.ts +4 -4
- package/dist/excalidraw/scene/Renderer.js +2 -3
- package/dist/excalidraw/scene/Scene.d.ts +16 -7
- package/dist/excalidraw/scene/Scene.js +17 -8
- package/dist/excalidraw/scene/Shape.d.ts +1 -1
- package/dist/excalidraw/scene/ShapeCache.d.ts +4 -4
- package/dist/excalidraw/scene/comparisons.d.ts +2 -2
- package/dist/excalidraw/scene/export.d.ts +2 -2
- package/dist/excalidraw/scene/export.js +2 -2
- package/dist/excalidraw/scene/scroll.d.ts +2 -2
- package/dist/excalidraw/scene/scrollbars.d.ts +3 -3
- package/dist/excalidraw/scene/selection.d.ts +2 -2
- package/dist/excalidraw/scene/types.d.ts +6 -8
- package/dist/excalidraw/scene/zoom.d.ts +1 -1
- package/dist/excalidraw/shapes.d.ts +7 -0
- package/dist/excalidraw/shapes.js +40 -0
- package/dist/excalidraw/snapping.d.ts +4 -4
- package/dist/excalidraw/snapping.js +2 -1
- package/dist/excalidraw/store.d.ts +34 -4
- package/dist/excalidraw/store.js +27 -0
- package/dist/excalidraw/types.d.ts +25 -20
- package/dist/excalidraw/utils.d.ts +4 -4
- package/dist/excalidraw/zindex.d.ts +2 -2
- package/dist/prod/{en-XW4JO6VX.json → en-EB2MBPAV.json} +24 -3
- package/dist/prod/index.css +1 -1
- package/dist/prod/index.js +39 -39
- package/dist/utils/bbox.d.ts +2 -2
- package/dist/utils/collision.d.ts +1 -1
- package/dist/utils/export.d.ts +2 -2
- package/dist/utils/geometry/geometry.d.ts +1 -1
- package/dist/utils/geometry/shape.d.ts +1 -1
- package/dist/utils/withinBounds.d.ts +1 -1
- package/history.ts +4 -4
- package/package.json +2 -2
- package/dist/browser/dev/excalidraw-assets-dev/chunk-47LVF2XL.js.map +0 -7
- package/dist/browser/dev/excalidraw-assets-dev/chunk-XOM7LNOU.js.map +0 -7
- package/dist/browser/dev/excalidraw-assets-dev/dist-ITJNUBZF.js.map +0 -7
- package/dist/browser/prod/excalidraw-assets/chunk-4SNEEDZH.js +0 -55
- package/dist/browser/prod/excalidraw-assets/dist-54276HPL.js +0 -6
- package/dist/browser/prod/excalidraw-assets/en-7GPZE2Y2.js +0 -1
- package/dist/browser/prod/excalidraw-assets/image-ISQJGWLB.js +0 -1
- package/dist/excalidraw/components/Stats.d.ts +0 -11
- package/dist/excalidraw/components/Stats.js +0 -13
- /package/dist/browser/dev/excalidraw-assets-dev/{en-TR4QLF5E.js.map → en-AZFA5HJJ.js.map} +0 -0
- /package/dist/browser/dev/excalidraw-assets-dev/{image-LHMGJWTI.js.map → image-5XCR4WHS.js.map} +0 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { ExcalidrawElement, NonDeletedSceneElementsMap } from "../../element/types";
|
|
3
|
+
import type Scene from "../../scene/Scene";
|
|
4
|
+
import type { AppState } from "../../types";
|
|
5
|
+
import type { AtomicUnit } from "./utils";
|
|
6
|
+
interface MultiDimensionProps {
|
|
7
|
+
property: "width" | "height";
|
|
8
|
+
elements: readonly ExcalidrawElement[];
|
|
9
|
+
elementsMap: NonDeletedSceneElementsMap;
|
|
10
|
+
atomicUnits: AtomicUnit[];
|
|
11
|
+
scene: Scene;
|
|
12
|
+
appState: AppState;
|
|
13
|
+
}
|
|
14
|
+
declare const MultiDimension: ({ property, elements, elementsMap, atomicUnits, scene, appState, }: MultiDimensionProps) => JSX.Element;
|
|
15
|
+
export default MultiDimension;
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import { getCommonBounds, isTextElement } from "../../element";
|
|
4
|
+
import { updateBoundElements } from "../../element/binding";
|
|
5
|
+
import { mutateElement } from "../../element/mutateElement";
|
|
6
|
+
import { rescalePointsInElement } from "../../element/resizeElements";
|
|
7
|
+
import { getBoundTextElement, handleBindTextResize, } from "../../element/textElement";
|
|
8
|
+
import DragInput from "./DragInput";
|
|
9
|
+
import { getAtomicUnits, getStepSizedValue, isPropertyEditable } from "./utils";
|
|
10
|
+
import { getElementsInAtomicUnit, resizeElement } from "./utils";
|
|
11
|
+
import { MIN_WIDTH_OR_HEIGHT } from "../../constants";
|
|
12
|
+
const STEP_SIZE = 10;
|
|
13
|
+
const getResizedUpdates = (anchorX, anchorY, scale, origElement) => {
|
|
14
|
+
const offsetX = origElement.x - anchorX;
|
|
15
|
+
const offsetY = origElement.y - anchorY;
|
|
16
|
+
const nextWidth = origElement.width * scale;
|
|
17
|
+
const nextHeight = origElement.height * scale;
|
|
18
|
+
const x = anchorX + offsetX * scale;
|
|
19
|
+
const y = anchorY + offsetY * scale;
|
|
20
|
+
return {
|
|
21
|
+
width: nextWidth,
|
|
22
|
+
height: nextHeight,
|
|
23
|
+
x,
|
|
24
|
+
y,
|
|
25
|
+
...rescalePointsInElement(origElement, nextWidth, nextHeight, false),
|
|
26
|
+
...(isTextElement(origElement)
|
|
27
|
+
? { fontSize: origElement.fontSize * scale }
|
|
28
|
+
: {}),
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
const resizeElementInGroup = (anchorX, anchorY, property, scale, latestElement, origElement, elementsMap, originalElementsMap) => {
|
|
32
|
+
const updates = getResizedUpdates(anchorX, anchorY, scale, origElement);
|
|
33
|
+
mutateElement(latestElement, updates, false);
|
|
34
|
+
const boundTextElement = getBoundTextElement(origElement, originalElementsMap);
|
|
35
|
+
if (boundTextElement) {
|
|
36
|
+
const newFontSize = boundTextElement.fontSize * scale;
|
|
37
|
+
updateBoundElements(latestElement, elementsMap, {
|
|
38
|
+
newSize: { width: updates.width, height: updates.height },
|
|
39
|
+
});
|
|
40
|
+
const latestBoundTextElement = elementsMap.get(boundTextElement.id);
|
|
41
|
+
if (latestBoundTextElement && isTextElement(latestBoundTextElement)) {
|
|
42
|
+
mutateElement(latestBoundTextElement, {
|
|
43
|
+
fontSize: newFontSize,
|
|
44
|
+
}, false);
|
|
45
|
+
handleBindTextResize(latestElement, elementsMap, property === "width" ? "e" : "s", true);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const resizeGroup = (nextWidth, nextHeight, initialHeight, aspectRatio, anchor, property, latestElements, originalElements, elementsMap, originalElementsMap) => {
|
|
50
|
+
// keep aspect ratio for groups
|
|
51
|
+
if (property === "width") {
|
|
52
|
+
nextHeight = Math.round((nextWidth / aspectRatio) * 100) / 100;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
nextWidth = Math.round(nextHeight * aspectRatio * 100) / 100;
|
|
56
|
+
}
|
|
57
|
+
const scale = nextHeight / initialHeight;
|
|
58
|
+
for (let i = 0; i < originalElements.length; i++) {
|
|
59
|
+
const origElement = originalElements[i];
|
|
60
|
+
const latestElement = latestElements[i];
|
|
61
|
+
resizeElementInGroup(anchor[0], anchor[1], property, scale, latestElement, origElement, elementsMap, originalElementsMap);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const handleDimensionChange = ({ accumulatedChange, originalElements, originalElementsMap, originalAppState, shouldChangeByStepSize, nextValue, scene, property, }) => {
|
|
65
|
+
const elementsMap = scene.getNonDeletedElementsMap();
|
|
66
|
+
const atomicUnits = getAtomicUnits(originalElements, originalAppState);
|
|
67
|
+
if (nextValue !== undefined) {
|
|
68
|
+
for (const atomicUnit of atomicUnits) {
|
|
69
|
+
const elementsInUnit = getElementsInAtomicUnit(atomicUnit, elementsMap, originalElementsMap);
|
|
70
|
+
if (elementsInUnit.length > 1) {
|
|
71
|
+
const latestElements = elementsInUnit.map((el) => el.latest);
|
|
72
|
+
const originalElements = elementsInUnit.map((el) => el.original);
|
|
73
|
+
const [x1, y1, x2, y2] = getCommonBounds(originalElements);
|
|
74
|
+
const initialWidth = x2 - x1;
|
|
75
|
+
const initialHeight = y2 - y1;
|
|
76
|
+
const aspectRatio = initialWidth / initialHeight;
|
|
77
|
+
const nextWidth = Math.max(MIN_WIDTH_OR_HEIGHT, property === "width" ? Math.max(0, nextValue) : initialWidth);
|
|
78
|
+
const nextHeight = Math.max(MIN_WIDTH_OR_HEIGHT, property === "height" ? Math.max(0, nextValue) : initialHeight);
|
|
79
|
+
resizeGroup(nextWidth, nextHeight, initialHeight, aspectRatio, [x1, y1], property, latestElements, originalElements, elementsMap, originalElementsMap);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
const [el] = elementsInUnit;
|
|
83
|
+
const latestElement = el?.latest;
|
|
84
|
+
const origElement = el?.original;
|
|
85
|
+
if (latestElement &&
|
|
86
|
+
origElement &&
|
|
87
|
+
isPropertyEditable(latestElement, property)) {
|
|
88
|
+
let nextWidth = property === "width" ? Math.max(0, nextValue) : latestElement.width;
|
|
89
|
+
if (property === "width") {
|
|
90
|
+
if (shouldChangeByStepSize) {
|
|
91
|
+
nextWidth = getStepSizedValue(nextWidth, STEP_SIZE);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
nextWidth = Math.round(nextWidth);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
let nextHeight = property === "height"
|
|
98
|
+
? Math.max(0, nextValue)
|
|
99
|
+
: latestElement.height;
|
|
100
|
+
if (property === "height") {
|
|
101
|
+
if (shouldChangeByStepSize) {
|
|
102
|
+
nextHeight = getStepSizedValue(nextHeight, STEP_SIZE);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
nextHeight = Math.round(nextHeight);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
nextWidth = Math.max(MIN_WIDTH_OR_HEIGHT, nextWidth);
|
|
109
|
+
nextHeight = Math.max(MIN_WIDTH_OR_HEIGHT, nextHeight);
|
|
110
|
+
resizeElement(nextWidth, nextHeight, false, origElement, elementsMap, false);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
scene.triggerUpdate();
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const changeInWidth = property === "width" ? accumulatedChange : 0;
|
|
118
|
+
const changeInHeight = property === "height" ? accumulatedChange : 0;
|
|
119
|
+
for (const atomicUnit of atomicUnits) {
|
|
120
|
+
const elementsInUnit = getElementsInAtomicUnit(atomicUnit, elementsMap, originalElementsMap);
|
|
121
|
+
if (elementsInUnit.length > 1) {
|
|
122
|
+
const latestElements = elementsInUnit.map((el) => el.latest);
|
|
123
|
+
const originalElements = elementsInUnit.map((el) => el.original);
|
|
124
|
+
const [x1, y1, x2, y2] = getCommonBounds(originalElements);
|
|
125
|
+
const initialWidth = x2 - x1;
|
|
126
|
+
const initialHeight = y2 - y1;
|
|
127
|
+
const aspectRatio = initialWidth / initialHeight;
|
|
128
|
+
let nextWidth = Math.max(0, initialWidth + changeInWidth);
|
|
129
|
+
if (property === "width") {
|
|
130
|
+
if (shouldChangeByStepSize) {
|
|
131
|
+
nextWidth = getStepSizedValue(nextWidth, STEP_SIZE);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
nextWidth = Math.round(nextWidth);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
let nextHeight = Math.max(0, initialHeight + changeInHeight);
|
|
138
|
+
if (property === "height") {
|
|
139
|
+
if (shouldChangeByStepSize) {
|
|
140
|
+
nextHeight = getStepSizedValue(nextHeight, STEP_SIZE);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
nextHeight = Math.round(nextHeight);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
nextWidth = Math.max(MIN_WIDTH_OR_HEIGHT, nextWidth);
|
|
147
|
+
nextHeight = Math.max(MIN_WIDTH_OR_HEIGHT, nextHeight);
|
|
148
|
+
resizeGroup(nextWidth, nextHeight, initialHeight, aspectRatio, [x1, y1], property, latestElements, originalElements, elementsMap, originalElementsMap);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
const [el] = elementsInUnit;
|
|
152
|
+
const latestElement = el?.latest;
|
|
153
|
+
const origElement = el?.original;
|
|
154
|
+
if (latestElement &&
|
|
155
|
+
origElement &&
|
|
156
|
+
isPropertyEditable(latestElement, property)) {
|
|
157
|
+
let nextWidth = Math.max(0, origElement.width + changeInWidth);
|
|
158
|
+
if (property === "width") {
|
|
159
|
+
if (shouldChangeByStepSize) {
|
|
160
|
+
nextWidth = getStepSizedValue(nextWidth, STEP_SIZE);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
nextWidth = Math.round(nextWidth);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
let nextHeight = Math.max(0, origElement.height + changeInHeight);
|
|
167
|
+
if (property === "height") {
|
|
168
|
+
if (shouldChangeByStepSize) {
|
|
169
|
+
nextHeight = getStepSizedValue(nextHeight, STEP_SIZE);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
nextHeight = Math.round(nextHeight);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
nextWidth = Math.max(MIN_WIDTH_OR_HEIGHT, nextWidth);
|
|
176
|
+
nextHeight = Math.max(MIN_WIDTH_OR_HEIGHT, nextHeight);
|
|
177
|
+
resizeElement(nextWidth, nextHeight, false, origElement, elementsMap);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
scene.triggerUpdate();
|
|
182
|
+
};
|
|
183
|
+
const MultiDimension = ({ property, elements, elementsMap, atomicUnits, scene, appState, }) => {
|
|
184
|
+
const sizes = useMemo(() => atomicUnits.map((atomicUnit) => {
|
|
185
|
+
const elementsInUnit = getElementsInAtomicUnit(atomicUnit, elementsMap);
|
|
186
|
+
if (elementsInUnit.length > 1) {
|
|
187
|
+
const [x1, y1, x2, y2] = getCommonBounds(elementsInUnit.map((el) => el.latest));
|
|
188
|
+
return (Math.round((property === "width" ? x2 - x1 : y2 - y1) * 100) / 100);
|
|
189
|
+
}
|
|
190
|
+
const [el] = elementsInUnit;
|
|
191
|
+
return (Math.round((property === "width" ? el.latest.width : el.latest.height) * 100) / 100);
|
|
192
|
+
}), [elementsMap, atomicUnits, property]);
|
|
193
|
+
const value = new Set(sizes).size === 1 ? Math.round(sizes[0] * 100) / 100 : "Mixed";
|
|
194
|
+
const editable = sizes.length > 0;
|
|
195
|
+
return (_jsx(DragInput, { label: property === "width" ? "W" : "H", elements: elements, dragInputCallback: handleDimensionChange, value: value, editable: editable, appState: appState, property: property, scene: scene }));
|
|
196
|
+
};
|
|
197
|
+
export default MultiDimension;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { ExcalidrawElement, NonDeletedSceneElementsMap } from "../../element/types";
|
|
3
|
+
import type Scene from "../../scene/Scene";
|
|
4
|
+
import type { AppState } from "../../types";
|
|
5
|
+
interface MultiFontSizeProps {
|
|
6
|
+
elements: readonly ExcalidrawElement[];
|
|
7
|
+
scene: Scene;
|
|
8
|
+
elementsMap: NonDeletedSceneElementsMap;
|
|
9
|
+
appState: AppState;
|
|
10
|
+
property: "fontSize";
|
|
11
|
+
}
|
|
12
|
+
declare const MultiFontSize: ({ elements, scene, appState, property, elementsMap, }: MultiFontSizeProps) => JSX.Element | null;
|
|
13
|
+
export default MultiFontSize;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { isTextElement, redrawTextBoundingBox } from "../../element";
|
|
3
|
+
import { mutateElement } from "../../element/mutateElement";
|
|
4
|
+
import { hasBoundTextElement } from "../../element/typeChecks";
|
|
5
|
+
import { isInGroup } from "../../groups";
|
|
6
|
+
import { fontSizeIcon } from "../icons";
|
|
7
|
+
import StatsDragInput from "./DragInput";
|
|
8
|
+
import { getStepSizedValue } from "./utils";
|
|
9
|
+
import { getBoundTextElement } from "../../element/textElement";
|
|
10
|
+
const MIN_FONT_SIZE = 4;
|
|
11
|
+
const STEP_SIZE = 4;
|
|
12
|
+
const getApplicableTextElements = (elements, elementsMap) => elements.reduce((acc, el) => {
|
|
13
|
+
if (!el || isInGroup(el)) {
|
|
14
|
+
return acc;
|
|
15
|
+
}
|
|
16
|
+
if (isTextElement(el)) {
|
|
17
|
+
acc.push(el);
|
|
18
|
+
return acc;
|
|
19
|
+
}
|
|
20
|
+
if (hasBoundTextElement(el)) {
|
|
21
|
+
const boundTextElement = getBoundTextElement(el, elementsMap);
|
|
22
|
+
if (boundTextElement) {
|
|
23
|
+
acc.push(boundTextElement);
|
|
24
|
+
return acc;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return acc;
|
|
28
|
+
}, []);
|
|
29
|
+
const handleFontSizeChange = ({ accumulatedChange, originalElements, shouldChangeByStepSize, nextValue, scene, }) => {
|
|
30
|
+
const elementsMap = scene.getNonDeletedElementsMap();
|
|
31
|
+
const latestTextElements = originalElements.map((el) => elementsMap.get(el.id));
|
|
32
|
+
let nextFontSize;
|
|
33
|
+
if (nextValue) {
|
|
34
|
+
nextFontSize = Math.max(Math.round(nextValue), MIN_FONT_SIZE);
|
|
35
|
+
for (const textElement of latestTextElements) {
|
|
36
|
+
mutateElement(textElement, {
|
|
37
|
+
fontSize: nextFontSize,
|
|
38
|
+
}, false);
|
|
39
|
+
redrawTextBoundingBox(textElement, scene.getContainerElement(textElement), elementsMap, false);
|
|
40
|
+
}
|
|
41
|
+
scene.triggerUpdate();
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
const originalTextElements = originalElements;
|
|
45
|
+
for (let i = 0; i < latestTextElements.length; i++) {
|
|
46
|
+
const latestElement = latestTextElements[i];
|
|
47
|
+
const originalElement = originalTextElements[i];
|
|
48
|
+
const originalFontSize = Math.round(originalElement.fontSize);
|
|
49
|
+
const changeInFontSize = Math.round(accumulatedChange);
|
|
50
|
+
let nextFontSize = Math.max(originalFontSize + changeInFontSize, MIN_FONT_SIZE);
|
|
51
|
+
if (shouldChangeByStepSize) {
|
|
52
|
+
nextFontSize = getStepSizedValue(nextFontSize, STEP_SIZE);
|
|
53
|
+
}
|
|
54
|
+
mutateElement(latestElement, {
|
|
55
|
+
fontSize: nextFontSize,
|
|
56
|
+
}, false);
|
|
57
|
+
redrawTextBoundingBox(latestElement, scene.getContainerElement(latestElement), elementsMap, false);
|
|
58
|
+
}
|
|
59
|
+
scene.triggerUpdate();
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const MultiFontSize = ({ elements, scene, appState, property, elementsMap, }) => {
|
|
63
|
+
const latestTextElements = getApplicableTextElements(elements, elementsMap);
|
|
64
|
+
if (!latestTextElements.length) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
const fontSizes = latestTextElements.map((textEl) => Math.round(textEl.fontSize * 10) / 10);
|
|
68
|
+
const value = new Set(fontSizes).size === 1 ? fontSizes[0] : "Mixed";
|
|
69
|
+
const editable = fontSizes.length > 0;
|
|
70
|
+
return (_jsx(StatsDragInput, { label: "F", icon: fontSizeIcon, elements: latestTextElements, dragInputCallback: handleFontSizeChange, value: value, editable: editable, scene: scene, property: property, appState: appState }));
|
|
71
|
+
};
|
|
72
|
+
export default MultiFontSize;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { ElementsMap, ExcalidrawElement } from "../../element/types";
|
|
3
|
+
import type Scene from "../../scene/Scene";
|
|
4
|
+
import type { AtomicUnit } from "./utils";
|
|
5
|
+
import type { AppState } from "../../types";
|
|
6
|
+
interface MultiPositionProps {
|
|
7
|
+
property: "x" | "y";
|
|
8
|
+
elements: readonly ExcalidrawElement[];
|
|
9
|
+
elementsMap: ElementsMap;
|
|
10
|
+
atomicUnits: AtomicUnit[];
|
|
11
|
+
scene: Scene;
|
|
12
|
+
appState: AppState;
|
|
13
|
+
}
|
|
14
|
+
declare const MultiPosition: ({ property, elements, elementsMap, atomicUnits, scene, appState, }: MultiPositionProps) => JSX.Element;
|
|
15
|
+
export default MultiPosition;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { rotate } from "../../math";
|
|
3
|
+
import StatsDragInput from "./DragInput";
|
|
4
|
+
import { getAtomicUnits, getStepSizedValue, isPropertyEditable } from "./utils";
|
|
5
|
+
import { getCommonBounds, isTextElement } from "../../element";
|
|
6
|
+
import { useMemo } from "react";
|
|
7
|
+
import { getElementsInAtomicUnit, moveElement } from "./utils";
|
|
8
|
+
const STEP_SIZE = 10;
|
|
9
|
+
const moveElements = (property, changeInTopX, changeInTopY, elements, originalElements, elementsMap, originalElementsMap) => {
|
|
10
|
+
for (let i = 0; i < elements.length; i++) {
|
|
11
|
+
const origElement = originalElements[i];
|
|
12
|
+
const [cx, cy] = [
|
|
13
|
+
origElement.x + origElement.width / 2,
|
|
14
|
+
origElement.y + origElement.height / 2,
|
|
15
|
+
];
|
|
16
|
+
const [topLeftX, topLeftY] = rotate(origElement.x, origElement.y, cx, cy, origElement.angle);
|
|
17
|
+
const newTopLeftX = property === "x" ? Math.round(topLeftX + changeInTopX) : topLeftX;
|
|
18
|
+
const newTopLeftY = property === "y" ? Math.round(topLeftY + changeInTopY) : topLeftY;
|
|
19
|
+
moveElement(newTopLeftX, newTopLeftY, origElement, elementsMap, originalElementsMap, false);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const moveGroupTo = (nextX, nextY, originalElements, elementsMap, originalElementsMap, scene) => {
|
|
23
|
+
const [x1, y1, ,] = getCommonBounds(originalElements);
|
|
24
|
+
const offsetX = nextX - x1;
|
|
25
|
+
const offsetY = nextY - y1;
|
|
26
|
+
for (let i = 0; i < originalElements.length; i++) {
|
|
27
|
+
const origElement = originalElements[i];
|
|
28
|
+
const latestElement = elementsMap.get(origElement.id);
|
|
29
|
+
if (!latestElement) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
// bound texts are moved with their containers
|
|
33
|
+
if (!isTextElement(latestElement) || !latestElement.containerId) {
|
|
34
|
+
const [cx, cy] = [
|
|
35
|
+
latestElement.x + latestElement.width / 2,
|
|
36
|
+
latestElement.y + latestElement.height / 2,
|
|
37
|
+
];
|
|
38
|
+
const [topLeftX, topLeftY] = rotate(latestElement.x, latestElement.y, cx, cy, latestElement.angle);
|
|
39
|
+
moveElement(topLeftX + offsetX, topLeftY + offsetY, origElement, elementsMap, originalElementsMap, false);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const handlePositionChange = ({ accumulatedChange, originalElements, originalElementsMap, shouldChangeByStepSize, nextValue, property, scene, originalAppState, }) => {
|
|
44
|
+
const elementsMap = scene.getNonDeletedElementsMap();
|
|
45
|
+
if (nextValue !== undefined) {
|
|
46
|
+
for (const atomicUnit of getAtomicUnits(originalElements, originalAppState)) {
|
|
47
|
+
const elementsInUnit = getElementsInAtomicUnit(atomicUnit, elementsMap, originalElementsMap);
|
|
48
|
+
if (elementsInUnit.length > 1) {
|
|
49
|
+
const [x1, y1, ,] = getCommonBounds(elementsInUnit.map((el) => el.latest));
|
|
50
|
+
const newTopLeftX = property === "x" ? nextValue : x1;
|
|
51
|
+
const newTopLeftY = property === "y" ? nextValue : y1;
|
|
52
|
+
moveGroupTo(newTopLeftX, newTopLeftY, elementsInUnit.map((el) => el.original), elementsMap, originalElementsMap, scene);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
const origElement = elementsInUnit[0]?.original;
|
|
56
|
+
const latestElement = elementsInUnit[0]?.latest;
|
|
57
|
+
if (origElement &&
|
|
58
|
+
latestElement &&
|
|
59
|
+
isPropertyEditable(latestElement, property)) {
|
|
60
|
+
const [cx, cy] = [
|
|
61
|
+
origElement.x + origElement.width / 2,
|
|
62
|
+
origElement.y + origElement.height / 2,
|
|
63
|
+
];
|
|
64
|
+
const [topLeftX, topLeftY] = rotate(origElement.x, origElement.y, cx, cy, origElement.angle);
|
|
65
|
+
const newTopLeftX = property === "x" ? nextValue : topLeftX;
|
|
66
|
+
const newTopLeftY = property === "y" ? nextValue : topLeftY;
|
|
67
|
+
moveElement(newTopLeftX, newTopLeftY, origElement, elementsMap, originalElementsMap, false);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
scene.triggerUpdate();
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const change = shouldChangeByStepSize
|
|
75
|
+
? getStepSizedValue(accumulatedChange, STEP_SIZE)
|
|
76
|
+
: accumulatedChange;
|
|
77
|
+
const changeInTopX = property === "x" ? change : 0;
|
|
78
|
+
const changeInTopY = property === "y" ? change : 0;
|
|
79
|
+
moveElements(property, changeInTopX, changeInTopY, originalElements, originalElements, elementsMap, originalElementsMap);
|
|
80
|
+
scene.triggerUpdate();
|
|
81
|
+
};
|
|
82
|
+
const MultiPosition = ({ property, elements, elementsMap, atomicUnits, scene, appState, }) => {
|
|
83
|
+
const positions = useMemo(() => atomicUnits.map((atomicUnit) => {
|
|
84
|
+
const elementsInUnit = Object.keys(atomicUnit)
|
|
85
|
+
.map((id) => elementsMap.get(id))
|
|
86
|
+
.filter((el) => el !== undefined);
|
|
87
|
+
// we're dealing with a group
|
|
88
|
+
if (elementsInUnit.length > 1) {
|
|
89
|
+
const [x1, y1] = getCommonBounds(elementsInUnit);
|
|
90
|
+
return Math.round((property === "x" ? x1 : y1) * 100) / 100;
|
|
91
|
+
}
|
|
92
|
+
const [el] = elementsInUnit;
|
|
93
|
+
const [cx, cy] = [el.x + el.width / 2, el.y + el.height / 2];
|
|
94
|
+
const [topLeftX, topLeftY] = rotate(el.x, el.y, cx, cy, el.angle);
|
|
95
|
+
return Math.round((property === "x" ? topLeftX : topLeftY) * 100) / 100;
|
|
96
|
+
}), [atomicUnits, elementsMap, property]);
|
|
97
|
+
const value = new Set(positions).size === 1 ? positions[0] : "Mixed";
|
|
98
|
+
return (_jsx(StatsDragInput, { label: property === "x" ? "X" : "Y", elements: elements, dragInputCallback: handlePositionChange, value: value, property: property, scene: scene, appState: appState }));
|
|
99
|
+
};
|
|
100
|
+
export default MultiPosition;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { ElementsMap, ExcalidrawElement } from "../../element/types";
|
|
3
|
+
import type Scene from "../../scene/Scene";
|
|
4
|
+
import type { AppState } from "../../types";
|
|
5
|
+
interface PositionProps {
|
|
6
|
+
property: "x" | "y";
|
|
7
|
+
element: ExcalidrawElement;
|
|
8
|
+
elementsMap: ElementsMap;
|
|
9
|
+
scene: Scene;
|
|
10
|
+
appState: AppState;
|
|
11
|
+
}
|
|
12
|
+
declare const Position: ({ property, element, elementsMap, scene, appState, }: PositionProps) => JSX.Element;
|
|
13
|
+
export default Position;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { rotate } from "../../math";
|
|
3
|
+
import StatsDragInput from "./DragInput";
|
|
4
|
+
import { getStepSizedValue, moveElement } from "./utils";
|
|
5
|
+
const STEP_SIZE = 10;
|
|
6
|
+
const handlePositionChange = ({ accumulatedChange, originalElements, originalElementsMap, shouldChangeByStepSize, nextValue, property, scene, }) => {
|
|
7
|
+
const elementsMap = scene.getNonDeletedElementsMap();
|
|
8
|
+
const origElement = originalElements[0];
|
|
9
|
+
const [cx, cy] = [
|
|
10
|
+
origElement.x + origElement.width / 2,
|
|
11
|
+
origElement.y + origElement.height / 2,
|
|
12
|
+
];
|
|
13
|
+
const [topLeftX, topLeftY] = rotate(origElement.x, origElement.y, cx, cy, origElement.angle);
|
|
14
|
+
if (nextValue !== undefined) {
|
|
15
|
+
const newTopLeftX = property === "x" ? nextValue : topLeftX;
|
|
16
|
+
const newTopLeftY = property === "y" ? nextValue : topLeftY;
|
|
17
|
+
moveElement(newTopLeftX, newTopLeftY, origElement, elementsMap, originalElementsMap);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const changeInTopX = property === "x" ? accumulatedChange : 0;
|
|
21
|
+
const changeInTopY = property === "y" ? accumulatedChange : 0;
|
|
22
|
+
const newTopLeftX = property === "x"
|
|
23
|
+
? Math.round(shouldChangeByStepSize
|
|
24
|
+
? getStepSizedValue(origElement.x + changeInTopX, STEP_SIZE)
|
|
25
|
+
: topLeftX + changeInTopX)
|
|
26
|
+
: topLeftX;
|
|
27
|
+
const newTopLeftY = property === "y"
|
|
28
|
+
? Math.round(shouldChangeByStepSize
|
|
29
|
+
? getStepSizedValue(origElement.y + changeInTopY, STEP_SIZE)
|
|
30
|
+
: topLeftY + changeInTopY)
|
|
31
|
+
: topLeftY;
|
|
32
|
+
moveElement(newTopLeftX, newTopLeftY, origElement, elementsMap, originalElementsMap);
|
|
33
|
+
};
|
|
34
|
+
const Position = ({ property, element, elementsMap, scene, appState, }) => {
|
|
35
|
+
const [topLeftX, topLeftY] = rotate(element.x, element.y, element.x + element.width / 2, element.y + element.height / 2, element.angle);
|
|
36
|
+
const value = Math.round((property === "x" ? topLeftX : topLeftY) * 100) / 100;
|
|
37
|
+
return (_jsx(StatsDragInput, { label: property === "x" ? "X" : "Y", elements: [element], dragInputCallback: handlePositionChange, value: value, property: property, scene: scene, appState: appState }));
|
|
38
|
+
};
|
|
39
|
+
export default Position;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { NonDeletedExcalidrawElement } from "../../element/types";
|
|
3
|
+
import type { AppState, ExcalidrawProps } from "../../types";
|
|
4
|
+
import type Scene from "../../scene/Scene";
|
|
5
|
+
interface StatsProps {
|
|
6
|
+
scene: Scene;
|
|
7
|
+
onClose: () => void;
|
|
8
|
+
renderCustomStats: ExcalidrawProps["renderCustomStats"];
|
|
9
|
+
}
|
|
10
|
+
export declare const Stats: (props: StatsProps) => JSX.Element;
|
|
11
|
+
export declare const StatsInner: import("react").MemoExoticComponent<({ scene, onClose, renderCustomStats, selectedElements, appState, sceneNonce, }: StatsProps & {
|
|
12
|
+
sceneNonce: number;
|
|
13
|
+
selectedElements: readonly NonDeletedExcalidrawElement[];
|
|
14
|
+
appState: AppState;
|
|
15
|
+
}) => JSX.Element>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useMemo, useState, memo } from "react";
|
|
3
|
+
import { getCommonBounds } from "../../element/bounds";
|
|
4
|
+
import { t } from "../../i18n";
|
|
5
|
+
import { CloseIcon } from "../icons";
|
|
6
|
+
import { Island } from "../Island";
|
|
7
|
+
import { throttle } from "lodash";
|
|
8
|
+
import Dimension from "./Dimension";
|
|
9
|
+
import Angle from "./Angle";
|
|
10
|
+
import FontSize from "./FontSize";
|
|
11
|
+
import MultiDimension from "./MultiDimension";
|
|
12
|
+
import { elementsAreInSameGroup } from "../../groups";
|
|
13
|
+
import MultiAngle from "./MultiAngle";
|
|
14
|
+
import MultiFontSize from "./MultiFontSize";
|
|
15
|
+
import Position from "./Position";
|
|
16
|
+
import MultiPosition from "./MultiPosition";
|
|
17
|
+
import Collapsible from "./Collapsible";
|
|
18
|
+
import { useExcalidrawAppState, useExcalidrawSetAppState } from "../App";
|
|
19
|
+
import { getAtomicUnits } from "./utils";
|
|
20
|
+
import { STATS_PANELS } from "../../constants";
|
|
21
|
+
const STATS_TIMEOUT = 50;
|
|
22
|
+
export const Stats = (props) => {
|
|
23
|
+
const appState = useExcalidrawAppState();
|
|
24
|
+
const sceneNonce = props.scene.getSceneNonce() || 1;
|
|
25
|
+
const selectedElements = props.scene.getSelectedElements({
|
|
26
|
+
selectedElementIds: appState.selectedElementIds,
|
|
27
|
+
includeBoundTextElement: false,
|
|
28
|
+
});
|
|
29
|
+
return (_jsx(StatsInner, { ...props, appState: appState, sceneNonce: sceneNonce, selectedElements: selectedElements }));
|
|
30
|
+
};
|
|
31
|
+
export const StatsInner = memo(({ scene, onClose, renderCustomStats, selectedElements, appState, sceneNonce, }) => {
|
|
32
|
+
const elements = scene.getNonDeletedElements();
|
|
33
|
+
const elementsMap = scene.getNonDeletedElementsMap();
|
|
34
|
+
const setAppState = useExcalidrawSetAppState();
|
|
35
|
+
const singleElement = selectedElements.length === 1 ? selectedElements[0] : null;
|
|
36
|
+
const multipleElements = selectedElements.length > 1 ? selectedElements : null;
|
|
37
|
+
const [sceneDimension, setSceneDimension] = useState({
|
|
38
|
+
width: 0,
|
|
39
|
+
height: 0,
|
|
40
|
+
});
|
|
41
|
+
const throttledSetSceneDimension = useMemo(() => throttle((elements) => {
|
|
42
|
+
const boundingBox = getCommonBounds(elements);
|
|
43
|
+
setSceneDimension({
|
|
44
|
+
width: Math.round(boundingBox[2]) - Math.round(boundingBox[0]),
|
|
45
|
+
height: Math.round(boundingBox[3]) - Math.round(boundingBox[1]),
|
|
46
|
+
});
|
|
47
|
+
}, STATS_TIMEOUT), []);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
throttledSetSceneDimension(elements);
|
|
50
|
+
}, [sceneNonce, elements, throttledSetSceneDimension]);
|
|
51
|
+
useEffect(() => () => throttledSetSceneDimension.cancel(), [throttledSetSceneDimension]);
|
|
52
|
+
const atomicUnits = useMemo(() => {
|
|
53
|
+
return getAtomicUnits(selectedElements, appState);
|
|
54
|
+
}, [selectedElements, appState]);
|
|
55
|
+
return (_jsx("div", { className: "Stats", children: _jsxs(Island, { padding: 3, children: [_jsxs("div", { className: "title", children: [_jsx("h2", { children: t("stats.title") }), _jsx("div", { className: "close", onClick: onClose, children: CloseIcon })] }), _jsx(Collapsible, { label: _jsx("h3", { children: t("stats.generalStats") }), open: !!(appState.stats.panels & STATS_PANELS.generalStats), openTrigger: () => setAppState((state) => {
|
|
56
|
+
return {
|
|
57
|
+
...state,
|
|
58
|
+
stats: {
|
|
59
|
+
open: true,
|
|
60
|
+
panels: state.stats.panels ^ STATS_PANELS.generalStats,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}), children: _jsx("table", { children: _jsxs("tbody", { children: [_jsx("tr", { children: _jsx("th", { colSpan: 2, children: t("stats.scene") }) }), _jsxs("tr", { children: [_jsx("td", { children: t("stats.elements") }), _jsx("td", { children: elements.length })] }), _jsxs("tr", { children: [_jsx("td", { children: t("stats.width") }), _jsx("td", { children: sceneDimension.width })] }), _jsxs("tr", { children: [_jsx("td", { children: t("stats.height") }), _jsx("td", { children: sceneDimension.height })] }), renderCustomStats?.(elements, appState)] }) }) }), selectedElements.length > 0 && (_jsx("div", { id: "elementStats", style: {
|
|
64
|
+
marginTop: 12,
|
|
65
|
+
}, children: _jsxs(Collapsible, { label: _jsx("h3", { children: t("stats.elementProperties") }), open: !!(appState.stats.panels & STATS_PANELS.elementProperties), openTrigger: () => setAppState((state) => {
|
|
66
|
+
return {
|
|
67
|
+
...state,
|
|
68
|
+
stats: {
|
|
69
|
+
open: true,
|
|
70
|
+
panels: state.stats.panels ^ STATS_PANELS.elementProperties,
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}), children: [singleElement && (_jsxs("div", { className: "sectionContent", children: [_jsx("div", { className: "elementType", children: t(`element.${singleElement.type}`) }), _jsxs("div", { className: "statsItem", children: [_jsx(Position, { element: singleElement, property: "x", elementsMap: elementsMap, scene: scene, appState: appState }), _jsx(Position, { element: singleElement, property: "y", elementsMap: elementsMap, scene: scene, appState: appState }), _jsx(Dimension, { property: "width", element: singleElement, scene: scene, appState: appState }), _jsx(Dimension, { property: "height", element: singleElement, scene: scene, appState: appState }), _jsx(Angle, { property: "angle", element: singleElement, scene: scene, appState: appState }), _jsx(FontSize, { property: "fontSize", element: singleElement, scene: scene, appState: appState })] })] })), multipleElements && (_jsxs("div", { className: "sectionContent", children: [elementsAreInSameGroup(multipleElements) && (_jsx("div", { className: "elementType", children: t("element.group") })), _jsxs("div", { className: "elementsCount", children: [_jsx("div", { children: t("stats.elements") }), _jsx("div", { children: selectedElements.length })] }), _jsxs("div", { className: "statsItem", children: [_jsx(MultiPosition, { property: "x", elements: multipleElements, elementsMap: elementsMap, atomicUnits: atomicUnits, scene: scene, appState: appState }), _jsx(MultiPosition, { property: "y", elements: multipleElements, elementsMap: elementsMap, atomicUnits: atomicUnits, scene: scene, appState: appState }), _jsx(MultiDimension, { property: "width", elements: multipleElements, elementsMap: elementsMap, atomicUnits: atomicUnits, scene: scene, appState: appState }), _jsx(MultiDimension, { property: "height", elements: multipleElements, elementsMap: elementsMap, atomicUnits: atomicUnits, scene: scene, appState: appState }), _jsx(MultiAngle, { property: "angle", elements: multipleElements, scene: scene, appState: appState }), _jsx(MultiFontSize, { property: "fontSize", elements: multipleElements, scene: scene, appState: appState, elementsMap: elementsMap })] })] }))] }) }))] }) }));
|
|
74
|
+
}, (prev, next) => {
|
|
75
|
+
return (prev.sceneNonce === next.sceneNonce &&
|
|
76
|
+
prev.selectedElements === next.selectedElements &&
|
|
77
|
+
prev.appState.stats.panels === next.appState.stats.panels);
|
|
78
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ElementsMap, ExcalidrawElement, NonDeletedExcalidrawElement, NonDeletedSceneElementsMap } from "../../element/types";
|
|
2
|
+
import type { AppState } from "../../types";
|
|
3
|
+
export type StatsInputProperty = "x" | "y" | "width" | "height" | "angle" | "fontSize";
|
|
4
|
+
export declare const SMALLEST_DELTA = 0.01;
|
|
5
|
+
export declare const isPropertyEditable: (element: ExcalidrawElement, property: keyof ExcalidrawElement) => boolean;
|
|
6
|
+
export declare const getStepSizedValue: (value: number, stepSize: number) => number;
|
|
7
|
+
export type AtomicUnit = Record<string, true>;
|
|
8
|
+
export declare const getElementsInAtomicUnit: (atomicUnit: AtomicUnit, elementsMap: ElementsMap, originalElementsMap?: ElementsMap) => {
|
|
9
|
+
original: NonDeletedExcalidrawElement;
|
|
10
|
+
latest: NonDeletedExcalidrawElement;
|
|
11
|
+
}[];
|
|
12
|
+
export declare const newOrigin: (x1: number, y1: number, w1: number, h1: number, w2: number, h2: number, angle: number) => {
|
|
13
|
+
x: number;
|
|
14
|
+
y: number;
|
|
15
|
+
};
|
|
16
|
+
export declare const resizeElement: (nextWidth: number, nextHeight: number, keepAspectRatio: boolean, origElement: ExcalidrawElement, elementsMap: NonDeletedSceneElementsMap, shouldInformMutation?: boolean) => void;
|
|
17
|
+
export declare const moveElement: (newTopLeftX: number, newTopLeftY: number, originalElement: ExcalidrawElement, elementsMap: NonDeletedSceneElementsMap, originalElementsMap: ElementsMap, shouldInformMutation?: boolean) => void;
|
|
18
|
+
export declare const getAtomicUnits: (targetElements: readonly ExcalidrawElement[], appState: AppState) => AtomicUnit[];
|
|
19
|
+
export declare const updateBindings: (latestElement: ExcalidrawElement, elementsMap: NonDeletedSceneElementsMap, options?: {
|
|
20
|
+
simultaneouslyUpdated?: readonly ExcalidrawElement[];
|
|
21
|
+
newSize?: {
|
|
22
|
+
width: number;
|
|
23
|
+
height: number;
|
|
24
|
+
};
|
|
25
|
+
}) => void;
|