diff --git a/package.json b/package.json index b887febf7d2..2d14d01230b 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,9 @@ "main": "dist/module.js", "unpkg": "dist/freesewing.min.js", "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": "mocha -r ts-node/register tests/*.test.js", "clean": "rimraf dist", diff --git a/rollup.browser.js b/rollup.browser.js index 676dfd30d99..e86c9023e66 100644 --- a/rollup.browser.js +++ b/rollup.browser.js @@ -7,10 +7,9 @@ import json from "rollup-plugin-json"; export default { input: "src/index.js", output: { - file: "dist/freesewing.min.js", + file: "dist/browser.js", format: "iife", name: "freesewing", - banner: `/**\n * Freesewing\n * (c) ${new Date().getFullYear()} Joost De Cock\n * @license MIT\n */`, sourcemap: true }, plugins: [ diff --git a/rollup.node.js b/rollup.node.js index ddd0e495d68..009669f10fc 100644 --- a/rollup.node.js +++ b/rollup.node.js @@ -6,7 +6,7 @@ import json from "rollup-plugin-json"; export default { input: "src/index.js", output: { - file: "dist/module.js", + file: "dist/node.js", format: "cjs" }, plugins: [ diff --git a/src/pattern.js b/src/pattern.js index abb7a526772..96a6c50c729 100644 --- a/src/pattern.js +++ b/src/pattern.js @@ -38,9 +38,14 @@ export default function pattern(config = false) { this.settings = {}; this.values = {}; this.parts = {}; + + // Context object to pass around + this.context = new Object(); + for (let id of config.parts) { this.parts[id] = new part(id); } + this.context.parts = this.parts; this.options = {}; if (typeof config.options !== "undefined" && config.options.length > 0) { for (let conf of config.options) { @@ -48,15 +53,16 @@ export default function pattern(config = false) { else this.options[conf.id] = conf.val; } } - - // Context object to pass around this.context = { parts: this.parts, - options: this.options, - values: this.values, config: this.config, - settings: this.settings + settings: this.settings, + options: this.options, + values: this.values }; + for (let id of config.parts) { + this.parts[id].context = this.context; + } } /** diff --git a/src/svg.js b/src/svg.js index d6ae1897fbd..19dbcface08 100644 --- a/src/svg.js +++ b/src/svg.js @@ -155,11 +155,17 @@ svg.prototype.renderPathText = function(path) { let text = path.attributes.get("data-text"); if (!text) return false; let attributes = path.attributes.renderIfPrefixIs("data-text-"); + // Sadly aligning text along a patch can't be done in CSS only + let offset = ""; + let align = path.attributes.get("data-text-class"); + if (align && align.indexOf("center") > -1) offset = ' startOffset="50%" '; + else if (align && align.indexOf("right") > -1) + offset = ' startOffset="100%" '; let svg = this.nl() + ""; this.indent(); svg += `${text}`; + )}" ${offset}>${text}`; this.outdent(); svg += this.nl() + ""; diff --git a/src/utils.js b/src/utils.js index d82bea2242d..2a9cb35ccee 100644 --- a/src/utils.js +++ b/src/utils.js @@ -64,13 +64,13 @@ export function beamCrossesY(from, to, y) { } /** Returns an object with shorthand access for pattern design */ -export function shorthand(part, context) { - let final = context.settings.mode === "draft" ? true : false; - let paperless = context.settings.paperless === true ? true : false; +export function shorthand(part) { + let final = part.context.settings.mode === "draft" ? true : false; + let paperless = part.context.settings.paperless === true ? true : false; return { - measurements: context.settings.measurements || {}, - options: context.options || {}, - values: context.values || {}, + measurements: part.context.settings.measurements || {}, + options: part.context.options || {}, + values: part.context.values || {}, points: part.points || {}, paths: part.paths || {}, snippets: part.snippets || {},