🚧 Changes to context
This commit is contained in:
parent
014eee3209
commit
54766af63c
6 changed files with 29 additions and 15 deletions
|
@ -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",
|
||||
|
|
|
@ -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: [
|
||||
|
|
|
@ -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: [
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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() + "<text>";
|
||||
this.indent();
|
||||
svg += `<textPath xlink:href="#${path.attributes.get(
|
||||
"id"
|
||||
)}" startOffset="50%"><tspan ${attributes}>${text}</tspan></textPath>`;
|
||||
)}" ${offset}><tspan ${attributes}>${text}</tspan></textPath>`;
|
||||
this.outdent();
|
||||
svg += this.nl() + "</text>";
|
||||
|
||||
|
|
12
src/utils.js
12
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 || {},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue