48 lines
1.3 KiB
JavaScript
48 lines
1.3 KiB
JavaScript
/**
|
|
* interact.js 1.10.27
|
|
*
|
|
* Copyright (c) 2012-present Taye Adeyemi <dev@taye.me>
|
|
* Released under the MIT License.
|
|
* https://raw.github.com/taye/interact.js/main/LICENSE
|
|
*/
|
|
|
|
var grid = grid => {
|
|
const coordFields = [['x', 'y'], ['left', 'top'], ['right', 'bottom'], ['width', 'height']].filter(_ref => {
|
|
let [xField, yField] = _ref;
|
|
return xField in grid || yField in grid;
|
|
});
|
|
const gridFunc = (x, y) => {
|
|
const {
|
|
range,
|
|
limits = {
|
|
left: -Infinity,
|
|
right: Infinity,
|
|
top: -Infinity,
|
|
bottom: Infinity
|
|
},
|
|
offset = {
|
|
x: 0,
|
|
y: 0
|
|
}
|
|
} = grid;
|
|
const result = {
|
|
range,
|
|
grid,
|
|
x: null,
|
|
y: null
|
|
};
|
|
for (const [xField, yField] of coordFields) {
|
|
const gridx = Math.round((x - offset.x) / grid[xField]);
|
|
const gridy = Math.round((y - offset.y) / grid[yField]);
|
|
result[xField] = Math.max(limits.left, Math.min(limits.right, gridx * grid[xField] + offset.x));
|
|
result[yField] = Math.max(limits.top, Math.min(limits.bottom, gridy * grid[yField] + offset.y));
|
|
}
|
|
return result;
|
|
};
|
|
gridFunc.grid = grid;
|
|
gridFunc.coordFields = coordFields;
|
|
return gridFunc;
|
|
};
|
|
export { grid as default };
|
|
//# sourceMappingURL=grid.js.map
|