1
0
Fork 0

chore(plugin-annotations): Refactor plugin structure

This commit is contained in:
joostdecock 2023-03-11 19:01:40 +01:00
parent 607bc010da
commit 94d8ae4cab
11 changed files with 611 additions and 706 deletions

View file

@ -1,5 +1,3 @@
import { version, name } from '../data.mjs'
// Method that draws the actual bartack // Method that draws the actual bartack
const drawBartack = (pointList, { Path }) => { const drawBartack = (pointList, { Path }) => {
let path = new Path().move(pointList.path1[0]) let path = new Path().move(pointList.path1[0])
@ -102,11 +100,8 @@ function createBartack(so, props) {
return true return true
} }
// The actual plugin // Export macros
export const bartack = { export const bartackMacros = {
name,
version,
macros: {
bartack: function (so, props) { bartack: function (so, props) {
return createBartack(so, props) return createBartack(so, props)
}, },
@ -126,9 +121,4 @@ export const bartack = {
so.to = false so.to = false
return createBartack(so, props) return createBartack(so, props)
}, },
},
} }
// More specifically named exports
export const bartackPlugin = bartack
export const pluginBartack = bartack

View file

@ -1,5 +1,3 @@
import { name, version } from '../data.mjs'
const defs = [ const defs = [
// button // button
` `
@ -65,18 +63,13 @@ const defs = [
</g>`, </g>`,
] ]
export const buttons = { // Export hooks
name, export const buttonsHooks = {
version, preRender: [
hooks: { function (svg) {
preRender: function (svg) {
for (const def of defs) { for (const def of defs) {
if (svg.defs.indexOf(def) === -1) svg.defs += def if (svg.defs.indexOf(def) === -1) svg.defs += def
} }
}, },
}, ],
} }
// More specifically named exports
export const buttonsPlugin = buttons
export const pluginButtons = buttons

View file

@ -1,9 +1,5 @@
import { name, version } from '../data.mjs' // Export macros
export const crossboxMacros = {
export const crossbox = {
name: 'crossbox',
version,
macros: {
crossbox: function (so, { points, Point, paths, Path, getId }) { crossbox: function (so, { points, Point, paths, Path, getId }) {
let id = getId() let id = getId()
let shiftFraction = 0.1 let shiftFraction = 0.1
@ -54,9 +50,4 @@ export const crossbox = {
.attr('data-text-class', 'center') .attr('data-text-class', 'center')
} }
}, },
},
} }
// More specifically named exports
export const crossboxPlugin = crossbox
export const pluginCrossbox = crossbox

View file

@ -1,5 +1,3 @@
import { name, version } from '../data.mjs'
const markers = ` const markers = `
<marker orient="auto" refY="4.0" refX="0.0" id="cutonfoldFrom" style="overflow:visible;" markerWidth="12" markerHeight="8"> <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" /> <path class="note fill-note" d="M 0,4 L 12,0 C 10,2 10,6 12,8 z" />
@ -9,15 +7,16 @@ const markers = `
</marker> </marker>
` `
export const cutonfold = { // Export hooks
name, export const cutonfoldHooks = {
version, preRender: [
hooks: { function (svg) {
preRender: (svg) => {
if (svg.defs.indexOf(markers) === -1) svg.defs += markers if (svg.defs.indexOf(markers) === -1) svg.defs += markers
}, },
}, ],
macros: { }
// Export macros
export const cutonfoldMacros = {
cutonfold: function (so, { points, paths, Path, complete, setCutOnFold, setGrain, scale }) { cutonfold: function (so, { points, paths, Path, complete, setCutOnFold, setGrain, scale }) {
if (so === false) { if (so === false) {
delete points.cutonfoldFrom delete points.cutonfoldFrom
@ -63,9 +62,4 @@ export const cutonfold = {
.attr('data-text-class', 'center fill-note') .attr('data-text-class', 'center fill-note')
} }
}, },
},
} }
// More specifically named exports
export const cutonfoldPlugin = cutonfold
export const pluginCutonfold = cutonfold

View file

@ -1,5 +1,3 @@
import { name, version } from '../data.mjs'
const markers = ` const markers = `
<marker orient="auto" refY="4.0" refX="10.0" id="grainlineFrom" style="overflow:visible;" markerWidth="12" markerHeight="8"> <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" /> <path class="note fill-note" d="M 0,4 L 12,0 C 10,2 10,6 12,8 z" />
@ -10,15 +8,15 @@ const markers = `
const dflts = { text: 'grainline' } const dflts = { text: 'grainline' }
export const grainline = { // Export hooks and macros
name, export const grainlineHooks = {
version, preRender: [
hooks: { function (svg) {
preRender: (svg) => {
if (svg.defs.indexOf(markers) === -1) svg.defs += markers if (svg.defs.indexOf(markers) === -1) svg.defs += markers
}, },
}, ],
macros: { }
export const grainlineMacros = {
grainline: function (so = {}, { points, paths, Path, complete, setGrain }) { grainline: function (so = {}, { points, paths, Path, complete, setGrain }) {
if (so === false) { if (so === false) {
delete points.grainlineFrom delete points.grainlineFrom
@ -48,9 +46,4 @@ export const grainline = {
.attr('data-text-class', 'center fill-note') .attr('data-text-class', 'center fill-note')
} }
}, },
},
} }
// More specifically named exports
export const grainlinePlugin = grainline
export const pluginGrainline = grainline

View file

@ -1,59 +1,41 @@
import { name, version } from '../data.mjs' import { name, version } from '../data.mjs'
// Hooks only
import { bartackPlugin } from './bartack.mjs' import { buttonsHooks } from './buttons.mjs'
import { buttonsPlugin } from './buttons.mjs' import { logoHooks } from './logo.mjs'
import { crossboxPlugin } from './crossbox.mjs' import { notchesHooks } from './notches.mjs'
import { cutonfoldPlugin } from './cutonfold.mjs' // Macros only
import { grainlinePlugin } from './grainline.mjs' import { bartackMacros } from './bartack.mjs'
import { logoPlugin } from './logo.mjs' import { crossboxMacros } from './crossbox.mjs'
import { notchesPlugin } from './notches.mjs' import { scaleboxMacros } from './scalebox.mjs'
import { pleatPlugin } from './pleat.mjs' // Hooks and Macros
import { scaleboxPlugin } from './scalebox.mjs' import { cutonfoldMacros, cutonfoldHooks } from './cutonfold.mjs'
import { sewtogetherPlugin } from './sewtogether.mjs' import { grainlineMacros, grainlineHooks } from './grainline.mjs'
import { pleatMacros, pleatHooks } from './pleat.mjs'
const annotationPlugins = [ import { sewtogetherMacros, sewtogetherHooks } from './sewtogether.mjs'
bartackPlugin,
buttonsPlugin,
crossboxPlugin,
cutonfoldPlugin,
grainlinePlugin,
logoPlugin,
notchesPlugin,
pleatPlugin,
scaleboxPlugin,
sewtogetherPlugin,
]
function annotationHooks() {
const hooks = {}
for (const plugin of annotationPlugins) {
for (const i in plugin.hooks) {
if (typeof hooks[i] === 'undefined') hooks[i] = []
const hook = plugin.hooks[i]
if (typeof hook === 'function') hooks[i].push(hook)
else if (typeof hook === 'object') {
for (let method of hook) hooks[i].push(method)
}
}
}
return hooks
}
function annotationMacros() {
const macros = {}
for (const plugin of annotationPlugins) {
for (const i in plugin.macros) macros[i] = plugin.macros[i]
}
return macros
}
export const plugin = { export const plugin = {
name, name,
version, version,
hooks: annotationHooks(), hooks: {
macros: annotationMacros(), preRender: [
...buttonsHooks.preRender,
...logoHooks.preRender,
...notchesHooks.preRender,
...cutonfoldHooks.preRender,
...grainlineHooks.preRender,
...pleatHooks.preRender,
...sewtogetherHooks.preRender,
],
},
macros: {
...bartackMacros,
...crossboxMacros,
...scaleboxMacros,
...cutonfoldMacros,
...grainlineMacros,
...pleatMacros,
...sewtogetherMacros,
},
} }
export const annotationPlugin = plugin export const annotationPlugin = plugin

File diff suppressed because one or more lines are too long

View file

@ -1,5 +1,3 @@
import { name, version } from '../data.mjs'
const markers = ` const markers = `
<g id="notch"> <g id="notch">
<circle cy="0" cx="0" r="1.4" class="fill-note" /> <circle cy="0" cx="0" r="1.4" class="fill-note" />
@ -10,16 +8,11 @@ const markers = `
<circle cy="0" cx="0" r="2.8" class="note" /> <circle cy="0" cx="0" r="2.8" class="note" />
</g>` </g>`
export const notches = { // Export hooks
name, export const notchesHooks = {
version, preRender: [
hooks: { function (svg) {
preRender: function (svg) {
if (svg.defs.indexOf(`id="notch"`) === -1) svg.defs += markers if (svg.defs.indexOf(`id="notch"`) === -1) svg.defs += markers
}, },
}, ],
} }
// More specifically named exports
export const notchesPlugin = notches
export const pluginNotches = notches

View file

@ -1,20 +1,20 @@
import { name, version } from '../data.mjs'
const markers = ` const markers = `
<marker id="pleatTo" markerWidth="12" markerHeight="8" orient="auto" refY="4" refX="12"> <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" /> <path class="note fill-note" d="M 12,4 L 0,0 C 2,2 2,6 0,8 z" />
</marker> </marker>
` `
export const pleat = { // Export hooks
name, export const pleatHooks = {
version, preRender: [
hooks: { function (svg) {
preRender: (svg) => {
if (svg.defs.indexOf(markers) === -1) svg.defs += markers if (svg.defs.indexOf(markers) === -1) svg.defs += markers
}, },
}, ],
macros: { }
// Export macros
export const pleatMacros = {
pleat: function (so, { points, paths, Path, complete, scale }) { pleat: function (so, { points, paths, Path, complete, scale }) {
if (so === false) { if (so === false) {
delete points.pleatFrom delete points.pleatFrom
@ -68,9 +68,4 @@ export const pleat = {
.attr('marker-end', 'url(#pleatTo)') .attr('marker-end', 'url(#pleatTo)')
} }
}, },
},
} }
// More specifically named exports
export const pleatPlugin = pleat
export const pluginPleat = pleat

View file

@ -1,15 +1,5 @@
import { name, version } from '../data.mjs' // Export macros
export const scaleboxMacros = {
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 scalebox = {
name,
version,
macros: {
scalebox: function (so, { store, points, paths, scale, Point, Path }) { scalebox: function (so, { store, points, paths, scale, Point, Path }) {
// Passing `false` will remove the scalebox // Passing `false` will remove the scalebox
if (so === false) { if (so === false) {
@ -289,9 +279,4 @@ export const scalebox = {
.attr('data-text', `${imperialDisplaySize} x ${imperialDisplaySize}`) .attr('data-text', `${imperialDisplaySize} x ${imperialDisplaySize}`)
.attr('data-text-class', 'text-xs center ') .attr('data-text-class', 'text-xs center ')
}, },
},
} }
// More specifically named exports
export const scaleboxPlugin = scalebox
export const pluginScalebox = scalebox

View file

@ -1,5 +1,3 @@
import { name, version } from '../data.mjs'
const markers = ` const markers = `
<marker id="sewTogetherStart" markerWidth="4" markerHeight="4" orient="auto" refX="0" refY="2"> <marker id="sewTogetherStart" markerWidth="4" markerHeight="4" orient="auto" refX="0" refY="2">
<path class="note stroke-sm" d="M4,4 L0,2 4,0" /> <path class="note stroke-sm" d="M4,4 L0,2 4,0" />
@ -12,15 +10,17 @@ const markers = `
</marker> </marker>
` `
export const sewtogether = { // Export hooks
name, export const sewtogetherHooks = {
version, preRender: [
hooks: { function (svg) {
preRender: (svg) => {
if (svg.defs.indexOf(markers) === -1) svg.defs += markers if (svg.defs.indexOf(markers) === -1) svg.defs += markers
}, },
}, ],
macros: { }
// Export macros
export const sewtogetherMacros = {
sewtogether: function (so, { points, paths, Path, complete, scale, sa }) { sewtogether: function (so, { points, paths, Path, complete, scale, sa }) {
if (so === false) { if (so === false) {
delete points.sewtogetherFrom delete points.sewtogetherFrom
@ -86,9 +86,4 @@ export const sewtogether = {
.attr('data-text-class', 'center fill-note text-xs') .attr('data-text-class', 'center fill-note text-xs')
} }
}, },
},
} }
// More specifically named exports
export const sewtogetherPlugin = sewtogether
export const pluginSewtogether = sewtogether