@excalidraw/element 0.18.0-c141960 → 0.18.0-c158187
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dev/index.js +1061 -171
- package/dist/dev/index.js.map +4 -4
- package/dist/prod/index.js +17 -17
- package/dist/types/common/src/bounds.d.ts +10 -0
- package/dist/types/common/src/colors.d.ts +5 -2
- package/dist/types/common/src/constants.d.ts +13 -11
- package/dist/types/common/src/font-metadata.d.ts +1 -3
- package/dist/types/common/src/index.d.ts +1 -0
- package/dist/types/common/src/keys.d.ts +1 -1
- package/dist/types/common/src/utility-types.d.ts +0 -1
- package/dist/types/common/src/utils.d.ts +43 -33
- package/dist/types/common/src/visualdebug.d.ts +1 -1
- package/dist/types/element/src/Scene.d.ts +3 -3
- package/dist/types/element/src/binding.d.ts +6 -4
- package/dist/types/element/src/bounds.d.ts +2 -10
- package/dist/types/element/src/collision.d.ts +2 -2
- package/dist/types/element/src/comparisons.d.ts +7 -7
- package/dist/types/element/src/dragElements.d.ts +3 -3
- package/dist/types/element/src/duplicate.d.ts +3 -3
- package/dist/types/element/src/fractionalIndex.d.ts +2 -2
- package/dist/types/element/src/frame.d.ts +5 -1
- package/dist/types/element/src/heading.d.ts +2 -1
- package/dist/types/element/src/image.d.ts +1 -11
- package/dist/types/element/src/index.d.ts +1 -0
- package/dist/types/element/src/linearElementEditor.d.ts +1 -2
- package/dist/types/element/src/mutateElement.d.ts +3 -1
- package/dist/types/element/src/newElement.d.ts +6 -6
- package/dist/types/element/src/renderElement.d.ts +0 -6
- package/dist/types/element/src/resizeElements.d.ts +10 -10
- package/dist/types/element/src/resizeTest.d.ts +1 -1
- package/dist/types/element/src/selection.d.ts +3 -7
- package/dist/types/element/src/shape.d.ts +8 -7
- package/dist/types/element/src/textMeasurements.d.ts +1 -3
- package/dist/types/{excalidraw/data → element/src}/transform.d.ts +3 -3
- package/dist/types/element/src/transformHandles.d.ts +3 -23
- package/dist/types/element/src/typeChecks.d.ts +2 -4
- package/dist/types/element/src/utils.d.ts +3 -1
- package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +62 -126
- package/dist/types/excalidraw/actions/actionAlign.d.ts +0 -1
- package/dist/types/excalidraw/actions/actionBoundText.d.ts +44 -87
- package/dist/types/excalidraw/actions/actionCanvas.d.ts +263 -510
- package/dist/types/excalidraw/actions/actionClipboard.d.ts +44 -87
- package/dist/types/excalidraw/actions/actionCropEditor.d.ts +21 -43
- package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +74 -142
- package/dist/types/excalidraw/actions/actionDistribute.d.ts +0 -1
- package/dist/types/excalidraw/actions/actionDuplicateSelection.d.ts +0 -1
- package/dist/types/excalidraw/actions/actionElementLink.d.ts +18 -40
- package/dist/types/excalidraw/actions/actionElementLock.d.ts +45 -88
- package/dist/types/excalidraw/actions/actionEmbeddable.d.ts +22 -44
- package/dist/types/excalidraw/actions/actionExport.d.ts +85 -170
- package/dist/types/excalidraw/actions/actionFinalize.d.ts +1 -2
- package/dist/types/excalidraw/actions/actionFlip.d.ts +0 -1
- package/dist/types/excalidraw/actions/actionFrame.d.ts +181 -302
- package/dist/types/excalidraw/actions/actionGroup.d.ts +48 -99
- package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +122 -180
- package/dist/types/excalidraw/actions/actionLink.d.ts +22 -44
- package/dist/types/excalidraw/actions/actionMenu.d.ts +17 -39
- package/dist/types/excalidraw/actions/actionNavigate.d.ts +14 -17
- package/dist/types/excalidraw/actions/actionProperties.d.ts +59 -102
- package/dist/types/excalidraw/actions/actionSelectAll.d.ts +24 -50
- package/dist/types/excalidraw/actions/actionStyles.d.ts +20 -42
- package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +22 -44
- package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +22 -44
- package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +16 -38
- package/dist/types/excalidraw/actions/actionToggleStats.d.ts +22 -44
- package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +22 -44
- package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +22 -44
- package/dist/types/excalidraw/actions/actionZindex.d.ts +0 -1
- package/dist/types/excalidraw/actions/manager.d.ts +1 -1
- package/dist/types/excalidraw/actions/register.d.ts +2 -2
- package/dist/types/excalidraw/appState.d.ts +3 -3
- package/dist/types/excalidraw/clipboard.d.ts +7 -31
- package/dist/types/excalidraw/components/Actions.d.ts +1 -1
- package/dist/types/excalidraw/components/App.d.ts +33 -41
- package/dist/types/excalidraw/components/Card.d.ts +0 -1
- package/dist/types/excalidraw/components/ColorPicker/ColorInput.d.ts +7 -4
- package/dist/types/excalidraw/components/ColorPicker/ColorPicker.d.ts +0 -1
- package/dist/types/excalidraw/components/ColorPicker/keyboardNavHandlers.d.ts +0 -1
- package/dist/types/excalidraw/components/CommandPalette/types.d.ts +0 -1
- package/dist/types/excalidraw/components/ConvertElementTypePopup.d.ts +2 -2
- package/dist/types/excalidraw/components/DarkModeToggle.d.ts +1 -1
- package/dist/types/excalidraw/components/DefaultSidebar.d.ts +9 -13
- package/dist/types/excalidraw/components/ElementLinkDialog.d.ts +1 -1
- package/dist/types/excalidraw/components/Ellipsify.d.ts +1 -2
- package/dist/types/excalidraw/components/ErrorDialog.d.ts +1 -1
- package/dist/types/excalidraw/components/ExcalidrawLogo.d.ts +0 -1
- package/dist/types/excalidraw/components/EyeDropper.d.ts +0 -1
- package/dist/types/excalidraw/components/FontPicker/keyboardNavHandlers.d.ts +0 -1
- package/dist/types/excalidraw/components/HelpDialog.d.ts +1 -1
- package/dist/types/excalidraw/components/InlineIcon.d.ts +2 -2
- package/dist/types/excalidraw/components/LibraryMenuControlButtons.d.ts +1 -1
- package/dist/types/excalidraw/components/LibraryMenuHeaderContent.d.ts +1 -2
- package/dist/types/excalidraw/components/LibraryUnit.d.ts +2 -3
- package/dist/types/excalidraw/components/LoadingMessage.d.ts +0 -1
- package/dist/types/excalidraw/components/MobileToolBar.d.ts +0 -1
- package/dist/types/excalidraw/components/Modal.d.ts +0 -1
- package/dist/types/excalidraw/components/OverwriteConfirm/OverwriteConfirm.d.ts +1 -1
- package/dist/types/excalidraw/components/RadioGroup.d.ts +0 -1
- package/dist/types/excalidraw/components/RadioSelection.d.ts +4 -4
- package/dist/types/excalidraw/components/ScrollableList.d.ts +0 -1
- package/dist/types/excalidraw/components/Sidebar/Sidebar.d.ts +15 -21
- package/dist/types/excalidraw/components/Sidebar/SidebarHeader.d.ts +1 -1
- package/dist/types/excalidraw/components/Sidebar/SidebarTab.d.ts +1 -2
- package/dist/types/excalidraw/components/Sidebar/SidebarTabTrigger.d.ts +1 -2
- package/dist/types/excalidraw/components/Sidebar/SidebarTabTriggers.d.ts +1 -2
- package/dist/types/excalidraw/components/Sidebar/SidebarTabs.d.ts +1 -2
- package/dist/types/excalidraw/components/Spinner.d.ts +4 -4
- package/dist/types/excalidraw/components/Stats/CanvasGrid.d.ts +0 -1
- package/dist/types/excalidraw/components/Stats/Collapsible.d.ts +0 -1
- package/dist/types/excalidraw/components/Stats/DragInput.d.ts +0 -1
- package/dist/types/excalidraw/components/Stats/index.d.ts +7 -8
- package/dist/types/excalidraw/components/TTDDialog/TTDDialog.d.ts +1 -2
- package/dist/types/excalidraw/components/TTDDialog/TTDDialogOutput.d.ts +0 -1
- package/dist/types/excalidraw/components/TTDDialog/TTDDialogTab.d.ts +1 -2
- package/dist/types/excalidraw/components/TTDDialog/TTDDialogTabTrigger.d.ts +1 -2
- package/dist/types/excalidraw/components/TTDDialog/TTDDialogTabTriggers.d.ts +1 -2
- package/dist/types/excalidraw/components/TTDDialog/TTDDialogTrigger.d.ts +1 -1
- package/dist/types/excalidraw/components/TTDDialog/common.d.ts +2 -3
- package/dist/types/excalidraw/components/Toast.d.ts +3 -3
- package/dist/types/excalidraw/components/Trans.d.ts +2 -2
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenu.d.ts +28 -32
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuContent.d.ts +5 -5
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuGroup.d.ts +3 -3
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItem.d.ts +10 -18
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemContent.d.ts +3 -3
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemContentRadio.d.ts +0 -1
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemCustom.d.ts +2 -2
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemLink.d.ts +6 -6
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuTrigger.d.ts +3 -4
- package/dist/types/excalidraw/components/dropdownMenu/common.d.ts +1 -1
- package/dist/types/excalidraw/components/hoc/withInternalFallback.d.ts +1 -1
- package/dist/types/excalidraw/components/hyperlink/helpers.d.ts +1 -1
- package/dist/types/excalidraw/components/icons.d.ts +11 -11
- package/dist/types/excalidraw/components/live-collaboration/LiveCollaborationTrigger.d.ts +2 -13
- package/dist/types/excalidraw/components/main-menu/DefaultItems.d.ts +2 -2
- package/dist/types/excalidraw/components/main-menu/MainMenu.d.ts +26 -28
- package/dist/types/excalidraw/components/welcome-screen/WelcomeScreen.Center.d.ts +6 -6
- package/dist/types/excalidraw/components/welcome-screen/WelcomeScreen.d.ts +15 -16
- package/dist/types/excalidraw/data/blob.d.ts +321 -3
- package/dist/types/excalidraw/data/encode.d.ts +4 -4
- package/dist/types/excalidraw/data/encryption.d.ts +5 -5
- package/dist/types/excalidraw/data/filesystem.d.ts +2 -2
- package/dist/types/excalidraw/data/index.d.ts +3 -3
- package/dist/types/excalidraw/data/json.d.ts +159 -2
- package/dist/types/excalidraw/data/library.d.ts +24 -9
- package/dist/types/excalidraw/data/restore.d.ts +25 -10
- package/dist/types/excalidraw/editor-jotai.d.ts +11 -11
- package/dist/types/excalidraw/hooks/useOutsideClick.d.ts +1 -2
- package/dist/types/excalidraw/hooks/useScrollPosition.d.ts +1 -2
- package/dist/types/excalidraw/i18n.d.ts +2 -2
- package/dist/types/excalidraw/index.d.ts +2 -4
- package/dist/types/excalidraw/renderer/helpers.d.ts +6 -4
- package/dist/types/excalidraw/renderer/interactiveScene.d.ts +8 -6
- package/dist/types/excalidraw/scene/Renderer.d.ts +5 -2
- package/dist/types/excalidraw/scene/export.d.ts +2 -2
- package/dist/types/excalidraw/scene/scroll.d.ts +1 -6
- package/dist/types/excalidraw/scene/types.d.ts +7 -2
- package/dist/types/excalidraw/snapping.d.ts +5 -5
- package/dist/types/excalidraw/subset/harfbuzz/harfbuzz-bindings.d.ts +1 -1
- package/dist/types/excalidraw/subset/harfbuzz/harfbuzz-loader.d.ts +1 -1
- package/dist/types/excalidraw/subset/harfbuzz/harfbuzz-wasm.d.ts +1 -1
- package/dist/types/excalidraw/subset/woff2/woff2-loader.d.ts +2 -2
- package/dist/types/excalidraw/subset/woff2/woff2-wasm.d.ts +1 -1
- package/dist/types/excalidraw/types.d.ts +1 -1
- package/dist/types/excalidraw/wysiwyg/textWysiwyg.d.ts +2 -2
- package/dist/types/math/src/polygon.d.ts +2 -2
- package/dist/types/math/src/range.d.ts +1 -3
- package/dist/types/math/src/segment.d.ts +3 -3
- package/dist/types/utils/src/bbox.d.ts +1 -1
- package/dist/types/utils/src/export.d.ts +5 -5
- package/dist/types/utils/src/shape.d.ts +6 -6
- package/dist/types/utils/src/withinBounds.d.ts +2 -2
- package/package.json +3 -3
package/dist/dev/index.js
CHANGED
|
@@ -2447,21 +2447,6 @@ var getClosedCurveShape = (element, roughShape, startingPoint = pointFrom(0, 0),
|
|
|
2447
2447
|
|
|
2448
2448
|
// src/shape.ts
|
|
2449
2449
|
init_define_import_meta_env();
|
|
2450
|
-
import {
|
|
2451
|
-
pointFrom as pointFrom13,
|
|
2452
|
-
pointDistance as pointDistance6,
|
|
2453
|
-
pointRotateRads as pointRotateRads12
|
|
2454
|
-
} from "@excalidraw/math";
|
|
2455
|
-
import {
|
|
2456
|
-
ROUGHNESS,
|
|
2457
|
-
isTransparent as isTransparent3,
|
|
2458
|
-
assertNever as assertNever2,
|
|
2459
|
-
COLOR_PALETTE,
|
|
2460
|
-
LINE_POLYGON_POINT_MERGE_DISTANCE
|
|
2461
|
-
} from "@excalidraw/common";
|
|
2462
|
-
|
|
2463
|
-
// src/renderElement.ts
|
|
2464
|
-
init_define_import_meta_env();
|
|
2465
2450
|
|
|
2466
2451
|
// ../../node_modules/perfect-freehand/dist/esm/index.js
|
|
2467
2452
|
init_define_import_meta_env();
|
|
@@ -2626,7 +2611,24 @@ function ae(e, t = {}) {
|
|
|
2626
2611
|
return ce(me(e, t), t);
|
|
2627
2612
|
}
|
|
2628
2613
|
|
|
2614
|
+
// src/shape.ts
|
|
2615
|
+
import {
|
|
2616
|
+
pointFrom as pointFrom13,
|
|
2617
|
+
pointDistance as pointDistance6,
|
|
2618
|
+
pointRotateRads as pointRotateRads12
|
|
2619
|
+
} from "@excalidraw/math";
|
|
2620
|
+
import {
|
|
2621
|
+
ROUGHNESS,
|
|
2622
|
+
THEME as THEME2,
|
|
2623
|
+
isTransparent as isTransparent3,
|
|
2624
|
+
assertNever as assertNever2,
|
|
2625
|
+
COLOR_PALETTE,
|
|
2626
|
+
LINE_POLYGON_POINT_MERGE_DISTANCE,
|
|
2627
|
+
applyDarkModeFilter as applyDarkModeFilter2
|
|
2628
|
+
} from "@excalidraw/common";
|
|
2629
|
+
|
|
2629
2630
|
// src/renderElement.ts
|
|
2631
|
+
init_define_import_meta_env();
|
|
2630
2632
|
import {
|
|
2631
2633
|
isRightAngleRads,
|
|
2632
2634
|
lineSegment as lineSegment6,
|
|
@@ -2644,7 +2646,8 @@ import {
|
|
|
2644
2646
|
getFontString as getFontString3,
|
|
2645
2647
|
isRTL,
|
|
2646
2648
|
getVerticalOffset,
|
|
2647
|
-
invariant as invariant9
|
|
2649
|
+
invariant as invariant9,
|
|
2650
|
+
applyDarkModeFilter
|
|
2648
2651
|
} from "@excalidraw/common";
|
|
2649
2652
|
|
|
2650
2653
|
// src/cropElement.ts
|
|
@@ -3129,7 +3132,6 @@ import {
|
|
|
3129
3132
|
} from "@excalidraw/common";
|
|
3130
3133
|
import {
|
|
3131
3134
|
deconstructLinearOrFreeDrawElement as deconstructLinearOrFreeDrawElement2,
|
|
3132
|
-
getHoveredElementForBinding as getHoveredElementForBinding2,
|
|
3133
3135
|
isPathALoop as isPathALoop2,
|
|
3134
3136
|
moveArrowAboveBindable,
|
|
3135
3137
|
projectFixedPointOntoDiagonal as projectFixedPointOntoDiagonal2
|
|
@@ -3350,7 +3352,6 @@ var getDefaultRoundnessTypeForElement = (element) => {
|
|
|
3350
3352
|
}
|
|
3351
3353
|
return null;
|
|
3352
3354
|
};
|
|
3353
|
-
var isBounds = (box) => Array.isArray(box) && box.length === 4 && typeof box[0] === "number" && typeof box[1] === "number" && typeof box[2] === "number" && typeof box[3] === "number";
|
|
3354
3355
|
var getLinearElementSubType = (element) => {
|
|
3355
3356
|
if (isSharpArrow(element)) {
|
|
3356
3357
|
return "sharpArrow";
|
|
@@ -5177,7 +5178,11 @@ var isBindableElementInsideOtherBindable = (innerElement, outerElement, elements
|
|
|
5177
5178
|
|
|
5178
5179
|
// src/heading.ts
|
|
5179
5180
|
init_define_import_meta_env();
|
|
5180
|
-
import {
|
|
5181
|
+
import {
|
|
5182
|
+
invariant as invariant5,
|
|
5183
|
+
isDevEnv as isDevEnv2,
|
|
5184
|
+
isTestEnv as isTestEnv3
|
|
5185
|
+
} from "@excalidraw/common";
|
|
5181
5186
|
import {
|
|
5182
5187
|
pointFrom as pointFrom6,
|
|
5183
5188
|
pointFromVector as pointFromVector5,
|
|
@@ -6955,10 +6960,12 @@ var shouldEnableBindingForPointerEvent = (event) => {
|
|
|
6955
6960
|
var isBindingEnabled = (appState) => {
|
|
6956
6961
|
return appState.isBindingEnabled;
|
|
6957
6962
|
};
|
|
6958
|
-
var bindOrUnbindBindingElement = (arrow, draggingPoints, scene, appState, opts) => {
|
|
6963
|
+
var bindOrUnbindBindingElement = (arrow, draggingPoints, scenePointerX, scenePointerY, scene, appState, opts) => {
|
|
6959
6964
|
const { start, end } = getBindingStrategyForDraggingBindingElementEndpoints(
|
|
6960
6965
|
arrow,
|
|
6961
6966
|
draggingPoints,
|
|
6967
|
+
scenePointerX,
|
|
6968
|
+
scenePointerY,
|
|
6962
6969
|
scene.getNonDeletedElementsMap(),
|
|
6963
6970
|
scene.getNonDeletedElements(),
|
|
6964
6971
|
appState,
|
|
@@ -7205,7 +7212,7 @@ var bindingStrategyForSimpleArrowEndpointDragging_complex = (point, currentBindi
|
|
|
7205
7212
|
}
|
|
7206
7213
|
return { current, other: isMultiPoint ? { mode: void 0 } : other };
|
|
7207
7214
|
};
|
|
7208
|
-
var getBindingStrategyForDraggingBindingElementEndpoints = (arrow, draggingPoints, elementsMap, elements, appState, opts) => {
|
|
7215
|
+
var getBindingStrategyForDraggingBindingElementEndpoints = (arrow, draggingPoints, screenPointerX, screenPointerY, elementsMap, elements, appState, opts) => {
|
|
7209
7216
|
if (getFeatureFlag("COMPLEX_BINDINGS")) {
|
|
7210
7217
|
return getBindingStrategyForDraggingBindingElementEndpoints_complex(
|
|
7211
7218
|
arrow,
|
|
@@ -7219,13 +7226,15 @@ var getBindingStrategyForDraggingBindingElementEndpoints = (arrow, draggingPoint
|
|
|
7219
7226
|
return getBindingStrategyForDraggingBindingElementEndpoints_simple(
|
|
7220
7227
|
arrow,
|
|
7221
7228
|
draggingPoints,
|
|
7229
|
+
screenPointerX,
|
|
7230
|
+
screenPointerY,
|
|
7222
7231
|
elementsMap,
|
|
7223
7232
|
elements,
|
|
7224
7233
|
appState,
|
|
7225
7234
|
opts
|
|
7226
7235
|
);
|
|
7227
7236
|
};
|
|
7228
|
-
var getBindingStrategyForDraggingBindingElementEndpoints_simple = (arrow, draggingPoints, elementsMap, elements, appState, opts) => {
|
|
7237
|
+
var getBindingStrategyForDraggingBindingElementEndpoints_simple = (arrow, draggingPoints, scenePointerX, scenePointerY, elementsMap, elements, appState, opts) => {
|
|
7229
7238
|
const startIdx = 0;
|
|
7230
7239
|
const endIdx = arrow.points.length - 1;
|
|
7231
7240
|
const startDragged = draggingPoints.has(startIdx);
|
|
@@ -7275,7 +7284,11 @@ var getBindingStrategyForDraggingBindingElementEndpoints_simple = (arrow, draggi
|
|
|
7275
7284
|
elementsMap,
|
|
7276
7285
|
(e) => maxBindingDistance_simple(appState.zoom)
|
|
7277
7286
|
);
|
|
7278
|
-
const pointInElement = hit &&
|
|
7287
|
+
const pointInElement = hit && (opts?.angleLocked ? isPointInElement(
|
|
7288
|
+
pointFrom8(scenePointerX, scenePointerY),
|
|
7289
|
+
hit,
|
|
7290
|
+
elementsMap
|
|
7291
|
+
) : isPointInElement(globalPoint, hit, elementsMap));
|
|
7279
7292
|
const otherBindableElement = otherBinding ? elementsMap.get(
|
|
7280
7293
|
otherBinding.elementId
|
|
7281
7294
|
) : void 0;
|
|
@@ -7345,10 +7358,25 @@ var getBindingStrategyForDraggingBindingElementEndpoints_simple = (arrow, draggi
|
|
|
7345
7358
|
elementsMap
|
|
7346
7359
|
) || globalPoint
|
|
7347
7360
|
} : { mode: null };
|
|
7361
|
+
const otherEndpoint = LinearElementEditor.getPointAtIndexGlobalCoordinates(
|
|
7362
|
+
arrow,
|
|
7363
|
+
startDragged ? -1 : 0,
|
|
7364
|
+
elementsMap
|
|
7365
|
+
);
|
|
7348
7366
|
const other = otherBindableElement && !otherFocusPointIsInElement && appState.selectedLinearElement?.initialState.altFocusPoint ? {
|
|
7349
7367
|
mode: "orbit",
|
|
7350
7368
|
element: otherBindableElement,
|
|
7351
7369
|
focusPoint: appState.selectedLinearElement.initialState.altFocusPoint
|
|
7370
|
+
} : opts?.angleLocked && otherBindableElement ? {
|
|
7371
|
+
mode: "orbit",
|
|
7372
|
+
element: otherBindableElement,
|
|
7373
|
+
focusPoint: projectFixedPointOntoDiagonal(
|
|
7374
|
+
arrow,
|
|
7375
|
+
otherEndpoint,
|
|
7376
|
+
otherBindableElement,
|
|
7377
|
+
startDragged ? "end" : "start",
|
|
7378
|
+
elementsMap
|
|
7379
|
+
) || otherEndpoint
|
|
7352
7380
|
} : { mode: void 0 };
|
|
7353
7381
|
return {
|
|
7354
7382
|
start: startDragged ? current : other,
|
|
@@ -7450,6 +7478,8 @@ var bindOrUnbindBindingElements = (selectedArrows, scene, appState) => {
|
|
|
7450
7478
|
arrow,
|
|
7451
7479
|
/* @__PURE__ */ new Map(),
|
|
7452
7480
|
// No dragging points in this case
|
|
7481
|
+
Infinity,
|
|
7482
|
+
Infinity,
|
|
7453
7483
|
scene,
|
|
7454
7484
|
appState
|
|
7455
7485
|
);
|
|
@@ -7578,7 +7608,14 @@ var updateBoundElements = (changedElement, scene, options) => {
|
|
|
7578
7608
|
};
|
|
7579
7609
|
var updateBindings = (latestElement, scene, appState, options) => {
|
|
7580
7610
|
if (isArrowElement(latestElement)) {
|
|
7581
|
-
bindOrUnbindBindingElement(
|
|
7611
|
+
bindOrUnbindBindingElement(
|
|
7612
|
+
latestElement,
|
|
7613
|
+
/* @__PURE__ */ new Map(),
|
|
7614
|
+
Infinity,
|
|
7615
|
+
Infinity,
|
|
7616
|
+
scene,
|
|
7617
|
+
appState
|
|
7618
|
+
);
|
|
7582
7619
|
} else {
|
|
7583
7620
|
updateBoundElements(latestElement, scene, {
|
|
7584
7621
|
...options,
|
|
@@ -7617,7 +7654,7 @@ var getDistanceForBinding = (point, bindableElement, elementsMap, zoom) => {
|
|
|
7617
7654
|
};
|
|
7618
7655
|
var bindPointToSnapToElementOutline = (arrowElement, bindableElement, startOrEnd, elementsMap, customIntersector) => {
|
|
7619
7656
|
const elbowed = isElbowArrow(arrowElement);
|
|
7620
|
-
const point =
|
|
7657
|
+
const point = LinearElementEditor.getPointAtIndexGlobalCoordinates(
|
|
7621
7658
|
arrowElement,
|
|
7622
7659
|
startOrEnd === "start" ? 0 : -1,
|
|
7623
7660
|
elementsMap
|
|
@@ -7625,7 +7662,12 @@ var bindPointToSnapToElementOutline = (arrowElement, bindableElement, startOrEnd
|
|
|
7625
7662
|
if (arrowElement.points.length < 2) {
|
|
7626
7663
|
return point;
|
|
7627
7664
|
}
|
|
7628
|
-
const edgePoint = isRectanguloidElement(bindableElement) ? avoidRectangularCorner(
|
|
7665
|
+
const edgePoint = isRectanguloidElement(bindableElement) && elbowed ? avoidRectangularCorner(
|
|
7666
|
+
arrowElement,
|
|
7667
|
+
bindableElement,
|
|
7668
|
+
elementsMap,
|
|
7669
|
+
point
|
|
7670
|
+
) : point;
|
|
7629
7671
|
const adjacentPoint = customIntersector && !elbowed ? customIntersector[1] : LinearElementEditor.getPointAtIndexGlobalCoordinates(
|
|
7630
7672
|
arrowElement,
|
|
7631
7673
|
startOrEnd === "start" ? 1 : -2,
|
|
@@ -8334,6 +8376,356 @@ var normalizeFixedPoint = (fixedPoint) => {
|
|
|
8334
8376
|
}
|
|
8335
8377
|
return fixedPoint;
|
|
8336
8378
|
};
|
|
8379
|
+
var getShapeType = (element) => {
|
|
8380
|
+
if (element.type === "ellipse" || element.type === "diamond") {
|
|
8381
|
+
return element.type;
|
|
8382
|
+
}
|
|
8383
|
+
return "rectangle";
|
|
8384
|
+
};
|
|
8385
|
+
var SHAPE_CONFIGS = {
|
|
8386
|
+
// rectangle: 15° corners, 75° edges
|
|
8387
|
+
rectangle: [
|
|
8388
|
+
{ centerAngle: 0, sectorWidth: 75, side: "right" },
|
|
8389
|
+
{ centerAngle: 45, sectorWidth: 15, side: "bottom-right" },
|
|
8390
|
+
{ centerAngle: 90, sectorWidth: 75, side: "bottom" },
|
|
8391
|
+
{ centerAngle: 135, sectorWidth: 15, side: "bottom-left" },
|
|
8392
|
+
{ centerAngle: 180, sectorWidth: 75, side: "left" },
|
|
8393
|
+
{ centerAngle: 225, sectorWidth: 15, side: "top-left" },
|
|
8394
|
+
{ centerAngle: 270, sectorWidth: 75, side: "top" },
|
|
8395
|
+
{ centerAngle: 315, sectorWidth: 15, side: "top-right" }
|
|
8396
|
+
],
|
|
8397
|
+
// diamond: 15° vertices, 75° edges
|
|
8398
|
+
diamond: [
|
|
8399
|
+
{ centerAngle: 0, sectorWidth: 15, side: "right" },
|
|
8400
|
+
{ centerAngle: 45, sectorWidth: 75, side: "bottom-right" },
|
|
8401
|
+
{ centerAngle: 90, sectorWidth: 15, side: "bottom" },
|
|
8402
|
+
{ centerAngle: 135, sectorWidth: 75, side: "bottom-left" },
|
|
8403
|
+
{ centerAngle: 180, sectorWidth: 15, side: "left" },
|
|
8404
|
+
{ centerAngle: 225, sectorWidth: 75, side: "top-left" },
|
|
8405
|
+
{ centerAngle: 270, sectorWidth: 15, side: "top" },
|
|
8406
|
+
{ centerAngle: 315, sectorWidth: 75, side: "top-right" }
|
|
8407
|
+
],
|
|
8408
|
+
// ellipse: 15° cardinal points, 75° diagonals
|
|
8409
|
+
ellipse: [
|
|
8410
|
+
{ centerAngle: 0, sectorWidth: 15, side: "right" },
|
|
8411
|
+
{ centerAngle: 45, sectorWidth: 75, side: "bottom-right" },
|
|
8412
|
+
{ centerAngle: 90, sectorWidth: 15, side: "bottom" },
|
|
8413
|
+
{ centerAngle: 135, sectorWidth: 75, side: "bottom-left" },
|
|
8414
|
+
{ centerAngle: 180, sectorWidth: 15, side: "left" },
|
|
8415
|
+
{ centerAngle: 225, sectorWidth: 75, side: "top-left" },
|
|
8416
|
+
{ centerAngle: 270, sectorWidth: 15, side: "top" },
|
|
8417
|
+
{ centerAngle: 315, sectorWidth: 75, side: "top-right" }
|
|
8418
|
+
]
|
|
8419
|
+
};
|
|
8420
|
+
var getSectorBoundaries = (config) => {
|
|
8421
|
+
return config.map((sector, index) => {
|
|
8422
|
+
const halfWidth = sector.sectorWidth / 2;
|
|
8423
|
+
let start = sector.centerAngle - halfWidth;
|
|
8424
|
+
let end = sector.centerAngle + halfWidth;
|
|
8425
|
+
start = (start % 360 + 360) % 360;
|
|
8426
|
+
end = (end % 360 + 360) % 360;
|
|
8427
|
+
return { start, end, side: sector.side };
|
|
8428
|
+
});
|
|
8429
|
+
};
|
|
8430
|
+
var getShapeSideAdaptive = (fixedPoint, shapeType) => {
|
|
8431
|
+
const [x, y] = fixedPoint;
|
|
8432
|
+
const centerX = x - 0.5;
|
|
8433
|
+
const centerY = y - 0.5;
|
|
8434
|
+
let angle = Math.atan2(centerY, centerX);
|
|
8435
|
+
if (angle < 0) {
|
|
8436
|
+
angle += 2 * Math.PI;
|
|
8437
|
+
}
|
|
8438
|
+
const degrees = angle * 180 / Math.PI;
|
|
8439
|
+
const config = SHAPE_CONFIGS[shapeType];
|
|
8440
|
+
const boundaries = getSectorBoundaries(config);
|
|
8441
|
+
for (const boundary of boundaries) {
|
|
8442
|
+
if (boundary.start <= boundary.end) {
|
|
8443
|
+
if (degrees >= boundary.start && degrees <= boundary.end) {
|
|
8444
|
+
return boundary.side;
|
|
8445
|
+
}
|
|
8446
|
+
} else if (degrees >= boundary.start || degrees <= boundary.end) {
|
|
8447
|
+
return boundary.side;
|
|
8448
|
+
}
|
|
8449
|
+
}
|
|
8450
|
+
let minDiff = Infinity;
|
|
8451
|
+
let nearestSide = config[0].side;
|
|
8452
|
+
for (const sector of config) {
|
|
8453
|
+
let diff = Math.abs(degrees - sector.centerAngle);
|
|
8454
|
+
if (diff > 180) {
|
|
8455
|
+
diff = 360 - diff;
|
|
8456
|
+
}
|
|
8457
|
+
if (diff < minDiff) {
|
|
8458
|
+
minDiff = diff;
|
|
8459
|
+
nearestSide = sector.side;
|
|
8460
|
+
}
|
|
8461
|
+
}
|
|
8462
|
+
return nearestSide;
|
|
8463
|
+
};
|
|
8464
|
+
var getBindingSideMidPoint = (binding, elementsMap) => {
|
|
8465
|
+
const bindableElement = elementsMap.get(binding.elementId);
|
|
8466
|
+
if (!bindableElement || bindableElement.isDeleted || !isBindableElement(bindableElement)) {
|
|
8467
|
+
return null;
|
|
8468
|
+
}
|
|
8469
|
+
const center = elementCenterPoint(bindableElement, elementsMap);
|
|
8470
|
+
const shapeType = getShapeType(bindableElement);
|
|
8471
|
+
const side = getShapeSideAdaptive(
|
|
8472
|
+
normalizeFixedPoint(binding.fixedPoint),
|
|
8473
|
+
shapeType
|
|
8474
|
+
);
|
|
8475
|
+
const OFFSET = 0.01;
|
|
8476
|
+
if (bindableElement.type === "diamond") {
|
|
8477
|
+
const [sides, corners] = deconstructDiamondElement(bindableElement);
|
|
8478
|
+
const [bottomRight, bottomLeft, topLeft, topRight] = sides;
|
|
8479
|
+
let x;
|
|
8480
|
+
let y;
|
|
8481
|
+
switch (side) {
|
|
8482
|
+
case "left": {
|
|
8483
|
+
if (corners.length >= 3) {
|
|
8484
|
+
const leftCorner = corners[2];
|
|
8485
|
+
const midPoint = leftCorner[1];
|
|
8486
|
+
x = midPoint[0] - OFFSET;
|
|
8487
|
+
y = midPoint[1];
|
|
8488
|
+
} else {
|
|
8489
|
+
const midPoint = getMidPoint(bottomLeft[1], topLeft[0]);
|
|
8490
|
+
x = midPoint[0] - OFFSET;
|
|
8491
|
+
y = midPoint[1];
|
|
8492
|
+
}
|
|
8493
|
+
break;
|
|
8494
|
+
}
|
|
8495
|
+
case "right": {
|
|
8496
|
+
if (corners.length >= 1) {
|
|
8497
|
+
const rightCorner = corners[0];
|
|
8498
|
+
const midPoint = rightCorner[1];
|
|
8499
|
+
x = midPoint[0] + OFFSET;
|
|
8500
|
+
y = midPoint[1];
|
|
8501
|
+
} else {
|
|
8502
|
+
const midPoint = getMidPoint(topRight[1], bottomRight[0]);
|
|
8503
|
+
x = midPoint[0] + OFFSET;
|
|
8504
|
+
y = midPoint[1];
|
|
8505
|
+
}
|
|
8506
|
+
break;
|
|
8507
|
+
}
|
|
8508
|
+
case "top": {
|
|
8509
|
+
if (corners.length >= 4) {
|
|
8510
|
+
const topCorner = corners[3];
|
|
8511
|
+
const midPoint = topCorner[1];
|
|
8512
|
+
x = midPoint[0];
|
|
8513
|
+
y = midPoint[1] - OFFSET;
|
|
8514
|
+
} else {
|
|
8515
|
+
const midPoint = getMidPoint(topLeft[1], topRight[0]);
|
|
8516
|
+
x = midPoint[0];
|
|
8517
|
+
y = midPoint[1] - OFFSET;
|
|
8518
|
+
}
|
|
8519
|
+
break;
|
|
8520
|
+
}
|
|
8521
|
+
case "bottom": {
|
|
8522
|
+
if (corners.length >= 2) {
|
|
8523
|
+
const bottomCorner = corners[1];
|
|
8524
|
+
const midPoint = bottomCorner[1];
|
|
8525
|
+
x = midPoint[0];
|
|
8526
|
+
y = midPoint[1] + OFFSET;
|
|
8527
|
+
} else {
|
|
8528
|
+
const midPoint = getMidPoint(bottomRight[1], bottomLeft[0]);
|
|
8529
|
+
x = midPoint[0];
|
|
8530
|
+
y = midPoint[1] + OFFSET;
|
|
8531
|
+
}
|
|
8532
|
+
break;
|
|
8533
|
+
}
|
|
8534
|
+
case "top-right": {
|
|
8535
|
+
const midPoint = getMidPoint(topRight[0], topRight[1]);
|
|
8536
|
+
x = midPoint[0] + OFFSET * 0.707;
|
|
8537
|
+
y = midPoint[1] - OFFSET * 0.707;
|
|
8538
|
+
break;
|
|
8539
|
+
}
|
|
8540
|
+
case "bottom-right": {
|
|
8541
|
+
const midPoint = getMidPoint(bottomRight[0], bottomRight[1]);
|
|
8542
|
+
x = midPoint[0] + OFFSET * 0.707;
|
|
8543
|
+
y = midPoint[1] + OFFSET * 0.707;
|
|
8544
|
+
break;
|
|
8545
|
+
}
|
|
8546
|
+
case "bottom-left": {
|
|
8547
|
+
const midPoint = getMidPoint(bottomLeft[0], bottomLeft[1]);
|
|
8548
|
+
x = midPoint[0] - OFFSET * 0.707;
|
|
8549
|
+
y = midPoint[1] + OFFSET * 0.707;
|
|
8550
|
+
break;
|
|
8551
|
+
}
|
|
8552
|
+
case "top-left": {
|
|
8553
|
+
const midPoint = getMidPoint(topLeft[0], topLeft[1]);
|
|
8554
|
+
x = midPoint[0] - OFFSET * 0.707;
|
|
8555
|
+
y = midPoint[1] - OFFSET * 0.707;
|
|
8556
|
+
break;
|
|
8557
|
+
}
|
|
8558
|
+
default: {
|
|
8559
|
+
return null;
|
|
8560
|
+
}
|
|
8561
|
+
}
|
|
8562
|
+
return pointRotateRads8(pointFrom8(x, y), center, bindableElement.angle);
|
|
8563
|
+
}
|
|
8564
|
+
if (bindableElement.type === "ellipse") {
|
|
8565
|
+
const ellipseCenterX = bindableElement.x + bindableElement.width / 2;
|
|
8566
|
+
const ellipseCenterY = bindableElement.y + bindableElement.height / 2;
|
|
8567
|
+
const radiusX = bindableElement.width / 2;
|
|
8568
|
+
const radiusY = bindableElement.height / 2;
|
|
8569
|
+
let x;
|
|
8570
|
+
let y;
|
|
8571
|
+
switch (side) {
|
|
8572
|
+
case "top": {
|
|
8573
|
+
x = ellipseCenterX;
|
|
8574
|
+
y = ellipseCenterY - radiusY - OFFSET;
|
|
8575
|
+
break;
|
|
8576
|
+
}
|
|
8577
|
+
case "right": {
|
|
8578
|
+
x = ellipseCenterX + radiusX + OFFSET;
|
|
8579
|
+
y = ellipseCenterY;
|
|
8580
|
+
break;
|
|
8581
|
+
}
|
|
8582
|
+
case "bottom": {
|
|
8583
|
+
x = ellipseCenterX;
|
|
8584
|
+
y = ellipseCenterY + radiusY + OFFSET;
|
|
8585
|
+
break;
|
|
8586
|
+
}
|
|
8587
|
+
case "left": {
|
|
8588
|
+
x = ellipseCenterX - radiusX - OFFSET;
|
|
8589
|
+
y = ellipseCenterY;
|
|
8590
|
+
break;
|
|
8591
|
+
}
|
|
8592
|
+
case "top-right": {
|
|
8593
|
+
const angle = -Math.PI / 4;
|
|
8594
|
+
const ellipseX = radiusX * Math.cos(angle);
|
|
8595
|
+
const ellipseY = radiusY * Math.sin(angle);
|
|
8596
|
+
x = ellipseCenterX + ellipseX + OFFSET * 0.707;
|
|
8597
|
+
y = ellipseCenterY + ellipseY - OFFSET * 0.707;
|
|
8598
|
+
break;
|
|
8599
|
+
}
|
|
8600
|
+
case "bottom-right": {
|
|
8601
|
+
const angle = Math.PI / 4;
|
|
8602
|
+
const ellipseX = radiusX * Math.cos(angle);
|
|
8603
|
+
const ellipseY = radiusY * Math.sin(angle);
|
|
8604
|
+
x = ellipseCenterX + ellipseX + OFFSET * 0.707;
|
|
8605
|
+
y = ellipseCenterY + ellipseY + OFFSET * 0.707;
|
|
8606
|
+
break;
|
|
8607
|
+
}
|
|
8608
|
+
case "bottom-left": {
|
|
8609
|
+
const angle = 3 * Math.PI / 4;
|
|
8610
|
+
const ellipseX = radiusX * Math.cos(angle);
|
|
8611
|
+
const ellipseY = radiusY * Math.sin(angle);
|
|
8612
|
+
x = ellipseCenterX + ellipseX - OFFSET * 0.707;
|
|
8613
|
+
y = ellipseCenterY + ellipseY + OFFSET * 0.707;
|
|
8614
|
+
break;
|
|
8615
|
+
}
|
|
8616
|
+
case "top-left": {
|
|
8617
|
+
const angle = -3 * Math.PI / 4;
|
|
8618
|
+
const ellipseX = radiusX * Math.cos(angle);
|
|
8619
|
+
const ellipseY = radiusY * Math.sin(angle);
|
|
8620
|
+
x = ellipseCenterX + ellipseX - OFFSET * 0.707;
|
|
8621
|
+
y = ellipseCenterY + ellipseY - OFFSET * 0.707;
|
|
8622
|
+
break;
|
|
8623
|
+
}
|
|
8624
|
+
default: {
|
|
8625
|
+
return null;
|
|
8626
|
+
}
|
|
8627
|
+
}
|
|
8628
|
+
return pointRotateRads8(pointFrom8(x, y), center, bindableElement.angle);
|
|
8629
|
+
}
|
|
8630
|
+
if (isRectangularElement(bindableElement)) {
|
|
8631
|
+
const [sides, corners] = deconstructRectanguloidElement(
|
|
8632
|
+
bindableElement
|
|
8633
|
+
);
|
|
8634
|
+
const [top, right, bottom, left] = sides;
|
|
8635
|
+
let x;
|
|
8636
|
+
let y;
|
|
8637
|
+
switch (side) {
|
|
8638
|
+
case "top": {
|
|
8639
|
+
const midPoint = getMidPoint(top[0], top[1]);
|
|
8640
|
+
x = midPoint[0];
|
|
8641
|
+
y = midPoint[1] - OFFSET;
|
|
8642
|
+
break;
|
|
8643
|
+
}
|
|
8644
|
+
case "right": {
|
|
8645
|
+
const midPoint = getMidPoint(right[0], right[1]);
|
|
8646
|
+
x = midPoint[0] + OFFSET;
|
|
8647
|
+
y = midPoint[1];
|
|
8648
|
+
break;
|
|
8649
|
+
}
|
|
8650
|
+
case "bottom": {
|
|
8651
|
+
const midPoint = getMidPoint(bottom[0], bottom[1]);
|
|
8652
|
+
x = midPoint[0];
|
|
8653
|
+
y = midPoint[1] + OFFSET;
|
|
8654
|
+
break;
|
|
8655
|
+
}
|
|
8656
|
+
case "left": {
|
|
8657
|
+
const midPoint = getMidPoint(left[0], left[1]);
|
|
8658
|
+
x = midPoint[0] - OFFSET;
|
|
8659
|
+
y = midPoint[1];
|
|
8660
|
+
break;
|
|
8661
|
+
}
|
|
8662
|
+
case "top-left": {
|
|
8663
|
+
if (corners.length >= 1) {
|
|
8664
|
+
const corner = corners[0];
|
|
8665
|
+
const p1 = corner[0];
|
|
8666
|
+
const p2 = corner[3];
|
|
8667
|
+
const midPoint = getMidPoint(p1, p2);
|
|
8668
|
+
x = midPoint[0] - OFFSET * 0.707;
|
|
8669
|
+
y = midPoint[1] - OFFSET * 0.707;
|
|
8670
|
+
} else {
|
|
8671
|
+
x = bindableElement.x - OFFSET;
|
|
8672
|
+
y = bindableElement.y - OFFSET;
|
|
8673
|
+
}
|
|
8674
|
+
break;
|
|
8675
|
+
}
|
|
8676
|
+
case "top-right": {
|
|
8677
|
+
if (corners.length >= 2) {
|
|
8678
|
+
const corner = corners[1];
|
|
8679
|
+
const p1 = corner[0];
|
|
8680
|
+
const p2 = corner[3];
|
|
8681
|
+
const midPoint = getMidPoint(p1, p2);
|
|
8682
|
+
x = midPoint[0] + OFFSET * 0.707;
|
|
8683
|
+
y = midPoint[1] - OFFSET * 0.707;
|
|
8684
|
+
} else {
|
|
8685
|
+
x = bindableElement.x + bindableElement.width + OFFSET;
|
|
8686
|
+
y = bindableElement.y - OFFSET;
|
|
8687
|
+
}
|
|
8688
|
+
break;
|
|
8689
|
+
}
|
|
8690
|
+
case "bottom-right": {
|
|
8691
|
+
if (corners.length >= 3) {
|
|
8692
|
+
const corner = corners[2];
|
|
8693
|
+
const p1 = corner[0];
|
|
8694
|
+
const p2 = corner[3];
|
|
8695
|
+
const midPoint = getMidPoint(p1, p2);
|
|
8696
|
+
x = midPoint[0] + OFFSET * 0.707;
|
|
8697
|
+
y = midPoint[1] + OFFSET * 0.707;
|
|
8698
|
+
} else {
|
|
8699
|
+
x = bindableElement.x + bindableElement.width + OFFSET;
|
|
8700
|
+
y = bindableElement.y + bindableElement.height + OFFSET;
|
|
8701
|
+
}
|
|
8702
|
+
break;
|
|
8703
|
+
}
|
|
8704
|
+
case "bottom-left": {
|
|
8705
|
+
if (corners.length >= 4) {
|
|
8706
|
+
const corner = corners[3];
|
|
8707
|
+
const p1 = corner[0];
|
|
8708
|
+
const p2 = corner[3];
|
|
8709
|
+
const midPoint = getMidPoint(p1, p2);
|
|
8710
|
+
x = midPoint[0] - OFFSET * 0.707;
|
|
8711
|
+
y = midPoint[1] + OFFSET * 0.707;
|
|
8712
|
+
} else {
|
|
8713
|
+
x = bindableElement.x - OFFSET;
|
|
8714
|
+
y = bindableElement.y + bindableElement.height + OFFSET;
|
|
8715
|
+
}
|
|
8716
|
+
break;
|
|
8717
|
+
}
|
|
8718
|
+
default: {
|
|
8719
|
+
return null;
|
|
8720
|
+
}
|
|
8721
|
+
}
|
|
8722
|
+
return pointRotateRads8(pointFrom8(x, y), center, bindableElement.angle);
|
|
8723
|
+
}
|
|
8724
|
+
return null;
|
|
8725
|
+
};
|
|
8726
|
+
var getMidPoint = (p1, p2) => {
|
|
8727
|
+
return pointFrom8((p1[0] + p2[0]) / 2, (p1[1] + p2[1]) / 2);
|
|
8728
|
+
};
|
|
8337
8729
|
|
|
8338
8730
|
// src/linearElementEditor.ts
|
|
8339
8731
|
var getNormalizedPoints = ({
|
|
@@ -8460,14 +8852,9 @@ var LinearElementEditor = class _LinearElementEditor {
|
|
|
8460
8852
|
const point = element.points[idx];
|
|
8461
8853
|
const pivotPoint = element.points[idx - 1];
|
|
8462
8854
|
const customLineAngle = linearElementEditor.customLineAngle ?? determineCustomLinearAngle(pivotPoint, element.points[idx]);
|
|
8463
|
-
const hoveredElement = getHoveredElementForBinding2(
|
|
8464
|
-
pointFrom9(scenePointerX, scenePointerY),
|
|
8465
|
-
elements,
|
|
8466
|
-
elementsMap
|
|
8467
|
-
);
|
|
8468
8855
|
let deltaX = 0;
|
|
8469
8856
|
let deltaY = 0;
|
|
8470
|
-
if (shouldRotateWithDiscreteAngle(event)
|
|
8857
|
+
if (shouldRotateWithDiscreteAngle(event)) {
|
|
8471
8858
|
const [width, height] = _LinearElementEditor._getShiftLockedDelta(
|
|
8472
8859
|
element,
|
|
8473
8860
|
elementsMap,
|
|
@@ -8498,11 +8885,13 @@ var LinearElementEditor = class _LinearElementEditor {
|
|
|
8498
8885
|
[idx],
|
|
8499
8886
|
deltaX,
|
|
8500
8887
|
deltaY,
|
|
8888
|
+
scenePointerX,
|
|
8889
|
+
scenePointerY,
|
|
8501
8890
|
elementsMap,
|
|
8502
8891
|
element,
|
|
8503
8892
|
elements,
|
|
8504
8893
|
app,
|
|
8505
|
-
event
|
|
8894
|
+
shouldRotateWithDiscreteAngle(event),
|
|
8506
8895
|
event.altKey
|
|
8507
8896
|
);
|
|
8508
8897
|
_LinearElementEditor.movePoints(element, app.scene, positions, {
|
|
@@ -8592,14 +8981,9 @@ var LinearElementEditor = class _LinearElementEditor {
|
|
|
8592
8981
|
const endIsSelected = selectedPointsIndices.includes(
|
|
8593
8982
|
element.points.length - 1
|
|
8594
8983
|
);
|
|
8595
|
-
const hoveredElement = getHoveredElementForBinding2(
|
|
8596
|
-
pointFrom9(scenePointerX, scenePointerY),
|
|
8597
|
-
elements,
|
|
8598
|
-
elementsMap
|
|
8599
|
-
);
|
|
8600
8984
|
let deltaX = 0;
|
|
8601
8985
|
let deltaY = 0;
|
|
8602
|
-
if (shouldRotateWithDiscreteAngle(event) && singlePointDragged
|
|
8986
|
+
if (shouldRotateWithDiscreteAngle(event) && singlePointDragged) {
|
|
8603
8987
|
const [width, height] = _LinearElementEditor._getShiftLockedDelta(
|
|
8604
8988
|
element,
|
|
8605
8989
|
elementsMap,
|
|
@@ -8630,11 +9014,13 @@ var LinearElementEditor = class _LinearElementEditor {
|
|
|
8630
9014
|
selectedPointsIndices,
|
|
8631
9015
|
deltaX,
|
|
8632
9016
|
deltaY,
|
|
9017
|
+
scenePointerX,
|
|
9018
|
+
scenePointerY,
|
|
8633
9019
|
elementsMap,
|
|
8634
9020
|
element,
|
|
8635
9021
|
elements,
|
|
8636
9022
|
app,
|
|
8637
|
-
event
|
|
9023
|
+
shouldRotateWithDiscreteAngle(event) && singlePointDragged,
|
|
8638
9024
|
event.altKey
|
|
8639
9025
|
);
|
|
8640
9026
|
_LinearElementEditor.movePoints(element, app.scene, positions, {
|
|
@@ -9708,7 +10094,7 @@ var normalizeSelectedPoints = (points) => {
|
|
|
9708
10094
|
nextPoints = nextPoints.sort((a2, b2) => a2 - b2);
|
|
9709
10095
|
return nextPoints.length ? nextPoints : null;
|
|
9710
10096
|
};
|
|
9711
|
-
var pointDraggingUpdates = (selectedPointsIndices, deltaX, deltaY, elementsMap, element, elements, app,
|
|
10097
|
+
var pointDraggingUpdates = (selectedPointsIndices, deltaX, deltaY, scenePointerX, scenePointerY, elementsMap, element, elements, app, angleLocked, altKey) => {
|
|
9712
10098
|
const naiveDraggingPoints = new Map(
|
|
9713
10099
|
selectedPointsIndices.map((pointIndex) => {
|
|
9714
10100
|
return [
|
|
@@ -9735,12 +10121,14 @@ var pointDraggingUpdates = (selectedPointsIndices, deltaX, deltaY, elementsMap,
|
|
|
9735
10121
|
const { start, end } = getBindingStrategyForDraggingBindingElementEndpoints(
|
|
9736
10122
|
element,
|
|
9737
10123
|
naiveDraggingPoints,
|
|
10124
|
+
scenePointerX,
|
|
10125
|
+
scenePointerY,
|
|
9738
10126
|
elementsMap,
|
|
9739
10127
|
elements,
|
|
9740
10128
|
app.state,
|
|
9741
10129
|
{
|
|
9742
10130
|
newArrow: !!app.state.newElement,
|
|
9743
|
-
|
|
10131
|
+
angleLocked,
|
|
9744
10132
|
altKey
|
|
9745
10133
|
}
|
|
9746
10134
|
);
|
|
@@ -9818,7 +10206,8 @@ var pointDraggingUpdates = (selectedPointsIndices, deltaX, deltaY, elementsMap,
|
|
|
9818
10206
|
startBinding: updates.startBinding === void 0 ? element.startBinding : updates.startBinding === null ? null : updates.startBinding,
|
|
9819
10207
|
endBinding: updates.endBinding === void 0 ? element.endBinding : updates.endBinding === null ? null : updates.endBinding
|
|
9820
10208
|
};
|
|
9821
|
-
const
|
|
10209
|
+
const startCustomIntersector = start.focusPoint && end.focusPoint ? lineSegment5(start.focusPoint, end.focusPoint) : void 0;
|
|
10210
|
+
const endCustomIntersector = start.focusPoint && end.focusPoint ? lineSegment5(end.focusPoint, start.focusPoint) : void 0;
|
|
9822
10211
|
const startIsDraggingOverEndElement = element.endBinding && nextArrow.startBinding && startIsDragged && nextArrow.startBinding.elementId === element.endBinding.elementId;
|
|
9823
10212
|
const endIsDraggingOverStartElement = element.startBinding && nextArrow.endBinding && endIsDragged && element.startBinding.elementId === nextArrow.endBinding.elementId;
|
|
9824
10213
|
const endBindable = nextArrow.endBinding ? end.element ?? elementsMap.get(
|
|
@@ -9830,7 +10219,7 @@ var pointDraggingUpdates = (selectedPointsIndices, deltaX, deltaY, elementsMap,
|
|
|
9830
10219
|
nextArrow.endBinding,
|
|
9831
10220
|
endBindable,
|
|
9832
10221
|
elementsMap,
|
|
9833
|
-
|
|
10222
|
+
endCustomIntersector
|
|
9834
10223
|
) || nextArrow.points[nextArrow.points.length - 1] : nextArrow.points[nextArrow.points.length - 1];
|
|
9835
10224
|
nextArrow.points[nextArrow.points.length - 1] = endLocalPoint;
|
|
9836
10225
|
const startBindable = nextArrow.startBinding ? start.element ?? elementsMap.get(
|
|
@@ -9842,7 +10231,7 @@ var pointDraggingUpdates = (selectedPointsIndices, deltaX, deltaY, elementsMap,
|
|
|
9842
10231
|
nextArrow.startBinding,
|
|
9843
10232
|
startBindable,
|
|
9844
10233
|
elementsMap,
|
|
9845
|
-
|
|
10234
|
+
startCustomIntersector
|
|
9846
10235
|
) || nextArrow.points[0] : nextArrow.points[0];
|
|
9847
10236
|
const endChanged = pointDistance5(
|
|
9848
10237
|
endLocalPoint,
|
|
@@ -11014,11 +11403,7 @@ var frameAndChildrenSelectedTogether = (selectedElements) => {
|
|
|
11014
11403
|
};
|
|
11015
11404
|
|
|
11016
11405
|
// src/renderElement.ts
|
|
11017
|
-
var IMAGE_INVERT_FILTER = "invert(100%) hue-rotate(180deg) saturate(1.25)";
|
|
11018
11406
|
var isPendingImageElement = (element, renderConfig) => isInitializedImageElement(element) && !renderConfig.imageCache.has(element.fileId);
|
|
11019
|
-
var shouldResetImageFilter = (element, renderConfig, appState) => {
|
|
11020
|
-
return appState.theme === THEME.DARK && isInitializedImageElement(element) && !isPendingImageElement(element, renderConfig) && renderConfig.imageCache.get(element.fileId)?.mimeType !== MIME_TYPES.svg;
|
|
11021
|
-
};
|
|
11022
11407
|
var getCanvasPadding = (element) => {
|
|
11023
11408
|
switch (element.type) {
|
|
11024
11409
|
case "freedraw":
|
|
@@ -11090,9 +11475,6 @@ var generateElementCanvas = (element, elementsMap, zoom, renderConfig, appState)
|
|
|
11090
11475
|
window.devicePixelRatio * scale
|
|
11091
11476
|
);
|
|
11092
11477
|
const rc = rough_default.canvas(canvas);
|
|
11093
|
-
if (shouldResetImageFilter(element, renderConfig, appState)) {
|
|
11094
|
-
context.filter = IMAGE_INVERT_FILTER;
|
|
11095
|
-
}
|
|
11096
11478
|
drawElementOnCanvas(element, rc, context, renderConfig);
|
|
11097
11479
|
context.restore();
|
|
11098
11480
|
const boundTextElement = getBoundTextElement(element, elementsMap);
|
|
@@ -11181,28 +11563,31 @@ var drawElementOnCanvas = (element, rc, context, renderConfig) => {
|
|
|
11181
11563
|
case "ellipse": {
|
|
11182
11564
|
context.lineJoin = "round";
|
|
11183
11565
|
context.lineCap = "round";
|
|
11184
|
-
rc.draw(ShapeCache.
|
|
11566
|
+
rc.draw(ShapeCache.generateElementShape(element, renderConfig));
|
|
11185
11567
|
break;
|
|
11186
11568
|
}
|
|
11187
11569
|
case "arrow":
|
|
11188
11570
|
case "line": {
|
|
11189
11571
|
context.lineJoin = "round";
|
|
11190
11572
|
context.lineCap = "round";
|
|
11191
|
-
ShapeCache.
|
|
11192
|
-
|
|
11193
|
-
|
|
11573
|
+
ShapeCache.generateElementShape(element, renderConfig).forEach(
|
|
11574
|
+
(shape) => {
|
|
11575
|
+
rc.draw(shape);
|
|
11576
|
+
}
|
|
11577
|
+
);
|
|
11194
11578
|
break;
|
|
11195
11579
|
}
|
|
11196
11580
|
case "freedraw": {
|
|
11197
11581
|
context.save();
|
|
11198
|
-
|
|
11199
|
-
const
|
|
11200
|
-
|
|
11201
|
-
|
|
11202
|
-
|
|
11203
|
-
|
|
11204
|
-
|
|
11205
|
-
|
|
11582
|
+
const shapes = ShapeCache.generateElementShape(element, renderConfig);
|
|
11583
|
+
for (const shape of shapes) {
|
|
11584
|
+
if (typeof shape === "string") {
|
|
11585
|
+
context.fillStyle = renderConfig.theme === THEME.DARK ? applyDarkModeFilter(element.strokeColor) : element.strokeColor;
|
|
11586
|
+
context.fill(new Path2D(shape));
|
|
11587
|
+
} else {
|
|
11588
|
+
rc.draw(shape);
|
|
11589
|
+
}
|
|
11590
|
+
}
|
|
11206
11591
|
context.restore();
|
|
11207
11592
|
break;
|
|
11208
11593
|
}
|
|
@@ -11252,7 +11637,7 @@ var drawElementOnCanvas = (element, rc, context, renderConfig) => {
|
|
|
11252
11637
|
context.canvas.setAttribute("dir", rtl ? "rtl" : "ltr");
|
|
11253
11638
|
context.save();
|
|
11254
11639
|
context.font = getFontString3(element);
|
|
11255
|
-
context.fillStyle = element.strokeColor;
|
|
11640
|
+
context.fillStyle = renderConfig.theme === THEME.DARK ? applyDarkModeFilter(element.strokeColor) : element.strokeColor;
|
|
11256
11641
|
context.textAlign = element.textAlign;
|
|
11257
11642
|
const lines = element.text.replace(/\r\n?/g, "\n").split("\n");
|
|
11258
11643
|
const horizontalOffset = element.textAlign === "center" ? element.width / 2 : element.textAlign === "right" ? element.width : 0;
|
|
@@ -11400,9 +11785,9 @@ var renderElement = (element, elementsMap, allElementsMap, rc, context, renderCo
|
|
|
11400
11785
|
);
|
|
11401
11786
|
context.fillStyle = "rgba(0, 0, 200, 0.04)";
|
|
11402
11787
|
context.lineWidth = FRAME_STYLE.strokeWidth / appState.zoom.value;
|
|
11403
|
-
context.strokeStyle = FRAME_STYLE.strokeColor;
|
|
11788
|
+
context.strokeStyle = appState.theme === THEME.DARK ? applyDarkModeFilter(FRAME_STYLE.strokeColor) : FRAME_STYLE.strokeColor;
|
|
11404
11789
|
if (isMagicFrameElement(element)) {
|
|
11405
|
-
context.strokeStyle = appState.theme === THEME.LIGHT ? "#7affd7" : "#1d8264";
|
|
11790
|
+
context.strokeStyle = appState.theme === THEME.LIGHT ? "#7affd7" : applyDarkModeFilter("#1d8264");
|
|
11406
11791
|
}
|
|
11407
11792
|
if (FRAME_STYLE.radius && context.roundRect) {
|
|
11408
11793
|
context.beginPath();
|
|
@@ -11423,7 +11808,6 @@ var renderElement = (element, elementsMap, allElementsMap, rc, context, renderCo
|
|
|
11423
11808
|
break;
|
|
11424
11809
|
}
|
|
11425
11810
|
case "freedraw": {
|
|
11426
|
-
ShapeCache.generateElementShape(element, null);
|
|
11427
11811
|
if (renderConfig.isExporting) {
|
|
11428
11812
|
const [x1, y1, x2, y2] = getElementAbsoluteCoords2(element, elementsMap);
|
|
11429
11813
|
const cx = (x1 + x2) / 2 + appState.scrollX;
|
|
@@ -11465,7 +11849,6 @@ var renderElement = (element, elementsMap, allElementsMap, rc, context, renderCo
|
|
|
11465
11849
|
case "text":
|
|
11466
11850
|
case "iframe":
|
|
11467
11851
|
case "embeddable": {
|
|
11468
|
-
ShapeCache.generateElementShape(element, renderConfig);
|
|
11469
11852
|
if (renderConfig.isExporting) {
|
|
11470
11853
|
const [x1, y1, x2, y2] = getElementAbsoluteCoords2(element, elementsMap);
|
|
11471
11854
|
const cx = (x1 + x2) / 2 + appState.scrollX;
|
|
@@ -11486,9 +11869,6 @@ var renderElement = (element, elementsMap, allElementsMap, rc, context, renderCo
|
|
|
11486
11869
|
}
|
|
11487
11870
|
context.save();
|
|
11488
11871
|
context.translate(cx, cy);
|
|
11489
|
-
if (shouldResetImageFilter(element, renderConfig, appState)) {
|
|
11490
|
-
context.filter = "none";
|
|
11491
|
-
}
|
|
11492
11872
|
const boundTextElement = getBoundTextElement(element, elementsMap);
|
|
11493
11873
|
if (isArrowElement(element) && boundTextElement) {
|
|
11494
11874
|
const tempCanvas = document.createElement("canvas");
|
|
@@ -11600,19 +11980,6 @@ var renderElement = (element, elementsMap, allElementsMap, rc, context, renderCo
|
|
|
11600
11980
|
}
|
|
11601
11981
|
context.globalAlpha = 1;
|
|
11602
11982
|
};
|
|
11603
|
-
var pathsCache = /* @__PURE__ */ new WeakMap([]);
|
|
11604
|
-
function generateFreeDrawShape(element) {
|
|
11605
|
-
const svgPathData = getFreeDrawSvgPath(element);
|
|
11606
|
-
const path = new Path2D(svgPathData);
|
|
11607
|
-
pathsCache.set(element, path);
|
|
11608
|
-
return path;
|
|
11609
|
-
}
|
|
11610
|
-
function getFreeDrawPath2D(element) {
|
|
11611
|
-
return pathsCache.get(element);
|
|
11612
|
-
}
|
|
11613
|
-
function getFreeDrawSvgPath(element) {
|
|
11614
|
-
return getSvgPathFromStroke(getFreedrawOutlinePoints(element));
|
|
11615
|
-
}
|
|
11616
11983
|
function getFreedrawOutlineAsSegments(element, points, elementsMap) {
|
|
11617
11984
|
const bounds = getElementBounds(
|
|
11618
11985
|
{
|
|
@@ -11662,46 +12029,11 @@ function getFreedrawOutlineAsSegments(element, points, elementsMap) {
|
|
|
11662
12029
|
]
|
|
11663
12030
|
);
|
|
11664
12031
|
}
|
|
11665
|
-
function getFreedrawOutlinePoints(element) {
|
|
11666
|
-
const inputPoints = element.simulatePressure ? element.points : element.points.length ? element.points.map(([x, y], i) => [x, y, element.pressures[i]]) : [[0, 0, 0.5]];
|
|
11667
|
-
const options = {
|
|
11668
|
-
simulatePressure: element.simulatePressure,
|
|
11669
|
-
size: element.strokeWidth * 4.25,
|
|
11670
|
-
thinning: 0.6,
|
|
11671
|
-
smoothing: 0.5,
|
|
11672
|
-
streamline: 0.5,
|
|
11673
|
-
easing: (t) => Math.sin(t * Math.PI / 2),
|
|
11674
|
-
// https://easings.net/#easeOutSine
|
|
11675
|
-
last: true
|
|
11676
|
-
};
|
|
11677
|
-
return ae(inputPoints, options);
|
|
11678
|
-
}
|
|
11679
|
-
function med(A2, B2) {
|
|
11680
|
-
return [(A2[0] + B2[0]) / 2, (A2[1] + B2[1]) / 2];
|
|
11681
|
-
}
|
|
11682
|
-
var TO_FIXED_PRECISION = /(\s?[A-Z]?,?-?[0-9]*\.[0-9]{0,2})(([0-9]|e|-)*)/g;
|
|
11683
|
-
function getSvgPathFromStroke(points) {
|
|
11684
|
-
if (!points.length) {
|
|
11685
|
-
return "";
|
|
11686
|
-
}
|
|
11687
|
-
const max = points.length - 1;
|
|
11688
|
-
return points.reduce(
|
|
11689
|
-
(acc, point, i, arr) => {
|
|
11690
|
-
if (i === max) {
|
|
11691
|
-
acc.push(point, med(point, arr[0]), "L", arr[0], "Z");
|
|
11692
|
-
} else {
|
|
11693
|
-
acc.push(point, med(point, arr[i + 1]));
|
|
11694
|
-
}
|
|
11695
|
-
return acc;
|
|
11696
|
-
},
|
|
11697
|
-
["M", points[0], "Q"]
|
|
11698
|
-
).join(" ").replace(TO_FIXED_PRECISION, "$1");
|
|
11699
|
-
}
|
|
11700
12032
|
|
|
11701
12033
|
// src/comparisons.ts
|
|
11702
12034
|
init_define_import_meta_env();
|
|
11703
12035
|
var hasBackground = (type) => type === "rectangle" || type === "iframe" || type === "embeddable" || type === "ellipse" || type === "diamond" || type === "line" || type === "freedraw";
|
|
11704
|
-
var hasStrokeColor = (type) => type === "rectangle" || type === "ellipse" || type === "diamond" || type === "freedraw" || type === "arrow" || type === "line" || type === "text";
|
|
12036
|
+
var hasStrokeColor = (type) => type === "rectangle" || type === "ellipse" || type === "diamond" || type === "freedraw" || type === "arrow" || type === "line" || type === "text" || type === "embeddable";
|
|
11705
12037
|
var hasStrokeWidth = (type) => type === "rectangle" || type === "iframe" || type === "embeddable" || type === "ellipse" || type === "diamond" || type === "freedraw" || type === "arrow" || type === "line";
|
|
11706
12038
|
var hasStrokeStyle = (type) => type === "rectangle" || type === "iframe" || type === "embeddable" || type === "ellipse" || type === "diamond" || type === "arrow" || type === "line";
|
|
11707
12039
|
var canChangeRoundness = (type) => type === "rectangle" || type === "iframe" || type === "embeddable" || type === "line" || type === "diamond" || type === "image";
|
|
@@ -11716,13 +12048,17 @@ var ShapeCache = class _ShapeCache {
|
|
|
11716
12048
|
* Retrieves shape from cache if available. Use this only if shape
|
|
11717
12049
|
* is optional and you have a fallback in case it's not cached.
|
|
11718
12050
|
*/
|
|
11719
|
-
static get = (element) => {
|
|
11720
|
-
|
|
11721
|
-
|
|
11722
|
-
|
|
12051
|
+
static get = (element, theme) => {
|
|
12052
|
+
const cached = _ShapeCache.cache.get(element);
|
|
12053
|
+
if (cached && (theme === null || cached.theme === theme)) {
|
|
12054
|
+
return cached.shape;
|
|
12055
|
+
}
|
|
12056
|
+
return void 0;
|
|
12057
|
+
};
|
|
12058
|
+
static delete = (element) => {
|
|
12059
|
+
_ShapeCache.cache.delete(element);
|
|
12060
|
+
elementWithCanvasCache.delete(element);
|
|
11723
12061
|
};
|
|
11724
|
-
static set = (element, shape) => _ShapeCache.cache.set(element, shape);
|
|
11725
|
-
static delete = (element) => _ShapeCache.cache.delete(element);
|
|
11726
12062
|
static destroy = () => {
|
|
11727
12063
|
_ShapeCache.cache = /* @__PURE__ */ new WeakMap();
|
|
11728
12064
|
};
|
|
@@ -11731,21 +12067,27 @@ var ShapeCache = class _ShapeCache {
|
|
|
11731
12067
|
* returns cached shape.
|
|
11732
12068
|
*/
|
|
11733
12069
|
static generateElementShape = (element, renderConfig) => {
|
|
11734
|
-
const cachedShape = renderConfig?.isExporting ? void 0 : _ShapeCache.get(element);
|
|
12070
|
+
const cachedShape = renderConfig?.isExporting ? void 0 : _ShapeCache.get(element, renderConfig ? renderConfig.theme : null);
|
|
11735
12071
|
if (cachedShape !== void 0) {
|
|
11736
12072
|
return cachedShape;
|
|
11737
12073
|
}
|
|
11738
12074
|
elementWithCanvasCache.delete(element);
|
|
11739
|
-
const shape =
|
|
12075
|
+
const shape = _generateElementShape(
|
|
11740
12076
|
element,
|
|
11741
12077
|
_ShapeCache.rg,
|
|
11742
12078
|
renderConfig || {
|
|
11743
12079
|
isExporting: false,
|
|
11744
12080
|
canvasBackgroundColor: COLOR_PALETTE.white,
|
|
11745
|
-
embedsValidationStatus: null
|
|
12081
|
+
embedsValidationStatus: null,
|
|
12082
|
+
theme: THEME2.LIGHT
|
|
11746
12083
|
}
|
|
11747
12084
|
);
|
|
11748
|
-
|
|
12085
|
+
if (!renderConfig?.isExporting) {
|
|
12086
|
+
_ShapeCache.cache.set(element, {
|
|
12087
|
+
shape,
|
|
12088
|
+
theme: renderConfig?.theme || THEME2.LIGHT
|
|
12089
|
+
});
|
|
12090
|
+
}
|
|
11749
12091
|
return shape;
|
|
11750
12092
|
};
|
|
11751
12093
|
};
|
|
@@ -11765,7 +12107,7 @@ function adjustRoughness(element) {
|
|
|
11765
12107
|
}
|
|
11766
12108
|
return Math.min(roughness / (maxSize < 10 ? 3 : 2), 2.5);
|
|
11767
12109
|
}
|
|
11768
|
-
var generateRoughOptions = (element, continuousPath = false) => {
|
|
12110
|
+
var generateRoughOptions = (element, continuousPath = false, isDarkMode = false) => {
|
|
11769
12111
|
const options = {
|
|
11770
12112
|
seed: element.seed,
|
|
11771
12113
|
strokeLineDash: element.strokeStyle === "dashed" ? getDashArrayDashed(element.strokeWidth) : element.strokeStyle === "dotted" ? getDashArrayDotted(element.strokeWidth) : void 0,
|
|
@@ -11781,7 +12123,7 @@ var generateRoughOptions = (element, continuousPath = false) => {
|
|
|
11781
12123
|
fillWeight: element.strokeWidth / 2,
|
|
11782
12124
|
hachureGap: element.strokeWidth * 4,
|
|
11783
12125
|
roughness: adjustRoughness(element),
|
|
11784
|
-
stroke: element.strokeColor,
|
|
12126
|
+
stroke: isDarkMode ? applyDarkModeFilter2(element.strokeColor) : element.strokeColor,
|
|
11785
12127
|
preserveVertices: continuousPath || element.roughness < ROUGHNESS.cartoonist
|
|
11786
12128
|
};
|
|
11787
12129
|
switch (element.type) {
|
|
@@ -11791,7 +12133,7 @@ var generateRoughOptions = (element, continuousPath = false) => {
|
|
|
11791
12133
|
case "diamond":
|
|
11792
12134
|
case "ellipse": {
|
|
11793
12135
|
options.fillStyle = element.fillStyle;
|
|
11794
|
-
options.fill = isTransparent3(element.backgroundColor) ? void 0 : element.backgroundColor;
|
|
12136
|
+
options.fill = isTransparent3(element.backgroundColor) ? void 0 : isDarkMode ? applyDarkModeFilter2(element.backgroundColor) : element.backgroundColor;
|
|
11795
12137
|
if (element.type === "ellipse") {
|
|
11796
12138
|
options.curveFitting = 1;
|
|
11797
12139
|
}
|
|
@@ -11801,7 +12143,7 @@ var generateRoughOptions = (element, continuousPath = false) => {
|
|
|
11801
12143
|
case "freedraw": {
|
|
11802
12144
|
if (isPathALoop(element.points)) {
|
|
11803
12145
|
options.fillStyle = element.fillStyle;
|
|
11804
|
-
options.fill = element.backgroundColor === "transparent" ? void 0 : element.backgroundColor;
|
|
12146
|
+
options.fill = element.backgroundColor === "transparent" ? void 0 : isDarkMode ? applyDarkModeFilter2(element.backgroundColor) : element.backgroundColor;
|
|
11805
12147
|
}
|
|
11806
12148
|
return options;
|
|
11807
12149
|
}
|
|
@@ -11829,7 +12171,7 @@ var modifyIframeLikeForRoughOptions = (element, isExporting, embedsValidationSta
|
|
|
11829
12171
|
}
|
|
11830
12172
|
return element;
|
|
11831
12173
|
};
|
|
11832
|
-
var getArrowheadShapes = (element, shape, position, arrowhead, generator, options, canvasBackgroundColor) => {
|
|
12174
|
+
var getArrowheadShapes = (element, shape, position, arrowhead, generator, options, canvasBackgroundColor, isDarkMode) => {
|
|
11833
12175
|
const arrowheadPoints = getArrowheadPoints(
|
|
11834
12176
|
element,
|
|
11835
12177
|
shape,
|
|
@@ -11846,6 +12188,7 @@ var getArrowheadShapes = (element, shape, position, arrowhead, generator, option
|
|
|
11846
12188
|
const [, , x3, y3, x4, y4] = arrowheadPoints2;
|
|
11847
12189
|
return [generator.line(x3, y3, x4, y4, options2)];
|
|
11848
12190
|
};
|
|
12191
|
+
const strokeColor = isDarkMode ? applyDarkModeFilter2(element.strokeColor) : element.strokeColor;
|
|
11849
12192
|
switch (arrowhead) {
|
|
11850
12193
|
case "dot":
|
|
11851
12194
|
case "circle":
|
|
@@ -11855,9 +12198,9 @@ var getArrowheadShapes = (element, shape, position, arrowhead, generator, option
|
|
|
11855
12198
|
return [
|
|
11856
12199
|
generator.circle(x, y, diameter, {
|
|
11857
12200
|
...options,
|
|
11858
|
-
fill: arrowhead === "circle_outline" ? canvasBackgroundColor :
|
|
12201
|
+
fill: arrowhead === "circle_outline" ? canvasBackgroundColor : strokeColor,
|
|
11859
12202
|
fillStyle: "solid",
|
|
11860
|
-
stroke:
|
|
12203
|
+
stroke: strokeColor,
|
|
11861
12204
|
roughness: Math.min(0.5, options.roughness || 0)
|
|
11862
12205
|
})
|
|
11863
12206
|
];
|
|
@@ -11876,7 +12219,7 @@ var getArrowheadShapes = (element, shape, position, arrowhead, generator, option
|
|
|
11876
12219
|
],
|
|
11877
12220
|
{
|
|
11878
12221
|
...options,
|
|
11879
|
-
fill: arrowhead === "triangle_outline" ? canvasBackgroundColor :
|
|
12222
|
+
fill: arrowhead === "triangle_outline" ? canvasBackgroundColor : strokeColor,
|
|
11880
12223
|
fillStyle: "solid",
|
|
11881
12224
|
roughness: Math.min(1, options.roughness || 0)
|
|
11882
12225
|
}
|
|
@@ -11898,7 +12241,7 @@ var getArrowheadShapes = (element, shape, position, arrowhead, generator, option
|
|
|
11898
12241
|
],
|
|
11899
12242
|
{
|
|
11900
12243
|
...options,
|
|
11901
|
-
fill: arrowhead === "diamond_outline" ? canvasBackgroundColor :
|
|
12244
|
+
fill: arrowhead === "diamond_outline" ? canvasBackgroundColor : strokeColor,
|
|
11902
12245
|
fillStyle: "solid",
|
|
11903
12246
|
roughness: Math.min(1, options.roughness || 0)
|
|
11904
12247
|
}
|
|
@@ -12079,11 +12422,13 @@ var generateLinearCollisionShape = (element) => {
|
|
|
12079
12422
|
}
|
|
12080
12423
|
}
|
|
12081
12424
|
};
|
|
12082
|
-
var
|
|
12425
|
+
var _generateElementShape = (element, generator, {
|
|
12083
12426
|
isExporting,
|
|
12084
12427
|
canvasBackgroundColor,
|
|
12085
|
-
embedsValidationStatus
|
|
12428
|
+
embedsValidationStatus,
|
|
12429
|
+
theme
|
|
12086
12430
|
}) => {
|
|
12431
|
+
const isDarkMode = theme === THEME2.DARK;
|
|
12087
12432
|
switch (element.type) {
|
|
12088
12433
|
case "rectangle":
|
|
12089
12434
|
case "iframe":
|
|
@@ -12101,7 +12446,8 @@ var generateElementShape = (element, generator, {
|
|
|
12101
12446
|
isExporting,
|
|
12102
12447
|
embedsValidationStatus
|
|
12103
12448
|
),
|
|
12104
|
-
true
|
|
12449
|
+
true,
|
|
12450
|
+
isDarkMode
|
|
12105
12451
|
)
|
|
12106
12452
|
);
|
|
12107
12453
|
} else {
|
|
@@ -12116,7 +12462,8 @@ var generateElementShape = (element, generator, {
|
|
|
12116
12462
|
isExporting,
|
|
12117
12463
|
embedsValidationStatus
|
|
12118
12464
|
),
|
|
12119
|
-
false
|
|
12465
|
+
false,
|
|
12466
|
+
isDarkMode
|
|
12120
12467
|
)
|
|
12121
12468
|
);
|
|
12122
12469
|
}
|
|
@@ -12140,7 +12487,7 @@ var generateElementShape = (element, generator, {
|
|
|
12140
12487
|
C ${leftX} ${leftY}, ${leftX} ${leftY}, ${leftX + verticalRadius} ${leftY - horizontalRadius}
|
|
12141
12488
|
L ${topX - verticalRadius} ${topY + horizontalRadius}
|
|
12142
12489
|
C ${topX} ${topY}, ${topX} ${topY}, ${topX + verticalRadius} ${topY + horizontalRadius}`,
|
|
12143
|
-
generateRoughOptions(element, true)
|
|
12490
|
+
generateRoughOptions(element, true, isDarkMode)
|
|
12144
12491
|
);
|
|
12145
12492
|
} else {
|
|
12146
12493
|
shape = generator.polygon(
|
|
@@ -12150,7 +12497,7 @@ var generateElementShape = (element, generator, {
|
|
|
12150
12497
|
[bottomX, bottomY],
|
|
12151
12498
|
[leftX, leftY]
|
|
12152
12499
|
],
|
|
12153
|
-
generateRoughOptions(element)
|
|
12500
|
+
generateRoughOptions(element, false, isDarkMode)
|
|
12154
12501
|
);
|
|
12155
12502
|
}
|
|
12156
12503
|
return shape;
|
|
@@ -12161,14 +12508,14 @@ var generateElementShape = (element, generator, {
|
|
|
12161
12508
|
element.height / 2,
|
|
12162
12509
|
element.width,
|
|
12163
12510
|
element.height,
|
|
12164
|
-
generateRoughOptions(element)
|
|
12511
|
+
generateRoughOptions(element, false, isDarkMode)
|
|
12165
12512
|
);
|
|
12166
12513
|
return shape;
|
|
12167
12514
|
}
|
|
12168
12515
|
case "line":
|
|
12169
12516
|
case "arrow": {
|
|
12170
12517
|
let shape;
|
|
12171
|
-
const options = generateRoughOptions(element);
|
|
12518
|
+
const options = generateRoughOptions(element, false, isDarkMode);
|
|
12172
12519
|
const points = element.points.length ? element.points : [pointFrom13(0, 0)];
|
|
12173
12520
|
if (isElbowArrow(element)) {
|
|
12174
12521
|
if (!points.every(
|
|
@@ -12184,7 +12531,7 @@ var generateElementShape = (element, generator, {
|
|
|
12184
12531
|
shape = [
|
|
12185
12532
|
generator.path(
|
|
12186
12533
|
generateElbowArrowShape(points, 16),
|
|
12187
|
-
generateRoughOptions(element, true)
|
|
12534
|
+
generateRoughOptions(element, true, isDarkMode)
|
|
12188
12535
|
)
|
|
12189
12536
|
];
|
|
12190
12537
|
}
|
|
@@ -12211,7 +12558,8 @@ var generateElementShape = (element, generator, {
|
|
|
12211
12558
|
startArrowhead,
|
|
12212
12559
|
generator,
|
|
12213
12560
|
options,
|
|
12214
|
-
canvasBackgroundColor
|
|
12561
|
+
canvasBackgroundColor,
|
|
12562
|
+
isDarkMode
|
|
12215
12563
|
);
|
|
12216
12564
|
shape.push(...shapes);
|
|
12217
12565
|
}
|
|
@@ -12225,7 +12573,8 @@ var generateElementShape = (element, generator, {
|
|
|
12225
12573
|
endArrowhead,
|
|
12226
12574
|
generator,
|
|
12227
12575
|
options,
|
|
12228
|
-
canvasBackgroundColor
|
|
12576
|
+
canvasBackgroundColor,
|
|
12577
|
+
isDarkMode
|
|
12229
12578
|
);
|
|
12230
12579
|
shape.push(...shapes);
|
|
12231
12580
|
}
|
|
@@ -12233,21 +12582,21 @@ var generateElementShape = (element, generator, {
|
|
|
12233
12582
|
return shape;
|
|
12234
12583
|
}
|
|
12235
12584
|
case "freedraw": {
|
|
12236
|
-
|
|
12237
|
-
generateFreeDrawShape(element);
|
|
12585
|
+
const shapes = [];
|
|
12238
12586
|
if (isPathALoop(element.points)) {
|
|
12239
12587
|
const simplifiedPoints = simplify(
|
|
12240
12588
|
element.points,
|
|
12241
12589
|
0.75
|
|
12242
12590
|
);
|
|
12243
|
-
|
|
12244
|
-
|
|
12245
|
-
|
|
12246
|
-
|
|
12247
|
-
|
|
12248
|
-
|
|
12591
|
+
shapes.push(
|
|
12592
|
+
generator.curve(simplifiedPoints, {
|
|
12593
|
+
...generateRoughOptions(element, false, isDarkMode),
|
|
12594
|
+
stroke: "none"
|
|
12595
|
+
})
|
|
12596
|
+
);
|
|
12249
12597
|
}
|
|
12250
|
-
|
|
12598
|
+
shapes.push(getFreeDrawSvgPath(element));
|
|
12599
|
+
return shapes;
|
|
12251
12600
|
}
|
|
12252
12601
|
case "frame":
|
|
12253
12602
|
case "magicframe":
|
|
@@ -12326,7 +12675,7 @@ var getElementShape = (element, elementsMap) => {
|
|
|
12326
12675
|
return getPolygonShape(element);
|
|
12327
12676
|
case "arrow":
|
|
12328
12677
|
case "line": {
|
|
12329
|
-
const roughShape = ShapeCache.
|
|
12678
|
+
const roughShape = ShapeCache.generateElementShape(element, null)[0];
|
|
12330
12679
|
const [, , , , cx, cy] = getElementAbsoluteCoords2(element, elementsMap);
|
|
12331
12680
|
return shouldTestInside(element) ? getClosedCurveShape(
|
|
12332
12681
|
element,
|
|
@@ -12380,6 +12729,45 @@ var toggleLinePolygonState = (element, nextPolygonState) => {
|
|
|
12380
12729
|
};
|
|
12381
12730
|
return ret;
|
|
12382
12731
|
};
|
|
12732
|
+
var getFreeDrawSvgPath = (element) => {
|
|
12733
|
+
return getSvgPathFromStroke(
|
|
12734
|
+
getFreedrawOutlinePoints(element)
|
|
12735
|
+
);
|
|
12736
|
+
};
|
|
12737
|
+
var getFreedrawOutlinePoints = (element) => {
|
|
12738
|
+
const inputPoints = element.simulatePressure ? element.points : element.points.length ? element.points.map(([x, y], i) => [x, y, element.pressures[i]]) : [[0, 0, 0.5]];
|
|
12739
|
+
return ae(inputPoints, {
|
|
12740
|
+
simulatePressure: element.simulatePressure,
|
|
12741
|
+
size: element.strokeWidth * 4.25,
|
|
12742
|
+
thinning: 0.6,
|
|
12743
|
+
smoothing: 0.5,
|
|
12744
|
+
streamline: 0.5,
|
|
12745
|
+
easing: (t) => Math.sin(t * Math.PI / 2),
|
|
12746
|
+
// https://easings.net/#easeOutSine
|
|
12747
|
+
last: true
|
|
12748
|
+
});
|
|
12749
|
+
};
|
|
12750
|
+
var med = (A2, B2) => {
|
|
12751
|
+
return [(A2[0] + B2[0]) / 2, (A2[1] + B2[1]) / 2];
|
|
12752
|
+
};
|
|
12753
|
+
var TO_FIXED_PRECISION = /(\s?[A-Z]?,?-?[0-9]*\.[0-9]{0,2})(([0-9]|e|-)*)/g;
|
|
12754
|
+
var getSvgPathFromStroke = (points) => {
|
|
12755
|
+
if (!points.length) {
|
|
12756
|
+
return "";
|
|
12757
|
+
}
|
|
12758
|
+
const max = points.length - 1;
|
|
12759
|
+
return points.reduce(
|
|
12760
|
+
(acc, point, i, arr) => {
|
|
12761
|
+
if (i === max) {
|
|
12762
|
+
acc.push(point, med(point, arr[0]), "L", arr[0], "Z");
|
|
12763
|
+
} else {
|
|
12764
|
+
acc.push(point, med(point, arr[i + 1]));
|
|
12765
|
+
}
|
|
12766
|
+
return acc;
|
|
12767
|
+
},
|
|
12768
|
+
["M", points[0], "Q"]
|
|
12769
|
+
).join(" ").replace(TO_FIXED_PRECISION, "$1");
|
|
12770
|
+
};
|
|
12383
12771
|
|
|
12384
12772
|
// src/bounds.ts
|
|
12385
12773
|
var ElementBounds = class _ElementBounds {
|
|
@@ -12978,7 +13366,7 @@ var getLinearElementRotatedBounds = (element, cx, cy, elementsMap) => {
|
|
|
12978
13366
|
}
|
|
12979
13367
|
return coords2;
|
|
12980
13368
|
}
|
|
12981
|
-
const cachedShape = ShapeCache.get(element)?.[0];
|
|
13369
|
+
const cachedShape = ShapeCache.get(element, null)?.[0];
|
|
12982
13370
|
const shape = cachedShape ?? generateLinearElementShape(element);
|
|
12983
13371
|
const ops = getCurvePathOps(shape);
|
|
12984
13372
|
const transformXY = ([x, y]) => pointRotateRads13(
|
|
@@ -19494,9 +19882,515 @@ var showSelectedShapeActions = (appState, elements) => Boolean(
|
|
|
19494
19882
|
!appState.viewModeEnabled && appState.openDialog?.name !== "elementLinkSelector" && (appState.activeTool.type !== "custom" && (appState.editingTextElement || appState.activeTool.type !== "selection" && appState.activeTool.type !== "lasso" && appState.activeTool.type !== "eraser" && appState.activeTool.type !== "hand" && appState.activeTool.type !== "laser") || getSelectedElements(elements, appState).length)
|
|
19495
19883
|
);
|
|
19496
19884
|
|
|
19885
|
+
// src/transform.ts
|
|
19886
|
+
init_define_import_meta_env();
|
|
19887
|
+
import { pointFrom as pointFrom19 } from "@excalidraw/math";
|
|
19888
|
+
import {
|
|
19889
|
+
DEFAULT_FONT_FAMILY as DEFAULT_FONT_FAMILY3,
|
|
19890
|
+
DEFAULT_FONT_SIZE as DEFAULT_FONT_SIZE4,
|
|
19891
|
+
TEXT_ALIGN as TEXT_ALIGN2,
|
|
19892
|
+
VERTICAL_ALIGN as VERTICAL_ALIGN4,
|
|
19893
|
+
getSizeFromPoints as getSizeFromPoints3,
|
|
19894
|
+
randomId as randomId4,
|
|
19895
|
+
arrayToMap as arrayToMap11,
|
|
19896
|
+
assertNever as assertNever5,
|
|
19897
|
+
cloneJSON,
|
|
19898
|
+
getFontString as getFontString8,
|
|
19899
|
+
isDevEnv as isDevEnv7,
|
|
19900
|
+
toBrandedType as toBrandedType3,
|
|
19901
|
+
getLineHeight as getLineHeight2
|
|
19902
|
+
} from "@excalidraw/common";
|
|
19903
|
+
var DEFAULT_LINEAR_ELEMENT_PROPS = {
|
|
19904
|
+
width: 100,
|
|
19905
|
+
height: 0
|
|
19906
|
+
};
|
|
19907
|
+
var DEFAULT_DIMENSION = 100;
|
|
19908
|
+
var bindTextToContainer = (container, textProps, scene) => {
|
|
19909
|
+
const textElement = newTextElement({
|
|
19910
|
+
x: 0,
|
|
19911
|
+
y: 0,
|
|
19912
|
+
textAlign: TEXT_ALIGN2.CENTER,
|
|
19913
|
+
verticalAlign: VERTICAL_ALIGN4.MIDDLE,
|
|
19914
|
+
...textProps,
|
|
19915
|
+
containerId: container.id,
|
|
19916
|
+
strokeColor: textProps.strokeColor || container.strokeColor
|
|
19917
|
+
});
|
|
19918
|
+
Object.assign(container, {
|
|
19919
|
+
boundElements: (container.boundElements || []).concat({
|
|
19920
|
+
type: "text",
|
|
19921
|
+
id: textElement.id
|
|
19922
|
+
})
|
|
19923
|
+
});
|
|
19924
|
+
redrawTextBoundingBox(textElement, container, scene);
|
|
19925
|
+
return [container, textElement];
|
|
19926
|
+
};
|
|
19927
|
+
var bindLinearElementToElement = (linearElement, start, end, elementStore, scene) => {
|
|
19928
|
+
let startBoundElement;
|
|
19929
|
+
let endBoundElement;
|
|
19930
|
+
Object.assign(linearElement, {
|
|
19931
|
+
startBinding: linearElement?.startBinding || null,
|
|
19932
|
+
endBinding: linearElement.endBinding || null
|
|
19933
|
+
});
|
|
19934
|
+
if (start) {
|
|
19935
|
+
const width = start?.width ?? DEFAULT_DIMENSION;
|
|
19936
|
+
const height = start?.height ?? DEFAULT_DIMENSION;
|
|
19937
|
+
let existingElement;
|
|
19938
|
+
if (start.id) {
|
|
19939
|
+
existingElement = elementStore.getElement(start.id);
|
|
19940
|
+
if (!existingElement) {
|
|
19941
|
+
console.error(`No element for start binding with id ${start.id} found`);
|
|
19942
|
+
}
|
|
19943
|
+
}
|
|
19944
|
+
const startX = start.x || linearElement.x - width;
|
|
19945
|
+
const startY = start.y || linearElement.y - height / 2;
|
|
19946
|
+
const startType = existingElement ? existingElement.type : start.type;
|
|
19947
|
+
if (startType) {
|
|
19948
|
+
if (startType === "text") {
|
|
19949
|
+
let text = "";
|
|
19950
|
+
if (existingElement && existingElement.type === "text") {
|
|
19951
|
+
text = existingElement.text;
|
|
19952
|
+
} else if (start.type === "text") {
|
|
19953
|
+
text = start.text;
|
|
19954
|
+
}
|
|
19955
|
+
if (!text) {
|
|
19956
|
+
console.error(
|
|
19957
|
+
`No text found for start binding text element for ${linearElement.id}`
|
|
19958
|
+
);
|
|
19959
|
+
}
|
|
19960
|
+
startBoundElement = newTextElement({
|
|
19961
|
+
x: startX,
|
|
19962
|
+
y: startY,
|
|
19963
|
+
type: "text",
|
|
19964
|
+
...existingElement,
|
|
19965
|
+
...start,
|
|
19966
|
+
text
|
|
19967
|
+
});
|
|
19968
|
+
Object.assign(startBoundElement, {
|
|
19969
|
+
x: start.x || linearElement.x - startBoundElement.width,
|
|
19970
|
+
y: start.y || linearElement.y - startBoundElement.height / 2
|
|
19971
|
+
});
|
|
19972
|
+
} else {
|
|
19973
|
+
switch (startType) {
|
|
19974
|
+
case "rectangle":
|
|
19975
|
+
case "ellipse":
|
|
19976
|
+
case "diamond": {
|
|
19977
|
+
startBoundElement = newElement({
|
|
19978
|
+
x: startX,
|
|
19979
|
+
y: startY,
|
|
19980
|
+
width,
|
|
19981
|
+
height,
|
|
19982
|
+
...existingElement,
|
|
19983
|
+
...start,
|
|
19984
|
+
type: startType
|
|
19985
|
+
});
|
|
19986
|
+
break;
|
|
19987
|
+
}
|
|
19988
|
+
default: {
|
|
19989
|
+
assertNever5(
|
|
19990
|
+
linearElement,
|
|
19991
|
+
`Unhandled element start type "${start.type}"`,
|
|
19992
|
+
true
|
|
19993
|
+
);
|
|
19994
|
+
}
|
|
19995
|
+
}
|
|
19996
|
+
}
|
|
19997
|
+
bindBindingElement(
|
|
19998
|
+
linearElement,
|
|
19999
|
+
startBoundElement,
|
|
20000
|
+
"orbit",
|
|
20001
|
+
"start",
|
|
20002
|
+
scene
|
|
20003
|
+
);
|
|
20004
|
+
}
|
|
20005
|
+
}
|
|
20006
|
+
if (end) {
|
|
20007
|
+
const height = end?.height ?? DEFAULT_DIMENSION;
|
|
20008
|
+
const width = end?.width ?? DEFAULT_DIMENSION;
|
|
20009
|
+
let existingElement;
|
|
20010
|
+
if (end.id) {
|
|
20011
|
+
existingElement = elementStore.getElement(end.id);
|
|
20012
|
+
if (!existingElement) {
|
|
20013
|
+
console.error(`No element for end binding with id ${end.id} found`);
|
|
20014
|
+
}
|
|
20015
|
+
}
|
|
20016
|
+
const endX = end.x || linearElement.x + linearElement.width;
|
|
20017
|
+
const endY = end.y || linearElement.y - height / 2;
|
|
20018
|
+
const endType = existingElement ? existingElement.type : end.type;
|
|
20019
|
+
if (endType) {
|
|
20020
|
+
if (endType === "text") {
|
|
20021
|
+
let text = "";
|
|
20022
|
+
if (existingElement && existingElement.type === "text") {
|
|
20023
|
+
text = existingElement.text;
|
|
20024
|
+
} else if (end.type === "text") {
|
|
20025
|
+
text = end.text;
|
|
20026
|
+
}
|
|
20027
|
+
if (!text) {
|
|
20028
|
+
console.error(
|
|
20029
|
+
`No text found for end binding text element for ${linearElement.id}`
|
|
20030
|
+
);
|
|
20031
|
+
}
|
|
20032
|
+
endBoundElement = newTextElement({
|
|
20033
|
+
x: endX,
|
|
20034
|
+
y: endY,
|
|
20035
|
+
type: "text",
|
|
20036
|
+
...existingElement,
|
|
20037
|
+
...end,
|
|
20038
|
+
text
|
|
20039
|
+
});
|
|
20040
|
+
Object.assign(endBoundElement, {
|
|
20041
|
+
y: end.y || linearElement.y - endBoundElement.height / 2
|
|
20042
|
+
});
|
|
20043
|
+
} else {
|
|
20044
|
+
switch (endType) {
|
|
20045
|
+
case "rectangle":
|
|
20046
|
+
case "ellipse":
|
|
20047
|
+
case "diamond": {
|
|
20048
|
+
endBoundElement = newElement({
|
|
20049
|
+
x: endX,
|
|
20050
|
+
y: endY,
|
|
20051
|
+
width,
|
|
20052
|
+
height,
|
|
20053
|
+
...existingElement,
|
|
20054
|
+
...end,
|
|
20055
|
+
type: endType
|
|
20056
|
+
});
|
|
20057
|
+
break;
|
|
20058
|
+
}
|
|
20059
|
+
default: {
|
|
20060
|
+
assertNever5(
|
|
20061
|
+
linearElement,
|
|
20062
|
+
`Unhandled element end type "${endType}"`,
|
|
20063
|
+
true
|
|
20064
|
+
);
|
|
20065
|
+
}
|
|
20066
|
+
}
|
|
20067
|
+
}
|
|
20068
|
+
bindBindingElement(
|
|
20069
|
+
linearElement,
|
|
20070
|
+
endBoundElement,
|
|
20071
|
+
"orbit",
|
|
20072
|
+
"end",
|
|
20073
|
+
scene
|
|
20074
|
+
);
|
|
20075
|
+
}
|
|
20076
|
+
}
|
|
20077
|
+
if (linearElement.points.length < 2) {
|
|
20078
|
+
return {
|
|
20079
|
+
linearElement,
|
|
20080
|
+
startBoundElement,
|
|
20081
|
+
endBoundElement
|
|
20082
|
+
};
|
|
20083
|
+
}
|
|
20084
|
+
const endPointIndex = linearElement.points.length - 1;
|
|
20085
|
+
const delta = 0.5;
|
|
20086
|
+
const newPoints = cloneJSON(linearElement.points);
|
|
20087
|
+
if (linearElement.points[endPointIndex][0] > linearElement.points[endPointIndex - 1][0]) {
|
|
20088
|
+
newPoints[0][0] = delta;
|
|
20089
|
+
newPoints[endPointIndex][0] -= delta;
|
|
20090
|
+
}
|
|
20091
|
+
if (linearElement.points[endPointIndex][0] < linearElement.points[endPointIndex - 1][0]) {
|
|
20092
|
+
newPoints[0][0] = -delta;
|
|
20093
|
+
newPoints[endPointIndex][0] += delta;
|
|
20094
|
+
}
|
|
20095
|
+
if (linearElement.points[endPointIndex][1] > linearElement.points[endPointIndex - 1][1]) {
|
|
20096
|
+
newPoints[0][1] = delta;
|
|
20097
|
+
newPoints[endPointIndex][1] -= delta;
|
|
20098
|
+
}
|
|
20099
|
+
if (linearElement.points[endPointIndex][1] < linearElement.points[endPointIndex - 1][1]) {
|
|
20100
|
+
newPoints[0][1] = -delta;
|
|
20101
|
+
newPoints[endPointIndex][1] += delta;
|
|
20102
|
+
}
|
|
20103
|
+
Object.assign(
|
|
20104
|
+
linearElement,
|
|
20105
|
+
LinearElementEditor.getNormalizeElementPointsAndCoords({
|
|
20106
|
+
...linearElement,
|
|
20107
|
+
points: newPoints
|
|
20108
|
+
})
|
|
20109
|
+
);
|
|
20110
|
+
return {
|
|
20111
|
+
linearElement,
|
|
20112
|
+
startBoundElement,
|
|
20113
|
+
endBoundElement
|
|
20114
|
+
};
|
|
20115
|
+
};
|
|
20116
|
+
var ElementStore = class {
|
|
20117
|
+
excalidrawElements = /* @__PURE__ */ new Map();
|
|
20118
|
+
add = (ele) => {
|
|
20119
|
+
if (!ele) {
|
|
20120
|
+
return;
|
|
20121
|
+
}
|
|
20122
|
+
this.excalidrawElements.set(ele.id, ele);
|
|
20123
|
+
};
|
|
20124
|
+
getElements = () => {
|
|
20125
|
+
return syncInvalidIndices(Array.from(this.excalidrawElements.values()));
|
|
20126
|
+
};
|
|
20127
|
+
getElementsMap = () => {
|
|
20128
|
+
return toBrandedType3(
|
|
20129
|
+
arrayToMap11(this.getElements())
|
|
20130
|
+
);
|
|
20131
|
+
};
|
|
20132
|
+
getElement = (id) => {
|
|
20133
|
+
return this.excalidrawElements.get(id);
|
|
20134
|
+
};
|
|
20135
|
+
};
|
|
20136
|
+
var convertToExcalidrawElements = (elementsSkeleton, opts) => {
|
|
20137
|
+
if (!elementsSkeleton) {
|
|
20138
|
+
return [];
|
|
20139
|
+
}
|
|
20140
|
+
const elements = cloneJSON(elementsSkeleton);
|
|
20141
|
+
const elementStore = new ElementStore();
|
|
20142
|
+
const elementsWithIds = /* @__PURE__ */ new Map();
|
|
20143
|
+
const oldToNewElementIdMap = /* @__PURE__ */ new Map();
|
|
20144
|
+
for (const element of elements) {
|
|
20145
|
+
let excalidrawElement;
|
|
20146
|
+
const originalId = element.id;
|
|
20147
|
+
if (opts?.regenerateIds !== false) {
|
|
20148
|
+
Object.assign(element, { id: randomId4() });
|
|
20149
|
+
}
|
|
20150
|
+
switch (element.type) {
|
|
20151
|
+
case "rectangle":
|
|
20152
|
+
case "ellipse":
|
|
20153
|
+
case "diamond": {
|
|
20154
|
+
const width = element?.label?.text && element.width === void 0 ? 0 : element?.width || DEFAULT_DIMENSION;
|
|
20155
|
+
const height = element?.label?.text && element.height === void 0 ? 0 : element?.height || DEFAULT_DIMENSION;
|
|
20156
|
+
excalidrawElement = newElement({
|
|
20157
|
+
...element,
|
|
20158
|
+
width,
|
|
20159
|
+
height
|
|
20160
|
+
});
|
|
20161
|
+
break;
|
|
20162
|
+
}
|
|
20163
|
+
case "line": {
|
|
20164
|
+
const width = element.width || DEFAULT_LINEAR_ELEMENT_PROPS.width;
|
|
20165
|
+
const height = element.height || DEFAULT_LINEAR_ELEMENT_PROPS.height;
|
|
20166
|
+
excalidrawElement = newLinearElement({
|
|
20167
|
+
width,
|
|
20168
|
+
height,
|
|
20169
|
+
points: [pointFrom19(0, 0), pointFrom19(width, height)],
|
|
20170
|
+
...element
|
|
20171
|
+
});
|
|
20172
|
+
break;
|
|
20173
|
+
}
|
|
20174
|
+
case "arrow": {
|
|
20175
|
+
const width = element.width || DEFAULT_LINEAR_ELEMENT_PROPS.width;
|
|
20176
|
+
const height = element.height || DEFAULT_LINEAR_ELEMENT_PROPS.height;
|
|
20177
|
+
excalidrawElement = newArrowElement({
|
|
20178
|
+
width,
|
|
20179
|
+
height,
|
|
20180
|
+
endArrowhead: "arrow",
|
|
20181
|
+
points: [pointFrom19(0, 0), pointFrom19(width, height)],
|
|
20182
|
+
...element,
|
|
20183
|
+
type: "arrow"
|
|
20184
|
+
});
|
|
20185
|
+
Object.assign(
|
|
20186
|
+
excalidrawElement,
|
|
20187
|
+
getSizeFromPoints3(excalidrawElement.points)
|
|
20188
|
+
);
|
|
20189
|
+
break;
|
|
20190
|
+
}
|
|
20191
|
+
case "text": {
|
|
20192
|
+
const fontFamily = element?.fontFamily || DEFAULT_FONT_FAMILY3;
|
|
20193
|
+
const fontSize = element?.fontSize || DEFAULT_FONT_SIZE4;
|
|
20194
|
+
const lineHeight = element?.lineHeight || getLineHeight2(fontFamily);
|
|
20195
|
+
const text = element.text ?? "";
|
|
20196
|
+
const normalizedText = normalizeText(text);
|
|
20197
|
+
const metrics = measureText(
|
|
20198
|
+
normalizedText,
|
|
20199
|
+
getFontString8({ fontFamily, fontSize }),
|
|
20200
|
+
lineHeight
|
|
20201
|
+
);
|
|
20202
|
+
excalidrawElement = newTextElement({
|
|
20203
|
+
width: metrics.width,
|
|
20204
|
+
height: metrics.height,
|
|
20205
|
+
fontFamily,
|
|
20206
|
+
fontSize,
|
|
20207
|
+
...element
|
|
20208
|
+
});
|
|
20209
|
+
break;
|
|
20210
|
+
}
|
|
20211
|
+
case "image": {
|
|
20212
|
+
excalidrawElement = newImageElement({
|
|
20213
|
+
width: element?.width || DEFAULT_DIMENSION,
|
|
20214
|
+
height: element?.height || DEFAULT_DIMENSION,
|
|
20215
|
+
...element
|
|
20216
|
+
});
|
|
20217
|
+
break;
|
|
20218
|
+
}
|
|
20219
|
+
case "frame": {
|
|
20220
|
+
excalidrawElement = newFrameElement({
|
|
20221
|
+
x: 0,
|
|
20222
|
+
y: 0,
|
|
20223
|
+
...element
|
|
20224
|
+
});
|
|
20225
|
+
break;
|
|
20226
|
+
}
|
|
20227
|
+
case "magicframe": {
|
|
20228
|
+
excalidrawElement = newMagicFrameElement({
|
|
20229
|
+
x: 0,
|
|
20230
|
+
y: 0,
|
|
20231
|
+
...element
|
|
20232
|
+
});
|
|
20233
|
+
break;
|
|
20234
|
+
}
|
|
20235
|
+
case "freedraw":
|
|
20236
|
+
case "iframe":
|
|
20237
|
+
case "embeddable": {
|
|
20238
|
+
excalidrawElement = element;
|
|
20239
|
+
break;
|
|
20240
|
+
}
|
|
20241
|
+
default: {
|
|
20242
|
+
excalidrawElement = element;
|
|
20243
|
+
assertNever5(
|
|
20244
|
+
element,
|
|
20245
|
+
`Unhandled element type "${element.type}"`,
|
|
20246
|
+
true
|
|
20247
|
+
);
|
|
20248
|
+
}
|
|
20249
|
+
}
|
|
20250
|
+
const existingElement = elementStore.getElement(excalidrawElement.id);
|
|
20251
|
+
if (existingElement) {
|
|
20252
|
+
console.error(`Duplicate id found for ${excalidrawElement.id}`);
|
|
20253
|
+
} else {
|
|
20254
|
+
elementStore.add(excalidrawElement);
|
|
20255
|
+
elementsWithIds.set(excalidrawElement.id, element);
|
|
20256
|
+
if (originalId) {
|
|
20257
|
+
oldToNewElementIdMap.set(originalId, excalidrawElement.id);
|
|
20258
|
+
}
|
|
20259
|
+
}
|
|
20260
|
+
}
|
|
20261
|
+
const elementsMap = elementStore.getElementsMap();
|
|
20262
|
+
const scene = new Scene(elementsMap);
|
|
20263
|
+
for (const [id, element] of elementsWithIds) {
|
|
20264
|
+
const excalidrawElement = elementStore.getElement(id);
|
|
20265
|
+
switch (element.type) {
|
|
20266
|
+
case "rectangle":
|
|
20267
|
+
case "ellipse":
|
|
20268
|
+
case "diamond":
|
|
20269
|
+
case "arrow": {
|
|
20270
|
+
if (element.label?.text) {
|
|
20271
|
+
let [container, text] = bindTextToContainer(
|
|
20272
|
+
excalidrawElement,
|
|
20273
|
+
element?.label,
|
|
20274
|
+
scene
|
|
20275
|
+
);
|
|
20276
|
+
elementStore.add(container);
|
|
20277
|
+
elementStore.add(text);
|
|
20278
|
+
if (isArrowElement(container)) {
|
|
20279
|
+
const originalStart = element.type === "arrow" ? element?.start : void 0;
|
|
20280
|
+
const originalEnd = element.type === "arrow" ? element?.end : void 0;
|
|
20281
|
+
if (originalStart && originalStart.id) {
|
|
20282
|
+
const newStartId = oldToNewElementIdMap.get(originalStart.id);
|
|
20283
|
+
if (newStartId) {
|
|
20284
|
+
Object.assign(originalStart, { id: newStartId });
|
|
20285
|
+
}
|
|
20286
|
+
}
|
|
20287
|
+
if (originalEnd && originalEnd.id) {
|
|
20288
|
+
const newEndId = oldToNewElementIdMap.get(originalEnd.id);
|
|
20289
|
+
if (newEndId) {
|
|
20290
|
+
Object.assign(originalEnd, { id: newEndId });
|
|
20291
|
+
}
|
|
20292
|
+
}
|
|
20293
|
+
const { linearElement, startBoundElement, endBoundElement } = bindLinearElementToElement(
|
|
20294
|
+
container,
|
|
20295
|
+
originalStart,
|
|
20296
|
+
originalEnd,
|
|
20297
|
+
elementStore,
|
|
20298
|
+
scene
|
|
20299
|
+
);
|
|
20300
|
+
container = linearElement;
|
|
20301
|
+
elementStore.add(linearElement);
|
|
20302
|
+
elementStore.add(startBoundElement);
|
|
20303
|
+
elementStore.add(endBoundElement);
|
|
20304
|
+
}
|
|
20305
|
+
} else {
|
|
20306
|
+
switch (element.type) {
|
|
20307
|
+
case "arrow": {
|
|
20308
|
+
const { start, end } = element;
|
|
20309
|
+
if (start && start.id) {
|
|
20310
|
+
const newStartId = oldToNewElementIdMap.get(start.id);
|
|
20311
|
+
Object.assign(start, { id: newStartId });
|
|
20312
|
+
}
|
|
20313
|
+
if (end && end.id) {
|
|
20314
|
+
const newEndId = oldToNewElementIdMap.get(end.id);
|
|
20315
|
+
Object.assign(end, { id: newEndId });
|
|
20316
|
+
}
|
|
20317
|
+
const { linearElement, startBoundElement, endBoundElement } = bindLinearElementToElement(
|
|
20318
|
+
excalidrawElement,
|
|
20319
|
+
start,
|
|
20320
|
+
end,
|
|
20321
|
+
elementStore,
|
|
20322
|
+
scene
|
|
20323
|
+
);
|
|
20324
|
+
elementStore.add(linearElement);
|
|
20325
|
+
elementStore.add(startBoundElement);
|
|
20326
|
+
elementStore.add(endBoundElement);
|
|
20327
|
+
break;
|
|
20328
|
+
}
|
|
20329
|
+
}
|
|
20330
|
+
}
|
|
20331
|
+
break;
|
|
20332
|
+
}
|
|
20333
|
+
}
|
|
20334
|
+
}
|
|
20335
|
+
for (const [id, element] of elementsWithIds) {
|
|
20336
|
+
if (element.type !== "frame" && element.type !== "magicframe") {
|
|
20337
|
+
continue;
|
|
20338
|
+
}
|
|
20339
|
+
const frame = elementStore.getElement(id);
|
|
20340
|
+
if (!frame) {
|
|
20341
|
+
throw new Error(`Excalidraw element with id ${id} doesn't exist`);
|
|
20342
|
+
}
|
|
20343
|
+
const childrenElements = [];
|
|
20344
|
+
element.children.forEach((id2) => {
|
|
20345
|
+
const newElementId = oldToNewElementIdMap.get(id2);
|
|
20346
|
+
if (!newElementId) {
|
|
20347
|
+
throw new Error(`Element with ${id2} wasn't mapped correctly`);
|
|
20348
|
+
}
|
|
20349
|
+
const elementInFrame = elementStore.getElement(newElementId);
|
|
20350
|
+
if (!elementInFrame) {
|
|
20351
|
+
throw new Error(`Frame element with id ${newElementId} doesn't exist`);
|
|
20352
|
+
}
|
|
20353
|
+
Object.assign(elementInFrame, { frameId: frame.id });
|
|
20354
|
+
elementInFrame?.boundElements?.forEach((boundElement) => {
|
|
20355
|
+
const ele = elementStore.getElement(boundElement.id);
|
|
20356
|
+
if (!ele) {
|
|
20357
|
+
throw new Error(
|
|
20358
|
+
`Bound element with id ${boundElement.id} doesn't exist`
|
|
20359
|
+
);
|
|
20360
|
+
}
|
|
20361
|
+
Object.assign(ele, { frameId: frame.id });
|
|
20362
|
+
childrenElements.push(ele);
|
|
20363
|
+
});
|
|
20364
|
+
childrenElements.push(elementInFrame);
|
|
20365
|
+
});
|
|
20366
|
+
let [minX, minY, maxX, maxY] = getCommonBounds(childrenElements);
|
|
20367
|
+
const PADDING = 10;
|
|
20368
|
+
minX = minX - PADDING;
|
|
20369
|
+
minY = minY - PADDING;
|
|
20370
|
+
maxX = maxX + PADDING;
|
|
20371
|
+
maxY = maxY + PADDING;
|
|
20372
|
+
const frameX = frame?.x || minX;
|
|
20373
|
+
const frameY = frame?.y || minY;
|
|
20374
|
+
const frameWidth = frame?.width || maxX - minX;
|
|
20375
|
+
const frameHeight = frame?.height || maxY - minY;
|
|
20376
|
+
Object.assign(frame, {
|
|
20377
|
+
x: frameX,
|
|
20378
|
+
y: frameY,
|
|
20379
|
+
width: frameWidth,
|
|
20380
|
+
height: frameHeight
|
|
20381
|
+
});
|
|
20382
|
+
if (isDevEnv7() && element.children.length && (frame?.x || frame?.y || frame?.width || frame?.height)) {
|
|
20383
|
+
console.info(
|
|
20384
|
+
"User provided frame attributes are being considered, if you find this inaccurate, please remove any of the attributes - x, y, width and height so frame coordinates and dimensions are calculated automatically"
|
|
20385
|
+
);
|
|
20386
|
+
}
|
|
20387
|
+
}
|
|
20388
|
+
return elementStore.getElements();
|
|
20389
|
+
};
|
|
20390
|
+
|
|
19497
20391
|
// src/zindex.ts
|
|
19498
20392
|
init_define_import_meta_env();
|
|
19499
|
-
import { arrayToMap as
|
|
20393
|
+
import { arrayToMap as arrayToMap12, findIndex, findLastIndex as findLastIndex2 } from "@excalidraw/common";
|
|
19500
20394
|
var isOfTargetFrame = (element, frameId) => {
|
|
19501
20395
|
return element.frameId === frameId || element.id === frameId;
|
|
19502
20396
|
};
|
|
@@ -19505,7 +20399,7 @@ var getIndicesToMove = (elements, appState, elementsToBeMoved) => {
|
|
|
19505
20399
|
let deletedIndices = [];
|
|
19506
20400
|
let includeDeletedIndex = null;
|
|
19507
20401
|
let index = -1;
|
|
19508
|
-
const selectedElementIds =
|
|
20402
|
+
const selectedElementIds = arrayToMap12(
|
|
19509
20403
|
elementsToBeMoved ? elementsToBeMoved : getSelectedElements(elements, appState, {
|
|
19510
20404
|
includeBoundTextElement: true,
|
|
19511
20405
|
includeElementsInFrames: true
|
|
@@ -19799,7 +20693,7 @@ var shiftElementsToEnd = (elements, appState, direction, containingFrame, elemen
|
|
|
19799
20693
|
return nextElements;
|
|
19800
20694
|
};
|
|
19801
20695
|
function shiftElementsAccountingForFrames(allElements, appState, direction, shiftFunction) {
|
|
19802
|
-
const elementsToMove =
|
|
20696
|
+
const elementsToMove = arrayToMap12(
|
|
19803
20697
|
getSelectedElements(allElements, appState, {
|
|
19804
20698
|
includeBoundTextElement: true,
|
|
19805
20699
|
includeElementsInFrames: true
|
|
@@ -19917,7 +20811,6 @@ export {
|
|
|
19917
20811
|
HEADING_LEFT,
|
|
19918
20812
|
HEADING_RIGHT,
|
|
19919
20813
|
HEADING_UP,
|
|
19920
|
-
IMAGE_INVERT_FILTER,
|
|
19921
20814
|
INVISIBLY_SMALL_ELEMENT_SIZE,
|
|
19922
20815
|
InvalidFractionalIndexError,
|
|
19923
20816
|
LinearElementEditor,
|
|
@@ -19957,6 +20850,7 @@ export {
|
|
|
19957
20850
|
computeBoundTextPosition,
|
|
19958
20851
|
computeContainerDimensionForBoundText,
|
|
19959
20852
|
containsCJK,
|
|
20853
|
+
convertToExcalidrawElements,
|
|
19960
20854
|
createPlaceholderEmbeddableLabel,
|
|
19961
20855
|
createSrcDoc,
|
|
19962
20856
|
cropElement,
|
|
@@ -19986,7 +20880,6 @@ export {
|
|
|
19986
20880
|
fixDuplicatedBindingsAfterDuplication,
|
|
19987
20881
|
flipHeading,
|
|
19988
20882
|
frameAndChildrenSelectedTogether,
|
|
19989
|
-
generateFreeDrawShape,
|
|
19990
20883
|
generateLinearCollisionShape,
|
|
19991
20884
|
generateRoughOptions,
|
|
19992
20885
|
getAllHoveredElementAtPoint,
|
|
@@ -19997,6 +20890,7 @@ export {
|
|
|
19997
20890
|
getArrowheadPoints,
|
|
19998
20891
|
getArrowheadSize,
|
|
19999
20892
|
getBindingGap,
|
|
20893
|
+
getBindingSideMidPoint,
|
|
20000
20894
|
getBindingStrategyForDraggingBindingElementEndpoints,
|
|
20001
20895
|
getBoundTextElement,
|
|
20002
20896
|
getBoundTextElementId,
|
|
@@ -20038,8 +20932,6 @@ export {
|
|
|
20038
20932
|
getFrameChildren,
|
|
20039
20933
|
getFrameLikeElements,
|
|
20040
20934
|
getFrameLikeTitle,
|
|
20041
|
-
getFreeDrawPath2D,
|
|
20042
|
-
getFreeDrawSvgPath,
|
|
20043
20935
|
getFreedrawOutlineAsSegments,
|
|
20044
20936
|
getFreedrawOutlinePoints,
|
|
20045
20937
|
getGlobalFixedPointForBindableElement,
|
|
@@ -20124,7 +21016,6 @@ export {
|
|
|
20124
21016
|
isBindingElementType,
|
|
20125
21017
|
isBindingEnabled,
|
|
20126
21018
|
isBoundToContainer,
|
|
20127
|
-
isBounds,
|
|
20128
21019
|
isCursorInFrame,
|
|
20129
21020
|
isCurvedArrow,
|
|
20130
21021
|
isElbowArrow,
|
|
@@ -20203,7 +21094,6 @@ export {
|
|
|
20203
21094
|
originalContainerCache,
|
|
20204
21095
|
parseElementLinkFromURL,
|
|
20205
21096
|
parseTokens,
|
|
20206
|
-
pathsCache,
|
|
20207
21097
|
pointInsideBounds,
|
|
20208
21098
|
positionElementsOnGrid,
|
|
20209
21099
|
projectFixedPointOntoDiagonal,
|