js-draw 0.18.2 → 0.20.0
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/.eslintrc.js +1 -0
- package/CHANGELOG.md +10 -0
- package/dist/bundle.js +2 -2
- package/dist/bundledStyles.js +1 -0
- package/dist/cjs/src/Color4.d.ts +8 -0
- package/dist/cjs/src/Color4.js +67 -0
- package/dist/cjs/src/Editor.d.ts +2 -2
- package/dist/cjs/src/Editor.js +7 -7
- package/dist/cjs/src/SVGLoader.js +77 -12
- package/dist/cjs/src/Viewport.d.ts +2 -0
- package/dist/cjs/src/Viewport.js +6 -2
- package/dist/cjs/src/components/AbstractComponent.d.ts +2 -2
- package/dist/cjs/src/components/AbstractComponent.js +3 -3
- package/dist/cjs/src/components/{ImageBackground.d.ts → BackgroundComponent.d.ts} +23 -3
- package/dist/cjs/src/components/BackgroundComponent.js +309 -0
- package/dist/cjs/src/components/RestylableComponent.d.ts +21 -2
- package/dist/cjs/src/components/Stroke.d.ts +35 -0
- package/dist/cjs/src/components/Stroke.js +37 -3
- package/dist/cjs/src/components/TextComponent.d.ts +27 -17
- package/dist/cjs/src/components/TextComponent.js +23 -1
- package/dist/cjs/src/components/lib.d.ts +4 -3
- package/dist/cjs/src/components/lib.js +2 -2
- package/dist/cjs/src/components/util/StrokeSmoother.js +25 -15
- package/dist/cjs/src/lib.d.ts +30 -0
- package/dist/cjs/src/lib.js +30 -0
- package/dist/cjs/src/localizations/de.js +1 -1
- package/dist/cjs/src/localizations/es.js +1 -1
- package/dist/cjs/src/math/Path.js +1 -1
- package/dist/cjs/src/math/polynomial/QuadraticBezier.d.ts +28 -0
- package/dist/cjs/src/math/polynomial/QuadraticBezier.js +115 -0
- package/dist/cjs/src/math/polynomial/solveQuadratic.d.ts +6 -0
- package/dist/cjs/src/math/polynomial/solveQuadratic.js +36 -0
- package/dist/cjs/src/rendering/RenderingStyle.d.ts +4 -4
- package/dist/cjs/src/rendering/TextRenderingStyle.d.ts +10 -10
- package/dist/cjs/src/rendering/lib.d.ts +2 -0
- package/dist/cjs/src/rendering/renderers/AbstractRenderer.d.ts +2 -2
- package/dist/cjs/src/rendering/renderers/CanvasRenderer.d.ts +2 -2
- package/dist/cjs/src/rendering/renderers/CanvasRenderer.js +5 -3
- package/dist/cjs/src/rendering/renderers/DummyRenderer.d.ts +2 -2
- package/dist/cjs/src/rendering/renderers/SVGRenderer.d.ts +2 -2
- package/dist/cjs/src/rendering/renderers/SVGRenderer.js +15 -6
- package/dist/cjs/src/rendering/renderers/TextOnlyRenderer.d.ts +2 -2
- package/dist/cjs/src/toolbar/IconProvider.d.ts +2 -2
- package/dist/cjs/src/toolbar/localization.d.ts +2 -1
- package/dist/cjs/src/toolbar/localization.js +3 -2
- package/dist/cjs/src/toolbar/widgets/BaseWidget.js +1 -1
- package/dist/cjs/src/toolbar/widgets/DocumentPropertiesWidget.d.ts +5 -0
- package/dist/cjs/src/toolbar/widgets/DocumentPropertiesWidget.js +77 -2
- package/dist/cjs/src/toolbar/widgets/PenToolWidget.js +1 -1
- package/dist/cjs/src/tools/FindTool.js +1 -1
- package/dist/cjs/src/tools/SoundUITool.d.ts +24 -0
- package/dist/cjs/src/tools/SoundUITool.js +164 -0
- package/dist/cjs/src/tools/TextTool.d.ts +2 -2
- package/dist/cjs/src/tools/ToolController.js +6 -1
- package/dist/cjs/src/tools/lib.d.ts +1 -0
- package/dist/cjs/src/tools/lib.js +3 -1
- package/dist/cjs/src/tools/localization.d.ts +3 -0
- package/dist/cjs/src/tools/localization.js +3 -0
- package/dist/mjs/src/Color4.d.ts +8 -0
- package/dist/mjs/src/Color4.mjs +64 -0
- package/dist/mjs/src/Editor.d.ts +2 -2
- package/dist/mjs/src/Editor.mjs +6 -6
- package/dist/mjs/src/SVGLoader.mjs +76 -11
- package/dist/mjs/src/Viewport.d.ts +2 -0
- package/dist/mjs/src/Viewport.mjs +6 -2
- package/dist/mjs/src/components/AbstractComponent.d.ts +2 -2
- package/dist/mjs/src/components/AbstractComponent.mjs +3 -3
- package/dist/mjs/src/components/{ImageBackground.d.ts → BackgroundComponent.d.ts} +23 -3
- package/dist/mjs/src/components/BackgroundComponent.mjs +279 -0
- package/dist/mjs/src/components/RestylableComponent.d.ts +21 -2
- package/dist/mjs/src/components/Stroke.d.ts +35 -0
- package/dist/mjs/src/components/Stroke.mjs +37 -3
- package/dist/mjs/src/components/TextComponent.d.ts +27 -17
- package/dist/mjs/src/components/TextComponent.mjs +23 -1
- package/dist/mjs/src/components/lib.d.ts +4 -3
- package/dist/mjs/src/components/lib.mjs +2 -2
- package/dist/mjs/src/components/util/StrokeSmoother.mjs +25 -15
- package/dist/mjs/src/lib.d.ts +30 -0
- package/dist/mjs/src/lib.mjs +30 -0
- package/dist/mjs/src/localizations/de.mjs +1 -1
- package/dist/mjs/src/localizations/es.mjs +1 -1
- package/dist/mjs/src/math/Path.mjs +1 -1
- package/dist/mjs/src/math/polynomial/QuadraticBezier.d.ts +28 -0
- package/dist/mjs/src/math/polynomial/QuadraticBezier.mjs +109 -0
- package/dist/mjs/src/math/polynomial/solveQuadratic.d.ts +6 -0
- package/dist/mjs/src/math/polynomial/solveQuadratic.mjs +34 -0
- package/dist/mjs/src/rendering/RenderingStyle.d.ts +4 -4
- package/dist/mjs/src/rendering/TextRenderingStyle.d.ts +10 -10
- package/dist/mjs/src/rendering/lib.d.ts +2 -0
- package/dist/mjs/src/rendering/renderers/AbstractRenderer.d.ts +2 -2
- package/dist/mjs/src/rendering/renderers/CanvasRenderer.d.ts +2 -2
- package/dist/mjs/src/rendering/renderers/CanvasRenderer.mjs +5 -3
- package/dist/mjs/src/rendering/renderers/DummyRenderer.d.ts +2 -2
- package/dist/mjs/src/rendering/renderers/SVGRenderer.d.ts +2 -2
- package/dist/mjs/src/rendering/renderers/SVGRenderer.mjs +15 -6
- package/dist/mjs/src/rendering/renderers/TextOnlyRenderer.d.ts +2 -2
- package/dist/mjs/src/toolbar/IconProvider.d.ts +2 -2
- package/dist/mjs/src/toolbar/localization.d.ts +2 -1
- package/dist/mjs/src/toolbar/localization.mjs +3 -2
- package/dist/mjs/src/toolbar/widgets/BaseWidget.mjs +1 -1
- package/dist/mjs/src/toolbar/widgets/DocumentPropertiesWidget.d.ts +5 -0
- package/dist/mjs/src/toolbar/widgets/DocumentPropertiesWidget.mjs +54 -2
- package/dist/mjs/src/toolbar/widgets/PenToolWidget.mjs +1 -1
- package/dist/mjs/src/tools/FindTool.mjs +1 -1
- package/dist/mjs/src/tools/SoundUITool.d.ts +24 -0
- package/dist/mjs/src/tools/SoundUITool.mjs +158 -0
- package/dist/mjs/src/tools/TextTool.d.ts +2 -2
- package/dist/mjs/src/tools/ToolController.mjs +6 -1
- package/dist/mjs/src/tools/lib.d.ts +1 -0
- package/dist/mjs/src/tools/lib.mjs +1 -0
- package/dist/mjs/src/tools/localization.d.ts +3 -0
- package/dist/mjs/src/tools/localization.mjs +3 -0
- package/jest.config.js +1 -1
- package/package.json +19 -17
- package/src/Editor.css +2 -2
- package/src/tools/SoundUITool.css +15 -0
- package/src/tools/tools.css +4 -0
- package/dist/cjs/src/components/ImageBackground.js +0 -146
- package/dist/mjs/src/components/ImageBackground.mjs +0 -139
- package/src/Color4.test.ts +0 -40
- package/src/Color4.ts +0 -236
- package/src/Editor.loadFrom.test.ts +0 -24
- package/src/Editor.toSVG.test.ts +0 -111
- package/src/Editor.ts +0 -1122
- package/src/EditorImage.test.ts +0 -120
- package/src/EditorImage.ts +0 -603
- package/src/EventDispatcher.test.ts +0 -123
- package/src/EventDispatcher.ts +0 -71
- package/src/Pointer.ts +0 -127
- package/src/SVGLoader.test.ts +0 -114
- package/src/SVGLoader.ts +0 -511
- package/src/UndoRedoHistory.test.ts +0 -33
- package/src/UndoRedoHistory.ts +0 -102
- package/src/Viewport.ts +0 -319
- package/src/bundle/bundled.ts +0 -7
- package/src/commands/Command.ts +0 -45
- package/src/commands/Duplicate.ts +0 -48
- package/src/commands/Erase.ts +0 -74
- package/src/commands/SerializableCommand.ts +0 -49
- package/src/commands/UnresolvedCommand.ts +0 -37
- package/src/commands/invertCommand.ts +0 -51
- package/src/commands/lib.ts +0 -16
- package/src/commands/localization.ts +0 -47
- package/src/commands/uniteCommands.test.ts +0 -23
- package/src/commands/uniteCommands.ts +0 -135
- package/src/components/AbstractComponent.transformBy.test.ts +0 -22
- package/src/components/AbstractComponent.ts +0 -364
- package/src/components/ImageBackground.test.ts +0 -35
- package/src/components/ImageBackground.ts +0 -176
- package/src/components/ImageComponent.ts +0 -171
- package/src/components/RestylableComponent.ts +0 -142
- package/src/components/SVGGlobalAttributesObject.ts +0 -81
- package/src/components/Stroke.test.ts +0 -139
- package/src/components/Stroke.ts +0 -245
- package/src/components/TextComponent.test.ts +0 -99
- package/src/components/TextComponent.ts +0 -315
- package/src/components/UnknownSVGObject.test.ts +0 -10
- package/src/components/UnknownSVGObject.ts +0 -60
- package/src/components/builders/ArrowBuilder.ts +0 -107
- package/src/components/builders/FreehandLineBuilder.ts +0 -212
- package/src/components/builders/LineBuilder.ts +0 -77
- package/src/components/builders/PressureSensitiveFreehandLineBuilder.ts +0 -454
- package/src/components/builders/RectangleBuilder.ts +0 -74
- package/src/components/builders/types.ts +0 -15
- package/src/components/lib.ts +0 -25
- package/src/components/localization.ts +0 -22
- package/src/components/util/StrokeSmoother.ts +0 -293
- package/src/components/util/describeComponentList.ts +0 -18
- package/src/lib.ts +0 -37
- package/src/localization.ts +0 -34
- package/src/localizations/de.ts +0 -98
- package/src/localizations/en.ts +0 -8
- package/src/localizations/es.ts +0 -74
- package/src/localizations/getLocalizationTable.test.ts +0 -27
- package/src/localizations/getLocalizationTable.ts +0 -55
- package/src/math/LineSegment2.test.ts +0 -99
- package/src/math/LineSegment2.ts +0 -160
- package/src/math/Mat33.test.ts +0 -244
- package/src/math/Mat33.ts +0 -437
- package/src/math/Path.fromString.test.ts +0 -223
- package/src/math/Path.test.ts +0 -198
- package/src/math/Path.toString.test.ts +0 -77
- package/src/math/Path.ts +0 -790
- package/src/math/Rect2.test.ts +0 -204
- package/src/math/Rect2.ts +0 -315
- package/src/math/Triangle.ts +0 -29
- package/src/math/Vec2.test.ts +0 -30
- package/src/math/Vec2.ts +0 -18
- package/src/math/Vec3.test.ts +0 -44
- package/src/math/Vec3.ts +0 -218
- package/src/math/lib.ts +0 -15
- package/src/math/rounding.test.ts +0 -65
- package/src/math/rounding.ts +0 -156
- package/src/rendering/Display.ts +0 -249
- package/src/rendering/RenderingStyle.test.ts +0 -68
- package/src/rendering/RenderingStyle.ts +0 -55
- package/src/rendering/TextRenderingStyle.ts +0 -45
- package/src/rendering/caching/CacheRecord.test.ts +0 -49
- package/src/rendering/caching/CacheRecord.ts +0 -77
- package/src/rendering/caching/CacheRecordManager.ts +0 -71
- package/src/rendering/caching/RenderingCache.test.ts +0 -44
- package/src/rendering/caching/RenderingCache.ts +0 -66
- package/src/rendering/caching/RenderingCacheNode.ts +0 -405
- package/src/rendering/caching/testUtils.ts +0 -35
- package/src/rendering/caching/types.ts +0 -34
- package/src/rendering/lib.ts +0 -6
- package/src/rendering/localization.ts +0 -20
- package/src/rendering/renderers/AbstractRenderer.ts +0 -222
- package/src/rendering/renderers/CanvasRenderer.ts +0 -296
- package/src/rendering/renderers/DummyRenderer.test.ts +0 -42
- package/src/rendering/renderers/DummyRenderer.ts +0 -136
- package/src/rendering/renderers/SVGRenderer.ts +0 -354
- package/src/rendering/renderers/TextOnlyRenderer.ts +0 -70
- package/src/testing/beforeEachFile.ts +0 -8
- package/src/testing/createEditor.ts +0 -11
- package/src/testing/global.d.ts +0 -17
- package/src/testing/lib.ts +0 -3
- package/src/testing/loadExpectExtensions.ts +0 -25
- package/src/testing/sendPenEvent.ts +0 -31
- package/src/testing/sendTouchEvent.ts +0 -78
- package/src/toolbar/HTMLToolbar.ts +0 -492
- package/src/toolbar/IconProvider.ts +0 -736
- package/src/toolbar/lib.ts +0 -4
- package/src/toolbar/localization.ts +0 -106
- package/src/toolbar/makeColorInput.ts +0 -145
- package/src/toolbar/types.ts +0 -5
- package/src/toolbar/widgets/ActionButtonWidget.ts +0 -39
- package/src/toolbar/widgets/BaseToolWidget.ts +0 -56
- package/src/toolbar/widgets/BaseWidget.ts +0 -377
- package/src/toolbar/widgets/DocumentPropertiesWidget.ts +0 -167
- package/src/toolbar/widgets/EraserToolWidget.ts +0 -85
- package/src/toolbar/widgets/HandToolWidget.ts +0 -250
- package/src/toolbar/widgets/InsertImageWidget.ts +0 -223
- package/src/toolbar/widgets/OverflowWidget.ts +0 -92
- package/src/toolbar/widgets/PenToolWidget.ts +0 -288
- package/src/toolbar/widgets/SelectionToolWidget.ts +0 -190
- package/src/toolbar/widgets/TextToolWidget.ts +0 -145
- package/src/toolbar/widgets/lib.ts +0 -13
- package/src/tools/BaseTool.ts +0 -76
- package/src/tools/Eraser.test.ts +0 -103
- package/src/tools/Eraser.ts +0 -139
- package/src/tools/FindTool.ts +0 -152
- package/src/tools/PanZoom.test.ts +0 -310
- package/src/tools/PanZoom.ts +0 -520
- package/src/tools/PasteHandler.ts +0 -95
- package/src/tools/Pen.test.ts +0 -194
- package/src/tools/Pen.ts +0 -226
- package/src/tools/PipetteTool.ts +0 -55
- package/src/tools/SelectionTool/SelectAllShortcutHandler.ts +0 -28
- package/src/tools/SelectionTool/Selection.ts +0 -607
- package/src/tools/SelectionTool/SelectionHandle.ts +0 -108
- package/src/tools/SelectionTool/SelectionTool.test.ts +0 -261
- package/src/tools/SelectionTool/SelectionTool.ts +0 -480
- package/src/tools/SelectionTool/TransformMode.ts +0 -114
- package/src/tools/SelectionTool/types.ts +0 -11
- package/src/tools/TextTool.ts +0 -326
- package/src/tools/ToolController.ts +0 -178
- package/src/tools/ToolEnabledGroup.ts +0 -14
- package/src/tools/ToolSwitcherShortcut.ts +0 -39
- package/src/tools/ToolbarShortcutHandler.ts +0 -34
- package/src/tools/UndoRedoShortcut.test.ts +0 -56
- package/src/tools/UndoRedoShortcut.ts +0 -25
- package/src/tools/lib.ts +0 -21
- package/src/tools/localization.ts +0 -66
- package/src/types.ts +0 -234
- package/src/util/assertions.ts +0 -55
- package/src/util/fileToBase64.ts +0 -18
- package/src/util/untilNextAnimationFrame.ts +0 -9
- package/src/util/waitForTimeout.ts +0 -9
package/src/toolbar/lib.ts
DELETED
@@ -1,106 +0,0 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
export interface ToolbarLocalization {
|
4
|
-
fontLabel: string;
|
5
|
-
textSize: string;
|
6
|
-
touchPanning: string;
|
7
|
-
lockRotation: string;
|
8
|
-
outlinedRectanglePen: string;
|
9
|
-
filledRectanglePen: string;
|
10
|
-
linePen: string;
|
11
|
-
arrowPen: string;
|
12
|
-
image: string;
|
13
|
-
inputAltText: string;
|
14
|
-
chooseFile: string;
|
15
|
-
cancel: string;
|
16
|
-
submit: string;
|
17
|
-
freehandPen: string;
|
18
|
-
pressureSensitiveFreehandPen: string;
|
19
|
-
selectObjectType: string;
|
20
|
-
colorLabel: string;
|
21
|
-
pen: string;
|
22
|
-
eraser: string;
|
23
|
-
select: string;
|
24
|
-
handTool: string;
|
25
|
-
thicknessLabel: string;
|
26
|
-
resizeImageToSelection: string;
|
27
|
-
deleteSelection: string;
|
28
|
-
duplicateSelection: string;
|
29
|
-
pickColorFromScreen: string;
|
30
|
-
clickToPickColorAnnouncement: string;
|
31
|
-
reformatSelection: string;
|
32
|
-
undo: string;
|
33
|
-
redo: string;
|
34
|
-
zoom: string;
|
35
|
-
resetView: string;
|
36
|
-
selectionToolKeyboardShortcuts: string;
|
37
|
-
paste: string;
|
38
|
-
documentProperties: string;
|
39
|
-
backgroundColor: string;
|
40
|
-
imageWidthOption: string;
|
41
|
-
imageHeightOption: string;
|
42
|
-
toggleOverflow: string,
|
43
|
-
|
44
|
-
errorImageHasZeroSize: string;
|
45
|
-
|
46
|
-
dropdownShown: (toolName: string)=> string;
|
47
|
-
dropdownHidden: (toolName: string)=> string;
|
48
|
-
zoomLevel: (zoomPercentage: number)=> string;
|
49
|
-
colorChangedAnnouncement: (color: string)=> string;
|
50
|
-
imageSize: (size: number, units: string)=> string;
|
51
|
-
imageLoadError: (message: string)=> string;
|
52
|
-
}
|
53
|
-
|
54
|
-
export const defaultToolbarLocalization: ToolbarLocalization = {
|
55
|
-
pen: 'Pen',
|
56
|
-
eraser: 'Eraser',
|
57
|
-
select: 'Select',
|
58
|
-
handTool: 'Pan',
|
59
|
-
zoom: 'Zoom',
|
60
|
-
image: 'Image',
|
61
|
-
reformatSelection: 'Format selection',
|
62
|
-
inputAltText: 'Alt text: ',
|
63
|
-
chooseFile: 'Choose file: ',
|
64
|
-
submit: 'Submit',
|
65
|
-
cancel: 'Cancel',
|
66
|
-
resetView: 'Reset view',
|
67
|
-
thicknessLabel: 'Thickness: ',
|
68
|
-
colorLabel: 'Color: ',
|
69
|
-
fontLabel: 'Font: ',
|
70
|
-
textSize: 'Size: ',
|
71
|
-
resizeImageToSelection: 'Resize image to selection',
|
72
|
-
deleteSelection: 'Delete selection',
|
73
|
-
duplicateSelection: 'Duplicate selection',
|
74
|
-
undo: 'Undo',
|
75
|
-
redo: 'Redo',
|
76
|
-
selectObjectType: 'Object type: ',
|
77
|
-
pickColorFromScreen: 'Pick color from screen',
|
78
|
-
clickToPickColorAnnouncement: 'Click on the screen to pick a color',
|
79
|
-
selectionToolKeyboardShortcuts: 'Selection tool: Use arrow keys to move selected items, lowercase/uppercase ‘i’ and ‘o’ to resize.',
|
80
|
-
documentProperties: 'Document',
|
81
|
-
backgroundColor: 'Background Color: ',
|
82
|
-
imageWidthOption: 'Width: ',
|
83
|
-
imageHeightOption: 'Height: ',
|
84
|
-
toggleOverflow: 'More',
|
85
|
-
|
86
|
-
touchPanning: 'Touchscreen panning',
|
87
|
-
|
88
|
-
freehandPen: 'Freehand',
|
89
|
-
pressureSensitiveFreehandPen: 'Freehand (pressure sensitive)',
|
90
|
-
arrowPen: 'Arrow',
|
91
|
-
linePen: 'Line',
|
92
|
-
outlinedRectanglePen: 'Outlined rectangle',
|
93
|
-
filledRectanglePen: 'Filled rectangle',
|
94
|
-
lockRotation: 'Lock rotation',
|
95
|
-
|
96
|
-
paste: 'Paste',
|
97
|
-
|
98
|
-
dropdownShown: (toolName) => `Dropdown for ${toolName} shown`,
|
99
|
-
dropdownHidden: (toolName) => `Dropdown for ${toolName} hidden`,
|
100
|
-
zoomLevel: (zoomPercent: number) => `Zoom: ${zoomPercent}%`,
|
101
|
-
colorChangedAnnouncement: (color: string) => `Color changed to ${color}`,
|
102
|
-
imageSize: (size: number, units: string) => `Image size: ${size} ${units}`,
|
103
|
-
|
104
|
-
errorImageHasZeroSize: 'Error: Image has zero size',
|
105
|
-
imageLoadError: (message: string)=> `Error loading image: ${message}`,
|
106
|
-
};
|
@@ -1,145 +0,0 @@
|
|
1
|
-
import Color4 from '../Color4';
|
2
|
-
import Editor from '../Editor';
|
3
|
-
import PipetteTool from '../tools/PipetteTool';
|
4
|
-
import { EditorEventType } from '../types';
|
5
|
-
|
6
|
-
type OnColorChangeListener = (color: Color4)=>void;
|
7
|
-
type SetColorCallback = (color: Color4|string) => void;
|
8
|
-
|
9
|
-
// Returns [ color input, input container, callback to change the color value ].
|
10
|
-
export const makeColorInput = (
|
11
|
-
editor: Editor, onColorChange: OnColorChangeListener
|
12
|
-
): [ HTMLInputElement, HTMLElement, SetColorCallback ] => {
|
13
|
-
|
14
|
-
const colorInputContainer = document.createElement('span');
|
15
|
-
const colorInput = document.createElement('input');
|
16
|
-
|
17
|
-
colorInput.type = 'button';
|
18
|
-
colorInput.classList.add('coloris_input');
|
19
|
-
colorInputContainer.classList.add('color-input-container');
|
20
|
-
|
21
|
-
colorInputContainer.appendChild(colorInput);
|
22
|
-
const pipetteController = addPipetteTool(editor, colorInputContainer, (color: Color4) => {
|
23
|
-
colorInput.value = color.toHexString();
|
24
|
-
onInputEnd();
|
25
|
-
|
26
|
-
// Update the color preview, if it exists (may be managed by Coloris).
|
27
|
-
const parentElem = colorInput.parentElement;
|
28
|
-
if (parentElem && parentElem.classList.contains('clr-field')) {
|
29
|
-
parentElem.style.color = colorInput.value;
|
30
|
-
}
|
31
|
-
});
|
32
|
-
|
33
|
-
let currentColor: Color4|undefined;
|
34
|
-
const handleColorInput = () => {
|
35
|
-
currentColor = Color4.fromHex(colorInput.value);
|
36
|
-
};
|
37
|
-
|
38
|
-
// Only change the pen color when we finish sending input (this limits the number of
|
39
|
-
// editor events triggered and accessibility announcements).
|
40
|
-
const onInputEnd = () => {
|
41
|
-
handleColorInput();
|
42
|
-
|
43
|
-
if (currentColor) {
|
44
|
-
editor.announceForAccessibility(
|
45
|
-
editor.localization.colorChangedAnnouncement(currentColor.toHexString())
|
46
|
-
);
|
47
|
-
onColorChange(currentColor);
|
48
|
-
editor.notifier.dispatch(EditorEventType.ColorPickerColorSelected, {
|
49
|
-
kind: EditorEventType.ColorPickerColorSelected,
|
50
|
-
color: currentColor,
|
51
|
-
});
|
52
|
-
}
|
53
|
-
};
|
54
|
-
|
55
|
-
colorInput.oninput = handleColorInput;
|
56
|
-
colorInput.addEventListener('open', () => {
|
57
|
-
editor.notifier.dispatch(EditorEventType.ColorPickerToggled, {
|
58
|
-
kind: EditorEventType.ColorPickerToggled,
|
59
|
-
open: true,
|
60
|
-
});
|
61
|
-
pipetteController.cancel();
|
62
|
-
});
|
63
|
-
colorInput.addEventListener('close', () => {
|
64
|
-
editor.notifier.dispatch(EditorEventType.ColorPickerToggled, {
|
65
|
-
kind: EditorEventType.ColorPickerToggled,
|
66
|
-
open: false,
|
67
|
-
});
|
68
|
-
onInputEnd();
|
69
|
-
});
|
70
|
-
|
71
|
-
const setColorInputValue = (color: Color4|string) => {
|
72
|
-
if (typeof color === 'object') {
|
73
|
-
color = color.toHexString();
|
74
|
-
}
|
75
|
-
|
76
|
-
colorInput.value = color;
|
77
|
-
|
78
|
-
// Fire all color event listeners. See
|
79
|
-
// https://github.com/mdbassit/Coloris#manually-updating-the-thumbnail
|
80
|
-
colorInput.dispatchEvent(new Event('input', { bubbles: true }));
|
81
|
-
};
|
82
|
-
|
83
|
-
return [ colorInput, colorInputContainer, setColorInputValue ];
|
84
|
-
};
|
85
|
-
|
86
|
-
const addPipetteTool = (editor: Editor, container: HTMLElement, onColorChange: OnColorChangeListener) => {
|
87
|
-
const pipetteButton = document.createElement('button');
|
88
|
-
pipetteButton.classList.add('pipetteButton');
|
89
|
-
pipetteButton.title = editor.localization.pickColorFromScreen;
|
90
|
-
pipetteButton.setAttribute('alt', pipetteButton.title);
|
91
|
-
|
92
|
-
const updatePipetteIcon = (color?: Color4) => {
|
93
|
-
pipetteButton.replaceChildren(editor.icons.makePipetteIcon(color));
|
94
|
-
};
|
95
|
-
updatePipetteIcon();
|
96
|
-
|
97
|
-
const pipetteTool: PipetteTool|undefined = editor.toolController.getMatchingTools(PipetteTool)[0];
|
98
|
-
const endColorSelectMode = () => {
|
99
|
-
pipetteTool?.clearColorListener();
|
100
|
-
updatePipetteIcon();
|
101
|
-
pipetteButton.classList.remove('active');
|
102
|
-
};
|
103
|
-
const pipetteColorSelect = (color: Color4|null) => {
|
104
|
-
endColorSelectMode();
|
105
|
-
|
106
|
-
if (color) {
|
107
|
-
onColorChange(color);
|
108
|
-
}
|
109
|
-
};
|
110
|
-
const pipetteColorPreview = (color: Color4|null) => {
|
111
|
-
if (color) {
|
112
|
-
updatePipetteIcon(color);
|
113
|
-
} else {
|
114
|
-
updatePipetteIcon();
|
115
|
-
}
|
116
|
-
};
|
117
|
-
|
118
|
-
pipetteButton.onclick = () => {
|
119
|
-
// If already picking, cancel it.
|
120
|
-
if (pipetteButton.classList.contains('active')) {
|
121
|
-
endColorSelectMode();
|
122
|
-
return;
|
123
|
-
}
|
124
|
-
|
125
|
-
pipetteTool?.setColorListener(
|
126
|
-
pipetteColorPreview,
|
127
|
-
pipetteColorSelect,
|
128
|
-
);
|
129
|
-
if (pipetteTool) {
|
130
|
-
pipetteButton.classList.add('active');
|
131
|
-
editor.announceForAccessibility(editor.localization.clickToPickColorAnnouncement);
|
132
|
-
}
|
133
|
-
};
|
134
|
-
|
135
|
-
container.appendChild(pipetteButton);
|
136
|
-
|
137
|
-
return {
|
138
|
-
// Cancel a pipette color selection if one is in progress.
|
139
|
-
cancel: () => {
|
140
|
-
endColorSelectMode();
|
141
|
-
},
|
142
|
-
};
|
143
|
-
};
|
144
|
-
|
145
|
-
export default makeColorInput;
|
package/src/toolbar/types.ts
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
import Editor from '../../Editor';
|
2
|
-
import { ToolbarLocalization } from '../localization';
|
3
|
-
import BaseWidget from './BaseWidget';
|
4
|
-
|
5
|
-
export default class ActionButtonWidget extends BaseWidget {
|
6
|
-
public constructor(
|
7
|
-
editor: Editor,
|
8
|
-
id: string,
|
9
|
-
|
10
|
-
protected makeIcon: ()=> Element|null,
|
11
|
-
protected title: string,
|
12
|
-
protected clickAction: ()=>void,
|
13
|
-
|
14
|
-
localizationTable?: ToolbarLocalization,
|
15
|
-
protected mustBeToplevel: boolean = false,
|
16
|
-
) {
|
17
|
-
super(editor, id, localizationTable);
|
18
|
-
}
|
19
|
-
|
20
|
-
protected handleClick() {
|
21
|
-
this.clickAction();
|
22
|
-
}
|
23
|
-
|
24
|
-
protected getTitle(): string {
|
25
|
-
return this.title;
|
26
|
-
}
|
27
|
-
|
28
|
-
protected createIcon(): Element|null {
|
29
|
-
return this.makeIcon();
|
30
|
-
}
|
31
|
-
|
32
|
-
protected fillDropdown(_dropdown: HTMLElement): boolean {
|
33
|
-
return false;
|
34
|
-
}
|
35
|
-
|
36
|
-
public canBeInOverflowMenu(): boolean {
|
37
|
-
return !this.mustBeToplevel;
|
38
|
-
}
|
39
|
-
}
|
@@ -1,56 +0,0 @@
|
|
1
|
-
import Editor from '../../Editor';
|
2
|
-
import BaseTool from '../../tools/BaseTool';
|
3
|
-
import { EditorEventType } from '../../types';
|
4
|
-
import { ToolbarLocalization } from '../localization';
|
5
|
-
import BaseWidget from './BaseWidget';
|
6
|
-
|
7
|
-
export default abstract class BaseToolWidget extends BaseWidget {
|
8
|
-
public constructor(
|
9
|
-
protected editor: Editor,
|
10
|
-
protected targetTool: BaseTool,
|
11
|
-
id: string,
|
12
|
-
localizationTable?: ToolbarLocalization,
|
13
|
-
) {
|
14
|
-
super(editor, id, localizationTable);
|
15
|
-
|
16
|
-
editor.notifier.on(EditorEventType.ToolEnabled, toolEvt => {
|
17
|
-
if (toolEvt.kind !== EditorEventType.ToolEnabled) {
|
18
|
-
throw new Error('Incorrect event type! (Expected ToolEnabled)');
|
19
|
-
}
|
20
|
-
|
21
|
-
if (toolEvt.tool === targetTool) {
|
22
|
-
this.setSelected(true);
|
23
|
-
}
|
24
|
-
});
|
25
|
-
|
26
|
-
editor.notifier.on(EditorEventType.ToolDisabled, toolEvt => {
|
27
|
-
if (toolEvt.kind !== EditorEventType.ToolDisabled) {
|
28
|
-
throw new Error('Incorrect event type! (Expected ToolDisabled)');
|
29
|
-
}
|
30
|
-
|
31
|
-
if (toolEvt.tool === targetTool) {
|
32
|
-
this.setSelected(false);
|
33
|
-
this.setDropdownVisible(false);
|
34
|
-
}
|
35
|
-
});
|
36
|
-
}
|
37
|
-
|
38
|
-
protected handleClick() {
|
39
|
-
if (this.hasDropdown) {
|
40
|
-
if (!this.targetTool.isEnabled()) {
|
41
|
-
this.targetTool.setEnabled(true);
|
42
|
-
} else {
|
43
|
-
this.setDropdownVisible(!this.isDropdownVisible());
|
44
|
-
}
|
45
|
-
} else {
|
46
|
-
this.targetTool.setEnabled(!this.targetTool.isEnabled());
|
47
|
-
}
|
48
|
-
}
|
49
|
-
|
50
|
-
public addTo(parent: HTMLElement) {
|
51
|
-
const result = super.addTo(parent);
|
52
|
-
this.setSelected(this.targetTool.isEnabled());
|
53
|
-
|
54
|
-
return result;
|
55
|
-
}
|
56
|
-
}
|