js-draw 1.29.2 → 1.30.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/dist/bundle.js +44 -34
- package/dist/cjs/Editor.d.ts +2 -2
- package/dist/cjs/Editor.js +16 -9
- package/dist/cjs/components/ImageComponent.js +1 -1
- package/dist/cjs/components/builders/FreehandLineBuilder.d.ts +5 -1
- package/dist/cjs/components/builders/FreehandLineBuilder.js +7 -4
- package/dist/cjs/components/builders/PolylineBuilder.d.ts +5 -1
- package/dist/cjs/components/builders/PolylineBuilder.js +7 -4
- package/dist/cjs/components/builders/PressureSensitiveFreehandLineBuilder.d.ts +1 -0
- package/dist/cjs/components/builders/PressureSensitiveFreehandLineBuilder.js +13 -10
- package/dist/cjs/components/builders/autocorrect/makeShapeFitAutocorrect.js +3 -0
- package/dist/cjs/components/builders/autocorrect/makeSnapToGridAutocorrect.js +3 -0
- package/dist/cjs/components/builders/types.d.ts +6 -0
- package/dist/cjs/dialogs/makeMessageDialog.js +5 -3
- package/dist/cjs/localizations/getLocalizationTable.js +2 -0
- package/dist/cjs/localizations/sk.d.ts +3 -0
- package/dist/cjs/localizations/sk.js +182 -0
- package/dist/cjs/rendering/Display.d.ts +2 -0
- package/dist/cjs/rendering/Display.js +13 -4
- package/dist/cjs/rendering/renderers/AbstractRenderer.d.ts +20 -1
- package/dist/cjs/rendering/renderers/AbstractRenderer.js +7 -0
- package/dist/cjs/rendering/renderers/AcceleratedInkingCanvasRenderer.d.ts +22 -0
- package/dist/cjs/rendering/renderers/AcceleratedInkingCanvasRenderer.js +50 -0
- package/dist/cjs/toolbar/EdgeToolbar.js +3 -2
- package/dist/cjs/toolbar/IconProvider.js +1 -1
- package/dist/cjs/toolbar/utils/HelpDisplay.js +7 -6
- package/dist/cjs/toolbar/widgets/BaseWidget.js +1 -1
- package/dist/cjs/toolbar/widgets/DocumentPropertiesWidget.js +5 -3
- package/dist/cjs/toolbar/widgets/HandToolWidget.js +4 -3
- package/dist/cjs/toolbar/widgets/InsertImageWidget/InsertImageWidget.js +14 -11
- package/dist/cjs/toolbar/widgets/PenToolWidget.js +2 -1
- package/dist/cjs/toolbar/widgets/components/makeButtonGrid.js +3 -2
- package/dist/cjs/toolbar/widgets/components/makeColorInput.js +2 -1
- package/dist/cjs/toolbar/widgets/components/makeGridSelector.js +2 -2
- package/dist/cjs/toolbar/widgets/components/makeSnappedList.js +1 -1
- package/dist/cjs/tools/FindTool.js +3 -2
- package/dist/cjs/tools/Pen.d.ts +2 -0
- package/dist/cjs/tools/Pen.js +24 -12
- package/dist/cjs/tools/SelectionTool/SelectionMenuShortcut.js +7 -2
- package/dist/cjs/tools/SoundUITool.js +6 -4
- package/dist/cjs/tools/util/createMenuOverlay.js +9 -7
- package/dist/cjs/util/dom/createButton.d.ts +7 -0
- package/dist/cjs/util/dom/createButton.js +20 -0
- package/dist/cjs/util/{createElement.d.ts → dom/createElement.d.ts} +3 -0
- package/dist/cjs/version.js +1 -1
- package/dist/mjs/Editor.d.ts +2 -2
- package/dist/mjs/Editor.mjs +16 -9
- package/dist/mjs/components/ImageComponent.mjs +1 -1
- package/dist/mjs/components/builders/FreehandLineBuilder.d.ts +5 -1
- package/dist/mjs/components/builders/FreehandLineBuilder.mjs +7 -4
- package/dist/mjs/components/builders/PolylineBuilder.d.ts +5 -1
- package/dist/mjs/components/builders/PolylineBuilder.mjs +7 -4
- package/dist/mjs/components/builders/PressureSensitiveFreehandLineBuilder.d.ts +1 -0
- package/dist/mjs/components/builders/PressureSensitiveFreehandLineBuilder.mjs +13 -10
- package/dist/mjs/components/builders/autocorrect/makeShapeFitAutocorrect.mjs +3 -0
- package/dist/mjs/components/builders/autocorrect/makeSnapToGridAutocorrect.mjs +3 -0
- package/dist/mjs/components/builders/types.d.ts +6 -0
- package/dist/mjs/dialogs/makeMessageDialog.mjs +5 -3
- package/dist/mjs/localizations/getLocalizationTable.mjs +2 -0
- package/dist/mjs/localizations/sk.d.ts +3 -0
- package/dist/mjs/localizations/sk.mjs +180 -0
- package/dist/mjs/rendering/Display.d.ts +2 -0
- package/dist/mjs/rendering/Display.mjs +13 -4
- package/dist/mjs/rendering/renderers/AbstractRenderer.d.ts +20 -1
- package/dist/mjs/rendering/renderers/AbstractRenderer.mjs +7 -0
- package/dist/mjs/rendering/renderers/AcceleratedInkingCanvasRenderer.d.ts +22 -0
- package/dist/mjs/rendering/renderers/AcceleratedInkingCanvasRenderer.mjs +44 -0
- package/dist/mjs/toolbar/EdgeToolbar.mjs +3 -2
- package/dist/mjs/toolbar/IconProvider.mjs +1 -1
- package/dist/mjs/toolbar/utils/HelpDisplay.mjs +7 -6
- package/dist/mjs/toolbar/widgets/BaseWidget.mjs +1 -1
- package/dist/mjs/toolbar/widgets/DocumentPropertiesWidget.mjs +5 -3
- package/dist/mjs/toolbar/widgets/HandToolWidget.mjs +4 -3
- package/dist/mjs/toolbar/widgets/InsertImageWidget/InsertImageWidget.mjs +14 -11
- package/dist/mjs/toolbar/widgets/PenToolWidget.mjs +2 -1
- package/dist/mjs/toolbar/widgets/components/makeButtonGrid.mjs +3 -2
- package/dist/mjs/toolbar/widgets/components/makeColorInput.mjs +2 -1
- package/dist/mjs/toolbar/widgets/components/makeGridSelector.mjs +2 -2
- package/dist/mjs/toolbar/widgets/components/makeSnappedList.mjs +1 -1
- package/dist/mjs/tools/FindTool.mjs +3 -2
- package/dist/mjs/tools/Pen.d.ts +2 -0
- package/dist/mjs/tools/Pen.mjs +24 -12
- package/dist/mjs/tools/SelectionTool/SelectionMenuShortcut.mjs +4 -2
- package/dist/mjs/tools/SoundUITool.mjs +6 -4
- package/dist/mjs/tools/util/createMenuOverlay.mjs +9 -7
- package/dist/mjs/util/dom/createButton.d.ts +7 -0
- package/dist/mjs/util/dom/createButton.mjs +15 -0
- package/dist/mjs/util/{createElement.d.ts → dom/createElement.d.ts} +3 -0
- package/dist/mjs/version.mjs +1 -1
- package/package.json +4 -4
- /package/dist/cjs/util/{addLongPressOrHoverCssClasses.d.ts → dom/addLongPressOrHoverCssClasses.d.ts} +0 -0
- /package/dist/cjs/util/{addLongPressOrHoverCssClasses.js → dom/addLongPressOrHoverCssClasses.js} +0 -0
- /package/dist/cjs/util/{cloneElementWithStyles.d.ts → dom/cloneElementWithStyles.d.ts} +0 -0
- /package/dist/cjs/util/{cloneElementWithStyles.js → dom/cloneElementWithStyles.js} +0 -0
- /package/dist/cjs/util/{createElement.js → dom/createElement.js} +0 -0
- /package/dist/cjs/util/{listenForKeyboardEventsFrom.d.ts → dom/listenForKeyboardEventsFrom.d.ts} +0 -0
- /package/dist/cjs/util/{listenForKeyboardEventsFrom.js → dom/listenForKeyboardEventsFrom.js} +0 -0
- /package/dist/cjs/util/{listenForLongPressOrHover.d.ts → dom/listenForLongPressOrHover.d.ts} +0 -0
- /package/dist/cjs/util/{listenForLongPressOrHover.js → dom/listenForLongPressOrHover.js} +0 -0
- /package/dist/cjs/util/{listenForLongPressOrHover.test.d.ts → dom/listenForLongPressOrHover.test.d.ts} +0 -0
- /package/dist/cjs/util/{stopPropagationOfScrollingWheelEvents.d.ts → dom/stopPropagationOfScrollingWheelEvents.d.ts} +0 -0
- /package/dist/cjs/util/{stopPropagationOfScrollingWheelEvents.js → dom/stopPropagationOfScrollingWheelEvents.js} +0 -0
- /package/dist/cjs/util/{waitForImageLoaded.d.ts → dom/waitForImageLoaded.d.ts} +0 -0
- /package/dist/cjs/util/{waitForImageLoaded.js → dom/waitForImageLoaded.js} +0 -0
- /package/dist/mjs/util/{addLongPressOrHoverCssClasses.d.ts → dom/addLongPressOrHoverCssClasses.d.ts} +0 -0
- /package/dist/mjs/util/{addLongPressOrHoverCssClasses.mjs → dom/addLongPressOrHoverCssClasses.mjs} +0 -0
- /package/dist/mjs/util/{cloneElementWithStyles.d.ts → dom/cloneElementWithStyles.d.ts} +0 -0
- /package/dist/mjs/util/{cloneElementWithStyles.mjs → dom/cloneElementWithStyles.mjs} +0 -0
- /package/dist/mjs/util/{createElement.mjs → dom/createElement.mjs} +0 -0
- /package/dist/mjs/util/{listenForKeyboardEventsFrom.d.ts → dom/listenForKeyboardEventsFrom.d.ts} +0 -0
- /package/dist/mjs/util/{listenForKeyboardEventsFrom.mjs → dom/listenForKeyboardEventsFrom.mjs} +0 -0
- /package/dist/mjs/util/{listenForLongPressOrHover.d.ts → dom/listenForLongPressOrHover.d.ts} +0 -0
- /package/dist/mjs/util/{listenForLongPressOrHover.mjs → dom/listenForLongPressOrHover.mjs} +0 -0
- /package/dist/mjs/util/{listenForLongPressOrHover.test.d.ts → dom/listenForLongPressOrHover.test.d.ts} +0 -0
- /package/dist/mjs/util/{stopPropagationOfScrollingWheelEvents.d.ts → dom/stopPropagationOfScrollingWheelEvents.d.ts} +0 -0
- /package/dist/mjs/util/{stopPropagationOfScrollingWheelEvents.mjs → dom/stopPropagationOfScrollingWheelEvents.mjs} +0 -0
- /package/dist/mjs/util/{waitForImageLoaded.d.ts → dom/waitForImageLoaded.d.ts} +0 -0
- /package/dist/mjs/util/{waitForImageLoaded.mjs → dom/waitForImageLoaded.mjs} +0 -0
@@ -0,0 +1,44 @@
|
|
1
|
+
import CanvasRenderer from './CanvasRenderer.mjs';
|
2
|
+
class CanvasInkPresenter {
|
3
|
+
constructor(canvas, viewport) {
|
4
|
+
this.viewport = viewport;
|
5
|
+
this.enabled = new Map();
|
6
|
+
this.presenter = null;
|
7
|
+
this.style = { color: 'black', diameter: 2 };
|
8
|
+
if ('ink' in navigator && navigator.ink) {
|
9
|
+
const ink = navigator.ink;
|
10
|
+
ink.requestPresenter({ presentationArea: canvas }).then((presenter) => {
|
11
|
+
this.presenter = presenter;
|
12
|
+
});
|
13
|
+
}
|
14
|
+
}
|
15
|
+
setEnabled(pointerId, enabled) {
|
16
|
+
this.enabled.set(pointerId, enabled);
|
17
|
+
}
|
18
|
+
updateStyle(style) {
|
19
|
+
const colorString = style.color.toString();
|
20
|
+
// style.diameter must be a postive integer.
|
21
|
+
this.style = {
|
22
|
+
color: colorString,
|
23
|
+
diameter: Math.ceil(style.width / this.viewport.getSizeOfPixelOnCanvas()),
|
24
|
+
};
|
25
|
+
}
|
26
|
+
onEvent(event) {
|
27
|
+
if (this.presenter && this.enabled.get(event.pointerId) && event.isTrusted) {
|
28
|
+
this.presenter.updateInkTrailStartPoint(event, this.style);
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
32
|
+
/** A canvas that uses the web ink API for accelerated inking. */
|
33
|
+
export default class AcceleratedInkingCanvasRenderer extends CanvasRenderer {
|
34
|
+
constructor(ctx, viewport) {
|
35
|
+
super(ctx, viewport);
|
36
|
+
this.inkPresenter = new CanvasInkPresenter(ctx.canvas, viewport);
|
37
|
+
}
|
38
|
+
getDraftInkPresenter() {
|
39
|
+
return this.inkPresenter;
|
40
|
+
}
|
41
|
+
onEvent(event) {
|
42
|
+
this.inkPresenter.onEvent(event);
|
43
|
+
}
|
44
|
+
}
|
@@ -3,8 +3,9 @@ import { toolbarCSSPrefix } from './constants.mjs';
|
|
3
3
|
import EdgeToolbarLayoutManager from './widgets/layout/EdgeToolbarLayoutManager.mjs';
|
4
4
|
import { MutableReactiveValue, ReactiveValue } from '../util/ReactiveValue.mjs';
|
5
5
|
import AbstractToolbar from './AbstractToolbar.mjs';
|
6
|
-
import stopPropagationOfScrollingWheelEvents from '../util/stopPropagationOfScrollingWheelEvents.mjs';
|
6
|
+
import stopPropagationOfScrollingWheelEvents from '../util/dom/stopPropagationOfScrollingWheelEvents.mjs';
|
7
7
|
import makeDraggable from './utils/makeDraggable.mjs';
|
8
|
+
import createButton from '../util/dom/createButton.mjs';
|
8
9
|
/**
|
9
10
|
* Creates an `EdgeToolbar`.
|
10
11
|
*
|
@@ -85,7 +86,7 @@ export default class EdgeToolbar extends AbstractToolbar {
|
|
85
86
|
this.menuContainer.classList.remove(belowEdgeClassName);
|
86
87
|
}
|
87
88
|
});
|
88
|
-
this.closeButton =
|
89
|
+
this.closeButton = createButton();
|
89
90
|
this.closeButton.classList.add('drag-elem');
|
90
91
|
// The close button has default focus -- forward its events to the main editor so that keyboard
|
91
92
|
// shortcuts still work.
|
@@ -10,7 +10,7 @@ import Viewport from '../Viewport.mjs';
|
|
10
10
|
import { makeFreehandLineBuilder } from '../components/builders/FreehandLineBuilder.mjs';
|
11
11
|
import { makePolylineBuilder } from '../components/builders/PolylineBuilder.mjs';
|
12
12
|
import { EraserMode } from '../tools/Eraser.mjs';
|
13
|
-
import { createSvgElement, createSvgElements, createSvgPaths } from '../util/createElement.mjs';
|
13
|
+
import { createSvgElement, createSvgElements, createSvgPaths } from '../util/dom/createElement.mjs';
|
14
14
|
import { SelectionMode } from '../tools/SelectionTool/types.mjs';
|
15
15
|
const svgNamespace = 'http://www.w3.org/2000/svg';
|
16
16
|
let checkerboardIdCounter = 0;
|
@@ -7,8 +7,9 @@ var _HelpDisplay_helpData;
|
|
7
7
|
import { Rect2 } from '@js-draw/math';
|
8
8
|
import makeDraggable from './makeDraggable.mjs';
|
9
9
|
import { MutableReactiveValue } from '../../util/ReactiveValue.mjs';
|
10
|
-
import cloneElementWithStyles from '../../util/cloneElementWithStyles.mjs';
|
11
|
-
import addLongPressOrHoverCssClasses from '../../util/addLongPressOrHoverCssClasses.mjs';
|
10
|
+
import cloneElementWithStyles from '../../util/dom/cloneElementWithStyles.mjs';
|
11
|
+
import addLongPressOrHoverCssClasses from '../../util/dom/addLongPressOrHoverCssClasses.mjs';
|
12
|
+
import createButton from '../../util/dom/createButton.mjs';
|
12
13
|
/**
|
13
14
|
* Creates the main content of the help overlay.
|
14
15
|
*
|
@@ -214,7 +215,7 @@ class HelpDisplay {
|
|
214
215
|
}
|
215
216
|
};
|
216
217
|
const makeCloseButton = () => {
|
217
|
-
const closeButton =
|
218
|
+
const closeButton = createButton();
|
218
219
|
closeButton.classList.add('close-button');
|
219
220
|
closeButton.appendChild(this.context.icons.makeCloseIcon());
|
220
221
|
const label = this.context.localization.close;
|
@@ -273,8 +274,8 @@ class HelpDisplay {
|
|
273
274
|
const makeNavigationButtons = (navigation) => {
|
274
275
|
const navigationButtonContainer = document.createElement('div');
|
275
276
|
navigationButtonContainer.classList.add('navigation-buttons');
|
276
|
-
const nextButton =
|
277
|
-
const previousButton =
|
277
|
+
const nextButton = createButton();
|
278
|
+
const previousButton = createButton();
|
278
279
|
nextButton.textContent = this.context.localization.next;
|
279
280
|
previousButton.textContent = this.context.localization.previous;
|
280
281
|
nextButton.classList.add('next');
|
@@ -424,7 +425,7 @@ class HelpDisplay {
|
|
424
425
|
createToggleButton() {
|
425
426
|
const buttonContainer = document.createElement('div');
|
426
427
|
buttonContainer.classList.add('toolbar-help-overlay-button');
|
427
|
-
const helpButton =
|
428
|
+
const helpButton = createButton();
|
428
429
|
helpButton.classList.add('button');
|
429
430
|
const icon = this.context.icons.makeHelpIcon();
|
430
431
|
icon.classList.add('icon');
|
@@ -14,7 +14,7 @@ import ToolbarShortcutHandler from '../../tools/ToolbarShortcutHandler.mjs';
|
|
14
14
|
import { keyPressEventFromHTMLEvent, keyUpEventFromHTMLEvent, } from '../../inputEvents.mjs';
|
15
15
|
import { toolbarCSSPrefix } from '../constants.mjs';
|
16
16
|
import DropdownLayoutManager from './layout/DropdownLayoutManager.mjs';
|
17
|
-
import addLongPressOrHoverCssClasses from '../../util/addLongPressOrHoverCssClasses.mjs';
|
17
|
+
import addLongPressOrHoverCssClasses from '../../util/dom/addLongPressOrHoverCssClasses.mjs';
|
18
18
|
import HelpDisplay from '../utils/HelpDisplay.mjs';
|
19
19
|
import { assertIsObject } from '../../util/assertions.mjs';
|
20
20
|
/**
|
@@ -7,6 +7,7 @@ import { EditorEventType } from '../../types.mjs';
|
|
7
7
|
import { toolbarCSSPrefix } from '../constants.mjs';
|
8
8
|
import makeColorInput from './components/makeColorInput.mjs';
|
9
9
|
import BaseWidget from './BaseWidget.mjs';
|
10
|
+
import createButton from '../../util/dom/createButton.mjs';
|
10
11
|
class DocumentPropertiesWidget extends BaseWidget {
|
11
12
|
constructor(editor, localizationTable) {
|
12
13
|
super(editor, 'document-properties-widget', localizationTable);
|
@@ -216,9 +217,10 @@ class DocumentPropertiesWidget extends BaseWidget {
|
|
216
217
|
this.editor.dispatch(image.setAutoresizeEnabled(checked));
|
217
218
|
});
|
218
219
|
// The "About..." button
|
219
|
-
const aboutButton =
|
220
|
-
|
221
|
-
|
220
|
+
const aboutButton = createButton({
|
221
|
+
classList: ['about-button'],
|
222
|
+
text: this.localizationTable.about,
|
223
|
+
});
|
222
224
|
aboutButton.onclick = () => {
|
223
225
|
this.editor.showAboutDialog();
|
224
226
|
};
|
@@ -6,11 +6,12 @@ import { toolbarCSSPrefix } from '../constants.mjs';
|
|
6
6
|
import BaseToolWidget from './BaseToolWidget.mjs';
|
7
7
|
import BaseWidget from './BaseWidget.mjs';
|
8
8
|
import makeSeparator from './components/makeSeparator.mjs';
|
9
|
+
import createButton from '../../util/dom/createButton.mjs';
|
9
10
|
const makeZoomControl = (localizationTable, editor, helpDisplay) => {
|
10
11
|
const zoomLevelRow = document.createElement('div');
|
11
|
-
const increaseButton =
|
12
|
-
const decreaseButton =
|
13
|
-
const resetViewButton =
|
12
|
+
const increaseButton = createButton();
|
13
|
+
const decreaseButton = createButton();
|
14
|
+
const resetViewButton = createButton();
|
14
15
|
const zoomLevelDisplay = document.createElement('span');
|
15
16
|
increaseButton.innerText = '+';
|
16
17
|
decreaseButton.innerText = '-';
|
@@ -13,6 +13,7 @@ import bytesToSizeString from '../../../util/bytesToSizeString.mjs';
|
|
13
13
|
import { ImageWrapper } from './ImageWrapper.mjs';
|
14
14
|
import makeSnappedList from '../components/makeSnappedList.mjs';
|
15
15
|
import fileToImages from './fileToImages.mjs';
|
16
|
+
import createButton from '../../../util/dom/createButton.mjs';
|
16
17
|
/**
|
17
18
|
* Provides a widget that allows inserting or modifying raster images.
|
18
19
|
*
|
@@ -78,7 +79,7 @@ class InsertImageWidget extends BaseWidget {
|
|
78
79
|
const actionButtonRow = document.createElement('div');
|
79
80
|
actionButtonRow.classList.add('action-button-row');
|
80
81
|
this.statusView.classList.add('insert-image-image-status-view');
|
81
|
-
this.submitButton =
|
82
|
+
this.submitButton = createButton();
|
82
83
|
this.selectedFiles = selectedFiles;
|
83
84
|
this.imageAltTextInput = document.createElement('input');
|
84
85
|
// Label the alt text input
|
@@ -165,16 +166,18 @@ class InsertImageWidget extends BaseWidget {
|
|
165
166
|
const sizeText = document.createElement('span');
|
166
167
|
sizeText.innerText = this.localizationTable.imageSize(Math.round(size), units);
|
167
168
|
// Add a button to allow decreasing the size of large images.
|
168
|
-
const decreaseSizeButton =
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
resetSizeButton
|
175
|
-
|
176
|
-
|
177
|
-
|
169
|
+
const decreaseSizeButton = createButton({
|
170
|
+
text: this.localizationTable.decreaseImageSize,
|
171
|
+
onClick: () => {
|
172
|
+
currentImage?.decreaseSize();
|
173
|
+
},
|
174
|
+
});
|
175
|
+
const resetSizeButton = createButton({
|
176
|
+
text: this.localizationTable.resetImage,
|
177
|
+
onClick: () => {
|
178
|
+
currentImage?.reset();
|
179
|
+
},
|
180
|
+
});
|
178
181
|
this.statusView.replaceChildren(sizeText);
|
179
182
|
if (currentImage?.isLarge()) {
|
180
183
|
this.statusView.appendChild(decreaseSizeButton);
|
@@ -13,6 +13,7 @@ import { toolbarCSSPrefix } from '../constants.mjs';
|
|
13
13
|
import makeThicknessSlider from './components/makeThicknessSlider.mjs';
|
14
14
|
import makeGridSelector from './components/makeGridSelector.mjs';
|
15
15
|
import { makePolylineBuilder } from '../../components/builders/PolylineBuilder.mjs';
|
16
|
+
import createElement from '../../util/dom/createElement.mjs';
|
16
17
|
/**
|
17
18
|
* This toolbar widget allows a user to control a single {@link Pen} tool.
|
18
19
|
*
|
@@ -179,7 +180,7 @@ class PenToolWidget extends BaseToolWidget {
|
|
179
180
|
const container = document.createElement('div');
|
180
181
|
container.classList.add('action-button-row', `${toolbarCSSPrefix}-pen-tool-toggle-buttons`);
|
181
182
|
const addToggleButton = (labelText, icon) => {
|
182
|
-
const button =
|
183
|
+
const button = createElement('button', { type: 'button' });
|
183
184
|
button.classList.add(`${toolbarCSSPrefix}-toggle-button`);
|
184
185
|
const iconElement = icon.cloneNode(true);
|
185
186
|
iconElement.classList.add('icon');
|
@@ -1,4 +1,5 @@
|
|
1
|
-
import addLongPressOrHoverCssClasses from '../../../util/addLongPressOrHoverCssClasses.mjs';
|
1
|
+
import addLongPressOrHoverCssClasses from '../../../util/dom/addLongPressOrHoverCssClasses.mjs';
|
2
|
+
import createButton from '../../../util/dom/createButton.mjs';
|
2
3
|
/**
|
3
4
|
* Creates HTML `button` elements from `buttonSpecs` and displays them in a
|
4
5
|
* grid with `columnCount` columns.
|
@@ -8,7 +9,7 @@ const makeButtonGrid = (buttonSpecs, columnCount) => {
|
|
8
9
|
container.classList.add('toolbar-button-grid');
|
9
10
|
container.style.setProperty('--column-count', `${columnCount}`);
|
10
11
|
const makeButton = (buttonSpec) => {
|
11
|
-
const buttonElement =
|
12
|
+
const buttonElement = createButton();
|
12
13
|
buttonElement.classList.add('button');
|
13
14
|
const iconElement = buttonSpec.icon();
|
14
15
|
iconElement.classList.add('icon');
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { Color4 } from '@js-draw/math';
|
2
2
|
import PipetteTool from '../../../tools/PipetteTool.mjs';
|
3
3
|
import { EditorEventType } from '../../../types.mjs';
|
4
|
+
import createButton from '../../../util/dom/createButton.mjs';
|
4
5
|
// Returns [ color input, input container, callback to change the color value ].
|
5
6
|
export const makeColorInput = (editor, onColorChange) => {
|
6
7
|
const container = document.createElement('span');
|
@@ -93,7 +94,7 @@ export const makeColorInput = (editor, onColorChange) => {
|
|
93
94
|
};
|
94
95
|
};
|
95
96
|
const addPipetteTool = (editor, container, onColorChange) => {
|
96
|
-
const pipetteButton =
|
97
|
+
const pipetteButton = createButton();
|
97
98
|
pipetteButton.classList.add('pipetteButton');
|
98
99
|
pipetteButton.title = editor.localization.pickColorFromScreen;
|
99
100
|
pipetteButton.setAttribute('alt', pipetteButton.title);
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { MutableReactiveValue } from '../../../util/ReactiveValue.mjs';
|
2
|
-
import stopPropagationOfScrollingWheelEvents from '../../../util/stopPropagationOfScrollingWheelEvents.mjs';
|
3
|
-
import addLongPressOrHoverCssClasses from '../../../util/addLongPressOrHoverCssClasses.mjs';
|
2
|
+
import stopPropagationOfScrollingWheelEvents from '../../../util/dom/stopPropagationOfScrollingWheelEvents.mjs';
|
3
|
+
import addLongPressOrHoverCssClasses from '../../../util/dom/addLongPressOrHoverCssClasses.mjs';
|
4
4
|
import { toolbarCSSPrefix } from '../../constants.mjs';
|
5
5
|
let idCounter = 0;
|
6
6
|
/**
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import stopPropagationOfScrollingWheelEvents from '../../../util/stopPropagationOfScrollingWheelEvents.mjs';
|
1
|
+
import stopPropagationOfScrollingWheelEvents from '../../../util/dom/stopPropagationOfScrollingWheelEvents.mjs';
|
2
2
|
import { MutableReactiveValue, ReactiveValue } from '../../../util/ReactiveValue.mjs';
|
3
3
|
/**
|
4
4
|
* Creates a list that snaps to each item and reports the selected item.
|
@@ -5,6 +5,7 @@ import TextComponent from '../components/TextComponent.mjs';
|
|
5
5
|
import ImageComponent from '../components/ImageComponent.mjs';
|
6
6
|
import BaseTool from './BaseTool.mjs';
|
7
7
|
import { toggleFindVisibleShortcutId } from './keybindings.mjs';
|
8
|
+
import createButton from '../util/dom/createButton.mjs';
|
8
9
|
const cssPrefix = 'find-tool';
|
9
10
|
export default class FindTool extends BaseTool {
|
10
11
|
constructor(editor) {
|
@@ -62,8 +63,8 @@ export default class FindTool extends BaseTool {
|
|
62
63
|
fillOverlay() {
|
63
64
|
const label = document.createElement('label');
|
64
65
|
this.searchInput = document.createElement('input');
|
65
|
-
const nextBtn =
|
66
|
-
const closeBtn =
|
66
|
+
const nextBtn = createButton();
|
67
|
+
const closeBtn = createButton();
|
67
68
|
// Math.random() ensures that the ID is unique (to allow us to refer to it
|
68
69
|
// with an htmlFor).
|
69
70
|
this.searchInput.setAttribute('id', `${cssPrefix}-searchInput-${Math.random()}`);
|
package/dist/mjs/tools/Pen.d.ts
CHANGED
@@ -25,6 +25,7 @@ export default class Pen extends BaseTool {
|
|
25
25
|
private currentDeviceType;
|
26
26
|
private currentPointerId;
|
27
27
|
private styleValue;
|
28
|
+
private wetInkRenderer;
|
28
29
|
private style;
|
29
30
|
private shapeAutocompletionEnabled;
|
30
31
|
private pressureSensitivityEnabled;
|
@@ -42,6 +43,7 @@ export default class Pen extends BaseTool {
|
|
42
43
|
eventCanBeDeliveredToNonActiveTool(event: PointerEvt): boolean;
|
43
44
|
onPointerMove({ current }: PointerEvt): void;
|
44
45
|
onPointerUp({ current }: PointerEvt): boolean;
|
46
|
+
private postGestureCleanup;
|
45
47
|
onGestureCancel(): void;
|
46
48
|
private removedAutocorrectedShapeRecently;
|
47
49
|
private autocorrectShape;
|
package/dist/mjs/tools/Pen.mjs
CHANGED
@@ -40,6 +40,7 @@ export default class Pen extends BaseTool {
|
|
40
40
|
this.style = newValue;
|
41
41
|
this.noteUpdated();
|
42
42
|
});
|
43
|
+
this.wetInkRenderer = this.editor.display.getWetInkRenderer();
|
43
44
|
}
|
44
45
|
getPressureMultiplier() {
|
45
46
|
const thickness = this.style.thickness;
|
@@ -71,13 +72,17 @@ export default class Pen extends BaseTool {
|
|
71
72
|
// Displays the stroke that is currently being built with the display's `wetInkRenderer`.
|
72
73
|
previewStroke() {
|
73
74
|
this.editor.clearWetInk();
|
74
|
-
const wetInkRenderer = this.editor.display.getWetInkRenderer();
|
75
75
|
if (this.autocorrectedShape) {
|
76
76
|
const visibleRect = this.editor.viewport.visibleRect;
|
77
|
-
this.autocorrectedShape.render(wetInkRenderer, visibleRect);
|
77
|
+
this.autocorrectedShape.render(this.wetInkRenderer, visibleRect);
|
78
78
|
}
|
79
|
-
else {
|
80
|
-
this.builder
|
79
|
+
else if (this.builder) {
|
80
|
+
this.builder.preview(this.wetInkRenderer);
|
81
|
+
if (this.builder.inkTrailStyle) {
|
82
|
+
const trailStyle = this.builder.inkTrailStyle();
|
83
|
+
const draftInkPresenter = this.wetInkRenderer.getDraftInkPresenter();
|
84
|
+
draftInkPresenter.updateStyle(trailStyle);
|
85
|
+
}
|
81
86
|
}
|
82
87
|
}
|
83
88
|
// Throws if no stroke builder exists.
|
@@ -113,6 +118,10 @@ export default class Pen extends BaseTool {
|
|
113
118
|
}
|
114
119
|
this.lastAutocorrectedShape = null;
|
115
120
|
this.removedAutocorrectedShapeTime = 0;
|
121
|
+
if (this.builder.inkTrailStyle) {
|
122
|
+
// Accelerate inking
|
123
|
+
this.wetInkRenderer.getDraftInkPresenter().setEnabled(current.id, true);
|
124
|
+
}
|
116
125
|
return true;
|
117
126
|
}
|
118
127
|
return false;
|
@@ -171,12 +180,21 @@ export default class Pen extends BaseTool {
|
|
171
180
|
this.finalizeStroke();
|
172
181
|
return false;
|
173
182
|
}
|
174
|
-
|
183
|
+
postGestureCleanup() {
|
184
|
+
if (this.currentPointerId !== null) {
|
185
|
+
this.wetInkRenderer.getDraftInkPresenter().setEnabled(this.currentPointerId, false);
|
186
|
+
}
|
175
187
|
this.builder = null;
|
188
|
+
this.lastPoint = null;
|
189
|
+
this.autocorrectedShape = null;
|
190
|
+
this.lastAutocorrectedShape = null;
|
176
191
|
this.editor.clearWetInk();
|
177
192
|
this.stationaryDetector?.destroy();
|
178
193
|
this.stationaryDetector = null;
|
179
194
|
}
|
195
|
+
onGestureCancel() {
|
196
|
+
this.postGestureCleanup();
|
197
|
+
}
|
180
198
|
removedAutocorrectedShapeRecently() {
|
181
199
|
return this.removedAutocorrectedShapeTime > performance.now() - 320;
|
182
200
|
}
|
@@ -225,13 +243,7 @@ export default class Pen extends BaseTool {
|
|
225
243
|
console.warn('Pen: Not adding empty stroke', stroke, 'to the canvas.');
|
226
244
|
}
|
227
245
|
}
|
228
|
-
this.
|
229
|
-
this.lastPoint = null;
|
230
|
-
this.autocorrectedShape = null;
|
231
|
-
this.lastAutocorrectedShape = null;
|
232
|
-
this.editor.clearWetInk();
|
233
|
-
this.stationaryDetector?.destroy();
|
234
|
-
this.stationaryDetector = null;
|
246
|
+
this.postGestureCleanup();
|
235
247
|
}
|
236
248
|
noteUpdated() {
|
237
249
|
this.editor.notifier.dispatch(EditorEventType.ToolUpdated, {
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import { Rect2, Vec2 } from '@js-draw/math';
|
2
2
|
import { cssPrefix } from './SelectionTool.mjs';
|
3
|
+
import createButton from '../../util/dom/createButton.mjs';
|
3
4
|
const verticalOffset = 40;
|
4
5
|
export default class SelectionMenuShortcut {
|
5
6
|
constructor(parent, viewport, icon, showContextMenu, localization) {
|
@@ -20,8 +21,9 @@ export default class SelectionMenuShortcut {
|
|
20
21
|
this.updatePosition();
|
21
22
|
}
|
22
23
|
initUI() {
|
23
|
-
const button =
|
24
|
-
|
24
|
+
const button = createButton({
|
25
|
+
classList: ['icon'],
|
26
|
+
});
|
25
27
|
button.replaceChildren(this.icon);
|
26
28
|
button.ariaLabel = this.localization.selectionMenu__show;
|
27
29
|
button.title = button.ariaLabel;
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import { LineSegment2, Color4 } from '@js-draw/math';
|
2
2
|
import BaseTool from './BaseTool.mjs';
|
3
|
+
import createButton from '../util/dom/createButton.mjs';
|
3
4
|
class SoundFeedback {
|
4
5
|
constructor() {
|
5
6
|
this.closed = false;
|
@@ -92,10 +93,11 @@ export default class SoundUITool extends BaseTool {
|
|
92
93
|
// Create a screen-reader-usable method of toggling the tool:
|
93
94
|
this.toggleButtonContainer = document.createElement('div');
|
94
95
|
this.toggleButtonContainer.classList.add('js-draw-sound-ui-toggle');
|
95
|
-
this.toggleButton =
|
96
|
-
|
97
|
-
|
98
|
-
|
96
|
+
this.toggleButton = createButton({
|
97
|
+
onClick: () => {
|
98
|
+
this.setEnabled(!this.isEnabled());
|
99
|
+
},
|
100
|
+
});
|
99
101
|
this.toggleButtonContainer.appendChild(this.toggleButton);
|
100
102
|
this.updateToggleButtonText();
|
101
103
|
editor.createHTMLOverlay(this.toggleButtonContainer);
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import waitForTimeout from '../../util/waitForTimeout.mjs';
|
2
2
|
import { EditorEventType } from '../../types.mjs';
|
3
|
+
import createButton from '../../util/dom/createButton.mjs';
|
3
4
|
let idCounter = 0;
|
4
5
|
const createMenuOverlay = async (editor, canvasAnchor, options) => {
|
5
6
|
const overlay = document.createElement('div');
|
@@ -96,16 +97,17 @@ const createMenuOverlay = async (editor, canvasAnchor, options) => {
|
|
96
97
|
}
|
97
98
|
});
|
98
99
|
for (const option of options) {
|
99
|
-
const optionElement =
|
100
|
+
const optionElement = createButton({
|
101
|
+
classList: ['option', 'editor-popup-menu-option'],
|
102
|
+
onClick: (event) => {
|
103
|
+
if (event.defaultPrevented)
|
104
|
+
return;
|
105
|
+
onOptionSelected(option.key);
|
106
|
+
},
|
107
|
+
});
|
100
108
|
optionElement.id = `menu-overlay-option-${idCounter++}`;
|
101
109
|
optionElement.role = 'menuitem';
|
102
|
-
optionElement.classList.add('option', 'editor-popup-menu-option');
|
103
110
|
optionElement.replaceChildren(option.icon(), document.createTextNode(option.text));
|
104
|
-
optionElement.onclick = (event) => {
|
105
|
-
if (event.defaultPrevented)
|
106
|
-
return;
|
107
|
-
onOptionSelected(option.key);
|
108
|
-
};
|
109
111
|
contentElement.appendChild(optionElement);
|
110
112
|
if (optionElements.length === 0) {
|
111
113
|
optionElement.autofocus = true;
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import createElement from './createElement.mjs';
|
2
|
+
const createButton = ({ onClick, text, classList = [] } = {}) => {
|
3
|
+
const button = createElement('button', { type: 'button' });
|
4
|
+
if (onClick) {
|
5
|
+
button.onclick = onClick;
|
6
|
+
}
|
7
|
+
if (text) {
|
8
|
+
button.textContent = text;
|
9
|
+
}
|
10
|
+
for (const className of classList) {
|
11
|
+
button.classList.add(className);
|
12
|
+
}
|
13
|
+
return button;
|
14
|
+
};
|
15
|
+
export default createButton;
|
package/dist/mjs/version.mjs
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "js-draw",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.30.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/lib.d.ts",
|
6
6
|
"main": "./dist/cjs/lib.js",
|
@@ -64,11 +64,11 @@
|
|
64
64
|
"postpack": "ts-node tools/copyREADME.ts revert"
|
65
65
|
},
|
66
66
|
"dependencies": {
|
67
|
-
"@js-draw/math": "^1.
|
67
|
+
"@js-draw/math": "^1.30.1",
|
68
68
|
"@melloware/coloris": "0.22.0"
|
69
69
|
},
|
70
70
|
"devDependencies": {
|
71
|
-
"@js-draw/build-tool": "^1.
|
71
|
+
"@js-draw/build-tool": "^1.30.1",
|
72
72
|
"@types/jest": "29.5.5",
|
73
73
|
"@types/jsdom": "21.1.3"
|
74
74
|
},
|
@@ -86,5 +86,5 @@
|
|
86
86
|
"freehand",
|
87
87
|
"svg"
|
88
88
|
],
|
89
|
-
"gitHead": "
|
89
|
+
"gitHead": "a416de226b49ee0c9244ec7f7b9522515a49bcb7"
|
90
90
|
}
|
/package/dist/cjs/util/{addLongPressOrHoverCssClasses.d.ts → dom/addLongPressOrHoverCssClasses.d.ts}
RENAMED
File without changes
|
/package/dist/cjs/util/{addLongPressOrHoverCssClasses.js → dom/addLongPressOrHoverCssClasses.js}
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
/package/dist/cjs/util/{listenForKeyboardEventsFrom.d.ts → dom/listenForKeyboardEventsFrom.d.ts}
RENAMED
File without changes
|
/package/dist/cjs/util/{listenForKeyboardEventsFrom.js → dom/listenForKeyboardEventsFrom.js}
RENAMED
File without changes
|
/package/dist/cjs/util/{listenForLongPressOrHover.d.ts → dom/listenForLongPressOrHover.d.ts}
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
/package/dist/mjs/util/{addLongPressOrHoverCssClasses.d.ts → dom/addLongPressOrHoverCssClasses.d.ts}
RENAMED
File without changes
|
/package/dist/mjs/util/{addLongPressOrHoverCssClasses.mjs → dom/addLongPressOrHoverCssClasses.mjs}
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
/package/dist/mjs/util/{listenForKeyboardEventsFrom.d.ts → dom/listenForKeyboardEventsFrom.d.ts}
RENAMED
File without changes
|
/package/dist/mjs/util/{listenForKeyboardEventsFrom.mjs → dom/listenForKeyboardEventsFrom.mjs}
RENAMED
File without changes
|
/package/dist/mjs/util/{listenForLongPressOrHover.d.ts → dom/listenForLongPressOrHover.d.ts}
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|