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

37 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-08-03 15:03:33 +02:00
import markers from './markers'
import { version, name } from '../package.json'
2018-08-10 18:42:20 +02:00
export default {
name: name,
version: version,
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', version)
svg.defs += markers
}
2021-04-24 10:16:31 +02:00
},
2018-08-10 18:42:20 +02:00
},
macros: {
2021-01-31 09:22:15 +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
return true
}
2019-08-03 15:03:33 +02:00
let points = this.points
points.grainlineFrom = so.from.shiftFractionTowards(so.to, 0.05)
points.grainlineTo = so.to.shiftFractionTowards(so.from, 0.05)
2018-08-10 18:42:20 +02:00
this.paths.grainline = new this.Path()
.move(points.grainlineFrom)
.line(points.grainlineTo)
2019-08-03 15:03:33 +02:00
.attr('class', 'note')
.attr('marker-start', 'url(#grainlineFrom)')
.attr('marker-end', 'url(#grainlineTo)')
.attr('data-text', 'grainline')
.attr('data-text-class', 'center fill-note')
2021-04-24 10:16:31 +02:00
},
},
2019-08-03 15:03:33 +02:00
}