2019-08-03 15:03:33 +02:00
|
|
|
import markers from './markers'
|
2022-01-25 09:27:00 +01:00
|
|
|
import pkg from '../package.json'
|
2018-08-10 18:42:20 +02:00
|
|
|
|
2022-01-18 09:17:26 +01:00
|
|
|
const dflts = {
|
2022-01-19 16:23:40 +01:00
|
|
|
text: 'grainline',
|
2022-01-18 09:17:26 +01:00
|
|
|
}
|
|
|
|
|
2018-08-10 18:42:20 +02:00
|
|
|
export default {
|
2022-01-25 09:27:00 +01:00
|
|
|
name: pkg.name,
|
|
|
|
version: pkg.version,
|
2018-08-10 18:42:20 +02:00
|
|
|
hooks: {
|
2021-11-27 16:44:01 +01:00
|
|
|
preRender: (svg) => {
|
2019-08-03 15:03:33 +02:00
|
|
|
if (svg.attributes.get('freesewing:plugin-grainline') === false) {
|
2022-01-25 09:27:00 +01:00
|
|
|
svg.attributes.set('freesewing:plugin-grainline', pkg.version)
|
2019-08-03 15:03:33 +02:00
|
|
|
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: {
|
2022-01-19 16:23:40 +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
|
2022-07-31 12:10:02 +02:00
|
|
|
this.setGrain(90) // Restoring default
|
2019-08-03 15:03:33 +02:00
|
|
|
return true
|
2019-07-16 16:18:39 +02:00
|
|
|
}
|
2022-01-18 09:17:26 +01:00
|
|
|
so = {
|
|
|
|
...dflts,
|
2022-01-19 16:23:40 +01:00
|
|
|
...so,
|
2022-01-18 09:17:26 +01:00
|
|
|
}
|
2019-08-03 15:03:33 +02:00
|
|
|
let points = this.points
|
2022-07-31 12:10:02 +02:00
|
|
|
this.setGrain(so.from.angle(so.to))
|
2019-08-03 15:03:33 +02:00
|
|
|
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)')
|
2022-01-18 09:17:26 +01:00
|
|
|
.attr('data-text', so.text)
|
2019-08-03 15:03:33 +02:00
|
|
|
.attr('data-text-class', 'center fill-note')
|
2021-04-24 10:16:31 +02:00
|
|
|
},
|
|
|
|
},
|
2019-08-03 15:03:33 +02:00
|
|
|
}
|