mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Remove filepp.pl as preprocessor and switch to our own Prepro.js, a simple preprocesssor for JavaScript that speaks JavaScript, written in JavaScript, allowing preprocessing to either happen at build time or compile time.
This commit is contained in:
parent
a0a426982f
commit
8eaeb7fb5e
9 changed files with 168 additions and 2995 deletions
|
@ -35,5 +35,5 @@ then
|
|||
mkdir ../dist/
|
||||
fi
|
||||
|
||||
./preprocess.sh $MODE ../src/paper.js ../dist/paper.js "-DBROWSER"
|
||||
#./preprocess.sh $MODE ../src/paper.js ../dist/paper-server.js "-DSERVER"
|
||||
./preprocess.sh $MODE ../src/paper.js ../dist/paper.js '{ "browser": true }'
|
||||
#./preprocess.sh $MODE ../src/paper.js ../dist/paper-server.js '{ "server": true }'
|
||||
|
|
2924
build/filepp.pl
2924
build/filepp.pl
File diff suppressed because it is too large
Load diff
97
build/prepro.js
Executable file
97
build/prepro.js
Executable file
|
@ -0,0 +1,97 @@
|
|||
#! /usr/bin/env node
|
||||
/*
|
||||
* Paper.js
|
||||
*
|
||||
* This file is part of Paper.js, a JavaScript Vector Graphics Library,
|
||||
* based on Scriptographer.org and designed to be largely API compatible.
|
||||
* http://paperjs.org/
|
||||
* http://scriptographer.org/
|
||||
*
|
||||
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Prepro.js - A simple preprocesssor for JavaScript that speaks JavaScript,
|
||||
* written in JavaScript, allowing preprocessing to either happen at build time
|
||||
* or compile time. Very useful for libraries that are built for distribution,
|
||||
* but can be also compiled from seperate sources directly for development,
|
||||
* supporting build time switches.
|
||||
*/
|
||||
|
||||
// Require libs
|
||||
|
||||
var fs = require('fs'),
|
||||
path = require('path');
|
||||
|
||||
// Parse arguments
|
||||
|
||||
var args = process.argv.slice(2),
|
||||
options = {},
|
||||
files = [];
|
||||
|
||||
while (args.length > 0) {
|
||||
var arg = args.shift();
|
||||
switch (arg) {
|
||||
case '-d':
|
||||
// Definitions are provided as JSON and supposed to be object literals
|
||||
var def = JSON.parse(args.shift());
|
||||
// Merge new definitions into options object.
|
||||
for (var key in def)
|
||||
options[key] = def[key];
|
||||
break;
|
||||
default:
|
||||
files.push(arg);
|
||||
}
|
||||
}
|
||||
|
||||
// Preprocessing
|
||||
|
||||
var code = [];
|
||||
|
||||
function include(base, file) {
|
||||
// Compose a pathname from base and file, which is specified relatively,
|
||||
// and normalize the new path, to get rid of ..
|
||||
file = path.normalize(path.join(base, file));
|
||||
var content = fs.readFileSync(file).toString();
|
||||
content.split(/\r\n|\n|\r/mg).forEach(function(line) {
|
||||
// See if our line starts with the preprocess prefix.
|
||||
var match = line.match(/^\s*\/\*#\*\/\s*(.*)$/);
|
||||
if (match) {
|
||||
// Check if the preprocessing line is an include statement, and if
|
||||
// so, handle it straight away
|
||||
line = match[1];
|
||||
if (match = line.match(/^include\(['"]([^;]*)['"]\);?$/)) {
|
||||
// Pass on the dirname of the current file as the new base
|
||||
include(path.dirname(file), match[1]);
|
||||
} else {
|
||||
// Any other preprocessing code is simply added, for later
|
||||
// evaluation.
|
||||
code.push(line);
|
||||
}
|
||||
} else {
|
||||
// Perhaps we need to replace some values? Supported formats are:
|
||||
// /*#=*/ options.NAME (outside comments)
|
||||
// *#=* options.NAME (inside comments)
|
||||
line = line.replace(/\/?\*#=\*\/?\s*options\.([\w]*)/g,
|
||||
function(all, name) {
|
||||
return options[name];
|
||||
}
|
||||
);
|
||||
// No add a statement that when evaluated writes out this code line
|
||||
code.push('console.log(' + JSON.stringify(line) + ');');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Include all files. Everything else happens from there, through include()
|
||||
files.forEach(function(file) {
|
||||
include(path.resolve(), file);
|
||||
});
|
||||
|
||||
// Evaluate the resulting code: Calls puts() and writes the result to stdout.
|
||||
eval(code.join('\n'));
|
|
@ -35,8 +35,8 @@
|
|||
VERSION=0.2
|
||||
DATE=$(git log -1 --pretty=format:%ad)
|
||||
|
||||
KEYWORD="//#"
|
||||
COMMAND="./filepp.pl -kc $KEYWORD $4 -DVERSION=$VERSION -DDATE='$DATE' $2"
|
||||
COMMAND="./prepro.js -d '{ \"version\": $VERSION, \"date\": \"$DATE\" }' -d '$4' $2"
|
||||
echo $COMMAND
|
||||
|
||||
case $1 in
|
||||
stripped)
|
||||
|
|
|
@ -42,7 +42,7 @@ var PaperScope = this.PaperScope = Base.extend(/** @lends PaperScope# */{
|
|||
*
|
||||
* @type Number
|
||||
*/
|
||||
version: VERSION,
|
||||
version: /*#=*/ options.version,
|
||||
|
||||
/**
|
||||
* The currently active project.
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
* @namespace
|
||||
*/
|
||||
var PaperScript = this.PaperScript = new function() {
|
||||
//#include "../../lib/parse-js-min.js"
|
||||
/*#*/ include('../../lib/parse-js-min.js');
|
||||
|
||||
// Math Operators
|
||||
|
||||
|
@ -153,7 +153,7 @@ var PaperScript = this.PaperScript = new function() {
|
|||
* @return {Object} The result of the code evaluation.
|
||||
*/
|
||||
function evaluate(code, scope) {
|
||||
//#ifdef BROWSER
|
||||
/*#*/ if (options.browser) {
|
||||
// See if it's a script tag or a string
|
||||
if (typeof code !== 'string') {
|
||||
// If a canvas id is provided, create a project for it now,
|
||||
|
@ -171,7 +171,7 @@ var PaperScript = this.PaperScript = new function() {
|
|||
code = code.innerHTML;
|
||||
}
|
||||
}
|
||||
//#endif // BROWSER
|
||||
/*#*/ } // options.browser
|
||||
// Set currently active scope.
|
||||
paper = scope;
|
||||
var view = scope.view,
|
||||
|
@ -224,7 +224,7 @@ var PaperScript = this.PaperScript = new function() {
|
|||
return res;
|
||||
}
|
||||
|
||||
//#ifdef BROWSER
|
||||
/*#*/ if (options.browser) {
|
||||
// Code borrowed from Coffee Script:
|
||||
function request(url, scope) {
|
||||
var xhr = new (window.ActiveXObject || XMLHttpRequest)(
|
||||
|
@ -287,14 +287,14 @@ var PaperScript = this.PaperScript = new function() {
|
|||
hasAttribute: handleAttribute('has')
|
||||
};
|
||||
|
||||
//#else // !BROWSER
|
||||
/*#*/ } else { // !options.browser
|
||||
|
||||
return {
|
||||
compile: compile,
|
||||
evaluate: evaluate
|
||||
};
|
||||
|
||||
//#endif // !BROWSER
|
||||
/*#*/ } // !options.browser
|
||||
};
|
||||
|
||||
// Export load directly:
|
||||
|
|
|
@ -35,11 +35,11 @@ var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{
|
|||
if (object.getContext) {
|
||||
this.setCanvas(object);
|
||||
} else {
|
||||
//#ifdef BROWSER
|
||||
/*#*/ if (options.browser) {
|
||||
// If it's a string, get the element with this id first.
|
||||
if (typeof object === 'string')
|
||||
object = document.getElementById(object);
|
||||
//#endif // BROWSER
|
||||
/*#*/ } // options.browser
|
||||
this.setImage(object);
|
||||
}
|
||||
this._matrix = new Matrix();
|
||||
|
|
110
src/paper.js
110
src/paper.js
|
@ -1,5 +1,5 @@
|
|||
/*!
|
||||
* Paper.js vVERSION
|
||||
* Paper.js v*#=* options.version
|
||||
*
|
||||
* This file is part of Paper.js, a JavaScript Vector Graphics Library,
|
||||
* based on Scriptographer.org and designed to be largely API compatible.
|
||||
|
@ -13,7 +13,7 @@
|
|||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Date: DATE
|
||||
* Date: *#=* options.date
|
||||
*
|
||||
***
|
||||
*
|
||||
|
@ -134,78 +134,78 @@
|
|||
|
||||
var paper = new function() {
|
||||
// Inline Bootstrap core (the Base class) inside the paper scope first:
|
||||
//#include "../lib/bootstrap.js"
|
||||
/*#*/ include('../lib/bootstrap.js');
|
||||
|
||||
//#include "core/Base.js"
|
||||
//#include "core/PaperScope.js"
|
||||
/*#*/ include('core/Base.js');
|
||||
/*#*/ include('core/PaperScope.js');
|
||||
|
||||
// Include Paper classes, which are later injected into PaperScope by setting
|
||||
// them on the 'this' object, e.g.:
|
||||
// var Point = this.Point = Base.extend(...);
|
||||
|
||||
//#include "basic/Point.js"
|
||||
//#include "basic/Size.js"
|
||||
//#include "basic/Rectangle.js"
|
||||
//#include "basic/Matrix.js"
|
||||
//#include "basic/Line.js"
|
||||
/*#*/ include('basic/Point.js');
|
||||
/*#*/ include('basic/Size.js');
|
||||
/*#*/ include('basic/Rectangle.js');
|
||||
/*#*/ include('basic/Matrix.js');
|
||||
/*#*/ include('basic/Line.js');
|
||||
|
||||
//#include "project/Project.js"
|
||||
//#include "project/Symbol.js"
|
||||
/*#*/ include('project/Project.js');
|
||||
/*#*/ include('project/Symbol.js');
|
||||
|
||||
//#include "item/ChangeFlag.js"
|
||||
//#include "item/Item.js"
|
||||
//#include "item/Group.js"
|
||||
//#include "item/Layer.js"
|
||||
//#include "item/PlacedItem.js"
|
||||
//#include "item/Raster.js"
|
||||
//#include "item/PlacedSymbol.js"
|
||||
//#include "item/HitResult.js"
|
||||
/*#*/ include('item/ChangeFlag.js');
|
||||
/*#*/ include('item/Item.js');
|
||||
/*#*/ include('item/Group.js');
|
||||
/*#*/ include('item/Layer.js');
|
||||
/*#*/ include('item/PlacedItem.js');
|
||||
/*#*/ include('item/Raster.js');
|
||||
/*#*/ include('item/PlacedSymbol.js');
|
||||
/*#*/ include('item/HitResult.js');
|
||||
|
||||
//#include "path/Segment.js"
|
||||
//#include "path/SegmentPoint.js"
|
||||
//#include "path/SelectionState.js"
|
||||
//#include "path/Curve.js"
|
||||
//#include "path/CurveLocation.js"
|
||||
//#include "path/PathItem.js"
|
||||
//#include "path/Path.js"
|
||||
//#include "path/Path.Constructors.js"
|
||||
//#include "path/CompoundPath.js"
|
||||
//#include "path/PathFlattener.js"
|
||||
//#include "path/PathFitter.js"
|
||||
/*#*/ include('path/Segment.js');
|
||||
/*#*/ include('path/SegmentPoint.js');
|
||||
/*#*/ include('path/SelectionState.js');
|
||||
/*#*/ include('path/Curve.js');
|
||||
/*#*/ include('path/CurveLocation.js');
|
||||
/*#*/ include('path/PathItem.js');
|
||||
/*#*/ include('path/Path.js');
|
||||
/*#*/ include('path/Path.Constructors.js');
|
||||
/*#*/ include('path/CompoundPath.js');
|
||||
/*#*/ include('path/PathFlattener.js');
|
||||
/*#*/ include('path/PathFitter.js');
|
||||
|
||||
//#include "text/TextItem.js"
|
||||
//#include "text/PointText.js"
|
||||
/*#*/ include('text/TextItem.js');
|
||||
/*#*/ include('text/PointText.js');
|
||||
|
||||
//#include "style/Style.js"
|
||||
//#include "style/PathStyle.js"
|
||||
//#include "style/ParagraphStyle.js"
|
||||
//#include "style/CharacterStyle.js"
|
||||
/*#*/ include('style/Style.js');
|
||||
/*#*/ include('style/PathStyle.js');
|
||||
/*#*/ include('style/ParagraphStyle.js');
|
||||
/*#*/ include('style/CharacterStyle.js');
|
||||
|
||||
//#include "color/Color.js"
|
||||
//#include "color/GradientColor.js"
|
||||
//#include "color/Gradient.js"
|
||||
//#include "color/GradientStop.js"
|
||||
/*#*/ include('color/Color.js');
|
||||
/*#*/ include('color/GradientColor.js');
|
||||
/*#*/ include('color/Gradient.js');
|
||||
/*#*/ include('color/GradientStop.js');
|
||||
|
||||
//#ifdef BROWSER
|
||||
/*#*/ if (options.browser) {
|
||||
|
||||
//#include "browser/DomElement.js"
|
||||
//#include "browser/DomEvent.js"
|
||||
/*#*/ include('browser/DomElement.js');
|
||||
/*#*/ include('browser/DomEvent.js');
|
||||
|
||||
//#include "ui/View.js"
|
||||
//#include "ui/Event.js"
|
||||
//#include "ui/KeyEvent.js"
|
||||
//#include "ui/Key.js"
|
||||
/*#*/ include('ui/View.js');
|
||||
/*#*/ include('ui/Event.js');
|
||||
/*#*/ include('ui/KeyEvent.js');
|
||||
/*#*/ include('ui/Key.js');
|
||||
|
||||
//#include "tool/ToolEvent.js"
|
||||
//#include "tool/Tool.js"
|
||||
/*#*/ include('tool/ToolEvent.js');
|
||||
/*#*/ include('tool/Tool.js');
|
||||
|
||||
//#endif // BROWSER
|
||||
/*#*/ } // options.browser
|
||||
|
||||
//#include "util/CanvasProvider.js"
|
||||
//#include "util/Numerical.js"
|
||||
//#include "util/BlendMode.js"
|
||||
/*#*/ include('util/CanvasProvider.js');
|
||||
/*#*/ include('util/Numerical.js');
|
||||
/*#*/ include('util/BlendMode.js');
|
||||
|
||||
//#include "core/PaperScript.js"
|
||||
/*#*/ include('core/PaperScript.js');
|
||||
|
||||
// Iterate over all proced Base classes and set the _name property of their
|
||||
// constructors to the key under which they are stored. This is a simple hack
|
||||
|
|
|
@ -37,15 +37,15 @@ var CanvasProvider = {
|
|||
}
|
||||
return canvas;
|
||||
} else {
|
||||
//#ifdef BROWSER
|
||||
/*#*/ if (options.browser) {
|
||||
var canvas = document.createElement('canvas');
|
||||
canvas.width = size.width;
|
||||
canvas.height = size.height;
|
||||
return canvas;
|
||||
//#else // !BROWSER
|
||||
/*#*/ } else { // !options.browser
|
||||
// Only rhino-canvas for now:
|
||||
return new Image(size.width, size.height);
|
||||
//#endif // !BROWSER
|
||||
/*#*/ } // !options.browser
|
||||
}
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in a new issue