yeet
This commit is contained in:
8
node_modules/@expo/image-utils/build/Cache.d.ts
generated
vendored
Normal file
8
node_modules/@expo/image-utils/build/Cache.d.ts
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
/// <reference types="node" />
|
||||
import { ImageOptions } from './Image.types';
|
||||
export declare function createCacheKey(fileSource: string, properties: string[]): string;
|
||||
export declare function createCacheKeyWithDirectoryAsync(projectRoot: string, type: string, icon: ImageOptions): Promise<string>;
|
||||
export declare function ensureCacheDirectory(projectRoot: string, type: string, cacheKey: string): Promise<string>;
|
||||
export declare function getImageFromCacheAsync(fileName: string, cacheKey: string): Promise<null | Buffer>;
|
||||
export declare function cacheImageAsync(fileName: string, buffer: Buffer, cacheKey: string): Promise<void>;
|
||||
export declare function clearUnusedCachesAsync(projectRoot: string, type: string): Promise<void>;
|
77
node_modules/@expo/image-utils/build/Cache.js
generated
vendored
Normal file
77
node_modules/@expo/image-utils/build/Cache.js
generated
vendored
Normal file
@ -0,0 +1,77 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const crypto_1 = __importDefault(require("crypto"));
|
||||
const fs_extra_1 = require("fs-extra");
|
||||
const path_1 = require("path");
|
||||
const CACHE_LOCATION = '.expo/web/cache/production/images';
|
||||
const cacheKeys = {};
|
||||
// Calculate SHA256 Checksum value of a file based on its contents
|
||||
function calculateHash(filePath) {
|
||||
const contents = filePath.startsWith('http') ? filePath : fs_extra_1.readFileSync(filePath);
|
||||
return crypto_1.default.createHash('sha256').update(contents).digest('hex');
|
||||
}
|
||||
// Create a hash key for caching the images between builds
|
||||
function createCacheKey(fileSource, properties) {
|
||||
const hash = calculateHash(fileSource);
|
||||
return [hash].concat(properties).filter(Boolean).join('-');
|
||||
}
|
||||
exports.createCacheKey = createCacheKey;
|
||||
async function createCacheKeyWithDirectoryAsync(projectRoot, type, icon) {
|
||||
const cacheKey = `${type}-${createCacheKey(icon.src, [icon.resizeMode, icon.backgroundColor])}`;
|
||||
if (!(cacheKey in cacheKeys)) {
|
||||
cacheKeys[cacheKey] = await ensureCacheDirectory(projectRoot, type, cacheKey);
|
||||
}
|
||||
return cacheKey;
|
||||
}
|
||||
exports.createCacheKeyWithDirectoryAsync = createCacheKeyWithDirectoryAsync;
|
||||
async function ensureCacheDirectory(projectRoot, type, cacheKey) {
|
||||
const cacheFolder = path_1.join(projectRoot, CACHE_LOCATION, type, cacheKey);
|
||||
await fs_extra_1.ensureDir(cacheFolder);
|
||||
return cacheFolder;
|
||||
}
|
||||
exports.ensureCacheDirectory = ensureCacheDirectory;
|
||||
async function getImageFromCacheAsync(fileName, cacheKey) {
|
||||
try {
|
||||
return await fs_extra_1.readFile(path_1.resolve(cacheKeys[cacheKey], fileName));
|
||||
}
|
||||
catch (_a) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
exports.getImageFromCacheAsync = getImageFromCacheAsync;
|
||||
async function cacheImageAsync(fileName, buffer, cacheKey) {
|
||||
try {
|
||||
await fs_extra_1.writeFile(path_1.resolve(cacheKeys[cacheKey], fileName), buffer);
|
||||
}
|
||||
catch ({ message }) {
|
||||
console.warn(`Error caching image: "${fileName}". ${message}`);
|
||||
}
|
||||
}
|
||||
exports.cacheImageAsync = cacheImageAsync;
|
||||
async function clearUnusedCachesAsync(projectRoot, type) {
|
||||
// Clean up any old caches
|
||||
const cacheFolder = path_1.join(projectRoot, CACHE_LOCATION, type);
|
||||
await fs_extra_1.ensureDir(cacheFolder);
|
||||
const currentCaches = fs_extra_1.readdirSync(cacheFolder);
|
||||
if (!Array.isArray(currentCaches)) {
|
||||
console.warn('Failed to read the icon cache');
|
||||
return;
|
||||
}
|
||||
const deleteCachePromises = [];
|
||||
for (const cache of currentCaches) {
|
||||
// skip hidden folders
|
||||
if (cache.startsWith('.')) {
|
||||
continue;
|
||||
}
|
||||
// delete
|
||||
if (!(cache in cacheKeys)) {
|
||||
deleteCachePromises.push(fs_extra_1.remove(path_1.join(cacheFolder, cache)));
|
||||
}
|
||||
}
|
||||
await Promise.all(deleteCachePromises);
|
||||
}
|
||||
exports.clearUnusedCachesAsync = clearUnusedCachesAsync;
|
||||
//# sourceMappingURL=Cache.js.map
|
1
node_modules/@expo/image-utils/build/Cache.js.map
generated
vendored
Normal file
1
node_modules/@expo/image-utils/build/Cache.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
2
node_modules/@expo/image-utils/build/Download.d.ts
generated
vendored
Normal file
2
node_modules/@expo/image-utils/build/Download.d.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
export declare function downloadOrUseCachedImage(url: string): Promise<string>;
|
||||
export declare function downloadImage(url: string): Promise<string>;
|
52
node_modules/@expo/image-utils/build/Download.js
generated
vendored
Normal file
52
node_modules/@expo/image-utils/build/Download.js
generated
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fs_extra_1 = __importDefault(require("fs-extra"));
|
||||
const es_1 = __importDefault(require("jimp/es"));
|
||||
const node_fetch_1 = __importDefault(require("node-fetch"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const stream_1 = __importDefault(require("stream"));
|
||||
const tempy_1 = __importDefault(require("tempy"));
|
||||
const util_1 = __importDefault(require("util"));
|
||||
// cache downloaded images into memory
|
||||
const cacheDownloadedKeys = {};
|
||||
function stripQueryParams(url) {
|
||||
return url.split('?')[0].split('#')[0];
|
||||
}
|
||||
async function downloadOrUseCachedImage(url) {
|
||||
if (url in cacheDownloadedKeys) {
|
||||
return cacheDownloadedKeys[url];
|
||||
}
|
||||
if (url.startsWith('http')) {
|
||||
cacheDownloadedKeys[url] = await downloadImage(url);
|
||||
}
|
||||
else {
|
||||
cacheDownloadedKeys[url] = url;
|
||||
}
|
||||
return cacheDownloadedKeys[url];
|
||||
}
|
||||
exports.downloadOrUseCachedImage = downloadOrUseCachedImage;
|
||||
async function downloadImage(url) {
|
||||
const outputPath = tempy_1.default.directory();
|
||||
const response = await node_fetch_1.default(url);
|
||||
if (!response.ok) {
|
||||
throw new Error(`It was not possible to download image from '${url}'`);
|
||||
}
|
||||
// Download to local file
|
||||
const streamPipeline = util_1.default.promisify(stream_1.default.pipeline);
|
||||
const localPath = path_1.default.join(outputPath, path_1.default.basename(stripQueryParams(url)));
|
||||
await streamPipeline(response.body, fs_extra_1.default.createWriteStream(localPath));
|
||||
// If an image URL doesn't have a name, get the mime type and move the file.
|
||||
const img = await es_1.default.read(localPath);
|
||||
const mime = img.getMIME().split('/').pop();
|
||||
if (!localPath.endsWith(mime)) {
|
||||
const newPath = path_1.default.join(outputPath, `image.${mime}`);
|
||||
await fs_extra_1.default.move(localPath, newPath);
|
||||
return newPath;
|
||||
}
|
||||
return localPath;
|
||||
}
|
||||
exports.downloadImage = downloadImage;
|
||||
//# sourceMappingURL=Download.js.map
|
1
node_modules/@expo/image-utils/build/Download.js.map
generated
vendored
Normal file
1
node_modules/@expo/image-utils/build/Download.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"Download.js","sourceRoot":"","sources":["../src/Download.ts"],"names":[],"mappings":";;;;;AAAA,wDAA0B;AAC1B,iDAA2B;AAC3B,4DAA+B;AAC/B,gDAAwB;AACxB,oDAA4B;AAC5B,kDAA8B;AAC9B,gDAAwB;AAExB,sCAAsC;AACtC,MAAM,mBAAmB,GAA2B,EAAE,CAAC;AAEvD,SAAS,gBAAgB,CAAC,GAAW;IACnC,OAAO,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AACzC,CAAC;AAEM,KAAK,UAAU,wBAAwB,CAAC,GAAW;IACxD,IAAI,GAAG,IAAI,mBAAmB,EAAE;QAC9B,OAAO,mBAAmB,CAAC,GAAG,CAAC,CAAC;KACjC;IACD,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE;QAC1B,mBAAmB,CAAC,GAAG,CAAC,GAAG,MAAM,aAAa,CAAC,GAAG,CAAC,CAAC;KACrD;SAAM;QACL,mBAAmB,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;KAChC;IACD,OAAO,mBAAmB,CAAC,GAAG,CAAC,CAAC;AAClC,CAAC;AAVD,4DAUC;AAEM,KAAK,UAAU,aAAa,CAAC,GAAW;IAC7C,MAAM,UAAU,GAAG,eAAS,CAAC,SAAS,EAAE,CAAC;IAEzC,MAAM,QAAQ,GAAG,MAAM,oBAAK,CAAC,GAAG,CAAC,CAAC;IAClC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,+CAA+C,GAAG,GAAG,CAAC,CAAC;KACxE;IAED,yBAAyB;IACzB,MAAM,cAAc,GAAG,cAAI,CAAC,SAAS,CAAC,gBAAM,CAAC,QAAQ,CAAC,CAAC;IACvD,MAAM,SAAS,GAAG,cAAI,CAAC,IAAI,CAAC,UAAU,EAAE,cAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAC9E,MAAM,cAAc,CAAC,QAAQ,CAAC,IAAI,EAAE,kBAAE,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,CAAC;IAErE,4EAA4E;IAC5E,MAAM,GAAG,GAAG,MAAM,YAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACvC,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAG,CAAC;IAC7C,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;QAC7B,MAAM,OAAO,GAAG,cAAI,CAAC,IAAI,CAAC,UAAU,EAAE,SAAS,IAAI,EAAE,CAAC,CAAC;QACvD,MAAM,kBAAE,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAClC,OAAO,OAAO,CAAC;KAChB;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAvBD,sCAuBC","sourcesContent":["import fs from 'fs-extra';\nimport Jimp from 'jimp/es';\nimport fetch from 'node-fetch';\nimport path from 'path';\nimport stream from 'stream';\nimport temporary from 'tempy';\nimport util from 'util';\n\n// cache downloaded images into memory\nconst cacheDownloadedKeys: Record<string, string> = {};\n\nfunction stripQueryParams(url: string): string {\n return url.split('?')[0].split('#')[0];\n}\n\nexport async function downloadOrUseCachedImage(url: string): Promise<string> {\n if (url in cacheDownloadedKeys) {\n return cacheDownloadedKeys[url];\n }\n if (url.startsWith('http')) {\n cacheDownloadedKeys[url] = await downloadImage(url);\n } else {\n cacheDownloadedKeys[url] = url;\n }\n return cacheDownloadedKeys[url];\n}\n\nexport async function downloadImage(url: string): Promise<string> {\n const outputPath = temporary.directory();\n\n const response = await fetch(url);\n if (!response.ok) {\n throw new Error(`It was not possible to download image from '${url}'`);\n }\n\n // Download to local file\n const streamPipeline = util.promisify(stream.pipeline);\n const localPath = path.join(outputPath, path.basename(stripQueryParams(url)));\n await streamPipeline(response.body, fs.createWriteStream(localPath));\n\n // If an image URL doesn't have a name, get the mime type and move the file.\n const img = await Jimp.read(localPath);\n const mime = img.getMIME().split('/').pop()!;\n if (!localPath.endsWith(mime)) {\n const newPath = path.join(outputPath, `image.${mime}`);\n await fs.move(localPath, newPath);\n return newPath;\n }\n\n return localPath;\n}\n"]}
|
2
node_modules/@expo/image-utils/build/Ico.d.ts
generated
vendored
Normal file
2
node_modules/@expo/image-utils/build/Ico.d.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/// <reference types="node" />
|
||||
export declare function generateAsync(buffers: Buffer[]): Promise<Buffer>;
|
97
node_modules/@expo/image-utils/build/Ico.js
generated
vendored
Normal file
97
node_modules/@expo/image-utils/build/Ico.js
generated
vendored
Normal file
@ -0,0 +1,97 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
// Inspired by https://github.com/kevva/to-ico but reuses existing packages to keep bundle size small.
|
||||
const parse_png_1 = __importDefault(require("parse-png"));
|
||||
const constants = {
|
||||
directorySize: 16,
|
||||
bitmapSize: 40,
|
||||
headerSize: 6,
|
||||
colorMode: 0,
|
||||
};
|
||||
function createHeader(header) {
|
||||
const buffer = Buffer.alloc(constants.headerSize);
|
||||
buffer.writeUInt16LE(0, 0);
|
||||
buffer.writeUInt16LE(1, 2);
|
||||
buffer.writeUInt16LE(header, 4);
|
||||
return buffer;
|
||||
}
|
||||
function createDirectory(data, offset) {
|
||||
const buffer = Buffer.alloc(constants.directorySize);
|
||||
const size = data.data.length + constants.bitmapSize;
|
||||
const width = data.width === 256 ? 0 : data.width;
|
||||
const height = data.height === 256 ? 0 : data.height;
|
||||
const bpp = data.bpp * 8;
|
||||
buffer.writeUInt8(width, 0);
|
||||
buffer.writeUInt8(height, 1);
|
||||
buffer.writeUInt8(0, 2);
|
||||
buffer.writeUInt8(0, 3);
|
||||
buffer.writeUInt16LE(1, 4);
|
||||
buffer.writeUInt16LE(bpp, 6);
|
||||
buffer.writeUInt32LE(size, 8);
|
||||
buffer.writeUInt32LE(offset, 12);
|
||||
return buffer;
|
||||
}
|
||||
function createBitmap(data, compression) {
|
||||
const buffer = Buffer.alloc(constants.bitmapSize);
|
||||
buffer.writeUInt32LE(constants.bitmapSize, 0);
|
||||
buffer.writeInt32LE(data.width, 4);
|
||||
buffer.writeInt32LE(data.height * 2, 8);
|
||||
buffer.writeUInt16LE(1, 12);
|
||||
buffer.writeUInt16LE(data.bpp * 8, 14);
|
||||
buffer.writeUInt32LE(compression, 16);
|
||||
buffer.writeUInt32LE(data.data.length, 20);
|
||||
buffer.writeInt32LE(0, 24);
|
||||
buffer.writeInt32LE(0, 28);
|
||||
buffer.writeUInt32LE(0, 32);
|
||||
buffer.writeUInt32LE(0, 36);
|
||||
return buffer;
|
||||
}
|
||||
function createDIB(data, width, height, bpp) {
|
||||
const cols = width * bpp;
|
||||
const rows = height * cols;
|
||||
const end = rows - cols;
|
||||
const buffer = Buffer.alloc(data.length);
|
||||
for (let row = 0; row < rows; row += cols) {
|
||||
for (let col = 0; col < cols; col += bpp) {
|
||||
let pos = row + col;
|
||||
const r = data.readUInt8(pos);
|
||||
const g = data.readUInt8(pos + 1);
|
||||
const b = data.readUInt8(pos + 2);
|
||||
const a = data.readUInt8(pos + 3);
|
||||
pos = end - row + col;
|
||||
buffer.writeUInt8(b, pos);
|
||||
buffer.writeUInt8(g, pos + 1);
|
||||
buffer.writeUInt8(r, pos + 2);
|
||||
buffer.writeUInt8(a, pos + 3);
|
||||
}
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
function generateFromPNGs(pngs) {
|
||||
const header = createHeader(pngs.length);
|
||||
const arr = [header];
|
||||
let len = header.length;
|
||||
let offset = constants.headerSize + constants.directorySize * pngs.length;
|
||||
for (const png of pngs) {
|
||||
const dir = createDirectory(png, offset);
|
||||
arr.push(dir);
|
||||
len += dir.length;
|
||||
offset += png.data.length + constants.bitmapSize;
|
||||
}
|
||||
for (const png of pngs) {
|
||||
const header = createBitmap(png, constants.colorMode);
|
||||
const dib = createDIB(png.data, png.width, png.height, png.bpp);
|
||||
arr.push(header, dib);
|
||||
len += header.length + dib.length;
|
||||
}
|
||||
return Buffer.concat(arr, len);
|
||||
}
|
||||
async function generateAsync(buffers) {
|
||||
const pngs = await Promise.all(buffers.map(x => parse_png_1.default(x)));
|
||||
return generateFromPNGs(pngs);
|
||||
}
|
||||
exports.generateAsync = generateAsync;
|
||||
//# sourceMappingURL=Ico.js.map
|
1
node_modules/@expo/image-utils/build/Ico.js.map
generated
vendored
Normal file
1
node_modules/@expo/image-utils/build/Ico.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
24
node_modules/@expo/image-utils/build/Image.d.ts
generated
vendored
Normal file
24
node_modules/@expo/image-utils/build/Image.d.ts
generated
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
/// <reference types="node" />
|
||||
import { ImageOptions } from './Image.types';
|
||||
export declare function generateImageAsync(options: {
|
||||
projectRoot: string;
|
||||
cacheType?: string;
|
||||
}, imageOptions: ImageOptions): Promise<{
|
||||
source: Buffer;
|
||||
name: string;
|
||||
}>;
|
||||
export declare function generateFaviconAsync(pngImageBuffer: Buffer, sizes?: number[]): Promise<Buffer>;
|
||||
/**
|
||||
* Layers the provided foreground image over the provided background image.
|
||||
*
|
||||
* @param foregroundImageBuffer
|
||||
* @param foregroundImageBuffer
|
||||
* @param x pixel offset from the left edge, defaults to 0.
|
||||
* @param y pixel offset from the top edge, defaults to 0.
|
||||
*/
|
||||
export declare function compositeImagesAsync({ foreground, background, x, y, }: {
|
||||
foreground: Buffer;
|
||||
background: Buffer;
|
||||
x?: number;
|
||||
y?: number;
|
||||
}): Promise<Buffer>;
|
164
node_modules/@expo/image-utils/build/Image.js
generated
vendored
Normal file
164
node_modules/@expo/image-utils/build/Image.js
generated
vendored
Normal file
@ -0,0 +1,164 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const chalk_1 = __importDefault(require("chalk"));
|
||||
const mime_1 = __importDefault(require("mime"));
|
||||
const Cache = __importStar(require("./Cache"));
|
||||
const Download = __importStar(require("./Download"));
|
||||
const Ico = __importStar(require("./Ico"));
|
||||
const Jimp = __importStar(require("./jimp"));
|
||||
const Sharp = __importStar(require("./sharp"));
|
||||
const supportedMimeTypes = ['image/png', 'image/jpeg', 'image/webp', 'image/gif'];
|
||||
let hasWarned = false;
|
||||
async function resizeImagesAsync(buffer, sizes) {
|
||||
const sharp = await getSharpAsync();
|
||||
if (!sharp) {
|
||||
return Jimp.resizeBufferAsync(buffer, sizes);
|
||||
}
|
||||
return Sharp.resizeBufferAsync(buffer, sizes);
|
||||
}
|
||||
async function resizeAsync(imageOptions) {
|
||||
const sharp = await getSharpAsync();
|
||||
const { width, height, backgroundColor, resizeMode } = imageOptions;
|
||||
if (!sharp) {
|
||||
const inputOptions = { input: imageOptions.src, quality: 100 };
|
||||
const jimp = await Jimp.resize(inputOptions, {
|
||||
width,
|
||||
height,
|
||||
fit: resizeMode,
|
||||
background: backgroundColor,
|
||||
});
|
||||
if (imageOptions.removeTransparency) {
|
||||
jimp.colorType(2);
|
||||
}
|
||||
if (imageOptions.borderRadius) {
|
||||
// TODO: support setting border radius with Jimp. Currently only support making the image a circle
|
||||
await Jimp.circleAsync(jimp);
|
||||
}
|
||||
const imgBuffer = await jimp.getBufferAsync(jimp.getMIME());
|
||||
return imgBuffer;
|
||||
}
|
||||
try {
|
||||
let sharpBuffer = sharp(imageOptions.src)
|
||||
.ensureAlpha()
|
||||
.resize(width, height, { fit: resizeMode, background: 'transparent' });
|
||||
// Skip an extra step if the background is explicitly transparent.
|
||||
if (backgroundColor && backgroundColor !== 'transparent') {
|
||||
// Add the background color to the image
|
||||
sharpBuffer = sharpBuffer.composite([
|
||||
{
|
||||
// create a background color
|
||||
input: {
|
||||
create: {
|
||||
width,
|
||||
height,
|
||||
// allow alpha colors
|
||||
channels: imageOptions.removeTransparency ? 3 : 4,
|
||||
background: backgroundColor,
|
||||
},
|
||||
},
|
||||
// dest-over makes the first image (input) appear on top of the created image (background color)
|
||||
blend: 'dest-over',
|
||||
},
|
||||
]);
|
||||
}
|
||||
else if (imageOptions.removeTransparency) {
|
||||
sharpBuffer.flatten();
|
||||
}
|
||||
if (imageOptions.borderRadius) {
|
||||
const mask = Buffer.from(`<svg><rect x="0" y="0" width="${width}" height="${height}"
|
||||
rx="${imageOptions.borderRadius}" ry="${imageOptions.borderRadius}"
|
||||
fill="${backgroundColor && backgroundColor !== 'transparent' ? backgroundColor : 'none'}" /></svg>`);
|
||||
sharpBuffer.composite([{ input: mask, blend: 'dest-over' }]);
|
||||
}
|
||||
return await sharpBuffer.png().toBuffer();
|
||||
}
|
||||
catch ({ message }) {
|
||||
throw new Error(`It was not possible to generate splash screen '${imageOptions.src}'. ${message}`);
|
||||
}
|
||||
}
|
||||
async function getSharpAsync() {
|
||||
let sharp;
|
||||
if (await Sharp.isAvailableAsync())
|
||||
sharp = await Sharp.findSharpInstanceAsync();
|
||||
return sharp;
|
||||
}
|
||||
function getDimensionsId(imageOptions) {
|
||||
return imageOptions.width === imageOptions.height
|
||||
? `${imageOptions.width}`
|
||||
: `${imageOptions.width}x${imageOptions.height}`;
|
||||
}
|
||||
async function maybeWarnAboutInstallingSharpAsync() {
|
||||
// Putting the warning here will prevent the warning from showing if all images were reused from the cache
|
||||
if (!hasWarned && !(await Sharp.isAvailableAsync())) {
|
||||
hasWarned = true;
|
||||
console.log();
|
||||
console.log(chalk_1.default.bgYellow.black(`Using node to generate images. This is much slower than using native packages.`));
|
||||
console.log(chalk_1.default.yellow(`\u203A Optionally you can stop the process and try again after successfully running \`npm install -g sharp-cli\`.\n`));
|
||||
}
|
||||
}
|
||||
async function ensureImageOptionsAsync(imageOptions) {
|
||||
const icon = Object.assign(Object.assign({}, imageOptions), { src: await Download.downloadOrUseCachedImage(imageOptions.src) });
|
||||
const mimeType = mime_1.default.getType(icon.src);
|
||||
if (!mimeType) {
|
||||
throw new Error(`Invalid mimeType for image with source: ${icon.src}`);
|
||||
}
|
||||
if (!supportedMimeTypes.includes(mimeType)) {
|
||||
throw new Error(`Supplied image is not a supported image type: ${imageOptions.src}`);
|
||||
}
|
||||
if (!icon.name) {
|
||||
icon.name = `icon_${getDimensionsId(imageOptions)}.${mime_1.default.getExtension(mimeType)}`;
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
async function generateImageAsync(options, imageOptions) {
|
||||
const icon = await ensureImageOptionsAsync(imageOptions);
|
||||
if (!options.cacheType) {
|
||||
await maybeWarnAboutInstallingSharpAsync();
|
||||
return { name: icon.name, source: await resizeAsync(icon) };
|
||||
}
|
||||
const cacheKey = await Cache.createCacheKeyWithDirectoryAsync(options.projectRoot, options.cacheType, icon);
|
||||
const name = icon.name;
|
||||
let source = await Cache.getImageFromCacheAsync(name, cacheKey);
|
||||
if (!source) {
|
||||
await maybeWarnAboutInstallingSharpAsync();
|
||||
source = await resizeAsync(icon);
|
||||
await Cache.cacheImageAsync(name, source, cacheKey);
|
||||
}
|
||||
return { name, source };
|
||||
}
|
||||
exports.generateImageAsync = generateImageAsync;
|
||||
async function generateFaviconAsync(pngImageBuffer, sizes = [16, 32, 48]) {
|
||||
const buffers = await resizeImagesAsync(pngImageBuffer, sizes);
|
||||
return await Ico.generateAsync(buffers);
|
||||
}
|
||||
exports.generateFaviconAsync = generateFaviconAsync;
|
||||
/**
|
||||
* Layers the provided foreground image over the provided background image.
|
||||
*
|
||||
* @param foregroundImageBuffer
|
||||
* @param foregroundImageBuffer
|
||||
* @param x pixel offset from the left edge, defaults to 0.
|
||||
* @param y pixel offset from the top edge, defaults to 0.
|
||||
*/
|
||||
async function compositeImagesAsync({ foreground, background, x = 0, y = 0, }) {
|
||||
const sharp = await getSharpAsync();
|
||||
if (!sharp) {
|
||||
const image = (await Jimp.getJimpImageAsync(background)).composite(await Jimp.getJimpImageAsync(foreground), x, y);
|
||||
return await image.getBufferAsync(image.getMIME());
|
||||
}
|
||||
return await sharp(background)
|
||||
.composite([{ input: foreground, left: x, top: y }])
|
||||
.toBuffer();
|
||||
}
|
||||
exports.compositeImagesAsync = compositeImagesAsync;
|
||||
//# sourceMappingURL=Image.js.map
|
1
node_modules/@expo/image-utils/build/Image.js.map
generated
vendored
Normal file
1
node_modules/@expo/image-utils/build/Image.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
13
node_modules/@expo/image-utils/build/Image.types.d.ts
generated
vendored
Normal file
13
node_modules/@expo/image-utils/build/Image.types.d.ts
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
export declare type ResizeMode = 'contain' | 'cover' | 'fill' | 'inside' | 'outside';
|
||||
export declare type ImageFormat = 'input' | 'jpeg' | 'jpg' | 'png' | 'raw' | 'tiff' | 'webp';
|
||||
export declare type ImageOptions = {
|
||||
src: string;
|
||||
name?: string;
|
||||
resizeMode: ResizeMode;
|
||||
backgroundColor: string;
|
||||
removeTransparency?: boolean;
|
||||
width: number;
|
||||
height: number;
|
||||
padding?: number;
|
||||
borderRadius?: number;
|
||||
};
|
3
node_modules/@expo/image-utils/build/Image.types.js
generated
vendored
Normal file
3
node_modules/@expo/image-utils/build/Image.types.js
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=Image.types.js.map
|
1
node_modules/@expo/image-utils/build/Image.types.js.map
generated
vendored
Normal file
1
node_modules/@expo/image-utils/build/Image.types.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"Image.types.js","sourceRoot":"","sources":["../src/Image.types.ts"],"names":[],"mappings":"","sourcesContent":["export type ResizeMode = 'contain' | 'cover' | 'fill' | 'inside' | 'outside';\n\nexport type ImageFormat = 'input' | 'jpeg' | 'jpg' | 'png' | 'raw' | 'tiff' | 'webp';\n\nexport type ImageOptions = {\n src: string;\n name?: string;\n resizeMode: ResizeMode;\n backgroundColor: string;\n removeTransparency?: boolean;\n width: number;\n height: number;\n padding?: number;\n borderRadius?: number;\n};\n"]}
|
10
node_modules/@expo/image-utils/build/index.d.ts
generated
vendored
Normal file
10
node_modules/@expo/image-utils/build/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
/// <reference types="node" />
|
||||
import * as Cache from './Cache';
|
||||
import { compositeImagesAsync, generateFaviconAsync, generateImageAsync } from './Image';
|
||||
import { ImageFormat, ImageOptions, ResizeMode } from './Image.types';
|
||||
import { jimpAsync } from './jimp';
|
||||
import { findSharpInstanceAsync, isAvailableAsync, sharpAsync } from './sharp';
|
||||
import { SharpCommandOptions, SharpGlobalOptions } from './sharp.types';
|
||||
export declare function imageAsync(options: SharpGlobalOptions, commands?: SharpCommandOptions[]): Promise<Buffer | string[]>;
|
||||
export { jimpAsync, findSharpInstanceAsync, isAvailableAsync, sharpAsync, generateImageAsync, generateFaviconAsync, Cache, compositeImagesAsync, };
|
||||
export { SharpGlobalOptions, SharpCommandOptions, ResizeMode, ImageFormat, ImageOptions };
|
29
node_modules/@expo/image-utils/build/index.js
generated
vendored
Normal file
29
node_modules/@expo/image-utils/build/index.js
generated
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const Cache = __importStar(require("./Cache"));
|
||||
exports.Cache = Cache;
|
||||
const Image_1 = require("./Image");
|
||||
exports.compositeImagesAsync = Image_1.compositeImagesAsync;
|
||||
exports.generateFaviconAsync = Image_1.generateFaviconAsync;
|
||||
exports.generateImageAsync = Image_1.generateImageAsync;
|
||||
const jimp_1 = require("./jimp");
|
||||
exports.jimpAsync = jimp_1.jimpAsync;
|
||||
const sharp_1 = require("./sharp");
|
||||
exports.findSharpInstanceAsync = sharp_1.findSharpInstanceAsync;
|
||||
exports.isAvailableAsync = sharp_1.isAvailableAsync;
|
||||
exports.sharpAsync = sharp_1.sharpAsync;
|
||||
async function imageAsync(options, commands = []) {
|
||||
if (await sharp_1.isAvailableAsync()) {
|
||||
return sharp_1.sharpAsync(options, commands);
|
||||
}
|
||||
return jimp_1.jimpAsync(Object.assign(Object.assign({}, options), { format: jimp_1.convertFormat(options.format), originalInput: options.input }), commands);
|
||||
}
|
||||
exports.imageAsync = imageAsync;
|
||||
//# sourceMappingURL=index.js.map
|
1
node_modules/@expo/image-utils/build/index.js.map
generated
vendored
Normal file
1
node_modules/@expo/image-utils/build/index.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA,+CAAiC;AA2B/B,sBAAK;AA1BP,mCAAyF;AA2BvF,+BA3BO,4BAAoB,CA2BP;AAFpB,+BAzB6B,4BAAoB,CAyB7B;AADpB,6BAxBmD,0BAAkB,CAwBnD;AAtBpB,iCAAkD;AAkBhD,oBAlBsB,gBAAS,CAkBtB;AAjBX,mCAA+E;AAkB7E,iCAlBO,8BAAsB,CAkBP;AACtB,2BAnB+B,wBAAgB,CAmB/B;AAChB,qBApBiD,kBAAU,CAoBjD;AAjBL,KAAK,UAAU,UAAU,CAC9B,OAA2B,EAC3B,WAAkC,EAAE;IAEpC,IAAI,MAAM,wBAAgB,EAAE,EAAE;QAC5B,OAAO,kBAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;KACtC;IACD,OAAO,gBAAS,iCACT,OAAO,KAAE,MAAM,EAAE,oBAAa,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,aAAa,EAAE,OAAO,CAAC,KAAK,KACjF,QAAQ,CACT,CAAC;AACJ,CAAC;AAXD,gCAWC","sourcesContent":["import * as Cache from './Cache';\nimport { compositeImagesAsync, generateFaviconAsync, generateImageAsync } from './Image';\nimport { ImageFormat, ImageOptions, ResizeMode } from './Image.types';\nimport { convertFormat, jimpAsync } from './jimp';\nimport { findSharpInstanceAsync, isAvailableAsync, sharpAsync } from './sharp';\nimport { SharpCommandOptions, SharpGlobalOptions } from './sharp.types';\n\nexport async function imageAsync(\n options: SharpGlobalOptions,\n commands: SharpCommandOptions[] = []\n) {\n if (await isAvailableAsync()) {\n return sharpAsync(options, commands);\n }\n return jimpAsync(\n { ...options, format: convertFormat(options.format), originalInput: options.input },\n commands\n );\n}\n\nexport {\n jimpAsync,\n findSharpInstanceAsync,\n isAvailableAsync,\n sharpAsync,\n generateImageAsync,\n generateFaviconAsync,\n Cache,\n compositeImagesAsync,\n};\n\nexport { SharpGlobalOptions, SharpCommandOptions, ResizeMode, ImageFormat, ImageOptions };\n"]}
|
15
node_modules/@expo/image-utils/build/jimp.d.ts
generated
vendored
Normal file
15
node_modules/@expo/image-utils/build/jimp.d.ts
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
/// <reference types="node" />
|
||||
import Jimp from 'jimp/es';
|
||||
import { ResizeOptions, SharpCommandOptions, SharpGlobalOptions } from './sharp.types';
|
||||
declare type JimpGlobalOptions = Omit<SharpGlobalOptions, 'input'> & {
|
||||
input: string | Buffer | Jimp;
|
||||
originalInput: string;
|
||||
};
|
||||
export declare function resizeBufferAsync(buffer: Buffer, sizes: number[]): Promise<Buffer[]>;
|
||||
export declare function convertFormat(format?: string): string | undefined;
|
||||
export declare function jimpAsync(options: JimpGlobalOptions, commands?: SharpCommandOptions[]): Promise<Buffer>;
|
||||
export declare function isFolderAsync(path: string): Promise<boolean>;
|
||||
export declare function circleAsync(jimp: Jimp): Promise<Jimp>;
|
||||
export declare function getJimpImageAsync(input: string | Buffer | Jimp): Promise<Jimp>;
|
||||
export declare function resize({ input, quality }: JimpGlobalOptions, { background, position, fit, width, height }: Omit<ResizeOptions, 'operation'>): Promise<Jimp>;
|
||||
export {};
|
180
node_modules/@expo/image-utils/build/jimp.js
generated
vendored
Normal file
180
node_modules/@expo/image-utils/build/jimp.js
generated
vendored
Normal file
@ -0,0 +1,180 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fs_extra_1 = __importDefault(require("fs-extra"));
|
||||
const es_1 = __importDefault(require("jimp/es"));
|
||||
const path = __importStar(require("path"));
|
||||
async function resizeBufferAsync(buffer, sizes) {
|
||||
return Promise.all(sizes.map(async (size) => {
|
||||
// Parse the buffer each time to prevent mutable copies.
|
||||
// Parse the buffer each time to prevent mutable copies.
|
||||
const jimpImage = await es_1.default.read(buffer);
|
||||
const mime = jimpImage.getMIME();
|
||||
return jimpImage.resize(size, size).getBufferAsync(mime);
|
||||
}));
|
||||
}
|
||||
exports.resizeBufferAsync = resizeBufferAsync;
|
||||
function convertFormat(format) {
|
||||
if (typeof format === 'undefined')
|
||||
return format;
|
||||
const input = format === null || format === void 0 ? void 0 : format.toLowerCase();
|
||||
switch (input) {
|
||||
case 'png':
|
||||
case 'webp':
|
||||
case 'jpeg':
|
||||
return `image/${input}`;
|
||||
case 'jpg':
|
||||
return `image/jpeg`;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
exports.convertFormat = convertFormat;
|
||||
async function jimpAsync(options, commands = []) {
|
||||
if (commands.length) {
|
||||
const command = commands.shift();
|
||||
if (command) {
|
||||
let input;
|
||||
if (command.operation === 'resize') {
|
||||
input = await resize(options, command);
|
||||
}
|
||||
else if (command.operation === 'flatten') {
|
||||
input = await flatten(options, command);
|
||||
}
|
||||
else {
|
||||
throw new Error(`The operation: '${command.operation}' is not supported with Jimp`);
|
||||
}
|
||||
// @ts-ignore
|
||||
return jimpAsync(Object.assign(Object.assign({}, options), { input }), commands);
|
||||
}
|
||||
}
|
||||
const image = await getJimpImageAsync(options.input);
|
||||
const mime = typeof options.format === 'string' ? options.format : image.getMIME();
|
||||
const imgBuffer = await image.getBufferAsync(mime);
|
||||
if (typeof options.output === 'string') {
|
||||
if (await isFolderAsync(options.output)) {
|
||||
await fs_extra_1.default.writeFile(path.join(options.output, path.basename(options.originalInput)), imgBuffer);
|
||||
}
|
||||
else {
|
||||
await fs_extra_1.default.writeFile(options.output, imgBuffer);
|
||||
}
|
||||
}
|
||||
return imgBuffer;
|
||||
}
|
||||
exports.jimpAsync = jimpAsync;
|
||||
async function isFolderAsync(path) {
|
||||
try {
|
||||
return (await fs_extra_1.default.stat(path)).isDirectory();
|
||||
}
|
||||
catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
exports.isFolderAsync = isFolderAsync;
|
||||
function circleAsync(jimp) {
|
||||
const radius = Math.min(jimp.bitmap.width, jimp.bitmap.height) / 2;
|
||||
const center = {
|
||||
x: jimp.bitmap.width / 2,
|
||||
y: jimp.bitmap.height / 2,
|
||||
};
|
||||
return new Promise(resolve => {
|
||||
jimp.scanQuiet(0, 0, jimp.bitmap.width, jimp.bitmap.height, (x, y, idx) => {
|
||||
const curR = Math.sqrt(Math.pow(x - center.x, 2) + Math.pow(y - center.y, 2));
|
||||
if (radius - curR <= 0.0) {
|
||||
jimp.bitmap.data[idx + 3] = 0;
|
||||
}
|
||||
else if (radius - curR < 1.0) {
|
||||
jimp.bitmap.data[idx + 3] = 255 * (radius - curR);
|
||||
}
|
||||
resolve(jimp);
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.circleAsync = circleAsync;
|
||||
async function getJimpImageAsync(input) {
|
||||
// @ts-ignore: Jimp types are broken
|
||||
if (typeof input === 'string' || input instanceof Buffer)
|
||||
return await es_1.default.read(input);
|
||||
return input;
|
||||
}
|
||||
exports.getJimpImageAsync = getJimpImageAsync;
|
||||
async function resize({ input, quality = 100 }, { background, position, fit, width, height = es_1.default.AUTO }) {
|
||||
let initialImage = await getJimpImageAsync(input);
|
||||
const jimpPosition = convertPosition(position);
|
||||
const jimpQuality = typeof quality !== 'number' ? 100 : quality;
|
||||
if (fit === 'cover') {
|
||||
initialImage = initialImage.cover(width, height, jimpPosition);
|
||||
}
|
||||
else if (fit === 'contain') {
|
||||
initialImage = initialImage.contain(width, height, jimpPosition);
|
||||
}
|
||||
else {
|
||||
throw new Error(`Unsupported fit: ${fit}. Please choose either 'cover', or 'contain' when using Jimp`);
|
||||
}
|
||||
if (background) {
|
||||
initialImage = initialImage.composite(new es_1.default(width, height, background), 0, 0, {
|
||||
mode: es_1.default.BLEND_DESTINATION_OVER,
|
||||
opacitySource: 1,
|
||||
opacityDest: 1,
|
||||
});
|
||||
}
|
||||
return await initialImage.quality(jimpQuality);
|
||||
}
|
||||
exports.resize = resize;
|
||||
async function flatten({ input, quality = 100 }, { background }) {
|
||||
const initialImage = await getJimpImageAsync(input);
|
||||
const jimpQuality = typeof quality !== 'number' ? 100 : quality;
|
||||
return initialImage.quality(jimpQuality).background(es_1.default.cssColorToHex(background));
|
||||
}
|
||||
/**
|
||||
* Convert sharp position to Jimp position.
|
||||
*
|
||||
* @param position
|
||||
*/
|
||||
function convertPosition(position) {
|
||||
if (!position)
|
||||
return convertPosition('center');
|
||||
switch (position) {
|
||||
case 'center':
|
||||
case 'centre':
|
||||
return es_1.default.VERTICAL_ALIGN_MIDDLE | es_1.default.HORIZONTAL_ALIGN_CENTER;
|
||||
case 'north':
|
||||
case 'top':
|
||||
return es_1.default.VERTICAL_ALIGN_TOP | es_1.default.HORIZONTAL_ALIGN_CENTER;
|
||||
case 'east':
|
||||
case 'right':
|
||||
return es_1.default.VERTICAL_ALIGN_MIDDLE | es_1.default.HORIZONTAL_ALIGN_RIGHT;
|
||||
case 'south':
|
||||
case 'bottom':
|
||||
return es_1.default.VERTICAL_ALIGN_BOTTOM | es_1.default.HORIZONTAL_ALIGN_CENTER;
|
||||
case 'west':
|
||||
case 'left':
|
||||
return es_1.default.VERTICAL_ALIGN_MIDDLE | es_1.default.HORIZONTAL_ALIGN_LEFT;
|
||||
case 'northeast':
|
||||
case 'right top':
|
||||
return es_1.default.VERTICAL_ALIGN_TOP | es_1.default.HORIZONTAL_ALIGN_RIGHT;
|
||||
case 'southeast':
|
||||
case 'right bottom':
|
||||
return es_1.default.VERTICAL_ALIGN_BOTTOM | es_1.default.HORIZONTAL_ALIGN_RIGHT;
|
||||
case 'southwest':
|
||||
case 'left bottom':
|
||||
return es_1.default.VERTICAL_ALIGN_BOTTOM | es_1.default.HORIZONTAL_ALIGN_LEFT;
|
||||
case 'northwest':
|
||||
case 'left top':
|
||||
return es_1.default.VERTICAL_ALIGN_TOP | es_1.default.HORIZONTAL_ALIGN_LEFT;
|
||||
case 'entropy':
|
||||
case 'attention':
|
||||
throw new Error(`Position: '${position}' is not supported`);
|
||||
default:
|
||||
throw new Error(`Unknown position: '${position}'`);
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=jimp.js.map
|
1
node_modules/@expo/image-utils/build/jimp.js.map
generated
vendored
Normal file
1
node_modules/@expo/image-utils/build/jimp.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
14
node_modules/@expo/image-utils/build/sharp.d.ts
generated
vendored
Normal file
14
node_modules/@expo/image-utils/build/sharp.d.ts
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
/// <reference types="node" />
|
||||
import { SharpCommandOptions, SharpGlobalOptions } from './sharp.types';
|
||||
export declare function resizeBufferAsync(buffer: Buffer, sizes: number[]): Promise<Buffer[]>;
|
||||
/**
|
||||
* Returns `true` if a global sharp instance can be found.
|
||||
* This functionality can be overridden with `process.env.EXPO_IMAGE_UTILS_NO_SHARP=1`.
|
||||
*/
|
||||
export declare function isAvailableAsync(): Promise<boolean>;
|
||||
export declare function sharpAsync(options: SharpGlobalOptions, commands?: SharpCommandOptions[]): Promise<string[]>;
|
||||
/**
|
||||
* Returns the instance of `sharp` installed by the global `sharp-cli` package.
|
||||
* This method will throw errors if the `sharp` instance cannot be found, these errors can be circumvented by ensuring `isAvailableAsync()` resolves to `true`.
|
||||
*/
|
||||
export declare function findSharpInstanceAsync(): Promise<any | null>;
|
202
node_modules/@expo/image-utils/build/sharp.js
generated
vendored
Normal file
202
node_modules/@expo/image-utils/build/sharp.js
generated
vendored
Normal file
@ -0,0 +1,202 @@
|
||||
"use strict";
|
||||
var __rest = (this && this.__rest) || function (s, e) {
|
||||
var t = {};
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
||||
t[p] = s[p];
|
||||
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
||||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
||||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
||||
t[p[i]] = s[p[i]];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const spawn_async_1 = __importDefault(require("@expo/spawn-async"));
|
||||
const getenv_1 = require("getenv");
|
||||
const resolve_from_1 = __importDefault(require("resolve-from"));
|
||||
const semver_1 = __importDefault(require("semver"));
|
||||
const SHARP_HELP_PATTERN = /\n\nSpecify --help for available options/g;
|
||||
const SHARP_REQUIRED_VERSION = '^1.10.0';
|
||||
async function resizeBufferAsync(buffer, sizes) {
|
||||
const sharp = await findSharpInstanceAsync();
|
||||
const metadata = await sharp(buffer).metadata();
|
||||
// Create buffer for each size
|
||||
const resizedBuffers = await Promise.all(sizes.map(dimension => {
|
||||
const density = (dimension / Math.max(metadata.width, metadata.height)) * metadata.density;
|
||||
return sharp(buffer, {
|
||||
density: isNaN(density) ? undefined : Math.ceil(density),
|
||||
})
|
||||
.resize(dimension, dimension, { fit: 'contain', background: 'transparent' })
|
||||
.toBuffer();
|
||||
}));
|
||||
return resizedBuffers;
|
||||
}
|
||||
exports.resizeBufferAsync = resizeBufferAsync;
|
||||
const isSharpDisabled = getenv_1.boolish('EXPO_IMAGE_UTILS_NO_SHARP', false);
|
||||
/**
|
||||
* Returns `true` if a global sharp instance can be found.
|
||||
* This functionality can be overridden with `process.env.EXPO_IMAGE_UTILS_NO_SHARP=1`.
|
||||
*/
|
||||
async function isAvailableAsync() {
|
||||
if (isSharpDisabled) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
return !!(await findSharpBinAsync());
|
||||
}
|
||||
catch (_a) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
exports.isAvailableAsync = isAvailableAsync;
|
||||
async function sharpAsync(options, commands = []) {
|
||||
const bin = await findSharpBinAsync();
|
||||
try {
|
||||
const { stdout } = await spawn_async_1.default(bin, [
|
||||
...getOptions(options),
|
||||
...getCommandOptions(commands),
|
||||
]);
|
||||
const outputFilePaths = stdout.trim().split('\n');
|
||||
return outputFilePaths;
|
||||
}
|
||||
catch (error) {
|
||||
if (error.stderr) {
|
||||
throw new Error('\nProcessing images using sharp-cli failed: ' +
|
||||
error.message +
|
||||
'\nOutput: ' +
|
||||
error.stderr.replace(SHARP_HELP_PATTERN, ''));
|
||||
}
|
||||
else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.sharpAsync = sharpAsync;
|
||||
function getOptions(options) {
|
||||
const args = [];
|
||||
for (const [key, value] of Object.entries(options)) {
|
||||
if (value != null && value !== false) {
|
||||
if (typeof value === 'boolean') {
|
||||
args.push(`--${key}`);
|
||||
}
|
||||
else if (typeof value === 'number') {
|
||||
args.push(`--${key}`, value.toFixed());
|
||||
}
|
||||
else {
|
||||
args.push(`--${key}`, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return args;
|
||||
}
|
||||
function getCommandOptions(commands) {
|
||||
const args = [];
|
||||
for (const command of commands) {
|
||||
if (command.operation === 'resize') {
|
||||
const { operation, width } = command, namedOptions = __rest(command, ["operation", "width"]);
|
||||
args.push(operation, width.toFixed(), ...getOptions(namedOptions));
|
||||
}
|
||||
else {
|
||||
const { operation } = command, namedOptions = __rest(command, ["operation"]);
|
||||
args.push(operation, ...getOptions(namedOptions));
|
||||
}
|
||||
args.push('--');
|
||||
}
|
||||
return args;
|
||||
}
|
||||
let _sharpBin = null;
|
||||
let _sharpInstance = null;
|
||||
async function findSharpBinAsync() {
|
||||
if (_sharpBin) {
|
||||
return _sharpBin;
|
||||
}
|
||||
try {
|
||||
const sharpCliPackage = require('sharp-cli/package.json');
|
||||
const libVipsVersion = require('sharp').versions.vips;
|
||||
if (sharpCliPackage &&
|
||||
semver_1.default.satisfies(sharpCliPackage.version, SHARP_REQUIRED_VERSION) &&
|
||||
typeof sharpCliPackage.bin.sharp === 'string' &&
|
||||
typeof libVipsVersion === 'string') {
|
||||
_sharpBin = require.resolve(`sharp-cli/${sharpCliPackage.bin.sharp}`);
|
||||
return _sharpBin;
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
// fall back to global sharp-cli
|
||||
}
|
||||
let installedCliVersion;
|
||||
try {
|
||||
installedCliVersion = (await spawn_async_1.default('sharp', ['--version'])).stdout.toString().trim();
|
||||
}
|
||||
catch (e) {
|
||||
throw notFoundError(SHARP_REQUIRED_VERSION);
|
||||
}
|
||||
if (!semver_1.default.satisfies(installedCliVersion, SHARP_REQUIRED_VERSION)) {
|
||||
showVersionMismatchWarning(SHARP_REQUIRED_VERSION, installedCliVersion);
|
||||
}
|
||||
_sharpBin = 'sharp';
|
||||
return _sharpBin;
|
||||
}
|
||||
/**
|
||||
* Returns the instance of `sharp` installed by the global `sharp-cli` package.
|
||||
* This method will throw errors if the `sharp` instance cannot be found, these errors can be circumvented by ensuring `isAvailableAsync()` resolves to `true`.
|
||||
*/
|
||||
async function findSharpInstanceAsync() {
|
||||
if (isSharpDisabled) {
|
||||
throw new Error('Global instance of sharp-cli cannot be retrieved because sharp-cli has been disabled with the environment variable `EXPO_IMAGE_UTILS_NO_SHARP`');
|
||||
}
|
||||
if (_sharpInstance) {
|
||||
return _sharpInstance;
|
||||
}
|
||||
// Ensure sharp-cli version is correct
|
||||
await findSharpBinAsync();
|
||||
// Attempt to use local sharp package
|
||||
try {
|
||||
const sharp = require('sharp');
|
||||
_sharpInstance = sharp;
|
||||
return sharp;
|
||||
}
|
||||
catch (_a) { }
|
||||
// Attempt to resolve the sharp instance used by the global CLI
|
||||
let sharpCliPath;
|
||||
try {
|
||||
sharpCliPath = (await spawn_async_1.default('which', ['sharp'])).stdout.toString().trim();
|
||||
}
|
||||
catch (e) {
|
||||
throw new Error(`Failed to find the instance of sharp used by the global sharp-cli package.`);
|
||||
}
|
||||
// resolve sharp from the sharp-cli package
|
||||
const sharpPath = resolve_from_1.default.silent(sharpCliPath, 'sharp');
|
||||
if (sharpPath) {
|
||||
try {
|
||||
// attempt to require the global sharp package
|
||||
_sharpInstance = require(sharpPath);
|
||||
}
|
||||
catch (_b) { }
|
||||
}
|
||||
return _sharpInstance;
|
||||
}
|
||||
exports.findSharpInstanceAsync = findSharpInstanceAsync;
|
||||
function notFoundError(requiredCliVersion) {
|
||||
return new Error(`This command requires version ${requiredCliVersion} of \`sharp-cli\`. \n` +
|
||||
`You can install it using \`npm install -g sharp-cli@${requiredCliVersion}\`. \n` +
|
||||
'\n' +
|
||||
'For prerequisites, see: https://sharp.dimens.io/en/stable/install/#prerequisites');
|
||||
}
|
||||
let versionMismatchWarningShown = false;
|
||||
function showVersionMismatchWarning(requiredCliVersion, installedCliVersion) {
|
||||
if (versionMismatchWarningShown) {
|
||||
return;
|
||||
}
|
||||
console.warn(`Warning: This command requires version ${requiredCliVersion} of \`sharp-cli\`. \n` +
|
||||
`Currently installed version: "${installedCliVersion}" \n` +
|
||||
`Required version: "${requiredCliVersion}" \n` +
|
||||
`You can install it using \`npm install -g sharp-cli@${requiredCliVersion}\`. \n` +
|
||||
'\n' +
|
||||
'For prerequisites, see: https://sharp.dimens.io/en/stable/install/#prerequisites');
|
||||
versionMismatchWarningShown = true;
|
||||
}
|
||||
//# sourceMappingURL=sharp.js.map
|
1
node_modules/@expo/image-utils/build/sharp.js.map
generated
vendored
Normal file
1
node_modules/@expo/image-utils/build/sharp.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
35
node_modules/@expo/image-utils/build/sharp.types.d.ts
generated
vendored
Normal file
35
node_modules/@expo/image-utils/build/sharp.types.d.ts
generated
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
import { ImageFormat, ResizeMode } from './Image.types';
|
||||
export declare type SharpGlobalOptions = {
|
||||
compressionLevel?: '';
|
||||
format?: ImageFormat;
|
||||
input: string;
|
||||
limitInputPixels?: number;
|
||||
output: string;
|
||||
progressive?: boolean;
|
||||
quality?: number;
|
||||
withMetadata?: boolean;
|
||||
[key: string]: string | number | boolean | undefined | null;
|
||||
};
|
||||
export declare type SharpCommandOptions = RemoveAlphaOptions | ResizeOptions | FlattenOptions;
|
||||
export declare type FlattenOptions = {
|
||||
operation: 'flatten';
|
||||
background: string;
|
||||
};
|
||||
export declare type RemoveAlphaOptions = {
|
||||
operation: 'removeAlpha';
|
||||
};
|
||||
export declare type Position = 'center' | 'centre' | 'north' | 'east' | 'south' | 'west' | 'northeast' | 'southeast' | 'southwest' | 'northwest' | 'top' | 'right' | 'bottom' | 'left' | 'right top' | 'right bottom' | 'left bottom' | 'left top' | 'entropy' | 'attention';
|
||||
export declare type ResizeOptions = {
|
||||
operation: 'resize';
|
||||
background?: string;
|
||||
fastShrinkOnLoad?: boolean;
|
||||
fit?: ResizeMode;
|
||||
height?: number;
|
||||
kernel?: 'nearest' | 'cubic' | 'mitchell' | 'lanczos2' | 'lanczos3';
|
||||
position?: Position;
|
||||
width: number;
|
||||
withoutEnlargement?: boolean;
|
||||
};
|
||||
export declare type Options = object | {
|
||||
[key: string]: boolean | number | string | undefined;
|
||||
};
|
3
node_modules/@expo/image-utils/build/sharp.types.js
generated
vendored
Normal file
3
node_modules/@expo/image-utils/build/sharp.types.js
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=sharp.types.js.map
|
1
node_modules/@expo/image-utils/build/sharp.types.js.map
generated
vendored
Normal file
1
node_modules/@expo/image-utils/build/sharp.types.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"sharp.types.js","sourceRoot":"","sources":["../src/sharp.types.ts"],"names":[],"mappings":"","sourcesContent":["import { ImageFormat, ResizeMode } from './Image.types';\n\nexport type SharpGlobalOptions = {\n compressionLevel?: '';\n format?: ImageFormat;\n input: string;\n limitInputPixels?: number;\n output: string;\n progressive?: boolean;\n quality?: number;\n withMetadata?: boolean;\n [key: string]: string | number | boolean | undefined | null;\n};\n\nexport type SharpCommandOptions = RemoveAlphaOptions | ResizeOptions | FlattenOptions;\n\nexport type FlattenOptions = {\n operation: 'flatten';\n background: string;\n};\n\nexport type RemoveAlphaOptions = {\n operation: 'removeAlpha';\n};\n\nexport type Position =\n | 'center'\n | 'centre'\n | 'north'\n | 'east'\n | 'south'\n | 'west'\n | 'northeast'\n | 'southeast'\n | 'southwest'\n | 'northwest'\n | 'top'\n | 'right'\n | 'bottom'\n | 'left'\n | 'right top'\n | 'right bottom'\n | 'left bottom'\n | 'left top'\n | 'entropy'\n | 'attention';\n\nexport type ResizeOptions = {\n operation: 'resize';\n background?: string;\n fastShrinkOnLoad?: boolean;\n fit?: ResizeMode;\n height?: number;\n kernel?: 'nearest' | 'cubic' | 'mitchell' | 'lanczos2' | 'lanczos3';\n position?: Position;\n width: number;\n withoutEnlargement?: boolean;\n};\n\nexport type Options =\n | object\n | {\n [key: string]: boolean | number | string | undefined;\n };\n"]}
|
Reference in New Issue
Block a user