js-draw 0.7.2 → 0.9.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.
Files changed (82) hide show
  1. package/.github/ISSUE_TEMPLATE/translation.md +1 -0
  2. package/CHANGELOG.md +12 -0
  3. package/dist/bundle.js +1 -1
  4. package/dist/src/Color4.js +3 -0
  5. package/dist/src/SVGLoader.js +5 -7
  6. package/dist/src/components/Stroke.js +10 -3
  7. package/dist/src/components/builders/FreehandLineBuilder.d.ts +10 -23
  8. package/dist/src/components/builders/FreehandLineBuilder.js +70 -396
  9. package/dist/src/components/builders/PressureSensitiveFreehandLineBuilder.d.ts +36 -0
  10. package/dist/src/components/builders/PressureSensitiveFreehandLineBuilder.js +339 -0
  11. package/dist/src/components/lib.d.ts +2 -0
  12. package/dist/src/components/lib.js +2 -0
  13. package/dist/src/components/util/StrokeSmoother.d.ts +35 -0
  14. package/dist/src/components/util/StrokeSmoother.js +206 -0
  15. package/dist/src/math/Mat33.d.ts +2 -0
  16. package/dist/src/math/Mat33.js +4 -0
  17. package/dist/src/math/Path.d.ts +2 -0
  18. package/dist/src/math/Path.js +44 -0
  19. package/dist/src/rendering/renderers/CanvasRenderer.js +2 -0
  20. package/dist/src/rendering/renderers/SVGRenderer.d.ts +2 -0
  21. package/dist/src/rendering/renderers/SVGRenderer.js +20 -0
  22. package/dist/src/toolbar/HTMLToolbar.d.ts +3 -0
  23. package/dist/src/toolbar/HTMLToolbar.js +24 -0
  24. package/dist/src/toolbar/IconProvider.d.ts +1 -0
  25. package/dist/src/toolbar/IconProvider.js +43 -1
  26. package/dist/src/toolbar/localization.d.ts +2 -0
  27. package/dist/src/toolbar/localization.js +2 -0
  28. package/dist/src/toolbar/makeColorInput.d.ts +2 -1
  29. package/dist/src/toolbar/makeColorInput.js +13 -2
  30. package/dist/src/toolbar/widgets/ActionButtonWidget.d.ts +1 -1
  31. package/dist/src/toolbar/widgets/ActionButtonWidget.js +2 -2
  32. package/dist/src/toolbar/widgets/BaseToolWidget.d.ts +1 -2
  33. package/dist/src/toolbar/widgets/BaseToolWidget.js +2 -3
  34. package/dist/src/toolbar/widgets/BaseWidget.d.ts +32 -2
  35. package/dist/src/toolbar/widgets/BaseWidget.js +67 -6
  36. package/dist/src/toolbar/widgets/EraserToolWidget.d.ts +4 -0
  37. package/dist/src/toolbar/widgets/EraserToolWidget.js +3 -0
  38. package/dist/src/toolbar/widgets/HandToolWidget.d.ts +3 -1
  39. package/dist/src/toolbar/widgets/HandToolWidget.js +22 -13
  40. package/dist/src/toolbar/widgets/PenToolWidget.d.ts +7 -1
  41. package/dist/src/toolbar/widgets/PenToolWidget.js +83 -12
  42. package/dist/src/toolbar/widgets/SelectionToolWidget.d.ts +1 -1
  43. package/dist/src/toolbar/widgets/SelectionToolWidget.js +7 -7
  44. package/dist/src/toolbar/widgets/TextToolWidget.d.ts +4 -1
  45. package/dist/src/toolbar/widgets/TextToolWidget.js +17 -3
  46. package/dist/src/tools/PanZoom.d.ts +4 -1
  47. package/dist/src/tools/PanZoom.js +24 -1
  48. package/dist/src/tools/Pen.d.ts +2 -2
  49. package/dist/src/tools/Pen.js +2 -2
  50. package/dist/src/tools/SelectionTool/Selection.d.ts +1 -0
  51. package/dist/src/tools/SelectionTool/Selection.js +8 -1
  52. package/dist/src/tools/ToolController.js +2 -1
  53. package/package.json +1 -1
  54. package/src/Color4.ts +2 -0
  55. package/src/SVGLoader.ts +8 -8
  56. package/src/components/Stroke.ts +16 -3
  57. package/src/components/builders/FreehandLineBuilder.ts +54 -495
  58. package/src/components/builders/PressureSensitiveFreehandLineBuilder.ts +454 -0
  59. package/src/components/lib.ts +3 -1
  60. package/src/components/util/StrokeSmoother.ts +290 -0
  61. package/src/math/Mat33.ts +5 -0
  62. package/src/math/Path.test.ts +49 -0
  63. package/src/math/Path.ts +51 -0
  64. package/src/rendering/renderers/CanvasRenderer.ts +2 -0
  65. package/src/rendering/renderers/SVGRenderer.ts +24 -0
  66. package/src/toolbar/HTMLToolbar.ts +33 -0
  67. package/src/toolbar/IconProvider.ts +49 -1
  68. package/src/toolbar/localization.ts +4 -0
  69. package/src/toolbar/makeColorInput.ts +21 -3
  70. package/src/toolbar/widgets/ActionButtonWidget.ts +6 -3
  71. package/src/toolbar/widgets/BaseToolWidget.ts +4 -3
  72. package/src/toolbar/widgets/BaseWidget.ts +83 -5
  73. package/src/toolbar/widgets/EraserToolWidget.ts +11 -0
  74. package/src/toolbar/widgets/HandToolWidget.ts +48 -17
  75. package/src/toolbar/widgets/PenToolWidget.ts +110 -13
  76. package/src/toolbar/widgets/SelectionToolWidget.ts +8 -5
  77. package/src/toolbar/widgets/TextToolWidget.ts +29 -4
  78. package/src/tools/PanZoom.ts +28 -1
  79. package/src/tools/Pen.test.ts +2 -2
  80. package/src/tools/Pen.ts +1 -1
  81. package/src/tools/SelectionTool/Selection.ts +10 -1
  82. package/src/tools/ToolController.ts +2 -1
package/src/tools/Pen.ts CHANGED
@@ -14,13 +14,13 @@ export interface PenStyle {
14
14
 
15
15
  export default class Pen extends BaseTool {
16
16
  protected builder: ComponentBuilder|null = null;
17
- protected builderFactory: ComponentBuilderFactory = makeFreehandLineBuilder;
18
17
  private lastPoint: StrokeDataPoint|null = null;
19
18
 
20
19
  public constructor(
21
20
  private editor: Editor,
22
21
  description: string,
23
22
  private style: PenStyle,
23
+ private builderFactory: ComponentBuilderFactory = makeFreehandLineBuilder,
24
24
  ) {
25
25
  super(editor.notifier, description);
26
26
  }
@@ -37,6 +37,8 @@ export default class Selection {
37
37
  private container: HTMLElement;
38
38
  private backgroundElem: HTMLElement;
39
39
 
40
+ private hasParent: boolean = true;
41
+
40
42
  public constructor(startPoint: Point2, private editor: Editor) {
41
43
  this.originalRegion = new Rect2(startPoint.x, startPoint.y, 0, 0);
42
44
  this.transformers = {
@@ -155,7 +157,7 @@ export default class Selection {
155
157
  public setTransform(transform: Mat33, preview: boolean = true) {
156
158
  this.transform = transform;
157
159
 
158
- if (preview) {
160
+ if (preview && this.hasParent) {
159
161
  this.previewTransformCmds();
160
162
  this.scrollTo();
161
163
  }
@@ -329,6 +331,11 @@ export default class Selection {
329
331
 
330
332
  // @internal
331
333
  public updateUI() {
334
+ // Don't update old selections.
335
+ if (!this.hasParent) {
336
+ return;
337
+ }
338
+
332
339
  // marginLeft, marginTop: Display relative to the top left of the selection overlay.
333
340
  // left, top don't work for this.
334
341
  this.backgroundElem.style.marginLeft = `${this.screenRegion.topLeft.x}px`;
@@ -428,6 +435,7 @@ export default class Selection {
428
435
  }
429
436
 
430
437
  elem.appendChild(this.container);
438
+ this.hasParent = true;
431
439
  }
432
440
 
433
441
  public setToPoint(point: Point2) {
@@ -440,6 +448,7 @@ export default class Selection {
440
448
  this.container.remove();
441
449
  }
442
450
  this.originalRegion = Rect2.empty;
451
+ this.hasParent = false;
443
452
  }
444
453
 
445
454
  public setSelectedObjects(objects: AbstractComponent[], bbox: Rect2) {
@@ -14,6 +14,7 @@ import PipetteTool from './PipetteTool';
14
14
  import ToolSwitcherShortcut from './ToolSwitcherShortcut';
15
15
  import PasteHandler from './PasteHandler';
16
16
  import ToolbarShortcutHandler from './ToolbarShortcutHandler';
17
+ import { makePressureSensitiveFreehandLineBuilder } from '../components/builders/PressureSensitiveFreehandLineBuilder';
17
18
 
18
19
  export default class ToolController {
19
20
  private tools: BaseTool[];
@@ -34,7 +35,7 @@ export default class ToolController {
34
35
  new Pen(editor, localization.penTool(2), { color: Color4.clay, thickness: 4 }),
35
36
 
36
37
  // Highlighter-like pen with width=64
37
- new Pen(editor, localization.penTool(3), { color: Color4.ofRGBA(1, 1, 0, 0.5), thickness: 64 }),
38
+ new Pen(editor, localization.penTool(3), { color: Color4.ofRGBA(1, 1, 0, 0.5), thickness: 64 }, makePressureSensitiveFreehandLineBuilder),
38
39
 
39
40
  new Eraser(editor, localization.eraserTool),
40
41
  new SelectionTool(editor, localization.selectionTool),