@inweb/markup 27.1.5 → 27.1.7

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
@@ -42,7 +42,7 @@
42
42
  : {};
43
43
  const Konva$2 = {
44
44
  _global: glob,
45
- version: '10.0.12',
45
+ version: '10.2.0',
46
46
  isBrowser: detectBrowser(),
47
47
  isUnminified: /param/.test(function (param) { }.toString()),
48
48
  dblClickWindow: 400,
@@ -414,7 +414,7 @@ js: import "konva/skia-backend";
414
414
  let _isCanvasFarblingActive = null;
415
415
  const req = (typeof requestAnimationFrame !== 'undefined' && requestAnimationFrame) ||
416
416
  function (f) {
417
- setTimeout(f, 60);
417
+ setTimeout(f, 16);
418
418
  };
419
419
  const Util = {
420
420
  _isElement(obj) {
@@ -2211,8 +2211,8 @@ js: import "konva/skia-backend";
2211
2211
  }
2212
2212
  clearCache() {
2213
2213
  if (this._cache.has(CANVAS)) {
2214
- const { scene, filter, hit, buffer } = this._cache.get(CANVAS);
2215
- Util.releaseCanvas(scene, filter, hit, buffer);
2214
+ const { scene, filter, hit } = this._cache.get(CANVAS);
2215
+ Util.releaseCanvas(scene._canvas, filter._canvas, hit._canvas);
2216
2216
  this._cache.delete(CANVAS);
2217
2217
  }
2218
2218
  this._clearSelfAndDescendantCache();
@@ -2295,11 +2295,11 @@ js: import "konva/skia-backend";
2295
2295
  sceneContext.stroke();
2296
2296
  sceneContext.restore();
2297
2297
  }
2298
+ Util.releaseCanvas(bufferCanvas._canvas);
2298
2299
  this._cache.set(CANVAS, {
2299
2300
  scene: cachedSceneCanvas,
2300
2301
  filter: cachedFilterCanvas,
2301
2302
  hit: cachedHitCanvas,
2302
- buffer: bufferCanvas,
2303
2303
  x: x,
2304
2304
  y: y,
2305
2305
  });
@@ -3324,19 +3324,20 @@ js: import "konva/skia-backend";
3324
3324
  }
3325
3325
  }
3326
3326
  _getProtoListeners(eventType) {
3327
- var _a, _b, _c;
3328
- const allListeners = (_a = this._cache.get(ALL_LISTENERS)) !== null && _a !== void 0 ? _a : {};
3327
+ var _a, _b;
3328
+ const { nodeType } = this;
3329
+ const allListeners = Node.protoListenerMap.get(nodeType) || {};
3329
3330
  let events = allListeners === null || allListeners === void 0 ? void 0 : allListeners[eventType];
3330
3331
  if (events === undefined) {
3331
3332
  events = [];
3332
3333
  let obj = Object.getPrototypeOf(this);
3333
3334
  while (obj) {
3334
- const hierarchyEvents = (_c = (_b = obj.eventListeners) === null || _b === void 0 ? void 0 : _b[eventType]) !== null && _c !== void 0 ? _c : [];
3335
+ const hierarchyEvents = (_b = (_a = obj.eventListeners) === null || _a === void 0 ? void 0 : _a[eventType]) !== null && _b !== void 0 ? _b : [];
3335
3336
  events.push(...hierarchyEvents);
3336
3337
  obj = Object.getPrototypeOf(obj);
3337
3338
  }
3338
3339
  allListeners[eventType] = events;
3339
- this._cache.set(ALL_LISTENERS, allListeners);
3340
+ Node.protoListenerMap.set(nodeType, allListeners);
3340
3341
  }
3341
3342
  return events;
3342
3343
  }
@@ -3526,6 +3527,7 @@ js: import "konva/skia-backend";
3526
3527
  return no;
3527
3528
  }
3528
3529
  }
3530
+ Node.protoListenerMap = new Map();
3529
3531
  Node.prototype.nodeType = 'Node';
3530
3532
  Node.prototype._attrsAffectingSize = [];
3531
3533
  Node.prototype.eventListeners = {};
@@ -4983,7 +4985,15 @@ js: import "konva/skia-backend";
4983
4985
  stage = this.getStage();
4984
4986
  const bc = bufferCanvas || stage.bufferCanvas;
4985
4987
  const bufferContext = bc.getContext();
4986
- bufferContext.clear();
4988
+ if (bufferCanvas) {
4989
+ bufferContext.save();
4990
+ bufferContext.setTransform(1, 0, 0, 1, 0, 0);
4991
+ bufferContext.clearRect(0, 0, bc.width, bc.height);
4992
+ bufferContext.restore();
4993
+ }
4994
+ else {
4995
+ bufferContext.clear();
4996
+ }
4987
4997
  bufferContext.save();
4988
4998
  bufferContext._applyLineJoin(this);
4989
4999
  bufferContext._applyMiterLimit(this);
@@ -6276,6 +6286,35 @@ js: import "konva/skia-backend";
6276
6286
  }
6277
6287
  return allPoints;
6278
6288
  }
6289
+ function getBezierExtremaPoints(points) {
6290
+ const axisPoints = [
6291
+ [points[0], points[2], points[4], points[6]],
6292
+ [points[1], points[3], points[5], points[7]],
6293
+ ];
6294
+ const extremaTs = [];
6295
+ for (const axis of axisPoints) {
6296
+ const a = -3 * axis[0] + 9 * axis[1] - 9 * axis[2] + 3 * axis[3];
6297
+ if (a !== 0) {
6298
+ const b = 6 * axis[0] - 12 * axis[1] + 6 * axis[2];
6299
+ const c = -3 * axis[0] + 3 * axis[1];
6300
+ const discriminant = b * b - 4 * a * c;
6301
+ if (discriminant >= 0) {
6302
+ const d = Math.sqrt(discriminant);
6303
+ extremaTs.push((-b + d) / (2 * a));
6304
+ extremaTs.push((-b - d) / (2 * a));
6305
+ }
6306
+ }
6307
+ }
6308
+ return extremaTs
6309
+ .filter((t) => t > 0 && t < 1)
6310
+ .flatMap((t) => axisPoints.map((axis) => {
6311
+ const mt = 1 - t;
6312
+ return (mt * mt * mt * axis[0] +
6313
+ 3 * mt * mt * t * axis[1] +
6314
+ 3 * mt * t * t * axis[2] +
6315
+ t * t * t * axis[3]);
6316
+ }));
6317
+ }
6279
6318
  class Line extends Shape {
6280
6319
  constructor(config) {
6281
6320
  super(config);
@@ -6377,6 +6416,15 @@ js: import "konva/skia-backend";
6377
6416
  points[points.length - 1],
6378
6417
  ];
6379
6418
  }
6419
+ else if (this.bezier()) {
6420
+ points = [
6421
+ points[0],
6422
+ points[1],
6423
+ ...getBezierExtremaPoints(this.points()),
6424
+ points[points.length - 2],
6425
+ points[points.length - 1],
6426
+ ];
6427
+ }
6380
6428
  else {
6381
6429
  points = this.points();
6382
6430
  }
@@ -8666,7 +8714,7 @@ js: import "konva/skia-backend";
8666
8714
  if (!this.text()) {
8667
8715
  return;
8668
8716
  }
8669
- let padding = this.padding(), fontSize = this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, verticalAlign = this.verticalAlign(), direction = this.direction(), alignY = 0, align = this.align(), totalWidth = this.getWidth(), letterSpacing = this.letterSpacing(), charRenderFunc = this.charRenderFunc(), fill = this.fill(), textDecoration = this.textDecoration(), shouldUnderline = textDecoration.indexOf('underline') !== -1, shouldLineThrough = textDecoration.indexOf('line-through') !== -1, n;
8717
+ let padding = this.padding(), fontSize = this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, verticalAlign = this.verticalAlign(), direction = this.direction(), alignY = 0, align = this.align(), totalWidth = this.getWidth(), letterSpacing = this.letterSpacing(), charRenderFunc = this.charRenderFunc(), fill = this.fill(), textDecoration = this.textDecoration(), underlineOffset = this.underlineOffset(), shouldUnderline = textDecoration.indexOf('underline') !== -1, shouldLineThrough = textDecoration.indexOf('line-through') !== -1, n;
8670
8718
  direction = direction === INHERIT ? context.direction : direction;
8671
8719
  let translateY = lineHeightPx / 2;
8672
8720
  let baseline = MIDDLE;
@@ -8704,9 +8752,9 @@ js: import "konva/skia-backend";
8704
8752
  if (shouldUnderline) {
8705
8753
  context.save();
8706
8754
  context.beginPath();
8707
- const yOffset = !Konva$2.legacyTextRendering
8755
+ const yOffset = underlineOffset !== null && underlineOffset !== void 0 ? underlineOffset : (!Konva$2.legacyTextRendering
8708
8756
  ? Math.round(fontSize / 4)
8709
- : Math.round(fontSize / 2);
8757
+ : Math.round(fontSize / 2));
8710
8758
  const x = lineTranslateX;
8711
8759
  const y = translateY + lineTranslateY + yOffset;
8712
8760
  context.moveTo(x, y);
@@ -9025,6 +9073,7 @@ js: import "konva/skia-backend";
9025
9073
  Factory.addGetterSetter(Text, 'letterSpacing', 0, getNumberValidator());
9026
9074
  Factory.addGetterSetter(Text, 'text', '', getStringValidator());
9027
9075
  Factory.addGetterSetter(Text, 'textDecoration', '');
9076
+ Factory.addGetterSetter(Text, 'underlineOffset', undefined, getNumberValidator());
9028
9077
  Factory.addGetterSetter(Text, 'charRenderFunc', undefined);
9029
9078
 
9030
9079
  const EMPTY_STRING = '', NORMAL = 'normal';
@@ -9293,6 +9342,7 @@ js: import "konva/skia-backend";
9293
9342
  const ATTR_CHANGE_LIST = [
9294
9343
  'resizeEnabledChange',
9295
9344
  'rotateAnchorOffsetChange',
9345
+ 'rotateAnchorAngleChange',
9296
9346
  'rotateEnabledChange',
9297
9347
  'enabledAnchorsChange',
9298
9348
  'anchorSizeChange',
@@ -9690,11 +9740,38 @@ js: import "konva/skia-backend";
9690
9740
  sceneFunc(ctx, shape) {
9691
9741
  const tr = shape.getParent();
9692
9742
  const padding = tr.padding();
9743
+ const width = shape.width();
9744
+ const height = shape.height();
9693
9745
  ctx.beginPath();
9694
- ctx.rect(-padding, -padding, shape.width() + padding * 2, shape.height() + padding * 2);
9695
- ctx.moveTo(shape.width() / 2, -padding);
9746
+ ctx.rect(-padding, -padding, width + padding * 2, height + padding * 2);
9696
9747
  if (tr.rotateEnabled() && tr.rotateLineVisible()) {
9697
- ctx.lineTo(shape.width() / 2, -tr.rotateAnchorOffset() * Util._sign(shape.height()) - padding);
9748
+ const rotateAnchorAngle = tr.rotateAnchorAngle();
9749
+ const rotateAnchorOffset = tr.rotateAnchorOffset();
9750
+ const rad = Util.degToRad(rotateAnchorAngle);
9751
+ const dirX = Math.sin(rad);
9752
+ const dirY = -Math.cos(rad);
9753
+ const cx = width / 2;
9754
+ const cy = height / 2;
9755
+ let t = Infinity;
9756
+ if (dirY < 0) {
9757
+ t = Math.min(t, -cy / dirY);
9758
+ }
9759
+ else if (dirY > 0) {
9760
+ t = Math.min(t, (height - cy) / dirY);
9761
+ }
9762
+ if (dirX < 0) {
9763
+ t = Math.min(t, -cx / dirX);
9764
+ }
9765
+ else if (dirX > 0) {
9766
+ t = Math.min(t, (width - cx) / dirX);
9767
+ }
9768
+ const edgeX = cx + dirX * t;
9769
+ const edgeY = cy + dirY * t;
9770
+ const sign = Util._sign(height);
9771
+ const endX = edgeX + dirX * rotateAnchorOffset * sign;
9772
+ const endY = edgeY + dirY * rotateAnchorOffset * sign;
9773
+ ctx.moveTo(edgeX, edgeY);
9774
+ ctx.lineTo(endX, endY);
9698
9775
  }
9699
9776
  ctx.fillStrokeShape(shape);
9700
9777
  },
@@ -9776,7 +9853,8 @@ js: import "konva/skia-backend";
9776
9853
  const attrs = this._getNodeRect();
9777
9854
  x = anchorNode.x() - attrs.width / 2;
9778
9855
  y = -anchorNode.y() + attrs.height / 2;
9779
- let delta = Math.atan2(-y, x) + Math.PI / 2;
9856
+ const rotateAnchorAngleRad = Konva$2.getAngle(this.rotateAnchorAngle());
9857
+ let delta = Math.atan2(-y, x) + Math.PI / 2 - rotateAnchorAngleRad;
9780
9858
  if (attrs.height < 0) {
9781
9859
  delta -= Math.PI;
9782
9860
  }
@@ -10171,9 +10249,32 @@ js: import "konva/skia-backend";
10171
10249
  offsetY: anchorSize / 2 - padding,
10172
10250
  visible: resizeEnabled && enabledAnchors.indexOf('bottom-right') >= 0,
10173
10251
  });
10252
+ const rotateAnchorAngle = this.rotateAnchorAngle();
10253
+ const rotateAnchorOffset = this.rotateAnchorOffset();
10254
+ const rad = Util.degToRad(rotateAnchorAngle);
10255
+ const dirX = Math.sin(rad);
10256
+ const dirY = -Math.cos(rad);
10257
+ const cx = width / 2;
10258
+ const cy = height / 2;
10259
+ let t = Infinity;
10260
+ if (dirY < 0) {
10261
+ t = Math.min(t, -cy / dirY);
10262
+ }
10263
+ else if (dirY > 0) {
10264
+ t = Math.min(t, (height - cy) / dirY);
10265
+ }
10266
+ if (dirX < 0) {
10267
+ t = Math.min(t, -cx / dirX);
10268
+ }
10269
+ else if (dirX > 0) {
10270
+ t = Math.min(t, (width - cx) / dirX);
10271
+ }
10272
+ const edgeX = cx + dirX * t;
10273
+ const edgeY = cy + dirY * t;
10274
+ const sign = Util._sign(height);
10174
10275
  this._batchChangeChild('.rotater', {
10175
- x: width / 2,
10176
- y: -this.rotateAnchorOffset() * Util._sign(height) - padding,
10276
+ x: edgeX + dirX * rotateAnchorOffset * sign,
10277
+ y: edgeY + dirY * rotateAnchorOffset * sign - padding * dirY,
10177
10278
  visible: this.rotateEnabled(),
10178
10279
  });
10179
10280
  this._batchChangeChild('.back', {
@@ -10261,6 +10362,7 @@ js: import "konva/skia-backend";
10261
10362
  Factory.addGetterSetter(Transformer, 'rotateLineVisible', true);
10262
10363
  Factory.addGetterSetter(Transformer, 'rotationSnaps', []);
10263
10364
  Factory.addGetterSetter(Transformer, 'rotateAnchorOffset', 50, getNumberValidator());
10365
+ Factory.addGetterSetter(Transformer, 'rotateAnchorAngle', 0, getNumberValidator());
10264
10366
  Factory.addGetterSetter(Transformer, 'rotateAnchorCursor', 'crosshair');
10265
10367
  Factory.addGetterSetter(Transformer, 'rotationSnapTolerance', 5, getNumberValidator());
10266
10368
  Factory.addGetterSetter(Transformer, 'borderEnabled', true);