chore(core): Make generatePartTransform a named export
This commit is contained in:
parent
20440b9830
commit
7a33cf1783
3 changed files with 30 additions and 25 deletions
|
@ -18,9 +18,13 @@ export {
|
||||||
Snippet,
|
Snippet,
|
||||||
utils,
|
utils,
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is a helper for configuration files
|
// This is a helper for configuration files
|
||||||
export const pctBasedOn = utils.pctBasedOn
|
export const pctBasedOn = utils.pctBasedOn
|
||||||
|
|
||||||
|
// This is a helper for manual layouts
|
||||||
|
export const generatePartTransform = utils.generatePartTransform
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Default exports will be removed in FreeSewing v3
|
* Default exports will be removed in FreeSewing v3
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -350,33 +350,9 @@ Part.prototype.shorthand = function () {
|
||||||
return shorthand
|
return shorthand
|
||||||
}
|
}
|
||||||
|
|
||||||
/** generate the transform attributes needed for the given part */
|
|
||||||
export const generatePartTransform = (x, y, rotate, flipX, flipY, part) => {
|
|
||||||
const center = {
|
|
||||||
x: part.topLeft.x + (part.bottomRight.x - part.topLeft.x)/2,
|
|
||||||
y: part.topLeft.y + (part.bottomRight.y - part.topLeft.y)/2,
|
|
||||||
}
|
|
||||||
|
|
||||||
const transforms = [`translate(${x},${y})`]
|
|
||||||
if (flipX) transforms.push(
|
|
||||||
'scale(-1, 1)',
|
|
||||||
)
|
|
||||||
if (flipY) transforms.push(
|
|
||||||
'scale(1, -1)',
|
|
||||||
)
|
|
||||||
if (rotate) transforms.push(
|
|
||||||
`rotate(${rotate})`
|
|
||||||
)
|
|
||||||
|
|
||||||
return {
|
|
||||||
transform: transforms.join(' '),
|
|
||||||
'transform-origin': `${center.x} ${center.y}`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Part.prototype.generateTransform = function(transforms) {
|
Part.prototype.generateTransform = function(transforms) {
|
||||||
const {move, rotate, flipX, flipY} = transforms;
|
const {move, rotate, flipX, flipY} = transforms;
|
||||||
const generated = generatePartTransform(move.x, move.y, rotate, flipX, flipY, this);
|
const generated = utils.generatePartTransform(move.x, move.y, rotate, flipX, flipY, this);
|
||||||
|
|
||||||
for (var t in generated) {
|
for (var t in generated) {
|
||||||
this.attr(t, generated[t], true);
|
this.attr(t, generated[t], true);
|
||||||
|
|
|
@ -359,3 +359,28 @@ export function pctBasedOn(measurement) {
|
||||||
fromAbs: (val, { measurements }) => Math.round((10 * val) / measurements[measurement]) / 10,
|
fromAbs: (val, { measurements }) => Math.round((10 * val) / measurements[measurement]) / 10,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Generates the transform attributes needed for a given part */
|
||||||
|
export const generatePartTransform = (x, y, rotate, flipX, flipY, part) => {
|
||||||
|
const center = {
|
||||||
|
x: part.topLeft.x + (part.bottomRight.x - part.topLeft.x)/2,
|
||||||
|
y: part.topLeft.y + (part.bottomRight.y - part.topLeft.y)/2,
|
||||||
|
}
|
||||||
|
|
||||||
|
const transforms = [`translate(${x},${y})`]
|
||||||
|
if (flipX) transforms.push(
|
||||||
|
'scale(-1, 1)',
|
||||||
|
)
|
||||||
|
if (flipY) transforms.push(
|
||||||
|
'scale(1, -1)',
|
||||||
|
)
|
||||||
|
if (rotate) transforms.push(
|
||||||
|
`rotate(${rotate})`
|
||||||
|
)
|
||||||
|
|
||||||
|
return {
|
||||||
|
transform: transforms.join(' '),
|
||||||
|
'transform-origin': `${center.x} ${center.y}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue