@shopify/shop-minis-react
Version:
React component library for Shopify Shop Minis with Tailwind CSS v4 support (source-only, requires TypeScript)
73 lines (72 loc) • 1.86 kB
JavaScript
import { toUint8Array as l } from "../shop-minis-react/node_modules/.pnpm/js-base64@3.7.7/node_modules/js-base64/base64.js";
import { thumbHashToDataURL as h } from "../shop-minis-react/node_modules/.pnpm/thumbhash@0.1.1/node_modules/thumbhash/thumbhash.js";
function d(t) {
if (t)
try {
const e = l(t);
return h(e);
} catch (e) {
console.warn("Failed to decode thumbhash to data URL", e);
return;
}
}
function m(t) {
const [e, r] = t.split(","), n = e.match(/:(.*?);/), c = n ? n[1] : "image/png", a = atob(r), s = new Uint8Array(a.length);
for (let o = 0; o < a.length; o++)
s[o] = a.charCodeAt(o);
return new Blob([s], { type: c });
}
function R(t) {
if (t)
try {
const e = d(t);
if (!e) return;
const r = m(e);
return URL.createObjectURL(r);
} catch (e) {
console.warn("Failed to create thumbhash blob URL", e);
return;
}
}
function w(t) {
return new Promise((e, r) => {
const n = new FileReader();
n.onloadend = () => e(n.result), n.onerror = r, n.readAsDataURL(t);
});
}
const i = {
xxsUrl: 32,
xsUrl: 64,
sUrl: 128,
xxsmUrl: 256,
xsmUrl: 384,
smUrl: 512,
mUrl: 640,
lUrl: 1080,
xlUrl: 2048
}, u = 0.05, U = Object.entries(i).sort(
([, t], [, e]) => t - e
), f = (t) => {
for (const [e, r] of U) {
const n = r + r * u;
if (t <= n) return e;
}
return "xlUrl";
}, b = (t, e) => {
const n = new RegExp(/\?+/g).test(t) ? "&" : "?";
return `${t}${n}width=${e}`;
}, y = (t) => {
if (!t) return "";
if (!t.startsWith("https://cdn.shopify.com"))
return t;
const e = window.innerWidth ?? screen.width, r = f(e);
return b(t, i[r]);
};
export {
m as dataURLToBlob,
w as fileToDataUri,
y as getResizedImageUrl,
R as getThumbhashBlobURL,
d as getThumbhashDataURL
};
//# sourceMappingURL=image.js.map