fabric-vectr 6.7.13 → 6.7.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +106 -24
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/index.min.mjs +1 -1
- package/dist/index.min.mjs.map +1 -1
- package/dist/index.mjs +106 -24
- package/dist/index.mjs.map +1 -1
- package/dist/index.node.cjs +106 -24
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +106 -24
- package/dist/index.node.mjs.map +1 -1
- package/dist/package.json.min.mjs +1 -1
- package/dist/package.json.mjs +1 -1
- package/dist/src/canvas/Canvas.d.ts +10 -0
- package/dist/src/canvas/Canvas.d.ts.map +1 -1
- package/dist/src/canvas/Canvas.min.mjs +1 -1
- package/dist/src/canvas/Canvas.min.mjs.map +1 -1
- package/dist/src/canvas/Canvas.mjs +85 -10
- package/dist/src/canvas/Canvas.mjs.map +1 -1
- package/dist/src/canvas/SelectableCanvas.d.ts +6 -0
- package/dist/src/canvas/SelectableCanvas.d.ts.map +1 -1
- package/dist/src/canvas/SelectableCanvas.min.mjs.map +1 -1
- package/dist/src/canvas/SelectableCanvas.mjs.map +1 -1
- package/dist/src/canvas/StaticCanvas.d.ts.map +1 -1
- package/dist/src/canvas/StaticCanvas.min.mjs +1 -1
- package/dist/src/canvas/StaticCanvas.min.mjs.map +1 -1
- package/dist/src/canvas/StaticCanvas.mjs +15 -12
- package/dist/src/canvas/StaticCanvas.mjs.map +1 -1
- package/dist/src/shapes/Object/FabricObjectSVGExportMixin.d.ts.map +1 -1
- package/dist/src/shapes/Object/FabricObjectSVGExportMixin.min.mjs +1 -1
- package/dist/src/shapes/Object/FabricObjectSVGExportMixin.min.mjs.map +1 -1
- package/dist/src/shapes/Object/FabricObjectSVGExportMixin.mjs +5 -1
- package/dist/src/shapes/Object/FabricObjectSVGExportMixin.mjs.map +1 -1
- package/dist-extensions/src/canvas/Canvas.d.ts +10 -0
- package/dist-extensions/src/canvas/Canvas.d.ts.map +1 -1
- package/dist-extensions/src/canvas/SelectableCanvas.d.ts +6 -0
- package/dist-extensions/src/canvas/SelectableCanvas.d.ts.map +1 -1
- package/dist-extensions/src/canvas/StaticCanvas.d.ts.map +1 -1
- package/dist-extensions/src/shapes/Object/FabricObjectSVGExportMixin.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/canvas/Canvas.ts +89 -8
- package/src/canvas/SelectableCanvas.ts +6 -0
- package/src/canvas/StaticCanvas.spec.ts +23 -0
- package/src/canvas/StaticCanvas.ts +19 -12
- package/src/canvas/__tests__/additiveSelection.test.ts +118 -0
- package/src/shapes/Object/FabricObjectSVGExportMixin.ts +5 -1
- package/src/shapes/Text/TextSVGExportMixin.spec.ts +16 -0
package/dist/index.mjs
CHANGED
|
@@ -360,7 +360,7 @@ class Cache {
|
|
|
360
360
|
}
|
|
361
361
|
const cache = new Cache();
|
|
362
362
|
|
|
363
|
-
var version = "6.7.
|
|
363
|
+
var version = "6.7.15";
|
|
364
364
|
|
|
365
365
|
// use this syntax so babel plugin see this import here
|
|
366
366
|
const VERSION = version;
|
|
@@ -3074,25 +3074,28 @@ class StaticCanvas extends createCollectionMixin(CommonMethods) {
|
|
|
3074
3074
|
*/
|
|
3075
3075
|
_createPathForText() {
|
|
3076
3076
|
const pathMarkups = [];
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3077
|
+
const objects = [];
|
|
3078
|
+
this._objects.forEach(function add(object) {
|
|
3079
|
+
objects.push(object);
|
|
3080
|
+
if (isCollection(object)) {
|
|
3081
|
+
object._objects.forEach(add);
|
|
3082
|
+
}
|
|
3083
|
+
});
|
|
3084
|
+
objects.forEach(instance => {
|
|
3083
3085
|
if (instance.excludeFromExport) {
|
|
3084
|
-
|
|
3086
|
+
return;
|
|
3085
3087
|
}
|
|
3086
3088
|
if (!isTextObject(instance) || !instance.path) {
|
|
3087
|
-
|
|
3089
|
+
return;
|
|
3088
3090
|
}
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3091
|
+
const pathId = `TEXTPATH_${instance.id}`;
|
|
3092
|
+
const pathMarkup = instance.path._toSVG();
|
|
3093
|
+
const index = pathMarkup.indexOf('COMMON_PARTS');
|
|
3094
|
+
|
|
3092
3095
|
// 加上id, 和路径偏移
|
|
3093
3096
|
pathMarkup[index] = ['id="' + pathId + '" ', 'transform="translate(' + -instance.path.pathOffset.x + ',' + -instance.path.pathOffset.y + ')" '].join('');
|
|
3094
3097
|
pathMarkups.push(pathMarkup.join(''));
|
|
3095
|
-
}
|
|
3098
|
+
});
|
|
3096
3099
|
return pathMarkups.join('\n');
|
|
3097
3100
|
}
|
|
3098
3101
|
createSVGClipPathMarkup(options) {
|
|
@@ -5045,13 +5048,17 @@ class FabricObjectSVGExportMixin {
|
|
|
5045
5048
|
commonPieces = [styleInfo, vectorEffect, noStyle ? '' : this.addPaintOrder(), ' ', additionalTransform ? `transform="${additionalTransform}" ` : ''].join('');
|
|
5046
5049
|
|
|
5047
5050
|
// James added shadow 放在上面
|
|
5051
|
+
// 文本等调用方已经通过 withShadow 挂载 filter 时,避免再额外复制一份可见对象,
|
|
5052
|
+
// 但仍然需要输出 filter 定义,否则普通 SVG 会丢失阴影。
|
|
5048
5053
|
if (shadow) {
|
|
5054
|
+
markup.push(shadow.toSVG(this));
|
|
5055
|
+
}
|
|
5056
|
+
if (shadow && !withShadow) {
|
|
5049
5057
|
const styleInfoWithShadow = 'style="' + this.getSvgStyles(false) + '" ';
|
|
5050
5058
|
const commonPiecesWithShadow = [styleInfoWithShadow, vectorEffect, noStyle ? '' : this.addPaintOrder(), ' ', additionalTransform ? 'transform="' + additionalTransform + '" ' : ''].join('');
|
|
5051
5059
|
const objectMarkupCopy = JSON.parse(JSON.stringify(objectMarkup));
|
|
5052
5060
|
objectMarkupCopy[index] = commonPiecesWithShadow;
|
|
5053
5061
|
markup.push(objectMarkupCopy.join(''));
|
|
5054
|
-
markup.push(shadow.toSVG(this));
|
|
5055
5062
|
}
|
|
5056
5063
|
// objectMarkup中是导出主对象(如path)的svg,index下标是style,放在commonPieces
|
|
5057
5064
|
objectMarkup[index] = commonPieces;
|
|
@@ -15807,11 +15814,16 @@ class Canvas extends SelectableCanvas {
|
|
|
15807
15814
|
shouldRender = true;
|
|
15808
15815
|
} else if (this._shouldClearSelection(e, target)) {
|
|
15809
15816
|
const objs = this.getActiveObjects();
|
|
15810
|
-
|
|
15811
|
-
//
|
|
15812
|
-
objs.
|
|
15813
|
-
if (!
|
|
15814
|
-
|
|
15817
|
+
// holding the selection key keeps the current selection alive so that the
|
|
15818
|
+
// following box selection (or click) can add to it instead of replacing it
|
|
15819
|
+
const additive = !!objs.length && !!this.selection && this._isSelectionKeyPressed(e);
|
|
15820
|
+
if (!additive) {
|
|
15821
|
+
this.discardActiveObject(e);
|
|
15822
|
+
// 多选取消,重置Coords, 防止无法再次选中
|
|
15823
|
+
objs.forEach(obj => obj.setCoords());
|
|
15824
|
+
if (!target && this.switchIsolateObject(e)) {
|
|
15825
|
+
return;
|
|
15826
|
+
}
|
|
15815
15827
|
}
|
|
15816
15828
|
}
|
|
15817
15829
|
// we start a group selector rectangle if
|
|
@@ -15826,7 +15838,12 @@ class Canvas extends SelectableCanvas {
|
|
|
15826
15838
|
x: p.x,
|
|
15827
15839
|
y: p.y,
|
|
15828
15840
|
deltaY: 0,
|
|
15829
|
-
deltaX: 0
|
|
15841
|
+
deltaX: 0,
|
|
15842
|
+
// capture the modifier now: releasing the key during the drag
|
|
15843
|
+
// must not turn an additive selection into a replacing one
|
|
15844
|
+
...(this._isSelectionKeyPressed(e) ? {
|
|
15845
|
+
additive: true
|
|
15846
|
+
} : {})
|
|
15830
15847
|
};
|
|
15831
15848
|
}
|
|
15832
15849
|
|
|
@@ -16209,13 +16226,17 @@ class Canvas extends SelectableCanvas {
|
|
|
16209
16226
|
x,
|
|
16210
16227
|
y,
|
|
16211
16228
|
deltaX,
|
|
16212
|
-
deltaY
|
|
16229
|
+
deltaY,
|
|
16230
|
+
additive
|
|
16213
16231
|
} = this._groupSelector,
|
|
16214
16232
|
point1 = new Point(x, y),
|
|
16215
16233
|
point2 = point1.add(new Point(deltaX, deltaY)),
|
|
16216
16234
|
tl = point1.min(point2),
|
|
16217
16235
|
br = point1.max(point2),
|
|
16218
16236
|
size = br.subtract(tl);
|
|
16237
|
+
|
|
16238
|
+
// the box only collects the first level objects of the current selection scope,
|
|
16239
|
+
// meaning the children of the isolated group, or the canvas root objects
|
|
16219
16240
|
const collectedObjects = this.collectObjects(this.getSearchTargets(), {
|
|
16220
16241
|
left: tl.x,
|
|
16221
16242
|
top: tl.y,
|
|
@@ -16224,6 +16245,16 @@ class Canvas extends SelectableCanvas {
|
|
|
16224
16245
|
}, {
|
|
16225
16246
|
includeIntersecting: !this.selectionFullyContained
|
|
16226
16247
|
});
|
|
16248
|
+
|
|
16249
|
+
// cleanup
|
|
16250
|
+
this._groupSelector = null;
|
|
16251
|
+
|
|
16252
|
+
// the selection key was held while dragging and there is something to add to:
|
|
16253
|
+
// keep the current selection and merge the collected objects into it
|
|
16254
|
+
if (additive && this.getActiveObjects().length) {
|
|
16255
|
+
this.addToActiveSelection(e, collectedObjects);
|
|
16256
|
+
return true;
|
|
16257
|
+
}
|
|
16227
16258
|
const objects =
|
|
16228
16259
|
// though this method runs only after mouse move the pointer could do a mouse up on the same position as mouse down
|
|
16229
16260
|
// should it be handled as is?
|
|
@@ -16244,12 +16275,63 @@ class Canvas extends SelectableCanvas {
|
|
|
16244
16275
|
canvas: this
|
|
16245
16276
|
}), e);
|
|
16246
16277
|
}
|
|
16247
|
-
|
|
16248
|
-
// cleanup
|
|
16249
|
-
this._groupSelector = null;
|
|
16250
16278
|
return true;
|
|
16251
16279
|
}
|
|
16252
16280
|
|
|
16281
|
+
/**
|
|
16282
|
+
* Merges the objects collected by a box selection into the current selection.
|
|
16283
|
+
* Only objects belonging to the current selection scope are taken into account:
|
|
16284
|
+
* the first level children of the isolated group, or the canvas root objects
|
|
16285
|
+
* when no group is isolated. Previously selected objects outside of that scope
|
|
16286
|
+
* are removed from the selection, since a selection can't mix objects coming
|
|
16287
|
+
* from different containers.
|
|
16288
|
+
* @private
|
|
16289
|
+
*/
|
|
16290
|
+
addToActiveSelection(e, collectedObjects) {
|
|
16291
|
+
const prevActiveObjects = this.getActiveObjects(),
|
|
16292
|
+
scope = this.getSearchTargets(),
|
|
16293
|
+
kept = prevActiveObjects.filter(object => scope.includes(object)),
|
|
16294
|
+
dropped = prevActiveObjects.filter(object => !scope.includes(object)),
|
|
16295
|
+
added = collectedObjects.filter(object => !prevActiveObjects.includes(object) && !object.onSelect({
|
|
16296
|
+
e
|
|
16297
|
+
}));
|
|
16298
|
+
if (!kept.length && !added.length) {
|
|
16299
|
+
// the box didn't add anything and nothing of the current selection
|
|
16300
|
+
// belongs to this scope
|
|
16301
|
+
dropped.length && this.discardActiveObject(e);
|
|
16302
|
+
return;
|
|
16303
|
+
}
|
|
16304
|
+
const activeObject = this._activeObject;
|
|
16305
|
+
if (isActiveSelection(activeObject)) {
|
|
16306
|
+
dropped.length && activeObject.remove(...dropped);
|
|
16307
|
+
added.length && activeObject.multiSelectAdd(...added);
|
|
16308
|
+
if (activeObject.size() === 1) {
|
|
16309
|
+
// deselecting the active selection returns the last remaining object to the canvas
|
|
16310
|
+
this._setActiveObject(activeObject.item(0), e);
|
|
16311
|
+
}
|
|
16312
|
+
this._fireSelectionEvents(prevActiveObjects, e);
|
|
16313
|
+
return;
|
|
16314
|
+
}
|
|
16315
|
+
const objects = kept.concat(added);
|
|
16316
|
+
if (objects.length === 1) {
|
|
16317
|
+
objects[0] !== activeObject && this.setActiveObject(objects[0], e);
|
|
16318
|
+
return;
|
|
16319
|
+
}
|
|
16320
|
+
|
|
16321
|
+
// build the active selection out of the kept and the newly collected objects
|
|
16322
|
+
const klass = classRegistry.getClass('ActiveSelection');
|
|
16323
|
+
const newActiveSelection = new klass([], {
|
|
16324
|
+
/**
|
|
16325
|
+
* it is crucial to pass the canvas ref before calling {@link ActiveSelection#multiSelectAdd}
|
|
16326
|
+
* since it uses {@link FabricObject#isInFrontOf} which relies on the canvas ref
|
|
16327
|
+
*/
|
|
16328
|
+
canvas: this
|
|
16329
|
+
});
|
|
16330
|
+
newActiveSelection.multiSelectAdd(...objects);
|
|
16331
|
+
this._setActiveObject(newActiveSelection, e);
|
|
16332
|
+
this._fireSelectionEvents(prevActiveObjects, e);
|
|
16333
|
+
}
|
|
16334
|
+
|
|
16253
16335
|
/**
|
|
16254
16336
|
* @override clear {@link textEditingManager}
|
|
16255
16337
|
*/
|