2023-02-20 22:58:05 +00:00
|
|
|
const markers = `
|
|
|
|
<marker orient="auto" refY="4.0" refX="10.0" id="grainlineFrom" style="overflow:visible;" markerWidth="12" markerHeight="8">
|
|
|
|
<path class="note fill-note" d="M 0,4 L 12,0 C 10,2 10,6 12,8 z" />
|
|
|
|
</marker>
|
|
|
|
<marker orient="auto" refY="4.0" refX="2.0" id="grainlineTo" style="overflow:visible;" markerWidth="12" markerHeight="8">
|
|
|
|
<path class="note fill-note" d="M 12,4 L 0,0 C 2,2 2,6 0,8 z" />
|
|
|
|
</marker>`
|
|
|
|
|
|
|
|
const dflts = { text: 'grainline' }
|
|
|
|
|
2023-03-11 19:01:40 +01:00
|
|
|
// Export hooks and macros
|
|
|
|
export const grainlineHooks = {
|
|
|
|
preRender: [
|
|
|
|
function (svg) {
|
2023-02-20 22:58:05 +00:00
|
|
|
if (svg.defs.indexOf(markers) === -1) svg.defs += markers
|
|
|
|
},
|
2023-03-11 19:01:40 +01:00
|
|
|
],
|
|
|
|
}
|
|
|
|
export const grainlineMacros = {
|
2023-04-15 14:40:51 -04:00
|
|
|
grainline: function (so = {}, { points, paths, Path, complete, store }) {
|
2023-03-11 19:01:40 +01:00
|
|
|
if (so === false) {
|
|
|
|
delete points.grainlineFrom
|
|
|
|
delete points.grainlineTo
|
|
|
|
delete paths.grainline
|
2023-04-15 14:40:51 -04:00
|
|
|
if (store.cutlist?.setGrain) store.cutlist.setGrain(90) // Restoring default
|
2023-03-11 19:01:40 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
so = {
|
|
|
|
...dflts,
|
|
|
|
...so,
|
|
|
|
}
|
|
|
|
// setGrain relies on plugin-cutlist
|
2023-04-15 14:40:51 -04:00
|
|
|
if (typeof store.cutlist?.setGrain === 'function') {
|
|
|
|
store.cutlist.setGrain(so.from.angle(so.to))
|
2023-03-11 19:01:40 +01:00
|
|
|
}
|
|
|
|
if (complete) {
|
|
|
|
points.grainlineFrom = so.from.shiftFractionTowards(so.to, 0.05)
|
|
|
|
points.grainlineTo = so.to.shiftFractionTowards(so.from, 0.05)
|
|
|
|
paths.grainline = new 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')
|
|
|
|
}
|
2023-02-20 22:58:05 +00:00
|
|
|
},
|
|
|
|
}
|