@nasser-sw/fabric 7.0.1-beta4 → 7.0.1-beta6
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 +40 -31
- 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 +40 -31
- package/dist/index.mjs.map +1 -1
- package/dist/index.node.cjs +40 -31
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +40 -31
- 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/shapes/Line.d.ts +1 -0
- package/dist/src/shapes/Line.d.ts.map +1 -1
- package/dist/src/shapes/Line.min.mjs +1 -1
- package/dist/src/shapes/Line.min.mjs.map +1 -1
- package/dist/src/shapes/Line.mjs +39 -30
- package/dist/src/shapes/Line.mjs.map +1 -1
- package/dist-extensions/src/shapes/Line.d.ts +1 -0
- package/dist-extensions/src/shapes/Line.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/shapes/Line.ts +34 -18
package/src/shapes/Line.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { CENTER, LEFT, TOP } from '../constants';
|
|
|
12
12
|
import type { CSSRules } from '../parser/typedefs';
|
|
13
13
|
import { Control } from '../controls/Control';
|
|
14
14
|
import type { TPointerEvent, Transform } from '../EventTypeDefs';
|
|
15
|
+
import { multiplyTransformMatrices } from '../util/misc/matrix';
|
|
15
16
|
|
|
16
17
|
const coordProps = ['x1', 'x2', 'y1', 'y2'] as const;
|
|
17
18
|
|
|
@@ -99,13 +100,11 @@ export class Line<
|
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
_p1PositionHandler() {
|
|
102
|
-
|
|
103
|
-
return new Point(this.x1, this.y1).transform(vpt);
|
|
103
|
+
return new Point(this.x1, this.y1).transform(this.getViewportTransform());
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
_p2PositionHandler() {
|
|
107
|
-
|
|
108
|
-
return new Point(this.x2, this.y2).transform(vpt);
|
|
107
|
+
return new Point(this.x2, this.y2).transform(this.getViewportTransform());
|
|
109
108
|
}
|
|
110
109
|
|
|
111
110
|
_renderEndpointControl(
|
|
@@ -176,17 +175,17 @@ export class Line<
|
|
|
176
175
|
|
|
177
176
|
setCoords() {
|
|
178
177
|
if (this._useEndpointCoords) {
|
|
179
|
-
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
|
|
178
|
+
// Set the object's center to the geometric center of the line
|
|
179
|
+
const center = this._findCenterFromElement();
|
|
180
|
+
this.left = center.x;
|
|
181
|
+
this.top = center.y;
|
|
182
|
+
|
|
183
|
+
// Set width and height for hit detection and bounding box
|
|
183
184
|
const effectiveStrokeWidth =
|
|
184
185
|
this.hitStrokeWidth === 'auto'
|
|
185
186
|
? this.strokeWidth
|
|
186
187
|
: this.hitStrokeWidth;
|
|
187
188
|
const hitPadding = Math.max(effectiveStrokeWidth / 2 + 5, 10);
|
|
188
|
-
this.left = minX - hitPadding + (maxX - minX + hitPadding * 2) / 2;
|
|
189
|
-
this.top = minY - hitPadding + (maxY - minY + hitPadding * 2) / 2;
|
|
190
189
|
this.width = Math.abs(this.x2 - this.x1) + hitPadding * 2;
|
|
191
190
|
this.height = Math.abs(this.y2 - this.y1) + hitPadding * 2;
|
|
192
191
|
}
|
|
@@ -385,8 +384,6 @@ export class Line<
|
|
|
385
384
|
_renderDirectly(ctx: CanvasRenderingContext2D) {
|
|
386
385
|
if (!this.visible) return;
|
|
387
386
|
ctx.save();
|
|
388
|
-
const vpt = this.canvas?.viewportTransform || [1, 0, 0, 1, 0, 0];
|
|
389
|
-
ctx.transform(vpt[0], vpt[1], vpt[2], vpt[3], vpt[4], vpt[5]);
|
|
390
387
|
ctx.globalAlpha = this.opacity;
|
|
391
388
|
ctx.strokeStyle = this.stroke?.toString() || '#000';
|
|
392
389
|
ctx.lineWidth = this.strokeWidth;
|
|
@@ -459,12 +456,31 @@ export class Line<
|
|
|
459
456
|
}
|
|
460
457
|
|
|
461
458
|
_toSVG() {
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
459
|
+
if (this._useEndpointCoords) {
|
|
460
|
+
// Use absolute coordinates to bypass all Fabric.js transforms
|
|
461
|
+
return [
|
|
462
|
+
`<line stroke="${this.stroke}" stroke-width="${this.strokeWidth}" stroke-linecap="${this.strokeLineCap}" `,
|
|
463
|
+
`x1="${this.x1}" y1="${this.y1}" x2="${this.x2}" y2="${this.y2}" />\n`,
|
|
464
|
+
];
|
|
465
|
+
} else {
|
|
466
|
+
// Use standard calcLinePoints for legacy mode
|
|
467
|
+
const { x1, x2, y1, y2 } = this.calcLinePoints();
|
|
468
|
+
return [
|
|
469
|
+
'<line ',
|
|
470
|
+
'COMMON_PARTS',
|
|
471
|
+
`x1="${x1}" y1="${y1}" x2="${x2}" y2="${y2}" />\n`,
|
|
472
|
+
];
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
toSVG(reviver?: (markup: string) => string): string {
|
|
477
|
+
if (this._useEndpointCoords) {
|
|
478
|
+
// Override toSVG to prevent Fabric.js from adding transform wrapper
|
|
479
|
+
const markup = this._toSVG().join('');
|
|
480
|
+
return reviver ? reviver(markup) : markup;
|
|
481
|
+
}
|
|
482
|
+
// Use default behavior for legacy mode
|
|
483
|
+
return super.toSVG(reviver);
|
|
468
484
|
}
|
|
469
485
|
|
|
470
486
|
static ATTRIBUTE_NAMES = SHARED_ATTRIBUTES.concat(coordProps);
|