@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.
@@ -1345,7 +1345,10 @@ class KonvaCloud {
1345
1345
  };
1346
1346
  }
1347
1347
  }
1348
- const ARC_RADIUS = 16;
1348
+ const ARC_RADIUS = 8;
1349
+ const ARC_LENGTH = 15;
1350
+ const MIN_CLOUD_WIDTH = 50;
1351
+ const MIN_CLOUD_HEIGHT = 50;
1349
1352
  this._ref = new Konva.Shape({
1350
1353
  x: params.position.x,
1351
1354
  y: params.position.y,
@@ -1357,63 +1360,76 @@ class KonvaCloud {
1357
1360
  strokeScaleEnabled: false,
1358
1361
  globalCompositeOperation: "source-over",
1359
1362
  sceneFunc: (context, shape) => {
1360
- function calculateMidpoint(position, width, height) {
1361
- const midX = position.x + width / 2;
1362
- const midY = position.y + height / 2;
1363
- return {
1364
- x: midX,
1365
- y: midY
1366
- };
1367
- }
1363
+ const width = this._ref.width();
1364
+ const height = this._ref.height();
1368
1365
  const points = [ {
1369
1366
  x: 0,
1370
1367
  y: 0
1371
1368
  }, {
1372
- x: 0 + this._ref.width(),
1369
+ x: 0 + width,
1373
1370
  y: 0
1374
1371
  }, {
1375
- x: 0 + this._ref.width(),
1376
- y: 0 + this._ref.height()
1372
+ x: 0 + width,
1373
+ y: 0 + height
1377
1374
  }, {
1378
1375
  x: 0,
1379
- y: 0 + this._ref.height()
1376
+ y: 0 + height
1380
1377
  }, {
1381
1378
  x: 0,
1382
1379
  y: 0
1383
1380
  } ];
1384
- const midPoint = calculateMidpoint({
1385
- x: 0,
1386
- y: 0
1387
- }, this._ref.width(), this._ref.height());
1388
- const baseArcLength = 30;
1389
- context.beginPath();
1390
- for (let iPoint = 0; iPoint < points.length - 1; iPoint++) {
1391
- let approxArcLength = baseArcLength;
1392
- const dx = points[iPoint + 1].x - points[iPoint].x;
1393
- const dy = points[iPoint + 1].y - points[iPoint].y;
1394
- const length = Math.sqrt(dx * dx + dy * dy);
1395
- const arcCount = Math.floor(length / approxArcLength);
1396
- const lengthMod = length % approxArcLength;
1397
- approxArcLength = baseArcLength + arcCount / lengthMod;
1398
- let pX = points[iPoint].x + dx / arcCount / 2;
1399
- let pY = points[iPoint].y + dy / arcCount / 2;
1400
- const pEndX = points[iPoint + 1].x;
1401
- const pEndY = points[iPoint + 1].y;
1402
- const endAngle = Math.atan((pEndY - pY) / (pEndX - pX));
1403
- const startAngle = endAngle + Math.PI;
1404
- const counterClockwise = pX > midPoint.x && pY > midPoint.y;
1405
- for (let iArc = 0; iArc < arcCount; iArc++) {
1406
- if (counterClockwise) {
1407
- context.arc(pX, pY, ARC_RADIUS, endAngle, startAngle);
1408
- } else {
1409
- context.arc(pX, pY, ARC_RADIUS, startAngle, endAngle);
1381
+ if (width >= MIN_CLOUD_WIDTH - 1 || height >= MIN_CLOUD_HEIGHT - 1) drawCloud(ARC_RADIUS, ARC_LENGTH); else if (width >= MIN_CLOUD_WIDTH / 2 || height >= MIN_CLOUD_HEIGHT / 2) drawCloud(ARC_RADIUS / 2, ARC_LENGTH / 2); else drawRectangle();
1382
+ function calculateMidpoint(position) {
1383
+ const midX = position.x + width / 2;
1384
+ const midY = position.y + height / 2;
1385
+ return {
1386
+ x: midX,
1387
+ y: midY
1388
+ };
1389
+ }
1390
+ function drawCloud(arcRadius, arcLength) {
1391
+ const midPoint = calculateMidpoint({
1392
+ x: 0,
1393
+ y: 0
1394
+ });
1395
+ context.beginPath();
1396
+ for (let iPoint = 0; iPoint < points.length - 1; iPoint++) {
1397
+ let approxArcLength = arcLength;
1398
+ const dx = points[iPoint + 1].x - points[iPoint].x;
1399
+ const dy = points[iPoint + 1].y - points[iPoint].y;
1400
+ const length = Math.sqrt(dx * dx + dy * dy);
1401
+ const arcCount = Math.floor(length / approxArcLength);
1402
+ const lengthMod = length % approxArcLength;
1403
+ approxArcLength = arcLength + arcCount / lengthMod;
1404
+ let pX = points[iPoint].x + dx / arcCount / 2;
1405
+ let pY = points[iPoint].y + dy / arcCount / 2;
1406
+ const pEndX = points[iPoint + 1].x;
1407
+ const pEndY = points[iPoint + 1].y;
1408
+ const endAngle = Math.atan((pEndY - pY) / (pEndX - pX));
1409
+ const startAngle = endAngle + Math.PI;
1410
+ const counterClockwise = pX > midPoint.x && pY > midPoint.y;
1411
+ for (let iArc = 0; iArc < arcCount; iArc++) {
1412
+ if (counterClockwise) {
1413
+ context.arc(pX, pY, arcRadius, endAngle, startAngle);
1414
+ } else {
1415
+ context.arc(pX, pY, arcRadius, startAngle, endAngle);
1416
+ }
1417
+ pX += dx / arcCount;
1418
+ pY += dy / arcCount;
1410
1419
  }
1411
- pX += dx / arcCount;
1412
- pY += dy / arcCount;
1413
1420
  }
1421
+ context.closePath();
1422
+ context.fillStrokeShape(shape);
1423
+ }
1424
+ function drawRectangle() {
1425
+ context.beginPath();
1426
+ context.lineTo(points[1].x, points[1].y);
1427
+ context.lineTo(points[2].x, points[2].y);
1428
+ context.lineTo(points[3].x, points[3].y);
1429
+ context.lineTo(points[4].x, points[4].y);
1430
+ context.closePath();
1431
+ context.fillStrokeShape(shape);
1414
1432
  }
1415
- context.closePath();
1416
- context.fillStrokeShape(shape);
1417
1433
  }
1418
1434
  });
1419
1435
  this._ref.className = "Cloud";
@@ -1433,10 +1449,8 @@ class KonvaCloud {
1433
1449
  if (scaleByX) newWidth *= attrs.scaleX;
1434
1450
  let newHeight = this._ref.height();
1435
1451
  if (scaleByY) newHeight *= attrs.scaleY;
1436
- const minWidth = 100;
1437
- const minHeight = 100;
1438
- if (newWidth < minWidth) newWidth = minWidth;
1439
- if (newHeight < minHeight) newHeight = minHeight;
1452
+ if (newWidth < MIN_CLOUD_WIDTH) newWidth = MIN_CLOUD_WIDTH;
1453
+ if (newHeight < MIN_CLOUD_HEIGHT) newHeight = MIN_CLOUD_HEIGHT;
1440
1454
  if (scaleByX) {
1441
1455
  this._ref.width(newWidth);
1442
1456
  }