js-draw 1.21.1 → 1.21.3
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/Editor.css +4 -2
- package/dist/bundle.js +2 -2
- package/dist/bundledStyles.js +1 -1
- package/dist/cjs/toolbar/widgets/InsertImageWidget/ImageWrapper.d.ts +1 -1
- package/dist/cjs/tools/BaseTool.d.ts +61 -0
- package/dist/cjs/tools/BaseTool.js +179 -0
- package/dist/cjs/tools/Eraser.d.ts +60 -0
- package/dist/cjs/tools/Eraser.js +299 -0
- package/dist/cjs/tools/Eraser.test.d.ts +1 -0
- package/dist/cjs/tools/FindTool.d.ts +21 -0
- package/dist/cjs/tools/FindTool.js +137 -0
- package/dist/cjs/tools/FindTool.test.d.ts +1 -0
- package/dist/cjs/tools/InputFilter/ContextMenuRecognizer.d.ts +17 -0
- package/dist/cjs/tools/InputFilter/ContextMenuRecognizer.js +105 -0
- package/dist/cjs/tools/InputFilter/ContextMenuRecognizer.test.d.ts +1 -0
- package/dist/cjs/tools/InputFilter/FunctionMapper.d.ts +12 -0
- package/dist/cjs/tools/InputFilter/FunctionMapper.js +21 -0
- package/dist/cjs/tools/InputFilter/InputMapper.d.ts +23 -0
- package/dist/cjs/tools/InputFilter/InputMapper.js +38 -0
- package/dist/cjs/tools/InputFilter/InputPipeline.d.ts +15 -0
- package/dist/cjs/tools/InputFilter/InputPipeline.js +54 -0
- package/dist/cjs/tools/InputFilter/InputPipeline.test.d.ts +1 -0
- package/dist/cjs/tools/InputFilter/InputStabilizer.d.ts +29 -0
- package/dist/cjs/tools/InputFilter/InputStabilizer.js +181 -0
- package/dist/cjs/tools/InputFilter/StrokeKeyboardControl.d.ts +21 -0
- package/dist/cjs/tools/InputFilter/StrokeKeyboardControl.js +84 -0
- package/dist/cjs/tools/PanZoom.d.ts +125 -0
- package/dist/cjs/tools/PanZoom.js +517 -0
- package/dist/cjs/tools/PanZoom.test.d.ts +1 -0
- package/dist/cjs/tools/PasteHandler.d.ts +23 -0
- package/dist/cjs/tools/PasteHandler.js +109 -0
- package/dist/cjs/tools/Pen.d.ts +54 -0
- package/dist/cjs/tools/Pen.js +335 -0
- package/dist/cjs/tools/Pen.test.d.ts +1 -0
- package/dist/cjs/tools/PipetteTool.d.ts +28 -0
- package/dist/cjs/tools/PipetteTool.js +69 -0
- package/dist/cjs/tools/ScrollbarTool.d.ts +18 -0
- package/dist/cjs/tools/ScrollbarTool.js +85 -0
- package/dist/cjs/tools/SelectionTool/SelectAllShortcutHandler.d.ts +9 -0
- package/dist/cjs/tools/SelectionTool/SelectAllShortcutHandler.js +32 -0
- package/dist/cjs/tools/SelectionTool/Selection.d.ts +72 -0
- package/dist/cjs/tools/SelectionTool/Selection.js +634 -0
- package/dist/cjs/tools/SelectionTool/SelectionHandle.d.ts +62 -0
- package/dist/cjs/tools/SelectionTool/SelectionHandle.js +141 -0
- package/dist/cjs/tools/SelectionTool/SelectionMenuShortcut.d.ts +32 -0
- package/dist/cjs/tools/SelectionTool/SelectionMenuShortcut.js +86 -0
- package/dist/cjs/tools/SelectionTool/SelectionTool.d.ts +42 -0
- package/dist/cjs/tools/SelectionTool/SelectionTool.js +500 -0
- package/dist/cjs/tools/SelectionTool/SelectionTool.selecting.test.d.ts +1 -0
- package/dist/cjs/tools/SelectionTool/SelectionTool.test.d.ts +1 -0
- package/dist/cjs/tools/SelectionTool/ToPointerAutoscroller.d.ts +23 -0
- package/dist/cjs/tools/SelectionTool/ToPointerAutoscroller.js +83 -0
- package/dist/cjs/tools/SelectionTool/TransformMode.d.ts +42 -0
- package/dist/cjs/tools/SelectionTool/TransformMode.js +155 -0
- package/dist/cjs/tools/SelectionTool/keybindings.d.ts +15 -0
- package/dist/cjs/tools/SelectionTool/keybindings.js +38 -0
- package/dist/cjs/tools/SelectionTool/types.d.ts +35 -0
- package/dist/cjs/tools/SelectionTool/types.js +14 -0
- package/dist/cjs/tools/SelectionTool/util/makeClipboardErrorHandlers.d.ts +6 -0
- package/dist/cjs/tools/SelectionTool/util/makeClipboardErrorHandlers.js +50 -0
- package/dist/cjs/tools/SelectionTool/util/showSelectionContextMenu.d.ts +5 -0
- package/dist/cjs/tools/SelectionTool/util/showSelectionContextMenu.js +43 -0
- package/dist/cjs/tools/SoundUITool.d.ts +26 -0
- package/dist/cjs/tools/SoundUITool.js +171 -0
- package/dist/cjs/tools/TextTool.d.ts +36 -0
- package/dist/cjs/tools/TextTool.js +285 -0
- package/dist/cjs/tools/TextTool.test.d.ts +1 -0
- package/dist/cjs/tools/ToolController.d.ts +73 -0
- package/dist/cjs/tools/ToolController.js +304 -0
- package/dist/cjs/tools/ToolController.test.d.ts +1 -0
- package/dist/cjs/tools/ToolEnabledGroup.d.ts +6 -0
- package/dist/cjs/tools/ToolEnabledGroup.js +13 -0
- package/dist/cjs/tools/ToolSwitcherShortcut.d.ts +16 -0
- package/dist/cjs/tools/ToolSwitcherShortcut.js +40 -0
- package/dist/cjs/tools/ToolbarShortcutHandler.d.ts +12 -0
- package/dist/cjs/tools/ToolbarShortcutHandler.js +34 -0
- package/dist/cjs/tools/UndoRedoShortcut.d.ts +8 -0
- package/dist/cjs/tools/UndoRedoShortcut.js +27 -0
- package/dist/cjs/tools/UndoRedoShortcut.test.d.ts +1 -0
- package/dist/cjs/tools/keybindings.d.ts +16 -0
- package/dist/cjs/tools/keybindings.js +58 -0
- package/dist/cjs/tools/lib.d.ts +14 -0
- package/dist/cjs/tools/lib.js +36 -0
- package/dist/cjs/tools/localization.d.ts +43 -0
- package/dist/cjs/tools/localization.js +45 -0
- package/dist/cjs/tools/util/StationaryPenDetector.d.ts +25 -0
- package/dist/cjs/tools/util/StationaryPenDetector.js +107 -0
- package/dist/cjs/tools/util/createMenuOverlay.d.ts +10 -0
- package/dist/cjs/tools/util/createMenuOverlay.js +126 -0
- package/dist/cjs/tools/util/createMenuOverlay.test.d.ts +1 -0
- package/dist/cjs/version.js +1 -1
- package/dist/mjs/toolbar/widgets/InsertImageWidget/ImageWrapper.d.ts +1 -1
- package/dist/mjs/tools/BaseTool.d.ts +61 -0
- package/dist/mjs/tools/BaseTool.mjs +177 -0
- package/dist/mjs/tools/Eraser.d.ts +60 -0
- package/dist/mjs/tools/Eraser.mjs +292 -0
- package/dist/mjs/tools/Eraser.test.d.ts +1 -0
- package/dist/mjs/tools/FindTool.d.ts +21 -0
- package/dist/mjs/tools/FindTool.mjs +131 -0
- package/dist/mjs/tools/FindTool.test.d.ts +1 -0
- package/dist/mjs/tools/InputFilter/ContextMenuRecognizer.d.ts +17 -0
- package/dist/mjs/tools/InputFilter/ContextMenuRecognizer.mjs +76 -0
- package/dist/mjs/tools/InputFilter/ContextMenuRecognizer.test.d.ts +1 -0
- package/dist/mjs/tools/InputFilter/FunctionMapper.d.ts +12 -0
- package/dist/mjs/tools/InputFilter/FunctionMapper.mjs +15 -0
- package/dist/mjs/tools/InputFilter/InputMapper.d.ts +23 -0
- package/dist/mjs/tools/InputFilter/InputMapper.mjs +36 -0
- package/dist/mjs/tools/InputFilter/InputPipeline.d.ts +15 -0
- package/dist/mjs/tools/InputFilter/InputPipeline.mjs +49 -0
- package/dist/mjs/tools/InputFilter/InputPipeline.test.d.ts +1 -0
- package/dist/mjs/tools/InputFilter/InputStabilizer.d.ts +29 -0
- package/dist/mjs/tools/InputFilter/InputStabilizer.mjs +175 -0
- package/dist/mjs/tools/InputFilter/StrokeKeyboardControl.d.ts +21 -0
- package/dist/mjs/tools/InputFilter/StrokeKeyboardControl.mjs +78 -0
- package/dist/mjs/tools/PanZoom.d.ts +125 -0
- package/dist/mjs/tools/PanZoom.mjs +510 -0
- package/dist/mjs/tools/PanZoom.test.d.ts +1 -0
- package/dist/mjs/tools/PasteHandler.d.ts +23 -0
- package/dist/mjs/tools/PasteHandler.mjs +103 -0
- package/dist/mjs/tools/Pen.d.ts +54 -0
- package/dist/mjs/tools/Pen.mjs +306 -0
- package/dist/mjs/tools/Pen.test.d.ts +1 -0
- package/dist/mjs/tools/PipetteTool.d.ts +28 -0
- package/dist/mjs/tools/PipetteTool.mjs +63 -0
- package/dist/mjs/tools/ScrollbarTool.d.ts +18 -0
- package/dist/mjs/tools/ScrollbarTool.mjs +79 -0
- package/dist/mjs/tools/SelectionTool/SelectAllShortcutHandler.d.ts +9 -0
- package/dist/mjs/tools/SelectionTool/SelectAllShortcutHandler.mjs +26 -0
- package/dist/mjs/tools/SelectionTool/Selection.d.ts +72 -0
- package/dist/mjs/tools/SelectionTool/Selection.mjs +606 -0
- package/dist/mjs/tools/SelectionTool/SelectionHandle.d.ts +62 -0
- package/dist/mjs/tools/SelectionTool/SelectionHandle.mjs +137 -0
- package/dist/mjs/tools/SelectionTool/SelectionMenuShortcut.d.ts +32 -0
- package/dist/mjs/tools/SelectionTool/SelectionMenuShortcut.mjs +83 -0
- package/dist/mjs/tools/SelectionTool/SelectionTool.d.ts +42 -0
- package/dist/mjs/tools/SelectionTool/SelectionTool.mjs +493 -0
- package/dist/mjs/tools/SelectionTool/SelectionTool.selecting.test.d.ts +1 -0
- package/dist/mjs/tools/SelectionTool/SelectionTool.test.d.ts +1 -0
- package/dist/mjs/tools/SelectionTool/ToPointerAutoscroller.d.ts +23 -0
- package/dist/mjs/tools/SelectionTool/ToPointerAutoscroller.mjs +77 -0
- package/dist/mjs/tools/SelectionTool/TransformMode.d.ts +42 -0
- package/dist/mjs/tools/SelectionTool/TransformMode.mjs +146 -0
- package/dist/mjs/tools/SelectionTool/keybindings.d.ts +15 -0
- package/dist/mjs/tools/SelectionTool/keybindings.mjs +32 -0
- package/dist/mjs/tools/SelectionTool/types.d.ts +35 -0
- package/dist/mjs/tools/SelectionTool/types.mjs +11 -0
- package/dist/mjs/tools/SelectionTool/util/makeClipboardErrorHandlers.d.ts +6 -0
- package/dist/mjs/tools/SelectionTool/util/makeClipboardErrorHandlers.mjs +45 -0
- package/dist/mjs/tools/SelectionTool/util/showSelectionContextMenu.d.ts +5 -0
- package/dist/mjs/tools/SelectionTool/util/showSelectionContextMenu.mjs +38 -0
- package/dist/mjs/tools/SoundUITool.d.ts +26 -0
- package/dist/mjs/tools/SoundUITool.mjs +165 -0
- package/dist/mjs/tools/TextTool.d.ts +36 -0
- package/dist/mjs/tools/TextTool.mjs +279 -0
- package/dist/mjs/tools/TextTool.test.d.ts +1 -0
- package/dist/mjs/tools/ToolController.d.ts +73 -0
- package/dist/mjs/tools/ToolController.mjs +275 -0
- package/dist/mjs/tools/ToolController.test.d.ts +1 -0
- package/dist/mjs/tools/ToolEnabledGroup.d.ts +6 -0
- package/dist/mjs/tools/ToolEnabledGroup.mjs +10 -0
- package/dist/mjs/tools/ToolSwitcherShortcut.d.ts +16 -0
- package/dist/mjs/tools/ToolSwitcherShortcut.mjs +34 -0
- package/dist/mjs/tools/ToolbarShortcutHandler.d.ts +12 -0
- package/dist/mjs/tools/ToolbarShortcutHandler.mjs +28 -0
- package/dist/mjs/tools/UndoRedoShortcut.d.ts +8 -0
- package/dist/mjs/tools/UndoRedoShortcut.mjs +21 -0
- package/dist/mjs/tools/UndoRedoShortcut.test.d.ts +1 -0
- package/dist/mjs/tools/keybindings.d.ts +16 -0
- package/dist/mjs/tools/keybindings.mjs +38 -0
- package/dist/mjs/tools/lib.d.ts +14 -0
- package/dist/mjs/tools/lib.mjs +14 -0
- package/dist/mjs/tools/localization.d.ts +43 -0
- package/dist/mjs/tools/localization.mjs +42 -0
- package/dist/mjs/tools/util/StationaryPenDetector.d.ts +25 -0
- package/dist/mjs/tools/util/StationaryPenDetector.mjs +103 -0
- package/dist/mjs/tools/util/createMenuOverlay.d.ts +10 -0
- package/dist/mjs/tools/util/createMenuOverlay.mjs +121 -0
- package/dist/mjs/tools/util/createMenuOverlay.test.d.ts +1 -0
- package/dist/mjs/version.mjs +1 -1
- package/package.json +4 -4
- package/src/tools/FindTool.css +7 -0
- package/src/tools/ScrollbarTool.scss +57 -0
- package/src/tools/SelectionTool/SelectionTool.scss +165 -0
- package/src/tools/SelectionTool/util/makeClipboardErrorHandlers.scss +15 -0
- package/src/tools/SoundUITool.scss +22 -0
- package/src/tools/tools.scss +6 -0
- package/src/tools/util/createMenuOverlay.scss +67 -0
@@ -0,0 +1,146 @@
|
|
1
|
+
import { Mat33, Vec2 } from '@js-draw/math';
|
2
|
+
import Viewport from '../../Viewport.mjs';
|
3
|
+
import { ResizeMode } from './types.mjs';
|
4
|
+
export class DragTransformer {
|
5
|
+
constructor(editor, selection) {
|
6
|
+
this.editor = editor;
|
7
|
+
this.selection = selection;
|
8
|
+
}
|
9
|
+
onDragStart(startPoint) {
|
10
|
+
this.selection.setTransform(Mat33.identity);
|
11
|
+
this.dragStartPoint = startPoint;
|
12
|
+
}
|
13
|
+
onDragUpdate(canvasPos) {
|
14
|
+
const delta = this.editor.viewport.roundPoint(canvasPos.minus(this.dragStartPoint));
|
15
|
+
this.selection.setTransform(Mat33.translation(delta));
|
16
|
+
}
|
17
|
+
onDragEnd() {
|
18
|
+
return this.selection.finalizeTransform();
|
19
|
+
}
|
20
|
+
}
|
21
|
+
export class ResizeTransformer {
|
22
|
+
constructor(editor, selection) {
|
23
|
+
this.editor = editor;
|
24
|
+
this.selection = selection;
|
25
|
+
this.mode = ResizeMode.Both;
|
26
|
+
}
|
27
|
+
onDragStart(startPoint, mode) {
|
28
|
+
this.selection.setTransform(Mat33.identity);
|
29
|
+
this.mode = mode;
|
30
|
+
this.dragStartPoint = startPoint;
|
31
|
+
this.computeOriginAndScaleRate();
|
32
|
+
}
|
33
|
+
computeOriginAndScaleRate() {
|
34
|
+
// Store the index of the furthest corner from startPoint. We'll use that
|
35
|
+
// to determine where the transform considers (0, 0) (where we scale from).
|
36
|
+
const selectionRect = this.selection.preTransformRegion;
|
37
|
+
const selectionBoxCorners = selectionRect.corners;
|
38
|
+
let largestDistSquared = 0;
|
39
|
+
for (let i = 0; i < selectionBoxCorners.length; i++) {
|
40
|
+
const currentCorner = selectionBoxCorners[i];
|
41
|
+
const distSquaredToCurrent = this.dragStartPoint.minus(currentCorner).magnitudeSquared();
|
42
|
+
if (distSquaredToCurrent > largestDistSquared) {
|
43
|
+
largestDistSquared = distSquaredToCurrent;
|
44
|
+
this.transformOrigin = currentCorner;
|
45
|
+
}
|
46
|
+
}
|
47
|
+
// Determine whether moving the mouse to the right increases or decreases the width.
|
48
|
+
let widthScaleRate = 1;
|
49
|
+
let heightScaleRate = 1;
|
50
|
+
if (this.transformOrigin.x > selectionRect.center.x) {
|
51
|
+
widthScaleRate = -1;
|
52
|
+
}
|
53
|
+
if (this.transformOrigin.y > selectionRect.center.y) {
|
54
|
+
heightScaleRate = -1;
|
55
|
+
}
|
56
|
+
this.scaleRate = Vec2.of(widthScaleRate, heightScaleRate);
|
57
|
+
}
|
58
|
+
onDragUpdate(canvasPos) {
|
59
|
+
const canvasDelta = canvasPos.minus(this.dragStartPoint);
|
60
|
+
const origWidth = this.selection.preTransformRegion.width;
|
61
|
+
const origHeight = this.selection.preTransformRegion.height;
|
62
|
+
let scale = Vec2.of(1, 1);
|
63
|
+
if (this.mode === ResizeMode.HorizontalOnly) {
|
64
|
+
const newWidth = origWidth + canvasDelta.x * this.scaleRate.x;
|
65
|
+
scale = Vec2.of(newWidth / origWidth, scale.y);
|
66
|
+
}
|
67
|
+
if (this.mode === ResizeMode.VerticalOnly) {
|
68
|
+
const newHeight = origHeight + canvasDelta.y * this.scaleRate.y;
|
69
|
+
scale = Vec2.of(scale.x, newHeight / origHeight);
|
70
|
+
}
|
71
|
+
if (this.mode === ResizeMode.Both) {
|
72
|
+
const delta = Math.abs(canvasDelta.x) > Math.abs(canvasDelta.y) ? canvasDelta.x : canvasDelta.y;
|
73
|
+
const newWidth = origWidth + delta;
|
74
|
+
scale = Vec2.of(newWidth / origWidth, newWidth / origWidth);
|
75
|
+
}
|
76
|
+
// Round: If this isn't done, scaling can create numbers with long decimal representations.
|
77
|
+
// long decimal representations => large file sizes.
|
78
|
+
scale = scale.map(component => Viewport.roundScaleRatio(component, 2));
|
79
|
+
if (scale.x !== 0 && scale.y !== 0) {
|
80
|
+
const origin = this.editor.viewport.roundPoint(this.transformOrigin);
|
81
|
+
this.selection.setTransform(Mat33.scaling2D(scale, origin));
|
82
|
+
}
|
83
|
+
}
|
84
|
+
onDragEnd() {
|
85
|
+
return this.selection.finalizeTransform();
|
86
|
+
}
|
87
|
+
}
|
88
|
+
export class RotateTransformer {
|
89
|
+
constructor(editor, selection) {
|
90
|
+
this.editor = editor;
|
91
|
+
this.selection = selection;
|
92
|
+
this.startAngle = 0;
|
93
|
+
this.targetRotation = 0;
|
94
|
+
this.maximumDistFromStart = 0;
|
95
|
+
}
|
96
|
+
getAngle(canvasPoint) {
|
97
|
+
const selectionCenter = this.selection.preTransformRegion.center;
|
98
|
+
const offset = canvasPoint.minus(selectionCenter);
|
99
|
+
return offset.angle();
|
100
|
+
}
|
101
|
+
roundAngle(angle) {
|
102
|
+
// Round angles to the nearest 16th of a turn
|
103
|
+
const roundingFactor = 16 / 2 / Math.PI;
|
104
|
+
return Math.round(angle * roundingFactor) / roundingFactor;
|
105
|
+
}
|
106
|
+
onDragStart(startPoint) {
|
107
|
+
this.startPoint = startPoint;
|
108
|
+
this.selection.setTransform(Mat33.identity);
|
109
|
+
this.startAngle = this.getAngle(startPoint);
|
110
|
+
this.targetRotation = 0;
|
111
|
+
// Used to determine whether the user clicked or not.
|
112
|
+
this.maximumDistFromStart = 0;
|
113
|
+
this.startTime = performance.now();
|
114
|
+
}
|
115
|
+
setRotationTo(angle) {
|
116
|
+
// Transform in canvas space
|
117
|
+
const canvasSelCenter = this.editor.viewport.roundPoint(this.selection.preTransformRegion.center);
|
118
|
+
const unrounded = Mat33.zRotation(angle);
|
119
|
+
const roundedRotationTransform = unrounded.mapEntries(entry => Viewport.roundScaleRatio(entry));
|
120
|
+
const fullRoundedTransform = Mat33
|
121
|
+
.translation(canvasSelCenter)
|
122
|
+
.rightMul(roundedRotationTransform)
|
123
|
+
.rightMul(Mat33.translation(canvasSelCenter.times(-1)));
|
124
|
+
this.selection.setTransform(fullRoundedTransform);
|
125
|
+
}
|
126
|
+
onDragUpdate(canvasPos) {
|
127
|
+
this.targetRotation = this.roundAngle(this.getAngle(canvasPos) - this.startAngle);
|
128
|
+
this.setRotationTo(this.targetRotation);
|
129
|
+
const distFromStart = canvasPos.minus(this.startPoint).magnitude();
|
130
|
+
if (distFromStart > this.maximumDistFromStart) {
|
131
|
+
this.maximumDistFromStart = distFromStart;
|
132
|
+
}
|
133
|
+
}
|
134
|
+
onDragEnd() {
|
135
|
+
// Anything with motion less than this is considered a click
|
136
|
+
const clickThresholdDist = 10;
|
137
|
+
const clickThresholdTime = 0.4; // s
|
138
|
+
const dragTimeSeconds = (performance.now() - this.startTime) / 1000;
|
139
|
+
if (dragTimeSeconds < clickThresholdTime
|
140
|
+
&& this.maximumDistFromStart < clickThresholdDist
|
141
|
+
&& this.targetRotation === 0) {
|
142
|
+
this.setRotationTo(-Math.PI / 2);
|
143
|
+
}
|
144
|
+
return this.selection.finalizeTransform();
|
145
|
+
}
|
146
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
export declare const selectAllKeyboardShortcut = "jsdraw.tools.SelectionTool.selectAll";
|
2
|
+
export declare const duplicateSelectionShortcut = "jsdraw.tools.SelectionTool.duplicateSelection";
|
3
|
+
export declare const sendToBackSelectionShortcut = "jsdraw.tools.SelectionTool.sendToBack";
|
4
|
+
export declare const translateLeftSelectionShortcutId = "jsdraw.tools.SelectionTool.translateLeft";
|
5
|
+
export declare const translateRightSelectionShortcutId = "jsdraw.tools.SelectionTool.translateRight";
|
6
|
+
export declare const translateUpSelectionShortcutId = "jsdraw.tools.SelectionTool.translateUp";
|
7
|
+
export declare const translateDownSelectionShortcutId = "jsdraw.tools.SelectionTool.translateDown";
|
8
|
+
export declare const rotateCounterClockwiseSelectionShortcutId = "jsdraw.tools.SelectionTool.rotateCCW";
|
9
|
+
export declare const rotateClockwiseSelectionShortcutId = "jsdraw.tools.SelectionTool.rotateCW";
|
10
|
+
export declare const shrinkXSelectionShortcutId = "jsdraw.tools.SelectionTool.shrink.x";
|
11
|
+
export declare const stretchXSelectionShortcutId = "jsdraw.tools.SelectionTool.stretch.x";
|
12
|
+
export declare const shrinkYSelectionShortcutId = "jsdraw.tools.SelectionTool.shrink.y";
|
13
|
+
export declare const stretchYSelectionShortcutId = "jsdraw.tools.SelectionTool.stretch.y";
|
14
|
+
export declare const shrinkXYSelectionShortcutId = "jsdraw.tools.SelectionTool.shrink.xy";
|
15
|
+
export declare const stretchXYSelectionShortcutId = "jsdraw.tools.SelectionTool.stretch.xy";
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import KeyboardShortcutManager from '../../shortcuts/KeyboardShortcutManager.mjs';
|
2
|
+
// Selection
|
3
|
+
export const selectAllKeyboardShortcut = 'jsdraw.tools.SelectionTool.selectAll';
|
4
|
+
KeyboardShortcutManager.registerDefaultKeyboardShortcut(selectAllKeyboardShortcut, ['CtrlOrMeta+KeyA'], 'Select all');
|
5
|
+
export const duplicateSelectionShortcut = 'jsdraw.tools.SelectionTool.duplicateSelection';
|
6
|
+
KeyboardShortcutManager.registerDefaultKeyboardShortcut(duplicateSelectionShortcut, ['CtrlOrMeta+KeyD'], 'Duplicate selection');
|
7
|
+
export const sendToBackSelectionShortcut = 'jsdraw.tools.SelectionTool.sendToBack';
|
8
|
+
KeyboardShortcutManager.registerDefaultKeyboardShortcut(sendToBackSelectionShortcut, ['End'], 'Send to back');
|
9
|
+
export const translateLeftSelectionShortcutId = 'jsdraw.tools.SelectionTool.translateLeft';
|
10
|
+
KeyboardShortcutManager.registerDefaultKeyboardShortcut(translateLeftSelectionShortcutId, ['KeyA', 'KeyH', 'ArrowLeft'], 'Move selection left');
|
11
|
+
export const translateRightSelectionShortcutId = 'jsdraw.tools.SelectionTool.translateRight';
|
12
|
+
KeyboardShortcutManager.registerDefaultKeyboardShortcut(translateRightSelectionShortcutId, ['KeyD', 'KeyL', 'ArrowRight'], 'Move selection right');
|
13
|
+
export const translateUpSelectionShortcutId = 'jsdraw.tools.SelectionTool.translateUp';
|
14
|
+
KeyboardShortcutManager.registerDefaultKeyboardShortcut(translateUpSelectionShortcutId, ['KeyQ', 'KeyK', 'ArrowUp'], 'Move selection up');
|
15
|
+
export const translateDownSelectionShortcutId = 'jsdraw.tools.SelectionTool.translateDown';
|
16
|
+
KeyboardShortcutManager.registerDefaultKeyboardShortcut(translateDownSelectionShortcutId, ['KeyE', 'KeyJ', 'ArrowDown'], 'Move selection down');
|
17
|
+
export const rotateCounterClockwiseSelectionShortcutId = 'jsdraw.tools.SelectionTool.rotateCCW';
|
18
|
+
KeyboardShortcutManager.registerDefaultKeyboardShortcut(rotateCounterClockwiseSelectionShortcutId, ['Shift+KeyR'], 'Rotate selection counter clockwise');
|
19
|
+
export const rotateClockwiseSelectionShortcutId = 'jsdraw.tools.SelectionTool.rotateCW';
|
20
|
+
KeyboardShortcutManager.registerDefaultKeyboardShortcut(rotateClockwiseSelectionShortcutId, ['KeyR'], 'Rotate selection clockwise');
|
21
|
+
export const shrinkXSelectionShortcutId = 'jsdraw.tools.SelectionTool.shrink.x';
|
22
|
+
KeyboardShortcutManager.registerDefaultKeyboardShortcut(shrinkXSelectionShortcutId, ['KeyI'], 'Decrease width');
|
23
|
+
export const stretchXSelectionShortcutId = 'jsdraw.tools.SelectionTool.stretch.x';
|
24
|
+
KeyboardShortcutManager.registerDefaultKeyboardShortcut(stretchXSelectionShortcutId, ['Shift+KeyI'], 'Increase width');
|
25
|
+
export const shrinkYSelectionShortcutId = 'jsdraw.tools.SelectionTool.shrink.y';
|
26
|
+
KeyboardShortcutManager.registerDefaultKeyboardShortcut(shrinkYSelectionShortcutId, ['KeyO'], 'Decrease height');
|
27
|
+
export const stretchYSelectionShortcutId = 'jsdraw.tools.SelectionTool.stretch.y';
|
28
|
+
KeyboardShortcutManager.registerDefaultKeyboardShortcut(stretchYSelectionShortcutId, ['Shift+KeyO'], 'Increase height');
|
29
|
+
export const shrinkXYSelectionShortcutId = 'jsdraw.tools.SelectionTool.shrink.xy';
|
30
|
+
KeyboardShortcutManager.registerDefaultKeyboardShortcut(shrinkXYSelectionShortcutId, ['Comma'], 'Decrease selection size');
|
31
|
+
export const stretchXYSelectionShortcutId = 'jsdraw.tools.SelectionTool.stretch.xy';
|
32
|
+
KeyboardShortcutManager.registerDefaultKeyboardShortcut(stretchXYSelectionShortcutId, ['Period'], 'Increase selection size');
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import type { Rect2, Point2 } from '@js-draw/math';
|
2
|
+
import Pointer from '../../Pointer';
|
3
|
+
export declare enum ResizeMode {
|
4
|
+
Both = 0,
|
5
|
+
HorizontalOnly = 1,
|
6
|
+
VerticalOnly = 2
|
7
|
+
}
|
8
|
+
export declare enum TransformMode {
|
9
|
+
Snap = 0,
|
10
|
+
NoSnap = 1
|
11
|
+
}
|
12
|
+
/**
|
13
|
+
* Represents a child of the selection that should move with the selection
|
14
|
+
* and handle events.
|
15
|
+
*
|
16
|
+
* Although selection children should be `HTMLElement`s, the selection may be
|
17
|
+
* hidden behind an invisible element. As such, these elements should handle
|
18
|
+
* drag start/update/end events.
|
19
|
+
*/
|
20
|
+
export interface SelectionBoxChild {
|
21
|
+
/**
|
22
|
+
* Update the position of this child, based on the screen position of
|
23
|
+
* the selection box.
|
24
|
+
*/
|
25
|
+
updatePosition(selectionScreenBBox: Rect2): void;
|
26
|
+
/** @returns true iff `point` (in editor **canvas** coordinates) is in this child. */
|
27
|
+
containsPoint(point: Point2): boolean;
|
28
|
+
/** Adds this component's HTMLElement to the given `container`. */
|
29
|
+
addTo(container: HTMLElement): void;
|
30
|
+
/** Removes this from its parent container. */
|
31
|
+
remove(): void;
|
32
|
+
handleDragStart(pointer: Pointer): boolean;
|
33
|
+
handleDragUpdate(pointer: Pointer): void;
|
34
|
+
handleDragEnd(): void;
|
35
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
export var ResizeMode;
|
2
|
+
(function (ResizeMode) {
|
3
|
+
ResizeMode[ResizeMode["Both"] = 0] = "Both";
|
4
|
+
ResizeMode[ResizeMode["HorizontalOnly"] = 1] = "HorizontalOnly";
|
5
|
+
ResizeMode[ResizeMode["VerticalOnly"] = 2] = "VerticalOnly";
|
6
|
+
})(ResizeMode || (ResizeMode = {}));
|
7
|
+
export var TransformMode;
|
8
|
+
(function (TransformMode) {
|
9
|
+
TransformMode[TransformMode["Snap"] = 0] = "Snap";
|
10
|
+
TransformMode[TransformMode["NoSnap"] = 1] = "NoSnap";
|
11
|
+
})(TransformMode || (TransformMode = {}));
|
@@ -0,0 +1,45 @@
|
|
1
|
+
import makeMessageDialog from '../../../dialogs/makeMessageDialog.mjs';
|
2
|
+
import ClipboardHandler from '../../../util/ClipboardHandler.mjs';
|
3
|
+
const makeClipboardErrorHandlers = (editor) => {
|
4
|
+
const makeErrorDialog = (error) => {
|
5
|
+
const dialog = makeMessageDialog(editor, {
|
6
|
+
title: editor.localization.copyPasteError__heading,
|
7
|
+
classNames: ['clipboard-error-dialog']
|
8
|
+
});
|
9
|
+
dialog.appendChild(document.createTextNode(editor.localization.copyPasteError__description));
|
10
|
+
const errorDetailsElement = document.createElement('details');
|
11
|
+
const errorDetailsSummary = document.createElement('summary');
|
12
|
+
errorDetailsSummary.textContent = editor.localization.copyPasteError__errorDetails;
|
13
|
+
errorDetailsElement.appendChild(errorDetailsSummary);
|
14
|
+
errorDetailsElement.appendChild(document.createTextNode(`Error: ${error}`));
|
15
|
+
dialog.appendChild(errorDetailsElement);
|
16
|
+
return dialog;
|
17
|
+
};
|
18
|
+
return {
|
19
|
+
async onCopyError(error) {
|
20
|
+
makeErrorDialog(error);
|
21
|
+
},
|
22
|
+
onPasteError(error) {
|
23
|
+
const dialog = makeErrorDialog(error);
|
24
|
+
const textboxLabel = document.createElement('label');
|
25
|
+
textboxLabel.textContent = editor.localization.copyPasteError__pasteRetry;
|
26
|
+
const pasteTextbox = document.createElement('textarea');
|
27
|
+
textboxLabel.appendChild(pasteTextbox);
|
28
|
+
const retryHandler = new ClipboardHandler(editor);
|
29
|
+
const handlePaste = (event) => {
|
30
|
+
event.preventDefault();
|
31
|
+
// Use .then to ensure that .paste runs within the event handler.
|
32
|
+
// Paste can fail if certain logic is run async.
|
33
|
+
return retryHandler.paste(event).then((pasted) => {
|
34
|
+
if (pasted) {
|
35
|
+
dialog.close();
|
36
|
+
}
|
37
|
+
});
|
38
|
+
};
|
39
|
+
pasteTextbox.onpaste = handlePaste;
|
40
|
+
pasteTextbox.ondrop = handlePaste;
|
41
|
+
dialog.appendChild(textboxLabel);
|
42
|
+
},
|
43
|
+
};
|
44
|
+
};
|
45
|
+
export default makeClipboardErrorHandlers;
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import { Point2 } from '@js-draw/math';
|
2
|
+
import Editor from '../../../Editor';
|
3
|
+
import Selection from '../Selection';
|
4
|
+
declare const showSelectionContextMenu: (selectionBox: Selection | null, editor: Editor, canvasAnchor: Point2, preferSelectionMenu: boolean, clearSelection: () => void) => Promise<void>;
|
5
|
+
export default showSelectionContextMenu;
|
@@ -0,0 +1,38 @@
|
|
1
|
+
import createMenuOverlay from '../../util/createMenuOverlay.mjs';
|
2
|
+
import ClipboardHandler from '../../../util/ClipboardHandler.mjs';
|
3
|
+
import makeClipboardErrorHandlers from './makeClipboardErrorHandlers.mjs';
|
4
|
+
const showSelectionContextMenu = async (selectionBox, editor, canvasAnchor, preferSelectionMenu, clearSelection) => {
|
5
|
+
const localization = editor.localization;
|
6
|
+
const showSelectionMenu = selectionBox?.getSelectedItemCount() && preferSelectionMenu;
|
7
|
+
const noSelectionMenu = [{
|
8
|
+
text: localization.selectionMenu__paste,
|
9
|
+
icon: () => editor.icons.makePasteIcon(),
|
10
|
+
key: () => {
|
11
|
+
const clipboardHandler = new ClipboardHandler(editor, makeClipboardErrorHandlers(editor));
|
12
|
+
void clipboardHandler.paste();
|
13
|
+
},
|
14
|
+
}];
|
15
|
+
const onActivated = await createMenuOverlay(editor, canvasAnchor, showSelectionMenu ? [{
|
16
|
+
text: localization.selectionMenu__duplicate,
|
17
|
+
icon: () => editor.icons.makeDuplicateSelectionIcon(),
|
18
|
+
key: async () => {
|
19
|
+
await editor.dispatch(await selectionBox.duplicateSelectedObjects());
|
20
|
+
},
|
21
|
+
}, {
|
22
|
+
text: localization.selectionMenu__delete,
|
23
|
+
icon: () => editor.icons.makeDeleteSelectionIcon(),
|
24
|
+
key: async () => {
|
25
|
+
await editor.dispatch(selectionBox.deleteSelectedObjects());
|
26
|
+
clearSelection();
|
27
|
+
},
|
28
|
+
}, {
|
29
|
+
text: localization.selectionMenu__copyToClipboard,
|
30
|
+
icon: () => editor.icons.makeCopyIcon(),
|
31
|
+
key: () => {
|
32
|
+
const clipboardHandler = new ClipboardHandler(editor, makeClipboardErrorHandlers(editor));
|
33
|
+
void clipboardHandler.copy();
|
34
|
+
},
|
35
|
+
}, ...noSelectionMenu] : noSelectionMenu);
|
36
|
+
onActivated?.();
|
37
|
+
};
|
38
|
+
export default showSelectionContextMenu;
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import Editor from '../Editor';
|
2
|
+
import { KeyPressEvent, PointerEvt } from '../inputEvents';
|
3
|
+
import BaseTool from './BaseTool';
|
4
|
+
/**
|
5
|
+
* This tool, when enabled, plays a sound representing the color of the portion of the display
|
6
|
+
* currently under the cursor. This tool adds a button that can be navigated to with the tab key
|
7
|
+
* that enables/disables the tool.
|
8
|
+
*
|
9
|
+
* This allows the user to explore the content of the display without a working screen.
|
10
|
+
*/
|
11
|
+
export default class SoundUITool extends BaseTool {
|
12
|
+
private editor;
|
13
|
+
private soundFeedback;
|
14
|
+
private toggleButton;
|
15
|
+
private toggleButtonContainer;
|
16
|
+
constructor(editor: Editor, description: string);
|
17
|
+
canReceiveInputInReadOnlyEditor(): boolean;
|
18
|
+
private updateToggleButtonText;
|
19
|
+
setEnabled(enabled: boolean): void;
|
20
|
+
onKeyPress(event: KeyPressEvent): boolean;
|
21
|
+
private lastPointerPos;
|
22
|
+
onPointerDown({ current, allPointers }: PointerEvt): boolean;
|
23
|
+
onPointerMove({ current }: PointerEvt): void;
|
24
|
+
onPointerUp(_event: PointerEvt): void;
|
25
|
+
onGestureCancel(): void;
|
26
|
+
}
|
@@ -0,0 +1,165 @@
|
|
1
|
+
import { LineSegment2, Color4 } from '@js-draw/math';
|
2
|
+
import BaseTool from './BaseTool.mjs';
|
3
|
+
class SoundFeedback {
|
4
|
+
constructor() {
|
5
|
+
this.closed = false;
|
6
|
+
// No AudioContext? Exit!
|
7
|
+
if (!window.AudioContext) {
|
8
|
+
console.warn('Accessibility sound UI: Unable to open AudioContext.');
|
9
|
+
this.closed = true;
|
10
|
+
return;
|
11
|
+
}
|
12
|
+
this.ctx = new AudioContext();
|
13
|
+
// Color oscillator and gain
|
14
|
+
this.colorOscHue = this.ctx.createOscillator();
|
15
|
+
this.colorOscValue = this.ctx.createOscillator();
|
16
|
+
this.colorOscSaturation = this.ctx.createOscillator();
|
17
|
+
this.colorOscHue.type = 'triangle';
|
18
|
+
this.colorOscSaturation.type = 'sine';
|
19
|
+
this.colorOscValue.type = 'sawtooth';
|
20
|
+
this.valueGain = this.ctx.createGain();
|
21
|
+
this.colorOscValue.connect(this.valueGain);
|
22
|
+
this.valueGain.gain.setValueAtTime(0.18, this.ctx.currentTime);
|
23
|
+
this.colorGain = this.ctx.createGain();
|
24
|
+
this.colorOscHue.connect(this.colorGain);
|
25
|
+
this.valueGain.connect(this.colorGain);
|
26
|
+
this.colorOscSaturation.connect(this.colorGain);
|
27
|
+
this.colorGain.connect(this.ctx.destination);
|
28
|
+
// Boundary oscillator and gain
|
29
|
+
this.boundaryGain = this.ctx.createGain();
|
30
|
+
this.boundaryOsc = this.ctx.createOscillator();
|
31
|
+
this.boundaryOsc.type = 'sawtooth';
|
32
|
+
this.boundaryGain.gain.setValueAtTime(0, this.ctx.currentTime);
|
33
|
+
this.boundaryOsc.connect(this.boundaryGain);
|
34
|
+
this.boundaryGain.connect(this.ctx.destination);
|
35
|
+
// Prepare for the first announcement/feedback.
|
36
|
+
this.colorOscHue.start();
|
37
|
+
this.colorOscSaturation.start();
|
38
|
+
this.colorOscValue.start();
|
39
|
+
this.boundaryOsc.start();
|
40
|
+
this.pause();
|
41
|
+
}
|
42
|
+
pause() {
|
43
|
+
if (this.closed)
|
44
|
+
return;
|
45
|
+
this.colorGain.gain.setValueAtTime(0, this.ctx.currentTime);
|
46
|
+
void this.ctx.suspend();
|
47
|
+
}
|
48
|
+
play() {
|
49
|
+
if (this.closed)
|
50
|
+
return;
|
51
|
+
void this.ctx.resume();
|
52
|
+
}
|
53
|
+
setColor(color) {
|
54
|
+
const hsv = color.asHSV();
|
55
|
+
// Choose frequencies that roughly correspond to hue, saturation, and value.
|
56
|
+
const hueFrequency = (-Math.cos(hsv.x / 2)) * 220 + 440;
|
57
|
+
const saturationFrequency = hsv.y * 440 + 220;
|
58
|
+
const valueFrequency = (hsv.z + 0.1) * 440;
|
59
|
+
// Sigmoid with maximum 0.25 * alpha.
|
60
|
+
// Louder for greater value.
|
61
|
+
const gain = 0.25 * Math.min(1, color.a) / (1 + Math.exp(-(hsv.z - 0.5) * 3));
|
62
|
+
this.colorOscHue.frequency.setValueAtTime(hueFrequency, this.ctx.currentTime);
|
63
|
+
this.colorOscSaturation.frequency.setValueAtTime(saturationFrequency, this.ctx.currentTime);
|
64
|
+
this.colorOscValue.frequency.setValueAtTime(valueFrequency, this.ctx.currentTime);
|
65
|
+
this.valueGain.gain.setValueAtTime((1 - hsv.z) * 0.4, this.ctx.currentTime);
|
66
|
+
this.colorGain.gain.setValueAtTime(gain, this.ctx.currentTime);
|
67
|
+
}
|
68
|
+
announceBoundaryCross(boundaryCrossCount) {
|
69
|
+
this.boundaryGain.gain.cancelScheduledValues(this.ctx.currentTime);
|
70
|
+
this.boundaryGain.gain.setValueAtTime(0, this.ctx.currentTime);
|
71
|
+
this.boundaryGain.gain.linearRampToValueAtTime(0.018, this.ctx.currentTime + 0.1);
|
72
|
+
this.boundaryOsc.frequency.setValueAtTime(440 + Math.atan(boundaryCrossCount / 2) * 100, this.ctx.currentTime);
|
73
|
+
this.boundaryGain.gain.linearRampToValueAtTime(0, this.ctx.currentTime + 0.25);
|
74
|
+
}
|
75
|
+
close() {
|
76
|
+
this.ctx.close();
|
77
|
+
this.closed = true;
|
78
|
+
}
|
79
|
+
}
|
80
|
+
/**
|
81
|
+
* This tool, when enabled, plays a sound representing the color of the portion of the display
|
82
|
+
* currently under the cursor. This tool adds a button that can be navigated to with the tab key
|
83
|
+
* that enables/disables the tool.
|
84
|
+
*
|
85
|
+
* This allows the user to explore the content of the display without a working screen.
|
86
|
+
*/
|
87
|
+
export default class SoundUITool extends BaseTool {
|
88
|
+
constructor(editor, description) {
|
89
|
+
super(editor.notifier, description);
|
90
|
+
this.editor = editor;
|
91
|
+
this.soundFeedback = null;
|
92
|
+
// Create a screen-reader-usable method of toggling the tool:
|
93
|
+
this.toggleButtonContainer = document.createElement('div');
|
94
|
+
this.toggleButtonContainer.classList.add('js-draw-sound-ui-toggle');
|
95
|
+
this.toggleButton = document.createElement('button');
|
96
|
+
this.toggleButton.onclick = () => {
|
97
|
+
this.setEnabled(!this.isEnabled());
|
98
|
+
};
|
99
|
+
this.toggleButtonContainer.appendChild(this.toggleButton);
|
100
|
+
this.updateToggleButtonText();
|
101
|
+
editor.createHTMLOverlay(this.toggleButtonContainer);
|
102
|
+
}
|
103
|
+
canReceiveInputInReadOnlyEditor() {
|
104
|
+
return true;
|
105
|
+
}
|
106
|
+
updateToggleButtonText() {
|
107
|
+
const containerEnabledClass = 'sound-ui-tool-enabled';
|
108
|
+
if (this.isEnabled()) {
|
109
|
+
this.toggleButton.innerText = this.editor.localization.disableAccessibilityExploreTool;
|
110
|
+
this.toggleButtonContainer.classList.add(containerEnabledClass);
|
111
|
+
}
|
112
|
+
else {
|
113
|
+
this.toggleButton.innerText = this.editor.localization.enableAccessibilityExploreTool;
|
114
|
+
this.toggleButtonContainer.classList.remove(containerEnabledClass);
|
115
|
+
}
|
116
|
+
}
|
117
|
+
setEnabled(enabled) {
|
118
|
+
super.setEnabled(enabled);
|
119
|
+
if (!this.isEnabled()) {
|
120
|
+
this.soundFeedback?.close();
|
121
|
+
this.soundFeedback = null;
|
122
|
+
}
|
123
|
+
else {
|
124
|
+
this.editor.announceForAccessibility(this.editor.localization.soundExplorerUsageAnnouncement);
|
125
|
+
}
|
126
|
+
this.updateToggleButtonText();
|
127
|
+
}
|
128
|
+
onKeyPress(event) {
|
129
|
+
if (event.code === 'Escape') {
|
130
|
+
this.setEnabled(false);
|
131
|
+
return true;
|
132
|
+
}
|
133
|
+
return false;
|
134
|
+
}
|
135
|
+
onPointerDown({ current, allPointers }) {
|
136
|
+
if (!this.soundFeedback) {
|
137
|
+
this.soundFeedback = new SoundFeedback();
|
138
|
+
}
|
139
|
+
// Allow two-finger gestures to move the screen.
|
140
|
+
if (allPointers.length >= 2) {
|
141
|
+
return false;
|
142
|
+
}
|
143
|
+
// Accept multiple cursors -- some screen readers require multiple (touch) pointers to interact with
|
144
|
+
// an image instead of using the built-in navigation features.
|
145
|
+
this.soundFeedback?.play();
|
146
|
+
this.soundFeedback?.setColor(this.editor.display.getColorAt(current.screenPos) ?? Color4.black);
|
147
|
+
this.lastPointerPos = current.canvasPos;
|
148
|
+
return true;
|
149
|
+
}
|
150
|
+
onPointerMove({ current }) {
|
151
|
+
this.soundFeedback?.setColor(this.editor.display.getColorAt(current.screenPos) ?? Color4.black);
|
152
|
+
const pointerMotionLine = new LineSegment2(this.lastPointerPos, current.canvasPos);
|
153
|
+
const collisions = this.editor.image.getElementsIntersectingRegion(pointerMotionLine.bbox).filter(component => component.intersects(pointerMotionLine));
|
154
|
+
this.lastPointerPos = current.canvasPos;
|
155
|
+
if (collisions.length > 0) {
|
156
|
+
this.soundFeedback?.announceBoundaryCross(collisions.length);
|
157
|
+
}
|
158
|
+
}
|
159
|
+
onPointerUp(_event) {
|
160
|
+
this.soundFeedback?.pause();
|
161
|
+
}
|
162
|
+
onGestureCancel() {
|
163
|
+
this.soundFeedback?.pause();
|
164
|
+
}
|
165
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import Editor from '../Editor';
|
2
|
+
import { Color4 } from '@js-draw/math';
|
3
|
+
import { PointerEvt } from '../inputEvents';
|
4
|
+
import BaseTool from './BaseTool';
|
5
|
+
import { ToolLocalization } from './localization';
|
6
|
+
import TextRenderingStyle from '../rendering/TextRenderingStyle';
|
7
|
+
import { MutableReactiveValue } from '../util/ReactiveValue';
|
8
|
+
export default class TextTool extends BaseTool {
|
9
|
+
private editor;
|
10
|
+
private localizationTable;
|
11
|
+
private textStyleValue;
|
12
|
+
private textStyle;
|
13
|
+
private textEditOverlay;
|
14
|
+
private textInputElem;
|
15
|
+
private textTargetPosition;
|
16
|
+
private textMeasuringCtx;
|
17
|
+
private textRotation;
|
18
|
+
private textScale;
|
19
|
+
private removeExistingCommand;
|
20
|
+
constructor(editor: Editor, description: string, localizationTable: ToolLocalization);
|
21
|
+
private initTextMeasuringCanvas;
|
22
|
+
private getTextAscent;
|
23
|
+
private flushInput;
|
24
|
+
private getTextScaleMatrix;
|
25
|
+
private updateTextInput;
|
26
|
+
private startTextInput;
|
27
|
+
setEnabled(enabled: boolean): void;
|
28
|
+
onPointerDown({ current, allPointers }: PointerEvt): boolean;
|
29
|
+
onGestureCancel(): void;
|
30
|
+
setFontFamily(fontFamily: string): void;
|
31
|
+
setColor(color: Color4): void;
|
32
|
+
setFontSize(size: number): void;
|
33
|
+
getTextStyle(): TextRenderingStyle;
|
34
|
+
getStyleValue(): MutableReactiveValue<TextRenderingStyle>;
|
35
|
+
private setTextStyle;
|
36
|
+
}
|