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
@@ -418,7 +418,7 @@ class Cache {
418
418
  }
419
419
  const cache = new Cache();
420
420
 
421
- var version = "6.7.13";
421
+ var version = "6.7.15";
422
422
 
423
423
  // use this syntax so babel plugin see this import here
424
424
  const VERSION = version;
@@ -3132,25 +3132,28 @@ let StaticCanvas$1 = class StaticCanvas extends createCollectionMixin(CommonMeth
3132
3132
  */
3133
3133
  _createPathForText() {
3134
3134
  const pathMarkups = [];
3135
- let instance,
3136
- i,
3137
- len,
3138
- objects = this._objects;
3139
- for (i = 0, len = objects.length; i < len; i++) {
3140
- instance = objects[i];
3135
+ const objects = [];
3136
+ this._objects.forEach(function add(object) {
3137
+ objects.push(object);
3138
+ if (isCollection(object)) {
3139
+ object._objects.forEach(add);
3140
+ }
3141
+ });
3142
+ objects.forEach(instance => {
3141
3143
  if (instance.excludeFromExport) {
3142
- continue;
3144
+ return;
3143
3145
  }
3144
3146
  if (!isTextObject(instance) || !instance.path) {
3145
- continue;
3147
+ return;
3146
3148
  }
3147
- let pathId = `TEXTPATH_${instance.id}`;
3148
- let pathMarkup = instance.path._toSVG();
3149
- let index = pathMarkup.indexOf('COMMON_PARTS');
3149
+ const pathId = `TEXTPATH_${instance.id}`;
3150
+ const pathMarkup = instance.path._toSVG();
3151
+ const index = pathMarkup.indexOf('COMMON_PARTS');
3152
+
3150
3153
  // 加上id, 和路径偏移
3151
3154
  pathMarkup[index] = ['id="' + pathId + '" ', 'transform="translate(' + -instance.path.pathOffset.x + ',' + -instance.path.pathOffset.y + ')" '].join('');
3152
3155
  pathMarkups.push(pathMarkup.join(''));
3153
- }
3156
+ });
3154
3157
  return pathMarkups.join('\n');
3155
3158
  }
3156
3159
  createSVGClipPathMarkup(options) {
@@ -5103,13 +5106,17 @@ class FabricObjectSVGExportMixin {
5103
5106
  commonPieces = [styleInfo, vectorEffect, noStyle ? '' : this.addPaintOrder(), ' ', additionalTransform ? `transform="${additionalTransform}" ` : ''].join('');
5104
5107
 
5105
5108
  // James added shadow 放在上面
5109
+ // 文本等调用方已经通过 withShadow 挂载 filter 时,避免再额外复制一份可见对象,
5110
+ // 但仍然需要输出 filter 定义,否则普通 SVG 会丢失阴影。
5106
5111
  if (shadow) {
5112
+ markup.push(shadow.toSVG(this));
5113
+ }
5114
+ if (shadow && !withShadow) {
5107
5115
  const styleInfoWithShadow = 'style="' + this.getSvgStyles(false) + '" ';
5108
5116
  const commonPiecesWithShadow = [styleInfoWithShadow, vectorEffect, noStyle ? '' : this.addPaintOrder(), ' ', additionalTransform ? 'transform="' + additionalTransform + '" ' : ''].join('');
5109
5117
  const objectMarkupCopy = JSON.parse(JSON.stringify(objectMarkup));
5110
5118
  objectMarkupCopy[index] = commonPiecesWithShadow;
5111
5119
  markup.push(objectMarkupCopy.join(''));
5112
- markup.push(shadow.toSVG(this));
5113
5120
  }
5114
5121
  // objectMarkup中是导出主对象(如path)的svg,index下标是style,放在commonPieces
5115
5122
  objectMarkup[index] = commonPieces;
@@ -15865,11 +15872,16 @@ let Canvas$1 = class Canvas extends SelectableCanvas {
15865
15872
  shouldRender = true;
15866
15873
  } else if (this._shouldClearSelection(e, target)) {
15867
15874
  const objs = this.getActiveObjects();
15868
- this.discardActiveObject(e);
15869
- // 多选取消,重置Coords, 防止无法再次选中
15870
- objs.forEach(obj => obj.setCoords());
15871
- if (!target && this.switchIsolateObject(e)) {
15872
- return;
15875
+ // holding the selection key keeps the current selection alive so that the
15876
+ // following box selection (or click) can add to it instead of replacing it
15877
+ const additive = !!objs.length && !!this.selection && this._isSelectionKeyPressed(e);
15878
+ if (!additive) {
15879
+ this.discardActiveObject(e);
15880
+ // 多选取消,重置Coords, 防止无法再次选中
15881
+ objs.forEach(obj => obj.setCoords());
15882
+ if (!target && this.switchIsolateObject(e)) {
15883
+ return;
15884
+ }
15873
15885
  }
15874
15886
  }
15875
15887
  // we start a group selector rectangle if
@@ -15884,7 +15896,12 @@ let Canvas$1 = class Canvas extends SelectableCanvas {
15884
15896
  x: p.x,
15885
15897
  y: p.y,
15886
15898
  deltaY: 0,
15887
- deltaX: 0
15899
+ deltaX: 0,
15900
+ // capture the modifier now: releasing the key during the drag
15901
+ // must not turn an additive selection into a replacing one
15902
+ ...(this._isSelectionKeyPressed(e) ? {
15903
+ additive: true
15904
+ } : {})
15888
15905
  };
15889
15906
  }
15890
15907
 
@@ -16267,13 +16284,17 @@ let Canvas$1 = class Canvas extends SelectableCanvas {
16267
16284
  x,
16268
16285
  y,
16269
16286
  deltaX,
16270
- deltaY
16287
+ deltaY,
16288
+ additive
16271
16289
  } = this._groupSelector,
16272
16290
  point1 = new Point(x, y),
16273
16291
  point2 = point1.add(new Point(deltaX, deltaY)),
16274
16292
  tl = point1.min(point2),
16275
16293
  br = point1.max(point2),
16276
16294
  size = br.subtract(tl);
16295
+
16296
+ // the box only collects the first level objects of the current selection scope,
16297
+ // meaning the children of the isolated group, or the canvas root objects
16277
16298
  const collectedObjects = this.collectObjects(this.getSearchTargets(), {
16278
16299
  left: tl.x,
16279
16300
  top: tl.y,
@@ -16282,6 +16303,16 @@ let Canvas$1 = class Canvas extends SelectableCanvas {
16282
16303
  }, {
16283
16304
  includeIntersecting: !this.selectionFullyContained
16284
16305
  });
16306
+
16307
+ // cleanup
16308
+ this._groupSelector = null;
16309
+
16310
+ // the selection key was held while dragging and there is something to add to:
16311
+ // keep the current selection and merge the collected objects into it
16312
+ if (additive && this.getActiveObjects().length) {
16313
+ this.addToActiveSelection(e, collectedObjects);
16314
+ return true;
16315
+ }
16285
16316
  const objects =
16286
16317
  // though this method runs only after mouse move the pointer could do a mouse up on the same position as mouse down
16287
16318
  // should it be handled as is?
@@ -16302,12 +16333,63 @@ let Canvas$1 = class Canvas extends SelectableCanvas {
16302
16333
  canvas: this
16303
16334
  }), e);
16304
16335
  }
16305
-
16306
- // cleanup
16307
- this._groupSelector = null;
16308
16336
  return true;
16309
16337
  }
16310
16338
 
16339
+ /**
16340
+ * Merges the objects collected by a box selection into the current selection.
16341
+ * Only objects belonging to the current selection scope are taken into account:
16342
+ * the first level children of the isolated group, or the canvas root objects
16343
+ * when no group is isolated. Previously selected objects outside of that scope
16344
+ * are removed from the selection, since a selection can't mix objects coming
16345
+ * from different containers.
16346
+ * @private
16347
+ */
16348
+ addToActiveSelection(e, collectedObjects) {
16349
+ const prevActiveObjects = this.getActiveObjects(),
16350
+ scope = this.getSearchTargets(),
16351
+ kept = prevActiveObjects.filter(object => scope.includes(object)),
16352
+ dropped = prevActiveObjects.filter(object => !scope.includes(object)),
16353
+ added = collectedObjects.filter(object => !prevActiveObjects.includes(object) && !object.onSelect({
16354
+ e
16355
+ }));
16356
+ if (!kept.length && !added.length) {
16357
+ // the box didn't add anything and nothing of the current selection
16358
+ // belongs to this scope
16359
+ dropped.length && this.discardActiveObject(e);
16360
+ return;
16361
+ }
16362
+ const activeObject = this._activeObject;
16363
+ if (isActiveSelection(activeObject)) {
16364
+ dropped.length && activeObject.remove(...dropped);
16365
+ added.length && activeObject.multiSelectAdd(...added);
16366
+ if (activeObject.size() === 1) {
16367
+ // deselecting the active selection returns the last remaining object to the canvas
16368
+ this._setActiveObject(activeObject.item(0), e);
16369
+ }
16370
+ this._fireSelectionEvents(prevActiveObjects, e);
16371
+ return;
16372
+ }
16373
+ const objects = kept.concat(added);
16374
+ if (objects.length === 1) {
16375
+ objects[0] !== activeObject && this.setActiveObject(objects[0], e);
16376
+ return;
16377
+ }
16378
+
16379
+ // build the active selection out of the kept and the newly collected objects
16380
+ const klass = classRegistry.getClass('ActiveSelection');
16381
+ const newActiveSelection = new klass([], {
16382
+ /**
16383
+ * it is crucial to pass the canvas ref before calling {@link ActiveSelection#multiSelectAdd}
16384
+ * since it uses {@link FabricObject#isInFrontOf} which relies on the canvas ref
16385
+ */
16386
+ canvas: this
16387
+ });
16388
+ newActiveSelection.multiSelectAdd(...objects);
16389
+ this._setActiveObject(newActiveSelection, e);
16390
+ this._fireSelectionEvents(prevActiveObjects, e);
16391
+ }
16392
+
16311
16393
  /**
16312
16394
  * @override clear {@link textEditingManager}
16313
16395
  */