js-draw 0.1.6 → 0.1.9

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.
Files changed (138) hide show
  1. package/.eslintrc.js +1 -0
  2. package/CHANGELOG.md +16 -0
  3. package/README.md +2 -2
  4. package/dist/bundle.js +1 -1
  5. package/dist/src/Color4.js +6 -2
  6. package/dist/src/Editor.d.ts +1 -0
  7. package/dist/src/Editor.js +23 -8
  8. package/dist/src/EditorImage.d.ts +8 -13
  9. package/dist/src/EditorImage.js +51 -29
  10. package/dist/src/Viewport.d.ts +9 -1
  11. package/dist/src/Viewport.js +3 -1
  12. package/dist/src/commands/Command.d.ts +9 -8
  13. package/dist/src/commands/Command.js +15 -14
  14. package/dist/src/commands/Duplicate.d.ts +14 -0
  15. package/dist/src/commands/Duplicate.js +34 -0
  16. package/dist/src/commands/Erase.d.ts +5 -2
  17. package/dist/src/commands/Erase.js +28 -9
  18. package/dist/src/commands/SerializableCommand.d.ts +13 -0
  19. package/dist/src/commands/SerializableCommand.js +28 -0
  20. package/dist/src/commands/localization.d.ts +2 -0
  21. package/dist/src/commands/localization.js +2 -0
  22. package/dist/src/components/AbstractComponent.d.ts +15 -2
  23. package/dist/src/components/AbstractComponent.js +122 -26
  24. package/dist/src/components/SVGGlobalAttributesObject.d.ts +6 -1
  25. package/dist/src/components/SVGGlobalAttributesObject.js +23 -1
  26. package/dist/src/components/Stroke.d.ts +5 -0
  27. package/dist/src/components/Stroke.js +32 -1
  28. package/dist/src/components/Text.d.ts +11 -4
  29. package/dist/src/components/Text.js +57 -3
  30. package/dist/src/components/UnknownSVGObject.d.ts +2 -0
  31. package/dist/src/components/UnknownSVGObject.js +12 -1
  32. package/dist/src/components/builders/RectangleBuilder.d.ts +3 -1
  33. package/dist/src/components/builders/RectangleBuilder.js +17 -8
  34. package/dist/src/components/util/describeComponentList.d.ts +4 -0
  35. package/dist/src/components/util/describeComponentList.js +14 -0
  36. package/dist/src/geometry/Path.d.ts +4 -1
  37. package/dist/src/geometry/Path.js +4 -0
  38. package/dist/src/rendering/Display.d.ts +3 -0
  39. package/dist/src/rendering/Display.js +13 -0
  40. package/dist/src/rendering/RenderingStyle.d.ts +24 -0
  41. package/dist/src/rendering/RenderingStyle.js +32 -0
  42. package/dist/src/rendering/caching/RenderingCacheNode.js +5 -1
  43. package/dist/src/rendering/renderers/AbstractRenderer.d.ts +1 -8
  44. package/dist/src/rendering/renderers/AbstractRenderer.js +1 -6
  45. package/dist/src/rendering/renderers/CanvasRenderer.d.ts +2 -1
  46. package/dist/src/rendering/renderers/DummyRenderer.d.ts +2 -1
  47. package/dist/src/rendering/renderers/SVGRenderer.d.ts +2 -1
  48. package/dist/src/rendering/renderers/TextOnlyRenderer.d.ts +2 -1
  49. package/dist/src/toolbar/HTMLToolbar.d.ts +2 -1
  50. package/dist/src/toolbar/HTMLToolbar.js +57 -535
  51. package/dist/src/toolbar/icons.d.ts +5 -0
  52. package/dist/src/toolbar/icons.js +186 -13
  53. package/dist/src/toolbar/localization.d.ts +4 -0
  54. package/dist/src/toolbar/localization.js +4 -0
  55. package/dist/src/toolbar/makeColorInput.d.ts +5 -0
  56. package/dist/src/toolbar/makeColorInput.js +95 -0
  57. package/dist/src/toolbar/widgets/BaseToolWidget.d.ts +12 -0
  58. package/dist/src/toolbar/widgets/BaseToolWidget.js +44 -0
  59. package/dist/src/toolbar/widgets/BaseWidget.d.ts +32 -0
  60. package/dist/src/toolbar/widgets/BaseWidget.js +148 -0
  61. package/dist/src/toolbar/widgets/EraserWidget.d.ts +6 -0
  62. package/dist/src/toolbar/widgets/EraserWidget.js +14 -0
  63. package/dist/src/toolbar/widgets/HandToolWidget.d.ts +13 -0
  64. package/dist/src/toolbar/widgets/HandToolWidget.js +133 -0
  65. package/dist/src/toolbar/widgets/PenWidget.d.ts +20 -0
  66. package/dist/src/toolbar/widgets/PenWidget.js +131 -0
  67. package/dist/src/toolbar/widgets/SelectionWidget.d.ts +11 -0
  68. package/dist/src/toolbar/widgets/SelectionWidget.js +56 -0
  69. package/dist/src/toolbar/widgets/TextToolWidget.d.ts +13 -0
  70. package/dist/src/toolbar/widgets/TextToolWidget.js +72 -0
  71. package/dist/src/tools/Pen.js +1 -1
  72. package/dist/src/tools/PipetteTool.d.ts +20 -0
  73. package/dist/src/tools/PipetteTool.js +40 -0
  74. package/dist/src/tools/SelectionTool.d.ts +2 -0
  75. package/dist/src/tools/SelectionTool.js +41 -23
  76. package/dist/src/tools/TextTool.js +1 -1
  77. package/dist/src/tools/ToolController.d.ts +3 -1
  78. package/dist/src/tools/ToolController.js +4 -0
  79. package/dist/src/tools/localization.d.ts +2 -1
  80. package/dist/src/tools/localization.js +3 -2
  81. package/dist/src/types.d.ts +7 -2
  82. package/dist/src/types.js +1 -0
  83. package/jest.config.js +2 -0
  84. package/package.json +6 -6
  85. package/src/Color4.ts +9 -3
  86. package/src/Editor.ts +28 -11
  87. package/src/EditorImage.test.ts +5 -5
  88. package/src/EditorImage.ts +61 -20
  89. package/src/SVGLoader.ts +2 -1
  90. package/src/Viewport.ts +2 -1
  91. package/src/commands/Command.ts +21 -19
  92. package/src/commands/Duplicate.ts +49 -0
  93. package/src/commands/Erase.ts +34 -13
  94. package/src/commands/SerializableCommand.ts +41 -0
  95. package/src/commands/localization.ts +5 -0
  96. package/src/components/AbstractComponent.ts +168 -26
  97. package/src/components/SVGGlobalAttributesObject.ts +34 -2
  98. package/src/components/Stroke.test.ts +53 -0
  99. package/src/components/Stroke.ts +37 -2
  100. package/src/components/Text.test.ts +38 -0
  101. package/src/components/Text.ts +80 -5
  102. package/src/components/UnknownSVGObject.test.ts +10 -0
  103. package/src/components/UnknownSVGObject.ts +15 -1
  104. package/src/components/builders/FreehandLineBuilder.ts +2 -1
  105. package/src/components/builders/RectangleBuilder.ts +23 -8
  106. package/src/components/util/describeComponentList.ts +18 -0
  107. package/src/geometry/Path.ts +8 -1
  108. package/src/rendering/Display.ts +17 -1
  109. package/src/rendering/RenderingStyle.test.ts +68 -0
  110. package/src/rendering/RenderingStyle.ts +46 -0
  111. package/src/rendering/caching/RenderingCache.test.ts +1 -1
  112. package/src/rendering/caching/RenderingCacheNode.ts +6 -1
  113. package/src/rendering/renderers/AbstractRenderer.ts +1 -15
  114. package/src/rendering/renderers/CanvasRenderer.ts +2 -1
  115. package/src/rendering/renderers/DummyRenderer.ts +2 -1
  116. package/src/rendering/renderers/SVGRenderer.ts +2 -1
  117. package/src/rendering/renderers/TextOnlyRenderer.ts +2 -1
  118. package/src/toolbar/HTMLToolbar.ts +64 -661
  119. package/src/toolbar/icons.ts +205 -13
  120. package/src/toolbar/localization.ts +10 -2
  121. package/src/toolbar/makeColorInput.ts +120 -0
  122. package/src/toolbar/toolbar.css +116 -78
  123. package/src/toolbar/widgets/BaseToolWidget.ts +53 -0
  124. package/src/toolbar/widgets/BaseWidget.ts +175 -0
  125. package/src/toolbar/widgets/EraserWidget.ts +16 -0
  126. package/src/toolbar/widgets/HandToolWidget.ts +186 -0
  127. package/src/toolbar/widgets/PenWidget.ts +165 -0
  128. package/src/toolbar/widgets/SelectionWidget.ts +72 -0
  129. package/src/toolbar/widgets/TextToolWidget.ts +90 -0
  130. package/src/tools/Pen.ts +1 -1
  131. package/src/tools/PipetteTool.ts +56 -0
  132. package/src/tools/SelectionTool.test.ts +2 -4
  133. package/src/tools/SelectionTool.ts +47 -27
  134. package/src/tools/TextTool.ts +1 -1
  135. package/src/tools/ToolController.ts +10 -6
  136. package/src/tools/UndoRedoShortcut.test.ts +1 -1
  137. package/src/tools/localization.ts +6 -3
  138. package/src/types.ts +12 -1
@@ -0,0 +1,90 @@
1
+ import Editor from '../../Editor';
2
+ import TextTool from '../../tools/TextTool';
3
+ import { EditorEventType } from '../../types';
4
+ import { toolbarCSSPrefix } from '../HTMLToolbar';
5
+ import { makeTextIcon } from '../icons';
6
+ import { ToolbarLocalization } from '../localization';
7
+ import makeColorInput from '../makeColorInput';
8
+ import BaseToolWidget from './BaseToolWidget';
9
+
10
+ export default class TextToolWidget extends BaseToolWidget {
11
+ private updateDropdownInputs: (()=>void)|null = null;
12
+ public constructor(editor: Editor, private tool: TextTool, localization: ToolbarLocalization) {
13
+ super(editor, tool, localization);
14
+
15
+ editor.notifier.on(EditorEventType.ToolUpdated, evt => {
16
+ if (evt.kind === EditorEventType.ToolUpdated && evt.tool === tool) {
17
+ this.updateIcon();
18
+ this.updateDropdownInputs?.();
19
+ }
20
+ });
21
+ }
22
+
23
+ protected getTitle(): string {
24
+ return this.targetTool.description;
25
+ }
26
+
27
+ protected createIcon(): Element {
28
+ const textStyle = this.tool.getTextStyle();
29
+ return makeTextIcon(textStyle);
30
+ }
31
+
32
+ private static idCounter: number = 0;
33
+ protected fillDropdown(dropdown: HTMLElement): boolean {
34
+ const fontRow = document.createElement('div');
35
+ const colorRow = document.createElement('div');
36
+
37
+ const fontInput = document.createElement('select');
38
+ const fontLabel = document.createElement('label');
39
+
40
+ const [ colorInput, colorInputContainer ] = makeColorInput(this.editor, color => {
41
+ this.tool.setColor(color);
42
+ });
43
+ const colorLabel = document.createElement('label');
44
+
45
+ const fontsInInput = new Set();
46
+ const addFontToInput = (fontName: string) => {
47
+ const option = document.createElement('option');
48
+ option.value = fontName;
49
+ option.textContent = fontName;
50
+ fontInput.appendChild(option);
51
+ fontsInInput.add(fontName);
52
+ };
53
+
54
+ fontLabel.innerText = this.localizationTable.fontLabel;
55
+ colorLabel.innerText = this.localizationTable.colorLabel;
56
+
57
+ colorInput.id = `${toolbarCSSPrefix}-text-color-input-${TextToolWidget.idCounter++}`;
58
+ colorLabel.setAttribute('for', colorInput.id);
59
+
60
+ addFontToInput('monospace');
61
+ addFontToInput('serif');
62
+ addFontToInput('sans-serif');
63
+ fontInput.id = `${toolbarCSSPrefix}-text-font-input-${TextToolWidget.idCounter++}`;
64
+ fontLabel.setAttribute('for', fontInput.id);
65
+
66
+ fontInput.onchange = () => {
67
+ this.tool.setFontFamily(fontInput.value);
68
+ };
69
+
70
+ colorRow.appendChild(colorLabel);
71
+ colorRow.appendChild(colorInputContainer);
72
+
73
+ fontRow.appendChild(fontLabel);
74
+ fontRow.appendChild(fontInput);
75
+
76
+ this.updateDropdownInputs = () => {
77
+ const style = this.tool.getTextStyle();
78
+ colorInput.value = style.renderingStyle.fill.toHexString();
79
+
80
+ if (!fontsInInput.has(style.fontFamily)) {
81
+ addFontToInput(style.fontFamily);
82
+ }
83
+ fontInput.value = style.fontFamily;
84
+ };
85
+ this.updateDropdownInputs();
86
+
87
+ dropdown.replaceChildren(colorRow, fontRow);
88
+ return true;
89
+ }
90
+ }
package/src/tools/Pen.ts CHANGED
@@ -93,7 +93,7 @@ export default class Pen extends BaseTool {
93
93
 
94
94
  if (stroke.getBBox().area > 0) {
95
95
  const canFlatten = true;
96
- const action = new EditorImage.AddElementCommand(stroke, canFlatten);
96
+ const action = EditorImage.addElement(stroke, canFlatten);
97
97
  this.editor.dispatch(action);
98
98
  } else {
99
99
  console.warn('Pen: Not adding empty stroke', stroke, 'to the canvas.');
@@ -0,0 +1,56 @@
1
+ import Color4 from '../Color4';
2
+ import Editor from '../Editor';
3
+ import { PointerEvt } from '../types';
4
+ import BaseTool from './BaseTool';
5
+ import { ToolType } from './ToolController';
6
+
7
+ type ColorListener = (color: Color4|null)=>void;
8
+
9
+ export default class PipetteTool extends BaseTool {
10
+ public kind: ToolType = ToolType.Pipette;
11
+
12
+ private colorPreviewListener: ColorListener|null = null;
13
+ private colorSelectListener: ColorListener|null = null;
14
+
15
+ public constructor(
16
+ private editor: Editor,
17
+ description: string,
18
+ ) {
19
+ super(editor.notifier, description);
20
+ }
21
+
22
+ public setColorListener(
23
+ colorPreviewListener: ColorListener,
24
+
25
+ // Called when the gesture ends -- when the user has selected a color.
26
+ colorSelectListener: ColorListener,
27
+ ) {
28
+ this.colorPreviewListener = colorPreviewListener;
29
+ this.colorSelectListener = colorSelectListener;
30
+ }
31
+
32
+ public clearColorListener() {
33
+ this.colorPreviewListener = null;
34
+ this.colorSelectListener = null;
35
+ }
36
+
37
+ public onPointerDown({ current, allPointers }: PointerEvt): boolean {
38
+ if (this.colorPreviewListener && allPointers.length === 1) {
39
+ this.colorPreviewListener(this.editor.display.getColorAt(current.screenPos));
40
+ return true;
41
+ }
42
+ return false;
43
+ }
44
+
45
+ public onPointerMove({ current }: PointerEvt): void {
46
+ this.colorPreviewListener?.(this.editor.display.getColorAt(current.screenPos));
47
+ }
48
+
49
+ public onPointerUp({ current }: PointerEvt): void {
50
+ this.colorSelectListener?.(this.editor.display.getColorAt(current.screenPos));
51
+ }
52
+
53
+ public onGestureCancel(): void {
54
+ this.colorSelectListener?.(null);
55
+ }
56
+ }
@@ -2,7 +2,6 @@
2
2
 
3
3
  import Color4 from '../Color4';
4
4
  import Stroke from '../components/Stroke';
5
- import { RenderingMode } from '../rendering/Display';
6
5
  import Editor from '../Editor';
7
6
  import EditorImage from '../EditorImage';
8
7
  import Path from '../geometry/Path';
@@ -10,19 +9,18 @@ import { Vec2 } from '../geometry/Vec2';
10
9
  import { InputEvtType } from '../types';
11
10
  import SelectionTool from './SelectionTool';
12
11
  import { ToolType } from './ToolController';
12
+ import createEditor from '../testing/createEditor';
13
13
 
14
14
  const getSelectionTool = (editor: Editor): SelectionTool => {
15
15
  return editor.toolController.getMatchingTools(ToolType.Selection)[0] as SelectionTool;
16
16
  };
17
17
 
18
- const createEditor = () => new Editor(document.body, { renderingMode: RenderingMode.DummyRenderer });
19
-
20
18
  const createSquareStroke = () => {
21
19
  const testStroke = new Stroke([
22
20
  // A filled unit square
23
21
  Path.fromString('M0,0 L1,0 L1,1 L0,1 Z').toRenderable({ fill: Color4.blue }),
24
22
  ]);
25
- const addTestStrokeCommand = new EditorImage.AddElementCommand(testStroke);
23
+ const addTestStrokeCommand = EditorImage.addElement(testStroke);
26
24
 
27
25
  return { testStroke, addTestStrokeCommand };
28
26
  };
@@ -1,4 +1,5 @@
1
1
  import Command from '../commands/Command';
2
+ import Duplicate from '../commands/Duplicate';
2
3
  import Erase from '../commands/Erase';
3
4
  import AbstractComponent from '../components/AbstractComponent';
4
5
  import Editor from '../Editor';
@@ -6,6 +7,7 @@ import Mat33 from '../geometry/Mat33';
6
7
  // import Mat33 from "../geometry/Mat33";
7
8
  import Rect2 from '../geometry/Rect2';
8
9
  import { Point2, Vec2 } from '../geometry/Vec2';
10
+ import { EditorLocalization } from '../localization';
9
11
  import { EditorEventType, PointerEvt } from '../types';
10
12
  import BaseTool from './BaseTool';
11
13
  import { ToolType } from './ToolController';
@@ -263,32 +265,46 @@ class Selection {
263
265
  this.region = this.region.transformedBoundingBox(inverseTransform);
264
266
 
265
267
  // Make the commands undo-able
266
- this.editor.dispatch({
267
- apply: async (editor) => {
268
- // Approximate the new selection
269
- this.region = this.region.transformedBoundingBox(fullTransform);
270
- this.boxRotation += deltaBoxRotation;
271
- this.updateUI();
272
-
273
- await editor.asyncApplyCommands(currentTransfmCommands, updateChunkSize);
274
- this.recomputeRegion();
275
- this.updateUI();
276
- },
277
- unapply: async (editor) => {
278
- this.region = this.region.transformedBoundingBox(inverseTransform);
279
- this.boxRotation -= deltaBoxRotation;
280
- this.updateUI();
281
-
282
- await editor.asyncUnapplyCommands(currentTransfmCommands, updateChunkSize);
283
- this.recomputeRegion();
284
- this.updateUI();
285
- },
286
-
287
- description(localizationTable) {
288
- return localizationTable.transformedElements(currentTransfmCommands.length);
289
- },
290
- });
291
- }
268
+ this.editor.dispatch(new Selection.ApplyTransformationCommand(
269
+ this, currentTransfmCommands, fullTransform, inverseTransform, deltaBoxRotation
270
+ ));
271
+ }
272
+
273
+ private static ApplyTransformationCommand = class extends Command {
274
+ public constructor(
275
+ private selection: Selection,
276
+ private currentTransfmCommands: Command[],
277
+ private fullTransform: Mat33, private inverseTransform: Mat33,
278
+ private deltaBoxRotation: number,
279
+ ) {
280
+ super();
281
+ }
282
+
283
+ public async apply(editor: Editor) {
284
+ // Approximate the new selection
285
+ this.selection.region = this.selection.region.transformedBoundingBox(this.fullTransform);
286
+ this.selection.boxRotation += this.deltaBoxRotation;
287
+ this.selection.updateUI();
288
+
289
+ await editor.asyncApplyCommands(this.currentTransfmCommands, updateChunkSize);
290
+ this.selection.recomputeRegion();
291
+ this.selection.updateUI();
292
+ }
293
+
294
+ public async unapply(editor: Editor) {
295
+ this.selection.region = this.selection.region.transformedBoundingBox(this.inverseTransform);
296
+ this.selection.boxRotation -= this.deltaBoxRotation;
297
+ this.selection.updateUI();
298
+
299
+ await editor.asyncUnapplyCommands(this.currentTransfmCommands, updateChunkSize);
300
+ this.selection.recomputeRegion();
301
+ this.selection.updateUI();
302
+ }
303
+
304
+ public description(localizationTable: EditorLocalization) {
305
+ return localizationTable.transformedElements(this.currentTransfmCommands.length);
306
+ }
307
+ };
292
308
 
293
309
  // Preview the effects of the current transformation on the selection
294
310
  private previewTransformCmds() {
@@ -431,6 +447,10 @@ class Selection {
431
447
  public deleteSelectedObjects(): Command {
432
448
  return new Erase(this.selectedElems);
433
449
  }
450
+
451
+ public duplicateSelectedObjects(): Command {
452
+ return new Duplicate(this.selectedElems);
453
+ }
434
454
  }
435
455
 
436
456
  export default class SelectionTool extends BaseTool {
@@ -494,7 +514,7 @@ export default class SelectionTool extends BaseTool {
494
514
  );
495
515
 
496
516
  const selectionRect = this.selectionBox.region;
497
- this.editor.viewport.zoomTo(selectionRect, false).apply(this.editor);
517
+ this.editor.dispatchNoAnnounce(this.editor.viewport.zoomTo(selectionRect, false), false);
498
518
  }
499
519
  }
500
520
 
@@ -84,7 +84,7 @@ export default class TextTool extends BaseTool {
84
84
  this.textStyle,
85
85
  );
86
86
 
87
- const action = new EditorImage.AddElementCommand(textComponent);
87
+ const action = EditorImage.addElement(textComponent);
88
88
  this.editor.dispatch(action);
89
89
  }
90
90
  }
@@ -10,14 +10,17 @@ import Color4 from '../Color4';
10
10
  import { ToolLocalization } from './localization';
11
11
  import UndoRedoShortcut from './UndoRedoShortcut';
12
12
  import TextTool from './TextTool';
13
+ import PipetteTool from './PipetteTool';
13
14
 
14
15
  export enum ToolType {
15
- Pen,
16
- Selection,
17
- Eraser,
18
- PanZoom,
19
- Text,
20
- UndoRedoShortcut,
16
+ Pen,
17
+ Selection,
18
+ Eraser,
19
+ PanZoom,
20
+ Text,
21
+ UndoRedoShortcut,
22
+ Pipette,
23
+ Other,
21
24
  }
22
25
 
23
26
  export default class ToolController {
@@ -42,6 +45,7 @@ export default class ToolController {
42
45
  new TextTool(editor, localization.textTool, localization),
43
46
  ];
44
47
  this.tools = [
48
+ new PipetteTool(editor, localization.pipetteTool),
45
49
  panZoomTool,
46
50
  ...primaryTools,
47
51
  new UndoRedoShortcut(editor),
@@ -9,7 +9,7 @@ import { InputEvtType } from '../types';
9
9
 
10
10
  describe('UndoRedoShortcut', () => {
11
11
  const testStroke = new Stroke([Path.fromString('M0,0L10,10').toRenderable({ fill: Color4.red })]);
12
- const addTestStrokeCommand = new EditorImage.AddElementCommand(testStroke);
12
+ const addTestStrokeCommand = EditorImage.addElement(testStroke);
13
13
 
14
14
  it('ctrl+z should undo', () => {
15
15
  const editor = createEditor();
@@ -1,12 +1,14 @@
1
1
 
2
2
  export interface ToolLocalization {
3
- rightClickDragPanTool: string;
4
3
  penTool: (penId: number)=>string;
5
4
  selectionTool: string;
6
5
  eraserTool: string;
7
6
  touchPanTool: string;
8
7
  twoFingerPanZoomTool: string;
9
8
  undoRedoTool: string;
9
+ pipetteTool: string;
10
+ rightClickDragPanTool: string;
11
+
10
12
  textTool: string;
11
13
  enterTextToInsert: string;
12
14
 
@@ -18,10 +20,11 @@ export const defaultToolLocalization: ToolLocalization = {
18
20
  penTool: (penId) => `Pen ${penId}`,
19
21
  selectionTool: 'Selection',
20
22
  eraserTool: 'Eraser',
21
- touchPanTool: 'Touch Panning',
22
- twoFingerPanZoomTool: 'Panning and Zooming',
23
+ touchPanTool: 'Touch panning',
24
+ twoFingerPanZoomTool: 'Panning and zooming',
23
25
  undoRedoTool: 'Undo/Redo',
24
26
  rightClickDragPanTool: 'Right-click drag',
27
+ pipetteTool: 'Pick color from screen',
25
28
 
26
29
  textTool: 'Text',
27
30
  enterTextToInsert: 'Text to insert',
package/src/types.ts CHANGED
@@ -77,6 +77,8 @@ export type InputEvt = KeyPressEvent | WheelEvt | GestureCancelEvt | PointerEvt;
77
77
  export type EditorNotifier = EventDispatcher<EditorEventType, EditorEventDataType>;
78
78
 
79
79
 
80
+
81
+
80
82
  export enum EditorEventType {
81
83
  ToolEnabled,
82
84
  ToolDisabled,
@@ -86,6 +88,7 @@ export enum EditorEventType {
86
88
  ViewportChanged,
87
89
  DisplayResized,
88
90
  ColorPickerToggled,
91
+ ColorPickerColorSelected
89
92
  }
90
93
 
91
94
  type EditorToolEventType = EditorEventType.ToolEnabled
@@ -124,7 +127,15 @@ export interface ColorPickerToggled {
124
127
  readonly open: boolean;
125
128
  }
126
129
 
127
- export type EditorEventDataType = EditorToolEvent | EditorObjectEvent | EditorViewportChangedEvent | DisplayResizedEvent | EditorUndoStackUpdated | ColorPickerToggled;
130
+ export interface ColorPickerColorSelected {
131
+ readonly kind: EditorEventType.ColorPickerColorSelected;
132
+ readonly color: Color4;
133
+ }
134
+
135
+ export type EditorEventDataType = EditorToolEvent | EditorObjectEvent
136
+ | EditorViewportChangedEvent | DisplayResizedEvent
137
+ | EditorUndoStackUpdated
138
+ | ColorPickerToggled| ColorPickerColorSelected;
128
139
 
129
140
 
130
141
  // Returns a Promise to indicate that the event source should pause until the Promise resolves.