@inweb/viewer-visualize 25.3.21 → 25.3.23

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.
@@ -3509,6 +3509,8 @@ class KonvaImage {
3509
3509
  });
3510
3510
  this._canvasImage.onload = () => {
3511
3511
  this._ref.image(this._canvasImage);
3512
+ if (this._ref.height() === 0) this._ref.height(this._canvasImage.height);
3513
+ if (this._ref.width() === 0) this._ref.width(this._canvasImage.width);
3512
3514
  this._ratio = this._ref.height() === 0 || this._ref.width() === 0 ? 1 : this._ref.height() / this._ref.width();
3513
3515
  };
3514
3516
  this._canvasImage.src = params.src;
@@ -3781,6 +3783,7 @@ class KonvaMarkup {
3781
3783
  const draggerName = event.data;
3782
3784
  this._markupContainer.className = this._canvasOriginal.className.split(" ").filter((x => !x.startsWith("oda-cursor-"))).filter((x => x)).concat(`oda-cursor-${draggerName.toLowerCase()}`).join(" ");
3783
3785
  this.removeTextInput();
3786
+ this.removeImageInput();
3784
3787
  const markupMode = MarkupMode[draggerName];
3785
3788
  const konvaMode = MarkupMode2Konva.get(markupMode);
3786
3789
  if (konvaMode) {
@@ -3849,6 +3852,7 @@ class KonvaMarkup {
3849
3852
  }
3850
3853
  clearOverlay() {
3851
3854
  this.removeTextInput();
3855
+ this.removeImageInput();
3852
3856
  this._konvaTransformer.nodes([]);
3853
3857
  Object.values(MarkupMode).forEach((mode => this.konvaLayerFind(mode).forEach((x => x.destroy()))));
3854
3858
  }
@@ -3868,6 +3872,14 @@ class KonvaMarkup {
3868
3872
  }));
3869
3873
  this._konvaLayer.draw();
3870
3874
  }
3875
+ colorizeSelectedMarkups(r, g, b) {
3876
+ this.getSelectedObjects().forEach((obj => {
3877
+ const colorable = obj;
3878
+ if (colorable && colorable.setColor) {
3879
+ colorable.setColor(new MarkupColor(r, g, b).HexColor);
3880
+ }
3881
+ }));
3882
+ }
3871
3883
  setViewpoint(viewpoint) {
3872
3884
  const markupColor = viewpoint.custom_fields.markup_color || {
3873
3885
  r: 255,
@@ -4091,46 +4103,61 @@ class KonvaMarkup {
4091
4103
  layer.add(transformer);
4092
4104
  let isPaint = false;
4093
4105
  let lastLine;
4106
+ let mouseDownPos;
4107
+ let lastObj;
4094
4108
  stage.on("mousedown touchstart", (e => {
4095
- if (!this._markupIsActive || e.target !== stage || this._markupMode === MarkupMode.Text) return;
4109
+ if (!this._markupIsActive || e.target !== stage || this._markupMode === MarkupMode.Text || this._markupMode === MarkupMode.Image) return;
4096
4110
  if (e.target === stage && transformer.nodes().length > 0) {
4097
4111
  transformer.nodes([]);
4098
4112
  return;
4099
4113
  }
4100
4114
  const pos = stage.getPointerPosition();
4115
+ mouseDownPos = pos;
4116
+ isPaint = [ MarkupMode.Arrow, MarkupMode.Cloud, MarkupMode.Ellipse, MarkupMode.Line, MarkupMode.Rectangle ].some((m => m === this._markupMode));
4101
4117
  if (this._markupMode === MarkupMode.Line) {
4102
4118
  lastLine = this.addLine([ pos.x, pos.y, pos.x, pos.y ]);
4103
- isPaint = true;
4104
- } else if (this._markupMode === MarkupMode.Rectangle) {
4105
- this.addRectangle({
4106
- x: pos.x,
4107
- y: pos.y
4108
- }, 50, 50);
4109
- } else if (this._markupMode === MarkupMode.Ellipse) {
4110
- this.addEllipse({
4111
- x: pos.x,
4112
- y: pos.y
4113
- }, {
4114
- x: 50,
4115
- y: 50
4116
- });
4117
- } else if (this._markupMode === MarkupMode.Arrow) {
4118
- this.addArrow({
4119
- x: pos.x,
4120
- y: pos.y
4121
- }, {
4122
- x: pos.x + 50,
4123
- y: pos.y + 50
4124
- });
4125
- } else if (this._markupMode === MarkupMode.Cloud) {
4126
- this.addCloud({
4127
- x: pos.x,
4128
- y: pos.y
4129
- }, 200, 400);
4130
4119
  }
4131
4120
  }));
4132
4121
  stage.on("mouseup touchend", (e => {
4133
4122
  if (!this._markupIsActive) return;
4123
+ if (isPaint) {
4124
+ const pos = stage.getPointerPosition();
4125
+ const defParams = mouseDownPos && pos.x === mouseDownPos.x && pos.y === mouseDownPos.y;
4126
+ const startX = defParams ? mouseDownPos.x : Math.min(mouseDownPos.x, pos.x);
4127
+ const startY = defParams ? mouseDownPos.y : Math.min(mouseDownPos.y, pos.y);
4128
+ const dX = defParams ? 200 : Math.abs(mouseDownPos.x - pos.x);
4129
+ const dY = defParams ? 200 : Math.abs(mouseDownPos.y - pos.y);
4130
+ if (defParams) {
4131
+ if (this._markupMode === MarkupMode.Rectangle) {
4132
+ this.addRectangle({
4133
+ x: startX,
4134
+ y: startY
4135
+ }, dX, dY);
4136
+ } else if (this._markupMode === MarkupMode.Ellipse) {
4137
+ this.addEllipse({
4138
+ x: startX,
4139
+ y: startY
4140
+ }, {
4141
+ x: dX / 2,
4142
+ y: dY / 2
4143
+ });
4144
+ } else if (this._markupMode === MarkupMode.Arrow) {
4145
+ this.addArrow({
4146
+ x: mouseDownPos.x,
4147
+ y: mouseDownPos.y
4148
+ }, {
4149
+ x: defParams ? mouseDownPos.x + 200 : pos.x,
4150
+ y: defParams ? startY : pos.y
4151
+ });
4152
+ } else if (this._markupMode === MarkupMode.Cloud) {
4153
+ this.addCloud({
4154
+ x: startX,
4155
+ y: startY
4156
+ }, Math.max(100, dX), Math.max(100, dY));
4157
+ }
4158
+ }
4159
+ }
4160
+ lastObj = undefined;
4134
4161
  isPaint = false;
4135
4162
  }));
4136
4163
  stage.on("mousemove touchmove", (e => {
@@ -4139,23 +4166,78 @@ class KonvaMarkup {
4139
4166
  return;
4140
4167
  }
4141
4168
  const pos = stage.getPointerPosition();
4142
- const newPoints = lastLine.points().concat([ pos.x, pos.y ]);
4143
- lastLine.points(newPoints);
4169
+ const defParams = mouseDownPos && pos.x === mouseDownPos.x && pos.y === mouseDownPos.y;
4170
+ const startX = defParams ? mouseDownPos.x : Math.min(mouseDownPos.x, pos.x);
4171
+ const startY = defParams ? mouseDownPos.y : Math.min(mouseDownPos.y, pos.y);
4172
+ const dX = defParams ? 200 : Math.abs(mouseDownPos.x - pos.x);
4173
+ const dY = defParams ? 200 : Math.abs(mouseDownPos.y - pos.y);
4174
+ if (this._markupMode === MarkupMode.Line) {
4175
+ lastLine.addPoints([ {
4176
+ x: pos.x,
4177
+ y: pos.y
4178
+ } ]);
4179
+ } else if (this._markupMode === MarkupMode.Arrow) {
4180
+ if (lastObj) lastObj.setEndPoint(pos.x, pos.y); else lastObj = this.addArrow({
4181
+ x: mouseDownPos.x,
4182
+ y: mouseDownPos.y
4183
+ }, {
4184
+ x: pos.x,
4185
+ y: pos.y
4186
+ });
4187
+ } else if (this._markupMode === MarkupMode.Rectangle) {
4188
+ if (lastObj) {
4189
+ lastObj.setPosition(startX, startY);
4190
+ lastObj.setWidth(dX);
4191
+ lastObj.setHeight(dY);
4192
+ } else lastObj = this.addRectangle({
4193
+ x: startX,
4194
+ y: startY
4195
+ }, dX, dY);
4196
+ } else if (this._markupMode === MarkupMode.Ellipse) {
4197
+ if (lastObj) {
4198
+ lastObj.setPosition(startX, startY);
4199
+ lastObj.setRadiusX(dX);
4200
+ lastObj.setRadiusY(dY);
4201
+ } else lastObj = this.addEllipse({
4202
+ x: startX,
4203
+ y: startY
4204
+ }, {
4205
+ x: dX,
4206
+ y: dY
4207
+ });
4208
+ } else if (this._markupMode === MarkupMode.Cloud) {
4209
+ if (lastObj) {
4210
+ lastObj.setPosition(startX, startY);
4211
+ lastObj.setWidth(Math.max(100, dX));
4212
+ lastObj.setHeight(Math.max(100, dY));
4213
+ } else lastObj = this.addCloud({
4214
+ x: startX,
4215
+ y: startY
4216
+ }, dX, dY);
4217
+ }
4144
4218
  }));
4145
4219
  stage.on("click tap", (e => {
4146
4220
  if (!this._markupIsActive) return;
4147
4221
  if (e.target === stage) {
4148
4222
  if (this._markupMode === MarkupMode.Text) {
4149
- if (this._textInputRef) this.addText(this._textInputRef.value, this._textInputPos, this._textInputAngle); else if (transformer.nodes().length === 0) {
4223
+ if (this._textInputRef && this._textInputRef.value) this.addText(this._textInputRef.value, this._textInputPos, this._textInputAngle); else if (transformer.nodes().length === 0) {
4150
4224
  const pos = stage.getPointerPosition();
4151
4225
  this.createTextInput(pos, e.evt.pageX, e.evt.pageY, 0, null);
4152
4226
  }
4227
+ } else if (this._markupMode === MarkupMode.Image) {
4228
+ if (this._imageInputRef && this._imageInputRef.value) this.addImage({
4229
+ x: this._imageInputPos.x,
4230
+ y: this._imageInputPos.y
4231
+ }, this._imageInputRef.value, 0, 0, this._imageInputRef.value); else if (transformer.nodes().length === 0) {
4232
+ const pos = stage.getPointerPosition();
4233
+ this.createImageInput(pos);
4234
+ }
4153
4235
  }
4154
4236
  transformer.nodes([]);
4155
4237
  return;
4156
4238
  }
4157
4239
  if (e.target.className === "Text" && transformer.nodes().length === 1 && transformer.nodes()[0] === e.target) {
4158
- if (this._textInputRef) this.addText(this._textInputRef.value, this._textInputPos, this._textInputAngle); else this.createTextInput({
4240
+ if (this._textInputRef && this._textInputRef.value) this.addText(this._textInputRef.value, this._textInputPos, this._textInputAngle); else this.createTextInput({
4159
4241
  x: e.target.attrs.x,
4160
4242
  y: e.target.attrs.y
4161
4243
  }, e.evt.pageX, e.evt.pageY, e.target.attrs.rotation, e.target.attrs.text);
@@ -4163,6 +4245,15 @@ class KonvaMarkup {
4163
4245
  } else {
4164
4246
  this.removeTextInput();
4165
4247
  }
4248
+ if (e.target.className === "Image" && transformer.nodes().length === 1 && transformer.nodes()[0] === e.target) {
4249
+ if (this._imageInputRef && this._imageInputRef.value) this.addImage(this._imageInputPos, this._imageInputRef.value, 0, 0); else this.createImageInput({
4250
+ x: e.target.attrs.x,
4251
+ y: e.target.attrs.y
4252
+ });
4253
+ return;
4254
+ } else {
4255
+ this.removeImageInput();
4256
+ }
4166
4257
  if (transformer.nodes().filter((x => x.className === "Cloud")).length > 0 || e.target.className === "Cloud") {
4167
4258
  transformer.rotateEnabled(false);
4168
4259
  } else {
@@ -4441,7 +4532,7 @@ class KonvaMarkup {
4441
4532
  });
4442
4533
  const obj = konvaLine.ref();
4443
4534
  this._konvaLayer.add(obj);
4444
- return obj;
4535
+ return konvaLine;
4445
4536
  }
4446
4537
  createTextInput(pos, inputX, inputY, angle, text) {
4447
4538
  if (!this._textInputRef) {
@@ -4479,6 +4570,48 @@ class KonvaMarkup {
4479
4570
  this._textInputPos = null;
4480
4571
  this._textInputAngle = 0;
4481
4572
  }
4573
+ createImageInput(pos) {
4574
+ if (!this._imageInputRef) {
4575
+ const convertBase64 = file => new Promise(((resolve, reject) => {
4576
+ const fileReader = new FileReader;
4577
+ fileReader.readAsDataURL(file);
4578
+ fileReader.onload = () => {
4579
+ resolve(fileReader.result);
4580
+ };
4581
+ fileReader.onerror = error => {
4582
+ reject(error);
4583
+ };
4584
+ }));
4585
+ this._imageInputPos = pos;
4586
+ this._imageInputRef = document.createElement("input");
4587
+ this._imageInputRef.style.display = "none";
4588
+ this._imageInputRef.type = "file";
4589
+ this._imageInputRef.accept = "image/png, image/jpeg";
4590
+ this._imageInputRef.onchange = async event => {
4591
+ const file = event.target.files[0];
4592
+ const base64 = await convertBase64(file);
4593
+ this.addImage({
4594
+ x: this._imageInputPos.x,
4595
+ y: this._imageInputPos.y
4596
+ }, base64.toString(), 0, 0);
4597
+ };
4598
+ this._imageInputRef.oncancel = event => {
4599
+ this.removeImageInput();
4600
+ };
4601
+ document.body.appendChild(this._imageInputRef);
4602
+ setTimeout((() => {
4603
+ this._imageInputRef.click();
4604
+ }), 50);
4605
+ } else {
4606
+ this.removeImageInput();
4607
+ }
4608
+ }
4609
+ removeImageInput() {
4610
+ var _a;
4611
+ (_a = this._imageInputRef) === null || _a === void 0 ? void 0 : _a.remove();
4612
+ this._imageInputRef = null;
4613
+ this._imageInputPos = null;
4614
+ }
4482
4615
  addText(specifiedText, position, angle, color, textSize, fontSize, id) {
4483
4616
  if (specifiedText) {
4484
4617
  const tol = 1e-6;
@@ -4525,7 +4658,7 @@ class KonvaMarkup {
4525
4658
  });
4526
4659
  const obj = konvaRectangle.ref();
4527
4660
  this._konvaLayer.add(obj);
4528
- return obj;
4661
+ return konvaRectangle;
4529
4662
  }
4530
4663
  addEllipse(position, radius, lineWidth, color, id) {
4531
4664
  if (!position) return;
@@ -4538,7 +4671,7 @@ class KonvaMarkup {
4538
4671
  });
4539
4672
  const obj = konvaEllipse.ref();
4540
4673
  this._konvaLayer.add(obj);
4541
- return obj;
4674
+ return konvaEllipse;
4542
4675
  }
4543
4676
  addArrow(start, end, color, id) {
4544
4677
  if (!start || !end) return;
@@ -4550,7 +4683,7 @@ class KonvaMarkup {
4550
4683
  });
4551
4684
  const obj = konvaArrow.ref();
4552
4685
  this._konvaLayer.add(obj);
4553
- return obj;
4686
+ return konvaArrow;
4554
4687
  }
4555
4688
  addCloud(position, width, height, lineWidth, color, id) {
4556
4689
  if (!position || !width || !height) return;
@@ -4564,20 +4697,28 @@ class KonvaMarkup {
4564
4697
  });
4565
4698
  const obj = konvaCloud.ref();
4566
4699
  this._konvaLayer.add(obj);
4567
- return obj;
4700
+ return konvaCloud;
4568
4701
  }
4569
4702
  addImage(position, src, width, height, id) {
4570
- if (!position || !width || !height) return;
4571
- const konvaImage = new KonvaImage({
4572
- position: position,
4573
- src: src,
4574
- width: width,
4575
- height: height,
4576
- id: id
4577
- });
4578
- const obj = konvaImage.ref();
4579
- this._konvaLayer.add(obj);
4580
- return obj;
4703
+ if (!position) return;
4704
+ if (src) {
4705
+ const konvaImage = new KonvaImage({
4706
+ position: position,
4707
+ src: src,
4708
+ width: width,
4709
+ height: height,
4710
+ id: id
4711
+ });
4712
+ const obj = konvaImage.ref();
4713
+ this._konvaLayer.add(obj);
4714
+ const trNodes = this._konvaTransformer.nodes();
4715
+ if (trNodes.length > 0) {
4716
+ trNodes[0].destroy();
4717
+ this._konvaTransformer.nodes([]);
4718
+ }
4719
+ }
4720
+ this.removeImageInput();
4721
+ return;
4581
4722
  }
4582
4723
  }
4583
4724
 
@@ -4755,6 +4896,9 @@ class VisualizeMarkup {
4755
4896
  itr.delete();
4756
4897
  this._viewer.update();
4757
4898
  }
4899
+ colorizeSelectedMarkups(r = 255, g = 0, b = 0) {
4900
+ throw new Error("Not implemented yet");
4901
+ }
4758
4902
  setViewpoint(viewpoint) {
4759
4903
  function getLogicalPoint3dAsArray(point3d) {
4760
4904
  return [ point3d.x, point3d.y, point3d.z ];
@@ -4984,7 +5128,7 @@ class Viewer extends EventEmitter2 {
4984
5128
  };
4985
5129
  onProgress === null || onProgress === void 0 ? void 0 : onProgress(event);
4986
5130
  }));
4987
- this.visualizeJs = visualizeJs;
5131
+ this._visualizeJs = visualizeJs;
4988
5132
  this.visualizeJs.canvas = canvas;
4989
5133
  this.visualizeJs.Viewer.create();
4990
5134
  this.canvas = canvas;
@@ -5005,7 +5149,6 @@ class Viewer extends EventEmitter2 {
5005
5149
  return this;
5006
5150
  }
5007
5151
  dispose() {
5008
- var _a, _b, _c, _d;
5009
5152
  this.cancel();
5010
5153
  this.emitEvent({
5011
5154
  type: "dispose"
@@ -5013,19 +5156,20 @@ class Viewer extends EventEmitter2 {
5013
5156
  if (this.frameId) cancelAnimationFrame(this.frameId);
5014
5157
  this.frameId = 0;
5015
5158
  this.setActiveDragger("");
5016
- (_a = this._zoomWheelDragger) === null || _a === void 0 ? void 0 : _a.dispose();
5017
- (_b = this._gestureManager) === null || _b === void 0 ? void 0 : _b.dispose();
5018
5159
  this.removeAllListeners();
5019
- (_c = this._resizeObserver) === null || _c === void 0 ? void 0 : _c.disconnect();
5160
+ if (this._gestureManager) this._gestureManager.dispose();
5161
+ this._gestureManager = undefined;
5162
+ if (this._zoomWheelDragger) this._zoomWheelDragger.dispose();
5163
+ this._zoomWheelDragger = undefined;
5164
+ if (this._resizeObserver) this._resizeObserver.disconnect();
5020
5165
  this._resizeObserver = undefined;
5021
5166
  this.markup.dispose();
5022
- this.canvasEvents.forEach((x => {
5023
- var _a;
5024
- return (_a = this.canvas) === null || _a === void 0 ? void 0 : _a.removeEventListener(x, this.canvaseventlistener);
5025
- }));
5026
- this.canvas = undefined;
5027
- (_d = this.visualizeJs) === null || _d === void 0 ? void 0 : _d.getViewer().clear();
5028
- this.visualizeJs = undefined;
5167
+ if (this.canvas) {
5168
+ this.canvasEvents.forEach((x => this.canvas.removeEventListener(x, this.canvaseventlistener)));
5169
+ this.canvas = undefined;
5170
+ }
5171
+ if (this._visualizeJs) this._visualizeJs.getViewer().clear();
5172
+ this._visualizeJs = undefined;
5029
5173
  return this;
5030
5174
  }
5031
5175
  isInitialized() {
@@ -5109,6 +5253,9 @@ class Viewer extends EventEmitter2 {
5109
5253
  this._isRunAsyncUpdate = false;
5110
5254
  }
5111
5255
  }
5256
+ get visualizeJs() {
5257
+ return this._visualizeJs;
5258
+ }
5112
5259
  visLib() {
5113
5260
  return this.visualizeJs;
5114
5261
  }
@@ -5522,6 +5669,9 @@ class Viewer extends EventEmitter2 {
5522
5669
  colorizeAllMarkup(r = 255, g = 0, b = 0) {
5523
5670
  this.markup.colorizeAllMarkup(r, g, b);
5524
5671
  }
5672
+ colorizeSelectedMarkups(r = 255, g = 0, b = 0) {
5673
+ this.markup.colorizeSelectedMarkups(r, g, b);
5674
+ }
5525
5675
  addMarkupEntity(entityName) {
5526
5676
  if (!this.visualizeJs) return null;
5527
5677
  this.syncOverlay();