chore(plugin-buttons): Ported to v3
This commit is contained in:
parent
b72f952847
commit
20ab289232
8 changed files with 70 additions and 63 deletions
|
@ -14,7 +14,7 @@ const banner = `/**
|
||||||
const options = {
|
const options = {
|
||||||
banner: { js: banner },
|
banner: { js: banner },
|
||||||
bundle: true,
|
bundle: true,
|
||||||
entryPoints: ['src/index.js'],
|
entryPoints: ['src/index.mjs'],
|
||||||
format: 'esm',
|
format: 'esm',
|
||||||
outfile: 'dist/index.mjs',
|
outfile: 'dist/index.mjs',
|
||||||
external: ["@freesewing"],
|
external: ["@freesewing"],
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
"vbuild": "VERBOSE=1 node --experimental-json-modules build.mjs",
|
"vbuild": "VERBOSE=1 node --experimental-json-modules build.mjs",
|
||||||
"lab": "cd ../../sites/lab && yarn start",
|
"lab": "cd ../../sites/lab && yarn start",
|
||||||
"tips": "node ../../scripts/help.mjs",
|
"tips": "node ../../scripts/help.mjs",
|
||||||
"prettier": "npx prettier --write 'src/*.js' 'tests/*.mjs'",
|
"prettier": "npx prettier --write 'src/*.mjs' 'tests/*.mjs'",
|
||||||
"testci": "npx mocha tests/*.test.mjs --reporter ../../tests/reporters/terse.js",
|
"testci": "npx mocha tests/*.test.mjs --reporter ../../tests/reporters/terse.js",
|
||||||
"cibuild_step1": "node --experimental-json-modules build.mjs"
|
"cibuild_step1": "node --experimental-json-modules build.mjs"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
export default `
|
|
||||||
<g id="button">
|
|
||||||
<circle
|
|
||||||
cx="0" cy="0" r="3.4"
|
|
||||||
class="mark"
|
|
||||||
/>
|
|
||||||
<circle cx="-1" cy="-1" r="0.5" class="no-stroke fill-mark"/>
|
|
||||||
<circle cx="1" cy="-1" r="0.5" class="no-stroke fill-mark" />
|
|
||||||
<circle cx="1" cy="1" r="0.5" class="no-stroke fill-mark" />
|
|
||||||
<circle cx="-1" cy="1" r="0.5" class="no-stroke fill-mark" />
|
|
||||||
</g>`
|
|
|
@ -1,19 +0,0 @@
|
||||||
export default `
|
|
||||||
<g id="buttonhole">
|
|
||||||
<path
|
|
||||||
class="mark"
|
|
||||||
d="M -1,-5 L 1,-5 L 1,5 L -1,5 z"
|
|
||||||
/>
|
|
||||||
</g>
|
|
||||||
<g id="buttonhole-start">
|
|
||||||
<path
|
|
||||||
class="mark"
|
|
||||||
d="M -1,-10 L 1,-10 L 1,0 L -1,0 z"
|
|
||||||
/>
|
|
||||||
</g>
|
|
||||||
<g id="buttonhole-end">
|
|
||||||
<path
|
|
||||||
class="mark"
|
|
||||||
d="M -1,0 L 1,0 L 1,10 L -1,10 z"
|
|
||||||
/>
|
|
||||||
</g>`
|
|
|
@ -1,17 +0,0 @@
|
||||||
import button from './button'
|
|
||||||
import buttonhole from './buttonhole'
|
|
||||||
import snaps from './snaps'
|
|
||||||
import pkg from '../package.json'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: pkg.name,
|
|
||||||
version: pkg.version,
|
|
||||||
hooks: {
|
|
||||||
preRender: function (svg) {
|
|
||||||
if (svg.attributes.get('freesewing:plugin-buttons') === false) {
|
|
||||||
svg.attributes.set('freesewing:plugin-buttons', pkg.version)
|
|
||||||
svg.defs += button + buttonhole + snaps
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
|
@ -1,4 +1,40 @@
|
||||||
export default `
|
import { name, version } from '../package.json' assert { type: 'json' }
|
||||||
|
|
||||||
|
const defs = [
|
||||||
|
// button
|
||||||
|
`
|
||||||
|
<g id="button">
|
||||||
|
<circle
|
||||||
|
cx="0" cy="0" r="3.4"
|
||||||
|
class="mark"
|
||||||
|
/>
|
||||||
|
<circle cx="-1" cy="-1" r="0.5" class="no-stroke fill-mark"/>
|
||||||
|
<circle cx="1" cy="-1" r="0.5" class="no-stroke fill-mark" />
|
||||||
|
<circle cx="1" cy="1" r="0.5" class="no-stroke fill-mark" />
|
||||||
|
<circle cx="-1" cy="1" r="0.5" class="no-stroke fill-mark" />
|
||||||
|
</g>`,
|
||||||
|
// buttonhole
|
||||||
|
`
|
||||||
|
<g id="buttonhole">
|
||||||
|
<path
|
||||||
|
class="mark"
|
||||||
|
d="M -1,-5 L 1,-5 L 1,5 L -1,5 z"
|
||||||
|
/>
|
||||||
|
</g>
|
||||||
|
<g id="buttonhole-start">
|
||||||
|
<path
|
||||||
|
class="mark"
|
||||||
|
d="M -1,-10 L 1,-10 L 1,0 L -1,0 z"
|
||||||
|
/>
|
||||||
|
</g>
|
||||||
|
<g id="buttonhole-end">
|
||||||
|
<path
|
||||||
|
class="mark"
|
||||||
|
d="M -1,0 L 1,0 L 1,10 L -1,10 z"
|
||||||
|
/>
|
||||||
|
</g>`,
|
||||||
|
// snaps
|
||||||
|
`
|
||||||
<radialGradient id="snap-stud-grad" cx="50%" cy="50%" r="50%" fx="50%" fy="50%">
|
<radialGradient id="snap-stud-grad" cx="50%" cy="50%" r="50%" fx="50%" fy="50%">
|
||||||
<stop offset="30%" style="stop-color:rgb(235,235,235); stop-opacity:1"/>
|
<stop offset="30%" style="stop-color:rgb(235,235,235); stop-opacity:1"/>
|
||||||
<stop offset="80%" style="stop-color:rgb(100,100,100);stop-opacity:1" />
|
<stop offset="80%" style="stop-color:rgb(100,100,100);stop-opacity:1" />
|
||||||
|
@ -27,3 +63,22 @@ export default `
|
||||||
d="M -1.7,-1 L -1.7,1 M 1.7,-1 L 1.7,1" id="snap-socket-lines"
|
d="M -1.7,-1 L -1.7,1 M 1.7,-1 L 1.7,1" id="snap-socket-lines"
|
||||||
/>
|
/>
|
||||||
</g>`
|
</g>`
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
export const plugin = {
|
||||||
|
name,
|
||||||
|
version,
|
||||||
|
hooks: {
|
||||||
|
preRender: function (svg) {
|
||||||
|
for (const def of defs) {
|
||||||
|
if (svg.defs.indexOf(def) === -1) svg.defs += def
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// More specifically named exports
|
||||||
|
export const buttonsPlugin = plugin
|
||||||
|
export const pluginButtons = plugin
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import chai from 'chai'
|
import chai from 'chai'
|
||||||
import freesewing from '@freesewing/core'
|
import { Pattern } from '@freesewing/core'
|
||||||
import plugin from '../dist/index.mjs'
|
import { plugin } from './dist/index.mjs'
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
|
|
||||||
const pattern = new freesewing.Pattern().use(plugin)
|
const pattern = new Pattern().use(plugin)
|
||||||
pattern.draft().render()
|
pattern.draft().render()
|
||||||
|
|
||||||
describe('Buttons Plugin Test', () => {
|
describe('Buttons Plugin Test', () => {
|
||||||
|
@ -15,7 +15,7 @@ describe('Buttons Plugin Test', () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
it('Draws a button on an anchor point', () => {
|
it('Draws a button on an anchor point', () => {
|
||||||
let pattern = new freesewing.Pattern()
|
let pattern = new Pattern()
|
||||||
pattern.use(plugin)
|
pattern.use(plugin)
|
||||||
pattern.parts.test = new pattern.Part()
|
pattern.parts.test = new pattern.Part()
|
||||||
let { Point, snippets, Snippet } = pattern.parts.test.shorthand()
|
let { Point, snippets, Snippet } = pattern.parts.test.shorthand()
|
||||||
|
@ -26,7 +26,7 @@ describe('Buttons Plugin Test', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Draws a buttonhole centred on an anchor point', () => {
|
it('Draws a buttonhole centred on an anchor point', () => {
|
||||||
let pattern = new freesewing.Pattern()
|
let pattern = new Pattern()
|
||||||
pattern.use(plugin)
|
pattern.use(plugin)
|
||||||
pattern.parts.test = new pattern.Part()
|
pattern.parts.test = new pattern.Part()
|
||||||
let { Point, snippets, Snippet } = pattern.parts.test.shorthand()
|
let { Point, snippets, Snippet } = pattern.parts.test.shorthand()
|
||||||
|
@ -37,7 +37,7 @@ describe('Buttons Plugin Test', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Draws a buttonhole starting on an anchor point', () => {
|
it('Draws a buttonhole starting on an anchor point', () => {
|
||||||
let pattern = new freesewing.Pattern()
|
let pattern = new Pattern()
|
||||||
pattern.use(plugin)
|
pattern.use(plugin)
|
||||||
pattern.parts.test = new pattern.Part()
|
pattern.parts.test = new pattern.Part()
|
||||||
let { Point, snippets, Snippet } = pattern.parts.test.shorthand()
|
let { Point, snippets, Snippet } = pattern.parts.test.shorthand()
|
||||||
|
@ -48,7 +48,7 @@ describe('Buttons Plugin Test', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Draws a buttonhole ending on an anchor point', () => {
|
it('Draws a buttonhole ending on an anchor point', () => {
|
||||||
let pattern = new freesewing.Pattern()
|
let pattern = new Pattern()
|
||||||
pattern.use(plugin)
|
pattern.use(plugin)
|
||||||
pattern.parts.test = new pattern.Part()
|
pattern.parts.test = new pattern.Part()
|
||||||
let { Point, snippets, Snippet } = pattern.parts.test.shorthand()
|
let { Point, snippets, Snippet } = pattern.parts.test.shorthand()
|
||||||
|
@ -59,7 +59,7 @@ describe('Buttons Plugin Test', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Draws a snap-stud on an anchor point', () => {
|
it('Draws a snap-stud on an anchor point', () => {
|
||||||
let pattern = new freesewing.Pattern()
|
let pattern = new Pattern()
|
||||||
pattern.use(plugin)
|
pattern.use(plugin)
|
||||||
pattern.parts.test = new pattern.Part()
|
pattern.parts.test = new pattern.Part()
|
||||||
let { Point, snippets, Snippet } = pattern.parts.test.shorthand()
|
let { Point, snippets, Snippet } = pattern.parts.test.shorthand()
|
||||||
|
@ -70,7 +70,7 @@ describe('Buttons Plugin Test', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Draws a snap-socket on an anchor point', () => {
|
it('Draws a snap-socket on an anchor point', () => {
|
||||||
let pattern = new freesewing.Pattern()
|
let pattern = new Pattern()
|
||||||
pattern.use(plugin)
|
pattern.use(plugin)
|
||||||
pattern.parts.test = new pattern.Part()
|
pattern.parts.test = new pattern.Part()
|
||||||
let { Point, snippets, Snippet } = pattern.parts.test.shorthand()
|
let { Point, snippets, Snippet } = pattern.parts.test.shorthand()
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
// This file is auto-generated.
|
// This file is auto-generated | Any changes you make will be overwritten.
|
||||||
// Changes you make will be overwritten.
|
import { plugin } from './dist/index.mjs'
|
||||||
import plugin from './dist/index.mjs'
|
|
||||||
import { sharedPluginTests } from '../../../tests/plugins/shared.mjs'
|
import { sharedPluginTests } from '../../../tests/plugins/shared.mjs'
|
||||||
|
|
||||||
|
|
||||||
// Run shared tests
|
// Run shared tests
|
||||||
sharedPluginTests(plugin)
|
sharedPluginTests(plugin)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue