@anu3ev/fabric-image-editor 0.1.49 → 0.1.51
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/assets/worker-Cmho-Hr0.js +2 -0
- package/dist/main.js +204 -196
- package/package.json +3 -1
- package/dist/worker.ts +0 -78
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var u=(g,o,r)=>new Promise((i,e)=>{var d=t=>{try{n(r.next(t))}catch(c){e(c)}},l=t=>{try{n(r.throw(t))}catch(c){e(c)}},n=t=>t.done?i(t.value):Promise.resolve(t.value).then(d,l);n((r=r.apply(g,o)).next())});(function(){"use strict";self.onmessage=g=>u(this,null,function*(){const{action:o,payload:r,requestId:i}=g.data;try{switch(o){case"resizeImage":{const{dataURL:e,maxWidth:d,maxHeight:l,minWidth:n,minHeight:t,sizeType:c}=r,h=yield createImageBitmap(yield(yield fetch(e)).blob());let{width:a,height:s}=h,w=Math.min(d/a,l/s);c==="min"&&(w=Math.max(n/a,t/s)),a=Math.floor(a*w),s=Math.floor(s*w);const m=new OffscreenCanvas(a,s),f=m.getContext("2d");if(!f)throw new Error("Failed to get 2D context from OffscreenCanvas");f.drawImage(h,0,0,a,s);const b=yield m.convertToBlob();self.postMessage({requestId:i,action:o,success:!0,data:b});break}case"toDataURL":{const{bitmap:e,format:d,quality:l,returnBlob:n}=r,{width:t,height:c}=e,h=new OffscreenCanvas(e.width,e.height),a=h.getContext("2d");if(!a)throw new Error("Failed to get 2D context from OffscreenCanvas");a.drawImage(e,0,0,t,c);const s=yield h.convertToBlob({type:d,quality:l});if(n){self.postMessage({requestId:i,action:o,success:!0,data:s});break}const w=yield new Promise(m=>{const f=new FileReader;f.onload=()=>m(f.result),f.readAsDataURL(s)});self.postMessage({requestId:i,action:o,success:!0,data:w});break}default:throw new Error(`Unknown action ${o}`)}}catch(e){self.postMessage({requestId:i,action:o,success:!1,error:e.message})}})})();
|
|
2
|
+
//# sourceMappingURL=worker-Cmho-Hr0.js.map
|
package/dist/main.js
CHANGED
|
@@ -2,40 +2,40 @@ var je = Object.defineProperty, fe = Object.defineProperties;
|
|
|
2
2
|
var be = Object.getOwnPropertyDescriptors;
|
|
3
3
|
var H = Object.getOwnPropertySymbols;
|
|
4
4
|
var ce = Object.prototype.hasOwnProperty, de = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var re = (
|
|
5
|
+
var re = (r, e, t) => e in r ? je(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, f = (r, e) => {
|
|
6
6
|
for (var t in e || (e = {}))
|
|
7
|
-
ce.call(e, t) && re(
|
|
7
|
+
ce.call(e, t) && re(r, t, e[t]);
|
|
8
8
|
if (H)
|
|
9
9
|
for (var t of H(e))
|
|
10
|
-
de.call(e, t) && re(
|
|
11
|
-
return
|
|
12
|
-
}, le = (
|
|
13
|
-
var Y = (
|
|
10
|
+
de.call(e, t) && re(r, t, e[t]);
|
|
11
|
+
return r;
|
|
12
|
+
}, le = (r, e) => fe(r, be(e));
|
|
13
|
+
var Y = (r, e) => {
|
|
14
14
|
var t = {};
|
|
15
|
-
for (var s in
|
|
16
|
-
ce.call(
|
|
17
|
-
if (
|
|
18
|
-
for (var s of H(
|
|
19
|
-
e.indexOf(s) < 0 && de.call(
|
|
15
|
+
for (var s in r)
|
|
16
|
+
ce.call(r, s) && e.indexOf(s) < 0 && (t[s] = r[s]);
|
|
17
|
+
if (r != null && H)
|
|
18
|
+
for (var s of H(r))
|
|
19
|
+
e.indexOf(s) < 0 && de.call(r, s) && (t[s] = r[s]);
|
|
20
20
|
return t;
|
|
21
21
|
};
|
|
22
|
-
var I = (
|
|
22
|
+
var I = (r, e, t) => new Promise((s, i) => {
|
|
23
23
|
var n = (d) => {
|
|
24
24
|
try {
|
|
25
25
|
o(t.next(d));
|
|
26
|
-
} catch (
|
|
27
|
-
i(
|
|
26
|
+
} catch (c) {
|
|
27
|
+
i(c);
|
|
28
28
|
}
|
|
29
29
|
}, a = (d) => {
|
|
30
30
|
try {
|
|
31
31
|
o(t.throw(d));
|
|
32
|
-
} catch (
|
|
33
|
-
i(
|
|
32
|
+
} catch (c) {
|
|
33
|
+
i(c);
|
|
34
34
|
}
|
|
35
35
|
}, o = (d) => d.done ? s(d.value) : Promise.resolve(d.value).then(n, a);
|
|
36
|
-
o((t = t.apply(
|
|
36
|
+
o((t = t.apply(r, e)).next());
|
|
37
37
|
});
|
|
38
|
-
import { ActiveSelection as v, util as R, controlsUtils as
|
|
38
|
+
import { ActiveSelection as v, util as R, controlsUtils as ye, InteractiveFabricObject as pe, loadSVGFromURL as Ie, FabricImage as Z, Point as _, Rect as ve, Circle as Ae, Triangle as Se, Group as X, Canvas as Ce, Pattern as Ne } from "fabric";
|
|
39
39
|
import { create as De } from "jsondiffpatch";
|
|
40
40
|
import Le from "diff-match-patch";
|
|
41
41
|
var we = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict", D = function() {
|
|
@@ -76,10 +76,10 @@ class z {
|
|
|
76
76
|
pasteImageFromClipboard: a,
|
|
77
77
|
undoRedoByHotKeys: o,
|
|
78
78
|
selectAllByHotkey: d,
|
|
79
|
-
deleteObjectsByHotkey:
|
|
79
|
+
deleteObjectsByHotkey: c,
|
|
80
80
|
resetObjectFitByDoubleClick: l
|
|
81
81
|
} = this.options;
|
|
82
|
-
t && (this.canvas.on("mouse:down", this.handleCanvasDragStartBound), this.canvas.on("mouse:move", this.handleCanvasDraggingBound), this.canvas.on("mouse:up", this.handleCanvasDragEndBound), document.addEventListener("keydown", this.handleSpaceKeyDownBound, { capture: !0 }), document.addEventListener("keyup", this.handleSpaceKeyUpBound, { capture: !0 })), s && this.canvas.on("mouse:wheel", this.handleMouseWheelZoomBound), i && (this.canvas.on("selection:created", this.handleBringToFrontBound), this.canvas.on("selection:updated", this.handleBringToFrontBound)), l && this.canvas.on("mouse:dblclick", this.handleResetObjectFitBound), e && window.addEventListener("resize", this.handleContainerResizeBound, { capture: !0 }), n && document.addEventListener("keydown", this.handleCopyEventBound, { capture: !0 }), a && document.addEventListener("paste", this.handlePasteEventBound, { capture: !0 }), o && (document.addEventListener("keydown", this.handleUndoRedoEventBound, { capture: !0 }), document.addEventListener("keyup", this.handleUndoRedoKeyUpBound, { capture: !0 })), d && document.addEventListener("keydown", this.handleSelectAllEventBound, { capture: !0 }),
|
|
82
|
+
t && (this.canvas.on("mouse:down", this.handleCanvasDragStartBound), this.canvas.on("mouse:move", this.handleCanvasDraggingBound), this.canvas.on("mouse:up", this.handleCanvasDragEndBound), document.addEventListener("keydown", this.handleSpaceKeyDownBound, { capture: !0 }), document.addEventListener("keyup", this.handleSpaceKeyUpBound, { capture: !0 })), s && this.canvas.on("mouse:wheel", this.handleMouseWheelZoomBound), i && (this.canvas.on("selection:created", this.handleBringToFrontBound), this.canvas.on("selection:updated", this.handleBringToFrontBound)), l && this.canvas.on("mouse:dblclick", this.handleResetObjectFitBound), e && window.addEventListener("resize", this.handleContainerResizeBound, { capture: !0 }), n && document.addEventListener("keydown", this.handleCopyEventBound, { capture: !0 }), a && document.addEventListener("paste", this.handlePasteEventBound, { capture: !0 }), o && (document.addEventListener("keydown", this.handleUndoRedoEventBound, { capture: !0 }), document.addEventListener("keyup", this.handleUndoRedoKeyUpBound, { capture: !0 })), d && document.addEventListener("keydown", this.handleSelectAllEventBound, { capture: !0 }), c && document.addEventListener("keydown", this.handleDeleteObjectsEventBound, { capture: !0 }), this.canvas.on("object:modified", this.handleObjectModifiedHistoryBound), this.canvas.on("object:rotating", this.handleObjectRotatingHistoryBound), this.canvas.on("object:added", this.handleObjectAddedHistoryBound), this.canvas.on("object:removed", this.handleObjectRemovedHistoryBound), this.canvas.on("object:added", this.handleOverlayUpdateBound), this.canvas.on("selection:created", this.handleOverlayUpdateBound), this.canvas.on("selection:created", this.handleLockedSelectionBound), this.canvas.on("selection:updated", this.handleLockedSelectionBound);
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
85
85
|
* При массовом выделении объектов удаляем из него залоченные.
|
|
@@ -324,13 +324,21 @@ class Ee {
|
|
|
324
324
|
return this.loaders[e] ? (this.cache.has(e) || this.cache.set(e, this.loaders[e]()), this.cache.get(e)) : Promise.reject(new Error(`Unknown module "${e}"`));
|
|
325
325
|
}
|
|
326
326
|
}
|
|
327
|
-
|
|
327
|
+
function Oe(r) {
|
|
328
|
+
return new Worker(
|
|
329
|
+
"" + new URL("assets/worker-Cmho-Hr0.js", import.meta.url).href,
|
|
330
|
+
{
|
|
331
|
+
name: r == null ? void 0 : r.name
|
|
332
|
+
}
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
class Te {
|
|
328
336
|
/**
|
|
329
337
|
* @param scriptUrl — URL скрипта воркера.
|
|
330
|
-
* По-умолчанию использует
|
|
338
|
+
* По-умолчанию использует DefaultWorker из соседнего файла
|
|
331
339
|
*/
|
|
332
|
-
constructor(e
|
|
333
|
-
this.worker = new Worker(e, { type: "module" }), this._callbacks = /* @__PURE__ */ new Map(), this.worker.onmessage = this._handleMessage.bind(this);
|
|
340
|
+
constructor(e) {
|
|
341
|
+
e ? this.worker = new Worker(e, { type: "module" }) : this.worker = new Oe(), this._callbacks = /* @__PURE__ */ new Map(), this.worker.onmessage = this._handleMessage.bind(this);
|
|
334
342
|
}
|
|
335
343
|
/**
|
|
336
344
|
* Обработчик сообщений от воркера
|
|
@@ -370,26 +378,26 @@ class Oe {
|
|
|
370
378
|
this.worker.terminate();
|
|
371
379
|
}
|
|
372
380
|
}
|
|
373
|
-
const C = 12,
|
|
374
|
-
function W(
|
|
375
|
-
const n = C, a =
|
|
376
|
-
|
|
381
|
+
const C = 12, ke = 2, Q = 8, J = 20, xe = 100, $ = 20, K = 8, Be = 100, q = 32, ee = 1, Ze = "#2B2D33", te = "#3D8BF4", se = "#FFFFFF";
|
|
382
|
+
function W(r, e, t, s, i) {
|
|
383
|
+
const n = C, a = ke;
|
|
384
|
+
r.save(), r.translate(e, t), r.rotate(R.degreesToRadians(i.angle)), r.fillStyle = se, r.strokeStyle = te, r.lineWidth = ee, r.beginPath(), r.roundRect(-12 / 2, -12 / 2, n, n, a), r.fill(), r.stroke(), r.restore();
|
|
377
385
|
}
|
|
378
|
-
function he(
|
|
379
|
-
const n = Q, a = J, o =
|
|
380
|
-
|
|
386
|
+
function he(r, e, t, s, i) {
|
|
387
|
+
const n = Q, a = J, o = xe;
|
|
388
|
+
r.save(), r.translate(e, t), r.rotate(R.degreesToRadians(i.angle)), r.fillStyle = se, r.strokeStyle = te, r.lineWidth = ee, r.beginPath(), r.roundRect(-8 / 2, -20 / 2, n, a, o), r.fill(), r.stroke(), r.restore();
|
|
381
389
|
}
|
|
382
|
-
function ge(
|
|
383
|
-
const n = $, a = K, o =
|
|
384
|
-
|
|
390
|
+
function ge(r, e, t, s, i) {
|
|
391
|
+
const n = $, a = K, o = Be;
|
|
392
|
+
r.save(), r.translate(e, t), r.rotate(R.degreesToRadians(i.angle)), r.fillStyle = se, r.strokeStyle = te, r.lineWidth = ee, r.beginPath(), r.roundRect(-20 / 2, -8 / 2, n, a, o), r.fill(), r.stroke(), r.restore();
|
|
385
393
|
}
|
|
386
394
|
const Ue = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCIgZmlsbD0ibm9uZSI+PHBhdGggZmlsbD0iI2ZmZiIgZD0iTTE4Ljc1IDQuMzc1djMuNzVhLjYyNS42MjUgMCAwIDEtLjYyNS42MjVoLTMuNzVhLjYyNS42MjUgMCAwIDEgMC0xLjI1aDIuMTRsLTIuMDc3LTEuOTAzLS4wMi0uMDE5YTYuMjUgNi4yNSAwIDEgMC0uMTMgOC45NjcuNjI2LjYyNiAwIDAgMSAuODYuOTA5QTcuNDU2IDcuNDU2IDAgMCAxIDEwIDE3LjVoLS4xMDNhNy41IDcuNSAwIDEgMSA1LjM5Ni0xMi44MTJMMTcuNSA2LjcwM1Y0LjM3NWEuNjI1LjYyNSAwIDAgMSAxLjI1IDBaIi8+PC9zdmc+", ue = new Image();
|
|
387
395
|
ue.src = Ue;
|
|
388
|
-
function
|
|
396
|
+
function ze(r, e, t, s, i) {
|
|
389
397
|
const a = q / 2;
|
|
390
|
-
|
|
398
|
+
r.save(), r.translate(e, t), r.rotate(R.degreesToRadians(i.angle)), r.fillStyle = Ze, r.beginPath(), r.arc(0, 0, a, 0, 2 * Math.PI), r.fill(), r.drawImage(ue, -16 / 2, -16 / 2, a, a), r.restore();
|
|
391
399
|
}
|
|
392
|
-
const
|
|
400
|
+
const Re = {
|
|
393
401
|
// Угловые точки
|
|
394
402
|
tl: {
|
|
395
403
|
render: W,
|
|
@@ -451,17 +459,17 @@ const ze = {
|
|
|
451
459
|
},
|
|
452
460
|
// Специальный «rotate» контрол
|
|
453
461
|
mtr: {
|
|
454
|
-
render:
|
|
462
|
+
render: ze,
|
|
455
463
|
sizeX: q,
|
|
456
464
|
sizeY: q,
|
|
457
465
|
offsetX: 0,
|
|
458
466
|
offsetY: -32
|
|
459
467
|
}
|
|
460
468
|
};
|
|
461
|
-
class
|
|
469
|
+
class He {
|
|
462
470
|
static apply() {
|
|
463
|
-
const e =
|
|
464
|
-
Object.entries(
|
|
471
|
+
const e = ye.createObjectDefaultControls();
|
|
472
|
+
Object.entries(Re).forEach(([t, s]) => {
|
|
465
473
|
Object.assign(e[t], {
|
|
466
474
|
render: s.render,
|
|
467
475
|
sizeX: s.sizeX,
|
|
@@ -472,10 +480,10 @@ class Re {
|
|
|
472
480
|
var l;
|
|
473
481
|
(l = a.target.canvas) == null || l.setCursor("grabbing");
|
|
474
482
|
});
|
|
475
|
-
}),
|
|
483
|
+
}), pe.ownDefaults.controls = e;
|
|
476
484
|
}
|
|
477
485
|
}
|
|
478
|
-
const
|
|
486
|
+
const Ye = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h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"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCIgZmlsbD0ibm9uZSI+PHBhdGggZmlsbD0iI0VDNEU0MCIgZmlsbC1ydWxlPSJldmVub2RkIiBkPSJNOC4xMjUgMS4yNUExLjg3NSAxLjg3NSAwIDAgMCA2LjI1IDMuMTI1di42MjVIMy4xMjVhLjYyNS42MjUgMCAwIDAgMCAxLjI1aC42MjV2MTEuMjVBMS4yNSAxLjI1IDAgMCAwIDUgMTcuNWgxMGExLjI1IDEuMjUgMCAwIDAgMS4yNS0xLjI1VjVoLjYyNWEuNjI1LjYyNSAwIDAgMCAwLTEuMjVIMTMuNzV2LS42MjVhMS44NzUgMS44NzUgMCAwIDAtMS44NzUtMS44NzVoLTMuNzVabTQuMzc1IDIuNXYtLjYyNWEuNjI1LjYyNSAwIDAgMC0uNjI1LS42MjVoLTMuNzVhLjYyNS42MjUgMCAwIDAtLjYyNS42MjV2LjYyNWg1Wk01IDE2LjI1VjVoMTB2MTEuMjVINVpNOC4xMjUgNy41Yy4zNDUgMCAuNjI1LjI4LjYyNS42MjV2NWEuNjI1LjYyNSAwIDEgMS0xLjI1IDB2LTVjMC0uMzQ1LjI4LS42MjUuNjI1LS42MjVabTQuMzc1IDUuNjI1di01YS42MjUuNjI1IDAgMCAwLTEuMjUgMHY1YS42MjUuNjI1IDAgMSAwIDEuMjUgMFoiIGNsaXAtcnVsZT0iZXZlbm9kZCIvPjwvc3ZnPg==", U = {
|
|
479
487
|
style: {
|
|
480
488
|
position: "absolute",
|
|
481
489
|
display: "none",
|
|
@@ -542,54 +550,54 @@ const He = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMj
|
|
|
542
550
|
],
|
|
543
551
|
offsetTop: 50,
|
|
544
552
|
icons: {
|
|
545
|
-
copyPaste:
|
|
546
|
-
delete:
|
|
547
|
-
lock:
|
|
548
|
-
unlock:
|
|
549
|
-
bringToFront:
|
|
550
|
-
sendToBack:
|
|
551
|
-
bringForward:
|
|
552
|
-
sendBackwards:
|
|
553
|
+
copyPaste: Ye,
|
|
554
|
+
delete: Xe,
|
|
555
|
+
lock: We,
|
|
556
|
+
unlock: _e,
|
|
557
|
+
bringToFront: Ve,
|
|
558
|
+
sendToBack: Ge,
|
|
559
|
+
bringForward: Pe,
|
|
560
|
+
sendBackwards: Fe
|
|
553
561
|
},
|
|
554
562
|
handlers: {
|
|
555
|
-
copyPaste: (
|
|
556
|
-
yield
|
|
563
|
+
copyPaste: (r) => I(void 0, null, function* () {
|
|
564
|
+
yield r.clipboardManager.copy(), yield r.clipboardManager.paste();
|
|
557
565
|
}),
|
|
558
|
-
delete: (
|
|
559
|
-
|
|
566
|
+
delete: (r) => {
|
|
567
|
+
r.deletionManager.deleteSelectedObjects();
|
|
560
568
|
},
|
|
561
|
-
lock: (
|
|
562
|
-
|
|
569
|
+
lock: (r) => {
|
|
570
|
+
r.objectLockManager.lockObject();
|
|
563
571
|
},
|
|
564
|
-
unlock: (
|
|
565
|
-
|
|
572
|
+
unlock: (r) => {
|
|
573
|
+
r.objectLockManager.unlockObject();
|
|
566
574
|
},
|
|
567
|
-
bringForward: (
|
|
568
|
-
|
|
575
|
+
bringForward: (r) => {
|
|
576
|
+
r.layerManager.bringForward();
|
|
569
577
|
},
|
|
570
|
-
bringToFront: (
|
|
571
|
-
|
|
578
|
+
bringToFront: (r) => {
|
|
579
|
+
r.layerManager.bringToFront();
|
|
572
580
|
},
|
|
573
|
-
sendToBack: (
|
|
574
|
-
|
|
581
|
+
sendToBack: (r) => {
|
|
582
|
+
r.layerManager.sendToBack();
|
|
575
583
|
},
|
|
576
|
-
sendBackwards: (
|
|
577
|
-
|
|
584
|
+
sendBackwards: (r) => {
|
|
585
|
+
r.layerManager.sendBackwards();
|
|
578
586
|
}
|
|
579
587
|
}
|
|
580
588
|
};
|
|
581
|
-
class
|
|
589
|
+
class Qe {
|
|
582
590
|
constructor({ editor: e }) {
|
|
583
591
|
this.currentTarget = null, this.currentLocked = !1, this.isTransforming = !1, this.editor = e, this.canvas = e.canvas, this.options = e.options, this._initToolbar();
|
|
584
592
|
}
|
|
585
593
|
_initToolbar() {
|
|
586
594
|
if (!this.options.showToolbar) return;
|
|
587
595
|
const e = this.options.toolbar || {};
|
|
588
|
-
this.config = le(f(f({},
|
|
589
|
-
style: f(f({},
|
|
590
|
-
btnStyle: f(f({},
|
|
591
|
-
icons: f(f({},
|
|
592
|
-
handlers: f(f({},
|
|
596
|
+
this.config = le(f(f({}, U), e), {
|
|
597
|
+
style: f(f({}, U.style), e.style || {}),
|
|
598
|
+
btnStyle: f(f({}, U.btnStyle), e.btnStyle || {}),
|
|
599
|
+
icons: f(f({}, U.icons), e.icons || {}),
|
|
600
|
+
handlers: f(f({}, U.handlers), e.handlers || {})
|
|
593
601
|
}), this.currentTarget = null, this.currentLocked = !1, this.isTransforming = !1, this._onMouseDown = this._handleMouseDown.bind(this), this._onObjectMoving = this._startTransform.bind(this), this._onObjectScaling = this._startTransform.bind(this), this._onObjectRotating = this._startTransform.bind(this), this._onMouseUp = this._endTransform.bind(this), this._onObjectModified = this._endTransform.bind(this), this._onSelectionChange = this._updateToolbar.bind(this), this._onSelectionClear = () => {
|
|
594
602
|
this.el.style.display = "none";
|
|
595
603
|
}, this._createDOM(), this._bindEvents();
|
|
@@ -618,8 +626,8 @@ class Xe {
|
|
|
618
626
|
for (const t of e) {
|
|
619
627
|
const { name: s, handle: i } = t, { icons: n = {}, btnStyle: a, handlers: o = {} } = this.config, d = document.createElement("button");
|
|
620
628
|
d.innerHTML = n[i] ? `<img src="${n[i]}" title="${s}" />` : s, Object.assign(d.style, a), d.onclick = () => {
|
|
621
|
-
var
|
|
622
|
-
return (
|
|
629
|
+
var c;
|
|
630
|
+
return (c = o[i]) == null ? void 0 : c.call(o, this.editor);
|
|
623
631
|
}, this.el.appendChild(d);
|
|
624
632
|
}
|
|
625
633
|
}
|
|
@@ -678,7 +686,7 @@ class Xe {
|
|
|
678
686
|
}
|
|
679
687
|
const { el: t, config: s, canvas: i } = this;
|
|
680
688
|
e.setCoords();
|
|
681
|
-
const n = i.getZoom(), [, , , , a, o] = i.viewportTransform, { x: d } = e.getCenterPoint(), { top:
|
|
689
|
+
const n = i.getZoom(), [, , , , a, o] = i.viewportTransform, { x: d } = e.getCenterPoint(), { top: c, height: l } = e.getBoundingRect(), g = d * n + a - t.offsetWidth / 2, u = s.offsetTop || 0, m = (c + l) * n + o + u;
|
|
682
690
|
Object.assign(t.style, {
|
|
683
691
|
left: `${g}px`,
|
|
684
692
|
top: `${m}px`,
|
|
@@ -692,7 +700,7 @@ class Xe {
|
|
|
692
700
|
this.el.removeEventListener("mouseover", this._onBtnOver), this.el.removeEventListener("mouseout", this._onBtnOut), this.canvas.off("mouse:down", this._onMouseDown), this.canvas.off("object:moving", this._onObjectMoving), this.canvas.off("object:scaling", this._onObjectScaling), this.canvas.off("object:rotating", this._onObjectRotating), this.canvas.off("mouse:up", this._onMouseUp), this.canvas.off("object:modified", this._onObjectModified), this.canvas.off("selection:created", this._onSelectionChange), this.canvas.off("selection:updated", this._onSelectionChange), this.canvas.off("after:render", this._onSelectionChange), this.canvas.off("selection:cleared", this._onSelectionClear), this.el.remove();
|
|
693
701
|
}
|
|
694
702
|
}
|
|
695
|
-
class
|
|
703
|
+
class Je {
|
|
696
704
|
constructor({ editor: e }) {
|
|
697
705
|
this.editor = e, this.canvas = e.canvas, this._historySuspendCount = 0, this.baseState = null, this.patches = [], this.currentIndex = 0, this.maxHistoryLength = e.options.maxHistoryLength, this.totalChangesCount = 0, this.baseStateChangesCount = 0, this._createDiffPatcher();
|
|
698
706
|
}
|
|
@@ -807,9 +815,9 @@ class Qe {
|
|
|
807
815
|
console.log("loadStateFromFullState fullState", e);
|
|
808
816
|
const { canvas: t, canvasManager: s, interactionBlocker: i } = this.editor, { width: n, height: a } = t;
|
|
809
817
|
yield t.loadFromJSON(e);
|
|
810
|
-
const o = t.getObjects().find((
|
|
818
|
+
const o = t.getObjects().find((c) => c.id === "montage-area");
|
|
811
819
|
o && (this.editor.montageArea = o, (n !== e.width || a !== e.height) && s.updateCanvasAndFitObjects());
|
|
812
|
-
const d = t.getObjects().find((
|
|
820
|
+
const d = t.getObjects().find((c) => c.id === "overlay-mask");
|
|
813
821
|
d && (i.overlayMask = d, i.overlayMask.visible = !1), t.renderAll(), t.fire("editor:history-state-loaded", {
|
|
814
822
|
fullState: e,
|
|
815
823
|
currentIndex: this.currentIndex,
|
|
@@ -895,7 +903,7 @@ class Qe {
|
|
|
895
903
|
});
|
|
896
904
|
}
|
|
897
905
|
}
|
|
898
|
-
const
|
|
906
|
+
const $e = 0.1, Ke = 2, qe = 0.1, et = 90, x = 16, B = 16, O = 4096, T = 4096;
|
|
899
907
|
class N {
|
|
900
908
|
constructor({ editor: e }) {
|
|
901
909
|
this.editor = e, this.options = e.options, this._createdBlobUrls = [], this.acceptContentTypes = this.editor.options.acceptContentTypes, this.acceptFormats = this.getAllowedFormatsFromContentTypes();
|
|
@@ -920,10 +928,10 @@ class N {
|
|
|
920
928
|
withoutSave: i = !1
|
|
921
929
|
} = e;
|
|
922
930
|
if (!t) return null;
|
|
923
|
-
const { canvas: n, montageArea: a, transformManager: o, historyManager: d, errorManager:
|
|
931
|
+
const { canvas: n, montageArea: a, transformManager: o, historyManager: d, errorManager: c } = this.editor, l = yield this.getContentType(t), h = N.getFormatFromContentType(l), { acceptContentTypes: g, acceptFormats: u } = this;
|
|
924
932
|
if (!this.isAllowedContentType(l)) {
|
|
925
933
|
const m = `Неверный contentType для изображения: ${l}. Ожидается один из: ${this.acceptContentTypes.join(", ")}.`;
|
|
926
|
-
return
|
|
934
|
+
return c.emitError({
|
|
927
935
|
origin: "ImageManager",
|
|
928
936
|
method: "importImage",
|
|
929
937
|
code: "INVALID_CONTENT_TYPE",
|
|
@@ -940,7 +948,7 @@ class N {
|
|
|
940
948
|
const A = yield (yield fetch(t, { mode: "cors" })).blob();
|
|
941
949
|
m = URL.createObjectURL(A);
|
|
942
950
|
} else
|
|
943
|
-
return
|
|
951
|
+
return c.emitError({
|
|
944
952
|
origin: "ImageManager",
|
|
945
953
|
method: "importImage",
|
|
946
954
|
code: "INVALID_SOURCE_TYPE",
|
|
@@ -948,27 +956,27 @@ class N {
|
|
|
948
956
|
data: { source: t, format: h, contentType: l, acceptContentTypes: g, acceptFormats: u }
|
|
949
957
|
}), null;
|
|
950
958
|
if (this._createdBlobUrls.push(m), h === "svg") {
|
|
951
|
-
const
|
|
952
|
-
M = R.groupSVGElements(
|
|
959
|
+
const p = yield Ie(m);
|
|
960
|
+
M = R.groupSVGElements(p.objects, p.options);
|
|
953
961
|
} else
|
|
954
|
-
M = yield
|
|
962
|
+
M = yield Z.fromURL(m, { crossOrigin: "anonymous" });
|
|
955
963
|
const { width: j, height: b } = M;
|
|
956
|
-
if (M instanceof
|
|
957
|
-
const
|
|
964
|
+
if (M instanceof Z) {
|
|
965
|
+
const p = M.getElement();
|
|
958
966
|
let A = "";
|
|
959
|
-
if (
|
|
967
|
+
if (p instanceof HTMLImageElement ? A = p.src : p instanceof HTMLCanvasElement && (A = p.toDataURL()), b > T || j > O) {
|
|
960
968
|
const w = yield this.resizeImageToBoundaries(A, "max"), E = URL.createObjectURL(w);
|
|
961
|
-
this._createdBlobUrls.push(E), M = yield
|
|
969
|
+
this._createdBlobUrls.push(E), M = yield Z.fromURL(E, { crossOrigin: "anonymous" });
|
|
962
970
|
} else if (b < B || j < x) {
|
|
963
971
|
const w = yield this.resizeImageToBoundaries(A, "min"), E = URL.createObjectURL(w);
|
|
964
|
-
this._createdBlobUrls.push(E), M = yield
|
|
972
|
+
this._createdBlobUrls.push(E), M = yield Z.fromURL(E, { crossOrigin: "anonymous" });
|
|
965
973
|
}
|
|
966
974
|
}
|
|
967
975
|
if (M.set("id", `${M.type}-${D()}`), M.set("format", h), s === "scale-montage")
|
|
968
976
|
this.editor.canvasManager.scaleMontageAreaToImage({ object: M, withoutSave: !0 });
|
|
969
977
|
else {
|
|
970
|
-
const { width:
|
|
971
|
-
s === "image-contain" && w < 1 ? o.fitObject({ object: M, type: "contain", withoutSave: !0 }) : s === "image-cover" && (j >
|
|
978
|
+
const { width: p, height: A } = a, w = this.calculateScaleFactor({ imageObject: M, scaleType: s });
|
|
979
|
+
s === "image-contain" && w < 1 ? o.fitObject({ object: M, type: "contain", withoutSave: !0 }) : s === "image-cover" && (j > p || b > A) && o.fitObject({ object: M, type: "cover", withoutSave: !0 });
|
|
972
980
|
}
|
|
973
981
|
n.add(M), n.centerObject(M), n.setActiveObject(M), n.renderAll(), d.resumeHistory(), i || d.saveState();
|
|
974
982
|
const L = {
|
|
@@ -981,7 +989,7 @@ class N {
|
|
|
981
989
|
};
|
|
982
990
|
return n.fire("editor:image-imported", L), L;
|
|
983
991
|
} catch (m) {
|
|
984
|
-
return
|
|
992
|
+
return c.emitError({
|
|
985
993
|
origin: "ImageManager",
|
|
986
994
|
method: "importImage",
|
|
987
995
|
code: "IMPORT_FAILED",
|
|
@@ -1040,18 +1048,18 @@ class N {
|
|
|
1040
1048
|
exportAsBlob: n = !1
|
|
1041
1049
|
} = e, { canvas: a, montageArea: o, workerManager: d } = this.editor;
|
|
1042
1050
|
try {
|
|
1043
|
-
const
|
|
1051
|
+
const c = s === "application/pdf", l = c ? "image/jpg" : s, h = N.getFormatFromContentType(l);
|
|
1044
1052
|
o.setCoords();
|
|
1045
1053
|
const { left: g, top: u, width: m, height: M } = o.getBoundingRect(), j = yield a.clone(["id", "format", "locked"]);
|
|
1046
1054
|
["image/jpg", "image/jpeg"].includes(l) && (j.backgroundColor = "#ffffff");
|
|
1047
|
-
const b = j.getObjects().find((
|
|
1055
|
+
const b = j.getObjects().find((y) => y.id === o.id);
|
|
1048
1056
|
b && (b.visible = !1), j.viewportTransform = [1, 0, 0, 1, -g, -u], j.setDimensions({ width: m, height: M }, { backstoreOnly: !0 }), j.renderAll();
|
|
1049
|
-
const L = j.getObjects().filter((
|
|
1057
|
+
const L = j.getObjects().filter((y) => y.format).every((y) => y.format === "svg");
|
|
1050
1058
|
if (h === "svg" && L) {
|
|
1051
|
-
const
|
|
1059
|
+
const y = j.toSVG();
|
|
1052
1060
|
j.dispose();
|
|
1053
1061
|
const S = {
|
|
1054
|
-
image: N._exportSVGStringAsFile(
|
|
1062
|
+
image: N._exportSVGStringAsFile(y, {
|
|
1055
1063
|
exportAsBase64: i,
|
|
1056
1064
|
exportAsBlob: n,
|
|
1057
1065
|
fileName: t
|
|
@@ -1062,26 +1070,26 @@ class N {
|
|
|
1062
1070
|
};
|
|
1063
1071
|
return a.fire("editor:canvas-exported", S), S;
|
|
1064
1072
|
}
|
|
1065
|
-
const
|
|
1073
|
+
const p = yield new Promise((y, k) => {
|
|
1066
1074
|
j.getElement().toBlob((S) => {
|
|
1067
|
-
S ?
|
|
1075
|
+
S ? y(S) : k(new Error("Failed to create Blob from canvas"));
|
|
1068
1076
|
});
|
|
1069
1077
|
});
|
|
1070
1078
|
if (j.dispose(), n) {
|
|
1071
|
-
const
|
|
1072
|
-
image:
|
|
1079
|
+
const y = {
|
|
1080
|
+
image: p,
|
|
1073
1081
|
format: h,
|
|
1074
1082
|
contentType: l,
|
|
1075
1083
|
fileName: t
|
|
1076
1084
|
};
|
|
1077
|
-
return a.fire("editor:canvas-exported",
|
|
1085
|
+
return a.fire("editor:canvas-exported", y), y;
|
|
1078
1086
|
}
|
|
1079
|
-
const A = yield createImageBitmap(
|
|
1087
|
+
const A = yield createImageBitmap(p), w = yield d.post(
|
|
1080
1088
|
"toDataURL",
|
|
1081
1089
|
{ format: h, quality: 1, bitmap: A },
|
|
1082
1090
|
[A]
|
|
1083
1091
|
);
|
|
1084
|
-
if (
|
|
1092
|
+
if (c) {
|
|
1085
1093
|
const k = m * 0.264583, S = M * 0.264583, Me = (yield this.editor.moduleLoader.loadModule("jspdf")).jsPDF, G = new Me({
|
|
1086
1094
|
orientation: k > S ? "landscape" : "portrait",
|
|
1087
1095
|
unit: "mm",
|
|
@@ -1105,27 +1113,27 @@ class N {
|
|
|
1105
1113
|
return a.fire("editor:canvas-exported", ae), ae;
|
|
1106
1114
|
}
|
|
1107
1115
|
if (i) {
|
|
1108
|
-
const
|
|
1116
|
+
const y = {
|
|
1109
1117
|
image: w,
|
|
1110
1118
|
format: h,
|
|
1111
1119
|
contentType: l,
|
|
1112
1120
|
fileName: t
|
|
1113
1121
|
};
|
|
1114
|
-
return a.fire("editor:canvas-exported",
|
|
1122
|
+
return a.fire("editor:canvas-exported", y), y;
|
|
1115
1123
|
}
|
|
1116
1124
|
const E = h === "svg" && !L ? t.replace(/\.[^/.]+$/, ".png") : t, ne = {
|
|
1117
|
-
image: new File([
|
|
1125
|
+
image: new File([p], E, { type: l }),
|
|
1118
1126
|
format: h,
|
|
1119
1127
|
contentType: l,
|
|
1120
1128
|
fileName: E
|
|
1121
1129
|
};
|
|
1122
1130
|
return a.fire("editor:canvas-exported", ne), ne;
|
|
1123
|
-
} catch (
|
|
1131
|
+
} catch (c) {
|
|
1124
1132
|
return this.editor.errorManager.emitError({
|
|
1125
1133
|
origin: "ImageManager",
|
|
1126
1134
|
method: "exportCanvasAsImageFile",
|
|
1127
1135
|
code: "IMAGE_EXPORT_FAILED",
|
|
1128
|
-
message: `Ошибка экспорта изображения: ${
|
|
1136
|
+
message: `Ошибка экспорта изображения: ${c.message}`,
|
|
1129
1137
|
data: { contentType: s, fileName: t, exportAsBase64: i, exportAsBlob: n }
|
|
1130
1138
|
}), null;
|
|
1131
1139
|
}
|
|
@@ -1150,8 +1158,8 @@ class N {
|
|
|
1150
1158
|
contentType: i = "image/png",
|
|
1151
1159
|
exportAsBase64: n = !1,
|
|
1152
1160
|
exportAsBlob: a = !1
|
|
1153
|
-
} = e, { canvas: o, workerManager: d } = this.editor,
|
|
1154
|
-
if (!
|
|
1161
|
+
} = e, { canvas: o, workerManager: d } = this.editor, c = t || o.getActiveObject();
|
|
1162
|
+
if (!c)
|
|
1155
1163
|
return this.editor.errorManager.emitError({
|
|
1156
1164
|
origin: "ImageManager",
|
|
1157
1165
|
method: "exportObjectAsImageFile",
|
|
@@ -1162,12 +1170,12 @@ class N {
|
|
|
1162
1170
|
try {
|
|
1163
1171
|
const l = N.getFormatFromContentType(i);
|
|
1164
1172
|
if (l === "svg") {
|
|
1165
|
-
const M =
|
|
1173
|
+
const M = c.toSVG(), j = N._exportSVGStringAsFile(M, {
|
|
1166
1174
|
exportAsBase64: n,
|
|
1167
1175
|
exportAsBlob: a,
|
|
1168
1176
|
fileName: s
|
|
1169
1177
|
}), b = {
|
|
1170
|
-
object:
|
|
1178
|
+
object: c,
|
|
1171
1179
|
image: j,
|
|
1172
1180
|
format: l,
|
|
1173
1181
|
contentType: "image/svg+xml",
|
|
@@ -1175,8 +1183,8 @@ class N {
|
|
|
1175
1183
|
};
|
|
1176
1184
|
return o.fire("editor:object-exported", b), b;
|
|
1177
1185
|
}
|
|
1178
|
-
if (n &&
|
|
1179
|
-
const M = yield createImageBitmap(
|
|
1186
|
+
if (n && c instanceof Z) {
|
|
1187
|
+
const M = yield createImageBitmap(c.getElement()), j = yield d.post(
|
|
1180
1188
|
"toDataURL",
|
|
1181
1189
|
{
|
|
1182
1190
|
format: l,
|
|
@@ -1185,7 +1193,7 @@ class N {
|
|
|
1185
1193
|
},
|
|
1186
1194
|
[M]
|
|
1187
1195
|
), b = {
|
|
1188
|
-
object:
|
|
1196
|
+
object: c,
|
|
1189
1197
|
image: j,
|
|
1190
1198
|
format: l,
|
|
1191
1199
|
contentType: i,
|
|
@@ -1193,14 +1201,14 @@ class N {
|
|
|
1193
1201
|
};
|
|
1194
1202
|
return o.fire("editor:object-exported", b), b;
|
|
1195
1203
|
}
|
|
1196
|
-
const h =
|
|
1204
|
+
const h = c.toCanvasElement(), g = yield new Promise((M, j) => {
|
|
1197
1205
|
h.toBlob((b) => {
|
|
1198
1206
|
b ? M(b) : j(new Error("Failed to create Blob from canvas"));
|
|
1199
1207
|
});
|
|
1200
1208
|
});
|
|
1201
1209
|
if (a) {
|
|
1202
1210
|
const M = {
|
|
1203
|
-
object:
|
|
1211
|
+
object: c,
|
|
1204
1212
|
image: g,
|
|
1205
1213
|
format: l,
|
|
1206
1214
|
contentType: i,
|
|
@@ -1209,7 +1217,7 @@ class N {
|
|
|
1209
1217
|
return o.fire("editor:object-exported", M), M;
|
|
1210
1218
|
}
|
|
1211
1219
|
const u = new File([g], s, { type: i }), m = {
|
|
1212
|
-
object:
|
|
1220
|
+
object: c,
|
|
1213
1221
|
image: u,
|
|
1214
1222
|
format: l,
|
|
1215
1223
|
contentType: i,
|
|
@@ -1344,7 +1352,7 @@ class N {
|
|
|
1344
1352
|
return t ? t[1] : "";
|
|
1345
1353
|
}
|
|
1346
1354
|
}
|
|
1347
|
-
class
|
|
1355
|
+
class tt {
|
|
1348
1356
|
/**
|
|
1349
1357
|
* @param options
|
|
1350
1358
|
* @param options.editor – экземпляр редактора
|
|
@@ -1368,9 +1376,9 @@ class et {
|
|
|
1368
1376
|
canvas: n,
|
|
1369
1377
|
montageArea: a,
|
|
1370
1378
|
options: { canvasBackstoreWidth: o }
|
|
1371
|
-
} = this.editor, { width: d, height:
|
|
1379
|
+
} = this.editor, { width: d, height: c } = a, l = Math.max(Math.min(Number(e), O), x);
|
|
1372
1380
|
if (!o || o === "auto" || i ? this.adaptCanvasToContainer() : o ? this.setCanvasBackstoreWidth(Number(o)) : this.setCanvasBackstoreWidth(l), a.set({ width: l }), (m = n.clipPath) == null || m.set({ width: l }), t) {
|
|
1373
|
-
const M = l / d, j =
|
|
1381
|
+
const M = l / d, j = c * M;
|
|
1374
1382
|
this.setResolutionHeight(j);
|
|
1375
1383
|
return;
|
|
1376
1384
|
}
|
|
@@ -1398,9 +1406,9 @@ class et {
|
|
|
1398
1406
|
canvas: n,
|
|
1399
1407
|
montageArea: a,
|
|
1400
1408
|
options: { canvasBackstoreHeight: o }
|
|
1401
|
-
} = this.editor, { width: d, height:
|
|
1409
|
+
} = this.editor, { width: d, height: c } = a, l = Math.max(Math.min(Number(e), T), B);
|
|
1402
1410
|
if (!o || o === "auto" || i ? this.adaptCanvasToContainer() : o ? this.setCanvasBackstoreHeight(Number(o)) : this.setCanvasBackstoreHeight(l), a.set({ height: l }), (m = n.clipPath) == null || m.set({ height: l }), t) {
|
|
1403
|
-
const M = l /
|
|
1411
|
+
const M = l / c, j = d * M;
|
|
1404
1412
|
this.setResolutionWidth(j);
|
|
1405
1413
|
return;
|
|
1406
1414
|
}
|
|
@@ -1611,15 +1619,15 @@ class et {
|
|
|
1611
1619
|
}
|
|
1612
1620
|
const o = t === "width" ? "width" : "height";
|
|
1613
1621
|
if (typeof s == "string") {
|
|
1614
|
-
a.forEach((
|
|
1615
|
-
|
|
1622
|
+
a.forEach((c) => {
|
|
1623
|
+
c.style[o] = s;
|
|
1616
1624
|
});
|
|
1617
1625
|
return;
|
|
1618
1626
|
}
|
|
1619
1627
|
if (isNaN(s)) return;
|
|
1620
1628
|
const d = `${s}px`;
|
|
1621
|
-
a.forEach((
|
|
1622
|
-
|
|
1629
|
+
a.forEach((c) => {
|
|
1630
|
+
c.style[o] = d;
|
|
1623
1631
|
}), i.fire(`editor:display-${e}-${o}-changed`, {
|
|
1624
1632
|
element: e,
|
|
1625
1633
|
value: s
|
|
@@ -1642,9 +1650,9 @@ class et {
|
|
|
1642
1650
|
montageAreaWidth: o,
|
|
1643
1651
|
montageAreaHeight: d
|
|
1644
1652
|
}
|
|
1645
|
-
} = this.editor,
|
|
1646
|
-
if (!
|
|
1647
|
-
const { width: l, height: h } =
|
|
1653
|
+
} = this.editor, c = e || i.getActiveObject();
|
|
1654
|
+
if (!c || c.type !== "image" && c.format !== "svg") return;
|
|
1655
|
+
const { width: l, height: h } = c;
|
|
1648
1656
|
let g = Math.min(l, O), u = Math.min(h, T);
|
|
1649
1657
|
if (t) {
|
|
1650
1658
|
const {
|
|
@@ -1653,8 +1661,8 @@ class et {
|
|
|
1653
1661
|
} = n, j = l / m, b = h / M, L = Math.max(j, b);
|
|
1654
1662
|
g = m * L, u = M * L;
|
|
1655
1663
|
}
|
|
1656
|
-
this.setResolutionWidth(g, { withoutSave: !0 }), this.setResolutionHeight(u, { withoutSave: !0 }), (l > o || h > d) && a.calculateAndApplyDefaultZoom(), a.resetObject(
|
|
1657
|
-
object:
|
|
1664
|
+
this.setResolutionWidth(g, { withoutSave: !0 }), this.setResolutionHeight(u, { withoutSave: !0 }), (l > o || h > d) && a.calculateAndApplyDefaultZoom(), a.resetObject(c, { withoutSave: !0 }), i.centerObject(c), i.renderAll(), s || this.editor.historyManager.saveState(), i.fire("editor:montage-area-scaled-to-image", {
|
|
1665
|
+
object: c,
|
|
1658
1666
|
width: g,
|
|
1659
1667
|
height: u,
|
|
1660
1668
|
preserveAspectRatio: t,
|
|
@@ -1696,9 +1704,9 @@ class et {
|
|
|
1696
1704
|
return e.getObjects().filter((n) => n.id !== t.id && n.id !== (s == null ? void 0 : s.id));
|
|
1697
1705
|
}
|
|
1698
1706
|
}
|
|
1699
|
-
class
|
|
1707
|
+
class st {
|
|
1700
1708
|
constructor({ editor: e }) {
|
|
1701
|
-
this.editor = e, this.options = e.options, this.minZoom = this.options.minZoom ||
|
|
1709
|
+
this.editor = e, this.options = e.options, this.minZoom = this.options.minZoom || $e, this.maxZoom = this.options.maxZoom || Ke, this.defaultZoom = this.options.defaultScale, this.maxZoomFactor = this.options.maxZoomFactor;
|
|
1702
1710
|
}
|
|
1703
1711
|
/**
|
|
1704
1712
|
* Метод рассчитывает и применяет зум по умолчанию для монтажной области редактора.
|
|
@@ -1708,8 +1716,8 @@ class tt {
|
|
|
1708
1716
|
* @param scale - Желаемый масштаб относительно размеров контейнера редактора.
|
|
1709
1717
|
*/
|
|
1710
1718
|
calculateAndApplyDefaultZoom(e = this.options.defaultScale) {
|
|
1711
|
-
const { canvas: t } = this.editor, s = t.editorContainer, i = s.clientWidth, n = s.clientHeight, { width: a, height: o } = this.editor.montageArea, d = i / a * e,
|
|
1712
|
-
this.defaultZoom = Math.min(d,
|
|
1719
|
+
const { canvas: t } = this.editor, s = t.editorContainer, i = s.clientWidth, n = s.clientHeight, { width: a, height: o } = this.editor.montageArea, d = i / a * e, c = n / o * e;
|
|
1720
|
+
this.defaultZoom = Math.min(d, c);
|
|
1713
1721
|
const { defaultZoom: l, maxZoomFactor: h, minZoom: g, maxZoom: u } = this;
|
|
1714
1722
|
this.minZoom = Math.min(l / h, g), this.maxZoom = Math.max(l * h, u), this.setZoom();
|
|
1715
1723
|
}
|
|
@@ -1722,10 +1730,10 @@ class tt {
|
|
|
1722
1730
|
* @fires editor:zoom-changed
|
|
1723
1731
|
* Если передавать координаты курсора, то нужно быть аккуратнее, так как юзер может выйти за пределы рабочей области
|
|
1724
1732
|
*/
|
|
1725
|
-
zoom(e =
|
|
1733
|
+
zoom(e = qe, t = {}) {
|
|
1726
1734
|
var g, u;
|
|
1727
1735
|
if (!e) return;
|
|
1728
|
-
const { minZoom: s, maxZoom: i } = this, { canvas: n } = this.editor, a = n.getZoom(), o = n.getCenterPoint(), d = (g = t.pointX) != null ? g : o.x,
|
|
1736
|
+
const { minZoom: s, maxZoom: i } = this, { canvas: n } = this.editor, a = n.getZoom(), o = n.getCenterPoint(), d = (g = t.pointX) != null ? g : o.x, c = (u = t.pointY) != null ? u : o.y, l = new _(d, c);
|
|
1729
1737
|
let h = Number((a + Number(e)).toFixed(2));
|
|
1730
1738
|
h > i && (h = i), h < s && (h = s), n.zoomToPoint(l, h), console.log({
|
|
1731
1739
|
currentZoom: a,
|
|
@@ -1769,7 +1777,7 @@ class tt {
|
|
|
1769
1777
|
* @param options.withoutSave - Не сохранять состояние
|
|
1770
1778
|
* @fires editor:object-rotated
|
|
1771
1779
|
*/
|
|
1772
|
-
rotate(e =
|
|
1780
|
+
rotate(e = et, { withoutSave: t } = {}) {
|
|
1773
1781
|
const { canvas: s, historyManager: i } = this.editor, n = s.getActiveObject();
|
|
1774
1782
|
if (!n) return;
|
|
1775
1783
|
const a = n.angle + e;
|
|
@@ -1847,19 +1855,19 @@ class tt {
|
|
|
1847
1855
|
const { canvas: n, imageManager: a, historyManager: o } = this.editor, d = e || n.getActiveObject();
|
|
1848
1856
|
if (d) {
|
|
1849
1857
|
if (d.set("angle", 0), d instanceof v && !i) {
|
|
1850
|
-
const
|
|
1851
|
-
n.discardActiveObject(),
|
|
1858
|
+
const c = d.getObjects();
|
|
1859
|
+
n.discardActiveObject(), c.forEach((h) => {
|
|
1852
1860
|
const g = a.calculateScaleFactor({ imageObject: h, scaleType: t });
|
|
1853
1861
|
h.scale(g), n.centerObject(h);
|
|
1854
1862
|
});
|
|
1855
|
-
const l = new v(
|
|
1863
|
+
const l = new v(c, { canvas: n });
|
|
1856
1864
|
n.setActiveObject(l);
|
|
1857
1865
|
} else {
|
|
1858
|
-
const
|
|
1866
|
+
const c = a.calculateScaleFactor({
|
|
1859
1867
|
imageObject: d,
|
|
1860
1868
|
scaleType: t
|
|
1861
1869
|
});
|
|
1862
|
-
d.scale(
|
|
1870
|
+
d.scale(c), n.centerObject(d);
|
|
1863
1871
|
}
|
|
1864
1872
|
n.renderAll(), s || o.saveState(), n.fire("editor:object-fitted", {
|
|
1865
1873
|
object: d,
|
|
@@ -1892,31 +1900,31 @@ class tt {
|
|
|
1892
1900
|
imageManager: a,
|
|
1893
1901
|
historyManager: o,
|
|
1894
1902
|
options: { scaleType: d }
|
|
1895
|
-
} = this.editor,
|
|
1896
|
-
if (!
|
|
1897
|
-
if (o.suspendHistory(),
|
|
1903
|
+
} = this.editor, c = e || i.getActiveObject();
|
|
1904
|
+
if (!c || c.locked) return;
|
|
1905
|
+
if (o.suspendHistory(), c.type === "image" || c.format === "svg" || c.set({
|
|
1898
1906
|
scaleX: 1,
|
|
1899
1907
|
scaleY: 1,
|
|
1900
1908
|
flipX: !1,
|
|
1901
1909
|
flipY: !1,
|
|
1902
1910
|
angle: 0
|
|
1903
1911
|
}), t)
|
|
1904
|
-
this.fitObject({ object:
|
|
1912
|
+
this.fitObject({ object: c, withoutSave: !0, fitAsOneObject: !0 });
|
|
1905
1913
|
else {
|
|
1906
|
-
const { width: h, height: g } = n, { width: u, height: m } =
|
|
1907
|
-
imageObject:
|
|
1914
|
+
const { width: h, height: g } = n, { width: u, height: m } = c, M = a.calculateScaleFactor({
|
|
1915
|
+
imageObject: c,
|
|
1908
1916
|
scaleType: d
|
|
1909
1917
|
});
|
|
1910
|
-
d === "contain" && M < 1 || d === "cover" && (u > h || m > g) ? this.fitObject({ object:
|
|
1918
|
+
d === "contain" && M < 1 || d === "cover" && (u > h || m > g) ? this.fitObject({ object: c, withoutSave: !0, fitAsOneObject: !0 }) : c.set({ scaleX: 1, scaleY: 1 });
|
|
1911
1919
|
}
|
|
1912
|
-
|
|
1913
|
-
object:
|
|
1920
|
+
c.set({ flipX: !1, flipY: !1, angle: 0 }), i.centerObject(c), i.renderAll(), o.resumeHistory(), s || o.saveState(), i.fire("editor:object-reset", {
|
|
1921
|
+
object: c,
|
|
1914
1922
|
withoutSave: s,
|
|
1915
1923
|
alwaysFitObject: t
|
|
1916
1924
|
});
|
|
1917
1925
|
}
|
|
1918
1926
|
}
|
|
1919
|
-
class
|
|
1927
|
+
class it {
|
|
1920
1928
|
constructor({ editor: e }) {
|
|
1921
1929
|
this.editor = e, this.isBlocked = !1, this.overlayMask = null, this._createOverlay();
|
|
1922
1930
|
}
|
|
@@ -2030,8 +2038,8 @@ class P {
|
|
|
2030
2038
|
if (o) {
|
|
2031
2039
|
if (o instanceof v) {
|
|
2032
2040
|
const d = o.getObjects();
|
|
2033
|
-
for (let
|
|
2034
|
-
s.sendObjectToBack(d[
|
|
2041
|
+
for (let c = d.length - 1; c >= 0; c -= 1)
|
|
2042
|
+
s.sendObjectToBack(d[c]);
|
|
2035
2043
|
} else
|
|
2036
2044
|
s.sendObjectToBack(o);
|
|
2037
2045
|
s.sendObjectToBack(i), a && s.sendObjectToBack(a), s.renderAll(), n.resumeHistory(), t || n.saveState(), s.fire("editor:object-send-to-back", {
|
|
@@ -2070,14 +2078,14 @@ class P {
|
|
|
2070
2078
|
let a = -1;
|
|
2071
2079
|
for (let o = 0; o < s.length; o += 1) {
|
|
2072
2080
|
const d = s[o];
|
|
2073
|
-
if (!i.includes(d) && n.some((
|
|
2081
|
+
if (!i.includes(d) && n.some((c) => o > c)) {
|
|
2074
2082
|
a = o;
|
|
2075
2083
|
break;
|
|
2076
2084
|
}
|
|
2077
2085
|
}
|
|
2078
|
-
a !== -1 && i.map((d) => ({ obj: d, index: s.indexOf(d) })).sort((d,
|
|
2079
|
-
const
|
|
2080
|
-
|
|
2086
|
+
a !== -1 && i.map((d) => ({ obj: d, index: s.indexOf(d) })).sort((d, c) => c.index - d.index).forEach((d) => {
|
|
2087
|
+
const c = s.indexOf(d.obj);
|
|
2088
|
+
c < a && (e.moveObjectTo(d.obj, a), a = c);
|
|
2081
2089
|
});
|
|
2082
2090
|
}
|
|
2083
2091
|
/**
|
|
@@ -2091,7 +2099,7 @@ class P {
|
|
|
2091
2099
|
e.moveObjectTo(i[a], n - 1);
|
|
2092
2100
|
}
|
|
2093
2101
|
}
|
|
2094
|
-
class
|
|
2102
|
+
class nt {
|
|
2095
2103
|
/**
|
|
2096
2104
|
* Менеджер фигур для редактора.
|
|
2097
2105
|
* @param options - Опции и настройки менеджера фигур.
|
|
@@ -2115,7 +2123,7 @@ class it {
|
|
|
2115
2123
|
* @param flags.withoutSelection - Не выделять объект
|
|
2116
2124
|
* @param flags.withoutAdding - Не добавлять объект в canvas
|
|
2117
2125
|
*/
|
|
2118
|
-
addRectangle(l = {}, { withoutSelection: d, withoutAdding:
|
|
2126
|
+
addRectangle(l = {}, { withoutSelection: d, withoutAdding: c } = {}) {
|
|
2119
2127
|
var h = l, {
|
|
2120
2128
|
id: e = `rect-${D()}`,
|
|
2121
2129
|
left: t,
|
|
@@ -2139,7 +2147,7 @@ class it {
|
|
|
2139
2147
|
height: n,
|
|
2140
2148
|
fill: a
|
|
2141
2149
|
}, o));
|
|
2142
|
-
return !t && !s && g.centerObject(u),
|
|
2150
|
+
return !t && !s && g.centerObject(u), c || (g.add(u), d || g.setActiveObject(u), g.renderAll()), u;
|
|
2143
2151
|
}
|
|
2144
2152
|
/**
|
|
2145
2153
|
* Добавление круга
|
|
@@ -2157,8 +2165,8 @@ class it {
|
|
|
2157
2165
|
* @param flags.withoutSelection - Не выделять объект
|
|
2158
2166
|
* @param flags.withoutAdding - Не добавлять объект в canvas
|
|
2159
2167
|
*/
|
|
2160
|
-
addCircle(
|
|
2161
|
-
var l =
|
|
2168
|
+
addCircle(c = {}, { withoutSelection: o, withoutAdding: d } = {}) {
|
|
2169
|
+
var l = c, {
|
|
2162
2170
|
id: e = `circle-${D()}`,
|
|
2163
2171
|
left: t,
|
|
2164
2172
|
top: s,
|
|
@@ -2197,7 +2205,7 @@ class it {
|
|
|
2197
2205
|
* @param flags.withoutSelection - Не выделять объект
|
|
2198
2206
|
* @param flags.withoutAdding - Не добавлять объект в canvas
|
|
2199
2207
|
*/
|
|
2200
|
-
addTriangle(l = {}, { withoutSelection: d, withoutAdding:
|
|
2208
|
+
addTriangle(l = {}, { withoutSelection: d, withoutAdding: c } = {}) {
|
|
2201
2209
|
var h = l, {
|
|
2202
2210
|
id: e = `triangle-${D()}`,
|
|
2203
2211
|
left: t,
|
|
@@ -2221,10 +2229,10 @@ class it {
|
|
|
2221
2229
|
width: i,
|
|
2222
2230
|
height: n
|
|
2223
2231
|
}, o));
|
|
2224
|
-
return !t && !s && g.centerObject(u),
|
|
2232
|
+
return !t && !s && g.centerObject(u), c || (g.add(u), d || g.setActiveObject(u), g.renderAll()), u;
|
|
2225
2233
|
}
|
|
2226
2234
|
}
|
|
2227
|
-
class
|
|
2235
|
+
class at {
|
|
2228
2236
|
/**
|
|
2229
2237
|
* @param options
|
|
2230
2238
|
* @param options.editor - экземпляр редактора с доступом к canvas
|
|
@@ -2262,10 +2270,10 @@ class nt {
|
|
|
2262
2270
|
}), this._cloneAndFire(e, s);
|
|
2263
2271
|
return;
|
|
2264
2272
|
}
|
|
2265
|
-
const n = s.toCanvasElement().toDataURL(), a = n.slice(5).split(";")[0], o = n.split(",")[1], d = atob(o),
|
|
2273
|
+
const n = s.toCanvasElement().toDataURL(), a = n.slice(5).split(";")[0], o = n.split(",")[1], d = atob(o), c = new Uint8Array(d.length);
|
|
2266
2274
|
for (let g = 0; g < d.length; g += 1)
|
|
2267
|
-
|
|
2268
|
-
const l = new Blob([
|
|
2275
|
+
c[g] = d.charCodeAt(g);
|
|
2276
|
+
const l = new Blob([c.buffer], { type: a }), h = new ClipboardItem({ [a]: l });
|
|
2269
2277
|
navigator.clipboard.write([h]).catch((g) => {
|
|
2270
2278
|
t.emitWarning({
|
|
2271
2279
|
origin: "ClipboardManager",
|
|
@@ -2307,16 +2315,16 @@ class nt {
|
|
|
2307
2315
|
const o = i.getAsFile();
|
|
2308
2316
|
if (!o) return;
|
|
2309
2317
|
const d = new FileReader();
|
|
2310
|
-
d.onload = (
|
|
2311
|
-
|
|
2318
|
+
d.onload = (c) => {
|
|
2319
|
+
c.target && this.editor.imageManager.importImage({ source: c.target.result });
|
|
2312
2320
|
}, d.readAsDataURL(o);
|
|
2313
2321
|
return;
|
|
2314
2322
|
}
|
|
2315
2323
|
const n = e.getData("text/html");
|
|
2316
2324
|
if (n) {
|
|
2317
|
-
const
|
|
2318
|
-
if (
|
|
2319
|
-
t.importImage({ source:
|
|
2325
|
+
const c = new DOMParser().parseFromString(n, "text/html").querySelector("img");
|
|
2326
|
+
if (c != null && c.src) {
|
|
2327
|
+
t.importImage({ source: c.src });
|
|
2320
2328
|
return;
|
|
2321
2329
|
}
|
|
2322
2330
|
}
|
|
@@ -2367,8 +2375,8 @@ class F {
|
|
|
2367
2375
|
lockSkewingY: !0,
|
|
2368
2376
|
locked: !0
|
|
2369
2377
|
};
|
|
2370
|
-
a.set(o), !t && F._isGroupOrSelection(a) && a.getObjects().forEach((
|
|
2371
|
-
|
|
2378
|
+
a.set(o), !t && F._isGroupOrSelection(a) && a.getObjects().forEach((c) => {
|
|
2379
|
+
c.set(o);
|
|
2372
2380
|
}), i.renderAll(), s || n.saveState(), i.fire("editor:object-locked", {
|
|
2373
2381
|
object: a,
|
|
2374
2382
|
skipInnerObjects: t,
|
|
@@ -2406,7 +2414,7 @@ class F {
|
|
|
2406
2414
|
return e instanceof v || e instanceof X;
|
|
2407
2415
|
}
|
|
2408
2416
|
}
|
|
2409
|
-
class
|
|
2417
|
+
class ot {
|
|
2410
2418
|
constructor({ editor: e }) {
|
|
2411
2419
|
this.editor = e;
|
|
2412
2420
|
}
|
|
@@ -2459,7 +2467,7 @@ class at {
|
|
|
2459
2467
|
});
|
|
2460
2468
|
}
|
|
2461
2469
|
}
|
|
2462
|
-
class
|
|
2470
|
+
class rt {
|
|
2463
2471
|
constructor({ editor: e }) {
|
|
2464
2472
|
this.editor = e;
|
|
2465
2473
|
}
|
|
@@ -2474,7 +2482,7 @@ class ot {
|
|
|
2474
2482
|
n && s.lockObject({ object: a, skipInnerObjects: !0, withoutSave: !0 }), e.setActiveObject(a), e.requestRenderAll(), e.fire("editor:all-objects-selected", { selected: a });
|
|
2475
2483
|
}
|
|
2476
2484
|
}
|
|
2477
|
-
class
|
|
2485
|
+
class ct {
|
|
2478
2486
|
constructor({ editor: e }) {
|
|
2479
2487
|
this.editor = e;
|
|
2480
2488
|
}
|
|
@@ -2502,7 +2510,7 @@ class rt {
|
|
|
2502
2510
|
}));
|
|
2503
2511
|
}
|
|
2504
2512
|
}
|
|
2505
|
-
const
|
|
2513
|
+
const dt = {
|
|
2506
2514
|
IMAGE_MANAGER: {
|
|
2507
2515
|
/**
|
|
2508
2516
|
* Некорректный Content-Type изображения
|
|
@@ -2643,7 +2651,7 @@ class V {
|
|
|
2643
2651
|
* @returns true, если код допустим, иначе false
|
|
2644
2652
|
*/
|
|
2645
2653
|
static isValidErrorCode(e) {
|
|
2646
|
-
return e ? Object.values(
|
|
2654
|
+
return e ? Object.values(dt).some((t) => Object.values(t).includes(e)) : !1;
|
|
2647
2655
|
}
|
|
2648
2656
|
}
|
|
2649
2657
|
class ie {
|
|
@@ -2671,13 +2679,13 @@ class ie {
|
|
|
2671
2679
|
canvasCSSHeight: a,
|
|
2672
2680
|
initialImage: o,
|
|
2673
2681
|
initialStateJSON: d,
|
|
2674
|
-
scaleType:
|
|
2682
|
+
scaleType: c,
|
|
2675
2683
|
_onReadyCallback: l
|
|
2676
2684
|
} = this.options;
|
|
2677
|
-
if (
|
|
2685
|
+
if (He.apply(), this.canvas = new Ce(this.containerId, this.options), this.moduleLoader = new Ee(), this.workerManager = new Te(), this.errorManager = new V({ editor: this }), this.historyManager = new Je({ editor: this }), this.toolbar = new Qe({ editor: this }), this.transformManager = new st({ editor: this }), this.canvasManager = new tt({ editor: this }), this.imageManager = new N({ editor: this }), this.layerManager = new P({ editor: this }), this.shapeManager = new nt({ editor: this }), this.interactionBlocker = new it({ editor: this }), this.clipboardManager = new at({ editor: this }), this.objectLockManager = new F({ editor: this }), this.groupingManager = new ot({ editor: this }), this.selectionManager = new rt({ editor: this }), this.deletionManager = new ct({ editor: this }), this._createMontageArea(), this._createClippingArea(), this.listeners = new z({ editor: this, options: this.options }), this.canvasManager.setEditorContainerWidth(e), this.canvasManager.setEditorContainerHeight(t), this.canvasManager.setCanvasWrapperWidth(s), this.canvasManager.setCanvasWrapperHeight(i), this.canvasManager.setCanvasCSSWidth(n), this.canvasManager.setCanvasCSSHeight(a), o != null && o.source) {
|
|
2678
2686
|
const {
|
|
2679
2687
|
source: h,
|
|
2680
|
-
scale: g = `image-${
|
|
2688
|
+
scale: g = `image-${c}`,
|
|
2681
2689
|
withoutSave: u = !0
|
|
2682
2690
|
} = o;
|
|
2683
2691
|
yield this.imageManager.importImage({ source: h, scale: g, withoutSave: u });
|
|
@@ -2753,7 +2761,7 @@ class ie {
|
|
|
2753
2761
|
});
|
|
2754
2762
|
}
|
|
2755
2763
|
}
|
|
2756
|
-
const
|
|
2764
|
+
const lt = {
|
|
2757
2765
|
/**
|
|
2758
2766
|
* Опции редактора
|
|
2759
2767
|
*/
|
|
@@ -2841,18 +2849,18 @@ const dt = {
|
|
|
2841
2849
|
deleteObjectsByHotkey: !0,
|
|
2842
2850
|
resetObjectFitByDoubleClick: !0
|
|
2843
2851
|
};
|
|
2844
|
-
function
|
|
2845
|
-
const t = f(f({},
|
|
2852
|
+
function bt(r, e = {}) {
|
|
2853
|
+
const t = f(f({}, lt), e), s = document.getElementById(r);
|
|
2846
2854
|
if (!s)
|
|
2847
|
-
return Promise.reject(new Error(`Контейнер с ID "${
|
|
2855
|
+
return Promise.reject(new Error(`Контейнер с ID "${r}" не найден.`));
|
|
2848
2856
|
const i = document.createElement("canvas");
|
|
2849
|
-
return i.id = `${
|
|
2857
|
+
return i.id = `${r}-canvas`, s.appendChild(i), t.editorContainer = s, new Promise((n) => {
|
|
2850
2858
|
t._onReadyCallback = n;
|
|
2851
2859
|
const a = new ie(i.id, t);
|
|
2852
|
-
window[
|
|
2860
|
+
window[r] = a;
|
|
2853
2861
|
});
|
|
2854
2862
|
}
|
|
2855
2863
|
export {
|
|
2856
|
-
|
|
2864
|
+
bt as default
|
|
2857
2865
|
};
|
|
2858
2866
|
//# sourceMappingURL=main.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anu3ev/fabric-image-editor",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.51",
|
|
4
4
|
"description": "JavaScript image editor 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": [
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"dev:build": "vite build --watch --mode development --config vite.config.dev.js",
|
|
13
13
|
"prebuild": "npm install",
|
|
14
14
|
"build": "vite build --config vite.config.prod.js",
|
|
15
|
+
"build:docs": "vite build --config vite.config.docs.js",
|
|
15
16
|
"preview": "vite preview",
|
|
16
17
|
"lint": "eslint \"src/**/*.{js,ts}\""
|
|
17
18
|
},
|
|
@@ -50,5 +51,6 @@
|
|
|
50
51
|
"publishConfig": {
|
|
51
52
|
"access": "public"
|
|
52
53
|
},
|
|
54
|
+
"homepage": "https://Anu3ev.github.io/image-editor",
|
|
53
55
|
"license": "MIT"
|
|
54
56
|
}
|
package/dist/worker.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-restricted-globals */
|
|
2
|
-
|
|
3
|
-
self.onmessage = async(e: MessageEvent): Promise<void> => {
|
|
4
|
-
const { action, payload, requestId } = e.data
|
|
5
|
-
|
|
6
|
-
try {
|
|
7
|
-
switch (action) {
|
|
8
|
-
case 'resizeImage': {
|
|
9
|
-
const { dataURL, maxWidth, maxHeight, minWidth, minHeight, sizeType } = payload
|
|
10
|
-
const imgBitmap = await createImageBitmap(await (await fetch(dataURL)).blob())
|
|
11
|
-
|
|
12
|
-
// вычисляем новый размер
|
|
13
|
-
let { width, height } = imgBitmap
|
|
14
|
-
let ratio = Math.min(maxWidth / width, maxHeight / height)
|
|
15
|
-
|
|
16
|
-
if (sizeType === 'min') {
|
|
17
|
-
ratio = Math.max(minWidth / width, minHeight / height)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
width = Math.floor(width * ratio)
|
|
21
|
-
height = Math.floor(height * ratio)
|
|
22
|
-
|
|
23
|
-
// рисуем изображение в offscreen
|
|
24
|
-
const offscreen = new OffscreenCanvas(width, height)
|
|
25
|
-
const ctx = offscreen.getContext('2d')
|
|
26
|
-
|
|
27
|
-
if (!ctx) {
|
|
28
|
-
throw new Error('Failed to get 2D context from OffscreenCanvas')
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
ctx.drawImage(imgBitmap, 0, 0, width, height)
|
|
32
|
-
|
|
33
|
-
// конвертим в blob
|
|
34
|
-
const resizedBlob = await offscreen.convertToBlob()
|
|
35
|
-
|
|
36
|
-
self.postMessage({ requestId, action, success: true, data: resizedBlob })
|
|
37
|
-
break
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
case 'toDataURL': {
|
|
41
|
-
const { bitmap, format, quality, returnBlob } = payload
|
|
42
|
-
const { width, height } = bitmap
|
|
43
|
-
|
|
44
|
-
// рисуем изображение в offscreen
|
|
45
|
-
const off = new OffscreenCanvas(bitmap.width, bitmap.height)
|
|
46
|
-
const ctx = off.getContext('2d')
|
|
47
|
-
|
|
48
|
-
if (!ctx) {
|
|
49
|
-
throw new Error('Failed to get 2D context from OffscreenCanvas')
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
ctx.drawImage(bitmap, 0, 0, width, height)
|
|
53
|
-
|
|
54
|
-
// конвертируем в blob, а затем в dataURL
|
|
55
|
-
const blob = await off.convertToBlob({ type: format, quality })
|
|
56
|
-
|
|
57
|
-
if (returnBlob) {
|
|
58
|
-
self.postMessage({ requestId, action, success: true, data: blob })
|
|
59
|
-
break
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const dataURL = await new Promise((res) => {
|
|
63
|
-
const r = new FileReader()
|
|
64
|
-
r.onload = () => res(r.result)
|
|
65
|
-
r.readAsDataURL(blob)
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
self.postMessage({ requestId, action, success: true, data: dataURL })
|
|
69
|
-
break
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
default:
|
|
73
|
-
throw new Error(`Unknown action ${action}`)
|
|
74
|
-
}
|
|
75
|
-
} catch (err) {
|
|
76
|
-
self.postMessage({ requestId, action, success: false, error: (err as Error).message })
|
|
77
|
-
}
|
|
78
|
-
}
|