diff --git a/packages/plugin-designer/dist/module.js b/packages/plugin-designer/dist/module.js deleted file mode 100644 index fa0738aa938..00000000000 --- a/packages/plugin-designer/dist/module.js +++ /dev/null @@ -1,234 +0,0 @@ -/** - * @freesewing/theme-designer | v0.3.0 - * The designer theme for freesewing - * (c) 2018 Joost De Cock (https://github.com/joostdecock) - * @license MIT - */ -"use strict"; - -var script = ` -function pointHover(evt) { - var point = evt.target; - var id = point.id; - var cx = point.getAttribute('x'); - var cy = point.getAttribute('y'); - console.log('Point '+id+' ( '+cx+' , '+cy+' )'); - var scale = 2; - cx = cx-scale*cx; - cy = cy-scale*cy; - point.setAttribute("transform", 'matrix('+scale+', 0, 0, '+scale+', '+cx+', '+cy+')'); - setTimeout(function(){ - var point = document.getElementById(evt.target.id); - point.removeAttribute("transform", ''); - }, 1000); -} -`; - -var style = ` -path.curve-control{stroke:#f0ad4e;stroke-width: 0.2;} -path.debug{stroke:#d9534f;stroke-opacity:0.4;stroke-width:2;} -.point{fill:none;stroke-width:0.6;stroke:#f0ad4e;} -text.tooltip{font-size:3px;} -`; - -var snippets = ` - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -`; - -var version = "0.3.0"; - -var index = { - hooks: { - preRenderSvg: function(next) { - // Add style, script and snippets - this.style += style; - this.script += script; - this.defs += snippets; - - // Add SVG attributes - this.attributes.add("freesewing:theme-designer", version); - - /** Decorares points with extra info */ - var decoratePoints = function(svg) { - for (let partId in svg.pattern.parts) { - let part = svg.pattern.parts[partId]; - if (part.render) { - for (let pointId in part.points) { - let point = part.points[pointId]; - point.attributes.add("id", svg.getUid()); - point.attributes.add("data-point", pointId); - point.attributes.add("data-part", partId); - let type = - pointId.substr(0, 1) === "_" ? "point-hidden" : "point"; - let id = svg.getUid(); - part.snippets[id] = new svg.pattern.snippet( - type, - point, - `Point ${pointId} in part ${partId}` - ); - part.snippets[id].attributes.add( - "onmouseover", - "pointHover(evt)" - ); - part.snippets[id].attributes.add("id", id); - part.snippets[id].attributes.add("data-point", pointId); - part.snippets[id].attributes.add("data-part", partId); - } - } - } - }; - - /** Decorares path points with extra info */ - var decoratePathPoint = function( - id, - Snippet, - snippets$$1, - point, - type, - pathId, - partId - ) { - snippets$$1[id] = new Snippet( - `path-${type}-point`, - point, - `Path ${pathId}: ${type}` - ); - snippets$$1[id].attributes.add("onmouseover", "pointHover(evt)"); - snippets$$1[id].attributes.add("id", id); - snippets$$1[id].attributes.add( - "data-point", - point.attributes.get("data-point") - ); - snippets$$1[id].attributes.add("data-path", pathId); - snippets$$1[id].attributes.add("data-part", partId); - }; - - /** Draws curve control handles */ - var decorateCurveHandles = function( - id, - Path, - paths, - from, - to, - pathId, - partId - ) { - let path = new Path().move(from).line(to); - path.attributes.add("class", "curve-control"); - path.attributes.add("id", id); - path.attributes.add("data-path", pathId); - path.attributes.add("data-part", partId); - paths[id] = path; - }; - - /** Decorares paths with extra info */ - var decoratePaths = function(svg) { - for (let partId in svg.pattern.parts) { - let part = svg.pattern.parts[partId]; - if (part.render) { - for (let pathId in part.paths) { - let path = part.paths[pathId]; - if (!path.render) return false; - let current; - for (let op of path.ops) { - if (op.type !== "close") { - decoratePathPoint( - svg.getUid(), - svg.pattern.snippet, - part.snippets, - op.to, - op.type, - pathId, - partId - ); - } - if (op.type === "curve") { - decoratePathPoint( - svg.getUid(), - svg.pattern.snippet, - part.snippets, - op.cp1, - "handle", - pathId, - partId - ); - decoratePathPoint( - svg.getUid(), - svg.pattern.snippet, - part.snippets, - op.cp2, - "handle", - pathId, - partId - ); - decorateCurveHandles( - svg.getUid(), - svg.pattern.path, - part.paths, - current, - op.cp1, - pathId, - partId - ); - decorateCurveHandles( - svg.getUid(), - svg.pattern.path, - part.paths, - op.to, - op.cp2, - pathId, - partId - ); - } - current = op.to; - } - } - } - } - }; - - // Decorate pattern - decoratePoints(this); - decoratePaths(this); - console.log( - "Designer theme plugin: Here's the pattern object:", - this.pattern - ); - next(); - } - } -}; - -module.exports = index; diff --git a/packages/plugin-designer/dist/theme.min.js b/packages/plugin-designer/dist/theme.min.js deleted file mode 100644 index a61c5153238..00000000000 --- a/packages/plugin-designer/dist/theme.min.js +++ /dev/null @@ -1,232 +0,0 @@ -this.freesewing = this.freesewing || {}; -this.freesewing.plugins = this.freesewing.plugins || {}; -this.freesewing.plugins.designer = (function() { - "use strict"; - - var script = ` -function pointHover(evt) { - var point = evt.target; - var id = point.id; - var cx = point.getAttribute('x'); - var cy = point.getAttribute('y'); - console.log('Point '+id+' ( '+cx+' , '+cy+' )'); - var scale = 2; - cx = cx-scale*cx; - cy = cy-scale*cy; - point.setAttribute("transform", 'matrix('+scale+', 0, 0, '+scale+', '+cx+', '+cy+')'); - setTimeout(function(){ - var point = document.getElementById(evt.target.id); - point.removeAttribute("transform", ''); - }, 1000); -} -`; - - var style = ` -path.curve-control{stroke:#f0ad4e;stroke-width: 0.2;} -path.debug{stroke:#d9534f;stroke-opacity:0.4;stroke-width:2;} -.point{fill:none;stroke-width:0.6;stroke:#f0ad4e;} -text.tooltip{font-size:3px;} -`; - - var snippets = ` - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -`; - - var version = "0.3.0"; - - var index = { - hooks: { - preRenderSvg: function(next) { - // Add style, script and snippets - this.style += style; - this.script += script; - this.defs += snippets; - - // Add SVG attributes - this.attributes.add("freesewing:theme-designer", version); - - /** Decorares points with extra info */ - var decoratePoints = function(svg) { - for (let partId in svg.pattern.parts) { - let part = svg.pattern.parts[partId]; - if (part.render) { - for (let pointId in part.points) { - let point = part.points[pointId]; - point.attributes.add("id", svg.getUid()); - point.attributes.add("data-point", pointId); - point.attributes.add("data-part", partId); - let type = - pointId.substr(0, 1) === "_" ? "point-hidden" : "point"; - let id = svg.getUid(); - part.snippets[id] = new svg.pattern.snippet( - type, - point, - `Point ${pointId} in part ${partId}` - ); - part.snippets[id].attributes.add( - "onmouseover", - "pointHover(evt)" - ); - part.snippets[id].attributes.add("id", id); - part.snippets[id].attributes.add("data-point", pointId); - part.snippets[id].attributes.add("data-part", partId); - } - } - } - }; - - /** Decorares path points with extra info */ - var decoratePathPoint = function( - id, - Snippet, - snippets$$1, - point, - type, - pathId, - partId - ) { - snippets$$1[id] = new Snippet( - `path-${type}-point`, - point, - `Path ${pathId}: ${type}` - ); - snippets$$1[id].attributes.add("onmouseover", "pointHover(evt)"); - snippets$$1[id].attributes.add("id", id); - snippets$$1[id].attributes.add( - "data-point", - point.attributes.get("data-point") - ); - snippets$$1[id].attributes.add("data-path", pathId); - snippets$$1[id].attributes.add("data-part", partId); - }; - - /** Draws curve control handles */ - var decorateCurveHandles = function( - id, - Path, - paths, - from, - to, - pathId, - partId - ) { - let path = new Path().move(from).line(to); - path.attributes.add("class", "curve-control"); - path.attributes.add("id", id); - path.attributes.add("data-path", pathId); - path.attributes.add("data-part", partId); - paths[id] = path; - }; - - /** Decorares paths with extra info */ - var decoratePaths = function(svg) { - for (let partId in svg.pattern.parts) { - let part = svg.pattern.parts[partId]; - if (part.render) { - for (let pathId in part.paths) { - let path = part.paths[pathId]; - if (!path.render) return false; - let current; - for (let op of path.ops) { - if (op.type !== "close") { - decoratePathPoint( - svg.getUid(), - svg.pattern.snippet, - part.snippets, - op.to, - op.type, - pathId, - partId - ); - } - if (op.type === "curve") { - decoratePathPoint( - svg.getUid(), - svg.pattern.snippet, - part.snippets, - op.cp1, - "handle", - pathId, - partId - ); - decoratePathPoint( - svg.getUid(), - svg.pattern.snippet, - part.snippets, - op.cp2, - "handle", - pathId, - partId - ); - decorateCurveHandles( - svg.getUid(), - svg.pattern.path, - part.paths, - current, - op.cp1, - pathId, - partId - ); - decorateCurveHandles( - svg.getUid(), - svg.pattern.path, - part.paths, - op.to, - op.cp2, - pathId, - partId - ); - } - current = op.to; - } - } - } - } - }; - - // Decorate pattern - decoratePoints(this); - decoratePaths(this); - console.log( - "Designer theme plugin: Here's the pattern object:", - this.pattern - ); - next(); - } - } - }; - - return index; -})(); diff --git a/packages/plugin-designer/package.json b/packages/plugin-designer/package.json index 48d87278d94..0876eb18083 100644 --- a/packages/plugin-designer/package.json +++ b/packages/plugin-designer/package.json @@ -17,8 +17,9 @@ "design", "sewing patterns" ], - "main": "dist/module.js", - "unpkg": "dist/theme.min.js", + "main": "dist/node.js", + "unpkg": "dist/browser.js", + "browser": "dist/browser.js", "scripts": { "precommit": "npm run pretty && lint-staged", "test": "echo \"Error: no test specified\" && exit 1", diff --git a/packages/plugin-designer/rollup.browser.js b/packages/plugin-designer/rollup.browser.js index 0137ec186df..e70d4e4efbd 100644 --- a/packages/plugin-designer/rollup.browser.js +++ b/packages/plugin-designer/rollup.browser.js @@ -8,7 +8,7 @@ import meta from "./package.json"; export default { input: "src/index.js", output: { - file: "dist/theme.min.js", + file: "dist/browser.js", format: "iife", name: "freesewing.plugins.designer" }, @@ -20,15 +20,15 @@ export default { commonjs(), babel({ exclude: "node_modules/**" + }), + terser({ + output: { + preamble: `/**\n * ${meta.name} | v${meta.version}\n * ${ + meta.description + }\n * (c) ${new Date().getFullYear()} ${meta.author}\n * @license ${ + meta.license + }\n */` + } }) - //terser({ - // output: { - // preamble: `/**\n * ${meta.name} | v${meta.version}\n * ${ - // meta.description - // }\n * (c) ${new Date().getFullYear()} ${meta.author}\n * @license ${ - // meta.license - // }\n */` - // } - //}) ] }; diff --git a/packages/plugin-designer/rollup.node.js b/packages/plugin-designer/rollup.node.js index 5acbdc22531..2760397f3d1 100644 --- a/packages/plugin-designer/rollup.node.js +++ b/packages/plugin-designer/rollup.node.js @@ -1,19 +1,15 @@ +import { terser } from "rollup-plugin-terser"; import filesize from "rollup-plugin-filesize"; import babel from "rollup-plugin-babel"; -import resolve from "rollup-plugin-node-resolve"; import json from "rollup-plugin-json"; +import resolve from "rollup-plugin-node-resolve"; import meta from "./package.json"; export default { input: "src/index.js", output: { - file: "dist/module.js", - format: "cjs", - banner: `/**\n * ${meta.name} | v${meta.version}\n * ${ - meta.description - }\n * (c) ${new Date().getFullYear()} ${meta.author}\n * @license ${ - meta.license - }\n */` + file: "dist/node.js", + format: "cjs" }, plugins: [ resolve({ @@ -23,6 +19,15 @@ export default { babel({ exclude: "node_modules/**" }), - filesize() + filesize(), + terser({ + output: { + preamble: `/**\n * ${meta.name} | v${meta.version}\n * ${ + meta.description + }\n * (c) ${new Date().getFullYear()} ${meta.author}\n * @license ${ + meta.license + }\n */` + } + }) ] }; diff --git a/packages/plugin-designer/src/index.js b/packages/plugin-designer/src/index.js index b6fd448d8bc..8bb5f95c88e 100644 --- a/packages/plugin-designer/src/index.js +++ b/packages/plugin-designer/src/index.js @@ -1,13 +1,11 @@ import script from "./lib/script"; -import style from "./lib/style"; import snippets from "./lib/snippets"; import { version } from "../package.json"; export default { hooks: { preRenderSvg: function(next) { - // Add style, script and snippets - this.style += style; + // Add script and snippets this.script += script; this.defs += snippets; @@ -80,7 +78,7 @@ export default { partId ) { let path = new Path().move(from).line(to); - path.attributes.add("class", "curve-control"); + path.attributes.add("class", "curve-control stroke-various stroke-sm"); path.attributes.add("id", id); path.attributes.add("data-path", pathId); path.attributes.add("data-part", partId); @@ -157,10 +155,7 @@ export default { // Decorate pattern decoratePoints(this); decoratePaths(this); - console.log( - "Designer theme plugin: Here's the pattern object:", - this.pattern - ); + console.log("Designer plugin: Here's the pattern object:", this.pattern); next(); } } diff --git a/packages/plugin-designer/src/lib/script.js b/packages/plugin-designer/src/lib/script.js index b529a86f6eb..ac29b11aa24 100644 --- a/packages/plugin-designer/src/lib/script.js +++ b/packages/plugin-designer/src/lib/script.js @@ -4,14 +4,18 @@ function pointHover(evt) { var id = point.id; var cx = point.getAttribute('x'); var cy = point.getAttribute('y'); - console.log('Point '+id+' ( '+cx+' , '+cy+' )'); + var name = point.getAttribute('data-point'); + var part = point.getAttribute('data-part'); + console.log(name+' ('+cx+', '+cy+') @ '+part); var scale = 2; cx = cx-scale*cx; cy = cy-scale*cy; point.setAttribute("transform", 'matrix('+scale+', 0, 0, '+scale+', '+cx+', '+cy+')'); + pointUnhover(id); +} +function pointUnhover(id) { setTimeout(function(){ - var point = document.getElementById(evt.target.id); - point.removeAttribute("transform", ''); - }, 1000); + document.getElementById(id).removeAttribute("transform", ''); + }, 500); } `; diff --git a/packages/plugin-designer/src/lib/snippets.js b/packages/plugin-designer/src/lib/snippets.js index 4c091fc89a4..7b4106fb6fc 100644 --- a/packages/plugin-designer/src/lib/snippets.js +++ b/packages/plugin-designer/src/lib/snippets.js @@ -1,35 +1,22 @@ export default ` - - + + - - + + - - + + - + - - - - - - - - - - - - - - + `; diff --git a/packages/plugin-designer/src/lib/style.js b/packages/plugin-designer/src/lib/style.js deleted file mode 100644 index 2384a65e696..00000000000 --- a/packages/plugin-designer/src/lib/style.js +++ /dev/null @@ -1,6 +0,0 @@ -export default ` -path.curve-control{stroke:#f0ad4e;stroke-width: 0.2;} -path.debug{stroke:#d9534f;stroke-opacity:0.4;stroke-width:2;} -.point{fill:none;stroke-width:0.6;stroke:#f0ad4e;} -text.tooltip{font-size:3px;} -`;