import { name, version } from '../data.mjs' const markers = ` ` const dflts = { text: 'grainline' } export const grainline = { name, version, hooks: { preRender: (svg) => { if (svg.defs.indexOf(markers) === -1) svg.defs += markers }, }, macros: { grainline: function (so = {}, { points, paths, Path, complete, setGrain }) { if (so === false) { delete points.grainlineFrom delete points.grainlineTo delete paths.grainline setGrain(90) // Restoring default return true } so = { ...dflts, ...so, } // setGrain relies on plugin-cutlist if (typeof setGrain === 'function') { 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) 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') } }, }, } // More specifically named exports export const grainlinePlugin = grainline export const pluginGrainline = grainline