mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-03-14 00:39:57 -04:00
Implement Prepro.js for the browser too, in order to be able to load the library from paper.js source files and preprocess on the fly on the browser side.
This commit is contained in:
parent
5b6df3d3bf
commit
f98c8f29fc
7 changed files with 152 additions and 161 deletions
|
@ -18,6 +18,5 @@
|
|||
# development of the library itself.
|
||||
|
||||
echo "// Paper.js loader for development, as produced by the build/load.sh script
|
||||
var root = '../../';
|
||||
document.write('<script type=\"text/javascript\" src=\"' + root
|
||||
+ 'src/load.js\"></script>');" > ../dist/paper.js;
|
||||
document.write('<script type=\"text/javascript\" src=\"../../src/load/prepro.js\"></script>');
|
||||
document.write('<script type=\"text/javascript\" src=\"../../src/load/load.js\"></script>');" > ../dist/paper.js;
|
31
src/core/initialize.js
Normal file
31
src/core/initialize.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// Iterate over all produced Base classes and set the _name property of their
|
||||
// constructors to the key under which they are stored. This is a simple hack
|
||||
// that allow us to use their names.
|
||||
// Setting Function#name is not possible, as that is read-only.
|
||||
Base.each(this, function(val, key) {
|
||||
if (val && val.prototype instanceof Base)
|
||||
val._name = key;
|
||||
});
|
||||
|
||||
/*#*/ if (options.version == 'dev') {
|
||||
// We're already leaking into the global scope, so let's just assign the global
|
||||
// paper object with a prepare scope. See paper.js for the non-dev version of
|
||||
// this code.
|
||||
paper = new PaperScope();
|
||||
/*#*/ } // options.version == 'dev'
|
146
src/load.js
146
src/load.js
|
@ -1,146 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// This file is only used by examples and unit tests, in order to load the
|
||||
// library without having to preprocess it first.
|
||||
//
|
||||
// NOTE: Any files added as includes to paper.js also need to be listed here
|
||||
|
||||
// Define VERSION, so PaperScope is not bailing out.
|
||||
var VERSION = 'dev;'
|
||||
|
||||
var sources = [
|
||||
'lib/bootstrap.js',
|
||||
'lib/parse-js.js',
|
||||
'lib/stats.js',
|
||||
|
||||
'src/core/Base.js',
|
||||
'src/core/PaperScope.js',
|
||||
|
||||
'src/paper.js',
|
||||
|
||||
'src/basic/Point.js',
|
||||
'src/basic/Size.js',
|
||||
'src/basic/Rectangle.js',
|
||||
'src/basic/Matrix.js',
|
||||
'src/basic/Line.js',
|
||||
|
||||
'src/project/Project.js',
|
||||
'src/project/Symbol.js',
|
||||
|
||||
'src/item/ChangeFlag.js',
|
||||
'src/item/Item.js',
|
||||
'src/item/Group.js',
|
||||
'src/item/Layer.js',
|
||||
'src/item/PlacedItem.js',
|
||||
'src/item/Raster.js',
|
||||
'src/item/PlacedSymbol.js',
|
||||
'src/item/HitResult.js',
|
||||
|
||||
'src/path/Segment.js',
|
||||
'src/path/SegmentPoint.js',
|
||||
'src/path/SelectionState.js',
|
||||
'src/path/Curve.js',
|
||||
'src/path/CurveLocation.js',
|
||||
'src/path/PathItem.js',
|
||||
'src/path/Path.js',
|
||||
'src/path/Path.Constructors.js',
|
||||
'src/path/CompoundPath.js',
|
||||
'src/path/PathFlattener.js',
|
||||
'src/path/PathFitter.js',
|
||||
|
||||
'src/text/TextItem.js',
|
||||
'src/text/PointText.js',
|
||||
|
||||
'src/style/Style.js',
|
||||
'src/style/PathStyle.js',
|
||||
'src/style/ParagraphStyle.js',
|
||||
'src/style/CharacterStyle.js',
|
||||
|
||||
'src/color/Color.js',
|
||||
'src/color/GradientColor.js',
|
||||
'src/color/Gradient.js',
|
||||
'src/color/GradientStop.js',
|
||||
|
||||
'src/browser/DomElement.js',
|
||||
'src/browser/DomEvent.js',
|
||||
|
||||
'src/ui/View.js',
|
||||
'src/ui/Event.js',
|
||||
'src/ui/KeyEvent.js',
|
||||
'src/ui/Key.js',
|
||||
|
||||
'src/tool/ToolEvent.js',
|
||||
'src/tool/Tool.js',
|
||||
|
||||
'src/util/CanvasProvider.js',
|
||||
'src/util/Numerical.js',
|
||||
'src/util/BlendMode.js',
|
||||
|
||||
'src/core/PaperScript.js'
|
||||
];
|
||||
|
||||
// Load unit tests after library if asked to do so
|
||||
if (window.tests) {
|
||||
sources.push(
|
||||
'test/lib/qunit/qunit.js',
|
||||
'test/lib/helpers.js',
|
||||
|
||||
'test/tests/Point.js',
|
||||
'test/tests/Size.js',
|
||||
'test/tests/Rectangle.js',
|
||||
|
||||
'test/tests/Color.js',
|
||||
|
||||
'test/tests/Project.js',
|
||||
|
||||
'test/tests/Item.js',
|
||||
'test/tests/Item_Cloning.js',
|
||||
'test/tests/Item_Order.js',
|
||||
|
||||
'test/tests/Layer.js',
|
||||
'test/tests/Group.js',
|
||||
'test/tests/Segment.js',
|
||||
|
||||
'test/tests/Path.js',
|
||||
'test/tests/PathStyle.js',
|
||||
'test/tests/Path_Shapes.js',
|
||||
'test/tests/Path_Drawing_Commands.js',
|
||||
'test/tests/Path_Curves.js',
|
||||
'test/tests/Path_Bounds.js',
|
||||
'test/tests/Path_Length.js',
|
||||
'test/tests/CompoundPath.js',
|
||||
|
||||
'test/tests/PlacedSymbol.js',
|
||||
|
||||
'test/tests/HitResult.js'
|
||||
);
|
||||
}
|
||||
|
||||
for (var i = 0; i < sources.length; i++) {
|
||||
document.write('<script type="text/javascript" src="' + (window.root || '')
|
||||
+ sources[i] + '"></script>');
|
||||
}
|
||||
|
||||
// Append a bit of code that names our classes.
|
||||
// See src/paper.js for an in-depth explanation.
|
||||
document.write('<script type="text/javascript">\
|
||||
Base.each(this, function(val, key) {\
|
||||
if (val && val.prototype instanceof Base)\
|
||||
val._name = key;\
|
||||
});\
|
||||
</script>');
|
||||
|
29
src/load/load.js
Normal file
29
src/load/load.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// This file is only used by examples and unit tests, using prepro.js to
|
||||
// 'preprocess' it on the fly in the browser, avoiding the step of having to
|
||||
// manually preprocess it after each change.
|
||||
|
||||
// Define options for compile-time preprocessing.
|
||||
var options = {
|
||||
browser: true,
|
||||
stats: true,
|
||||
tests: this.tests,
|
||||
version: 'dev'
|
||||
};
|
||||
|
||||
include('../paper.js');
|
43
src/load/prepro.js
Normal file
43
src/load/prepro.js
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// Since loading prepro.js is also used further down to prevent inline scripts
|
||||
// from executing right away, check that its actual code is only executed once.
|
||||
if (!window.include) {
|
||||
// Determine the source of prepro.js, so we can use it to prevent inline
|
||||
// scripts from loading straight away.
|
||||
var scripts = document.getElementsByTagName('script');
|
||||
var script = scripts[scripts.length - 1];
|
||||
var self = script.getAttribute('src');
|
||||
var root = self.match(/^(.*\/)/)[1];
|
||||
|
||||
window.include = function(url) {
|
||||
url = root + url;
|
||||
var newRoot = url.match(/^(.*\/)/)[1];
|
||||
// Load prepro.js again, just to prevent the setting of newRoot frome
|
||||
// executing straight away, and delaying it until right before the
|
||||
// script at 'url' is loaded.
|
||||
document.write([
|
||||
'<script type="text/javascript" src="', self, '"></script>',
|
||||
// Set newRoot, so include() from 'url' load from the right place
|
||||
'<script type="text/javascript">root = "', newRoot, '";</script>',
|
||||
// Load the actual script
|
||||
'<script type="text/javascript" src="', url, '"></script>',
|
||||
// Set root back to the root before
|
||||
'<script type="text/javascript">root = "', root, '";</script>'
|
||||
].join(''));
|
||||
}
|
||||
}
|
54
src/paper.js
54
src/paper.js
|
@ -136,6 +136,10 @@ var paper = new function() {
|
|||
// Inline Bootstrap core (the Base class) inside the paper scope first:
|
||||
/*#*/ include('../lib/bootstrap.js');
|
||||
|
||||
/*#*/ if (options.stats) {
|
||||
/*#*/ include('../lib/stats.js');
|
||||
/*#*/ } // options.stats
|
||||
|
||||
/*#*/ include('core/Base.js');
|
||||
/*#*/ include('core/PaperScope.js');
|
||||
|
||||
|
@ -187,7 +191,6 @@ var paper = new function() {
|
|||
/*#*/ include('color/GradientStop.js');
|
||||
|
||||
/*#*/ if (options.browser) {
|
||||
|
||||
/*#*/ include('browser/DomElement.js');
|
||||
/*#*/ include('browser/DomEvent.js');
|
||||
|
||||
|
@ -198,7 +201,6 @@ var paper = new function() {
|
|||
|
||||
/*#*/ include('tool/ToolEvent.js');
|
||||
/*#*/ include('tool/Tool.js');
|
||||
|
||||
/*#*/ } // options.browser
|
||||
|
||||
/*#*/ include('util/CanvasProvider.js');
|
||||
|
@ -207,16 +209,48 @@ var paper = new function() {
|
|||
|
||||
/*#*/ 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
|
||||
// that allow us to use their names.
|
||||
// Setting Function#name is not possible, as that is read-only.
|
||||
Base.each(this, function(val, key) {
|
||||
if (val && val.prototype instanceof Base)
|
||||
val._name = key;
|
||||
});
|
||||
/*#*/ include('core/initialize.js');
|
||||
|
||||
/*#*/ if (options.version != 'dev') {
|
||||
// Finally inject the classes set on 'this' into the PaperScope class and create
|
||||
// the first PaperScope and return it, all in one statement.
|
||||
// The version for 'dev' of this happens in core/initialize.js, since it depends
|
||||
// on sequentiality of include() loading.
|
||||
return new (PaperScope.inject(this));
|
||||
/*#*/ } // options.version != 'dev'
|
||||
};
|
||||
|
||||
/*#*/ // Load unit tests after library if we're asked to do so
|
||||
/*#*/ if (options.tests) {
|
||||
/*#*/ include('../test/lib/qunit/qunit.js');
|
||||
/*#*/ include('../test/lib/helpers.js');
|
||||
|
||||
/*#*/ include('../test/tests/Point.js');
|
||||
/*#*/ include('../test/tests/Size.js');
|
||||
/*#*/ include('../test/tests/Rectangle.js');
|
||||
|
||||
/*#*/ include('../test/tests/Color.js');
|
||||
|
||||
/*#*/ include('../test/tests/Project.js');
|
||||
|
||||
/*#*/ include('../test/tests/Item.js');
|
||||
/*#*/ include('../test/tests/Item_Cloning.js');
|
||||
/*#*/ include('../test/tests/Item_Order.js');
|
||||
|
||||
/*#*/ include('../test/tests/Layer.js');
|
||||
/*#*/ include('../test/tests/Group.js');
|
||||
/*#*/ include('../test/tests/Segment.js');
|
||||
|
||||
/*#*/ include('../test/tests/Path.js');
|
||||
/*#*/ include('../test/tests/PathStyle.js');
|
||||
/*#*/ include('../test/tests/Path_Shapes.js');
|
||||
/*#*/ include('../test/tests/Path_Drawing_Commands.js');
|
||||
/*#*/ include('../test/tests/Path_Curves.js');
|
||||
/*#*/ include('../test/tests/Path_Bounds.js');
|
||||
/*#*/ include('../test/tests/Path_Length.js');
|
||||
/*#*/ include('../test/tests/CompoundPath.js');
|
||||
|
||||
/*#*/ include('../test/tests/PlacedSymbol.js');
|
||||
|
||||
/*#*/ include('../test/tests/HitResult.js');
|
||||
/*#*/ } // options.tests
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
<head>
|
||||
<title>Paper.js Tests</title>
|
||||
<link rel="stylesheet" href="lib/qunit/qunit.css" type="text/css" media="screen">
|
||||
<script type="text/javascript"> var root = '../', tests = true; </script>
|
||||
<script type="text/javascript" src="../src/load.js"></script>
|
||||
<script type="text/javascript" src="../src/load/prepro.js"></script>
|
||||
<script type="text/javascript">var tests = true;</script>
|
||||
<script type="text/javascript" src="../src/load/load.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1 id="qunit-header">QUnit Test Suite</h1>
|
||||
|
|
Loading…
Reference in a new issue