@inweb/markup 26.5.2 → 26.5.3

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
@@ -13195,7 +13195,10 @@
13195
13195
  params.position2 = { x: params.position.x + params.width, y: params.position.y + params.height };
13196
13196
  }
13197
13197
  }
13198
- const ARC_RADIUS = 16;
13198
+ const ARC_RADIUS = 8;
13199
+ const ARC_LENGTH = 15;
13200
+ const MIN_CLOUD_WIDTH = 50;
13201
+ const MIN_CLOUD_HEIGHT = 50;
13199
13202
  this._ref = new Konva.Shape({
13200
13203
  x: params.position.x,
13201
13204
  y: params.position.y,
@@ -13207,51 +13210,71 @@
13207
13210
  strokeScaleEnabled: false,
13208
13211
  globalCompositeOperation: "source-over",
13209
13212
  sceneFunc: (context, shape) => {
13210
- function calculateMidpoint(position, width, height) {
13211
- const midX = position.x + width / 2;
13212
- const midY = position.y + height / 2;
13213
- return { x: midX, y: midY };
13214
- }
13213
+ const width = this._ref.width();
13214
+ const height = this._ref.height();
13215
13215
  const points = [
13216
13216
  { x: 0, y: 0 },
13217
- { x: 0 + this._ref.width(), y: 0 },
13218
- { x: 0 + this._ref.width(), y: 0 + this._ref.height() },
13219
- { x: 0, y: 0 + this._ref.height() },
13217
+ { x: 0 + width, y: 0 },
13218
+ { x: 0 + width, y: 0 + height },
13219
+ { x: 0, y: 0 + height },
13220
13220
  { x: 0, y: 0 },
13221
13221
  ];
13222
- const midPoint = calculateMidpoint({ x: 0, y: 0 }, this._ref.width(), this._ref.height());
13223
- const baseArcLength = 30;
13224
- context.beginPath();
13225
- for (let iPoint = 0; iPoint < points.length - 1; iPoint++) {
13226
- let approxArcLength = baseArcLength;
13227
- const dx = points[iPoint + 1].x - points[iPoint].x;
13228
- const dy = points[iPoint + 1].y - points[iPoint].y;
13229
- const length = Math.sqrt(dx * dx + dy * dy);
13230
- const arcCount = Math.floor(length / approxArcLength);
13231
- const lengthMod = length % approxArcLength;
13232
- approxArcLength = baseArcLength + arcCount / lengthMod;
13233
- let pX = points[iPoint].x + dx / arcCount / 2;
13234
- let pY = points[iPoint].y + dy / arcCount / 2;
13235
- const pEndX = points[iPoint + 1].x;
13236
- const pEndY = points[iPoint + 1].y;
13237
- const endAngle = Math.atan((pEndY - pY) / (pEndX - pX));
13238
- const startAngle = endAngle + Math.PI;
13239
- const counterClockwise = pX > midPoint.x && pY > midPoint.y;
13240
- for (let iArc = 0; iArc < arcCount; iArc++) {
13241
- if (counterClockwise) {
13242
- context.arc(pX, pY, ARC_RADIUS, endAngle, startAngle);
13243
- }
13244
- else {
13245
- context.arc(pX, pY, ARC_RADIUS, startAngle, endAngle);
13222
+ if (width >= MIN_CLOUD_WIDTH - 1 || height >= MIN_CLOUD_HEIGHT - 1)
13223
+ drawCloud(ARC_RADIUS, ARC_LENGTH);
13224
+ else if (width >= MIN_CLOUD_WIDTH / 2 || height >= MIN_CLOUD_HEIGHT / 2)
13225
+ drawCloud(ARC_RADIUS / 2, ARC_LENGTH / 2);
13226
+ else
13227
+ drawRectangle();
13228
+ function calculateMidpoint(position) {
13229
+ const midX = position.x + width / 2;
13230
+ const midY = position.y + height / 2;
13231
+ return { x: midX, y: midY };
13232
+ }
13233
+ function drawCloud(arcRadius, arcLength) {
13234
+ const midPoint = calculateMidpoint({ x: 0, y: 0 });
13235
+ context.beginPath();
13236
+ for (let iPoint = 0; iPoint < points.length - 1; iPoint++) {
13237
+ let approxArcLength = arcLength;
13238
+ const dx = points[iPoint + 1].x - points[iPoint].x;
13239
+ const dy = points[iPoint + 1].y - points[iPoint].y;
13240
+ const length = Math.sqrt(dx * dx + dy * dy);
13241
+ const arcCount = Math.floor(length / approxArcLength);
13242
+ const lengthMod = length % approxArcLength;
13243
+ approxArcLength = arcLength + arcCount / lengthMod;
13244
+ let pX = points[iPoint].x + dx / arcCount / 2;
13245
+ let pY = points[iPoint].y + dy / arcCount / 2;
13246
+ const pEndX = points[iPoint + 1].x;
13247
+ const pEndY = points[iPoint + 1].y;
13248
+ const endAngle = Math.atan((pEndY - pY) / (pEndX - pX));
13249
+ const startAngle = endAngle + Math.PI;
13250
+ const counterClockwise = pX > midPoint.x && pY > midPoint.y;
13251
+ for (let iArc = 0; iArc < arcCount; iArc++) {
13252
+ if (counterClockwise) {
13253
+ context.arc(pX, pY, arcRadius, endAngle, startAngle);
13254
+ }
13255
+ else {
13256
+ context.arc(pX, pY, arcRadius, startAngle, endAngle);
13257
+ }
13258
+ pX += dx / arcCount;
13259
+ pY += dy / arcCount;
13246
13260
  }
13247
- pX += dx / arcCount;
13248
- pY += dy / arcCount;
13249
13261
  }
13262
+ context.closePath();
13263
+ // (!) Konva specific method, it is very important
13264
+ // it will apply are required styles
13265
+ context.fillStrokeShape(shape);
13266
+ }
13267
+ function drawRectangle() {
13268
+ context.beginPath();
13269
+ context.lineTo(points[1].x, points[1].y);
13270
+ context.lineTo(points[2].x, points[2].y);
13271
+ context.lineTo(points[3].x, points[3].y);
13272
+ context.lineTo(points[4].x, points[4].y);
13273
+ context.closePath();
13274
+ // (!) Konva specific method, it is very important
13275
+ // it will apply are required styles
13276
+ context.fillStrokeShape(shape);
13250
13277
  }
13251
- context.closePath();
13252
- // (!) Konva specific method, it is very important
13253
- // it will apply are required styles
13254
- context.fillStrokeShape(shape);
13255
13278
  },
13256
13279
  });
13257
13280
  this._ref.className = "Cloud";
@@ -13267,12 +13290,10 @@
13267
13290
  let newHeight = this._ref.height();
13268
13291
  if (scaleByY)
13269
13292
  newHeight *= attrs.scaleY;
13270
- const minWidth = 100;
13271
- const minHeight = 100;
13272
- if (newWidth < minWidth)
13273
- newWidth = minWidth;
13274
- if (newHeight < minHeight)
13275
- newHeight = minHeight;
13293
+ if (newWidth < MIN_CLOUD_WIDTH)
13294
+ newWidth = MIN_CLOUD_WIDTH;
13295
+ if (newHeight < MIN_CLOUD_HEIGHT)
13296
+ newHeight = MIN_CLOUD_HEIGHT;
13276
13297
  if (scaleByX) {
13277
13298
  this._ref.width(newWidth);
13278
13299
  }