@inweb/markup 25.8.16 → 25.8.20

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 CHANGED
@@ -11571,8 +11571,13 @@
11571
11571
  this._ref = ref;
11572
11572
  return;
11573
11573
  }
11574
- if (!params || !params.points)
11575
- return;
11574
+ if (!params)
11575
+ params = {};
11576
+ if (!params.points)
11577
+ params.points = [
11578
+ { x: 50, y: 50 },
11579
+ { x: 100, y: 100 },
11580
+ ];
11576
11581
  const konvaPoints = [];
11577
11582
  params.points.forEach((point) => konvaPoints.push(point.x, point.y));
11578
11583
  this._ref = new Konva.Line({
@@ -11674,8 +11679,12 @@
11674
11679
  this._ref = ref;
11675
11680
  return;
11676
11681
  }
11677
- if (!params || !params.position || !params.text)
11678
- return;
11682
+ if (!params)
11683
+ params = {};
11684
+ if (!params.position)
11685
+ params.position = { x: 100, y: 100 };
11686
+ if (!params.text)
11687
+ params.text = "default";
11679
11688
  this._ref = new Konva.Text({
11680
11689
  x: params.position.x,
11681
11690
  y: params.position.y,
@@ -11776,8 +11785,10 @@
11776
11785
  this._ref = ref;
11777
11786
  return;
11778
11787
  }
11779
- if (!params || !params.position)
11780
- return;
11788
+ if (!params)
11789
+ params = {};
11790
+ if (!params.position)
11791
+ params.position = { x: 100, y: 100 };
11781
11792
  this._ref = new Konva.Rect({
11782
11793
  stroke: (_a = params.color) !== null && _a !== void 0 ? _a : "#ff0000",
11783
11794
  strokeWidth: (_b = params.lineWidth) !== null && _b !== void 0 ? _b : 4,
@@ -11886,8 +11897,12 @@
11886
11897
  this._ref = ref;
11887
11898
  return;
11888
11899
  }
11889
- if (!params || !params.position || !params.radius)
11890
- return;
11900
+ if (!params)
11901
+ params = {};
11902
+ if (!params.position)
11903
+ params.position = { x: 100, y: 100 };
11904
+ if (!params.radius)
11905
+ params.radius = { x: 25, y: 25 };
11891
11906
  this._ref = new Konva.Ellipse({
11892
11907
  stroke: (_a = params.color) !== null && _a !== void 0 ? _a : "#ff0000",
11893
11908
  strokeWidth: (_b = params.lineWidth) !== null && _b !== void 0 ? _b : 4,
@@ -12002,8 +12017,12 @@
12002
12017
  this._ref = ref;
12003
12018
  return;
12004
12019
  }
12005
- if (!params || !params.start || !params.end)
12006
- return;
12020
+ if (!params)
12021
+ params = {};
12022
+ if (!params.start)
12023
+ params.start = { x: 50, y: 50 };
12024
+ if (!params.end)
12025
+ params.end = { x: 100, y: 100 };
12007
12026
  this._ref = new Konva.Arrow({
12008
12027
  stroke: (_a = params.color) !== null && _a !== void 0 ? _a : "#ff0000",
12009
12028
  fill: (_b = params.color) !== null && _b !== void 0 ? _b : "#ff0000",
@@ -12091,16 +12110,63 @@
12091
12110
  constructor(params, ref = null) {
12092
12111
  var _a, _b;
12093
12112
  this._ratio = 1;
12113
+ this.EPSILON = 10e-6;
12114
+ this.BASE64_NOT_FOUND = "data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAAADsAAAA7AF5KHG9AAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAmhJREFUWIXtlr9rVEEQxz+H8RQUJIdeIopYm0vkCg0GBBtbG1NF7Kxt7dR/IGIw/uhTaBNLERURg2kCEUyCYCPi70b0InjGS57FzOZN3r19d+9HJIVfWO52dma/s7Mz8xa2KAaBCWAR+AkECWOmSOIdwC1gtQOpHc+NfQ8wClQ8+1d0vcdH/lQ3bSIRGAZ2pTjAqNovANXIWlXlAXA2zvi2Ln4AjqYgtagYEutENSLvjRoOImFv5iB32Ae8UrLXwFBk3h9ndF0VJnKSO9gTu3yKu5Z1LKnS8YIcABgw5Ks692JZFXcXRJ46Aq6kikCnHNi/mQ50WwVtfaIoBzL3gRk2drSscJ2wrc4VvUoe2wn/41/iBfoVLRnBGnDSY3AAKacy8AmYR+o7K1zCl6wgrgpOAc/MuhvfgMuk+1JGHQgSBcAloKXy78AjYBppJk5/noTulseBMZ23iD/piHFkEdgTQzKk+5wHjmHC3cmBg0BD5xcSTrFXyQPgIWFtDwMvab+2N8DpbhyY1v/3E8gdDgNfVX9SCVZ0/gW4B0wB71S2BpxLcuCM/jaQSHSDEeAX4VMuAG4gTzyHbcAVXXO6GxxwIX+vvxe7JHcYQ07nHqklj96UIW/YhSWzMKcep8VVtf8B1Dw6h4DfhB+sdbgn2R+gnoEc5NR3dZ+3QJ9H74HqXLPCGlJyTfI9y3YCs0owq3OLOpKkLeBI1HhSDT/mdKIPiUCARMTlQx34TMLjtww8IczmO8AJ/N/2JNSQXAiQ671JePePge0+wzJSQq4FFzlaenIvucUAkiQLhC/mLGNZ9xgn5s63BP4CCk0QDtm4BhoAAAAASUVORK5CYII=";
12115
+ this.BASE64_HEADER_START = "data:image/";
12094
12116
  if (ref) {
12095
- // if (ref.height() === 0 || ref.width() === 0) return;
12117
+ if (!ref.src || !ref.src.startsWith(this.BASE64_HEADER_START))
12118
+ ref.src = this.BASE64_NOT_FOUND;
12119
+ if (ref.height() <= this.EPSILON)
12120
+ ref.height(32);
12121
+ if (ref.width() <= this.EPSILON)
12122
+ ref.width(32);
12096
12123
  this._ref = ref;
12097
12124
  this._canvasImage = ref.image();
12098
- this._ratio = this._ref.height() === 0 || this._ref.width() === 0 ? 1 : this._ref.height() / this._ref.width();
12125
+ this._ratio =
12126
+ this._ref.height() <= this.EPSILON || this._ref.width() <= this.EPSILON
12127
+ ? 1
12128
+ : this._ref.height() / this._ref.width();
12099
12129
  return;
12100
12130
  }
12101
- if (!params || !params.position || !params.src)
12102
- return;
12131
+ if (!params)
12132
+ params = {};
12133
+ if (!params.position)
12134
+ params.position = { x: 50, y: 50 };
12135
+ if (!params.src || !params.src.startsWith(this.BASE64_HEADER_START))
12136
+ params.src = this.BASE64_NOT_FOUND;
12103
12137
  this._canvasImage = new Image();
12138
+ this._canvasImage.onload = () => {
12139
+ this._ref.image(this._canvasImage);
12140
+ if (this._ref.height() <= this.EPSILON)
12141
+ this._ref.height(this._canvasImage.height);
12142
+ if (this._ref.width() <= this.EPSILON)
12143
+ this._ref.width(this._canvasImage.width);
12144
+ this._ratio =
12145
+ this._ref.height() <= this.EPSILON || this._ref.width() <= this.EPSILON
12146
+ ? 1
12147
+ : this._ref.height() / this._ref.width();
12148
+ // need to rescale only if input width and height are 0 - we do not loading Viewpoint with existing params
12149
+ if ((params.width <= this.EPSILON || params.height <= this.EPSILON) &&
12150
+ (params.maxWidth >= this.EPSILON || params.maxWidth >= this.EPSILON)) {
12151
+ const heightOutOfCanvas = params.maxHeight - this._canvasImage.height;
12152
+ const widthOutOfCanvas = params.maxWidth - this._canvasImage.width;
12153
+ if (heightOutOfCanvas <= this.EPSILON || widthOutOfCanvas <= this.EPSILON) {
12154
+ if (widthOutOfCanvas <= this.EPSILON && widthOutOfCanvas < heightOutOfCanvas / this._ratio) {
12155
+ this._ref.height(params.maxWidth * this._ratio);
12156
+ this._ref.width(params.maxWidth);
12157
+ }
12158
+ else {
12159
+ this._ref.width(params.maxHeight / this._ratio);
12160
+ this._ref.height(params.maxHeight);
12161
+ }
12162
+ }
12163
+ }
12164
+ };
12165
+ this._canvasImage.onerror = () => {
12166
+ this._canvasImage.onerror = function () { };
12167
+ this._canvasImage.src = this.BASE64_NOT_FOUND;
12168
+ };
12169
+ this._canvasImage.src = params.src;
12104
12170
  this._ref = new Konva.Image({
12105
12171
  x: params.position.x,
12106
12172
  y: params.position.y,
@@ -12109,15 +12175,6 @@
12109
12175
  height: (_b = params.height) !== null && _b !== void 0 ? _b : 0,
12110
12176
  draggable: true,
12111
12177
  });
12112
- this._canvasImage.onload = () => {
12113
- this._ref.image(this._canvasImage);
12114
- if (this._ref.height() === 0)
12115
- this._ref.height(this._canvasImage.height);
12116
- if (this._ref.width() === 0)
12117
- this._ref.width(this._canvasImage.width);
12118
- this._ratio = this._ref.height() === 0 || this._ref.width() === 0 ? 1 : this._ref.height() / this._ref.width();
12119
- };
12120
- this._canvasImage.src = params.src;
12121
12178
  this._ref.on("transform", (e) => {
12122
12179
  const attrs = e.target.attrs;
12123
12180
  if (attrs.rotation !== this._ref.rotation())
@@ -12215,8 +12272,10 @@
12215
12272
  this._ref = ref;
12216
12273
  return;
12217
12274
  }
12218
- if (!params || !params.position)
12219
- return;
12275
+ if (!params)
12276
+ params = {};
12277
+ if (!params.position)
12278
+ params.position = { x: 100, y: 100 };
12220
12279
  const arcRadius = 16;
12221
12280
  this._ref = new Konva.Shape({
12222
12281
  x: params.position.x,
@@ -13229,6 +13288,8 @@
13229
13288
  src,
13230
13289
  width,
13231
13290
  height,
13291
+ maxWidth: this._konvaStage.width() - position.x,
13292
+ maxHeight: this._konvaStage.height() - position.y,
13232
13293
  id,
13233
13294
  });
13234
13295
  this.addObject(konvaImage);