@eriese recommendations
This commit is contained in:
parent
9536476512
commit
8887a97dd2
13 changed files with 65 additions and 120 deletions
|
@ -43,7 +43,7 @@ describe('Svg', () => {
|
||||||
expect(svg.freeId).to.equal(0)
|
expect(svg.freeId).to.equal(0)
|
||||||
expect(svg.body).to.equal('')
|
expect(svg.body).to.equal('')
|
||||||
expect(svg.style).to.equal('')
|
expect(svg.style).to.equal('')
|
||||||
expect(svg.defs instanceof Defs).to.equal(true)
|
expect(svg.defs).to.be.an.instanceof(Defs)
|
||||||
expect(svg.prefix).to.equal('<?xml version="1.0" encoding="UTF-8" standalone="no"?>')
|
expect(svg.prefix).to.equal('<?xml version="1.0" encoding="UTF-8" standalone="no"?>')
|
||||||
expect(svg.attributes.get('xmlns')).to.equal('http://www.w3.org/2000/svg')
|
expect(svg.attributes.get('xmlns')).to.equal('http://www.w3.org/2000/svg')
|
||||||
expect(svg.attributes.get('xmlns:svg')).to.equal('http://www.w3.org/2000/svg')
|
expect(svg.attributes.get('xmlns:svg')).to.equal('http://www.w3.org/2000/svg')
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
const defs = [
|
// Export defs
|
||||||
|
export const buttonsDefs = [
|
||||||
{
|
{
|
||||||
name: 'button',
|
name: 'button',
|
||||||
def: `
|
def: `
|
||||||
|
@ -84,14 +85,3 @@ const defs = [
|
||||||
</g>`,
|
</g>`,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
// Export hooks
|
|
||||||
export const buttonsHooks = {
|
|
||||||
preRender: [
|
|
||||||
function (svg) {
|
|
||||||
for (const def of defs) {
|
|
||||||
svg.defs.setIfUnset(def.name, def.def)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
const defs = [
|
// Export defs
|
||||||
|
export const cutonfoldDefs = [
|
||||||
{
|
{
|
||||||
name: 'cutonfoldFrom',
|
name: 'cutonfoldFrom',
|
||||||
def: `
|
def: `
|
||||||
|
@ -15,16 +16,6 @@ const defs = [
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
// Export hooks
|
|
||||||
export const cutonfoldHooks = {
|
|
||||||
preRender: [
|
|
||||||
function (svg) {
|
|
||||||
for (const def of defs) {
|
|
||||||
svg.defs.setIfUnset(def.name, def.def)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
// Export macros
|
// Export macros
|
||||||
export const cutonfoldMacros = {
|
export const cutonfoldMacros = {
|
||||||
cutonfold: function (so, { points, paths, Path, complete, setCutOnFold, setGrain, scale }) {
|
cutonfold: function (so, { points, paths, Path, complete, setCutOnFold, setGrain, scale }) {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
const defs = [
|
// Export defs
|
||||||
|
export const dimensionsDefs = [
|
||||||
{
|
{
|
||||||
name: 'dimensionFrom',
|
name: 'dimensionFrom',
|
||||||
def: `
|
def: `
|
||||||
|
@ -79,16 +80,7 @@ function lleader(so, type, props, id) {
|
||||||
return point
|
return point
|
||||||
}
|
}
|
||||||
|
|
||||||
// Export hooks and macros
|
// Export macros
|
||||||
export const dimensionsHooks = {
|
|
||||||
preRender: [
|
|
||||||
function (svg) {
|
|
||||||
for (const def of defs) {
|
|
||||||
svg.defs.setIfUnset(def.name, def.def)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
export const dimensionsMacros = {
|
export const dimensionsMacros = {
|
||||||
// horizontal
|
// horizontal
|
||||||
hd: function (so, props) {
|
hd: function (so, props) {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
const defs = [
|
// Export defs
|
||||||
|
export const grainlineDefs = [
|
||||||
{
|
{
|
||||||
name: 'grainlineFrom',
|
name: 'grainlineFrom',
|
||||||
def: `
|
def: `
|
||||||
|
@ -17,16 +18,7 @@ const defs = [
|
||||||
|
|
||||||
const dflts = { text: 'grainline' }
|
const dflts = { text: 'grainline' }
|
||||||
|
|
||||||
// Export hooks and macros
|
// Export macros
|
||||||
export const grainlineHooks = {
|
|
||||||
preRender: [
|
|
||||||
function (svg) {
|
|
||||||
for (const def of defs) {
|
|
||||||
svg.defs.setIfUnset(def.name, def.def)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
export const grainlineMacros = {
|
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) {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import { name, version } from '../data.mjs'
|
import { name, version } from '../data.mjs'
|
||||||
// Hooks only
|
// Defs only
|
||||||
import { buttonsHooks } from './buttons.mjs'
|
import { buttonsDefs } from './buttons.mjs'
|
||||||
import { logoHooks } from './logo.mjs'
|
import { logoDefs } from './logo.mjs'
|
||||||
import { notchesHooks } from './notches.mjs'
|
import { notchesDefs } from './notches.mjs'
|
||||||
// Macros only
|
// Macros only
|
||||||
import { bannerMacros } from './banner.mjs'
|
import { bannerMacros } from './banner.mjs'
|
||||||
import { bannerboxMacros } from './bannerbox.mjs'
|
import { bannerboxMacros } from './bannerbox.mjs'
|
||||||
|
@ -10,26 +10,36 @@ import { bartackMacros } from './bartack.mjs'
|
||||||
import { crossboxMacros } from './crossbox.mjs'
|
import { crossboxMacros } from './crossbox.mjs'
|
||||||
import { scaleboxMacros } from './scalebox.mjs'
|
import { scaleboxMacros } from './scalebox.mjs'
|
||||||
import { titleMacros } from './title.mjs'
|
import { titleMacros } from './title.mjs'
|
||||||
// Hooks and Macros
|
// Defs and Macros
|
||||||
import { cutonfoldMacros, cutonfoldHooks } from './cutonfold.mjs'
|
import { cutonfoldMacros, cutonfoldDefs } from './cutonfold.mjs'
|
||||||
import { dimensionsMacros, dimensionsHooks } from './dimensions.mjs'
|
import { dimensionsMacros, dimensionsDefs } from './dimensions.mjs'
|
||||||
import { grainlineMacros, grainlineHooks } from './grainline.mjs'
|
import { grainlineMacros, grainlineDefs } from './grainline.mjs'
|
||||||
import { pleatMacros, pleatHooks } from './pleat.mjs'
|
import { pleatMacros, pleatDefs } from './pleat.mjs'
|
||||||
import { sewtogetherMacros, sewtogetherHooks } from './sewtogether.mjs'
|
import { sewtogetherMacros, sewtogetherDefs } from './sewtogether.mjs'
|
||||||
|
|
||||||
export const plugin = {
|
export const plugin = {
|
||||||
name,
|
name,
|
||||||
version,
|
version,
|
||||||
hooks: {
|
hooks: {
|
||||||
preRender: [
|
preRender: [
|
||||||
...buttonsHooks.preRender,
|
function (svg) {
|
||||||
...logoHooks.preRender,
|
const defs = [
|
||||||
...notchesHooks.preRender,
|
...buttonsDefs,
|
||||||
...cutonfoldHooks.preRender,
|
...cutonfoldDefs,
|
||||||
...dimensionsHooks.preRender,
|
...dimensionsDefs,
|
||||||
...grainlineHooks.preRender,
|
...grainlineDefs,
|
||||||
...pleatHooks.preRender,
|
...logoDefs,
|
||||||
...sewtogetherHooks.preRender,
|
...notchesDefs,
|
||||||
|
...pleatDefs,
|
||||||
|
...sewtogetherDefs,
|
||||||
|
]
|
||||||
|
for (const def of defs) {
|
||||||
|
svg.defs.setIfUnset(
|
||||||
|
def.name,
|
||||||
|
typeof def.def === 'function' ? def.def(svg.pattern.settings[0].scale) : def.def
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
macros: {
|
macros: {
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,4 +1,5 @@
|
||||||
const defs = [
|
// Export hooks
|
||||||
|
export const notchesDefs = [
|
||||||
{
|
{
|
||||||
name: 'notch',
|
name: 'notch',
|
||||||
def: `
|
def: `
|
||||||
|
@ -16,14 +17,3 @@ const defs = [
|
||||||
</g>`,
|
</g>`,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
// Export hooks
|
|
||||||
export const notchesHooks = {
|
|
||||||
preRender: [
|
|
||||||
function (svg) {
|
|
||||||
for (const def of defs) {
|
|
||||||
svg.defs.setIfUnset(def.name, def.def)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,17 +1,14 @@
|
||||||
const markers = `
|
// Export defs
|
||||||
|
export const pleatDefs = [
|
||||||
|
{
|
||||||
|
name: 'notch',
|
||||||
|
def: `
|
||||||
<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 hooks
|
]
|
||||||
export const pleatHooks = {
|
|
||||||
preRender: [
|
|
||||||
function (svg) {
|
|
||||||
svg.defs.setIfUnset('pleatTo', markers)
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
||||||
// Export macros
|
// Export macros
|
||||||
export const pleatMacros = {
|
export const pleatMacros = {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
const defs = [
|
// Export defs
|
||||||
|
export const sewtogetherDefs = [
|
||||||
{
|
{
|
||||||
name: 'sewTogetherStart',
|
name: 'sewTogetherStart',
|
||||||
def: `
|
def: `
|
||||||
|
@ -22,17 +23,6 @@ const defs = [
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
// Export hooks
|
|
||||||
export const sewtogetherHooks = {
|
|
||||||
preRender: [
|
|
||||||
function (svg) {
|
|
||||||
for (const def of defs) {
|
|
||||||
svg.defs.setIfUnset(def.name, def.def)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
||||||
// Export macros
|
// Export macros
|
||||||
export const sewtogetherMacros = {
|
export const sewtogetherMacros = {
|
||||||
sewTogether: function (so, { points, paths, Path, complete, sa }) {
|
sewTogether: function (so, { points, paths, Path, complete, sa }) {
|
||||||
|
|
|
@ -11,7 +11,7 @@ pattern.draft().render()
|
||||||
describe('Buttons Plugin Test', () => {
|
describe('Buttons Plugin Test', () => {
|
||||||
for (const snippet of ['button', 'buttonhole', 'snap-stud', 'snap-socket']) {
|
for (const snippet of ['button', 'buttonhole', 'snap-stud', 'snap-socket']) {
|
||||||
it(`Should add the ${snippet} snippet to defs`, () => {
|
it(`Should add the ${snippet} snippet to defs`, () => {
|
||||||
expect(pattern.svg.defs.render().indexOf(`<g id="${snippet}">`)).to.not.equal(-1)
|
expect(pattern.svg.defs.get(snippet)).to.not.equal(false)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,6 @@ describe('Logo Plugin Tests', () => {
|
||||||
const Pattern = new Design()
|
const Pattern = new Design()
|
||||||
const pattern = new Pattern().use(annotationsPlugin)
|
const pattern = new Pattern().use(annotationsPlugin)
|
||||||
pattern.draft().render()
|
pattern.draft().render()
|
||||||
expect(pattern.svg.defs.render()).to.contain(
|
expect(pattern.svg.defs.get('logo')).to.not.equal(false)
|
||||||
'<g id="logo" transform="scale(1) translate(-23 -36)"><path class="logo"'
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -16,14 +16,12 @@ const pattern = new Pattern()
|
||||||
pattern.draft().render()
|
pattern.draft().render()
|
||||||
|
|
||||||
describe('Notches Plugin Test', () => {
|
describe('Notches Plugin Test', () => {
|
||||||
it(`Should add the snippets to defs`, () => {
|
it(`Should add the bnotch to defs`, () => {
|
||||||
expect(pattern.svg.defs.render()).to.contain('<g id="notch">')
|
expect(pattern.svg.defs.get('bnotch')).to.not.equal(false)
|
||||||
})
|
})
|
||||||
|
it(`Should add the notch to defs`, () => {
|
||||||
it(`Should add the notches snippet to defs`, () => {
|
expect(pattern.svg.defs.get('notch')).to.not.equal(false)
|
||||||
expect(pattern.svg.defs.render().indexOf(`<g id="notch">`)).to.not.equal(-1)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Draws a notch on an anchor point', () => {
|
it('Draws a notch on an anchor point', () => {
|
||||||
const part = {
|
const part = {
|
||||||
name: 'test',
|
name: 'test',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue