Merge branch 'master' of github.com:freesewing/plugin-bundle
This commit is contained in:
parent
23f1dd5e97
commit
4d931d78d5
12 changed files with 4711 additions and 430 deletions
|
@ -1,3 +1,10 @@
|
|||
{
|
||||
"plugins": ["transform-object-rest-spread"]
|
||||
"presets": [
|
||||
[
|
||||
"@babel/preset-env",
|
||||
{
|
||||
"useBuiltIns": "entry"
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
|
|
9
packages/plugin-bundle/.travis.yml
Normal file
9
packages/plugin-bundle/.travis.yml
Normal file
|
@ -0,0 +1,9 @@
|
|||
language: node_js
|
||||
node_js:
|
||||
- "node"
|
||||
install:
|
||||
- npm install
|
||||
- npm run build
|
||||
script:
|
||||
- npm run test
|
||||
- npm run coverage
|
|
@ -5,8 +5,11 @@
|
|||
<br><sup>a library for made-to-measure sewing patterns</sup>
|
||||
</h4>
|
||||
<p align="center">
|
||||
<a href="https://travis-ci.org/freesewing/plugin-bundle"><img src="https://badgen.net/travis/freesewing/plugin-bundle/master" alt="Travis build"></a>
|
||||
<a href="https://www.npmjs.com/package/@freesewing/plugin-bundle"><img src="https://badgen.net/npm/v/@freesewing/plugin-bundle" alt="Version"></a>
|
||||
<a href="https://www.npmjs.com/package/@freesewing/plugin-bundle"><img src="https://badgen.net/npm/license/@freesewing/plugin-bundle" alt="License"></a>
|
||||
<a href="https://codecov.io/gh/freesewing/plugin-bundle"><img src="https://badgen.net/codecov/c/github/freesewing/plugin-bundle/master" alt="Code coverage"></a>
|
||||
<a href="https://deepscan.io/dashboard#view=project&pid=3253&bid=27563"><img src="https://deepscan.io/api/projects/3253/branches/27563/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>
|
||||
|
|
4477
packages/plugin-bundle/package-lock.json
generated
4477
packages/plugin-bundle/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -24,7 +24,9 @@
|
|||
"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",
|
||||
"test": "nyc mocha --require @babel/register tests/*.test.js",
|
||||
"report": "nyc report --reporter=html mocha --require @babel/register tests/*.test.js",
|
||||
"coverage": "nyc npm test && nyc report --reporter=text-lcov > coverage.lcov && ./node_modules/.bin/codecov",
|
||||
"clean": "rimraf dist",
|
||||
"pretty": "npx prettier --write \"src/*.js\"",
|
||||
"lint": "eslint --fix \"src/*.js\"",
|
||||
|
@ -45,23 +47,35 @@
|
|||
"git add"
|
||||
]
|
||||
},
|
||||
"nyc": {
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"tests"
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.1.0",
|
||||
"@babel/preset-env": "^7.1.0",
|
||||
"@babel/register": "^7.0.0",
|
||||
"@babel/plugin-proposal-object-rest-spread": "7.0.0-beta.56",
|
||||
"babel-core": "^6.26.3",
|
||||
"babel-eslint": "^8.2.6",
|
||||
"babel-plugin-transform-object-rest-spread": "^6.26.0",
|
||||
"eslint": "5.4.0",
|
||||
"eslint-config-prettier": "2.10.0",
|
||||
"chai": "^4.1.2",
|
||||
"chai-string": "1.4.0",
|
||||
"codecov": "^3.1.0",
|
||||
"eslint": "^5.2.0",
|
||||
"eslint-config-prettier": "^2.9.0",
|
||||
"eslint-plugin-prettier": "^2.6.2",
|
||||
"freesewing": "^0.18.3",
|
||||
"husky": "^0.14.3",
|
||||
"lint-staged": "7.2.2",
|
||||
"prettier": "1.14.2",
|
||||
"lint-staged": "^7.2.0",
|
||||
"mocha": "^5.2.0",
|
||||
"nyc": "12.0.2",
|
||||
"prettier": "^1.13.7",
|
||||
"rimraf": "^2.6.2",
|
||||
"rollup-plugin-babel": "^3.0.7",
|
||||
"rollup-plugin-commonjs": "9.1.5",
|
||||
"rollup": "^0.66.2",
|
||||
"rollup-plugin-babel": "^4.0.3",
|
||||
"rollup-plugin-filesize": "^4.0.1",
|
||||
"rollup-plugin-json": "^3.0.0",
|
||||
"rollup-plugin-node-resolve": "3.3.0",
|
||||
"rollup-plugin-node-resolve": "^3.3.0",
|
||||
"rollup-plugin-terser": "^1.0.1"
|
||||
},
|
||||
"files": [
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { terser } from "rollup-plugin-terser";
|
||||
import babel from "rollup-plugin-babel";
|
||||
import resolve from "rollup-plugin-node-resolve";
|
||||
import commonjs from "rollup-plugin-commonjs";
|
||||
import json from "rollup-plugin-json";
|
||||
import { version, name, description, author, license } from "./package.json";
|
||||
|
||||
|
@ -12,7 +11,6 @@ export default {
|
|||
browser: true
|
||||
}),
|
||||
json(),
|
||||
commonjs(),
|
||||
babel({
|
||||
exclude: "node_modules/**"
|
||||
}),
|
||||
|
|
21
packages/plugin-bundle/tests/bundle.test.js
Normal file
21
packages/plugin-bundle/tests/bundle.test.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
import freesewing from "freesewing";
|
||||
let expect = require("chai").expect;
|
||||
let plugin = require("../dist/index.js");
|
||||
let bundle = [
|
||||
"cutonfold",
|
||||
"dimension",
|
||||
"grainline",
|
||||
"logo",
|
||||
"title",
|
||||
"scalebox"
|
||||
];
|
||||
|
||||
it("Should set the plugins name:version attribute", () => {
|
||||
let pattern = new freesewing.Pattern().with(plugin);
|
||||
pattern.render();
|
||||
for (let plug of bundle) {
|
||||
expect(
|
||||
typeof pattern.svg.attributes.get("freesewing:plugin-" + plug)
|
||||
).to.equal("string");
|
||||
}
|
||||
});
|
61
packages/plugin-bundle/tests/cutonfold.test.js
Normal file
61
packages/plugin-bundle/tests/cutonfold.test.js
Normal file
|
@ -0,0 +1,61 @@
|
|||
import freesewing from "freesewing";
|
||||
import { version } from "../node_modules/@freesewing/plugin-cutonfold/package.json";
|
||||
let expect = require("chai").expect;
|
||||
let plugin = require("../dist/index.js");
|
||||
|
||||
it("Should set the plugin name:version attribute", () => {
|
||||
let pattern = new freesewing.Pattern().with(plugin);
|
||||
pattern.render();
|
||||
expect(pattern.svg.attributes.get("freesewing:plugin-cutonfold")).to.equal(
|
||||
version
|
||||
);
|
||||
});
|
||||
|
||||
it("Should run the default cutonfold macro", () => {
|
||||
let pattern = new freesewing.Pattern();
|
||||
pattern.draft = function() {};
|
||||
pattern.with(plugin);
|
||||
pattern.parts.test = new pattern.Part();
|
||||
pattern.parts.test.points.from = new pattern.Point(10, 20);
|
||||
pattern.parts.test.points.to = new pattern.Point(10, 230);
|
||||
let { macro } = pattern.parts.test.shorthand();
|
||||
macro("cutonfold", {
|
||||
from: pattern.parts.test.points.from,
|
||||
to: pattern.parts.test.points.to
|
||||
});
|
||||
let c = pattern.parts.test.paths.cutonfold;
|
||||
expect(c.attributes.get("class")).to.equal("note");
|
||||
expect(c.attributes.get("marker-start")).to.equal("url(#cutonfoldFrom)");
|
||||
expect(c.attributes.get("marker-end")).to.equal("url(#cutonfoldTo)");
|
||||
expect(c.attributes.get("data-text")).to.equal("cutOnFold");
|
||||
expect(c.attributes.get("data-text-class")).to.equal("center fill-note");
|
||||
expect(c.ops[0].type).to.equal("move");
|
||||
expect(c.ops[1].type).to.equal("line");
|
||||
expect(c.ops[2].type).to.equal("line");
|
||||
expect(c.ops[3].type).to.equal("line");
|
||||
expect(c.ops[0].to.x).to.equal(10);
|
||||
expect(c.ops[0].to.y).to.equal(200);
|
||||
expect(c.ops[1].to.x).to.equal(30);
|
||||
expect(c.ops[1].to.y).to.equal(200);
|
||||
expect(c.ops[2].to.x).to.equal(30);
|
||||
expect(c.ops[2].to.y).to.equal(50);
|
||||
expect(c.ops[3].to.x).to.equal(10);
|
||||
expect(c.ops[3].to.y).to.equal(50);
|
||||
});
|
||||
|
||||
it("Should run the cutonfold/grainline macro", () => {
|
||||
let pattern = new freesewing.Pattern();
|
||||
pattern.draft = function() {};
|
||||
pattern.with(plugin);
|
||||
pattern.parts.test = new pattern.Part();
|
||||
pattern.parts.test.points.from = new pattern.Point(10, 20);
|
||||
pattern.parts.test.points.to = new pattern.Point(10, 230);
|
||||
let { macro } = pattern.parts.test.shorthand();
|
||||
macro("cutonfold", {
|
||||
from: pattern.parts.test.points.from,
|
||||
to: pattern.parts.test.points.to,
|
||||
grainline: true
|
||||
});
|
||||
let c = pattern.parts.test.paths.cutonfold;
|
||||
expect(c.attributes.get("data-text")).to.equal("cutOnFoldAndGrainline");
|
||||
});
|
185
packages/plugin-bundle/tests/dimension.test.js
Normal file
185
packages/plugin-bundle/tests/dimension.test.js
Normal file
|
@ -0,0 +1,185 @@
|
|||
import freesewing from "freesewing";
|
||||
import { version } from "../node_modules/@freesewing/plugin-dimension/package.json";
|
||||
let expect = require("chai").expect;
|
||||
let plugin = require("../dist/index.js");
|
||||
|
||||
it("Should set the plugin name:version attribute", () => {
|
||||
let pattern = new freesewing.Pattern().with(plugin);
|
||||
pattern.render();
|
||||
expect(pattern.svg.attributes.get("freesewing:plugin-dimension")).to.equal(
|
||||
version
|
||||
);
|
||||
});
|
||||
|
||||
it("Should run the hd macro", () => {
|
||||
let pattern = new freesewing.Pattern();
|
||||
pattern.draft = function() {};
|
||||
pattern.with(plugin);
|
||||
pattern.parts.test = new pattern.Part();
|
||||
pattern.parts.test.points.from = new pattern.Point(10, 20);
|
||||
pattern.parts.test.points.to = new pattern.Point(200, 20);
|
||||
let { macro } = pattern.parts.test.shorthand();
|
||||
macro("hd", {
|
||||
from: pattern.parts.test.points.from,
|
||||
to: pattern.parts.test.points.to,
|
||||
y: 35
|
||||
});
|
||||
let c = pattern.parts.test.paths[1];
|
||||
expect(c.attributes.get("class")).to.equal("mark");
|
||||
expect(c.attributes.get("marker-start")).to.equal("url(#dimensionFrom)");
|
||||
expect(c.attributes.get("marker-end")).to.equal("url(#dimensionTo)");
|
||||
expect(c.attributes.get("data-text")).to.equal("19cm");
|
||||
expect(c.attributes.get("data-text-class")).to.equal("fill-mark center");
|
||||
expect(c.ops[0].type).to.equal("move");
|
||||
expect(c.ops[1].type).to.equal("line");
|
||||
expect(c.ops[0].to.x).to.equal(10);
|
||||
expect(c.ops[0].to.y).to.equal(35);
|
||||
expect(c.ops[1].to.x).to.equal(200);
|
||||
expect(c.ops[1].to.y).to.equal(35);
|
||||
c = pattern.parts.test.paths["1_ls"];
|
||||
expect(c.attributes.get("class")).to.equal("mark dotted");
|
||||
expect(c.ops[0].type).to.equal("move");
|
||||
expect(c.ops[1].type).to.equal("line");
|
||||
expect(c.ops[0].to.x).to.equal(10);
|
||||
expect(c.ops[0].to.y).to.equal(20);
|
||||
expect(c.ops[1].to.x).to.equal(10);
|
||||
expect(c.ops[1].to.y).to.equal(35);
|
||||
c = pattern.parts.test.paths["1_le"];
|
||||
expect(c.attributes.get("class")).to.equal("mark dotted");
|
||||
expect(c.ops[0].type).to.equal("move");
|
||||
expect(c.ops[1].type).to.equal("line");
|
||||
expect(c.ops[0].to.x).to.equal(200);
|
||||
expect(c.ops[0].to.y).to.equal(20);
|
||||
expect(c.ops[1].to.x).to.equal(200);
|
||||
expect(c.ops[1].to.y).to.equal(35);
|
||||
});
|
||||
|
||||
it("Should run the vd macro", () => {
|
||||
let pattern = new freesewing.Pattern();
|
||||
pattern.draft = function() {};
|
||||
pattern.with(plugin);
|
||||
pattern.parts.test = new pattern.Part();
|
||||
pattern.parts.test.points.from = new pattern.Point(10, 20);
|
||||
pattern.parts.test.points.to = new pattern.Point(10, 200);
|
||||
let { macro } = pattern.parts.test.shorthand();
|
||||
macro("vd", {
|
||||
from: pattern.parts.test.points.from,
|
||||
to: pattern.parts.test.points.to,
|
||||
x: 25
|
||||
});
|
||||
let c = pattern.parts.test.paths[1];
|
||||
expect(c.attributes.get("class")).to.equal("mark");
|
||||
expect(c.attributes.get("marker-start")).to.equal("url(#dimensionFrom)");
|
||||
expect(c.attributes.get("marker-end")).to.equal("url(#dimensionTo)");
|
||||
expect(c.attributes.get("data-text")).to.equal("18cm");
|
||||
expect(c.attributes.get("data-text-class")).to.equal("fill-mark center");
|
||||
expect(c.ops[0].type).to.equal("move");
|
||||
expect(c.ops[1].type).to.equal("line");
|
||||
expect(c.ops[0].to.x).to.equal(25);
|
||||
expect(c.ops[0].to.y).to.equal(20);
|
||||
expect(c.ops[1].to.x).to.equal(25);
|
||||
expect(c.ops[1].to.y).to.equal(200);
|
||||
c = pattern.parts.test.paths["1_ls"];
|
||||
expect(c.attributes.get("class")).to.equal("mark dotted");
|
||||
expect(c.ops[0].type).to.equal("move");
|
||||
expect(c.ops[1].type).to.equal("line");
|
||||
expect(c.ops[0].to.x).to.equal(10);
|
||||
expect(c.ops[0].to.y).to.equal(20);
|
||||
expect(c.ops[1].to.x).to.equal(25);
|
||||
expect(c.ops[1].to.y).to.equal(20);
|
||||
c = pattern.parts.test.paths["1_le"];
|
||||
expect(c.attributes.get("class")).to.equal("mark dotted");
|
||||
expect(c.ops[0].type).to.equal("move");
|
||||
expect(c.ops[1].type).to.equal("line");
|
||||
expect(c.ops[0].to.x).to.equal(10);
|
||||
expect(c.ops[0].to.y).to.equal(200);
|
||||
expect(c.ops[1].to.x).to.equal(25);
|
||||
expect(c.ops[1].to.y).to.equal(200);
|
||||
});
|
||||
|
||||
it("Should run the ld macro", () => {
|
||||
let pattern = new freesewing.Pattern();
|
||||
pattern.draft = function() {};
|
||||
pattern.with(plugin);
|
||||
pattern.parts.test = new pattern.Part();
|
||||
pattern.parts.test.points.from = new pattern.Point(10, 10);
|
||||
pattern.parts.test.points.to = new pattern.Point(100, 100);
|
||||
let { macro } = pattern.parts.test.shorthand();
|
||||
macro("ld", {
|
||||
from: pattern.parts.test.points.from,
|
||||
to: pattern.parts.test.points.to,
|
||||
d: 15
|
||||
});
|
||||
let c = pattern.parts.test.paths[1];
|
||||
expect(c.attributes.get("class")).to.equal("mark");
|
||||
expect(c.attributes.get("marker-start")).to.equal("url(#dimensionFrom)");
|
||||
expect(c.attributes.get("marker-end")).to.equal("url(#dimensionTo)");
|
||||
expect(c.attributes.get("data-text")).to.equal("12.73cm");
|
||||
expect(c.attributes.get("data-text-class")).to.equal("fill-mark center");
|
||||
expect(c.ops[0].type).to.equal("move");
|
||||
expect(c.ops[1].type).to.equal("line");
|
||||
expect(c.ops[0].to.x).to.equal(20.61);
|
||||
expect(c.ops[0].to.y).to.equal(-0.61);
|
||||
expect(c.ops[1].to.x).to.equal(110.61);
|
||||
expect(c.ops[1].to.y).to.equal(89.39);
|
||||
c = pattern.parts.test.paths["1_ls"];
|
||||
expect(c.attributes.get("class")).to.equal("mark dotted");
|
||||
expect(c.ops[0].type).to.equal("move");
|
||||
expect(c.ops[1].type).to.equal("line");
|
||||
expect(c.ops[0].to.x).to.equal(10);
|
||||
expect(c.ops[0].to.y).to.equal(10);
|
||||
expect(c.ops[1].to.x).to.equal(20.61);
|
||||
expect(c.ops[1].to.y).to.equal(-0.61);
|
||||
c = pattern.parts.test.paths["1_le"];
|
||||
expect(c.attributes.get("class")).to.equal("mark dotted");
|
||||
expect(c.ops[0].type).to.equal("move");
|
||||
expect(c.ops[1].type).to.equal("line");
|
||||
expect(c.ops[0].to.x).to.equal(100);
|
||||
expect(c.ops[0].to.y).to.equal(100);
|
||||
expect(c.ops[1].to.x).to.equal(110.61);
|
||||
expect(c.ops[1].to.y).to.equal(89.39);
|
||||
});
|
||||
|
||||
it("Should run the pd macro", () => {
|
||||
let pattern = new freesewing.Pattern();
|
||||
pattern.draft = function() {};
|
||||
pattern.with(plugin);
|
||||
pattern.parts.test = new pattern.Part();
|
||||
let from = new pattern.Point(10, 10);
|
||||
let cp1 = new pattern.Point(100, 10);
|
||||
let cp2 = new pattern.Point(10, 100);
|
||||
let to = new pattern.Point(100, 100);
|
||||
let { macro } = pattern.parts.test.shorthand();
|
||||
macro("pd", {
|
||||
path: new pattern.Path().move(from).curve(cp1, cp2, to),
|
||||
d: 15
|
||||
});
|
||||
let c = pattern.parts.test.paths[1];
|
||||
expect(c.attributes.get("class")).to.equal("mark");
|
||||
expect(c.attributes.get("marker-start")).to.equal("url(#dimensionFrom)");
|
||||
expect(c.attributes.get("marker-end")).to.equal("url(#dimensionTo)");
|
||||
expect(c.attributes.get("data-text")).to.equal("15.09cm");
|
||||
expect(c.attributes.get("data-text-class")).to.equal("fill-mark center");
|
||||
expect(c.ops[0].type).to.equal("move");
|
||||
expect(c.ops[1].type).to.equal("curve");
|
||||
expect(c.ops[0].to.x).to.equal(10);
|
||||
expect(c.ops[0].to.y).to.equal(25);
|
||||
expect(c.ops[1].to.x).to.equal(37.15);
|
||||
expect(c.ops[1].to.y).to.equal(32.79);
|
||||
c = pattern.parts.test.paths["1_ls"];
|
||||
expect(c.attributes.get("class")).to.equal("mark dotted");
|
||||
expect(c.ops[0].type).to.equal("move");
|
||||
expect(c.ops[1].type).to.equal("line");
|
||||
expect(c.ops[0].to.x).to.equal(10);
|
||||
expect(c.ops[0].to.y).to.equal(10);
|
||||
expect(c.ops[1].to.x).to.equal(10);
|
||||
expect(c.ops[1].to.y).to.equal(25);
|
||||
c = pattern.parts.test.paths["1_le"];
|
||||
expect(c.attributes.get("class")).to.equal("mark dotted");
|
||||
expect(c.ops[0].type).to.equal("move");
|
||||
expect(c.ops[1].type).to.equal("line");
|
||||
expect(c.ops[0].to.x).to.equal(100);
|
||||
expect(c.ops[0].to.y).to.equal(100);
|
||||
expect(c.ops[1].to.x).to.equal(100);
|
||||
expect(c.ops[1].to.y).to.equal(115);
|
||||
});
|
38
packages/plugin-bundle/tests/grainline.test.js
Normal file
38
packages/plugin-bundle/tests/grainline.test.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
import freesewing from "freesewing";
|
||||
import { version } from "../node_modules/@freesewing/plugin-grainline/package.json";
|
||||
let expect = require("chai").expect;
|
||||
let plugin = require("../dist/index.js");
|
||||
|
||||
it("Should set the plugin name:version attribute", () => {
|
||||
let pattern = new freesewing.Pattern().with(plugin);
|
||||
pattern.render();
|
||||
expect(pattern.svg.attributes.get("freesewing:plugin-grainline")).to.equal(
|
||||
version
|
||||
);
|
||||
});
|
||||
|
||||
it("Should run the default grainline macro", () => {
|
||||
let pattern = new freesewing.Pattern();
|
||||
pattern.draft = function() {};
|
||||
pattern.with(plugin);
|
||||
pattern.parts.test = new pattern.Part();
|
||||
pattern.parts.test.points.from = new pattern.Point(10, 20);
|
||||
pattern.parts.test.points.to = new pattern.Point(10, 230);
|
||||
let { macro } = pattern.parts.test.shorthand();
|
||||
macro("grainline", {
|
||||
from: pattern.parts.test.points.from,
|
||||
to: pattern.parts.test.points.to
|
||||
});
|
||||
let c = pattern.parts.test.paths.grainline;
|
||||
expect(c.attributes.get("class")).to.equal("note");
|
||||
expect(c.attributes.get("marker-start")).to.equal("url(#grainlineFrom)");
|
||||
expect(c.attributes.get("marker-end")).to.equal("url(#grainlineTo)");
|
||||
expect(c.attributes.get("data-text")).to.equal("grainline");
|
||||
expect(c.attributes.get("data-text-class")).to.equal("center fill-note");
|
||||
expect(c.ops[0].type).to.equal("move");
|
||||
expect(c.ops[1].type).to.equal("line");
|
||||
expect(c.ops[0].to.x).to.equal(10);
|
||||
expect(c.ops[0].to.y).to.equal(30.5);
|
||||
expect(c.ops[1].to.x).to.equal(10);
|
||||
expect(c.ops[1].to.y).to.equal(219.5);
|
||||
});
|
184
packages/plugin-bundle/tests/scalebox.test.js
Normal file
184
packages/plugin-bundle/tests/scalebox.test.js
Normal file
|
@ -0,0 +1,184 @@
|
|||
import freesewing from "freesewing";
|
||||
import { version } from "../node_modules/@freesewing/plugin-scalebox/package.json";
|
||||
let expect = require("chai").expect;
|
||||
let plugin = require("../dist/index.js");
|
||||
|
||||
it("Should set the plugin name:version attribute", () => {
|
||||
let pattern = new freesewing.Pattern().with(plugin);
|
||||
pattern.render();
|
||||
expect(pattern.svg.attributes.get("freesewing:plugin-scalebox")).to.equal(
|
||||
version
|
||||
);
|
||||
});
|
||||
|
||||
it("Should run the default scalebox macro", () => {
|
||||
let pattern = new freesewing.Pattern();
|
||||
pattern.draft = function() {};
|
||||
pattern.with(plugin);
|
||||
pattern.parts.test = new pattern.Part();
|
||||
pattern.parts.test.points.anchor = new pattern.Point(100, 200);
|
||||
let { macro } = pattern.parts.test.shorthand();
|
||||
macro("scalebox", {
|
||||
at: pattern.parts.test.points.anchor
|
||||
});
|
||||
let p = pattern.parts.test.points;
|
||||
expect(p.__scaleboxMetricTopLeft.x).to.equal(50);
|
||||
expect(p.__scaleboxMetricTopLeft.y).to.equal(175);
|
||||
expect(p.__scaleboxMetricTopRight.x).to.equal(150);
|
||||
expect(p.__scaleboxMetricTopRight.y).to.equal(175);
|
||||
expect(p.__scaleboxMetricBottomLeft.x).to.equal(50);
|
||||
expect(p.__scaleboxMetricBottomLeft.y).to.equal(225);
|
||||
expect(p.__scaleboxMetricBottomRight.x).to.equal(150);
|
||||
expect(p.__scaleboxMetricBottomRight.y).to.equal(225);
|
||||
expect(p.__scaleboxImperialTopLeft.x).to.equal(49.2);
|
||||
expect(p.__scaleboxImperialTopLeft.y).to.equal(174.6);
|
||||
expect(p.__scaleboxImperialTopRight.x).to.equal(150.8);
|
||||
expect(p.__scaleboxImperialTopRight.y).to.equal(174.6);
|
||||
expect(p.__scaleboxImperialBottomLeft.x).to.equal(49.2);
|
||||
expect(p.__scaleboxImperialBottomLeft.y).to.equal(225.4);
|
||||
expect(p.__scaleboxImperialBottomRight.x).to.equal(150.8);
|
||||
expect(p.__scaleboxImperialBottomRight.y).to.equal(225.4);
|
||||
expect(p.__scaleboxLead.x).to.equal(55);
|
||||
expect(p.__scaleboxLead.y).to.equal(185);
|
||||
expect(p.__scaleboxTitle.x).to.equal(55);
|
||||
expect(p.__scaleboxTitle.y).to.equal(195);
|
||||
expect(p.__scaleboxText.x).to.equal(55);
|
||||
expect(p.__scaleboxText.y).to.equal(203);
|
||||
expect(p.__scaleboxLink.x).to.equal(55);
|
||||
expect(p.__scaleboxLink.y).to.equal(211);
|
||||
expect(p.__scaleboxMetric.x).to.equal(100);
|
||||
expect(p.__scaleboxMetric.y).to.equal(220);
|
||||
expect(p.__scaleboxImperial.x).to.equal(100);
|
||||
expect(p.__scaleboxImperial.y).to.equal(224);
|
||||
p = pattern.parts.test.paths.__scaleboxMetric;
|
||||
expect(p.attributes.get("style")).to.equal("fill: #FFF; stroke: none;");
|
||||
expect(p.ops[0].type).to.equal("move");
|
||||
expect(p.ops[1].type).to.equal("line");
|
||||
expect(p.ops[2].type).to.equal("line");
|
||||
expect(p.ops[3].type).to.equal("line");
|
||||
expect(p.ops[4].type).to.equal("close");
|
||||
expect(p.ops[0].to.x).to.equal(50);
|
||||
expect(p.ops[0].to.y).to.equal(175);
|
||||
expect(p.ops[1].to.x).to.equal(50);
|
||||
expect(p.ops[1].to.y).to.equal(225);
|
||||
expect(p.ops[2].to.x).to.equal(150);
|
||||
expect(p.ops[2].to.y).to.equal(225);
|
||||
expect(p.ops[3].to.x).to.equal(150);
|
||||
expect(p.ops[3].to.y).to.equal(175);
|
||||
p = pattern.parts.test.paths.__scaleboxImperial;
|
||||
expect(p.attributes.get("style")).to.equal("fill: #000; stroke: none;");
|
||||
expect(p.ops[0].type).to.equal("move");
|
||||
expect(p.ops[1].type).to.equal("line");
|
||||
expect(p.ops[2].type).to.equal("line");
|
||||
expect(p.ops[3].type).to.equal("line");
|
||||
expect(p.ops[4].type).to.equal("close");
|
||||
expect(p.ops[0].to.x).to.equal(49.2);
|
||||
expect(p.ops[0].to.y).to.equal(174.6);
|
||||
expect(p.ops[1].to.x).to.equal(49.2);
|
||||
expect(p.ops[1].to.y).to.equal(225.4);
|
||||
expect(p.ops[2].to.x).to.equal(150.8);
|
||||
expect(p.ops[2].to.y).to.equal(225.4);
|
||||
expect(p.ops[3].to.x).to.equal(150.8);
|
||||
expect(p.ops[3].to.y).to.equal(174.6);
|
||||
});
|
||||
|
||||
it("Should run the scalebox macro with rotation", () => {
|
||||
let pattern = new freesewing.Pattern();
|
||||
pattern.draft = function() {};
|
||||
pattern.with(plugin);
|
||||
pattern.parts.test = new pattern.Part();
|
||||
pattern.parts.test.points.anchor = new pattern.Point(100, 200);
|
||||
let { macro } = pattern.parts.test.shorthand();
|
||||
macro("scalebox", {
|
||||
at: pattern.parts.test.points.anchor,
|
||||
rotate: 90
|
||||
});
|
||||
let p = pattern.parts.test.points;
|
||||
expect(p.__scaleboxMetricTopLeft.x).to.equal(75);
|
||||
expect(p.__scaleboxMetricTopLeft.y).to.equal(250);
|
||||
expect(p.__scaleboxMetricTopRight.x).to.equal(75);
|
||||
expect(p.__scaleboxMetricTopRight.y).to.equal(150);
|
||||
expect(p.__scaleboxMetricBottomLeft.x).to.equal(125);
|
||||
expect(p.__scaleboxMetricBottomLeft.y).to.equal(250);
|
||||
expect(p.__scaleboxMetricBottomRight.x).to.equal(125);
|
||||
expect(p.__scaleboxMetricBottomRight.y).to.equal(150);
|
||||
expect(p.__scaleboxImperialTopLeft.x).to.equal(74.6);
|
||||
expect(p.__scaleboxImperialTopLeft.y).to.equal(250.8);
|
||||
expect(p.__scaleboxImperialTopRight.x).to.equal(74.6);
|
||||
expect(p.__scaleboxImperialTopRight.y).to.equal(149.2);
|
||||
expect(p.__scaleboxImperialBottomLeft.x).to.equal(125.4);
|
||||
expect(p.__scaleboxImperialBottomLeft.y).to.equal(250.8);
|
||||
expect(p.__scaleboxImperialBottomRight.x).to.equal(125.4);
|
||||
expect(p.__scaleboxImperialBottomRight.y).to.equal(149.2);
|
||||
expect(p.__scaleboxLead.x).to.equal(85);
|
||||
expect(p.__scaleboxLead.y).to.equal(245);
|
||||
expect(p.__scaleboxTitle.x).to.equal(95);
|
||||
expect(p.__scaleboxTitle.y).to.equal(245);
|
||||
expect(p.__scaleboxText.x).to.equal(103);
|
||||
expect(p.__scaleboxText.y).to.equal(245);
|
||||
expect(p.__scaleboxLink.x).to.equal(111);
|
||||
expect(p.__scaleboxLink.y).to.equal(245);
|
||||
expect(p.__scaleboxMetric.x).to.equal(120);
|
||||
expect(p.__scaleboxMetric.y).to.equal(200);
|
||||
expect(p.__scaleboxImperial.x).to.equal(124);
|
||||
expect(p.__scaleboxImperial.y).to.equal(200);
|
||||
});
|
||||
|
||||
it("Should run the scalebox macro with default text", () => {
|
||||
let pattern = new freesewing.Pattern({
|
||||
name: "unitTest",
|
||||
version: 99
|
||||
});
|
||||
pattern.draft = function() {};
|
||||
pattern.with(plugin);
|
||||
pattern.parts.test = new pattern.Part();
|
||||
pattern.parts.test.points.anchor = new pattern.Point(100, 200);
|
||||
let { macro } = pattern.parts.test.shorthand();
|
||||
macro("scalebox", {
|
||||
at: pattern.parts.test.points.anchor
|
||||
});
|
||||
let p = pattern.parts.test.points.__scaleboxLead.attributes;
|
||||
expect(p.get("data-text")).to.equal("freesewing");
|
||||
expect(p.get("data-text-class")).to.equal("text-sm");
|
||||
p = pattern.parts.test.points.__scaleboxTitle.attributes;
|
||||
expect(p.get("data-text")).to.equal("unitTest v99");
|
||||
expect(p.get("data-text-class")).to.equal("text-lg");
|
||||
p = pattern.parts.test.points.__scaleboxText.attributes;
|
||||
expect(p.get("data-text-class")).to.equal("text-xs");
|
||||
expect(p.get("data-text-lineheight")).to.equal("4");
|
||||
expect(p.list["data-text"][0]).to.equal(
|
||||
"freesewingIsMadeByJoostDeCockAndContributors"
|
||||
);
|
||||
expect(p.list["data-text"][1]).to.equal("\n");
|
||||
expect(p.list["data-text"][2]).to.equal(
|
||||
"withTheFinancialSupportOfOurPatrons"
|
||||
);
|
||||
});
|
||||
|
||||
it("Should run the scalebox macro with custom text", () => {
|
||||
let pattern = new freesewing.Pattern({
|
||||
name: "unitTest",
|
||||
version: 99
|
||||
});
|
||||
pattern.draft = function() {};
|
||||
pattern.with(plugin);
|
||||
pattern.parts.test = new pattern.Part();
|
||||
pattern.parts.test.points.anchor = new pattern.Point(100, 200);
|
||||
let { macro } = pattern.parts.test.shorthand();
|
||||
macro("scalebox", {
|
||||
at: pattern.parts.test.points.anchor,
|
||||
lead: "theLead",
|
||||
title: "theTitle",
|
||||
text: "theText"
|
||||
});
|
||||
let p = pattern.parts.test.points.__scaleboxLead.attributes;
|
||||
expect(p.get("data-text")).to.equal("theLead");
|
||||
expect(p.get("data-text-class")).to.equal("text-sm");
|
||||
p = pattern.parts.test.points.__scaleboxTitle.attributes;
|
||||
expect(p.get("data-text")).to.equal("theTitle");
|
||||
expect(p.get("data-text-class")).to.equal("text-lg");
|
||||
p = pattern.parts.test.points.__scaleboxText.attributes;
|
||||
expect(p.get("data-text")).to.equal("theText");
|
||||
expect(p.get("data-text-class")).to.equal("text-xs");
|
||||
expect(p.get("data-text-lineheight")).to.equal("4");
|
||||
});
|
116
packages/plugin-bundle/tests/title.test.js
Normal file
116
packages/plugin-bundle/tests/title.test.js
Normal file
|
@ -0,0 +1,116 @@
|
|||
import freesewing from "freesewing";
|
||||
import { version } from "../node_modules/@freesewing/plugin-title/package.json";
|
||||
let expect = require("chai").expect;
|
||||
let plugin = require("../dist/index.js");
|
||||
|
||||
it("Should set the plugin name:version attribute", () => {
|
||||
let pattern = new freesewing.Pattern().with(plugin);
|
||||
pattern.render();
|
||||
expect(pattern.svg.attributes.get("freesewing:plugin-title")).to.equal(
|
||||
version
|
||||
);
|
||||
});
|
||||
|
||||
it("Should run the title macro", () => {
|
||||
let pattern = new freesewing.Pattern({ name: "testPattern", version: 99 });
|
||||
pattern.draft = function() {};
|
||||
pattern.with(plugin);
|
||||
pattern.parts.test = new pattern.Part();
|
||||
pattern.parts.test.points.anchor = new pattern.Point(-12, -34);
|
||||
let { macro } = pattern.parts.test.shorthand();
|
||||
macro("title", {
|
||||
at: pattern.parts.test.points.anchor,
|
||||
nr: 3,
|
||||
title: "unitTest"
|
||||
});
|
||||
pattern.render();
|
||||
let p = pattern.parts.test.points.__titleNr;
|
||||
expect(p.x).to.equal(-12);
|
||||
expect(p.y).to.equal(-34);
|
||||
expect(p.attributes.get("data-text")).to.equal("3");
|
||||
expect(p.attributes.get("data-text-class")).to.equal(
|
||||
"title-nr note fill-note"
|
||||
);
|
||||
expect(p.attributes.get("data-text-x")).to.equal("-12");
|
||||
expect(p.attributes.get("data-text-y")).to.equal("-34");
|
||||
p = pattern.parts.test.points.__titleName;
|
||||
expect(p.attributes.get("data-text")).to.equal("unitTest");
|
||||
expect(p.attributes.get("data-text-class")).to.equal("title-name");
|
||||
expect(p.attributes.get("data-text-x")).to.equal("-12");
|
||||
expect(p.attributes.get("data-text-y")).to.equal("-21");
|
||||
p = pattern.parts.test.points.__titlePattern;
|
||||
expect(p.attributes.get("data-text")).to.equal("testPattern v99");
|
||||
expect(p.attributes.get("data-text-class")).to.equal(
|
||||
"title-pattern fill-note"
|
||||
);
|
||||
expect(p.attributes.get("data-text-x")).to.equal("-12");
|
||||
expect(p.attributes.get("data-text-y")).to.equal("-14");
|
||||
});
|
||||
|
||||
it("Should run the title macro with append flag", () => {
|
||||
let pattern = new freesewing.Pattern({ name: "testPattern", version: 99 });
|
||||
pattern.draft = function() {};
|
||||
pattern.with(plugin);
|
||||
pattern.parts.test = new pattern.Part();
|
||||
pattern.parts.test.points.anchor = new pattern.Point(-12, -34).attr(
|
||||
"data-text",
|
||||
"#"
|
||||
);
|
||||
let { macro } = pattern.parts.test.shorthand();
|
||||
macro("title", {
|
||||
at: pattern.parts.test.points.anchor,
|
||||
nr: 3,
|
||||
title: "unitTest",
|
||||
append: true
|
||||
});
|
||||
pattern.render();
|
||||
let p = pattern.parts.test.points.__titleNr;
|
||||
expect(p.x).to.equal(-12);
|
||||
expect(p.y).to.equal(-34);
|
||||
expect(p.attributes.get("data-text")).to.equal("# 3");
|
||||
expect(p.attributes.get("data-text-class")).to.equal(
|
||||
"title-nr note fill-note"
|
||||
);
|
||||
expect(p.attributes.get("data-text-x")).to.equal("-12");
|
||||
expect(p.attributes.get("data-text-y")).to.equal("-34");
|
||||
});
|
||||
|
||||
it("Should run the title macro with point prefix", () => {
|
||||
let pattern = new freesewing.Pattern({ name: "testPattern", version: 99 });
|
||||
pattern.draft = function() {};
|
||||
pattern.with(plugin);
|
||||
pattern.parts.test = new pattern.Part();
|
||||
pattern.parts.test.points.anchor = new pattern.Point(-12, -34).attr(
|
||||
"data-text",
|
||||
"#"
|
||||
);
|
||||
let { macro } = pattern.parts.test.shorthand();
|
||||
macro("title", {
|
||||
at: pattern.parts.test.points.anchor,
|
||||
nr: 3,
|
||||
title: "unitTest",
|
||||
prefix: "foo"
|
||||
});
|
||||
pattern.render();
|
||||
let p = pattern.parts.test.points._foo_titleNr;
|
||||
expect(p.x).to.equal(-12);
|
||||
expect(p.y).to.equal(-34);
|
||||
expect(p.attributes.get("data-text")).to.equal("3");
|
||||
expect(p.attributes.get("data-text-class")).to.equal(
|
||||
"title-nr note fill-note"
|
||||
);
|
||||
expect(p.attributes.get("data-text-x")).to.equal("-12");
|
||||
expect(p.attributes.get("data-text-y")).to.equal("-34");
|
||||
p = pattern.parts.test.points._foo_titleName;
|
||||
expect(p.attributes.get("data-text")).to.equal("unitTest");
|
||||
expect(p.attributes.get("data-text-class")).to.equal("title-name");
|
||||
expect(p.attributes.get("data-text-x")).to.equal("-12");
|
||||
expect(p.attributes.get("data-text-y")).to.equal("-21");
|
||||
p = pattern.parts.test.points._foo_titlePattern;
|
||||
expect(p.attributes.get("data-text")).to.equal("testPattern v99");
|
||||
expect(p.attributes.get("data-text-class")).to.equal(
|
||||
"title-pattern fill-note"
|
||||
);
|
||||
expect(p.attributes.get("data-text-x")).to.equal("-12");
|
||||
expect(p.attributes.get("data-text-y")).to.equal("-14");
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue