@inweb/markup 26.12.0 → 26.12.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 +119 -60
- package/dist/markup.js.map +1 -1
- package/dist/markup.min.js +1 -1
- package/dist/markup.module.js +12 -6
- package/dist/markup.module.js.map +1 -1
- package/lib/markup/Konva/KonvaMarkup.d.ts +2 -0
- package/package.json +3 -3
- package/src/markup/Konva/KonvaMarkup.ts +14 -6
package/dist/markup.js
CHANGED
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
: {};
|
|
43
43
|
const Konva$2 = {
|
|
44
44
|
_global: glob,
|
|
45
|
-
version: '10.0.
|
|
45
|
+
version: '10.0.12',
|
|
46
46
|
isBrowser: detectBrowser(),
|
|
47
47
|
isUnminified: /param/.test(function (param) { }.toString()),
|
|
48
48
|
dblClickWindow: 400,
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
document: glob.document,
|
|
85
85
|
_injectGlobal(Konva) {
|
|
86
86
|
if (typeof glob.Konva !== 'undefined') {
|
|
87
|
-
console.error('
|
|
87
|
+
console.error('Several Konva instances detected. It is not recommended to use multiple Konva instances in the same environment.');
|
|
88
88
|
}
|
|
89
89
|
glob.Konva = Konva;
|
|
90
90
|
},
|
|
@@ -259,7 +259,7 @@ js: import "konva/skia-backend";
|
|
|
259
259
|
return result;
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
|
-
const OBJECT_ARRAY = '[object Array]', OBJECT_NUMBER = '[object Number]', OBJECT_STRING = '[object String]', OBJECT_BOOLEAN = '[object Boolean]', PI_OVER_DEG180 = Math.PI / 180, DEG180_OVER_PI = 180 / Math.PI, HASH
|
|
262
|
+
const OBJECT_ARRAY = '[object Array]', OBJECT_NUMBER = '[object Number]', OBJECT_STRING = '[object String]', OBJECT_BOOLEAN = '[object Boolean]', PI_OVER_DEG180 = Math.PI / 180, DEG180_OVER_PI = 180 / Math.PI, HASH = '#', EMPTY_STRING$1 = '', ZERO = '0', KONVA_WARNING = 'Konva warning: ', KONVA_ERROR = 'Konva error: ', RGB_PAREN = 'rgb(', COLORS = {
|
|
263
263
|
aliceblue: [240, 248, 255],
|
|
264
264
|
antiquewhite: [250, 235, 215],
|
|
265
265
|
aqua: [0, 255, 255],
|
|
@@ -411,6 +411,7 @@ js: import "konva/skia-backend";
|
|
|
411
411
|
yellowgreen: [154, 205, 5],
|
|
412
412
|
}, RGB_REGEX = /rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/;
|
|
413
413
|
let animQueue = [];
|
|
414
|
+
let _isCanvasFarblingActive = null;
|
|
414
415
|
const req = (typeof requestAnimationFrame !== 'undefined' && requestAnimationFrame) ||
|
|
415
416
|
function (f) {
|
|
416
417
|
setTimeout(f, 60);
|
|
@@ -506,7 +507,7 @@ js: import "konva/skia-backend";
|
|
|
506
507
|
return ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
|
|
507
508
|
},
|
|
508
509
|
_hexToRgb(hex) {
|
|
509
|
-
hex = hex.replace(HASH
|
|
510
|
+
hex = hex.replace(HASH, EMPTY_STRING$1);
|
|
510
511
|
const bigint = parseInt(hex, 16);
|
|
511
512
|
return {
|
|
512
513
|
r: (bigint >> 16) & 255,
|
|
@@ -519,7 +520,58 @@ js: import "konva/skia-backend";
|
|
|
519
520
|
while (randColor.length < 6) {
|
|
520
521
|
randColor = ZERO + randColor;
|
|
521
522
|
}
|
|
522
|
-
return HASH
|
|
523
|
+
return HASH + randColor;
|
|
524
|
+
},
|
|
525
|
+
isCanvasFarblingActive() {
|
|
526
|
+
if (_isCanvasFarblingActive !== null) {
|
|
527
|
+
return _isCanvasFarblingActive;
|
|
528
|
+
}
|
|
529
|
+
if (typeof document === 'undefined') {
|
|
530
|
+
_isCanvasFarblingActive = false;
|
|
531
|
+
return false;
|
|
532
|
+
}
|
|
533
|
+
const c = this.createCanvasElement();
|
|
534
|
+
c.width = 10;
|
|
535
|
+
c.height = 10;
|
|
536
|
+
const ctx = c.getContext('2d', {
|
|
537
|
+
willReadFrequently: true,
|
|
538
|
+
});
|
|
539
|
+
ctx.clearRect(0, 0, 10, 10);
|
|
540
|
+
ctx.fillStyle = '#282828';
|
|
541
|
+
ctx.fillRect(0, 0, 10, 10);
|
|
542
|
+
const d = ctx.getImageData(0, 0, 10, 10).data;
|
|
543
|
+
let isFarbling = false;
|
|
544
|
+
for (let i = 0; i < 100; i++) {
|
|
545
|
+
if (d[i * 4] !== 40 ||
|
|
546
|
+
d[i * 4 + 1] !== 40 ||
|
|
547
|
+
d[i * 4 + 2] !== 40 ||
|
|
548
|
+
d[i * 4 + 3] !== 255) {
|
|
549
|
+
isFarbling = true;
|
|
550
|
+
break;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
_isCanvasFarblingActive = isFarbling;
|
|
554
|
+
this.releaseCanvas(c);
|
|
555
|
+
return _isCanvasFarblingActive;
|
|
556
|
+
},
|
|
557
|
+
getHitColor() {
|
|
558
|
+
const color = this.getRandomColor();
|
|
559
|
+
return this.isCanvasFarblingActive()
|
|
560
|
+
? this.getSnappedHexColor(color)
|
|
561
|
+
: color;
|
|
562
|
+
},
|
|
563
|
+
getHitColorKey(r, g, b) {
|
|
564
|
+
if (this.isCanvasFarblingActive()) {
|
|
565
|
+
r = Math.round(r / 5) * 5;
|
|
566
|
+
g = Math.round(g / 5) * 5;
|
|
567
|
+
b = Math.round(b / 5) * 5;
|
|
568
|
+
}
|
|
569
|
+
return HASH + this._rgbToHex(r, g, b);
|
|
570
|
+
},
|
|
571
|
+
getSnappedHexColor(hex) {
|
|
572
|
+
const rgb = this._hexToRgb(hex);
|
|
573
|
+
return (HASH +
|
|
574
|
+
this._rgbToHex(Math.round(rgb.r / 5) * 5, Math.round(rgb.g / 5) * 5, Math.round(rgb.b / 5) * 5));
|
|
523
575
|
},
|
|
524
576
|
getRGB(color) {
|
|
525
577
|
let rgb;
|
|
@@ -531,7 +583,7 @@ js: import "konva/skia-backend";
|
|
|
531
583
|
b: rgb[2],
|
|
532
584
|
};
|
|
533
585
|
}
|
|
534
|
-
else if (color[0] === HASH
|
|
586
|
+
else if (color[0] === HASH) {
|
|
535
587
|
return this._hexToRgb(color.substring(1));
|
|
536
588
|
}
|
|
537
589
|
else if (color.substr(0, 4) === RGB_PAREN) {
|
|
@@ -1615,42 +1667,12 @@ js: import "konva/skia-backend";
|
|
|
1615
1667
|
this.setSize(config.width, config.height);
|
|
1616
1668
|
}
|
|
1617
1669
|
}
|
|
1618
|
-
function isCanvasFarblingActive() {
|
|
1619
|
-
const c = Util.createCanvasElement();
|
|
1620
|
-
c.width = 1;
|
|
1621
|
-
c.height = 1;
|
|
1622
|
-
const ctx = c.getContext('2d', {
|
|
1623
|
-
willReadFrequently: true,
|
|
1624
|
-
});
|
|
1625
|
-
ctx.clearRect(0, 0, 1, 1);
|
|
1626
|
-
ctx.fillStyle = 'rgba(255,0,255,1)';
|
|
1627
|
-
ctx.fillRect(0, 0, 1, 1);
|
|
1628
|
-
const d = ctx.getImageData(0, 0, 1, 1).data;
|
|
1629
|
-
const exact = d[0] === 255 && d[1] === 0 && d[2] === 255 && d[3] === 255;
|
|
1630
|
-
return !exact;
|
|
1631
|
-
}
|
|
1632
|
-
function isBraveBrowser() {
|
|
1633
|
-
var _a, _b;
|
|
1634
|
-
if (typeof navigator === 'undefined') {
|
|
1635
|
-
return false;
|
|
1636
|
-
}
|
|
1637
|
-
return (_b = (_a = navigator.brave) === null || _a === void 0 ? void 0 : _a.isBrave()) !== null && _b !== void 0 ? _b : false;
|
|
1638
|
-
}
|
|
1639
|
-
let warned = false;
|
|
1640
|
-
function checkHitCanvasSupport() {
|
|
1641
|
-
if (isBraveBrowser() && isCanvasFarblingActive() && !warned) {
|
|
1642
|
-
warned = true;
|
|
1643
|
-
Util.error('Looks like you have "Brave shield" enabled in your browser. It breaks KonvaJS internals. Please disable it. You may need to ask your users to do the same.');
|
|
1644
|
-
}
|
|
1645
|
-
return isBraveBrowser() && isCanvasFarblingActive();
|
|
1646
|
-
}
|
|
1647
1670
|
class HitCanvas extends Canvas {
|
|
1648
1671
|
constructor(config = { width: 0, height: 0 }) {
|
|
1649
1672
|
super(config);
|
|
1650
1673
|
this.hitCanvas = true;
|
|
1651
1674
|
this.context = new HitContext(this);
|
|
1652
1675
|
this.setSize(config.width, config.height);
|
|
1653
|
-
checkHitCanvasSupport();
|
|
1654
1676
|
}
|
|
1655
1677
|
}
|
|
1656
1678
|
|
|
@@ -2506,7 +2528,7 @@ js: import "konva/skia-backend";
|
|
|
2506
2528
|
return ancestors;
|
|
2507
2529
|
}
|
|
2508
2530
|
getAttrs() {
|
|
2509
|
-
return
|
|
2531
|
+
return this.attrs || {};
|
|
2510
2532
|
}
|
|
2511
2533
|
setAttrs(config) {
|
|
2512
2534
|
this._batchTransformChanges(() => {
|
|
@@ -4679,11 +4701,18 @@ js: import "konva/skia-backend";
|
|
|
4679
4701
|
constructor(config) {
|
|
4680
4702
|
super(config);
|
|
4681
4703
|
let key;
|
|
4704
|
+
let attempts = 0;
|
|
4682
4705
|
while (true) {
|
|
4683
|
-
key = Util.
|
|
4706
|
+
key = Util.getHitColor();
|
|
4684
4707
|
if (key && !(key in shapes)) {
|
|
4685
4708
|
break;
|
|
4686
4709
|
}
|
|
4710
|
+
attempts++;
|
|
4711
|
+
if (attempts >= 10000) {
|
|
4712
|
+
Util.warn('Failed to find a unique color key for a shape. Konva may work incorrectly. Most likely your browser is using canvas farbling. Consider disabling it.');
|
|
4713
|
+
key = Util.getRandomColor();
|
|
4714
|
+
break;
|
|
4715
|
+
}
|
|
4687
4716
|
}
|
|
4688
4717
|
this.colorKey = key;
|
|
4689
4718
|
shapes[key] = this;
|
|
@@ -4966,8 +4995,10 @@ js: import "konva/skia-backend";
|
|
|
4966
4995
|
if (hasShadow) {
|
|
4967
4996
|
context._applyShadow(this);
|
|
4968
4997
|
}
|
|
4969
|
-
|
|
4970
|
-
|
|
4998
|
+
if (!cachingSelf) {
|
|
4999
|
+
context._applyOpacity(this);
|
|
5000
|
+
context._applyGlobalCompositeOperation(this);
|
|
5001
|
+
}
|
|
4971
5002
|
context.drawImage(bc._canvas, bc.x || 0, bc.y || 0, bc.width / ratio, bc.height / ratio);
|
|
4972
5003
|
}
|
|
4973
5004
|
else {
|
|
@@ -5161,7 +5192,7 @@ js: import "konva/skia-backend";
|
|
|
5161
5192
|
setDrawHitFunc: 'setHitFunc',
|
|
5162
5193
|
});
|
|
5163
5194
|
|
|
5164
|
-
const
|
|
5195
|
+
const BEFORE_DRAW = 'beforeDraw', DRAW = 'draw', INTERSECTION_OFFSETS = [
|
|
5165
5196
|
{ x: 0, y: 0 },
|
|
5166
5197
|
{ x: -1, y: -1 },
|
|
5167
5198
|
{ x: 1, y: -1 },
|
|
@@ -5379,8 +5410,8 @@ js: import "konva/skia-backend";
|
|
|
5379
5410
|
const p = this.hitCanvas.context.getImageData(Math.round(pos.x * ratio), Math.round(pos.y * ratio), 1, 1).data;
|
|
5380
5411
|
const p3 = p[3];
|
|
5381
5412
|
if (p3 === 255) {
|
|
5382
|
-
const colorKey = Util.
|
|
5383
|
-
const shape = shapes[
|
|
5413
|
+
const colorKey = Util.getHitColorKey(p[0], p[1], p[2]);
|
|
5414
|
+
const shape = shapes[colorKey];
|
|
5384
5415
|
if (shape) {
|
|
5385
5416
|
return {
|
|
5386
5417
|
shape: shape,
|
|
@@ -8085,12 +8116,12 @@ js: import "konva/skia-backend";
|
|
|
8085
8116
|
context.fillStrokeShape(this);
|
|
8086
8117
|
}
|
|
8087
8118
|
getWidth() {
|
|
8088
|
-
var _a, _b;
|
|
8089
|
-
return (_a = this.attrs.width) !== null && _a !== void 0 ? _a : (_b = this.image()) === null || _b === void 0 ? void 0 : _b.width;
|
|
8119
|
+
var _a, _b, _c;
|
|
8120
|
+
return (_c = (_a = this.attrs.width) !== null && _a !== void 0 ? _a : (_b = this.image()) === null || _b === void 0 ? void 0 : _b.width) !== null && _c !== void 0 ? _c : 0;
|
|
8090
8121
|
}
|
|
8091
8122
|
getHeight() {
|
|
8092
|
-
var _a, _b;
|
|
8093
|
-
return (_a = this.attrs.height) !== null && _a !== void 0 ? _a : (_b = this.image()) === null || _b === void 0 ? void 0 : _b.height;
|
|
8123
|
+
var _a, _b, _c;
|
|
8124
|
+
return (_c = (_a = this.attrs.height) !== null && _a !== void 0 ? _a : (_b = this.image()) === null || _b === void 0 ? void 0 : _b.height) !== null && _c !== void 0 ? _c : 0;
|
|
8094
8125
|
}
|
|
8095
8126
|
static fromURL(url, callback, onError = null) {
|
|
8096
8127
|
const img = Util.createImageElement();
|
|
@@ -8106,6 +8137,7 @@ js: import "konva/skia-backend";
|
|
|
8106
8137
|
}
|
|
8107
8138
|
};
|
|
8108
8139
|
Image$1.prototype.className = 'Image';
|
|
8140
|
+
Image$1.prototype._attrsAffectingSize = ['image'];
|
|
8109
8141
|
_registerNode(Image$1);
|
|
8110
8142
|
Factory.addGetterSetter(Image$1, 'cornerRadius', 0, getNumberOrArrayOfNumbersValidator(4));
|
|
8111
8143
|
Factory.addGetterSetter(Image$1, 'image');
|
|
@@ -8333,8 +8365,8 @@ js: import "konva/skia-backend";
|
|
|
8333
8365
|
getSelfRect() {
|
|
8334
8366
|
const points = this._getPoints();
|
|
8335
8367
|
let minX = points[0].x;
|
|
8336
|
-
let maxX = points[0].
|
|
8337
|
-
let minY = points[0].
|
|
8368
|
+
let maxX = points[0].x;
|
|
8369
|
+
let minY = points[0].y;
|
|
8338
8370
|
let maxY = points[0].y;
|
|
8339
8371
|
points.forEach((point) => {
|
|
8340
8372
|
minX = Math.min(minX, point.x);
|
|
@@ -8686,6 +8718,7 @@ js: import "konva/skia-backend";
|
|
|
8686
8718
|
context.stroke();
|
|
8687
8719
|
context.restore();
|
|
8688
8720
|
}
|
|
8721
|
+
const lineThroughStartX = lineTranslateX;
|
|
8689
8722
|
if (direction !== RTL &&
|
|
8690
8723
|
(letterSpacing !== 0 || align === JUSTIFY || charRenderFunc)) {
|
|
8691
8724
|
const spacesNumber = text.split(' ').length - 1;
|
|
@@ -8737,7 +8770,7 @@ js: import "konva/skia-backend";
|
|
|
8737
8770
|
const yOffset = !Konva$2.legacyTextRendering
|
|
8738
8771
|
? -Math.round(fontSize / 4)
|
|
8739
8772
|
: 0;
|
|
8740
|
-
const x =
|
|
8773
|
+
const x = lineThroughStartX;
|
|
8741
8774
|
context.moveTo(x, translateY + lineTranslateY + yOffset);
|
|
8742
8775
|
const lineWidth = align === JUSTIFY && !lastLine ? totalWidth - padding * 2 : width;
|
|
8743
8776
|
context.lineTo(x + Math.round(lineWidth), translateY + lineTranslateY + yOffset);
|
|
@@ -9040,7 +9073,9 @@ js: import "konva/skia-backend";
|
|
|
9040
9073
|
const fill = this.fill();
|
|
9041
9074
|
const fontSize = this.fontSize();
|
|
9042
9075
|
const glyphInfo = this.glyphInfo;
|
|
9043
|
-
|
|
9076
|
+
const hasUnderline = textDecoration.indexOf('underline') !== -1;
|
|
9077
|
+
const hasLineThrough = textDecoration.indexOf('line-through') !== -1;
|
|
9078
|
+
if (hasUnderline) {
|
|
9044
9079
|
context.beginPath();
|
|
9045
9080
|
}
|
|
9046
9081
|
for (let i = 0; i < glyphInfo.length; i++) {
|
|
@@ -9050,15 +9085,32 @@ js: import "konva/skia-backend";
|
|
|
9050
9085
|
context.rotate(glyphInfo[i].rotation);
|
|
9051
9086
|
this.partialText = glyphInfo[i].text;
|
|
9052
9087
|
context.fillStrokeShape(this);
|
|
9053
|
-
if (
|
|
9088
|
+
if (hasUnderline) {
|
|
9054
9089
|
if (i === 0) {
|
|
9055
9090
|
context.moveTo(0, fontSize / 2 + 1);
|
|
9056
9091
|
}
|
|
9057
|
-
context.lineTo(
|
|
9092
|
+
context.lineTo(glyphInfo[i].width, fontSize / 2 + 1);
|
|
9058
9093
|
}
|
|
9059
9094
|
context.restore();
|
|
9060
9095
|
}
|
|
9061
|
-
if (
|
|
9096
|
+
if (hasUnderline) {
|
|
9097
|
+
context.strokeStyle = fill;
|
|
9098
|
+
context.lineWidth = fontSize / 20;
|
|
9099
|
+
context.stroke();
|
|
9100
|
+
}
|
|
9101
|
+
if (hasLineThrough) {
|
|
9102
|
+
context.beginPath();
|
|
9103
|
+
for (let i = 0; i < glyphInfo.length; i++) {
|
|
9104
|
+
context.save();
|
|
9105
|
+
const p0 = glyphInfo[i].p0;
|
|
9106
|
+
context.translate(p0.x, p0.y);
|
|
9107
|
+
context.rotate(glyphInfo[i].rotation);
|
|
9108
|
+
if (i === 0) {
|
|
9109
|
+
context.moveTo(0, 0);
|
|
9110
|
+
}
|
|
9111
|
+
context.lineTo(glyphInfo[i].width, 0);
|
|
9112
|
+
context.restore();
|
|
9113
|
+
}
|
|
9062
9114
|
context.strokeStyle = fill;
|
|
9063
9115
|
context.lineWidth = fontSize / 20;
|
|
9064
9116
|
context.stroke();
|
|
@@ -9171,6 +9223,7 @@ js: import "konva/skia-backend";
|
|
|
9171
9223
|
rotation: rotation,
|
|
9172
9224
|
p0: charStartPoint,
|
|
9173
9225
|
p1: charEndPoint,
|
|
9226
|
+
width: width,
|
|
9174
9227
|
});
|
|
9175
9228
|
offsetToGlyph += glyphWidth;
|
|
9176
9229
|
}
|
|
@@ -12667,14 +12720,13 @@ js: import "konva/skia-backend";
|
|
|
12667
12720
|
});
|
|
12668
12721
|
};
|
|
12669
12722
|
this.pan = () => {
|
|
12670
|
-
this.
|
|
12671
|
-
markupObject.updateScreenCoordinates();
|
|
12672
|
-
});
|
|
12723
|
+
this.updateScreenCoordinatesForAll();
|
|
12673
12724
|
};
|
|
12674
12725
|
this.zoomAt = () => {
|
|
12675
|
-
this.
|
|
12676
|
-
|
|
12677
|
-
|
|
12726
|
+
this.updateScreenCoordinatesForAll();
|
|
12727
|
+
};
|
|
12728
|
+
this.changeCameraMode = () => {
|
|
12729
|
+
this.clearOverlay();
|
|
12678
12730
|
};
|
|
12679
12731
|
this.redirectToViewer = (event) => {
|
|
12680
12732
|
if (this._viewer)
|
|
@@ -12708,11 +12760,13 @@ js: import "konva/skia-backend";
|
|
|
12708
12760
|
this._viewer.addEventListener("changeactivedragger", this.changeActiveDragger);
|
|
12709
12761
|
this._viewer.addEventListener("pan", this.pan);
|
|
12710
12762
|
this._viewer.addEventListener("zoomat", this.zoomAt);
|
|
12763
|
+
this._viewer.addEventListener("changecameramode", this.changeCameraMode);
|
|
12711
12764
|
}
|
|
12712
12765
|
}
|
|
12713
12766
|
dispose() {
|
|
12714
12767
|
var _a, _b;
|
|
12715
12768
|
if (this._viewer) {
|
|
12769
|
+
this._viewer.removeEventListener("changecameramode", this.changeCameraMode);
|
|
12716
12770
|
this._viewer.removeEventListener("zoomat", this.zoomAt);
|
|
12717
12771
|
this._viewer.removeEventListener("pan", this.pan);
|
|
12718
12772
|
this._viewer.removeEventListener("changeactivedragger", this.changeActiveDragger);
|
|
@@ -12887,6 +12941,11 @@ js: import "konva/skia-backend";
|
|
|
12887
12941
|
ref.parent === this._groupGeometry ||
|
|
12888
12942
|
ref.parent === this._groupTexts);
|
|
12889
12943
|
}
|
|
12944
|
+
updateScreenCoordinatesForAll() {
|
|
12945
|
+
this.getObjects().forEach((markupObject) => {
|
|
12946
|
+
markupObject.updateScreenCoordinates();
|
|
12947
|
+
});
|
|
12948
|
+
}
|
|
12890
12949
|
initializeKonva() {
|
|
12891
12950
|
const stage = new Konva.Stage({
|
|
12892
12951
|
container: this._markupContainer,
|