@vimeo/iris
Version:
Vimeo Design System
108 lines (104 loc) • 2.94 kB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function coordinates(attach, anchorToWindow) {
if (typeof attach === 'string' && !anchorToWindow) {
switch (attach) {
case 'top':
return [
[],
[],
];
case 'topRight':
return [
[],
[],
];
case 'right':
return [
[],
[],
];
case 'bottomRight':
return [
[],
[],
];
case 'bottom':
return [
[],
[],
];
case 'bottomLeft':
return [
[],
[],
];
case 'left':
return [
[],
[],
];
case 'topLeft':
return [
[],
[],
];
}
}
if (typeof attach === 'string' && anchorToWindow) {
switch (attach) {
case 'top':
return [
[],
[],
];
case 'topRight':
return [
[],
[],
];
case 'right':
return [
[],
[],
];
case 'bottomRight':
return [
[],
[],
];
case 'bottom':
return [
[],
[],
];
case 'bottomLeft':
return [
[],
[],
];
case 'left':
return [
[],
[],
];
case 'topLeft':
return [
[],
[],
];
}
}
if (attach && invalidCoords(attach)) {
console.error("Invalid coordinates: ".concat(attach, ". Values must be 0 - 100."));
return attach.map(limitCoords);
}
return attach;
}
var invalidCoords = function (attach) {
return attach.flatMap(function (a) { return a; }).some(function (a) { return a < 0 || a > 100; });
};
var limitCoords = function (coords) {
return coords.map(function (a) { return Math.min(100, Math.max(0, a)); });
};
exports.coordinates = coordinates;