fabric-vectr 6.7.14 → 6.7.16

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 (39) hide show
  1. package/dist/index.js +90 -12
  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 +90 -12
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/index.node.cjs +90 -12
  10. package/dist/index.node.cjs.map +1 -1
  11. package/dist/index.node.mjs +90 -12
  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/shapes/Textbox.d.ts.map +1 -1
  26. package/dist/src/shapes/Textbox.min.mjs +1 -1
  27. package/dist/src/shapes/Textbox.min.mjs.map +1 -1
  28. package/dist/src/shapes/Textbox.mjs +4 -1
  29. package/dist/src/shapes/Textbox.mjs.map +1 -1
  30. package/dist-extensions/src/canvas/Canvas.d.ts +10 -0
  31. package/dist-extensions/src/canvas/Canvas.d.ts.map +1 -1
  32. package/dist-extensions/src/canvas/SelectableCanvas.d.ts +6 -0
  33. package/dist-extensions/src/canvas/SelectableCanvas.d.ts.map +1 -1
  34. package/dist-extensions/src/shapes/Textbox.d.ts.map +1 -1
  35. package/package.json +33 -33
  36. package/src/canvas/Canvas.ts +89 -8
  37. package/src/canvas/SelectableCanvas.ts +6 -0
  38. package/src/canvas/__tests__/additiveSelection.test.ts +118 -0
  39. package/src/shapes/Textbox.ts +4 -1
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.14";
363
+ var version = "6.7.16";
364
364
 
365
365
  // use this syntax so babel plugin see this import here
366
366
  const VERSION = version;
@@ -15814,11 +15814,16 @@ class Canvas extends SelectableCanvas {
15814
15814
  shouldRender = true;
15815
15815
  } else if (this._shouldClearSelection(e, target)) {
15816
15816
  const objs = this.getActiveObjects();
15817
- this.discardActiveObject(e);
15818
- // 多选取消,重置Coords, 防止无法再次选中
15819
- objs.forEach(obj => obj.setCoords());
15820
- if (!target && this.switchIsolateObject(e)) {
15821
- return;
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
+ }
15822
15827
  }
15823
15828
  }
15824
15829
  // we start a group selector rectangle if
@@ -15833,7 +15838,12 @@ class Canvas extends SelectableCanvas {
15833
15838
  x: p.x,
15834
15839
  y: p.y,
15835
15840
  deltaY: 0,
15836
- 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
+ } : {})
15837
15847
  };
15838
15848
  }
15839
15849
 
@@ -16216,13 +16226,17 @@ class Canvas extends SelectableCanvas {
16216
16226
  x,
16217
16227
  y,
16218
16228
  deltaX,
16219
- deltaY
16229
+ deltaY,
16230
+ additive
16220
16231
  } = this._groupSelector,
16221
16232
  point1 = new Point(x, y),
16222
16233
  point2 = point1.add(new Point(deltaX, deltaY)),
16223
16234
  tl = point1.min(point2),
16224
16235
  br = point1.max(point2),
16225
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
16226
16240
  const collectedObjects = this.collectObjects(this.getSearchTargets(), {
16227
16241
  left: tl.x,
16228
16242
  top: tl.y,
@@ -16231,6 +16245,16 @@ class Canvas extends SelectableCanvas {
16231
16245
  }, {
16232
16246
  includeIntersecting: !this.selectionFullyContained
16233
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
+ }
16234
16258
  const objects =
16235
16259
  // though this method runs only after mouse move the pointer could do a mouse up on the same position as mouse down
16236
16260
  // should it be handled as is?
@@ -16251,12 +16275,63 @@ class Canvas extends SelectableCanvas {
16251
16275
  canvas: this
16252
16276
  }), e);
16253
16277
  }
16254
-
16255
- // cleanup
16256
- this._groupSelector = null;
16257
16278
  return true;
16258
16279
  }
16259
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
+
16260
16335
  /**
16261
16336
  * @override clear {@link textEditingManager}
16262
16337
  */
@@ -24458,7 +24533,10 @@ class Textbox extends IText {
24458
24533
  }
24459
24534
 
24460
24535
  // 处理文字的水平偏移
24461
- spanOffX = options.left - (minSpanX || 0);
24536
+ // 只有当 tspan 显式携带 x/dx 位置(minSpanX 非空)时,tspan 的 x 才是相对
24537
+ // <text> 原点的偏移量,需要换算成绝对坐标;否则 <text> 上的 x 本身就是绝对坐标,
24538
+ // 直接使用,避免把整个 left 减掉导致 X 轴整体偏移(GPT 等标准 SVG 常见)。
24539
+ spanOffX = minSpanX != null ? options.left - minSpanX : 0;
24462
24540
 
24463
24541
  // textAlign保持和parsedAnchor一致
24464
24542
  options.textAlign = parsedAnchor;