diff --git a/.eslintrc.js b/.eslintrc.js
new file mode 100644
index 00000000000..0f3a863bf14
--- /dev/null
+++ b/.eslintrc.js
@@ -0,0 +1,8 @@
+module.exports = {
+ plugins: ["prettier"],
+ rules: {
+ "prettier/prettier": "error"
+ },
+ extends: "plugin:prettier/recommended",
+ parser: "babel-eslint"
+};
diff --git a/.npmignore b/.npmignore
index c3af857904e..849ddff3b7e 100644
--- a/.npmignore
+++ b/.npmignore
@@ -1 +1 @@
-lib/
+dist/
diff --git a/README.md b/README.md
index 68cb5251095..e4af09a7a1a 100644
--- a/README.md
+++ b/README.md
@@ -6,8 +6,7 @@
# freesewing
-A port of [freesewing core](https://github.com/freesewing/core)
-to node.js, using [TypeScript](https://www.typescriptlang.org/).
+A port of [freesewing core](https://github.com/freesewing/core) to node.js.
> This is alpha code.
diff --git a/index.ts b/index.ts
deleted file mode 100644
index f49c13b5fc9..00000000000
--- a/index.ts
+++ /dev/null
@@ -1,28 +0,0 @@
-import { Freesewing } from './lib/freesewing'
-
-var freesewing = new Freesewing();
-
-
-
-
-
-
-
-
-
-
- //svg.pre('loadStyle', function (next) {
- // console.log('loadStyle hook');
- // console.log(this.style);
- // this.style= 'p {line-height: 1.21;}';
- // console.log('logging in hook', this);
- // next();
- //});
-
-//var p = new app.pattern({parts:['tst']});
-//p.draft = function(){
-// console.log('drafting in lib index');
-//}
-//p.draft();
-//p.render();
-export default freesewing;
diff --git a/lib/attributes.ts b/lib/attributes.ts
deleted file mode 100644
index ba3bdba08a8..00000000000
--- a/lib/attributes.ts
+++ /dev/null
@@ -1,53 +0,0 @@
-export class Attributes {
- list: any = {};
-
- constructor(init?) {
- for (let key in init) {
- let val = init[key];
- this.add(key, val);
- }
-
- return this;
- }
-
- /** Adds an attribute */
- add(name: string, value: string): Attributes {
- if(typeof this.list[name] === 'undefined') {
- this.list[name] = [];
- }
-
- this.list[name].push(value);
-
- return this;
- }
-
- /** Retrieves an attribute */
- get(name: string): string {
- if(typeof this.list[name] === 'undefined') return false;
- else return this.list[name].join(' ');
- }
-
- /** Returns SVG code for attributes */
- render(): string {
- let svg = '';
- for (let key in this.list) {
- svg += ` ${key}="${this.list[key].join(' ')}"`;
- }
-
- return svg;
- }
-
- /** Returns SVG code for attributes with a fiven prefix
- * typically used for data-text*/
- renderIfPrefixIs(prefix:string = ''): string {
- let svg = '';
- let prefixLen = prefix.length;
- for (let key in this.list) {
- if(key.substr(0,prefixLen) === prefix) {
- svg += ` ${key.substr(prefixLen)}="${this.list[key].join(' ')}"`;
- }
- }
-
- return svg;
- }
-}
diff --git a/lib/freesewing.ts b/lib/freesewing.ts
deleted file mode 100644
index 9909cecfe51..00000000000
--- a/lib/freesewing.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-import { Pattern } from './pattern'
-import { Point } from './point'
-import { Path } from './path'
-import { Snippet } from './snippet'
-import * as utils from './utils'
-
-export class Freesewing {
- version: string;
- pattern: Pattern;
- point: Point;
- path: Path;
- snippet: Snippet;
- utils: utils;
- constructor() {
- this.version = '1.0.1';
- this.pattern = Pattern;
- this.point = Point;
- this.path = Path;
- this.snippet = Snippet;
- this.utils = utils;
- }
-}
diff --git a/lib/hooks.d.ts b/lib/hooks.d.ts
deleted file mode 100644
index 1c5abbbbba0..00000000000
--- a/lib/hooks.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-declare module 'hooks';
diff --git a/lib/hooks.ts b/lib/hooks.ts
deleted file mode 100644
index 23b438301f7..00000000000
--- a/lib/hooks.ts
+++ /dev/null
@@ -1,24 +0,0 @@
-export class Hooks {
- hooks: object;
- all: string[];
-
- constructor(app) {
- this._hooks = {};
- this.all = ['preRenderSvg', 'postRenderSvg'];
- }
-
- list(hook): function[] {
- if(typeof this._hooks[hook] === 'undefined') {
- return false;
- }
-
- return this._hooks[hook];
- }
-
- attach (hook: string, obj: object): void {
- if(typeof this._hooks[hook] === 'undefined') return;
- for(let func of this._hooks[hook]) {
- obj.pre(hook, func);
- }
- }
-}
diff --git a/lib/option.ts b/lib/option.ts
deleted file mode 100644
index 0ce3517347a..00000000000
--- a/lib/option.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-import { PatternOption } from './types'
-export class Option {
- id: string;
- config: PatternOption;
- val: number;
-
- constructor(config: PatternOption) {
- this.id = config.id;
- this.config = config;
- this.val = config.val;
-
- return this;
- }
-}
diff --git a/lib/part.ts b/lib/part.ts
deleted file mode 100644
index a1999b26488..00000000000
--- a/lib/part.ts
+++ /dev/null
@@ -1,41 +0,0 @@
-import { Point } from './point'
-import { Path } from './path'
-import { Snippet } from './snippet'
-import { Attributes } from './attributes'
-import hooklib from 'hooks'
-
-export class Part {
- id: string;
- render: boolean;
- points: { [index: string]: Point; } = {};
- paths: { [index: string]: Path; } = {};
- snippets: { [index: string]: Snippet; } = {};
- attributes = new Attributes();
- // Expose constructors for macros
- point: Point = Point;
- path: Path = Path;
- attr: Attribute = Attributes;
- [propName: string]: any;
-
- constructor(id: string) {
- this.id = id;
- this.render = (id.substr(0,1) === '_') ? false : true;
- this.points.origin = new Point(0,0);
- for(let k in hooklib) this[k] = hooklib[k];
-
- return this;
- }
-
- macroRunner(args?) {
- let self = this;
- let data = args;
- let method = function (key, data) {
- let macro = `_macro_${key}`;
- if(typeof self[macro] === 'function') {
- self[macro](data);
- }
- }
-
- return method;
- }
-}
diff --git a/lib/path.ts b/lib/path.ts
deleted file mode 100644
index 6923bdc479f..00000000000
--- a/lib/path.ts
+++ /dev/null
@@ -1,76 +0,0 @@
-import { Point } from './point'
-import { Attributes } from './attributes'
-
-
-export class Path {
- render: boolean = true;
- ops: {
- type: "move" | "line" | "curve" | "close";
- to?: Point;
- cp1?: Point;
- cp2?: Point;
- }[] = [];
- attributes: Attributes = new Attributes();
-
- /** Adds a move operation to Point to */
- move(to: Point): Path {
- this.ops.push({type: "move", to});
-
- return this;
- }
-
- /** Adds a line operation to Point to */
- line(to: Point): Path {
- this.ops.push({type: "line", to});
-
- return this;
- }
-
- /** Adds a line operation to Point to */
- curve(cp1: Point, cp2: Point, to: Point): Path {
- this.ops.push({type: "curve", cp1, cp2, to});
-
- return this;
- }
-
- /** Adds a close operation */
- close(): Path {
- this.ops.push({type: "close"});
-
- return this;
- }
-
- /** Adds an attribute. This is here to make this call chainable in assignment */
- attr(name, value): Path {
- this.attributes.add(name, value);
-
- return this;
- }
-
- /** Returns SVG pathstring for this path */
- asPathstring() {
- let d = '';
- for(let op of this.ops) {
- switch (op.type) {
- case 'move':
- d += `M ${op.to!.x},${op.to!.y}`;
- break;
- case 'line':
- d += ` L ${op.to!.x},${op.to!.y}`;
- break;
- case 'curve':
- d += ` C ${op.cp1!.x},${op.cp1!.y} ${op.cp2!.x},${op.cp2!.y} ${op.to!.x},${op.to!.y}`;
- break;
- case 'close':
- d += ' z';
- break;
- default:
- throw `${op.type} is not a valid path command`;
- break;
- }
- }
-
- return d;
- }
-
-}
diff --git a/lib/pattern.ts b/lib/pattern.ts
deleted file mode 100644
index 84dff11b1b6..00000000000
--- a/lib/pattern.ts
+++ /dev/null
@@ -1,111 +0,0 @@
-import { PatternConfig, PatternOption } from './types'
-import { Point } from './point'
-import { Part } from './part'
-import { Svg } from './svg'
-import { Hooks } from './hooks'
-import { Option } from './option'
-import { Snippet } from './snippet'
-import { Path } from './path'
-
-export class Pattern {
- config: PatternConfig;
- svg: Svg;
- parts: {
- [index: string]: Part;
- }
- options: {[propName: string]: number};
- values: {[propName: string]: any} = {};
- settings: {[propName: string]: any} = {mode: 'draft', units: 'metric'};
- hooks: Hooks;
- snippet: Snippet;
- path: Path;
- context: any
- hook: any;
-
- constructor(config: PatternConfig) {
- if(!config) {
- throw "Could not create pattern: You need to provide a pattern config."
- }
- if(typeof config.parts === 'undefined' || !config.parts || config.parts.length < 1) {
- throw "Could not create pattern: You should define at least one part in your pattern config";
- }
- this.config = config;
- this.point = Point;
- this.path = Path;
- this.snippet = Snippet;
- this.parts = {};
- this.svg = new Svg(this);
- this.hooks = new Hooks();
- for (let id of config.parts) {
- this.parts[id] = new Part(id);
- }
-
- this.options = {};
- if(typeof config.options !== 'undefined' && config.options.length > 0) {
- for (let conf of config.options) {
- if(conf.type === 'percentage') this.options[conf.id] = conf.val/100;
- else this.options[conf.id] = conf.val;
- }
- }
- this.context = {
- parts: this.parts,
- options: this.options,
- values: this.values,
- config: this.config,
- settings: this.settings
- }
- return this;
- }
-
- draft(): void {
- throw Error('You have to implement the draft() method in your Pattern instance.');
- }
-
- render(): string {
- this.hooks.attach('preRenderSvg', this.svg);
- this.hooks.attach('postRenderSvg', this.svg);
- //this.hooks.attach('insertText', this.svg);
-
- return this.svg.render(this);
- }
-
- on(hook, method): void {
- if(typeof this.hooks._hooks[hook] === 'undefined') {
- this.hooks._hooks[hook] = [];
- }
- this.hooks._hooks[hook].push(method);
- }
-
- macro(key, method): void {
- let name = `_macro_${key}`;
- this.on(name, method);
- for(let partId in this.parts) {
- let part = this.parts[partId];
- part[name] = () => null;
- this.hooks.attach(name, part);
- }
- }
-
- withPlugin(plugin: () => void): void {
- if(plugin.hooks) this.loadPluginHooks(plugin);
- if(plugin.macros) this.loadPluginMacros(plugin);
-
- return this; // Make it chainable
- }
-
- loadPluginHooks(plugin: () => void): void {
- for(let hook of this.hooks.all) {
- if(typeof plugin.hooks[hook] === 'function') {
- this.on(hook, plugin.hooks[hook]);
- }
- }
- }
-
- loadPluginMacros(plugin: () => void): void {
- for(let macro in plugin.macros) {
- if(typeof plugin.macros[macro] === 'function') {
- this.macro(macro, plugin.macros[macro]);
- }
- }
- }
-}
diff --git a/lib/snippet.ts b/lib/snippet.ts
deleted file mode 100644
index 8a8d00eb585..00000000000
--- a/lib/snippet.ts
+++ /dev/null
@@ -1,17 +0,0 @@
-import { Point } from './point'
-import { Attributes } from './attributes'
-
-export class Snippet {
- anchor: Point;
- def: string;
- attributes: Attributes = new Attributes();
- description: string | false;
-
- constructor(def: string, anchor: Point, description: string | false = false) {
- this.anchor = anchor;
- this.def = def;
- this.description = description;
-
- return this;
- }
-}
diff --git a/lib/svg.ts b/lib/svg.ts
deleted file mode 100644
index fc9724f8296..00000000000
--- a/lib/svg.ts
+++ /dev/null
@@ -1,251 +0,0 @@
-import { Part } from './part'
-import { Path } from './path'
-import { Snippet } from './snippet'
-import { Pattern } from './pattern'
-import { Attributes } from './attributes'
-import hooklib from 'hooks'
-import { Hooks } from './hooks'
-
-export class Svg {
- prefix: string;
- body: string = '';
- style: string = '';
- script: string = '';
- header: string = '';
- footer: string = '';
- defs: string = '';
- attributes: Attributes = new Attributes();
- tabs: number = 0;
- freeId: number = 1;
- svg: string = '';
- openGroups: string[] = [];
- hook: any;
- hooks: string[];
- pattern: Pattern;
-
- constructor(pattern: Pattern) {
- this.pattern = pattern; // Needed to expose pattern to hooks
- this.prefix = '';
- this.attributes.add("xmlns", "http://www.w3.org/2000/svg");
- this.attributes.add("xmlns:svg", "http://www.w3.org/2000/svg");
- this.attributes.add("xmlns:xlink", "http://www.w3.org/1999/xlink");
- this.hooks = ['preRenderSvg', 'postRenderSvg'];
- for(let k in hooklib) this[k] = hooklib[k];
- for(let k in this.hooks) this.hook(k, this[k]);
-
- return this;
- }
-
- /** Method to attach preRenderSvg hooks on */
- preRenderSvg(): void {}
-
- /** Method to attach postRenderSvg hooks on */
- postRenderSvg(): void {}
-
- /** Renders a draft object as SVG */
- render(pattern: Pattern): string {
- this.preRenderSvg();
- this.svg = this.prefix;
- this.svg += this.renderComments(this.header);
- this.svg += this.renderSvgTag(pattern);
- this.svg += this.renderStyle();
- this.svg += this.renderScript();
- this.svg += this.renderDefs();
- this.svg += this.openGroup('draftContainer');
- for (let partId in pattern.parts) {
- let part = pattern.parts[partId];
- if (part.render) {
- this.svg += this.openGroup(part.id, part.attributes);
- this.svg += this.renderPart(part);
- this.svg += this.closeGroup();
- }
- }
- this.svg += this.closeGroup();
- this.svg += this.nl()+'';
- this.svg += this.renderComments(this.footer);
- this.postRenderSvg();
- return this.svg;
- }
-
- /** Returns SVG code for the opening SVG tag */
- renderSvgTag(pattern: Pattern) {
- let svg = '";
+ this.svg += this.renderComments(this.footer);
+ this.postRenderSvg();
+ return this.svg;
+ };
+
+ /** Returns SVG code for the opening SVG tag */
+ this.prototype.renderSvgTag = funtion(pattern);
+ {
+ let svg = "