xydata-tools-uniapp 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -0
- package/dist/assets/defaultAddPicBg.png +0 -0
- package/dist/assets/file-icon/document.png +0 -0
- package/dist/assets/file-icon/image.png +0 -0
- package/dist/assets/file-icon/ms-excel.png +0 -0
- package/dist/assets/file-icon/ms-powerpoint.png +0 -0
- package/dist/assets/file-icon/ms-word.png +0 -0
- package/dist/assets/file-icon/pdf.png +0 -0
- package/dist/assets/file-icon/video.png +0 -0
- package/dist/assets/file-icon/zip.png +0 -0
- package/dist/assets/loading.png +0 -0
- package/dist/assets/uploadVideoBg.png +0 -0
- package/dist/assets/videoPlay.png +0 -0
- package/dist/components/uni-app/file-picker/file-picker.vue +633 -0
- package/dist/components/uni-app/file-picker/styles.scss +196 -0
- package/dist/components/uni-app/media-picker/media-picker.vue +1645 -0
- package/dist/components/uni-app/media-picker/shmily-drag-media.vue +924 -0
- package/dist/components/uni-app/media-picker/styles.scss +531 -0
- package/dist/components/uni-app/watermark/index.js +633 -0
- package/dist/index.d.ts +452 -0
- package/dist/index.js +9 -0
- package/dist/shims-vue.d.ts +8 -0
- package/dist/types/components/uni-app/watermark/index.d.ts +2 -0
- package/dist/types/utils/watermark-shared.d.ts +42 -0
- package/dist/utils/watermark-shared.js +346 -0
- package/package.json +42 -0
|
@@ -0,0 +1,633 @@
|
|
|
1
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
2
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
3
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
4
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
5
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
6
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
7
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
8
|
+
/**
|
|
9
|
+
* watermark/index.js
|
|
10
|
+
* uni-app 端水印渲染层。
|
|
11
|
+
* 复用 src/utils/watermark-shared.js 的配置规范化与布局计算逻辑,
|
|
12
|
+
* 通过运行时判断平台,实现两套绘制出口:
|
|
13
|
+
* - H5:原生离屏 canvas + toBlob -> blob URL(避免 canvasToTempFilePath 返回 dataURL 的上传兼容问题)
|
|
14
|
+
* - 非 H5(微信小程序 / App 等):uni.getImageInfo + uni.createCanvasContext + uni.canvasToTempFilePath
|
|
15
|
+
*
|
|
16
|
+
* 注意:本文件会被 father 的 babel 统一编译,因此不使用 uni-app 的条件编译注释(#ifdef/#ifndef),
|
|
17
|
+
* 改为运行时判断,避免两个分支的同名 const 在编译期产生重复声明。
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { normalizeWatermarkConfig, resolveSpacing, resolveTextPosition, resolveImageSize, resolveBoxPosition, resolveFontSize, resolveStrokeWidth, isFullscreenWatermarkItem, isImageWatermarkItem } from "../../../utils/watermark-shared.js";
|
|
21
|
+
var toRadians = function toRadians(deg) {
|
|
22
|
+
return (deg || 0) * Math.PI / 180;
|
|
23
|
+
};
|
|
24
|
+
var drawTextWithStrokeH5 = function drawTextWithStrokeH5(ctx, text, x, y, item, fontSize) {
|
|
25
|
+
var strokeWidth = resolveStrokeWidth(item, fontSize);
|
|
26
|
+
if (strokeWidth > 0 && typeof ctx.strokeText === 'function') {
|
|
27
|
+
ctx.strokeStyle = item.strokeColor;
|
|
28
|
+
ctx.lineWidth = strokeWidth;
|
|
29
|
+
ctx.strokeText(text, x, y);
|
|
30
|
+
}
|
|
31
|
+
ctx.fillText(text, x, y);
|
|
32
|
+
};
|
|
33
|
+
var drawTextWithStrokeMini = function drawTextWithStrokeMini(ctx, text, x, y, item, fontSize) {
|
|
34
|
+
var strokeWidth = resolveStrokeWidth(item, fontSize);
|
|
35
|
+
var canStroke = strokeWidth > 0 && typeof ctx.strokeText === 'function' && typeof ctx.setStrokeStyle === 'function' && typeof ctx.setLineWidth === 'function';
|
|
36
|
+
if (canStroke) {
|
|
37
|
+
ctx.setStrokeStyle(item.strokeColor);
|
|
38
|
+
ctx.setLineWidth(strokeWidth);
|
|
39
|
+
ctx.strokeText(text, x, y);
|
|
40
|
+
}
|
|
41
|
+
ctx.fillText(text, x, y);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** 是否为 H5 运行环境 */
|
|
45
|
+
var isH5 = function isH5() {
|
|
46
|
+
return typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 根据图片路径/信息推断导出格式。
|
|
51
|
+
* 优先保持原图格式(与 PC 端 applyImageWatermark 的 outputType 逻辑一致),
|
|
52
|
+
* 避免强制转 PNG 导致后端按扩展名校验失败或文件体积异常。
|
|
53
|
+
* @param {String|Object} source - 图片路径,或 getImageInfo 返回的图片信息对象
|
|
54
|
+
* @returns {{ ext: String, mime: String }} 扩展名与 MIME 类型
|
|
55
|
+
*/
|
|
56
|
+
var resolveOutputFormat = function resolveOutputFormat(source) {
|
|
57
|
+
var type = source && (source.type || source.mimeType) || '';
|
|
58
|
+
var path = source && (source.path || source.src) || source || '';
|
|
59
|
+
var lowerType = "".concat(type).toLowerCase();
|
|
60
|
+
var lowerPath = "".concat(path).toLowerCase();
|
|
61
|
+
var extOf = function extOf(e) {
|
|
62
|
+
switch (e) {
|
|
63
|
+
case 'png':
|
|
64
|
+
return {
|
|
65
|
+
ext: 'png',
|
|
66
|
+
mime: 'image/png'
|
|
67
|
+
};
|
|
68
|
+
case 'webp':
|
|
69
|
+
return {
|
|
70
|
+
ext: 'webp',
|
|
71
|
+
mime: 'image/webp'
|
|
72
|
+
};
|
|
73
|
+
case 'bmp':
|
|
74
|
+
return {
|
|
75
|
+
ext: 'bmp',
|
|
76
|
+
mime: 'image/bmp'
|
|
77
|
+
};
|
|
78
|
+
default:
|
|
79
|
+
return {
|
|
80
|
+
ext: 'jpg',
|
|
81
|
+
mime: 'image/jpeg'
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// 1) 优先从 mimeType/type 推断
|
|
87
|
+
if (lowerType.indexOf('png') !== -1) return extOf('png');
|
|
88
|
+
if (lowerType.indexOf('webp') !== -1) return extOf('webp');
|
|
89
|
+
if (lowerType.indexOf('bmp') !== -1) return extOf('bmp');
|
|
90
|
+
if (lowerType.indexOf('jpeg') !== -1 || lowerType.indexOf('jpg') !== -1) return extOf('jpg');
|
|
91
|
+
|
|
92
|
+
// 2) 其次从路径扩展名推断(临时路径如 wxfile://tmp_xxx.jpg)
|
|
93
|
+
var extMatch = lowerPath.match(/\.([a-z0-9]+)(?:[?#].*)?$/);
|
|
94
|
+
if (extMatch) {
|
|
95
|
+
return extOf(extMatch[1]);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// 3) 默认 jpg
|
|
99
|
+
return extOf('jpg');
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* 解析错误处理结果:返回 false 表示阻止上传,其余视为降级上传原图
|
|
104
|
+
*/
|
|
105
|
+
export var resolveWatermarkError = /*#__PURE__*/function () {
|
|
106
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(error, context) {
|
|
107
|
+
var _context$watermark;
|
|
108
|
+
var handler;
|
|
109
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
110
|
+
while (1) switch (_context.prev = _context.next) {
|
|
111
|
+
case 0:
|
|
112
|
+
console.error('[MediaPicker watermark error]', error);
|
|
113
|
+
handler = context === null || context === void 0 || (_context$watermark = context.watermark) === null || _context$watermark === void 0 ? void 0 : _context$watermark.onWatermarkError;
|
|
114
|
+
if (!(typeof handler !== 'function')) {
|
|
115
|
+
_context.next = 4;
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
return _context.abrupt("return", true);
|
|
119
|
+
case 4:
|
|
120
|
+
return _context.abrupt("return", handler(error, context));
|
|
121
|
+
case 5:
|
|
122
|
+
case "end":
|
|
123
|
+
return _context.stop();
|
|
124
|
+
}
|
|
125
|
+
}, _callee);
|
|
126
|
+
}));
|
|
127
|
+
return function resolveWatermarkError(_x, _x2) {
|
|
128
|
+
return _ref.apply(this, arguments);
|
|
129
|
+
};
|
|
130
|
+
}();
|
|
131
|
+
|
|
132
|
+
/* ============================================================
|
|
133
|
+
* 通用:文字宽度测量(H5 与小程序 ctx 接口差异兼容)
|
|
134
|
+
* ============================================================ */
|
|
135
|
+
var measureTextWidthH5 = function measureTextWidthH5(ctx, text) {
|
|
136
|
+
if (ctx && typeof ctx.measureText === 'function') {
|
|
137
|
+
try {
|
|
138
|
+
return ctx.measureText(text).width || 0;
|
|
139
|
+
} catch (e) {
|
|
140
|
+
return 0;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return 0;
|
|
144
|
+
};
|
|
145
|
+
var measureTextWidthMini = function measureTextWidthMini(ctx, text, fontSize) {
|
|
146
|
+
if (ctx && typeof ctx.measureText === 'function') {
|
|
147
|
+
try {
|
|
148
|
+
var measured = ctx.measureText(text);
|
|
149
|
+
var width = measured && _typeof(measured) === 'object' ? measured.width : measured;
|
|
150
|
+
if (typeof width === 'number' && width > 0) {
|
|
151
|
+
return width;
|
|
152
|
+
}
|
|
153
|
+
} catch (e) {
|
|
154
|
+
/* 降级到估算 */
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
// 降级:按字符宽度估算
|
|
158
|
+
return "".concat(text).length * fontSize * 0.6;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
/* ============================================================
|
|
162
|
+
* H5 平台:离屏 canvas + toBlob
|
|
163
|
+
* ============================================================ */
|
|
164
|
+
var loadImageH5 = function loadImageH5(src) {
|
|
165
|
+
return new Promise(function (resolve, reject) {
|
|
166
|
+
var img = new window.Image();
|
|
167
|
+
if (!src.startsWith('blob:') && !src.startsWith('data:')) {
|
|
168
|
+
img.crossOrigin = 'anonymous';
|
|
169
|
+
}
|
|
170
|
+
img.onload = function () {
|
|
171
|
+
return resolve(img);
|
|
172
|
+
};
|
|
173
|
+
img.onerror = function () {
|
|
174
|
+
return reject(new Error('图片加载失败'));
|
|
175
|
+
};
|
|
176
|
+
img.src = src;
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* 将 Blob 转为带指定文件名与 MIME 的 File 对象(H5)。
|
|
182
|
+
* 兼容不支持 File 构造器的环境(降级为设置 blob.name)。
|
|
183
|
+
*/
|
|
184
|
+
var blobToFileH5 = function blobToFileH5(blob, fileName, mime) {
|
|
185
|
+
if (typeof window.File === 'function') {
|
|
186
|
+
try {
|
|
187
|
+
return new window.File([blob], fileName, {
|
|
188
|
+
type: mime || blob.type || ''
|
|
189
|
+
});
|
|
190
|
+
} catch (e) {
|
|
191
|
+
/* 降级 */
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
blob.name = fileName;
|
|
195
|
+
blob.lastModified = Date.now();
|
|
196
|
+
return blob;
|
|
197
|
+
};
|
|
198
|
+
var drawWatermarkItemsH5 = /*#__PURE__*/function () {
|
|
199
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(ctx, canvas, watermark) {
|
|
200
|
+
var _iterator, _step, item, margin, fontSize, point, src, watermarkImage, size, box, spacing, textWidth, stepX, stepY, overflow, y, x;
|
|
201
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
202
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
203
|
+
case 0:
|
|
204
|
+
_iterator = _createForOfIteratorHelper(watermark.items);
|
|
205
|
+
_context2.prev = 1;
|
|
206
|
+
_iterator.s();
|
|
207
|
+
case 3:
|
|
208
|
+
if ((_step = _iterator.n()).done) {
|
|
209
|
+
_context2.next = 28;
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
item = _step.value;
|
|
213
|
+
margin = typeof item.margin === 'number' ? item.margin : watermark.margin;
|
|
214
|
+
fontSize = resolveFontSize(canvas, item);
|
|
215
|
+
point = resolveTextPosition(canvas, item, margin);
|
|
216
|
+
ctx.save();
|
|
217
|
+
ctx.globalAlpha = item.opacity;
|
|
218
|
+
if (!isImageWatermarkItem(item)) {
|
|
219
|
+
_context2.next = 22;
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
src = item.src || item.url || item.imageUrl;
|
|
223
|
+
_context2.next = 14;
|
|
224
|
+
return loadImageH5(src);
|
|
225
|
+
case 14:
|
|
226
|
+
watermarkImage = _context2.sent;
|
|
227
|
+
size = resolveImageSize(canvas, item, watermarkImage);
|
|
228
|
+
box = resolveBoxPosition(canvas, item, margin, size.width, size.height);
|
|
229
|
+
ctx.translate(box.x + size.width / 2, box.y + size.height / 2);
|
|
230
|
+
ctx.rotate(toRadians(item.rotate));
|
|
231
|
+
ctx.drawImage(watermarkImage, -size.width / 2, -size.height / 2, size.width, size.height);
|
|
232
|
+
ctx.restore();
|
|
233
|
+
return _context2.abrupt("continue", 26);
|
|
234
|
+
case 22:
|
|
235
|
+
ctx.font = "".concat(fontSize, "px ").concat(item.fontFamily);
|
|
236
|
+
ctx.fillStyle = item.color;
|
|
237
|
+
if (isFullscreenWatermarkItem(item)) {
|
|
238
|
+
spacing = resolveSpacing(canvas, item);
|
|
239
|
+
textWidth = measureTextWidthH5(ctx, item.text);
|
|
240
|
+
stepX = Math.max(textWidth + spacing, fontSize * 4);
|
|
241
|
+
stepY = Math.max(fontSize + spacing, fontSize * 3);
|
|
242
|
+
overflow = Math.max(canvas.width, canvas.height);
|
|
243
|
+
ctx.textAlign = 'center';
|
|
244
|
+
ctx.textBaseline = 'middle';
|
|
245
|
+
for (y = -overflow; y <= canvas.height + overflow; y += stepY) {
|
|
246
|
+
for (x = -overflow; x <= canvas.width + overflow; x += stepX) {
|
|
247
|
+
ctx.save();
|
|
248
|
+
ctx.translate(x, y);
|
|
249
|
+
ctx.rotate(toRadians(item.rotate));
|
|
250
|
+
drawTextWithStrokeH5(ctx, item.text, 0, 0, item, fontSize);
|
|
251
|
+
ctx.restore();
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
} else {
|
|
255
|
+
ctx.textAlign = point.textAlign;
|
|
256
|
+
ctx.textBaseline = point.textBaseline;
|
|
257
|
+
ctx.translate(point.x, point.y);
|
|
258
|
+
ctx.rotate(toRadians(item.rotate));
|
|
259
|
+
drawTextWithStrokeH5(ctx, item.text, 0, 0, item, fontSize);
|
|
260
|
+
}
|
|
261
|
+
ctx.restore();
|
|
262
|
+
case 26:
|
|
263
|
+
_context2.next = 3;
|
|
264
|
+
break;
|
|
265
|
+
case 28:
|
|
266
|
+
_context2.next = 33;
|
|
267
|
+
break;
|
|
268
|
+
case 30:
|
|
269
|
+
_context2.prev = 30;
|
|
270
|
+
_context2.t0 = _context2["catch"](1);
|
|
271
|
+
_iterator.e(_context2.t0);
|
|
272
|
+
case 33:
|
|
273
|
+
_context2.prev = 33;
|
|
274
|
+
_iterator.f();
|
|
275
|
+
return _context2.finish(33);
|
|
276
|
+
case 36:
|
|
277
|
+
case "end":
|
|
278
|
+
return _context2.stop();
|
|
279
|
+
}
|
|
280
|
+
}, _callee2, null, [[1, 30, 33, 36]]);
|
|
281
|
+
}));
|
|
282
|
+
return function drawWatermarkItemsH5(_x3, _x4, _x5) {
|
|
283
|
+
return _ref2.apply(this, arguments);
|
|
284
|
+
};
|
|
285
|
+
}();
|
|
286
|
+
var canvasToBlobH5 = function canvasToBlobH5(canvas, type) {
|
|
287
|
+
var quality = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0.92;
|
|
288
|
+
return new Promise(function (resolve, reject) {
|
|
289
|
+
if (!canvas.toBlob) {
|
|
290
|
+
reject(new Error('当前浏览器不支持 Canvas 文件导出'));
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
canvas.toBlob(function (blob) {
|
|
294
|
+
if (blob) {
|
|
295
|
+
resolve(blob);
|
|
296
|
+
} else {
|
|
297
|
+
reject(new Error('水印图片生成失败'));
|
|
298
|
+
}
|
|
299
|
+
}, type, quality);
|
|
300
|
+
});
|
|
301
|
+
};
|
|
302
|
+
var applyImageWatermarkToPathH5 = /*#__PURE__*/function () {
|
|
303
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(path, normalized) {
|
|
304
|
+
var options,
|
|
305
|
+
image,
|
|
306
|
+
canvas,
|
|
307
|
+
ctx,
|
|
308
|
+
format,
|
|
309
|
+
blob,
|
|
310
|
+
sourceName,
|
|
311
|
+
file,
|
|
312
|
+
_args3 = arguments;
|
|
313
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
314
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
315
|
+
case 0:
|
|
316
|
+
options = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : {};
|
|
317
|
+
_context3.next = 3;
|
|
318
|
+
return loadImageH5(path);
|
|
319
|
+
case 3:
|
|
320
|
+
image = _context3.sent;
|
|
321
|
+
canvas = document.createElement('canvas');
|
|
322
|
+
canvas.width = image.naturalWidth || image.width;
|
|
323
|
+
canvas.height = image.naturalHeight || image.height;
|
|
324
|
+
ctx = canvas.getContext('2d');
|
|
325
|
+
if (ctx) {
|
|
326
|
+
_context3.next = 10;
|
|
327
|
+
break;
|
|
328
|
+
}
|
|
329
|
+
throw new Error('当前浏览器不支持 Canvas 绘制');
|
|
330
|
+
case 10:
|
|
331
|
+
ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
|
|
332
|
+
_context3.next = 13;
|
|
333
|
+
return drawWatermarkItemsH5(ctx, canvas, normalized);
|
|
334
|
+
case 13:
|
|
335
|
+
// 保持原图格式,避免强制 PNG 导致后端格式校验失败
|
|
336
|
+
format = resolveOutputFormat(path);
|
|
337
|
+
_context3.next = 16;
|
|
338
|
+
return canvasToBlobH5(canvas, format.mime);
|
|
339
|
+
case 16:
|
|
340
|
+
blob = _context3.sent;
|
|
341
|
+
// H5 端返回真正的 File 对象(携带正确的文件名与 MIME),
|
|
342
|
+
// 供 uni.uploadFile 的 files 参数直接上传,避免 blob URL 上传时文件名丢失导致后端 500。
|
|
343
|
+
sourceName = options.fileName || "watermark_".concat(Date.now(), ".").concat(format.ext);
|
|
344
|
+
file = blobToFileH5(blob, sourceName, format.mime);
|
|
345
|
+
return _context3.abrupt("return", {
|
|
346
|
+
file: file,
|
|
347
|
+
ext: format.ext,
|
|
348
|
+
format: format
|
|
349
|
+
});
|
|
350
|
+
case 20:
|
|
351
|
+
case "end":
|
|
352
|
+
return _context3.stop();
|
|
353
|
+
}
|
|
354
|
+
}, _callee3);
|
|
355
|
+
}));
|
|
356
|
+
return function applyImageWatermarkToPathH5(_x6, _x7) {
|
|
357
|
+
return _ref3.apply(this, arguments);
|
|
358
|
+
};
|
|
359
|
+
}();
|
|
360
|
+
|
|
361
|
+
/* ============================================================
|
|
362
|
+
* 非 H5 平台:uni.getImageInfo + createCanvasContext + canvasToTempFilePath
|
|
363
|
+
* ============================================================ */
|
|
364
|
+
var CANVAS_MAX_SIDE = 4096;
|
|
365
|
+
var getImageInfoMini = function getImageInfoMini(src) {
|
|
366
|
+
return new Promise(function (resolve, reject) {
|
|
367
|
+
uni.getImageInfo({
|
|
368
|
+
src: src,
|
|
369
|
+
success: function success(res) {
|
|
370
|
+
return resolve(res);
|
|
371
|
+
},
|
|
372
|
+
fail: function fail(err) {
|
|
373
|
+
return reject(err);
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
};
|
|
378
|
+
var createCanvasContextMini = function createCanvasContextMini(canvasId, instance) {
|
|
379
|
+
return uni.createCanvasContext(canvasId, instance);
|
|
380
|
+
};
|
|
381
|
+
var canvasToTempFilePathMini = function canvasToTempFilePathMini(canvasId, width, height, format, instance) {
|
|
382
|
+
return new Promise(function (resolve, reject) {
|
|
383
|
+
// 保持原图格式导出(jpg 优先,png 次之),避免后端格式校验失败
|
|
384
|
+
var fileType = format && format.ext === 'png' ? 'png' : 'jpg';
|
|
385
|
+
uni.canvasToTempFilePath({
|
|
386
|
+
canvasId: canvasId,
|
|
387
|
+
destWidth: width,
|
|
388
|
+
destHeight: height,
|
|
389
|
+
fileType: fileType,
|
|
390
|
+
quality: 1,
|
|
391
|
+
success: function success(res) {
|
|
392
|
+
return resolve(res.tempFilePath);
|
|
393
|
+
},
|
|
394
|
+
fail: function fail(err) {
|
|
395
|
+
return reject(err);
|
|
396
|
+
}
|
|
397
|
+
}, instance);
|
|
398
|
+
});
|
|
399
|
+
};
|
|
400
|
+
var drawWatermarkItemsMini = /*#__PURE__*/function () {
|
|
401
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(ctx, canvas, watermark) {
|
|
402
|
+
var _iterator2, _step2, item, margin, fontSize, point, src, watermarkImageInfo, drawableSrc, size, box, spacing, textWidth, stepX, stepY, overflow, y, x;
|
|
403
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
404
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
405
|
+
case 0:
|
|
406
|
+
_iterator2 = _createForOfIteratorHelper(watermark.items);
|
|
407
|
+
_context4.prev = 1;
|
|
408
|
+
_iterator2.s();
|
|
409
|
+
case 3:
|
|
410
|
+
if ((_step2 = _iterator2.n()).done) {
|
|
411
|
+
_context4.next = 29;
|
|
412
|
+
break;
|
|
413
|
+
}
|
|
414
|
+
item = _step2.value;
|
|
415
|
+
margin = typeof item.margin === 'number' ? item.margin : watermark.margin;
|
|
416
|
+
fontSize = resolveFontSize(canvas, item);
|
|
417
|
+
point = resolveTextPosition(canvas, item, margin);
|
|
418
|
+
ctx.save();
|
|
419
|
+
ctx.setGlobalAlpha(item.opacity == null ? 1 : item.opacity);
|
|
420
|
+
if (!isImageWatermarkItem(item)) {
|
|
421
|
+
_context4.next = 23;
|
|
422
|
+
break;
|
|
423
|
+
}
|
|
424
|
+
src = item.src || item.url || item.imageUrl; // 图片水印资源先转本地可绘制 path
|
|
425
|
+
_context4.next = 14;
|
|
426
|
+
return getImageInfoMini(src);
|
|
427
|
+
case 14:
|
|
428
|
+
watermarkImageInfo = _context4.sent;
|
|
429
|
+
drawableSrc = watermarkImageInfo.path || src;
|
|
430
|
+
size = resolveImageSize(canvas, item, {
|
|
431
|
+
naturalWidth: watermarkImageInfo.width,
|
|
432
|
+
naturalHeight: watermarkImageInfo.height
|
|
433
|
+
});
|
|
434
|
+
box = resolveBoxPosition(canvas, item, margin, size.width, size.height);
|
|
435
|
+
ctx.translate(box.x + size.width / 2, box.y + size.height / 2);
|
|
436
|
+
ctx.rotate(toRadians(item.rotate));
|
|
437
|
+
ctx.drawImage(drawableSrc, -size.width / 2, -size.height / 2, size.width, size.height);
|
|
438
|
+
ctx.restore();
|
|
439
|
+
return _context4.abrupt("continue", 27);
|
|
440
|
+
case 23:
|
|
441
|
+
ctx.setFontSize(fontSize);
|
|
442
|
+
ctx.setFillStyle(item.color);
|
|
443
|
+
if (isFullscreenWatermarkItem(item)) {
|
|
444
|
+
spacing = resolveSpacing(canvas, item);
|
|
445
|
+
textWidth = measureTextWidthMini(ctx, item.text, fontSize);
|
|
446
|
+
stepX = Math.max(textWidth + spacing, fontSize * 4);
|
|
447
|
+
stepY = Math.max(fontSize + spacing, fontSize * 3);
|
|
448
|
+
overflow = Math.max(canvas.width, canvas.height);
|
|
449
|
+
ctx.setTextAlign('center');
|
|
450
|
+
ctx.setTextBaseline('middle');
|
|
451
|
+
for (y = -overflow; y <= canvas.height + overflow; y += stepY) {
|
|
452
|
+
for (x = -overflow; x <= canvas.width + overflow; x += stepX) {
|
|
453
|
+
ctx.save();
|
|
454
|
+
ctx.translate(x, y);
|
|
455
|
+
ctx.rotate(toRadians(item.rotate));
|
|
456
|
+
drawTextWithStrokeMini(ctx, item.text, 0, 0, item, fontSize);
|
|
457
|
+
ctx.restore();
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
} else {
|
|
461
|
+
ctx.setTextAlign(point.textAlign);
|
|
462
|
+
ctx.setTextBaseline(point.textBaseline);
|
|
463
|
+
ctx.translate(point.x, point.y);
|
|
464
|
+
ctx.rotate(toRadians(item.rotate));
|
|
465
|
+
drawTextWithStrokeMini(ctx, item.text, 0, 0, item, fontSize);
|
|
466
|
+
}
|
|
467
|
+
ctx.restore();
|
|
468
|
+
case 27:
|
|
469
|
+
_context4.next = 3;
|
|
470
|
+
break;
|
|
471
|
+
case 29:
|
|
472
|
+
_context4.next = 34;
|
|
473
|
+
break;
|
|
474
|
+
case 31:
|
|
475
|
+
_context4.prev = 31;
|
|
476
|
+
_context4.t0 = _context4["catch"](1);
|
|
477
|
+
_iterator2.e(_context4.t0);
|
|
478
|
+
case 34:
|
|
479
|
+
_context4.prev = 34;
|
|
480
|
+
_iterator2.f();
|
|
481
|
+
return _context4.finish(34);
|
|
482
|
+
case 37:
|
|
483
|
+
case "end":
|
|
484
|
+
return _context4.stop();
|
|
485
|
+
}
|
|
486
|
+
}, _callee4, null, [[1, 31, 34, 37]]);
|
|
487
|
+
}));
|
|
488
|
+
return function drawWatermarkItemsMini(_x8, _x9, _x10) {
|
|
489
|
+
return _ref4.apply(this, arguments);
|
|
490
|
+
};
|
|
491
|
+
}();
|
|
492
|
+
var applyImageWatermarkToPathMini = /*#__PURE__*/function () {
|
|
493
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(path, normalized, options) {
|
|
494
|
+
var info, drawableSrc, format, canvasWidth, canvasHeight, maxSide, scale, canvas, ctx;
|
|
495
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
496
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
497
|
+
case 0:
|
|
498
|
+
if (options.canvasId) {
|
|
499
|
+
_context5.next = 2;
|
|
500
|
+
break;
|
|
501
|
+
}
|
|
502
|
+
throw new Error('缺少 canvasId,无法绘制水印');
|
|
503
|
+
case 2:
|
|
504
|
+
_context5.next = 4;
|
|
505
|
+
return getImageInfoMini(path);
|
|
506
|
+
case 4:
|
|
507
|
+
info = _context5.sent;
|
|
508
|
+
drawableSrc = info.path || path;
|
|
509
|
+
format = resolveOutputFormat(info.path || path);
|
|
510
|
+
canvasWidth = info.width || 1;
|
|
511
|
+
canvasHeight = info.height || 1; // 超出 canvas 尺寸上限时等比缩放,避免绘制失败
|
|
512
|
+
maxSide = Math.max(canvasWidth, canvasHeight);
|
|
513
|
+
if (maxSide > CANVAS_MAX_SIDE) {
|
|
514
|
+
scale = CANVAS_MAX_SIDE / maxSide;
|
|
515
|
+
canvasWidth = Math.floor(canvasWidth * scale);
|
|
516
|
+
canvasHeight = Math.floor(canvasHeight * scale);
|
|
517
|
+
}
|
|
518
|
+
canvas = {
|
|
519
|
+
width: canvasWidth,
|
|
520
|
+
height: canvasHeight
|
|
521
|
+
}; // 通知组件设置 canvas 显示尺寸,使绘制坐标系与图片实际尺寸匹配,
|
|
522
|
+
// 避免固定 CSS 尺寸导致绘制内容被裁剪。
|
|
523
|
+
if (!(typeof options.setCanvasSize === 'function')) {
|
|
524
|
+
_context5.next = 15;
|
|
525
|
+
break;
|
|
526
|
+
}
|
|
527
|
+
_context5.next = 15;
|
|
528
|
+
return options.setCanvasSize(canvasWidth, canvasHeight);
|
|
529
|
+
case 15:
|
|
530
|
+
// 先绘制原图,再串行加载并绘制水印项(含图片水印资源的异步加载),
|
|
531
|
+
// 最后统一调用 ctx.draw 并导出临时文件路径。
|
|
532
|
+
ctx = createCanvasContextMini(options.canvasId, options.instance);
|
|
533
|
+
ctx.drawImage(drawableSrc, 0, 0, canvasWidth, canvasHeight);
|
|
534
|
+
_context5.next = 19;
|
|
535
|
+
return drawWatermarkItemsMini(ctx, canvas, normalized);
|
|
536
|
+
case 19:
|
|
537
|
+
return _context5.abrupt("return", new Promise(function (resolve, reject) {
|
|
538
|
+
var settled = false;
|
|
539
|
+
// 兜底超时:小程序旧版 canvas 若被移出屏幕等原因导致 ctx.draw 回调不触发,
|
|
540
|
+
// 会卡死整个上传流程,这里超时后 reject,由上层降级为上传原图。
|
|
541
|
+
var timer = setTimeout(function () {
|
|
542
|
+
if (!settled) {
|
|
543
|
+
settled = true;
|
|
544
|
+
reject(new Error('水印绘制超时'));
|
|
545
|
+
}
|
|
546
|
+
}, 8000);
|
|
547
|
+
var finish = function finish(result) {
|
|
548
|
+
if (!settled) {
|
|
549
|
+
settled = true;
|
|
550
|
+
clearTimeout(timer);
|
|
551
|
+
resolve(result);
|
|
552
|
+
}
|
|
553
|
+
};
|
|
554
|
+
var fail = function fail(err) {
|
|
555
|
+
if (!settled) {
|
|
556
|
+
settled = true;
|
|
557
|
+
clearTimeout(timer);
|
|
558
|
+
reject(err);
|
|
559
|
+
}
|
|
560
|
+
};
|
|
561
|
+
ctx.draw(false, function () {
|
|
562
|
+
// 延迟一帧确保绘制完成后再导出
|
|
563
|
+
setTimeout(function () {
|
|
564
|
+
canvasToTempFilePathMini(options.canvasId, canvasWidth, canvasHeight, format, options.instance).then(function (tempFilePath) {
|
|
565
|
+
return finish({
|
|
566
|
+
url: tempFilePath,
|
|
567
|
+
format: format
|
|
568
|
+
});
|
|
569
|
+
}).catch(fail);
|
|
570
|
+
}, 50);
|
|
571
|
+
});
|
|
572
|
+
}));
|
|
573
|
+
case 20:
|
|
574
|
+
case "end":
|
|
575
|
+
return _context5.stop();
|
|
576
|
+
}
|
|
577
|
+
}, _callee5);
|
|
578
|
+
}));
|
|
579
|
+
return function applyImageWatermarkToPathMini(_x11, _x12, _x13) {
|
|
580
|
+
return _ref5.apply(this, arguments);
|
|
581
|
+
};
|
|
582
|
+
}();
|
|
583
|
+
|
|
584
|
+
/* ============================================================
|
|
585
|
+
* 统一出口:根据运行时环境选择绘制路径
|
|
586
|
+
* ============================================================ */
|
|
587
|
+
export var applyImageWatermarkToPath = /*#__PURE__*/function () {
|
|
588
|
+
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(path, watermark) {
|
|
589
|
+
var options,
|
|
590
|
+
normalized,
|
|
591
|
+
result,
|
|
592
|
+
_args6 = arguments;
|
|
593
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
594
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
595
|
+
case 0:
|
|
596
|
+
options = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : {};
|
|
597
|
+
normalized = normalizeWatermarkConfig(watermark);
|
|
598
|
+
if (normalized) {
|
|
599
|
+
_context6.next = 4;
|
|
600
|
+
break;
|
|
601
|
+
}
|
|
602
|
+
return _context6.abrupt("return", path);
|
|
603
|
+
case 4:
|
|
604
|
+
if (!(typeof normalized.processor === 'function')) {
|
|
605
|
+
_context6.next = 9;
|
|
606
|
+
break;
|
|
607
|
+
}
|
|
608
|
+
_context6.next = 7;
|
|
609
|
+
return normalized.processor(path, {
|
|
610
|
+
path: path,
|
|
611
|
+
watermark: normalized
|
|
612
|
+
});
|
|
613
|
+
case 7:
|
|
614
|
+
result = _context6.sent;
|
|
615
|
+
return _context6.abrupt("return", result || path);
|
|
616
|
+
case 9:
|
|
617
|
+
if (!isH5()) {
|
|
618
|
+
_context6.next = 11;
|
|
619
|
+
break;
|
|
620
|
+
}
|
|
621
|
+
return _context6.abrupt("return", applyImageWatermarkToPathH5(path, normalized, options));
|
|
622
|
+
case 11:
|
|
623
|
+
return _context6.abrupt("return", applyImageWatermarkToPathMini(path, normalized, options));
|
|
624
|
+
case 12:
|
|
625
|
+
case "end":
|
|
626
|
+
return _context6.stop();
|
|
627
|
+
}
|
|
628
|
+
}, _callee6);
|
|
629
|
+
}));
|
|
630
|
+
return function applyImageWatermarkToPath(_x14, _x15) {
|
|
631
|
+
return _ref6.apply(this, arguments);
|
|
632
|
+
};
|
|
633
|
+
}();
|