one
Version:
One is a new React Framework that makes Vite serve both native and web.
96 lines (93 loc) • 3.34 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf,
__hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all) __defProp(target, name, {
get: all[name],
enumerable: !0
});
},
__copyProps = (to, from, except, desc) => {
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
get: () => from[key],
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
value: mod,
enumerable: !0
}) : target, mod)),
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
value: !0
}), mod);
var getImageData_exports = {};
__export(getImageData_exports, {
getImageData: () => getImageData,
getSharp: () => getSharp,
processImageMeta: () => processImageMeta
});
module.exports = __toCommonJS(getImageData_exports);
var import_fs = require("fs"),
import_path = require("path"),
sharpWarned = !1;
async function getSharp() {
try {
var sharpModule = await import("sharp");
return sharpModule.default || sharpModule;
} catch {
return sharpWarned || (sharpWarned = !0, console.warn(`
[one] To use getImageData, install sharp:
npm install sharp
`)), null;
}
}
async function processImageMeta(filePath) {
var sharp = await getSharp();
if (!sharp) return null;
try {
var image = sharp(filePath),
metadata = await image.metadata(),
{
width = 0,
height = 0
} = metadata,
blurBuffer = await image.resize(10).blur(1).jpeg({
quality: 40
}).toBuffer(),
blurDataURL = `data:image/jpeg;base64,${blurBuffer.toString("base64")}`;
return {
width,
height,
blurDataURL
};
} catch (e) {
return console.warn(`[one] processImageMeta: Failed to process ${filePath}:`, e), null;
}
}
async function getImageData(filePath) {
var resolvedPath, src;
filePath.startsWith("/") ? (resolvedPath = (0, import_path.resolve)("./public", filePath.slice(1)), src = filePath) : (resolvedPath = (0, import_path.resolve)(filePath), src = filePath.replace(/^\.\.?\//, "").replace(/^public\//, ""), src.startsWith("/") || (src = "/" + src));
var defaultResult = {
src,
width: 0,
height: 0,
blurDataURL: ""
};
if (!(0, import_fs.existsSync)(resolvedPath)) return console.warn(`[one] getImageData: File not found: ${resolvedPath}`), defaultResult;
var meta = await processImageMeta(resolvedPath);
return meta ? {
src,
...meta
} : defaultResult;
}
//# sourceMappingURL=getImageData.native.js.map