chore(plugin-notches): Ported to v3
This commit is contained in:
parent
e843144355
commit
fcea467c8e
6 changed files with 37 additions and 29 deletions
|
@ -14,7 +14,7 @@ const banner = `/**
|
|||
const options = {
|
||||
banner: { js: banner },
|
||||
bundle: true,
|
||||
entryPoints: ['src/index.js'],
|
||||
entryPoints: ['src/index.mjs'],
|
||||
format: 'esm',
|
||||
outfile: 'dist/index.mjs',
|
||||
external: ["@freesewing"],
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
"vbuild": "VERBOSE=1 node --experimental-json-modules build.mjs",
|
||||
"lab": "cd ../../sites/lab && yarn start",
|
||||
"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",
|
||||
"cibuild_step1": "node --experimental-json-modules build.mjs"
|
||||
},
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
import pkg from '../package.json'
|
||||
|
||||
const notches =
|
||||
'<g id="notch"><circle cy="0" cx="0" r="1.4" class="fill-note" /><circle cy="0" cx="0" r="2.8" class="note" /></g><g id="bnotch"><path d="M -1.1 -1.1 L 1.1 1.1 M 1.1 -1.1 L -1.1 1.1" class="note" /><circle cy="0" cx="0" r="2.8" class="note" /></g>'
|
||||
|
||||
export default {
|
||||
name: pkg.name,
|
||||
version: pkg.version,
|
||||
hooks: {
|
||||
preRender: function (svg) {
|
||||
if (svg.attributes.get('freesewing:plugin-notches') === false) {
|
||||
svg.defs += notches
|
||||
svg.attributes.set('freesewing:plugin-notches', pkg.version)
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
26
plugins/plugin-notches/src/index.mjs
Normal file
26
plugins/plugin-notches/src/index.mjs
Normal file
|
@ -0,0 +1,26 @@
|
|||
import { name, version } from '../package.json'
|
||||
|
||||
const notches = `
|
||||
<g id="notch">
|
||||
<circle cy="0" cx="0" r="1.4" class="fill-note" />
|
||||
<circle cy="0" cx="0" r="2.8" class="note" />
|
||||
</g>
|
||||
<g id="bnotch">
|
||||
<path d="M -1.1 -1.1 L 1.1 1.1 M 1.1 -1.1 L -1.1 1.1" class="note" />
|
||||
<circle cy="0" cx="0" r="2.8" class="note" />
|
||||
</g>`
|
||||
|
||||
export const plugin = {
|
||||
name,
|
||||
version,
|
||||
hooks: {
|
||||
preRender: function (svg) {
|
||||
if (svg.defs.indexOf(`id="notch"`) === -1) svg.defs += notches
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// More specifically named exports
|
||||
export const notchesPlugin = plugin
|
||||
export const pluginNotches = plugin
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
import chai from 'chai'
|
||||
import freesewing from '@freesewing/core'
|
||||
import plugin from '../dist/index.mjs'
|
||||
import { Pattern } from '@freesewing/core'
|
||||
import { plugin } from '../dist/index.mjs'
|
||||
|
||||
const expect = chai.expect
|
||||
|
||||
const pattern = new freesewing.Pattern().use(plugin)
|
||||
const pattern = new Pattern().use(plugin)
|
||||
pattern.draft().render()
|
||||
|
||||
describe('Notches Plugin Test', () => {
|
||||
|
@ -17,13 +17,13 @@ describe('Notches Plugin Test', () => {
|
|||
})
|
||||
|
||||
it("Draws a notch on an anchor point", () => {
|
||||
let pattern = new freesewing.Pattern()
|
||||
const pattern = new Pattern()
|
||||
pattern.use(plugin)
|
||||
pattern.parts.test = new pattern.Part()
|
||||
let { Point, snippets, Snippet } = pattern.parts.test.shorthand()
|
||||
const { Point, snippets, Snippet } = pattern.parts.test.shorthand()
|
||||
snippets.button = new Snippet('notch', new Point(10,20))
|
||||
pattern.render()
|
||||
let c = pattern.svg
|
||||
const c = pattern.svg
|
||||
expect(c.layout.test.svg).to.contain('<use x="10" y="20" xlink:href="#notch"')
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
// This file is auto-generated.
|
||||
// Changes you make will be overwritten.
|
||||
import plugin from './dist/index.mjs'
|
||||
// This file is auto-generated | Any changes you make will be overwritten.
|
||||
import { plugin } from './dist/index.mjs'
|
||||
import { sharedPluginTests } from '../../../tests/plugins/shared.mjs'
|
||||
|
||||
|
||||
// Run shared tests
|
||||
sharedPluginTests(plugin)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue