update jsdom API. close #36

This commit is contained in:
Лаврёнов Антон
2015-03-13 15:33:48 +00:00
parent 2345ae2658
commit 796f949a31
5 changed files with 237 additions and 236 deletions

View File

@@ -1,8 +1,8 @@
{ {
"name": "konva", "name": "konva",
"version": "0.9.0", "version": "0.9.5",
"authors": [ "authors": [
"Eric Rowell", "Anton Lavrenov" "Anton Lavrenov", "Eric Rowell"
], ],
"homepage": "http://konvajs.github.io", "homepage": "http://konvajs.github.io",
"description": "Konva is an HTML5 Canvas JavaScript framework that enables high performance animations, transitions, node nesting, layering, filtering, caching, event handling for desktop and mobile applications, and much more.", "description": "Konva is an HTML5 Canvas JavaScript framework that enables high performance animations, transitions, node nesting, layering, filtering, caching, event handling for desktop and mobile applications, and much more.",
@@ -21,6 +21,7 @@
"*.yml", "*.yml",
".jshitrc", ".jshitrc",
".npmignore", ".npmignore",
"package.json",
".travis.yml", ".travis.yml",
".gitignore", ".gitignore",
"Gruntfile.js" "Gruntfile.js"

450
konva.js
View File

@@ -1,9 +1,9 @@
/* /*
* Konva JavaScript Framework v0.9.0 * Konva JavaScript Framework v0.9.5
* http://konvajs.github.io/ * http://konvajs.github.io/
* Licensed under the MIT or GPL Version 2 licenses. * Licensed under the MIT or GPL Version 2 licenses.
* Date: 2015-02-27 * Date: 2015-03-13
* *
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS) * Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
* Modified work Copyright (C) 2014 - 2015 by Anton Lavrenov (Konva) * Modified work Copyright (C) 2014 - 2015 by Anton Lavrenov (Konva)
@@ -36,7 +36,7 @@ var Konva = {};
Konva = { Konva = {
// public // public
version: '0.9.0', version: '0.9.5',
// private // private
stages: [], stages: [],
@@ -601,7 +601,7 @@ var Konva = {};
var jsdom = require('jsdom').jsdom; var jsdom = require('jsdom').jsdom;
Konva.document = jsdom('<!DOCTYPE html><html><head></head><body></body></html>'); Konva.document = jsdom('<!DOCTYPE html><html><head></head><body></body></html>');
Konva.window = Konva.document.createWindow(); Konva.window = Konva.document.parentWindow;
Konva.window.Image = Canvas.Image; Konva.window.Image = Canvas.Image;
Konva._nodeCanvas = Canvas; Konva._nodeCanvas = Canvas;
} }
@@ -4663,32 +4663,32 @@ var Konva = {};
Konva.Collection.mapMethods(Konva.Node); Konva.Collection.mapMethods(Konva.Node);
})(); })();
;(function() { ;(function() {
/** /**
* Grayscale Filter * Grayscale Filter
* @function * @function
* @memberof Konva.Filters * @memberof Konva.Filters
* @param {Object} imageData * @param {Object} imageData
* @example * @example
* node.cache(); * node.cache();
* node.filters([Konva.Filters.Grayscale]); * node.filters([Konva.Filters.Grayscale]);
*/ */
Konva.Filters.Grayscale = function(imageData) { Konva.Filters.Grayscale = function(imageData) {
var data = imageData.data, var data = imageData.data,
len = data.length, len = data.length,
i, brightness; i, brightness;
for(i = 0; i < len; i += 4) { for(i = 0; i < len; i += 4) {
brightness = 0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2]; brightness = 0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2];
// red // red
data[i] = brightness; data[i] = brightness;
// green // green
data[i + 1] = brightness; data[i + 1] = brightness;
// blue // blue
data[i + 2] = brightness; data[i + 2] = brightness;
} }
}; };
})(); })();
;(function() { ;(function() {
/** /**
* Brighten Filter. * Brighten Filter.
@@ -4728,30 +4728,30 @@ var Konva = {};
*/ */
})(); })();
;(function() { ;(function() {
/** /**
* Invert Filter * Invert Filter
* @function * @function
* @memberof Konva.Filters * @memberof Konva.Filters
* @param {Object} imageData * @param {Object} imageData
* @example * @example
* node.cache(); * node.cache();
* node.filters([Konva.Filters.Invert]); * node.filters([Konva.Filters.Invert]);
*/ */
Konva.Filters.Invert = function(imageData) { Konva.Filters.Invert = function(imageData) {
var data = imageData.data, var data = imageData.data,
len = data.length, len = data.length,
i; i;
for(i = 0; i < len; i += 4) { for(i = 0; i < len; i += 4) {
// red // red
data[i] = 255 - data[i]; data[i] = 255 - data[i];
// green // green
data[i + 1] = 255 - data[i + 1]; data[i + 1] = 255 - data[i + 1];
// blue // blue
data[i + 2] = 255 - data[i + 2]; data[i + 2] = 255 - data[i + 2];
} }
}; };
})();;/* })();;/*
the Gauss filter the Gauss filter
master repo: https://github.com/pavelpower/konvajsGaussFilter/ master repo: https://github.com/pavelpower/konvajsGaussFilter/
@@ -5913,175 +5913,175 @@ var Konva = {};
* @param {Number} level between 0 and 1 * @param {Number} level between 0 and 1
* @returns {Number} * @returns {Number}
*/ */
})();;(function () { })();;(function () {
/** /**
* Noise Filter. Randomly adds or substracts to the color channels * Noise Filter. Randomly adds or substracts to the color channels
* @function * @function
* @name Noise * @name Noise
* @memberof Konva.Filters * @memberof Konva.Filters
* @param {Object} imageData * @param {Object} imageData
* @author ippo615 * @author ippo615
* @example * @example
* node.cache(); * node.cache();
* node.filters([Konva.Filters.Noise]); * node.filters([Konva.Filters.Noise]);
* node.noise(0.8); * node.noise(0.8);
*/ */
Konva.Filters.Noise = function (imageData) { Konva.Filters.Noise = function (imageData) {
var amount = this.noise() * 255, var amount = this.noise() * 255,
data = imageData.data, data = imageData.data,
nPixels = data.length, nPixels = data.length,
half = amount / 2, half = amount / 2,
i; i;
for (i = 0; i < nPixels; i += 4) { for (i = 0; i < nPixels; i += 4) {
data[i + 0] += half - 2 * half * Math.random(); data[i + 0] += half - 2 * half * Math.random();
data[i + 1] += half - 2 * half * Math.random(); data[i + 1] += half - 2 * half * Math.random();
data[i + 2] += half - 2 * half * Math.random(); data[i + 2] += half - 2 * half * Math.random();
} }
}; };
Konva.Factory.addGetterSetter(Konva.Node, 'noise', 0.2, null, Konva.Factory.afterSetFilter); Konva.Factory.addGetterSetter(Konva.Node, 'noise', 0.2, null, Konva.Factory.afterSetFilter);
/** /**
* get/set noise amount. Must be a value between 0 and 1. Use with {@link Konva.Filters.Noise} filter. * get/set noise amount. Must be a value between 0 and 1. Use with {@link Konva.Filters.Noise} filter.
* @name noise * @name noise
* @method * @method
* @memberof Konva.Node.prototype * @memberof Konva.Node.prototype
* @param {Number} noise * @param {Number} noise
* @returns {Number} * @returns {Number}
*/ */
})(); })();
;(function () { ;(function () {
/** /**
* Pixelate Filter. Averages groups of pixels and redraws * Pixelate Filter. Averages groups of pixels and redraws
* them as larger pixels * them as larger pixels
* @function * @function
* @name Pixelate * @name Pixelate
* @memberof Konva.Filters * @memberof Konva.Filters
* @param {Object} imageData * @param {Object} imageData
* @author ippo615 * @author ippo615
* @example * @example
* node.cache(); * node.cache();
* node.filters([Konva.Filters.Pixelate]); * node.filters([Konva.Filters.Pixelate]);
* node.pixelSize(10); * node.pixelSize(10);
*/ */
Konva.Filters.Pixelate = function (imageData) { Konva.Filters.Pixelate = function (imageData) {
var pixelSize = Math.ceil(this.pixelSize()), var pixelSize = Math.ceil(this.pixelSize()),
width = imageData.width, width = imageData.width,
height = imageData.height, height = imageData.height,
x, y, i, x, y, i,
//pixelsPerBin = pixelSize * pixelSize, //pixelsPerBin = pixelSize * pixelSize,
red, green, blue, alpha, red, green, blue, alpha,
nBinsX = Math.ceil(width / pixelSize), nBinsX = Math.ceil(width / pixelSize),
nBinsY = Math.ceil(height / pixelSize), nBinsY = Math.ceil(height / pixelSize),
xBinStart, xBinEnd, yBinStart, yBinEnd, xBinStart, xBinEnd, yBinStart, yBinEnd,
xBin, yBin, pixelsInBin; xBin, yBin, pixelsInBin;
imageData = imageData.data; imageData = imageData.data;
for (xBin = 0; xBin < nBinsX; xBin += 1) { for (xBin = 0; xBin < nBinsX; xBin += 1) {
for (yBin = 0; yBin < nBinsY; yBin += 1) { for (yBin = 0; yBin < nBinsY; yBin += 1) {
// Initialize the color accumlators to 0 // Initialize the color accumlators to 0
red = 0; red = 0;
green = 0; green = 0;
blue = 0; blue = 0;
alpha = 0; alpha = 0;
// Determine which pixels are included in this bin // Determine which pixels are included in this bin
xBinStart = xBin * pixelSize; xBinStart = xBin * pixelSize;
xBinEnd = xBinStart + pixelSize; xBinEnd = xBinStart + pixelSize;
yBinStart = yBin * pixelSize; yBinStart = yBin * pixelSize;
yBinEnd = yBinStart + pixelSize; yBinEnd = yBinStart + pixelSize;
// Add all of the pixels to this bin! // Add all of the pixels to this bin!
pixelsInBin = 0; pixelsInBin = 0;
for (x = xBinStart; x < xBinEnd; x += 1) { for (x = xBinStart; x < xBinEnd; x += 1) {
if( x >= width ){ continue; } if( x >= width ){ continue; }
for (y = yBinStart; y < yBinEnd; y += 1) { for (y = yBinStart; y < yBinEnd; y += 1) {
if( y >= height ){ continue; } if( y >= height ){ continue; }
i = (width * y + x) * 4; i = (width * y + x) * 4;
red += imageData[i + 0]; red += imageData[i + 0];
green += imageData[i + 1]; green += imageData[i + 1];
blue += imageData[i + 2]; blue += imageData[i + 2];
alpha += imageData[i + 3]; alpha += imageData[i + 3];
pixelsInBin += 1; pixelsInBin += 1;
} }
} }
// Make sure the channels are between 0-255 // Make sure the channels are between 0-255
red = red / pixelsInBin; red = red / pixelsInBin;
green = green / pixelsInBin; green = green / pixelsInBin;
blue = blue / pixelsInBin; blue = blue / pixelsInBin;
// Draw this bin // Draw this bin
for (x = xBinStart; x < xBinEnd; x += 1) { for (x = xBinStart; x < xBinEnd; x += 1) {
if( x >= width ){ continue; } if( x >= width ){ continue; }
for (y = yBinStart; y < yBinEnd; y += 1) { for (y = yBinStart; y < yBinEnd; y += 1) {
if( y >= height ){ continue; } if( y >= height ){ continue; }
i = (width * y + x) * 4; i = (width * y + x) * 4;
imageData[i + 0] = red; imageData[i + 0] = red;
imageData[i + 1] = green; imageData[i + 1] = green;
imageData[i + 2] = blue; imageData[i + 2] = blue;
imageData[i + 3] = alpha; imageData[i + 3] = alpha;
} }
} }
} }
} }
}; };
Konva.Factory.addGetterSetter(Konva.Node, 'pixelSize', 8, null, Konva.Factory.afterSetFilter); Konva.Factory.addGetterSetter(Konva.Node, 'pixelSize', 8, null, Konva.Factory.afterSetFilter);
/** /**
* get/set pixel size. Use with {@link Konva.Filters.Pixelate} filter. * get/set pixel size. Use with {@link Konva.Filters.Pixelate} filter.
* @name pixelSize * @name pixelSize
* @method * @method
* @memberof Konva.Node.prototype * @memberof Konva.Node.prototype
* @param {Integer} pixelSize * @param {Integer} pixelSize
* @returns {Integer} * @returns {Integer}
*/ */
})();;(function () { })();;(function () {
/** /**
* Threshold Filter. Pushes any value above the mid point to * Threshold Filter. Pushes any value above the mid point to
* the max and any value below the mid point to the min. * the max and any value below the mid point to the min.
* This affects the alpha channel. * This affects the alpha channel.
* @function * @function
* @name Threshold * @name Threshold
* @memberof Konva.Filters * @memberof Konva.Filters
* @param {Object} imageData * @param {Object} imageData
* @author ippo615 * @author ippo615
* @example * @example
* node.cache(); * node.cache();
* node.filters([Konva.Filters.Threshold]); * node.filters([Konva.Filters.Threshold]);
* node.threshold(0.1); * node.threshold(0.1);
*/ */
Konva.Filters.Threshold = function (imageData) { Konva.Filters.Threshold = function (imageData) {
var level = this.threshold() * 255, var level = this.threshold() * 255,
data = imageData.data, data = imageData.data,
len = data.length, len = data.length,
i; i;
for (i = 0; i < len; i += 1) { for (i = 0; i < len; i += 1) {
data[i] = data[i] < level ? 0 : 255; data[i] = data[i] < level ? 0 : 255;
} }
}; };
Konva.Factory.addGetterSetter(Konva.Node, 'threshold', 0.5, null, Konva.Factory.afterSetFilter); Konva.Factory.addGetterSetter(Konva.Node, 'threshold', 0.5, null, Konva.Factory.afterSetFilter);
/** /**
* get/set threshold. Must be a value between 0 and 1. Use with {@link Konva.Filters.Threshold} or {@link Konva.Filters.Mask} filter. * get/set threshold. Must be a value between 0 and 1. Use with {@link Konva.Filters.Threshold} or {@link Konva.Filters.Mask} filter.
* @name threshold * @name threshold
* @method * @method
* @memberof Konva.Node.prototype * @memberof Konva.Node.prototype
* @param {Number} threshold * @param {Number} threshold
* @returns {Number} * @returns {Number}
*/ */
})();;(function() { })();;(function() {
/** /**
* Sepia Filter * Sepia Filter
@@ -7039,7 +7039,7 @@ var Konva = {};
params.node = this; params.node = this;
params.onFinish = function() { params.onFinish = function() {
tween.destroy(); tween.destroy();
onFinish(); onFinish && onFinish();
}; };
var tween = new Konva.Tween(params); var tween = new Konva.Tween(params);
tween.play(); tween.play();
@@ -9809,7 +9809,6 @@ var Konva = {};
DIV = 'div', DIV = 'div',
RELATIVE = 'relative', RELATIVE = 'relative',
INLINE_BLOCK = 'inline-block',
KONVA_CONTENT = 'konvajs-content', KONVA_CONTENT = 'konvajs-content',
SPACE = ' ', SPACE = ' ',
UNDERSCORE = '_', UNDERSCORE = '_',
@@ -10472,7 +10471,6 @@ var Konva = {};
// content // content
this.content = Konva.document.createElement(DIV); this.content = Konva.document.createElement(DIV);
this.content.style.position = RELATIVE; this.content.style.position = RELATIVE;
this.content.style.display = INLINE_BLOCK;
this.content.className = KONVA_CONTENT; this.content.className = KONVA_CONTENT;
this.content.setAttribute('role', 'presentation'); this.content.setAttribute('role', 'presentation');
container.appendChild(this.content); container.appendChild(this.content);

14
konva.min.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -1,5 +1,5 @@
var fs = require('fs'), var fs = require('fs'),
Konva = require('./dist/konva-dev'); Konva = require('../dist/konva-dev');
// Create stage. Container parameter is not required in NodeJS. // Create stage. Container parameter is not required in NodeJS.

View File

@@ -381,7 +381,7 @@ var Konva = {};
var jsdom = require('jsdom').jsdom; var jsdom = require('jsdom').jsdom;
Konva.document = jsdom('<!DOCTYPE html><html><head></head><body></body></html>'); Konva.document = jsdom('<!DOCTYPE html><html><head></head><body></body></html>');
Konva.window = Konva.document.createWindow(); Konva.window = Konva.document.parentWindow;
Konva.window.Image = Canvas.Image; Konva.window.Image = Canvas.Image;
Konva._nodeCanvas = Canvas; Konva._nodeCanvas = Canvas;
} }