UNPKG

@shopify/shop-minis-react

Version:

React component library for Shopify Shop Minis with Tailwind CSS v4 support (source-only, requires TypeScript)

62 lines (61 loc) 1.44 kB
const z = { low: { size: 1080, compression: 0.7 }, medium: { size: 1600, compression: 0.85 }, high: { size: 2048, compression: 0.92 } }; function f({ file: s, quality: g, customQuality: r }) { if (g === "original") return Promise.resolve(s); const c = z[g], d = r ? { size: r.size ?? c.size, compression: r.compression ?? c.compression } : c, i = d.size; return new Promise((h, a) => { const t = new Image(), m = URL.createObjectURL(s); t.onerror = () => { URL.revokeObjectURL(m), a(new Error("Failed to load image")); }, t.onload = () => { URL.revokeObjectURL(m); const n = document.createElement("canvas"); let e = t.width, o = t.height; e > o ? e > i && (o *= i / e, e = i) : o > i && (e *= i / o, o = i), n.width = e, n.height = o; const l = n.getContext("2d"); if (!l) { a(new Error("Failed to get canvas context")); return; } l.drawImage(t, 0, 0, e, o), n.toBlob( (w) => { if (!w) { a(new Error("Failed to create blob")); return; } const p = new File([w], s.name, { type: "image/jpeg", lastModified: Date.now() }); h(p); }, "image/jpeg", d.compression ); }, t.src = m; }); } export { f as resizeImage }; //# sourceMappingURL=resizeImage.js.map