fabric 6.0.0-beta13 → 6.0.0-beta15
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 +35 -1
- package/CONTRIBUTING.md +9 -9
- package/dist/fabric.d.ts +36 -3
- package/dist/index.js +218 -324
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.mjs +214 -323
- package/dist/index.mjs.map +1 -1
- package/dist/index.node.cjs +218 -324
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +214 -323
- 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 +11 -11
- 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 +7 -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 +45 -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/loadSVGFromString.test.ts +36 -0
- package/src/parser/parseSVGDocument.ts +2 -1
- package/src/parser/parseUseDirectives.ts +6 -2
- package/src/parser/recursivelyParseGradientsXlink.ts +1 -3
- 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 +15 -14
- package/src/shapes/Object/FabricObject.spec.ts +16 -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 +16 -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/src/parser/elementById.d.ts +0 -7
- package/src/parser/elementById.ts +0 -18
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-beta15";
|
|
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
|
/**
|
|
@@ -10547,15 +10456,11 @@ class Group extends createCollectionMixin(FabricObject) {
|
|
|
10547
10456
|
canEnterGroup(object) {
|
|
10548
10457
|
if (object === this || this.isDescendantOf(object)) {
|
|
10549
10458
|
// 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_ */
|
|
10459
|
+
log('error', 'Group: circular object trees are not supported, this call has no effect');
|
|
10553
10460
|
return false;
|
|
10554
10461
|
} else if (this._objects.indexOf(object) !== -1) {
|
|
10555
10462
|
// 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_ */
|
|
10463
|
+
log('error', 'Group: duplicate objects are not supported inside group, this call has no effect');
|
|
10559
10464
|
return false;
|
|
10560
10465
|
}
|
|
10561
10466
|
return true;
|
|
@@ -11408,7 +11313,9 @@ class ActiveSelection extends Group {
|
|
|
11408
11313
|
// save ref to group for later in order to return to it
|
|
11409
11314
|
const parent = object.group;
|
|
11410
11315
|
parent._exitGroup(object);
|
|
11411
|
-
|
|
11316
|
+
// make sure we are setting the correct owning group
|
|
11317
|
+
// in case `object` is transferred between active selections
|
|
11318
|
+
!(parent instanceof ActiveSelection) && (object.__owningGroup = parent);
|
|
11412
11319
|
}
|
|
11413
11320
|
this._enterGroup(object, removeParentTransform);
|
|
11414
11321
|
return true;
|
|
@@ -13060,7 +12967,7 @@ function request(url) {
|
|
|
13060
12967
|
xhr.onerror = xhr.ontimeout = noop;
|
|
13061
12968
|
};
|
|
13062
12969
|
if (signal && signal.aborted) {
|
|
13063
|
-
throw new
|
|
12970
|
+
throw new SignalAbortedError('request');
|
|
13064
12971
|
} else if (signal) {
|
|
13065
12972
|
signal.addEventListener('abort', abort, {
|
|
13066
12973
|
once: true
|
|
@@ -13507,9 +13414,9 @@ class SelectableCanvas extends StaticCanvas {
|
|
|
13507
13414
|
* @type FabricObject[]
|
|
13508
13415
|
* @private
|
|
13509
13416
|
*/
|
|
13510
|
-
_defineProperty(this, "_objectsToRender",
|
|
13417
|
+
_defineProperty(this, "_objectsToRender", void 0);
|
|
13511
13418
|
/**
|
|
13512
|
-
* hold a
|
|
13419
|
+
* hold a reference to a data structure that contains information
|
|
13513
13420
|
* on the current on going transform
|
|
13514
13421
|
* @type
|
|
13515
13422
|
* @private
|
|
@@ -13577,6 +13484,10 @@ class SelectableCanvas extends StaticCanvas {
|
|
|
13577
13484
|
}
|
|
13578
13485
|
super._onObjectRemoved(obj);
|
|
13579
13486
|
}
|
|
13487
|
+
_onStackOrderChanged() {
|
|
13488
|
+
this._objectsToRender = undefined;
|
|
13489
|
+
super._onStackOrderChanged();
|
|
13490
|
+
}
|
|
13580
13491
|
|
|
13581
13492
|
/**
|
|
13582
13493
|
* Divides objects in two groups, one to render immediately
|
|
@@ -13640,15 +13551,6 @@ class SelectableCanvas extends StaticCanvas {
|
|
|
13640
13551
|
});
|
|
13641
13552
|
}
|
|
13642
13553
|
|
|
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
13554
|
/**
|
|
13653
13555
|
* Set the canvas tolerance value for pixel taret find.
|
|
13654
13556
|
* Use only integer numbers.
|
|
@@ -13669,8 +13571,8 @@ class SelectableCanvas extends StaticCanvas {
|
|
|
13669
13571
|
* @TODO this seems dumb that we treat controls with transparency. we can find controls
|
|
13670
13572
|
* programmatically without painting them, the cache canvas optimization is always valid
|
|
13671
13573
|
* @param {FabricObject} target Object to check
|
|
13672
|
-
* @param {Number} x Left coordinate
|
|
13673
|
-
* @param {Number} y Top coordinate
|
|
13574
|
+
* @param {Number} x Left coordinate in viewport space
|
|
13575
|
+
* @param {Number} y Top coordinate in viewport space
|
|
13674
13576
|
* @return {Boolean}
|
|
13675
13577
|
*/
|
|
13676
13578
|
isTargetTransparent(target, x, y) {
|
|
@@ -13780,6 +13682,7 @@ class SelectableCanvas extends StaticCanvas {
|
|
|
13780
13682
|
* @param {FaricObject} target
|
|
13781
13683
|
*/
|
|
13782
13684
|
_setupCurrentTransform(e, target, alreadySelected) {
|
|
13685
|
+
var _control$getActionHan;
|
|
13783
13686
|
if (!target) {
|
|
13784
13687
|
return;
|
|
13785
13688
|
}
|
|
@@ -13788,7 +13691,7 @@ class SelectableCanvas extends StaticCanvas {
|
|
|
13788
13691
|
sendPointToPlane(this.getPointer(e), undefined, target.group.calcTransformMatrix()) : this.getPointer(e);
|
|
13789
13692
|
const corner = target.getActiveControl() || '',
|
|
13790
13693
|
control = !!corner && target.controls[corner],
|
|
13791
|
-
actionHandler = alreadySelected && control ? control.getActionHandler(e, target, control) : dragHandler,
|
|
13694
|
+
actionHandler = alreadySelected && control ? (_control$getActionHan = control.getActionHandler(e, target, control)) === null || _control$getActionHan === void 0 ? void 0 : _control$getActionHan.bind(control) : dragHandler,
|
|
13792
13695
|
action = getActionFromCorner(alreadySelected, corner, e, target),
|
|
13793
13696
|
origin = this._getOriginFromCorner(target, corner),
|
|
13794
13697
|
altKey = e[this.centeredKey],
|
|
@@ -13926,19 +13829,15 @@ class SelectableCanvas extends StaticCanvas {
|
|
|
13926
13829
|
|
|
13927
13830
|
/**
|
|
13928
13831
|
* Checks point is inside the object.
|
|
13929
|
-
* @param {Object} [pointer] x,y object of point coordinates we want to check.
|
|
13930
13832
|
* @param {FabricObject} obj Object to test against
|
|
13931
|
-
* @param {Object} [
|
|
13833
|
+
* @param {Object} [pointer] point from viewport.
|
|
13932
13834
|
* @return {Boolean} true if point is contained within an area of given object
|
|
13933
13835
|
* @private
|
|
13934
13836
|
*/
|
|
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)) {
|
|
13837
|
+
_checkTarget(obj, pointer) {
|
|
13838
|
+
if (obj && obj.visible && obj.evented && obj.containsPoint(this.restorePointerVpt(pointer), true)) {
|
|
13940
13839
|
if ((this.perPixelTargetFind || obj.perPixelTargetFind) && !obj.isEditing) {
|
|
13941
|
-
if (!this.isTargetTransparent(obj,
|
|
13840
|
+
if (!this.isTargetTransparent(obj, pointer.x, pointer.y)) {
|
|
13942
13841
|
return true;
|
|
13943
13842
|
}
|
|
13944
13843
|
} else {
|
|
@@ -13957,23 +13856,19 @@ class SelectableCanvas extends StaticCanvas {
|
|
|
13957
13856
|
*/
|
|
13958
13857
|
_searchPossibleTargets(objects, pointer) {
|
|
13959
13858
|
// Cache all targets where their bounding box contains point.
|
|
13960
|
-
let
|
|
13961
|
-
i = objects.length;
|
|
13859
|
+
let i = objects.length;
|
|
13962
13860
|
// Do not check for currently grouped objects, since we check the parent group itself.
|
|
13963
13861
|
// until we call this function specifically to search inside the activeGroup
|
|
13964
13862
|
while (i--) {
|
|
13965
|
-
const
|
|
13966
|
-
|
|
13967
|
-
if (this._checkTarget(pointerToUse, objToCheck, pointer)) {
|
|
13968
|
-
target = objects[i];
|
|
13863
|
+
const target = objects[i];
|
|
13864
|
+
if (this._checkTarget(target, pointer)) {
|
|
13969
13865
|
if (isCollection(target) && target.subTargetCheck) {
|
|
13970
13866
|
const subTarget = this._searchPossibleTargets(target._objects, pointer);
|
|
13971
13867
|
subTarget && this.targets.push(subTarget);
|
|
13972
13868
|
}
|
|
13973
|
-
|
|
13869
|
+
return target;
|
|
13974
13870
|
}
|
|
13975
13871
|
}
|
|
13976
|
-
return target;
|
|
13977
13872
|
}
|
|
13978
13873
|
|
|
13979
13874
|
/**
|
|
@@ -13993,6 +13888,7 @@ class SelectableCanvas extends StaticCanvas {
|
|
|
13993
13888
|
|
|
13994
13889
|
/**
|
|
13995
13890
|
* Returns pointer coordinates without the effect of the viewport
|
|
13891
|
+
* Takes a point in html canvas space and gives you back a point of the scene.
|
|
13996
13892
|
* @param {Object} pointer with "x" and "y" number values in canvas HTML coordinates
|
|
13997
13893
|
* @return {Object} object with "x" and "y" number values in fabricCanvas coordinates
|
|
13998
13894
|
*/
|
|
@@ -14224,6 +14120,11 @@ class SelectableCanvas extends StaticCanvas {
|
|
|
14224
14120
|
return false;
|
|
14225
14121
|
}
|
|
14226
14122
|
this._activeObject = object;
|
|
14123
|
+
if (object instanceof ActiveSelection && this._activeSelection !== object) {
|
|
14124
|
+
this._activeSelection = object;
|
|
14125
|
+
object.set('canvas', this);
|
|
14126
|
+
object.setCoords();
|
|
14127
|
+
}
|
|
14227
14128
|
return true;
|
|
14228
14129
|
}
|
|
14229
14130
|
|
|
@@ -15123,7 +15024,7 @@ class Canvas extends SelectableCanvas {
|
|
|
15123
15024
|
const mouseUpHandler = control && control.getMouseUpHandler(e, target, control);
|
|
15124
15025
|
if (mouseUpHandler) {
|
|
15125
15026
|
pointer = this.getPointer(e);
|
|
15126
|
-
mouseUpHandler(e, transform, pointer.x, pointer.y);
|
|
15027
|
+
mouseUpHandler.call(control, e, transform, pointer.x, pointer.y);
|
|
15127
15028
|
}
|
|
15128
15029
|
}
|
|
15129
15030
|
target.isMoving = false;
|
|
@@ -15134,7 +15035,7 @@ class Canvas extends SelectableCanvas {
|
|
|
15134
15035
|
const originalControl = transform.target && transform.target.controls[transform.corner],
|
|
15135
15036
|
originalMouseUpHandler = originalControl && originalControl.getMouseUpHandler(e, transform.target, originalControl);
|
|
15136
15037
|
pointer = pointer || this.getPointer(e);
|
|
15137
|
-
originalMouseUpHandler && originalMouseUpHandler(e, transform, pointer.x, pointer.y);
|
|
15038
|
+
originalMouseUpHandler && originalMouseUpHandler.call(originalControl, e, transform, pointer.x, pointer.y);
|
|
15138
15039
|
}
|
|
15139
15040
|
this._setCursorFromEvent(e, target);
|
|
15140
15041
|
this._handleEvent(e, 'up', LEFT_CLICK, isClick);
|
|
@@ -15156,7 +15057,7 @@ class Canvas extends SelectableCanvas {
|
|
|
15156
15057
|
this.fire(eventType, options);
|
|
15157
15058
|
target && target.fire(eventType, options);
|
|
15158
15059
|
for (let i = 0; i < subTargets.length; i++) {
|
|
15159
|
-
subTargets[i].fire(eventType, options);
|
|
15060
|
+
subTargets[i] !== target && subTargets[i].fire(eventType, options);
|
|
15160
15061
|
}
|
|
15161
15062
|
return options;
|
|
15162
15063
|
}
|
|
@@ -15193,7 +15094,7 @@ class Canvas extends SelectableCanvas {
|
|
|
15193
15094
|
// this may be a little be more complicated of what we want to handle
|
|
15194
15095
|
target && target.fire("mouse".concat(eventType), options);
|
|
15195
15096
|
for (let i = 0; i < targets.length; i++) {
|
|
15196
|
-
targets[i].fire("mouse".concat(eventType), options);
|
|
15097
|
+
targets[i] !== target && targets[i].fire("mouse".concat(eventType), options);
|
|
15197
15098
|
}
|
|
15198
15099
|
}
|
|
15199
15100
|
|
|
@@ -15365,7 +15266,7 @@ class Canvas extends SelectableCanvas {
|
|
|
15365
15266
|
pointer = this.getPointer(e),
|
|
15366
15267
|
mouseDownHandler = control && control.getMouseDownHandler(e, target, control);
|
|
15367
15268
|
if (mouseDownHandler) {
|
|
15368
|
-
mouseDownHandler(e, this._currentTransform, pointer.x, pointer.y);
|
|
15269
|
+
mouseDownHandler.call(control, e, this._currentTransform, pointer.x, pointer.y);
|
|
15369
15270
|
}
|
|
15370
15271
|
}
|
|
15371
15272
|
}
|
|
@@ -15540,7 +15441,7 @@ class Canvas extends SelectableCanvas {
|
|
|
15540
15441
|
pointer: this.getPointer(e, true),
|
|
15541
15442
|
absolutePointer: this.getPointer(e)
|
|
15542
15443
|
});
|
|
15543
|
-
fireCanvas && this.fire(
|
|
15444
|
+
fireCanvas && this.fire(canvasOut, outOpt);
|
|
15544
15445
|
oldTarget.fire(targetOut, outOpt);
|
|
15545
15446
|
}
|
|
15546
15447
|
if (target && targetChanged) {
|
|
@@ -15552,7 +15453,7 @@ class Canvas extends SelectableCanvas {
|
|
|
15552
15453
|
pointer: this.getPointer(e, true),
|
|
15553
15454
|
absolutePointer: this.getPointer(e)
|
|
15554
15455
|
});
|
|
15555
|
-
fireCanvas && this.fire(
|
|
15456
|
+
fireCanvas && this.fire(canvasIn, inOpt);
|
|
15556
15457
|
target.fire(targetIn, inOpt);
|
|
15557
15458
|
}
|
|
15558
15459
|
}
|
|
@@ -16208,6 +16109,7 @@ _defineProperty(Gradient, "type", 'Gradient');
|
|
|
16208
16109
|
classRegistry.setClass(Gradient, 'gradient');
|
|
16209
16110
|
|
|
16210
16111
|
const _excluded$b = ["source"];
|
|
16112
|
+
|
|
16211
16113
|
/**
|
|
16212
16114
|
* @see {@link http://fabricjs.com/patterns demo}
|
|
16213
16115
|
* @see {@link http://fabricjs.com/dynamic-patterns demo}
|
|
@@ -16225,7 +16127,7 @@ class Pattern {
|
|
|
16225
16127
|
return 'pattern';
|
|
16226
16128
|
}
|
|
16227
16129
|
set type(value) {
|
|
16228
|
-
|
|
16130
|
+
log('warn', 'Setting type has no effect', value);
|
|
16229
16131
|
}
|
|
16230
16132
|
|
|
16231
16133
|
/**
|
|
@@ -18968,9 +18870,9 @@ function getMeasuringContext() {
|
|
|
18968
18870
|
* Text class
|
|
18969
18871
|
* @tutorial {@link http://fabricjs.com/fabric-intro-part-2#text}
|
|
18970
18872
|
*/
|
|
18971
|
-
class
|
|
18873
|
+
class FabricText extends StyledText {
|
|
18972
18874
|
static getDefaults() {
|
|
18973
|
-
return _objectSpread2(_objectSpread2({}, super.getDefaults()),
|
|
18875
|
+
return _objectSpread2(_objectSpread2({}, super.getDefaults()), FabricText.ownDefaults);
|
|
18974
18876
|
}
|
|
18975
18877
|
constructor(text) {
|
|
18976
18878
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
@@ -20017,7 +19919,7 @@ class Text extends StyledText {
|
|
|
20017
19919
|
fontSize = this.fontSize
|
|
20018
19920
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
20019
19921
|
let forMeasuring = arguments.length > 1 ? arguments[1] : undefined;
|
|
20020
|
-
const parsedFontFamily = fontFamily.includes("'") || fontFamily.includes('"') || fontFamily.includes(',') ||
|
|
19922
|
+
const parsedFontFamily = fontFamily.includes("'") || fontFamily.includes('"') || fontFamily.includes(',') || FabricText.genericFonts.includes(fontFamily.toLowerCase()) ? fontFamily : "\"".concat(fontFamily, "\"");
|
|
20021
19923
|
return [fontStyle, fontWeight, "".concat(forMeasuring ? this.CACHE_FONT_SIZE : fontSize, "px"), parsedFontFamily].join(' ');
|
|
20022
19924
|
}
|
|
20023
19925
|
|
|
@@ -20123,14 +20025,14 @@ class Text extends StyledText {
|
|
|
20123
20025
|
return 1;
|
|
20124
20026
|
}
|
|
20125
20027
|
/**
|
|
20126
|
-
* Returns
|
|
20028
|
+
* Returns FabricText instance from an SVG element (<b>not yet implemented</b>)
|
|
20127
20029
|
* @static
|
|
20128
20030
|
* @memberOf Text
|
|
20129
20031
|
* @param {HTMLElement} element Element to parse
|
|
20130
20032
|
* @param {Object} [options] Options object
|
|
20131
20033
|
*/
|
|
20132
20034
|
static async fromElement(element, options, cssRules) {
|
|
20133
|
-
const parsedAttributes = parseAttributes(element,
|
|
20035
|
+
const parsedAttributes = parseAttributes(element, FabricText.ATTRIBUTE_NAMES, cssRules);
|
|
20134
20036
|
const _options$parsedAttrib = _objectSpread2(_objectSpread2({}, options), parsedAttributes),
|
|
20135
20037
|
{
|
|
20136
20038
|
textAnchor = LEFT,
|
|
@@ -20185,9 +20087,9 @@ class Text extends StyledText {
|
|
|
20185
20087
|
/* _FROM_SVG_END_ */
|
|
20186
20088
|
|
|
20187
20089
|
/**
|
|
20188
|
-
* Returns
|
|
20090
|
+
* Returns FabricText instance from an object representation
|
|
20189
20091
|
* @param {Object} object plain js Object to create an instance from
|
|
20190
|
-
* @returns {Promise<
|
|
20092
|
+
* @returns {Promise<FabricText>}
|
|
20191
20093
|
*/
|
|
20192
20094
|
static fromObject(object) {
|
|
20193
20095
|
return this._fromObject(_objectSpread2(_objectSpread2({}, object), {}, {
|
|
@@ -20202,22 +20104,22 @@ class Text extends StyledText {
|
|
|
20202
20104
|
* @type string[]
|
|
20203
20105
|
* @protected
|
|
20204
20106
|
*/
|
|
20205
|
-
_defineProperty(
|
|
20206
|
-
_defineProperty(
|
|
20207
|
-
_defineProperty(
|
|
20208
|
-
_defineProperty(
|
|
20209
|
-
_defineProperty(
|
|
20107
|
+
_defineProperty(FabricText, "textLayoutProperties", textLayoutProperties);
|
|
20108
|
+
_defineProperty(FabricText, "cacheProperties", [...cacheProperties, ...additionalProps]);
|
|
20109
|
+
_defineProperty(FabricText, "ownDefaults", textDefaultValues);
|
|
20110
|
+
_defineProperty(FabricText, "type", 'Text');
|
|
20111
|
+
_defineProperty(FabricText, "genericFonts", ['sans-serif', 'serif', 'cursive', 'fantasy', 'monospace']);
|
|
20210
20112
|
/* _FROM_SVG_START_ */
|
|
20211
20113
|
/**
|
|
20212
|
-
* List of attribute names to account for when parsing SVG element (used by {@link
|
|
20114
|
+
* List of attribute names to account for when parsing SVG element (used by {@link FabricText.fromElement})
|
|
20213
20115
|
* @static
|
|
20214
20116
|
* @memberOf Text
|
|
20215
20117
|
* @see: http://www.w3.org/TR/SVG/text.html#TextElement
|
|
20216
20118
|
*/
|
|
20217
|
-
_defineProperty(
|
|
20218
|
-
applyMixins(
|
|
20219
|
-
classRegistry.setClass(
|
|
20220
|
-
classRegistry.setSVGClass(
|
|
20119
|
+
_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'));
|
|
20120
|
+
applyMixins(FabricText, [TextSVGExportMixin]);
|
|
20121
|
+
classRegistry.setClass(FabricText);
|
|
20122
|
+
classRegistry.setSVGClass(FabricText);
|
|
20221
20123
|
|
|
20222
20124
|
/**
|
|
20223
20125
|
* #### Dragging IText/Textbox Lifecycle
|
|
@@ -20570,7 +20472,7 @@ class DraggableTextDelegate {
|
|
|
20570
20472
|
* - `\-` Matches a "-" character (char code 45).
|
|
20571
20473
|
*/ // eslint-disable-next-line no-useless-escape
|
|
20572
20474
|
const reNonWord = /[ \n\.,;!\?\-]/;
|
|
20573
|
-
class ITextBehavior extends
|
|
20475
|
+
class ITextBehavior extends FabricText {
|
|
20574
20476
|
constructor() {
|
|
20575
20477
|
super(...arguments);
|
|
20576
20478
|
/**
|
|
@@ -22654,7 +22556,7 @@ class IText extends ITextClickBehavior {
|
|
|
22654
22556
|
lineIndex = cursorLocation.lineIndex,
|
|
22655
22557
|
charIndex = cursorLocation.charIndex > 0 ? cursorLocation.charIndex - 1 : 0,
|
|
22656
22558
|
charHeight = this.getValueOfPropertyAt(lineIndex, charIndex, 'fontSize'),
|
|
22657
|
-
multiplier = this.
|
|
22559
|
+
multiplier = this.getObjectScaling().x * this.canvas.getZoom(),
|
|
22658
22560
|
cursorWidth = this.cursorWidth / multiplier,
|
|
22659
22561
|
dy = this.getValueOfPropertyAt(lineIndex, charIndex, 'deltaY'),
|
|
22660
22562
|
topOffset = boundaries.topOffset + (1 - this._fontSizeFraction) * this.getHeightOfLine(lineIndex) / this.lineHeight - charHeight * (1 - this._fontSizeFraction);
|
|
@@ -23796,9 +23698,9 @@ const IMAGE_PROPS = ['cropX', 'cropY'];
|
|
|
23796
23698
|
/**
|
|
23797
23699
|
* @tutorial {@link http://fabricjs.com/fabric-intro-part-1#images}
|
|
23798
23700
|
*/
|
|
23799
|
-
class
|
|
23701
|
+
class FabricImage extends FabricObject {
|
|
23800
23702
|
static getDefaults() {
|
|
23801
|
-
return _objectSpread2(_objectSpread2({}, super.getDefaults()),
|
|
23703
|
+
return _objectSpread2(_objectSpread2({}, super.getDefaults()), FabricImage.ownDefaults);
|
|
23802
23704
|
}
|
|
23803
23705
|
/**
|
|
23804
23706
|
* Constructor
|
|
@@ -23816,7 +23718,7 @@ class Image extends FabricObject {
|
|
|
23816
23718
|
filters: []
|
|
23817
23719
|
}, options));
|
|
23818
23720
|
/**
|
|
23819
|
-
* When calling {@link
|
|
23721
|
+
* When calling {@link FabricImage.getSrc}, return value from element src with `element.getAttribute('src')`.
|
|
23820
23722
|
* This allows for relative urls as image src.
|
|
23821
23723
|
* @since 2.7.0
|
|
23822
23724
|
* @type Boolean
|
|
@@ -23873,7 +23775,7 @@ class Image extends FabricObject {
|
|
|
23873
23775
|
this._element = element;
|
|
23874
23776
|
this._originalElement = element;
|
|
23875
23777
|
this._setWidthHeight(size);
|
|
23876
|
-
element.classList.add(
|
|
23778
|
+
element.classList.add(FabricImage.CSS_CANVAS);
|
|
23877
23779
|
if (this.filters.length !== 0) {
|
|
23878
23780
|
this.applyFilters();
|
|
23879
23781
|
}
|
|
@@ -24346,12 +24248,12 @@ class Image extends FabricObject {
|
|
|
24346
24248
|
*/
|
|
24347
24249
|
|
|
24348
24250
|
/**
|
|
24349
|
-
* Creates an instance of
|
|
24251
|
+
* Creates an instance of FabricImage from its object representation
|
|
24350
24252
|
* @static
|
|
24351
24253
|
* @param {Object} object Object to create an instance from
|
|
24352
24254
|
* @param {object} [options] Options object
|
|
24353
24255
|
* @param {AbortSignal} [options.signal] handle aborting, see https://developer.mozilla.org/en-US/docs/Web/API/AbortController/signal
|
|
24354
|
-
* @returns {Promise<
|
|
24256
|
+
* @returns {Promise<FabricImage>}
|
|
24355
24257
|
*/
|
|
24356
24258
|
static fromObject(_ref) {
|
|
24357
24259
|
let {
|
|
@@ -24382,7 +24284,7 @@ class Image extends FabricObject {
|
|
|
24382
24284
|
* @static
|
|
24383
24285
|
* @param {String} url URL to create an image from
|
|
24384
24286
|
* @param {LoadImageOptions} [options] Options object
|
|
24385
|
-
* @returns {Promise<
|
|
24287
|
+
* @returns {Promise<FabricImage>}
|
|
24386
24288
|
*/
|
|
24387
24289
|
static fromURL(url) {
|
|
24388
24290
|
let {
|
|
@@ -24397,7 +24299,7 @@ class Image extends FabricObject {
|
|
|
24397
24299
|
}
|
|
24398
24300
|
|
|
24399
24301
|
/**
|
|
24400
|
-
* Returns {@link
|
|
24302
|
+
* Returns {@link FabricImage} instance from an SVG element
|
|
24401
24303
|
* @static
|
|
24402
24304
|
* @param {HTMLElement} element Element to parse
|
|
24403
24305
|
* @param {Object} [options] Options object
|
|
@@ -24409,23 +24311,23 @@ class Image extends FabricObject {
|
|
|
24409
24311
|
let cssRules = arguments.length > 2 ? arguments[2] : undefined;
|
|
24410
24312
|
const parsedAttributes = parseAttributes(element, this.ATTRIBUTE_NAMES, cssRules);
|
|
24411
24313
|
return this.fromURL(parsedAttributes['xlink:href'], options, parsedAttributes).catch(err => {
|
|
24412
|
-
|
|
24314
|
+
log('log', 'Unable to parse Image', err);
|
|
24413
24315
|
return null;
|
|
24414
24316
|
});
|
|
24415
24317
|
}
|
|
24416
24318
|
}
|
|
24417
|
-
_defineProperty(
|
|
24418
|
-
_defineProperty(
|
|
24419
|
-
_defineProperty(
|
|
24420
|
-
_defineProperty(
|
|
24319
|
+
_defineProperty(FabricImage, "type", 'Image');
|
|
24320
|
+
_defineProperty(FabricImage, "cacheProperties", [...cacheProperties, ...IMAGE_PROPS]);
|
|
24321
|
+
_defineProperty(FabricImage, "ownDefaults", imageDefaultValues);
|
|
24322
|
+
_defineProperty(FabricImage, "CSS_CANVAS", 'canvas-img');
|
|
24421
24323
|
/**
|
|
24422
|
-
* List of attribute names to account for when parsing SVG element (used by {@link
|
|
24324
|
+
* List of attribute names to account for when parsing SVG element (used by {@link FabricImage.fromElement})
|
|
24423
24325
|
* @static
|
|
24424
24326
|
* @see {@link http://www.w3.org/TR/SVG/struct.html#ImageElement}
|
|
24425
24327
|
*/
|
|
24426
|
-
_defineProperty(
|
|
24427
|
-
classRegistry.setClass(
|
|
24428
|
-
classRegistry.setSVGClass(
|
|
24328
|
+
_defineProperty(FabricImage, "ATTRIBUTE_NAMES", [...SHARED_ATTRIBUTES, 'x', 'y', 'width', 'height', 'preserveAspectRatio', 'xlink:href', 'crossOrigin', 'image-rendering']);
|
|
24329
|
+
classRegistry.setClass(FabricImage);
|
|
24330
|
+
classRegistry.setSVGClass(FabricImage);
|
|
24429
24331
|
|
|
24430
24332
|
/**
|
|
24431
24333
|
* Add a <g> element that envelop all child elements and makes the viewbox transformMatrix descend on all elements
|
|
@@ -24561,25 +24463,6 @@ function hasInvalidAncestor(element) {
|
|
|
24561
24463
|
return false;
|
|
24562
24464
|
}
|
|
24563
24465
|
|
|
24564
|
-
/**
|
|
24565
|
-
* @private
|
|
24566
|
-
* TODO: verify if this is still needed
|
|
24567
|
-
* to support IE8 missing getElementById on SVGdocument and on node xmlDOM
|
|
24568
|
-
*/
|
|
24569
|
-
function elementById(doc, id) {
|
|
24570
|
-
if (doc.getElementById) {
|
|
24571
|
-
return doc.getElementById(id);
|
|
24572
|
-
}
|
|
24573
|
-
const nodelist = doc.getElementsByTagName('*');
|
|
24574
|
-
for (let i = 0, len = nodelist.length; i < len; i++) {
|
|
24575
|
-
const node = nodelist[i];
|
|
24576
|
-
if (id === node.getAttribute('id')) {
|
|
24577
|
-
return node;
|
|
24578
|
-
}
|
|
24579
|
-
}
|
|
24580
|
-
return null;
|
|
24581
|
-
}
|
|
24582
|
-
|
|
24583
24466
|
function getMultipleNodes(doc, nodeNames) {
|
|
24584
24467
|
let nodeName,
|
|
24585
24468
|
nodeArray = [],
|
|
@@ -24606,7 +24489,12 @@ function parseUseDirectives(doc) {
|
|
|
24606
24489
|
const xlink = xlinkAttribute.slice(1);
|
|
24607
24490
|
const x = el.getAttribute('x') || 0;
|
|
24608
24491
|
const y = el.getAttribute('y') || 0;
|
|
24609
|
-
|
|
24492
|
+
const el2Orig = doc.getElementById(xlink);
|
|
24493
|
+
if (el2Orig === null) {
|
|
24494
|
+
// if we can't find the target of the xlink, consider this use tag bad, similar to no xlink
|
|
24495
|
+
return;
|
|
24496
|
+
}
|
|
24497
|
+
let el2 = el2Orig.cloneNode(true);
|
|
24610
24498
|
let currentTrans = (el2.getAttribute('transform') || '') + ' translate(' + x + ', ' + y + ')';
|
|
24611
24499
|
const oldLength = nodelist.length;
|
|
24612
24500
|
const namespace = svgNS;
|
|
@@ -24658,7 +24546,7 @@ const xlinkAttr = 'xlink:href';
|
|
|
24658
24546
|
function recursivelyParseGradientsXlink(doc, gradient) {
|
|
24659
24547
|
var _gradient$getAttribut;
|
|
24660
24548
|
const xLink = ((_gradient$getAttribut = gradient.getAttribute(xlinkAttr)) === null || _gradient$getAttribut === void 0 ? void 0 : _gradient$getAttribut.slice(1)) || '',
|
|
24661
|
-
referencedGradient =
|
|
24549
|
+
referencedGradient = doc.getElementById(xLink);
|
|
24662
24550
|
if (referencedGradient && referencedGradient.getAttribute(xlinkAttr)) {
|
|
24663
24551
|
recursivelyParseGradientsXlink(doc, referencedGradient);
|
|
24664
24552
|
}
|
|
@@ -24778,7 +24666,7 @@ class ElementsParser {
|
|
|
24778
24666
|
const obj = await klass.fromElement(el, this.options, this.cssRules);
|
|
24779
24667
|
this.resolveGradient(obj, el, 'fill');
|
|
24780
24668
|
this.resolveGradient(obj, el, 'stroke');
|
|
24781
|
-
if (obj instanceof
|
|
24669
|
+
if (obj instanceof FabricImage && obj._originalElement) {
|
|
24782
24670
|
removeTransformMatrixForSvgParsing(obj, obj.parsePreserveAspectRatioAttribute());
|
|
24783
24671
|
} else {
|
|
24784
24672
|
removeTransformMatrixForSvgParsing(obj);
|
|
@@ -24897,7 +24785,7 @@ async function parseSVGDocument(doc, reviver) {
|
|
|
24897
24785
|
signal
|
|
24898
24786
|
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
24899
24787
|
if (signal && signal.aborted) {
|
|
24900
|
-
|
|
24788
|
+
log('log', new SignalAbortedError('parseSVGDocument'));
|
|
24901
24789
|
// this is an unhappy path, we dont care about speed
|
|
24902
24790
|
return createEmptyResponse();
|
|
24903
24791
|
}
|
|
@@ -25001,7 +24889,7 @@ const getSize = poly => {
|
|
|
25001
24889
|
* This function locates the controls.
|
|
25002
24890
|
* It'll be used both for drawing and for interaction.
|
|
25003
24891
|
*/
|
|
25004
|
-
const
|
|
24892
|
+
const createPolyPositionHandler = pointIndex => {
|
|
25005
24893
|
return function (dim, finalMatrix, polyObject) {
|
|
25006
24894
|
var _polyObject$canvas$vi, _polyObject$canvas;
|
|
25007
24895
|
const x = polyObject.points[pointIndex].x - polyObject.pathOffset.x,
|
|
@@ -25034,7 +24922,7 @@ const polyActionHandler = (eventData, transform, x, y) => {
|
|
|
25034
24922
|
/**
|
|
25035
24923
|
* Keep the polygon in the same position when we change its `width`/`height`/`top`/`left`.
|
|
25036
24924
|
*/
|
|
25037
|
-
const
|
|
24925
|
+
const factoryPolyActionHandler = (pointIndex, fn) => {
|
|
25038
24926
|
return function (eventData, transform, x, y) {
|
|
25039
24927
|
const poly = transform.target,
|
|
25040
24928
|
anchorPoint = new Point(poly.points[(pointIndex > 0 ? pointIndex : poly.points.length) - 1]),
|
|
@@ -25048,14 +24936,15 @@ const anchorWrapper = (pointIndex, fn) => {
|
|
|
25048
24936
|
return actionPerformed;
|
|
25049
24937
|
};
|
|
25050
24938
|
};
|
|
24939
|
+
const createPolyActionHandler = pointIndex => factoryPolyActionHandler(pointIndex, polyActionHandler);
|
|
25051
24940
|
function createPolyControls(arg0) {
|
|
25052
24941
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
25053
24942
|
const controls = {};
|
|
25054
24943
|
for (let idx = 0; idx < (typeof arg0 === 'number' ? arg0 : arg0.points.length); idx++) {
|
|
25055
24944
|
controls["p".concat(idx)] = new Control(_objectSpread2({
|
|
25056
24945
|
actionName: 'modifyPoly',
|
|
25057
|
-
positionHandler:
|
|
25058
|
-
actionHandler:
|
|
24946
|
+
positionHandler: createPolyPositionHandler(idx),
|
|
24947
|
+
actionHandler: createPolyActionHandler(idx)
|
|
25059
24948
|
}, options));
|
|
25060
24949
|
}
|
|
25061
24950
|
return controls;
|
|
@@ -25065,11 +24954,15 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
25065
24954
|
__proto__: null,
|
|
25066
24955
|
changeWidth: changeWidth,
|
|
25067
24956
|
createObjectDefaultControls: createObjectDefaultControls,
|
|
24957
|
+
createPolyActionHandler: createPolyActionHandler,
|
|
25068
24958
|
createPolyControls: createPolyControls,
|
|
24959
|
+
createPolyPositionHandler: createPolyPositionHandler,
|
|
25069
24960
|
createResizeControls: createResizeControls,
|
|
25070
24961
|
createTextboxDefaultControls: createTextboxDefaultControls,
|
|
25071
24962
|
dragHandler: dragHandler,
|
|
24963
|
+
factoryPolyActionHandler: factoryPolyActionHandler,
|
|
25072
24964
|
getLocalPoint: getLocalPoint,
|
|
24965
|
+
polyActionHandler: polyActionHandler,
|
|
25073
24966
|
renderCircleControl: renderCircleControl,
|
|
25074
24967
|
renderSquareControl: renderSquareControl,
|
|
25075
24968
|
rotationStyleHandler: rotationStyleHandler,
|
|
@@ -25164,25 +25057,23 @@ class BaseFilter {
|
|
|
25164
25057
|
const fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
|
|
25165
25058
|
const program = gl.createProgram();
|
|
25166
25059
|
if (!vertexShader || !fragmentShader || !program) {
|
|
25167
|
-
throw new
|
|
25060
|
+
throw new FabricError('Vertex, fragment shader or program creation error');
|
|
25168
25061
|
}
|
|
25169
25062
|
gl.shaderSource(vertexShader, vertexSource);
|
|
25170
25063
|
gl.compileShader(vertexShader);
|
|
25171
25064
|
if (!gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS)) {
|
|
25172
|
-
throw new
|
|
25065
|
+
throw new FabricError("Vertex shader compile error for ".concat(this.type, ": ").concat(gl.getShaderInfoLog(vertexShader)));
|
|
25173
25066
|
}
|
|
25174
25067
|
gl.shaderSource(fragmentShader, fragmentSource);
|
|
25175
25068
|
gl.compileShader(fragmentShader);
|
|
25176
25069
|
if (!gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS)) {
|
|
25177
|
-
throw new
|
|
25070
|
+
throw new FabricError("Fragment shader compile error for ".concat(this.type, ": ").concat(gl.getShaderInfoLog(fragmentShader)));
|
|
25178
25071
|
}
|
|
25179
25072
|
gl.attachShader(program, vertexShader);
|
|
25180
25073
|
gl.attachShader(program, fragmentShader);
|
|
25181
25074
|
gl.linkProgram(program);
|
|
25182
25075
|
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));
|
|
25076
|
+
throw new FabricError("Shader link error for \"".concat(this.type, "\" ").concat(gl.getProgramInfoLog(program)));
|
|
25186
25077
|
}
|
|
25187
25078
|
const uniformLocations = this.getUniformLocations(gl, program) || {};
|
|
25188
25079
|
uniformLocations.uStepW = gl.getUniformLocation(program, 'uStepW');
|
|
@@ -25781,7 +25672,7 @@ class BlendImage extends BaseFilter {
|
|
|
25781
25672
|
image
|
|
25782
25673
|
} = _ref2,
|
|
25783
25674
|
filterOptions = _objectWithoutProperties(_ref2, _excluded$3);
|
|
25784
|
-
return
|
|
25675
|
+
return FabricImage.fromObject(image, options).then(enlivedImage => new this(_objectSpread2(_objectSpread2({}, filterOptions), {}, {
|
|
25785
25676
|
image: enlivedImage
|
|
25786
25677
|
})));
|
|
25787
25678
|
}
|
|
@@ -27735,5 +27626,5 @@ var filters = /*#__PURE__*/Object.freeze({
|
|
|
27735
27626
|
Vintage: Vintage
|
|
27736
27627
|
});
|
|
27737
27628
|
|
|
27738
|
-
export { ActiveSelection, BaseBrush, Canvas, Canvas2dFilterBackend, CanvasDOMManager, Circle, CircleBrush, Color, Control, Ellipse, Gradient, Group, IText, Image, Intersection, Line, FabricObject 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 };
|
|
27629
|
+
export { ActiveSelection, BaseBrush, Canvas, Canvas2dFilterBackend, CanvasDOMManager, Circle, CircleBrush, Color, Control, Ellipse, FabricImage, FabricObject, FabricText, Gradient, Group, IText, FabricImage as Image, Intersection, Line, FabricObject as Object, Observable, Path, Pattern, PatternBrush, PencilBrush, Point, Polygon, Polyline, Rect, Shadow, SprayBrush, StaticCanvas, StaticCanvasDOMManager, FabricText as 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
27630
|
//# sourceMappingURL=index.mjs.map
|