mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Add beginning of support for <script type="text/paperscript">, inspired by Coffee Script.
This commit is contained in:
parent
08970abd6d
commit
2c78a0a08b
4 changed files with 88 additions and 32 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
63
src/build.js
63
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',
|
||||
|
|
54
src/util/PaperScript.js
Normal file
54
src/util/PaperScript.js
Normal file
|
@ -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
|
||||
};
|
||||
};
|
Loading…
Reference in a new issue