@egova-mobile/app-media-utils 0.0.1

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,1512 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
+ // If the importer is in node compatibility mode or this is not an ESM
20
+ // file that has been converted to a CommonJS file using a Babel-
21
+ // compatible transform (i.e. "__esModule" has not been set), then set
22
+ // "default" to the CommonJS "module.exports" for node compatibility.
23
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
+ mod
25
+ ));
26
+ var __async = (__this, __arguments, generator) => {
27
+ return new Promise((resolve, reject) => {
28
+ var fulfilled = (value) => {
29
+ try {
30
+ step(generator.next(value));
31
+ } catch (e) {
32
+ reject(e);
33
+ }
34
+ };
35
+ var rejected = (value) => {
36
+ try {
37
+ step(generator.throw(value));
38
+ } catch (e) {
39
+ reject(e);
40
+ }
41
+ };
42
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
43
+ step((generator = generator.apply(__this, __arguments)).next());
44
+ });
45
+ };
46
+
47
+ // ../../node_modules/.pnpm/dayjs@1.11.10/node_modules/dayjs/dayjs.min.js
48
+ var require_dayjs_min = __commonJS({
49
+ "../../node_modules/.pnpm/dayjs@1.11.10/node_modules/dayjs/dayjs.min.js"(exports, module) {
50
+ !function(t, e) {
51
+ "object" == typeof exports && "undefined" != typeof module ? module.exports = e() : "function" == typeof define && define.amd ? define(e) : (t = "undefined" != typeof globalThis ? globalThis : t || self).dayjs = e();
52
+ }(exports, function() {
53
+ "use strict";
54
+ var t = 1e3, e = 6e4, n = 36e5, r = "millisecond", i = "second", s = "minute", u = "hour", a = "day", o = "week", c = "month", f = "quarter", h = "year", d = "date", l = "Invalid Date", $ = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/, y = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g, M = { name: "en", weekdays: "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"), months: "January_February_March_April_May_June_July_August_September_October_November_December".split("_"), ordinal: function(t2) {
55
+ var e2 = ["th", "st", "nd", "rd"], n2 = t2 % 100;
56
+ return "[" + t2 + (e2[(n2 - 20) % 10] || e2[n2] || e2[0]) + "]";
57
+ } }, m = function(t2, e2, n2) {
58
+ var r2 = String(t2);
59
+ return !r2 || r2.length >= e2 ? t2 : "" + Array(e2 + 1 - r2.length).join(n2) + t2;
60
+ }, v = { s: m, z: function(t2) {
61
+ var e2 = -t2.utcOffset(), n2 = Math.abs(e2), r2 = Math.floor(n2 / 60), i2 = n2 % 60;
62
+ return (e2 <= 0 ? "+" : "-") + m(r2, 2, "0") + ":" + m(i2, 2, "0");
63
+ }, m: function t2(e2, n2) {
64
+ if (e2.date() < n2.date())
65
+ return -t2(n2, e2);
66
+ var r2 = 12 * (n2.year() - e2.year()) + (n2.month() - e2.month()), i2 = e2.clone().add(r2, c), s2 = n2 - i2 < 0, u2 = e2.clone().add(r2 + (s2 ? -1 : 1), c);
67
+ return +(-(r2 + (n2 - i2) / (s2 ? i2 - u2 : u2 - i2)) || 0);
68
+ }, a: function(t2) {
69
+ return t2 < 0 ? Math.ceil(t2) || 0 : Math.floor(t2);
70
+ }, p: function(t2) {
71
+ return { M: c, y: h, w: o, d: a, D: d, h: u, m: s, s: i, ms: r, Q: f }[t2] || String(t2 || "").toLowerCase().replace(/s$/, "");
72
+ }, u: function(t2) {
73
+ return void 0 === t2;
74
+ } }, g = "en", D = {};
75
+ D[g] = M;
76
+ var p = "$isDayjsObject", S = function(t2) {
77
+ return t2 instanceof _ || !(!t2 || !t2[p]);
78
+ }, w = function t2(e2, n2, r2) {
79
+ var i2;
80
+ if (!e2)
81
+ return g;
82
+ if ("string" == typeof e2) {
83
+ var s2 = e2.toLowerCase();
84
+ D[s2] && (i2 = s2), n2 && (D[s2] = n2, i2 = s2);
85
+ var u2 = e2.split("-");
86
+ if (!i2 && u2.length > 1)
87
+ return t2(u2[0]);
88
+ } else {
89
+ var a2 = e2.name;
90
+ D[a2] = e2, i2 = a2;
91
+ }
92
+ return !r2 && i2 && (g = i2), i2 || !r2 && g;
93
+ }, O = function(t2, e2) {
94
+ if (S(t2))
95
+ return t2.clone();
96
+ var n2 = "object" == typeof e2 ? e2 : {};
97
+ return n2.date = t2, n2.args = arguments, new _(n2);
98
+ }, b = v;
99
+ b.l = w, b.i = S, b.w = function(t2, e2) {
100
+ return O(t2, { locale: e2.$L, utc: e2.$u, x: e2.$x, $offset: e2.$offset });
101
+ };
102
+ var _ = function() {
103
+ function M2(t2) {
104
+ this.$L = w(t2.locale, null, true), this.parse(t2), this.$x = this.$x || t2.x || {}, this[p] = true;
105
+ }
106
+ var m2 = M2.prototype;
107
+ return m2.parse = function(t2) {
108
+ this.$d = function(t3) {
109
+ var e2 = t3.date, n2 = t3.utc;
110
+ if (null === e2)
111
+ return /* @__PURE__ */ new Date(NaN);
112
+ if (b.u(e2))
113
+ return /* @__PURE__ */ new Date();
114
+ if (e2 instanceof Date)
115
+ return new Date(e2);
116
+ if ("string" == typeof e2 && !/Z$/i.test(e2)) {
117
+ var r2 = e2.match($);
118
+ if (r2) {
119
+ var i2 = r2[2] - 1 || 0, s2 = (r2[7] || "0").substring(0, 3);
120
+ return n2 ? new Date(Date.UTC(r2[1], i2, r2[3] || 1, r2[4] || 0, r2[5] || 0, r2[6] || 0, s2)) : new Date(r2[1], i2, r2[3] || 1, r2[4] || 0, r2[5] || 0, r2[6] || 0, s2);
121
+ }
122
+ }
123
+ return new Date(e2);
124
+ }(t2), this.init();
125
+ }, m2.init = function() {
126
+ var t2 = this.$d;
127
+ this.$y = t2.getFullYear(), this.$M = t2.getMonth(), this.$D = t2.getDate(), this.$W = t2.getDay(), this.$H = t2.getHours(), this.$m = t2.getMinutes(), this.$s = t2.getSeconds(), this.$ms = t2.getMilliseconds();
128
+ }, m2.$utils = function() {
129
+ return b;
130
+ }, m2.isValid = function() {
131
+ return !(this.$d.toString() === l);
132
+ }, m2.isSame = function(t2, e2) {
133
+ var n2 = O(t2);
134
+ return this.startOf(e2) <= n2 && n2 <= this.endOf(e2);
135
+ }, m2.isAfter = function(t2, e2) {
136
+ return O(t2) < this.startOf(e2);
137
+ }, m2.isBefore = function(t2, e2) {
138
+ return this.endOf(e2) < O(t2);
139
+ }, m2.$g = function(t2, e2, n2) {
140
+ return b.u(t2) ? this[e2] : this.set(n2, t2);
141
+ }, m2.unix = function() {
142
+ return Math.floor(this.valueOf() / 1e3);
143
+ }, m2.valueOf = function() {
144
+ return this.$d.getTime();
145
+ }, m2.startOf = function(t2, e2) {
146
+ var n2 = this, r2 = !!b.u(e2) || e2, f2 = b.p(t2), l2 = function(t3, e3) {
147
+ var i2 = b.w(n2.$u ? Date.UTC(n2.$y, e3, t3) : new Date(n2.$y, e3, t3), n2);
148
+ return r2 ? i2 : i2.endOf(a);
149
+ }, $2 = function(t3, e3) {
150
+ return b.w(n2.toDate()[t3].apply(n2.toDate("s"), (r2 ? [0, 0, 0, 0] : [23, 59, 59, 999]).slice(e3)), n2);
151
+ }, y2 = this.$W, M3 = this.$M, m3 = this.$D, v2 = "set" + (this.$u ? "UTC" : "");
152
+ switch (f2) {
153
+ case h:
154
+ return r2 ? l2(1, 0) : l2(31, 11);
155
+ case c:
156
+ return r2 ? l2(1, M3) : l2(0, M3 + 1);
157
+ case o:
158
+ var g2 = this.$locale().weekStart || 0, D2 = (y2 < g2 ? y2 + 7 : y2) - g2;
159
+ return l2(r2 ? m3 - D2 : m3 + (6 - D2), M3);
160
+ case a:
161
+ case d:
162
+ return $2(v2 + "Hours", 0);
163
+ case u:
164
+ return $2(v2 + "Minutes", 1);
165
+ case s:
166
+ return $2(v2 + "Seconds", 2);
167
+ case i:
168
+ return $2(v2 + "Milliseconds", 3);
169
+ default:
170
+ return this.clone();
171
+ }
172
+ }, m2.endOf = function(t2) {
173
+ return this.startOf(t2, false);
174
+ }, m2.$set = function(t2, e2) {
175
+ var n2, o2 = b.p(t2), f2 = "set" + (this.$u ? "UTC" : ""), l2 = (n2 = {}, n2[a] = f2 + "Date", n2[d] = f2 + "Date", n2[c] = f2 + "Month", n2[h] = f2 + "FullYear", n2[u] = f2 + "Hours", n2[s] = f2 + "Minutes", n2[i] = f2 + "Seconds", n2[r] = f2 + "Milliseconds", n2)[o2], $2 = o2 === a ? this.$D + (e2 - this.$W) : e2;
176
+ if (o2 === c || o2 === h) {
177
+ var y2 = this.clone().set(d, 1);
178
+ y2.$d[l2]($2), y2.init(), this.$d = y2.set(d, Math.min(this.$D, y2.daysInMonth())).$d;
179
+ } else
180
+ l2 && this.$d[l2]($2);
181
+ return this.init(), this;
182
+ }, m2.set = function(t2, e2) {
183
+ return this.clone().$set(t2, e2);
184
+ }, m2.get = function(t2) {
185
+ return this[b.p(t2)]();
186
+ }, m2.add = function(r2, f2) {
187
+ var d2, l2 = this;
188
+ r2 = Number(r2);
189
+ var $2 = b.p(f2), y2 = function(t2) {
190
+ var e2 = O(l2);
191
+ return b.w(e2.date(e2.date() + Math.round(t2 * r2)), l2);
192
+ };
193
+ if ($2 === c)
194
+ return this.set(c, this.$M + r2);
195
+ if ($2 === h)
196
+ return this.set(h, this.$y + r2);
197
+ if ($2 === a)
198
+ return y2(1);
199
+ if ($2 === o)
200
+ return y2(7);
201
+ var M3 = (d2 = {}, d2[s] = e, d2[u] = n, d2[i] = t, d2)[$2] || 1, m3 = this.$d.getTime() + r2 * M3;
202
+ return b.w(m3, this);
203
+ }, m2.subtract = function(t2, e2) {
204
+ return this.add(-1 * t2, e2);
205
+ }, m2.format = function(t2) {
206
+ var e2 = this, n2 = this.$locale();
207
+ if (!this.isValid())
208
+ return n2.invalidDate || l;
209
+ var r2 = t2 || "YYYY-MM-DDTHH:mm:ssZ", i2 = b.z(this), s2 = this.$H, u2 = this.$m, a2 = this.$M, o2 = n2.weekdays, c2 = n2.months, f2 = n2.meridiem, h2 = function(t3, n3, i3, s3) {
210
+ return t3 && (t3[n3] || t3(e2, r2)) || i3[n3].slice(0, s3);
211
+ }, d2 = function(t3) {
212
+ return b.s(s2 % 12 || 12, t3, "0");
213
+ }, $2 = f2 || function(t3, e3, n3) {
214
+ var r3 = t3 < 12 ? "AM" : "PM";
215
+ return n3 ? r3.toLowerCase() : r3;
216
+ };
217
+ return r2.replace(y, function(t3, r3) {
218
+ return r3 || function(t4) {
219
+ switch (t4) {
220
+ case "YY":
221
+ return String(e2.$y).slice(-2);
222
+ case "YYYY":
223
+ return b.s(e2.$y, 4, "0");
224
+ case "M":
225
+ return a2 + 1;
226
+ case "MM":
227
+ return b.s(a2 + 1, 2, "0");
228
+ case "MMM":
229
+ return h2(n2.monthsShort, a2, c2, 3);
230
+ case "MMMM":
231
+ return h2(c2, a2);
232
+ case "D":
233
+ return e2.$D;
234
+ case "DD":
235
+ return b.s(e2.$D, 2, "0");
236
+ case "d":
237
+ return String(e2.$W);
238
+ case "dd":
239
+ return h2(n2.weekdaysMin, e2.$W, o2, 2);
240
+ case "ddd":
241
+ return h2(n2.weekdaysShort, e2.$W, o2, 3);
242
+ case "dddd":
243
+ return o2[e2.$W];
244
+ case "H":
245
+ return String(s2);
246
+ case "HH":
247
+ return b.s(s2, 2, "0");
248
+ case "h":
249
+ return d2(1);
250
+ case "hh":
251
+ return d2(2);
252
+ case "a":
253
+ return $2(s2, u2, true);
254
+ case "A":
255
+ return $2(s2, u2, false);
256
+ case "m":
257
+ return String(u2);
258
+ case "mm":
259
+ return b.s(u2, 2, "0");
260
+ case "s":
261
+ return String(e2.$s);
262
+ case "ss":
263
+ return b.s(e2.$s, 2, "0");
264
+ case "SSS":
265
+ return b.s(e2.$ms, 3, "0");
266
+ case "Z":
267
+ return i2;
268
+ }
269
+ return null;
270
+ }(t3) || i2.replace(":", "");
271
+ });
272
+ }, m2.utcOffset = function() {
273
+ return 15 * -Math.round(this.$d.getTimezoneOffset() / 15);
274
+ }, m2.diff = function(r2, d2, l2) {
275
+ var $2, y2 = this, M3 = b.p(d2), m3 = O(r2), v2 = (m3.utcOffset() - this.utcOffset()) * e, g2 = this - m3, D2 = function() {
276
+ return b.m(y2, m3);
277
+ };
278
+ switch (M3) {
279
+ case h:
280
+ $2 = D2() / 12;
281
+ break;
282
+ case c:
283
+ $2 = D2();
284
+ break;
285
+ case f:
286
+ $2 = D2() / 3;
287
+ break;
288
+ case o:
289
+ $2 = (g2 - v2) / 6048e5;
290
+ break;
291
+ case a:
292
+ $2 = (g2 - v2) / 864e5;
293
+ break;
294
+ case u:
295
+ $2 = g2 / n;
296
+ break;
297
+ case s:
298
+ $2 = g2 / e;
299
+ break;
300
+ case i:
301
+ $2 = g2 / t;
302
+ break;
303
+ default:
304
+ $2 = g2;
305
+ }
306
+ return l2 ? $2 : b.a($2);
307
+ }, m2.daysInMonth = function() {
308
+ return this.endOf(c).$D;
309
+ }, m2.$locale = function() {
310
+ return D[this.$L];
311
+ }, m2.locale = function(t2, e2) {
312
+ if (!t2)
313
+ return this.$L;
314
+ var n2 = this.clone(), r2 = w(t2, e2, true);
315
+ return r2 && (n2.$L = r2), n2;
316
+ }, m2.clone = function() {
317
+ return b.w(this.$d, this);
318
+ }, m2.toDate = function() {
319
+ return new Date(this.valueOf());
320
+ }, m2.toJSON = function() {
321
+ return this.isValid() ? this.toISOString() : null;
322
+ }, m2.toISOString = function() {
323
+ return this.$d.toISOString();
324
+ }, m2.toString = function() {
325
+ return this.$d.toUTCString();
326
+ }, M2;
327
+ }(), k = _.prototype;
328
+ return O.prototype = k, [["$ms", r], ["$s", i], ["$m", s], ["$H", u], ["$W", a], ["$M", c], ["$y", h], ["$D", d]].forEach(function(t2) {
329
+ k[t2[1]] = function(e2) {
330
+ return this.$g(e2, t2[0], t2[1]);
331
+ };
332
+ }), O.extend = function(t2, e2) {
333
+ return t2.$i || (t2(e2, _, O), t2.$i = true), O;
334
+ }, O.locale = w, O.isDayjs = S, O.unix = function(t2) {
335
+ return O(1e3 * t2);
336
+ }, O.en = D[g], O.Ls = D, O.p = {}, O;
337
+ });
338
+ }
339
+ });
340
+
341
+ // ../../node_modules/.pnpm/dayjs@1.11.10/node_modules/dayjs/locale/zh-cn.js
342
+ var require_zh_cn = __commonJS({
343
+ "../../node_modules/.pnpm/dayjs@1.11.10/node_modules/dayjs/locale/zh-cn.js"(exports, module) {
344
+ !function(e, _) {
345
+ "object" == typeof exports && "undefined" != typeof module ? module.exports = _(require_dayjs_min()) : "function" == typeof define && define.amd ? define(["dayjs"], _) : (e = "undefined" != typeof globalThis ? globalThis : e || self).dayjs_locale_zh_cn = _(e.dayjs);
346
+ }(exports, function(e) {
347
+ "use strict";
348
+ function _(e2) {
349
+ return e2 && "object" == typeof e2 && "default" in e2 ? e2 : { default: e2 };
350
+ }
351
+ var t = _(e), d = { name: "zh-cn", weekdays: "星期日_星期一_星期二_星期三_星期四_星期五_星期六".split("_"), weekdaysShort: "周日_周一_周二_周三_周四_周五_周六".split("_"), weekdaysMin: "日_一_二_三_四_五_六".split("_"), months: "一月_二月_三月_四月_五月_六月_七月_八月_九月_十月_十一月_十二月".split("_"), monthsShort: "1月_2月_3月_4月_5月_6月_7月_8月_9月_10月_11月_12月".split("_"), ordinal: function(e2, _2) {
352
+ return "W" === _2 ? e2 + "周" : e2 + "日";
353
+ }, weekStart: 1, yearStart: 4, formats: { LT: "HH:mm", LTS: "HH:mm:ss", L: "YYYY/MM/DD", LL: "YYYY年M月D日", LLL: "YYYY年M月D日Ah点mm分", LLLL: "YYYY年M月D日ddddAh点mm分", l: "YYYY/M/D", ll: "YYYY年M月D日", lll: "YYYY年M月D日 HH:mm", llll: "YYYY年M月D日dddd HH:mm" }, relativeTime: { future: "%s内", past: "%s前", s: "几秒", m: "1 分钟", mm: "%d 分钟", h: "1 小时", hh: "%d 小时", d: "1 天", dd: "%d 天", M: "1 个月", MM: "%d 个月", y: "1 年", yy: "%d 年" }, meridiem: function(e2, _2) {
354
+ var t2 = 100 * e2 + _2;
355
+ return t2 < 600 ? "凌晨" : t2 < 900 ? "早上" : t2 < 1100 ? "上午" : t2 < 1300 ? "中午" : t2 < 1800 ? "下午" : "晚上";
356
+ } };
357
+ return t.default.locale(d, null, true), d;
358
+ });
359
+ }
360
+ });
361
+
362
+ // src/utils/type-check.ts
363
+ function checkDataType(tgt, type) {
364
+ const dataType = Object.prototype.toString.call(tgt).replace(/\[object (\w+)\]/, "$1").toLowerCase();
365
+ return type ? dataType === type : dataType;
366
+ }
367
+ function checkIsUndefined(tgt) {
368
+ return checkDataType(tgt, "undefined");
369
+ }
370
+ function checkIsNull(tgt) {
371
+ return checkDataType(tgt, "null");
372
+ }
373
+ function checkIsUndefinedOrNull(tgt) {
374
+ return checkIsUndefined(tgt) || checkIsNull(tgt);
375
+ }
376
+ function checkIsString(tgt) {
377
+ return checkDataType(tgt, "string");
378
+ }
379
+ function checkIsStringValid(tgt) {
380
+ if (checkDataType(tgt, "string")) {
381
+ return tgt !== "";
382
+ } else {
383
+ return false;
384
+ }
385
+ }
386
+ function checkIsRegExp(tgt) {
387
+ return checkDataType(tgt, "regexp");
388
+ }
389
+
390
+ // src/utils/type-parse.ts
391
+ function parseInteger(obj, defaultValue) {
392
+ let result = parseInt(obj, 10);
393
+ if (isNaN(result)) {
394
+ result = defaultValue || 0;
395
+ }
396
+ return result;
397
+ }
398
+ function parseDecimal(obj, defaultValue) {
399
+ let result = parseFloat(obj);
400
+ if (isNaN(result)) {
401
+ result = defaultValue || 0;
402
+ }
403
+ return result;
404
+ }
405
+
406
+ // src/utils/date.ts
407
+ var FORMAT = {
408
+ //英文简写如:12:01
409
+ FORMAT_HM: "HH:mm",
410
+ //英文简写如:1-12 12:01
411
+ FORMAT_MDHM: "MM-dd HH:mm",
412
+ //中文简写如:1月12日
413
+ FORMAT_MD_CN: "MM月dd日",
414
+ //中文简写如:1月12日
415
+ FORMAT_MD: "MM-dd",
416
+ //英文简写(默认)如:2010-12-01
417
+ FORMAT_YMD: "yyyy-MM-dd",
418
+ FORMAT_YMD_SLASH: "yyyy/MM/dd",
419
+ //英文简写(默认)如:2010-12
420
+ FORMAT_YM: "yyyy-MM",
421
+ //英文全称 如:2010-12-01 23:15
422
+ FORMAT_YMDHM: "yyyy-MM-dd HH:mm",
423
+ //英文全称 如:2010-12-01 23:15:06
424
+ FORMAT_YMDHMS: "yyyy-MM-dd HH:mm:ss",
425
+ //英文全称 如:2010-12-01 23:15:06
426
+ FORMAT_YMDHMSMS: "yyyy-MM-dd HH:mm:ss msms",
427
+ //中文简写 如:2010年12月
428
+ FORMAT_YM_CN: "yyyy年MM月",
429
+ //中文简写 如:2010年12月01日
430
+ FORMAT_YMD_CN: "yyyy年MM月dd日",
431
+ //中文简写 如:2010年12月01日 12时
432
+ FORMAT_YMDH_CN: "yyyy年MM月dd日 HH时",
433
+ //中文简写 如:12月01日 12时
434
+ FORMAT_MDH_CN: "MM月dd日 HH时",
435
+ //中文简写 如:2010年12月01日 12时12分
436
+ FORMAT_YMDHM_CN: "yyyy年MM月dd日 HH时mm分",
437
+ //中文全称 如:2010年12月01日 23时15分06秒
438
+ FORMAT_YMDHMS_CN: "yyyy年MM月dd日 HH时mm分ss秒"
439
+ };
440
+
441
+ // src/utils/system-check.ts
442
+ function checkIsAndroid() {
443
+ return /android/.test(navigator.userAgent.toLowerCase());
444
+ }
445
+ function checkIsIOS() {
446
+ return /ios|iphone|ipad|ipod/.test(navigator.userAgent.toLowerCase());
447
+ }
448
+ function checkIsWindows() {
449
+ return navigator.platform.indexOf("Win") > -1;
450
+ }
451
+
452
+ // src/image/watermark.ts
453
+ var import_dayjs = __toESM(require_dayjs_min());
454
+ var import_zh_cn = __toESM(require_zh_cn());
455
+ import_dayjs.default.locale("zh-cn");
456
+ var Point = class {
457
+ constructor(x, y) {
458
+ this.x = x;
459
+ this.y = y;
460
+ }
461
+ };
462
+ var Size = class {
463
+ constructor(width, height) {
464
+ this.width = width;
465
+ this.height = height;
466
+ }
467
+ };
468
+ var clamp = (value, min, max) => Math.min(Math.max(value, min), max);
469
+ var subString = (str, startIndex, length) => {
470
+ if (checkIsUndefinedOrNull(length)) {
471
+ return str.substring(startIndex);
472
+ } else {
473
+ return str.substring(startIndex, startIndex + length);
474
+ }
475
+ };
476
+ var DEFAULT_ADDRESS_ICON = "data:image/png;base64,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";
477
+ var ColorMap = {
478
+ transparent: "#00000000",
479
+ white: "#FFFFFF",
480
+ black: "#000000",
481
+ darkgray: "#444444",
482
+ gray: "#888888",
483
+ lightgray: "#CCCCCC",
484
+ darkgrey: "#444444",
485
+ grey: "#888888",
486
+ lightgrey: "#CCCCCC",
487
+ red: "#FF0000",
488
+ green: "#00FF00",
489
+ blue: "#0000FF",
490
+ yellow: "#FFFF00",
491
+ cyan: "#00FFFF",
492
+ magenta: "#FF00FF",
493
+ aqua: "#00FFFF",
494
+ fuchsia: "#FF00FF",
495
+ lime: "#00FF00",
496
+ maroon: "#800000",
497
+ navy: "#000080",
498
+ olive: "#808000",
499
+ purple: "#800080",
500
+ silver: "#C0C0C0",
501
+ teal: "#008080",
502
+ orange: "#FF9933"
503
+ };
504
+ function getColorValue(key) {
505
+ for (const k of Object.getOwnPropertyNames(ColorMap)) {
506
+ if (k === key) {
507
+ return ColorMap[k];
508
+ }
509
+ }
510
+ return null;
511
+ }
512
+ var CONTENT_PADDING = 10;
513
+ var DEFAULT_PADDING = 2;
514
+ var DEFAULT_FONT_SIZE = 25;
515
+ var DEFAULT_CANVAS_SIZE = 480;
516
+ var DEFAULT_BACKGROUND_OPACITY = 128;
517
+ var LOGO_DEFAULT_PADDING = 4;
518
+ var WatermarkStyle = class {
519
+ //是否是简化配置
520
+ /**
521
+ * Watermark Style
522
+ * @param fontName
523
+ * @param fontWeight
524
+ * @param fontColor
525
+ * @param fontSize
526
+ * @param backgroundColor
527
+ * @param backgroundOpacity
528
+ * @param paddingTop
529
+ * @param paddingBottom
530
+ * @param position
531
+ * @param scale
532
+ * @param simplified
533
+ */
534
+ constructor(fontName, fontWeight, fontColor, fontSize, backgroundColor, backgroundOpacity, paddingTop, paddingBottom, position, scale, simplified) {
535
+ this.fontName = fontName;
536
+ this.fontWeight = fontWeight;
537
+ this.fontColor = fontColor;
538
+ this.fontSize = fontSize;
539
+ this.backgroundColor = backgroundColor;
540
+ this.backgroundOpacity = backgroundOpacity;
541
+ this.paddingTop = paddingTop;
542
+ this.paddingBottom = paddingBottom;
543
+ this.position = position;
544
+ this.scale = scale;
545
+ this.simplified = simplified;
546
+ }
547
+ };
548
+ var WatermarkImage = class {
549
+ constructor(image = "", width = 20, height = 20, position = 0 /* POSITION_LEFT */) {
550
+ this.image = image;
551
+ this.width = width;
552
+ this.height = height;
553
+ this.position = position;
554
+ }
555
+ };
556
+ var Watermark = class {
557
+ /**
558
+ * 水印对象,包含需要渲染的文本、图像,以及相应的style
559
+ * @param content
560
+ * @param watermarkStyle
561
+ */
562
+ constructor(content, watermarkStyle, watermarkImage) {
563
+ this.content = content;
564
+ this.style = watermarkStyle;
565
+ this.watermarkImage = watermarkImage;
566
+ }
567
+ };
568
+ var WatermarkContext = class {
569
+ /**
570
+ * 打水印需要的环境信息
571
+ * @param address
572
+ * @param watermarkTime
573
+ * @param humanName
574
+ * @param projectName
575
+ * @param logo
576
+ */
577
+ constructor(params) {
578
+ this.address = params.address;
579
+ this.watermarkTime = params.watermarkTime;
580
+ this.humanName = params.humanName;
581
+ this.projectName = params.projectName;
582
+ this.logo = params.logo;
583
+ this.applicationName = params.applicationName;
584
+ this.pixel = params.pixel;
585
+ this.width = params.width;
586
+ this.height = params.height;
587
+ }
588
+ };
589
+ var WatermarkOptions = class {
590
+ /**
591
+ * 水印配置项
592
+ * @param enabled, 是否开启水印
593
+ * @param watermarkConfigString,水印配置的字符串
594
+ * @param context,打水印需要的环境信息
595
+ */
596
+ constructor(params) {
597
+ this.enabled = params.enabled;
598
+ this.watermarkConfigString = params.watermarkConfigString;
599
+ this.context = params.context;
600
+ }
601
+ };
602
+ function getHeitiFontFamily(fontFamily = "") {
603
+ let defaultFontFamily;
604
+ if (checkIsWindows()) {
605
+ if (fontFamily.includes("黑体")) {
606
+ fontFamily = "";
607
+ }
608
+ defaultFontFamily = "'Roboto Black', 'Droid Sans'";
609
+ } else if (checkIsIOS()) {
610
+ if (fontFamily.includes("黑体")) {
611
+ fontFamily = "";
612
+ }
613
+ defaultFontFamily = "'PingFang SC Medium'";
614
+ } else if (checkIsAndroid()) {
615
+ defaultFontFamily = "'Roboto Black', 'Droid Sans'";
616
+ } else {
617
+ defaultFontFamily = '"PingFang SC Medium", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif';
618
+ }
619
+ return fontFamily ? `${fontFamily}, ${defaultFontFamily}` : defaultFontFamily;
620
+ }
621
+ function parseWatermarkStyle(styleString, canvasSize) {
622
+ if (!checkIsStringValid(styleString)) {
623
+ return null;
624
+ }
625
+ const styleParts = styleString.split("$");
626
+ if (styleParts.length <= 0) {
627
+ return null;
628
+ }
629
+ const scale = Math.min(canvasSize.width, canvasSize.height) / DEFAULT_CANVAS_SIZE;
630
+ if (parseInteger(styleParts[0], -1) !== -1) {
631
+ const fontSize = Math.round(
632
+ parseDecimal(styleParts[0], DEFAULT_FONT_SIZE) * scale
633
+ );
634
+ let position = "lefttop" /* LeftTop */;
635
+ if (styleParts[1]) {
636
+ position = styleParts[1];
637
+ }
638
+ let paddingTop = DEFAULT_PADDING * scale;
639
+ let paddingBottom = DEFAULT_PADDING * scale;
640
+ if (styleParts[2]) {
641
+ const paddingParts = styleParts[2].split("_");
642
+ paddingTop = parseInteger(paddingParts[0], DEFAULT_PADDING) * scale;
643
+ if (paddingParts[1]) {
644
+ paddingBottom = parseInteger(paddingParts[1], DEFAULT_PADDING) * scale;
645
+ }
646
+ }
647
+ const fontName = getHeitiFontFamily();
648
+ const fontWeight = "normal" /* Normal */;
649
+ const fontColor = ColorMap.transparent;
650
+ const backgroundColor = ColorMap.transparent;
651
+ const backgroundOpacity = 128;
652
+ return new WatermarkStyle(
653
+ fontName,
654
+ fontWeight,
655
+ fontColor,
656
+ fontSize,
657
+ backgroundColor,
658
+ backgroundOpacity,
659
+ paddingTop,
660
+ paddingBottom,
661
+ position,
662
+ scale,
663
+ true
664
+ );
665
+ } else {
666
+ const fontName = getHeitiFontFamily(styleParts[0]);
667
+ let fontWeight = "normal" /* Normal */;
668
+ if (styleParts[1]) {
669
+ fontWeight = styleParts[1];
670
+ }
671
+ let fontColor = ColorMap.white;
672
+ if (styleParts[2]) {
673
+ const color = getColorValue(styleParts[2]);
674
+ if (color) {
675
+ fontColor = color;
676
+ }
677
+ }
678
+ let fontSize = Math.round(DEFAULT_FONT_SIZE * scale);
679
+ if (styleParts[3]) {
680
+ fontSize = Math.round(
681
+ parseDecimal(styleParts[3], DEFAULT_FONT_SIZE) * scale
682
+ );
683
+ }
684
+ let backgroundColor = ColorMap.blue;
685
+ if (styleParts[4]) {
686
+ const color = getColorValue(styleParts[4]);
687
+ if (color) {
688
+ backgroundColor = color;
689
+ }
690
+ }
691
+ let position = "lefttop" /* LeftTop */;
692
+ if (styleParts[5]) {
693
+ position = styleParts[5];
694
+ }
695
+ let backgroundOpacity = 255;
696
+ if (styleParts[6]) {
697
+ let opacity = parseInteger(styleParts[6], DEFAULT_BACKGROUND_OPACITY);
698
+ opacity = clamp(opacity, 0, 255);
699
+ backgroundOpacity = opacity;
700
+ }
701
+ let paddingTop = DEFAULT_PADDING * scale;
702
+ let paddingBottom = DEFAULT_PADDING * scale;
703
+ if (styleParts[7]) {
704
+ const paddingParts = styleParts[7].split("_");
705
+ paddingTop = parseInteger(paddingParts[0], DEFAULT_PADDING) * scale;
706
+ if (paddingParts[1]) {
707
+ paddingBottom = parseInteger(paddingParts[1], DEFAULT_PADDING) * scale;
708
+ }
709
+ }
710
+ return new WatermarkStyle(
711
+ fontName,
712
+ fontWeight,
713
+ fontColor,
714
+ fontSize,
715
+ backgroundColor,
716
+ backgroundOpacity,
717
+ paddingTop,
718
+ paddingBottom,
719
+ position,
720
+ scale,
721
+ false
722
+ );
723
+ }
724
+ }
725
+ var TextScanner = class {
726
+ /**
727
+ * The content to scan
728
+ * @param text
729
+ */
730
+ constructor(text) {
731
+ this.text = text;
732
+ this.cursor = 0;
733
+ }
734
+ hasNext(obj) {
735
+ if (checkIsUndefinedOrNull(obj)) {
736
+ return this.cursor < this.text.length;
737
+ } else if (checkIsString(obj)) {
738
+ const str = obj;
739
+ const current = subString(this.text, this.cursor, str.length);
740
+ if (current === str) {
741
+ return true;
742
+ }
743
+ } else if (checkIsRegExp(obj)) {
744
+ const regex = obj;
745
+ const subText = subString(this.text, this.cursor);
746
+ const matchResults = subText.match(regex);
747
+ if (matchResults) {
748
+ if (matchResults.index === 0) {
749
+ return true;
750
+ }
751
+ }
752
+ }
753
+ return false;
754
+ }
755
+ next(obj) {
756
+ if (checkIsUndefinedOrNull(obj)) {
757
+ return subString(this.text, this.cursor, 1);
758
+ } else if (checkIsString(obj)) {
759
+ const str = obj;
760
+ if (subString(this.text, this.cursor, str.length) === str) {
761
+ return str;
762
+ }
763
+ } else if (checkIsRegExp(obj)) {
764
+ const regex = obj;
765
+ const subText = subString(this.text, this.cursor);
766
+ const matchResults = subText.match(regex);
767
+ if (matchResults) {
768
+ if (matchResults.index === 0) {
769
+ return matchResults;
770
+ }
771
+ }
772
+ }
773
+ return null;
774
+ }
775
+ skip(obj) {
776
+ if (checkIsUndefinedOrNull(obj)) {
777
+ this.cursor += 1;
778
+ } else if (checkIsStringValid(obj)) {
779
+ const str = obj;
780
+ this.cursor += str.length;
781
+ }
782
+ return this;
783
+ }
784
+ };
785
+ function transformFormatString(format) {
786
+ let transformString = format;
787
+ if (format.includes("d")) {
788
+ transformString = transformString.replace(/d/g, "D");
789
+ }
790
+ if (format.includes("y")) {
791
+ transformString = transformString.replace(/y/g, "Y");
792
+ }
793
+ if (format.includes("E")) {
794
+ transformString = transformString.replace(/E/g, "d");
795
+ }
796
+ return transformString;
797
+ }
798
+ function buildContent(contentConfigString, watermarkContext, style, canvasSize) {
799
+ let content = "";
800
+ const watermarkImage = new WatermarkImage();
801
+ if (contentConfigString.includes("{logo")) {
802
+ const start = contentConfigString.indexOf("{logo");
803
+ const end = contentConfigString.indexOf("}", start);
804
+ if (end != -1) {
805
+ const logoConfigWithBrace = contentConfigString.substring(start, end + 1);
806
+ if (contentConfigString.startsWith(logoConfigWithBrace) || contentConfigString.endsWith(logoConfigWithBrace)) {
807
+ if (contentConfigString.startsWith(logoConfigWithBrace)) {
808
+ watermarkImage.position = 0 /* POSITION_LEFT */;
809
+ } else {
810
+ watermarkImage.position = 1 /* POSITION_RIGHT */;
811
+ }
812
+ const imgWidthHeight = (style == null ? void 0 : style.fontSize) || 20;
813
+ watermarkImage.image = watermarkContext.logo;
814
+ watermarkImage.height = imgWidthHeight;
815
+ watermarkImage.width = imgWidthHeight;
816
+ }
817
+ contentConfigString = contentConfigString.replace(
818
+ logoConfigWithBrace,
819
+ ""
820
+ );
821
+ }
822
+ }
823
+ const scanner = new TextScanner(contentConfigString);
824
+ let steps = 0;
825
+ while (scanner.hasNext() && /* 防止scanner代码错误产生无限循环,设置一个最大scan步数*/
826
+ steps < contentConfigString.length) {
827
+ const dateRegex = new RegExp("date{(.*?)}|date" /* Date */);
828
+ if (scanner.hasNext(dateRegex)) {
829
+ const regexResult = scanner.next(dateRegex);
830
+ if (regexResult) {
831
+ const matchResults = regexResult;
832
+ let format = FORMAT.FORMAT_YMD;
833
+ if (matchResults && matchResults.length >= 2) {
834
+ if (checkIsStringValid(matchResults[1])) {
835
+ format = matchResults[1];
836
+ }
837
+ }
838
+ content += (0, import_dayjs.default)(watermarkContext.watermarkTime).format(
839
+ transformFormatString(format)
840
+ );
841
+ scanner.skip(matchResults.input);
842
+ }
843
+ } else if (scanner.hasNext("time" /* Time */)) {
844
+ const value = (0, import_dayjs.default)(watermarkContext.watermarkTime).format(
845
+ FORMAT.FORMAT_HM
846
+ );
847
+ content += value;
848
+ scanner.skip("time" /* Time */);
849
+ } else if (scanner.hasNext("address" /* Address */)) {
850
+ content += watermarkContext.address;
851
+ if (!watermarkImage.image) {
852
+ const imgWidthHeight = (style == null ? void 0 : style.fontSize) || 20;
853
+ watermarkImage.image = DEFAULT_ADDRESS_ICON;
854
+ watermarkImage.height = imgWidthHeight;
855
+ watermarkImage.width = imgWidthHeight;
856
+ }
857
+ scanner.skip("address" /* Address */);
858
+ } else if (scanner.hasNext("humanname" /* HumanName */)) {
859
+ content += watermarkContext.humanName;
860
+ scanner.skip("humanname" /* HumanName */);
861
+ } else if (scanner.hasNext("projectName" /* ProjectName */)) {
862
+ content += watermarkContext.projectName;
863
+ scanner.skip("projectName" /* ProjectName */);
864
+ } else if (scanner.hasNext("applicationName" /* ApplicationName */)) {
865
+ content += watermarkContext.applicationName;
866
+ scanner.skip("applicationName" /* ApplicationName */);
867
+ } else if (scanner.hasNext("pixel" /* Pixel */)) {
868
+ content += `${canvasSize.width} * ${canvasSize.height}`;
869
+ scanner.skip("pixel" /* Pixel */);
870
+ } else if (scanner.hasNext("width" /* Width */)) {
871
+ content += canvasSize.width;
872
+ scanner.skip("width" /* Width */);
873
+ } else if (scanner.hasNext("height" /* Height */)) {
874
+ content += canvasSize.height;
875
+ scanner.skip("height" /* Height */);
876
+ } else {
877
+ const nextChar = scanner.next();
878
+ if (checkIsString(nextChar)) {
879
+ content += nextChar;
880
+ }
881
+ scanner.skip();
882
+ }
883
+ steps++;
884
+ }
885
+ return { content, watermarkImage };
886
+ }
887
+ function parseWatermarks(watermarkConfigString, canvasSize, watermarkContext) {
888
+ const watermarks = [];
889
+ const configStringArray = watermarkConfigString.split("###");
890
+ for (let i = 0; i < configStringArray.length; i++) {
891
+ const configString = configStringArray[i];
892
+ const configParts = configString.split("*#*");
893
+ if (configParts.length === 2) {
894
+ const styleString = configParts[0];
895
+ const contentString = configParts[1];
896
+ const style = parseWatermarkStyle(styleString, canvasSize);
897
+ const data = buildContent(
898
+ contentString,
899
+ watermarkContext,
900
+ style,
901
+ canvasSize
902
+ );
903
+ if (style && (data.content || data.watermarkImage.image)) {
904
+ const watermark = new Watermark(
905
+ data.content,
906
+ style,
907
+ data.watermarkImage
908
+ );
909
+ watermarks.push(watermark);
910
+ }
911
+ }
912
+ }
913
+ return watermarks;
914
+ }
915
+ var Tile = class {
916
+ constructor(origin, size, lineHeight, lineWidths, lines, style, watermarkImage) {
917
+ this.origin = origin;
918
+ this.size = size;
919
+ this.lineHeight = lineHeight;
920
+ this.lineWidths = lineWidths;
921
+ this.lines = lines;
922
+ this.style = style;
923
+ this.watermarkImage = watermarkImage;
924
+ }
925
+ };
926
+ function getCanvasScale(canvas, len) {
927
+ const min = Math.min(canvas.width, canvas.height);
928
+ return min / DEFAULT_CANVAS_SIZE * len;
929
+ }
930
+ function buildTile(canvas, watermark) {
931
+ const { content, style, watermarkImage } = watermark;
932
+ const origin = new Point(0, 0);
933
+ const size = new Size(0, 0);
934
+ const lines = [];
935
+ const ctx = canvas.getContext("2d");
936
+ if (!ctx) {
937
+ return null;
938
+ }
939
+ let imageWidth = 0;
940
+ if (watermarkImage.image) {
941
+ imageWidth = watermarkImage.width + LOGO_DEFAULT_PADDING * style.scale;
942
+ }
943
+ ctx.font = `${style.fontWeight} ${style.fontSize}px ${style.fontName}`;
944
+ const contentPadding = getCanvasScale(canvas, CONTENT_PADDING);
945
+ const contentWidth = canvas.width - contentPadding * 2 - imageWidth;
946
+ const lineHeight = ctx.measureText("M").width;
947
+ const lineWidths = [];
948
+ let temp = "";
949
+ let lastWidth = 0;
950
+ for (let i = 0; i < content.length; i++) {
951
+ const lineWidth = ctx.measureText(temp).width;
952
+ if (lineWidth >= contentWidth) {
953
+ const line = temp.substring(0, temp.length - 1);
954
+ const preLineWidth = ctx.measureText(line).width;
955
+ lines.push(line);
956
+ lineWidths.push(preLineWidth);
957
+ temp = temp.substring(temp.length - 1);
958
+ }
959
+ lastWidth = lineWidth;
960
+ temp += content[i];
961
+ }
962
+ lines.push(temp);
963
+ lineWidths.push(lastWidth);
964
+ size.width = contentWidth;
965
+ size.height = lines.length * lineHeight;
966
+ return new Tile(
967
+ origin,
968
+ size,
969
+ lineHeight,
970
+ lineWidths,
971
+ lines,
972
+ style,
973
+ watermarkImage
974
+ );
975
+ }
976
+ function getAxisPoint(canvasWidth, width, tile, origin, line) {
977
+ const { style, watermarkImage, lines, lineHeight } = tile;
978
+ const padding = (CONTENT_PADDING + DEFAULT_PADDING) * style.scale;
979
+ let axisPoint = new Point(padding, origin.y);
980
+ if (style.position.startsWith("center")) {
981
+ axisPoint = new Point(canvasWidth / 2, origin.y);
982
+ } else if (style.position.startsWith("right")) {
983
+ axisPoint = new Point(canvasWidth - padding, origin.y);
984
+ }
985
+ const imagePoint = new Point(axisPoint.x, axisPoint.y);
986
+ if (watermarkImage.image) {
987
+ const maxWidth = Math.max(...tile.lineWidths);
988
+ if (watermarkImage.position === 0 /* POSITION_LEFT */) {
989
+ if (style.position.startsWith("left")) {
990
+ axisPoint.x = axisPoint.x + watermarkImage.width + LOGO_DEFAULT_PADDING * style.scale;
991
+ } else if (style.position.startsWith("center")) {
992
+ if (line) {
993
+ axisPoint.x = axisPoint.x + watermarkImage.width / 2 + LOGO_DEFAULT_PADDING / 2 * style.scale;
994
+ imagePoint.x = lines.length === 1 ? imagePoint.x - width / 2 - watermarkImage.width - LOGO_DEFAULT_PADDING / 2 * style.scale : imagePoint.x - maxWidth / 2 - watermarkImage.width / 2 - LOGO_DEFAULT_PADDING / 2 * style.scale;
995
+ } else {
996
+ imagePoint.x = imagePoint.x - watermarkImage.width / 2;
997
+ }
998
+ } else {
999
+ if (line) {
1000
+ imagePoint.x = lines.length === 1 ? imagePoint.x - width - 2 * watermarkImage.width - LOGO_DEFAULT_PADDING / 2 * style.scale : imagePoint.x - maxWidth - watermarkImage.width - LOGO_DEFAULT_PADDING / 2 * style.scale;
1001
+ } else {
1002
+ imagePoint.x = imagePoint.x - watermarkImage.width;
1003
+ }
1004
+ }
1005
+ } else {
1006
+ if (style.position.startsWith("left")) {
1007
+ imagePoint.x = lines.length === 1 ? axisPoint.x + width + watermarkImage.width + LOGO_DEFAULT_PADDING * style.scale : axisPoint.x + maxWidth + LOGO_DEFAULT_PADDING * style.scale;
1008
+ } else if (style.position.startsWith("center")) {
1009
+ axisPoint.x = axisPoint.x - watermarkImage.width / 2;
1010
+ imagePoint.x = lines.length === 1 ? imagePoint.x + width / 2 + LOGO_DEFAULT_PADDING * style.scale : imagePoint.x + maxWidth / 2 - watermarkImage.width / 2 + LOGO_DEFAULT_PADDING * style.scale;
1011
+ } else {
1012
+ axisPoint.x = axisPoint.x - watermarkImage.width;
1013
+ imagePoint.x = imagePoint.x - watermarkImage.width + LOGO_DEFAULT_PADDING / 2 * style.scale;
1014
+ }
1015
+ }
1016
+ if (lines.length > 1) {
1017
+ imagePoint.y = imagePoint.y + lines.length * lineHeight / 2 - watermarkImage.height / 2;
1018
+ }
1019
+ }
1020
+ return {
1021
+ text: axisPoint,
1022
+ image: imagePoint
1023
+ };
1024
+ }
1025
+ function getTextAlign(style) {
1026
+ let align = "left";
1027
+ if (style.position.startsWith("center")) {
1028
+ align = "center";
1029
+ } else if (style.position.startsWith("right")) {
1030
+ align = "right";
1031
+ }
1032
+ return align;
1033
+ }
1034
+ function loadImage(url) {
1035
+ return new Promise((resolve, reject) => {
1036
+ const img = new Image();
1037
+ img.src = url;
1038
+ img.crossOrigin = "anonymous";
1039
+ img.onload = function(e) {
1040
+ if (img.complete) {
1041
+ resolve(img);
1042
+ } else {
1043
+ console.error(e);
1044
+ reject(new Error("文件加载失败"));
1045
+ }
1046
+ };
1047
+ });
1048
+ }
1049
+ function drawLine(canvas, line, width, origin, tile, drawImage) {
1050
+ return __async(this, null, function* () {
1051
+ const ctx = canvas.getContext("2d");
1052
+ if (!ctx) {
1053
+ return;
1054
+ }
1055
+ const { style, watermarkImage } = tile;
1056
+ ctx.textBaseline = "top";
1057
+ ctx.font = `${style.fontWeight} ${style.fontSize}px ${style.fontName}`;
1058
+ const point = getAxisPoint(canvas.width, width, tile, origin, line);
1059
+ ctx.textAlign = getTextAlign(style);
1060
+ if (watermarkImage.image && drawImage) {
1061
+ const image = yield loadImage(watermarkImage.image);
1062
+ ctx.drawImage(
1063
+ image,
1064
+ Math.round(point.image.x),
1065
+ Math.round(point.image.y),
1066
+ watermarkImage.width,
1067
+ watermarkImage.height
1068
+ );
1069
+ }
1070
+ if (style.simplified) {
1071
+ ctx.shadowBlur = 4;
1072
+ ctx.shadowColor = "rgba(0, 0, 0, 0.5)";
1073
+ const offset = clamp(style.fontSize / 40, 2, 4);
1074
+ ctx.shadowOffsetY = offset;
1075
+ ctx.shadowOffsetX = offset;
1076
+ ctx.fillStyle = "rgba(255,255,255, 0.5)";
1077
+ } else {
1078
+ ctx.fillStyle = style.fontColor;
1079
+ }
1080
+ ctx.fillText(line, Math.round(point.text.x), Math.round(point.text.y));
1081
+ });
1082
+ }
1083
+ function hexToRGB(hex, alpha) {
1084
+ const r = parseInt(hex.slice(1, 3), 16), g = parseInt(hex.slice(3, 5), 16), b = parseInt(hex.slice(5, 7), 16);
1085
+ if (alpha) {
1086
+ return "rgba(" + r + ", " + g + ", " + b + ", " + alpha + ")";
1087
+ } else {
1088
+ return "rgb(" + r + ", " + g + ", " + b + ")";
1089
+ }
1090
+ }
1091
+ function drawBackground(canvas, tile) {
1092
+ const ctx = canvas.getContext("2d");
1093
+ if (!ctx) {
1094
+ return;
1095
+ }
1096
+ let { backgroundColor } = tile.style;
1097
+ let backgroundOpacity = parseDecimal(
1098
+ String(tile.style.backgroundOpacity),
1099
+ -1
1100
+ );
1101
+ if (backgroundOpacity > 255) {
1102
+ backgroundOpacity = 255;
1103
+ }
1104
+ const { style } = tile;
1105
+ const { paddingTop, paddingBottom } = style;
1106
+ if (backgroundColor !== "transparent") {
1107
+ if (backgroundColor.startsWith("#") && backgroundOpacity >= 0) {
1108
+ backgroundColor = hexToRGB(backgroundColor, backgroundOpacity / 255);
1109
+ }
1110
+ ctx.fillStyle = backgroundColor;
1111
+ const padding = (CONTENT_PADDING + DEFAULT_PADDING) * style.scale;
1112
+ const paddingScale = tile.style.fontSize / DEFAULT_FONT_SIZE;
1113
+ for (let j = 0; j < tile.lineWidths.length; j++) {
1114
+ const { lineHeight } = tile;
1115
+ const lineWidth = tile.lineWidths[j];
1116
+ let paddingRight = 30 * paddingScale;
1117
+ let paddingLeft = 10 * paddingScale;
1118
+ let axisPoint = new Point(padding - paddingLeft, tile.origin.y);
1119
+ if (style.position.startsWith("center")) {
1120
+ paddingLeft = 20 * paddingScale;
1121
+ paddingRight = 20 * paddingScale;
1122
+ axisPoint = new Point(
1123
+ (canvas.width - lineWidth) / 2 - paddingLeft,
1124
+ tile.origin.y
1125
+ );
1126
+ } else if (style.position.startsWith("right")) {
1127
+ paddingLeft = 30 * paddingScale;
1128
+ paddingRight = 10 * paddingScale;
1129
+ axisPoint = new Point(
1130
+ canvas.width - lineWidth - padding - paddingLeft,
1131
+ tile.origin.y
1132
+ );
1133
+ }
1134
+ if (j === 0) {
1135
+ const top = checkIsWindows() ? paddingTop + 6 * style.scale : paddingTop;
1136
+ ctx.fillRect(
1137
+ axisPoint.x,
1138
+ axisPoint.y - paddingTop > 0 ? axisPoint.y - top : 0,
1139
+ paddingLeft + lineWidth + paddingRight,
1140
+ top
1141
+ );
1142
+ }
1143
+ ctx.fillRect(
1144
+ axisPoint.x,
1145
+ axisPoint.y + j * lineHeight,
1146
+ paddingLeft + lineWidth + paddingRight,
1147
+ lineHeight
1148
+ );
1149
+ if (j === tile.lineWidths.length - 1) {
1150
+ const bottom = checkIsIOS() ? paddingBottom + 4 * style.scale : paddingBottom;
1151
+ ctx.fillRect(
1152
+ axisPoint.x,
1153
+ axisPoint.y + (j + 1) * lineHeight,
1154
+ paddingLeft + lineWidth + paddingRight,
1155
+ bottom
1156
+ );
1157
+ }
1158
+ }
1159
+ }
1160
+ }
1161
+ function drawTile(canvas, tile) {
1162
+ return __async(this, null, function* () {
1163
+ if (!tile.style.simplified) {
1164
+ drawBackground(canvas, tile);
1165
+ }
1166
+ for (let i = 0; i < tile.lines.length; i++) {
1167
+ const origin = new Point(
1168
+ tile.origin.x,
1169
+ i * tile.lineHeight + tile.origin.y
1170
+ );
1171
+ yield drawLine(
1172
+ canvas,
1173
+ tile.lines[i],
1174
+ tile.lineWidths[i],
1175
+ origin,
1176
+ tile,
1177
+ i === 0
1178
+ );
1179
+ }
1180
+ });
1181
+ }
1182
+ function drawGroupedWatermarks(canvas, watermarks, groupPosition) {
1183
+ return __async(this, null, function* () {
1184
+ if (!watermarks || watermarks.length === 0) {
1185
+ return;
1186
+ }
1187
+ const tiles = [];
1188
+ let totalHeight = 0;
1189
+ for (let i = 0; i < watermarks.length; i++) {
1190
+ const watermark = watermarks[i];
1191
+ const tile = buildTile(canvas, watermark);
1192
+ if (tile) {
1193
+ tiles.push(tile);
1194
+ totalHeight += tile.size.height + CONTENT_PADDING;
1195
+ }
1196
+ }
1197
+ if (totalHeight <= 0) {
1198
+ console.error("watermarks height " + totalHeight);
1199
+ console.error(JSON.stringify(watermarks));
1200
+ return;
1201
+ }
1202
+ const contentPadding = getCanvasScale(canvas, CONTENT_PADDING);
1203
+ let baseOrigin = new Point(contentPadding, contentPadding);
1204
+ if (groupPosition === "center" /* Center */) {
1205
+ baseOrigin = new Point(
1206
+ contentPadding,
1207
+ Math.round((canvas.height - totalHeight) / 2)
1208
+ );
1209
+ } else if (groupPosition === "bottom" /* Bottom */) {
1210
+ baseOrigin = new Point(
1211
+ contentPadding,
1212
+ canvas.height - totalHeight - contentPadding
1213
+ );
1214
+ } else if (groupPosition === "top" /* Top */) {
1215
+ baseOrigin = new Point(contentPadding, contentPadding);
1216
+ }
1217
+ let lastMarginTop = 0;
1218
+ for (let i = 0; i < tiles.length; i++) {
1219
+ const tile = tiles[i];
1220
+ lastMarginTop += tile.style.paddingTop;
1221
+ tile.origin = new Point(
1222
+ tile.origin.x + baseOrigin.x,
1223
+ lastMarginTop + baseOrigin.y
1224
+ );
1225
+ lastMarginTop += tile.size.height;
1226
+ lastMarginTop += tile.style.paddingBottom;
1227
+ }
1228
+ for (let i = 0; i < tiles.length; i++) {
1229
+ const tile = tiles[i];
1230
+ yield drawTile(canvas, tile);
1231
+ }
1232
+ });
1233
+ }
1234
+ function groupingWatermarks(watermarks) {
1235
+ const topList = [];
1236
+ const centerList = [];
1237
+ const bottomList = [];
1238
+ for (let i = 0; i < watermarks.length; i++) {
1239
+ const watermark = watermarks[i];
1240
+ if (watermark.style.position.endsWith("top")) {
1241
+ topList.push(watermark);
1242
+ } else if (watermark.style.position.endsWith("center")) {
1243
+ centerList.push(watermark);
1244
+ } else if (watermark.style.position.endsWith("bottom")) {
1245
+ bottomList.push(watermark);
1246
+ }
1247
+ }
1248
+ return {
1249
+ ["top" /* Top */]: topList,
1250
+ ["center" /* Center */]: centerList,
1251
+ ["bottom" /* Bottom */]: bottomList
1252
+ };
1253
+ }
1254
+ function renderWatermark(canvas, options) {
1255
+ return __async(this, null, function* () {
1256
+ if (!options.enabled || options.watermarkConfigString === "no") {
1257
+ return Promise.resolve(canvas);
1258
+ }
1259
+ let { watermarkConfigString } = options;
1260
+ if (watermarkConfigString === "default") {
1261
+ watermarkConfigString = "50$lefttop$50*#*time###25$lefttop*#*date";
1262
+ }
1263
+ const watermarks = parseWatermarks(
1264
+ watermarkConfigString,
1265
+ new Size(canvas.width, canvas.height),
1266
+ options.context
1267
+ );
1268
+ const groupedWatermarks = groupingWatermarks(watermarks);
1269
+ yield drawGroupedWatermarks(
1270
+ canvas,
1271
+ groupedWatermarks["top" /* Top */],
1272
+ "top" /* Top */
1273
+ );
1274
+ yield drawGroupedWatermarks(
1275
+ canvas,
1276
+ groupedWatermarks["center" /* Center */],
1277
+ "center" /* Center */
1278
+ );
1279
+ yield drawGroupedWatermarks(
1280
+ canvas,
1281
+ groupedWatermarks["bottom" /* Bottom */],
1282
+ "bottom" /* Bottom */
1283
+ );
1284
+ return Promise.resolve(canvas);
1285
+ });
1286
+ }
1287
+ function checkWatermarkConfigSupported(watermarkConfigString) {
1288
+ const configStringArray = watermarkConfigString.split("###");
1289
+ for (let i = 0; i < configStringArray.length; i++) {
1290
+ const configString = configStringArray[i];
1291
+ const configParts = configString.split("*#*");
1292
+ if (configParts.length === 2) {
1293
+ const styleString = configParts[0];
1294
+ const styleParts = styleString.split("$");
1295
+ if (styleParts.length <= 0) {
1296
+ console.error("水印配置不合法");
1297
+ return false;
1298
+ }
1299
+ }
1300
+ }
1301
+ return true;
1302
+ }
1303
+
1304
+ // src/image/image-util.ts
1305
+ function file2DataURL(file) {
1306
+ return new Promise((resolve, reject) => {
1307
+ const a = new FileReader();
1308
+ a.onload = function(res) {
1309
+ if (res && res.target) {
1310
+ resolve(res.target.result);
1311
+ } else {
1312
+ reject(new Error("读取文件url失败"));
1313
+ }
1314
+ };
1315
+ a.readAsDataURL(file);
1316
+ });
1317
+ }
1318
+ function file2Image(file) {
1319
+ return new Promise((resolve, reject) => {
1320
+ file2DataURL(file).then((url) => {
1321
+ const img = new Image();
1322
+ img.src = url;
1323
+ img.onload = function() {
1324
+ if (img.complete) {
1325
+ resolve(img);
1326
+ } else {
1327
+ reject(new Error("文件加载失败"));
1328
+ }
1329
+ };
1330
+ }).catch(reject);
1331
+ });
1332
+ }
1333
+ function image2file(img, fileName, lastModified, type = "image/jpeg", quality = 0.8) {
1334
+ return image2Canvas(img, type).then((canvas) => {
1335
+ return canvas2File(canvas, fileName, lastModified, type, quality);
1336
+ });
1337
+ }
1338
+ function image2Canvas(img, type, width, height) {
1339
+ const canvas = document.createElement("canvas");
1340
+ const _width = width || img.width;
1341
+ const _height = height || img.height;
1342
+ canvas.width = _width;
1343
+ canvas.height = _height;
1344
+ const ctx = canvas.getContext("2d");
1345
+ if (ctx) {
1346
+ ctx.fillStyle = "transparent";
1347
+ if (type === "image/jpeg") {
1348
+ ctx.fillStyle = "#fff";
1349
+ }
1350
+ ctx.drawImage(img, 0, 0, _width, _height);
1351
+ return Promise.resolve(canvas);
1352
+ } else {
1353
+ return Promise.reject(null);
1354
+ }
1355
+ }
1356
+ function canvas2Image(canvas, type = "image/jpeg", quality = 0.8) {
1357
+ const image = new Image();
1358
+ image.src = canvas.toDataURL(type, quality);
1359
+ return Promise.resolve(image);
1360
+ }
1361
+ function canvas2File(canvas, fileName, lastModified, type = "image/jpeg", quality = 0.8) {
1362
+ return new Promise((resolve, reject) => {
1363
+ canvas.toBlob(
1364
+ (blob) => {
1365
+ if (!blob) {
1366
+ reject(new Error("canvas文件导出失败"));
1367
+ } else {
1368
+ const file = new File([blob], fileName, { lastModified, type });
1369
+ resolve(file);
1370
+ }
1371
+ },
1372
+ type,
1373
+ quality
1374
+ );
1375
+ });
1376
+ }
1377
+ function resize(img, {
1378
+ inputType = "image/jpeg",
1379
+ imageWidth = -1,
1380
+ imageHeight = -1,
1381
+ sideLengthLimit = 640,
1382
+ baseOnShortSide = true,
1383
+ // 是否以短边为基准缩放
1384
+ resultType = "image"
1385
+ }) {
1386
+ let scale = 1;
1387
+ const scaleBaseFunc = baseOnShortSide ? Math.min : Math.max;
1388
+ if (imageWidth > 0 && imageHeight > 0) {
1389
+ scale = sideLengthLimit / scaleBaseFunc(imageWidth, imageHeight);
1390
+ } else if (img.width > 0 && img.height > 0) {
1391
+ scale = sideLengthLimit / scaleBaseFunc(img.width, img.height);
1392
+ imageWidth = img.width;
1393
+ imageHeight = img.height;
1394
+ } else {
1395
+ return Promise.reject(new Error("image width/height 无效"));
1396
+ }
1397
+ const targetWidth = scale > 1 ? imageWidth : imageWidth * scale;
1398
+ const targetHeight = scale > 1 ? imageHeight : imageHeight * scale;
1399
+ if (resultType === "image") {
1400
+ return image2Canvas(img, inputType, targetWidth, targetHeight).then(
1401
+ (canvas) => {
1402
+ return canvas2Image(canvas);
1403
+ }
1404
+ );
1405
+ } else {
1406
+ return image2Canvas(img, inputType, targetWidth, targetHeight);
1407
+ }
1408
+ }
1409
+
1410
+ // src/image/image-processor.ts
1411
+ var MAX_SIDE_LENGTH = 1920;
1412
+ var MIN_SIDE_LENGTH = 480;
1413
+ var PHOTO_FILE_SIZE_LIMIT = 1e3;
1414
+ var DEFAULT_JPEG_QUALITY = 0.8;
1415
+ var MIN_JPEG_QUALITY = 0.1;
1416
+ var JPEG_QUALITY_STEP = 0.05;
1417
+ var ResizeOptions = class {
1418
+ // 最大边长
1419
+ constructor(maxSideLength) {
1420
+ if (checkIsUndefinedOrNull(maxSideLength)) {
1421
+ this.maxSideLength = MAX_SIDE_LENGTH;
1422
+ } else {
1423
+ this.maxSideLength = maxSideLength;
1424
+ if (this.maxSideLength > MAX_SIDE_LENGTH) {
1425
+ this.maxSideLength = MAX_SIDE_LENGTH;
1426
+ } else if (this.maxSideLength < MIN_SIDE_LENGTH) {
1427
+ this.maxSideLength = MIN_SIDE_LENGTH;
1428
+ }
1429
+ }
1430
+ }
1431
+ };
1432
+ var CompressOptions = class {
1433
+ // 图片大小限制,单位kb
1434
+ constructor(photoFileSizeLimit) {
1435
+ if (checkIsUndefinedOrNull(photoFileSizeLimit)) {
1436
+ this.photoFileSizeLimit = PHOTO_FILE_SIZE_LIMIT;
1437
+ } else {
1438
+ this.photoFileSizeLimit = photoFileSizeLimit;
1439
+ }
1440
+ }
1441
+ };
1442
+ var ImageProcessor = class {
1443
+ // 压缩图片的配置
1444
+ constructor(file, resizeOptions, watermarkOptions, compressOptions) {
1445
+ this.file = file;
1446
+ this.resizeOptions = resizeOptions;
1447
+ this.watermarkOptions = watermarkOptions;
1448
+ this.compressOptions = compressOptions;
1449
+ }
1450
+ process() {
1451
+ const filename = this.file.name;
1452
+ const { lastModified } = this.file;
1453
+ let fileType = this.file.type;
1454
+ if (this.file.size > this.compressOptions.photoFileSizeLimit * 1024) {
1455
+ fileType = "image/jpeg";
1456
+ }
1457
+ if (fileType === "image/gif") {
1458
+ fileType = "image/png";
1459
+ }
1460
+ return file2Image(this.file).then((img) => {
1461
+ return resize(img, {
1462
+ inputType: fileType,
1463
+ sideLengthLimit: this.resizeOptions.maxSideLength,
1464
+ resultType: "canvas"
1465
+ });
1466
+ }).then((result) => __async(this, null, function* () {
1467
+ const canvas = result;
1468
+ return yield renderWatermark(canvas, this.watermarkOptions);
1469
+ })).then((canvas) => {
1470
+ const exportFilename = filename.replace(/\./g, "-") + ".jpg";
1471
+ return this.compress(
1472
+ canvas,
1473
+ exportFilename,
1474
+ lastModified,
1475
+ fileType,
1476
+ DEFAULT_JPEG_QUALITY
1477
+ );
1478
+ });
1479
+ }
1480
+ compress(canvas, filename, lastModified, type, quality) {
1481
+ return canvas2File(canvas, filename, lastModified, type, quality).then(
1482
+ (file) => {
1483
+ if (file.size > this.compressOptions.photoFileSizeLimit * 1024 && quality - JPEG_QUALITY_STEP > MIN_JPEG_QUALITY) {
1484
+ return this.compress(
1485
+ canvas,
1486
+ filename,
1487
+ lastModified,
1488
+ type,
1489
+ quality - JPEG_QUALITY_STEP
1490
+ );
1491
+ } else {
1492
+ return Promise.resolve(file);
1493
+ }
1494
+ }
1495
+ );
1496
+ }
1497
+ };
1498
+ export {
1499
+ CompressOptions,
1500
+ ImageProcessor,
1501
+ ResizeOptions,
1502
+ WatermarkContext,
1503
+ WatermarkOptions,
1504
+ canvas2File,
1505
+ canvas2Image,
1506
+ checkWatermarkConfigSupported,
1507
+ file2DataURL,
1508
+ file2Image,
1509
+ image2Canvas,
1510
+ image2file,
1511
+ resize
1512
+ };