2022-08-28 12:26:34 +02:00
|
|
|
import { name, version } from '../package.json' assert { type: 'json' }
|
2018-07-21 16:37:18 +02:00
|
|
|
|
2022-08-28 12:26:34 +02:00
|
|
|
const markers = `
|
|
|
|
<marker orient="auto" refY="4.0" refX="0.0" id="cutonfoldFrom" 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="12.0" id="cutonfoldTo" 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>
|
|
|
|
`
|
|
|
|
|
|
|
|
export const plugin = {
|
|
|
|
name,
|
|
|
|
version,
|
2018-07-21 15:34:46 +02:00
|
|
|
hooks: {
|
2021-11-21 17:27:03 +01:00
|
|
|
preRender: (svg) => {
|
2022-08-28 12:26:34 +02:00
|
|
|
if (svg.defs.indexOf(markers) === -1) svg.defs += markers
|
2021-04-24 10:16:31 +02:00
|
|
|
},
|
2018-07-24 09:10:09 +00:00
|
|
|
},
|
|
|
|
macros: {
|
2021-01-31 09:22:15 +01:00
|
|
|
cutonfold: function (so) {
|
2022-07-31 12:25:06 +02:00
|
|
|
const { points, complete } = this.shorthand()
|
2019-07-16 16:20:16 +02:00
|
|
|
if (so === false) {
|
2019-08-03 15:03:33 +02:00
|
|
|
delete this.points.cutonfoldFrom
|
|
|
|
delete this.points.cutonfoldTo
|
|
|
|
delete this.points.cutonfoldVia1
|
|
|
|
delete this.points.cutonfoldVia2
|
|
|
|
delete this.paths.cutonfold
|
2022-07-31 12:25:06 +02:00
|
|
|
this.setCutOnFold(false) // Restore default
|
2019-08-03 15:03:33 +02:00
|
|
|
return true
|
2019-07-16 16:20:16 +02:00
|
|
|
}
|
2019-02-13 14:18:23 +01:00
|
|
|
so = {
|
2019-09-29 16:58:21 +02:00
|
|
|
offset: 15,
|
2019-02-13 14:49:25 +01:00
|
|
|
margin: 5,
|
2019-08-03 15:03:33 +02:00
|
|
|
prefix: '',
|
2021-04-24 10:16:31 +02:00
|
|
|
...so,
|
2019-08-03 15:03:33 +02:00
|
|
|
}
|
2022-07-31 12:25:06 +02:00
|
|
|
this.setCutOnFold(so.from, so.to)
|
|
|
|
if (so.grainline) this.setGrain(so.from.angle(so.to))
|
|
|
|
if (complete) {
|
|
|
|
points['cutonfoldFrom' + so.prefix] = so.from.shiftFractionTowards(so.to, so.margin / 100)
|
|
|
|
points['cutonfoldTo' + so.prefix] = so.to.shiftFractionTowards(so.from, so.margin / 100)
|
|
|
|
points['cutonfoldVia1' + so.prefix] = points['cutonfoldFrom' + so.prefix]
|
|
|
|
.shiftTowards(so.from, so.offset * this.context.settings.scale)
|
|
|
|
.rotate(-90, points['cutonfoldFrom' + so.prefix])
|
|
|
|
points['cutonfoldVia2' + so.prefix] = points['cutonfoldTo' + so.prefix]
|
|
|
|
.shiftTowards(so.to, so.offset * this.context.settings.scale)
|
|
|
|
.rotate(90, points['cutonfoldTo' + so.prefix])
|
|
|
|
const 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')
|
|
|
|
}
|
2021-04-24 10:16:31 +02:00
|
|
|
},
|
|
|
|
},
|
2019-08-03 15:03:33 +02:00
|
|
|
}
|
2022-08-28 14:42:50 +02:00
|
|
|
|
|
|
|
// More specifically named exports
|
|
|
|
export const cutonfoldPlugin = plugin
|
|
|
|
export const pluginCutonfold = plugin
|
|
|
|
|