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: {
|
2021-11-21 17:43:13 +01:00
|
|
|
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
|
2018-12-08 17:51:54 +01:00
|
|
|
}
|
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) {
|
2019-07-16 16:18:39 +02:00
|
|
|
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-07-16 16:18:39 +02:00
|
|
|
}
|
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
|
|
|
}
|