one
Version:
One is a React framework for web, iOS, and Android apps.
97 lines (96 loc) • 3.84 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all) __defProp(target, name, {
get: all[name],
enumerable: true
});
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: () => from[key],
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var options_exports = {};
__export(options_exports, {
resolveCameraOptions: () => resolveCameraOptions,
resolveImagePickerOptions: () => resolveImagePickerOptions
});
module.exports = __toCommonJS(options_exports);
function resolveMediaTypes(mediaTypes, verb) {
const list = Array.isArray(mediaTypes) ? mediaTypes : [mediaTypes ?? "images"];
if (list.length === 0) {
throw new Error(`ImagePicker.${verb}: mediaTypes must list at least one media type`);
}
for (const mediaType of list) {
if (mediaType !== "images" && mediaType !== "videos") {
throw new Error(`ImagePicker.${verb}: mediaTypes must be 'images' or 'videos', got '${String(mediaType)}'`);
}
}
return [...new Set(list)];
}
function resolveSelectionLimit(selectionLimit, verb) {
const limit = selectionLimit ?? 1;
if (!Number.isInteger(limit) || limit < 0) {
throw new Error(`ImagePicker.${verb}: selectionLimit must be a nonnegative integer, got '${String(selectionLimit)}'`);
}
return limit;
}
function resolveImagePickerOptions(options = {}, verb = "launchLibrary") {
const mediaTypes = resolveMediaTypes(options.mediaTypes, verb);
const selectionLimit = resolveSelectionLimit(options.selectionLimit, verb);
const allowsEditing = options.allowsEditing ?? false;
if (typeof allowsEditing !== "boolean") {
throw new Error(`ImagePicker.${verb}: allowsEditing must be a boolean`);
}
if (allowsEditing) {
if (selectionLimit !== 1) {
throw new Error(`ImagePicker.${verb}: allowsEditing needs a single pick: set selectionLimit to 1`);
}
if (mediaTypes.length !== 1 || mediaTypes[0] !== "images") {
throw new Error(`ImagePicker.${verb}: allowsEditing only supports images: set mediaTypes to 'images'`);
}
}
let aspect;
if (options.aspect !== void 0) {
const [x, y] = options.aspect;
if (!Array.isArray(options.aspect) || options.aspect.length !== 2 || typeof x !== "number" || typeof y !== "number" || !Number.isFinite(x) || !Number.isFinite(y) || x <= 0 || y <= 0) {
throw new Error(`ImagePicker.${verb}: aspect must be [x, y] of positive numbers`);
}
aspect = {
x,
y
};
}
const quality = options.quality ?? 1;
if (typeof quality !== "number" || Number.isNaN(quality) || quality < 0 || quality > 1) {
throw new Error(`ImagePicker.${verb}: quality must be a number from 0 to 1`);
}
const videoMaxDuration = options.videoMaxDuration ?? 0;
if (typeof videoMaxDuration !== "number" || Number.isNaN(videoMaxDuration) || videoMaxDuration < 0) {
throw new Error(`ImagePicker.${verb}: videoMaxDuration must be a nonnegative number`);
}
const videoQuality = options.videoQuality ?? "high";
if (videoQuality !== "high" && videoQuality !== "medium" && videoQuality !== "low") {
throw new Error(`ImagePicker.${verb}: videoQuality must be 'high', 'medium' or 'low', got '${String(options.videoQuality)}'`);
}
return {
mediaTypes,
selectionLimit,
allowsEditing,
aspect,
quality,
videoMaxDuration,
videoQuality
};
}
function resolveCameraOptions(options = {}) {
return resolveImagePickerOptions(options, "launchCamera");
}