image-process
Advanced tools
Comparing version
/*! | ||
* image-process version 4.3.0 | ||
* image-process version 4.3.1 | ||
* Author: Xing Zhong <capricorncd@qq.com, zx198401@gmail.com> | ||
* Repository: https://github.com/capricorncd/image-process-tools | ||
* Released on: 2022-09-18 17:51:48 (GMT+0900) | ||
* Released on: 2022-12-30 14:17:09 (GMT+0900) | ||
*/ | ||
@@ -13,8 +13,8 @@ /*! | ||
*/ | ||
var z = Object.defineProperty, P = Object.getOwnPropertySymbols, k = Object.prototype.hasOwnProperty, W = Object.prototype.propertyIsEnumerable, S = (t, e, i) => e in t ? z(t, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : t[e] = i, p = (t, e) => { | ||
var z = Object.defineProperty, P = Object.getOwnPropertySymbols, k = Object.prototype.hasOwnProperty, W = Object.prototype.propertyIsEnumerable, E = (t, e, i) => e in t ? z(t, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : t[e] = i, _ = (t, e) => { | ||
for (var i in e || (e = {})) | ||
k.call(e, i) && S(t, i, e[i]); | ||
k.call(e, i) && E(t, i, e[i]); | ||
if (P) | ||
for (var i of P(e)) | ||
W.call(e, i) && S(t, i, e[i]); | ||
W.call(e, i) && E(t, i, e[i]); | ||
return t; | ||
@@ -25,24 +25,24 @@ }; | ||
} | ||
function $(t) { | ||
function B(t) { | ||
return t !== null && !V(t) && typeof t == "object"; | ||
} | ||
var Y = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, f = { exports: {} }; | ||
var Y = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, o = { exports: {} }; | ||
/*! For license information please see date-utils-2020.js.LICENSE.txt */ | ||
(function(t, e) { | ||
(function(i, r) { | ||
t.exports = r(); | ||
(function(i, n) { | ||
t.exports = n(); | ||
})(typeof self < "u" ? self : Y, function() { | ||
return (() => { | ||
var i = { 949: (n, a) => { | ||
var i = { 949: (r, a) => { | ||
Object.defineProperty(a, "__esModule", { value: !0 }), a.toTwoDigits = void 0, a.toTwoDigits = function(h) { | ||
return h[1] ? h : "0" + h; | ||
}; | ||
}, 607: (n, a, h) => { | ||
}, 607: (r, a, h) => { | ||
Object.defineProperty(a, "__esModule", { value: !0 }), a.toTwoDigits = a.toDate = a.formatDate = void 0; | ||
var d = h(949); | ||
var s = h(949); | ||
Object.defineProperty(a, "toTwoDigits", { enumerable: !0, get: function() { | ||
return d.toTwoDigits; | ||
return s.toTwoDigits; | ||
} }); | ||
var l = { weeks: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] }; | ||
function o(u) { | ||
function f(u) { | ||
if (u instanceof Date) | ||
@@ -53,14 +53,14 @@ return u; | ||
if (typeof u == "string") { | ||
var s = u.trim(); | ||
if (/^\d+$/.test(s)) { | ||
var g = s.length; | ||
return g === 8 ? new Date([s.substr(0, 4), s.substr(4, 2), s.substr(6, 2)].join("/")) : g === 6 ? new Date([s.substr(0, 4), s.substr(4, 2), "01"].join("/")) : g === 4 ? new Date(s + "/01/01") : new Date(parseInt(u)); | ||
var d = u.trim(); | ||
if (/^\d+$/.test(d)) { | ||
var c = d.length; | ||
return c === 8 ? new Date([d.substr(0, 4), d.substr(4, 2), d.substr(6, 2)].join("/")) : c === 6 ? new Date([d.substr(0, 4), d.substr(4, 2), "01"].join("/")) : c === 4 ? new Date(d + "/01/01") : new Date(parseInt(u)); | ||
} | ||
if (s = s.replace(/[年月日]/g, function(c) { | ||
return c === "\u65E5" ? "" : "/"; | ||
}).replace(/[(((].*?[)))]/g, " ").replace(/\bam|pm\b/gi, " ").replace(/\s+/g, " "), /^(\d{4})[-/](\d{1,2})[-/](\d{1,2})$/.test(s)) | ||
if (d = d.replace(/[年月日]/g, function(g) { | ||
return g === "\u65E5" ? "" : "/"; | ||
}).replace(/[(((].*?[)))]/g, " ").replace(/\bam|pm\b/gi, " ").replace(/\s+/g, " "), /^(\d{4})[-/](\d{1,2})[-/](\d{1,2})$/.test(d)) | ||
return new Date([RegExp.$1, RegExp.$2, RegExp.$3].join("/")); | ||
if (/^(\d{4})[-/](\d{1,2})$/.test(s)) | ||
if (/^(\d{4})[-/](\d{1,2})$/.test(d)) | ||
return new Date([RegExp.$1, RegExp.$2, "01"].join("/")); | ||
var w = new Date(s); | ||
var w = new Date(d); | ||
return isNaN(w.getFullYear()) ? null : w; | ||
@@ -70,38 +70,38 @@ } | ||
} | ||
a.formatDate = function(u, s, g) { | ||
var w, c = o(u); | ||
if (!c || !s) | ||
a.formatDate = function(u, d, c) { | ||
var w, g = f(u); | ||
if (!g || !d) | ||
return u + ""; | ||
if (s === "timestamp") | ||
return c.getTime().toString(); | ||
/(y+)/i.test(s) && (w = RegExp.$1, s = s.replace(w, (c.getFullYear() + "").substr(4 - w.length))), g && Array.isArray(g.weeks) || (g = l); | ||
var b = { "M+": c.getMonth() + 1, "d+": c.getDate(), "h+": c.getHours(), "m+": c.getMinutes(), "s+": c.getSeconds(), "w+": c.getDay(), "W+": g.weeks[c.getDay()], "a+": c.getHours() < 12 ? "am" : "pm", "A+": c.getHours() < 12 ? "AM" : "PM" }; | ||
if (d === "timestamp") | ||
return g.getTime().toString(); | ||
/(y+)/i.test(d) && (w = RegExp.$1, d = d.replace(w, (g.getFullYear() + "").substr(4 - w.length))), c && Array.isArray(c.weeks) || (c = l); | ||
var b = { "M+": g.getMonth() + 1, "d+": g.getDate(), "h+": g.getHours(), "m+": g.getMinutes(), "s+": g.getSeconds(), "w+": g.getDay(), "W+": c.weeks[g.getDay()], "a+": g.getHours() < 12 ? "am" : "pm", "A+": g.getHours() < 12 ? "AM" : "PM" }; | ||
for (var R in b) | ||
if (new RegExp("(" + R + ")").test(s)) { | ||
if (new RegExp("(" + R + ")").test(d)) { | ||
w = RegExp.$1; | ||
var D = b[R] + ""; | ||
s = s.replace(w, w.length === 1 ? D : d.toTwoDigits(D)); | ||
d = d.replace(w, w.length === 1 ? D : s.toTwoDigits(D)); | ||
} | ||
if (/(g)/i.test(s)) { | ||
var T = c.toString().split(/\s+/).slice(5), N = s.includes("g"); | ||
s = s.replace(/g/i, N ? T[0] : T.join(" ")); | ||
if (/(g)/i.test(d)) { | ||
var T = g.toString().split(/\s+/).slice(5), N = d.includes("g"); | ||
d = d.replace(/g/i, N ? T[0] : T.join(" ")); | ||
} | ||
return s; | ||
}, a.toDate = o; | ||
} }, r = {}; | ||
return function n(a) { | ||
if (r[a]) | ||
return r[a].exports; | ||
var h = r[a] = { exports: {} }; | ||
return i[a](h, h.exports, n), h.exports; | ||
return d; | ||
}, a.toDate = f; | ||
} }, n = {}; | ||
return function r(a) { | ||
if (n[a]) | ||
return n[a].exports; | ||
var h = n[a] = { exports: {} }; | ||
return i[a](h, h.exports, r), h.exports; | ||
}(607); | ||
})(); | ||
}); | ||
})(f); | ||
function O(t = "", e = "-") { | ||
return t.replace(/[A-Z]/g, (i, r) => `${r > 0 ? e : ""}${i.toLowerCase()}`); | ||
})(o); | ||
function A(t = "", e = "-") { | ||
return t.replace(/[A-Z]/g, (i, n) => `${n > 0 ? e : ""}${i.toLowerCase()}`); | ||
} | ||
function Z(t = "", e = !1) { | ||
const i = t.replace(/[-_\s](\w)/g, (r, n) => n.toUpperCase()); | ||
return e ? i.replace(/^\w/, (r) => r.toUpperCase()) : i; | ||
const i = t.replace(/[-_\s](\w)/g, (n, r) => r.toUpperCase()); | ||
return e ? i.replace(/^\w/, (n) => n.toUpperCase()) : i; | ||
} | ||
@@ -111,3 +111,3 @@ function q(t) { | ||
} | ||
function B(t, e = !1) { | ||
function F(t, e = !1) { | ||
if (typeof t == "number") | ||
@@ -117,3 +117,3 @@ return t; | ||
if (!e && /^(-?\d+(?:\.\d+)?)\D*/.test(q(t))) | ||
return B(RegExp.$1, !0); | ||
return F(RegExp.$1, !0); | ||
const i = Number(t); | ||
@@ -124,13 +124,13 @@ return isNaN(i) ? 0 : i; | ||
} | ||
function A(t = {}, e = !1) { | ||
const i = e ? Z : O, r = {}; | ||
for (const [n, a] of Object.entries(t)) | ||
r[i(n)] = $(a) ? A(a, e) : a; | ||
return r; | ||
function S(t = {}, e = !1) { | ||
const i = e ? Z : A, n = {}; | ||
for (const [r, a] of Object.entries(t)) | ||
n[i(r)] = B(a) ? S(a, e) : a; | ||
return n; | ||
} | ||
function F(t, e = !1, i = 2) { | ||
const r = ["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"], n = e ? 1e3 : 1024; | ||
function U(t, e = !1, i = 2) { | ||
const n = ["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"], r = e ? 1e3 : 1024; | ||
let a = String(t), h = "Byte"; | ||
for (let d = 0, l = t / n; l > 1; l /= n, d++) | ||
a = l.toFixed(i), h = r[d]; | ||
for (let s = 0, l = t / r; l > 1; l /= r, s++) | ||
a = l.toFixed(i), h = n[s]; | ||
return e && (h = h.replace("i", "")), { | ||
@@ -144,17 +144,17 @@ text: a.replace(/\.0+$/, "") + h, | ||
function y(t, e = {}, i) { | ||
const r = document.createElement(t); | ||
for (const [n, a] of Object.entries(e)) | ||
r.setAttribute(O(n), n === "style" && $(a) ? G(a) : a); | ||
return i && (Array.isArray(i) || (i = [i]), i.forEach((n) => { | ||
if (typeof n == "string") { | ||
const n = document.createElement(t); | ||
for (const [r, a] of Object.entries(e)) | ||
n.setAttribute(A(r), r === "style" && B(a) ? G(a) : a); | ||
return i && (Array.isArray(i) || (i = [i]), i.forEach((r) => { | ||
if (typeof r == "string") { | ||
const a = y("div"); | ||
a.innerHTML = n, r.append(...a.childNodes); | ||
a.innerHTML = r, n.append(...a.childNodes); | ||
} else | ||
r.append(n); | ||
})), r; | ||
n.append(r); | ||
})), n; | ||
} | ||
function G(...t) { | ||
const e = t.reduce((r, n) => p(p({}, r), A(n)), {}), i = []; | ||
for (const [r, n] of Object.entries(e)) | ||
n === "" || typeof n > "u" || n === null || i.push(`${r}:${n}`); | ||
const e = t.reduce((n, r) => _(_({}, n), S(r)), {}), i = []; | ||
for (const [n, r] of Object.entries(e)) | ||
r === "" || typeof r > "u" || r === null || i.push(`${n}:${r}`); | ||
return i.join(";"); | ||
@@ -164,8 +164,8 @@ } | ||
return new Promise((e, i) => { | ||
const r = new FileReader(); | ||
r.onload = (n) => { | ||
const n = new FileReader(); | ||
n.onload = (r) => { | ||
var a; | ||
const h = (a = n.target) == null ? void 0 : a.result; | ||
h ? e(h) : i(new Error(`FileReader's result is null, ${n.target}`)); | ||
}, r.onerror = i, r.readAsDataURL(t); | ||
const h = (a = r.target) == null ? void 0 : a.result; | ||
h ? e(h) : i(new Error(`FileReader's result is null, ${r.target}`)); | ||
}, n.onerror = i, n.readAsDataURL(t); | ||
}); | ||
@@ -176,3 +176,3 @@ } | ||
} | ||
function U(t) { | ||
function M(t) { | ||
const e = t.split(","); | ||
@@ -185,14 +185,14 @@ let i = ""; | ||
} | ||
function M(t, e) { | ||
const i = U(t), r = window.atob(i.data); | ||
function L(t, e) { | ||
const i = M(t), n = window.atob(i.data); | ||
e = e || i.type; | ||
const n = new Uint8Array(r.length); | ||
for (let a = 0; a < r.length; a++) | ||
n[a] = r.charCodeAt(a); | ||
return new Blob([n], { type: e }); | ||
const r = new Uint8Array(n.length); | ||
for (let a = 0; a < n.length; a++) | ||
r[a] = n.charCodeAt(a); | ||
return new Blob([r], { type: e }); | ||
} | ||
f.exports.formatDate; | ||
f.exports.toDate; | ||
f.exports.toTwoDigits; | ||
const L = { | ||
o.exports.formatDate; | ||
o.exports.toDate; | ||
o.exports.toTwoDigits; | ||
const p = { | ||
enableDevicePixelRatio: !1, | ||
@@ -205,19 +205,21 @@ isForce: !1, | ||
height: 0, | ||
longestSide: 0 | ||
longEdge: 0 | ||
}, J = /^data:(.+?);base64/, Q = /^image\/.+/; | ||
function C(t, e) { | ||
return new Promise((i, r) => { | ||
const n = { | ||
...L, | ||
...e | ||
return new Promise((i, n) => { | ||
var a; | ||
const r = { | ||
...p, | ||
...e, | ||
longEdge: (a = e == null ? void 0 : e.longEdge) != null ? a : e == null ? void 0 : e.longestSide | ||
}; | ||
typeof t == "string" && J.test(t) ? E(t, n, i, r) : (t instanceof File || t instanceof Blob) && Q.test(t.type) ? K(t).then((a) => { | ||
E(a, n, i, r); | ||
}).catch(r) : r(new Error(`Invalid file, ${t}`)); | ||
typeof t == "string" && J.test(t) ? $(t, r, i, n) : (t instanceof File || t instanceof Blob) && Q.test(t.type) ? K(t).then((h) => { | ||
$(h, r, i, n); | ||
}).catch(n) : n(new Error(`Invalid file, ${t}`)); | ||
}); | ||
} | ||
function E(t, e, i, r) { | ||
const { type: n } = U(t), a = M(t, n), h = new Image(); | ||
function $(t, e, i, n) { | ||
const { type: r } = M(t), a = L(t, r), h = new Image(); | ||
h.onload = () => { | ||
const d = { | ||
const s = { | ||
element: h, | ||
@@ -229,6 +231,6 @@ blob: a, | ||
height: h.naturalHeight || h.height, | ||
type: n, | ||
size: F(a.size) | ||
type: r, | ||
size: U(a.size) | ||
}; | ||
e.cropInfo && e.cropInfo.sw && e.cropInfo.sh ? _(d, e, i, r, { | ||
e.cropInfo && e.cropInfo.sw && e.cropInfo.sh ? O(s, e, i, n, { | ||
...e.cropInfo, | ||
@@ -239,20 +241,20 @@ dx: 0, | ||
dh: e.cropInfo.sh | ||
}) : e.width && e.height ? _(d, e, i, r, I(d, e)) : e.width || e.height || e.longestSide ? X(d, e, i, r) : m({ ...d, raw: d }, e, i); | ||
}, h.onerror = r, h.src = t; | ||
}) : e.width && e.height ? O(s, e, i, n, I(s, e)) : e.width || e.height || e.longEdge ? X(s, e, i, n) : m({ ...s, raw: s }, e, i); | ||
}, h.onerror = n, h.src = t; | ||
} | ||
function _(t, e, i, r, n) { | ||
function O(t, e, i, n, r) { | ||
try { | ||
Object.prototype.hasOwnProperty.call(n, "enableDevicePixelRatio") || (n.enableDevicePixelRatio = e.enableDevicePixelRatio); | ||
Object.prototype.hasOwnProperty.call(r, "enableDevicePixelRatio") || (r.enableDevicePixelRatio = e.enableDevicePixelRatio); | ||
const a = v(t.element, { | ||
enableDevicePixelRatio: e.enableDevicePixelRatio, | ||
sx: n.sx, | ||
sy: n.sy, | ||
sw: n.sw, | ||
sh: n.sh, | ||
sx: r.sx, | ||
sy: r.sy, | ||
sw: r.sw, | ||
sh: r.sh, | ||
dx: 0, | ||
dy: 0, | ||
dw: n.sw, | ||
dh: n.sh | ||
dw: r.sw, | ||
dh: r.sh | ||
}); | ||
!e.width && !e.height ? e.longestSide ? n.sw > n.sh ? (e.width = e.longestSide, e.height = n.sh * e.width / n.sw) : (e.height = e.longestSide, e.width = n.sw * e.height / n.sh) : (e.width = n.sw, e.height = n.sh) : e.width ? e.height = n.sh * e.width / n.sw : e.width = n.sw * e.height / n.sh, j( | ||
!e.width && !e.height ? e.longEdge ? r.sw > r.sh ? (e.width = e.longEdge, e.height = r.sh * e.width / r.sw) : (e.height = e.longEdge, e.width = r.sw * e.height / r.sh) : (e.width = r.sw, e.height = r.sh) : e.width ? e.height = r.sh * e.width / r.sw : e.width = r.sw * e.height / r.sh, j( | ||
a, | ||
@@ -262,3 +264,3 @@ t, | ||
{ | ||
...n, | ||
...r, | ||
sx: 0, | ||
@@ -272,9 +274,9 @@ sy: 0, | ||
} catch (a) { | ||
r(a); | ||
n(a); | ||
} | ||
} | ||
function X(t, e, i, r) { | ||
function X(t, e, i, n) { | ||
try { | ||
e.longestSide && !e.width && !e.height && (t.width >= t.height ? e.width = e.longestSide : e.height = e.longestSide); | ||
const n = { | ||
e.longEdge && !e.width && !e.height && (t.width >= t.height ? e.width = e.longEdge : e.height = e.longEdge); | ||
const r = { | ||
enableDevicePixelRatio: e.enableDevicePixelRatio, | ||
@@ -295,3 +297,3 @@ sx: 0, | ||
} | ||
n.dh = t.height * e.width / t.width, e.height = n.dh; | ||
r.dh = t.height * e.width / t.width, e.height = r.dh; | ||
} else { | ||
@@ -302,7 +304,7 @@ if (t.height < e.height && !e.isForce) { | ||
} | ||
n.dw = t.width * e.height / t.height, e.width = n.dw; | ||
r.dw = t.width * e.height / t.height, e.width = r.dw; | ||
} | ||
j(t.element, t, e, n, i); | ||
} catch (n) { | ||
r(n); | ||
j(t.element, t, e, r, i); | ||
} catch (r) { | ||
n(r); | ||
} | ||
@@ -329,14 +331,14 @@ } | ||
} | ||
function j(t, e, i, r, n) { | ||
let a = e.width > e.height ? e.width - r.dw : e.height - r.dh; | ||
function j(t, e, i, n, r) { | ||
let a = e.width > e.height ? e.width - n.dw : e.height - n.dh; | ||
if (a > i.perResize) { | ||
const h = e.height / e.width; | ||
for (; a > i.perResize; ) | ||
a -= i.perResize, r.sw = t.width, r.sh = t.height, r.dw = i.width + a, r.dh = r.dw * h, t = v(t, r); | ||
a -= i.perResize, n.sw = t.width, n.sh = t.height, n.dw = i.width + a, n.dh = n.dw * h, t = v(t, n); | ||
} | ||
r.sw = t.width, r.sh = t.height, r.dw = i.width, r.dh = i.height, H(t, e, i, r, n); | ||
n.sw = t.width, n.sh = t.height, n.dw = i.width, n.dh = i.height, H(t, e, i, n, r); | ||
} | ||
function H(t, e, i, r, n) { | ||
const a = v(t, r), h = /^\w+\/\*$/.test(i.mimeType) || !i.mimeType ? e.type : i.mimeType, d = a.toDataURL(h, i.quality), l = M(d, h); | ||
n({ | ||
function H(t, e, i, n, r) { | ||
const a = v(t, n), h = /^\w+\/\*$/.test(i.mimeType) || !i.mimeType ? e.type : i.mimeType, s = a.toDataURL(h, i.quality), l = L(s, h); | ||
r({ | ||
element: a, | ||
@@ -347,5 +349,5 @@ type: h, | ||
blob: l, | ||
data: d, | ||
data: s, | ||
url: x(l), | ||
size: F(l.size), | ||
size: U(l.size), | ||
raw: e | ||
@@ -355,17 +357,17 @@ }); | ||
function I(t, e) { | ||
const { width: i, height: r } = t, { width: n, height: a } = e; | ||
const { width: i, height: n } = t, { width: r, height: a } = e; | ||
let h; | ||
const d = r * n / a; | ||
if (i > d) | ||
const s = n * r / a; | ||
if (i > s) | ||
h = { | ||
sx: (i - d) / 2, | ||
sx: (i - s) / 2, | ||
sy: 0, | ||
sw: d, | ||
sh: r | ||
sw: s, | ||
sh: n | ||
}; | ||
else { | ||
const l = i * a / n; | ||
const l = i * a / r; | ||
h = { | ||
sx: 0, | ||
sy: (r - l) / 2, | ||
sy: (n - l) / 2, | ||
sw: i, | ||
@@ -379,3 +381,3 @@ sh: l | ||
dy: 0, | ||
dw: n, | ||
dw: r, | ||
dh: a | ||
@@ -385,6 +387,6 @@ }; | ||
function v(t, e) { | ||
const i = e.enableDevicePixelRatio && window.devicePixelRatio || 1, r = y("canvas"); | ||
r.width = e.dw * i, r.height = e.dh * i; | ||
const n = r.getContext("2d"); | ||
return n.scale(i, i), n.drawImage( | ||
const i = e.enableDevicePixelRatio && window.devicePixelRatio || 1, n = y("canvas"); | ||
n.width = e.dw * i, n.height = e.dh * i; | ||
const r = n.getContext("2d"); | ||
return r.scale(i, i), r.drawImage( | ||
t, | ||
@@ -399,8 +401,8 @@ e.sx, | ||
e.dh | ||
), r; | ||
), n; | ||
} | ||
function ee(t, e) { | ||
return new Promise((i, r) => { | ||
const n = { | ||
...L, | ||
return new Promise((i, n) => { | ||
const r = { | ||
...p, | ||
...e | ||
@@ -411,8 +413,8 @@ }, a = x(t); | ||
autoplay: !0 | ||
}), d = !1; | ||
h.onerror = r, h.oncanplay = () => { | ||
if (d) | ||
}), s = !1; | ||
h.onerror = n, h.oncanplay = () => { | ||
if (s) | ||
return; | ||
d = !0; | ||
const l = h.duration, o = typeof n.currentTime > "u" ? l * Math.random() : B(n.currentTime), u = { | ||
s = !0; | ||
const l = h.duration, f = typeof r.currentTime > "u" ? l * Math.random() : F(r.currentTime), u = { | ||
url: a, | ||
@@ -423,21 +425,21 @@ videoFile: t, | ||
duration: l, | ||
currentTime: Math.min(o, l) | ||
currentTime: Math.min(f, l) | ||
}; | ||
te(h, u).then((s) => { | ||
!n.width && !n.height && (n.width = u.videoWidth, n.height = u.videoHeight), C(s, e).then((g) => { | ||
te(h, u).then((d) => { | ||
!r.width && !r.height && (r.width = u.videoWidth, r.height = u.videoHeight), C(d, e).then((c) => { | ||
i({ | ||
videoInfo: u, | ||
...g | ||
...c | ||
}), h = null; | ||
}).catch(r); | ||
}).catch(r); | ||
}).catch(n); | ||
}).catch(n); | ||
}; | ||
}); | ||
} | ||
function te(t, { currentTime: e, videoWidth: i, videoHeight: r }) { | ||
return new Promise((n) => { | ||
function te(t, { currentTime: e, videoWidth: i, videoHeight: n }) { | ||
return new Promise((r) => { | ||
t.currentTime = e, t.pause(); | ||
const a = "image/jpeg", h = y("canvas"), d = h.getContext("2d"); | ||
h.width = i, h.height = r, setTimeout(() => { | ||
d.drawImage(t, 0, 0, h.width, h.height), n(h.toDataURL(a)); | ||
const a = "image/jpeg", h = y("canvas"), s = h.getContext("2d"); | ||
h.width = i, h.height = n, setTimeout(() => { | ||
s.drawImage(t, 0, 0, h.width, h.height), r(h.toDataURL(a)); | ||
}, 500); | ||
@@ -447,17 +449,17 @@ }); | ||
function ie(t, e) { | ||
return new Promise((i, r) => { | ||
const n = t.type; | ||
/^(image|video)/.test(n) ? RegExp.$1 === "image" ? C(t, e).then(i).catch(r) : ee(t, e).then(i).catch(r) : r(new Error(`File type[${n}] not supported`)); | ||
return new Promise((i, n) => { | ||
const r = t.type; | ||
/^(image|video)/.test(r) ? RegExp.$1 === "image" ? C(t, e).then(i).catch(n) : ee(t, e).then(i).catch(n) : n(new Error(`File type[${r}] not supported`)); | ||
}); | ||
} | ||
export { | ||
M as base64ToBlob, | ||
L as base64ToBlob, | ||
x as createBlobURL, | ||
y as createElement, | ||
K as fileToBase64, | ||
F as formatBytes, | ||
U as formatBytes, | ||
C as handleImageFile, | ||
ie as handleMediaFile, | ||
ee as handleVideoFile, | ||
U as splitBase64 | ||
M as splitBase64 | ||
}; |
/*! | ||
* image-process version 4.3.0 | ||
* image-process version 4.3.1 | ||
* Author: Xing Zhong <capricorncd@qq.com, zx198401@gmail.com> | ||
* Repository: https://github.com/capricorncd/image-process-tools | ||
* Released on: 2022-09-18 17:51:48 (GMT+0900) | ||
* Released on: 2022-12-30 14:17:09 (GMT+0900) | ||
*/ | ||
(function(g,w){typeof exports=="object"&&typeof module<"u"?w(exports):typeof define=="function"&&define.amd?define(["exports"],w):(g=typeof globalThis<"u"?globalThis:g||self,w(g.imageProcess={}))})(this,function(g){"use strict";/*! | ||
(function(c,o){typeof exports=="object"&&typeof module<"u"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(c=typeof globalThis<"u"?globalThis:c||self,o(c.imageProcess={}))})(this,function(c){"use strict";/*! | ||
* zx-sml version 0.6.0 | ||
@@ -12,2 +12,2 @@ * Author: Xing Zhong<zx198401@gmail.com> | ||
* Released on: 2022-09-09 21:21:26 (GMT+0900) | ||
*/var w=Object.defineProperty,_=Object.getOwnPropertySymbols,V=Object.prototype.hasOwnProperty,Y=Object.prototype.propertyIsEnumerable,E=(t,e,i)=>e in t?w(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,B=(t,e)=>{for(var i in e||(e={}))V.call(e,i)&&E(t,i,e[i]);if(_)for(var i of _(e))Y.call(e,i)&&E(t,i,e[i]);return t};function Z(t){return Array.isArray(t)}function $(t){return t!==null&&!Z(t)&&typeof t=="object"}var q=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},m={exports:{}};/*! For license information please see date-utils-2020.js.LICENSE.txt */(function(t,e){(function(i,r){t.exports=r()})(typeof self<"u"?self:q,function(){return(()=>{var i={949:(n,a)=>{Object.defineProperty(a,"__esModule",{value:!0}),a.toTwoDigits=void 0,a.toTwoDigits=function(d){return d[1]?d:"0"+d}},607:(n,a,d)=>{Object.defineProperty(a,"__esModule",{value:!0}),a.toTwoDigits=a.toDate=a.formatDate=void 0;var h=d(949);Object.defineProperty(a,"toTwoDigits",{enumerable:!0,get:function(){return h.toTwoDigits}});var l={weeks:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]};function v(u){if(u instanceof Date)return u;if(typeof u=="number")return new Date(u);if(typeof u=="string"){var s=u.trim();if(/^\d+$/.test(s)){var o=s.length;return o===8?new Date([s.substr(0,4),s.substr(4,2),s.substr(6,2)].join("/")):o===6?new Date([s.substr(0,4),s.substr(4,2),"01"].join("/")):o===4?new Date(s+"/01/01"):new Date(parseInt(u))}if(s=s.replace(/[年月日]/g,function(c){return c==="\u65E5"?"":"/"}).replace(/[(((].*?[)))]/g," ").replace(/\bam|pm\b/gi," ").replace(/\s+/g," "),/^(\d{4})[-/](\d{1,2})[-/](\d{1,2})$/.test(s))return new Date([RegExp.$1,RegExp.$2,RegExp.$3].join("/"));if(/^(\d{4})[-/](\d{1,2})$/.test(s))return new Date([RegExp.$1,RegExp.$2,"01"].join("/"));var f=new Date(s);return isNaN(f.getFullYear())?null:f}return null}a.formatDate=function(u,s,o){var f,c=v(u);if(!c||!s)return u+"";if(s==="timestamp")return c.getTime().toString();/(y+)/i.test(s)&&(f=RegExp.$1,s=s.replace(f,(c.getFullYear()+"").substr(4-f.length))),o&&Array.isArray(o.weeks)||(o=l);var N={"M+":c.getMonth()+1,"d+":c.getDate(),"h+":c.getHours(),"m+":c.getMinutes(),"s+":c.getSeconds(),"w+":c.getDay(),"W+":o.weeks[c.getDay()],"a+":c.getHours()<12?"am":"pm","A+":c.getHours()<12?"AM":"PM"};for(var z in N)if(new RegExp("("+z+")").test(s)){f=RegExp.$1;var k=N[z]+"";s=s.replace(f,f.length===1?k:h.toTwoDigits(k))}if(/(g)/i.test(s)){var W=c.toString().split(/\s+/).slice(5),ne=s.includes("g");s=s.replace(/g/i,ne?W[0]:W.join(" "))}return s},a.toDate=v}},r={};return function n(a){if(r[a])return r[a].exports;var d=r[a]={exports:{}};return i[a](d,d.exports,n),d.exports}(607)})()})})(m);function p(t="",e="-"){return t.replace(/[A-Z]/g,(i,r)=>`${r>0?e:""}${i.toLowerCase()}`)}function G(t="",e=!1){const i=t.replace(/[-_\s](\w)/g,(r,n)=>n.toUpperCase());return e?i.replace(/^\w/,r=>r.toUpperCase()):i}function K(t){return t.replace(/^-?[1-9]\d{0,2}(,\d{3})+/,e=>e.replace(/,/g,""))}function O(t,e=!1){if(typeof t=="number")return t;if(typeof t=="string"){if(!e&&/^(-?\d+(?:\.\d+)?)\D*/.test(K(t)))return O(RegExp.$1,!0);const i=Number(t);return isNaN(i)?0:i}return 0}function F(t={},e=!1){const i=e?G:p,r={};for(const[n,a]of Object.entries(t))r[i(n)]=$(a)?F(a,e):a;return r}function x(t,e=!1,i=2){const r=["KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"],n=e?1e3:1024;let a=String(t),d="Byte";for(let h=0,l=t/n;l>1;l/=n,h++)a=l.toFixed(i),d=r[h];return e&&(d=d.replace("i","")),{text:a.replace(/\.0+$/,"")+d,value:+a,unit:d,bytes:t}}function y(t,e={},i){const r=document.createElement(t);for(const[n,a]of Object.entries(e))r.setAttribute(p(n),n==="style"&&$(a)?J(a):a);return i&&(Array.isArray(i)||(i=[i]),i.forEach(n=>{if(typeof n=="string"){const a=y("div");a.innerHTML=n,r.append(...a.childNodes)}else r.append(n)})),r}function J(...t){const e=t.reduce((r,n)=>B(B({},r),F(n)),{}),i=[];for(const[r,n]of Object.entries(e))n===""||typeof n>"u"||n===null||i.push(`${r}:${n}`);return i.join(";")}function M(t){return new Promise((e,i)=>{const r=new FileReader;r.onload=n=>{var a;const d=(a=n.target)==null?void 0:a.result;d?e(d):i(new Error(`FileReader's result is null, ${n.target}`))},r.onerror=i,r.readAsDataURL(t)})}function b(t){return(window.URL||window.webkitURL).createObjectURL(t)}function R(t){const e=t.split(",");let i="";return/data:(\w+\/\w+);base64/.test(e[0])&&(i=RegExp.$1),{type:i,data:e[1]}}function D(t,e){const i=R(t),r=window.atob(i.data);e=e||i.type;const n=new Uint8Array(r.length);for(let a=0;a<r.length;a++)n[a]=r.charCodeAt(a);return new Blob([n],{type:e})}m.exports.formatDate,m.exports.toDate,m.exports.toTwoDigits;const U={enableDevicePixelRatio:!1,isForce:!1,mimeType:"image/jpeg",perResize:500,quality:.9,width:0,height:0,longestSide:0},Q=/^data:(.+?);base64/,X=/^image\/.+/;function T(t,e){return new Promise((i,r)=>{const n={...U,...e};typeof t=="string"&&Q.test(t)?A(t,n,i,r):(t instanceof File||t instanceof Blob)&&X.test(t.type)?M(t).then(a=>{A(a,n,i,r)}).catch(r):r(new Error(`Invalid file, ${t}`))})}function A(t,e,i,r){const{type:n}=R(t),a=D(t,n),d=new Image;d.onload=()=>{const h={element:d,blob:a,data:t,url:b(a),width:d.naturalWidth||d.width,height:d.naturalHeight||d.height,type:n,size:x(a.size)};e.cropInfo&&e.cropInfo.sw&&e.cropInfo.sh?L(h,e,i,r,{...e.cropInfo,dx:0,dy:0,dw:e.cropInfo.sw,dh:e.cropInfo.sh}):e.width&&e.height?L(h,e,i,r,ee(h,e)):e.width||e.height||e.longestSide?I(h,e,i,r):P({...h,raw:h},e,i)},d.onerror=r,d.src=t}function L(t,e,i,r,n){try{Object.prototype.hasOwnProperty.call(n,"enableDevicePixelRatio")||(n.enableDevicePixelRatio=e.enableDevicePixelRatio);const a=S(t.element,{enableDevicePixelRatio:e.enableDevicePixelRatio,sx:n.sx,sy:n.sy,sw:n.sw,sh:n.sh,dx:0,dy:0,dw:n.sw,dh:n.sh});!e.width&&!e.height?e.longestSide?n.sw>n.sh?(e.width=e.longestSide,e.height=n.sh*e.width/n.sw):(e.height=e.longestSide,e.width=n.sw*e.height/n.sh):(e.width=n.sw,e.height=n.sh):e.width?e.height=n.sh*e.width/n.sw:e.width=n.sw*e.height/n.sh,j(a,t,e,{...n,sx:0,sy:0,sw:a.width,sh:a.height},i)}catch(a){r(a)}}function I(t,e,i,r){try{e.longestSide&&!e.width&&!e.height&&(t.width>=t.height?e.width=e.longestSide:e.height=e.longestSide);const n={enableDevicePixelRatio:e.enableDevicePixelRatio,sx:0,sy:0,sw:t.width,sh:t.height,dx:0,dy:0,dw:e.width,dh:e.height};if(e.width){if(t.width<e.width&&!e.isForce){P({...t,raw:t},e,i);return}n.dh=t.height*e.width/t.width,e.height=n.dh}else{if(t.height<e.height&&!e.isForce){P({...t,raw:t},e,i);return}n.dw=t.width*e.height/t.height,e.width=n.dw}j(t.element,t,e,n,i)}catch(n){r(n)}}function P(t,e,i){t.type!==e.mimeType?(t.type=e.mimeType,C(t.element,t.raw,e,{enableDevicePixelRatio:e.enableDevicePixelRatio,sx:0,sy:0,sw:t.width,sh:t.height,dx:0,dy:0,dw:t.width,dh:t.height},i)):i(t)}function j(t,e,i,r,n){let a=e.width>e.height?e.width-r.dw:e.height-r.dh;if(a>i.perResize){const d=e.height/e.width;for(;a>i.perResize;)a-=i.perResize,r.sw=t.width,r.sh=t.height,r.dw=i.width+a,r.dh=r.dw*d,t=S(t,r)}r.sw=t.width,r.sh=t.height,r.dw=i.width,r.dh=i.height,C(t,e,i,r,n)}function C(t,e,i,r,n){const a=S(t,r),d=/^\w+\/\*$/.test(i.mimeType)||!i.mimeType?e.type:i.mimeType,h=a.toDataURL(d,i.quality),l=D(h,d);n({element:a,type:d,width:a.width,height:a.height,blob:l,data:h,url:b(l),size:x(l.size),raw:e})}function ee(t,e){const{width:i,height:r}=t,{width:n,height:a}=e;let d;const h=r*n/a;if(i>h)d={sx:(i-h)/2,sy:0,sw:h,sh:r};else{const l=i*a/n;d={sx:0,sy:(r-l)/2,sw:i,sh:l}}return{...d,dx:0,dy:0,dw:n,dh:a}}function S(t,e){const i=e.enableDevicePixelRatio&&window.devicePixelRatio||1,r=y("canvas");r.width=e.dw*i,r.height=e.dh*i;const n=r.getContext("2d");return n.scale(i,i),n.drawImage(t,e.sx,e.sy,e.sw,e.sh,e.dx,e.dy,e.dw,e.dh),r}function H(t,e){return new Promise((i,r)=>{const n={...U,...e},a=b(t);let d=y("video",{src:a,autoplay:!0}),h=!1;d.onerror=r,d.oncanplay=()=>{if(h)return;h=!0;const l=d.duration,v=typeof n.currentTime>"u"?l*Math.random():O(n.currentTime),u={url:a,videoFile:t,videoWidth:d.videoWidth,videoHeight:d.videoHeight,duration:l,currentTime:Math.min(v,l)};te(d,u).then(s=>{!n.width&&!n.height&&(n.width=u.videoWidth,n.height=u.videoHeight),T(s,e).then(o=>{i({videoInfo:u,...o}),d=null}).catch(r)}).catch(r)}})}function te(t,{currentTime:e,videoWidth:i,videoHeight:r}){return new Promise(n=>{t.currentTime=e,t.pause();const a="image/jpeg",d=y("canvas"),h=d.getContext("2d");d.width=i,d.height=r,setTimeout(()=>{h.drawImage(t,0,0,d.width,d.height),n(d.toDataURL(a))},500)})}function ie(t,e){return new Promise((i,r)=>{const n=t.type;/^(image|video)/.test(n)?RegExp.$1==="image"?T(t,e).then(i).catch(r):H(t,e).then(i).catch(r):r(new Error(`File type[${n}] not supported`))})}g.base64ToBlob=D,g.createBlobURL=b,g.createElement=y,g.fileToBase64=M,g.formatBytes=x,g.handleImageFile=T,g.handleMediaFile=ie,g.handleVideoFile=H,g.splitBase64=R,Object.defineProperties(g,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); | ||
*/var o=Object.defineProperty,_=Object.getOwnPropertySymbols,V=Object.prototype.hasOwnProperty,Y=Object.prototype.propertyIsEnumerable,B=(t,e,i)=>e in t?o(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,$=(t,e)=>{for(var i in e||(e={}))V.call(e,i)&&B(t,i,e[i]);if(_)for(var i of _(e))Y.call(e,i)&&B(t,i,e[i]);return t};function Z(t){return Array.isArray(t)}function O(t){return t!==null&&!Z(t)&&typeof t=="object"}var q=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},m={exports:{}};/*! For license information please see date-utils-2020.js.LICENSE.txt */(function(t,e){(function(i,r){t.exports=r()})(typeof self<"u"?self:q,function(){return(()=>{var i={949:(n,a)=>{Object.defineProperty(a,"__esModule",{value:!0}),a.toTwoDigits=void 0,a.toTwoDigits=function(d){return d[1]?d:"0"+d}},607:(n,a,d)=>{Object.defineProperty(a,"__esModule",{value:!0}),a.toTwoDigits=a.toDate=a.formatDate=void 0;var l=d(949);Object.defineProperty(a,"toTwoDigits",{enumerable:!0,get:function(){return l.toTwoDigits}});var s={weeks:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]};function v(u){if(u instanceof Date)return u;if(typeof u=="number")return new Date(u);if(typeof u=="string"){var h=u.trim();if(/^\d+$/.test(h)){var f=h.length;return f===8?new Date([h.substr(0,4),h.substr(4,2),h.substr(6,2)].join("/")):f===6?new Date([h.substr(0,4),h.substr(4,2),"01"].join("/")):f===4?new Date(h+"/01/01"):new Date(parseInt(u))}if(h=h.replace(/[年月日]/g,function(g){return g==="\u65E5"?"":"/"}).replace(/[(((].*?[)))]/g," ").replace(/\bam|pm\b/gi," ").replace(/\s+/g," "),/^(\d{4})[-/](\d{1,2})[-/](\d{1,2})$/.test(h))return new Date([RegExp.$1,RegExp.$2,RegExp.$3].join("/"));if(/^(\d{4})[-/](\d{1,2})$/.test(h))return new Date([RegExp.$1,RegExp.$2,"01"].join("/"));var w=new Date(h);return isNaN(w.getFullYear())?null:w}return null}a.formatDate=function(u,h,f){var w,g=v(u);if(!g||!h)return u+"";if(h==="timestamp")return g.getTime().toString();/(y+)/i.test(h)&&(w=RegExp.$1,h=h.replace(w,(g.getFullYear()+"").substr(4-w.length))),f&&Array.isArray(f.weeks)||(f=s);var N={"M+":g.getMonth()+1,"d+":g.getDate(),"h+":g.getHours(),"m+":g.getMinutes(),"s+":g.getSeconds(),"w+":g.getDay(),"W+":f.weeks[g.getDay()],"a+":g.getHours()<12?"am":"pm","A+":g.getHours()<12?"AM":"PM"};for(var z in N)if(new RegExp("("+z+")").test(h)){w=RegExp.$1;var k=N[z]+"";h=h.replace(w,w.length===1?k:l.toTwoDigits(k))}if(/(g)/i.test(h)){var W=g.toString().split(/\s+/).slice(5),ne=h.includes("g");h=h.replace(/g/i,ne?W[0]:W.join(" "))}return h},a.toDate=v}},r={};return function n(a){if(r[a])return r[a].exports;var d=r[a]={exports:{}};return i[a](d,d.exports,n),d.exports}(607)})()})})(m);function F(t="",e="-"){return t.replace(/[A-Z]/g,(i,r)=>`${r>0?e:""}${i.toLowerCase()}`)}function G(t="",e=!1){const i=t.replace(/[-_\s](\w)/g,(r,n)=>n.toUpperCase());return e?i.replace(/^\w/,r=>r.toUpperCase()):i}function K(t){return t.replace(/^-?[1-9]\d{0,2}(,\d{3})+/,e=>e.replace(/,/g,""))}function M(t,e=!1){if(typeof t=="number")return t;if(typeof t=="string"){if(!e&&/^(-?\d+(?:\.\d+)?)\D*/.test(K(t)))return M(RegExp.$1,!0);const i=Number(t);return isNaN(i)?0:i}return 0}function S(t={},e=!1){const i=e?G:F,r={};for(const[n,a]of Object.entries(t))r[i(n)]=O(a)?S(a,e):a;return r}function x(t,e=!1,i=2){const r=["KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"],n=e?1e3:1024;let a=String(t),d="Byte";for(let l=0,s=t/n;s>1;s/=n,l++)a=s.toFixed(i),d=r[l];return e&&(d=d.replace("i","")),{text:a.replace(/\.0+$/,"")+d,value:+a,unit:d,bytes:t}}function y(t,e={},i){const r=document.createElement(t);for(const[n,a]of Object.entries(e))r.setAttribute(F(n),n==="style"&&O(a)?J(a):a);return i&&(Array.isArray(i)||(i=[i]),i.forEach(n=>{if(typeof n=="string"){const a=y("div");a.innerHTML=n,r.append(...a.childNodes)}else r.append(n)})),r}function J(...t){const e=t.reduce((r,n)=>$($({},r),S(n)),{}),i=[];for(const[r,n]of Object.entries(e))n===""||typeof n>"u"||n===null||i.push(`${r}:${n}`);return i.join(";")}function U(t){return new Promise((e,i)=>{const r=new FileReader;r.onload=n=>{var a;const d=(a=n.target)==null?void 0:a.result;d?e(d):i(new Error(`FileReader's result is null, ${n.target}`))},r.onerror=i,r.readAsDataURL(t)})}function b(t){return(window.URL||window.webkitURL).createObjectURL(t)}function R(t){const e=t.split(",");let i="";return/data:(\w+\/\w+);base64/.test(e[0])&&(i=RegExp.$1),{type:i,data:e[1]}}function D(t,e){const i=R(t),r=window.atob(i.data);e=e||i.type;const n=new Uint8Array(r.length);for(let a=0;a<r.length;a++)n[a]=r.charCodeAt(a);return new Blob([n],{type:e})}m.exports.formatDate,m.exports.toDate,m.exports.toTwoDigits;const A={enableDevicePixelRatio:!1,isForce:!1,mimeType:"image/jpeg",perResize:500,quality:.9,width:0,height:0,longEdge:0},Q=/^data:(.+?);base64/,X=/^image\/.+/;function T(t,e){return new Promise((i,r)=>{var a;const n={...A,...e,longEdge:(a=e==null?void 0:e.longEdge)!=null?a:e==null?void 0:e.longestSide};typeof t=="string"&&Q.test(t)?L(t,n,i,r):(t instanceof File||t instanceof Blob)&&X.test(t.type)?U(t).then(d=>{L(d,n,i,r)}).catch(r):r(new Error(`Invalid file, ${t}`))})}function L(t,e,i,r){const{type:n}=R(t),a=D(t,n),d=new Image;d.onload=()=>{const l={element:d,blob:a,data:t,url:b(a),width:d.naturalWidth||d.width,height:d.naturalHeight||d.height,type:n,size:x(a.size)};e.cropInfo&&e.cropInfo.sw&&e.cropInfo.sh?j(l,e,i,r,{...e.cropInfo,dx:0,dy:0,dw:e.cropInfo.sw,dh:e.cropInfo.sh}):e.width&&e.height?j(l,e,i,r,ee(l,e)):e.width||e.height||e.longEdge?I(l,e,i,r):P({...l,raw:l},e,i)},d.onerror=r,d.src=t}function j(t,e,i,r,n){try{Object.prototype.hasOwnProperty.call(n,"enableDevicePixelRatio")||(n.enableDevicePixelRatio=e.enableDevicePixelRatio);const a=E(t.element,{enableDevicePixelRatio:e.enableDevicePixelRatio,sx:n.sx,sy:n.sy,sw:n.sw,sh:n.sh,dx:0,dy:0,dw:n.sw,dh:n.sh});!e.width&&!e.height?e.longEdge?n.sw>n.sh?(e.width=e.longEdge,e.height=n.sh*e.width/n.sw):(e.height=e.longEdge,e.width=n.sw*e.height/n.sh):(e.width=n.sw,e.height=n.sh):e.width?e.height=n.sh*e.width/n.sw:e.width=n.sw*e.height/n.sh,p(a,t,e,{...n,sx:0,sy:0,sw:a.width,sh:a.height},i)}catch(a){r(a)}}function I(t,e,i,r){try{e.longEdge&&!e.width&&!e.height&&(t.width>=t.height?e.width=e.longEdge:e.height=e.longEdge);const n={enableDevicePixelRatio:e.enableDevicePixelRatio,sx:0,sy:0,sw:t.width,sh:t.height,dx:0,dy:0,dw:e.width,dh:e.height};if(e.width){if(t.width<e.width&&!e.isForce){P({...t,raw:t},e,i);return}n.dh=t.height*e.width/t.width,e.height=n.dh}else{if(t.height<e.height&&!e.isForce){P({...t,raw:t},e,i);return}n.dw=t.width*e.height/t.height,e.width=n.dw}p(t.element,t,e,n,i)}catch(n){r(n)}}function P(t,e,i){t.type!==e.mimeType?(t.type=e.mimeType,C(t.element,t.raw,e,{enableDevicePixelRatio:e.enableDevicePixelRatio,sx:0,sy:0,sw:t.width,sh:t.height,dx:0,dy:0,dw:t.width,dh:t.height},i)):i(t)}function p(t,e,i,r,n){let a=e.width>e.height?e.width-r.dw:e.height-r.dh;if(a>i.perResize){const d=e.height/e.width;for(;a>i.perResize;)a-=i.perResize,r.sw=t.width,r.sh=t.height,r.dw=i.width+a,r.dh=r.dw*d,t=E(t,r)}r.sw=t.width,r.sh=t.height,r.dw=i.width,r.dh=i.height,C(t,e,i,r,n)}function C(t,e,i,r,n){const a=E(t,r),d=/^\w+\/\*$/.test(i.mimeType)||!i.mimeType?e.type:i.mimeType,l=a.toDataURL(d,i.quality),s=D(l,d);n({element:a,type:d,width:a.width,height:a.height,blob:s,data:l,url:b(s),size:x(s.size),raw:e})}function ee(t,e){const{width:i,height:r}=t,{width:n,height:a}=e;let d;const l=r*n/a;if(i>l)d={sx:(i-l)/2,sy:0,sw:l,sh:r};else{const s=i*a/n;d={sx:0,sy:(r-s)/2,sw:i,sh:s}}return{...d,dx:0,dy:0,dw:n,dh:a}}function E(t,e){const i=e.enableDevicePixelRatio&&window.devicePixelRatio||1,r=y("canvas");r.width=e.dw*i,r.height=e.dh*i;const n=r.getContext("2d");return n.scale(i,i),n.drawImage(t,e.sx,e.sy,e.sw,e.sh,e.dx,e.dy,e.dw,e.dh),r}function H(t,e){return new Promise((i,r)=>{const n={...A,...e},a=b(t);let d=y("video",{src:a,autoplay:!0}),l=!1;d.onerror=r,d.oncanplay=()=>{if(l)return;l=!0;const s=d.duration,v=typeof n.currentTime>"u"?s*Math.random():M(n.currentTime),u={url:a,videoFile:t,videoWidth:d.videoWidth,videoHeight:d.videoHeight,duration:s,currentTime:Math.min(v,s)};te(d,u).then(h=>{!n.width&&!n.height&&(n.width=u.videoWidth,n.height=u.videoHeight),T(h,e).then(f=>{i({videoInfo:u,...f}),d=null}).catch(r)}).catch(r)}})}function te(t,{currentTime:e,videoWidth:i,videoHeight:r}){return new Promise(n=>{t.currentTime=e,t.pause();const a="image/jpeg",d=y("canvas"),l=d.getContext("2d");d.width=i,d.height=r,setTimeout(()=>{l.drawImage(t,0,0,d.width,d.height),n(d.toDataURL(a))},500)})}function ie(t,e){return new Promise((i,r)=>{const n=t.type;/^(image|video)/.test(n)?RegExp.$1==="image"?T(t,e).then(i).catch(r):H(t,e).then(i).catch(r):r(new Error(`File type[${n}] not supported`))})}c.base64ToBlob=D,c.createBlobURL=b,c.createElement=y,c.fileToBase64=U,c.formatBytes=x,c.handleImageFile=T,c.handleMediaFile=ie,c.handleVideoFile=H,c.splitBase64=R,Object.defineProperties(c,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); |
{ | ||
"name": "image-process", | ||
"version": "4.3.0", | ||
"description": "A Image clipping or scaling, support local or same domain video file screenshot. It's implemented in canvas.", | ||
"version": "4.3.1", | ||
"description": "A Image clipping or scaling, support local or same domain video file screenshot. It's implemented in canvas.", | ||
"main": "dist/image-process.umd.js", | ||
@@ -29,3 +29,3 @@ "module": "dist/image-process.es.js", | ||
"dev": "cd packages/demo && pnpm run dev", | ||
"demo:build": "cd packages/demo && pnpm run build", | ||
"build:demo": "cd packages/demo && pnpm run build", | ||
"build": "cd packages/core && pnpm run build", | ||
@@ -32,0 +32,0 @@ "docs": "cd packages/core && pnpm run docs", |
@@ -46,2 +46,3 @@ # image-process | ||
```html | ||
<script src="./dist/image-process.umd.js"></script> | ||
<script> | ||
@@ -89,3 +90,3 @@ imageProcess.handleMediaFile(file, options) | ||
file|`File`|yes|Image or video file. | ||
options|`Partial<MediaFileHandlerOptions>`|no|See [MediaFileHandlerOptions](#MediaFileHandlerOptions). | ||
options|`MediaFileHandlerOptions`|no|See [MediaFileHandlerOptions](#MediaFileHandlerOptions). | ||
@@ -120,3 +121,3 @@ - @returns `Promise<MediaFileHandlerResult>` See [MediaFileHandlerResult](#MediaFileHandlerResult). | ||
height|`number`|no|The `height` of the processed image. Default is `0`. | ||
longestSide|`number`|no|The size of the longest side. Valid when width and height are `0`. Default is `0`. | ||
longEdge|`number`|no|The value of long edge. Valid when width and height are `0`. Default is `0`. | ||
cropInfo|`OptionsCropInfo`|no|See [OptionsCropInfo](#OptionsCropInfo). | ||
@@ -150,4 +151,4 @@ | ||
height?: number | ||
// The size of the longest side. Valid when width and height are `0`. Default is `0`. | ||
longestSide?: number | ||
// The value of long edge. Valid when width and height are `0`. Default is `0`. | ||
longEdge?: number | ||
// See [OptionsCropInfo](#OptionsCropInfo). | ||
@@ -174,3 +175,3 @@ cropInfo?: OptionsCropInfo | ||
element|`HTMLImageElement`/`HTMLCanvasElement`|yes|`HTMLImageElement` or `HTMLCanvasElement`. | ||
raw|`MediaFileHandlerRawData`|yes|Raw information of the image file being processed. See [MediaFileHandlerRawData].(#MediaFileHandlerRawData). | ||
raw|`MediaFileHandlerRawData`|yes|Raw information of the image file being processed. See [MediaFileHandlerRawData](#MediaFileHandlerRawData). | ||
@@ -184,3 +185,3 @@ <details> | ||
element: HTMLImageElement | HTMLCanvasElement | ||
// Raw information of the image file being processed. See [MediaFileHandlerRawData].(#MediaFileHandlerRawData). | ||
// Raw information of the image file being processed. See [MediaFileHandlerRawData](#MediaFileHandlerRawData). | ||
raw: MediaFileHandlerRawData | ||
@@ -242,3 +243,3 @@ } | ||
element|`HTMLImageElement`/`HTMLCanvasElement`|yes|`HTMLImageElement` or `HTMLCanvasElement`. | ||
raw|`MediaFileHandlerRawData`|yes|Raw information of the image file being processed. See [MediaFileHandlerRawData].(#MediaFileHandlerRawData). | ||
raw|`MediaFileHandlerRawData`|yes|Raw information of the image file being processed. See [MediaFileHandlerRawData](#MediaFileHandlerRawData). | ||
videoInfo|`VideoInfo`|no|Video file information. See [VideoInfo](#videoinfo). | ||
@@ -369,3 +370,3 @@ | ||
height|`number`|no|The `height` of the processed image. Default is `0`. | ||
longestSide|`number`|no|The size of the longest side. Valid when width and height are `0`. Default is `0`. | ||
longEdge|`number`|no|The value of long edge. Valid when width and height are `0`. Default is `0`. | ||
cropInfo|`OptionsCropInfo`|no|See [OptionsCropInfo](#OptionsCropInfo). | ||
@@ -402,3 +403,3 @@ currentTime|`number`|no|The `HTMLMediaElement` interface's `currentTime` property specifies the current playback time in seconds. If it is longer than the video duration, the last frame will be captured. The default is a `random` timestamp in the video duration. | ||
element|`HTMLImageElement`/`HTMLCanvasElement`|yes|`HTMLImageElement` or `HTMLCanvasElement`. | ||
raw|`MediaFileHandlerRawData`|yes|Raw information of the image file being processed. See [MediaFileHandlerRawData].(#MediaFileHandlerRawData). | ||
raw|`MediaFileHandlerRawData`|yes|Raw information of the image file being processed. See [MediaFileHandlerRawData](#MediaFileHandlerRawData). | ||
videoInfo|`VideoInfo`|yes|When taking a screenshot of the video, the original video file information. See [VideoInfo](#VideoInfo). | ||
@@ -405,0 +406,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
42631
0.38%490
0.41%464
0.22%0
-100%