one
Version:
One is a React framework for web, iOS, and Android apps.
94 lines (92 loc) • 4.24 kB
JavaScript
function resolveMediaTypes(mediaTypes, verb) {
var list = Array.isArray(mediaTypes) ? mediaTypes : [mediaTypes !== null && mediaTypes !== void 0 ? mediaTypes : "images"];
if (list.length === 0) {
throw new Error(`ImagePicker.${verb}: mediaTypes must list at least one media type`);
}
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
try {
for (var _iterator = list[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var mediaType = _step.value;
if (mediaType !== "images" && mediaType !== "videos") {
throw new Error(`ImagePicker.${verb}: mediaTypes must be 'images' or 'videos', got '${String(mediaType)}'`);
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return [...new Set(list)];
}
function resolveSelectionLimit(selectionLimit, verb) {
var limit = selectionLimit !== null && selectionLimit !== void 0 ? 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() {
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, verb = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "launchLibrary";
var _options_allowsEditing, _options_quality, _options_videoMaxDuration, _options_videoQuality;
var mediaTypes = resolveMediaTypes(options.mediaTypes, verb);
var selectionLimit = resolveSelectionLimit(options.selectionLimit, verb);
var allowsEditing = (_options_allowsEditing = options.allowsEditing) !== null && _options_allowsEditing !== void 0 ? _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'`);
}
}
var aspect;
if (options.aspect !== void 0) {
var [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
};
}
var quality = (_options_quality = options.quality) !== null && _options_quality !== void 0 ? _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`);
}
var videoMaxDuration = (_options_videoMaxDuration = options.videoMaxDuration) !== null && _options_videoMaxDuration !== void 0 ? _options_videoMaxDuration : 0;
if (typeof videoMaxDuration !== "number" || Number.isNaN(videoMaxDuration) || videoMaxDuration < 0) {
throw new Error(`ImagePicker.${verb}: videoMaxDuration must be a nonnegative number`);
}
var videoQuality = (_options_videoQuality = options.videoQuality) !== null && _options_videoQuality !== void 0 ? _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() {
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
return resolveImagePickerOptions(options, "launchCamera");
}
export { resolveCameraOptions, resolveImagePickerOptions };
//# sourceMappingURL=options.native.js.map