chore(plugin-annotations): Refactor plugin structure
This commit is contained in:
parent
607bc010da
commit
94d8ae4cab
11 changed files with 611 additions and 706 deletions
|
@ -1,76 +1,71 @@
|
|||
import { name, version } from '../data.mjs'
|
||||
|
||||
const markers = `
|
||||
<marker id="pleatTo" markerWidth="12" markerHeight="8" orient="auto" refY="4" refX="12">
|
||||
<path class="note fill-note" d="M 12,4 L 0,0 C 2,2 2,6 0,8 z" />
|
||||
</marker>
|
||||
`
|
||||
|
||||
export const pleat = {
|
||||
name,
|
||||
version,
|
||||
hooks: {
|
||||
preRender: (svg) => {
|
||||
// Export hooks
|
||||
export const pleatHooks = {
|
||||
preRender: [
|
||||
function (svg) {
|
||||
if (svg.defs.indexOf(markers) === -1) svg.defs += markers
|
||||
},
|
||||
},
|
||||
macros: {
|
||||
pleat: function (so, { points, paths, Path, complete, scale }) {
|
||||
if (so === false) {
|
||||
delete points.pleatFrom
|
||||
delete points.pleatFromIn
|
||||
delete points.pleatTo
|
||||
delete points.pleatToIn
|
||||
delete paths.pleatTo
|
||||
delete paths.pleatFrom
|
||||
delete paths.pleatArrow
|
||||
return true
|
||||
}
|
||||
so = {
|
||||
margin: 35,
|
||||
prefix: 'pleat',
|
||||
reverse: false,
|
||||
...so,
|
||||
}
|
||||
if (complete) {
|
||||
points[so.prefix + 'From'] = so.from
|
||||
points[so.prefix + 'To'] = so.to
|
||||
points[so.prefix + 'FromIn'] = points[so.prefix + 'From'].shift(
|
||||
so.from.shiftTowards(so.to, 0.1).angle(so.from) + 270,
|
||||
so.margin * scale
|
||||
)
|
||||
points[so.prefix + 'ToIn'] = points[so.prefix + 'To'].shift(
|
||||
so.from.shiftTowards(so.to, 0.1).angle(so.to) + 90,
|
||||
so.margin * scale
|
||||
)
|
||||
paths[so.prefix + 'PleatFrom'] = new Path()
|
||||
.move(points[so.prefix + 'From'])
|
||||
.line(points[so.prefix + 'FromIn'])
|
||||
.attr('class', 'note' + (so.reverse ? ' dashed' : ''))
|
||||
paths[so.prefix + 'PleatTo'] = new Path()
|
||||
.move(points[so.prefix + 'To'])
|
||||
.line(points[so.prefix + 'ToIn'])
|
||||
.attr('class', 'note' + (so.reverse ? '' : ' dashed'))
|
||||
paths[so.prefix + 'PleatArrow'] = new Path()
|
||||
.move(
|
||||
points[so.prefix + (so.reverse ? 'To' : 'From')].shiftFractionTowards(
|
||||
points[so.prefix + (so.reverse ? 'ToIn' : 'FromIn')],
|
||||
0.25
|
||||
)
|
||||
)
|
||||
.line(
|
||||
points[so.prefix + (so.reverse ? 'From' : 'To')].shiftFractionTowards(
|
||||
points[so.prefix + (so.reverse ? 'FromIn' : 'ToIn')],
|
||||
0.25
|
||||
)
|
||||
)
|
||||
.attr('class', 'note')
|
||||
.attr('marker-end', 'url(#pleatTo)')
|
||||
}
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
// More specifically named exports
|
||||
export const pleatPlugin = pleat
|
||||
export const pluginPleat = pleat
|
||||
// Export macros
|
||||
export const pleatMacros = {
|
||||
pleat: function (so, { points, paths, Path, complete, scale }) {
|
||||
if (so === false) {
|
||||
delete points.pleatFrom
|
||||
delete points.pleatFromIn
|
||||
delete points.pleatTo
|
||||
delete points.pleatToIn
|
||||
delete paths.pleatTo
|
||||
delete paths.pleatFrom
|
||||
delete paths.pleatArrow
|
||||
return true
|
||||
}
|
||||
so = {
|
||||
margin: 35,
|
||||
prefix: 'pleat',
|
||||
reverse: false,
|
||||
...so,
|
||||
}
|
||||
if (complete) {
|
||||
points[so.prefix + 'From'] = so.from
|
||||
points[so.prefix + 'To'] = so.to
|
||||
points[so.prefix + 'FromIn'] = points[so.prefix + 'From'].shift(
|
||||
so.from.shiftTowards(so.to, 0.1).angle(so.from) + 270,
|
||||
so.margin * scale
|
||||
)
|
||||
points[so.prefix + 'ToIn'] = points[so.prefix + 'To'].shift(
|
||||
so.from.shiftTowards(so.to, 0.1).angle(so.to) + 90,
|
||||
so.margin * scale
|
||||
)
|
||||
paths[so.prefix + 'PleatFrom'] = new Path()
|
||||
.move(points[so.prefix + 'From'])
|
||||
.line(points[so.prefix + 'FromIn'])
|
||||
.attr('class', 'note' + (so.reverse ? ' dashed' : ''))
|
||||
paths[so.prefix + 'PleatTo'] = new Path()
|
||||
.move(points[so.prefix + 'To'])
|
||||
.line(points[so.prefix + 'ToIn'])
|
||||
.attr('class', 'note' + (so.reverse ? '' : ' dashed'))
|
||||
paths[so.prefix + 'PleatArrow'] = new Path()
|
||||
.move(
|
||||
points[so.prefix + (so.reverse ? 'To' : 'From')].shiftFractionTowards(
|
||||
points[so.prefix + (so.reverse ? 'ToIn' : 'FromIn')],
|
||||
0.25
|
||||
)
|
||||
)
|
||||
.line(
|
||||
points[so.prefix + (so.reverse ? 'From' : 'To')].shiftFractionTowards(
|
||||
points[so.prefix + (so.reverse ? 'FromIn' : 'ToIn')],
|
||||
0.25
|
||||
)
|
||||
)
|
||||
.attr('class', 'note')
|
||||
.attr('marker-end', 'url(#pleatTo)')
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue