kritzel-stencil 0.0.121 → 0.0.123
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-BcrLbdO1.js → index-C05uAr89.js} +10 -4
- package/dist/cjs/index-C05uAr89.js.map +1 -0
- package/dist/cjs/{index-BjLSiQIM.js → index-UcX3pzju.js} +348 -141
- package/dist/cjs/index-UcX3pzju.js.map +1 -0
- package/dist/cjs/index.cjs.js +1 -1
- package/dist/cjs/kritzel-brush-style_18.cjs.entry.js +137 -81
- package/dist/cjs/kritzel-brush-style_18.cjs.entry.js.map +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/stencil.cjs.js +2 -2
- package/dist/cjs/stencil.cjs.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/hover.handler.js +22 -0
- package/dist/collection/classes/handlers/hover.handler.js.map +1 -0
- 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 +16 -20
- 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 +34 -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 +133 -4
- package/dist/collection/classes/objects/path.class.js.map +1 -1
- package/dist/collection/classes/objects/selection-box.class.js +2 -2
- package/dist/collection/classes/objects/selection-box.class.js.map +1 -1
- package/dist/collection/classes/objects/selection-group.class.js +3 -2
- 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 +17 -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 +5 -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/collection-manifest.json +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 +43 -37
- package/dist/collection/components/core/kritzel-engine/kritzel-engine.js.map +1 -1
- package/dist/collection/components/shared/kritzel-color-palette/kritzel-color-palette.css +1 -1
- package/dist/collection/components/shared/kritzel-font-size/kritzel-font-size.css +1 -1
- package/dist/collection/components/shared/kritzel-stroke-size/kritzel-stroke-size.css +1 -1
- package/dist/collection/components/ui/kritzel-controls/kritzel-controls.css +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 +3 -3
- package/dist/components/kritzel-brush-style.js +1 -1
- package/dist/components/kritzel-color-palette.js +1 -1
- package/dist/components/kritzel-color.js +1 -1
- package/dist/components/kritzel-context-menu.js +1 -1
- package/dist/components/kritzel-control-brush-config.js +1 -1
- package/dist/components/kritzel-control-text-config.js +1 -1
- package/dist/components/kritzel-controls.js +1 -1
- package/dist/components/kritzel-cursor-trail.js +1 -1
- package/dist/components/kritzel-dropdown.js +1 -1
- package/dist/components/kritzel-editor.js +23 -23
- package/dist/components/kritzel-editor.js.map +1 -1
- package/dist/components/kritzel-engine.js +1 -1
- package/dist/components/kritzel-font-family.js +1 -1
- package/dist/components/kritzel-font-size.js +1 -1
- package/dist/components/kritzel-font.js +1 -1
- package/dist/components/kritzel-icon.js +1 -1
- package/dist/components/kritzel-stroke-size.js +1 -1
- package/dist/components/kritzel-tooltip.js +1 -1
- package/dist/components/kritzel-utility-panel.js +1 -1
- package/dist/components/{p-CqPrOhzi.js → p-BOj_wqdw.js} +4 -4
- package/dist/components/{p-CqPrOhzi.js.map → p-BOj_wqdw.js.map} +1 -1
- package/dist/components/{p-CEYRFk55.js → p-BY8BWGge.js} +4 -4
- package/dist/components/{p-CEYRFk55.js.map → p-BY8BWGge.js.map} +1 -1
- package/dist/components/{p-D-Rf05Ov.js → p-Bn5P7YQn.js} +5 -5
- package/dist/components/{p-D-Rf05Ov.js.map → p-Bn5P7YQn.js.map} +1 -1
- package/dist/components/{p-CIb4IA9u.js → p-C9usqwb5.js} +5 -5
- package/dist/components/{p-CIb4IA9u.js.map → p-C9usqwb5.js.map} +1 -1
- package/dist/components/{p-gDLg_PJJ.js → p-CF8ziFc4.js} +4 -4
- package/dist/components/{p-gDLg_PJJ.js.map → p-CF8ziFc4.js.map} +1 -1
- package/dist/components/{p-CDpq9L_H.js → p-CiT5gBDh.js} +3 -3
- package/dist/components/{p-CDpq9L_H.js.map → p-CiT5gBDh.js.map} +1 -1
- package/dist/components/{p-D1oFXBAp.js → p-Cn_kantt.js} +5 -5
- package/dist/components/{p-D1oFXBAp.js.map → p-Cn_kantt.js.map} +1 -1
- package/dist/components/{p-DC3j4P1n.js → p-Cnc43o9b.js} +227 -41
- package/dist/components/p-Cnc43o9b.js.map +1 -0
- package/dist/components/{p-BAMl2Ww6.js → p-CneTqrgt.js} +18 -18
- package/dist/components/{p-BAMl2Ww6.js.map → p-CneTqrgt.js.map} +1 -1
- package/dist/components/{p-B2wWYPH8.js → p-CtiROna-.js} +3 -3
- package/dist/components/{p-B2wWYPH8.js.map → p-CtiROna-.js.map} +1 -1
- package/dist/components/{p-D0L3GqSK.js → p-Cw2ATHMj.js} +3 -3
- package/dist/components/{p-D0L3GqSK.js.map → p-Cw2ATHMj.js.map} +1 -1
- package/dist/components/{p-CxmkJbeV.js → p-D0sLslUq.js} +3 -3
- package/dist/components/{p-CxmkJbeV.js.map → p-D0sLslUq.js.map} +1 -1
- package/dist/components/{p-dCaxwGmu.js → p-DJN0U8pI.js} +10 -4
- package/dist/components/p-DJN0U8pI.js.map +1 -0
- package/dist/components/{p-q-xqpmae.js → p-DJaVT2yR.js} +255 -178
- package/dist/components/p-DJaVT2yR.js.map +1 -0
- package/dist/components/{p-C3E9PtD3.js → p-DMAzUKo6.js} +10 -10
- package/dist/components/{p-C3E9PtD3.js.map → p-DMAzUKo6.js.map} +1 -1
- package/dist/components/{p-DbPbyRLO.js → p-DSLY0tr5.js} +5 -5
- package/dist/components/{p-DbPbyRLO.js.map → p-DSLY0tr5.js.map} +1 -1
- package/dist/components/{p--2FkikYE.js → p-DpiklJU9.js} +3 -3
- package/dist/components/{p--2FkikYE.js.map → p-DpiklJU9.js.map} +1 -1
- package/dist/components/{p--tElassI.js → p-NZJPrwJV.js} +3 -3
- package/dist/components/{p--tElassI.js.map → p-NZJPrwJV.js.map} +1 -1
- package/dist/components/{p-BSS4UREq.js → p-ubNAWsY_.js} +9 -9
- package/dist/components/{p-BSS4UREq.js.map → p-ubNAWsY_.js.map} +1 -1
- package/dist/esm/{index-BPFXWTBp.js → index-BGl8znzE.js} +10 -4
- package/dist/esm/index-BGl8znzE.js.map +1 -0
- package/dist/esm/{index-DsUDklEm.js → index-DO2IiM_o.js} +348 -141
- package/dist/esm/index-DO2IiM_o.js.map +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/kritzel-brush-style_18.entry.js +137 -81
- package/dist/esm/kritzel-brush-style_18.entry.js.map +1 -1
- package/dist/esm/loader.js +2 -2
- package/dist/esm/stencil.js +3 -3
- package/dist/esm/stencil.js.map +1 -1
- package/dist/stencil/index.esm.js +1 -1
- package/dist/stencil/p-BGl8znzE.js +3 -0
- package/dist/stencil/p-BGl8znzE.js.map +1 -0
- package/dist/stencil/p-DO2IiM_o.js +2 -0
- package/dist/stencil/p-DO2IiM_o.js.map +1 -0
- package/dist/stencil/p-c64f6589.entry.js +2 -0
- package/dist/stencil/p-c64f6589.entry.js.map +1 -0
- package/dist/stencil/stencil.esm.js +1 -1
- package/dist/stencil/stencil.esm.js.map +1 -1
- package/dist/types/classes/handlers/hover.handler.d.ts +6 -0
- package/dist/types/classes/handlers/selection.handler.d.ts +1 -1
- package/dist/types/classes/history.class.d.ts +1 -0
- package/dist/types/classes/objects/base-object.class.d.ts +12 -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 +9 -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/classes/tools/selection-tool.class.d.ts +2 -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 +12 -4
- package/package.json +5 -5
- package/dist/cjs/index-BcrLbdO1.js.map +0 -1
- package/dist/cjs/index-BjLSiQIM.js.map +0 -1
- package/dist/components/p-DC3j4P1n.js.map +0 -1
- package/dist/components/p-dCaxwGmu.js.map +0 -1
- package/dist/components/p-q-xqpmae.js.map +0 -1
- package/dist/esm/index-BPFXWTBp.js.map +0 -1
- package/dist/esm/index-DsUDklEm.js.map +0 -1
- package/dist/stencil/p-3797c300.entry.js +0 -2
- package/dist/stencil/p-3797c300.entry.js.map +0 -1
- package/dist/stencil/p-BPFXWTBp.js +0 -3
- package/dist/stencil/p-BPFXWTBp.js.map +0 -1
- package/dist/stencil/p-DsUDklEm.js +0 -2
- package/dist/stencil/p-DsUDklEm.js.map +0 -1
|
@@ -296,8 +296,12 @@ class ObjectHelper {
|
|
|
296
296
|
}
|
|
297
297
|
static clone(objOrObjs) {
|
|
298
298
|
const cloneObject = (obj) => {
|
|
299
|
-
const remainingProps = __rest(
|
|
300
|
-
|
|
299
|
+
const _a = obj, { element } = _a, remainingProps = __rest(_a, ["_store", "_elementRef", "totalWidth", "totalHeight", "element"]);
|
|
300
|
+
const clonedProps = structuredClone(remainingProps);
|
|
301
|
+
if (element && element instanceof HTMLElement) {
|
|
302
|
+
clonedProps.element = element.cloneNode(true);
|
|
303
|
+
}
|
|
304
|
+
return clonedProps;
|
|
301
305
|
};
|
|
302
306
|
if (Array.isArray(objOrObjs)) {
|
|
303
307
|
return objOrObjs.map(cloneObject);
|
|
@@ -312,6 +316,59 @@ class ObjectHelper {
|
|
|
312
316
|
}
|
|
313
317
|
}
|
|
314
318
|
|
|
319
|
+
class KritzelGeometryHelper {
|
|
320
|
+
static doPolygonsIntersect(polygon1, polygon2) {
|
|
321
|
+
// 1. Convert polygons to array of points for easier processing
|
|
322
|
+
const points1 = [polygon1.bottomLeft, polygon1.bottomRight, polygon1.topRight, polygon1.topLeft];
|
|
323
|
+
const points2 = [polygon2.bottomLeft, polygon2.bottomRight, polygon2.topRight, polygon2.topLeft];
|
|
324
|
+
// 2. Check if any point of polygon1 is inside polygon2
|
|
325
|
+
for (const point of points1) {
|
|
326
|
+
if (this.isPointInPolygon(point, points2)) {
|
|
327
|
+
return true;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
// 3. Check if any point of polygon2 is inside polygon1
|
|
331
|
+
for (const point of points2) {
|
|
332
|
+
if (this.isPointInPolygon(point, points1)) {
|
|
333
|
+
return true;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
// 4. Check for edge intersections (more complex)
|
|
337
|
+
for (let i = 0; i < points1.length; i++) {
|
|
338
|
+
const p1a = points1[i];
|
|
339
|
+
const p1b = points1[(i + 1) % points1.length]; // Wrap around to the first point
|
|
340
|
+
for (let j = 0; j < points2.length; j++) {
|
|
341
|
+
const p2a = points2[j];
|
|
342
|
+
const p2b = points2[(j + 1) % points2.length];
|
|
343
|
+
if (this.intersectLines(p1a, p1b, p2a, p2b)) {
|
|
344
|
+
return true;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
return false; // No intersection found
|
|
349
|
+
}
|
|
350
|
+
static isPointInPolygon(point, polygon) {
|
|
351
|
+
let inside = false;
|
|
352
|
+
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
|
|
353
|
+
const xi = polygon[i].x, yi = polygon[i].y;
|
|
354
|
+
const xj = polygon[j].x, yj = polygon[j].y;
|
|
355
|
+
const intersect = yi > point.y !== yj > point.y && point.x < ((xj - xi) * (point.y - yi)) / (yj - yi) + xi;
|
|
356
|
+
if (intersect)
|
|
357
|
+
inside = !inside;
|
|
358
|
+
}
|
|
359
|
+
return inside;
|
|
360
|
+
}
|
|
361
|
+
static intersectLines(p1a, p1b, p2a, p2b) {
|
|
362
|
+
const det = (p1b.x - p1a.x) * (p2b.y - p2a.y) - (p1b.y - p1a.y) * (p2b.x - p2a.x);
|
|
363
|
+
if (det === 0) {
|
|
364
|
+
return false; // Lines are parallel
|
|
365
|
+
}
|
|
366
|
+
const t = ((p2a.x - p1a.x) * (p2b.y - p2a.y) - (p2a.y - p1a.y) * (p2b.x - p2a.x)) / det;
|
|
367
|
+
const u = -((p1a.x - p2a.x) * (p1b.y - p1a.y) - (p1a.y - p2a.y) * (p1b.x - p1a.x)) / det;
|
|
368
|
+
return t >= 0 && t <= 1 && u >= 0 && u <= 1;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
315
372
|
class KritzelBaseObject {
|
|
316
373
|
get totalWidth() {
|
|
317
374
|
return this.width + this.padding * 2;
|
|
@@ -346,8 +403,8 @@ class KritzelBaseObject {
|
|
|
346
403
|
};
|
|
347
404
|
}
|
|
348
405
|
get rotatedPolygon() {
|
|
349
|
-
const cx =
|
|
350
|
-
const cy =
|
|
406
|
+
const cx = this.translateX + this.totalWidth / 2 / this.scale;
|
|
407
|
+
const cy = this.translateY + this.totalHeight / 2 / this.scale;
|
|
351
408
|
const angle = this.rotation;
|
|
352
409
|
const adjustedWidth = this.totalWidth / this.scale;
|
|
353
410
|
const adjustedHeight = this.totalHeight / this.scale;
|
|
@@ -367,39 +424,19 @@ class KritzelBaseObject {
|
|
|
367
424
|
return rotatedCorners;
|
|
368
425
|
}
|
|
369
426
|
get minXRotated() {
|
|
370
|
-
const corners = [
|
|
371
|
-
this.rotatedPolygon.topLeft.x,
|
|
372
|
-
this.rotatedPolygon.topRight.x,
|
|
373
|
-
this.rotatedPolygon.bottomRight.x,
|
|
374
|
-
this.rotatedPolygon.bottomLeft.x,
|
|
375
|
-
];
|
|
427
|
+
const corners = [this.rotatedPolygon.topLeft.x, this.rotatedPolygon.topRight.x, this.rotatedPolygon.bottomRight.x, this.rotatedPolygon.bottomLeft.x];
|
|
376
428
|
return Math.min(...corners);
|
|
377
429
|
}
|
|
378
430
|
get minYRotated() {
|
|
379
|
-
const corners = [
|
|
380
|
-
this.rotatedPolygon.topLeft.y,
|
|
381
|
-
this.rotatedPolygon.topRight.y,
|
|
382
|
-
this.rotatedPolygon.bottomRight.y,
|
|
383
|
-
this.rotatedPolygon.bottomLeft.y,
|
|
384
|
-
];
|
|
431
|
+
const corners = [this.rotatedPolygon.topLeft.y, this.rotatedPolygon.topRight.y, this.rotatedPolygon.bottomRight.y, this.rotatedPolygon.bottomLeft.y];
|
|
385
432
|
return Math.min(...corners);
|
|
386
433
|
}
|
|
387
434
|
get maxXRotated() {
|
|
388
|
-
const corners = [
|
|
389
|
-
this.rotatedPolygon.topLeft.x,
|
|
390
|
-
this.rotatedPolygon.topRight.x,
|
|
391
|
-
this.rotatedPolygon.bottomRight.x,
|
|
392
|
-
this.rotatedPolygon.bottomLeft.x,
|
|
393
|
-
];
|
|
435
|
+
const corners = [this.rotatedPolygon.topLeft.x, this.rotatedPolygon.topRight.x, this.rotatedPolygon.bottomRight.x, this.rotatedPolygon.bottomLeft.x];
|
|
394
436
|
return Math.max(...corners);
|
|
395
437
|
}
|
|
396
438
|
get maxYRotated() {
|
|
397
|
-
const corners = [
|
|
398
|
-
this.rotatedPolygon.topLeft.y,
|
|
399
|
-
this.rotatedPolygon.topRight.y,
|
|
400
|
-
this.rotatedPolygon.bottomRight.y,
|
|
401
|
-
this.rotatedPolygon.bottomLeft.y,
|
|
402
|
-
];
|
|
439
|
+
const corners = [this.rotatedPolygon.topLeft.y, this.rotatedPolygon.topRight.y, this.rotatedPolygon.bottomRight.y, this.rotatedPolygon.bottomLeft.y];
|
|
403
440
|
return Math.max(...corners);
|
|
404
441
|
}
|
|
405
442
|
get transformationMatrix() {
|
|
@@ -419,18 +456,20 @@ class KritzelBaseObject {
|
|
|
419
456
|
}
|
|
420
457
|
constructor() {
|
|
421
458
|
this.__class__ = 'KritzelBaseObject';
|
|
422
|
-
this.visible = true;
|
|
423
459
|
this.borderWidth = 0;
|
|
424
460
|
this.opacity = 1;
|
|
425
461
|
this.padding = 0;
|
|
426
|
-
this.selected = false;
|
|
427
462
|
this.resizing = false;
|
|
428
463
|
this.rotation = 0;
|
|
429
464
|
this.markedForRemoval = false;
|
|
430
|
-
this.isMounted = false;
|
|
431
465
|
this.zIndex = 0;
|
|
466
|
+
this.isVisible = true;
|
|
467
|
+
this.isSelected = false;
|
|
468
|
+
this.isHovered = false;
|
|
469
|
+
this.isMounted = false;
|
|
432
470
|
this.isEditable = false;
|
|
433
|
-
this.
|
|
471
|
+
this.isInteractive = false;
|
|
472
|
+
this.isDebugInfoVisible = false;
|
|
434
473
|
this.id = this.generateId();
|
|
435
474
|
}
|
|
436
475
|
static create(store) {
|
|
@@ -446,6 +485,18 @@ class KritzelBaseObject {
|
|
|
446
485
|
this.elementRef = element;
|
|
447
486
|
this.isMounted = true;
|
|
448
487
|
}
|
|
488
|
+
unmount() {
|
|
489
|
+
if (!this.isMounted) {
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
this.isMounted = false;
|
|
493
|
+
}
|
|
494
|
+
remount() {
|
|
495
|
+
if (!this.isMounted) {
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
this.isMounted = false;
|
|
499
|
+
}
|
|
449
500
|
generateId() {
|
|
450
501
|
return ObjectHelper.generateUUID();
|
|
451
502
|
}
|
|
@@ -455,10 +506,10 @@ class KritzelBaseObject {
|
|
|
455
506
|
y: -this._store.state.translateY / this._store.state.scale,
|
|
456
507
|
width: this._store.state.viewportWidth / this._store.state.scale,
|
|
457
508
|
height: this._store.state.viewportHeight / this._store.state.scale};
|
|
458
|
-
return this.boundingBox.x < viewportBounds.x + viewportBounds.width &&
|
|
509
|
+
return (this.boundingBox.x < viewportBounds.x + viewportBounds.width &&
|
|
459
510
|
this.boundingBox.x + this.boundingBox.width > viewportBounds.x &&
|
|
460
511
|
this.boundingBox.y < viewportBounds.y + viewportBounds.height &&
|
|
461
|
-
this.boundingBox.y + this.boundingBox.height > viewportBounds.y;
|
|
512
|
+
this.boundingBox.y + this.boundingBox.height > viewportBounds.y);
|
|
462
513
|
}
|
|
463
514
|
centerInViewport() {
|
|
464
515
|
const scale = this._store.state.scale;
|
|
@@ -503,6 +554,13 @@ class KritzelBaseObject {
|
|
|
503
554
|
edit() {
|
|
504
555
|
// This method can be overridden by subclasses to handle edit actions.
|
|
505
556
|
}
|
|
557
|
+
hitTest(_x, _y) {
|
|
558
|
+
return true; // Default implementation, can be overridden by subclasses
|
|
559
|
+
}
|
|
560
|
+
hitTestPolygon(polygon) {
|
|
561
|
+
const objectPolygon = this.rotatedPolygon;
|
|
562
|
+
return KritzelGeometryHelper.doPolygonsIntersect(objectPolygon, polygon);
|
|
563
|
+
}
|
|
506
564
|
}
|
|
507
565
|
|
|
508
566
|
class KritzelText extends KritzelBaseObject {
|
|
@@ -518,7 +576,7 @@ class KritzelText extends KritzelBaseObject {
|
|
|
518
576
|
this.fontColor = '#000000';
|
|
519
577
|
this.initialWidth = 3;
|
|
520
578
|
this.isNew = true;
|
|
521
|
-
this.
|
|
579
|
+
this.isDebugInfoVisible = true;
|
|
522
580
|
this.isEditable = true;
|
|
523
581
|
this.rows = 1;
|
|
524
582
|
if (config) {
|
|
@@ -679,8 +737,9 @@ class KritzelPath extends KritzelBaseObject {
|
|
|
679
737
|
this.height = 0;
|
|
680
738
|
this.width = 0;
|
|
681
739
|
this.scale = 1;
|
|
682
|
-
this.
|
|
683
|
-
this.
|
|
740
|
+
this.isVisible = true;
|
|
741
|
+
this.isDebugInfoVisible = true;
|
|
742
|
+
this._adjustedPoints = null;
|
|
684
743
|
this.options = config;
|
|
685
744
|
this.points = (_a = config === null || config === void 0 ? void 0 : config.points) !== null && _a !== void 0 ? _a : [];
|
|
686
745
|
this.translateX = (_b = config === null || config === void 0 ? void 0 : config.translateX) !== null && _b !== void 0 ? _b : 0;
|
|
@@ -724,10 +783,137 @@ class KritzelPath extends KritzelBaseObject {
|
|
|
724
783
|
this.y = Math.min(...this.points.map(p => p[1])) - this.strokeWidth / 2;
|
|
725
784
|
this.translateX = x;
|
|
726
785
|
this.translateY = y;
|
|
786
|
+
this._adjustedPoints = null;
|
|
727
787
|
}
|
|
728
788
|
rotate(value) {
|
|
729
|
-
|
|
730
|
-
this.
|
|
789
|
+
this.rotation = value;
|
|
790
|
+
this._adjustedPoints = null;
|
|
791
|
+
}
|
|
792
|
+
move(_startX, _startY, _endX, _endY) {
|
|
793
|
+
this._adjustedPoints = null;
|
|
794
|
+
}
|
|
795
|
+
hitTest(x, y) {
|
|
796
|
+
const halfStroke = this.strokeWidth / this.scale / 2;
|
|
797
|
+
if (this._adjustedPoints === null) {
|
|
798
|
+
this._adjustedPoints = this.computeAdjustedPoints();
|
|
799
|
+
}
|
|
800
|
+
if (this._adjustedPoints.length === 1) {
|
|
801
|
+
const p1 = this._adjustedPoints[0];
|
|
802
|
+
const distance = this.pointToLineSegmentDistance(x, y, p1[0], p1[1], p1[0], p1[1]);
|
|
803
|
+
return distance <= halfStroke;
|
|
804
|
+
}
|
|
805
|
+
for (let i = 0; i < this._adjustedPoints.length - 1; i++) {
|
|
806
|
+
const p1 = this._adjustedPoints[i];
|
|
807
|
+
const p2 = this._adjustedPoints[i + 1];
|
|
808
|
+
const distance = this.pointToLineSegmentDistance(x, y, p1[0], p1[1], p2[0], p2[1]);
|
|
809
|
+
if (distance <= halfStroke) {
|
|
810
|
+
return true;
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
return false;
|
|
814
|
+
}
|
|
815
|
+
hitTestPolygon(polygon) {
|
|
816
|
+
const halfStroke = this.strokeWidth / this.scale / 2;
|
|
817
|
+
if (this._adjustedPoints === null) {
|
|
818
|
+
this._adjustedPoints = this.computeAdjustedPoints();
|
|
819
|
+
}
|
|
820
|
+
const polyPoints = [
|
|
821
|
+
{ x: polygon.bottomLeft.x, y: polygon.bottomLeft.y },
|
|
822
|
+
{ x: polygon.bottomRight.x, y: polygon.bottomRight.y },
|
|
823
|
+
{ x: polygon.topRight.x, y: polygon.topRight.y },
|
|
824
|
+
{ x: polygon.topLeft.x, y: polygon.topLeft.y },
|
|
825
|
+
];
|
|
826
|
+
for (const [px, py] of this._adjustedPoints) {
|
|
827
|
+
if (KritzelGeometryHelper.isPointInPolygon({ x: px, y: py }, polyPoints)) {
|
|
828
|
+
return true;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
for (const pt of polyPoints) {
|
|
832
|
+
if (this.hitTest(pt.x, pt.y)) {
|
|
833
|
+
return true;
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
for (let i = 0; i < this._adjustedPoints.length - 1; i++) {
|
|
837
|
+
const p1 = { x: this._adjustedPoints[i][0], y: this._adjustedPoints[i][1] };
|
|
838
|
+
const p2 = { x: this._adjustedPoints[i + 1][0], y: this._adjustedPoints[i + 1][1] };
|
|
839
|
+
for (let j = 0; j < polyPoints.length; j++) {
|
|
840
|
+
const q1 = polyPoints[j];
|
|
841
|
+
const q2 = polyPoints[(j + 1) % polyPoints.length];
|
|
842
|
+
if (KritzelGeometryHelper.intersectLines(p1, p2, q1, q2)) {
|
|
843
|
+
return true;
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
for (let i = 0; i < this._adjustedPoints.length - 1; i++) {
|
|
848
|
+
const p1 = this._adjustedPoints[i];
|
|
849
|
+
const p2 = this._adjustedPoints[i + 1];
|
|
850
|
+
for (let j = 0; j < polyPoints.length; j++) {
|
|
851
|
+
const q1 = polyPoints[j];
|
|
852
|
+
const q2 = polyPoints[(j + 1) % polyPoints.length];
|
|
853
|
+
const d1 = this.pointToLineSegmentDistance(q1.x, q1.y, p1[0], p1[1], p2[0], p2[1]);
|
|
854
|
+
const d2 = this.pointToLineSegmentDistance(q2.x, q2.y, p1[0], p1[1], p2[0], p2[1]);
|
|
855
|
+
const d3 = this.pointToLineSegmentDistance(p1[0], p1[1], q1.x, q1.y, q2.x, q2.y);
|
|
856
|
+
const d4 = this.pointToLineSegmentDistance(p2[0], p2[1], q1.x, q1.y, q2.x, q2.y);
|
|
857
|
+
const minD = Math.min(d1, d2, d3, d4);
|
|
858
|
+
if (minD <= halfStroke) {
|
|
859
|
+
return true;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
return false;
|
|
864
|
+
}
|
|
865
|
+
computeAdjustedPoints() {
|
|
866
|
+
var _a;
|
|
867
|
+
if (!((_a = this.points) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
868
|
+
return [];
|
|
869
|
+
}
|
|
870
|
+
const angle = this.rotation;
|
|
871
|
+
const cos = Math.cos(angle);
|
|
872
|
+
const sin = Math.sin(angle);
|
|
873
|
+
const xs = this.points.map(p => p[0]);
|
|
874
|
+
const ys = this.points.map(p => p[1]);
|
|
875
|
+
const pivot = {
|
|
876
|
+
x: (Math.min(...xs) + Math.max(...xs)) / 2,
|
|
877
|
+
y: (Math.min(...ys) + Math.max(...ys)) / 2,
|
|
878
|
+
};
|
|
879
|
+
const { x: cx, y: cy } = pivot;
|
|
880
|
+
const rotatedPoints = this.points.map(([x, y]) => {
|
|
881
|
+
const dx = x - cx;
|
|
882
|
+
const dy = y - cy;
|
|
883
|
+
return [cx + dx * cos - dy * sin, cy + dx * sin + dy * cos];
|
|
884
|
+
});
|
|
885
|
+
const deltaX = this.x - this.translateX;
|
|
886
|
+
const deltaY = this.y - this.translateY;
|
|
887
|
+
return rotatedPoints.map(([px, py]) => [(px + this.options.translateX - deltaX) / this.scale, (py + this.options.translateY - deltaY) / this.scale]);
|
|
888
|
+
}
|
|
889
|
+
pointToLineSegmentDistance(x, y, x1, y1, x2, y2) {
|
|
890
|
+
const A = x - x1;
|
|
891
|
+
const B = y - y1;
|
|
892
|
+
const C = x2 - x1;
|
|
893
|
+
const D = y2 - y1;
|
|
894
|
+
const dot = A * C + B * D;
|
|
895
|
+
const len_sq = C * C + D * D;
|
|
896
|
+
let param = -1;
|
|
897
|
+
if (len_sq !== 0) {
|
|
898
|
+
// in case of 0 length line
|
|
899
|
+
param = dot / len_sq;
|
|
900
|
+
}
|
|
901
|
+
let xx, yy;
|
|
902
|
+
if (param < 0) {
|
|
903
|
+
xx = x1;
|
|
904
|
+
yy = y1;
|
|
905
|
+
}
|
|
906
|
+
else if (param > 1) {
|
|
907
|
+
xx = x2;
|
|
908
|
+
yy = y2;
|
|
909
|
+
}
|
|
910
|
+
else {
|
|
911
|
+
xx = x1 + param * C;
|
|
912
|
+
yy = y1 + param * D;
|
|
913
|
+
}
|
|
914
|
+
const dx = x - xx;
|
|
915
|
+
const dy = y - yy;
|
|
916
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
731
917
|
}
|
|
732
918
|
updateDimensions() {
|
|
733
919
|
const rotatedPoints = this.points.map(([x, y]) => {
|
|
@@ -800,7 +986,7 @@ class KritzelImage extends KritzelBaseObject {
|
|
|
800
986
|
this.maxWidth = 300;
|
|
801
987
|
this.maxHeight = 300;
|
|
802
988
|
this.maxCompressionSize = 300;
|
|
803
|
-
this.
|
|
989
|
+
this.isDebugInfoVisible = true;
|
|
804
990
|
this.src = (config === null || config === void 0 ? void 0 : config.src) || '';
|
|
805
991
|
this.x = (config === null || config === void 0 ? void 0 : config.x) || 0;
|
|
806
992
|
this.y = (config === null || config === void 0 ? void 0 : config.y) || 0;
|
|
@@ -969,6 +1155,57 @@ class BatchCommand extends KritzelBaseCommand {
|
|
|
969
1155
|
}
|
|
970
1156
|
}
|
|
971
1157
|
|
|
1158
|
+
class KritzelCustomElement extends KritzelBaseObject {
|
|
1159
|
+
constructor(config) {
|
|
1160
|
+
super();
|
|
1161
|
+
this.__class__ = 'KritzelCustomElement';
|
|
1162
|
+
this.isInteractive = true;
|
|
1163
|
+
if (config) {
|
|
1164
|
+
this.translateX = config.translateX || 0;
|
|
1165
|
+
this.translateY = config.translateY || 0;
|
|
1166
|
+
this.scale = config.scale || 1;
|
|
1167
|
+
this.element = config.element;
|
|
1168
|
+
this.height = config.height || 0;
|
|
1169
|
+
this.width = config.width || 0;
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
static create(store, config) {
|
|
1173
|
+
const object = new KritzelCustomElement(config);
|
|
1174
|
+
object._store = store;
|
|
1175
|
+
object.id = object.generateId();
|
|
1176
|
+
return object;
|
|
1177
|
+
}
|
|
1178
|
+
mount(element) {
|
|
1179
|
+
if (this.isMounted) {
|
|
1180
|
+
return;
|
|
1181
|
+
}
|
|
1182
|
+
this.elementRef = element;
|
|
1183
|
+
this.isMounted = true;
|
|
1184
|
+
this.elementRef.appendChild(this.element);
|
|
1185
|
+
}
|
|
1186
|
+
resize(x, y, width, height) {
|
|
1187
|
+
if (width <= 1 || height <= 1) {
|
|
1188
|
+
return;
|
|
1189
|
+
}
|
|
1190
|
+
this.width = width;
|
|
1191
|
+
this.height = height;
|
|
1192
|
+
this.translateX = x;
|
|
1193
|
+
this.translateY = y;
|
|
1194
|
+
if (this.element) {
|
|
1195
|
+
this.element.style.width = `${width}px`;
|
|
1196
|
+
this.element.style.height = `${height}px`;
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
copy() {
|
|
1200
|
+
const copiedObject = Object.create(Object.getPrototypeOf(this));
|
|
1201
|
+
Object.assign(copiedObject, this);
|
|
1202
|
+
copiedObject.id = this.generateId();
|
|
1203
|
+
copiedObject.isMounted = false;
|
|
1204
|
+
copiedObject.element = this.element.cloneNode(true);
|
|
1205
|
+
return copiedObject;
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
|
|
972
1209
|
class RemoveObjectCommand extends KritzelBaseCommand {
|
|
973
1210
|
constructor(store, initiator, object) {
|
|
974
1211
|
super(store, initiator);
|
|
@@ -976,9 +1213,11 @@ class RemoveObjectCommand extends KritzelBaseCommand {
|
|
|
976
1213
|
}
|
|
977
1214
|
execute() {
|
|
978
1215
|
this._store.state.objectsOctree.remove(object => object.id === this.object.id);
|
|
1216
|
+
this._store.state.objectsOctree.filter(object => object instanceof KritzelCustomElement).forEach(object => object.remount());
|
|
979
1217
|
}
|
|
980
1218
|
undo() {
|
|
981
1219
|
this._store.state.objectsOctree.insert(this.object);
|
|
1220
|
+
this._store.state.objectsOctree.filter(object => object instanceof KritzelCustomElement).forEach(object => object.remount());
|
|
982
1221
|
}
|
|
983
1222
|
}
|
|
984
1223
|
|
|
@@ -1002,28 +1241,33 @@ class KritzelEraserTool extends KritzelBaseTool {
|
|
|
1002
1241
|
}
|
|
1003
1242
|
}
|
|
1004
1243
|
handlePointerMove(event) {
|
|
1005
|
-
var _a
|
|
1244
|
+
var _a;
|
|
1006
1245
|
if (event.pointerType === 'mouse') {
|
|
1007
1246
|
if (this._store.state.isErasing) {
|
|
1008
|
-
const
|
|
1009
|
-
if (
|
|
1247
|
+
const selectedObjects = this._store.getObjectsFromPointerEvent(event, '.object');
|
|
1248
|
+
if (selectedObjects.length === 0)
|
|
1010
1249
|
return;
|
|
1011
|
-
const
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1250
|
+
const x = this._store.state.pointerX;
|
|
1251
|
+
const y = this._store.state.pointerY;
|
|
1252
|
+
selectedObjects.forEach(selectedObject => {
|
|
1253
|
+
selectedObject.markedForRemoval = selectedObject.hitTest(x, y);
|
|
1254
|
+
});
|
|
1015
1255
|
this._store.rerender();
|
|
1016
1256
|
}
|
|
1017
1257
|
}
|
|
1018
1258
|
if (event.pointerType === 'touch') {
|
|
1019
1259
|
if (this._store.state.pointers.size === 1 && this._store.state.isErasing) {
|
|
1020
|
-
const shadowRoot = (
|
|
1260
|
+
const shadowRoot = (_a = this._store.state.host) === null || _a === void 0 ? void 0 : _a.shadowRoot;
|
|
1021
1261
|
if (!shadowRoot)
|
|
1022
1262
|
return;
|
|
1023
|
-
const
|
|
1024
|
-
if (
|
|
1263
|
+
const selectedObjects = this._store.getObjectsFromPointerEvent(event, '.object');
|
|
1264
|
+
if (selectedObjects.length === 0)
|
|
1025
1265
|
return;
|
|
1026
|
-
|
|
1266
|
+
const x = this._store.state.pointerX;
|
|
1267
|
+
const y = this._store.state.pointerY;
|
|
1268
|
+
selectedObjects.forEach(selectedObject => {
|
|
1269
|
+
selectedObject.markedForRemoval = selectedObject.hitTest(x, y);
|
|
1270
|
+
});
|
|
1027
1271
|
this._store.rerender();
|
|
1028
1272
|
}
|
|
1029
1273
|
}
|
|
@@ -1031,9 +1275,7 @@ class KritzelEraserTool extends KritzelBaseTool {
|
|
|
1031
1275
|
handlePointerUp(event) {
|
|
1032
1276
|
if (event.pointerType === 'mouse') {
|
|
1033
1277
|
if (this._store.state.isErasing) {
|
|
1034
|
-
const removeCommands = this._store.allObjects
|
|
1035
|
-
.filter(object => object.markedForRemoval)
|
|
1036
|
-
.map(object => {
|
|
1278
|
+
const removeCommands = this._store.allObjects.filter(object => object.markedForRemoval).map(object => {
|
|
1037
1279
|
object.markedForRemoval = false;
|
|
1038
1280
|
return new RemoveObjectCommand(this._store, this, object);
|
|
1039
1281
|
});
|
|
@@ -1116,7 +1358,7 @@ class KritzelMoveHandler extends KritzelBaseHandler {
|
|
|
1116
1358
|
var _a, _b;
|
|
1117
1359
|
if (event.pointerType === 'mouse') {
|
|
1118
1360
|
if (KritzelEventHelper.isLeftClick(event)) {
|
|
1119
|
-
if (((_a = this._store.state.selectionGroup) === null || _a === void 0 ? void 0 : _a.
|
|
1361
|
+
if (((_a = this._store.state.selectionGroup) === null || _a === void 0 ? void 0 : _a.isSelected) && !this._store.state.isResizeHandleSelected && !this._store.state.isRotationHandleSelected) {
|
|
1120
1362
|
const clientX = event.clientX - this._store.offsetX;
|
|
1121
1363
|
const clientY = event.clientY - this._store.offsetY;
|
|
1122
1364
|
this._store.state.isDragging = true;
|
|
@@ -1130,7 +1372,7 @@ class KritzelMoveHandler extends KritzelBaseHandler {
|
|
|
1130
1372
|
if (event.pointerType === 'touch') {
|
|
1131
1373
|
const activePointers = Array.from(this._store.state.pointers.values());
|
|
1132
1374
|
if (this._store.state.pointers.size === 1) {
|
|
1133
|
-
if (((_b = this._store.state.selectionGroup) === null || _b === void 0 ? void 0 : _b.
|
|
1375
|
+
if (((_b = this._store.state.selectionGroup) === null || _b === void 0 ? void 0 : _b.isSelected) && !this._store.state.isResizeHandleSelected && !this._store.state.isRotationHandleSelected) {
|
|
1134
1376
|
const x = Math.round(activePointers[0].clientX - this._store.offsetX);
|
|
1135
1377
|
const y = Math.round(activePointers[0].clientY - this._store.offsetY);
|
|
1136
1378
|
this.dragStartX = x;
|
|
@@ -1482,59 +1724,6 @@ class KritzelRotationHandler extends KritzelBaseHandler {
|
|
|
1482
1724
|
}
|
|
1483
1725
|
}
|
|
1484
1726
|
|
|
1485
|
-
class KritzelGeometryHelper {
|
|
1486
|
-
static doPolygonsIntersect(polygon1, polygon2) {
|
|
1487
|
-
// 1. Convert polygons to array of points for easier processing
|
|
1488
|
-
const points1 = [polygon1.bottomLeft, polygon1.bottomRight, polygon1.topRight, polygon1.topLeft];
|
|
1489
|
-
const points2 = [polygon2.bottomLeft, polygon2.bottomRight, polygon2.topRight, polygon2.topLeft];
|
|
1490
|
-
// 2. Check if any point of polygon1 is inside polygon2
|
|
1491
|
-
for (const point of points1) {
|
|
1492
|
-
if (this.isPointInPolygon(point, points2)) {
|
|
1493
|
-
return true;
|
|
1494
|
-
}
|
|
1495
|
-
}
|
|
1496
|
-
// 3. Check if any point of polygon2 is inside polygon1
|
|
1497
|
-
for (const point of points2) {
|
|
1498
|
-
if (this.isPointInPolygon(point, points1)) {
|
|
1499
|
-
return true;
|
|
1500
|
-
}
|
|
1501
|
-
}
|
|
1502
|
-
// 4. Check for edge intersections (more complex)
|
|
1503
|
-
for (let i = 0; i < points1.length; i++) {
|
|
1504
|
-
const p1a = points1[i];
|
|
1505
|
-
const p1b = points1[(i + 1) % points1.length]; // Wrap around to the first point
|
|
1506
|
-
for (let j = 0; j < points2.length; j++) {
|
|
1507
|
-
const p2a = points2[j];
|
|
1508
|
-
const p2b = points2[(j + 1) % points2.length];
|
|
1509
|
-
if (this.intersectLines(p1a, p1b, p2a, p2b)) {
|
|
1510
|
-
return true;
|
|
1511
|
-
}
|
|
1512
|
-
}
|
|
1513
|
-
}
|
|
1514
|
-
return false; // No intersection found
|
|
1515
|
-
}
|
|
1516
|
-
static isPointInPolygon(point, polygon) {
|
|
1517
|
-
let inside = false;
|
|
1518
|
-
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
|
|
1519
|
-
const xi = polygon[i].x, yi = polygon[i].y;
|
|
1520
|
-
const xj = polygon[j].x, yj = polygon[j].y;
|
|
1521
|
-
const intersect = yi > point.y !== yj > point.y && point.x < ((xj - xi) * (point.y - yi)) / (yj - yi) + xi;
|
|
1522
|
-
if (intersect)
|
|
1523
|
-
inside = !inside;
|
|
1524
|
-
}
|
|
1525
|
-
return inside;
|
|
1526
|
-
}
|
|
1527
|
-
static intersectLines(p1a, p1b, p2a, p2b) {
|
|
1528
|
-
const det = (p1b.x - p1a.x) * (p2b.y - p2a.y) - (p1b.y - p1a.y) * (p2b.x - p2a.x);
|
|
1529
|
-
if (det === 0) {
|
|
1530
|
-
return false; // Lines are parallel
|
|
1531
|
-
}
|
|
1532
|
-
const t = ((p2a.x - p1a.x) * (p2b.y - p2a.y) - (p2a.y - p1a.y) * (p2b.x - p2a.x)) / det;
|
|
1533
|
-
const u = -((p1a.x - p2a.x) * (p1b.y - p1a.y) - (p1a.y - p2a.y) * (p1b.x - p1a.x)) / det;
|
|
1534
|
-
return t >= 0 && t <= 1 && u >= 0 && u <= 1;
|
|
1535
|
-
}
|
|
1536
|
-
}
|
|
1537
|
-
|
|
1538
1727
|
class KrtizelSelectionBox extends KritzelBaseObject {
|
|
1539
1728
|
constructor() {
|
|
1540
1729
|
super(...arguments);
|
|
@@ -1547,8 +1736,8 @@ class KrtizelSelectionBox extends KritzelBaseObject {
|
|
|
1547
1736
|
object.id = object.generateId();
|
|
1548
1737
|
object.scale = store.state.scale;
|
|
1549
1738
|
object.zIndex = 99999;
|
|
1550
|
-
object.backgroundColor = 'var(--kritzel-selection-box-background-color, rgba(
|
|
1551
|
-
object.borderColor = 'var(--kritzel-selection-box-border-color, rgba(
|
|
1739
|
+
object.backgroundColor = 'var(--kritzel-selection-box-background-color, rgba(0, 122, 255, 0.2))';
|
|
1740
|
+
object.borderColor = 'var(--kritzel-selection-box-border-color, rgba(0, 122, 255, 0.5))';
|
|
1552
1741
|
object.borderWidth = 2;
|
|
1553
1742
|
object.height = 0;
|
|
1554
1743
|
object.width = 0;
|
|
@@ -1625,8 +1814,10 @@ class KritzelSelectionHandler extends KritzelBaseHandler {
|
|
|
1625
1814
|
if (event.pointerType === 'mouse') {
|
|
1626
1815
|
if (KritzelEventHelper.isLeftClick(event) && this._store.state.isSelecting) {
|
|
1627
1816
|
if (this.isSelectionClick) {
|
|
1628
|
-
this.
|
|
1629
|
-
this.
|
|
1817
|
+
const x = this._store.state.pointerX;
|
|
1818
|
+
const y = this._store.state.pointerY;
|
|
1819
|
+
const selectedObject = this._store.getObjectsFromPointerEvent(event, '.object').find(obj => obj.hitTest(x, y));
|
|
1820
|
+
this.addObjectToSelectionGroup(selectedObject);
|
|
1630
1821
|
this.removeSelectionBox();
|
|
1631
1822
|
}
|
|
1632
1823
|
if (this.isSelectionDrag) {
|
|
@@ -1640,8 +1831,10 @@ class KritzelSelectionHandler extends KritzelBaseHandler {
|
|
|
1640
1831
|
clearTimeout(this.touchStartTimeout);
|
|
1641
1832
|
if (this._store.state.isSelecting) {
|
|
1642
1833
|
if (this.isSelectionClick) {
|
|
1643
|
-
this.
|
|
1644
|
-
this.
|
|
1834
|
+
const x = this._store.state.pointerX;
|
|
1835
|
+
const y = this._store.state.pointerY;
|
|
1836
|
+
const selectedObject = this._store.getObjectsFromPointerEvent(event, '.object').find(obj => obj.hitTest(x, y));
|
|
1837
|
+
this.addObjectToSelectionGroup(selectedObject);
|
|
1645
1838
|
this.removeSelectionBox();
|
|
1646
1839
|
}
|
|
1647
1840
|
if (this.isSelectionDrag) {
|
|
@@ -1735,23 +1928,16 @@ class KritzelSelectionHandler extends KritzelBaseHandler {
|
|
|
1735
1928
|
updateSelectedObjects() {
|
|
1736
1929
|
this._store.allObjects
|
|
1737
1930
|
.filter(o => !(o instanceof KrtizelSelectionBox))
|
|
1738
|
-
.forEach(object =>
|
|
1739
|
-
const objectPolygon = object.rotatedPolygon;
|
|
1740
|
-
const selectionBoxPolygon = this._store.state.selectionBox.rotatedPolygon;
|
|
1741
|
-
object.selected = KritzelGeometryHelper.doPolygonsIntersect(objectPolygon, selectionBoxPolygon);
|
|
1742
|
-
});
|
|
1931
|
+
.forEach(object => (object.isSelected = object.hitTestPolygon(this._store.state.selectionBox.rotatedPolygon)));
|
|
1743
1932
|
}
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
const selectedObject = selectedObjects[index];
|
|
1747
|
-
if (!selectedObject) {
|
|
1933
|
+
addObjectToSelectionGroup(object) {
|
|
1934
|
+
if (!object) {
|
|
1748
1935
|
return;
|
|
1749
1936
|
}
|
|
1750
|
-
selectedObjects.forEach(o => (o.selected = false));
|
|
1751
1937
|
this._store.state.selectionGroup = KritzelSelectionGroup.create(this._store);
|
|
1752
|
-
this._store.state.selectionGroup.addOrRemove(
|
|
1753
|
-
this._store.state.selectionGroup.
|
|
1754
|
-
this._store.state.selectionGroup.rotation =
|
|
1938
|
+
this._store.state.selectionGroup.addOrRemove(object);
|
|
1939
|
+
this._store.state.selectionGroup.isSelected = true;
|
|
1940
|
+
this._store.state.selectionGroup.rotation = object.rotation;
|
|
1755
1941
|
this._store.history.executeCommand(new AddSelectionGroupCommand(this._store, this, this._store.state.selectionGroup));
|
|
1756
1942
|
}
|
|
1757
1943
|
addSelectedObjectsToSelectionGroup() {
|
|
@@ -1761,10 +1947,10 @@ class KritzelSelectionHandler extends KritzelBaseHandler {
|
|
|
1761
1947
|
}
|
|
1762
1948
|
this._store.state.selectionGroup = KritzelSelectionGroup.create(this._store);
|
|
1763
1949
|
selectedObjects.forEach(o => {
|
|
1764
|
-
o.
|
|
1950
|
+
o.isSelected = false;
|
|
1765
1951
|
this._store.state.selectionGroup.addOrRemove(o);
|
|
1766
1952
|
});
|
|
1767
|
-
this._store.state.selectionGroup.
|
|
1953
|
+
this._store.state.selectionGroup.isSelected = true;
|
|
1768
1954
|
if (this._store.state.selectionGroup.length === 1) {
|
|
1769
1955
|
this._store.state.selectionGroup.rotation = this._store.state.selectionGroup.objects[0].rotation;
|
|
1770
1956
|
}
|
|
@@ -1772,11 +1958,31 @@ class KritzelSelectionHandler extends KritzelBaseHandler {
|
|
|
1772
1958
|
}
|
|
1773
1959
|
}
|
|
1774
1960
|
|
|
1961
|
+
class KritzelHoverHandler extends KritzelBaseHandler {
|
|
1962
|
+
constructor(store) {
|
|
1963
|
+
super(store);
|
|
1964
|
+
}
|
|
1965
|
+
handlePointerMove(event) {
|
|
1966
|
+
if (event.pointerType === 'mouse') {
|
|
1967
|
+
const hoveredObject = this._store.getObjectFromPointerEvent(event, '.object');
|
|
1968
|
+
if (!hoveredObject)
|
|
1969
|
+
return;
|
|
1970
|
+
const x = this._store.state.pointerX;
|
|
1971
|
+
const y = this._store.state.pointerY;
|
|
1972
|
+
hoveredObject.isHovered = hoveredObject.hitTest(x, y);
|
|
1973
|
+
if (hoveredObject.isHovered) {
|
|
1974
|
+
console.log(hoveredObject.id);
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1979
|
+
|
|
1775
1980
|
class KritzelSelectionTool extends KritzelBaseTool {
|
|
1776
1981
|
constructor(store) {
|
|
1777
1982
|
super(store);
|
|
1778
1983
|
this.selectionHandler = new KritzelSelectionHandler(this._store);
|
|
1779
1984
|
this.moveHandler = new KritzelMoveHandler(this._store);
|
|
1985
|
+
this.hoverHandler = new KritzelHoverHandler(this._store);
|
|
1780
1986
|
this.resizeHandler = new KritzelResizeHandler(this._store);
|
|
1781
1987
|
this.rotationHandler = new KritzelRotationHandler(this._store);
|
|
1782
1988
|
}
|
|
@@ -1797,12 +2003,8 @@ class KritzelSelectionTool extends KritzelBaseTool {
|
|
|
1797
2003
|
!this._store.state.isRotationHandleSelected) {
|
|
1798
2004
|
this._store.history.executeCommand(new RemoveSelectionGroupCommand(this._store, this._store.state.selectionGroup));
|
|
1799
2005
|
}
|
|
1800
|
-
if (selectedObject && selectedObject.
|
|
1801
|
-
|
|
1802
|
-
if (this._store.state.isDragging === false && this._store.state.isResizing === false && this._store.state.isRotating === false) {
|
|
1803
|
-
selectedObject.objects[0].onSelectedClick();
|
|
1804
|
-
}
|
|
1805
|
-
}, 100);
|
|
2006
|
+
if (selectedObject && selectedObject.isSelected === false && (selectedObject === null || selectedObject === void 0 ? void 0 : selectedObject.objects.length) === 1 && selectedObject.objects[0].isInteractive) {
|
|
2007
|
+
return;
|
|
1806
2008
|
}
|
|
1807
2009
|
}
|
|
1808
2010
|
this.moveHandler.handlePointerDown(event);
|
|
@@ -1843,6 +2045,7 @@ class KritzelSelectionTool extends KritzelBaseTool {
|
|
|
1843
2045
|
}
|
|
1844
2046
|
if (event.pointerType === 'mouse') {
|
|
1845
2047
|
this.moveHandler.handlePointerMove(event);
|
|
2048
|
+
this.hoverHandler.handlePointerMove(event);
|
|
1846
2049
|
this.selectionHandler.handlePointerMove(event);
|
|
1847
2050
|
this.resizeHandler.handlePointerMove(event);
|
|
1848
2051
|
this.rotationHandler.handlePointerMove(event);
|
|
@@ -1939,6 +2142,9 @@ class KritzelReviver {
|
|
|
1939
2142
|
case 'KritzelImage':
|
|
1940
2143
|
revivedObj = KritzelImage.create(this._store).revive(obj);
|
|
1941
2144
|
break;
|
|
2145
|
+
case 'KritzelCustomElement':
|
|
2146
|
+
revivedObj = KritzelCustomElement.create(this._store).revive(obj);
|
|
2147
|
+
break;
|
|
1942
2148
|
case 'KritzelSelectionGroup':
|
|
1943
2149
|
revivedObj = KritzelSelectionGroup.create(this._store).revive(obj);
|
|
1944
2150
|
break;
|
|
@@ -2004,7 +2210,7 @@ class KritzelSelectionGroup extends KritzelBaseObject {
|
|
|
2004
2210
|
this.refreshObjectDimensions();
|
|
2005
2211
|
}
|
|
2006
2212
|
deselectAllChildren() {
|
|
2007
|
-
this.objects.forEach(obj => (obj.
|
|
2213
|
+
this.objects.forEach(obj => (obj.isSelected = false));
|
|
2008
2214
|
}
|
|
2009
2215
|
updatePosition(x, y) {
|
|
2010
2216
|
this.objects.forEach(obj => {
|
|
@@ -2033,6 +2239,7 @@ class KritzelSelectionGroup extends KritzelBaseObject {
|
|
|
2033
2239
|
this.objects.forEach(obj => {
|
|
2034
2240
|
obj.translateX += deltaX;
|
|
2035
2241
|
obj.translateY += deltaY;
|
|
2242
|
+
obj.move(startX, startY, endX, endY);
|
|
2036
2243
|
this._store.state.objectsOctree.update(obj);
|
|
2037
2244
|
});
|
|
2038
2245
|
this.unchangedObjects.forEach(obj => {
|
|
@@ -2071,7 +2278,7 @@ class KritzelSelectionGroup extends KritzelBaseObject {
|
|
|
2071
2278
|
const rotatedY = sin * offsetX + cos * offsetY;
|
|
2072
2279
|
child.translateX = centerX + rotatedX - child.totalWidth / 2 / child.scale;
|
|
2073
2280
|
child.translateY = centerY + rotatedY - child.totalHeight / 2 / child.scale;
|
|
2074
|
-
child.
|
|
2281
|
+
child.rotate(this.objects.length === 1 ? value : value + unchangedChild.rotation);
|
|
2075
2282
|
this._store.state.objectsOctree.update(child);
|
|
2076
2283
|
});
|
|
2077
2284
|
}
|
|
@@ -2209,7 +2416,7 @@ class KritzelImageTool extends KritzelBaseTool {
|
|
|
2209
2416
|
addImageToStore(image) {
|
|
2210
2417
|
const selectionGroup = KritzelSelectionGroup.create(this._store);
|
|
2211
2418
|
selectionGroup.addOrRemove(image);
|
|
2212
|
-
selectionGroup.
|
|
2419
|
+
selectionGroup.isSelected = true;
|
|
2213
2420
|
const addImageCommand = new AddObjectCommand(this._store, this, image);
|
|
2214
2421
|
const addSelectionGroupCommand = new AddSelectionGroupCommand(this._store, this, selectionGroup);
|
|
2215
2422
|
this._store.history.executeCommand(new BatchCommand(this._store, this, [addImageCommand, addSelectionGroupCommand]));
|
|
@@ -2313,6 +2520,6 @@ const DEFAULT_TEXT_CONFIG = {
|
|
|
2313
2520
|
};
|
|
2314
2521
|
|
|
2315
2522
|
export { AddObjectCommand as A, BatchCommand as B, DEFAULT_BRUSH_CONFIG as D, KritzelBrushTool as K, RemoveSelectionGroupCommand as R, KritzelTextTool as a, KritzelMouseButton as b, KritzelSelectionTool as c, KritzelEraserTool as d, DEFAULT_TEXT_CONFIG as e, KritzelImageTool as f, KritzelEventHelper as g, KritzelBaseCommand as h, KritzelSelectionGroup as i, KrtizelSelectionBox as j, RemoveObjectCommand as k, AddSelectionGroupCommand as l, KritzelToolRegistry as m, KritzelBaseHandler as n, KritzelBaseTool as o, KritzelKeyboardHelper as p, KritzelText as q, KritzelPath as r, KritzelImage as s };
|
|
2316
|
-
//# sourceMappingURL=index-
|
|
2523
|
+
//# sourceMappingURL=index-DO2IiM_o.js.map
|
|
2317
2524
|
|
|
2318
|
-
//# sourceMappingURL=index-
|
|
2525
|
+
//# sourceMappingURL=index-DO2IiM_o.js.map
|