diff --git a/plugins/plugin-buttons/build.mjs b/plugins/plugin-buttons/build.mjs
index 9d1da1994da..0f283af1c6d 100644
--- a/plugins/plugin-buttons/build.mjs
+++ b/plugins/plugin-buttons/build.mjs
@@ -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"],
diff --git a/plugins/plugin-buttons/package.json b/plugins/plugin-buttons/package.json
index 41167deaf12..616924d6df2 100644
--- a/plugins/plugin-buttons/package.json
+++ b/plugins/plugin-buttons/package.json
@@ -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"
},
diff --git a/plugins/plugin-buttons/src/button.js b/plugins/plugin-buttons/src/button.js
deleted file mode 100644
index 5170f7fd583..00000000000
--- a/plugins/plugin-buttons/src/button.js
+++ /dev/null
@@ -1,11 +0,0 @@
-export default `
-
-
-
-
-
-
-`
diff --git a/plugins/plugin-buttons/src/buttonhole.js b/plugins/plugin-buttons/src/buttonhole.js
deleted file mode 100644
index 221214df981..00000000000
--- a/plugins/plugin-buttons/src/buttonhole.js
+++ /dev/null
@@ -1,19 +0,0 @@
-export default `
-
-
-
-
-
-
-
-
-`
diff --git a/plugins/plugin-buttons/src/index.js b/plugins/plugin-buttons/src/index.js
deleted file mode 100644
index f0e9b2864fb..00000000000
--- a/plugins/plugin-buttons/src/index.js
+++ /dev/null
@@ -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
- }
- },
- },
-}
diff --git a/plugins/plugin-buttons/src/snaps.js b/plugins/plugin-buttons/src/index.mjs
similarity index 51%
rename from plugins/plugin-buttons/src/snaps.js
rename to plugins/plugin-buttons/src/index.mjs
index 11aa881b892..4a8a637d6db 100644
--- a/plugins/plugin-buttons/src/snaps.js
+++ b/plugins/plugin-buttons/src/index.mjs
@@ -1,4 +1,40 @@
-export default `
+import { name, version } from '../package.json' assert { type: 'json' }
+
+const defs = [
+ // button
+ `
+
+
+
+
+
+
+`,
+ // buttonhole
+ `
+
+
+
+
+
+
+
+
+`,
+ // snaps
+ `
@@ -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"
/>
`
+]
+
+
+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
+
diff --git a/plugins/plugin-buttons/tests/plugin.test.mjs b/plugins/plugin-buttons/tests/plugin.test.mjs
index 3f3d179a0cc..81fad3154c6 100644
--- a/plugins/plugin-buttons/tests/plugin.test.mjs
+++ b/plugins/plugin-buttons/tests/plugin.test.mjs
@@ -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('Buttons Plugin Test', () => {
@@ -15,7 +15,7 @@ describe('Buttons Plugin Test', () => {
}
it('Draws a button on an anchor point', () => {
- let pattern = new freesewing.Pattern()
+ let pattern = new Pattern()
pattern.use(plugin)
pattern.parts.test = new pattern.Part()
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', () => {
- let pattern = new freesewing.Pattern()
+ let pattern = new Pattern()
pattern.use(plugin)
pattern.parts.test = new pattern.Part()
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', () => {
- let pattern = new freesewing.Pattern()
+ let pattern = new Pattern()
pattern.use(plugin)
pattern.parts.test = new pattern.Part()
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', () => {
- let pattern = new freesewing.Pattern()
+ let pattern = new Pattern()
pattern.use(plugin)
pattern.parts.test = new pattern.Part()
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', () => {
- let pattern = new freesewing.Pattern()
+ let pattern = new Pattern()
pattern.use(plugin)
pattern.parts.test = new pattern.Part()
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', () => {
- let pattern = new freesewing.Pattern()
+ let pattern = new Pattern()
pattern.use(plugin)
pattern.parts.test = new pattern.Part()
let { Point, snippets, Snippet } = pattern.parts.test.shorthand()
diff --git a/plugins/plugin-buttons/tests/shared.test.mjs b/plugins/plugin-buttons/tests/shared.test.mjs
index 9638f75571e..fdf846844b0 100644
--- a/plugins/plugin-buttons/tests/shared.test.mjs
+++ b/plugins/plugin-buttons/tests/shared.test.mjs
@@ -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)
+