diff --git a/build/build.sh b/build/build.sh index 310e5254..61ea9123 100755 --- a/build/build.sh +++ b/build/build.sh @@ -20,4 +20,5 @@ then mkdir ../out/ fi +./preprocess.sh ../src/build.js ../out/paper-browser.js "-DBROWSER" $MODE ./preprocess.sh ../src/build.js ../out/paper.js "" $MODE diff --git a/build/preprocess.sh b/build/preprocess.sh index 6cecbe00..d24f4081 100755 --- a/build/preprocess.sh +++ b/build/preprocess.sh @@ -17,7 +17,7 @@ # compressed No comments and no whitespaces # compiled Uses Google Closure Compiler to reduce file size even more -KEYWORD="#" +KEYWORD="//#" case $4 in stripped) diff --git a/src/build.js b/src/build.js index aa63cb35..e882d0e5 100644 --- a/src/build.js +++ b/src/build.js @@ -1,43 +1,44 @@ var paper = new function() { -#include "paper.js" +//#include "paper.js" -#include "basic/Point.js" -#include "basic/Size.js" -#include "basic/Rectangle.js" -#include "basic/Matrix.js" +//#include "basic/Point.js" +//#include "basic/Size.js" +//#include "basic/Rectangle.js" +//#include "basic/Matrix.js" -#include "document/DocumentView.js" -#include "document/Document.js" -#include "document/Symbol.js" +//#include "document/DocumentView.js" +//#include "document/Document.js" +//#include "document/Symbol.js" -#include "item/Item.js" -#include "item/Group.js" -#include "item/Layer.js" -#include "item/Raster.js" -#include "item/PlacedSymbol.js" -#include "item/PathStyle.js" +//#include "item/Item.js" +//#include "item/Group.js" +//#include "item/Layer.js" +//#include "item/Raster.js" +//#include "item/PlacedSymbol.js" +//#include "item/PathStyle.js" -#include "path/Segment.js" -#include "path/Curve.js" -#include "path/PathItem.js" -#include "path/Path.js" -#include "path/CompoundPath.js" -#include "path/Path.Constructors.js" +//#include "path/Segment.js" +//#include "path/Curve.js" +//#include "path/PathItem.js" +//#include "path/Path.js" +//#include "path/CompoundPath.js" +//#include "path/Path.Constructors.js" -#include "color/Color.js" -#include "color/RGBColor.js" -#include "color/GrayColor.js" -#include "color/GradientColor.js" -#include "color/Gradient.js" -#include "color/GradientStop.js" +//#include "color/Color.js" +//#include "color/RGBColor.js" +//#include "color/GrayColor.js" +//#include "color/GradientColor.js" +//#include "color/Gradient.js" +//#include "color/GradientStop.js" -#include "tool/ToolEvent.js" -#include "tool/ToolHandler.js" -#include "tool/Tool.js" +//#include "tool/ToolEvent.js" +//#include "tool/ToolHandler.js" +//#include "tool/Tool.js" -#include "util/CanvasProvider.js" -#include "util/MathUtils.js" +//#include "util/CanvasProvider.js" +//#include "util/MathUtils.js" +//#include "util/PaperScript.js" // Inject all prototypes from the paper scope into the paper object. return Base.each(['Point', 'Size', 'Rectangle', 'Matrix', 'DocumentView', diff --git a/src/util/PaperScript.js b/src/util/PaperScript.js new file mode 100644 index 00000000..f2cd67db --- /dev/null +++ b/src/util/PaperScript.js @@ -0,0 +1,54 @@ +var PaperScript = new function() { + function compile(code) { + return code; + } + + function run(code) { + with (paper) { + return eval(compile(code)); + } + } + +//#ifdef BROWSER + // Code borrowed from Coffee Script: + function load(url) { + var xhr = new (window.ActiveXObject || XMLHttpRequest)('Microsoft.XMLHTTP'); + xhr.open('GET', url, true); + if ('overrideMimeType' in xhr) { + xhr.overrideMimeType('text/plain'); + } + xhr.onreadystatechange = function() { + if (xhr.readyState === 4) { + return run(xhr.responseText); + } + }; + return xhr.send(null); + } + + function runScripts() { + var scripts = document.getElementsByTagName('script'); + for (var i = 0, l = scripts.length; i < l; i++) { + var script = scripts[i]; + if (script.type === 'text/paperscript') { + if (script.src) { + load(script.src); + } else { + run(script.innerHTML); + } + } + } + return null; + } + + if (window.addEventListener) { + addEventListener('DOMContentLoaded', runScripts, false); + } else { + attachEvent('onload', runScripts); + } +//#endif // BROWSER + + return { + compile: compile, + run: run + }; +};