@inweb/markup 25.8.15 → 25.8.19

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
@@ -12091,11 +12091,15 @@
12091
12091
  constructor(params, ref = null) {
12092
12092
  var _a, _b;
12093
12093
  this._ratio = 1;
12094
+ this.EPSILON = 10e-6;
12094
12095
  if (ref) {
12095
12096
  // if (ref.height() === 0 || ref.width() === 0) return;
12096
12097
  this._ref = ref;
12097
12098
  this._canvasImage = ref.image();
12098
- this._ratio = this._ref.height() === 0 || this._ref.width() === 0 ? 1 : this._ref.height() / this._ref.width();
12099
+ this._ratio =
12100
+ this._ref.height() <= this.EPSILON || this._ref.width() <= this.EPSILON
12101
+ ? 1
12102
+ : this._ref.height() / this._ref.width();
12099
12103
  return;
12100
12104
  }
12101
12105
  if (!params || !params.position || !params.src)
@@ -12111,11 +12115,30 @@
12111
12115
  });
12112
12116
  this._canvasImage.onload = () => {
12113
12117
  this._ref.image(this._canvasImage);
12114
- if (this._ref.height() === 0)
12118
+ if (this._ref.height() <= this.EPSILON)
12115
12119
  this._ref.height(this._canvasImage.height);
12116
- if (this._ref.width() === 0)
12120
+ if (this._ref.width() <= this.EPSILON)
12117
12121
  this._ref.width(this._canvasImage.width);
12118
- this._ratio = this._ref.height() === 0 || this._ref.width() === 0 ? 1 : this._ref.height() / this._ref.width();
12122
+ this._ratio =
12123
+ this._ref.height() <= this.EPSILON || this._ref.width() <= this.EPSILON
12124
+ ? 1
12125
+ : this._ref.height() / this._ref.width();
12126
+ // need to rescale only if input width and height are 0 - we do not loading Viewpoint with existing params
12127
+ if ((params.width <= this.EPSILON || params.height <= this.EPSILON) &&
12128
+ (params.maxWidth >= this.EPSILON || params.maxWidth >= this.EPSILON)) {
12129
+ const heightOutOfCanvas = params.maxHeight - this._canvasImage.height;
12130
+ const widthOutOfCanvas = params.maxWidth - this._canvasImage.width;
12131
+ if (heightOutOfCanvas <= this.EPSILON || widthOutOfCanvas <= this.EPSILON) {
12132
+ if (widthOutOfCanvas <= this.EPSILON && widthOutOfCanvas < heightOutOfCanvas / this._ratio) {
12133
+ this._ref.height(params.maxWidth * this._ratio);
12134
+ this._ref.width(params.maxWidth);
12135
+ }
12136
+ else {
12137
+ this._ref.width(params.maxHeight / this._ratio);
12138
+ this._ref.height(params.maxHeight);
12139
+ }
12140
+ }
12141
+ }
12119
12142
  };
12120
12143
  this._canvasImage.src = params.src;
12121
12144
  this._ref.on("transform", (e) => {
@@ -12885,7 +12908,10 @@
12885
12908
  for (let i = 0; i < linePoints.length; i += 2) {
12886
12909
  // we need getAbsoluteTransform because inside Konva position starts from {0, 0}
12887
12910
  // https://stackoverflow.com/a/57641487 - check answer's comments
12888
- const atPoint = absoluteTransform.point({ x: linePoints[i], y: linePoints[i + 1] });
12911
+ const atPoint = absoluteTransform.point({
12912
+ x: linePoints[i],
12913
+ y: linePoints[i + 1],
12914
+ });
12889
12915
  const worldPoint = this._worldTransformer.screenToWorld(atPoint);
12890
12916
  worldPoints.push(worldPoint);
12891
12917
  }
@@ -12906,7 +12932,10 @@
12906
12932
  this.konvaLayerFind("Text").forEach((ref) => {
12907
12933
  const textSize = 0.02;
12908
12934
  const textScale = this._worldTransformer.getScale();
12909
- const position = { x: ref.x(), y: ref.y() };
12935
+ const position = {
12936
+ x: ref.x(),
12937
+ y: ref.y(),
12938
+ };
12910
12939
  const worldPoint = this._worldTransformer.screenToWorld(position);
12911
12940
  const shape = new KonvaText(null, ref);
12912
12941
  const text = {
@@ -12962,9 +12991,15 @@
12962
12991
  this.konvaLayerFind("Arrow").forEach((ref) => {
12963
12992
  // we need getAbsoluteTransform because inside Konva position starts from {0, 0}
12964
12993
  const absoluteTransform = ref.getAbsoluteTransform();
12965
- const atStartPoint = absoluteTransform.point({ x: ref.points()[0], y: ref.points()[1] });
12994
+ const atStartPoint = absoluteTransform.point({
12995
+ x: ref.points()[0],
12996
+ y: ref.points()[1],
12997
+ });
12966
12998
  const worldStartPoint = this._worldTransformer.screenToWorld(atStartPoint);
12967
- const atEndPoint = absoluteTransform.point({ x: ref.points()[2], y: ref.points()[3] });
12999
+ const atEndPoint = absoluteTransform.point({
13000
+ x: ref.points()[2],
13001
+ y: ref.points()[3],
13002
+ });
12968
13003
  const worldEndPoint = this._worldTransformer.screenToWorld(atEndPoint);
12969
13004
  const shape = new KonvaArrow(null, ref);
12970
13005
  const arrow = {
@@ -13217,6 +13252,8 @@
13217
13252
  src,
13218
13253
  width,
13219
13254
  height,
13255
+ maxWidth: this._konvaStage.width() - position.x,
13256
+ maxHeight: this._konvaStage.height() - position.y,
13220
13257
  id,
13221
13258
  });
13222
13259
  this.addObject(konvaImage);