kritzel-stencil 0.0.120 → 0.0.122
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/cjs/{index-BjLSiQIM.js → index-CFCyVs0_.js} +185 -69
- package/dist/cjs/index-CFCyVs0_.js.map +1 -0
- package/dist/cjs/index.cjs.js +1 -1
- package/dist/cjs/kritzel-brush-style_18.cjs.entry.js +129 -72
- package/dist/cjs/kritzel-brush-style_18.cjs.entry.js.map +1 -1
- package/dist/collection/classes/commands/remove-object.command.js +3 -0
- package/dist/collection/classes/commands/remove-object.command.js.map +1 -1
- package/dist/collection/classes/handlers/context-menu.handler.js +1 -1
- package/dist/collection/classes/handlers/context-menu.handler.js.map +1 -1
- package/dist/collection/classes/handlers/move.handler.js +2 -2
- package/dist/collection/classes/handlers/move.handler.js.map +1 -1
- package/dist/collection/classes/handlers/selection.handler.js +5 -5
- package/dist/collection/classes/handlers/selection.handler.js.map +1 -1
- package/dist/collection/classes/history.class.js +16 -13
- package/dist/collection/classes/history.class.js.map +1 -1
- package/dist/collection/classes/objects/base-object.class.js +28 -32
- package/dist/collection/classes/objects/base-object.class.js.map +1 -1
- package/dist/collection/classes/objects/custom-element.class.js +52 -0
- package/dist/collection/classes/objects/custom-element.class.js.map +1 -0
- package/dist/collection/classes/objects/image.class.js +1 -1
- package/dist/collection/classes/objects/image.class.js.map +1 -1
- package/dist/collection/classes/objects/path.class.js +62 -2
- package/dist/collection/classes/objects/path.class.js.map +1 -1
- package/dist/collection/classes/objects/selection-group.class.js +1 -1
- package/dist/collection/classes/objects/selection-group.class.js.map +1 -1
- package/dist/collection/classes/objects/text.class.js +1 -1
- package/dist/collection/classes/objects/text.class.js.map +1 -1
- package/dist/collection/classes/reviver.class.js +4 -0
- package/dist/collection/classes/reviver.class.js.map +1 -1
- package/dist/collection/classes/store.class.js +45 -6
- package/dist/collection/classes/store.class.js.map +1 -1
- package/dist/collection/classes/tools/eraser-tool.class.js +18 -14
- package/dist/collection/classes/tools/eraser-tool.class.js.map +1 -1
- package/dist/collection/classes/tools/image-tool.class.js +1 -1
- package/dist/collection/classes/tools/image-tool.class.js.map +1 -1
- package/dist/collection/classes/tools/selection-tool.class.js +2 -6
- package/dist/collection/classes/tools/selection-tool.class.js.map +1 -1
- package/dist/collection/classes/viewport.class.js +20 -12
- package/dist/collection/classes/viewport.class.js.map +1 -1
- package/dist/collection/components/core/kritzel-editor/kritzel-editor.js +6 -6
- package/dist/collection/components/core/kritzel-editor/kritzel-editor.js.map +1 -1
- package/dist/collection/components/core/kritzel-engine/kritzel-engine.js +40 -33
- package/dist/collection/components/core/kritzel-engine/kritzel-engine.js.map +1 -1
- package/dist/collection/configs/default-engine-state.js +2 -2
- package/dist/collection/configs/default-engine-state.js.map +1 -1
- package/dist/collection/helpers/html.helper.js +7 -0
- package/dist/collection/helpers/html.helper.js.map +1 -0
- package/dist/collection/helpers/object.helper.js +6 -2
- package/dist/collection/helpers/object.helper.js.map +1 -1
- package/dist/collection/interfaces/engine-state.interface.js.map +1 -1
- package/dist/collection/interfaces/object.interface.js.map +1 -1
- package/dist/components/index.js +2 -2
- package/dist/components/kritzel-controls.js +1 -1
- package/dist/components/kritzel-editor.js +7 -7
- package/dist/components/kritzel-editor.js.map +1 -1
- package/dist/components/kritzel-engine.js +1 -1
- package/dist/components/{p-eS30Bqrc.js → p-COPOzWCn.js} +213 -100
- package/dist/components/p-COPOzWCn.js.map +1 -0
- package/dist/components/{p-DC3j4P1n.js → p-Ch8eM2R8.js} +99 -39
- package/dist/components/p-Ch8eM2R8.js.map +1 -0
- package/dist/components/{p-BAMl2Ww6.js → p-DIu9OTyP.js} +3 -3
- package/dist/components/{p-BAMl2Ww6.js.map → p-DIu9OTyP.js.map} +1 -1
- package/dist/esm/{index-DsUDklEm.js → index-DYLW4hYm.js} +185 -69
- package/dist/esm/index-DYLW4hYm.js.map +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/kritzel-brush-style_18.entry.js +129 -72
- package/dist/esm/kritzel-brush-style_18.entry.js.map +1 -1
- package/dist/stencil/index.esm.js +1 -1
- package/dist/stencil/p-DYLW4hYm.js +2 -0
- package/dist/stencil/p-DYLW4hYm.js.map +1 -0
- package/dist/stencil/p-fa584641.entry.js +2 -0
- package/dist/stencil/p-fa584641.entry.js.map +1 -0
- package/dist/stencil/stencil.esm.js +1 -1
- package/dist/types/classes/history.class.d.ts +1 -0
- package/dist/types/classes/objects/base-object.class.d.ts +10 -6
- package/dist/types/classes/objects/custom-element.class.d.ts +26 -0
- package/dist/types/classes/objects/image.class.d.ts +1 -1
- package/dist/types/classes/objects/path.class.d.ts +5 -2
- package/dist/types/classes/objects/text.class.d.ts +1 -1
- package/dist/types/classes/store.class.d.ts +5 -0
- package/dist/types/components.d.ts +4 -4
- package/dist/types/helpers/html.helper.d.ts +3 -0
- package/dist/types/interfaces/engine-state.interface.d.ts +2 -2
- package/dist/types/interfaces/object.interface.d.ts +9 -4
- package/package.json +1 -1
- package/dist/cjs/index-BjLSiQIM.js.map +0 -1
- package/dist/components/p-DC3j4P1n.js.map +0 -1
- package/dist/components/p-eS30Bqrc.js.map +0 -1
- package/dist/esm/index-DsUDklEm.js.map +0 -1
- package/dist/stencil/p-0ae72b0d.entry.js +0 -2
- package/dist/stencil/p-0ae72b0d.entry.js.map +0 -1
- package/dist/stencil/p-DsUDklEm.js +0 -2
- package/dist/stencil/p-DsUDklEm.js.map +0 -1
|
@@ -298,8 +298,12 @@ class ObjectHelper {
|
|
|
298
298
|
}
|
|
299
299
|
static clone(objOrObjs) {
|
|
300
300
|
const cloneObject = (obj) => {
|
|
301
|
-
const remainingProps = __rest(
|
|
302
|
-
|
|
301
|
+
const _a = obj, { element } = _a, remainingProps = __rest(_a, ["_store", "_elementRef", "totalWidth", "totalHeight", "element"]);
|
|
302
|
+
const clonedProps = structuredClone(remainingProps);
|
|
303
|
+
if (element && element instanceof HTMLElement) {
|
|
304
|
+
clonedProps.element = element.cloneNode(true);
|
|
305
|
+
}
|
|
306
|
+
return clonedProps;
|
|
303
307
|
};
|
|
304
308
|
if (Array.isArray(objOrObjs)) {
|
|
305
309
|
return objOrObjs.map(cloneObject);
|
|
@@ -348,8 +352,8 @@ class KritzelBaseObject {
|
|
|
348
352
|
};
|
|
349
353
|
}
|
|
350
354
|
get rotatedPolygon() {
|
|
351
|
-
const cx =
|
|
352
|
-
const cy =
|
|
355
|
+
const cx = this.translateX + this.totalWidth / 2 / this.scale;
|
|
356
|
+
const cy = this.translateY + this.totalHeight / 2 / this.scale;
|
|
353
357
|
const angle = this.rotation;
|
|
354
358
|
const adjustedWidth = this.totalWidth / this.scale;
|
|
355
359
|
const adjustedHeight = this.totalHeight / this.scale;
|
|
@@ -369,39 +373,19 @@ class KritzelBaseObject {
|
|
|
369
373
|
return rotatedCorners;
|
|
370
374
|
}
|
|
371
375
|
get minXRotated() {
|
|
372
|
-
const corners = [
|
|
373
|
-
this.rotatedPolygon.topLeft.x,
|
|
374
|
-
this.rotatedPolygon.topRight.x,
|
|
375
|
-
this.rotatedPolygon.bottomRight.x,
|
|
376
|
-
this.rotatedPolygon.bottomLeft.x,
|
|
377
|
-
];
|
|
376
|
+
const corners = [this.rotatedPolygon.topLeft.x, this.rotatedPolygon.topRight.x, this.rotatedPolygon.bottomRight.x, this.rotatedPolygon.bottomLeft.x];
|
|
378
377
|
return Math.min(...corners);
|
|
379
378
|
}
|
|
380
379
|
get minYRotated() {
|
|
381
|
-
const corners = [
|
|
382
|
-
this.rotatedPolygon.topLeft.y,
|
|
383
|
-
this.rotatedPolygon.topRight.y,
|
|
384
|
-
this.rotatedPolygon.bottomRight.y,
|
|
385
|
-
this.rotatedPolygon.bottomLeft.y,
|
|
386
|
-
];
|
|
380
|
+
const corners = [this.rotatedPolygon.topLeft.y, this.rotatedPolygon.topRight.y, this.rotatedPolygon.bottomRight.y, this.rotatedPolygon.bottomLeft.y];
|
|
387
381
|
return Math.min(...corners);
|
|
388
382
|
}
|
|
389
383
|
get maxXRotated() {
|
|
390
|
-
const corners = [
|
|
391
|
-
this.rotatedPolygon.topLeft.x,
|
|
392
|
-
this.rotatedPolygon.topRight.x,
|
|
393
|
-
this.rotatedPolygon.bottomRight.x,
|
|
394
|
-
this.rotatedPolygon.bottomLeft.x,
|
|
395
|
-
];
|
|
384
|
+
const corners = [this.rotatedPolygon.topLeft.x, this.rotatedPolygon.topRight.x, this.rotatedPolygon.bottomRight.x, this.rotatedPolygon.bottomLeft.x];
|
|
396
385
|
return Math.max(...corners);
|
|
397
386
|
}
|
|
398
387
|
get maxYRotated() {
|
|
399
|
-
const corners = [
|
|
400
|
-
this.rotatedPolygon.topLeft.y,
|
|
401
|
-
this.rotatedPolygon.topRight.y,
|
|
402
|
-
this.rotatedPolygon.bottomRight.y,
|
|
403
|
-
this.rotatedPolygon.bottomLeft.y,
|
|
404
|
-
];
|
|
388
|
+
const corners = [this.rotatedPolygon.topLeft.y, this.rotatedPolygon.topRight.y, this.rotatedPolygon.bottomRight.y, this.rotatedPolygon.bottomLeft.y];
|
|
405
389
|
return Math.max(...corners);
|
|
406
390
|
}
|
|
407
391
|
get transformationMatrix() {
|
|
@@ -421,18 +405,19 @@ class KritzelBaseObject {
|
|
|
421
405
|
}
|
|
422
406
|
constructor() {
|
|
423
407
|
this.__class__ = 'KritzelBaseObject';
|
|
424
|
-
this.visible = true;
|
|
425
408
|
this.borderWidth = 0;
|
|
426
409
|
this.opacity = 1;
|
|
427
410
|
this.padding = 0;
|
|
428
|
-
this.selected = false;
|
|
429
411
|
this.resizing = false;
|
|
430
412
|
this.rotation = 0;
|
|
431
413
|
this.markedForRemoval = false;
|
|
432
|
-
this.isMounted = false;
|
|
433
414
|
this.zIndex = 0;
|
|
415
|
+
this.isVisible = true;
|
|
416
|
+
this.isSelected = false;
|
|
417
|
+
this.isMounted = false;
|
|
434
418
|
this.isEditable = false;
|
|
435
|
-
this.
|
|
419
|
+
this.isInteractive = false;
|
|
420
|
+
this.isDebugInfoVisible = false;
|
|
436
421
|
this.id = this.generateId();
|
|
437
422
|
}
|
|
438
423
|
static create(store) {
|
|
@@ -448,6 +433,18 @@ class KritzelBaseObject {
|
|
|
448
433
|
this.elementRef = element;
|
|
449
434
|
this.isMounted = true;
|
|
450
435
|
}
|
|
436
|
+
unmount() {
|
|
437
|
+
if (!this.isMounted) {
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
this.isMounted = false;
|
|
441
|
+
}
|
|
442
|
+
remount() {
|
|
443
|
+
if (!this.isMounted) {
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
this.isMounted = false;
|
|
447
|
+
}
|
|
451
448
|
generateId() {
|
|
452
449
|
return ObjectHelper.generateUUID();
|
|
453
450
|
}
|
|
@@ -457,10 +454,10 @@ class KritzelBaseObject {
|
|
|
457
454
|
y: -this._store.state.translateY / this._store.state.scale,
|
|
458
455
|
width: this._store.state.viewportWidth / this._store.state.scale,
|
|
459
456
|
height: this._store.state.viewportHeight / this._store.state.scale};
|
|
460
|
-
return this.boundingBox.x < viewportBounds.x + viewportBounds.width &&
|
|
457
|
+
return (this.boundingBox.x < viewportBounds.x + viewportBounds.width &&
|
|
461
458
|
this.boundingBox.x + this.boundingBox.width > viewportBounds.x &&
|
|
462
459
|
this.boundingBox.y < viewportBounds.y + viewportBounds.height &&
|
|
463
|
-
this.boundingBox.y + this.boundingBox.height > viewportBounds.y;
|
|
460
|
+
this.boundingBox.y + this.boundingBox.height > viewportBounds.y);
|
|
464
461
|
}
|
|
465
462
|
centerInViewport() {
|
|
466
463
|
const scale = this._store.state.scale;
|
|
@@ -505,6 +502,9 @@ class KritzelBaseObject {
|
|
|
505
502
|
edit() {
|
|
506
503
|
// This method can be overridden by subclasses to handle edit actions.
|
|
507
504
|
}
|
|
505
|
+
hitTest(_x, _y) {
|
|
506
|
+
return true; // Default implementation, can be overridden by subclasses
|
|
507
|
+
}
|
|
508
508
|
}
|
|
509
509
|
|
|
510
510
|
class KritzelText extends KritzelBaseObject {
|
|
@@ -520,7 +520,7 @@ class KritzelText extends KritzelBaseObject {
|
|
|
520
520
|
this.fontColor = '#000000';
|
|
521
521
|
this.initialWidth = 3;
|
|
522
522
|
this.isNew = true;
|
|
523
|
-
this.
|
|
523
|
+
this.isDebugInfoVisible = true;
|
|
524
524
|
this.isEditable = true;
|
|
525
525
|
this.rows = 1;
|
|
526
526
|
if (config) {
|
|
@@ -681,10 +681,14 @@ class KritzelPath extends KritzelBaseObject {
|
|
|
681
681
|
this.height = 0;
|
|
682
682
|
this.width = 0;
|
|
683
683
|
this.scale = 1;
|
|
684
|
-
this.
|
|
685
|
-
this.
|
|
684
|
+
this.isVisible = true;
|
|
685
|
+
this.isDebugInfoVisible = true;
|
|
686
686
|
this.options = config;
|
|
687
687
|
this.points = (_a = config === null || config === void 0 ? void 0 : config.points) !== null && _a !== void 0 ? _a : [];
|
|
688
|
+
this.adjustedPoints = this.points.map(([px, py]) => [
|
|
689
|
+
(px + this.options.translateX) / this.scale,
|
|
690
|
+
(py + this.options.translateY) / this.scale,
|
|
691
|
+
]);
|
|
688
692
|
this.translateX = (_b = config === null || config === void 0 ? void 0 : config.translateX) !== null && _b !== void 0 ? _b : 0;
|
|
689
693
|
this.translateY = (_c = config === null || config === void 0 ? void 0 : config.translateY) !== null && _c !== void 0 ? _c : 0;
|
|
690
694
|
this.scale = (_d = config === null || config === void 0 ? void 0 : config.scale) !== null && _d !== void 0 ? _d : 1;
|
|
@@ -700,6 +704,13 @@ class KritzelPath extends KritzelBaseObject {
|
|
|
700
704
|
object.id = object.generateId();
|
|
701
705
|
object.options = options;
|
|
702
706
|
object.points = (_a = options === null || options === void 0 ? void 0 : options.points) !== null && _a !== void 0 ? _a : [];
|
|
707
|
+
object.adjustedPoints = object.points.map(([px, py]) => {
|
|
708
|
+
var _a, _b;
|
|
709
|
+
return [
|
|
710
|
+
(px + (options === null || options === void 0 ? void 0 : options.translateX)) / ((_a = options === null || options === void 0 ? void 0 : options.scale) !== null && _a !== void 0 ? _a : 1),
|
|
711
|
+
(py + (options === null || options === void 0 ? void 0 : options.translateY)) / ((_b = options === null || options === void 0 ? void 0 : options.scale) !== null && _b !== void 0 ? _b : 1),
|
|
712
|
+
];
|
|
713
|
+
});
|
|
703
714
|
object.translateX = (_b = options === null || options === void 0 ? void 0 : options.translateX) !== null && _b !== void 0 ? _b : 0;
|
|
704
715
|
object.translateY = (_c = options === null || options === void 0 ? void 0 : options.translateY) !== null && _c !== void 0 ? _c : 0;
|
|
705
716
|
object.scale = (_d = options === null || options === void 0 ? void 0 : options.scale) !== null && _d !== void 0 ? _d : 1;
|
|
@@ -719,6 +730,10 @@ class KritzelPath extends KritzelBaseObject {
|
|
|
719
730
|
this.width = width;
|
|
720
731
|
this.height = height;
|
|
721
732
|
this.points = this.points.map(([x, y]) => [x * scaleX, y * scaleY]);
|
|
733
|
+
this.adjustedPoints = this.points.map(([px, py]) => [
|
|
734
|
+
(px + this.options.translateX) / this.scale,
|
|
735
|
+
(py + this.options.translateY) / this.scale,
|
|
736
|
+
]);
|
|
722
737
|
this.d = this.generateSvgPath();
|
|
723
738
|
this.width = Math.max(...this.points.map(p => p[0])) - Math.min(...this.points.map(p => p[0])) + this.strokeWidth;
|
|
724
739
|
this.height = Math.max(...this.points.map(p => p[1])) - Math.min(...this.points.map(p => p[1])) + this.strokeWidth;
|
|
@@ -731,6 +746,51 @@ class KritzelPath extends KritzelBaseObject {
|
|
|
731
746
|
super.rotate(value);
|
|
732
747
|
this.updateDimensions();
|
|
733
748
|
}
|
|
749
|
+
hitTest(x, y) {
|
|
750
|
+
const halfStroke = this.strokeWidth / this.scale / 2;
|
|
751
|
+
if (this.adjustedPoints.length === 1) {
|
|
752
|
+
const p1 = this.adjustedPoints[0];
|
|
753
|
+
const distance = this.pointToLineSegmentDistance(x, y, p1[0], p1[1], p1[0], p1[1]);
|
|
754
|
+
return distance <= halfStroke;
|
|
755
|
+
}
|
|
756
|
+
for (let i = 0; i < this.adjustedPoints.length - 1; i++) {
|
|
757
|
+
const p1 = this.adjustedPoints[i];
|
|
758
|
+
const p2 = this.adjustedPoints[i + 1];
|
|
759
|
+
const distance = this.pointToLineSegmentDistance(x, y, p1[0], p1[1], p2[0], p2[1]);
|
|
760
|
+
if (distance <= halfStroke) {
|
|
761
|
+
return true;
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
return false;
|
|
765
|
+
}
|
|
766
|
+
pointToLineSegmentDistance(x, y, x1, y1, x2, y2) {
|
|
767
|
+
const A = x - x1;
|
|
768
|
+
const B = y - y1;
|
|
769
|
+
const C = x2 - x1;
|
|
770
|
+
const D = y2 - y1;
|
|
771
|
+
const dot = A * C + B * D;
|
|
772
|
+
const len_sq = C * C + D * D;
|
|
773
|
+
let param = -1;
|
|
774
|
+
if (len_sq !== 0) { // in case of 0 length line
|
|
775
|
+
param = dot / len_sq;
|
|
776
|
+
}
|
|
777
|
+
let xx, yy;
|
|
778
|
+
if (param < 0) {
|
|
779
|
+
xx = x1;
|
|
780
|
+
yy = y1;
|
|
781
|
+
}
|
|
782
|
+
else if (param > 1) {
|
|
783
|
+
xx = x2;
|
|
784
|
+
yy = y2;
|
|
785
|
+
}
|
|
786
|
+
else {
|
|
787
|
+
xx = x1 + param * C;
|
|
788
|
+
yy = y1 + param * D;
|
|
789
|
+
}
|
|
790
|
+
const dx = x - xx;
|
|
791
|
+
const dy = y - yy;
|
|
792
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
793
|
+
}
|
|
734
794
|
updateDimensions() {
|
|
735
795
|
const rotatedPoints = this.points.map(([x, y]) => {
|
|
736
796
|
const rotatedX = x * Math.cos(this.rotation) - y * Math.sin(this.rotation);
|
|
@@ -802,7 +862,7 @@ class KritzelImage extends KritzelBaseObject {
|
|
|
802
862
|
this.maxWidth = 300;
|
|
803
863
|
this.maxHeight = 300;
|
|
804
864
|
this.maxCompressionSize = 300;
|
|
805
|
-
this.
|
|
865
|
+
this.isDebugInfoVisible = true;
|
|
806
866
|
this.src = (config === null || config === void 0 ? void 0 : config.src) || '';
|
|
807
867
|
this.x = (config === null || config === void 0 ? void 0 : config.x) || 0;
|
|
808
868
|
this.y = (config === null || config === void 0 ? void 0 : config.y) || 0;
|
|
@@ -971,6 +1031,57 @@ class BatchCommand extends KritzelBaseCommand {
|
|
|
971
1031
|
}
|
|
972
1032
|
}
|
|
973
1033
|
|
|
1034
|
+
class KritzelCustomElement extends KritzelBaseObject {
|
|
1035
|
+
constructor(config) {
|
|
1036
|
+
super();
|
|
1037
|
+
this.__class__ = 'KritzelCustomElement';
|
|
1038
|
+
this.isInteractive = true;
|
|
1039
|
+
if (config) {
|
|
1040
|
+
this.translateX = config.translateX || 0;
|
|
1041
|
+
this.translateY = config.translateY || 0;
|
|
1042
|
+
this.scale = config.scale || 1;
|
|
1043
|
+
this.element = config.element;
|
|
1044
|
+
this.height = config.height || 0;
|
|
1045
|
+
this.width = config.width || 0;
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
static create(store, config) {
|
|
1049
|
+
const object = new KritzelCustomElement(config);
|
|
1050
|
+
object._store = store;
|
|
1051
|
+
object.id = object.generateId();
|
|
1052
|
+
return object;
|
|
1053
|
+
}
|
|
1054
|
+
mount(element) {
|
|
1055
|
+
if (this.isMounted) {
|
|
1056
|
+
return;
|
|
1057
|
+
}
|
|
1058
|
+
this.elementRef = element;
|
|
1059
|
+
this.isMounted = true;
|
|
1060
|
+
this.elementRef.appendChild(this.element);
|
|
1061
|
+
}
|
|
1062
|
+
resize(x, y, width, height) {
|
|
1063
|
+
if (width <= 1 || height <= 1) {
|
|
1064
|
+
return;
|
|
1065
|
+
}
|
|
1066
|
+
this.width = width;
|
|
1067
|
+
this.height = height;
|
|
1068
|
+
this.translateX = x;
|
|
1069
|
+
this.translateY = y;
|
|
1070
|
+
if (this.element) {
|
|
1071
|
+
this.element.style.width = `${width}px`;
|
|
1072
|
+
this.element.style.height = `${height}px`;
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
copy() {
|
|
1076
|
+
const copiedObject = Object.create(Object.getPrototypeOf(this));
|
|
1077
|
+
Object.assign(copiedObject, this);
|
|
1078
|
+
copiedObject.id = this.generateId();
|
|
1079
|
+
copiedObject.isMounted = false;
|
|
1080
|
+
copiedObject.element = this.element.cloneNode(true);
|
|
1081
|
+
return copiedObject;
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
|
|
974
1085
|
class RemoveObjectCommand extends KritzelBaseCommand {
|
|
975
1086
|
constructor(store, initiator, object) {
|
|
976
1087
|
super(store, initiator);
|
|
@@ -978,9 +1089,11 @@ class RemoveObjectCommand extends KritzelBaseCommand {
|
|
|
978
1089
|
}
|
|
979
1090
|
execute() {
|
|
980
1091
|
this._store.state.objectsOctree.remove(object => object.id === this.object.id);
|
|
1092
|
+
this._store.state.objectsOctree.filter(object => object instanceof KritzelCustomElement).forEach(object => object.remount());
|
|
981
1093
|
}
|
|
982
1094
|
undo() {
|
|
983
1095
|
this._store.state.objectsOctree.insert(this.object);
|
|
1096
|
+
this._store.state.objectsOctree.filter(object => object instanceof KritzelCustomElement).forEach(object => object.remount());
|
|
984
1097
|
}
|
|
985
1098
|
}
|
|
986
1099
|
|
|
@@ -1004,28 +1117,34 @@ class KritzelEraserTool extends KritzelBaseTool {
|
|
|
1004
1117
|
}
|
|
1005
1118
|
}
|
|
1006
1119
|
handlePointerMove(event) {
|
|
1007
|
-
var _a
|
|
1120
|
+
var _a;
|
|
1008
1121
|
if (event.pointerType === 'mouse') {
|
|
1009
1122
|
if (this._store.state.isErasing) {
|
|
1010
|
-
const
|
|
1011
|
-
if (
|
|
1123
|
+
const selectedObjects = this._store.getObjectsFromPointerEvent(event, '.object');
|
|
1124
|
+
if (selectedObjects.length === 0)
|
|
1012
1125
|
return;
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
selectedObject
|
|
1126
|
+
console.log('selectedObjects', selectedObjects);
|
|
1127
|
+
const x = this._store.state.pointerX;
|
|
1128
|
+
const y = this._store.state.pointerY;
|
|
1129
|
+
selectedObjects.forEach(selectedObject => {
|
|
1130
|
+
selectedObject.markedForRemoval = selectedObject.hitTest(x, y);
|
|
1131
|
+
});
|
|
1017
1132
|
this._store.rerender();
|
|
1018
1133
|
}
|
|
1019
1134
|
}
|
|
1020
1135
|
if (event.pointerType === 'touch') {
|
|
1021
1136
|
if (this._store.state.pointers.size === 1 && this._store.state.isErasing) {
|
|
1022
|
-
const shadowRoot = (
|
|
1137
|
+
const shadowRoot = (_a = this._store.state.host) === null || _a === void 0 ? void 0 : _a.shadowRoot;
|
|
1023
1138
|
if (!shadowRoot)
|
|
1024
1139
|
return;
|
|
1025
|
-
const
|
|
1026
|
-
if (
|
|
1140
|
+
const selectedObjects = this._store.getObjectsFromPointerEvent(event, '.object');
|
|
1141
|
+
if (selectedObjects.length === 0)
|
|
1027
1142
|
return;
|
|
1028
|
-
|
|
1143
|
+
const x = this._store.state.pointerX;
|
|
1144
|
+
const y = this._store.state.pointerY;
|
|
1145
|
+
selectedObjects.forEach(selectedObject => {
|
|
1146
|
+
selectedObject.markedForRemoval = selectedObject.hitTest(x, y);
|
|
1147
|
+
});
|
|
1029
1148
|
this._store.rerender();
|
|
1030
1149
|
}
|
|
1031
1150
|
}
|
|
@@ -1033,9 +1152,7 @@ class KritzelEraserTool extends KritzelBaseTool {
|
|
|
1033
1152
|
handlePointerUp(event) {
|
|
1034
1153
|
if (event.pointerType === 'mouse') {
|
|
1035
1154
|
if (this._store.state.isErasing) {
|
|
1036
|
-
const removeCommands = this._store.allObjects
|
|
1037
|
-
.filter(object => object.markedForRemoval)
|
|
1038
|
-
.map(object => {
|
|
1155
|
+
const removeCommands = this._store.allObjects.filter(object => object.markedForRemoval).map(object => {
|
|
1039
1156
|
object.markedForRemoval = false;
|
|
1040
1157
|
return new RemoveObjectCommand(this._store, this, object);
|
|
1041
1158
|
});
|
|
@@ -1118,7 +1235,7 @@ class KritzelMoveHandler extends KritzelBaseHandler {
|
|
|
1118
1235
|
var _a, _b;
|
|
1119
1236
|
if (event.pointerType === 'mouse') {
|
|
1120
1237
|
if (KritzelEventHelper.isLeftClick(event)) {
|
|
1121
|
-
if (((_a = this._store.state.selectionGroup) === null || _a === void 0 ? void 0 : _a.
|
|
1238
|
+
if (((_a = this._store.state.selectionGroup) === null || _a === void 0 ? void 0 : _a.isSelected) && !this._store.state.isResizeHandleSelected && !this._store.state.isRotationHandleSelected) {
|
|
1122
1239
|
const clientX = event.clientX - this._store.offsetX;
|
|
1123
1240
|
const clientY = event.clientY - this._store.offsetY;
|
|
1124
1241
|
this._store.state.isDragging = true;
|
|
@@ -1132,7 +1249,7 @@ class KritzelMoveHandler extends KritzelBaseHandler {
|
|
|
1132
1249
|
if (event.pointerType === 'touch') {
|
|
1133
1250
|
const activePointers = Array.from(this._store.state.pointers.values());
|
|
1134
1251
|
if (this._store.state.pointers.size === 1) {
|
|
1135
|
-
if (((_b = this._store.state.selectionGroup) === null || _b === void 0 ? void 0 : _b.
|
|
1252
|
+
if (((_b = this._store.state.selectionGroup) === null || _b === void 0 ? void 0 : _b.isSelected) && !this._store.state.isResizeHandleSelected && !this._store.state.isRotationHandleSelected) {
|
|
1136
1253
|
const x = Math.round(activePointers[0].clientX - this._store.offsetX);
|
|
1137
1254
|
const y = Math.round(activePointers[0].clientY - this._store.offsetY);
|
|
1138
1255
|
this.dragStartX = x;
|
|
@@ -1740,7 +1857,7 @@ class KritzelSelectionHandler extends KritzelBaseHandler {
|
|
|
1740
1857
|
.forEach(object => {
|
|
1741
1858
|
const objectPolygon = object.rotatedPolygon;
|
|
1742
1859
|
const selectionBoxPolygon = this._store.state.selectionBox.rotatedPolygon;
|
|
1743
|
-
object.
|
|
1860
|
+
object.isSelected = KritzelGeometryHelper.doPolygonsIntersect(objectPolygon, selectionBoxPolygon);
|
|
1744
1861
|
});
|
|
1745
1862
|
}
|
|
1746
1863
|
addSelectedObjectAtIndexToSelectionGroup(index) {
|
|
@@ -1749,10 +1866,10 @@ class KritzelSelectionHandler extends KritzelBaseHandler {
|
|
|
1749
1866
|
if (!selectedObject) {
|
|
1750
1867
|
return;
|
|
1751
1868
|
}
|
|
1752
|
-
selectedObjects.forEach(o => (o.
|
|
1869
|
+
selectedObjects.forEach(o => (o.isSelected = false));
|
|
1753
1870
|
this._store.state.selectionGroup = KritzelSelectionGroup.create(this._store);
|
|
1754
1871
|
this._store.state.selectionGroup.addOrRemove(selectedObject);
|
|
1755
|
-
this._store.state.selectionGroup.
|
|
1872
|
+
this._store.state.selectionGroup.isSelected = true;
|
|
1756
1873
|
this._store.state.selectionGroup.rotation = this._store.state.selectionGroup.objects[0].rotation;
|
|
1757
1874
|
this._store.history.executeCommand(new AddSelectionGroupCommand(this._store, this, this._store.state.selectionGroup));
|
|
1758
1875
|
}
|
|
@@ -1763,10 +1880,10 @@ class KritzelSelectionHandler extends KritzelBaseHandler {
|
|
|
1763
1880
|
}
|
|
1764
1881
|
this._store.state.selectionGroup = KritzelSelectionGroup.create(this._store);
|
|
1765
1882
|
selectedObjects.forEach(o => {
|
|
1766
|
-
o.
|
|
1883
|
+
o.isSelected = false;
|
|
1767
1884
|
this._store.state.selectionGroup.addOrRemove(o);
|
|
1768
1885
|
});
|
|
1769
|
-
this._store.state.selectionGroup.
|
|
1886
|
+
this._store.state.selectionGroup.isSelected = true;
|
|
1770
1887
|
if (this._store.state.selectionGroup.length === 1) {
|
|
1771
1888
|
this._store.state.selectionGroup.rotation = this._store.state.selectionGroup.objects[0].rotation;
|
|
1772
1889
|
}
|
|
@@ -1799,12 +1916,8 @@ class KritzelSelectionTool extends KritzelBaseTool {
|
|
|
1799
1916
|
!this._store.state.isRotationHandleSelected) {
|
|
1800
1917
|
this._store.history.executeCommand(new RemoveSelectionGroupCommand(this._store, this._store.state.selectionGroup));
|
|
1801
1918
|
}
|
|
1802
|
-
if (selectedObject && selectedObject.
|
|
1803
|
-
|
|
1804
|
-
if (this._store.state.isDragging === false && this._store.state.isResizing === false && this._store.state.isRotating === false) {
|
|
1805
|
-
selectedObject.objects[0].onSelectedClick();
|
|
1806
|
-
}
|
|
1807
|
-
}, 100);
|
|
1919
|
+
if (selectedObject && selectedObject.isSelected === false && (selectedObject === null || selectedObject === void 0 ? void 0 : selectedObject.objects.length) === 1 && selectedObject.objects[0].isInteractive) {
|
|
1920
|
+
return;
|
|
1808
1921
|
}
|
|
1809
1922
|
}
|
|
1810
1923
|
this.moveHandler.handlePointerDown(event);
|
|
@@ -1941,6 +2054,9 @@ class KritzelReviver {
|
|
|
1941
2054
|
case 'KritzelImage':
|
|
1942
2055
|
revivedObj = KritzelImage.create(this._store).revive(obj);
|
|
1943
2056
|
break;
|
|
2057
|
+
case 'KritzelCustomElement':
|
|
2058
|
+
revivedObj = KritzelCustomElement.create(this._store).revive(obj);
|
|
2059
|
+
break;
|
|
1944
2060
|
case 'KritzelSelectionGroup':
|
|
1945
2061
|
revivedObj = KritzelSelectionGroup.create(this._store).revive(obj);
|
|
1946
2062
|
break;
|
|
@@ -2006,7 +2122,7 @@ class KritzelSelectionGroup extends KritzelBaseObject {
|
|
|
2006
2122
|
this.refreshObjectDimensions();
|
|
2007
2123
|
}
|
|
2008
2124
|
deselectAllChildren() {
|
|
2009
|
-
this.objects.forEach(obj => (obj.
|
|
2125
|
+
this.objects.forEach(obj => (obj.isSelected = false));
|
|
2010
2126
|
}
|
|
2011
2127
|
updatePosition(x, y) {
|
|
2012
2128
|
this.objects.forEach(obj => {
|
|
@@ -2211,7 +2327,7 @@ class KritzelImageTool extends KritzelBaseTool {
|
|
|
2211
2327
|
addImageToStore(image) {
|
|
2212
2328
|
const selectionGroup = KritzelSelectionGroup.create(this._store);
|
|
2213
2329
|
selectionGroup.addOrRemove(image);
|
|
2214
|
-
selectionGroup.
|
|
2330
|
+
selectionGroup.isSelected = true;
|
|
2215
2331
|
const addImageCommand = new AddObjectCommand(this._store, this, image);
|
|
2216
2332
|
const addSelectionGroupCommand = new AddSelectionGroupCommand(this._store, this, selectionGroup);
|
|
2217
2333
|
this._store.history.executeCommand(new BatchCommand(this._store, this, [addImageCommand, addSelectionGroupCommand]));
|
|
@@ -2337,6 +2453,6 @@ exports.KritzelToolRegistry = KritzelToolRegistry;
|
|
|
2337
2453
|
exports.KrtizelSelectionBox = KrtizelSelectionBox;
|
|
2338
2454
|
exports.RemoveObjectCommand = RemoveObjectCommand;
|
|
2339
2455
|
exports.RemoveSelectionGroupCommand = RemoveSelectionGroupCommand;
|
|
2340
|
-
//# sourceMappingURL=index-
|
|
2456
|
+
//# sourceMappingURL=index-CFCyVs0_.js.map
|
|
2341
2457
|
|
|
2342
|
-
//# sourceMappingURL=index-
|
|
2458
|
+
//# sourceMappingURL=index-CFCyVs0_.js.map
|