@yorab/react-paint 0.18.1 → 1.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +266 -22
- package/dist/_chunks/canvas-CDYlr833.js +1 -0
- package/dist/_chunks/editor-BARYd5Od.js +1 -0
- package/dist/canvas/components/Canvas.d.ts +15 -3
- package/dist/canvas/components/EditTextBox.d.ts +4 -4
- package/dist/canvas/constants/app.d.ts +32 -17
- package/dist/canvas/constants/grid.d.ts +7 -0
- package/dist/canvas/constants/picture.d.ts +8 -0
- package/dist/canvas/constants/shapes.d.ts +2 -2
- package/dist/canvas/constants/tools.d.ts +12 -2
- package/dist/canvas/constants/zoom.d.ts +4 -2
- package/dist/canvas/context/PaintContext.d.ts +9 -0
- package/dist/canvas/hooks/useAnnotationsStyle.d.ts +5 -0
- package/dist/canvas/hooks/useAutoScroll.d.ts +4 -0
- package/dist/canvas/hooks/useCanvasRenderer.d.ts +17 -0
- package/dist/canvas/hooks/useDrawableCanvas.d.ts +8 -5
- package/dist/canvas/hooks/useDropPicture.d.ts +7 -0
- package/dist/canvas/hooks/useKeyboard.d.ts +6 -32
- package/dist/canvas/hooks/usePaintState.d.ts +9 -0
- package/dist/canvas/hooks/usePinchZoomAndMove.d.ts +3 -13
- package/dist/canvas/hooks/useReactPaint.d.ts +11 -163
- package/dist/canvas/hooks/useResizeObserver.d.ts +1 -0
- package/dist/canvas/hooks/useShapeEvents.d.ts +7 -0
- package/dist/canvas/hooks/useZoom.d.ts +4 -17
- package/dist/canvas/index.d.ts +24 -17
- package/dist/canvas/index.js +1 -1
- package/dist/canvas/store/createStore.d.ts +14 -0
- package/dist/canvas/store/eventEmitter.d.ts +11 -0
- package/dist/canvas/store/internal.d.ts +5 -0
- package/dist/canvas/store/paintStore.d.ts +898 -0
- package/dist/canvas/store/selectors.d.ts +855 -0
- package/dist/canvas/store/shapesReducer.d.ts +66 -0
- package/dist/canvas/store/types.d.ts +72 -0
- package/dist/canvas/types/Canvas.d.ts +19 -0
- package/dist/{src/common → canvas}/types/Mode.d.ts +8 -15
- package/dist/{common → canvas}/types/Settings.d.ts +6 -1
- package/dist/{common → canvas}/types/Shapes.d.ts +27 -21
- package/dist/canvas/types/editor.d.ts +388 -0
- package/dist/{common → canvas}/types/tools.d.ts +10 -6
- package/dist/{common → canvas}/utils/array.d.ts +2 -0
- package/dist/canvas/utils/canvas.d.ts +18 -2
- package/dist/canvas/utils/click.d.ts +17 -0
- package/dist/canvas/utils/data.d.ts +6 -5
- package/dist/canvas/utils/equality.d.ts +5 -0
- package/dist/canvas/utils/file.d.ts +36 -266
- package/dist/canvas/utils/grid.d.ts +1 -1
- package/dist/canvas/utils/intersect.d.ts +24 -14
- package/dist/canvas/utils/object.d.ts +11 -0
- package/dist/{src/common/utils/selection.d.ts → canvas/utils/selectedShapes.d.ts} +2 -2
- package/dist/canvas/utils/selection/anchors.d.ts +16 -0
- package/dist/canvas/utils/selection/groupSelection.d.ts +3 -3
- package/dist/canvas/utils/selection/lineSelection.d.ts +3 -10
- package/dist/canvas/utils/selection/rectSelection.d.ts +6 -11
- package/dist/canvas/utils/selection/selectionFrame.d.ts +2 -2
- package/dist/canvas/utils/selection.d.ts +7 -5
- package/dist/canvas/utils/shapeInput.d.ts +45 -0
- package/dist/canvas/utils/shapePatch.d.ts +10 -0
- package/dist/canvas/utils/shapes/brush.d.ts +6 -6
- package/dist/canvas/utils/shapes/circle.d.ts +5 -5
- package/dist/canvas/utils/shapes/curve.d.ts +4 -4
- package/dist/canvas/utils/shapes/ellipse.d.ts +5 -5
- package/dist/canvas/utils/shapes/group.d.ts +9 -3
- package/dist/canvas/utils/shapes/index.d.ts +31 -5
- package/dist/canvas/utils/shapes/line.d.ts +5 -5
- package/dist/canvas/utils/shapes/path.d.ts +16 -8
- package/dist/canvas/utils/shapes/picture.d.ts +7 -5
- package/dist/canvas/utils/shapes/polygon.d.ts +4 -4
- package/dist/canvas/utils/shapes/rectangle.d.ts +5 -5
- package/dist/canvas/utils/shapes/text.d.ts +12 -6
- package/dist/canvas/utils/shapes/triangle.d.ts +2 -2
- package/dist/canvas/utils/tools.d.ts +12 -3
- package/dist/canvas/utils/transform.d.ts +5 -4
- package/dist/canvas/utils/trigo.d.ts +17 -1
- package/dist/canvas/utils/util.d.ts +14 -0
- package/dist/canvas/utils/zoom.d.ts +29 -15
- package/dist/editor/components/common/Button.d.ts +0 -1
- package/dist/editor/components/common/FileInput.d.ts +0 -1
- package/dist/editor/components/common/Loading.d.ts +1 -2
- package/dist/editor/components/common/Menu.d.ts +3 -2
- package/dist/editor/components/common/Modal.d.ts +1 -2
- package/dist/editor/components/common/Panel.d.ts +1 -2
- package/dist/editor/components/common/Snackbar.d.ts +2 -3
- package/dist/editor/components/settings/ClosedPointsField.d.ts +1 -1
- package/dist/editor/components/settings/ColorField.d.ts +1 -2
- package/dist/editor/components/settings/DeleteButton.d.ts +3 -4
- package/dist/editor/components/settings/FontFamilyField.d.ts +1 -2
- package/dist/editor/components/settings/LayoutButton.d.ts +1 -2
- package/dist/editor/components/settings/Layouts.d.ts +4 -15
- package/dist/editor/components/settings/LineArrowField.d.ts +1 -2
- package/dist/editor/components/settings/LineTypeField.d.ts +2 -3
- package/dist/editor/components/settings/RangeField.d.ts +1 -2
- package/dist/editor/components/settings/SelectField.d.ts +1 -2
- package/dist/editor/components/settings/SettingsBar.d.ts +3 -18
- package/dist/editor/components/settings/ToggleField.d.ts +2 -1
- package/dist/editor/components/settings/ZoomButton.d.ts +1 -2
- package/dist/editor/components/settings/ZoomPanel.d.ts +4 -0
- package/dist/editor/components/toolbox/ActionButton.d.ts +9 -0
- package/dist/editor/components/toolbox/ContextMenu.d.ts +5 -24
- package/dist/editor/components/toolbox/ExportModal.d.ts +1 -2
- package/dist/editor/components/toolbox/LoadFileTool.d.ts +4 -4
- package/dist/editor/components/toolbox/MenuGroup.d.ts +1 -7
- package/dist/editor/components/toolbox/PictureUrlInput.d.ts +2 -2
- package/dist/editor/components/toolbox/Tool.d.ts +3 -3
- package/dist/editor/components/toolbox/Toolbar.d.ts +5 -16
- package/dist/editor/components/toolbox/ToolbarGroup.d.ts +2 -3
- package/dist/editor/constants/options.d.ts +11 -1
- package/dist/editor/constants/snackbar.d.ts +1 -1
- package/dist/editor/constants/style.d.ts +0 -9
- package/dist/editor/constants/tools.d.ts +12 -32
- package/dist/editor/editor.css +1 -0
- package/dist/editor/hooks/useDrag.d.ts +3 -3
- package/dist/editor/hooks/useMenu.d.ts +3 -2
- package/dist/editor/hooks/usePressOutside.d.ts +7 -0
- package/dist/editor/hooks/useSnackbar.d.ts +1 -1
- package/dist/editor/index.d.ts +12 -22
- package/dist/editor/index.js +1 -1
- package/dist/editor/types/tools.d.ts +7 -0
- package/dist/editor/utils/dom.d.ts +1 -0
- package/dist/editor/utils/style.d.ts +7 -1
- package/dist/editor/utils/toolbar.d.ts +1 -2
- package/dist/editor/utils/util.d.ts +5 -0
- package/dist/index.d.ts +2 -5
- package/dist/react-paint.css +1 -1
- package/dist/react-paint.js +1 -1
- package/dist/react-paint.umd.cjs +1 -1
- package/package.json +37 -26
- package/dist/_chunks/array-DuJem3vg.js +0 -1
- package/dist/_chunks/canvas-DF1RWuxW.js +0 -1
- package/dist/_chunks/editor-DuVskl0R.js +0 -1
- package/dist/canvas/context/CanvasContext.d.ts +0 -55
- package/dist/canvas/hooks/useComponent.d.ts +0 -12
- package/dist/canvas/hooks/useDoubleClick.d.ts +0 -5
- package/dist/canvas/hooks/useEventListener.d.ts +0 -2
- package/dist/canvas/hooks/useShapes.d.ts +0 -44
- package/dist/common/hooks/useDebounce.d.ts +0 -2
- package/dist/common/types/Canvas.d.ts +0 -8
- package/dist/common/types/Mode.d.ts +0 -64
- package/dist/common/types/react.d.ts +0 -6
- package/dist/common/utils/dom.d.ts +0 -1
- package/dist/common/utils/object.d.ts +0 -4
- package/dist/common/utils/selection.d.ts +0 -4
- package/dist/common/utils/util.d.ts +0 -3
- package/dist/editor/constants/grid.d.ts +0 -7
- package/dist/src/canvas/components/Canvas.d.ts +0 -4
- package/dist/src/canvas/components/EditTextBox.d.ts +0 -13
- package/dist/src/canvas/constants/app.d.ts +0 -37
- package/dist/src/canvas/constants/grid.d.ts +0 -1
- package/dist/src/canvas/constants/keyboard.d.ts +0 -27
- package/dist/src/canvas/constants/picture.d.ts +0 -1
- package/dist/src/canvas/constants/rendering.d.ts +0 -3
- package/dist/src/canvas/constants/shapes.d.ts +0 -10
- package/dist/src/canvas/constants/tools.d.ts +0 -4
- package/dist/src/canvas/constants/zoom.d.ts +0 -5
- package/dist/src/canvas/context/CanvasContext.d.ts +0 -55
- package/dist/src/canvas/hooks/useComponent.d.ts +0 -12
- package/dist/src/canvas/hooks/useDoubleClick.d.ts +0 -5
- package/dist/src/canvas/hooks/useDrawableCanvas.d.ts +0 -6
- package/dist/src/canvas/hooks/useEventListener.d.ts +0 -2
- package/dist/src/canvas/hooks/useKeyboard.d.ts +0 -33
- package/dist/src/canvas/hooks/usePinchZoomAndMove.d.ts +0 -17
- package/dist/src/canvas/hooks/useReactPaint.d.ts +0 -164
- package/dist/src/canvas/hooks/useResizeObserver.d.ts +0 -6
- package/dist/src/canvas/hooks/useShapes.d.ts +0 -44
- package/dist/src/canvas/hooks/useZoom.d.ts +0 -22
- package/dist/src/canvas/index.d.ts +0 -19
- package/dist/src/canvas/utils/canvas.d.ts +0 -15
- package/dist/src/canvas/utils/data.d.ts +0 -5
- package/dist/src/canvas/utils/file.d.ts +0 -274
- package/dist/src/canvas/utils/grid.d.ts +0 -2
- package/dist/src/canvas/utils/intersect.d.ts +0 -27
- package/dist/src/canvas/utils/selection/groupSelection.d.ts +0 -4
- package/dist/src/canvas/utils/selection/lineSelection.d.ts +0 -19
- package/dist/src/canvas/utils/selection/rectSelection.d.ts +0 -20
- package/dist/src/canvas/utils/selection/selectionFrame.d.ts +0 -3
- package/dist/src/canvas/utils/selection.d.ts +0 -12
- package/dist/src/canvas/utils/shapes/brush.d.ts +0 -21
- package/dist/src/canvas/utils/shapes/circle.d.ts +0 -18
- package/dist/src/canvas/utils/shapes/curve.d.ts +0 -17
- package/dist/src/canvas/utils/shapes/ellipse.d.ts +0 -18
- package/dist/src/canvas/utils/shapes/group.d.ts +0 -33
- package/dist/src/canvas/utils/shapes/index.d.ts +0 -35
- package/dist/src/canvas/utils/shapes/line.d.ts +0 -19
- package/dist/src/canvas/utils/shapes/path.d.ts +0 -29
- package/dist/src/canvas/utils/shapes/picture.d.ts +0 -13
- package/dist/src/canvas/utils/shapes/polygon.d.ts +0 -18
- package/dist/src/canvas/utils/shapes/rectangle.d.ts +0 -22
- package/dist/src/canvas/utils/shapes/text.d.ts +0 -27
- package/dist/src/canvas/utils/shapes/triangle.d.ts +0 -4
- package/dist/src/canvas/utils/transform.d.ts +0 -15
- package/dist/src/canvas/utils/trigo.d.ts +0 -19
- package/dist/src/canvas/utils/zoom.d.ts +0 -58
- package/dist/src/common/hooks/useDebounce.d.ts +0 -2
- package/dist/src/common/types/Canvas.d.ts +0 -8
- package/dist/src/common/types/Settings.d.ts +0 -24
- package/dist/src/common/types/Shapes.d.ts +0 -153
- package/dist/src/common/types/react.d.ts +0 -6
- package/dist/src/common/types/tools.d.ts +0 -164
- package/dist/src/common/types/utils.d.ts +0 -4
- package/dist/src/common/utils/array.d.ts +0 -2
- package/dist/src/common/utils/dom.d.ts +0 -1
- package/dist/src/common/utils/object.d.ts +0 -4
- package/dist/src/common/utils/util.d.ts +0 -3
- package/dist/src/editor/components/common/Button.d.ts +0 -16
- package/dist/src/editor/components/common/FileInput.d.ts +0 -13
- package/dist/src/editor/components/common/Loading.d.ts +0 -6
- package/dist/src/editor/components/common/Menu.d.ts +0 -10
- package/dist/src/editor/components/common/Modal.d.ts +0 -11
- package/dist/src/editor/components/common/Panel.d.ts +0 -15
- package/dist/src/editor/components/common/Snackbar.d.ts +0 -7
- package/dist/src/editor/components/settings/ClosedPointsField.d.ts +0 -10
- package/dist/src/editor/components/settings/ColorField.d.ts +0 -15
- package/dist/src/editor/components/settings/DeleteButton.d.ts +0 -8
- package/dist/src/editor/components/settings/FontFamilyField.d.ts +0 -12
- package/dist/src/editor/components/settings/LayoutButton.d.ts +0 -7
- package/dist/src/editor/components/settings/Layouts.d.ts +0 -19
- package/dist/src/editor/components/settings/LineArrowField.d.ts +0 -12
- package/dist/src/editor/components/settings/LineTypeField.d.ts +0 -16
- package/dist/src/editor/components/settings/RangeField.d.ts +0 -19
- package/dist/src/editor/components/settings/SelectField.d.ts +0 -18
- package/dist/src/editor/components/settings/SettingsBar.d.ts +0 -26
- package/dist/src/editor/components/settings/ToggleField.d.ts +0 -13
- package/dist/src/editor/components/settings/ZoomButton.d.ts +0 -8
- package/dist/src/editor/components/toolbox/ContextMenu.d.ts +0 -25
- package/dist/src/editor/components/toolbox/ExportModal.d.ts +0 -7
- package/dist/src/editor/components/toolbox/LoadFileTool.d.ts +0 -11
- package/dist/src/editor/components/toolbox/MenuGroup.d.ts +0 -27
- package/dist/src/editor/components/toolbox/PictureUrlInput.d.ts +0 -7
- package/dist/src/editor/components/toolbox/Tool.d.ts +0 -11
- package/dist/src/editor/components/toolbox/Toolbar.d.ts +0 -26
- package/dist/src/editor/components/toolbox/ToolbarGroup.d.ts +0 -14
- package/dist/src/editor/constants/grid.d.ts +0 -7
- package/dist/src/editor/constants/icons.d.ts +0 -43
- package/dist/src/editor/constants/loading.d.ts +0 -1
- package/dist/src/editor/constants/options.d.ts +0 -13
- package/dist/src/editor/constants/snackbar.d.ts +0 -7
- package/dist/src/editor/constants/style.d.ts +0 -14
- package/dist/src/editor/constants/tools.d.ts +0 -32
- package/dist/src/editor/hooks/useDrag.d.ts +0 -15
- package/dist/src/editor/hooks/useMenu.d.ts +0 -11
- package/dist/src/editor/hooks/useSnackbar.d.ts +0 -10
- package/dist/src/editor/index.d.ts +0 -25
- package/dist/src/editor/types/snackbar.d.ts +0 -7
- package/dist/src/editor/utils/style.d.ts +0 -2
- package/dist/src/editor/utils/toolbar.d.ts +0 -11
- package/dist/src/index.d.ts +0 -5
- /package/dist/{common → canvas}/types/utils.d.ts +0 -0
- /package/dist/{canvas → editor}/hooks/useDebounce.d.ts +0 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { ChangeSource } from './../../canvas/types/editor.js';
|
|
2
|
+
import type { SelectionType, ShapeEntity } from './../../canvas/types/Shapes.js';
|
|
3
|
+
type HistoryEntry = {
|
|
4
|
+
shapes: ShapeEntity[];
|
|
5
|
+
selectedShape: SelectionType | undefined;
|
|
6
|
+
source: ChangeSource;
|
|
7
|
+
};
|
|
8
|
+
export type ShapesState = {
|
|
9
|
+
shapes: ShapeEntity[];
|
|
10
|
+
selectedShape: SelectionType | undefined;
|
|
11
|
+
history: {
|
|
12
|
+
states: HistoryEntry[];
|
|
13
|
+
cursor: number;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export type ShapesAction = {
|
|
17
|
+
type: 'ADD';
|
|
18
|
+
newShapes: ShapeEntity[];
|
|
19
|
+
index?: number | undefined;
|
|
20
|
+
} | {
|
|
21
|
+
type: 'UPDATE';
|
|
22
|
+
updatedShapes: ShapeEntity[];
|
|
23
|
+
newSelectedShape: SelectionType | undefined;
|
|
24
|
+
save: boolean;
|
|
25
|
+
source?: ChangeSource | undefined;
|
|
26
|
+
} | {
|
|
27
|
+
type: 'REMOVE';
|
|
28
|
+
ids: Set<string>;
|
|
29
|
+
newSelectedShape: SelectionType | undefined;
|
|
30
|
+
source?: ChangeSource | undefined;
|
|
31
|
+
} | {
|
|
32
|
+
type: 'DUPLICATE';
|
|
33
|
+
newShapesMap: Map<string, ShapeEntity>;
|
|
34
|
+
newSelectedShape: SelectionType | undefined;
|
|
35
|
+
} | {
|
|
36
|
+
type: 'RESET_AND_SAVE';
|
|
37
|
+
shapes: ShapeEntity[];
|
|
38
|
+
newSelectedShape: SelectionType | undefined;
|
|
39
|
+
} | {
|
|
40
|
+
type: 'SET_SELECTION';
|
|
41
|
+
newSelectedShape: SelectionType | undefined;
|
|
42
|
+
} | {
|
|
43
|
+
type: 'SAVE';
|
|
44
|
+
source?: ChangeSource | undefined;
|
|
45
|
+
} | {
|
|
46
|
+
type: 'UNDO';
|
|
47
|
+
} | {
|
|
48
|
+
type: 'REDO';
|
|
49
|
+
} | {
|
|
50
|
+
type: 'CLEAR';
|
|
51
|
+
shapes: ShapeEntity[];
|
|
52
|
+
clearHistory: boolean;
|
|
53
|
+
source: ChangeSource;
|
|
54
|
+
} | {
|
|
55
|
+
type: 'REFRESH_ALL';
|
|
56
|
+
shapes: ShapeEntity[];
|
|
57
|
+
newSelectedShape: SelectionType | undefined;
|
|
58
|
+
}
|
|
59
|
+
/** Merges the steps added after the cursor `from` into a single one, the last */
|
|
60
|
+
| {
|
|
61
|
+
type: 'SQUASH_HISTORY';
|
|
62
|
+
from: number;
|
|
63
|
+
};
|
|
64
|
+
export declare const INITIAL_SHAPES_STATE: ShapesState;
|
|
65
|
+
export declare const shapesReducer: (state: ShapesState, action: ShapesAction) => ShapesState;
|
|
66
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { OptionalOptions } from './../../canvas/constants/app.js';
|
|
2
|
+
import type { ShapesState } from './../../canvas/store/shapesReducer.js';
|
|
3
|
+
import type { CanvasSize } from './../../canvas/types/Canvas.js';
|
|
4
|
+
import type { ResolvedOptions } from './../../canvas/types/editor.js';
|
|
5
|
+
import type { HoverModeData, SelectionModeData } from './../../canvas/types/Mode.js';
|
|
6
|
+
import type { Point, SelectionType, ShapeInput } from './../../canvas/types/Shapes.js';
|
|
7
|
+
import type { CustomTool } from './../../canvas/types/tools.js';
|
|
8
|
+
export type UseReactPaintProps = {
|
|
9
|
+
width?: number | undefined;
|
|
10
|
+
height?: number | undefined;
|
|
11
|
+
shapes?: ShapeInput[] | undefined;
|
|
12
|
+
mode?: 'editor' | 'viewer' | undefined;
|
|
13
|
+
disabled?: boolean | undefined;
|
|
14
|
+
options?: OptionalOptions | undefined;
|
|
15
|
+
};
|
|
16
|
+
export type PaintConfig = {
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
mode: 'editor' | 'viewer';
|
|
20
|
+
disabled: boolean;
|
|
21
|
+
options: ResolvedOptions;
|
|
22
|
+
};
|
|
23
|
+
export type SelectionFrameState = {
|
|
24
|
+
oldSelection: SelectionType | undefined;
|
|
25
|
+
frame: [Point, Point];
|
|
26
|
+
};
|
|
27
|
+
export type PanStart = {
|
|
28
|
+
start: Point;
|
|
29
|
+
originalOffset: Point;
|
|
30
|
+
};
|
|
31
|
+
export type CanvasTransformation = {
|
|
32
|
+
offset: Point;
|
|
33
|
+
zoom: number;
|
|
34
|
+
};
|
|
35
|
+
export type Modifiers = {
|
|
36
|
+
shift: boolean;
|
|
37
|
+
alt: boolean;
|
|
38
|
+
space: boolean;
|
|
39
|
+
};
|
|
40
|
+
export type Focus = {
|
|
41
|
+
component: boolean;
|
|
42
|
+
canvas: boolean;
|
|
43
|
+
};
|
|
44
|
+
export type InternalState = {
|
|
45
|
+
/** Props of the hook */
|
|
46
|
+
config: PaintConfig;
|
|
47
|
+
/** Shapes, selection and history */
|
|
48
|
+
document: ShapesState;
|
|
49
|
+
clipboard: SelectionType | undefined;
|
|
50
|
+
tools: {
|
|
51
|
+
available: CustomTool[];
|
|
52
|
+
activeToolId: string;
|
|
53
|
+
};
|
|
54
|
+
view: {
|
|
55
|
+
canvasSize: CanvasSize;
|
|
56
|
+
transformation: CanvasTransformation;
|
|
57
|
+
gridGap: number;
|
|
58
|
+
};
|
|
59
|
+
interaction: {
|
|
60
|
+
selectionMode: SelectionModeData<Point | number>;
|
|
61
|
+
/** The hovered shape is read from the drawing by its id: it follows the changes of its shape, and goes with it */
|
|
62
|
+
hoveredShapeId: string | undefined;
|
|
63
|
+
/** What the cursor would do on the selection: it gives the cursor of the canvas */
|
|
64
|
+
hoverMode: HoverModeData;
|
|
65
|
+
selectionFrame: SelectionFrameState | undefined;
|
|
66
|
+
modifiers: Modifiers;
|
|
67
|
+
panStart: PanStart | undefined;
|
|
68
|
+
/** Speed of the auto scroll, while a selection frame is drawn close to the borders */
|
|
69
|
+
moveAcceleration: Point;
|
|
70
|
+
focus: Focus;
|
|
71
|
+
};
|
|
72
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type CanvasSize = {
|
|
2
|
+
realWidth: number;
|
|
3
|
+
realHeight: number;
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
scaleRatio: number;
|
|
7
|
+
};
|
|
8
|
+
export type Size = 'infinite' | 'fixed';
|
|
9
|
+
/**
|
|
10
|
+
* How the canvas follows the size of its container. The first four keep the logical size, width×height, and show the
|
|
11
|
+
* whole drawing, its width following the container:
|
|
12
|
+
* - 'scaleDown': at most width pixels wide, scaled down in a narrower container
|
|
13
|
+
* - 'scale': as wide as the container, scaled up or down
|
|
14
|
+
* - 'scaleUp': at least width pixels wide, scaled up in a wider container
|
|
15
|
+
* - 'none': always width×height pixels
|
|
16
|
+
*
|
|
17
|
+
* 'extend' fills the container at the scale 1: the visible area of the drawing follows the container
|
|
18
|
+
*/
|
|
19
|
+
export type Resize = 'scaleDown' | 'scale' | 'scaleUp' | 'none' | 'extend';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SelectionHover } from './editor.js';
|
|
2
|
+
import type { Point, SelectionType } from './Shapes.js';
|
|
2
3
|
export type SelectionModeDefault = {
|
|
3
4
|
mode: 'default';
|
|
4
5
|
};
|
|
@@ -40,25 +41,17 @@ export type SelectionModeTranslate = {
|
|
|
40
41
|
export type SelectionModeContextMenu<AnchorType extends Point | number = Point> = {
|
|
41
42
|
mode: 'contextMenu';
|
|
42
43
|
cursorStartPosition: Point;
|
|
44
|
+
clientPosition: {
|
|
45
|
+
x: number;
|
|
46
|
+
y: number;
|
|
47
|
+
};
|
|
43
48
|
originalShape: SelectionType | undefined;
|
|
44
49
|
anchor: AnchorType | undefined;
|
|
45
50
|
};
|
|
46
51
|
export type SelectionModeData<AnchorType extends Point | number> = SelectionModeDefault | SelectionModeSelectionFrame | SelectionModeBrush | SelectionModeResize<AnchorType> | SelectionModeRotate | SelectionModeTranslate | SelectionModeEditText | SelectionModePreview | SelectionModeContextMenu<AnchorType>;
|
|
52
|
+
/** The part of the selection under the pointer, or 'default' away from it */
|
|
47
53
|
export type HoverModeData = {
|
|
48
54
|
outOfView?: boolean;
|
|
49
55
|
} & ({
|
|
50
56
|
mode: 'default';
|
|
51
|
-
} |
|
|
52
|
-
mode: 'selectionFrame';
|
|
53
|
-
} | {
|
|
54
|
-
mode: 'resize';
|
|
55
|
-
anchor: Point | number;
|
|
56
|
-
} | {
|
|
57
|
-
mode: 'brush';
|
|
58
|
-
} | {
|
|
59
|
-
mode: 'rotate';
|
|
60
|
-
} | {
|
|
61
|
-
mode: 'translate';
|
|
62
|
-
} | {
|
|
63
|
-
mode: 'textedition';
|
|
64
|
-
});
|
|
57
|
+
} | SelectionHover);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Point } from './../../
|
|
1
|
+
import type { Point } from './../../canvas/types/Shapes.js';
|
|
2
2
|
export type BrushAlgo = 'simple' | 'quadratic';
|
|
3
3
|
export type UtilsSettings = {
|
|
4
4
|
brushAlgo: BrushAlgo;
|
|
@@ -14,6 +14,11 @@ export type UtilsSettings = {
|
|
|
14
14
|
scaleRatio: number;
|
|
15
15
|
scaleRatioWithNoZoom: number;
|
|
16
16
|
};
|
|
17
|
+
/** Logical size of the drawing: its limits when its size is fixed. canvasSize.realWidth is the visible area at zoom 1 */
|
|
18
|
+
drawingSize: {
|
|
19
|
+
width: number;
|
|
20
|
+
height: number;
|
|
21
|
+
};
|
|
17
22
|
selectionPadding: number;
|
|
18
23
|
size: 'infinite' | 'fixed';
|
|
19
24
|
features: {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ShapeTypeArray } from '
|
|
1
|
+
import type { ShapeTypeArray } from './../../canvas/constants/shapes.js';
|
|
2
2
|
export type ShapeType = (typeof ShapeTypeArray)[number];
|
|
3
3
|
export type Point = [number, number];
|
|
4
4
|
export type Rect = {
|
|
@@ -55,25 +55,18 @@ export type StyleShape = {
|
|
|
55
55
|
fontItalic?: boolean;
|
|
56
56
|
fontBold?: boolean;
|
|
57
57
|
};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
border: Path2D;
|
|
61
|
-
line: Path2D | undefined;
|
|
62
|
-
shapePath: Path2D | undefined;
|
|
63
|
-
anchors: Path2D[];
|
|
64
|
-
};
|
|
65
|
-
export type SelectionLinesType = {
|
|
66
|
-
type: 'line';
|
|
67
|
-
border: Path2D;
|
|
68
|
-
shapePath: Path2D | undefined;
|
|
69
|
-
anchors: Path2D[];
|
|
70
|
-
};
|
|
58
|
+
/** Data of the application attached to a shape: it is not drawn, and is kept in the history, the copies and the exported data */
|
|
59
|
+
export type ShapeData = Record<string, unknown>;
|
|
71
60
|
type GenericDrawableShape = {
|
|
61
|
+
/** Kept when the shape is exported and loaded again. A new id is created when it is missing or already used */
|
|
62
|
+
id?: string;
|
|
72
63
|
rotation?: number;
|
|
73
64
|
toolId?: string;
|
|
74
65
|
visible?: boolean;
|
|
75
66
|
locked?: boolean;
|
|
76
67
|
style?: StyleShape | undefined;
|
|
68
|
+
/** Free data of the application, which must be serializable in JSON. A patch replaces it as a whole */
|
|
69
|
+
data?: ShapeData | undefined;
|
|
77
70
|
} & ((Line & {
|
|
78
71
|
type: 'line';
|
|
79
72
|
}) | (Picture & {
|
|
@@ -133,17 +126,30 @@ export type ShapeEntity<T extends Exclude<ShapeType, 'triangle'> = Exclude<Shape
|
|
|
133
126
|
path: Path2D;
|
|
134
127
|
} & DrawableShape<T> & ({
|
|
135
128
|
type: 'line';
|
|
136
|
-
selection?: SelectionLinesType | undefined;
|
|
137
129
|
arrows?: TriangleEntity[];
|
|
138
130
|
} | {
|
|
139
|
-
type: '
|
|
140
|
-
selection?: SelectionLinesType | undefined;
|
|
141
|
-
} | {
|
|
142
|
-
type: 'text' | 'picture' | 'rect' | 'square' | 'circle' | 'ellipse' | 'group' | 'brush';
|
|
143
|
-
selection?: SelectionDefaultType | undefined;
|
|
131
|
+
type: Exclude<ShapeType, 'line' | 'triangle'>;
|
|
144
132
|
});
|
|
133
|
+
/** A shape as exported: without the computed data, and with its id */
|
|
134
|
+
export type ExportedShape = ExportedDrawableShape & {
|
|
135
|
+
id: string;
|
|
136
|
+
};
|
|
137
|
+
/** Types of the shapes which can be created and edited: triangles and groups are only built by the canvas */
|
|
138
|
+
export type EditableShapeType = Exclude<ShapeType, 'triangle' | 'group'>;
|
|
139
|
+
/** A text can be given without its size: it is computed from its font size, or from its width */
|
|
140
|
+
export type TextShapeInput = Omit<ExportedDrawableShape<'text'>, 'width' | 'height' | 'fontSize'> & Partial<Pick<DrawableShape<'text'>, 'width' | 'height' | 'fontSize'>>;
|
|
141
|
+
/**
|
|
142
|
+
* A shape given by the consumer, to create or to load it. Triangles and groups are refused by addShapes and left out
|
|
143
|
+
* when loading: they are accepted by the type so that data typed as DrawableShape can be given
|
|
144
|
+
*/
|
|
145
|
+
export type ShapeInput = ExportedDrawableShape | TextShapeInput;
|
|
146
|
+
type DistributivePatch<T> = T extends unknown ? {
|
|
147
|
+
id: string;
|
|
148
|
+
} & Partial<Omit<T, 'id' | 'type' | 'img'>> : never;
|
|
149
|
+
/** Fields of a shape to update, found by its id. Its type cannot change, and its style is merged with the current one */
|
|
150
|
+
export type ShapePatch = DistributivePatch<ExportedDrawableShape<EditableShapeType>>;
|
|
145
151
|
export type StateData = {
|
|
146
|
-
shapes?:
|
|
152
|
+
shapes?: ExportedShape[];
|
|
147
153
|
config?: {
|
|
148
154
|
width: number;
|
|
149
155
|
height: number;
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
import type { AppOptions, OptionalOptions } from './../../canvas/constants/app.js';
|
|
2
|
+
import type { Resize, Size } from './../../canvas/types/Canvas.js';
|
|
3
|
+
import type { SelectionModeData } from './../../canvas/types/Mode.js';
|
|
4
|
+
import type { ExportedShape, Point, Rect, ShapeEntity, ShapeInput, ShapePatch, StateData, StyleShape } from './../../canvas/types/Shapes.js';
|
|
5
|
+
import type { CustomTool, ToolsType } from './../../canvas/types/tools.js';
|
|
6
|
+
export type InteractionMode = SelectionModeData<Point | number>['mode'];
|
|
7
|
+
export type ExportView = 'fitToShapes' | 'defaultView' | 'currentZoom';
|
|
8
|
+
export type ZoomAction = 'unzoom' | 'zoom' | 'default';
|
|
9
|
+
export type ShapesOrderAction = 'first' | 'last' | 'forward' | 'backward';
|
|
10
|
+
export type ShapesTransformAction = 'flipHorizontally' | 'flipVertically' | 'rotateClockwise' | 'rotateCounterclockwise';
|
|
11
|
+
export type ShapeStyleField = keyof StyleShape;
|
|
12
|
+
export type ToolSettingValue = string | number | boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Options of useReactPaint with the overrides of setOptions and their defaults. The functions are kept out of the state,
|
|
15
|
+
* so that options can be compared by value
|
|
16
|
+
*/
|
|
17
|
+
export type ResolvedOptions = Omit<AppOptions, 'clearCallback' | 'resolvePictureSrc'>;
|
|
18
|
+
export type ContextMenuState = {
|
|
19
|
+
/** Shapes targeted by the context menu (empty when opened on an empty area) */
|
|
20
|
+
shapes: ShapeEntity[];
|
|
21
|
+
/** Index of the curve / polygon point under the cursor, if any */
|
|
22
|
+
anchorIndex: number | undefined;
|
|
23
|
+
/** Whether this point can be removed with actions.removeShapePoint: a polygon or a curve keeps at least 2 points */
|
|
24
|
+
canRemoveAnchor: boolean;
|
|
25
|
+
/** Cursor position in canvas logical coordinates */
|
|
26
|
+
canvasPosition: Point;
|
|
27
|
+
/** Cursor position in viewport coordinates, convenient for a position: fixed menu */
|
|
28
|
+
clientPosition: {
|
|
29
|
+
x: number;
|
|
30
|
+
y: number;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Part of the selection under the pointer, which a press drags: its inside (translate), the anchor of the rotation, or an
|
|
35
|
+
* anchor of the resize. The anchor is the index of a point of a line, a polygon or a curve, or else its place on the
|
|
36
|
+
* borders of the selection before its rotation, from [0, 0] (top left) to [1, 1] (bottom right)
|
|
37
|
+
*/
|
|
38
|
+
export type SelectionHover = {
|
|
39
|
+
mode: 'translate';
|
|
40
|
+
} | {
|
|
41
|
+
mode: 'rotate';
|
|
42
|
+
} | {
|
|
43
|
+
mode: 'resize';
|
|
44
|
+
anchor: Point | number;
|
|
45
|
+
};
|
|
46
|
+
export type InteractionState = {
|
|
47
|
+
/** The gesture running, like 'translate', 'rotate', 'resize', 'selectionFrame' or 'brush', or 'default' between them */
|
|
48
|
+
mode: InteractionMode;
|
|
49
|
+
/** Shape under the mouse, between the gestures. The anchors of the selection outside of its shape are given by selectionHover */
|
|
50
|
+
hoveredShape: ShapeEntity | undefined;
|
|
51
|
+
/** Part of the selection under the pointer, which tells the gesture a press starts. It follows the moves between the gestures */
|
|
52
|
+
selectionHover: SelectionHover | undefined;
|
|
53
|
+
selectionFrame: [Point, Point] | undefined;
|
|
54
|
+
modifiers: {
|
|
55
|
+
shift: boolean;
|
|
56
|
+
alt: boolean;
|
|
57
|
+
space: boolean;
|
|
58
|
+
};
|
|
59
|
+
isPanning: boolean;
|
|
60
|
+
focus: {
|
|
61
|
+
component: boolean;
|
|
62
|
+
canvas: boolean;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
export type EditorState = {
|
|
66
|
+
mode: 'editor' | 'viewer';
|
|
67
|
+
disabled: boolean;
|
|
68
|
+
features: {
|
|
69
|
+
edition: boolean;
|
|
70
|
+
zoom: boolean;
|
|
71
|
+
};
|
|
72
|
+
/** Logical size of the drawing: the visible area follows the container when the resize option is 'extend' */
|
|
73
|
+
width: number;
|
|
74
|
+
height: number;
|
|
75
|
+
layout: {
|
|
76
|
+
size: Size;
|
|
77
|
+
resize: Resize;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* A point of the drawing is displayed at (point + offset) × scaleRatio pixels from the top left corner of the canvas.
|
|
81
|
+
* visibleArea is the part of the drawing displayed, in its units: it goes beyond a fixed drawing smaller than the view
|
|
82
|
+
*/
|
|
83
|
+
view: {
|
|
84
|
+
zoom: number;
|
|
85
|
+
offset: Point;
|
|
86
|
+
displayWidth: number;
|
|
87
|
+
displayHeight: number;
|
|
88
|
+
scaleRatio: number;
|
|
89
|
+
visibleArea: Rect;
|
|
90
|
+
};
|
|
91
|
+
/** Options in effect. The grid and the default styles of the tools changed while editing are in gridGap and tools */
|
|
92
|
+
options: ResolvedOptions;
|
|
93
|
+
gridGap: number;
|
|
94
|
+
shapes: ShapeEntity[];
|
|
95
|
+
/** Selected shape, or group of shapes when several are selected */
|
|
96
|
+
selection: ShapeEntity | undefined;
|
|
97
|
+
selectedShapes: ShapeEntity[];
|
|
98
|
+
/** Ids of the selected shapes, to give to the actions. The array keeps its identity while the same shapes are selected */
|
|
99
|
+
selectedShapeIds: string[];
|
|
100
|
+
/** One of the selection tool, the move tool or the tools */
|
|
101
|
+
activeTool: ToolsType;
|
|
102
|
+
tools: CustomTool[];
|
|
103
|
+
history: {
|
|
104
|
+
canUndo: boolean;
|
|
105
|
+
canRedo: boolean;
|
|
106
|
+
canClear: boolean;
|
|
107
|
+
};
|
|
108
|
+
clipboard: {
|
|
109
|
+
hasContent: boolean;
|
|
110
|
+
};
|
|
111
|
+
withContextMenu: boolean;
|
|
112
|
+
/** Whether image files dropped on the canvas are added: the withDropPicture option, the edition and the picture tool */
|
|
113
|
+
withDropPicture: boolean;
|
|
114
|
+
interaction: InteractionState;
|
|
115
|
+
contextMenu: ContextMenuState | undefined;
|
|
116
|
+
};
|
|
117
|
+
/** Origin of a change of the drawing, given to dataChanged: changes received from elsewhere can be applied as 'remote' */
|
|
118
|
+
export type ChangeSource = 'user' | 'remote';
|
|
119
|
+
/** Changes of the shapes given to dataChanged, from the previous state of the drawing: an undo gives the reverse changes */
|
|
120
|
+
export type DataChanges = {
|
|
121
|
+
/** Shapes created, as exported */
|
|
122
|
+
added: ExportedShape[];
|
|
123
|
+
/** Shapes modified, with their version before the change */
|
|
124
|
+
updated: {
|
|
125
|
+
shape: ExportedShape;
|
|
126
|
+
previous: ExportedShape;
|
|
127
|
+
}[];
|
|
128
|
+
/** Shapes deleted, in their last version */
|
|
129
|
+
removed: ExportedShape[];
|
|
130
|
+
/** Whether the shapes still there are in another order */
|
|
131
|
+
reordered: boolean;
|
|
132
|
+
};
|
|
133
|
+
/** Options of the actions which change the shapes */
|
|
134
|
+
export type ShapesActionOptions = {
|
|
135
|
+
/** Adds a step to the history, true by default. A continuous change (like a slider) saves only its last step */
|
|
136
|
+
save?: boolean;
|
|
137
|
+
/** Origin of the change given to dataChanged, 'user' by default */
|
|
138
|
+
source?: ChangeSource;
|
|
139
|
+
};
|
|
140
|
+
export type SelectionUpdateMode = 'replace' | 'add' | 'remove';
|
|
141
|
+
/** Box of shapes, in the frame of their selection: turned by their rotation when they all have the same one */
|
|
142
|
+
export type ShapesBounds = Rect & {
|
|
143
|
+
rotation: number;
|
|
144
|
+
center: Point;
|
|
145
|
+
};
|
|
146
|
+
export type ExportImageFormat = 'png' | 'jpeg' | 'webp';
|
|
147
|
+
export type ExportImageOptions = {
|
|
148
|
+
/** Area exported, 'defaultView' by default */
|
|
149
|
+
view?: ExportView;
|
|
150
|
+
/** 'png' by default */
|
|
151
|
+
format?: ExportImageFormat;
|
|
152
|
+
/** Quality between 0 and 1, for the jpeg and webp formats */
|
|
153
|
+
quality?: number;
|
|
154
|
+
/** Color drawn under the shapes. A jpeg is white by default */
|
|
155
|
+
backgroundColor?: string;
|
|
156
|
+
/**
|
|
157
|
+
* Image drawn under the shapes, over the whole canvas, like the picture laid under the canvas with useAnnotationsStyle.
|
|
158
|
+
* An image from another origin without CORS headers makes the export fail with a SecurityError
|
|
159
|
+
*/
|
|
160
|
+
backgroundImage?: CanvasImageSource;
|
|
161
|
+
};
|
|
162
|
+
export type EditorActions = {
|
|
163
|
+
/** Selects one of the selection tool, the move tool or the tools, found by id. An unknown tool is ignored */
|
|
164
|
+
selectTool: (toolOrId: ToolsType | string) => void;
|
|
165
|
+
/** Sets the default value of a setting of a tool. A field the tool has not is ignored */
|
|
166
|
+
updateToolSettings: (toolId: string, field: string, value: ToolSettingValue) => void;
|
|
167
|
+
/** Sets several default values of a tool, used by the next shapes drawn with it. The fields the tool has not are ignored */
|
|
168
|
+
setToolStyle: (toolId: string, style: StyleShape) => void;
|
|
169
|
+
/** Selects the shapes, adds them to the selection or removes them from it ('replace' by default) */
|
|
170
|
+
selectShapes: (ids: string[], options?: {
|
|
171
|
+
mode?: SelectionUpdateMode;
|
|
172
|
+
}) => void;
|
|
173
|
+
selectAllShapes: () => void;
|
|
174
|
+
clearSelection: () => void;
|
|
175
|
+
/**
|
|
176
|
+
* Creates shapes and returns their ids. An id given with a shape is kept when it is free. The style is completed with
|
|
177
|
+
* the defaults of the tool of the shape, and the size of a text can be left out. A picture is drawn once its source is
|
|
178
|
+
* loaded. Throws an error, without creating any shape, when one of them is invalid
|
|
179
|
+
*/
|
|
180
|
+
addShapes: (shapes: ShapeInput[], options?: ShapesActionOptions & {
|
|
181
|
+
select?: boolean;
|
|
182
|
+
index?: number;
|
|
183
|
+
}) => string[];
|
|
184
|
+
/**
|
|
185
|
+
* Updates fields of shapes, found by their ids: geometry, points, text, style (merged), data (replaced)...
|
|
186
|
+
* The box of a text follows its new content or font size, its font size follows its new width or font. Throws an error, without
|
|
187
|
+
* changing anything, when a patch is invalid. Locked shapes are updated too
|
|
188
|
+
*/
|
|
189
|
+
updateShapes: (patches: ShapePatch[], options?: ShapesActionOptions) => void;
|
|
190
|
+
removeShapes: (ids: string[], options?: ShapesActionOptions) => void;
|
|
191
|
+
duplicateShapes: (ids: string[], options?: {
|
|
192
|
+
translate?: boolean;
|
|
193
|
+
select?: boolean;
|
|
194
|
+
}) => void;
|
|
195
|
+
/** Moves the shapes by a vector, in the units of the drawing. Locked shapes do not move */
|
|
196
|
+
translateShapes: (ids: string[], vector: Point, options?: ShapesActionOptions) => void;
|
|
197
|
+
/** Turns the shapes by an angle in radians, clockwise, around their center or the given point. Locked shapes do not turn */
|
|
198
|
+
rotateShapes: (ids: string[], angle: number, options?: ShapesActionOptions & {
|
|
199
|
+
center?: Point;
|
|
200
|
+
}) => void;
|
|
201
|
+
/**
|
|
202
|
+
* Resizes the shapes so that their box (see getBounds) becomes the given one. When one of them keeps its
|
|
203
|
+
* proportions (square, circle, picture, text), the box keeps them too, from its top left corner. Locked shapes do not change
|
|
204
|
+
*/
|
|
205
|
+
resizeShapes: (ids: string[], bounds: Rect, options?: ShapesActionOptions) => void;
|
|
206
|
+
/** Flips or turns by a quarter the shapes, around their center */
|
|
207
|
+
transformShapes: (ids: string[], action: ShapesTransformAction) => void;
|
|
208
|
+
setShapesStyle: (ids: string[], style: StyleShape, options?: ShapesActionOptions & {
|
|
209
|
+
updateTool?: boolean;
|
|
210
|
+
}) => void;
|
|
211
|
+
/** Sets one field of the style. With save false, the change is not added to the history, like while a slider moves */
|
|
212
|
+
updateShapesStyle: (ids: string[], field: ShapeStyleField, value: ToolSettingValue, options?: {
|
|
213
|
+
save?: boolean;
|
|
214
|
+
}) => void;
|
|
215
|
+
moveShapes: (ids: string[], action: ShapesOrderAction) => void;
|
|
216
|
+
swapShapes: (firstId: string, secondId: string) => void;
|
|
217
|
+
/** Moves a shape at an index of the shapes, 0 being the foreground */
|
|
218
|
+
setShapeIndex: (id: string, index: number) => void;
|
|
219
|
+
/** Orders the shapes from the foreground. The shapes left out stay behind, in their current order */
|
|
220
|
+
reorderShapes: (orderedIds: string[]) => void;
|
|
221
|
+
toggleShapesVisibility: (ids: string[]) => void;
|
|
222
|
+
toggleShapesLock: (ids: string[]) => void;
|
|
223
|
+
setShapesVisibility: (ids: string[], visible: boolean) => void;
|
|
224
|
+
setShapesLocked: (ids: string[], locked: boolean) => void;
|
|
225
|
+
/** Inserts a point in a polygon or a curve, before the point at this index (at the end when the index is the length) */
|
|
226
|
+
insertShapePoint: (id: string, index: number, point: Point) => void;
|
|
227
|
+
/** Moves a point of a line, a polygon or a curve */
|
|
228
|
+
moveShapePoint: (id: string, index: number, point: Point) => void;
|
|
229
|
+
/** Removes a point of a polygon or a curve, unless it would keep less than 2 points */
|
|
230
|
+
removeShapePoint: (id: string, pointIndex: number) => void;
|
|
231
|
+
/** Selects a text and opens its edition box, like a double click. Does nothing when the Canvas is not mounted */
|
|
232
|
+
editText: (id: string) => void;
|
|
233
|
+
/** Adds a picture from a file or an URL, at the center of the visible area, or centered on the position (in the units of the drawing) */
|
|
234
|
+
addPicture: (fileOrUrl: File | string, options?: {
|
|
235
|
+
maxWidth?: number;
|
|
236
|
+
maxHeight?: number;
|
|
237
|
+
select?: boolean;
|
|
238
|
+
position?: Point;
|
|
239
|
+
}) => Promise<ShapeEntity>;
|
|
240
|
+
copy: (ids?: string[]) => void;
|
|
241
|
+
cut: (ids?: string[]) => void;
|
|
242
|
+
paste: () => void;
|
|
243
|
+
undo: () => void;
|
|
244
|
+
redo: () => void;
|
|
245
|
+
saveShapes: () => void;
|
|
246
|
+
clearCanvas: () => void;
|
|
247
|
+
loadFile: (file: File) => Promise<void>;
|
|
248
|
+
/** Loads exported data, or their JSON string. The history is cleared by default */
|
|
249
|
+
loadData: (data: StateData | {
|
|
250
|
+
shapes?: ShapeInput[];
|
|
251
|
+
} | string, options?: {
|
|
252
|
+
clearHistory?: boolean;
|
|
253
|
+
}) => Promise<void>;
|
|
254
|
+
exportPicture: (options?: ExportImageOptions & {
|
|
255
|
+
fileName?: string;
|
|
256
|
+
}) => void;
|
|
257
|
+
exportData: (options?: {
|
|
258
|
+
fileName?: string;
|
|
259
|
+
}) => void;
|
|
260
|
+
setZoom: (action: ZoomAction) => void;
|
|
261
|
+
/** Sets the zoom level, keeping the given point of the drawing still (the center of the view by default) */
|
|
262
|
+
zoomTo: (level: number, options?: {
|
|
263
|
+
center?: Point;
|
|
264
|
+
}) => void;
|
|
265
|
+
/**
|
|
266
|
+
* Zooms and scrolls the view so that the shapes fill it, all the visible shapes by default. The padding is a margin in
|
|
267
|
+
* pixels of the screen. The zoom stays within its limits, and the view inside the canvas when its size is fixed
|
|
268
|
+
*/
|
|
269
|
+
zoomToShapes: (ids?: string[], options?: {
|
|
270
|
+
padding?: number;
|
|
271
|
+
}) => void;
|
|
272
|
+
resetZoom: () => void;
|
|
273
|
+
/** Moves the view: the offset is kept inside the canvas when its size is fixed */
|
|
274
|
+
setOffset: (offset: Point) => void;
|
|
275
|
+
/** Scrolls the view by a vector in the units of the drawing */
|
|
276
|
+
panBy: (vector: Point) => void;
|
|
277
|
+
/** Sets the gap of the grid, which the shapes snap to. 0 hides it, see GRID_PRESETS */
|
|
278
|
+
setGridGap: (gap: number) => void;
|
|
279
|
+
/** Opens the context menu at a position of the viewport, for the given shapes or else the selection. Does nothing when the context menu is disabled */
|
|
280
|
+
openContextMenu: (options: {
|
|
281
|
+
clientPosition: {
|
|
282
|
+
x: number;
|
|
283
|
+
y: number;
|
|
284
|
+
};
|
|
285
|
+
canvasPosition?: Point;
|
|
286
|
+
ids?: string[];
|
|
287
|
+
}) => void;
|
|
288
|
+
/** Closes the context menu and gives the focus back to the canvas. Does nothing when the menu is not open */
|
|
289
|
+
closeContextMenu: () => void;
|
|
290
|
+
/**
|
|
291
|
+
* Overrides options of useReactPaint. The overrides are kept over the props until resetOptions: objects are merged,
|
|
292
|
+
* arrays (like availableTools) are replaced
|
|
293
|
+
*/
|
|
294
|
+
setOptions: (options: OptionalOptions) => void;
|
|
295
|
+
/** Removes the overrides of setOptions: the options come back to the props */
|
|
296
|
+
resetOptions: () => void;
|
|
297
|
+
/** Restores the settings changed while editing: the default styles of the tools, the grid, the zoom and the active tool */
|
|
298
|
+
resetSettings: () => void;
|
|
299
|
+
};
|
|
300
|
+
/** Pointer event over the canvas */
|
|
301
|
+
export type ShapePointerInfo = {
|
|
302
|
+
/** Position in the units of the drawing */
|
|
303
|
+
canvasPosition: Point;
|
|
304
|
+
/** Position in the viewport, convenient for a position: fixed element */
|
|
305
|
+
clientPosition: {
|
|
306
|
+
x: number;
|
|
307
|
+
y: number;
|
|
308
|
+
};
|
|
309
|
+
originalEvent: PointerEvent;
|
|
310
|
+
};
|
|
311
|
+
/**
|
|
312
|
+
* Arguments given to the listeners of each event. The listeners are typed from them, so that the event of a listener
|
|
313
|
+
* is found from its name only: a union of the listeners of all the events would be too complex for TypeScript
|
|
314
|
+
*/
|
|
315
|
+
export type ReactPaintEventArgs = {
|
|
316
|
+
/** The drawing changes: its data, the origin of the change, and the shapes added, updated and removed */
|
|
317
|
+
dataChanged: [data: StateData, source: ChangeSource, changes: DataChanges];
|
|
318
|
+
selectionChanged: [selectedShapes: ShapeEntity[]];
|
|
319
|
+
toolChanged: [tool: ToolsType];
|
|
320
|
+
/** A visible shape is clicked, also in viewer mode. Locked shapes are clicked too */
|
|
321
|
+
shapeClicked: [shape: ShapeEntity, info: ShapePointerInfo];
|
|
322
|
+
/** The pointer enters a visible shape, or leaves it (undefined). Only computed while a listener is registered */
|
|
323
|
+
shapeHovered: [shape: ShapeEntity | undefined, info: ShapePointerInfo];
|
|
324
|
+
/**
|
|
325
|
+
* The drawing is clicked, on a visible shape or on an empty area (undefined), in every mode. A click outside of a fixed
|
|
326
|
+
* drawing smaller than the view is ignored
|
|
327
|
+
*/
|
|
328
|
+
canvasClicked: [shape: ShapeEntity | undefined, info: ShapePointerInfo];
|
|
329
|
+
/** The drawing is clicked twice at the same place, after the second canvasClicked */
|
|
330
|
+
canvasDoubleClicked: [shape: ShapeEntity | undefined, info: ShapePointerInfo];
|
|
331
|
+
/** A file dropped on the canvas is not added as a picture: its type is not an accepted image, or the image could not be loaded */
|
|
332
|
+
pictureDropFailed: [file: File, error: unknown];
|
|
333
|
+
/** A picture added by addShapes, or whose source is changed by updateShapes, is loaded and drawn */
|
|
334
|
+
pictureLoaded: [shape: ShapeEntity<'picture'>];
|
|
335
|
+
/**
|
|
336
|
+
* The image of a picture cannot be loaded. The picture is left out of loaded data, and stays in the drawing, not drawn,
|
|
337
|
+
* when it was added by addShapes or updateShapes: getShape(shape.id) tells which
|
|
338
|
+
*/
|
|
339
|
+
pictureLoadFailed: [shape: ShapeEntity<'picture'>, error: unknown];
|
|
340
|
+
};
|
|
341
|
+
export type ReactPaintEvents = {
|
|
342
|
+
[E in keyof ReactPaintEventArgs]: (...args: ReactPaintEventArgs[E]) => void;
|
|
343
|
+
};
|
|
344
|
+
export type ReactPaintEventName = keyof ReactPaintEvents;
|
|
345
|
+
/**
|
|
346
|
+
* Handle returned by useReactPaint, given to the Canvas and Editor components. Its identity never changes:
|
|
347
|
+
* read the state with usePaintState during a render, or with getState in a handler.
|
|
348
|
+
*/
|
|
349
|
+
export type ReactPaint = {
|
|
350
|
+
actions: EditorActions;
|
|
351
|
+
/** Current state, without subscription. The same object is returned as long as nothing changes */
|
|
352
|
+
getState: () => EditorState;
|
|
353
|
+
/** Calls the listener after each change of the state. Returns the function that unsubscribes it */
|
|
354
|
+
subscribe: (listener: () => void) => () => void;
|
|
355
|
+
/** Returns the function that unregisters the listener */
|
|
356
|
+
registerEvent: <E extends ReactPaintEventName>(event: E, fn: ReactPaintEvents[E]) => () => void;
|
|
357
|
+
/** Unregisters the listener, or all the listeners of the event when none is given */
|
|
358
|
+
unregisterEvent: <E extends ReactPaintEventName>(event: E, fn?: ReactPaintEvents[E]) => void;
|
|
359
|
+
/**
|
|
360
|
+
* Runs the function: the changes it makes give a single step of the history, a single dataChanged event and a single
|
|
361
|
+
* render. The changes made before an error are kept
|
|
362
|
+
*/
|
|
363
|
+
batch: <R>(fn: () => R) => R;
|
|
364
|
+
/** A shape found by its id */
|
|
365
|
+
getShape: (id: string) => ShapeEntity | undefined;
|
|
366
|
+
/** Box of the shapes, without the padding of the selection */
|
|
367
|
+
getBounds: (ids: string[]) => ShapesBounds | undefined;
|
|
368
|
+
/** Visible shapes under a point of the drawing, from the foreground. Needs a browser */
|
|
369
|
+
getShapesAt: (point: Point) => ShapeEntity[];
|
|
370
|
+
/** Point of the drawing at a position of the viewport. Undefined while the Canvas is not mounted or not displayed */
|
|
371
|
+
toCanvasPosition: (clientPosition: {
|
|
372
|
+
x: number;
|
|
373
|
+
y: number;
|
|
374
|
+
}) => Point | undefined;
|
|
375
|
+
/** Position in the viewport of a point of the drawing, to place an element over it. Undefined while the Canvas is not mounted or not displayed */
|
|
376
|
+
toClientPosition: (point: Point) => {
|
|
377
|
+
x: number;
|
|
378
|
+
y: number;
|
|
379
|
+
} | undefined;
|
|
380
|
+
resetCanvas: (shapes?: ShapeInput[], clearHistory?: boolean) => void;
|
|
381
|
+
getCurrentImage: (options?: ExportImageOptions) => string;
|
|
382
|
+
getCurrentData: () => StateData;
|
|
383
|
+
/**
|
|
384
|
+
* Callback ref of the area where the keyboard shortcuts are active, the Canvas by default. The pointer always works over the Canvas.
|
|
385
|
+
* Set it on the root element of an editor so that the shortcuts also work while its toolbar is focused. The Editor component sets it
|
|
386
|
+
*/
|
|
387
|
+
scopeRef: (element: HTMLElement | null) => void;
|
|
388
|
+
};
|