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.
Files changed (48) hide show
  1. package/dist/index.js +106 -24
  2. package/dist/index.js.map +1 -1
  3. package/dist/index.min.js +1 -1
  4. package/dist/index.min.js.map +1 -1
  5. package/dist/index.min.mjs +1 -1
  6. package/dist/index.min.mjs.map +1 -1
  7. package/dist/index.mjs +106 -24
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/index.node.cjs +106 -24
  10. package/dist/index.node.cjs.map +1 -1
  11. package/dist/index.node.mjs +106 -24
  12. package/dist/index.node.mjs.map +1 -1
  13. package/dist/package.json.min.mjs +1 -1
  14. package/dist/package.json.mjs +1 -1
  15. package/dist/src/canvas/Canvas.d.ts +10 -0
  16. package/dist/src/canvas/Canvas.d.ts.map +1 -1
  17. package/dist/src/canvas/Canvas.min.mjs +1 -1
  18. package/dist/src/canvas/Canvas.min.mjs.map +1 -1
  19. package/dist/src/canvas/Canvas.mjs +85 -10
  20. package/dist/src/canvas/Canvas.mjs.map +1 -1
  21. package/dist/src/canvas/SelectableCanvas.d.ts +6 -0
  22. package/dist/src/canvas/SelectableCanvas.d.ts.map +1 -1
  23. package/dist/src/canvas/SelectableCanvas.min.mjs.map +1 -1
  24. package/dist/src/canvas/SelectableCanvas.mjs.map +1 -1
  25. package/dist/src/canvas/StaticCanvas.d.ts.map +1 -1
  26. package/dist/src/canvas/StaticCanvas.min.mjs +1 -1
  27. package/dist/src/canvas/StaticCanvas.min.mjs.map +1 -1
  28. package/dist/src/canvas/StaticCanvas.mjs +15 -12
  29. package/dist/src/canvas/StaticCanvas.mjs.map +1 -1
  30. package/dist/src/shapes/Object/FabricObjectSVGExportMixin.d.ts.map +1 -1
  31. package/dist/src/shapes/Object/FabricObjectSVGExportMixin.min.mjs +1 -1
  32. package/dist/src/shapes/Object/FabricObjectSVGExportMixin.min.mjs.map +1 -1
  33. package/dist/src/shapes/Object/FabricObjectSVGExportMixin.mjs +5 -1
  34. package/dist/src/shapes/Object/FabricObjectSVGExportMixin.mjs.map +1 -1
  35. package/dist-extensions/src/canvas/Canvas.d.ts +10 -0
  36. package/dist-extensions/src/canvas/Canvas.d.ts.map +1 -1
  37. package/dist-extensions/src/canvas/SelectableCanvas.d.ts +6 -0
  38. package/dist-extensions/src/canvas/SelectableCanvas.d.ts.map +1 -1
  39. package/dist-extensions/src/canvas/StaticCanvas.d.ts.map +1 -1
  40. package/dist-extensions/src/shapes/Object/FabricObjectSVGExportMixin.d.ts.map +1 -1
  41. package/package.json +1 -1
  42. package/src/canvas/Canvas.ts +89 -8
  43. package/src/canvas/SelectableCanvas.ts +6 -0
  44. package/src/canvas/StaticCanvas.spec.ts +23 -0
  45. package/src/canvas/StaticCanvas.ts +19 -12
  46. package/src/canvas/__tests__/additiveSelection.test.ts +118 -0
  47. package/src/shapes/Object/FabricObjectSVGExportMixin.ts +5 -1
  48. package/src/shapes/Text/TextSVGExportMixin.spec.ts +16 -0
package/dist/index.js CHANGED
@@ -366,7 +366,7 @@
366
366
  }
367
367
  const cache = new Cache();
368
368
 
369
- var version = "6.7.13";
369
+ var version = "6.7.15";
370
370
 
371
371
  // use this syntax so babel plugin see this import here
372
372
  const VERSION = version;
@@ -3080,25 +3080,28 @@
3080
3080
  */
3081
3081
  _createPathForText() {
3082
3082
  const pathMarkups = [];
3083
- let instance,
3084
- i,
3085
- len,
3086
- objects = this._objects;
3087
- for (i = 0, len = objects.length; i < len; i++) {
3088
- instance = objects[i];
3083
+ const objects = [];
3084
+ this._objects.forEach(function add(object) {
3085
+ objects.push(object);
3086
+ if (isCollection(object)) {
3087
+ object._objects.forEach(add);
3088
+ }
3089
+ });
3090
+ objects.forEach(instance => {
3089
3091
  if (instance.excludeFromExport) {
3090
- continue;
3092
+ return;
3091
3093
  }
3092
3094
  if (!isTextObject(instance) || !instance.path) {
3093
- continue;
3095
+ return;
3094
3096
  }
3095
- let pathId = `TEXTPATH_${instance.id}`;
3096
- let pathMarkup = instance.path._toSVG();
3097
- let index = pathMarkup.indexOf('COMMON_PARTS');
3097
+ const pathId = `TEXTPATH_${instance.id}`;
3098
+ const pathMarkup = instance.path._toSVG();
3099
+ const index = pathMarkup.indexOf('COMMON_PARTS');
3100
+
3098
3101
  // 加上id, 和路径偏移
3099
3102
  pathMarkup[index] = ['id="' + pathId + '" ', 'transform="translate(' + -instance.path.pathOffset.x + ',' + -instance.path.pathOffset.y + ')" '].join('');
3100
3103
  pathMarkups.push(pathMarkup.join(''));
3101
- }
3104
+ });
3102
3105
  return pathMarkups.join('\n');
3103
3106
  }
3104
3107
  createSVGClipPathMarkup(options) {
@@ -5051,13 +5054,17 @@
5051
5054
  commonPieces = [styleInfo, vectorEffect, noStyle ? '' : this.addPaintOrder(), ' ', additionalTransform ? `transform="${additionalTransform}" ` : ''].join('');
5052
5055
 
5053
5056
  // James added shadow 放在上面
5057
+ // 文本等调用方已经通过 withShadow 挂载 filter 时,避免再额外复制一份可见对象,
5058
+ // 但仍然需要输出 filter 定义,否则普通 SVG 会丢失阴影。
5054
5059
  if (shadow) {
5060
+ markup.push(shadow.toSVG(this));
5061
+ }
5062
+ if (shadow && !withShadow) {
5055
5063
  const styleInfoWithShadow = 'style="' + this.getSvgStyles(false) + '" ';
5056
5064
  const commonPiecesWithShadow = [styleInfoWithShadow, vectorEffect, noStyle ? '' : this.addPaintOrder(), ' ', additionalTransform ? 'transform="' + additionalTransform + '" ' : ''].join('');
5057
5065
  const objectMarkupCopy = JSON.parse(JSON.stringify(objectMarkup));
5058
5066
  objectMarkupCopy[index] = commonPiecesWithShadow;
5059
5067
  markup.push(objectMarkupCopy.join(''));
5060
- markup.push(shadow.toSVG(this));
5061
5068
  }
5062
5069
  // objectMarkup中是导出主对象(如path)的svg,index下标是style,放在commonPieces
5063
5070
  objectMarkup[index] = commonPieces;
@@ -15813,11 +15820,16 @@
15813
15820
  shouldRender = true;
15814
15821
  } else if (this._shouldClearSelection(e, target)) {
15815
15822
  const objs = this.getActiveObjects();
15816
- this.discardActiveObject(e);
15817
- // 多选取消,重置Coords, 防止无法再次选中
15818
- objs.forEach(obj => obj.setCoords());
15819
- if (!target && this.switchIsolateObject(e)) {
15820
- return;
15823
+ // holding the selection key keeps the current selection alive so that the
15824
+ // following box selection (or click) can add to it instead of replacing it
15825
+ const additive = !!objs.length && !!this.selection && this._isSelectionKeyPressed(e);
15826
+ if (!additive) {
15827
+ this.discardActiveObject(e);
15828
+ // 多选取消,重置Coords, 防止无法再次选中
15829
+ objs.forEach(obj => obj.setCoords());
15830
+ if (!target && this.switchIsolateObject(e)) {
15831
+ return;
15832
+ }
15821
15833
  }
15822
15834
  }
15823
15835
  // we start a group selector rectangle if
@@ -15832,7 +15844,12 @@
15832
15844
  x: p.x,
15833
15845
  y: p.y,
15834
15846
  deltaY: 0,
15835
- deltaX: 0
15847
+ deltaX: 0,
15848
+ // capture the modifier now: releasing the key during the drag
15849
+ // must not turn an additive selection into a replacing one
15850
+ ...(this._isSelectionKeyPressed(e) ? {
15851
+ additive: true
15852
+ } : {})
15836
15853
  };
15837
15854
  }
15838
15855
 
@@ -16215,13 +16232,17 @@
16215
16232
  x,
16216
16233
  y,
16217
16234
  deltaX,
16218
- deltaY
16235
+ deltaY,
16236
+ additive
16219
16237
  } = this._groupSelector,
16220
16238
  point1 = new Point(x, y),
16221
16239
  point2 = point1.add(new Point(deltaX, deltaY)),
16222
16240
  tl = point1.min(point2),
16223
16241
  br = point1.max(point2),
16224
16242
  size = br.subtract(tl);
16243
+
16244
+ // the box only collects the first level objects of the current selection scope,
16245
+ // meaning the children of the isolated group, or the canvas root objects
16225
16246
  const collectedObjects = this.collectObjects(this.getSearchTargets(), {
16226
16247
  left: tl.x,
16227
16248
  top: tl.y,
@@ -16230,6 +16251,16 @@
16230
16251
  }, {
16231
16252
  includeIntersecting: !this.selectionFullyContained
16232
16253
  });
16254
+
16255
+ // cleanup
16256
+ this._groupSelector = null;
16257
+
16258
+ // the selection key was held while dragging and there is something to add to:
16259
+ // keep the current selection and merge the collected objects into it
16260
+ if (additive && this.getActiveObjects().length) {
16261
+ this.addToActiveSelection(e, collectedObjects);
16262
+ return true;
16263
+ }
16233
16264
  const objects =
16234
16265
  // though this method runs only after mouse move the pointer could do a mouse up on the same position as mouse down
16235
16266
  // should it be handled as is?
@@ -16250,12 +16281,63 @@
16250
16281
  canvas: this
16251
16282
  }), e);
16252
16283
  }
16253
-
16254
- // cleanup
16255
- this._groupSelector = null;
16256
16284
  return true;
16257
16285
  }
16258
16286
 
16287
+ /**
16288
+ * Merges the objects collected by a box selection into the current selection.
16289
+ * Only objects belonging to the current selection scope are taken into account:
16290
+ * the first level children of the isolated group, or the canvas root objects
16291
+ * when no group is isolated. Previously selected objects outside of that scope
16292
+ * are removed from the selection, since a selection can't mix objects coming
16293
+ * from different containers.
16294
+ * @private
16295
+ */
16296
+ addToActiveSelection(e, collectedObjects) {
16297
+ const prevActiveObjects = this.getActiveObjects(),
16298
+ scope = this.getSearchTargets(),
16299
+ kept = prevActiveObjects.filter(object => scope.includes(object)),
16300
+ dropped = prevActiveObjects.filter(object => !scope.includes(object)),
16301
+ added = collectedObjects.filter(object => !prevActiveObjects.includes(object) && !object.onSelect({
16302
+ e
16303
+ }));
16304
+ if (!kept.length && !added.length) {
16305
+ // the box didn't add anything and nothing of the current selection
16306
+ // belongs to this scope
16307
+ dropped.length && this.discardActiveObject(e);
16308
+ return;
16309
+ }
16310
+ const activeObject = this._activeObject;
16311
+ if (isActiveSelection(activeObject)) {
16312
+ dropped.length && activeObject.remove(...dropped);
16313
+ added.length && activeObject.multiSelectAdd(...added);
16314
+ if (activeObject.size() === 1) {
16315
+ // deselecting the active selection returns the last remaining object to the canvas
16316
+ this._setActiveObject(activeObject.item(0), e);
16317
+ }
16318
+ this._fireSelectionEvents(prevActiveObjects, e);
16319
+ return;
16320
+ }
16321
+ const objects = kept.concat(added);
16322
+ if (objects.length === 1) {
16323
+ objects[0] !== activeObject && this.setActiveObject(objects[0], e);
16324
+ return;
16325
+ }
16326
+
16327
+ // build the active selection out of the kept and the newly collected objects
16328
+ const klass = classRegistry.getClass('ActiveSelection');
16329
+ const newActiveSelection = new klass([], {
16330
+ /**
16331
+ * it is crucial to pass the canvas ref before calling {@link ActiveSelection#multiSelectAdd}
16332
+ * since it uses {@link FabricObject#isInFrontOf} which relies on the canvas ref
16333
+ */
16334
+ canvas: this
16335
+ });
16336
+ newActiveSelection.multiSelectAdd(...objects);
16337
+ this._setActiveObject(newActiveSelection, e);
16338
+ this._fireSelectionEvents(prevActiveObjects, e);
16339
+ }
16340
+
16259
16341
  /**
16260
16342
  * @override clear {@link textEditingManager}
16261
16343
  */