diff --git a/konva.js b/konva.js index 5cab7e1b..c060243f 100644 --- a/konva.js +++ b/konva.js @@ -2,7 +2,7 @@ * Konva JavaScript Framework v1.6.4 * http://konvajs.github.io/ * Licensed under the MIT or GPL Version 2 licenses. - * Date: Thu Jul 27 2017 + * Date: Fri Jul 28 2017 * * Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS) * Modified work Copyright (C) 2014 - 2017 by Anton Lavrenov (Konva) @@ -197,12 +197,11 @@ var ua = userAgent.toLowerCase(), // jQuery UA regex match = /(chrome)[ \/]([\w.]+)/.exec(ua) || - /(webkit)[ \/]([\w.]+)/.exec(ua) || - /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) || - /(msie) ([\w.]+)/.exec(ua) || - ua.indexOf('compatible') < 0 && - /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) || - [], + /(webkit)[ \/]([\w.]+)/.exec(ua) || + /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) || + /(msie) ([\w.]+)/.exec(ua) || + (ua.indexOf('compatible') < 0 && + /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua)) || [], // adding mobile flag as well mobile = !!userAgent.match( /Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i @@ -228,7 +227,7 @@ ? window : typeof WorkerGlobalScope !== 'undefined' ? self : {}; - Konva.UA = Konva._parseUA(glob.navigator && glob.navigator.userAgent || ''); + Konva.UA = Konva._parseUA((glob.navigator && glob.navigator.userAgent) || ''); if (glob.Konva) { console.error( @@ -445,8 +444,8 @@ var s = Math.sin(rad); var m11 = this.m[0] * c + this.m[2] * s; var m12 = this.m[1] * c + this.m[3] * s; - var m21 = this.m[0] * (-s) + this.m[2] * c; - var m22 = this.m[1] * (-s) + this.m[3] * c; + var m21 = this.m[0] * -s + this.m[2] * c; + var m22 = this.m[1] * -s + this.m[3] * c; this.m[0] = m11; this.m[1] = m12; this.m[2] = m21; @@ -518,8 +517,8 @@ invert: function() { var d = 1 / (this.m[0] * this.m[3] - this.m[1] * this.m[2]); var m0 = this.m[3] * d; - var m1 = (-this.m[1]) * d; - var m2 = (-this.m[2]) * d; + var m1 = -this.m[1] * d; + var m2 = -this.m[2] * d; var m3 = this.m[0] * d; var m4 = d * (this.m[2] * this.m[5] - this.m[3] * this.m[4]); var m5 = d * (this.m[1] * this.m[4] - this.m[0] * this.m[5]); @@ -809,9 +808,11 @@ return false; } var firstChar = selector[0]; - return firstChar === '#' || + return ( + firstChar === '#' || firstChar === '.' || - firstChar === firstChar.toUpperCase(); + firstChar === firstChar.toUpperCase() + ); }, createCanvasElement: function() { var canvas = Konva.document.createElement('canvas'); @@ -825,7 +826,7 @@ return typeof exports !== 'object'; }, _isInDocument: function(el) { - while (el = el.parentNode) { + while ((el = el.parentNode)) { if (el == Konva.document) { return true; } @@ -896,8 +897,8 @@ hex = hex.replace(HASH, EMPTY_STRING); var bigint = parseInt(hex, 16); return { - r: bigint >> 16 & 255, - g: bigint >> 8 & 255, + r: (bigint >> 16) & 255, + g: (bigint >> 8) & 255, b: bigint & 255 }; }, @@ -907,7 +908,7 @@ * @memberof Konva.Util.prototype */ getRandomColor: function() { - var randColor = (Math.random() * 0xffffff << 0).toString(16); + var randColor = ((Math.random() * 0xffffff) << 0).toString(16); while (randColor.length < 6) { randColor = ZERO + randColor; } @@ -970,11 +971,13 @@ // from https://github.com/component/color-parser colorToRGBA: function(str) { str = str || 'black'; - return Konva.Util._namedColorToRBA(str) || + return ( + Konva.Util._namedColorToRBA(str) || Konva.Util._hex3ColorToRGBA(str) || Konva.Util._hex6ColorToRGBA(str) || Konva.Util._rgbColorToRGBA(str) || - Konva.Util._rgbaColorToRGBA(str); + Konva.Util._rgbaColorToRGBA(str) + ); }, // Parse named css color. Like "green" _namedColorToRBA: function(str) { @@ -1287,7 +1290,8 @@ context = canvas.getContext('2d'), _pixelRatio = (function() { var devicePixelRatio = Konva.window.devicePixelRatio || 1, - backingStoreRatio = context.webkitBackingStorePixelRatio || + backingStoreRatio = + context.webkitBackingStorePixelRatio || context.mozBackingStorePixelRatio || context.msBackingStorePixelRatio || context.oBackingStorePixelRatio || @@ -2261,7 +2265,8 @@ }, addDeprecatedGetterSetter: function(constructor, attr, def, validator) { var method = GET + Konva.Util._capitalize(attr); - var message = attr + + var message = + attr + ' property is deprecated and will be removed soon. Look at Konva change log for more information.'; constructor.prototype[method] = function() { Konva.Util.error(message); @@ -5604,12 +5609,12 @@ stackIn = stackStart; stackOut = stackEnd; for (x = 0; x < width; x++) { - pixels[yi + 3] = pa = a_sum * mul_sum >> shg_sum; + pixels[yi + 3] = pa = (a_sum * mul_sum) >> shg_sum; if (pa !== 0) { pa = 255 / pa; - pixels[yi] = (r_sum * mul_sum >> shg_sum) * pa; - pixels[yi + 1] = (g_sum * mul_sum >> shg_sum) * pa; - pixels[yi + 2] = (b_sum * mul_sum >> shg_sum) * pa; + pixels[yi] = ((r_sum * mul_sum) >> shg_sum) * pa; + pixels[yi + 1] = ((g_sum * mul_sum) >> shg_sum) * pa; + pixels[yi + 2] = ((b_sum * mul_sum) >> shg_sum) * pa; } else { pixels[yi] = pixels[yi + 1] = pixels[yi + 2] = 0; } @@ -5624,7 +5629,7 @@ b_out_sum -= stackIn.b; a_out_sum -= stackIn.a; - p = yw + ((p = x + radius + 1) < widthMinus1 ? p : widthMinus1) << 2; + p = (yw + ((p = x + radius + 1) < widthMinus1 ? p : widthMinus1)) << 2; r_in_sum += stackIn.r = pixels[p]; g_in_sum += stackIn.g = pixels[p + 1]; @@ -5682,7 +5687,7 @@ yp = width; for (i = 1; i <= radius; i++) { - yi = yp + x << 2; + yi = (yp + x) << 2; r_sum += (stack.r = pr = pixels[yi]) * (rbs = radiusPlus1 - i); g_sum += (stack.g = pg = pixels[yi + 1]) * rbs; @@ -5706,12 +5711,12 @@ stackOut = stackEnd; for (y = 0; y < height; y++) { p = yi << 2; - pixels[p + 3] = pa = a_sum * mul_sum >> shg_sum; + pixels[p + 3] = pa = (a_sum * mul_sum) >> shg_sum; if (pa > 0) { pa = 255 / pa; - pixels[p] = (r_sum * mul_sum >> shg_sum) * pa; - pixels[p + 1] = (g_sum * mul_sum >> shg_sum) * pa; - pixels[p + 2] = (b_sum * mul_sum >> shg_sum) * pa; + pixels[p] = ((r_sum * mul_sum) >> shg_sum) * pa; + pixels[p + 1] = ((g_sum * mul_sum) >> shg_sum) * pa; + pixels[p + 2] = ((b_sum * mul_sum) >> shg_sum) * pa; } else { pixels[p] = pixels[p + 1] = pixels[p + 2] = 0; } @@ -5726,8 +5731,10 @@ b_out_sum -= stackIn.b; a_out_sum -= stackIn.a; - p = x + - ((p = y + radiusPlus1) < heightMinus1 ? p : heightMinus1) * width << + p = + (x + + ((p = y + radiusPlus1) < heightMinus1 ? p : heightMinus1) * + width) << 2; r_sum += r_in_sum += stackIn.r = pixels[p]; @@ -6038,8 +6045,8 @@ brightness; for (i = 0; i < nPixels; i += 4) { - brightness = (0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2]) / - 255; + brightness = + (0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2]) / 255; data[i] = brightness * red; // r data[i + 1] = brightness * green; // g data[i + 2] = brightness * blue; // b @@ -7876,14 +7883,17 @@ shouldDrawHit: function(canvas) { var layer = this.getLayer(); var dd = Konva.DD; - var layerUnderDrag = dd && + var layerUnderDrag = + dd && Konva.isDragging() && Konva.DD.anim.getLayers().indexOf(layer) !== -1; - return (canvas && canvas.isCache) || + return ( + (canvas && canvas.isCache) || (layer && layer.hitGraphEnabled() && this.isVisible() && - !layerUnderDrag); + !layerUnderDrag) + ); }, getClientRect: function(skipTransform) { var minX, minY, maxX, maxY; @@ -7894,6 +7904,10 @@ height: 0 }; this.children.each(function(child) { + // skip invisible children + if (!child.isVisible()) { + return; + } var rect = child.getClientRect(); // skip invisible children (like empty groups) @@ -8245,12 +8259,14 @@ return this._getCache(HAS_SHADOW, this._hasShadow); }, _hasShadow: function() { - return this.getShadowEnabled() && + return ( + this.getShadowEnabled() && (this.getShadowOpacity() !== 0 && !!(this.getShadowColor() || this.getShadowBlur() || this.getShadowOffsetX() || - this.getShadowOffsetY())); + this.getShadowOffsetY())) + ); }, getShadowRGBA: function() { return this._getCache(SHADOW_RGBA, this._getShadowRGBA); @@ -8258,7 +8274,8 @@ _getShadowRGBA: function() { if (this.hasShadow()) { var rgba = Konva.Util.colorToRGBA(this.shadowColor()); - return 'rgba(' + + return ( + 'rgba(' + rgba.r + ',' + rgba.g + @@ -8266,7 +8283,8 @@ rgba.b + ',' + rgba.a * (this.getShadowOpacity() || 1) + - ')'; + ')' + ); } }, /** @@ -8322,18 +8340,20 @@ return this; }, _useBufferCanvas: function(caching) { - return (!caching && - (this.perfectDrawEnabled() && - this.getAbsoluteOpacity() !== 1 && - this.hasFill() && - this.hasStroke() && - this.getStage())) || + return ( + (!caching && + (this.perfectDrawEnabled() && + this.getAbsoluteOpacity() !== 1 && + this.hasFill() && + this.hasStroke() && + this.getStage())) || (this.perfectDrawEnabled() && this.hasShadow() && this.getAbsoluteOpacity() !== 1 && this.hasFill() && this.hasStroke() && - this.getStage()); + this.getStage()) + ); }, /** * return self rectangle (x, y, width, height) of shape. @@ -8350,8 +8370,8 @@ getSelfRect: function() { var size = this.getSize(); return { - x: this._centroid ? Math.round((-size.width) / 2) : 0, - y: this._centroid ? Math.round((-size.height) / 2) : 0, + x: this._centroid ? Math.round(-size.width / 2) : 0, + y: this._centroid ? Math.round(-size.height / 2) : 0, width: size.width, height: size.height }; @@ -11261,12 +11281,14 @@ } var RAF = (function() { - return Konva.global.requestAnimationFrame || + return ( + Konva.global.requestAnimationFrame || Konva.global.webkitRequestAnimationFrame || Konva.global.mozRequestAnimationFrame || Konva.global.oRequestAnimationFrame || Konva.global.msRequestAnimationFrame || - FRAF; + FRAF + ); })(); function requestAnimFrame() { @@ -11519,13 +11541,10 @@ var that = this, Anim = Konva.Animation; if (!this.batchAnim) { - this.batchAnim = new Anim( - function() { - // stop animation after first tick - that.batchAnim.stop(); - }, - this - ); + this.batchAnim = new Anim(function() { + // stop animation after first tick + that.batchAnim.stop(); + }, this); } if (!this.batchAnim.isRunning()) { @@ -11716,19 +11735,17 @@ this.node = node; this._id = idCounter++; - var layers = node.getLayer() || + var layers = + node.getLayer() || (node instanceof Konva.Stage ? node.getLayers() : null); if (!layers) { Konva.Util.error( 'Tween constructor have `node` that is not in a layer. Please add node into layer first.' ); } - this.anim = new Konva.Animation( - function() { - that.tween.onEnterFrame(); - }, - layers - ); + this.anim = new Konva.Animation(function() { + that.tween.onEnterFrame(); + }, layers); this.tween = new Tween( key, @@ -11865,7 +11882,8 @@ newVal.push((start[n] || 0) + diff[n] * i); } } else if (colorAttrs.indexOf(key) !== -1) { - newVal = 'rgba(' + + newVal = + 'rgba(' + Math.round(start.r + diff.r * i) + ',' + Math.round(start.g + diff.g * i) + @@ -12093,9 +12111,11 @@ } else { s = p / (2 * Math.PI) * Math.asin(c / a); } - return -(a * - Math.pow(2, 10 * (t -= 1)) * - Math.sin((t * d - s) * (2 * Math.PI) / p)) + b; + return ( + -(a * + Math.pow(2, 10 * (t -= 1)) * + Math.sin((t * d - s) * (2 * Math.PI) / p)) + b + ); }, /** * elastic ease out @@ -12120,11 +12140,11 @@ } else { s = p / (2 * Math.PI) * Math.asin(c / a); } - return a * - Math.pow(2, (-10) * t) * - Math.sin((t * d - s) * (2 * Math.PI) / p) + + return ( + a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + - b; + b + ); }, /** * elastic ease in out @@ -12150,18 +12170,22 @@ s = p / (2 * Math.PI) * Math.asin(c / a); } if (t < 1) { - return (-0.5) * - (a * - Math.pow(2, 10 * (t -= 1)) * - Math.sin((t * d - s) * (2 * Math.PI) / p)) + - b; + return ( + -0.5 * + (a * + Math.pow(2, 10 * (t -= 1)) * + Math.sin((t * d - s) * (2 * Math.PI) / p)) + + b + ); } - return a * - Math.pow(2, (-10) * (t -= 1)) * - Math.sin((t * d - s) * (2 * Math.PI) / p) * - 0.5 + + return ( + a * + Math.pow(2, -10 * (t -= 1)) * + Math.sin((t * d - s) * (2 * Math.PI) / p) * + 0.5 + c + - b; + b + ); }, /** * bounce ease out @@ -12196,9 +12220,9 @@ if (t < d / 2) { return Konva.Easings.BounceEaseIn(t * 2, 0, c, d) * 0.5 + b; } else { - return Konva.Easings.BounceEaseOut(t * 2 - d, 0, c, d) * 0.5 + - c * 0.5 + - b; + return ( + Konva.Easings.BounceEaseOut(t * 2 - d, 0, c, d) * 0.5 + c * 0.5 + b + ); } }, /** @@ -12215,7 +12239,7 @@ * @memberof Konva.Easings */ EaseOut: function(t, b, c, d) { - return (-c) * (t /= d) * (t - 2) + b; + return -c * (t /= d) * (t - 2) + b; }, /** * ease in out @@ -12226,7 +12250,7 @@ if ((t /= d / 2) < 1) { return c / 2 * t * t + b; } - return (-c) / 2 * (--t * (t - 2) - 1) + b; + return -c / 2 * (--t * (t - 2) - 1) + b; }, /** * strong ease in @@ -13828,9 +13852,11 @@ this.hitFunc(this._hitFunc); }, _useBufferCanvas: function() { - return (this.hasShadow() || this.getAbsoluteOpacity() !== 1) && + return ( + (this.hasShadow() || this.getAbsoluteOpacity() !== 1) && this.hasStroke() && - this.getStage(); + this.getStage() + ); }, _sceneFunc: function(context) { var width = this.getWidth(), @@ -14342,8 +14368,8 @@ * @returns {Number} */ getHeight: function() { - var isAuto = this.attrs.height === AUTO || - this.attrs.height === undefined; + var isAuto = + this.attrs.height === AUTO || this.attrs.height === undefined; return isAuto ? this.getTextHeight() * this.textArr.length * this.getLineHeight() + this.getPadding() * 2 @@ -14386,19 +14412,23 @@ // removing font variant will solve // fix for: https://github.com/konvajs/konva/issues/94 if (Konva.UA.isIE) { - return this.getFontStyle() + + return ( + this.getFontStyle() + SPACE + this.getFontSize() + PX_SPACE + - this.getFontFamily(); + this.getFontFamily() + ); } - return this.getFontStyle() + + return ( + this.getFontStyle() + SPACE + this.getFontVariant() + SPACE + this.getFontSize() + PX_SPACE + - this.getFontFamily(); + this.getFontFamily() + ); }, _addTextLine: function(line) { if (this.align() === JUSTIFY) { @@ -14410,8 +14440,10 @@ _getTextWidth: function(text) { var latterSpacing = this.getLetterSpacing(); var length = text.length; - return dummyContext.measureText(text).width + - (length ? latterSpacing * (length - 1) : 0); + return ( + dummyContext.measureText(text).width + + (length ? latterSpacing * (length - 1) : 0) + ); }, _setTextData: function() { var lines = this.getText().split('\n'), @@ -14449,7 +14481,7 @@ */ var low = 0, high = line.length, match = '', matchWidth = 0; while (low < high) { - var mid = low + high >>> 1, + var mid = (low + high) >>> 1, substr = line.slice(0, mid + 1), substrWidth = this._getTextWidth(substr); if (substrWidth <= maxWidth) { @@ -14469,10 +14501,9 @@ // a fitting substring was found if (wrapAtWord) { // try to find a space or dash where wrapping could be done - var wrapIndex = Math.max( - match.lastIndexOf(SPACE), - match.lastIndexOf(DASH) - ) + 1; + var wrapIndex = + Math.max(match.lastIndexOf(SPACE), match.lastIndexOf(DASH)) + + 1; if (wrapIndex > 0) { // re-cut the substring found at the space/dash position low = wrapIndex; @@ -15294,17 +15325,16 @@ context.fillShape(this); }, _useBufferCanvas: function() { - return (this.hasShadow() || this.getAbsoluteOpacity() !== 1) && - this.hasStroke(); + return ( + (this.hasShadow() || this.getAbsoluteOpacity() !== 1) && + this.hasStroke() + ); }, _setInterval: function() { var that = this; - this.interval = setInterval( - function() { - that._updateIndex(); - }, - 1000 / this.getFrameRate() - ); + this.interval = setInterval(function() { + that._updateIndex(); + }, 1000 / this.getFrameRate()); }, /** * start sprite animation @@ -15943,7 +15973,6 @@ cpy = p.shift(); points.push(cpx, cpy); break; - // Note: lineTo handlers need to be above this point case 'm': var dx = p.shift(); @@ -16294,8 +16323,8 @@ // Derived from: http://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes var psi = psiDeg * (Math.PI / 180.0); var xp = Math.cos(psi) * (x1 - x2) / 2.0 + Math.sin(psi) * (y1 - y2) / 2.0; - var yp = (-1) * Math.sin(psi) * (x1 - x2) / 2.0 + - Math.cos(psi) * (y1 - y2) / 2.0; + var yp = + -1 * Math.sin(psi) * (x1 - x2) / 2.0 + Math.cos(psi) * (y1 - y2) / 2.0; var lambda = xp * xp / (rx * rx) + yp * yp / (ry * ry); @@ -16317,7 +16346,7 @@ } var cxp = f * rx * yp / ry; - var cyp = f * (-ry) * xp / rx; + var cyp = f * -ry * xp / rx; var cx = (x1 + x2) / 2.0 + Math.cos(psi) * cxp - Math.sin(psi) * cyp; var cy = (y1 + y2) / 2.0 + Math.sin(psi) * cxp + Math.cos(psi) * cyp; @@ -16333,7 +16362,7 @@ }; var theta = vAngle([1, 0], [(xp - cxp) / rx, (yp - cyp) / ry]); var u = [(xp - cxp) / rx, (yp - cyp) / ry]; - var v = [((-1) * xp - cxp) / rx, ((-1) * yp - cyp) / ry]; + var v = [(-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry]; var dTheta = vAngle(u, v); if (vRatio(u, v) <= -1) { @@ -16707,7 +16736,8 @@ p1 = undefined; while ( - Math.abs(glyphWidth - currLen) / glyphWidth > 0.01 && attempts < 25 + Math.abs(glyphWidth - currLen) / glyphWidth > 0.01 && + attempts < 25 ) { attempts++; var cumulativePathLength = currLen; @@ -16715,7 +16745,8 @@ pathCmd = getNextPathSegment(); if ( - pathCmd && cumulativePathLength + pathCmd.pathLength < glyphWidth + pathCmd && + cumulativePathLength + pathCmd.pathLength < glyphWidth ) { cumulativePathLength += pathCmd.pathLength; pathCmd = undefined; @@ -16837,7 +16868,6 @@ pathCmd.points[3] ); break; - } if (p1 !== undefined) { @@ -16932,7 +16962,8 @@ }; // map TextPath methods to Text - Konva.TextPath.prototype._getContextFont = Konva.Text.prototype._getContextFont; + Konva.TextPath.prototype._getContextFont = + Konva.Text.prototype._getContextFont; Konva.Util.extend(Konva.TextPath, Konva.Shape); @@ -17186,7 +17217,7 @@ for (n = 1; n < sides; n++) { x = radius * Math.sin(n * 2 * Math.PI / sides); - y = (-1) * radius * Math.cos(n * 2 * Math.PI / sides); + y = -1 * radius * Math.cos(n * 2 * Math.PI / sides); context.lineTo(x, y); } context.closePath(); @@ -17371,7 +17402,7 @@ for (var n = 1; n < numPoints * 2; n++) { var radius = n % 2 === 0 ? outerRadius : innerRadius; var x = radius * Math.sin(n * Math.PI / numPoints); - var y = (-1) * radius * Math.cos(n * Math.PI / numPoints); + var y = -1 * radius * Math.cos(n * Math.PI / numPoints); context.lineTo(x, y); } context.closePath(); @@ -17613,7 +17644,7 @@ switch (pointerDirection) { case UP: x = width / 2; - y = (-1) * pointerHeight; + y = -1 * pointerHeight; break; case RIGHT: x = width + pointerWidth; @@ -17624,21 +17655,21 @@ y = height + pointerHeight; break; case LEFT: - x = (-1) * pointerWidth; + x = -1 * pointerWidth; y = height / 2; break; } tag.setAttrs({ - x: (-1) * x, - y: (-1) * y, + x: -1 * x, + y: -1 * y, width: width, height: height }); text.setAttrs({ - x: (-1) * x, - y: (-1) * y + x: -1 * x, + y: -1 * y }); } } @@ -17687,7 +17718,7 @@ if (pointerDirection === UP) { context.lineTo((width - pointerWidth) / 2, 0); - context.lineTo(width / 2, (-1) * pointerHeight); + context.lineTo(width / 2, -1 * pointerHeight); context.lineTo((width + pointerWidth) / 2, 0); } @@ -17747,7 +17778,7 @@ if (pointerDirection === LEFT) { context.lineTo(0, (height + pointerHeight) / 2); - context.lineTo((-1) * pointerWidth, height / 2); + context.lineTo(-1 * pointerWidth, height / 2); context.lineTo(0, (height - pointerHeight) / 2); } @@ -17989,7 +18020,7 @@ ctx.rotate(radians); ctx.moveTo(0, 0); ctx.lineTo(-length, width / 2); - ctx.lineTo(-length, (-width) / 2); + ctx.lineTo(-length, -width / 2); ctx.closePath(); ctx.restore(); @@ -18001,7 +18032,7 @@ ctx.rotate((Math.atan2(-dy, -dx) + PI2) % PI2); ctx.moveTo(0, 0); ctx.lineTo(-length, width / 2); - ctx.lineTo(-length, (-width) / 2); + ctx.lineTo(-length, -width / 2); ctx.closePath(); ctx.restore(); } diff --git a/konva.min.js b/konva.min.js index 0cbd2027..32d08148 100644 --- a/konva.min.js +++ b/konva.min.js @@ -2,7 +2,7 @@ * Konva JavaScript Framework v1.6.4 * http://konvajs.github.io/ * Licensed under the MIT or GPL Version 2 licenses. - * Date: Thu Jul 27 2017 + * Date: Fri Jul 28 2017 * * Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS) * Modified work Copyright (C) 2014 - 2017 by Anton Lavrenov (Konva) @@ -41,6 +41,6 @@ * node.cache(); * node.filters([Konva.Filters.Sepia]); */ -Konva.Filters.Sepia=function(t){var e,n,i,a,r,o,s,h,c,l=t.data,d=t.width,u=t.height,v=4*d;do{e=(u-1)*v,n=d;do{i=e+4*(n-1),a=l[i],r=l[i+1],o=l[i+2],s=.393*a+.769*r+.189*o,h=.349*a+.686*r+.168*o,c=.272*a+.534*r+.131*o,l[i]=s>255?255:s,l[i+1]=h>255?255:h,l[i+2]=c>255?255:c,l[i+3]=l[i+3]}while(--n)}while(--u)}}(),function(){"use strict";Konva.Filters.Solarize=function(t){var e=t.data,n=t.width,i=t.height,a=4*n,r=i;do{var o=(r-1)*a,s=n;do{var h=o+4*(s-1),c=e[h],l=e[h+1],d=e[h+2];c>127&&(c=255-c),l>127&&(l=255-l),d>127&&(d=255-d),e[h]=c,e[h+1]=l,e[h+2]=d}while(--s)}while(--r)}}(),function(){"use strict";var t=function(t,e,n){var i,a,r,o,s=t.data,h=e.data,c=t.width,l=t.height,d=n.polarCenterX||c/2,u=n.polarCenterY||l/2,v=0,f=0,g=0,p=0,m=Math.sqrt(d*d+u*u);a=c-d,r=l-u,o=Math.sqrt(a*a+r*r),m=o>m?o:m;var y,_,K,S,C=l,x=c,w=360/x*Math.PI/180;for(_=0;__?h:_;var K,S,C,x,w=u,b=d,F=n.polarRotation||0;for(a=0;af&&(C=S,x=0,w=-1),r=0;r0},removeChildren:function(){for(var t,e=Konva.Collection.toCollection(this.children),n=0;n1){for(var e=0;e0},destroy:function(){return t.Node.prototype.destroy.call(this),delete t.shapes[this.colorKey],this},_useBufferCanvas:function(t){return!t&&this.perfectDrawEnabled()&&1!==this.getAbsoluteOpacity()&&this.hasFill()&&this.hasStroke()&&this.getStage()||this.perfectDrawEnabled()&&this.hasShadow()&&1!==this.getAbsoluteOpacity()&&this.hasFill()&&this.hasStroke()&&this.getStage()},getSelfRect:function(){var t=this.getSize();return{x:this._centroid?Math.round(-t.width/2):0,y:this._centroid?Math.round(-t.height/2):0,width:t.width,height:t.height}},getClientRect:function(t){var e=this.getSelfRect(),n=this.hasStroke()&&this.strokeWidth()||0,i=e.width+n,a=e.height+n,r=this.hasShadow()?this.shadowOffsetX():0,o=this.hasShadow()?this.shadowOffsetY():0,s=i+Math.abs(r),h=a+Math.abs(o),c=this.hasShadow()&&this.shadowBlur()||0,l=s+2*c,d=h+2*c,u=0;Math.round(n/2)!==n/2&&(u=1);var v={width:l+u,height:d+u,x:-Math.round(n/2+c)+Math.min(r,0)+e.x,y:-Math.round(n/2+c)+Math.min(o,0)+e.y};return t?v:this._transformedRect(v)},drawScene:function(t,e,n,i){var a,r,o,s=this.getLayer(),h=t||s.getCanvas(),c=h.getContext(),l=this._cache.canvas,d=this.sceneFunc(),u=this.hasShadow(),v=this.hasStroke();if(!this.isVisible())return this;if(l)return c.save(),s._applyTransform(this,c,e),this._drawCachedSceneCanvas(c),c.restore(),this;if(!d)return this;if(c.save(),this._useBufferCanvas(n)&&!i){if(a=this.getStage(),r=a.bufferCanvas,o=r.getContext(),o.clear(),o.save(),o._applyLineJoin(this),!n)if(s)s._applyTransform(this,o,e);else{var f=this.getAbsoluteTransform(e).getMatrix();c.transform(f[0],f[1],f[2],f[3],f[4],f[5])}d.call(this,o),o.restore();var g=r.pixelRatio;u&&!h.hitCanvas?(c.save(),c._applyShadow(this),c._applyOpacity(this),c._applyGlobalCompositeOperation(this),c.drawImage(r._canvas,0,0,r.width/g,r.height/g),c.restore()):(c._applyOpacity(this),c._applyGlobalCompositeOperation(this),c.drawImage(r._canvas,0,0,r.width/g,r.height/g))}else{if(c._applyLineJoin(this),!n)if(s)s._applyTransform(this,c,e);else{var p=this.getAbsoluteTransform(e).getMatrix();c.transform(p[0],p[1],p[2],p[3],p[4],p[5])}u&&v&&!h.hitCanvas?(c.save(),n||(c._applyOpacity(this),c._applyGlobalCompositeOperation(this)),c._applyShadow(this),d.call(this,c),c.restore(),this.hasFill()&&this.getShadowForStrokeEnabled()&&d.call(this,c)):u&&!h.hitCanvas?(c.save(),n||(c._applyOpacity(this),c._applyGlobalCompositeOperation(this)),c._applyShadow(this),d.call(this,c),c.restore()):(n||(c._applyOpacity(this),c._applyGlobalCompositeOperation(this)),d.call(this,c))}return c.restore(),this},drawHit:function(t,e,n){var i=this.getLayer(),a=t||i.hitCanvas,r=a.getContext(),o=this.hitFunc()||this.sceneFunc(),s=this._cache.canvas,h=s&&s.hit;if(!this.shouldDrawHit(a))return this;if(i&&i.clearHitCache(),h)return r.save(),i._applyTransform(this,r,e),this._drawCachedHitCanvas(r),r.restore(),this;if(!o)return this;if(r.save(),r._applyLineJoin(this),!n)if(i)i._applyTransform(this,r,e);else{var c=this.getAbsoluteTransform(e).getMatrix();r.transform(c[0],c[1],c[2],c[3],c[4],c[5])}return o.call(this,r),r.restore(),this},drawHitFromCache:function(e){var n,i,a,r,o,s,h=e||0,c=this._cache.canvas,l=this._getCachedSceneCanvas(),d=c.hit,u=d.getContext(),v=d.getWidth(),f=d.getHeight();u.clear(),u.drawImage(l._canvas,0,0,v,f);try{for(n=u.getImageData(0,0,v,f),i=n.data,a=i.length,r=t.Util._hexToRgb(this.colorKey),o=0;oh?(i[o]=r.r,i[o+1]=r.g,i[o+2]=r.b,i[o+3]=255):i[o+3]=0;u.putImageData(n,0,0)}catch(e){t.Util.error("Unable to draw hit graph from cached scene canvas. "+e.message)}return this}}),t.Util.extend(t.Shape,t.Node),t.Factory.addGetterSetter(t.Shape,"stroke"),t.Factory.addDeprecatedGetterSetter(t.Shape,"strokeRed",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"strokeGreen",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"strokeBlue",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"strokeAlpha",1,t.Validators.alphaComponent),t.Factory.addGetterSetter(t.Shape,"strokeWidth",2),t.Factory.addGetterSetter(t.Shape,"strokeHitEnabled",!0),t.Factory.addGetterSetter(t.Shape,"perfectDrawEnabled",!0),t.Factory.addGetterSetter(t.Shape,"shadowForStrokeEnabled",!0),t.Factory.addGetterSetter(t.Shape,"lineJoin"),t.Factory.addGetterSetter(t.Shape,"lineCap"),t.Factory.addGetterSetter(t.Shape,"sceneFunc"),t.Factory.addGetterSetter(t.Shape,"hitFunc"),t.Factory.addGetterSetter(t.Shape,"dash"),t.Factory.addGetterSetter(t.Shape,"dashOffset",0),t.Factory.addGetterSetter(t.Shape,"shadowColor"),t.Factory.addDeprecatedGetterSetter(t.Shape,"shadowRed",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"shadowGreen",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"shadowBlue",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"shadowAlpha",1,t.Validators.alphaComponent),t.Factory.addGetterSetter(t.Shape,"shadowBlur"),t.Factory.addGetterSetter(t.Shape,"shadowOpacity"),t.Factory.addComponentsGetterSetter(t.Shape,"shadowOffset",["x","y"]),t.Factory.addGetterSetter(t.Shape,"shadowOffsetX",0),t.Factory.addGetterSetter(t.Shape,"shadowOffsetY",0),t.Factory.addGetterSetter(t.Shape,"fillPatternImage"),t.Factory.addGetterSetter(t.Shape,"fill"),t.Factory.addDeprecatedGetterSetter(t.Shape,"fillRed",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"fillGreen",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"fillBlue",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"fillAlpha",1,t.Validators.alphaComponent),t.Factory.addGetterSetter(t.Shape,"fillPatternX",0),t.Factory.addGetterSetter(t.Shape,"fillPatternY",0),t.Factory.addGetterSetter(t.Shape,"fillLinearGradientColorStops"),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientStartRadius",0),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientEndRadius",0),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientColorStops"),t.Factory.addGetterSetter(t.Shape,"fillPatternRepeat","repeat"),t.Factory.addGetterSetter(t.Shape,"fillEnabled",!0),t.Factory.addGetterSetter(t.Shape,"strokeEnabled",!0),t.Factory.addGetterSetter(t.Shape,"shadowEnabled",!0),t.Factory.addGetterSetter(t.Shape,"dashEnabled",!0),t.Factory.addGetterSetter(t.Shape,"strokeScaleEnabled",!0),t.Factory.addGetterSetter(t.Shape,"fillPriority","color"),t.Factory.addComponentsGetterSetter(t.Shape,"fillPatternOffset",["x","y"]),t.Factory.addGetterSetter(t.Shape,"fillPatternOffsetX",0),t.Factory.addGetterSetter(t.Shape,"fillPatternOffsetY",0),t.Factory.addComponentsGetterSetter(t.Shape,"fillPatternScale",["x","y"]),t.Factory.addGetterSetter(t.Shape,"fillPatternScaleX",1),t.Factory.addGetterSetter(t.Shape,"fillPatternScaleY",1),t.Factory.addComponentsGetterSetter(t.Shape,"fillLinearGradientStartPoint",["x","y"]),t.Factory.addGetterSetter(t.Shape,"fillLinearGradientStartPointX",0),t.Factory.addGetterSetter(t.Shape,"fillLinearGradientStartPointY",0),t.Factory.addComponentsGetterSetter(t.Shape,"fillLinearGradientEndPoint",["x","y"]),t.Factory.addGetterSetter(t.Shape,"fillLinearGradientEndPointX",0),t.Factory.addGetterSetter(t.Shape,"fillLinearGradientEndPointY",0),t.Factory.addComponentsGetterSetter(t.Shape,"fillRadialGradientStartPoint",["x","y"]),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientStartPointX",0),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientStartPointY",0),t.Factory.addComponentsGetterSetter(t.Shape,"fillRadialGradientEndPoint",["x","y"]),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientEndPointX",0),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientEndPointY",0),t.Factory.addGetterSetter(t.Shape,"fillPatternRotation",0),t.Factory.backCompat(t.Shape,{dashArray:"dash",getDashArray:"getDash",setDashArray:"getDash",drawFunc:"sceneFunc",getDrawFunc:"getSceneFunc",setDrawFunc:"setSceneFunc",drawHitFunc:"hitFunc",getDrawHitFunc:"getHitFunc",setDrawHitFunc:"setHitFunc"}),t.Collection.mapMethods(t.Shape)}(Konva),function(){"use strict";function t(t,n){t.content.addEventListener(n,function(i){t[e+n](i)},!1)}var e="_",n=["mousedown","mousemove","mouseup","mouseout","touchstart","touchmove","touchend","mouseover","wheel","contextmenu"],i=n.length;Konva.Stage=function(t){this.___init(t)},Konva.Util.addMethods(Konva.Stage,{___init:function(t){this.nodeType="Stage",Konva.Container.call(this,t),this._id=Konva.idCounter++,this._buildDOM(),this._bindContentEvents(),this._enableNestedTransforms=!1,Konva.stages.push(this)},_validateAdd:function(t){"Layer"!==t.getType()&&Konva.Util.throw("You may only add layers to the stage.")},setContainer:function(t){if("string"==typeof t){if("."===t.charAt(0)){var e=t.slice(1);t=Konva.document.getElementsByClassName(e)[0]}else{var n;n="#"!==t.charAt(0)?t:t.slice(1),t=Konva.document.getElementById(n)}if(!t)throw"Can not find container in document with id "+n}return this._setAttr("container",t),this},shouldDrawHit:function(){return!0},draw:function(){return Konva.Node.prototype.draw.call(this),this},setHeight:function(t){return Konva.Node.prototype.setHeight.call(this,t),this._resizeDOM(),this},setWidth:function(t){return Konva.Node.prototype.setWidth.call(this,t),this._resizeDOM(),this},clear:function(){var t,e=this.children,n=e.length;for(t=0;t-1&&Konva.stages.splice(e,1),this},getPointerPosition:function(){return this.pointerPos},getStage:function(){return this},getContent:function(){return this.content},toDataURL:function(t){t=t||{};var e=t.mimeType||null,n=t.quality||null,i=t.x||0,a=t.y||0,r=new Konva.SceneCanvas({width:t.width||this.getWidth(),height:t.height||this.getHeight(),pixelRatio:t.pixelRatio}),o=r.getContext()._context,s=this.children;(i||a)&&o.translate(-1*i,-1*a),s.each(function(t){var e=t.getCanvas().getWidth(),n=t.getCanvas().getHeight(),i=t.getCanvas().getPixelRatio();o.drawImage(t.getCanvas()._canvas,0,0,e/i,n/i)});var h=r.toDataURL(e,n);return t.callback&&t.callback(h),h},toImage:function(t){var e=t.callback;t.callback=function(t){Konva.Util._getImage(t,function(t){e(t)})},this.toDataURL(t)},getIntersection:function(t,e){var n,i,a=this.getChildren(),r=a.length,o=r-1;for(n=o;n>=0;n--)if(i=a[n].getIntersection(t,e))return i;return null},_resizeDOM:function(){if(this.content){var t,e,n=this.getWidth(),i=this.getHeight(),a=this.getChildren(),r=a.length;for(this.content.style.width=n+"px",this.content.style.height=i+"px",this.bufferCanvas.setSize(n,i),this.bufferHitCanvas.setSize(n,i),t=0;t1){for(var e=0;e0){var a=t.touches[0];n=a.clientX-e.left,i=a.clientY-e.top}}else n=t.clientX-e.left,i=t.clientY-e.top;null!==n&&null!==i&&(this.pointerPos={x:n,y:i})},_getContentPosition:function(){var t=this.content.getBoundingClientRect?this.content.getBoundingClientRect():{top:0,left:0};return{top:t.top,left:t.left}},_buildDOM:function(){var t=this.getContainer();if(!t){if(Konva.Util.isBrowser())throw"Stage has no container. A container is required.";t=Konva.document.createElement("div")}t.innerHTML="",this.content=Konva.document.createElement("div"),this.content.style.position="relative",this.content.className="konvajs-content",this.content.setAttribute("role","presentation"),t.appendChild(this.content),this.bufferCanvas=new Konva.SceneCanvas,this.bufferHitCanvas=new Konva.HitCanvas({pixelRatio:1}),this._resizeDOM()},_onContent:function(t,e){var n,i,a=t.split(" "),r=a.length;for(n=0;n0?{antialiased:!0}:{}},drawScene:function(t,e){var n=this.getLayer(),i=t||n&&n.getCanvas();return this._fire("beforeDraw",{node:this}),this.getClearBeforeDraw()&&i.getContext().clear(),Konva.Container.prototype.drawScene.call(this,i,e),this._fire("draw",{node:this}),this},drawHit:function(t,e){var n=this.getLayer(),i=t||n&&n.hitCanvas;return n&&n.getClearBeforeDraw()&&n.getHitCanvas().getContext().clear(),Konva.Container.prototype.drawHit.call(this,i,e),this.imageData=null,this},clear:function(t){return Konva.BaseLayer.prototype.clear.call(this,t),this.getHitCanvas().getContext().clear(t),this.imageData=null,this},setVisible:function(t){return Konva.Node.prototype.setVisible.call(this,t),t?(this.getCanvas()._canvas.style.display="block",this.hitCanvas._canvas.style.display="block"):(this.getCanvas()._canvas.style.display="none",this.hitCanvas._canvas.style.display="none"),this},enableHitGraph:function(){return this.setHitGraphEnabled(!0),this},disableHitGraph:function(){return this.setHitGraphEnabled(!1),this},setSize:function(t,e){return Konva.BaseLayer.prototype.setSize.call(this,t,e),this.hitCanvas.setSize(t,e),this}}), -Konva.Util.extend(Konva.Layer,Konva.BaseLayer),Konva.Factory.addGetterSetter(Konva.Layer,"hitGraphEnabled",!0),Konva.Collection.mapMethods(Konva.Layer)}(),function(){"use strict";Konva.FastLayer=function(t){this.____init(t)},Konva.Util.addMethods(Konva.FastLayer,{____init:function(t){this.nodeType="Layer",this.canvas=new Konva.SceneCanvas,Konva.BaseLayer.call(this,t)},_validateAdd:function(t){"Shape"!==t.getType()&&Konva.Util.throw("You may only add shapes to a fast layer.")},_setCanvasSize:function(t,e){this.canvas.setSize(t,e)},hitGraphEnabled:function(){return!1},getIntersection:function(){return null},drawScene:function(t){var e=this.getLayer(),n=t||e&&e.getCanvas();return this.getClearBeforeDraw()&&n.getContext().clear(),Konva.Container.prototype.drawScene.call(this,n),this},draw:function(){return this.drawScene(),this},setVisible:function(t){return Konva.Node.prototype.setVisible.call(this,t),this.getCanvas()._canvas.style.display=t?"block":"none",this}}),Konva.Util.extend(Konva.FastLayer,Konva.BaseLayer),Konva.Collection.mapMethods(Konva.FastLayer)}(),function(){"use strict";Konva.Group=function(t){this.___init(t)},Konva.Util.addMethods(Konva.Group,{___init:function(t){this.nodeType="Group",Konva.Container.call(this,t)},_validateAdd:function(t){var e=t.getType();"Group"!==e&&"Shape"!==e&&Konva.Util.throw("You may only add groups and shapes to groups.")}}),Konva.Util.extend(Konva.Group,Konva.Container),Konva.Collection.mapMethods(Konva.Group)}(),function(t){"use strict";function e(t){setTimeout(t,1e3/60)}function n(){return a.apply(t.global,arguments)}var i=function(){return t.global.performance&&t.global.performance.now?function(){return t.global.performance.now()}:function(){return(new Date).getTime()}}(),a=function(){return t.global.requestAnimationFrame||t.global.webkitRequestAnimationFrame||t.global.mozRequestAnimationFrame||t.global.oRequestAnimationFrame||t.global.msRequestAnimationFrame||e}();t.Animation=function(e,n){var a=t.Animation;this.func=e,this.setLayers(n),this.id=a.animIdCounter++,this.frame={time:0,timeDiff:0,lastTime:i()}},t.Animation.prototype={setLayers:function(t){var e=[];return e=t?t.length>0?t:[t]:[],this.layers=e,this},getLayers:function(){return this.layers},addLayer:function(t){var e,n=this.layers,i=n.length;for(e=0;ethis.duration?this.yoyo?(this._time=this.duration,this.reverse()):this.finish():t<0?this.yoyo?(this._time=0,this.play()):this.reset():(this._time=t,this.update())},getTime:function(){return this._time},setPosition:function(t){this.prevPos=this._pos,this.propFunc(t),this._pos=t},getPosition:function(t){return void 0===t&&(t=this._time),this.func(t,this.begin,this._change,this.duration)},play:function(){this.state=2,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")},reverse:function(){this.state=3,this._time=this.duration-this._time,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onReverse")},seek:function(t){this.pause(),this._time=t,this.update(),this.fire("onSeek")},reset:function(){this.pause(),this._time=0,this.update(),this.fire("onReset")},finish:function(){this.pause(),this._time=this.duration,this.update(),this.fire("onFinish")},update:function(){this.setPosition(this.getPosition(this._time))},onEnterFrame:function(){var t=this.getTimer()-this._startTime;2===this.state?this.setTime(t):3===this.state&&this.setTime(this.duration-t)},pause:function(){this.state=1,this.fire("onPause")},getTimer:function(){return(new Date).getTime()}},Konva.Tween=function(n){var a,r,o=this,s=n.node,h=s._id,c=n.easing||Konva.Easings.Linear,l=!!n.yoyo;a=void 0===n.duration?1:0===n.duration?.001:n.duration,this.node=s,this._id=e++;var d=s.getLayer()||(s instanceof Konva.Stage?s.getLayers():null);d||Konva.Util.error("Tween constructor have `node` that is not in a layer. Please add node into layer first."),this.anim=new Konva.Animation(function(){o.tween.onEnterFrame()},d),this.tween=new i(r,function(t){o._tweenFunc(t)},c,0,1,1e3*a,l),this._addListeners(),Konva.Tween.attrs[h]||(Konva.Tween.attrs[h]={}),Konva.Tween.attrs[h][this._id]||(Konva.Tween.attrs[h][this._id]={}),Konva.Tween.tweens[h]||(Konva.Tween.tweens[h]={});for(r in n)void 0===t[r]&&this._addAttr(r,n[r]);this.reset(),this.onFinish=n.onFinish,this.onReset=n.onReset},Konva.Tween.attrs={},Konva.Tween.tweens={},Konva.Tween.prototype={_addAttr:function(t,e){var i,a,r,o,s,h,c,l=this.node,d=l._id;if(r=Konva.Tween.tweens[d][t],r&&delete Konva.Tween.attrs[d][r][t],i=l.getAttr(t),Konva.Util._isArray(e))for(a=[],s=Math.max(e.length,i.length),"points"===t&&e.length!==i.length&&(e.length>i.length?(c=i,i=Konva.Util._prepareArrayForTween(i,e,l.closed())):(h=e,e=Konva.Util._prepareArrayForTween(e,i,l.closed()))),o=0;ol)for(;y.length>0;){for(var K=0,S=y.length,C="",x=0;K>>1,b=y.slice(0,w+1),F=this._getTextWidth(b);F<=l?(K=w+1,C=b,x=F):S=w}if(!C)break;if(g){var T=Math.max(C.lastIndexOf(" "),C.lastIndexOf("-"))+1;T>0&&(K=T,C=C.slice(0,K),x=this._getTextWidth(C))}if(this._addTextLine(C),n=Math.max(n,x),u+=i,!f||h&&u+i>d)break;if(y=y.slice(K),y.length>0&&(_=this._getTextWidth(y))<=l){this._addTextLine(y),u+=i,n=Math.max(n,_);break}}else this._addTextLine(y),u+=i,n=Math.max(n,_);if(h&&u+i>d)break}a.restore(),this.textHeight=e,this.textWidth=n}},Konva.Util.extend(Konva.Text,Konva.Shape),Konva.Factory.addGetterSetter(Konva.Text,"fontFamily","Arial"),Konva.Factory.addGetterSetter(Konva.Text,"fontSize",12),Konva.Factory.addGetterSetter(Konva.Text,"fontStyle","normal"),Konva.Factory.addGetterSetter(Konva.Text,"fontVariant","normal"),Konva.Factory.addGetterSetter(Konva.Text,"padding",0),Konva.Factory.addGetterSetter(Konva.Text,"align","left"),Konva.Factory.addGetterSetter(Konva.Text,"lineHeight",1),Konva.Factory.addGetterSetter(Konva.Text,"wrap","word"),Konva.Factory.addGetterSetter(Konva.Text,"letterSpacing",0),Konva.Factory.addGetter(Konva.Text,"text",""),Konva.Factory.addOverloadedGetterSetter(Konva.Text,"text"),Konva.Factory.addGetterSetter(Konva.Text,"textDecoration",""),Konva.Collection.mapMethods(Konva.Text)}(),function(){"use strict";Konva.Line=function(t){this.___init(t)},Konva.Line.prototype={___init:function(t){Konva.Shape.call(this,t),this.className="Line",this.on("pointsChange.konva tensionChange.konva closedChange.konva bezierChange.konva",function(){this._clearCache("tensionPoints")}),this.sceneFunc(this._sceneFunc)},_sceneFunc:function(t){var e,n,i,a=this.getPoints(),r=a.length,o=this.getTension(),s=this.getClosed(),h=this.getBezier();if(r){if(t.beginPath(),t.moveTo(a[0],a[1]),0!==o&&r>4){for(e=this.getTensionPoints(),n=e.length,i=s?0:4,s||t.quadraticCurveTo(e[0],e[1],e[2],e[3]);ih?s:h,f=s>h?1:s/h,g=s>h?h/s:1;t.translate(r,o),t.rotate(d),t.scale(f,g),t.arc(0,0,v,c,c+l,1-u),t.scale(1/f,1/g),t.rotate(-d),t.translate(-r,-o);break;case"z":t.closePath()}}t.fillStrokeShape(this)},getSelfRect:function(){var t=[];this.dataArray.forEach(function(e){t=t.concat(e.points)});for(var e,n,i=t[0],a=t[0],r=t[1],o=t[1],s=0;s0&&""===l[0]&&l.shift();for(var d=0;d0&&!isNaN(l[0]);){var u,v,f,g,p,m,y,_,K,S,C=null,x=[],w=o,b=s;switch(c){case"l":o+=l.shift(),s+=l.shift(),C="L",x.push(o,s);break;case"L":o=l.shift(),s=l.shift(),x.push(o,s);break;case"m":var F=l.shift(),T=l.shift();if(o+=F,s+=T,C="M",r.length>2&&"z"===r[r.length-1].command)for(var P=r.length-2;P>=0;P--)if("M"===r[P].command){o=r[P].points[0]+F,s=r[P].points[1]+T;break}x.push(o,s),c="l";break;case"M":o=l.shift(),s=l.shift(),C="M",x.push(o,s),c="L";break;case"h":o+=l.shift(),C="L",x.push(o,s);break;case"H":o=l.shift(),C="L",x.push(o,s);break;case"v":s+=l.shift(),C="L",x.push(o,s);break;case"V":s=l.shift(),C="L",x.push(o,s);break;case"C":x.push(l.shift(),l.shift(),l.shift(),l.shift()),o=l.shift(),s=l.shift(),x.push(o,s);break;case"c":x.push(o+l.shift(),s+l.shift(),o+l.shift(),s+l.shift()),o+=l.shift(),s+=l.shift(),C="C",x.push(o,s);break;case"S":v=o,f=s,u=r[r.length-1],"C"===u.command&&(v=o+(o-u.points[2]),f=s+(s-u.points[3])),x.push(v,f,l.shift(),l.shift()),o=l.shift(),s=l.shift(),C="C",x.push(o,s);break;case"s":v=o,f=s,u=r[r.length-1],"C"===u.command&&(v=o+(o-u.points[2]),f=s+(s-u.points[3])),x.push(v,f,o+l.shift(),s+l.shift()),o+=l.shift(),s+=l.shift(),C="C",x.push(o,s);break;case"Q":x.push(l.shift(),l.shift()),o=l.shift(),s=l.shift(),x.push(o,s);break;case"q":x.push(o+l.shift(),s+l.shift()),o+=l.shift(),s+=l.shift(),C="Q",x.push(o,s);break;case"T":v=o,f=s,u=r[r.length-1],"Q"===u.command&&(v=o+(o-u.points[0]),f=s+(s-u.points[1])),o=l.shift(),s=l.shift(),C="Q",x.push(v,f,o,s);break;case"t":v=o,f=s,u=r[r.length-1],"Q"===u.command&&(v=o+(o-u.points[0]),f=s+(s-u.points[1])),o+=l.shift(),s+=l.shift(),C="Q",x.push(v,f,o,s);break;case"A":g=l.shift(),p=l.shift(),m=l.shift(),y=l.shift(),_=l.shift(),K=o,S=s,o=l.shift(),s=l.shift(),C="A",x=this.convertEndpointToCenterParameterization(K,S,o,s,y,_,g,p,m);break;case"a":g=l.shift(),p=l.shift(),m=l.shift(),y=l.shift(),_=l.shift(),K=o,S=s,o+=l.shift(),s+=l.shift(),C="A",x=this.convertEndpointToCenterParameterization(K,S,o,s,y,_,g,p,m)}r.push({command:C||c,points:x,start:{x:w,y:b},pathLength:this.calcLength(w,b,C||c,x)})}"z"!==c&&"Z"!==c||r.push({command:"z",points:[],start:void 0,pathLength:0})}return r},Konva.Path.calcLength=function(t,e,n,i){var a,r,o,s,h=Konva.Path;switch(n){case"L":return h.getLineLength(t,e,i[0],i[1]);case"C":for(a=0,r=h.getPointOnCubicBezier(0,t,e,i[0],i[1],i[2],i[3],i[4],i[5]),s=.01;s<=1;s+=.01)o=h.getPointOnCubicBezier(s,t,e,i[0],i[1],i[2],i[3],i[4],i[5]),a+=h.getLineLength(r.x,r.y,o.x,o.y),r=o;return a;case"Q":for(a=0,r=h.getPointOnQuadraticBezier(0,t,e,i[0],i[1],i[2],i[3]),s=.01;s<=1;s+=.01)o=h.getPointOnQuadraticBezier(s,t,e,i[0],i[1],i[2],i[3]),a+=h.getLineLength(r.x,r.y,o.x,o.y),r=o;return a;case"A":a=0;var c=i[4],l=i[5],d=i[4]+l,u=Math.PI/180;if(Math.abs(c-d)d;s-=u)o=h.getPointOnEllipticalArc(i[0],i[1],i[2],i[3],s,0),a+=h.getLineLength(r.x,r.y,o.x,o.y),r=o;else for(s=c+u;s1&&(o*=Math.sqrt(u),s*=Math.sqrt(u));var v=Math.sqrt((o*o*(s*s)-o*o*(d*d)-s*s*(l*l))/(o*o*(d*d)+s*s*(l*l)));a===r&&(v*=-1),isNaN(v)&&(v=0);var f=v*o*d/s,g=v*-s*l/o,p=(t+n)/2+Math.cos(c)*f-Math.sin(c)*g,m=(e+i)/2+Math.sin(c)*f+Math.cos(c)*g,y=function(t){return Math.sqrt(t[0]*t[0]+t[1]*t[1])},_=function(t,e){return(t[0]*e[0]+t[1]*e[1])/(y(t)*y(e))},K=function(t,e){return(t[0]*e[1]=1&&(w=0),0===r&&w>0&&(w-=2*Math.PI),1===r&&w<0&&(w+=2*Math.PI),[p,m,o,s,S,w,c,r]},Konva.Factory.addGetterSetter(Konva.Path,"data"),Konva.Collection.mapMethods(Konva.Path)}(),function(){"use strict";function t(t){t.fillText(this.partialText,0,0)}function e(t){t.strokeText(this.partialText,0,0)}Konva.TextPath=function(t){this.___init(t)},Konva.TextPath.prototype={___init:function(n){var i=this;this.dummyCanvas=Konva.Util.createCanvasElement(),this.dataArray=[],Konva.Shape.call(this,n),this._fillFunc=t,this._strokeFunc=e,this._fillFuncHit=t,this._strokeFuncHit=e,this.className="TextPath",this.dataArray=Konva.Path.parsePathData(this.attrs.data),this.on("dataChange.konva",function(){i.dataArray=Konva.Path.parsePathData(this.attrs.data),i._setTextData()}),this.on("textChange.konva alignChange.konva letterSpacingChange.konva",i._setTextData),i._setTextData(),this.sceneFunc(this._sceneFunc),this.hitFunc(this._hitFunc)},_sceneFunc:function(t){t.setAttr("font",this._getContextFont()),t.setAttr("textBaseline",this.getTextBaseline()),t.setAttr("textAlign","left"),t.save();var e=this.textDecoration(),n=this.fill(),i=this.fontSize(),a=this.glyphInfo;"underline"===e&&t.beginPath();for(var r=0;r=1){var n=e[0].p0;t.moveTo(n.x,n.y)}for(var i=0;i0&&(r+=t.dataArray[o].pathLength);var s=0;"center"===i&&(s=Math.max(0,r/2-a/2)),"right"===i&&(s=Math.max(0,r-a));for(var h,c,l,d=this.getText().split(""),u=this.getText().split(" ").length-1,v=-1,f=0,g=function(){f=0;for(var e=t.dataArray,n=v+1;n0)return v=n,e[n];"M"===e[n].command&&(h={x:e[n].points[0],y:e[n].points[1]})}return{}},p=function(e){var o=t._getTextSize(e).width+n;" "===e&&"justify"===i&&(o+=(r-a)/u);var s=0,d=0;for(c=void 0;Math.abs(o-s)/o>.01&&d<25;){d++;for(var v=s;void 0===l;)(l=g())&&v+l.pathLengtho?c=Konva.Path.getPointOnLine(o,h.x,h.y,l.points[0],l.points[1],h.x,h.y):l=void 0;break;case"A":var m=l.points[4],y=l.points[5],_=l.points[4]+y;0===f?f=m+1e-8:o>s?f+=Math.PI/180*y/Math.abs(y):f-=Math.PI/360*y/Math.abs(y),(y<0&&f<_||y>=0&&f>_)&&(f=_,p=!0),c=Konva.Path.getPointOnEllipticalArc(l.points[0],l.points[1],l.points[2],l.points[3],f,l.points[6]);break;case"C":0===f?f=o>l.pathLength?1e-8:o/l.pathLength:o>s?f+=(o-s)/l.pathLength:f-=(s-o)/l.pathLength,f>1&&(f=1,p=!0),c=Konva.Path.getPointOnCubicBezier(f,l.start.x,l.start.y,l.points[0],l.points[1],l.points[2],l.points[3],l.points[4],l.points[5]);break;case"Q":0===f?f=o/l.pathLength:o>s?f+=(o-s)/l.pathLength:f-=(s-o)/l.pathLength,f>1&&(f=1,p=!0),c=Konva.Path.getPointOnQuadraticBezier(f,l.start.x,l.start.y,l.points[0],l.points[1],l.points[2],l.points[3])}void 0!==c&&(s=Konva.Path.getLineLength(h.x,h.y,c.x,c.y)),p&&(p=!1,l=void 0)}},m=t._getTextSize("C").width+n,y=0;y255?255:s,l[i+1]=h>255?255:h,l[i+2]=c>255?255:c,l[i+3]=l[i+3]}while(--n)}while(--u)}}(),function(){"use strict";Konva.Filters.Solarize=function(t){var e=t.data,n=t.width,i=t.height,a=4*n,r=i;do{var o=(r-1)*a,s=n;do{var h=o+4*(s-1),c=e[h],l=e[h+1],d=e[h+2];c>127&&(c=255-c),l>127&&(l=255-l),d>127&&(d=255-d),e[h]=c,e[h+1]=l,e[h+2]=d}while(--s)}while(--r)}}(),function(){"use strict";var t=function(t,e,n){var i,a,r,o,s=t.data,h=e.data,c=t.width,l=t.height,d=n.polarCenterX||c/2,u=n.polarCenterY||l/2,v=0,f=0,g=0,p=0,m=Math.sqrt(d*d+u*u);a=c-d,r=l-u,o=Math.sqrt(a*a+r*r),m=o>m?o:m;var y,_,K,S,C=l,x=c,w=360/x*Math.PI/180;for(_=0;__?h:_;var K,S,C,x,w=u,b=d,F=n.polarRotation||0;for(a=0;af&&(C=S,x=0,w=-1),r=0;r0},removeChildren:function(){for(var t,e=Konva.Collection.toCollection(this.children),n=0;n1){for(var e=0;e0},destroy:function(){return t.Node.prototype.destroy.call(this),delete t.shapes[this.colorKey],this},_useBufferCanvas:function(t){return!t&&this.perfectDrawEnabled()&&1!==this.getAbsoluteOpacity()&&this.hasFill()&&this.hasStroke()&&this.getStage()||this.perfectDrawEnabled()&&this.hasShadow()&&1!==this.getAbsoluteOpacity()&&this.hasFill()&&this.hasStroke()&&this.getStage()},getSelfRect:function(){var t=this.getSize();return{x:this._centroid?Math.round(-t.width/2):0,y:this._centroid?Math.round(-t.height/2):0,width:t.width,height:t.height}},getClientRect:function(t){var e=this.getSelfRect(),n=this.hasStroke()&&this.strokeWidth()||0,i=e.width+n,a=e.height+n,r=this.hasShadow()?this.shadowOffsetX():0,o=this.hasShadow()?this.shadowOffsetY():0,s=i+Math.abs(r),h=a+Math.abs(o),c=this.hasShadow()&&this.shadowBlur()||0,l=s+2*c,d=h+2*c,u=0;Math.round(n/2)!==n/2&&(u=1);var v={width:l+u,height:d+u,x:-Math.round(n/2+c)+Math.min(r,0)+e.x,y:-Math.round(n/2+c)+Math.min(o,0)+e.y};return t?v:this._transformedRect(v)},drawScene:function(t,e,n,i){var a,r,o,s=this.getLayer(),h=t||s.getCanvas(),c=h.getContext(),l=this._cache.canvas,d=this.sceneFunc(),u=this.hasShadow(),v=this.hasStroke();if(!this.isVisible())return this;if(l)return c.save(),s._applyTransform(this,c,e),this._drawCachedSceneCanvas(c),c.restore(),this;if(!d)return this;if(c.save(),this._useBufferCanvas(n)&&!i){if(a=this.getStage(),r=a.bufferCanvas,o=r.getContext(),o.clear(),o.save(),o._applyLineJoin(this),!n)if(s)s._applyTransform(this,o,e);else{var f=this.getAbsoluteTransform(e).getMatrix();c.transform(f[0],f[1],f[2],f[3],f[4],f[5])}d.call(this,o),o.restore();var g=r.pixelRatio;u&&!h.hitCanvas?(c.save(),c._applyShadow(this),c._applyOpacity(this),c._applyGlobalCompositeOperation(this),c.drawImage(r._canvas,0,0,r.width/g,r.height/g),c.restore()):(c._applyOpacity(this),c._applyGlobalCompositeOperation(this),c.drawImage(r._canvas,0,0,r.width/g,r.height/g))}else{if(c._applyLineJoin(this),!n)if(s)s._applyTransform(this,c,e);else{var p=this.getAbsoluteTransform(e).getMatrix();c.transform(p[0],p[1],p[2],p[3],p[4],p[5])}u&&v&&!h.hitCanvas?(c.save(),n||(c._applyOpacity(this),c._applyGlobalCompositeOperation(this)),c._applyShadow(this),d.call(this,c),c.restore(),this.hasFill()&&this.getShadowForStrokeEnabled()&&d.call(this,c)):u&&!h.hitCanvas?(c.save(),n||(c._applyOpacity(this),c._applyGlobalCompositeOperation(this)),c._applyShadow(this),d.call(this,c),c.restore()):(n||(c._applyOpacity(this),c._applyGlobalCompositeOperation(this)),d.call(this,c))}return c.restore(),this},drawHit:function(t,e,n){var i=this.getLayer(),a=t||i.hitCanvas,r=a.getContext(),o=this.hitFunc()||this.sceneFunc(),s=this._cache.canvas,h=s&&s.hit;if(!this.shouldDrawHit(a))return this;if(i&&i.clearHitCache(),h)return r.save(),i._applyTransform(this,r,e),this._drawCachedHitCanvas(r),r.restore(),this;if(!o)return this;if(r.save(),r._applyLineJoin(this),!n)if(i)i._applyTransform(this,r,e);else{var c=this.getAbsoluteTransform(e).getMatrix();r.transform(c[0],c[1],c[2],c[3],c[4],c[5])}return o.call(this,r),r.restore(),this},drawHitFromCache:function(e){var n,i,a,r,o,s,h=e||0,c=this._cache.canvas,l=this._getCachedSceneCanvas(),d=c.hit,u=d.getContext(),v=d.getWidth(),f=d.getHeight();u.clear(),u.drawImage(l._canvas,0,0,v,f);try{for(n=u.getImageData(0,0,v,f),i=n.data,a=i.length,r=t.Util._hexToRgb(this.colorKey),o=0;oh?(i[o]=r.r,i[o+1]=r.g,i[o+2]=r.b,i[o+3]=255):i[o+3]=0;u.putImageData(n,0,0)}catch(e){t.Util.error("Unable to draw hit graph from cached scene canvas. "+e.message)}return this}}),t.Util.extend(t.Shape,t.Node),t.Factory.addGetterSetter(t.Shape,"stroke"),t.Factory.addDeprecatedGetterSetter(t.Shape,"strokeRed",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"strokeGreen",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"strokeBlue",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"strokeAlpha",1,t.Validators.alphaComponent),t.Factory.addGetterSetter(t.Shape,"strokeWidth",2),t.Factory.addGetterSetter(t.Shape,"strokeHitEnabled",!0),t.Factory.addGetterSetter(t.Shape,"perfectDrawEnabled",!0),t.Factory.addGetterSetter(t.Shape,"shadowForStrokeEnabled",!0),t.Factory.addGetterSetter(t.Shape,"lineJoin"),t.Factory.addGetterSetter(t.Shape,"lineCap"),t.Factory.addGetterSetter(t.Shape,"sceneFunc"),t.Factory.addGetterSetter(t.Shape,"hitFunc"),t.Factory.addGetterSetter(t.Shape,"dash"),t.Factory.addGetterSetter(t.Shape,"dashOffset",0),t.Factory.addGetterSetter(t.Shape,"shadowColor"),t.Factory.addDeprecatedGetterSetter(t.Shape,"shadowRed",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"shadowGreen",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"shadowBlue",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"shadowAlpha",1,t.Validators.alphaComponent),t.Factory.addGetterSetter(t.Shape,"shadowBlur"),t.Factory.addGetterSetter(t.Shape,"shadowOpacity"),t.Factory.addComponentsGetterSetter(t.Shape,"shadowOffset",["x","y"]),t.Factory.addGetterSetter(t.Shape,"shadowOffsetX",0),t.Factory.addGetterSetter(t.Shape,"shadowOffsetY",0),t.Factory.addGetterSetter(t.Shape,"fillPatternImage"),t.Factory.addGetterSetter(t.Shape,"fill"),t.Factory.addDeprecatedGetterSetter(t.Shape,"fillRed",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"fillGreen",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"fillBlue",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"fillAlpha",1,t.Validators.alphaComponent),t.Factory.addGetterSetter(t.Shape,"fillPatternX",0),t.Factory.addGetterSetter(t.Shape,"fillPatternY",0),t.Factory.addGetterSetter(t.Shape,"fillLinearGradientColorStops"),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientStartRadius",0),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientEndRadius",0),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientColorStops"),t.Factory.addGetterSetter(t.Shape,"fillPatternRepeat","repeat"),t.Factory.addGetterSetter(t.Shape,"fillEnabled",!0),t.Factory.addGetterSetter(t.Shape,"strokeEnabled",!0),t.Factory.addGetterSetter(t.Shape,"shadowEnabled",!0),t.Factory.addGetterSetter(t.Shape,"dashEnabled",!0),t.Factory.addGetterSetter(t.Shape,"strokeScaleEnabled",!0),t.Factory.addGetterSetter(t.Shape,"fillPriority","color"),t.Factory.addComponentsGetterSetter(t.Shape,"fillPatternOffset",["x","y"]),t.Factory.addGetterSetter(t.Shape,"fillPatternOffsetX",0),t.Factory.addGetterSetter(t.Shape,"fillPatternOffsetY",0),t.Factory.addComponentsGetterSetter(t.Shape,"fillPatternScale",["x","y"]),t.Factory.addGetterSetter(t.Shape,"fillPatternScaleX",1),t.Factory.addGetterSetter(t.Shape,"fillPatternScaleY",1),t.Factory.addComponentsGetterSetter(t.Shape,"fillLinearGradientStartPoint",["x","y"]),t.Factory.addGetterSetter(t.Shape,"fillLinearGradientStartPointX",0),t.Factory.addGetterSetter(t.Shape,"fillLinearGradientStartPointY",0),t.Factory.addComponentsGetterSetter(t.Shape,"fillLinearGradientEndPoint",["x","y"]),t.Factory.addGetterSetter(t.Shape,"fillLinearGradientEndPointX",0),t.Factory.addGetterSetter(t.Shape,"fillLinearGradientEndPointY",0),t.Factory.addComponentsGetterSetter(t.Shape,"fillRadialGradientStartPoint",["x","y"]),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientStartPointX",0),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientStartPointY",0),t.Factory.addComponentsGetterSetter(t.Shape,"fillRadialGradientEndPoint",["x","y"]),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientEndPointX",0),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientEndPointY",0),t.Factory.addGetterSetter(t.Shape,"fillPatternRotation",0),t.Factory.backCompat(t.Shape,{dashArray:"dash",getDashArray:"getDash",setDashArray:"getDash",drawFunc:"sceneFunc",getDrawFunc:"getSceneFunc",setDrawFunc:"setSceneFunc",drawHitFunc:"hitFunc",getDrawHitFunc:"getHitFunc",setDrawHitFunc:"setHitFunc"}),t.Collection.mapMethods(t.Shape)}(Konva),function(){"use strict";function t(t,n){t.content.addEventListener(n,function(i){t[e+n](i)},!1)}var e="_",n=["mousedown","mousemove","mouseup","mouseout","touchstart","touchmove","touchend","mouseover","wheel","contextmenu"],i=n.length;Konva.Stage=function(t){this.___init(t)},Konva.Util.addMethods(Konva.Stage,{___init:function(t){this.nodeType="Stage",Konva.Container.call(this,t),this._id=Konva.idCounter++,this._buildDOM(),this._bindContentEvents(),this._enableNestedTransforms=!1,Konva.stages.push(this)},_validateAdd:function(t){"Layer"!==t.getType()&&Konva.Util.throw("You may only add layers to the stage.")},setContainer:function(t){if("string"==typeof t){if("."===t.charAt(0)){var e=t.slice(1);t=Konva.document.getElementsByClassName(e)[0]}else{var n;n="#"!==t.charAt(0)?t:t.slice(1),t=Konva.document.getElementById(n)}if(!t)throw"Can not find container in document with id "+n}return this._setAttr("container",t),this},shouldDrawHit:function(){return!0},draw:function(){return Konva.Node.prototype.draw.call(this),this},setHeight:function(t){return Konva.Node.prototype.setHeight.call(this,t),this._resizeDOM(),this},setWidth:function(t){return Konva.Node.prototype.setWidth.call(this,t),this._resizeDOM(),this},clear:function(){var t,e=this.children,n=e.length;for(t=0;t-1&&Konva.stages.splice(e,1),this},getPointerPosition:function(){return this.pointerPos},getStage:function(){return this},getContent:function(){return this.content},toDataURL:function(t){t=t||{};var e=t.mimeType||null,n=t.quality||null,i=t.x||0,a=t.y||0,r=new Konva.SceneCanvas({width:t.width||this.getWidth(),height:t.height||this.getHeight(),pixelRatio:t.pixelRatio}),o=r.getContext()._context,s=this.children;(i||a)&&o.translate(-1*i,-1*a),s.each(function(t){var e=t.getCanvas().getWidth(),n=t.getCanvas().getHeight(),i=t.getCanvas().getPixelRatio();o.drawImage(t.getCanvas()._canvas,0,0,e/i,n/i)});var h=r.toDataURL(e,n);return t.callback&&t.callback(h),h},toImage:function(t){var e=t.callback;t.callback=function(t){Konva.Util._getImage(t,function(t){e(t)})},this.toDataURL(t)},getIntersection:function(t,e){var n,i,a=this.getChildren(),r=a.length,o=r-1;for(n=o;n>=0;n--)if(i=a[n].getIntersection(t,e))return i;return null},_resizeDOM:function(){if(this.content){var t,e,n=this.getWidth(),i=this.getHeight(),a=this.getChildren(),r=a.length;for(this.content.style.width=n+"px",this.content.style.height=i+"px",this.bufferCanvas.setSize(n,i),this.bufferHitCanvas.setSize(n,i),t=0;t1){for(var e=0;e0){var a=t.touches[0];n=a.clientX-e.left,i=a.clientY-e.top}}else n=t.clientX-e.left,i=t.clientY-e.top;null!==n&&null!==i&&(this.pointerPos={x:n,y:i})},_getContentPosition:function(){var t=this.content.getBoundingClientRect?this.content.getBoundingClientRect():{top:0,left:0};return{top:t.top,left:t.left}},_buildDOM:function(){var t=this.getContainer();if(!t){if(Konva.Util.isBrowser())throw"Stage has no container. A container is required.";t=Konva.document.createElement("div")}t.innerHTML="",this.content=Konva.document.createElement("div"),this.content.style.position="relative",this.content.className="konvajs-content",this.content.setAttribute("role","presentation"),t.appendChild(this.content),this.bufferCanvas=new Konva.SceneCanvas,this.bufferHitCanvas=new Konva.HitCanvas({pixelRatio:1}),this._resizeDOM()},_onContent:function(t,e){var n,i,a=t.split(" "),r=a.length;for(n=0;n0?{antialiased:!0}:{}},drawScene:function(t,e){var n=this.getLayer(),i=t||n&&n.getCanvas();return this._fire("beforeDraw",{node:this}),this.getClearBeforeDraw()&&i.getContext().clear(),Konva.Container.prototype.drawScene.call(this,i,e),this._fire("draw",{node:this}),this},drawHit:function(t,e){var n=this.getLayer(),i=t||n&&n.hitCanvas;return n&&n.getClearBeforeDraw()&&n.getHitCanvas().getContext().clear(),Konva.Container.prototype.drawHit.call(this,i,e),this.imageData=null,this},clear:function(t){return Konva.BaseLayer.prototype.clear.call(this,t),this.getHitCanvas().getContext().clear(t),this.imageData=null,this},setVisible:function(t){return Konva.Node.prototype.setVisible.call(this,t),t?(this.getCanvas()._canvas.style.display="block",this.hitCanvas._canvas.style.display="block"):(this.getCanvas()._canvas.style.display="none",this.hitCanvas._canvas.style.display="none"),this},enableHitGraph:function(){return this.setHitGraphEnabled(!0),this},disableHitGraph:function(){return this.setHitGraphEnabled(!1),this},setSize:function(t,e){return Konva.BaseLayer.prototype.setSize.call(this,t,e),this.hitCanvas.setSize(t,e),this} +}),Konva.Util.extend(Konva.Layer,Konva.BaseLayer),Konva.Factory.addGetterSetter(Konva.Layer,"hitGraphEnabled",!0),Konva.Collection.mapMethods(Konva.Layer)}(),function(){"use strict";Konva.FastLayer=function(t){this.____init(t)},Konva.Util.addMethods(Konva.FastLayer,{____init:function(t){this.nodeType="Layer",this.canvas=new Konva.SceneCanvas,Konva.BaseLayer.call(this,t)},_validateAdd:function(t){"Shape"!==t.getType()&&Konva.Util.throw("You may only add shapes to a fast layer.")},_setCanvasSize:function(t,e){this.canvas.setSize(t,e)},hitGraphEnabled:function(){return!1},getIntersection:function(){return null},drawScene:function(t){var e=this.getLayer(),n=t||e&&e.getCanvas();return this.getClearBeforeDraw()&&n.getContext().clear(),Konva.Container.prototype.drawScene.call(this,n),this},draw:function(){return this.drawScene(),this},setVisible:function(t){return Konva.Node.prototype.setVisible.call(this,t),this.getCanvas()._canvas.style.display=t?"block":"none",this}}),Konva.Util.extend(Konva.FastLayer,Konva.BaseLayer),Konva.Collection.mapMethods(Konva.FastLayer)}(),function(){"use strict";Konva.Group=function(t){this.___init(t)},Konva.Util.addMethods(Konva.Group,{___init:function(t){this.nodeType="Group",Konva.Container.call(this,t)},_validateAdd:function(t){var e=t.getType();"Group"!==e&&"Shape"!==e&&Konva.Util.throw("You may only add groups and shapes to groups.")}}),Konva.Util.extend(Konva.Group,Konva.Container),Konva.Collection.mapMethods(Konva.Group)}(),function(t){"use strict";function e(t){setTimeout(t,1e3/60)}function n(){return a.apply(t.global,arguments)}var i=function(){return t.global.performance&&t.global.performance.now?function(){return t.global.performance.now()}:function(){return(new Date).getTime()}}(),a=function(){return t.global.requestAnimationFrame||t.global.webkitRequestAnimationFrame||t.global.mozRequestAnimationFrame||t.global.oRequestAnimationFrame||t.global.msRequestAnimationFrame||e}();t.Animation=function(e,n){var a=t.Animation;this.func=e,this.setLayers(n),this.id=a.animIdCounter++,this.frame={time:0,timeDiff:0,lastTime:i()}},t.Animation.prototype={setLayers:function(t){var e=[];return e=t?t.length>0?t:[t]:[],this.layers=e,this},getLayers:function(){return this.layers},addLayer:function(t){var e,n=this.layers,i=n.length;for(e=0;ethis.duration?this.yoyo?(this._time=this.duration,this.reverse()):this.finish():t<0?this.yoyo?(this._time=0,this.play()):this.reset():(this._time=t,this.update())},getTime:function(){return this._time},setPosition:function(t){this.prevPos=this._pos,this.propFunc(t),this._pos=t},getPosition:function(t){return void 0===t&&(t=this._time),this.func(t,this.begin,this._change,this.duration)},play:function(){this.state=2,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")},reverse:function(){this.state=3,this._time=this.duration-this._time,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onReverse")},seek:function(t){this.pause(),this._time=t,this.update(),this.fire("onSeek")},reset:function(){this.pause(),this._time=0,this.update(),this.fire("onReset")},finish:function(){this.pause(),this._time=this.duration,this.update(),this.fire("onFinish")},update:function(){this.setPosition(this.getPosition(this._time))},onEnterFrame:function(){var t=this.getTimer()-this._startTime;2===this.state?this.setTime(t):3===this.state&&this.setTime(this.duration-t)},pause:function(){this.state=1,this.fire("onPause")},getTimer:function(){return(new Date).getTime()}},Konva.Tween=function(n){var a,r,o=this,s=n.node,h=s._id,c=n.easing||Konva.Easings.Linear,l=!!n.yoyo;a=void 0===n.duration?1:0===n.duration?.001:n.duration,this.node=s,this._id=e++;var d=s.getLayer()||(s instanceof Konva.Stage?s.getLayers():null);d||Konva.Util.error("Tween constructor have `node` that is not in a layer. Please add node into layer first."),this.anim=new Konva.Animation(function(){o.tween.onEnterFrame()},d),this.tween=new i(r,function(t){o._tweenFunc(t)},c,0,1,1e3*a,l),this._addListeners(),Konva.Tween.attrs[h]||(Konva.Tween.attrs[h]={}),Konva.Tween.attrs[h][this._id]||(Konva.Tween.attrs[h][this._id]={}),Konva.Tween.tweens[h]||(Konva.Tween.tweens[h]={});for(r in n)void 0===t[r]&&this._addAttr(r,n[r]);this.reset(),this.onFinish=n.onFinish,this.onReset=n.onReset},Konva.Tween.attrs={},Konva.Tween.tweens={},Konva.Tween.prototype={_addAttr:function(t,e){var i,a,r,o,s,h,c,l=this.node,d=l._id;if(r=Konva.Tween.tweens[d][t],r&&delete Konva.Tween.attrs[d][r][t],i=l.getAttr(t),Konva.Util._isArray(e))for(a=[],s=Math.max(e.length,i.length),"points"===t&&e.length!==i.length&&(e.length>i.length?(c=i,i=Konva.Util._prepareArrayForTween(i,e,l.closed())):(h=e,e=Konva.Util._prepareArrayForTween(e,i,l.closed()))),o=0;ol)for(;y.length>0;){for(var K=0,S=y.length,C="",x=0;K>>1,b=y.slice(0,w+1),F=this._getTextWidth(b);F<=l?(K=w+1,C=b,x=F):S=w}if(!C)break;if(g){var T=Math.max(C.lastIndexOf(" "),C.lastIndexOf("-"))+1;T>0&&(K=T,C=C.slice(0,K),x=this._getTextWidth(C))}if(this._addTextLine(C),n=Math.max(n,x),u+=i,!f||h&&u+i>d)break;if(y=y.slice(K),y.length>0&&(_=this._getTextWidth(y))<=l){this._addTextLine(y),u+=i,n=Math.max(n,_);break}}else this._addTextLine(y),u+=i,n=Math.max(n,_);if(h&&u+i>d)break}a.restore(),this.textHeight=e,this.textWidth=n}},Konva.Util.extend(Konva.Text,Konva.Shape),Konva.Factory.addGetterSetter(Konva.Text,"fontFamily","Arial"),Konva.Factory.addGetterSetter(Konva.Text,"fontSize",12),Konva.Factory.addGetterSetter(Konva.Text,"fontStyle","normal"),Konva.Factory.addGetterSetter(Konva.Text,"fontVariant","normal"),Konva.Factory.addGetterSetter(Konva.Text,"padding",0),Konva.Factory.addGetterSetter(Konva.Text,"align","left"),Konva.Factory.addGetterSetter(Konva.Text,"lineHeight",1),Konva.Factory.addGetterSetter(Konva.Text,"wrap","word"),Konva.Factory.addGetterSetter(Konva.Text,"letterSpacing",0),Konva.Factory.addGetter(Konva.Text,"text",""),Konva.Factory.addOverloadedGetterSetter(Konva.Text,"text"),Konva.Factory.addGetterSetter(Konva.Text,"textDecoration",""),Konva.Collection.mapMethods(Konva.Text)}(),function(){"use strict";Konva.Line=function(t){this.___init(t)},Konva.Line.prototype={___init:function(t){Konva.Shape.call(this,t),this.className="Line",this.on("pointsChange.konva tensionChange.konva closedChange.konva bezierChange.konva",function(){this._clearCache("tensionPoints")}),this.sceneFunc(this._sceneFunc)},_sceneFunc:function(t){var e,n,i,a=this.getPoints(),r=a.length,o=this.getTension(),s=this.getClosed(),h=this.getBezier();if(r){if(t.beginPath(),t.moveTo(a[0],a[1]),0!==o&&r>4){for(e=this.getTensionPoints(),n=e.length,i=s?0:4,s||t.quadraticCurveTo(e[0],e[1],e[2],e[3]);ih?s:h,f=s>h?1:s/h,g=s>h?h/s:1;t.translate(r,o),t.rotate(d),t.scale(f,g),t.arc(0,0,v,c,c+l,1-u),t.scale(1/f,1/g),t.rotate(-d),t.translate(-r,-o);break;case"z":t.closePath()}}t.fillStrokeShape(this)},getSelfRect:function(){var t=[];this.dataArray.forEach(function(e){t=t.concat(e.points)});for(var e,n,i=t[0],a=t[0],r=t[1],o=t[1],s=0;s0&&""===l[0]&&l.shift();for(var d=0;d0&&!isNaN(l[0]);){var u,v,f,g,p,m,y,_,K,S,C=null,x=[],w=o,b=s;switch(c){case"l":o+=l.shift(),s+=l.shift(),C="L",x.push(o,s);break;case"L":o=l.shift(),s=l.shift(),x.push(o,s);break;case"m":var F=l.shift(),T=l.shift();if(o+=F,s+=T,C="M",r.length>2&&"z"===r[r.length-1].command)for(var P=r.length-2;P>=0;P--)if("M"===r[P].command){o=r[P].points[0]+F,s=r[P].points[1]+T;break}x.push(o,s),c="l";break;case"M":o=l.shift(),s=l.shift(),C="M",x.push(o,s),c="L";break;case"h":o+=l.shift(),C="L",x.push(o,s);break;case"H":o=l.shift(),C="L",x.push(o,s);break;case"v":s+=l.shift(),C="L",x.push(o,s);break;case"V":s=l.shift(),C="L",x.push(o,s);break;case"C":x.push(l.shift(),l.shift(),l.shift(),l.shift()),o=l.shift(),s=l.shift(),x.push(o,s);break;case"c":x.push(o+l.shift(),s+l.shift(),o+l.shift(),s+l.shift()),o+=l.shift(),s+=l.shift(),C="C",x.push(o,s);break;case"S":v=o,f=s,u=r[r.length-1],"C"===u.command&&(v=o+(o-u.points[2]),f=s+(s-u.points[3])),x.push(v,f,l.shift(),l.shift()),o=l.shift(),s=l.shift(),C="C",x.push(o,s);break;case"s":v=o,f=s,u=r[r.length-1],"C"===u.command&&(v=o+(o-u.points[2]),f=s+(s-u.points[3])),x.push(v,f,o+l.shift(),s+l.shift()),o+=l.shift(),s+=l.shift(),C="C",x.push(o,s);break;case"Q":x.push(l.shift(),l.shift()),o=l.shift(),s=l.shift(),x.push(o,s);break;case"q":x.push(o+l.shift(),s+l.shift()),o+=l.shift(),s+=l.shift(),C="Q",x.push(o,s);break;case"T":v=o,f=s,u=r[r.length-1],"Q"===u.command&&(v=o+(o-u.points[0]),f=s+(s-u.points[1])),o=l.shift(),s=l.shift(),C="Q",x.push(v,f,o,s);break;case"t":v=o,f=s,u=r[r.length-1],"Q"===u.command&&(v=o+(o-u.points[0]),f=s+(s-u.points[1])),o+=l.shift(),s+=l.shift(),C="Q",x.push(v,f,o,s);break;case"A":g=l.shift(),p=l.shift(),m=l.shift(),y=l.shift(),_=l.shift(),K=o,S=s,o=l.shift(),s=l.shift(),C="A",x=this.convertEndpointToCenterParameterization(K,S,o,s,y,_,g,p,m);break;case"a":g=l.shift(),p=l.shift(),m=l.shift(),y=l.shift(),_=l.shift(),K=o,S=s,o+=l.shift(),s+=l.shift(),C="A",x=this.convertEndpointToCenterParameterization(K,S,o,s,y,_,g,p,m)}r.push({command:C||c,points:x,start:{x:w,y:b},pathLength:this.calcLength(w,b,C||c,x)})}"z"!==c&&"Z"!==c||r.push({command:"z",points:[],start:void 0,pathLength:0})}return r},Konva.Path.calcLength=function(t,e,n,i){var a,r,o,s,h=Konva.Path;switch(n){case"L":return h.getLineLength(t,e,i[0],i[1]);case"C":for(a=0,r=h.getPointOnCubicBezier(0,t,e,i[0],i[1],i[2],i[3],i[4],i[5]),s=.01;s<=1;s+=.01)o=h.getPointOnCubicBezier(s,t,e,i[0],i[1],i[2],i[3],i[4],i[5]),a+=h.getLineLength(r.x,r.y,o.x,o.y),r=o;return a;case"Q":for(a=0,r=h.getPointOnQuadraticBezier(0,t,e,i[0],i[1],i[2],i[3]),s=.01;s<=1;s+=.01)o=h.getPointOnQuadraticBezier(s,t,e,i[0],i[1],i[2],i[3]),a+=h.getLineLength(r.x,r.y,o.x,o.y),r=o;return a;case"A":a=0;var c=i[4],l=i[5],d=i[4]+l,u=Math.PI/180;if(Math.abs(c-d)d;s-=u)o=h.getPointOnEllipticalArc(i[0],i[1],i[2],i[3],s,0),a+=h.getLineLength(r.x,r.y,o.x,o.y),r=o;else for(s=c+u;s1&&(o*=Math.sqrt(u),s*=Math.sqrt(u));var v=Math.sqrt((o*o*(s*s)-o*o*(d*d)-s*s*(l*l))/(o*o*(d*d)+s*s*(l*l)));a===r&&(v*=-1),isNaN(v)&&(v=0);var f=v*o*d/s,g=v*-s*l/o,p=(t+n)/2+Math.cos(c)*f-Math.sin(c)*g,m=(e+i)/2+Math.sin(c)*f+Math.cos(c)*g,y=function(t){return Math.sqrt(t[0]*t[0]+t[1]*t[1])},_=function(t,e){return(t[0]*e[0]+t[1]*e[1])/(y(t)*y(e))},K=function(t,e){return(t[0]*e[1]=1&&(w=0),0===r&&w>0&&(w-=2*Math.PI),1===r&&w<0&&(w+=2*Math.PI),[p,m,o,s,S,w,c,r]},Konva.Factory.addGetterSetter(Konva.Path,"data"),Konva.Collection.mapMethods(Konva.Path)}(),function(){"use strict";function t(t){t.fillText(this.partialText,0,0)}function e(t){t.strokeText(this.partialText,0,0)}Konva.TextPath=function(t){this.___init(t)},Konva.TextPath.prototype={___init:function(n){var i=this;this.dummyCanvas=Konva.Util.createCanvasElement(),this.dataArray=[],Konva.Shape.call(this,n),this._fillFunc=t,this._strokeFunc=e,this._fillFuncHit=t,this._strokeFuncHit=e,this.className="TextPath",this.dataArray=Konva.Path.parsePathData(this.attrs.data),this.on("dataChange.konva",function(){i.dataArray=Konva.Path.parsePathData(this.attrs.data),i._setTextData()}),this.on("textChange.konva alignChange.konva letterSpacingChange.konva",i._setTextData),i._setTextData(),this.sceneFunc(this._sceneFunc),this.hitFunc(this._hitFunc)},_sceneFunc:function(t){t.setAttr("font",this._getContextFont()),t.setAttr("textBaseline",this.getTextBaseline()),t.setAttr("textAlign","left"),t.save();var e=this.textDecoration(),n=this.fill(),i=this.fontSize(),a=this.glyphInfo;"underline"===e&&t.beginPath();for(var r=0;r=1){var n=e[0].p0;t.moveTo(n.x,n.y)}for(var i=0;i0&&(r+=t.dataArray[o].pathLength);var s=0;"center"===i&&(s=Math.max(0,r/2-a/2)),"right"===i&&(s=Math.max(0,r-a));for(var h,c,l,d=this.getText().split(""),u=this.getText().split(" ").length-1,v=-1,f=0,g=function(){f=0;for(var e=t.dataArray,n=v+1;n0)return v=n,e[n];"M"===e[n].command&&(h={x:e[n].points[0],y:e[n].points[1]})}return{}},p=function(e){var o=t._getTextSize(e).width+n;" "===e&&"justify"===i&&(o+=(r-a)/u);var s=0,d=0;for(c=void 0;Math.abs(o-s)/o>.01&&d<25;){d++;for(var v=s;void 0===l;)(l=g())&&v+l.pathLengtho?c=Konva.Path.getPointOnLine(o,h.x,h.y,l.points[0],l.points[1],h.x,h.y):l=void 0;break;case"A":var m=l.points[4],y=l.points[5],_=l.points[4]+y;0===f?f=m+1e-8:o>s?f+=Math.PI/180*y/Math.abs(y):f-=Math.PI/360*y/Math.abs(y),(y<0&&f<_||y>=0&&f>_)&&(f=_,p=!0),c=Konva.Path.getPointOnEllipticalArc(l.points[0],l.points[1],l.points[2],l.points[3],f,l.points[6]);break;case"C":0===f?f=o>l.pathLength?1e-8:o/l.pathLength:o>s?f+=(o-s)/l.pathLength:f-=(s-o)/l.pathLength,f>1&&(f=1,p=!0),c=Konva.Path.getPointOnCubicBezier(f,l.start.x,l.start.y,l.points[0],l.points[1],l.points[2],l.points[3],l.points[4],l.points[5]);break;case"Q":0===f?f=o/l.pathLength:o>s?f+=(o-s)/l.pathLength:f-=(s-o)/l.pathLength,f>1&&(f=1,p=!0),c=Konva.Path.getPointOnQuadraticBezier(f,l.start.x,l.start.y,l.points[0],l.points[1],l.points[2],l.points[3])}void 0!==c&&(s=Konva.Path.getLineLength(h.x,h.y,c.x,c.y)),p&&(p=!1,l=void 0)}},m=t._getTextSize("C").width+n,y=0;y> 16 & 255, - g: bigint >> 8 & 255, + r: (bigint >> 16) & 255, + g: (bigint >> 8) & 255, b: bigint & 255 }; }, @@ -635,7 +637,7 @@ * @memberof Konva.Util.prototype */ getRandomColor: function() { - var randColor = (Math.random() * 0xffffff << 0).toString(16); + var randColor = ((Math.random() * 0xffffff) << 0).toString(16); while (randColor.length < 6) { randColor = ZERO + randColor; } @@ -698,11 +700,13 @@ // from https://github.com/component/color-parser colorToRGBA: function(str) { str = str || 'black'; - return Konva.Util._namedColorToRBA(str) || + return ( + Konva.Util._namedColorToRBA(str) || Konva.Util._hex3ColorToRGBA(str) || Konva.Util._hex6ColorToRGBA(str) || Konva.Util._rgbColorToRGBA(str) || - Konva.Util._rgbaColorToRGBA(str); + Konva.Util._rgbaColorToRGBA(str) + ); }, // Parse named css color. Like "green" _namedColorToRBA: function(str) { diff --git a/src/filters/Blur.js b/src/filters/Blur.js index 2f8f828e..2cb50475 100644 --- a/src/filters/Blur.js +++ b/src/filters/Blur.js @@ -664,12 +664,12 @@ stackIn = stackStart; stackOut = stackEnd; for (x = 0; x < width; x++) { - pixels[yi + 3] = pa = a_sum * mul_sum >> shg_sum; + pixels[yi + 3] = pa = (a_sum * mul_sum) >> shg_sum; if (pa !== 0) { pa = 255 / pa; - pixels[yi] = (r_sum * mul_sum >> shg_sum) * pa; - pixels[yi + 1] = (g_sum * mul_sum >> shg_sum) * pa; - pixels[yi + 2] = (b_sum * mul_sum >> shg_sum) * pa; + pixels[yi] = ((r_sum * mul_sum) >> shg_sum) * pa; + pixels[yi + 1] = ((g_sum * mul_sum) >> shg_sum) * pa; + pixels[yi + 2] = ((b_sum * mul_sum) >> shg_sum) * pa; } else { pixels[yi] = pixels[yi + 1] = pixels[yi + 2] = 0; } @@ -684,7 +684,7 @@ b_out_sum -= stackIn.b; a_out_sum -= stackIn.a; - p = yw + ((p = x + radius + 1) < widthMinus1 ? p : widthMinus1) << 2; + p = (yw + ((p = x + radius + 1) < widthMinus1 ? p : widthMinus1)) << 2; r_in_sum += stackIn.r = pixels[p]; g_in_sum += stackIn.g = pixels[p + 1]; @@ -742,7 +742,7 @@ yp = width; for (i = 1; i <= radius; i++) { - yi = yp + x << 2; + yi = (yp + x) << 2; r_sum += (stack.r = pr = pixels[yi]) * (rbs = radiusPlus1 - i); g_sum += (stack.g = pg = pixels[yi + 1]) * rbs; @@ -766,12 +766,12 @@ stackOut = stackEnd; for (y = 0; y < height; y++) { p = yi << 2; - pixels[p + 3] = pa = a_sum * mul_sum >> shg_sum; + pixels[p + 3] = pa = (a_sum * mul_sum) >> shg_sum; if (pa > 0) { pa = 255 / pa; - pixels[p] = (r_sum * mul_sum >> shg_sum) * pa; - pixels[p + 1] = (g_sum * mul_sum >> shg_sum) * pa; - pixels[p + 2] = (b_sum * mul_sum >> shg_sum) * pa; + pixels[p] = ((r_sum * mul_sum) >> shg_sum) * pa; + pixels[p + 1] = ((g_sum * mul_sum) >> shg_sum) * pa; + pixels[p + 2] = ((b_sum * mul_sum) >> shg_sum) * pa; } else { pixels[p] = pixels[p + 1] = pixels[p + 2] = 0; } @@ -786,8 +786,10 @@ b_out_sum -= stackIn.b; a_out_sum -= stackIn.a; - p = x + - ((p = y + radiusPlus1) < heightMinus1 ? p : heightMinus1) * width << + p = + (x + + ((p = y + radiusPlus1) < heightMinus1 ? p : heightMinus1) * + width) << 2; r_sum += r_in_sum += stackIn.r = pixels[p]; diff --git a/src/filters/RGB.js b/src/filters/RGB.js index ffa6ae81..2deb4361 100644 --- a/src/filters/RGB.js +++ b/src/filters/RGB.js @@ -23,8 +23,8 @@ brightness; for (i = 0; i < nPixels; i += 4) { - brightness = (0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2]) / - 255; + brightness = + (0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2]) / 255; data[i] = brightness * red; // r data[i + 1] = brightness * green; // g data[i + 2] = brightness * blue; // b diff --git a/src/shapes/Arrow.js b/src/shapes/Arrow.js index 1465ddc0..6b44d361 100644 --- a/src/shapes/Arrow.js +++ b/src/shapes/Arrow.js @@ -49,7 +49,7 @@ ctx.rotate(radians); ctx.moveTo(0, 0); ctx.lineTo(-length, width / 2); - ctx.lineTo(-length, (-width) / 2); + ctx.lineTo(-length, -width / 2); ctx.closePath(); ctx.restore(); @@ -61,7 +61,7 @@ ctx.rotate((Math.atan2(-dy, -dx) + PI2) % PI2); ctx.moveTo(0, 0); ctx.lineTo(-length, width / 2); - ctx.lineTo(-length, (-width) / 2); + ctx.lineTo(-length, -width / 2); ctx.closePath(); ctx.restore(); } diff --git a/src/shapes/Image.js b/src/shapes/Image.js index 483dd5a6..150b0c12 100644 --- a/src/shapes/Image.js +++ b/src/shapes/Image.js @@ -39,9 +39,11 @@ this.hitFunc(this._hitFunc); }, _useBufferCanvas: function() { - return (this.hasShadow() || this.getAbsoluteOpacity() !== 1) && + return ( + (this.hasShadow() || this.getAbsoluteOpacity() !== 1) && this.hasStroke() && - this.getStage(); + this.getStage() + ); }, _sceneFunc: function(context) { var width = this.getWidth(), diff --git a/src/shapes/Label.js b/src/shapes/Label.js index 6a0dd274..99d7174a 100644 --- a/src/shapes/Label.js +++ b/src/shapes/Label.js @@ -134,7 +134,7 @@ switch (pointerDirection) { case UP: x = width / 2; - y = (-1) * pointerHeight; + y = -1 * pointerHeight; break; case RIGHT: x = width + pointerWidth; @@ -145,21 +145,21 @@ y = height + pointerHeight; break; case LEFT: - x = (-1) * pointerWidth; + x = -1 * pointerWidth; y = height / 2; break; } tag.setAttrs({ - x: (-1) * x, - y: (-1) * y, + x: -1 * x, + y: -1 * y, width: width, height: height }); text.setAttrs({ - x: (-1) * x, - y: (-1) * y + x: -1 * x, + y: -1 * y }); } } @@ -208,7 +208,7 @@ if (pointerDirection === UP) { context.lineTo((width - pointerWidth) / 2, 0); - context.lineTo(width / 2, (-1) * pointerHeight); + context.lineTo(width / 2, -1 * pointerHeight); context.lineTo((width + pointerWidth) / 2, 0); } @@ -268,7 +268,7 @@ if (pointerDirection === LEFT) { context.lineTo(0, (height + pointerHeight) / 2); - context.lineTo((-1) * pointerWidth, height / 2); + context.lineTo(-1 * pointerWidth, height / 2); context.lineTo(0, (height - pointerHeight) / 2); } diff --git a/src/shapes/Path.js b/src/shapes/Path.js index 0848c627..e0ae186f 100644 --- a/src/shapes/Path.js +++ b/src/shapes/Path.js @@ -362,7 +362,6 @@ cpy = p.shift(); points.push(cpx, cpy); break; - // Note: lineTo handlers need to be above this point case 'm': var dx = p.shift(); @@ -713,8 +712,8 @@ // Derived from: http://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes var psi = psiDeg * (Math.PI / 180.0); var xp = Math.cos(psi) * (x1 - x2) / 2.0 + Math.sin(psi) * (y1 - y2) / 2.0; - var yp = (-1) * Math.sin(psi) * (x1 - x2) / 2.0 + - Math.cos(psi) * (y1 - y2) / 2.0; + var yp = + -1 * Math.sin(psi) * (x1 - x2) / 2.0 + Math.cos(psi) * (y1 - y2) / 2.0; var lambda = xp * xp / (rx * rx) + yp * yp / (ry * ry); @@ -736,7 +735,7 @@ } var cxp = f * rx * yp / ry; - var cyp = f * (-ry) * xp / rx; + var cyp = f * -ry * xp / rx; var cx = (x1 + x2) / 2.0 + Math.cos(psi) * cxp - Math.sin(psi) * cyp; var cy = (y1 + y2) / 2.0 + Math.sin(psi) * cxp + Math.cos(psi) * cyp; @@ -752,7 +751,7 @@ }; var theta = vAngle([1, 0], [(xp - cxp) / rx, (yp - cyp) / ry]); var u = [(xp - cxp) / rx, (yp - cyp) / ry]; - var v = [((-1) * xp - cxp) / rx, ((-1) * yp - cyp) / ry]; + var v = [(-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry]; var dTheta = vAngle(u, v); if (vRatio(u, v) <= -1) { diff --git a/src/shapes/RegularPolygon.js b/src/shapes/RegularPolygon.js index aa4bfd26..ac1278b2 100644 --- a/src/shapes/RegularPolygon.js +++ b/src/shapes/RegularPolygon.js @@ -41,7 +41,7 @@ for (n = 1; n < sides; n++) { x = radius * Math.sin(n * 2 * Math.PI / sides); - y = (-1) * radius * Math.cos(n * 2 * Math.PI / sides); + y = -1 * radius * Math.cos(n * 2 * Math.PI / sides); context.lineTo(x, y); } context.closePath(); diff --git a/src/shapes/Sprite.js b/src/shapes/Sprite.js index 8376ee4b..75ef5cda 100644 --- a/src/shapes/Sprite.js +++ b/src/shapes/Sprite.js @@ -142,17 +142,16 @@ context.fillShape(this); }, _useBufferCanvas: function() { - return (this.hasShadow() || this.getAbsoluteOpacity() !== 1) && - this.hasStroke(); + return ( + (this.hasShadow() || this.getAbsoluteOpacity() !== 1) && + this.hasStroke() + ); }, _setInterval: function() { var that = this; - this.interval = setInterval( - function() { - that._updateIndex(); - }, - 1000 / this.getFrameRate() - ); + this.interval = setInterval(function() { + that._updateIndex(); + }, 1000 / this.getFrameRate()); }, /** * start sprite animation diff --git a/src/shapes/Star.js b/src/shapes/Star.js index f6d3cbe3..39a61302 100644 --- a/src/shapes/Star.js +++ b/src/shapes/Star.js @@ -46,7 +46,7 @@ for (var n = 1; n < numPoints * 2; n++) { var radius = n % 2 === 0 ? outerRadius : innerRadius; var x = radius * Math.sin(n * Math.PI / numPoints); - var y = (-1) * radius * Math.cos(n * Math.PI / numPoints); + var y = -1 * radius * Math.cos(n * Math.PI / numPoints); context.lineTo(x, y); } context.closePath(); diff --git a/src/shapes/Text.js b/src/shapes/Text.js index f30feb90..de3b4078 100644 --- a/src/shapes/Text.js +++ b/src/shapes/Text.js @@ -241,8 +241,8 @@ * @returns {Number} */ getHeight: function() { - var isAuto = this.attrs.height === AUTO || - this.attrs.height === undefined; + var isAuto = + this.attrs.height === AUTO || this.attrs.height === undefined; return isAuto ? this.getTextHeight() * this.textArr.length * this.getLineHeight() + this.getPadding() * 2 @@ -285,19 +285,23 @@ // removing font variant will solve // fix for: https://github.com/konvajs/konva/issues/94 if (Konva.UA.isIE) { - return this.getFontStyle() + + return ( + this.getFontStyle() + SPACE + this.getFontSize() + PX_SPACE + - this.getFontFamily(); + this.getFontFamily() + ); } - return this.getFontStyle() + + return ( + this.getFontStyle() + SPACE + this.getFontVariant() + SPACE + this.getFontSize() + PX_SPACE + - this.getFontFamily(); + this.getFontFamily() + ); }, _addTextLine: function(line) { if (this.align() === JUSTIFY) { @@ -309,8 +313,10 @@ _getTextWidth: function(text) { var latterSpacing = this.getLetterSpacing(); var length = text.length; - return dummyContext.measureText(text).width + - (length ? latterSpacing * (length - 1) : 0); + return ( + dummyContext.measureText(text).width + + (length ? latterSpacing * (length - 1) : 0) + ); }, _setTextData: function() { var lines = this.getText().split('\n'), @@ -348,7 +354,7 @@ */ var low = 0, high = line.length, match = '', matchWidth = 0; while (low < high) { - var mid = low + high >>> 1, + var mid = (low + high) >>> 1, substr = line.slice(0, mid + 1), substrWidth = this._getTextWidth(substr); if (substrWidth <= maxWidth) { @@ -368,10 +374,9 @@ // a fitting substring was found if (wrapAtWord) { // try to find a space or dash where wrapping could be done - var wrapIndex = Math.max( - match.lastIndexOf(SPACE), - match.lastIndexOf(DASH) - ) + 1; + var wrapIndex = + Math.max(match.lastIndexOf(SPACE), match.lastIndexOf(DASH)) + + 1; if (wrapIndex > 0) { // re-cut the substring found at the space/dash position low = wrapIndex; diff --git a/src/shapes/TextPath.js b/src/shapes/TextPath.js index 25d7212b..fdb2c3ed 100644 --- a/src/shapes/TextPath.js +++ b/src/shapes/TextPath.js @@ -262,7 +262,8 @@ p1 = undefined; while ( - Math.abs(glyphWidth - currLen) / glyphWidth > 0.01 && attempts < 25 + Math.abs(glyphWidth - currLen) / glyphWidth > 0.01 && + attempts < 25 ) { attempts++; var cumulativePathLength = currLen; @@ -270,7 +271,8 @@ pathCmd = getNextPathSegment(); if ( - pathCmd && cumulativePathLength + pathCmd.pathLength < glyphWidth + pathCmd && + cumulativePathLength + pathCmd.pathLength < glyphWidth ) { cumulativePathLength += pathCmd.pathLength; pathCmd = undefined; @@ -392,7 +394,6 @@ pathCmd.points[3] ); break; - } if (p1 !== undefined) { @@ -487,7 +488,8 @@ }; // map TextPath methods to Text - Konva.TextPath.prototype._getContextFont = Konva.Text.prototype._getContextFont; + Konva.TextPath.prototype._getContextFont = + Konva.Text.prototype._getContextFont; Konva.Util.extend(Konva.TextPath, Konva.Shape); diff --git a/test/functional/DragAndDropEvents-test.js b/test/functional/DragAndDropEvents-test.js index 0080695b..4d2b9c7a 100644 --- a/test/functional/DragAndDropEvents-test.js +++ b/test/functional/DragAndDropEvents-test.js @@ -71,52 +71,49 @@ suite('DragAndDropEvents', function() { assert(!Konva.isDragging(), ' isDragging() should be false 5'); assert(Konva.isDragReady(), ' isDragReady()) should be true 6'); - setTimeout( - function() { - stage.simulateMouseMove({ - x: 100, - y: 98 - }); + setTimeout(function() { + stage.simulateMouseMove({ + x: 100, + y: 98 + }); - assert(Konva.isDragging(), ' isDragging() should be true 7'); - assert(Konva.isDragReady(), ' isDragReady()) should be true 8'); + assert(Konva.isDragging(), ' isDragging() should be true 7'); + assert(Konva.isDragReady(), ' isDragReady()) should be true 8'); - assert(dragStart, 'dragstart event was not triggered 9'); - //assert.equal(dragMove, 'dragmove event was not triggered'); - assert(!dragEnd, 'dragend event should not have been triggered 10'); + assert(dragStart, 'dragstart event was not triggered 9'); + //assert.equal(dragMove, 'dragmove event was not triggered'); + assert(!dragEnd, 'dragend event should not have been triggered 10'); - stage.simulateMouseUp({ - x: 100, - y: 98 - }); + stage.simulateMouseUp({ + x: 100, + y: 98 + }); - assert(dragStart, 'dragstart event was not triggered 11'); - assert(dragMove, 'dragmove event was not triggered 12'); - assert(dragEnd, 'dragend event was not triggered 13'); + assert(dragStart, 'dragstart event was not triggered 11'); + assert(dragMove, 'dragmove event was not triggered 12'); + assert(dragEnd, 'dragend event was not triggered 13'); - assert.equal( - events.toString(), - 'mouseup,dragend', - 'mouseup should occur before dragend 14' - ); + assert.equal( + events.toString(), + 'mouseup,dragend', + 'mouseup should occur before dragend 14' + ); - assert(!Konva.isDragging(), ' isDragging() should be false 15'); - assert(!Konva.isDragReady(), ' isDragReady()) should be false 16'); + assert(!Konva.isDragging(), ' isDragging() should be false 15'); + assert(!Konva.isDragReady(), ' isDragReady()) should be false 16'); - //console.log(greenCircle.getPosition()); - //console.log(circle.getPosition()); + //console.log(greenCircle.getPosition()); + //console.log(circle.getPosition()); - assert.equal(greenCircle.getX(), 40, 'green circle x should be 40'); - assert.equal(greenCircle.getY(), 40, 'green circle y should be 40'); - assert.equal(circle.getX(), 100, 'circle x should be 100'); - assert.equal(circle.getY(), 100, 'circle y should be 100'); + assert.equal(greenCircle.getX(), 40, 'green circle x should be 40'); + assert.equal(greenCircle.getY(), 40, 'green circle y should be 40'); + assert.equal(circle.getX(), 100, 'circle x should be 100'); + assert.equal(circle.getY(), 100, 'circle y should be 100'); - showHit(layer); + showHit(layer); - done(); - }, - 20 - ); + done(); + }, 20); }); // ====================================================== @@ -171,31 +168,28 @@ suite('DragAndDropEvents', function() { assert(!circle.isDragging(), 'circle should not be dragging'); - setTimeout( - function() { - stage.simulateMouseMove({ - x: 100, - y: 98 - }); + setTimeout(function() { + stage.simulateMouseMove({ + x: 100, + y: 98 + }); - assert(circle.isDragging(), 'circle should be dragging'); - assert(!dragEnd, 'dragEnd should not have fired yet'); + assert(circle.isDragging(), 'circle should be dragging'); + assert(!dragEnd, 'dragEnd should not have fired yet'); - // at this point, we are in drag and drop mode + // at this point, we are in drag and drop mode - // removing or destroying the circle should trigger dragend - circle.destroy(); - layer.draw(); + // removing or destroying the circle should trigger dragend + circle.destroy(); + layer.draw(); - assert( - !circle.isDragging(), - 'destroying circle should stop drag and drop' - ); - assert(dragEnd, 'dragEnd should have fired'); - done(); - }, - 20 - ); + assert( + !circle.isDragging(), + 'destroying circle should stop drag and drop' + ); + assert(dragEnd, 'dragEnd should have fired'); + done(); + }, 20); }); // ====================================================== @@ -232,24 +226,21 @@ suite('DragAndDropEvents', function() { y: 40 }); - setTimeout( - function() { - stage.simulateMouseMove({ - x: 100, - y: 100 - }); + setTimeout(function() { + stage.simulateMouseMove({ + x: 100, + y: 100 + }); - stage.simulateMouseUp({ - x: 100, - y: 100 - }); + stage.simulateMouseUp({ + x: 100, + y: 100 + }); - assert(!clicked, 'click event should not have been fired'); + assert(!clicked, 'click event should not have been fired'); - done(); - }, - 20 - ); + done(); + }, 20); }); // ====================================================== @@ -277,27 +268,24 @@ suite('DragAndDropEvents', function() { y: 40 }); - setTimeout( - function() { - stage.simulateMouseMove({ - x: 40, - y: 42 - }); - assert(!circle.isDragging(), 'still not dragging'); - stage.simulateMouseMove({ - x: 40, - y: 45 - }); - assert(circle.isDragging(), 'now circle is dragging'); - stage.simulateMouseUp({ - x: 41, - y: 45 - }); + setTimeout(function() { + stage.simulateMouseMove({ + x: 40, + y: 42 + }); + assert(!circle.isDragging(), 'still not dragging'); + stage.simulateMouseMove({ + x: 40, + y: 45 + }); + assert(circle.isDragging(), 'now circle is dragging'); + stage.simulateMouseUp({ + x: 41, + y: 45 + }); - done(); - }, - 20 - ); + done(); + }, 20); }); // ====================================================== @@ -347,24 +335,21 @@ suite('DragAndDropEvents', function() { y: 100 }); - setTimeout( - function() { - stage.simulateMouseMove({ - x: 100, - y: 100 - }); + setTimeout(function() { + stage.simulateMouseMove({ + x: 100, + y: 100 + }); - stage.simulateMouseUp({ - x: 100, - y: 100 - }); + stage.simulateMouseUp({ + x: 100, + y: 100 + }); - assert.equal(circle.getPosition().x, 380, 'circle x should be 380'); - assert.equal(circle.getPosition().y, 100, 'circle y should be 100'); - done(); - }, - 20 - ); + assert.equal(circle.getPosition().x, 380, 'circle x should be 380'); + assert.equal(circle.getPosition().y, 100, 'circle y should be 100'); + done(); + }, 20); }); // ====================================================== @@ -413,27 +398,24 @@ suite('DragAndDropEvents', function() { y: 96 }); - setTimeout( - function() { - stage.simulateMouseMove({ - x: 210, - y: 109 - }); + setTimeout(function() { + stage.simulateMouseMove({ + x: 210, + y: 109 + }); - stage.simulateMouseUp({ - x: 210, - y: 109 - }); + stage.simulateMouseUp({ + x: 210, + y: 109 + }); - //console.log(layer.getPosition()) + //console.log(layer.getPosition()) - assert.equal(layer.getX(), -189, 'layer x should be -189'); - assert.equal(layer.getY(), 13, 'layer y should be 13'); + assert.equal(layer.getX(), -189, 'layer x should be -189'); + assert.equal(layer.getY(), 13, 'layer y should be 13'); - done(); - }, - 20 - ); + done(); + }, 20); }); // ====================================================== @@ -475,24 +457,21 @@ suite('DragAndDropEvents', function() { y: 100 }); - setTimeout( - function() { - stage.simulateMouseMove({ - x: 300, - y: 110 - }); + setTimeout(function() { + stage.simulateMouseMove({ + x: 300, + y: 110 + }); - stage.simulateMouseUp({ - x: 300, - y: 110 - }); + stage.simulateMouseUp({ + x: 300, + y: 110 + }); - assert.equal(stage.getX(), 300); - assert.equal(stage.getY(), 10); + assert.equal(stage.getX(), 300); + assert.equal(stage.getY(), 10); - done(); - }, - 20 - ); + done(); + }, 20); }); }); diff --git a/test/functional/MouseEvents-test.js b/test/functional/MouseEvents-test.js index 6675f999..4abcacc8 100644 --- a/test/functional/MouseEvents-test.js +++ b/test/functional/MouseEvents-test.js @@ -19,7 +19,7 @@ suite('MouseEvents', function() { layer.add(circle); stage.add(layer); - var circleMousedown = circleMouseup = stageContentMousedown = stageContentMouseup = stageContentMousemove = stageContentMouseout = stageContentMouseover = stageContentClick = stageContentDblClick = 0; + var circleMousedown = (circleMouseup = stageContentMousedown = stageContentMouseup = stageContentMousemove = stageContentMouseout = stageContentMouseover = stageContentClick = stageContentDblClick = 0); var top = stage.content.getBoundingClientRect().top; @@ -103,33 +103,30 @@ suite('MouseEvents', function() { assert.equal(stageContentMouseup, 3); //assert.equal(stageContentDblClick, 1); - setTimeout( - function() { - stage.simulateMouseMove({ - x: 200, - y: 1 - }); + setTimeout(function() { + stage.simulateMouseMove({ + x: 200, + y: 1 + }); - assert.equal(stageContentMousemove, 1); + assert.equal(stageContentMousemove, 1); - stage._mouseout({ - offsetX: 0, - offsetY: 0 - }); + stage._mouseout({ + offsetX: 0, + offsetY: 0 + }); - assert.equal(stageContentMouseout, 1); + assert.equal(stageContentMouseout, 1); - stage._mouseover({ - offsetX: 0, - offsetY: 0 - }); + stage._mouseover({ + offsetX: 0, + offsetY: 0 + }); - assert.equal(stageContentMouseover, 1); + assert.equal(stageContentMouseover, 1); - done(); - }, - 20 - ); + done(); + }, 20); }); // ====================================================== @@ -435,226 +432,206 @@ suite('MouseEvents', function() { assert.equal(circle.getFill(), 'red', 'circle fill should be red'); assert.equal(circle.getStroke(), 'black', 'circle stroke should be black'); - setTimeout( - function() { + setTimeout(function() { + stage.simulateMouseMove({ + x: 377, + y: 101 + }); + + assert.equal(circle.getFill(), 'yellow', 'circle fill should be yellow'); + assert.equal( + circle.getStroke(), + 'purple', + 'circle stroke should be purple' + ); + + setTimeout(function() { + // move mouse back out of circle stage.simulateMouseMove({ - x: 377, - y: 101 + x: 157, + y: 138 }); - assert.equal( - circle.getFill(), - 'yellow', - 'circle fill should be yellow' - ); + assert.equal(circle.getFill(), 'red', 'circle fill should be red'); assert.equal( circle.getStroke(), - 'purple', - 'circle stroke should be purple' + 'black', + 'circle stroke should be black' ); - - setTimeout( - function() { - // move mouse back out of circle - stage.simulateMouseMove({ - x: 157, - y: 138 - }); - - assert.equal(circle.getFill(), 'red', 'circle fill should be red'); - assert.equal( - circle.getStroke(), - 'black', - 'circle stroke should be black' - ); - done(); - }, - 20 - ); - }, - 20 - ); + done(); + }, 20); + }, 20); }); // ====================================================== - test( - 'mousedown mouseup mouseover mouseout mousemove click dblclick', - function(done) { - var stage = addStage(); - var layer = new Konva.Layer(); - var circle = new Konva.Circle({ - x: stage.getWidth() / 2, - y: stage.getHeight() / 2, - radius: 70, - fill: 'red', - stroke: 'black', - strokeWidth: 4 + test('mousedown mouseup mouseover mouseout mousemove click dblclick', function( + done + ) { + var stage = addStage(); + var layer = new Konva.Layer(); + var circle = new Konva.Circle({ + x: stage.getWidth() / 2, + y: stage.getHeight() / 2, + radius: 70, + fill: 'red', + stroke: 'black', + strokeWidth: 4 + }); + + // desktop events + var mousedown = false; + var mouseup = false; + var click = false; + var dblclick = false; + var mouseover = false; + var mouseout = false; + var mousemove = false; + + circle.on('mousedown', function() { + mousedown = true; + //log('mousedown'); + }); + + circle.on('mouseup', function() { + mouseup = true; + //log('mouseup'); + }); + + circle.on('mouseover', function() { + mouseover = true; + //log('mouseover'); + }); + + circle.on('mouseout', function() { + mouseout = true; + //log('mouseout'); + }); + + circle.on('mousemove', function() { + mousemove = true; + //log('mousemove'); + }); + + circle.on('click', function() { + click = true; + //log('click'); + }); + + circle.on('dblclick', function() { + dblclick = true; + //log('dblclick'); + }); + + layer.add(circle); + stage.add(layer); + + var top = stage.content.getBoundingClientRect().top; + + setTimeout(function() { + // move mouse to center of circle to trigger mouseover + stage.simulateMouseMove({ + x: 290, + y: 100 }); - // desktop events - var mousedown = false; - var mouseup = false; - var click = false; - var dblclick = false; - var mouseover = false; - var mouseout = false; - var mousemove = false; + assert(mouseover, '1) mouseover should be true'); + assert(!mousemove, '1) mousemove should be true'); + assert(!mousedown, '1) mousedown should be false'); + assert(!mouseup, '1) mouseup should be false'); + assert(!click, '1) click should be false'); + assert(!dblclick, '1) dblclick should be false'); + assert(!mouseout, '1) mouseout should be false'); - circle.on('mousedown', function() { - mousedown = true; - //log('mousedown'); - }); + setTimeout(function() { + // move mouse again inside circle to trigger mousemove + stage.simulateMouseMove({ + x: 290, + y: 100 + }); - circle.on('mouseup', function() { - mouseup = true; - //log('mouseup'); - }); + assert(mouseover, '2) mouseover should be true'); + assert(mousemove, '2) mousemove should be true'); + assert(!mousedown, '2) mousedown should be false'); + assert(!mouseup, '2) mouseup should be false'); + assert(!click, '2) click should be false'); + assert(!dblclick, '2) dblclick should be false'); + assert(!mouseout, '2) mouseout should be false'); - circle.on('mouseover', function() { - mouseover = true; - //log('mouseover'); - }); + // mousedown inside circle + stage.simulateMouseDown({ + x: 290, + y: 100 + }); - circle.on('mouseout', function() { - mouseout = true; - //log('mouseout'); - }); + assert(mouseover, '3) mouseover should be true'); + assert(mousemove, '3) mousemove should be true'); + assert(mousedown, '3) mousedown should be true'); + assert(!mouseup, '3) mouseup should be false'); + assert(!click, '3) click should be false'); + assert(!dblclick, '3) dblclick should be false'); + assert(!mouseout, '3) mouseout should be false'); - circle.on('mousemove', function() { - mousemove = true; - //log('mousemove'); - }); + // mouseup inside circle + stage.simulateMouseUp({ + x: 290, + y: 100 + }); - circle.on('click', function() { - click = true; - //log('click'); - }); + assert(mouseover, '4) mouseover should be true'); + assert(mousemove, '4) mousemove should be true'); + assert(mousedown, '4) mousedown should be true'); + assert(mouseup, '4) mouseup should be true'); + assert(click, '4) click should be true'); + assert(!dblclick, '4) dblclick should be false'); + assert(!mouseout, '4) mouseout should be false'); - circle.on('dblclick', function() { - dblclick = true; - //log('dblclick'); - }); + // mousedown inside circle + stage.simulateMouseDown({ + x: 290, + y: 100 + }); - layer.add(circle); - stage.add(layer); + assert(mouseover, '5) mouseover should be true'); + assert(mousemove, '5) mousemove should be true'); + assert(mousedown, '5) mousedown should be true'); + assert(mouseup, '5) mouseup should be true'); + assert(click, '5) click should be true'); + assert(!dblclick, '5) dblclick should be false'); + assert(!mouseout, '5) mouseout should be false'); - var top = stage.content.getBoundingClientRect().top; + // mouseup inside circle to trigger double click + stage.simulateMouseUp({ + x: 290, + y: 100 + }); - setTimeout( - function() { - // move mouse to center of circle to trigger mouseover + assert(mouseover, '6) mouseover should be true'); + assert(mousemove, '6) mousemove should be true'); + assert(mousedown, '6) mousedown should be true'); + assert(mouseup, '6) mouseup should be true'); + assert(click, '6) click should be true'); + assert(dblclick, '6) dblclick should be true'); + assert(!mouseout, '6) mouseout should be false'); + + setTimeout(function() { + // move mouse outside of circle to trigger mouseout stage.simulateMouseMove({ - x: 290, + x: 0, y: 100 }); - assert(mouseover, '1) mouseover should be true'); - assert(!mousemove, '1) mousemove should be true'); - assert(!mousedown, '1) mousedown should be false'); - assert(!mouseup, '1) mouseup should be false'); - assert(!click, '1) click should be false'); - assert(!dblclick, '1) dblclick should be false'); - assert(!mouseout, '1) mouseout should be false'); - - setTimeout( - function() { - // move mouse again inside circle to trigger mousemove - stage.simulateMouseMove({ - x: 290, - y: 100 - }); - - assert(mouseover, '2) mouseover should be true'); - assert(mousemove, '2) mousemove should be true'); - assert(!mousedown, '2) mousedown should be false'); - assert(!mouseup, '2) mouseup should be false'); - assert(!click, '2) click should be false'); - assert(!dblclick, '2) dblclick should be false'); - assert(!mouseout, '2) mouseout should be false'); - - // mousedown inside circle - stage.simulateMouseDown({ - x: 290, - y: 100 - }); - - assert(mouseover, '3) mouseover should be true'); - assert(mousemove, '3) mousemove should be true'); - assert(mousedown, '3) mousedown should be true'); - assert(!mouseup, '3) mouseup should be false'); - assert(!click, '3) click should be false'); - assert(!dblclick, '3) dblclick should be false'); - assert(!mouseout, '3) mouseout should be false'); - - // mouseup inside circle - stage.simulateMouseUp({ - x: 290, - y: 100 - }); - - assert(mouseover, '4) mouseover should be true'); - assert(mousemove, '4) mousemove should be true'); - assert(mousedown, '4) mousedown should be true'); - assert(mouseup, '4) mouseup should be true'); - assert(click, '4) click should be true'); - assert(!dblclick, '4) dblclick should be false'); - assert(!mouseout, '4) mouseout should be false'); - - // mousedown inside circle - stage.simulateMouseDown({ - x: 290, - y: 100 - }); - - assert(mouseover, '5) mouseover should be true'); - assert(mousemove, '5) mousemove should be true'); - assert(mousedown, '5) mousedown should be true'); - assert(mouseup, '5) mouseup should be true'); - assert(click, '5) click should be true'); - assert(!dblclick, '5) dblclick should be false'); - assert(!mouseout, '5) mouseout should be false'); - - // mouseup inside circle to trigger double click - stage.simulateMouseUp({ - x: 290, - y: 100 - }); - - assert(mouseover, '6) mouseover should be true'); - assert(mousemove, '6) mousemove should be true'); - assert(mousedown, '6) mousedown should be true'); - assert(mouseup, '6) mouseup should be true'); - assert(click, '6) click should be true'); - assert(dblclick, '6) dblclick should be true'); - assert(!mouseout, '6) mouseout should be false'); - - setTimeout( - function() { - // move mouse outside of circle to trigger mouseout - stage.simulateMouseMove({ - x: 0, - y: 100 - }); - - assert(mouseover, '7) mouseover should be true'); - assert(mousemove, '7) mousemove should be true'); - assert(mousedown, '7) mousedown should be true'); - assert(mouseup, '7) mouseup should be true'); - assert(click, '7) click should be true'); - assert(dblclick, '7) dblclick should be true'); - assert(mouseout, '7) mouseout should be true'); - done(); - }, - 20 - ); - }, - 20 - ); - }, - 20 - ); - } - ); + assert(mouseover, '7) mouseover should be true'); + assert(mousemove, '7) mousemove should be true'); + assert(mousedown, '7) mousedown should be true'); + assert(mouseup, '7) mouseup should be true'); + assert(click, '7) click should be true'); + assert(dblclick, '7) dblclick should be true'); + assert(mouseout, '7) mouseout should be true'); + done(); + }, 20); + }, 20); + }, 20); + }); // ====================================================== test('test group mousedown events', function() { @@ -890,168 +867,89 @@ suite('MouseEvents', function() { var top = stage.content.getBoundingClientRect().top; - setTimeout( - function() { - // move mouse outside of circles + setTimeout(function() { + // move mouse outside of circles + stage.simulateMouseMove({ + x: 177, + y: 146 + }); + + assert.equal(redMouseenters, 0, 'redMouseenters should be 0'); + assert.equal(redMouseleaves, 0, 'redMouseleaves should be 0'); + assert.equal(greenMouseenters, 0, 'greenMouseenters should be 0'); + assert.equal(greenMouseleaves, 0, 'greenMouseleaves should be 0'); + assert.equal(groupMouseenters, 0, 'groupMouseenters should be 0'); + assert.equal(groupMouseleaves, 0, 'groupMouseleaves should be 0'); + + setTimeout(function() { + // move mouse inside of red circle stage.simulateMouseMove({ - x: 177, - y: 146 + x: 236, + y: 145 }); - assert.equal(redMouseenters, 0, 'redMouseenters should be 0'); + //console.log('groupMouseenters=' + groupMouseenters); + + assert.equal(redMouseenters, 1, 'redMouseenters should be 1'); assert.equal(redMouseleaves, 0, 'redMouseleaves should be 0'); assert.equal(greenMouseenters, 0, 'greenMouseenters should be 0'); assert.equal(greenMouseleaves, 0, 'greenMouseleaves should be 0'); - assert.equal(groupMouseenters, 0, 'groupMouseenters should be 0'); + assert.equal(groupMouseenters, 1, 'groupMouseenters should be 1'); assert.equal(groupMouseleaves, 0, 'groupMouseleaves should be 0'); - setTimeout( - function() { - // move mouse inside of red circle + setTimeout(function() { + // move mouse inside of green circle + stage.simulateMouseMove({ + x: 284, + y: 118 + }); + + assert.equal(redMouseenters, 1, 'redMouseenters should be 1'); + assert.equal(redMouseleaves, 1, 'redMouseleaves should be 1'); + assert.equal(greenMouseenters, 1, 'greenMouseenters should be 1'); + assert.equal(greenMouseleaves, 0, 'greenMouseleaves should be 0'); + assert.equal(groupMouseenters, 1, 'groupMouseenters should be 1'); + assert.equal(groupMouseleaves, 0, 'groupMouseleaves should be 0'); + + setTimeout(function() { + // move mouse back to red circle + stage.simulateMouseMove({ - x: 236, - y: 145 + x: 345, + y: 105 }); - //console.log('groupMouseenters=' + groupMouseenters); - - assert.equal(redMouseenters, 1, 'redMouseenters should be 1'); - assert.equal(redMouseleaves, 0, 'redMouseleaves should be 0'); - assert.equal(greenMouseenters, 0, 'greenMouseenters should be 0'); - assert.equal(greenMouseleaves, 0, 'greenMouseleaves should be 0'); + assert.equal(redMouseenters, 2, 'redMouseenters should be 2'); + assert.equal(redMouseleaves, 1, 'redMouseleaves should be 1'); + assert.equal(greenMouseenters, 1, 'greenMouseenters should be 1'); + assert.equal(greenMouseleaves, 1, 'greenMouseleaves should be 1'); assert.equal(groupMouseenters, 1, 'groupMouseenters should be 1'); assert.equal(groupMouseleaves, 0, 'groupMouseleaves should be 0'); - setTimeout( - function() { - // move mouse inside of green circle - stage.simulateMouseMove({ - x: 284, - y: 118 - }); + setTimeout(function() { + // move mouse outside of circles + stage.simulateMouseMove({ + x: 177, + y: 146 + }); - assert.equal(redMouseenters, 1, 'redMouseenters should be 1'); - assert.equal(redMouseleaves, 1, 'redMouseleaves should be 1'); - assert.equal( - greenMouseenters, - 1, - 'greenMouseenters should be 1' - ); - assert.equal( - greenMouseleaves, - 0, - 'greenMouseleaves should be 0' - ); - assert.equal( - groupMouseenters, - 1, - 'groupMouseenters should be 1' - ); - assert.equal( - groupMouseleaves, - 0, - 'groupMouseleaves should be 0' - ); + assert.equal(redMouseenters, 2, 'redMouseenters should be 2'); + assert.equal(redMouseleaves, 2, 'redMouseleaves should be 2'); + assert.equal(greenMouseenters, 1, 'greenMouseenters should be 1'); + assert.equal(greenMouseleaves, 1, 'greenMouseleaves should be 1'); + assert.equal(groupMouseenters, 1, 'groupMouseenters should be 1'); + assert.equal(groupMouseleaves, 1, 'groupMouseleaves should be 1'); - setTimeout( - function() { - // move mouse back to red circle + //document.body.appendChild(layer.bufferCanvas.element) - stage.simulateMouseMove({ - x: 345, - y: 105 - }); + //layer.bufferCanvas.element.style.marginTop = '220px'; - assert.equal( - redMouseenters, - 2, - 'redMouseenters should be 2' - ); - assert.equal( - redMouseleaves, - 1, - 'redMouseleaves should be 1' - ); - assert.equal( - greenMouseenters, - 1, - 'greenMouseenters should be 1' - ); - assert.equal( - greenMouseleaves, - 1, - 'greenMouseleaves should be 1' - ); - assert.equal( - groupMouseenters, - 1, - 'groupMouseenters should be 1' - ); - assert.equal( - groupMouseleaves, - 0, - 'groupMouseleaves should be 0' - ); - - setTimeout( - function() { - // move mouse outside of circles - stage.simulateMouseMove({ - x: 177, - y: 146 - }); - - assert.equal( - redMouseenters, - 2, - 'redMouseenters should be 2' - ); - assert.equal( - redMouseleaves, - 2, - 'redMouseleaves should be 2' - ); - assert.equal( - greenMouseenters, - 1, - 'greenMouseenters should be 1' - ); - assert.equal( - greenMouseleaves, - 1, - 'greenMouseleaves should be 1' - ); - assert.equal( - groupMouseenters, - 1, - 'groupMouseenters should be 1' - ); - assert.equal( - groupMouseleaves, - 1, - 'groupMouseleaves should be 1' - ); - - //document.body.appendChild(layer.bufferCanvas.element) - - //layer.bufferCanvas.element.style.marginTop = '220px'; - - done(); - }, - 20 - ); - }, - 20 - ); - }, - 20 - ); - }, - 20 - ); - }, - 20 - ); + done(); + }, 20); + }, 20); + }, 20); + }, 20); + }, 20); }); // ====================================================== @@ -1697,143 +1595,95 @@ suite('MouseEvents', function() { mouseouts++; }); - setTimeout( - function() { - // move mouse far outside circle + setTimeout(function() { + // move mouse far outside circle + stage.simulateMouseMove({ + x: 113, + y: 112 + }); + + setTimeout(function() { + assert.equal(mouseovers, 0, '1) mouseovers should be 0'); + assert.equal(mouseouts, 0, '1) mouseouts should be 0'); + stage.simulateMouseMove({ - x: 113, - y: 112 + x: 286, + y: 118 }); - setTimeout( - function() { - assert.equal(mouseovers, 0, '1) mouseovers should be 0'); - assert.equal(mouseouts, 0, '1) mouseouts should be 0'); + assert.equal(mouseovers, 1, '2) mouseovers should be 1'); + assert.equal(mouseouts, 0, '2)mouseouts should be 0'); + setTimeout(function() { + stage.simulateMouseMove({ + x: 113, + y: 112 + }); + + assert.equal(mouseovers, 1, '3) mouseovers should be 1'); + assert.equal(mouseouts, 1, '3) mouseouts should be 1'); + + showHit(layer); + + // set drawBufferFunc with setter + + circle.hitFunc(function(context) { + var _context = context._context; + _context.beginPath(); + _context.arc(0, 0, this.getRadius() - 50, 0, Math.PI * 2, true); + _context.closePath(); + context.fillStrokeShape(this); + }); + + layer.getHitCanvas().getContext().clear(); + layer.drawHit(); + + setTimeout(function() { + // move mouse far outside circle stage.simulateMouseMove({ - x: 286, - y: 118 + x: 113, + y: 112 }); - assert.equal(mouseovers, 1, '2) mouseovers should be 1'); - assert.equal(mouseouts, 0, '2)mouseouts should be 0'); + assert.equal(mouseovers, 1, '4) mouseovers should be 1'); + assert.equal(mouseouts, 1, '4) mouseouts should be 1'); - setTimeout( - function() { + setTimeout(function() { + stage.simulateMouseMove({ + x: 286, + y: 118 + }); + + assert.equal(mouseovers, 1, '5) mouseovers should be 1'); + assert.equal(mouseouts, 1, '5) mouseouts should be 1'); + + setTimeout(function() { stage.simulateMouseMove({ - x: 113, + x: 321, y: 112 }); - assert.equal(mouseovers, 1, '3) mouseovers should be 1'); - assert.equal(mouseouts, 1, '3) mouseouts should be 1'); + assert.equal(mouseovers, 1, '6) mouseovers should be 1'); + assert.equal(mouseouts, 1, '6) mouseouts should be 1'); - showHit(layer); + setTimeout(function() { + // move to center of circle + stage.simulateMouseMove({ + x: 375, + y: 112 + }); - // set drawBufferFunc with setter + assert.equal(mouseovers, 2, '7) mouseovers should be 2'); + assert.equal(mouseouts, 1, '7) mouseouts should be 1'); - circle.hitFunc(function(context) { - var _context = context._context; - _context.beginPath(); - _context.arc( - 0, - 0, - this.getRadius() - 50, - 0, - Math.PI * 2, - true - ); - _context.closePath(); - context.fillStrokeShape(this); - }); - - layer.getHitCanvas().getContext().clear(); - layer.drawHit(); - - setTimeout( - function() { - // move mouse far outside circle - stage.simulateMouseMove({ - x: 113, - y: 112 - }); - - assert.equal(mouseovers, 1, '4) mouseovers should be 1'); - assert.equal(mouseouts, 1, '4) mouseouts should be 1'); - - setTimeout( - function() { - stage.simulateMouseMove({ - x: 286, - y: 118 - }); - - assert.equal( - mouseovers, - 1, - '5) mouseovers should be 1' - ); - assert.equal(mouseouts, 1, '5) mouseouts should be 1'); - - setTimeout( - function() { - stage.simulateMouseMove({ - x: 321, - y: 112 - }); - - assert.equal( - mouseovers, - 1, - '6) mouseovers should be 1' - ); - assert.equal( - mouseouts, - 1, - '6) mouseouts should be 1' - ); - - setTimeout( - function() { - // move to center of circle - stage.simulateMouseMove({ - x: 375, - y: 112 - }); - - assert.equal( - mouseovers, - 2, - '7) mouseovers should be 2' - ); - assert.equal( - mouseouts, - 1, - '7) mouseouts should be 1' - ); - - done(); - }, - 20 - ); - }, - 20 - ); - }, - 20 - ); - }, - 20 - ); - }, - 20 - ); - }, - 20 - ); - }, - 20 - ); + done(); + }, 20); + }, 20); + }, 20); + }, 20); + }, 20); + }, 20); + }, 20); }); test('change ratio for hit graph', function() { diff --git a/test/lib/blanket.js b/test/lib/blanket.js index e73ae647..505be708 100644 --- a/test/lib/blanket.js +++ b/test/lib/blanket.js @@ -56,7 +56,7 @@ parseStatement: true, parseSourceElement: true */ } else if (typeof exports !== 'undefined') { factory(exports); } else { - factory(root.esprima = {}); + factory((root.esprima = {})); } })(this, function(exports) { 'use strict'; @@ -283,7 +283,8 @@ parseStatement: true, parseSourceElement: true */ // 7.2 White Space function isWhiteSpace(ch) { - return ch === 0x20 || + return ( + ch === 0x20 || ch === 0x09 || ch === 0x0b || ch === 0x0c || @@ -307,7 +308,8 @@ parseStatement: true, parseSourceElement: true */ 0x205f, 0x3000, 0xfeff - ].indexOf(ch) >= 0); + ].indexOf(ch) >= 0) + ); } // 7.3 Line Terminators @@ -319,24 +321,28 @@ parseStatement: true, parseSourceElement: true */ // 7.6 Identifier Names and Identifiers function isIdentifierStart(ch) { - return ch === 0x24 || + return ( + ch === 0x24 || ch === 0x5f || // $ (dollar) and _ (underscore) (ch >= 0x41 && ch <= 0x5a) || // A..Z (ch >= 0x61 && ch <= 0x7a) || // a..z ch === 0x5c || // \ (backslash) (ch >= 0x80 && - Regex.NonAsciiIdentifierStart.test(String.fromCharCode(ch))); + Regex.NonAsciiIdentifierStart.test(String.fromCharCode(ch))) + ); } function isIdentifierPart(ch) { - return ch === 0x24 || + return ( + ch === 0x24 || ch === 0x5f || // $ (dollar) and _ (underscore) (ch >= 0x41 && ch <= 0x5a) || // A..Z (ch >= 0x61 && ch <= 0x7a) || // a..z (ch >= 0x30 && ch <= 0x39) || // 0..9 ch === 0x5c || // \ (backslash) (ch >= 0x80 && - Regex.NonAsciiIdentifierPart.test(String.fromCharCode(ch))); + Regex.NonAsciiIdentifierPart.test(String.fromCharCode(ch))) + ); } // 7.6.1.2 Future Reserved Words @@ -391,34 +397,42 @@ parseStatement: true, parseSourceElement: true */ case 2: return id === 'if' || id === 'in' || id === 'do'; case 3: - return id === 'var' || + return ( + id === 'var' || id === 'for' || id === 'new' || id === 'try' || - id === 'let'; + id === 'let' + ); case 4: - return id === 'this' || + return ( + id === 'this' || id === 'else' || id === 'case' || id === 'void' || id === 'with' || - id === 'enum'; + id === 'enum' + ); case 5: - return id === 'while' || + return ( + id === 'while' || id === 'break' || id === 'catch' || id === 'throw' || id === 'const' || id === 'yield' || id === 'class' || - id === 'super'; + id === 'super' + ); case 6: - return id === 'return' || + return ( + id === 'return' || id === 'typeof' || id === 'delete' || id === 'switch' || id === 'export' || - id === 'import'; + id === 'import' + ); case 7: return id === 'default' || id === 'finally' || id === 'extends'; case 8: @@ -635,7 +649,7 @@ parseStatement: true, parseSourceElement: true */ function getEscapedIdentifier() { var ch, id; - ch = source.charCodeAt((index++)); + ch = source.charCodeAt(index++); id = String.fromCharCode(ch); // '\u' (U+005C, U+0075) denotes an escaped character. @@ -1316,10 +1330,12 @@ parseStatement: true, parseSourceElement: true */ } function isIdentifierName(token) { - return token.type === Token.Identifier || + return ( + token.type === Token.Identifier || token.type === Token.Keyword || token.type === Token.BooleanLiteral || - token.type === Token.NullLiteral; + token.type === Token.NullLiteral + ); } function advanceSlash() { @@ -1537,19 +1553,16 @@ parseStatement: true, parseSourceElement: true */ } else { if ( extra.bottomRightStack.length > 0 && - extra.bottomRightStack[ - extra.bottomRightStack.length - 1 - ].trailingComments && - extra.bottomRightStack[ - extra.bottomRightStack.length - 1 - ].trailingComments[0].range[0] >= node.range[1] + extra.bottomRightStack[extra.bottomRightStack.length - 1] + .trailingComments && + extra.bottomRightStack[extra.bottomRightStack.length - 1] + .trailingComments[0].range[0] >= node.range[1] ) { - trailingComments = extra.bottomRightStack[ - extra.bottomRightStack.length - 1 - ].trailingComments; - delete extra.bottomRightStack[ - extra.bottomRightStack.length - 1 - ].trailingComments; + trailingComments = + extra.bottomRightStack[extra.bottomRightStack.length - 1] + .trailingComments; + delete extra.bottomRightStack[extra.bottomRightStack.length - 1] + .trailingComments; } } @@ -1565,9 +1578,8 @@ parseStatement: true, parseSourceElement: true */ if (lastChild) { if ( lastChild.leadingComments && - lastChild.leadingComments[ - lastChild.leadingComments.length - 1 - ].range[1] <= node.range[0] + lastChild.leadingComments[lastChild.leadingComments.length - 1] + .range[1] <= node.range[0] ) { node.leadingComments = lastChild.leadingComments; delete lastChild.leadingComments; @@ -2085,7 +2097,8 @@ parseStatement: true, parseSourceElement: true */ return false; } op = lookahead.value; - return op === '=' || + return ( + op === '=' || op === '*=' || op === '/=' || op === '%=' || @@ -2096,7 +2109,8 @@ parseStatement: true, parseSourceElement: true */ op === '>>>=' || op === '&=' || op === '^=' || - op === '|='; + op === '|=' + ); } function consumeSemicolon() { @@ -2122,8 +2136,9 @@ parseStatement: true, parseSourceElement: true */ // Return true if provided expression is LeftHandSideExpression function isLeftHandSide(expr) { - return expr.type === Syntax.Identifier || - expr.type === Syntax.MemberExpression; + return ( + expr.type === Syntax.Identifier || expr.type === Syntax.MemberExpression + ); } // 11.1.4 Array Initialiser @@ -2355,7 +2370,8 @@ parseStatement: true, parseSourceElement: true */ if (type === Token.Identifier) { expr = delegate.createIdentifier(lex().value); } else if ( - type === Token.StringLiteral || type === Token.NumericLiteral + type === Token.StringLiteral || + type === Token.NumericLiteral ) { if (strict && lookahead.octal) { throwErrorTolerant(lookahead, Messages.StrictOctalLiteral); @@ -2558,7 +2574,8 @@ parseStatement: true, parseSourceElement: true */ var token, expr, startToken; if ( - lookahead.type !== Token.Punctuator && lookahead.type !== Token.Keyword + lookahead.type !== Token.Punctuator && + lookahead.type !== Token.Keyword ) { expr = parsePostfixExpression(); } else if (match('++') || match('--')) { @@ -2587,7 +2604,9 @@ parseStatement: true, parseSourceElement: true */ expr = delegate.createUnaryExpression(token.value, expr); expr = delegate.markEnd(expr, startToken); } else if ( - matchKeyword('delete') || matchKeyword('void') || matchKeyword('typeof') + matchKeyword('delete') || + matchKeyword('void') || + matchKeyword('typeof') ) { startToken = lookahead; token = lex(); @@ -3963,11 +3982,13 @@ parseStatement: true, parseSourceElement: true */ if (typeof options !== 'undefined') { extra.range = typeof options.range === 'boolean' && options.range; extra.loc = typeof options.loc === 'boolean' && options.loc; - extra.attachComment = typeof options.attachComment === 'boolean' && - options.attachComment; + extra.attachComment = + typeof options.attachComment === 'boolean' && options.attachComment; if ( - extra.loc && options.source !== null && options.source !== undefined + extra.loc && + options.source !== null && + options.source !== undefined ) { extra.source = toString(options.source); } @@ -4049,7 +4070,8 @@ parseStatement: true, parseSourceElement: true */ (function(require, module) { var parse = require('esprima').parse; - var objectKeys = Object.keys || + var objectKeys = + Object.keys || function(obj) { var keys = []; for (var key in obj) @@ -4063,7 +4085,8 @@ parseStatement: true, parseSourceElement: true */ } }; - var isArray = Array.isArray || + var isArray = + Array.isArray || function(xs) { return Object.prototype.toString.call(xs) === '[object Array]'; }; @@ -4230,7 +4253,8 @@ var parseAndModify = inBrowser ? window.falafel : require('falafel'); if (source) { for (var prop in source) { if ( - dest[prop] instanceof Object && typeof dest[prop] !== 'function' + dest[prop] instanceof Object && + typeof dest[prop] !== 'function' ) { _blanket._extend(dest[prop], source[prop]); } else { @@ -4285,11 +4309,11 @@ var parseAndModify = inBrowser ? window.falafel : require('falafel'); { loc: true, comment: true }, _blanket._addTracking(inFileName) ); - instrumented = _blanket._trackingSetup(inFileName, sourceArray) + - instrumented; + instrumented = + _blanket._trackingSetup(inFileName, sourceArray) + instrumented; if (_blanket.options('sourceURL')) { - instrumented += '\n//@ sourceURL=' + - inFileName.replace('http://', ''); + instrumented += + '\n//@ sourceURL=' + inFileName.replace('http://', ''); } if (_blanket.options('debug')) { console.log('BLANKET-Instrumented file: ', inFileName); @@ -4324,43 +4348,35 @@ var parseAndModify = inBrowser ? window.falafel : require('falafel'); var intro = ''; var covVar = _blanket.getCovVar(); - intro += 'if (typeof ' + - covVar + - " === 'undefined') " + - covVar + - ' = {};\n'; + intro += + 'if (typeof ' + covVar + " === 'undefined') " + covVar + ' = {};\n'; if (branches) { intro += 'var _$branchFcn=function(f,l,c,r){ '; intro += 'if (!!r) { '; - intro += covVar + + intro += + covVar + '[f].branchData[l][c][0] = ' + covVar + '[f].branchData[l][c][0] || [];'; intro += covVar + '[f].branchData[l][c][0].push(r); }'; intro += 'else { '; - intro += covVar + + intro += + covVar + '[f].branchData[l][c][1] = ' + covVar + '[f].branchData[l][c][1] || [];'; intro += covVar + '[f].branchData[l][c][1].push(r); }'; intro += 'return r;};\n'; } - intro += 'if (typeof ' + - covVar + - "['" + - filename + - "'] === 'undefined'){"; + intro += + 'if (typeof ' + covVar + "['" + filename + "'] === 'undefined'){"; intro += covVar + "['" + filename + "']=[];\n"; if (branches) { intro += covVar + "['" + filename + "'].branchData=[];\n"; } - intro += covVar + - "['" + - filename + - "'].source=['" + - sourceString + - "'];\n"; + intro += + covVar + "['" + filename + "'].source=['" + sourceString + "'];\n"; //initialize array values _blanket._trackingArraySetup .sort(function(a, b) { @@ -4379,21 +4395,24 @@ var parseAndModify = inBrowser ? window.falafel : require('falafel'); }) .forEach(function(item) { if (item.file === filename) { - intro += 'if (typeof ' + + intro += + 'if (typeof ' + covVar + "['" + filename + "'].branchData[" + item.line + "] === 'undefined'){\n"; - intro += covVar + + intro += + covVar + "['" + filename + "'].branchData[" + item.line + ']=[];\n'; intro += '}'; - intro += covVar + + intro += + covVar + "['" + filename + "'].branchData[" + @@ -4401,7 +4420,8 @@ var parseAndModify = inBrowser ? window.falafel : require('falafel'); '][' + item.column + '] = [];\n'; - intro += covVar + + intro += + covVar + "['" + filename + "'].branchData[" + @@ -4411,7 +4431,8 @@ var parseAndModify = inBrowser ? window.falafel : require('falafel'); '].consequent = ' + JSON.stringify(item.consequent) + ';\n'; - intro += covVar + + intro += + covVar + "['" + filename + "'].branchData[" + @@ -4436,7 +4457,8 @@ var parseAndModify = inBrowser ? window.falafel : require('falafel'); bracketsExistAlt.update('{\n' + bracketsExistAlt.source() + '}\n'); } if ( - bracketsExistObject && bracketsExistObject.type !== 'BlockStatement' + bracketsExistObject && + bracketsExistObject.type !== 'BlockStatement' ) { bracketsExistObject.update( '{\n' + bracketsExistObject.source() + '}\n' @@ -4457,7 +4479,8 @@ var parseAndModify = inBrowser ? window.falafel : require('falafel'); alternate: node.alternate.loc }); - var updated = '_$branchFcn' + + var updated = + '_$branchFcn' + "('" + filename + "'," + @@ -4692,16 +4715,23 @@ var parseAndModify = inBrowser ? window.falafel : require('falafel'); loader += ' '; loader += "
"; loader += "
"; - loader += 'Error: Blanket.js encountered a cross origin request error while instrumenting the source files. '; - loader += '

This is likely caused by the source files being referenced locally (using the file:// protocol). '; - loader += "

Some solutions include starting Chrome with special flags, running a server locally, or using a browser without these CORS restrictions (Safari)."; + loader += + 'Error: Blanket.js encountered a cross origin request error while instrumenting the source files. '; + loader += + '

This is likely caused by the source files being referenced locally (using the file:// protocol). '; + loader += + "

Some solutions include starting Chrome with special flags, running a server locally, or using a browser without these CORS restrictions (Safari)."; loader += '
'; if (typeof FileReader !== 'undefined') { - loader += '
Or, try the experimental loader. When prompted, simply click on the directory containing all the source files you want covered.'; - loader += 'Start Loader'; - loader += ""; + loader += + '
Or, try the experimental loader. When prompted, simply click on the directory containing all the source files you want covered.'; + loader += + 'Start Loader'; + loader += + ""; } - loader += "
Close"; + loader += + "
Close"; loader += "
"; loader += '
'; @@ -4716,7 +4746,8 @@ var parseAndModify = inBrowser ? window.falafel : require('falafel'); css += 'height:100%;'; css += 'background-color:black;'; css += 'opacity:.5; '; - css += "-ms-filter:'progid:DXImageTransform.Microsoft.Alpha(Opacity=50)'; "; + css += + "-ms-filter:'progid:DXImageTransform.Microsoft.Alpha(Opacity=50)'; "; css += 'filter:alpha(opacity=50); '; css += 'z-index:40001; }'; @@ -4793,9 +4824,8 @@ var parseAndModify = inBrowser ? window.falafel : require('falafel'); var script = document.createElement('script'); script.type = 'text/javascript'; script.text = data; - (document.body || document.getElementsByTagName('head')[0]).appendChild( - script - ); + (document.body || document.getElementsByTagName('head')[0]) + .appendChild(script); }, hasAdapter: function(callback) { return _blanket.options('adapter') !== null; @@ -4886,19 +4916,16 @@ var parseAndModify = inBrowser ? window.falafel : require('falafel'); }); var currScript = -1; - _blanket.utils.loadAll( - function(test) { - if (test) { - return typeof scripts[currScript + 1] !== 'undefined'; - } - currScript++; - if (currScript >= scripts.length) { - return null; - } - return scripts[currScript]; - }, - callback - ); + _blanket.utils.loadAll(function(test) { + if (test) { + return typeof scripts[currScript + 1] !== 'undefined'; + } + currScript++; + if (currScript >= scripts.length) { + return null; + } + return scripts[currScript]; + }, callback); } }, beforeStartTestRunner: function(opts) { @@ -4960,7 +4987,8 @@ var parseAndModify = inBrowser ? window.falafel : require('falafel'); })(blanket); blanket.defaultReporter = function(coverage) { - var cssSytle = "#blanket-main {margin:2px;background:#EEE;color:#333;clear:both;font-family:'Helvetica Neue Light', 'HelveticaNeue-Light', 'Helvetica Neue', Calibri, Helvetica, Arial, sans-serif; font-size:17px;} #blanket-main a {color:#333;text-decoration:none;} #blanket-main a:hover {text-decoration:underline;} .blanket {margin:0;padding:5px;clear:both;border-bottom: 1px solid #FFFFFF;} .bl-error {color:red;}.bl-success {color:#5E7D00;} .bl-file{width:auto;} .bl-cl{float:left;} .blanket div.rs {margin-left:50px; width:150px; float:right} .bl-nb {padding-right:10px;} #blanket-main a.bl-logo {color: #EB1764;cursor: pointer;font-weight: bold;text-decoration: none} .bl-source{ overflow-x:scroll; background-color: #FFFFFF; border: 1px solid #CBCBCB; color: #363636; margin: 25px 20px; width: 80%;} .bl-source div{white-space: pre;font-family: monospace;} .bl-source > div > span:first-child{background-color: #EAEAEA;color: #949494;display: inline-block;padding: 0 10px;text-align: center;width: 30px;} .bl-source .miss{background-color:#e6c3c7} .bl-source span.branchWarning{color:#000;background-color:yellow;} .bl-source span.branchOkay{color:#000;background-color:transparent;}", + var cssSytle = + "#blanket-main {margin:2px;background:#EEE;color:#333;clear:both;font-family:'Helvetica Neue Light', 'HelveticaNeue-Light', 'Helvetica Neue', Calibri, Helvetica, Arial, sans-serif; font-size:17px;} #blanket-main a {color:#333;text-decoration:none;} #blanket-main a:hover {text-decoration:underline;} .blanket {margin:0;padding:5px;clear:both;border-bottom: 1px solid #FFFFFF;} .bl-error {color:red;}.bl-success {color:#5E7D00;} .bl-file{width:auto;} .bl-cl{float:left;} .blanket div.rs {margin-left:50px; width:150px; float:right} .bl-nb {padding-right:10px;} #blanket-main a.bl-logo {color: #EB1764;cursor: pointer;font-weight: bold;text-decoration: none} .bl-source{ overflow-x:scroll; background-color: #FFFFFF; border: 1px solid #CBCBCB; color: #363636; margin: 25px 20px; width: 80%;} .bl-source div{white-space: pre;font-family: monospace;} .bl-source > div > span:first-child{background-color: #EAEAEA;color: #949494;display: inline-block;padding: 0 10px;text-align: center;width: 30px;} .bl-source .miss{background-color:#e6c3c7} .bl-source span.branchWarning{color:#000;background-color:yellow;} .bl-source span.branchOkay{color:#000;background-color:transparent;}", successRate = 60, head = document.head, fileNumber = 0, @@ -4969,17 +4997,20 @@ blanket.defaultReporter = function(coverage) { hasBranchTracking = Object.keys(coverage.files).some(function(elem) { return typeof coverage.files[elem].branchData !== 'undefined'; }), - bodyContent = "
results
Coverage (%)
Covered/Total Smts.
" + + bodyContent = + "
results
Coverage (%)
Covered/Total Smts.
" + (hasBranchTracking ? "
Covered/Total Branches
" : '') + "
", - fileTemplate = "
{{fileNumber}}.{{file}}
{{percentage}} %
{{numberCovered}}/{{totalSmts}}
" + + fileTemplate = + "
{{fileNumber}}.{{file}}
{{percentage}} %
{{numberCovered}}/{{totalSmts}}
" + (hasBranchTracking ? "
{{passedBranches}}/{{totalBranches}}
" : '') + "
"; - grandTotalTemplate = "
{{rowTitle}}
{{percentage}} %
{{numberCovered}}/{{totalSmts}}
" + + grandTotalTemplate = + "
{{rowTitle}}
{{percentage}} %
{{numberCovered}}/{{totalSmts}}
" + (hasBranchTracking ? "
{{passedBranches}}/{{totalBranches}}
" : '') + @@ -5041,7 +5072,8 @@ blanket.defaultReporter = function(coverage) { var newsrc = ''; var postfix = ''; if (branchStack.length > 0) { - newsrc += ""; if (branchStack[0][0].end.line === lineNum) { - newsrc += escapeInvalidXmlChars( - src.slice(0, branchStack[0][0].end.column) - ) + ''; + newsrc += + escapeInvalidXmlChars(src.slice(0, branchStack[0][0].end.column)) + + ''; src = src.slice(branchStack[0][0].end.column); branchStack.shift(); if (branchStack.length > 0) { - newsrc += ""; if (branchStack[0][0].end.line === lineNum) { - newsrc += escapeInvalidXmlChars( - src.slice(0, branchStack[0][0].end.column) - ) + ''; + newsrc += + escapeInvalidXmlChars( + src.slice(0, branchStack[0][0].end.column) + ) + ''; src = src.slice(branchStack[0][0].end.column); branchStack.shift(); if (!cols) { @@ -5099,12 +5133,12 @@ blanket.defaultReporter = function(coverage) { branchStack.unshift([cons, thisline]); src = escapeInvalidXmlChars(src); } else { - var style = ""; - newsrc += escapeInvalidXmlChars( - src.slice(0, cons.start.column - offset) - ) + style; + newsrc += + escapeInvalidXmlChars(src.slice(0, cons.start.column - offset)) + style; if ( cols.length > colsIndex + 1 && @@ -5138,7 +5172,8 @@ blanket.defaultReporter = function(coverage) { newsrc += escapeInvalidXmlChars( src.slice(cons.end.column - offset, alt.start.column - offset) ); - style = ""; newsrc += style; @@ -5210,7 +5245,8 @@ blanket.defaultReporter = function(coverage) { var src = statsForFile.source[i]; if ( - branchStack.length > 0 || typeof statsForFile.branchData !== 'undefined' + branchStack.length > 0 || + typeof statsForFile.branchData !== 'undefined' ) { if (typeof statsForFile.branchData[i + 1] !== 'undefined') { var cols = statsForFile.branchData[i + 1].filter(isUndefined); @@ -5236,7 +5272,8 @@ blanket.defaultReporter = function(coverage) { lineClass = 'miss'; } } - code[i + 1] = "
" + (i + 1) + @@ -5343,14 +5380,12 @@ blanket.defaultReporter = function(coverage) { for (var thisModuleName in totals.moduleTotalStatements) { if (totals.moduleTotalStatements.hasOwnProperty(thisModuleName)) { var moduleTotalSt = totals.moduleTotalStatements[thisModuleName]; - var moduleTotalCovSt = totals.moduleTotalCoveredStatements[ - thisModuleName - ]; + var moduleTotalCovSt = + totals.moduleTotalCoveredStatements[thisModuleName]; var moduleTotalBr = totals.moduleTotalBranches[thisModuleName]; - var moduleTotalCovBr = totals.moduleTotalCoveredBranches[ - thisModuleName - ]; + var moduleTotalCovBr = + totals.moduleTotalCoveredBranches[thisModuleName]; createAggregateTotal( moduleTotalSt, @@ -5497,9 +5532,10 @@ blanket.defaultReporter = function(coverage) { } else if (pattern.indexOf('#') === 0) { return window[pattern.slice(1)].call(window, filename); } else { - return filename.indexOf( - _blanket.utils.normalizeBackslashes(pattern) - ) > -1; + return ( + filename.indexOf(_blanket.utils.normalizeBackslashes(pattern)) > + -1 + ); } } else if (pattern instanceof Array) { return pattern.some(function(elem) { @@ -5523,15 +5559,19 @@ blanket.defaultReporter = function(coverage) { //global filter in place, data-cover-only var antimatch = _blanket.options('antifilter'); selectedScripts = toArray.call(document.scripts).filter(function(s) { - return toArray.call(s.attributes).filter(function(sn) { - return sn.nodeName === 'src' && - _blanket.utils.matchPatternAttribute(sn.nodeValue, filter) && - (typeof antimatch === 'undefined' || - !_blanket.utils.matchPatternAttribute( - sn.nodeValue, - antimatch - )); - }).length === 1; + return ( + toArray.call(s.attributes).filter(function(sn) { + return ( + sn.nodeName === 'src' && + _blanket.utils.matchPatternAttribute(sn.nodeValue, filter) && + (typeof antimatch === 'undefined' || + !_blanket.utils.matchPatternAttribute( + sn.nodeValue, + antimatch + )) + ); + }).length === 1 + ); }); } else { selectedScripts = toArray.call( @@ -5610,14 +5650,11 @@ blanket.defaultReporter = function(coverage) { }, attachScript: function(options, cb) { var timeout = _blanket.options('timeout') || 3000; - setTimeout( - function() { - if (!_blanket.utils.cache[options.url].loaded) { - throw new Error('error loading source script'); - } - }, - timeout - ); + setTimeout(function() { + if (!_blanket.utils.cache[options.url].loaded) { + throw new Error('error loading source script'); + } + }, timeout); _blanket.utils.getFile(options.url, cb, function() { throw new Error('error loading source script'); }); @@ -5838,7 +5875,8 @@ blanket.defaultReporter = function(coverage) { ? blanket._commonjs.requirejs : window.requirejs; if ( - !_blanket.options('engineOnly') && _blanket.options('existingRequireJS') + !_blanket.options('engineOnly') && + _blanket.options('existingRequireJS') ) { _blanket.utils.oldloader = requirejs.load; diff --git a/test/lib/imagediff.js b/test/lib/imagediff.js index de9cc117..f04dba1f 100644 --- a/test/lib/imagediff.js +++ b/test/lib/imagediff.js @@ -67,14 +67,18 @@ typeof object.data !== UNDEFINED); } function isImageType(object) { - return isImage(object) || + return ( + isImage(object) || isCanvas(object) || isContext(object) || - isImageData(object); + isImageData(object) + ); } function isType(object, type) { - return typeof object === 'object' && - !!Object.prototype.toString.apply(object).match(type); + return ( + typeof object === 'object' && + !!Object.prototype.toString.apply(object).match(type) + ); } // Type Conversion diff --git a/test/lib/stats.js b/test/lib/stats.js index c3591c57..c260dcb1 100644 --- a/test/lib/stats.js +++ b/test/lib/stats.js @@ -27,12 +27,14 @@ var Stats = function() { f.appendChild(a); var i = document.createElement('div'); i.id = 'fpsText'; - i.style.cssText = 'color:#0ff;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px'; + i.style.cssText = + 'color:#0ff;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px'; i.innerHTML = 'FPS'; a.appendChild(i); var c = document.createElement('div'); c.id = 'fpsGraph'; - c.style.cssText = 'position:relative;width:74px;height:30px;background-color:#0ff'; + c.style.cssText = + 'position:relative;width:74px;height:30px;background-color:#0ff'; for (a.appendChild(c); 74 > c.children.length; ) { var j = document.createElement('span'); j.style.cssText = 'width:1px;height:30px;float:left;background-color:#113'; @@ -40,20 +42,22 @@ var Stats = function() { } var d = document.createElement('div'); d.id = 'ms'; - d.style.cssText = 'padding:0 0 3px 3px;text-align:left;background-color:#020;display:none'; + d.style.cssText = + 'padding:0 0 3px 3px;text-align:left;background-color:#020;display:none'; f.appendChild(d); var k = document.createElement('div'); k.id = 'msText'; - k.style.cssText = 'color:#0f0;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px'; + k.style.cssText = + 'color:#0f0;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px'; k.innerHTML = 'MS'; d.appendChild(k); var e = document.createElement('div'); e.id = 'msGraph'; - e.style.cssText = 'position:relative;width:74px;height:30px;background-color:#0f0'; + e.style.cssText = + 'position:relative;width:74px;height:30px;background-color:#0f0'; for (d.appendChild(e); 74 > e.children.length; ) - j = document.createElement( - 'span' - ), j.style.cssText = 'width:1px;height:30px;float:left;background-color:#131', e.appendChild( + (j = document.createElement('span')), (j.style.cssText = + 'width:1px;height:30px;float:left;background-color:#131'), e.appendChild( j ); var t = function(b) { @@ -64,7 +68,7 @@ var Stats = function() { d.style.display = 'none'; break; case 1: - a.style.display = 'none', d.style.display = 'block'; + (a.style.display = 'none'), (d.style.display = 'block'); } }; return { @@ -84,13 +88,15 @@ var Stats = function() { e.appendChild(e.firstChild).style.height = a + 'px'; r++; b > m + 1e3 && - (h = Math.round(1e3 * r / (b - m)), p = Math.min(p, h), q = Math.max( - q, + ((h = Math.round(1e3 * r / (b - m))), (p = Math.min( + p, h - ), i.textContent = h + ' FPS (' + p + '-' + q + ')', a = Math.min( + )), (q = Math.max(q, h)), (i.textContent = + h + ' FPS (' + p + '-' + q + ')'), (a = Math.min( 30, 30 - 30 * (h / 100) - ), c.appendChild(c.firstChild).style.height = a + 'px', m = b, r = 0); + )), (c.appendChild(c.firstChild).style.height = + a + 'px'), (m = b), (r = 0)); return b; }, update: function() { diff --git a/test/manual/manual-test.js b/test/manual/manual-test.js index 778d8da5..dd9ad511 100644 --- a/test/manual/manual-test.js +++ b/test/manual/manual-test.js @@ -32,15 +32,12 @@ suite('Manual', function() { // in ms var centerX = stage.width() / 2; - var anim = new Konva.Animation( - function(frame) { - hexagon.setX( - amplitude * Math.sin(new Date().getTime() * 2 * Math.PI / period) + - centerX - ); - }, - layer - ); + var anim = new Konva.Animation(function(frame) { + hexagon.setX( + amplitude * Math.sin(new Date().getTime() * 2 * Math.PI / period) + + centerX + ); + }, layer); anim.start(); }); @@ -69,12 +66,9 @@ suite('Manual', function() { var velocity = 360; // 1 rev per second - var anim = new Konva.Animation( - function(frame) { - layer.find('Rect').rotate(velocity * frame.timeDiff / 1000); - }, - layer - ); + var anim = new Konva.Animation(function(frame) { + layer.find('Rect').rotate(velocity * frame.timeDiff / 1000); + }, layer); anim.start(); }); @@ -321,47 +315,46 @@ suite('Manual', function() { }); // ====================================================== - test( - 'create image hit region with pixelRatio, look at hit, test hit with mouseover', - function(done) { - var imageObj = new Image(); + test('create image hit region with pixelRatio, look at hit, test hit with mouseover', function( + done + ) { + var imageObj = new Image(); - Konva.pixelRatio = 2; - var stage = addStage(); - var layer = new Konva.Layer(); + Konva.pixelRatio = 2; + var stage = addStage(); + var layer = new Konva.Layer(); - imageObj.onload = function() { - var lion = new Konva.Image({ - x: 200, - y: 40, - image: imageObj, - draggable: true - }); + imageObj.onload = function() { + var lion = new Konva.Image({ + x: 200, + y: 40, + image: imageObj, + draggable: true + }); - layer.add(lion); + layer.add(lion); - stage.add(layer); + stage.add(layer); - lion.cache(); - lion.drawHitFromCache(); - layer.draw(); + lion.cache(); + lion.drawHitFromCache(); + layer.draw(); - lion.on('mouseenter', function() { - document.body.style.cursor = 'pointer'; - }); + lion.on('mouseenter', function() { + document.body.style.cursor = 'pointer'; + }); - lion.on('mouseleave', function() { - document.body.style.cursor = 'default'; - }); + lion.on('mouseleave', function() { + document.body.style.cursor = 'default'; + }); - Konva.pixelRatio = undefined; - done(); - }; - imageObj.src = 'assets/lion.png'; + Konva.pixelRatio = undefined; + done(); + }; + imageObj.src = 'assets/lion.png'; - showHit(layer); - } - ); + showHit(layer); + }); // ====================================================== test('image hit region with alpha threshold, mouseover circle', function( diff --git a/test/performance/common/random-squares.js b/test/performance/common/random-squares.js index b3219ec2..c77b7534 100644 --- a/test/performance/common/random-squares.js +++ b/test/performance/common/random-squares.js @@ -8,14 +8,16 @@ var height = 300; var VERSION = Konva.version === 'dev' ? 'new' : 'old'; window.requestAnimFrame = (function() { - return window.requestAnimationFrame || + return ( + window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(callback) { window.setTimeout(callback, 1000 / 30); - }; + } + ); })(); function fpsCounter() { diff --git a/test/performance/webgl-2d.js b/test/performance/webgl-2d.js index 8f22077e..a689a409 100644 --- a/test/performance/webgl-2d.js +++ b/test/performance/webgl-2d.js @@ -49,7 +49,7 @@ var M_HALF_PI = M_PI / 2.0; function isPOT(value) { - return value > 0 && (value - 1 & value) === 0; + return value > 0 && ((value - 1) & value) === 0; } var vec3 = { @@ -105,9 +105,11 @@ if (a === undefined || b === undefined) { return false; } - return Math.abs(a[0] - b[0]) < epsilon && + return ( + Math.abs(a[0] - b[0]) < epsilon && Math.abs(a[1] - b[1]) < epsilon && - Math.abs(a[2] - b[2]) < epsilon; + Math.abs(a[2] - b[2]) < epsilon + ); } }; @@ -280,7 +282,7 @@ */ }; - var WebGL2D = this.WebGL2D = function WebGL2D(canvas, options) { + var WebGL2D = (this.WebGL2D = function WebGL2D(canvas, options) { this.canvas = canvas; this.options = options || {}; this.gl = undefined; @@ -307,7 +309,7 @@ return gl2d.gl; } - var gl = gl2d.gl = gl2d.canvas.$getContext('experimental-webgl'); + var gl = (gl2d.gl = gl2d.canvas.$getContext('experimental-webgl')); gl2d.initShaders(); gl2d.initBuffers(); @@ -342,7 +344,7 @@ })(this); this.postInit(); - }; + }); // Enables WebGL2D on your canvas WebGL2D.enable = function(canvas, options) { @@ -398,7 +400,7 @@ stackDepth, sMask ) { - var w = 2 / this.canvas.width, h = (-2) / this.canvas.height; + var w = 2 / this.canvas.width, h = -2 / this.canvas.height; stackDepth = stackDepth || 1; @@ -462,7 +464,7 @@ this.shaderProgram = storedShader; return storedShader; } else { - var fs = this.fs = gl.createShader(gl.FRAGMENT_SHADER); + var fs = (this.fs = gl.createShader(gl.FRAGMENT_SHADER)); gl.shaderSource(this.fs, this.getFragmentShaderSource(sMask)); gl.compileShader(this.fs); @@ -470,7 +472,7 @@ throw 'fragment shader error: ' + gl.getShaderInfoLog(this.fs); } - var vs = this.vs = gl.createShader(gl.VERTEX_SHADER); + var vs = (this.vs = gl.createShader(gl.VERTEX_SHADER)); gl.shaderSource( this.vs, this.getVertexShaderSource(transformStackDepth, sMask) @@ -481,7 +483,7 @@ throw 'vertex shader error: ' + gl.getShaderInfoLog(this.vs); } - var shaderProgram = this.shaderProgram = gl.createProgram(); + var shaderProgram = (this.shaderProgram = gl.createProgram()); shaderProgram.stackDepth = transformStackDepth; gl.attachShader(shaderProgram, fs); gl.attachShader(shaderProgram, vs); @@ -625,8 +627,8 @@ alphaChannel, sameType; - if (match = reRGBAColor.exec(value)) { - hasAlpha = match[1], alphaChannel = parseFloat(match[8]); + if ((match = reRGBAColor.exec(value))) { + (hasAlpha = match[1]), (alphaChannel = parseFloat(match[8])); if ( (hasAlpha && isNaN(alphaChannel)) || @@ -638,7 +640,7 @@ sameType = match[3]; for (var i = 2; i < 8; i += 2) { - channel = match[i], isPercent = match[i + 1]; + (channel = match[i]), (isPercent = match[i + 1]); if (isPercent !== sameType) { return false; @@ -657,15 +659,15 @@ } result.push(hasAlpha ? alphaChannel : 1.0); - } else if (match = reHSLAColor.exec(value)) { - hasAlpha = match[1], alphaChannel = parseFloat(match[5]); + } else if ((match = reHSLAColor.exec(value))) { + (hasAlpha = match[1]), (alphaChannel = parseFloat(match[5])); result = HSLAToRGBA( match[2], match[3], match[4], parseFloat(hasAlpha && alphaChannel ? alphaChannel : 1.0) ); - } else if (match = reHex6Color.exec(value)) { + } else if ((match = reHex6Color.exec(value))) { var colorInt = parseInt(match[1], 16); result = [ ((colorInt & 0xff0000) >> 16) / 255, @@ -673,8 +675,9 @@ (colorInt & 0x0000ff) / 255, 1.0 ]; - } else if (match = reHex3Color.exec(value)) { - var hexString = '#' + + } else if ((match = reHex3Color.exec(value))) { + var hexString = + '#' + [match[1], match[1], match[2], match[2], match[3], match[3]].join(''); result = colorStringToVec4(hexString); } else if (value.toLowerCase() in colorKeywords) { @@ -690,7 +693,8 @@ } function colorVecToString(vec4) { - return 'rgba(' + + return ( + 'rgba(' + vec4[0] * 255 + ', ' + vec4[1] * 255 + @@ -698,7 +702,8 @@ vec4[2] * 255 + ', ' + parseFloat(vec4[3]) + - ')'; + ')' + ); } var colorKeywords = { @@ -917,8 +922,8 @@ return colorVecToString(drawState.strokeStyle); }, set: function(value) { - drawState.strokeStyle = colorStringToVec4(value) || - drawStyle.strokeStyle; + drawState.strokeStyle = + colorStringToVec4(value) || drawStyle.strokeStyle; } }); @@ -1398,7 +1403,8 @@ // we may wish to consider tiling large images like this instead of scaling and // adjust appropriately (flip to next texture source and tile offset) when drawing if ( - image.width > gl2d.maxTextureSize || image.height > gl2d.maxTextureSize + image.width > gl2d.maxTextureSize || + image.height > gl2d.maxTextureSize ) { var canvas = document.createElement('canvas'); diff --git a/test/setStats.js b/test/setStats.js index b6228797..167c199c 100644 --- a/test/setStats.js +++ b/test/setStats.js @@ -1,12 +1,14 @@ window.requestAnimFrame = (function(callback) { - return window.requestAnimationFrame || + return ( + window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(callback) { window.setTimeout(callback, 1000 / 30); - }; + } + ); })(); stats = new Stats(); diff --git a/test/unit/Animation-test.js b/test/unit/Animation-test.js index 00e3e1c9..1bca5551 100644 --- a/test/unit/Animation-test.js +++ b/test/unit/Animation-test.js @@ -21,14 +21,11 @@ suite('Animation', function() { // in ms var centerX = stage.getWidth() / 2 - 100 / 2; - var anim = new Konva.Animation( - function(frame) { - rect.setX( - amplitude * Math.sin(frame.time * 2 * Math.PI / period) + centerX - ); - }, - layer - ); + var anim = new Konva.Animation(function(frame) { + rect.setX( + amplitude * Math.sin(frame.time * 2 * Math.PI / period) + centerX + ); + }, layer); var a = Konva.Animation.animations; var startLen = a.length; diff --git a/test/unit/DragAndDrop-test.js b/test/unit/DragAndDrop-test.js index 51290479..d4849c5f 100644 --- a/test/unit/DragAndDrop-test.js +++ b/test/unit/DragAndDrop-test.js @@ -16,29 +16,26 @@ suite('DragAndDrop', function() { stage.add(layer); layer.add(circle); - setTimeout( - function() { - layer.draw(); + setTimeout(function() { + layer.draw(); - // test defaults - assert.equal(circle.draggable(), false); + // test defaults + assert.equal(circle.draggable(), false); - //change properties - circle.setDraggable(true); + //change properties + circle.setDraggable(true); - //circle.on('click', function(){}); + //circle.on('click', function(){}); - layer.draw(); + layer.draw(); - showHit(layer); + showHit(layer); - // test new properties - assert.equal(circle.getDraggable(), true); + // test new properties + assert.equal(circle.getDraggable(), true); - done(); - }, - 50 - ); + done(); + }, 50); }); // ====================================================== @@ -344,25 +341,22 @@ suite('DragAndDrop', function() { y: stage.height() / 2 }); - setTimeout( - function() { - assert.equal(stage.isDragging(), true); + setTimeout(function() { + assert.equal(stage.isDragging(), true); - stage.simulateMouseUp({ - x: stage.width() / 2 - 50, - y: stage.height() / 2 - }); + stage.simulateMouseUp({ + x: stage.width() / 2 - 50, + y: stage.height() / 2 + }); - var shape = layer.getIntersection({ - x: stage.width() / 2 + 5, - y: stage.height() / 2 - }); + var shape = layer.getIntersection({ + x: stage.width() / 2 + 5, + y: stage.height() / 2 + }); - assert.equal(shape, circle); - done(); - }, - 50 - ); + assert.equal(shape, circle); + done(); + }, 50); }); test('removing shape while drag and drop should no throw error', function() { @@ -402,42 +396,39 @@ suite('DragAndDrop', function() { }); }); - test( - 'destroying shape while drag and drop should no throw error', - function() { - var stage = addStage(); - var layer = new Konva.Layer(); + test('destroying shape while drag and drop should no throw error', function() { + var stage = addStage(); + var layer = new Konva.Layer(); - var circle = new Konva.Circle({ - x: stage.getWidth() / 2, - y: stage.getHeight() / 2, - radius: 70, - fill: 'green', - stroke: 'black', - strokeWidth: 4, - name: 'myCircle', - draggable: true - }); + var circle = new Konva.Circle({ + x: stage.getWidth() / 2, + y: stage.getHeight() / 2, + radius: 70, + fill: 'green', + stroke: 'black', + strokeWidth: 4, + name: 'myCircle', + draggable: true + }); - layer.add(circle); - stage.add(layer); + layer.add(circle); + stage.add(layer); - stage.simulateMouseDown({ - x: 291, - y: 112 - }); + stage.simulateMouseDown({ + x: 291, + y: 112 + }); - circle.destroy(); + circle.destroy(); - stage.simulateMouseMove({ - x: 311, - y: 112 - }); + stage.simulateMouseMove({ + x: 311, + y: 112 + }); - stage.simulateMouseUp({ - x: 291, - y: 112 - }); - } - ); + stage.simulateMouseUp({ + x: 291, + y: 112 + }); + }); }); diff --git a/test/unit/Layer-test.js b/test/unit/Layer-test.js index e8b9112b..ed1f83d3 100644 --- a/test/unit/Layer-test.js +++ b/test/unit/Layer-test.js @@ -245,44 +245,41 @@ suite('Layer', function() { }); // ====================================================== - test( - 'set clearBeforeDraw to false, and test toDataURL for stage, layer, group, and shape', - function() { - var stage = addStage(); + test('set clearBeforeDraw to false, and test toDataURL for stage, layer, group, and shape', function() { + var stage = addStage(); - var layer = new Konva.Layer({ - clearBeforeDraw: false, - throttle: 999 - }); + var layer = new Konva.Layer({ + clearBeforeDraw: false, + throttle: 999 + }); - var group = new Konva.Group(); + var group = new Konva.Group(); - var circle = new Konva.Circle({ - x: 100, - y: stage.getHeight() / 2, - radius: 70, - fill: 'green', - stroke: 'black', - strokeWidth: 4 - }); + var circle = new Konva.Circle({ + x: 100, + y: stage.getHeight() / 2, + radius: 70, + fill: 'green', + stroke: 'black', + strokeWidth: 4 + }); - group.add(circle); - layer.add(group); - stage.add(layer); + group.add(circle); + layer.add(group); + stage.add(layer); - for (var n = 0; n < 20; n++) { - circle.move({ x: 10, y: 0 }); - layer.draw(); - } - - var trace = layer.getContext().getTrace(); - //console.log(trace); - assert.equal( - trace, - 'save();transform(1,0,0,1,220,100);beginPath();arc(0,0,70,0,6.283,false);closePath();fillStyle=green;fill();lineWidth=4;strokeStyle=black;stroke();restore();save();transform(1,0,0,1,230,100);beginPath();arc(0,0,70,0,6.283,false);closePath();fillStyle=green;fill();lineWidth=4;strokeStyle=black;stroke();restore();save();transform(1,0,0,1,240,100);beginPath();arc(0,0,70,0,6.283,false);closePath();fillStyle=green;fill();lineWidth=4;strokeStyle=black;stroke();restore();save();transform(1,0,0,1,250,100);beginPath();arc(0,0,70,0,6.283,false);closePath();fillStyle=green;fill();lineWidth=4;strokeStyle=black;stroke();restore();save();transform(1,0,0,1,260,100);beginPath();arc(0,0,70,0,6.283,false);closePath();fillStyle=green;fill();lineWidth=4;strokeStyle=black;stroke();restore();save();transform(1,0,0,1,270,100);beginPath();arc(0,0,70,0,6.283,false);closePath();fillStyle=green;fill();lineWidth=4;strokeStyle=black;stroke();restore();save();transform(1,0,0,1,280,100);beginPath();arc(0,0,70,0,6.283,false);closePath();fillStyle=green;fill();lineWidth=4;strokeStyle=black;stroke();restore();save();transform(1,0,0,1,290,100);beginPath();arc(0,0,70,0,6.283,false);closePath();fillStyle=green;fill();lineWidth=4;strokeStyle=black;stroke();restore();save();transform(1,0,0,1,300,100);beginPath();arc(0,0,70,0,6.283,false);closePath();fillStyle=green;fill();lineWidth=4;strokeStyle=black;stroke();restore();' - ); + for (var n = 0; n < 20; n++) { + circle.move({ x: 10, y: 0 }); + layer.draw(); } - ); + + var trace = layer.getContext().getTrace(); + //console.log(trace); + assert.equal( + trace, + 'save();transform(1,0,0,1,220,100);beginPath();arc(0,0,70,0,6.283,false);closePath();fillStyle=green;fill();lineWidth=4;strokeStyle=black;stroke();restore();save();transform(1,0,0,1,230,100);beginPath();arc(0,0,70,0,6.283,false);closePath();fillStyle=green;fill();lineWidth=4;strokeStyle=black;stroke();restore();save();transform(1,0,0,1,240,100);beginPath();arc(0,0,70,0,6.283,false);closePath();fillStyle=green;fill();lineWidth=4;strokeStyle=black;stroke();restore();save();transform(1,0,0,1,250,100);beginPath();arc(0,0,70,0,6.283,false);closePath();fillStyle=green;fill();lineWidth=4;strokeStyle=black;stroke();restore();save();transform(1,0,0,1,260,100);beginPath();arc(0,0,70,0,6.283,false);closePath();fillStyle=green;fill();lineWidth=4;strokeStyle=black;stroke();restore();save();transform(1,0,0,1,270,100);beginPath();arc(0,0,70,0,6.283,false);closePath();fillStyle=green;fill();lineWidth=4;strokeStyle=black;stroke();restore();save();transform(1,0,0,1,280,100);beginPath();arc(0,0,70,0,6.283,false);closePath();fillStyle=green;fill();lineWidth=4;strokeStyle=black;stroke();restore();save();transform(1,0,0,1,290,100);beginPath();arc(0,0,70,0,6.283,false);closePath();fillStyle=green;fill();lineWidth=4;strokeStyle=black;stroke();restore();save();transform(1,0,0,1,300,100);beginPath();arc(0,0,70,0,6.283,false);closePath();fillStyle=green;fill();lineWidth=4;strokeStyle=black;stroke();restore();' + ); + }); // ====================================================== test('save layer as png', function() { diff --git a/test/unit/Node-cache-test.js b/test/unit/Node-cache-test.js index 706818a3..f03d5eb2 100644 --- a/test/unit/Node-cache-test.js +++ b/test/unit/Node-cache-test.js @@ -286,8 +286,8 @@ suite('Caching', function() { context.fillStyle = 'green'; context.shadowColor = 'black'; context.shadowBlur = 10 * canvas.ratio; - context.shadowOffsetX = (-10) * canvas.ratio; - context.shadowOffsetY = (-10) * canvas.ratio; + context.shadowOffsetX = -10 * canvas.ratio; + context.shadowOffsetY = -10 * canvas.ratio; context.fill(); compareLayerAndCanvas(layer, canvas, 50); }); @@ -325,8 +325,8 @@ suite('Caching', function() { context.fillStyle = 'green'; context.shadowColor = 'black'; context.shadowBlur = 10 * canvas.ratio; - context.shadowOffsetX = (-10) * canvas.ratio; - context.shadowOffsetY = (-10) * canvas.ratio; + context.shadowOffsetX = -10 * canvas.ratio; + context.shadowOffsetY = -10 * canvas.ratio; context.fill(); compareLayerAndCanvas(layer, canvas, 50); }); @@ -617,33 +617,30 @@ suite('Caching', function() { compareLayerAndCanvas(layer, canvas, 150); }); - test( - 'cache shape that is larger than stage but need buffer canvas', - function() { - var stage = addStage(); - var layer = new Konva.Layer(); - var group = new Konva.Group(); - var circle = new Konva.Circle({ - x: stage.width() / 2, - y: stage.height() / 2, - radius: 400, - fill: 'red', - stroke: 'black', - strokeWidth: 50, - opacity: 0.5, - scaleX: 1 / 5, - scaleY: 1 / 5 - }); + test('cache shape that is larger than stage but need buffer canvas', function() { + var stage = addStage(); + var layer = new Konva.Layer(); + var group = new Konva.Group(); + var circle = new Konva.Circle({ + x: stage.width() / 2, + y: stage.height() / 2, + radius: 400, + fill: 'red', + stroke: 'black', + strokeWidth: 50, + opacity: 0.5, + scaleX: 1 / 5, + scaleY: 1 / 5 + }); - group.add(circle); - layer.add(group); - stage.add(layer); - circle.cache(); - layer.draw(); + group.add(circle); + layer.add(group); + stage.add(layer); + circle.cache(); + layer.draw(); - cloneAndCompareLayer(layer, 200); - } - ); + cloneAndCompareLayer(layer, 200); + }); test('cache nested groups', function() { var stage = addStage(); diff --git a/test/unit/Node-test.js b/test/unit/Node-test.js index 2fe2bff0..5dc1b0e5 100644 --- a/test/unit/Node-test.js +++ b/test/unit/Node-test.js @@ -1512,154 +1512,145 @@ suite('Node', function() { }); // ====================================================== - test( - 'test getPosition and getAbsolutePosition for shape inside transformed stage', - function() { - var stage = addStage(); - var layer = new Konva.Layer(); - var rect = new Konva.Rect({ - x: 200, - y: 20, - width: 100, - height: 50, - fill: 'red', - stroke: 'black', - strokeWidth: 4, - draggable: true - }); + test('test getPosition and getAbsolutePosition for shape inside transformed stage', function() { + var stage = addStage(); + var layer = new Konva.Layer(); + var rect = new Konva.Rect({ + x: 200, + y: 20, + width: 100, + height: 50, + fill: 'red', + stroke: 'black', + strokeWidth: 4, + draggable: true + }); - layer.add(rect); - stage.add(layer); + layer.add(rect); + stage.add(layer); - stage.rotate(180 / 3); - stage.setScale({ x: 0.5, y: 0.5 }); + stage.rotate(180 / 3); + stage.setScale({ x: 0.5, y: 0.5 }); - stage.draw(); + stage.draw(); - assert.equal(rect.getPosition().x, 200); - assert.equal(rect.getPosition().y, 20); + assert.equal(rect.getPosition().x, 200); + assert.equal(rect.getPosition().y, 20); - assert.equal(Math.round(rect.getAbsolutePosition().x), 41); - assert.equal(Math.round(rect.getAbsolutePosition().y), 92); - } - ); + assert.equal(Math.round(rect.getAbsolutePosition().x), 41); + assert.equal(Math.round(rect.getAbsolutePosition().y), 92); + }); // ====================================================== - test( - 'test consecutive getAbsolutePositions()s when shape has offset', - function() { - var stage = addStage(); - var layer = new Konva.Layer(); - var rect = new Konva.Rect({ - x: 200, - y: 20, - width: 100, - height: 50, - fill: 'red', - stroke: 'black', - strokeWidth: 4, - draggable: true, - offsetX: 30, - offsetY: 30 - //rotationDeg: 60 - //rotationDeg: Math.PI / 3 - }); + test('test consecutive getAbsolutePositions()s when shape has offset', function() { + var stage = addStage(); + var layer = new Konva.Layer(); + var rect = new Konva.Rect({ + x: 200, + y: 20, + width: 100, + height: 50, + fill: 'red', + stroke: 'black', + strokeWidth: 4, + draggable: true, + offsetX: 30, + offsetY: 30 + //rotationDeg: 60 + //rotationDeg: Math.PI / 3 + }); - layer.add(rect); - stage.add(layer); + layer.add(rect); + stage.add(layer); - assert( - rect.getAbsolutePosition().x === 200 && - rect.getAbsolutePosition().y === 20, - 'absolute position should be 200, 20' - ); - assert( - rect.getAbsolutePosition().x === 200 && - rect.getAbsolutePosition().y === 20, - 'absolute position should be 200, 20' - ); - assert( - rect.getAbsolutePosition().x === 200 && - rect.getAbsolutePosition().y === 20, - 'absolute position should be 200, 20' - ); - assert( - rect.getAbsolutePosition().x === 200 && - rect.getAbsolutePosition().y === 20, - 'absolute position should be 200, 20' - ); - assert( - rect.getAbsolutePosition().x === 200 && - rect.getAbsolutePosition().y === 20, - 'absolute position should be 200, 20' - ); - } - ); + assert( + rect.getAbsolutePosition().x === 200 && + rect.getAbsolutePosition().y === 20, + 'absolute position should be 200, 20' + ); + assert( + rect.getAbsolutePosition().x === 200 && + rect.getAbsolutePosition().y === 20, + 'absolute position should be 200, 20' + ); + assert( + rect.getAbsolutePosition().x === 200 && + rect.getAbsolutePosition().y === 20, + 'absolute position should be 200, 20' + ); + assert( + rect.getAbsolutePosition().x === 200 && + rect.getAbsolutePosition().y === 20, + 'absolute position should be 200, 20' + ); + assert( + rect.getAbsolutePosition().x === 200 && + rect.getAbsolutePosition().y === 20, + 'absolute position should be 200, 20' + ); + }); // ====================================================== - test( - 'test getPosition and getAbsolutePosition for transformed parent with offset offset', - function() { - var side = 100; - var diagonal = Math.sqrt(side * side * 2); + test('test getPosition and getAbsolutePosition for transformed parent with offset offset', function() { + var side = 100; + var diagonal = Math.sqrt(side * side * 2); - var stage = addStage(); - var layer = new Konva.Layer({ - name: 'layerName', - id: 'layerId' - }); - var group = new Konva.Group({ - name: 'groupName', - id: 'groupId', - rotation: 45, - offset: { x: side / 2, y: side / 2 }, - x: diagonal / 2, - y: diagonal / 2 - }); - var rect = new Konva.Rect({ - x: 0, - y: 0, - width: side, - height: side, - fill: 'red', - name: 'rectName', - id: 'rectId' - }); - var marker = new Konva.Rect({ - x: side, - y: 0, - width: 1, - height: 1, - fill: 'blue', - stroke: 'blue', - strokeWidth: 4, - name: 'markerName', - id: 'markerId' - }); + var stage = addStage(); + var layer = new Konva.Layer({ + name: 'layerName', + id: 'layerId' + }); + var group = new Konva.Group({ + name: 'groupName', + id: 'groupId', + rotation: 45, + offset: { x: side / 2, y: side / 2 }, + x: diagonal / 2, + y: diagonal / 2 + }); + var rect = new Konva.Rect({ + x: 0, + y: 0, + width: side, + height: side, + fill: 'red', + name: 'rectName', + id: 'rectId' + }); + var marker = new Konva.Rect({ + x: side, + y: 0, + width: 1, + height: 1, + fill: 'blue', + stroke: 'blue', + strokeWidth: 4, + name: 'markerName', + id: 'markerId' + }); - group.add(rect); - group.add(marker); - layer.add(group); - stage.add(layer); + group.add(rect); + group.add(marker); + layer.add(group); + stage.add(layer); - assert.equal( - Math.round(marker.getAbsolutePosition().x), - Math.round(diagonal), - 'marker absolute position x should be about ' + - Math.round(diagonal) + - ' but is about ' + - Math.round(marker.getAbsolutePosition().x) - ); - assert.equal( - Math.round(marker.getAbsolutePosition().y), - Math.round(diagonal / 2), - 'marker absolute position y should be about ' + - Math.round(diagonal / 2) + - ' but is about ' + - Math.round(marker.getAbsolutePosition().y) - ); - } - ); + assert.equal( + Math.round(marker.getAbsolutePosition().x), + Math.round(diagonal), + 'marker absolute position x should be about ' + + Math.round(diagonal) + + ' but is about ' + + Math.round(marker.getAbsolutePosition().x) + ); + assert.equal( + Math.round(marker.getAbsolutePosition().y), + Math.round(diagonal / 2), + 'marker absolute position y should be about ' + + Math.round(diagonal / 2) + + ' but is about ' + + Math.round(marker.getAbsolutePosition().y) + ); + }); // ====================================================== test('test relative getAbsolutePosition for transformed parent ', function() { @@ -2062,82 +2053,76 @@ suite('Node', function() { assert.equal(fired, true); }); // ====================================================== - test( - 'move shape, group, and layer, and then get absolute position', - function() { - var stage = addStage(); - var layer = new Konva.Layer(); - var group = new Konva.Group(); + test('move shape, group, and layer, and then get absolute position', function() { + var stage = addStage(); + var layer = new Konva.Layer(); + var group = new Konva.Group(); - var circle = new Konva.Circle({ - x: stage.getWidth() / 2, - y: stage.getHeight() / 2, - radius: 70, - fill: 'green', - stroke: 'black', - strokeWidth: 4 - }); + var circle = new Konva.Circle({ + x: stage.getWidth() / 2, + y: stage.getHeight() / 2, + radius: 70, + fill: 'green', + stroke: 'black', + strokeWidth: 4 + }); - group.add(circle); - layer.add(group); - stage.add(layer); + group.add(circle); + layer.add(group); + stage.add(layer); - circle.setPosition({ x: 100, y: 0 }); - group.setPosition({ x: 100, y: 0 }); - layer.setPosition({ x: 100, y: 0 }); + circle.setPosition({ x: 100, y: 0 }); + group.setPosition({ x: 100, y: 0 }); + layer.setPosition({ x: 100, y: 0 }); - // test relative positions - assert.equal(circle.getPosition().x, 100); - assert.equal(group.getPosition().x, 100); - assert.equal(layer.getPosition().x, 100); + // test relative positions + assert.equal(circle.getPosition().x, 100); + assert.equal(group.getPosition().x, 100); + assert.equal(layer.getPosition().x, 100); - // test absolute positions - assert.equal(circle.getAbsolutePosition().x, 300); - assert.equal(group.getAbsolutePosition().x, 200); - assert.equal(layer.getAbsolutePosition().x, 100); + // test absolute positions + assert.equal(circle.getAbsolutePosition().x, 300); + assert.equal(group.getAbsolutePosition().x, 200); + assert.equal(layer.getAbsolutePosition().x, 100); - layer.draw(); - } - ); + layer.draw(); + }); // ====================================================== - test( - 'scale layer, rotate group, position shape, and then get absolute position', - function() { - var stage = addStage(); - var layer = new Konva.Layer({ - scale: { - x: 2, - y: 2 - } - }); - var group = new Konva.Group({ - x: 100, - rotation: 90 - }); + test('scale layer, rotate group, position shape, and then get absolute position', function() { + var stage = addStage(); + var layer = new Konva.Layer({ + scale: { + x: 2, + y: 2 + } + }); + var group = new Konva.Group({ + x: 100, + rotation: 90 + }); - var rect = new Konva.Rect({ - x: 50, - y: 10, - width: 100, - height: 50, - fill: 'green', - stroke: 'black', - strokeWidth: 4, - draggable: true - }); + var rect = new Konva.Rect({ + x: 50, + y: 10, + width: 100, + height: 50, + fill: 'green', + stroke: 'black', + strokeWidth: 4, + draggable: true + }); - group.add(rect); - layer.add(group); - stage.add(layer); + group.add(rect); + layer.add(group); + stage.add(layer); - // test absolute positions - assert.equal(rect.getAbsolutePosition().x, 180); - assert.equal(rect.getAbsolutePosition().y, 100); + // test absolute positions + assert.equal(rect.getAbsolutePosition().x, 180); + assert.equal(rect.getAbsolutePosition().y, 100); - layer.draw(); - } - ); + layer.draw(); + }); // ====================================================== test('hide show circle', function() { @@ -2359,7 +2344,8 @@ suite('Node', function() { group.add(circle); layer.draw(); - var expectedJson = '{"attrs":{"width":578,"height":200},"className":"Stage","children":[{"attrs":{},"className":"Layer","children":[{"attrs":{},"className":"Group","children":[{"attrs":{"x":289,"y":100,"radius":70,"fill":"green","stroke":"black","strokeWidth":4,"name":"myCircle","draggable":true},"className":"Circle"}]}]}]}'; + var expectedJson = + '{"attrs":{"width":578,"height":200},"className":"Stage","children":[{"attrs":{},"className":"Layer","children":[{"attrs":{},"className":"Group","children":[{"attrs":{"x":289,"y":100,"radius":70,"fill":"green","stroke":"black","strokeWidth":4,"name":"myCircle","draggable":true},"className":"Circle"}]}]}]}'; assert.equal(stage.toJSON(), expectedJson); }); @@ -2385,7 +2371,8 @@ suite('Node', function() { group.add(circle); layer.draw(); - var expectedJson = '{"attrs":{"x":289,"y":100,"radius":70,"fill":"green","stroke":"black","strokeWidth":4,"name":"myCircle","draggable":true},"className":"Circle"}'; + var expectedJson = + '{"attrs":{"x":289,"y":100,"radius":70,"fill":"green","stroke":"black","strokeWidth":4,"name":"myCircle","draggable":true},"className":"Circle"}'; assert.equal(circle.toJSON(), expectedJson); }); @@ -2421,7 +2408,8 @@ suite('Node', function() { } }); - var expectedJson = '{"attrs":{"x":289,"y":100,"radius":70,"fill":"green","stroke":"black","strokeWidth":4,"name":"myCircle","draggable":true,"customAttr":3,"customAttrObj":{"x":1,"y":5,"size":{"width":10,"height":20}}},"className":"Circle"}'; + var expectedJson = + '{"attrs":{"x":289,"y":100,"radius":70,"fill":"green","stroke":"black","strokeWidth":4,"name":"myCircle","draggable":true,"customAttr":3,"customAttrObj":{"x":1,"y":5,"size":{"width":10,"height":20}}},"className":"Circle"}'; assert.equal(circle.toJSON(), expectedJson); }); @@ -2429,7 +2417,8 @@ suite('Node', function() { // ====================================================== test('load stage using json', function() { var container = addContainer(); - var json = '{"attrs":{"width":578,"height":200},"className":"Stage","children":[{"attrs":{},"className":"Layer","children":[{"attrs":{},"className":"Group","children":[{"attrs":{"x":289,"y":100,"radius":70,"fill":"green","stroke":"black","strokeWidth":4,"name":"myCircle","draggable":true},"className":"Shape"}]}]}]}'; + var json = + '{"attrs":{"width":578,"height":200},"className":"Stage","children":[{"attrs":{},"className":"Layer","children":[{"attrs":{},"className":"Group","children":[{"attrs":{"x":289,"y":100,"radius":70,"fill":"green","stroke":"black","strokeWidth":4,"name":"myCircle","draggable":true},"className":"Shape"}]}]}]}'; var stage = Konva.Node.create(json, container); assert.equal(stage.toJSON(), json); @@ -2474,7 +2463,8 @@ suite('Node', function() { assert.equal(triangle.getId(), 'myTriangle'); - var expectedJson = '{"attrs":{"width":578,"height":200},"className":"Stage","children":[{"attrs":{},"className":"Layer","children":[{"attrs":{},"className":"Group","children":[{"attrs":{"fill":"#00D2FF","stroke":"black","strokeWidth":4,"id":"myTriangle"},"className":"Shape"}]}]}]}'; + var expectedJson = + '{"attrs":{"width":578,"height":200},"className":"Stage","children":[{"attrs":{},"className":"Layer","children":[{"attrs":{},"className":"Group","children":[{"attrs":{"fill":"#00D2FF","stroke":"black","strokeWidth":4,"id":"myTriangle"},"className":"Shape"}]}]}]}'; assert.equal(stage.toJSON(), expectedJson); @@ -2493,7 +2483,8 @@ suite('Node', function() { context.closePath(); context.fillStrokeShape(this); }; - var json = '{"attrs":{"width":578,"height":200},"className":"Stage","children":[{"attrs":{},"className":"Layer","children":[{"attrs":{},"className":"Group","children":[{"attrs":{"fill":"#00D2FF","stroke":"black","strokeWidth":4,"id":"myTriangle","customAttrObj":{"x":1,"y":5,"size":{"width":10,"height":20}}},"className":"Shape"}]}]}]}'; + var json = + '{"attrs":{"width":578,"height":200},"className":"Stage","children":[{"attrs":{},"className":"Layer","children":[{"attrs":{},"className":"Group","children":[{"attrs":{"fill":"#00D2FF","stroke":"black","strokeWidth":4,"id":"myTriangle","customAttrObj":{"x":1,"y":5,"size":{"width":10,"height":20}}},"className":"Shape"}]}]}]}'; var stage = Konva.Node.create(json, container); @@ -2525,7 +2516,8 @@ suite('Node', function() { layer.add(darth); stage.add(layer); - var json = '{"attrs":{"width":578,"height":200},"className":"Stage","children":[{"attrs":{},"className":"Layer","children":[{"attrs":{"x":200,"y":60,"offsetX":50,"offsetY":150,"id":"darth"},"className":"Image"}]}]}'; + var json = + '{"attrs":{"width":578,"height":200},"className":"Stage","children":[{"attrs":{},"className":"Layer","children":[{"attrs":{"x":200,"y":60,"offsetX":50,"offsetY":150,"id":"darth"},"className":"Image"}]}]}'; assert.equal(stage.toJSON(), json); @@ -2539,7 +2531,8 @@ suite('Node', function() { var imageObj = new Image(); var container = addContainer(); imageObj.onload = function() { - var json = '{"attrs":{"width":578,"height":200},"className":"Stage","children":[{"attrs":{},"className":"Layer","children":[{"attrs":{"x":200,"y":60,"offsetX":50,"offsetY":150,"id":"darth"},"className":"Image"}]}]}'; + var json = + '{"attrs":{"width":578,"height":200},"className":"Stage","children":[{"attrs":{},"className":"Layer","children":[{"attrs":{"x":200,"y":60,"offsetX":50,"offsetY":150,"id":"darth"},"className":"Image"}]}]}'; var stage = Konva.Node.create(json, container); assert.equal(stage.toJSON(), json); @@ -2610,33 +2603,30 @@ suite('Node', function() { }); // ====================================================== - test( - 'memory leak test for destroy and a shape with several names', - function() { - var stage = addStage(); - var layer = new Konva.Layer(); - var circle = new Konva.Circle({ - x: stage.getWidth() / 2, - y: stage.getHeight() / 2, - radius: 70, - fill: 'green', - stroke: 'black', - strokeWidth: 4, - name: 'my-new-shape my-new-circle' - }); + test('memory leak test for destroy and a shape with several names', function() { + var stage = addStage(); + var layer = new Konva.Layer(); + var circle = new Konva.Circle({ + x: stage.getWidth() / 2, + y: stage.getHeight() / 2, + radius: 70, + fill: 'green', + stroke: 'black', + strokeWidth: 4, + name: 'my-new-shape my-new-circle' + }); - layer.add(circle); - stage.add(layer); + layer.add(circle); + stage.add(layer); - assert.equal(Konva.names['my-new-shape'].length, 1); - assert.equal(Konva.names['my-new-circle'].length, 1); + assert.equal(Konva.names['my-new-shape'].length, 1); + assert.equal(Konva.names['my-new-circle'].length, 1); - circle.destroy(); + circle.destroy(); - assert.equal(Konva.names['my-new-shape'], undefined); - assert.equal(Konva.names['my-new-circle'], undefined); - } - ); + assert.equal(Konva.names['my-new-shape'], undefined); + assert.equal(Konva.names['my-new-circle'], undefined); + }); // ====================================================== test('destroy shape without adding its parent to stage', function() { diff --git a/test/unit/Tween-test.js b/test/unit/Tween-test.js index 27efd172..e29672e1 100644 --- a/test/unit/Tween-test.js +++ b/test/unit/Tween-test.js @@ -124,14 +124,11 @@ suite('Tween', function() { }); tween.play(); - setTimeout( - function() { - assert.equal(circle.x(), 200); - assert.equal(circle.y(), 100); - done(); - }, - 60 - ); + setTimeout(function() { + assert.equal(circle.x(), 200); + assert.equal(circle.y(), 100); + done(); + }, 60); }); test('color tweening', function(done) { @@ -207,12 +204,9 @@ suite('Tween', function() { x: 10, duration: 0.001 }); - setTimeout( - function() { - done(); - }, - 50 - ); + setTimeout(function() { + done(); + }, 50); }); suite('tween array with different length', function() { diff --git a/test/unit/shapes/Label-test.js b/test/unit/shapes/Label-test.js index 8fc493e6..aea0cda5 100644 --- a/test/unit/shapes/Label-test.js +++ b/test/unit/shapes/Label-test.js @@ -64,7 +64,8 @@ suite('Label', function() { test('create label from json', function() { var stage = addStage(); - var json = '{"attrs":{"x":100,"y":100,"draggable":true},"className":"Label","children":[{"attrs":{"fill":"#bbb","stroke":"#333","shadowColor":"black","shadowBlur":10,"shadowOffsetX":10,"shadowOffsetY":10,"shadowOpacity":0.2,"lineJoin":"round","pointerDirection":"up","pointerWidth":20,"pointerHeight":20,"cornerRadius":5,"x":-151.5,"y":20,"width":303,"height":60},"className":"Tag"},{"attrs":{"text":"Hello big world","fontSize":50,"lineHeight":1.2,"fill":"green","width":"auto","height":"auto","x":-151.5,"y":20},"className":"Text"}]}'; + var json = + '{"attrs":{"x":100,"y":100,"draggable":true},"className":"Label","children":[{"attrs":{"fill":"#bbb","stroke":"#333","shadowColor":"black","shadowBlur":10,"shadowOffsetX":10,"shadowOffsetY":10,"shadowOpacity":0.2,"lineJoin":"round","pointerDirection":"up","pointerWidth":20,"pointerHeight":20,"cornerRadius":5,"x":-151.5,"y":20,"width":303,"height":60},"className":"Tag"},{"attrs":{"text":"Hello big world","fontSize":50,"lineHeight":1.2,"fill":"green","width":"auto","height":"auto","x":-151.5,"y":20},"className":"Text"}]}'; var layer = new Konva.Layer(); var label = Konva.Node.create(json); diff --git a/test/unit/shapes/Path-test.js b/test/unit/shapes/Path-test.js index c0d63cf6..446cad53 100644 --- a/test/unit/shapes/Path-test.js +++ b/test/unit/shapes/Path-test.js @@ -82,53 +82,47 @@ suite('Path', function() { }); //======================================================= - test( - 'complex path made of many different closed and open paths (Sopwith Camel)', - function() { - var stage = addStage(); - var layer = new Konva.Layer(); + test('complex path made of many different closed and open paths (Sopwith Camel)', function() { + var stage = addStage(); + var layer = new Konva.Layer(); - var path = new Konva.Path({ - data: 'm 15.749277,58.447629 8.495831,-0.05348 m 0.319898,-15.826548 -0.202438,17.295748 0.942206,0.941911 1.345933,-1.816987 0.20211,-11.642611 z m 77.458374,28.680768 c 0,5.308829 -4.303525,9.612686 -9.612485,9.612686 -5.30873,0 -9.612194,-4.303857 -9.612194,-9.612686 0,-5.308829 4.303464,-9.61226 9.612194,-9.61226 5.30896,0 9.612485,4.303431 9.612485,9.61226 z m -3.520874,0 c 0,3.364079 -2.72763,6.091348 -6.091611,6.091348 -3.364243,0 -6.091119,-2.727269 -6.091119,-6.091348 0,-3.363719 2.726876,-6.090791 6.091119,-6.090791 3.363981,0 6.091611,2.727072 6.091611,6.090791 z m -3.997576,0 c 0,1.156718 -0.937743,2.093937 -2.094035,2.093937 -1.156062,0 -2.093871,-0.937219 -2.093871,-2.093937 0,-1.156357 0.937809,-2.093773 2.093871,-2.093773 1.156292,0 2.094035,0.937416 2.094035,2.093773 z m 45.77821,4.283023 c -0.24607,1.90039 5.06492,3.680204 7.61403,5.520093 0.50662,0.514199 0.27889,0.975967 -0.0984,1.427532 l 3.9019,-1.141987 c -0.59258,-0.121397 -1.85951,0.01969 -1.71294,-0.380038 -0.85894,-1.950525 -3.68693,-2.761261 -5.61518,-4.092495 -1.06971,-1.03496 0.0997,-1.60766 0.76126,-2.284203 z M 43.206396,42.60133 55.578964,74.008743 58.71987,73.910313 47.203939,44.40726 c -1.109013,-0.737406 -1.174108,-2.1004 -3.997543,-1.808752 z m -18.654022,-0.570632 12.467721,31.692335 3.140643,0.09843 -12.467656,-31.692927 z m 2.285318,42.353106 -2.636648,-0.06431 0.163066,0.734584 3.709372,9.956142 2.357927,-1.168202 z m 19.411934,0.566268 -6.370726,9.901284 2.090163,1.615665 7.13671,-11.417403 0.303821,-0.4347 -2.942667,-0.02953 z m -12.091915,8.286013 c -5.729323,0 -10.367941,4.560169 -10.367941,10.184405 0,5.62429 4.638618,10.18489 10.367941,10.18489 5.729424,0 10.37654,-4.5606 10.37654,-10.18489 0,-5.624236 -4.647083,-10.184405 -10.37654,-10.184405 z m 0,2.473319 c 4.310029,0 7.811352,3.453552 7.811352,7.711086 0,4.25776 -3.50129,7.71167 -7.811352,7.71167 -4.310157,0 -7.803016,-3.45391 -7.803016,-7.71167 0,-4.257534 3.492859,-7.711086 7.803016,-7.711086 z m 3.528526,-21.795876 c -1.29032,-0.0066 -2.97525,0.03839 -3.402437,1.45155 l -0.01969,7.494437 c 0.586775,0.761915 1.42432,0.688978 2.236565,0.71411 l 26.529545,-0.14502 8.636784,0.761324 0,-7.518487 C 71.56989,75.908478 71.09444,75.467051 70.239377,75.338961 61.126027,73.734287 49.244756,73.929146 37.690371,73.911166 z M 20.959576,41.269176 c -0.0098,0.603377 0.575258,0.881409 0.575258,0.881409 L 58.95771,42.33629 c -4.893946,-0.985482 -16.592629,-2.859625 -32.835015,-2.783473 -1.570354,0.107617 -5.151439,1.109571 -5.163119,1.712718 z m 3.353022,14.276273 c -2.79955,0.01312 -5.595489,0.02953 -8.382964,0.05545 l 0,9.9e-5 0.0033,1.447677 -1.173484,0.01312 0.0066,1.244485 1.184048,0.05807 c -1.34298,0.220812 -2.956414,1.305807 -3.054779,3.476618 0.0098,3.269061 0.01312,6.538943 0.01312,9.808103 l -1.21197,0.0033 -0.01969,-2.361569 -4.6851755,0.0033 0,5.901969 4.6323185,0.0066 -0.02953,-1.7556 1.308596,-0.02297 0.0098,9.180447 c -0.0066,1.315781 2.739048,3.634336 4.542583,3.634336 l 4.811756,-2.995032 c 1.616583,-0.107617 1.758126,0.482078 1.884346,1.076924 l 35.667571,0.318914 6.909664,-0.81031 m 4.994738,-0.585889 85.216614,-9.991675 c 4.93952,-0.487623 14.9162,-22.255511 -3.75098,-25.556727 -5.12814,-0.887479 -15.53194,4.839613 -21.44018,9.104984 -2.31314,1.954593 -1.74166,4.084194 0.0263,5.982879 l -72.209399,-8.111923 -2.12281,-0.0012 c -0.966453,1.390128 -3.158262,3.260465 -4.554559,4.053123 M 49.36027,58.361483 c -1.699757,-1.038536 -2.965602,-2.804438 -4.533856,-2.875275 -3.903936,0.0011 -7.904399,0.0066 -11.882849,0.01312 m -3.081192,0.0066 c -1.043195,0.0033 -2.082715,0.0066 -3.116396,0.0098', - stroke: '#000', - strokeWidth: 1, - lineCap: 'round', - lineJoin: 'round' - }); + var path = new Konva.Path({ + data: 'm 15.749277,58.447629 8.495831,-0.05348 m 0.319898,-15.826548 -0.202438,17.295748 0.942206,0.941911 1.345933,-1.816987 0.20211,-11.642611 z m 77.458374,28.680768 c 0,5.308829 -4.303525,9.612686 -9.612485,9.612686 -5.30873,0 -9.612194,-4.303857 -9.612194,-9.612686 0,-5.308829 4.303464,-9.61226 9.612194,-9.61226 5.30896,0 9.612485,4.303431 9.612485,9.61226 z m -3.520874,0 c 0,3.364079 -2.72763,6.091348 -6.091611,6.091348 -3.364243,0 -6.091119,-2.727269 -6.091119,-6.091348 0,-3.363719 2.726876,-6.090791 6.091119,-6.090791 3.363981,0 6.091611,2.727072 6.091611,6.090791 z m -3.997576,0 c 0,1.156718 -0.937743,2.093937 -2.094035,2.093937 -1.156062,0 -2.093871,-0.937219 -2.093871,-2.093937 0,-1.156357 0.937809,-2.093773 2.093871,-2.093773 1.156292,0 2.094035,0.937416 2.094035,2.093773 z m 45.77821,4.283023 c -0.24607,1.90039 5.06492,3.680204 7.61403,5.520093 0.50662,0.514199 0.27889,0.975967 -0.0984,1.427532 l 3.9019,-1.141987 c -0.59258,-0.121397 -1.85951,0.01969 -1.71294,-0.380038 -0.85894,-1.950525 -3.68693,-2.761261 -5.61518,-4.092495 -1.06971,-1.03496 0.0997,-1.60766 0.76126,-2.284203 z M 43.206396,42.60133 55.578964,74.008743 58.71987,73.910313 47.203939,44.40726 c -1.109013,-0.737406 -1.174108,-2.1004 -3.997543,-1.808752 z m -18.654022,-0.570632 12.467721,31.692335 3.140643,0.09843 -12.467656,-31.692927 z m 2.285318,42.353106 -2.636648,-0.06431 0.163066,0.734584 3.709372,9.956142 2.357927,-1.168202 z m 19.411934,0.566268 -6.370726,9.901284 2.090163,1.615665 7.13671,-11.417403 0.303821,-0.4347 -2.942667,-0.02953 z m -12.091915,8.286013 c -5.729323,0 -10.367941,4.560169 -10.367941,10.184405 0,5.62429 4.638618,10.18489 10.367941,10.18489 5.729424,0 10.37654,-4.5606 10.37654,-10.18489 0,-5.624236 -4.647083,-10.184405 -10.37654,-10.184405 z m 0,2.473319 c 4.310029,0 7.811352,3.453552 7.811352,7.711086 0,4.25776 -3.50129,7.71167 -7.811352,7.71167 -4.310157,0 -7.803016,-3.45391 -7.803016,-7.71167 0,-4.257534 3.492859,-7.711086 7.803016,-7.711086 z m 3.528526,-21.795876 c -1.29032,-0.0066 -2.97525,0.03839 -3.402437,1.45155 l -0.01969,7.494437 c 0.586775,0.761915 1.42432,0.688978 2.236565,0.71411 l 26.529545,-0.14502 8.636784,0.761324 0,-7.518487 C 71.56989,75.908478 71.09444,75.467051 70.239377,75.338961 61.126027,73.734287 49.244756,73.929146 37.690371,73.911166 z M 20.959576,41.269176 c -0.0098,0.603377 0.575258,0.881409 0.575258,0.881409 L 58.95771,42.33629 c -4.893946,-0.985482 -16.592629,-2.859625 -32.835015,-2.783473 -1.570354,0.107617 -5.151439,1.109571 -5.163119,1.712718 z m 3.353022,14.276273 c -2.79955,0.01312 -5.595489,0.02953 -8.382964,0.05545 l 0,9.9e-5 0.0033,1.447677 -1.173484,0.01312 0.0066,1.244485 1.184048,0.05807 c -1.34298,0.220812 -2.956414,1.305807 -3.054779,3.476618 0.0098,3.269061 0.01312,6.538943 0.01312,9.808103 l -1.21197,0.0033 -0.01969,-2.361569 -4.6851755,0.0033 0,5.901969 4.6323185,0.0066 -0.02953,-1.7556 1.308596,-0.02297 0.0098,9.180447 c -0.0066,1.315781 2.739048,3.634336 4.542583,3.634336 l 4.811756,-2.995032 c 1.616583,-0.107617 1.758126,0.482078 1.884346,1.076924 l 35.667571,0.318914 6.909664,-0.81031 m 4.994738,-0.585889 85.216614,-9.991675 c 4.93952,-0.487623 14.9162,-22.255511 -3.75098,-25.556727 -5.12814,-0.887479 -15.53194,4.839613 -21.44018,9.104984 -2.31314,1.954593 -1.74166,4.084194 0.0263,5.982879 l -72.209399,-8.111923 -2.12281,-0.0012 c -0.966453,1.390128 -3.158262,3.260465 -4.554559,4.053123 M 49.36027,58.361483 c -1.699757,-1.038536 -2.965602,-2.804438 -4.533856,-2.875275 -3.903936,0.0011 -7.904399,0.0066 -11.882849,0.01312 m -3.081192,0.0066 c -1.043195,0.0033 -2.082715,0.0066 -3.116396,0.0098', + stroke: '#000', + strokeWidth: 1, + lineCap: 'round', + lineJoin: 'round' + }); - layer.add(path); + layer.add(path); - stage.add(layer); - } - ); + stage.add(layer); + }); //======================================================= - test( - 'complex path made of many different closed and open paths (Sopwith Camel) cached', - function() { - var stage = addStage(); - var layer = new Konva.Layer(); + test('complex path made of many different closed and open paths (Sopwith Camel) cached', function() { + var stage = addStage(); + var layer = new Konva.Layer(); - var path = new Konva.Path({ - data: 'm 15.749277,58.447629 8.495831,-0.05348 m 0.319898,-15.826548 -0.202438,17.295748 0.942206,0.941911 1.345933,-1.816987 0.20211,-11.642611 z m 77.458374,28.680768 c 0,5.308829 -4.303525,9.612686 -9.612485,9.612686 -5.30873,0 -9.612194,-4.303857 -9.612194,-9.612686 0,-5.308829 4.303464,-9.61226 9.612194,-9.61226 5.30896,0 9.612485,4.303431 9.612485,9.61226 z m -3.520874,0 c 0,3.364079 -2.72763,6.091348 -6.091611,6.091348 -3.364243,0 -6.091119,-2.727269 -6.091119,-6.091348 0,-3.363719 2.726876,-6.090791 6.091119,-6.090791 3.363981,0 6.091611,2.727072 6.091611,6.090791 z m -3.997576,0 c 0,1.156718 -0.937743,2.093937 -2.094035,2.093937 -1.156062,0 -2.093871,-0.937219 -2.093871,-2.093937 0,-1.156357 0.937809,-2.093773 2.093871,-2.093773 1.156292,0 2.094035,0.937416 2.094035,2.093773 z m 45.77821,4.283023 c -0.24607,1.90039 5.06492,3.680204 7.61403,5.520093 0.50662,0.514199 0.27889,0.975967 -0.0984,1.427532 l 3.9019,-1.141987 c -0.59258,-0.121397 -1.85951,0.01969 -1.71294,-0.380038 -0.85894,-1.950525 -3.68693,-2.761261 -5.61518,-4.092495 -1.06971,-1.03496 0.0997,-1.60766 0.76126,-2.284203 z M 43.206396,42.60133 55.578964,74.008743 58.71987,73.910313 47.203939,44.40726 c -1.109013,-0.737406 -1.174108,-2.1004 -3.997543,-1.808752 z m -18.654022,-0.570632 12.467721,31.692335 3.140643,0.09843 -12.467656,-31.692927 z m 2.285318,42.353106 -2.636648,-0.06431 0.163066,0.734584 3.709372,9.956142 2.357927,-1.168202 z m 19.411934,0.566268 -6.370726,9.901284 2.090163,1.615665 7.13671,-11.417403 0.303821,-0.4347 -2.942667,-0.02953 z m -12.091915,8.286013 c -5.729323,0 -10.367941,4.560169 -10.367941,10.184405 0,5.62429 4.638618,10.18489 10.367941,10.18489 5.729424,0 10.37654,-4.5606 10.37654,-10.18489 0,-5.624236 -4.647083,-10.184405 -10.37654,-10.184405 z m 0,2.473319 c 4.310029,0 7.811352,3.453552 7.811352,7.711086 0,4.25776 -3.50129,7.71167 -7.811352,7.71167 -4.310157,0 -7.803016,-3.45391 -7.803016,-7.71167 0,-4.257534 3.492859,-7.711086 7.803016,-7.711086 z m 3.528526,-21.795876 c -1.29032,-0.0066 -2.97525,0.03839 -3.402437,1.45155 l -0.01969,7.494437 c 0.586775,0.761915 1.42432,0.688978 2.236565,0.71411 l 26.529545,-0.14502 8.636784,0.761324 0,-7.518487 C 71.56989,75.908478 71.09444,75.467051 70.239377,75.338961 61.126027,73.734287 49.244756,73.929146 37.690371,73.911166 z M 20.959576,41.269176 c -0.0098,0.603377 0.575258,0.881409 0.575258,0.881409 L 58.95771,42.33629 c -4.893946,-0.985482 -16.592629,-2.859625 -32.835015,-2.783473 -1.570354,0.107617 -5.151439,1.109571 -5.163119,1.712718 z m 3.353022,14.276273 c -2.79955,0.01312 -5.595489,0.02953 -8.382964,0.05545 l 0,9.9e-5 0.0033,1.447677 -1.173484,0.01312 0.0066,1.244485 1.184048,0.05807 c -1.34298,0.220812 -2.956414,1.305807 -3.054779,3.476618 0.0098,3.269061 0.01312,6.538943 0.01312,9.808103 l -1.21197,0.0033 -0.01969,-2.361569 -4.6851755,0.0033 0,5.901969 4.6323185,0.0066 -0.02953,-1.7556 1.308596,-0.02297 0.0098,9.180447 c -0.0066,1.315781 2.739048,3.634336 4.542583,3.634336 l 4.811756,-2.995032 c 1.616583,-0.107617 1.758126,0.482078 1.884346,1.076924 l 35.667571,0.318914 6.909664,-0.81031 m 4.994738,-0.585889 85.216614,-9.991675 c 4.93952,-0.487623 14.9162,-22.255511 -3.75098,-25.556727 -5.12814,-0.887479 -15.53194,4.839613 -21.44018,9.104984 -2.31314,1.954593 -1.74166,4.084194 0.0263,5.982879 l -72.209399,-8.111923 -2.12281,-0.0012 c -0.966453,1.390128 -3.158262,3.260465 -4.554559,4.053123 M 49.36027,58.361483 c -1.699757,-1.038536 -2.965602,-2.804438 -4.533856,-2.875275 -3.903936,0.0011 -7.904399,0.0066 -11.882849,0.01312 m -3.081192,0.0066 c -1.043195,0.0033 -2.082715,0.0066 -3.116396,0.0098', - stroke: '#000', - strokeWidth: 1, - lineCap: 'round', - lineJoin: 'round', - draggable: true - }); + var path = new Konva.Path({ + data: 'm 15.749277,58.447629 8.495831,-0.05348 m 0.319898,-15.826548 -0.202438,17.295748 0.942206,0.941911 1.345933,-1.816987 0.20211,-11.642611 z m 77.458374,28.680768 c 0,5.308829 -4.303525,9.612686 -9.612485,9.612686 -5.30873,0 -9.612194,-4.303857 -9.612194,-9.612686 0,-5.308829 4.303464,-9.61226 9.612194,-9.61226 5.30896,0 9.612485,4.303431 9.612485,9.61226 z m -3.520874,0 c 0,3.364079 -2.72763,6.091348 -6.091611,6.091348 -3.364243,0 -6.091119,-2.727269 -6.091119,-6.091348 0,-3.363719 2.726876,-6.090791 6.091119,-6.090791 3.363981,0 6.091611,2.727072 6.091611,6.090791 z m -3.997576,0 c 0,1.156718 -0.937743,2.093937 -2.094035,2.093937 -1.156062,0 -2.093871,-0.937219 -2.093871,-2.093937 0,-1.156357 0.937809,-2.093773 2.093871,-2.093773 1.156292,0 2.094035,0.937416 2.094035,2.093773 z m 45.77821,4.283023 c -0.24607,1.90039 5.06492,3.680204 7.61403,5.520093 0.50662,0.514199 0.27889,0.975967 -0.0984,1.427532 l 3.9019,-1.141987 c -0.59258,-0.121397 -1.85951,0.01969 -1.71294,-0.380038 -0.85894,-1.950525 -3.68693,-2.761261 -5.61518,-4.092495 -1.06971,-1.03496 0.0997,-1.60766 0.76126,-2.284203 z M 43.206396,42.60133 55.578964,74.008743 58.71987,73.910313 47.203939,44.40726 c -1.109013,-0.737406 -1.174108,-2.1004 -3.997543,-1.808752 z m -18.654022,-0.570632 12.467721,31.692335 3.140643,0.09843 -12.467656,-31.692927 z m 2.285318,42.353106 -2.636648,-0.06431 0.163066,0.734584 3.709372,9.956142 2.357927,-1.168202 z m 19.411934,0.566268 -6.370726,9.901284 2.090163,1.615665 7.13671,-11.417403 0.303821,-0.4347 -2.942667,-0.02953 z m -12.091915,8.286013 c -5.729323,0 -10.367941,4.560169 -10.367941,10.184405 0,5.62429 4.638618,10.18489 10.367941,10.18489 5.729424,0 10.37654,-4.5606 10.37654,-10.18489 0,-5.624236 -4.647083,-10.184405 -10.37654,-10.184405 z m 0,2.473319 c 4.310029,0 7.811352,3.453552 7.811352,7.711086 0,4.25776 -3.50129,7.71167 -7.811352,7.71167 -4.310157,0 -7.803016,-3.45391 -7.803016,-7.71167 0,-4.257534 3.492859,-7.711086 7.803016,-7.711086 z m 3.528526,-21.795876 c -1.29032,-0.0066 -2.97525,0.03839 -3.402437,1.45155 l -0.01969,7.494437 c 0.586775,0.761915 1.42432,0.688978 2.236565,0.71411 l 26.529545,-0.14502 8.636784,0.761324 0,-7.518487 C 71.56989,75.908478 71.09444,75.467051 70.239377,75.338961 61.126027,73.734287 49.244756,73.929146 37.690371,73.911166 z M 20.959576,41.269176 c -0.0098,0.603377 0.575258,0.881409 0.575258,0.881409 L 58.95771,42.33629 c -4.893946,-0.985482 -16.592629,-2.859625 -32.835015,-2.783473 -1.570354,0.107617 -5.151439,1.109571 -5.163119,1.712718 z m 3.353022,14.276273 c -2.79955,0.01312 -5.595489,0.02953 -8.382964,0.05545 l 0,9.9e-5 0.0033,1.447677 -1.173484,0.01312 0.0066,1.244485 1.184048,0.05807 c -1.34298,0.220812 -2.956414,1.305807 -3.054779,3.476618 0.0098,3.269061 0.01312,6.538943 0.01312,9.808103 l -1.21197,0.0033 -0.01969,-2.361569 -4.6851755,0.0033 0,5.901969 4.6323185,0.0066 -0.02953,-1.7556 1.308596,-0.02297 0.0098,9.180447 c -0.0066,1.315781 2.739048,3.634336 4.542583,3.634336 l 4.811756,-2.995032 c 1.616583,-0.107617 1.758126,0.482078 1.884346,1.076924 l 35.667571,0.318914 6.909664,-0.81031 m 4.994738,-0.585889 85.216614,-9.991675 c 4.93952,-0.487623 14.9162,-22.255511 -3.75098,-25.556727 -5.12814,-0.887479 -15.53194,4.839613 -21.44018,9.104984 -2.31314,1.954593 -1.74166,4.084194 0.0263,5.982879 l -72.209399,-8.111923 -2.12281,-0.0012 c -0.966453,1.390128 -3.158262,3.260465 -4.554559,4.053123 M 49.36027,58.361483 c -1.699757,-1.038536 -2.965602,-2.804438 -4.533856,-2.875275 -3.903936,0.0011 -7.904399,0.0066 -11.882849,0.01312 m -3.081192,0.0066 c -1.043195,0.0033 -2.082715,0.0066 -3.116396,0.0098', + stroke: '#000', + strokeWidth: 1, + lineCap: 'round', + lineJoin: 'round', + draggable: true + }); - layer.add(path); + layer.add(path); - stage.add(layer); + stage.add(layer); - path.cache(); - layer.draw(); - // layer.draw(); - cloneAndCompareLayer(layer, 230); - showHit(layer); - } - ); + path.cache(); + layer.draw(); + // layer.draw(); + cloneAndCompareLayer(layer, 230); + showHit(layer); + }); // ====================================================== test('moveTo with implied lineTos and trailing comma', function() { @@ -227,7 +221,8 @@ suite('Path', function() { var stage = addStage(); var layer = new Konva.Layer(); - var c = 'M12.582,9.551C3.251,16.237,0.921,29.021,7.08,38.564l-2.36,1.689l4.893,2.262l4.893,2.262l-0.568-5.36l-0.567-5.359l-2.365,1.694c-4.657-7.375-2.83-17.185,4.352-22.33c7.451-5.338,17.817-3.625,23.156,3.824c5.337,7.449,3.625,17.813-3.821,23.152l2.857,3.988c9.617-6.893,11.827-20.277,4.935-29.896C35.591,4.87,22.204,2.658,12.582,9.551z'; + var c = + 'M12.582,9.551C3.251,16.237,0.921,29.021,7.08,38.564l-2.36,1.689l4.893,2.262l4.893,2.262l-0.568-5.36l-0.567-5.359l-2.365,1.694c-4.657-7.375-2.83-17.185,4.352-22.33c7.451-5.338,17.817-3.625,23.156,3.824c5.337,7.449,3.625,17.813-3.821,23.152l2.857,3.988c9.617-6.893,11.827-20.277,4.935-29.896C35.591,4.87,22.204,2.658,12.582,9.551z'; var path = new Konva.Path({ data: c, @@ -408,7 +403,8 @@ suite('Path', function() { var stage = addStage(); var layer = new Konva.Layer(); - var c = 'M100,350 l 50,-25 a25,25 -30 0,1 50,-25 l 50,-25 a25,50 -30 0,1 50,-25 l 50,-25 a25,75 -30 0,1 50,-25 l 50,-25 a25,100 -30 0,1 50,-25 l 50,-25'; + var c = + 'M100,350 l 50,-25 a25,25 -30 0,1 50,-25 l 50,-25 a25,50 -30 0,1 50,-25 l 50,-25 a25,75 -30 0,1 50,-25 l 50,-25 a25,100 -30 0,1 50,-25 l 50,-25'; var path = new Konva.Path({ data: c, @@ -473,49 +469,46 @@ suite('Path', function() { }); // ====================================================== - test( - 'Able to determine point on line some distance from another point on line', - function() { - var stage = addStage(); - var layer = new Konva.Layer(); + test('Able to determine point on line some distance from another point on line', function() { + var stage = addStage(); + var layer = new Konva.Layer(); - var c = 'M10,10 210,160'; - // i.e., from a 3-4-5 triangle + var c = 'M10,10 210,160'; + // i.e., from a 3-4-5 triangle - var path = new Konva.Path({ - stroke: 'red', - strokeWidth: 3 - }); + var path = new Konva.Path({ + stroke: 'red', + strokeWidth: 3 + }); - path.setData(c); - layer.add(path); + path.setData(c); + layer.add(path); - layer.add( - new Konva.Circle({ - x: 10, - y: 10, - radius: 10, - fill: 'black' - }) - ); + layer.add( + new Konva.Circle({ + x: 10, + y: 10, + radius: 10, + fill: 'black' + }) + ); - var p1 = Konva.Path.getPointOnLine(125, 10, 10, 210, 160); - // should be 1/2 way, or (110,85) - assert.equal(Math.round(p1.x), 110); - assert.equal(Math.round(p1.y), 85); + var p1 = Konva.Path.getPointOnLine(125, 10, 10, 210, 160); + // should be 1/2 way, or (110,85) + assert.equal(Math.round(p1.x), 110); + assert.equal(Math.round(p1.y), 85); - layer.add( - new Konva.Circle({ - x: p1.x, - y: p1.y, - radius: 10, - fill: 'blue' - }) - ); + layer.add( + new Konva.Circle({ + x: p1.x, + y: p1.y, + radius: 10, + fill: 'blue' + }) + ); - stage.add(layer); - } - ); + stage.add(layer); + }); // ====================================================== test('Able to determine points on Cubic Bezier Curve', function() { @@ -628,196 +621,192 @@ suite('Path', function() { }); // ====================================================== - test( - 'Able to determine points on Elliptical Arc with clockwise stroke', - function() { - var stage = addStage(); - var layer = new Konva.Layer(); + test('Able to determine points on Elliptical Arc with clockwise stroke', function() { + var stage = addStage(); + var layer = new Konva.Layer(); - var c = 'M 50,100 A 100 50 0 1 1 150 150'; + var c = 'M 50,100 A 100 50 0 1 1 150 150'; - var path = new Konva.Path({ - stroke: 'red', - strokeWidth: 3 - }); + var path = new Konva.Path({ + stroke: 'red', + strokeWidth: 3 + }); - path.setData(c); + path.setData(c); - layer.add(path); + layer.add(path); - var centerParamPoints = Konva.Path.convertEndpointToCenterParameterization( - 50, - 100, - 150, - 150, - 1, - 1, - 100, - 50, - 0 - ); + var centerParamPoints = Konva.Path.convertEndpointToCenterParameterization( + 50, + 100, + 150, + 150, + 1, + 1, + 100, + 50, + 0 + ); - var start = centerParamPoints[4]; - // 4 = theta - var dTheta = centerParamPoints[5]; - // 5 = dTheta - var end = centerParamPoints[4] + dTheta; - var inc = Math.PI / 6.0; - // 30 degree resolution + var start = centerParamPoints[4]; + // 4 = theta + var dTheta = centerParamPoints[5]; + // 5 = dTheta + var end = centerParamPoints[4] + dTheta; + var inc = Math.PI / 6.0; + // 30 degree resolution - var p1 = Konva.Path.getPointOnEllipticalArc( - centerParamPoints[0], - centerParamPoints[1], - centerParamPoints[2], - centerParamPoints[3], - start, - 0 - ); - c = 'M ' + p1.x.toString() + ' ' + p1.y.toString(); + var p1 = Konva.Path.getPointOnEllipticalArc( + centerParamPoints[0], + centerParamPoints[1], + centerParamPoints[2], + centerParamPoints[3], + start, + 0 + ); + c = 'M ' + p1.x.toString() + ' ' + p1.y.toString(); - if ( - dTheta < 0 // clockwise - ) { - for (t = start - inc; t > end; t -= inc) { - p1 = Konva.Path.getPointOnEllipticalArc( - centerParamPoints[0], - centerParamPoints[1], - centerParamPoints[2], - centerParamPoints[3], - t, - 0 - ); - c += ' ' + p1.x.toString() + ' ' + p1.y.toString(); - } - } else { // counter-clockwise - for (t = start + inc; t < end; t += inc) { - p1 = Konva.Path.getPointOnEllipticalArc( - centerParamPoints[0], - centerParamPoints[1], - centerParamPoints[2], - centerParamPoints[3], - t, - 0 - ); - c += ' ' + p1.x.toString() + ' ' + p1.y.toString(); - } + if ( + dTheta < 0 // clockwise + ) { + for (t = start - inc; t > end; t -= inc) { + p1 = Konva.Path.getPointOnEllipticalArc( + centerParamPoints[0], + centerParamPoints[1], + centerParamPoints[2], + centerParamPoints[3], + t, + 0 + ); + c += ' ' + p1.x.toString() + ' ' + p1.y.toString(); + } + } else { + // counter-clockwise + for (t = start + inc; t < end; t += inc) { + p1 = Konva.Path.getPointOnEllipticalArc( + centerParamPoints[0], + centerParamPoints[1], + centerParamPoints[2], + centerParamPoints[3], + t, + 0 + ); + c += ' ' + p1.x.toString() + ' ' + p1.y.toString(); } - p1 = Konva.Path.getPointOnEllipticalArc( - centerParamPoints[0], - centerParamPoints[1], - centerParamPoints[2], - centerParamPoints[3], - end, - 0 - ); - c += ' ' + p1.x.toString() + ' ' + p1.y.toString(); - - var testpath = new Konva.Path({ - stroke: 'black', - strokeWidth: 2, - data: c - }); - - layer.add(testpath); - stage.add(layer); } - ); + p1 = Konva.Path.getPointOnEllipticalArc( + centerParamPoints[0], + centerParamPoints[1], + centerParamPoints[2], + centerParamPoints[3], + end, + 0 + ); + c += ' ' + p1.x.toString() + ' ' + p1.y.toString(); + + var testpath = new Konva.Path({ + stroke: 'black', + strokeWidth: 2, + data: c + }); + + layer.add(testpath); + stage.add(layer); + }); // ====================================================== - test( - 'Able to determine points on Elliptical Arc with counter-clockwise stroke', - function() { - var stage = addStage(); - var layer = new Konva.Layer(); + test('Able to determine points on Elliptical Arc with counter-clockwise stroke', function() { + var stage = addStage(); + var layer = new Konva.Layer(); - var c = 'M 250,100 A 100 50 0 1 0 150 150'; + var c = 'M 250,100 A 100 50 0 1 0 150 150'; - var path = new Konva.Path({ - stroke: 'red', - strokeWidth: 3 - }); + var path = new Konva.Path({ + stroke: 'red', + strokeWidth: 3 + }); - path.setData(c); + path.setData(c); - layer.add(path); + layer.add(path); - var centerParamPoints = Konva.Path.convertEndpointToCenterParameterization( - 250, - 100, - 150, - 150, - 1, - 0, - 100, - 50, - 0 - ); + var centerParamPoints = Konva.Path.convertEndpointToCenterParameterization( + 250, + 100, + 150, + 150, + 1, + 0, + 100, + 50, + 0 + ); - var start = centerParamPoints[4]; - // 4 = theta - var dTheta = centerParamPoints[5]; - // 5 = dTheta - var end = centerParamPoints[4] + dTheta; - var inc = Math.PI / 6.0; - // 30 degree resolution + var start = centerParamPoints[4]; + // 4 = theta + var dTheta = centerParamPoints[5]; + // 5 = dTheta + var end = centerParamPoints[4] + dTheta; + var inc = Math.PI / 6.0; + // 30 degree resolution - var p1 = Konva.Path.getPointOnEllipticalArc( - centerParamPoints[0], - centerParamPoints[1], - centerParamPoints[2], - centerParamPoints[3], - start, - 0 - ); - c = 'M ' + p1.x.toString() + ' ' + p1.y.toString(); + var p1 = Konva.Path.getPointOnEllipticalArc( + centerParamPoints[0], + centerParamPoints[1], + centerParamPoints[2], + centerParamPoints[3], + start, + 0 + ); + c = 'M ' + p1.x.toString() + ' ' + p1.y.toString(); - if ( - dTheta < 0 // clockwise - ) { - for (t = start - inc; t > end; t -= inc) { - p1 = Konva.Path.getPointOnEllipticalArc( - centerParamPoints[0], - centerParamPoints[1], - centerParamPoints[2], - centerParamPoints[3], - t, - 0 - ); - c += ' ' + p1.x.toString() + ' ' + p1.y.toString(); - } - } else { // counter-clockwise - for (t = start + inc; t < end; t += inc) { - p1 = Konva.Path.getPointOnEllipticalArc( - centerParamPoints[0], - centerParamPoints[1], - centerParamPoints[2], - centerParamPoints[3], - t, - 0 - ); - c += ' ' + p1.x.toString() + ' ' + p1.y.toString(); - } + if ( + dTheta < 0 // clockwise + ) { + for (t = start - inc; t > end; t -= inc) { + p1 = Konva.Path.getPointOnEllipticalArc( + centerParamPoints[0], + centerParamPoints[1], + centerParamPoints[2], + centerParamPoints[3], + t, + 0 + ); + c += ' ' + p1.x.toString() + ' ' + p1.y.toString(); + } + } else { + // counter-clockwise + for (t = start + inc; t < end; t += inc) { + p1 = Konva.Path.getPointOnEllipticalArc( + centerParamPoints[0], + centerParamPoints[1], + centerParamPoints[2], + centerParamPoints[3], + t, + 0 + ); + c += ' ' + p1.x.toString() + ' ' + p1.y.toString(); } - p1 = Konva.Path.getPointOnEllipticalArc( - centerParamPoints[0], - centerParamPoints[1], - centerParamPoints[2], - centerParamPoints[3], - end, - 0 - ); - c += ' ' + p1.x.toString() + ' ' + p1.y.toString(); - - var testpath = new Konva.Path({ - stroke: 'black', - strokeWidth: 2, - data: c - }); - - layer.add(testpath); - stage.add(layer); } - ); + p1 = Konva.Path.getPointOnEllipticalArc( + centerParamPoints[0], + centerParamPoints[1], + centerParamPoints[2], + centerParamPoints[3], + end, + 0 + ); + c += ' ' + p1.x.toString() + ' ' + p1.y.toString(); + + var testpath = new Konva.Path({ + stroke: 'black', + strokeWidth: 2, + data: c + }); + + layer.add(testpath); + stage.add(layer); + }); // ====================================================== test('Able to determine points on Elliptical Arc when rotated', function() { @@ -881,7 +870,8 @@ suite('Path', function() { ); c += ' ' + p1.x.toString() + ' ' + p1.y.toString(); } - } else { // counter-clockwise + } else { + // counter-clockwise for (t = start + inc; t < end; t += inc) { p1 = Konva.Path.getPointOnEllipticalArc( centerParamPoints[0], diff --git a/test/unit/shapes/Sprite-test.js b/test/unit/shapes/Sprite-test.js index d0bc6bba..2f9b6c7c 100644 --- a/test/unit/shapes/Sprite-test.js +++ b/test/unit/shapes/Sprite-test.js @@ -88,23 +88,17 @@ suite('Sprite', function() { sprite.start(); // kick once - setTimeout( - function() { - sprite.setAnimation('kicking'); - sprite.on('indexChange', function(evt) { - if (evt.newVal === 0 && this.getAnimation() === 'kicking') { - sprite.setAnimation('standing'); - } - }); - }, - 2000 - ); - setTimeout( - function() { - sprite.stop(); - }, - 3000 - ); + setTimeout(function() { + sprite.setAnimation('kicking'); + sprite.on('indexChange', function(evt) { + if (evt.newVal === 0 && this.getAnimation() === 'kicking') { + sprite.setAnimation('standing'); + } + }); + }, 2000); + setTimeout(function() { + sprite.stop(); + }, 3000); done(); }; @@ -170,14 +164,11 @@ suite('Sprite', function() { }; sprite.start(); - setTimeout( - function() { - sprite.stop(); - assert.equal(updateCount < 7, true); - done(); - }, - 1000 - ); + setTimeout(function() { + sprite.stop(); + assert.equal(updateCount < 7, true); + done(); + }, 1000); }; imageObj.src = 'assets/scorpion-sprite.png'; }); @@ -273,16 +264,13 @@ suite('Sprite', function() { sprite.start(); sprite2.start(); - setTimeout( - function() { - sprite.stop(); - sprite2.stop(); - assert.equal(updateCount > 15, true); - assert.equal(updateCount < 27, true); - done(); - }, - 1000 - ); + setTimeout(function() { + sprite.stop(); + sprite2.stop(); + assert.equal(updateCount > 15, true); + assert.equal(updateCount < 27, true); + done(); + }, 1000); }; imageObj.src = 'assets/scorpion-sprite.png'; }); @@ -395,29 +383,23 @@ suite('Sprite', function() { layer.add(sprite); stage.add(layer); assert.equal(sprite.frameRate(), 50); - setTimeout( - function() { - sprite.frameRate(100); - assert.equal(sprite.frameRate(), 100); - // don't run animation after change frame rate - assert.equal(sprite.anim.isRunning(), false); + setTimeout(function() { + sprite.frameRate(100); + assert.equal(sprite.frameRate(), 100); + // don't run animation after change frame rate + assert.equal(sprite.anim.isRunning(), false); - sprite.start(); - }, - 23 - ); + sprite.start(); + }, 23); - setTimeout( - function() { - sprite.frameRate(52); - assert.equal(sprite.anim.isRunning(), true); - // for this moment should tick more than 2 times - // make sure that sprite is not restating after set frame rate - assert.equal(sprite.frameIndex() > 2, true); - done(); - }, - 68 - ); + setTimeout(function() { + sprite.frameRate(52); + assert.equal(sprite.anim.isRunning(), true); + // for this moment should tick more than 2 times + // make sure that sprite is not restating after set frame rate + assert.equal(sprite.frameIndex() > 2, true); + done(); + }, 68); }; imageObj.src = 'assets/scorpion-sprite.png'; }); diff --git a/test/unit/shapes/Text-test.js b/test/unit/shapes/Text-test.js index 2a8e0f78..af53d4f3 100644 --- a/test/unit/shapes/Text-test.js +++ b/test/unit/shapes/Text-test.js @@ -14,21 +14,18 @@ suite('Text', function() { }); // ====================================================== - test( - 'text with undefined text property should not throw an error', - function() { - var stage = addStage(); - var layer = new Konva.Layer(); + test('text with undefined text property should not throw an error', function() { + var stage = addStage(); + var layer = new Konva.Layer(); - stage.add(layer); - var text = new Konva.Text({ text: undefined }); + stage.add(layer); + var text = new Konva.Text({ text: undefined }); - layer.add(text); - layer.draw(); + layer.add(text); + layer.draw(); - assert.equal(text.getWidth(), 0); - } - ); + assert.equal(text.getWidth(), 0); + }); test('add text with shadows', function() { var stage = addStage(); @@ -414,7 +411,8 @@ suite('Text', function() { stage.add(layer); - var trace = 'fillStyle;fillText();translate();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();restore();translate();save();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();restore();translate();restore();restore();'; + var trace = + 'fillStyle;fillText();translate();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();restore();translate();save();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();fillStyle;fillText();translate();restore();translate();restore();restore();'; assert.equal(layer.getContext().getTrace(true), trace); }); @@ -473,7 +471,8 @@ suite('Text', function() { layer.add(text); stage.add(layer); - var trace = 'clearRect(0,0,578,200);save();transform(1,0,0,1,10,10);font=normal normal 15px Arial;textBaseline=middle;textAlign=left;save();translate(0,7.5);save();save();beginPath();moveTo(0,8);lineTo(52,8);stroke();restore();fillStyle=red;fillText(h,0,0);translate(13,0);fillStyle=red;fillText(e,0,0);translate(13,0);fillStyle=red;fillText(l,0,0);translate(8,0);fillStyle=red;fillText(l,0,0);translate(8,0);fillStyle=red;fillText(o,0,0);translate(13,0);restore();translate(0,15);save();save();beginPath();moveTo(0,8);lineTo(56,8);stroke();restore();fillStyle=red;fillText(w,0,0);translate(16,0);fillStyle=red;fillText(o,0,0);translate(13,0);fillStyle=red;fillText(r,0,0);translate(10,0);fillStyle=red;fillText(l,0,0);translate(8,0);fillStyle=red;fillText(d,0,0);translate(13,0);restore();translate(0,15);restore();restore();'; + var trace = + 'clearRect(0,0,578,200);save();transform(1,0,0,1,10,10);font=normal normal 15px Arial;textBaseline=middle;textAlign=left;save();translate(0,7.5);save();save();beginPath();moveTo(0,8);lineTo(52,8);stroke();restore();fillStyle=red;fillText(h,0,0);translate(13,0);fillStyle=red;fillText(e,0,0);translate(13,0);fillStyle=red;fillText(l,0,0);translate(8,0);fillStyle=red;fillText(l,0,0);translate(8,0);fillStyle=red;fillText(o,0,0);translate(13,0);restore();translate(0,15);save();save();beginPath();moveTo(0,8);lineTo(56,8);stroke();restore();fillStyle=red;fillText(w,0,0);translate(16,0);fillStyle=red;fillText(o,0,0);translate(13,0);fillStyle=red;fillText(r,0,0);translate(10,0);fillStyle=red;fillText(l,0,0);translate(8,0);fillStyle=red;fillText(d,0,0);translate(13,0);restore();translate(0,15);restore();restore();'; assert.equal(layer.getContext().getTrace(), trace); }); @@ -495,7 +494,8 @@ suite('Text', function() { stage.add(layer); // TODO - var trace = 'clearRect();save();transform();font;textBaseline;textAlign;save();translate();save();save();beginPath();moveTo();lineTo();stroke();restore();fillStyle;fillText();restore();translate();save();save();beginPath();moveTo();lineTo();stroke();restore();fillStyle;fillText();restore();translate();restore();restore();'; + var trace = + 'clearRect();save();transform();font;textBaseline;textAlign;save();translate();save();save();beginPath();moveTo();lineTo();stroke();restore();fillStyle;fillText();restore();translate();save();save();beginPath();moveTo();lineTo();stroke();restore();fillStyle;fillText();restore();translate();restore();restore();'; console.log(layer.getContext().getTrace(true)); assert.equal(layer.getContext().getTrace(true), trace); }); @@ -516,7 +516,8 @@ suite('Text', function() { layer.add(text); stage.add(layer); - var trace = 'clearRect();save();transform();font;textBaseline;textAlign;save();translate();save();save();beginPath();moveTo();lineTo();stroke();restore();save();beginPath();moveTo();lineTo();stroke();restore();fillStyle;fillText();restore();translate();save();save();beginPath();moveTo();lineTo();stroke();restore();save();beginPath();moveTo();lineTo();stroke();restore();fillStyle;fillText();restore();translate();restore();restore();'; + var trace = + 'clearRect();save();transform();font;textBaseline;textAlign;save();translate();save();save();beginPath();moveTo();lineTo();stroke();restore();save();beginPath();moveTo();lineTo();stroke();restore();fillStyle;fillText();restore();translate();save();save();beginPath();moveTo();lineTo();stroke();restore();save();beginPath();moveTo();lineTo();stroke();restore();fillStyle;fillText();restore();translate();restore();restore();'; assert.equal(layer.getContext().getTrace(true), trace); }); diff --git a/test/unit/shapes/TextPath-test.js b/test/unit/shapes/TextPath-test.js index 05a3b464..a365c6d8 100644 --- a/test/unit/shapes/TextPath-test.js +++ b/test/unit/shapes/TextPath-test.js @@ -184,7 +184,8 @@ suite('TextPath', function() { var stage = addStage(); var layer = new Konva.Layer(); - var c = 'M 955.92249,-42.126952 L 955.92249,-42.126952 L 955.92249,-42.126952 L 961.93262,212.9279 C 961.72797,213.3372 961.22315,215.2234 960.80572,215.5574 C 957.45077,218.2413 956.9054,218.3026 953.66869,216.6843 C 952.62164,216.1607 951.67338,214.3658 949.91236,214.8061 C 947.3405,215.4491 948.09281,215.8744 946.53166,217.4355 C 945.22315,218.744 943.52659,219.8744 943.52659,222.3188 C 943.52659,225.6087 944.62943,224.7909 946.15603,226.8264 C 947.55965,228.6979 948.18154,229.6696 948.78546,232.0852 C 949.37174,234.4304 951.2918,235.2197 952.16616,236.9685 C 953.11809,238.8723 956.44837,240.9001 955.17122,242.6029 C 955.17122,242.8772 955.27602,243.9657 955.17122,244.1055 C 954.37248,245.1705 952.25782,247.1195 951.79052,248.9887 C 951.25154,251.1447 951.97226,252.3937 951.41489,254.6232 C 950.9178,256.6116 949.53672,257.6472 949.53672,259.8821 C 949.53672,261.2894 949.87203,263.5578 950.66362,265.1409 C 951.32462,266.4629 953.24159,268.3158 953.66869,270.0242 C 954.03114,271.474 954.12634,273.8281 953.66869,275.6587 C 953.20033,277.5321 952.16616,278.7427 952.16616,280.9175 C 952.16616,281.7694 952.66216,286.9313 952.16616,287.3033 C 950.55129,287.3033 950.38215,287.5144 949.16109,288.4302 C 947.74898,289.4893 945.57047,291.4095 944.65349,292.9378 C 943.57061,294.7426 942.86906,296.6011 942.3997,298.9479 C 941.97063,301.0933 941.32659,303.0261 940.1459,304.2068 C 938.60102,305.7517 939.019,307.4128 939.019,309.8413 C 939.019,311.6467 939.44296,314.3005 938.26773,315.4758 C 937.15545,316.5881 934.88703,318.5361 934.88703,320.7346 C 934.88703,322.7058 934.79432,324.8714 935.26267,326.7448 C 935.72373,328.589 935.6383,330.6902 935.6383,332.7549 C 935.6383,334.5937 936.08895,337.1125 935.26267,338.765 C 933.38787,342.5146 935.26267,342.5858 935.26267,345.5264 C 935.61053,346.9179 935.6383,348.2383 935.6383,350.034 C 935.6383,351.5752 934.96036,354.5783 932.63323,353.4147 C 932.09123,353.1437 928.92886,348.8032 927.75,351.1609 C 926.64231,353.3763 926.87972,354.3829 928.12564,356.0442 C 929.10471,357.3496 930.01787,360.3569 928.12564,361.303 C 926.67006,362.0308 924.24963,362.5828 924.74494,365.0593 C 925.21304,367.3998 926.19847,367.8684 926.6231,369.567 C 926.7781,370.1869 927.80544,374.5783 926.24747,375.2014 C 924.2456,376.0022 920.63857,376.64 919.86171,378.5821 C 918.7844,381.2754 918.89909,381.8572 921.36424,383.0897 C 922.93947,383.8774 923.65296,384.6272 925.12057,386.0948 C 925.4026,386.3768 928.41848,391.3951 926.99874,392.1049 C 926.6231,392.2301 926.22599,392.3035 925.87184,392.4806 C 924.02717,393.4029 922.07311,394.7556 920.61297,395.4856 C 918.19436,396.6949 919.66034,398.0609 920.23734,400.3689 C 920.66358,402.0738 920.9143,404.1809 919.48607,405.2521 C 918.27148,406.163 916.40598,407.9567 914.60284,407.5059 C 912.7458,407.0416 911.06841,406.8699 909.71961,407.8815 C 908.08698,409.106 906.39997,410.6424 905.96328,412.3891 C 905.46424,414.3853 903.5041,416.8116 901.83132,417.648 C 900.14443,418.4914 897.73682,419.2163 895.82119,420.6531 C 894.39644,421.7216 891.99114,423.3808 890.93796,424.785 C 889.59804,426.5716 888.40557,428.0687 886.80599,429.6682 C 885.18365,431.2906 883.35936,432.8052 882.29839,434.9271 C 881.56876,436.3864 879.95545,436.9836 879.29333,438.3078 C 878.57656,439.7413 877.73542,441.3406 876.28826,442.0641 C 874.75553,442.8305 873.35007,443.456 871.40503,443.9423 C 867.75936,444.8537 869.30342,446.1864 868.7756,448.8255 C 868.7756,449.4008 868.88599,450.1518 868.7756,450.7037 C 868.4147,452.5082 867.97176,454.46 866.14617,454.46 C 863.87643,454.46 863.13519,452.5202 860.51167,452.9575 C 858.30041,453.326 855.7288,453.4708 853.75028,454.46 C 851.66578,455.5023 850.88183,456.6114 849.24268,457.8407 C 848.34172,458.5165 844.59521,461.2214 842.85692,461.2214 C 841.06194,461.2214 838.75283,461.625 837.59805,460.4702 C 836.02546,458.8976 834.59299,457.0331 834.59299,454.8357 C 834.59299,452.5753 834.44046,450.9268 833.09045,449.5768 C 831.22582,447.7122 830.88608,448.6344 829.33412,450.7037 C 827.57516,453.049 826.50225,455.876 824.07526,457.0895 C 820.97109,458.6416 819.33963,458.3772 818.44076,461.9727 C 817.87317,464.2431 816.93823,466.7246 816.93823,469.1097 C 816.93823,470.8675 817.70296,474.7173 816.93823,476.2468 C 816.14706,477.8291 812.41394,478.9791 810.9281,476.998 C 808.83845,474.2118 810.41749,473.2417 805.66924,473.2417 C 801.6473,473.2417 799.28347,473.0146 799.28347,477.3737 C 799.28347,479.1155 799.58784,484.5107 796.65404,484.5107 C 796.27841,484.5107 795.90277,484.5107 795.52714,484.5107 C 793.06311,484.5107 790.57051,484.2819 789.51701,486.3889 C 789.24153,486.9398 789.17021,490.492 788.39011,491.2721 C 785.76325,493.8989 789.66759,493.7526 790.26828,496.1553 C 790.57092,497.3659 791.29959,501.1341 790.26828,502.1654 C 788.37505,504.0587 788.1443,505.2726 787.63885,507.7999 C 787.12622,510.3631 787.28641,510.4294 784.25815,510.4294 C 779.52049,510.4294 778.62062,512.1783 781.25308,515.6882 C 782.04773,516.7478 784.15693,519.0183 785.76068,519.8202 C 787.2339,520.5568 788.2453,521.5264 787.63885,523.9522 C 787.29534,525.3262 785.38505,526.8783 785.38505,528.8354 C 785.38505,532.3304 785.96541,532.0452 787.63885,533.7186 C 789.35939,535.4392 791.26358,536.4988 790.64391,538.9775 C 790.07532,541.2518 787.846,540.5966 785.38505,540.1044 C 784.8577,539.9989 777.87238,538.1167 777.87238,538.2262 C 777.87238,538.3043 777.87238,541.4667 777.87238,543.1095 C 777.87238,545.7389 776.11001,547.6978 773.74042,549.1196 C 769.72179,551.5308 769.56137,548.92 765.85212,547.9927 C 764.43987,547.6396 762.84706,547.0925 762.84706,544.9876 C 762.84706,542.5025 764.72522,540.5566 764.72522,538.9775 C 764.72522,537.481 764.49962,535.4457 763.97396,533.343 C 763.53464,531.5857 763.96677,529.2128 760.96889,529.9623 C 759.74476,530.2683 755.76059,530.9158 755.3344,529.211 C 754.79258,527.0438 753.83472,525.0819 752.32933,523.5765 C 751.7239,522.9711 748.78535,518.481 747.07047,520.1958 C 745.42956,521.8367 745.1923,522.8794 745.1923,525.4547 C 745.1923,529.5231 743.80555,527.5927 741.43597,529.9623 C 739.21241,532.1859 738.84328,532.0691 738.05527,535.2212 C 737.62578,536.9391 737.33255,538.9489 736.17711,540.1044 C 735.37222,540.9093 731.5352,542.6268 730.91824,543.8607 C 729.89113,545.9149 730.31425,546.7847 731.29388,548.744 C 731.93347,550.0231 732.94949,551.8879 732.42078,554.0028 C 731.86797,556.214 729.92914,558.5699 727.16191,559.2617 C 726.16187,559.7617 724.82639,560.5029 723.78121,560.7642 C 721.91594,561.2305 719.64925,561.351 719.64925,564.1449 C 719.64925,566.832 719.04019,568.7236 721.15178,569.7794 C 722.21289,570.31 724.72561,571.2926 725.28375,572.4088 C 726.18968,574.2207 726.03501,576.214 726.03501,578.419 C 726.03501,580.9518 724.90811,582.9761 724.90811,585.1804 C 724.90811,587.587 724.17206,589.3326 725.28375,590.8149 C 726.38582,592.2843 727.68532,592.9085 728.28881,595.3225 C 728.47077,596.0503 729.29883,599.6882 728.66444,600.957 C 728.20299,601.8799 726.62388,604.7133 724.90811,604.7133 C 722.23081,604.7133 719.55156,603.2108 717.77108,603.2108 C 712.9722,603.2108 711.01958,602.0443 709.88279,606.5915 C 709.52114,608.038 708.85871,610.3121 708.38026,612.2259 C 707.78279,614.6158 706.87772,616.6877 706.87772,619.363 C 706.87772,621.8398 706.7087,624.1711 706.12646,626.5 C 705.78303,627.8737 704.58011,630.6495 702.74576,631.3832 C 700.14612,632.4231 699.90837,632.6269 696.73563,633.2614 C 695.19072,633.5704 692.38471,634.0127 690.34987,634.0127 C 687.92024,634.0127 684.24023,633.3112 682.08594,634.3883 C 680.51621,635.1732 677.63742,637.5327 677.20271,639.2715 C 676.32889,642.7668 669.65019,641.1298 666.68498,639.6472 C 665.51347,639.0614 662.57658,637.112 662.17738,635.5152 C 661.57521,633.1065 663.16351,629.2235 662.17738,627.2513 C 661.26634,625.4292 659.87344,623.4448 658.42105,621.9924 C 657.38134,620.9527 655.38855,620.0777 654.28908,618.6117 C 653.089,617.0116 651.62053,616.0553 650.15712,614.1041 C 648.34003,611.6813 647.12666,612.2259 643.77136,612.2259 C 639.94754,612.2259 634.27092,612.8011 630.99983,610.3478 C 628.83169,608.7217 627.09631,607.7996 625.74097,605.0889 C 624.63961,602.8862 624.51407,601.3082 623.8628,598.7032 C 623.8628,597.1031 624.2465,594.9791 623.8628,593.4443 C 623.39918,591.5898 621.23337,589.3243 621.23337,587.4342 C 621.23337,587.1837 621.29411,586.9258 621.23337,586.6829 C 620.53685,583.8968 622.36027,582.4393 622.36027,580.6728 C 622.36027,578.1478 621.87342,577.1809 620.10647,575.4139 C 619.11396,574.4214 614.71345,572.543 612.96944,574.287 C 611.60526,575.6512 609.17921,577.309 606.95931,578.419 C 604.01326,579.892 598.66588,576.9755 597.19285,579.9215 C 596.40756,581.4921 595.76926,583.6587 595.31468,585.9316 C 594.88705,588.0698 594.09657,589.556 591.55835,590.0636 C 590.26591,590.3221 585.80562,591.0513 585.17259,592.3174 C 584.45323,593.7561 582.33804,595.3917 581.79189,597.5763 C 581.21425,599.8868 580.53762,600.7708 578.78683,602.0839 C 576.60544,603.7199 574.24457,604.0233 571.27416,602.8351 C 569.56134,602.15 566.96195,601.3583 564.51277,601.7082 C 562.15094,602.0456 560.7219,604.7047 559.2539,604.3377 C 556.608,603.6762 556.41629,603.5592 554.74631,601.3326 C 553.7801,600.0443 552.83677,595.5353 551.36561,594.9468 C 549.22437,594.0903 546.63624,594.001 543.85294,593.4443 C 541.39906,592.9535 538.87331,593.0687 536.34028,593.0687 C 532.49916,593.0687 532.93906,592.2969 530.70579,590.0636 C 529.57858,588.9364 527.94151,588.118 525.82255,587.0585 C 523.85495,586.0747 523.02163,585.6928 520.56369,586.3073 C 518.15725,586.9089 517.4765,588.4877 515.68046,588.9367 C 514.53264,589.2237 511.38458,588.643 510.04596,589.3123 C 508.49749,590.0866 507.19267,590.5834 506.66527,592.693 C 506.20828,594.521 505.99947,595.9598 504.7871,597.5763 C 503.10137,599.8239 501.43481,599.4686 499.1526,598.3275 C 496.74377,597.1231 496.63249,597.7484 493.89374,597.2006 C 491.45635,596.7131 490.45647,596.313 488.63487,594.9468 C 486.20245,593.1225 485.84728,591.7342 484.87854,589.3123 C 484.34805,587.9861 483.82138,584.0535 482.24911,584.0535 C 479.1858,584.0535 478.32694,584.2633 476.23898,582.1753 C 475.01433,580.9507 474.104,579.7043 472.85828,578.0433 C 471.87387,576.7308 471.15841,575.0383 468.72632,575.0383 C 465.62648,575.0383 465.0931,574.4101 463.09182,572.4088 C 461.80618,571.1232 459.77548,570.155 457.45733,570.155 C 454.22738,570.155 453.13567,570.2034 450.69593,572.0332 C 449.01793,573.2917 445.74427,574.287 443.5589,574.287 C 441.14907,574.287 438.88122,574.5776 436.7975,573.5357 C 435.27776,572.7759 434.01441,571.5961 432.28991,570.9063 C 429.9965,569.989 427.79078,568.6525 425.15288,568.6525 C 423.40022,568.6525 419.8328,569.7488 418.39148,569.0281 C 418.14106,568.9029 417.89064,568.7777 417.64021,568.6525 C 415.49479,567.5798 416.55622,567.2358 415.38641,564.8962 C 414.77237,563.6681 414.63515,562.1788 414.63515,560.0129 C 414.63515,558.3145 415.04465,556.0165 414.63515,554.3784 C 414.06491,552.0975 414.24886,549.8602 412.38135,547.9927 C 411.40995,547.0213 409.24156,545.0938 408.62502,543.8607 C 408.07318,542.757 407.08617,540.8193 405.99559,539.7288 C 404.23882,537.972 404.86869,537.4962 404.86869,535.2212 C 404.86869,532.3223 402.92378,530.8222 402.23926,528.0841 C 402.03511,527.2676 400.20775,523.9522 399.23419,523.9522 C 397.40724,523.9522 395.17436,524.3278 393.59969,524.3278 C 392.1471,524.3278 388.62445,524.895 387.9652,523.5765 C 387.16017,521.9665 386.46266,520.8647 386.46266,518.3177 C 386.46266,517.2392 387.06995,513.4929 386.46266,512.6832 C 385.44124,511.3213 383.94518,508.9268 382.3307,508.9268 C 380.0442,508.9268 378.68472,509.6505 377.07184,510.0537 C 374.43842,510.7121 375.12089,510.9506 374.06677,513.0588 C 372.99551,515.2013 371.43568,515.6866 369.55917,513.8101 C 367.11608,511.367 367.54854,511.9833 366.17847,513.8101 C 364.4331,516.1372 362.02692,517.942 359.04145,517.942 C 356.27733,517.942 354.79253,517.3325 353.78258,515.3126 C 352.71976,513.187 352.20547,512.3075 349.65062,512.3075 C 347.43943,512.3075 345.67638,511.8115 345.14302,509.6781 C 344.69437,507.8835 343.8574,505.0515 342.51359,504.0436 C 341.49931,503.2829 339.32282,500.99 337.25472,502.5411 C 336.12724,503.3867 330.59067,511.5766 329.49596,511.5766 L 339.92116,9.4291543 L 531.3294,9.5579943 C 531.53498,9.8775343 531.74056,10.197084 531.94614,10.516624 C 532.70213,11.691684 530.89998,12.894794 530.62953,14.247024 C 530.42067,15.291354 532.94855,14.371684 533.70163,15.124764 C 533.96143,15.384574 533.06188,17.795104 533.26276,18.196854 C 533.6241,18.919554 537.09651,16.118584 537.43203,15.783074 C 538.52925,14.685844 541.26067,15.533334 542.2596,15.783074 C 544.36225,16.308734 544.53484,13.969904 545.77057,16.441374 C 546.72008,18.340404 548.8757,18.577754 550.81758,18.855164 C 551.5334,18.957424 552.36959,15.108804 552.7925,14.685894 C 553.70371,13.774684 554.04733,13.026284 554.76742,14.466454 C 555.55609,16.043794 556.96728,16.885754 558.27838,18.196854 C 559.14892,19.067394 560.36843,19.874104 561.35048,20.610644 C 562.42985,21.420174 563.12715,21.998014 564.20314,22.805004 C 565.9662,24.127294 567.78898,25.511804 570.12789,26.096534 C 572.7652,26.755854 576.55367,27.553934 578.90531,28.729754 C 580.9132,29.733704 583.43718,29.459644 585.48837,30.485234 C 586.49144,30.986774 588.94826,31.133324 590.09651,31.362974 C 591.42028,32.024864 591.77294,34.338314 592.07143,35.532254 C 592.3559,36.670124 593.11993,38.320014 593.82691,39.262654 C 594.69143,40.415344 596.17315,41.423224 597.11844,41.895874 C 598.26675,42.470034 600.11464,43.649294 601.28771,44.529104 C 602.4452,45.397214 603.546,45.151114 603.04319,47.162324 C 602.73764,48.384554 601.38101,48.605074 600.62941,49.356674 C 599.50817,50.477904 599.93932,51.519254 600.84884,52.428774 C 601.81016,53.390084 603.26382,53.305314 604.14037,52.428774 C 604.62824,51.940894 608.18038,52.428774 608.96795,52.428774 C 611.1468,52.428774 610.66216,51.127474 612.47891,50.673284 C 612.63759,50.633624 612.77149,50.526994 612.91778,50.453854 C 614.68717,49.569154 616.9206,51.445064 617.9648,49.356674 C 618.52936,48.227544 619.56541,48.220674 619.93972,46.723454 C 620.25133,45.477014 620.37729,44.531694 621.03689,43.212484 C 621.76915,41.747964 621.9135,40.434484 622.79237,39.262654 C 623.77356,37.954414 624.27391,36.972204 625.64503,36.629424 C 627.98413,36.044654 628.95445,36.884634 629.81431,38.604344 C 630.5868,40.149334 629.04661,41.566394 628.05882,42.554184 C 627.03053,43.582464 626.94563,46.049134 627.83939,46.942884 C 628.71859,47.822094 631.7203,46.960114 632.66697,46.723454 C 635.14429,46.104124 638.40825,46.723454 641.00551,46.723454 C 642.99376,46.723454 643.25279,47.744904 644.29704,49.137244 C 645.27121,50.436134 645.05681,51.584644 643.63873,52.648204 C 642.199,53.728004 640.62809,54.372964 639.25003,55.061994 C 637.13418,56.119914 635.43133,55.127564 633.54471,54.184254 C 631.95211,53.387954 630.44161,53.389994 628.71713,53.964814 C 626.84122,54.590124 627.42091,55.720304 625.20616,55.720304 C 623.21044,55.720304 622.67528,55.410144 621.25633,54.842564 C 619.91862,54.307474 619.00883,54.278974 617.9648,55.061994 C 617.10854,55.704184 616.39298,55.720304 614.8927,55.720304 C 613.05499,55.720304 612.78965,55.409564 611.82061,56.378604 C 611.11873,57.080484 611.94664,57.914654 609.40682,57.914654 C 607.90864,57.914654 607.56008,59.135134 606.55416,59.889574 C 605.2063,60.900474 602.08634,60.328444 600.40997,60.328444 C 598.82692,60.328444 597.23216,60.282954 596.02126,60.767314 C 592.93299,62.002624 597.05347,63.219724 597.77675,63.400534 C 599.71594,63.885334 600.39327,64.211484 600.84884,66.033764 C 601.33813,67.990904 602.14535,68.474354 603.48206,66.692064 C 604.91144,64.786234 602.91352,64.497714 606.77359,64.497714 C 607.59464,64.497714 608.63043,67.232284 608.96795,67.569814 C 610.45793,69.059794 611.16665,70.095494 613.13722,71.080774 C 614.46498,71.744654 616.30615,67.595574 616.64819,66.911504 C 617.28296,65.641964 617.99069,64.704204 619.28141,64.058844 C 621.30547,63.046814 622.75619,64.278284 624.76729,64.278284 C 626.50942,64.278284 627.61995,65.003454 627.61995,62.742234 C 627.61995,61.212584 627.63406,61.199134 628.93656,60.547884 C 628.93656,59.039954 631.8995,61.398604 633.10584,62.303364 C 634.22905,63.145774 635.25806,64.560214 636.6168,65.375454 C 638.02819,66.222284 639.45789,65.179164 639.90833,64.278284 C 640.50672,63.081494 642.69629,63.368184 643.63873,63.839414 C 644.9694,64.504744 646.71554,64.500074 648.02744,65.156024 C 649.65658,65.970594 651.25018,66.091894 652.63558,67.130944 C 654.5709,68.582434 655.72441,69.284754 658.12146,69.764164 C 660.76933,70.293734 662.17378,70.473704 664.26565,71.519644 C 666.22906,72.501344 668.08427,73.121854 669.75154,74.372304 C 670.99777,75.306984 673.61008,75.688914 675.23742,75.688914 C 678.09495,75.688914 679.5978,74.715624 682.03992,73.494564 C 683.61178,72.708634 685.09563,72.194334 686.20919,71.080774 C 687.25214,70.037824 688.09533,68.975204 689.28128,67.789244 C 690.81968,66.250844 691.90496,66.472634 694.10886,66.472634 C 695.98476,66.472634 697.61589,67.130944 699.37531,67.130944 C 700.88236,67.130944 702.30921,68.008684 703.98345,68.008684 C 705.78815,68.008684 706.82154,67.443974 708.15272,66.911504 C 709.49084,66.376254 710.32631,65.391024 711.22482,64.717154 C 712.93357,63.435584 713.93405,62.155634 715.83296,61.206184 C 717.44839,60.398474 719.60451,59.255264 721.09941,58.134094 C 722.32027,57.218444 724.55866,55.842944 725.92699,55.500864 C 727.42616,55.126074 729.09302,54.102794 730.53513,53.525944 C 732.4374,52.765044 734.47148,52.545224 736.02101,51.770464 C 736.81463,51.373654 738.38579,51.112164 739.31254,51.112164 C 739.58229,50.977294 739.8977,50.965874 740.19028,50.892724 C 741.93619,50.456234 744.97275,50.145724 746.55391,51.331594 C 747.77567,52.247914 749.08929,52.550364 750.06487,53.525944 C 751.05366,54.514734 751.10636,54.963084 752.6981,55.281434 C 753.97746,55.537304 755.20688,54.403694 756.64793,54.403694 C 757.60799,54.403694 759.65763,56.143574 760.59777,56.378604 C 762.10547,56.755534 763.41059,56.817474 764.98648,56.817474 C 766.46659,56.817474 768.85254,54.943624 770.47236,54.403694 C 772.25575,53.809224 773.23113,53.525944 775.29994,53.525944 C 777.348,53.525944 779.39606,53.525944 781.44413,53.525944 C 783.12504,53.525944 784.01926,53.375894 785.17453,53.087074 C 786.13177,52.847764 786.81429,52.867644 787.80775,52.867644 C 789.68721,52.397784 790.54366,51.799654 792.41589,51.331594 C 793.72507,51.004304 794.52824,48.862394 795.04912,47.820634 C 795.74654,46.425784 796.31421,45.768114 797.24347,44.529104 C 798.0814,43.411864 799.90954,42.318324 801.19331,41.676444 C 802.47959,41.033304 803.007,40.301614 804.04597,39.262654 C 804.9791,38.329524 805.42163,37.448114 806.24032,36.629424 C 807.32555,35.544194 808.33509,33.723304 809.09298,32.460154 C 809.72369,31.408974 811.13754,30.635024 812.16508,29.607494 C 812.75994,29.012634 816.59236,28.500674 817.43152,28.290884 C 818.9728,27.905564 820.03772,26.864014 820.94249,25.657664 C 821.81326,24.496634 822.20664,23.673144 822.47854,22.585564 C 822.70979,21.660554 823.16846,20.484194 823.35628,19.732904 C 823.39176,19.590984 823.35628,19.440324 823.35628,19.294034 C 824.72829,14.181234 833.5556,11.720324 838.16552,9.4153643 C 840.3455,8.3253643 841.62867,5.2222343 843.25846,3.0491743 C 844.34873,1.5954943 847.99376,1.4409443 850.04906,0.92711429 C 853.15105,0.15161429 855.95039,-0.84630571 858.11289,-2.4681757 C 860.2827,-4.0955457 863.83523,-5.3512957 866.17672,-6.2878857 C 868.93603,-7.3916157 871.61677,-9.3068957 873.81614,-10.956426 C 875.97519,-12.575706 878.16034,-13.552932 880.60673,-14.776132 C 882.92916,-15.937342 883.77331,-17.477632 886.5485,-18.171422 C 890.51751,-19.163682 894.57232,-17.476362 898.43204,-19.020252 C 901.2465,-20.146032 904.60721,-21.731172 907.3447,-22.415552 C 909.30842,-22.906482 911.47245,-25.328252 913.28647,-26.235262 C 916.00359,-27.593822 917.08159,-29.412202 919.65265,-30.054972 C 921.32298,-30.472552 924.26602,-31.730552 926.44325,-32.601442 C 928.89479,-33.582062 931.86421,-33.402072 933.65826,-34.299092 C 936.16619,-35.553052 937.08458,-36.322802 939.17561,-36.845562 C 941.67817,-37.471202 944.13749,-38.007702 946.81503,-38.543212 C 948.94134,-38.968472 950.98649,-40.592612 952.33239,-41.938512 C 953.1616,-42.767712 955.07166,-42.233042 955.92249,-42.126952 z '; + var c = + 'M 955.92249,-42.126952 L 955.92249,-42.126952 L 955.92249,-42.126952 L 961.93262,212.9279 C 961.72797,213.3372 961.22315,215.2234 960.80572,215.5574 C 957.45077,218.2413 956.9054,218.3026 953.66869,216.6843 C 952.62164,216.1607 951.67338,214.3658 949.91236,214.8061 C 947.3405,215.4491 948.09281,215.8744 946.53166,217.4355 C 945.22315,218.744 943.52659,219.8744 943.52659,222.3188 C 943.52659,225.6087 944.62943,224.7909 946.15603,226.8264 C 947.55965,228.6979 948.18154,229.6696 948.78546,232.0852 C 949.37174,234.4304 951.2918,235.2197 952.16616,236.9685 C 953.11809,238.8723 956.44837,240.9001 955.17122,242.6029 C 955.17122,242.8772 955.27602,243.9657 955.17122,244.1055 C 954.37248,245.1705 952.25782,247.1195 951.79052,248.9887 C 951.25154,251.1447 951.97226,252.3937 951.41489,254.6232 C 950.9178,256.6116 949.53672,257.6472 949.53672,259.8821 C 949.53672,261.2894 949.87203,263.5578 950.66362,265.1409 C 951.32462,266.4629 953.24159,268.3158 953.66869,270.0242 C 954.03114,271.474 954.12634,273.8281 953.66869,275.6587 C 953.20033,277.5321 952.16616,278.7427 952.16616,280.9175 C 952.16616,281.7694 952.66216,286.9313 952.16616,287.3033 C 950.55129,287.3033 950.38215,287.5144 949.16109,288.4302 C 947.74898,289.4893 945.57047,291.4095 944.65349,292.9378 C 943.57061,294.7426 942.86906,296.6011 942.3997,298.9479 C 941.97063,301.0933 941.32659,303.0261 940.1459,304.2068 C 938.60102,305.7517 939.019,307.4128 939.019,309.8413 C 939.019,311.6467 939.44296,314.3005 938.26773,315.4758 C 937.15545,316.5881 934.88703,318.5361 934.88703,320.7346 C 934.88703,322.7058 934.79432,324.8714 935.26267,326.7448 C 935.72373,328.589 935.6383,330.6902 935.6383,332.7549 C 935.6383,334.5937 936.08895,337.1125 935.26267,338.765 C 933.38787,342.5146 935.26267,342.5858 935.26267,345.5264 C 935.61053,346.9179 935.6383,348.2383 935.6383,350.034 C 935.6383,351.5752 934.96036,354.5783 932.63323,353.4147 C 932.09123,353.1437 928.92886,348.8032 927.75,351.1609 C 926.64231,353.3763 926.87972,354.3829 928.12564,356.0442 C 929.10471,357.3496 930.01787,360.3569 928.12564,361.303 C 926.67006,362.0308 924.24963,362.5828 924.74494,365.0593 C 925.21304,367.3998 926.19847,367.8684 926.6231,369.567 C 926.7781,370.1869 927.80544,374.5783 926.24747,375.2014 C 924.2456,376.0022 920.63857,376.64 919.86171,378.5821 C 918.7844,381.2754 918.89909,381.8572 921.36424,383.0897 C 922.93947,383.8774 923.65296,384.6272 925.12057,386.0948 C 925.4026,386.3768 928.41848,391.3951 926.99874,392.1049 C 926.6231,392.2301 926.22599,392.3035 925.87184,392.4806 C 924.02717,393.4029 922.07311,394.7556 920.61297,395.4856 C 918.19436,396.6949 919.66034,398.0609 920.23734,400.3689 C 920.66358,402.0738 920.9143,404.1809 919.48607,405.2521 C 918.27148,406.163 916.40598,407.9567 914.60284,407.5059 C 912.7458,407.0416 911.06841,406.8699 909.71961,407.8815 C 908.08698,409.106 906.39997,410.6424 905.96328,412.3891 C 905.46424,414.3853 903.5041,416.8116 901.83132,417.648 C 900.14443,418.4914 897.73682,419.2163 895.82119,420.6531 C 894.39644,421.7216 891.99114,423.3808 890.93796,424.785 C 889.59804,426.5716 888.40557,428.0687 886.80599,429.6682 C 885.18365,431.2906 883.35936,432.8052 882.29839,434.9271 C 881.56876,436.3864 879.95545,436.9836 879.29333,438.3078 C 878.57656,439.7413 877.73542,441.3406 876.28826,442.0641 C 874.75553,442.8305 873.35007,443.456 871.40503,443.9423 C 867.75936,444.8537 869.30342,446.1864 868.7756,448.8255 C 868.7756,449.4008 868.88599,450.1518 868.7756,450.7037 C 868.4147,452.5082 867.97176,454.46 866.14617,454.46 C 863.87643,454.46 863.13519,452.5202 860.51167,452.9575 C 858.30041,453.326 855.7288,453.4708 853.75028,454.46 C 851.66578,455.5023 850.88183,456.6114 849.24268,457.8407 C 848.34172,458.5165 844.59521,461.2214 842.85692,461.2214 C 841.06194,461.2214 838.75283,461.625 837.59805,460.4702 C 836.02546,458.8976 834.59299,457.0331 834.59299,454.8357 C 834.59299,452.5753 834.44046,450.9268 833.09045,449.5768 C 831.22582,447.7122 830.88608,448.6344 829.33412,450.7037 C 827.57516,453.049 826.50225,455.876 824.07526,457.0895 C 820.97109,458.6416 819.33963,458.3772 818.44076,461.9727 C 817.87317,464.2431 816.93823,466.7246 816.93823,469.1097 C 816.93823,470.8675 817.70296,474.7173 816.93823,476.2468 C 816.14706,477.8291 812.41394,478.9791 810.9281,476.998 C 808.83845,474.2118 810.41749,473.2417 805.66924,473.2417 C 801.6473,473.2417 799.28347,473.0146 799.28347,477.3737 C 799.28347,479.1155 799.58784,484.5107 796.65404,484.5107 C 796.27841,484.5107 795.90277,484.5107 795.52714,484.5107 C 793.06311,484.5107 790.57051,484.2819 789.51701,486.3889 C 789.24153,486.9398 789.17021,490.492 788.39011,491.2721 C 785.76325,493.8989 789.66759,493.7526 790.26828,496.1553 C 790.57092,497.3659 791.29959,501.1341 790.26828,502.1654 C 788.37505,504.0587 788.1443,505.2726 787.63885,507.7999 C 787.12622,510.3631 787.28641,510.4294 784.25815,510.4294 C 779.52049,510.4294 778.62062,512.1783 781.25308,515.6882 C 782.04773,516.7478 784.15693,519.0183 785.76068,519.8202 C 787.2339,520.5568 788.2453,521.5264 787.63885,523.9522 C 787.29534,525.3262 785.38505,526.8783 785.38505,528.8354 C 785.38505,532.3304 785.96541,532.0452 787.63885,533.7186 C 789.35939,535.4392 791.26358,536.4988 790.64391,538.9775 C 790.07532,541.2518 787.846,540.5966 785.38505,540.1044 C 784.8577,539.9989 777.87238,538.1167 777.87238,538.2262 C 777.87238,538.3043 777.87238,541.4667 777.87238,543.1095 C 777.87238,545.7389 776.11001,547.6978 773.74042,549.1196 C 769.72179,551.5308 769.56137,548.92 765.85212,547.9927 C 764.43987,547.6396 762.84706,547.0925 762.84706,544.9876 C 762.84706,542.5025 764.72522,540.5566 764.72522,538.9775 C 764.72522,537.481 764.49962,535.4457 763.97396,533.343 C 763.53464,531.5857 763.96677,529.2128 760.96889,529.9623 C 759.74476,530.2683 755.76059,530.9158 755.3344,529.211 C 754.79258,527.0438 753.83472,525.0819 752.32933,523.5765 C 751.7239,522.9711 748.78535,518.481 747.07047,520.1958 C 745.42956,521.8367 745.1923,522.8794 745.1923,525.4547 C 745.1923,529.5231 743.80555,527.5927 741.43597,529.9623 C 739.21241,532.1859 738.84328,532.0691 738.05527,535.2212 C 737.62578,536.9391 737.33255,538.9489 736.17711,540.1044 C 735.37222,540.9093 731.5352,542.6268 730.91824,543.8607 C 729.89113,545.9149 730.31425,546.7847 731.29388,548.744 C 731.93347,550.0231 732.94949,551.8879 732.42078,554.0028 C 731.86797,556.214 729.92914,558.5699 727.16191,559.2617 C 726.16187,559.7617 724.82639,560.5029 723.78121,560.7642 C 721.91594,561.2305 719.64925,561.351 719.64925,564.1449 C 719.64925,566.832 719.04019,568.7236 721.15178,569.7794 C 722.21289,570.31 724.72561,571.2926 725.28375,572.4088 C 726.18968,574.2207 726.03501,576.214 726.03501,578.419 C 726.03501,580.9518 724.90811,582.9761 724.90811,585.1804 C 724.90811,587.587 724.17206,589.3326 725.28375,590.8149 C 726.38582,592.2843 727.68532,592.9085 728.28881,595.3225 C 728.47077,596.0503 729.29883,599.6882 728.66444,600.957 C 728.20299,601.8799 726.62388,604.7133 724.90811,604.7133 C 722.23081,604.7133 719.55156,603.2108 717.77108,603.2108 C 712.9722,603.2108 711.01958,602.0443 709.88279,606.5915 C 709.52114,608.038 708.85871,610.3121 708.38026,612.2259 C 707.78279,614.6158 706.87772,616.6877 706.87772,619.363 C 706.87772,621.8398 706.7087,624.1711 706.12646,626.5 C 705.78303,627.8737 704.58011,630.6495 702.74576,631.3832 C 700.14612,632.4231 699.90837,632.6269 696.73563,633.2614 C 695.19072,633.5704 692.38471,634.0127 690.34987,634.0127 C 687.92024,634.0127 684.24023,633.3112 682.08594,634.3883 C 680.51621,635.1732 677.63742,637.5327 677.20271,639.2715 C 676.32889,642.7668 669.65019,641.1298 666.68498,639.6472 C 665.51347,639.0614 662.57658,637.112 662.17738,635.5152 C 661.57521,633.1065 663.16351,629.2235 662.17738,627.2513 C 661.26634,625.4292 659.87344,623.4448 658.42105,621.9924 C 657.38134,620.9527 655.38855,620.0777 654.28908,618.6117 C 653.089,617.0116 651.62053,616.0553 650.15712,614.1041 C 648.34003,611.6813 647.12666,612.2259 643.77136,612.2259 C 639.94754,612.2259 634.27092,612.8011 630.99983,610.3478 C 628.83169,608.7217 627.09631,607.7996 625.74097,605.0889 C 624.63961,602.8862 624.51407,601.3082 623.8628,598.7032 C 623.8628,597.1031 624.2465,594.9791 623.8628,593.4443 C 623.39918,591.5898 621.23337,589.3243 621.23337,587.4342 C 621.23337,587.1837 621.29411,586.9258 621.23337,586.6829 C 620.53685,583.8968 622.36027,582.4393 622.36027,580.6728 C 622.36027,578.1478 621.87342,577.1809 620.10647,575.4139 C 619.11396,574.4214 614.71345,572.543 612.96944,574.287 C 611.60526,575.6512 609.17921,577.309 606.95931,578.419 C 604.01326,579.892 598.66588,576.9755 597.19285,579.9215 C 596.40756,581.4921 595.76926,583.6587 595.31468,585.9316 C 594.88705,588.0698 594.09657,589.556 591.55835,590.0636 C 590.26591,590.3221 585.80562,591.0513 585.17259,592.3174 C 584.45323,593.7561 582.33804,595.3917 581.79189,597.5763 C 581.21425,599.8868 580.53762,600.7708 578.78683,602.0839 C 576.60544,603.7199 574.24457,604.0233 571.27416,602.8351 C 569.56134,602.15 566.96195,601.3583 564.51277,601.7082 C 562.15094,602.0456 560.7219,604.7047 559.2539,604.3377 C 556.608,603.6762 556.41629,603.5592 554.74631,601.3326 C 553.7801,600.0443 552.83677,595.5353 551.36561,594.9468 C 549.22437,594.0903 546.63624,594.001 543.85294,593.4443 C 541.39906,592.9535 538.87331,593.0687 536.34028,593.0687 C 532.49916,593.0687 532.93906,592.2969 530.70579,590.0636 C 529.57858,588.9364 527.94151,588.118 525.82255,587.0585 C 523.85495,586.0747 523.02163,585.6928 520.56369,586.3073 C 518.15725,586.9089 517.4765,588.4877 515.68046,588.9367 C 514.53264,589.2237 511.38458,588.643 510.04596,589.3123 C 508.49749,590.0866 507.19267,590.5834 506.66527,592.693 C 506.20828,594.521 505.99947,595.9598 504.7871,597.5763 C 503.10137,599.8239 501.43481,599.4686 499.1526,598.3275 C 496.74377,597.1231 496.63249,597.7484 493.89374,597.2006 C 491.45635,596.7131 490.45647,596.313 488.63487,594.9468 C 486.20245,593.1225 485.84728,591.7342 484.87854,589.3123 C 484.34805,587.9861 483.82138,584.0535 482.24911,584.0535 C 479.1858,584.0535 478.32694,584.2633 476.23898,582.1753 C 475.01433,580.9507 474.104,579.7043 472.85828,578.0433 C 471.87387,576.7308 471.15841,575.0383 468.72632,575.0383 C 465.62648,575.0383 465.0931,574.4101 463.09182,572.4088 C 461.80618,571.1232 459.77548,570.155 457.45733,570.155 C 454.22738,570.155 453.13567,570.2034 450.69593,572.0332 C 449.01793,573.2917 445.74427,574.287 443.5589,574.287 C 441.14907,574.287 438.88122,574.5776 436.7975,573.5357 C 435.27776,572.7759 434.01441,571.5961 432.28991,570.9063 C 429.9965,569.989 427.79078,568.6525 425.15288,568.6525 C 423.40022,568.6525 419.8328,569.7488 418.39148,569.0281 C 418.14106,568.9029 417.89064,568.7777 417.64021,568.6525 C 415.49479,567.5798 416.55622,567.2358 415.38641,564.8962 C 414.77237,563.6681 414.63515,562.1788 414.63515,560.0129 C 414.63515,558.3145 415.04465,556.0165 414.63515,554.3784 C 414.06491,552.0975 414.24886,549.8602 412.38135,547.9927 C 411.40995,547.0213 409.24156,545.0938 408.62502,543.8607 C 408.07318,542.757 407.08617,540.8193 405.99559,539.7288 C 404.23882,537.972 404.86869,537.4962 404.86869,535.2212 C 404.86869,532.3223 402.92378,530.8222 402.23926,528.0841 C 402.03511,527.2676 400.20775,523.9522 399.23419,523.9522 C 397.40724,523.9522 395.17436,524.3278 393.59969,524.3278 C 392.1471,524.3278 388.62445,524.895 387.9652,523.5765 C 387.16017,521.9665 386.46266,520.8647 386.46266,518.3177 C 386.46266,517.2392 387.06995,513.4929 386.46266,512.6832 C 385.44124,511.3213 383.94518,508.9268 382.3307,508.9268 C 380.0442,508.9268 378.68472,509.6505 377.07184,510.0537 C 374.43842,510.7121 375.12089,510.9506 374.06677,513.0588 C 372.99551,515.2013 371.43568,515.6866 369.55917,513.8101 C 367.11608,511.367 367.54854,511.9833 366.17847,513.8101 C 364.4331,516.1372 362.02692,517.942 359.04145,517.942 C 356.27733,517.942 354.79253,517.3325 353.78258,515.3126 C 352.71976,513.187 352.20547,512.3075 349.65062,512.3075 C 347.43943,512.3075 345.67638,511.8115 345.14302,509.6781 C 344.69437,507.8835 343.8574,505.0515 342.51359,504.0436 C 341.49931,503.2829 339.32282,500.99 337.25472,502.5411 C 336.12724,503.3867 330.59067,511.5766 329.49596,511.5766 L 339.92116,9.4291543 L 531.3294,9.5579943 C 531.53498,9.8775343 531.74056,10.197084 531.94614,10.516624 C 532.70213,11.691684 530.89998,12.894794 530.62953,14.247024 C 530.42067,15.291354 532.94855,14.371684 533.70163,15.124764 C 533.96143,15.384574 533.06188,17.795104 533.26276,18.196854 C 533.6241,18.919554 537.09651,16.118584 537.43203,15.783074 C 538.52925,14.685844 541.26067,15.533334 542.2596,15.783074 C 544.36225,16.308734 544.53484,13.969904 545.77057,16.441374 C 546.72008,18.340404 548.8757,18.577754 550.81758,18.855164 C 551.5334,18.957424 552.36959,15.108804 552.7925,14.685894 C 553.70371,13.774684 554.04733,13.026284 554.76742,14.466454 C 555.55609,16.043794 556.96728,16.885754 558.27838,18.196854 C 559.14892,19.067394 560.36843,19.874104 561.35048,20.610644 C 562.42985,21.420174 563.12715,21.998014 564.20314,22.805004 C 565.9662,24.127294 567.78898,25.511804 570.12789,26.096534 C 572.7652,26.755854 576.55367,27.553934 578.90531,28.729754 C 580.9132,29.733704 583.43718,29.459644 585.48837,30.485234 C 586.49144,30.986774 588.94826,31.133324 590.09651,31.362974 C 591.42028,32.024864 591.77294,34.338314 592.07143,35.532254 C 592.3559,36.670124 593.11993,38.320014 593.82691,39.262654 C 594.69143,40.415344 596.17315,41.423224 597.11844,41.895874 C 598.26675,42.470034 600.11464,43.649294 601.28771,44.529104 C 602.4452,45.397214 603.546,45.151114 603.04319,47.162324 C 602.73764,48.384554 601.38101,48.605074 600.62941,49.356674 C 599.50817,50.477904 599.93932,51.519254 600.84884,52.428774 C 601.81016,53.390084 603.26382,53.305314 604.14037,52.428774 C 604.62824,51.940894 608.18038,52.428774 608.96795,52.428774 C 611.1468,52.428774 610.66216,51.127474 612.47891,50.673284 C 612.63759,50.633624 612.77149,50.526994 612.91778,50.453854 C 614.68717,49.569154 616.9206,51.445064 617.9648,49.356674 C 618.52936,48.227544 619.56541,48.220674 619.93972,46.723454 C 620.25133,45.477014 620.37729,44.531694 621.03689,43.212484 C 621.76915,41.747964 621.9135,40.434484 622.79237,39.262654 C 623.77356,37.954414 624.27391,36.972204 625.64503,36.629424 C 627.98413,36.044654 628.95445,36.884634 629.81431,38.604344 C 630.5868,40.149334 629.04661,41.566394 628.05882,42.554184 C 627.03053,43.582464 626.94563,46.049134 627.83939,46.942884 C 628.71859,47.822094 631.7203,46.960114 632.66697,46.723454 C 635.14429,46.104124 638.40825,46.723454 641.00551,46.723454 C 642.99376,46.723454 643.25279,47.744904 644.29704,49.137244 C 645.27121,50.436134 645.05681,51.584644 643.63873,52.648204 C 642.199,53.728004 640.62809,54.372964 639.25003,55.061994 C 637.13418,56.119914 635.43133,55.127564 633.54471,54.184254 C 631.95211,53.387954 630.44161,53.389994 628.71713,53.964814 C 626.84122,54.590124 627.42091,55.720304 625.20616,55.720304 C 623.21044,55.720304 622.67528,55.410144 621.25633,54.842564 C 619.91862,54.307474 619.00883,54.278974 617.9648,55.061994 C 617.10854,55.704184 616.39298,55.720304 614.8927,55.720304 C 613.05499,55.720304 612.78965,55.409564 611.82061,56.378604 C 611.11873,57.080484 611.94664,57.914654 609.40682,57.914654 C 607.90864,57.914654 607.56008,59.135134 606.55416,59.889574 C 605.2063,60.900474 602.08634,60.328444 600.40997,60.328444 C 598.82692,60.328444 597.23216,60.282954 596.02126,60.767314 C 592.93299,62.002624 597.05347,63.219724 597.77675,63.400534 C 599.71594,63.885334 600.39327,64.211484 600.84884,66.033764 C 601.33813,67.990904 602.14535,68.474354 603.48206,66.692064 C 604.91144,64.786234 602.91352,64.497714 606.77359,64.497714 C 607.59464,64.497714 608.63043,67.232284 608.96795,67.569814 C 610.45793,69.059794 611.16665,70.095494 613.13722,71.080774 C 614.46498,71.744654 616.30615,67.595574 616.64819,66.911504 C 617.28296,65.641964 617.99069,64.704204 619.28141,64.058844 C 621.30547,63.046814 622.75619,64.278284 624.76729,64.278284 C 626.50942,64.278284 627.61995,65.003454 627.61995,62.742234 C 627.61995,61.212584 627.63406,61.199134 628.93656,60.547884 C 628.93656,59.039954 631.8995,61.398604 633.10584,62.303364 C 634.22905,63.145774 635.25806,64.560214 636.6168,65.375454 C 638.02819,66.222284 639.45789,65.179164 639.90833,64.278284 C 640.50672,63.081494 642.69629,63.368184 643.63873,63.839414 C 644.9694,64.504744 646.71554,64.500074 648.02744,65.156024 C 649.65658,65.970594 651.25018,66.091894 652.63558,67.130944 C 654.5709,68.582434 655.72441,69.284754 658.12146,69.764164 C 660.76933,70.293734 662.17378,70.473704 664.26565,71.519644 C 666.22906,72.501344 668.08427,73.121854 669.75154,74.372304 C 670.99777,75.306984 673.61008,75.688914 675.23742,75.688914 C 678.09495,75.688914 679.5978,74.715624 682.03992,73.494564 C 683.61178,72.708634 685.09563,72.194334 686.20919,71.080774 C 687.25214,70.037824 688.09533,68.975204 689.28128,67.789244 C 690.81968,66.250844 691.90496,66.472634 694.10886,66.472634 C 695.98476,66.472634 697.61589,67.130944 699.37531,67.130944 C 700.88236,67.130944 702.30921,68.008684 703.98345,68.008684 C 705.78815,68.008684 706.82154,67.443974 708.15272,66.911504 C 709.49084,66.376254 710.32631,65.391024 711.22482,64.717154 C 712.93357,63.435584 713.93405,62.155634 715.83296,61.206184 C 717.44839,60.398474 719.60451,59.255264 721.09941,58.134094 C 722.32027,57.218444 724.55866,55.842944 725.92699,55.500864 C 727.42616,55.126074 729.09302,54.102794 730.53513,53.525944 C 732.4374,52.765044 734.47148,52.545224 736.02101,51.770464 C 736.81463,51.373654 738.38579,51.112164 739.31254,51.112164 C 739.58229,50.977294 739.8977,50.965874 740.19028,50.892724 C 741.93619,50.456234 744.97275,50.145724 746.55391,51.331594 C 747.77567,52.247914 749.08929,52.550364 750.06487,53.525944 C 751.05366,54.514734 751.10636,54.963084 752.6981,55.281434 C 753.97746,55.537304 755.20688,54.403694 756.64793,54.403694 C 757.60799,54.403694 759.65763,56.143574 760.59777,56.378604 C 762.10547,56.755534 763.41059,56.817474 764.98648,56.817474 C 766.46659,56.817474 768.85254,54.943624 770.47236,54.403694 C 772.25575,53.809224 773.23113,53.525944 775.29994,53.525944 C 777.348,53.525944 779.39606,53.525944 781.44413,53.525944 C 783.12504,53.525944 784.01926,53.375894 785.17453,53.087074 C 786.13177,52.847764 786.81429,52.867644 787.80775,52.867644 C 789.68721,52.397784 790.54366,51.799654 792.41589,51.331594 C 793.72507,51.004304 794.52824,48.862394 795.04912,47.820634 C 795.74654,46.425784 796.31421,45.768114 797.24347,44.529104 C 798.0814,43.411864 799.90954,42.318324 801.19331,41.676444 C 802.47959,41.033304 803.007,40.301614 804.04597,39.262654 C 804.9791,38.329524 805.42163,37.448114 806.24032,36.629424 C 807.32555,35.544194 808.33509,33.723304 809.09298,32.460154 C 809.72369,31.408974 811.13754,30.635024 812.16508,29.607494 C 812.75994,29.012634 816.59236,28.500674 817.43152,28.290884 C 818.9728,27.905564 820.03772,26.864014 820.94249,25.657664 C 821.81326,24.496634 822.20664,23.673144 822.47854,22.585564 C 822.70979,21.660554 823.16846,20.484194 823.35628,19.732904 C 823.39176,19.590984 823.35628,19.440324 823.35628,19.294034 C 824.72829,14.181234 833.5556,11.720324 838.16552,9.4153643 C 840.3455,8.3253643 841.62867,5.2222343 843.25846,3.0491743 C 844.34873,1.5954943 847.99376,1.4409443 850.04906,0.92711429 C 853.15105,0.15161429 855.95039,-0.84630571 858.11289,-2.4681757 C 860.2827,-4.0955457 863.83523,-5.3512957 866.17672,-6.2878857 C 868.93603,-7.3916157 871.61677,-9.3068957 873.81614,-10.956426 C 875.97519,-12.575706 878.16034,-13.552932 880.60673,-14.776132 C 882.92916,-15.937342 883.77331,-17.477632 886.5485,-18.171422 C 890.51751,-19.163682 894.57232,-17.476362 898.43204,-19.020252 C 901.2465,-20.146032 904.60721,-21.731172 907.3447,-22.415552 C 909.30842,-22.906482 911.47245,-25.328252 913.28647,-26.235262 C 916.00359,-27.593822 917.08159,-29.412202 919.65265,-30.054972 C 921.32298,-30.472552 924.26602,-31.730552 926.44325,-32.601442 C 928.89479,-33.582062 931.86421,-33.402072 933.65826,-34.299092 C 936.16619,-35.553052 937.08458,-36.322802 939.17561,-36.845562 C 941.67817,-37.471202 944.13749,-38.007702 946.81503,-38.543212 C 948.94134,-38.968472 950.98649,-40.592612 952.33239,-41.938512 C 953.1616,-42.767712 955.07166,-42.233042 955.92249,-42.126952 z '; var textpath = new Konva.TextPath({ y: 50, @@ -300,7 +301,8 @@ suite('TextPath', function() { stage.add(layer); // console.log(layer.getContext().getTrace(true)); - var trace = 'rotate();fillStyle;fillText();lineWidth;strokeStyle;strokeText();restore();save();translate();rotate();fillStyle;fillText();lineWidth;strokeStyle;strokeText();restore();save();translate();rotate();fillStyle;fillText();lineWidth;strokeStyle;strokeText();restore();save();translate();rotate();fillStyle;fillText();lineWidth;strokeStyle;strokeText();restore();save();translate();rotate();fillStyle;fillText();lineWidth;strokeStyle;strokeText();restore();save();translate();rotate();fillStyle;fillText();lineWidth;strokeStyle;strokeText();restore();save();translate();rotate();fillStyle;fillText();lineWidth;strokeStyle;strokeText();restore();save();translate();rotate();fillStyle;fillText();lineWidth;strokeStyle;strokeText();restore();save();translate();rotate();fillStyle;fillText();lineWidth;strokeStyle;strokeText();restore();save();translate();rotate();fillStyle;fillText();lineWidth;strokeStyle;strokeText();restore();save();translate();rotate();fillStyle;fillText();lineWidth;strokeStyle;strokeText();restore();restore();restore();'; + var trace = + 'rotate();fillStyle;fillText();lineWidth;strokeStyle;strokeText();restore();save();translate();rotate();fillStyle;fillText();lineWidth;strokeStyle;strokeText();restore();save();translate();rotate();fillStyle;fillText();lineWidth;strokeStyle;strokeText();restore();save();translate();rotate();fillStyle;fillText();lineWidth;strokeStyle;strokeText();restore();save();translate();rotate();fillStyle;fillText();lineWidth;strokeStyle;strokeText();restore();save();translate();rotate();fillStyle;fillText();lineWidth;strokeStyle;strokeText();restore();save();translate();rotate();fillStyle;fillText();lineWidth;strokeStyle;strokeText();restore();save();translate();rotate();fillStyle;fillText();lineWidth;strokeStyle;strokeText();restore();save();translate();rotate();fillStyle;fillText();lineWidth;strokeStyle;strokeText();restore();save();translate();rotate();fillStyle;fillText();lineWidth;strokeStyle;strokeText();restore();save();translate();rotate();fillStyle;fillText();lineWidth;strokeStyle;strokeText();restore();restore();restore();'; assert.equal(layer.getContext().getTrace(true), trace); }); @@ -325,7 +327,8 @@ suite('TextPath', function() { layer.add(textpath); stage.add(layer); - var trace = 'rotate();fillStyle;fillText();lineTo();restore();save();translate();rotate();fillStyle;fillText();lineTo();restore();save();translate();rotate();fillStyle;fillText();lineTo();restore();save();translate();rotate();fillStyle;fillText();lineTo();restore();save();translate();rotate();fillStyle;fillText();lineTo();restore();save();translate();rotate();fillStyle;fillText();lineTo();restore();save();translate();rotate();fillStyle;fillText();lineTo();restore();save();translate();rotate();fillStyle;fillText();lineTo();restore();save();translate();rotate();fillStyle;fillText();lineTo();restore();save();translate();rotate();fillStyle;fillText();lineTo();restore();save();translate();rotate();fillStyle;fillText();lineTo();restore();save();translate();rotate();fillStyle;fillText();lineTo();restore();save();translate();rotate();fillStyle;fillText();lineTo();restore();save();translate();rotate();fillStyle;fillText();lineTo();restore();stroke();restore();restore();'; + var trace = + 'rotate();fillStyle;fillText();lineTo();restore();save();translate();rotate();fillStyle;fillText();lineTo();restore();save();translate();rotate();fillStyle;fillText();lineTo();restore();save();translate();rotate();fillStyle;fillText();lineTo();restore();save();translate();rotate();fillStyle;fillText();lineTo();restore();save();translate();rotate();fillStyle;fillText();lineTo();restore();save();translate();rotate();fillStyle;fillText();lineTo();restore();save();translate();rotate();fillStyle;fillText();lineTo();restore();save();translate();rotate();fillStyle;fillText();lineTo();restore();save();translate();rotate();fillStyle;fillText();lineTo();restore();save();translate();rotate();fillStyle;fillText();lineTo();restore();save();translate();rotate();fillStyle;fillText();lineTo();restore();save();translate();rotate();fillStyle;fillText();lineTo();restore();save();translate();rotate();fillStyle;fillText();lineTo();restore();stroke();restore();restore();'; assert.equal(layer.getContext().getTrace(true), trace); });