@servantcdh/ez-planet-labeling 0.3.2 → 0.4.0

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,788 +0,0 @@
1
- import * as k from "fabric";
2
- import { classRegistry as ye, LayoutManager as ge, FixedLayout as me, Path as be, Group as $ } from "fabric";
3
- function te(t, e) {
4
- this.v = t, this.k = e;
5
- }
6
- function W(t, e) {
7
- (e == null || e > t.length) && (e = t.length);
8
- for (var r = 0, n = Array(e); r < e; r++) n[r] = t[r];
9
- return n;
10
- }
11
- function we(t) {
12
- if (Array.isArray(t)) return t;
13
- }
14
- function Pe(t) {
15
- if (Array.isArray(t)) return W(t);
16
- }
17
- function x(t) {
18
- if (t === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
19
- return t;
20
- }
21
- function H(t, e, r, n, a, o, u) {
22
- try {
23
- var i = t[o](u), c = i.value;
24
- } catch (s) {
25
- return void r(s);
26
- }
27
- i.done ? e(c) : Promise.resolve(c).then(n, a);
28
- }
29
- function G(t) {
30
- return function() {
31
- var e = this, r = arguments;
32
- return new Promise(function(n, a) {
33
- var o = t.apply(e, r);
34
- function u(c) {
35
- H(o, n, a, u, i, "next", c);
36
- }
37
- function i(c) {
38
- H(o, n, a, u, i, "throw", c);
39
- }
40
- u(void 0);
41
- });
42
- };
43
- }
44
- function re(t, e, r) {
45
- return e = _(e), Te(t, oe() ? Reflect.construct(e, r || [], _(t).constructor) : e.apply(t, r));
46
- }
47
- function ne(t, e) {
48
- if (!(t instanceof e)) throw new TypeError("Cannot call a class as a function");
49
- }
50
- function Oe(t, e) {
51
- for (var r = 0; r < e.length; r++) {
52
- var n = e[r];
53
- n.enumerable = n.enumerable || !1, n.configurable = !0, "value" in n && (n.writable = !0), Object.defineProperty(t, se(n.key), n);
54
- }
55
- }
56
- function ae(t, e, r) {
57
- return e && Oe(t.prototype, e), Object.defineProperty(t, "prototype", {
58
- writable: !1
59
- }), t;
60
- }
61
- function M(t, e, r) {
62
- return (e = se(e)) in t ? Object.defineProperty(t, e, {
63
- value: r,
64
- enumerable: !0,
65
- configurable: !0,
66
- writable: !0
67
- }) : t[e] = r, t;
68
- }
69
- function T() {
70
- return T = typeof Reflect < "u" && Reflect.get ? Reflect.get.bind() : function(t, e, r) {
71
- var n = Ge(t, e);
72
- if (n) {
73
- var a = Object.getOwnPropertyDescriptor(n, e);
74
- return a.get ? a.get.call(arguments.length < 3 ? t : r) : a.value;
75
- }
76
- }, T.apply(null, arguments);
77
- }
78
- function _(t) {
79
- return _ = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function(e) {
80
- return e.__proto__ || Object.getPrototypeOf(e);
81
- }, _(t);
82
- }
83
- function ie(t, e) {
84
- if (typeof e != "function" && e !== null) throw new TypeError("Super expression must either be null or a function");
85
- t.prototype = Object.create(e && e.prototype, {
86
- constructor: {
87
- value: t,
88
- writable: !0,
89
- configurable: !0
90
- }
91
- }), Object.defineProperty(t, "prototype", {
92
- writable: !1
93
- }), e && Y(t, e);
94
- }
95
- function oe() {
96
- try {
97
- var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {
98
- }));
99
- } catch {
100
- }
101
- return (oe = function() {
102
- return !!t;
103
- })();
104
- }
105
- function _e(t) {
106
- if (typeof Symbol < "u" && t[Symbol.iterator] != null || t["@@iterator"] != null) return Array.from(t);
107
- }
108
- function Ee(t, e) {
109
- var r = t == null ? null : typeof Symbol < "u" && t[Symbol.iterator] || t["@@iterator"];
110
- if (r != null) {
111
- var n, a, o, u, i = [], c = !0, s = !1;
112
- try {
113
- if (o = (r = r.call(t)).next, e === 0) {
114
- if (Object(r) !== r) return;
115
- c = !1;
116
- } else for (; !(c = (n = o.call(r)).done) && (i.push(n.value), i.length !== e); c = !0) ;
117
- } catch (f) {
118
- s = !0, a = f;
119
- } finally {
120
- try {
121
- if (!c && r.return != null && (u = r.return(), Object(u) !== u)) return;
122
- } finally {
123
- if (s) throw a;
124
- }
125
- }
126
- return i;
127
- }
128
- }
129
- function ke() {
130
- throw new TypeError(`Invalid attempt to destructure non-iterable instance.
131
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`);
132
- }
133
- function Ce() {
134
- throw new TypeError(`Invalid attempt to spread non-iterable instance.
135
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`);
136
- }
137
- function q(t, e) {
138
- var r = Object.keys(t);
139
- if (Object.getOwnPropertySymbols) {
140
- var n = Object.getOwnPropertySymbols(t);
141
- e && (n = n.filter(function(a) {
142
- return Object.getOwnPropertyDescriptor(t, a).enumerable;
143
- })), r.push.apply(r, n);
144
- }
145
- return r;
146
- }
147
- function Se(t) {
148
- for (var e = 1; e < arguments.length; e++) {
149
- var r = arguments[e] != null ? arguments[e] : {};
150
- e % 2 ? q(Object(r), !0).forEach(function(n) {
151
- M(t, n, r[n]);
152
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(t, Object.getOwnPropertyDescriptors(r)) : q(Object(r)).forEach(function(n) {
153
- Object.defineProperty(t, n, Object.getOwnPropertyDescriptor(r, n));
154
- });
155
- }
156
- return t;
157
- }
158
- function Te(t, e) {
159
- if (e && (typeof e == "object" || typeof e == "function")) return e;
160
- if (e !== void 0) throw new TypeError("Derived constructors may only return object or undefined");
161
- return x(t);
162
- }
163
- function z() {
164
- /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
165
- var t, e, r = typeof Symbol == "function" ? Symbol : {}, n = r.iterator || "@@iterator", a = r.toStringTag || "@@toStringTag";
166
- function o(y, l, w, D) {
167
- var P = l && l.prototype instanceof i ? l : i, K = Object.create(P.prototype);
168
- return d(K, "_invoke", function(he, ve, de) {
169
- var S, h, g, F = 0, Q = de || [], A = !1, C = {
170
- p: 0,
171
- n: 0,
172
- v: t,
173
- a: N,
174
- f: N.bind(t, 4),
175
- d: function(O, m) {
176
- return S = O, h = 0, g = t, C.n = m, u;
177
- }
178
- };
179
- function N(O, m) {
180
- for (h = O, g = m, e = 0; !A && F && !j && e < Q.length; e++) {
181
- var j, b = Q[e], L = C.p, B = b[2];
182
- O > 3 ? (j = B === m) && (g = b[(h = b[4]) ? 5 : (h = 3, 3)], b[4] = b[5] = t) : b[0] <= L && ((j = O < 2 && L < b[1]) ? (h = 0, C.v = m, C.n = b[1]) : L < B && (j = O < 3 || b[0] > m || m > B) && (b[4] = O, b[5] = m, C.n = B, h = 0));
183
- }
184
- if (j || O > 1) return u;
185
- throw A = !0, m;
186
- }
187
- return function(O, m, j) {
188
- if (F > 1) throw TypeError("Generator is already running");
189
- for (A && m === 1 && N(m, j), h = m, g = j; (e = h < 2 ? t : g) || !A; ) {
190
- S || (h ? h < 3 ? (h > 1 && (C.n = -1), N(h, g)) : C.n = g : C.v = g);
191
- try {
192
- if (F = 2, S) {
193
- if (h || (O = "next"), e = S[O]) {
194
- if (!(e = e.call(S, g))) throw TypeError("iterator result is not an object");
195
- if (!e.done) return e;
196
- g = e.value, h < 2 && (h = 0);
197
- } else h === 1 && (e = S.return) && e.call(S), h < 2 && (g = TypeError("The iterator does not provide a '" + O + "' method"), h = 1);
198
- S = t;
199
- } else if ((e = (A = C.n < 0) ? g : he.call(ve, C)) !== u) break;
200
- } catch (b) {
201
- S = t, h = 1, g = b;
202
- } finally {
203
- F = 1;
204
- }
205
- }
206
- return {
207
- value: e,
208
- done: A
209
- };
210
- };
211
- }(y, w, D), !0), K;
212
- }
213
- var u = {};
214
- function i() {
215
- }
216
- function c() {
217
- }
218
- function s() {
219
- }
220
- e = Object.getPrototypeOf;
221
- var f = [][n] ? e(e([][n]())) : (d(e = {}, n, function() {
222
- return this;
223
- }), e), p = s.prototype = i.prototype = Object.create(f);
224
- function v(y) {
225
- return Object.setPrototypeOf ? Object.setPrototypeOf(y, s) : (y.__proto__ = s, d(y, a, "GeneratorFunction")), y.prototype = Object.create(p), y;
226
- }
227
- return c.prototype = s, d(p, "constructor", s), d(s, "constructor", c), c.displayName = "GeneratorFunction", d(s, a, "GeneratorFunction"), d(p), d(p, a, "Generator"), d(p, n, function() {
228
- return this;
229
- }), d(p, "toString", function() {
230
- return "[object Generator]";
231
- }), (z = function() {
232
- return {
233
- w: o,
234
- m: v
235
- };
236
- })();
237
- }
238
- function je(t, e, r, n, a) {
239
- var o = ue(t, e, r, n, a);
240
- return o.next().then(function(u) {
241
- return u.done ? u.value : o.next();
242
- });
243
- }
244
- function ue(t, e, r, n, a) {
245
- return new V(z().w(t, e, r, n), a || Promise);
246
- }
247
- function V(t, e) {
248
- function r(a, o, u, i) {
249
- try {
250
- var c = t[a](o), s = c.value;
251
- return s instanceof te ? e.resolve(s.v).then(function(f) {
252
- r("next", f, u, i);
253
- }, function(f) {
254
- r("throw", f, u, i);
255
- }) : e.resolve(s).then(function(f) {
256
- c.value = f, u(c);
257
- }, function(f) {
258
- return r("throw", f, u, i);
259
- });
260
- } catch (f) {
261
- i(f);
262
- }
263
- }
264
- var n;
265
- this.next || (d(V.prototype), d(V.prototype, typeof Symbol == "function" && Symbol.asyncIterator || "@asyncIterator", function() {
266
- return this;
267
- })), d(this, "_invoke", function(a, o, u) {
268
- function i() {
269
- return new e(function(c, s) {
270
- r(a, u, c, s);
271
- });
272
- }
273
- return n = n ? n.then(i, i) : i();
274
- }, !0);
275
- }
276
- function d(t, e, r, n) {
277
- var a = Object.defineProperty;
278
- try {
279
- a({}, "", {});
280
- } catch {
281
- a = 0;
282
- }
283
- d = function(o, u, i, c) {
284
- function s(f, p) {
285
- d(o, f, function(v) {
286
- return this._invoke(f, p, v);
287
- });
288
- }
289
- u ? a ? a(o, u, {
290
- value: i,
291
- enumerable: !c,
292
- configurable: !c,
293
- writable: !c
294
- }) : o[u] = i : (s("next", 0), s("throw", 1), s("return", 2));
295
- }, d(t, e, r, n);
296
- }
297
- function Ae(t) {
298
- var e = Object(t), r = [];
299
- for (var n in e) r.unshift(n);
300
- return function a() {
301
- for (; r.length; ) if ((n = r.pop()) in e) return a.value = n, a.done = !1, a;
302
- return a.done = !0, a;
303
- };
304
- }
305
- function J(t) {
306
- if (t != null) {
307
- var e = t[typeof Symbol == "function" && Symbol.iterator || "@@iterator"], r = 0;
308
- if (e) return e.call(t);
309
- if (typeof t.next == "function") return t;
310
- if (!isNaN(t.length)) return {
311
- next: function() {
312
- return t && r >= t.length && (t = void 0), {
313
- value: t && t[r++],
314
- done: !t
315
- };
316
- }
317
- };
318
- }
319
- throw new TypeError(typeof t + " is not iterable");
320
- }
321
- function Y(t, e) {
322
- return Y = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(r, n) {
323
- return r.__proto__ = n, r;
324
- }, Y(t, e);
325
- }
326
- function Z(t, e) {
327
- return we(t) || Ee(t, e) || ce(t, e) || ke();
328
- }
329
- function Ge(t, e) {
330
- for (; !{}.hasOwnProperty.call(t, e) && (t = _(t)) !== null; ) ;
331
- return t;
332
- }
333
- function I(t) {
334
- return Pe(t) || _e(t) || ce(t) || Ce();
335
- }
336
- function Me(t, e) {
337
- if (typeof t != "object" || !t) return t;
338
- var r = t[Symbol.toPrimitive];
339
- if (r !== void 0) {
340
- var n = r.call(t, e);
341
- if (typeof n != "object") return n;
342
- throw new TypeError("@@toPrimitive must return a primitive value.");
343
- }
344
- return (e === "string" ? String : Number)(t);
345
- }
346
- function se(t) {
347
- var e = Me(t, "string");
348
- return typeof e == "symbol" ? e : e + "";
349
- }
350
- function ce(t, e) {
351
- if (t) {
352
- if (typeof t == "string") return W(t, e);
353
- var r = {}.toString.call(t).slice(8, -1);
354
- return r === "Object" && t.constructor && (r = t.constructor.name), r === "Map" || r === "Set" ? Array.from(t) : r === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r) ? W(t, e) : void 0;
355
- }
356
- }
357
- function E() {
358
- var t = z(), e = t.m(E), r = (Object.getPrototypeOf ? Object.getPrototypeOf(e) : e.__proto__).constructor;
359
- function n(u) {
360
- var i = typeof u == "function" && u.constructor;
361
- return !!i && (i === r || (i.displayName || i.name) === "GeneratorFunction");
362
- }
363
- var a = {
364
- throw: 1,
365
- return: 2,
366
- break: 3,
367
- continue: 3
368
- };
369
- function o(u) {
370
- var i, c;
371
- return function(s) {
372
- i || (i = {
373
- stop: function() {
374
- return c(s.a, 2);
375
- },
376
- catch: function() {
377
- return s.v;
378
- },
379
- abrupt: function(f, p) {
380
- return c(s.a, a[f], p);
381
- },
382
- delegateYield: function(f, p, v) {
383
- return i.resultName = p, c(s.d, J(f), v);
384
- },
385
- finish: function(f) {
386
- return c(s.f, f);
387
- }
388
- }, c = function(f, p, v) {
389
- s.p = i.prev, s.n = i.next;
390
- try {
391
- return f(p, v);
392
- } finally {
393
- i.next = s.n;
394
- }
395
- }), i.resultName && (i[i.resultName] = s.v, i.resultName = void 0), i.sent = s.v, i.next = s.n;
396
- try {
397
- return u.call(this, i);
398
- } finally {
399
- s.p = i.prev, s.n = i.next;
400
- }
401
- };
402
- }
403
- return (E = function() {
404
- return {
405
- wrap: function(u, i, c, s) {
406
- return t.w(o(u), i, c, s && s.reverse());
407
- },
408
- isGeneratorFunction: n,
409
- mark: t.m,
410
- awrap: function(u, i) {
411
- return new te(u, i);
412
- },
413
- AsyncIterator: V,
414
- async: function(u, i, c, s, f) {
415
- return (n(i) ? ue : je)(o(u), i, c, s, f);
416
- },
417
- keys: Ae,
418
- values: J
419
- };
420
- })();
421
- }
422
- var R = /* @__PURE__ */ function(t) {
423
- ie(e, t);
424
- function e(r, n) {
425
- var a;
426
- return ne(this, e), a = re(this, e, [r, Se({
427
- originX: "center",
428
- originY: "center",
429
- left: 0,
430
- top: 0,
431
- layoutManager: new ge(new me())
432
- }, n)]), M(x(a), "blockErasing", !1), a;
433
- }
434
- return ae(e, [{
435
- key: "drawObject",
436
- value: function(n) {
437
- var a = [], o = [];
438
- this._objects.forEach(function(u) {
439
- return (u instanceof be ? a : o).push(u);
440
- }), n.save(), n.fillStyle = "black", n.fillRect(-this.width / 2, -this.height / 2, this.width, this.height), n.restore(), !this.blockErasing && a.forEach(function(u) {
441
- u.render(n);
442
- }), o.forEach(function(u) {
443
- u.globalCompositeOperation = u.inverted ? "destination-out" : "source-in", u.render(n);
444
- });
445
- }
446
- }]), e;
447
- }($);
448
- M(R, "type", "clipping");
449
- ye.setClass(R);
450
- var ee = function(e, r) {
451
- var n = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "source-over";
452
- e.save(), e.imageSmoothingEnabled = !0, e.imageSmoothingQuality = "high", e.globalCompositeOperation = n, e.resetTransform(), e.drawImage(r.canvas, 0, 0), e.restore();
453
- }, Ie = function(e, r, n) {
454
- ee(e, r, "destination-out"), n ? ee(r, n, "source-in") : (r.save(), r.resetTransform(), r.clearRect(0, 0, r.canvas.width, r.canvas.height), r.restore());
455
- };
456
- function le(t) {
457
- return t.flatMap(function(e) {
458
- return !e.erasable || e.isNotVisible() ? [] : e instanceof $ && e.erasable === "deep" ? le(e.getObjects()) : [e];
459
- });
460
- }
461
- function Re(t, e, r) {
462
- e.clearContext(t), t.imageSmoothingEnabled = e.imageSmoothingEnabled, t.imageSmoothingQuality = "high", t.patternQuality = "best", e._renderBackground(t), t.save(), t.transform.apply(t, I(e.viewportTransform)), r.forEach(function(a) {
463
- return a.render(t);
464
- }), t.restore();
465
- var n = e.clipPath;
466
- n && (n._set("canvas", e), n.shouldCache(), n._transformDone = !0, n.renderCache({
467
- forClipping: !0
468
- }), e.drawClipPathOnCanvas(t, n)), e._renderOverlay(t);
469
- }
470
- function De(t, e, r) {
471
- var n = e.inverted, a = e.opacity, o = r.canvas, u = r.objects, i = u === void 0 ? o._objectsToRender || o._objects : u, c = r.background, s = c === void 0 ? o.backgroundImage : c, f = r.overlay, p = f === void 0 ? o.overlayImage : f, v = 1 - a, y = le([].concat(I(i), I([s, p].filter(function(l) {
472
- return !!l;
473
- })))).map(function(l) {
474
- if (n) {
475
- if (l.clipPath instanceof R)
476
- return l.clipPath.blockErasing = !0, l.clipPath.set("dirty", !0), l.set("dirty", !0), {
477
- object: l,
478
- clipPath: l.clipPath
479
- };
480
- } else {
481
- var w, D = l.opacity;
482
- return l.opacity *= v, (w = l.parent) === null || w === void 0 || w.set("dirty", !0), {
483
- object: l,
484
- opacity: D
485
- };
486
- }
487
- });
488
- Re(t, o, i), y.forEach(function(l) {
489
- if (l)
490
- if (l.opacity) {
491
- var w;
492
- l.object.opacity = l.opacity, (w = l.object.parent) === null || w === void 0 || w.set("dirty", !0);
493
- } else l.clipPath && (l.clipPath.blockErasing = !1, l.clipPath.set("dirty", !0), l.object.set("dirty", !0));
494
- });
495
- }
496
- function fe(t, e) {
497
- return t.flatMap(function(r) {
498
- return !r.erasable || !r.intersectsWithObject(e) ? [] : r instanceof $ && r.erasable === "deep" ? fe(r.getObjects(), e) : [r];
499
- });
500
- }
501
- var Fe = function(e) {
502
- var r = e.clipPath;
503
- if (r instanceof R)
504
- return r;
505
- var n = e.strokeWidth, a = new k.Point(n, n), o = e.strokeUniform ? a.divide(e.getObjectScaling()) : a, u = new R([], {
506
- width: e.width + o.x,
507
- height: e.height + o.y
508
- });
509
- if (r) {
510
- var i = r.translateToOriginPoint(new k.Point(), r.originX, r.originY), c = i.x, s = i.y;
511
- r.originX = r.originY = "center", k.util.sendObjectToPlane(r, void 0, k.util.createTranslateMatrix(c, s)), u.add(r);
512
- }
513
- return e.clipPath = u;
514
- };
515
- function pe(t, e) {
516
- var r = Fe(t);
517
- r.add(e), r.set("dirty", !0), t.set("dirty", !0);
518
- }
519
- function Ne(t, e) {
520
- return U.apply(this, arguments);
521
- }
522
- function U() {
523
- return U = G(/* @__PURE__ */ E().mark(function t(e, r) {
524
- var n;
525
- return E().wrap(function(o) {
526
- for (; ; ) switch (o.prev = o.next) {
527
- case 0:
528
- return o.next = 2, r.clone();
529
- case 2:
530
- return n = o.sent, k.util.sendObjectToPlane(n, void 0, e.calcTransformMatrix()), pe(e, n), o.abrupt("return", n);
531
- case 6:
532
- case "end":
533
- return o.stop();
534
- }
535
- }, t);
536
- })), U.apply(this, arguments);
537
- }
538
- function Be(t, e, r) {
539
- return X.apply(this, arguments);
540
- }
541
- function X() {
542
- return X = G(/* @__PURE__ */ E().mark(function t(e, r, n) {
543
- var a, o;
544
- return E().wrap(function(i) {
545
- for (; ; ) switch (i.prev = i.next) {
546
- case 0:
547
- return i.next = 2, n.clone();
548
- case 2:
549
- return a = i.sent, o = r && e.translateToOriginPoint(new k.Point(), e.originX, e.originY), k.util.sendObjectToPlane(a, void 0, o ? k.util.multiplyTransformMatrixArray([
550
- [1, 0, 0, 1, o.x, o.y],
551
- // apply vpt from center of drawable
552
- r,
553
- [1, 0, 0, 1, -o.x, -o.y],
554
- e.calcTransformMatrix()
555
- ]) : e.calcTransformMatrix()), pe(e, a), i.abrupt("return", a);
556
- case 7:
557
- case "end":
558
- return i.stop();
559
- }
560
- }, t);
561
- })), X.apply(this, arguments);
562
- }
563
- var xe = function(e, r, n) {
564
- var a = n.width, o = n.height, u = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 1;
565
- e.width = a, e.height = o, u > 1 && (e.setAttribute("width", (a * u).toString()), e.setAttribute("height", (o * u).toString()), r.scale(u, u));
566
- }, Le = /* @__PURE__ */ function(t) {
567
- ie(e, t);
568
- function e(r) {
569
- var n;
570
- ne(this, e), n = re(this, e, [r]), M(x(n), "inverted", !1), M(x(n), "active", !1);
571
- var a = document.createElement("canvas"), o = a.getContext("2d");
572
- if (!o)
573
- throw new Error("Failed to get context");
574
- return xe(a, o, r, n.canvas.getRetinaScaling()), n.effectContext = o, n.eventEmitter = new EventTarget(), n;
575
- }
576
- return ae(e, [{
577
- key: "on",
578
- value: function(n, a, o) {
579
- var u = this;
580
- return this.eventEmitter.addEventListener(n, a, o), function() {
581
- return u.eventEmitter.removeEventListener(n, a, o);
582
- };
583
- }
584
- }, {
585
- key: "drawEffect",
586
- value: function() {
587
- De(this.effectContext, {
588
- opacity: new k.Color(this.color).getAlpha(),
589
- inverted: this.inverted
590
- }, {
591
- canvas: this.canvas
592
- });
593
- }
594
- /**
595
- * @override
596
- */
597
- }, {
598
- key: "_setBrushStyles",
599
- value: function() {
600
- var n = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this.canvas.contextTop;
601
- T(_(e.prototype), "_setBrushStyles", this).call(this, n), n.strokeStyle = "black";
602
- }
603
- /**
604
- * @override strictly speaking the eraser needs a full render only if it has opacity set.
605
- * However since {@link PencilBrush} is designed for subclassing that is what we have to work with.
606
- */
607
- }, {
608
- key: "needsFullRender",
609
- value: function() {
610
- return !0;
611
- }
612
- /**
613
- * @override erase
614
- */
615
- }, {
616
- key: "_render",
617
- value: function() {
618
- var n = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this.canvas.getTopContext();
619
- T(_(e.prototype), "_render", this).call(this, n), Ie(this.canvas.getContext(), n, this.effectContext);
620
- }
621
- /**
622
- * @override {@link drawEffect}
623
- */
624
- }, {
625
- key: "onMouseDown",
626
- value: function(n, a) {
627
- var o = this;
628
- this.eventEmitter.dispatchEvent(new CustomEvent("start", {
629
- detail: a,
630
- cancelable: !0
631
- })) && (this.active = !0, this.eventEmitter.dispatchEvent(new CustomEvent("redraw", {
632
- detail: {
633
- type: "start"
634
- },
635
- cancelable: !0
636
- })) && this.drawEffect(), this._disposer = this.canvas.on("after:render", function(u) {
637
- var i = u.ctx;
638
- i === o.canvas.getContext() && (o.eventEmitter.dispatchEvent(new CustomEvent("redraw", {
639
- detail: {
640
- type: "render"
641
- },
642
- cancelable: !0
643
- })) && o.drawEffect(), o._render());
644
- }), T(_(e.prototype), "onMouseDown", this).call(this, n, a));
645
- }
646
- /**
647
- * @override run if active
648
- */
649
- }, {
650
- key: "onMouseMove",
651
- value: function(n, a) {
652
- this.active && this.eventEmitter.dispatchEvent(new CustomEvent("move", {
653
- detail: a,
654
- cancelable: !0
655
- })) && T(_(e.prototype), "onMouseMove", this).call(this, n, a);
656
- }
657
- /**
658
- * @override run if active, dispose of {@link drawEffect} listener
659
- */
660
- }, {
661
- key: "onMouseUp",
662
- value: function(n) {
663
- var a;
664
- return this.active && T(_(e.prototype), "onMouseUp", this).call(this, n), this.active = !1, (a = this._disposer) === null || a === void 0 || a.call(this), delete this._disposer, !1;
665
- }
666
- /**
667
- * @override {@link fabric.PencilBrush} logic
668
- */
669
- }, {
670
- key: "convertPointsToSVGPath",
671
- value: function(n) {
672
- return T(_(e.prototype), "convertPointsToSVGPath", this).call(this, this.decimate ? this.decimatePoints(n, this.decimate) : n);
673
- }
674
- /**
675
- * @override
676
- */
677
- }, {
678
- key: "createPath",
679
- value: function(n) {
680
- var a = T(_(e.prototype), "createPath", this).call(this, n);
681
- return a.set(this.inverted ? {
682
- globalCompositeOperation: "source-over",
683
- stroke: "white"
684
- } : {
685
- globalCompositeOperation: "destination-out",
686
- stroke: "black",
687
- opacity: new k.Color(this.color).getAlpha()
688
- }), a;
689
- }
690
- }, {
691
- key: "commit",
692
- value: function() {
693
- var r = G(/* @__PURE__ */ E().mark(function a(o) {
694
- var u, i;
695
- return E().wrap(function(s) {
696
- for (; ; ) switch (s.prev = s.next) {
697
- case 0:
698
- return u = o.path, i = o.targets, s.t0 = Map, s.next = 4, Promise.all([].concat(I(i.map(/* @__PURE__ */ function() {
699
- var f = G(/* @__PURE__ */ E().mark(function p(v) {
700
- return E().wrap(function(l) {
701
- for (; ; ) switch (l.prev = l.next) {
702
- case 0:
703
- return l.t0 = v, l.next = 3, Ne(v, u);
704
- case 3:
705
- return l.t1 = l.sent, l.abrupt("return", [l.t0, l.t1]);
706
- case 5:
707
- case "end":
708
- return l.stop();
709
- }
710
- }, p);
711
- }));
712
- return function(p) {
713
- return f.apply(this, arguments);
714
- };
715
- }())), I([[this.canvas.backgroundImage, this.canvas.backgroundVpt ? void 0 : this.canvas.viewportTransform], [this.canvas.overlayImage, this.canvas.overlayVpt ? void 0 : this.canvas.viewportTransform]].filter(function(f) {
716
- var p = Z(f, 1), v = p[0];
717
- return !!(v != null && v.erasable);
718
- }).map(/* @__PURE__ */ function() {
719
- var f = G(/* @__PURE__ */ E().mark(function p(v) {
720
- var y, l, w;
721
- return E().wrap(function(P) {
722
- for (; ; ) switch (P.prev = P.next) {
723
- case 0:
724
- return y = Z(v, 2), l = y[0], w = y[1], P.t0 = l, P.next = 4, Be(l, w, u);
725
- case 4:
726
- return P.t1 = P.sent, P.abrupt("return", [P.t0, P.t1]);
727
- case 6:
728
- case "end":
729
- return P.stop();
730
- }
731
- }, p);
732
- }));
733
- return function(p) {
734
- return f.apply(this, arguments);
735
- };
736
- }()))));
737
- case 4:
738
- return s.t1 = s.sent, s.abrupt("return", new s.t0(s.t1));
739
- case 6:
740
- case "end":
741
- return s.stop();
742
- }
743
- }, a, this);
744
- }));
745
- function n(a) {
746
- return r.apply(this, arguments);
747
- }
748
- return n;
749
- }()
750
- /**
751
- * @override handle events
752
- */
753
- }, {
754
- key: "_finalizeAndAddPath",
755
- value: function() {
756
- var n = this._points;
757
- if (n.length < 2) {
758
- this.eventEmitter.dispatchEvent(new CustomEvent("cancel", {
759
- cancelable: !1
760
- }));
761
- return;
762
- }
763
- var a = this.createPath(this.convertPointsToSVGPath(n)), o = fe(this.canvas.getObjects(), a);
764
- this.eventEmitter.dispatchEvent(new CustomEvent("end", {
765
- detail: {
766
- path: a,
767
- targets: o
768
- },
769
- cancelable: !0
770
- })) && this.commit({
771
- path: a,
772
- targets: o
773
- }), this.canvas.clearContext(this.canvas.contextTop), this.canvas.requestRenderAll(), this._resetShadow();
774
- }
775
- }, {
776
- key: "dispose",
777
- value: function() {
778
- var n = this.effectContext.canvas;
779
- n.width = n.height = 0;
780
- }
781
- }]), e;
782
- }(k.PencilBrush);
783
- export {
784
- R as ClippingGroup,
785
- Le as EraserBrush,
786
- Be as eraseCanvasDrawable,
787
- Ne as eraseObject
788
- };