@inweb/markup 26.5.2 → 26.5.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inweb/markup",
3
- "version": "26.5.2",
3
+ "version": "26.5.4",
4
4
  "description": "JavaScript 2D markups",
5
5
  "homepage": "https://cloud.opendesign.com/docs/index.html",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -26,8 +26,8 @@
26
26
  "docs": "typedoc"
27
27
  },
28
28
  "dependencies": {
29
- "@inweb/eventemitter2": "~26.5.2",
30
- "@inweb/viewer-core": "~26.5.2"
29
+ "@inweb/eventemitter2": "~26.5.4",
30
+ "@inweb/viewer-core": "~26.5.4"
31
31
  },
32
32
  "devDependencies": {
33
33
  "konva": "^9.3.18"
@@ -65,7 +65,10 @@ export class KonvaCloud implements IMarkupCloud {
65
65
  }
66
66
  }
67
67
 
68
- const ARC_RADIUS = 16;
68
+ const ARC_RADIUS = 8;
69
+ const ARC_LENGTH = 15;
70
+ const MIN_CLOUD_WIDTH = 50;
71
+ const MIN_CLOUD_HEIGHT = 50;
69
72
 
70
73
  this._ref = new Konva.Shape({
71
74
  x: params.position.x,
@@ -78,57 +81,77 @@ export class KonvaCloud implements IMarkupCloud {
78
81
  strokeScaleEnabled: false,
79
82
  globalCompositeOperation: "source-over",
80
83
  sceneFunc: (context, shape) => {
81
- function calculateMidpoint(position, width, height) {
82
- const midX = position.x + width / 2;
83
- const midY = position.y + height / 2;
84
- return { x: midX, y: midY };
85
- }
86
-
84
+ const width = this._ref.width();
85
+ const height = this._ref.height();
87
86
  const points = [
88
87
  { x: 0, y: 0 },
89
- { x: 0 + this._ref.width(), y: 0 },
90
- { x: 0 + this._ref.width(), y: 0 + this._ref.height() },
91
- { x: 0, y: 0 + this._ref.height() },
88
+ { x: 0 + width, y: 0 },
89
+ { x: 0 + width, y: 0 + height },
90
+ { x: 0, y: 0 + height },
92
91
  { x: 0, y: 0 },
93
92
  ];
94
93
 
95
- const midPoint = calculateMidpoint({ x: 0, y: 0 }, this._ref.width(), this._ref.height());
96
-
97
- const baseArcLength = 30;
98
- context.beginPath();
99
- for (let iPoint = 0; iPoint < points.length - 1; iPoint++) {
100
- let approxArcLength = baseArcLength;
101
- const dx = points[iPoint + 1].x - points[iPoint].x;
102
- const dy = points[iPoint + 1].y - points[iPoint].y;
103
- const length = Math.sqrt(dx * dx + dy * dy);
104
-
105
- const arcCount = Math.floor(length / approxArcLength);
106
- const lengthMod = length % approxArcLength;
107
- approxArcLength = baseArcLength + arcCount / lengthMod;
108
-
109
- let pX = points[iPoint].x + dx / arcCount / 2;
110
- let pY = points[iPoint].y + dy / arcCount / 2;
111
- const pEndX = points[iPoint + 1].x;
112
- const pEndY = points[iPoint + 1].y;
113
- const endAngle = Math.atan((pEndY - pY) / (pEndX - pX));
114
- const startAngle = endAngle + Math.PI;
115
- const counterClockwise = pX > midPoint.x && pY > midPoint.y;
116
- for (let iArc = 0; iArc < arcCount; iArc++) {
117
- if (counterClockwise) {
118
- context.arc(pX, pY, ARC_RADIUS, endAngle, startAngle);
119
- } else {
120
- context.arc(pX, pY, ARC_RADIUS, startAngle, endAngle);
121
- }
94
+ if (width >= MIN_CLOUD_WIDTH - 1 || height >= MIN_CLOUD_HEIGHT - 1) drawCloud(ARC_RADIUS, ARC_LENGTH);
95
+ else if (width >= MIN_CLOUD_WIDTH / 2 || height >= MIN_CLOUD_HEIGHT / 2)
96
+ drawCloud(ARC_RADIUS / 2, ARC_LENGTH / 2);
97
+ else drawRectangle();
122
98
 
123
- pX += dx / arcCount;
124
- pY += dy / arcCount;
99
+ function calculateMidpoint(position) {
100
+ const midX = position.x + width / 2;
101
+ const midY = position.y + height / 2;
102
+ return { x: midX, y: midY };
103
+ }
104
+
105
+ function drawCloud(arcRadius, arcLength) {
106
+ const midPoint = calculateMidpoint({ x: 0, y: 0 });
107
+
108
+ context.beginPath();
109
+ for (let iPoint = 0; iPoint < points.length - 1; iPoint++) {
110
+ let approxArcLength = arcLength;
111
+ const dx = points[iPoint + 1].x - points[iPoint].x;
112
+ const dy = points[iPoint + 1].y - points[iPoint].y;
113
+ const length = Math.sqrt(dx * dx + dy * dy);
114
+
115
+ const arcCount = Math.floor(length / approxArcLength);
116
+ const lengthMod = length % approxArcLength;
117
+ approxArcLength = arcLength + arcCount / lengthMod;
118
+
119
+ let pX = points[iPoint].x + dx / arcCount / 2;
120
+ let pY = points[iPoint].y + dy / arcCount / 2;
121
+ const pEndX = points[iPoint + 1].x;
122
+ const pEndY = points[iPoint + 1].y;
123
+ const endAngle = Math.atan((pEndY - pY) / (pEndX - pX));
124
+ const startAngle = endAngle + Math.PI;
125
+ const counterClockwise = pX > midPoint.x && pY > midPoint.y;
126
+ for (let iArc = 0; iArc < arcCount; iArc++) {
127
+ if (counterClockwise) {
128
+ context.arc(pX, pY, arcRadius, endAngle, startAngle);
129
+ } else {
130
+ context.arc(pX, pY, arcRadius, startAngle, endAngle);
131
+ }
132
+
133
+ pX += dx / arcCount;
134
+ pY += dy / arcCount;
135
+ }
125
136
  }
137
+
138
+ context.closePath();
139
+ // (!) Konva specific method, it is very important
140
+ // it will apply are required styles
141
+ context.fillStrokeShape(shape);
126
142
  }
127
143
 
128
- context.closePath();
129
- // (!) Konva specific method, it is very important
130
- // it will apply are required styles
131
- context.fillStrokeShape(shape);
144
+ function drawRectangle() {
145
+ context.beginPath();
146
+ context.lineTo(points[1].x, points[1].y);
147
+ context.lineTo(points[2].x, points[2].y);
148
+ context.lineTo(points[3].x, points[3].y);
149
+ context.lineTo(points[4].x, points[4].y);
150
+ context.closePath();
151
+ // (!) Konva specific method, it is very important
152
+ // it will apply are required styles
153
+ context.fillStrokeShape(shape);
154
+ }
132
155
  },
133
156
  });
134
157
 
@@ -148,11 +171,8 @@ export class KonvaCloud implements IMarkupCloud {
148
171
  let newHeight = this._ref.height();
149
172
  if (scaleByY) newHeight *= attrs.scaleY;
150
173
 
151
- const minWidth = 100;
152
- const minHeight = 100;
153
-
154
- if (newWidth < minWidth) newWidth = minWidth;
155
- if (newHeight < minHeight) newHeight = minHeight;
174
+ if (newWidth < MIN_CLOUD_WIDTH) newWidth = MIN_CLOUD_WIDTH;
175
+ if (newHeight < MIN_CLOUD_HEIGHT) newHeight = MIN_CLOUD_HEIGHT;
156
176
 
157
177
  if (scaleByX) {
158
178
  this._ref.width(newWidth);