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.
- package/.github/ISSUE_TEMPLATE/translation.md +1 -0
- package/CHANGELOG.md +12 -0
- package/dist/bundle.js +1 -1
- package/dist/src/Color4.js +3 -0
- package/dist/src/SVGLoader.js +5 -7
- package/dist/src/components/Stroke.js +10 -3
- package/dist/src/components/builders/FreehandLineBuilder.d.ts +10 -23
- package/dist/src/components/builders/FreehandLineBuilder.js +70 -396
- package/dist/src/components/builders/PressureSensitiveFreehandLineBuilder.d.ts +36 -0
- package/dist/src/components/builders/PressureSensitiveFreehandLineBuilder.js +339 -0
- package/dist/src/components/lib.d.ts +2 -0
- package/dist/src/components/lib.js +2 -0
- package/dist/src/components/util/StrokeSmoother.d.ts +35 -0
- package/dist/src/components/util/StrokeSmoother.js +206 -0
- package/dist/src/math/Mat33.d.ts +2 -0
- package/dist/src/math/Mat33.js +4 -0
- package/dist/src/math/Path.d.ts +2 -0
- package/dist/src/math/Path.js +44 -0
- package/dist/src/rendering/renderers/CanvasRenderer.js +2 -0
- package/dist/src/rendering/renderers/SVGRenderer.d.ts +2 -0
- package/dist/src/rendering/renderers/SVGRenderer.js +20 -0
- package/dist/src/toolbar/HTMLToolbar.d.ts +3 -0
- package/dist/src/toolbar/HTMLToolbar.js +24 -0
- package/dist/src/toolbar/IconProvider.d.ts +1 -0
- package/dist/src/toolbar/IconProvider.js +43 -1
- package/dist/src/toolbar/localization.d.ts +2 -0
- package/dist/src/toolbar/localization.js +2 -0
- package/dist/src/toolbar/makeColorInput.d.ts +2 -1
- package/dist/src/toolbar/makeColorInput.js +13 -2
- package/dist/src/toolbar/widgets/ActionButtonWidget.d.ts +1 -1
- package/dist/src/toolbar/widgets/ActionButtonWidget.js +2 -2
- package/dist/src/toolbar/widgets/BaseToolWidget.d.ts +1 -2
- package/dist/src/toolbar/widgets/BaseToolWidget.js +2 -3
- package/dist/src/toolbar/widgets/BaseWidget.d.ts +32 -2
- package/dist/src/toolbar/widgets/BaseWidget.js +67 -6
- package/dist/src/toolbar/widgets/EraserToolWidget.d.ts +4 -0
- package/dist/src/toolbar/widgets/EraserToolWidget.js +3 -0
- package/dist/src/toolbar/widgets/HandToolWidget.d.ts +3 -1
- package/dist/src/toolbar/widgets/HandToolWidget.js +22 -13
- package/dist/src/toolbar/widgets/PenToolWidget.d.ts +7 -1
- package/dist/src/toolbar/widgets/PenToolWidget.js +83 -12
- package/dist/src/toolbar/widgets/SelectionToolWidget.d.ts +1 -1
- package/dist/src/toolbar/widgets/SelectionToolWidget.js +7 -7
- package/dist/src/toolbar/widgets/TextToolWidget.d.ts +4 -1
- package/dist/src/toolbar/widgets/TextToolWidget.js +17 -3
- package/dist/src/tools/PanZoom.d.ts +4 -1
- package/dist/src/tools/PanZoom.js +24 -1
- package/dist/src/tools/Pen.d.ts +2 -2
- package/dist/src/tools/Pen.js +2 -2
- package/dist/src/tools/SelectionTool/Selection.d.ts +1 -0
- package/dist/src/tools/SelectionTool/Selection.js +8 -1
- package/dist/src/tools/ToolController.js +2 -1
- package/package.json +1 -1
- package/src/Color4.ts +2 -0
- package/src/SVGLoader.ts +8 -8
- package/src/components/Stroke.ts +16 -3
- package/src/components/builders/FreehandLineBuilder.ts +54 -495
- package/src/components/builders/PressureSensitiveFreehandLineBuilder.ts +454 -0
- package/src/components/lib.ts +3 -1
- package/src/components/util/StrokeSmoother.ts +290 -0
- package/src/math/Mat33.ts +5 -0
- package/src/math/Path.test.ts +49 -0
- package/src/math/Path.ts +51 -0
- package/src/rendering/renderers/CanvasRenderer.ts +2 -0
- package/src/rendering/renderers/SVGRenderer.ts +24 -0
- package/src/toolbar/HTMLToolbar.ts +33 -0
- package/src/toolbar/IconProvider.ts +49 -1
- package/src/toolbar/localization.ts +4 -0
- package/src/toolbar/makeColorInput.ts +21 -3
- package/src/toolbar/widgets/ActionButtonWidget.ts +6 -3
- package/src/toolbar/widgets/BaseToolWidget.ts +4 -3
- package/src/toolbar/widgets/BaseWidget.ts +83 -5
- package/src/toolbar/widgets/EraserToolWidget.ts +11 -0
- package/src/toolbar/widgets/HandToolWidget.ts +48 -17
- package/src/toolbar/widgets/PenToolWidget.ts +110 -13
- package/src/toolbar/widgets/SelectionToolWidget.ts +8 -5
- package/src/toolbar/widgets/TextToolWidget.ts +29 -4
- package/src/tools/PanZoom.ts +28 -1
- package/src/tools/Pen.test.ts +2 -2
- package/src/tools/Pen.ts +1 -1
- package/src/tools/SelectionTool/Selection.ts +10 -1
- 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),
|