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.mjs
CHANGED
|
@@ -224,6 +224,26 @@ class Configuration extends BaseConfiguration {
|
|
|
224
224
|
}
|
|
225
225
|
const config = new Configuration();
|
|
226
226
|
|
|
227
|
+
const log = function (severity) {
|
|
228
|
+
for (var _len = arguments.length, optionalParams = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
229
|
+
optionalParams[_key - 1] = arguments[_key];
|
|
230
|
+
}
|
|
231
|
+
return (
|
|
232
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
233
|
+
console[severity]('fabric', ...optionalParams)
|
|
234
|
+
);
|
|
235
|
+
};
|
|
236
|
+
class FabricError extends Error {
|
|
237
|
+
constructor(message, options) {
|
|
238
|
+
super("fabric: ".concat(message), options);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
class SignalAbortedError extends FabricError {
|
|
242
|
+
constructor(context) {
|
|
243
|
+
super("".concat(context, " 'options.signal' is in 'aborted' state"));
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
227
247
|
class GLProbe {}
|
|
228
248
|
|
|
229
249
|
/**
|
|
@@ -255,7 +275,7 @@ class WebGLProbe extends GLProbe {
|
|
|
255
275
|
if (gl) {
|
|
256
276
|
this.maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE);
|
|
257
277
|
this.GLPrecision = ['highp', 'mediump', 'lowp'].find(precision => this.testPrecision(gl, precision));
|
|
258
|
-
|
|
278
|
+
log('log', "WebGL: max texture size ".concat(this.maxTextureSize));
|
|
259
279
|
}
|
|
260
280
|
}
|
|
261
281
|
isSupported(textureSize) {
|
|
@@ -393,7 +413,7 @@ class Cache {
|
|
|
393
413
|
}
|
|
394
414
|
const cache = new Cache();
|
|
395
415
|
|
|
396
|
-
var version = "6.0.0-
|
|
416
|
+
var version = "6.0.0-beta14";
|
|
397
417
|
|
|
398
418
|
// use this syntax so babel plugin see this import here
|
|
399
419
|
const VERSION = version;
|
|
@@ -441,7 +461,7 @@ class ClassRegistry {
|
|
|
441
461
|
getClass(classType) {
|
|
442
462
|
const constructor = this[JSON$1].get(classType);
|
|
443
463
|
if (!constructor) {
|
|
444
|
-
throw new
|
|
464
|
+
throw new FabricError("No class registered for ".concat(classType));
|
|
445
465
|
}
|
|
446
466
|
return constructor;
|
|
447
467
|
}
|
|
@@ -487,8 +507,8 @@ class AnimationRegistry extends Array {
|
|
|
487
507
|
}
|
|
488
508
|
|
|
489
509
|
/**
|
|
490
|
-
* Cancel all running animations attached to a
|
|
491
|
-
* @param {
|
|
510
|
+
* Cancel all running animations attached to a canvas on the next frame
|
|
511
|
+
* @param {StaticCanvas} canvas
|
|
492
512
|
*/
|
|
493
513
|
cancelByCanvas(canvas) {
|
|
494
514
|
if (!canvas) {
|
|
@@ -496,7 +516,7 @@ class AnimationRegistry extends Array {
|
|
|
496
516
|
}
|
|
497
517
|
const animations = this.filter(animation => {
|
|
498
518
|
var _animation$target;
|
|
499
|
-
return typeof animation.target === 'object' && ((_animation$target = animation.target) === null || _animation$target === void 0 ? void 0 : _animation$target.canvas) === canvas;
|
|
519
|
+
return animation.target === canvas || typeof animation.target === 'object' && ((_animation$target = animation.target) === null || _animation$target === void 0 ? void 0 : _animation$target.canvas) === canvas;
|
|
500
520
|
});
|
|
501
521
|
animations.forEach(animation => animation.abort());
|
|
502
522
|
return animations;
|
|
@@ -1433,7 +1453,7 @@ function createCollectionMixin(Base) {
|
|
|
1433
1453
|
// we iterate reverse order to collect top first in case of click.
|
|
1434
1454
|
for (let i = this._objects.length - 1; i >= 0; i--) {
|
|
1435
1455
|
const object = this._objects[i];
|
|
1436
|
-
if (object.selectable && object.visible && (includeIntersecting && object.intersectsWithRect(tl, br, true) || object.isContainedWithinRect(tl, br, true) || includeIntersecting && object.containsPoint(tl,
|
|
1456
|
+
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))) {
|
|
1437
1457
|
objects.push(object);
|
|
1438
1458
|
}
|
|
1439
1459
|
}
|
|
@@ -1523,7 +1543,7 @@ const uid = () => id++;
|
|
|
1523
1543
|
const createCanvasElement = () => {
|
|
1524
1544
|
const element = getFabricDocument().createElement('canvas');
|
|
1525
1545
|
if (!element || typeof element.getContext === 'undefined') {
|
|
1526
|
-
throw new
|
|
1546
|
+
throw new FabricError('Failed to create `canvas` element');
|
|
1527
1547
|
}
|
|
1528
1548
|
return element;
|
|
1529
1549
|
};
|
|
@@ -1811,7 +1831,7 @@ const loadImage = function (url) {
|
|
|
1811
1831
|
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1812
1832
|
return new Promise(function (resolve, reject) {
|
|
1813
1833
|
if (signal && signal.aborted) {
|
|
1814
|
-
return reject(new
|
|
1834
|
+
return reject(new SignalAbortedError('loadImage'));
|
|
1815
1835
|
}
|
|
1816
1836
|
const img = createImage();
|
|
1817
1837
|
let abort;
|
|
@@ -1836,7 +1856,7 @@ const loadImage = function (url) {
|
|
|
1836
1856
|
img.onload = done;
|
|
1837
1857
|
img.onerror = function () {
|
|
1838
1858
|
abort && (signal === null || signal === void 0 ? void 0 : signal.removeEventListener('abort', abort));
|
|
1839
|
-
reject(new
|
|
1859
|
+
reject(new FabricError("Error loading ".concat(img.src)));
|
|
1840
1860
|
};
|
|
1841
1861
|
crossOrigin && (img.crossOrigin = crossOrigin);
|
|
1842
1862
|
img.src = url;
|
|
@@ -2694,22 +2714,29 @@ const matrixToSVG = transform => 'matrix(' + transform.map(value => toFixed(valu
|
|
|
2694
2714
|
* we work around it by "moving" alpha channel into opacity attribute and setting fill's alpha to 1
|
|
2695
2715
|
* @param prop
|
|
2696
2716
|
* @param value
|
|
2717
|
+
* @param {boolean} inlineStyle The default is inline style, the separator used is ":", The other is "="
|
|
2697
2718
|
* @returns
|
|
2698
2719
|
*/
|
|
2699
|
-
const colorPropToSVG = (prop, value)
|
|
2720
|
+
const colorPropToSVG = function (prop, value) {
|
|
2721
|
+
let inlineStyle = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
2722
|
+
let colorValue;
|
|
2723
|
+
let opacityValue;
|
|
2700
2724
|
if (!value) {
|
|
2701
|
-
|
|
2725
|
+
colorValue = 'none';
|
|
2702
2726
|
} else if (value.toLive) {
|
|
2703
|
-
|
|
2727
|
+
colorValue = "url(#SVGID_".concat(value.id, ")");
|
|
2704
2728
|
} else {
|
|
2705
2729
|
const color = new Color(value),
|
|
2706
2730
|
opacity = color.getAlpha();
|
|
2707
|
-
|
|
2731
|
+
colorValue = color.toRgb();
|
|
2708
2732
|
if (opacity !== 1) {
|
|
2709
|
-
|
|
2710
|
-
str += "".concat(prop, "-opacity: ").concat(opacity.toString(), "; ");
|
|
2733
|
+
opacityValue = opacity.toString();
|
|
2711
2734
|
}
|
|
2712
|
-
|
|
2735
|
+
}
|
|
2736
|
+
if (inlineStyle) {
|
|
2737
|
+
return "".concat(prop, ": ").concat(colorValue, "; ").concat(opacityValue ? "".concat(prop, "-opacity: ").concat(opacityValue, "; ") : '');
|
|
2738
|
+
} else {
|
|
2739
|
+
return "".concat(prop, "=\"").concat(colorValue, "\" ").concat(opacityValue ? "".concat(prop, "-opacity=\"").concat(opacityValue, "\" ") : '');
|
|
2713
2740
|
}
|
|
2714
2741
|
};
|
|
2715
2742
|
const createSVGRect = function (color, _ref) {
|
|
@@ -2720,7 +2747,7 @@ const createSVGRect = function (color, _ref) {
|
|
|
2720
2747
|
height
|
|
2721
2748
|
} = _ref;
|
|
2722
2749
|
let precision = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : config.NUM_FRACTION_DIGITS;
|
|
2723
|
-
const svgColor = colorPropToSVG('fill', color);
|
|
2750
|
+
const svgColor = colorPropToSVG('fill', color, false);
|
|
2724
2751
|
const [x, y, w, h] = [left, top, width, height].map(value => toFixed(value, precision));
|
|
2725
2752
|
return "<rect ".concat(svgColor, " x=\"").concat(x, "\" y=\"").concat(y, "\" width=\"").concat(w, "\" height=\"").concat(h, "\"></rect>");
|
|
2726
2753
|
};
|
|
@@ -2932,13 +2959,10 @@ class StaticCanvasDOMManager {
|
|
|
2932
2959
|
}
|
|
2933
2960
|
createLowerCanvas(arg0) {
|
|
2934
2961
|
// canvasEl === 'HTMLCanvasElement' does not work on jsdom/node
|
|
2935
|
-
const el = isHTMLCanvas(arg0) ? arg0 : getFabricDocument().getElementById(arg0) || createCanvasElement();
|
|
2962
|
+
const el = isHTMLCanvas(arg0) ? arg0 : arg0 && getFabricDocument().getElementById(arg0) || createCanvasElement();
|
|
2936
2963
|
if (el.hasAttribute('data-fabric')) {
|
|
2937
|
-
|
|
2938
|
-
throw new Error('fabric.js: trying to initialize a canvas that has already been initialized');
|
|
2939
|
-
/* _DEV_MODE_END_ */
|
|
2964
|
+
throw new FabricError('Trying to initialize a canvas that has already been initialized. Did you forget to dispose the canvas?');
|
|
2940
2965
|
}
|
|
2941
|
-
|
|
2942
2966
|
this._originalCanvasStyle = el.style.cssText;
|
|
2943
2967
|
el.setAttribute('data-fabric', 'main');
|
|
2944
2968
|
el.classList.add('lower-canvas');
|
|
@@ -3107,9 +3131,7 @@ class StaticCanvas extends createCollectionMixin(CommonMethods) {
|
|
|
3107
3131
|
}
|
|
3108
3132
|
_onObjectAdded(obj) {
|
|
3109
3133
|
if (obj.canvas && obj.canvas !== this) {
|
|
3110
|
-
|
|
3111
|
-
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');
|
|
3112
|
-
/* _DEV_MODE_END_ */
|
|
3134
|
+
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');
|
|
3113
3135
|
obj.canvas.remove(obj);
|
|
3114
3136
|
}
|
|
3115
3137
|
obj._set('canvas', this);
|
|
@@ -4039,7 +4061,7 @@ class StaticCanvas extends createCollectionMixin(CommonMethods) {
|
|
|
4039
4061
|
signal
|
|
4040
4062
|
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
4041
4063
|
if (!json) {
|
|
4042
|
-
return Promise.reject(new
|
|
4064
|
+
return Promise.reject(new FabricError('`json` is undefined'));
|
|
4043
4065
|
}
|
|
4044
4066
|
|
|
4045
4067
|
// parse json if it wasn't already
|
|
@@ -4209,6 +4231,7 @@ class StaticCanvas extends createCollectionMixin(CommonMethods) {
|
|
|
4209
4231
|
width: this.width,
|
|
4210
4232
|
height: this.height
|
|
4211
4233
|
});
|
|
4234
|
+
runningAnimations.cancelByCanvas(this);
|
|
4212
4235
|
this.disposed = true;
|
|
4213
4236
|
return new Promise((resolve, reject) => {
|
|
4214
4237
|
const task = () => {
|
|
@@ -4495,10 +4518,10 @@ const sendPointToPlane = function (point) {
|
|
|
4495
4518
|
const transformPointRelativeToCanvas = (point, canvas, relationBefore, relationAfter) => {
|
|
4496
4519
|
// is this still needed with TS?
|
|
4497
4520
|
if (relationBefore !== 'child' && relationBefore !== 'sibling') {
|
|
4498
|
-
throw new
|
|
4521
|
+
throw new FabricError("received bad argument ".concat(relationBefore));
|
|
4499
4522
|
}
|
|
4500
4523
|
if (relationAfter !== 'child' && relationAfter !== 'sibling') {
|
|
4501
|
-
throw new
|
|
4524
|
+
throw new FabricError("received bad argument ".concat(relationAfter));
|
|
4502
4525
|
}
|
|
4503
4526
|
if (relationBefore === relationAfter) {
|
|
4504
4527
|
return point;
|
|
@@ -5605,6 +5628,31 @@ class Intersection {
|
|
|
5605
5628
|
}
|
|
5606
5629
|
}
|
|
5607
5630
|
|
|
5631
|
+
/**
|
|
5632
|
+
* Use the ray casting algorithm to determine if {@link point} is in the polygon defined by {@link points}
|
|
5633
|
+
* @see https://en.wikipedia.org/wiki/Point_in_polygon
|
|
5634
|
+
* @param point
|
|
5635
|
+
* @param points polygon points
|
|
5636
|
+
* @returns
|
|
5637
|
+
*/
|
|
5638
|
+
static isPointInPolygon(point, points) {
|
|
5639
|
+
const other = new Point(point).setX(Math.min(point.x - 1, ...points.map(p => p.x)));
|
|
5640
|
+
let hits = 0;
|
|
5641
|
+
for (let index = 0; index < points.length; index++) {
|
|
5642
|
+
const inter = this.intersectSegmentSegment(
|
|
5643
|
+
// polygon side
|
|
5644
|
+
points[index], points[(index + 1) % points.length],
|
|
5645
|
+
// ray
|
|
5646
|
+
point, other);
|
|
5647
|
+
if (inter.includes(point)) {
|
|
5648
|
+
// point is on the polygon side
|
|
5649
|
+
return true;
|
|
5650
|
+
}
|
|
5651
|
+
hits += Number(inter.status === 'Intersection');
|
|
5652
|
+
}
|
|
5653
|
+
return hits % 2 === 1;
|
|
5654
|
+
}
|
|
5655
|
+
|
|
5608
5656
|
/**
|
|
5609
5657
|
* Checks if a line intersects another
|
|
5610
5658
|
* @see {@link https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection line intersection}
|
|
@@ -6141,21 +6189,15 @@ class ObjectGeometry extends ObjectOrigin {
|
|
|
6141
6189
|
* Checks if object is fully contained within area of another object
|
|
6142
6190
|
* @param {Object} other Object to test
|
|
6143
6191
|
* @param {Boolean} [absolute] use coordinates without viewportTransform
|
|
6144
|
-
* @param {Boolean} [calculate] use coordinates of current position instead of
|
|
6192
|
+
* @param {Boolean} [calculate] use coordinates of current position instead of stored ones
|
|
6145
6193
|
* @return {Boolean} true if object is fully contained within area of another object
|
|
6146
6194
|
*/
|
|
6147
6195
|
isContainedWithinObject(other) {
|
|
6148
6196
|
let absolute = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
6149
6197
|
let calculate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
6150
|
-
const points = this.getCoords(absolute, calculate)
|
|
6151
|
-
|
|
6152
|
-
|
|
6153
|
-
for (let i = 0; i < 4; i++) {
|
|
6154
|
-
if (!other.containsPoint(points[i], lines)) {
|
|
6155
|
-
return false;
|
|
6156
|
-
}
|
|
6157
|
-
}
|
|
6158
|
-
return true;
|
|
6198
|
+
const points = this.getCoords(absolute, calculate);
|
|
6199
|
+
calculate && other.getCoords(absolute, true);
|
|
6200
|
+
return points.every(point => other.containsPoint(point));
|
|
6159
6201
|
}
|
|
6160
6202
|
|
|
6161
6203
|
/**
|
|
@@ -6177,19 +6219,14 @@ class ObjectGeometry extends ObjectOrigin {
|
|
|
6177
6219
|
/**
|
|
6178
6220
|
* Checks if point is inside the object
|
|
6179
6221
|
* @param {Point} point Point to check against
|
|
6180
|
-
* @param {Object} [lines] object returned from @method _getImageLines
|
|
6181
6222
|
* @param {Boolean} [absolute] use coordinates without viewportTransform
|
|
6182
6223
|
* @param {Boolean} [calculate] use coordinates of current position instead of stored ones
|
|
6183
6224
|
* @return {Boolean} true if point is inside the object
|
|
6184
6225
|
*/
|
|
6185
|
-
containsPoint(point
|
|
6186
|
-
let absolute = arguments.length >
|
|
6187
|
-
let calculate = arguments.length >
|
|
6188
|
-
|
|
6189
|
-
imageLines = lines || this._getImageLines(coords),
|
|
6190
|
-
xPoints = this._findCrossPoints(point, imageLines);
|
|
6191
|
-
// if xPoints is odd then point is inside the object
|
|
6192
|
-
return xPoints !== 0 && xPoints % 2 === 1;
|
|
6226
|
+
containsPoint(point) {
|
|
6227
|
+
let absolute = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
6228
|
+
let calculate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
6229
|
+
return Intersection.isPointInPolygon(point, this.getCoords(absolute, calculate));
|
|
6193
6230
|
}
|
|
6194
6231
|
|
|
6195
6232
|
/**
|
|
@@ -6231,7 +6268,7 @@ class ObjectGeometry extends ObjectOrigin {
|
|
|
6231
6268
|
_containsCenterOfCanvas(pointTL, pointBR, calculate) {
|
|
6232
6269
|
// worst case scenario the object is so big that contains the screen
|
|
6233
6270
|
const centerPoint = pointTL.midPointFrom(pointBR);
|
|
6234
|
-
return this.containsPoint(centerPoint,
|
|
6271
|
+
return this.containsPoint(centerPoint, true, calculate);
|
|
6235
6272
|
}
|
|
6236
6273
|
|
|
6237
6274
|
/**
|
|
@@ -6254,100 +6291,6 @@ class ObjectGeometry extends ObjectOrigin {
|
|
|
6254
6291
|
return allPointsAreOutside && this._containsCenterOfCanvas(tl, br, calculate);
|
|
6255
6292
|
}
|
|
6256
6293
|
|
|
6257
|
-
/**
|
|
6258
|
-
* Method that returns an object with the object edges in it, given the coordinates of the corners
|
|
6259
|
-
* @private
|
|
6260
|
-
* @param {Object} lineCoords or aCoords Coordinates of the object corners
|
|
6261
|
-
*/
|
|
6262
|
-
_getImageLines(_ref) {
|
|
6263
|
-
let {
|
|
6264
|
-
tl,
|
|
6265
|
-
tr,
|
|
6266
|
-
bl,
|
|
6267
|
-
br
|
|
6268
|
-
} = _ref;
|
|
6269
|
-
const lines = {
|
|
6270
|
-
topline: {
|
|
6271
|
-
o: tl,
|
|
6272
|
-
d: tr
|
|
6273
|
-
},
|
|
6274
|
-
rightline: {
|
|
6275
|
-
o: tr,
|
|
6276
|
-
d: br
|
|
6277
|
-
},
|
|
6278
|
-
bottomline: {
|
|
6279
|
-
o: br,
|
|
6280
|
-
d: bl
|
|
6281
|
-
},
|
|
6282
|
-
leftline: {
|
|
6283
|
-
o: bl,
|
|
6284
|
-
d: tl
|
|
6285
|
-
}
|
|
6286
|
-
};
|
|
6287
|
-
|
|
6288
|
-
// // debugging
|
|
6289
|
-
// if (this.canvas.contextTop) {
|
|
6290
|
-
// this.canvas.contextTop.fillRect(lines.bottomline.d.x, lines.bottomline.d.y, 2, 2);
|
|
6291
|
-
// this.canvas.contextTop.fillRect(lines.bottomline.o.x, lines.bottomline.o.y, 2, 2);
|
|
6292
|
-
//
|
|
6293
|
-
// this.canvas.contextTop.fillRect(lines.leftline.d.x, lines.leftline.d.y, 2, 2);
|
|
6294
|
-
// this.canvas.contextTop.fillRect(lines.leftline.o.x, lines.leftline.o.y, 2, 2);
|
|
6295
|
-
//
|
|
6296
|
-
// this.canvas.contextTop.fillRect(lines.topline.d.x, lines.topline.d.y, 2, 2);
|
|
6297
|
-
// this.canvas.contextTop.fillRect(lines.topline.o.x, lines.topline.o.y, 2, 2);
|
|
6298
|
-
//
|
|
6299
|
-
// this.canvas.contextTop.fillRect(lines.rightline.d.x, lines.rightline.d.y, 2, 2);
|
|
6300
|
-
// this.canvas.contextTop.fillRect(lines.rightline.o.x, lines.rightline.o.y, 2, 2);
|
|
6301
|
-
// }
|
|
6302
|
-
|
|
6303
|
-
return lines;
|
|
6304
|
-
}
|
|
6305
|
-
|
|
6306
|
-
/**
|
|
6307
|
-
* Helper method to determine how many cross points are between the 4 object edges
|
|
6308
|
-
* and the horizontal line determined by a point on canvas
|
|
6309
|
-
* @private
|
|
6310
|
-
* @param {Point} point Point to check
|
|
6311
|
-
* @param {Object} lines Coordinates of the object being evaluated
|
|
6312
|
-
* @return {number} number of crossPoint
|
|
6313
|
-
*/
|
|
6314
|
-
_findCrossPoints(point, lines) {
|
|
6315
|
-
let xcount = 0;
|
|
6316
|
-
for (const lineKey in lines) {
|
|
6317
|
-
let xi;
|
|
6318
|
-
const iLine = lines[lineKey];
|
|
6319
|
-
// optimization 1: line below point. no cross
|
|
6320
|
-
if (iLine.o.y < point.y && iLine.d.y < point.y) {
|
|
6321
|
-
continue;
|
|
6322
|
-
}
|
|
6323
|
-
// optimization 2: line above point. no cross
|
|
6324
|
-
if (iLine.o.y >= point.y && iLine.d.y >= point.y) {
|
|
6325
|
-
continue;
|
|
6326
|
-
}
|
|
6327
|
-
// optimization 3: vertical line case
|
|
6328
|
-
if (iLine.o.x === iLine.d.x && iLine.o.x >= point.x) {
|
|
6329
|
-
xi = iLine.o.x;
|
|
6330
|
-
}
|
|
6331
|
-
// calculate the intersection point
|
|
6332
|
-
else {
|
|
6333
|
-
const b1 = 0;
|
|
6334
|
-
const b2 = (iLine.d.y - iLine.o.y) / (iLine.d.x - iLine.o.x);
|
|
6335
|
-
const a1 = point.y - b1 * point.x;
|
|
6336
|
-
const a2 = iLine.o.y - b2 * iLine.o.x;
|
|
6337
|
-
xi = -(a1 - a2) / (b1 - b2);
|
|
6338
|
-
}
|
|
6339
|
-
// don't count xi < point.x cases
|
|
6340
|
-
if (xi >= point.x) {
|
|
6341
|
-
xcount += 1;
|
|
6342
|
-
}
|
|
6343
|
-
// optimization 4: specific for square images
|
|
6344
|
-
if (xcount === 2) {
|
|
6345
|
-
break;
|
|
6346
|
-
}
|
|
6347
|
-
}
|
|
6348
|
-
return xcount;
|
|
6349
|
-
}
|
|
6350
|
-
|
|
6351
6294
|
/**
|
|
6352
6295
|
* Returns coordinates of object's bounding rectangle (left, top, width, height)
|
|
6353
6296
|
* the box is intended as aligned to axis of canvas.
|
|
@@ -7113,7 +7056,7 @@ let FabricObject$1 = class FabricObject extends AnimatableObject {
|
|
|
7113
7056
|
return name.toLowerCase();
|
|
7114
7057
|
}
|
|
7115
7058
|
set type(value) {
|
|
7116
|
-
|
|
7059
|
+
log('warn', 'Setting type has no effect', value);
|
|
7117
7060
|
}
|
|
7118
7061
|
|
|
7119
7062
|
/**
|
|
@@ -8033,7 +7976,7 @@ let FabricObject$1 = class FabricObject extends AnimatableObject {
|
|
|
8033
7976
|
* @param {Boolean} [options.enableRetinaScaling] Enable retina scaling for clone image. Introduce in 1.6.4
|
|
8034
7977
|
* @param {Boolean} [options.withoutTransform] Remove current object transform ( no scale , no angle, no flip, no skew ). Introduced in 2.3.4
|
|
8035
7978
|
* @param {Boolean} [options.withoutShadow] Remove current object shadow. Introduced in 2.4.2
|
|
8036
|
-
* @return {
|
|
7979
|
+
* @return {FabricImage} Object cloned as image.
|
|
8037
7980
|
*/
|
|
8038
7981
|
cloneAsImage(options) {
|
|
8039
7982
|
const canvasEl = this.toCanvasElement(options);
|
|
@@ -8530,28 +8473,28 @@ class Control {
|
|
|
8530
8473
|
* @type {?Number}
|
|
8531
8474
|
* @default null
|
|
8532
8475
|
*/
|
|
8533
|
-
_defineProperty(this, "sizeX",
|
|
8476
|
+
_defineProperty(this, "sizeX", 0);
|
|
8534
8477
|
/**
|
|
8535
8478
|
* Sets the height of the control. If null, defaults to object's cornerSize.
|
|
8536
8479
|
* Expects both sizeX and sizeY to be set when set.
|
|
8537
8480
|
* @type {?Number}
|
|
8538
8481
|
* @default null
|
|
8539
8482
|
*/
|
|
8540
|
-
_defineProperty(this, "sizeY",
|
|
8483
|
+
_defineProperty(this, "sizeY", 0);
|
|
8541
8484
|
/**
|
|
8542
8485
|
* Sets the length of the touch area of the control. If null, defaults to object's touchCornerSize.
|
|
8543
8486
|
* Expects both touchSizeX and touchSizeY to be set when set.
|
|
8544
8487
|
* @type {?Number}
|
|
8545
8488
|
* @default null
|
|
8546
8489
|
*/
|
|
8547
|
-
_defineProperty(this, "touchSizeX",
|
|
8490
|
+
_defineProperty(this, "touchSizeX", 0);
|
|
8548
8491
|
/**
|
|
8549
8492
|
* Sets the height of the touch area of the control. If null, defaults to object's touchCornerSize.
|
|
8550
8493
|
* Expects both touchSizeX and touchSizeY to be set when set.
|
|
8551
8494
|
* @type {?Number}
|
|
8552
8495
|
* @default null
|
|
8553
8496
|
*/
|
|
8554
|
-
_defineProperty(this, "touchSizeY",
|
|
8497
|
+
_defineProperty(this, "touchSizeY", 0);
|
|
8555
8498
|
/**
|
|
8556
8499
|
* Css cursor style to display when the control is hovered.
|
|
8557
8500
|
* if the method `cursorStyleHandler` is provided, this property is ignored.
|
|
@@ -8596,10 +8539,16 @@ class Control {
|
|
|
8596
8539
|
* @return {Boolean} true if the action/event modified the object
|
|
8597
8540
|
*/
|
|
8598
8541
|
|
|
8599
|
-
shouldActivate(controlKey, fabricObject) {
|
|
8542
|
+
shouldActivate(controlKey, fabricObject, pointer, _ref) {
|
|
8600
8543
|
var _fabricObject$canvas;
|
|
8544
|
+
let {
|
|
8545
|
+
tl,
|
|
8546
|
+
tr,
|
|
8547
|
+
br,
|
|
8548
|
+
bl
|
|
8549
|
+
} = _ref;
|
|
8601
8550
|
// TODO: locking logic can be handled here instead of in the control handler logic
|
|
8602
|
-
return ((_fabricObject$canvas = fabricObject.canvas) === null || _fabricObject$canvas === void 0 ? void 0 : _fabricObject$canvas.getActiveObject()) === fabricObject && fabricObject.isControlVisible(controlKey);
|
|
8551
|
+
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]);
|
|
8603
8552
|
}
|
|
8604
8553
|
|
|
8605
8554
|
/**
|
|
@@ -8692,36 +8641,15 @@ class Control {
|
|
|
8692
8641
|
* @param {Number} centerY y coordinate where the control center should be
|
|
8693
8642
|
* @param {boolean} isTouch true if touch corner, false if normal corner
|
|
8694
8643
|
*/
|
|
8695
|
-
calcCornerCoords(
|
|
8696
|
-
|
|
8697
|
-
|
|
8698
|
-
|
|
8699
|
-
if (xSize && ySize && xSize !== ySize) {
|
|
8700
|
-
// handle rectangular corners
|
|
8701
|
-
const controlTriangleAngle = Math.atan2(ySize, xSize);
|
|
8702
|
-
const cornerHypotenuse = Math.sqrt(xSize * xSize + ySize * ySize) / 2;
|
|
8703
|
-
const newTheta = controlTriangleAngle - degreesToRadians(objectAngle);
|
|
8704
|
-
const newThetaComp = halfPI - controlTriangleAngle - degreesToRadians(objectAngle);
|
|
8705
|
-
cosHalfOffset = cornerHypotenuse * cos(newTheta);
|
|
8706
|
-
sinHalfOffset = cornerHypotenuse * sin(newTheta);
|
|
8707
|
-
// use complementary angle for two corners
|
|
8708
|
-
cosHalfOffsetComp = cornerHypotenuse * cos(newThetaComp);
|
|
8709
|
-
sinHalfOffsetComp = cornerHypotenuse * sin(newThetaComp);
|
|
8710
|
-
} else {
|
|
8711
|
-
// handle square corners
|
|
8712
|
-
// use default object corner size unless size is defined
|
|
8713
|
-
const cornerSize = xSize && ySize ? xSize : objectCornerSize;
|
|
8714
|
-
const cornerHypotenuse = cornerSize * Math.SQRT1_2;
|
|
8715
|
-
// complementary angles are equal since they're both 45 degrees
|
|
8716
|
-
const newTheta = degreesToRadians(45 - objectAngle);
|
|
8717
|
-
cosHalfOffset = cosHalfOffsetComp = cornerHypotenuse * cos(newTheta);
|
|
8718
|
-
sinHalfOffset = sinHalfOffsetComp = cornerHypotenuse * sin(newTheta);
|
|
8719
|
-
}
|
|
8644
|
+
calcCornerCoords(angle, objectCornerSize, centerX, centerY, isTouch, fabricObject) {
|
|
8645
|
+
const t = multiplyTransformMatrixArray([createTranslateMatrix(centerX, centerY), createRotateMatrix({
|
|
8646
|
+
angle
|
|
8647
|
+
}), createScaleMatrix((isTouch ? this.touchSizeX : this.sizeX) || objectCornerSize, (isTouch ? this.touchSizeY : this.sizeY) || objectCornerSize)]);
|
|
8720
8648
|
return {
|
|
8721
|
-
tl: new Point(
|
|
8722
|
-
tr: new Point(
|
|
8723
|
-
bl: new Point(
|
|
8724
|
-
br: new Point(
|
|
8649
|
+
tl: new Point(-0.5, -0.5).transform(t),
|
|
8650
|
+
tr: new Point(0.5, -0.5).transform(t),
|
|
8651
|
+
bl: new Point(-0.5, 0.5).transform(t),
|
|
8652
|
+
br: new Point(0.5, 0.5).transform(t)
|
|
8725
8653
|
};
|
|
8726
8654
|
}
|
|
8727
8655
|
|
|
@@ -9363,34 +9291,14 @@ class InteractiveFabricObject extends FabricObject$1 {
|
|
|
9363
9291
|
return '';
|
|
9364
9292
|
}
|
|
9365
9293
|
this.__corner = undefined;
|
|
9366
|
-
// had to keep the reverse loop because was breaking tests
|
|
9367
9294
|
const cornerEntries = Object.entries(this.oCoords);
|
|
9368
9295
|
for (let i = cornerEntries.length - 1; i >= 0; i--) {
|
|
9369
9296
|
const [key, corner] = cornerEntries[i];
|
|
9370
|
-
if (this.controls[key].shouldActivate(key, this)) {
|
|
9371
|
-
|
|
9372
|
-
|
|
9373
|
-
if (xPoints !== 0 && xPoints % 2 === 1) {
|
|
9374
|
-
this.__corner = key;
|
|
9375
|
-
return key;
|
|
9376
|
-
}
|
|
9297
|
+
if (this.controls[key].shouldActivate(key, this, pointer, forTouch ? corner.touchCorner : corner.corner)) {
|
|
9298
|
+
// this.canvas.contextTop.fillRect(pointer.x - 1, pointer.y - 1, 2, 2);
|
|
9299
|
+
return this.__corner = key;
|
|
9377
9300
|
}
|
|
9378
|
-
|
|
9379
|
-
// // debugging
|
|
9380
|
-
//
|
|
9381
|
-
// this.canvas.contextTop.fillRect(lines.bottomline.d.x, lines.bottomline.d.y, 2, 2);
|
|
9382
|
-
// this.canvas.contextTop.fillRect(lines.bottomline.o.x, lines.bottomline.o.y, 2, 2);
|
|
9383
|
-
//
|
|
9384
|
-
// this.canvas.contextTop.fillRect(lines.leftline.d.x, lines.leftline.d.y, 2, 2);
|
|
9385
|
-
// this.canvas.contextTop.fillRect(lines.leftline.o.x, lines.leftline.o.y, 2, 2);
|
|
9386
|
-
//
|
|
9387
|
-
// this.canvas.contextTop.fillRect(lines.topline.d.x, lines.topline.d.y, 2, 2);
|
|
9388
|
-
// this.canvas.contextTop.fillRect(lines.topline.o.x, lines.topline.o.y, 2, 2);
|
|
9389
|
-
//
|
|
9390
|
-
// this.canvas.contextTop.fillRect(lines.rightline.d.x, lines.rightline.d.y, 2, 2);
|
|
9391
|
-
// this.canvas.contextTop.fillRect(lines.rightline.o.x, lines.rightline.o.y, 2, 2);
|
|
9392
9301
|
}
|
|
9393
|
-
|
|
9394
9302
|
return '';
|
|
9395
9303
|
}
|
|
9396
9304
|
|
|
@@ -9446,8 +9354,9 @@ class InteractiveFabricObject extends FabricObject$1 {
|
|
|
9446
9354
|
* @private
|
|
9447
9355
|
*/
|
|
9448
9356
|
_calcCornerCoords(control, position) {
|
|
9449
|
-
const
|
|
9450
|
-
const
|
|
9357
|
+
const angle = this.getTotalAngle();
|
|
9358
|
+
const corner = control.calcCornerCoords(angle, this.cornerSize, position.x, position.y, false, this);
|
|
9359
|
+
const touchCorner = control.calcCornerCoords(angle, this.touchCornerSize, position.x, position.y, true, this);
|
|
9451
9360
|
return {
|
|
9452
9361
|
corner,
|
|
9453
9362
|
touchCorner
|
|
@@ -9465,7 +9374,7 @@ class InteractiveFabricObject extends FabricObject$1 {
|
|
|
9465
9374
|
setCoords() {
|
|
9466
9375
|
super.setCoords();
|
|
9467
9376
|
// set coordinates of the draggable boxes in the corners used to scale/rotate the image
|
|
9468
|
-
this.oCoords = this.calcOCoords();
|
|
9377
|
+
this.canvas && (this.oCoords = this.calcOCoords());
|
|
9469
9378
|
}
|
|
9470
9379
|
|
|
9471
9380
|
/**
|
|
@@ -9843,6 +9752,14 @@ applyMixins(FabricObject, [FabricObjectSVGExportMixin]);
|
|
|
9843
9752
|
classRegistry.setClass(FabricObject);
|
|
9844
9753
|
classRegistry.setClass(FabricObject, 'object');
|
|
9845
9754
|
|
|
9755
|
+
/**
|
|
9756
|
+
* @deprecated The old fabric.Object class can't be imported as Object because of conflict with the JS api
|
|
9757
|
+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object
|
|
9758
|
+
* For this reason it has been renamed to FabricObject.
|
|
9759
|
+
* Please use `import { FabricObject }` in place of `import { Object as FabricObject }`
|
|
9760
|
+
*/
|
|
9761
|
+
class _Object extends FabricObject {}
|
|
9762
|
+
|
|
9846
9763
|
/**
|
|
9847
9764
|
* Returns true if context has transparent pixel
|
|
9848
9765
|
* at specified location (taking tolerance into account)
|
|
@@ -10547,15 +10464,11 @@ class Group extends createCollectionMixin(FabricObject) {
|
|
|
10547
10464
|
canEnterGroup(object) {
|
|
10548
10465
|
if (object === this || this.isDescendantOf(object)) {
|
|
10549
10466
|
// prevent circular object tree
|
|
10550
|
-
|
|
10551
|
-
console.error('fabric.Group: circular object trees are not supported, this call has no effect');
|
|
10552
|
-
/* _DEV_MODE_END_ */
|
|
10467
|
+
log('error', 'Group: circular object trees are not supported, this call has no effect');
|
|
10553
10468
|
return false;
|
|
10554
10469
|
} else if (this._objects.indexOf(object) !== -1) {
|
|
10555
10470
|
// is already in the objects array
|
|
10556
|
-
|
|
10557
|
-
console.error('fabric.Group: duplicate objects are not supported inside group, this call has no effect');
|
|
10558
|
-
/* _DEV_MODE_END_ */
|
|
10471
|
+
log('error', 'Group: duplicate objects are not supported inside group, this call has no effect');
|
|
10559
10472
|
return false;
|
|
10560
10473
|
}
|
|
10561
10474
|
return true;
|
|
@@ -11408,7 +11321,9 @@ class ActiveSelection extends Group {
|
|
|
11408
11321
|
// save ref to group for later in order to return to it
|
|
11409
11322
|
const parent = object.group;
|
|
11410
11323
|
parent._exitGroup(object);
|
|
11411
|
-
|
|
11324
|
+
// make sure we are setting the correct owning group
|
|
11325
|
+
// in case `object` is transferred between active selections
|
|
11326
|
+
!(parent instanceof ActiveSelection) && (object.__owningGroup = parent);
|
|
11412
11327
|
}
|
|
11413
11328
|
this._enterGroup(object, removeParentTransform);
|
|
11414
11329
|
return true;
|
|
@@ -13060,7 +12975,7 @@ function request(url) {
|
|
|
13060
12975
|
xhr.onerror = xhr.ontimeout = noop;
|
|
13061
12976
|
};
|
|
13062
12977
|
if (signal && signal.aborted) {
|
|
13063
|
-
throw new
|
|
12978
|
+
throw new SignalAbortedError('request');
|
|
13064
12979
|
} else if (signal) {
|
|
13065
12980
|
signal.addEventListener('abort', abort, {
|
|
13066
12981
|
once: true
|
|
@@ -13507,9 +13422,9 @@ class SelectableCanvas extends StaticCanvas {
|
|
|
13507
13422
|
* @type FabricObject[]
|
|
13508
13423
|
* @private
|
|
13509
13424
|
*/
|
|
13510
|
-
_defineProperty(this, "_objectsToRender",
|
|
13425
|
+
_defineProperty(this, "_objectsToRender", void 0);
|
|
13511
13426
|
/**
|
|
13512
|
-
* hold a
|
|
13427
|
+
* hold a reference to a data structure that contains information
|
|
13513
13428
|
* on the current on going transform
|
|
13514
13429
|
* @type
|
|
13515
13430
|
* @private
|
|
@@ -13577,6 +13492,10 @@ class SelectableCanvas extends StaticCanvas {
|
|
|
13577
13492
|
}
|
|
13578
13493
|
super._onObjectRemoved(obj);
|
|
13579
13494
|
}
|
|
13495
|
+
_onStackOrderChanged() {
|
|
13496
|
+
this._objectsToRender = undefined;
|
|
13497
|
+
super._onStackOrderChanged();
|
|
13498
|
+
}
|
|
13580
13499
|
|
|
13581
13500
|
/**
|
|
13582
13501
|
* Divides objects in two groups, one to render immediately
|
|
@@ -13640,15 +13559,6 @@ class SelectableCanvas extends StaticCanvas {
|
|
|
13640
13559
|
});
|
|
13641
13560
|
}
|
|
13642
13561
|
|
|
13643
|
-
/**
|
|
13644
|
-
* Given a pointer on the canvas with a viewport applied,
|
|
13645
|
-
* find out the pointer in object coordinates
|
|
13646
|
-
* @private
|
|
13647
|
-
*/
|
|
13648
|
-
_normalizePointer(object, pointer) {
|
|
13649
|
-
return transformPoint(this.restorePointerVpt(pointer), invertTransform(object.calcTransformMatrix()));
|
|
13650
|
-
}
|
|
13651
|
-
|
|
13652
13562
|
/**
|
|
13653
13563
|
* Set the canvas tolerance value for pixel taret find.
|
|
13654
13564
|
* Use only integer numbers.
|
|
@@ -13669,8 +13579,8 @@ class SelectableCanvas extends StaticCanvas {
|
|
|
13669
13579
|
* @TODO this seems dumb that we treat controls with transparency. we can find controls
|
|
13670
13580
|
* programmatically without painting them, the cache canvas optimization is always valid
|
|
13671
13581
|
* @param {FabricObject} target Object to check
|
|
13672
|
-
* @param {Number} x Left coordinate
|
|
13673
|
-
* @param {Number} y Top coordinate
|
|
13582
|
+
* @param {Number} x Left coordinate in viewport space
|
|
13583
|
+
* @param {Number} y Top coordinate in viewport space
|
|
13674
13584
|
* @return {Boolean}
|
|
13675
13585
|
*/
|
|
13676
13586
|
isTargetTransparent(target, x, y) {
|
|
@@ -13780,6 +13690,7 @@ class SelectableCanvas extends StaticCanvas {
|
|
|
13780
13690
|
* @param {FaricObject} target
|
|
13781
13691
|
*/
|
|
13782
13692
|
_setupCurrentTransform(e, target, alreadySelected) {
|
|
13693
|
+
var _control$getActionHan;
|
|
13783
13694
|
if (!target) {
|
|
13784
13695
|
return;
|
|
13785
13696
|
}
|
|
@@ -13788,7 +13699,7 @@ class SelectableCanvas extends StaticCanvas {
|
|
|
13788
13699
|
sendPointToPlane(this.getPointer(e), undefined, target.group.calcTransformMatrix()) : this.getPointer(e);
|
|
13789
13700
|
const corner = target.getActiveControl() || '',
|
|
13790
13701
|
control = !!corner && target.controls[corner],
|
|
13791
|
-
actionHandler = alreadySelected && control ? control.getActionHandler(e, target, control) : dragHandler,
|
|
13702
|
+
actionHandler = alreadySelected && control ? (_control$getActionHan = control.getActionHandler(e, target, control)) === null || _control$getActionHan === void 0 ? void 0 : _control$getActionHan.bind(control) : dragHandler,
|
|
13792
13703
|
action = getActionFromCorner(alreadySelected, corner, e, target),
|
|
13793
13704
|
origin = this._getOriginFromCorner(target, corner),
|
|
13794
13705
|
altKey = e[this.centeredKey],
|
|
@@ -13926,19 +13837,15 @@ class SelectableCanvas extends StaticCanvas {
|
|
|
13926
13837
|
|
|
13927
13838
|
/**
|
|
13928
13839
|
* Checks point is inside the object.
|
|
13929
|
-
* @param {Object} [pointer] x,y object of point coordinates we want to check.
|
|
13930
13840
|
* @param {FabricObject} obj Object to test against
|
|
13931
|
-
* @param {Object} [
|
|
13841
|
+
* @param {Object} [pointer] point from viewport.
|
|
13932
13842
|
* @return {Boolean} true if point is contained within an area of given object
|
|
13933
13843
|
* @private
|
|
13934
13844
|
*/
|
|
13935
|
-
_checkTarget(
|
|
13936
|
-
if (obj && obj.visible && obj.evented &&
|
|
13937
|
-
// http://www.geog.ubc.ca/courses/klink/gis.notes/ncgia/u32.html
|
|
13938
|
-
// http://idav.ucdavis.edu/~okreylos/TAship/Spring2000/PointInPolygon.html
|
|
13939
|
-
obj.containsPoint(pointer)) {
|
|
13845
|
+
_checkTarget(obj, pointer) {
|
|
13846
|
+
if (obj && obj.visible && obj.evented && obj.containsPoint(this.restorePointerVpt(pointer), true)) {
|
|
13940
13847
|
if ((this.perPixelTargetFind || obj.perPixelTargetFind) && !obj.isEditing) {
|
|
13941
|
-
if (!this.isTargetTransparent(obj,
|
|
13848
|
+
if (!this.isTargetTransparent(obj, pointer.x, pointer.y)) {
|
|
13942
13849
|
return true;
|
|
13943
13850
|
}
|
|
13944
13851
|
} else {
|
|
@@ -13957,23 +13864,19 @@ class SelectableCanvas extends StaticCanvas {
|
|
|
13957
13864
|
*/
|
|
13958
13865
|
_searchPossibleTargets(objects, pointer) {
|
|
13959
13866
|
// Cache all targets where their bounding box contains point.
|
|
13960
|
-
let
|
|
13961
|
-
i = objects.length;
|
|
13867
|
+
let i = objects.length;
|
|
13962
13868
|
// Do not check for currently grouped objects, since we check the parent group itself.
|
|
13963
13869
|
// until we call this function specifically to search inside the activeGroup
|
|
13964
13870
|
while (i--) {
|
|
13965
|
-
const
|
|
13966
|
-
|
|
13967
|
-
if (this._checkTarget(pointerToUse, objToCheck, pointer)) {
|
|
13968
|
-
target = objects[i];
|
|
13871
|
+
const target = objects[i];
|
|
13872
|
+
if (this._checkTarget(target, pointer)) {
|
|
13969
13873
|
if (isCollection(target) && target.subTargetCheck) {
|
|
13970
13874
|
const subTarget = this._searchPossibleTargets(target._objects, pointer);
|
|
13971
13875
|
subTarget && this.targets.push(subTarget);
|
|
13972
13876
|
}
|
|
13973
|
-
|
|
13877
|
+
return target;
|
|
13974
13878
|
}
|
|
13975
13879
|
}
|
|
13976
|
-
return target;
|
|
13977
13880
|
}
|
|
13978
13881
|
|
|
13979
13882
|
/**
|
|
@@ -13993,6 +13896,7 @@ class SelectableCanvas extends StaticCanvas {
|
|
|
13993
13896
|
|
|
13994
13897
|
/**
|
|
13995
13898
|
* Returns pointer coordinates without the effect of the viewport
|
|
13899
|
+
* Takes a point in html canvas space and gives you back a point of the scene.
|
|
13996
13900
|
* @param {Object} pointer with "x" and "y" number values in canvas HTML coordinates
|
|
13997
13901
|
* @return {Object} object with "x" and "y" number values in fabricCanvas coordinates
|
|
13998
13902
|
*/
|
|
@@ -14224,6 +14128,11 @@ class SelectableCanvas extends StaticCanvas {
|
|
|
14224
14128
|
return false;
|
|
14225
14129
|
}
|
|
14226
14130
|
this._activeObject = object;
|
|
14131
|
+
if (object instanceof ActiveSelection && this._activeSelection !== object) {
|
|
14132
|
+
this._activeSelection = object;
|
|
14133
|
+
object.set('canvas', this);
|
|
14134
|
+
object.setCoords();
|
|
14135
|
+
}
|
|
14227
14136
|
return true;
|
|
14228
14137
|
}
|
|
14229
14138
|
|
|
@@ -15123,7 +15032,7 @@ class Canvas extends SelectableCanvas {
|
|
|
15123
15032
|
const mouseUpHandler = control && control.getMouseUpHandler(e, target, control);
|
|
15124
15033
|
if (mouseUpHandler) {
|
|
15125
15034
|
pointer = this.getPointer(e);
|
|
15126
|
-
mouseUpHandler(e, transform, pointer.x, pointer.y);
|
|
15035
|
+
mouseUpHandler.call(control, e, transform, pointer.x, pointer.y);
|
|
15127
15036
|
}
|
|
15128
15037
|
}
|
|
15129
15038
|
target.isMoving = false;
|
|
@@ -15134,7 +15043,7 @@ class Canvas extends SelectableCanvas {
|
|
|
15134
15043
|
const originalControl = transform.target && transform.target.controls[transform.corner],
|
|
15135
15044
|
originalMouseUpHandler = originalControl && originalControl.getMouseUpHandler(e, transform.target, originalControl);
|
|
15136
15045
|
pointer = pointer || this.getPointer(e);
|
|
15137
|
-
originalMouseUpHandler && originalMouseUpHandler(e, transform, pointer.x, pointer.y);
|
|
15046
|
+
originalMouseUpHandler && originalMouseUpHandler.call(originalControl, e, transform, pointer.x, pointer.y);
|
|
15138
15047
|
}
|
|
15139
15048
|
this._setCursorFromEvent(e, target);
|
|
15140
15049
|
this._handleEvent(e, 'up', LEFT_CLICK, isClick);
|
|
@@ -15156,7 +15065,7 @@ class Canvas extends SelectableCanvas {
|
|
|
15156
15065
|
this.fire(eventType, options);
|
|
15157
15066
|
target && target.fire(eventType, options);
|
|
15158
15067
|
for (let i = 0; i < subTargets.length; i++) {
|
|
15159
|
-
subTargets[i].fire(eventType, options);
|
|
15068
|
+
subTargets[i] !== target && subTargets[i].fire(eventType, options);
|
|
15160
15069
|
}
|
|
15161
15070
|
return options;
|
|
15162
15071
|
}
|
|
@@ -15193,7 +15102,7 @@ class Canvas extends SelectableCanvas {
|
|
|
15193
15102
|
// this may be a little be more complicated of what we want to handle
|
|
15194
15103
|
target && target.fire("mouse".concat(eventType), options);
|
|
15195
15104
|
for (let i = 0; i < targets.length; i++) {
|
|
15196
|
-
targets[i].fire("mouse".concat(eventType), options);
|
|
15105
|
+
targets[i] !== target && targets[i].fire("mouse".concat(eventType), options);
|
|
15197
15106
|
}
|
|
15198
15107
|
}
|
|
15199
15108
|
|
|
@@ -15365,7 +15274,7 @@ class Canvas extends SelectableCanvas {
|
|
|
15365
15274
|
pointer = this.getPointer(e),
|
|
15366
15275
|
mouseDownHandler = control && control.getMouseDownHandler(e, target, control);
|
|
15367
15276
|
if (mouseDownHandler) {
|
|
15368
|
-
mouseDownHandler(e, this._currentTransform, pointer.x, pointer.y);
|
|
15277
|
+
mouseDownHandler.call(control, e, this._currentTransform, pointer.x, pointer.y);
|
|
15369
15278
|
}
|
|
15370
15279
|
}
|
|
15371
15280
|
}
|
|
@@ -15540,7 +15449,7 @@ class Canvas extends SelectableCanvas {
|
|
|
15540
15449
|
pointer: this.getPointer(e, true),
|
|
15541
15450
|
absolutePointer: this.getPointer(e)
|
|
15542
15451
|
});
|
|
15543
|
-
fireCanvas && this.fire(
|
|
15452
|
+
fireCanvas && this.fire(canvasOut, outOpt);
|
|
15544
15453
|
oldTarget.fire(targetOut, outOpt);
|
|
15545
15454
|
}
|
|
15546
15455
|
if (target && targetChanged) {
|
|
@@ -15552,7 +15461,7 @@ class Canvas extends SelectableCanvas {
|
|
|
15552
15461
|
pointer: this.getPointer(e, true),
|
|
15553
15462
|
absolutePointer: this.getPointer(e)
|
|
15554
15463
|
});
|
|
15555
|
-
fireCanvas && this.fire(
|
|
15464
|
+
fireCanvas && this.fire(canvasIn, inOpt);
|
|
15556
15465
|
target.fire(targetIn, inOpt);
|
|
15557
15466
|
}
|
|
15558
15467
|
}
|
|
@@ -16208,6 +16117,7 @@ _defineProperty(Gradient, "type", 'Gradient');
|
|
|
16208
16117
|
classRegistry.setClass(Gradient, 'gradient');
|
|
16209
16118
|
|
|
16210
16119
|
const _excluded$b = ["source"];
|
|
16120
|
+
|
|
16211
16121
|
/**
|
|
16212
16122
|
* @see {@link http://fabricjs.com/patterns demo}
|
|
16213
16123
|
* @see {@link http://fabricjs.com/dynamic-patterns demo}
|
|
@@ -16225,7 +16135,7 @@ class Pattern {
|
|
|
16225
16135
|
return 'pattern';
|
|
16226
16136
|
}
|
|
16227
16137
|
set type(value) {
|
|
16228
|
-
|
|
16138
|
+
log('warn', 'Setting type has no effect', value);
|
|
16229
16139
|
}
|
|
16230
16140
|
|
|
16231
16141
|
/**
|
|
@@ -18968,9 +18878,9 @@ function getMeasuringContext() {
|
|
|
18968
18878
|
* Text class
|
|
18969
18879
|
* @tutorial {@link http://fabricjs.com/fabric-intro-part-2#text}
|
|
18970
18880
|
*/
|
|
18971
|
-
class
|
|
18881
|
+
class FabricText extends StyledText {
|
|
18972
18882
|
static getDefaults() {
|
|
18973
|
-
return _objectSpread2(_objectSpread2({}, super.getDefaults()),
|
|
18883
|
+
return _objectSpread2(_objectSpread2({}, super.getDefaults()), FabricText.ownDefaults);
|
|
18974
18884
|
}
|
|
18975
18885
|
constructor(text) {
|
|
18976
18886
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
@@ -20017,7 +19927,7 @@ class Text extends StyledText {
|
|
|
20017
19927
|
fontSize = this.fontSize
|
|
20018
19928
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
20019
19929
|
let forMeasuring = arguments.length > 1 ? arguments[1] : undefined;
|
|
20020
|
-
const parsedFontFamily = fontFamily.includes("'") || fontFamily.includes('"') || fontFamily.includes(',') ||
|
|
19930
|
+
const parsedFontFamily = fontFamily.includes("'") || fontFamily.includes('"') || fontFamily.includes(',') || FabricText.genericFonts.includes(fontFamily.toLowerCase()) ? fontFamily : "\"".concat(fontFamily, "\"");
|
|
20021
19931
|
return [fontStyle, fontWeight, "".concat(forMeasuring ? this.CACHE_FONT_SIZE : fontSize, "px"), parsedFontFamily].join(' ');
|
|
20022
19932
|
}
|
|
20023
19933
|
|
|
@@ -20123,14 +20033,14 @@ class Text extends StyledText {
|
|
|
20123
20033
|
return 1;
|
|
20124
20034
|
}
|
|
20125
20035
|
/**
|
|
20126
|
-
* Returns
|
|
20036
|
+
* Returns FabricText instance from an SVG element (<b>not yet implemented</b>)
|
|
20127
20037
|
* @static
|
|
20128
20038
|
* @memberOf Text
|
|
20129
20039
|
* @param {HTMLElement} element Element to parse
|
|
20130
20040
|
* @param {Object} [options] Options object
|
|
20131
20041
|
*/
|
|
20132
20042
|
static async fromElement(element, options, cssRules) {
|
|
20133
|
-
const parsedAttributes = parseAttributes(element,
|
|
20043
|
+
const parsedAttributes = parseAttributes(element, FabricText.ATTRIBUTE_NAMES, cssRules);
|
|
20134
20044
|
const _options$parsedAttrib = _objectSpread2(_objectSpread2({}, options), parsedAttributes),
|
|
20135
20045
|
{
|
|
20136
20046
|
textAnchor = LEFT,
|
|
@@ -20185,9 +20095,9 @@ class Text extends StyledText {
|
|
|
20185
20095
|
/* _FROM_SVG_END_ */
|
|
20186
20096
|
|
|
20187
20097
|
/**
|
|
20188
|
-
* Returns
|
|
20098
|
+
* Returns FabricText instance from an object representation
|
|
20189
20099
|
* @param {Object} object plain js Object to create an instance from
|
|
20190
|
-
* @returns {Promise<
|
|
20100
|
+
* @returns {Promise<FabricText>}
|
|
20191
20101
|
*/
|
|
20192
20102
|
static fromObject(object) {
|
|
20193
20103
|
return this._fromObject(_objectSpread2(_objectSpread2({}, object), {}, {
|
|
@@ -20202,22 +20112,30 @@ class Text extends StyledText {
|
|
|
20202
20112
|
* @type string[]
|
|
20203
20113
|
* @protected
|
|
20204
20114
|
*/
|
|
20205
|
-
_defineProperty(
|
|
20206
|
-
_defineProperty(
|
|
20207
|
-
_defineProperty(
|
|
20208
|
-
_defineProperty(
|
|
20209
|
-
_defineProperty(
|
|
20115
|
+
_defineProperty(FabricText, "textLayoutProperties", textLayoutProperties);
|
|
20116
|
+
_defineProperty(FabricText, "cacheProperties", [...cacheProperties, ...additionalProps]);
|
|
20117
|
+
_defineProperty(FabricText, "ownDefaults", textDefaultValues);
|
|
20118
|
+
_defineProperty(FabricText, "type", 'Text');
|
|
20119
|
+
_defineProperty(FabricText, "genericFonts", ['sans-serif', 'serif', 'cursive', 'fantasy', 'monospace']);
|
|
20210
20120
|
/* _FROM_SVG_START_ */
|
|
20211
20121
|
/**
|
|
20212
|
-
* List of attribute names to account for when parsing SVG element (used by {@link
|
|
20122
|
+
* List of attribute names to account for when parsing SVG element (used by {@link FabricText.fromElement})
|
|
20213
20123
|
* @static
|
|
20214
20124
|
* @memberOf Text
|
|
20215
20125
|
* @see: http://www.w3.org/TR/SVG/text.html#TextElement
|
|
20216
20126
|
*/
|
|
20217
|
-
_defineProperty(
|
|
20218
|
-
applyMixins(
|
|
20219
|
-
classRegistry.setClass(
|
|
20220
|
-
classRegistry.setSVGClass(
|
|
20127
|
+
_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'));
|
|
20128
|
+
applyMixins(FabricText, [TextSVGExportMixin]);
|
|
20129
|
+
classRegistry.setClass(FabricText);
|
|
20130
|
+
classRegistry.setSVGClass(FabricText);
|
|
20131
|
+
|
|
20132
|
+
/**
|
|
20133
|
+
* @deprecated The old fabric.Text class can't be imported as Text because of conflict with Web API.
|
|
20134
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/Text/Text
|
|
20135
|
+
* For this reason it has been renamed to FabricText.
|
|
20136
|
+
* Please use `import { FabricText }` in place of `import { Text as FabricText }`
|
|
20137
|
+
*/
|
|
20138
|
+
class Text extends FabricText {}
|
|
20221
20139
|
|
|
20222
20140
|
/**
|
|
20223
20141
|
* #### Dragging IText/Textbox Lifecycle
|
|
@@ -20570,7 +20488,7 @@ class DraggableTextDelegate {
|
|
|
20570
20488
|
* - `\-` Matches a "-" character (char code 45).
|
|
20571
20489
|
*/ // eslint-disable-next-line no-useless-escape
|
|
20572
20490
|
const reNonWord = /[ \n\.,;!\?\-]/;
|
|
20573
|
-
class ITextBehavior extends
|
|
20491
|
+
class ITextBehavior extends FabricText {
|
|
20574
20492
|
constructor() {
|
|
20575
20493
|
super(...arguments);
|
|
20576
20494
|
/**
|
|
@@ -22654,7 +22572,7 @@ class IText extends ITextClickBehavior {
|
|
|
22654
22572
|
lineIndex = cursorLocation.lineIndex,
|
|
22655
22573
|
charIndex = cursorLocation.charIndex > 0 ? cursorLocation.charIndex - 1 : 0,
|
|
22656
22574
|
charHeight = this.getValueOfPropertyAt(lineIndex, charIndex, 'fontSize'),
|
|
22657
|
-
multiplier = this.
|
|
22575
|
+
multiplier = this.getObjectScaling().x * this.canvas.getZoom(),
|
|
22658
22576
|
cursorWidth = this.cursorWidth / multiplier,
|
|
22659
22577
|
dy = this.getValueOfPropertyAt(lineIndex, charIndex, 'deltaY'),
|
|
22660
22578
|
topOffset = boundaries.topOffset + (1 - this._fontSizeFraction) * this.getHeightOfLine(lineIndex) / this.lineHeight - charHeight * (1 - this._fontSizeFraction);
|
|
@@ -23796,9 +23714,9 @@ const IMAGE_PROPS = ['cropX', 'cropY'];
|
|
|
23796
23714
|
/**
|
|
23797
23715
|
* @tutorial {@link http://fabricjs.com/fabric-intro-part-1#images}
|
|
23798
23716
|
*/
|
|
23799
|
-
class
|
|
23717
|
+
class FabricImage extends FabricObject {
|
|
23800
23718
|
static getDefaults() {
|
|
23801
|
-
return _objectSpread2(_objectSpread2({}, super.getDefaults()),
|
|
23719
|
+
return _objectSpread2(_objectSpread2({}, super.getDefaults()), FabricImage.ownDefaults);
|
|
23802
23720
|
}
|
|
23803
23721
|
/**
|
|
23804
23722
|
* Constructor
|
|
@@ -23816,7 +23734,7 @@ class Image extends FabricObject {
|
|
|
23816
23734
|
filters: []
|
|
23817
23735
|
}, options));
|
|
23818
23736
|
/**
|
|
23819
|
-
* When calling {@link
|
|
23737
|
+
* When calling {@link FabricImage.getSrc}, return value from element src with `element.getAttribute('src')`.
|
|
23820
23738
|
* This allows for relative urls as image src.
|
|
23821
23739
|
* @since 2.7.0
|
|
23822
23740
|
* @type Boolean
|
|
@@ -23873,7 +23791,7 @@ class Image extends FabricObject {
|
|
|
23873
23791
|
this._element = element;
|
|
23874
23792
|
this._originalElement = element;
|
|
23875
23793
|
this._setWidthHeight(size);
|
|
23876
|
-
element.classList.add(
|
|
23794
|
+
element.classList.add(FabricImage.CSS_CANVAS);
|
|
23877
23795
|
if (this.filters.length !== 0) {
|
|
23878
23796
|
this.applyFilters();
|
|
23879
23797
|
}
|
|
@@ -24346,12 +24264,12 @@ class Image extends FabricObject {
|
|
|
24346
24264
|
*/
|
|
24347
24265
|
|
|
24348
24266
|
/**
|
|
24349
|
-
* Creates an instance of
|
|
24267
|
+
* Creates an instance of FabricImage from its object representation
|
|
24350
24268
|
* @static
|
|
24351
24269
|
* @param {Object} object Object to create an instance from
|
|
24352
24270
|
* @param {object} [options] Options object
|
|
24353
24271
|
* @param {AbortSignal} [options.signal] handle aborting, see https://developer.mozilla.org/en-US/docs/Web/API/AbortController/signal
|
|
24354
|
-
* @returns {Promise<
|
|
24272
|
+
* @returns {Promise<FabricImage>}
|
|
24355
24273
|
*/
|
|
24356
24274
|
static fromObject(_ref) {
|
|
24357
24275
|
let {
|
|
@@ -24382,7 +24300,7 @@ class Image extends FabricObject {
|
|
|
24382
24300
|
* @static
|
|
24383
24301
|
* @param {String} url URL to create an image from
|
|
24384
24302
|
* @param {LoadImageOptions} [options] Options object
|
|
24385
|
-
* @returns {Promise<
|
|
24303
|
+
* @returns {Promise<FabricImage>}
|
|
24386
24304
|
*/
|
|
24387
24305
|
static fromURL(url) {
|
|
24388
24306
|
let {
|
|
@@ -24397,7 +24315,7 @@ class Image extends FabricObject {
|
|
|
24397
24315
|
}
|
|
24398
24316
|
|
|
24399
24317
|
/**
|
|
24400
|
-
* Returns {@link
|
|
24318
|
+
* Returns {@link FabricImage} instance from an SVG element
|
|
24401
24319
|
* @static
|
|
24402
24320
|
* @param {HTMLElement} element Element to parse
|
|
24403
24321
|
* @param {Object} [options] Options object
|
|
@@ -24409,23 +24327,31 @@ class Image extends FabricObject {
|
|
|
24409
24327
|
let cssRules = arguments.length > 2 ? arguments[2] : undefined;
|
|
24410
24328
|
const parsedAttributes = parseAttributes(element, this.ATTRIBUTE_NAMES, cssRules);
|
|
24411
24329
|
return this.fromURL(parsedAttributes['xlink:href'], options, parsedAttributes).catch(err => {
|
|
24412
|
-
|
|
24330
|
+
log('log', 'Unable to parse Image', err);
|
|
24413
24331
|
return null;
|
|
24414
24332
|
});
|
|
24415
24333
|
}
|
|
24416
24334
|
}
|
|
24417
|
-
_defineProperty(
|
|
24418
|
-
_defineProperty(
|
|
24419
|
-
_defineProperty(
|
|
24420
|
-
_defineProperty(
|
|
24335
|
+
_defineProperty(FabricImage, "type", 'Image');
|
|
24336
|
+
_defineProperty(FabricImage, "cacheProperties", [...cacheProperties, ...IMAGE_PROPS]);
|
|
24337
|
+
_defineProperty(FabricImage, "ownDefaults", imageDefaultValues);
|
|
24338
|
+
_defineProperty(FabricImage, "CSS_CANVAS", 'canvas-img');
|
|
24421
24339
|
/**
|
|
24422
|
-
* List of attribute names to account for when parsing SVG element (used by {@link
|
|
24340
|
+
* List of attribute names to account for when parsing SVG element (used by {@link FabricImage.fromElement})
|
|
24423
24341
|
* @static
|
|
24424
24342
|
* @see {@link http://www.w3.org/TR/SVG/struct.html#ImageElement}
|
|
24425
24343
|
*/
|
|
24426
|
-
_defineProperty(
|
|
24427
|
-
classRegistry.setClass(
|
|
24428
|
-
classRegistry.setSVGClass(
|
|
24344
|
+
_defineProperty(FabricImage, "ATTRIBUTE_NAMES", [...SHARED_ATTRIBUTES, 'x', 'y', 'width', 'height', 'preserveAspectRatio', 'xlink:href', 'crossOrigin', 'image-rendering']);
|
|
24345
|
+
classRegistry.setClass(FabricImage);
|
|
24346
|
+
classRegistry.setSVGClass(FabricImage);
|
|
24347
|
+
|
|
24348
|
+
/**
|
|
24349
|
+
* @deprecated The old fabric.Image class can't be imported as Image because of conflict with Web API.
|
|
24350
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/Image
|
|
24351
|
+
* For this reason it has been renamed to FabricImage.
|
|
24352
|
+
* Please use `import { FabricImage }` in place of `import { Image as FabricImage }`
|
|
24353
|
+
*/
|
|
24354
|
+
class Image extends FabricImage {}
|
|
24429
24355
|
|
|
24430
24356
|
/**
|
|
24431
24357
|
* Add a <g> element that envelop all child elements and makes the viewbox transformMatrix descend on all elements
|
|
@@ -24778,7 +24704,7 @@ class ElementsParser {
|
|
|
24778
24704
|
const obj = await klass.fromElement(el, this.options, this.cssRules);
|
|
24779
24705
|
this.resolveGradient(obj, el, 'fill');
|
|
24780
24706
|
this.resolveGradient(obj, el, 'stroke');
|
|
24781
|
-
if (obj instanceof
|
|
24707
|
+
if (obj instanceof FabricImage && obj._originalElement) {
|
|
24782
24708
|
removeTransformMatrixForSvgParsing(obj, obj.parsePreserveAspectRatioAttribute());
|
|
24783
24709
|
} else {
|
|
24784
24710
|
removeTransformMatrixForSvgParsing(obj);
|
|
@@ -24897,7 +24823,7 @@ async function parseSVGDocument(doc, reviver) {
|
|
|
24897
24823
|
signal
|
|
24898
24824
|
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
24899
24825
|
if (signal && signal.aborted) {
|
|
24900
|
-
|
|
24826
|
+
log('log', new SignalAbortedError('parseSVGDocument'));
|
|
24901
24827
|
// this is an unhappy path, we dont care about speed
|
|
24902
24828
|
return createEmptyResponse();
|
|
24903
24829
|
}
|
|
@@ -25001,7 +24927,7 @@ const getSize = poly => {
|
|
|
25001
24927
|
* This function locates the controls.
|
|
25002
24928
|
* It'll be used both for drawing and for interaction.
|
|
25003
24929
|
*/
|
|
25004
|
-
const
|
|
24930
|
+
const createPolyPositionHandler = pointIndex => {
|
|
25005
24931
|
return function (dim, finalMatrix, polyObject) {
|
|
25006
24932
|
var _polyObject$canvas$vi, _polyObject$canvas;
|
|
25007
24933
|
const x = polyObject.points[pointIndex].x - polyObject.pathOffset.x,
|
|
@@ -25034,7 +24960,7 @@ const polyActionHandler = (eventData, transform, x, y) => {
|
|
|
25034
24960
|
/**
|
|
25035
24961
|
* Keep the polygon in the same position when we change its `width`/`height`/`top`/`left`.
|
|
25036
24962
|
*/
|
|
25037
|
-
const
|
|
24963
|
+
const factoryPolyActionHandler = (pointIndex, fn) => {
|
|
25038
24964
|
return function (eventData, transform, x, y) {
|
|
25039
24965
|
const poly = transform.target,
|
|
25040
24966
|
anchorPoint = new Point(poly.points[(pointIndex > 0 ? pointIndex : poly.points.length) - 1]),
|
|
@@ -25048,14 +24974,15 @@ const anchorWrapper = (pointIndex, fn) => {
|
|
|
25048
24974
|
return actionPerformed;
|
|
25049
24975
|
};
|
|
25050
24976
|
};
|
|
24977
|
+
const createPolyActionHandler = pointIndex => factoryPolyActionHandler(pointIndex, polyActionHandler);
|
|
25051
24978
|
function createPolyControls(arg0) {
|
|
25052
24979
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
25053
24980
|
const controls = {};
|
|
25054
24981
|
for (let idx = 0; idx < (typeof arg0 === 'number' ? arg0 : arg0.points.length); idx++) {
|
|
25055
24982
|
controls["p".concat(idx)] = new Control(_objectSpread2({
|
|
25056
24983
|
actionName: 'modifyPoly',
|
|
25057
|
-
positionHandler:
|
|
25058
|
-
actionHandler:
|
|
24984
|
+
positionHandler: createPolyPositionHandler(idx),
|
|
24985
|
+
actionHandler: createPolyActionHandler(idx)
|
|
25059
24986
|
}, options));
|
|
25060
24987
|
}
|
|
25061
24988
|
return controls;
|
|
@@ -25065,11 +24992,15 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
25065
24992
|
__proto__: null,
|
|
25066
24993
|
changeWidth: changeWidth,
|
|
25067
24994
|
createObjectDefaultControls: createObjectDefaultControls,
|
|
24995
|
+
createPolyActionHandler: createPolyActionHandler,
|
|
25068
24996
|
createPolyControls: createPolyControls,
|
|
24997
|
+
createPolyPositionHandler: createPolyPositionHandler,
|
|
25069
24998
|
createResizeControls: createResizeControls,
|
|
25070
24999
|
createTextboxDefaultControls: createTextboxDefaultControls,
|
|
25071
25000
|
dragHandler: dragHandler,
|
|
25001
|
+
factoryPolyActionHandler: factoryPolyActionHandler,
|
|
25072
25002
|
getLocalPoint: getLocalPoint,
|
|
25003
|
+
polyActionHandler: polyActionHandler,
|
|
25073
25004
|
renderCircleControl: renderCircleControl,
|
|
25074
25005
|
renderSquareControl: renderSquareControl,
|
|
25075
25006
|
rotationStyleHandler: rotationStyleHandler,
|
|
@@ -25164,25 +25095,23 @@ class BaseFilter {
|
|
|
25164
25095
|
const fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
|
|
25165
25096
|
const program = gl.createProgram();
|
|
25166
25097
|
if (!vertexShader || !fragmentShader || !program) {
|
|
25167
|
-
throw new
|
|
25098
|
+
throw new FabricError('Vertex, fragment shader or program creation error');
|
|
25168
25099
|
}
|
|
25169
25100
|
gl.shaderSource(vertexShader, vertexSource);
|
|
25170
25101
|
gl.compileShader(vertexShader);
|
|
25171
25102
|
if (!gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS)) {
|
|
25172
|
-
throw new
|
|
25103
|
+
throw new FabricError("Vertex shader compile error for ".concat(this.type, ": ").concat(gl.getShaderInfoLog(vertexShader)));
|
|
25173
25104
|
}
|
|
25174
25105
|
gl.shaderSource(fragmentShader, fragmentSource);
|
|
25175
25106
|
gl.compileShader(fragmentShader);
|
|
25176
25107
|
if (!gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS)) {
|
|
25177
|
-
throw new
|
|
25108
|
+
throw new FabricError("Fragment shader compile error for ".concat(this.type, ": ").concat(gl.getShaderInfoLog(fragmentShader)));
|
|
25178
25109
|
}
|
|
25179
25110
|
gl.attachShader(program, vertexShader);
|
|
25180
25111
|
gl.attachShader(program, fragmentShader);
|
|
25181
25112
|
gl.linkProgram(program);
|
|
25182
25113
|
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
25183
|
-
throw new
|
|
25184
|
-
// eslint-disable-next-line prefer-template
|
|
25185
|
-
'Shader link error for "${this.type}" ' + gl.getProgramInfoLog(program));
|
|
25114
|
+
throw new FabricError("Shader link error for \"".concat(this.type, "\" ").concat(gl.getProgramInfoLog(program)));
|
|
25186
25115
|
}
|
|
25187
25116
|
const uniformLocations = this.getUniformLocations(gl, program) || {};
|
|
25188
25117
|
uniformLocations.uStepW = gl.getUniformLocation(program, 'uStepW');
|
|
@@ -25781,7 +25710,7 @@ class BlendImage extends BaseFilter {
|
|
|
25781
25710
|
image
|
|
25782
25711
|
} = _ref2,
|
|
25783
25712
|
filterOptions = _objectWithoutProperties(_ref2, _excluded$3);
|
|
25784
|
-
return
|
|
25713
|
+
return FabricImage.fromObject(image, options).then(enlivedImage => new this(_objectSpread2(_objectSpread2({}, filterOptions), {}, {
|
|
25785
25714
|
image: enlivedImage
|
|
25786
25715
|
})));
|
|
25787
25716
|
}
|
|
@@ -27735,5 +27664,5 @@ var filters = /*#__PURE__*/Object.freeze({
|
|
|
27735
27664
|
Vintage: Vintage
|
|
27736
27665
|
});
|
|
27737
27666
|
|
|
27738
|
-
export { ActiveSelection, BaseBrush, Canvas, Canvas2dFilterBackend, CanvasDOMManager, Circle, CircleBrush, Color, Control, Ellipse, Gradient, Group, IText, Image, Intersection, Line,
|
|
27667
|
+
export { ActiveSelection, BaseBrush, Canvas, Canvas2dFilterBackend, CanvasDOMManager, Circle, CircleBrush, Color, Control, Ellipse, FabricImage, FabricObject, FabricText, Gradient, Group, IText, Image, Intersection, Line, _Object as Object, Observable, Path, Pattern, PatternBrush, PencilBrush, Point, Polygon, Polyline, Rect, Shadow, SprayBrush, StaticCanvas, StaticCanvasDOMManager, Text, Textbox, Triangle, WebGLFilterBackend, cache, classRegistry, config, index as controlsUtils, createCollectionMixin, filters, getCSSRules, getEnv, getFabricDocument, getFabricWindow, getFilterBackend, iMatrix, initFilterBackend, isWebGLPipelineState, loadSVGFromString, loadSVGFromURL, parseAttributes, parseFontDeclaration, parsePointsAttribute, parseSVGDocument, parseStyleAttribute, parseTransformAttribute, runningAnimations, setEnv, setFilterBackend, index$1 as util, VERSION as version };
|
|
27739
27668
|
//# sourceMappingURL=index.mjs.map
|