@inweb/markup 26.4.1 → 26.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/markup.js +81 -17
- package/dist/markup.js.map +1 -1
- package/dist/markup.min.js +1 -1
- package/dist/markup.module.js +106 -19
- package/dist/markup.module.js.map +1 -1
- package/lib/markup/IMarkupEllipse.d.ts +16 -1
- package/lib/markup/IMarkupImage.d.ts +12 -4
- package/lib/markup/IMarkupRectangle.d.ts +2 -2
- package/lib/markup/Utils.d.ts +7 -0
- package/package.json +3 -3
- package/src/markup/IMarkupEllipse.ts +12 -1
- package/src/markup/IMarkupImage.ts +10 -4
- package/src/markup/IMarkupRectangle.ts +2 -2
- package/src/markup/Konva/KonvaCloud.ts +5 -2
- package/src/markup/Konva/KonvaEllipse.ts +8 -1
- package/src/markup/Konva/KonvaImage.ts +41 -0
- package/src/markup/Konva/KonvaMarkup.ts +36 -8
- package/src/markup/Konva/KonvaRectangle.ts +5 -2
- package/src/markup/Utils.ts +3 -0
package/dist/markup.js
CHANGED
|
@@ -12395,8 +12395,8 @@
|
|
|
12395
12395
|
if (!params.position)
|
|
12396
12396
|
params.position = { x: 0, y: 0 };
|
|
12397
12397
|
if (params.position2) {
|
|
12398
|
-
params.width = params.
|
|
12399
|
-
params.height = params.
|
|
12398
|
+
params.width = params.position2.x - params.position.x;
|
|
12399
|
+
params.height = params.position2.y - params.position.y;
|
|
12400
12400
|
}
|
|
12401
12401
|
else {
|
|
12402
12402
|
if (!params.width || !params.height) {
|
|
@@ -12488,6 +12488,9 @@
|
|
|
12488
12488
|
setPosition(x, y) {
|
|
12489
12489
|
this._ref.setPosition({ x, y });
|
|
12490
12490
|
this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({ x, y }));
|
|
12491
|
+
const rightLowerPoint = { x: x + this._ref.width(), y: y + this._ref.y() };
|
|
12492
|
+
const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
|
|
12493
|
+
this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
|
|
12491
12494
|
}
|
|
12492
12495
|
ref() {
|
|
12493
12496
|
return this._ref;
|
|
@@ -12542,6 +12545,10 @@
|
|
|
12542
12545
|
}
|
|
12543
12546
|
}
|
|
12544
12547
|
|
|
12548
|
+
function getDistanceIn2D(p1, p2) {
|
|
12549
|
+
return Math.sqrt(Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2));
|
|
12550
|
+
}
|
|
12551
|
+
|
|
12545
12552
|
///////////////////////////////////////////////////////////////////////////////
|
|
12546
12553
|
// Copyright (C) 2002-2025, Open Design Alliance (the "Alliance").
|
|
12547
12554
|
// All rights reserved.
|
|
@@ -12588,8 +12595,17 @@
|
|
|
12588
12595
|
params = {};
|
|
12589
12596
|
if (!params.position)
|
|
12590
12597
|
params.position = { x: 0, y: 0 };
|
|
12591
|
-
if (
|
|
12592
|
-
params.radius =
|
|
12598
|
+
if (params.position2) {
|
|
12599
|
+
params.radius.x = getDistanceIn2D(params.position, params.position2);
|
|
12600
|
+
if (params.position3)
|
|
12601
|
+
params.radius.y = getDistanceIn2D(params.position, params.position3);
|
|
12602
|
+
else
|
|
12603
|
+
params.radius.x = params.radius.y;
|
|
12604
|
+
}
|
|
12605
|
+
else {
|
|
12606
|
+
if (!params.radius)
|
|
12607
|
+
params.radius = { x: 25, y: 25 };
|
|
12608
|
+
}
|
|
12593
12609
|
this._ref = new Konva.Ellipse({
|
|
12594
12610
|
stroke: (_a = params.color) !== null && _a !== undefined ? _a : "#ff0000",
|
|
12595
12611
|
strokeWidth: (_b = params.lineWidth) !== null && _b !== undefined ? _b : 4,
|
|
@@ -12931,9 +12947,14 @@
|
|
|
12931
12947
|
? 1
|
|
12932
12948
|
: this._ref.height() / this._ref.width();
|
|
12933
12949
|
const wcsStart = this._ref.getAttr("wcsStart");
|
|
12950
|
+
const wcsEnd = this._ref.getAttr("wcsEnd");
|
|
12934
12951
|
if (!wcsStart) {
|
|
12935
12952
|
this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({ x: ref.x(), y: ref.y() }));
|
|
12936
12953
|
}
|
|
12954
|
+
if (!wcsEnd) {
|
|
12955
|
+
const rightBottomPoint = { x: ref.x() + ref.width(), y: ref.y() + ref.height() };
|
|
12956
|
+
this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({ x: rightBottomPoint.x, y: rightBottomPoint.y }));
|
|
12957
|
+
}
|
|
12937
12958
|
return;
|
|
12938
12959
|
}
|
|
12939
12960
|
if (!params)
|
|
@@ -12942,6 +12963,10 @@
|
|
|
12942
12963
|
params.position = { x: 0, y: 0 };
|
|
12943
12964
|
if (!params.src || !params.src.startsWith(this.BASE64_HEADER_START))
|
|
12944
12965
|
params.src = this.BASE64_NOT_FOUND;
|
|
12966
|
+
if (params.position2) {
|
|
12967
|
+
params.width = params.position2.x - params.position.x;
|
|
12968
|
+
params.height = params.position2.y - params.position.y;
|
|
12969
|
+
}
|
|
12945
12970
|
this._canvasImage = new Image();
|
|
12946
12971
|
this._canvasImage.onload = () => {
|
|
12947
12972
|
this._ref.image(this._canvasImage);
|
|
@@ -12967,6 +12992,11 @@
|
|
|
12967
12992
|
this._ref.width(params.maxHeight / this._ratio);
|
|
12968
12993
|
this._ref.height(params.maxHeight);
|
|
12969
12994
|
}
|
|
12995
|
+
const wcsEnd = this._worldTransformer.screenToWorld({
|
|
12996
|
+
x: params.position.x + this._ref.width(),
|
|
12997
|
+
y: params.position.y + this._ref.height(),
|
|
12998
|
+
});
|
|
12999
|
+
this._ref.setAttr("wcsEnd", wcsEnd);
|
|
12970
13000
|
}
|
|
12971
13001
|
}
|
|
12972
13002
|
};
|
|
@@ -13020,11 +13050,13 @@
|
|
|
13020
13050
|
const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
|
|
13021
13051
|
const position = absoluteTransform.point({ x: this._ref.x(), y: this._ref.y() });
|
|
13022
13052
|
this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
|
|
13053
|
+
this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({ x: position.x + this._ref.width(), y: position.y + this._ref.height() }));
|
|
13023
13054
|
});
|
|
13024
13055
|
this._ref.on("dragend", (e) => {
|
|
13025
13056
|
const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
|
|
13026
13057
|
const position = absoluteTransform.point({ x: this._ref.x(), y: this._ref.y() });
|
|
13027
13058
|
this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
|
|
13059
|
+
this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({ x: position.x + this._ref.width(), y: position.y + this._ref.height() }));
|
|
13028
13060
|
});
|
|
13029
13061
|
this._ref.id(this._ref._id.toString());
|
|
13030
13062
|
}
|
|
@@ -13040,6 +13072,9 @@
|
|
|
13040
13072
|
setWidth(w) {
|
|
13041
13073
|
this._ref.width(w);
|
|
13042
13074
|
this._ref.height(w * this._ratio);
|
|
13075
|
+
const rightLowerPoint = { x: this._ref.x() + w, y: this._ref.y() + this._ref.height() };
|
|
13076
|
+
const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
|
|
13077
|
+
this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
|
|
13043
13078
|
}
|
|
13044
13079
|
getHeight() {
|
|
13045
13080
|
return this._ref.height();
|
|
@@ -13047,6 +13082,9 @@
|
|
|
13047
13082
|
setHeight(h) {
|
|
13048
13083
|
this._ref.height(h);
|
|
13049
13084
|
this._ref.width(h / this._ratio);
|
|
13085
|
+
const rightLowerPoint = { x: this._ref.x() + this._ref.width(), y: this._ref.y() + h };
|
|
13086
|
+
const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
|
|
13087
|
+
this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
|
|
13050
13088
|
}
|
|
13051
13089
|
ref() {
|
|
13052
13090
|
return this._ref;
|
|
@@ -13082,13 +13120,20 @@
|
|
|
13082
13120
|
setPosition(x, y) {
|
|
13083
13121
|
this._ref.setPosition({ x, y });
|
|
13084
13122
|
this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({ x, y }));
|
|
13123
|
+
const rightLowerPoint = { x: x + this._ref.width(), y: y + this._ref.y() };
|
|
13124
|
+
const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
|
|
13125
|
+
this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
|
|
13085
13126
|
}
|
|
13086
13127
|
updateScreenCoordinates() {
|
|
13087
13128
|
let screenPositionStart = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart"));
|
|
13129
|
+
let screenPositionEnd = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsEnd"));
|
|
13088
13130
|
let invert = this._ref.getStage().getAbsoluteTransform().copy();
|
|
13089
13131
|
invert = invert.invert();
|
|
13090
13132
|
const positionStart = invert.point(screenPositionStart);
|
|
13133
|
+
const positionEnd = invert.point(screenPositionEnd);
|
|
13091
13134
|
this._ref.position({ x: positionStart.x, y: positionStart.y });
|
|
13135
|
+
this._ref.width(Math.abs(positionEnd.x - positionStart.x));
|
|
13136
|
+
this._ref.height(Math.abs(positionEnd.y - positionStart.y));
|
|
13092
13137
|
}
|
|
13093
13138
|
}
|
|
13094
13139
|
|
|
@@ -13136,8 +13181,8 @@
|
|
|
13136
13181
|
if (!params.position)
|
|
13137
13182
|
params.position = { x: 0, y: 0 };
|
|
13138
13183
|
if (params.position2) {
|
|
13139
|
-
params.width = params.
|
|
13140
|
-
params.height = params.
|
|
13184
|
+
params.width = params.position2.x - params.position.x;
|
|
13185
|
+
params.height = params.position2.y - params.position.y;
|
|
13141
13186
|
}
|
|
13142
13187
|
else {
|
|
13143
13188
|
if (!params.width || !params.height) {
|
|
@@ -13300,6 +13345,9 @@
|
|
|
13300
13345
|
setPosition(x, y) {
|
|
13301
13346
|
this._ref.position({ x, y });
|
|
13302
13347
|
this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({ x, y }));
|
|
13348
|
+
const rightLowerPoint = { x: x + this._ref.width(), y: y + this._ref.y() };
|
|
13349
|
+
const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
|
|
13350
|
+
this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
|
|
13303
13351
|
}
|
|
13304
13352
|
getWidth() {
|
|
13305
13353
|
return this._ref.width();
|
|
@@ -13569,11 +13617,14 @@
|
|
|
13569
13617
|
});
|
|
13570
13618
|
(_d = viewpoint.rectangles) === null || _d === undefined ? undefined : _d.forEach((rect) => {
|
|
13571
13619
|
const screenPoint = this._worldTransformer.worldToScreen(rect.position);
|
|
13572
|
-
|
|
13620
|
+
const screenPoint2 = rect.position2 ? this._worldTransformer.worldToScreen(rect.position2) : null;
|
|
13621
|
+
this.addRectangle(screenPoint, screenPoint2, rect.width, rect.height, rect.line_width, rect.color, rect.id);
|
|
13573
13622
|
});
|
|
13574
13623
|
(_e = viewpoint.ellipses) === null || _e === undefined ? undefined : _e.forEach((ellipse) => {
|
|
13575
13624
|
const screenPoint = this._worldTransformer.worldToScreen(ellipse.position);
|
|
13576
|
-
|
|
13625
|
+
const screenPoint2 = ellipse.position2 ? this._worldTransformer.worldToScreen(ellipse.position2) : null;
|
|
13626
|
+
const screenPoint3 = ellipse.position3 ? this._worldTransformer.worldToScreen(ellipse.position3) : null;
|
|
13627
|
+
this.addEllipse(screenPoint, screenPoint2, screenPoint3, ellipse.radius, ellipse.line_width, ellipse.color, ellipse.id);
|
|
13577
13628
|
});
|
|
13578
13629
|
(_f = viewpoint.arrows) === null || _f === undefined ? undefined : _f.forEach((arrow) => {
|
|
13579
13630
|
const startPoint = this._worldTransformer.worldToScreen(arrow.start);
|
|
@@ -13582,11 +13633,13 @@
|
|
|
13582
13633
|
});
|
|
13583
13634
|
(_g = viewpoint.clouds) === null || _g === undefined ? undefined : _g.forEach((cloud) => {
|
|
13584
13635
|
const screenPoint = this._worldTransformer.worldToScreen(cloud.position);
|
|
13585
|
-
|
|
13636
|
+
const screenPoint2 = cloud.position2 ? this._worldTransformer.worldToScreen(cloud.position2) : null;
|
|
13637
|
+
this.addCloud(screenPoint, screenPoint2, cloud.width, cloud.height, cloud.line_width, cloud.color, cloud.id);
|
|
13586
13638
|
});
|
|
13587
13639
|
(_h = viewpoint.images) === null || _h === undefined ? undefined : _h.forEach((image) => {
|
|
13588
13640
|
const screenPoint = this._worldTransformer.worldToScreen(image.position);
|
|
13589
|
-
|
|
13641
|
+
const screenPoint2 = image.position2 ? this._worldTransformer.worldToScreen(image.position2) : null;
|
|
13642
|
+
this.addImage(screenPoint, screenPoint2, image.src, image.width, image.height, image.id);
|
|
13590
13643
|
});
|
|
13591
13644
|
}
|
|
13592
13645
|
getViewpoint(viewpoint) {
|
|
@@ -13737,7 +13790,7 @@
|
|
|
13737
13790
|
this.addRectangle({ x: startX, y: startY }, null, dX, dY);
|
|
13738
13791
|
}
|
|
13739
13792
|
else if (this._markupMode === "Ellipse") {
|
|
13740
|
-
this.addEllipse({ x: startX, y: startY }, { x: dX / 2, y: dY / 2 });
|
|
13793
|
+
this.addEllipse({ x: startX, y: startY }, null, null, { x: dX / 2, y: dY / 2 });
|
|
13741
13794
|
}
|
|
13742
13795
|
else if (this._markupMode === "Arrow") {
|
|
13743
13796
|
this.addArrow({ x: mouseDownPos.x, y: mouseDownPos.y }, { x: defParams ? mouseDownPos.x + 200 : pos.x, y: defParams ? startY : pos.y });
|
|
@@ -13789,7 +13842,7 @@
|
|
|
13789
13842
|
lastObj.setRadiusY(dY);
|
|
13790
13843
|
}
|
|
13791
13844
|
else
|
|
13792
|
-
lastObj = this.addEllipse({ x: startX, y: startY }, { x: dX, y: dY });
|
|
13845
|
+
lastObj = this.addEllipse({ x: startX, y: startY }, null, null, { x: dX, y: dY });
|
|
13793
13846
|
}
|
|
13794
13847
|
else if (this._markupMode === "Cloud") {
|
|
13795
13848
|
if (lastObj) {
|
|
@@ -13817,7 +13870,7 @@
|
|
|
13817
13870
|
}
|
|
13818
13871
|
else if (this._markupMode === "Image") {
|
|
13819
13872
|
if (this._imageInputRef && this._imageInputRef.value)
|
|
13820
|
-
this.addImage({ x: this._imageInputPos.x, y: this._imageInputPos.y }, this._imageInputRef.value, 0, 0, this._imageInputRef.value);
|
|
13873
|
+
this.addImage({ x: this._imageInputPos.x, y: this._imageInputPos.y }, null, this._imageInputRef.value, 0, 0, this._imageInputRef.value);
|
|
13821
13874
|
else if (transformer.nodes().length === 0) {
|
|
13822
13875
|
const pos = this.getRelativePointerPosition(stage);
|
|
13823
13876
|
this.createImageInput(pos);
|
|
@@ -13841,7 +13894,7 @@
|
|
|
13841
13894
|
if (this._markupMode === "Image" || this._markupMode === "SelectMarkup") {
|
|
13842
13895
|
if (e.target.className === "Image" && transformer.nodes().length === 1 && transformer.nodes()[0] === e.target) {
|
|
13843
13896
|
if (this._imageInputRef && this._imageInputRef.value)
|
|
13844
|
-
this.addImage(this._imageInputPos, this._imageInputRef.value, 0, 0);
|
|
13897
|
+
this.addImage(this._imageInputPos, null, this._imageInputRef.value, 0, 0);
|
|
13845
13898
|
else
|
|
13846
13899
|
this.createImageInput({ x: e.target.attrs.x, y: e.target.attrs.y });
|
|
13847
13900
|
return;
|
|
@@ -13959,6 +14012,7 @@
|
|
|
13959
14012
|
const rectangle = {
|
|
13960
14013
|
id: shape.id(),
|
|
13961
14014
|
position: wcsStart,
|
|
14015
|
+
position2: wcsEnd,
|
|
13962
14016
|
width: Math.abs(screenStart.x - screenEnd.x),
|
|
13963
14017
|
height: Math.abs(screenStart.y - screenEnd.y),
|
|
13964
14018
|
line_width: shape.getLineWidth(),
|
|
@@ -13972,12 +14026,16 @@
|
|
|
13972
14026
|
const ellipses = [];
|
|
13973
14027
|
this.konvaLayerFind("Ellipse").forEach((ref) => {
|
|
13974
14028
|
const wcsPosition = ref.getAttr("wcsPosition");
|
|
14029
|
+
const wcsPosition2 = ref.getAttr("wcsRadiusX");
|
|
14030
|
+
const wcsPosition3 = ref.getAttr("wcsRadiusY");
|
|
13975
14031
|
const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
|
|
13976
14032
|
const scale = stageAbsoluteTransform.getMatrix()[0];
|
|
13977
14033
|
const shape = new KonvaEllipse(null, ref, this._worldTransformer);
|
|
13978
14034
|
const ellipse = {
|
|
13979
14035
|
id: shape.id(),
|
|
13980
14036
|
position: wcsPosition,
|
|
14037
|
+
position2: wcsPosition2,
|
|
14038
|
+
position3: wcsPosition3,
|
|
13981
14039
|
radius: {
|
|
13982
14040
|
x: ref.getRadiusX() * scale,
|
|
13983
14041
|
y: ref.getRadiusY() * scale,
|
|
@@ -14010,12 +14068,14 @@
|
|
|
14010
14068
|
const images = [];
|
|
14011
14069
|
this.konvaLayerFind("Image").forEach((ref) => {
|
|
14012
14070
|
const wcsStart = ref.getAttr("wcsStart");
|
|
14071
|
+
const wcsEnd = ref.getAttr("wcsEnd");
|
|
14013
14072
|
const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
|
|
14014
14073
|
const scale = stageAbsoluteTransform.getMatrix()[0];
|
|
14015
14074
|
const shape = new KonvaImage(null, ref, this._worldTransformer);
|
|
14016
14075
|
const image = {
|
|
14017
14076
|
id: shape.id(),
|
|
14018
14077
|
position: wcsStart,
|
|
14078
|
+
position2: wcsEnd,
|
|
14019
14079
|
src: shape.getSrc(),
|
|
14020
14080
|
width: shape.getWidth() * scale,
|
|
14021
14081
|
height: shape.getHeight() * scale,
|
|
@@ -14035,6 +14095,7 @@
|
|
|
14035
14095
|
const cloud = {
|
|
14036
14096
|
id: shape.id(),
|
|
14037
14097
|
position: wcsStart,
|
|
14098
|
+
position2: wcsEnd,
|
|
14038
14099
|
width: Math.abs(screenStart.x - screenEnd.x),
|
|
14039
14100
|
height: Math.abs(screenStart.y - screenEnd.y),
|
|
14040
14101
|
line_width: shape.getLineWidth(),
|
|
@@ -14137,7 +14198,7 @@
|
|
|
14137
14198
|
this._imageInputRef.onchange = async (event) => {
|
|
14138
14199
|
const file = event.target.files[0];
|
|
14139
14200
|
const base64 = await convertBase64(file);
|
|
14140
|
-
this.addImage({ x: this._imageInputPos.x, y: this._imageInputPos.y }, base64.toString(), 0, 0);
|
|
14201
|
+
this.addImage({ x: this._imageInputPos.x, y: this._imageInputPos.y }, null, base64.toString(), 0, 0);
|
|
14141
14202
|
};
|
|
14142
14203
|
this._imageInputRef.oncancel = (event) => {
|
|
14143
14204
|
this.removeImageInput();
|
|
@@ -14198,11 +14259,13 @@
|
|
|
14198
14259
|
this.addObject(konvaRectangle);
|
|
14199
14260
|
return konvaRectangle;
|
|
14200
14261
|
}
|
|
14201
|
-
addEllipse(position, radius, lineWidth, color, id) {
|
|
14262
|
+
addEllipse(position, position2, position3, radius, lineWidth, color, id) {
|
|
14202
14263
|
if (!position)
|
|
14203
14264
|
return;
|
|
14204
14265
|
const konvaEllipse = new KonvaEllipse({
|
|
14205
14266
|
position,
|
|
14267
|
+
position2,
|
|
14268
|
+
position3,
|
|
14206
14269
|
radius,
|
|
14207
14270
|
lineWidth,
|
|
14208
14271
|
color: color || this._markupColor.asHex(),
|
|
@@ -14238,7 +14301,7 @@
|
|
|
14238
14301
|
this.addObject(konvaCloud);
|
|
14239
14302
|
return konvaCloud;
|
|
14240
14303
|
}
|
|
14241
|
-
addImage(position, src, width, height, id) {
|
|
14304
|
+
addImage(position, position2, src, width, height, id) {
|
|
14242
14305
|
var _a;
|
|
14243
14306
|
if (!position || !src)
|
|
14244
14307
|
return;
|
|
@@ -14248,6 +14311,7 @@
|
|
|
14248
14311
|
this.removeImageInput();
|
|
14249
14312
|
const konvaImage = new KonvaImage({
|
|
14250
14313
|
position,
|
|
14314
|
+
position2,
|
|
14251
14315
|
src,
|
|
14252
14316
|
width,
|
|
14253
14317
|
height,
|