mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-08-28 22:08:54 -04:00
Simplify the way the paper namespace is created and populated.
This commit is contained in:
parent
c6d79f964c
commit
92bf51a7cc
29 changed files with 38 additions and 50 deletions
|
@ -3,7 +3,7 @@
|
|||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
||||
var Matrix = Base.extend({
|
||||
var Matrix = this.Matrix = Base.extend({
|
||||
beans: true,
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* Paper.js document. It is also used to represent two dimensional vector
|
||||
* objects.
|
||||
*/
|
||||
var Point = Base.extend({
|
||||
var Point = this.Point = Base.extend({
|
||||
beans: true,
|
||||
|
||||
initialize: function() {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var Rectangle = Base.extend({
|
||||
var Rectangle = this.Rectangle = Base.extend({
|
||||
beans: true,
|
||||
|
||||
initialize: function() {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var Size = Base.extend({
|
||||
var Size = this.Size = Base.extend({
|
||||
initialize: function() {
|
||||
if (arguments.length == 2) {
|
||||
this.width = arguments[0];
|
||||
|
|
10
src/build.js
10
src/build.js
|
@ -40,14 +40,4 @@ var paper = new function() {
|
|||
//#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',
|
||||
'Document', 'Symbol', 'Item', 'Group', 'Layer', 'Raster', 'PlacedSymbol',
|
||||
'PathStyle', 'Segment', 'Curve', 'PathItem', 'Path', 'CompoundPath',
|
||||
'Color', 'RGBColor', 'GrayColor', 'GradientColor', 'Gradient',
|
||||
'GradientStop', 'ToolEvent', 'ToolHandler', 'Tool'],
|
||||
function(name) {
|
||||
this[name] = eval(name);
|
||||
}, paper);
|
||||
|
||||
};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var Color = Base.extend({
|
||||
var Color = this.Color = Base.extend({
|
||||
beans: true,
|
||||
|
||||
initialize: function() {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var Gradient = Base.extend({
|
||||
var Gradient = this.Gradient = Base.extend({
|
||||
initialize: function() {
|
||||
this.stops = [
|
||||
new GradientStop('white', 0),
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var GradientColor = Color.extend({
|
||||
var GradientColor = this.GradientColor = Color.extend({
|
||||
beans: true,
|
||||
|
||||
initialize: function(gradient, origin, destination, hilite) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var GradientStop = Base.extend({
|
||||
var GradientStop = this.GradientStop = Base.extend({
|
||||
beans: true,
|
||||
|
||||
// TODO: support midPoint? (initial tests didn't look nice)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var GrayColor = Color.extend({
|
||||
var GrayColor = this.GrayColor = Color.extend({
|
||||
beans: true,
|
||||
|
||||
initialize: function() {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var RGBColor = Color.extend(new function() {
|
||||
var RGBColor = this.RGBColor = Color.extend(new function() {
|
||||
// TODO: convert hex codes to [r,g,b]?
|
||||
var namedColors = {
|
||||
lightpink: 'ffb6c1', pink: 'ffc0cb', crimson: 'dc143c',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var Document = Base.extend({
|
||||
var Document = this.Document = Base.extend({
|
||||
beans: true,
|
||||
|
||||
initialize: function(canvas) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var DocumentView = Base.extend({
|
||||
var DocumentView = this.DocumentView = Base.extend({
|
||||
beans: true,
|
||||
|
||||
initialize: function(document) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var Symbol = Base.extend({
|
||||
var Symbol = this.Symbol = Base.extend({
|
||||
beans: true,
|
||||
|
||||
initialize: function(item) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var Group = Item.extend({
|
||||
var Group = this.Group = Item.extend({
|
||||
beans: true,
|
||||
initialize: function(items) {
|
||||
this.base();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var Item = Base.extend({
|
||||
var Item = this.Item = Base.extend({
|
||||
beans: true,
|
||||
|
||||
initialize: function() {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var Layer = Group.extend({
|
||||
var Layer = this.Layer = Group.extend({
|
||||
beans: true,
|
||||
|
||||
initialize: function() {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var PathStyle = Base.extend(new function() {
|
||||
var PathStyle = this.PathStyle = Base.extend(new function() {
|
||||
var keys = ['windingRule', 'resolution', 'strokeColor', 'strokeWidth',
|
||||
'strokeCap', 'strokeJoin', 'dashOffset','dashArray', 'miterLimit',
|
||||
'strokeOverprint', 'fillColor', 'fillOverprint'];
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var PlacedSymbol = Item.extend({
|
||||
var PlacedSymbol = this.PlacedSymbol = Item.extend({
|
||||
beans: true,
|
||||
|
||||
initialize: function() {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var Raster = Item.extend({
|
||||
var Raster = this.Raster = Item.extend({
|
||||
beans: true,
|
||||
|
||||
// TODO: implement url / type, width, height
|
||||
|
|
14
src/paper.js
14
src/paper.js
|
@ -1,10 +1,8 @@
|
|||
var paper = new Base().inject({
|
||||
document: null,
|
||||
documents: [],
|
||||
this.document = null;
|
||||
this.documents = [];
|
||||
|
||||
install: function(scope) {
|
||||
for (var i in paper) {
|
||||
scope[i] = paper[i];
|
||||
}
|
||||
this.install = function(scope) {
|
||||
for (var i in this) {
|
||||
scope[i] = this[i];
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var CompoundPath = PathItem.extend({
|
||||
var CompoundPath = this.CompoundPath = PathItem.extend({
|
||||
initialize: function(items) {
|
||||
this.base();
|
||||
this.children = [];
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var Curve = Base.extend({
|
||||
var Curve = this.Curve = Base.extend({
|
||||
initialize: function() {
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var Path = PathItem.extend({
|
||||
var Path = this.Path = PathItem.extend({
|
||||
beans: true,
|
||||
|
||||
initialize: function(/* segments */) {
|
||||
|
@ -12,8 +12,10 @@ var Path = PathItem.extend({
|
|||
if (!segments || !Array.isArray(segments)
|
||||
|| typeof segments[0] != 'object')
|
||||
segments = arguments;
|
||||
for (var i = 0, l = segments.length; i < l; i++)
|
||||
this._add(Segment.read(segments, i, 1));
|
||||
for (var i = 0, l = segments.length; i < l; i++) {
|
||||
var seg = Segment.read(segments, i, 1);
|
||||
this._add(seg);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var PathItem = Item.extend({
|
||||
var PathItem = this.PathItem = Item.extend({
|
||||
beans: true,
|
||||
|
||||
initialize: function() {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var Segment = Base.extend({
|
||||
var Segment = this.Segment = Base.extend({
|
||||
initialize: function() {
|
||||
if (arguments.length == 0) {
|
||||
this.point = new Point();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var Tool = ToolHandler.extend(new function() {
|
||||
var Tool = this.Tool = ToolHandler.extend(new function() {
|
||||
function viewToArtwork(event, document) {
|
||||
var point = Point.create(event.offset.x, event.offset.y);
|
||||
// TODO: always the active view?
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var ToolHandler = Base.extend({
|
||||
var ToolHandler = this.ToolHandler = Base.extend({
|
||||
beans: true,
|
||||
|
||||
/**
|
||||
|
@ -48,7 +48,7 @@ var ToolHandler = Base.extend({
|
|||
|
||||
getFixedDistance: function() {
|
||||
if (this._minDistance != null
|
||||
&& this._minDistance == this._maxDistance)
|
||||
&& this._minDistance.equals(this._maxDistance))
|
||||
return this._minDistance;
|
||||
return null;
|
||||
},
|
||||
|
|
|
@ -114,9 +114,7 @@ var PaperScript = new function() {
|
|||
}
|
||||
|
||||
function run(code) {
|
||||
// Use paper.extend() to create a paper scope within which the code is
|
||||
// evaluated.
|
||||
with (paper.extend()) {
|
||||
with (paper) {
|
||||
var tool = /onMouse(?:Up|Down|Move|Drag)/.test(code) && new Tool();
|
||||
var res = eval(compile(code));
|
||||
if (tool) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue