fabric 6.0.0-beta13 → 6.0.0-beta14
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/.eslintrc.js +9 -0
- package/CHANGELOG.md +30 -1
- package/CONTRIBUTING.md +9 -9
- package/dist/fabric.d.ts +3 -3
- package/dist/index.js +234 -302
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.mjs +231 -302
- package/dist/index.mjs.map +1 -1
- package/dist/index.node.cjs +234 -302
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +231 -302
- package/dist/index.node.mjs.map +1 -1
- package/dist/src/Intersection.d.ts +8 -0
- package/dist/src/canvas/Canvas.d.ts +1 -1
- package/dist/src/canvas/CanvasOptions.d.ts +1 -1
- package/dist/src/canvas/DOMManagers/CanvasDOMManager.d.ts +1 -1
- package/dist/src/canvas/DOMManagers/StaticCanvasDOMManager.d.ts +2 -2
- package/dist/src/canvas/SelectableCanvas.d.ts +10 -15
- package/dist/src/canvas/StaticCanvas.d.ts +2 -2
- package/dist/src/controls/Control.d.ts +8 -8
- package/dist/src/controls/index.d.ts +1 -1
- package/dist/src/controls/polyControl.d.ts +25 -0
- package/dist/src/filters/BlendImage.d.ts +4 -4
- package/dist/src/shapes/Group.d.ts +5 -1
- package/dist/src/shapes/IText/ITextBehavior.d.ts +2 -2
- package/dist/src/shapes/Image.d.ts +19 -11
- package/dist/src/shapes/Object/FabricObject.d.ts +8 -0
- package/dist/src/shapes/Object/InteractiveObject.d.ts +2 -3
- package/dist/src/shapes/Object/Object.d.ts +4 -4
- package/dist/src/shapes/Object/ObjectGeometry.d.ts +3 -29
- package/dist/src/shapes/Object/types/FabricObjectProps.d.ts +1 -1
- package/dist/src/shapes/Path.d.ts +1 -1
- package/dist/src/shapes/Text/StyledText.d.ts +2 -2
- package/dist/src/shapes/Text/Text.d.ts +15 -7
- package/dist/src/shapes/Text/TextSVGExportMixin.d.ts +7 -7
- package/dist/src/shapes/Text/constants.d.ts +2 -2
- package/dist/src/util/animation/AnimationRegistry.d.ts +4 -4
- package/dist/src/util/internals/console.d.ts +8 -0
- package/dist/src/util/misc/dom.d.ts +1 -1
- package/dist/src/util/misc/svgParsing.d.ts +2 -1
- package/dist/src/util/typeAssertions.d.ts +2 -2
- package/fabric.ts +7 -3
- package/jest.extend.ts +3 -1
- package/package.json +5 -6
- package/playwright.setup.ts +82 -14
- package/src/ClassRegistry.ts +3 -1
- package/src/Collection.ts +2 -3
- package/src/Intersection.spec.ts +74 -0
- package/src/Intersection.ts +30 -0
- package/src/Pattern/Pattern.ts +2 -1
- package/src/benchmarks/README.md +7 -0
- package/src/benchmarks/calcCornerCoords.mjs +117 -0
- package/src/benchmarks/raycasting.mjs +154 -0
- package/src/canvas/Canvas.ts +23 -11
- package/src/canvas/CanvasOptions.ts +1 -1
- package/src/canvas/DOMManagers/CanvasDOMManager.ts +1 -1
- package/src/canvas/DOMManagers/StaticCanvasDOMManager.ts +7 -7
- package/src/canvas/SelectableCanvas.ts +30 -43
- package/src/canvas/StaticCanvas.ts +9 -7
- package/src/canvas/__tests__/SelectableCanvas.spec.ts +60 -0
- package/src/canvas/__tests__/__snapshots__/eventData.test.ts.snap +193 -2
- package/src/canvas/__tests__/eventData.test.ts +40 -1
- package/src/controls/Control.spec.ts +41 -0
- package/src/controls/Control.ts +36 -44
- package/src/controls/index.ts +1 -1
- package/src/controls/polyControl.ts +8 -5
- package/src/filters/BaseFilter.ts +8 -6
- package/src/filters/BlendImage.ts +4 -4
- package/src/filters/GLProbes/WebGLProbe.ts +2 -1
- package/src/parser/elements_parser.ts +2 -2
- package/src/parser/parseSVGDocument.ts +2 -1
- package/src/shapes/ActiveSelection.spec.ts +35 -1
- package/src/shapes/ActiveSelection.ts +3 -1
- package/src/shapes/Group.ts +7 -8
- package/src/shapes/IText/IText.test.ts +43 -0
- package/src/shapes/IText/IText.ts +1 -1
- package/src/shapes/IText/ITextBehavior.ts +2 -2
- package/src/shapes/IText/__snapshots__/IText.test.ts.snap +50 -0
- package/src/shapes/Image.ts +23 -14
- package/src/shapes/Object/FabricObject.spec.ts +16 -0
- package/src/shapes/Object/FabricObject.ts +8 -0
- package/src/shapes/Object/InteractiveObject.spec.ts +43 -0
- package/src/shapes/Object/InteractiveObject.ts +20 -30
- package/src/shapes/Object/Object.ts +6 -5
- package/src/shapes/Object/ObjectGeometry.ts +11 -126
- package/src/shapes/Object/types/FabricObjectProps.ts +1 -1
- package/src/shapes/Text/StyledText.ts +5 -2
- package/src/shapes/Text/Text.spec.ts +9 -9
- package/src/shapes/Text/Text.ts +24 -15
- package/src/shapes/Text/TextSVGExportMixin.spec.ts +29 -0
- package/src/shapes/Text/TextSVGExportMixin.ts +16 -13
- package/src/shapes/Text/__snapshots__/Text.spec.ts.snap +6 -6
- package/src/shapes/Text/constants.ts +2 -2
- package/src/util/animation/AnimationRegistry.ts +7 -6
- package/src/util/internals/console.ts +18 -0
- package/src/util/internals/dom_request.ts +2 -1
- package/src/util/misc/dom.ts +3 -2
- package/src/util/misc/objectEnlive.ts +3 -2
- package/src/util/misc/planeChange.ts +3 -2
- package/src/util/misc/svgParsing.ts +22 -9
- package/src/util/transform_matrix_removal.ts +3 -3
- package/src/util/typeAssertions.ts +2 -2
- package/typedoc.config.json +6 -0
- package/typedoc.json +3 -2
package/dist/index.node.cjs
CHANGED
|
@@ -245,6 +245,26 @@ class NodeGLProbe extends GLProbe {
|
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
247
|
|
|
248
|
+
const log = function (severity) {
|
|
249
|
+
for (var _len = arguments.length, optionalParams = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
250
|
+
optionalParams[_key - 1] = arguments[_key];
|
|
251
|
+
}
|
|
252
|
+
return (
|
|
253
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
254
|
+
console[severity]('fabric', ...optionalParams)
|
|
255
|
+
);
|
|
256
|
+
};
|
|
257
|
+
class FabricError extends Error {
|
|
258
|
+
constructor(message, options) {
|
|
259
|
+
super("fabric: ".concat(message), options);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
class SignalAbortedError extends FabricError {
|
|
263
|
+
constructor(context) {
|
|
264
|
+
super("".concat(context, " 'options.signal' is in 'aborted' state"));
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
248
268
|
/**
|
|
249
269
|
* Lazy initialize WebGL constants
|
|
250
270
|
*/
|
|
@@ -274,7 +294,7 @@ class WebGLProbe extends GLProbe {
|
|
|
274
294
|
if (gl) {
|
|
275
295
|
this.maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE);
|
|
276
296
|
this.GLPrecision = ['highp', 'mediump', 'lowp'].find(precision => this.testPrecision(gl, precision));
|
|
277
|
-
|
|
297
|
+
log('log', "WebGL: max texture size ".concat(this.maxTextureSize));
|
|
278
298
|
}
|
|
279
299
|
}
|
|
280
300
|
isSupported(textureSize) {
|
|
@@ -455,7 +475,7 @@ class Cache {
|
|
|
455
475
|
}
|
|
456
476
|
const cache = new Cache();
|
|
457
477
|
|
|
458
|
-
var version = "6.0.0-
|
|
478
|
+
var version = "6.0.0-beta14";
|
|
459
479
|
|
|
460
480
|
// use this syntax so babel plugin see this import here
|
|
461
481
|
const VERSION = version;
|
|
@@ -503,7 +523,7 @@ class ClassRegistry {
|
|
|
503
523
|
getClass(classType) {
|
|
504
524
|
const constructor = this[JSON$1].get(classType);
|
|
505
525
|
if (!constructor) {
|
|
506
|
-
throw new
|
|
526
|
+
throw new FabricError("No class registered for ".concat(classType));
|
|
507
527
|
}
|
|
508
528
|
return constructor;
|
|
509
529
|
}
|
|
@@ -549,8 +569,8 @@ class AnimationRegistry extends Array {
|
|
|
549
569
|
}
|
|
550
570
|
|
|
551
571
|
/**
|
|
552
|
-
* Cancel all running animations attached to a
|
|
553
|
-
* @param {
|
|
572
|
+
* Cancel all running animations attached to a canvas on the next frame
|
|
573
|
+
* @param {StaticCanvas} canvas
|
|
554
574
|
*/
|
|
555
575
|
cancelByCanvas(canvas) {
|
|
556
576
|
if (!canvas) {
|
|
@@ -558,7 +578,7 @@ class AnimationRegistry extends Array {
|
|
|
558
578
|
}
|
|
559
579
|
const animations = this.filter(animation => {
|
|
560
580
|
var _animation$target;
|
|
561
|
-
return typeof animation.target === 'object' && ((_animation$target = animation.target) === null || _animation$target === void 0 ? void 0 : _animation$target.canvas) === canvas;
|
|
581
|
+
return animation.target === canvas || typeof animation.target === 'object' && ((_animation$target = animation.target) === null || _animation$target === void 0 ? void 0 : _animation$target.canvas) === canvas;
|
|
562
582
|
});
|
|
563
583
|
animations.forEach(animation => animation.abort());
|
|
564
584
|
return animations;
|
|
@@ -1495,7 +1515,7 @@ function createCollectionMixin(Base) {
|
|
|
1495
1515
|
// we iterate reverse order to collect top first in case of click.
|
|
1496
1516
|
for (let i = this._objects.length - 1; i >= 0; i--) {
|
|
1497
1517
|
const object = this._objects[i];
|
|
1498
|
-
if (object.selectable && object.visible && (includeIntersecting && object.intersectsWithRect(tl, br, true) || object.isContainedWithinRect(tl, br, true) || includeIntersecting && object.containsPoint(tl,
|
|
1518
|
+
if (object.selectable && object.visible && (includeIntersecting && object.intersectsWithRect(tl, br, true) || object.isContainedWithinRect(tl, br, true) || includeIntersecting && object.containsPoint(tl, true) || includeIntersecting && object.containsPoint(br, true))) {
|
|
1499
1519
|
objects.push(object);
|
|
1500
1520
|
}
|
|
1501
1521
|
}
|
|
@@ -1585,7 +1605,7 @@ const uid = () => id++;
|
|
|
1585
1605
|
const createCanvasElement = () => {
|
|
1586
1606
|
const element = getFabricDocument().createElement('canvas');
|
|
1587
1607
|
if (!element || typeof element.getContext === 'undefined') {
|
|
1588
|
-
throw new
|
|
1608
|
+
throw new FabricError('Failed to create `canvas` element');
|
|
1589
1609
|
}
|
|
1590
1610
|
return element;
|
|
1591
1611
|
};
|
|
@@ -1873,7 +1893,7 @@ const loadImage = function (url) {
|
|
|
1873
1893
|
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1874
1894
|
return new Promise(function (resolve, reject) {
|
|
1875
1895
|
if (signal && signal.aborted) {
|
|
1876
|
-
return reject(new
|
|
1896
|
+
return reject(new SignalAbortedError('loadImage'));
|
|
1877
1897
|
}
|
|
1878
1898
|
const img = createImage();
|
|
1879
1899
|
let abort;
|
|
@@ -1898,7 +1918,7 @@ const loadImage = function (url) {
|
|
|
1898
1918
|
img.onload = done;
|
|
1899
1919
|
img.onerror = function () {
|
|
1900
1920
|
abort && (signal === null || signal === void 0 ? void 0 : signal.removeEventListener('abort', abort));
|
|
1901
|
-
reject(new
|
|
1921
|
+
reject(new FabricError("Error loading ".concat(img.src)));
|
|
1902
1922
|
};
|
|
1903
1923
|
crossOrigin && (img.crossOrigin = crossOrigin);
|
|
1904
1924
|
img.src = url;
|
|
@@ -2756,22 +2776,29 @@ const matrixToSVG = transform => 'matrix(' + transform.map(value => toFixed(valu
|
|
|
2756
2776
|
* we work around it by "moving" alpha channel into opacity attribute and setting fill's alpha to 1
|
|
2757
2777
|
* @param prop
|
|
2758
2778
|
* @param value
|
|
2779
|
+
* @param {boolean} inlineStyle The default is inline style, the separator used is ":", The other is "="
|
|
2759
2780
|
* @returns
|
|
2760
2781
|
*/
|
|
2761
|
-
const colorPropToSVG = (prop, value)
|
|
2782
|
+
const colorPropToSVG = function (prop, value) {
|
|
2783
|
+
let inlineStyle = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
2784
|
+
let colorValue;
|
|
2785
|
+
let opacityValue;
|
|
2762
2786
|
if (!value) {
|
|
2763
|
-
|
|
2787
|
+
colorValue = 'none';
|
|
2764
2788
|
} else if (value.toLive) {
|
|
2765
|
-
|
|
2789
|
+
colorValue = "url(#SVGID_".concat(value.id, ")");
|
|
2766
2790
|
} else {
|
|
2767
2791
|
const color = new Color(value),
|
|
2768
2792
|
opacity = color.getAlpha();
|
|
2769
|
-
|
|
2793
|
+
colorValue = color.toRgb();
|
|
2770
2794
|
if (opacity !== 1) {
|
|
2771
|
-
|
|
2772
|
-
str += "".concat(prop, "-opacity: ").concat(opacity.toString(), "; ");
|
|
2795
|
+
opacityValue = opacity.toString();
|
|
2773
2796
|
}
|
|
2774
|
-
|
|
2797
|
+
}
|
|
2798
|
+
if (inlineStyle) {
|
|
2799
|
+
return "".concat(prop, ": ").concat(colorValue, "; ").concat(opacityValue ? "".concat(prop, "-opacity: ").concat(opacityValue, "; ") : '');
|
|
2800
|
+
} else {
|
|
2801
|
+
return "".concat(prop, "=\"").concat(colorValue, "\" ").concat(opacityValue ? "".concat(prop, "-opacity=\"").concat(opacityValue, "\" ") : '');
|
|
2775
2802
|
}
|
|
2776
2803
|
};
|
|
2777
2804
|
const createSVGRect = function (color, _ref) {
|
|
@@ -2782,7 +2809,7 @@ const createSVGRect = function (color, _ref) {
|
|
|
2782
2809
|
height
|
|
2783
2810
|
} = _ref;
|
|
2784
2811
|
let precision = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : config.NUM_FRACTION_DIGITS;
|
|
2785
|
-
const svgColor = colorPropToSVG('fill', color);
|
|
2812
|
+
const svgColor = colorPropToSVG('fill', color, false);
|
|
2786
2813
|
const [x, y, w, h] = [left, top, width, height].map(value => toFixed(value, precision));
|
|
2787
2814
|
return "<rect ".concat(svgColor, " x=\"").concat(x, "\" y=\"").concat(y, "\" width=\"").concat(w, "\" height=\"").concat(h, "\"></rect>");
|
|
2788
2815
|
};
|
|
@@ -2994,13 +3021,10 @@ class StaticCanvasDOMManager {
|
|
|
2994
3021
|
}
|
|
2995
3022
|
createLowerCanvas(arg0) {
|
|
2996
3023
|
// canvasEl === 'HTMLCanvasElement' does not work on jsdom/node
|
|
2997
|
-
const el = isHTMLCanvas(arg0) ? arg0 : getFabricDocument().getElementById(arg0) || createCanvasElement();
|
|
3024
|
+
const el = isHTMLCanvas(arg0) ? arg0 : arg0 && getFabricDocument().getElementById(arg0) || createCanvasElement();
|
|
2998
3025
|
if (el.hasAttribute('data-fabric')) {
|
|
2999
|
-
|
|
3000
|
-
throw new Error('fabric.js: trying to initialize a canvas that has already been initialized');
|
|
3001
|
-
/* _DEV_MODE_END_ */
|
|
3026
|
+
throw new FabricError('Trying to initialize a canvas that has already been initialized. Did you forget to dispose the canvas?');
|
|
3002
3027
|
}
|
|
3003
|
-
|
|
3004
3028
|
this._originalCanvasStyle = el.style.cssText;
|
|
3005
3029
|
el.setAttribute('data-fabric', 'main');
|
|
3006
3030
|
el.classList.add('lower-canvas');
|
|
@@ -3169,9 +3193,7 @@ let StaticCanvas$1 = class StaticCanvas extends createCollectionMixin(CommonMeth
|
|
|
3169
3193
|
}
|
|
3170
3194
|
_onObjectAdded(obj) {
|
|
3171
3195
|
if (obj.canvas && obj.canvas !== this) {
|
|
3172
|
-
|
|
3173
|
-
console.warn('fabric.Canvas: trying to add an object that belongs to a different canvas.\n' + 'Resulting to default behavior: removing object from previous canvas and adding to new canvas');
|
|
3174
|
-
/* _DEV_MODE_END_ */
|
|
3196
|
+
log('warn', 'Canvas is trying to add an object that belongs to a different canvas.\n' + 'Resulting to default behavior: removing object from previous canvas and adding to new canvas');
|
|
3175
3197
|
obj.canvas.remove(obj);
|
|
3176
3198
|
}
|
|
3177
3199
|
obj._set('canvas', this);
|
|
@@ -4101,7 +4123,7 @@ let StaticCanvas$1 = class StaticCanvas extends createCollectionMixin(CommonMeth
|
|
|
4101
4123
|
signal
|
|
4102
4124
|
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
4103
4125
|
if (!json) {
|
|
4104
|
-
return Promise.reject(new
|
|
4126
|
+
return Promise.reject(new FabricError('`json` is undefined'));
|
|
4105
4127
|
}
|
|
4106
4128
|
|
|
4107
4129
|
// parse json if it wasn't already
|
|
@@ -4271,6 +4293,7 @@ let StaticCanvas$1 = class StaticCanvas extends createCollectionMixin(CommonMeth
|
|
|
4271
4293
|
width: this.width,
|
|
4272
4294
|
height: this.height
|
|
4273
4295
|
});
|
|
4296
|
+
runningAnimations.cancelByCanvas(this);
|
|
4274
4297
|
this.disposed = true;
|
|
4275
4298
|
return new Promise((resolve, reject) => {
|
|
4276
4299
|
const task = () => {
|
|
@@ -4557,10 +4580,10 @@ const sendPointToPlane = function (point) {
|
|
|
4557
4580
|
const transformPointRelativeToCanvas = (point, canvas, relationBefore, relationAfter) => {
|
|
4558
4581
|
// is this still needed with TS?
|
|
4559
4582
|
if (relationBefore !== 'child' && relationBefore !== 'sibling') {
|
|
4560
|
-
throw new
|
|
4583
|
+
throw new FabricError("received bad argument ".concat(relationBefore));
|
|
4561
4584
|
}
|
|
4562
4585
|
if (relationAfter !== 'child' && relationAfter !== 'sibling') {
|
|
4563
|
-
throw new
|
|
4586
|
+
throw new FabricError("received bad argument ".concat(relationAfter));
|
|
4564
4587
|
}
|
|
4565
4588
|
if (relationBefore === relationAfter) {
|
|
4566
4589
|
return point;
|
|
@@ -5667,6 +5690,31 @@ class Intersection {
|
|
|
5667
5690
|
}
|
|
5668
5691
|
}
|
|
5669
5692
|
|
|
5693
|
+
/**
|
|
5694
|
+
* Use the ray casting algorithm to determine if {@link point} is in the polygon defined by {@link points}
|
|
5695
|
+
* @see https://en.wikipedia.org/wiki/Point_in_polygon
|
|
5696
|
+
* @param point
|
|
5697
|
+
* @param points polygon points
|
|
5698
|
+
* @returns
|
|
5699
|
+
*/
|
|
5700
|
+
static isPointInPolygon(point, points) {
|
|
5701
|
+
const other = new Point(point).setX(Math.min(point.x - 1, ...points.map(p => p.x)));
|
|
5702
|
+
let hits = 0;
|
|
5703
|
+
for (let index = 0; index < points.length; index++) {
|
|
5704
|
+
const inter = this.intersectSegmentSegment(
|
|
5705
|
+
// polygon side
|
|
5706
|
+
points[index], points[(index + 1) % points.length],
|
|
5707
|
+
// ray
|
|
5708
|
+
point, other);
|
|
5709
|
+
if (inter.includes(point)) {
|
|
5710
|
+
// point is on the polygon side
|
|
5711
|
+
return true;
|
|
5712
|
+
}
|
|
5713
|
+
hits += Number(inter.status === 'Intersection');
|
|
5714
|
+
}
|
|
5715
|
+
return hits % 2 === 1;
|
|
5716
|
+
}
|
|
5717
|
+
|
|
5670
5718
|
/**
|
|
5671
5719
|
* Checks if a line intersects another
|
|
5672
5720
|
* @see {@link https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection line intersection}
|
|
@@ -6203,21 +6251,15 @@ class ObjectGeometry extends ObjectOrigin {
|
|
|
6203
6251
|
* Checks if object is fully contained within area of another object
|
|
6204
6252
|
* @param {Object} other Object to test
|
|
6205
6253
|
* @param {Boolean} [absolute] use coordinates without viewportTransform
|
|
6206
|
-
* @param {Boolean} [calculate] use coordinates of current position instead of
|
|
6254
|
+
* @param {Boolean} [calculate] use coordinates of current position instead of stored ones
|
|
6207
6255
|
* @return {Boolean} true if object is fully contained within area of another object
|
|
6208
6256
|
*/
|
|
6209
6257
|
isContainedWithinObject(other) {
|
|
6210
6258
|
let absolute = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
6211
6259
|
let calculate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
6212
|
-
const points = this.getCoords(absolute, calculate)
|
|
6213
|
-
|
|
6214
|
-
|
|
6215
|
-
for (let i = 0; i < 4; i++) {
|
|
6216
|
-
if (!other.containsPoint(points[i], lines)) {
|
|
6217
|
-
return false;
|
|
6218
|
-
}
|
|
6219
|
-
}
|
|
6220
|
-
return true;
|
|
6260
|
+
const points = this.getCoords(absolute, calculate);
|
|
6261
|
+
calculate && other.getCoords(absolute, true);
|
|
6262
|
+
return points.every(point => other.containsPoint(point));
|
|
6221
6263
|
}
|
|
6222
6264
|
|
|
6223
6265
|
/**
|
|
@@ -6239,19 +6281,14 @@ class ObjectGeometry extends ObjectOrigin {
|
|
|
6239
6281
|
/**
|
|
6240
6282
|
* Checks if point is inside the object
|
|
6241
6283
|
* @param {Point} point Point to check against
|
|
6242
|
-
* @param {Object} [lines] object returned from @method _getImageLines
|
|
6243
6284
|
* @param {Boolean} [absolute] use coordinates without viewportTransform
|
|
6244
6285
|
* @param {Boolean} [calculate] use coordinates of current position instead of stored ones
|
|
6245
6286
|
* @return {Boolean} true if point is inside the object
|
|
6246
6287
|
*/
|
|
6247
|
-
containsPoint(point
|
|
6248
|
-
let absolute = arguments.length >
|
|
6249
|
-
let calculate = arguments.length >
|
|
6250
|
-
|
|
6251
|
-
imageLines = lines || this._getImageLines(coords),
|
|
6252
|
-
xPoints = this._findCrossPoints(point, imageLines);
|
|
6253
|
-
// if xPoints is odd then point is inside the object
|
|
6254
|
-
return xPoints !== 0 && xPoints % 2 === 1;
|
|
6288
|
+
containsPoint(point) {
|
|
6289
|
+
let absolute = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
6290
|
+
let calculate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
6291
|
+
return Intersection.isPointInPolygon(point, this.getCoords(absolute, calculate));
|
|
6255
6292
|
}
|
|
6256
6293
|
|
|
6257
6294
|
/**
|
|
@@ -6293,7 +6330,7 @@ class ObjectGeometry extends ObjectOrigin {
|
|
|
6293
6330
|
_containsCenterOfCanvas(pointTL, pointBR, calculate) {
|
|
6294
6331
|
// worst case scenario the object is so big that contains the screen
|
|
6295
6332
|
const centerPoint = pointTL.midPointFrom(pointBR);
|
|
6296
|
-
return this.containsPoint(centerPoint,
|
|
6333
|
+
return this.containsPoint(centerPoint, true, calculate);
|
|
6297
6334
|
}
|
|
6298
6335
|
|
|
6299
6336
|
/**
|
|
@@ -6316,100 +6353,6 @@ class ObjectGeometry extends ObjectOrigin {
|
|
|
6316
6353
|
return allPointsAreOutside && this._containsCenterOfCanvas(tl, br, calculate);
|
|
6317
6354
|
}
|
|
6318
6355
|
|
|
6319
|
-
/**
|
|
6320
|
-
* Method that returns an object with the object edges in it, given the coordinates of the corners
|
|
6321
|
-
* @private
|
|
6322
|
-
* @param {Object} lineCoords or aCoords Coordinates of the object corners
|
|
6323
|
-
*/
|
|
6324
|
-
_getImageLines(_ref) {
|
|
6325
|
-
let {
|
|
6326
|
-
tl,
|
|
6327
|
-
tr,
|
|
6328
|
-
bl,
|
|
6329
|
-
br
|
|
6330
|
-
} = _ref;
|
|
6331
|
-
const lines = {
|
|
6332
|
-
topline: {
|
|
6333
|
-
o: tl,
|
|
6334
|
-
d: tr
|
|
6335
|
-
},
|
|
6336
|
-
rightline: {
|
|
6337
|
-
o: tr,
|
|
6338
|
-
d: br
|
|
6339
|
-
},
|
|
6340
|
-
bottomline: {
|
|
6341
|
-
o: br,
|
|
6342
|
-
d: bl
|
|
6343
|
-
},
|
|
6344
|
-
leftline: {
|
|
6345
|
-
o: bl,
|
|
6346
|
-
d: tl
|
|
6347
|
-
}
|
|
6348
|
-
};
|
|
6349
|
-
|
|
6350
|
-
// // debugging
|
|
6351
|
-
// if (this.canvas.contextTop) {
|
|
6352
|
-
// this.canvas.contextTop.fillRect(lines.bottomline.d.x, lines.bottomline.d.y, 2, 2);
|
|
6353
|
-
// this.canvas.contextTop.fillRect(lines.bottomline.o.x, lines.bottomline.o.y, 2, 2);
|
|
6354
|
-
//
|
|
6355
|
-
// this.canvas.contextTop.fillRect(lines.leftline.d.x, lines.leftline.d.y, 2, 2);
|
|
6356
|
-
// this.canvas.contextTop.fillRect(lines.leftline.o.x, lines.leftline.o.y, 2, 2);
|
|
6357
|
-
//
|
|
6358
|
-
// this.canvas.contextTop.fillRect(lines.topline.d.x, lines.topline.d.y, 2, 2);
|
|
6359
|
-
// this.canvas.contextTop.fillRect(lines.topline.o.x, lines.topline.o.y, 2, 2);
|
|
6360
|
-
//
|
|
6361
|
-
// this.canvas.contextTop.fillRect(lines.rightline.d.x, lines.rightline.d.y, 2, 2);
|
|
6362
|
-
// this.canvas.contextTop.fillRect(lines.rightline.o.x, lines.rightline.o.y, 2, 2);
|
|
6363
|
-
// }
|
|
6364
|
-
|
|
6365
|
-
return lines;
|
|
6366
|
-
}
|
|
6367
|
-
|
|
6368
|
-
/**
|
|
6369
|
-
* Helper method to determine how many cross points are between the 4 object edges
|
|
6370
|
-
* and the horizontal line determined by a point on canvas
|
|
6371
|
-
* @private
|
|
6372
|
-
* @param {Point} point Point to check
|
|
6373
|
-
* @param {Object} lines Coordinates of the object being evaluated
|
|
6374
|
-
* @return {number} number of crossPoint
|
|
6375
|
-
*/
|
|
6376
|
-
_findCrossPoints(point, lines) {
|
|
6377
|
-
let xcount = 0;
|
|
6378
|
-
for (const lineKey in lines) {
|
|
6379
|
-
let xi;
|
|
6380
|
-
const iLine = lines[lineKey];
|
|
6381
|
-
// optimization 1: line below point. no cross
|
|
6382
|
-
if (iLine.o.y < point.y && iLine.d.y < point.y) {
|
|
6383
|
-
continue;
|
|
6384
|
-
}
|
|
6385
|
-
// optimization 2: line above point. no cross
|
|
6386
|
-
if (iLine.o.y >= point.y && iLine.d.y >= point.y) {
|
|
6387
|
-
continue;
|
|
6388
|
-
}
|
|
6389
|
-
// optimization 3: vertical line case
|
|
6390
|
-
if (iLine.o.x === iLine.d.x && iLine.o.x >= point.x) {
|
|
6391
|
-
xi = iLine.o.x;
|
|
6392
|
-
}
|
|
6393
|
-
// calculate the intersection point
|
|
6394
|
-
else {
|
|
6395
|
-
const b1 = 0;
|
|
6396
|
-
const b2 = (iLine.d.y - iLine.o.y) / (iLine.d.x - iLine.o.x);
|
|
6397
|
-
const a1 = point.y - b1 * point.x;
|
|
6398
|
-
const a2 = iLine.o.y - b2 * iLine.o.x;
|
|
6399
|
-
xi = -(a1 - a2) / (b1 - b2);
|
|
6400
|
-
}
|
|
6401
|
-
// don't count xi < point.x cases
|
|
6402
|
-
if (xi >= point.x) {
|
|
6403
|
-
xcount += 1;
|
|
6404
|
-
}
|
|
6405
|
-
// optimization 4: specific for square images
|
|
6406
|
-
if (xcount === 2) {
|
|
6407
|
-
break;
|
|
6408
|
-
}
|
|
6409
|
-
}
|
|
6410
|
-
return xcount;
|
|
6411
|
-
}
|
|
6412
|
-
|
|
6413
6356
|
/**
|
|
6414
6357
|
* Returns coordinates of object's bounding rectangle (left, top, width, height)
|
|
6415
6358
|
* the box is intended as aligned to axis of canvas.
|
|
@@ -7175,7 +7118,7 @@ let FabricObject$1 = class FabricObject extends AnimatableObject {
|
|
|
7175
7118
|
return name.toLowerCase();
|
|
7176
7119
|
}
|
|
7177
7120
|
set type(value) {
|
|
7178
|
-
|
|
7121
|
+
log('warn', 'Setting type has no effect', value);
|
|
7179
7122
|
}
|
|
7180
7123
|
|
|
7181
7124
|
/**
|
|
@@ -8095,7 +8038,7 @@ let FabricObject$1 = class FabricObject extends AnimatableObject {
|
|
|
8095
8038
|
* @param {Boolean} [options.enableRetinaScaling] Enable retina scaling for clone image. Introduce in 1.6.4
|
|
8096
8039
|
* @param {Boolean} [options.withoutTransform] Remove current object transform ( no scale , no angle, no flip, no skew ). Introduced in 2.3.4
|
|
8097
8040
|
* @param {Boolean} [options.withoutShadow] Remove current object shadow. Introduced in 2.4.2
|
|
8098
|
-
* @return {
|
|
8041
|
+
* @return {FabricImage} Object cloned as image.
|
|
8099
8042
|
*/
|
|
8100
8043
|
cloneAsImage(options) {
|
|
8101
8044
|
const canvasEl = this.toCanvasElement(options);
|
|
@@ -8592,28 +8535,28 @@ class Control {
|
|
|
8592
8535
|
* @type {?Number}
|
|
8593
8536
|
* @default null
|
|
8594
8537
|
*/
|
|
8595
|
-
_defineProperty(this, "sizeX",
|
|
8538
|
+
_defineProperty(this, "sizeX", 0);
|
|
8596
8539
|
/**
|
|
8597
8540
|
* Sets the height of the control. If null, defaults to object's cornerSize.
|
|
8598
8541
|
* Expects both sizeX and sizeY to be set when set.
|
|
8599
8542
|
* @type {?Number}
|
|
8600
8543
|
* @default null
|
|
8601
8544
|
*/
|
|
8602
|
-
_defineProperty(this, "sizeY",
|
|
8545
|
+
_defineProperty(this, "sizeY", 0);
|
|
8603
8546
|
/**
|
|
8604
8547
|
* Sets the length of the touch area of the control. If null, defaults to object's touchCornerSize.
|
|
8605
8548
|
* Expects both touchSizeX and touchSizeY to be set when set.
|
|
8606
8549
|
* @type {?Number}
|
|
8607
8550
|
* @default null
|
|
8608
8551
|
*/
|
|
8609
|
-
_defineProperty(this, "touchSizeX",
|
|
8552
|
+
_defineProperty(this, "touchSizeX", 0);
|
|
8610
8553
|
/**
|
|
8611
8554
|
* Sets the height of the touch area of the control. If null, defaults to object's touchCornerSize.
|
|
8612
8555
|
* Expects both touchSizeX and touchSizeY to be set when set.
|
|
8613
8556
|
* @type {?Number}
|
|
8614
8557
|
* @default null
|
|
8615
8558
|
*/
|
|
8616
|
-
_defineProperty(this, "touchSizeY",
|
|
8559
|
+
_defineProperty(this, "touchSizeY", 0);
|
|
8617
8560
|
/**
|
|
8618
8561
|
* Css cursor style to display when the control is hovered.
|
|
8619
8562
|
* if the method `cursorStyleHandler` is provided, this property is ignored.
|
|
@@ -8658,10 +8601,16 @@ class Control {
|
|
|
8658
8601
|
* @return {Boolean} true if the action/event modified the object
|
|
8659
8602
|
*/
|
|
8660
8603
|
|
|
8661
|
-
shouldActivate(controlKey, fabricObject) {
|
|
8604
|
+
shouldActivate(controlKey, fabricObject, pointer, _ref) {
|
|
8662
8605
|
var _fabricObject$canvas;
|
|
8606
|
+
let {
|
|
8607
|
+
tl,
|
|
8608
|
+
tr,
|
|
8609
|
+
br,
|
|
8610
|
+
bl
|
|
8611
|
+
} = _ref;
|
|
8663
8612
|
// TODO: locking logic can be handled here instead of in the control handler logic
|
|
8664
|
-
return ((_fabricObject$canvas = fabricObject.canvas) === null || _fabricObject$canvas === void 0 ? void 0 : _fabricObject$canvas.getActiveObject()) === fabricObject && fabricObject.isControlVisible(controlKey);
|
|
8613
|
+
return ((_fabricObject$canvas = fabricObject.canvas) === null || _fabricObject$canvas === void 0 ? void 0 : _fabricObject$canvas.getActiveObject()) === fabricObject && fabricObject.isControlVisible(controlKey) && Intersection.isPointInPolygon(pointer, [tl, tr, br, bl]);
|
|
8665
8614
|
}
|
|
8666
8615
|
|
|
8667
8616
|
/**
|
|
@@ -8754,36 +8703,15 @@ class Control {
|
|
|
8754
8703
|
* @param {Number} centerY y coordinate where the control center should be
|
|
8755
8704
|
* @param {boolean} isTouch true if touch corner, false if normal corner
|
|
8756
8705
|
*/
|
|
8757
|
-
calcCornerCoords(
|
|
8758
|
-
|
|
8759
|
-
|
|
8760
|
-
|
|
8761
|
-
if (xSize && ySize && xSize !== ySize) {
|
|
8762
|
-
// handle rectangular corners
|
|
8763
|
-
const controlTriangleAngle = Math.atan2(ySize, xSize);
|
|
8764
|
-
const cornerHypotenuse = Math.sqrt(xSize * xSize + ySize * ySize) / 2;
|
|
8765
|
-
const newTheta = controlTriangleAngle - degreesToRadians(objectAngle);
|
|
8766
|
-
const newThetaComp = halfPI - controlTriangleAngle - degreesToRadians(objectAngle);
|
|
8767
|
-
cosHalfOffset = cornerHypotenuse * cos(newTheta);
|
|
8768
|
-
sinHalfOffset = cornerHypotenuse * sin(newTheta);
|
|
8769
|
-
// use complementary angle for two corners
|
|
8770
|
-
cosHalfOffsetComp = cornerHypotenuse * cos(newThetaComp);
|
|
8771
|
-
sinHalfOffsetComp = cornerHypotenuse * sin(newThetaComp);
|
|
8772
|
-
} else {
|
|
8773
|
-
// handle square corners
|
|
8774
|
-
// use default object corner size unless size is defined
|
|
8775
|
-
const cornerSize = xSize && ySize ? xSize : objectCornerSize;
|
|
8776
|
-
const cornerHypotenuse = cornerSize * Math.SQRT1_2;
|
|
8777
|
-
// complementary angles are equal since they're both 45 degrees
|
|
8778
|
-
const newTheta = degreesToRadians(45 - objectAngle);
|
|
8779
|
-
cosHalfOffset = cosHalfOffsetComp = cornerHypotenuse * cos(newTheta);
|
|
8780
|
-
sinHalfOffset = sinHalfOffsetComp = cornerHypotenuse * sin(newTheta);
|
|
8781
|
-
}
|
|
8706
|
+
calcCornerCoords(angle, objectCornerSize, centerX, centerY, isTouch, fabricObject) {
|
|
8707
|
+
const t = multiplyTransformMatrixArray([createTranslateMatrix(centerX, centerY), createRotateMatrix({
|
|
8708
|
+
angle
|
|
8709
|
+
}), createScaleMatrix((isTouch ? this.touchSizeX : this.sizeX) || objectCornerSize, (isTouch ? this.touchSizeY : this.sizeY) || objectCornerSize)]);
|
|
8782
8710
|
return {
|
|
8783
|
-
tl: new Point(
|
|
8784
|
-
tr: new Point(
|
|
8785
|
-
bl: new Point(
|
|
8786
|
-
br: new Point(
|
|
8711
|
+
tl: new Point(-0.5, -0.5).transform(t),
|
|
8712
|
+
tr: new Point(0.5, -0.5).transform(t),
|
|
8713
|
+
bl: new Point(-0.5, 0.5).transform(t),
|
|
8714
|
+
br: new Point(0.5, 0.5).transform(t)
|
|
8787
8715
|
};
|
|
8788
8716
|
}
|
|
8789
8717
|
|
|
@@ -9425,34 +9353,14 @@ class InteractiveFabricObject extends FabricObject$1 {
|
|
|
9425
9353
|
return '';
|
|
9426
9354
|
}
|
|
9427
9355
|
this.__corner = undefined;
|
|
9428
|
-
// had to keep the reverse loop because was breaking tests
|
|
9429
9356
|
const cornerEntries = Object.entries(this.oCoords);
|
|
9430
9357
|
for (let i = cornerEntries.length - 1; i >= 0; i--) {
|
|
9431
9358
|
const [key, corner] = cornerEntries[i];
|
|
9432
|
-
if (this.controls[key].shouldActivate(key, this)) {
|
|
9433
|
-
|
|
9434
|
-
|
|
9435
|
-
if (xPoints !== 0 && xPoints % 2 === 1) {
|
|
9436
|
-
this.__corner = key;
|
|
9437
|
-
return key;
|
|
9438
|
-
}
|
|
9359
|
+
if (this.controls[key].shouldActivate(key, this, pointer, forTouch ? corner.touchCorner : corner.corner)) {
|
|
9360
|
+
// this.canvas.contextTop.fillRect(pointer.x - 1, pointer.y - 1, 2, 2);
|
|
9361
|
+
return this.__corner = key;
|
|
9439
9362
|
}
|
|
9440
|
-
|
|
9441
|
-
// // debugging
|
|
9442
|
-
//
|
|
9443
|
-
// this.canvas.contextTop.fillRect(lines.bottomline.d.x, lines.bottomline.d.y, 2, 2);
|
|
9444
|
-
// this.canvas.contextTop.fillRect(lines.bottomline.o.x, lines.bottomline.o.y, 2, 2);
|
|
9445
|
-
//
|
|
9446
|
-
// this.canvas.contextTop.fillRect(lines.leftline.d.x, lines.leftline.d.y, 2, 2);
|
|
9447
|
-
// this.canvas.contextTop.fillRect(lines.leftline.o.x, lines.leftline.o.y, 2, 2);
|
|
9448
|
-
//
|
|
9449
|
-
// this.canvas.contextTop.fillRect(lines.topline.d.x, lines.topline.d.y, 2, 2);
|
|
9450
|
-
// this.canvas.contextTop.fillRect(lines.topline.o.x, lines.topline.o.y, 2, 2);
|
|
9451
|
-
//
|
|
9452
|
-
// this.canvas.contextTop.fillRect(lines.rightline.d.x, lines.rightline.d.y, 2, 2);
|
|
9453
|
-
// this.canvas.contextTop.fillRect(lines.rightline.o.x, lines.rightline.o.y, 2, 2);
|
|
9454
9363
|
}
|
|
9455
|
-
|
|
9456
9364
|
return '';
|
|
9457
9365
|
}
|
|
9458
9366
|
|
|
@@ -9508,8 +9416,9 @@ class InteractiveFabricObject extends FabricObject$1 {
|
|
|
9508
9416
|
* @private
|
|
9509
9417
|
*/
|
|
9510
9418
|
_calcCornerCoords(control, position) {
|
|
9511
|
-
const
|
|
9512
|
-
const
|
|
9419
|
+
const angle = this.getTotalAngle();
|
|
9420
|
+
const corner = control.calcCornerCoords(angle, this.cornerSize, position.x, position.y, false, this);
|
|
9421
|
+
const touchCorner = control.calcCornerCoords(angle, this.touchCornerSize, position.x, position.y, true, this);
|
|
9513
9422
|
return {
|
|
9514
9423
|
corner,
|
|
9515
9424
|
touchCorner
|
|
@@ -9527,7 +9436,7 @@ class InteractiveFabricObject extends FabricObject$1 {
|
|
|
9527
9436
|
setCoords() {
|
|
9528
9437
|
super.setCoords();
|
|
9529
9438
|
// set coordinates of the draggable boxes in the corners used to scale/rotate the image
|
|
9530
|
-
this.oCoords = this.calcOCoords();
|
|
9439
|
+
this.canvas && (this.oCoords = this.calcOCoords());
|
|
9531
9440
|
}
|
|
9532
9441
|
|
|
9533
9442
|
/**
|
|
@@ -9905,6 +9814,14 @@ applyMixins(FabricObject, [FabricObjectSVGExportMixin]);
|
|
|
9905
9814
|
classRegistry.setClass(FabricObject);
|
|
9906
9815
|
classRegistry.setClass(FabricObject, 'object');
|
|
9907
9816
|
|
|
9817
|
+
/**
|
|
9818
|
+
* @deprecated The old fabric.Object class can't be imported as Object because of conflict with the JS api
|
|
9819
|
+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object
|
|
9820
|
+
* For this reason it has been renamed to FabricObject.
|
|
9821
|
+
* Please use `import { FabricObject }` in place of `import { Object as FabricObject }`
|
|
9822
|
+
*/
|
|
9823
|
+
class _Object extends FabricObject {}
|
|
9824
|
+
|
|
9908
9825
|
/**
|
|
9909
9826
|
* Returns true if context has transparent pixel
|
|
9910
9827
|
* at specified location (taking tolerance into account)
|
|
@@ -10609,15 +10526,11 @@ class Group extends createCollectionMixin(FabricObject) {
|
|
|
10609
10526
|
canEnterGroup(object) {
|
|
10610
10527
|
if (object === this || this.isDescendantOf(object)) {
|
|
10611
10528
|
// prevent circular object tree
|
|
10612
|
-
|
|
10613
|
-
console.error('fabric.Group: circular object trees are not supported, this call has no effect');
|
|
10614
|
-
/* _DEV_MODE_END_ */
|
|
10529
|
+
log('error', 'Group: circular object trees are not supported, this call has no effect');
|
|
10615
10530
|
return false;
|
|
10616
10531
|
} else if (this._objects.indexOf(object) !== -1) {
|
|
10617
10532
|
// is already in the objects array
|
|
10618
|
-
|
|
10619
|
-
console.error('fabric.Group: duplicate objects are not supported inside group, this call has no effect');
|
|
10620
|
-
/* _DEV_MODE_END_ */
|
|
10533
|
+
log('error', 'Group: duplicate objects are not supported inside group, this call has no effect');
|
|
10621
10534
|
return false;
|
|
10622
10535
|
}
|
|
10623
10536
|
return true;
|
|
@@ -11470,7 +11383,9 @@ class ActiveSelection extends Group {
|
|
|
11470
11383
|
// save ref to group for later in order to return to it
|
|
11471
11384
|
const parent = object.group;
|
|
11472
11385
|
parent._exitGroup(object);
|
|
11473
|
-
|
|
11386
|
+
// make sure we are setting the correct owning group
|
|
11387
|
+
// in case `object` is transferred between active selections
|
|
11388
|
+
!(parent instanceof ActiveSelection) && (object.__owningGroup = parent);
|
|
11474
11389
|
}
|
|
11475
11390
|
this._enterGroup(object, removeParentTransform);
|
|
11476
11391
|
return true;
|
|
@@ -13122,7 +13037,7 @@ function request(url) {
|
|
|
13122
13037
|
xhr.onerror = xhr.ontimeout = noop;
|
|
13123
13038
|
};
|
|
13124
13039
|
if (signal && signal.aborted) {
|
|
13125
|
-
throw new
|
|
13040
|
+
throw new SignalAbortedError('request');
|
|
13126
13041
|
} else if (signal) {
|
|
13127
13042
|
signal.addEventListener('abort', abort, {
|
|
13128
13043
|
once: true
|
|
@@ -13569,9 +13484,9 @@ class SelectableCanvas extends StaticCanvas$1 {
|
|
|
13569
13484
|
* @type FabricObject[]
|
|
13570
13485
|
* @private
|
|
13571
13486
|
*/
|
|
13572
|
-
_defineProperty(this, "_objectsToRender",
|
|
13487
|
+
_defineProperty(this, "_objectsToRender", void 0);
|
|
13573
13488
|
/**
|
|
13574
|
-
* hold a
|
|
13489
|
+
* hold a reference to a data structure that contains information
|
|
13575
13490
|
* on the current on going transform
|
|
13576
13491
|
* @type
|
|
13577
13492
|
* @private
|
|
@@ -13639,6 +13554,10 @@ class SelectableCanvas extends StaticCanvas$1 {
|
|
|
13639
13554
|
}
|
|
13640
13555
|
super._onObjectRemoved(obj);
|
|
13641
13556
|
}
|
|
13557
|
+
_onStackOrderChanged() {
|
|
13558
|
+
this._objectsToRender = undefined;
|
|
13559
|
+
super._onStackOrderChanged();
|
|
13560
|
+
}
|
|
13642
13561
|
|
|
13643
13562
|
/**
|
|
13644
13563
|
* Divides objects in two groups, one to render immediately
|
|
@@ -13702,15 +13621,6 @@ class SelectableCanvas extends StaticCanvas$1 {
|
|
|
13702
13621
|
});
|
|
13703
13622
|
}
|
|
13704
13623
|
|
|
13705
|
-
/**
|
|
13706
|
-
* Given a pointer on the canvas with a viewport applied,
|
|
13707
|
-
* find out the pointer in object coordinates
|
|
13708
|
-
* @private
|
|
13709
|
-
*/
|
|
13710
|
-
_normalizePointer(object, pointer) {
|
|
13711
|
-
return transformPoint(this.restorePointerVpt(pointer), invertTransform(object.calcTransformMatrix()));
|
|
13712
|
-
}
|
|
13713
|
-
|
|
13714
13624
|
/**
|
|
13715
13625
|
* Set the canvas tolerance value for pixel taret find.
|
|
13716
13626
|
* Use only integer numbers.
|
|
@@ -13731,8 +13641,8 @@ class SelectableCanvas extends StaticCanvas$1 {
|
|
|
13731
13641
|
* @TODO this seems dumb that we treat controls with transparency. we can find controls
|
|
13732
13642
|
* programmatically without painting them, the cache canvas optimization is always valid
|
|
13733
13643
|
* @param {FabricObject} target Object to check
|
|
13734
|
-
* @param {Number} x Left coordinate
|
|
13735
|
-
* @param {Number} y Top coordinate
|
|
13644
|
+
* @param {Number} x Left coordinate in viewport space
|
|
13645
|
+
* @param {Number} y Top coordinate in viewport space
|
|
13736
13646
|
* @return {Boolean}
|
|
13737
13647
|
*/
|
|
13738
13648
|
isTargetTransparent(target, x, y) {
|
|
@@ -13842,6 +13752,7 @@ class SelectableCanvas extends StaticCanvas$1 {
|
|
|
13842
13752
|
* @param {FaricObject} target
|
|
13843
13753
|
*/
|
|
13844
13754
|
_setupCurrentTransform(e, target, alreadySelected) {
|
|
13755
|
+
var _control$getActionHan;
|
|
13845
13756
|
if (!target) {
|
|
13846
13757
|
return;
|
|
13847
13758
|
}
|
|
@@ -13850,7 +13761,7 @@ class SelectableCanvas extends StaticCanvas$1 {
|
|
|
13850
13761
|
sendPointToPlane(this.getPointer(e), undefined, target.group.calcTransformMatrix()) : this.getPointer(e);
|
|
13851
13762
|
const corner = target.getActiveControl() || '',
|
|
13852
13763
|
control = !!corner && target.controls[corner],
|
|
13853
|
-
actionHandler = alreadySelected && control ? control.getActionHandler(e, target, control) : dragHandler,
|
|
13764
|
+
actionHandler = alreadySelected && control ? (_control$getActionHan = control.getActionHandler(e, target, control)) === null || _control$getActionHan === void 0 ? void 0 : _control$getActionHan.bind(control) : dragHandler,
|
|
13854
13765
|
action = getActionFromCorner(alreadySelected, corner, e, target),
|
|
13855
13766
|
origin = this._getOriginFromCorner(target, corner),
|
|
13856
13767
|
altKey = e[this.centeredKey],
|
|
@@ -13988,19 +13899,15 @@ class SelectableCanvas extends StaticCanvas$1 {
|
|
|
13988
13899
|
|
|
13989
13900
|
/**
|
|
13990
13901
|
* Checks point is inside the object.
|
|
13991
|
-
* @param {Object} [pointer] x,y object of point coordinates we want to check.
|
|
13992
13902
|
* @param {FabricObject} obj Object to test against
|
|
13993
|
-
* @param {Object} [
|
|
13903
|
+
* @param {Object} [pointer] point from viewport.
|
|
13994
13904
|
* @return {Boolean} true if point is contained within an area of given object
|
|
13995
13905
|
* @private
|
|
13996
13906
|
*/
|
|
13997
|
-
_checkTarget(
|
|
13998
|
-
if (obj && obj.visible && obj.evented &&
|
|
13999
|
-
// http://www.geog.ubc.ca/courses/klink/gis.notes/ncgia/u32.html
|
|
14000
|
-
// http://idav.ucdavis.edu/~okreylos/TAship/Spring2000/PointInPolygon.html
|
|
14001
|
-
obj.containsPoint(pointer)) {
|
|
13907
|
+
_checkTarget(obj, pointer) {
|
|
13908
|
+
if (obj && obj.visible && obj.evented && obj.containsPoint(this.restorePointerVpt(pointer), true)) {
|
|
14002
13909
|
if ((this.perPixelTargetFind || obj.perPixelTargetFind) && !obj.isEditing) {
|
|
14003
|
-
if (!this.isTargetTransparent(obj,
|
|
13910
|
+
if (!this.isTargetTransparent(obj, pointer.x, pointer.y)) {
|
|
14004
13911
|
return true;
|
|
14005
13912
|
}
|
|
14006
13913
|
} else {
|
|
@@ -14019,23 +13926,19 @@ class SelectableCanvas extends StaticCanvas$1 {
|
|
|
14019
13926
|
*/
|
|
14020
13927
|
_searchPossibleTargets(objects, pointer) {
|
|
14021
13928
|
// Cache all targets where their bounding box contains point.
|
|
14022
|
-
let
|
|
14023
|
-
i = objects.length;
|
|
13929
|
+
let i = objects.length;
|
|
14024
13930
|
// Do not check for currently grouped objects, since we check the parent group itself.
|
|
14025
13931
|
// until we call this function specifically to search inside the activeGroup
|
|
14026
13932
|
while (i--) {
|
|
14027
|
-
const
|
|
14028
|
-
|
|
14029
|
-
if (this._checkTarget(pointerToUse, objToCheck, pointer)) {
|
|
14030
|
-
target = objects[i];
|
|
13933
|
+
const target = objects[i];
|
|
13934
|
+
if (this._checkTarget(target, pointer)) {
|
|
14031
13935
|
if (isCollection(target) && target.subTargetCheck) {
|
|
14032
13936
|
const subTarget = this._searchPossibleTargets(target._objects, pointer);
|
|
14033
13937
|
subTarget && this.targets.push(subTarget);
|
|
14034
13938
|
}
|
|
14035
|
-
|
|
13939
|
+
return target;
|
|
14036
13940
|
}
|
|
14037
13941
|
}
|
|
14038
|
-
return target;
|
|
14039
13942
|
}
|
|
14040
13943
|
|
|
14041
13944
|
/**
|
|
@@ -14055,6 +13958,7 @@ class SelectableCanvas extends StaticCanvas$1 {
|
|
|
14055
13958
|
|
|
14056
13959
|
/**
|
|
14057
13960
|
* Returns pointer coordinates without the effect of the viewport
|
|
13961
|
+
* Takes a point in html canvas space and gives you back a point of the scene.
|
|
14058
13962
|
* @param {Object} pointer with "x" and "y" number values in canvas HTML coordinates
|
|
14059
13963
|
* @return {Object} object with "x" and "y" number values in fabricCanvas coordinates
|
|
14060
13964
|
*/
|
|
@@ -14286,6 +14190,11 @@ class SelectableCanvas extends StaticCanvas$1 {
|
|
|
14286
14190
|
return false;
|
|
14287
14191
|
}
|
|
14288
14192
|
this._activeObject = object;
|
|
14193
|
+
if (object instanceof ActiveSelection && this._activeSelection !== object) {
|
|
14194
|
+
this._activeSelection = object;
|
|
14195
|
+
object.set('canvas', this);
|
|
14196
|
+
object.setCoords();
|
|
14197
|
+
}
|
|
14289
14198
|
return true;
|
|
14290
14199
|
}
|
|
14291
14200
|
|
|
@@ -15185,7 +15094,7 @@ let Canvas$1 = class Canvas extends SelectableCanvas {
|
|
|
15185
15094
|
const mouseUpHandler = control && control.getMouseUpHandler(e, target, control);
|
|
15186
15095
|
if (mouseUpHandler) {
|
|
15187
15096
|
pointer = this.getPointer(e);
|
|
15188
|
-
mouseUpHandler(e, transform, pointer.x, pointer.y);
|
|
15097
|
+
mouseUpHandler.call(control, e, transform, pointer.x, pointer.y);
|
|
15189
15098
|
}
|
|
15190
15099
|
}
|
|
15191
15100
|
target.isMoving = false;
|
|
@@ -15196,7 +15105,7 @@ let Canvas$1 = class Canvas extends SelectableCanvas {
|
|
|
15196
15105
|
const originalControl = transform.target && transform.target.controls[transform.corner],
|
|
15197
15106
|
originalMouseUpHandler = originalControl && originalControl.getMouseUpHandler(e, transform.target, originalControl);
|
|
15198
15107
|
pointer = pointer || this.getPointer(e);
|
|
15199
|
-
originalMouseUpHandler && originalMouseUpHandler(e, transform, pointer.x, pointer.y);
|
|
15108
|
+
originalMouseUpHandler && originalMouseUpHandler.call(originalControl, e, transform, pointer.x, pointer.y);
|
|
15200
15109
|
}
|
|
15201
15110
|
this._setCursorFromEvent(e, target);
|
|
15202
15111
|
this._handleEvent(e, 'up', LEFT_CLICK, isClick);
|
|
@@ -15218,7 +15127,7 @@ let Canvas$1 = class Canvas extends SelectableCanvas {
|
|
|
15218
15127
|
this.fire(eventType, options);
|
|
15219
15128
|
target && target.fire(eventType, options);
|
|
15220
15129
|
for (let i = 0; i < subTargets.length; i++) {
|
|
15221
|
-
subTargets[i].fire(eventType, options);
|
|
15130
|
+
subTargets[i] !== target && subTargets[i].fire(eventType, options);
|
|
15222
15131
|
}
|
|
15223
15132
|
return options;
|
|
15224
15133
|
}
|
|
@@ -15255,7 +15164,7 @@ let Canvas$1 = class Canvas extends SelectableCanvas {
|
|
|
15255
15164
|
// this may be a little be more complicated of what we want to handle
|
|
15256
15165
|
target && target.fire("mouse".concat(eventType), options);
|
|
15257
15166
|
for (let i = 0; i < targets.length; i++) {
|
|
15258
|
-
targets[i].fire("mouse".concat(eventType), options);
|
|
15167
|
+
targets[i] !== target && targets[i].fire("mouse".concat(eventType), options);
|
|
15259
15168
|
}
|
|
15260
15169
|
}
|
|
15261
15170
|
|
|
@@ -15427,7 +15336,7 @@ let Canvas$1 = class Canvas extends SelectableCanvas {
|
|
|
15427
15336
|
pointer = this.getPointer(e),
|
|
15428
15337
|
mouseDownHandler = control && control.getMouseDownHandler(e, target, control);
|
|
15429
15338
|
if (mouseDownHandler) {
|
|
15430
|
-
mouseDownHandler(e, this._currentTransform, pointer.x, pointer.y);
|
|
15339
|
+
mouseDownHandler.call(control, e, this._currentTransform, pointer.x, pointer.y);
|
|
15431
15340
|
}
|
|
15432
15341
|
}
|
|
15433
15342
|
}
|
|
@@ -15602,7 +15511,7 @@ let Canvas$1 = class Canvas extends SelectableCanvas {
|
|
|
15602
15511
|
pointer: this.getPointer(e, true),
|
|
15603
15512
|
absolutePointer: this.getPointer(e)
|
|
15604
15513
|
});
|
|
15605
|
-
fireCanvas && this.fire(
|
|
15514
|
+
fireCanvas && this.fire(canvasOut, outOpt);
|
|
15606
15515
|
oldTarget.fire(targetOut, outOpt);
|
|
15607
15516
|
}
|
|
15608
15517
|
if (target && targetChanged) {
|
|
@@ -15614,7 +15523,7 @@ let Canvas$1 = class Canvas extends SelectableCanvas {
|
|
|
15614
15523
|
pointer: this.getPointer(e, true),
|
|
15615
15524
|
absolutePointer: this.getPointer(e)
|
|
15616
15525
|
});
|
|
15617
|
-
fireCanvas && this.fire(
|
|
15526
|
+
fireCanvas && this.fire(canvasIn, inOpt);
|
|
15618
15527
|
target.fire(targetIn, inOpt);
|
|
15619
15528
|
}
|
|
15620
15529
|
}
|
|
@@ -16270,6 +16179,7 @@ _defineProperty(Gradient, "type", 'Gradient');
|
|
|
16270
16179
|
classRegistry.setClass(Gradient, 'gradient');
|
|
16271
16180
|
|
|
16272
16181
|
const _excluded$b = ["source"];
|
|
16182
|
+
|
|
16273
16183
|
/**
|
|
16274
16184
|
* @see {@link http://fabricjs.com/patterns demo}
|
|
16275
16185
|
* @see {@link http://fabricjs.com/dynamic-patterns demo}
|
|
@@ -16287,7 +16197,7 @@ class Pattern {
|
|
|
16287
16197
|
return 'pattern';
|
|
16288
16198
|
}
|
|
16289
16199
|
set type(value) {
|
|
16290
|
-
|
|
16200
|
+
log('warn', 'Setting type has no effect', value);
|
|
16291
16201
|
}
|
|
16292
16202
|
|
|
16293
16203
|
/**
|
|
@@ -19030,9 +18940,9 @@ function getMeasuringContext() {
|
|
|
19030
18940
|
* Text class
|
|
19031
18941
|
* @tutorial {@link http://fabricjs.com/fabric-intro-part-2#text}
|
|
19032
18942
|
*/
|
|
19033
|
-
class
|
|
18943
|
+
class FabricText extends StyledText {
|
|
19034
18944
|
static getDefaults() {
|
|
19035
|
-
return _objectSpread2(_objectSpread2({}, super.getDefaults()),
|
|
18945
|
+
return _objectSpread2(_objectSpread2({}, super.getDefaults()), FabricText.ownDefaults);
|
|
19036
18946
|
}
|
|
19037
18947
|
constructor(text) {
|
|
19038
18948
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
@@ -20079,7 +19989,7 @@ class Text extends StyledText {
|
|
|
20079
19989
|
fontSize = this.fontSize
|
|
20080
19990
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
20081
19991
|
let forMeasuring = arguments.length > 1 ? arguments[1] : undefined;
|
|
20082
|
-
const parsedFontFamily = fontFamily.includes("'") || fontFamily.includes('"') || fontFamily.includes(',') ||
|
|
19992
|
+
const parsedFontFamily = fontFamily.includes("'") || fontFamily.includes('"') || fontFamily.includes(',') || FabricText.genericFonts.includes(fontFamily.toLowerCase()) ? fontFamily : "\"".concat(fontFamily, "\"");
|
|
20083
19993
|
return [fontStyle, fontWeight, "".concat(forMeasuring ? this.CACHE_FONT_SIZE : fontSize, "px"), parsedFontFamily].join(' ');
|
|
20084
19994
|
}
|
|
20085
19995
|
|
|
@@ -20185,14 +20095,14 @@ class Text extends StyledText {
|
|
|
20185
20095
|
return 1;
|
|
20186
20096
|
}
|
|
20187
20097
|
/**
|
|
20188
|
-
* Returns
|
|
20098
|
+
* Returns FabricText instance from an SVG element (<b>not yet implemented</b>)
|
|
20189
20099
|
* @static
|
|
20190
20100
|
* @memberOf Text
|
|
20191
20101
|
* @param {HTMLElement} element Element to parse
|
|
20192
20102
|
* @param {Object} [options] Options object
|
|
20193
20103
|
*/
|
|
20194
20104
|
static async fromElement(element, options, cssRules) {
|
|
20195
|
-
const parsedAttributes = parseAttributes(element,
|
|
20105
|
+
const parsedAttributes = parseAttributes(element, FabricText.ATTRIBUTE_NAMES, cssRules);
|
|
20196
20106
|
const _options$parsedAttrib = _objectSpread2(_objectSpread2({}, options), parsedAttributes),
|
|
20197
20107
|
{
|
|
20198
20108
|
textAnchor = LEFT,
|
|
@@ -20247,9 +20157,9 @@ class Text extends StyledText {
|
|
|
20247
20157
|
/* _FROM_SVG_END_ */
|
|
20248
20158
|
|
|
20249
20159
|
/**
|
|
20250
|
-
* Returns
|
|
20160
|
+
* Returns FabricText instance from an object representation
|
|
20251
20161
|
* @param {Object} object plain js Object to create an instance from
|
|
20252
|
-
* @returns {Promise<
|
|
20162
|
+
* @returns {Promise<FabricText>}
|
|
20253
20163
|
*/
|
|
20254
20164
|
static fromObject(object) {
|
|
20255
20165
|
return this._fromObject(_objectSpread2(_objectSpread2({}, object), {}, {
|
|
@@ -20264,22 +20174,30 @@ class Text extends StyledText {
|
|
|
20264
20174
|
* @type string[]
|
|
20265
20175
|
* @protected
|
|
20266
20176
|
*/
|
|
20267
|
-
_defineProperty(
|
|
20268
|
-
_defineProperty(
|
|
20269
|
-
_defineProperty(
|
|
20270
|
-
_defineProperty(
|
|
20271
|
-
_defineProperty(
|
|
20177
|
+
_defineProperty(FabricText, "textLayoutProperties", textLayoutProperties);
|
|
20178
|
+
_defineProperty(FabricText, "cacheProperties", [...cacheProperties, ...additionalProps]);
|
|
20179
|
+
_defineProperty(FabricText, "ownDefaults", textDefaultValues);
|
|
20180
|
+
_defineProperty(FabricText, "type", 'Text');
|
|
20181
|
+
_defineProperty(FabricText, "genericFonts", ['sans-serif', 'serif', 'cursive', 'fantasy', 'monospace']);
|
|
20272
20182
|
/* _FROM_SVG_START_ */
|
|
20273
20183
|
/**
|
|
20274
|
-
* List of attribute names to account for when parsing SVG element (used by {@link
|
|
20184
|
+
* List of attribute names to account for when parsing SVG element (used by {@link FabricText.fromElement})
|
|
20275
20185
|
* @static
|
|
20276
20186
|
* @memberOf Text
|
|
20277
20187
|
* @see: http://www.w3.org/TR/SVG/text.html#TextElement
|
|
20278
20188
|
*/
|
|
20279
|
-
_defineProperty(
|
|
20280
|
-
applyMixins(
|
|
20281
|
-
classRegistry.setClass(
|
|
20282
|
-
classRegistry.setSVGClass(
|
|
20189
|
+
_defineProperty(FabricText, "ATTRIBUTE_NAMES", SHARED_ATTRIBUTES.concat('x', 'y', 'dx', 'dy', 'font-family', 'font-style', 'font-weight', 'font-size', 'letter-spacing', 'text-decoration', 'text-anchor'));
|
|
20190
|
+
applyMixins(FabricText, [TextSVGExportMixin]);
|
|
20191
|
+
classRegistry.setClass(FabricText);
|
|
20192
|
+
classRegistry.setSVGClass(FabricText);
|
|
20193
|
+
|
|
20194
|
+
/**
|
|
20195
|
+
* @deprecated The old fabric.Text class can't be imported as Text because of conflict with Web API.
|
|
20196
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/Text/Text
|
|
20197
|
+
* For this reason it has been renamed to FabricText.
|
|
20198
|
+
* Please use `import { FabricText }` in place of `import { Text as FabricText }`
|
|
20199
|
+
*/
|
|
20200
|
+
class Text extends FabricText {}
|
|
20283
20201
|
|
|
20284
20202
|
/**
|
|
20285
20203
|
* #### Dragging IText/Textbox Lifecycle
|
|
@@ -20632,7 +20550,7 @@ class DraggableTextDelegate {
|
|
|
20632
20550
|
* - `\-` Matches a "-" character (char code 45).
|
|
20633
20551
|
*/ // eslint-disable-next-line no-useless-escape
|
|
20634
20552
|
const reNonWord = /[ \n\.,;!\?\-]/;
|
|
20635
|
-
class ITextBehavior extends
|
|
20553
|
+
class ITextBehavior extends FabricText {
|
|
20636
20554
|
constructor() {
|
|
20637
20555
|
super(...arguments);
|
|
20638
20556
|
/**
|
|
@@ -22716,7 +22634,7 @@ class IText extends ITextClickBehavior {
|
|
|
22716
22634
|
lineIndex = cursorLocation.lineIndex,
|
|
22717
22635
|
charIndex = cursorLocation.charIndex > 0 ? cursorLocation.charIndex - 1 : 0,
|
|
22718
22636
|
charHeight = this.getValueOfPropertyAt(lineIndex, charIndex, 'fontSize'),
|
|
22719
|
-
multiplier = this.
|
|
22637
|
+
multiplier = this.getObjectScaling().x * this.canvas.getZoom(),
|
|
22720
22638
|
cursorWidth = this.cursorWidth / multiplier,
|
|
22721
22639
|
dy = this.getValueOfPropertyAt(lineIndex, charIndex, 'deltaY'),
|
|
22722
22640
|
topOffset = boundaries.topOffset + (1 - this._fontSizeFraction) * this.getHeightOfLine(lineIndex) / this.lineHeight - charHeight * (1 - this._fontSizeFraction);
|
|
@@ -23858,9 +23776,9 @@ const IMAGE_PROPS = ['cropX', 'cropY'];
|
|
|
23858
23776
|
/**
|
|
23859
23777
|
* @tutorial {@link http://fabricjs.com/fabric-intro-part-1#images}
|
|
23860
23778
|
*/
|
|
23861
|
-
class
|
|
23779
|
+
class FabricImage extends FabricObject {
|
|
23862
23780
|
static getDefaults() {
|
|
23863
|
-
return _objectSpread2(_objectSpread2({}, super.getDefaults()),
|
|
23781
|
+
return _objectSpread2(_objectSpread2({}, super.getDefaults()), FabricImage.ownDefaults);
|
|
23864
23782
|
}
|
|
23865
23783
|
/**
|
|
23866
23784
|
* Constructor
|
|
@@ -23878,7 +23796,7 @@ class Image extends FabricObject {
|
|
|
23878
23796
|
filters: []
|
|
23879
23797
|
}, options));
|
|
23880
23798
|
/**
|
|
23881
|
-
* When calling {@link
|
|
23799
|
+
* When calling {@link FabricImage.getSrc}, return value from element src with `element.getAttribute('src')`.
|
|
23882
23800
|
* This allows for relative urls as image src.
|
|
23883
23801
|
* @since 2.7.0
|
|
23884
23802
|
* @type Boolean
|
|
@@ -23935,7 +23853,7 @@ class Image extends FabricObject {
|
|
|
23935
23853
|
this._element = element;
|
|
23936
23854
|
this._originalElement = element;
|
|
23937
23855
|
this._setWidthHeight(size);
|
|
23938
|
-
element.classList.add(
|
|
23856
|
+
element.classList.add(FabricImage.CSS_CANVAS);
|
|
23939
23857
|
if (this.filters.length !== 0) {
|
|
23940
23858
|
this.applyFilters();
|
|
23941
23859
|
}
|
|
@@ -24408,12 +24326,12 @@ class Image extends FabricObject {
|
|
|
24408
24326
|
*/
|
|
24409
24327
|
|
|
24410
24328
|
/**
|
|
24411
|
-
* Creates an instance of
|
|
24329
|
+
* Creates an instance of FabricImage from its object representation
|
|
24412
24330
|
* @static
|
|
24413
24331
|
* @param {Object} object Object to create an instance from
|
|
24414
24332
|
* @param {object} [options] Options object
|
|
24415
24333
|
* @param {AbortSignal} [options.signal] handle aborting, see https://developer.mozilla.org/en-US/docs/Web/API/AbortController/signal
|
|
24416
|
-
* @returns {Promise<
|
|
24334
|
+
* @returns {Promise<FabricImage>}
|
|
24417
24335
|
*/
|
|
24418
24336
|
static fromObject(_ref) {
|
|
24419
24337
|
let {
|
|
@@ -24444,7 +24362,7 @@ class Image extends FabricObject {
|
|
|
24444
24362
|
* @static
|
|
24445
24363
|
* @param {String} url URL to create an image from
|
|
24446
24364
|
* @param {LoadImageOptions} [options] Options object
|
|
24447
|
-
* @returns {Promise<
|
|
24365
|
+
* @returns {Promise<FabricImage>}
|
|
24448
24366
|
*/
|
|
24449
24367
|
static fromURL(url) {
|
|
24450
24368
|
let {
|
|
@@ -24459,7 +24377,7 @@ class Image extends FabricObject {
|
|
|
24459
24377
|
}
|
|
24460
24378
|
|
|
24461
24379
|
/**
|
|
24462
|
-
* Returns {@link
|
|
24380
|
+
* Returns {@link FabricImage} instance from an SVG element
|
|
24463
24381
|
* @static
|
|
24464
24382
|
* @param {HTMLElement} element Element to parse
|
|
24465
24383
|
* @param {Object} [options] Options object
|
|
@@ -24471,23 +24389,31 @@ class Image extends FabricObject {
|
|
|
24471
24389
|
let cssRules = arguments.length > 2 ? arguments[2] : undefined;
|
|
24472
24390
|
const parsedAttributes = parseAttributes(element, this.ATTRIBUTE_NAMES, cssRules);
|
|
24473
24391
|
return this.fromURL(parsedAttributes['xlink:href'], options, parsedAttributes).catch(err => {
|
|
24474
|
-
|
|
24392
|
+
log('log', 'Unable to parse Image', err);
|
|
24475
24393
|
return null;
|
|
24476
24394
|
});
|
|
24477
24395
|
}
|
|
24478
24396
|
}
|
|
24479
|
-
_defineProperty(
|
|
24480
|
-
_defineProperty(
|
|
24481
|
-
_defineProperty(
|
|
24482
|
-
_defineProperty(
|
|
24397
|
+
_defineProperty(FabricImage, "type", 'Image');
|
|
24398
|
+
_defineProperty(FabricImage, "cacheProperties", [...cacheProperties, ...IMAGE_PROPS]);
|
|
24399
|
+
_defineProperty(FabricImage, "ownDefaults", imageDefaultValues);
|
|
24400
|
+
_defineProperty(FabricImage, "CSS_CANVAS", 'canvas-img');
|
|
24483
24401
|
/**
|
|
24484
|
-
* List of attribute names to account for when parsing SVG element (used by {@link
|
|
24402
|
+
* List of attribute names to account for when parsing SVG element (used by {@link FabricImage.fromElement})
|
|
24485
24403
|
* @static
|
|
24486
24404
|
* @see {@link http://www.w3.org/TR/SVG/struct.html#ImageElement}
|
|
24487
24405
|
*/
|
|
24488
|
-
_defineProperty(
|
|
24489
|
-
classRegistry.setClass(
|
|
24490
|
-
classRegistry.setSVGClass(
|
|
24406
|
+
_defineProperty(FabricImage, "ATTRIBUTE_NAMES", [...SHARED_ATTRIBUTES, 'x', 'y', 'width', 'height', 'preserveAspectRatio', 'xlink:href', 'crossOrigin', 'image-rendering']);
|
|
24407
|
+
classRegistry.setClass(FabricImage);
|
|
24408
|
+
classRegistry.setSVGClass(FabricImage);
|
|
24409
|
+
|
|
24410
|
+
/**
|
|
24411
|
+
* @deprecated The old fabric.Image class can't be imported as Image because of conflict with Web API.
|
|
24412
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/Image
|
|
24413
|
+
* For this reason it has been renamed to FabricImage.
|
|
24414
|
+
* Please use `import { FabricImage }` in place of `import { Image as FabricImage }`
|
|
24415
|
+
*/
|
|
24416
|
+
class Image extends FabricImage {}
|
|
24491
24417
|
|
|
24492
24418
|
/**
|
|
24493
24419
|
* Add a <g> element that envelop all child elements and makes the viewbox transformMatrix descend on all elements
|
|
@@ -24840,7 +24766,7 @@ class ElementsParser {
|
|
|
24840
24766
|
const obj = await klass.fromElement(el, this.options, this.cssRules);
|
|
24841
24767
|
this.resolveGradient(obj, el, 'fill');
|
|
24842
24768
|
this.resolveGradient(obj, el, 'stroke');
|
|
24843
|
-
if (obj instanceof
|
|
24769
|
+
if (obj instanceof FabricImage && obj._originalElement) {
|
|
24844
24770
|
removeTransformMatrixForSvgParsing(obj, obj.parsePreserveAspectRatioAttribute());
|
|
24845
24771
|
} else {
|
|
24846
24772
|
removeTransformMatrixForSvgParsing(obj);
|
|
@@ -24959,7 +24885,7 @@ async function parseSVGDocument(doc, reviver) {
|
|
|
24959
24885
|
signal
|
|
24960
24886
|
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
24961
24887
|
if (signal && signal.aborted) {
|
|
24962
|
-
|
|
24888
|
+
log('log', new SignalAbortedError('parseSVGDocument'));
|
|
24963
24889
|
// this is an unhappy path, we dont care about speed
|
|
24964
24890
|
return createEmptyResponse();
|
|
24965
24891
|
}
|
|
@@ -25063,7 +24989,7 @@ const getSize = poly => {
|
|
|
25063
24989
|
* This function locates the controls.
|
|
25064
24990
|
* It'll be used both for drawing and for interaction.
|
|
25065
24991
|
*/
|
|
25066
|
-
const
|
|
24992
|
+
const createPolyPositionHandler = pointIndex => {
|
|
25067
24993
|
return function (dim, finalMatrix, polyObject) {
|
|
25068
24994
|
var _polyObject$canvas$vi, _polyObject$canvas;
|
|
25069
24995
|
const x = polyObject.points[pointIndex].x - polyObject.pathOffset.x,
|
|
@@ -25096,7 +25022,7 @@ const polyActionHandler = (eventData, transform, x, y) => {
|
|
|
25096
25022
|
/**
|
|
25097
25023
|
* Keep the polygon in the same position when we change its `width`/`height`/`top`/`left`.
|
|
25098
25024
|
*/
|
|
25099
|
-
const
|
|
25025
|
+
const factoryPolyActionHandler = (pointIndex, fn) => {
|
|
25100
25026
|
return function (eventData, transform, x, y) {
|
|
25101
25027
|
const poly = transform.target,
|
|
25102
25028
|
anchorPoint = new Point(poly.points[(pointIndex > 0 ? pointIndex : poly.points.length) - 1]),
|
|
@@ -25110,14 +25036,15 @@ const anchorWrapper = (pointIndex, fn) => {
|
|
|
25110
25036
|
return actionPerformed;
|
|
25111
25037
|
};
|
|
25112
25038
|
};
|
|
25039
|
+
const createPolyActionHandler = pointIndex => factoryPolyActionHandler(pointIndex, polyActionHandler);
|
|
25113
25040
|
function createPolyControls(arg0) {
|
|
25114
25041
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
25115
25042
|
const controls = {};
|
|
25116
25043
|
for (let idx = 0; idx < (typeof arg0 === 'number' ? arg0 : arg0.points.length); idx++) {
|
|
25117
25044
|
controls["p".concat(idx)] = new Control(_objectSpread2({
|
|
25118
25045
|
actionName: 'modifyPoly',
|
|
25119
|
-
positionHandler:
|
|
25120
|
-
actionHandler:
|
|
25046
|
+
positionHandler: createPolyPositionHandler(idx),
|
|
25047
|
+
actionHandler: createPolyActionHandler(idx)
|
|
25121
25048
|
}, options));
|
|
25122
25049
|
}
|
|
25123
25050
|
return controls;
|
|
@@ -25127,11 +25054,15 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
25127
25054
|
__proto__: null,
|
|
25128
25055
|
changeWidth: changeWidth,
|
|
25129
25056
|
createObjectDefaultControls: createObjectDefaultControls,
|
|
25057
|
+
createPolyActionHandler: createPolyActionHandler,
|
|
25130
25058
|
createPolyControls: createPolyControls,
|
|
25059
|
+
createPolyPositionHandler: createPolyPositionHandler,
|
|
25131
25060
|
createResizeControls: createResizeControls,
|
|
25132
25061
|
createTextboxDefaultControls: createTextboxDefaultControls,
|
|
25133
25062
|
dragHandler: dragHandler,
|
|
25063
|
+
factoryPolyActionHandler: factoryPolyActionHandler,
|
|
25134
25064
|
getLocalPoint: getLocalPoint,
|
|
25065
|
+
polyActionHandler: polyActionHandler,
|
|
25135
25066
|
renderCircleControl: renderCircleControl,
|
|
25136
25067
|
renderSquareControl: renderSquareControl,
|
|
25137
25068
|
rotationStyleHandler: rotationStyleHandler,
|
|
@@ -25226,25 +25157,23 @@ class BaseFilter {
|
|
|
25226
25157
|
const fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
|
|
25227
25158
|
const program = gl.createProgram();
|
|
25228
25159
|
if (!vertexShader || !fragmentShader || !program) {
|
|
25229
|
-
throw new
|
|
25160
|
+
throw new FabricError('Vertex, fragment shader or program creation error');
|
|
25230
25161
|
}
|
|
25231
25162
|
gl.shaderSource(vertexShader, vertexSource);
|
|
25232
25163
|
gl.compileShader(vertexShader);
|
|
25233
25164
|
if (!gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS)) {
|
|
25234
|
-
throw new
|
|
25165
|
+
throw new FabricError("Vertex shader compile error for ".concat(this.type, ": ").concat(gl.getShaderInfoLog(vertexShader)));
|
|
25235
25166
|
}
|
|
25236
25167
|
gl.shaderSource(fragmentShader, fragmentSource);
|
|
25237
25168
|
gl.compileShader(fragmentShader);
|
|
25238
25169
|
if (!gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS)) {
|
|
25239
|
-
throw new
|
|
25170
|
+
throw new FabricError("Fragment shader compile error for ".concat(this.type, ": ").concat(gl.getShaderInfoLog(fragmentShader)));
|
|
25240
25171
|
}
|
|
25241
25172
|
gl.attachShader(program, vertexShader);
|
|
25242
25173
|
gl.attachShader(program, fragmentShader);
|
|
25243
25174
|
gl.linkProgram(program);
|
|
25244
25175
|
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
25245
|
-
throw new
|
|
25246
|
-
// eslint-disable-next-line prefer-template
|
|
25247
|
-
'Shader link error for "${this.type}" ' + gl.getProgramInfoLog(program));
|
|
25176
|
+
throw new FabricError("Shader link error for \"".concat(this.type, "\" ").concat(gl.getProgramInfoLog(program)));
|
|
25248
25177
|
}
|
|
25249
25178
|
const uniformLocations = this.getUniformLocations(gl, program) || {};
|
|
25250
25179
|
uniformLocations.uStepW = gl.getUniformLocation(program, 'uStepW');
|
|
@@ -25843,7 +25772,7 @@ class BlendImage extends BaseFilter {
|
|
|
25843
25772
|
image
|
|
25844
25773
|
} = _ref2,
|
|
25845
25774
|
filterOptions = _objectWithoutProperties(_ref2, _excluded$3);
|
|
25846
|
-
return
|
|
25775
|
+
return FabricImage.fromObject(image, options).then(enlivedImage => new this(_objectSpread2(_objectSpread2({}, filterOptions), {}, {
|
|
25847
25776
|
image: enlivedImage
|
|
25848
25777
|
})));
|
|
25849
25778
|
}
|
|
@@ -27839,13 +27768,16 @@ exports.CircleBrush = CircleBrush;
|
|
|
27839
27768
|
exports.Color = Color;
|
|
27840
27769
|
exports.Control = Control;
|
|
27841
27770
|
exports.Ellipse = Ellipse;
|
|
27771
|
+
exports.FabricImage = FabricImage;
|
|
27772
|
+
exports.FabricObject = FabricObject;
|
|
27773
|
+
exports.FabricText = FabricText;
|
|
27842
27774
|
exports.Gradient = Gradient;
|
|
27843
27775
|
exports.Group = Group;
|
|
27844
27776
|
exports.IText = IText;
|
|
27845
27777
|
exports.Image = Image;
|
|
27846
27778
|
exports.Intersection = Intersection;
|
|
27847
27779
|
exports.Line = Line;
|
|
27848
|
-
exports.Object =
|
|
27780
|
+
exports.Object = _Object;
|
|
27849
27781
|
exports.Observable = Observable;
|
|
27850
27782
|
exports.Path = Path;
|
|
27851
27783
|
exports.Pattern = Pattern;
|