chore(plugin-bartack): Ported to v3
This commit is contained in:
parent
15dbb867ac
commit
a28286280d
6 changed files with 61 additions and 57 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,34 +0,0 @@
|
||||||
import pkg from '../package.json'
|
|
||||||
import bartack from './bartack'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: pkg.name,
|
|
||||||
version: pkg.version,
|
|
||||||
hooks: {
|
|
||||||
preRender: (svg) => svg.attributes.setIfUnset('freesewing:plugin-bartack', pkg.version),
|
|
||||||
},
|
|
||||||
macros: {
|
|
||||||
bartack: function (so) {
|
|
||||||
const self = this
|
|
||||||
return bartack(so, self)
|
|
||||||
},
|
|
||||||
bartackAlong: function (so) {
|
|
||||||
const self = this
|
|
||||||
so.bartackFractionAlong = false
|
|
||||||
so.bartackAlong = true
|
|
||||||
so.anchor = false
|
|
||||||
so.from = false
|
|
||||||
so.to = false
|
|
||||||
return bartack(so, self)
|
|
||||||
},
|
|
||||||
bartackFractionAlong: function (so) {
|
|
||||||
const self = this
|
|
||||||
so.bartackFractionAlong = true
|
|
||||||
so.bartackAlong = false
|
|
||||||
so.anchor = false
|
|
||||||
so.from = false
|
|
||||||
so.to = false
|
|
||||||
return bartack(so, self)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
|
@ -1,5 +1,9 @@
|
||||||
const name = (n, so) => `${so.prefix}${n}${so.suffix}`
|
import { version, name } from '../package.json' assert { type: 'json' }
|
||||||
|
|
||||||
|
// Helper method to construct prefixed/suffixed name
|
||||||
|
const getName = (n, so) => `${so.prefix}${n}${so.suffix}`
|
||||||
|
|
||||||
|
// Method that draws the actual bartack
|
||||||
const drawBartack = (points, self) => {
|
const drawBartack = (points, self) => {
|
||||||
let path = new self.Path().move(points.path1[0])
|
let path = new self.Path().move(points.path1[0])
|
||||||
for (const i in points.path1) {
|
for (const i in points.path1) {
|
||||||
|
@ -10,6 +14,7 @@ const drawBartack = (points, self) => {
|
||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper method to generate the points to draw on later
|
||||||
const getPoints = (path, so) => {
|
const getPoints = (path, so) => {
|
||||||
let path1 = path.offset(so.width / 2)
|
let path1 = path.offset(so.width / 2)
|
||||||
let path2 = path.offset(so.width / -2)
|
let path2 = path.offset(so.width / -2)
|
||||||
|
@ -87,10 +92,45 @@ export default function bartack(so, self) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.paths[name('bartack', so)] = bartackPath(guide, so, self).attr(
|
self.paths[`${so.prefix}bartack${so.suffix}`] = bartackPath(guide, so, self)
|
||||||
'class',
|
.attr('class', 'stroke-sm stroke-mark')
|
||||||
'stroke-sm stroke-mark'
|
|
||||||
)
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// The actual plugin
|
||||||
|
export const plugin = {
|
||||||
|
name,
|
||||||
|
version,
|
||||||
|
macros: {
|
||||||
|
bartack: function (so) {
|
||||||
|
const self = this
|
||||||
|
return bartack(so, self)
|
||||||
|
},
|
||||||
|
bartackAlong: function (so) {
|
||||||
|
const self = this
|
||||||
|
so.bartackFractionAlong = false
|
||||||
|
so.bartackAlong = true
|
||||||
|
so.anchor = false
|
||||||
|
so.from = false
|
||||||
|
so.to = false
|
||||||
|
return bartack(so, self)
|
||||||
|
},
|
||||||
|
bartackFractionAlong: function (so) {
|
||||||
|
const self = this
|
||||||
|
so.bartackFractionAlong = true
|
||||||
|
so.bartackAlong = false
|
||||||
|
so.anchor = false
|
||||||
|
so.from = false
|
||||||
|
so.to = false
|
||||||
|
return bartack(so, self)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// More specifically named exports
|
||||||
|
export const bartackPlugin = plugin
|
||||||
|
export const pluginBartack = plugin
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
import chai from 'chai'
|
import chai from 'chai'
|
||||||
import freesewing from '@freesewing/core'
|
import { round, 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 round = freesewing.utils.round
|
|
||||||
|
|
||||||
describe('Bartack plugin Tests', () => {
|
describe('Bartack plugin Tests', () => {
|
||||||
it('draws a default bartack from a point', function () {
|
it('draws a default bartack from a point', function () {
|
||||||
const pattern = new freesewing.Pattern()
|
const pattern = new Pattern()
|
||||||
pattern.use(plugin)
|
pattern.use(plugin)
|
||||||
pattern.parts.test = new pattern.Part()
|
pattern.parts.test = new pattern.Part()
|
||||||
pattern.parts.test.points.from = new pattern.Point(10, 20)
|
pattern.parts.test.points.from = new pattern.Point(10, 20)
|
||||||
|
@ -33,7 +32,7 @@ describe('Bartack plugin Tests', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('draws a bartack along a path', function () {
|
it('draws a bartack along a path', function () {
|
||||||
const pattern = new freesewing.Pattern()
|
const pattern = new Pattern()
|
||||||
pattern.use(plugin)
|
pattern.use(plugin)
|
||||||
pattern.parts.test = new pattern.Part()
|
pattern.parts.test = new pattern.Part()
|
||||||
const from = new pattern.Point(10, 20)
|
const from = new pattern.Point(10, 20)
|
||||||
|
@ -61,7 +60,7 @@ describe('Bartack plugin Tests', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can be called using the bartackFractionAlong syntax', function () {
|
it('can be called using the bartackFractionAlong syntax', function () {
|
||||||
const pattern = new freesewing.Pattern()
|
const pattern = new Pattern()
|
||||||
pattern.use(plugin)
|
pattern.use(plugin)
|
||||||
pattern.parts.test = new pattern.Part()
|
pattern.parts.test = new pattern.Part()
|
||||||
const from = new pattern.Point(10, 20)
|
const from = new pattern.Point(10, 20)
|
||||||
|
@ -91,7 +90,7 @@ describe('Bartack plugin Tests', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can be called using the bartackFractionAlong syntax', function () {
|
it('can be called using the bartackFractionAlong syntax', function () {
|
||||||
const pattern = new freesewing.Pattern()
|
const pattern = new Pattern()
|
||||||
pattern.use(plugin)
|
pattern.use(plugin)
|
||||||
pattern.parts.test = new pattern.Part()
|
pattern.parts.test = new pattern.Part()
|
||||||
const from = new pattern.Point(10, 20)
|
const from = new pattern.Point(10, 20)
|
||||||
|
@ -121,7 +120,7 @@ describe('Bartack plugin Tests', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('has configurable length', function () {
|
it('has configurable length', function () {
|
||||||
const pattern = new freesewing.Pattern()
|
const pattern = new Pattern()
|
||||||
pattern.use(plugin)
|
pattern.use(plugin)
|
||||||
pattern.parts.test = new pattern.Part()
|
pattern.parts.test = new pattern.Part()
|
||||||
pattern.parts.test.points.from = new pattern.Point(10, 20)
|
pattern.parts.test.points.from = new pattern.Point(10, 20)
|
||||||
|
@ -148,7 +147,7 @@ describe('Bartack plugin Tests', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('has configurable width', function () {
|
it('has configurable width', function () {
|
||||||
const pattern = new freesewing.Pattern()
|
const pattern = new Pattern()
|
||||||
pattern.use(plugin)
|
pattern.use(plugin)
|
||||||
pattern.parts.test = new pattern.Part()
|
pattern.parts.test = new pattern.Part()
|
||||||
pattern.parts.test.points.from = new pattern.Point(10, 20)
|
pattern.parts.test.points.from = new pattern.Point(10, 20)
|
||||||
|
@ -175,7 +174,7 @@ describe('Bartack plugin Tests', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('has configurable angle', function () {
|
it('has configurable angle', function () {
|
||||||
const pattern = new freesewing.Pattern()
|
const pattern = new Pattern()
|
||||||
pattern.use(plugin)
|
pattern.use(plugin)
|
||||||
pattern.parts.test = new pattern.Part()
|
pattern.parts.test = new pattern.Part()
|
||||||
pattern.parts.test.points.from = new pattern.Point(10, 20)
|
pattern.parts.test.points.from = new pattern.Point(10, 20)
|
||||||
|
@ -202,7 +201,7 @@ describe('Bartack plugin Tests', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('has configurable suffix', function () {
|
it('has configurable suffix', function () {
|
||||||
const pattern = new freesewing.Pattern()
|
const pattern = new Pattern()
|
||||||
pattern.use(plugin)
|
pattern.use(plugin)
|
||||||
pattern.parts.test = new pattern.Part()
|
pattern.parts.test = new pattern.Part()
|
||||||
pattern.parts.test.points.from = new pattern.Point(10, 20)
|
pattern.parts.test.points.from = new pattern.Point(10, 20)
|
||||||
|
@ -216,7 +215,7 @@ describe('Bartack plugin Tests', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('has configurable prefix', function () {
|
it('has configurable prefix', function () {
|
||||||
const pattern = new freesewing.Pattern()
|
const pattern = new Pattern()
|
||||||
pattern.use(plugin)
|
pattern.use(plugin)
|
||||||
pattern.parts.test = new pattern.Part()
|
pattern.parts.test = new pattern.Part()
|
||||||
pattern.parts.test.points.from = new pattern.Point(10, 20)
|
pattern.parts.test.points.from = new pattern.Point(10, 20)
|
||||||
|
|
|
@ -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