1
0
Fork 0

tada: Initial commit

This commit is contained in:
Joost De Cock 2018-08-20 14:00:26 +02:00
parent 33bb527722
commit 47fb5b128b
11 changed files with 5121 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

62
packages/plugin-scalebox/.gitignore vendored Normal file
View file

@ -0,0 +1,62 @@
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,4 @@
src
.editorconfig
.babelrc
webpack.config.js

View file

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2018 freesewing
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

View file

@ -1 +1,90 @@
# plugin-scalebox
<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>
# plugin-scalebox
A freesewing plugin to add a scalebox to your pattern.
## Usage
To load this plugin, add it to your instantiated pattern.
On node.js:
```js
import freesewing from 'freesewing'
import scalebox from '@freesewing/plugin-scalebox'
let pattern = new freesewing.Pattern()
.with(scalebox);
```
In the browser, this plugin will register as `freesewing.plugins.scalebox`:
```html
<script type="text/javascript" src="https://unpkg.com/freesewing"></script>
<script type="text/javascript" src="https://unpkg.com/@freesewing/plugin-scalebox"></script>
<script>
var pattern = new freesewing.Patter()
.with(freesewing.plugins.scalebox);
</script>
```
You can now use the **scalebox** macro as such:
```js
macro('scalebox', {
at: new Point(0,0),
lead: 'This is the lead',
title: 'This is the title',
text: "And this is the text\nwhich has room for a few lines should you\nfeel so inclined"
});
```
## Configuration
The macro configuration object takes the following properties:
Name | Description | Default
---------|---------------------------------------------|-------------------
`at` | A Point object to anchor the scalebox on |
`lead` | The lead text | freesewing
`title` | The lead text | pattern name & version
`text` | The lead text | *See example below*
## Example
This plugin provides the **scalebox** macro that inserts a scalebox like this:
![Example of the scalebox inserted by this plugin](https://github.com/freesewing/plugin-scalebox/raw/master/img/example.png)
These are the default values. The example under Usage above would render like this:
![Example of the scalebox inserted by this plugin](https://github.com/freesewing/plugin-scalebox/raw/master/img/custom.png)
## Install
To install, run:
```sh
npm install @freesewing/plugin-scalebox
```
## Build
To build this plugin, run:
```sh
npm run build
```
## License: MIT
See [the license file](https://github.com/freesewing/plugin-theme/blob/master/LICENSE)
for details.

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

4783
packages/plugin-scalebox/package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,70 @@
{
"name": "@freesewing/plugin-scalebox",
"version": "0.0.1",
"description": "A freesewing plugin to add a scalebox to your pattern",
"author": "Joost De Cock <joost@decock.org> (https://github.com/joostdecock)",
"license": "MIT",
"homepage": "https://github.com/freesewing/plugin-scalebox#readme",
"repository": "github:freesewing/plugin-scalebox",
"bugs": {
"url": "https://github.com/freesewing/plugin-scalebox/issues"
},
"keywords": [
"freesewing",
"plugin",
"sewing",
"patterns",
"scale"
],
"main": "dist/index.js",
"unpkg": "dist/browser.js",
"module": "dist/index.mjs",
"scripts": {
"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",
"precommit": "npm run pretty && lint-staged",
"test": "echo 'Error: no test specified' && exit 1",
"clean": "rimraf dist",
"pretty": "npx prettier --write 'src/*.js'",
"lint": "eslint --fix 'src/*.js'",
"browserbuild": "rollup -c rollup.js --file dist/browser.js --format iife --name freesewing.plugins.scalebox",
"nodebuild": "rollup -c rollup.js --file dist/index.js --format cjs",
"modulebuild": "rollup -c rollup.js --file dist/index.mjs --format es",
"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"
]
},
"devDependencies": {
"babel-core": "^6.26.3",
"babel-eslint": "^8.2.6",
"eslint": "^5.2.0",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-prettier": "^2.6.2",
"husky": "^0.14.3",
"lint-staged": "^7.2.0",
"prettier": "^1.13.7",
"rimraf": "^2.6.2",
"rollup-plugin-babel": "^3.0.7",
"rollup-plugin-commonjs": "^9.1.3",
"rollup-plugin-filesize": "^4.0.1",
"rollup-plugin-json": "^3.0.0",
"rollup-plugin-node-resolve": "^3.3.0",
"rollup-plugin-terser": "^1.0.1"
},
"files": [
"dist/*",
"README.md",
"package-lock.json",
"package.json"
]
}

View file

@ -0,0 +1,23 @@
import { terser } from "rollup-plugin-terser";
import babel from "rollup-plugin-babel";
import resolve from "rollup-plugin-node-resolve";
import json from "rollup-plugin-json";
import { version, name, description, author, license } from "./package.json";
export default {
input: "src/index.js",
plugins: [
resolve({
browser: true
}),
json(),
babel({
exclude: "node_modules/**"
}),
terser({
output: {
preamble: `/**\n * ${name} | v${version}\n * ${description}\n * (c) ${new Date().getFullYear()} ${author}\n * @license ${license}\n */`
}
})
]
};

View file

@ -0,0 +1,75 @@
import { version, name } from "../package.json";
export default {
name: name,
version: version,
hooks: {
preRender: function(next) {
this.attributes.add("freesewing:plugin-scalebox", version);
next();
}
},
macros: {
scalebox: function(so) {
// Boxes
this.points.__scaleboxMetricTopLeft = new this.Point(so.at.x - 50, so.at.y - 25);
this.points.__scaleboxMetricTopRight = new this.Point(so.at.x + 50, so.at.y - 25);
this.points.__scaleboxMetricBottomLeft = new this.Point(so.at.x - 50, so.at.y + 25);
this.points.__scaleboxMetricBottomRight = new this.Point(so.at.x + 50, so.at.y + 25);
this.points.__scaleboxImperialTopLeft = new this.Point(so.at.x - 50.8, so.at.y - 25.4);
this.points.__scaleboxImperialTopRight = new this.Point(so.at.x + 50.8, so.at.y - 25.4);
this.points.__scaleboxImperialBottomLeft = new this.Point(so.at.x - 50.8, so.at.y + 25.4);
this.points.__scaleboxImperialBottomRight = new this.Point(so.at.x + 50.8, so.at.y + 25.4);
this.paths.__scaleboxImperial = new this.Path()
.move(this.points.__scaleboxImperialTopLeft)
.line(this.points.__scaleboxImperialBottomLeft)
.line(this.points.__scaleboxImperialBottomRight)
.line(this.points.__scaleboxImperialTopRight)
.close()
.attr('style', 'fill: #000; stroke: none;');
this.paths.__scaleboxMetric = new this.Path()
.move(this.points.__scaleboxMetricTopLeft)
.line(this.points.__scaleboxMetricBottomLeft)
.line(this.points.__scaleboxMetricBottomRight)
.line(this.points.__scaleboxMetricTopRight)
.close()
.attr('style', 'fill: #FFF; stroke: none;');
// Lead
this.points.__scaleboxLead = new this.Point(so.at.x - 45, so.at.y - 15)
.attr('data-text', so.lead || 'freesewing')
.attr('data-text-class', 'text-sm');
// Title
this.points.__scaleboxTitle = this.points.__scaleboxLead.shift(-90, 10)
.attr(
"data-text",
so.title || this.context.config.name + " v" + this.context.config.version
)
.attr('data-text-class', 'text-lg');
// Text
this.points.__scaleboxText = this.points.__scaleboxTitle.shift(-90, 8);
if(typeof so.text === 'string') {
this.points.__scaleboxText.attr('data-text', so.text);
} else {
this.points.__scaleboxText
.attr("data-text", "Freesewing is made by Joost De Cock & contributors")
.attr('data-text', "\n")
.attr('data-text', "with the financial support of our Patrons")
this.points.__scaleboxLink = this.points.__scaleboxText.shift(-90, 8)
.attr('data-text', "freesewing.org/patrons/join")
.attr('data-text-class', 'text-xs fill-note');
}
this.points.__scaleboxText
.attr('data-text-class', 'text-xs')
.attr('data-text-lineheight', 4);
// Instructions
this.points.__scaleboxMetric = new this.Point(so.at.x, so.at.y + 20)
.attr('data-text', 'The (white) inside of this box should measure')
.attr('data-text', '10cm x 5cm')
.attr('data-text-class', 'text-xs center');
this.points.__scaleboxImperial = new this.Point(so.at.x, so.at.y + 24)
.attr('data-text', 'The (black) outside of this box should measure')
.attr('data-text', '4" x 2"')
.attr('data-text-class', 'text-xs center ');
}
}
};