feat(plugin-bartack): New plugin for bartacks
This commit is contained in:
parent
856a6bc2e0
commit
ef670f7888
9 changed files with 365 additions and 0 deletions
10
packages/plugin-bartack/.babelrc
Normal file
10
packages/plugin-bartack/.babelrc
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"presets": [
|
||||
[
|
||||
"@babel/preset-env",
|
||||
{
|
||||
"useBuiltIns": "entry"
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
9
packages/plugin-bartack/CHANGELOG.md
Normal file
9
packages/plugin-bartack/CHANGELOG.md
Normal file
|
@ -0,0 +1,9 @@
|
|||
# Change log for: @freesewing/plugin-bartack
|
||||
|
||||
|
||||
|
||||
This is the **initial release**, and the start of this change log.
|
||||
|
||||
> Prior to version 2, FreeSewing was not a JavaScript project.
|
||||
> As such, that history is out of scope for this change log.
|
||||
|
118
packages/plugin-bartack/README.md
Normal file
118
packages/plugin-bartack/README.md
Normal file
|
@ -0,0 +1,118 @@
|
|||

|
||||
<p align='center'><a
|
||||
href="https://www.npmjs.com/package/@freesewing/plugin-bartack"
|
||||
title="@freesewing/plugin-bartack on NPM"
|
||||
><img src="https://img.shields.io/npm/v/@freesewing/plugin-bartack.svg"
|
||||
alt="@freesewing/plugin-bartack on NPM"/>
|
||||
</a><a
|
||||
href="https://opensource.org/licenses/MIT"
|
||||
title="License: MIT"
|
||||
><img src="https://img.shields.io/npm/l/@freesewing/plugin-bartack.svg?label=License"
|
||||
alt="License: MIT"/>
|
||||
</a><a
|
||||
href="https://deepscan.io/dashboard#view=project&tid=2114&pid=2993&bid=23256"
|
||||
title="Code quality on DeepScan"
|
||||
><img src="https://deepscan.io/api/teams/2114/projects/2993/branches/23256/badge/grade.svg"
|
||||
alt="Code quality on DeepScan"/>
|
||||
</a><a
|
||||
href="https://github.com/freesewing/freesewing/issues?q=is%3Aissue+is%3Aopen+label%3Apkg%3Aplugin-bartack"
|
||||
title="Open issues tagged pkg:plugin-bartack"
|
||||
><img src="https://img.shields.io/github/issues/freesewing/freesewing/pkg:plugin-bartack.svg?label=Issues"
|
||||
alt="Open issues tagged pkg:plugin-bartack"/>
|
||||
</a><a
|
||||
href="https://todo.freesewing.org/"
|
||||
title="Project board"
|
||||
><img src="https://img.shields.io/badge/%F3%A0%80%A0-Project%20board-9775fa.svg?logo=github&logoColor=white&logoWidth=15"
|
||||
alt="Project board"/>
|
||||
</a></p><p align='center'><a
|
||||
href="https://twitter.com/freesewing_org"
|
||||
title="Follow @freesewing_org on Twitter"
|
||||
><img src="https://img.shields.io/badge/%F3%A0%80%A0-Follow%20us-blue.svg?logo=twitter&logoColor=white&logoWidth=15"
|
||||
alt="Follow @freesewing_org on Twitter"/>
|
||||
</a><a
|
||||
href="https://chat.freesewing.org"
|
||||
title="Chat with us on Discord"
|
||||
><img src="https://img.shields.io/discord/698854858052075530?label=Chat%20on%20Discord"
|
||||
alt="Chat with us on Discord"/>
|
||||
</a><a
|
||||
href="https://freesewing.org/patrons/join"
|
||||
title="Become a FreeSewing Patron"
|
||||
><img src="https://img.shields.io/badge/%F3%A0%80%A0-Support%20us-blueviolet.svg?logo=cash-app&logoColor=white&logoWidth=15"
|
||||
alt="Become a FreeSewing Patron"/>
|
||||
</a><a
|
||||
href="https://instagram.com/freesewing_org"
|
||||
title="Follow @freesewing_org on Twitter"
|
||||
><img src="https://img.shields.io/badge/%F3%A0%80%A0-Follow%20us-E4405F.svg?logo=instagram&logoColor=white&logoWidth=15"
|
||||
alt="Follow @freesewing_org on Twitter"/>
|
||||
</a></p>
|
||||
|
||||
# @freesewing/plugin-bartack
|
||||
|
||||
A FreeSewing plugin to add bartacks to your pattern
|
||||
|
||||
|
||||
|
||||
## What am I looking at? 🤔
|
||||
|
||||
This repository is our *monorepo*
|
||||
holding [all our NPM packages](https://freesewing.dev/reference/packages/).
|
||||
|
||||
This folder holds: @freesewing/plugin-bartack
|
||||
|
||||
## About FreeSewing 💀
|
||||
|
||||
Where the world of makers and developers collide, that's where you'll find FreeSewing.
|
||||
|
||||
If you're a maker, checkout [freesewing.org](https://freesewing.org/) where you can generate
|
||||
our sewing patterns adapted to your measurements.
|
||||
|
||||
If you're a developer, our documentation is on [freesewing.dev](https://freesewing.dev/).
|
||||
Our [core library](https://freesewing.dev/reference/api/) is a *batteries-included* toolbox
|
||||
for parametric design of sewing patterns. But we also provide a range
|
||||
of [plugins](https://freesewing.dev/reference/plugins/) that further extend the
|
||||
functionality of the platform.
|
||||
|
||||
If you have NodeJS installed, you can try it right now by running:
|
||||
|
||||
```bash
|
||||
npx create-freesewing-pattern
|
||||
```
|
||||
|
||||
Or, consult our getting started guides
|
||||
for [Linux](https://freesewing.dev/tutorials/getting-started-linux/),
|
||||
[MacOS](https://freesewing.dev/tutorials/getting-started-mac/),
|
||||
or [Windows](https://freesewing.dev/tutorials/getting-started-windows/).
|
||||
|
||||
We also have a [pattern design tutorial](https://freesewing.dev/tutorials/pattern-design/) that
|
||||
walks you through your first parametric design,
|
||||
and [a friendly community](https://freesewing.org/community/where/) with
|
||||
people who can help you when you get stuck.
|
||||
|
||||
## Support FreeSewing: Become a patron 🥰
|
||||
|
||||
FreeSewing is an open source project run by a community,
|
||||
and financially supported by our patrons.
|
||||
|
||||
If you feel what we do is worthwhile, and you can spend a few coind without
|
||||
hardship, then you should [join us and become a patron](https://freesewing.org/community/join).
|
||||
|
||||
## Links 👩💻
|
||||
|
||||
- 💻 Makers website: [freesewing.org](https://freesewing.org)
|
||||
- 💻 Developers website: [freesewing.dev](https://freesewing.dev)
|
||||
- 💬 Chat: On Discord via [chat.freesewing.org](https://chat.freesewing.org/)
|
||||
- ✅ Todo list/Kanban board: On Github via [todo.freesewing.org](https://todo.freesewing.org/)
|
||||
- 🐦 Twitter: [@freesewing_org](https://twitter.com/freesewing_org)
|
||||
- 📷 Instagram: [@freesewing_org](https://instagram.com/freesewing_org)
|
||||
|
||||
## License: MIT 🤓
|
||||
|
||||
© [Joost De Cock](https://github.com/joostdecock).
|
||||
See [the license file](https://github.com/freesewing/freesewing/blob/develop/LICENSE) for details.
|
||||
|
||||
## Where to get help 🤯
|
||||
|
||||
Our [chatrooms on Discord](https://chat.freesewing.org/) are the best place to ask questions,
|
||||
share your feedback, or just hang out.
|
||||
|
||||
If you want to report a problem, please [create an issue](https://github.com/freesewing/freesewing/issues/new).
|
BIN
packages/plugin-bartack/img/example.png
Normal file
BIN
packages/plugin-bartack/img/example.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 79 KiB |
55
packages/plugin-bartack/package.json
Normal file
55
packages/plugin-bartack/package.json
Normal file
|
@ -0,0 +1,55 @@
|
|||
{
|
||||
"name": "@freesewing/plugin-bartack",
|
||||
"version": "2.14.0",
|
||||
"description": "A FreeSewing plugin to add bartacks to your pattern",
|
||||
"author": "Joost De Cock <joost@decock.org> (https://github.com/joostdecock)",
|
||||
"homepage": "https://freesewing.org/",
|
||||
"repository": "github:freesewing/freesewing",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/freesewing/freesewing/issues"
|
||||
},
|
||||
"keywords": [
|
||||
"freesewing",
|
||||
"plugin",
|
||||
"sewing pattern",
|
||||
"sewing",
|
||||
"design",
|
||||
"parametric design",
|
||||
"made to measure",
|
||||
"diy",
|
||||
"fashion"
|
||||
],
|
||||
"main": "dist/index.js",
|
||||
"module": "dist/index.mjs",
|
||||
"scripts": {
|
||||
"clean": "rimraf dist",
|
||||
"build": "rollup -c",
|
||||
"test": "echo \"plugin-bartack: No tests configured. Perhaps you'd like to do this?\" && exit 0",
|
||||
"pubtest": "npm publish --registry http://localhost:6662",
|
||||
"pubforce": "npm publish",
|
||||
"symlink": "mkdir -p ./node_modules/@freesewing && cd ./node_modules/@freesewing && ln -s -f ../../../* . && cd -",
|
||||
"start": "rollup -c -w"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@freesewing/core": "^2.14.0"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {},
|
||||
"files": [
|
||||
"dist/*",
|
||||
"README.md",
|
||||
"package.json"
|
||||
],
|
||||
"publishConfig": {
|
||||
"access": "public",
|
||||
"tag": "latest"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.0.0",
|
||||
"npm": ">=6"
|
||||
},
|
||||
"rollup": {
|
||||
"exports": "default"
|
||||
}
|
||||
}
|
37
packages/plugin-bartack/rollup.config.js
Normal file
37
packages/plugin-bartack/rollup.config.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
import resolve from '@rollup/plugin-node-resolve'
|
||||
import commonjs from '@rollup/plugin-commonjs'
|
||||
import json from '@rollup/plugin-json'
|
||||
import { terser } from 'rollup-plugin-terser'
|
||||
import peerDepsExternal from 'rollup-plugin-peer-deps-external'
|
||||
import { name, version, description, author, license, main, module, rollup } from './package.json'
|
||||
|
||||
const output = [
|
||||
{
|
||||
file: main,
|
||||
format: 'cjs',
|
||||
sourcemap: true,
|
||||
exports: rollup.exports
|
||||
}
|
||||
]
|
||||
if (typeof module !== 'undefined')
|
||||
output.push({
|
||||
file: module,
|
||||
format: 'es',
|
||||
sourcemap: true
|
||||
})
|
||||
|
||||
export default {
|
||||
input: 'src/index.js',
|
||||
output,
|
||||
plugins: [
|
||||
peerDepsExternal(),
|
||||
resolve({ modulesOnly: true }),
|
||||
commonjs(),
|
||||
json(),
|
||||
terser({
|
||||
output: {
|
||||
preamble: `/**\n * ${name} | v${version}\n * ${description}\n * (c) ${new Date().getFullYear()} ${author}\n * @license ${license}\n */`
|
||||
}
|
||||
})
|
||||
]
|
||||
}
|
92
packages/plugin-bartack/src/bartack.js
Normal file
92
packages/plugin-bartack/src/bartack.js
Normal file
|
@ -0,0 +1,92 @@
|
|||
const name = (n, so) => `${so.prefix}${n}${so.suffix}`
|
||||
|
||||
const drawBartack = (points, so, self) => {
|
||||
let path = new self.Path().move(points.path1[0])
|
||||
for (let i in points.path1) {
|
||||
if (points.path1[i]) path = path.line(points.path1[i])
|
||||
if (points.path2[i]) path = path.line(points.path2[i])
|
||||
}
|
||||
|
||||
return path
|
||||
}
|
||||
|
||||
const getPoints = (path, so, self) => {
|
||||
let path1 = path.offset(so.width / 2)
|
||||
let path2 = path.offset(so.width / -2)
|
||||
let len1 = path1.length()
|
||||
let len2 = path2.length()
|
||||
|
||||
// Make sure path1 is always the longest one
|
||||
if (len2 > len1) {
|
||||
let tmp = path2
|
||||
path2 = path1
|
||||
path1 = tmp
|
||||
tmp = len2
|
||||
len2 = len1
|
||||
len1 = tmp
|
||||
}
|
||||
|
||||
let points = {
|
||||
path1: [path1.start()],
|
||||
path2: [path2.start()]
|
||||
}
|
||||
let steps = Math.ceil((len1 / so.width) * so.density)
|
||||
for (let i = 1; i < steps; i++) {
|
||||
points.path1.push(path1.shiftFractionAlong((1 / steps) * i))
|
||||
points.path2.push(path2.shiftFractionAlong((1 / steps) * i))
|
||||
}
|
||||
|
||||
return points
|
||||
}
|
||||
|
||||
const bartackPath = (path, so, self) =>
|
||||
path ? drawBartack(getPoints(path, so, self), so, self) : null
|
||||
|
||||
export default function bartack(so, self) {
|
||||
const defaults = {
|
||||
width: 3,
|
||||
length: 15,
|
||||
density: 3,
|
||||
angle: 0,
|
||||
prefix: '',
|
||||
suffix: '',
|
||||
anchor: false,
|
||||
path: false,
|
||||
from: false,
|
||||
to: false,
|
||||
start: 0,
|
||||
end: 1,
|
||||
bartackAlong: false,
|
||||
bartackFractionAlong: false
|
||||
}
|
||||
so = { ...defaults, ...so }
|
||||
|
||||
let guide = false
|
||||
|
||||
if (so.anchor)
|
||||
// Anchor + angle + length
|
||||
guide = new self.Path().move(so.anchor).line(so.anchor.shift(so.angle, so.length))
|
||||
else if (so.from && so.to)
|
||||
// From to
|
||||
guide = new self.Path().move(so.from).line(so.to)
|
||||
else if (so.path) {
|
||||
// Along path
|
||||
let start = false
|
||||
let end = false
|
||||
if (so.bartackAlong) {
|
||||
if (so.start > 0) start = so.path.shiftAlong(so.start)
|
||||
if (end < so.path.length) end = so.path.shiftAlong(so.end)
|
||||
} else if (so.bartackFractionAlong) {
|
||||
if (so.start > 0) start = so.path.shiftFractionAlong(so.start)
|
||||
if (so.end < 1) end = so.path.shiftFractionAlong(so.end)
|
||||
}
|
||||
if (start && end) guide = so.path.split(start).pop().split(end).shift()
|
||||
else if (start) guide = so.path.split(start).pop()
|
||||
else if (end) guide = so.path.split(end).shift()
|
||||
else guide = so.path.clone()
|
||||
}
|
||||
|
||||
self.paths[name('bartack', so)] = bartackPath(guide, so, self).attr('class', 'stroke-sm bartack')
|
||||
|
||||
return true
|
||||
}
|
30
packages/plugin-bartack/src/index.js
Normal file
30
packages/plugin-bartack/src/index.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
import { name, version } from '../package.json'
|
||||
import bartack from './bartack'
|
||||
|
||||
export default {
|
||||
name: name,
|
||||
version: version,
|
||||
hooks: {
|
||||
preRender: function (svg) {
|
||||
if (svg.attributes.get('freesewing:plugin-bartack') === false) {
|
||||
svg.attributes.set('freesewing:plugin-bartack', version)
|
||||
}
|
||||
}
|
||||
},
|
||||
macros: {
|
||||
bartack: function (so) {
|
||||
let self = this
|
||||
return bartack(so, self)
|
||||
},
|
||||
bartackAlong: function (so) {
|
||||
let self = this
|
||||
so.bartackAlong = true
|
||||
return bartack(so, self)
|
||||
},
|
||||
bartackFractionAlong: function (so) {
|
||||
let self = this
|
||||
so.bartackFractionAlong = true
|
||||
return bartack(so, self)
|
||||
}
|
||||
}
|
||||
}
|
14
packages/plugin-bartack/tests/buttons.test.js
Normal file
14
packages/plugin-bartack/tests/buttons.test.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
import freesewing from "freesewing";
|
||||
import { version } from "../package.json";
|
||||
let chai = require("chai");
|
||||
let expect = chai.expect;
|
||||
chai.use(require('chai-string'));
|
||||
let plugin = require("../dist/index.js");
|
||||
|
||||
it("Should set the plugin name:version attribute", () => {
|
||||
let pattern = new freesewing.Pattern();
|
||||
pattern.use(plugin).draft().render();
|
||||
expect(pattern.svg.attributes.get("freesewing:plugin-buttons")).to.equal(
|
||||
version
|
||||
);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue