1
0
Fork 0

🚧 Changes to context

This commit is contained in:
joostdecock 2018-07-25 14:53:10 +00:00
parent 014eee3209
commit 54766af63c
6 changed files with 29 additions and 15 deletions

View file

@ -5,6 +5,9 @@
"main": "dist/module.js", "main": "dist/module.js",
"unpkg": "dist/freesewing.min.js", "unpkg": "dist/freesewing.min.js",
"scripts": { "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", "precommit": "npm run pretty && lint-staged",
"test": "mocha -r ts-node/register tests/*.test.js", "test": "mocha -r ts-node/register tests/*.test.js",
"clean": "rimraf dist", "clean": "rimraf dist",

View file

@ -7,10 +7,9 @@ import json from "rollup-plugin-json";
export default { export default {
input: "src/index.js", input: "src/index.js",
output: { output: {
file: "dist/freesewing.min.js", file: "dist/browser.js",
format: "iife", format: "iife",
name: "freesewing", name: "freesewing",
banner: `/**\n * Freesewing\n * (c) ${new Date().getFullYear()} Joost De Cock\n * @license MIT\n */`,
sourcemap: true sourcemap: true
}, },
plugins: [ plugins: [

View file

@ -6,7 +6,7 @@ import json from "rollup-plugin-json";
export default { export default {
input: "src/index.js", input: "src/index.js",
output: { output: {
file: "dist/module.js", file: "dist/node.js",
format: "cjs" format: "cjs"
}, },
plugins: [ plugins: [

View file

@ -38,9 +38,14 @@ export default function pattern(config = false) {
this.settings = {}; this.settings = {};
this.values = {}; this.values = {};
this.parts = {}; this.parts = {};
// Context object to pass around
this.context = new Object();
for (let id of config.parts) { for (let id of config.parts) {
this.parts[id] = new part(id); this.parts[id] = new part(id);
} }
this.context.parts = this.parts;
this.options = {}; this.options = {};
if (typeof config.options !== "undefined" && config.options.length > 0) { if (typeof config.options !== "undefined" && config.options.length > 0) {
for (let conf of config.options) { for (let conf of config.options) {
@ -48,15 +53,16 @@ export default function pattern(config = false) {
else this.options[conf.id] = conf.val; else this.options[conf.id] = conf.val;
} }
} }
// Context object to pass around
this.context = { this.context = {
parts: this.parts, parts: this.parts,
options: this.options,
values: this.values,
config: this.config, 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;
}
} }
/** /**

View file

@ -155,11 +155,17 @@ svg.prototype.renderPathText = function(path) {
let text = path.attributes.get("data-text"); let text = path.attributes.get("data-text");
if (!text) return false; if (!text) return false;
let attributes = path.attributes.renderIfPrefixIs("data-text-"); 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() + "<text>"; let svg = this.nl() + "<text>";
this.indent(); this.indent();
svg += `<textPath xlink:href="#${path.attributes.get( svg += `<textPath xlink:href="#${path.attributes.get(
"id" "id"
)}" startOffset="50%"><tspan ${attributes}>${text}</tspan></textPath>`; )}" ${offset}><tspan ${attributes}>${text}</tspan></textPath>`;
this.outdent(); this.outdent();
svg += this.nl() + "</text>"; svg += this.nl() + "</text>";

View file

@ -64,13 +64,13 @@ export function beamCrossesY(from, to, y) {
} }
/** Returns an object with shorthand access for pattern design */ /** Returns an object with shorthand access for pattern design */
export function shorthand(part, context) { export function shorthand(part) {
let final = context.settings.mode === "draft" ? true : false; let final = part.context.settings.mode === "draft" ? true : false;
let paperless = context.settings.paperless === true ? true : false; let paperless = part.context.settings.paperless === true ? true : false;
return { return {
measurements: context.settings.measurements || {}, measurements: part.context.settings.measurements || {},
options: context.options || {}, options: part.context.options || {},
values: context.values || {}, values: part.context.values || {},
points: part.points || {}, points: part.points || {},
paths: part.paths || {}, paths: part.paths || {},
snippets: part.snippets || {}, snippets: part.snippets || {},