1
0
Fork 0

chore(plugin-bartack): Ported to v3

This commit is contained in:
Joost De Cock 2022-08-28 11:58:04 +02:00
parent 15dbb867ac
commit a28286280d
6 changed files with 61 additions and 57 deletions

View file

@ -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"],

View file

@ -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"
},

View file

@ -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)
},
},
}

View file

@ -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) => {
let path = new self.Path().move(points.path1[0])
for (const i in points.path1) {
@ -10,6 +14,7 @@ const drawBartack = (points, self) => {
return path
}
// Helper method to generate the points to draw on later
const getPoints = (path, so) => {
let path1 = 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(
'class',
'stroke-sm stroke-mark'
)
self.paths[`${so.prefix}bartack${so.suffix}`] = bartackPath(guide, so, self)
.attr('class', 'stroke-sm stroke-mark')
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

View file

@ -1,13 +1,12 @@
import chai from 'chai'
import freesewing from '@freesewing/core'
import plugin from '../dist/index.mjs'
import { round, Pattern } from '@freesewing/core'
import { plugin } from '../dist/index.mjs'
const expect = chai.expect
const round = freesewing.utils.round
describe('Bartack plugin Tests', () => {
it('draws a default bartack from a point', function () {
const pattern = new freesewing.Pattern()
const pattern = new Pattern()
pattern.use(plugin)
pattern.parts.test = new pattern.Part()
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 () {
const pattern = new freesewing.Pattern()
const pattern = new Pattern()
pattern.use(plugin)
pattern.parts.test = new pattern.Part()
const from = new pattern.Point(10, 20)
@ -61,7 +60,7 @@ describe('Bartack plugin Tests', () => {
})
it('can be called using the bartackFractionAlong syntax', function () {
const pattern = new freesewing.Pattern()
const pattern = new Pattern()
pattern.use(plugin)
pattern.parts.test = new pattern.Part()
const from = new pattern.Point(10, 20)
@ -91,7 +90,7 @@ describe('Bartack plugin Tests', () => {
})
it('can be called using the bartackFractionAlong syntax', function () {
const pattern = new freesewing.Pattern()
const pattern = new Pattern()
pattern.use(plugin)
pattern.parts.test = new pattern.Part()
const from = new pattern.Point(10, 20)
@ -121,7 +120,7 @@ describe('Bartack plugin Tests', () => {
})
it('has configurable length', function () {
const pattern = new freesewing.Pattern()
const pattern = new Pattern()
pattern.use(plugin)
pattern.parts.test = new pattern.Part()
pattern.parts.test.points.from = new pattern.Point(10, 20)
@ -148,7 +147,7 @@ describe('Bartack plugin Tests', () => {
})
it('has configurable width', function () {
const pattern = new freesewing.Pattern()
const pattern = new Pattern()
pattern.use(plugin)
pattern.parts.test = new pattern.Part()
pattern.parts.test.points.from = new pattern.Point(10, 20)
@ -175,7 +174,7 @@ describe('Bartack plugin Tests', () => {
})
it('has configurable angle', function () {
const pattern = new freesewing.Pattern()
const pattern = new Pattern()
pattern.use(plugin)
pattern.parts.test = new pattern.Part()
pattern.parts.test.points.from = new pattern.Point(10, 20)
@ -202,7 +201,7 @@ describe('Bartack plugin Tests', () => {
})
it('has configurable suffix', function () {
const pattern = new freesewing.Pattern()
const pattern = new Pattern()
pattern.use(plugin)
pattern.parts.test = new pattern.Part()
pattern.parts.test.points.from = new pattern.Point(10, 20)
@ -216,7 +215,7 @@ describe('Bartack plugin Tests', () => {
})
it('has configurable prefix', function () {
const pattern = new freesewing.Pattern()
const pattern = new Pattern()
pattern.use(plugin)
pattern.parts.test = new pattern.Part()
pattern.parts.test.points.from = new pattern.Point(10, 20)

View file

@ -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)