UNPKG

one

Version:

One is a React framework for web, iOS, and Android apps.

74 lines (72 loc) • 2.95 kB
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"); } export { resolveCameraOptions, resolveImagePickerOptions }; //# sourceMappingURL=options.mjs.map