@inweb/markup 26.5.1 → 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.
@@ -637,7 +637,7 @@ function getDistanceIn2D(p1, p2) {
637
637
 
638
638
  class KonvaEllipse {
639
639
  constructor(params, ref = null, worldTransformer = new WorldTransform) {
640
- var _a, _b;
640
+ var _a, _b, _c;
641
641
  this._worldTransformer = worldTransformer;
642
642
  if (ref) {
643
643
  this._ref = ref;
@@ -670,6 +670,10 @@ class KonvaEllipse {
670
670
  y: 0
671
671
  };
672
672
  if (params.position2) {
673
+ (_a = params.radius) !== null && _a !== undefined ? _a : params.radius = {
674
+ x: 0,
675
+ y: 0
676
+ };
673
677
  params.radius.x = getDistanceIn2D(params.position, params.position2);
674
678
  if (params.position3) params.radius.y = getDistanceIn2D(params.position, params.position3); else params.radius.x = params.radius.y;
675
679
  } else {
@@ -679,8 +683,8 @@ class KonvaEllipse {
679
683
  };
680
684
  }
681
685
  this._ref = new Konva.Ellipse({
682
- stroke: (_a = params.color) !== null && _a !== undefined ? _a : "#ff0000",
683
- strokeWidth: (_b = params.lineWidth) !== null && _b !== undefined ? _b : 4,
686
+ stroke: (_b = params.color) !== null && _b !== undefined ? _b : "#ff0000",
687
+ strokeWidth: (_c = params.lineWidth) !== null && _c !== undefined ? _c : 4,
684
688
  globalCompositeOperation: "source-over",
685
689
  lineCap: "round",
686
690
  lineJoin: "round",
@@ -1116,13 +1120,13 @@ class KonvaImage {
1116
1120
  this._ref.width(params.maxHeight / this._ratio);
1117
1121
  this._ref.height(params.maxHeight);
1118
1122
  }
1119
- const wcsEnd = this._worldTransformer.screenToWorld({
1120
- x: params.position.x + this._ref.width(),
1121
- y: params.position.y + this._ref.height()
1122
- });
1123
- this._ref.setAttr("wcsEnd", wcsEnd);
1124
1123
  }
1125
1124
  }
1125
+ const wcsEnd = this._worldTransformer.screenToWorld({
1126
+ x: params.position.x + this._ref.width(),
1127
+ y: params.position.y + this._ref.height()
1128
+ });
1129
+ this._ref.setAttr("wcsEnd", wcsEnd);
1126
1130
  };
1127
1131
  this._canvasImage.onerror = () => {
1128
1132
  this._canvasImage.onerror = function() {};
@@ -1341,7 +1345,10 @@ class KonvaCloud {
1341
1345
  };
1342
1346
  }
1343
1347
  }
1344
- 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;
1345
1352
  this._ref = new Konva.Shape({
1346
1353
  x: params.position.x,
1347
1354
  y: params.position.y,
@@ -1353,63 +1360,76 @@ class KonvaCloud {
1353
1360
  strokeScaleEnabled: false,
1354
1361
  globalCompositeOperation: "source-over",
1355
1362
  sceneFunc: (context, shape) => {
1356
- function calculateMidpoint(position, width, height) {
1357
- const midX = position.x + width / 2;
1358
- const midY = position.y + height / 2;
1359
- return {
1360
- x: midX,
1361
- y: midY
1362
- };
1363
- }
1363
+ const width = this._ref.width();
1364
+ const height = this._ref.height();
1364
1365
  const points = [ {
1365
1366
  x: 0,
1366
1367
  y: 0
1367
1368
  }, {
1368
- x: 0 + this._ref.width(),
1369
+ x: 0 + width,
1369
1370
  y: 0
1370
1371
  }, {
1371
- x: 0 + this._ref.width(),
1372
- y: 0 + this._ref.height()
1372
+ x: 0 + width,
1373
+ y: 0 + height
1373
1374
  }, {
1374
1375
  x: 0,
1375
- y: 0 + this._ref.height()
1376
+ y: 0 + height
1376
1377
  }, {
1377
1378
  x: 0,
1378
1379
  y: 0
1379
1380
  } ];
1380
- const midPoint = calculateMidpoint({
1381
- x: 0,
1382
- y: 0
1383
- }, this._ref.width(), this._ref.height());
1384
- const baseArcLength = 30;
1385
- context.beginPath();
1386
- for (let iPoint = 0; iPoint < points.length - 1; iPoint++) {
1387
- let approxArcLength = baseArcLength;
1388
- const dx = points[iPoint + 1].x - points[iPoint].x;
1389
- const dy = points[iPoint + 1].y - points[iPoint].y;
1390
- const length = Math.sqrt(dx * dx + dy * dy);
1391
- const arcCount = Math.floor(length / approxArcLength);
1392
- const lengthMod = length % approxArcLength;
1393
- approxArcLength = baseArcLength + arcCount / lengthMod;
1394
- let pX = points[iPoint].x + dx / arcCount / 2;
1395
- let pY = points[iPoint].y + dy / arcCount / 2;
1396
- const pEndX = points[iPoint + 1].x;
1397
- const pEndY = points[iPoint + 1].y;
1398
- const endAngle = Math.atan((pEndY - pY) / (pEndX - pX));
1399
- const startAngle = endAngle + Math.PI;
1400
- const counterClockwise = pX > midPoint.x && pY > midPoint.y;
1401
- for (let iArc = 0; iArc < arcCount; iArc++) {
1402
- if (counterClockwise) {
1403
- context.arc(pX, pY, ARC_RADIUS, endAngle, startAngle);
1404
- } else {
1405
- 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;
1406
1419
  }
1407
- pX += dx / arcCount;
1408
- pY += dy / arcCount;
1409
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);
1410
1432
  }
1411
- context.closePath();
1412
- context.fillStrokeShape(shape);
1413
1433
  }
1414
1434
  });
1415
1435
  this._ref.className = "Cloud";
@@ -1429,10 +1449,8 @@ class KonvaCloud {
1429
1449
  if (scaleByX) newWidth *= attrs.scaleX;
1430
1450
  let newHeight = this._ref.height();
1431
1451
  if (scaleByY) newHeight *= attrs.scaleY;
1432
- const minWidth = 100;
1433
- const minHeight = 100;
1434
- if (newWidth < minWidth) newWidth = minWidth;
1435
- 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;
1436
1454
  if (scaleByX) {
1437
1455
  this._ref.width(newWidth);
1438
1456
  }