import markers from "./lib/markers"; import { version, name } from "../package.json"; export default { name: name, version: version, hooks: { preRender: function(svg) { if (svg.attributes.get("freesewing:plugin-cutonfold") === false) { svg.attributes.set("freesewing:plugin-cutonfold", version); svg.defs += markers; } } }, macros: { cutonfold: function(so) { let points = this.points; so = { offset: 50, margin: 5, prefix: "", ...so }; points["cutonfoldFrom" + so.prefix] = so.to.shiftFractionTowards( so.from, so.margin / 100 ); points["cutonfoldTo" + so.prefix] = so.from.shiftFractionTowards( so.to, so.margin / 100 ); points["cutonfoldVia1" + so.prefix] = so.to .shiftTowards(so.from, so.offset) .rotate(-90, points["cutonfoldFrom" + so.prefix]); points["cutonfoldVia2" + so.prefix] = so.from .shiftTowards(so.to, so.offset) .rotate(90, points["cutonfoldTo" + so.prefix]); let text = so.grainline ? "cutOnFoldAndGrainline" : "cutOnFold"; this.paths["cutonfold" + so.prefix] = new this.Path() .move(points["cutonfoldFrom" + so.prefix]) .line(points["cutonfoldVia1" + so.prefix]) .line(points["cutonfoldVia2" + so.prefix]) .line(points["cutonfoldTo" + so.prefix]) .attr("class", "note") .attr("marker-start", "url(#cutonfoldFrom)") .attr("marker-end", "url(#cutonfoldTo)") .attr("data-text", text) .attr("data-text-class", "center fill-note"); } } };