tldraw 5.2.0-next.e2b8d10bf10e → 5.2.0
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/DOCS.md +20294 -0
- package/README.md +13 -1
- package/RELEASE_NOTES.md +2908 -0
- package/dist-cjs/index.d.ts +110 -23
- package/dist-cjs/index.js +3 -3
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/TldrawImage.js +0 -1
- package/dist-cjs/lib/TldrawImage.js.map +2 -2
- package/dist-cjs/lib/bindings/arrow/ArrowBindingUtil.js +2 -1
- package/dist-cjs/lib/bindings/arrow/ArrowBindingUtil.js.map +2 -2
- package/dist-cjs/lib/defaultEmbedDefinitions.js +3 -2
- package/dist-cjs/lib/defaultEmbedDefinitions.js.map +2 -2
- package/dist-cjs/lib/defaultOverlayUtils.js +11 -11
- package/dist-cjs/lib/defaultOverlayUtils.js.map +2 -2
- package/dist-cjs/lib/overlays/SelectionForegroundOverlayUtil.js +76 -64
- package/dist-cjs/lib/overlays/SelectionForegroundOverlayUtil.js.map +2 -2
- package/dist-cjs/lib/overlays/ShapeHandleOverlayUtil.js +1 -1
- package/dist-cjs/lib/overlays/ShapeHandleOverlayUtil.js.map +2 -2
- package/dist-cjs/lib/overlays/ShapeIndicatorOverlayUtil.js +107 -0
- package/dist-cjs/lib/overlays/ShapeIndicatorOverlayUtil.js.map +7 -0
- package/dist-cjs/lib/shapes/arrow/toolStates/Pointing.js +3 -0
- package/dist-cjs/lib/shapes/arrow/toolStates/Pointing.js.map +2 -2
- package/dist-cjs/lib/shapes/bookmark/BookmarkShapeUtil.js +12 -3
- package/dist-cjs/lib/shapes/bookmark/BookmarkShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/bookmark/bookmarks.js +54 -6
- package/dist-cjs/lib/shapes/bookmark/bookmarks.js.map +2 -2
- package/dist-cjs/lib/shapes/draw/DrawShapeUtil.js +2 -1
- package/dist-cjs/lib/shapes/draw/DrawShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/draw/getPath.js +1 -1
- package/dist-cjs/lib/shapes/draw/getPath.js.map +2 -2
- package/dist-cjs/lib/shapes/draw/toolStates/Drawing.js +45 -47
- package/dist-cjs/lib/shapes/draw/toolStates/Drawing.js.map +2 -2
- package/dist-cjs/lib/shapes/embed/EmbedShapeUtil.js +2 -1
- package/dist-cjs/lib/shapes/embed/EmbedShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/frame/FrameShapeTool.js +23 -18
- package/dist-cjs/lib/shapes/frame/FrameShapeTool.js.map +2 -2
- package/dist-cjs/lib/shapes/geo/GeoShapeUtil.js +1 -1
- package/dist-cjs/lib/shapes/geo/GeoShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/geo/toolStates/Pointing.js +3 -0
- package/dist-cjs/lib/shapes/geo/toolStates/Pointing.js.map +2 -2
- package/dist-cjs/lib/shapes/highlight/HighlightShapeUtil.js +11 -7
- package/dist-cjs/lib/shapes/highlight/HighlightShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/image/ImageShapeUtil.js +3 -11
- package/dist-cjs/lib/shapes/image/ImageShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/line/toolStates/Pointing.js +5 -1
- package/dist-cjs/lib/shapes/line/toolStates/Pointing.js.map +2 -2
- package/dist-cjs/lib/shapes/note/NoteShapeUtil.js +31 -41
- package/dist-cjs/lib/shapes/note/NoteShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/note/noteHelpers.js +1 -1
- package/dist-cjs/lib/shapes/note/noteHelpers.js.map +2 -2
- package/dist-cjs/lib/shapes/note/toolStates/Pointing.js +28 -6
- package/dist-cjs/lib/shapes/note/toolStates/Pointing.js.map +2 -2
- package/dist-cjs/lib/shapes/shared/PlainTextLabel.js +3 -2
- package/dist-cjs/lib/shapes/shared/PlainTextLabel.js.map +2 -2
- package/dist-cjs/lib/shapes/shared/RichTextLabel.js +3 -3
- package/dist-cjs/lib/shapes/shared/RichTextLabel.js.map +2 -2
- package/dist-cjs/lib/shapes/shared/defaultStyleDefs.js +17 -3
- package/dist-cjs/lib/shapes/shared/defaultStyleDefs.js.map +2 -2
- package/dist-cjs/lib/shapes/shared/freehand/core.js +424 -0
- package/dist-cjs/lib/shapes/shared/freehand/core.js.map +7 -0
- package/dist-cjs/lib/shapes/shared/freehand/fmt.js +106 -0
- package/dist-cjs/lib/shapes/shared/freehand/fmt.js.map +7 -0
- package/dist-cjs/lib/shapes/shared/freehand/getStroke.js +6 -6
- package/dist-cjs/lib/shapes/shared/freehand/getStroke.js.map +2 -2
- package/dist-cjs/lib/shapes/shared/freehand/getStrokeOutlinePoints.js +320 -86
- package/dist-cjs/lib/shapes/shared/freehand/getStrokeOutlinePoints.js.map +3 -3
- package/dist-cjs/lib/shapes/shared/freehand/getStrokePoints.js +20 -96
- package/dist-cjs/lib/shapes/shared/freehand/getStrokePoints.js.map +3 -3
- package/dist-cjs/lib/shapes/shared/freehand/svg.js +55 -19
- package/dist-cjs/lib/shapes/shared/freehand/svg.js.map +2 -2
- package/dist-cjs/lib/shapes/shared/freehand/svgInk.js +189 -97
- package/dist-cjs/lib/shapes/shared/freehand/svgInk.js.map +3 -3
- package/dist-cjs/lib/shapes/shared/freehand/types.js.map +1 -1
- package/dist-cjs/lib/shapes/shared/interpolate-props.js +6 -2
- package/dist-cjs/lib/shapes/shared/interpolate-props.js.map +2 -2
- package/dist-cjs/lib/shapes/text/toolStates/Pointing.js +3 -0
- package/dist-cjs/lib/shapes/text/toolStates/Pointing.js.map +2 -2
- package/dist-cjs/lib/tools/HandTool/HandTool.js +16 -6
- package/dist-cjs/lib/tools/HandTool/HandTool.js.map +2 -2
- package/dist-cjs/lib/tools/HandTool/childStates/Dragging.js +10 -1
- package/dist-cjs/lib/tools/HandTool/childStates/Dragging.js.map +2 -2
- package/dist-cjs/lib/tools/HandTool/childStates/OneFingerZooming.js +84 -0
- package/dist-cjs/lib/tools/HandTool/childStates/OneFingerZooming.js.map +7 -0
- package/dist-cjs/lib/tools/SelectTool/childStates/Idle.js +12 -0
- package/dist-cjs/lib/tools/SelectTool/childStates/Idle.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/PointingShape.js +4 -0
- package/dist-cjs/lib/tools/SelectTool/childStates/PointingShape.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/Resizing.js +107 -46
- package/dist-cjs/lib/tools/SelectTool/childStates/Resizing.js.map +2 -2
- package/dist-cjs/lib/ui/TldrawUi.js +4 -3
- package/dist-cjs/lib/ui/TldrawUi.js.map +2 -2
- package/dist-cjs/lib/ui/components/A11y.js +2 -0
- package/dist-cjs/lib/ui/components/A11y.js.map +2 -2
- package/dist-cjs/lib/ui/components/ContextMenu/DefaultContextMenu.js +14 -1
- package/dist-cjs/lib/ui/components/ContextMenu/DefaultContextMenu.js.map +2 -2
- package/dist-cjs/lib/ui/components/ContextMenu/DefaultContextMenuContent.js +0 -6
- package/dist-cjs/lib/ui/components/ContextMenu/DefaultContextMenuContent.js.map +2 -2
- package/dist-cjs/lib/ui/components/DefaultFollowingIndicator.js.map +2 -2
- package/dist-cjs/lib/ui/components/Dialogs.js +17 -37
- package/dist-cjs/lib/ui/components/Dialogs.js.map +2 -2
- package/dist-cjs/lib/ui/components/HelperButtons/BackToContent.js +19 -4
- package/dist-cjs/lib/ui/components/HelperButtons/BackToContent.js.map +2 -2
- package/dist-cjs/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.js +12 -2
- package/dist-cjs/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.js.map +2 -2
- package/dist-cjs/lib/ui/components/Minimap/DefaultMinimap.js +47 -70
- package/dist-cjs/lib/ui/components/Minimap/DefaultMinimap.js.map +2 -2
- package/dist-cjs/lib/ui/components/Minimap/MinimapManager.js +25 -46
- package/dist-cjs/lib/ui/components/Minimap/MinimapManager.js.map +2 -2
- package/dist-cjs/lib/ui/components/SharePanel/DefaultPeopleMenuAvatar.js.map +2 -2
- package/dist-cjs/lib/ui/components/SharePanel/DefaultPeopleMenuContent.js.map +2 -2
- package/dist-cjs/lib/ui/components/SharePanel/DefaultPeopleMenuFacePile.js.map +2 -2
- package/dist-cjs/lib/ui/components/SharePanel/DefaultPeopleMenuItem.js +1 -1
- package/dist-cjs/lib/ui/components/SharePanel/DefaultPeopleMenuItem.js.map +2 -2
- package/dist-cjs/lib/ui/components/StylePanel/StylePanelButtonPicker.js +1 -0
- package/dist-cjs/lib/ui/components/StylePanel/StylePanelButtonPicker.js.map +2 -2
- package/dist-cjs/lib/ui/components/menu-items.js +7 -0
- package/dist-cjs/lib/ui/components/menu-items.js.map +2 -2
- package/dist-cjs/lib/ui/components/primitives/TldrawUiDropdownMenu.js +2 -1
- package/dist-cjs/lib/ui/components/primitives/TldrawUiDropdownMenu.js.map +2 -2
- package/dist-cjs/lib/ui/components/primitives/TldrawUiIcon.js +14 -3
- package/dist-cjs/lib/ui/components/primitives/TldrawUiIcon.js.map +2 -2
- package/dist-cjs/lib/ui/components/primitives/TldrawUiInput.js +2 -0
- package/dist-cjs/lib/ui/components/primitives/TldrawUiInput.js.map +2 -2
- package/dist-cjs/lib/ui/components/primitives/TldrawUiPopover.js +2 -0
- package/dist-cjs/lib/ui/components/primitives/TldrawUiPopover.js.map +2 -2
- package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuCheckboxItem.js +0 -2
- package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuCheckboxItem.js.map +2 -2
- package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuSubmenu.js +1 -2
- package/dist-cjs/lib/ui/components/primitives/menus/TldrawUiMenuSubmenu.js.map +2 -2
- package/dist-cjs/lib/ui/context/actions.js +70 -1
- package/dist-cjs/lib/ui/context/actions.js.map +2 -2
- package/dist-cjs/lib/ui/context/asset-urls.js +5 -8
- package/dist-cjs/lib/ui/context/asset-urls.js.map +2 -2
- package/dist-cjs/lib/ui/context/events.js.map +2 -2
- package/dist-cjs/lib/ui/hooks/useKeyboardShortcuts.js +13 -0
- package/dist-cjs/lib/ui/hooks/useKeyboardShortcuts.js.map +2 -2
- package/dist-cjs/lib/ui/hooks/useTools.js +1 -1
- package/dist-cjs/lib/ui/hooks/useTools.js.map +2 -2
- package/dist-cjs/lib/ui/hooks/useTranslation/TLUiTranslationKey.js.map +1 -1
- package/dist-cjs/lib/ui/hooks/useTranslation/defaultTranslation.js +2 -0
- package/dist-cjs/lib/ui/hooks/useTranslation/defaultTranslation.js.map +2 -2
- package/dist-cjs/lib/ui/version.js +3 -3
- package/dist-cjs/lib/ui/version.js.map +1 -1
- package/dist-cjs/lib/utils/embeds/embeds.js +4 -4
- package/dist-cjs/lib/utils/embeds/embeds.js.map +2 -2
- package/dist-cjs/lib/utils/test-helpers.js +2 -2
- package/dist-cjs/lib/utils/test-helpers.js.map +2 -2
- package/dist-cjs/lib/utils/text/richText.js +3 -1
- package/dist-cjs/lib/utils/text/richText.js.map +2 -2
- package/dist-esm/index.d.mts +110 -23
- package/dist-esm/index.mjs +5 -3
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/TldrawImage.mjs +0 -1
- package/dist-esm/lib/TldrawImage.mjs.map +2 -2
- package/dist-esm/lib/bindings/arrow/ArrowBindingUtil.mjs +2 -1
- package/dist-esm/lib/bindings/arrow/ArrowBindingUtil.mjs.map +2 -2
- package/dist-esm/lib/defaultEmbedDefinitions.mjs +3 -2
- package/dist-esm/lib/defaultEmbedDefinitions.mjs.map +2 -2
- package/dist-esm/lib/defaultOverlayUtils.mjs +11 -11
- package/dist-esm/lib/defaultOverlayUtils.mjs.map +2 -2
- package/dist-esm/lib/overlays/SelectionForegroundOverlayUtil.mjs +77 -65
- package/dist-esm/lib/overlays/SelectionForegroundOverlayUtil.mjs.map +2 -2
- package/dist-esm/lib/overlays/ShapeHandleOverlayUtil.mjs +1 -1
- package/dist-esm/lib/overlays/ShapeHandleOverlayUtil.mjs.map +2 -2
- package/dist-esm/lib/overlays/ShapeIndicatorOverlayUtil.mjs +87 -0
- package/dist-esm/lib/overlays/ShapeIndicatorOverlayUtil.mjs.map +7 -0
- package/dist-esm/lib/shapes/arrow/toolStates/Pointing.mjs +9 -1
- package/dist-esm/lib/shapes/arrow/toolStates/Pointing.mjs.map +2 -2
- package/dist-esm/lib/shapes/bookmark/BookmarkShapeUtil.mjs +15 -3
- package/dist-esm/lib/shapes/bookmark/BookmarkShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/bookmark/bookmarks.mjs +54 -6
- package/dist-esm/lib/shapes/bookmark/bookmarks.mjs.map +2 -2
- package/dist-esm/lib/shapes/draw/DrawShapeUtil.mjs +3 -1
- package/dist-esm/lib/shapes/draw/DrawShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/draw/getPath.mjs +1 -1
- package/dist-esm/lib/shapes/draw/getPath.mjs.map +2 -2
- package/dist-esm/lib/shapes/draw/toolStates/Drawing.mjs +46 -47
- package/dist-esm/lib/shapes/draw/toolStates/Drawing.mjs.map +2 -2
- package/dist-esm/lib/shapes/embed/EmbedShapeUtil.mjs +2 -1
- package/dist-esm/lib/shapes/embed/EmbedShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/frame/FrameShapeTool.mjs +23 -18
- package/dist-esm/lib/shapes/frame/FrameShapeTool.mjs.map +2 -2
- package/dist-esm/lib/shapes/geo/GeoShapeUtil.mjs +2 -1
- package/dist-esm/lib/shapes/geo/GeoShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/geo/toolStates/Pointing.mjs +4 -0
- package/dist-esm/lib/shapes/geo/toolStates/Pointing.mjs.map +2 -2
- package/dist-esm/lib/shapes/highlight/HighlightShapeUtil.mjs +12 -7
- package/dist-esm/lib/shapes/highlight/HighlightShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/image/ImageShapeUtil.mjs +3 -11
- package/dist-esm/lib/shapes/image/ImageShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/line/toolStates/Pointing.mjs +6 -1
- package/dist-esm/lib/shapes/line/toolStates/Pointing.mjs.map +2 -2
- package/dist-esm/lib/shapes/note/NoteShapeUtil.mjs +32 -42
- package/dist-esm/lib/shapes/note/NoteShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/note/noteHelpers.mjs +1 -1
- package/dist-esm/lib/shapes/note/noteHelpers.mjs.map +2 -2
- package/dist-esm/lib/shapes/note/toolStates/Pointing.mjs +29 -6
- package/dist-esm/lib/shapes/note/toolStates/Pointing.mjs.map +2 -2
- package/dist-esm/lib/shapes/shared/PlainTextLabel.mjs +3 -2
- package/dist-esm/lib/shapes/shared/PlainTextLabel.mjs.map +2 -2
- package/dist-esm/lib/shapes/shared/RichTextLabel.mjs +4 -3
- package/dist-esm/lib/shapes/shared/RichTextLabel.mjs.map +2 -2
- package/dist-esm/lib/shapes/shared/defaultStyleDefs.mjs +17 -3
- package/dist-esm/lib/shapes/shared/defaultStyleDefs.mjs.map +2 -2
- package/dist-esm/lib/shapes/shared/freehand/core.mjs +404 -0
- package/dist-esm/lib/shapes/shared/freehand/core.mjs.map +7 -0
- package/dist-esm/lib/shapes/shared/freehand/fmt.mjs +86 -0
- package/dist-esm/lib/shapes/shared/freehand/fmt.mjs.map +7 -0
- package/dist-esm/lib/shapes/shared/freehand/getStroke.mjs +7 -7
- package/dist-esm/lib/shapes/shared/freehand/getStroke.mjs.map +2 -2
- package/dist-esm/lib/shapes/shared/freehand/getStrokeOutlinePoints.mjs +332 -86
- package/dist-esm/lib/shapes/shared/freehand/getStrokeOutlinePoints.mjs.map +3 -3
- package/dist-esm/lib/shapes/shared/freehand/getStrokePoints.mjs +31 -96
- package/dist-esm/lib/shapes/shared/freehand/getStrokePoints.mjs.map +3 -3
- package/dist-esm/lib/shapes/shared/freehand/svg.mjs +55 -19
- package/dist-esm/lib/shapes/shared/freehand/svg.mjs.map +2 -2
- package/dist-esm/lib/shapes/shared/freehand/svgInk.mjs +214 -99
- package/dist-esm/lib/shapes/shared/freehand/svgInk.mjs.map +3 -3
- package/dist-esm/lib/shapes/shared/interpolate-props.mjs +6 -2
- package/dist-esm/lib/shapes/shared/interpolate-props.mjs.map +2 -2
- package/dist-esm/lib/shapes/text/toolStates/Pointing.mjs +4 -0
- package/dist-esm/lib/shapes/text/toolStates/Pointing.mjs.map +2 -2
- package/dist-esm/lib/tools/HandTool/HandTool.mjs +16 -6
- package/dist-esm/lib/tools/HandTool/HandTool.mjs.map +2 -2
- package/dist-esm/lib/tools/HandTool/childStates/Dragging.mjs +10 -1
- package/dist-esm/lib/tools/HandTool/childStates/Dragging.mjs.map +2 -2
- package/dist-esm/lib/tools/HandTool/childStates/OneFingerZooming.mjs +64 -0
- package/dist-esm/lib/tools/HandTool/childStates/OneFingerZooming.mjs.map +7 -0
- package/dist-esm/lib/tools/SelectTool/childStates/Idle.mjs +12 -0
- package/dist-esm/lib/tools/SelectTool/childStates/Idle.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/PointingShape.mjs +4 -0
- package/dist-esm/lib/tools/SelectTool/childStates/PointingShape.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/Resizing.mjs +108 -46
- package/dist-esm/lib/tools/SelectTool/childStates/Resizing.mjs.map +2 -2
- package/dist-esm/lib/ui/TldrawUi.mjs +4 -3
- package/dist-esm/lib/ui/TldrawUi.mjs.map +2 -2
- package/dist-esm/lib/ui/components/A11y.mjs +2 -0
- package/dist-esm/lib/ui/components/A11y.mjs.map +2 -2
- package/dist-esm/lib/ui/components/ContextMenu/DefaultContextMenu.mjs +21 -2
- package/dist-esm/lib/ui/components/ContextMenu/DefaultContextMenu.mjs.map +2 -2
- package/dist-esm/lib/ui/components/ContextMenu/DefaultContextMenuContent.mjs +0 -6
- package/dist-esm/lib/ui/components/ContextMenu/DefaultContextMenuContent.mjs.map +2 -2
- package/dist-esm/lib/ui/components/DefaultFollowingIndicator.mjs.map +2 -2
- package/dist-esm/lib/ui/components/Dialogs.mjs +19 -39
- package/dist-esm/lib/ui/components/Dialogs.mjs.map +2 -2
- package/dist-esm/lib/ui/components/HelperButtons/BackToContent.mjs +20 -5
- package/dist-esm/lib/ui/components/HelperButtons/BackToContent.mjs.map +2 -2
- package/dist-esm/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.mjs +12 -2
- package/dist-esm/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.mjs.map +2 -2
- package/dist-esm/lib/ui/components/Minimap/DefaultMinimap.mjs +47 -70
- package/dist-esm/lib/ui/components/Minimap/DefaultMinimap.mjs.map +2 -2
- package/dist-esm/lib/ui/components/Minimap/MinimapManager.mjs +25 -46
- package/dist-esm/lib/ui/components/Minimap/MinimapManager.mjs.map +2 -2
- package/dist-esm/lib/ui/components/SharePanel/DefaultPeopleMenuAvatar.mjs.map +2 -2
- package/dist-esm/lib/ui/components/SharePanel/DefaultPeopleMenuContent.mjs.map +2 -2
- package/dist-esm/lib/ui/components/SharePanel/DefaultPeopleMenuFacePile.mjs.map +2 -2
- package/dist-esm/lib/ui/components/SharePanel/DefaultPeopleMenuItem.mjs +1 -1
- package/dist-esm/lib/ui/components/SharePanel/DefaultPeopleMenuItem.mjs.map +2 -2
- package/dist-esm/lib/ui/components/StylePanel/StylePanelButtonPicker.mjs +1 -0
- package/dist-esm/lib/ui/components/StylePanel/StylePanelButtonPicker.mjs.map +2 -2
- package/dist-esm/lib/ui/components/menu-items.mjs +7 -0
- package/dist-esm/lib/ui/components/menu-items.mjs.map +2 -2
- package/dist-esm/lib/ui/components/primitives/TldrawUiDropdownMenu.mjs +2 -1
- package/dist-esm/lib/ui/components/primitives/TldrawUiDropdownMenu.mjs.map +2 -2
- package/dist-esm/lib/ui/components/primitives/TldrawUiIcon.mjs +14 -3
- package/dist-esm/lib/ui/components/primitives/TldrawUiIcon.mjs.map +2 -2
- package/dist-esm/lib/ui/components/primitives/TldrawUiInput.mjs +2 -0
- package/dist-esm/lib/ui/components/primitives/TldrawUiInput.mjs.map +2 -2
- package/dist-esm/lib/ui/components/primitives/TldrawUiPopover.mjs +2 -0
- package/dist-esm/lib/ui/components/primitives/TldrawUiPopover.mjs.map +2 -2
- package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuCheckboxItem.mjs +0 -2
- package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuCheckboxItem.mjs.map +2 -2
- package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuSubmenu.mjs +1 -2
- package/dist-esm/lib/ui/components/primitives/menus/TldrawUiMenuSubmenu.mjs.map +2 -2
- package/dist-esm/lib/ui/context/actions.mjs +71 -1
- package/dist-esm/lib/ui/context/actions.mjs.map +2 -2
- package/dist-esm/lib/ui/context/asset-urls.mjs +5 -8
- package/dist-esm/lib/ui/context/asset-urls.mjs.map +2 -2
- package/dist-esm/lib/ui/context/events.mjs.map +2 -2
- package/dist-esm/lib/ui/hooks/useKeyboardShortcuts.mjs +13 -0
- package/dist-esm/lib/ui/hooks/useKeyboardShortcuts.mjs.map +2 -2
- package/dist-esm/lib/ui/hooks/useTools.mjs +1 -1
- package/dist-esm/lib/ui/hooks/useTools.mjs.map +2 -2
- package/dist-esm/lib/ui/hooks/useTranslation/defaultTranslation.mjs +2 -0
- package/dist-esm/lib/ui/hooks/useTranslation/defaultTranslation.mjs.map +2 -2
- package/dist-esm/lib/ui/version.mjs +3 -3
- package/dist-esm/lib/ui/version.mjs.map +1 -1
- package/dist-esm/lib/utils/embeds/embeds.mjs +4 -4
- package/dist-esm/lib/utils/embeds/embeds.mjs.map +2 -2
- package/dist-esm/lib/utils/test-helpers.mjs +2 -2
- package/dist-esm/lib/utils/test-helpers.mjs.map +2 -2
- package/dist-esm/lib/utils/text/richText.mjs +3 -1
- package/dist-esm/lib/utils/text/richText.mjs.map +2 -2
- package/package.json +11 -6
- package/src/index.ts +6 -1
- package/src/lib/TldrawImage.tsx +2 -2
- package/src/lib/bindings/arrow/ArrowBindingUtil.ts +5 -1
- package/src/lib/defaultEmbedDefinitions.ts +28 -6
- package/src/lib/defaultOverlayUtils.ts +11 -11
- package/src/lib/overlays/SelectionForegroundOverlayUtil.ts +91 -72
- package/src/lib/overlays/ShapeHandleOverlayUtil.ts +3 -1
- package/src/lib/overlays/ShapeIndicatorOverlayUtil.ts +133 -0
- package/src/lib/shapes/arrow/toolStates/Pointing.tsx +11 -1
- package/src/lib/shapes/bookmark/BookmarkShapeUtil.tsx +16 -3
- package/src/lib/shapes/bookmark/bookmarks.ts +105 -15
- package/src/lib/shapes/draw/DrawShapeUtil.tsx +7 -5
- package/src/lib/shapes/draw/getPath.ts +1 -1
- package/src/lib/shapes/draw/toolStates/Drawing.ts +55 -48
- package/src/lib/shapes/embed/EmbedShapeUtil.tsx +14 -4
- package/src/lib/shapes/frame/FrameShapeTool.ts +35 -24
- package/src/lib/shapes/geo/GeoShapeUtil.test.tsx +46 -0
- package/src/lib/shapes/geo/GeoShapeUtil.tsx +2 -1
- package/src/lib/shapes/geo/toolStates/Pointing.ts +5 -0
- package/src/lib/shapes/highlight/HighlightShapeUtil.tsx +14 -11
- package/src/lib/shapes/image/ImageShapeUtil.tsx +7 -11
- package/src/lib/shapes/line/LineShapeTool.test.ts +41 -0
- package/src/lib/shapes/line/toolStates/Pointing.ts +12 -2
- package/src/lib/shapes/note/NoteShapeUtil.tsx +36 -51
- package/src/lib/shapes/note/noteCloning.test.ts +5 -5
- package/src/lib/shapes/note/noteHelpers.ts +1 -1
- package/src/lib/shapes/note/toolStates/Pointing.ts +40 -7
- package/src/lib/shapes/shared/PlainTextLabel.tsx +3 -3
- package/src/lib/shapes/shared/RichTextLabel.tsx +4 -3
- package/src/lib/shapes/shared/defaultStyleDefs.tsx +25 -3
- package/src/lib/shapes/shared/freehand/core.ts +547 -0
- package/src/lib/shapes/shared/freehand/fmt.ts +106 -0
- package/src/lib/shapes/shared/freehand/getStroke.ts +7 -7
- package/src/lib/shapes/shared/freehand/getStrokeOutlinePoints.ts +451 -139
- package/src/lib/shapes/shared/freehand/getStrokePoints.ts +33 -153
- package/src/lib/shapes/shared/freehand/svg.ts +72 -23
- package/src/lib/shapes/shared/freehand/svgInk.ts +281 -136
- package/src/lib/shapes/shared/freehand/types.ts +0 -1
- package/src/lib/shapes/shared/interpolate-props.ts +6 -2
- package/src/lib/shapes/text/toolStates/Pointing.ts +5 -0
- package/src/lib/tools/HandTool/HandTool.ts +19 -6
- package/src/lib/tools/HandTool/childStates/Dragging.ts +17 -1
- package/src/lib/tools/HandTool/childStates/OneFingerZooming.ts +79 -0
- package/src/lib/tools/SelectTool/childStates/Idle.ts +16 -2
- package/src/lib/tools/SelectTool/childStates/PointingShape.ts +8 -0
- package/src/lib/tools/SelectTool/childStates/Resizing.ts +137 -49
- package/src/lib/ui/TldrawUi.tsx +3 -3
- package/src/lib/ui/components/A11y.tsx +2 -0
- package/src/lib/ui/components/ContextMenu/DefaultContextMenu.tsx +32 -2
- package/src/lib/ui/components/ContextMenu/DefaultContextMenuContent.tsx +5 -6
- package/src/lib/ui/components/DefaultFollowingIndicator.tsx +2 -2
- package/src/lib/ui/components/Dialogs.tsx +20 -23
- package/src/lib/ui/components/HelperButtons/BackToContent.tsx +32 -4
- package/src/lib/ui/components/KeyboardShortcutsDialog/DefaultKeyboardShortcutsDialogContent.tsx +10 -0
- package/src/lib/ui/components/Minimap/DefaultMinimap.tsx +60 -74
- package/src/lib/ui/components/Minimap/MinimapManager.ts +35 -57
- package/src/lib/ui/components/SharePanel/DefaultPeopleMenuAvatar.tsx +2 -2
- package/src/lib/ui/components/SharePanel/DefaultPeopleMenuContent.tsx +2 -1
- package/src/lib/ui/components/SharePanel/DefaultPeopleMenuFacePile.tsx +2 -1
- package/src/lib/ui/components/SharePanel/DefaultPeopleMenuItem.tsx +3 -3
- package/src/lib/ui/components/StylePanel/StylePanelButtonPicker.tsx +5 -0
- package/src/lib/ui/components/menu-items.tsx +9 -0
- package/src/lib/ui/components/primitives/TldrawUiDropdownMenu.tsx +3 -1
- package/src/lib/ui/components/primitives/TldrawUiIcon.tsx +15 -3
- package/src/lib/ui/components/primitives/TldrawUiInput.tsx +4 -0
- package/src/lib/ui/components/primitives/TldrawUiPopover.tsx +7 -0
- package/src/lib/ui/components/primitives/menus/TldrawUiMenuCheckboxItem.tsx +0 -2
- package/src/lib/ui/components/primitives/menus/TldrawUiMenuSubmenu.tsx +0 -1
- package/src/lib/ui/context/actions.tsx +88 -1
- package/src/lib/ui/context/asset-urls.tsx +9 -8
- package/src/lib/ui/context/events.tsx +2 -0
- package/src/lib/ui/hooks/useKeyboardShortcuts.ts +45 -7
- package/src/lib/ui/hooks/useTools.tsx +7 -1
- package/src/lib/ui/hooks/useTranslation/TLUiTranslationKey.ts +2 -0
- package/src/lib/ui/hooks/useTranslation/defaultTranslation.ts +2 -0
- package/src/lib/ui/version.ts +3 -3
- package/src/lib/ui.css +20 -9
- package/src/lib/utils/embeds/embeds.test.ts +14 -12
- package/src/lib/utils/embeds/embeds.ts +10 -4
- package/src/lib/utils/test-helpers.ts +3 -3
- package/src/lib/utils/text/richText.test.ts +36 -0
- package/src/lib/utils/text/richText.ts +9 -1
- package/src/test/HandTool.test.ts +93 -0
- package/src/test/ImageShapeUtil.test.ts +88 -0
- package/src/test/SelectTool.test.ts +102 -1
- package/src/test/__snapshots__/drawing.test.ts.snap +2 -1
- package/src/test/attribution.test.ts +40 -29
- package/src/test/bookmark-shapes.test.ts +256 -28
- package/src/test/commands/__snapshots__/getSvgString.test.ts.snap +2 -2
- package/src/test/commands/clipboardCallbacks.test.ts +3 -1
- package/src/test/commands/getSvgString.test.ts +30 -0
- package/src/test/commands/penmode.test.ts +97 -1
- package/src/test/commands/setCamera.test.ts +12 -0
- package/src/test/dragFromToolbar.test.ts +67 -0
- package/src/test/drawing.test.ts +48 -7
- package/src/test/frames.test.ts +72 -0
- package/src/test/freehand/corpus/presets.ts +71 -0
- package/src/test/freehand/corpus/real.ts +370 -0
- package/src/test/freehand/corpus/strokes.ts +50 -0
- package/src/test/freehand/svg.test.ts +20 -0
- package/src/test/freehand/wellformed.test.ts +30 -0
- package/src/test/long-press-create.test.ts +102 -0
- package/src/test/overlays/CollaboratorBrushOverlayUtil.test.ts +4 -4
- package/src/test/overlays/CollaboratorCursorOverlayUtil.test.ts +18 -18
- package/src/test/overlays/CollaboratorHintOverlayUtil.test.ts +7 -7
- package/src/test/overlays/CollaboratorScribbleOverlayUtil.test.ts +3 -3
- package/src/test/overlays/OverlayManager.test.ts +1 -1
- package/src/test/overlays/SelectionForegroundOverlayUtil.test.ts +58 -0
- package/src/test/overlays/ShapeHandleOverlayUtil.test.ts +2 -2
- package/src/test/overlays/ShapeIndicatorOverlayUtil.test.ts +36 -0
- package/src/test/resizing.test.ts +250 -0
- package/src/test/right-click-context-menu.test.ts +90 -0
- package/src/test/rightClickPanning.test.ts +11 -0
- package/src/test/selection-omnibus.test.ts +15 -2
- package/src/test/spatialIndex.test.ts +132 -0
- package/src/test/translating.test.ts +0 -6
- package/src/test/ui/ContextMenu.test.tsx +146 -3
- package/src/test/ui/Dialogs.test.tsx +256 -0
- package/src/test/ui/copyHoveredStyles.test.tsx +154 -0
- package/src/test/ui/keyboardShortcuts.test.tsx +266 -0
- package/tldraw.css +35 -12
- package/dist-cjs/lib/shapes/shared/freehand/setStrokePointRadii.js +0 -100
- package/dist-cjs/lib/shapes/shared/freehand/setStrokePointRadii.js.map +0 -7
- package/dist-esm/lib/shapes/shared/freehand/setStrokePointRadii.mjs +0 -80
- package/dist-esm/lib/shapes/shared/freehand/setStrokePointRadii.mjs.map +0 -7
- package/src/lib/shapes/shared/freehand/setStrokePointRadii.ts +0 -127
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/lib/shapes/shared/freehand/svgInk.ts"],
|
|
4
|
-
"sourcesContent": ["import { Vec, VecLike, assert, average, precise, toDomPrecision } from '@tldraw/editor'\nimport { getStrokeOutlineTracks } from './getStrokeOutlinePoints'\nimport { getStrokePoints } from './getStrokePoints'\nimport { setStrokePointRadii } from './setStrokePointRadii'\nimport { StrokeOptions, StrokePoint } from './types'\n\nexport function svgInk(rawInputPoints: VecLike[], options: StrokeOptions = {}) {\n\tconst { start = {}, end = {} } = options\n\tconst { cap: capStart = true } = start\n\tconst { cap: capEnd = true } = end\n\tassert(!start.taper && !end.taper, 'cap taper not supported here')\n\tassert(!start.easing && !end.easing, 'cap easing not supported here')\n\tassert(capStart && capEnd, 'cap must be true')\n\n\tconst points = getStrokePoints(rawInputPoints, options)\n\tsetStrokePointRadii(points, options)\n\tconst partitions = partitionAtElbows(points)\n\tlet svg = ''\n\tfor (const partition of partitions) {\n\t\tsvg += renderPartition(partition, options)\n\t}\n\n\treturn svg\n}\n\nfunction partitionAtElbows(points: StrokePoint[]): StrokePoint[][] {\n\tif (points.length <= 2) return [points]\n\n\tconst result: StrokePoint[][] = []\n\tlet currentPartition: StrokePoint[] = [points[0]]\n\tlet prevV = Vec.Sub(points[1].point, points[0].point).uni()\n\tlet nextV: Vec\n\tlet dpr: number\n\tlet prevPoint: StrokePoint, thisPoint: StrokePoint, nextPoint: StrokePoint\n\tfor (let i = 1, n = points.length; i < n - 1; i++) {\n\t\tprevPoint = points[i - 1]\n\t\tthisPoint = points[i]\n\t\tnextPoint = points[i + 1]\n\n\t\tnextV = Vec.Sub(nextPoint.point, thisPoint.point).uni()\n\t\tdpr = Vec.Dpr(prevV, nextV)\n\t\tprevV = nextV\n\n\t\tif (dpr < -0.8) {\n\t\t\t// always treat such acute angles as elbows\n\t\t\t// and use the extended .input point as the elbow point for swooshiness in fast zaggy lines\n\t\t\tconst elbowPoint = {\n\t\t\t\t...thisPoint,\n\t\t\t\tpoint: thisPoint.input,\n\t\t\t}\n\t\t\tcurrentPartition.push(elbowPoint)\n\t\t\tresult.push(cleanUpPartition(currentPartition))\n\t\t\tcurrentPartition = [elbowPoint]\n\t\t\tcontinue\n\t\t}\n\t\tcurrentPartition.push(thisPoint)\n\n\t\tif (dpr > 0.7) {\n\t\t\t// Not an elbow\n\t\t\tcontinue\n\t\t}\n\n\t\t// so now we have a reasonably acute angle but it might not be an elbow if it's far\n\t\t// away from it's neighbors, angular dist is a normalized representation of how far away the point is from it's neighbors\n\t\t// (normalized by the radius)\n\t\tif (\n\t\t\t(Vec.Dist2(prevPoint.point, thisPoint.point) + Vec.Dist2(thisPoint.point, nextPoint.point)) /\n\t\t\t\t((prevPoint.radius + thisPoint.radius + nextPoint.radius) / 3) ** 2 <\n\t\t\t1.5\n\t\t) {\n\t\t\t// if this point is kinda close to its neighbors and it has a reasonably\n\t\t\t// acute angle, it's probably a hard elbow\n\t\t\tcurrentPartition.push(thisPoint)\n\t\t\tresult.push(cleanUpPartition(currentPartition))\n\t\t\tcurrentPartition = [thisPoint]\n\t\t\tcontinue\n\t\t}\n\t}\n\tcurrentPartition.push(points[points.length - 1])\n\tresult.push(cleanUpPartition(currentPartition))\n\n\treturn result\n}\n\nfunction cleanUpPartition(partition: StrokePoint[]) {\n\t// clean up start of partition (remove points that are too close to the start)\n\tconst startPoint = partition[0]\n\tlet nextPoint: StrokePoint\n\twhile (partition.length > 2) {\n\t\tnextPoint = partition[1]\n\t\tif (\n\t\t\tVec.Dist2(startPoint.point, nextPoint.point) <\n\t\t\t(((startPoint.radius + nextPoint.radius) / 2) * 0.5) ** 2\n\t\t) {\n\t\t\tpartition.splice(1, 1)\n\t\t} else {\n\t\t\tbreak\n\t\t}\n\t}\n\t// clean up end of partition in the same fashion\n\tconst endPoint = partition[partition.length - 1]\n\tlet prevPoint: StrokePoint\n\twhile (partition.length > 2) {\n\t\tprevPoint = partition[partition.length - 2]\n\t\tif (\n\t\t\tVec.Dist2(endPoint.point, prevPoint.point) <\n\t\t\t(((endPoint.radius + prevPoint.radius) / 2) * 0.5) ** 2\n\t\t) {\n\t\t\tpartition.splice(partition.length - 2, 1)\n\t\t} else {\n\t\t\tbreak\n\t\t}\n\t}\n\t// now readjust the cap point vectors to point to their nearest neighbors\n\tif (partition.length > 1) {\n\t\tpartition[0] = {\n\t\t\t...partition[0],\n\t\t\tvector: Vec.Sub(partition[0].point, partition[1].point).uni(),\n\t\t}\n\t\tpartition[partition.length - 1] = {\n\t\t\t...partition[partition.length - 1],\n\t\t\tvector: Vec.Sub(\n\t\t\t\tpartition[partition.length - 2].point,\n\t\t\t\tpartition[partition.length - 1].point\n\t\t\t).uni(),\n\t\t}\n\t}\n\treturn partition\n}\n\nfunction circlePath(cx: number, cy: number, r: number) {\n\treturn (\n\t\t'M ' +\n\t\tcx +\n\t\t' ' +\n\t\tcy +\n\t\t' m -' +\n\t\tr +\n\t\t', 0 a ' +\n\t\tr +\n\t\t',' +\n\t\tr +\n\t\t' 0 1,1 ' +\n\t\tr * 2 +\n\t\t',0 a ' +\n\t\tr +\n\t\t',' +\n\t\tr +\n\t\t' 0 1,1 -' +\n\t\tr * 2 +\n\t\t',0'\n\t)\n}\n\nfunction renderPartition(strokePoints: StrokePoint[], options: StrokeOptions = {}): string {\n\tif (strokePoints.length === 0) return ''\n\tif (strokePoints.length === 1) {\n\t\treturn circlePath(strokePoints[0].point.x, strokePoints[0].point.y, strokePoints[0].radius)\n\t}\n\n\tconst { left, right } = getStrokeOutlineTracks(strokePoints, options)\n\tright.reverse()\n\tlet svg = `M${precise(left[0])}T`\n\n\t// draw left track\n\tfor (let i = 1; i < left.length; i++) {\n\t\tsvg += average(left[i - 1], left[i])\n\t}\n\t// draw end cap arc\n\t{\n\t\tconst point = strokePoints[strokePoints.length - 1]\n\t\tconst radius = point.radius\n\t\tconst direction = point.vector.clone().per().neg()\n\t\tconst arcStart = Vec.Add(point.point, Vec.Mul(direction, radius))\n\t\tconst arcEnd = Vec.Add(point.point, Vec.Mul(direction, -radius))\n\t\tsvg += `${precise(arcStart)}A${toDomPrecision(radius)},${toDomPrecision(\n\t\t\tradius\n\t\t)} 0 0 1 ${precise(arcEnd)}T`\n\t}\n\t// draw right track\n\tfor (let i = 1; i < right.length; i++) {\n\t\tsvg += average(right[i - 1], right[i])\n\t}\n\t// draw start cap arc\n\t{\n\t\tconst point = strokePoints[0]\n\t\tconst radius = point.radius\n\t\tconst direction = point.vector.clone().per()\n\t\tconst arcStart = Vec.Add(point.point, Vec.Mul(direction, radius))\n\t\tconst arcEnd = Vec.Add(point.point, Vec.Mul(direction, -radius))\n\t\tsvg += `${precise(arcStart)}A${toDomPrecision(radius)},${toDomPrecision(\n\t\t\tradius\n\t\t)} 0 0 1 ${precise(arcEnd)}Z`\n\t}\n\treturn svg\n}\n"],
|
|
5
|
-
"mappings": "AAAA,
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["import { VecLike, assert } from '@tldraw/editor'\nimport {\n\tcomputeRadii,\n\tingest,\n\tinputX,\n\tinputY,\n\tloadSrcFromPipeline,\n\tloadSrcPartition,\n\tpointCount,\n\tpointX,\n\tpointY,\n\tradii,\n\tsrcCount,\n\tsrcRadius,\n\tsrcX,\n\tsrcY,\n} from './core'\nimport { finishPath, resetPath, toCenti, writeC, writeCPair, writeStr } from './fmt'\nimport {\n\tbuildTracks,\n\ttrackLeftCount,\n\ttrackLeftX,\n\ttrackLeftY,\n\ttrackRightCount,\n\ttrackRightX,\n\ttrackRightY,\n} from './getStrokeOutlinePoints'\nimport { StrokeOptions } from './types'\n\n/**\n * Render a freehand stroke as svg path data in a single pass, from raw input points to a filled\n * outline with round caps. This is the path used by tldraw's draw shape when drawing with ink.\n *\n * @param rawInputPoints - The raw input points (as `{x, y, z}`, where `z` is pressure).\n * @param options - An object with options.\n * @public\n */\nexport function svgInk(rawInputPoints: VecLike[], options: StrokeOptions = {}) {\n\tconst { start = {}, end = {} } = options\n\tconst { cap: capStart = true } = start\n\tconst { cap: capEnd = true } = end\n\tassert(!start.taper && !end.taper, 'cap taper not supported here')\n\tassert(!start.easing && !end.easing, 'cap easing not supported here')\n\tassert(capStart && capEnd, 'cap must be true')\n\n\tingest(rawInputPoints, options)\n\tcomputeRadii(options)\n\tresetPath()\n\tpartitionAtElbows(options)\n\treturn finishPath()\n}\n\n/**\n * Walk the stroke points in the pipeline buffers, cutting the stroke into partitions at\n * elbows, and render each one. Partitions are index ranges into the pipeline: each runs\n * from the previous boundary point to the next elbow. An acute elbow uses the input point\n * rather than the streamlined point at the boundary (for swooshiness in fast zaggy\n * lines), in which case the next partition's second point keeps the vector it had in the\n * uncut stroke via the vector anchor.\n */\nfunction partitionAtElbows(options: StrokeOptions): void {\n\tconst n = pointCount\n\tif (n === 0) return\n\tif (n <= 2) {\n\t\tloadSrcFromPipeline()\n\t\trenderPartition(options, false, 0, 0)\n\t\treturn\n\t}\n\n\tconst ptX = pointX\n\tconst ptY = pointY\n\tconst rads = radii\n\n\t// The start of the current partition, and whether it is an acute elbow (which reads\n\t// the input coordinates rather than the streamlined ones).\n\tlet a = 0\n\tlet aElbow = false\n\tlet hasAnchor = false\n\tlet anchorX = 0\n\tlet anchorY = 0\n\n\t// Unit direction of the previous segment, computed with scalar math to avoid\n\t// allocating two vectors per point.\n\tlet dx = ptX[1] - ptX[0]\n\tlet dy = ptY[1] - ptY[0]\n\tlet len = Math.sqrt(dx * dx + dy * dy)\n\tlet prevVx = dx / len\n\tlet prevVy = dy / len\n\n\tfor (let i = 1; i < n - 1; i++) {\n\t\tdx = ptX[i + 1] - ptX[i]\n\t\tdy = ptY[i + 1] - ptY[i]\n\t\tlen = Math.sqrt(dx * dx + dy * dy)\n\t\tconst nextVx = dx / len\n\t\tconst nextVy = dy / len\n\t\tconst dpr = prevVx * nextVx + prevVy * nextVy\n\t\tprevVx = nextVx\n\t\tprevVy = nextVy\n\n\t\tif (dpr < -0.8) {\n\t\t\t// always treat such acute angles as elbows\n\t\t\t// and use the extended input point as the elbow point for swooshiness in fast zaggy lines\n\t\t\tfinishPartition(a, aElbow, i, true, false, hasAnchor, anchorX, anchorY, options)\n\t\t\ta = i\n\t\t\taElbow = true\n\t\t\t// The next partition's second point keeps the vector it had in the uncut stroke,\n\t\t\t// which pointed at this point's streamlined position rather than its input.\n\t\t\thasAnchor = true\n\t\t\tanchorX = ptX[i]\n\t\t\tanchorY = ptY[i]\n\t\t\tcontinue\n\t\t}\n\n\t\tif (dpr > 0.7) {\n\t\t\t// Not an elbow\n\t\t\tcontinue\n\t\t}\n\n\t\t// so now we have a reasonably acute angle but it might not be an elbow if it's far\n\t\t// away from it's neighbors, angular dist is a normalized representation of how far away the point is from it's neighbors\n\t\t// (normalized by the radius)\n\t\tconst pdx = ptX[i] - ptX[i - 1]\n\t\tconst pdy = ptY[i] - ptY[i - 1]\n\t\tconst ndx = ptX[i + 1] - ptX[i]\n\t\tconst ndy = ptY[i + 1] - ptY[i]\n\t\tconst meanRadius = (rads[i - 1] + rads[i] + rads[i + 1]) / 3\n\t\tif ((pdx * pdx + pdy * pdy + ndx * ndx + ndy * ndy) / (meanRadius * meanRadius) < 1.5) {\n\t\t\t// if this point is kinda close to its neighbors and it has a reasonably\n\t\t\t// acute angle, it's probably a hard elbow. The boundary point ends its\n\t\t\t// partition twice over (the object pipeline pushed it twice).\n\t\t\tfinishPartition(a, aElbow, i, false, true, hasAnchor, anchorX, anchorY, options)\n\t\t\ta = i\n\t\t\taElbow = false\n\t\t\thasAnchor = false\n\t\t\tcontinue\n\t\t}\n\t}\n\tfinishPartition(a, aElbow, n - 1, false, false, hasAnchor, anchorX, anchorY, options)\n}\n\n/**\n * Clean up a partition's ends (drop inner points too close to the boundary points), load\n * it into the track-source buffers and render it. The partition runs from boundary `a` to\n * boundary `b`; `bDup` marks a hard elbow whose end point is duplicated.\n */\nfunction finishPartition(\n\ta: number,\n\taElbow: boolean,\n\tb: number,\n\tbElbow: boolean,\n\tbDup: boolean,\n\thasAnchor: boolean,\n\tanchorX: number,\n\tanchorY: number,\n\toptions: StrokeOptions\n): void {\n\t// The partition as the object pipeline would have built it: point a, points a+1..b-1,\n\t// point b (twice when bDup). Cleanup only ever removes points adjacent to the ends, so\n\t// it reduces to two skip counters.\n\tconst ptX = pointX\n\tconst ptY = pointY\n\tconst rads = radii\n\n\tconst len = b - a + 1 + (bDup ? 1 : 0)\n\tlet s = 0\n\tlet e = 0\n\n\t// clean up start of partition (remove points that are too close to the start)\n\tconst startX = aElbow ? inputX[a] : ptX[a]\n\tconst startY = aElbow ? inputY[a] : ptY[a]\n\tconst startRadius = rads[a]\n\twhile (len - s > 2) {\n\t\tconst i = a + 1 + s\n\t\tconst dx = startX - ptX[i]\n\t\tconst dy = startY - ptY[i]\n\t\tif (dx * dx + dy * dy < (((startRadius + rads[i]) / 2) * 0.5) ** 2) {\n\t\t\t// The surviving second point's vector keeps pointing at the spliced-out point.\n\t\t\thasAnchor = true\n\t\t\tanchorX = ptX[i]\n\t\t\tanchorY = ptY[i]\n\t\t\ts++\n\t\t} else {\n\t\t\tbreak\n\t\t}\n\t}\n\n\t// clean up end of partition in the same fashion\n\tconst endX = bElbow ? inputX[b] : ptX[b]\n\tconst endY = bElbow ? inputY[b] : ptY[b]\n\tconst endRadius = rads[b]\n\twhile (len - s - e > 2) {\n\t\tconst i = bDup ? b - e : b - 1 - e\n\t\tconst dx = endX - ptX[i]\n\t\tconst dy = endY - ptY[i]\n\t\tif (dx * dx + dy * dy < (((endRadius + rads[i]) / 2) * 0.5) ** 2) {\n\t\t\te++\n\t\t} else {\n\t\t\tbreak\n\t\t}\n\t}\n\n\tconst innerStart = a + 1 + s\n\tconst innerEnd = bDup ? b - e : b - 1 - e\n\tloadSrcPartition(a, aElbow, innerStart, innerEnd, b, bElbow, bDup && e === 0)\n\trenderPartition(options, hasAnchor, anchorX, anchorY)\n}\n\nfunction writeCirclePath(cx: number, cy: number, r: number) {\n\tconst ncx = toCenti(cx)\n\tconst ncy = toCenti(cy)\n\tconst nr = toCenti(r)\n\twriteStr('M ')\n\twriteC(ncx)\n\twriteStr(' ')\n\twriteC(ncy)\n\twriteStr(' m -')\n\twriteC(nr)\n\twriteStr(', 0 a ')\n\twriteC(nr)\n\twriteStr(',')\n\twriteC(nr)\n\twriteStr(' 0 1,1 ')\n\twriteC(nr * 2)\n\twriteStr(',0 a ')\n\twriteC(nr)\n\twriteStr(',')\n\twriteC(nr)\n\twriteStr(' 0 1,1 -')\n\twriteC(nr * 2)\n\twriteStr(',0')\n}\n\n/** Append an arc from the current position to the cap's other side: `a r,r 0 0 1 dx,dy`. */\nfunction writeCapArc(nr: number, dx: number, dy: number) {\n\twriteStr('a')\n\twriteC(nr)\n\twriteStr(',')\n\twriteC(nr)\n\twriteStr(' 0 0 1 ')\n\twriteCPair(dx, dy)\n}\n\n/** Render the partition currently loaded in the track-source buffers. */\nfunction renderPartition(\n\toptions: StrokeOptions,\n\thasAnchor: boolean,\n\tanchorX: number,\n\tanchorY: number\n): void {\n\tconst n = srcCount\n\tif (n === 0) return\n\tif (n === 1) {\n\t\twriteCirclePath(srcX[0], srcY[0], srcRadius[0])\n\t\treturn\n\t}\n\n\tbuildTracks(options, hasAnchor, anchorX, anchorY)\n\n\tconst lxs = trackLeftX\n\tconst lys = trackLeftY\n\tconst rxs = trackRightX\n\tconst rys = trackRightY\n\n\t// Current position in integer hundredths; all subsequent commands are relative.\n\tlet cx = toCenti(lxs[0])\n\tlet cy = toCenti(lys[0])\n\twriteStr('M')\n\twriteCPair(cx, cy)\n\twriteStr('t')\n\n\t// draw left track, as quadratic curves through the midpoints of consecutive points\n\tlet prevX = lxs[0]\n\tlet prevY = lys[0]\n\tfor (let i = 1; i < trackLeftCount; i++) {\n\t\tconst ptX = lxs[i]\n\t\tconst ptY = lys[i]\n\t\tconst mx = Math.round((prevX + ptX) * 50)\n\t\tconst my = Math.round((prevY + ptY) * 50)\n\t\twriteCPair(mx - cx, my - cy)\n\t\tcx = mx\n\t\tcy = my\n\t\tprevX = ptX\n\t\tprevY = ptY\n\t}\n\t// draw end cap arc\n\t{\n\t\tconst pointX = srcX[n - 1]\n\t\tconst pointY = srcY[n - 1]\n\t\tconst radius = srcRadius[n - 1]\n\t\t// The cap vector points from the last point back at its nearest neighbor.\n\t\tconst vdx = srcX[n - 2] - pointX\n\t\tconst vdy = srcY[n - 2] - pointY\n\t\tconst vlen = Math.sqrt(vdx * vdx + vdy * vdy)\n\t\t// The arc endpoints sit one radius to each side, perpendicular to the cap vector.\n\t\tconst dx = (-vdy / vlen) * radius\n\t\tconst dy = (vdx / vlen) * radius\n\t\tconst asx = toCenti(pointX + dx)\n\t\tconst asy = toCenti(pointY + dy)\n\t\tconst aex = toCenti(pointX - dx)\n\t\tconst aey = toCenti(pointY - dy)\n\t\twriteCPair(asx - cx, asy - cy)\n\t\twriteCapArc(toCenti(radius), aex - asx, aey - asy)\n\t\twriteStr('t')\n\t\tcx = aex\n\t\tcy = aey\n\t}\n\t// draw right track in reverse, also as quadratic curves through midpoints\n\tprevX = rxs[trackRightCount - 1]\n\tprevY = rys[trackRightCount - 1]\n\tfor (let i = trackRightCount - 2; i >= 0; i--) {\n\t\tconst ptX = rxs[i]\n\t\tconst ptY = rys[i]\n\t\tconst mx = Math.round((prevX + ptX) * 50)\n\t\tconst my = Math.round((prevY + ptY) * 50)\n\t\twriteCPair(mx - cx, my - cy)\n\t\tcx = mx\n\t\tcy = my\n\t\tprevX = ptX\n\t\tprevY = ptY\n\t}\n\t// draw start cap arc\n\t{\n\t\tconst pointX = srcX[0]\n\t\tconst pointY = srcY[0]\n\t\tconst radius = srcRadius[0]\n\t\t// The cap vector points from the first point back past its nearest neighbor.\n\t\tconst vdx = pointX - srcX[1]\n\t\tconst vdy = pointY - srcY[1]\n\t\tconst vlen = Math.sqrt(vdx * vdx + vdy * vdy)\n\t\t// The arc endpoints sit one radius to each side, perpendicular to the cap vector.\n\t\tconst dx = (vdy / vlen) * radius\n\t\tconst dy = (-vdx / vlen) * radius\n\t\tconst asx = toCenti(pointX + dx)\n\t\tconst asy = toCenti(pointY + dy)\n\t\tconst aex = toCenti(pointX - dx)\n\t\tconst aey = toCenti(pointY - dy)\n\t\twriteCPair(asx - cx, asy - cy)\n\t\twriteCapArc(toCenti(radius), aex - asx, aey - asy)\n\t\twriteStr('Z')\n\t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AQ;AAAA,EACT;AAEA;AACC,UAAMD,UAAS,KAAK,CAAC;AACrB,UAAMC,UAAS,KAAK,CAAC;AACrB,UAAM,SAAS,UAAU,CAAC;AAE1B,UAAM,MAAMD,UAAS,KAAK,CAAC;AAC3B,UAAM,MAAMC,UAAS,KAAK,CAAC;AAC3B,UAAM,OAAO,KAAK,KAAK,MAAM,MAAM,MAAM,GAAG;AAE5C,UAAM,KAAM,MAAM,OAAQ;AAC1B,UAAM,KAAM,CAAC,MAAM,OAAQ;AAC3B,UAAM,MAAM,QAAQD,UAAS,EAAE;AAC/B,UAAM,MAAM,QAAQC,UAAS,EAAE;AAC/B,UAAM,MAAM,QAAQD,UAAS,EAAE;AAC/B,UAAM,MAAM,QAAQC,UAAS,EAAE;AAC/B,eAAW,MAAM,IAAI,MAAM,EAAE;AAC7B,gBAAY,QAAQ,MAAM,GAAG,MAAM,KAAK,MAAM,GAAG;AACjD,aAAS,GAAG;AAAA,EACb;AACD;",
|
|
6
|
+
"names": ["pointX", "pointY"]
|
|
7
7
|
}
|
|
@@ -2,8 +2,12 @@ import { b64Vecs, lerp } from "@tldraw/editor";
|
|
|
2
2
|
function interpolateSegments(startSegments, endSegments, progress) {
|
|
3
3
|
const startPoints = [];
|
|
4
4
|
const endPoints = [];
|
|
5
|
-
startSegments.forEach(
|
|
6
|
-
|
|
5
|
+
startSegments.forEach(
|
|
6
|
+
(segment) => startPoints.push(...b64Vecs.decodePoints(segment.path, segment.dim))
|
|
7
|
+
);
|
|
8
|
+
endSegments.forEach(
|
|
9
|
+
(segment) => endPoints.push(...b64Vecs.decodePoints(segment.path, segment.dim))
|
|
10
|
+
);
|
|
7
11
|
const maxLength = Math.max(startPoints.length, endPoints.length);
|
|
8
12
|
const pointsToUseStart = [];
|
|
9
13
|
const pointsToUseEnd = [];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/shapes/shared/interpolate-props.ts"],
|
|
4
|
-
"sourcesContent": ["import { TLDrawShapeSegment, VecModel, b64Vecs, lerp } from '@tldraw/editor'\n\n/** @public */\nexport function interpolateSegments(\n\tstartSegments: TLDrawShapeSegment[],\n\tendSegments: TLDrawShapeSegment[],\n\tprogress: number\n): TLDrawShapeSegment[] {\n\tconst startPoints: VecModel[] = []\n\tconst endPoints: VecModel[] = []\n\n\t// Extract all points from startSegments and endSegments\n\tstartSegments.forEach((segment)
|
|
5
|
-
"mappings": "AAAA,SAAuC,SAAS,YAAY;AAGrD,SAAS,oBACf,eACA,aACA,UACuB;AACvB,QAAM,cAA0B,CAAC;AACjC,QAAM,YAAwB,CAAC;AAG/B,gBAAc,
|
|
4
|
+
"sourcesContent": ["import { TLDrawShapeSegment, VecModel, b64Vecs, lerp } from '@tldraw/editor'\n\n/** @public */\nexport function interpolateSegments(\n\tstartSegments: TLDrawShapeSegment[],\n\tendSegments: TLDrawShapeSegment[],\n\tprogress: number\n): TLDrawShapeSegment[] {\n\tconst startPoints: VecModel[] = []\n\tconst endPoints: VecModel[] = []\n\n\t// Extract all points from startSegments and endSegments\n\tstartSegments.forEach((segment) =>\n\t\tstartPoints.push(...b64Vecs.decodePoints(segment.path, segment.dim))\n\t)\n\tendSegments.forEach((segment) =>\n\t\tendPoints.push(...b64Vecs.decodePoints(segment.path, segment.dim))\n\t)\n\n\tconst maxLength = Math.max(startPoints.length, endPoints.length)\n\tconst pointsToUseStart: VecModel[] = []\n\tconst pointsToUseEnd: VecModel[] = []\n\n\t// Ensure both arrays have the same length\n\tfor (let i = 0; i < maxLength; i++) {\n\t\tpointsToUseStart.push(startPoints[i] || startPoints[startPoints.length - 1])\n\t\tpointsToUseEnd.push(endPoints[i] || endPoints[endPoints.length - 1])\n\t}\n\n\t// Interpolate points\n\tconst interpolatedPoints = pointsToUseStart.map((point, k) => {\n\t\tlet z = 0.5\n\t\tif (pointsToUseEnd[k].z !== undefined && point.z !== undefined) {\n\t\t\tz = lerp(point.z, pointsToUseEnd[k].z as number, progress)\n\t\t}\n\t\treturn {\n\t\t\tx: lerp(point.x, pointsToUseEnd[k].x, progress),\n\t\t\ty: lerp(point.y, pointsToUseEnd[k].y, progress),\n\t\t\tz,\n\t\t}\n\t})\n\t// Return all interpolated points in a single segment\n\treturn [\n\t\t{\n\t\t\ttype: 'free',\n\t\t\tpath: b64Vecs.encodePoints(interpolatedPoints),\n\t\t},\n\t]\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAuC,SAAS,YAAY;AAGrD,SAAS,oBACf,eACA,aACA,UACuB;AACvB,QAAM,cAA0B,CAAC;AACjC,QAAM,YAAwB,CAAC;AAG/B,gBAAc;AAAA,IAAQ,CAAC,YACtB,YAAY,KAAK,GAAG,QAAQ,aAAa,QAAQ,MAAM,QAAQ,GAAG,CAAC;AAAA,EACpE;AACA,cAAY;AAAA,IAAQ,CAAC,YACpB,UAAU,KAAK,GAAG,QAAQ,aAAa,QAAQ,MAAM,QAAQ,GAAG,CAAC;AAAA,EAClE;AAEA,QAAM,YAAY,KAAK,IAAI,YAAY,QAAQ,UAAU,MAAM;AAC/D,QAAM,mBAA+B,CAAC;AACtC,QAAM,iBAA6B,CAAC;AAGpC,WAAS,IAAI,GAAG,IAAI,WAAW,KAAK;AACnC,qBAAiB,KAAK,YAAY,CAAC,KAAK,YAAY,YAAY,SAAS,CAAC,CAAC;AAC3E,mBAAe,KAAK,UAAU,CAAC,KAAK,UAAU,UAAU,SAAS,CAAC,CAAC;AAAA,EACpE;AAGA,QAAM,qBAAqB,iBAAiB,IAAI,CAAC,OAAO,MAAM;AAC7D,QAAI,IAAI;AACR,QAAI,eAAe,CAAC,EAAE,MAAM,UAAa,MAAM,MAAM,QAAW;AAC/D,UAAI,KAAK,MAAM,GAAG,eAAe,CAAC,EAAE,GAAa,QAAQ;AAAA,IAC1D;AACA,WAAO;AAAA,MACN,GAAG,KAAK,MAAM,GAAG,eAAe,CAAC,EAAE,GAAG,QAAQ;AAAA,MAC9C,GAAG,KAAK,MAAM,GAAG,eAAe,CAAC,EAAE,GAAG,QAAQ;AAAA,MAC9C;AAAA,IACD;AAAA,EACD,CAAC;AAED,SAAO;AAAA,IACN;AAAA,MACC,MAAM;AAAA,MACN,MAAM,QAAQ,aAAa,kBAAkB;AAAA,IAC9C;AAAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
StateNode,
|
|
3
3
|
Vec,
|
|
4
4
|
createShapeId,
|
|
5
|
+
cancelShapeCreationOnLongPress,
|
|
5
6
|
isShapeId,
|
|
6
7
|
maybeSnapToGrid,
|
|
7
8
|
toRichText
|
|
@@ -59,6 +60,9 @@ class Pointing extends StateNode {
|
|
|
59
60
|
onPointerUp() {
|
|
60
61
|
this.complete();
|
|
61
62
|
}
|
|
63
|
+
onLongPress() {
|
|
64
|
+
cancelShapeCreationOnLongPress(this.editor, () => this.cancel());
|
|
65
|
+
}
|
|
62
66
|
onComplete() {
|
|
63
67
|
this.cancel();
|
|
64
68
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/lib/shapes/text/toolStates/Pointing.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n\tStateNode,\n\tTLPointerEventInfo,\n\tTLShapeId,\n\tTLTextShape,\n\tVec,\n\tcreateShapeId,\n\tisShapeId,\n\tmaybeSnapToGrid,\n\ttoRichText,\n} from '@tldraw/editor'\nimport { startEditingShapeWithRichText } from '../../../tools/SelectTool/selectHelpers'\n\nexport class Pointing extends StateNode {\n\tstatic override id = 'pointing'\n\n\tshape?: TLTextShape\n\n\tmarkId = ''\n\n\tenterTime = 0\n\toverride onEnter(): void {\n\t\tthis.enterTime = Date.now()\n\t}\n\n\toverride onExit() {\n\t\tthis.editor.setHintingShapes([])\n\t}\n\n\toverride onPointerMove(info: TLPointerEventInfo) {\n\t\t// Create a fixed width shape if the user wants to do that.\n\n\t\t// Don't create a fixed width shape unless the the drag is a little larger,\n\t\t// otherwise you get a vertical column of single characters if you accidentally\n\t\t// drag a bit unintentionally.\n\n\t\t// If the user hasn't been pointing for more than 150ms, don't create a fixed width shape\n\t\tif (Date.now() - this.enterTime < 150) return\n\n\t\tconst { editor } = this\n\t\tconst isPointing = editor.inputs.getIsPointing()\n\n\t\tif (!isPointing) return\n\n\t\tconst originPagePoint = editor.inputs.getOriginPagePoint()\n\t\tconst currentPagePoint = editor.inputs.getCurrentPagePoint()\n\n\t\tconst currentDragDist = Math.abs(originPagePoint.x - currentPagePoint.x)\n\n\t\tconst baseMinDragDistForFixedWidth = Math.sqrt(\n\t\t\teditor.getInstanceState().isCoarsePointer\n\t\t\t\t? editor.options.coarseDragDistanceSquared\n\t\t\t\t: editor.options.dragDistanceSquared\n\t\t)\n\n\t\t// Ten times the base drag distance for fixed width\n\t\tconst minSquaredDragDist = (baseMinDragDistForFixedWidth * 6) / editor.getZoomLevel()\n\n\t\tif (currentDragDist > minSquaredDragDist) {\n\t\t\tconst id = createShapeId()\n\t\t\tthis.markId = editor.markHistoryStoppingPoint(`creating_text:${id}`)\n\n\t\t\t// create the initial shape with the width that we've dragged\n\t\t\tconst shape = this.createTextShape(id, originPagePoint, false, currentDragDist)\n\n\t\t\tif (!shape) {\n\t\t\t\tthis.cancel()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\t// Now save the fresh reference\n\t\t\tthis.shape = editor.getShape(shape)\n\n\t\t\teditor.select(id)\n\n\t\t\tconst scale = this.editor.getResizeScaleFactor()\n\n\t\t\teditor.setCurrentTool('select.resizing', {\n\t\t\t\t...info,\n\t\t\t\ttarget: 'selection',\n\t\t\t\thandle: 'right',\n\t\t\t\tisCreating: true,\n\t\t\t\tcreatingMarkId: this.markId,\n\t\t\t\t// Make sure the cursor offset takes into account how far we've already dragged\n\t\t\t\tcreationCursorOffset: { x: currentDragDist * scale, y: 1 },\n\t\t\t\tonInteractionEnd: 'text',\n\t\t\t\tonCreate: () => {\n\t\t\t\t\tstartEditingShapeWithRichText(editor, shape.id)\n\t\t\t\t},\n\t\t\t})\n\t\t}\n\t}\n\n\toverride onPointerUp() {\n\t\tthis.complete()\n\t}\n\n\toverride onComplete() {\n\t\tthis.cancel()\n\t}\n\n\toverride onCancel() {\n\t\tthis.cancel()\n\t}\n\n\toverride onInterrupt() {\n\t\tthis.cancel()\n\t}\n\n\tprivate complete() {\n\t\tthis.editor.markHistoryStoppingPoint('creating text shape')\n\t\tconst id = createShapeId()\n\t\tconst originPagePoint = this.editor.inputs.getOriginPagePoint()\n\t\tconst shape = this.createTextShape(id, originPagePoint, true, 20)\n\t\tif (!shape) return\n\n\t\tthis.editor.select(id)\n\t\tstartEditingShapeWithRichText(this.editor, id)\n\t}\n\n\tprivate cancel() {\n\t\tthis.parent.transition('idle')\n\t\tthis.editor.bailToMark(this.markId)\n\t}\n\n\tprivate createTextShape(id: TLShapeId, point: Vec, autoSize: boolean, width: number) {\n\t\tthis.editor.createShape({\n\t\t\tid,\n\t\t\ttype: 'text',\n\t\t\tx: point.x,\n\t\t\ty: point.y,\n\t\t\tprops: {\n\t\t\t\trichText: toRichText(''),\n\t\t\t\tautoSize,\n\t\t\t\tw: width,\n\t\t\t\tscale: this.editor.getResizeScaleFactor(),\n\t\t\t},\n\t\t})\n\n\t\tconst shape = this.editor.getShape<TLTextShape>(id)\n\t\tif (!shape) {\n\t\t\tthis.cancel()\n\t\t\treturn\n\t\t}\n\n\t\tconst bounds = this.editor.getShapePageBounds(shape)!\n\n\t\tconst delta = new Vec()\n\n\t\tif (autoSize) {\n\t\t\tswitch (shape.props.textAlign) {\n\t\t\t\tcase 'start': {\n\t\t\t\t\tdelta.x = 0\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'middle': {\n\t\t\t\t\tdelta.x = -bounds.width / 2\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'end': {\n\t\t\t\t\tdelta.x = -bounds.width\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tdelta.x = 0\n\t\t}\n\n\t\tdelta.y = -bounds.height / 2\n\n\t\tif (isShapeId(shape.parentId)) {\n\t\t\tconst transform = this.editor.getShapeParentTransform(shape)\n\t\t\tdelta.rot(-transform.rotation())\n\t\t}\n\n\t\tconst shapeX = shape.x + delta.x\n\t\tconst shapeY = shape.y + delta.y\n\t\tif (this.editor.getInstanceState().isGridMode) {\n\t\t\tconst topLeft = new Vec(shapeX, shapeY)\n\t\t\tconst gridSnappedPoint = maybeSnapToGrid(topLeft, this.editor)\n\t\t\tconst gridDelta = Vec.Sub(topLeft, gridSnappedPoint)\n\t\t\tthis.editor.updateShape({\n\t\t\t\t...shape,\n\t\t\t\tx: shapeX - gridDelta.x,\n\t\t\t\ty: shapeY - gridDelta.y,\n\t\t\t})\n\t\t} else {\n\t\t\tthis.editor.updateShape({\n\t\t\t\t...shape,\n\t\t\t\tx: shapeX,\n\t\t\t\ty: shapeY,\n\t\t\t})\n\t\t}\n\n\t\treturn shape\n\t}\n}\n"],
|
|
5
|
-
"mappings": "AAAA;AAAA,EACC;AAAA,EAIA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,qCAAqC;AAEvC,MAAM,iBAAiB,UAAU;AAAA,EACvC,OAAgB,KAAK;AAAA,EAErB;AAAA,EAEA,SAAS;AAAA,EAET,YAAY;AAAA,EACH,UAAgB;AACxB,SAAK,YAAY,KAAK,IAAI;AAAA,EAC3B;AAAA,EAES,SAAS;AACjB,SAAK,OAAO,iBAAiB,CAAC,CAAC;AAAA,EAChC;AAAA,EAES,cAAc,MAA0B;AAQhD,QAAI,KAAK,IAAI,IAAI,KAAK,YAAY,IAAK;AAEvC,UAAM,EAAE,OAAO,IAAI;AACnB,UAAM,aAAa,OAAO,OAAO,cAAc;AAE/C,QAAI,CAAC,WAAY;AAEjB,UAAM,kBAAkB,OAAO,OAAO,mBAAmB;AACz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M;AAC/B,UAAM,SAAS,MAAM,IAAI,MAAM;AAC/B,QAAI,KAAK,OAAO,iBAAiB,EAAE,YAAY;AAC9C,YAAM,UAAU,IAAI,IAAI,QAAQ,MAAM;AACtC,YAAM,mBAAmB,gBAAgB,SAAS,KAAK,MAAM;AAC7D,YAAM,YAAY,IAAI,IAAI,SAAS,gBAAgB;AACnD,WAAK,OAAO,YAAY;AAAA,QACvB,GAAG;AAAA,QACH,GAAG,SAAS,UAAU;AAAA,QACtB,GAAG,SAAS,UAAU;AAAA,MACvB,CAAC;AAAA,IACF,OAAO;AACN,WAAK,OAAO,YAAY;AAAA,QACvB,GAAG;AAAA,QACH,GAAG;AAAA,QACH,GAAG;AAAA,MACJ,CAAC;AAAA,IACF;AAEA,WAAO;AAAA,EACR;AACD;",
|
|
4
|
+
"sourcesContent": ["import {\n\tStateNode,\n\tTLPointerEventInfo,\n\tTLShapeId,\n\tTLTextShape,\n\tVec,\n\tcreateShapeId,\n\tcancelShapeCreationOnLongPress,\n\tisShapeId,\n\tmaybeSnapToGrid,\n\ttoRichText,\n} from '@tldraw/editor'\nimport { startEditingShapeWithRichText } from '../../../tools/SelectTool/selectHelpers'\n\nexport class Pointing extends StateNode {\n\tstatic override id = 'pointing'\n\n\tshape?: TLTextShape\n\n\tmarkId = ''\n\n\tenterTime = 0\n\toverride onEnter(): void {\n\t\tthis.enterTime = Date.now()\n\t}\n\n\toverride onExit() {\n\t\tthis.editor.setHintingShapes([])\n\t}\n\n\toverride onPointerMove(info: TLPointerEventInfo) {\n\t\t// Create a fixed width shape if the user wants to do that.\n\n\t\t// Don't create a fixed width shape unless the the drag is a little larger,\n\t\t// otherwise you get a vertical column of single characters if you accidentally\n\t\t// drag a bit unintentionally.\n\n\t\t// If the user hasn't been pointing for more than 150ms, don't create a fixed width shape\n\t\tif (Date.now() - this.enterTime < 150) return\n\n\t\tconst { editor } = this\n\t\tconst isPointing = editor.inputs.getIsPointing()\n\n\t\tif (!isPointing) return\n\n\t\tconst originPagePoint = editor.inputs.getOriginPagePoint()\n\t\tconst currentPagePoint = editor.inputs.getCurrentPagePoint()\n\n\t\tconst currentDragDist = Math.abs(originPagePoint.x - currentPagePoint.x)\n\n\t\tconst baseMinDragDistForFixedWidth = Math.sqrt(\n\t\t\teditor.getInstanceState().isCoarsePointer\n\t\t\t\t? editor.options.coarseDragDistanceSquared\n\t\t\t\t: editor.options.dragDistanceSquared\n\t\t)\n\n\t\t// Ten times the base drag distance for fixed width\n\t\tconst minSquaredDragDist = (baseMinDragDistForFixedWidth * 6) / editor.getZoomLevel()\n\n\t\tif (currentDragDist > minSquaredDragDist) {\n\t\t\tconst id = createShapeId()\n\t\t\tthis.markId = editor.markHistoryStoppingPoint(`creating_text:${id}`)\n\n\t\t\t// create the initial shape with the width that we've dragged\n\t\t\tconst shape = this.createTextShape(id, originPagePoint, false, currentDragDist)\n\n\t\t\tif (!shape) {\n\t\t\t\tthis.cancel()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\t// Now save the fresh reference\n\t\t\tthis.shape = editor.getShape(shape)\n\n\t\t\teditor.select(id)\n\n\t\t\tconst scale = this.editor.getResizeScaleFactor()\n\n\t\t\teditor.setCurrentTool('select.resizing', {\n\t\t\t\t...info,\n\t\t\t\ttarget: 'selection',\n\t\t\t\thandle: 'right',\n\t\t\t\tisCreating: true,\n\t\t\t\tcreatingMarkId: this.markId,\n\t\t\t\t// Make sure the cursor offset takes into account how far we've already dragged\n\t\t\t\tcreationCursorOffset: { x: currentDragDist * scale, y: 1 },\n\t\t\t\tonInteractionEnd: 'text',\n\t\t\t\tonCreate: () => {\n\t\t\t\t\tstartEditingShapeWithRichText(editor, shape.id)\n\t\t\t\t},\n\t\t\t})\n\t\t}\n\t}\n\n\toverride onPointerUp() {\n\t\tthis.complete()\n\t}\n\n\toverride onLongPress() {\n\t\tcancelShapeCreationOnLongPress(this.editor, () => this.cancel())\n\t}\n\n\toverride onComplete() {\n\t\tthis.cancel()\n\t}\n\n\toverride onCancel() {\n\t\tthis.cancel()\n\t}\n\n\toverride onInterrupt() {\n\t\tthis.cancel()\n\t}\n\n\tprivate complete() {\n\t\tthis.editor.markHistoryStoppingPoint('creating text shape')\n\t\tconst id = createShapeId()\n\t\tconst originPagePoint = this.editor.inputs.getOriginPagePoint()\n\t\tconst shape = this.createTextShape(id, originPagePoint, true, 20)\n\t\tif (!shape) return\n\n\t\tthis.editor.select(id)\n\t\tstartEditingShapeWithRichText(this.editor, id)\n\t}\n\n\tprivate cancel() {\n\t\tthis.parent.transition('idle')\n\t\tthis.editor.bailToMark(this.markId)\n\t}\n\n\tprivate createTextShape(id: TLShapeId, point: Vec, autoSize: boolean, width: number) {\n\t\tthis.editor.createShape({\n\t\t\tid,\n\t\t\ttype: 'text',\n\t\t\tx: point.x,\n\t\t\ty: point.y,\n\t\t\tprops: {\n\t\t\t\trichText: toRichText(''),\n\t\t\t\tautoSize,\n\t\t\t\tw: width,\n\t\t\t\tscale: this.editor.getResizeScaleFactor(),\n\t\t\t},\n\t\t})\n\n\t\tconst shape = this.editor.getShape<TLTextShape>(id)\n\t\tif (!shape) {\n\t\t\tthis.cancel()\n\t\t\treturn\n\t\t}\n\n\t\tconst bounds = this.editor.getShapePageBounds(shape)!\n\n\t\tconst delta = new Vec()\n\n\t\tif (autoSize) {\n\t\t\tswitch (shape.props.textAlign) {\n\t\t\t\tcase 'start': {\n\t\t\t\t\tdelta.x = 0\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'middle': {\n\t\t\t\t\tdelta.x = -bounds.width / 2\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'end': {\n\t\t\t\t\tdelta.x = -bounds.width\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tdelta.x = 0\n\t\t}\n\n\t\tdelta.y = -bounds.height / 2\n\n\t\tif (isShapeId(shape.parentId)) {\n\t\t\tconst transform = this.editor.getShapeParentTransform(shape)\n\t\t\tdelta.rot(-transform.rotation())\n\t\t}\n\n\t\tconst shapeX = shape.x + delta.x\n\t\tconst shapeY = shape.y + delta.y\n\t\tif (this.editor.getInstanceState().isGridMode) {\n\t\t\tconst topLeft = new Vec(shapeX, shapeY)\n\t\t\tconst gridSnappedPoint = maybeSnapToGrid(topLeft, this.editor)\n\t\t\tconst gridDelta = Vec.Sub(topLeft, gridSnappedPoint)\n\t\t\tthis.editor.updateShape({\n\t\t\t\t...shape,\n\t\t\t\tx: shapeX - gridDelta.x,\n\t\t\t\ty: shapeY - gridDelta.y,\n\t\t\t})\n\t\t} else {\n\t\t\tthis.editor.updateShape({\n\t\t\t\t...shape,\n\t\t\t\tx: shapeX,\n\t\t\t\ty: shapeY,\n\t\t\t})\n\t\t}\n\n\t\treturn shape\n\t}\n}\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EACC;AAAA,EAIA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,qCAAqC;AAEvC,MAAM,iBAAiB,UAAU;AAAA,EACvC,OAAgB,KAAK;AAAA,EAErB;AAAA,EAEA,SAAS;AAAA,EAET,YAAY;AAAA,EACH,UAAgB;AACxB,SAAK,YAAY,KAAK,IAAI;AAAA,EAC3B;AAAA,EAES,SAAS;AACjB,SAAK,OAAO,iBAAiB,CAAC,CAAC;AAAA,EAChC;AAAA,EAES,cAAc,MAA0B;AAQhD,QAAI,KAAK,IAAI,IAAI,KAAK,YAAY,IAAK;AAEvC,UAAM,EAAE,OAAO,IAAI;AACnB,UAAM,aAAa,OAAO,OAAO,cAAc;AAE/C,QAAI,CAAC,WAAY;AAEjB,UAAM,kBAAkB,OAAO,OAAO,mBAAmB;AACzD,UAAM,mBAAmB,OAAO,OAAO,oBAAoB;AAE3D,UAAM,kBAAkB,KAAK,IAAI,gBAAgB,IAAI,iBAAiB,CAAC;AAEvE,UAAM,+BAA+B,KAAK;AAAA,MACzC,OAAO,iBAAiB,EAAE,kBACvB,OAA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C,YAAM,UAAU,IAAI,IAAI,QAAQ,MAAM;AACtC,YAAM,mBAAmB,gBAAgB,SAAS,KAAK,MAAM;AAC7D,YAAM,YAAY,IAAI,IAAI,SAAS,gBAAgB;AACnD,WAAK,OAAO,YAAY;AAAA,QACvB,GAAG;AAAA,QACH,GAAG,SAAS,UAAU;AAAA,QACtB,GAAG,SAAS,UAAU;AAAA,MACvB,CAAC;AAAA,IACF,OAAO;AACN,WAAK,OAAO,YAAY;AAAA,QACvB,GAAG;AAAA,QACH,GAAG;AAAA,QACH,GAAG;AAAA,MACJ,CAAC;AAAA,IACF;AAEA,WAAO;AAAA,EACR;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,20 +1,30 @@
|
|
|
1
1
|
import { EASINGS, StateNode } from "@tldraw/editor";
|
|
2
2
|
import { Dragging } from "./childStates/Dragging.mjs";
|
|
3
3
|
import { Idle } from "./childStates/Idle.mjs";
|
|
4
|
+
import { OneFingerZooming } from "./childStates/OneFingerZooming.mjs";
|
|
4
5
|
import { Pointing } from "./childStates/Pointing.mjs";
|
|
5
6
|
class HandTool extends StateNode {
|
|
6
7
|
static id = "hand";
|
|
7
8
|
static initial = "idle";
|
|
8
9
|
static isLockable = false;
|
|
9
10
|
static children() {
|
|
10
|
-
return [Idle, Pointing, Dragging];
|
|
11
|
+
return [Idle, Pointing, Dragging, OneFingerZooming];
|
|
11
12
|
}
|
|
12
13
|
onDoubleClick(info) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
switch (info.phase) {
|
|
15
|
+
case "settle-down": {
|
|
16
|
+
if (this.editor.getInstanceState().isCoarsePointer) {
|
|
17
|
+
this.transition("one_finger_zooming", info);
|
|
18
|
+
}
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
case "settle-up": {
|
|
22
|
+
const currentScreenPoint = this.editor.inputs.getCurrentScreenPoint();
|
|
23
|
+
this.editor.zoomIn(currentScreenPoint, {
|
|
24
|
+
animation: { duration: 220, easing: EASINGS.easeOutQuint }
|
|
25
|
+
});
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
18
28
|
}
|
|
19
29
|
}
|
|
20
30
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/tools/HandTool/HandTool.ts"],
|
|
4
|
-
"sourcesContent": ["import { EASINGS, StateNode, TLClickEventInfo, TLStateNodeConstructor } from '@tldraw/editor'\nimport { Dragging } from './childStates/Dragging'\nimport { Idle } from './childStates/Idle'\nimport { Pointing } from './childStates/Pointing'\n\n/** @public */\nexport class HandTool extends StateNode {\n\tstatic override id = 'hand'\n\tstatic override initial = 'idle'\n\tstatic override isLockable = false\n\tstatic override children(): TLStateNodeConstructor[] {\n\t\treturn [Idle, Pointing, Dragging]\n\t}\n\n\toverride onDoubleClick(info: TLClickEventInfo) {\n\t\
|
|
5
|
-
"mappings": "AAAA,SAAS,SAAS,iBAA2D;AAC7E,SAAS,gBAAgB;AACzB,SAAS,YAAY;AACrB,SAAS,gBAAgB;AAGlB,MAAM,iBAAiB,UAAU;AAAA,EACvC,OAAgB,KAAK;AAAA,EACrB,OAAgB,UAAU;AAAA,EAC1B,OAAgB,aAAa;AAAA,EAC7B,OAAgB,WAAqC;AACpD,WAAO,CAAC,MAAM,UAAU,
|
|
4
|
+
"sourcesContent": ["import { EASINGS, StateNode, TLClickEventInfo, TLStateNodeConstructor } from '@tldraw/editor'\nimport { Dragging } from './childStates/Dragging'\nimport { Idle } from './childStates/Idle'\nimport { OneFingerZooming } from './childStates/OneFingerZooming'\nimport { Pointing } from './childStates/Pointing'\n\n/** @public */\nexport class HandTool extends StateNode {\n\tstatic override id = 'hand'\n\tstatic override initial = 'idle'\n\tstatic override isLockable = false\n\tstatic override children(): TLStateNodeConstructor[] {\n\t\treturn [Idle, Pointing, Dragging, OneFingerZooming]\n\t}\n\n\toverride onDoubleClick(info: TLClickEventInfo) {\n\t\tswitch (info.phase) {\n\t\t\tcase 'settle-down': {\n\t\t\t\t// A double-tap whose second press is still held down: begin one-finger\n\t\t\t\t// drag-to-zoom. This is a touch gesture, so only enter it on a coarse pointer.\n\t\t\t\tif (this.editor.getInstanceState().isCoarsePointer) {\n\t\t\t\t\tthis.transition('one_finger_zooming', info)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'settle-up': {\n\t\t\t\t// A double-tap whose second press was released: zoom in by one step.\n\t\t\t\tconst currentScreenPoint = this.editor.inputs.getCurrentScreenPoint()\n\t\t\t\tthis.editor.zoomIn(currentScreenPoint, {\n\t\t\t\t\tanimation: { duration: 220, easing: EASINGS.easeOutQuint },\n\t\t\t\t})\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,SAAS,iBAA2D;AAC7E,SAAS,gBAAgB;AACzB,SAAS,YAAY;AACrB,SAAS,wBAAwB;AACjC,SAAS,gBAAgB;AAGlB,MAAM,iBAAiB,UAAU;AAAA,EACvC,OAAgB,KAAK;AAAA,EACrB,OAAgB,UAAU;AAAA,EAC1B,OAAgB,aAAa;AAAA,EAC7B,OAAgB,WAAqC;AACpD,WAAO,CAAC,MAAM,UAAU,UAAU,gBAAgB;AAAA,EACnD;AAAA,EAES,cAAc,MAAwB;AAC9C,YAAQ,KAAK,OAAO;AAAA,MACnB,KAAK,eAAe;AAGnB,YAAI,KAAK,OAAO,iBAAiB,EAAE,iBAAiB;AACnD,eAAK,WAAW,sBAAsB,IAAI;AAAA,QAC3C;AACA;AAAA,MACD;AAAA,MACA,KAAK,aAAa;AAEjB,cAAM,qBAAqB,KAAK,OAAO,OAAO,sBAAsB;AACpE,aAAK,OAAO,OAAO,oBAAoB;AAAA,UACtC,WAAW,EAAE,UAAU,KAAK,QAAQ,QAAQ,aAAa;AAAA,QAC1D,CAAC;AACD;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -10,9 +10,15 @@ class Dragging extends StateNode {
|
|
|
10
10
|
onPointerMove() {
|
|
11
11
|
this.update();
|
|
12
12
|
}
|
|
13
|
+
onPointerDown() {
|
|
14
|
+
this.parent.transition("idle");
|
|
15
|
+
}
|
|
13
16
|
onPointerUp() {
|
|
14
17
|
this.complete();
|
|
15
18
|
}
|
|
19
|
+
onInterrupt() {
|
|
20
|
+
this.parent.transition("idle");
|
|
21
|
+
}
|
|
16
22
|
onCancel() {
|
|
17
23
|
this.parent.transition("idle");
|
|
18
24
|
}
|
|
@@ -32,7 +38,10 @@ class Dragging extends StateNode {
|
|
|
32
38
|
const pointerVelocity = editor.inputs.getPointerVelocity();
|
|
33
39
|
const velocityAtPointerUp = Math.min(pointerVelocity.len(), 2);
|
|
34
40
|
if (velocityAtPointerUp > 0.1) {
|
|
35
|
-
this.editor.slideCamera({
|
|
41
|
+
this.editor.slideCamera({
|
|
42
|
+
speed: velocityAtPointerUp,
|
|
43
|
+
direction: { x: pointerVelocity.x, y: pointerVelocity.y, z: 0 }
|
|
44
|
+
});
|
|
36
45
|
}
|
|
37
46
|
this.parent.transition("idle");
|
|
38
47
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/lib/tools/HandTool/childStates/Dragging.ts"],
|
|
4
|
-
"sourcesContent": ["import { StateNode, Vec } from '@tldraw/editor'\n\nexport class Dragging extends StateNode {\n\tstatic override id = 'dragging'\n\tstatic override trackPerformance = true\n\n\tinitialCamera = new Vec()\n\n\toverride onEnter() {\n\t\tthis.initialCamera = Vec.From(this.editor.getCamera())\n\t\tthis.update()\n\t}\n\n\toverride onPointerMove() {\n\t\tthis.update()\n\t}\n\n\toverride onPointerUp() {\n\t\tthis.complete()\n\t}\n\n\toverride onCancel() {\n\t\tthis.parent.transition('idle')\n\t}\n\n\toverride onComplete() {\n\t\tthis.complete()\n\t}\n\n\tprivate update() {\n\t\tconst { initialCamera, editor } = this\n\t\tconst currentScreenPoint = editor.inputs.getCurrentScreenPoint()\n\t\tconst originScreenPoint = editor.inputs.getOriginScreenPoint()\n\n\t\tconst delta = Vec.Sub(currentScreenPoint, originScreenPoint).div(editor.getZoomLevel())\n\t\tif (delta.len2() === 0) return\n\t\teditor.setCamera(initialCamera.clone().add(delta))\n\t}\n\n\tprivate complete() {\n\t\tconst { editor } = this\n\t\tconst pointerVelocity = editor.inputs.getPointerVelocity()\n\n\t\tconst velocityAtPointerUp = Math.min(pointerVelocity.len(), 2)\n\n\t\tif (velocityAtPointerUp > 0.1) {\n\t\t\tthis.editor.slideCamera({
|
|
5
|
-
"mappings": "AAAA,SAAS,WAAW,WAAW;AAExB,MAAM,iBAAiB,UAAU;AAAA,EACvC,OAAgB,KAAK;AAAA,EACrB,OAAgB,mBAAmB;AAAA,EAEnC,gBAAgB,IAAI,IAAI;AAAA,EAEf,UAAU;AAClB,SAAK,gBAAgB,IAAI,KAAK,KAAK,OAAO,UAAU,CAAC;AACrD,SAAK,OAAO;AAAA,EACb;AAAA,EAES,gBAAgB;AACxB,SAAK,OAAO;AAAA,EACb;AAAA,EAES,cAAc;AACtB,SAAK,SAAS;AAAA,EACf;AAAA,EAES,WAAW;AACnB,SAAK,OAAO,WAAW,MAAM;AAAA,EAC9B;AAAA,EAES,aAAa;AACrB,SAAK,SAAS;AAAA,EACf;AAAA,EAEQ,SAAS;AAChB,UAAM,EAAE,eAAe,OAAO,IAAI;AAClC,UAAM,qBAAqB,OAAO,OAAO,sBAAsB;AAC/D,UAAM,oBAAoB,OAAO,OAAO,qBAAqB;AAE7D,UAAM,QAAQ,IAAI,IAAI,oBAAoB,iBAAiB,EAAE,IAAI,OAAO,aAAa,CAAC;AACtF,QAAI,MAAM,KAAK,MAAM,EAAG;AACxB,WAAO,UAAU,cAAc,MAAM,EAAE,IAAI,KAAK,CAAC;AAAA,EAClD;AAAA,EAEQ,WAAW;AAClB,UAAM,EAAE,OAAO,IAAI;AACnB,UAAM,kBAAkB,OAAO,OAAO,mBAAmB;AAEzD,UAAM,sBAAsB,KAAK,IAAI,gBAAgB,IAAI,GAAG,CAAC;AAE7D,QAAI,sBAAsB,KAAK;AAC9B,WAAK,OAAO,YAAY,
|
|
4
|
+
"sourcesContent": ["import { StateNode, Vec } from '@tldraw/editor'\n\nexport class Dragging extends StateNode {\n\tstatic override id = 'dragging'\n\tstatic override trackPerformance = true\n\n\tinitialCamera = new Vec()\n\n\toverride onEnter() {\n\t\tthis.initialCamera = Vec.From(this.editor.getCamera())\n\t\tthis.update()\n\t}\n\n\toverride onPointerMove() {\n\t\tthis.update()\n\t}\n\n\toverride onPointerDown() {\n\t\t// A second touch resets the input origin to the new pointer, so continuing\n\t\t// the pan would snap the camera. Yield before the pinch begins; the pan\n\t\t// does not resume when the pinch ends.\n\t\tthis.parent.transition('idle')\n\t}\n\n\toverride onPointerUp() {\n\t\tthis.complete()\n\t}\n\n\toverride onInterrupt() {\n\t\t// A pinch interrupts when it starts (without a preceding pointer_down on\n\t\t// some inputs, like Safari trackpads), so end the pan here too.\n\t\tthis.parent.transition('idle')\n\t}\n\n\toverride onCancel() {\n\t\tthis.parent.transition('idle')\n\t}\n\n\toverride onComplete() {\n\t\tthis.complete()\n\t}\n\n\tprivate update() {\n\t\tconst { initialCamera, editor } = this\n\t\tconst currentScreenPoint = editor.inputs.getCurrentScreenPoint()\n\t\tconst originScreenPoint = editor.inputs.getOriginScreenPoint()\n\n\t\tconst delta = Vec.Sub(currentScreenPoint, originScreenPoint).div(editor.getZoomLevel())\n\t\tif (delta.len2() === 0) return\n\t\teditor.setCamera(initialCamera.clone().add(delta))\n\t}\n\n\tprivate complete() {\n\t\tconst { editor } = this\n\t\tconst pointerVelocity = editor.inputs.getPointerVelocity()\n\n\t\tconst velocityAtPointerUp = Math.min(pointerVelocity.len(), 2)\n\n\t\tif (velocityAtPointerUp > 0.1) {\n\t\t\tthis.editor.slideCamera({\n\t\t\t\tspeed: velocityAtPointerUp,\n\t\t\t\tdirection: { x: pointerVelocity.x, y: pointerVelocity.y, z: 0 },\n\t\t\t})\n\t\t}\n\n\t\tthis.parent.transition('idle')\n\t}\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,WAAW,WAAW;AAExB,MAAM,iBAAiB,UAAU;AAAA,EACvC,OAAgB,KAAK;AAAA,EACrB,OAAgB,mBAAmB;AAAA,EAEnC,gBAAgB,IAAI,IAAI;AAAA,EAEf,UAAU;AAClB,SAAK,gBAAgB,IAAI,KAAK,KAAK,OAAO,UAAU,CAAC;AACrD,SAAK,OAAO;AAAA,EACb;AAAA,EAES,gBAAgB;AACxB,SAAK,OAAO;AAAA,EACb;AAAA,EAES,gBAAgB;AAIxB,SAAK,OAAO,WAAW,MAAM;AAAA,EAC9B;AAAA,EAES,cAAc;AACtB,SAAK,SAAS;AAAA,EACf;AAAA,EAES,cAAc;AAGtB,SAAK,OAAO,WAAW,MAAM;AAAA,EAC9B;AAAA,EAES,WAAW;AACnB,SAAK,OAAO,WAAW,MAAM;AAAA,EAC9B;AAAA,EAES,aAAa;AACrB,SAAK,SAAS;AAAA,EACf;AAAA,EAEQ,SAAS;AAChB,UAAM,EAAE,eAAe,OAAO,IAAI;AAClC,UAAM,qBAAqB,OAAO,OAAO,sBAAsB;AAC/D,UAAM,oBAAoB,OAAO,OAAO,qBAAqB;AAE7D,UAAM,QAAQ,IAAI,IAAI,oBAAoB,iBAAiB,EAAE,IAAI,OAAO,aAAa,CAAC;AACtF,QAAI,MAAM,KAAK,MAAM,EAAG;AACxB,WAAO,UAAU,cAAc,MAAM,EAAE,IAAI,KAAK,CAAC;AAAA,EAClD;AAAA,EAEQ,WAAW;AAClB,UAAM,EAAE,OAAO,IAAI;AACnB,UAAM,kBAAkB,OAAO,OAAO,mBAAmB;AAEzD,UAAM,sBAAsB,KAAK,IAAI,gBAAgB,IAAI,GAAG,CAAC;AAE7D,QAAI,sBAAsB,KAAK;AAC9B,WAAK,OAAO,YAAY;AAAA,QACvB,OAAO;AAAA,QACP,WAAW,EAAE,GAAG,gBAAgB,GAAG,GAAG,gBAAgB,GAAG,GAAG,EAAE;AAAA,MAC/D,CAAC;AAAA,IACF;AAEA,SAAK,OAAO,WAAW,MAAM;AAAA,EAC9B;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { StateNode, Vec, clamp, last } from "@tldraw/editor";
|
|
2
|
+
class OneFingerZooming extends StateNode {
|
|
3
|
+
static id = "one_finger_zooming";
|
|
4
|
+
anchorScreenPoint = new Vec();
|
|
5
|
+
initialCamera = new Vec();
|
|
6
|
+
initialZoom = 1;
|
|
7
|
+
originScreenY = 0;
|
|
8
|
+
onEnter(_info) {
|
|
9
|
+
const camera = this.editor.getCamera();
|
|
10
|
+
this.initialCamera = Vec.From(camera);
|
|
11
|
+
this.initialZoom = camera.z;
|
|
12
|
+
this.anchorScreenPoint = this.editor.inputs.getOriginScreenPoint().clone();
|
|
13
|
+
this.originScreenY = this.editor.inputs.getCurrentScreenPoint().y;
|
|
14
|
+
this.editor.setCursor({ type: "grab", rotation: 0 });
|
|
15
|
+
}
|
|
16
|
+
onPointerMove(_info) {
|
|
17
|
+
this.editor.menus.clearOpenMenus();
|
|
18
|
+
const currentScreenY = this.editor.inputs.getCurrentScreenPoint().y;
|
|
19
|
+
const dy = (this.originScreenY - currentScreenY) * -1;
|
|
20
|
+
const zoomFactor = Math.pow(2, dy / 200);
|
|
21
|
+
const newZoom = this.clampZoom(this.initialZoom * zoomFactor);
|
|
22
|
+
const { x: cx, y: cy } = this.initialCamera;
|
|
23
|
+
const { x: sx, y: sy } = this.anchorScreenPoint;
|
|
24
|
+
this.editor.setCamera(
|
|
25
|
+
new Vec(
|
|
26
|
+
cx + sx / newZoom - sx / this.initialZoom,
|
|
27
|
+
cy + sy / newZoom - sy / this.initialZoom,
|
|
28
|
+
newZoom
|
|
29
|
+
),
|
|
30
|
+
{ immediate: true }
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
onPointerUp(_info) {
|
|
34
|
+
this.complete();
|
|
35
|
+
}
|
|
36
|
+
onCancel() {
|
|
37
|
+
this.parent.transition("idle");
|
|
38
|
+
}
|
|
39
|
+
onInterrupt() {
|
|
40
|
+
this.parent.transition("idle");
|
|
41
|
+
}
|
|
42
|
+
complete() {
|
|
43
|
+
const pointerVelocity = this.editor.inputs.getPointerVelocity();
|
|
44
|
+
const velocityAtPointerUp = Math.min(pointerVelocity.len(), 2);
|
|
45
|
+
if (velocityAtPointerUp > 0.1) {
|
|
46
|
+
this.editor.slideCamera({
|
|
47
|
+
speed: velocityAtPointerUp,
|
|
48
|
+
direction: { x: 0, y: 0, z: Math.sign(pointerVelocity.y) * 0.01 }
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
this.parent.transition("idle");
|
|
52
|
+
}
|
|
53
|
+
clampZoom(zoom) {
|
|
54
|
+
const { zoomSteps } = this.editor.getCameraOptions();
|
|
55
|
+
const baseZoom = this.editor.getBaseZoom();
|
|
56
|
+
const zoomMin = zoomSteps[0] * baseZoom;
|
|
57
|
+
const zoomMax = last(zoomSteps) * baseZoom;
|
|
58
|
+
return clamp(zoom, zoomMin, zoomMax);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export {
|
|
62
|
+
OneFingerZooming
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=OneFingerZooming.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/lib/tools/HandTool/childStates/OneFingerZooming.ts"],
|
|
4
|
+
"sourcesContent": ["import { StateNode, TLPointerEventInfo, Vec, clamp, last } from '@tldraw/editor'\n\nexport class OneFingerZooming extends StateNode {\n\tstatic override id = 'one_finger_zooming'\n\n\tprivate anchorScreenPoint = new Vec()\n\tprivate initialCamera = new Vec()\n\tprivate initialZoom = 1\n\tprivate originScreenY = 0\n\n\toverride onEnter(_info: TLPointerEventInfo) {\n\t\tconst camera = this.editor.getCamera()\n\t\tthis.initialCamera = Vec.From(camera)\n\t\tthis.initialZoom = camera.z\n\t\tthis.anchorScreenPoint = this.editor.inputs.getOriginScreenPoint().clone()\n\t\tthis.originScreenY = this.editor.inputs.getCurrentScreenPoint().y\n\t\tthis.editor.setCursor({ type: 'grab', rotation: 0 })\n\t}\n\n\toverride onPointerMove(_info: TLPointerEventInfo) {\n\t\tthis.editor.menus.clearOpenMenus()\n\n\t\tconst currentScreenY = this.editor.inputs.getCurrentScreenPoint().y\n\n\t\t// Dragging up = zoom out, dragging down = zoom in (same as google maps default)\n\t\t// we won't respect the user's zoom direction preference because it only applies\n\t\t// to mouse input\n\t\tconst dy = (this.originScreenY - currentScreenY) * -1\n\n\t\t// ~200px of drag \u2248 2x zoom change.\n\t\tconst zoomFactor = Math.pow(2, dy / 200)\n\t\tconst newZoom = this.clampZoom(this.initialZoom * zoomFactor)\n\n\t\tconst { x: cx, y: cy } = this.initialCamera\n\t\tconst { x: sx, y: sy } = this.anchorScreenPoint\n\t\tthis.editor.setCamera(\n\t\t\tnew Vec(\n\t\t\t\tcx + sx / newZoom - sx / this.initialZoom,\n\t\t\t\tcy + sy / newZoom - sy / this.initialZoom,\n\t\t\t\tnewZoom\n\t\t\t),\n\t\t\t{ immediate: true }\n\t\t)\n\t}\n\n\toverride onPointerUp(_info: TLPointerEventInfo) {\n\t\tthis.complete()\n\t}\n\n\toverride onCancel() {\n\t\tthis.parent.transition('idle')\n\t}\n\n\toverride onInterrupt() {\n\t\tthis.parent.transition('idle')\n\t}\n\n\tprivate complete() {\n\t\tconst pointerVelocity = this.editor.inputs.getPointerVelocity()\n\t\tconst velocityAtPointerUp = Math.min(pointerVelocity.len(), 2)\n\n\t\tif (velocityAtPointerUp > 0.1) {\n\t\t\t// Use velocity y-sign for momentum direction (positive y = moving down = zoom in)\n\t\t\tthis.editor.slideCamera({\n\t\t\t\tspeed: velocityAtPointerUp,\n\t\t\t\tdirection: { x: 0, y: 0, z: Math.sign(pointerVelocity.y) * 0.01 },\n\t\t\t})\n\t\t}\n\t\tthis.parent.transition('idle')\n\t}\n\n\tprivate clampZoom(zoom: number): number {\n\t\tconst { zoomSteps } = this.editor.getCameraOptions()\n\t\tconst baseZoom = this.editor.getBaseZoom()\n\t\tconst zoomMin = zoomSteps[0] * baseZoom\n\t\tconst zoomMax = last(zoomSteps)! * baseZoom\n\t\treturn clamp(zoom, zoomMin, zoomMax)\n\t}\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,WAA+B,KAAK,OAAO,YAAY;AAEzD,MAAM,yBAAyB,UAAU;AAAA,EAC/C,OAAgB,KAAK;AAAA,EAEb,oBAAoB,IAAI,IAAI;AAAA,EAC5B,gBAAgB,IAAI,IAAI;AAAA,EACxB,cAAc;AAAA,EACd,gBAAgB;AAAA,EAEf,QAAQ,OAA2B;AAC3C,UAAM,SAAS,KAAK,OAAO,UAAU;AACrC,SAAK,gBAAgB,IAAI,KAAK,MAAM;AACpC,SAAK,cAAc,OAAO;AAC1B,SAAK,oBAAoB,KAAK,OAAO,OAAO,qBAAqB,EAAE,MAAM;AACzE,SAAK,gBAAgB,KAAK,OAAO,OAAO,sBAAsB,EAAE;AAChE,SAAK,OAAO,UAAU,EAAE,MAAM,QAAQ,UAAU,EAAE,CAAC;AAAA,EACpD;AAAA,EAES,cAAc,OAA2B;AACjD,SAAK,OAAO,MAAM,eAAe;AAEjC,UAAM,iBAAiB,KAAK,OAAO,OAAO,sBAAsB,EAAE;AAKlE,UAAM,MAAM,KAAK,gBAAgB,kBAAkB;AAGnD,UAAM,aAAa,KAAK,IAAI,GAAG,KAAK,GAAG;AACvC,UAAM,UAAU,KAAK,UAAU,KAAK,cAAc,UAAU;AAE5D,UAAM,EAAE,GAAG,IAAI,GAAG,GAAG,IAAI,KAAK;AAC9B,UAAM,EAAE,GAAG,IAAI,GAAG,GAAG,IAAI,KAAK;AAC9B,SAAK,OAAO;AAAA,MACX,IAAI;AAAA,QACH,KAAK,KAAK,UAAU,KAAK,KAAK;AAAA,QAC9B,KAAK,KAAK,UAAU,KAAK,KAAK;AAAA,QAC9B;AAAA,MACD;AAAA,MACA,EAAE,WAAW,KAAK;AAAA,IACnB;AAAA,EACD;AAAA,EAES,YAAY,OAA2B;AAC/C,SAAK,SAAS;AAAA,EACf;AAAA,EAES,WAAW;AACnB,SAAK,OAAO,WAAW,MAAM;AAAA,EAC9B;AAAA,EAES,cAAc;AACtB,SAAK,OAAO,WAAW,MAAM;AAAA,EAC9B;AAAA,EAEQ,WAAW;AAClB,UAAM,kBAAkB,KAAK,OAAO,OAAO,mBAAmB;AAC9D,UAAM,sBAAsB,KAAK,IAAI,gBAAgB,IAAI,GAAG,CAAC;AAE7D,QAAI,sBAAsB,KAAK;AAE9B,WAAK,OAAO,YAAY;AAAA,QACvB,OAAO;AAAA,QACP,WAAW,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,KAAK,KAAK,gBAAgB,CAAC,IAAI,KAAK;AAAA,MACjE,CAAC;AAAA,IACF;AACA,SAAK,OAAO,WAAW,MAAM;AAAA,EAC9B;AAAA,EAEQ,UAAU,MAAsB;AACvC,UAAM,EAAE,UAAU,IAAI,KAAK,OAAO,iBAAiB;AACnD,UAAM,WAAW,KAAK,OAAO,YAAY;AACzC,UAAM,UAAU,UAAU,CAAC,IAAI;AAC/B,UAAM,UAAU,KAAK,SAAS,IAAK;AACnC,WAAO,MAAM,MAAM,SAAS,OAAO;AAAA,EACpC;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -223,6 +223,18 @@ class Idle extends StateNode {
|
|
|
223
223
|
this.editor.options.hitTestMargin / this.editor.getZoomLevel()
|
|
224
224
|
);
|
|
225
225
|
if (hitOverlay) {
|
|
226
|
+
if (hitOverlay.type === "shape_handle") {
|
|
227
|
+
const shape = this.editor.getShape(hitOverlay.props.shapeId);
|
|
228
|
+
if (shape) {
|
|
229
|
+
this.onDoubleClick({
|
|
230
|
+
...info,
|
|
231
|
+
target: "handle",
|
|
232
|
+
shape,
|
|
233
|
+
handle: hitOverlay.props.handle
|
|
234
|
+
});
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
226
238
|
const overlayType = hitOverlay.props.overlayType;
|
|
227
239
|
if (overlayType === "resize_handle" || overlayType === "rotate_handle" || overlayType === "mobile_rotate") {
|
|
228
240
|
this.onDoubleClick({
|