1
0
Fork 0
freesewing/packages/albert/src/index.js

74 lines
2.7 KiB
JavaScript
Raw Normal View History

2020-09-25 15:47:28 -07:00
import freesewing from '@freesewing/core'
import plugins from '@freesewing/plugin-bundle'
import config from '../config'
import draftFront from './front'
import draftStrap from './strap'
import draftPocket from './pocket'
2020-09-26 17:11:31 -07:00
const crossBox = {
//name,
//version,
macros: {
crossBox: function (so) {
let id = this.getId()
let shiftFraction = 0.1
this.points[id + '_boxTopLeft'] = so.from.copy()
this.points[id + '_boxBottomRight'] = so.to.copy()
this.points[id + '_boxTopRight'] = new this.Point(so.to.x, so.from.y)
this.points[id + '_boxBottomLeft'] = new this.Point(so.from.x, so.to.y)
this.points[id + '_topCrossTL'] = this.points[id + '_boxTopLeft'].shiftFractionTowards(
this.points[id + '_boxBottomRight'],
shiftFraction
)
this.points[id + '_topCrossTR'] = this.points[id + '_boxTopRight'].shiftFractionTowards(
this.points[id + '_boxBottomLeft'],
shiftFraction
)
this.points[id + '_topCrossBL'] = this.points[id + '_boxBottomLeft'].shiftFractionTowards(
this.points[id + '_boxTopRight'],
shiftFraction
)
this.points[id + '_topCrossBR'] = this.points[id + '_boxBottomRight'].shiftFractionTowards(
this.points[id + '_boxTopLeft'],
shiftFraction
)
this.paths[id + 'crossBox'] = new this.Path()
.move(this.points[id + '_boxTopLeft'])
.line(this.points[id + '_boxTopRight'])
.line(this.points[id + '_boxBottomRight'])
.line(this.points[id + '_boxBottomLeft'])
.line(this.points[id + '_boxTopLeft'])
.close()
.attr('class', 'lining dotted stroke-sm')
this.paths[id + '_topCross'] = new this.Path()
.move(this.points[id + '_topCrossTL'])
.line(this.points[id + '_topCrossBR'])
.line(this.points[id + '_topCrossTR'])
.line(this.points[id + '_topCrossBL'])
.line(this.points[id + '_topCrossTL'])
.line(this.points[id + '_topCrossTR'])
.move(this.points[id + '_topCrossBR'])
.line(this.points[id + '_topCrossBL'])
.attr('class', 'lining dotted stroke-sm')
if (typeof so.text === 'string') {
this.points.textAnchor = this.points[id + '_boxTopLeft']
.shiftFractionTowards(this.points[id + '_boxBottomRight'], 0.5)
.attr('data-text', so.text)
.attr('data-text-class', 'center')
}
2021-04-24 10:16:31 +02:00
},
},
2020-09-26 17:11:31 -07:00
}
2020-09-25 15:47:28 -07:00
// Create new design
2020-09-26 17:11:31 -07:00
const Pattern = new freesewing.Design(config, [plugins, crossBox])
2020-09-25 15:47:28 -07:00
// Attach the draft methods to the prototype
Pattern.prototype.draftFront = draftFront
Pattern.prototype.draftStrap = draftStrap
Pattern.prototype.draftPocket = draftPocket
export default Pattern