1
0
Fork 0
freesewing/plugins/plugin-grainline/src/index.js

49 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-08-03 15:03:33 +02:00
import markers from './markers'
import pkg from '../package.json'
2018-08-10 18:42:20 +02:00
const dflts = {
2022-01-19 16:23:40 +01:00
text: 'grainline',
}
2018-08-10 18:42:20 +02:00
export default {
name: pkg.name,
version: pkg.version,
2018-08-10 18:42:20 +02:00
hooks: {
preRender: (svg) => {
2019-08-03 15:03:33 +02:00
if (svg.attributes.get('freesewing:plugin-grainline') === false) {
svg.attributes.set('freesewing:plugin-grainline', pkg.version)
2019-08-03 15:03:33 +02:00
svg.defs += markers
}
2021-04-24 10:16:31 +02:00
},
2018-08-10 18:42:20 +02:00
},
macros: {
2022-01-19 16:23:40 +01:00
grainline: function (so = {}) {
if (so === false) {
2019-08-03 15:03:33 +02:00
delete this.points.grainlineFrom
delete this.points.grainlineTo
delete this.paths.grainline
this.setGrain(90) // Restoring default
2019-08-03 15:03:33 +02:00
return true
}
so = {
...dflts,
2022-01-19 16:23:40 +01:00
...so,
}
const { points, complete } = this.shorthand()
this.setGrain(so.from.angle(so.to))
if (complete) {
points.grainlineFrom = so.from.shiftFractionTowards(so.to, 0.05)
points.grainlineTo = so.to.shiftFractionTowards(so.from, 0.05)
this.paths.grainline = new this.Path()
.move(points.grainlineFrom)
.line(points.grainlineTo)
.attr('class', 'note')
.attr('marker-start', 'url(#grainlineFrom)')
.attr('marker-end', 'url(#grainlineTo)')
.attr('data-text', so.text)
.attr('data-text-class', 'center fill-note')
}
2021-04-24 10:16:31 +02:00
},
},
2019-08-03 15:03:33 +02:00
}