2023-03-14 13:18:55 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2019-12-17 19:27:28 +00:00
|
|
|
import { helper } from '@ember/component/helper';
|
|
|
|
// arguments should be a list of {x: numLike, y: numLike} points
|
|
|
|
// numLike meaning they should be numbers (or numberlike strings i.e. "1" vs 1)
|
2022-09-15 08:43:17 +00:00
|
|
|
const curve = function () {
|
2019-12-17 19:27:28 +00:00
|
|
|
const args = [...arguments];
|
|
|
|
// our arguments are destination first control points last
|
|
|
|
// SVGs are control points first destination last
|
|
|
|
// we 'shift,push' to turn that around and then map
|
|
|
|
// through the values to convert it to 'x y, x y' etc
|
|
|
|
// whether the curve is cubic-bezier (C) or quadratic-bezier (Q)
|
|
|
|
// then depends on the amount of control points
|
|
|
|
// `Q|C x y, x y, x y` etc
|
|
|
|
return `${arguments.length > 2 ? `C` : `Q`} ${args
|
|
|
|
.concat(args.shift())
|
2022-09-15 08:43:17 +00:00
|
|
|
.map((p) => Object.values(p).join(' '))
|
2019-12-17 19:27:28 +00:00
|
|
|
.join(',')}`;
|
|
|
|
};
|
2022-09-15 08:43:17 +00:00
|
|
|
const move = function (d) {
|
2019-12-17 19:27:28 +00:00
|
|
|
return `
|
|
|
|
M ${d.x} ${d.y}
|
|
|
|
`;
|
|
|
|
};
|
|
|
|
|
2022-09-15 08:43:17 +00:00
|
|
|
export default helper(function ([dest], hash) {
|
2019-12-17 19:27:28 +00:00
|
|
|
const src = hash.src || { x: 0, y: 0 };
|
|
|
|
const type = hash.type || 'cubic';
|
|
|
|
let args = [
|
|
|
|
dest,
|
|
|
|
{
|
|
|
|
x: (src.x + dest.x) / 2,
|
|
|
|
y: src.y,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
if (type === 'cubic') {
|
|
|
|
args.push({
|
|
|
|
x: args[1].x,
|
|
|
|
y: dest.y,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return `${move(src)}${curve(...args)}`;
|
|
|
|
});
|