65be7973be
* rotate rectanble with fixed angle * rotate dashed rectangle with fixed angle * fix rotate handler rect * fix canvas size with rotation * angle in element base * fix bug in calculating canvas size * trial only for rectangle * hitTest for rectangle rotation * properly resize rotated rectangle * fix canvas size calculation * giving up... workaround for now * **experimental** handler to rotate rectangle * remove rotation on copy for debugging * update snapshots * better rotation handler with atan2 * rotate when drawImage * add rotation handler * hitTest for any shapes * fix hitTest for curved lines * rotate text element * rotation locking * hint messaage for rotating * show proper handlers on mobile (a workaround, there should be a better way) * refactor hitTest * support exporting png * support exporting svg * fix rotating curved line * refactor drawElementFromCanvas with getElementAbsoluteCoords * fix export png and svg * adjust resize positions for lines (N, E, S, W) * do not make handlers big on mobile * Update src/locales/en.json Alright! Co-Authored-By: Lipis <lipiridis@gmail.com> * do not show rotation/resizing hints on mobile * proper calculation for N and W positions * simplify calculation * use "rotation" as property name for clarification (may increase bundle size) * update snapshots excluding rotation handle * refactor with adjustPositionWithRotation * refactor with adjustXYWithRotation * forgot to rename rotation * rename internal function * initialize element angle on restore * rotate wysiwyg editor * fix shift-rotate around 270deg * improve rotation locking * refactor adjustXYWithRotation * avoid rotation degree becomes >=360 * refactor with generateHandler Co-authored-by: Lipis <lipiridis@gmail.com> Co-authored-by: dwelle <luzar.david@gmail.com>
82 lines
2.2 KiB
TypeScript
82 lines
2.2 KiB
TypeScript
import { AppState, FlooredNumber } from "./types";
|
|
import { getDateTime } from "./utils";
|
|
|
|
export const DEFAULT_FONT = "20px Virgil";
|
|
|
|
export function getDefaultAppState(): AppState {
|
|
return {
|
|
isLoading: false,
|
|
draggingElement: null,
|
|
resizingElement: null,
|
|
multiElement: null,
|
|
editingElement: null,
|
|
elementType: "selection",
|
|
elementLocked: false,
|
|
exportBackground: true,
|
|
currentItemStrokeColor: "#000000",
|
|
currentItemBackgroundColor: "transparent",
|
|
currentItemFillStyle: "hachure",
|
|
currentItemStrokeWidth: 1,
|
|
currentItemRoughness: 1,
|
|
currentItemOpacity: 100,
|
|
currentItemFont: DEFAULT_FONT,
|
|
viewBackgroundColor: "#ffffff",
|
|
scrollX: 0 as FlooredNumber,
|
|
scrollY: 0 as FlooredNumber,
|
|
cursorX: 0,
|
|
cursorY: 0,
|
|
scrolledOutside: false,
|
|
name: `excalidraw-${getDateTime()}`,
|
|
isCollaborating: false,
|
|
isResizing: false,
|
|
isRotating: false,
|
|
selectionElement: null,
|
|
zoom: 1,
|
|
openMenu: null,
|
|
lastPointerDownWith: "mouse",
|
|
selectedElementIds: {},
|
|
collaborators: new Map(),
|
|
shouldCacheIgnoreZoom: false,
|
|
};
|
|
}
|
|
|
|
export function clearAppStateForLocalStorage(appState: AppState) {
|
|
const {
|
|
draggingElement,
|
|
resizingElement,
|
|
multiElement,
|
|
editingElement,
|
|
selectionElement,
|
|
isResizing,
|
|
isRotating,
|
|
collaborators,
|
|
isCollaborating,
|
|
isLoading,
|
|
...exportedState
|
|
} = appState;
|
|
return exportedState;
|
|
}
|
|
|
|
export function clearAppStatePropertiesForHistory(
|
|
appState: AppState,
|
|
): Partial<AppState> {
|
|
return {
|
|
exportBackground: appState.exportBackground,
|
|
currentItemStrokeColor: appState.currentItemStrokeColor,
|
|
currentItemBackgroundColor: appState.currentItemBackgroundColor,
|
|
currentItemFillStyle: appState.currentItemFillStyle,
|
|
currentItemStrokeWidth: appState.currentItemStrokeWidth,
|
|
currentItemRoughness: appState.currentItemRoughness,
|
|
currentItemOpacity: appState.currentItemOpacity,
|
|
currentItemFont: appState.currentItemFont,
|
|
viewBackgroundColor: appState.viewBackgroundColor,
|
|
name: appState.name,
|
|
};
|
|
}
|
|
|
|
export function cleanAppStateForExport(appState: AppState) {
|
|
return {
|
|
viewBackgroundColor: appState.viewBackgroundColor,
|
|
};
|
|
}
|