leiting-bim 2.1.197 → 2.1.198

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.
@@ -0,0 +1,793 @@
1
+ function X(r, t) {
2
+ t === void 0 && (t = {});
3
+ var e = t.insertAt;
4
+ if (!(typeof document > "u")) {
5
+ var a = document.head || document.getElementsByTagName("head")[0], i = document.createElement("style");
6
+ i.type = "text/css", e === "top" && a.firstChild ? a.insertBefore(i, a.firstChild) : a.appendChild(i), i.styleSheet ? i.styleSheet.cssText = r : i.appendChild(document.createTextNode(r));
7
+ }
8
+ }
9
+ var Y = "@keyframes watermark{0%{background-position:0 0}25%{background-position:100% 100%}50%{background-position:100% 0}75%{background-position:0 100%}to{background-position:0 0}}@keyframes watermark-horizontal{0%{background-position-x:0}to{background-position-x:100%}}@keyframes watermark-vertical{0%{background-position-y:0}to{background-position-y:100%}}";
10
+ X(Y);
11
+ var W = function(r, t) {
12
+ return W = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(e, a) {
13
+ e.__proto__ = a;
14
+ } || function(e, a) {
15
+ for (var i in a) Object.prototype.hasOwnProperty.call(a, i) && (e[i] = a[i]);
16
+ }, W(r, t);
17
+ };
18
+ function q(r, t) {
19
+ if (typeof t != "function" && t !== null)
20
+ throw new TypeError("Class extends value " + String(t) + " is not a constructor or null");
21
+ W(r, t);
22
+ function e() {
23
+ this.constructor = r;
24
+ }
25
+ r.prototype = t === null ? Object.create(t) : (e.prototype = t.prototype, new e());
26
+ }
27
+ var _ = function() {
28
+ return _ = Object.assign || function(t) {
29
+ for (var e, a = 1, i = arguments.length; a < i; a++) {
30
+ e = arguments[a];
31
+ for (var n in e) Object.prototype.hasOwnProperty.call(e, n) && (t[n] = e[n]);
32
+ }
33
+ return t;
34
+ }, _.apply(this, arguments);
35
+ };
36
+ function S(r, t, e, a) {
37
+ function i(n) {
38
+ return n instanceof e ? n : new e(function(o) {
39
+ o(n);
40
+ });
41
+ }
42
+ return new (e || (e = Promise))(function(n, o) {
43
+ function l(c) {
44
+ try {
45
+ d(a.next(c));
46
+ } catch (h) {
47
+ o(h);
48
+ }
49
+ }
50
+ function s(c) {
51
+ try {
52
+ d(a.throw(c));
53
+ } catch (h) {
54
+ o(h);
55
+ }
56
+ }
57
+ function d(c) {
58
+ c.done ? n(c.value) : i(c.value).then(l, s);
59
+ }
60
+ d((a = a.apply(r, t || [])).next());
61
+ });
62
+ }
63
+ function b(r, t) {
64
+ var e = { label: 0, sent: function() {
65
+ if (n[0] & 1) throw n[1];
66
+ return n[1];
67
+ }, trys: [], ops: [] }, a, i, n, o = Object.create((typeof Iterator == "function" ? Iterator : Object).prototype);
68
+ return o.next = l(0), o.throw = l(1), o.return = l(2), typeof Symbol == "function" && (o[Symbol.iterator] = function() {
69
+ return this;
70
+ }), o;
71
+ function l(d) {
72
+ return function(c) {
73
+ return s([d, c]);
74
+ };
75
+ }
76
+ function s(d) {
77
+ if (a) throw new TypeError("Generator is already executing.");
78
+ for (; o && (o = 0, d[0] && (e = 0)), e; ) try {
79
+ if (a = 1, i && (n = d[0] & 2 ? i.return : d[0] ? i.throw || ((n = i.return) && n.call(i), 0) : i.next) && !(n = n.call(i, d[1])).done) return n;
80
+ switch (i = 0, n && (d = [d[0] & 2, n.value]), d[0]) {
81
+ case 0:
82
+ case 1:
83
+ n = d;
84
+ break;
85
+ case 4:
86
+ return e.label++, { value: d[1], done: !1 };
87
+ case 5:
88
+ e.label++, i = d[1], d = [0];
89
+ continue;
90
+ case 7:
91
+ d = e.ops.pop(), e.trys.pop();
92
+ continue;
93
+ default:
94
+ if (n = e.trys, !(n = n.length > 0 && n[n.length - 1]) && (d[0] === 6 || d[0] === 2)) {
95
+ e = 0;
96
+ continue;
97
+ }
98
+ if (d[0] === 3 && (!n || d[1] > n[0] && d[1] < n[3])) {
99
+ e.label = d[1];
100
+ break;
101
+ }
102
+ if (d[0] === 6 && e.label < n[1]) {
103
+ e.label = n[1], n = d;
104
+ break;
105
+ }
106
+ if (n && e.label < n[2]) {
107
+ e.label = n[2], e.ops.push(d);
108
+ break;
109
+ }
110
+ n[2] && e.ops.pop(), e.trys.pop();
111
+ continue;
112
+ }
113
+ d = t.call(r, e);
114
+ } catch (c) {
115
+ d = [6, c], i = 0;
116
+ } finally {
117
+ a = n = 0;
118
+ }
119
+ if (d[0] & 5) throw d[1];
120
+ return { value: d[0] ? d[1] : void 0, done: !0 };
121
+ }
122
+ }
123
+ var V = function(r) {
124
+ return r.toDataURL("image/png", 1);
125
+ }, N = function(r) {
126
+ return typeof r == "function";
127
+ }, x = function(r) {
128
+ return r === void 0;
129
+ }, F = function(r) {
130
+ return typeof r == "string";
131
+ }, z = function(r, t, e) {
132
+ t === void 0 && (t = {}), e === void 0 && (e = "http://www.w3.org/2000/svg");
133
+ var a = document.createElementNS(e, r);
134
+ for (var i in t)
135
+ a.setAttribute(i, t[i]);
136
+ return a;
137
+ }, K = function(r, t, e) {
138
+ for (var a = [], i = "", n = "", o = 0, l = t.length; o < l; o++) {
139
+ if (n = t.charAt(o), n === `
140
+ `) {
141
+ a.push(i), i = "";
142
+ continue;
143
+ }
144
+ i += n, r.measureText(i).width > e && (a.push(i.substring(0, i.length - 1)), i = "", o--);
145
+ }
146
+ return a.push(i), a;
147
+ }, U = function(r, t) {
148
+ return S(void 0, void 0, void 0, function() {
149
+ var e, a, i, n, o, l, s, d, c;
150
+ return b(this, function(h) {
151
+ switch (h.label) {
152
+ case 0:
153
+ return e = z("svg", {
154
+ xmlns: "http://www.w3.org/2000/svg"
155
+ }), a = document.createElement("div"), a.setAttribute("xmlns", "http://www.w3.org/1999/xhtml"), a.style.cssText = `
156
+ text-align: center;
157
+ display: flex;
158
+ align-items: center;
159
+ justify-content: center;
160
+ width: 100%;
161
+ height: 100%;
162
+ font: `.concat(r.font, `;
163
+ color: `).concat(t.fontColor, `;
164
+ `), a.innerHTML = "<div class='rich-text-content'>".concat(t.content, "</div>"), document.body.appendChild(a), [4, $(a)];
165
+ case 1:
166
+ return h.sent(), i = (c = a.querySelector(".rich-text-content")) === null || c === void 0 ? void 0 : c.getBoundingClientRect(), n = i?.width, o = i?.height, document.body.removeChild(a), l = t.richTextWidth || n || t.width, s = t.richTextHeight || o || t.height, e.setAttribute("width", l.toString()), e.setAttribute("height", s.toString()), d = z("foreignObject", {
167
+ width: l.toString(),
168
+ height: s.toString()
169
+ }), d.appendChild(a), e.appendChild(d), [2, {
170
+ element: e,
171
+ width: l,
172
+ height: s
173
+ }];
174
+ }
175
+ });
176
+ });
177
+ };
178
+ function $(r) {
179
+ return S(this, void 0, void 0, function() {
180
+ var t, e, a, i, n;
181
+ return b(this, function(o) {
182
+ switch (o.label) {
183
+ case 0:
184
+ t = r.querySelectorAll("img"), e = function(l) {
185
+ var s, d, c, h, u;
186
+ return b(this, function(v) {
187
+ switch (v.label) {
188
+ case 0:
189
+ if (s = l.getAttribute("src"), !s) return [3, 6];
190
+ v.label = 1;
191
+ case 1:
192
+ return v.trys.push([1, 5, , 6]), [4, fetch(s)];
193
+ case 2:
194
+ return d = v.sent(), [4, d.blob()];
195
+ case 3:
196
+ return c = v.sent(), [4, new Promise(function(m, p) {
197
+ var f = new FileReader();
198
+ f.onloadend = function() {
199
+ return m(f.result);
200
+ }, f.onerror = p, f.readAsDataURL(c);
201
+ })];
202
+ case 4:
203
+ return h = v.sent(), F(h) && l.setAttribute("src", h), [3, 6];
204
+ case 5:
205
+ return u = v.sent(), console.error("Error converting ".concat(s, " to base64:"), u), [3, 6];
206
+ case 6:
207
+ return [
208
+ 2
209
+ /*return*/
210
+ ];
211
+ }
212
+ });
213
+ }, a = 0, i = Array.from(t), o.label = 1;
214
+ case 1:
215
+ return a < i.length ? (n = i[a], [5, e(n)]) : [3, 4];
216
+ case 2:
217
+ o.sent(), o.label = 3;
218
+ case 3:
219
+ return a++, [3, 1];
220
+ case 4:
221
+ return [
222
+ 2
223
+ /*return*/
224
+ ];
225
+ }
226
+ });
227
+ });
228
+ }
229
+ var J = function(r) {
230
+ var t = r.outerHTML.replace(/<(img|br|input|hr|embed)(.*?)>/g, "<$1$2/>").replace(/\n/g, "").replace(/\t/g, "").replace(/#/g, "%23");
231
+ return "data:image/svg+xml;charset=utf-8,".concat(t);
232
+ }, y = function(r, t) {
233
+ return x(r) ? t : r;
234
+ }, B = function(r, t, e) {
235
+ t === void 0 && (t = void 0), e === void 0 && (e = void 0);
236
+ var a = new Image();
237
+ return a.setAttribute("crossOrigin", "anonymous"), !x(t) && (a.width = t), !x(e) && (a.height = e), a.src = r, new Promise(function(i) {
238
+ a.onload = function() {
239
+ i(a);
240
+ };
241
+ });
242
+ }, Q = function(r, t, e) {
243
+ return Array.from({ length: r }, function() {
244
+ return new Array(t).fill(e);
245
+ });
246
+ }, Z = function(r, t) {
247
+ if (!r)
248
+ return "";
249
+ var e = Math.random() * 6 + 2, a = Math.random() * 2 + 2;
250
+ switch (t) {
251
+ case "repeat":
252
+ return "animation: 200s linear 0s infinite alternate watermark !important;";
253
+ case "repeat-x":
254
+ return "animation: ".concat(e, "s linear 0s infinite alternate watermark-vertical !important;'");
255
+ case "repeat-y":
256
+ return "animation: ".concat(a, "s linear 0s infinite alternate watermark-horizontal !important;'");
257
+ case "no-repeat":
258
+ return "animation: ".concat(e, "s linear 0s infinite alternate watermark-horizontal, ").concat(a, "s linear 0s infinite alternate watermark-vertical !important;");
259
+ default:
260
+ return "";
261
+ }
262
+ }, G = {
263
+ width: 300,
264
+ height: 300,
265
+ rotate: 45,
266
+ layout: "default",
267
+ auxiliaryLine: !1,
268
+ translatePlacement: "middle",
269
+ contentType: "text",
270
+ content: "hello watermark-js-plus",
271
+ textType: "fill",
272
+ imageWidth: 0,
273
+ imageHeight: 0,
274
+ lineHeight: 30,
275
+ zIndex: 2147483647,
276
+ backgroundPosition: "0 0",
277
+ backgroundRepeat: "repeat",
278
+ fontSize: "20px",
279
+ fontFamily: "sans-serif",
280
+ fontStyle: "",
281
+ fontVariant: "",
282
+ fontColor: "#000",
283
+ fontWeight: "normal",
284
+ filter: "none",
285
+ letterSpacing: "0px",
286
+ wordSpacing: "0px",
287
+ globalAlpha: 0.5,
288
+ mode: "default",
289
+ mutationObserve: !0,
290
+ monitorProtection: !1,
291
+ movable: !1,
292
+ parent: "body",
293
+ onSuccess: function() {
294
+ },
295
+ onBeforeDestroy: function() {
296
+ },
297
+ onDestroyed: function() {
298
+ },
299
+ onObserveError: function() {
300
+ }
301
+ }, tt = function(r, t, e) {
302
+ var a = r.getContext("2d");
303
+ if (a === null)
304
+ throw new Error("get context error");
305
+ a.font = "".concat(t.fontStyle, " ").concat(t.fontVariant, " ").concat(t.fontWeight, " ").concat(t.fontSize, " ").concat(t.fontFamily), a.filter = t.filter, a.letterSpacing = t.letterSpacing, a.wordSpacing = t.wordSpacing, t?.rotate && (t.rotate = (360 - t.rotate % 360) * (Math.PI / 180)), x(e.textRowMaxWidth) && (t.textRowMaxWidth = t.width);
306
+ var i = {
307
+ image: {
308
+ rect: {
309
+ width: t.imageWidth,
310
+ height: t.imageHeight
311
+ },
312
+ position: {
313
+ x: 0,
314
+ y: 0
315
+ }
316
+ },
317
+ textLine: {
318
+ data: [],
319
+ yOffsetValue: 0
320
+ },
321
+ advancedStyleParams: {
322
+ linear: {
323
+ x0: 0,
324
+ x1: 0
325
+ },
326
+ radial: {
327
+ x0: 0,
328
+ y0: 0,
329
+ r0: 0,
330
+ x1: 0,
331
+ y1: 0,
332
+ r1: 0
333
+ },
334
+ conic: {
335
+ x: 0,
336
+ y: 0,
337
+ startAngle: 0
338
+ },
339
+ pattern: {}
340
+ }
341
+ };
342
+ switch (t.contentType) {
343
+ case "text":
344
+ i.textLine.data = [t.content];
345
+ break;
346
+ case "multi-line-text":
347
+ i.textLine.data = K(a, t.content, t.textRowMaxWidth);
348
+ break;
349
+ }
350
+ var n = t.width / 2, o = t.height / 2, l = "middle", s = "center";
351
+ switch (!x(e?.translateX) && !x(e?.translateY) ? (n = e?.translateX, o = e?.translateY, l = "top", s = "left") : (i.advancedStyleParams.linear.x0 = -t.width / 2, i.advancedStyleParams.linear.x1 = t.width / 2, i.advancedStyleParams.radial.r0 = 0, i.advancedStyleParams.radial.r1 = t.width / 2), e.translatePlacement) {
352
+ case "top":
353
+ n = t.width / 2, o = 0, l = "top", i.advancedStyleParams.linear.x0 = -t.width / 2, i.advancedStyleParams.linear.x1 = t.width / 2, i.advancedStyleParams.radial.y0 = i.textLine.data.length * t.lineHeight / 2, i.advancedStyleParams.radial.y1 = i.textLine.data.length * t.lineHeight / 2, i.advancedStyleParams.conic.y = i.textLine.data.length * t.lineHeight / 2;
354
+ break;
355
+ case "top-start":
356
+ n = 0, o = 0, l = "top", s = "start", i.advancedStyleParams.linear.x0 = 0, i.advancedStyleParams.linear.x1 = t.width, i.advancedStyleParams.radial.x0 = t.width / 2, i.advancedStyleParams.radial.y0 = i.textLine.data.length * t.lineHeight / 2, i.advancedStyleParams.radial.x1 = t.width / 2, i.advancedStyleParams.radial.y1 = i.textLine.data.length * t.lineHeight / 2, i.advancedStyleParams.conic.x = t.width / 2, i.advancedStyleParams.conic.y = i.textLine.data.length * t.lineHeight / 2;
357
+ break;
358
+ case "top-end":
359
+ n = t.width, o = 0, l = "top", s = "end", i.advancedStyleParams.linear.x0 = 0, i.advancedStyleParams.linear.x1 = -t.width, i.advancedStyleParams.radial.x0 = -t.width / 2, i.advancedStyleParams.radial.y0 = i.textLine.data.length * t.lineHeight / 2, i.advancedStyleParams.radial.x1 = -t.width / 2, i.advancedStyleParams.radial.y1 = i.textLine.data.length * t.lineHeight / 2, i.advancedStyleParams.conic.x = -t.width / 2, i.advancedStyleParams.conic.y = i.textLine.data.length * t.lineHeight / 2;
360
+ break;
361
+ case "bottom":
362
+ n = t.width / 2, o = t.height, l = "bottom", i.advancedStyleParams.linear.x0 = -t.width / 2, i.advancedStyleParams.linear.x1 = t.width / 2, i.advancedStyleParams.radial.y0 = -i.textLine.data.length * t.lineHeight / 2, i.advancedStyleParams.radial.y1 = -i.textLine.data.length * t.lineHeight / 2, i.advancedStyleParams.conic.x = 0, i.advancedStyleParams.conic.y = -i.textLine.data.length * t.lineHeight / 2;
363
+ break;
364
+ case "bottom-start":
365
+ n = 0, o = t.height, l = "bottom", s = "start", i.advancedStyleParams.linear.x0 = 0, i.advancedStyleParams.linear.x1 = t.width, i.advancedStyleParams.radial.x0 = t.width / 2, i.advancedStyleParams.radial.y0 = -i.textLine.data.length * t.lineHeight / 2, i.advancedStyleParams.radial.x1 = t.width / 2, i.advancedStyleParams.radial.y1 = -i.textLine.data.length * t.lineHeight / 2, i.advancedStyleParams.conic.x = t.width / 2, i.advancedStyleParams.conic.y = -i.textLine.data.length * t.lineHeight / 2;
366
+ break;
367
+ case "bottom-end":
368
+ n = t.width, o = t.height, l = "bottom", s = "end", i.advancedStyleParams.linear.x0 = 0, i.advancedStyleParams.linear.x1 = -t.width, i.advancedStyleParams.radial.x0 = -t.width / 2, i.advancedStyleParams.radial.y0 = -i.textLine.data.length * t.lineHeight / 2, i.advancedStyleParams.radial.x1 = -t.width / 2, i.advancedStyleParams.radial.y1 = -i.textLine.data.length * t.lineHeight / 2, i.advancedStyleParams.conic.x = -t.width / 2, i.advancedStyleParams.conic.y = -i.textLine.data.length * t.lineHeight / 2;
369
+ break;
370
+ case "left":
371
+ n = 0, o = t.height / 2, s = "start", i.advancedStyleParams.linear.x0 = 0, i.advancedStyleParams.linear.x1 = t.width, i.advancedStyleParams.radial.x0 = t.width / 2, i.advancedStyleParams.radial.x1 = t.width / 2, i.advancedStyleParams.conic.x = t.width / 2, i.advancedStyleParams.conic.y = 0;
372
+ break;
373
+ case "right":
374
+ n = t.width, o = t.height / 2, s = "end", i.advancedStyleParams.linear.x0 = 0, i.advancedStyleParams.linear.x1 = -t.width, i.advancedStyleParams.radial.x0 = -t.width / 2, i.advancedStyleParams.radial.x1 = -t.width / 2, i.advancedStyleParams.conic.x = -t.width / 2, i.advancedStyleParams.conic.y = 0;
375
+ break;
376
+ }
377
+ if (t.translateX = n, t.translateY = o, x(e?.textBaseline) && (t.textBaseline = l), x(e?.textAlign) && (t.textAlign = s), ["text", "multi-line-text"].includes(t.contentType))
378
+ switch (t.textBaseline) {
379
+ case "middle":
380
+ i.textLine.yOffsetValue = (i.textLine.data.length - 1) * t.lineHeight / 2;
381
+ break;
382
+ case "bottom":
383
+ case "alphabetic":
384
+ case "ideographic":
385
+ i.textLine.yOffsetValue = (i.textLine.data.length - 1) * t.lineHeight + (t.lineHeight - parseInt(t.fontSize)) / 2;
386
+ break;
387
+ case "top":
388
+ case "hanging":
389
+ i.textLine.yOffsetValue = -t.lineHeight / 2 + parseInt(t.fontSize) / 2;
390
+ break;
391
+ }
392
+ return i;
393
+ }, j = (function(r) {
394
+ typeof window > "u" || r && Object.defineProperty(window, "MutationObserver", {
395
+ writable: !1,
396
+ configurable: !1
397
+ });
398
+ }), O = (
399
+ /** @class */
400
+ (function() {
401
+ function r(t, e) {
402
+ this.props = t, this.options = e, this.canvas = r.createCanvas(this.options.width, this.options.height), this.recommendOptions = tt(this.canvas, this.options, this.props);
403
+ }
404
+ return r.createCanvas = function(t, e) {
405
+ var a, i = window.devicePixelRatio || 1, n = document.createElement("canvas");
406
+ return n.width = t * i, n.height = e * i, n.style.width = "".concat(t, "px"), n.style.height = "".concat(e, "px"), (a = n.getContext("2d")) === null || a === void 0 || a.setTransform(i, 0, 0, i, 0, 0), n;
407
+ }, r.clearCanvas = function(t) {
408
+ var e = t.getContext("2d");
409
+ if (e === null)
410
+ throw new Error("get context error");
411
+ e.restore(), e.resetTransform(), e.clearRect(0, 0, t.width, t.height);
412
+ var a = window.devicePixelRatio || 1;
413
+ e.setTransform(a, 0, 0, a, 0, 0);
414
+ }, r.prototype.getCanvas = function() {
415
+ return this.canvas;
416
+ }, r.prototype.clear = function() {
417
+ r.clearCanvas(this.canvas);
418
+ }, r.prototype.draw = function() {
419
+ var t = this, e = this.canvas.getContext("2d");
420
+ if (e === null)
421
+ throw new Error("get context error");
422
+ return this.options.auxiliaryLine && (e.beginPath(), e.rect(0, 0, this.options.width, this.options.height), e.lineWidth = 1, e.strokeStyle = "#000", e.stroke(), e.closePath(), e.beginPath(), e.rect(this.options.translateX, this.options.translateY, 1, 1), e.lineWidth = 1, e.strokeStyle = "#f00", e.stroke(), e.closePath()), this.setStyle(e), e.save(), e.translate(this.options.translateX, this.options.translateY), e.rotate(this.options.rotate), new Promise(function(a) {
423
+ switch (t.options.contentType) {
424
+ case "text":
425
+ t.drawText(e, a);
426
+ break;
427
+ case "image":
428
+ t.drawImage(e, a);
429
+ break;
430
+ case "multi-line-text":
431
+ t.drawMultiLineText(e, a);
432
+ break;
433
+ case "rich-text":
434
+ t.drawRichText(e, a);
435
+ break;
436
+ }
437
+ });
438
+ }, r.prototype.setStyle = function(t) {
439
+ var e, a = "fillStyle";
440
+ this.options.textType === "stroke" && (a = "strokeStyle");
441
+ var i = this.options.fontColor;
442
+ if (!((e = this.options) === null || e === void 0) && e.advancedStyle)
443
+ switch (this.options.advancedStyle.type) {
444
+ case "linear":
445
+ i = this.createLinearGradient(t);
446
+ break;
447
+ case "radial":
448
+ i = this.createRadialGradient(t);
449
+ break;
450
+ case "conic":
451
+ i = this.createConicGradient(t);
452
+ break;
453
+ case "pattern":
454
+ i = this.createPattern(t);
455
+ break;
456
+ }
457
+ t[a] && i && (t[a] = i), this.options.textAlign && (t.textAlign = this.options.textAlign), this.options.textBaseline && (t.textBaseline = this.options.textBaseline), t.globalAlpha = this.options.globalAlpha, this.options.shadowStyle && (t.shadowBlur = y(this.options.shadowStyle.shadowBlur, 0), t.shadowColor = y(this.options.shadowStyle.shadowColor, "#00000000"), t.shadowOffsetX = y(this.options.shadowStyle.shadowOffsetX, 0), t.shadowOffsetY = y(this.options.shadowStyle.shadowOffsetY, 0)), N(this.options.extraDrawFunc) && this.options.extraDrawFunc(t);
458
+ }, r.prototype.createLinearGradient = function(t) {
459
+ var e, a, i, n, o, l, s, d, c, h, u, v, m, p, f, w = t.createLinearGradient(y((i = (a = (e = this.options.advancedStyle) === null || e === void 0 ? void 0 : e.params) === null || a === void 0 ? void 0 : a.linear) === null || i === void 0 ? void 0 : i.x0, this.recommendOptions.advancedStyleParams.linear.x0), y((l = (o = (n = this.options.advancedStyle) === null || n === void 0 ? void 0 : n.params) === null || o === void 0 ? void 0 : o.linear) === null || l === void 0 ? void 0 : l.y0, 0), y((c = (d = (s = this.options.advancedStyle) === null || s === void 0 ? void 0 : s.params) === null || d === void 0 ? void 0 : d.linear) === null || c === void 0 ? void 0 : c.x1, this.recommendOptions.advancedStyleParams.linear.x1), y((v = (u = (h = this.options.advancedStyle) === null || h === void 0 ? void 0 : h.params) === null || u === void 0 ? void 0 : u.linear) === null || v === void 0 ? void 0 : v.y1, 0));
460
+ return (f = (p = (m = this.options) === null || m === void 0 ? void 0 : m.advancedStyle) === null || p === void 0 ? void 0 : p.colorStops) === null || f === void 0 || f.forEach(function(g) {
461
+ w.addColorStop(g.offset, g.color);
462
+ }), w;
463
+ }, r.prototype.createConicGradient = function(t) {
464
+ var e, a, i, n, o, l, s, d, c, h, u, v, m, p, f, w = t.createConicGradient(y((n = (i = (a = (e = this.options) === null || e === void 0 ? void 0 : e.advancedStyle) === null || a === void 0 ? void 0 : a.params) === null || i === void 0 ? void 0 : i.conic) === null || n === void 0 ? void 0 : n.startAngle, 0), y((d = (s = (l = (o = this.options) === null || o === void 0 ? void 0 : o.advancedStyle) === null || l === void 0 ? void 0 : l.params) === null || s === void 0 ? void 0 : s.conic) === null || d === void 0 ? void 0 : d.x, this.recommendOptions.advancedStyleParams.conic.x), y((v = (u = (h = (c = this.options) === null || c === void 0 ? void 0 : c.advancedStyle) === null || h === void 0 ? void 0 : h.params) === null || u === void 0 ? void 0 : u.conic) === null || v === void 0 ? void 0 : v.y, this.recommendOptions.advancedStyleParams.conic.y));
465
+ return (f = (p = (m = this.options) === null || m === void 0 ? void 0 : m.advancedStyle) === null || p === void 0 ? void 0 : p.colorStops) === null || f === void 0 || f.forEach(function(g) {
466
+ w.addColorStop(g.offset, g.color);
467
+ }), w;
468
+ }, r.prototype.createRadialGradient = function(t) {
469
+ var e, a, i, n, o, l, s, d, c, h, u, v, m, p, f, w, g, k, P, C, L, E, T, A, D, H, R, I = t.createRadialGradient(y((n = (i = (a = (e = this.options) === null || e === void 0 ? void 0 : e.advancedStyle) === null || a === void 0 ? void 0 : a.params) === null || i === void 0 ? void 0 : i.radial) === null || n === void 0 ? void 0 : n.x0, this.recommendOptions.advancedStyleParams.radial.x0), y((d = (s = (l = (o = this.options) === null || o === void 0 ? void 0 : o.advancedStyle) === null || l === void 0 ? void 0 : l.params) === null || s === void 0 ? void 0 : s.radial) === null || d === void 0 ? void 0 : d.y0, this.recommendOptions.advancedStyleParams.radial.y0), y((v = (u = (h = (c = this.options) === null || c === void 0 ? void 0 : c.advancedStyle) === null || h === void 0 ? void 0 : h.params) === null || u === void 0 ? void 0 : u.radial) === null || v === void 0 ? void 0 : v.r0, this.recommendOptions.advancedStyleParams.radial.r0), y((w = (f = (p = (m = this.options) === null || m === void 0 ? void 0 : m.advancedStyle) === null || p === void 0 ? void 0 : p.params) === null || f === void 0 ? void 0 : f.radial) === null || w === void 0 ? void 0 : w.x1, this.recommendOptions.advancedStyleParams.radial.x1), y((C = (P = (k = (g = this.options) === null || g === void 0 ? void 0 : g.advancedStyle) === null || k === void 0 ? void 0 : k.params) === null || P === void 0 ? void 0 : P.radial) === null || C === void 0 ? void 0 : C.y1, this.recommendOptions.advancedStyleParams.radial.y1), y((A = (T = (E = (L = this.options) === null || L === void 0 ? void 0 : L.advancedStyle) === null || E === void 0 ? void 0 : E.params) === null || T === void 0 ? void 0 : T.radial) === null || A === void 0 ? void 0 : A.r1, this.recommendOptions.advancedStyleParams.radial.r1));
470
+ return (R = (H = (D = this.options) === null || D === void 0 ? void 0 : D.advancedStyle) === null || H === void 0 ? void 0 : H.colorStops) === null || R === void 0 || R.forEach(function(M) {
471
+ I.addColorStop(M.offset, M.color);
472
+ }), I;
473
+ }, r.prototype.createPattern = function(t) {
474
+ var e, a, i, n, o, l, s, d;
475
+ return t.createPattern((n = (i = (a = (e = this.options) === null || e === void 0 ? void 0 : e.advancedStyle) === null || a === void 0 ? void 0 : a.params) === null || i === void 0 ? void 0 : i.pattern) === null || n === void 0 ? void 0 : n.image, ((d = (s = (l = (o = this.options) === null || o === void 0 ? void 0 : o.advancedStyle) === null || l === void 0 ? void 0 : l.params) === null || s === void 0 ? void 0 : s.pattern) === null || d === void 0 ? void 0 : d.repetition) || "");
476
+ }, r.prototype.setText = function(t, e) {
477
+ var a = "fillText";
478
+ this.options.textType === "stroke" && (a = "strokeText"), t[a] && t[a](e.text, e.x, e.y, e.maxWidth);
479
+ }, r.prototype.drawText = function(t, e) {
480
+ this.setText(t, {
481
+ text: this.options.content,
482
+ x: 0,
483
+ y: 0 - this.recommendOptions.textLine.yOffsetValue,
484
+ maxWidth: this.options.textRowMaxWidth || this.options.width
485
+ }), e(t.canvas);
486
+ }, r.prototype.drawImage = function(t, e) {
487
+ var a = this;
488
+ B(this.options.image).then(function(i) {
489
+ var n = a.getImageRect(i), o = n.width, l = n.height, s = a.getDrawImagePosition(o, l);
490
+ t.drawImage(i, s.x, s.y, o, l), e(t.canvas);
491
+ });
492
+ }, r.prototype.drawMultiLineText = function(t, e) {
493
+ var a = this, i = this.recommendOptions.textLine.data, n = this.recommendOptions.textLine.yOffsetValue;
494
+ i.forEach(function(o, l) {
495
+ a.setText(t, {
496
+ text: o,
497
+ x: 0,
498
+ y: a.options.lineHeight * l - n,
499
+ maxWidth: a.options.textRowMaxWidth || a.options.width
500
+ });
501
+ }), e(t.canvas);
502
+ }, r.prototype.drawRichText = function(t, e) {
503
+ return S(this, void 0, void 0, function() {
504
+ var a, i = this;
505
+ return b(this, function(n) {
506
+ switch (n.label) {
507
+ case 0:
508
+ return [4, U(t, this.options)];
509
+ case 1:
510
+ return a = n.sent(), B(J(a.element), a.width, a.height).then(function(o) {
511
+ var l = i.getDrawImagePosition(o.width, o.height);
512
+ t.drawImage(o, l.x, l.y, o.width, o.height), e(t.canvas);
513
+ }), [
514
+ 2
515
+ /*return*/
516
+ ];
517
+ }
518
+ });
519
+ });
520
+ }, r.prototype.getImageRect = function(t) {
521
+ var e = { width: this.options.imageWidth || 0, height: this.options.imageHeight || 0 };
522
+ switch (!0) {
523
+ case (e.width !== 0 && e.height === 0):
524
+ e.height = e.width * t.height / t.width;
525
+ break;
526
+ case (e.width === 0 && e.height !== 0):
527
+ e.width = e.height * t.width / t.height;
528
+ break;
529
+ case (e.width === 0 && e.height === 0):
530
+ e.width = t.width, e.height = t.height;
531
+ break;
532
+ }
533
+ return e;
534
+ }, r.prototype.getDrawImagePosition = function(t, e) {
535
+ var a, i, n = {
536
+ x: -t / 2,
537
+ y: -e / 2
538
+ };
539
+ switch (this.options.translatePlacement) {
540
+ case "top":
541
+ n.x = -t / 2, n.y = 0;
542
+ break;
543
+ case "top-start":
544
+ n.x = 0, n.y = 0;
545
+ break;
546
+ case "top-end":
547
+ n.x = -t, n.y = 0;
548
+ break;
549
+ case "bottom":
550
+ n.x = -t / 2, n.y = -e;
551
+ break;
552
+ case "bottom-start":
553
+ n.x = 0, n.y = -e;
554
+ break;
555
+ case "bottom-end":
556
+ n.x = -t, n.y = -e;
557
+ break;
558
+ case "left":
559
+ n.x = 0, n.y = -e / 2;
560
+ break;
561
+ case "right":
562
+ n.x = -t, n.y = -e / 2;
563
+ break;
564
+ }
565
+ return !x((a = this.props) === null || a === void 0 ? void 0 : a.translateX) && (n.x = 0), !x((i = this.props) === null || i === void 0 ? void 0 : i.translateY) && (n.y = 0), n;
566
+ }, r;
567
+ })()
568
+ ), et = (
569
+ /** @class */
570
+ (function() {
571
+ function r(t, e) {
572
+ var a, i, n, o;
573
+ this.options = t, this.partialWidth = this.options.width, this.partialHeight = this.options.height, this.rows = ((a = this.options.gridLayoutOptions) === null || a === void 0 ? void 0 : a.rows) || 1, this.cols = ((i = this.options.gridLayoutOptions) === null || i === void 0 ? void 0 : i.cols) || 1, this.matrix = ((n = this.options.gridLayoutOptions) === null || n === void 0 ? void 0 : n.matrix) || Q(this.rows, this.cols, 1), this.gap = ((o = this.options.gridLayoutOptions) === null || o === void 0 ? void 0 : o.gap) || [0, 0], this.partialCanvas = e;
574
+ }
575
+ return r.prototype.draw = function() {
576
+ var t, e, a, i, n, o, l, s, d = O.createCanvas(((t = this.options.gridLayoutOptions) === null || t === void 0 ? void 0 : t.width) || this.partialWidth * this.cols + this.gap[0] * this.cols, ((e = this.options.gridLayoutOptions) === null || e === void 0 ? void 0 : e.height) || this.partialHeight * this.rows + this.gap[1] * this.rows), c = d.getContext("2d");
577
+ !((a = this.options.gridLayoutOptions) === null || a === void 0) && a.backgroundImage && c?.drawImage((i = this.options.gridLayoutOptions) === null || i === void 0 ? void 0 : i.backgroundImage, 0, 0, (n = this.options.gridLayoutOptions) === null || n === void 0 ? void 0 : n.width, (o = this.options.gridLayoutOptions) === null || o === void 0 ? void 0 : o.height);
578
+ for (var h = 0; h < this.rows; h++)
579
+ for (var u = 0; u < this.cols; u++)
580
+ !((s = (l = this.matrix) === null || l === void 0 ? void 0 : l[h]) === null || s === void 0) && s[u] && c?.drawImage(this.partialCanvas, this.partialWidth * u + this.gap[0] * u, this.partialHeight * h + this.gap[1] * h, this.partialWidth, this.partialHeight);
581
+ return d;
582
+ }, r;
583
+ })()
584
+ ), it = function(r, t) {
585
+ return r.layout === "grid" ? new et(r, t).draw() : t;
586
+ }, at = function(r) {
587
+ var t, e, a;
588
+ if (r.layout === "grid") {
589
+ var i = ((t = r.gridLayoutOptions) === null || t === void 0 ? void 0 : t.cols) || 1, n = ((e = r.gridLayoutOptions) === null || e === void 0 ? void 0 : e.rows) || 1, o = ((a = r.gridLayoutOptions) === null || a === void 0 ? void 0 : a.gap) || [0, 0];
590
+ return [r.width * i + o[0] * i, r.height * n + o[1] * n];
591
+ } else
592
+ return [r.width, r.height];
593
+ }, nt = (
594
+ /** @class */
595
+ (function() {
596
+ function r(t) {
597
+ t === void 0 && (t = {}), this.parentElement = document.body, this.isCreating = !1, this.props = t, this.options = _(_({}, G), t), this.changeParentElement(this.options.parent), this.watermarkCanvas = new O(this.props, this.options), j(this.options.monitorProtection);
598
+ }
599
+ return r.prototype.changeOptions = function() {
600
+ return S(this, arguments, void 0, function(t, e, a) {
601
+ return t === void 0 && (t = {}), e === void 0 && (e = "overwrite"), a === void 0 && (a = !0), b(this, function(i) {
602
+ switch (i.label) {
603
+ case 0:
604
+ return this.initConfigData(t, e), j(this.options.monitorProtection), a ? (this.remove(), [4, this.create()]) : [3, 2];
605
+ case 1:
606
+ i.sent(), i.label = 2;
607
+ case 2:
608
+ return [
609
+ 2
610
+ /*return*/
611
+ ];
612
+ }
613
+ });
614
+ });
615
+ }, r.prototype.create = function() {
616
+ return S(this, void 0, void 0, function() {
617
+ var t, e, a, i, n, o, l, s, d, c, h, u;
618
+ return b(this, function(v) {
619
+ switch (v.label) {
620
+ case 0:
621
+ return this.isCreating ? [
622
+ 2
623
+ /*return*/
624
+ ] : (this.isCreating = !0, this.validateUnique() ? this.validateContent() ? (t = x(this.watermarkDom), [4, (o = this.watermarkCanvas) === null || o === void 0 ? void 0 : o.draw()]) : (this.isCreating = !1, [
625
+ 2
626
+ /*return*/
627
+ ]) : (this.isCreating = !1, [
628
+ 2
629
+ /*return*/
630
+ ]));
631
+ case 1:
632
+ if (v.sent(), this.layoutCanvas = it(this.options, (l = this.watermarkCanvas) === null || l === void 0 ? void 0 : l.getCanvas()), e = V(this.layoutCanvas), (s = this.watermarkCanvas) === null || s === void 0 || s.clear(), this.watermarkDom = document.createElement("div"), a = document.createElement("div"), this.watermarkDom.__WATERMARK__ = "watermark", this.watermarkDom.__WATERMARK__INSTANCE__ = this, i = this.checkParentElementType(), this.watermarkDom.style.cssText = `
633
+ z-index:`.concat(this.options.zIndex, `!important;display:block!important;visibility:visible!important;transform:none!important;scale:none!important;
634
+ `).concat(i === "custom" ? "top:0!important;bottom:0!important;left:0!important;right:0!important;height:100%!important;pointer-events:none!important;position:absolute!important;" : "position:relative!important;", `
635
+ `), n = at(this.options), a.style.cssText = `
636
+ display:block!important;visibility:visible!important;pointer-events:none;top:0;bottom:0;left:0;right:0;transform:none!important;scale:none!important;
637
+ position:`.concat(i === "root" ? "fixed" : "absolute", `!important;-webkit-print-color-adjust:exact!important;width:100%!important;height:100%!important;
638
+ z-index:`).concat(this.options.zIndex, "!important;background-image:url(").concat(e, ")!important;background-repeat:").concat(this.options.backgroundRepeat, `!important;
639
+ background-size:`).concat(n[0], "px ").concat(n[1], "px!important;background-position:").concat(this.options.backgroundPosition, `;
640
+ `).concat(Z(this.options.movable, this.options.backgroundRepeat), `
641
+ `), this.watermarkDom.appendChild(a), this.parentElement.appendChild(this.watermarkDom), this.options.mutationObserve)
642
+ try {
643
+ this.bindMutationObserve();
644
+ } catch {
645
+ (c = (d = this.options).onObserveError) === null || c === void 0 || c.call(d);
646
+ }
647
+ return t && ((u = (h = this.options).onSuccess) === null || u === void 0 || u.call(h)), this.isCreating = !1, [
648
+ 2
649
+ /*return*/
650
+ ];
651
+ }
652
+ });
653
+ });
654
+ }, r.prototype.destroy = function() {
655
+ this.remove(), this.watermarkDom = void 0;
656
+ }, r.prototype.check = function() {
657
+ return S(this, void 0, void 0, function() {
658
+ return b(this, function(t) {
659
+ return [2, this.parentElement.contains(this.watermarkDom)];
660
+ });
661
+ });
662
+ }, r.prototype.remove = function() {
663
+ var t, e, a, i, n, o, l, s;
664
+ (e = (t = this.options).onBeforeDestroy) === null || e === void 0 || e.call(t), (a = this.observer) === null || a === void 0 || a.disconnect(), (i = this.parentObserve) === null || i === void 0 || i.disconnect(), (o = (n = this.watermarkDom) === null || n === void 0 ? void 0 : n.parentNode) === null || o === void 0 || o.removeChild(this.watermarkDom), (s = (l = this.options).onDestroyed) === null || s === void 0 || s.call(l);
665
+ }, r.prototype.initConfigData = function(t, e) {
666
+ var a = this;
667
+ e === void 0 && (e = "overwrite"), e === "append" ? Object.keys(t).forEach(function(i) {
668
+ a.props && (a.props[i] = t[i]);
669
+ }) : this.props = t, this.options = _(_({}, G), this.props), this.changeParentElement(this.options.parent), this.watermarkCanvas = new O(this.props, this.options);
670
+ }, r.prototype.changeParentElement = function(t) {
671
+ if (typeof t == "string") {
672
+ var e = document.querySelector(t);
673
+ e && (this.parentElement = e);
674
+ } else
675
+ this.parentElement = t;
676
+ this.parentElement || console.error("[WatermarkJsPlus]: please pass a valid parent element.");
677
+ }, r.prototype.validateUnique = function() {
678
+ var t = !0;
679
+ return Array.from(this.parentElement.childNodes).forEach(function(e) {
680
+ t && Object.hasOwnProperty.call(e, "__WATERMARK__") && (t = !1);
681
+ }), t;
682
+ }, r.prototype.validateContent = function() {
683
+ switch (this.options.contentType) {
684
+ case "image":
685
+ return Object.hasOwnProperty.call(this.options, "image");
686
+ case "multi-line-text":
687
+ case "rich-text":
688
+ case "text":
689
+ return this.options.content.length > 0;
690
+ }
691
+ }, r.prototype.checkParentElementType = function() {
692
+ return ["html", "body"].includes(this.parentElement.tagName.toLocaleLowerCase()) ? "root" : "custom";
693
+ }, r.prototype.bindMutationObserve = function() {
694
+ var t = this;
695
+ this.watermarkDom && (this.observer = new MutationObserver(function(e) {
696
+ return S(t, void 0, void 0, function() {
697
+ return b(this, function(a) {
698
+ switch (a.label) {
699
+ case 0:
700
+ return e.length > 0 ? (this.remove(), [4, this.create()]) : [3, 2];
701
+ case 1:
702
+ a.sent(), a.label = 2;
703
+ case 2:
704
+ return [
705
+ 2
706
+ /*return*/
707
+ ];
708
+ }
709
+ });
710
+ });
711
+ }), this.observer.observe(this.watermarkDom, {
712
+ attributes: !0,
713
+ // 属性的变动
714
+ childList: !0,
715
+ // 子节点的变动(指新增,删除或者更改)
716
+ subtree: !0,
717
+ // 布尔值,表示是否将该观察器应用于该节点的所有后代节点。
718
+ characterData: !0
719
+ // 节点内容或节点文本的变动。
720
+ }), this.parentObserve = new MutationObserver(function(e) {
721
+ return S(t, void 0, void 0, function() {
722
+ var a, i, n, o;
723
+ return b(this, function(l) {
724
+ switch (l.label) {
725
+ case 0:
726
+ a = 0, i = e, l.label = 1;
727
+ case 1:
728
+ return a < i.length ? (n = i[a], o = Array.from(n.removedNodes).includes(this.watermarkDom), o ? (this.remove(), [4, this.create()]) : [3, 3]) : [3, 4];
729
+ case 2:
730
+ l.sent(), l.label = 3;
731
+ case 3:
732
+ return a++, [3, 1];
733
+ case 4:
734
+ return [
735
+ 2
736
+ /*return*/
737
+ ];
738
+ }
739
+ });
740
+ });
741
+ }), this.parentObserve.observe(this.parentElement, {
742
+ childList: !0
743
+ // 子节点的变动(指新增,删除或者更改)
744
+ }));
745
+ }, r;
746
+ })()
747
+ );
748
+ (function(r) {
749
+ q(t, r);
750
+ function t(e) {
751
+ e === void 0 && (e = {});
752
+ var a = {
753
+ globalAlpha: 5e-3,
754
+ mode: "blind"
755
+ };
756
+ return r.call(this, _(_({}, e), a)) || this;
757
+ }
758
+ return t.prototype.changeOptions = function() {
759
+ return S(this, arguments, void 0, function(e, a, i) {
760
+ return e === void 0 && (e = {}), a === void 0 && (a = "overwrite"), i === void 0 && (i = !0), b(this, function(n) {
761
+ switch (n.label) {
762
+ case 0:
763
+ return e.globalAlpha = 5e-3, e.mode = "blind", this.initConfigData(e, a), j(this.options.monitorProtection), i ? (this.remove(), [4, this.create()]) : [3, 2];
764
+ case 1:
765
+ n.sent(), n.label = 2;
766
+ case 2:
767
+ return [
768
+ 2
769
+ /*return*/
770
+ ];
771
+ }
772
+ });
773
+ });
774
+ }, t.decode = function(e) {
775
+ var a = e.url, i = a === void 0 ? "" : a, n = e.fillColor, o = n === void 0 ? "#000" : n, l = e.compositeOperation, s = l === void 0 ? "color-burn" : l, d = e.mode, c = d === void 0 ? "canvas" : d, h = e.compositeTimes, u = h === void 0 ? 3 : h, v = e.onSuccess;
776
+ if (i && c === "canvas") {
777
+ var m = new Image();
778
+ m.src = i, m.addEventListener("load", function() {
779
+ var p = m.width, f = m.height, w = O.createCanvas(p, f), g = w.getContext("2d");
780
+ if (!g)
781
+ throw new Error("get context error");
782
+ g.drawImage(m, 0, 0, p, f), g.globalCompositeOperation = s, g.fillStyle = o;
783
+ for (var k = 0; k < u; k++)
784
+ g.fillRect(0, 0, p, f);
785
+ var P = V(w);
786
+ N(v) && v?.(P);
787
+ });
788
+ }
789
+ }, t;
790
+ })(nt);
791
+ export {
792
+ nt as Watermark
793
+ };