js-draw 0.21.0 → 0.22.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/CHANGELOG.md +16 -1
- package/dist/bundle.js +3 -3
- package/dist/bundledStyles.js +1 -1
- package/dist/cjs/src/Color4.js +2 -2
- package/dist/cjs/src/Editor.d.ts +1 -3
- package/dist/cjs/src/EditorImage.js +8 -2
- package/dist/cjs/src/Viewport.js +1 -1
- package/dist/cjs/src/commands/Command.js +1 -1
- package/dist/cjs/src/commands/SerializableCommand.js +1 -1
- package/dist/cjs/src/commands/uniteCommands.js +5 -0
- package/dist/cjs/src/components/AbstractComponent.js +6 -1
- package/dist/cjs/src/components/ImageComponent.d.ts +6 -6
- package/dist/cjs/src/components/ImageComponent.js +17 -12
- package/dist/cjs/src/components/TextComponent.js +1 -1
- package/dist/cjs/src/localizations/de.js +1 -1
- package/dist/cjs/src/math/Mat33.js +1 -1
- package/dist/cjs/src/math/Path.js +1 -1
- package/dist/cjs/src/math/Rect2.js +1 -1
- package/dist/cjs/src/math/Vec3.js +1 -1
- package/dist/cjs/src/rendering/Display.d.ts +1 -1
- package/dist/cjs/src/rendering/Display.js +1 -2
- package/dist/cjs/src/toolbar/HTMLToolbar.d.ts +2 -0
- package/dist/cjs/src/toolbar/HTMLToolbar.js +71 -12
- package/dist/cjs/src/toolbar/localization.d.ts +1 -0
- package/dist/cjs/src/toolbar/localization.js +1 -0
- package/dist/cjs/src/toolbar/makeColorInput.js +8 -0
- package/dist/cjs/src/toolbar/widgets/BaseToolWidget.d.ts +0 -1
- package/dist/cjs/src/toolbar/widgets/BaseToolWidget.js +0 -1
- package/dist/cjs/src/toolbar/widgets/BaseWidget.d.ts +5 -0
- package/dist/cjs/src/toolbar/widgets/BaseWidget.js +24 -7
- package/dist/cjs/src/toolbar/widgets/DocumentPropertiesWidget.js +1 -1
- package/dist/cjs/src/toolbar/widgets/EraserToolWidget.js +1 -1
- package/dist/cjs/src/toolbar/widgets/InsertImageWidget.js +1 -1
- package/dist/cjs/src/toolbar/widgets/PenToolWidget.js +1 -1
- package/dist/cjs/src/toolbar/widgets/TextToolWidget.js +1 -1
- package/dist/cjs/src/tools/SelectionTool/Selection.js +5 -2
- package/dist/cjs/src/tools/SelectionTool/SelectionTool.js +1 -1
- package/dist/cjs/src/types.d.ts +2 -0
- package/dist/mjs/src/Color4.mjs +2 -1
- package/dist/mjs/src/Editor.d.ts +1 -3
- package/dist/mjs/src/EditorImage.mjs +10 -2
- package/dist/mjs/src/Viewport.mjs +2 -1
- package/dist/mjs/src/commands/Command.mjs +2 -1
- package/dist/mjs/src/commands/SerializableCommand.mjs +2 -1
- package/dist/mjs/src/commands/uniteCommands.mjs +5 -0
- package/dist/mjs/src/components/AbstractComponent.mjs +7 -1
- package/dist/mjs/src/components/ImageComponent.d.ts +6 -6
- package/dist/mjs/src/components/ImageComponent.mjs +17 -12
- package/dist/mjs/src/components/TextComponent.mjs +2 -1
- package/dist/mjs/src/localizations/de.mjs +1 -1
- package/dist/mjs/src/math/Mat33.mjs +2 -1
- package/dist/mjs/src/math/Path.mjs +2 -1
- package/dist/mjs/src/math/Rect2.mjs +2 -1
- package/dist/mjs/src/math/Vec3.mjs +2 -1
- package/dist/mjs/src/rendering/Display.d.ts +1 -1
- package/dist/mjs/src/rendering/Display.mjs +1 -2
- package/dist/mjs/src/toolbar/HTMLToolbar.d.ts +2 -0
- package/dist/mjs/src/toolbar/HTMLToolbar.mjs +72 -12
- package/dist/mjs/src/toolbar/localization.d.ts +1 -0
- package/dist/mjs/src/toolbar/localization.mjs +1 -0
- package/dist/mjs/src/toolbar/makeColorInput.mjs +8 -0
- package/dist/mjs/src/toolbar/widgets/BaseToolWidget.d.ts +0 -1
- package/dist/mjs/src/toolbar/widgets/BaseToolWidget.mjs +0 -1
- package/dist/mjs/src/toolbar/widgets/BaseWidget.d.ts +5 -0
- package/dist/mjs/src/toolbar/widgets/BaseWidget.mjs +24 -7
- package/dist/mjs/src/toolbar/widgets/DocumentPropertiesWidget.mjs +2 -1
- package/dist/mjs/src/toolbar/widgets/EraserToolWidget.mjs +2 -1
- package/dist/mjs/src/toolbar/widgets/InsertImageWidget.mjs +2 -1
- package/dist/mjs/src/toolbar/widgets/PenToolWidget.mjs +2 -1
- package/dist/mjs/src/toolbar/widgets/TextToolWidget.mjs +2 -1
- package/dist/mjs/src/tools/SelectionTool/Selection.mjs +6 -2
- package/dist/mjs/src/tools/SelectionTool/SelectionTool.mjs +2 -1
- package/dist/mjs/src/types.d.ts +2 -0
- package/package.json +13 -13
- package/src/toolbar/toolbar.css +7 -0
- package/tsconfig-typedoc.json +7 -0
- package/tsconfig.json +2 -0
- package/typedoc.json +1 -0
@@ -16,8 +16,9 @@ import ActionButtonWidget from './widgets/ActionButtonWidget.mjs';
|
|
16
16
|
import InsertImageWidget from './widgets/InsertImageWidget.mjs';
|
17
17
|
import DocumentPropertiesWidget from './widgets/DocumentPropertiesWidget.mjs';
|
18
18
|
import OverflowWidget from './widgets/OverflowWidget.mjs';
|
19
|
+
import { Vec2 } from '../math/Vec2.mjs';
|
19
20
|
export const toolbarCSSPrefix = 'toolbar-';
|
20
|
-
|
21
|
+
class HTMLToolbar {
|
21
22
|
/** @internal */
|
22
23
|
constructor(editor, parent, localizationTable = defaultToolbarLocalization) {
|
23
24
|
this.editor = editor;
|
@@ -30,6 +31,7 @@ export default class HTMLToolbar {
|
|
30
31
|
// Widget to toggle overflow menu.
|
31
32
|
this.overflowWidget = null;
|
32
33
|
this.updateColoris = null;
|
34
|
+
this.closeColorPickerOverlay = null;
|
33
35
|
this.reLayoutQueued = false;
|
34
36
|
this.container = document.createElement('div');
|
35
37
|
this.container.classList.add(`${toolbarCSSPrefix}root`);
|
@@ -50,6 +52,68 @@ export default class HTMLToolbar {
|
|
50
52
|
console.warn('ResizeObserver not supported. Toolbar will not resize.');
|
51
53
|
}
|
52
54
|
}
|
55
|
+
setupCloseColorPickerOverlay() {
|
56
|
+
if (this.closeColorPickerOverlay)
|
57
|
+
return;
|
58
|
+
this.closeColorPickerOverlay = document.createElement('div');
|
59
|
+
this.closeColorPickerOverlay.className = `${toolbarCSSPrefix}closeColorPickerOverlay`;
|
60
|
+
this.editor.createHTMLOverlay(this.closeColorPickerOverlay);
|
61
|
+
// Buffer events: Send events to the editor only if the pointer has moved enough to
|
62
|
+
// suggest that the user is attempting to draw, rather than click to close the color picker.
|
63
|
+
let eventBuffer = [];
|
64
|
+
let gestureStartPos = null;
|
65
|
+
// Hide the color picker when attempting to draw on the overlay.
|
66
|
+
this.listeners.push(this.editor.handlePointerEventsFrom(this.closeColorPickerOverlay, (eventName, event) => {
|
67
|
+
var _a, _b;
|
68
|
+
// Position of the current event.
|
69
|
+
const currentPos = Vec2.of(event.pageX, event.pageY);
|
70
|
+
// Whether to send the current event to the editor
|
71
|
+
let sendToEditor = true;
|
72
|
+
if (eventName === 'pointerdown') {
|
73
|
+
closeColoris();
|
74
|
+
// Buffer the event, but don't send it to the editor yet.
|
75
|
+
// We don't want to send single-click events, but we do want to send full strokes.
|
76
|
+
eventBuffer = [];
|
77
|
+
eventBuffer.push([eventName, event]);
|
78
|
+
gestureStartPos = currentPos;
|
79
|
+
// Capture the pointer so we receive future events even if the overlay is hidden.
|
80
|
+
(_a = this.closeColorPickerOverlay) === null || _a === void 0 ? void 0 : _a.setPointerCapture(event.pointerId);
|
81
|
+
// Don't send to the editor.
|
82
|
+
sendToEditor = false;
|
83
|
+
}
|
84
|
+
else if (eventName === 'pointermove') {
|
85
|
+
// Skip if the pointer hasn't moved enough to not be a "click".
|
86
|
+
const strokeStartThreshold = 10;
|
87
|
+
if (gestureStartPos && currentPos.minus(gestureStartPos).magnitude() < strokeStartThreshold) {
|
88
|
+
eventBuffer.push([eventName, event]);
|
89
|
+
sendToEditor = false;
|
90
|
+
}
|
91
|
+
else {
|
92
|
+
// Send all buffered events to the editor -- start the stroke.
|
93
|
+
for (const [eventName, event] of eventBuffer) {
|
94
|
+
this.editor.handleHTMLPointerEvent(eventName, event);
|
95
|
+
}
|
96
|
+
eventBuffer = [];
|
97
|
+
sendToEditor = true;
|
98
|
+
}
|
99
|
+
}
|
100
|
+
// Otherwise, if we received a pointerup/pointercancel without flushing all pointerevents from the
|
101
|
+
// buffer, the gesture wasn't recognised as a stroke. Thus, the editor isn't expecting a pointerup/
|
102
|
+
// pointercancel event.
|
103
|
+
else if ((eventName === 'pointerup' || eventName === 'pointercancel') && eventBuffer.length > 0) {
|
104
|
+
(_b = this.closeColorPickerOverlay) === null || _b === void 0 ? void 0 : _b.releasePointerCapture(event.pointerId);
|
105
|
+
eventBuffer = [];
|
106
|
+
// Don't send to the editor.
|
107
|
+
sendToEditor = false;
|
108
|
+
}
|
109
|
+
// Transfer focus to the editor to allow keyboard events to be handled.
|
110
|
+
if (eventName === 'pointerup') {
|
111
|
+
this.editor.focus();
|
112
|
+
}
|
113
|
+
// Forward all other events to the editor.
|
114
|
+
return sendToEditor;
|
115
|
+
}));
|
116
|
+
}
|
53
117
|
// @internal
|
54
118
|
setupColorPickers() {
|
55
119
|
// Much of the setup only needs to be done once.
|
@@ -57,16 +121,7 @@ export default class HTMLToolbar {
|
|
57
121
|
this.updateColoris();
|
58
122
|
return;
|
59
123
|
}
|
60
|
-
|
61
|
-
closePickerOverlay.className = `${toolbarCSSPrefix}closeColorPickerOverlay`;
|
62
|
-
this.editor.createHTMLOverlay(closePickerOverlay);
|
63
|
-
// Hide the color picker when attempting to draw on the overlay.
|
64
|
-
this.listeners.push(this.editor.handlePointerEventsFrom(closePickerOverlay, (eventName) => {
|
65
|
-
if (eventName === 'pointerdown') {
|
66
|
-
closeColoris();
|
67
|
-
}
|
68
|
-
return true;
|
69
|
-
}));
|
124
|
+
this.setupCloseColorPickerOverlay();
|
70
125
|
const maxSwatchLen = 12;
|
71
126
|
const swatches = [
|
72
127
|
Color4.red.toHexString(),
|
@@ -111,7 +166,9 @@ export default class HTMLToolbar {
|
|
111
166
|
}
|
112
167
|
// Show/hide the overlay. Making the overlay visible gives users a surface to click
|
113
168
|
// on that shows/hides the color picker.
|
114
|
-
|
169
|
+
if (this.closeColorPickerOverlay) {
|
170
|
+
this.closeColorPickerOverlay.style.display = event.open ? 'block' : 'none';
|
171
|
+
}
|
115
172
|
}));
|
116
173
|
// Add newly-selected colors to the swatch.
|
117
174
|
this.listeners.push(this.editor.notifier.on(EditorEventType.ColorPickerColorSelected, event => {
|
@@ -373,11 +430,14 @@ export default class HTMLToolbar {
|
|
373
430
|
this.addDefaultActionButtons();
|
374
431
|
}
|
375
432
|
remove() {
|
433
|
+
var _a;
|
376
434
|
this.container.remove();
|
377
435
|
this.resizeObserver.disconnect();
|
436
|
+
(_a = this.closeColorPickerOverlay) === null || _a === void 0 ? void 0 : _a.remove();
|
378
437
|
for (const listener of this.listeners) {
|
379
438
|
listener.remove();
|
380
439
|
}
|
381
440
|
}
|
382
441
|
}
|
383
442
|
HTMLToolbar.colorisStarted = false;
|
443
|
+
export default HTMLToolbar;
|
@@ -23,6 +23,7 @@ export const defaultToolbarLocalization = {
|
|
23
23
|
selectPenType: 'Pen type: ',
|
24
24
|
pickColorFromScreen: 'Pick color from screen',
|
25
25
|
clickToPickColorAnnouncement: 'Click on the screen to pick a color',
|
26
|
+
colorSelectionCanceledAnnouncement: 'Color selection canceled',
|
26
27
|
selectionToolKeyboardShortcuts: 'Selection tool: Use arrow keys to move selected items, lowercase/uppercase ‘i’ and ‘o’ to resize.',
|
27
28
|
documentProperties: 'Page',
|
28
29
|
backgroundColor: 'Background Color: ',
|
@@ -42,6 +42,11 @@ export const makeColorInput = (editor, onColorChange) => {
|
|
42
42
|
open: true,
|
43
43
|
});
|
44
44
|
pipetteController.cancel();
|
45
|
+
// Focus the Coloris color picker, if it exists.
|
46
|
+
// Don't focus the text input within the color picker, however,
|
47
|
+
// as this displays a keyboard on mobile devices.
|
48
|
+
const colorPickerElem = document.querySelector('#clr-picker #clr-hue-slider');
|
49
|
+
colorPickerElem === null || colorPickerElem === void 0 ? void 0 : colorPickerElem.focus();
|
45
50
|
});
|
46
51
|
colorInput.addEventListener('close', () => {
|
47
52
|
editor.notifier.dispatch(EditorEventType.ColorPickerToggled, {
|
@@ -49,6 +54,8 @@ export const makeColorInput = (editor, onColorChange) => {
|
|
49
54
|
open: false,
|
50
55
|
});
|
51
56
|
onInputEnd();
|
57
|
+
// Restore focus to the input that opened the color picker
|
58
|
+
colorInput.focus();
|
52
59
|
});
|
53
60
|
const setColorInputValue = (color) => {
|
54
61
|
if (typeof color === 'object') {
|
@@ -94,6 +101,7 @@ const addPipetteTool = (editor, container, onColorChange) => {
|
|
94
101
|
// If already picking, cancel it.
|
95
102
|
if (pipetteButton.classList.contains('active')) {
|
96
103
|
endColorSelectMode();
|
104
|
+
editor.announceForAccessibility(editor.localization.colorSelectionCanceledAnnouncement);
|
97
105
|
return;
|
98
106
|
}
|
99
107
|
pipetteTool === null || pipetteTool === void 0 ? void 0 : pipetteTool.setColorListener(pipetteColorPreview, pipetteColorSelect);
|
@@ -3,7 +3,6 @@ import BaseTool from '../../tools/BaseTool';
|
|
3
3
|
import { ToolbarLocalization } from '../localization';
|
4
4
|
import BaseWidget from './BaseWidget';
|
5
5
|
export default abstract class BaseToolWidget extends BaseWidget {
|
6
|
-
protected editor: Editor;
|
7
6
|
protected targetTool: BaseTool;
|
8
7
|
constructor(editor: Editor, targetTool: BaseTool, id: string, localizationTable?: ToolbarLocalization);
|
9
8
|
protected handleClick(): void;
|
@@ -3,7 +3,6 @@ import BaseWidget from './BaseWidget.mjs';
|
|
3
3
|
export default class BaseToolWidget extends BaseWidget {
|
4
4
|
constructor(editor, targetTool, id, localizationTable) {
|
5
5
|
super(editor, id, localizationTable);
|
6
|
-
this.editor = editor;
|
7
6
|
this.targetTool = targetTool;
|
8
7
|
editor.notifier.on(EditorEventType.ToolEnabled, toolEvt => {
|
9
8
|
if (toolEvt.kind !== EditorEventType.ToolEnabled) {
|
@@ -37,6 +37,11 @@ export default abstract class BaseWidget {
|
|
37
37
|
protected get hasDropdown(): boolean;
|
38
38
|
protected addSubWidget(widget: BaseWidget): void;
|
39
39
|
private toolbarWidgetToggleListener;
|
40
|
+
/**
|
41
|
+
* Adds this to `parent`. This can only be called once for each ToolbarWidget.
|
42
|
+
* Returns the element that was just added to `parent`.
|
43
|
+
* @internal
|
44
|
+
*/
|
40
45
|
addTo(parent: HTMLElement): HTMLElement;
|
41
46
|
protected updateIcon(): void;
|
42
47
|
setDisabled(disabled: boolean): void;
|
@@ -135,14 +135,26 @@ export default class BaseWidget {
|
|
135
135
|
const id = widget.getUniqueIdIn(this.subWidgets);
|
136
136
|
this.subWidgets[id] = widget;
|
137
137
|
}
|
138
|
-
|
139
|
-
|
140
|
-
|
138
|
+
/**
|
139
|
+
* Adds this to `parent`. This can only be called once for each ToolbarWidget.
|
140
|
+
* Returns the element that was just added to `parent`.
|
141
|
+
* @internal
|
142
|
+
*/
|
141
143
|
addTo(parent) {
|
142
|
-
|
143
|
-
this.setupActionBtnClickListener(this.button);
|
144
|
+
// Update title and icon
|
144
145
|
this.icon = null;
|
145
146
|
this.updateIcon();
|
147
|
+
this.label.innerText = this.getTitle();
|
148
|
+
const longLabelCSSClass = 'long-label';
|
149
|
+
if (this.label.innerText.length > 7) {
|
150
|
+
this.label.classList.add(longLabelCSSClass);
|
151
|
+
}
|
152
|
+
else {
|
153
|
+
this.label.classList.remove(longLabelCSSClass);
|
154
|
+
}
|
155
|
+
// Click functionality
|
156
|
+
this.setupActionBtnClickListener(this.button);
|
157
|
+
// Clear anything already in this.container.
|
146
158
|
this.container.replaceChildren();
|
147
159
|
this.button.replaceChildren(this.icon, this.label);
|
148
160
|
this.container.appendChild(this.button);
|
@@ -199,13 +211,18 @@ export default class BaseWidget {
|
|
199
211
|
if (currentlySelected === selected) {
|
200
212
|
return;
|
201
213
|
}
|
214
|
+
// Ensure that accessibility tools check and read the value of
|
215
|
+
// aria-checked.
|
216
|
+
// TODO: Ensure that 'role' is set to 'switch' by default for selectable
|
217
|
+
// buttons.
|
218
|
+
this.button.setAttribute('role', 'switch');
|
202
219
|
if (selected) {
|
203
220
|
this.container.classList.add('selected');
|
204
|
-
this.button.
|
221
|
+
this.button.setAttribute('aria-checked', 'true');
|
205
222
|
}
|
206
223
|
else {
|
207
224
|
this.container.classList.remove('selected');
|
208
|
-
this.button.
|
225
|
+
this.button.setAttribute('aria-checked', 'false');
|
209
226
|
}
|
210
227
|
}
|
211
228
|
setDropdownVisible(visible) {
|
@@ -7,7 +7,7 @@ import { EditorEventType } from '../../types.mjs';
|
|
7
7
|
import { toolbarCSSPrefix } from '../HTMLToolbar.mjs';
|
8
8
|
import makeColorInput from '../makeColorInput.mjs';
|
9
9
|
import BaseWidget from './BaseWidget.mjs';
|
10
|
-
|
10
|
+
class DocumentPropertiesWidget extends BaseWidget {
|
11
11
|
constructor(editor, localizationTable) {
|
12
12
|
super(editor, 'document-properties-widget', localizationTable);
|
13
13
|
this.updateDropdownContent = () => { };
|
@@ -170,3 +170,4 @@ export default class DocumentPropertiesWidget extends BaseWidget {
|
|
170
170
|
}
|
171
171
|
}
|
172
172
|
DocumentPropertiesWidget.idCounter = 0;
|
173
|
+
export default DocumentPropertiesWidget;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { EditorEventType } from '../../types.mjs';
|
2
2
|
import { toolbarCSSPrefix } from '../HTMLToolbar.mjs';
|
3
3
|
import BaseToolWidget from './BaseToolWidget.mjs';
|
4
|
-
|
4
|
+
class EraserToolWidget extends BaseToolWidget {
|
5
5
|
constructor(editor, tool, localizationTable) {
|
6
6
|
super(editor, tool, 'eraser-tool-widget', localizationTable);
|
7
7
|
this.tool = tool;
|
@@ -55,3 +55,4 @@ export default class EraserToolWidget extends BaseToolWidget {
|
|
55
55
|
}
|
56
56
|
}
|
57
57
|
EraserToolWidget.nextThicknessInputId = 0;
|
58
|
+
export default EraserToolWidget;
|
@@ -15,7 +15,7 @@ import SelectionTool from '../../tools/SelectionTool/SelectionTool.mjs';
|
|
15
15
|
import Mat33 from '../../math/Mat33.mjs';
|
16
16
|
import fileToBase64 from '../../util/fileToBase64.mjs';
|
17
17
|
import ActionButtonWidget from './ActionButtonWidget.mjs';
|
18
|
-
|
18
|
+
class InsertImageWidget extends ActionButtonWidget {
|
19
19
|
constructor(editor, localization) {
|
20
20
|
localization !== null && localization !== void 0 ? localization : (localization = editor.localization);
|
21
21
|
super(editor, 'insert-image-widget', () => editor.icons.makeInsertImageIcon(), localization.image, () => this.onClicked());
|
@@ -168,3 +168,4 @@ export default class InsertImageWidget extends ActionButtonWidget {
|
|
168
168
|
}
|
169
169
|
}
|
170
170
|
InsertImageWidget.nextInputId = 0;
|
171
|
+
export default InsertImageWidget;
|
@@ -8,7 +8,7 @@ import { toolbarCSSPrefix } from '../HTMLToolbar.mjs';
|
|
8
8
|
import makeColorInput from '../makeColorInput.mjs';
|
9
9
|
import BaseToolWidget from './BaseToolWidget.mjs';
|
10
10
|
import Color4 from '../../Color4.mjs';
|
11
|
-
|
11
|
+
class PenToolWidget extends BaseToolWidget {
|
12
12
|
constructor(editor, tool, localization) {
|
13
13
|
super(editor, tool, 'pen', localization);
|
14
14
|
this.tool = tool;
|
@@ -218,3 +218,4 @@ export default class PenToolWidget extends BaseToolWidget {
|
|
218
218
|
}
|
219
219
|
}
|
220
220
|
PenToolWidget.idCounter = 0;
|
221
|
+
export default PenToolWidget;
|
@@ -3,7 +3,7 @@ import { EditorEventType } from '../../types.mjs';
|
|
3
3
|
import { toolbarCSSPrefix } from '../HTMLToolbar.mjs';
|
4
4
|
import makeColorInput from '../makeColorInput.mjs';
|
5
5
|
import BaseToolWidget from './BaseToolWidget.mjs';
|
6
|
-
|
6
|
+
class TextToolWidget extends BaseToolWidget {
|
7
7
|
constructor(editor, tool, localization) {
|
8
8
|
super(editor, tool, 'text-tool-widget', localization);
|
9
9
|
this.tool = tool;
|
@@ -107,3 +107,4 @@ export default class TextToolWidget extends BaseToolWidget {
|
|
107
107
|
}
|
108
108
|
}
|
109
109
|
TextToolWidget.idCounter = 0;
|
110
|
+
export default TextToolWidget;
|
@@ -27,7 +27,7 @@ import EditorImage from '../../EditorImage.mjs';
|
|
27
27
|
const updateChunkSize = 100;
|
28
28
|
const maxPreviewElemCount = 500;
|
29
29
|
// @internal
|
30
|
-
|
30
|
+
class Selection {
|
31
31
|
constructor(startPoint, editor) {
|
32
32
|
this.editor = editor;
|
33
33
|
this.transform = Mat33.identity;
|
@@ -125,6 +125,9 @@ export default class Selection {
|
|
125
125
|
this.transform = Mat33.identity;
|
126
126
|
// Make the commands undo-able
|
127
127
|
this.editor.dispatch(new Selection.ApplyTransformationCommand(this, selectedElems, fullTransform));
|
128
|
+
// Clear renderings of any in-progress transformations
|
129
|
+
const wetInkRenderer = this.editor.display.getWetInkRenderer();
|
130
|
+
wetInkRenderer.clear();
|
128
131
|
}
|
129
132
|
// Preview the effects of the current transformation on the selection
|
130
133
|
previewTransformCmds() {
|
@@ -442,7 +445,7 @@ Selection.ApplyTransformationCommand = class extends SerializableCommand {
|
|
442
445
|
(_b = this.selection) === null || _b === void 0 ? void 0 : _b.setTransform(this.fullTransform.inverse(), false);
|
443
446
|
(_c = this.selection) === null || _c === void 0 ? void 0 : _c.updateUI();
|
444
447
|
yield editor.asyncUnapplyCommands(this.transformCommands, updateChunkSize, true);
|
445
|
-
(_d = this.selection) === null || _d === void 0 ? void 0 : _d.setTransform(Mat33.identity);
|
448
|
+
(_d = this.selection) === null || _d === void 0 ? void 0 : _d.setTransform(Mat33.identity, false);
|
446
449
|
(_e = this.selection) === null || _e === void 0 ? void 0 : _e.recomputeRegion();
|
447
450
|
(_f = this.selection) === null || _f === void 0 ? void 0 : _f.updateUI();
|
448
451
|
});
|
@@ -457,3 +460,4 @@ Selection.ApplyTransformationCommand = class extends SerializableCommand {
|
|
457
460
|
return localizationTable.transformedElements(this.selectedElemIds.length);
|
458
461
|
}
|
459
462
|
};
|
463
|
+
export default Selection;
|
@@ -9,7 +9,7 @@ import TextComponent from '../../components/TextComponent.mjs';
|
|
9
9
|
export const cssPrefix = 'selection-tool-';
|
10
10
|
// Allows users to select/transform portions of the `EditorImage`.
|
11
11
|
// With respect to `extend`ing, `SelectionTool` is not stable.
|
12
|
-
|
12
|
+
class SelectionTool extends BaseTool {
|
13
13
|
constructor(editor, description) {
|
14
14
|
super(editor.notifier, description);
|
15
15
|
this.editor = editor;
|
@@ -396,3 +396,4 @@ SelectionTool.handleableKeys = [
|
|
396
396
|
'i', 'I', 'o', 'O',
|
397
397
|
'Control', 'Meta',
|
398
398
|
];
|
399
|
+
export default SelectionTool;
|
package/dist/mjs/src/types.d.ts
CHANGED
@@ -9,6 +9,8 @@ import Pointer from './Pointer';
|
|
9
9
|
import Color4 from './Color4';
|
10
10
|
import Command from './commands/Command';
|
11
11
|
import BaseWidget from './toolbar/widgets/BaseWidget';
|
12
|
+
export type HTMLPointerEventName = 'pointerdown' | 'pointermove' | 'pointerup' | 'pointercancel';
|
13
|
+
export type HTMLPointerEventFilter = (eventName: HTMLPointerEventName, event: PointerEvent) => boolean;
|
12
14
|
export interface PointerEvtListener {
|
13
15
|
onPointerDown(event: PointerEvt): boolean;
|
14
16
|
onPointerMove(event: PointerEvt): void;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "js-draw",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.22.1",
|
4
4
|
"description": "Draw pictures using a pen, touchscreen, or mouse! JS-draw is a drawing library for JavaScript and TypeScript. ",
|
5
5
|
"types": "./dist/mjs/src/lib.d.ts",
|
6
6
|
"main": "./dist/cjs/src/lib.js",
|
@@ -82,32 +82,32 @@
|
|
82
82
|
"postpack": "pinst --enable"
|
83
83
|
},
|
84
84
|
"dependencies": {
|
85
|
-
"@melloware/coloris": "^0.
|
85
|
+
"@melloware/coloris": "^0.19.1",
|
86
86
|
"bezier-js": "^6.1.3"
|
87
87
|
},
|
88
88
|
"devDependencies": {
|
89
89
|
"@types/bezier-js": "^4.1.0",
|
90
|
-
"@types/jest": "^29.
|
91
|
-
"@types/jsdom": "^21.1.
|
92
|
-
"@types/node": "^18.
|
93
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
94
|
-
"@typescript-eslint/parser": "^5.
|
90
|
+
"@types/jest": "^29.5.1",
|
91
|
+
"@types/jsdom": "^21.1.1",
|
92
|
+
"@types/node": "^18.16.2",
|
93
|
+
"@typescript-eslint/eslint-plugin": "^5.59.1",
|
94
|
+
"@typescript-eslint/parser": "^5.59.1",
|
95
95
|
"css-loader": "^6.7.3",
|
96
|
-
"eslint": "^8.
|
96
|
+
"eslint": "^8.39.0",
|
97
97
|
"husky": "^8.0.3",
|
98
98
|
"jest": "^29.5.0",
|
99
99
|
"jest-environment-jsdom": "^29.5.0",
|
100
100
|
"jsdom": "^21.1.1",
|
101
|
-
"lint-staged": "^13.2.
|
101
|
+
"lint-staged": "^13.2.2",
|
102
102
|
"pinst": "^3.0.0",
|
103
103
|
"style-loader": "^3.3.2",
|
104
104
|
"terser-webpack-plugin": "^5.3.7",
|
105
|
-
"ts-jest": "^29.0
|
105
|
+
"ts-jest": "^29.1.0",
|
106
106
|
"ts-loader": "^9.4.2",
|
107
107
|
"ts-node": "^10.9.1",
|
108
|
-
"typedoc": "^0.
|
109
|
-
"typescript": "^
|
110
|
-
"webpack": "^5.
|
108
|
+
"typedoc": "^0.24.6",
|
109
|
+
"typescript": "^5.0.4",
|
110
|
+
"webpack": "^5.81.0"
|
111
111
|
},
|
112
112
|
"bugs": {
|
113
113
|
"url": "https://github.com/personalizedrefrigerator/js-draw/issues"
|
package/src/toolbar/toolbar.css
CHANGED
@@ -74,6 +74,7 @@
|
|
74
74
|
margin-right: 3px;
|
75
75
|
|
76
76
|
min-width: 40px;
|
77
|
+
max-width: 105px;
|
77
78
|
width: min-content;
|
78
79
|
font-size: 1em;
|
79
80
|
}
|
@@ -82,6 +83,12 @@
|
|
82
83
|
cursor: inherit;
|
83
84
|
}
|
84
85
|
|
86
|
+
/* Decrease the font size of labels in the main toolbar if they're long. */
|
87
|
+
:not(.toolbar-dropdown) > .toolbar-toolContainer >
|
88
|
+
.toolbar-button > label.long-label {
|
89
|
+
font-size: 0.75em;
|
90
|
+
}
|
91
|
+
|
85
92
|
.toolbar-dropdown > .toolbar-toolContainer > button,
|
86
93
|
.toolbar-dropdown > .toolbar-toolContainer > .toolbar-button {
|
87
94
|
width: 6em;
|
package/tsconfig.json
CHANGED