@inweb/markup 25.7.10 → 25.8.1
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/markup.js +90 -122
- package/dist/markup.js.map +1 -1
- package/dist/markup.min.js +1 -1
- package/dist/markup.module.js +74 -136
- package/dist/markup.module.js.map +1 -1
- package/lib/markup/Konva/KonvaMarkup.d.ts +1 -2
- package/lib/markup/WorldTransform.d.ts +23 -0
- package/package.json +3 -3
- package/src/markup/Konva/KonvaMarkup.ts +55 -137
- package/src/markup/WorldTransform.ts +36 -0
package/dist/markup.js
CHANGED
|
@@ -11525,6 +11525,40 @@
|
|
|
11525
11525
|
}
|
|
11526
11526
|
}
|
|
11527
11527
|
|
|
11528
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
11529
|
+
// Copyright (C) 2002-2024, Open Design Alliance (the "Alliance").
|
|
11530
|
+
// All rights reserved.
|
|
11531
|
+
//
|
|
11532
|
+
// This software and its documentation and related materials are owned by
|
|
11533
|
+
// the Alliance. The software may only be incorporated into application
|
|
11534
|
+
// programs owned by members of the Alliance, subject to a signed
|
|
11535
|
+
// Membership Agreement and Supplemental Software License Agreement with the
|
|
11536
|
+
// Alliance. The structure and organization of this software are the valuable
|
|
11537
|
+
// trade secrets of the Alliance and its suppliers. The software is also
|
|
11538
|
+
// protected by copyright law and international treaty provisions. Application
|
|
11539
|
+
// programs incorporating this software must include the following statement
|
|
11540
|
+
// with their copyright notices:
|
|
11541
|
+
//
|
|
11542
|
+
// This application incorporates Open Design Alliance software pursuant to a
|
|
11543
|
+
// license agreement with Open Design Alliance.
|
|
11544
|
+
// Open Design Alliance Copyright (C) 2002-2024 by Open Design Alliance.
|
|
11545
|
+
// All rights reserved.
|
|
11546
|
+
//
|
|
11547
|
+
// By use of this software, its documentation or related materials, you
|
|
11548
|
+
// acknowledge and accept the above terms.
|
|
11549
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
11550
|
+
class WorldTransform {
|
|
11551
|
+
screenToWorld(position) {
|
|
11552
|
+
return { x: position.x, y: position.y, z: 0 };
|
|
11553
|
+
}
|
|
11554
|
+
worldToScreen(position) {
|
|
11555
|
+
return { x: position.x, y: position.y };
|
|
11556
|
+
}
|
|
11557
|
+
getScale() {
|
|
11558
|
+
return { x: 1, y: 1, z: 1 };
|
|
11559
|
+
}
|
|
11560
|
+
}
|
|
11561
|
+
|
|
11528
11562
|
const LineTypeSpecs = new Map([
|
|
11529
11563
|
["solid", []],
|
|
11530
11564
|
["dot", [30, 30, 0.001, 30]],
|
|
@@ -12347,31 +12381,37 @@
|
|
|
12347
12381
|
},
|
|
12348
12382
|
Line: {
|
|
12349
12383
|
name: "Line",
|
|
12350
|
-
initializer: (ref) => new KonvaLine(
|
|
12384
|
+
initializer: (ref, params = null) => new KonvaLine(params, ref),
|
|
12385
|
+
zIndex: 1,
|
|
12351
12386
|
},
|
|
12352
12387
|
Text: {
|
|
12353
12388
|
name: "Text",
|
|
12354
|
-
initializer: (ref) => new KonvaText(
|
|
12389
|
+
initializer: (ref, params = null) => new KonvaText(params, ref),
|
|
12355
12390
|
},
|
|
12356
12391
|
Rectangle: {
|
|
12357
12392
|
name: "Rect",
|
|
12358
|
-
initializer: (ref) => new KonvaRectangle(
|
|
12393
|
+
initializer: (ref, params = null) => new KonvaRectangle(params, ref),
|
|
12394
|
+
zIndex: 1,
|
|
12359
12395
|
},
|
|
12360
12396
|
Ellipse: {
|
|
12361
12397
|
name: "Ellipse",
|
|
12362
|
-
initializer: (ref) => new KonvaEllipse(
|
|
12398
|
+
initializer: (ref, params = null) => new KonvaEllipse(params, ref),
|
|
12399
|
+
zIndex: 1,
|
|
12363
12400
|
},
|
|
12364
12401
|
Arrow: {
|
|
12365
12402
|
name: "Arrow",
|
|
12366
|
-
initializer: (ref) => new KonvaArrow(
|
|
12403
|
+
initializer: (ref, params = null) => new KonvaArrow(params, ref),
|
|
12404
|
+
zIndex: 1,
|
|
12367
12405
|
},
|
|
12368
12406
|
Image: {
|
|
12369
12407
|
name: "Image",
|
|
12370
|
-
initializer: (ref) => new KonvaImage(
|
|
12408
|
+
initializer: (ref, params = null) => new KonvaImage(params, ref),
|
|
12409
|
+
zIndex: 0,
|
|
12371
12410
|
},
|
|
12372
12411
|
Cloud: {
|
|
12373
12412
|
name: "Cloud",
|
|
12374
12413
|
initializer: (ref) => new KonvaCloud(null, ref),
|
|
12414
|
+
zIndex: 1,
|
|
12375
12415
|
},
|
|
12376
12416
|
};
|
|
12377
12417
|
/**
|
|
@@ -12410,7 +12450,7 @@
|
|
|
12410
12450
|
this.pan = (event) => {
|
|
12411
12451
|
const dX = event.dX / window.devicePixelRatio;
|
|
12412
12452
|
const dY = event.dY / window.devicePixelRatio;
|
|
12413
|
-
|
|
12453
|
+
this.getObjects().forEach((obj) => obj.ref().move({ x: dX, y: dY }));
|
|
12414
12454
|
};
|
|
12415
12455
|
this.redirectToViewer = (event) => {
|
|
12416
12456
|
if (this._viewer)
|
|
@@ -12421,7 +12461,7 @@
|
|
|
12421
12461
|
if (!Konva)
|
|
12422
12462
|
throw new Error('Markup: Error during initialization. Konva is not initialized. Update node_modules or add to your page <script src="https://unpkg.com/konva@9/konva.min.js"></script>');
|
|
12423
12463
|
this._viewer = viewer;
|
|
12424
|
-
this._worldTransformer = worldTransformer;
|
|
12464
|
+
this._worldTransformer = worldTransformer !== null && worldTransformer !== void 0 ? worldTransformer : new WorldTransform();
|
|
12425
12465
|
this._container = container;
|
|
12426
12466
|
this._pointerEvents = pointerEvents !== null && pointerEvents !== void 0 ? pointerEvents : [];
|
|
12427
12467
|
this._markupContainer = document.createElement("div");
|
|
@@ -12467,8 +12507,8 @@
|
|
|
12467
12507
|
clearOverlay() {
|
|
12468
12508
|
this.removeTextInput();
|
|
12469
12509
|
this.removeImageInput();
|
|
12470
|
-
this.
|
|
12471
|
-
|
|
12510
|
+
this.clearSelected();
|
|
12511
|
+
this.getObjects().forEach((obj) => obj.ref().destroy());
|
|
12472
12512
|
}
|
|
12473
12513
|
getMarkupColor() {
|
|
12474
12514
|
return this._markupColor.RGB;
|
|
@@ -12476,24 +12516,21 @@
|
|
|
12476
12516
|
setMarkupColor(r, g, b) {
|
|
12477
12517
|
this._markupColor.setColor(r, g, b);
|
|
12478
12518
|
}
|
|
12479
|
-
colorizeAllMarkup(r
|
|
12480
|
-
const
|
|
12481
|
-
|
|
12482
|
-
|
|
12483
|
-
|
|
12484
|
-
|
|
12485
|
-
if (konvaObj.setColor)
|
|
12486
|
-
konvaObj.setColor(hex);
|
|
12487
|
-
});
|
|
12519
|
+
colorizeAllMarkup(r, g, b) {
|
|
12520
|
+
const hexColor = new MarkupColor(r, g, b).HexColor;
|
|
12521
|
+
this.getObjects().forEach((obj) => {
|
|
12522
|
+
const colorable = obj;
|
|
12523
|
+
if (colorable && colorable.setColor)
|
|
12524
|
+
colorable.setColor(hexColor);
|
|
12488
12525
|
});
|
|
12489
12526
|
this._konvaLayer.draw();
|
|
12490
12527
|
}
|
|
12491
12528
|
colorizeSelectedMarkups(r, g, b) {
|
|
12529
|
+
const hexColor = new MarkupColor(r, g, b).HexColor;
|
|
12492
12530
|
this.getSelectedObjects().forEach((obj) => {
|
|
12493
12531
|
const colorable = obj;
|
|
12494
|
-
if (colorable && colorable.setColor)
|
|
12495
|
-
colorable.setColor(
|
|
12496
|
-
}
|
|
12532
|
+
if (colorable && colorable.setColor)
|
|
12533
|
+
colorable.setColor(hexColor);
|
|
12497
12534
|
});
|
|
12498
12535
|
}
|
|
12499
12536
|
setViewpoint(viewpoint) {
|
|
@@ -12533,99 +12570,35 @@
|
|
|
12533
12570
|
return this;
|
|
12534
12571
|
}
|
|
12535
12572
|
createObject(type, params) {
|
|
12536
|
-
|
|
12537
|
-
|
|
12538
|
-
|
|
12539
|
-
|
|
12540
|
-
|
|
12541
|
-
object = new KonvaLine(params);
|
|
12542
|
-
zIndex = 1;
|
|
12543
|
-
break;
|
|
12544
|
-
case "text":
|
|
12545
|
-
object = new KonvaText(params);
|
|
12546
|
-
break;
|
|
12547
|
-
case "rectangle":
|
|
12548
|
-
object = new KonvaRectangle(params);
|
|
12549
|
-
zIndex = 1;
|
|
12550
|
-
break;
|
|
12551
|
-
case "ellipse":
|
|
12552
|
-
object = new KonvaEllipse(params);
|
|
12553
|
-
zIndex = 1;
|
|
12554
|
-
break;
|
|
12555
|
-
case "arrow":
|
|
12556
|
-
object = new KonvaArrow(params);
|
|
12557
|
-
break;
|
|
12558
|
-
case "image":
|
|
12559
|
-
object = new KonvaImage(params);
|
|
12560
|
-
zIndex = 0;
|
|
12561
|
-
break;
|
|
12562
|
-
case "cloud":
|
|
12563
|
-
object = new KonvaCloud(params);
|
|
12564
|
-
zIndex = 1;
|
|
12565
|
-
break;
|
|
12566
|
-
default:
|
|
12567
|
-
throw new Error("Markup CreateObject - unsupported type has been detected.");
|
|
12568
|
-
}
|
|
12573
|
+
var _a;
|
|
12574
|
+
const konvaShape = MarkupMode2Konva[type];
|
|
12575
|
+
if (!konvaShape || !konvaShape.initializer)
|
|
12576
|
+
throw new Error(`Markup CreateObject - unsupported markup type ${type}`);
|
|
12577
|
+
const object = konvaShape.initializer(null, params);
|
|
12569
12578
|
this.addObject(object);
|
|
12570
|
-
// Set zIndex only when shape has been added to Layer else we will get
|
|
12571
|
-
|
|
12579
|
+
// Set zIndex only when shape has been added to Layer else we will get
|
|
12580
|
+
// "Konva warning: Node has no parent. zIndex parameter is ignored."
|
|
12581
|
+
object.setZIndex((_a = konvaShape.zIndex) !== null && _a !== void 0 ? _a : this._zIndex);
|
|
12572
12582
|
this._zIndex++;
|
|
12573
12583
|
return object;
|
|
12574
12584
|
}
|
|
12575
12585
|
getObjects() {
|
|
12576
12586
|
const objects = [];
|
|
12577
|
-
|
|
12578
|
-
|
|
12579
|
-
|
|
12580
|
-
this.konvaLayerFind("Text").forEach((text) => {
|
|
12581
|
-
objects.push(new KonvaText(null, text));
|
|
12582
|
-
});
|
|
12583
|
-
this.konvaLayerFind("Rectangle").forEach((rectangle) => {
|
|
12584
|
-
objects.push(new KonvaRectangle(null, rectangle));
|
|
12585
|
-
});
|
|
12586
|
-
this.konvaLayerFind("Ellipse").forEach((ellipse) => {
|
|
12587
|
-
objects.push(new KonvaEllipse(null, ellipse));
|
|
12588
|
-
});
|
|
12589
|
-
this.konvaLayerFind("Arrow").forEach((arrow) => {
|
|
12590
|
-
objects.push(new KonvaArrow(null, arrow));
|
|
12591
|
-
});
|
|
12592
|
-
this.konvaLayerFind("Image").forEach((image) => {
|
|
12593
|
-
objects.push(new KonvaImage(null, image));
|
|
12594
|
-
});
|
|
12595
|
-
this.konvaLayerFind("Cloud").forEach((cloud) => {
|
|
12596
|
-
objects.push(new KonvaCloud(null, cloud));
|
|
12587
|
+
Object.keys(MarkupMode2Konva).forEach((type) => {
|
|
12588
|
+
const konvaShape = MarkupMode2Konva[type];
|
|
12589
|
+
this.konvaLayerFind(type).forEach((ref) => objects.push(konvaShape.initializer(ref)));
|
|
12597
12590
|
});
|
|
12598
12591
|
return objects;
|
|
12599
12592
|
}
|
|
12600
12593
|
getSelectedObjects() {
|
|
12601
|
-
|
|
12602
|
-
|
|
12603
|
-
|
|
12604
|
-
|
|
12605
|
-
|
|
12606
|
-
|
|
12607
|
-
|
|
12608
|
-
|
|
12609
|
-
objects.push(new KonvaText(null, obj));
|
|
12610
|
-
break;
|
|
12611
|
-
case "Rect":
|
|
12612
|
-
objects.push(new KonvaRectangle(null, obj));
|
|
12613
|
-
break;
|
|
12614
|
-
case "Ellipse":
|
|
12615
|
-
objects.push(new KonvaEllipse(null, obj));
|
|
12616
|
-
break;
|
|
12617
|
-
case "Arrow":
|
|
12618
|
-
objects.push(new KonvaArrow(null, obj));
|
|
12619
|
-
break;
|
|
12620
|
-
case "Image":
|
|
12621
|
-
objects.push(new KonvaImage(null, obj));
|
|
12622
|
-
break;
|
|
12623
|
-
case "Cloud":
|
|
12624
|
-
objects.push(new KonvaCloud(null, obj));
|
|
12625
|
-
break;
|
|
12626
|
-
}
|
|
12627
|
-
});
|
|
12628
|
-
return objects;
|
|
12594
|
+
return this._konvaTransformer
|
|
12595
|
+
.nodes()
|
|
12596
|
+
.map((ref) => {
|
|
12597
|
+
const name = ref.className;
|
|
12598
|
+
const konvaShape = Object.values(MarkupMode2Konva).find((shape) => shape.name === name);
|
|
12599
|
+
return konvaShape ? konvaShape.initializer(ref) : null;
|
|
12600
|
+
})
|
|
12601
|
+
.filter((x) => x);
|
|
12629
12602
|
}
|
|
12630
12603
|
selectObjects(objects) {
|
|
12631
12604
|
const selectedObjs = this._konvaTransformer.nodes().concat(objects.map((x) => x.ref()));
|
|
@@ -12634,9 +12607,6 @@
|
|
|
12634
12607
|
clearSelected() {
|
|
12635
12608
|
this._konvaTransformer.nodes([]);
|
|
12636
12609
|
}
|
|
12637
|
-
getPoint3dFromArray(array) {
|
|
12638
|
-
return { x: array[0], y: array[1], z: array[2] };
|
|
12639
|
-
}
|
|
12640
12610
|
fillViewpointShapes(viewpoint) {
|
|
12641
12611
|
const markupLines = this.getMarkupLines();
|
|
12642
12612
|
if (markupLines && markupLines.length > 0) {
|
|
@@ -12684,8 +12654,8 @@
|
|
|
12684
12654
|
addObject(object) {
|
|
12685
12655
|
this._konvaLayer.add(object.ref());
|
|
12686
12656
|
}
|
|
12687
|
-
konvaLayerFind(
|
|
12688
|
-
const konvaShape = MarkupMode2Konva[
|
|
12657
|
+
konvaLayerFind(type) {
|
|
12658
|
+
const konvaShape = MarkupMode2Konva[type];
|
|
12689
12659
|
if (konvaShape && konvaShape.initializer) {
|
|
12690
12660
|
// for "draggable" Konva uses Rectangles in Transformer. We need only Shapes from layer.
|
|
12691
12661
|
return this._konvaLayer.find(konvaShape.name).filter((ref) => ref.parent === this._konvaLayer);
|
|
@@ -12931,7 +12901,7 @@
|
|
|
12931
12901
|
const konvaLine = new KonvaLine(null, line);
|
|
12932
12902
|
lines.push({
|
|
12933
12903
|
id: konvaLine.id(),
|
|
12934
|
-
points: worldPoints
|
|
12904
|
+
points: worldPoints,
|
|
12935
12905
|
color: konvaLine.getColor() || "#ff0000",
|
|
12936
12906
|
type: konvaLine.getLineType() || this.lineType,
|
|
12937
12907
|
width: konvaLine.getLineWidth() || this.lineWidth,
|
|
@@ -12946,14 +12916,12 @@
|
|
|
12946
12916
|
this.konvaLayerFind("Text").forEach((text) => {
|
|
12947
12917
|
if (!text)
|
|
12948
12918
|
return;
|
|
12949
|
-
const position =
|
|
12950
|
-
|
|
12951
|
-
y: text.y(),
|
|
12952
|
-
});
|
|
12919
|
+
const position = { x: text.x(), y: text.y() };
|
|
12920
|
+
const worldPoint = this._worldTransformer.screenToWorld(position);
|
|
12953
12921
|
const shape = new KonvaText(null, text);
|
|
12954
12922
|
texts.push({
|
|
12955
12923
|
id: shape.id(),
|
|
12956
|
-
position:
|
|
12924
|
+
position: worldPoint,
|
|
12957
12925
|
text: shape.getText(),
|
|
12958
12926
|
text_size: textSize * textScale.y,
|
|
12959
12927
|
angle: shape.getRotation(),
|
|
@@ -12971,7 +12939,7 @@
|
|
|
12971
12939
|
const shape = new KonvaRectangle(null, rect);
|
|
12972
12940
|
rectangles.push({
|
|
12973
12941
|
id: shape.id(),
|
|
12974
|
-
position:
|
|
12942
|
+
position: worldPoint,
|
|
12975
12943
|
width: shape.getWidth(),
|
|
12976
12944
|
height: shape.getHeigth(),
|
|
12977
12945
|
line_width: shape.getLineWidth(),
|
|
@@ -12988,7 +12956,7 @@
|
|
|
12988
12956
|
const shape = new KonvaEllipse(null, ellipse);
|
|
12989
12957
|
ellipses.push({
|
|
12990
12958
|
id: shape.id(),
|
|
12991
|
-
position:
|
|
12959
|
+
position: worldPoint,
|
|
12992
12960
|
radius: { x: ellipse.getRadiusX(), y: ellipse.getRadiusY() },
|
|
12993
12961
|
line_width: shape.getLineWidth(),
|
|
12994
12962
|
color: shape.getColor(),
|
|
@@ -13008,8 +12976,8 @@
|
|
|
13008
12976
|
const shape = new KonvaArrow(null, arrow);
|
|
13009
12977
|
arrows.push({
|
|
13010
12978
|
id: shape.id(),
|
|
13011
|
-
start:
|
|
13012
|
-
end:
|
|
12979
|
+
start: worldStartPoint,
|
|
12980
|
+
end: worldEndPoint,
|
|
13013
12981
|
color: shape.getColor(),
|
|
13014
12982
|
});
|
|
13015
12983
|
});
|
|
@@ -13023,7 +12991,7 @@
|
|
|
13023
12991
|
const shape = new KonvaImage(null, image);
|
|
13024
12992
|
images.push({
|
|
13025
12993
|
id: shape.id(),
|
|
13026
|
-
position:
|
|
12994
|
+
position: worldPoint,
|
|
13027
12995
|
src: shape.getSrc(),
|
|
13028
12996
|
width: shape.getWidth(),
|
|
13029
12997
|
height: shape.getHeight(),
|
|
@@ -13039,7 +13007,7 @@
|
|
|
13039
13007
|
const shape = new KonvaCloud(null, cloud);
|
|
13040
13008
|
clouds.push({
|
|
13041
13009
|
id: shape.id(),
|
|
13042
|
-
position:
|
|
13010
|
+
position: worldPoint,
|
|
13043
13011
|
width: shape.getWidth(),
|
|
13044
13012
|
height: shape.getHeigth(),
|
|
13045
13013
|
line_width: shape.getLineWidth(),
|