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