@anu3ev/fabric-image-editor 0.9.24 → 0.9.26
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/main.js +225 -143
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -3404,72 +3404,24 @@ var Ut = class {
|
|
|
3404
3404
|
}
|
|
3405
3405
|
}
|
|
3406
3406
|
async exportObjectAsImageFile(t = {}) {
|
|
3407
|
-
let { object: n,
|
|
3408
|
-
|
|
3407
|
+
let { object: n, exportAsBase64: r = !1, exportAsBlob: i = !1 } = t, { canvas: a } = this.editor, o = n || a.getActiveObject(), s = this._createObjectExportRequest({
|
|
3408
|
+
object: o ?? void 0,
|
|
3409
|
+
options: t
|
|
3410
|
+
});
|
|
3411
|
+
if (!e._hasExportObject({ request: s })) return this.editor.errorManager.emitError({
|
|
3409
3412
|
origin: "ImageManager",
|
|
3410
3413
|
method: "exportObjectAsImageFile",
|
|
3411
3414
|
code: "NO_OBJECT_SELECTED",
|
|
3412
3415
|
message: "Не выбран объект для экспорта",
|
|
3413
3416
|
data: {
|
|
3414
|
-
contentType:
|
|
3415
|
-
fileName:
|
|
3416
|
-
exportAsBase64:
|
|
3417
|
-
exportAsBlob:
|
|
3417
|
+
contentType: s.contentType,
|
|
3418
|
+
fileName: s.fileName,
|
|
3419
|
+
exportAsBase64: r,
|
|
3420
|
+
exportAsBlob: i
|
|
3418
3421
|
}
|
|
3419
3422
|
}), null;
|
|
3420
|
-
let { contentType: m, format: h = "" } = u, g = i ?? m ?? "image/png", _ = this.getFormatFromContentType(g) || h || "png", v = r ?? `image.${_}`;
|
|
3421
3423
|
try {
|
|
3422
|
-
|
|
3423
|
-
let t = u.toSVG(), n = {
|
|
3424
|
-
object: u,
|
|
3425
|
-
image: e._exportSVGStringAsFile(t, {
|
|
3426
|
-
exportAsBase64: o,
|
|
3427
|
-
exportAsBlob: s,
|
|
3428
|
-
fileName: v
|
|
3429
|
-
}),
|
|
3430
|
-
format: _,
|
|
3431
|
-
contentType: "image/svg+xml",
|
|
3432
|
-
fileName: v.replace(/\.[^/.]+$/, ".svg")
|
|
3433
|
-
};
|
|
3434
|
-
return c.fire("editor:object-exported", n), n;
|
|
3435
|
-
}
|
|
3436
|
-
if (o && u instanceof a) {
|
|
3437
|
-
let e = await createImageBitmap(u.getElement()), t = {
|
|
3438
|
-
object: u,
|
|
3439
|
-
image: await l.post("toDataURL", {
|
|
3440
|
-
contentType: g,
|
|
3441
|
-
quality: 1,
|
|
3442
|
-
bitmap: e
|
|
3443
|
-
}, [e]),
|
|
3444
|
-
format: _,
|
|
3445
|
-
contentType: g,
|
|
3446
|
-
fileName: v
|
|
3447
|
-
};
|
|
3448
|
-
return c.fire("editor:object-exported", t), t;
|
|
3449
|
-
}
|
|
3450
|
-
let t = u.toCanvasElement({ enableRetinaScaling: !1 }), n = await new Promise((e, n) => {
|
|
3451
|
-
t.toBlob((t) => {
|
|
3452
|
-
t ? e(t) : n(/* @__PURE__ */ Error("Failed to create Blob from canvas"));
|
|
3453
|
-
});
|
|
3454
|
-
});
|
|
3455
|
-
if (s) {
|
|
3456
|
-
let e = {
|
|
3457
|
-
object: u,
|
|
3458
|
-
image: n,
|
|
3459
|
-
format: _,
|
|
3460
|
-
contentType: g,
|
|
3461
|
-
fileName: v
|
|
3462
|
-
};
|
|
3463
|
-
return c.fire("editor:object-exported", e), e;
|
|
3464
|
-
}
|
|
3465
|
-
let r = {
|
|
3466
|
-
object: u,
|
|
3467
|
-
image: new File([n], v, { type: g }),
|
|
3468
|
-
format: _,
|
|
3469
|
-
contentType: g,
|
|
3470
|
-
fileName: v
|
|
3471
|
-
};
|
|
3472
|
-
return c.fire("editor:object-exported", r), r;
|
|
3424
|
+
return s.format === "svg" ? this._exportSvgObject({ request: s }) : e._canExportImageElementAsBase64({ request: s }) ? await this._exportImageElementAsBase64({ request: s }) : await this._exportRenderedObject({ request: s });
|
|
3473
3425
|
} catch (e) {
|
|
3474
3426
|
return this.editor.errorManager.emitError({
|
|
3475
3427
|
origin: "ImageManager",
|
|
@@ -3477,14 +3429,120 @@ var Ut = class {
|
|
|
3477
3429
|
code: "IMAGE_EXPORT_FAILED",
|
|
3478
3430
|
message: `Ошибка экспорта объекта: ${e.message}`,
|
|
3479
3431
|
data: {
|
|
3480
|
-
contentType:
|
|
3481
|
-
fileName:
|
|
3482
|
-
exportAsBase64:
|
|
3483
|
-
exportAsBlob:
|
|
3432
|
+
contentType: s.contentType,
|
|
3433
|
+
fileName: s.fileName,
|
|
3434
|
+
exportAsBase64: r,
|
|
3435
|
+
exportAsBlob: i
|
|
3484
3436
|
}
|
|
3485
3437
|
}), null;
|
|
3486
3438
|
}
|
|
3487
3439
|
}
|
|
3440
|
+
_createObjectExportRequest({ object: e, options: t }) {
|
|
3441
|
+
let { fileName: n, contentType: r, exportAsBase64: i = !1, exportAsBlob: a = !1 } = t, { contentType: o, format: s = "" } = e || {}, c = r ?? o ?? "image/png", l = this.getFormatFromContentType(c) || s || "png";
|
|
3442
|
+
return {
|
|
3443
|
+
object: e,
|
|
3444
|
+
contentType: c,
|
|
3445
|
+
format: l,
|
|
3446
|
+
fileName: n ?? `image.${l}`,
|
|
3447
|
+
exportAsBase64: i,
|
|
3448
|
+
exportAsBlob: a
|
|
3449
|
+
};
|
|
3450
|
+
}
|
|
3451
|
+
static _hasExportObject({ request: e }) {
|
|
3452
|
+
return !!e.object;
|
|
3453
|
+
}
|
|
3454
|
+
static _canExportImageElementAsBase64({ request: t }) {
|
|
3455
|
+
return !t.exportAsBase64 || !(t.object instanceof a) ? !1 : !e._hasVisibleImageCrop({ image: t.object });
|
|
3456
|
+
}
|
|
3457
|
+
static _hasVisibleImageCrop({ image: t }) {
|
|
3458
|
+
let n = Number(t.cropX ?? 0), r = Number(t.cropY ?? 0), i = Number(t.width ?? 0), a = Number(t.height ?? 0), o = e._getImageElementSize({ image: t });
|
|
3459
|
+
return !!(n || r || o.width && i && i < o.width || o.height && a && a < o.height);
|
|
3460
|
+
}
|
|
3461
|
+
static _getImageElementSize({ image: e }) {
|
|
3462
|
+
let t = e.getElement();
|
|
3463
|
+
return {
|
|
3464
|
+
width: t.naturalWidth || t.videoWidth || t.width || 0,
|
|
3465
|
+
height: t.naturalHeight || t.videoHeight || t.height || 0
|
|
3466
|
+
};
|
|
3467
|
+
}
|
|
3468
|
+
_exportSvgObject({ request: t }) {
|
|
3469
|
+
let { canvas: n } = this.editor, r = t.object.toSVG(), i = e._exportSVGStringAsFile(r, {
|
|
3470
|
+
exportAsBase64: t.exportAsBase64,
|
|
3471
|
+
exportAsBlob: t.exportAsBlob,
|
|
3472
|
+
fileName: t.fileName
|
|
3473
|
+
}), a = {
|
|
3474
|
+
object: t.object,
|
|
3475
|
+
image: i,
|
|
3476
|
+
format: t.format,
|
|
3477
|
+
contentType: "image/svg+xml",
|
|
3478
|
+
fileName: t.fileName.replace(/\.[^/.]+$/, ".svg")
|
|
3479
|
+
};
|
|
3480
|
+
return n.fire("editor:object-exported", a), a;
|
|
3481
|
+
}
|
|
3482
|
+
async _exportImageElementAsBase64({ request: e }) {
|
|
3483
|
+
let { canvas: t, workerManager: n } = this.editor, r = await createImageBitmap(e.object.getElement()), i = await n.post("toDataURL", {
|
|
3484
|
+
contentType: e.contentType,
|
|
3485
|
+
quality: 1,
|
|
3486
|
+
bitmap: r
|
|
3487
|
+
}, [r]), a = {
|
|
3488
|
+
object: e.object,
|
|
3489
|
+
image: i,
|
|
3490
|
+
format: e.format,
|
|
3491
|
+
contentType: e.contentType,
|
|
3492
|
+
fileName: e.fileName
|
|
3493
|
+
};
|
|
3494
|
+
return t.fire("editor:object-exported", a), a;
|
|
3495
|
+
}
|
|
3496
|
+
async _exportRenderedObject({ request: e }) {
|
|
3497
|
+
let { canvas: t } = this.editor, n = await this._createObjectBlob({ request: e });
|
|
3498
|
+
if (e.exportAsBlob) {
|
|
3499
|
+
let r = {
|
|
3500
|
+
object: e.object,
|
|
3501
|
+
image: n,
|
|
3502
|
+
format: e.format,
|
|
3503
|
+
contentType: e.contentType,
|
|
3504
|
+
fileName: e.fileName
|
|
3505
|
+
};
|
|
3506
|
+
return t.fire("editor:object-exported", r), r;
|
|
3507
|
+
}
|
|
3508
|
+
if (e.exportAsBase64) {
|
|
3509
|
+
let r = await this._convertBlobToDataUrl({
|
|
3510
|
+
blob: n,
|
|
3511
|
+
contentType: e.contentType
|
|
3512
|
+
}), i = {
|
|
3513
|
+
object: e.object,
|
|
3514
|
+
image: r,
|
|
3515
|
+
format: e.format,
|
|
3516
|
+
contentType: e.contentType,
|
|
3517
|
+
fileName: e.fileName
|
|
3518
|
+
};
|
|
3519
|
+
return t.fire("editor:object-exported", i), i;
|
|
3520
|
+
}
|
|
3521
|
+
let r = new File([n], e.fileName, { type: e.contentType }), i = {
|
|
3522
|
+
object: e.object,
|
|
3523
|
+
image: r,
|
|
3524
|
+
format: e.format,
|
|
3525
|
+
contentType: e.contentType,
|
|
3526
|
+
fileName: e.fileName
|
|
3527
|
+
};
|
|
3528
|
+
return t.fire("editor:object-exported", i), i;
|
|
3529
|
+
}
|
|
3530
|
+
async _createObjectBlob({ request: e }) {
|
|
3531
|
+
let t = e.object.toCanvasElement({ enableRetinaScaling: !1 });
|
|
3532
|
+
return new Promise((n, r) => {
|
|
3533
|
+
t.toBlob((e) => {
|
|
3534
|
+
e ? n(e) : r(/* @__PURE__ */ Error("Failed to create Blob from canvas"));
|
|
3535
|
+
}, e.contentType, 1);
|
|
3536
|
+
});
|
|
3537
|
+
}
|
|
3538
|
+
async _convertBlobToDataUrl({ blob: e, contentType: t }) {
|
|
3539
|
+
let { workerManager: n } = this.editor, r = await createImageBitmap(e);
|
|
3540
|
+
return n.post("toDataURL", {
|
|
3541
|
+
contentType: t,
|
|
3542
|
+
quality: 1,
|
|
3543
|
+
bitmap: r
|
|
3544
|
+
}, [r]);
|
|
3545
|
+
}
|
|
3488
3546
|
revokeBlobUrls() {
|
|
3489
3547
|
this._createdBlobUrls.forEach(URL.revokeObjectURL), this._createdBlobUrls = [];
|
|
3490
3548
|
}
|
|
@@ -13545,22 +13603,22 @@ var yo = class {
|
|
|
13545
13603
|
color: d,
|
|
13546
13604
|
lineWidth: 1
|
|
13547
13605
|
});
|
|
13548
|
-
}, ss = .
|
|
13549
|
-
function
|
|
13550
|
-
return
|
|
13606
|
+
}, ss = .1, cs = .5, ls = 1e-6, us = .02, ds = 1e-6, fs = 1;
|
|
13607
|
+
function ps({ target: e, transform: t, rawScaleX: n, rawScaleY: r, effectiveWidth: i, effectiveHeight: a, fallbackScale: o, isUniform: s, preservePlacement: c, snapGuards: l }) {
|
|
13608
|
+
return js({
|
|
13551
13609
|
target: e,
|
|
13552
13610
|
snapGuards: l
|
|
13553
13611
|
}) ? {
|
|
13554
13612
|
scaleX: n,
|
|
13555
13613
|
scaleY: r
|
|
13556
|
-
} :
|
|
13614
|
+
} : hs({
|
|
13557
13615
|
target: e,
|
|
13558
13616
|
effectiveWidth: i,
|
|
13559
13617
|
effectiveHeight: a,
|
|
13560
13618
|
transform: t,
|
|
13561
13619
|
preservePlacement: c,
|
|
13562
13620
|
snapGuards: l
|
|
13563
|
-
}) ||
|
|
13621
|
+
}) || ms({
|
|
13564
13622
|
target: e,
|
|
13565
13623
|
rawScaleX: n,
|
|
13566
13624
|
rawScaleY: r,
|
|
@@ -13568,7 +13626,7 @@ function ms({ target: e, transform: t, rawScaleX: n, rawScaleY: r, effectiveWidt
|
|
|
13568
13626
|
effectiveHeight: a,
|
|
13569
13627
|
preservePlacement: c,
|
|
13570
13628
|
snapGuards: l
|
|
13571
|
-
}) || (
|
|
13629
|
+
}) || (bs({
|
|
13572
13630
|
target: e,
|
|
13573
13631
|
rawScaleX: n,
|
|
13574
13632
|
rawScaleY: r,
|
|
@@ -13582,18 +13640,18 @@ function ms({ target: e, transform: t, rawScaleX: n, rawScaleY: r, effectiveWidt
|
|
|
13582
13640
|
isUniform: s
|
|
13583
13641
|
}),
|
|
13584
13642
|
preservePlacement: c,
|
|
13585
|
-
shouldPreferInsideCandidate:
|
|
13643
|
+
shouldPreferInsideCandidate: As({
|
|
13586
13644
|
target: e,
|
|
13587
13645
|
snapGuards: l
|
|
13588
13646
|
}),
|
|
13589
13647
|
snapGuards: l
|
|
13590
13648
|
}) ?? o);
|
|
13591
13649
|
}
|
|
13592
|
-
function
|
|
13593
|
-
if (!
|
|
13650
|
+
function ms({ target: e, rawScaleX: t, rawScaleY: n, effectiveWidth: r, effectiveHeight: i, preservePlacement: a, snapGuards: o }) {
|
|
13651
|
+
if (!Ms({
|
|
13594
13652
|
target: e,
|
|
13595
13653
|
snapGuards: o
|
|
13596
|
-
}) ||
|
|
13654
|
+
}) || Ns({
|
|
13597
13655
|
target: e,
|
|
13598
13656
|
snapGuards: o
|
|
13599
13657
|
})) return null;
|
|
@@ -13601,13 +13659,13 @@ function hs({ target: e, rawScaleX: t, rawScaleY: n, effectiveWidth: r, effectiv
|
|
|
13601
13659
|
scaleX: t,
|
|
13602
13660
|
scaleY: n
|
|
13603
13661
|
};
|
|
13604
|
-
return !
|
|
13662
|
+
return !gs({
|
|
13605
13663
|
target: e,
|
|
13606
13664
|
candidate: s,
|
|
13607
13665
|
preservePlacement: a,
|
|
13608
|
-
maxDistance:
|
|
13666
|
+
maxDistance: cs,
|
|
13609
13667
|
snapGuards: o
|
|
13610
|
-
}) || !
|
|
13668
|
+
}) || !vs({
|
|
13611
13669
|
target: e,
|
|
13612
13670
|
candidate: s,
|
|
13613
13671
|
effectiveWidth: r,
|
|
@@ -13615,8 +13673,8 @@ function hs({ target: e, rawScaleX: t, rawScaleY: n, effectiveWidth: r, effectiv
|
|
|
13615
13673
|
snapGuards: o
|
|
13616
13674
|
}) ? null : s;
|
|
13617
13675
|
}
|
|
13618
|
-
function
|
|
13619
|
-
if (!
|
|
13676
|
+
function hs({ target: e, transform: t, effectiveWidth: n, effectiveHeight: r, preservePlacement: i, snapGuards: a }) {
|
|
13677
|
+
if (!As({
|
|
13620
13678
|
target: e,
|
|
13621
13679
|
snapGuards: a
|
|
13622
13680
|
})) return null;
|
|
@@ -13625,12 +13683,12 @@ function gs({ target: e, transform: t, effectiveWidth: n, effectiveHeight: r, pr
|
|
|
13625
13683
|
let c = {
|
|
13626
13684
|
scaleX: o,
|
|
13627
13685
|
scaleY: s
|
|
13628
|
-
}, l =
|
|
13686
|
+
}, l = gs({
|
|
13629
13687
|
target: e,
|
|
13630
13688
|
candidate: c,
|
|
13631
13689
|
preservePlacement: i,
|
|
13632
13690
|
snapGuards: a
|
|
13633
|
-
}), u =
|
|
13691
|
+
}), u = _s({
|
|
13634
13692
|
target: e,
|
|
13635
13693
|
candidate: c,
|
|
13636
13694
|
effectiveWidth: n,
|
|
@@ -13639,7 +13697,7 @@ function gs({ target: e, transform: t, effectiveWidth: n, effectiveHeight: r, pr
|
|
|
13639
13697
|
});
|
|
13640
13698
|
return !l || !u ? null : c;
|
|
13641
13699
|
}
|
|
13642
|
-
function
|
|
13700
|
+
function gs({ target: e, candidate: t, preservePlacement: n, maxDistance: r = fs, snapGuards: i }) {
|
|
13643
13701
|
let a = Ws({
|
|
13644
13702
|
target: e,
|
|
13645
13703
|
candidate: t,
|
|
@@ -13652,63 +13710,91 @@ function _s({ target: e, candidate: t, preservePlacement: n, maxDistance: r = ps
|
|
|
13652
13710
|
}) > r) return !1;
|
|
13653
13711
|
return !0;
|
|
13654
13712
|
}
|
|
13655
|
-
function
|
|
13656
|
-
for (let a of i) if (!
|
|
13713
|
+
function _s({ target: e, candidate: t, effectiveWidth: n, effectiveHeight: r, snapGuards: i }) {
|
|
13714
|
+
for (let a of i) if (!Es({
|
|
13657
13715
|
target: e,
|
|
13658
13716
|
displaySize: a.type === "vertical" ? Math.abs(t.scaleX) * n : Math.abs(t.scaleY) * r,
|
|
13659
13717
|
snapGuard: a
|
|
13660
13718
|
})) return !1;
|
|
13661
13719
|
return !0;
|
|
13662
13720
|
}
|
|
13663
|
-
function
|
|
13664
|
-
for (let a of i) if (!
|
|
13721
|
+
function vs({ target: e, candidate: t, effectiveWidth: n, effectiveHeight: r, snapGuards: i }) {
|
|
13722
|
+
for (let a of i) if (!ys({
|
|
13665
13723
|
target: e,
|
|
13666
13724
|
displaySize: a.type === "vertical" ? Math.abs(t.scaleX) * n : Math.abs(t.scaleY) * r,
|
|
13667
13725
|
snapGuard: a
|
|
13668
13726
|
})) return !1;
|
|
13669
13727
|
return !0;
|
|
13670
13728
|
}
|
|
13671
|
-
function
|
|
13672
|
-
let r =
|
|
13729
|
+
function ys({ target: e, displaySize: t, snapGuard: n }) {
|
|
13730
|
+
let r = Os({
|
|
13673
13731
|
target: e,
|
|
13674
13732
|
snapGuard: n
|
|
13675
13733
|
});
|
|
13676
13734
|
if (r === null) return !1;
|
|
13677
|
-
let i = Math.round(r +
|
|
13735
|
+
let i = Math.round(r + ls);
|
|
13678
13736
|
return Math.round(t) <= i;
|
|
13679
13737
|
}
|
|
13680
|
-
function
|
|
13681
|
-
|
|
13682
|
-
|
|
13683
|
-
|
|
13684
|
-
|
|
13685
|
-
|
|
13686
|
-
|
|
13687
|
-
|
|
13688
|
-
|
|
13689
|
-
|
|
13690
|
-
|
|
13691
|
-
|
|
13692
|
-
|
|
13693
|
-
|
|
13694
|
-
}
|
|
13695
|
-
return l && Ss({
|
|
13738
|
+
function bs({ target: e, rawScaleX: t, rawScaleY: n, effectiveWidth: r, effectiveHeight: i, candidates: a, preservePlacement: o, shouldPreferInsideCandidate: s, snapGuards: c }) {
|
|
13739
|
+
if (!s) return xs({
|
|
13740
|
+
target: e,
|
|
13741
|
+
candidates: a,
|
|
13742
|
+
preservePlacement: o,
|
|
13743
|
+
snapGuards: c
|
|
13744
|
+
});
|
|
13745
|
+
let { insideCandidate: l, onGuideCandidate: u } = Ss({
|
|
13746
|
+
target: e,
|
|
13747
|
+
candidates: a,
|
|
13748
|
+
preservePlacement: o,
|
|
13749
|
+
snapGuards: c
|
|
13750
|
+
});
|
|
13751
|
+
return u && Cs({
|
|
13696
13752
|
target: e,
|
|
13697
|
-
candidate:
|
|
13753
|
+
candidate: u,
|
|
13698
13754
|
rawScaleX: t,
|
|
13699
13755
|
rawScaleY: n,
|
|
13700
13756
|
effectiveWidth: r,
|
|
13701
13757
|
effectiveHeight: i,
|
|
13702
13758
|
snapGuards: c
|
|
13703
|
-
}) ?
|
|
13759
|
+
}) ? u : l || u || null;
|
|
13704
13760
|
}
|
|
13705
|
-
function
|
|
13761
|
+
function xs({ target: e, candidates: t, preservePlacement: n, snapGuards: r }) {
|
|
13762
|
+
let i = null;
|
|
13763
|
+
for (let a of t) {
|
|
13764
|
+
let t = Us({
|
|
13765
|
+
target: e,
|
|
13766
|
+
candidate: a,
|
|
13767
|
+
preservePlacement: n,
|
|
13768
|
+
snapGuards: r
|
|
13769
|
+
});
|
|
13770
|
+
if (t.state === "on-guide") return a;
|
|
13771
|
+
t.state === "inside" && !i && (i = a);
|
|
13772
|
+
}
|
|
13773
|
+
return i;
|
|
13774
|
+
}
|
|
13775
|
+
function Ss({ target: e, candidates: t, preservePlacement: n, snapGuards: r }) {
|
|
13776
|
+
let i = null, a = null, o = Infinity;
|
|
13777
|
+
for (let s of t) {
|
|
13778
|
+
let t = Us({
|
|
13779
|
+
target: e,
|
|
13780
|
+
candidate: s,
|
|
13781
|
+
preservePlacement: n,
|
|
13782
|
+
snapGuards: r
|
|
13783
|
+
});
|
|
13784
|
+
t.state === "on-guide" && !i && (i = s), t.state === "inside" && t.distance < o && (a = s, o = t.distance);
|
|
13785
|
+
}
|
|
13786
|
+
return {
|
|
13787
|
+
insideCandidate: a,
|
|
13788
|
+
onGuideCandidate: i
|
|
13789
|
+
};
|
|
13790
|
+
}
|
|
13791
|
+
function Cs({ target: e, candidate: t, rawScaleX: n, rawScaleY: r, effectiveWidth: i, effectiveHeight: a, snapGuards: o }) {
|
|
13706
13792
|
for (let s of o) {
|
|
13707
13793
|
let o = s.type === "vertical" ? Math.abs(t.scaleX) * i : Math.abs(t.scaleY) * a, c = s.type === "vertical" ? Math.abs(n) * i : Math.abs(r) * a;
|
|
13708
|
-
if (!
|
|
13794
|
+
if (!ws({ displaySize: o }) || !Ts({
|
|
13709
13795
|
displaySize: o,
|
|
13710
13796
|
rawDisplaySize: c
|
|
13711
|
-
}) || !
|
|
13797
|
+
}) || !Es({
|
|
13712
13798
|
target: e,
|
|
13713
13799
|
displaySize: o,
|
|
13714
13800
|
snapGuard: s
|
|
@@ -13716,60 +13802,60 @@ function Ss({ target: e, candidate: t, rawScaleX: n, rawScaleY: r, effectiveWidt
|
|
|
13716
13802
|
}
|
|
13717
13803
|
return !0;
|
|
13718
13804
|
}
|
|
13719
|
-
function
|
|
13720
|
-
return Math.abs(e - Math.round(e)) <=
|
|
13805
|
+
function ws({ displaySize: e }) {
|
|
13806
|
+
return Math.abs(e - Math.round(e)) <= ls;
|
|
13721
13807
|
}
|
|
13722
|
-
function
|
|
13723
|
-
return Math.abs(e - t) <=
|
|
13808
|
+
function Ts({ displaySize: e, rawDisplaySize: t }) {
|
|
13809
|
+
return Math.abs(e - t) <= us;
|
|
13724
13810
|
}
|
|
13725
|
-
function
|
|
13726
|
-
let r =
|
|
13811
|
+
function Es({ target: e, displaySize: t, snapGuard: n }) {
|
|
13812
|
+
let r = Ds({
|
|
13727
13813
|
target: e,
|
|
13728
13814
|
snapGuard: n
|
|
13729
13815
|
});
|
|
13730
13816
|
return r === null ? !1 : Math.round(t) <= r;
|
|
13731
13817
|
}
|
|
13732
|
-
function
|
|
13733
|
-
let n =
|
|
13818
|
+
function Ds({ target: e, snapGuard: t }) {
|
|
13819
|
+
let n = Os({
|
|
13734
13820
|
target: e,
|
|
13735
13821
|
snapGuard: t
|
|
13736
13822
|
});
|
|
13737
|
-
return n === null ? null : Math.round(n +
|
|
13823
|
+
return n === null ? null : Math.round(n + ls);
|
|
13738
13824
|
}
|
|
13739
|
-
function
|
|
13825
|
+
function Os({ target: e, snapGuard: t }) {
|
|
13740
13826
|
let n = e, { cropSource: r } = n;
|
|
13741
13827
|
if (!r) return null;
|
|
13742
13828
|
let i = cn({ object: r });
|
|
13743
13829
|
if (!i) return null;
|
|
13744
13830
|
let a = t.type === "vertical" ? Math.abs(n.cropSourceScaleX ?? 1) : Math.abs(n.cropSourceScaleY ?? 1);
|
|
13745
13831
|
if (!Number.isFinite(a) || a <= 0) return null;
|
|
13746
|
-
let o =
|
|
13832
|
+
let o = ks({
|
|
13747
13833
|
sourceBounds: i,
|
|
13748
13834
|
snapGuard: t
|
|
13749
13835
|
});
|
|
13750
13836
|
return !Number.isFinite(o) || o <= 0 ? null : o / a;
|
|
13751
13837
|
}
|
|
13752
|
-
function
|
|
13838
|
+
function ks({ sourceBounds: e, snapGuard: t }) {
|
|
13753
13839
|
let { edge: n, position: r } = t;
|
|
13754
13840
|
return n === "left" ? e.right - r : n === "right" ? r - e.left : n === "top" ? e.bottom - r : r - e.top;
|
|
13755
13841
|
}
|
|
13756
|
-
function
|
|
13757
|
-
return
|
|
13842
|
+
function As({ target: e, snapGuards: t }) {
|
|
13843
|
+
return Ms({
|
|
13758
13844
|
target: e,
|
|
13759
13845
|
snapGuards: t
|
|
13760
|
-
}) ? !
|
|
13846
|
+
}) ? !Ns({
|
|
13761
13847
|
target: e,
|
|
13762
13848
|
snapGuards: t
|
|
13763
13849
|
}) : !1;
|
|
13764
13850
|
}
|
|
13765
|
-
function
|
|
13766
|
-
if (
|
|
13851
|
+
function js({ target: e, snapGuards: t }) {
|
|
13852
|
+
if (Ms({
|
|
13767
13853
|
target: e,
|
|
13768
13854
|
snapGuards: t
|
|
13769
13855
|
})) return !1;
|
|
13770
13856
|
let n = G({ object: e });
|
|
13771
13857
|
if (!n) return !1;
|
|
13772
|
-
for (let e of t) if (!
|
|
13858
|
+
for (let e of t) if (!Js({
|
|
13773
13859
|
bounds: n,
|
|
13774
13860
|
snapGuard: e
|
|
13775
13861
|
}) || !Ls({
|
|
@@ -13778,36 +13864,32 @@ function As({ target: e, snapGuards: t }) {
|
|
|
13778
13864
|
})) return !1;
|
|
13779
13865
|
return !0;
|
|
13780
13866
|
}
|
|
13781
|
-
function
|
|
13867
|
+
function Ms({ target: e, snapGuards: t }) {
|
|
13782
13868
|
if (typeof e.getObjectDisplaySize != "function") return !1;
|
|
13783
|
-
let n = e, r = t.some((e) => e.type === "vertical" && !
|
|
13869
|
+
let n = e, r = t.some((e) => e.type === "vertical" && !Is({ scale: n.cropSourceScaleX })), i = t.some((e) => e.type === "horizontal" && !Is({ scale: n.cropSourceScaleY }));
|
|
13784
13870
|
return r || i;
|
|
13785
13871
|
}
|
|
13786
|
-
function
|
|
13872
|
+
function Ns({ target: e, snapGuards: t }) {
|
|
13787
13873
|
let { cropSource: n } = e;
|
|
13788
13874
|
if (!n) return !1;
|
|
13789
13875
|
let r = G({ object: n });
|
|
13790
|
-
return r ? t.some((e) =>
|
|
13876
|
+
return r ? t.some((e) => Ps({
|
|
13791
13877
|
snapGuard: e,
|
|
13792
13878
|
sourceBounds: r
|
|
13793
13879
|
})) : !1;
|
|
13794
13880
|
}
|
|
13795
|
-
function
|
|
13881
|
+
function Ps({ snapGuard: e, sourceBounds: t }) {
|
|
13796
13882
|
let { edge: n, position: r } = e, i = t.bottom;
|
|
13797
|
-
return n === "left" && (i = t.left), n === "right" && (i = t.right), n === "top" && (i = t.top),
|
|
13883
|
+
return n === "left" && (i = t.left), n === "right" && (i = t.right), n === "top" && (i = t.top), Fs({
|
|
13798
13884
|
position: r,
|
|
13799
13885
|
boundary: i
|
|
13800
13886
|
});
|
|
13801
13887
|
}
|
|
13802
|
-
function
|
|
13803
|
-
return Math.abs(e - t) <=
|
|
13804
|
-
}
|
|
13805
|
-
function Fs({ scale: e }) {
|
|
13806
|
-
return Math.abs(Math.abs(e ?? 1) - 1) <= fs;
|
|
13888
|
+
function Fs({ position: e, boundary: t }) {
|
|
13889
|
+
return Math.abs(e - t) <= ss;
|
|
13807
13890
|
}
|
|
13808
|
-
function Is({
|
|
13809
|
-
|
|
13810
|
-
return Math.abs(e.position - t) <= ss;
|
|
13891
|
+
function Is({ scale: e }) {
|
|
13892
|
+
return Math.abs(Math.abs(e ?? 1) - 1) <= ds;
|
|
13811
13893
|
}
|
|
13812
13894
|
function Ls({ bounds: e, snapGuard: t }) {
|
|
13813
13895
|
let n = t.type === "vertical" ? e.right - e.left : e.bottom - e.top;
|
|
@@ -13927,11 +14009,11 @@ function Ks({ bounds: e, snapGuard: t }) {
|
|
|
13927
14009
|
}
|
|
13928
14010
|
function qs({ bounds: e, snapGuard: t }) {
|
|
13929
14011
|
let { edge: n, position: r } = t;
|
|
13930
|
-
return n === "left" ? e.left >= r -
|
|
14012
|
+
return n === "left" ? e.left >= r - ss : n === "right" ? e.right <= r + ss : n === "top" ? e.top >= r - ss : e.bottom <= r + ss;
|
|
13931
14013
|
}
|
|
13932
14014
|
function Js({ bounds: e, snapGuard: t }) {
|
|
13933
14015
|
let { edge: n, position: r } = t;
|
|
13934
|
-
return n === "left" ? Math.abs(e.left - r) <=
|
|
14016
|
+
return n === "left" ? Math.abs(e.left - r) <= ss : n === "right" ? Math.abs(e.right - r) <= ss : n === "top" ? Math.abs(e.top - r) <= ss : Math.abs(e.bottom - r) <= ss;
|
|
13935
14017
|
}
|
|
13936
14018
|
//#endregion
|
|
13937
14019
|
//#region src/editor/snapping-manager/pixel-grid.ts
|
|
@@ -14053,7 +14135,7 @@ function oc({ target: e, transform: t, rawScaleX: n, rawScaleY: r, effectiveWidt
|
|
|
14053
14135
|
effectiveWidth: i,
|
|
14054
14136
|
effectiveHeight: a
|
|
14055
14137
|
});
|
|
14056
|
-
return s.length === 0 ? c :
|
|
14138
|
+
return s.length === 0 ? c : ps({
|
|
14057
14139
|
target: e,
|
|
14058
14140
|
transform: t,
|
|
14059
14141
|
rawScaleX: n,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anu3ev/fabric-image-editor",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.26",
|
|
4
4
|
"description": "TypeScript image editor library built on FabricJS, allowing you to create instances with an integrated montage area and providing an API to modify and manage state.",
|
|
5
5
|
"module": "dist/main.js",
|
|
6
6
|
"files": [
|