1
0
Fork 0

tada: Initial commit

This commit is contained in:
Joost De Cock 2019-04-07 17:01:58 +02:00
parent f69ebd81f6
commit e655904396
16 changed files with 4447 additions and 2 deletions

View file

@ -0,0 +1,13 @@
# editorconfig.org
root = true
[*]
indent_size = 2
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false

64
packages/florent/.gitignore vendored Normal file
View file

@ -0,0 +1,64 @@
*.php
cnf.yml
dist
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
# next.js build output
.next

View file

@ -0,0 +1,2 @@
src
.editorconfig

21
packages/florent/LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2018 Joost De Cock
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -1,2 +1,27 @@
# florent
Port of the Floren flat cap pattern to JavaScript
<p align="center">
<a title="Go to freesewing.org" href="https://freesewing.org/"><img src="https://freesewing.org/img/logo/black.svg" align="center" width="150px" alt="Freesewing logo"/></a>
</p>
<h4 align="center"><em>&nbsp;<a title="Go to freesewing.org" href="https://freesewing.org/">freesewing</a></em>
<br><sup>a library for made-to-measure sewing patterns</sup>
</h4>
<p align="center">
<a href="https://www.npmjs.com/package/@freesewing/florent"><img src="https://badgen.net/npm/v/@freesewing/florent" alt="Version"></a>
<a href="https://www.npmjs.com/package/@freesewing/florent"><img src="https://badgen.net/npm/license/@freesewing/florent" alt="License"></a>
<a href="https://deepscan.io/dashboard#view=project&tid=2114&pid=4730&bid=37767"><img src="https://deepscan.io/api/teams/2114/projects/4730/branches/37767/badge/grade.svg" alt="DeepScan grade"></a>
<a href="https://gitter.im/freesewing/freesewing"><img src="https://badgen.net/badge/chat/on%20Gitter/cyan" alt="Chat on Gitter"></a>
<a href="https://freesewing.org/patrons/join"><img src="https://badgen.net/badge/become/a%20Patron/FF5B77" alt="Become a Patron"></a>
</p>
# freesewing / patterns / florent
Florent is a [freesewing](https://github.com/freesewing/freesewing) pattern
for a flat cap.
See [freesewing.org/patterns/florent](https://freesewing.org/patterns/florent)
for more info and examples.
## Install
```
npm i --save @freesewing/florent
```

View file

@ -0,0 +1,24 @@
import { version } from "../package.json";
export default {
name: "florent",
version: version,
measurements: ["headCircumference"],
dependencies: {
side: "top",
brimTop: "brimBottom",
brimInterfacing: "brimBottom"
},
inject: {
side: "top",
brimTop: "brimBottom",
brimInterfacing: "brimBottom"
},
options: {
// Constants
topSide: 0.8,
brim: 0,
// Percentages
headEase: { pct: 2, min: 0, max: 5 }
}
};

View file

@ -0,0 +1,70 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Florent</title>
<style>
.two {
display: inline-block;
max-width: 95%;
margin: auto;
}
</style>
</head>
<body>
<div id="svg"></div>
<div id="svg1" class="two"></div>
<div id="svg2" class="two"></div>
<script type="text/javascript" src="../../freesewing/dist/browser.js"></script>
<script type="text/javascript" src="node_modules/@freesewing/plugin-bundle/dist/browser.js"></script>
<script type="text/javascript" src="dist/browser.js"></script>
<script type="text/javascript" src="node_modules/@freesewing/plugin-theme/dist/browser.js"></script>
<script type="text/javascript" src="node_modules/@freesewing/plugin-designer/dist/browser.js"></script>
<script type="text/javascript" src="node_modules/@freesewing/plugin-debug/dist/browser.js"></script>
<script type="text/javascript" src="../../plugins/plugin-validate/dist/browser.js"></script>
<script type="text/javascript" src="node_modules/@freesewing/plugin-i18n/dist/browser.js"></script>
<script type="text/javascript" src="node_modules/@freesewing/models/dist/browser.js"></script>
<script>
let settings = {
"complete": true,
"idPrefix": "fs-",
"locale": "en",
"options": {
//"hemStyle": "rounded",
},
//"embed": true,
"sa": 10,
"paperless": true,
"measurements": { "headCircumference": 600 },
//only: ["chestPocketBag"]
};
var pattern = new freesewing.patterns.florent(settings);
pattern.use(freesewing.plugins.theme);
//pattern.use(freesewing.plugins.designer);
pattern.use(freesewing.plugins.validate);
pattern.draft();
//pattern.sampleOption("collarFlare");
document.getElementById("svg1").innerHTML = pattern.render();
function pointHover(evt) {
var point = evt.target;
var id = point.id;
var cx = point.getAttribute('x');
var cy = point.getAttribute('y');
var name = point.getAttribute('data-point');
var part = point.getAttribute('data-part');
console.log(name+' ('+cx+', '+cy+') @ '+part);
var scale = 2;
cx = cx-scale*cx;
cy = cy-scale*cy;
point.setAttribute("transform", 'matrix('+scale+', 0, 0, '+scale+', '+cx+', '+cy+')');
pointUnhover(id);
}
function pointUnhover(id) {
setTimeout(function(){
document.getElementById(id).removeAttribute("transform", '');
}, 500);
}
</script>
</body>
</html>

3733
packages/florent/package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,79 @@
{
"version": "0.0.1",
"name": "@freesewing/florent",
"description": "Freesewing pattern for a flat cap",
"author": "Joost De Cock <joost@decock.org> (https://github.com/joostdecock)",
"license": "MIT",
"homepage": "https://github.com/freesewing/florent#readme",
"repository": "github:freesewing/florent",
"bugs": {
"url": "https://github.com/freesewing/florent/issues"
},
"keywords": [
"freesewing",
"pattern",
"cap",
"sewing"
],
"main": "dist/index.js",
"module": "dist/index.mjs",
"unpkg": "dist/browser.js",
"scripts": {
"precommit": "npm run pretty && lint-staged",
"patch": "npm version patch -m ':bookmark: v%s' && npm run build",
"minor": "npm version minor -m ':bookmark: v%s' && npm run build",
"major": "npm version major -m ':bookmark: v%s' && npm run build",
"test": "echo \"Error: no test specified\" && exit 1",
"clean": "rimraf dist",
"pretty": "npx prettier --write 'src/*.js'",
"lint": "eslint --fix 'src/*.js'",
"watch": "nodemon -w src -w config --exec 'rollup -c rollup.js -o dist/browser.js -f iife -m true -n freesewing_patterns_florent --footer \"freesewing.patterns.florent = freesewing_patterns_florent;\"'",
"browserbuild": "rollup -c rollup.js -o dist/browser.js -f iife -m true -n freesewing_patterns_florent --footer 'freesewing.patterns.florent = freesewing_patterns_florent;'",
"nodebuild": "rollup -c rollup.js -o dist/index.js -f cjs -m true",
"modulebuild": "rollup -c rollup.js -o dist/index.mjs -f es -m true",
"build": "npm run clean && npm run browserbuild && npm run nodebuild && npm run modulebuild"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,json}": [
"prettier --write",
"git add"
]
},
"dependencies": {
"@freesewing/plugin-bundle": "0.8.0",
"freesewing": "latest"
},
"devDependencies": {
"@babel/core": "7.4.0",
"@freesewing/antman": "latest",
"@freesewing/models": "latest",
"@freesewing/plugin-debug": "latest",
"@freesewing/plugin-designer": "latest",
"@freesewing/plugin-i18n": "latest",
"@freesewing/plugin-theme": "latest",
"@freesewing/plugin-validate": "latest",
"eslint": "5.15.3",
"eslint-config-prettier": "latest",
"eslint-plugin-prettier": "latest",
"husky": "latest",
"lint-staged": "latest",
"prettier": "latest",
"rimraf": "latest",
"rollup": "1.7.2",
"rollup-plugin-babel": "latest",
"rollup-plugin-babel-minify": "8.0.0",
"rollup-plugin-json": "4.0.0",
"rollup-plugin-node-resolve": "latest"
},
"files": [
"dist/*",
"README.md",
"package-lock.json",
"package.json"
]
}

View file

@ -0,0 +1,33 @@
import babel from "rollup-plugin-babel";
import resolve from "rollup-plugin-node-resolve";
import json from "rollup-plugin-json";
import minify from "rollup-plugin-babel-minify";
import { name, version, description, author, license } from "./package.json";
export default {
input: "src/index.js",
plugins: [
resolve({ browser: true }),
json(),
babel({ exclude: "node_modules/**" }),
minify({
comments: false,
sourceMap: true,
banner: `/**\n * ${name} | v${version}\n * ${description}\n * (c) ${new Date().getFullYear()} ${author}\n * @license ${license}\n */`
})
],
external: [
"freesewing",
"@freesewing/bent",
"@freesewing/plugin-bundle",
"@freesewing/plugin-buttons"
],
output: {
globals: {
freesewing: "freesewing",
"@freesewing/bent": "freesewing.patterns.bent",
"@freesewing/plugin-bundle": "freesewing.plugins.bundle",
"@freesewing/plugin-buttons": "freesewing.plugins.buttons"
}
}
};

View file

@ -0,0 +1,59 @@
export default function(part) {
let {
paperless,
sa,
store,
complete,
points,
options,
macro,
Point,
paths,
Path,
measurements
} = part.shorthand();
let scale = 1;
let base = scale * measurements.headCircumference * (1 + options.headEase);
points.tipRight = new Point(base * 0.147, 0);
points.tipLeft = points.tipRight.flipX();
points.tipRightCp2 = points.tipRight.shift(-115, base * 0.051);
points.tipLeftCp1 = points.tipRightCp2.flipX();
points.tipRightCp1 = points.tipRight.shift(-75, base * 0.195);
points.tipLeftCp2 = points.tipRightCp1.flipX();
points.innerMid = new Point(0, base * 0.13);
points.outerMid = new Point(0, base * 0.226);
points.innerMidCp2 = points.innerMid.shift(180, base * 0.13);
points.innerMidCp1 = points.innerMidCp2.flipX();
points.outerMidCp1 = points.outerMid.shift(180, base * 0.066);
points.outerMidCp2 = points.outerMidCp1.flipX();
store.set(
"brimInnerLength",
new Path()
.move(points.tipRight)
.curve(points.tipRightCp2, points.innerMidCp1, points.innerMid)
.length() * 2
);
paths.seam = new Path()
.move(points.tipLeft)
.curve(points.tipLeftCp2, points.outerMidCp1, points.outerMid)
.curve(points.outerMidCp2, points.tipRightCp1, points.tipRight)
.curve(points.tipRightCp2, points.innerMidCp1, points.innerMid)
.curve(points.innerMidCp2, points.tipLeftCp1, points.tipLeft)
.line(points.tipLeft)
.close()
.attr("class", "fabric");
if (complete) {
if (sa) {
}
if (paperless) {
}
}
return part;
}

View file

@ -0,0 +1,68 @@
export default function(part) {
let {
paperless,
sa,
store,
complete,
points,
options,
macro,
Point,
paths,
Path,
measurements
} = part.shorthand();
paths.hint = paths.seam.clone().attr("class", "dashed stroke-sm");
paths.outset = new Path()
.move(points.tipLeft)
.curve(points.tipLeftCp2, points.outerMidCp1, points.outerMid)
.curve(points.outerMidCp2, points.tipRightCp1, points.tipRight)
.attr("class", "lining");
//.offset(1.5)
points.outsetStart = paths.outset.shiftAlong(5);
points.outsetEnd = paths.outset.reverse().shiftAlong(5);
paths.outset = paths.outset
.split(points.outsetStart)
.pop()
.split(points.outsetEnd)
.shift()
.offset(1.5);
paths.inset = new Path()
.move(points.tipLeft)
.curve(points.tipLeftCp1, points.innerMidCp2, points.innerMid)
.curve(points.innerMidCp1, points.tipRightCp2, points.tipRight)
.attr("class", "various");
//.offset(1.5)
points.insetStart = paths.inset.shiftAlong(5);
points.insetEnd = paths.inset.reverse().shiftAlong(5);
paths.inset = paths.inset
.split(points.insetStart)
.pop()
.split(points.insetEnd)
.shift()
.offset(1.5);
paths.inset.render = false;
paths.outset.render = false;
paths.hint = paths.seam.clone().attr("class", "dashed stroke-sm");
paths.seam = paths.outset
.clone()
.line(paths.inset.end())
.join(paths.inset.reverse())
.line(paths.outset.start())
.close()
.attr("class", "interfacing");
if (complete) {
if (sa) {
}
if (paperless) {
}
}
return part;
}

View file

@ -0,0 +1,40 @@
export default function(part) {
let {
paperless,
sa,
store,
complete,
points,
options,
macro,
Point,
paths,
Path,
measurements
} = part.shorthand();
paths.hint = new Path()
.move(points.tipLeft)
.curve(points.tipLeftCp2, points.outerMidCp1, points.outerMid)
.curve(points.outerMidCp2, points.tipRightCp1, points.tipRight)
.attr("class", "dashed stroke-sm");
paths.seam = paths.hint.offset(3);
paths.seam = paths.seam
.line(points.tipRight)
.curve(points.tipRightCp2, points.innerMidCp1, points.innerMid)
.curve(points.innerMidCp2, points.tipLeftCp1, points.tipLeft)
.line(paths.seam.start())
.close()
.attr("class", "fabric");
if (complete) {
if (sa) {
}
if (paperless) {
}
}
return part;
}

View file

@ -0,0 +1,21 @@
import freesewing from "freesewing";
import plugins from "@freesewing/plugin-bundle";
import config from "../config";
// Parts
import draftTop from "./top";
import draftSide from "./side";
import draftBrimBottom from "./brimbottom";
import draftBrimTop from "./brimtop";
import draftBrimInterfacing from "./briminterfacing";
// Create new design
const Florent = new freesewing.Design(config, plugins);
// Attachdraft methods to prototype
Florent.prototype.draftTop = draftTop;
Florent.prototype.draftSide = draftSide;
Florent.prototype.draftBrimBottom = draftBrimBottom;
Florent.prototype.draftBrimTop = draftBrimTop;
Florent.prototype.draftBrimInterfacing = draftBrimInterfacing;
export default Florent;

View file

@ -0,0 +1,30 @@
export default function(part) {
let {
paperless,
sa,
store,
complete,
points,
options,
macro,
Point,
paths,
Path,
measurements
} = part.shorthand();
// Clean up
delete paths.seam;
paths.side.render = true;
if (complete) {
if (sa) {
}
if (paperless) {
}
}
return part;
}

163
packages/florent/src/top.js Normal file
View file

@ -0,0 +1,163 @@
export default function(part) {
let {
paperless,
sa,
store,
complete,
points,
options,
macro,
Point,
paths,
Path,
measurements
} = part.shorthand();
const fitCap = (part, scale) => {
let {
paperless,
sa,
store,
complete,
points,
options,
macro,
Point,
paths,
Path,
measurements
} = part.shorthand();
let base = scale * measurements.headCircumference * (1 + options.headEase);
// Top
points.midFront = new Point(0, 0);
points.midFrontCp2 = points.midFront.shift(-90, base * 0.074);
points.midMid = points.midFront.shift(0, base * 0.34);
points.midBack = new Point(base * 0.654, base * 0.124);
points.midSide = new Point(base * 0.2525, base * 0.178);
points.midSideCp1 = points.midSide.shift(180, base * 0.185);
points.midSideCp2 = points.midSide.shift(0, base * 0.101);
points.backHollow = new Point(base * 0.488, base * 0.136);
points.backHollowCp1 = points.backHollow.shift(180, base * 0.033);
points.backHollowCp2 = points.backHollow.shift(0, base * 0.033);
points.backEdge = new Point(base * 0.576, base * 0.185);
let angle = points.backEdge.angle(points.midBack) + 90;
points.backSide = points.backEdge.shift(angle, base * 0.025);
points.backSideCp1 = points.backSide.shift(angle, base * 0.02);
points.midMidCp1 = points.midMid.shift(0, base * 0.1);
points.midBackCp2 = points.midBack.shift(angle, base * 0.09);
// Side
points.foldTop = new Point(0, 0);
points.foldTopCp1 = points.foldTop.shift(-90, base * 0.0433);
points.foldBottom = points.foldTop.shift(0, base * 0.126);
points.foldBottomCp2 = points.foldBottom.shift(-90, base * 0.0866);
points.tip = new Point(base * 0.411, base * 0.207);
points.tipCp1 = points.tip.shift(-85, base * 0.1);
points.tipCp2 = points.tip.shift(177, base * 0.067);
points.outerTop = new Point(base * 0.328, base * 0.337);
points.outerTopCp1 = points.outerTop.shift(180, base * 0.05);
points.outerTopCp2 = points.outerTop.shift(0, base * 0.05);
points.outerGuide = new Point(base * 0.0867, base * 0.1913);
points.outerGuideCp1 = points.outerGuide.shift(135, base * 0.076);
points.outerGuideCp2 = points.outerGuide.shift(-45, base * 0.145);
points.innerGuide = new Point(base * 0.22, base * 0.172);
points.innerGuideCp1 = points.innerGuide.shift(-38, base * 0.052);
points.innerGuideCp2 = points.innerGuide.shift(142, base * 0.035);
let backLength = points.backEdge.dist(points.midBack) * 2;
let sideLength =
new Path()
.move(points.tip)
.curve(points.tipCp2, points.innerGuideCp1, points.innerGuide)
.curve(points.innerGuideCp2, points.foldBottomCp2, points.foldBottom)
.length() * 2;
// Return delta between target and actual seam length
return (
measurements.headCircumference * (1 + options.headEase) -
(backLength + sideLength)
);
};
const sideSeamDelta = part => {
let { Path } = part.shorthand();
let top = new Path()
.move(points.midFront)
.curve(points.midFrontCp2, points.midSideCp1, points.midSide)
.curve(points.midSideCp2, points.backHollowCp1, points.backHollow)
.curve(points.backHollowCp2, points.backSideCp1, points.backSide)
.line(points.backEdge)
.length();
let side = new Path()
.move(points.foldTop)
.curve(points.foldTopCp1, points.outerGuideCp1, points.outerGuide)
.curve(points.outerGuideCp2, points.outerTopCp1, points.outerTop)
.curve(points.outerTopCp2, points.tipCp1, points.tip)
.length();
return top - side;
};
// Fit head
let scale = 1;
let count = 1;
let delta = fitCap(part, scale);
while (Math.abs(delta) > 1 && count < 25) {
count++;
if (delta > 0) scale = 1000 / (1000 - delta);
// Too small
else scale = 1000 / (1000 + delta); // Too large
delta = fitCap(part, scale);
}
// Match side seam
delta = sideSeamDelta(part);
count = 1;
let top = ["outerTop", "outerTopCp1", "outerTopCp2"];
let guide = ["outerGuide", "outerGuideCp1", "outerGuideCp2"];
while (Math.abs(delta) > 1 && count < 25) {
for (let i of top) points[i] = points[i].shift(-90, delta / 3);
for (let i of guide) points[i] = points[i].shift(-135, delta / 3);
delta = sideSeamDelta(part);
count++;
}
// Paths
paths.seam = new Path()
.move(points.midMid)
.line(points.midFront)
.curve(points.midFrontCp2, points.midSideCp1, points.midSide)
.curve(points.midSideCp2, points.backHollowCp1, points.backHollow)
.curve(points.backHollowCp2, points.backSideCp1, points.backSide)
.line(points.backEdge)
.line(points.midBack)
.curve(points.midBackCp2, points.midMidCp1, points.midMid)
.close()
.attr("class", "fabric");
paths.side = new Path()
.move(points.foldTop)
.curve(points.foldTopCp1, points.outerGuideCp1, points.outerGuide)
.curve(points.outerGuideCp2, points.outerTopCp1, points.outerTop)
.curve(points.outerTopCp2, points.tipCp1, points.tip)
.curve(points.tipCp2, points.innerGuideCp1, points.innerGuide)
.curve(points.innerGuideCp2, points.foldBottomCp2, points.foldBottom)
.attr("class", "fabric");
// Uncomment to see the side part here
paths.side.render = false;
if (complete) {
if (sa) {
}
if (paperless) {
}
}
return part;
}