one
Version:
One is a React framework for web, iOS, and Android apps.
197 lines (194 loc) • 8.43 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 mapValidation_exports = {};
__export(mapValidation_exports, { resolveNativeMapModel: () => resolveNativeMapModel });
module.exports = __toCommonJS(mapValidation_exports);
var defaultCamera = {
coordinates: {
latitude: 37.7749,
longitude: -122.4194
},
zoom: 12
};
var hexColor = /^#[0-9a-f]{6}([0-9a-f]{2})?$/i;
function coordinates(value, what) {
if (!value || !Number.isFinite(value.latitude) || value.latitude < -90 || value.latitude > 90 || !Number.isFinite(value.longitude) || value.longitude < -180 || value.longitude > 180) throw new Error(`One.UI.Map ${what} must be a latitude from -90 to 90 and a longitude from -180 to 180`);
return value;
}
function color(value, what) {
if (value === void 0) return "";
if (typeof value !== "string" || !hexColor.test(value)) throw new Error(`One.UI.Map ${what} must be a #rrggbb or #rrggbbaa string`);
return value;
}
function width(value, what) {
if (value === void 0) return 0;
if (!Number.isFinite(value) || value < 0) throw new Error(`One.UI.Map ${what} must be a finite number at or above 0`);
return value;
}
function uniqueIds(ids, what) {
if (new Set(ids).size !== ids.length) throw new Error(`One.UI.Map ${what} ids must be unique`);
}
function markers(value) {
var list = value !== null && value !== void 0 ? value : [];
if (!Array.isArray(list)) throw new Error("One.UI.Map markers must be an array");
uniqueIds(list.map(function(marker) {
return marker === null || marker === void 0 ? void 0 : marker.id;
}), "marker");
return list.map(function(marker) {
var _marker_title;
if (typeof (marker === null || marker === void 0 ? void 0 : marker.id) !== "string") throw new Error("One.UI.Map markers must contain a string id");
var point = coordinates(marker.coordinates, `marker "${marker.id}" coordinates`);
if (marker.title !== void 0 && typeof marker.title !== "string") throw new Error(`One.UI.Map marker "${marker.id}" title must be a string`);
return {
id: marker.id,
title: (_marker_title = marker.title) !== null && _marker_title !== void 0 ? _marker_title : "",
latitude: point.latitude,
longitude: point.longitude,
tint: color(marker.tintColor, `marker "${marker.id}" tintColor`)
};
});
}
function overlayPoints(value, what) {
if (!Array.isArray(value) || value.length === 0) throw new Error(`One.UI.Map ${what} coordinates must be a non-empty array`);
return value.map(function(point, index) {
return coordinates(point, `${what} coordinates[${index}]`);
});
}
function resolveNativeMapModel(input) {
var _input_cameraPosition, _input_polylines, _input_polygons, _input_circles;
var camera = (_input_cameraPosition = input.cameraPosition) !== null && _input_cameraPosition !== void 0 ? _input_cameraPosition : defaultCamera;
var center = coordinates(camera.coordinates, "cameraPosition coordinates");
if (!camera || !Number.isFinite(camera.zoom)) throw new Error("One.UI.Map cameraPosition zoom must be a finite number");
var resolvedMarkers = markers(input.markers);
var polylines = (_input_polylines = input.polylines) !== null && _input_polylines !== void 0 ? _input_polylines : [];
var polygons = (_input_polygons = input.polygons) !== null && _input_polygons !== void 0 ? _input_polygons : [];
var circles = (_input_circles = input.circles) !== null && _input_circles !== void 0 ? _input_circles : [];
if (!Array.isArray(polylines)) throw new Error("One.UI.Map polylines must be an array");
if (!Array.isArray(polygons)) throw new Error("One.UI.Map polygons must be an array");
if (!Array.isArray(circles)) throw new Error("One.UI.Map circles must be an array");
uniqueIds(polylines.map(function(line2) {
return line2 === null || line2 === void 0 ? void 0 : line2.id;
}), "polyline");
uniqueIds(polygons.map(function(polygon2) {
return polygon2 === null || polygon2 === void 0 ? void 0 : polygon2.id;
}), "polygon");
uniqueIds(circles.map(function(circle2) {
return circle2 === null || circle2 === void 0 ? void 0 : circle2.id;
}), "circle");
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
try {
for (var _iterator = polylines[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var line = _step.value;
if (typeof (line === null || line === void 0 ? void 0 : line.id) !== "string") throw new Error("One.UI.Map polylines must contain a string id");
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
try {
for (var _iterator1 = polygons[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
var polygon = _step1.value;
if (typeof (polygon === null || polygon === void 0 ? void 0 : polygon.id) !== "string") throw new Error("One.UI.Map polygons must contain a string id");
}
} catch (err) {
_didIteratorError1 = true;
_iteratorError1 = err;
} finally {
try {
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
_iterator1.return();
}
} finally {
if (_didIteratorError1) {
throw _iteratorError1;
}
}
}
var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = void 0;
try {
for (var _iterator2 = circles[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var circle = _step2.value;
if (typeof (circle === null || circle === void 0 ? void 0 : circle.id) !== "string") throw new Error("One.UI.Map circles must contain a string id");
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
return {
latitude: center.latitude,
longitude: center.longitude,
zoom: camera.zoom,
markers: resolvedMarkers,
overlays: JSON.stringify({
polylines: polylines.map(function(line2) {
return {
id: line2.id,
coordinates: overlayPoints(line2.coordinates, `polyline "${line2.id}"`),
color: color(line2.color, `polyline "${line2.id}" color`),
width: width(line2.width, `polyline "${line2.id}" width`)
};
}),
polygons: polygons.map(function(polygon2) {
return {
id: polygon2.id,
coordinates: overlayPoints(polygon2.coordinates, `polygon "${polygon2.id}"`),
color: color(polygon2.color, `polygon "${polygon2.id}" color`),
lineColor: color(polygon2.lineColor, `polygon "${polygon2.id}" lineColor`),
lineWidth: width(polygon2.lineWidth, `polygon "${polygon2.id}" lineWidth`)
};
}),
circles: circles.map(function(circle2) {
if (!Number.isFinite(circle2.radius) || circle2.radius <= 0) throw new Error(`One.UI.Map circle "${circle2.id}" radius must be a positive number of metres`);
return {
id: circle2.id,
center: coordinates(circle2.center, `circle "${circle2.id}" center`),
radius: circle2.radius,
color: color(circle2.color, `circle "${circle2.id}" color`),
lineColor: color(circle2.lineColor, `circle "${circle2.id}" lineColor`),
lineWidth: width(circle2.lineWidth, `circle "${circle2.id}" lineWidth`)
};
})
})
};
}
//# sourceMappingURL=mapValidation.native.js.map