ablok-photobooth 0.2.42 → 0.2.44

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.
@@ -1,6 +1,6 @@
1
1
  import { _ as a } from "./chunks/photo-app.vue_vue_type_style_index_0_lang-BdQvhbLS.js";
2
- import { _ as e } from "./chunks/fabric-canvas.vue_vue_type_style_index_0_lang-B-D65X2t.js";
3
- import { _ as s } from "./chunks/creative-booth.vue_vue_type_style_index_0_lang-BHKoShl5.js";
2
+ import { _ as e } from "./chunks/fabric-canvas.vue_vue_type_style_index_0_lang-C9fwZf_Y.js";
3
+ import { _ as s } from "./chunks/creative-booth.vue_vue_type_style_index_0_lang-CRbsZZLr.js";
4
4
  import { _ as m } from "./chunks/face-swap.vue_vue_type_style_index_0_lang-B0EJ4Q3T.js";
5
5
  import { _ } from "./chunks/color-booth.vue_vue_type_style_index_0_lang-Cxo8ZMRt.js";
6
6
  export {
@@ -1,6 +1,6 @@
1
1
  import { defineComponent as x, ref as c, computed as l, watch as S, openBlock as u, createElementBlock as v, createElementVNode as h, createVNode as B, normalizeClass as M, createCommentVNode as b, createBlock as V } from "vue";
2
2
  import w from "ablok-components/components/molecules/media-thumbnails/media-thumbnails.vue";
3
- import { _ as A } from "./fabric-canvas.vue_vue_type_style_index_0_lang-B-D65X2t.js";
3
+ import { _ as A } from "./fabric-canvas.vue_vue_type_style_index_0_lang-C9fwZf_Y.js";
4
4
  const C = { class: "creative-booth" }, D = { class: "media-container" }, O = ["innerHTML"], E = { class: "creative-booth__thumbnails" }, F = [
5
5
  {
6
6
  type: "background",
@@ -0,0 +1,316 @@
1
+ import { defineComponent as Z, ref as j, watch as ee, onMounted as te, onUnmounted as ae, openBlock as ne, createElementBlock as oe, createElementVNode as M, renderSlot as re } from "vue";
2
+ import { debounce as ie } from "lodash";
3
+ function O(i) {
4
+ return new Promise((c, l) => {
5
+ i.oncomplete = i.onsuccess = () => c(i.result), i.onabort = i.onerror = () => l(i.error);
6
+ });
7
+ }
8
+ function se(i, c) {
9
+ const l = indexedDB.open(i);
10
+ l.onupgradeneeded = () => l.result.createObjectStore(c);
11
+ const d = O(l);
12
+ return (p, w) => d.then(
13
+ (u) => w(u.transaction(c, p).objectStore(c))
14
+ );
15
+ }
16
+ let _;
17
+ function A() {
18
+ return _ || (_ = se("keyval-store", "keyval")), _;
19
+ }
20
+ function le(i, c = A()) {
21
+ return c("readonly", (l) => O(l.get(i)));
22
+ }
23
+ function ce(i, c, l = A()) {
24
+ return l("readwrite", (d) => (d.put(c, i), O(d.transaction)));
25
+ }
26
+ function de(i, c = A()) {
27
+ return c("readwrite", (l) => (l.delete(i), O(l.transaction)));
28
+ }
29
+ const ue = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%20stroke='%23ffffffCC'%20stroke-width='2'%20stroke-linecap='round'%20stroke-linejoin='round'%20class='feather%20feather-rotate-cw'%3e%3cpolyline%20points='23%204%2023%2010%2017%2010'%3e%3c/polyline%3e%3cpath%20d='M20.49%2015a9%209%200%201%201-2.12-9.36L23%2010'%3e%3c/path%3e%3c/svg%3e", fe = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%20stroke='%23ffffffCC'%20stroke-width='2'%20stroke-linecap='round'%20stroke-linejoin='round'%20class='feather%20feather-x-circle'%3e%3ccircle%20cx='12'%20cy='12'%20r='10'%20fill='none'%3e%3c/circle%3e%3cline%20x1='15'%20y1='9'%20x2='9'%20y2='15'%20fill='none'%3e%3c/line%3e%3cline%20x1='9'%20y1='9'%20x2='15'%20y2='15'%20fill='none'%3e%3c/line%3e%3c/svg%3e", ge = { class: "fabric-canvas__canvas" }, me = {
30
+ id: "fabricCanvas",
31
+ ref: "canvasRef"
32
+ }, ye = /* @__PURE__ */ Z({
33
+ __name: "fabric-canvas",
34
+ props: {
35
+ modelValue: {
36
+ type: String,
37
+ default: ""
38
+ },
39
+ jsonModel: {
40
+ type: null,
41
+ default: void 0
42
+ },
43
+ exportToSvg: {
44
+ type: Boolean,
45
+ default: !1
46
+ },
47
+ resetState: {
48
+ type: Boolean,
49
+ default: !1
50
+ },
51
+ options: {
52
+ type: Object,
53
+ default: () => ({})
54
+ },
55
+ feature: {
56
+ type: String,
57
+ default: ""
58
+ },
59
+ required: {
60
+ type: Boolean,
61
+ default: !1
62
+ },
63
+ pending: {
64
+ type: Boolean,
65
+ default: !1
66
+ },
67
+ emitPending: {
68
+ type: Boolean,
69
+ default: !1
70
+ },
71
+ animationDuration: {
72
+ type: Number,
73
+ default: 0
74
+ }
75
+ },
76
+ emits: ["update:modelValue", "update:jsonModel", "update:pending", "on-ready"],
77
+ setup(i, { expose: c, emit: l }) {
78
+ let d, p, w, u, F, x, R, C;
79
+ const b = l;
80
+ c({ setBackgroundImage: N, setOverlayImage: X, addCanvasObject: Y });
81
+ const o = i, v = j(), f = j(0), g = j(0);
82
+ let a, E = !1;
83
+ const T = j();
84
+ async function G(e, t) {
85
+ return new Promise(async (n) => {
86
+ const r = JSON.parse(t);
87
+ if (r.backgroundImage) {
88
+ const s = await h(r.backgroundImage.src || r.backgroundImage.filename);
89
+ s.set({
90
+ opacity: 1
91
+ }), e.backgroundImage = s, e.centerObject(s);
92
+ }
93
+ if (r.overlayImage) {
94
+ const s = await h(r.overlayImage.src || r.overlayImage.filename);
95
+ s.set({
96
+ opacity: 1
97
+ }), e.overlayImage = D(s), e.centerObject(s);
98
+ }
99
+ (await u.enlivenObjects(r.objects, {
100
+ reviver: void 0
101
+ })).forEach((s) => {
102
+ e.add(s);
103
+ }), n(e);
104
+ });
105
+ }
106
+ async function h(e) {
107
+ const t = await B(e);
108
+ e.includes("data:image") || (t.filename = e);
109
+ const n = u.findScaleToCover(t, a), r = t instanceof p;
110
+ return t.set({
111
+ left: 0,
112
+ top: 0,
113
+ opacity: r && o.animationDuration > 0 ? 0 : 1,
114
+ scaleX: n,
115
+ scaleY: n,
116
+ src: e
117
+ }), t;
118
+ }
119
+ async function k(e) {
120
+ !(e instanceof p) || o.animationDuration === 0 || (o.emitPending && b("update:pending", !0), await new Promise((n) => {
121
+ const r = o.animationDuration, S = Date.now(), s = () => {
122
+ const I = Date.now() - S, m = Math.min(I / r, 1);
123
+ e.set("opacity", m), a.renderAll(), m < 1 ? requestAnimationFrame(s) : (o.emitPending && b("update:pending", !1), n());
124
+ };
125
+ requestAnimationFrame(s);
126
+ }));
127
+ }
128
+ function U(e) {
129
+ const t = u.findScaleToCover(e, a);
130
+ return e.set({
131
+ scaleX: t,
132
+ scaleY: t
133
+ }), e;
134
+ }
135
+ async function N(e) {
136
+ const t = await h(e.src);
137
+ a.backgroundImage = t, a.centerObject(t), a.renderAll(), await k(t), y();
138
+ }
139
+ function D(e) {
140
+ return e.set({
141
+ scaleX: f.value / e.width,
142
+ scaleY: g.value / e.height
143
+ }), e;
144
+ }
145
+ async function P(e) {
146
+ const t = await h(e.src);
147
+ t.selectable = !1, t.assetType = "foreground", a.add(t), a.centerObject(t), a.renderAll(), await k(t), y();
148
+ }
149
+ async function X(e) {
150
+ const t = await h(e.src);
151
+ a.overlayImage = D(t), a.centerObject(t), a.renderAll(), await k(t), y();
152
+ }
153
+ async function Y(e) {
154
+ a.discardActiveObject();
155
+ const t = await B(e.src);
156
+ t.filename = e.src;
157
+ const n = f.value / 3, r = g.value / 3, S = n / t.width, s = r / t.height, I = Math.min(S, s);
158
+ t.set({
159
+ scaleX: I,
160
+ scaleY: I,
161
+ left: f.value / 2,
162
+ top: g.value / 2
163
+ }), t.id = e.id, t.padding = 8, a.add(t), a.setActiveObject(t), await k(t), a.renderAll();
164
+ }
165
+ function L(e, t) {
166
+ t.target.id;
167
+ const n = t.target;
168
+ return a.remove(n), a.requestRenderAll(), !0;
169
+ }
170
+ function W() {
171
+ if (!(!v.value || !a)) {
172
+ if (f.value = v.value.offsetWidth, g.value = v.value.offsetHeight, a.setDimensions({ width: f.value, height: g.value }), a.backgroundImage && (a.backgroundImage = U(a.backgroundImage), a.centerObject(a.backgroundImage)), a.overlayImage) {
173
+ const e = a.overlayImage;
174
+ a.overlayImage = D(e), a.centerObject(e);
175
+ }
176
+ a.getObjects().forEach((e) => {
177
+ e.assetType === "foreground" && (e = U(e), a.centerObject(e));
178
+ }), a.renderAll();
179
+ }
180
+ }
181
+ const V = ie(() => {
182
+ W();
183
+ }, 200, { trailing: !0, leading: !1 });
184
+ function z(e) {
185
+ return (t, n, r, S, s) => {
186
+ t.save(), t.translate(n, r), t.rotate(u.degreesToRadians(s.angle)), t.fillStyle = o.options.themeData?.colors?.primary, t.fillRect(-24 / 2, -24 / 2, 24, 24);
187
+ const m = 20;
188
+ t.drawImage(e, -m / 2, -m / 2, m, m), t.restore();
189
+ };
190
+ }
191
+ function q() {
192
+ const e = document.createElement("img");
193
+ e.src = ue;
194
+ const t = document.createElement("img");
195
+ t.src = fe, a.on("object:added", (n) => {
196
+ n.target && n.target.controls && (n.target.set({
197
+ transparentCorners: !1,
198
+ cornerSize: 16,
199
+ cornerStyle: "circle",
200
+ ...o.options.themeData?.colors?.primary ? {
201
+ cornerColor: o.options.themeData?.colors?.primary,
202
+ cornerStrokeColor: o.options.themeData?.colors?.primary,
203
+ borderColor: o.options.themeData?.colors?.primary
204
+ } : {}
205
+ }), n.target.controls.ml.visible = !1, n.target.controls.mr.visible = !1, n.target.controls.mb.visible = !1, n.target.controls.mt.visible = !1, n.target.controls.mtr.visible = !1, n.target.controls.rotate = new w({
206
+ x: 0.5,
207
+ y: -0.5,
208
+ offsetX: 32,
209
+ offsetY: 0,
210
+ cursorStyle: "pointer",
211
+ actionName: "rotate",
212
+ actionHandler: C.rotationWithSnapping,
213
+ cursorStyleHandler: C.rotationStyleHandler,
214
+ render: z(e)
215
+ }), n.target.controls.delete = new w({
216
+ x: 0.5,
217
+ y: -0.5,
218
+ offsetX: 32,
219
+ offsetY: 32,
220
+ cursorStyle: "pointer",
221
+ mouseUpHandler: L,
222
+ render: z(t)
223
+ }));
224
+ });
225
+ }
226
+ async function J() {
227
+ return await new Promise((e) => {
228
+ setTimeout(() => {
229
+ const t = o.exportToSvg ? a.toSVG() : a.toDataURL({ multiplier: 2 });
230
+ e(t);
231
+ }, 200);
232
+ });
233
+ }
234
+ function y() {
235
+ setTimeout(async () => {
236
+ const e = a.toDatalessJSON(["selectable", "assetType", "filename"]);
237
+ await ce("fabric-canvas", JSON.stringify(e));
238
+ let t = !0;
239
+ if (o.required)
240
+ switch (t = !1, o.feature) {
241
+ case "overlay":
242
+ e.overlayImage && (t = !0);
243
+ break;
244
+ case "background":
245
+ e.backgroundImage && (t = !0);
246
+ break;
247
+ case "stickers":
248
+ e.objects.length > 1 && (t = !0);
249
+ break;
250
+ default:
251
+ (e.objects.length > 1 || e.backgroundImage || e.overlayImage) && (t = !0);
252
+ }
253
+ if (t) {
254
+ E = !0;
255
+ const n = await J();
256
+ b("update:modelValue", n), b("update:jsonModel", e);
257
+ }
258
+ }, 120);
259
+ }
260
+ async function $(e) {
261
+ try {
262
+ return await p.fromURL(e);
263
+ } catch (t) {
264
+ throw console.error("Error loading image:", t), t;
265
+ }
266
+ }
267
+ async function K(e) {
268
+ const { objects: t, options: n } = await F(e);
269
+ return u.groupSVGElements(t, n);
270
+ }
271
+ async function Q(e) {
272
+ const { objects: t, options: n } = await x(e);
273
+ return u.groupSVGElements(t, n);
274
+ }
275
+ async function B(e) {
276
+ return e && typeof e == "string" && e.trim().startsWith("<") ? await Q(e) : e && new RegExp(/([\w_/-]*\.svg$)|(image\/svg\+xml)/gi).test(e) ? await K(e) : await $(e);
277
+ }
278
+ async function H(e, t) {
279
+ e && !t && !E && await P({ src: e });
280
+ }
281
+ return ee(() => o.modelValue, async (e, t) => {
282
+ a && await H(e, t);
283
+ }), te(async () => {
284
+ ({ Canvas: d, FabricImage: p, Control: w, util: u, loadSVGFromURL: F, loadSVGFromString: x, config: R, controlsUtils: C } = await import("fabric")), f.value = v.value.offsetWidth, g.value = v.value.offsetHeight, window.addEventListener("resize", V), R.NUM_FRACTION_DIGITS = 8;
285
+ const e = d.prototype._onTouchStart;
286
+ d.prototype._onTouchStart = function(t) {
287
+ const n = this.findTarget(t);
288
+ this.allowTouchScrolling && n.assetType && !this.isDrawingMode || e.call(this, t);
289
+ }, a = new d("fabricCanvas", {
290
+ width: f.value,
291
+ height: g.value,
292
+ // enableRetinaScaling: false,
293
+ skipOffscreen: !0,
294
+ // devicePixelRatio: 4,
295
+ allowTouchScrolling: !0
296
+ // backstoreOnly: true
297
+ }), o.resetState && await de("fabric-canvas"), T.value = await le("fabric-canvas"), T.value ? (await G(a, T.value), a.requestRenderAll(), requestAnimationFrame(() => {
298
+ a.renderAll();
299
+ })) : o.modelValue && H(o.modelValue, ""), a.on("object:added", y), a.on("object:removed", y), a.on("object:modified", y), q(), a.renderAll(), b("on-ready", a);
300
+ }), ae(() => {
301
+ window.removeEventListener("resize", V);
302
+ }), (e, t) => (ne(), oe("div", {
303
+ class: "fabric-canvas",
304
+ ref_key: "root",
305
+ ref: v
306
+ }, [
307
+ M("div", ge, [
308
+ M("canvas", me, null, 512)
309
+ ]),
310
+ re(e.$slots, "default")
311
+ ], 512));
312
+ }
313
+ });
314
+ export {
315
+ ye as _
316
+ };
@@ -1,5 +1,5 @@
1
- import { _ as o } from "./chunks/creative-booth.vue_vue_type_style_index_0_lang-BHKoShl5.js";
2
- import { D as m } from "./chunks/creative-booth.vue_vue_type_style_index_0_lang-BHKoShl5.js";
1
+ import { _ as o } from "./chunks/creative-booth.vue_vue_type_style_index_0_lang-CRbsZZLr.js";
2
+ import { D as m } from "./chunks/creative-booth.vue_vue_type_style_index_0_lang-CRbsZZLr.js";
3
3
  export {
4
4
  m as DEFAULT_ASSETS,
5
5
  o as default
@@ -1,4 +1,4 @@
1
- import { _ as f } from "./chunks/fabric-canvas.vue_vue_type_style_index_0_lang-B-D65X2t.js";
1
+ import { _ as f } from "./chunks/fabric-canvas.vue_vue_type_style_index_0_lang-C9fwZf_Y.js";
2
2
  export {
3
3
  f as default
4
4
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ablok-photobooth",
3
3
  "private": false,
4
- "version": "0.2.42",
4
+ "version": "0.2.44",
5
5
  "type": "module",
6
6
  "peerDependencies": {
7
7
  "@popperjs/core": "^2.11.6",
@@ -1,318 +0,0 @@
1
- import { defineComponent as Q, ref as j, watch as Z, onMounted as ee, openBlock as te, createElementBlock as ae, createElementVNode as B, renderSlot as oe } from "vue";
2
- import { debounce as ne } from "lodash";
3
- function C(s) {
4
- return new Promise((c, l) => {
5
- s.oncomplete = s.onsuccess = () => c(s.result), s.onabort = s.onerror = () => l(s.error);
6
- });
7
- }
8
- function re(s, c) {
9
- const l = indexedDB.open(s);
10
- l.onupgradeneeded = () => l.result.createObjectStore(c);
11
- const f = C(l);
12
- return (p, y) => f.then(
13
- (g) => y(g.transaction(c, p).objectStore(c))
14
- );
15
- }
16
- let D;
17
- function _() {
18
- return D || (D = re("keyval-store", "keyval")), D;
19
- }
20
- function ie(s, c = _()) {
21
- return c("readonly", (l) => C(l.get(s)));
22
- }
23
- function se(s, c, l = _()) {
24
- return l("readwrite", (f) => (f.put(c, s), C(f.transaction)));
25
- }
26
- function le(s, c = _()) {
27
- return c("readwrite", (l) => (l.delete(s), C(l.transaction)));
28
- }
29
- const ce = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%20stroke='%23ffffffCC'%20stroke-width='2'%20stroke-linecap='round'%20stroke-linejoin='round'%20class='feather%20feather-rotate-cw'%3e%3cpolyline%20points='23%204%2023%2010%2017%2010'%3e%3c/polyline%3e%3cpath%20d='M20.49%2015a9%209%200%201%201-2.12-9.36L23%2010'%3e%3c/path%3e%3c/svg%3e", de = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%20stroke='%23ffffffCC'%20stroke-width='2'%20stroke-linecap='round'%20stroke-linejoin='round'%20class='feather%20feather-x-circle'%3e%3ccircle%20cx='12'%20cy='12'%20r='10'%20fill='none'%3e%3c/circle%3e%3cline%20x1='15'%20y1='9'%20x2='9'%20y2='15'%20fill='none'%3e%3c/line%3e%3cline%20x1='9'%20y1='9'%20x2='15'%20y2='15'%20fill='none'%3e%3c/line%3e%3c/svg%3e", ue = { class: "fabric-canvas__canvas" }, fe = {
30
- id: "fabricCanvas",
31
- ref: "canvasRef"
32
- }, pe = /* @__PURE__ */ Q({
33
- __name: "fabric-canvas",
34
- props: {
35
- modelValue: {
36
- type: String,
37
- default: ""
38
- },
39
- jsonModel: {
40
- type: null,
41
- default: void 0
42
- },
43
- exportToSvg: {
44
- type: Boolean,
45
- default: !1
46
- },
47
- resetState: {
48
- type: Boolean,
49
- default: !1
50
- },
51
- options: {
52
- type: Object,
53
- default: () => ({})
54
- },
55
- feature: {
56
- type: String,
57
- default: ""
58
- },
59
- required: {
60
- type: Boolean,
61
- default: !1
62
- },
63
- pending: {
64
- type: Boolean,
65
- default: !1
66
- },
67
- emitPending: {
68
- type: Boolean,
69
- default: !1
70
- },
71
- animationDuration: {
72
- type: Number,
73
- default: 0
74
- }
75
- },
76
- emits: ["update:modelValue", "update:jsonModel", "update:pending", "on-ready"],
77
- setup(s, { expose: c, emit: l }) {
78
- let f, p, y, g, A, F, x, O;
79
- const h = l;
80
- c({ setBackgroundImage: M, setOverlayImage: Y, addCanvasObject: G });
81
- const n = s, w = j(), d = j(0), u = j(0);
82
- let a, R = !1;
83
- const T = j();
84
- async function H(e, t) {
85
- return new Promise(async (o) => {
86
- const r = JSON.parse(t);
87
- if (r.backgroundImage) {
88
- const i = await b(r.backgroundImage.src || r.backgroundImage.filename);
89
- i.set({
90
- opacity: 1
91
- }), e.backgroundImage = i, e.centerObject(i);
92
- }
93
- if (r.overlayImage) {
94
- const i = await b(r.overlayImage.src || r.overlayImage.filename);
95
- i.set({
96
- opacity: 1,
97
- left: d.value / 2,
98
- top: u.value / 2,
99
- scaleX: d.value / i.width,
100
- scaleY: u.value / i.height
101
- }), e.overlayImage = i;
102
- }
103
- (await g.enlivenObjects(r.objects, {
104
- reviver: void 0
105
- })).forEach((i) => {
106
- e.add(i);
107
- }), o(e);
108
- });
109
- }
110
- async function b(e) {
111
- const t = await U(e);
112
- e.includes("data:image") || (t.filename = e);
113
- const o = g.findScaleToCover(t, a), r = t instanceof p;
114
- return t.set({
115
- left: 0,
116
- top: 0,
117
- opacity: r && n.animationDuration > 0 ? 0 : 1,
118
- scaleX: o,
119
- scaleY: o,
120
- src: e
121
- }), t;
122
- }
123
- async function k(e) {
124
- !(e instanceof p) || n.animationDuration === 0 || (n.emitPending && h("update:pending", !0), await new Promise((o) => {
125
- const r = n.animationDuration, S = Date.now(), i = () => {
126
- const I = Date.now() - S, m = Math.min(I / r, 1);
127
- e.set("opacity", m), a.renderAll(), m < 1 ? requestAnimationFrame(i) : (n.emitPending && h("update:pending", !1), o());
128
- };
129
- requestAnimationFrame(i);
130
- }));
131
- }
132
- function V(e) {
133
- const t = g.findScaleToCover(e, a);
134
- return e.set({
135
- scaleX: t,
136
- scaleY: t
137
- }), e;
138
- }
139
- async function M(e) {
140
- const t = await b(e.src);
141
- a.backgroundImage = t, a.centerObject(t), a.renderAll(), await k(t), v();
142
- }
143
- async function X(e) {
144
- const t = await b(e.src);
145
- t.selectable = !1, t.assetType = "foreground", a.add(t), a.centerObject(t), a.renderAll(), await k(t), v();
146
- }
147
- async function Y(e) {
148
- const t = await b(e.src);
149
- t.set({
150
- left: d.value / 2,
151
- top: u.value / 2,
152
- scaleX: d.value / t.width,
153
- scaleY: u.value / t.height
154
- }), a.overlayImage = t, a.renderAll(), await k(t), v();
155
- }
156
- async function G(e) {
157
- a.discardActiveObject();
158
- const t = await U(e.src);
159
- t.filename = e.src;
160
- const o = d.value / 3, r = u.value / 3, S = o / t.width, i = r / t.height, I = Math.min(S, i);
161
- t.set({
162
- scaleX: I,
163
- scaleY: I,
164
- left: d.value / 2,
165
- top: u.value / 2
166
- }), t.id = e.id, t.padding = 8, a.add(t), a.setActiveObject(t), await k(t), a.renderAll();
167
- }
168
- function N(e, t) {
169
- t.target.id;
170
- const o = t.target;
171
- return a.remove(o), a.requestRenderAll(), !0;
172
- }
173
- function P() {
174
- if (d.value = w.value.offsetWidth, u.value = w.value.offsetHeight, a.setDimensions({ width: d.value, height: u.value }), a.backgroundImage && (a.backgroundImage = V(a.backgroundImage), a.centerObject(a.backgroundImage)), a.overlayImage) {
175
- const e = a.overlayImage;
176
- e.set({
177
- scaleX: d.value / e.width,
178
- scaleY: u.value / e.height
179
- });
180
- }
181
- a.getObjects().forEach((e) => {
182
- e.assetType === "foreground" && (e = V(e), a.centerObject(e));
183
- }), a.renderAll();
184
- }
185
- const L = ne(() => {
186
- P();
187
- }, 200, { trailing: !0, leading: !1 });
188
- function E(e) {
189
- return (t, o, r, S, i) => {
190
- t.save(), t.translate(o, r), t.rotate(g.degreesToRadians(i.angle)), t.fillStyle = n.options.themeData?.colors?.primary, t.fillRect(-24 / 2, -24 / 2, 24, 24);
191
- const m = 20;
192
- t.drawImage(e, -m / 2, -m / 2, m, m), t.restore();
193
- };
194
- }
195
- function W() {
196
- const e = document.createElement("img");
197
- e.src = ce;
198
- const t = document.createElement("img");
199
- t.src = de, a.on("object:added", (o) => {
200
- o.target && o.target.controls && (o.target.set({
201
- transparentCorners: !1,
202
- cornerSize: 16,
203
- cornerStyle: "circle",
204
- ...n.options.themeData?.colors?.primary ? {
205
- cornerColor: n.options.themeData?.colors?.primary,
206
- cornerStrokeColor: n.options.themeData?.colors?.primary,
207
- borderColor: n.options.themeData?.colors?.primary
208
- } : {}
209
- }), o.target.controls.ml.visible = !1, o.target.controls.mr.visible = !1, o.target.controls.mb.visible = !1, o.target.controls.mt.visible = !1, o.target.controls.mtr.visible = !1, o.target.controls.rotate = new y({
210
- x: 0.5,
211
- y: -0.5,
212
- offsetX: 32,
213
- offsetY: 0,
214
- cursorStyle: "pointer",
215
- actionName: "rotate",
216
- actionHandler: O.rotationWithSnapping,
217
- cursorStyleHandler: O.rotationStyleHandler,
218
- render: E(e)
219
- }), o.target.controls.delete = new y({
220
- x: 0.5,
221
- y: -0.5,
222
- offsetX: 32,
223
- offsetY: 32,
224
- cursorStyle: "pointer",
225
- mouseUpHandler: N,
226
- render: E(t)
227
- }));
228
- });
229
- }
230
- async function q() {
231
- return await new Promise((e) => {
232
- setTimeout(() => {
233
- const t = n.exportToSvg ? a.toSVG() : a.toDataURL({ multiplier: 2 });
234
- e(t);
235
- }, 200);
236
- });
237
- }
238
- function v() {
239
- setTimeout(async () => {
240
- const e = a.toDatalessJSON(["selectable", "assetType", "filename"]);
241
- await se("fabric-canvas", JSON.stringify(e));
242
- let t = !0;
243
- if (n.required)
244
- switch (t = !1, n.feature) {
245
- case "overlay":
246
- e.overlayImage && (t = !0);
247
- break;
248
- case "background":
249
- e.backgroundImage && (t = !0);
250
- break;
251
- case "stickers":
252
- e.objects.length > 1 && (t = !0);
253
- break;
254
- default:
255
- (e.objects.length > 1 || e.backgroundImage || e.overlayImage) && (t = !0);
256
- }
257
- if (t) {
258
- R = !0;
259
- const o = await q();
260
- h("update:modelValue", o), h("update:jsonModel", e);
261
- }
262
- }, 120);
263
- }
264
- async function J(e) {
265
- try {
266
- return await p.fromURL(e);
267
- } catch (t) {
268
- throw console.error("Error loading image:", t), t;
269
- }
270
- }
271
- async function $(e) {
272
- const { objects: t, options: o } = await A(e);
273
- return g.groupSVGElements(t, o);
274
- }
275
- async function K(e) {
276
- const { objects: t, options: o } = await F(e);
277
- return g.groupSVGElements(t, o);
278
- }
279
- async function U(e) {
280
- return e && typeof e == "string" && e.trim().startsWith("<") ? await K(e) : e && new RegExp(/([\w_/-]*\.svg$)|(image\/svg\+xml)/gi).test(e) ? await $(e) : await J(e);
281
- }
282
- async function z(e, t) {
283
- e && !t && !R && X({ src: e });
284
- }
285
- return Z(() => n.modelValue, async (e, t) => {
286
- z(e, t);
287
- }), ee(async () => {
288
- ({ Canvas: f, FabricImage: p, Control: y, util: g, loadSVGFromURL: A, loadSVGFromString: F, config: x, controlsUtils: O } = await import("fabric")), d.value = w.value.offsetWidth, u.value = w.value.offsetHeight, window.addEventListener("resize", L), x.NUM_FRACTION_DIGITS = 8;
289
- const e = f.prototype._onTouchStart;
290
- f.prototype._onTouchStart = function(t) {
291
- const o = this.findTarget(t);
292
- this.allowTouchScrolling && o.assetType && !this.isDrawingMode || e.call(this, t);
293
- }, a = new f("fabricCanvas", {
294
- width: d.value,
295
- height: u.value,
296
- // enableRetinaScaling: false,
297
- skipOffscreen: !0,
298
- // devicePixelRatio: 4,
299
- allowTouchScrolling: !0
300
- // backstoreOnly: true
301
- }), n.resetState && await le("fabric-canvas"), T.value = await ie("fabric-canvas"), T.value ? (await H(a, T.value), a.requestRenderAll(), requestAnimationFrame(() => {
302
- a.renderAll();
303
- })) : n.modelValue && z(n.modelValue, ""), a.on("object:added", v), a.on("object:removed", v), a.on("object:modified", v), W(), a.renderAll(), h("on-ready", a);
304
- }), (e, t) => (te(), ae("div", {
305
- class: "fabric-canvas",
306
- ref_key: "root",
307
- ref: w
308
- }, [
309
- B("div", ue, [
310
- B("canvas", fe, null, 512)
311
- ]),
312
- oe(e.$slots, "default")
313
- ], 512));
314
- }
315
- });
316
- export {
317
- pe as _
318
- };