From 5bb3482073afb274113b4c51ec5a7d95e2c56e6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sat, 2 Nov 2013 21:29:09 +0100 Subject: [PATCH] Bump version to v0.9.11 --- bower.json | 2 +- dist/paper-core.js | 472 ++++++++++++++++++++++++--------------- dist/paper-core.min.js | 16 +- dist/paper-full.js | 495 ++++++++++++++++++++++++----------------- dist/paper-full.min.js | 16 +- dist/paper-node.js | 387 +++++++++++++++++++------------- dist/paper.js | 495 ++++++++++++++++++++++++----------------- package.json | 2 +- 8 files changed, 1138 insertions(+), 747 deletions(-) diff --git a/bower.json b/bower.json index 52ec59a1..72c4a988 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "paper", - "version": "0.9.9", + "version": "0.9.11", "main": "dist/paper.js", "ignore": [ "build", diff --git a/dist/paper-core.js b/dist/paper-core.js index 84d8e75e..f90faf45 100644 --- a/dist/paper-core.js +++ b/dist/paper-core.js @@ -1,5 +1,5 @@ /*! - * Paper.js v0.9.10 - The Swiss Army Knife of Vector Graphics Scripting. + * Paper.js v0.9.11 - The Swiss Army Knife of Vector Graphics Scripting. * http://paperjs.org/ * * Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey @@ -9,7 +9,7 @@ * * All rights reserved. * - * Date: Tue Oct 29 21:56:00 2013 +0100 + * Date: Sat Nov 2 21:26:32 2013 +0100 * *** * @@ -466,31 +466,33 @@ Base.inject({ : res; }, - deserialize: function(obj, data) { - var res = obj; - data = data || {}; - if (Array.isArray(obj)) { - var type = obj[0], + deserialize: function(json, target, _data) { + var res = json; + _data = _data || {}; + if (Array.isArray(json)) { + var type = json[0], isDictionary = type === 'dictionary'; if (!isDictionary) { - if (data.dictionary && obj.length == 1 && /^#/.test(type)) - return data.dictionary[type]; + if (_data.dictionary && json.length == 1 && /^#/.test(type)) + return _data.dictionary[type]; type = Base.exports[type]; } res = []; - for (var i = type ? 1 : 0, l = obj.length; i < l; i++) - res.push(Base.deserialize(obj[i], data)); + for (var i = type ? 1 : 0, l = json.length; i < l; i++) + res.push(Base.deserialize(json[i], null, _data)); if (isDictionary) { - data.dictionary = res[0]; + _data.dictionary = res[0]; } else if (type) { var args = res; - res = Base.create(type.prototype); + res = target instanceof type + ? target + : Base.create(type.prototype); type.apply(res, args); } - } else if (Base.isPlainObject(obj)) { + } else if (Base.isPlainObject(json)) { res = {}; - for (var key in obj) - res[key] = Base.deserialize(obj[key], data); + for (var key in json) + res[key] = Base.deserialize(json[key], null, _data); } return res; }, @@ -499,9 +501,9 @@ Base.inject({ return JSON.stringify(Base.serialize(obj, options)); }, - importJSON: function(json) { + importJSON: function(json, target) { return Base.deserialize( - typeof json === 'string' ? JSON.parse(json) : json); + typeof json === 'string' ? JSON.parse(json) : json, target); }, splice: function(list, items, index, remove) { @@ -682,7 +684,7 @@ var PaperScope = Base.extend({ } }, - version: '0.9.10', + version: '0.9.11', getView: function() { return this.project && this.project.view; @@ -694,6 +696,10 @@ var PaperScope = Base.extend({ return this._tool; }, + getPaper: function() { + return this; + }, + evaluate: function(code) { var res = paper.PaperScript.evaluate(code, this); View.updateFocus(); @@ -2009,10 +2015,10 @@ var Matrix = Base.extend({ return !this._getDeterminant(); }, - transform: function( src, srcOff, dst, dstOff, numPts) { + transform: function( src, srcOffset, dst, dstOffset, count) { return arguments.length < 5 ? this._transformPoint(Point.read(arguments)) - : this._transformCoordinates(src, srcOff, dst, dstOff, numPts); + : this._transformCoordinates(src, srcOffset, dst, dstOffset, count); }, _transformPoint: function(point, dest, dontNotify) { @@ -2027,10 +2033,11 @@ var Matrix = Base.extend({ ); }, - _transformCoordinates: function(src, srcOff, dst, dstOff, numPts) { - var i = srcOff, j = dstOff, - srcEnd = srcOff + 2 * numPts; - while (i < srcEnd) { + _transformCoordinates: function(src, srcOffset, dst, dstOffset, count) { + var i = srcOffset, + j = dstOffset, + max = i + 2 * count; + while (i < max) { var x = src[i++], y = src[i++]; dst[j++] = x * this._a + y * this._b + this._tx; @@ -2736,6 +2743,10 @@ var Item = Base.extend(Callback, { hasStroke: function() { return this.getStyle().hasStroke(); + }, + + hasShadow: function() { + return this.getStyle().hasShadow(); } }, Base.each(['locked', 'visible', 'blendMode', 'opacity', 'guide'], function(name) { @@ -3251,7 +3262,10 @@ var Item = Base.extend(Callback, { }, { importJSON: function(json) { - return this.addChild(Base.importJSON(json)); + var res = Base.importJSON(json, this); + return res !== this + ? this.addChild(res) + : res; }, addChild: function(item, _preserve) { @@ -3387,6 +3401,8 @@ var Item = Base.extend(Callback, { return removed; }, + clear: '#removeChildren', + reverseChildren: function() { if (this._children) { this._children.reverse(); @@ -3561,43 +3577,49 @@ var Item = Base.extend(Callback, { _setStyles: function(ctx) { var style = this._style, - matrix = this._matrix, - strokeWidth = style.getStrokeWidth(), fillColor = style.getFillColor(), strokeColor = style.getStrokeColor(), shadowColor = style.getShadowColor(); if (fillColor) - ctx.fillStyle = fillColor.toCanvasStyle(ctx, matrix); - if (strokeColor && strokeWidth > 0) { - ctx.strokeStyle = strokeColor.toCanvasStyle(ctx, matrix); - ctx.lineWidth = strokeWidth; - var strokeJoin = style.getStrokeJoin(), - strokeCap = style.getStrokeCap(), - miterLimit = style.getMiterLimit(), - dashArray = style.getDashArray(), - dashOffset = style.getDashOffset(); - if (strokeJoin) - ctx.lineJoin = strokeJoin; - if (strokeCap) - ctx.lineCap = strokeCap; - if (miterLimit) - ctx.miterLimit = miterLimit; - if (paper.support.nativeDash && dashArray && dashArray.length) { - if ('setLineDash' in ctx) { - ctx.setLineDash(dashArray); - ctx.lineDashOffset = dashOffset; - } else { - ctx.mozDash = dashArray; - ctx.mozDashOffset = dashOffset; + ctx.fillStyle = fillColor.toCanvasStyle(ctx); + if (strokeColor) { + var strokeWidth = style.getStrokeWidth(); + if (strokeWidth > 0) { + ctx.strokeStyle = strokeColor.toCanvasStyle(ctx); + ctx.lineWidth = strokeWidth; + var strokeJoin = style.getStrokeJoin(), + strokeCap = style.getStrokeCap(), + miterLimit = style.getMiterLimit(); + if (strokeJoin) + ctx.lineJoin = strokeJoin; + if (strokeCap) + ctx.lineCap = strokeCap; + if (miterLimit) + ctx.miterLimit = miterLimit; + if (paper.support.nativeDash) { + var dashArray = style.getDashArray(), + dashOffset = style.getDashOffset(); + if (dashArray && dashArray.length) { + if ('setLineDash' in ctx) { + ctx.setLineDash(dashArray); + ctx.lineDashOffset = dashOffset; + } else { + ctx.mozDash = dashArray; + ctx.mozDashOffset = dashOffset; + } + } } } } if (shadowColor) { - ctx.shadowColor = shadowColor.toCanvasStyle(ctx); - ctx.shadowBlur = style.getShadowBlur(); - var offset = this.getShadowOffset(); - ctx.shadowOffsetX = offset.x; - ctx.shadowOffsetY = offset.y; + var shadowBlur = style.getShadowBlur(); + if (shadowBlur > 0) { + ctx.shadowColor = shadowColor.toCanvasStyle(ctx); + ctx.shadowBlur = shadowBlur; + var offset = this.getShadowOffset(); + ctx.shadowOffsetX = offset.x; + ctx.shadowOffsetY = offset.y; + } } }, @@ -3894,8 +3916,8 @@ var Shape = Item.extend({ radius: this._radius, insert: false }); - path.transform(this._matrix); path.setStyle(this._style); + path.transform(this._matrix); if (insert || insert === undefined) path.insertAbove(this); return path; @@ -3951,8 +3973,10 @@ var Shape = Item.extend({ } if (!clip && (hasFill || hasStroke)) { this._setStyles(ctx); - if (hasFill) + if (hasFill) { ctx.fill(style.getWindingRule()); + ctx.shadowColor = 'rgba(0,0,0,0)'; + } if (hasStroke) ctx.stroke(); } @@ -5912,7 +5936,7 @@ var PathItem = Item.extend({ setPathData: function(data) { - var parts = data.match(/[a-z][^a-z]*/ig), + var parts = data.match(/[mlhvcsqtaz][^mlhvcsqtaz]*/ig), coords, relative = false, control, @@ -5934,18 +5958,15 @@ var PathItem = Item.extend({ ); } - if (this._type === 'path') - this.removeSegments(); - else - this.removeChildren(); + this.clear(); for (var i = 0, l = parts.length; i < l; i++) { var part = parts[i], cmd = part[0], lower = cmd.toLowerCase(); - coords = part.slice(1).trim().split(/[\s,]+|(?=[+-])/); + coords = part.match(/[+-]?(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?/g); + var length = coords && coords.length; relative = cmd === lower; - var length = coords.length; switch (lower) { case 'm': case 'l': @@ -6304,6 +6325,8 @@ var Path = PathItem.extend({ return removed; }, + clear: '#removeSegments', + isFullySelected: function() { var length = this._segments.length; return this._selected && length > 0 && this._selectedSegmentState @@ -6899,8 +6922,10 @@ var Path = PathItem.extend({ if (!clip && !compound && (hasFill || hasStroke)) { this._setStyles(ctx); - if (hasFill) + if (hasFill) { ctx.fill(style.getWindingRule()); + ctx.shadowColor = 'rgba(0,0,0,0)'; + } if (hasStroke) { if (dashLength) { ctx.beginPath(); @@ -7057,16 +7082,16 @@ var Path = PathItem.extend({ cubicCurveTo: function() { var handle1 = Point.read(arguments), handle2 = Point.read(arguments), - to = Point.read(arguments); - var current = getCurrentSegment(this); + to = Point.read(arguments), + current = getCurrentSegment(this); current.setHandleOut(handle1.subtract(current._point)); this._add([ new Segment(to, handle2.subtract(to)) ]); }, quadraticCurveTo: function() { var handle = Point.read(arguments), - to = Point.read(arguments); - var current = getCurrentSegment(this)._point; + to = Point.read(arguments), + current = getCurrentSegment(this)._point; this.cubicCurveTo( handle.add(current.subtract(handle).multiply(1 / 3)), handle.add(to.subtract(handle).multiply(1 / 3)), @@ -7145,25 +7170,41 @@ var Path = PathItem.extend({ this._add(segments); }, - lineBy: function(vector) { - vector = Point.read(arguments); - var current = getCurrentSegment(this); - this.lineTo(current._point.add(vector)); + lineBy: function() { + var to = Point.read(arguments), + current = getCurrentSegment(this)._point; + this.lineTo(current.add(to)); }, - curveBy: function(throughVector, toVector, parameter) { - throughVector = Point.read(throughVector); - toVector = Point.read(toVector); - var current = getCurrentSegment(this)._point; - this.curveTo(current.add(throughVector), current.add(toVector), - parameter); + curveBy: function() { + var through = Point.read(arguments), + to = Point.read(arguments), + parameter = Base.read(arguments), + current = getCurrentSegment(this)._point; + this.curveTo(current.add(through), current.add(to), parameter); }, - arcBy: function(throughVector, toVector) { - throughVector = Point.read(throughVector); - toVector = Point.read(toVector); - var current = getCurrentSegment(this)._point; - this.arcTo(current.add(throughVector), current.add(toVector)); + cubicCurveBy: function() { + var handle1 = Point.read(arguments), + handle2 = Point.read(arguments), + to = Point.read(arguments), + current = getCurrentSegment(this)._point; + this.cubicCurveTo(current.add(handle1), current.add(handle2), + current.add(to)); + }, + + quadraticCurveBy: function() { + var handle = Point.read(arguments), + to = Point.read(arguments), + current = getCurrentSegment(this)._point; + this.quadraticCurveTo(current.add(handle), current.add(to)); + }, + + arcBy: function() { + var through = Point.read(arguments), + to = Point.read(arguments), + current = getCurrentSegment(this)._point; + this.arcTo(current.add(through), current.add(to)); }, closePath: function() { @@ -7644,8 +7685,10 @@ var CompoundPath = PathItem.extend({ if (!param.clip) { this._setStyles(ctx); var style = this._style; - if (style.hasFill()) + if (style.hasFill()) { ctx.fill(style.getWindingRule()); + ctx.shadowColor = 'rgba(0,0,0,0)'; + } if (style.hasStroke()) ctx.stroke(); } @@ -7674,13 +7717,15 @@ var CompoundPath = PathItem.extend({ } }; - Base.each(['lineTo', 'cubicCurveTo', 'quadraticCurveTo', 'curveTo', - 'arcTo', 'lineBy', 'curveBy', 'arcBy'], function(key) { - fields[key] = function() { - var path = getCurrentPath(this); - path[key].apply(path, arguments); - }; - }); + Base.each(['lineTo', 'cubicCurveTo', 'quadraticCurveTo', 'curveTo', 'arcTo', + 'lineBy', 'cubicCurveBy', 'quadraticCurveBy', 'curveBy', 'arcBy'], + function(key) { + fields[key] = function() { + var path = getCurrentPath(this); + path[key].apply(path, arguments); + }; + } + ); return fields; }); @@ -8212,13 +8257,18 @@ var PointText = TextItem.extend({ this._setStyles(ctx); var style = this._style, lines = this._lines, - leading = style.getLeading(); + leading = style.getLeading(), + shadowColor = ctx.shadowColor; + ctx.font = style.getFontStyle(); ctx.textAlign = style.getJustification(); for (var i = 0, l = lines.length; i < l; i++) { + ctx.shadowColor = shadowColor; var line = lines[i]; - if (style.hasFill()) + if (style.hasFill()) { ctx.fillText(line, 0, 0); + ctx.shadowColor = 'rgba(0,0,0,0)'; + } if (style.hasStroke()) ctx.strokeText(line, 0, 0); ctx.translate(0, leading); @@ -8597,7 +8647,7 @@ var Color = Base.extend(new function() { }, clone: function() { - return new Color(this._type, this._components.slice(), this._alpha); + return new Color(this); }, _convert: function(type) { @@ -8685,23 +8735,21 @@ var Color = Base.extend(new function() { + components.join(',') + ')'; }, - toCanvasStyle: function(ctx, matrix) { + toCanvasStyle: function(ctx) { if (this._canvasStyle) return this._canvasStyle; if (this._type !== 'gradient') return this._canvasStyle = this.toCSS(); var components = this._components, - translation = matrix ? matrix.getTranslation() : new Point(), gradient = components[0], stops = gradient._stops, - origin = components[1].subtract(translation), - destination = components[2].subtract(translation), + origin = components[1], + destination = components[2], canvasGradient; if (gradient._radial) { var radius = destination.getDistance(origin), highlight = components[3]; if (highlight) { - highlight = highlight.subtract(translation); var vector = highlight.subtract(origin); if (vector.getLength() > radius) highlight = origin.add(vector.normalize(radius - 0.1)); @@ -9027,8 +9075,11 @@ var Style = Base.extend(new function() { if (isColor) { if (old) delete old._owner; - if (value && value.constructor === Color) + if (value && value.constructor === Color) { + if (value._owner) + value = value.clone(); value._owner = this._item; + } } this._values[key] = value; if (this._item) @@ -9118,6 +9169,10 @@ var Style = Base.extend(new function() { return !!this.getStrokeColor() && this.getStrokeWidth() > 0; }, + hasShadow: function() { + return !!this.getShadowColor() && this.getShadowBlur() > 0; + }, + getLeading: function getLeading() { var leading = getLeading.base.call(this); return leading != null ? leading : this.getFontSize() * 1.2; @@ -9377,18 +9432,10 @@ var DomEvent = { }; DomEvent.requestAnimationFrame = new function() { - var part = 'equestAnimationFrame', - request = window['r' + part] || window['webkitR' + part] - || window['mozR' + part] || window['oR' + part] - || window['msR' + part]; - if (request) { - request(function(time) { - if (time == null) - request = null; - }); - } - - var callbacks = [], + var nativeRequest = DomElement.getPrefixValue(window, + 'requestAnimationFrame'), + requested = false, + callbacks = [], focused = true, timer; @@ -9401,24 +9448,36 @@ DomEvent.requestAnimationFrame = new function() { } }); - return function(callback, element) { - if (request) - return request(callback, element); - callbacks.push([callback, element]); - if (timer) - return; - timer = setInterval(function() { - for (var i = callbacks.length - 1; i >= 0; i--) { - var entry = callbacks[i], - func = entry[0], - el = entry[1]; - if (!el || (PaperScope.getAttribute(el, 'keepalive') == 'true' - || focused) && DomElement.isInView(el)) { - callbacks.splice(i, 1); - func(Date.now()); - } + function handleCallbacks() { + for (var i = callbacks.length - 1; i >= 0; i--) { + var entry = callbacks[i], + func = entry[0], + el = entry[1]; + if (!el || (PaperScope.getAttribute(el, 'keepalive') == 'true' + || focused) && DomElement.isInView(el)) { + callbacks.splice(i, 1); + func(); } - }, 1000 / 60); + } + if (nativeRequest) { + if (callbacks.length) { + nativeRequest(handleCallbacks); + } else { + requested = false; + } + } + } + + return function(callback, element) { + callbacks.push([callback, element]); + if (nativeRequest) { + if (!requested) { + nativeRequest(handleCallbacks); + requested = true; + } + } else if (!timer) { + timer = setInterval(handleCallbacks, 1000 / 60); + } }; }; @@ -10005,6 +10064,7 @@ var Key = new function() { tool = scope && scope._tool; keyMap[key] = down; if (tool && tool.responds(type)) { + paper = scope; tool.fire(type, new KeyEvent(down, key, character, event)); if (view) view.draw(true); @@ -10327,6 +10387,28 @@ var Tool = PaperScopeItem.extend({ }); +var Http = { + request: function(method, url, callback) { + var xhr = new (window.ActiveXObject || XMLHttpRequest)( + 'Microsoft.XMLHTTP'); + xhr.open(method.toUpperCase(), url, true); + if ('overrideMimeType' in xhr) + xhr.overrideMimeType('text/plain'); + xhr.onreadystatechange = function() { + if (xhr.readyState === 4) { + var status = xhr.status; + if (status === 0 || status === 200) { + callback.call(xhr, xhr.responseText); + } else { + throw new Error('Could not load ' + url + ' (Error ' + + status + ')'); + } + } + }; + return xhr.send(null); + } +}; + var CanvasProvider = { canvases: [], @@ -10702,13 +10784,13 @@ new function() { return attrs; } - function exportGroup(item) { + function exportGroup(item, options) { var attrs = getTransform(item), children = item._children; var node = createElement('g', attrs); for (var i = 0, l = children.length; i < l; i++) { var child = children[i]; - var childNode = exportSVG(child); + var childNode = exportSVG(child, options); if (childNode) { if (child.isClipMask()) { var clip = createElement('clipPath'); @@ -10736,7 +10818,12 @@ new function() { return createElement('image', attrs); } - function exportPath(item) { + function exportPath(item, options) { + if (options.matchShapes) { + var shape = item.toShape(false); + if (shape) + return exportShape(shape, options); + } var segments = item._segments, type, attrs; @@ -10772,7 +10859,6 @@ new function() { function exportShape(item) { var shape = item._shape, - center = item.getPosition(true), radius = item._radius, attrs = getTransform(item, true, shape !== 'rectangle'); if (shape === 'rectangle') { @@ -10806,7 +10892,7 @@ new function() { return createElement('path', attrs); } - function exportPlacedSymbol(item) { + function exportPlacedSymbol(item, options) { var attrs = getTransform(item, true), symbol = item.getSymbol(), symbolNode = getDefinition(symbol, 'symbol'), @@ -10816,7 +10902,7 @@ new function() { symbolNode = createElement('symbol', { viewBox: formatter.rectangle(bounds) }); - symbolNode.appendChild(exportSVG(definition)); + symbolNode.appendChild(exportSVG(definition, options)); setDefinition(symbol, symbolNode, 'symbol'); } attrs.href = '#' + symbolNode.id; @@ -10827,7 +10913,7 @@ new function() { return createElement('use', attrs); } - function exportGradient(color, item) { + function exportGradient(color) { var gradientNode = getDefinition(color, 'color'); if (!gradientNode) { var gradient = color.getGradient(), @@ -10951,29 +11037,31 @@ new function() { } function exportDefinitions(node, options) { - if (!definitions) - return node; - var svg = node.nodeName.toLowerCase() === 'svg' && node, + var svg = node, defs = null; - for (var i in definitions.svgs) { - if (!defs) { - if (!svg) { - svg = createElement('svg'); - svg.appendChild(node); + if (definitions) { + svg = node.nodeName.toLowerCase() === 'svg' && node; + for (var i in definitions.svgs) { + if (!defs) { + if (!svg) { + svg = createElement('svg'); + svg.appendChild(node); + } + defs = svg.insertBefore(createElement('defs'), + svg.firstChild); } - defs = svg.insertBefore(createElement('defs'), svg.firstChild); + defs.appendChild(definitions.svgs[i]); } - defs.appendChild(definitions.svgs[i]); + definitions = null; } - definitions = null; return options.asString ? new XMLSerializer().serializeToString(svg) : svg; } - function exportSVG(item) { + function exportSVG(item, options) { var exporter = exporters[item._type], - node = exporter && exporter(item, item._type); + node = exporter && exporter(item, options); if (node && item._data) node.setAttribute('data-paper-data', JSON.stringify(item._data)); return node && applyStyle(item, node); @@ -10989,7 +11077,7 @@ new function() { Item.inject({ exportSVG: function(options) { options = setOptions(options); - return exportDefinitions(exportSVG(this), options); + return exportDefinitions(exportSVG(this, options), options); } }); @@ -11008,7 +11096,7 @@ new function() { 'xmlns:xlink': 'http://www.w3.org/1999/xlink' }); for (var i = 0, l = layers.length; i < l; i++) - node.appendChild(exportSVG(layers[i])); + node.appendChild(exportSVG(layers[i], options)); return exportDefinitions(node, options); } }); @@ -11037,15 +11125,15 @@ new function() { function getPoint(node, x, y, allowNull) { x = getValue(node, x, false, allowNull); y = getValue(node, y, false, allowNull); - return allowNull && x == null && y == null ? null - : new Point(x || 0, y || 0); + return allowNull && (x == null || y == null) ? null + : new Point(x, y); } function getSize(node, w, h, allowNull) { w = getValue(node, w, false, allowNull); h = getValue(node, h, false, allowNull); - return allowNull && w == null && h == null ? null - : new Size(w || 0, h || 0); + return allowNull && (w == null || h == null) ? null + : new Size(w, h); } function convertValue(value, type, lookup) { @@ -11062,7 +11150,7 @@ new function() { : value; } - function importGroup(node, type, options) { + function importGroup(node, type, isRoot, options) { var nodes = node.childNodes, clip = type === 'clippath', item = new Group(), @@ -11071,20 +11159,20 @@ new function() { children = []; if (!clip) { item._transformContent = false; - item = applyAttributes(item, node); + item = applyAttributes(item, node, isRoot); project._currentStyle = item._style.clone(); } for (var i = 0, l = nodes.length; i < l; i++) { var childNode = nodes[i], child; if (childNode.nodeType === 1 - && (child = importSVG(childNode, options)) + && (child = importSVG(childNode, false, options)) && !(child instanceof Symbol)) children.push(child); } item.addChildren(children); if (clip) - item = applyAttributes(item.reduce(), node); + item = applyAttributes(item.reduce(), node, isRoot); project._currentStyle = currentStyle; if (clip || type === 'defs') { item.remove(); @@ -11138,8 +11226,8 @@ new function() { } var importers = { - '#document': function(node, type, options) { - return importSVG(node.childNodes[0], options); + '#document': function(node, type, isRoot, options) { + return importSVG(node.childNodes[0], isRoot, options); }, g: importGroup, @@ -11161,8 +11249,8 @@ new function() { return raster; }, - symbol: function(node, type) { - return new Symbol(importGroup(node, type), true); + symbol: function(node, type, isRoot, options) { + return new Symbol(importGroup(node, type, isRoot, options), true); }, defs: importGroup, @@ -11256,8 +11344,13 @@ new function() { var attributes = Base.merge(Base.each(SVGStyles, function(entry) { this[entry.attribute] = function(item, value) { - item[entry.set]( - convertValue(value, entry.type, entry.fromSVG)); + item[entry.set](convertValue(value, entry.type, entry.fromSVG)); + if (entry.type === 'color' && item instanceof Shape) { + var color = item[entry.get](); + if (color) + color.transform(new Matrix().translate( + item.getPosition(true).negate())); + } }; }, {}), { id: function(item, value) { @@ -11343,10 +11436,10 @@ new function() { : value; } - function applyAttributes(item, node) { + function applyAttributes(item, node, isRoot) { var styles = { node: DomElement.getStyles(node) || {}, - parent: DomElement.getStyles(node.parentNode) || {} + parent: !isRoot && DomElement.getStyles(node.parentNode) || {} }; Base.each(attributes, function(apply, name) { var value = getAttribute(node, name, styles); @@ -11362,38 +11455,55 @@ new function() { return match && definitions[match[1]]; } - function importSVG(node, options, clearDefs) { + function importSVG(node, isRoot, options) { if (!options) options = {}; - if (typeof node === 'string') + if (typeof node === 'string') { + if (isRoot && !/^.*d;d++){var m=l[d],v=m[1];u(m[0],{get:e["get"+v]||e["is"+v],set:e["set"+v]},!0)}}return e}function n(i,n,r,s){try{i&&(s||t===s&&c(i)?u:l).call(i,n,r=r||i)}catch(a){if(a!==e.stop)throw a}return r}function r(t){return n(t,function(t,e){this[e]=t},new t.constructor)}var s=/^(statics|generics|preserve|enumerable|prototype|toString|valueOf)$/,a=Object.prototype.toString,h=Array.prototype,o=h.slice,u=h.forEach||function(t,e){for(var i=0,n=this.length;n>i;i++)t.call(e,this[i],i,this)},l=function(t,e){for(var i in this)this.hasOwnProperty(i)&&t.call(e,this[i],i,this)},c=Array.isArray=Array.isArray||function(t){return"[object Array]"===a.call(t)},d=Object.create||function(t){return{__proto__:t}},_=Object.getOwnPropertyDescriptor||function(t,e){var i=t.__lookupGetter__&&t.__lookupGetter__(e);return i?{get:i,set:t.__lookupSetter__(e),enumerable:!0,configurable:!0}:t.hasOwnProperty(e)?{value:t[e],enumerable:!0,configurable:!0,writable:!0}:null},f=Object.defineProperty||function(t,e,i){return(i.get||i.set)&&t.__defineGetter__?(i.get&&t.__defineGetter__(e,i.get),i.set&&t.__defineSetter__(e,i.set)):t[e]=i.value,t},g=function(t,e,i){return delete t[e],f(t,e,i)};return i(function(){},{inject:function(t){if(t){var e=this.prototype,n=Object.getPrototypeOf(e).constructor,r=t.statics===!0?t:t.statics;r!=t&&i(e,t,t.enumerable,n&&n.prototype,t.preserve,t.generics&&this),i(this,r,!0,n,t.preserve)}for(var s=1,a=arguments.length;a>s;s++)this.inject(arguments[s]);return this},extend:function(){for(var t,e=this,n=0,r=arguments.length;r>n&&!(t=arguments[n].initialize);n++);return t=t||function(){e.apply(this,arguments)},t.prototype=d(this.prototype),g(t.prototype,"constructor",{value:t,writable:!0,configurable:!0}),i(t,this,!0),arguments.length?this.inject.apply(t,arguments):t}},!0).inject({inject:function(){for(var t=0,e=arguments.length;e>t;t++)i(this,arguments[t],arguments[t].enumerable);return this},extend:function(){var t=d(this);return t.inject.apply(t,arguments)},each:function(t,e){return n(this,t,e)},clone:function(){return r(this)},statics:{each:n,clone:r,create:d,define:g,describe:_,isPlainObject:function(t){var i=null!=t&&t.constructor;return i&&(i===Object||i===e||"Object"===i.name)},pick:function(){for(var e=0,i=arguments.length;i>e;e++)if(arguments[e]!==t)return arguments[e];return null},stop:{}}})};"undefined"!=typeof module&&(module.exports=e),e.inject({generics:!0,clone:function(){return new this.constructor(this)},toString:function(){return null!=this._id?(this._class||"Object")+(this._name?" '"+this._name+"'":" @"+this._id):"{ "+e.each(this,function(t,e){if(!/^_/.test(e)){var i=typeof t;this.push(e+": "+("number"===i?a.instance.number(t):"string"===i?"'"+t+"'":t))}},[]).join(", ")+" }"},exportJSON:function(t){return e.exportJSON(this,t)},toJSON:function(){return e.serialize(this)},_set:function(i,n){if(i&&e.isPlainObject(i)){var r=i._filtering||i;for(var s in r)if(s in this&&r.hasOwnProperty(s)&&(!n||!n[s])){var a=i[s];a!==t&&(this[s]=a)}return!0}},statics:{exports:{},extend:function ee(){var t=ee.base.apply(this,arguments),i=t.prototype._class;return i&&!e.exports[i]&&(e.exports[i]=t),t},equals:function(t,i){function n(t,e){for(var i in t)if(t.hasOwnProperty(i)&&!e.hasOwnProperty(i))return!1;return!0}if(t===i)return!0;if(t&&t.equals)return t.equals(i);if(i&&i.equals)return i.equals(t);if(Array.isArray(t)&&Array.isArray(i)){if(t.length!==i.length)return!1;for(var r=0,s=t.length;s>r;r++)if(!e.equals(t[r],i[r]))return!1;return!0}if(t&&"object"==typeof t&&i&&"object"==typeof i){if(!n(t,i)||!n(i,t))return!1;for(var r in t)if(t.hasOwnProperty(r)&&!e.equals(t[r],i[r]))return!1;return!0}return!1},read:function(t,i,n,r){if(this===e){var s=this.peek(t,i);return t._index++,t.__read=1,s}var a=this.prototype,h=a._readIndex,o=i||h&&t._index||0;n||(n=t.length-o);var u=t[o];return u instanceof this||r&&r.readNull&&null==u&&1>=n?(h&&(t._index=o+1),u&&r&&r.clone?u.clone():u):(u=e.create(this.prototype),h&&(u.__read=!0),r&&(u.__options=r),u=u.initialize.apply(u,o>0||ns;s++)r.push(Array.isArray(n=t[s])?this.read(n,0,0,i):this.read(t,s,1,i));return r},readNamed:function(i,n,r,s,a){var h=this.getNamed(i,n),o=h!==t;if(o){var u=i._filtered;u||(u=i._filtered=e.create(i[0]),u._filtering=i[0]),u[n]=t}return this.read(o?[h]:i,r,s,a)},getNamed:function(i,n){var r=i[0];return i._hasObject===t&&(i._hasObject=1===i.length&&e.isPlainObject(r)),i._hasObject?n?r[n]:i._filtered||r:t},hasNamed:function(t,e){return!!this.getNamed(t,e)},isPlainValue:function(t){return this.isPlainObject(t)||Array.isArray(t)},serialize:function(t,i,n,r){i=i||{};var s,h=!r;if(h&&(i.formatter=new a(i.precision),r={length:0,definitions:{},references:{},add:function(t,e){var i="#"+t._id,n=this.references[i];if(!n){this.length++;var r=e.call(t),s=t._class;s&&r[0]!==s&&r.unshift(s),this.definitions[i]=r,n=this.references[i]=[i]}return n}}),t&&t._serialize){s=t._serialize(i,r);var o=t._class;!o||n||s._compact||s[0]===o||s.unshift(o)}else if(Array.isArray(t)){s=[];for(var u=0,l=t.length;l>u;u++)s[u]=e.serialize(t[u],i,n,r);n&&(s._compact=!0)}else if(e.isPlainObject(t)){s={};for(var u in t)t.hasOwnProperty(u)&&(s[u]=e.serialize(t[u],i,n,r))}else s="number"==typeof t?i.formatter.number(t,i.precision):t;return h&&r.length>0?[["dictionary",r.definitions],s]:s},deserialize:function(t,i){var n=t;if(i=i||{},Array.isArray(t)){var r=t[0],s="dictionary"===r;if(!s){if(i.dictionary&&1==t.length&&/^#/.test(r))return i.dictionary[r];r=e.exports[r]}n=[];for(var a=r?1:0,h=t.length;h>a;a++)n.push(e.deserialize(t[a],i));if(s)i.dictionary=n[0];else if(r){var o=n;n=e.create(r.prototype),r.apply(n,o)}}else if(e.isPlainObject(t)){n={};for(var u in t)n[u]=e.deserialize(t[u],i)}return n},exportJSON:function(t,i){return JSON.stringify(e.serialize(t,i))},importJSON:function(t){return e.deserialize("string"==typeof t?JSON.parse(t):t)},splice:function(e,i,n,r){var s=i&&i.length,a=n===t;n=a?e.length:n,n>e.length&&(n=e.length);for(var h=0;s>h;h++)i[h]._index=n+h;if(a)return e.push.apply(e,i),[];var o=[n,r];i&&o.push.apply(o,i);for(var u=e.splice.apply(e,o),h=0,l=u.length;l>h;h++)delete u[h]._index;for(var h=n+s,l=e.length;l>h;h++)e[h]._index=h;return u},merge:function(){return e.each(arguments,function(t){e.each(t,function(t,e){this[e]=t},this)},new e,!0)},capitalize:function(t){return t.replace(/\b[a-z]/g,function(t){return t.toUpperCase()})},camelize:function(t){return t.replace(/-(.)/g,function(t,e){return e.toUpperCase()})},hyphenate:function(t){return t.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}}});var n={attach:function(i,n){if("string"!=typeof i)return e.each(i,function(t,e){this.attach(e,t)},this),t;var r=this._eventTypes[i];if(r){var s=this._handlers=this._handlers||{};s=s[i]=s[i]||[],-1==s.indexOf(n)&&(s.push(n),r.install&&1==s.length&&r.install.call(this,i))}},detach:function(i,n){if("string"!=typeof i)return e.each(i,function(t,e){this.detach(e,t)},this),t;var r,s=this._eventTypes[i],a=this._handlers&&this._handlers[i];s&&a&&(!n||-1!=(r=a.indexOf(n))&&1==a.length?(s.uninstall&&s.uninstall.call(this,i),delete this._handlers[i]):-1!=r&&a.splice(r,1))},once:function(t,e){this.attach(t,function(){e.apply(this,arguments),this.detach(t,e)})},fire:function(t,i){var n=this._handlers&&this._handlers[t];if(!n)return!1;var r=[].slice.call(arguments,1);return e.each(n,function(t){t.apply(this,r)===!1&&i&&i.stop&&i.stop()},this),!0},responds:function(t){return!(!this._handlers||!this._handlers[t])},on:"#attach",off:"#detach",trigger:"#fire",statics:{inject:function ie(){for(var t=0,i=arguments.length;i>t;t++){var n=arguments[t],r=n._events;if(r){var s={};e.each(r,function(t,i){var r="string"==typeof t,a=r?t:i,h=e.capitalize(a),o=a.substring(2).toLowerCase();s[o]=r?{}:t,a="_"+a,n["get"+h]=function(){return this[a]},n["set"+h]=function(t){t?this.attach(o,t):this[a]&&this.detach(o,this[a]),this[a]=t}}),n._eventTypes=s}ie.base.call(this,n)}return this}}},r=e.extend({_class:"PaperScope",initialize:function ne(t){if(paper=this,this.project=null,this.projects=[],this.tools=[],this.palettes=[],this._id=t&&(t.getAttribute("id")||t.src)||"paperscope-"+ne._id++,t&&t.setAttribute("id",this._id),ne._scopes[this._id]=this,!this.support){var e=$.getContext(1,1);ne.prototype.support={nativeDash:"setLineDash"in e||"mozDash"in e,nativeBlendModes:K.nativeModes},$.release(e)}},version:"0.9.10",getView:function(){return this.project&&this.project.view},getTool:function(){return this._tool||(this._tool=new U),this._tool},evaluate:function(t){var e=paper.PaperScript.evaluate(t,this);return Z.updateFocus(),e},install:function(t){var i=this;e.each(["project","view","tool"],function(n){e.define(t,n,{configurable:!0,get:function(){return i[n]}})});for(var n in this)/^(version|_id)/.test(n)||(t[n]=this[n])},setup:function(t){return paper=this,this.project=new v(t),this},activate:function(){paper=this},clear:function(){for(var t=this.projects.length-1;t>=0;t--)this.projects[t].remove();for(var t=this.tools.length-1;t>=0;t--)this.tools[t].remove();for(var t=this.palettes.length-1;t>=0;t--)this.palettes[t].remove()},remove:function(){this.clear(),delete r._scopes[this._id]},statics:new function(){function t(t){return t+="Attribute",function(e,i){return e[t](i)||e[t]("data-paper-"+i)}}return{_scopes:{},_id:0,get:function(t){return"object"==typeof t&&(t=t.getAttribute("id")),this._scopes[t]||null},getAttribute:t("get"),hasAttribute:t("has")}}}),s=e.extend(n,{initialize:function(t){this._scope=paper,this._index=this._scope[this._list].push(this)-1,(t||!this._scope[this._reference])&&this.activate()},activate:function(){if(!this._scope)return!1;var t=this._scope[this._reference];return t&&t!=this&&t.fire("deactivate"),this._scope[this._reference]=this,this.fire("activate",t),!0},isActive:function(){return this._scope[this._reference]===this},remove:function(){return null==this._index?!1:(e.splice(this._scope[this._list],null,this._index,1),this._scope[this._reference]==this&&(this._scope[this._reference]=null),this._scope=null,!0)}}),a=e.extend({initialize:function(t){this.precision=t||5,this.multiplier=Math.pow(10,this.precision)},number:function(t){return Math.round(t*this.multiplier)/this.multiplier},point:function(t,e){return this.number(t.x)+(e||",")+this.number(t.y)},size:function(t,e){return this.number(t.width)+(e||",")+this.number(t.height)},rectangle:function(t,e){return this.point(t,e)+(e||",")+this.size(t,e)}});a.instance=new a;var h=new function(){var e=[[.5773502691896257],[0,.7745966692414834],[.33998104358485626,.8611363115940526],[0,.5384693101056831,.906179845938664],[.2386191860831969,.6612093864662645,.932469514203152],[0,.4058451513773972,.7415311855993945,.9491079123427585],[.1834346424956498,.525532409916329,.7966664774136267,.9602898564975363],[0,.3242534234038089,.6133714327005904,.8360311073266358,.9681602395076261],[.14887433898163122,.4333953941292472,.6794095682990244,.8650633666889845,.9739065285171717],[0,.26954315595234496,.5190961292068118,.7301520055740494,.8870625997680953,.978228658146057],[.1252334085114689,.3678314989981802,.5873179542866175,.7699026741943047,.9041172563704749,.9815606342467192],[0,.2304583159551348,.44849275103644687,.6423493394403402,.8015780907333099,.9175983992229779,.9841830547185881],[.10805494870734367,.31911236892788974,.5152486363581541,.6872929048116855,.827201315069765,.9284348836635735,.9862838086968123],[0,.20119409399743451,.3941513470775634,.5709721726085388,.7244177313601701,.8482065834104272,.937273392400706,.9879925180204854],[.09501250983763744,.2816035507792589,.45801677765722737,.6178762444026438,.755404408355003,.8656312023878318,.9445750230732326,.9894009349916499]],i=[[1],[.8888888888888888,.5555555555555556],[.6521451548625461,.34785484513745385],[.5688888888888889,.47862867049936647,.23692688505618908],[.46791393457269104,.3607615730481386,.17132449237917036],[.4179591836734694,.3818300505051189,.27970539148927664,.1294849661688697],[.362683783378362,.31370664587788727,.22238103445337448,.10122853629037626],[.3302393550012598,.31234707704000286,.26061069640293544,.1806481606948574,.08127438836157441],[.29552422471475287,.26926671930999635,.21908636251598204,.1494513491505806,.06667134430868814],[.2729250867779006,.26280454451024665,.23319376459199048,.18629021092773426,.1255803694649046,.05566856711617366],[.24914704581340277,.2334925365383548,.20316742672306592,.16007832854334622,.10693932599531843,.04717533638651183],[.2325515532308739,.22628318026289723,.2078160475368885,.17814598076194574,.13887351021978725,.09212149983772845,.04048400476531588],[.2152638534631578,.2051984637212956,.18553839747793782,.15720316715819355,.12151857068790319,.08015808715976021,.03511946033175186],[.2025782419255613,.19843148532711158,.1861610000155622,.16626920581699392,.13957067792615432,.10715922046717194,.07036604748810812,.03075324199611727],[.1894506104550685,.18260341504492358,.16915651939500254,.14959598881657674,.12462897125553388,.09515851168249279,.062253523938647894,.027152459411754096]],n=Math.abs,r=Math.sqrt,s=Math.pow,a=Math.cos,o=Math.PI;return{TOLERANCE:1e-5,EPSILON:1e-11,KAPPA:4*(r(2)-1)/3,isZero:function(t){return n(t)<=h.EPSILON},integrate:function(t,n,r,s){for(var a=e[s-2],h=i[s-2],o=.5*(r-n),u=o+n,l=0,c=s+1>>1,d=1&s?h[l++]*t(u):0;c>l;){var _=o*a[l];d+=h[l++]*(t(u+_)+t(u-_))}return o*d},findRoot:function(t,e,i,r,s,a,h){for(var o=0;a>o;o++){var u=t(i),l=u/e(i);if(n(l)0?(s=i,i=r>=c?.5*(r+s):c):(r=i,i=c>=s?.5*(r+s):c)}},solveQuadratic:function(e,i,s,a,h,o){function u(t){return(l||t>=h&&o>=t)&&(a[c++]=t),c}var l=h===t,c=0,d=this.EPSILON;if(n(e)=d?u(-s/i):n(s)g)return 0;var m=g>f?r(g-f):0;return u(m-_),m>0&&u(-m-_),c},solveCubic:function(e,i,u,l,c,d,_){function f(t){return(m||t>=d&&_>=t)&&(c[v++]=t),v}var g=this.EPSILON;if(n(e)0?1:-1;return f(2*-S*C-i),f(S*C-i)}if(0>b){var C=r(y),P=Math.acos(w/(C*C*C))/3,z=-2*C,M=2*o/3;return f(z*a(P)-i),f(z*a(P+M)-i),f(z*a(P-M)-i)}var I=(w>0?-1:1)*s(n(w)+r(b),1/3);return f(I+y/I-i)}}},o=e.extend({_class:"Point",_readIndex:!0,initialize:function(t,e){var i=typeof t;if("number"===i){var n="number"==typeof e;this.x=t,this.y=n?e:t,this.__read&&(this.__read=n?2:1)}else"undefined"===i||null===t?(this.x=this.y=0,this.__read&&(this.__read=null===t?1:0)):(Array.isArray(t)?(this.x=t[0],this.y=t.length>1?t[1]:t[0]):null!=t.x?(this.x=t.x,this.y=t.y):null!=t.width?(this.x=t.width,this.y=t.height):null!=t.angle?(this.x=t.length,this.y=0,this.setAngle(t.angle)):(this.x=this.y=0,this.__read&&(this.__read=0)),this.__read&&(this.__read=1))},set:function(t,e){return this.x=t,this.y=e,this},equals:function(t){return t===this||t&&(this.x===t.x&&this.y===t.y||Array.isArray(t)&&this.x===t[0]&&this.y===t[1])||!1},clone:function(){return new o(this.x,this.y)},toString:function(){var t=a.instance;return"{ x: "+t.number(this.x)+", y: "+t.number(this.y)+" }"},_serialize:function(t){var e=t.formatter;return[e.number(this.x),e.number(this.y)]},add:function(t){return t=o.read(arguments),new o(this.x+t.x,this.y+t.y)},subtract:function(t){return t=o.read(arguments),new o(this.x-t.x,this.y-t.y)},multiply:function(t){return t=o.read(arguments),new o(this.x*t.x,this.y*t.y)},divide:function(t){return t=o.read(arguments),new o(this.x/t.x,this.y/t.y)},modulo:function(t){return t=o.read(arguments),new o(this.x%t.x,this.y%t.y)},negate:function(){return new o(-this.x,-this.y)},transform:function(t){return t?t._transformPoint(this):this},getDistance:function(t,e){t=o.read(arguments);var i=t.x-this.x,n=t.y-this.y,r=i*i+n*n;return e?r:Math.sqrt(r)},getLength:function(){var t=this.x*this.x+this.y*this.y;return arguments.length&&arguments[0]?t:Math.sqrt(t)},setLength:function(t){if(this.isZero()){var e=this._angle||0;this.set(Math.cos(e)*t,Math.sin(e)*t)}else{var i=t/this.getLength();h.isZero(i)&&this.getAngle(),this.set(this.x*i,this.y*i)}return this},normalize:function(e){e===t&&(e=1);var i=this.getLength(),n=0!==i?e/i:0,r=new o(this.x*n,this.y*n);return r._angle=this._angle,r},getAngle:function(){return 180*this.getAngleInRadians(arguments[0])/Math.PI},setAngle:function(t){if(t=this._angle=t*Math.PI/180,!this.isZero()){var e=this.getLength();this.set(Math.cos(t)*e,Math.sin(t)*e)}return this},getAngleInRadians:function(){if(arguments[0]===t)return null==this._angle&&(this._angle=Math.atan2(this.y,this.x)),this._angle;var e=o.read(arguments),i=this.getLength()*e.getLength();return h.isZero(i)?0/0:Math.acos(this.dot(e)/i)},getAngleInDegrees:function(){return this.getAngle(arguments[0])},getQuadrant:function(){return this.x>=0?this.y>=0?1:4:this.y>=0?2:3},getDirectedAngle:function(t){return t=o.read(arguments),180*Math.atan2(this.cross(t),this.dot(t))/Math.PI},rotate:function(t,e){if(0===t)return this.clone();t=t*Math.PI/180;var i=e?this.subtract(e):this,n=Math.sin(t),r=Math.cos(t);return i=new o(i.x*r-i.y*n,i.y*r+i.x*n),e?i.add(e):i},isInside:function(t){return t.contains(this)},isClose:function(t,e){return this.getDistance(t)1?t[1]:t[0]):null!=t.width?(this.width=t.width,this.height=t.height):null!=t.x?(this.width=t.x,this.height=t.y):(this.width=this.height=0,this.__read&&(this.__read=0)),this.__read&&(this.__read=1))},set:function(t,e){return this.width=t,this.height=e,this},equals:function(t){return t===this||t&&(this.width===t.width&&this.height===t.height||Array.isArray(t)&&this.width===t[0]&&this.height===t[1])||!1},clone:function(){return new c(this.width,this.height)},toString:function(){var t=a.instance;return"{ width: "+t.number(this.width)+", height: "+t.number(this.height)+" }"},_serialize:function(t){var e=t.formatter;return[e.number(this.width),e.number(this.height)]},add:function(t){return t=c.read(arguments),new c(this.width+t.width,this.height+t.height)},subtract:function(t){return t=c.read(arguments),new c(this.width-t.width,this.height-t.height)},multiply:function(t){return t=c.read(arguments),new c(this.width*t.width,this.height*t.height)},divide:function(t){return t=c.read(arguments),new c(this.width/t.width,this.height/t.height)},modulo:function(t){return t=c.read(arguments),new c(this.width%t.width,this.height%t.height)},negate:function(){return new c(-this.width,-this.height)},isZero:function(){return h.isZero(this.width)&&h.isZero(this.height)},isNaN:function(){return isNaN(this.width)||isNaN(this.height)},statics:{min:function(t,e){return new c(Math.min(t.width,e.width),Math.min(t.height,e.height))},max:function(t,e){return new c(Math.max(t.width,e.width),Math.max(t.height,e.height))},random:function(){return new c(Math.random(),Math.random())}}},e.each(["round","ceil","floor","abs"],function(t){var e=Math[t];this[t]=function(){return new c(e(this.width),e(this.height))}},{})),d=c.extend({initialize:function(t,e,i,n){this._width=t,this._height=e,this._owner=i,this._setter=n},set:function(t,e,i){return this._width=t,this._height=e,i||this._owner[this._setter](this),this},getWidth:function(){return this._width},setWidth:function(t){this._width=t,this._owner[this._setter](this)},getHeight:function(){return this._height},setHeight:function(t){this._height=t,this._owner[this._setter](this)}}),_=e.extend({_class:"Rectangle",_readIndex:!0,initialize:function(i,n,r,s){var a=typeof i,h=0;if("number"===a?(this.x=i,this.y=n,this.width=r,this.height=s,h=4):"undefined"===a||null===i?(this.x=this.y=this.width=this.height=0,h=null===i?1:0):1===arguments.length&&(Array.isArray(i)?(this.x=i[0],this.y=i[1],this.width=i[2],this.height=i[3],h=1):i.x!==t||i.width!==t?(this.x=i.x||0,this.y=i.y||0,this.width=i.width||0,this.height=i.height||0,h=1):i.from===t&&i.to===t&&(this.x=this.y=this.width=this.height=0,this._set(i),h=1)),!h){var u=o.readNamed(arguments,"from"),l=e.peek(arguments);if(this.x=u.x,this.y=u.y,l&&l.x!==t||e.hasNamed(arguments,"to")){var d=o.readNamed(arguments,"to");this.width=d.x-u.x,this.height=d.y-u.y,this.width<0&&(this.x=d.x,this.width=-this.width),this.height<0&&(this.y=d.y,this.height=-this.height)}else{var _=c.read(arguments);this.width=_.width,this.height=_.height}h=arguments._index}this.__read&&(this.__read=h)},set:function(t,e,i,n){return this.x=t,this.y=e,this.width=i,this.height=n,this},clone:function(){return new _(this.x,this.y,this.width,this.height)},equals:function(t){return e.isPlainValue(t)&&(t=_.read(arguments)),t===this||t&&this.x===t.x&&this.y===t.y&&this.width===t.width&&this.height===t.height||!1},toString:function(){var t=a.instance;return"{ x: "+t.number(this.x)+", y: "+t.number(this.y)+", width: "+t.number(this.width)+", height: "+t.number(this.height)+" }"},_serialize:function(t){var e=t.formatter;return[e.number(this.x),e.number(this.y),e.number(this.width),e.number(this.height)]},getPoint:function(){return new(arguments[0]?o:u)(this.x,this.y,this,"setPoint")},setPoint:function(t){t=o.read(arguments),this.x=t.x,this.y=t.y},getSize:function(){return new(arguments[0]?c:d)(this.width,this.height,this,"setSize")},setSize:function(t){t=c.read(arguments),this._fixX&&(this.x+=(this.width-t.width)*this._fixX),this._fixY&&(this.y+=(this.height-t.height)*this._fixY),this.width=t.width,this.height=t.height,this._fixW=1,this._fixH=1},getLeft:function(){return this.x},setLeft:function(t){this._fixW||(this.width-=t-this.x),this.x=t,this._fixX=0},getTop:function(){return this.y},setTop:function(t){this._fixH||(this.height-=t-this.y),this.y=t,this._fixY=0},getRight:function(){return this.x+this.width},setRight:function(e){this._fixX!==t&&1!==this._fixX&&(this._fixW=0),this._fixW?this.x=e-this.width:this.width=e-this.x,this._fixX=1},getBottom:function(){return this.y+this.height},setBottom:function(e){this._fixY!==t&&1!==this._fixY&&(this._fixH=0),this._fixH?this.y=e-this.height:this.height=e-this.y,this._fixY=1},getCenterX:function(){return this.x+.5*this.width},setCenterX:function(t){this.x=t-.5*this.width,this._fixX=.5},getCenterY:function(){return this.y+.5*this.height},setCenterY:function(t){this.y=t-.5*this.height,this._fixY=.5},getCenter:function(){return new(arguments[0]?o:u)(this.getCenterX(),this.getCenterY(),this,"setCenter")},setCenter:function(t){return t=o.read(arguments),this.setCenterX(t.x),this.setCenterY(t.y),this},isEmpty:function(){return 0==this.width||0==this.height},contains:function(e){return e&&e.width!==t||4==(Array.isArray(e)?e:arguments).length?this._containsRectangle(_.read(arguments)):this._containsPoint(o.read(arguments))},_containsPoint:function(t){var e=t.x,i=t.y;return e>=this.x&&i>=this.y&&e<=this.x+this.width&&i<=this.y+this.height},_containsRectangle:function(t){var e=t.x,i=t.y;return e>=this.x&&i>=this.y&&e+t.width<=this.x+this.width&&i+t.height<=this.y+this.height},intersects:function(t){return t=_.read(arguments),t.x+t.width>this.x&&t.y+t.height>this.y&&t.x=this.x&&t.y+t.height>=this.y&&t.x<=this.x+this.width&&t.y<=this.y+this.height},intersect:function(t){t=_.read(arguments);var e=Math.max(this.x,t.x),i=Math.max(this.y,t.y),n=Math.min(this.x+this.width,t.x+t.width),r=Math.min(this.y+this.height,t.y+t.height);return new _(e,i,n-e,r-i)},unite:function(t){t=_.read(arguments);var e=Math.min(this.x,t.x),i=Math.min(this.y,t.y),n=Math.max(this.x+this.width,t.x+t.width),r=Math.max(this.y+this.height,t.y+t.height);return new _(e,i,n-e,r-i)},include:function(t){t=o.read(arguments);var e=Math.min(this.x,t.x),i=Math.min(this.y,t.y),n=Math.max(this.x+this.width,t.x),r=Math.max(this.y+this.height,t.y);return new _(e,i,n-e,r-i)},expand:function(e,i){return i===t&&(i=e),new _(this.x-e/2,this.y-i/2,this.width+e,this.height+i)},scale:function(e,i){return this.expand(this.width*e-this.width,this.height*(i===t?e:i)-this.height)}},new function(){return e.each([["Top","Left"],["Top","Right"],["Bottom","Left"],["Bottom","Right"],["Left","Center"],["Top","Center"],["Right","Center"],["Bottom","Center"]],function(t,e){var i=t.join(""),n=/^[RL]/.test(i);e>=4&&(t[1]+=n?"Y":"X");var r=t[n?0:1],s=t[n?1:0],a="get"+r,h="get"+s,l="set"+r,c="set"+s,d="get"+i,_="set"+i;this[d]=function(){return new(arguments[0]?o:u)(this[a](),this[h](),this,_)},this[_]=function(t){t=o.read(arguments),this[l](t.x),this[c](t.y)}},{})}),f=_.extend({initialize:function(t,e,i,n,r,s){this.set(t,e,i,n,!0),this._owner=r,this._setter=s},set:function(t,e,i,n,r){return this._x=t,this._y=e,this._width=i,this._height=n,r||this._owner[this._setter](this),this}},new function(){var t=_.prototype;return e.each(["x","y","width","height"],function(t){var i=e.capitalize(t),n="_"+t;this["get"+i]=function(){return this[n]},this["set"+i]=function(t){this[n]=t,this._dontNotify||this._owner[this._setter](this)}},e.each(["Point","Size","Center","Left","Top","Right","Bottom","CenterX","CenterY","TopLeft","TopRight","BottomLeft","BottomRight","LeftCenter","TopCenter","RightCenter","BottomCenter"],function(e){var i="set"+e;this[i]=function(){this._dontNotify=!0,t[i].apply(this,arguments),delete this._dontNotify,this._owner[this._setter](this)}},{isSelected:function(){return this._owner._boundsSelected},setSelected:function(t){var e=this._owner;e.setSelected&&(e._boundsSelected=t,e.setSelected(t||e._selectedSegmentState>0))}}))}),g=e.extend({_class:"Matrix",initialize:function re(t){var e=arguments.length,i=!0;if(6===e?this.set.apply(this,arguments):1===e?t instanceof re?this.set(t._a,t._c,t._b,t._d,t._tx,t._ty):Array.isArray(t)?this.set.apply(this,t):i=!1:0===e?this.reset():i=!1,!i)throw Error("Unsupported matrix parameters")},set:function(t,e,i,n,r,s){return this._a=t,this._c=e,this._b=i,this._d=n,this._tx=r,this._ty=s,this},_serialize:function(t){return e.serialize(this.getValues(),t)},clone:function(){return new g(this._a,this._c,this._b,this._d,this._tx,this._ty)},equals:function(t){return t===this||t&&this._a===t._a&&this._b===t._b&&this._c===t._c&&this._d===t._d&&this._tx===t._tx&&this._ty===t._ty||!1},toString:function(){var t=a.instance;return"[["+[t.number(this._a),t.number(this._b),t.number(this._tx)].join(", ")+"], ["+[t.number(this._c),t.number(this._d),t.number(this._ty)].join(", ")+"]]"},reset:function(){return this._a=this._d=1,this._c=this._b=this._tx=this._ty=0,this},scale:function(){var t=o.read(arguments),e=o.read(arguments,0,0,{readNull:!0});return e&&this.translate(e),this._a*=t.x,this._c*=t.x,this._b*=t.y,this._d*=t.y,e&&this.translate(e.negate()),this},translate:function(t){t=o.read(arguments);var e=t.x,i=t.y;return this._tx+=e*this._a+i*this._b,this._ty+=e*this._c+i*this._d,this},rotate:function(t,e){e=o.read(arguments,1),t=t*Math.PI/180;var i=e.x,n=e.y,r=Math.cos(t),s=Math.sin(t),a=i-i*r+n*s,h=n-i*s-n*r,u=this._a,l=this._b,c=this._c,d=this._d;return this._a=r*u+s*l,this._b=-s*u+r*l,this._c=r*c+s*d,this._d=-s*c+r*d,this._tx+=a*u+h*l,this._ty+=a*c+h*d,this},shear:function(){var t=o.read(arguments),e=o.read(arguments,0,0,{readNull:!0});e&&this.translate(e);var i=this._a,n=this._c;return this._a+=t.y*this._b,this._c+=t.y*this._d,this._b+=t.x*i,this._d+=t.x*n,e&&this.translate(e.negate()),this},concatenate:function(t){var e=this._a,i=this._b,n=this._c,r=this._d;return this._a=t._a*e+t._c*i,this._b=t._b*e+t._d*i,this._c=t._a*n+t._c*r,this._d=t._b*n+t._d*r,this._tx+=t._tx*e+t._ty*i,this._ty+=t._tx*n+t._ty*r,this},preConcatenate:function(t){var e=this._a,i=this._b,n=this._c,r=this._d,s=this._tx,a=this._ty;return this._a=t._a*e+t._b*n,this._b=t._a*i+t._b*r,this._c=t._c*e+t._d*n,this._d=t._c*i+t._d*r,this._tx=t._a*s+t._b*a+t._tx,this._ty=t._c*s+t._d*a+t._ty,this},isIdentity:function(){return 1==this._a&&0==this._c&&0==this._b&&1==this._d&&0==this._tx&&0==this._ty},isInvertible:function(){return!!this._getDeterminant()},isSingular:function(){return!this._getDeterminant()},transform:function(t,e,i,n,r){return arguments.length<5?this._transformPoint(o.read(arguments)):this._transformCoordinates(t,e,i,n,r)},_transformPoint:function(t,e,i){var n=t.x,r=t.y;return e||(e=new o),e.set(n*this._a+r*this._b+this._tx,n*this._c+r*this._d+this._ty,i)},_transformCoordinates:function(t,e,i,n,r){for(var s=e,a=n,h=e+2*r;h>s;){var o=t[s++],u=t[s++];i[a++]=o*this._a+u*this._b+this._tx,i[a++]=o*this._c+u*this._d+this._ty}return i},_transformCorners:function(t){var e=t.x,i=t.y,n=e+t.width,r=i+t.height,s=[e,i,n,i,n,r,e,r];return this._transformCoordinates(s,0,s,0,4)},_transformBounds:function(t,e,i){for(var n=this._transformCorners(t),r=n.slice(0,2),s=n.slice(),a=2;8>a;a++){var h=n[a],o=1&a;hs[o]&&(s[o]=h)}return e||(e=new _),e.set(r[0],r[1],s[0]-r[0],s[1]-r[1],i)},inverseTransform:function(){return this._inverseTransform(o.read(arguments))},_getDeterminant:function(){var t=this._a*this._d-this._b*this._c;return isFinite(t)&&!h.isZero(t)&&isFinite(this._tx)&&isFinite(this._ty)?t:null},_inverseTransform:function(t,e,i){var n=this._getDeterminant();if(!n)return null;var r=t.x-this._tx,s=t.y-this._ty;return e||(e=new o),e.set((r*this._d-s*this._b)/n,(s*this._a-r*this._c)/n,i)},decompose:function(){var t=this._a,e=this._b,i=this._c,n=this._d;if(h.isZero(t*n-e*i))return null;var r=Math.sqrt(t*t+e*e);t/=r,e/=r;var s=t*i+e*n;i-=t*s,n-=e*s;var a=Math.sqrt(i*i+n*n);return i/=a,n/=a,s/=a,e*i>t*n&&(t=-t,e=-e,s=-s,r=-r),{translation:this.getTranslation(),scaling:new o(r,a),rotation:180*-Math.atan2(e,t)/Math.PI,shearing:s} -},getValues:function(){return[this._a,this._c,this._b,this._d,this._tx,this._ty]},getTranslation:function(){return new o(this._tx,this._ty)},getScaling:function(){return(this.decompose()||{}).scaling},getRotation:function(){return(this.decompose()||{}).rotation},inverted:function(){var t=this._getDeterminant();return t&&new g(this._d/t,-this._c/t,-this._b/t,this._a/t,(this._b*this._ty-this._d*this._tx)/t,(this._c*this._tx-this._a*this._ty)/t)},shiftless:function(){return new g(this._a,this._c,this._b,this._d,0,0)},applyToContext:function(t){t.transform(this._a,this._c,this._b,this._d,this._tx,this._ty)}},new function(){return e.each({scaleX:"_a",scaleY:"_d",translateX:"_tx",translateY:"_ty",shearX:"_b",shearY:"_c"},function(t,i){i=e.capitalize(i),this["get"+i]=function(){return this[t]},this["set"+i]=function(e){this[t]=e}},{})}),m=e.extend({_class:"Line",initialize:function(t,e,i,n,r){var s=!1;arguments.length>=4?(this._px=t,this._py=e,this._vx=i,this._vy=n,s=r):(this._px=t.x,this._py=t.y,this._vx=e.x,this._vy=e.y,s=i),s||(this._vx-=this._px,this._vy-=this._py)},getPoint:function(){return new o(this._px,this._py)},getVector:function(){return new o(this._vx,this._vy)},getLength:function(){return this.getVector().getLength()},intersect:function(t,e){return m.intersect(this._px,this._py,this._vx,this._vy,t._px,t._py,t._vx,t._vy,!0,e)},getSide:function(t){return m.getSide(this._px,this._py,this._vx,this._vy,t.x,t.y,!0)},getDistance:function(t){return Math.abs(m.getSignedDistance(this._px,this._py,this._vx,this._vy,t.x,t.y,!0))},statics:{intersect:function(t,e,i,n,r,s,a,u,l,c){l||(i-=t,n-=e,a-=r,u-=s);var d=u*i-a*n;if(!h.isZero(d)){var _=t-r,f=e-s,g=(a*f-u*_)/d,m=(i*f-n*_)/d;if((c||g>=0&&1>=g)&&(c||m>=0&&1>=m))return new o(t+g*i,e+g*n)}},getSide:function(t,e,i,n,r,s,a){a||(i-=t,n-=e);var h=r-t,o=s-e,u=h*n-o*i;return 0===u&&(u=h*i+o*n,u>0&&(h-=i,o-=n,u=h*i+o*n,0>u&&(u=0))),0>u?-1:u>0?1:0},getSignedDistance:function(t,e,i,n,r,s,a){a||(i-=t,n-=e);var h=n/i,o=e-h*t;return(s-h*r-o)/Math.sqrt(h*h+1)}}}),v=s.extend({_class:"Project",_list:"projects",_reference:"project",initialize:function(t){s.call(this,!0),this.layers=[],this.symbols=[],this._currentStyle=new E,this.activeLayer=new x,t&&(this.view=t instanceof Z?t:Z.create(t)),this._selectedItems={},this._selectedItemCount=0,this._drawCount=0,this.options={}},_serialize:function(t,i){return e.serialize(this.layers,t,!0,i)},clear:function(){for(var t=this.layers.length-1;t>=0;t--)this.layers[t].remove();this.symbols=[]},remove:function se(){return se.base.call(this)?(this.view&&this.view.remove(),!0):!1},getCurrentStyle:function(){return this._currentStyle},setCurrentStyle:function(t){this._currentStyle.initialize(t)},getIndex:function(){return this._index},getSelectedItems:function(){var t=[];for(var e in this._selectedItems){var i=this._selectedItems[e];i.isInserted()&&t.push(i)}return t},_updateSelection:function(t){var e=t._id,i=this._selectedItems;t._selected?i[e]!==t&&(this._selectedItemCount++,i[e]=t):i[e]===t&&(this._selectedItemCount--,delete i[e])},selectAll:function(){for(var t=this.layers,e=0,i=t.length;i>e;e++)t[e].setFullySelected(!0)},deselectAll:function(){var t=this._selectedItems;for(var e in t)t[e].setFullySelected(!1)},hitTest:function(t,i){t=o.read(arguments),i=P.getOptions(e.read(arguments));for(var n=this.layers.length-1;n>=0;n--){var r=this.layers[n].hitTest(t,i);if(r)return r}return null}},new function(){function t(t,e,i){for(var n=t.layers,r=i&&[],s=0,a=n.length;a>s;s++){var h=n[s][i?"getItems":"getItem"](e);if(i)r.push.apply(r,h);else if(h)return h}return i?r:null}return{getItems:function(e){return t(this,e,!0)},getItem:function(e){return t(this,e,!1)}}},{importJSON:function(t){return this.activate(),e.importJSON(t)},draw:function(t,i){this._drawCount++,t.save(),i.applyToContext(t);for(var n=e.merge({offset:new o(0,0),transforms:[i],trackTransforms:!0}),r=0,s=this.layers.length;s>r;r++)this.layers[r].draw(t,n);if(t.restore(),this._selectedItemCount>0){t.save(),t.strokeWidth=1;for(var a in this._selectedItems){var h=this._selectedItems[a];if(h._drawCount===this._drawCount&&(h._drawSelected||h._boundsSelected)){var u=h.getSelectedColor()||h.getLayer().getSelectedColor();t.strokeStyle=t.fillStyle=u?u.toCanvasStyle(t):"#009dec";var l=h._globalMatrix;if(h._drawSelected&&h._drawSelected(t,l),h._boundsSelected){var c=l._transformCorners(h._getBounds("getBounds"));t.beginPath();for(var r=0;8>r;r++)t[0===r?"moveTo":"lineTo"](c[r],c[++r]);t.closePath(),t.stroke();for(var r=0;8>r;r++)t.beginPath(),t.rect(c[r]-2,c[++r]-2,4,4),t.fill()}}}t.restore()}}}),p=e.extend({_class:"Symbol",initialize:function ae(t,e){this._id=ae._id=(ae._id||0)+1,this.project=paper.project,this.project.symbols.push(this),t&&this.setDefinition(t,e),this._instances={}},_serialize:function(t,i){return i.add(this,function(){return e.serialize([this._class,this._definition],t,!1,i)})},_changed:function(t){e.each(this._instances,function(e){e._changed(t)})},getDefinition:function(){return this._definition},setDefinition:function(t){t._parentSymbol&&(t=t.clone()),this._definition&&delete this._definition._parentSymbol,this._definition=t,t.remove(),t.setSelected(!1),arguments[1]||t.setPosition(new o),t._parentSymbol=this,this._changed(5)},place:function(t){return new S(this,t)},clone:function(){return new p(this._definition.clone(!1))}}),y=e.extend(n,{statics:{extend:function he(t){t._serializeFields&&(t._serializeFields=e.merge(this.prototype._serializeFields,t._serializeFields));var i=he.base.apply(this,arguments),n=i.prototype,r=n._class;return r&&(n._type=e.hyphenate(r)),i}},_class:"Item",_transformContent:!0,_boundsSelected:!1,_serializeFields:{name:null,matrix:new g,locked:!1,visible:!0,blendMode:"normal",opacity:1,guide:!1,selected:!1,clipMask:!1,data:{}},initialize:function(){},_initialize:function(t,e){if(this._id=y._id=(y._id||0)+1,!this._project){var i=paper.project,n=i.activeLayer;!n||t&&t.insert===!1?this._setProject(i):n.addChild(this)}return this._style=new E(this._project._currentStyle,this),this._matrix=new g,e&&this._matrix.translate(e),t?this._set(t,{insert:!0}):!0},_events:new function(){var t={mousedown:{mousedown:1,mousedrag:1,click:1,doubleclick:1},mouseup:{mouseup:1,mousedrag:1,click:1,doubleclick:1},mousemove:{mousedrag:1,mousemove:1,mouseenter:1,mouseleave:1}},i={install:function(e){var i=this._project.view._eventCounters;if(i)for(var n in t)i[n]=(i[n]||0)+(t[n][e]||0)},uninstall:function(e){var i=this._project.view._eventCounters;if(i)for(var n in t)i[n]-=t[n][e]||0}};return e.each(["onMouseDown","onMouseUp","onMouseDrag","onClick","onDoubleClick","onMouseMove","onMouseEnter","onMouseLeave"],function(t){this[t]=i},{onFrame:{install:function(){this._project.view._animateItem(this,!0)},uninstall:function(){this._project.view._animateItem(this,!1)}},onLoad:{}})},_serialize:function(t,i){function n(n){for(var a in n){var h=s[a];e.equals(h,"leading"===a?1.2*n.fontSize:n[a])||(r[a]=e.serialize(h,t,"data"!==a,i))}}var r={},s=this;return n(this._serializeFields),this instanceof w||n(this._style._defaults),[this._class,r]},_changed:function(t){var e=this._parent,i=this._project,n=this._parentSymbol;if(this._drawCount=null,4&t&&(delete this._bounds,delete this._position),e&&12&t&&e._clearBoundsCache(),2&t&&this._clearBoundsCache(),i&&(1&t&&(i._needsRedraw=!0),i._changes)){var r=i._changesById[this._id];r?r.flags|=t:(r={item:this,flags:t},i._changesById[this._id]=r,i._changes.push(r))}n&&n._changed(t)},set:function(t){return t&&this._set(t),this},getId:function(){return this._id},getType:function(){return this._type},getName:function(){return this._name},setName:function(e,i){if(this._name&&this._removeNamed(),e===+e+"")throw Error("Names consisting only of numbers are not supported.");if(e&&this._parent){for(var n=this._parent._children,r=this._parent._namedChildren,s=e,a=1;i&&n[e];)e=s+" "+a++;(r[e]=r[e]||[]).push(this),n[e]=this}this._name=e||t,this._changed(32)},getStyle:function(){return this._style},setStyle:function(t){this.getStyle().set(t)},hasFill:function(){return this.getStyle().hasFill()},hasStroke:function(){return this.getStyle().hasStroke()}},e.each(["locked","visible","blendMode","opacity","guide"],function(t){var i=e.capitalize(t),t="_"+t;this["get"+i]=function(){return this[t]},this["set"+i]=function(e){e!=this[t]&&(this[t]=e,this._changed("_locked"===t?32:33))}},{}),{_locked:!1,_visible:!0,_blendMode:"normal",_opacity:1,_guide:!1,isSelected:function(){if(this._children)for(var t=0,e=this._children.length;e>t;t++)if(this._children[t].isSelected())return!0;return this._selected},setSelected:function(t){if(this._children&&!arguments[1])for(var e=0,i=this._children.length;i>e;e++)this._children[e].setSelected(t);(t=!!t)!=this._selected&&(this._selected=t,this._project._updateSelection(this),this._changed(33))},_selected:!1,isFullySelected:function(){if(this._children&&this._selected){for(var t=0,e=this._children.length;e>t;t++)if(!this._children[t].isFullySelected())return!1;return!0}return this._selected},setFullySelected:function(t){if(this._children)for(var e=0,i=this._children.length;i>e;e++)this._children[e].setFullySelected(t);this.setSelected(t,!0)},isClipMask:function(){return this._clipMask},setClipMask:function(t){this._clipMask!=(t=!!t)&&(this._clipMask=t,t&&(this.setFillColor(null),this.setStrokeColor(null)),this._changed(33),this._parent&&this._parent._changed(256))},_clipMask:!1,getData:function(){return this._data||(this._data={}),this._data},setData:function(t){this._data=t},getPosition:function(){var t=this._position||(this._position=this.getBounds().getCenter(!0));return new(arguments[0]?o:u)(t.x,t.y,this,"setPosition")},setPosition:function(){this.translate(o.read(arguments).subtract(this.getPosition(!0)))},getMatrix:function(){return this._matrix},setMatrix:function(t){this._matrix.initialize(t),this._changed(5)},getGlobalMatrix:function(){return this._drawCount===this._project._drawCount&&this._globalMatrix||null},globalToLocal:function(){var t=this.getGlobalMatrix();return t&&t._transformPoint(o.read(arguments))},localToGlobal:function(){var t=this.getGlobalMatrix();return t&&t._inverseTransform(o.read(arguments))},isEmpty:function(){return!this._children||0==this._children.length}},e.each(["getBounds","getStrokeBounds","getHandleBounds","getRoughBounds"],function(t){this[t]=function(){var e=this._boundsGetter,i=this._getCachedBounds("string"==typeof e?e:e&&e[t]||t,arguments[0]);return"getBounds"===t?new f(i.x,i.y,i.width,i.height,this,"setBounds"):i}},{_getCachedBounds:function(t,e,i){var n=(!e||e.equals(this._matrix))&&t;if(i&&this._parent){var r=i._id,s=this._parent._boundsCache=this._parent._boundsCache||{ids:{},list:[]};s.ids[r]||(s.list.push(i),s.ids[r]=i)}if(n&&this._bounds&&this._bounds[n])return this._bounds[n].clone();var a=this._matrix.isIdentity();e=!e||e.isIdentity()?a?null:this._matrix:a?e:e.clone().concatenate(this._matrix);var h=this._getBounds(t,e,n?this:i);return n&&(this._bounds||(this._bounds={}),this._bounds[n]=h.clone()),h},_clearBoundsCache:function(){if(this._boundsCache){for(var t=0,e=this._boundsCache.list,i=e.length;i>t;t++){var n=e[t];delete n._bounds,n!=this&&n._boundsCache&&n._clearBoundsCache()}delete this._boundsCache}},_getBounds:function(t,e,i){var n=this._children;if(!n||0==n.length)return new _;for(var r=1/0,s=-r,a=r,h=s,o=0,u=n.length;u>o;o++){var l=n[o];if(l._visible&&!l.isEmpty()){var c=l._getCachedBounds(t,e,i);r=Math.min(c.x,r),a=Math.min(c.y,a),s=Math.max(c.x+c.width,s),h=Math.max(c.y+c.height,h)}}return isFinite(r)?new _(r,a,s-r,h-a):new _},setBounds:function(t){t=_.read(arguments);var e=this.getBounds(),i=new g,n=t.getCenter();i.translate(n),(t.width!=e.width||t.height!=e.height)&&i.scale(0!=e.width?t.width/e.width:1,0!=e.height?t.height/e.height:1),n=e.getCenter(),i.translate(-n.x,-n.y),this.transform(i)}}),{getProject:function(){return this._project},_setProject:function(t){if(this._project!=t&&(this._project=t,this._children))for(var e=0,i=this._children.length;i>e;e++)this._children[e]._setProject(t)},getLayer:function(){for(var t=this;t=t._parent;)if(t instanceof x)return t;return null},getParent:function(){return this._parent},setParent:function(t){return t.addChild(this)},getChildren:function(){return this._children},setChildren:function(t){this.removeChildren(),this.addChildren(t)},getFirstChild:function(){return this._children&&this._children[0]||null},getLastChild:function(){return this._children&&this._children[this._children.length-1]||null},getNextSibling:function(){return this._parent&&this._parent._children[this._index+1]||null},getPreviousSibling:function(){return this._parent&&this._parent._children[this._index-1]||null},getIndex:function(){return this._index},isInserted:function(){return this._parent?this._parent.isInserted():!1},equals:function(t){return t===this||t&&this._class===t._class&&this._style.equals(t._style)&&this._matrix.equals(t._matrix)&&this._locked===t._locked&&this._visible===t._visible&&this._blendMode===t._blendMode&&this._opacity===t._opacity&&this._clipMask===t._clipMask&&this._guide===t._guide&&this._equals(t)||!1},_equals:function(t){return e.equals(this._children,t._children)},clone:function(t){return this._clone(new this.constructor({insert:!1}),t)},_clone:function(e,i){if(e.setStyle(this._style),this._children)for(var n=0,r=this._children.length;r>n;n++)e.addChild(this._children[n].clone(!1),!0);(i||i===t)&&e.insertAbove(this);for(var s=["_locked","_visible","_blendMode","_opacity","_clipMask","_guide"],n=0,r=s.length;r>n;n++){var a=s[n];this.hasOwnProperty(a)&&(e[a]=this[a])}return e._matrix.initialize(this._matrix),e.setSelected(this._selected),this._name&&e.setName(this._name,!0),e},copyTo:function(t){var e=this.clone();return t.layers?t.activeLayer.addChild(e):t.addChild(e),e},rasterize:function(t){var i=this.getStrokeBounds(),n=(t||72)/72,r=i.getTopLeft().floor(),s=i.getBottomRight().ceil();size=new c(s.subtract(r)),canvas=$.getCanvas(size),ctx=canvas.getContext("2d"),matrix=(new g).scale(n).translate(r.negate()),ctx.save(),matrix.applyToContext(ctx),this.draw(ctx,e.merge({transforms:[matrix]})),ctx.restore();var a=new C({canvas:canvas,insert:!1});return a.setPosition(r.add(size.divide(2))),a.insertAbove(this),a},contains:function(){return!!this._contains(this._matrix._inverseTransform(o.read(arguments)))},_contains:function(t){if(this._children){for(var e=this._children.length-1;e>=0;e--)if(this._children[e].contains(t))return!0;return!1}return t.isInside(this._getBounds("getBounds"))},hitTest:function(i,n){function r(r,s){var o=h["get"+s]();return i.getDistance(o)l&&!s;l++)s=r("bounds",u[l])}return(s||(s=this._children||!(n.guides&&!this._guide||n.selected&&!this._selected)?this._hitTest(i,n):null))&&s.point&&(s.point=a._matrix.transform(s.point)),s},_hitTest:function(t,e){var i=this._children;if(i){for(var n,r=i.length-1;r>=0;r--)if(n=i[r].hitTest(t,e))return n}else if(e.fill&&this.hasFill()&&this._contains(t))return new P("fill",this)},matches:function(t){function i(t,n){for(var r in t)if(t.hasOwnProperty(r)){var s=t[r],a=n[r];if(e.isPlainObject(s)&&e.isPlainObject(a)){if(!i(s,a))return!1}else if(!e.equals(s,a))return!1}return!0}for(var n in t)if(t.hasOwnProperty(n)){var r=this[n],s=t[n];if(s instanceof RegExp){if(!s.test(r))return!1}else if("function"==typeof s){if(!s(r))return!1}else if(e.isPlainObject(s)){if(!i(s,r))return!1}else if(!e.equals(r,s))return!1}return!0}},new function(){function t(e,i,n){for(var r=e._children,s=n&&[],a=0,h=r&&r.length;h>a;a++){var o=r[a];if(o.matches(i)){if(!n)return o;s.push(o)}var u=t(o,i,n);if(n)s.push.apply(s,u);else if(u)return u}return n?s:null}return{getItems:function(e){return t(this,e,!0)},getItem:function(e){return t(this,e,!1)}}},{importJSON:function(t){return this.addChild(e.importJSON(t))},addChild:function(e,i){return this.insertChild(t,e,i)},insertChild:function(t,e,i){var n=this.insertChildren(t,[e],i);return n&&n[0]},addChildren:function(t,e){return this.insertChildren(this._children.length,t,e)},insertChildren:function(t,i,n,r){var s=this._children;if(s&&i&&i.length>0){i=Array.prototype.slice.apply(i);for(var a=i.length-1;a>=0;a--){var h=i[a];r&&h._type!==r?i.splice(a,1):h._remove(!0)}e.splice(s,i,t,0);for(var a=0,o=i.length;o>a;a++){var h=i[a];h._parent=this,h._setProject(this._project),h._name&&h.setName(h._name)}this._changed(7)}else i=null;return i},_insert:function(t,e,i){if(!e._parent)return null;var n=e._index+(t?1:0);return e._parent===this._parent&&n>this._index&&n--,e._parent.insertChild(n,this,i)},insertAbove:function(t,e){return this._insert(!0,t,e)},insertBelow:function(t,e){return this._insert(!1,t,e)},sendToBack:function(){return this._parent.insertChild(0,this)},bringToFront:function(){return this._parent.addChild(this)},appendTop:"#addChild",appendBottom:function(t){return this.insertChild(0,t)},moveAbove:"#insertAbove",moveBelow:"#insertBelow",reduce:function(){if(this._children&&1===this._children.length){var t=this._children[0];return t.insertAbove(this),this.remove(),t}return this},_removeNamed:function(){var t=this._parent._children,e=this._parent._namedChildren,i=this._name,n=e[i],r=n?n.indexOf(this):-1;-1!=r&&(t[i]==this&&delete t[i],n.splice(r,1),n.length?t[i]=n[n.length-1]:delete e[i])},_remove:function(t){return this._parent?(this._name&&this._removeNamed(),null!=this._index&&e.splice(this._parent._children,null,this._index,1),t&&this._parent._changed(7),this._parent=null,!0):!1},remove:function(){return this._remove(!0)},removeChildren:function(t,i){if(!this._children)return null;t=t||0,i=e.pick(i,this._children.length);for(var n=e.splice(this._children,null,t,i-t),r=n.length-1;r>=0;r--)n[r]._remove(!1);return n.length>0&&this._changed(7),n},reverseChildren:function(){if(this._children){this._children.reverse();for(var t=0,e=this._children.length;e>t;t++)this._children[t]._index=t;this._changed(7)}},isEditable:function(){for(var t=this;t;){if(!t._visible||t._locked)return!1;t=t._parent}return!0},_getOrder:function(t){function e(t){var e=[];do e.unshift(t);while(t=t._parent);return e}for(var i=e(this),n=e(t),r=0,s=Math.min(i.length,n.length);s>r;r++)if(i[r]!=n[r])return i[r]._index0},isAbove:function(t){return-1===this._getOrder(t)},isBelow:function(t){return 1===this._getOrder(t)},isParent:function(t){return this._parent===t},isChild:function(t){return t&&t._parent===this},isDescendant:function(t){for(var e=this;e=e._parent;)if(e==t)return!0;return!1},isAncestor:function(t){return t?t.isDescendant(this):!1},isGroupedWith:function(t){for(var e=this._parent;e;){if(e._parent&&/^(group|layer|compound-path)$/.test(e._type)&&t.isDescendant(e))return!0;e=e._parent}return!1},scale:function(t,e,i){return(arguments.length<2||"object"==typeof e)&&(i=e,e=t),this.transform((new g).scale(t,e,i||this.getPosition(!0)))},translate:function(){var t=new g;return this.transform(t.translate.apply(t,arguments))},rotate:function(t,e){return this.transform((new g).rotate(t,e||this.getPosition(!0)))},shear:function(t,e,i){return(arguments.length<2||"object"==typeof e)&&(i=e,e=t),this.transform((new g).shear(t,e,i||this.getPosition(!0)))},transform:function(t){var e=this._bounds,i=this._position;if(this._matrix.preConcatenate(t),(this._transformContent||arguments[1])&&this.applyMatrix(!0),this._changed(5),e&&0===t.getRotation()%90){for(var n in e){var r=e[n];t._transformBounds(r,r)}var s=this._boundsGetter,r=e[s&&s.getBounds||s||"getBounds"];r&&(this._position=r.getCenter(!0)),this._bounds=e}else i&&(this._position=t._transformPoint(i,i));return this},_applyMatrix:function(t,e){var i=this._children;if(i&&i.length>0){for(var n=0,r=i.length;r>n;n++)i[n].transform(t,e);return!0}},applyMatrix:function(t){var e=this._matrix;if(this._applyMatrix(e,!0)){var i=this._style,n=i.getFillColor(!0),r=i.getStrokeColor(!0);n&&n.transform(e),r&&r.transform(e),e.reset()}t||this._changed(5)},fitBounds:function(t,e){t=_.read(arguments);var i=this.getBounds(),n=i.height/i.width,r=t.height/t.width,s=(e?n>r:r>n)?t.width/i.width:t.height/i.height,a=new _(new o,new c(i.width*s,i.height*s));a.setCenter(t.getCenter()),this.setBounds(a)},_setStyles:function(t){var e=this._style,i=this._matrix,n=e.getStrokeWidth(),r=e.getFillColor(),s=e.getStrokeColor(),a=e.getShadowColor();if(r&&(t.fillStyle=r.toCanvasStyle(t,i)),s&&n>0){t.strokeStyle=s.toCanvasStyle(t,i),t.lineWidth=n;var h=e.getStrokeJoin(),o=e.getStrokeCap(),u=e.getMiterLimit(),l=e.getDashArray(),c=e.getDashOffset();h&&(t.lineJoin=h),o&&(t.lineCap=o),u&&(t.miterLimit=u),paper.support.nativeDash&&l&&l.length&&("setLineDash"in t?(t.setLineDash(l),t.lineDashOffset=c):(t.mozDash=l,t.mozDashOffset=c))}if(a){t.shadowColor=a.toCanvasStyle(t),t.shadowBlur=e.getShadowBlur();var d=this.getShadowOffset();t.shadowOffsetX=d.x,t.shadowOffsetY=d.y}},draw:function(t,e){if(this._visible&&0!==this._opacity){this._drawCount=this._project._drawCount;var i=e.trackTransforms,n=e.transforms,r=n[n.length-1],s=r.clone().concatenate(this._matrix);i&&n.push(this._globalMatrix=s);var a,h,o,u=this._blendMode,l=this._opacity,d="normal"===u,_=K.nativeModes[u],f=d&&1===l||(_||d&&1>l)&&this._canComposite();if(!f){var g=this.getStrokeBounds(r);if(!g.width||!g.height)return;o=e.offset,h=e.offset=g.getTopLeft().floor(),a=t,t=$.getContext(g.getSize().ceil().add(new c(1,1)))}t.save(),f?(t.globalAlpha=l,_&&(t.globalCompositeOperation=u)):t.translate(-h.x,-h.y),(f?this._matrix:s).applyToContext(t),!f&&e.clipItem&&e.clipItem.draw(t,e.extend({clip:!0})),this._draw(t,e),t.restore(),i&&n.pop(),e.clip&&t.clip(),f||(K.process(u,t,a,l,h.subtract(o)),$.release(t),e.offset=o)}},_canComposite:function(){return!1}},e.each(["down","drag","up","move"],function(t){this["removeOn"+e.capitalize(t)]=function(){var e={};return e[t]=!0,this.removeOn(e)}},{removeOn:function(t){for(var e in t)if(t[e]){var i="mouse"+e,n=this._project,r=n._removeSets=n._removeSets||{};r[i]=r[i]||{},r[i][this._id]=this}return this}})),w=y.extend({_class:"Group",_serializeFields:{children:[]},initialize:function(t){this._children=[],this._namedChildren={},this._initialize(t)||this.addChildren(Array.isArray(t)?t:arguments)},_changed:function oe(t){oe.base.call(this,t),2&t&&this._transformContent&&!this._matrix.isIdentity()&&this.applyMatrix(),258&t&&delete this._clipItem},_getClipItem:function(){if(this._clipItem!==t)return this._clipItem;for(var e=0,i=this._children.length;i>e;e++){var n=this._children[e];if(n._clipMask)return this._clipItem=n}return this._clipItem=null},getTransformContent:function(){return this._transformContent},setTransformContent:function(t){this._transformContent=t,t&&this.applyMatrix()},isClipped:function(){return!!this._getClipItem()},setClipped:function(t){var e=this.getFirstChild();e&&e.setClipMask(t)},_draw:function(t,e){var i=e.clipItem=this._getClipItem();i&&i.draw(t,e.extend({clip:!0}));for(var n=0,r=this._children.length;r>n;n++){var s=this._children[n];s!==i&&s.draw(t,e)}e.clipItem=null}}),x=w.extend({_class:"Layer",initialize:function(){this._project=paper.project,this._index=this._project.layers.push(this)-1,w.apply(this,arguments),this.activate()},_remove:function ue(t){return this._parent?ue.base.call(this,t):null!=this._index?(this._project.activeLayer===this&&(this._project.activeLayer=this.getNextSibling()||this.getPreviousSibling()),e.splice(this._project.layers,null,this._index,1),this._project._needsRedraw=!0,!0):!1},getNextSibling:function le(){return this._parent?le.base.call(this):this._project.layers[this._index+1]||null},getPreviousSibling:function ce(){return this._parent?ce.base.call(this):this._project.layers[this._index-1]||null},isInserted:function de(){return this._parent?de.base.call(this):null!=this._index},activate:function(){this._project.activeLayer=this},_insert:function _e(t,i,n){return i instanceof x&&!i._parent&&this._remove(!0)?(e.splice(i._project.layers,[this],i._index+(t?1:0),0),this._setProject(i._project),this):_e.base.call(this,t,i,n)}}),b=y.extend({_class:"Shape",_transformContent:!1,_boundsSelected:!0,initialize:function(t,e,i,n,r){this._shape=t,this._size=i,this._radius=n,this._initialize(r,e)},_equals:function(t){return this._shape===t._shape&&this._size.equals(t._size)&&e.equals(this._radius,t._radius)},clone:function(t){return this._clone(new b(this._shape,this.getPosition(!0),this._size.clone(),this._radius.clone?this._radius.clone():this._radius,{insert:!1}),t)},getShape:function(){return this._shape},getSize:function(){var t=this._size;return new d(t.width,t.height,this,"setSize")},setSize:function(){var t=this._shape,e=c.read(arguments);if(!this._size.equals(e)){var i=e.width,n=e.height;if("rectangle"===t){var r=c.min(this._radius,e.divide(2));this._radius.set(r.width,r.height)}else"circle"===t?(i=n=(i+n)/2,this._radius=i/2):"ellipse"===t&&this._radius.set(i/2,n/2);this._size.set(i,n),this._changed(5)}},getRadius:function(){var t=this._radius;return"circle"===this._shape?t:new d(t.width,t.height,this,"setRadius")},setRadius:function(t){var e=this._shape;if("circle"===e){if(t===this._radius)return;var i=2*t;this._size.set(i,i)}else{if(t=c.read(arguments),this._radius.equals(t))return;if(this._radius.set(t.width,t.height),"rectangle"===e){var i=c.max(this._size,t.multiply(2));this._size.set(i.width,i.height)}else"ellipse"===e&&this._size.set(2*t.width,2*t.height)}this._changed(5)},isEmpty:function(){return!1},toPath:function(i){var n=new(O[e.capitalize(this._shape)])({center:new o,size:this._size,radius:this._radius,insert:!1});return n.transform(this._matrix),n.setStyle(this._style),(i||i===t)&&n.insertAbove(this),n},_draw:function(t,e){var i=this._style,n=i.hasFill(),r=i.hasStroke(),s=e.clip;if(n||r||s){var a=this._radius,o=this._shape;if(t.beginPath(),"circle"===o)t.arc(0,0,a,0,2*Math.PI,!0);else{var u=a.width,l=a.height,c=h.KAPPA;if("ellipse"===o){var d=u*c,_=l*c;t.moveTo(-u,0),t.bezierCurveTo(-u,-_,-d,-l,0,-l),t.bezierCurveTo(d,-l,u,-_,u,0),t.bezierCurveTo(u,_,d,l,0,l),t.bezierCurveTo(-d,l,-u,_,-u,0)}else{var f=this._size,g=f.width,m=f.height;if(0===u&&0===l)t.rect(-g/2,-m/2,g,m);else{c=1-c;var v=g/2,p=m/2,d=u*c,_=l*c;t.moveTo(-v,-p+l),t.bezierCurveTo(-v,-p+_,-v+d,-p,-v+u,-p),t.lineTo(v-u,-p),t.bezierCurveTo(v-d,-p,v,-p+_,v,-p+l),t.lineTo(v,p-l),t.bezierCurveTo(v,p-_,v-d,p,v-u,p),t.lineTo(-v+u,p),t.bezierCurveTo(-v+d,p,-v,p-_,-v,p-l)}}}t.closePath()}s||!n&&!r||(this._setStyles(t),n&&t.fill(i.getWindingRule()),r&&t.stroke())},_canComposite:function(){return!(this.hasFill()&&this.hasStroke())},_getBounds:function(t,e){var i=new _(this._size).setCenter(0,0);return"getBounds"!==t&&this.hasStroke()&&(i=i.expand(this.getStrokeWidth())),e?e._transformBounds(i):i}},new function(){function t(t,e,i){var n=t._radius;if(!n.isZero())for(var r=t._size.divide(2),s=0;4>s;s++){var a=new o(1&s?1:-1,s>1?1:-1),h=a.multiply(r),u=h.subtract(a.multiply(n)),l=new _(h,u);if((i?l.expand(i):l).contains(e))return u}}function e(t,e){var i=t.getAngleInRadians(),n=2*e.width,r=2*e.height,s=n*Math.sin(i),a=r*Math.cos(i);return n*r/(2*Math.sqrt(s*s+a*a))}return{_contains:function i(e){if("rectangle"===this._shape){var n=t(this,e);return n?e.subtract(n).divide(this._radius).getLength()<=1:i.base.call(this,e)}return e.divide(this.size).getLength()<=.5},_hitTest:function n(i,r){var s=!1;if(this.hasStroke()){var a=this._shape,h=this._radius,o=this.getStrokeWidth()+2*r.tolerance;if("rectangle"===a){var u=t(this,i,o);if(u){var l=i.subtract(u);s=2*Math.abs(l.getLength()-e(l,h))<=o}else{var c=new _(this._size).setCenter(0,0),d=c.expand(o),f=c.expand(-o);s=d._containsPoint(i)&&!f._containsPoint(i)}}else"ellipse"===a&&(h=e(i,h)),s=2*Math.abs(i.getLength()-h)<=o}return s?new P("stroke",this):n.base.apply(this,arguments)}}},{statics:new function(){function t(t,i,n,r,s){return new b(t,i,n,r,e.getNamed(s))}return{Circle:function(){var i=o.readNamed(arguments,"center"),n=e.readNamed(arguments,"radius");return t("circle",i,new c(2*n),n,arguments)},Rectangle:function(){var e=_.readNamed(arguments,"rectangle"),i=c.min(c.readNamed(arguments,"radius"),e.getSize(!0).divide(2));return t("rectangle",e.getCenter(!0),e.getSize(!0),i,arguments)},Ellipse:function(){var e=b._readEllipse(arguments);return radius=e.radius,t("ellipse",e.center,radius.multiply(2),radius,arguments)},_readEllipse:function(t){var i,n;if(e.hasNamed(t,"radius"))i=o.readNamed(t,"center"),n=c.readNamed(t,"radius");else{var r=_.readNamed(t,"rectangle");i=r.getCenter(!0),n=r.getSize(!0).divide(2)}return{center:i,radius:n}}}}}),C=y.extend({_class:"Raster",_transformContent:!1,_boundsGetter:"getBounds",_boundsSelected:!0,_serializeFields:{source:null},initialize:function(e,i){this._initialize(e,i!==t&&o.read(arguments,1))||("string"==typeof e?this.setSource(e):this.setImage(e)),this._size||(this._size=new c)},_equals:function(t){return this.getSource()===t.getSource()},clone:function(t){var e={insert:!1},i=this._image;if(i)e.image=i;else if(this._canvas){var n=e.canvas=$.getCanvas(this._size);n.getContext("2d").drawImage(this._canvas,0,0)}return this._clone(new C(e),t)},getSize:function(){var t=this._size;return new d(t.width,t.height,this,"setSize")},setSize:function(){var t=c.read(arguments);if(!this._size.equals(t)){var e=this.getElement();this.setCanvas($.getCanvas(t)),e&&this.getContext(!0).drawImage(e,0,0,t.width,t.height)}},getWidth:function(){return this._size.width},getHeight:function(){return this._size.height},isEmpty:function(){return 0==this._size.width&&0==this._size.height},getPpi:function(){var t=this._matrix,e=new o(0,0).transform(t),i=new o(1,0).transform(t).subtract(e),n=new o(0,1).transform(t).subtract(e);return new c(72/i.getLength(),72/n.getLength())},getImage:function(){return this._image},setImage:function(t){this._canvas&&$.release(this._canvas),t.getContext?(this._image=null,this._canvas=t):(this._image=t,this._canvas=null),this._size=new c(t.naturalWidth||t.width,t.naturalHeight||t.height),this._context=null,this._changed(133)},getCanvas:function(){if(!this._canvas){var t=$.getContext(this._size);try{this._image&&t.drawImage(this._image,0,0),this._canvas=t.canvas}catch(e){$.release(t)}}return this._canvas},setCanvas:"#setImage",getContext:function(){return this._context||(this._context=this.getCanvas().getContext("2d")),arguments[0]&&(this._image=null,this._changed(129)),this._context},setContext:function(t){this._context=t},getSource:function(){return this._image&&this._image.src||this.toDataURL()},setSource:function(t){function e(){var t=i._project.view;t&&(paper=t._scope),i.fire("load"),t&&t.draw(!0)}var i=this,n=document.getElementById(t)||new Image;n.naturalWidth&&n.naturalHeight?setTimeout(e,0):(V.add(n,{load:function(){i.setImage(n),e()}}),n.src||(n.src=t)),this.setImage(n)},getElement:function(){return this._canvas||this._image},getSubCanvas:function(t){t=_.read(arguments);var e=$.getContext(t.getSize());return e.drawImage(this.getCanvas(),t.x,t.y,t.width,t.height,0,0,t.width,t.height),e.canvas},getSubRaster:function(t){t=_.read(arguments);var e=new C({canvas:this.getSubCanvas(t),insert:!1});return e.translate(t.getCenter().subtract(this.getSize().divide(2))),e._matrix.preConcatenate(this._matrix),e.insertAbove(this),e},toDataURL:function(){var t=this._image&&this._image.src;if(/^data:/.test(t))return t;var e=this.getCanvas();return e?e.toDataURL():null},drawImage:function(t,e){e=o.read(arguments,1),this.getContext(!0).drawImage(t,e.x,e.y) -},getAverageColor:function(t){var i,n;t?t instanceof A?(n=t,i=t.getBounds()):t.width?i=new _(t):t.x&&(i=new _(t.x-.5,t.y-.5,1,1)):i=this.getBounds();var r=32,s=Math.min(i.width,r),a=Math.min(i.height,r),h=C._sampleContext;h?h.clearRect(0,0,r+1,r+1):h=C._sampleContext=$.getContext(new c(r)),h.save();var o=(new g).scale(s/i.width,a/i.height).translate(-i.x,-i.y);o.applyToContext(h),n&&n.draw(h,e.merge({clip:!0,transforms:[o]})),this._matrix.applyToContext(h),h.drawImage(this.getElement(),-this._size.width/2,-this._size.height/2),h.restore();for(var u=h.getImageData(.5,.5,Math.ceil(s),Math.ceil(a)).data,l=[0,0,0],d=0,f=0,m=u.length;m>f;f+=4){var v=u[f+3];d+=v,v/=255,l[0]+=u[f]*v,l[1]+=u[f+1]*v,l[2]+=u[f+2]*v}for(var f=0;3>f;f++)l[f]/=d;return d?B.read(l):null},getPixel:function(t){t=o.read(arguments);var e=this.getContext().getImageData(t.x,t.y,1,1).data;return new B("rgb",[e[0]/255,e[1]/255,e[2]/255],e[3]/255)},setPixel:function(){var t=o.read(arguments),e=B.read(arguments),i=e._convert("rgb"),n=e._alpha,r=this.getContext(!0),s=r.createImageData(1,1),a=s.data;a[0]=255*i[0],a[1]=255*i[1],a[2]=255*i[2],a[3]=null!=n?255*n:255,r.putImageData(s,t.x,t.y)},createImageData:function(t){return t=c.read(arguments),this.getContext().createImageData(t.width,t.height)},getImageData:function(t){return t=_.read(arguments),t.isEmpty()&&(t=new _(this._size)),this.getContext().getImageData(t.x,t.y,t.width,t.height)},setImageData:function(t,e){e=o.read(arguments,1),this.getContext(!0).putImageData(t,e.x,e.y)},_getBounds:function(t,e){var i=new _(this._size).setCenter(0,0);return e?e._transformBounds(i):i},_hitTest:function(t){if(this._contains(t)){var e=this;return new P("pixel",e,{offset:t.add(e._size.divide(2)).round(),color:{get:function(){return e.getPixel(this.offset)}}})}},_draw:function(t){var e=this.getElement();e&&(t.globalAlpha=this._opacity,t.drawImage(e,-this._size.width/2,-this._size.height/2))},_canComposite:function(){return!0}}),S=y.extend({_class:"PlacedSymbol",_transformContent:!1,_boundsGetter:{getBounds:"getStrokeBounds"},_boundsSelected:!0,_serializeFields:{symbol:null},initialize:function(e,i){this._initialize(e,i!==t&&o.read(arguments,1))||this.setSymbol(e instanceof p?e:new p(e))},_equals:function(t){return this._symbol===t._symbol},getSymbol:function(){return this._symbol},setSymbol:function(t){this._symbol&&delete this._symbol._instances[this._id],this._symbol=t,t._instances[this._id]=this},clone:function(t){return this._clone(new S({symbol:this.symbol,insert:!1}),t)},isEmpty:function(){return this._symbol._definition.isEmpty()},_getBounds:function(t,e){return this.symbol._definition._getCachedBounds(t,e)},_hitTest:function(t,e,i){var n=this._symbol._definition._hitTest(t,e,i);return n&&(n.item=this),n},_draw:function(t,e){this.symbol._definition.draw(t,e)}}),P=e.extend({_class:"HitResult",initialize:function(t,e,i){this.type=t,this.item=e,i&&(i.enumerable=!0,this.inject(i))},statics:{getOptions:function(t){return t&&t._merged?t:e.merge({type:null,tolerance:paper.project.options.hitTolerance||2,fill:!t,stroke:!t,segments:!t,handles:!1,ends:!1,center:!1,bounds:!1,guides:!1,selected:!1,_merged:!0},t)}}}),z=e.extend({_class:"Segment",initialize:function(e,i,n,r,s,a){var h,o,u,l=arguments.length;0===l||(1===l?e.point?(h=e.point,o=e.handleIn,u=e.handleOut):h=e:2===l&&"number"==typeof e?h=arguments:3>=l?(h=e,o=i,u=n):(h=e!==t?[e,i]:null,o=n!==t?[n,r]:null,u=s!==t?[s,a]:null)),new M(h,this,"_point"),new M(o,this,"_handleIn"),new M(u,this,"_handleOut")},_serialize:function(t){return e.serialize(this.isLinear()?this._point:[this._point,this._handleIn,this._handleOut],t,!0)},_changed:function(t){if(this._path){var e,i=this._path._curves&&this.getCurve();i&&(i._changed(),(e=i[t==this._point||t==this._handleIn&&i._segment1==this?"getPrevious":"getNext"]())&&e._changed()),this._path._changed(5)}},getPoint:function(){return this._point},setPoint:function(t){t=o.read(arguments),this._point.set(t.x,t.y)},getHandleIn:function(){return this._handleIn},setHandleIn:function(t){t=o.read(arguments),this._handleIn.set(t.x,t.y)},getHandleOut:function(){return this._handleOut},setHandleOut:function(t){t=o.read(arguments),this._handleOut.set(t.x,t.y)},isLinear:function(){return this._handleIn.isZero()&&this._handleOut.isZero()},setLinear:function(){this._handleIn.set(0,0),this._handleOut.set(0,0)},isColinear:function(t){var e=this.getNext(),i=t.getNext();return this._handleOut.isZero()&&e._handleIn.isZero()&&t._handleOut.isZero()&&i._handleIn.isZero()&&e._point.subtract(this._point).isColinear(i._point.subtract(t._point))},isOrthogonal:function(){var t=this.getPrevious(),e=this.getNext();return t._handleOut.isZero()&&this._handleIn.isZero()&&this._handleOut.isZero()&&e._handleIn.isZero()&&this._point.subtract(t._point).isOrthogonal(e._point.subtract(this._point))},isArc:function(){var t=this.getNext(),e=this._handleOut,i=t._handleIn,n=h.KAPPA;if(e.isOrthogonal(i)){var r=this._point,s=t._point,a=new m(r,e,!0).intersect(new m(s,i,!0),!0);return a&&h.isZero(e.getLength()/a.subtract(r).getLength()-n)&&h.isZero(i.getLength()/a.subtract(s).getLength()-n)}return!1},_isSelected:function(t){var e=this._selectionState;return t==this._point?!!(4&e):t==this._handleIn?!!(1&e):t==this._handleOut?!!(2&e):!1},_setSelected:function(t,e){var i=this._path,e=!!e,n=this._selectionState||0,r=[!!(4&n),!!(1&n),!!(2&n)];if(t===this._point){if(e)r[1]=r[2]=!1;else{var s=this.getPrevious(),a=this.getNext();r[1]=s&&(s._point.isSelected()||s._handleOut.isSelected()),r[2]=a&&(a._point.isSelected()||a._handleIn.isSelected())}r[0]=e}else{var h=t===this._handleIn?1:2;r[h]!=e&&(e&&(r[0]=!1),r[h]=e)}this._selectionState=(r[0]?4:0)|(r[1]?1:0)|(r[2]?2:0),i&&n!=this._selectionState&&(i._updateSelection(this,n,this._selectionState),i._changed(33))},isSelected:function(){return this._isSelected(this._point)},setSelected:function(t){this._setSelected(this._point,t)},getIndex:function(){return this._index!==t?this._index:null},getPath:function(){return this._path||null},getCurve:function(){var t=this._path,e=this._index;return t?(t._closed||e!=t._segments.length-1||e--,t.getCurves()[e]||null):null},getLocation:function(){var t=this.getCurve();return t?new k(t,t.getNext()?0:1):null},getNext:function(){var t=this._path&&this._path._segments;return t&&(t[this._index+1]||this._path._closed&&t[0])||null},getPrevious:function(){var t=this._path&&this._path._segments;return t&&(t[this._index-1]||this._path._closed&&t[t.length-1])||null},reverse:function(){return new z(this._point,this._handleOut,this._handleIn)},remove:function(){return this._path?!!this._path.removeSegment(this._index):!1},clone:function(){return new z(this._point,this._handleIn,this._handleOut)},equals:function(t){return t===this||t&&this._class===t._class&&this._point.equals(t._point)&&this._handleIn.equals(t._handleIn)&&this._handleOut.equals(t._handleOut)||!1},toString:function(){var t=["point: "+this._point];return this._handleIn.isZero()||t.push("handleIn: "+this._handleIn),this._handleOut.isZero()||t.push("handleOut: "+this._handleOut),"{ "+t.join(", ")+" }"},_transformCoordinates:function(t,e,i){var n=this._point,r=i&&this._handleIn.isZero()?null:this._handleIn,s=i&&this._handleOut.isZero()?null:this._handleOut,a=n._x,h=n._y,o=2;return e[0]=a,e[1]=h,r&&(e[o++]=r._x+a,e[o++]=r._y+h),s&&(e[o++]=s._x+a,e[o++]=s._y+h),t&&(t._transformCoordinates(e,0,e,0,o/2),a=e[0],h=e[1],i?(n._x=a,n._y=h,o=2,r&&(r._x=e[o++]-a,r._y=e[o++]-h),s&&(s._x=e[o++]-a,s._y=e[o++]-h)):(r||(e[o++]=a,e[o++]=h),s||(e[o++]=a,e[o++]=h))),e}}),M=o.extend({initialize:function(e,i,n){var r,s,a;e?(r=e[0])!==t?s=e[1]:((r=e.x)===t&&(e=o.read(arguments),r=e.x),s=e.y,a=e.selected):r=s=0,this._x=r,this._y=s,this._owner=i,i[n]=this,a&&this.setSelected(!0)},set:function(t,e){return this._x=t,this._y=e,this._owner._changed(this),this},_serialize:function(t){var e=t.formatter,i=e.number(this._x),n=e.number(this._y);return this.isSelected()?{x:i,y:n,selected:!0}:[i,n]},getX:function(){return this._x},setX:function(t){this._x=t,this._owner._changed(this)},getY:function(){return this._y},setY:function(t){this._y=t,this._owner._changed(this)},isZero:function(){return h.isZero(this._x)&&h.isZero(this._y)},setSelected:function(t){this._owner._setSelected(this,t)},isSelected:function(){return this._owner._isSelected(this)}}),I=e.extend({_class:"Curve",initialize:function(t,e,i,n,r,s,a,h){var o=arguments.length;if(3===o)this._path=t,this._segment1=e,this._segment2=i;else if(0===o)this._segment1=new z,this._segment2=new z;else if(1===o)this._segment1=new z(t.segment1),this._segment2=new z(t.segment2);else if(2===o)this._segment1=new z(t),this._segment2=new z(e);else{var u,l,c,d;4===o?(u=t,l=e,c=i,d=n):8===o&&(u=[t,e],d=[a,h],l=[i-t,n-e],c=[r-a,s-h]),this._segment1=new z(u,null,l),this._segment2=new z(d,c,null)}},_changed:function(){delete this._length,delete this._bounds},getPoint1:function(){return this._segment1._point},setPoint1:function(t){t=o.read(arguments),this._segment1._point.set(t.x,t.y)},getPoint2:function(){return this._segment2._point},setPoint2:function(t){t=o.read(arguments),this._segment2._point.set(t.x,t.y)},getHandle1:function(){return this._segment1._handleOut},setHandle1:function(t){t=o.read(arguments),this._segment1._handleOut.set(t.x,t.y)},getHandle2:function(){return this._segment2._handleIn},setHandle2:function(t){t=o.read(arguments),this._segment2._handleIn.set(t.x,t.y)},getSegment1:function(){return this._segment1},getSegment2:function(){return this._segment2},getPath:function(){return this._path},getIndex:function(){return this._segment1._index},getNext:function(){var t=this._path&&this._path._curves;return t&&(t[this._segment1._index+1]||this._path._closed&&t[0])||null},getPrevious:function(){var t=this._path&&this._path._curves;return t&&(t[this._segment1._index-1]||this._path._closed&&t[t.length-1])||null},isSelected:function(){return this.getHandle1().isSelected()&&this.getHandle2().isSelected()},setSelected:function(t){this.getHandle1().setSelected(t),this.getHandle2().setSelected(t)},getValues:function(){return I.getValues(this._segment1,this._segment2)},getPoints:function(){for(var t=this.getValues(),e=[],i=0;8>i;i+=2)e.push(new o(t[i],t[i+1]));return e},getLength:function(){var t=arguments[0],e=arguments[1],i=0===arguments.length||0===t&&1===e;if(i&&null!=this._length)return this._length;var n=I.getLength(this.getValues(),t,e);return i&&(this._length=n),n},getArea:function(){return I.getArea(this.getValues())},getPart:function(t,e){return new I(I.getPart(this.getValues(),t,e))},isLinear:function(){return this._segment1._handleOut.isZero()&&this._segment2._handleIn.isZero()},getIntersections:function(t){return I.getIntersections(this.getValues(),t.getValues(),this,t,[])},reverse:function(){return new I(this._segment2.reverse(),this._segment1.reverse())},_getParameter:function(e,i){return i?e:e&&e.curve===this?e.parameter:e===t&&i===t?.5:this.getParameterAt(e,0)},divide:function(t,e){var i=this._getParameter(t,e),n=null;if(i>0&&1>i){var r=I.subdivide(this.getValues(),i),s=this.isLinear(),a=r[0],h=r[1];s||(this._segment1._handleOut.set(a[2]-a[0],a[3]-a[1]),this._segment2._handleIn.set(h[4]-h[6],h[5]-h[7]));var u=a[6],l=a[7],c=new z(new o(u,l),!s&&new o(a[4]-u,a[5]-l),!s&&new o(h[2]-u,h[3]-l));if(this._path)this._segment1._index>0&&0===this._segment2._index?this._path.add(c):this._path.insert(this._segment2._index,c),n=this;else{var d=this._segment2;this._segment2=c,n=new I(c,d)}}return n},split:function(t,e){return this._path?this._path.split(this._segment1._index,this._getParameter(t,e)):null},clone:function(){return new I(this._segment1,this._segment2)},toString:function(){var t=["point1: "+this._segment1._point];return this._segment1._handleOut.isZero()||t.push("handle1: "+this._segment1._handleOut),this._segment2._handleIn.isZero()||t.push("handle2: "+this._segment2._handleIn),t.push("point2: "+this._segment2._point),"{ "+t.join(", ")+" }"},statics:{getValues:function(t,e){var i=t._point,n=t._handleOut,r=e._handleIn,s=e._point;return[i._x,i._y,i._x+n._x,i._y+n._y,s._x+r._x,s._y+r._y,s._x,s._y]},evaluate:function(t,e,i){var n,r,s=t[0],a=t[1],h=t[2],u=t[3],l=t[4],c=t[5],d=t[6],_=t[7];if(0!==i||0!==e&&1!==e){var f=3*(h-s),g=3*(l-h)-f,m=d-s-f-g,v=3*(u-a),p=3*(c-u)-v,y=_-a-v-p;if(0===i)n=((m*e+g)*e+f)*e+s,r=((y*e+p)*e+v)*e+a;else{var w=1e-5;if(w>e&&h==s&&u==a||e>1-w&&l==d&&c==_?(n=l-h,r=c-u):(n=(3*m*e+2*g)*e+f,r=(3*y*e+2*p)*e+v),3===i){var x=6*m*e+2*g,b=6*y*e+2*p;return(n*b-r*x)/Math.pow(n*n+r*r,1.5)}}}else n=0===e?s:d,r=0===e?a:_;return 2==i?new o(r,-n):new o(n,r)},subdivide:function(e,i){var n=e[0],r=e[1],s=e[2],a=e[3],h=e[4],o=e[5],u=e[6],l=e[7];i===t&&(i=.5);var c=1-i,d=c*n+i*s,_=c*r+i*a,f=c*s+i*h,g=c*a+i*o,m=c*h+i*u,v=c*o+i*l,p=c*d+i*f,y=c*_+i*g,w=c*f+i*m,x=c*g+i*v,b=c*p+i*w,C=c*y+i*x;return[[n,r,d,_,p,y,b,C],[b,C,w,x,m,v,u,l]]},solveCubic:function(t,e,i,n,r,s){var a=t[e],o=t[e+2],u=t[e+4],l=t[e+6],c=3*(o-a),d=3*(u-o)-c,_=l-a-c-d;return h.solveCubic(_,d,c,a-i,n,r,s)},getParameterOf:function(t,e,i){if(Math.abs(t[0]-e)<1e-5&&Math.abs(t[1]-i)<1e-5)return 0;if(Math.abs(t[6]-e)<1e-5&&Math.abs(t[7]-i)<1e-5)return 1;for(var n,r,s=[],a=[],h=I.solveCubic(t,0,e,s),o=I.solveCubic(t,1,i,a),u=0;-1==h||h>u;)if(-1==h||(n=s[u++])>=0&&1>=n){for(var l=0;-1==o||o>l;)if((-1==o||(r=a[l++])>=0&&1>=r)&&(-1==h?n=r:-1==o&&(r=n),Math.abs(n-r)<1e-5))return.5*(n+r);if(-1==h)break}return null},getPart:function(t,e,i){return e>0&&(t=I.subdivide(t,e)[1]),1>i&&(t=I.subdivide(t,(i-e)/(1-e))[0]),t},isLinear:function(t){var e=h.isZero;return e(t[0]-t[2])&&e(t[1]-t[3])&&e(t[4]-t[6])&&e(t[5]-t[7])},isFlatEnough:function(t,e){var i=t[0],n=t[1],r=t[2],s=t[3],a=t[4],h=t[5],o=t[6],u=t[7],l=3*r-2*i-o,c=3*s-2*n-u,d=3*a-2*o-i,_=3*h-2*u-n;return Math.max(l*l,d*d)+Math.max(c*c,_*_)<10*e*e},getArea:function(t){var e=t[0],i=t[1],n=t[2],r=t[3],s=t[4],a=t[5],h=t[6],o=t[7];return(3*r*e-1.5*r*s-1.5*r*h-3*i*n-1.5*i*s-.5*i*h+1.5*a*e+1.5*a*n-3*a*h+.5*o*e+1.5*o*n+3*o*s)/10},getBounds:function(t){for(var e=t.slice(0,2),i=e.slice(),n=[0,0],r=0;2>r;r++)I._addBounds(t[r],t[r+2],t[r+4],t[r+6],r,0,e,i,n);return new _(e[0],e[1],i[0]-e[0],i[1]-e[1])},_addBounds:function(t,e,i,n,r,s,a,o,u){function l(t,e){var i=t-e,n=t+e;io[r]&&(o[r]=n)}var c=3*(e-i)-t+n,d=2*(t+i)-4*e,_=e-t,f=h.solveQuadratic(c,d,_,u),g=1e-5,m=1-g;l(n,0);for(var v=0;f>v;v++){var p=u[v],y=1-p;p>g&&m>p&&l(y*y*y*t+3*y*y*p*e+3*y*p*p*i+p*p*p*n,s)}},_getWinding:function(t,e,i,n,r){function s(t){var e=t[1],n=t[7],r=1;if(e>n){var s=e;e=n,n=s,r=-1}return(e>i||i>n)&&(r=0),r}var a=1e-5,o=Math.abs;if(I.isLinear(t)){var u=s(t);if(!u)return 0;var l=(t[6]-t[0])*(i-t[1])-(t[7]-t[1])*(e-t[0]);return(-a>l?-1:1)==u?0:u}for(var c,d=t[1],_=t[3],f=t[5],g=t[7],m=3*(_-f)-d+g,v=2*(d+f)-4*_,p=_-d,y=h.solveQuadratic(m,v,p,n,a,1-a),w=t,x=n[0],b=0,C=0;y>=C;C++){if(C===y)c=w;else{var S=I.subdivide(w,x);c=S[0],w=S[1],x=n[C],x=(n[C+1]-x)/(1-x)}C>0&&(c[3]=c[1]),y>C&&(c[5]=w[1]);var u=s(c);if(u){var P,z;if(1===I.solveCubic(c,1,i,r,-a,1+-a))P=r[0],z=I.evaluate(c,P,0).x;else{var M=(c[1]+c[7])/2;if(P=M>i&&u>0?0:1,1===P&&i==c[7])continue;z=0===P?c[0]:c[6]}var k=o(I.evaluate(c,P,1).y)=z+(k?-a:a*u))||k&&(o(P)0?1:0))e?1:0)},getParameterOf:function(t){return t=o.read(arguments),I.getParameterOf(this.getValues(),t.x,t.y)},getLocationAt:function(t,e){return e||(t=this.getParameterAt(t)),new k(this,t)},getLocationOf:function(t){t=o.read(arguments);var e=this.getParameterOf(t);return null!=e?new k(this,e):null},getNearestLocation:function(t){function e(e){if(e>=0&&1>=e){var n=t.getDistance(I.evaluate(i,e,0),!0);if(s>n)return s=n,a=e,!0}}t=o.read(arguments);for(var i=this.getValues(),n=100,r=h.TOLERANCE,s=1/0,a=0,u=0;n>=u;u++)e(u/n);for(var l=1/(2*n);l>r;)e(a-l)||e(a+l)||(l/=2);var c=I.evaluate(i,a,0);return new k(this,a,c,null,null,null,t.getDistance(c))},getNearestPoint:function(t){return t=o.read(arguments),this.getNearestLocation(t).getPoint()}}),new function(){function e(t){var e=t[0],i=t[1],n=t[2],r=t[3],s=t[4],a=t[5],h=t[6],o=t[7],u=9*(n-s)+3*(h-e),l=6*(e+s)-12*n,c=3*(n-e),d=9*(r-a)+3*(o-i),_=6*(i+a)-12*r,f=3*(r-i);return function(t){var e=(u*t+l)*t+c,i=(d*t+_)*t+f;return Math.sqrt(e*e+i*i)}}function i(t,e){return Math.max(2,Math.min(16,Math.ceil(32*Math.abs(e-t))))}return{statics:!0,getLength:function(n,r,s){r===t&&(r=0),s===t&&(s=1);var a=h.isZero;if(a(n[0]-n[2])&&a(n[1]-n[3])&&a(n[6]-n[4])&&a(n[7]-n[5])){var o=n[6]-n[0],u=n[7]-n[1];return(s-r)*Math.sqrt(o*o+u*u)}var l=e(n);return h.integrate(l,r,s,i(r,s))},getParameterAt:function(t,n,r){function s(t){var e=i(r,t);return _+=t>r?h.integrate(l,r,t,e):-h.integrate(l,t,r,e),r=t,_-n}if(0===n)return r;var a=n>0,o=a?r:0,u=a?1:r,n=Math.abs(n),l=e(t),c=h.integrate(l,o,u,i(o,u));if(n>=c)return a?u:o;var d=n/c,_=0;return h.findRoot(s,l,a?o+d:u-d,o,u,16,1e-5)}}},new function(){function t(t,e,i,n,r,s,a){var h=t[0],o=t[t.length-1];h&&n.equals(h._point)||o&&n.equals(o._point)||t.push(new k(e,i,n,r,s,a))}function e(n,r,s,a,h,o,u,l){if(l=(l||0)+1,!(l>20)){o=o||[0,1],u=u||[0,1];for(var c=I.getPart(n,o[0],o[1]),d=I.getPart(r,u[0],u[1]),_=0;_++<20;){var f,g=i(c,d,f=u.slice()),m=0;if(0===g)break;if(g>0){if(u=f,d=I.getPart(r,u[0],u[1]),m=i(d,c,f=o.slice()),0===m)break;g>0&&(o=f,c=I.getPart(n,o[0],o[1]))}if(0>g||0>m){if(o[1]-o[0]>u[1]-u[0]){var v=(o[0]+o[1])/2;e(n,r,s,a,h,[o[0],v],u,l),e(n,r,s,a,h,[v,o[1]],u,l);break}var v=(u[0]+u[1])/2;e(n,r,s,a,h,o,[u[0],v],l),e(n,r,s,a,h,o,[v,u[1]],l);break}if(Math.abs(o[1]-o[0])<=1e-5&&Math.abs(u[1]-u[0])<=1e-5){var p=(o[0]+o[1])/2,y=(u[0]+u[1])/2;t(h,s,p,I.evaluate(n,p,0),a,y,I.evaluate(r,y,0));break}}}}function i(t,e,i){var r=t[0],s=t[1],a=t[2],h=t[3],o=t[4],u=t[5],l=t[6],c=t[7],d=e[0],_=e[1],f=e[2],g=e[3],v=e[4],p=e[5],y=e[6],w=e[7],x=m.getSignedDistance,b=x(r,s,l,c,a,h)||0,C=x(r,s,l,c,o,u)||0,S=b*C>0?.75:4/9,P=S*Math.min(0,b,C),z=S*Math.max(0,b,C),M=x(r,s,l,c,d,_),k=x(r,s,l,c,f,g),A=x(r,s,l,c,v,p),O=x(r,s,l,c,y,w);if(P>Math.max(M,k,A,O)||zO&&(L=P,P=z,z=L);for(var D=-1/0,N=1/0,j=-1/0,B=0,F=T.length;F>B;B++){var q=T[B],E=T[(B+1)%F];E[1]=V&&H>=P){var G=R+(P-V)/W;N>G&&(N=G),G>D&&(D=G)}if(z>=V&&H>=z){var G=R+(z-V)/W;G>j&&(j=G),N>G&&(N=0)}}if(1/0!==N&&j!==-1/0){var X=Math.min(P,z),J=Math.max(P,z);O>X&&J>O&&(j=1),M>X&&J>M&&(N=0),D>j&&(j=1);var Y=i[0],U=i[1]-Y;if(i[0]=Y+N*U,i[1]=Y+j*U,(U-(i[1]-i[0]))/U>=.2)return 1}return I.getBounds(t).touches(I.getBounds(e))?-1:0}function n(t,e,i,n){var r=[0,t],s=[1/3,e],a=[2/3,i],h=[1,n],o=m.getSignedDistance,u=o(0,t,1,n,1/3,e),l=o(0,t,1,n,2/3,i);if(0>u*l)return[r,s,h,a];var c,d;return Math.abs(u)>Math.abs(l)?(c=s,d=(n-i-(n-t)/3)*(2*(n-i)-n+e)/3):(c=a,d=(e-t+(t-n)/3)*(-2*(t-e)+t-i)/3),0>d?[r,c,h]:[r,s,a,h]}function r(e,i,n,r,s){for(var a=I.isLinear(e),h=a?i:e,o=a?e:i,u=o[0],l=o[1],c=o[6],d=o[7],_=c-u,f=d-l,g=Math.atan2(-f,_),m=Math.sin(g),v=Math.cos(g),p=_*v-f*m,y=[0,0,0,0,p,0,p,0],w=[],x=0;8>x;x+=2){var b=h[x]-u,C=h[x+1]-l;w.push(b*v-C*m,C*v+b*m)}for(var S=[],P=I.solveCubic(w,1,0,S,0,1),x=0;P>x;x++){var z=S[x],b=I.evaluate(w,z,0).x;if(b>=0&&p>=b){var M=I.getParameterOf(y,b,0),k=a?M:z,A=a?z:M;t(s,n,k,I.evaluate(e,k,0),r,A,I.evaluate(i,A,0))}}}function s(e,i,n,r,s){var a=m.intersect(e[0],e[1],e[6],e[7],i[0],i[1],i[6],i[7]);a&&t(s,n,null,a,r)}return{statics:{getIntersections:function(t,i,n,a,h){var o=I.isLinear(t),u=I.isLinear(i);return(o&&u?s:o||u?r:e)(t,i,n,a,h),h}}}}),k=e.extend({_class:"CurveLocation",initialize:function fe(t,e,i,n,r,s,a){this._id=fe._id=(fe._id||0)+1,this._curve=t,this._segment1=t._segment1,this._segment2=t._segment2,this._parameter=e,this._point=i,this._curve2=n,this._parameter2=r,this._point2=s,this._distance=a},getSegment:function(){if(!this._segment){var t=this.getCurve(),e=this.getParameter();if(1===e)this._segment=t._segment2;else if(0===e||arguments[0])this._segment=t._segment1;else{if(null==e)return null;this._segment=t.getLength(0,e)a;a++)s[a]=n[a].getValues();for(var a=0,h=i.length;h>a;a++)for(var o=i[a],u=o.getValues(),l=0;r>l;l++)I.getIntersections(u,s[l],o,n[l],e);return e},setPathData:function(t){function e(t,e,i){var r=parseFloat(n[t]);return a&&(r+=h[e]),i&&(h[e]=r),r}function i(t,i){return new o(e(t,"x",i),e(t+1,"y",i))}var n,r,s=t.match(/[a-z][^a-z]*/gi),a=!1,h=new o;"path"===this._type?this.removeSegments():this.removeChildren();for(var u=0,l=s.length;l>u;u++){var c=s[u],d=c[0],_=d.toLowerCase();n=c.slice(1).trim().split(/[\s,]+|(?=[+-])/),a=d===_;var f=n.length;switch(_){case"m":case"l":for(var g=0;f>g;g+=2)this[0===g&&"m"===_?"moveTo":"lineTo"](i(g,!0));break;case"h":case"v":for(var m="h"==_?"x":"y",g=0;f>g;g++)e(g,m,!0),this.lineTo(h);break;case"c":for(var g=0;f>g;g+=6)this.cubicCurveTo(i(g),r=i(g+2),i(g+4,!0));break;case"s":for(var g=0;f>g;g+=4)this.cubicCurveTo(h.multiply(2).subtract(r),r=i(g),i(g+2,!0));break;case"q":for(var g=0;f>g;g+=4)this.quadraticCurveTo(r=i(g),i(g+2,!0));break;case"t":for(var g=0;f>g;g+=2)this.quadraticCurveTo(r=h.multiply(2).subtract(r),i(g,!0));break;case"a":break;case"z":this.closePath()}}},_canComposite:function(){return!(this.hasFill()&&this.hasStroke())},_contains:function(t){var e=this._getWinding(t);return!!("evenodd"===this.getWindingRule()?1&e:e)}}),O=A.extend({_class:"Path",_serializeFields:{segments:[],closed:!1},initialize:function(e){this._closed=!1,this._segments=[];var i=Array.isArray(e)?"object"==typeof e[0]?e:arguments:e&&(e.point!==t&&e.size===t||e.x!==t)?arguments:null;this.setSegments(i||[]),this._initialize(!i&&e)},_equals:function(t){return e.equals(this._segments,t._segments)},clone:function(e){var i=this._clone(new O({segments:this._segments,insert:!1}),e);return i._closed=this._closed,this._clockwise!==t&&(i._clockwise=this._clockwise),i},_changed:function ge(t){if(ge.base.call(this,t),4&t){if(delete this._length,delete this._clockwise,this._curves)for(var e=0,i=this._curves.length;i>e;e++)this._curves[e]._changed(5)}else 8&t&&delete this._bounds},getSegments:function(){return this._segments},setSegments:function(t){var e=this.isFullySelected();this._segments.length=0,this._selectedSegmentState=0,delete this._curves,this._add(z.readAll(t)),e&&this.setFullySelected(!0)},getFirstSegment:function(){return this._segments[0]},getLastSegment:function(){return this._segments[this._segments.length-1]},getCurves:function(){var t=this._curves,e=this._segments;if(!t){var i=this._countCurves();t=this._curves=Array(i);for(var n=0;i>n;n++)t[n]=new I(this,e[n],e[n+1]||e[0])}return t},getFirstCurve:function(){return this.getCurves()[0]},getLastCurve:function(){var t=this.getCurves();return t[t.length-1]},getPathData:function(){function t(t,e,s){var a=t._point,h=e._point,o=t._handleOut,u=e._handleIn;if(o.isZero()&&u.isZero())s||r.push("L"+n.point(h,i));else{var l=h.subtract(a);r.push("c"+n.point(o,i)+" "+n.point(l.add(u),i)+" "+n.point(l,i))}}var e=this._segments,i=arguments[0],n=a.instance,r=[];if(0===e.length)return"";r.push("M"+n.point(e[0]._point));for(var s=0,h=e.length-1;h>s;s++)t(e[s],e[s+1],!1);return this._closed&&(t(e[e.length-1],e[0],!0),r.push("z")),r.join("")},isClosed:function(){return this._closed},setClosed:function(t){if(this._closed!=(t=!!t)){if(this._closed=t,this._curves){var e=this._curves.length=this._countCurves();t&&(this._curves[e-1]=new I(this,this._segments[e-1],this._segments[0]))}this._changed(5)}},isEmpty:function(){return 0===this._segments.length},isPolygon:function(){for(var t=0,e=this._segments.length;e>t;t++)if(!this._segments[t].isLinear())return!1;return!0},_applyMatrix:function(t){for(var e=Array(6),i=0,n=this._segments.length;n>i;i++)this._segments[i]._transformCoordinates(t,e,!0);return!0},_add:function(t,e){for(var i=this._segments,n=this._curves,r=t.length,s=null==e,e=s?i.length:e,a=0;r>a;a++){var h=t[a];h._path&&(h=t[a]=h.clone()),h._path=this,h._index=e+a,h._selectionState&&this._updateSelection(h,0,h._selectionState)}if(s)i.push.apply(i,t);else{i.splice.apply(i,[e,0].concat(t));for(var a=e+r,o=i.length;o>a;a++)i[a]._index=a}if(n||t._curves){n||(n=this._curves=[]);var u=e>0?e-1:e,l=u,c=Math.min(u+r,this._countCurves());t._curves&&(n.splice.apply(n,[u,0].concat(t._curves)),l+=t._curves.length);for(var a=l;c>a;a++)n.splice(a,0,new I(this,null,null));this._adjustCurves(u,c)}return this._changed(5),t},_adjustCurves:function(t,e){for(var i,n=this._segments,r=this._curves,s=t;e>s;s++)i=r[s],i._path=this,i._segment1=n[s],i._segment2=n[s+1]||n[0];(i=r[this._closed&&0===t?n.length-1:t-1])&&(i._segment2=n[t]||n[0]),(i=r[e])&&(i._segment1=n[e])},_countCurves:function(){var t=this._segments.length;return!this._closed&&t>0?t-1:t},add:function(t){return arguments.length>1&&"number"!=typeof t?this._add(z.readAll(arguments)):this._add([z.read(arguments)])[0]},insert:function(t,e){return arguments.length>2&&"number"!=typeof e?this._add(z.readAll(arguments,1),t):this._add([z.read(arguments,1)],t)[0]},addSegment:function(){return this._add([z.read(arguments)])[0]},insertSegment:function(t){return this._add([z.read(arguments,1)],t)[0]},addSegments:function(t){return this._add(z.readAll(t))},insertSegments:function(t,e){return this._add(z.readAll(e),t)},removeSegment:function(t){return this.removeSegments(t,t+1)[0]||null},removeSegments:function(t,i){t=t||0,i=e.pick(i,this._segments.length);var n=this._segments,r=this._curves,s=n.length,a=n.splice(t,i-t),h=a.length;if(!h)return a;for(var o=0;h>o;o++){var u=a[o];u._selectionState&&this._updateSelection(u,u._selectionState,0),delete u._index,delete u._path}for(var o=t,l=n.length;l>o;o++)n[o]._index=o;if(r){var c=t>0&&i===s+(this._closed?1:0)?t-1:t,r=r.splice(c,h);arguments[2]&&(a._curves=r.slice(1)),this._adjustCurves(c,c)}return this._changed(5),a},isFullySelected:function(){var t=this._segments.length;return this._selected&&t>0&&this._selectedSegmentState===4*t},setFullySelected:function(t){t&&this._selectSegments(!0),this.setSelected(t)},setSelected:function me(t){t||this._selectSegments(!1),me.base.call(this,t)},_selectSegments:function(t){var e=this._segments.length;this._selectedSegmentState=t?4*e:0;for(var i=0;e>i;i++)this._segments[i]._selectionState=t?4:0},_updateSelection:function(t,e,i){t._selectionState=i;var n=this._selectedSegmentState+=i-e;n>0&&this.setSelected(!0)},flatten:function(t){for(var e=new T(this),i=0,n=e.length/Math.ceil(e.length/t),r=e.length+(this._closed?-n:n)/2,s=[];r>=i;)s.push(new z(e.evaluate(i,0))),i+=n;this.setSegments(s)},simplify:function(t){if(this._segments.length>2){var e=new D(this,t||2.5);this.setSegments(e.fit())}},split:function(t,e){if(null!==e){if(1===arguments.length){var i=t;"number"==typeof i&&(i=this.getLocationAt(i)),t=i.index,e=i.parameter}e>=1&&(t++,e--);var n=this.getCurves();if(t>=0&&t0&&n[t++].divide(e,!0);var r,s=this.removeSegments(t,this._segments.length,!0);return this._closed?(this.setClosed(!1),r=this):t>0&&(r=this._clone((new O).insertAbove(this,!0))),r._add(s,0),this.addSegment(s[0]),r}return null}},isClockwise:function(){return this._clockwise!==t?this._clockwise:O.isClockwise(this._segments)},setClockwise:function(t){this.isClockwise()!=(t=!!t)&&this.reverse(),this._clockwise=t},reverse:function(){this._segments.reverse();for(var e=0,i=this._segments.length;i>e;e++){var n=this._segments[e],r=n._handleIn;n._handleIn=n._handleOut,n._handleOut=r,n._index=e}delete this._curves,this._clockwise!==t&&(this._clockwise=!this._clockwise)},join:function(t){if(t){var e=t._segments,i=this.getLastSegment(),n=t.getLastSegment();i._point.equals(n._point)&&t.reverse();var r,s=t.getFirstSegment();return i._point.equals(s._point)?(i.setHandleOut(s._handleOut),this._add(e.slice(1))):(r=this.getFirstSegment(),r._point.equals(s._point)&&t.reverse(),n=t.getLastSegment(),r._point.equals(n._point)?(r.setHandleIn(n._handleIn),this._add(e.slice(0,e.length-1),0)):this._add(e.slice())),t.closed&&this._add([e[0]]),t.remove(),r=this.getFirstSegment(),i=this.getLastSegment(),i._point.equals(r._point)&&(r.setHandleIn(i._handleIn),i.remove(),this.setClosed(!0)),this._changed(5),!0}return!1},getLength:function(){if(null==this._length){var t=this.getCurves();this._length=0;for(var e=0,i=t.length;i>e;e++)this._length+=t[e].getLength()}return this._length},getArea:function(){for(var t=this.getCurves(),e=0,i=0,n=t.length;n>i;i++)e+=t[i].getArea();return e},_getOffset:function(t){var e=t&&t.getIndex();if(null!=e){for(var i=this.getCurves(),n=0,r=0;e>r;r++)n+=i[r].getLength();var s=i[e];return n+s.getLength(0,t.getParameter())}return null},getLocationOf:function(t){t=o.read(arguments);for(var e=this.getCurves(),i=0,n=e.length;n>i;i++){var r=e[i].getLocationOf(t);if(r)return r}return null},getLocationAt:function(t,e){var i=this.getCurves(),n=0;if(e){var r=~~t;return i[r].getLocationAt(t-r,!0)}for(var s=0,a=i.length;a>s;s++){var h=n,o=i[s];if(n+=o.getLength(),n>=t)return o.getLocationAt(t-h)}return t<=this.getLength()?new k(i[i.length-1],1):null},getPointAt:function(t,e){var i=this.getLocationAt(t,e);return i&&i.getPoint()},getTangentAt:function(t,e){var i=this.getLocationAt(t,e);return i&&i.getTangent()},getNormalAt:function(t,e){var i=this.getLocationAt(t,e);return i&&i.getNormal()},getNearestLocation:function(t){t=o.read(arguments);for(var e=this.getCurves(),i=1/0,n=null,r=0,s=e.length;s>r;r++){var a=e[r].getNearestLocation(t); -a._distanceo;o++){var l=i[o].getValues(),c=l[0],d=l[1];(c!==l[2]||d!==l[3]||c!==l[4]||d!==l[5]||c!==l[6]||d!==l[7])&&(r+=I._getWinding(l,t.x,t.y,s,a))}return e||(r+=I._getWinding(h,t.x,t.y,s,a)),r},_hitTest:function(e,i){function n(i,n,r){return e.getDistance(n)s;s++)r+=I._getWinding(a(s),t.x,t.y,i,n);return!!r}function o(t){return("round"!==u||"round"!==l)&&(d=[],v||t._index>0&&t._index0)?h(e):e.getDistance(t._point)<=y}var u,l,c,d,_,f,g=this.getStyle(),m=this._segments,v=this._closed,p=i.tolerance,y=0,w=this;if(i.stroke&&(y=g.getStrokeWidth()/2,y>0?(u=g.getStrokeJoin(),l=g.getStrokeCap(),c=y*g.getMiterLimit()):u=l="round",y+=p),!i.ends||i.segments||v){if(i.segments||i.handles)for(var x=0,b=m.length;b>x;x++)if(f=r(m[x]))return f}else if(f=r(m[0],!0)||r(m[m.length-1],!0))return f;if(y>0){if(_=this.getNearestLocation(e)){var C=_.getParameter();0===C||1===C?o(_.getSegment())||(_=null):_._distance>y&&(_=null)}if(!_&&"miter"===u)for(var x=0,b=m.length;b>x;x++){var S=m[x];if(e.getDistance(S._point)<=c&&o(S)){_=S.getLocation();break}}}return!_&&i.fill&&this.hasFill()&&this.contains(e)?new P("fill",this):_?new P("stroke",this,{location:_}):null}},new function(){function t(t,e,i,n){function r(e){var i=a[e],n=a[e+1];(d!=i||_!=n)&&(t.beginPath(),t.moveTo(d,_),t.lineTo(i,n),t.stroke(),t.beginPath(),t.arc(i,n,s,0,2*Math.PI,!0),t.fill())}for(var s=n/2,a=Array(6),h=0,o=e.length;o>h;h++){var u=e[h];u._transformCoordinates(i,a,!1);var l=u._selectionState,c=4&l,d=a[0],_=a[1];(c||1&l)&&r(2),(c||2&l)&&r(4),t.save(),t.beginPath(),t.rect(d-s,_-s,n,n),t.fill(),c||(t.beginPath(),t.rect(d-s+1,_-s+1,n-2,n-2),t.fillStyle="#ffffff",t.fill()),t.restore()}}function e(t,e,i){function n(e){var n=d[e];if(i)n._transformCoordinates(i,f,!1),r=f[0],s=f[1];else{var _=n._point;r=_._x,s=_._y}if(g)t.moveTo(r,s),g=!1;else{if(i)o=f[2],u=f[3];else{var m=n._handleIn;o=r+m._x,u=s+m._y}o==r&&u==s&&l==a&&c==h?t.lineTo(r,s):t.bezierCurveTo(l,c,o,u,r,s)}if(a=r,h=s,i)l=f[4],c=f[5];else{var m=n._handleOut;l=a+m._x,c=h+m._y}}for(var r,s,a,h,o,u,l,c,d=e._segments,_=d.length,f=Array(6),g=!0,m=0;_>m;m++)n(m);e._closed&&_>1&&n(0)}return{_draw:function(t,i){function n(t){return u[(t%l+l)%l]}var r=i.clip,s=i.compound;s||t.beginPath();var a=this.getStyle(),h=a.hasFill(),o=a.hasStroke(),u=a.getDashArray(),l=!paper.support.nativeDash&&o&&u&&u.length;if((h||o&&!l||s||r)&&e(t,this),this._closed&&t.closePath(),!r&&!s&&(h||o)&&(this._setStyles(t),h&&t.fill(a.getWindingRule()),o)){if(l){t.beginPath();var c,d=new T(this),_=d.length,f=-a.getDashOffset(),g=0;for(f%=_;f>0;)f-=n(g--)+n(g--);for(;_>f;)c=f+n(g++),(f>0||c>0)&&d.drawPart(t,Math.max(f,0),Math.max(c,0)),f=c+n(g++)}t.stroke()}},_drawSelected:function(i,n){i.beginPath(),e(i,this,n),i.stroke(),t(i,this._segments,n,this._project.options.handleSize||4)}}},new function(){function t(t){var e=t.length,i=[],n=[],r=2;i[0]=t[0]/r;for(var s=1;e>s;s++)n[s]=1/r,r=(e-1>s?4:2)-n[s],i[s]=(t[s]-i[s-1])/r;for(var s=1;e>s;s++)i[e-s-1]-=n[e-s]*i[e-s];return i}return{smooth:function(){var e,i=this._segments,n=i.length,r=n;if(!(2>=n)){this._closed?(e=Math.min(n,4),r+=2*Math.min(n,e)):e=0;for(var s=[],a=0;n>a;a++)s[a+e]=i[a]._point;if(this._closed)for(var a=0;e>a;a++)s[a]=i[a+n-e]._point,s[a+n+e]=i[a]._point;else r--;for(var h=[],a=1;r-1>a;a++)h[a]=4*s[a]._x+2*s[a+1]._x;h[0]=s[0]._x+2*s[1]._x,h[r-1]=3*s[r-1]._x;for(var u=t(h),a=1;r-1>a;a++)h[a]=4*s[a]._y+2*s[a+1]._y;h[0]=s[0]._y+2*s[1]._y,h[r-1]=3*s[r-1]._y;var l=t(h);if(this._closed){for(var a=0,c=n;e>a;a++,c++){var d=a/e,_=1-d,f=a+e,g=c+e;u[c]=u[a]*d+u[c]*_,l[c]=l[a]*d+l[c]*_,u[g]=u[f]*_+u[g]*d,l[g]=l[f]*_+l[g]*d}r--}for(var m=null,a=e;r-e>=a;a++){var v=i[a-e];m&&v.setHandleIn(m.subtract(v._point)),r>a&&(v.setHandleOut(new o(u[a],l[a]).subtract(v._point)),m=r-1>a?new o(2*s[a+1]._x-u[a+1],2*s[a+1]._y-l[a+1]):new o((s[r]._x+u[r-1])/2,(s[r]._y+l[r-1])/2))}if(this._closed&&m){var v=this._segments[0];v.setHandleIn(m.subtract(v._point))}}}}},new function(){function t(t){var e=t._segments;if(0==e.length)throw Error("Use a moveTo() command first");return e[e.length-1]}return{moveTo:function(){1===this._segments.length&&this.removeSegment(0),this._segments.length||this._add([new z(o.read(arguments))])},moveBy:function(){throw Error("moveBy() is unsupported on Path items.")},lineTo:function(){this._add([new z(o.read(arguments))])},cubicCurveTo:function(){var e=o.read(arguments),i=o.read(arguments),n=o.read(arguments),r=t(this);r.setHandleOut(e.subtract(r._point)),this._add([new z(n,i.subtract(n))])},quadraticCurveTo:function(){var e=o.read(arguments),i=o.read(arguments),n=t(this)._point;this.cubicCurveTo(e.add(n.subtract(e).multiply(1/3)),e.add(i.subtract(e).multiply(1/3)),i)},curveTo:function(){var i=o.read(arguments),n=o.read(arguments),r=e.pick(e.read(arguments),.5),s=1-r,a=t(this)._point,h=i.subtract(a.multiply(s*s)).subtract(n.multiply(r*r)).divide(2*r*s);if(h.isNaN())throw Error("Cannot put a curve through points with parameter = "+r);this.quadraticCurveTo(h,n)},arcTo:function(i,n){var r,s=t(this),a=s._point,h=o.read(arguments),u=e.pick(e.peek(arguments),!0);if("boolean"==typeof u){i=h,n=u;var l=a.add(i).divide(2),r=l.add(l.subtract(a).rotate(n?-90:90))}else r=h,i=o.read(arguments);var c=new m(a.add(r).divide(2),r.subtract(a).rotate(90),!0),d=new m(r.add(i).divide(2),i.subtract(r).rotate(90),!0),_=c.intersect(d,!0),f=new m(a,i),g=f.getSide(r);if(!_){if(!g)return this.lineTo(i);throw Error("Cannot put an arc through the given points: "+[a,r,i])}var v=a.subtract(_),p=v.getDirectedAngle(i.subtract(_)),y=f.getSide(_);0==y?p=g*Math.abs(p):g==y&&(p-=360*(0>p?-1:1));for(var w=Math.abs(p),x=w>=360?4:Math.ceil(w/90),b=p/x,C=b*Math.PI/360,S=4/3*Math.sin(C)/(1+Math.cos(C)),P=[],M=0;x>=M;M++){var I=x>M?_.add(v):i,k=x>M?v.rotate(90).multiply(S):null;0==M?s.setHandleOut(k):P.push(new z(I,v.rotate(-90).multiply(S),k)),v=v.rotate(b)}this._add(P)},lineBy:function(e){e=o.read(arguments);var i=t(this);this.lineTo(i._point.add(e))},curveBy:function(e,i,n){e=o.read(e),i=o.read(i);var r=t(this)._point;this.curveTo(r.add(e),r.add(i),n)},arcBy:function(e,i){e=o.read(e),i=o.read(i);var n=t(this)._point;this.arcTo(n.add(e),n.add(i))},closePath:function(){var t=this.getFirstSegment(),e=this.getLastSegment();t._point.equals(e._point)&&(t.setHandleIn(e._handleIn),e.remove()),this.setClosed(!0)}}},{_getBounds:function(t,e){return O[t](this._segments,this._closed,this.getStyle(),e)},statics:{isClockwise:function(t){for(var e=0,i=0,n=t.length;n>i;i++)for(var r=I.getValues(t[i],t[n>i+1?i+1:0]),s=2;8>s;s+=2)e+=(r[s-2]-r[s])*(r[s+1]+r[s-1]);return e>0},getBounds:function(t,e,i,n,r){function s(t){t._transformCoordinates(n,h,!1);for(var e=0;2>e;e++)I._addBounds(o[e],o[e+4],h[e+2],h[e],e,r?r[e]:0,u,l,c);var i=o;o=h,h=i}var a=t[0];if(!a)return new _;for(var h=Array(6),o=a._transformCoordinates(n,Array(6),!1),u=o.slice(0,2),l=u.slice(),c=Array(2),d=1,f=t.length;f>d;d++)s(t[d]);return e&&s(a),new _(u[0],u[1],l[0]-u[0],l[1]-u[1])},getStrokeBounds:function(t,e,i,n){function r(t,e){if(!e)return[t,t];var i=e.shiftless(),n=i.transform(new o(t,0)),r=i.transform(new o(0,t)),s=n.getAngleInRadians(),a=n.getLength(),h=r.getLength(),u=Math.sin(s),l=Math.cos(s),c=Math.tan(s),d=-Math.atan(h*c/a),_=Math.atan(h/(c*a));return[Math.abs(a*Math.cos(d)*l-h*Math.sin(d)*u),Math.abs(h*Math.sin(_)*l+a*Math.cos(_)*u)]}function s(t){f=f.include(n?n._transformPoint(t,t):t)}function a(t,e){"round"===e||!t._handleIn.isZero()&&!t._handleOut.isZero()?f=f.unite(p.setCenter(n?n._transformPoint(t._point):t._point)):O._addSquareJoin(t,e,l,v,s)}function h(t,e){switch(e){case"round":a(t,e);break;case"butt":case"square":O._addSquareCap(t,e,l,s)}}if(!i.hasStroke())return O.getBounds(t,e,i,n);for(var u=t.length-(e?0:1),l=i.getStrokeWidth()/2,d=r(l,n),f=O.getBounds(t,e,i,n,d),g=i.getStrokeJoin(),m=i.getStrokeCap(),v=l*i.getMiterLimit(),p=new _(new c(d).multiply(2)),y=1;u>y;y++)a(t[y],g);return e?a(t[0],g):(h(t[0],m),h(t[t.length-1],m)),f},_addSquareJoin:function(t,e,i,n,r,s){var a=t.getCurve(),h=a.getPrevious(),u=a.getPointAt(0,!0),l=h.getNormalAt(1,!0),c=a.getNormalAt(0,!0),d=l.getDirectedAngle(c)<0?-i:i;if(l.setLength(d),c.setLength(d),s&&(r(u),r(u.add(l))),"miter"===e){var _=new m(u.add(l),new o(-l.y,l.x),!0).intersect(new m(u.add(c),new o(-c.y,c.x),!0),!0);if(_&&u.getDistance(_)<=n&&(r(_),!s))return}s||r(u.add(l)),r(u.add(c))},_addSquareCap:function(t,e,i,n,r){var s=t._point,a=t.getLocation(),h=a.getNormal().normalize(i);r&&(n(s.subtract(h)),n(s.add(h))),"square"===e&&(s=s.add(h.rotate(0==a.getParameter()?-90:90))),n(s.add(h)),n(s.subtract(h))},getHandleBounds:function(t,e,i,n,r,s){var a=Array(6),h=1/0,o=-h,u=h,l=o;r=r/2||0,s=s/2||0;for(var c=0,d=t.length;d>c;c++){var f=t[c];f._transformCoordinates(n,a,!1);for(var g=0;6>g;g+=2){var m=0==g?s:r,v=a[g],p=a[g+1],y=v-m,w=v+m,x=p-m,b=p+m;h>y&&(h=y),w>o&&(o=w),u>x&&(u=x),b>l&&(l=b)}}return new _(h,u,o-h,l-u)},getRoughBounds:function(t,e,i,n){var r=i.getStrokeColor()?i.getStrokeWidth():0,s=r;return 0===r?r=1e-5:("miter"===i.getStrokeJoin()&&(s=r*i.getMiterLimit()),"square"===i.getStrokeCap()&&(s=Math.max(s,r*Math.sqrt(2)))),O.getHandleBounds(t,e,i,n,r,s)}}});O.inject({statics:new function(){function t(t,i,r){for(var s=new O,a=Array(4),h=0;4>h;h++){var o=n[h];a[h]=new z(o._point.multiply(i).add(t),o._handleIn.multiply(i),o._handleOut.multiply(i))}return s._add(a),s._closed=!0,s.set(e.getNamed(r))}var i=h.KAPPA,n=[new z([-1,0],[0,i],[0,-i]),new z([0,-1],[-i,0],[i,0]),new z([1,0],[0,-i],[0,i]),new z([0,1],[i,0],[-i,0])];return{Line:function(){return new O(o.readNamed(arguments,"from"),o.readNamed(arguments,"to")).set(e.getNamed(arguments))},Circle:function(){var i=o.readNamed(arguments,"center"),n=e.readNamed(arguments,"radius");return t(i,new c(n),arguments)},Rectangle:function(){var t=_.readNamed(arguments,"rectangle"),n=c.readNamed(arguments,"radius",0,0,{readNull:!0}),r=t.getBottomLeft(!0),s=t.getTopLeft(!0),a=t.getTopRight(!0),h=t.getBottomRight(!0);if(path=new O,!n||n.isZero())path._add([new z(r),new z(s),new z(a),new z(h)]);else{n=c.min(n,t.getSize(!0).divide(2));var o=n.width,u=n.height,l=o*i,d=u*i;path._add([new z(r.add(o,0),null,[-l,0]),new z(r.subtract(0,u),[0,d]),new z(s.add(0,u),null,[0,-d]),new z(s.add(o,0),[-l,0],null),new z(a.subtract(o,0),null,[l,0]),new z(a.add(0,u),[0,-d],null),new z(h.subtract(0,u),null,[0,d]),new z(h.subtract(o,0),[l,0])])}return path._closed=!0,path.set(e.getNamed(arguments))},RoundRectangle:"#Rectangle",Ellipse:function(){var e=b._readEllipse(arguments);return t(e.center,e.radius,arguments)},Oval:"#Ellipse",Arc:function(){var t=o.readNamed(arguments,"from"),i=o.readNamed(arguments,"through"),n=o.readNamed(arguments,"to"),r=new O;return r.moveTo(t),r.arcTo(i,n),r.set(e.getNamed(arguments))},RegularPolygon:function(){for(var t=o.readNamed(arguments,"center"),i=e.readNamed(arguments,"sides"),n=e.readNamed(arguments,"radius"),r=new O,s=360/i,a=!(i%3),h=new o(0,a?-n:n),u=a?-1:.5,l=Array(i),c=0;i>c;c++)l[c]=new z(t.add(h.rotate((c+u)*s)));return r._add(l),r._closed=!0,r.set(e.getNamed(arguments))},Star:function(){for(var t=o.readNamed(arguments,"center"),i=2*e.readNamed(arguments,"points"),n=e.readNamed(arguments,"radius1"),r=e.readNamed(arguments,"radius2"),s=new O,a=360/i,h=new o(0,-1),u=Array(i),l=0;i>l;l++)u[l]=new z(t.add(h.rotate(a*l).multiply(l%2?r:n)));return s._add(u),s._closed=!0,s.set(e.getNamed(arguments))}}}});var L=A.extend({_class:"CompoundPath",_serializeFields:{children:[]},initialize:function(t){this._children=[],this._namedChildren={},this._initialize(t)||this.addChildren(Array.isArray(t)?t:arguments)},insertChildren:function ve(e,i,n){i=ve.base.call(this,e,i,n,"path");for(var r=0,s=!n&&i&&i.length;s>r;r++){var a=i[r];a._clockwise===t&&a.setClockwise(0===a._index)}return i},reverse:function(){for(var t=this._children,e=0,i=t.length;i>e;e++)t[e].reverse()},smooth:function(){for(var t=0,e=this._children.length;e>t;t++)this._children[t].smooth()},isClockwise:function(){var t=this.getFirstChild();return t&&t.isClockwise()},setClockwise:function(t){this.isClockwise()!=!!t&&this.reverse()},getFirstSegment:function(){var t=this.getFirstChild();return t&&t.getFirstSegment()},getLastSegment:function(){var t=this.getLastChild();return t&&t.getLastSegment()},getCurves:function(){for(var t=this._children,e=[],i=0,n=t.length;n>i;i++)e=e.concat(t[i].getCurves());return e},getFirstCurve:function(){var t=this.getFirstChild();return t&&t.getFirstCurve()},getLastCurve:function(){var t=this.getLastChild();return t&&t.getFirstCurve()},getArea:function(){for(var t=this._children,e=0,i=0,n=t.length;n>i;i++)e+=t[i].getArea();return e},getPathData:function(){for(var t=this._children,e=[],i=0,n=t.length;n>i;i++)e.push(t[i].getPathData(arguments[0]));return e.join(" ")},_getWinding:function(t){for(var e=this._children,i=0,n=0,r=e.length;r>n;n++)i+=e[n]._getWinding(t);return i},_hitTest:function pe(t,i){var n=pe.base.call(this,t,e.merge(i,{fill:!1}));if(!n)if(i.compoundChildren)for(var r=this._children,s=r.length-1;s>=0&&!n;s--)n=r[s]._hitTest(t,i);else i.fill&&this.hasFill()&&this._contains(t)&&(n=new P("fill",this));return n},_draw:function(t,e){var i=this._children;if(0!==i.length){t.beginPath(),e=e.extend({compound:!0});for(var n=0,r=i.length;r>n;n++)i[n].draw(t,e);if(!e.clip){this._setStyles(t);var s=this._style;s.hasFill()&&t.fill(s.getWindingRule()),s.hasStroke()&&t.stroke()}}}},new function(){function t(t){if(!t._children.length)throw Error("Use a moveTo() command first");return t._children[t._children.length-1]}var i={moveTo:function(){var t=new O;this.addChild(t),t.moveTo.apply(t,arguments)},moveBy:function(){this.moveTo(t(this).getLastSegment()._point.add(o.read(arguments)))},closePath:function(){t(this).closePath()}};return e.each(["lineTo","cubicCurveTo","quadraticCurveTo","curveTo","arcTo","lineBy","curveBy","arcBy"],function(e){i[e]=function(){var i=t(this);i[e].apply(i,arguments)}}),i}),T=e.extend({initialize:function(t){function e(t,e){var i=I.getValues(t,e);s.curves.push(i),s._computeParts(i,t._index,0,1)}this.curves=[],this.parts=[],this.length=0,this.index=0;for(var i,n=t._segments,r=n[0],s=this,a=1,h=n.length;h>a;a++)i=n[a],e(r,i),r=i;t._closed&&e(i,n[0])},_computeParts:function(t,e,i,n){if(n-i>1/32&&!I.isFlatEnough(t,.25)){var r=I.subdivide(t),s=(i+n)/2;this._computeParts(r[0],e,i,s),this._computeParts(r[1],e,s,n)}else{var a=t[6]-t[0],h=t[7]-t[1],o=Math.sqrt(a*a+h*h);o>1e-5&&(this.length+=o,this.parts.push({offset:this.length,value:n,index:e}))}},getParameterAt:function(t){for(var e,i=this.index;e=i,!(0==i||this.parts[--i].offsete;e++){var r=this.parts[e];if(r.offset>=t){this.index=e;var s=this.parts[e-1],a=s&&s.index==r.index?s.value:0,h=s?s.offset:0;return{value:a+(r.value-a)*(t-h)/(r.offset-h),index:r.index}}}var r=this.parts[this.parts.length-1];return{value:1,index:r.index}},evaluate:function(t,e){var i=this.getParameterAt(t);return I.evaluate(this.curves[i.index],i.value,e)},drawPart:function(t,e,i){e=this.getParameterAt(e),i=this.getParameterAt(i);for(var n=e.index;n<=i.index;n++){var r=I.getPart(this.curves[n],n==e.index?e.value:0,n==i.index?i.value:1);n==e.index&&t.moveTo(r[0],r[1]),t.bezierCurveTo.apply(t,r.slice(2))}}}),D=e.extend({initialize:function(t,e){this.points=[];for(var i,n=t._segments,r=0,s=n.length;s>r;r++){var a=n[r].point.clone();i&&i.equals(a)||(this.points.push(a),i=a)}this.error=e},fit:function(){var t=this.points,e=t.length;return this.segments=e>0?[new z(t[0])]:[],e>1&&this.fitCubic(0,e-1,t[1].subtract(t[0]).normalize(),t[e-2].subtract(t[e-1]).normalize()),this.segments},fitCubic:function(e,i,n,r){if(1==i-e){var s=this.points[e],a=this.points[i],h=s.getDistance(a)/3;return this.addCurve([s,s.add(n.normalize(h)),a.add(r.normalize(h)),a]),t}for(var o,u=this.chordLengthParameterize(e,i),l=Math.max(this.error,this.error*this.error),c=0;4>=c;c++){var d=this.generateBezier(e,i,u,n,r),_=this.findMaxError(e,i,d,u);if(_.error=l)break;this.reparameterize(e,i,u,d),l=_.error}var f=this.points[o-1].subtract(this.points[o]),g=this.points[o].subtract(this.points[o+1]),m=f.add(g).divide(2).normalize();this.fitCubic(e,o,n,m),this.fitCubic(o,i,m.negate(),r)},addCurve:function(t){var e=this.segments[this.segments.length-1];e.setHandleOut(t[1].subtract(t[0])),this.segments.push(new z(t[3],t[2].subtract(t[3])))},generateBezier:function(t,e,i,n,r){for(var s=1e-11,a=this.points[t],h=this.points[e],o=[[0,0],[0,0]],u=[0,0],l=0,c=e-t+1;c>l;l++){var d=i[l],_=1-d,f=3*d*_,g=_*_*_,m=f*_,v=f*d,p=d*d*d,y=n.normalize(m),w=r.normalize(v),x=this.points[t+l].subtract(a.multiply(g+m)).subtract(h.multiply(v+p));o[0][0]+=y.dot(y),o[0][1]+=y.dot(w),o[1][0]=o[0][1],o[1][1]+=w.dot(w),u[0]+=y.dot(x),u[1]+=w.dot(x)}var b,C,S=o[0][0]*o[1][1]-o[1][0]*o[0][1];if(Math.abs(S)>s){var P=o[0][0]*u[1]-o[1][0]*u[0],z=u[0]*o[1][1]-u[1]*o[0][1];b=z/S,C=P/S}else{var M=o[0][0]+o[0][1],I=o[1][0]+o[1][1];b=C=Math.abs(M)>s?u[0]/M:Math.abs(I)>s?u[1]/I:0}var k=h.getDistance(a);return s*=k,(s>b||s>C)&&(b=C=k/3),[a,a.add(n.normalize(b)),h.add(r.normalize(C)),h]},reparameterize:function(t,e,i,n){for(var r=t;e>=r;r++)i[r-t]=this.findRoot(n,this.points[r],i[r-t])},findRoot:function(t,e,i){for(var n=[],r=[],s=0;2>=s;s++)n[s]=t[s+1].subtract(t[s]).multiply(3);for(var s=0;1>=s;s++)r[s]=n[s+1].subtract(n[s]).multiply(2);var a=this.evaluate(3,t,i),h=this.evaluate(2,n,i),o=this.evaluate(1,r,i),u=a.subtract(e),l=h.dot(h)+u.dot(o);return Math.abs(l)<1e-5?i:i-u.dot(h)/l},evaluate:function(t,e,i){for(var n=e.slice(),r=1;t>=r;r++)for(var s=0;t-r>=s;s++)n[s]=n[s].multiply(1-i).add(n[s+1].multiply(i));return n[0]},chordLengthParameterize:function(t,e){for(var i=[0],n=t+1;e>=n;n++)i[n-t]=i[n-t-1]+this.points[n].getDistance(this.points[n-1]);for(var n=1,r=e-t;r>=n;n++)i[n]/=i[r];return i},findMaxError:function(t,e,i,n){for(var r=Math.floor((e-t+1)/2),s=0,a=t+1;e>a;a++){var h=this.evaluate(3,i,n[a-t]),o=h.subtract(this.points[a]),u=o.x*o.x+o.y*o.y;u>=s&&(s=u,r=a)}return{error:s,index:r}}});A.inject(new function(){function t(t,e){t.sort(function(t,e){var i=t.getPath(),n=e.getPath();return i===n?t.getIndex()+t.getParameter()-(e.getIndex()+e.getParameter()):i._id-n._id});for(var i=e&&[],n=t.length-1;n>=0;n--){var r=t[n],s=r.getIntersection(),a=r.divide(),h=a&&a.getSegment1()||r.getSegment();i&&i.push(s),h._intersection=s,r._segment=h}return i}function e(t){if(t instanceof L){for(var e=t._children,i=e.length,n=Array(i),r=Array(i),s=e[0].isClockwise(),a=0;i>a;a++)n[a]=e[a].getBounds(),r[a]=0;for(var a=0;i>a;a++){for(var h=1;i>h;h++)a!==h&&n[a].contains(n[h])&&r[h]++;a>0&&0===r[a]%2&&e[a].setClockwise(s)}}return t}function i(i,r,s,a){i=e(i.clone(!1)),r=e(r.clone(!1));var h=i.isClockwise(),u=r.isClockwise(),l=i.getIntersections(r);t(t(l,!0)),h||i.reverse(),a^u||r.reverse(),h=!0,u=!a;for(var c=[].concat(i._children||[i]).concat(r._children||[r]),d=[],_=new L,f=0,g=c.length;g>f;f++){var m=c[f],v=m._parent,p=m.isClockwise(),y=m._segments;m=v instanceof L?v:m;for(var w=y.length-1;w>=0;w--){var x=y[w],b=x.getCurve().getPoint(.5),C=m!==i&&i.contains(b)&&(p===h||a||!n(i,b)),S=m!==r&&r.contains(b)&&(p===u||!n(r,b));s(m===i,C,S)?x._invalid=!0:d.push(x)}}for(var f=0,g=d.length;g>f;f++){var x=d[f];if(!x._visited){var m=new O,P=x._intersection,M=P&&P.getSegment(!0);x.getPrevious()._invalid&&x.setHandleIn(M?M._handleIn:new o(0,0));do{if(x._visited=!0,x._invalid&&x._intersection){var I=x._intersection.getSegment(!0);m.add(new z(x._point,x._handleIn,I._handleOut)),I._visited=!0,x=I}else m.add(x.clone());x=x.getNext()}while(x&&!x._visited&&x!==M);var k=m._segments.length;k>1&&(k>2||!m.isPolygon())?(m.setClosed(!0),_.addChild(m,!0)):m.remove()}}return i.remove(),r.remove(),_.reduce()}function n(t,e){var i=t.getCurves(),n=t.getBounds();if(n.contains(e))for(var r=0,s=i.length;s>r;r++){var a=i[r];if(a.getBounds().contains(e)&&a.getParameterOf(e))return!0}return!1}return{unite:function(t){return i(this,t,function(t,e,i){return e||i})},intersect:function(t){return i(this,t,function(t,e,i){return!(e||i)})},subtract:function(t){return i(this,t,function(t,e,i){return t&&i||!t&&!e},!0)},exclude:function(t){return new w([this.subtract(t),t.subtract(this)])},divide:function(t){return new w([this.subtract(t),this.intersect(t)])}}});var N=y.extend({_class:"TextItem",_boundsSelected:!0,_serializeFields:{content:null},_boundsGetter:"getBounds",initialize:function(i){this._content="",this._lines=[];var n=i&&e.isPlainObject(i)&&i.x===t&&i.y===t;this._initialize(n&&i,!n&&o.read(arguments))},_equals:function(t){return this._content===t._content},_clone:function ye(t){return t.setContent(this._content),ye.base.call(this,t)},getContent:function(){return this._content},setContent:function(t){this._content=""+t,this._lines=this._content.split(/\r\n|\n|\r/gm),this._changed(69)},isEmpty:function(){return!this._content},getCharacterStyle:"#getStyle",setCharacterStyle:"#setStyle",getParagraphStyle:"#getStyle",setParagraphStyle:"#setStyle"}),j=N.extend({_class:"PointText",initialize:function(){N.apply(this,arguments)},clone:function(t){return this._clone(new j({insert:!1}),t)},getPoint:function(){var t=this._matrix.getTranslation();return new u(t.x,t.y,this,"setPoint")},setPoint:function(t){t=o.read(arguments),this.translate(t.subtract(this._matrix.getTranslation()))},_draw:function(t){if(this._content){this._setStyles(t);var e=this._style,i=this._lines,n=e.getLeading();t.font=e.getFontStyle(),t.textAlign=e.getJustification();for(var r=0,s=i.length;s>r;r++){var a=i[r];e.hasFill()&&t.fillText(a,0,0),e.hasStroke()&&t.strokeText(a,0,0),t.translate(0,n)}}}},new function(){var t=null;return{_getBounds:function(e,i){t||(t=$.getContext(1,1));var n=this._style,r=this._lines,s=r.length,a=n.getJustification(),h=n.getLeading(),o=0;t.font=n.getFontStyle();for(var u=0,l=0;s>l;l++)u=Math.max(u,t.measureText(r[l]).width);"left"!==a&&(o-=u/("center"===a?2:1));var c=new _(o,s?-.75*h:0,u,s*h);return i?i._transformBounds(c,c):c}}}),B=e.extend(new function(){function t(t){var e=h[t];if(!e){n||(n=$.getContext(1,1),n.globalCompositeOperation="copy"),n.fillStyle="rgba(0,0,0,0)",n.fillStyle=t,n.fillRect(0,0,1,1);var i=n.getImageData(0,0,1,1).data;e=h[t]=[i[0]/255,i[1]/255,i[2]/255]}return e.slice()}function i(t){var e=t.match(/^#?(\w{1,2})(\w{1,2})(\w{1,2})$/);if(e.length>=4){for(var i=[0,0,0],n=0;3>n;n++){var r=e[n+1];i[n]=parseInt(1==r.length?r+r:r,16)/255}return i}}var n,r={gray:["gray"],rgb:["red","green","blue"],hsb:["hue","saturation","brightness"],hsl:["hue","saturation","lightness"],gradient:["gradient","origin","destination","highlight"]},s={},h={},u=[[0,3,1],[2,0,1],[1,0,3],[1,2,0],[3,1,0],[0,1,2]],l={"rgb-hsb":function(t,e,i){var n=Math.max(t,e,i),r=Math.min(t,e,i),s=n-r,a=0===s?0:60*(n==t?(e-i)/s+(i>e?6:0):n==e?(i-t)/s+2:(t-e)/s+4);return[a,0===n?0:s/n,n]},"hsb-rgb":function(t,e,i){var t=t/60%6,n=Math.floor(t),r=t-n,n=u[n],s=[i,i*(1-e),i*(1-e*r),i*(1-e*(1-r))];return[s[n[0]],s[n[1]],s[n[2]]]},"rgb-hsl":function(t,e,i){var n=Math.max(t,e,i),r=Math.min(t,e,i),s=n-r,a=0===s,h=a?0:60*(n==t?(e-i)/s+(i>e?6:0):n==e?(i-t)/s+2:(t-e)/s+4),o=(n+r)/2,u=a?0:.5>o?s/(n+r):s/(2-n-r);return[h,u,o]},"hsl-rgb":function(t,e,i){if(t/=360,0===e)return[i,i,i];for(var n=[t+1/3,t,t-1/3],r=.5>i?i*(1+e):i+e-i*e,s=2*i-r,a=[],h=0;3>h;h++){var o=n[h];0>o&&(o+=1),o>1&&(o-=1),a[h]=1>6*o?s+6*(r-s)*o:1>2*o?r:2>3*o?s+6*(r-s)*(2/3-o):s}return a},"rgb-gray":function(t,e,i){return[.2989*t+.587*e+.114*i]},"gray-rgb":function(t){return[t,t,t]},"gray-hsb":function(t){return[0,0,t]},"gray-hsl":function(t){return[0,0,t]},"gradient-rgb":function(){return[]},"rgb-gradient":function(){return[]}};return e.each(r,function(t,i){s[i]=[],e.each(t,function(t,n){var a=e.capitalize(t),h=/^(hue|saturation)$/.test(t),u=s[i][n]="gradient"===t?function(t){var e=this._components[0];return t=F.read(Array.isArray(t)?t:arguments,0,0,{readNull:!0}),e!==t&&(e&&e._removeOwner(this),t&&t._addOwner(this)),t}:"hue"===t?function(t){return isNaN(t)?0:(t%360+360)%360}:"gradient"===i?function(){return o.read(arguments,0,0,{readNull:"highlight"===t,clone:!0})}:function(t){return isNaN(t)?0:Math.min(Math.max(t,0),1)};this["get"+a]=function(){return this._type===i||h&&/^hs[bl]$/.test(this._type)?this._components[n]:this._convert(i)[n]},this["set"+a]=function(t){this._type===i||h&&/^hs[bl]$/.test(this._type)||(this._components=this._convert(i),this._properties=r[i],this._type=i),t=u.call(this,t),null!=t&&(this._components[n]=t,this._changed())}},this)},{_class:"Color",_readIndex:!0,initialize:function c(e){var n,a,h,o,u=Array.prototype.slice,l=arguments,d=0,_=!0;Array.isArray(e)&&(l=e,e=l[0]);var f=null!=e&&typeof e;if("string"===f&&e in r&&(n=e,e=l[1],Array.isArray(e)?(a=e,h=l[2]):(this.__read&&(d=1),l=u.call(l,1),f=typeof e)),!a){if(_=!(this.__options&&this.__options.dontParse),o="number"===f?l:"object"===f&&null!=e.length?e:null){n||(n=o.length>=3?"rgb":"gray");var g=r[n].length;h=o[g],this.__read&&(d+=o===arguments?g+(null!=h?1:0):1),o.length>g&&(o=u.call(o,0,g))}else if("string"===f)a=e.match(/^#[0-9a-f]{3,6}$/i)?i(e):t(e),n="rgb";else if("object"===f)if(e.constructor===c){if(n=e._type,a=e._components.slice(),h=e._alpha,"gradient"===n)for(var m=1,v=a.length;v>m;m++){var p=a[m];p&&(a[m]=p.clone())}}else if(e.constructor===F)n="gradient",o=l;else{n="hue"in e?"lightness"in e?"hsl":"hsb":"gradient"in e||"stops"in e||"radial"in e?"gradient":"gray"in e?"gray":"rgb";var y=r[n];x=_&&s[n],this._components=a=[];for(var m=0,v=y.length;v>m;m++){var w=e[y[m]];null==w&&0===m&&"gradient"===n&&"stops"in e&&(w={stops:e.stops,radial:e.radial}),_&&(w=x[m].call(this,w)),null!=w&&(a[m]=w)}h=e.alpha}this.__read&&n&&(d=1)}if(this._type=n||"rgb","gradient"===n&&(this._id=c._id=(c._id||0)+1),!a){this._components=a=[];for(var x=s[this._type],m=0,v=x.length;v>m;m++){var w=o&&o[m];_&&(w=x[m].call(this,w)),null!=w&&(a[m]=w)}}this._components=a,this._properties=r[this._type],this._alpha=h,this.__read&&(this.__read=d)},_serialize:function(t,i){var n=this.getComponents();return e.serialize(/^(gray|rgb)$/.test(this._type)?n:[this._type].concat(n),t,!0,i)},_changed:function(){this._canvasStyle=null,this._owner&&this._owner._changed(17)},clone:function(){return new B(this._type,this._components.slice(),this._alpha)},_convert:function(t){var e;return this._type===t?this._components.slice():(e=l[this._type+"-"+t])?e.apply(this,this._components):l["rgb-"+t].apply(this,l[this._type+"-rgb"].apply(this,this._components))},convert:function(t){return new B(t,this._convert(t),this._alpha)},getType:function(){return this._type},setType:function(t){this._components=this._convert(t),this._properties=r[t],this._type=t},getComponents:function(){var t=this._components.slice();return null!=this._alpha&&t.push(this._alpha),t},getAlpha:function(){return null!=this._alpha?this._alpha:1},setAlpha:function(t){this._alpha=null==t?null:Math.min(Math.max(t,0),1),this._changed()},hasAlpha:function(){return null!=this._alpha},equals:function(t){return e.isPlainValue(t)&&(t=B.read(arguments)),t===this||t&&this._class===t._class&&this._type===t._type&&this._alpha===t._alpha&&e.equals(this._components,t._components)||!1},toString:function(){for(var t=this._properties,e=[],i="gradient"===this._type,n=a.instance,r=0,s=t.length;s>r;r++){var h=this._components[r];null!=h&&e.push(t[r]+": "+(i?h:n.number(h)))}return null!=this._alpha&&e.push("alpha: "+n.number(this._alpha)),"{ "+e.join(", ")+" }"},toCSS:function(t){var e=this._convert("rgb"),i=t||null==this._alpha?1:this._alpha;return e=[Math.round(255*e[0]),Math.round(255*e[1]),Math.round(255*e[2])],1>i&&e.push(i),(4==e.length?"rgba(":"rgb(")+e.join(",")+")"},toCanvasStyle:function(t,e){if(this._canvasStyle)return this._canvasStyle;if("gradient"!==this._type)return this._canvasStyle=this.toCSS();var i,n=this._components,r=e?e.getTranslation():new o,s=n[0],a=s._stops,h=n[1].subtract(r),u=n[2].subtract(r);if(s._radial){var l=u.getDistance(h),c=n[3];if(c){c=c.subtract(r);var d=c.subtract(h);d.getLength()>l&&(c=h.add(d.normalize(l-.1)))}var _=c||h;i=t.createRadialGradient(_.x,_.y,0,h.x,h.y,l)}else i=t.createLinearGradient(h.x,h.y,u.x,u.y);for(var f=0,g=a.length;g>f;f++){var m=a[f];i.addColorStop(m._rampPoint,m._color.toCanvasStyle())}return this._canvasStyle=i},transform:function(t){if("gradient"===this._type){for(var e=this._components,i=1,n=e.length;n>i;i++){var r=e[i];t._transformPoint(r,r,!0)}this._changed()}},statics:{_types:r,random:function(){var t=Math.random;return new B(t(),t(),t())}}})},new function(){function t(t,e){return 0>t?0:e&&t>360?360:!e&&t>1?1:t}var i={add:function(e,i,n){return t(e+i,n)},subtract:function(e,i,n){return t(e-i,n)},multiply:function(e,i,n){return t(e*i,n)},divide:function(e,i,n){return t(e/i,n)}};return e.each(i,function(t,e){var i={dontParse:/^(multiply|divide)$/.test(e)};this[e]=function(e){e=B.read(arguments,0,0,i);for(var n=this._type,r=this._properties,s=this._components,a=e._convert(n),h=0,o=s.length;o>h;h++)a[h]=t(s[h],a[h],"hue"===r[h]);return new B(n,a,null!=this._alpha?t(this._alpha,e.getAlpha()):null)}},{})});e.each(B._types,function(t,i){var n=this[e.capitalize(i)+"Color"]=function(t){var e=null!=t&&typeof t,n="object"===e&&null!=t.length?t:"string"===e?null:arguments;return n?new B(i,n):new B(t)};if(3==i.length){var r=i.toUpperCase();B[r]=this[r+"Color"]=n}},e.exports);var F=e.extend({_class:"Gradient",initialize:function we(t,e){this._id=we._id=(we._id||0)+1,t&&this._set(t)&&(t=e=null),this._stops||this.setStops(t||["white","black"]),null==this._radial&&this.setRadial("string"==typeof e&&"radial"===e||e||!1)},_serialize:function(t,i){return i.add(this,function(){return e.serialize([this._stops,this._radial],t,!0,i)})},_changed:function(){for(var t=0,e=this._owners&&this._owners.length;e>t;t++)this._owners[t]._changed()},_addOwner:function(t){this._owners||(this._owners=[]),this._owners.push(t)},_removeOwner:function(t){var e=this._owners?this._owners.indexOf(t):-1;-1!=e&&(this._owners.splice(e,1),0===this._owners.length&&delete this._owners)},clone:function(){for(var t=[],e=0,i=this._stops.length;i>e;e++)t[e]=this._stops[e].clone();return new this.constructor(t) -},getStops:function(){return this._stops},setStops:function(t){if(this.stops)for(var e=0,i=this._stops.length;i>e;e++)delete this._stops[e]._owner;if(t.length<2)throw Error("Gradient stop list needs to contain at least two stops.");this._stops=q.readAll(t,0,!1,!0);for(var e=0,i=this._stops.length;i>e;e++){var n=this._stops[e];n._owner=this,n._defaultRamp&&n.setRampPoint(e/(i-1))}this._changed()},getRadial:function(){return this._radial},setRadial:function(t){this._radial=t,this._changed()},equals:function(t){if(t===this)return!0;if(t&&this._class===t._class&&this._stops.length===t._stops.length){for(var e=0,i=this._stops.length;i>e;e++)if(!this._stops[e].equals(t._stops[e]))return!1;return!0}return!1}}),q=e.extend({_class:"GradientStop",initialize:function(e,i){if(e){var n,r;i===t&&Array.isArray(e)?(n=e[0],r=e[1]):e.color?(n=e.color,r=e.rampPoint):(n=e,r=i),this.setColor(n),this.setRampPoint(r)}},clone:function(){return new q(this._color.clone(),this._rampPoint)},_serialize:function(t,i){return e.serialize([this._color,this._rampPoint],t,!0,i)},_changed:function(){this._owner&&this._owner._changed(17)},getRampPoint:function(){return this._rampPoint},setRampPoint:function(t){this._defaultRamp=null==t,this._rampPoint=t||0,this._changed()},getColor:function(){return this._color},setColor:function(t){this._color=B.read(arguments),this._color===t&&(this._color=t.clone()),this._color._owner=this,this._changed()},equals:function(t){return t===this||t&&this._class===t._class&&this._color.equals(t._color)&&this._rampPoint==t._rampPoint||!1}}),E=e.extend(new function(){var i={fillColor:t,strokeColor:t,strokeWidth:1,strokeCap:"butt",strokeJoin:"miter",miterLimit:10,dashOffset:0,dashArray:[],windingRule:"nonzero",shadowColor:t,shadowBlur:0,shadowOffset:new o,selectedColor:t,font:"sans-serif",fontSize:12,leading:null,justification:"left"},n={strokeWidth:25,strokeCap:25,strokeJoin:25,miterLimit:25,font:5,fontSize:5,leading:5,justification:5},r={},s={_defaults:i,_textDefaults:e.merge(i,{fillColor:new B})};return e.each(i,function(i,a){var h=/Color$/.test(a),o=e.capitalize(a),u=n[a],l="set"+o,c="get"+o;s[l]=function(t){var e=this._item&&this._item._children;if(e&&e.length>0&&"compound-path"!==this._item._type)for(var i=0,n=e.length;n>i;i++)e[i]._style[l](t);else{var r=this._values[a];r!=t&&(h&&(r&&delete r._owner,t&&t.constructor===B&&(t._owner=this._item)),this._values[a]=t,this._item&&this._item._changed(u||17))}},s[c]=function(){var i,n=this._item&&this._item._children;if(!n||0===n.length||arguments[0]||"compound-path"===this._item._type){var i=this._values[a];return i===t?(i=this._defaults[a],i&&i.clone&&(i=i.clone()),this._values[a]=i):!h||i&&i.constructor===B||(this._values[a]=i=B.read([i],0,0,{readNull:!0,clone:!0}),i&&(i._owner=this._item)),i}for(var r=0,s=n.length;s>r;r++){var o=n[r]._style[c]();if(0===r)i=o;else if(!e.equals(i,o))return t}return i},r[c]=function(){return this._style[c]()},r[l]=function(t){this._style[l](t)}}),y.inject(r),s},{_class:"Style",initialize:function(t,e){this._values={},this._item=e,e instanceof N&&(this._defaults=this._textDefaults),t&&this.set(t)},set:function(t){var e=t instanceof E,i=e?t._values:t;if(i)for(var n in i)if(n in this._defaults){var r=i[n];this[n]=r&&e&&r.clone?r.clone():r}},equals:function(t){return t===this||t&&this._class===t._class&&e.equals(this._values,t._values)||!1},hasFill:function(){return!!this.getFillColor()},hasStroke:function(){return!!this.getStrokeColor()&&this.getStrokeWidth()>0},getLeading:function xe(){var t=xe.base.call(this);return null!=t?t:1.2*this.getFontSize()},getFontStyle:function(){var t=this.getFontSize();return t+(/[a-z]/i.test(t+"")?" ":"px ")+this.getFont()}}),R=new function(){function i(t,n){for(var r=[],s=0,a=t&&t.length;a>s;){var h=t[s++];if("string"==typeof h)h=document.createElement(h);else if(!h||!h.nodeType)continue;e.isPlainObject(t[s])&&R.set(h,t[s++]),Array.isArray(t[s])&&i(t[s++],h),n&&n.appendChild(h),r.push(h)}return r}var n=/^(checked|value|selected|disabled)$/i,r={text:"textContent",html:"innerHTML"},s={lineHeight:1,zoom:1,zIndex:1,opacity:1};return{create:function(t,e){var n=Array.isArray(t),r=i(n?t:arguments,n?e:null);return 1==r.length?r[0]:r},find:function(t,e){return(e||document).querySelector(t)},findAll:function(t,e){return(e||document).querySelectorAll(t)},get:function(t,e){return t?n.test(e)?"value"===e||"string"!=typeof t[e]?t[e]:!0:e in r?t[r[e]]:t.getAttribute(e):null},set:function(e,i,s){if("string"!=typeof i)for(var a in i)i.hasOwnProperty(a)&&this.set(e,a,i[a]);else{if(!e||s===t)return e;n.test(i)?e[i]=s:i in r?e[r[i]]=s:"style"===i?this.setStyle(e,s):"events"===i?V.add(e,s):e.setAttribute(i,s)}return e},getStyles:function(t){var e=t&&9!==t.nodeType?t.ownerDocument:t,i=e&&e.defaultView;return i&&i.getComputedStyle(t,"")},getStyle:function(t,e){return t&&t.style[e]||this.getStyles(t)[e]||null},setStyle:function(t,e,i){if("string"!=typeof e)for(var n in e)e.hasOwnProperty(n)&&this.setStyle(t,n,e[n]);else!/^-?[\d\.]+$/.test(i)||e in s||(i+="px"),t.style[e]=i;return t},hasClass:function(t,e){return RegExp("\\s*"+e+"\\s*").test(t.className)},addClass:function(t,e){t.className=(t.className+" "+e).trim()},removeClass:function(t,e){t.className=t.className.replace(RegExp("\\s*"+e+"\\s*")," ").trim()},remove:function(t){t.parentNode&&t.parentNode.removeChild(t)},removeChildren:function(t){for(;t.firstChild;)t.removeChild(t.firstChild)},getBounds:function(t,e){var i,n=t.ownerDocument,r=n.body,s=n.documentElement;try{i=t.getBoundingClientRect()}catch(a){i={left:0,top:0,width:0,height:0}}var h=i.left-(s.clientLeft||r.clientLeft||0),o=i.top-(s.clientTop||r.clientTop||0);if(!e){var u=n.defaultView;h+=u.pageXOffset||s.scrollLeft||r.scrollLeft,o+=u.pageYOffset||s.scrollTop||r.scrollTop}return new _(h,o,i.width,i.height)},getViewportBounds:function(t){var e=t.ownerDocument,i=e.defaultView,n=e.documentElement;return new _(0,0,i.innerWidth||n.clientWidth,i.innerHeight||n.clientHeight)},getOffset:function(t,e){return this.getBounds(t,e).getPoint()},getSize:function(t){return this.getBounds(t,!0).getSize()},isInvisible:function(t){return this.getSize(t).equals(new c(0,0))},isInView:function(t){return!this.isInvisible(t)&&this.getViewportBounds(t).intersects(this.getBounds(t,!0))},getPrefixValue:function(t,e){for(var i=t[e],n=["webkit","moz","ms","o"],r=e[0].toUpperCase()+e.substring(1),s=0;4>s&&null==i;s++)i=t[n[s]+r];return i}}},V={add:function(t,e){for(var i in e){var n=e[i];t.addEventListener?t.addEventListener(i,n,!1):t.attachEvent&&t.attachEvent("on"+i,n.bound=function(){n.call(t,window.event)})}},remove:function(t,e){for(var i in e){var n=e[i];t.removeEventListener?t.removeEventListener(i,n,!1):t.detachEvent&&t.detachEvent("on"+i,n.bound)}},getPoint:function(t){var e=t.targetTouches?t.targetTouches.length?t.targetTouches[0]:t.changedTouches[0]:t;return new o(e.pageX||e.clientX+document.documentElement.scrollLeft,e.pageY||e.clientY+document.documentElement.scrollTop)},getTarget:function(t){return t.target||t.srcElement},getOffset:function(t,e){return V.getPoint(t).subtract(R.getOffset(e||V.getTarget(t)))},preventDefault:function(t){t.preventDefault?t.preventDefault():t.returnValue=!1},stopPropagation:function(t){t.stopPropagation?t.stopPropagation():t.cancelBubble=!0},stop:function(t){V.stopPropagation(t),V.preventDefault(t)}};V.requestAnimationFrame=new function(){var e="equestAnimationFrame",i=window["r"+e]||window["webkitR"+e]||window["mozR"+e]||window["oR"+e]||window["msR"+e];i&&i(function(t){null==t&&(i=null)});var n,s=[],a=!0;return V.add(window,{focus:function(){a=!0},blur:function(){a=!1}}),function(e,h){return i?i(e,h):(s.push([e,h]),n||(n=setInterval(function(){for(var t=s.length-1;t>=0;t--){var e=s[t],i=e[0],n=e[1];(!n||("true"==r.getAttribute(n,"keepalive")||a)&&R.isInView(n))&&(s.splice(t,1),i(Date.now()))}},1e3/60)),t)}};var Z=e.extend(n,{_class:"View",initialize:function be(t){this._scope=paper,this._project=paper.project,this._element=t;var e;if(this._id=t.getAttribute("id"),null==this._id&&t.setAttribute("id",this._id="view-"+be._id++),V.add(t,this._viewHandlers),r.hasAttribute(t,"resize")){var i=R.getOffset(t,!0),n=this;e=R.getViewportBounds(t).getSize().subtract(i),this._windowHandlers={resize:function(){R.isInvisible(t)||(i=R.getOffset(t,!0)),n.setViewSize(R.getViewportBounds(t).getSize().subtract(i))}},V.add(window,this._windowHandlers)}else e=new c(parseInt(t.getAttribute("width"),10),parseInt(t.getAttribute("height"),10)),e.isNaN()&&(e=R.getSize(t));if(t.width=e.width,t.height=e.height,r.hasAttribute(t,"stats")&&"object"==typeof Stats){this._stats=new Stats;var s=this._stats.domElement,a=s.style,i=R.getOffset(t);a.position="absolute",a.left=i.x+"px",a.top=i.y+"px",document.body.appendChild(s)}be._views.push(this),be._viewsById[this._id]=this,this._viewSize=new d(e.width,e.height,this,"setViewSize"),this._matrix=new g,this._zoom=1,be._focused||(be._focused=this),this._frameItems={},this._frameItemCount=0},remove:function(){return this._project?(Z._focused==this&&(Z._focused=null),Z._views.splice(Z._views.indexOf(this),1),delete Z._viewsById[this._id],this._project.view==this&&(this._project.view=null),V.remove(this._element,this._viewHandlers),V.remove(window,this._windowHandlers),this._element=this._project=null,this.detach("frame"),this._frameItems={},!0):!1},_events:{onFrame:{install:function(){this._requested||(this._animate=!0,this._requestFrame())},uninstall:function(){this._animate=!1}},onResize:{}},_animate:!1,_time:0,_count:0,_requestFrame:function(){var t=this;V.requestAnimationFrame(function(){t._requested=!1,t._animate&&(t._requestFrame(),t._handleFrame())},this._element),this._requested=!0},_handleFrame:function(){paper=this._scope;var t=Date.now()/1e3,i=this._before?t-this._before:0;this._before=t,this._handlingFrame=!0,this.fire("frame",e.merge({delta:i,time:this._time+=i,count:this._count++})),this._stats&&this._stats.update(),this._handlingFrame=!1,this.draw(!0)},_animateItem:function(t,e){var i=this._frameItems;e?(i[t._id]={item:t,time:0,count:0},1===++this._frameItemCount&&this.attach("frame",this._handleFrameItems)):(delete i[t._id],0===--this._frameItemCount&&this.detach("frame",this._handleFrameItems))},_handleFrameItems:function(t){for(var i in this._frameItems){var n=this._frameItems[i];n.item.fire("frame",e.merge(t,{time:n.time+=t.delta,count:n.count++}))}},_redraw:function(){this._project._needsRedraw=!0,this._handlingFrame||(this._animate?this._handleFrame():this.draw())},_transform:function(t){this._matrix.concatenate(t),this._bounds=null,this._redraw()},getElement:function(){return this._element},getViewSize:function(){return this._viewSize},setViewSize:function(t){t=c.read(arguments);var e=t.subtract(this._viewSize);e.isZero()||(this._element.width=t.width,this._element.height=t.height,this._viewSize.set(t.width,t.height,!0),this._bounds=null,this.fire("resize",{size:t,delta:e}),this._redraw())},getBounds:function(){return this._bounds||(this._bounds=this._matrix.inverted()._transformBounds(new _(new o,this._viewSize))),this._bounds},getSize:function(){return this.getBounds().getSize(arguments[0])},getCenter:function(){return this.getBounds().getCenter(arguments[0])},setCenter:function(t){t=o.read(arguments),this.scrollBy(t.subtract(this.getCenter()))},getZoom:function(){return this._zoom},setZoom:function(t){this._transform((new g).scale(t/this._zoom,this.getCenter())),this._zoom=t},isVisible:function(){return R.isInView(this._element)},scrollBy:function(){this._transform((new g).translate(o.read(arguments).negate()))},projectToView:function(){return this._matrix._transformPoint(o.read(arguments))},viewToProject:function(){return this._matrix._inverseTransform(o.read(arguments))}},{statics:{_views:[],_viewsById:{},_id:0,create:function(t){return"string"==typeof t&&(t=document.getElementById(t)),new H(t)}}},new function(){function t(t){var e=V.getTarget(t);return e.getAttribute&&Z._viewsById[e.getAttribute("id")]}function e(t,e){return t.viewToProject(V.getOffset(e,t._element))}function i(){if(!Z._focused||!Z._focused.isVisible())for(var t=0,e=Z._views.length;e>t;t++){var i=Z._views[t];if(i&&i.isVisible()){Z._focused=u=i;break}}}function n(i){var n=Z._focused=t(i),r=e(n,i);l=!0,n._onMouseDown&&n._onMouseDown(i,r),(h=n._scope._tool)&&h._onHandleEvent("mousedown",r,i),n.draw(!0)}function r(n){var r;if(l||(r=t(n),r?(o=Z._focused,Z._focused=u=r):u&&u==Z._focused&&(Z._focused=o,i())),r=r||Z._focused){var s=n&&e(r,n);r._onMouseMove&&r._onMouseMove(n,s),(h=r._scope._tool)&&h._onHandleEvent(l&&h.responds("mousedrag")?"mousedrag":"mousemove",s,n)&&V.stop(n),r.draw(!0)}}function s(t){var i=Z._focused;if(i&&l){var n=e(i,t);curPoint=null,l=!1,i._onMouseUp&&i._onMouseUp(t,n),h&&h._onHandleEvent("mouseup",n,t)&&V.stop(t),i.draw(!0)}}function a(t){l&&V.stop(t)}var h,o,u,l=!1;return V.add(document,{mousemove:r,mouseup:s,touchmove:r,touchend:s,selectstart:a,scroll:i}),V.add(window,{load:i}),{_viewHandlers:{mousedown:n,touchstart:n,selectstart:a},statics:{updateFocus:i}}}),H=Z.extend({_class:"CanvasView",initialize:function(t){if(!(t instanceof HTMLCanvasElement)){var e=c.read(arguments);if(e.isZero())throw Error("Cannot create CanvasView with the provided arguments: "+arguments);t=$.getCanvas(e)}var i=this._context=t.getContext("2d");this._eventCounters={};var n=(window.devicePixelRatio||1)/(R.getPrefixValue(i,"backingStorePixelRatio")||1);if(n>1){var r=t.clientWidth,s=t.clientHeight,a=t.style;t.width=r*n,t.height=s*n,a.width=r+"px",a.height=s+"px",i.scale(n,n)}Z.call(this,t)},draw:function(t){if(t&&!this._project._needsRedraw)return!1;var e=this._context,i=this._viewSize;return e.clearRect(0,0,i._width+1,i._height+1),this._project.draw(e,this._matrix),this._project._needsRedraw=!1,!0}},new function(){function t(t,e,i,n,r,s){for(var a,h=n;h;){if(h.responds(t)&&(a||(a=new J(t,e,i,n,r?i.subtract(r):null)),h.fire(t,a)&&(!s||a._stopped)))return!1;h=h.getParent()}return!0}function e(e,i,n,r,s){if(e._eventCounters[i]){var a=e._project,u=a.hitTest(r,{tolerance:a.options.hitTolerance||0,fill:!0,stroke:!0}),l=u&&u.item;if(l)return"mousemove"===i&&l!=h&&(s=r),"mousemove"===i&&o||t(i,n,r,l,s),l}}var i,n,r,s,a,h,o,u,l;return{_onMouseDown:function(t,h){var c=e(this,"mousedown",t,h);u=a==c&&Date.now()-l<300,s=a=c,i=n=r=h,o=s&&s.responds("mousedrag")},_onMouseUp:function(a,h){var c=e(this,"mouseup",a,h);o&&(n&&!n.equals(h)&&t("mousedrag",a,h,s,n),c!=s&&(r=h,t("mousemove",a,h,c,r))),c===s&&(l=Date.now(),(!u||t("doubleclick",a,i,c))&&t("click",a,i,c),u=!1),s=null,o=!1},_onMouseMove:function(i,a){s&&t("mousedrag",i,a,s,n);var o=e(this,"mousemove",i,a,r);n=r=a,o!==h&&(t("mouseleave",i,a,h),h=o,t("mouseenter",i,a,o))}}}),W=e.extend({_class:"Event",initialize:function(t){this.event=t},preventDefault:function(){this._prevented=!0,V.preventDefault(this.event)},stopPropagation:function(){this._stopped=!0,V.stopPropagation(this.event)},stop:function(){this.stopPropagation(),this.preventDefault()},getModifiers:function(){return X.modifiers}}),G=W.extend({_class:"KeyEvent",initialize:function(t,e,i,n){W.call(this,n),this.type=t?"keydown":"keyup",this.key=e,this.character=i},toString:function(){return"{ type: '"+this.type+"', key: '"+this.key+"', character: '"+this.character+"', modifiers: "+this.getModifiers()+" }"}}),X=new function(){function t(t,e,i,r){var s=String.fromCharCode(i),h=n[e]||s.toLowerCase(),o=t?"keydown":"keyup",u=Z._focused,l=u&&u.isVisible()&&u._scope,c=l&&l._tool;a[h]=t,c&&c.responds(o)&&(c.fire(o,new G(t,h,s,r)),u&&u.draw(!0))}var i,n={8:"backspace",9:"tab",13:"enter",16:"shift",17:"control",18:"option",19:"pause",20:"caps-lock",27:"escape",32:"space",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",46:"delete",91:"command",93:"command",224:"command"},r=e.merge({shift:!1,control:!1,option:!1,command:!1,capsLock:!1,space:!1}),s={},a={};return V.add(document,{keydown:function(a){var h,o=a.which||a.keyCode,u=n[o];u?((h=e.camelize(u))in r&&(r[h]=!0),s[o]=0,t(!0,o,null,a)):i=o},keypress:function(e){if(null!=i){var n=e.which||e.keyCode;s[i]=n,t(!0,i,n,e),i=null}},keyup:function(i){var a,h=i.which||i.keyCode,o=n[h];o&&(a=e.camelize(o))in r&&(r[a]=!1),null!=s[h]&&(t(!1,h,s[h],i),delete s[h])}}),{modifiers:r,isDown:function(t){return!!a[t]}}},J=W.extend({_class:"MouseEvent",initialize:function(t,e,i,n,r){W.call(this,e),this.type=t,this.point=i,this.target=n,this.delta=r},toString:function(){return"{ type: '"+this.type+"', point: "+this.point+", target: "+this.target+(this.delta?", delta: "+this.delta:"")+", modifiers: "+this.getModifiers()+" }"}}),Y=W.extend({_class:"ToolEvent",_item:null,initialize:function(t,e,i){this.tool=t,this.type=e,this.event=i},_choosePoint:function(t,e){return t?t:e?e.clone():null},getPoint:function(){return this._choosePoint(this._point,this.tool._point)},setPoint:function(t){this._point=t},getLastPoint:function(){return this._choosePoint(this._lastPoint,this.tool._lastPoint)},setLastPoint:function(t){this._lastPoint=t},getDownPoint:function(){return this._choosePoint(this._downPoint,this.tool._downPoint)},setDownPoint:function(t){this._downPoint=t},getMiddlePoint:function(){return!this._middlePoint&&this.tool._lastPoint?this.tool._point.add(this.tool._lastPoint).divide(2):this._middlePoint},setMiddlePoint:function(t){this._middlePoint=t},getDelta:function(){return!this._delta&&this.tool._lastPoint?this.tool._point.subtract(this.tool._lastPoint):this._delta},setDelta:function(t){this._delta=t},getCount:function(){return/^mouse(down|up)$/.test(this.type)?this.tool._downCount:this.tool._count},setCount:function(t){this.tool[/^mouse(down|up)$/.test(this.type)?"downCount":"count"]=t},getItem:function(){if(!this._item){var t=this.tool._scope.project.hitTest(this.getPoint());if(t){for(var e=t.item,i=e._parent;/^(group|compound-path)$/.test(i._type);)e=i,i=i._parent;this._item=e}}return this._item},setItem:function(t){this._item=t},toString:function(){return"{ type: "+this.type+", point: "+this.getPoint()+", count: "+this.getCount()+", modifiers: "+this.getModifiers()+" }"}}),U=s.extend({_class:"Tool",_list:"tools",_reference:"_tool",_events:["onActivate","onDeactivate","onEditOptions","onMouseDown","onMouseUp","onMouseDrag","onMouseMove","onKeyDown","onKeyUp"],initialize:function(t){s.call(this),this._firstMove=!0,this._count=0,this._downCount=0,this._set(t)},getMinDistance:function(){return this._minDistance},setMinDistance:function(t){this._minDistance=t,null!=this._minDistance&&null!=this._maxDistance&&this._minDistance>this._maxDistance&&(this._maxDistance=this._minDistance)},getMaxDistance:function(){return this._maxDistance},setMaxDistance:function(t){this._maxDistance=t,null!=this._minDistance&&null!=this._maxDistance&&this._maxDistanceu)return!1;var l=null!=n?n:0;if(0!=l)if(u>l)e=this._point.add(o.normalize(l));else if(a)return!1}if(s&&e.equals(this._point))return!1}switch(this._lastPoint=r&&"mousemove"==t?e:this._point,this._point=e,t){case"mousedown":this._lastPoint=this._downPoint,this._downPoint=this._point,this._downCount++;break;case"mouseup":this._lastPoint=this._downPoint}return this._count=r?0:this._count+1,!0},_fireEvent:function(t,e){var i=paper.project._removeSets;if(i){"mouseup"===t&&(i.mousedrag=null);var n=i[t];if(n){for(var r in n){var s=n[r];for(var a in i){var h=i[a];h&&h!=n&&delete h[s._id]}s.remove()}i[t]=null}}return this.responds(t)&&this.fire(t,new Y(this,t,e))},_onHandleEvent:function(t,e,i){paper=this._scope;var n=!1;switch(t){case"mousedown":this._updateEvent(t,e,null,null,!0,!1,!1),n=this._fireEvent(t,i);break;case"mousedrag":for(var r=!1,s=!1;this._updateEvent(t,e,this.minDistance,this.maxDistance,!1,r,s);)n=this._fireEvent(t,i)||n,r=!0,s=!0;break;case"mouseup":!e.equals(this._point)&&this._updateEvent("mousedrag",e,this.minDistance,this.maxDistance,!1,!1,!1)&&(n=this._fireEvent("mousedrag",i)),this._updateEvent(t,e,null,this.maxDistance,!1,!1,!1),n=this._fireEvent(t,i)||n,this._updateEvent(t,e,null,null,!0,!1,!1),this._firstMove=!0;break;case"mousemove":for(;this._updateEvent(t,e,this.minDistance,this.maxDistance,this._firstMove,!0,!1);)n=this._fireEvent(t,i)||n,this._firstMove=!1}return n}}),$={canvases:[],getCanvas:function(e,i){var n,r=i===t?e:new c(e,i),s=!0;n=this.canvases.length?this.canvases.pop():document.createElement("canvas");var a=n.getContext("2d");return a.save(),n.width===r.width&&n.height===r.height?s&&a.clearRect(0,0,r.width+1,r.height+1):(n.width=r.width,n.height=r.height),n},getContext:function(t,e){return this.getCanvas(t,e).getContext("2d")},release:function(t){var e=t.canvas?t.canvas:t;e.getContext("2d").restore(),this.canvases.push(e)}},K=new function(){function t(t,e,i){return.2989*t+.587*e+.114*i}function i(e,i,n,r){var s=r-t(e,i,n);_=e+s,f=i+s,g=n+s;var r=t(_,f,g),a=m(_,f,g),h=v(_,f,g);if(0>a){var o=r-a;_=r+(_-r)*r/o,f=r+(f-r)*r/o,g=r+(g-r)*r/o}if(h>255){var u=255-r,l=h-r;_=r+(_-r)*u/l,f=r+(f-r)*u/l,g=r+(g-r)*u/l}}function n(t,e,i){return v(t,e,i)-m(t,e,i)}function r(t,e,i,n){var r,s=[t,e,i],a=v(t,e,i),h=m(t,e,i);h=h===t?0:h===e?1:2,a=a===t?0:a===e?1:2,r=0===m(h,a)?1===v(h,a)?2:1:0,s[a]>s[h]?(s[r]=(s[r]-s[h])*n/(s[a]-s[h]),s[a]=n):s[r]=s[a]=0,s[h]=0,_=s[0],f=s[1],g=s[2]}var s,a,h,o,u,l,c,d,_,f,g,m=Math.min,v=Math.max,p=Math.abs,y={multiply:function(){_=u*s/255,f=l*a/255,g=c*h/255},screen:function(){_=u+s-u*s/255,f=l+a-l*a/255,g=c+h-c*h/255},overlay:function(){_=128>u?2*u*s/255:255-2*(255-u)*(255-s)/255,f=128>l?2*l*a/255:255-2*(255-l)*(255-a)/255,g=128>c?2*c*h/255:255-2*(255-c)*(255-h)/255},"soft-light":function(){var t=s*u/255;_=t+u*(255-(255-u)*(255-s)/255-t)/255,t=a*l/255,f=t+l*(255-(255-l)*(255-a)/255-t)/255,t=h*c/255,g=t+c*(255-(255-c)*(255-h)/255-t)/255},"hard-light":function(){_=128>s?2*s*u/255:255-2*(255-s)*(255-u)/255,f=128>a?2*a*l/255:255-2*(255-a)*(255-l)/255,g=128>h?2*h*c/255:255-2*(255-h)*(255-c)/255},"color-dodge":function(){_=0===u?0:255===s?255:m(255,255*u/(255-s)),f=0===l?0:255===a?255:m(255,255*l/(255-a)),g=0===c?0:255===h?255:m(255,255*c/(255-h))},"color-burn":function(){_=255===u?255:0===s?0:v(0,255-255*(255-u)/s),f=255===l?255:0===a?0:v(0,255-255*(255-l)/a),g=255===c?255:0===h?0:v(0,255-255*(255-c)/h)},darken:function(){_=s>u?u:s,f=a>l?l:a,g=h>c?c:h},lighten:function(){_=u>s?u:s,f=l>a?l:a,g=c>h?c:h},difference:function(){_=u-s,0>_&&(_=-_),f=l-a,0>f&&(f=-f),g=c-h,0>g&&(g=-g)},exclusion:function(){_=u+s*(255-u-u)/255,f=l+a*(255-l-l)/255,g=c+h*(255-c-c)/255},hue:function(){r(s,a,h,n(u,l,c)),i(_,f,g,t(u,l,c))},saturation:function(){r(u,l,c,n(s,a,h)),i(_,f,g,t(u,l,c))},luminosity:function(){i(u,l,c,t(s,a,h))},color:function(){i(s,a,h,t(u,l,c))},add:function(){_=m(u+s,255),f=m(l+a,255),g=m(c+h,255)},subtract:function(){_=v(u-s,0),f=v(l-a,0),g=v(c-h,0)},average:function(){_=(u+s)/2,f=(l+a)/2,g=(c+h)/2},negation:function(){_=255-p(255-s-u),f=255-p(255-a-l),g=255-p(255-h-c)}},w=this.nativeModes=e.each(["source-over","source-in","source-out","source-atop","destination-over","destination-in","destination-out","destination-atop","lighter","darker","copy","xor"],function(t){this[t]=!0},{}),x=$.getContext(1,1);e.each(y,function(t,e){x.save();var i="darken"===e,n=!1;x.fillStyle=i?"#300":"#a00",x.fillRect(0,0,1,1),x.globalCompositeOperation=e,x.globalCompositeOperation===e&&(x.fillStyle=i?"#a00":"#300",x.fillRect(0,0,1,1),n=x.getImageData(0,0,1,1).data[0]!==(i?170:51)),w[e]=n,x.restore()}),$.release(x),this.process=function(t,e,i,n,r){var m=e.canvas,v="normal"===t;if(v||w[t])i.save(),i.setTransform(1,0,0,1,0,0),i.globalAlpha=n,v||(i.globalCompositeOperation=t),i.drawImage(m,r.x,r.y),i.restore();else{var p=y[t];if(!p)return;for(var x=i.getImageData(r.x,r.y,m.width,m.height),b=x.data,C=e.getImageData(0,0,m.width,m.height).data,S=0,P=b.length;P>S;S+=4){s=C[S],u=b[S],a=C[S+1],l=b[S+1],h=C[S+2],c=b[S+2],o=C[S+3],d=b[S+3],p();var z=o*n/255,M=1-z;b[S]=z*_+M*u,b[S+1]=z*f+M*l,b[S+2]=z*g+M*c,b[S+3]=o*n+M*d}i.putImageData(x,r.x,r.y)}}},Q=e.each({fillColor:["fill","color"],strokeColor:["stroke","color"],strokeWidth:["stroke-width","number"],strokeCap:["stroke-linecap","string"],strokeJoin:["stroke-linejoin","string"],miterLimit:["stroke-miterlimit","number"],dashArray:["stroke-dasharray","array"],dashOffset:["stroke-dashoffset","number"],font:["font-family","string"],fontSize:["font-size","number"],justification:["text-anchor","lookup",{left:"start",center:"middle",right:"end"}],opacity:["opacity","number"],blendMode:["mix-blend-mode","string"]},function(t,i){var n=e.capitalize(i),r=t[2];this[i]={type:t[1],property:i,attribute:t[0],toSVG:r,fromSVG:r&&e.each(r,function(t,e){this[t]=e},{}),get:"get"+n,set:"set"+n}},{}),te={href:"http://www.w3.org/1999/xlink",xlink:"http://www.w3.org/2000/xmlns"};return new function(){function t(t,e){for(var i in e){var n=e[i],r=te[i];"number"==typeof n&&(n=S.number(n)),r?t.setAttributeNS(r,i,n):t.setAttribute(i,n)}return t}function n(e,i){return t(document.createElementNS("http://www.w3.org/2000/svg",e),i)}function r(t,e,i){var n=t._matrix,r=n.getTranslation(),s={};if(e){n=n.shiftless();var a=n._inverseTransform(r);s[i?"cx":"x"]=a.x,s[i?"cy":"y"]=a.y,r=null}if(n.isIdentity())return s;var o=n.decompose();if(o&&!o.shearing){var u=[],l=o.rotation,c=o.scaling;r&&!r.isZero()&&u.push("translate("+S.point(r)+")"),h.isZero(c.x-1)&&h.isZero(c.y-1)||u.push("scale("+S.point(c)+")"),l&&u.push("rotate("+S.number(l)+")"),s.transform=u.join(" ")}else s.transform="matrix("+n.getValues().join(",")+")";return s}function s(e){for(var i=r(e),s=e._children,a=n("g",i),h=0,o=s.length;o>h;h++){var u=s[h],l=b(u);if(l)if(u.isClipMask()){var c=n("clipPath");c.appendChild(l),w(u,c,"clip"),t(a,{"clip-path":"url(#"+c.id+")"})}else a.appendChild(l)}return a}function o(t){var e=r(t,!0),i=t.getSize();return e.x-=i.width/2,e.y-=i.height/2,e.width=i.width,e.height=i.height,e.href=t.toDataURL(),n("image",e)}function u(t){var e,r,s=t._segments;if(0===s.length)return null;if(t.isPolygon())if(s.length>=3){e=t._closed?"polygon":"polyline";var a=[];for(i=0,l=s.length;l>i;i++)a.push(S.point(s[i]._point));r={points:a.join(" ")}}else{e="line";var h=s[0]._point,o=s[s.length-1]._point;r={x1:h.x,y1:h.y,x2:o.x,y2:o.y}}else{e="path";var u=t.getPathData();r=u&&{d:u}}return n(e,r)}function c(t){var e=t._shape,i=(t.getPosition(!0),t._radius),s=r(t,!0,"rectangle"!==e);if("rectangle"===e){e="rect";var a=t._size,h=a.width,o=a.height;s.x-=h/2,s.y-=o/2,s.width=h,s.height=o,i.isZero()&&(i=null)}return i&&("circle"===e?s.r=i:(s.rx=i.width,s.ry=i.height)),n(e,s)}function d(t){var e=r(t,!0),i=t.getPathData();return i&&(e.d=i),n("path",e)}function _(t){var e=r(t,!0),i=t.getSymbol(),s=p(i,"symbol"),a=i.getDefinition(),h=a.getBounds();return s||(s=n("symbol",{viewBox:S.rectangle(h)}),s.appendChild(b(a)),w(i,s,"symbol")),e.href="#"+s.id,e.x+=h.x,e.y+=h.y,e.width=S.number(h.width),e.height=S.number(h.height),n("use",e)}function f(t){var e=p(t,"color");if(!e){var i,r=t.getGradient(),s=r._radial,a=t.getOrigin().transform(),h=t.getDestination().transform();if(s){i={cx:a.x,cy:a.y,r:a.getDistance(h)};var o=t.getHighlight();o&&(o=o.transform(),i.fx=o.x,i.fy=o.y)}else i={x1:a.x,y1:a.y,x2:h.x,y2:h.y};i.gradientUnits="userSpaceOnUse",e=n((s?"radial":"linear")+"Gradient",i);for(var u=r._stops,l=0,c=u.length;c>l;l++){var d=u[l],_=d._color,f=_.getAlpha();i={offset:d._rampPoint,"stop-color":_.toCSS(!0)},1>f&&(i["stop-opacity"]=f),e.appendChild(n("stop",i))}w(t,e,"color")}return"url(#"+e.id+")"}function g(t){var e=n("text",r(t,!0));return e.textContent=t._content,e}function m(i,n){var r={},s=i.getParent();return null!=i._name&&(r.id=i._name),e.each(Q,function(t){var n=t.get,a=t.type,h=i[n]();if(!s||!e.equals(s[n](),h)){if("color"===a&&null!=h){var o=h.getAlpha();1>o&&(r[t.attribute+"-opacity"]=o)}r[t.attribute]=null==h?"none":"number"===a?S.number(h):"color"===a?h.gradient?f(h,i):h.toCSS(!0):"array"===a?h.join(","):"lookup"===a?t.toSVG[h]:h}}),1===r.opacity&&delete r.opacity,null==i._visibility||i._visibility||(r.visibility="hidden"),t(n,r)}function p(t,e){return P||(P={ids:{},svgs:{}}),t&&P.svgs[e+"-"+t._id]}function w(t,e,i){P||p();var n=P.ids[i]=(P.ids[i]||0)+1;e.id=i+"-"+n,P.svgs[i+"-"+t._id]=e}function x(t,e){if(!P)return t;var i="svg"===t.nodeName.toLowerCase()&&t,r=null;for(var s in P.svgs)r||(i||(i=n("svg"),i.appendChild(t)),r=i.insertBefore(n("defs"),i.firstChild)),r.appendChild(P.svgs[s]);return P=null,e.asString?(new XMLSerializer).serializeToString(i):i}function b(t){var e=z[t._type],i=e&&e(t,t._type);return i&&t._data&&i.setAttribute("data-paper-data",JSON.stringify(t._data)),i&&m(t,i)}function C(t){return t||(t={}),S=new a(t.precision),t}var S,P,z={group:s,layer:s,raster:o,path:u,shape:c,"compound-path":d,"placed-symbol":_,"point-text":g};y.inject({exportSVG:function(t){return t=C(t),x(b(this),t)}}),v.inject({exportSVG:function(t){t=C(t);for(var e=this.layers,i=this.view.getSize(),r=n("svg",{x:0,y:0,width:i.width,height:i.height,version:"1.1",xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink"}),s=0,a=e.length;a>s;s++)r.appendChild(b(e[s]));return x(r,t)}})},new function(){function i(t,e,i,n){var r=te[e],s=r?t.getAttributeNS(r,e):t.getAttribute(e);return"null"===s&&(s=null),null==s?n?null:i?"":0:i?s:parseFloat(s)}function n(t,e,n,r){return e=i(t,e,!1,r),n=i(t,n,!1,r),r&&null==e&&null==n?null:new o(e||0,n||0)}function r(t,e,n,r){return e=i(t,e,!1,r),n=i(t,n,!1,r),r&&null==e&&null==n?null:new c(e||0,n||0)}function s(t,e,i){return"none"===t?null:"number"===e?parseFloat(t):"array"===e?t?t.split(/[\s,]+/g).map(parseFloat):[]:"color"===e?S(t)||t:"lookup"===e?i[t]:t}function a(t,e,i){var n=t.childNodes,r="clippath"===e,s=new w,a=s._project,h=a._currentStyle,o=[];r||(s._transformContent=!1,s=x(s,t),a._currentStyle=s._style.clone());for(var u=0,l=n.length;l>u;u++){var c,d=n[u];1!==d.nodeType||!(c=P(d,i))||c instanceof p||o.push(c)}return s.addChildren(o),r&&(s=x(s.reduce(),t)),a._currentStyle=h,(r||"defs"===e)&&(s.remove(),s=null),s}function h(t,e){var i=new O,n=t.points;i.moveTo(n.getItem(0));for(var r=1,s=n.numberOfItems;s>r;r++)i.lineTo(n.getItem(r));return"polygon"===e&&i.closePath(),i}function u(t){var e=t.getAttribute("d"),i=e.match(/m/gi).length>1?new L:new O;return i.setPathData(e),i}function l(t,e){for(var r=t.childNodes,s=[],a=0,h=r.length;h>a;a++){var o=r[a];1===o.nodeType&&s.push(x(new q,o))}var u,l,c,d="radialgradient"===e,_=new F(s,d);return d?(u=n(t,"cx","cy"),l=u.add(i(t,"r"),0),c=n(t,"fx","fy",!0)):(u=n(t,"x1","y1"),l=n(t,"x2","y2")),x(new B(_,u,l,c),t),null}function d(t,e,i,n){for(var r=(n.getAttribute(i)||"").split(/\)\s*/g),s=new g,a=0,h=r.length;h>a;a++){var o=r[a];if(!o)break;for(var u=o.split("("),l=u[0],c=u[1].split(/[\s,]+/g),d=0,_=c.length;_>d;d++)c[d]=parseFloat(c[d]);switch(l){case"matrix":s.concatenate(new g(c[0],c[1],c[2],c[3],c[4],c[5]));break;case"rotate":s.rotate(c[0],c[1],c[2]);break;case"translate":s.translate(c[0],c[1]);break;case"scale":s.scale(c);break;case"skewX":case"skewY":var e=Math.tan(c[0]*Math.PI/180),f="skewX"==l;s.shear(f?e:0,f?0:e)}}t.transform(s)}function f(t,e,i){var n=t["fill-opacity"===i?"getFillColor":"getStrokeColor"]();n&&n.setAlpha(parseFloat(e))}function m(i,n,r){var s=i.attributes[n],a=s&&s.value;if(!a){var h=e.camelize(n);a=i.style[h],a||r.node[h]===r.parent[h]||(a=r.node[h])}return a?"none"===a?null:a:t}function x(i,n){var r={node:R.getStyles(n)||{},parent:R.getStyles(n.parentNode)||{}};return e.each(M,function(s,a){var h=m(n,a,r);h!==t&&(i=e.pick(s(i,h,a,n,r),i))}),i}function S(t){var e=t&&t.match(/\((?:#|)([^)']+)/);return e&&I[e[1]]}function P(t,e,i){e||(e={}),"string"==typeof t&&(t=(new DOMParser).parseFromString(t,"image/svg+xml"));var n=t.nodeName.toLowerCase(),r=z[n],s=r&&r(t,n,e),a="#document"!==n&&t.getAttribute("data-paper-data"); -return e.expandShapes&&s instanceof b&&(s.remove(),s=s.toPath()),!s||s instanceof w||(s=x(s,t)),s&&a&&(s._data=JSON.parse(a)),i&&(I={}),s}var z={"#document":function(t,e,i){return P(t.childNodes[0],i)},g:a,svg:a,clippath:a,polygon:h,polyline:h,path:u,lineargradient:l,radialgradient:l,image:function(t){var e=new C(i(t,"href",!0));return e.attach("load",function(){var e=r(t,"width","height");this.setSize(e),this.translate(n(t,"x","y").add(e.divide(2)))}),e},symbol:function(t,e){return new p(a(t,e),!0)},defs:a,use:function(t){var e=(i(t,"href",!0)||"").substring(1),r=I[e],s=n(t,"x","y");return r?r instanceof p?r.place(s):r.clone().translate(s):null},circle:function(t){return new b.Circle(n(t,"cx","cy"),i(t,"r"))},ellipse:function(t){return new b.Ellipse({center:n(t,"cx","cy"),radius:r(t,"rx","ry")})},rect:function(t){var e=n(t,"x","y"),i=r(t,"width","height"),s=r(t,"rx","ry");return new b.Rectangle(new _(e,i),s)},line:function(t){return new O.Line(n(t,"x1","y1"),n(t,"x2","y2"))},text:function(t){var e=new j(n(t,"x","y").add(n(t,"dx","dy")));return e.setContent(t.textContent.trim()||""),e}},M=e.merge(e.each(Q,function(t){this[t.attribute]=function(e,i){e[t.set](s(i,t.type,t.fromSVG))}},{}),{id:function(t,e){I[e]=t,t.setName&&t.setName(e)},"clip-path":function(t,e){var i=S(e);if(i){if(i=i.clone(),i.setClipMask(!0),!(t instanceof w))return new w(i,t);t.insertChild(0,i)}},gradientTransform:d,transform:d,"fill-opacity":f,"stroke-opacity":f,visibility:function(t,e){t.setVisible("visible"===e)},"stop-color":function(t,e){t.setColor&&t.setColor(e)},"stop-opacity":function(t,e){t._color&&t._color.setAlpha(parseFloat(e))},offset:function(t,e){var i=e.match(/(.*)%$/);t.setRampPoint(i?i[1]/100:parseFloat(e))},viewBox:function(t,e,i,n,a){var h=new _(s(e,"array")),o=r(n,"width","height",!0);if(t instanceof w){var u=o?h.getSize().divide(o):1,l=(new g).translate(h.getPoint()).scale(u);t.transform(l.inverted())}else if(t instanceof p){o&&h.setSize(o);var c="visible"!=m(n,"overflow",a),d=t._definition;c&&!h.contains(d.getBounds())&&(c=new b.Rectangle(h).transform(d._matrix),c.setClipMask(!0),d.addChild(c))}}}),I={};y.inject({importSVG:function(t,e){return this.addChild(P(t,e,!0))}}),v.inject({importSVG:function(t,e){return this.activate(),P(t,e,!0)}})},paper=new(r.inject(e.merge(e.exports,{enumerable:!0,Base:e,Numerical:h,DomElement:R,DomEvent:V,Key:X}))),"function"==typeof define&&define.amd&&define("paper",paper),paper}; \ No newline at end of file +var paper=new function(t){var e=new function(){function i(e,i,n,r,a,o){function u(r,s,o,u){var s=s||(s=_(i,r))&&(s.get?s:s.value);"string"==typeof s&&"#"===s[0]&&(s=e[s.substring(1)]||s);var c,d="function"==typeof s,f=s,v=a||d?s&&s.get?r in e:e[r]:null;!(o||s!==t&&i.hasOwnProperty(r))||a&&v||(d&&v&&(s.base=v),d&&l&&0===s.length&&(c=r.match(/^(get|is)(([A-Z])(.*))$/))&&l.push([c[3].toLowerCase()+c[4],c[2]]),f&&!d&&f.get&&"function"==typeof f.get&&0===f.get.length||(f={value:f,writable:!0}),(_(e,r)||{configurable:!0}).configurable&&(f.configurable=!0,f.enumerable=n),g(e,r,f)),!u||!d||a&&u[r]||(u[r]=function(t){return t&&e[r].apply(t,h.call(arguments,1))})}var l;if(i){l=[];for(var c in i)i.hasOwnProperty(c)&&!s.test(c)&&u(c,null,!0,o);u("toString"),u("valueOf");for(var d=0,f=l.length;f>d;d++){var v=l[d],m=v[1];u(v[0],{get:e["get"+m]||e["is"+m],set:e["set"+m]},!0)}}return e}function n(i,n,r,s){try{i&&(s||t===s&&c(i)?u:l).call(i,n,r=r||i)}catch(a){if(a!==e.stop)throw a}return r}function r(t){return n(t,function(t,e){this[e]=t},new t.constructor)}var s=/^(statics|generics|preserve|enumerable|prototype|toString|valueOf)$/,a=Object.prototype.toString,o=Array.prototype,h=o.slice,u=o.forEach||function(t,e){for(var i=0,n=this.length;n>i;i++)t.call(e,this[i],i,this)},l=function(t,e){for(var i in this)this.hasOwnProperty(i)&&t.call(e,this[i],i,this)},c=Array.isArray=Array.isArray||function(t){return"[object Array]"===a.call(t)},d=Object.create||function(t){return{__proto__:t}},_=Object.getOwnPropertyDescriptor||function(t,e){var i=t.__lookupGetter__&&t.__lookupGetter__(e);return i?{get:i,set:t.__lookupSetter__(e),enumerable:!0,configurable:!0}:t.hasOwnProperty(e)?{value:t[e],enumerable:!0,configurable:!0,writable:!0}:null},f=Object.defineProperty||function(t,e,i){return(i.get||i.set)&&t.__defineGetter__?(i.get&&t.__defineGetter__(e,i.get),i.set&&t.__defineSetter__(e,i.set)):t[e]=i.value,t},g=function(t,e,i){return delete t[e],f(t,e,i)};return i(function(){},{inject:function(t){if(t){var e=this.prototype,n=Object.getPrototypeOf(e).constructor,r=t.statics===!0?t:t.statics;r!=t&&i(e,t,t.enumerable,n&&n.prototype,t.preserve,t.generics&&this),i(this,r,!0,n,t.preserve)}for(var s=1,a=arguments.length;a>s;s++)this.inject(arguments[s]);return this},extend:function(){for(var t,e=this,n=0,r=arguments.length;r>n&&!(t=arguments[n].initialize);n++);return t=t||function(){e.apply(this,arguments)},t.prototype=d(this.prototype),g(t.prototype,"constructor",{value:t,writable:!0,configurable:!0}),i(t,this,!0),arguments.length?this.inject.apply(t,arguments):t}},!0).inject({inject:function(){for(var t=0,e=arguments.length;e>t;t++)i(this,arguments[t],arguments[t].enumerable);return this},extend:function(){var t=d(this);return t.inject.apply(t,arguments)},each:function(t,e){return n(this,t,e)},clone:function(){return r(this)},statics:{each:n,clone:r,create:d,define:g,describe:_,isPlainObject:function(t){var i=null!=t&&t.constructor;return i&&(i===Object||i===e||"Object"===i.name)},pick:function(){for(var e=0,i=arguments.length;i>e;e++)if(arguments[e]!==t)return arguments[e];return null},stop:{}}})};"undefined"!=typeof module&&(module.exports=e),e.inject({generics:!0,clone:function(){return new this.constructor(this)},toString:function(){return null!=this._id?(this._class||"Object")+(this._name?" '"+this._name+"'":" @"+this._id):"{ "+e.each(this,function(t,e){if(!/^_/.test(e)){var i=typeof t;this.push(e+": "+("number"===i?a.instance.number(t):"string"===i?"'"+t+"'":t))}},[]).join(", ")+" }"},exportJSON:function(t){return e.exportJSON(this,t)},toJSON:function(){return e.serialize(this)},_set:function(i,n){if(i&&e.isPlainObject(i)){var r=i._filtering||i;for(var s in r)if(s in this&&r.hasOwnProperty(s)&&(!n||!n[s])){var a=i[s];a!==t&&(this[s]=a)}return!0}},statics:{exports:{},extend:function ie(){var t=ie.base.apply(this,arguments),i=t.prototype._class;return i&&!e.exports[i]&&(e.exports[i]=t),t},equals:function(t,i){function n(t,e){for(var i in t)if(t.hasOwnProperty(i)&&!e.hasOwnProperty(i))return!1;return!0}if(t===i)return!0;if(t&&t.equals)return t.equals(i);if(i&&i.equals)return i.equals(t);if(Array.isArray(t)&&Array.isArray(i)){if(t.length!==i.length)return!1;for(var r=0,s=t.length;s>r;r++)if(!e.equals(t[r],i[r]))return!1;return!0}if(t&&"object"==typeof t&&i&&"object"==typeof i){if(!n(t,i)||!n(i,t))return!1;for(var r in t)if(t.hasOwnProperty(r)&&!e.equals(t[r],i[r]))return!1;return!0}return!1},read:function(t,i,n,r){if(this===e){var s=this.peek(t,i);return t._index++,t.__read=1,s}var a=this.prototype,o=a._readIndex,h=i||o&&t._index||0;n||(n=t.length-h);var u=t[h];return u instanceof this||r&&r.readNull&&null==u&&1>=n?(o&&(t._index=h+1),u&&r&&r.clone?u.clone():u):(u=e.create(this.prototype),o&&(u.__read=!0),r&&(u.__options=r),u=u.initialize.apply(u,h>0||ns;s++)r.push(Array.isArray(n=t[s])?this.read(n,0,0,i):this.read(t,s,1,i));return r},readNamed:function(i,n,r,s,a){var o=this.getNamed(i,n),h=o!==t;if(h){var u=i._filtered;u||(u=i._filtered=e.create(i[0]),u._filtering=i[0]),u[n]=t}return this.read(h?[o]:i,r,s,a)},getNamed:function(i,n){var r=i[0];return i._hasObject===t&&(i._hasObject=1===i.length&&e.isPlainObject(r)),i._hasObject?n?r[n]:i._filtered||r:t},hasNamed:function(t,e){return!!this.getNamed(t,e)},isPlainValue:function(t){return this.isPlainObject(t)||Array.isArray(t)},serialize:function(t,i,n,r){i=i||{};var s,o=!r;if(o&&(i.formatter=new a(i.precision),r={length:0,definitions:{},references:{},add:function(t,e){var i="#"+t._id,n=this.references[i];if(!n){this.length++;var r=e.call(t),s=t._class;s&&r[0]!==s&&r.unshift(s),this.definitions[i]=r,n=this.references[i]=[i]}return n}}),t&&t._serialize){s=t._serialize(i,r);var h=t._class;!h||n||s._compact||s[0]===h||s.unshift(h)}else if(Array.isArray(t)){s=[];for(var u=0,l=t.length;l>u;u++)s[u]=e.serialize(t[u],i,n,r);n&&(s._compact=!0)}else if(e.isPlainObject(t)){s={};for(var u in t)t.hasOwnProperty(u)&&(s[u]=e.serialize(t[u],i,n,r))}else s="number"==typeof t?i.formatter.number(t,i.precision):t;return o&&r.length>0?[["dictionary",r.definitions],s]:s},deserialize:function(t,i,n){var r=t;if(n=n||{},Array.isArray(t)){var s=t[0],a="dictionary"===s;if(!a){if(n.dictionary&&1==t.length&&/^#/.test(s))return n.dictionary[s];s=e.exports[s]}r=[];for(var o=s?1:0,h=t.length;h>o;o++)r.push(e.deserialize(t[o],null,n));if(a)n.dictionary=r[0];else if(s){var u=r;r=i instanceof s?i:e.create(s.prototype),s.apply(r,u)}}else if(e.isPlainObject(t)){r={};for(var l in t)r[l]=e.deserialize(t[l],null,n)}return r},exportJSON:function(t,i){return JSON.stringify(e.serialize(t,i))},importJSON:function(t,i){return e.deserialize("string"==typeof t?JSON.parse(t):t,i)},splice:function(e,i,n,r){var s=i&&i.length,a=n===t;n=a?e.length:n,n>e.length&&(n=e.length);for(var o=0;s>o;o++)i[o]._index=n+o;if(a)return e.push.apply(e,i),[];var h=[n,r];i&&h.push.apply(h,i);for(var u=e.splice.apply(e,h),o=0,l=u.length;l>o;o++)delete u[o]._index;for(var o=n+s,l=e.length;l>o;o++)e[o]._index=o;return u},merge:function(){return e.each(arguments,function(t){e.each(t,function(t,e){this[e]=t},this)},new e,!0)},capitalize:function(t){return t.replace(/\b[a-z]/g,function(t){return t.toUpperCase()})},camelize:function(t){return t.replace(/-(.)/g,function(t,e){return e.toUpperCase()})},hyphenate:function(t){return t.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}}});var n={attach:function(i,n){if("string"!=typeof i)return e.each(i,function(t,e){this.attach(e,t)},this),t;var r=this._eventTypes[i];if(r){var s=this._handlers=this._handlers||{};s=s[i]=s[i]||[],-1==s.indexOf(n)&&(s.push(n),r.install&&1==s.length&&r.install.call(this,i))}},detach:function(i,n){if("string"!=typeof i)return e.each(i,function(t,e){this.detach(e,t)},this),t;var r,s=this._eventTypes[i],a=this._handlers&&this._handlers[i];s&&a&&(!n||-1!=(r=a.indexOf(n))&&1==a.length?(s.uninstall&&s.uninstall.call(this,i),delete this._handlers[i]):-1!=r&&a.splice(r,1))},once:function(t,e){this.attach(t,function(){e.apply(this,arguments),this.detach(t,e)})},fire:function(t,i){var n=this._handlers&&this._handlers[t];if(!n)return!1;var r=[].slice.call(arguments,1);return e.each(n,function(t){t.apply(this,r)===!1&&i&&i.stop&&i.stop()},this),!0},responds:function(t){return!(!this._handlers||!this._handlers[t])},on:"#attach",off:"#detach",trigger:"#fire",statics:{inject:function ne(){for(var t=0,i=arguments.length;i>t;t++){var n=arguments[t],r=n._events;if(r){var s={};e.each(r,function(t,i){var r="string"==typeof t,a=r?t:i,o=e.capitalize(a),h=a.substring(2).toLowerCase();s[h]=r?{}:t,a="_"+a,n["get"+o]=function(){return this[a]},n["set"+o]=function(t){t?this.attach(h,t):this[a]&&this.detach(h,this[a]),this[a]=t}}),n._eventTypes=s}ne.base.call(this,n)}return this}}},r=e.extend({_class:"PaperScope",initialize:function re(t){if(paper=this,this.project=null,this.projects=[],this.tools=[],this.palettes=[],this._id=t&&(t.getAttribute("id")||t.src)||"paperscope-"+re._id++,t&&t.setAttribute("id",this._id),re._scopes[this._id]=this,!this.support){var e=K.getContext(1,1);re.prototype.support={nativeDash:"setLineDash"in e||"mozDash"in e,nativeBlendModes:Q.nativeModes},K.release(e)}},version:"0.9.11",getView:function(){return this.project&&this.project.view},getTool:function(){return this._tool||(this._tool=new U),this._tool},getPaper:function(){return this},evaluate:function(t){var e=paper.PaperScript.evaluate(t,this);return Z.updateFocus(),e},install:function(t){var i=this;e.each(["project","view","tool"],function(n){e.define(t,n,{configurable:!0,get:function(){return i[n]}})});for(var n in this)/^(version|_id)/.test(n)||(t[n]=this[n])},setup:function(t){return paper=this,this.project=new m(t),this},activate:function(){paper=this},clear:function(){for(var t=this.projects.length-1;t>=0;t--)this.projects[t].remove();for(var t=this.tools.length-1;t>=0;t--)this.tools[t].remove();for(var t=this.palettes.length-1;t>=0;t--)this.palettes[t].remove()},remove:function(){this.clear(),delete r._scopes[this._id]},statics:new function(){function t(t){return t+="Attribute",function(e,i){return e[t](i)||e[t]("data-paper-"+i)}}return{_scopes:{},_id:0,get:function(t){return"object"==typeof t&&(t=t.getAttribute("id")),this._scopes[t]||null},getAttribute:t("get"),hasAttribute:t("has")}}}),s=e.extend(n,{initialize:function(t){this._scope=paper,this._index=this._scope[this._list].push(this)-1,(t||!this._scope[this._reference])&&this.activate()},activate:function(){if(!this._scope)return!1;var t=this._scope[this._reference];return t&&t!=this&&t.fire("deactivate"),this._scope[this._reference]=this,this.fire("activate",t),!0},isActive:function(){return this._scope[this._reference]===this},remove:function(){return null==this._index?!1:(e.splice(this._scope[this._list],null,this._index,1),this._scope[this._reference]==this&&(this._scope[this._reference]=null),this._scope=null,!0)}}),a=e.extend({initialize:function(t){this.precision=t||5,this.multiplier=Math.pow(10,this.precision)},number:function(t){return Math.round(t*this.multiplier)/this.multiplier},point:function(t,e){return this.number(t.x)+(e||",")+this.number(t.y)},size:function(t,e){return this.number(t.width)+(e||",")+this.number(t.height)},rectangle:function(t,e){return this.point(t,e)+(e||",")+this.size(t,e)}});a.instance=new a;var o=new function(){var e=[[.5773502691896257],[0,.7745966692414834],[.33998104358485626,.8611363115940526],[0,.5384693101056831,.906179845938664],[.2386191860831969,.6612093864662645,.932469514203152],[0,.4058451513773972,.7415311855993945,.9491079123427585],[.1834346424956498,.525532409916329,.7966664774136267,.9602898564975363],[0,.3242534234038089,.6133714327005904,.8360311073266358,.9681602395076261],[.14887433898163122,.4333953941292472,.6794095682990244,.8650633666889845,.9739065285171717],[0,.26954315595234496,.5190961292068118,.7301520055740494,.8870625997680953,.978228658146057],[.1252334085114689,.3678314989981802,.5873179542866175,.7699026741943047,.9041172563704749,.9815606342467192],[0,.2304583159551348,.44849275103644687,.6423493394403402,.8015780907333099,.9175983992229779,.9841830547185881],[.10805494870734367,.31911236892788974,.5152486363581541,.6872929048116855,.827201315069765,.9284348836635735,.9862838086968123],[0,.20119409399743451,.3941513470775634,.5709721726085388,.7244177313601701,.8482065834104272,.937273392400706,.9879925180204854],[.09501250983763744,.2816035507792589,.45801677765722737,.6178762444026438,.755404408355003,.8656312023878318,.9445750230732326,.9894009349916499]],i=[[1],[.8888888888888888,.5555555555555556],[.6521451548625461,.34785484513745385],[.5688888888888889,.47862867049936647,.23692688505618908],[.46791393457269104,.3607615730481386,.17132449237917036],[.4179591836734694,.3818300505051189,.27970539148927664,.1294849661688697],[.362683783378362,.31370664587788727,.22238103445337448,.10122853629037626],[.3302393550012598,.31234707704000286,.26061069640293544,.1806481606948574,.08127438836157441],[.29552422471475287,.26926671930999635,.21908636251598204,.1494513491505806,.06667134430868814],[.2729250867779006,.26280454451024665,.23319376459199048,.18629021092773426,.1255803694649046,.05566856711617366],[.24914704581340277,.2334925365383548,.20316742672306592,.16007832854334622,.10693932599531843,.04717533638651183],[.2325515532308739,.22628318026289723,.2078160475368885,.17814598076194574,.13887351021978725,.09212149983772845,.04048400476531588],[.2152638534631578,.2051984637212956,.18553839747793782,.15720316715819355,.12151857068790319,.08015808715976021,.03511946033175186],[.2025782419255613,.19843148532711158,.1861610000155622,.16626920581699392,.13957067792615432,.10715922046717194,.07036604748810812,.03075324199611727],[.1894506104550685,.18260341504492358,.16915651939500254,.14959598881657674,.12462897125553388,.09515851168249279,.062253523938647894,.027152459411754096]],n=Math.abs,r=Math.sqrt,s=Math.pow,a=Math.cos,h=Math.PI;return{TOLERANCE:1e-5,EPSILON:1e-11,KAPPA:4*(r(2)-1)/3,isZero:function(t){return n(t)<=o.EPSILON},integrate:function(t,n,r,s){for(var a=e[s-2],o=i[s-2],h=.5*(r-n),u=h+n,l=0,c=s+1>>1,d=1&s?o[l++]*t(u):0;c>l;){var _=h*a[l];d+=o[l++]*(t(u+_)+t(u-_))}return h*d},findRoot:function(t,e,i,r,s,a,o){for(var h=0;a>h;h++){var u=t(i),l=u/e(i);if(n(l)0?(s=i,i=r>=c?.5*(r+s):c):(r=i,i=c>=s?.5*(r+s):c)}},solveQuadratic:function(e,i,s,a,o,h){function u(t){return(l||t>=o&&h>=t)&&(a[c++]=t),c}var l=o===t,c=0,d=this.EPSILON;if(n(e)=d?u(-s/i):n(s)g)return 0;var v=g>f?r(g-f):0;return u(v-_),v>0&&u(-v-_),c},solveCubic:function(e,i,u,l,c,d,_){function f(t){return(v||t>=d&&_>=t)&&(c[m++]=t),m}var g=this.EPSILON;if(n(e)0?1:-1;return f(2*-S*C-i),f(S*C-i)}if(0>b){var C=r(y),P=Math.acos(w/(C*C*C))/3,z=-2*C,M=2*h/3;return f(z*a(P)-i),f(z*a(P+M)-i),f(z*a(P-M)-i)}var I=(w>0?-1:1)*s(n(w)+r(b),1/3);return f(I+y/I-i)}}},h=e.extend({_class:"Point",_readIndex:!0,initialize:function(t,e){var i=typeof t;if("number"===i){var n="number"==typeof e;this.x=t,this.y=n?e:t,this.__read&&(this.__read=n?2:1)}else"undefined"===i||null===t?(this.x=this.y=0,this.__read&&(this.__read=null===t?1:0)):(Array.isArray(t)?(this.x=t[0],this.y=t.length>1?t[1]:t[0]):null!=t.x?(this.x=t.x,this.y=t.y):null!=t.width?(this.x=t.width,this.y=t.height):null!=t.angle?(this.x=t.length,this.y=0,this.setAngle(t.angle)):(this.x=this.y=0,this.__read&&(this.__read=0)),this.__read&&(this.__read=1))},set:function(t,e){return this.x=t,this.y=e,this},equals:function(t){return t===this||t&&(this.x===t.x&&this.y===t.y||Array.isArray(t)&&this.x===t[0]&&this.y===t[1])||!1},clone:function(){return new h(this.x,this.y)},toString:function(){var t=a.instance;return"{ x: "+t.number(this.x)+", y: "+t.number(this.y)+" }"},_serialize:function(t){var e=t.formatter;return[e.number(this.x),e.number(this.y)]},add:function(t){return t=h.read(arguments),new h(this.x+t.x,this.y+t.y)},subtract:function(t){return t=h.read(arguments),new h(this.x-t.x,this.y-t.y)},multiply:function(t){return t=h.read(arguments),new h(this.x*t.x,this.y*t.y)},divide:function(t){return t=h.read(arguments),new h(this.x/t.x,this.y/t.y)},modulo:function(t){return t=h.read(arguments),new h(this.x%t.x,this.y%t.y)},negate:function(){return new h(-this.x,-this.y)},transform:function(t){return t?t._transformPoint(this):this},getDistance:function(t,e){t=h.read(arguments);var i=t.x-this.x,n=t.y-this.y,r=i*i+n*n;return e?r:Math.sqrt(r)},getLength:function(){var t=this.x*this.x+this.y*this.y;return arguments.length&&arguments[0]?t:Math.sqrt(t)},setLength:function(t){if(this.isZero()){var e=this._angle||0;this.set(Math.cos(e)*t,Math.sin(e)*t)}else{var i=t/this.getLength();o.isZero(i)&&this.getAngle(),this.set(this.x*i,this.y*i)}return this},normalize:function(e){e===t&&(e=1);var i=this.getLength(),n=0!==i?e/i:0,r=new h(this.x*n,this.y*n);return r._angle=this._angle,r},getAngle:function(){return 180*this.getAngleInRadians(arguments[0])/Math.PI},setAngle:function(t){if(t=this._angle=t*Math.PI/180,!this.isZero()){var e=this.getLength();this.set(Math.cos(t)*e,Math.sin(t)*e)}return this},getAngleInRadians:function(){if(arguments[0]===t)return null==this._angle&&(this._angle=Math.atan2(this.y,this.x)),this._angle;var e=h.read(arguments),i=this.getLength()*e.getLength();return o.isZero(i)?0/0:Math.acos(this.dot(e)/i)},getAngleInDegrees:function(){return this.getAngle(arguments[0])},getQuadrant:function(){return this.x>=0?this.y>=0?1:4:this.y>=0?2:3},getDirectedAngle:function(t){return t=h.read(arguments),180*Math.atan2(this.cross(t),this.dot(t))/Math.PI},rotate:function(t,e){if(0===t)return this.clone();t=t*Math.PI/180;var i=e?this.subtract(e):this,n=Math.sin(t),r=Math.cos(t);return i=new h(i.x*r-i.y*n,i.y*r+i.x*n),e?i.add(e):i},isInside:function(t){return t.contains(this)},isClose:function(t,e){return this.getDistance(t)1?t[1]:t[0]):null!=t.width?(this.width=t.width,this.height=t.height):null!=t.x?(this.width=t.x,this.height=t.y):(this.width=this.height=0,this.__read&&(this.__read=0)),this.__read&&(this.__read=1))},set:function(t,e){return this.width=t,this.height=e,this},equals:function(t){return t===this||t&&(this.width===t.width&&this.height===t.height||Array.isArray(t)&&this.width===t[0]&&this.height===t[1])||!1},clone:function(){return new c(this.width,this.height)},toString:function(){var t=a.instance;return"{ width: "+t.number(this.width)+", height: "+t.number(this.height)+" }"},_serialize:function(t){var e=t.formatter;return[e.number(this.width),e.number(this.height)]},add:function(t){return t=c.read(arguments),new c(this.width+t.width,this.height+t.height)},subtract:function(t){return t=c.read(arguments),new c(this.width-t.width,this.height-t.height)},multiply:function(t){return t=c.read(arguments),new c(this.width*t.width,this.height*t.height)},divide:function(t){return t=c.read(arguments),new c(this.width/t.width,this.height/t.height)},modulo:function(t){return t=c.read(arguments),new c(this.width%t.width,this.height%t.height)},negate:function(){return new c(-this.width,-this.height)},isZero:function(){return o.isZero(this.width)&&o.isZero(this.height)},isNaN:function(){return isNaN(this.width)||isNaN(this.height)},statics:{min:function(t,e){return new c(Math.min(t.width,e.width),Math.min(t.height,e.height))},max:function(t,e){return new c(Math.max(t.width,e.width),Math.max(t.height,e.height))},random:function(){return new c(Math.random(),Math.random())}}},e.each(["round","ceil","floor","abs"],function(t){var e=Math[t];this[t]=function(){return new c(e(this.width),e(this.height))}},{})),d=c.extend({initialize:function(t,e,i,n){this._width=t,this._height=e,this._owner=i,this._setter=n},set:function(t,e,i){return this._width=t,this._height=e,i||this._owner[this._setter](this),this},getWidth:function(){return this._width},setWidth:function(t){this._width=t,this._owner[this._setter](this)},getHeight:function(){return this._height},setHeight:function(t){this._height=t,this._owner[this._setter](this)}}),_=e.extend({_class:"Rectangle",_readIndex:!0,initialize:function(i,n,r,s){var a=typeof i,o=0;if("number"===a?(this.x=i,this.y=n,this.width=r,this.height=s,o=4):"undefined"===a||null===i?(this.x=this.y=this.width=this.height=0,o=null===i?1:0):1===arguments.length&&(Array.isArray(i)?(this.x=i[0],this.y=i[1],this.width=i[2],this.height=i[3],o=1):i.x!==t||i.width!==t?(this.x=i.x||0,this.y=i.y||0,this.width=i.width||0,this.height=i.height||0,o=1):i.from===t&&i.to===t&&(this.x=this.y=this.width=this.height=0,this._set(i),o=1)),!o){var u=h.readNamed(arguments,"from"),l=e.peek(arguments);if(this.x=u.x,this.y=u.y,l&&l.x!==t||e.hasNamed(arguments,"to")){var d=h.readNamed(arguments,"to");this.width=d.x-u.x,this.height=d.y-u.y,this.width<0&&(this.x=d.x,this.width=-this.width),this.height<0&&(this.y=d.y,this.height=-this.height)}else{var _=c.read(arguments);this.width=_.width,this.height=_.height}o=arguments._index}this.__read&&(this.__read=o)},set:function(t,e,i,n){return this.x=t,this.y=e,this.width=i,this.height=n,this},clone:function(){return new _(this.x,this.y,this.width,this.height)},equals:function(t){return e.isPlainValue(t)&&(t=_.read(arguments)),t===this||t&&this.x===t.x&&this.y===t.y&&this.width===t.width&&this.height===t.height||!1},toString:function(){var t=a.instance;return"{ x: "+t.number(this.x)+", y: "+t.number(this.y)+", width: "+t.number(this.width)+", height: "+t.number(this.height)+" }"},_serialize:function(t){var e=t.formatter;return[e.number(this.x),e.number(this.y),e.number(this.width),e.number(this.height)]},getPoint:function(){return new(arguments[0]?h:u)(this.x,this.y,this,"setPoint")},setPoint:function(t){t=h.read(arguments),this.x=t.x,this.y=t.y},getSize:function(){return new(arguments[0]?c:d)(this.width,this.height,this,"setSize")},setSize:function(t){t=c.read(arguments),this._fixX&&(this.x+=(this.width-t.width)*this._fixX),this._fixY&&(this.y+=(this.height-t.height)*this._fixY),this.width=t.width,this.height=t.height,this._fixW=1,this._fixH=1},getLeft:function(){return this.x},setLeft:function(t){this._fixW||(this.width-=t-this.x),this.x=t,this._fixX=0},getTop:function(){return this.y},setTop:function(t){this._fixH||(this.height-=t-this.y),this.y=t,this._fixY=0},getRight:function(){return this.x+this.width},setRight:function(e){this._fixX!==t&&1!==this._fixX&&(this._fixW=0),this._fixW?this.x=e-this.width:this.width=e-this.x,this._fixX=1},getBottom:function(){return this.y+this.height},setBottom:function(e){this._fixY!==t&&1!==this._fixY&&(this._fixH=0),this._fixH?this.y=e-this.height:this.height=e-this.y,this._fixY=1},getCenterX:function(){return this.x+.5*this.width},setCenterX:function(t){this.x=t-.5*this.width,this._fixX=.5},getCenterY:function(){return this.y+.5*this.height},setCenterY:function(t){this.y=t-.5*this.height,this._fixY=.5},getCenter:function(){return new(arguments[0]?h:u)(this.getCenterX(),this.getCenterY(),this,"setCenter")},setCenter:function(t){return t=h.read(arguments),this.setCenterX(t.x),this.setCenterY(t.y),this},isEmpty:function(){return 0==this.width||0==this.height},contains:function(e){return e&&e.width!==t||4==(Array.isArray(e)?e:arguments).length?this._containsRectangle(_.read(arguments)):this._containsPoint(h.read(arguments))},_containsPoint:function(t){var e=t.x,i=t.y;return e>=this.x&&i>=this.y&&e<=this.x+this.width&&i<=this.y+this.height},_containsRectangle:function(t){var e=t.x,i=t.y;return e>=this.x&&i>=this.y&&e+t.width<=this.x+this.width&&i+t.height<=this.y+this.height},intersects:function(t){return t=_.read(arguments),t.x+t.width>this.x&&t.y+t.height>this.y&&t.x=this.x&&t.y+t.height>=this.y&&t.x<=this.x+this.width&&t.y<=this.y+this.height},intersect:function(t){t=_.read(arguments);var e=Math.max(this.x,t.x),i=Math.max(this.y,t.y),n=Math.min(this.x+this.width,t.x+t.width),r=Math.min(this.y+this.height,t.y+t.height);return new _(e,i,n-e,r-i)},unite:function(t){t=_.read(arguments);var e=Math.min(this.x,t.x),i=Math.min(this.y,t.y),n=Math.max(this.x+this.width,t.x+t.width),r=Math.max(this.y+this.height,t.y+t.height);return new _(e,i,n-e,r-i)},include:function(t){t=h.read(arguments);var e=Math.min(this.x,t.x),i=Math.min(this.y,t.y),n=Math.max(this.x+this.width,t.x),r=Math.max(this.y+this.height,t.y);return new _(e,i,n-e,r-i)},expand:function(e,i){return i===t&&(i=e),new _(this.x-e/2,this.y-i/2,this.width+e,this.height+i)},scale:function(e,i){return this.expand(this.width*e-this.width,this.height*(i===t?e:i)-this.height)}},new function(){return e.each([["Top","Left"],["Top","Right"],["Bottom","Left"],["Bottom","Right"],["Left","Center"],["Top","Center"],["Right","Center"],["Bottom","Center"]],function(t,e){var i=t.join(""),n=/^[RL]/.test(i);e>=4&&(t[1]+=n?"Y":"X");var r=t[n?0:1],s=t[n?1:0],a="get"+r,o="get"+s,l="set"+r,c="set"+s,d="get"+i,_="set"+i;this[d]=function(){return new(arguments[0]?h:u)(this[a](),this[o](),this,_)},this[_]=function(t){t=h.read(arguments),this[l](t.x),this[c](t.y)}},{})}),f=_.extend({initialize:function(t,e,i,n,r,s){this.set(t,e,i,n,!0),this._owner=r,this._setter=s},set:function(t,e,i,n,r){return this._x=t,this._y=e,this._width=i,this._height=n,r||this._owner[this._setter](this),this}},new function(){var t=_.prototype;return e.each(["x","y","width","height"],function(t){var i=e.capitalize(t),n="_"+t;this["get"+i]=function(){return this[n]},this["set"+i]=function(t){this[n]=t,this._dontNotify||this._owner[this._setter](this)}},e.each(["Point","Size","Center","Left","Top","Right","Bottom","CenterX","CenterY","TopLeft","TopRight","BottomLeft","BottomRight","LeftCenter","TopCenter","RightCenter","BottomCenter"],function(e){var i="set"+e;this[i]=function(){this._dontNotify=!0,t[i].apply(this,arguments),delete this._dontNotify,this._owner[this._setter](this)}},{isSelected:function(){return this._owner._boundsSelected},setSelected:function(t){var e=this._owner;e.setSelected&&(e._boundsSelected=t,e.setSelected(t||e._selectedSegmentState>0))}}))}),g=e.extend({_class:"Matrix",initialize:function se(t){var e=arguments.length,i=!0;if(6===e?this.set.apply(this,arguments):1===e?t instanceof se?this.set(t._a,t._c,t._b,t._d,t._tx,t._ty):Array.isArray(t)?this.set.apply(this,t):i=!1:0===e?this.reset():i=!1,!i)throw Error("Unsupported matrix parameters")},set:function(t,e,i,n,r,s){return this._a=t,this._c=e,this._b=i,this._d=n,this._tx=r,this._ty=s,this},_serialize:function(t){return e.serialize(this.getValues(),t)},clone:function(){return new g(this._a,this._c,this._b,this._d,this._tx,this._ty)},equals:function(t){return t===this||t&&this._a===t._a&&this._b===t._b&&this._c===t._c&&this._d===t._d&&this._tx===t._tx&&this._ty===t._ty||!1},toString:function(){var t=a.instance;return"[["+[t.number(this._a),t.number(this._b),t.number(this._tx)].join(", ")+"], ["+[t.number(this._c),t.number(this._d),t.number(this._ty)].join(", ")+"]]"},reset:function(){return this._a=this._d=1,this._c=this._b=this._tx=this._ty=0,this},scale:function(){var t=h.read(arguments),e=h.read(arguments,0,0,{readNull:!0});return e&&this.translate(e),this._a*=t.x,this._c*=t.x,this._b*=t.y,this._d*=t.y,e&&this.translate(e.negate()),this},translate:function(t){t=h.read(arguments);var e=t.x,i=t.y;return this._tx+=e*this._a+i*this._b,this._ty+=e*this._c+i*this._d,this},rotate:function(t,e){e=h.read(arguments,1),t=t*Math.PI/180;var i=e.x,n=e.y,r=Math.cos(t),s=Math.sin(t),a=i-i*r+n*s,o=n-i*s-n*r,u=this._a,l=this._b,c=this._c,d=this._d;return this._a=r*u+s*l,this._b=-s*u+r*l,this._c=r*c+s*d,this._d=-s*c+r*d,this._tx+=a*u+o*l,this._ty+=a*c+o*d,this},shear:function(){var t=h.read(arguments),e=h.read(arguments,0,0,{readNull:!0});e&&this.translate(e);var i=this._a,n=this._c;return this._a+=t.y*this._b,this._c+=t.y*this._d,this._b+=t.x*i,this._d+=t.x*n,e&&this.translate(e.negate()),this},concatenate:function(t){var e=this._a,i=this._b,n=this._c,r=this._d;return this._a=t._a*e+t._c*i,this._b=t._b*e+t._d*i,this._c=t._a*n+t._c*r,this._d=t._b*n+t._d*r,this._tx+=t._tx*e+t._ty*i,this._ty+=t._tx*n+t._ty*r,this},preConcatenate:function(t){var e=this._a,i=this._b,n=this._c,r=this._d,s=this._tx,a=this._ty;return this._a=t._a*e+t._b*n,this._b=t._a*i+t._b*r,this._c=t._c*e+t._d*n,this._d=t._c*i+t._d*r,this._tx=t._a*s+t._b*a+t._tx,this._ty=t._c*s+t._d*a+t._ty,this},isIdentity:function(){return 1==this._a&&0==this._c&&0==this._b&&1==this._d&&0==this._tx&&0==this._ty},isInvertible:function(){return!!this._getDeterminant()},isSingular:function(){return!this._getDeterminant()},transform:function(t,e,i,n,r){return arguments.length<5?this._transformPoint(h.read(arguments)):this._transformCoordinates(t,e,i,n,r)},_transformPoint:function(t,e,i){var n=t.x,r=t.y;return e||(e=new h),e.set(n*this._a+r*this._b+this._tx,n*this._c+r*this._d+this._ty,i)},_transformCoordinates:function(t,e,i,n,r){for(var s=e,a=n,o=s+2*r;o>s;){var h=t[s++],u=t[s++];i[a++]=h*this._a+u*this._b+this._tx,i[a++]=h*this._c+u*this._d+this._ty}return i},_transformCorners:function(t){var e=t.x,i=t.y,n=e+t.width,r=i+t.height,s=[e,i,n,i,n,r,e,r];return this._transformCoordinates(s,0,s,0,4)},_transformBounds:function(t,e,i){for(var n=this._transformCorners(t),r=n.slice(0,2),s=n.slice(),a=2;8>a;a++){var o=n[a],h=1&a;os[h]&&(s[h]=o)}return e||(e=new _),e.set(r[0],r[1],s[0]-r[0],s[1]-r[1],i)},inverseTransform:function(){return this._inverseTransform(h.read(arguments))},_getDeterminant:function(){var t=this._a*this._d-this._b*this._c;return isFinite(t)&&!o.isZero(t)&&isFinite(this._tx)&&isFinite(this._ty)?t:null},_inverseTransform:function(t,e,i){var n=this._getDeterminant();if(!n)return null;var r=t.x-this._tx,s=t.y-this._ty;return e||(e=new h),e.set((r*this._d-s*this._b)/n,(s*this._a-r*this._c)/n,i)},decompose:function(){var t=this._a,e=this._b,i=this._c,n=this._d;if(o.isZero(t*n-e*i))return null;var r=Math.sqrt(t*t+e*e);t/=r,e/=r;var s=t*i+e*n;i-=t*s,n-=e*s;var a=Math.sqrt(i*i+n*n);return i/=a,n/=a,s/=a,e*i>t*n&&(t=-t,e=-e,s=-s,r=-r),{translation:this.getTranslation(),scaling:new h(r,a),rotation:180*-Math.atan2(e,t)/Math.PI,shearing:s} +},getValues:function(){return[this._a,this._c,this._b,this._d,this._tx,this._ty]},getTranslation:function(){return new h(this._tx,this._ty)},getScaling:function(){return(this.decompose()||{}).scaling},getRotation:function(){return(this.decompose()||{}).rotation},inverted:function(){var t=this._getDeterminant();return t&&new g(this._d/t,-this._c/t,-this._b/t,this._a/t,(this._b*this._ty-this._d*this._tx)/t,(this._c*this._tx-this._a*this._ty)/t)},shiftless:function(){return new g(this._a,this._c,this._b,this._d,0,0)},applyToContext:function(t){t.transform(this._a,this._c,this._b,this._d,this._tx,this._ty)}},new function(){return e.each({scaleX:"_a",scaleY:"_d",translateX:"_tx",translateY:"_ty",shearX:"_b",shearY:"_c"},function(t,i){i=e.capitalize(i),this["get"+i]=function(){return this[t]},this["set"+i]=function(e){this[t]=e}},{})}),v=e.extend({_class:"Line",initialize:function(t,e,i,n,r){var s=!1;arguments.length>=4?(this._px=t,this._py=e,this._vx=i,this._vy=n,s=r):(this._px=t.x,this._py=t.y,this._vx=e.x,this._vy=e.y,s=i),s||(this._vx-=this._px,this._vy-=this._py)},getPoint:function(){return new h(this._px,this._py)},getVector:function(){return new h(this._vx,this._vy)},getLength:function(){return this.getVector().getLength()},intersect:function(t,e){return v.intersect(this._px,this._py,this._vx,this._vy,t._px,t._py,t._vx,t._vy,!0,e)},getSide:function(t){return v.getSide(this._px,this._py,this._vx,this._vy,t.x,t.y,!0)},getDistance:function(t){return Math.abs(v.getSignedDistance(this._px,this._py,this._vx,this._vy,t.x,t.y,!0))},statics:{intersect:function(t,e,i,n,r,s,a,u,l,c){l||(i-=t,n-=e,a-=r,u-=s);var d=u*i-a*n;if(!o.isZero(d)){var _=t-r,f=e-s,g=(a*f-u*_)/d,v=(i*f-n*_)/d;if((c||g>=0&&1>=g)&&(c||v>=0&&1>=v))return new h(t+g*i,e+g*n)}},getSide:function(t,e,i,n,r,s,a){a||(i-=t,n-=e);var o=r-t,h=s-e,u=o*n-h*i;return 0===u&&(u=o*i+h*n,u>0&&(o-=i,h-=n,u=o*i+h*n,0>u&&(u=0))),0>u?-1:u>0?1:0},getSignedDistance:function(t,e,i,n,r,s,a){a||(i-=t,n-=e);var o=n/i,h=e-o*t;return(s-o*r-h)/Math.sqrt(o*o+1)}}}),m=s.extend({_class:"Project",_list:"projects",_reference:"project",initialize:function(t){s.call(this,!0),this.layers=[],this.symbols=[],this._currentStyle=new E,this.activeLayer=new x,t&&(this.view=t instanceof Z?t:Z.create(t)),this._selectedItems={},this._selectedItemCount=0,this._drawCount=0,this.options={}},_serialize:function(t,i){return e.serialize(this.layers,t,!0,i)},clear:function(){for(var t=this.layers.length-1;t>=0;t--)this.layers[t].remove();this.symbols=[]},remove:function ae(){return ae.base.call(this)?(this.view&&this.view.remove(),!0):!1},getCurrentStyle:function(){return this._currentStyle},setCurrentStyle:function(t){this._currentStyle.initialize(t)},getIndex:function(){return this._index},getSelectedItems:function(){var t=[];for(var e in this._selectedItems){var i=this._selectedItems[e];i.isInserted()&&t.push(i)}return t},_updateSelection:function(t){var e=t._id,i=this._selectedItems;t._selected?i[e]!==t&&(this._selectedItemCount++,i[e]=t):i[e]===t&&(this._selectedItemCount--,delete i[e])},selectAll:function(){for(var t=this.layers,e=0,i=t.length;i>e;e++)t[e].setFullySelected(!0)},deselectAll:function(){var t=this._selectedItems;for(var e in t)t[e].setFullySelected(!1)},hitTest:function(t,i){t=h.read(arguments),i=P.getOptions(e.read(arguments));for(var n=this.layers.length-1;n>=0;n--){var r=this.layers[n].hitTest(t,i);if(r)return r}return null}},new function(){function t(t,e,i){for(var n=t.layers,r=i&&[],s=0,a=n.length;a>s;s++){var o=n[s][i?"getItems":"getItem"](e);if(i)r.push.apply(r,o);else if(o)return o}return i?r:null}return{getItems:function(e){return t(this,e,!0)},getItem:function(e){return t(this,e,!1)}}},{importJSON:function(t){return this.activate(),e.importJSON(t)},draw:function(t,i){this._drawCount++,t.save(),i.applyToContext(t);for(var n=e.merge({offset:new h(0,0),transforms:[i],trackTransforms:!0}),r=0,s=this.layers.length;s>r;r++)this.layers[r].draw(t,n);if(t.restore(),this._selectedItemCount>0){t.save(),t.strokeWidth=1;for(var a in this._selectedItems){var o=this._selectedItems[a];if(o._drawCount===this._drawCount&&(o._drawSelected||o._boundsSelected)){var u=o.getSelectedColor()||o.getLayer().getSelectedColor();t.strokeStyle=t.fillStyle=u?u.toCanvasStyle(t):"#009dec";var l=o._globalMatrix;if(o._drawSelected&&o._drawSelected(t,l),o._boundsSelected){var c=l._transformCorners(o._getBounds("getBounds"));t.beginPath();for(var r=0;8>r;r++)t[0===r?"moveTo":"lineTo"](c[r],c[++r]);t.closePath(),t.stroke();for(var r=0;8>r;r++)t.beginPath(),t.rect(c[r]-2,c[++r]-2,4,4),t.fill()}}}t.restore()}}}),p=e.extend({_class:"Symbol",initialize:function oe(t,e){this._id=oe._id=(oe._id||0)+1,this.project=paper.project,this.project.symbols.push(this),t&&this.setDefinition(t,e),this._instances={}},_serialize:function(t,i){return i.add(this,function(){return e.serialize([this._class,this._definition],t,!1,i)})},_changed:function(t){e.each(this._instances,function(e){e._changed(t)})},getDefinition:function(){return this._definition},setDefinition:function(t){t._parentSymbol&&(t=t.clone()),this._definition&&delete this._definition._parentSymbol,this._definition=t,t.remove(),t.setSelected(!1),arguments[1]||t.setPosition(new h),t._parentSymbol=this,this._changed(5)},place:function(t){return new S(this,t)},clone:function(){return new p(this._definition.clone(!1))}}),y=e.extend(n,{statics:{extend:function he(t){t._serializeFields&&(t._serializeFields=e.merge(this.prototype._serializeFields,t._serializeFields));var i=he.base.apply(this,arguments),n=i.prototype,r=n._class;return r&&(n._type=e.hyphenate(r)),i}},_class:"Item",_transformContent:!0,_boundsSelected:!1,_serializeFields:{name:null,matrix:new g,locked:!1,visible:!0,blendMode:"normal",opacity:1,guide:!1,selected:!1,clipMask:!1,data:{}},initialize:function(){},_initialize:function(t,e){if(this._id=y._id=(y._id||0)+1,!this._project){var i=paper.project,n=i.activeLayer;!n||t&&t.insert===!1?this._setProject(i):n.addChild(this)}return this._style=new E(this._project._currentStyle,this),this._matrix=new g,e&&this._matrix.translate(e),t?this._set(t,{insert:!0}):!0},_events:new function(){var t={mousedown:{mousedown:1,mousedrag:1,click:1,doubleclick:1},mouseup:{mouseup:1,mousedrag:1,click:1,doubleclick:1},mousemove:{mousedrag:1,mousemove:1,mouseenter:1,mouseleave:1}},i={install:function(e){var i=this._project.view._eventCounters;if(i)for(var n in t)i[n]=(i[n]||0)+(t[n][e]||0)},uninstall:function(e){var i=this._project.view._eventCounters;if(i)for(var n in t)i[n]-=t[n][e]||0}};return e.each(["onMouseDown","onMouseUp","onMouseDrag","onClick","onDoubleClick","onMouseMove","onMouseEnter","onMouseLeave"],function(t){this[t]=i},{onFrame:{install:function(){this._project.view._animateItem(this,!0)},uninstall:function(){this._project.view._animateItem(this,!1)}},onLoad:{}})},_serialize:function(t,i){function n(n){for(var a in n){var o=s[a];e.equals(o,"leading"===a?1.2*n.fontSize:n[a])||(r[a]=e.serialize(o,t,"data"!==a,i))}}var r={},s=this;return n(this._serializeFields),this instanceof w||n(this._style._defaults),[this._class,r]},_changed:function(t){var e=this._parent,i=this._project,n=this._parentSymbol;if(this._drawCount=null,4&t&&(delete this._bounds,delete this._position),e&&12&t&&e._clearBoundsCache(),2&t&&this._clearBoundsCache(),i&&(1&t&&(i._needsRedraw=!0),i._changes)){var r=i._changesById[this._id];r?r.flags|=t:(r={item:this,flags:t},i._changesById[this._id]=r,i._changes.push(r))}n&&n._changed(t)},set:function(t){return t&&this._set(t),this},getId:function(){return this._id},getType:function(){return this._type},getName:function(){return this._name},setName:function(e,i){if(this._name&&this._removeNamed(),e===+e+"")throw Error("Names consisting only of numbers are not supported.");if(e&&this._parent){for(var n=this._parent._children,r=this._parent._namedChildren,s=e,a=1;i&&n[e];)e=s+" "+a++;(r[e]=r[e]||[]).push(this),n[e]=this}this._name=e||t,this._changed(32)},getStyle:function(){return this._style},setStyle:function(t){this.getStyle().set(t)},hasFill:function(){return this.getStyle().hasFill()},hasStroke:function(){return this.getStyle().hasStroke()},hasShadow:function(){return this.getStyle().hasShadow()}},e.each(["locked","visible","blendMode","opacity","guide"],function(t){var i=e.capitalize(t),t="_"+t;this["get"+i]=function(){return this[t]},this["set"+i]=function(e){e!=this[t]&&(this[t]=e,this._changed("_locked"===t?32:33))}},{}),{_locked:!1,_visible:!0,_blendMode:"normal",_opacity:1,_guide:!1,isSelected:function(){if(this._children)for(var t=0,e=this._children.length;e>t;t++)if(this._children[t].isSelected())return!0;return this._selected},setSelected:function(t){if(this._children&&!arguments[1])for(var e=0,i=this._children.length;i>e;e++)this._children[e].setSelected(t);(t=!!t)!=this._selected&&(this._selected=t,this._project._updateSelection(this),this._changed(33))},_selected:!1,isFullySelected:function(){if(this._children&&this._selected){for(var t=0,e=this._children.length;e>t;t++)if(!this._children[t].isFullySelected())return!1;return!0}return this._selected},setFullySelected:function(t){if(this._children)for(var e=0,i=this._children.length;i>e;e++)this._children[e].setFullySelected(t);this.setSelected(t,!0)},isClipMask:function(){return this._clipMask},setClipMask:function(t){this._clipMask!=(t=!!t)&&(this._clipMask=t,t&&(this.setFillColor(null),this.setStrokeColor(null)),this._changed(33),this._parent&&this._parent._changed(256))},_clipMask:!1,getData:function(){return this._data||(this._data={}),this._data},setData:function(t){this._data=t},getPosition:function(){var t=this._position||(this._position=this.getBounds().getCenter(!0));return new(arguments[0]?h:u)(t.x,t.y,this,"setPosition")},setPosition:function(){this.translate(h.read(arguments).subtract(this.getPosition(!0)))},getMatrix:function(){return this._matrix},setMatrix:function(t){this._matrix.initialize(t),this._changed(5)},getGlobalMatrix:function(){return this._drawCount===this._project._drawCount&&this._globalMatrix||null},globalToLocal:function(){var t=this.getGlobalMatrix();return t&&t._transformPoint(h.read(arguments))},localToGlobal:function(){var t=this.getGlobalMatrix();return t&&t._inverseTransform(h.read(arguments))},isEmpty:function(){return!this._children||0==this._children.length}},e.each(["getBounds","getStrokeBounds","getHandleBounds","getRoughBounds"],function(t){this[t]=function(){var e=this._boundsGetter,i=this._getCachedBounds("string"==typeof e?e:e&&e[t]||t,arguments[0]);return"getBounds"===t?new f(i.x,i.y,i.width,i.height,this,"setBounds"):i}},{_getCachedBounds:function(t,e,i){var n=(!e||e.equals(this._matrix))&&t;if(i&&this._parent){var r=i._id,s=this._parent._boundsCache=this._parent._boundsCache||{ids:{},list:[]};s.ids[r]||(s.list.push(i),s.ids[r]=i)}if(n&&this._bounds&&this._bounds[n])return this._bounds[n].clone();var a=this._matrix.isIdentity();e=!e||e.isIdentity()?a?null:this._matrix:a?e:e.clone().concatenate(this._matrix);var o=this._getBounds(t,e,n?this:i);return n&&(this._bounds||(this._bounds={}),this._bounds[n]=o.clone()),o},_clearBoundsCache:function(){if(this._boundsCache){for(var t=0,e=this._boundsCache.list,i=e.length;i>t;t++){var n=e[t];delete n._bounds,n!=this&&n._boundsCache&&n._clearBoundsCache()}delete this._boundsCache}},_getBounds:function(t,e,i){var n=this._children;if(!n||0==n.length)return new _;for(var r=1/0,s=-r,a=r,o=s,h=0,u=n.length;u>h;h++){var l=n[h];if(l._visible&&!l.isEmpty()){var c=l._getCachedBounds(t,e,i);r=Math.min(c.x,r),a=Math.min(c.y,a),s=Math.max(c.x+c.width,s),o=Math.max(c.y+c.height,o)}}return isFinite(r)?new _(r,a,s-r,o-a):new _},setBounds:function(t){t=_.read(arguments);var e=this.getBounds(),i=new g,n=t.getCenter();i.translate(n),(t.width!=e.width||t.height!=e.height)&&i.scale(0!=e.width?t.width/e.width:1,0!=e.height?t.height/e.height:1),n=e.getCenter(),i.translate(-n.x,-n.y),this.transform(i)}}),{getProject:function(){return this._project},_setProject:function(t){if(this._project!=t&&(this._project=t,this._children))for(var e=0,i=this._children.length;i>e;e++)this._children[e]._setProject(t)},getLayer:function(){for(var t=this;t=t._parent;)if(t instanceof x)return t;return null},getParent:function(){return this._parent},setParent:function(t){return t.addChild(this)},getChildren:function(){return this._children},setChildren:function(t){this.removeChildren(),this.addChildren(t)},getFirstChild:function(){return this._children&&this._children[0]||null},getLastChild:function(){return this._children&&this._children[this._children.length-1]||null},getNextSibling:function(){return this._parent&&this._parent._children[this._index+1]||null},getPreviousSibling:function(){return this._parent&&this._parent._children[this._index-1]||null},getIndex:function(){return this._index},isInserted:function(){return this._parent?this._parent.isInserted():!1},equals:function(t){return t===this||t&&this._class===t._class&&this._style.equals(t._style)&&this._matrix.equals(t._matrix)&&this._locked===t._locked&&this._visible===t._visible&&this._blendMode===t._blendMode&&this._opacity===t._opacity&&this._clipMask===t._clipMask&&this._guide===t._guide&&this._equals(t)||!1},_equals:function(t){return e.equals(this._children,t._children)},clone:function(t){return this._clone(new this.constructor({insert:!1}),t)},_clone:function(e,i){if(e.setStyle(this._style),this._children)for(var n=0,r=this._children.length;r>n;n++)e.addChild(this._children[n].clone(!1),!0);(i||i===t)&&e.insertAbove(this);for(var s=["_locked","_visible","_blendMode","_opacity","_clipMask","_guide"],n=0,r=s.length;r>n;n++){var a=s[n];this.hasOwnProperty(a)&&(e[a]=this[a])}return e._matrix.initialize(this._matrix),e.setSelected(this._selected),this._name&&e.setName(this._name,!0),e},copyTo:function(t){var e=this.clone();return t.layers?t.activeLayer.addChild(e):t.addChild(e),e},rasterize:function(t){var i=this.getStrokeBounds(),n=(t||72)/72,r=i.getTopLeft().floor(),s=i.getBottomRight().ceil();size=new c(s.subtract(r)),canvas=K.getCanvas(size),ctx=canvas.getContext("2d"),matrix=(new g).scale(n).translate(r.negate()),ctx.save(),matrix.applyToContext(ctx),this.draw(ctx,e.merge({transforms:[matrix]})),ctx.restore();var a=new C({canvas:canvas,insert:!1});return a.setPosition(r.add(size.divide(2))),a.insertAbove(this),a},contains:function(){return!!this._contains(this._matrix._inverseTransform(h.read(arguments)))},_contains:function(t){if(this._children){for(var e=this._children.length-1;e>=0;e--)if(this._children[e].contains(t))return!0;return!1}return t.isInside(this._getBounds("getBounds"))},hitTest:function(i,n){function r(r,s){var h=o["get"+s]();return i.getDistance(h)l&&!s;l++)s=r("bounds",u[l])}return(s||(s=this._children||!(n.guides&&!this._guide||n.selected&&!this._selected)?this._hitTest(i,n):null))&&s.point&&(s.point=a._matrix.transform(s.point)),s},_hitTest:function(t,e){var i=this._children;if(i){for(var n,r=i.length-1;r>=0;r--)if(n=i[r].hitTest(t,e))return n}else if(e.fill&&this.hasFill()&&this._contains(t))return new P("fill",this)},matches:function(t){function i(t,n){for(var r in t)if(t.hasOwnProperty(r)){var s=t[r],a=n[r];if(e.isPlainObject(s)&&e.isPlainObject(a)){if(!i(s,a))return!1}else if(!e.equals(s,a))return!1}return!0}for(var n in t)if(t.hasOwnProperty(n)){var r=this[n],s=t[n];if(s instanceof RegExp){if(!s.test(r))return!1}else if("function"==typeof s){if(!s(r))return!1}else if(e.isPlainObject(s)){if(!i(s,r))return!1}else if(!e.equals(r,s))return!1}return!0}},new function(){function t(e,i,n){for(var r=e._children,s=n&&[],a=0,o=r&&r.length;o>a;a++){var h=r[a];if(h.matches(i)){if(!n)return h;s.push(h)}var u=t(h,i,n);if(n)s.push.apply(s,u);else if(u)return u}return n?s:null}return{getItems:function(e){return t(this,e,!0)},getItem:function(e){return t(this,e,!1)}}},{importJSON:function(t){var i=e.importJSON(t,this);return i!==this?this.addChild(i):i},addChild:function(e,i){return this.insertChild(t,e,i)},insertChild:function(t,e,i){var n=this.insertChildren(t,[e],i);return n&&n[0]},addChildren:function(t,e){return this.insertChildren(this._children.length,t,e)},insertChildren:function(t,i,n,r){var s=this._children;if(s&&i&&i.length>0){i=Array.prototype.slice.apply(i);for(var a=i.length-1;a>=0;a--){var o=i[a];r&&o._type!==r?i.splice(a,1):o._remove(!0)}e.splice(s,i,t,0);for(var a=0,h=i.length;h>a;a++){var o=i[a];o._parent=this,o._setProject(this._project),o._name&&o.setName(o._name)}this._changed(7)}else i=null;return i},_insert:function(t,e,i){if(!e._parent)return null;var n=e._index+(t?1:0);return e._parent===this._parent&&n>this._index&&n--,e._parent.insertChild(n,this,i)},insertAbove:function(t,e){return this._insert(!0,t,e)},insertBelow:function(t,e){return this._insert(!1,t,e)},sendToBack:function(){return this._parent.insertChild(0,this)},bringToFront:function(){return this._parent.addChild(this)},appendTop:"#addChild",appendBottom:function(t){return this.insertChild(0,t)},moveAbove:"#insertAbove",moveBelow:"#insertBelow",reduce:function(){if(this._children&&1===this._children.length){var t=this._children[0];return t.insertAbove(this),this.remove(),t}return this},_removeNamed:function(){var t=this._parent._children,e=this._parent._namedChildren,i=this._name,n=e[i],r=n?n.indexOf(this):-1;-1!=r&&(t[i]==this&&delete t[i],n.splice(r,1),n.length?t[i]=n[n.length-1]:delete e[i])},_remove:function(t){return this._parent?(this._name&&this._removeNamed(),null!=this._index&&e.splice(this._parent._children,null,this._index,1),t&&this._parent._changed(7),this._parent=null,!0):!1},remove:function(){return this._remove(!0)},removeChildren:function(t,i){if(!this._children)return null;t=t||0,i=e.pick(i,this._children.length);for(var n=e.splice(this._children,null,t,i-t),r=n.length-1;r>=0;r--)n[r]._remove(!1);return n.length>0&&this._changed(7),n},clear:"#removeChildren",reverseChildren:function(){if(this._children){this._children.reverse();for(var t=0,e=this._children.length;e>t;t++)this._children[t]._index=t;this._changed(7)}},isEditable:function(){for(var t=this;t;){if(!t._visible||t._locked)return!1;t=t._parent}return!0},_getOrder:function(t){function e(t){var e=[];do e.unshift(t);while(t=t._parent);return e}for(var i=e(this),n=e(t),r=0,s=Math.min(i.length,n.length);s>r;r++)if(i[r]!=n[r])return i[r]._index0},isAbove:function(t){return-1===this._getOrder(t)},isBelow:function(t){return 1===this._getOrder(t)},isParent:function(t){return this._parent===t},isChild:function(t){return t&&t._parent===this},isDescendant:function(t){for(var e=this;e=e._parent;)if(e==t)return!0;return!1},isAncestor:function(t){return t?t.isDescendant(this):!1},isGroupedWith:function(t){for(var e=this._parent;e;){if(e._parent&&/^(group|layer|compound-path)$/.test(e._type)&&t.isDescendant(e))return!0;e=e._parent}return!1},scale:function(t,e,i){return(arguments.length<2||"object"==typeof e)&&(i=e,e=t),this.transform((new g).scale(t,e,i||this.getPosition(!0)))},translate:function(){var t=new g;return this.transform(t.translate.apply(t,arguments))},rotate:function(t,e){return this.transform((new g).rotate(t,e||this.getPosition(!0)))},shear:function(t,e,i){return(arguments.length<2||"object"==typeof e)&&(i=e,e=t),this.transform((new g).shear(t,e,i||this.getPosition(!0)))},transform:function(t){var e=this._bounds,i=this._position;if(this._matrix.preConcatenate(t),(this._transformContent||arguments[1])&&this.applyMatrix(!0),this._changed(5),e&&0===t.getRotation()%90){for(var n in e){var r=e[n];t._transformBounds(r,r)}var s=this._boundsGetter,r=e[s&&s.getBounds||s||"getBounds"];r&&(this._position=r.getCenter(!0)),this._bounds=e}else i&&(this._position=t._transformPoint(i,i));return this},_applyMatrix:function(t,e){var i=this._children;if(i&&i.length>0){for(var n=0,r=i.length;r>n;n++)i[n].transform(t,e);return!0}},applyMatrix:function(t){var e=this._matrix;if(this._applyMatrix(e,!0)){var i=this._style,n=i.getFillColor(!0),r=i.getStrokeColor(!0);n&&n.transform(e),r&&r.transform(e),e.reset()}t||this._changed(5)},fitBounds:function(t,e){t=_.read(arguments);var i=this.getBounds(),n=i.height/i.width,r=t.height/t.width,s=(e?n>r:r>n)?t.width/i.width:t.height/i.height,a=new _(new h,new c(i.width*s,i.height*s));a.setCenter(t.getCenter()),this.setBounds(a)},_setStyles:function(t){var e=this._style,i=e.getFillColor(),n=e.getStrokeColor(),r=e.getShadowColor();if(i&&(t.fillStyle=i.toCanvasStyle(t)),n){var s=e.getStrokeWidth();if(s>0){t.strokeStyle=n.toCanvasStyle(t),t.lineWidth=s;var a=e.getStrokeJoin(),o=e.getStrokeCap(),h=e.getMiterLimit();if(a&&(t.lineJoin=a),o&&(t.lineCap=o),h&&(t.miterLimit=h),paper.support.nativeDash){var u=e.getDashArray(),l=e.getDashOffset();u&&u.length&&("setLineDash"in t?(t.setLineDash(u),t.lineDashOffset=l):(t.mozDash=u,t.mozDashOffset=l))}}}if(r){var c=e.getShadowBlur();if(c>0){t.shadowColor=r.toCanvasStyle(t),t.shadowBlur=c;var d=this.getShadowOffset();t.shadowOffsetX=d.x,t.shadowOffsetY=d.y}}},draw:function(t,e){if(this._visible&&0!==this._opacity){this._drawCount=this._project._drawCount;var i=e.trackTransforms,n=e.transforms,r=n[n.length-1],s=r.clone().concatenate(this._matrix);i&&n.push(this._globalMatrix=s);var a,o,h,u=this._blendMode,l=this._opacity,d="normal"===u,_=Q.nativeModes[u],f=d&&1===l||(_||d&&1>l)&&this._canComposite();if(!f){var g=this.getStrokeBounds(r);if(!g.width||!g.height)return;h=e.offset,o=e.offset=g.getTopLeft().floor(),a=t,t=K.getContext(g.getSize().ceil().add(new c(1,1)))}t.save(),f?(t.globalAlpha=l,_&&(t.globalCompositeOperation=u)):t.translate(-o.x,-o.y),(f?this._matrix:s).applyToContext(t),!f&&e.clipItem&&e.clipItem.draw(t,e.extend({clip:!0})),this._draw(t,e),t.restore(),i&&n.pop(),e.clip&&t.clip(),f||(Q.process(u,t,a,l,o.subtract(h)),K.release(t),e.offset=h)}},_canComposite:function(){return!1}},e.each(["down","drag","up","move"],function(t){this["removeOn"+e.capitalize(t)]=function(){var e={};return e[t]=!0,this.removeOn(e)}},{removeOn:function(t){for(var e in t)if(t[e]){var i="mouse"+e,n=this._project,r=n._removeSets=n._removeSets||{};r[i]=r[i]||{},r[i][this._id]=this}return this}})),w=y.extend({_class:"Group",_serializeFields:{children:[]},initialize:function(t){this._children=[],this._namedChildren={},this._initialize(t)||this.addChildren(Array.isArray(t)?t:arguments)},_changed:function ue(t){ue.base.call(this,t),2&t&&this._transformContent&&!this._matrix.isIdentity()&&this.applyMatrix(),258&t&&delete this._clipItem},_getClipItem:function(){if(this._clipItem!==t)return this._clipItem;for(var e=0,i=this._children.length;i>e;e++){var n=this._children[e];if(n._clipMask)return this._clipItem=n}return this._clipItem=null},getTransformContent:function(){return this._transformContent},setTransformContent:function(t){this._transformContent=t,t&&this.applyMatrix()},isClipped:function(){return!!this._getClipItem()},setClipped:function(t){var e=this.getFirstChild();e&&e.setClipMask(t)},_draw:function(t,e){var i=e.clipItem=this._getClipItem();i&&i.draw(t,e.extend({clip:!0}));for(var n=0,r=this._children.length;r>n;n++){var s=this._children[n];s!==i&&s.draw(t,e)}e.clipItem=null}}),x=w.extend({_class:"Layer",initialize:function(){this._project=paper.project,this._index=this._project.layers.push(this)-1,w.apply(this,arguments),this.activate()},_remove:function le(t){return this._parent?le.base.call(this,t):null!=this._index?(this._project.activeLayer===this&&(this._project.activeLayer=this.getNextSibling()||this.getPreviousSibling()),e.splice(this._project.layers,null,this._index,1),this._project._needsRedraw=!0,!0):!1},getNextSibling:function ce(){return this._parent?ce.base.call(this):this._project.layers[this._index+1]||null},getPreviousSibling:function de(){return this._parent?de.base.call(this):this._project.layers[this._index-1]||null},isInserted:function _e(){return this._parent?_e.base.call(this):null!=this._index},activate:function(){this._project.activeLayer=this},_insert:function fe(t,i,n){return i instanceof x&&!i._parent&&this._remove(!0)?(e.splice(i._project.layers,[this],i._index+(t?1:0),0),this._setProject(i._project),this):fe.base.call(this,t,i,n)}}),b=y.extend({_class:"Shape",_transformContent:!1,_boundsSelected:!0,initialize:function(t,e,i,n,r){this._shape=t,this._size=i,this._radius=n,this._initialize(r,e)},_equals:function(t){return this._shape===t._shape&&this._size.equals(t._size)&&e.equals(this._radius,t._radius)},clone:function(t){return this._clone(new b(this._shape,this.getPosition(!0),this._size.clone(),this._radius.clone?this._radius.clone():this._radius,{insert:!1}),t)},getShape:function(){return this._shape},getSize:function(){var t=this._size;return new d(t.width,t.height,this,"setSize")},setSize:function(){var t=this._shape,e=c.read(arguments);if(!this._size.equals(e)){var i=e.width,n=e.height;if("rectangle"===t){var r=c.min(this._radius,e.divide(2));this._radius.set(r.width,r.height)}else"circle"===t?(i=n=(i+n)/2,this._radius=i/2):"ellipse"===t&&this._radius.set(i/2,n/2);this._size.set(i,n),this._changed(5)}},getRadius:function(){var t=this._radius;return"circle"===this._shape?t:new d(t.width,t.height,this,"setRadius")},setRadius:function(t){var e=this._shape;if("circle"===e){if(t===this._radius)return;var i=2*t;this._size.set(i,i)}else{if(t=c.read(arguments),this._radius.equals(t))return;if(this._radius.set(t.width,t.height),"rectangle"===e){var i=c.max(this._size,t.multiply(2));this._size.set(i.width,i.height)}else"ellipse"===e&&this._size.set(2*t.width,2*t.height)}this._changed(5)},isEmpty:function(){return!1},toPath:function(i){var n=new(O[e.capitalize(this._shape)])({center:new h,size:this._size,radius:this._radius,insert:!1});return n.setStyle(this._style),n.transform(this._matrix),(i||i===t)&&n.insertAbove(this),n},_draw:function(t,e){var i=this._style,n=i.hasFill(),r=i.hasStroke(),s=e.clip;if(n||r||s){var a=this._radius,h=this._shape;if(t.beginPath(),"circle"===h)t.arc(0,0,a,0,2*Math.PI,!0);else{var u=a.width,l=a.height,c=o.KAPPA;if("ellipse"===h){var d=u*c,_=l*c;t.moveTo(-u,0),t.bezierCurveTo(-u,-_,-d,-l,0,-l),t.bezierCurveTo(d,-l,u,-_,u,0),t.bezierCurveTo(u,_,d,l,0,l),t.bezierCurveTo(-d,l,-u,_,-u,0)}else{var f=this._size,g=f.width,v=f.height;if(0===u&&0===l)t.rect(-g/2,-v/2,g,v);else{c=1-c;var m=g/2,p=v/2,d=u*c,_=l*c;t.moveTo(-m,-p+l),t.bezierCurveTo(-m,-p+_,-m+d,-p,-m+u,-p),t.lineTo(m-u,-p),t.bezierCurveTo(m-d,-p,m,-p+_,m,-p+l),t.lineTo(m,p-l),t.bezierCurveTo(m,p-_,m-d,p,m-u,p),t.lineTo(-m+u,p),t.bezierCurveTo(-m+d,p,-m,p-_,-m,p-l)}}}t.closePath()}s||!n&&!r||(this._setStyles(t),n&&(t.fill(i.getWindingRule()),t.shadowColor="rgba(0,0,0,0)"),r&&t.stroke())},_canComposite:function(){return!(this.hasFill()&&this.hasStroke())},_getBounds:function(t,e){var i=new _(this._size).setCenter(0,0);return"getBounds"!==t&&this.hasStroke()&&(i=i.expand(this.getStrokeWidth())),e?e._transformBounds(i):i}},new function(){function t(t,e,i){var n=t._radius;if(!n.isZero())for(var r=t._size.divide(2),s=0;4>s;s++){var a=new h(1&s?1:-1,s>1?1:-1),o=a.multiply(r),u=o.subtract(a.multiply(n)),l=new _(o,u);if((i?l.expand(i):l).contains(e))return u}}function e(t,e){var i=t.getAngleInRadians(),n=2*e.width,r=2*e.height,s=n*Math.sin(i),a=r*Math.cos(i);return n*r/(2*Math.sqrt(s*s+a*a))}return{_contains:function i(e){if("rectangle"===this._shape){var n=t(this,e);return n?e.subtract(n).divide(this._radius).getLength()<=1:i.base.call(this,e)}return e.divide(this.size).getLength()<=.5},_hitTest:function n(i,r){var s=!1;if(this.hasStroke()){var a=this._shape,o=this._radius,h=this.getStrokeWidth()+2*r.tolerance;if("rectangle"===a){var u=t(this,i,h);if(u){var l=i.subtract(u);s=2*Math.abs(l.getLength()-e(l,o))<=h}else{var c=new _(this._size).setCenter(0,0),d=c.expand(h),f=c.expand(-h);s=d._containsPoint(i)&&!f._containsPoint(i)}}else"ellipse"===a&&(o=e(i,o)),s=2*Math.abs(i.getLength()-o)<=h}return s?new P("stroke",this):n.base.apply(this,arguments)}}},{statics:new function(){function t(t,i,n,r,s){return new b(t,i,n,r,e.getNamed(s))}return{Circle:function(){var i=h.readNamed(arguments,"center"),n=e.readNamed(arguments,"radius");return t("circle",i,new c(2*n),n,arguments)},Rectangle:function(){var e=_.readNamed(arguments,"rectangle"),i=c.min(c.readNamed(arguments,"radius"),e.getSize(!0).divide(2));return t("rectangle",e.getCenter(!0),e.getSize(!0),i,arguments)},Ellipse:function(){var e=b._readEllipse(arguments);return radius=e.radius,t("ellipse",e.center,radius.multiply(2),radius,arguments)},_readEllipse:function(t){var i,n;if(e.hasNamed(t,"radius"))i=h.readNamed(t,"center"),n=c.readNamed(t,"radius");else{var r=_.readNamed(t,"rectangle");i=r.getCenter(!0),n=r.getSize(!0).divide(2)}return{center:i,radius:n}}}}}),C=y.extend({_class:"Raster",_transformContent:!1,_boundsGetter:"getBounds",_boundsSelected:!0,_serializeFields:{source:null},initialize:function(e,i){this._initialize(e,i!==t&&h.read(arguments,1))||("string"==typeof e?this.setSource(e):this.setImage(e)),this._size||(this._size=new c)},_equals:function(t){return this.getSource()===t.getSource()},clone:function(t){var e={insert:!1},i=this._image;if(i)e.image=i;else if(this._canvas){var n=e.canvas=K.getCanvas(this._size);n.getContext("2d").drawImage(this._canvas,0,0)}return this._clone(new C(e),t)},getSize:function(){var t=this._size;return new d(t.width,t.height,this,"setSize")},setSize:function(){var t=c.read(arguments);if(!this._size.equals(t)){var e=this.getElement();this.setCanvas(K.getCanvas(t)),e&&this.getContext(!0).drawImage(e,0,0,t.width,t.height)}},getWidth:function(){return this._size.width},getHeight:function(){return this._size.height},isEmpty:function(){return 0==this._size.width&&0==this._size.height},getPpi:function(){var t=this._matrix,e=new h(0,0).transform(t),i=new h(1,0).transform(t).subtract(e),n=new h(0,1).transform(t).subtract(e);return new c(72/i.getLength(),72/n.getLength())},getImage:function(){return this._image},setImage:function(t){this._canvas&&K.release(this._canvas),t.getContext?(this._image=null,this._canvas=t):(this._image=t,this._canvas=null),this._size=new c(t.naturalWidth||t.width,t.naturalHeight||t.height),this._context=null,this._changed(133)},getCanvas:function(){if(!this._canvas){var t=K.getContext(this._size);try{this._image&&t.drawImage(this._image,0,0),this._canvas=t.canvas}catch(e){K.release(t)}}return this._canvas},setCanvas:"#setImage",getContext:function(){return this._context||(this._context=this.getCanvas().getContext("2d")),arguments[0]&&(this._image=null,this._changed(129)),this._context},setContext:function(t){this._context=t},getSource:function(){return this._image&&this._image.src||this.toDataURL()},setSource:function(t){function e(){var t=i._project.view;t&&(paper=t._scope),i.fire("load"),t&&t.draw(!0)}var i=this,n=document.getElementById(t)||new Image;n.naturalWidth&&n.naturalHeight?setTimeout(e,0):(V.add(n,{load:function(){i.setImage(n),e()}}),n.src||(n.src=t)),this.setImage(n)},getElement:function(){return this._canvas||this._image},getSubCanvas:function(t){t=_.read(arguments);var e=K.getContext(t.getSize());return e.drawImage(this.getCanvas(),t.x,t.y,t.width,t.height,0,0,t.width,t.height),e.canvas},getSubRaster:function(t){t=_.read(arguments);var e=new C({canvas:this.getSubCanvas(t),insert:!1});return e.translate(t.getCenter().subtract(this.getSize().divide(2))),e._matrix.preConcatenate(this._matrix),e.insertAbove(this),e},toDataURL:function(){var t=this._image&&this._image.src; +if(/^data:/.test(t))return t;var e=this.getCanvas();return e?e.toDataURL():null},drawImage:function(t,e){e=h.read(arguments,1),this.getContext(!0).drawImage(t,e.x,e.y)},getAverageColor:function(t){var i,n;t?t instanceof A?(n=t,i=t.getBounds()):t.width?i=new _(t):t.x&&(i=new _(t.x-.5,t.y-.5,1,1)):i=this.getBounds();var r=32,s=Math.min(i.width,r),a=Math.min(i.height,r),o=C._sampleContext;o?o.clearRect(0,0,r+1,r+1):o=C._sampleContext=K.getContext(new c(r)),o.save();var h=(new g).scale(s/i.width,a/i.height).translate(-i.x,-i.y);h.applyToContext(o),n&&n.draw(o,e.merge({clip:!0,transforms:[h]})),this._matrix.applyToContext(o),o.drawImage(this.getElement(),-this._size.width/2,-this._size.height/2),o.restore();for(var u=o.getImageData(.5,.5,Math.ceil(s),Math.ceil(a)).data,l=[0,0,0],d=0,f=0,v=u.length;v>f;f+=4){var m=u[f+3];d+=m,m/=255,l[0]+=u[f]*m,l[1]+=u[f+1]*m,l[2]+=u[f+2]*m}for(var f=0;3>f;f++)l[f]/=d;return d?N.read(l):null},getPixel:function(t){t=h.read(arguments);var e=this.getContext().getImageData(t.x,t.y,1,1).data;return new N("rgb",[e[0]/255,e[1]/255,e[2]/255],e[3]/255)},setPixel:function(){var t=h.read(arguments),e=N.read(arguments),i=e._convert("rgb"),n=e._alpha,r=this.getContext(!0),s=r.createImageData(1,1),a=s.data;a[0]=255*i[0],a[1]=255*i[1],a[2]=255*i[2],a[3]=null!=n?255*n:255,r.putImageData(s,t.x,t.y)},createImageData:function(t){return t=c.read(arguments),this.getContext().createImageData(t.width,t.height)},getImageData:function(t){return t=_.read(arguments),t.isEmpty()&&(t=new _(this._size)),this.getContext().getImageData(t.x,t.y,t.width,t.height)},setImageData:function(t,e){e=h.read(arguments,1),this.getContext(!0).putImageData(t,e.x,e.y)},_getBounds:function(t,e){var i=new _(this._size).setCenter(0,0);return e?e._transformBounds(i):i},_hitTest:function(t){if(this._contains(t)){var e=this;return new P("pixel",e,{offset:t.add(e._size.divide(2)).round(),color:{get:function(){return e.getPixel(this.offset)}}})}},_draw:function(t){var e=this.getElement();e&&(t.globalAlpha=this._opacity,t.drawImage(e,-this._size.width/2,-this._size.height/2))},_canComposite:function(){return!0}}),S=y.extend({_class:"PlacedSymbol",_transformContent:!1,_boundsGetter:{getBounds:"getStrokeBounds"},_boundsSelected:!0,_serializeFields:{symbol:null},initialize:function(e,i){this._initialize(e,i!==t&&h.read(arguments,1))||this.setSymbol(e instanceof p?e:new p(e))},_equals:function(t){return this._symbol===t._symbol},getSymbol:function(){return this._symbol},setSymbol:function(t){this._symbol&&delete this._symbol._instances[this._id],this._symbol=t,t._instances[this._id]=this},clone:function(t){return this._clone(new S({symbol:this.symbol,insert:!1}),t)},isEmpty:function(){return this._symbol._definition.isEmpty()},_getBounds:function(t,e){return this.symbol._definition._getCachedBounds(t,e)},_hitTest:function(t,e,i){var n=this._symbol._definition._hitTest(t,e,i);return n&&(n.item=this),n},_draw:function(t,e){this.symbol._definition.draw(t,e)}}),P=e.extend({_class:"HitResult",initialize:function(t,e,i){this.type=t,this.item=e,i&&(i.enumerable=!0,this.inject(i))},statics:{getOptions:function(t){return t&&t._merged?t:e.merge({type:null,tolerance:paper.project.options.hitTolerance||2,fill:!t,stroke:!t,segments:!t,handles:!1,ends:!1,center:!1,bounds:!1,guides:!1,selected:!1,_merged:!0},t)}}}),z=e.extend({_class:"Segment",initialize:function(e,i,n,r,s,a){var o,h,u,l=arguments.length;0===l||(1===l?e.point?(o=e.point,h=e.handleIn,u=e.handleOut):o=e:2===l&&"number"==typeof e?o=arguments:3>=l?(o=e,h=i,u=n):(o=e!==t?[e,i]:null,h=n!==t?[n,r]:null,u=s!==t?[s,a]:null)),new M(o,this,"_point"),new M(h,this,"_handleIn"),new M(u,this,"_handleOut")},_serialize:function(t){return e.serialize(this.isLinear()?this._point:[this._point,this._handleIn,this._handleOut],t,!0)},_changed:function(t){if(this._path){var e,i=this._path._curves&&this.getCurve();i&&(i._changed(),(e=i[t==this._point||t==this._handleIn&&i._segment1==this?"getPrevious":"getNext"]())&&e._changed()),this._path._changed(5)}},getPoint:function(){return this._point},setPoint:function(t){t=h.read(arguments),this._point.set(t.x,t.y)},getHandleIn:function(){return this._handleIn},setHandleIn:function(t){t=h.read(arguments),this._handleIn.set(t.x,t.y)},getHandleOut:function(){return this._handleOut},setHandleOut:function(t){t=h.read(arguments),this._handleOut.set(t.x,t.y)},isLinear:function(){return this._handleIn.isZero()&&this._handleOut.isZero()},setLinear:function(){this._handleIn.set(0,0),this._handleOut.set(0,0)},isColinear:function(t){var e=this.getNext(),i=t.getNext();return this._handleOut.isZero()&&e._handleIn.isZero()&&t._handleOut.isZero()&&i._handleIn.isZero()&&e._point.subtract(this._point).isColinear(i._point.subtract(t._point))},isOrthogonal:function(){var t=this.getPrevious(),e=this.getNext();return t._handleOut.isZero()&&this._handleIn.isZero()&&this._handleOut.isZero()&&e._handleIn.isZero()&&this._point.subtract(t._point).isOrthogonal(e._point.subtract(this._point))},isArc:function(){var t=this.getNext(),e=this._handleOut,i=t._handleIn,n=o.KAPPA;if(e.isOrthogonal(i)){var r=this._point,s=t._point,a=new v(r,e,!0).intersect(new v(s,i,!0),!0);return a&&o.isZero(e.getLength()/a.subtract(r).getLength()-n)&&o.isZero(i.getLength()/a.subtract(s).getLength()-n)}return!1},_isSelected:function(t){var e=this._selectionState;return t==this._point?!!(4&e):t==this._handleIn?!!(1&e):t==this._handleOut?!!(2&e):!1},_setSelected:function(t,e){var i=this._path,e=!!e,n=this._selectionState||0,r=[!!(4&n),!!(1&n),!!(2&n)];if(t===this._point){if(e)r[1]=r[2]=!1;else{var s=this.getPrevious(),a=this.getNext();r[1]=s&&(s._point.isSelected()||s._handleOut.isSelected()),r[2]=a&&(a._point.isSelected()||a._handleIn.isSelected())}r[0]=e}else{var o=t===this._handleIn?1:2;r[o]!=e&&(e&&(r[0]=!1),r[o]=e)}this._selectionState=(r[0]?4:0)|(r[1]?1:0)|(r[2]?2:0),i&&n!=this._selectionState&&(i._updateSelection(this,n,this._selectionState),i._changed(33))},isSelected:function(){return this._isSelected(this._point)},setSelected:function(t){this._setSelected(this._point,t)},getIndex:function(){return this._index!==t?this._index:null},getPath:function(){return this._path||null},getCurve:function(){var t=this._path,e=this._index;return t?(t._closed||e!=t._segments.length-1||e--,t.getCurves()[e]||null):null},getLocation:function(){var t=this.getCurve();return t?new k(t,t.getNext()?0:1):null},getNext:function(){var t=this._path&&this._path._segments;return t&&(t[this._index+1]||this._path._closed&&t[0])||null},getPrevious:function(){var t=this._path&&this._path._segments;return t&&(t[this._index-1]||this._path._closed&&t[t.length-1])||null},reverse:function(){return new z(this._point,this._handleOut,this._handleIn)},remove:function(){return this._path?!!this._path.removeSegment(this._index):!1},clone:function(){return new z(this._point,this._handleIn,this._handleOut)},equals:function(t){return t===this||t&&this._class===t._class&&this._point.equals(t._point)&&this._handleIn.equals(t._handleIn)&&this._handleOut.equals(t._handleOut)||!1},toString:function(){var t=["point: "+this._point];return this._handleIn.isZero()||t.push("handleIn: "+this._handleIn),this._handleOut.isZero()||t.push("handleOut: "+this._handleOut),"{ "+t.join(", ")+" }"},_transformCoordinates:function(t,e,i){var n=this._point,r=i&&this._handleIn.isZero()?null:this._handleIn,s=i&&this._handleOut.isZero()?null:this._handleOut,a=n._x,o=n._y,h=2;return e[0]=a,e[1]=o,r&&(e[h++]=r._x+a,e[h++]=r._y+o),s&&(e[h++]=s._x+a,e[h++]=s._y+o),t&&(t._transformCoordinates(e,0,e,0,h/2),a=e[0],o=e[1],i?(n._x=a,n._y=o,h=2,r&&(r._x=e[h++]-a,r._y=e[h++]-o),s&&(s._x=e[h++]-a,s._y=e[h++]-o)):(r||(e[h++]=a,e[h++]=o),s||(e[h++]=a,e[h++]=o))),e}}),M=h.extend({initialize:function(e,i,n){var r,s,a;e?(r=e[0])!==t?s=e[1]:((r=e.x)===t&&(e=h.read(arguments),r=e.x),s=e.y,a=e.selected):r=s=0,this._x=r,this._y=s,this._owner=i,i[n]=this,a&&this.setSelected(!0)},set:function(t,e){return this._x=t,this._y=e,this._owner._changed(this),this},_serialize:function(t){var e=t.formatter,i=e.number(this._x),n=e.number(this._y);return this.isSelected()?{x:i,y:n,selected:!0}:[i,n]},getX:function(){return this._x},setX:function(t){this._x=t,this._owner._changed(this)},getY:function(){return this._y},setY:function(t){this._y=t,this._owner._changed(this)},isZero:function(){return o.isZero(this._x)&&o.isZero(this._y)},setSelected:function(t){this._owner._setSelected(this,t)},isSelected:function(){return this._owner._isSelected(this)}}),I=e.extend({_class:"Curve",initialize:function(t,e,i,n,r,s,a,o){var h=arguments.length;if(3===h)this._path=t,this._segment1=e,this._segment2=i;else if(0===h)this._segment1=new z,this._segment2=new z;else if(1===h)this._segment1=new z(t.segment1),this._segment2=new z(t.segment2);else if(2===h)this._segment1=new z(t),this._segment2=new z(e);else{var u,l,c,d;4===h?(u=t,l=e,c=i,d=n):8===h&&(u=[t,e],d=[a,o],l=[i-t,n-e],c=[r-a,s-o]),this._segment1=new z(u,null,l),this._segment2=new z(d,c,null)}},_changed:function(){delete this._length,delete this._bounds},getPoint1:function(){return this._segment1._point},setPoint1:function(t){t=h.read(arguments),this._segment1._point.set(t.x,t.y)},getPoint2:function(){return this._segment2._point},setPoint2:function(t){t=h.read(arguments),this._segment2._point.set(t.x,t.y)},getHandle1:function(){return this._segment1._handleOut},setHandle1:function(t){t=h.read(arguments),this._segment1._handleOut.set(t.x,t.y)},getHandle2:function(){return this._segment2._handleIn},setHandle2:function(t){t=h.read(arguments),this._segment2._handleIn.set(t.x,t.y)},getSegment1:function(){return this._segment1},getSegment2:function(){return this._segment2},getPath:function(){return this._path},getIndex:function(){return this._segment1._index},getNext:function(){var t=this._path&&this._path._curves;return t&&(t[this._segment1._index+1]||this._path._closed&&t[0])||null},getPrevious:function(){var t=this._path&&this._path._curves;return t&&(t[this._segment1._index-1]||this._path._closed&&t[t.length-1])||null},isSelected:function(){return this.getHandle1().isSelected()&&this.getHandle2().isSelected()},setSelected:function(t){this.getHandle1().setSelected(t),this.getHandle2().setSelected(t)},getValues:function(){return I.getValues(this._segment1,this._segment2)},getPoints:function(){for(var t=this.getValues(),e=[],i=0;8>i;i+=2)e.push(new h(t[i],t[i+1]));return e},getLength:function(){var t=arguments[0],e=arguments[1],i=0===arguments.length||0===t&&1===e;if(i&&null!=this._length)return this._length;var n=I.getLength(this.getValues(),t,e);return i&&(this._length=n),n},getArea:function(){return I.getArea(this.getValues())},getPart:function(t,e){return new I(I.getPart(this.getValues(),t,e))},isLinear:function(){return this._segment1._handleOut.isZero()&&this._segment2._handleIn.isZero()},getIntersections:function(t){return I.getIntersections(this.getValues(),t.getValues(),this,t,[])},reverse:function(){return new I(this._segment2.reverse(),this._segment1.reverse())},_getParameter:function(e,i){return i?e:e&&e.curve===this?e.parameter:e===t&&i===t?.5:this.getParameterAt(e,0)},divide:function(t,e){var i=this._getParameter(t,e),n=null;if(i>0&&1>i){var r=I.subdivide(this.getValues(),i),s=this.isLinear(),a=r[0],o=r[1];s||(this._segment1._handleOut.set(a[2]-a[0],a[3]-a[1]),this._segment2._handleIn.set(o[4]-o[6],o[5]-o[7]));var u=a[6],l=a[7],c=new z(new h(u,l),!s&&new h(a[4]-u,a[5]-l),!s&&new h(o[2]-u,o[3]-l));if(this._path)this._segment1._index>0&&0===this._segment2._index?this._path.add(c):this._path.insert(this._segment2._index,c),n=this;else{var d=this._segment2;this._segment2=c,n=new I(c,d)}}return n},split:function(t,e){return this._path?this._path.split(this._segment1._index,this._getParameter(t,e)):null},clone:function(){return new I(this._segment1,this._segment2)},toString:function(){var t=["point1: "+this._segment1._point];return this._segment1._handleOut.isZero()||t.push("handle1: "+this._segment1._handleOut),this._segment2._handleIn.isZero()||t.push("handle2: "+this._segment2._handleIn),t.push("point2: "+this._segment2._point),"{ "+t.join(", ")+" }"},statics:{getValues:function(t,e){var i=t._point,n=t._handleOut,r=e._handleIn,s=e._point;return[i._x,i._y,i._x+n._x,i._y+n._y,s._x+r._x,s._y+r._y,s._x,s._y]},evaluate:function(t,e,i){var n,r,s=t[0],a=t[1],o=t[2],u=t[3],l=t[4],c=t[5],d=t[6],_=t[7];if(0!==i||0!==e&&1!==e){var f=3*(o-s),g=3*(l-o)-f,v=d-s-f-g,m=3*(u-a),p=3*(c-u)-m,y=_-a-m-p;if(0===i)n=((v*e+g)*e+f)*e+s,r=((y*e+p)*e+m)*e+a;else{var w=1e-5;if(w>e&&o==s&&u==a||e>1-w&&l==d&&c==_?(n=l-o,r=c-u):(n=(3*v*e+2*g)*e+f,r=(3*y*e+2*p)*e+m),3===i){var x=6*v*e+2*g,b=6*y*e+2*p;return(n*b-r*x)/Math.pow(n*n+r*r,1.5)}}}else n=0===e?s:d,r=0===e?a:_;return 2==i?new h(r,-n):new h(n,r)},subdivide:function(e,i){var n=e[0],r=e[1],s=e[2],a=e[3],o=e[4],h=e[5],u=e[6],l=e[7];i===t&&(i=.5);var c=1-i,d=c*n+i*s,_=c*r+i*a,f=c*s+i*o,g=c*a+i*h,v=c*o+i*u,m=c*h+i*l,p=c*d+i*f,y=c*_+i*g,w=c*f+i*v,x=c*g+i*m,b=c*p+i*w,C=c*y+i*x;return[[n,r,d,_,p,y,b,C],[b,C,w,x,v,m,u,l]]},solveCubic:function(t,e,i,n,r,s){var a=t[e],h=t[e+2],u=t[e+4],l=t[e+6],c=3*(h-a),d=3*(u-h)-c,_=l-a-c-d;return o.solveCubic(_,d,c,a-i,n,r,s)},getParameterOf:function(t,e,i){if(Math.abs(t[0]-e)<1e-5&&Math.abs(t[1]-i)<1e-5)return 0;if(Math.abs(t[6]-e)<1e-5&&Math.abs(t[7]-i)<1e-5)return 1;for(var n,r,s=[],a=[],o=I.solveCubic(t,0,e,s),h=I.solveCubic(t,1,i,a),u=0;-1==o||o>u;)if(-1==o||(n=s[u++])>=0&&1>=n){for(var l=0;-1==h||h>l;)if((-1==h||(r=a[l++])>=0&&1>=r)&&(-1==o?n=r:-1==h&&(r=n),Math.abs(n-r)<1e-5))return.5*(n+r);if(-1==o)break}return null},getPart:function(t,e,i){return e>0&&(t=I.subdivide(t,e)[1]),1>i&&(t=I.subdivide(t,(i-e)/(1-e))[0]),t},isLinear:function(t){var e=o.isZero;return e(t[0]-t[2])&&e(t[1]-t[3])&&e(t[4]-t[6])&&e(t[5]-t[7])},isFlatEnough:function(t,e){var i=t[0],n=t[1],r=t[2],s=t[3],a=t[4],o=t[5],h=t[6],u=t[7],l=3*r-2*i-h,c=3*s-2*n-u,d=3*a-2*h-i,_=3*o-2*u-n;return Math.max(l*l,d*d)+Math.max(c*c,_*_)<10*e*e},getArea:function(t){var e=t[0],i=t[1],n=t[2],r=t[3],s=t[4],a=t[5],o=t[6],h=t[7];return(3*r*e-1.5*r*s-1.5*r*o-3*i*n-1.5*i*s-.5*i*o+1.5*a*e+1.5*a*n-3*a*o+.5*h*e+1.5*h*n+3*h*s)/10},getBounds:function(t){for(var e=t.slice(0,2),i=e.slice(),n=[0,0],r=0;2>r;r++)I._addBounds(t[r],t[r+2],t[r+4],t[r+6],r,0,e,i,n);return new _(e[0],e[1],i[0]-e[0],i[1]-e[1])},_addBounds:function(t,e,i,n,r,s,a,h,u){function l(t,e){var i=t-e,n=t+e;ih[r]&&(h[r]=n)}var c=3*(e-i)-t+n,d=2*(t+i)-4*e,_=e-t,f=o.solveQuadratic(c,d,_,u),g=1e-5,v=1-g;l(n,0);for(var m=0;f>m;m++){var p=u[m],y=1-p;p>g&&v>p&&l(y*y*y*t+3*y*y*p*e+3*y*p*p*i+p*p*p*n,s)}},_getWinding:function(t,e,i,n,r){function s(t){var e=t[1],n=t[7],r=1;if(e>n){var s=e;e=n,n=s,r=-1}return(e>i||i>n)&&(r=0),r}var a=1e-5,h=Math.abs;if(I.isLinear(t)){var u=s(t);if(!u)return 0;var l=(t[6]-t[0])*(i-t[1])-(t[7]-t[1])*(e-t[0]);return(-a>l?-1:1)==u?0:u}for(var c,d=t[1],_=t[3],f=t[5],g=t[7],v=3*(_-f)-d+g,m=2*(d+f)-4*_,p=_-d,y=o.solveQuadratic(v,m,p,n,a,1-a),w=t,x=n[0],b=0,C=0;y>=C;C++){if(C===y)c=w;else{var S=I.subdivide(w,x);c=S[0],w=S[1],x=n[C],x=(n[C+1]-x)/(1-x)}C>0&&(c[3]=c[1]),y>C&&(c[5]=w[1]);var u=s(c);if(u){var P,z;if(1===I.solveCubic(c,1,i,r,-a,1+-a))P=r[0],z=I.evaluate(c,P,0).x;else{var M=(c[1]+c[7])/2;if(P=M>i&&u>0?0:1,1===P&&i==c[7])continue;z=0===P?c[0]:c[6]}var k=h(I.evaluate(c,P,1).y)=z+(k?-a:a*u))||k&&(h(P)0?1:0))e?1:0)},getParameterOf:function(t){return t=h.read(arguments),I.getParameterOf(this.getValues(),t.x,t.y)},getLocationAt:function(t,e){return e||(t=this.getParameterAt(t)),new k(this,t)},getLocationOf:function(t){t=h.read(arguments);var e=this.getParameterOf(t);return null!=e?new k(this,e):null},getNearestLocation:function(t){function e(e){if(e>=0&&1>=e){var n=t.getDistance(I.evaluate(i,e,0),!0);if(s>n)return s=n,a=e,!0}}t=h.read(arguments);for(var i=this.getValues(),n=100,r=o.TOLERANCE,s=1/0,a=0,u=0;n>=u;u++)e(u/n);for(var l=1/(2*n);l>r;)e(a-l)||e(a+l)||(l/=2);var c=I.evaluate(i,a,0);return new k(this,a,c,null,null,null,t.getDistance(c))},getNearestPoint:function(t){return t=h.read(arguments),this.getNearestLocation(t).getPoint()}}),new function(){function e(t){var e=t[0],i=t[1],n=t[2],r=t[3],s=t[4],a=t[5],o=t[6],h=t[7],u=9*(n-s)+3*(o-e),l=6*(e+s)-12*n,c=3*(n-e),d=9*(r-a)+3*(h-i),_=6*(i+a)-12*r,f=3*(r-i);return function(t){var e=(u*t+l)*t+c,i=(d*t+_)*t+f;return Math.sqrt(e*e+i*i)}}function i(t,e){return Math.max(2,Math.min(16,Math.ceil(32*Math.abs(e-t))))}return{statics:!0,getLength:function(n,r,s){r===t&&(r=0),s===t&&(s=1);var a=o.isZero;if(a(n[0]-n[2])&&a(n[1]-n[3])&&a(n[6]-n[4])&&a(n[7]-n[5])){var h=n[6]-n[0],u=n[7]-n[1];return(s-r)*Math.sqrt(h*h+u*u)}var l=e(n);return o.integrate(l,r,s,i(r,s))},getParameterAt:function(t,n,r){function s(t){var e=i(r,t);return _+=t>r?o.integrate(l,r,t,e):-o.integrate(l,t,r,e),r=t,_-n}if(0===n)return r;var a=n>0,h=a?r:0,u=a?1:r,n=Math.abs(n),l=e(t),c=o.integrate(l,h,u,i(h,u));if(n>=c)return a?u:h;var d=n/c,_=0;return o.findRoot(s,l,a?h+d:u-d,h,u,16,1e-5)}}},new function(){function t(t,e,i,n,r,s,a){var o=t[0],h=t[t.length-1];o&&n.equals(o._point)||h&&n.equals(h._point)||t.push(new k(e,i,n,r,s,a))}function e(n,r,s,a,o,h,u,l){if(l=(l||0)+1,!(l>20)){h=h||[0,1],u=u||[0,1];for(var c=I.getPart(n,h[0],h[1]),d=I.getPart(r,u[0],u[1]),_=0;_++<20;){var f,g=i(c,d,f=u.slice()),v=0;if(0===g)break;if(g>0){if(u=f,d=I.getPart(r,u[0],u[1]),v=i(d,c,f=h.slice()),0===v)break;g>0&&(h=f,c=I.getPart(n,h[0],h[1]))}if(0>g||0>v){if(h[1]-h[0]>u[1]-u[0]){var m=(h[0]+h[1])/2;e(n,r,s,a,o,[h[0],m],u,l),e(n,r,s,a,o,[m,h[1]],u,l);break}var m=(u[0]+u[1])/2;e(n,r,s,a,o,h,[u[0],m],l),e(n,r,s,a,o,h,[m,u[1]],l);break}if(Math.abs(h[1]-h[0])<=1e-5&&Math.abs(u[1]-u[0])<=1e-5){var p=(h[0]+h[1])/2,y=(u[0]+u[1])/2;t(o,s,p,I.evaluate(n,p,0),a,y,I.evaluate(r,y,0));break}}}}function i(t,e,i){var r=t[0],s=t[1],a=t[2],o=t[3],h=t[4],u=t[5],l=t[6],c=t[7],d=e[0],_=e[1],f=e[2],g=e[3],m=e[4],p=e[5],y=e[6],w=e[7],x=v.getSignedDistance,b=x(r,s,l,c,a,o)||0,C=x(r,s,l,c,h,u)||0,S=b*C>0?.75:4/9,P=S*Math.min(0,b,C),z=S*Math.max(0,b,C),M=x(r,s,l,c,d,_),k=x(r,s,l,c,f,g),A=x(r,s,l,c,m,p),O=x(r,s,l,c,y,w);if(P>Math.max(M,k,A,O)||zO&&(T=P,P=z,z=T);for(var D=-1/0,j=1/0,B=-1/0,N=0,q=L.length;q>N;N++){var F=L[N],E=L[(N+1)%q];E[1]=V&&H>=P){var G=R+(P-V)/W;j>G&&(j=G),G>D&&(D=G)}if(z>=V&&H>=z){var G=R+(z-V)/W;G>B&&(B=G),j>G&&(j=0)}}if(1/0!==j&&B!==-1/0){var X=Math.min(P,z),J=Math.max(P,z);O>X&&J>O&&(B=1),M>X&&J>M&&(j=0),D>B&&(B=1);var Y=i[0],U=i[1]-Y;if(i[0]=Y+j*U,i[1]=Y+B*U,(U-(i[1]-i[0]))/U>=.2)return 1}return I.getBounds(t).touches(I.getBounds(e))?-1:0}function n(t,e,i,n){var r=[0,t],s=[1/3,e],a=[2/3,i],o=[1,n],h=v.getSignedDistance,u=h(0,t,1,n,1/3,e),l=h(0,t,1,n,2/3,i);if(0>u*l)return[r,s,o,a];var c,d;return Math.abs(u)>Math.abs(l)?(c=s,d=(n-i-(n-t)/3)*(2*(n-i)-n+e)/3):(c=a,d=(e-t+(t-n)/3)*(-2*(t-e)+t-i)/3),0>d?[r,c,o]:[r,s,a,o]}function r(e,i,n,r,s){for(var a=I.isLinear(e),o=a?i:e,h=a?e:i,u=h[0],l=h[1],c=h[6],d=h[7],_=c-u,f=d-l,g=Math.atan2(-f,_),v=Math.sin(g),m=Math.cos(g),p=_*m-f*v,y=[0,0,0,0,p,0,p,0],w=[],x=0;8>x;x+=2){var b=o[x]-u,C=o[x+1]-l;w.push(b*m-C*v,C*m+b*v)}for(var S=[],P=I.solveCubic(w,1,0,S,0,1),x=0;P>x;x++){var z=S[x],b=I.evaluate(w,z,0).x;if(b>=0&&p>=b){var M=I.getParameterOf(y,b,0),k=a?M:z,A=a?z:M;t(s,n,k,I.evaluate(e,k,0),r,A,I.evaluate(i,A,0))}}}function s(e,i,n,r,s){var a=v.intersect(e[0],e[1],e[6],e[7],i[0],i[1],i[6],i[7]);a&&t(s,n,null,a,r)}return{statics:{getIntersections:function(t,i,n,a,o){var h=I.isLinear(t),u=I.isLinear(i);return(h&&u?s:h||u?r:e)(t,i,n,a,o),o}}}}),k=e.extend({_class:"CurveLocation",initialize:function ge(t,e,i,n,r,s,a){this._id=ge._id=(ge._id||0)+1,this._curve=t,this._segment1=t._segment1,this._segment2=t._segment2,this._parameter=e,this._point=i,this._curve2=n,this._parameter2=r,this._point2=s,this._distance=a},getSegment:function(){if(!this._segment){var t=this.getCurve(),e=this.getParameter();if(1===e)this._segment=t._segment2;else if(0===e||arguments[0])this._segment=t._segment1;else{if(null==e)return null;this._segment=t.getLength(0,e)a;a++)s[a]=n[a].getValues();for(var a=0,o=i.length;o>a;a++)for(var h=i[a],u=h.getValues(),l=0;r>l;l++)I.getIntersections(u,s[l],h,n[l],e);return e},setPathData:function(t){function e(t,e,i){var r=parseFloat(n[t]);return a&&(r+=o[e]),i&&(o[e]=r),r}function i(t,i){return new h(e(t,"x",i),e(t+1,"y",i))}var n,r,s=t.match(/[mlhvcsqtaz][^mlhvcsqtaz]*/gi),a=!1,o=new h;this.clear();for(var u=0,l=s.length;l>u;u++){var c=s[u],d=c[0],_=d.toLowerCase();n=c.match(/[+-]?(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?/g);var f=n&&n.length;switch(a=d===_,_){case"m":case"l":for(var g=0;f>g;g+=2)this[0===g&&"m"===_?"moveTo":"lineTo"](i(g,!0));break;case"h":case"v":for(var v="h"==_?"x":"y",g=0;f>g;g++)e(g,v,!0),this.lineTo(o);break;case"c":for(var g=0;f>g;g+=6)this.cubicCurveTo(i(g),r=i(g+2),i(g+4,!0));break;case"s":for(var g=0;f>g;g+=4)this.cubicCurveTo(o.multiply(2).subtract(r),r=i(g),i(g+2,!0));break;case"q":for(var g=0;f>g;g+=4)this.quadraticCurveTo(r=i(g),i(g+2,!0));break;case"t":for(var g=0;f>g;g+=2)this.quadraticCurveTo(r=o.multiply(2).subtract(r),i(g,!0));break;case"a":break;case"z":this.closePath()}}},_canComposite:function(){return!(this.hasFill()&&this.hasStroke())},_contains:function(t){var e=this._getWinding(t);return!!("evenodd"===this.getWindingRule()?1&e:e)}}),O=A.extend({_class:"Path",_serializeFields:{segments:[],closed:!1},initialize:function(e){this._closed=!1,this._segments=[];var i=Array.isArray(e)?"object"==typeof e[0]?e:arguments:e&&(e.point!==t&&e.size===t||e.x!==t)?arguments:null;this.setSegments(i||[]),this._initialize(!i&&e)},_equals:function(t){return e.equals(this._segments,t._segments)},clone:function(e){var i=this._clone(new O({segments:this._segments,insert:!1}),e);return i._closed=this._closed,this._clockwise!==t&&(i._clockwise=this._clockwise),i},_changed:function ve(t){if(ve.base.call(this,t),4&t){if(delete this._length,delete this._clockwise,this._curves)for(var e=0,i=this._curves.length;i>e;e++)this._curves[e]._changed(5)}else 8&t&&delete this._bounds},getSegments:function(){return this._segments},setSegments:function(t){var e=this.isFullySelected();this._segments.length=0,this._selectedSegmentState=0,delete this._curves,this._add(z.readAll(t)),e&&this.setFullySelected(!0)},getFirstSegment:function(){return this._segments[0]},getLastSegment:function(){return this._segments[this._segments.length-1]},getCurves:function(){var t=this._curves,e=this._segments;if(!t){var i=this._countCurves();t=this._curves=Array(i);for(var n=0;i>n;n++)t[n]=new I(this,e[n],e[n+1]||e[0])}return t},getFirstCurve:function(){return this.getCurves()[0]},getLastCurve:function(){var t=this.getCurves();return t[t.length-1]},getPathData:function(){function t(t,e,s){var a=t._point,o=e._point,h=t._handleOut,u=e._handleIn;if(h.isZero()&&u.isZero())s||r.push("L"+n.point(o,i));else{var l=o.subtract(a);r.push("c"+n.point(h,i)+" "+n.point(l.add(u),i)+" "+n.point(l,i))}}var e=this._segments,i=arguments[0],n=a.instance,r=[];if(0===e.length)return"";r.push("M"+n.point(e[0]._point));for(var s=0,o=e.length-1;o>s;s++)t(e[s],e[s+1],!1);return this._closed&&(t(e[e.length-1],e[0],!0),r.push("z")),r.join("")},isClosed:function(){return this._closed},setClosed:function(t){if(this._closed!=(t=!!t)){if(this._closed=t,this._curves){var e=this._curves.length=this._countCurves();t&&(this._curves[e-1]=new I(this,this._segments[e-1],this._segments[0]))}this._changed(5)}},isEmpty:function(){return 0===this._segments.length},isPolygon:function(){for(var t=0,e=this._segments.length;e>t;t++)if(!this._segments[t].isLinear())return!1;return!0},_applyMatrix:function(t){for(var e=Array(6),i=0,n=this._segments.length;n>i;i++)this._segments[i]._transformCoordinates(t,e,!0);return!0},_add:function(t,e){for(var i=this._segments,n=this._curves,r=t.length,s=null==e,e=s?i.length:e,a=0;r>a;a++){var o=t[a];o._path&&(o=t[a]=o.clone()),o._path=this,o._index=e+a,o._selectionState&&this._updateSelection(o,0,o._selectionState)}if(s)i.push.apply(i,t);else{i.splice.apply(i,[e,0].concat(t));for(var a=e+r,h=i.length;h>a;a++)i[a]._index=a}if(n||t._curves){n||(n=this._curves=[]);var u=e>0?e-1:e,l=u,c=Math.min(u+r,this._countCurves());t._curves&&(n.splice.apply(n,[u,0].concat(t._curves)),l+=t._curves.length);for(var a=l;c>a;a++)n.splice(a,0,new I(this,null,null));this._adjustCurves(u,c)}return this._changed(5),t},_adjustCurves:function(t,e){for(var i,n=this._segments,r=this._curves,s=t;e>s;s++)i=r[s],i._path=this,i._segment1=n[s],i._segment2=n[s+1]||n[0];(i=r[this._closed&&0===t?n.length-1:t-1])&&(i._segment2=n[t]||n[0]),(i=r[e])&&(i._segment1=n[e])},_countCurves:function(){var t=this._segments.length;return!this._closed&&t>0?t-1:t},add:function(t){return arguments.length>1&&"number"!=typeof t?this._add(z.readAll(arguments)):this._add([z.read(arguments)])[0]},insert:function(t,e){return arguments.length>2&&"number"!=typeof e?this._add(z.readAll(arguments,1),t):this._add([z.read(arguments,1)],t)[0]},addSegment:function(){return this._add([z.read(arguments)])[0]},insertSegment:function(t){return this._add([z.read(arguments,1)],t)[0]},addSegments:function(t){return this._add(z.readAll(t))},insertSegments:function(t,e){return this._add(z.readAll(e),t)},removeSegment:function(t){return this.removeSegments(t,t+1)[0]||null},removeSegments:function(t,i){t=t||0,i=e.pick(i,this._segments.length);var n=this._segments,r=this._curves,s=n.length,a=n.splice(t,i-t),o=a.length;if(!o)return a;for(var h=0;o>h;h++){var u=a[h];u._selectionState&&this._updateSelection(u,u._selectionState,0),delete u._index,delete u._path}for(var h=t,l=n.length;l>h;h++)n[h]._index=h;if(r){var c=t>0&&i===s+(this._closed?1:0)?t-1:t,r=r.splice(c,o);arguments[2]&&(a._curves=r.slice(1)),this._adjustCurves(c,c)}return this._changed(5),a},clear:"#removeSegments",isFullySelected:function(){var t=this._segments.length;return this._selected&&t>0&&this._selectedSegmentState===4*t},setFullySelected:function(t){t&&this._selectSegments(!0),this.setSelected(t)},setSelected:function me(t){t||this._selectSegments(!1),me.base.call(this,t)},_selectSegments:function(t){var e=this._segments.length;this._selectedSegmentState=t?4*e:0;for(var i=0;e>i;i++)this._segments[i]._selectionState=t?4:0},_updateSelection:function(t,e,i){t._selectionState=i;var n=this._selectedSegmentState+=i-e;n>0&&this.setSelected(!0)},flatten:function(t){for(var e=new L(this),i=0,n=e.length/Math.ceil(e.length/t),r=e.length+(this._closed?-n:n)/2,s=[];r>=i;)s.push(new z(e.evaluate(i,0))),i+=n;this.setSegments(s)},simplify:function(t){if(this._segments.length>2){var e=new D(this,t||2.5);this.setSegments(e.fit())}},split:function(t,e){if(null!==e){if(1===arguments.length){var i=t;"number"==typeof i&&(i=this.getLocationAt(i)),t=i.index,e=i.parameter}e>=1&&(t++,e--);var n=this.getCurves();if(t>=0&&t0&&n[t++].divide(e,!0);var r,s=this.removeSegments(t,this._segments.length,!0);return this._closed?(this.setClosed(!1),r=this):t>0&&(r=this._clone((new O).insertAbove(this,!0))),r._add(s,0),this.addSegment(s[0]),r}return null}},isClockwise:function(){return this._clockwise!==t?this._clockwise:O.isClockwise(this._segments)},setClockwise:function(t){this.isClockwise()!=(t=!!t)&&this.reverse(),this._clockwise=t},reverse:function(){this._segments.reverse();for(var e=0,i=this._segments.length;i>e;e++){var n=this._segments[e],r=n._handleIn;n._handleIn=n._handleOut,n._handleOut=r,n._index=e}delete this._curves,this._clockwise!==t&&(this._clockwise=!this._clockwise)},join:function(t){if(t){var e=t._segments,i=this.getLastSegment(),n=t.getLastSegment();i._point.equals(n._point)&&t.reverse();var r,s=t.getFirstSegment();return i._point.equals(s._point)?(i.setHandleOut(s._handleOut),this._add(e.slice(1))):(r=this.getFirstSegment(),r._point.equals(s._point)&&t.reverse(),n=t.getLastSegment(),r._point.equals(n._point)?(r.setHandleIn(n._handleIn),this._add(e.slice(0,e.length-1),0)):this._add(e.slice())),t.closed&&this._add([e[0]]),t.remove(),r=this.getFirstSegment(),i=this.getLastSegment(),i._point.equals(r._point)&&(r.setHandleIn(i._handleIn),i.remove(),this.setClosed(!0)),this._changed(5),!0}return!1},getLength:function(){if(null==this._length){var t=this.getCurves();this._length=0;for(var e=0,i=t.length;i>e;e++)this._length+=t[e].getLength()}return this._length},getArea:function(){for(var t=this.getCurves(),e=0,i=0,n=t.length;n>i;i++)e+=t[i].getArea();return e},_getOffset:function(t){var e=t&&t.getIndex();if(null!=e){for(var i=this.getCurves(),n=0,r=0;e>r;r++)n+=i[r].getLength();var s=i[e];return n+s.getLength(0,t.getParameter())}return null},getLocationOf:function(t){t=h.read(arguments);for(var e=this.getCurves(),i=0,n=e.length;n>i;i++){var r=e[i].getLocationOf(t);if(r)return r}return null},getLocationAt:function(t,e){var i=this.getCurves(),n=0;if(e){var r=~~t;return i[r].getLocationAt(t-r,!0)}for(var s=0,a=i.length;a>s;s++){var o=n,h=i[s];if(n+=h.getLength(),n>=t)return h.getLocationAt(t-o)}return t<=this.getLength()?new k(i[i.length-1],1):null},getPointAt:function(t,e){var i=this.getLocationAt(t,e);return i&&i.getPoint()},getTangentAt:function(t,e){var i=this.getLocationAt(t,e);return i&&i.getTangent()},getNormalAt:function(t,e){var i=this.getLocationAt(t,e); +return i&&i.getNormal()},getNearestLocation:function(t){t=h.read(arguments);for(var e=this.getCurves(),i=1/0,n=null,r=0,s=e.length;s>r;r++){var a=e[r].getNearestLocation(t);a._distanceh;h++){var l=i[h].getValues(),c=l[0],d=l[1];(c!==l[2]||d!==l[3]||c!==l[4]||d!==l[5]||c!==l[6]||d!==l[7])&&(r+=I._getWinding(l,t.x,t.y,s,a))}return e||(r+=I._getWinding(o,t.x,t.y,s,a)),r},_hitTest:function(e,i){function n(i,n,r){return e.getDistance(n)s;s++)r+=I._getWinding(a(s),t.x,t.y,i,n);return!!r}function h(t){return("round"!==u||"round"!==l)&&(d=[],m||t._index>0&&t._index0)?o(e):e.getDistance(t._point)<=y}var u,l,c,d,_,f,g=this.getStyle(),v=this._segments,m=this._closed,p=i.tolerance,y=0,w=this;if(i.stroke&&(y=g.getStrokeWidth()/2,y>0?(u=g.getStrokeJoin(),l=g.getStrokeCap(),c=y*g.getMiterLimit()):u=l="round",y+=p),!i.ends||i.segments||m){if(i.segments||i.handles)for(var x=0,b=v.length;b>x;x++)if(f=r(v[x]))return f}else if(f=r(v[0],!0)||r(v[v.length-1],!0))return f;if(y>0){if(_=this.getNearestLocation(e)){var C=_.getParameter();0===C||1===C?h(_.getSegment())||(_=null):_._distance>y&&(_=null)}if(!_&&"miter"===u)for(var x=0,b=v.length;b>x;x++){var S=v[x];if(e.getDistance(S._point)<=c&&h(S)){_=S.getLocation();break}}}return!_&&i.fill&&this.hasFill()&&this.contains(e)?new P("fill",this):_?new P("stroke",this,{location:_}):null}},new function(){function t(t,e,i,n){function r(e){var i=a[e],n=a[e+1];(d!=i||_!=n)&&(t.beginPath(),t.moveTo(d,_),t.lineTo(i,n),t.stroke(),t.beginPath(),t.arc(i,n,s,0,2*Math.PI,!0),t.fill())}for(var s=n/2,a=Array(6),o=0,h=e.length;h>o;o++){var u=e[o];u._transformCoordinates(i,a,!1);var l=u._selectionState,c=4&l,d=a[0],_=a[1];(c||1&l)&&r(2),(c||2&l)&&r(4),t.save(),t.beginPath(),t.rect(d-s,_-s,n,n),t.fill(),c||(t.beginPath(),t.rect(d-s+1,_-s+1,n-2,n-2),t.fillStyle="#ffffff",t.fill()),t.restore()}}function e(t,e,i){function n(e){var n=d[e];if(i)n._transformCoordinates(i,f,!1),r=f[0],s=f[1];else{var _=n._point;r=_._x,s=_._y}if(g)t.moveTo(r,s),g=!1;else{if(i)h=f[2],u=f[3];else{var v=n._handleIn;h=r+v._x,u=s+v._y}h==r&&u==s&&l==a&&c==o?t.lineTo(r,s):t.bezierCurveTo(l,c,h,u,r,s)}if(a=r,o=s,i)l=f[4],c=f[5];else{var v=n._handleOut;l=a+v._x,c=o+v._y}}for(var r,s,a,o,h,u,l,c,d=e._segments,_=d.length,f=Array(6),g=!0,v=0;_>v;v++)n(v);e._closed&&_>1&&n(0)}return{_draw:function(t,i){function n(t){return u[(t%l+l)%l]}var r=i.clip,s=i.compound;s||t.beginPath();var a=this.getStyle(),o=a.hasFill(),h=a.hasStroke(),u=a.getDashArray(),l=!paper.support.nativeDash&&h&&u&&u.length;if((o||h&&!l||s||r)&&e(t,this),this._closed&&t.closePath(),!r&&!s&&(o||h)&&(this._setStyles(t),o&&(t.fill(a.getWindingRule()),t.shadowColor="rgba(0,0,0,0)"),h)){if(l){t.beginPath();var c,d=new L(this),_=d.length,f=-a.getDashOffset(),g=0;for(f%=_;f>0;)f-=n(g--)+n(g--);for(;_>f;)c=f+n(g++),(f>0||c>0)&&d.drawPart(t,Math.max(f,0),Math.max(c,0)),f=c+n(g++)}t.stroke()}},_drawSelected:function(i,n){i.beginPath(),e(i,this,n),i.stroke(),t(i,this._segments,n,this._project.options.handleSize||4)}}},new function(){function t(t){var e=t.length,i=[],n=[],r=2;i[0]=t[0]/r;for(var s=1;e>s;s++)n[s]=1/r,r=(e-1>s?4:2)-n[s],i[s]=(t[s]-i[s-1])/r;for(var s=1;e>s;s++)i[e-s-1]-=n[e-s]*i[e-s];return i}return{smooth:function(){var e,i=this._segments,n=i.length,r=n;if(!(2>=n)){this._closed?(e=Math.min(n,4),r+=2*Math.min(n,e)):e=0;for(var s=[],a=0;n>a;a++)s[a+e]=i[a]._point;if(this._closed)for(var a=0;e>a;a++)s[a]=i[a+n-e]._point,s[a+n+e]=i[a]._point;else r--;for(var o=[],a=1;r-1>a;a++)o[a]=4*s[a]._x+2*s[a+1]._x;o[0]=s[0]._x+2*s[1]._x,o[r-1]=3*s[r-1]._x;for(var u=t(o),a=1;r-1>a;a++)o[a]=4*s[a]._y+2*s[a+1]._y;o[0]=s[0]._y+2*s[1]._y,o[r-1]=3*s[r-1]._y;var l=t(o);if(this._closed){for(var a=0,c=n;e>a;a++,c++){var d=a/e,_=1-d,f=a+e,g=c+e;u[c]=u[a]*d+u[c]*_,l[c]=l[a]*d+l[c]*_,u[g]=u[f]*_+u[g]*d,l[g]=l[f]*_+l[g]*d}r--}for(var v=null,a=e;r-e>=a;a++){var m=i[a-e];v&&m.setHandleIn(v.subtract(m._point)),r>a&&(m.setHandleOut(new h(u[a],l[a]).subtract(m._point)),v=r-1>a?new h(2*s[a+1]._x-u[a+1],2*s[a+1]._y-l[a+1]):new h((s[r]._x+u[r-1])/2,(s[r]._y+l[r-1])/2))}if(this._closed&&v){var m=this._segments[0];m.setHandleIn(v.subtract(m._point))}}}}},new function(){function t(t){var e=t._segments;if(0==e.length)throw Error("Use a moveTo() command first");return e[e.length-1]}return{moveTo:function(){1===this._segments.length&&this.removeSegment(0),this._segments.length||this._add([new z(h.read(arguments))])},moveBy:function(){throw Error("moveBy() is unsupported on Path items.")},lineTo:function(){this._add([new z(h.read(arguments))])},cubicCurveTo:function(){var e=h.read(arguments),i=h.read(arguments),n=h.read(arguments),r=t(this);r.setHandleOut(e.subtract(r._point)),this._add([new z(n,i.subtract(n))])},quadraticCurveTo:function(){var e=h.read(arguments),i=h.read(arguments),n=t(this)._point;this.cubicCurveTo(e.add(n.subtract(e).multiply(1/3)),e.add(i.subtract(e).multiply(1/3)),i)},curveTo:function(){var i=h.read(arguments),n=h.read(arguments),r=e.pick(e.read(arguments),.5),s=1-r,a=t(this)._point,o=i.subtract(a.multiply(s*s)).subtract(n.multiply(r*r)).divide(2*r*s);if(o.isNaN())throw Error("Cannot put a curve through points with parameter = "+r);this.quadraticCurveTo(o,n)},arcTo:function(i,n){var r,s=t(this),a=s._point,o=h.read(arguments),u=e.pick(e.peek(arguments),!0);if("boolean"==typeof u){i=o,n=u;var l=a.add(i).divide(2),r=l.add(l.subtract(a).rotate(n?-90:90))}else r=o,i=h.read(arguments);var c=new v(a.add(r).divide(2),r.subtract(a).rotate(90),!0),d=new v(r.add(i).divide(2),i.subtract(r).rotate(90),!0),_=c.intersect(d,!0),f=new v(a,i),g=f.getSide(r);if(!_){if(!g)return this.lineTo(i);throw Error("Cannot put an arc through the given points: "+[a,r,i])}var m=a.subtract(_),p=m.getDirectedAngle(i.subtract(_)),y=f.getSide(_);0==y?p=g*Math.abs(p):g==y&&(p-=360*(0>p?-1:1));for(var w=Math.abs(p),x=w>=360?4:Math.ceil(w/90),b=p/x,C=b*Math.PI/360,S=4/3*Math.sin(C)/(1+Math.cos(C)),P=[],M=0;x>=M;M++){var I=x>M?_.add(m):i,k=x>M?m.rotate(90).multiply(S):null;0==M?s.setHandleOut(k):P.push(new z(I,m.rotate(-90).multiply(S),k)),m=m.rotate(b)}this._add(P)},lineBy:function(){var e=h.read(arguments),i=t(this)._point;this.lineTo(i.add(e))},curveBy:function(){var i=h.read(arguments),n=h.read(arguments),r=e.read(arguments),s=t(this)._point;this.curveTo(s.add(i),s.add(n),r)},cubicCurveBy:function(){var e=h.read(arguments),i=h.read(arguments),n=h.read(arguments),r=t(this)._point;this.cubicCurveTo(r.add(e),r.add(i),r.add(n))},quadraticCurveBy:function(){var e=h.read(arguments),i=h.read(arguments),n=t(this)._point;this.quadraticCurveTo(n.add(e),n.add(i))},arcBy:function(){var e=h.read(arguments),i=h.read(arguments),n=t(this)._point;this.arcTo(n.add(e),n.add(i))},closePath:function(){var t=this.getFirstSegment(),e=this.getLastSegment();t._point.equals(e._point)&&(t.setHandleIn(e._handleIn),e.remove()),this.setClosed(!0)}}},{_getBounds:function(t,e){return O[t](this._segments,this._closed,this.getStyle(),e)},statics:{isClockwise:function(t){for(var e=0,i=0,n=t.length;n>i;i++)for(var r=I.getValues(t[i],t[n>i+1?i+1:0]),s=2;8>s;s+=2)e+=(r[s-2]-r[s])*(r[s+1]+r[s-1]);return e>0},getBounds:function(t,e,i,n,r){function s(t){t._transformCoordinates(n,o,!1);for(var e=0;2>e;e++)I._addBounds(h[e],h[e+4],o[e+2],o[e],e,r?r[e]:0,u,l,c);var i=h;h=o,o=i}var a=t[0];if(!a)return new _;for(var o=Array(6),h=a._transformCoordinates(n,Array(6),!1),u=h.slice(0,2),l=u.slice(),c=Array(2),d=1,f=t.length;f>d;d++)s(t[d]);return e&&s(a),new _(u[0],u[1],l[0]-u[0],l[1]-u[1])},getStrokeBounds:function(t,e,i,n){function r(t,e){if(!e)return[t,t];var i=e.shiftless(),n=i.transform(new h(t,0)),r=i.transform(new h(0,t)),s=n.getAngleInRadians(),a=n.getLength(),o=r.getLength(),u=Math.sin(s),l=Math.cos(s),c=Math.tan(s),d=-Math.atan(o*c/a),_=Math.atan(o/(c*a));return[Math.abs(a*Math.cos(d)*l-o*Math.sin(d)*u),Math.abs(o*Math.sin(_)*l+a*Math.cos(_)*u)]}function s(t){f=f.include(n?n._transformPoint(t,t):t)}function a(t,e){"round"===e||!t._handleIn.isZero()&&!t._handleOut.isZero()?f=f.unite(p.setCenter(n?n._transformPoint(t._point):t._point)):O._addSquareJoin(t,e,l,m,s)}function o(t,e){switch(e){case"round":a(t,e);break;case"butt":case"square":O._addSquareCap(t,e,l,s)}}if(!i.hasStroke())return O.getBounds(t,e,i,n);for(var u=t.length-(e?0:1),l=i.getStrokeWidth()/2,d=r(l,n),f=O.getBounds(t,e,i,n,d),g=i.getStrokeJoin(),v=i.getStrokeCap(),m=l*i.getMiterLimit(),p=new _(new c(d).multiply(2)),y=1;u>y;y++)a(t[y],g);return e?a(t[0],g):(o(t[0],v),o(t[t.length-1],v)),f},_addSquareJoin:function(t,e,i,n,r,s){var a=t.getCurve(),o=a.getPrevious(),u=a.getPointAt(0,!0),l=o.getNormalAt(1,!0),c=a.getNormalAt(0,!0),d=l.getDirectedAngle(c)<0?-i:i;if(l.setLength(d),c.setLength(d),s&&(r(u),r(u.add(l))),"miter"===e){var _=new v(u.add(l),new h(-l.y,l.x),!0).intersect(new v(u.add(c),new h(-c.y,c.x),!0),!0);if(_&&u.getDistance(_)<=n&&(r(_),!s))return}s||r(u.add(l)),r(u.add(c))},_addSquareCap:function(t,e,i,n,r){var s=t._point,a=t.getLocation(),o=a.getNormal().normalize(i);r&&(n(s.subtract(o)),n(s.add(o))),"square"===e&&(s=s.add(o.rotate(0==a.getParameter()?-90:90))),n(s.add(o)),n(s.subtract(o))},getHandleBounds:function(t,e,i,n,r,s){var a=Array(6),o=1/0,h=-o,u=o,l=h;r=r/2||0,s=s/2||0;for(var c=0,d=t.length;d>c;c++){var f=t[c];f._transformCoordinates(n,a,!1);for(var g=0;6>g;g+=2){var v=0==g?s:r,m=a[g],p=a[g+1],y=m-v,w=m+v,x=p-v,b=p+v;o>y&&(o=y),w>h&&(h=w),u>x&&(u=x),b>l&&(l=b)}}return new _(o,u,h-o,l-u)},getRoughBounds:function(t,e,i,n){var r=i.getStrokeColor()?i.getStrokeWidth():0,s=r;return 0===r?r=1e-5:("miter"===i.getStrokeJoin()&&(s=r*i.getMiterLimit()),"square"===i.getStrokeCap()&&(s=Math.max(s,r*Math.sqrt(2)))),O.getHandleBounds(t,e,i,n,r,s)}}});O.inject({statics:new function(){function t(t,i,r){for(var s=new O,a=Array(4),o=0;4>o;o++){var h=n[o];a[o]=new z(h._point.multiply(i).add(t),h._handleIn.multiply(i),h._handleOut.multiply(i))}return s._add(a),s._closed=!0,s.set(e.getNamed(r))}var i=o.KAPPA,n=[new z([-1,0],[0,i],[0,-i]),new z([0,-1],[-i,0],[i,0]),new z([1,0],[0,-i],[0,i]),new z([0,1],[i,0],[-i,0])];return{Line:function(){return new O(h.readNamed(arguments,"from"),h.readNamed(arguments,"to")).set(e.getNamed(arguments))},Circle:function(){var i=h.readNamed(arguments,"center"),n=e.readNamed(arguments,"radius");return t(i,new c(n),arguments)},Rectangle:function(){var t=_.readNamed(arguments,"rectangle"),n=c.readNamed(arguments,"radius",0,0,{readNull:!0}),r=t.getBottomLeft(!0),s=t.getTopLeft(!0),a=t.getTopRight(!0),o=t.getBottomRight(!0);if(path=new O,!n||n.isZero())path._add([new z(r),new z(s),new z(a),new z(o)]);else{n=c.min(n,t.getSize(!0).divide(2));var h=n.width,u=n.height,l=h*i,d=u*i;path._add([new z(r.add(h,0),null,[-l,0]),new z(r.subtract(0,u),[0,d]),new z(s.add(0,u),null,[0,-d]),new z(s.add(h,0),[-l,0],null),new z(a.subtract(h,0),null,[l,0]),new z(a.add(0,u),[0,-d],null),new z(o.subtract(0,u),null,[0,d]),new z(o.subtract(h,0),[l,0])])}return path._closed=!0,path.set(e.getNamed(arguments))},RoundRectangle:"#Rectangle",Ellipse:function(){var e=b._readEllipse(arguments);return t(e.center,e.radius,arguments)},Oval:"#Ellipse",Arc:function(){var t=h.readNamed(arguments,"from"),i=h.readNamed(arguments,"through"),n=h.readNamed(arguments,"to"),r=new O;return r.moveTo(t),r.arcTo(i,n),r.set(e.getNamed(arguments))},RegularPolygon:function(){for(var t=h.readNamed(arguments,"center"),i=e.readNamed(arguments,"sides"),n=e.readNamed(arguments,"radius"),r=new O,s=360/i,a=!(i%3),o=new h(0,a?-n:n),u=a?-1:.5,l=Array(i),c=0;i>c;c++)l[c]=new z(t.add(o.rotate((c+u)*s)));return r._add(l),r._closed=!0,r.set(e.getNamed(arguments))},Star:function(){for(var t=h.readNamed(arguments,"center"),i=2*e.readNamed(arguments,"points"),n=e.readNamed(arguments,"radius1"),r=e.readNamed(arguments,"radius2"),s=new O,a=360/i,o=new h(0,-1),u=Array(i),l=0;i>l;l++)u[l]=new z(t.add(o.rotate(a*l).multiply(l%2?r:n)));return s._add(u),s._closed=!0,s.set(e.getNamed(arguments))}}}});var T=A.extend({_class:"CompoundPath",_serializeFields:{children:[]},initialize:function(t){this._children=[],this._namedChildren={},this._initialize(t)||this.addChildren(Array.isArray(t)?t:arguments)},insertChildren:function pe(e,i,n){i=pe.base.call(this,e,i,n,"path");for(var r=0,s=!n&&i&&i.length;s>r;r++){var a=i[r];a._clockwise===t&&a.setClockwise(0===a._index)}return i},reverse:function(){for(var t=this._children,e=0,i=t.length;i>e;e++)t[e].reverse()},smooth:function(){for(var t=0,e=this._children.length;e>t;t++)this._children[t].smooth()},isClockwise:function(){var t=this.getFirstChild();return t&&t.isClockwise()},setClockwise:function(t){this.isClockwise()!=!!t&&this.reverse()},getFirstSegment:function(){var t=this.getFirstChild();return t&&t.getFirstSegment()},getLastSegment:function(){var t=this.getLastChild();return t&&t.getLastSegment()},getCurves:function(){for(var t=this._children,e=[],i=0,n=t.length;n>i;i++)e=e.concat(t[i].getCurves());return e},getFirstCurve:function(){var t=this.getFirstChild();return t&&t.getFirstCurve()},getLastCurve:function(){var t=this.getLastChild();return t&&t.getFirstCurve()},getArea:function(){for(var t=this._children,e=0,i=0,n=t.length;n>i;i++)e+=t[i].getArea();return e},getPathData:function(){for(var t=this._children,e=[],i=0,n=t.length;n>i;i++)e.push(t[i].getPathData(arguments[0]));return e.join(" ")},_getWinding:function(t){for(var e=this._children,i=0,n=0,r=e.length;r>n;n++)i+=e[n]._getWinding(t);return i},_hitTest:function ye(t,i){var n=ye.base.call(this,t,e.merge(i,{fill:!1}));if(!n)if(i.compoundChildren)for(var r=this._children,s=r.length-1;s>=0&&!n;s--)n=r[s]._hitTest(t,i);else i.fill&&this.hasFill()&&this._contains(t)&&(n=new P("fill",this));return n},_draw:function(t,e){var i=this._children;if(0!==i.length){t.beginPath(),e=e.extend({compound:!0});for(var n=0,r=i.length;r>n;n++)i[n].draw(t,e);if(!e.clip){this._setStyles(t);var s=this._style;s.hasFill()&&(t.fill(s.getWindingRule()),t.shadowColor="rgba(0,0,0,0)"),s.hasStroke()&&t.stroke()}}}},new function(){function t(t){if(!t._children.length)throw Error("Use a moveTo() command first");return t._children[t._children.length-1]}var i={moveTo:function(){var t=new O;this.addChild(t),t.moveTo.apply(t,arguments)},moveBy:function(){this.moveTo(t(this).getLastSegment()._point.add(h.read(arguments)))},closePath:function(){t(this).closePath()}};return e.each(["lineTo","cubicCurveTo","quadraticCurveTo","curveTo","arcTo","lineBy","cubicCurveBy","quadraticCurveBy","curveBy","arcBy"],function(e){i[e]=function(){var i=t(this);i[e].apply(i,arguments)}}),i}),L=e.extend({initialize:function(t){function e(t,e){var i=I.getValues(t,e);s.curves.push(i),s._computeParts(i,t._index,0,1)}this.curves=[],this.parts=[],this.length=0,this.index=0;for(var i,n=t._segments,r=n[0],s=this,a=1,o=n.length;o>a;a++)i=n[a],e(r,i),r=i;t._closed&&e(i,n[0])},_computeParts:function(t,e,i,n){if(n-i>1/32&&!I.isFlatEnough(t,.25)){var r=I.subdivide(t),s=(i+n)/2;this._computeParts(r[0],e,i,s),this._computeParts(r[1],e,s,n)}else{var a=t[6]-t[0],o=t[7]-t[1],h=Math.sqrt(a*a+o*o);h>1e-5&&(this.length+=h,this.parts.push({offset:this.length,value:n,index:e}))}},getParameterAt:function(t){for(var e,i=this.index;e=i,!(0==i||this.parts[--i].offsete;e++){var r=this.parts[e];if(r.offset>=t){this.index=e;var s=this.parts[e-1],a=s&&s.index==r.index?s.value:0,o=s?s.offset:0;return{value:a+(r.value-a)*(t-o)/(r.offset-o),index:r.index}}}var r=this.parts[this.parts.length-1];return{value:1,index:r.index}},evaluate:function(t,e){var i=this.getParameterAt(t);return I.evaluate(this.curves[i.index],i.value,e)},drawPart:function(t,e,i){e=this.getParameterAt(e),i=this.getParameterAt(i);for(var n=e.index;n<=i.index;n++){var r=I.getPart(this.curves[n],n==e.index?e.value:0,n==i.index?i.value:1);n==e.index&&t.moveTo(r[0],r[1]),t.bezierCurveTo.apply(t,r.slice(2))}}}),D=e.extend({initialize:function(t,e){this.points=[];for(var i,n=t._segments,r=0,s=n.length;s>r;r++){var a=n[r].point.clone();i&&i.equals(a)||(this.points.push(a),i=a)}this.error=e},fit:function(){var t=this.points,e=t.length;return this.segments=e>0?[new z(t[0])]:[],e>1&&this.fitCubic(0,e-1,t[1].subtract(t[0]).normalize(),t[e-2].subtract(t[e-1]).normalize()),this.segments},fitCubic:function(e,i,n,r){if(1==i-e){var s=this.points[e],a=this.points[i],o=s.getDistance(a)/3;return this.addCurve([s,s.add(n.normalize(o)),a.add(r.normalize(o)),a]),t}for(var h,u=this.chordLengthParameterize(e,i),l=Math.max(this.error,this.error*this.error),c=0;4>=c;c++){var d=this.generateBezier(e,i,u,n,r),_=this.findMaxError(e,i,d,u);if(_.error=l)break;this.reparameterize(e,i,u,d),l=_.error}var f=this.points[h-1].subtract(this.points[h]),g=this.points[h].subtract(this.points[h+1]),v=f.add(g).divide(2).normalize();this.fitCubic(e,h,n,v),this.fitCubic(h,i,v.negate(),r)},addCurve:function(t){var e=this.segments[this.segments.length-1];e.setHandleOut(t[1].subtract(t[0])),this.segments.push(new z(t[3],t[2].subtract(t[3])))},generateBezier:function(t,e,i,n,r){for(var s=1e-11,a=this.points[t],o=this.points[e],h=[[0,0],[0,0]],u=[0,0],l=0,c=e-t+1;c>l;l++){var d=i[l],_=1-d,f=3*d*_,g=_*_*_,v=f*_,m=f*d,p=d*d*d,y=n.normalize(v),w=r.normalize(m),x=this.points[t+l].subtract(a.multiply(g+v)).subtract(o.multiply(m+p));h[0][0]+=y.dot(y),h[0][1]+=y.dot(w),h[1][0]=h[0][1],h[1][1]+=w.dot(w),u[0]+=y.dot(x),u[1]+=w.dot(x)}var b,C,S=h[0][0]*h[1][1]-h[1][0]*h[0][1];if(Math.abs(S)>s){var P=h[0][0]*u[1]-h[1][0]*u[0],z=u[0]*h[1][1]-u[1]*h[0][1];b=z/S,C=P/S}else{var M=h[0][0]+h[0][1],I=h[1][0]+h[1][1];b=C=Math.abs(M)>s?u[0]/M:Math.abs(I)>s?u[1]/I:0}var k=o.getDistance(a);return s*=k,(s>b||s>C)&&(b=C=k/3),[a,a.add(n.normalize(b)),o.add(r.normalize(C)),o]},reparameterize:function(t,e,i,n){for(var r=t;e>=r;r++)i[r-t]=this.findRoot(n,this.points[r],i[r-t])},findRoot:function(t,e,i){for(var n=[],r=[],s=0;2>=s;s++)n[s]=t[s+1].subtract(t[s]).multiply(3);for(var s=0;1>=s;s++)r[s]=n[s+1].subtract(n[s]).multiply(2);var a=this.evaluate(3,t,i),o=this.evaluate(2,n,i),h=this.evaluate(1,r,i),u=a.subtract(e),l=o.dot(o)+u.dot(h);return Math.abs(l)<1e-5?i:i-u.dot(o)/l},evaluate:function(t,e,i){for(var n=e.slice(),r=1;t>=r;r++)for(var s=0;t-r>=s;s++)n[s]=n[s].multiply(1-i).add(n[s+1].multiply(i));return n[0]},chordLengthParameterize:function(t,e){for(var i=[0],n=t+1;e>=n;n++)i[n-t]=i[n-t-1]+this.points[n].getDistance(this.points[n-1]);for(var n=1,r=e-t;r>=n;n++)i[n]/=i[r];return i},findMaxError:function(t,e,i,n){for(var r=Math.floor((e-t+1)/2),s=0,a=t+1;e>a;a++){var o=this.evaluate(3,i,n[a-t]),h=o.subtract(this.points[a]),u=h.x*h.x+h.y*h.y;u>=s&&(s=u,r=a)}return{error:s,index:r}}});A.inject(new function(){function t(t,e){t.sort(function(t,e){var i=t.getPath(),n=e.getPath();return i===n?t.getIndex()+t.getParameter()-(e.getIndex()+e.getParameter()):i._id-n._id});for(var i=e&&[],n=t.length-1;n>=0;n--){var r=t[n],s=r.getIntersection(),a=r.divide(),o=a&&a.getSegment1()||r.getSegment();i&&i.push(s),o._intersection=s,r._segment=o}return i}function e(t){if(t instanceof T){for(var e=t._children,i=e.length,n=Array(i),r=Array(i),s=e[0].isClockwise(),a=0;i>a;a++)n[a]=e[a].getBounds(),r[a]=0;for(var a=0;i>a;a++){for(var o=1;i>o;o++)a!==o&&n[a].contains(n[o])&&r[o]++;a>0&&0===r[a]%2&&e[a].setClockwise(s)}}return t}function i(i,r,s,a){i=e(i.clone(!1)),r=e(r.clone(!1));var o=i.isClockwise(),u=r.isClockwise(),l=i.getIntersections(r);t(t(l,!0)),o||i.reverse(),a^u||r.reverse(),o=!0,u=!a;for(var c=[].concat(i._children||[i]).concat(r._children||[r]),d=[],_=new T,f=0,g=c.length;g>f;f++){var v=c[f],m=v._parent,p=v.isClockwise(),y=v._segments;v=m instanceof T?m:v;for(var w=y.length-1;w>=0;w--){var x=y[w],b=x.getCurve().getPoint(.5),C=v!==i&&i.contains(b)&&(p===o||a||!n(i,b)),S=v!==r&&r.contains(b)&&(p===u||!n(r,b));s(v===i,C,S)?x._invalid=!0:d.push(x)}}for(var f=0,g=d.length;g>f;f++){var x=d[f];if(!x._visited){var v=new O,P=x._intersection,M=P&&P.getSegment(!0);x.getPrevious()._invalid&&x.setHandleIn(M?M._handleIn:new h(0,0));do{if(x._visited=!0,x._invalid&&x._intersection){var I=x._intersection.getSegment(!0);v.add(new z(x._point,x._handleIn,I._handleOut)),I._visited=!0,x=I}else v.add(x.clone());x=x.getNext()}while(x&&!x._visited&&x!==M);var k=v._segments.length;k>1&&(k>2||!v.isPolygon())?(v.setClosed(!0),_.addChild(v,!0)):v.remove()}}return i.remove(),r.remove(),_.reduce()}function n(t,e){var i=t.getCurves(),n=t.getBounds();if(n.contains(e))for(var r=0,s=i.length;s>r;r++){var a=i[r];if(a.getBounds().contains(e)&&a.getParameterOf(e))return!0}return!1}return{unite:function(t){return i(this,t,function(t,e,i){return e||i})},intersect:function(t){return i(this,t,function(t,e,i){return!(e||i)})},subtract:function(t){return i(this,t,function(t,e,i){return t&&i||!t&&!e},!0)},exclude:function(t){return new w([this.subtract(t),t.subtract(this)])},divide:function(t){return new w([this.subtract(t),this.intersect(t)])}}});var j=y.extend({_class:"TextItem",_boundsSelected:!0,_serializeFields:{content:null},_boundsGetter:"getBounds",initialize:function(i){this._content="",this._lines=[];var n=i&&e.isPlainObject(i)&&i.x===t&&i.y===t;this._initialize(n&&i,!n&&h.read(arguments))},_equals:function(t){return this._content===t._content},_clone:function we(t){return t.setContent(this._content),we.base.call(this,t)},getContent:function(){return this._content},setContent:function(t){this._content=""+t,this._lines=this._content.split(/\r\n|\n|\r/gm),this._changed(69)},isEmpty:function(){return!this._content},getCharacterStyle:"#getStyle",setCharacterStyle:"#setStyle",getParagraphStyle:"#getStyle",setParagraphStyle:"#setStyle"}),B=j.extend({_class:"PointText",initialize:function(){j.apply(this,arguments)},clone:function(t){return this._clone(new B({insert:!1}),t)},getPoint:function(){var t=this._matrix.getTranslation();return new u(t.x,t.y,this,"setPoint")},setPoint:function(t){t=h.read(arguments),this.translate(t.subtract(this._matrix.getTranslation()))},_draw:function(t){if(this._content){this._setStyles(t);var e=this._style,i=this._lines,n=e.getLeading(),r=t.shadowColor;t.font=e.getFontStyle(),t.textAlign=e.getJustification();for(var s=0,a=i.length;a>s;s++){t.shadowColor=r;var o=i[s];e.hasFill()&&(t.fillText(o,0,0),t.shadowColor="rgba(0,0,0,0)"),e.hasStroke()&&t.strokeText(o,0,0),t.translate(0,n)}}}},new function(){var t=null;return{_getBounds:function(e,i){t||(t=K.getContext(1,1));var n=this._style,r=this._lines,s=r.length,a=n.getJustification(),o=n.getLeading(),h=0;t.font=n.getFontStyle();for(var u=0,l=0;s>l;l++)u=Math.max(u,t.measureText(r[l]).width);"left"!==a&&(h-=u/("center"===a?2:1));var c=new _(h,s?-.75*o:0,u,s*o);return i?i._transformBounds(c,c):c}}}),N=e.extend(new function(){function t(t){var e=o[t];if(!e){n||(n=K.getContext(1,1),n.globalCompositeOperation="copy"),n.fillStyle="rgba(0,0,0,0)",n.fillStyle=t,n.fillRect(0,0,1,1);var i=n.getImageData(0,0,1,1).data;e=o[t]=[i[0]/255,i[1]/255,i[2]/255]}return e.slice()}function i(t){var e=t.match(/^#?(\w{1,2})(\w{1,2})(\w{1,2})$/);if(e.length>=4){for(var i=[0,0,0],n=0;3>n;n++){var r=e[n+1];i[n]=parseInt(1==r.length?r+r:r,16)/255}return i}}var n,r={gray:["gray"],rgb:["red","green","blue"],hsb:["hue","saturation","brightness"],hsl:["hue","saturation","lightness"],gradient:["gradient","origin","destination","highlight"]},s={},o={},u=[[0,3,1],[2,0,1],[1,0,3],[1,2,0],[3,1,0],[0,1,2]],l={"rgb-hsb":function(t,e,i){var n=Math.max(t,e,i),r=Math.min(t,e,i),s=n-r,a=0===s?0:60*(n==t?(e-i)/s+(i>e?6:0):n==e?(i-t)/s+2:(t-e)/s+4);return[a,0===n?0:s/n,n]},"hsb-rgb":function(t,e,i){var t=t/60%6,n=Math.floor(t),r=t-n,n=u[n],s=[i,i*(1-e),i*(1-e*r),i*(1-e*(1-r))];return[s[n[0]],s[n[1]],s[n[2]]]},"rgb-hsl":function(t,e,i){var n=Math.max(t,e,i),r=Math.min(t,e,i),s=n-r,a=0===s,o=a?0:60*(n==t?(e-i)/s+(i>e?6:0):n==e?(i-t)/s+2:(t-e)/s+4),h=(n+r)/2,u=a?0:.5>h?s/(n+r):s/(2-n-r);return[o,u,h]},"hsl-rgb":function(t,e,i){if(t/=360,0===e)return[i,i,i];for(var n=[t+1/3,t,t-1/3],r=.5>i?i*(1+e):i+e-i*e,s=2*i-r,a=[],o=0;3>o;o++){var h=n[o];0>h&&(h+=1),h>1&&(h-=1),a[o]=1>6*h?s+6*(r-s)*h:1>2*h?r:2>3*h?s+6*(r-s)*(2/3-h):s}return a},"rgb-gray":function(t,e,i){return[.2989*t+.587*e+.114*i]},"gray-rgb":function(t){return[t,t,t]},"gray-hsb":function(t){return[0,0,t]},"gray-hsl":function(t){return[0,0,t]},"gradient-rgb":function(){return[]},"rgb-gradient":function(){return[]}};return e.each(r,function(t,i){s[i]=[],e.each(t,function(t,n){var a=e.capitalize(t),o=/^(hue|saturation)$/.test(t),u=s[i][n]="gradient"===t?function(t){var e=this._components[0];return t=q.read(Array.isArray(t)?t:arguments,0,0,{readNull:!0}),e!==t&&(e&&e._removeOwner(this),t&&t._addOwner(this)),t}:"hue"===t?function(t){return isNaN(t)?0:(t%360+360)%360}:"gradient"===i?function(){return h.read(arguments,0,0,{readNull:"highlight"===t,clone:!0})}:function(t){return isNaN(t)?0:Math.min(Math.max(t,0),1)};this["get"+a]=function(){return this._type===i||o&&/^hs[bl]$/.test(this._type)?this._components[n]:this._convert(i)[n]},this["set"+a]=function(t){this._type===i||o&&/^hs[bl]$/.test(this._type)||(this._components=this._convert(i),this._properties=r[i],this._type=i),t=u.call(this,t),null!=t&&(this._components[n]=t,this._changed())}},this)},{_class:"Color",_readIndex:!0,initialize:function c(e){var n,a,o,h,u=Array.prototype.slice,l=arguments,d=0,_=!0;Array.isArray(e)&&(l=e,e=l[0]);var f=null!=e&&typeof e;if("string"===f&&e in r&&(n=e,e=l[1],Array.isArray(e)?(a=e,o=l[2]):(this.__read&&(d=1),l=u.call(l,1),f=typeof e)),!a){if(_=!(this.__options&&this.__options.dontParse),h="number"===f?l:"object"===f&&null!=e.length?e:null){n||(n=h.length>=3?"rgb":"gray");var g=r[n].length;o=h[g],this.__read&&(d+=h===arguments?g+(null!=o?1:0):1),h.length>g&&(h=u.call(h,0,g))}else if("string"===f)a=e.match(/^#[0-9a-f]{3,6}$/i)?i(e):t(e),n="rgb";else if("object"===f)if(e.constructor===c){if(n=e._type,a=e._components.slice(),o=e._alpha,"gradient"===n)for(var v=1,m=a.length;m>v;v++){var p=a[v];p&&(a[v]=p.clone())}}else if(e.constructor===q)n="gradient",h=l;else{n="hue"in e?"lightness"in e?"hsl":"hsb":"gradient"in e||"stops"in e||"radial"in e?"gradient":"gray"in e?"gray":"rgb";var y=r[n];x=_&&s[n],this._components=a=[];for(var v=0,m=y.length;m>v;v++){var w=e[y[v]];null==w&&0===v&&"gradient"===n&&"stops"in e&&(w={stops:e.stops,radial:e.radial}),_&&(w=x[v].call(this,w)),null!=w&&(a[v]=w)}o=e.alpha}this.__read&&n&&(d=1)}if(this._type=n||"rgb","gradient"===n&&(this._id=c._id=(c._id||0)+1),!a){this._components=a=[];for(var x=s[this._type],v=0,m=x.length;m>v;v++){var w=h&&h[v];_&&(w=x[v].call(this,w)),null!=w&&(a[v]=w)}}this._components=a,this._properties=r[this._type],this._alpha=o,this.__read&&(this.__read=d)},_serialize:function(t,i){var n=this.getComponents();return e.serialize(/^(gray|rgb)$/.test(this._type)?n:[this._type].concat(n),t,!0,i)},_changed:function(){this._canvasStyle=null,this._owner&&this._owner._changed(17)},clone:function(){return new N(this)},_convert:function(t){var e;return this._type===t?this._components.slice():(e=l[this._type+"-"+t])?e.apply(this,this._components):l["rgb-"+t].apply(this,l[this._type+"-rgb"].apply(this,this._components))},convert:function(t){return new N(t,this._convert(t),this._alpha)},getType:function(){return this._type},setType:function(t){this._components=this._convert(t),this._properties=r[t],this._type=t},getComponents:function(){var t=this._components.slice();return null!=this._alpha&&t.push(this._alpha),t},getAlpha:function(){return null!=this._alpha?this._alpha:1},setAlpha:function(t){this._alpha=null==t?null:Math.min(Math.max(t,0),1),this._changed()},hasAlpha:function(){return null!=this._alpha},equals:function(t){return e.isPlainValue(t)&&(t=N.read(arguments)),t===this||t&&this._class===t._class&&this._type===t._type&&this._alpha===t._alpha&&e.equals(this._components,t._components)||!1},toString:function(){for(var t=this._properties,e=[],i="gradient"===this._type,n=a.instance,r=0,s=t.length;s>r;r++){var o=this._components[r];null!=o&&e.push(t[r]+": "+(i?o:n.number(o)))}return null!=this._alpha&&e.push("alpha: "+n.number(this._alpha)),"{ "+e.join(", ")+" }"},toCSS:function(t){var e=this._convert("rgb"),i=t||null==this._alpha?1:this._alpha;return e=[Math.round(255*e[0]),Math.round(255*e[1]),Math.round(255*e[2])],1>i&&e.push(i),(4==e.length?"rgba(":"rgb(")+e.join(",")+")"},toCanvasStyle:function(t){if(this._canvasStyle)return this._canvasStyle;if("gradient"!==this._type)return this._canvasStyle=this.toCSS();var e,i=this._components,n=i[0],r=n._stops,s=i[1],a=i[2];if(n._radial){var o=a.getDistance(s),h=i[3];if(h){var u=h.subtract(s);u.getLength()>o&&(h=s.add(u.normalize(o-.1)))}var l=h||s;e=t.createRadialGradient(l.x,l.y,0,s.x,s.y,o)}else e=t.createLinearGradient(s.x,s.y,a.x,a.y);for(var c=0,d=r.length;d>c;c++){var _=r[c];e.addColorStop(_._rampPoint,_._color.toCanvasStyle())}return this._canvasStyle=e},transform:function(t){if("gradient"===this._type){for(var e=this._components,i=1,n=e.length;n>i;i++){var r=e[i];t._transformPoint(r,r,!0)}this._changed()}},statics:{_types:r,random:function(){var t=Math.random;return new N(t(),t(),t())}}})},new function(){function t(t,e){return 0>t?0:e&&t>360?360:!e&&t>1?1:t}var i={add:function(e,i,n){return t(e+i,n)},subtract:function(e,i,n){return t(e-i,n)},multiply:function(e,i,n){return t(e*i,n)},divide:function(e,i,n){return t(e/i,n)}};return e.each(i,function(t,e){var i={dontParse:/^(multiply|divide)$/.test(e)};this[e]=function(e){e=N.read(arguments,0,0,i);for(var n=this._type,r=this._properties,s=this._components,a=e._convert(n),o=0,h=s.length;h>o;o++)a[o]=t(s[o],a[o],"hue"===r[o]);return new N(n,a,null!=this._alpha?t(this._alpha,e.getAlpha()):null)}},{})});e.each(N._types,function(t,i){var n=this[e.capitalize(i)+"Color"]=function(t){var e=null!=t&&typeof t,n="object"===e&&null!=t.length?t:"string"===e?null:arguments;return n?new N(i,n):new N(t)};if(3==i.length){var r=i.toUpperCase();N[r]=this[r+"Color"]=n}},e.exports);var q=e.extend({_class:"Gradient",initialize:function xe(t,e){this._id=xe._id=(xe._id||0)+1,t&&this._set(t)&&(t=e=null),this._stops||this.setStops(t||["white","black"]),null==this._radial&&this.setRadial("string"==typeof e&&"radial"===e||e||!1) +},_serialize:function(t,i){return i.add(this,function(){return e.serialize([this._stops,this._radial],t,!0,i)})},_changed:function(){for(var t=0,e=this._owners&&this._owners.length;e>t;t++)this._owners[t]._changed()},_addOwner:function(t){this._owners||(this._owners=[]),this._owners.push(t)},_removeOwner:function(t){var e=this._owners?this._owners.indexOf(t):-1;-1!=e&&(this._owners.splice(e,1),0===this._owners.length&&delete this._owners)},clone:function(){for(var t=[],e=0,i=this._stops.length;i>e;e++)t[e]=this._stops[e].clone();return new this.constructor(t)},getStops:function(){return this._stops},setStops:function(t){if(this.stops)for(var e=0,i=this._stops.length;i>e;e++)delete this._stops[e]._owner;if(t.length<2)throw Error("Gradient stop list needs to contain at least two stops.");this._stops=F.readAll(t,0,!1,!0);for(var e=0,i=this._stops.length;i>e;e++){var n=this._stops[e];n._owner=this,n._defaultRamp&&n.setRampPoint(e/(i-1))}this._changed()},getRadial:function(){return this._radial},setRadial:function(t){this._radial=t,this._changed()},equals:function(t){if(t===this)return!0;if(t&&this._class===t._class&&this._stops.length===t._stops.length){for(var e=0,i=this._stops.length;i>e;e++)if(!this._stops[e].equals(t._stops[e]))return!1;return!0}return!1}}),F=e.extend({_class:"GradientStop",initialize:function(e,i){if(e){var n,r;i===t&&Array.isArray(e)?(n=e[0],r=e[1]):e.color?(n=e.color,r=e.rampPoint):(n=e,r=i),this.setColor(n),this.setRampPoint(r)}},clone:function(){return new F(this._color.clone(),this._rampPoint)},_serialize:function(t,i){return e.serialize([this._color,this._rampPoint],t,!0,i)},_changed:function(){this._owner&&this._owner._changed(17)},getRampPoint:function(){return this._rampPoint},setRampPoint:function(t){this._defaultRamp=null==t,this._rampPoint=t||0,this._changed()},getColor:function(){return this._color},setColor:function(t){this._color=N.read(arguments),this._color===t&&(this._color=t.clone()),this._color._owner=this,this._changed()},equals:function(t){return t===this||t&&this._class===t._class&&this._color.equals(t._color)&&this._rampPoint==t._rampPoint||!1}}),E=e.extend(new function(){var i={fillColor:t,strokeColor:t,strokeWidth:1,strokeCap:"butt",strokeJoin:"miter",miterLimit:10,dashOffset:0,dashArray:[],windingRule:"nonzero",shadowColor:t,shadowBlur:0,shadowOffset:new h,selectedColor:t,font:"sans-serif",fontSize:12,leading:null,justification:"left"},n={strokeWidth:25,strokeCap:25,strokeJoin:25,miterLimit:25,font:5,fontSize:5,leading:5,justification:5},r={},s={_defaults:i,_textDefaults:e.merge(i,{fillColor:new N})};return e.each(i,function(i,a){var o=/Color$/.test(a),h=e.capitalize(a),u=n[a],l="set"+h,c="get"+h;s[l]=function(t){var e=this._item&&this._item._children;if(e&&e.length>0&&"compound-path"!==this._item._type)for(var i=0,n=e.length;n>i;i++)e[i]._style[l](t);else{var r=this._values[a];r!=t&&(o&&(r&&delete r._owner,t&&t.constructor===N&&(t._owner&&(t=t.clone()),t._owner=this._item)),this._values[a]=t,this._item&&this._item._changed(u||17))}},s[c]=function(){var i,n=this._item&&this._item._children;if(!n||0===n.length||arguments[0]||"compound-path"===this._item._type){var i=this._values[a];return i===t?(i=this._defaults[a],i&&i.clone&&(i=i.clone()),this._values[a]=i):!o||i&&i.constructor===N||(this._values[a]=i=N.read([i],0,0,{readNull:!0,clone:!0}),i&&(i._owner=this._item)),i}for(var r=0,s=n.length;s>r;r++){var h=n[r]._style[c]();if(0===r)i=h;else if(!e.equals(i,h))return t}return i},r[c]=function(){return this._style[c]()},r[l]=function(t){this._style[l](t)}}),y.inject(r),s},{_class:"Style",initialize:function(t,e){this._values={},this._item=e,e instanceof j&&(this._defaults=this._textDefaults),t&&this.set(t)},set:function(t){var e=t instanceof E,i=e?t._values:t;if(i)for(var n in i)if(n in this._defaults){var r=i[n];this[n]=r&&e&&r.clone?r.clone():r}},equals:function(t){return t===this||t&&this._class===t._class&&e.equals(this._values,t._values)||!1},hasFill:function(){return!!this.getFillColor()},hasStroke:function(){return!!this.getStrokeColor()&&this.getStrokeWidth()>0},hasShadow:function(){return!!this.getShadowColor()&&this.getShadowBlur()>0},getLeading:function be(){var t=be.base.call(this);return null!=t?t:1.2*this.getFontSize()},getFontStyle:function(){var t=this.getFontSize();return t+(/[a-z]/i.test(t+"")?" ":"px ")+this.getFont()}}),R=new function(){function i(t,n){for(var r=[],s=0,a=t&&t.length;a>s;){var o=t[s++];if("string"==typeof o)o=document.createElement(o);else if(!o||!o.nodeType)continue;e.isPlainObject(t[s])&&R.set(o,t[s++]),Array.isArray(t[s])&&i(t[s++],o),n&&n.appendChild(o),r.push(o)}return r}var n=/^(checked|value|selected|disabled)$/i,r={text:"textContent",html:"innerHTML"},s={lineHeight:1,zoom:1,zIndex:1,opacity:1};return{create:function(t,e){var n=Array.isArray(t),r=i(n?t:arguments,n?e:null);return 1==r.length?r[0]:r},find:function(t,e){return(e||document).querySelector(t)},findAll:function(t,e){return(e||document).querySelectorAll(t)},get:function(t,e){return t?n.test(e)?"value"===e||"string"!=typeof t[e]?t[e]:!0:e in r?t[r[e]]:t.getAttribute(e):null},set:function(e,i,s){if("string"!=typeof i)for(var a in i)i.hasOwnProperty(a)&&this.set(e,a,i[a]);else{if(!e||s===t)return e;n.test(i)?e[i]=s:i in r?e[r[i]]=s:"style"===i?this.setStyle(e,s):"events"===i?V.add(e,s):e.setAttribute(i,s)}return e},getStyles:function(t){var e=t&&9!==t.nodeType?t.ownerDocument:t,i=e&&e.defaultView;return i&&i.getComputedStyle(t,"")},getStyle:function(t,e){return t&&t.style[e]||this.getStyles(t)[e]||null},setStyle:function(t,e,i){if("string"!=typeof e)for(var n in e)e.hasOwnProperty(n)&&this.setStyle(t,n,e[n]);else!/^-?[\d\.]+$/.test(i)||e in s||(i+="px"),t.style[e]=i;return t},hasClass:function(t,e){return RegExp("\\s*"+e+"\\s*").test(t.className)},addClass:function(t,e){t.className=(t.className+" "+e).trim()},removeClass:function(t,e){t.className=t.className.replace(RegExp("\\s*"+e+"\\s*")," ").trim()},remove:function(t){t.parentNode&&t.parentNode.removeChild(t)},removeChildren:function(t){for(;t.firstChild;)t.removeChild(t.firstChild)},getBounds:function(t,e){var i,n=t.ownerDocument,r=n.body,s=n.documentElement;try{i=t.getBoundingClientRect()}catch(a){i={left:0,top:0,width:0,height:0}}var o=i.left-(s.clientLeft||r.clientLeft||0),h=i.top-(s.clientTop||r.clientTop||0);if(!e){var u=n.defaultView;o+=u.pageXOffset||s.scrollLeft||r.scrollLeft,h+=u.pageYOffset||s.scrollTop||r.scrollTop}return new _(o,h,i.width,i.height)},getViewportBounds:function(t){var e=t.ownerDocument,i=e.defaultView,n=e.documentElement;return new _(0,0,i.innerWidth||n.clientWidth,i.innerHeight||n.clientHeight)},getOffset:function(t,e){return this.getBounds(t,e).getPoint()},getSize:function(t){return this.getBounds(t,!0).getSize()},isInvisible:function(t){return this.getSize(t).equals(new c(0,0))},isInView:function(t){return!this.isInvisible(t)&&this.getViewportBounds(t).intersects(this.getBounds(t,!0))},getPrefixValue:function(t,e){for(var i=t[e],n=["webkit","moz","ms","o"],r=e[0].toUpperCase()+e.substring(1),s=0;4>s&&null==i;s++)i=t[n[s]+r];return i}}},V={add:function(t,e){for(var i in e){var n=e[i];t.addEventListener?t.addEventListener(i,n,!1):t.attachEvent&&t.attachEvent("on"+i,n.bound=function(){n.call(t,window.event)})}},remove:function(t,e){for(var i in e){var n=e[i];t.removeEventListener?t.removeEventListener(i,n,!1):t.detachEvent&&t.detachEvent("on"+i,n.bound)}},getPoint:function(t){var e=t.targetTouches?t.targetTouches.length?t.targetTouches[0]:t.changedTouches[0]:t;return new h(e.pageX||e.clientX+document.documentElement.scrollLeft,e.pageY||e.clientY+document.documentElement.scrollTop)},getTarget:function(t){return t.target||t.srcElement},getOffset:function(t,e){return V.getPoint(t).subtract(R.getOffset(e||V.getTarget(t)))},preventDefault:function(t){t.preventDefault?t.preventDefault():t.returnValue=!1},stopPropagation:function(t){t.stopPropagation?t.stopPropagation():t.cancelBubble=!0},stop:function(t){V.stopPropagation(t),V.preventDefault(t)}};V.requestAnimationFrame=new function(){function t(){for(var e=s.length-1;e>=0;e--){var o=s[e],h=o[0],u=o[1];(!u||("true"==r.getAttribute(u,"keepalive")||a)&&R.isInView(u))&&(s.splice(e,1),h())}i&&(s.length?i(t):n=!1)}var e,i=R.getPrefixValue(window,"requestAnimationFrame"),n=!1,s=[],a=!0;return V.add(window,{focus:function(){a=!0},blur:function(){a=!1}}),function(r,a){s.push([r,a]),i?n||(i(t),n=!0):e||(e=setInterval(t,1e3/60))}};var Z=e.extend(n,{_class:"View",initialize:function Ce(t){this._scope=paper,this._project=paper.project,this._element=t;var e;if(this._id=t.getAttribute("id"),null==this._id&&t.setAttribute("id",this._id="view-"+Ce._id++),V.add(t,this._viewHandlers),r.hasAttribute(t,"resize")){var i=R.getOffset(t,!0),n=this;e=R.getViewportBounds(t).getSize().subtract(i),this._windowHandlers={resize:function(){R.isInvisible(t)||(i=R.getOffset(t,!0)),n.setViewSize(R.getViewportBounds(t).getSize().subtract(i))}},V.add(window,this._windowHandlers)}else e=new c(parseInt(t.getAttribute("width"),10),parseInt(t.getAttribute("height"),10)),e.isNaN()&&(e=R.getSize(t));if(t.width=e.width,t.height=e.height,r.hasAttribute(t,"stats")&&"object"==typeof Stats){this._stats=new Stats;var s=this._stats.domElement,a=s.style,i=R.getOffset(t);a.position="absolute",a.left=i.x+"px",a.top=i.y+"px",document.body.appendChild(s)}Ce._views.push(this),Ce._viewsById[this._id]=this,this._viewSize=new d(e.width,e.height,this,"setViewSize"),this._matrix=new g,this._zoom=1,Ce._focused||(Ce._focused=this),this._frameItems={},this._frameItemCount=0},remove:function(){return this._project?(Z._focused==this&&(Z._focused=null),Z._views.splice(Z._views.indexOf(this),1),delete Z._viewsById[this._id],this._project.view==this&&(this._project.view=null),V.remove(this._element,this._viewHandlers),V.remove(window,this._windowHandlers),this._element=this._project=null,this.detach("frame"),this._frameItems={},!0):!1},_events:{onFrame:{install:function(){this._requested||(this._animate=!0,this._requestFrame())},uninstall:function(){this._animate=!1}},onResize:{}},_animate:!1,_time:0,_count:0,_requestFrame:function(){var t=this;V.requestAnimationFrame(function(){t._requested=!1,t._animate&&(t._requestFrame(),t._handleFrame())},this._element),this._requested=!0},_handleFrame:function(){paper=this._scope;var t=Date.now()/1e3,i=this._before?t-this._before:0;this._before=t,this._handlingFrame=!0,this.fire("frame",e.merge({delta:i,time:this._time+=i,count:this._count++})),this._stats&&this._stats.update(),this._handlingFrame=!1,this.draw(!0)},_animateItem:function(t,e){var i=this._frameItems;e?(i[t._id]={item:t,time:0,count:0},1===++this._frameItemCount&&this.attach("frame",this._handleFrameItems)):(delete i[t._id],0===--this._frameItemCount&&this.detach("frame",this._handleFrameItems))},_handleFrameItems:function(t){for(var i in this._frameItems){var n=this._frameItems[i];n.item.fire("frame",e.merge(t,{time:n.time+=t.delta,count:n.count++}))}},_redraw:function(){this._project._needsRedraw=!0,this._handlingFrame||(this._animate?this._handleFrame():this.draw())},_transform:function(t){this._matrix.concatenate(t),this._bounds=null,this._redraw()},getElement:function(){return this._element},getViewSize:function(){return this._viewSize},setViewSize:function(t){t=c.read(arguments);var e=t.subtract(this._viewSize);e.isZero()||(this._element.width=t.width,this._element.height=t.height,this._viewSize.set(t.width,t.height,!0),this._bounds=null,this.fire("resize",{size:t,delta:e}),this._redraw())},getBounds:function(){return this._bounds||(this._bounds=this._matrix.inverted()._transformBounds(new _(new h,this._viewSize))),this._bounds},getSize:function(){return this.getBounds().getSize(arguments[0])},getCenter:function(){return this.getBounds().getCenter(arguments[0])},setCenter:function(t){t=h.read(arguments),this.scrollBy(t.subtract(this.getCenter()))},getZoom:function(){return this._zoom},setZoom:function(t){this._transform((new g).scale(t/this._zoom,this.getCenter())),this._zoom=t},isVisible:function(){return R.isInView(this._element)},scrollBy:function(){this._transform((new g).translate(h.read(arguments).negate()))},projectToView:function(){return this._matrix._transformPoint(h.read(arguments))},viewToProject:function(){return this._matrix._inverseTransform(h.read(arguments))}},{statics:{_views:[],_viewsById:{},_id:0,create:function(t){return"string"==typeof t&&(t=document.getElementById(t)),new H(t)}}},new function(){function t(t){var e=V.getTarget(t);return e.getAttribute&&Z._viewsById[e.getAttribute("id")]}function e(t,e){return t.viewToProject(V.getOffset(e,t._element))}function i(){if(!Z._focused||!Z._focused.isVisible())for(var t=0,e=Z._views.length;e>t;t++){var i=Z._views[t];if(i&&i.isVisible()){Z._focused=u=i;break}}}function n(i){var n=Z._focused=t(i),r=e(n,i);l=!0,n._onMouseDown&&n._onMouseDown(i,r),(o=n._scope._tool)&&o._onHandleEvent("mousedown",r,i),n.draw(!0)}function r(n){var r;if(l||(r=t(n),r?(h=Z._focused,Z._focused=u=r):u&&u==Z._focused&&(Z._focused=h,i())),r=r||Z._focused){var s=n&&e(r,n);r._onMouseMove&&r._onMouseMove(n,s),(o=r._scope._tool)&&o._onHandleEvent(l&&o.responds("mousedrag")?"mousedrag":"mousemove",s,n)&&V.stop(n),r.draw(!0)}}function s(t){var i=Z._focused;if(i&&l){var n=e(i,t);curPoint=null,l=!1,i._onMouseUp&&i._onMouseUp(t,n),o&&o._onHandleEvent("mouseup",n,t)&&V.stop(t),i.draw(!0)}}function a(t){l&&V.stop(t)}var o,h,u,l=!1;return V.add(document,{mousemove:r,mouseup:s,touchmove:r,touchend:s,selectstart:a,scroll:i}),V.add(window,{load:i}),{_viewHandlers:{mousedown:n,touchstart:n,selectstart:a},statics:{updateFocus:i}}}),H=Z.extend({_class:"CanvasView",initialize:function(t){if(!(t instanceof HTMLCanvasElement)){var e=c.read(arguments);if(e.isZero())throw Error("Cannot create CanvasView with the provided arguments: "+arguments);t=K.getCanvas(e)}var i=this._context=t.getContext("2d");this._eventCounters={};var n=(window.devicePixelRatio||1)/(R.getPrefixValue(i,"backingStorePixelRatio")||1);if(n>1){var r=t.clientWidth,s=t.clientHeight,a=t.style;t.width=r*n,t.height=s*n,a.width=r+"px",a.height=s+"px",i.scale(n,n)}Z.call(this,t)},draw:function(t){if(t&&!this._project._needsRedraw)return!1;var e=this._context,i=this._viewSize;return e.clearRect(0,0,i._width+1,i._height+1),this._project.draw(e,this._matrix),this._project._needsRedraw=!1,!0}},new function(){function t(t,e,i,n,r,s){for(var a,o=n;o;){if(o.responds(t)&&(a||(a=new J(t,e,i,n,r?i.subtract(r):null)),o.fire(t,a)&&(!s||a._stopped)))return!1;o=o.getParent()}return!0}function e(e,i,n,r,s){if(e._eventCounters[i]){var a=e._project,u=a.hitTest(r,{tolerance:a.options.hitTolerance||0,fill:!0,stroke:!0}),l=u&&u.item;if(l)return"mousemove"===i&&l!=o&&(s=r),"mousemove"===i&&h||t(i,n,r,l,s),l}}var i,n,r,s,a,o,h,u,l;return{_onMouseDown:function(t,o){var c=e(this,"mousedown",t,o);u=a==c&&Date.now()-l<300,s=a=c,i=n=r=o,h=s&&s.responds("mousedrag")},_onMouseUp:function(a,o){var c=e(this,"mouseup",a,o);h&&(n&&!n.equals(o)&&t("mousedrag",a,o,s,n),c!=s&&(r=o,t("mousemove",a,o,c,r))),c===s&&(l=Date.now(),(!u||t("doubleclick",a,i,c))&&t("click",a,i,c),u=!1),s=null,h=!1},_onMouseMove:function(i,a){s&&t("mousedrag",i,a,s,n);var h=e(this,"mousemove",i,a,r);n=r=a,h!==o&&(t("mouseleave",i,a,o),o=h,t("mouseenter",i,a,h))}}}),W=e.extend({_class:"Event",initialize:function(t){this.event=t},preventDefault:function(){this._prevented=!0,V.preventDefault(this.event)},stopPropagation:function(){this._stopped=!0,V.stopPropagation(this.event)},stop:function(){this.stopPropagation(),this.preventDefault()},getModifiers:function(){return X.modifiers}}),G=W.extend({_class:"KeyEvent",initialize:function(t,e,i,n){W.call(this,n),this.type=t?"keydown":"keyup",this.key=e,this.character=i},toString:function(){return"{ type: '"+this.type+"', key: '"+this.key+"', character: '"+this.character+"', modifiers: "+this.getModifiers()+" }"}}),X=new function(){function t(t,e,i,r){var s=String.fromCharCode(i),o=n[e]||s.toLowerCase(),h=t?"keydown":"keyup",u=Z._focused,l=u&&u.isVisible()&&u._scope,c=l&&l._tool;a[o]=t,c&&c.responds(h)&&(paper=l,c.fire(h,new G(t,o,s,r)),u&&u.draw(!0))}var i,n={8:"backspace",9:"tab",13:"enter",16:"shift",17:"control",18:"option",19:"pause",20:"caps-lock",27:"escape",32:"space",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",46:"delete",91:"command",93:"command",224:"command"},r=e.merge({shift:!1,control:!1,option:!1,command:!1,capsLock:!1,space:!1}),s={},a={};return V.add(document,{keydown:function(a){var o,h=a.which||a.keyCode,u=n[h];u?((o=e.camelize(u))in r&&(r[o]=!0),s[h]=0,t(!0,h,null,a)):i=h},keypress:function(e){if(null!=i){var n=e.which||e.keyCode;s[i]=n,t(!0,i,n,e),i=null}},keyup:function(i){var a,o=i.which||i.keyCode,h=n[o];h&&(a=e.camelize(h))in r&&(r[a]=!1),null!=s[o]&&(t(!1,o,s[o],i),delete s[o])}}),{modifiers:r,isDown:function(t){return!!a[t]}}},J=W.extend({_class:"MouseEvent",initialize:function(t,e,i,n,r){W.call(this,e),this.type=t,this.point=i,this.target=n,this.delta=r},toString:function(){return"{ type: '"+this.type+"', point: "+this.point+", target: "+this.target+(this.delta?", delta: "+this.delta:"")+", modifiers: "+this.getModifiers()+" }"}}),Y=W.extend({_class:"ToolEvent",_item:null,initialize:function(t,e,i){this.tool=t,this.type=e,this.event=i},_choosePoint:function(t,e){return t?t:e?e.clone():null},getPoint:function(){return this._choosePoint(this._point,this.tool._point)},setPoint:function(t){this._point=t},getLastPoint:function(){return this._choosePoint(this._lastPoint,this.tool._lastPoint)},setLastPoint:function(t){this._lastPoint=t},getDownPoint:function(){return this._choosePoint(this._downPoint,this.tool._downPoint)},setDownPoint:function(t){this._downPoint=t},getMiddlePoint:function(){return!this._middlePoint&&this.tool._lastPoint?this.tool._point.add(this.tool._lastPoint).divide(2):this._middlePoint},setMiddlePoint:function(t){this._middlePoint=t},getDelta:function(){return!this._delta&&this.tool._lastPoint?this.tool._point.subtract(this.tool._lastPoint):this._delta},setDelta:function(t){this._delta=t},getCount:function(){return/^mouse(down|up)$/.test(this.type)?this.tool._downCount:this.tool._count},setCount:function(t){this.tool[/^mouse(down|up)$/.test(this.type)?"downCount":"count"]=t},getItem:function(){if(!this._item){var t=this.tool._scope.project.hitTest(this.getPoint());if(t){for(var e=t.item,i=e._parent;/^(group|compound-path)$/.test(i._type);)e=i,i=i._parent;this._item=e}}return this._item},setItem:function(t){this._item=t},toString:function(){return"{ type: "+this.type+", point: "+this.getPoint()+", count: "+this.getCount()+", modifiers: "+this.getModifiers()+" }"}}),U=s.extend({_class:"Tool",_list:"tools",_reference:"_tool",_events:["onActivate","onDeactivate","onEditOptions","onMouseDown","onMouseUp","onMouseDrag","onMouseMove","onKeyDown","onKeyUp"],initialize:function(t){s.call(this),this._firstMove=!0,this._count=0,this._downCount=0,this._set(t)},getMinDistance:function(){return this._minDistance},setMinDistance:function(t){this._minDistance=t,null!=this._minDistance&&null!=this._maxDistance&&this._minDistance>this._maxDistance&&(this._maxDistance=this._minDistance)},getMaxDistance:function(){return this._maxDistance},setMaxDistance:function(t){this._maxDistance=t,null!=this._minDistance&&null!=this._maxDistance&&this._maxDistanceu)return!1;var l=null!=n?n:0;if(0!=l)if(u>l)e=this._point.add(h.normalize(l));else if(a)return!1}if(s&&e.equals(this._point))return!1}switch(this._lastPoint=r&&"mousemove"==t?e:this._point,this._point=e,t){case"mousedown":this._lastPoint=this._downPoint,this._downPoint=this._point,this._downCount++;break;case"mouseup":this._lastPoint=this._downPoint}return this._count=r?0:this._count+1,!0},_fireEvent:function(t,e){var i=paper.project._removeSets;if(i){"mouseup"===t&&(i.mousedrag=null);var n=i[t];if(n){for(var r in n){var s=n[r];for(var a in i){var o=i[a];o&&o!=n&&delete o[s._id]}s.remove()}i[t]=null}}return this.responds(t)&&this.fire(t,new Y(this,t,e))},_onHandleEvent:function(t,e,i){paper=this._scope;var n=!1;switch(t){case"mousedown":this._updateEvent(t,e,null,null,!0,!1,!1),n=this._fireEvent(t,i);break;case"mousedrag":for(var r=!1,s=!1;this._updateEvent(t,e,this.minDistance,this.maxDistance,!1,r,s);)n=this._fireEvent(t,i)||n,r=!0,s=!0;break;case"mouseup":!e.equals(this._point)&&this._updateEvent("mousedrag",e,this.minDistance,this.maxDistance,!1,!1,!1)&&(n=this._fireEvent("mousedrag",i)),this._updateEvent(t,e,null,this.maxDistance,!1,!1,!1),n=this._fireEvent(t,i)||n,this._updateEvent(t,e,null,null,!0,!1,!1),this._firstMove=!0;break;case"mousemove":for(;this._updateEvent(t,e,this.minDistance,this.maxDistance,this._firstMove,!0,!1);)n=this._fireEvent(t,i)||n,this._firstMove=!1}return n}}),$={request:function(t,e,i){var n=new(window.ActiveXObject||XMLHttpRequest)("Microsoft.XMLHTTP");return n.open(t.toUpperCase(),e,!0),"overrideMimeType"in n&&n.overrideMimeType("text/plain"),n.onreadystatechange=function(){if(4===n.readyState){var t=n.status;if(0!==t&&200!==t)throw Error("Could not load "+e+" (Error "+t+")");i.call(n,n.responseText)}},n.send(null)}},K={canvases:[],getCanvas:function(e,i){var n,r=i===t?e:new c(e,i),s=!0;n=this.canvases.length?this.canvases.pop():document.createElement("canvas");var a=n.getContext("2d");return a.save(),n.width===r.width&&n.height===r.height?s&&a.clearRect(0,0,r.width+1,r.height+1):(n.width=r.width,n.height=r.height),n},getContext:function(t,e){return this.getCanvas(t,e).getContext("2d")},release:function(t){var e=t.canvas?t.canvas:t;e.getContext("2d").restore(),this.canvases.push(e)}},Q=new function(){function t(t,e,i){return.2989*t+.587*e+.114*i}function i(e,i,n,r){var s=r-t(e,i,n);_=e+s,f=i+s,g=n+s;var r=t(_,f,g),a=v(_,f,g),o=m(_,f,g);if(0>a){var h=r-a;_=r+(_-r)*r/h,f=r+(f-r)*r/h,g=r+(g-r)*r/h}if(o>255){var u=255-r,l=o-r;_=r+(_-r)*u/l,f=r+(f-r)*u/l,g=r+(g-r)*u/l}}function n(t,e,i){return m(t,e,i)-v(t,e,i)}function r(t,e,i,n){var r,s=[t,e,i],a=m(t,e,i),o=v(t,e,i);o=o===t?0:o===e?1:2,a=a===t?0:a===e?1:2,r=0===v(o,a)?1===m(o,a)?2:1:0,s[a]>s[o]?(s[r]=(s[r]-s[o])*n/(s[a]-s[o]),s[a]=n):s[r]=s[a]=0,s[o]=0,_=s[0],f=s[1],g=s[2]}var s,a,o,h,u,l,c,d,_,f,g,v=Math.min,m=Math.max,p=Math.abs,y={multiply:function(){_=u*s/255,f=l*a/255,g=c*o/255},screen:function(){_=u+s-u*s/255,f=l+a-l*a/255,g=c+o-c*o/255},overlay:function(){_=128>u?2*u*s/255:255-2*(255-u)*(255-s)/255,f=128>l?2*l*a/255:255-2*(255-l)*(255-a)/255,g=128>c?2*c*o/255:255-2*(255-c)*(255-o)/255},"soft-light":function(){var t=s*u/255;_=t+u*(255-(255-u)*(255-s)/255-t)/255,t=a*l/255,f=t+l*(255-(255-l)*(255-a)/255-t)/255,t=o*c/255,g=t+c*(255-(255-c)*(255-o)/255-t)/255},"hard-light":function(){_=128>s?2*s*u/255:255-2*(255-s)*(255-u)/255,f=128>a?2*a*l/255:255-2*(255-a)*(255-l)/255,g=128>o?2*o*c/255:255-2*(255-o)*(255-c)/255},"color-dodge":function(){_=0===u?0:255===s?255:v(255,255*u/(255-s)),f=0===l?0:255===a?255:v(255,255*l/(255-a)),g=0===c?0:255===o?255:v(255,255*c/(255-o))},"color-burn":function(){_=255===u?255:0===s?0:m(0,255-255*(255-u)/s),f=255===l?255:0===a?0:m(0,255-255*(255-l)/a),g=255===c?255:0===o?0:m(0,255-255*(255-c)/o)},darken:function(){_=s>u?u:s,f=a>l?l:a,g=o>c?c:o},lighten:function(){_=u>s?u:s,f=l>a?l:a,g=c>o?c:o},difference:function(){_=u-s,0>_&&(_=-_),f=l-a,0>f&&(f=-f),g=c-o,0>g&&(g=-g)},exclusion:function(){_=u+s*(255-u-u)/255,f=l+a*(255-l-l)/255,g=c+o*(255-c-c)/255},hue:function(){r(s,a,o,n(u,l,c)),i(_,f,g,t(u,l,c))},saturation:function(){r(u,l,c,n(s,a,o)),i(_,f,g,t(u,l,c))},luminosity:function(){i(u,l,c,t(s,a,o))},color:function(){i(s,a,o,t(u,l,c))},add:function(){_=v(u+s,255),f=v(l+a,255),g=v(c+o,255)},subtract:function(){_=m(u-s,0),f=m(l-a,0),g=m(c-o,0)},average:function(){_=(u+s)/2,f=(l+a)/2,g=(c+o)/2},negation:function(){_=255-p(255-s-u),f=255-p(255-a-l),g=255-p(255-o-c)}},w=this.nativeModes=e.each(["source-over","source-in","source-out","source-atop","destination-over","destination-in","destination-out","destination-atop","lighter","darker","copy","xor"],function(t){this[t]=!0},{}),x=K.getContext(1,1);e.each(y,function(t,e){x.save();var i="darken"===e,n=!1;x.fillStyle=i?"#300":"#a00",x.fillRect(0,0,1,1),x.globalCompositeOperation=e,x.globalCompositeOperation===e&&(x.fillStyle=i?"#a00":"#300",x.fillRect(0,0,1,1),n=x.getImageData(0,0,1,1).data[0]!==(i?170:51)),w[e]=n,x.restore()}),K.release(x),this.process=function(t,e,i,n,r){var v=e.canvas,m="normal"===t;if(m||w[t])i.save(),i.setTransform(1,0,0,1,0,0),i.globalAlpha=n,m||(i.globalCompositeOperation=t),i.drawImage(v,r.x,r.y),i.restore();else{var p=y[t];if(!p)return;for(var x=i.getImageData(r.x,r.y,v.width,v.height),b=x.data,C=e.getImageData(0,0,v.width,v.height).data,S=0,P=b.length;P>S;S+=4){s=C[S],u=b[S],a=C[S+1],l=b[S+1],o=C[S+2],c=b[S+2],h=C[S+3],d=b[S+3],p();var z=h*n/255,M=1-z;b[S]=z*_+M*u,b[S+1]=z*f+M*l,b[S+2]=z*g+M*c,b[S+3]=h*n+M*d}i.putImageData(x,r.x,r.y)}}},te=e.each({fillColor:["fill","color"],strokeColor:["stroke","color"],strokeWidth:["stroke-width","number"],strokeCap:["stroke-linecap","string"],strokeJoin:["stroke-linejoin","string"],miterLimit:["stroke-miterlimit","number"],dashArray:["stroke-dasharray","array"],dashOffset:["stroke-dashoffset","number"],font:["font-family","string"],fontSize:["font-size","number"],justification:["text-anchor","lookup",{left:"start",center:"middle",right:"end"}],opacity:["opacity","number"],blendMode:["mix-blend-mode","string"]},function(t,i){var n=e.capitalize(i),r=t[2];this[i]={type:t[1],property:i,attribute:t[0],toSVG:r,fromSVG:r&&e.each(r,function(t,e){this[t]=e},{}),get:"get"+n,set:"set"+n}},{}),ee={href:"http://www.w3.org/1999/xlink",xlink:"http://www.w3.org/2000/xmlns"};return new function(){function t(t,e){for(var i in e){var n=e[i],r=ee[i];"number"==typeof n&&(n=S.number(n)),r?t.setAttributeNS(r,i,n):t.setAttribute(i,n)}return t}function n(e,i){return t(document.createElementNS("http://www.w3.org/2000/svg",e),i)}function r(t,e,i){var n=t._matrix,r=n.getTranslation(),s={};if(e){n=n.shiftless();var a=n._inverseTransform(r);s[i?"cx":"x"]=a.x,s[i?"cy":"y"]=a.y,r=null}if(n.isIdentity())return s;var h=n.decompose();if(h&&!h.shearing){var u=[],l=h.rotation,c=h.scaling;r&&!r.isZero()&&u.push("translate("+S.point(r)+")"),o.isZero(c.x-1)&&o.isZero(c.y-1)||u.push("scale("+S.point(c)+")"),l&&u.push("rotate("+S.number(l)+")"),s.transform=u.join(" ")}else s.transform="matrix("+n.getValues().join(",")+")";return s}function s(e,i){for(var s=r(e),a=e._children,o=n("g",s),h=0,u=a.length;u>h;h++){var l=a[h],c=b(l,i);if(c)if(l.isClipMask()){var d=n("clipPath");d.appendChild(c),w(l,d,"clip"),t(o,{"clip-path":"url(#"+d.id+")"})}else o.appendChild(c)}return o}function h(t){var e=r(t,!0),i=t.getSize();return e.x-=i.width/2,e.y-=i.height/2,e.width=i.width,e.height=i.height,e.href=t.toDataURL(),n("image",e)}function u(t,e){if(e.matchShapes){var r=t.toShape(!1);if(r)return c(r,e)}var s,a,o=t._segments;if(0===o.length)return null;if(t.isPolygon())if(o.length>=3){s=t._closed?"polygon":"polyline";var h=[];for(i=0,l=o.length;l>i;i++)h.push(S.point(o[i]._point));a={points:h.join(" ")}}else{s="line";var u=o[0]._point,d=o[o.length-1]._point;a={x1:u.x,y1:u.y,x2:d.x,y2:d.y}}else{s="path";var _=t.getPathData();a=_&&{d:_}}return n(s,a)}function c(t){var e=t._shape,i=t._radius,s=r(t,!0,"rectangle"!==e);if("rectangle"===e){e="rect";var a=t._size,o=a.width,h=a.height;s.x-=o/2,s.y-=h/2,s.width=o,s.height=h,i.isZero()&&(i=null)}return i&&("circle"===e?s.r=i:(s.rx=i.width,s.ry=i.height)),n(e,s)}function d(t){var e=r(t,!0),i=t.getPathData();return i&&(e.d=i),n("path",e)}function _(t,e){var i=r(t,!0),s=t.getSymbol(),a=p(s,"symbol"),o=s.getDefinition(),h=o.getBounds();return a||(a=n("symbol",{viewBox:S.rectangle(h)}),a.appendChild(b(o,e)),w(s,a,"symbol")),i.href="#"+a.id,i.x+=h.x,i.y+=h.y,i.width=S.number(h.width),i.height=S.number(h.height),n("use",i)}function f(t){var e=p(t,"color");if(!e){var i,r=t.getGradient(),s=r._radial,a=t.getOrigin().transform(),o=t.getDestination().transform();if(s){i={cx:a.x,cy:a.y,r:a.getDistance(o)};var h=t.getHighlight();h&&(h=h.transform(),i.fx=h.x,i.fy=h.y)}else i={x1:a.x,y1:a.y,x2:o.x,y2:o.y};i.gradientUnits="userSpaceOnUse",e=n((s?"radial":"linear")+"Gradient",i);for(var u=r._stops,l=0,c=u.length;c>l;l++){var d=u[l],_=d._color,f=_.getAlpha();i={offset:d._rampPoint,"stop-color":_.toCSS(!0)},1>f&&(i["stop-opacity"]=f),e.appendChild(n("stop",i))}w(t,e,"color")}return"url(#"+e.id+")"}function g(t){var e=n("text",r(t,!0));return e.textContent=t._content,e}function v(i,n){var r={},s=i.getParent();return null!=i._name&&(r.id=i._name),e.each(te,function(t){var n=t.get,a=t.type,o=i[n]();if(!s||!e.equals(s[n](),o)){if("color"===a&&null!=o){var h=o.getAlpha();1>h&&(r[t.attribute+"-opacity"]=h)}r[t.attribute]=null==o?"none":"number"===a?S.number(o):"color"===a?o.gradient?f(o,i):o.toCSS(!0):"array"===a?o.join(","):"lookup"===a?t.toSVG[o]:o}}),1===r.opacity&&delete r.opacity,null==i._visibility||i._visibility||(r.visibility="hidden"),t(n,r)}function p(t,e){return P||(P={ids:{},svgs:{}}),t&&P.svgs[e+"-"+t._id]}function w(t,e,i){P||p();var n=P.ids[i]=(P.ids[i]||0)+1;e.id=i+"-"+n,P.svgs[i+"-"+t._id]=e}function x(t,e){var i=t,r=null;if(P){i="svg"===t.nodeName.toLowerCase()&&t;for(var s in P.svgs)r||(i||(i=n("svg"),i.appendChild(t)),r=i.insertBefore(n("defs"),i.firstChild)),r.appendChild(P.svgs[s]);P=null}return e.asString?(new XMLSerializer).serializeToString(i):i}function b(t,e){var i=z[t._type],n=i&&i(t,e);return n&&t._data&&n.setAttribute("data-paper-data",JSON.stringify(t._data)),n&&v(t,n)}function C(t){return t||(t={}),S=new a(t.precision),t}var S,P,z={group:s,layer:s,raster:h,path:u,shape:c,"compound-path":d,"placed-symbol":_,"point-text":g};y.inject({exportSVG:function(t){return t=C(t),x(b(this,t),t)}}),m.inject({exportSVG:function(t){t=C(t);for(var e=this.layers,i=this.view.getSize(),r=n("svg",{x:0,y:0,width:i.width,height:i.height,version:"1.1",xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink"}),s=0,a=e.length;a>s;s++)r.appendChild(b(e[s],t));return x(r,t)}})},new function(){function i(t,e,i,n){var r=ee[e],s=r?t.getAttributeNS(r,e):t.getAttribute(e);return"null"===s&&(s=null),null==s?n?null:i?"":0:i?s:parseFloat(s)}function n(t,e,n,r){return e=i(t,e,!1,r),n=i(t,n,!1,r),!r||null!=e&&null!=n?new h(e,n):null}function r(t,e,n,r){return e=i(t,e,!1,r),n=i(t,n,!1,r),!r||null!=e&&null!=n?new c(e,n):null}function s(t,e,i){return"none"===t?null:"number"===e?parseFloat(t):"array"===e?t?t.split(/[\s,]+/g).map(parseFloat):[]:"color"===e?S(t)||t:"lookup"===e?i[t]:t}function a(t,e,i,n){var r=t.childNodes,s="clippath"===e,a=new w,o=a._project,h=o._currentStyle,u=[];s||(a._transformContent=!1,a=x(a,t,i),o._currentStyle=a._style.clone());for(var l=0,c=r.length;c>l;l++){var d,_=r[l];1!==_.nodeType||!(d=P(_,!1,n))||d instanceof p||u.push(d)}return a.addChildren(u),s&&(a=x(a.reduce(),t,i)),o._currentStyle=h,(s||"defs"===e)&&(a.remove(),a=null),a}function o(t,e){var i=new O,n=t.points;i.moveTo(n.getItem(0));for(var r=1,s=n.numberOfItems;s>r;r++)i.lineTo(n.getItem(r));return"polygon"===e&&i.closePath(),i}function u(t){var e=t.getAttribute("d"),i=e.match(/m/gi).length>1?new T:new O;return i.setPathData(e),i}function l(t,e){for(var r=t.childNodes,s=[],a=0,o=r.length;o>a;a++){var h=r[a];1===h.nodeType&&s.push(x(new F,h))}var u,l,c,d="radialgradient"===e,_=new q(s,d);return d?(u=n(t,"cx","cy"),l=u.add(i(t,"r"),0),c=n(t,"fx","fy",!0)):(u=n(t,"x1","y1"),l=n(t,"x2","y2")),x(new N(_,u,l,c),t),null}function d(t,e,i,n){for(var r=(n.getAttribute(i)||"").split(/\)\s*/g),s=new g,a=0,o=r.length;o>a;a++){var h=r[a];if(!h)break;for(var u=h.split("("),l=u[0],c=u[1].split(/[\s,]+/g),d=0,_=c.length;_>d;d++)c[d]=parseFloat(c[d]);switch(l){case"matrix":s.concatenate(new g(c[0],c[1],c[2],c[3],c[4],c[5])); +break;case"rotate":s.rotate(c[0],c[1],c[2]);break;case"translate":s.translate(c[0],c[1]);break;case"scale":s.scale(c);break;case"skewX":case"skewY":var e=Math.tan(c[0]*Math.PI/180),f="skewX"==l;s.shear(f?e:0,f?0:e)}}t.transform(s)}function f(t,e,i){var n=t["fill-opacity"===i?"getFillColor":"getStrokeColor"]();n&&n.setAlpha(parseFloat(e))}function v(i,n,r){var s=i.attributes[n],a=s&&s.value;if(!a){var o=e.camelize(n);a=i.style[o],a||r.node[o]===r.parent[o]||(a=r.node[o])}return a?"none"===a?null:a:t}function x(i,n,r){var s={node:R.getStyles(n)||{},parent:!r&&R.getStyles(n.parentNode)||{}};return e.each(M,function(r,a){var o=v(n,a,s);o!==t&&(i=e.pick(r(i,o,a,n,s),i))}),i}function S(t){var e=t&&t.match(/\((?:#|)([^)']+)/);return e&&I[e[1]]}function P(t,e,i){if(i||(i={}),"string"==typeof t){if(e&&!/^.* 0) { - ctx.strokeStyle = strokeColor.toCanvasStyle(ctx, matrix); - ctx.lineWidth = strokeWidth; - var strokeJoin = style.getStrokeJoin(), - strokeCap = style.getStrokeCap(), - miterLimit = style.getMiterLimit(), - dashArray = style.getDashArray(), - dashOffset = style.getDashOffset(); - if (strokeJoin) - ctx.lineJoin = strokeJoin; - if (strokeCap) - ctx.lineCap = strokeCap; - if (miterLimit) - ctx.miterLimit = miterLimit; - if (paper.support.nativeDash && dashArray && dashArray.length) { - if ('setLineDash' in ctx) { - ctx.setLineDash(dashArray); - ctx.lineDashOffset = dashOffset; - } else { - ctx.mozDash = dashArray; - ctx.mozDashOffset = dashOffset; + ctx.fillStyle = fillColor.toCanvasStyle(ctx); + if (strokeColor) { + var strokeWidth = style.getStrokeWidth(); + if (strokeWidth > 0) { + ctx.strokeStyle = strokeColor.toCanvasStyle(ctx); + ctx.lineWidth = strokeWidth; + var strokeJoin = style.getStrokeJoin(), + strokeCap = style.getStrokeCap(), + miterLimit = style.getMiterLimit(); + if (strokeJoin) + ctx.lineJoin = strokeJoin; + if (strokeCap) + ctx.lineCap = strokeCap; + if (miterLimit) + ctx.miterLimit = miterLimit; + if (paper.support.nativeDash) { + var dashArray = style.getDashArray(), + dashOffset = style.getDashOffset(); + if (dashArray && dashArray.length) { + if ('setLineDash' in ctx) { + ctx.setLineDash(dashArray); + ctx.lineDashOffset = dashOffset; + } else { + ctx.mozDash = dashArray; + ctx.mozDashOffset = dashOffset; + } + } } } } if (shadowColor) { - ctx.shadowColor = shadowColor.toCanvasStyle(ctx); - ctx.shadowBlur = style.getShadowBlur(); - var offset = this.getShadowOffset(); - ctx.shadowOffsetX = offset.x; - ctx.shadowOffsetY = offset.y; + var shadowBlur = style.getShadowBlur(); + if (shadowBlur > 0) { + ctx.shadowColor = shadowColor.toCanvasStyle(ctx); + ctx.shadowBlur = shadowBlur; + var offset = this.getShadowOffset(); + ctx.shadowOffsetX = offset.x; + ctx.shadowOffsetY = offset.y; + } } }, @@ -3894,8 +3916,8 @@ var Shape = Item.extend({ radius: this._radius, insert: false }); - path.transform(this._matrix); path.setStyle(this._style); + path.transform(this._matrix); if (insert || insert === undefined) path.insertAbove(this); return path; @@ -3951,8 +3973,10 @@ var Shape = Item.extend({ } if (!clip && (hasFill || hasStroke)) { this._setStyles(ctx); - if (hasFill) + if (hasFill) { ctx.fill(style.getWindingRule()); + ctx.shadowColor = 'rgba(0,0,0,0)'; + } if (hasStroke) ctx.stroke(); } @@ -5912,7 +5936,7 @@ var PathItem = Item.extend({ setPathData: function(data) { - var parts = data.match(/[a-z][^a-z]*/ig), + var parts = data.match(/[mlhvcsqtaz][^mlhvcsqtaz]*/ig), coords, relative = false, control, @@ -5934,18 +5958,15 @@ var PathItem = Item.extend({ ); } - if (this._type === 'path') - this.removeSegments(); - else - this.removeChildren(); + this.clear(); for (var i = 0, l = parts.length; i < l; i++) { var part = parts[i], cmd = part[0], lower = cmd.toLowerCase(); - coords = part.slice(1).trim().split(/[\s,]+|(?=[+-])/); + coords = part.match(/[+-]?(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?/g); + var length = coords && coords.length; relative = cmd === lower; - var length = coords.length; switch (lower) { case 'm': case 'l': @@ -6304,6 +6325,8 @@ var Path = PathItem.extend({ return removed; }, + clear: '#removeSegments', + isFullySelected: function() { var length = this._segments.length; return this._selected && length > 0 && this._selectedSegmentState @@ -6899,8 +6922,10 @@ var Path = PathItem.extend({ if (!clip && !compound && (hasFill || hasStroke)) { this._setStyles(ctx); - if (hasFill) + if (hasFill) { ctx.fill(style.getWindingRule()); + ctx.shadowColor = 'rgba(0,0,0,0)'; + } if (hasStroke) { if (dashLength) { ctx.beginPath(); @@ -7057,16 +7082,16 @@ var Path = PathItem.extend({ cubicCurveTo: function() { var handle1 = Point.read(arguments), handle2 = Point.read(arguments), - to = Point.read(arguments); - var current = getCurrentSegment(this); + to = Point.read(arguments), + current = getCurrentSegment(this); current.setHandleOut(handle1.subtract(current._point)); this._add([ new Segment(to, handle2.subtract(to)) ]); }, quadraticCurveTo: function() { var handle = Point.read(arguments), - to = Point.read(arguments); - var current = getCurrentSegment(this)._point; + to = Point.read(arguments), + current = getCurrentSegment(this)._point; this.cubicCurveTo( handle.add(current.subtract(handle).multiply(1 / 3)), handle.add(to.subtract(handle).multiply(1 / 3)), @@ -7145,25 +7170,41 @@ var Path = PathItem.extend({ this._add(segments); }, - lineBy: function(vector) { - vector = Point.read(arguments); - var current = getCurrentSegment(this); - this.lineTo(current._point.add(vector)); + lineBy: function() { + var to = Point.read(arguments), + current = getCurrentSegment(this)._point; + this.lineTo(current.add(to)); }, - curveBy: function(throughVector, toVector, parameter) { - throughVector = Point.read(throughVector); - toVector = Point.read(toVector); - var current = getCurrentSegment(this)._point; - this.curveTo(current.add(throughVector), current.add(toVector), - parameter); + curveBy: function() { + var through = Point.read(arguments), + to = Point.read(arguments), + parameter = Base.read(arguments), + current = getCurrentSegment(this)._point; + this.curveTo(current.add(through), current.add(to), parameter); }, - arcBy: function(throughVector, toVector) { - throughVector = Point.read(throughVector); - toVector = Point.read(toVector); - var current = getCurrentSegment(this)._point; - this.arcTo(current.add(throughVector), current.add(toVector)); + cubicCurveBy: function() { + var handle1 = Point.read(arguments), + handle2 = Point.read(arguments), + to = Point.read(arguments), + current = getCurrentSegment(this)._point; + this.cubicCurveTo(current.add(handle1), current.add(handle2), + current.add(to)); + }, + + quadraticCurveBy: function() { + var handle = Point.read(arguments), + to = Point.read(arguments), + current = getCurrentSegment(this)._point; + this.quadraticCurveTo(current.add(handle), current.add(to)); + }, + + arcBy: function() { + var through = Point.read(arguments), + to = Point.read(arguments), + current = getCurrentSegment(this)._point; + this.arcTo(current.add(through), current.add(to)); }, closePath: function() { @@ -7644,8 +7685,10 @@ var CompoundPath = PathItem.extend({ if (!param.clip) { this._setStyles(ctx); var style = this._style; - if (style.hasFill()) + if (style.hasFill()) { ctx.fill(style.getWindingRule()); + ctx.shadowColor = 'rgba(0,0,0,0)'; + } if (style.hasStroke()) ctx.stroke(); } @@ -7674,13 +7717,15 @@ var CompoundPath = PathItem.extend({ } }; - Base.each(['lineTo', 'cubicCurveTo', 'quadraticCurveTo', 'curveTo', - 'arcTo', 'lineBy', 'curveBy', 'arcBy'], function(key) { - fields[key] = function() { - var path = getCurrentPath(this); - path[key].apply(path, arguments); - }; - }); + Base.each(['lineTo', 'cubicCurveTo', 'quadraticCurveTo', 'curveTo', 'arcTo', + 'lineBy', 'cubicCurveBy', 'quadraticCurveBy', 'curveBy', 'arcBy'], + function(key) { + fields[key] = function() { + var path = getCurrentPath(this); + path[key].apply(path, arguments); + }; + } + ); return fields; }); @@ -8212,13 +8257,18 @@ var PointText = TextItem.extend({ this._setStyles(ctx); var style = this._style, lines = this._lines, - leading = style.getLeading(); + leading = style.getLeading(), + shadowColor = ctx.shadowColor; + ctx.font = style.getFontStyle(); ctx.textAlign = style.getJustification(); for (var i = 0, l = lines.length; i < l; i++) { + ctx.shadowColor = shadowColor; var line = lines[i]; - if (style.hasFill()) + if (style.hasFill()) { ctx.fillText(line, 0, 0); + ctx.shadowColor = 'rgba(0,0,0,0)'; + } if (style.hasStroke()) ctx.strokeText(line, 0, 0); ctx.translate(0, leading); @@ -8597,7 +8647,7 @@ var Color = Base.extend(new function() { }, clone: function() { - return new Color(this._type, this._components.slice(), this._alpha); + return new Color(this); }, _convert: function(type) { @@ -8685,23 +8735,21 @@ var Color = Base.extend(new function() { + components.join(',') + ')'; }, - toCanvasStyle: function(ctx, matrix) { + toCanvasStyle: function(ctx) { if (this._canvasStyle) return this._canvasStyle; if (this._type !== 'gradient') return this._canvasStyle = this.toCSS(); var components = this._components, - translation = matrix ? matrix.getTranslation() : new Point(), gradient = components[0], stops = gradient._stops, - origin = components[1].subtract(translation), - destination = components[2].subtract(translation), + origin = components[1], + destination = components[2], canvasGradient; if (gradient._radial) { var radius = destination.getDistance(origin), highlight = components[3]; if (highlight) { - highlight = highlight.subtract(translation); var vector = highlight.subtract(origin); if (vector.getLength() > radius) highlight = origin.add(vector.normalize(radius - 0.1)); @@ -9027,8 +9075,11 @@ var Style = Base.extend(new function() { if (isColor) { if (old) delete old._owner; - if (value && value.constructor === Color) + if (value && value.constructor === Color) { + if (value._owner) + value = value.clone(); value._owner = this._item; + } } this._values[key] = value; if (this._item) @@ -9118,6 +9169,10 @@ var Style = Base.extend(new function() { return !!this.getStrokeColor() && this.getStrokeWidth() > 0; }, + hasShadow: function() { + return !!this.getShadowColor() && this.getShadowBlur() > 0; + }, + getLeading: function getLeading() { var leading = getLeading.base.call(this); return leading != null ? leading : this.getFontSize() * 1.2; @@ -9377,18 +9432,10 @@ var DomEvent = { }; DomEvent.requestAnimationFrame = new function() { - var part = 'equestAnimationFrame', - request = window['r' + part] || window['webkitR' + part] - || window['mozR' + part] || window['oR' + part] - || window['msR' + part]; - if (request) { - request(function(time) { - if (time == null) - request = null; - }); - } - - var callbacks = [], + var nativeRequest = DomElement.getPrefixValue(window, + 'requestAnimationFrame'), + requested = false, + callbacks = [], focused = true, timer; @@ -9401,24 +9448,36 @@ DomEvent.requestAnimationFrame = new function() { } }); - return function(callback, element) { - if (request) - return request(callback, element); - callbacks.push([callback, element]); - if (timer) - return; - timer = setInterval(function() { - for (var i = callbacks.length - 1; i >= 0; i--) { - var entry = callbacks[i], - func = entry[0], - el = entry[1]; - if (!el || (PaperScope.getAttribute(el, 'keepalive') == 'true' - || focused) && DomElement.isInView(el)) { - callbacks.splice(i, 1); - func(Date.now()); - } + function handleCallbacks() { + for (var i = callbacks.length - 1; i >= 0; i--) { + var entry = callbacks[i], + func = entry[0], + el = entry[1]; + if (!el || (PaperScope.getAttribute(el, 'keepalive') == 'true' + || focused) && DomElement.isInView(el)) { + callbacks.splice(i, 1); + func(); } - }, 1000 / 60); + } + if (nativeRequest) { + if (callbacks.length) { + nativeRequest(handleCallbacks); + } else { + requested = false; + } + } + } + + return function(callback, element) { + callbacks.push([callback, element]); + if (nativeRequest) { + if (!requested) { + nativeRequest(handleCallbacks); + requested = true; + } + } else if (!timer) { + timer = setInterval(handleCallbacks, 1000 / 60); + } }; }; @@ -10005,6 +10064,7 @@ var Key = new function() { tool = scope && scope._tool; keyMap[key] = down; if (tool && tool.responds(type)) { + paper = scope; tool.fire(type, new KeyEvent(down, key, character, event)); if (view) view.draw(true); @@ -10545,6 +10605,28 @@ var Tool = PaperScopeItem.extend({ }); +var Http = { + request: function(method, url, callback) { + var xhr = new (window.ActiveXObject || XMLHttpRequest)( + 'Microsoft.XMLHTTP'); + xhr.open(method.toUpperCase(), url, true); + if ('overrideMimeType' in xhr) + xhr.overrideMimeType('text/plain'); + xhr.onreadystatechange = function() { + if (xhr.readyState === 4) { + var status = xhr.status; + if (status === 0 || status === 200) { + callback.call(xhr, xhr.responseText); + } else { + throw new Error('Could not load ' + url + ' (Error ' + + status + ')'); + } + } + }; + return xhr.send(null); + } +}; + var CanvasProvider = { canvases: [], @@ -10920,13 +11002,13 @@ new function() { return attrs; } - function exportGroup(item) { + function exportGroup(item, options) { var attrs = getTransform(item), children = item._children; var node = createElement('g', attrs); for (var i = 0, l = children.length; i < l; i++) { var child = children[i]; - var childNode = exportSVG(child); + var childNode = exportSVG(child, options); if (childNode) { if (child.isClipMask()) { var clip = createElement('clipPath'); @@ -10954,7 +11036,12 @@ new function() { return createElement('image', attrs); } - function exportPath(item) { + function exportPath(item, options) { + if (options.matchShapes) { + var shape = item.toShape(false); + if (shape) + return exportShape(shape, options); + } var segments = item._segments, type, attrs; @@ -10990,7 +11077,6 @@ new function() { function exportShape(item) { var shape = item._shape, - center = item.getPosition(true), radius = item._radius, attrs = getTransform(item, true, shape !== 'rectangle'); if (shape === 'rectangle') { @@ -11024,7 +11110,7 @@ new function() { return createElement('path', attrs); } - function exportPlacedSymbol(item) { + function exportPlacedSymbol(item, options) { var attrs = getTransform(item, true), symbol = item.getSymbol(), symbolNode = getDefinition(symbol, 'symbol'), @@ -11034,7 +11120,7 @@ new function() { symbolNode = createElement('symbol', { viewBox: formatter.rectangle(bounds) }); - symbolNode.appendChild(exportSVG(definition)); + symbolNode.appendChild(exportSVG(definition, options)); setDefinition(symbol, symbolNode, 'symbol'); } attrs.href = '#' + symbolNode.id; @@ -11045,7 +11131,7 @@ new function() { return createElement('use', attrs); } - function exportGradient(color, item) { + function exportGradient(color) { var gradientNode = getDefinition(color, 'color'); if (!gradientNode) { var gradient = color.getGradient(), @@ -11169,29 +11255,31 @@ new function() { } function exportDefinitions(node, options) { - if (!definitions) - return node; - var svg = node.nodeName.toLowerCase() === 'svg' && node, + var svg = node, defs = null; - for (var i in definitions.svgs) { - if (!defs) { - if (!svg) { - svg = createElement('svg'); - svg.appendChild(node); + if (definitions) { + svg = node.nodeName.toLowerCase() === 'svg' && node; + for (var i in definitions.svgs) { + if (!defs) { + if (!svg) { + svg = createElement('svg'); + svg.appendChild(node); + } + defs = svg.insertBefore(createElement('defs'), + svg.firstChild); } - defs = svg.insertBefore(createElement('defs'), svg.firstChild); + defs.appendChild(definitions.svgs[i]); } - defs.appendChild(definitions.svgs[i]); + definitions = null; } - definitions = null; return options.asString ? new XMLSerializer().serializeToString(svg) : svg; } - function exportSVG(item) { + function exportSVG(item, options) { var exporter = exporters[item._type], - node = exporter && exporter(item, item._type); + node = exporter && exporter(item, options); if (node && item._data) node.setAttribute('data-paper-data', JSON.stringify(item._data)); return node && applyStyle(item, node); @@ -11207,7 +11295,7 @@ new function() { Item.inject({ exportSVG: function(options) { options = setOptions(options); - return exportDefinitions(exportSVG(this), options); + return exportDefinitions(exportSVG(this, options), options); } }); @@ -11226,7 +11314,7 @@ new function() { 'xmlns:xlink': 'http://www.w3.org/1999/xlink' }); for (var i = 0, l = layers.length; i < l; i++) - node.appendChild(exportSVG(layers[i])); + node.appendChild(exportSVG(layers[i], options)); return exportDefinitions(node, options); } }); @@ -11255,15 +11343,15 @@ new function() { function getPoint(node, x, y, allowNull) { x = getValue(node, x, false, allowNull); y = getValue(node, y, false, allowNull); - return allowNull && x == null && y == null ? null - : new Point(x || 0, y || 0); + return allowNull && (x == null || y == null) ? null + : new Point(x, y); } function getSize(node, w, h, allowNull) { w = getValue(node, w, false, allowNull); h = getValue(node, h, false, allowNull); - return allowNull && w == null && h == null ? null - : new Size(w || 0, h || 0); + return allowNull && (w == null || h == null) ? null + : new Size(w, h); } function convertValue(value, type, lookup) { @@ -11280,7 +11368,7 @@ new function() { : value; } - function importGroup(node, type, options) { + function importGroup(node, type, isRoot, options) { var nodes = node.childNodes, clip = type === 'clippath', item = new Group(), @@ -11289,20 +11377,20 @@ new function() { children = []; if (!clip) { item._transformContent = false; - item = applyAttributes(item, node); + item = applyAttributes(item, node, isRoot); project._currentStyle = item._style.clone(); } for (var i = 0, l = nodes.length; i < l; i++) { var childNode = nodes[i], child; if (childNode.nodeType === 1 - && (child = importSVG(childNode, options)) + && (child = importSVG(childNode, false, options)) && !(child instanceof Symbol)) children.push(child); } item.addChildren(children); if (clip) - item = applyAttributes(item.reduce(), node); + item = applyAttributes(item.reduce(), node, isRoot); project._currentStyle = currentStyle; if (clip || type === 'defs') { item.remove(); @@ -11356,8 +11444,8 @@ new function() { } var importers = { - '#document': function(node, type, options) { - return importSVG(node.childNodes[0], options); + '#document': function(node, type, isRoot, options) { + return importSVG(node.childNodes[0], isRoot, options); }, g: importGroup, @@ -11379,8 +11467,8 @@ new function() { return raster; }, - symbol: function(node, type) { - return new Symbol(importGroup(node, type), true); + symbol: function(node, type, isRoot, options) { + return new Symbol(importGroup(node, type, isRoot, options), true); }, defs: importGroup, @@ -11474,8 +11562,13 @@ new function() { var attributes = Base.merge(Base.each(SVGStyles, function(entry) { this[entry.attribute] = function(item, value) { - item[entry.set]( - convertValue(value, entry.type, entry.fromSVG)); + item[entry.set](convertValue(value, entry.type, entry.fromSVG)); + if (entry.type === 'color' && item instanceof Shape) { + var color = item[entry.get](); + if (color) + color.transform(new Matrix().translate( + item.getPosition(true).negate())); + } }; }, {}), { id: function(item, value) { @@ -11561,10 +11654,10 @@ new function() { : value; } - function applyAttributes(item, node) { + function applyAttributes(item, node, isRoot) { var styles = { node: DomElement.getStyles(node) || {}, - parent: DomElement.getStyles(node.parentNode) || {} + parent: !isRoot && DomElement.getStyles(node.parentNode) || {} }; Base.each(attributes, function(apply, name) { var value = getAttribute(node, name, styles); @@ -11580,38 +11673,55 @@ new function() { return match && definitions[match[1]]; } - function importSVG(node, options, clearDefs) { + function importSVG(node, isRoot, options) { if (!options) options = {}; - if (typeof node === 'string') + if (typeof node === 'string') { + if (isRoot && !/^.*d;d++){var p=l[d],v=p[1];u(p[0],{get:e["get"+v]||e["is"+v],set:e["set"+v]},!0)}}return e}function i(n,i,r,s){try{n&&(s||t===s&&c(n)?u:l).call(n,i,r=r||n)}catch(a){if(a!==e.stop)throw a}return r}function r(t){return i(t,function(t,e){this[e]=t},new t.constructor)}var s=/^(statics|generics|preserve|enumerable|prototype|toString|valueOf)$/,a=Object.prototype.toString,o=Array.prototype,h=o.slice,u=o.forEach||function(t,e){for(var n=0,i=this.length;i>n;n++)t.call(e,this[n],n,this)},l=function(t,e){for(var n in this)this.hasOwnProperty(n)&&t.call(e,this[n],n,this)},c=Array.isArray=Array.isArray||function(t){return"[object Array]"===a.call(t)},d=Object.create||function(t){return{__proto__:t}},f=Object.getOwnPropertyDescriptor||function(t,e){var n=t.__lookupGetter__&&t.__lookupGetter__(e);return n?{get:n,set:t.__lookupSetter__(e),enumerable:!0,configurable:!0}:t.hasOwnProperty(e)?{value:t[e],enumerable:!0,configurable:!0,writable:!0}:null},_=Object.defineProperty||function(t,e,n){return(n.get||n.set)&&t.__defineGetter__?(n.get&&t.__defineGetter__(e,n.get),n.set&&t.__defineSetter__(e,n.set)):t[e]=n.value,t},g=function(t,e,n){return delete t[e],_(t,e,n)};return n(function(){},{inject:function(t){if(t){var e=this.prototype,i=Object.getPrototypeOf(e).constructor,r=t.statics===!0?t:t.statics;r!=t&&n(e,t,t.enumerable,i&&i.prototype,t.preserve,t.generics&&this),n(this,r,!0,i,t.preserve)}for(var s=1,a=arguments.length;a>s;s++)this.inject(arguments[s]);return this},extend:function(){for(var t,e=this,i=0,r=arguments.length;r>i&&!(t=arguments[i].initialize);i++);return t=t||function(){e.apply(this,arguments)},t.prototype=d(this.prototype),g(t.prototype,"constructor",{value:t,writable:!0,configurable:!0}),n(t,this,!0),arguments.length?this.inject.apply(t,arguments):t}},!0).inject({inject:function(){for(var t=0,e=arguments.length;e>t;t++)n(this,arguments[t],arguments[t].enumerable);return this},extend:function(){var t=d(this);return t.inject.apply(t,arguments)},each:function(t,e){return i(this,t,e)},clone:function(){return r(this)},statics:{each:i,clone:r,create:d,define:g,describe:f,isPlainObject:function(t){var n=null!=t&&t.constructor;return n&&(n===Object||n===e||"Object"===n.name)},pick:function(){for(var e=0,n=arguments.length;n>e;e++)if(arguments[e]!==t)return arguments[e];return null},stop:{}}})};"undefined"!=typeof module&&(module.exports=e),e.inject({generics:!0,clone:function(){return new this.constructor(this)},toString:function(){return null!=this._id?(this._class||"Object")+(this._name?" '"+this._name+"'":" @"+this._id):"{ "+e.each(this,function(t,e){if(!/^_/.test(e)){var n=typeof t;this.push(e+": "+("number"===n?a.instance.number(t):"string"===n?"'"+t+"'":t))}},[]).join(", ")+" }"},exportJSON:function(t){return e.exportJSON(this,t)},toJSON:function(){return e.serialize(this)},_set:function(n,i){if(n&&e.isPlainObject(n)){var r=n._filtering||n;for(var s in r)if(s in this&&r.hasOwnProperty(s)&&(!i||!i[s])){var a=n[s];a!==t&&(this[s]=a)}return!0}},statics:{exports:{},extend:function ne(){var t=ne.base.apply(this,arguments),n=t.prototype._class;return n&&!e.exports[n]&&(e.exports[n]=t),t},equals:function(t,n){function i(t,e){for(var n in t)if(t.hasOwnProperty(n)&&!e.hasOwnProperty(n))return!1;return!0}if(t===n)return!0;if(t&&t.equals)return t.equals(n);if(n&&n.equals)return n.equals(t);if(Array.isArray(t)&&Array.isArray(n)){if(t.length!==n.length)return!1;for(var r=0,s=t.length;s>r;r++)if(!e.equals(t[r],n[r]))return!1;return!0}if(t&&"object"==typeof t&&n&&"object"==typeof n){if(!i(t,n)||!i(n,t))return!1;for(var r in t)if(t.hasOwnProperty(r)&&!e.equals(t[r],n[r]))return!1;return!0}return!1},read:function(t,n,i,r){if(this===e){var s=this.peek(t,n);return t._index++,t.__read=1,s}var a=this.prototype,o=a._readIndex,h=n||o&&t._index||0;i||(i=t.length-h);var u=t[h];return u instanceof this||r&&r.readNull&&null==u&&1>=i?(o&&(t._index=h+1),u&&r&&r.clone?u.clone():u):(u=e.create(this.prototype),o&&(u.__read=!0),r&&(u.__options=r),u=u.initialize.apply(u,h>0||is;s++)r.push(Array.isArray(i=t[s])?this.read(i,0,0,n):this.read(t,s,1,n));return r},readNamed:function(n,i,r,s,a){var o=this.getNamed(n,i),h=o!==t;if(h){var u=n._filtered;u||(u=n._filtered=e.create(n[0]),u._filtering=n[0]),u[i]=t}return this.read(h?[o]:n,r,s,a)},getNamed:function(n,i){var r=n[0];return n._hasObject===t&&(n._hasObject=1===n.length&&e.isPlainObject(r)),n._hasObject?i?r[i]:n._filtered||r:t},hasNamed:function(t,e){return!!this.getNamed(t,e)},isPlainValue:function(t){return this.isPlainObject(t)||Array.isArray(t)},serialize:function(t,n,i,r){n=n||{};var s,o=!r;if(o&&(n.formatter=new a(n.precision),r={length:0,definitions:{},references:{},add:function(t,e){var n="#"+t._id,i=this.references[n];if(!i){this.length++;var r=e.call(t),s=t._class;s&&r[0]!==s&&r.unshift(s),this.definitions[n]=r,i=this.references[n]=[n]}return i}}),t&&t._serialize){s=t._serialize(n,r);var h=t._class;!h||i||s._compact||s[0]===h||s.unshift(h)}else if(Array.isArray(t)){s=[];for(var u=0,l=t.length;l>u;u++)s[u]=e.serialize(t[u],n,i,r);i&&(s._compact=!0)}else if(e.isPlainObject(t)){s={};for(var u in t)t.hasOwnProperty(u)&&(s[u]=e.serialize(t[u],n,i,r))}else s="number"==typeof t?n.formatter.number(t,n.precision):t;return o&&r.length>0?[["dictionary",r.definitions],s]:s},deserialize:function(t,n){var i=t;if(n=n||{},Array.isArray(t)){var r=t[0],s="dictionary"===r;if(!s){if(n.dictionary&&1==t.length&&/^#/.test(r))return n.dictionary[r];r=e.exports[r]}i=[];for(var a=r?1:0,o=t.length;o>a;a++)i.push(e.deserialize(t[a],n));if(s)n.dictionary=i[0];else if(r){var h=i;i=e.create(r.prototype),r.apply(i,h)}}else if(e.isPlainObject(t)){i={};for(var u in t)i[u]=e.deserialize(t[u],n)}return i},exportJSON:function(t,n){return JSON.stringify(e.serialize(t,n))},importJSON:function(t){return e.deserialize("string"==typeof t?JSON.parse(t):t)},splice:function(e,n,i,r){var s=n&&n.length,a=i===t;i=a?e.length:i,i>e.length&&(i=e.length);for(var o=0;s>o;o++)n[o]._index=i+o;if(a)return e.push.apply(e,n),[];var h=[i,r];n&&h.push.apply(h,n);for(var u=e.splice.apply(e,h),o=0,l=u.length;l>o;o++)delete u[o]._index;for(var o=i+s,l=e.length;l>o;o++)e[o]._index=o;return u},merge:function(){return e.each(arguments,function(t){e.each(t,function(t,e){this[e]=t},this)},new e,!0)},capitalize:function(t){return t.replace(/\b[a-z]/g,function(t){return t.toUpperCase()})},camelize:function(t){return t.replace(/-(.)/g,function(t,e){return e.toUpperCase()})},hyphenate:function(t){return t.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}}});var n={attach:function(n,i){if("string"!=typeof n)return e.each(n,function(t,e){this.attach(e,t)},this),t;var r=this._eventTypes[n];if(r){var s=this._handlers=this._handlers||{};s=s[n]=s[n]||[],-1==s.indexOf(i)&&(s.push(i),r.install&&1==s.length&&r.install.call(this,n))}},detach:function(n,i){if("string"!=typeof n)return e.each(n,function(t,e){this.detach(e,t)},this),t;var r,s=this._eventTypes[n],a=this._handlers&&this._handlers[n];s&&a&&(!i||-1!=(r=a.indexOf(i))&&1==a.length?(s.uninstall&&s.uninstall.call(this,n),delete this._handlers[n]):-1!=r&&a.splice(r,1))},once:function(t,e){this.attach(t,function(){e.apply(this,arguments),this.detach(t,e)})},fire:function(t,n){var i=this._handlers&&this._handlers[t];if(!i)return!1;var r=[].slice.call(arguments,1);return e.each(i,function(t){t.apply(this,r)===!1&&n&&n.stop&&n.stop()},this),!0},responds:function(t){return!(!this._handlers||!this._handlers[t])},on:"#attach",off:"#detach",trigger:"#fire",statics:{inject:function ie(){for(var t=0,n=arguments.length;n>t;t++){var i=arguments[t],r=i._events;if(r){var s={};e.each(r,function(t,n){var r="string"==typeof t,a=r?t:n,o=e.capitalize(a),h=a.substring(2).toLowerCase();s[h]=r?{}:t,a="_"+a,i["get"+o]=function(){return this[a]},i["set"+o]=function(t){t?this.attach(h,t):this[a]&&this.detach(h,this[a]),this[a]=t}}),i._eventTypes=s}ie.base.call(this,i)}return this}}},r=e.extend({_class:"PaperScope",initialize:function re(t){if(paper=this,this.project=null,this.projects=[],this.tools=[],this.palettes=[],this._id=t&&(t.getAttribute("id")||t.src)||"paperscope-"+re._id++,t&&t.setAttribute("id",this._id),re._scopes[this._id]=this,!this.support){var e=K.getContext(1,1);re.prototype.support={nativeDash:"setLineDash"in e||"mozDash"in e,nativeBlendModes:Q.nativeModes},K.release(e)}},version:"0.9.10",getView:function(){return this.project&&this.project.view},getTool:function(){return this._tool||(this._tool=new Y),this._tool},evaluate:function(t){var e=paper.PaperScript.evaluate(t,this);return Z.updateFocus(),e},install:function(t){var n=this;e.each(["project","view","tool"],function(i){e.define(t,i,{configurable:!0,get:function(){return n[i]}})});for(var i in this)/^(version|_id)/.test(i)||(t[i]=this[i])},setup:function(t){return paper=this,this.project=new v(t),this},activate:function(){paper=this},clear:function(){for(var t=this.projects.length-1;t>=0;t--)this.projects[t].remove();for(var t=this.tools.length-1;t>=0;t--)this.tools[t].remove();for(var t=this.palettes.length-1;t>=0;t--)this.palettes[t].remove()},remove:function(){this.clear(),delete r._scopes[this._id]},statics:new function(){function t(t){return t+="Attribute",function(e,n){return e[t](n)||e[t]("data-paper-"+n)}}return{_scopes:{},_id:0,get:function(t){return"object"==typeof t&&(t=t.getAttribute("id")),this._scopes[t]||null},getAttribute:t("get"),hasAttribute:t("has")}}}),s=e.extend(n,{initialize:function(t){this._scope=paper,this._index=this._scope[this._list].push(this)-1,(t||!this._scope[this._reference])&&this.activate()},activate:function(){if(!this._scope)return!1;var t=this._scope[this._reference];return t&&t!=this&&t.fire("deactivate"),this._scope[this._reference]=this,this.fire("activate",t),!0},isActive:function(){return this._scope[this._reference]===this},remove:function(){return null==this._index?!1:(e.splice(this._scope[this._list],null,this._index,1),this._scope[this._reference]==this&&(this._scope[this._reference]=null),this._scope=null,!0)}}),a=e.extend({initialize:function(t){this.precision=t||5,this.multiplier=Math.pow(10,this.precision)},number:function(t){return Math.round(t*this.multiplier)/this.multiplier},point:function(t,e){return this.number(t.x)+(e||",")+this.number(t.y)},size:function(t,e){return this.number(t.width)+(e||",")+this.number(t.height)},rectangle:function(t,e){return this.point(t,e)+(e||",")+this.size(t,e)}});a.instance=new a;var o=new function(){var e=[[.5773502691896257],[0,.7745966692414834],[.33998104358485626,.8611363115940526],[0,.5384693101056831,.906179845938664],[.2386191860831969,.6612093864662645,.932469514203152],[0,.4058451513773972,.7415311855993945,.9491079123427585],[.1834346424956498,.525532409916329,.7966664774136267,.9602898564975363],[0,.3242534234038089,.6133714327005904,.8360311073266358,.9681602395076261],[.14887433898163122,.4333953941292472,.6794095682990244,.8650633666889845,.9739065285171717],[0,.26954315595234496,.5190961292068118,.7301520055740494,.8870625997680953,.978228658146057],[.1252334085114689,.3678314989981802,.5873179542866175,.7699026741943047,.9041172563704749,.9815606342467192],[0,.2304583159551348,.44849275103644687,.6423493394403402,.8015780907333099,.9175983992229779,.9841830547185881],[.10805494870734367,.31911236892788974,.5152486363581541,.6872929048116855,.827201315069765,.9284348836635735,.9862838086968123],[0,.20119409399743451,.3941513470775634,.5709721726085388,.7244177313601701,.8482065834104272,.937273392400706,.9879925180204854],[.09501250983763744,.2816035507792589,.45801677765722737,.6178762444026438,.755404408355003,.8656312023878318,.9445750230732326,.9894009349916499]],n=[[1],[.8888888888888888,.5555555555555556],[.6521451548625461,.34785484513745385],[.5688888888888889,.47862867049936647,.23692688505618908],[.46791393457269104,.3607615730481386,.17132449237917036],[.4179591836734694,.3818300505051189,.27970539148927664,.1294849661688697],[.362683783378362,.31370664587788727,.22238103445337448,.10122853629037626],[.3302393550012598,.31234707704000286,.26061069640293544,.1806481606948574,.08127438836157441],[.29552422471475287,.26926671930999635,.21908636251598204,.1494513491505806,.06667134430868814],[.2729250867779006,.26280454451024665,.23319376459199048,.18629021092773426,.1255803694649046,.05566856711617366],[.24914704581340277,.2334925365383548,.20316742672306592,.16007832854334622,.10693932599531843,.04717533638651183],[.2325515532308739,.22628318026289723,.2078160475368885,.17814598076194574,.13887351021978725,.09212149983772845,.04048400476531588],[.2152638534631578,.2051984637212956,.18553839747793782,.15720316715819355,.12151857068790319,.08015808715976021,.03511946033175186],[.2025782419255613,.19843148532711158,.1861610000155622,.16626920581699392,.13957067792615432,.10715922046717194,.07036604748810812,.03075324199611727],[.1894506104550685,.18260341504492358,.16915651939500254,.14959598881657674,.12462897125553388,.09515851168249279,.062253523938647894,.027152459411754096]],i=Math.abs,r=Math.sqrt,s=Math.pow,a=Math.cos,h=Math.PI;return{TOLERANCE:1e-5,EPSILON:1e-11,KAPPA:4*(r(2)-1)/3,isZero:function(t){return i(t)<=o.EPSILON},integrate:function(t,i,r,s){for(var a=e[s-2],o=n[s-2],h=.5*(r-i),u=h+i,l=0,c=s+1>>1,d=1&s?o[l++]*t(u):0;c>l;){var f=h*a[l];d+=o[l++]*(t(u+f)+t(u-f))}return h*d},findRoot:function(t,e,n,r,s,a,o){for(var h=0;a>h;h++){var u=t(n),l=u/e(n);if(i(l)0?(s=n,n=r>=c?.5*(r+s):c):(r=n,n=c>=s?.5*(r+s):c)}},solveQuadratic:function(e,n,s,a,o,h){function u(t){return(l||t>=o&&h>=t)&&(a[c++]=t),c}var l=o===t,c=0,d=this.EPSILON;if(i(e)=d?u(-s/n):i(s)g)return 0;var p=g>_?r(g-_):0;return u(p-f),p>0&&u(-p-f),c},solveCubic:function(e,n,u,l,c,d,f){function _(t){return(p||t>=d&&f>=t)&&(c[v++]=t),v}var g=this.EPSILON;if(i(e)0?1:-1;return _(2*-S*C-n),_(S*C-n)}if(0>b){var C=r(y),P=Math.acos(w/(C*C*C))/3,k=-2*C,z=2*h/3;return _(k*a(P)-n),_(k*a(P+z)-n),_(k*a(P-z)-n)}var M=(w>0?-1:1)*s(i(w)+r(b),1/3);return _(M+y/M-n)}}},h=e.extend({_class:"Point",_readIndex:!0,initialize:function(t,e){var n=typeof t;if("number"===n){var i="number"==typeof e;this.x=t,this.y=i?e:t,this.__read&&(this.__read=i?2:1)}else"undefined"===n||null===t?(this.x=this.y=0,this.__read&&(this.__read=null===t?1:0)):(Array.isArray(t)?(this.x=t[0],this.y=t.length>1?t[1]:t[0]):null!=t.x?(this.x=t.x,this.y=t.y):null!=t.width?(this.x=t.width,this.y=t.height):null!=t.angle?(this.x=t.length,this.y=0,this.setAngle(t.angle)):(this.x=this.y=0,this.__read&&(this.__read=0)),this.__read&&(this.__read=1))},set:function(t,e){return this.x=t,this.y=e,this},equals:function(t){return t===this||t&&(this.x===t.x&&this.y===t.y||Array.isArray(t)&&this.x===t[0]&&this.y===t[1])||!1},clone:function(){return new h(this.x,this.y)},toString:function(){var t=a.instance;return"{ x: "+t.number(this.x)+", y: "+t.number(this.y)+" }"},_serialize:function(t){var e=t.formatter;return[e.number(this.x),e.number(this.y)]},add:function(t){return t=h.read(arguments),new h(this.x+t.x,this.y+t.y)},subtract:function(t){return t=h.read(arguments),new h(this.x-t.x,this.y-t.y)},multiply:function(t){return t=h.read(arguments),new h(this.x*t.x,this.y*t.y)},divide:function(t){return t=h.read(arguments),new h(this.x/t.x,this.y/t.y)},modulo:function(t){return t=h.read(arguments),new h(this.x%t.x,this.y%t.y)},negate:function(){return new h(-this.x,-this.y)},transform:function(t){return t?t._transformPoint(this):this},getDistance:function(t,e){t=h.read(arguments);var n=t.x-this.x,i=t.y-this.y,r=n*n+i*i;return e?r:Math.sqrt(r)},getLength:function(){var t=this.x*this.x+this.y*this.y;return arguments.length&&arguments[0]?t:Math.sqrt(t)},setLength:function(t){if(this.isZero()){var e=this._angle||0;this.set(Math.cos(e)*t,Math.sin(e)*t)}else{var n=t/this.getLength();o.isZero(n)&&this.getAngle(),this.set(this.x*n,this.y*n)}return this},normalize:function(e){e===t&&(e=1);var n=this.getLength(),i=0!==n?e/n:0,r=new h(this.x*i,this.y*i);return r._angle=this._angle,r},getAngle:function(){return 180*this.getAngleInRadians(arguments[0])/Math.PI},setAngle:function(t){if(t=this._angle=t*Math.PI/180,!this.isZero()){var e=this.getLength();this.set(Math.cos(t)*e,Math.sin(t)*e)}return this},getAngleInRadians:function(){if(arguments[0]===t)return null==this._angle&&(this._angle=Math.atan2(this.y,this.x)),this._angle;var e=h.read(arguments),n=this.getLength()*e.getLength();return o.isZero(n)?0/0:Math.acos(this.dot(e)/n)},getAngleInDegrees:function(){return this.getAngle(arguments[0])},getQuadrant:function(){return this.x>=0?this.y>=0?1:4:this.y>=0?2:3},getDirectedAngle:function(t){return t=h.read(arguments),180*Math.atan2(this.cross(t),this.dot(t))/Math.PI},rotate:function(t,e){if(0===t)return this.clone();t=t*Math.PI/180;var n=e?this.subtract(e):this,i=Math.sin(t),r=Math.cos(t);return n=new h(n.x*r-n.y*i,n.y*r+n.x*i),e?n.add(e):n},isInside:function(t){return t.contains(this)},isClose:function(t,e){return this.getDistance(t)1?t[1]:t[0]):null!=t.width?(this.width=t.width,this.height=t.height):null!=t.x?(this.width=t.x,this.height=t.y):(this.width=this.height=0,this.__read&&(this.__read=0)),this.__read&&(this.__read=1))},set:function(t,e){return this.width=t,this.height=e,this},equals:function(t){return t===this||t&&(this.width===t.width&&this.height===t.height||Array.isArray(t)&&this.width===t[0]&&this.height===t[1])||!1},clone:function(){return new c(this.width,this.height)},toString:function(){var t=a.instance;return"{ width: "+t.number(this.width)+", height: "+t.number(this.height)+" }"},_serialize:function(t){var e=t.formatter;return[e.number(this.width),e.number(this.height)]},add:function(t){return t=c.read(arguments),new c(this.width+t.width,this.height+t.height)},subtract:function(t){return t=c.read(arguments),new c(this.width-t.width,this.height-t.height)},multiply:function(t){return t=c.read(arguments),new c(this.width*t.width,this.height*t.height)},divide:function(t){return t=c.read(arguments),new c(this.width/t.width,this.height/t.height)},modulo:function(t){return t=c.read(arguments),new c(this.width%t.width,this.height%t.height)},negate:function(){return new c(-this.width,-this.height)},isZero:function(){return o.isZero(this.width)&&o.isZero(this.height)},isNaN:function(){return isNaN(this.width)||isNaN(this.height)},statics:{min:function(t,e){return new c(Math.min(t.width,e.width),Math.min(t.height,e.height))},max:function(t,e){return new c(Math.max(t.width,e.width),Math.max(t.height,e.height))},random:function(){return new c(Math.random(),Math.random())}}},e.each(["round","ceil","floor","abs"],function(t){var e=Math[t];this[t]=function(){return new c(e(this.width),e(this.height))}},{})),d=c.extend({initialize:function(t,e,n,i){this._width=t,this._height=e,this._owner=n,this._setter=i},set:function(t,e,n){return this._width=t,this._height=e,n||this._owner[this._setter](this),this},getWidth:function(){return this._width},setWidth:function(t){this._width=t,this._owner[this._setter](this)},getHeight:function(){return this._height},setHeight:function(t){this._height=t,this._owner[this._setter](this)}}),f=e.extend({_class:"Rectangle",_readIndex:!0,initialize:function(n,i,r,s){var a=typeof n,o=0;if("number"===a?(this.x=n,this.y=i,this.width=r,this.height=s,o=4):"undefined"===a||null===n?(this.x=this.y=this.width=this.height=0,o=null===n?1:0):1===arguments.length&&(Array.isArray(n)?(this.x=n[0],this.y=n[1],this.width=n[2],this.height=n[3],o=1):n.x!==t||n.width!==t?(this.x=n.x||0,this.y=n.y||0,this.width=n.width||0,this.height=n.height||0,o=1):n.from===t&&n.to===t&&(this.x=this.y=this.width=this.height=0,this._set(n),o=1)),!o){var u=h.readNamed(arguments,"from"),l=e.peek(arguments);if(this.x=u.x,this.y=u.y,l&&l.x!==t||e.hasNamed(arguments,"to")){var d=h.readNamed(arguments,"to");this.width=d.x-u.x,this.height=d.y-u.y,this.width<0&&(this.x=d.x,this.width=-this.width),this.height<0&&(this.y=d.y,this.height=-this.height)}else{var f=c.read(arguments);this.width=f.width,this.height=f.height}o=arguments._index}this.__read&&(this.__read=o)},set:function(t,e,n,i){return this.x=t,this.y=e,this.width=n,this.height=i,this},clone:function(){return new f(this.x,this.y,this.width,this.height)},equals:function(t){return e.isPlainValue(t)&&(t=f.read(arguments)),t===this||t&&this.x===t.x&&this.y===t.y&&this.width===t.width&&this.height===t.height||!1},toString:function(){var t=a.instance;return"{ x: "+t.number(this.x)+", y: "+t.number(this.y)+", width: "+t.number(this.width)+", height: "+t.number(this.height)+" }"},_serialize:function(t){var e=t.formatter;return[e.number(this.x),e.number(this.y),e.number(this.width),e.number(this.height)]},getPoint:function(){return new(arguments[0]?h:u)(this.x,this.y,this,"setPoint")},setPoint:function(t){t=h.read(arguments),this.x=t.x,this.y=t.y},getSize:function(){return new(arguments[0]?c:d)(this.width,this.height,this,"setSize")},setSize:function(t){t=c.read(arguments),this._fixX&&(this.x+=(this.width-t.width)*this._fixX),this._fixY&&(this.y+=(this.height-t.height)*this._fixY),this.width=t.width,this.height=t.height,this._fixW=1,this._fixH=1},getLeft:function(){return this.x},setLeft:function(t){this._fixW||(this.width-=t-this.x),this.x=t,this._fixX=0},getTop:function(){return this.y},setTop:function(t){this._fixH||(this.height-=t-this.y),this.y=t,this._fixY=0},getRight:function(){return this.x+this.width},setRight:function(e){this._fixX!==t&&1!==this._fixX&&(this._fixW=0),this._fixW?this.x=e-this.width:this.width=e-this.x,this._fixX=1},getBottom:function(){return this.y+this.height},setBottom:function(e){this._fixY!==t&&1!==this._fixY&&(this._fixH=0),this._fixH?this.y=e-this.height:this.height=e-this.y,this._fixY=1},getCenterX:function(){return this.x+.5*this.width},setCenterX:function(t){this.x=t-.5*this.width,this._fixX=.5},getCenterY:function(){return this.y+.5*this.height},setCenterY:function(t){this.y=t-.5*this.height,this._fixY=.5},getCenter:function(){return new(arguments[0]?h:u)(this.getCenterX(),this.getCenterY(),this,"setCenter")},setCenter:function(t){return t=h.read(arguments),this.setCenterX(t.x),this.setCenterY(t.y),this},isEmpty:function(){return 0==this.width||0==this.height},contains:function(e){return e&&e.width!==t||4==(Array.isArray(e)?e:arguments).length?this._containsRectangle(f.read(arguments)):this._containsPoint(h.read(arguments))},_containsPoint:function(t){var e=t.x,n=t.y;return e>=this.x&&n>=this.y&&e<=this.x+this.width&&n<=this.y+this.height},_containsRectangle:function(t){var e=t.x,n=t.y;return e>=this.x&&n>=this.y&&e+t.width<=this.x+this.width&&n+t.height<=this.y+this.height},intersects:function(t){return t=f.read(arguments),t.x+t.width>this.x&&t.y+t.height>this.y&&t.x=this.x&&t.y+t.height>=this.y&&t.x<=this.x+this.width&&t.y<=this.y+this.height},intersect:function(t){t=f.read(arguments);var e=Math.max(this.x,t.x),n=Math.max(this.y,t.y),i=Math.min(this.x+this.width,t.x+t.width),r=Math.min(this.y+this.height,t.y+t.height);return new f(e,n,i-e,r-n)},unite:function(t){t=f.read(arguments);var e=Math.min(this.x,t.x),n=Math.min(this.y,t.y),i=Math.max(this.x+this.width,t.x+t.width),r=Math.max(this.y+this.height,t.y+t.height);return new f(e,n,i-e,r-n)},include:function(t){t=h.read(arguments);var e=Math.min(this.x,t.x),n=Math.min(this.y,t.y),i=Math.max(this.x+this.width,t.x),r=Math.max(this.y+this.height,t.y);return new f(e,n,i-e,r-n)},expand:function(e,n){return n===t&&(n=e),new f(this.x-e/2,this.y-n/2,this.width+e,this.height+n)},scale:function(e,n){return this.expand(this.width*e-this.width,this.height*(n===t?e:n)-this.height)}},new function(){return e.each([["Top","Left"],["Top","Right"],["Bottom","Left"],["Bottom","Right"],["Left","Center"],["Top","Center"],["Right","Center"],["Bottom","Center"]],function(t,e){var n=t.join(""),i=/^[RL]/.test(n);e>=4&&(t[1]+=i?"Y":"X");var r=t[i?0:1],s=t[i?1:0],a="get"+r,o="get"+s,l="set"+r,c="set"+s,d="get"+n,f="set"+n;this[d]=function(){return new(arguments[0]?h:u)(this[a](),this[o](),this,f)},this[f]=function(t){t=h.read(arguments),this[l](t.x),this[c](t.y)}},{})}),_=f.extend({initialize:function(t,e,n,i,r,s){this.set(t,e,n,i,!0),this._owner=r,this._setter=s},set:function(t,e,n,i,r){return this._x=t,this._y=e,this._width=n,this._height=i,r||this._owner[this._setter](this),this}},new function(){var t=f.prototype;return e.each(["x","y","width","height"],function(t){var n=e.capitalize(t),i="_"+t;this["get"+n]=function(){return this[i]},this["set"+n]=function(t){this[i]=t,this._dontNotify||this._owner[this._setter](this)}},e.each(["Point","Size","Center","Left","Top","Right","Bottom","CenterX","CenterY","TopLeft","TopRight","BottomLeft","BottomRight","LeftCenter","TopCenter","RightCenter","BottomCenter"],function(e){var n="set"+e;this[n]=function(){this._dontNotify=!0,t[n].apply(this,arguments),delete this._dontNotify,this._owner[this._setter](this)}},{isSelected:function(){return this._owner._boundsSelected},setSelected:function(t){var e=this._owner;e.setSelected&&(e._boundsSelected=t,e.setSelected(t||e._selectedSegmentState>0))}}))}),g=e.extend({_class:"Matrix",initialize:function se(t){var e=arguments.length,n=!0;if(6===e?this.set.apply(this,arguments):1===e?t instanceof se?this.set(t._a,t._c,t._b,t._d,t._tx,t._ty):Array.isArray(t)?this.set.apply(this,t):n=!1:0===e?this.reset():n=!1,!n)throw Error("Unsupported matrix parameters")},set:function(t,e,n,i,r,s){return this._a=t,this._c=e,this._b=n,this._d=i,this._tx=r,this._ty=s,this},_serialize:function(t){return e.serialize(this.getValues(),t)},clone:function(){return new g(this._a,this._c,this._b,this._d,this._tx,this._ty)},equals:function(t){return t===this||t&&this._a===t._a&&this._b===t._b&&this._c===t._c&&this._d===t._d&&this._tx===t._tx&&this._ty===t._ty||!1},toString:function(){var t=a.instance;return"[["+[t.number(this._a),t.number(this._b),t.number(this._tx)].join(", ")+"], ["+[t.number(this._c),t.number(this._d),t.number(this._ty)].join(", ")+"]]"},reset:function(){return this._a=this._d=1,this._c=this._b=this._tx=this._ty=0,this},scale:function(){var t=h.read(arguments),e=h.read(arguments,0,0,{readNull:!0});return e&&this.translate(e),this._a*=t.x,this._c*=t.x,this._b*=t.y,this._d*=t.y,e&&this.translate(e.negate()),this},translate:function(t){t=h.read(arguments);var e=t.x,n=t.y;return this._tx+=e*this._a+n*this._b,this._ty+=e*this._c+n*this._d,this},rotate:function(t,e){e=h.read(arguments,1),t=t*Math.PI/180;var n=e.x,i=e.y,r=Math.cos(t),s=Math.sin(t),a=n-n*r+i*s,o=i-n*s-i*r,u=this._a,l=this._b,c=this._c,d=this._d;return this._a=r*u+s*l,this._b=-s*u+r*l,this._c=r*c+s*d,this._d=-s*c+r*d,this._tx+=a*u+o*l,this._ty+=a*c+o*d,this},shear:function(){var t=h.read(arguments),e=h.read(arguments,0,0,{readNull:!0});e&&this.translate(e);var n=this._a,i=this._c;return this._a+=t.y*this._b,this._c+=t.y*this._d,this._b+=t.x*n,this._d+=t.x*i,e&&this.translate(e.negate()),this},concatenate:function(t){var e=this._a,n=this._b,i=this._c,r=this._d;return this._a=t._a*e+t._c*n,this._b=t._b*e+t._d*n,this._c=t._a*i+t._c*r,this._d=t._b*i+t._d*r,this._tx+=t._tx*e+t._ty*n,this._ty+=t._tx*i+t._ty*r,this},preConcatenate:function(t){var e=this._a,n=this._b,i=this._c,r=this._d,s=this._tx,a=this._ty;return this._a=t._a*e+t._b*i,this._b=t._a*n+t._b*r,this._c=t._c*e+t._d*i,this._d=t._c*n+t._d*r,this._tx=t._a*s+t._b*a+t._tx,this._ty=t._c*s+t._d*a+t._ty,this},isIdentity:function(){return 1==this._a&&0==this._c&&0==this._b&&1==this._d&&0==this._tx&&0==this._ty},isInvertible:function(){return!!this._getDeterminant()},isSingular:function(){return!this._getDeterminant()},transform:function(t,e,n,i,r){return arguments.length<5?this._transformPoint(h.read(arguments)):this._transformCoordinates(t,e,n,i,r)},_transformPoint:function(t,e,n){var i=t.x,r=t.y;return e||(e=new h),e.set(i*this._a+r*this._b+this._tx,i*this._c+r*this._d+this._ty,n)},_transformCoordinates:function(t,e,n,i,r){for(var s=e,a=i,o=e+2*r;o>s;){var h=t[s++],u=t[s++];n[a++]=h*this._a+u*this._b+this._tx,n[a++]=h*this._c+u*this._d+this._ty}return n},_transformCorners:function(t){var e=t.x,n=t.y,i=e+t.width,r=n+t.height,s=[e,n,i,n,i,r,e,r];return this._transformCoordinates(s,0,s,0,4)},_transformBounds:function(t,e,n){for(var i=this._transformCorners(t),r=i.slice(0,2),s=i.slice(),a=2;8>a;a++){var o=i[a],h=1&a;os[h]&&(s[h]=o)}return e||(e=new f),e.set(r[0],r[1],s[0]-r[0],s[1]-r[1],n)},inverseTransform:function(){return this._inverseTransform(h.read(arguments))},_getDeterminant:function(){var t=this._a*this._d-this._b*this._c;return isFinite(t)&&!o.isZero(t)&&isFinite(this._tx)&&isFinite(this._ty)?t:null},_inverseTransform:function(t,e,n){var i=this._getDeterminant();if(!i)return null;var r=t.x-this._tx,s=t.y-this._ty;return e||(e=new h),e.set((r*this._d-s*this._b)/i,(s*this._a-r*this._c)/i,n)},decompose:function(){var t=this._a,e=this._b,n=this._c,i=this._d;if(o.isZero(t*i-e*n))return null;var r=Math.sqrt(t*t+e*e);t/=r,e/=r;var s=t*n+e*i;n-=t*s,i-=e*s;var a=Math.sqrt(n*n+i*i);return n/=a,i/=a,s/=a,e*n>t*i&&(t=-t,e=-e,s=-s,r=-r),{translation:this.getTranslation(),scaling:new h(r,a),rotation:180*-Math.atan2(e,t)/Math.PI,shearing:s} -},getValues:function(){return[this._a,this._c,this._b,this._d,this._tx,this._ty]},getTranslation:function(){return new h(this._tx,this._ty)},getScaling:function(){return(this.decompose()||{}).scaling},getRotation:function(){return(this.decompose()||{}).rotation},inverted:function(){var t=this._getDeterminant();return t&&new g(this._d/t,-this._c/t,-this._b/t,this._a/t,(this._b*this._ty-this._d*this._tx)/t,(this._c*this._tx-this._a*this._ty)/t)},shiftless:function(){return new g(this._a,this._c,this._b,this._d,0,0)},applyToContext:function(t){t.transform(this._a,this._c,this._b,this._d,this._tx,this._ty)}},new function(){return e.each({scaleX:"_a",scaleY:"_d",translateX:"_tx",translateY:"_ty",shearX:"_b",shearY:"_c"},function(t,n){n=e.capitalize(n),this["get"+n]=function(){return this[t]},this["set"+n]=function(e){this[t]=e}},{})}),p=e.extend({_class:"Line",initialize:function(t,e,n,i,r){var s=!1;arguments.length>=4?(this._px=t,this._py=e,this._vx=n,this._vy=i,s=r):(this._px=t.x,this._py=t.y,this._vx=e.x,this._vy=e.y,s=n),s||(this._vx-=this._px,this._vy-=this._py)},getPoint:function(){return new h(this._px,this._py)},getVector:function(){return new h(this._vx,this._vy)},getLength:function(){return this.getVector().getLength()},intersect:function(t,e){return p.intersect(this._px,this._py,this._vx,this._vy,t._px,t._py,t._vx,t._vy,!0,e)},getSide:function(t){return p.getSide(this._px,this._py,this._vx,this._vy,t.x,t.y,!0)},getDistance:function(t){return Math.abs(p.getSignedDistance(this._px,this._py,this._vx,this._vy,t.x,t.y,!0))},statics:{intersect:function(t,e,n,i,r,s,a,u,l,c){l||(n-=t,i-=e,a-=r,u-=s);var d=u*n-a*i;if(!o.isZero(d)){var f=t-r,_=e-s,g=(a*_-u*f)/d,p=(n*_-i*f)/d;if((c||g>=0&&1>=g)&&(c||p>=0&&1>=p))return new h(t+g*n,e+g*i)}},getSide:function(t,e,n,i,r,s,a){a||(n-=t,i-=e);var o=r-t,h=s-e,u=o*i-h*n;return 0===u&&(u=o*n+h*i,u>0&&(o-=n,h-=i,u=o*n+h*i,0>u&&(u=0))),0>u?-1:u>0?1:0},getSignedDistance:function(t,e,n,i,r,s,a){a||(n-=t,i-=e);var o=i/n,h=e-o*t;return(s-o*r-h)/Math.sqrt(o*o+1)}}}),v=s.extend({_class:"Project",_list:"projects",_reference:"project",initialize:function(t){s.call(this,!0),this.layers=[],this.symbols=[],this._currentStyle=new F,this.activeLayer=new x,t&&(this.view=t instanceof Z?t:Z.create(t)),this._selectedItems={},this._selectedItemCount=0,this._drawCount=0,this.options={}},_serialize:function(t,n){return e.serialize(this.layers,t,!0,n)},clear:function(){for(var t=this.layers.length-1;t>=0;t--)this.layers[t].remove();this.symbols=[]},remove:function ae(){return ae.base.call(this)?(this.view&&this.view.remove(),!0):!1},getCurrentStyle:function(){return this._currentStyle},setCurrentStyle:function(t){this._currentStyle.initialize(t)},getIndex:function(){return this._index},getSelectedItems:function(){var t=[];for(var e in this._selectedItems){var n=this._selectedItems[e];n.isInserted()&&t.push(n)}return t},_updateSelection:function(t){var e=t._id,n=this._selectedItems;t._selected?n[e]!==t&&(this._selectedItemCount++,n[e]=t):n[e]===t&&(this._selectedItemCount--,delete n[e])},selectAll:function(){for(var t=this.layers,e=0,n=t.length;n>e;e++)t[e].setFullySelected(!0)},deselectAll:function(){var t=this._selectedItems;for(var e in t)t[e].setFullySelected(!1)},hitTest:function(t,n){t=h.read(arguments),n=P.getOptions(e.read(arguments));for(var i=this.layers.length-1;i>=0;i--){var r=this.layers[i].hitTest(t,n);if(r)return r}return null}},new function(){function t(t,e,n){for(var i=t.layers,r=n&&[],s=0,a=i.length;a>s;s++){var o=i[s][n?"getItems":"getItem"](e);if(n)r.push.apply(r,o);else if(o)return o}return n?r:null}return{getItems:function(e){return t(this,e,!0)},getItem:function(e){return t(this,e,!1)}}},{importJSON:function(t){return this.activate(),e.importJSON(t)},draw:function(t,n){this._drawCount++,t.save(),n.applyToContext(t);for(var i=e.merge({offset:new h(0,0),transforms:[n],trackTransforms:!0}),r=0,s=this.layers.length;s>r;r++)this.layers[r].draw(t,i);if(t.restore(),this._selectedItemCount>0){t.save(),t.strokeWidth=1;for(var a in this._selectedItems){var o=this._selectedItems[a];if(o._drawCount===this._drawCount&&(o._drawSelected||o._boundsSelected)){var u=o.getSelectedColor()||o.getLayer().getSelectedColor();t.strokeStyle=t.fillStyle=u?u.toCanvasStyle(t):"#009dec";var l=o._globalMatrix;if(o._drawSelected&&o._drawSelected(t,l),o._boundsSelected){var c=l._transformCorners(o._getBounds("getBounds"));t.beginPath();for(var r=0;8>r;r++)t[0===r?"moveTo":"lineTo"](c[r],c[++r]);t.closePath(),t.stroke();for(var r=0;8>r;r++)t.beginPath(),t.rect(c[r]-2,c[++r]-2,4,4),t.fill()}}}t.restore()}}}),m=e.extend({_class:"Symbol",initialize:function oe(t,e){this._id=oe._id=(oe._id||0)+1,this.project=paper.project,this.project.symbols.push(this),t&&this.setDefinition(t,e),this._instances={}},_serialize:function(t,n){return n.add(this,function(){return e.serialize([this._class,this._definition],t,!1,n)})},_changed:function(t){e.each(this._instances,function(e){e._changed(t)})},getDefinition:function(){return this._definition},setDefinition:function(t){t._parentSymbol&&(t=t.clone()),this._definition&&delete this._definition._parentSymbol,this._definition=t,t.remove(),t.setSelected(!1),arguments[1]||t.setPosition(new h),t._parentSymbol=this,this._changed(5)},place:function(t){return new S(this,t)},clone:function(){return new m(this._definition.clone(!1))}}),y=e.extend(n,{statics:{extend:function he(t){t._serializeFields&&(t._serializeFields=e.merge(this.prototype._serializeFields,t._serializeFields));var n=he.base.apply(this,arguments),i=n.prototype,r=i._class;return r&&(i._type=e.hyphenate(r)),n}},_class:"Item",_transformContent:!0,_boundsSelected:!1,_serializeFields:{name:null,matrix:new g,locked:!1,visible:!0,blendMode:"normal",opacity:1,guide:!1,selected:!1,clipMask:!1,data:{}},initialize:function(){},_initialize:function(t,e){if(this._id=y._id=(y._id||0)+1,!this._project){var n=paper.project,i=n.activeLayer;!i||t&&t.insert===!1?this._setProject(n):i.addChild(this)}return this._style=new F(this._project._currentStyle,this),this._matrix=new g,e&&this._matrix.translate(e),t?this._set(t,{insert:!0}):!0},_events:new function(){var t={mousedown:{mousedown:1,mousedrag:1,click:1,doubleclick:1},mouseup:{mouseup:1,mousedrag:1,click:1,doubleclick:1},mousemove:{mousedrag:1,mousemove:1,mouseenter:1,mouseleave:1}},n={install:function(e){var n=this._project.view._eventCounters;if(n)for(var i in t)n[i]=(n[i]||0)+(t[i][e]||0)},uninstall:function(e){var n=this._project.view._eventCounters;if(n)for(var i in t)n[i]-=t[i][e]||0}};return e.each(["onMouseDown","onMouseUp","onMouseDrag","onClick","onDoubleClick","onMouseMove","onMouseEnter","onMouseLeave"],function(t){this[t]=n},{onFrame:{install:function(){this._project.view._animateItem(this,!0)},uninstall:function(){this._project.view._animateItem(this,!1)}},onLoad:{}})},_serialize:function(t,n){function i(i){for(var a in i){var o=s[a];e.equals(o,"leading"===a?1.2*i.fontSize:i[a])||(r[a]=e.serialize(o,t,"data"!==a,n))}}var r={},s=this;return i(this._serializeFields),this instanceof w||i(this._style._defaults),[this._class,r]},_changed:function(t){var e=this._parent,n=this._project,i=this._parentSymbol;if(this._drawCount=null,4&t&&(delete this._bounds,delete this._position),e&&12&t&&e._clearBoundsCache(),2&t&&this._clearBoundsCache(),n&&(1&t&&(n._needsRedraw=!0),n._changes)){var r=n._changesById[this._id];r?r.flags|=t:(r={item:this,flags:t},n._changesById[this._id]=r,n._changes.push(r))}i&&i._changed(t)},set:function(t){return t&&this._set(t),this},getId:function(){return this._id},getType:function(){return this._type},getName:function(){return this._name},setName:function(e,n){if(this._name&&this._removeNamed(),e===+e+"")throw Error("Names consisting only of numbers are not supported.");if(e&&this._parent){for(var i=this._parent._children,r=this._parent._namedChildren,s=e,a=1;n&&i[e];)e=s+" "+a++;(r[e]=r[e]||[]).push(this),i[e]=this}this._name=e||t,this._changed(32)},getStyle:function(){return this._style},setStyle:function(t){this.getStyle().set(t)},hasFill:function(){return this.getStyle().hasFill()},hasStroke:function(){return this.getStyle().hasStroke()}},e.each(["locked","visible","blendMode","opacity","guide"],function(t){var n=e.capitalize(t),t="_"+t;this["get"+n]=function(){return this[t]},this["set"+n]=function(e){e!=this[t]&&(this[t]=e,this._changed("_locked"===t?32:33))}},{}),{_locked:!1,_visible:!0,_blendMode:"normal",_opacity:1,_guide:!1,isSelected:function(){if(this._children)for(var t=0,e=this._children.length;e>t;t++)if(this._children[t].isSelected())return!0;return this._selected},setSelected:function(t){if(this._children&&!arguments[1])for(var e=0,n=this._children.length;n>e;e++)this._children[e].setSelected(t);(t=!!t)!=this._selected&&(this._selected=t,this._project._updateSelection(this),this._changed(33))},_selected:!1,isFullySelected:function(){if(this._children&&this._selected){for(var t=0,e=this._children.length;e>t;t++)if(!this._children[t].isFullySelected())return!1;return!0}return this._selected},setFullySelected:function(t){if(this._children)for(var e=0,n=this._children.length;n>e;e++)this._children[e].setFullySelected(t);this.setSelected(t,!0)},isClipMask:function(){return this._clipMask},setClipMask:function(t){this._clipMask!=(t=!!t)&&(this._clipMask=t,t&&(this.setFillColor(null),this.setStrokeColor(null)),this._changed(33),this._parent&&this._parent._changed(256))},_clipMask:!1,getData:function(){return this._data||(this._data={}),this._data},setData:function(t){this._data=t},getPosition:function(){var t=this._position||(this._position=this.getBounds().getCenter(!0));return new(arguments[0]?h:u)(t.x,t.y,this,"setPosition")},setPosition:function(){this.translate(h.read(arguments).subtract(this.getPosition(!0)))},getMatrix:function(){return this._matrix},setMatrix:function(t){this._matrix.initialize(t),this._changed(5)},getGlobalMatrix:function(){return this._drawCount===this._project._drawCount&&this._globalMatrix||null},globalToLocal:function(){var t=this.getGlobalMatrix();return t&&t._transformPoint(h.read(arguments))},localToGlobal:function(){var t=this.getGlobalMatrix();return t&&t._inverseTransform(h.read(arguments))},isEmpty:function(){return!this._children||0==this._children.length}},e.each(["getBounds","getStrokeBounds","getHandleBounds","getRoughBounds"],function(t){this[t]=function(){var e=this._boundsGetter,n=this._getCachedBounds("string"==typeof e?e:e&&e[t]||t,arguments[0]);return"getBounds"===t?new _(n.x,n.y,n.width,n.height,this,"setBounds"):n}},{_getCachedBounds:function(t,e,n){var i=(!e||e.equals(this._matrix))&&t;if(n&&this._parent){var r=n._id,s=this._parent._boundsCache=this._parent._boundsCache||{ids:{},list:[]};s.ids[r]||(s.list.push(n),s.ids[r]=n)}if(i&&this._bounds&&this._bounds[i])return this._bounds[i].clone();var a=this._matrix.isIdentity();e=!e||e.isIdentity()?a?null:this._matrix:a?e:e.clone().concatenate(this._matrix);var o=this._getBounds(t,e,i?this:n);return i&&(this._bounds||(this._bounds={}),this._bounds[i]=o.clone()),o},_clearBoundsCache:function(){if(this._boundsCache){for(var t=0,e=this._boundsCache.list,n=e.length;n>t;t++){var i=e[t];delete i._bounds,i!=this&&i._boundsCache&&i._clearBoundsCache()}delete this._boundsCache}},_getBounds:function(t,e,n){var i=this._children;if(!i||0==i.length)return new f;for(var r=1/0,s=-r,a=r,o=s,h=0,u=i.length;u>h;h++){var l=i[h];if(l._visible&&!l.isEmpty()){var c=l._getCachedBounds(t,e,n);r=Math.min(c.x,r),a=Math.min(c.y,a),s=Math.max(c.x+c.width,s),o=Math.max(c.y+c.height,o)}}return isFinite(r)?new f(r,a,s-r,o-a):new f},setBounds:function(t){t=f.read(arguments);var e=this.getBounds(),n=new g,i=t.getCenter();n.translate(i),(t.width!=e.width||t.height!=e.height)&&n.scale(0!=e.width?t.width/e.width:1,0!=e.height?t.height/e.height:1),i=e.getCenter(),n.translate(-i.x,-i.y),this.transform(n)}}),{getProject:function(){return this._project},_setProject:function(t){if(this._project!=t&&(this._project=t,this._children))for(var e=0,n=this._children.length;n>e;e++)this._children[e]._setProject(t)},getLayer:function(){for(var t=this;t=t._parent;)if(t instanceof x)return t;return null},getParent:function(){return this._parent},setParent:function(t){return t.addChild(this)},getChildren:function(){return this._children},setChildren:function(t){this.removeChildren(),this.addChildren(t)},getFirstChild:function(){return this._children&&this._children[0]||null},getLastChild:function(){return this._children&&this._children[this._children.length-1]||null},getNextSibling:function(){return this._parent&&this._parent._children[this._index+1]||null},getPreviousSibling:function(){return this._parent&&this._parent._children[this._index-1]||null},getIndex:function(){return this._index},isInserted:function(){return this._parent?this._parent.isInserted():!1},equals:function(t){return t===this||t&&this._class===t._class&&this._style.equals(t._style)&&this._matrix.equals(t._matrix)&&this._locked===t._locked&&this._visible===t._visible&&this._blendMode===t._blendMode&&this._opacity===t._opacity&&this._clipMask===t._clipMask&&this._guide===t._guide&&this._equals(t)||!1},_equals:function(t){return e.equals(this._children,t._children)},clone:function(t){return this._clone(new this.constructor({insert:!1}),t)},_clone:function(e,n){if(e.setStyle(this._style),this._children)for(var i=0,r=this._children.length;r>i;i++)e.addChild(this._children[i].clone(!1),!0);(n||n===t)&&e.insertAbove(this);for(var s=["_locked","_visible","_blendMode","_opacity","_clipMask","_guide"],i=0,r=s.length;r>i;i++){var a=s[i];this.hasOwnProperty(a)&&(e[a]=this[a])}return e._matrix.initialize(this._matrix),e.setSelected(this._selected),this._name&&e.setName(this._name,!0),e},copyTo:function(t){var e=this.clone();return t.layers?t.activeLayer.addChild(e):t.addChild(e),e},rasterize:function(t){var n=this.getStrokeBounds(),i=(t||72)/72,r=n.getTopLeft().floor(),s=n.getBottomRight().ceil();size=new c(s.subtract(r)),canvas=K.getCanvas(size),ctx=canvas.getContext("2d"),matrix=(new g).scale(i).translate(r.negate()),ctx.save(),matrix.applyToContext(ctx),this.draw(ctx,e.merge({transforms:[matrix]})),ctx.restore();var a=new C({canvas:canvas,insert:!1});return a.setPosition(r.add(size.divide(2))),a.insertAbove(this),a},contains:function(){return!!this._contains(this._matrix._inverseTransform(h.read(arguments)))},_contains:function(t){if(this._children){for(var e=this._children.length-1;e>=0;e--)if(this._children[e].contains(t))return!0;return!1}return t.isInside(this._getBounds("getBounds"))},hitTest:function(n,i){function r(r,s){var h=o["get"+s]();return n.getDistance(h)l&&!s;l++)s=r("bounds",u[l])}return(s||(s=this._children||!(i.guides&&!this._guide||i.selected&&!this._selected)?this._hitTest(n,i):null))&&s.point&&(s.point=a._matrix.transform(s.point)),s},_hitTest:function(t,e){var n=this._children;if(n){for(var i,r=n.length-1;r>=0;r--)if(i=n[r].hitTest(t,e))return i}else if(e.fill&&this.hasFill()&&this._contains(t))return new P("fill",this)},matches:function(t){function n(t,i){for(var r in t)if(t.hasOwnProperty(r)){var s=t[r],a=i[r];if(e.isPlainObject(s)&&e.isPlainObject(a)){if(!n(s,a))return!1}else if(!e.equals(s,a))return!1}return!0}for(var i in t)if(t.hasOwnProperty(i)){var r=this[i],s=t[i];if(s instanceof RegExp){if(!s.test(r))return!1}else if("function"==typeof s){if(!s(r))return!1}else if(e.isPlainObject(s)){if(!n(s,r))return!1}else if(!e.equals(r,s))return!1}return!0}},new function(){function t(e,n,i){for(var r=e._children,s=i&&[],a=0,o=r&&r.length;o>a;a++){var h=r[a];if(h.matches(n)){if(!i)return h;s.push(h)}var u=t(h,n,i);if(i)s.push.apply(s,u);else if(u)return u}return i?s:null}return{getItems:function(e){return t(this,e,!0)},getItem:function(e){return t(this,e,!1)}}},{importJSON:function(t){return this.addChild(e.importJSON(t))},addChild:function(e,n){return this.insertChild(t,e,n)},insertChild:function(t,e,n){var i=this.insertChildren(t,[e],n);return i&&i[0]},addChildren:function(t,e){return this.insertChildren(this._children.length,t,e)},insertChildren:function(t,n,i,r){var s=this._children;if(s&&n&&n.length>0){n=Array.prototype.slice.apply(n);for(var a=n.length-1;a>=0;a--){var o=n[a];r&&o._type!==r?n.splice(a,1):o._remove(!0)}e.splice(s,n,t,0);for(var a=0,h=n.length;h>a;a++){var o=n[a];o._parent=this,o._setProject(this._project),o._name&&o.setName(o._name)}this._changed(7)}else n=null;return n},_insert:function(t,e,n){if(!e._parent)return null;var i=e._index+(t?1:0);return e._parent===this._parent&&i>this._index&&i--,e._parent.insertChild(i,this,n)},insertAbove:function(t,e){return this._insert(!0,t,e)},insertBelow:function(t,e){return this._insert(!1,t,e)},sendToBack:function(){return this._parent.insertChild(0,this)},bringToFront:function(){return this._parent.addChild(this)},appendTop:"#addChild",appendBottom:function(t){return this.insertChild(0,t)},moveAbove:"#insertAbove",moveBelow:"#insertBelow",reduce:function(){if(this._children&&1===this._children.length){var t=this._children[0];return t.insertAbove(this),this.remove(),t}return this},_removeNamed:function(){var t=this._parent._children,e=this._parent._namedChildren,n=this._name,i=e[n],r=i?i.indexOf(this):-1;-1!=r&&(t[n]==this&&delete t[n],i.splice(r,1),i.length?t[n]=i[i.length-1]:delete e[n])},_remove:function(t){return this._parent?(this._name&&this._removeNamed(),null!=this._index&&e.splice(this._parent._children,null,this._index,1),t&&this._parent._changed(7),this._parent=null,!0):!1},remove:function(){return this._remove(!0)},removeChildren:function(t,n){if(!this._children)return null;t=t||0,n=e.pick(n,this._children.length);for(var i=e.splice(this._children,null,t,n-t),r=i.length-1;r>=0;r--)i[r]._remove(!1);return i.length>0&&this._changed(7),i},reverseChildren:function(){if(this._children){this._children.reverse();for(var t=0,e=this._children.length;e>t;t++)this._children[t]._index=t;this._changed(7)}},isEditable:function(){for(var t=this;t;){if(!t._visible||t._locked)return!1;t=t._parent}return!0},_getOrder:function(t){function e(t){var e=[];do e.unshift(t);while(t=t._parent);return e}for(var n=e(this),i=e(t),r=0,s=Math.min(n.length,i.length);s>r;r++)if(n[r]!=i[r])return n[r]._index0},isAbove:function(t){return-1===this._getOrder(t)},isBelow:function(t){return 1===this._getOrder(t)},isParent:function(t){return this._parent===t},isChild:function(t){return t&&t._parent===this},isDescendant:function(t){for(var e=this;e=e._parent;)if(e==t)return!0;return!1},isAncestor:function(t){return t?t.isDescendant(this):!1},isGroupedWith:function(t){for(var e=this._parent;e;){if(e._parent&&/^(group|layer|compound-path)$/.test(e._type)&&t.isDescendant(e))return!0;e=e._parent}return!1},scale:function(t,e,n){return(arguments.length<2||"object"==typeof e)&&(n=e,e=t),this.transform((new g).scale(t,e,n||this.getPosition(!0)))},translate:function(){var t=new g;return this.transform(t.translate.apply(t,arguments))},rotate:function(t,e){return this.transform((new g).rotate(t,e||this.getPosition(!0)))},shear:function(t,e,n){return(arguments.length<2||"object"==typeof e)&&(n=e,e=t),this.transform((new g).shear(t,e,n||this.getPosition(!0)))},transform:function(t){var e=this._bounds,n=this._position;if(this._matrix.preConcatenate(t),(this._transformContent||arguments[1])&&this.applyMatrix(!0),this._changed(5),e&&0===t.getRotation()%90){for(var i in e){var r=e[i];t._transformBounds(r,r)}var s=this._boundsGetter,r=e[s&&s.getBounds||s||"getBounds"];r&&(this._position=r.getCenter(!0)),this._bounds=e}else n&&(this._position=t._transformPoint(n,n));return this},_applyMatrix:function(t,e){var n=this._children;if(n&&n.length>0){for(var i=0,r=n.length;r>i;i++)n[i].transform(t,e);return!0}},applyMatrix:function(t){var e=this._matrix;if(this._applyMatrix(e,!0)){var n=this._style,i=n.getFillColor(!0),r=n.getStrokeColor(!0);i&&i.transform(e),r&&r.transform(e),e.reset()}t||this._changed(5)},fitBounds:function(t,e){t=f.read(arguments);var n=this.getBounds(),i=n.height/n.width,r=t.height/t.width,s=(e?i>r:r>i)?t.width/n.width:t.height/n.height,a=new f(new h,new c(n.width*s,n.height*s));a.setCenter(t.getCenter()),this.setBounds(a)},_setStyles:function(t){var e=this._style,n=this._matrix,i=e.getStrokeWidth(),r=e.getFillColor(),s=e.getStrokeColor(),a=e.getShadowColor();if(r&&(t.fillStyle=r.toCanvasStyle(t,n)),s&&i>0){t.strokeStyle=s.toCanvasStyle(t,n),t.lineWidth=i;var o=e.getStrokeJoin(),h=e.getStrokeCap(),u=e.getMiterLimit(),l=e.getDashArray(),c=e.getDashOffset();o&&(t.lineJoin=o),h&&(t.lineCap=h),u&&(t.miterLimit=u),paper.support.nativeDash&&l&&l.length&&("setLineDash"in t?(t.setLineDash(l),t.lineDashOffset=c):(t.mozDash=l,t.mozDashOffset=c))}if(a){t.shadowColor=a.toCanvasStyle(t),t.shadowBlur=e.getShadowBlur();var d=this.getShadowOffset();t.shadowOffsetX=d.x,t.shadowOffsetY=d.y}},draw:function(t,e){if(this._visible&&0!==this._opacity){this._drawCount=this._project._drawCount;var n=e.trackTransforms,i=e.transforms,r=i[i.length-1],s=r.clone().concatenate(this._matrix);n&&i.push(this._globalMatrix=s);var a,o,h,u=this._blendMode,l=this._opacity,d="normal"===u,f=Q.nativeModes[u],_=d&&1===l||(f||d&&1>l)&&this._canComposite();if(!_){var g=this.getStrokeBounds(r);if(!g.width||!g.height)return;h=e.offset,o=e.offset=g.getTopLeft().floor(),a=t,t=K.getContext(g.getSize().ceil().add(new c(1,1)))}t.save(),_?(t.globalAlpha=l,f&&(t.globalCompositeOperation=u)):t.translate(-o.x,-o.y),(_?this._matrix:s).applyToContext(t),!_&&e.clipItem&&e.clipItem.draw(t,e.extend({clip:!0})),this._draw(t,e),t.restore(),n&&i.pop(),e.clip&&t.clip(),_||(Q.process(u,t,a,l,o.subtract(h)),K.release(t),e.offset=h)}},_canComposite:function(){return!1}},e.each(["down","drag","up","move"],function(t){this["removeOn"+e.capitalize(t)]=function(){var e={};return e[t]=!0,this.removeOn(e)}},{removeOn:function(t){for(var e in t)if(t[e]){var n="mouse"+e,i=this._project,r=i._removeSets=i._removeSets||{};r[n]=r[n]||{},r[n][this._id]=this}return this}})),w=y.extend({_class:"Group",_serializeFields:{children:[]},initialize:function(t){this._children=[],this._namedChildren={},this._initialize(t)||this.addChildren(Array.isArray(t)?t:arguments)},_changed:function ue(t){ue.base.call(this,t),2&t&&this._transformContent&&!this._matrix.isIdentity()&&this.applyMatrix(),258&t&&delete this._clipItem},_getClipItem:function(){if(this._clipItem!==t)return this._clipItem;for(var e=0,n=this._children.length;n>e;e++){var i=this._children[e];if(i._clipMask)return this._clipItem=i}return this._clipItem=null},getTransformContent:function(){return this._transformContent},setTransformContent:function(t){this._transformContent=t,t&&this.applyMatrix()},isClipped:function(){return!!this._getClipItem()},setClipped:function(t){var e=this.getFirstChild();e&&e.setClipMask(t)},_draw:function(t,e){var n=e.clipItem=this._getClipItem();n&&n.draw(t,e.extend({clip:!0}));for(var i=0,r=this._children.length;r>i;i++){var s=this._children[i];s!==n&&s.draw(t,e)}e.clipItem=null}}),x=w.extend({_class:"Layer",initialize:function(){this._project=paper.project,this._index=this._project.layers.push(this)-1,w.apply(this,arguments),this.activate()},_remove:function le(t){return this._parent?le.base.call(this,t):null!=this._index?(this._project.activeLayer===this&&(this._project.activeLayer=this.getNextSibling()||this.getPreviousSibling()),e.splice(this._project.layers,null,this._index,1),this._project._needsRedraw=!0,!0):!1},getNextSibling:function ce(){return this._parent?ce.base.call(this):this._project.layers[this._index+1]||null},getPreviousSibling:function de(){return this._parent?de.base.call(this):this._project.layers[this._index-1]||null},isInserted:function fe(){return this._parent?fe.base.call(this):null!=this._index},activate:function(){this._project.activeLayer=this},_insert:function _e(t,n,i){return n instanceof x&&!n._parent&&this._remove(!0)?(e.splice(n._project.layers,[this],n._index+(t?1:0),0),this._setProject(n._project),this):_e.base.call(this,t,n,i)}}),b=y.extend({_class:"Shape",_transformContent:!1,_boundsSelected:!0,initialize:function(t,e,n,i,r){this._shape=t,this._size=n,this._radius=i,this._initialize(r,e)},_equals:function(t){return this._shape===t._shape&&this._size.equals(t._size)&&e.equals(this._radius,t._radius)},clone:function(t){return this._clone(new b(this._shape,this.getPosition(!0),this._size.clone(),this._radius.clone?this._radius.clone():this._radius,{insert:!1}),t)},getShape:function(){return this._shape},getSize:function(){var t=this._size;return new d(t.width,t.height,this,"setSize")},setSize:function(){var t=this._shape,e=c.read(arguments);if(!this._size.equals(e)){var n=e.width,i=e.height;if("rectangle"===t){var r=c.min(this._radius,e.divide(2));this._radius.set(r.width,r.height)}else"circle"===t?(n=i=(n+i)/2,this._radius=n/2):"ellipse"===t&&this._radius.set(n/2,i/2);this._size.set(n,i),this._changed(5)}},getRadius:function(){var t=this._radius;return"circle"===this._shape?t:new d(t.width,t.height,this,"setRadius")},setRadius:function(t){var e=this._shape;if("circle"===e){if(t===this._radius)return;var n=2*t;this._size.set(n,n)}else{if(t=c.read(arguments),this._radius.equals(t))return;if(this._radius.set(t.width,t.height),"rectangle"===e){var n=c.max(this._size,t.multiply(2));this._size.set(n.width,n.height)}else"ellipse"===e&&this._size.set(2*t.width,2*t.height)}this._changed(5)},isEmpty:function(){return!1},toPath:function(n){var i=new(O[e.capitalize(this._shape)])({center:new h,size:this._size,radius:this._radius,insert:!1});return i.transform(this._matrix),i.setStyle(this._style),(n||n===t)&&i.insertAbove(this),i},_draw:function(t,e){var n=this._style,i=n.hasFill(),r=n.hasStroke(),s=e.clip;if(i||r||s){var a=this._radius,h=this._shape;if(t.beginPath(),"circle"===h)t.arc(0,0,a,0,2*Math.PI,!0);else{var u=a.width,l=a.height,c=o.KAPPA;if("ellipse"===h){var d=u*c,f=l*c;t.moveTo(-u,0),t.bezierCurveTo(-u,-f,-d,-l,0,-l),t.bezierCurveTo(d,-l,u,-f,u,0),t.bezierCurveTo(u,f,d,l,0,l),t.bezierCurveTo(-d,l,-u,f,-u,0)}else{var _=this._size,g=_.width,p=_.height;if(0===u&&0===l)t.rect(-g/2,-p/2,g,p);else{c=1-c;var v=g/2,m=p/2,d=u*c,f=l*c;t.moveTo(-v,-m+l),t.bezierCurveTo(-v,-m+f,-v+d,-m,-v+u,-m),t.lineTo(v-u,-m),t.bezierCurveTo(v-d,-m,v,-m+f,v,-m+l),t.lineTo(v,m-l),t.bezierCurveTo(v,m-f,v-d,m,v-u,m),t.lineTo(-v+u,m),t.bezierCurveTo(-v+d,m,-v,m-f,-v,m-l)}}}t.closePath()}s||!i&&!r||(this._setStyles(t),i&&t.fill(n.getWindingRule()),r&&t.stroke())},_canComposite:function(){return!(this.hasFill()&&this.hasStroke())},_getBounds:function(t,e){var n=new f(this._size).setCenter(0,0);return"getBounds"!==t&&this.hasStroke()&&(n=n.expand(this.getStrokeWidth())),e?e._transformBounds(n):n}},new function(){function t(t,e,n){var i=t._radius;if(!i.isZero())for(var r=t._size.divide(2),s=0;4>s;s++){var a=new h(1&s?1:-1,s>1?1:-1),o=a.multiply(r),u=o.subtract(a.multiply(i)),l=new f(o,u);if((n?l.expand(n):l).contains(e))return u}}function e(t,e){var n=t.getAngleInRadians(),i=2*e.width,r=2*e.height,s=i*Math.sin(n),a=r*Math.cos(n);return i*r/(2*Math.sqrt(s*s+a*a))}return{_contains:function n(e){if("rectangle"===this._shape){var i=t(this,e);return i?e.subtract(i).divide(this._radius).getLength()<=1:n.base.call(this,e)}return e.divide(this.size).getLength()<=.5},_hitTest:function i(n,r){var s=!1;if(this.hasStroke()){var a=this._shape,o=this._radius,h=this.getStrokeWidth()+2*r.tolerance;if("rectangle"===a){var u=t(this,n,h);if(u){var l=n.subtract(u);s=2*Math.abs(l.getLength()-e(l,o))<=h}else{var c=new f(this._size).setCenter(0,0),d=c.expand(h),_=c.expand(-h);s=d._containsPoint(n)&&!_._containsPoint(n)}}else"ellipse"===a&&(o=e(n,o)),s=2*Math.abs(n.getLength()-o)<=h}return s?new P("stroke",this):i.base.apply(this,arguments)}}},{statics:new function(){function t(t,n,i,r,s){return new b(t,n,i,r,e.getNamed(s))}return{Circle:function(){var n=h.readNamed(arguments,"center"),i=e.readNamed(arguments,"radius");return t("circle",n,new c(2*i),i,arguments)},Rectangle:function(){var e=f.readNamed(arguments,"rectangle"),n=c.min(c.readNamed(arguments,"radius"),e.getSize(!0).divide(2));return t("rectangle",e.getCenter(!0),e.getSize(!0),n,arguments)},Ellipse:function(){var e=b._readEllipse(arguments);return radius=e.radius,t("ellipse",e.center,radius.multiply(2),radius,arguments)},_readEllipse:function(t){var n,i;if(e.hasNamed(t,"radius"))n=h.readNamed(t,"center"),i=c.readNamed(t,"radius");else{var r=f.readNamed(t,"rectangle");n=r.getCenter(!0),i=r.getSize(!0).divide(2)}return{center:n,radius:i}}}}}),C=y.extend({_class:"Raster",_transformContent:!1,_boundsGetter:"getBounds",_boundsSelected:!0,_serializeFields:{source:null},initialize:function(e,n){this._initialize(e,n!==t&&h.read(arguments,1))||("string"==typeof e?this.setSource(e):this.setImage(e)),this._size||(this._size=new c)},_equals:function(t){return this.getSource()===t.getSource()},clone:function(t){var e={insert:!1},n=this._image;if(n)e.image=n;else if(this._canvas){var i=e.canvas=K.getCanvas(this._size);i.getContext("2d").drawImage(this._canvas,0,0)}return this._clone(new C(e),t)},getSize:function(){var t=this._size;return new d(t.width,t.height,this,"setSize")},setSize:function(){var t=c.read(arguments);if(!this._size.equals(t)){var e=this.getElement();this.setCanvas(K.getCanvas(t)),e&&this.getContext(!0).drawImage(e,0,0,t.width,t.height)}},getWidth:function(){return this._size.width},getHeight:function(){return this._size.height},isEmpty:function(){return 0==this._size.width&&0==this._size.height},getPpi:function(){var t=this._matrix,e=new h(0,0).transform(t),n=new h(1,0).transform(t).subtract(e),i=new h(0,1).transform(t).subtract(e);return new c(72/n.getLength(),72/i.getLength())},getImage:function(){return this._image},setImage:function(t){this._canvas&&K.release(this._canvas),t.getContext?(this._image=null,this._canvas=t):(this._image=t,this._canvas=null),this._size=new c(t.naturalWidth||t.width,t.naturalHeight||t.height),this._context=null,this._changed(133)},getCanvas:function(){if(!this._canvas){var t=K.getContext(this._size);try{this._image&&t.drawImage(this._image,0,0),this._canvas=t.canvas}catch(e){K.release(t)}}return this._canvas},setCanvas:"#setImage",getContext:function(){return this._context||(this._context=this.getCanvas().getContext("2d")),arguments[0]&&(this._image=null,this._changed(129)),this._context},setContext:function(t){this._context=t},getSource:function(){return this._image&&this._image.src||this.toDataURL()},setSource:function(t){function e(){var t=n._project.view;t&&(paper=t._scope),n.fire("load"),t&&t.draw(!0)}var n=this,i=document.getElementById(t)||new Image;i.naturalWidth&&i.naturalHeight?setTimeout(e,0):(V.add(i,{load:function(){n.setImage(i),e()}}),i.src||(i.src=t)),this.setImage(i)},getElement:function(){return this._canvas||this._image},getSubCanvas:function(t){t=f.read(arguments);var e=K.getContext(t.getSize());return e.drawImage(this.getCanvas(),t.x,t.y,t.width,t.height,0,0,t.width,t.height),e.canvas},getSubRaster:function(t){t=f.read(arguments);var e=new C({canvas:this.getSubCanvas(t),insert:!1});return e.translate(t.getCenter().subtract(this.getSize().divide(2))),e._matrix.preConcatenate(this._matrix),e.insertAbove(this),e},toDataURL:function(){var t=this._image&&this._image.src;if(/^data:/.test(t))return t;var e=this.getCanvas();return e?e.toDataURL():null},drawImage:function(t,e){e=h.read(arguments,1),this.getContext(!0).drawImage(t,e.x,e.y) -},getAverageColor:function(t){var n,i;t?t instanceof A?(i=t,n=t.getBounds()):t.width?n=new f(t):t.x&&(n=new f(t.x-.5,t.y-.5,1,1)):n=this.getBounds();var r=32,s=Math.min(n.width,r),a=Math.min(n.height,r),o=C._sampleContext;o?o.clearRect(0,0,r+1,r+1):o=C._sampleContext=K.getContext(new c(r)),o.save();var h=(new g).scale(s/n.width,a/n.height).translate(-n.x,-n.y);h.applyToContext(o),i&&i.draw(o,e.merge({clip:!0,transforms:[h]})),this._matrix.applyToContext(o),o.drawImage(this.getElement(),-this._size.width/2,-this._size.height/2),o.restore();for(var u=o.getImageData(.5,.5,Math.ceil(s),Math.ceil(a)).data,l=[0,0,0],d=0,_=0,p=u.length;p>_;_+=4){var v=u[_+3];d+=v,v/=255,l[0]+=u[_]*v,l[1]+=u[_+1]*v,l[2]+=u[_+2]*v}for(var _=0;3>_;_++)l[_]/=d;return d?B.read(l):null},getPixel:function(t){t=h.read(arguments);var e=this.getContext().getImageData(t.x,t.y,1,1).data;return new B("rgb",[e[0]/255,e[1]/255,e[2]/255],e[3]/255)},setPixel:function(){var t=h.read(arguments),e=B.read(arguments),n=e._convert("rgb"),i=e._alpha,r=this.getContext(!0),s=r.createImageData(1,1),a=s.data;a[0]=255*n[0],a[1]=255*n[1],a[2]=255*n[2],a[3]=null!=i?255*i:255,r.putImageData(s,t.x,t.y)},createImageData:function(t){return t=c.read(arguments),this.getContext().createImageData(t.width,t.height)},getImageData:function(t){return t=f.read(arguments),t.isEmpty()&&(t=new f(this._size)),this.getContext().getImageData(t.x,t.y,t.width,t.height)},setImageData:function(t,e){e=h.read(arguments,1),this.getContext(!0).putImageData(t,e.x,e.y)},_getBounds:function(t,e){var n=new f(this._size).setCenter(0,0);return e?e._transformBounds(n):n},_hitTest:function(t){if(this._contains(t)){var e=this;return new P("pixel",e,{offset:t.add(e._size.divide(2)).round(),color:{get:function(){return e.getPixel(this.offset)}}})}},_draw:function(t){var e=this.getElement();e&&(t.globalAlpha=this._opacity,t.drawImage(e,-this._size.width/2,-this._size.height/2))},_canComposite:function(){return!0}}),S=y.extend({_class:"PlacedSymbol",_transformContent:!1,_boundsGetter:{getBounds:"getStrokeBounds"},_boundsSelected:!0,_serializeFields:{symbol:null},initialize:function(e,n){this._initialize(e,n!==t&&h.read(arguments,1))||this.setSymbol(e instanceof m?e:new m(e))},_equals:function(t){return this._symbol===t._symbol},getSymbol:function(){return this._symbol},setSymbol:function(t){this._symbol&&delete this._symbol._instances[this._id],this._symbol=t,t._instances[this._id]=this},clone:function(t){return this._clone(new S({symbol:this.symbol,insert:!1}),t)},isEmpty:function(){return this._symbol._definition.isEmpty()},_getBounds:function(t,e){return this.symbol._definition._getCachedBounds(t,e)},_hitTest:function(t,e,n){var i=this._symbol._definition._hitTest(t,e,n);return i&&(i.item=this),i},_draw:function(t,e){this.symbol._definition.draw(t,e)}}),P=e.extend({_class:"HitResult",initialize:function(t,e,n){this.type=t,this.item=e,n&&(n.enumerable=!0,this.inject(n))},statics:{getOptions:function(t){return t&&t._merged?t:e.merge({type:null,tolerance:paper.project.options.hitTolerance||2,fill:!t,stroke:!t,segments:!t,handles:!1,ends:!1,center:!1,bounds:!1,guides:!1,selected:!1,_merged:!0},t)}}}),k=e.extend({_class:"Segment",initialize:function(e,n,i,r,s,a){var o,h,u,l=arguments.length;0===l||(1===l?e.point?(o=e.point,h=e.handleIn,u=e.handleOut):o=e:2===l&&"number"==typeof e?o=arguments:3>=l?(o=e,h=n,u=i):(o=e!==t?[e,n]:null,h=i!==t?[i,r]:null,u=s!==t?[s,a]:null)),new z(o,this,"_point"),new z(h,this,"_handleIn"),new z(u,this,"_handleOut")},_serialize:function(t){return e.serialize(this.isLinear()?this._point:[this._point,this._handleIn,this._handleOut],t,!0)},_changed:function(t){if(this._path){var e,n=this._path._curves&&this.getCurve();n&&(n._changed(),(e=n[t==this._point||t==this._handleIn&&n._segment1==this?"getPrevious":"getNext"]())&&e._changed()),this._path._changed(5)}},getPoint:function(){return this._point},setPoint:function(t){t=h.read(arguments),this._point.set(t.x,t.y)},getHandleIn:function(){return this._handleIn},setHandleIn:function(t){t=h.read(arguments),this._handleIn.set(t.x,t.y)},getHandleOut:function(){return this._handleOut},setHandleOut:function(t){t=h.read(arguments),this._handleOut.set(t.x,t.y)},isLinear:function(){return this._handleIn.isZero()&&this._handleOut.isZero()},setLinear:function(){this._handleIn.set(0,0),this._handleOut.set(0,0)},isColinear:function(t){var e=this.getNext(),n=t.getNext();return this._handleOut.isZero()&&e._handleIn.isZero()&&t._handleOut.isZero()&&n._handleIn.isZero()&&e._point.subtract(this._point).isColinear(n._point.subtract(t._point))},isOrthogonal:function(){var t=this.getPrevious(),e=this.getNext();return t._handleOut.isZero()&&this._handleIn.isZero()&&this._handleOut.isZero()&&e._handleIn.isZero()&&this._point.subtract(t._point).isOrthogonal(e._point.subtract(this._point))},isArc:function(){var t=this.getNext(),e=this._handleOut,n=t._handleIn,i=o.KAPPA;if(e.isOrthogonal(n)){var r=this._point,s=t._point,a=new p(r,e,!0).intersect(new p(s,n,!0),!0);return a&&o.isZero(e.getLength()/a.subtract(r).getLength()-i)&&o.isZero(n.getLength()/a.subtract(s).getLength()-i)}return!1},_isSelected:function(t){var e=this._selectionState;return t==this._point?!!(4&e):t==this._handleIn?!!(1&e):t==this._handleOut?!!(2&e):!1},_setSelected:function(t,e){var n=this._path,e=!!e,i=this._selectionState||0,r=[!!(4&i),!!(1&i),!!(2&i)];if(t===this._point){if(e)r[1]=r[2]=!1;else{var s=this.getPrevious(),a=this.getNext();r[1]=s&&(s._point.isSelected()||s._handleOut.isSelected()),r[2]=a&&(a._point.isSelected()||a._handleIn.isSelected())}r[0]=e}else{var o=t===this._handleIn?1:2;r[o]!=e&&(e&&(r[0]=!1),r[o]=e)}this._selectionState=(r[0]?4:0)|(r[1]?1:0)|(r[2]?2:0),n&&i!=this._selectionState&&(n._updateSelection(this,i,this._selectionState),n._changed(33))},isSelected:function(){return this._isSelected(this._point)},setSelected:function(t){this._setSelected(this._point,t)},getIndex:function(){return this._index!==t?this._index:null},getPath:function(){return this._path||null},getCurve:function(){var t=this._path,e=this._index;return t?(t._closed||e!=t._segments.length-1||e--,t.getCurves()[e]||null):null},getLocation:function(){var t=this.getCurve();return t?new I(t,t.getNext()?0:1):null},getNext:function(){var t=this._path&&this._path._segments;return t&&(t[this._index+1]||this._path._closed&&t[0])||null},getPrevious:function(){var t=this._path&&this._path._segments;return t&&(t[this._index-1]||this._path._closed&&t[t.length-1])||null},reverse:function(){return new k(this._point,this._handleOut,this._handleIn)},remove:function(){return this._path?!!this._path.removeSegment(this._index):!1},clone:function(){return new k(this._point,this._handleIn,this._handleOut)},equals:function(t){return t===this||t&&this._class===t._class&&this._point.equals(t._point)&&this._handleIn.equals(t._handleIn)&&this._handleOut.equals(t._handleOut)||!1},toString:function(){var t=["point: "+this._point];return this._handleIn.isZero()||t.push("handleIn: "+this._handleIn),this._handleOut.isZero()||t.push("handleOut: "+this._handleOut),"{ "+t.join(", ")+" }"},_transformCoordinates:function(t,e,n){var i=this._point,r=n&&this._handleIn.isZero()?null:this._handleIn,s=n&&this._handleOut.isZero()?null:this._handleOut,a=i._x,o=i._y,h=2;return e[0]=a,e[1]=o,r&&(e[h++]=r._x+a,e[h++]=r._y+o),s&&(e[h++]=s._x+a,e[h++]=s._y+o),t&&(t._transformCoordinates(e,0,e,0,h/2),a=e[0],o=e[1],n?(i._x=a,i._y=o,h=2,r&&(r._x=e[h++]-a,r._y=e[h++]-o),s&&(s._x=e[h++]-a,s._y=e[h++]-o)):(r||(e[h++]=a,e[h++]=o),s||(e[h++]=a,e[h++]=o))),e}}),z=h.extend({initialize:function(e,n,i){var r,s,a;e?(r=e[0])!==t?s=e[1]:((r=e.x)===t&&(e=h.read(arguments),r=e.x),s=e.y,a=e.selected):r=s=0,this._x=r,this._y=s,this._owner=n,n[i]=this,a&&this.setSelected(!0)},set:function(t,e){return this._x=t,this._y=e,this._owner._changed(this),this},_serialize:function(t){var e=t.formatter,n=e.number(this._x),i=e.number(this._y);return this.isSelected()?{x:n,y:i,selected:!0}:[n,i]},getX:function(){return this._x},setX:function(t){this._x=t,this._owner._changed(this)},getY:function(){return this._y},setY:function(t){this._y=t,this._owner._changed(this)},isZero:function(){return o.isZero(this._x)&&o.isZero(this._y)},setSelected:function(t){this._owner._setSelected(this,t)},isSelected:function(){return this._owner._isSelected(this)}}),M=e.extend({_class:"Curve",initialize:function(t,e,n,i,r,s,a,o){var h=arguments.length;if(3===h)this._path=t,this._segment1=e,this._segment2=n;else if(0===h)this._segment1=new k,this._segment2=new k;else if(1===h)this._segment1=new k(t.segment1),this._segment2=new k(t.segment2);else if(2===h)this._segment1=new k(t),this._segment2=new k(e);else{var u,l,c,d;4===h?(u=t,l=e,c=n,d=i):8===h&&(u=[t,e],d=[a,o],l=[n-t,i-e],c=[r-a,s-o]),this._segment1=new k(u,null,l),this._segment2=new k(d,c,null)}},_changed:function(){delete this._length,delete this._bounds},getPoint1:function(){return this._segment1._point},setPoint1:function(t){t=h.read(arguments),this._segment1._point.set(t.x,t.y)},getPoint2:function(){return this._segment2._point},setPoint2:function(t){t=h.read(arguments),this._segment2._point.set(t.x,t.y)},getHandle1:function(){return this._segment1._handleOut},setHandle1:function(t){t=h.read(arguments),this._segment1._handleOut.set(t.x,t.y)},getHandle2:function(){return this._segment2._handleIn},setHandle2:function(t){t=h.read(arguments),this._segment2._handleIn.set(t.x,t.y)},getSegment1:function(){return this._segment1},getSegment2:function(){return this._segment2},getPath:function(){return this._path},getIndex:function(){return this._segment1._index},getNext:function(){var t=this._path&&this._path._curves;return t&&(t[this._segment1._index+1]||this._path._closed&&t[0])||null},getPrevious:function(){var t=this._path&&this._path._curves;return t&&(t[this._segment1._index-1]||this._path._closed&&t[t.length-1])||null},isSelected:function(){return this.getHandle1().isSelected()&&this.getHandle2().isSelected()},setSelected:function(t){this.getHandle1().setSelected(t),this.getHandle2().setSelected(t)},getValues:function(){return M.getValues(this._segment1,this._segment2)},getPoints:function(){for(var t=this.getValues(),e=[],n=0;8>n;n+=2)e.push(new h(t[n],t[n+1]));return e},getLength:function(){var t=arguments[0],e=arguments[1],n=0===arguments.length||0===t&&1===e;if(n&&null!=this._length)return this._length;var i=M.getLength(this.getValues(),t,e);return n&&(this._length=i),i},getArea:function(){return M.getArea(this.getValues())},getPart:function(t,e){return new M(M.getPart(this.getValues(),t,e))},isLinear:function(){return this._segment1._handleOut.isZero()&&this._segment2._handleIn.isZero()},getIntersections:function(t){return M.getIntersections(this.getValues(),t.getValues(),this,t,[])},reverse:function(){return new M(this._segment2.reverse(),this._segment1.reverse())},_getParameter:function(e,n){return n?e:e&&e.curve===this?e.parameter:e===t&&n===t?.5:this.getParameterAt(e,0)},divide:function(t,e){var n=this._getParameter(t,e),i=null;if(n>0&&1>n){var r=M.subdivide(this.getValues(),n),s=this.isLinear(),a=r[0],o=r[1];s||(this._segment1._handleOut.set(a[2]-a[0],a[3]-a[1]),this._segment2._handleIn.set(o[4]-o[6],o[5]-o[7]));var u=a[6],l=a[7],c=new k(new h(u,l),!s&&new h(a[4]-u,a[5]-l),!s&&new h(o[2]-u,o[3]-l));if(this._path)this._segment1._index>0&&0===this._segment2._index?this._path.add(c):this._path.insert(this._segment2._index,c),i=this;else{var d=this._segment2;this._segment2=c,i=new M(c,d)}}return i},split:function(t,e){return this._path?this._path.split(this._segment1._index,this._getParameter(t,e)):null},clone:function(){return new M(this._segment1,this._segment2)},toString:function(){var t=["point1: "+this._segment1._point];return this._segment1._handleOut.isZero()||t.push("handle1: "+this._segment1._handleOut),this._segment2._handleIn.isZero()||t.push("handle2: "+this._segment2._handleIn),t.push("point2: "+this._segment2._point),"{ "+t.join(", ")+" }"},statics:{getValues:function(t,e){var n=t._point,i=t._handleOut,r=e._handleIn,s=e._point;return[n._x,n._y,n._x+i._x,n._y+i._y,s._x+r._x,s._y+r._y,s._x,s._y]},evaluate:function(t,e,n){var i,r,s=t[0],a=t[1],o=t[2],u=t[3],l=t[4],c=t[5],d=t[6],f=t[7];if(0!==n||0!==e&&1!==e){var _=3*(o-s),g=3*(l-o)-_,p=d-s-_-g,v=3*(u-a),m=3*(c-u)-v,y=f-a-v-m;if(0===n)i=((p*e+g)*e+_)*e+s,r=((y*e+m)*e+v)*e+a;else{var w=1e-5;if(w>e&&o==s&&u==a||e>1-w&&l==d&&c==f?(i=l-o,r=c-u):(i=(3*p*e+2*g)*e+_,r=(3*y*e+2*m)*e+v),3===n){var x=6*p*e+2*g,b=6*y*e+2*m;return(i*b-r*x)/Math.pow(i*i+r*r,1.5)}}}else i=0===e?s:d,r=0===e?a:f;return 2==n?new h(r,-i):new h(i,r)},subdivide:function(e,n){var i=e[0],r=e[1],s=e[2],a=e[3],o=e[4],h=e[5],u=e[6],l=e[7];n===t&&(n=.5);var c=1-n,d=c*i+n*s,f=c*r+n*a,_=c*s+n*o,g=c*a+n*h,p=c*o+n*u,v=c*h+n*l,m=c*d+n*_,y=c*f+n*g,w=c*_+n*p,x=c*g+n*v,b=c*m+n*w,C=c*y+n*x;return[[i,r,d,f,m,y,b,C],[b,C,w,x,p,v,u,l]]},solveCubic:function(t,e,n,i,r,s){var a=t[e],h=t[e+2],u=t[e+4],l=t[e+6],c=3*(h-a),d=3*(u-h)-c,f=l-a-c-d;return o.solveCubic(f,d,c,a-n,i,r,s)},getParameterOf:function(t,e,n){if(Math.abs(t[0]-e)<1e-5&&Math.abs(t[1]-n)<1e-5)return 0;if(Math.abs(t[6]-e)<1e-5&&Math.abs(t[7]-n)<1e-5)return 1;for(var i,r,s=[],a=[],o=M.solveCubic(t,0,e,s),h=M.solveCubic(t,1,n,a),u=0;-1==o||o>u;)if(-1==o||(i=s[u++])>=0&&1>=i){for(var l=0;-1==h||h>l;)if((-1==h||(r=a[l++])>=0&&1>=r)&&(-1==o?i=r:-1==h&&(r=i),Math.abs(i-r)<1e-5))return.5*(i+r);if(-1==o)break}return null},getPart:function(t,e,n){return e>0&&(t=M.subdivide(t,e)[1]),1>n&&(t=M.subdivide(t,(n-e)/(1-e))[0]),t},isLinear:function(t){var e=o.isZero;return e(t[0]-t[2])&&e(t[1]-t[3])&&e(t[4]-t[6])&&e(t[5]-t[7])},isFlatEnough:function(t,e){var n=t[0],i=t[1],r=t[2],s=t[3],a=t[4],o=t[5],h=t[6],u=t[7],l=3*r-2*n-h,c=3*s-2*i-u,d=3*a-2*h-n,f=3*o-2*u-i;return Math.max(l*l,d*d)+Math.max(c*c,f*f)<10*e*e},getArea:function(t){var e=t[0],n=t[1],i=t[2],r=t[3],s=t[4],a=t[5],o=t[6],h=t[7];return(3*r*e-1.5*r*s-1.5*r*o-3*n*i-1.5*n*s-.5*n*o+1.5*a*e+1.5*a*i-3*a*o+.5*h*e+1.5*h*i+3*h*s)/10},getBounds:function(t){for(var e=t.slice(0,2),n=e.slice(),i=[0,0],r=0;2>r;r++)M._addBounds(t[r],t[r+2],t[r+4],t[r+6],r,0,e,n,i);return new f(e[0],e[1],n[0]-e[0],n[1]-e[1])},_addBounds:function(t,e,n,i,r,s,a,h,u){function l(t,e){var n=t-e,i=t+e;nh[r]&&(h[r]=i)}var c=3*(e-n)-t+i,d=2*(t+n)-4*e,f=e-t,_=o.solveQuadratic(c,d,f,u),g=1e-5,p=1-g;l(i,0);for(var v=0;_>v;v++){var m=u[v],y=1-m;m>g&&p>m&&l(y*y*y*t+3*y*y*m*e+3*y*m*m*n+m*m*m*i,s)}},_getWinding:function(t,e,n,i,r){function s(t){var e=t[1],i=t[7],r=1;if(e>i){var s=e;e=i,i=s,r=-1}return(e>n||n>i)&&(r=0),r}var a=1e-5,h=Math.abs;if(M.isLinear(t)){var u=s(t);if(!u)return 0;var l=(t[6]-t[0])*(n-t[1])-(t[7]-t[1])*(e-t[0]);return(-a>l?-1:1)==u?0:u}for(var c,d=t[1],f=t[3],_=t[5],g=t[7],p=3*(f-_)-d+g,v=2*(d+_)-4*f,m=f-d,y=o.solveQuadratic(p,v,m,i,a,1-a),w=t,x=i[0],b=0,C=0;y>=C;C++){if(C===y)c=w;else{var S=M.subdivide(w,x);c=S[0],w=S[1],x=i[C],x=(i[C+1]-x)/(1-x)}C>0&&(c[3]=c[1]),y>C&&(c[5]=w[1]);var u=s(c);if(u){var P,k;if(1===M.solveCubic(c,1,n,r,-a,1+-a))P=r[0],k=M.evaluate(c,P,0).x;else{var z=(c[1]+c[7])/2;if(P=z>n&&u>0?0:1,1===P&&n==c[7])continue;k=0===P?c[0]:c[6]}var I=h(M.evaluate(c,P,1).y)=k+(I?-a:a*u))||I&&(h(P)0?1:0))e?1:0)},getParameterOf:function(t){return t=h.read(arguments),M.getParameterOf(this.getValues(),t.x,t.y)},getLocationAt:function(t,e){return e||(t=this.getParameterAt(t)),new I(this,t)},getLocationOf:function(t){t=h.read(arguments);var e=this.getParameterOf(t);return null!=e?new I(this,e):null},getNearestLocation:function(t){function e(e){if(e>=0&&1>=e){var i=t.getDistance(M.evaluate(n,e,0),!0);if(s>i)return s=i,a=e,!0}}t=h.read(arguments);for(var n=this.getValues(),i=100,r=o.TOLERANCE,s=1/0,a=0,u=0;i>=u;u++)e(u/i);for(var l=1/(2*i);l>r;)e(a-l)||e(a+l)||(l/=2);var c=M.evaluate(n,a,0);return new I(this,a,c,null,null,null,t.getDistance(c))},getNearestPoint:function(t){return t=h.read(arguments),this.getNearestLocation(t).getPoint()}}),new function(){function e(t){var e=t[0],n=t[1],i=t[2],r=t[3],s=t[4],a=t[5],o=t[6],h=t[7],u=9*(i-s)+3*(o-e),l=6*(e+s)-12*i,c=3*(i-e),d=9*(r-a)+3*(h-n),f=6*(n+a)-12*r,_=3*(r-n);return function(t){var e=(u*t+l)*t+c,n=(d*t+f)*t+_;return Math.sqrt(e*e+n*n)}}function n(t,e){return Math.max(2,Math.min(16,Math.ceil(32*Math.abs(e-t))))}return{statics:!0,getLength:function(i,r,s){r===t&&(r=0),s===t&&(s=1);var a=o.isZero;if(a(i[0]-i[2])&&a(i[1]-i[3])&&a(i[6]-i[4])&&a(i[7]-i[5])){var h=i[6]-i[0],u=i[7]-i[1];return(s-r)*Math.sqrt(h*h+u*u)}var l=e(i);return o.integrate(l,r,s,n(r,s))},getParameterAt:function(t,i,r){function s(t){var e=n(r,t);return f+=t>r?o.integrate(l,r,t,e):-o.integrate(l,t,r,e),r=t,f-i}if(0===i)return r;var a=i>0,h=a?r:0,u=a?1:r,i=Math.abs(i),l=e(t),c=o.integrate(l,h,u,n(h,u));if(i>=c)return a?u:h;var d=i/c,f=0;return o.findRoot(s,l,a?h+d:u-d,h,u,16,1e-5)}}},new function(){function t(t,e,n,i,r,s,a){var o=t[0],h=t[t.length-1];o&&i.equals(o._point)||h&&i.equals(h._point)||t.push(new I(e,n,i,r,s,a))}function e(i,r,s,a,o,h,u,l){if(l=(l||0)+1,!(l>20)){h=h||[0,1],u=u||[0,1];for(var c=M.getPart(i,h[0],h[1]),d=M.getPart(r,u[0],u[1]),f=0;f++<20;){var _,g=n(c,d,_=u.slice()),p=0;if(0===g)break;if(g>0){if(u=_,d=M.getPart(r,u[0],u[1]),p=n(d,c,_=h.slice()),0===p)break;g>0&&(h=_,c=M.getPart(i,h[0],h[1]))}if(0>g||0>p){if(h[1]-h[0]>u[1]-u[0]){var v=(h[0]+h[1])/2;e(i,r,s,a,o,[h[0],v],u,l),e(i,r,s,a,o,[v,h[1]],u,l);break}var v=(u[0]+u[1])/2;e(i,r,s,a,o,h,[u[0],v],l),e(i,r,s,a,o,h,[v,u[1]],l);break}if(Math.abs(h[1]-h[0])<=1e-5&&Math.abs(u[1]-u[0])<=1e-5){var m=(h[0]+h[1])/2,y=(u[0]+u[1])/2;t(o,s,m,M.evaluate(i,m,0),a,y,M.evaluate(r,y,0));break}}}}function n(t,e,n){var r=t[0],s=t[1],a=t[2],o=t[3],h=t[4],u=t[5],l=t[6],c=t[7],d=e[0],f=e[1],_=e[2],g=e[3],v=e[4],m=e[5],y=e[6],w=e[7],x=p.getSignedDistance,b=x(r,s,l,c,a,o)||0,C=x(r,s,l,c,h,u)||0,S=b*C>0?.75:4/9,P=S*Math.min(0,b,C),k=S*Math.max(0,b,C),z=x(r,s,l,c,d,f),I=x(r,s,l,c,_,g),A=x(r,s,l,c,v,m),O=x(r,s,l,c,y,w);if(P>Math.max(z,I,A,O)||kO&&(L=P,P=k,k=L);for(var D=-1/0,E=1/0,j=-1/0,B=0,N=T.length;N>B;B++){var R=T[B],F=T[(B+1)%N];F[1]=V&&H>=P){var W=q+(P-V)/U;E>W&&(E=W),W>D&&(D=W)}if(k>=V&&H>=k){var W=q+(k-V)/U;W>j&&(j=W),E>W&&(E=0)}}if(1/0!==E&&j!==-1/0){var X=Math.min(P,k),G=Math.max(P,k);O>X&&G>O&&(j=1),z>X&&G>z&&(E=0),D>j&&(j=1);var J=n[0],$=n[1]-J;if(n[0]=J+E*$,n[1]=J+j*$,($-(n[1]-n[0]))/$>=.2)return 1}return M.getBounds(t).touches(M.getBounds(e))?-1:0}function i(t,e,n,i){var r=[0,t],s=[1/3,e],a=[2/3,n],o=[1,i],h=p.getSignedDistance,u=h(0,t,1,i,1/3,e),l=h(0,t,1,i,2/3,n);if(0>u*l)return[r,s,o,a];var c,d;return Math.abs(u)>Math.abs(l)?(c=s,d=(i-n-(i-t)/3)*(2*(i-n)-i+e)/3):(c=a,d=(e-t+(t-i)/3)*(-2*(t-e)+t-n)/3),0>d?[r,c,o]:[r,s,a,o]}function r(e,n,i,r,s){for(var a=M.isLinear(e),o=a?n:e,h=a?e:n,u=h[0],l=h[1],c=h[6],d=h[7],f=c-u,_=d-l,g=Math.atan2(-_,f),p=Math.sin(g),v=Math.cos(g),m=f*v-_*p,y=[0,0,0,0,m,0,m,0],w=[],x=0;8>x;x+=2){var b=o[x]-u,C=o[x+1]-l;w.push(b*v-C*p,C*v+b*p)}for(var S=[],P=M.solveCubic(w,1,0,S,0,1),x=0;P>x;x++){var k=S[x],b=M.evaluate(w,k,0).x;if(b>=0&&m>=b){var z=M.getParameterOf(y,b,0),I=a?z:k,A=a?k:z;t(s,i,I,M.evaluate(e,I,0),r,A,M.evaluate(n,A,0))}}}function s(e,n,i,r,s){var a=p.intersect(e[0],e[1],e[6],e[7],n[0],n[1],n[6],n[7]);a&&t(s,i,null,a,r)}return{statics:{getIntersections:function(t,n,i,a,o){var h=M.isLinear(t),u=M.isLinear(n);return(h&&u?s:h||u?r:e)(t,n,i,a,o),o}}}}),I=e.extend({_class:"CurveLocation",initialize:function ge(t,e,n,i,r,s,a){this._id=ge._id=(ge._id||0)+1,this._curve=t,this._segment1=t._segment1,this._segment2=t._segment2,this._parameter=e,this._point=n,this._curve2=i,this._parameter2=r,this._point2=s,this._distance=a},getSegment:function(){if(!this._segment){var t=this.getCurve(),e=this.getParameter();if(1===e)this._segment=t._segment2;else if(0===e||arguments[0])this._segment=t._segment1;else{if(null==e)return null;this._segment=t.getLength(0,e)a;a++)s[a]=i[a].getValues();for(var a=0,o=n.length;o>a;a++)for(var h=n[a],u=h.getValues(),l=0;r>l;l++)M.getIntersections(u,s[l],h,i[l],e);return e},setPathData:function(t){function e(t,e,n){var r=parseFloat(i[t]);return a&&(r+=o[e]),n&&(o[e]=r),r}function n(t,n){return new h(e(t,"x",n),e(t+1,"y",n))}var i,r,s=t.match(/[a-z][^a-z]*/gi),a=!1,o=new h;"path"===this._type?this.removeSegments():this.removeChildren();for(var u=0,l=s.length;l>u;u++){var c=s[u],d=c[0],f=d.toLowerCase();i=c.slice(1).trim().split(/[\s,]+|(?=[+-])/),a=d===f;var _=i.length;switch(f){case"m":case"l":for(var g=0;_>g;g+=2)this[0===g&&"m"===f?"moveTo":"lineTo"](n(g,!0));break;case"h":case"v":for(var p="h"==f?"x":"y",g=0;_>g;g++)e(g,p,!0),this.lineTo(o);break;case"c":for(var g=0;_>g;g+=6)this.cubicCurveTo(n(g),r=n(g+2),n(g+4,!0));break;case"s":for(var g=0;_>g;g+=4)this.cubicCurveTo(o.multiply(2).subtract(r),r=n(g),n(g+2,!0));break;case"q":for(var g=0;_>g;g+=4)this.quadraticCurveTo(r=n(g),n(g+2,!0));break;case"t":for(var g=0;_>g;g+=2)this.quadraticCurveTo(r=o.multiply(2).subtract(r),n(g,!0));break;case"a":break;case"z":this.closePath()}}},_canComposite:function(){return!(this.hasFill()&&this.hasStroke())},_contains:function(t){var e=this._getWinding(t);return!!("evenodd"===this.getWindingRule()?1&e:e)}}),O=A.extend({_class:"Path",_serializeFields:{segments:[],closed:!1},initialize:function(e){this._closed=!1,this._segments=[];var n=Array.isArray(e)?"object"==typeof e[0]?e:arguments:e&&(e.point!==t&&e.size===t||e.x!==t)?arguments:null;this.setSegments(n||[]),this._initialize(!n&&e)},_equals:function(t){return e.equals(this._segments,t._segments)},clone:function(e){var n=this._clone(new O({segments:this._segments,insert:!1}),e);return n._closed=this._closed,this._clockwise!==t&&(n._clockwise=this._clockwise),n},_changed:function pe(t){if(pe.base.call(this,t),4&t){if(delete this._length,delete this._clockwise,this._curves)for(var e=0,n=this._curves.length;n>e;e++)this._curves[e]._changed(5)}else 8&t&&delete this._bounds},getSegments:function(){return this._segments},setSegments:function(t){var e=this.isFullySelected();this._segments.length=0,this._selectedSegmentState=0,delete this._curves,this._add(k.readAll(t)),e&&this.setFullySelected(!0)},getFirstSegment:function(){return this._segments[0]},getLastSegment:function(){return this._segments[this._segments.length-1]},getCurves:function(){var t=this._curves,e=this._segments;if(!t){var n=this._countCurves();t=this._curves=Array(n);for(var i=0;n>i;i++)t[i]=new M(this,e[i],e[i+1]||e[0])}return t},getFirstCurve:function(){return this.getCurves()[0]},getLastCurve:function(){var t=this.getCurves();return t[t.length-1]},getPathData:function(){function t(t,e,s){var a=t._point,o=e._point,h=t._handleOut,u=e._handleIn;if(h.isZero()&&u.isZero())s||r.push("L"+i.point(o,n));else{var l=o.subtract(a);r.push("c"+i.point(h,n)+" "+i.point(l.add(u),n)+" "+i.point(l,n))}}var e=this._segments,n=arguments[0],i=a.instance,r=[];if(0===e.length)return"";r.push("M"+i.point(e[0]._point));for(var s=0,o=e.length-1;o>s;s++)t(e[s],e[s+1],!1);return this._closed&&(t(e[e.length-1],e[0],!0),r.push("z")),r.join("")},isClosed:function(){return this._closed},setClosed:function(t){if(this._closed!=(t=!!t)){if(this._closed=t,this._curves){var e=this._curves.length=this._countCurves();t&&(this._curves[e-1]=new M(this,this._segments[e-1],this._segments[0]))}this._changed(5)}},isEmpty:function(){return 0===this._segments.length},isPolygon:function(){for(var t=0,e=this._segments.length;e>t;t++)if(!this._segments[t].isLinear())return!1;return!0},_applyMatrix:function(t){for(var e=Array(6),n=0,i=this._segments.length;i>n;n++)this._segments[n]._transformCoordinates(t,e,!0);return!0},_add:function(t,e){for(var n=this._segments,i=this._curves,r=t.length,s=null==e,e=s?n.length:e,a=0;r>a;a++){var o=t[a];o._path&&(o=t[a]=o.clone()),o._path=this,o._index=e+a,o._selectionState&&this._updateSelection(o,0,o._selectionState)}if(s)n.push.apply(n,t);else{n.splice.apply(n,[e,0].concat(t));for(var a=e+r,h=n.length;h>a;a++)n[a]._index=a}if(i||t._curves){i||(i=this._curves=[]);var u=e>0?e-1:e,l=u,c=Math.min(u+r,this._countCurves());t._curves&&(i.splice.apply(i,[u,0].concat(t._curves)),l+=t._curves.length);for(var a=l;c>a;a++)i.splice(a,0,new M(this,null,null));this._adjustCurves(u,c)}return this._changed(5),t},_adjustCurves:function(t,e){for(var n,i=this._segments,r=this._curves,s=t;e>s;s++)n=r[s],n._path=this,n._segment1=i[s],n._segment2=i[s+1]||i[0];(n=r[this._closed&&0===t?i.length-1:t-1])&&(n._segment2=i[t]||i[0]),(n=r[e])&&(n._segment1=i[e])},_countCurves:function(){var t=this._segments.length;return!this._closed&&t>0?t-1:t},add:function(t){return arguments.length>1&&"number"!=typeof t?this._add(k.readAll(arguments)):this._add([k.read(arguments)])[0]},insert:function(t,e){return arguments.length>2&&"number"!=typeof e?this._add(k.readAll(arguments,1),t):this._add([k.read(arguments,1)],t)[0]},addSegment:function(){return this._add([k.read(arguments)])[0]},insertSegment:function(t){return this._add([k.read(arguments,1)],t)[0]},addSegments:function(t){return this._add(k.readAll(t))},insertSegments:function(t,e){return this._add(k.readAll(e),t)},removeSegment:function(t){return this.removeSegments(t,t+1)[0]||null},removeSegments:function(t,n){t=t||0,n=e.pick(n,this._segments.length);var i=this._segments,r=this._curves,s=i.length,a=i.splice(t,n-t),o=a.length;if(!o)return a;for(var h=0;o>h;h++){var u=a[h];u._selectionState&&this._updateSelection(u,u._selectionState,0),delete u._index,delete u._path}for(var h=t,l=i.length;l>h;h++)i[h]._index=h;if(r){var c=t>0&&n===s+(this._closed?1:0)?t-1:t,r=r.splice(c,o);arguments[2]&&(a._curves=r.slice(1)),this._adjustCurves(c,c)}return this._changed(5),a},isFullySelected:function(){var t=this._segments.length;return this._selected&&t>0&&this._selectedSegmentState===4*t},setFullySelected:function(t){t&&this._selectSegments(!0),this.setSelected(t)},setSelected:function ve(t){t||this._selectSegments(!1),ve.base.call(this,t)},_selectSegments:function(t){var e=this._segments.length;this._selectedSegmentState=t?4*e:0;for(var n=0;e>n;n++)this._segments[n]._selectionState=t?4:0},_updateSelection:function(t,e,n){t._selectionState=n;var i=this._selectedSegmentState+=n-e;i>0&&this.setSelected(!0)},flatten:function(t){for(var e=new T(this),n=0,i=e.length/Math.ceil(e.length/t),r=e.length+(this._closed?-i:i)/2,s=[];r>=n;)s.push(new k(e.evaluate(n,0))),n+=i;this.setSegments(s)},simplify:function(t){if(this._segments.length>2){var e=new D(this,t||2.5);this.setSegments(e.fit())}},split:function(t,e){if(null!==e){if(1===arguments.length){var n=t;"number"==typeof n&&(n=this.getLocationAt(n)),t=n.index,e=n.parameter}e>=1&&(t++,e--);var i=this.getCurves();if(t>=0&&t0&&i[t++].divide(e,!0);var r,s=this.removeSegments(t,this._segments.length,!0);return this._closed?(this.setClosed(!1),r=this):t>0&&(r=this._clone((new O).insertAbove(this,!0))),r._add(s,0),this.addSegment(s[0]),r}return null}},isClockwise:function(){return this._clockwise!==t?this._clockwise:O.isClockwise(this._segments)},setClockwise:function(t){this.isClockwise()!=(t=!!t)&&this.reverse(),this._clockwise=t},reverse:function(){this._segments.reverse();for(var e=0,n=this._segments.length;n>e;e++){var i=this._segments[e],r=i._handleIn;i._handleIn=i._handleOut,i._handleOut=r,i._index=e}delete this._curves,this._clockwise!==t&&(this._clockwise=!this._clockwise)},join:function(t){if(t){var e=t._segments,n=this.getLastSegment(),i=t.getLastSegment();n._point.equals(i._point)&&t.reverse();var r,s=t.getFirstSegment();return n._point.equals(s._point)?(n.setHandleOut(s._handleOut),this._add(e.slice(1))):(r=this.getFirstSegment(),r._point.equals(s._point)&&t.reverse(),i=t.getLastSegment(),r._point.equals(i._point)?(r.setHandleIn(i._handleIn),this._add(e.slice(0,e.length-1),0)):this._add(e.slice())),t.closed&&this._add([e[0]]),t.remove(),r=this.getFirstSegment(),n=this.getLastSegment(),n._point.equals(r._point)&&(r.setHandleIn(n._handleIn),n.remove(),this.setClosed(!0)),this._changed(5),!0}return!1},getLength:function(){if(null==this._length){var t=this.getCurves();this._length=0;for(var e=0,n=t.length;n>e;e++)this._length+=t[e].getLength()}return this._length},getArea:function(){for(var t=this.getCurves(),e=0,n=0,i=t.length;i>n;n++)e+=t[n].getArea();return e},_getOffset:function(t){var e=t&&t.getIndex();if(null!=e){for(var n=this.getCurves(),i=0,r=0;e>r;r++)i+=n[r].getLength();var s=n[e];return i+s.getLength(0,t.getParameter())}return null},getLocationOf:function(t){t=h.read(arguments);for(var e=this.getCurves(),n=0,i=e.length;i>n;n++){var r=e[n].getLocationOf(t);if(r)return r}return null},getLocationAt:function(t,e){var n=this.getCurves(),i=0;if(e){var r=~~t;return n[r].getLocationAt(t-r,!0)}for(var s=0,a=n.length;a>s;s++){var o=i,h=n[s];if(i+=h.getLength(),i>=t)return h.getLocationAt(t-o)}return t<=this.getLength()?new I(n[n.length-1],1):null},getPointAt:function(t,e){var n=this.getLocationAt(t,e);return n&&n.getPoint()},getTangentAt:function(t,e){var n=this.getLocationAt(t,e);return n&&n.getTangent()},getNormalAt:function(t,e){var n=this.getLocationAt(t,e);return n&&n.getNormal()},getNearestLocation:function(t){t=h.read(arguments);for(var e=this.getCurves(),n=1/0,i=null,r=0,s=e.length;s>r;r++){var a=e[r].getNearestLocation(t); -a._distanceh;h++){var l=n[h].getValues(),c=l[0],d=l[1];(c!==l[2]||d!==l[3]||c!==l[4]||d!==l[5]||c!==l[6]||d!==l[7])&&(r+=M._getWinding(l,t.x,t.y,s,a))}return e||(r+=M._getWinding(o,t.x,t.y,s,a)),r},_hitTest:function(e,n){function i(n,i,r){return e.getDistance(i)s;s++)r+=M._getWinding(a(s),t.x,t.y,n,i);return!!r}function h(t){return("round"!==u||"round"!==l)&&(d=[],v||t._index>0&&t._index0)?o(e):e.getDistance(t._point)<=y}var u,l,c,d,f,_,g=this.getStyle(),p=this._segments,v=this._closed,m=n.tolerance,y=0,w=this;if(n.stroke&&(y=g.getStrokeWidth()/2,y>0?(u=g.getStrokeJoin(),l=g.getStrokeCap(),c=y*g.getMiterLimit()):u=l="round",y+=m),!n.ends||n.segments||v){if(n.segments||n.handles)for(var x=0,b=p.length;b>x;x++)if(_=r(p[x]))return _}else if(_=r(p[0],!0)||r(p[p.length-1],!0))return _;if(y>0){if(f=this.getNearestLocation(e)){var C=f.getParameter();0===C||1===C?h(f.getSegment())||(f=null):f._distance>y&&(f=null)}if(!f&&"miter"===u)for(var x=0,b=p.length;b>x;x++){var S=p[x];if(e.getDistance(S._point)<=c&&h(S)){f=S.getLocation();break}}}return!f&&n.fill&&this.hasFill()&&this.contains(e)?new P("fill",this):f?new P("stroke",this,{location:f}):null}},new function(){function t(t,e,n,i){function r(e){var n=a[e],i=a[e+1];(d!=n||f!=i)&&(t.beginPath(),t.moveTo(d,f),t.lineTo(n,i),t.stroke(),t.beginPath(),t.arc(n,i,s,0,2*Math.PI,!0),t.fill())}for(var s=i/2,a=Array(6),o=0,h=e.length;h>o;o++){var u=e[o];u._transformCoordinates(n,a,!1);var l=u._selectionState,c=4&l,d=a[0],f=a[1];(c||1&l)&&r(2),(c||2&l)&&r(4),t.save(),t.beginPath(),t.rect(d-s,f-s,i,i),t.fill(),c||(t.beginPath(),t.rect(d-s+1,f-s+1,i-2,i-2),t.fillStyle="#ffffff",t.fill()),t.restore()}}function e(t,e,n){function i(e){var i=d[e];if(n)i._transformCoordinates(n,_,!1),r=_[0],s=_[1];else{var f=i._point;r=f._x,s=f._y}if(g)t.moveTo(r,s),g=!1;else{if(n)h=_[2],u=_[3];else{var p=i._handleIn;h=r+p._x,u=s+p._y}h==r&&u==s&&l==a&&c==o?t.lineTo(r,s):t.bezierCurveTo(l,c,h,u,r,s)}if(a=r,o=s,n)l=_[4],c=_[5];else{var p=i._handleOut;l=a+p._x,c=o+p._y}}for(var r,s,a,o,h,u,l,c,d=e._segments,f=d.length,_=Array(6),g=!0,p=0;f>p;p++)i(p);e._closed&&f>1&&i(0)}return{_draw:function(t,n){function i(t){return u[(t%l+l)%l]}var r=n.clip,s=n.compound;s||t.beginPath();var a=this.getStyle(),o=a.hasFill(),h=a.hasStroke(),u=a.getDashArray(),l=!paper.support.nativeDash&&h&&u&&u.length;if((o||h&&!l||s||r)&&e(t,this),this._closed&&t.closePath(),!r&&!s&&(o||h)&&(this._setStyles(t),o&&t.fill(a.getWindingRule()),h)){if(l){t.beginPath();var c,d=new T(this),f=d.length,_=-a.getDashOffset(),g=0;for(_%=f;_>0;)_-=i(g--)+i(g--);for(;f>_;)c=_+i(g++),(_>0||c>0)&&d.drawPart(t,Math.max(_,0),Math.max(c,0)),_=c+i(g++)}t.stroke()}},_drawSelected:function(n,i){n.beginPath(),e(n,this,i),n.stroke(),t(n,this._segments,i,this._project.options.handleSize||4)}}},new function(){function t(t){var e=t.length,n=[],i=[],r=2;n[0]=t[0]/r;for(var s=1;e>s;s++)i[s]=1/r,r=(e-1>s?4:2)-i[s],n[s]=(t[s]-n[s-1])/r;for(var s=1;e>s;s++)n[e-s-1]-=i[e-s]*n[e-s];return n}return{smooth:function(){var e,n=this._segments,i=n.length,r=i;if(!(2>=i)){this._closed?(e=Math.min(i,4),r+=2*Math.min(i,e)):e=0;for(var s=[],a=0;i>a;a++)s[a+e]=n[a]._point;if(this._closed)for(var a=0;e>a;a++)s[a]=n[a+i-e]._point,s[a+i+e]=n[a]._point;else r--;for(var o=[],a=1;r-1>a;a++)o[a]=4*s[a]._x+2*s[a+1]._x;o[0]=s[0]._x+2*s[1]._x,o[r-1]=3*s[r-1]._x;for(var u=t(o),a=1;r-1>a;a++)o[a]=4*s[a]._y+2*s[a+1]._y;o[0]=s[0]._y+2*s[1]._y,o[r-1]=3*s[r-1]._y;var l=t(o);if(this._closed){for(var a=0,c=i;e>a;a++,c++){var d=a/e,f=1-d,_=a+e,g=c+e;u[c]=u[a]*d+u[c]*f,l[c]=l[a]*d+l[c]*f,u[g]=u[_]*f+u[g]*d,l[g]=l[_]*f+l[g]*d}r--}for(var p=null,a=e;r-e>=a;a++){var v=n[a-e];p&&v.setHandleIn(p.subtract(v._point)),r>a&&(v.setHandleOut(new h(u[a],l[a]).subtract(v._point)),p=r-1>a?new h(2*s[a+1]._x-u[a+1],2*s[a+1]._y-l[a+1]):new h((s[r]._x+u[r-1])/2,(s[r]._y+l[r-1])/2))}if(this._closed&&p){var v=this._segments[0];v.setHandleIn(p.subtract(v._point))}}}}},new function(){function t(t){var e=t._segments;if(0==e.length)throw Error("Use a moveTo() command first");return e[e.length-1]}return{moveTo:function(){1===this._segments.length&&this.removeSegment(0),this._segments.length||this._add([new k(h.read(arguments))])},moveBy:function(){throw Error("moveBy() is unsupported on Path items.")},lineTo:function(){this._add([new k(h.read(arguments))])},cubicCurveTo:function(){var e=h.read(arguments),n=h.read(arguments),i=h.read(arguments),r=t(this);r.setHandleOut(e.subtract(r._point)),this._add([new k(i,n.subtract(i))])},quadraticCurveTo:function(){var e=h.read(arguments),n=h.read(arguments),i=t(this)._point;this.cubicCurveTo(e.add(i.subtract(e).multiply(1/3)),e.add(n.subtract(e).multiply(1/3)),n)},curveTo:function(){var n=h.read(arguments),i=h.read(arguments),r=e.pick(e.read(arguments),.5),s=1-r,a=t(this)._point,o=n.subtract(a.multiply(s*s)).subtract(i.multiply(r*r)).divide(2*r*s);if(o.isNaN())throw Error("Cannot put a curve through points with parameter = "+r);this.quadraticCurveTo(o,i)},arcTo:function(n,i){var r,s=t(this),a=s._point,o=h.read(arguments),u=e.pick(e.peek(arguments),!0);if("boolean"==typeof u){n=o,i=u;var l=a.add(n).divide(2),r=l.add(l.subtract(a).rotate(i?-90:90))}else r=o,n=h.read(arguments);var c=new p(a.add(r).divide(2),r.subtract(a).rotate(90),!0),d=new p(r.add(n).divide(2),n.subtract(r).rotate(90),!0),f=c.intersect(d,!0),_=new p(a,n),g=_.getSide(r);if(!f){if(!g)return this.lineTo(n);throw Error("Cannot put an arc through the given points: "+[a,r,n])}var v=a.subtract(f),m=v.getDirectedAngle(n.subtract(f)),y=_.getSide(f);0==y?m=g*Math.abs(m):g==y&&(m-=360*(0>m?-1:1));for(var w=Math.abs(m),x=w>=360?4:Math.ceil(w/90),b=m/x,C=b*Math.PI/360,S=4/3*Math.sin(C)/(1+Math.cos(C)),P=[],z=0;x>=z;z++){var M=x>z?f.add(v):n,I=x>z?v.rotate(90).multiply(S):null;0==z?s.setHandleOut(I):P.push(new k(M,v.rotate(-90).multiply(S),I)),v=v.rotate(b)}this._add(P)},lineBy:function(e){e=h.read(arguments);var n=t(this);this.lineTo(n._point.add(e))},curveBy:function(e,n,i){e=h.read(e),n=h.read(n);var r=t(this)._point;this.curveTo(r.add(e),r.add(n),i)},arcBy:function(e,n){e=h.read(e),n=h.read(n);var i=t(this)._point;this.arcTo(i.add(e),i.add(n))},closePath:function(){var t=this.getFirstSegment(),e=this.getLastSegment();t._point.equals(e._point)&&(t.setHandleIn(e._handleIn),e.remove()),this.setClosed(!0)}}},{_getBounds:function(t,e){return O[t](this._segments,this._closed,this.getStyle(),e)},statics:{isClockwise:function(t){for(var e=0,n=0,i=t.length;i>n;n++)for(var r=M.getValues(t[n],t[i>n+1?n+1:0]),s=2;8>s;s+=2)e+=(r[s-2]-r[s])*(r[s+1]+r[s-1]);return e>0},getBounds:function(t,e,n,i,r){function s(t){t._transformCoordinates(i,o,!1);for(var e=0;2>e;e++)M._addBounds(h[e],h[e+4],o[e+2],o[e],e,r?r[e]:0,u,l,c);var n=h;h=o,o=n}var a=t[0];if(!a)return new f;for(var o=Array(6),h=a._transformCoordinates(i,Array(6),!1),u=h.slice(0,2),l=u.slice(),c=Array(2),d=1,_=t.length;_>d;d++)s(t[d]);return e&&s(a),new f(u[0],u[1],l[0]-u[0],l[1]-u[1])},getStrokeBounds:function(t,e,n,i){function r(t,e){if(!e)return[t,t];var n=e.shiftless(),i=n.transform(new h(t,0)),r=n.transform(new h(0,t)),s=i.getAngleInRadians(),a=i.getLength(),o=r.getLength(),u=Math.sin(s),l=Math.cos(s),c=Math.tan(s),d=-Math.atan(o*c/a),f=Math.atan(o/(c*a));return[Math.abs(a*Math.cos(d)*l-o*Math.sin(d)*u),Math.abs(o*Math.sin(f)*l+a*Math.cos(f)*u)]}function s(t){_=_.include(i?i._transformPoint(t,t):t)}function a(t,e){"round"===e||!t._handleIn.isZero()&&!t._handleOut.isZero()?_=_.unite(m.setCenter(i?i._transformPoint(t._point):t._point)):O._addSquareJoin(t,e,l,v,s)}function o(t,e){switch(e){case"round":a(t,e);break;case"butt":case"square":O._addSquareCap(t,e,l,s)}}if(!n.hasStroke())return O.getBounds(t,e,n,i);for(var u=t.length-(e?0:1),l=n.getStrokeWidth()/2,d=r(l,i),_=O.getBounds(t,e,n,i,d),g=n.getStrokeJoin(),p=n.getStrokeCap(),v=l*n.getMiterLimit(),m=new f(new c(d).multiply(2)),y=1;u>y;y++)a(t[y],g);return e?a(t[0],g):(o(t[0],p),o(t[t.length-1],p)),_},_addSquareJoin:function(t,e,n,i,r,s){var a=t.getCurve(),o=a.getPrevious(),u=a.getPointAt(0,!0),l=o.getNormalAt(1,!0),c=a.getNormalAt(0,!0),d=l.getDirectedAngle(c)<0?-n:n;if(l.setLength(d),c.setLength(d),s&&(r(u),r(u.add(l))),"miter"===e){var f=new p(u.add(l),new h(-l.y,l.x),!0).intersect(new p(u.add(c),new h(-c.y,c.x),!0),!0);if(f&&u.getDistance(f)<=i&&(r(f),!s))return}s||r(u.add(l)),r(u.add(c))},_addSquareCap:function(t,e,n,i,r){var s=t._point,a=t.getLocation(),o=a.getNormal().normalize(n);r&&(i(s.subtract(o)),i(s.add(o))),"square"===e&&(s=s.add(o.rotate(0==a.getParameter()?-90:90))),i(s.add(o)),i(s.subtract(o))},getHandleBounds:function(t,e,n,i,r,s){var a=Array(6),o=1/0,h=-o,u=o,l=h;r=r/2||0,s=s/2||0;for(var c=0,d=t.length;d>c;c++){var _=t[c];_._transformCoordinates(i,a,!1);for(var g=0;6>g;g+=2){var p=0==g?s:r,v=a[g],m=a[g+1],y=v-p,w=v+p,x=m-p,b=m+p;o>y&&(o=y),w>h&&(h=w),u>x&&(u=x),b>l&&(l=b)}}return new f(o,u,h-o,l-u)},getRoughBounds:function(t,e,n,i){var r=n.getStrokeColor()?n.getStrokeWidth():0,s=r;return 0===r?r=1e-5:("miter"===n.getStrokeJoin()&&(s=r*n.getMiterLimit()),"square"===n.getStrokeCap()&&(s=Math.max(s,r*Math.sqrt(2)))),O.getHandleBounds(t,e,n,i,r,s)}}});O.inject({statics:new function(){function t(t,n,r){for(var s=new O,a=Array(4),o=0;4>o;o++){var h=i[o];a[o]=new k(h._point.multiply(n).add(t),h._handleIn.multiply(n),h._handleOut.multiply(n))}return s._add(a),s._closed=!0,s.set(e.getNamed(r))}var n=o.KAPPA,i=[new k([-1,0],[0,n],[0,-n]),new k([0,-1],[-n,0],[n,0]),new k([1,0],[0,-n],[0,n]),new k([0,1],[n,0],[-n,0])];return{Line:function(){return new O(h.readNamed(arguments,"from"),h.readNamed(arguments,"to")).set(e.getNamed(arguments))},Circle:function(){var n=h.readNamed(arguments,"center"),i=e.readNamed(arguments,"radius");return t(n,new c(i),arguments)},Rectangle:function(){var t=f.readNamed(arguments,"rectangle"),i=c.readNamed(arguments,"radius",0,0,{readNull:!0}),r=t.getBottomLeft(!0),s=t.getTopLeft(!0),a=t.getTopRight(!0),o=t.getBottomRight(!0);if(path=new O,!i||i.isZero())path._add([new k(r),new k(s),new k(a),new k(o)]);else{i=c.min(i,t.getSize(!0).divide(2));var h=i.width,u=i.height,l=h*n,d=u*n;path._add([new k(r.add(h,0),null,[-l,0]),new k(r.subtract(0,u),[0,d]),new k(s.add(0,u),null,[0,-d]),new k(s.add(h,0),[-l,0],null),new k(a.subtract(h,0),null,[l,0]),new k(a.add(0,u),[0,-d],null),new k(o.subtract(0,u),null,[0,d]),new k(o.subtract(h,0),[l,0])])}return path._closed=!0,path.set(e.getNamed(arguments))},RoundRectangle:"#Rectangle",Ellipse:function(){var e=b._readEllipse(arguments);return t(e.center,e.radius,arguments)},Oval:"#Ellipse",Arc:function(){var t=h.readNamed(arguments,"from"),n=h.readNamed(arguments,"through"),i=h.readNamed(arguments,"to"),r=new O;return r.moveTo(t),r.arcTo(n,i),r.set(e.getNamed(arguments))},RegularPolygon:function(){for(var t=h.readNamed(arguments,"center"),n=e.readNamed(arguments,"sides"),i=e.readNamed(arguments,"radius"),r=new O,s=360/n,a=!(n%3),o=new h(0,a?-i:i),u=a?-1:.5,l=Array(n),c=0;n>c;c++)l[c]=new k(t.add(o.rotate((c+u)*s)));return r._add(l),r._closed=!0,r.set(e.getNamed(arguments))},Star:function(){for(var t=h.readNamed(arguments,"center"),n=2*e.readNamed(arguments,"points"),i=e.readNamed(arguments,"radius1"),r=e.readNamed(arguments,"radius2"),s=new O,a=360/n,o=new h(0,-1),u=Array(n),l=0;n>l;l++)u[l]=new k(t.add(o.rotate(a*l).multiply(l%2?r:i)));return s._add(u),s._closed=!0,s.set(e.getNamed(arguments))}}}});var L=A.extend({_class:"CompoundPath",_serializeFields:{children:[]},initialize:function(t){this._children=[],this._namedChildren={},this._initialize(t)||this.addChildren(Array.isArray(t)?t:arguments)},insertChildren:function me(e,n,i){n=me.base.call(this,e,n,i,"path");for(var r=0,s=!i&&n&&n.length;s>r;r++){var a=n[r];a._clockwise===t&&a.setClockwise(0===a._index)}return n},reverse:function(){for(var t=this._children,e=0,n=t.length;n>e;e++)t[e].reverse()},smooth:function(){for(var t=0,e=this._children.length;e>t;t++)this._children[t].smooth()},isClockwise:function(){var t=this.getFirstChild();return t&&t.isClockwise()},setClockwise:function(t){this.isClockwise()!=!!t&&this.reverse()},getFirstSegment:function(){var t=this.getFirstChild();return t&&t.getFirstSegment()},getLastSegment:function(){var t=this.getLastChild();return t&&t.getLastSegment()},getCurves:function(){for(var t=this._children,e=[],n=0,i=t.length;i>n;n++)e=e.concat(t[n].getCurves());return e},getFirstCurve:function(){var t=this.getFirstChild();return t&&t.getFirstCurve()},getLastCurve:function(){var t=this.getLastChild();return t&&t.getFirstCurve()},getArea:function(){for(var t=this._children,e=0,n=0,i=t.length;i>n;n++)e+=t[n].getArea();return e},getPathData:function(){for(var t=this._children,e=[],n=0,i=t.length;i>n;n++)e.push(t[n].getPathData(arguments[0]));return e.join(" ")},_getWinding:function(t){for(var e=this._children,n=0,i=0,r=e.length;r>i;i++)n+=e[i]._getWinding(t);return n},_hitTest:function ye(t,n){var i=ye.base.call(this,t,e.merge(n,{fill:!1}));if(!i)if(n.compoundChildren)for(var r=this._children,s=r.length-1;s>=0&&!i;s--)i=r[s]._hitTest(t,n);else n.fill&&this.hasFill()&&this._contains(t)&&(i=new P("fill",this));return i},_draw:function(t,e){var n=this._children;if(0!==n.length){t.beginPath(),e=e.extend({compound:!0});for(var i=0,r=n.length;r>i;i++)n[i].draw(t,e);if(!e.clip){this._setStyles(t);var s=this._style;s.hasFill()&&t.fill(s.getWindingRule()),s.hasStroke()&&t.stroke()}}}},new function(){function t(t){if(!t._children.length)throw Error("Use a moveTo() command first");return t._children[t._children.length-1]}var n={moveTo:function(){var t=new O;this.addChild(t),t.moveTo.apply(t,arguments)},moveBy:function(){this.moveTo(t(this).getLastSegment()._point.add(h.read(arguments)))},closePath:function(){t(this).closePath()}};return e.each(["lineTo","cubicCurveTo","quadraticCurveTo","curveTo","arcTo","lineBy","curveBy","arcBy"],function(e){n[e]=function(){var n=t(this);n[e].apply(n,arguments)}}),n}),T=e.extend({initialize:function(t){function e(t,e){var n=M.getValues(t,e);s.curves.push(n),s._computeParts(n,t._index,0,1)}this.curves=[],this.parts=[],this.length=0,this.index=0;for(var n,i=t._segments,r=i[0],s=this,a=1,o=i.length;o>a;a++)n=i[a],e(r,n),r=n;t._closed&&e(n,i[0])},_computeParts:function(t,e,n,i){if(i-n>1/32&&!M.isFlatEnough(t,.25)){var r=M.subdivide(t),s=(n+i)/2;this._computeParts(r[0],e,n,s),this._computeParts(r[1],e,s,i)}else{var a=t[6]-t[0],o=t[7]-t[1],h=Math.sqrt(a*a+o*o);h>1e-5&&(this.length+=h,this.parts.push({offset:this.length,value:i,index:e}))}},getParameterAt:function(t){for(var e,n=this.index;e=n,!(0==n||this.parts[--n].offsete;e++){var r=this.parts[e];if(r.offset>=t){this.index=e;var s=this.parts[e-1],a=s&&s.index==r.index?s.value:0,o=s?s.offset:0;return{value:a+(r.value-a)*(t-o)/(r.offset-o),index:r.index}}}var r=this.parts[this.parts.length-1];return{value:1,index:r.index}},evaluate:function(t,e){var n=this.getParameterAt(t);return M.evaluate(this.curves[n.index],n.value,e)},drawPart:function(t,e,n){e=this.getParameterAt(e),n=this.getParameterAt(n);for(var i=e.index;i<=n.index;i++){var r=M.getPart(this.curves[i],i==e.index?e.value:0,i==n.index?n.value:1);i==e.index&&t.moveTo(r[0],r[1]),t.bezierCurveTo.apply(t,r.slice(2))}}}),D=e.extend({initialize:function(t,e){this.points=[];for(var n,i=t._segments,r=0,s=i.length;s>r;r++){var a=i[r].point.clone();n&&n.equals(a)||(this.points.push(a),n=a)}this.error=e},fit:function(){var t=this.points,e=t.length;return this.segments=e>0?[new k(t[0])]:[],e>1&&this.fitCubic(0,e-1,t[1].subtract(t[0]).normalize(),t[e-2].subtract(t[e-1]).normalize()),this.segments},fitCubic:function(e,n,i,r){if(1==n-e){var s=this.points[e],a=this.points[n],o=s.getDistance(a)/3;return this.addCurve([s,s.add(i.normalize(o)),a.add(r.normalize(o)),a]),t}for(var h,u=this.chordLengthParameterize(e,n),l=Math.max(this.error,this.error*this.error),c=0;4>=c;c++){var d=this.generateBezier(e,n,u,i,r),f=this.findMaxError(e,n,d,u);if(f.error=l)break;this.reparameterize(e,n,u,d),l=f.error}var _=this.points[h-1].subtract(this.points[h]),g=this.points[h].subtract(this.points[h+1]),p=_.add(g).divide(2).normalize();this.fitCubic(e,h,i,p),this.fitCubic(h,n,p.negate(),r)},addCurve:function(t){var e=this.segments[this.segments.length-1];e.setHandleOut(t[1].subtract(t[0])),this.segments.push(new k(t[3],t[2].subtract(t[3])))},generateBezier:function(t,e,n,i,r){for(var s=1e-11,a=this.points[t],o=this.points[e],h=[[0,0],[0,0]],u=[0,0],l=0,c=e-t+1;c>l;l++){var d=n[l],f=1-d,_=3*d*f,g=f*f*f,p=_*f,v=_*d,m=d*d*d,y=i.normalize(p),w=r.normalize(v),x=this.points[t+l].subtract(a.multiply(g+p)).subtract(o.multiply(v+m));h[0][0]+=y.dot(y),h[0][1]+=y.dot(w),h[1][0]=h[0][1],h[1][1]+=w.dot(w),u[0]+=y.dot(x),u[1]+=w.dot(x)}var b,C,S=h[0][0]*h[1][1]-h[1][0]*h[0][1];if(Math.abs(S)>s){var P=h[0][0]*u[1]-h[1][0]*u[0],k=u[0]*h[1][1]-u[1]*h[0][1];b=k/S,C=P/S}else{var z=h[0][0]+h[0][1],M=h[1][0]+h[1][1];b=C=Math.abs(z)>s?u[0]/z:Math.abs(M)>s?u[1]/M:0}var I=o.getDistance(a);return s*=I,(s>b||s>C)&&(b=C=I/3),[a,a.add(i.normalize(b)),o.add(r.normalize(C)),o]},reparameterize:function(t,e,n,i){for(var r=t;e>=r;r++)n[r-t]=this.findRoot(i,this.points[r],n[r-t])},findRoot:function(t,e,n){for(var i=[],r=[],s=0;2>=s;s++)i[s]=t[s+1].subtract(t[s]).multiply(3);for(var s=0;1>=s;s++)r[s]=i[s+1].subtract(i[s]).multiply(2);var a=this.evaluate(3,t,n),o=this.evaluate(2,i,n),h=this.evaluate(1,r,n),u=a.subtract(e),l=o.dot(o)+u.dot(h);return Math.abs(l)<1e-5?n:n-u.dot(o)/l},evaluate:function(t,e,n){for(var i=e.slice(),r=1;t>=r;r++)for(var s=0;t-r>=s;s++)i[s]=i[s].multiply(1-n).add(i[s+1].multiply(n));return i[0]},chordLengthParameterize:function(t,e){for(var n=[0],i=t+1;e>=i;i++)n[i-t]=n[i-t-1]+this.points[i].getDistance(this.points[i-1]);for(var i=1,r=e-t;r>=i;i++)n[i]/=n[r];return n},findMaxError:function(t,e,n,i){for(var r=Math.floor((e-t+1)/2),s=0,a=t+1;e>a;a++){var o=this.evaluate(3,n,i[a-t]),h=o.subtract(this.points[a]),u=h.x*h.x+h.y*h.y;u>=s&&(s=u,r=a)}return{error:s,index:r}}});A.inject(new function(){function t(t,e){t.sort(function(t,e){var n=t.getPath(),i=e.getPath();return n===i?t.getIndex()+t.getParameter()-(e.getIndex()+e.getParameter()):n._id-i._id});for(var n=e&&[],i=t.length-1;i>=0;i--){var r=t[i],s=r.getIntersection(),a=r.divide(),o=a&&a.getSegment1()||r.getSegment();n&&n.push(s),o._intersection=s,r._segment=o}return n}function e(t){if(t instanceof L){for(var e=t._children,n=e.length,i=Array(n),r=Array(n),s=e[0].isClockwise(),a=0;n>a;a++)i[a]=e[a].getBounds(),r[a]=0;for(var a=0;n>a;a++){for(var o=1;n>o;o++)a!==o&&i[a].contains(i[o])&&r[o]++;a>0&&0===r[a]%2&&e[a].setClockwise(s)}}return t}function n(n,r,s,a){n=e(n.clone(!1)),r=e(r.clone(!1));var o=n.isClockwise(),u=r.isClockwise(),l=n.getIntersections(r);t(t(l,!0)),o||n.reverse(),a^u||r.reverse(),o=!0,u=!a;for(var c=[].concat(n._children||[n]).concat(r._children||[r]),d=[],f=new L,_=0,g=c.length;g>_;_++){var p=c[_],v=p._parent,m=p.isClockwise(),y=p._segments;p=v instanceof L?v:p;for(var w=y.length-1;w>=0;w--){var x=y[w],b=x.getCurve().getPoint(.5),C=p!==n&&n.contains(b)&&(m===o||a||!i(n,b)),S=p!==r&&r.contains(b)&&(m===u||!i(r,b));s(p===n,C,S)?x._invalid=!0:d.push(x)}}for(var _=0,g=d.length;g>_;_++){var x=d[_];if(!x._visited){var p=new O,P=x._intersection,z=P&&P.getSegment(!0);x.getPrevious()._invalid&&x.setHandleIn(z?z._handleIn:new h(0,0));do{if(x._visited=!0,x._invalid&&x._intersection){var M=x._intersection.getSegment(!0);p.add(new k(x._point,x._handleIn,M._handleOut)),M._visited=!0,x=M}else p.add(x.clone());x=x.getNext()}while(x&&!x._visited&&x!==z);var I=p._segments.length;I>1&&(I>2||!p.isPolygon())?(p.setClosed(!0),f.addChild(p,!0)):p.remove()}}return n.remove(),r.remove(),f.reduce()}function i(t,e){var n=t.getCurves(),i=t.getBounds();if(i.contains(e))for(var r=0,s=n.length;s>r;r++){var a=n[r];if(a.getBounds().contains(e)&&a.getParameterOf(e))return!0}return!1}return{unite:function(t){return n(this,t,function(t,e,n){return e||n})},intersect:function(t){return n(this,t,function(t,e,n){return!(e||n)})},subtract:function(t){return n(this,t,function(t,e,n){return t&&n||!t&&!e},!0)},exclude:function(t){return new w([this.subtract(t),t.subtract(this)])},divide:function(t){return new w([this.subtract(t),this.intersect(t)])}}});var E=y.extend({_class:"TextItem",_boundsSelected:!0,_serializeFields:{content:null},_boundsGetter:"getBounds",initialize:function(n){this._content="",this._lines=[];var i=n&&e.isPlainObject(n)&&n.x===t&&n.y===t;this._initialize(i&&n,!i&&h.read(arguments))},_equals:function(t){return this._content===t._content},_clone:function we(t){return t.setContent(this._content),we.base.call(this,t)},getContent:function(){return this._content},setContent:function(t){this._content=""+t,this._lines=this._content.split(/\r\n|\n|\r/gm),this._changed(69)},isEmpty:function(){return!this._content},getCharacterStyle:"#getStyle",setCharacterStyle:"#setStyle",getParagraphStyle:"#getStyle",setParagraphStyle:"#setStyle"}),j=E.extend({_class:"PointText",initialize:function(){E.apply(this,arguments)},clone:function(t){return this._clone(new j({insert:!1}),t)},getPoint:function(){var t=this._matrix.getTranslation();return new u(t.x,t.y,this,"setPoint")},setPoint:function(t){t=h.read(arguments),this.translate(t.subtract(this._matrix.getTranslation()))},_draw:function(t){if(this._content){this._setStyles(t);var e=this._style,n=this._lines,i=e.getLeading();t.font=e.getFontStyle(),t.textAlign=e.getJustification();for(var r=0,s=n.length;s>r;r++){var a=n[r];e.hasFill()&&t.fillText(a,0,0),e.hasStroke()&&t.strokeText(a,0,0),t.translate(0,i)}}}},new function(){var t=null;return{_getBounds:function(e,n){t||(t=K.getContext(1,1));var i=this._style,r=this._lines,s=r.length,a=i.getJustification(),o=i.getLeading(),h=0;t.font=i.getFontStyle();for(var u=0,l=0;s>l;l++)u=Math.max(u,t.measureText(r[l]).width);"left"!==a&&(h-=u/("center"===a?2:1));var c=new f(h,s?-.75*o:0,u,s*o);return n?n._transformBounds(c,c):c}}}),B=e.extend(new function(){function t(t){var e=o[t];if(!e){i||(i=K.getContext(1,1),i.globalCompositeOperation="copy"),i.fillStyle="rgba(0,0,0,0)",i.fillStyle=t,i.fillRect(0,0,1,1);var n=i.getImageData(0,0,1,1).data;e=o[t]=[n[0]/255,n[1]/255,n[2]/255]}return e.slice()}function n(t){var e=t.match(/^#?(\w{1,2})(\w{1,2})(\w{1,2})$/);if(e.length>=4){for(var n=[0,0,0],i=0;3>i;i++){var r=e[i+1];n[i]=parseInt(1==r.length?r+r:r,16)/255}return n}}var i,r={gray:["gray"],rgb:["red","green","blue"],hsb:["hue","saturation","brightness"],hsl:["hue","saturation","lightness"],gradient:["gradient","origin","destination","highlight"]},s={},o={},u=[[0,3,1],[2,0,1],[1,0,3],[1,2,0],[3,1,0],[0,1,2]],l={"rgb-hsb":function(t,e,n){var i=Math.max(t,e,n),r=Math.min(t,e,n),s=i-r,a=0===s?0:60*(i==t?(e-n)/s+(n>e?6:0):i==e?(n-t)/s+2:(t-e)/s+4);return[a,0===i?0:s/i,i]},"hsb-rgb":function(t,e,n){var t=t/60%6,i=Math.floor(t),r=t-i,i=u[i],s=[n,n*(1-e),n*(1-e*r),n*(1-e*(1-r))];return[s[i[0]],s[i[1]],s[i[2]]]},"rgb-hsl":function(t,e,n){var i=Math.max(t,e,n),r=Math.min(t,e,n),s=i-r,a=0===s,o=a?0:60*(i==t?(e-n)/s+(n>e?6:0):i==e?(n-t)/s+2:(t-e)/s+4),h=(i+r)/2,u=a?0:.5>h?s/(i+r):s/(2-i-r);return[o,u,h]},"hsl-rgb":function(t,e,n){if(t/=360,0===e)return[n,n,n];for(var i=[t+1/3,t,t-1/3],r=.5>n?n*(1+e):n+e-n*e,s=2*n-r,a=[],o=0;3>o;o++){var h=i[o];0>h&&(h+=1),h>1&&(h-=1),a[o]=1>6*h?s+6*(r-s)*h:1>2*h?r:2>3*h?s+6*(r-s)*(2/3-h):s}return a},"rgb-gray":function(t,e,n){return[.2989*t+.587*e+.114*n]},"gray-rgb":function(t){return[t,t,t]},"gray-hsb":function(t){return[0,0,t]},"gray-hsl":function(t){return[0,0,t]},"gradient-rgb":function(){return[]},"rgb-gradient":function(){return[]}};return e.each(r,function(t,n){s[n]=[],e.each(t,function(t,i){var a=e.capitalize(t),o=/^(hue|saturation)$/.test(t),u=s[n][i]="gradient"===t?function(t){var e=this._components[0];return t=N.read(Array.isArray(t)?t:arguments,0,0,{readNull:!0}),e!==t&&(e&&e._removeOwner(this),t&&t._addOwner(this)),t}:"hue"===t?function(t){return isNaN(t)?0:(t%360+360)%360}:"gradient"===n?function(){return h.read(arguments,0,0,{readNull:"highlight"===t,clone:!0})}:function(t){return isNaN(t)?0:Math.min(Math.max(t,0),1)};this["get"+a]=function(){return this._type===n||o&&/^hs[bl]$/.test(this._type)?this._components[i]:this._convert(n)[i]},this["set"+a]=function(t){this._type===n||o&&/^hs[bl]$/.test(this._type)||(this._components=this._convert(n),this._properties=r[n],this._type=n),t=u.call(this,t),null!=t&&(this._components[i]=t,this._changed())}},this)},{_class:"Color",_readIndex:!0,initialize:function c(e){var i,a,o,h,u=Array.prototype.slice,l=arguments,d=0,f=!0;Array.isArray(e)&&(l=e,e=l[0]);var _=null!=e&&typeof e;if("string"===_&&e in r&&(i=e,e=l[1],Array.isArray(e)?(a=e,o=l[2]):(this.__read&&(d=1),l=u.call(l,1),_=typeof e)),!a){if(f=!(this.__options&&this.__options.dontParse),h="number"===_?l:"object"===_&&null!=e.length?e:null){i||(i=h.length>=3?"rgb":"gray");var g=r[i].length;o=h[g],this.__read&&(d+=h===arguments?g+(null!=o?1:0):1),h.length>g&&(h=u.call(h,0,g))}else if("string"===_)a=e.match(/^#[0-9a-f]{3,6}$/i)?n(e):t(e),i="rgb";else if("object"===_)if(e.constructor===c){if(i=e._type,a=e._components.slice(),o=e._alpha,"gradient"===i)for(var p=1,v=a.length;v>p;p++){var m=a[p];m&&(a[p]=m.clone())}}else if(e.constructor===N)i="gradient",h=l;else{i="hue"in e?"lightness"in e?"hsl":"hsb":"gradient"in e||"stops"in e||"radial"in e?"gradient":"gray"in e?"gray":"rgb";var y=r[i];x=f&&s[i],this._components=a=[];for(var p=0,v=y.length;v>p;p++){var w=e[y[p]];null==w&&0===p&&"gradient"===i&&"stops"in e&&(w={stops:e.stops,radial:e.radial}),f&&(w=x[p].call(this,w)),null!=w&&(a[p]=w)}o=e.alpha}this.__read&&i&&(d=1)}if(this._type=i||"rgb","gradient"===i&&(this._id=c._id=(c._id||0)+1),!a){this._components=a=[];for(var x=s[this._type],p=0,v=x.length;v>p;p++){var w=h&&h[p];f&&(w=x[p].call(this,w)),null!=w&&(a[p]=w)}}this._components=a,this._properties=r[this._type],this._alpha=o,this.__read&&(this.__read=d)},_serialize:function(t,n){var i=this.getComponents();return e.serialize(/^(gray|rgb)$/.test(this._type)?i:[this._type].concat(i),t,!0,n)},_changed:function(){this._canvasStyle=null,this._owner&&this._owner._changed(17)},clone:function(){return new B(this._type,this._components.slice(),this._alpha)},_convert:function(t){var e;return this._type===t?this._components.slice():(e=l[this._type+"-"+t])?e.apply(this,this._components):l["rgb-"+t].apply(this,l[this._type+"-rgb"].apply(this,this._components))},convert:function(t){return new B(t,this._convert(t),this._alpha)},getType:function(){return this._type},setType:function(t){this._components=this._convert(t),this._properties=r[t],this._type=t},getComponents:function(){var t=this._components.slice();return null!=this._alpha&&t.push(this._alpha),t},getAlpha:function(){return null!=this._alpha?this._alpha:1},setAlpha:function(t){this._alpha=null==t?null:Math.min(Math.max(t,0),1),this._changed()},hasAlpha:function(){return null!=this._alpha},equals:function(t){return e.isPlainValue(t)&&(t=B.read(arguments)),t===this||t&&this._class===t._class&&this._type===t._type&&this._alpha===t._alpha&&e.equals(this._components,t._components)||!1},toString:function(){for(var t=this._properties,e=[],n="gradient"===this._type,i=a.instance,r=0,s=t.length;s>r;r++){var o=this._components[r];null!=o&&e.push(t[r]+": "+(n?o:i.number(o)))}return null!=this._alpha&&e.push("alpha: "+i.number(this._alpha)),"{ "+e.join(", ")+" }"},toCSS:function(t){var e=this._convert("rgb"),n=t||null==this._alpha?1:this._alpha;return e=[Math.round(255*e[0]),Math.round(255*e[1]),Math.round(255*e[2])],1>n&&e.push(n),(4==e.length?"rgba(":"rgb(")+e.join(",")+")"},toCanvasStyle:function(t,e){if(this._canvasStyle)return this._canvasStyle;if("gradient"!==this._type)return this._canvasStyle=this.toCSS();var n,i=this._components,r=e?e.getTranslation():new h,s=i[0],a=s._stops,o=i[1].subtract(r),u=i[2].subtract(r);if(s._radial){var l=u.getDistance(o),c=i[3];if(c){c=c.subtract(r);var d=c.subtract(o);d.getLength()>l&&(c=o.add(d.normalize(l-.1)))}var f=c||o;n=t.createRadialGradient(f.x,f.y,0,o.x,o.y,l)}else n=t.createLinearGradient(o.x,o.y,u.x,u.y);for(var _=0,g=a.length;g>_;_++){var p=a[_];n.addColorStop(p._rampPoint,p._color.toCanvasStyle())}return this._canvasStyle=n},transform:function(t){if("gradient"===this._type){for(var e=this._components,n=1,i=e.length;i>n;n++){var r=e[n];t._transformPoint(r,r,!0)}this._changed()}},statics:{_types:r,random:function(){var t=Math.random;return new B(t(),t(),t())}}})},new function(){function t(t,e){return 0>t?0:e&&t>360?360:!e&&t>1?1:t}var n={add:function(e,n,i){return t(e+n,i)},subtract:function(e,n,i){return t(e-n,i)},multiply:function(e,n,i){return t(e*n,i)},divide:function(e,n,i){return t(e/n,i)}};return e.each(n,function(t,e){var n={dontParse:/^(multiply|divide)$/.test(e)};this[e]=function(e){e=B.read(arguments,0,0,n);for(var i=this._type,r=this._properties,s=this._components,a=e._convert(i),o=0,h=s.length;h>o;o++)a[o]=t(s[o],a[o],"hue"===r[o]);return new B(i,a,null!=this._alpha?t(this._alpha,e.getAlpha()):null)}},{})});e.each(B._types,function(t,n){var i=this[e.capitalize(n)+"Color"]=function(t){var e=null!=t&&typeof t,i="object"===e&&null!=t.length?t:"string"===e?null:arguments;return i?new B(n,i):new B(t)};if(3==n.length){var r=n.toUpperCase();B[r]=this[r+"Color"]=i}},e.exports);var N=e.extend({_class:"Gradient",initialize:function xe(t,e){this._id=xe._id=(xe._id||0)+1,t&&this._set(t)&&(t=e=null),this._stops||this.setStops(t||["white","black"]),null==this._radial&&this.setRadial("string"==typeof e&&"radial"===e||e||!1)},_serialize:function(t,n){return n.add(this,function(){return e.serialize([this._stops,this._radial],t,!0,n)})},_changed:function(){for(var t=0,e=this._owners&&this._owners.length;e>t;t++)this._owners[t]._changed()},_addOwner:function(t){this._owners||(this._owners=[]),this._owners.push(t)},_removeOwner:function(t){var e=this._owners?this._owners.indexOf(t):-1;-1!=e&&(this._owners.splice(e,1),0===this._owners.length&&delete this._owners)},clone:function(){for(var t=[],e=0,n=this._stops.length;n>e;e++)t[e]=this._stops[e].clone();return new this.constructor(t) -},getStops:function(){return this._stops},setStops:function(t){if(this.stops)for(var e=0,n=this._stops.length;n>e;e++)delete this._stops[e]._owner;if(t.length<2)throw Error("Gradient stop list needs to contain at least two stops.");this._stops=R.readAll(t,0,!1,!0);for(var e=0,n=this._stops.length;n>e;e++){var i=this._stops[e];i._owner=this,i._defaultRamp&&i.setRampPoint(e/(n-1))}this._changed()},getRadial:function(){return this._radial},setRadial:function(t){this._radial=t,this._changed()},equals:function(t){if(t===this)return!0;if(t&&this._class===t._class&&this._stops.length===t._stops.length){for(var e=0,n=this._stops.length;n>e;e++)if(!this._stops[e].equals(t._stops[e]))return!1;return!0}return!1}}),R=e.extend({_class:"GradientStop",initialize:function(e,n){if(e){var i,r;n===t&&Array.isArray(e)?(i=e[0],r=e[1]):e.color?(i=e.color,r=e.rampPoint):(i=e,r=n),this.setColor(i),this.setRampPoint(r)}},clone:function(){return new R(this._color.clone(),this._rampPoint)},_serialize:function(t,n){return e.serialize([this._color,this._rampPoint],t,!0,n)},_changed:function(){this._owner&&this._owner._changed(17)},getRampPoint:function(){return this._rampPoint},setRampPoint:function(t){this._defaultRamp=null==t,this._rampPoint=t||0,this._changed()},getColor:function(){return this._color},setColor:function(t){this._color=B.read(arguments),this._color===t&&(this._color=t.clone()),this._color._owner=this,this._changed()},equals:function(t){return t===this||t&&this._class===t._class&&this._color.equals(t._color)&&this._rampPoint==t._rampPoint||!1}}),F=e.extend(new function(){var n={fillColor:t,strokeColor:t,strokeWidth:1,strokeCap:"butt",strokeJoin:"miter",miterLimit:10,dashOffset:0,dashArray:[],windingRule:"nonzero",shadowColor:t,shadowBlur:0,shadowOffset:new h,selectedColor:t,font:"sans-serif",fontSize:12,leading:null,justification:"left"},i={strokeWidth:25,strokeCap:25,strokeJoin:25,miterLimit:25,font:5,fontSize:5,leading:5,justification:5},r={},s={_defaults:n,_textDefaults:e.merge(n,{fillColor:new B})};return e.each(n,function(n,a){var o=/Color$/.test(a),h=e.capitalize(a),u=i[a],l="set"+h,c="get"+h;s[l]=function(t){var e=this._item&&this._item._children;if(e&&e.length>0&&"compound-path"!==this._item._type)for(var n=0,i=e.length;i>n;n++)e[n]._style[l](t);else{var r=this._values[a];r!=t&&(o&&(r&&delete r._owner,t&&t.constructor===B&&(t._owner=this._item)),this._values[a]=t,this._item&&this._item._changed(u||17))}},s[c]=function(){var n,i=this._item&&this._item._children;if(!i||0===i.length||arguments[0]||"compound-path"===this._item._type){var n=this._values[a];return n===t?(n=this._defaults[a],n&&n.clone&&(n=n.clone()),this._values[a]=n):!o||n&&n.constructor===B||(this._values[a]=n=B.read([n],0,0,{readNull:!0,clone:!0}),n&&(n._owner=this._item)),n}for(var r=0,s=i.length;s>r;r++){var h=i[r]._style[c]();if(0===r)n=h;else if(!e.equals(n,h))return t}return n},r[c]=function(){return this._style[c]()},r[l]=function(t){this._style[l](t)}}),y.inject(r),s},{_class:"Style",initialize:function(t,e){this._values={},this._item=e,e instanceof E&&(this._defaults=this._textDefaults),t&&this.set(t)},set:function(t){var e=t instanceof F,n=e?t._values:t;if(n)for(var i in n)if(i in this._defaults){var r=n[i];this[i]=r&&e&&r.clone?r.clone():r}},equals:function(t){return t===this||t&&this._class===t._class&&e.equals(this._values,t._values)||!1},hasFill:function(){return!!this.getFillColor()},hasStroke:function(){return!!this.getStrokeColor()&&this.getStrokeWidth()>0},getLeading:function be(){var t=be.base.call(this);return null!=t?t:1.2*this.getFontSize()},getFontStyle:function(){var t=this.getFontSize();return t+(/[a-z]/i.test(t+"")?" ":"px ")+this.getFont()}}),q=new function(){function n(t,i){for(var r=[],s=0,a=t&&t.length;a>s;){var o=t[s++];if("string"==typeof o)o=document.createElement(o);else if(!o||!o.nodeType)continue;e.isPlainObject(t[s])&&q.set(o,t[s++]),Array.isArray(t[s])&&n(t[s++],o),i&&i.appendChild(o),r.push(o)}return r}var i=/^(checked|value|selected|disabled)$/i,r={text:"textContent",html:"innerHTML"},s={lineHeight:1,zoom:1,zIndex:1,opacity:1};return{create:function(t,e){var i=Array.isArray(t),r=n(i?t:arguments,i?e:null);return 1==r.length?r[0]:r},find:function(t,e){return(e||document).querySelector(t)},findAll:function(t,e){return(e||document).querySelectorAll(t)},get:function(t,e){return t?i.test(e)?"value"===e||"string"!=typeof t[e]?t[e]:!0:e in r?t[r[e]]:t.getAttribute(e):null},set:function(e,n,s){if("string"!=typeof n)for(var a in n)n.hasOwnProperty(a)&&this.set(e,a,n[a]);else{if(!e||s===t)return e;i.test(n)?e[n]=s:n in r?e[r[n]]=s:"style"===n?this.setStyle(e,s):"events"===n?V.add(e,s):e.setAttribute(n,s)}return e},getStyles:function(t){var e=t&&9!==t.nodeType?t.ownerDocument:t,n=e&&e.defaultView;return n&&n.getComputedStyle(t,"")},getStyle:function(t,e){return t&&t.style[e]||this.getStyles(t)[e]||null},setStyle:function(t,e,n){if("string"!=typeof e)for(var i in e)e.hasOwnProperty(i)&&this.setStyle(t,i,e[i]);else!/^-?[\d\.]+$/.test(n)||e in s||(n+="px"),t.style[e]=n;return t},hasClass:function(t,e){return RegExp("\\s*"+e+"\\s*").test(t.className)},addClass:function(t,e){t.className=(t.className+" "+e).trim()},removeClass:function(t,e){t.className=t.className.replace(RegExp("\\s*"+e+"\\s*")," ").trim()},remove:function(t){t.parentNode&&t.parentNode.removeChild(t)},removeChildren:function(t){for(;t.firstChild;)t.removeChild(t.firstChild)},getBounds:function(t,e){var n,i=t.ownerDocument,r=i.body,s=i.documentElement;try{n=t.getBoundingClientRect()}catch(a){n={left:0,top:0,width:0,height:0}}var o=n.left-(s.clientLeft||r.clientLeft||0),h=n.top-(s.clientTop||r.clientTop||0);if(!e){var u=i.defaultView;o+=u.pageXOffset||s.scrollLeft||r.scrollLeft,h+=u.pageYOffset||s.scrollTop||r.scrollTop}return new f(o,h,n.width,n.height)},getViewportBounds:function(t){var e=t.ownerDocument,n=e.defaultView,i=e.documentElement;return new f(0,0,n.innerWidth||i.clientWidth,n.innerHeight||i.clientHeight)},getOffset:function(t,e){return this.getBounds(t,e).getPoint()},getSize:function(t){return this.getBounds(t,!0).getSize()},isInvisible:function(t){return this.getSize(t).equals(new c(0,0))},isInView:function(t){return!this.isInvisible(t)&&this.getViewportBounds(t).intersects(this.getBounds(t,!0))},getPrefixValue:function(t,e){for(var n=t[e],i=["webkit","moz","ms","o"],r=e[0].toUpperCase()+e.substring(1),s=0;4>s&&null==n;s++)n=t[i[s]+r];return n}}},V={add:function(t,e){for(var n in e){var i=e[n];t.addEventListener?t.addEventListener(n,i,!1):t.attachEvent&&t.attachEvent("on"+n,i.bound=function(){i.call(t,window.event)})}},remove:function(t,e){for(var n in e){var i=e[n];t.removeEventListener?t.removeEventListener(n,i,!1):t.detachEvent&&t.detachEvent("on"+n,i.bound)}},getPoint:function(t){var e=t.targetTouches?t.targetTouches.length?t.targetTouches[0]:t.changedTouches[0]:t;return new h(e.pageX||e.clientX+document.documentElement.scrollLeft,e.pageY||e.clientY+document.documentElement.scrollTop)},getTarget:function(t){return t.target||t.srcElement},getOffset:function(t,e){return V.getPoint(t).subtract(q.getOffset(e||V.getTarget(t)))},preventDefault:function(t){t.preventDefault?t.preventDefault():t.returnValue=!1},stopPropagation:function(t){t.stopPropagation?t.stopPropagation():t.cancelBubble=!0},stop:function(t){V.stopPropagation(t),V.preventDefault(t)}};V.requestAnimationFrame=new function(){var e="equestAnimationFrame",n=window["r"+e]||window["webkitR"+e]||window["mozR"+e]||window["oR"+e]||window["msR"+e];n&&n(function(t){null==t&&(n=null)});var i,s=[],a=!0;return V.add(window,{focus:function(){a=!0},blur:function(){a=!1}}),function(e,o){return n?n(e,o):(s.push([e,o]),i||(i=setInterval(function(){for(var t=s.length-1;t>=0;t--){var e=s[t],n=e[0],i=e[1];(!i||("true"==r.getAttribute(i,"keepalive")||a)&&q.isInView(i))&&(s.splice(t,1),n(Date.now()))}},1e3/60)),t)}};var Z=e.extend(n,{_class:"View",initialize:function Ce(t){this._scope=paper,this._project=paper.project,this._element=t;var e;if(this._id=t.getAttribute("id"),null==this._id&&t.setAttribute("id",this._id="view-"+Ce._id++),V.add(t,this._viewHandlers),r.hasAttribute(t,"resize")){var n=q.getOffset(t,!0),i=this;e=q.getViewportBounds(t).getSize().subtract(n),this._windowHandlers={resize:function(){q.isInvisible(t)||(n=q.getOffset(t,!0)),i.setViewSize(q.getViewportBounds(t).getSize().subtract(n))}},V.add(window,this._windowHandlers)}else e=new c(parseInt(t.getAttribute("width"),10),parseInt(t.getAttribute("height"),10)),e.isNaN()&&(e=q.getSize(t));if(t.width=e.width,t.height=e.height,r.hasAttribute(t,"stats")&&"object"==typeof Stats){this._stats=new Stats;var s=this._stats.domElement,a=s.style,n=q.getOffset(t);a.position="absolute",a.left=n.x+"px",a.top=n.y+"px",document.body.appendChild(s)}Ce._views.push(this),Ce._viewsById[this._id]=this,this._viewSize=new d(e.width,e.height,this,"setViewSize"),this._matrix=new g,this._zoom=1,Ce._focused||(Ce._focused=this),this._frameItems={},this._frameItemCount=0},remove:function(){return this._project?(Z._focused==this&&(Z._focused=null),Z._views.splice(Z._views.indexOf(this),1),delete Z._viewsById[this._id],this._project.view==this&&(this._project.view=null),V.remove(this._element,this._viewHandlers),V.remove(window,this._windowHandlers),this._element=this._project=null,this.detach("frame"),this._frameItems={},!0):!1},_events:{onFrame:{install:function(){this._requested||(this._animate=!0,this._requestFrame())},uninstall:function(){this._animate=!1}},onResize:{}},_animate:!1,_time:0,_count:0,_requestFrame:function(){var t=this;V.requestAnimationFrame(function(){t._requested=!1,t._animate&&(t._requestFrame(),t._handleFrame())},this._element),this._requested=!0},_handleFrame:function(){paper=this._scope;var t=Date.now()/1e3,n=this._before?t-this._before:0;this._before=t,this._handlingFrame=!0,this.fire("frame",e.merge({delta:n,time:this._time+=n,count:this._count++})),this._stats&&this._stats.update(),this._handlingFrame=!1,this.draw(!0)},_animateItem:function(t,e){var n=this._frameItems;e?(n[t._id]={item:t,time:0,count:0},1===++this._frameItemCount&&this.attach("frame",this._handleFrameItems)):(delete n[t._id],0===--this._frameItemCount&&this.detach("frame",this._handleFrameItems))},_handleFrameItems:function(t){for(var n in this._frameItems){var i=this._frameItems[n];i.item.fire("frame",e.merge(t,{time:i.time+=t.delta,count:i.count++}))}},_redraw:function(){this._project._needsRedraw=!0,this._handlingFrame||(this._animate?this._handleFrame():this.draw())},_transform:function(t){this._matrix.concatenate(t),this._bounds=null,this._redraw()},getElement:function(){return this._element},getViewSize:function(){return this._viewSize},setViewSize:function(t){t=c.read(arguments);var e=t.subtract(this._viewSize);e.isZero()||(this._element.width=t.width,this._element.height=t.height,this._viewSize.set(t.width,t.height,!0),this._bounds=null,this.fire("resize",{size:t,delta:e}),this._redraw())},getBounds:function(){return this._bounds||(this._bounds=this._matrix.inverted()._transformBounds(new f(new h,this._viewSize))),this._bounds},getSize:function(){return this.getBounds().getSize(arguments[0])},getCenter:function(){return this.getBounds().getCenter(arguments[0])},setCenter:function(t){t=h.read(arguments),this.scrollBy(t.subtract(this.getCenter()))},getZoom:function(){return this._zoom},setZoom:function(t){this._transform((new g).scale(t/this._zoom,this.getCenter())),this._zoom=t},isVisible:function(){return q.isInView(this._element)},scrollBy:function(){this._transform((new g).translate(h.read(arguments).negate()))},projectToView:function(){return this._matrix._transformPoint(h.read(arguments))},viewToProject:function(){return this._matrix._inverseTransform(h.read(arguments))}},{statics:{_views:[],_viewsById:{},_id:0,create:function(t){return"string"==typeof t&&(t=document.getElementById(t)),new H(t)}}},new function(){function t(t){var e=V.getTarget(t);return e.getAttribute&&Z._viewsById[e.getAttribute("id")]}function e(t,e){return t.viewToProject(V.getOffset(e,t._element))}function n(){if(!Z._focused||!Z._focused.isVisible())for(var t=0,e=Z._views.length;e>t;t++){var n=Z._views[t];if(n&&n.isVisible()){Z._focused=u=n;break}}}function i(n){var i=Z._focused=t(n),r=e(i,n);l=!0,i._onMouseDown&&i._onMouseDown(n,r),(o=i._scope._tool)&&o._onHandleEvent("mousedown",r,n),i.draw(!0)}function r(i){var r;if(l||(r=t(i),r?(h=Z._focused,Z._focused=u=r):u&&u==Z._focused&&(Z._focused=h,n())),r=r||Z._focused){var s=i&&e(r,i);r._onMouseMove&&r._onMouseMove(i,s),(o=r._scope._tool)&&o._onHandleEvent(l&&o.responds("mousedrag")?"mousedrag":"mousemove",s,i)&&V.stop(i),r.draw(!0)}}function s(t){var n=Z._focused;if(n&&l){var i=e(n,t);curPoint=null,l=!1,n._onMouseUp&&n._onMouseUp(t,i),o&&o._onHandleEvent("mouseup",i,t)&&V.stop(t),n.draw(!0)}}function a(t){l&&V.stop(t)}var o,h,u,l=!1;return V.add(document,{mousemove:r,mouseup:s,touchmove:r,touchend:s,selectstart:a,scroll:n}),V.add(window,{load:n}),{_viewHandlers:{mousedown:i,touchstart:i,selectstart:a},statics:{updateFocus:n}}}),H=Z.extend({_class:"CanvasView",initialize:function(t){if(!(t instanceof HTMLCanvasElement)){var e=c.read(arguments);if(e.isZero())throw Error("Cannot create CanvasView with the provided arguments: "+arguments);t=K.getCanvas(e)}var n=this._context=t.getContext("2d");this._eventCounters={};var i=(window.devicePixelRatio||1)/(q.getPrefixValue(n,"backingStorePixelRatio")||1);if(i>1){var r=t.clientWidth,s=t.clientHeight,a=t.style;t.width=r*i,t.height=s*i,a.width=r+"px",a.height=s+"px",n.scale(i,i)}Z.call(this,t)},draw:function(t){if(t&&!this._project._needsRedraw)return!1;var e=this._context,n=this._viewSize;return e.clearRect(0,0,n._width+1,n._height+1),this._project.draw(e,this._matrix),this._project._needsRedraw=!1,!0}},new function(){function t(t,e,n,i,r,s){for(var a,o=i;o;){if(o.responds(t)&&(a||(a=new G(t,e,n,i,r?n.subtract(r):null)),o.fire(t,a)&&(!s||a._stopped)))return!1;o=o.getParent()}return!0}function e(e,n,i,r,s){if(e._eventCounters[n]){var a=e._project,u=a.hitTest(r,{tolerance:a.options.hitTolerance||0,fill:!0,stroke:!0}),l=u&&u.item;if(l)return"mousemove"===n&&l!=o&&(s=r),"mousemove"===n&&h||t(n,i,r,l,s),l}}var n,i,r,s,a,o,h,u,l;return{_onMouseDown:function(t,o){var c=e(this,"mousedown",t,o);u=a==c&&Date.now()-l<300,s=a=c,n=i=r=o,h=s&&s.responds("mousedrag")},_onMouseUp:function(a,o){var c=e(this,"mouseup",a,o);h&&(i&&!i.equals(o)&&t("mousedrag",a,o,s,i),c!=s&&(r=o,t("mousemove",a,o,c,r))),c===s&&(l=Date.now(),(!u||t("doubleclick",a,n,c))&&t("click",a,n,c),u=!1),s=null,h=!1},_onMouseMove:function(n,a){s&&t("mousedrag",n,a,s,i);var h=e(this,"mousemove",n,a,r);i=r=a,h!==o&&(t("mouseleave",n,a,o),o=h,t("mouseenter",n,a,h))}}}),U=e.extend({_class:"Event",initialize:function(t){this.event=t},preventDefault:function(){this._prevented=!0,V.preventDefault(this.event)},stopPropagation:function(){this._stopped=!0,V.stopPropagation(this.event)},stop:function(){this.stopPropagation(),this.preventDefault()},getModifiers:function(){return X.modifiers}}),W=U.extend({_class:"KeyEvent",initialize:function(t,e,n,i){U.call(this,i),this.type=t?"keydown":"keyup",this.key=e,this.character=n},toString:function(){return"{ type: '"+this.type+"', key: '"+this.key+"', character: '"+this.character+"', modifiers: "+this.getModifiers()+" }"}}),X=new function(){function t(t,e,n,r){var s=String.fromCharCode(n),o=i[e]||s.toLowerCase(),h=t?"keydown":"keyup",u=Z._focused,l=u&&u.isVisible()&&u._scope,c=l&&l._tool;a[o]=t,c&&c.responds(h)&&(c.fire(h,new W(t,o,s,r)),u&&u.draw(!0))}var n,i={8:"backspace",9:"tab",13:"enter",16:"shift",17:"control",18:"option",19:"pause",20:"caps-lock",27:"escape",32:"space",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",46:"delete",91:"command",93:"command",224:"command"},r=e.merge({shift:!1,control:!1,option:!1,command:!1,capsLock:!1,space:!1}),s={},a={};return V.add(document,{keydown:function(a){var o,h=a.which||a.keyCode,u=i[h];u?((o=e.camelize(u))in r&&(r[o]=!0),s[h]=0,t(!0,h,null,a)):n=h},keypress:function(e){if(null!=n){var i=e.which||e.keyCode;s[n]=i,t(!0,n,i,e),n=null}},keyup:function(n){var a,o=n.which||n.keyCode,h=i[o];h&&(a=e.camelize(h))in r&&(r[a]=!1),null!=s[o]&&(t(!1,o,s[o],n),delete s[o])}}),{modifiers:r,isDown:function(t){return!!a[t]}}},G=U.extend({_class:"MouseEvent",initialize:function(t,e,n,i,r){U.call(this,e),this.type=t,this.point=n,this.target=i,this.delta=r},toString:function(){return"{ type: '"+this.type+"', point: "+this.point+", target: "+this.target+(this.delta?", delta: "+this.delta:"")+", modifiers: "+this.getModifiers()+" }"}});e.extend(n,{_class:"Palette",_events:["onChange"],initialize:function(n,i,r){var s=q.find(".palettejs-panel")||q.find("body").appendChild(q.create("div",{"class":"palettejs-panel"}));this._element=s.appendChild(q.create("table",{"class":"palettejs-pane"})),this._title=n,r||(r={});for(var a in this._components=i){var o=i[a];o instanceof J||(null==o.value&&(o.value=r[a]),o.name=a,o=i[a]=new J(o)),this._element.appendChild(o._element),o._palette=this,r[a]===t&&(r[a]=o.value)}this._values=e.each(r,function(t,n){var s=i[n];s&&e.define(r,n,{enumerable:!0,configurable:!0,get:function(){return s._value},set:function(t){s.setValue(t)}})}),window.paper&&paper.palettes.push(this)},reset:function(){for(var t in this._components)this._components[t].reset()},remove:function(){q.remove(this._element)}});var J=e.extend(n,{_class:"Component",_events:["onChange","onClick"],_types:{"boolean":{type:"checkbox",value:"checked"},string:{type:"text"},number:{type:"number",number:!0},button:{type:"button"},text:{tag:"div",value:"text"},slider:{type:"range",number:!0},list:{tag:"select",options:function(){q.removeChildren(this._inputItem),q.create(e.each(this._options,function(t){this.push("option",{value:t,text:t})},[]),this._inputItem)}}},initialize:function(t){this._type=t.type in this._types?t.type:"options"in t?"list":"onClick"in t?"button":typeof t.value,this._info=this._types[this._type]||{type:this._type};var n=this,i=!0;this._inputItem=q.create(this._info.tag||"input",{type:this._info.type,events:{change:function(){n.setValue(q.get(this,n._info.value||"value"),i)},click:function(){n.fire("click")}}}),this.attach("change",function(t){i||this._palette.fire("change",this,this.name,t)}),this._element=q.create("tr",[this._labelItem=q.create("td"),"td",[this._inputItem]]),e.each(t,function(t,e){this[e]=t},this),this._defaultValue=this._value,i=!1},getType:function(){return this._type},getLabel:function(){return this._label},setLabel:function(t){this._label=t,q.set(this._labelItem,"text",t+":")},getOptions:function(){return this._options},setOptions:function(t){this._options=t,this._info.options&&this._info.options.call(this)},getValue:function(){return this._value},setValue:function(t,e){var n=this._info.value||"value";q.set(this._inputItem,n,t),t=q.get(this._inputItem,n),this._info.number&&(t=parseFloat(t,10)),this._value!==t&&(this._value=t,e||this.fire("change",t))},getRange:function(){return[parseFloat(q.get(this._inputItem,"min")),parseFloat(q.get(this._inputItem,"max"))]},setRange:function(t,e){var n=Array.isArray(t)?t:[t,e];q.set(this._inputItem,{min:n[0],max:n[1]})},getMin:function(){return this.getRange()[0]},setMin:function(t){this.setRange(t,this.getMax())},getMax:function(){return this.getRange()[1]},setMax:function(t){this.setRange(this.getMin(),t)},getStep:function(){return parseFloat(q.get(this._inputItem,"step"))},setStep:function(t){q.set(this._inputItem,"step",t)},reset:function(){this.setValue(this._defaultValue)}}),$=U.extend({_class:"ToolEvent",_item:null,initialize:function(t,e,n){this.tool=t,this.type=e,this.event=n},_choosePoint:function(t,e){return t?t:e?e.clone():null},getPoint:function(){return this._choosePoint(this._point,this.tool._point)},setPoint:function(t){this._point=t},getLastPoint:function(){return this._choosePoint(this._lastPoint,this.tool._lastPoint)},setLastPoint:function(t){this._lastPoint=t},getDownPoint:function(){return this._choosePoint(this._downPoint,this.tool._downPoint)},setDownPoint:function(t){this._downPoint=t},getMiddlePoint:function(){return!this._middlePoint&&this.tool._lastPoint?this.tool._point.add(this.tool._lastPoint).divide(2):this._middlePoint},setMiddlePoint:function(t){this._middlePoint=t},getDelta:function(){return!this._delta&&this.tool._lastPoint?this.tool._point.subtract(this.tool._lastPoint):this._delta},setDelta:function(t){this._delta=t},getCount:function(){return/^mouse(down|up)$/.test(this.type)?this.tool._downCount:this.tool._count},setCount:function(t){this.tool[/^mouse(down|up)$/.test(this.type)?"downCount":"count"]=t},getItem:function(){if(!this._item){var t=this.tool._scope.project.hitTest(this.getPoint());if(t){for(var e=t.item,n=e._parent;/^(group|compound-path)$/.test(n._type);)e=n,n=n._parent;this._item=e}}return this._item},setItem:function(t){this._item=t},toString:function(){return"{ type: "+this.type+", point: "+this.getPoint()+", count: "+this.getCount()+", modifiers: "+this.getModifiers()+" }"}}),Y=s.extend({_class:"Tool",_list:"tools",_reference:"_tool",_events:["onActivate","onDeactivate","onEditOptions","onMouseDown","onMouseUp","onMouseDrag","onMouseMove","onKeyDown","onKeyUp"],initialize:function(t){s.call(this),this._firstMove=!0,this._count=0,this._downCount=0,this._set(t)},getMinDistance:function(){return this._minDistance},setMinDistance:function(t){this._minDistance=t,null!=this._minDistance&&null!=this._maxDistance&&this._minDistance>this._maxDistance&&(this._maxDistance=this._minDistance)},getMaxDistance:function(){return this._maxDistance},setMaxDistance:function(t){this._maxDistance=t,null!=this._minDistance&&null!=this._maxDistance&&this._maxDistanceu)return!1;var l=null!=i?i:0;if(0!=l)if(u>l)e=this._point.add(h.normalize(l));else if(a)return!1}if(s&&e.equals(this._point))return!1}switch(this._lastPoint=r&&"mousemove"==t?e:this._point,this._point=e,t){case"mousedown":this._lastPoint=this._downPoint,this._downPoint=this._point,this._downCount++;break;case"mouseup":this._lastPoint=this._downPoint}return this._count=r?0:this._count+1,!0},_fireEvent:function(t,e){var n=paper.project._removeSets;if(n){"mouseup"===t&&(n.mousedrag=null);var i=n[t];if(i){for(var r in i){var s=i[r];for(var a in n){var o=n[a];o&&o!=i&&delete o[s._id]}s.remove()}n[t]=null}}return this.responds(t)&&this.fire(t,new $(this,t,e))},_onHandleEvent:function(t,e,n){paper=this._scope;var i=!1;switch(t){case"mousedown":this._updateEvent(t,e,null,null,!0,!1,!1),i=this._fireEvent(t,n);break;case"mousedrag":for(var r=!1,s=!1;this._updateEvent(t,e,this.minDistance,this.maxDistance,!1,r,s);)i=this._fireEvent(t,n)||i,r=!0,s=!0;break;case"mouseup":!e.equals(this._point)&&this._updateEvent("mousedrag",e,this.minDistance,this.maxDistance,!1,!1,!1)&&(i=this._fireEvent("mousedrag",n)),this._updateEvent(t,e,null,this.maxDistance,!1,!1,!1),i=this._fireEvent(t,n)||i,this._updateEvent(t,e,null,null,!0,!1,!1),this._firstMove=!0;break;case"mousemove":for(;this._updateEvent(t,e,this.minDistance,this.maxDistance,this._firstMove,!0,!1);)i=this._fireEvent(t,n)||i,this._firstMove=!1}return i}}),K={canvases:[],getCanvas:function(e,n){var i,r=n===t?e:new c(e,n),s=!0;i=this.canvases.length?this.canvases.pop():document.createElement("canvas");var a=i.getContext("2d");return a.save(),i.width===r.width&&i.height===r.height?s&&a.clearRect(0,0,r.width+1,r.height+1):(i.width=r.width,i.height=r.height),i},getContext:function(t,e){return this.getCanvas(t,e).getContext("2d")},release:function(t){var e=t.canvas?t.canvas:t;e.getContext("2d").restore(),this.canvases.push(e)}},Q=new function(){function t(t,e,n){return.2989*t+.587*e+.114*n}function n(e,n,i,r){var s=r-t(e,n,i);f=e+s,_=n+s,g=i+s;var r=t(f,_,g),a=p(f,_,g),o=v(f,_,g);if(0>a){var h=r-a;f=r+(f-r)*r/h,_=r+(_-r)*r/h,g=r+(g-r)*r/h}if(o>255){var u=255-r,l=o-r;f=r+(f-r)*u/l,_=r+(_-r)*u/l,g=r+(g-r)*u/l}}function i(t,e,n){return v(t,e,n)-p(t,e,n)}function r(t,e,n,i){var r,s=[t,e,n],a=v(t,e,n),o=p(t,e,n);o=o===t?0:o===e?1:2,a=a===t?0:a===e?1:2,r=0===p(o,a)?1===v(o,a)?2:1:0,s[a]>s[o]?(s[r]=(s[r]-s[o])*i/(s[a]-s[o]),s[a]=i):s[r]=s[a]=0,s[o]=0,f=s[0],_=s[1],g=s[2]}var s,a,o,h,u,l,c,d,f,_,g,p=Math.min,v=Math.max,m=Math.abs,y={multiply:function(){f=u*s/255,_=l*a/255,g=c*o/255},screen:function(){f=u+s-u*s/255,_=l+a-l*a/255,g=c+o-c*o/255},overlay:function(){f=128>u?2*u*s/255:255-2*(255-u)*(255-s)/255,_=128>l?2*l*a/255:255-2*(255-l)*(255-a)/255,g=128>c?2*c*o/255:255-2*(255-c)*(255-o)/255},"soft-light":function(){var t=s*u/255;f=t+u*(255-(255-u)*(255-s)/255-t)/255,t=a*l/255,_=t+l*(255-(255-l)*(255-a)/255-t)/255,t=o*c/255,g=t+c*(255-(255-c)*(255-o)/255-t)/255},"hard-light":function(){f=128>s?2*s*u/255:255-2*(255-s)*(255-u)/255,_=128>a?2*a*l/255:255-2*(255-a)*(255-l)/255,g=128>o?2*o*c/255:255-2*(255-o)*(255-c)/255},"color-dodge":function(){f=0===u?0:255===s?255:p(255,255*u/(255-s)),_=0===l?0:255===a?255:p(255,255*l/(255-a)),g=0===c?0:255===o?255:p(255,255*c/(255-o))},"color-burn":function(){f=255===u?255:0===s?0:v(0,255-255*(255-u)/s),_=255===l?255:0===a?0:v(0,255-255*(255-l)/a),g=255===c?255:0===o?0:v(0,255-255*(255-c)/o)},darken:function(){f=s>u?u:s,_=a>l?l:a,g=o>c?c:o},lighten:function(){f=u>s?u:s,_=l>a?l:a,g=c>o?c:o},difference:function(){f=u-s,0>f&&(f=-f),_=l-a,0>_&&(_=-_),g=c-o,0>g&&(g=-g)},exclusion:function(){f=u+s*(255-u-u)/255,_=l+a*(255-l-l)/255,g=c+o*(255-c-c)/255},hue:function(){r(s,a,o,i(u,l,c)),n(f,_,g,t(u,l,c))},saturation:function(){r(u,l,c,i(s,a,o)),n(f,_,g,t(u,l,c))},luminosity:function(){n(u,l,c,t(s,a,o))},color:function(){n(s,a,o,t(u,l,c))},add:function(){f=p(u+s,255),_=p(l+a,255),g=p(c+o,255)},subtract:function(){f=v(u-s,0),_=v(l-a,0),g=v(c-o,0)},average:function(){f=(u+s)/2,_=(l+a)/2,g=(c+o)/2},negation:function(){f=255-m(255-s-u),_=255-m(255-a-l),g=255-m(255-o-c)}},w=this.nativeModes=e.each(["source-over","source-in","source-out","source-atop","destination-over","destination-in","destination-out","destination-atop","lighter","darker","copy","xor"],function(t){this[t]=!0},{}),x=K.getContext(1,1);e.each(y,function(t,e){x.save();var n="darken"===e,i=!1;x.fillStyle=n?"#300":"#a00",x.fillRect(0,0,1,1),x.globalCompositeOperation=e,x.globalCompositeOperation===e&&(x.fillStyle=n?"#a00":"#300",x.fillRect(0,0,1,1),i=x.getImageData(0,0,1,1).data[0]!==(n?170:51)),w[e]=i,x.restore()}),K.release(x),this.process=function(t,e,n,i,r){var p=e.canvas,v="normal"===t;if(v||w[t])n.save(),n.setTransform(1,0,0,1,0,0),n.globalAlpha=i,v||(n.globalCompositeOperation=t),n.drawImage(p,r.x,r.y),n.restore();else{var m=y[t];if(!m)return;for(var x=n.getImageData(r.x,r.y,p.width,p.height),b=x.data,C=e.getImageData(0,0,p.width,p.height).data,S=0,P=b.length;P>S;S+=4){s=C[S],u=b[S],a=C[S+1],l=b[S+1],o=C[S+2],c=b[S+2],h=C[S+3],d=b[S+3],m();var k=h*i/255,z=1-k;b[S]=k*f+z*u,b[S+1]=k*_+z*l,b[S+2]=k*g+z*c,b[S+3]=h*i+z*d}n.putImageData(x,r.x,r.y)}}},te=e.each({fillColor:["fill","color"],strokeColor:["stroke","color"],strokeWidth:["stroke-width","number"],strokeCap:["stroke-linecap","string"],strokeJoin:["stroke-linejoin","string"],miterLimit:["stroke-miterlimit","number"],dashArray:["stroke-dasharray","array"],dashOffset:["stroke-dashoffset","number"],font:["font-family","string"],fontSize:["font-size","number"],justification:["text-anchor","lookup",{left:"start",center:"middle",right:"end"}],opacity:["opacity","number"],blendMode:["mix-blend-mode","string"]},function(t,n){var i=e.capitalize(n),r=t[2];this[n]={type:t[1],property:n,attribute:t[0],toSVG:r,fromSVG:r&&e.each(r,function(t,e){this[t]=e},{}),get:"get"+i,set:"set"+i}},{}),ee={href:"http://www.w3.org/1999/xlink",xlink:"http://www.w3.org/2000/xmlns"};return new function(){function t(t,e){for(var n in e){var i=e[n],r=ee[n];"number"==typeof i&&(i=S.number(i)),r?t.setAttributeNS(r,n,i):t.setAttribute(n,i)}return t}function n(e,n){return t(document.createElementNS("http://www.w3.org/2000/svg",e),n)}function r(t,e,n){var i=t._matrix,r=i.getTranslation(),s={};if(e){i=i.shiftless();var a=i._inverseTransform(r);s[n?"cx":"x"]=a.x,s[n?"cy":"y"]=a.y,r=null}if(i.isIdentity())return s;var h=i.decompose();if(h&&!h.shearing){var u=[],l=h.rotation,c=h.scaling;r&&!r.isZero()&&u.push("translate("+S.point(r)+")"),o.isZero(c.x-1)&&o.isZero(c.y-1)||u.push("scale("+S.point(c)+")"),l&&u.push("rotate("+S.number(l)+")"),s.transform=u.join(" ")}else s.transform="matrix("+i.getValues().join(",")+")";return s}function s(e){for(var i=r(e),s=e._children,a=n("g",i),o=0,h=s.length;h>o;o++){var u=s[o],l=b(u);if(l)if(u.isClipMask()){var c=n("clipPath");c.appendChild(l),w(u,c,"clip"),t(a,{"clip-path":"url(#"+c.id+")"})}else a.appendChild(l)}return a}function h(t){var e=r(t,!0),i=t.getSize();return e.x-=i.width/2,e.y-=i.height/2,e.width=i.width,e.height=i.height,e.href=t.toDataURL(),n("image",e)}function u(t){var e,r,s=t._segments;if(0===s.length)return null;if(t.isPolygon())if(s.length>=3){e=t._closed?"polygon":"polyline";var a=[];for(i=0,l=s.length;l>i;i++)a.push(S.point(s[i]._point));r={points:a.join(" ")}}else{e="line";var o=s[0]._point,h=s[s.length-1]._point;r={x1:o.x,y1:o.y,x2:h.x,y2:h.y}}else{e="path";var u=t.getPathData();r=u&&{d:u}}return n(e,r)}function c(t){var e=t._shape,i=(t.getPosition(!0),t._radius),s=r(t,!0,"rectangle"!==e);if("rectangle"===e){e="rect";var a=t._size,o=a.width,h=a.height;s.x-=o/2,s.y-=h/2,s.width=o,s.height=h,i.isZero()&&(i=null)}return i&&("circle"===e?s.r=i:(s.rx=i.width,s.ry=i.height)),n(e,s)}function d(t){var e=r(t,!0),i=t.getPathData();return i&&(e.d=i),n("path",e)}function f(t){var e=r(t,!0),i=t.getSymbol(),s=m(i,"symbol"),a=i.getDefinition(),o=a.getBounds();return s||(s=n("symbol",{viewBox:S.rectangle(o)}),s.appendChild(b(a)),w(i,s,"symbol")),e.href="#"+s.id,e.x+=o.x,e.y+=o.y,e.width=S.number(o.width),e.height=S.number(o.height),n("use",e)}function _(t){var e=m(t,"color");if(!e){var i,r=t.getGradient(),s=r._radial,a=t.getOrigin().transform(),o=t.getDestination().transform();if(s){i={cx:a.x,cy:a.y,r:a.getDistance(o)};var h=t.getHighlight();h&&(h=h.transform(),i.fx=h.x,i.fy=h.y)}else i={x1:a.x,y1:a.y,x2:o.x,y2:o.y};i.gradientUnits="userSpaceOnUse",e=n((s?"radial":"linear")+"Gradient",i);for(var u=r._stops,l=0,c=u.length;c>l;l++){var d=u[l],f=d._color,_=f.getAlpha();i={offset:d._rampPoint,"stop-color":f.toCSS(!0)},1>_&&(i["stop-opacity"]=_),e.appendChild(n("stop",i))}w(t,e,"color")}return"url(#"+e.id+")"}function g(t){var e=n("text",r(t,!0));return e.textContent=t._content,e}function p(n,i){var r={},s=n.getParent();return null!=n._name&&(r.id=n._name),e.each(te,function(t){var i=t.get,a=t.type,o=n[i]();if(!s||!e.equals(s[i](),o)){if("color"===a&&null!=o){var h=o.getAlpha();1>h&&(r[t.attribute+"-opacity"]=h)}r[t.attribute]=null==o?"none":"number"===a?S.number(o):"color"===a?o.gradient?_(o,n):o.toCSS(!0):"array"===a?o.join(","):"lookup"===a?t.toSVG[o]:o}}),1===r.opacity&&delete r.opacity,null==n._visibility||n._visibility||(r.visibility="hidden"),t(i,r)}function m(t,e){return P||(P={ids:{},svgs:{}}),t&&P.svgs[e+"-"+t._id]}function w(t,e,n){P||m();var i=P.ids[n]=(P.ids[n]||0)+1;e.id=n+"-"+i,P.svgs[n+"-"+t._id]=e}function x(t,e){if(!P)return t;var i="svg"===t.nodeName.toLowerCase()&&t,r=null;for(var s in P.svgs)r||(i||(i=n("svg"),i.appendChild(t)),r=i.insertBefore(n("defs"),i.firstChild)),r.appendChild(P.svgs[s]);return P=null,e.asString?(new XMLSerializer).serializeToString(i):i}function b(t){var e=k[t._type],n=e&&e(t,t._type);return n&&t._data&&n.setAttribute("data-paper-data",JSON.stringify(t._data)),n&&p(t,n)}function C(t){return t||(t={}),S=new a(t.precision),t}var S,P,k={group:s,layer:s,raster:h,path:u,shape:c,"compound-path":d,"placed-symbol":f,"point-text":g};y.inject({exportSVG:function(t){return t=C(t),x(b(this),t) -}}),v.inject({exportSVG:function(t){t=C(t);for(var e=this.layers,i=this.view.getSize(),r=n("svg",{x:0,y:0,width:i.width,height:i.height,version:"1.1",xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink"}),s=0,a=e.length;a>s;s++)r.appendChild(b(e[s]));return x(r,t)}})},new function(){function n(t,e,n,i){var r=ee[e],s=r?t.getAttributeNS(r,e):t.getAttribute(e);return"null"===s&&(s=null),null==s?i?null:n?"":0:n?s:parseFloat(s)}function i(t,e,i,r){return e=n(t,e,!1,r),i=n(t,i,!1,r),r&&null==e&&null==i?null:new h(e||0,i||0)}function r(t,e,i,r){return e=n(t,e,!1,r),i=n(t,i,!1,r),r&&null==e&&null==i?null:new c(e||0,i||0)}function s(t,e,n){return"none"===t?null:"number"===e?parseFloat(t):"array"===e?t?t.split(/[\s,]+/g).map(parseFloat):[]:"color"===e?S(t)||t:"lookup"===e?n[t]:t}function a(t,e,n){var i=t.childNodes,r="clippath"===e,s=new w,a=s._project,o=a._currentStyle,h=[];r||(s._transformContent=!1,s=x(s,t),a._currentStyle=s._style.clone());for(var u=0,l=i.length;l>u;u++){var c,d=i[u];1!==d.nodeType||!(c=P(d,n))||c instanceof m||h.push(c)}return s.addChildren(h),r&&(s=x(s.reduce(),t)),a._currentStyle=o,(r||"defs"===e)&&(s.remove(),s=null),s}function o(t,e){var n=new O,i=t.points;n.moveTo(i.getItem(0));for(var r=1,s=i.numberOfItems;s>r;r++)n.lineTo(i.getItem(r));return"polygon"===e&&n.closePath(),n}function u(t){var e=t.getAttribute("d"),n=e.match(/m/gi).length>1?new L:new O;return n.setPathData(e),n}function l(t,e){for(var r=t.childNodes,s=[],a=0,o=r.length;o>a;a++){var h=r[a];1===h.nodeType&&s.push(x(new R,h))}var u,l,c,d="radialgradient"===e,f=new N(s,d);return d?(u=i(t,"cx","cy"),l=u.add(n(t,"r"),0),c=i(t,"fx","fy",!0)):(u=i(t,"x1","y1"),l=i(t,"x2","y2")),x(new B(f,u,l,c),t),null}function d(t,e,n,i){for(var r=(i.getAttribute(n)||"").split(/\)\s*/g),s=new g,a=0,o=r.length;o>a;a++){var h=r[a];if(!h)break;for(var u=h.split("("),l=u[0],c=u[1].split(/[\s,]+/g),d=0,f=c.length;f>d;d++)c[d]=parseFloat(c[d]);switch(l){case"matrix":s.concatenate(new g(c[0],c[1],c[2],c[3],c[4],c[5]));break;case"rotate":s.rotate(c[0],c[1],c[2]);break;case"translate":s.translate(c[0],c[1]);break;case"scale":s.scale(c);break;case"skewX":case"skewY":var e=Math.tan(c[0]*Math.PI/180),_="skewX"==l;s.shear(_?e:0,_?0:e)}}t.transform(s)}function _(t,e,n){var i=t["fill-opacity"===n?"getFillColor":"getStrokeColor"]();i&&i.setAlpha(parseFloat(e))}function p(n,i,r){var s=n.attributes[i],a=s&&s.value;if(!a){var o=e.camelize(i);a=n.style[o],a||r.node[o]===r.parent[o]||(a=r.node[o])}return a?"none"===a?null:a:t}function x(n,i){var r={node:q.getStyles(i)||{},parent:q.getStyles(i.parentNode)||{}};return e.each(z,function(s,a){var o=p(i,a,r);o!==t&&(n=e.pick(s(n,o,a,i,r),n))}),n}function S(t){var e=t&&t.match(/\((?:#|)([^)']+)/);return e&&M[e[1]]}function P(t,e,n){e||(e={}),"string"==typeof t&&(t=(new DOMParser).parseFromString(t,"image/svg+xml"));var i=t.nodeName.toLowerCase(),r=k[i],s=r&&r(t,i,e),a="#document"!==i&&t.getAttribute("data-paper-data");return e.expandShapes&&s instanceof b&&(s.remove(),s=s.toPath()),!s||s instanceof w||(s=x(s,t)),s&&a&&(s._data=JSON.parse(a)),n&&(M={}),s}var k={"#document":function(t,e,n){return P(t.childNodes[0],n)},g:a,svg:a,clippath:a,polygon:o,polyline:o,path:u,lineargradient:l,radialgradient:l,image:function(t){var e=new C(n(t,"href",!0));return e.attach("load",function(){var e=r(t,"width","height");this.setSize(e),this.translate(i(t,"x","y").add(e.divide(2)))}),e},symbol:function(t,e){return new m(a(t,e),!0)},defs:a,use:function(t){var e=(n(t,"href",!0)||"").substring(1),r=M[e],s=i(t,"x","y");return r?r instanceof m?r.place(s):r.clone().translate(s):null},circle:function(t){return new b.Circle(i(t,"cx","cy"),n(t,"r"))},ellipse:function(t){return new b.Ellipse({center:i(t,"cx","cy"),radius:r(t,"rx","ry")})},rect:function(t){var e=i(t,"x","y"),n=r(t,"width","height"),s=r(t,"rx","ry");return new b.Rectangle(new f(e,n),s)},line:function(t){return new O.Line(i(t,"x1","y1"),i(t,"x2","y2"))},text:function(t){var e=new j(i(t,"x","y").add(i(t,"dx","dy")));return e.setContent(t.textContent.trim()||""),e}},z=e.merge(e.each(te,function(t){this[t.attribute]=function(e,n){e[t.set](s(n,t.type,t.fromSVG))}},{}),{id:function(t,e){M[e]=t,t.setName&&t.setName(e)},"clip-path":function(t,e){var n=S(e);if(n){if(n=n.clone(),n.setClipMask(!0),!(t instanceof w))return new w(n,t);t.insertChild(0,n)}},gradientTransform:d,transform:d,"fill-opacity":_,"stroke-opacity":_,visibility:function(t,e){t.setVisible("visible"===e)},"stop-color":function(t,e){t.setColor&&t.setColor(e)},"stop-opacity":function(t,e){t._color&&t._color.setAlpha(parseFloat(e))},offset:function(t,e){var n=e.match(/(.*)%$/);t.setRampPoint(n?n[1]/100:parseFloat(e))},viewBox:function(t,e,n,i,a){var o=new f(s(e,"array")),h=r(i,"width","height",!0);if(t instanceof w){var u=h?o.getSize().divide(h):1,l=(new g).translate(o.getPoint()).scale(u);t.transform(l.inverted())}else if(t instanceof m){h&&o.setSize(h);var c="visible"!=p(i,"overflow",a),d=t._definition;c&&!o.contains(d.getBounds())&&(c=new b.Rectangle(o).transform(d._matrix),c.setClipMask(!0),d.addChild(c))}}}),M={};y.inject({importSVG:function(t,e){return this.addChild(P(t,e,!0))}}),v.inject({importSVG:function(t,e){return this.activate(),P(t,e,!0)}})},paper=new(r.inject(e.merge(e.exports,{enumerable:!0,Base:e,Numerical:o,DomElement:q,DomEvent:V,Key:X}))),"function"==typeof define&&define.amd&&define("paper",paper),paper};paper.PaperScope.prototype.PaperScript=function(root){function _$_(t,e,n){var i=binaryOperators[e];if(t&&t[i]){var r=t[i](n);return"!="===e?!r:r}switch(e){case"+":return t+n;case"-":return t-n;case"*":return t*n;case"/":return t/n;case"%":return t%n;case"==":return t==n;case"!=":return t!=n}}function $_(t,e){var n=unaryOperators[t];if(n&&e&&e[n])return e[n]();switch(t){case"+":return+e;case"-":return-e}}function compile(t){function e(t){for(var e=0,n=s.length;n>e;e++){var i=s[e];if(i[0]>=t)break;t+=i[1]}return t}function n(n){return t.substring(e(n.range[0]),e(n.range[1]))}function i(n,i){for(var r=e(n.range[0]),a=e(n.range[1]),o=0,h=s.length-1;h>=0;h--)if(r>s[h][0]){o=h+1;break}s.splice(o,0,[r,i.length-a+r]),t=t.substring(0,r)+i+t.substring(a)}function r(t,e){if(t){for(var s in t)if("range"!==s){var a=t[s];if(Array.isArray(a))for(var o=0,h=a.length;h>o;o++)r(a[o],t);else a&&"object"==typeof a&&r(a,t)}switch(t&&t.type){case"BinaryExpression":if(t.operator in binaryOperators&&"Literal"!==t.left.type){var u=n(t.left),l=n(t.right);i(t,"_$_("+u+', "'+t.operator+'", '+l+")")}break;case"AssignmentExpression":if(/^.=$/.test(t.operator)&&"Literal"!==t.left.type){var u=n(t.left),l=n(t.right);i(t,u+" = _$_("+u+', "'+t.operator[0]+'", '+l+")")}break;case"UpdateExpression":if(!(t.prefix||e&&("BinaryExpression"===e.type&&/^[=!<>]/.test(e.operator)||"MemberExpression"===e.type&&e.computed))){var c=n(t.argument);i(t,c+" = _$_("+c+', "'+t.operator[0]+'", 1)')}break;case"UnaryExpression":if(t.operator in unaryOperators&&"Literal"!==t.argument.type){var c=n(t.argument);i(t,'$_("'+t.operator+'", '+c+")")}}}}var s=[];return r(scope.acorn.parse(t,{ranges:!0})),t}function evaluate(code,scope){paper=scope;var view=scope.project&&scope.project.view,res;with(scope)!function(){var onActivate,onDeactivate,onEditOptions,onMouseDown,onMouseUp,onMouseDrag,onMouseMove,onKeyDown,onKeyUp,onFrame,onResize;res=eval(compile(code)),/on(?:Key|Mouse)(?:Up|Down|Move|Drag)/.test(code)&&Base.each(paper.Tool.prototype._events,function(key){var value=eval(key);value&&(scope.getTool()[key]=value)}),view&&(view.setOnResize(onResize),view.fire("resize",{size:view.size,delta:new Point}),view.setOnFrame(onFrame),view.draw())}.call(scope);return res}function request(t,e){var n=new(window.ActiveXObject||XMLHttpRequest)("Microsoft.XMLHTTP");return n.open("GET",t,!0),n.overrideMimeType&&n.overrideMimeType("text/plain"),n.onreadystatechange=function(){return 4===n.readyState?evaluate(n.responseText,e):void 0},n.send(null)}function load(){for(var t=document.getElementsByTagName("script"),e=0,n=t.length;n>e;e++){var i=t[e];if(/^text\/(?:x-|)paperscript$/.test(i.type)&&!i.getAttribute("data-paper-ignore")){var r=PaperScope.getAttribute(i,"canvas"),s=PaperScope.get(r)||new PaperScope(i).setup(r);i.src?request(i.src,s):evaluate(i.innerHTML,s),i.setAttribute("data-paper-ignore",!0)}}}var Base=paper.Base,PaperScope=paper.PaperScope,exports,define,scope=this;!function(t,e){return"object"==typeof exports&&"object"==typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):(e(t.acorn||(t.acorn={})),void 0)}(this,function(t){"use strict";function e(t){ce=t||{};for(var e in ge)Object.prototype.hasOwnProperty.call(ce,e)||(ce[e]=ge[e]);_e=ce.sourceFile||null}function n(t,e){var n=pe(de,t);e+=" ("+n.line+":"+n.column+")";var i=new SyntaxError(e);throw i.pos=t,i.loc=n,i.raisedAt=ve,i}function i(t){function e(t){if(1==t.length)return n+="return str === "+JSON.stringify(t[0])+";";n+="switch(str){";for(var e=0;e3){i.sort(function(t,e){return e.length-t.length}),n+="switch(str.length){";for(var r=0;rve&&10!==n&&13!==n&&8232!==n&&8329!==n;)++ve,n=de.charCodeAt(ve);ce.onComment&&ce.onComment(!1,de.slice(t+2,ve),t,ve,e,ce.locations&&new r)}function u(){for(;fe>ve;){var t=de.charCodeAt(ve);if(32===t)++ve;else if(13===t){++ve;var e=de.charCodeAt(ve);10===e&&++ve,ce.locations&&(++Pe,ke=ve)}else if(10===t)++ve,++Pe,ke=ve;else if(14>t&&t>8)++ve;else if(47===t){var e=de.charCodeAt(ve+1);if(42===e)o();else{if(47!==e)break;h()}}else if(160===t)++ve;else{if(!(t>=5760&&Un.test(String.fromCharCode(t))))break;++ve}}}function l(){var t=de.charCodeAt(ve+1);return t>=48&&57>=t?S(!0):(++ve,a(xn))}function c(){var t=de.charCodeAt(ve+1);return Se?(++ve,x()):61===t?w(Pn,2):w(Cn,1)}function d(){var t=de.charCodeAt(ve+1);return 61===t?w(Pn,2):w(Bn,1)}function f(t){var e=de.charCodeAt(ve+1);return e===t?w(124===t?In:An,2):61===e?w(Pn,2):w(124===t?On:Tn,1)}function _(){var t=de.charCodeAt(ve+1);return 61===t?w(Pn,2):w(Ln,1)}function g(t){var e=de.charCodeAt(ve+1);return e===t?w(zn,2):61===e?w(Pn,2):w(kn,1)}function p(t){var e=de.charCodeAt(ve+1),n=1;return e===t?(n=62===t&&62===de.charCodeAt(ve+2)?3:2,61===de.charCodeAt(ve+n)?w(Pn,n+1):w(jn,n)):(61===e&&(n=61===de.charCodeAt(ve+2)?3:2),w(En,n))}function v(t){var e=de.charCodeAt(ve+1);return 61===e?w(Dn,61===de.charCodeAt(ve+2)?3:2):w(61===t?Sn:Mn,1)}function m(t){switch(t){case 46:return l();case 40:return++ve,a(pn);case 41:return++ve,a(vn);case 59:return++ve,a(yn);case 44:return++ve,a(mn);case 91:return++ve,a(dn);case 93:return++ve,a(fn);case 123:return++ve,a(_n);case 125:return++ve,a(gn);case 58:return++ve,a(wn);case 63:return++ve,a(bn);case 48:var e=de.charCodeAt(ve+1);if(120===e||88===e)return C();case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return S(!1);case 34:case 39:return P(t);case 47:return c(t);case 37:case 42:return d();case 124:case 38:return f(t);case 94:return _();case 43:case 45:return g(t);case 60:case 62:return p(t);case 61:case 33:return v(t);case 126:return w(Mn,1)}return!1}function y(t){if(t?ve=me+1:me=ve,ce.locations&&(we=new r),t)return x();if(ve>=fe)return a(Ne);var e=de.charCodeAt(ve);if(Kn(e)||92===e)return M();var i=m(e);if(i===!1){var s=String.fromCharCode(e);if("\\"===s||Gn.test(s))return M();n(ve,"Unexpected character '"+s+"'")}return i}function w(t,e){var n=de.slice(ve,ve+e);ve+=e,a(t,n)}function x(){for(var t,e,i="",r=ve;;){ve>=fe&&n(r,"Unterminated regular expression");var s=de.charAt(ve);if($n.test(s)&&n(r,"Unterminated regular expression"),t)t=!1;else{if("["===s)e=!0;else if("]"===s&&e)e=!1;else if("/"===s&&!e)break;t="\\"===s}++ve}var i=de.slice(r,ve);++ve;var o=z();return o&&!/^[gmsiy]*$/.test(o)&&n(r,"Invalid regexp flag"),a(Ee,RegExp(i,o))}function b(t,e){for(var n=ve,i=0,r=0,s=null==e?1/0:e;s>r;++r){var a,o=de.charCodeAt(ve);if(a=o>=97?o-97+10:o>=65?o-65+10:o>=48&&57>=o?o-48:1/0,a>=t)break;++ve,i=i*t+a}return ve===n||null!=e&&ve-n!==e?null:i}function C(){ve+=2;var t=b(16);return null==t&&n(me+2,"Expected hexadecimal number"),Kn(de.charCodeAt(ve))&&n(ve,"Identifier directly after number"),a(De,t)}function S(t){var e=ve,i=!1,r=48===de.charCodeAt(ve);t||null!==b(10)||n(e,"Invalid number"),46===de.charCodeAt(ve)&&(++ve,b(10),i=!0);var s=de.charCodeAt(ve);(69===s||101===s)&&(s=de.charCodeAt(++ve),(43===s||45===s)&&++ve,null===b(10)&&n(e,"Invalid number"),i=!0),Kn(de.charCodeAt(ve))&&n(ve,"Identifier directly after number");var o,h=de.slice(e,ve);return i?o=parseFloat(h):r&&1!==h.length?/[89]/.test(h)||Le?n(e,"Invalid number"):o=parseInt(h,8):o=parseInt(h,10),a(De,o)}function P(t){ve++;for(var e="";;){ve>=fe&&n(me,"Unterminated string constant");var i=de.charCodeAt(ve);if(i===t)return++ve,a(je,e);if(92===i){i=de.charCodeAt(++ve);var r=/^[0-7]+/.exec(de.slice(ve,ve+3));for(r&&(r=r[0]);r&&parseInt(r,8)>255;)r=r.slice(0,r.length-1);if("0"===r&&(r=null),++ve,r)Le&&n(ve-2,"Octal literal in strict mode"),e+=String.fromCharCode(parseInt(r,8)),ve+=r.length-1;else switch(i){case 110:e+="\n";break;case 114:e+="\r";break;case 120:e+=String.fromCharCode(k(2));break;case 117:e+=String.fromCharCode(k(4));break;case 85:e+=String.fromCharCode(k(8));break;case 116:e+=" ";break;case 98:e+="\b";break;case 118:e+=" ";break;case 102:e+="\f";break;case 48:e+="\0";break;case 13:10===de.charCodeAt(ve)&&++ve;case 10:ce.locations&&(ke=ve,++Pe);break;default:e+=String.fromCharCode(i)}}else(13===i||10===i||8232===i||8329===i)&&n(me,"Unterminated string constant"),e+=String.fromCharCode(i),++ve}}function k(t){var e=b(16,t);return null===e&&n(me,"Bad character escape sequence"),e}function z(){Rn=!1;for(var t,e=!0,i=ve;;){var r=de.charCodeAt(ve);if(Qn(r))Rn&&(t+=de.charAt(ve)),++ve;else{if(92!==r)break;Rn||(t=de.slice(i,ve)),Rn=!0,117!=de.charCodeAt(++ve)&&n(ve,"Expecting Unicode escape sequence \\uXXXX"),++ve;var s=k(4),a=String.fromCharCode(s);a||n(ve-1,"Invalid Unicode escape"),(e?Kn(s):Qn(s))||n(ve-4,"Invalid Unicode escape"),t+=a}e=!1}return Rn?t:de.slice(i,ve)}function M(){var t=z(),e=Be;return Rn||(Hn(t)?e=cn[t]:(ce.forbidReserved&&(3===ce.ecmaVersion?Fn:qn)(t)||Le&&Vn(t))&&n(me,"The keyword '"+t+"' is reserved")),a(e,t)}function I(){ze=me,Me=ye,Ie=xe,y()}function A(t){for(Le=t,ve=Me;ke>ve;)ke=de.lastIndexOf("\n",ke-2)+1,--Pe;u(),y()}function O(){this.type=null,this.start=me,this.end=null}function L(){this.start=we,this.end=null,null!==_e&&(this.source=_e)}function T(){var t=new O;return ce.locations&&(t.loc=new L),ce.ranges&&(t.range=[me,0]),t}function D(t){var e=new O;return e.start=t.start,ce.locations&&(e.loc=new L,e.loc.start=t.loc.start),ce.ranges&&(e.range=[t.range[0],0]),e}function E(t,e){return t.type=e,t.end=Me,ce.locations&&(t.loc.end=Ie),ce.ranges&&(t.range[1]=Me),t}function j(t){return ce.ecmaVersion>=5&&"ExpressionStatement"===t.type&&"Literal"===t.expression.type&&"use strict"===t.expression.value}function B(t){return be===t?(I(),!0):void 0}function N(){return!ce.strictSemicolons&&(be===Ne||be===gn||$n.test(de.slice(Me,me)))}function R(){B(yn)||N()||q()}function F(t){be===t?I():q()}function q(){n(me,"Unexpected token")}function V(t){"Identifier"!==t.type&&"MemberExpression"!==t.type&&n(t.start,"Assigning to rvalue"),Le&&"Identifier"===t.type&&Zn(t.name)&&n(t.start,"Assigning to "+t.name+" in strict mode")}function Z(t){ze=Me=ve,ce.locations&&(Ie=new r),Ae=Le=null,Oe=[],y();var e=t||T(),n=!0;for(t||(e.body=[]);be!==Ne;){var i=H();e.body.push(i),n&&j(i)&&A(!0),n=!1}return E(e,"Program")}function H(){be===Cn&&y(!0);var t=be,e=T();switch(t){case Re:case Ve:I();var i=t===Re;B(yn)||N()?e.label=null:be!==Be?q():(e.label=le(),R());for(var r=0;re){var r=D(t);r.left=t,r.operator=Ce,I(),r.right=te(ee(),i,n);var r=E(r,/&&|\|\|/.test(r.operator)?"LogicalExpression":"BinaryExpression");return te(r,e,n)}return t}function ee(){if(be.prefix){var t=T(),e=be.isUpdate;return t.operator=Ce,t.prefix=!0,I(),t.argument=ee(),e?V(t.argument):Le&&"delete"===t.operator&&"Identifier"===t.argument.type&&n(t.start,"Deleting local variable in strict mode"),E(t,e?"UpdateExpression":"UnaryExpression")}for(var i=ne();be.postfix&&!N();){var t=D(i);t.operator=Ce,t.prefix=!1,t.argument=i,V(i),I(),i=E(t,"UpdateExpression")}return i}function ne(){return ie(re())}function ie(t,e){if(B(xn)){var n=D(t);return n.object=t,n.property=le(!0),n.computed=!1,ie(E(n,"MemberExpression"),e)}if(B(dn)){var n=D(t);return n.object=t,n.property=$(),n.computed=!0,F(fn),ie(E(n,"MemberExpression"),e)}if(!e&&B(pn)){var n=D(t);return n.callee=t,n.arguments=ue(vn,!1),ie(E(n,"CallExpression"),e)}return t}function re(){switch(be){case an:var t=T();return I(),E(t,"ThisExpression");case Be:return le();case De:case je:case Ee:var t=T();return t.value=Ce,t.raw=de.slice(me,ye),I(),E(t,"Literal");case on:case hn:case un:var t=T();return t.value=be.atomValue,t.raw=be.keyword,I(),E(t,"Literal");case pn:var e=we,n=me;I();var i=$();return i.start=n,i.end=ye,ce.locations&&(i.loc.start=e,i.loc.end=xe),ce.ranges&&(i.range=[n,ye]),F(vn),i;case dn:var t=T();return I(),t.elements=ue(fn,!0,!0),E(t,"ArrayExpression");case _n:return ae();case Je:var t=T();return I(),he(t,!1);case sn:return se();default:q()}}function se(){var t=T();return I(),t.callee=ie(re(),!0),t.arguments=B(pn)?ue(vn,!1):Te,E(t,"NewExpression")}function ae(){var t=T(),e=!0,i=!1;for(t.properties=[],I();!B(gn);){if(e)e=!1;else if(F(mn),ce.allowTrailingCommas&&B(gn))break;var r,s={key:oe()},a=!1;if(B(wn)?(s.value=$(!0),r=s.kind="init"):ce.ecmaVersion>=5&&"Identifier"===s.key.type&&("get"===s.key.name||"set"===s.key.name)?(a=i=!0,r=s.kind=s.key.name,s.key=oe(),be!==pn&&q(),s.value=he(T(),!1)):q(),"Identifier"===s.key.type&&(Le||i))for(var o=0;oa?t.id:t.params[a];if((Vn(o.name)||Zn(o.name))&&n(o.start,"Defining '"+o.name+"' in strict mode"),a>=0)for(var h=0;a>h;++h)o.name===t.params[h].name&&n(o.start,"Argument name clash in strict mode")}return E(t,e?"FunctionDeclaration":"FunctionExpression")}function ue(t,e,n){for(var i=[],r=!0;!B(t);){if(r)r=!1;else if(F(mn),e&&ce.allowTrailingCommas&&B(t))break;n&&be===mn?i.push(null):i.push($(!0))}return i}function le(t){var e=T();return e.name=be===Be?Ce:t&&!ce.forbidReserved&&be.keyword||q(),I(),E(e,"Identifier")}t.version="0.3.2";var ce,de,fe,_e;t.parse=function(t,n){return de=t+"",fe=de.length,e(n),s(),Z(ce.program)};var ge=t.defaultOptions={ecmaVersion:5,strictSemicolons:!1,allowTrailingCommas:!0,forbidReserved:!1,locations:!1,onComment:null,ranges:!1,program:null,sourceFile:null},pe=t.getLineInfo=function(t,e){for(var n=1,i=0;;){Yn.lastIndex=i;var r=Yn.exec(t);if(!(r&&r.indext?36===t:91>t?!0:97>t?95===t:123>t?!0:t>=170&&Gn.test(String.fromCharCode(t)) +var paper=new function(t){var e=new function(){function n(e,n,i,r,a,o){function u(r,s,o,u){var s=s||(s=f(n,r))&&(s.get?s:s.value);"string"==typeof s&&"#"===s[0]&&(s=e[s.substring(1)]||s);var c,d="function"==typeof s,_=s,p=a||d?s&&s.get?r in e:e[r]:null;!(o||s!==t&&n.hasOwnProperty(r))||a&&p||(d&&p&&(s.base=p),d&&l&&0===s.length&&(c=r.match(/^(get|is)(([A-Z])(.*))$/))&&l.push([c[3].toLowerCase()+c[4],c[2]]),_&&!d&&_.get&&"function"==typeof _.get&&0===_.get.length||(_={value:_,writable:!0}),(f(e,r)||{configurable:!0}).configurable&&(_.configurable=!0,_.enumerable=i),g(e,r,_)),!u||!d||a&&u[r]||(u[r]=function(t){return t&&e[r].apply(t,h.call(arguments,1))})}var l;if(n){l=[];for(var c in n)n.hasOwnProperty(c)&&!s.test(c)&&u(c,null,!0,o);u("toString"),u("valueOf");for(var d=0,_=l.length;_>d;d++){var p=l[d],v=p[1];u(p[0],{get:e["get"+v]||e["is"+v],set:e["set"+v]},!0)}}return e}function i(n,i,r,s){try{n&&(s||t===s&&c(n)?u:l).call(n,i,r=r||n)}catch(a){if(a!==e.stop)throw a}return r}function r(t){return i(t,function(t,e){this[e]=t},new t.constructor)}var s=/^(statics|generics|preserve|enumerable|prototype|toString|valueOf)$/,a=Object.prototype.toString,o=Array.prototype,h=o.slice,u=o.forEach||function(t,e){for(var n=0,i=this.length;i>n;n++)t.call(e,this[n],n,this)},l=function(t,e){for(var n in this)this.hasOwnProperty(n)&&t.call(e,this[n],n,this)},c=Array.isArray=Array.isArray||function(t){return"[object Array]"===a.call(t)},d=Object.create||function(t){return{__proto__:t}},f=Object.getOwnPropertyDescriptor||function(t,e){var n=t.__lookupGetter__&&t.__lookupGetter__(e);return n?{get:n,set:t.__lookupSetter__(e),enumerable:!0,configurable:!0}:t.hasOwnProperty(e)?{value:t[e],enumerable:!0,configurable:!0,writable:!0}:null},_=Object.defineProperty||function(t,e,n){return(n.get||n.set)&&t.__defineGetter__?(n.get&&t.__defineGetter__(e,n.get),n.set&&t.__defineSetter__(e,n.set)):t[e]=n.value,t},g=function(t,e,n){return delete t[e],_(t,e,n)};return n(function(){},{inject:function(t){if(t){var e=this.prototype,i=Object.getPrototypeOf(e).constructor,r=t.statics===!0?t:t.statics;r!=t&&n(e,t,t.enumerable,i&&i.prototype,t.preserve,t.generics&&this),n(this,r,!0,i,t.preserve)}for(var s=1,a=arguments.length;a>s;s++)this.inject(arguments[s]);return this},extend:function(){for(var t,e=this,i=0,r=arguments.length;r>i&&!(t=arguments[i].initialize);i++);return t=t||function(){e.apply(this,arguments)},t.prototype=d(this.prototype),g(t.prototype,"constructor",{value:t,writable:!0,configurable:!0}),n(t,this,!0),arguments.length?this.inject.apply(t,arguments):t}},!0).inject({inject:function(){for(var t=0,e=arguments.length;e>t;t++)n(this,arguments[t],arguments[t].enumerable);return this},extend:function(){var t=d(this);return t.inject.apply(t,arguments)},each:function(t,e){return i(this,t,e)},clone:function(){return r(this)},statics:{each:i,clone:r,create:d,define:g,describe:f,isPlainObject:function(t){var n=null!=t&&t.constructor;return n&&(n===Object||n===e||"Object"===n.name)},pick:function(){for(var e=0,n=arguments.length;n>e;e++)if(arguments[e]!==t)return arguments[e];return null},stop:{}}})};"undefined"!=typeof module&&(module.exports=e),e.inject({generics:!0,clone:function(){return new this.constructor(this)},toString:function(){return null!=this._id?(this._class||"Object")+(this._name?" '"+this._name+"'":" @"+this._id):"{ "+e.each(this,function(t,e){if(!/^_/.test(e)){var n=typeof t;this.push(e+": "+("number"===n?a.instance.number(t):"string"===n?"'"+t+"'":t))}},[]).join(", ")+" }"},exportJSON:function(t){return e.exportJSON(this,t)},toJSON:function(){return e.serialize(this)},_set:function(n,i){if(n&&e.isPlainObject(n)){var r=n._filtering||n;for(var s in r)if(s in this&&r.hasOwnProperty(s)&&(!i||!i[s])){var a=n[s];a!==t&&(this[s]=a)}return!0}},statics:{exports:{},extend:function ie(){var t=ie.base.apply(this,arguments),n=t.prototype._class;return n&&!e.exports[n]&&(e.exports[n]=t),t},equals:function(t,n){function i(t,e){for(var n in t)if(t.hasOwnProperty(n)&&!e.hasOwnProperty(n))return!1;return!0}if(t===n)return!0;if(t&&t.equals)return t.equals(n);if(n&&n.equals)return n.equals(t);if(Array.isArray(t)&&Array.isArray(n)){if(t.length!==n.length)return!1;for(var r=0,s=t.length;s>r;r++)if(!e.equals(t[r],n[r]))return!1;return!0}if(t&&"object"==typeof t&&n&&"object"==typeof n){if(!i(t,n)||!i(n,t))return!1;for(var r in t)if(t.hasOwnProperty(r)&&!e.equals(t[r],n[r]))return!1;return!0}return!1},read:function(t,n,i,r){if(this===e){var s=this.peek(t,n);return t._index++,t.__read=1,s}var a=this.prototype,o=a._readIndex,h=n||o&&t._index||0;i||(i=t.length-h);var u=t[h];return u instanceof this||r&&r.readNull&&null==u&&1>=i?(o&&(t._index=h+1),u&&r&&r.clone?u.clone():u):(u=e.create(this.prototype),o&&(u.__read=!0),r&&(u.__options=r),u=u.initialize.apply(u,h>0||is;s++)r.push(Array.isArray(i=t[s])?this.read(i,0,0,n):this.read(t,s,1,n));return r},readNamed:function(n,i,r,s,a){var o=this.getNamed(n,i),h=o!==t;if(h){var u=n._filtered;u||(u=n._filtered=e.create(n[0]),u._filtering=n[0]),u[i]=t}return this.read(h?[o]:n,r,s,a)},getNamed:function(n,i){var r=n[0];return n._hasObject===t&&(n._hasObject=1===n.length&&e.isPlainObject(r)),n._hasObject?i?r[i]:n._filtered||r:t},hasNamed:function(t,e){return!!this.getNamed(t,e)},isPlainValue:function(t){return this.isPlainObject(t)||Array.isArray(t)},serialize:function(t,n,i,r){n=n||{};var s,o=!r;if(o&&(n.formatter=new a(n.precision),r={length:0,definitions:{},references:{},add:function(t,e){var n="#"+t._id,i=this.references[n];if(!i){this.length++;var r=e.call(t),s=t._class;s&&r[0]!==s&&r.unshift(s),this.definitions[n]=r,i=this.references[n]=[n]}return i}}),t&&t._serialize){s=t._serialize(n,r);var h=t._class;!h||i||s._compact||s[0]===h||s.unshift(h)}else if(Array.isArray(t)){s=[];for(var u=0,l=t.length;l>u;u++)s[u]=e.serialize(t[u],n,i,r);i&&(s._compact=!0)}else if(e.isPlainObject(t)){s={};for(var u in t)t.hasOwnProperty(u)&&(s[u]=e.serialize(t[u],n,i,r))}else s="number"==typeof t?n.formatter.number(t,n.precision):t;return o&&r.length>0?[["dictionary",r.definitions],s]:s},deserialize:function(t,n,i){var r=t;if(i=i||{},Array.isArray(t)){var s=t[0],a="dictionary"===s;if(!a){if(i.dictionary&&1==t.length&&/^#/.test(s))return i.dictionary[s];s=e.exports[s]}r=[];for(var o=s?1:0,h=t.length;h>o;o++)r.push(e.deserialize(t[o],null,i));if(a)i.dictionary=r[0];else if(s){var u=r;r=n instanceof s?n:e.create(s.prototype),s.apply(r,u)}}else if(e.isPlainObject(t)){r={};for(var l in t)r[l]=e.deserialize(t[l],null,i)}return r},exportJSON:function(t,n){return JSON.stringify(e.serialize(t,n))},importJSON:function(t,n){return e.deserialize("string"==typeof t?JSON.parse(t):t,n)},splice:function(e,n,i,r){var s=n&&n.length,a=i===t;i=a?e.length:i,i>e.length&&(i=e.length);for(var o=0;s>o;o++)n[o]._index=i+o;if(a)return e.push.apply(e,n),[];var h=[i,r];n&&h.push.apply(h,n);for(var u=e.splice.apply(e,h),o=0,l=u.length;l>o;o++)delete u[o]._index;for(var o=i+s,l=e.length;l>o;o++)e[o]._index=o;return u},merge:function(){return e.each(arguments,function(t){e.each(t,function(t,e){this[e]=t},this)},new e,!0)},capitalize:function(t){return t.replace(/\b[a-z]/g,function(t){return t.toUpperCase()})},camelize:function(t){return t.replace(/-(.)/g,function(t,e){return e.toUpperCase()})},hyphenate:function(t){return t.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}}});var n={attach:function(n,i){if("string"!=typeof n)return e.each(n,function(t,e){this.attach(e,t)},this),t;var r=this._eventTypes[n];if(r){var s=this._handlers=this._handlers||{};s=s[n]=s[n]||[],-1==s.indexOf(i)&&(s.push(i),r.install&&1==s.length&&r.install.call(this,n))}},detach:function(n,i){if("string"!=typeof n)return e.each(n,function(t,e){this.detach(e,t)},this),t;var r,s=this._eventTypes[n],a=this._handlers&&this._handlers[n];s&&a&&(!i||-1!=(r=a.indexOf(i))&&1==a.length?(s.uninstall&&s.uninstall.call(this,n),delete this._handlers[n]):-1!=r&&a.splice(r,1))},once:function(t,e){this.attach(t,function(){e.apply(this,arguments),this.detach(t,e)})},fire:function(t,n){var i=this._handlers&&this._handlers[t];if(!i)return!1;var r=[].slice.call(arguments,1);return e.each(i,function(t){t.apply(this,r)===!1&&n&&n.stop&&n.stop()},this),!0},responds:function(t){return!(!this._handlers||!this._handlers[t])},on:"#attach",off:"#detach",trigger:"#fire",statics:{inject:function re(){for(var t=0,n=arguments.length;n>t;t++){var i=arguments[t],r=i._events;if(r){var s={};e.each(r,function(t,n){var r="string"==typeof t,a=r?t:n,o=e.capitalize(a),h=a.substring(2).toLowerCase();s[h]=r?{}:t,a="_"+a,i["get"+o]=function(){return this[a]},i["set"+o]=function(t){t?this.attach(h,t):this[a]&&this.detach(h,this[a]),this[a]=t}}),i._eventTypes=s}re.base.call(this,i)}return this}}},r=e.extend({_class:"PaperScope",initialize:function se(t){if(paper=this,this.project=null,this.projects=[],this.tools=[],this.palettes=[],this._id=t&&(t.getAttribute("id")||t.src)||"paperscope-"+se._id++,t&&t.setAttribute("id",this._id),se._scopes[this._id]=this,!this.support){var e=Q.getContext(1,1);se.prototype.support={nativeDash:"setLineDash"in e||"mozDash"in e,nativeBlendModes:te.nativeModes},Q.release(e)}},version:"0.9.11",getView:function(){return this.project&&this.project.view},getTool:function(){return this._tool||(this._tool=new Y),this._tool},getPaper:function(){return this},evaluate:function(t){var e=paper.PaperScript.evaluate(t,this);return H.updateFocus(),e},install:function(t){var n=this;e.each(["project","view","tool"],function(i){e.define(t,i,{configurable:!0,get:function(){return n[i]}})});for(var i in this)/^(version|_id)/.test(i)||(t[i]=this[i])},setup:function(t){return paper=this,this.project=new v(t),this},activate:function(){paper=this},clear:function(){for(var t=this.projects.length-1;t>=0;t--)this.projects[t].remove();for(var t=this.tools.length-1;t>=0;t--)this.tools[t].remove();for(var t=this.palettes.length-1;t>=0;t--)this.palettes[t].remove()},remove:function(){this.clear(),delete r._scopes[this._id]},statics:new function(){function t(t){return t+="Attribute",function(e,n){return e[t](n)||e[t]("data-paper-"+n)}}return{_scopes:{},_id:0,get:function(t){return"object"==typeof t&&(t=t.getAttribute("id")),this._scopes[t]||null},getAttribute:t("get"),hasAttribute:t("has")}}}),s=e.extend(n,{initialize:function(t){this._scope=paper,this._index=this._scope[this._list].push(this)-1,(t||!this._scope[this._reference])&&this.activate()},activate:function(){if(!this._scope)return!1;var t=this._scope[this._reference];return t&&t!=this&&t.fire("deactivate"),this._scope[this._reference]=this,this.fire("activate",t),!0},isActive:function(){return this._scope[this._reference]===this},remove:function(){return null==this._index?!1:(e.splice(this._scope[this._list],null,this._index,1),this._scope[this._reference]==this&&(this._scope[this._reference]=null),this._scope=null,!0)}}),a=e.extend({initialize:function(t){this.precision=t||5,this.multiplier=Math.pow(10,this.precision)},number:function(t){return Math.round(t*this.multiplier)/this.multiplier},point:function(t,e){return this.number(t.x)+(e||",")+this.number(t.y)},size:function(t,e){return this.number(t.width)+(e||",")+this.number(t.height)},rectangle:function(t,e){return this.point(t,e)+(e||",")+this.size(t,e)}});a.instance=new a;var o=new function(){var e=[[.5773502691896257],[0,.7745966692414834],[.33998104358485626,.8611363115940526],[0,.5384693101056831,.906179845938664],[.2386191860831969,.6612093864662645,.932469514203152],[0,.4058451513773972,.7415311855993945,.9491079123427585],[.1834346424956498,.525532409916329,.7966664774136267,.9602898564975363],[0,.3242534234038089,.6133714327005904,.8360311073266358,.9681602395076261],[.14887433898163122,.4333953941292472,.6794095682990244,.8650633666889845,.9739065285171717],[0,.26954315595234496,.5190961292068118,.7301520055740494,.8870625997680953,.978228658146057],[.1252334085114689,.3678314989981802,.5873179542866175,.7699026741943047,.9041172563704749,.9815606342467192],[0,.2304583159551348,.44849275103644687,.6423493394403402,.8015780907333099,.9175983992229779,.9841830547185881],[.10805494870734367,.31911236892788974,.5152486363581541,.6872929048116855,.827201315069765,.9284348836635735,.9862838086968123],[0,.20119409399743451,.3941513470775634,.5709721726085388,.7244177313601701,.8482065834104272,.937273392400706,.9879925180204854],[.09501250983763744,.2816035507792589,.45801677765722737,.6178762444026438,.755404408355003,.8656312023878318,.9445750230732326,.9894009349916499]],n=[[1],[.8888888888888888,.5555555555555556],[.6521451548625461,.34785484513745385],[.5688888888888889,.47862867049936647,.23692688505618908],[.46791393457269104,.3607615730481386,.17132449237917036],[.4179591836734694,.3818300505051189,.27970539148927664,.1294849661688697],[.362683783378362,.31370664587788727,.22238103445337448,.10122853629037626],[.3302393550012598,.31234707704000286,.26061069640293544,.1806481606948574,.08127438836157441],[.29552422471475287,.26926671930999635,.21908636251598204,.1494513491505806,.06667134430868814],[.2729250867779006,.26280454451024665,.23319376459199048,.18629021092773426,.1255803694649046,.05566856711617366],[.24914704581340277,.2334925365383548,.20316742672306592,.16007832854334622,.10693932599531843,.04717533638651183],[.2325515532308739,.22628318026289723,.2078160475368885,.17814598076194574,.13887351021978725,.09212149983772845,.04048400476531588],[.2152638534631578,.2051984637212956,.18553839747793782,.15720316715819355,.12151857068790319,.08015808715976021,.03511946033175186],[.2025782419255613,.19843148532711158,.1861610000155622,.16626920581699392,.13957067792615432,.10715922046717194,.07036604748810812,.03075324199611727],[.1894506104550685,.18260341504492358,.16915651939500254,.14959598881657674,.12462897125553388,.09515851168249279,.062253523938647894,.027152459411754096]],i=Math.abs,r=Math.sqrt,s=Math.pow,a=Math.cos,h=Math.PI;return{TOLERANCE:1e-5,EPSILON:1e-11,KAPPA:4*(r(2)-1)/3,isZero:function(t){return i(t)<=o.EPSILON},integrate:function(t,i,r,s){for(var a=e[s-2],o=n[s-2],h=.5*(r-i),u=h+i,l=0,c=s+1>>1,d=1&s?o[l++]*t(u):0;c>l;){var f=h*a[l];d+=o[l++]*(t(u+f)+t(u-f))}return h*d},findRoot:function(t,e,n,r,s,a,o){for(var h=0;a>h;h++){var u=t(n),l=u/e(n);if(i(l)0?(s=n,n=r>=c?.5*(r+s):c):(r=n,n=c>=s?.5*(r+s):c)}},solveQuadratic:function(e,n,s,a,o,h){function u(t){return(l||t>=o&&h>=t)&&(a[c++]=t),c}var l=o===t,c=0,d=this.EPSILON;if(i(e)=d?u(-s/n):i(s)g)return 0;var p=g>_?r(g-_):0;return u(p-f),p>0&&u(-p-f),c},solveCubic:function(e,n,u,l,c,d,f){function _(t){return(p||t>=d&&f>=t)&&(c[v++]=t),v}var g=this.EPSILON;if(i(e)0?1:-1;return _(2*-S*C-n),_(S*C-n)}if(0>b){var C=r(y),P=Math.acos(w/(C*C*C))/3,k=-2*C,z=2*h/3;return _(k*a(P)-n),_(k*a(P+z)-n),_(k*a(P-z)-n)}var M=(w>0?-1:1)*s(i(w)+r(b),1/3);return _(M+y/M-n)}}},h=e.extend({_class:"Point",_readIndex:!0,initialize:function(t,e){var n=typeof t;if("number"===n){var i="number"==typeof e;this.x=t,this.y=i?e:t,this.__read&&(this.__read=i?2:1)}else"undefined"===n||null===t?(this.x=this.y=0,this.__read&&(this.__read=null===t?1:0)):(Array.isArray(t)?(this.x=t[0],this.y=t.length>1?t[1]:t[0]):null!=t.x?(this.x=t.x,this.y=t.y):null!=t.width?(this.x=t.width,this.y=t.height):null!=t.angle?(this.x=t.length,this.y=0,this.setAngle(t.angle)):(this.x=this.y=0,this.__read&&(this.__read=0)),this.__read&&(this.__read=1))},set:function(t,e){return this.x=t,this.y=e,this},equals:function(t){return t===this||t&&(this.x===t.x&&this.y===t.y||Array.isArray(t)&&this.x===t[0]&&this.y===t[1])||!1},clone:function(){return new h(this.x,this.y)},toString:function(){var t=a.instance;return"{ x: "+t.number(this.x)+", y: "+t.number(this.y)+" }"},_serialize:function(t){var e=t.formatter;return[e.number(this.x),e.number(this.y)]},add:function(t){return t=h.read(arguments),new h(this.x+t.x,this.y+t.y)},subtract:function(t){return t=h.read(arguments),new h(this.x-t.x,this.y-t.y)},multiply:function(t){return t=h.read(arguments),new h(this.x*t.x,this.y*t.y)},divide:function(t){return t=h.read(arguments),new h(this.x/t.x,this.y/t.y)},modulo:function(t){return t=h.read(arguments),new h(this.x%t.x,this.y%t.y)},negate:function(){return new h(-this.x,-this.y)},transform:function(t){return t?t._transformPoint(this):this},getDistance:function(t,e){t=h.read(arguments);var n=t.x-this.x,i=t.y-this.y,r=n*n+i*i;return e?r:Math.sqrt(r)},getLength:function(){var t=this.x*this.x+this.y*this.y;return arguments.length&&arguments[0]?t:Math.sqrt(t)},setLength:function(t){if(this.isZero()){var e=this._angle||0;this.set(Math.cos(e)*t,Math.sin(e)*t)}else{var n=t/this.getLength();o.isZero(n)&&this.getAngle(),this.set(this.x*n,this.y*n)}return this},normalize:function(e){e===t&&(e=1);var n=this.getLength(),i=0!==n?e/n:0,r=new h(this.x*i,this.y*i);return r._angle=this._angle,r},getAngle:function(){return 180*this.getAngleInRadians(arguments[0])/Math.PI},setAngle:function(t){if(t=this._angle=t*Math.PI/180,!this.isZero()){var e=this.getLength();this.set(Math.cos(t)*e,Math.sin(t)*e)}return this},getAngleInRadians:function(){if(arguments[0]===t)return null==this._angle&&(this._angle=Math.atan2(this.y,this.x)),this._angle;var e=h.read(arguments),n=this.getLength()*e.getLength();return o.isZero(n)?0/0:Math.acos(this.dot(e)/n)},getAngleInDegrees:function(){return this.getAngle(arguments[0])},getQuadrant:function(){return this.x>=0?this.y>=0?1:4:this.y>=0?2:3},getDirectedAngle:function(t){return t=h.read(arguments),180*Math.atan2(this.cross(t),this.dot(t))/Math.PI},rotate:function(t,e){if(0===t)return this.clone();t=t*Math.PI/180;var n=e?this.subtract(e):this,i=Math.sin(t),r=Math.cos(t);return n=new h(n.x*r-n.y*i,n.y*r+n.x*i),e?n.add(e):n},isInside:function(t){return t.contains(this)},isClose:function(t,e){return this.getDistance(t)1?t[1]:t[0]):null!=t.width?(this.width=t.width,this.height=t.height):null!=t.x?(this.width=t.x,this.height=t.y):(this.width=this.height=0,this.__read&&(this.__read=0)),this.__read&&(this.__read=1))},set:function(t,e){return this.width=t,this.height=e,this},equals:function(t){return t===this||t&&(this.width===t.width&&this.height===t.height||Array.isArray(t)&&this.width===t[0]&&this.height===t[1])||!1},clone:function(){return new c(this.width,this.height)},toString:function(){var t=a.instance;return"{ width: "+t.number(this.width)+", height: "+t.number(this.height)+" }"},_serialize:function(t){var e=t.formatter;return[e.number(this.width),e.number(this.height)]},add:function(t){return t=c.read(arguments),new c(this.width+t.width,this.height+t.height)},subtract:function(t){return t=c.read(arguments),new c(this.width-t.width,this.height-t.height)},multiply:function(t){return t=c.read(arguments),new c(this.width*t.width,this.height*t.height)},divide:function(t){return t=c.read(arguments),new c(this.width/t.width,this.height/t.height)},modulo:function(t){return t=c.read(arguments),new c(this.width%t.width,this.height%t.height)},negate:function(){return new c(-this.width,-this.height)},isZero:function(){return o.isZero(this.width)&&o.isZero(this.height)},isNaN:function(){return isNaN(this.width)||isNaN(this.height)},statics:{min:function(t,e){return new c(Math.min(t.width,e.width),Math.min(t.height,e.height))},max:function(t,e){return new c(Math.max(t.width,e.width),Math.max(t.height,e.height))},random:function(){return new c(Math.random(),Math.random())}}},e.each(["round","ceil","floor","abs"],function(t){var e=Math[t];this[t]=function(){return new c(e(this.width),e(this.height))}},{})),d=c.extend({initialize:function(t,e,n,i){this._width=t,this._height=e,this._owner=n,this._setter=i},set:function(t,e,n){return this._width=t,this._height=e,n||this._owner[this._setter](this),this},getWidth:function(){return this._width},setWidth:function(t){this._width=t,this._owner[this._setter](this)},getHeight:function(){return this._height},setHeight:function(t){this._height=t,this._owner[this._setter](this)}}),f=e.extend({_class:"Rectangle",_readIndex:!0,initialize:function(n,i,r,s){var a=typeof n,o=0;if("number"===a?(this.x=n,this.y=i,this.width=r,this.height=s,o=4):"undefined"===a||null===n?(this.x=this.y=this.width=this.height=0,o=null===n?1:0):1===arguments.length&&(Array.isArray(n)?(this.x=n[0],this.y=n[1],this.width=n[2],this.height=n[3],o=1):n.x!==t||n.width!==t?(this.x=n.x||0,this.y=n.y||0,this.width=n.width||0,this.height=n.height||0,o=1):n.from===t&&n.to===t&&(this.x=this.y=this.width=this.height=0,this._set(n),o=1)),!o){var u=h.readNamed(arguments,"from"),l=e.peek(arguments);if(this.x=u.x,this.y=u.y,l&&l.x!==t||e.hasNamed(arguments,"to")){var d=h.readNamed(arguments,"to");this.width=d.x-u.x,this.height=d.y-u.y,this.width<0&&(this.x=d.x,this.width=-this.width),this.height<0&&(this.y=d.y,this.height=-this.height)}else{var f=c.read(arguments);this.width=f.width,this.height=f.height}o=arguments._index}this.__read&&(this.__read=o)},set:function(t,e,n,i){return this.x=t,this.y=e,this.width=n,this.height=i,this},clone:function(){return new f(this.x,this.y,this.width,this.height)},equals:function(t){return e.isPlainValue(t)&&(t=f.read(arguments)),t===this||t&&this.x===t.x&&this.y===t.y&&this.width===t.width&&this.height===t.height||!1},toString:function(){var t=a.instance;return"{ x: "+t.number(this.x)+", y: "+t.number(this.y)+", width: "+t.number(this.width)+", height: "+t.number(this.height)+" }"},_serialize:function(t){var e=t.formatter;return[e.number(this.x),e.number(this.y),e.number(this.width),e.number(this.height)]},getPoint:function(){return new(arguments[0]?h:u)(this.x,this.y,this,"setPoint")},setPoint:function(t){t=h.read(arguments),this.x=t.x,this.y=t.y},getSize:function(){return new(arguments[0]?c:d)(this.width,this.height,this,"setSize")},setSize:function(t){t=c.read(arguments),this._fixX&&(this.x+=(this.width-t.width)*this._fixX),this._fixY&&(this.y+=(this.height-t.height)*this._fixY),this.width=t.width,this.height=t.height,this._fixW=1,this._fixH=1},getLeft:function(){return this.x},setLeft:function(t){this._fixW||(this.width-=t-this.x),this.x=t,this._fixX=0},getTop:function(){return this.y},setTop:function(t){this._fixH||(this.height-=t-this.y),this.y=t,this._fixY=0},getRight:function(){return this.x+this.width},setRight:function(e){this._fixX!==t&&1!==this._fixX&&(this._fixW=0),this._fixW?this.x=e-this.width:this.width=e-this.x,this._fixX=1},getBottom:function(){return this.y+this.height},setBottom:function(e){this._fixY!==t&&1!==this._fixY&&(this._fixH=0),this._fixH?this.y=e-this.height:this.height=e-this.y,this._fixY=1},getCenterX:function(){return this.x+.5*this.width},setCenterX:function(t){this.x=t-.5*this.width,this._fixX=.5},getCenterY:function(){return this.y+.5*this.height},setCenterY:function(t){this.y=t-.5*this.height,this._fixY=.5},getCenter:function(){return new(arguments[0]?h:u)(this.getCenterX(),this.getCenterY(),this,"setCenter")},setCenter:function(t){return t=h.read(arguments),this.setCenterX(t.x),this.setCenterY(t.y),this},isEmpty:function(){return 0==this.width||0==this.height},contains:function(e){return e&&e.width!==t||4==(Array.isArray(e)?e:arguments).length?this._containsRectangle(f.read(arguments)):this._containsPoint(h.read(arguments))},_containsPoint:function(t){var e=t.x,n=t.y;return e>=this.x&&n>=this.y&&e<=this.x+this.width&&n<=this.y+this.height},_containsRectangle:function(t){var e=t.x,n=t.y;return e>=this.x&&n>=this.y&&e+t.width<=this.x+this.width&&n+t.height<=this.y+this.height},intersects:function(t){return t=f.read(arguments),t.x+t.width>this.x&&t.y+t.height>this.y&&t.x=this.x&&t.y+t.height>=this.y&&t.x<=this.x+this.width&&t.y<=this.y+this.height},intersect:function(t){t=f.read(arguments);var e=Math.max(this.x,t.x),n=Math.max(this.y,t.y),i=Math.min(this.x+this.width,t.x+t.width),r=Math.min(this.y+this.height,t.y+t.height);return new f(e,n,i-e,r-n)},unite:function(t){t=f.read(arguments);var e=Math.min(this.x,t.x),n=Math.min(this.y,t.y),i=Math.max(this.x+this.width,t.x+t.width),r=Math.max(this.y+this.height,t.y+t.height);return new f(e,n,i-e,r-n)},include:function(t){t=h.read(arguments);var e=Math.min(this.x,t.x),n=Math.min(this.y,t.y),i=Math.max(this.x+this.width,t.x),r=Math.max(this.y+this.height,t.y);return new f(e,n,i-e,r-n)},expand:function(e,n){return n===t&&(n=e),new f(this.x-e/2,this.y-n/2,this.width+e,this.height+n)},scale:function(e,n){return this.expand(this.width*e-this.width,this.height*(n===t?e:n)-this.height)}},new function(){return e.each([["Top","Left"],["Top","Right"],["Bottom","Left"],["Bottom","Right"],["Left","Center"],["Top","Center"],["Right","Center"],["Bottom","Center"]],function(t,e){var n=t.join(""),i=/^[RL]/.test(n);e>=4&&(t[1]+=i?"Y":"X");var r=t[i?0:1],s=t[i?1:0],a="get"+r,o="get"+s,l="set"+r,c="set"+s,d="get"+n,f="set"+n;this[d]=function(){return new(arguments[0]?h:u)(this[a](),this[o](),this,f)},this[f]=function(t){t=h.read(arguments),this[l](t.x),this[c](t.y)}},{})}),_=f.extend({initialize:function(t,e,n,i,r,s){this.set(t,e,n,i,!0),this._owner=r,this._setter=s},set:function(t,e,n,i,r){return this._x=t,this._y=e,this._width=n,this._height=i,r||this._owner[this._setter](this),this}},new function(){var t=f.prototype;return e.each(["x","y","width","height"],function(t){var n=e.capitalize(t),i="_"+t;this["get"+n]=function(){return this[i]},this["set"+n]=function(t){this[i]=t,this._dontNotify||this._owner[this._setter](this)}},e.each(["Point","Size","Center","Left","Top","Right","Bottom","CenterX","CenterY","TopLeft","TopRight","BottomLeft","BottomRight","LeftCenter","TopCenter","RightCenter","BottomCenter"],function(e){var n="set"+e;this[n]=function(){this._dontNotify=!0,t[n].apply(this,arguments),delete this._dontNotify,this._owner[this._setter](this)}},{isSelected:function(){return this._owner._boundsSelected},setSelected:function(t){var e=this._owner;e.setSelected&&(e._boundsSelected=t,e.setSelected(t||e._selectedSegmentState>0))}}))}),g=e.extend({_class:"Matrix",initialize:function ae(t){var e=arguments.length,n=!0;if(6===e?this.set.apply(this,arguments):1===e?t instanceof ae?this.set(t._a,t._c,t._b,t._d,t._tx,t._ty):Array.isArray(t)?this.set.apply(this,t):n=!1:0===e?this.reset():n=!1,!n)throw Error("Unsupported matrix parameters")},set:function(t,e,n,i,r,s){return this._a=t,this._c=e,this._b=n,this._d=i,this._tx=r,this._ty=s,this},_serialize:function(t){return e.serialize(this.getValues(),t)},clone:function(){return new g(this._a,this._c,this._b,this._d,this._tx,this._ty)},equals:function(t){return t===this||t&&this._a===t._a&&this._b===t._b&&this._c===t._c&&this._d===t._d&&this._tx===t._tx&&this._ty===t._ty||!1},toString:function(){var t=a.instance;return"[["+[t.number(this._a),t.number(this._b),t.number(this._tx)].join(", ")+"], ["+[t.number(this._c),t.number(this._d),t.number(this._ty)].join(", ")+"]]"},reset:function(){return this._a=this._d=1,this._c=this._b=this._tx=this._ty=0,this},scale:function(){var t=h.read(arguments),e=h.read(arguments,0,0,{readNull:!0});return e&&this.translate(e),this._a*=t.x,this._c*=t.x,this._b*=t.y,this._d*=t.y,e&&this.translate(e.negate()),this},translate:function(t){t=h.read(arguments);var e=t.x,n=t.y;return this._tx+=e*this._a+n*this._b,this._ty+=e*this._c+n*this._d,this},rotate:function(t,e){e=h.read(arguments,1),t=t*Math.PI/180;var n=e.x,i=e.y,r=Math.cos(t),s=Math.sin(t),a=n-n*r+i*s,o=i-n*s-i*r,u=this._a,l=this._b,c=this._c,d=this._d;return this._a=r*u+s*l,this._b=-s*u+r*l,this._c=r*c+s*d,this._d=-s*c+r*d,this._tx+=a*u+o*l,this._ty+=a*c+o*d,this},shear:function(){var t=h.read(arguments),e=h.read(arguments,0,0,{readNull:!0});e&&this.translate(e);var n=this._a,i=this._c;return this._a+=t.y*this._b,this._c+=t.y*this._d,this._b+=t.x*n,this._d+=t.x*i,e&&this.translate(e.negate()),this},concatenate:function(t){var e=this._a,n=this._b,i=this._c,r=this._d;return this._a=t._a*e+t._c*n,this._b=t._b*e+t._d*n,this._c=t._a*i+t._c*r,this._d=t._b*i+t._d*r,this._tx+=t._tx*e+t._ty*n,this._ty+=t._tx*i+t._ty*r,this},preConcatenate:function(t){var e=this._a,n=this._b,i=this._c,r=this._d,s=this._tx,a=this._ty;return this._a=t._a*e+t._b*i,this._b=t._a*n+t._b*r,this._c=t._c*e+t._d*i,this._d=t._c*n+t._d*r,this._tx=t._a*s+t._b*a+t._tx,this._ty=t._c*s+t._d*a+t._ty,this},isIdentity:function(){return 1==this._a&&0==this._c&&0==this._b&&1==this._d&&0==this._tx&&0==this._ty},isInvertible:function(){return!!this._getDeterminant()},isSingular:function(){return!this._getDeterminant()},transform:function(t,e,n,i,r){return arguments.length<5?this._transformPoint(h.read(arguments)):this._transformCoordinates(t,e,n,i,r)},_transformPoint:function(t,e,n){var i=t.x,r=t.y;return e||(e=new h),e.set(i*this._a+r*this._b+this._tx,i*this._c+r*this._d+this._ty,n)},_transformCoordinates:function(t,e,n,i,r){for(var s=e,a=i,o=s+2*r;o>s;){var h=t[s++],u=t[s++];n[a++]=h*this._a+u*this._b+this._tx,n[a++]=h*this._c+u*this._d+this._ty}return n},_transformCorners:function(t){var e=t.x,n=t.y,i=e+t.width,r=n+t.height,s=[e,n,i,n,i,r,e,r];return this._transformCoordinates(s,0,s,0,4)},_transformBounds:function(t,e,n){for(var i=this._transformCorners(t),r=i.slice(0,2),s=i.slice(),a=2;8>a;a++){var o=i[a],h=1&a;os[h]&&(s[h]=o)}return e||(e=new f),e.set(r[0],r[1],s[0]-r[0],s[1]-r[1],n)},inverseTransform:function(){return this._inverseTransform(h.read(arguments))},_getDeterminant:function(){var t=this._a*this._d-this._b*this._c;return isFinite(t)&&!o.isZero(t)&&isFinite(this._tx)&&isFinite(this._ty)?t:null},_inverseTransform:function(t,e,n){var i=this._getDeterminant();if(!i)return null;var r=t.x-this._tx,s=t.y-this._ty;return e||(e=new h),e.set((r*this._d-s*this._b)/i,(s*this._a-r*this._c)/i,n)},decompose:function(){var t=this._a,e=this._b,n=this._c,i=this._d;if(o.isZero(t*i-e*n))return null;var r=Math.sqrt(t*t+e*e);t/=r,e/=r;var s=t*n+e*i;n-=t*s,i-=e*s;var a=Math.sqrt(n*n+i*i);return n/=a,i/=a,s/=a,e*n>t*i&&(t=-t,e=-e,s=-s,r=-r),{translation:this.getTranslation(),scaling:new h(r,a),rotation:180*-Math.atan2(e,t)/Math.PI,shearing:s} +},getValues:function(){return[this._a,this._c,this._b,this._d,this._tx,this._ty]},getTranslation:function(){return new h(this._tx,this._ty)},getScaling:function(){return(this.decompose()||{}).scaling},getRotation:function(){return(this.decompose()||{}).rotation},inverted:function(){var t=this._getDeterminant();return t&&new g(this._d/t,-this._c/t,-this._b/t,this._a/t,(this._b*this._ty-this._d*this._tx)/t,(this._c*this._tx-this._a*this._ty)/t)},shiftless:function(){return new g(this._a,this._c,this._b,this._d,0,0)},applyToContext:function(t){t.transform(this._a,this._c,this._b,this._d,this._tx,this._ty)}},new function(){return e.each({scaleX:"_a",scaleY:"_d",translateX:"_tx",translateY:"_ty",shearX:"_b",shearY:"_c"},function(t,n){n=e.capitalize(n),this["get"+n]=function(){return this[t]},this["set"+n]=function(e){this[t]=e}},{})}),p=e.extend({_class:"Line",initialize:function(t,e,n,i,r){var s=!1;arguments.length>=4?(this._px=t,this._py=e,this._vx=n,this._vy=i,s=r):(this._px=t.x,this._py=t.y,this._vx=e.x,this._vy=e.y,s=n),s||(this._vx-=this._px,this._vy-=this._py)},getPoint:function(){return new h(this._px,this._py)},getVector:function(){return new h(this._vx,this._vy)},getLength:function(){return this.getVector().getLength()},intersect:function(t,e){return p.intersect(this._px,this._py,this._vx,this._vy,t._px,t._py,t._vx,t._vy,!0,e)},getSide:function(t){return p.getSide(this._px,this._py,this._vx,this._vy,t.x,t.y,!0)},getDistance:function(t){return Math.abs(p.getSignedDistance(this._px,this._py,this._vx,this._vy,t.x,t.y,!0))},statics:{intersect:function(t,e,n,i,r,s,a,u,l,c){l||(n-=t,i-=e,a-=r,u-=s);var d=u*n-a*i;if(!o.isZero(d)){var f=t-r,_=e-s,g=(a*_-u*f)/d,p=(n*_-i*f)/d;if((c||g>=0&&1>=g)&&(c||p>=0&&1>=p))return new h(t+g*n,e+g*i)}},getSide:function(t,e,n,i,r,s,a){a||(n-=t,i-=e);var o=r-t,h=s-e,u=o*i-h*n;return 0===u&&(u=o*n+h*i,u>0&&(o-=n,h-=i,u=o*n+h*i,0>u&&(u=0))),0>u?-1:u>0?1:0},getSignedDistance:function(t,e,n,i,r,s,a){a||(n-=t,i-=e);var o=i/n,h=e-o*t;return(s-o*r-h)/Math.sqrt(o*o+1)}}}),v=s.extend({_class:"Project",_list:"projects",_reference:"project",initialize:function(t){s.call(this,!0),this.layers=[],this.symbols=[],this._currentStyle=new F,this.activeLayer=new x,t&&(this.view=t instanceof H?t:H.create(t)),this._selectedItems={},this._selectedItemCount=0,this._drawCount=0,this.options={}},_serialize:function(t,n){return e.serialize(this.layers,t,!0,n)},clear:function(){for(var t=this.layers.length-1;t>=0;t--)this.layers[t].remove();this.symbols=[]},remove:function oe(){return oe.base.call(this)?(this.view&&this.view.remove(),!0):!1},getCurrentStyle:function(){return this._currentStyle},setCurrentStyle:function(t){this._currentStyle.initialize(t)},getIndex:function(){return this._index},getSelectedItems:function(){var t=[];for(var e in this._selectedItems){var n=this._selectedItems[e];n.isInserted()&&t.push(n)}return t},_updateSelection:function(t){var e=t._id,n=this._selectedItems;t._selected?n[e]!==t&&(this._selectedItemCount++,n[e]=t):n[e]===t&&(this._selectedItemCount--,delete n[e])},selectAll:function(){for(var t=this.layers,e=0,n=t.length;n>e;e++)t[e].setFullySelected(!0)},deselectAll:function(){var t=this._selectedItems;for(var e in t)t[e].setFullySelected(!1)},hitTest:function(t,n){t=h.read(arguments),n=P.getOptions(e.read(arguments));for(var i=this.layers.length-1;i>=0;i--){var r=this.layers[i].hitTest(t,n);if(r)return r}return null}},new function(){function t(t,e,n){for(var i=t.layers,r=n&&[],s=0,a=i.length;a>s;s++){var o=i[s][n?"getItems":"getItem"](e);if(n)r.push.apply(r,o);else if(o)return o}return n?r:null}return{getItems:function(e){return t(this,e,!0)},getItem:function(e){return t(this,e,!1)}}},{importJSON:function(t){return this.activate(),e.importJSON(t)},draw:function(t,n){this._drawCount++,t.save(),n.applyToContext(t);for(var i=e.merge({offset:new h(0,0),transforms:[n],trackTransforms:!0}),r=0,s=this.layers.length;s>r;r++)this.layers[r].draw(t,i);if(t.restore(),this._selectedItemCount>0){t.save(),t.strokeWidth=1;for(var a in this._selectedItems){var o=this._selectedItems[a];if(o._drawCount===this._drawCount&&(o._drawSelected||o._boundsSelected)){var u=o.getSelectedColor()||o.getLayer().getSelectedColor();t.strokeStyle=t.fillStyle=u?u.toCanvasStyle(t):"#009dec";var l=o._globalMatrix;if(o._drawSelected&&o._drawSelected(t,l),o._boundsSelected){var c=l._transformCorners(o._getBounds("getBounds"));t.beginPath();for(var r=0;8>r;r++)t[0===r?"moveTo":"lineTo"](c[r],c[++r]);t.closePath(),t.stroke();for(var r=0;8>r;r++)t.beginPath(),t.rect(c[r]-2,c[++r]-2,4,4),t.fill()}}}t.restore()}}}),m=e.extend({_class:"Symbol",initialize:function he(t,e){this._id=he._id=(he._id||0)+1,this.project=paper.project,this.project.symbols.push(this),t&&this.setDefinition(t,e),this._instances={}},_serialize:function(t,n){return n.add(this,function(){return e.serialize([this._class,this._definition],t,!1,n)})},_changed:function(t){e.each(this._instances,function(e){e._changed(t)})},getDefinition:function(){return this._definition},setDefinition:function(t){t._parentSymbol&&(t=t.clone()),this._definition&&delete this._definition._parentSymbol,this._definition=t,t.remove(),t.setSelected(!1),arguments[1]||t.setPosition(new h),t._parentSymbol=this,this._changed(5)},place:function(t){return new S(this,t)},clone:function(){return new m(this._definition.clone(!1))}}),y=e.extend(n,{statics:{extend:function ue(t){t._serializeFields&&(t._serializeFields=e.merge(this.prototype._serializeFields,t._serializeFields));var n=ue.base.apply(this,arguments),i=n.prototype,r=i._class;return r&&(i._type=e.hyphenate(r)),n}},_class:"Item",_transformContent:!0,_boundsSelected:!1,_serializeFields:{name:null,matrix:new g,locked:!1,visible:!0,blendMode:"normal",opacity:1,guide:!1,selected:!1,clipMask:!1,data:{}},initialize:function(){},_initialize:function(t,e){if(this._id=y._id=(y._id||0)+1,!this._project){var n=paper.project,i=n.activeLayer;!i||t&&t.insert===!1?this._setProject(n):i.addChild(this)}return this._style=new F(this._project._currentStyle,this),this._matrix=new g,e&&this._matrix.translate(e),t?this._set(t,{insert:!0}):!0},_events:new function(){var t={mousedown:{mousedown:1,mousedrag:1,click:1,doubleclick:1},mouseup:{mouseup:1,mousedrag:1,click:1,doubleclick:1},mousemove:{mousedrag:1,mousemove:1,mouseenter:1,mouseleave:1}},n={install:function(e){var n=this._project.view._eventCounters;if(n)for(var i in t)n[i]=(n[i]||0)+(t[i][e]||0)},uninstall:function(e){var n=this._project.view._eventCounters;if(n)for(var i in t)n[i]-=t[i][e]||0}};return e.each(["onMouseDown","onMouseUp","onMouseDrag","onClick","onDoubleClick","onMouseMove","onMouseEnter","onMouseLeave"],function(t){this[t]=n},{onFrame:{install:function(){this._project.view._animateItem(this,!0)},uninstall:function(){this._project.view._animateItem(this,!1)}},onLoad:{}})},_serialize:function(t,n){function i(i){for(var a in i){var o=s[a];e.equals(o,"leading"===a?1.2*i.fontSize:i[a])||(r[a]=e.serialize(o,t,"data"!==a,n))}}var r={},s=this;return i(this._serializeFields),this instanceof w||i(this._style._defaults),[this._class,r]},_changed:function(t){var e=this._parent,n=this._project,i=this._parentSymbol;if(this._drawCount=null,4&t&&(delete this._bounds,delete this._position),e&&12&t&&e._clearBoundsCache(),2&t&&this._clearBoundsCache(),n&&(1&t&&(n._needsRedraw=!0),n._changes)){var r=n._changesById[this._id];r?r.flags|=t:(r={item:this,flags:t},n._changesById[this._id]=r,n._changes.push(r))}i&&i._changed(t)},set:function(t){return t&&this._set(t),this},getId:function(){return this._id},getType:function(){return this._type},getName:function(){return this._name},setName:function(e,n){if(this._name&&this._removeNamed(),e===+e+"")throw Error("Names consisting only of numbers are not supported.");if(e&&this._parent){for(var i=this._parent._children,r=this._parent._namedChildren,s=e,a=1;n&&i[e];)e=s+" "+a++;(r[e]=r[e]||[]).push(this),i[e]=this}this._name=e||t,this._changed(32)},getStyle:function(){return this._style},setStyle:function(t){this.getStyle().set(t)},hasFill:function(){return this.getStyle().hasFill()},hasStroke:function(){return this.getStyle().hasStroke()},hasShadow:function(){return this.getStyle().hasShadow()}},e.each(["locked","visible","blendMode","opacity","guide"],function(t){var n=e.capitalize(t),t="_"+t;this["get"+n]=function(){return this[t]},this["set"+n]=function(e){e!=this[t]&&(this[t]=e,this._changed("_locked"===t?32:33))}},{}),{_locked:!1,_visible:!0,_blendMode:"normal",_opacity:1,_guide:!1,isSelected:function(){if(this._children)for(var t=0,e=this._children.length;e>t;t++)if(this._children[t].isSelected())return!0;return this._selected},setSelected:function(t){if(this._children&&!arguments[1])for(var e=0,n=this._children.length;n>e;e++)this._children[e].setSelected(t);(t=!!t)!=this._selected&&(this._selected=t,this._project._updateSelection(this),this._changed(33))},_selected:!1,isFullySelected:function(){if(this._children&&this._selected){for(var t=0,e=this._children.length;e>t;t++)if(!this._children[t].isFullySelected())return!1;return!0}return this._selected},setFullySelected:function(t){if(this._children)for(var e=0,n=this._children.length;n>e;e++)this._children[e].setFullySelected(t);this.setSelected(t,!0)},isClipMask:function(){return this._clipMask},setClipMask:function(t){this._clipMask!=(t=!!t)&&(this._clipMask=t,t&&(this.setFillColor(null),this.setStrokeColor(null)),this._changed(33),this._parent&&this._parent._changed(256))},_clipMask:!1,getData:function(){return this._data||(this._data={}),this._data},setData:function(t){this._data=t},getPosition:function(){var t=this._position||(this._position=this.getBounds().getCenter(!0));return new(arguments[0]?h:u)(t.x,t.y,this,"setPosition")},setPosition:function(){this.translate(h.read(arguments).subtract(this.getPosition(!0)))},getMatrix:function(){return this._matrix},setMatrix:function(t){this._matrix.initialize(t),this._changed(5)},getGlobalMatrix:function(){return this._drawCount===this._project._drawCount&&this._globalMatrix||null},globalToLocal:function(){var t=this.getGlobalMatrix();return t&&t._transformPoint(h.read(arguments))},localToGlobal:function(){var t=this.getGlobalMatrix();return t&&t._inverseTransform(h.read(arguments))},isEmpty:function(){return!this._children||0==this._children.length}},e.each(["getBounds","getStrokeBounds","getHandleBounds","getRoughBounds"],function(t){this[t]=function(){var e=this._boundsGetter,n=this._getCachedBounds("string"==typeof e?e:e&&e[t]||t,arguments[0]);return"getBounds"===t?new _(n.x,n.y,n.width,n.height,this,"setBounds"):n}},{_getCachedBounds:function(t,e,n){var i=(!e||e.equals(this._matrix))&&t;if(n&&this._parent){var r=n._id,s=this._parent._boundsCache=this._parent._boundsCache||{ids:{},list:[]};s.ids[r]||(s.list.push(n),s.ids[r]=n)}if(i&&this._bounds&&this._bounds[i])return this._bounds[i].clone();var a=this._matrix.isIdentity();e=!e||e.isIdentity()?a?null:this._matrix:a?e:e.clone().concatenate(this._matrix);var o=this._getBounds(t,e,i?this:n);return i&&(this._bounds||(this._bounds={}),this._bounds[i]=o.clone()),o},_clearBoundsCache:function(){if(this._boundsCache){for(var t=0,e=this._boundsCache.list,n=e.length;n>t;t++){var i=e[t];delete i._bounds,i!=this&&i._boundsCache&&i._clearBoundsCache()}delete this._boundsCache}},_getBounds:function(t,e,n){var i=this._children;if(!i||0==i.length)return new f;for(var r=1/0,s=-r,a=r,o=s,h=0,u=i.length;u>h;h++){var l=i[h];if(l._visible&&!l.isEmpty()){var c=l._getCachedBounds(t,e,n);r=Math.min(c.x,r),a=Math.min(c.y,a),s=Math.max(c.x+c.width,s),o=Math.max(c.y+c.height,o)}}return isFinite(r)?new f(r,a,s-r,o-a):new f},setBounds:function(t){t=f.read(arguments);var e=this.getBounds(),n=new g,i=t.getCenter();n.translate(i),(t.width!=e.width||t.height!=e.height)&&n.scale(0!=e.width?t.width/e.width:1,0!=e.height?t.height/e.height:1),i=e.getCenter(),n.translate(-i.x,-i.y),this.transform(n)}}),{getProject:function(){return this._project},_setProject:function(t){if(this._project!=t&&(this._project=t,this._children))for(var e=0,n=this._children.length;n>e;e++)this._children[e]._setProject(t)},getLayer:function(){for(var t=this;t=t._parent;)if(t instanceof x)return t;return null},getParent:function(){return this._parent},setParent:function(t){return t.addChild(this)},getChildren:function(){return this._children},setChildren:function(t){this.removeChildren(),this.addChildren(t)},getFirstChild:function(){return this._children&&this._children[0]||null},getLastChild:function(){return this._children&&this._children[this._children.length-1]||null},getNextSibling:function(){return this._parent&&this._parent._children[this._index+1]||null},getPreviousSibling:function(){return this._parent&&this._parent._children[this._index-1]||null},getIndex:function(){return this._index},isInserted:function(){return this._parent?this._parent.isInserted():!1},equals:function(t){return t===this||t&&this._class===t._class&&this._style.equals(t._style)&&this._matrix.equals(t._matrix)&&this._locked===t._locked&&this._visible===t._visible&&this._blendMode===t._blendMode&&this._opacity===t._opacity&&this._clipMask===t._clipMask&&this._guide===t._guide&&this._equals(t)||!1},_equals:function(t){return e.equals(this._children,t._children)},clone:function(t){return this._clone(new this.constructor({insert:!1}),t)},_clone:function(e,n){if(e.setStyle(this._style),this._children)for(var i=0,r=this._children.length;r>i;i++)e.addChild(this._children[i].clone(!1),!0);(n||n===t)&&e.insertAbove(this);for(var s=["_locked","_visible","_blendMode","_opacity","_clipMask","_guide"],i=0,r=s.length;r>i;i++){var a=s[i];this.hasOwnProperty(a)&&(e[a]=this[a])}return e._matrix.initialize(this._matrix),e.setSelected(this._selected),this._name&&e.setName(this._name,!0),e},copyTo:function(t){var e=this.clone();return t.layers?t.activeLayer.addChild(e):t.addChild(e),e},rasterize:function(t){var n=this.getStrokeBounds(),i=(t||72)/72,r=n.getTopLeft().floor(),s=n.getBottomRight().ceil();size=new c(s.subtract(r)),canvas=Q.getCanvas(size),ctx=canvas.getContext("2d"),matrix=(new g).scale(i).translate(r.negate()),ctx.save(),matrix.applyToContext(ctx),this.draw(ctx,e.merge({transforms:[matrix]})),ctx.restore();var a=new C({canvas:canvas,insert:!1});return a.setPosition(r.add(size.divide(2))),a.insertAbove(this),a},contains:function(){return!!this._contains(this._matrix._inverseTransform(h.read(arguments)))},_contains:function(t){if(this._children){for(var e=this._children.length-1;e>=0;e--)if(this._children[e].contains(t))return!0;return!1}return t.isInside(this._getBounds("getBounds"))},hitTest:function(n,i){function r(r,s){var h=o["get"+s]();return n.getDistance(h)l&&!s;l++)s=r("bounds",u[l])}return(s||(s=this._children||!(i.guides&&!this._guide||i.selected&&!this._selected)?this._hitTest(n,i):null))&&s.point&&(s.point=a._matrix.transform(s.point)),s},_hitTest:function(t,e){var n=this._children;if(n){for(var i,r=n.length-1;r>=0;r--)if(i=n[r].hitTest(t,e))return i}else if(e.fill&&this.hasFill()&&this._contains(t))return new P("fill",this)},matches:function(t){function n(t,i){for(var r in t)if(t.hasOwnProperty(r)){var s=t[r],a=i[r];if(e.isPlainObject(s)&&e.isPlainObject(a)){if(!n(s,a))return!1}else if(!e.equals(s,a))return!1}return!0}for(var i in t)if(t.hasOwnProperty(i)){var r=this[i],s=t[i];if(s instanceof RegExp){if(!s.test(r))return!1}else if("function"==typeof s){if(!s(r))return!1}else if(e.isPlainObject(s)){if(!n(s,r))return!1}else if(!e.equals(r,s))return!1}return!0}},new function(){function t(e,n,i){for(var r=e._children,s=i&&[],a=0,o=r&&r.length;o>a;a++){var h=r[a];if(h.matches(n)){if(!i)return h;s.push(h)}var u=t(h,n,i);if(i)s.push.apply(s,u);else if(u)return u}return i?s:null}return{getItems:function(e){return t(this,e,!0)},getItem:function(e){return t(this,e,!1)}}},{importJSON:function(t){var n=e.importJSON(t,this);return n!==this?this.addChild(n):n},addChild:function(e,n){return this.insertChild(t,e,n)},insertChild:function(t,e,n){var i=this.insertChildren(t,[e],n);return i&&i[0]},addChildren:function(t,e){return this.insertChildren(this._children.length,t,e)},insertChildren:function(t,n,i,r){var s=this._children;if(s&&n&&n.length>0){n=Array.prototype.slice.apply(n);for(var a=n.length-1;a>=0;a--){var o=n[a];r&&o._type!==r?n.splice(a,1):o._remove(!0)}e.splice(s,n,t,0);for(var a=0,h=n.length;h>a;a++){var o=n[a];o._parent=this,o._setProject(this._project),o._name&&o.setName(o._name)}this._changed(7)}else n=null;return n},_insert:function(t,e,n){if(!e._parent)return null;var i=e._index+(t?1:0);return e._parent===this._parent&&i>this._index&&i--,e._parent.insertChild(i,this,n)},insertAbove:function(t,e){return this._insert(!0,t,e)},insertBelow:function(t,e){return this._insert(!1,t,e)},sendToBack:function(){return this._parent.insertChild(0,this)},bringToFront:function(){return this._parent.addChild(this)},appendTop:"#addChild",appendBottom:function(t){return this.insertChild(0,t)},moveAbove:"#insertAbove",moveBelow:"#insertBelow",reduce:function(){if(this._children&&1===this._children.length){var t=this._children[0];return t.insertAbove(this),this.remove(),t}return this},_removeNamed:function(){var t=this._parent._children,e=this._parent._namedChildren,n=this._name,i=e[n],r=i?i.indexOf(this):-1;-1!=r&&(t[n]==this&&delete t[n],i.splice(r,1),i.length?t[n]=i[i.length-1]:delete e[n])},_remove:function(t){return this._parent?(this._name&&this._removeNamed(),null!=this._index&&e.splice(this._parent._children,null,this._index,1),t&&this._parent._changed(7),this._parent=null,!0):!1},remove:function(){return this._remove(!0)},removeChildren:function(t,n){if(!this._children)return null;t=t||0,n=e.pick(n,this._children.length);for(var i=e.splice(this._children,null,t,n-t),r=i.length-1;r>=0;r--)i[r]._remove(!1);return i.length>0&&this._changed(7),i},clear:"#removeChildren",reverseChildren:function(){if(this._children){this._children.reverse();for(var t=0,e=this._children.length;e>t;t++)this._children[t]._index=t;this._changed(7)}},isEditable:function(){for(var t=this;t;){if(!t._visible||t._locked)return!1;t=t._parent}return!0},_getOrder:function(t){function e(t){var e=[];do e.unshift(t);while(t=t._parent);return e}for(var n=e(this),i=e(t),r=0,s=Math.min(n.length,i.length);s>r;r++)if(n[r]!=i[r])return n[r]._index0},isAbove:function(t){return-1===this._getOrder(t)},isBelow:function(t){return 1===this._getOrder(t)},isParent:function(t){return this._parent===t},isChild:function(t){return t&&t._parent===this},isDescendant:function(t){for(var e=this;e=e._parent;)if(e==t)return!0;return!1},isAncestor:function(t){return t?t.isDescendant(this):!1},isGroupedWith:function(t){for(var e=this._parent;e;){if(e._parent&&/^(group|layer|compound-path)$/.test(e._type)&&t.isDescendant(e))return!0;e=e._parent}return!1},scale:function(t,e,n){return(arguments.length<2||"object"==typeof e)&&(n=e,e=t),this.transform((new g).scale(t,e,n||this.getPosition(!0)))},translate:function(){var t=new g;return this.transform(t.translate.apply(t,arguments))},rotate:function(t,e){return this.transform((new g).rotate(t,e||this.getPosition(!0)))},shear:function(t,e,n){return(arguments.length<2||"object"==typeof e)&&(n=e,e=t),this.transform((new g).shear(t,e,n||this.getPosition(!0)))},transform:function(t){var e=this._bounds,n=this._position;if(this._matrix.preConcatenate(t),(this._transformContent||arguments[1])&&this.applyMatrix(!0),this._changed(5),e&&0===t.getRotation()%90){for(var i in e){var r=e[i];t._transformBounds(r,r)}var s=this._boundsGetter,r=e[s&&s.getBounds||s||"getBounds"];r&&(this._position=r.getCenter(!0)),this._bounds=e}else n&&(this._position=t._transformPoint(n,n));return this},_applyMatrix:function(t,e){var n=this._children;if(n&&n.length>0){for(var i=0,r=n.length;r>i;i++)n[i].transform(t,e);return!0}},applyMatrix:function(t){var e=this._matrix;if(this._applyMatrix(e,!0)){var n=this._style,i=n.getFillColor(!0),r=n.getStrokeColor(!0);i&&i.transform(e),r&&r.transform(e),e.reset()}t||this._changed(5)},fitBounds:function(t,e){t=f.read(arguments);var n=this.getBounds(),i=n.height/n.width,r=t.height/t.width,s=(e?i>r:r>i)?t.width/n.width:t.height/n.height,a=new f(new h,new c(n.width*s,n.height*s));a.setCenter(t.getCenter()),this.setBounds(a)},_setStyles:function(t){var e=this._style,n=e.getFillColor(),i=e.getStrokeColor(),r=e.getShadowColor();if(n&&(t.fillStyle=n.toCanvasStyle(t)),i){var s=e.getStrokeWidth();if(s>0){t.strokeStyle=i.toCanvasStyle(t),t.lineWidth=s;var a=e.getStrokeJoin(),o=e.getStrokeCap(),h=e.getMiterLimit();if(a&&(t.lineJoin=a),o&&(t.lineCap=o),h&&(t.miterLimit=h),paper.support.nativeDash){var u=e.getDashArray(),l=e.getDashOffset();u&&u.length&&("setLineDash"in t?(t.setLineDash(u),t.lineDashOffset=l):(t.mozDash=u,t.mozDashOffset=l))}}}if(r){var c=e.getShadowBlur();if(c>0){t.shadowColor=r.toCanvasStyle(t),t.shadowBlur=c;var d=this.getShadowOffset();t.shadowOffsetX=d.x,t.shadowOffsetY=d.y}}},draw:function(t,e){if(this._visible&&0!==this._opacity){this._drawCount=this._project._drawCount;var n=e.trackTransforms,i=e.transforms,r=i[i.length-1],s=r.clone().concatenate(this._matrix);n&&i.push(this._globalMatrix=s);var a,o,h,u=this._blendMode,l=this._opacity,d="normal"===u,f=te.nativeModes[u],_=d&&1===l||(f||d&&1>l)&&this._canComposite();if(!_){var g=this.getStrokeBounds(r);if(!g.width||!g.height)return;h=e.offset,o=e.offset=g.getTopLeft().floor(),a=t,t=Q.getContext(g.getSize().ceil().add(new c(1,1)))}t.save(),_?(t.globalAlpha=l,f&&(t.globalCompositeOperation=u)):t.translate(-o.x,-o.y),(_?this._matrix:s).applyToContext(t),!_&&e.clipItem&&e.clipItem.draw(t,e.extend({clip:!0})),this._draw(t,e),t.restore(),n&&i.pop(),e.clip&&t.clip(),_||(te.process(u,t,a,l,o.subtract(h)),Q.release(t),e.offset=h)}},_canComposite:function(){return!1}},e.each(["down","drag","up","move"],function(t){this["removeOn"+e.capitalize(t)]=function(){var e={};return e[t]=!0,this.removeOn(e)}},{removeOn:function(t){for(var e in t)if(t[e]){var n="mouse"+e,i=this._project,r=i._removeSets=i._removeSets||{};r[n]=r[n]||{},r[n][this._id]=this}return this}})),w=y.extend({_class:"Group",_serializeFields:{children:[]},initialize:function(t){this._children=[],this._namedChildren={},this._initialize(t)||this.addChildren(Array.isArray(t)?t:arguments)},_changed:function le(t){le.base.call(this,t),2&t&&this._transformContent&&!this._matrix.isIdentity()&&this.applyMatrix(),258&t&&delete this._clipItem},_getClipItem:function(){if(this._clipItem!==t)return this._clipItem;for(var e=0,n=this._children.length;n>e;e++){var i=this._children[e];if(i._clipMask)return this._clipItem=i}return this._clipItem=null},getTransformContent:function(){return this._transformContent},setTransformContent:function(t){this._transformContent=t,t&&this.applyMatrix()},isClipped:function(){return!!this._getClipItem()},setClipped:function(t){var e=this.getFirstChild();e&&e.setClipMask(t)},_draw:function(t,e){var n=e.clipItem=this._getClipItem();n&&n.draw(t,e.extend({clip:!0}));for(var i=0,r=this._children.length;r>i;i++){var s=this._children[i];s!==n&&s.draw(t,e)}e.clipItem=null}}),x=w.extend({_class:"Layer",initialize:function(){this._project=paper.project,this._index=this._project.layers.push(this)-1,w.apply(this,arguments),this.activate()},_remove:function ce(t){return this._parent?ce.base.call(this,t):null!=this._index?(this._project.activeLayer===this&&(this._project.activeLayer=this.getNextSibling()||this.getPreviousSibling()),e.splice(this._project.layers,null,this._index,1),this._project._needsRedraw=!0,!0):!1},getNextSibling:function de(){return this._parent?de.base.call(this):this._project.layers[this._index+1]||null},getPreviousSibling:function fe(){return this._parent?fe.base.call(this):this._project.layers[this._index-1]||null},isInserted:function _e(){return this._parent?_e.base.call(this):null!=this._index},activate:function(){this._project.activeLayer=this},_insert:function ge(t,n,i){return n instanceof x&&!n._parent&&this._remove(!0)?(e.splice(n._project.layers,[this],n._index+(t?1:0),0),this._setProject(n._project),this):ge.base.call(this,t,n,i)}}),b=y.extend({_class:"Shape",_transformContent:!1,_boundsSelected:!0,initialize:function(t,e,n,i,r){this._shape=t,this._size=n,this._radius=i,this._initialize(r,e)},_equals:function(t){return this._shape===t._shape&&this._size.equals(t._size)&&e.equals(this._radius,t._radius)},clone:function(t){return this._clone(new b(this._shape,this.getPosition(!0),this._size.clone(),this._radius.clone?this._radius.clone():this._radius,{insert:!1}),t)},getShape:function(){return this._shape},getSize:function(){var t=this._size;return new d(t.width,t.height,this,"setSize")},setSize:function(){var t=this._shape,e=c.read(arguments);if(!this._size.equals(e)){var n=e.width,i=e.height;if("rectangle"===t){var r=c.min(this._radius,e.divide(2));this._radius.set(r.width,r.height)}else"circle"===t?(n=i=(n+i)/2,this._radius=n/2):"ellipse"===t&&this._radius.set(n/2,i/2);this._size.set(n,i),this._changed(5)}},getRadius:function(){var t=this._radius;return"circle"===this._shape?t:new d(t.width,t.height,this,"setRadius")},setRadius:function(t){var e=this._shape;if("circle"===e){if(t===this._radius)return;var n=2*t;this._size.set(n,n)}else{if(t=c.read(arguments),this._radius.equals(t))return;if(this._radius.set(t.width,t.height),"rectangle"===e){var n=c.max(this._size,t.multiply(2));this._size.set(n.width,n.height)}else"ellipse"===e&&this._size.set(2*t.width,2*t.height)}this._changed(5)},isEmpty:function(){return!1},toPath:function(n){var i=new(O[e.capitalize(this._shape)])({center:new h,size:this._size,radius:this._radius,insert:!1});return i.setStyle(this._style),i.transform(this._matrix),(n||n===t)&&i.insertAbove(this),i},_draw:function(t,e){var n=this._style,i=n.hasFill(),r=n.hasStroke(),s=e.clip;if(i||r||s){var a=this._radius,h=this._shape;if(t.beginPath(),"circle"===h)t.arc(0,0,a,0,2*Math.PI,!0);else{var u=a.width,l=a.height,c=o.KAPPA;if("ellipse"===h){var d=u*c,f=l*c;t.moveTo(-u,0),t.bezierCurveTo(-u,-f,-d,-l,0,-l),t.bezierCurveTo(d,-l,u,-f,u,0),t.bezierCurveTo(u,f,d,l,0,l),t.bezierCurveTo(-d,l,-u,f,-u,0)}else{var _=this._size,g=_.width,p=_.height;if(0===u&&0===l)t.rect(-g/2,-p/2,g,p);else{c=1-c;var v=g/2,m=p/2,d=u*c,f=l*c;t.moveTo(-v,-m+l),t.bezierCurveTo(-v,-m+f,-v+d,-m,-v+u,-m),t.lineTo(v-u,-m),t.bezierCurveTo(v-d,-m,v,-m+f,v,-m+l),t.lineTo(v,m-l),t.bezierCurveTo(v,m-f,v-d,m,v-u,m),t.lineTo(-v+u,m),t.bezierCurveTo(-v+d,m,-v,m-f,-v,m-l)}}}t.closePath()}s||!i&&!r||(this._setStyles(t),i&&(t.fill(n.getWindingRule()),t.shadowColor="rgba(0,0,0,0)"),r&&t.stroke())},_canComposite:function(){return!(this.hasFill()&&this.hasStroke())},_getBounds:function(t,e){var n=new f(this._size).setCenter(0,0);return"getBounds"!==t&&this.hasStroke()&&(n=n.expand(this.getStrokeWidth())),e?e._transformBounds(n):n}},new function(){function t(t,e,n){var i=t._radius;if(!i.isZero())for(var r=t._size.divide(2),s=0;4>s;s++){var a=new h(1&s?1:-1,s>1?1:-1),o=a.multiply(r),u=o.subtract(a.multiply(i)),l=new f(o,u);if((n?l.expand(n):l).contains(e))return u}}function e(t,e){var n=t.getAngleInRadians(),i=2*e.width,r=2*e.height,s=i*Math.sin(n),a=r*Math.cos(n);return i*r/(2*Math.sqrt(s*s+a*a))}return{_contains:function n(e){if("rectangle"===this._shape){var i=t(this,e);return i?e.subtract(i).divide(this._radius).getLength()<=1:n.base.call(this,e)}return e.divide(this.size).getLength()<=.5},_hitTest:function i(n,r){var s=!1;if(this.hasStroke()){var a=this._shape,o=this._radius,h=this.getStrokeWidth()+2*r.tolerance;if("rectangle"===a){var u=t(this,n,h);if(u){var l=n.subtract(u);s=2*Math.abs(l.getLength()-e(l,o))<=h}else{var c=new f(this._size).setCenter(0,0),d=c.expand(h),_=c.expand(-h);s=d._containsPoint(n)&&!_._containsPoint(n)}}else"ellipse"===a&&(o=e(n,o)),s=2*Math.abs(n.getLength()-o)<=h}return s?new P("stroke",this):i.base.apply(this,arguments)}}},{statics:new function(){function t(t,n,i,r,s){return new b(t,n,i,r,e.getNamed(s))}return{Circle:function(){var n=h.readNamed(arguments,"center"),i=e.readNamed(arguments,"radius");return t("circle",n,new c(2*i),i,arguments)},Rectangle:function(){var e=f.readNamed(arguments,"rectangle"),n=c.min(c.readNamed(arguments,"radius"),e.getSize(!0).divide(2));return t("rectangle",e.getCenter(!0),e.getSize(!0),n,arguments)},Ellipse:function(){var e=b._readEllipse(arguments);return radius=e.radius,t("ellipse",e.center,radius.multiply(2),radius,arguments)},_readEllipse:function(t){var n,i;if(e.hasNamed(t,"radius"))n=h.readNamed(t,"center"),i=c.readNamed(t,"radius");else{var r=f.readNamed(t,"rectangle");n=r.getCenter(!0),i=r.getSize(!0).divide(2)}return{center:n,radius:i}}}}}),C=y.extend({_class:"Raster",_transformContent:!1,_boundsGetter:"getBounds",_boundsSelected:!0,_serializeFields:{source:null},initialize:function(e,n){this._initialize(e,n!==t&&h.read(arguments,1))||("string"==typeof e?this.setSource(e):this.setImage(e)),this._size||(this._size=new c)},_equals:function(t){return this.getSource()===t.getSource()},clone:function(t){var e={insert:!1},n=this._image;if(n)e.image=n;else if(this._canvas){var i=e.canvas=Q.getCanvas(this._size);i.getContext("2d").drawImage(this._canvas,0,0)}return this._clone(new C(e),t)},getSize:function(){var t=this._size;return new d(t.width,t.height,this,"setSize")},setSize:function(){var t=c.read(arguments);if(!this._size.equals(t)){var e=this.getElement();this.setCanvas(Q.getCanvas(t)),e&&this.getContext(!0).drawImage(e,0,0,t.width,t.height)}},getWidth:function(){return this._size.width},getHeight:function(){return this._size.height},isEmpty:function(){return 0==this._size.width&&0==this._size.height},getPpi:function(){var t=this._matrix,e=new h(0,0).transform(t),n=new h(1,0).transform(t).subtract(e),i=new h(0,1).transform(t).subtract(e);return new c(72/n.getLength(),72/i.getLength())},getImage:function(){return this._image},setImage:function(t){this._canvas&&Q.release(this._canvas),t.getContext?(this._image=null,this._canvas=t):(this._image=t,this._canvas=null),this._size=new c(t.naturalWidth||t.width,t.naturalHeight||t.height),this._context=null,this._changed(133)},getCanvas:function(){if(!this._canvas){var t=Q.getContext(this._size);try{this._image&&t.drawImage(this._image,0,0),this._canvas=t.canvas}catch(e){Q.release(t)}}return this._canvas},setCanvas:"#setImage",getContext:function(){return this._context||(this._context=this.getCanvas().getContext("2d")),arguments[0]&&(this._image=null,this._changed(129)),this._context},setContext:function(t){this._context=t},getSource:function(){return this._image&&this._image.src||this.toDataURL()},setSource:function(t){function e(){var t=n._project.view;t&&(paper=t._scope),n.fire("load"),t&&t.draw(!0)}var n=this,i=document.getElementById(t)||new Image;i.naturalWidth&&i.naturalHeight?setTimeout(e,0):(V.add(i,{load:function(){n.setImage(i),e()}}),i.src||(i.src=t)),this.setImage(i)},getElement:function(){return this._canvas||this._image},getSubCanvas:function(t){t=f.read(arguments);var e=Q.getContext(t.getSize());return e.drawImage(this.getCanvas(),t.x,t.y,t.width,t.height,0,0,t.width,t.height),e.canvas},getSubRaster:function(t){t=f.read(arguments);var e=new C({canvas:this.getSubCanvas(t),insert:!1});return e.translate(t.getCenter().subtract(this.getSize().divide(2))),e._matrix.preConcatenate(this._matrix),e.insertAbove(this),e},toDataURL:function(){var t=this._image&&this._image.src; +if(/^data:/.test(t))return t;var e=this.getCanvas();return e?e.toDataURL():null},drawImage:function(t,e){e=h.read(arguments,1),this.getContext(!0).drawImage(t,e.x,e.y)},getAverageColor:function(t){var n,i;t?t instanceof A?(i=t,n=t.getBounds()):t.width?n=new f(t):t.x&&(n=new f(t.x-.5,t.y-.5,1,1)):n=this.getBounds();var r=32,s=Math.min(n.width,r),a=Math.min(n.height,r),o=C._sampleContext;o?o.clearRect(0,0,r+1,r+1):o=C._sampleContext=Q.getContext(new c(r)),o.save();var h=(new g).scale(s/n.width,a/n.height).translate(-n.x,-n.y);h.applyToContext(o),i&&i.draw(o,e.merge({clip:!0,transforms:[h]})),this._matrix.applyToContext(o),o.drawImage(this.getElement(),-this._size.width/2,-this._size.height/2),o.restore();for(var u=o.getImageData(.5,.5,Math.ceil(s),Math.ceil(a)).data,l=[0,0,0],d=0,_=0,p=u.length;p>_;_+=4){var v=u[_+3];d+=v,v/=255,l[0]+=u[_]*v,l[1]+=u[_+1]*v,l[2]+=u[_+2]*v}for(var _=0;3>_;_++)l[_]/=d;return d?B.read(l):null},getPixel:function(t){t=h.read(arguments);var e=this.getContext().getImageData(t.x,t.y,1,1).data;return new B("rgb",[e[0]/255,e[1]/255,e[2]/255],e[3]/255)},setPixel:function(){var t=h.read(arguments),e=B.read(arguments),n=e._convert("rgb"),i=e._alpha,r=this.getContext(!0),s=r.createImageData(1,1),a=s.data;a[0]=255*n[0],a[1]=255*n[1],a[2]=255*n[2],a[3]=null!=i?255*i:255,r.putImageData(s,t.x,t.y)},createImageData:function(t){return t=c.read(arguments),this.getContext().createImageData(t.width,t.height)},getImageData:function(t){return t=f.read(arguments),t.isEmpty()&&(t=new f(this._size)),this.getContext().getImageData(t.x,t.y,t.width,t.height)},setImageData:function(t,e){e=h.read(arguments,1),this.getContext(!0).putImageData(t,e.x,e.y)},_getBounds:function(t,e){var n=new f(this._size).setCenter(0,0);return e?e._transformBounds(n):n},_hitTest:function(t){if(this._contains(t)){var e=this;return new P("pixel",e,{offset:t.add(e._size.divide(2)).round(),color:{get:function(){return e.getPixel(this.offset)}}})}},_draw:function(t){var e=this.getElement();e&&(t.globalAlpha=this._opacity,t.drawImage(e,-this._size.width/2,-this._size.height/2))},_canComposite:function(){return!0}}),S=y.extend({_class:"PlacedSymbol",_transformContent:!1,_boundsGetter:{getBounds:"getStrokeBounds"},_boundsSelected:!0,_serializeFields:{symbol:null},initialize:function(e,n){this._initialize(e,n!==t&&h.read(arguments,1))||this.setSymbol(e instanceof m?e:new m(e))},_equals:function(t){return this._symbol===t._symbol},getSymbol:function(){return this._symbol},setSymbol:function(t){this._symbol&&delete this._symbol._instances[this._id],this._symbol=t,t._instances[this._id]=this},clone:function(t){return this._clone(new S({symbol:this.symbol,insert:!1}),t)},isEmpty:function(){return this._symbol._definition.isEmpty()},_getBounds:function(t,e){return this.symbol._definition._getCachedBounds(t,e)},_hitTest:function(t,e,n){var i=this._symbol._definition._hitTest(t,e,n);return i&&(i.item=this),i},_draw:function(t,e){this.symbol._definition.draw(t,e)}}),P=e.extend({_class:"HitResult",initialize:function(t,e,n){this.type=t,this.item=e,n&&(n.enumerable=!0,this.inject(n))},statics:{getOptions:function(t){return t&&t._merged?t:e.merge({type:null,tolerance:paper.project.options.hitTolerance||2,fill:!t,stroke:!t,segments:!t,handles:!1,ends:!1,center:!1,bounds:!1,guides:!1,selected:!1,_merged:!0},t)}}}),k=e.extend({_class:"Segment",initialize:function(e,n,i,r,s,a){var o,h,u,l=arguments.length;0===l||(1===l?e.point?(o=e.point,h=e.handleIn,u=e.handleOut):o=e:2===l&&"number"==typeof e?o=arguments:3>=l?(o=e,h=n,u=i):(o=e!==t?[e,n]:null,h=i!==t?[i,r]:null,u=s!==t?[s,a]:null)),new z(o,this,"_point"),new z(h,this,"_handleIn"),new z(u,this,"_handleOut")},_serialize:function(t){return e.serialize(this.isLinear()?this._point:[this._point,this._handleIn,this._handleOut],t,!0)},_changed:function(t){if(this._path){var e,n=this._path._curves&&this.getCurve();n&&(n._changed(),(e=n[t==this._point||t==this._handleIn&&n._segment1==this?"getPrevious":"getNext"]())&&e._changed()),this._path._changed(5)}},getPoint:function(){return this._point},setPoint:function(t){t=h.read(arguments),this._point.set(t.x,t.y)},getHandleIn:function(){return this._handleIn},setHandleIn:function(t){t=h.read(arguments),this._handleIn.set(t.x,t.y)},getHandleOut:function(){return this._handleOut},setHandleOut:function(t){t=h.read(arguments),this._handleOut.set(t.x,t.y)},isLinear:function(){return this._handleIn.isZero()&&this._handleOut.isZero()},setLinear:function(){this._handleIn.set(0,0),this._handleOut.set(0,0)},isColinear:function(t){var e=this.getNext(),n=t.getNext();return this._handleOut.isZero()&&e._handleIn.isZero()&&t._handleOut.isZero()&&n._handleIn.isZero()&&e._point.subtract(this._point).isColinear(n._point.subtract(t._point))},isOrthogonal:function(){var t=this.getPrevious(),e=this.getNext();return t._handleOut.isZero()&&this._handleIn.isZero()&&this._handleOut.isZero()&&e._handleIn.isZero()&&this._point.subtract(t._point).isOrthogonal(e._point.subtract(this._point))},isArc:function(){var t=this.getNext(),e=this._handleOut,n=t._handleIn,i=o.KAPPA;if(e.isOrthogonal(n)){var r=this._point,s=t._point,a=new p(r,e,!0).intersect(new p(s,n,!0),!0);return a&&o.isZero(e.getLength()/a.subtract(r).getLength()-i)&&o.isZero(n.getLength()/a.subtract(s).getLength()-i)}return!1},_isSelected:function(t){var e=this._selectionState;return t==this._point?!!(4&e):t==this._handleIn?!!(1&e):t==this._handleOut?!!(2&e):!1},_setSelected:function(t,e){var n=this._path,e=!!e,i=this._selectionState||0,r=[!!(4&i),!!(1&i),!!(2&i)];if(t===this._point){if(e)r[1]=r[2]=!1;else{var s=this.getPrevious(),a=this.getNext();r[1]=s&&(s._point.isSelected()||s._handleOut.isSelected()),r[2]=a&&(a._point.isSelected()||a._handleIn.isSelected())}r[0]=e}else{var o=t===this._handleIn?1:2;r[o]!=e&&(e&&(r[0]=!1),r[o]=e)}this._selectionState=(r[0]?4:0)|(r[1]?1:0)|(r[2]?2:0),n&&i!=this._selectionState&&(n._updateSelection(this,i,this._selectionState),n._changed(33))},isSelected:function(){return this._isSelected(this._point)},setSelected:function(t){this._setSelected(this._point,t)},getIndex:function(){return this._index!==t?this._index:null},getPath:function(){return this._path||null},getCurve:function(){var t=this._path,e=this._index;return t?(t._closed||e!=t._segments.length-1||e--,t.getCurves()[e]||null):null},getLocation:function(){var t=this.getCurve();return t?new I(t,t.getNext()?0:1):null},getNext:function(){var t=this._path&&this._path._segments;return t&&(t[this._index+1]||this._path._closed&&t[0])||null},getPrevious:function(){var t=this._path&&this._path._segments;return t&&(t[this._index-1]||this._path._closed&&t[t.length-1])||null},reverse:function(){return new k(this._point,this._handleOut,this._handleIn)},remove:function(){return this._path?!!this._path.removeSegment(this._index):!1},clone:function(){return new k(this._point,this._handleIn,this._handleOut)},equals:function(t){return t===this||t&&this._class===t._class&&this._point.equals(t._point)&&this._handleIn.equals(t._handleIn)&&this._handleOut.equals(t._handleOut)||!1},toString:function(){var t=["point: "+this._point];return this._handleIn.isZero()||t.push("handleIn: "+this._handleIn),this._handleOut.isZero()||t.push("handleOut: "+this._handleOut),"{ "+t.join(", ")+" }"},_transformCoordinates:function(t,e,n){var i=this._point,r=n&&this._handleIn.isZero()?null:this._handleIn,s=n&&this._handleOut.isZero()?null:this._handleOut,a=i._x,o=i._y,h=2;return e[0]=a,e[1]=o,r&&(e[h++]=r._x+a,e[h++]=r._y+o),s&&(e[h++]=s._x+a,e[h++]=s._y+o),t&&(t._transformCoordinates(e,0,e,0,h/2),a=e[0],o=e[1],n?(i._x=a,i._y=o,h=2,r&&(r._x=e[h++]-a,r._y=e[h++]-o),s&&(s._x=e[h++]-a,s._y=e[h++]-o)):(r||(e[h++]=a,e[h++]=o),s||(e[h++]=a,e[h++]=o))),e}}),z=h.extend({initialize:function(e,n,i){var r,s,a;e?(r=e[0])!==t?s=e[1]:((r=e.x)===t&&(e=h.read(arguments),r=e.x),s=e.y,a=e.selected):r=s=0,this._x=r,this._y=s,this._owner=n,n[i]=this,a&&this.setSelected(!0)},set:function(t,e){return this._x=t,this._y=e,this._owner._changed(this),this},_serialize:function(t){var e=t.formatter,n=e.number(this._x),i=e.number(this._y);return this.isSelected()?{x:n,y:i,selected:!0}:[n,i]},getX:function(){return this._x},setX:function(t){this._x=t,this._owner._changed(this)},getY:function(){return this._y},setY:function(t){this._y=t,this._owner._changed(this)},isZero:function(){return o.isZero(this._x)&&o.isZero(this._y)},setSelected:function(t){this._owner._setSelected(this,t)},isSelected:function(){return this._owner._isSelected(this)}}),M=e.extend({_class:"Curve",initialize:function(t,e,n,i,r,s,a,o){var h=arguments.length;if(3===h)this._path=t,this._segment1=e,this._segment2=n;else if(0===h)this._segment1=new k,this._segment2=new k;else if(1===h)this._segment1=new k(t.segment1),this._segment2=new k(t.segment2);else if(2===h)this._segment1=new k(t),this._segment2=new k(e);else{var u,l,c,d;4===h?(u=t,l=e,c=n,d=i):8===h&&(u=[t,e],d=[a,o],l=[n-t,i-e],c=[r-a,s-o]),this._segment1=new k(u,null,l),this._segment2=new k(d,c,null)}},_changed:function(){delete this._length,delete this._bounds},getPoint1:function(){return this._segment1._point},setPoint1:function(t){t=h.read(arguments),this._segment1._point.set(t.x,t.y)},getPoint2:function(){return this._segment2._point},setPoint2:function(t){t=h.read(arguments),this._segment2._point.set(t.x,t.y)},getHandle1:function(){return this._segment1._handleOut},setHandle1:function(t){t=h.read(arguments),this._segment1._handleOut.set(t.x,t.y)},getHandle2:function(){return this._segment2._handleIn},setHandle2:function(t){t=h.read(arguments),this._segment2._handleIn.set(t.x,t.y)},getSegment1:function(){return this._segment1},getSegment2:function(){return this._segment2},getPath:function(){return this._path},getIndex:function(){return this._segment1._index},getNext:function(){var t=this._path&&this._path._curves;return t&&(t[this._segment1._index+1]||this._path._closed&&t[0])||null},getPrevious:function(){var t=this._path&&this._path._curves;return t&&(t[this._segment1._index-1]||this._path._closed&&t[t.length-1])||null},isSelected:function(){return this.getHandle1().isSelected()&&this.getHandle2().isSelected()},setSelected:function(t){this.getHandle1().setSelected(t),this.getHandle2().setSelected(t)},getValues:function(){return M.getValues(this._segment1,this._segment2)},getPoints:function(){for(var t=this.getValues(),e=[],n=0;8>n;n+=2)e.push(new h(t[n],t[n+1]));return e},getLength:function(){var t=arguments[0],e=arguments[1],n=0===arguments.length||0===t&&1===e;if(n&&null!=this._length)return this._length;var i=M.getLength(this.getValues(),t,e);return n&&(this._length=i),i},getArea:function(){return M.getArea(this.getValues())},getPart:function(t,e){return new M(M.getPart(this.getValues(),t,e))},isLinear:function(){return this._segment1._handleOut.isZero()&&this._segment2._handleIn.isZero()},getIntersections:function(t){return M.getIntersections(this.getValues(),t.getValues(),this,t,[])},reverse:function(){return new M(this._segment2.reverse(),this._segment1.reverse())},_getParameter:function(e,n){return n?e:e&&e.curve===this?e.parameter:e===t&&n===t?.5:this.getParameterAt(e,0)},divide:function(t,e){var n=this._getParameter(t,e),i=null;if(n>0&&1>n){var r=M.subdivide(this.getValues(),n),s=this.isLinear(),a=r[0],o=r[1];s||(this._segment1._handleOut.set(a[2]-a[0],a[3]-a[1]),this._segment2._handleIn.set(o[4]-o[6],o[5]-o[7]));var u=a[6],l=a[7],c=new k(new h(u,l),!s&&new h(a[4]-u,a[5]-l),!s&&new h(o[2]-u,o[3]-l));if(this._path)this._segment1._index>0&&0===this._segment2._index?this._path.add(c):this._path.insert(this._segment2._index,c),i=this;else{var d=this._segment2;this._segment2=c,i=new M(c,d)}}return i},split:function(t,e){return this._path?this._path.split(this._segment1._index,this._getParameter(t,e)):null},clone:function(){return new M(this._segment1,this._segment2)},toString:function(){var t=["point1: "+this._segment1._point];return this._segment1._handleOut.isZero()||t.push("handle1: "+this._segment1._handleOut),this._segment2._handleIn.isZero()||t.push("handle2: "+this._segment2._handleIn),t.push("point2: "+this._segment2._point),"{ "+t.join(", ")+" }"},statics:{getValues:function(t,e){var n=t._point,i=t._handleOut,r=e._handleIn,s=e._point;return[n._x,n._y,n._x+i._x,n._y+i._y,s._x+r._x,s._y+r._y,s._x,s._y]},evaluate:function(t,e,n){var i,r,s=t[0],a=t[1],o=t[2],u=t[3],l=t[4],c=t[5],d=t[6],f=t[7];if(0!==n||0!==e&&1!==e){var _=3*(o-s),g=3*(l-o)-_,p=d-s-_-g,v=3*(u-a),m=3*(c-u)-v,y=f-a-v-m;if(0===n)i=((p*e+g)*e+_)*e+s,r=((y*e+m)*e+v)*e+a;else{var w=1e-5;if(w>e&&o==s&&u==a||e>1-w&&l==d&&c==f?(i=l-o,r=c-u):(i=(3*p*e+2*g)*e+_,r=(3*y*e+2*m)*e+v),3===n){var x=6*p*e+2*g,b=6*y*e+2*m;return(i*b-r*x)/Math.pow(i*i+r*r,1.5)}}}else i=0===e?s:d,r=0===e?a:f;return 2==n?new h(r,-i):new h(i,r)},subdivide:function(e,n){var i=e[0],r=e[1],s=e[2],a=e[3],o=e[4],h=e[5],u=e[6],l=e[7];n===t&&(n=.5);var c=1-n,d=c*i+n*s,f=c*r+n*a,_=c*s+n*o,g=c*a+n*h,p=c*o+n*u,v=c*h+n*l,m=c*d+n*_,y=c*f+n*g,w=c*_+n*p,x=c*g+n*v,b=c*m+n*w,C=c*y+n*x;return[[i,r,d,f,m,y,b,C],[b,C,w,x,p,v,u,l]]},solveCubic:function(t,e,n,i,r,s){var a=t[e],h=t[e+2],u=t[e+4],l=t[e+6],c=3*(h-a),d=3*(u-h)-c,f=l-a-c-d;return o.solveCubic(f,d,c,a-n,i,r,s)},getParameterOf:function(t,e,n){if(Math.abs(t[0]-e)<1e-5&&Math.abs(t[1]-n)<1e-5)return 0;if(Math.abs(t[6]-e)<1e-5&&Math.abs(t[7]-n)<1e-5)return 1;for(var i,r,s=[],a=[],o=M.solveCubic(t,0,e,s),h=M.solveCubic(t,1,n,a),u=0;-1==o||o>u;)if(-1==o||(i=s[u++])>=0&&1>=i){for(var l=0;-1==h||h>l;)if((-1==h||(r=a[l++])>=0&&1>=r)&&(-1==o?i=r:-1==h&&(r=i),Math.abs(i-r)<1e-5))return.5*(i+r);if(-1==o)break}return null},getPart:function(t,e,n){return e>0&&(t=M.subdivide(t,e)[1]),1>n&&(t=M.subdivide(t,(n-e)/(1-e))[0]),t},isLinear:function(t){var e=o.isZero;return e(t[0]-t[2])&&e(t[1]-t[3])&&e(t[4]-t[6])&&e(t[5]-t[7])},isFlatEnough:function(t,e){var n=t[0],i=t[1],r=t[2],s=t[3],a=t[4],o=t[5],h=t[6],u=t[7],l=3*r-2*n-h,c=3*s-2*i-u,d=3*a-2*h-n,f=3*o-2*u-i;return Math.max(l*l,d*d)+Math.max(c*c,f*f)<10*e*e},getArea:function(t){var e=t[0],n=t[1],i=t[2],r=t[3],s=t[4],a=t[5],o=t[6],h=t[7];return(3*r*e-1.5*r*s-1.5*r*o-3*n*i-1.5*n*s-.5*n*o+1.5*a*e+1.5*a*i-3*a*o+.5*h*e+1.5*h*i+3*h*s)/10},getBounds:function(t){for(var e=t.slice(0,2),n=e.slice(),i=[0,0],r=0;2>r;r++)M._addBounds(t[r],t[r+2],t[r+4],t[r+6],r,0,e,n,i);return new f(e[0],e[1],n[0]-e[0],n[1]-e[1])},_addBounds:function(t,e,n,i,r,s,a,h,u){function l(t,e){var n=t-e,i=t+e;nh[r]&&(h[r]=i)}var c=3*(e-n)-t+i,d=2*(t+n)-4*e,f=e-t,_=o.solveQuadratic(c,d,f,u),g=1e-5,p=1-g;l(i,0);for(var v=0;_>v;v++){var m=u[v],y=1-m;m>g&&p>m&&l(y*y*y*t+3*y*y*m*e+3*y*m*m*n+m*m*m*i,s)}},_getWinding:function(t,e,n,i,r){function s(t){var e=t[1],i=t[7],r=1;if(e>i){var s=e;e=i,i=s,r=-1}return(e>n||n>i)&&(r=0),r}var a=1e-5,h=Math.abs;if(M.isLinear(t)){var u=s(t);if(!u)return 0;var l=(t[6]-t[0])*(n-t[1])-(t[7]-t[1])*(e-t[0]);return(-a>l?-1:1)==u?0:u}for(var c,d=t[1],f=t[3],_=t[5],g=t[7],p=3*(f-_)-d+g,v=2*(d+_)-4*f,m=f-d,y=o.solveQuadratic(p,v,m,i,a,1-a),w=t,x=i[0],b=0,C=0;y>=C;C++){if(C===y)c=w;else{var S=M.subdivide(w,x);c=S[0],w=S[1],x=i[C],x=(i[C+1]-x)/(1-x)}C>0&&(c[3]=c[1]),y>C&&(c[5]=w[1]);var u=s(c);if(u){var P,k;if(1===M.solveCubic(c,1,n,r,-a,1+-a))P=r[0],k=M.evaluate(c,P,0).x;else{var z=(c[1]+c[7])/2;if(P=z>n&&u>0?0:1,1===P&&n==c[7])continue;k=0===P?c[0]:c[6]}var I=h(M.evaluate(c,P,1).y)=k+(I?-a:a*u))||I&&(h(P)0?1:0))e?1:0)},getParameterOf:function(t){return t=h.read(arguments),M.getParameterOf(this.getValues(),t.x,t.y)},getLocationAt:function(t,e){return e||(t=this.getParameterAt(t)),new I(this,t)},getLocationOf:function(t){t=h.read(arguments);var e=this.getParameterOf(t);return null!=e?new I(this,e):null},getNearestLocation:function(t){function e(e){if(e>=0&&1>=e){var i=t.getDistance(M.evaluate(n,e,0),!0);if(s>i)return s=i,a=e,!0}}t=h.read(arguments);for(var n=this.getValues(),i=100,r=o.TOLERANCE,s=1/0,a=0,u=0;i>=u;u++)e(u/i);for(var l=1/(2*i);l>r;)e(a-l)||e(a+l)||(l/=2);var c=M.evaluate(n,a,0);return new I(this,a,c,null,null,null,t.getDistance(c))},getNearestPoint:function(t){return t=h.read(arguments),this.getNearestLocation(t).getPoint()}}),new function(){function e(t){var e=t[0],n=t[1],i=t[2],r=t[3],s=t[4],a=t[5],o=t[6],h=t[7],u=9*(i-s)+3*(o-e),l=6*(e+s)-12*i,c=3*(i-e),d=9*(r-a)+3*(h-n),f=6*(n+a)-12*r,_=3*(r-n);return function(t){var e=(u*t+l)*t+c,n=(d*t+f)*t+_;return Math.sqrt(e*e+n*n)}}function n(t,e){return Math.max(2,Math.min(16,Math.ceil(32*Math.abs(e-t))))}return{statics:!0,getLength:function(i,r,s){r===t&&(r=0),s===t&&(s=1);var a=o.isZero;if(a(i[0]-i[2])&&a(i[1]-i[3])&&a(i[6]-i[4])&&a(i[7]-i[5])){var h=i[6]-i[0],u=i[7]-i[1];return(s-r)*Math.sqrt(h*h+u*u)}var l=e(i);return o.integrate(l,r,s,n(r,s))},getParameterAt:function(t,i,r){function s(t){var e=n(r,t);return f+=t>r?o.integrate(l,r,t,e):-o.integrate(l,t,r,e),r=t,f-i}if(0===i)return r;var a=i>0,h=a?r:0,u=a?1:r,i=Math.abs(i),l=e(t),c=o.integrate(l,h,u,n(h,u));if(i>=c)return a?u:h;var d=i/c,f=0;return o.findRoot(s,l,a?h+d:u-d,h,u,16,1e-5)}}},new function(){function t(t,e,n,i,r,s,a){var o=t[0],h=t[t.length-1];o&&i.equals(o._point)||h&&i.equals(h._point)||t.push(new I(e,n,i,r,s,a))}function e(i,r,s,a,o,h,u,l){if(l=(l||0)+1,!(l>20)){h=h||[0,1],u=u||[0,1];for(var c=M.getPart(i,h[0],h[1]),d=M.getPart(r,u[0],u[1]),f=0;f++<20;){var _,g=n(c,d,_=u.slice()),p=0;if(0===g)break;if(g>0){if(u=_,d=M.getPart(r,u[0],u[1]),p=n(d,c,_=h.slice()),0===p)break;g>0&&(h=_,c=M.getPart(i,h[0],h[1]))}if(0>g||0>p){if(h[1]-h[0]>u[1]-u[0]){var v=(h[0]+h[1])/2;e(i,r,s,a,o,[h[0],v],u,l),e(i,r,s,a,o,[v,h[1]],u,l);break}var v=(u[0]+u[1])/2;e(i,r,s,a,o,h,[u[0],v],l),e(i,r,s,a,o,h,[v,u[1]],l);break}if(Math.abs(h[1]-h[0])<=1e-5&&Math.abs(u[1]-u[0])<=1e-5){var m=(h[0]+h[1])/2,y=(u[0]+u[1])/2;t(o,s,m,M.evaluate(i,m,0),a,y,M.evaluate(r,y,0));break}}}}function n(t,e,n){var r=t[0],s=t[1],a=t[2],o=t[3],h=t[4],u=t[5],l=t[6],c=t[7],d=e[0],f=e[1],_=e[2],g=e[3],v=e[4],m=e[5],y=e[6],w=e[7],x=p.getSignedDistance,b=x(r,s,l,c,a,o)||0,C=x(r,s,l,c,h,u)||0,S=b*C>0?.75:4/9,P=S*Math.min(0,b,C),k=S*Math.max(0,b,C),z=x(r,s,l,c,d,f),I=x(r,s,l,c,_,g),A=x(r,s,l,c,v,m),O=x(r,s,l,c,y,w);if(P>Math.max(z,I,A,O)||kO&&(L=P,P=k,k=L);for(var E=-1/0,j=1/0,D=-1/0,B=0,N=T.length;N>B;B++){var q=T[B],F=T[(B+1)%N];F[1]=V&&Z>=P){var W=R+(P-V)/U;j>W&&(j=W),W>E&&(E=W)}if(k>=V&&Z>=k){var W=R+(k-V)/U;W>D&&(D=W),j>W&&(j=0)}}if(1/0!==j&&D!==-1/0){var X=Math.min(P,k),G=Math.max(P,k);O>X&&G>O&&(D=1),z>X&&G>z&&(j=0),E>D&&(D=1);var J=n[0],$=n[1]-J;if(n[0]=J+j*$,n[1]=J+D*$,($-(n[1]-n[0]))/$>=.2)return 1}return M.getBounds(t).touches(M.getBounds(e))?-1:0}function i(t,e,n,i){var r=[0,t],s=[1/3,e],a=[2/3,n],o=[1,i],h=p.getSignedDistance,u=h(0,t,1,i,1/3,e),l=h(0,t,1,i,2/3,n);if(0>u*l)return[r,s,o,a];var c,d;return Math.abs(u)>Math.abs(l)?(c=s,d=(i-n-(i-t)/3)*(2*(i-n)-i+e)/3):(c=a,d=(e-t+(t-i)/3)*(-2*(t-e)+t-n)/3),0>d?[r,c,o]:[r,s,a,o]}function r(e,n,i,r,s){for(var a=M.isLinear(e),o=a?n:e,h=a?e:n,u=h[0],l=h[1],c=h[6],d=h[7],f=c-u,_=d-l,g=Math.atan2(-_,f),p=Math.sin(g),v=Math.cos(g),m=f*v-_*p,y=[0,0,0,0,m,0,m,0],w=[],x=0;8>x;x+=2){var b=o[x]-u,C=o[x+1]-l;w.push(b*v-C*p,C*v+b*p)}for(var S=[],P=M.solveCubic(w,1,0,S,0,1),x=0;P>x;x++){var k=S[x],b=M.evaluate(w,k,0).x;if(b>=0&&m>=b){var z=M.getParameterOf(y,b,0),I=a?z:k,A=a?k:z;t(s,i,I,M.evaluate(e,I,0),r,A,M.evaluate(n,A,0))}}}function s(e,n,i,r,s){var a=p.intersect(e[0],e[1],e[6],e[7],n[0],n[1],n[6],n[7]);a&&t(s,i,null,a,r)}return{statics:{getIntersections:function(t,n,i,a,o){var h=M.isLinear(t),u=M.isLinear(n);return(h&&u?s:h||u?r:e)(t,n,i,a,o),o}}}}),I=e.extend({_class:"CurveLocation",initialize:function pe(t,e,n,i,r,s,a){this._id=pe._id=(pe._id||0)+1,this._curve=t,this._segment1=t._segment1,this._segment2=t._segment2,this._parameter=e,this._point=n,this._curve2=i,this._parameter2=r,this._point2=s,this._distance=a},getSegment:function(){if(!this._segment){var t=this.getCurve(),e=this.getParameter();if(1===e)this._segment=t._segment2;else if(0===e||arguments[0])this._segment=t._segment1;else{if(null==e)return null;this._segment=t.getLength(0,e)a;a++)s[a]=i[a].getValues();for(var a=0,o=n.length;o>a;a++)for(var h=n[a],u=h.getValues(),l=0;r>l;l++)M.getIntersections(u,s[l],h,i[l],e);return e},setPathData:function(t){function e(t,e,n){var r=parseFloat(i[t]);return a&&(r+=o[e]),n&&(o[e]=r),r}function n(t,n){return new h(e(t,"x",n),e(t+1,"y",n))}var i,r,s=t.match(/[mlhvcsqtaz][^mlhvcsqtaz]*/gi),a=!1,o=new h;this.clear();for(var u=0,l=s.length;l>u;u++){var c=s[u],d=c[0],f=d.toLowerCase();i=c.match(/[+-]?(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?/g);var _=i&&i.length;switch(a=d===f,f){case"m":case"l":for(var g=0;_>g;g+=2)this[0===g&&"m"===f?"moveTo":"lineTo"](n(g,!0));break;case"h":case"v":for(var p="h"==f?"x":"y",g=0;_>g;g++)e(g,p,!0),this.lineTo(o);break;case"c":for(var g=0;_>g;g+=6)this.cubicCurveTo(n(g),r=n(g+2),n(g+4,!0));break;case"s":for(var g=0;_>g;g+=4)this.cubicCurveTo(o.multiply(2).subtract(r),r=n(g),n(g+2,!0));break;case"q":for(var g=0;_>g;g+=4)this.quadraticCurveTo(r=n(g),n(g+2,!0));break;case"t":for(var g=0;_>g;g+=2)this.quadraticCurveTo(r=o.multiply(2).subtract(r),n(g,!0));break;case"a":break;case"z":this.closePath()}}},_canComposite:function(){return!(this.hasFill()&&this.hasStroke())},_contains:function(t){var e=this._getWinding(t);return!!("evenodd"===this.getWindingRule()?1&e:e)}}),O=A.extend({_class:"Path",_serializeFields:{segments:[],closed:!1},initialize:function(e){this._closed=!1,this._segments=[];var n=Array.isArray(e)?"object"==typeof e[0]?e:arguments:e&&(e.point!==t&&e.size===t||e.x!==t)?arguments:null;this.setSegments(n||[]),this._initialize(!n&&e)},_equals:function(t){return e.equals(this._segments,t._segments)},clone:function(e){var n=this._clone(new O({segments:this._segments,insert:!1}),e);return n._closed=this._closed,this._clockwise!==t&&(n._clockwise=this._clockwise),n},_changed:function ve(t){if(ve.base.call(this,t),4&t){if(delete this._length,delete this._clockwise,this._curves)for(var e=0,n=this._curves.length;n>e;e++)this._curves[e]._changed(5)}else 8&t&&delete this._bounds},getSegments:function(){return this._segments},setSegments:function(t){var e=this.isFullySelected();this._segments.length=0,this._selectedSegmentState=0,delete this._curves,this._add(k.readAll(t)),e&&this.setFullySelected(!0)},getFirstSegment:function(){return this._segments[0]},getLastSegment:function(){return this._segments[this._segments.length-1]},getCurves:function(){var t=this._curves,e=this._segments;if(!t){var n=this._countCurves();t=this._curves=Array(n);for(var i=0;n>i;i++)t[i]=new M(this,e[i],e[i+1]||e[0])}return t},getFirstCurve:function(){return this.getCurves()[0]},getLastCurve:function(){var t=this.getCurves();return t[t.length-1]},getPathData:function(){function t(t,e,s){var a=t._point,o=e._point,h=t._handleOut,u=e._handleIn;if(h.isZero()&&u.isZero())s||r.push("L"+i.point(o,n));else{var l=o.subtract(a);r.push("c"+i.point(h,n)+" "+i.point(l.add(u),n)+" "+i.point(l,n))}}var e=this._segments,n=arguments[0],i=a.instance,r=[];if(0===e.length)return"";r.push("M"+i.point(e[0]._point));for(var s=0,o=e.length-1;o>s;s++)t(e[s],e[s+1],!1);return this._closed&&(t(e[e.length-1],e[0],!0),r.push("z")),r.join("")},isClosed:function(){return this._closed},setClosed:function(t){if(this._closed!=(t=!!t)){if(this._closed=t,this._curves){var e=this._curves.length=this._countCurves();t&&(this._curves[e-1]=new M(this,this._segments[e-1],this._segments[0]))}this._changed(5)}},isEmpty:function(){return 0===this._segments.length},isPolygon:function(){for(var t=0,e=this._segments.length;e>t;t++)if(!this._segments[t].isLinear())return!1;return!0},_applyMatrix:function(t){for(var e=Array(6),n=0,i=this._segments.length;i>n;n++)this._segments[n]._transformCoordinates(t,e,!0);return!0},_add:function(t,e){for(var n=this._segments,i=this._curves,r=t.length,s=null==e,e=s?n.length:e,a=0;r>a;a++){var o=t[a];o._path&&(o=t[a]=o.clone()),o._path=this,o._index=e+a,o._selectionState&&this._updateSelection(o,0,o._selectionState)}if(s)n.push.apply(n,t);else{n.splice.apply(n,[e,0].concat(t));for(var a=e+r,h=n.length;h>a;a++)n[a]._index=a}if(i||t._curves){i||(i=this._curves=[]);var u=e>0?e-1:e,l=u,c=Math.min(u+r,this._countCurves());t._curves&&(i.splice.apply(i,[u,0].concat(t._curves)),l+=t._curves.length);for(var a=l;c>a;a++)i.splice(a,0,new M(this,null,null));this._adjustCurves(u,c)}return this._changed(5),t},_adjustCurves:function(t,e){for(var n,i=this._segments,r=this._curves,s=t;e>s;s++)n=r[s],n._path=this,n._segment1=i[s],n._segment2=i[s+1]||i[0];(n=r[this._closed&&0===t?i.length-1:t-1])&&(n._segment2=i[t]||i[0]),(n=r[e])&&(n._segment1=i[e])},_countCurves:function(){var t=this._segments.length;return!this._closed&&t>0?t-1:t},add:function(t){return arguments.length>1&&"number"!=typeof t?this._add(k.readAll(arguments)):this._add([k.read(arguments)])[0]},insert:function(t,e){return arguments.length>2&&"number"!=typeof e?this._add(k.readAll(arguments,1),t):this._add([k.read(arguments,1)],t)[0]},addSegment:function(){return this._add([k.read(arguments)])[0]},insertSegment:function(t){return this._add([k.read(arguments,1)],t)[0]},addSegments:function(t){return this._add(k.readAll(t))},insertSegments:function(t,e){return this._add(k.readAll(e),t)},removeSegment:function(t){return this.removeSegments(t,t+1)[0]||null},removeSegments:function(t,n){t=t||0,n=e.pick(n,this._segments.length);var i=this._segments,r=this._curves,s=i.length,a=i.splice(t,n-t),o=a.length;if(!o)return a;for(var h=0;o>h;h++){var u=a[h];u._selectionState&&this._updateSelection(u,u._selectionState,0),delete u._index,delete u._path}for(var h=t,l=i.length;l>h;h++)i[h]._index=h;if(r){var c=t>0&&n===s+(this._closed?1:0)?t-1:t,r=r.splice(c,o);arguments[2]&&(a._curves=r.slice(1)),this._adjustCurves(c,c)}return this._changed(5),a},clear:"#removeSegments",isFullySelected:function(){var t=this._segments.length;return this._selected&&t>0&&this._selectedSegmentState===4*t},setFullySelected:function(t){t&&this._selectSegments(!0),this.setSelected(t)},setSelected:function me(t){t||this._selectSegments(!1),me.base.call(this,t)},_selectSegments:function(t){var e=this._segments.length;this._selectedSegmentState=t?4*e:0;for(var n=0;e>n;n++)this._segments[n]._selectionState=t?4:0},_updateSelection:function(t,e,n){t._selectionState=n;var i=this._selectedSegmentState+=n-e;i>0&&this.setSelected(!0)},flatten:function(t){for(var e=new T(this),n=0,i=e.length/Math.ceil(e.length/t),r=e.length+(this._closed?-i:i)/2,s=[];r>=n;)s.push(new k(e.evaluate(n,0))),n+=i;this.setSegments(s)},simplify:function(t){if(this._segments.length>2){var e=new E(this,t||2.5);this.setSegments(e.fit())}},split:function(t,e){if(null!==e){if(1===arguments.length){var n=t;"number"==typeof n&&(n=this.getLocationAt(n)),t=n.index,e=n.parameter}e>=1&&(t++,e--);var i=this.getCurves();if(t>=0&&t0&&i[t++].divide(e,!0);var r,s=this.removeSegments(t,this._segments.length,!0);return this._closed?(this.setClosed(!1),r=this):t>0&&(r=this._clone((new O).insertAbove(this,!0))),r._add(s,0),this.addSegment(s[0]),r}return null}},isClockwise:function(){return this._clockwise!==t?this._clockwise:O.isClockwise(this._segments)},setClockwise:function(t){this.isClockwise()!=(t=!!t)&&this.reverse(),this._clockwise=t},reverse:function(){this._segments.reverse();for(var e=0,n=this._segments.length;n>e;e++){var i=this._segments[e],r=i._handleIn;i._handleIn=i._handleOut,i._handleOut=r,i._index=e}delete this._curves,this._clockwise!==t&&(this._clockwise=!this._clockwise)},join:function(t){if(t){var e=t._segments,n=this.getLastSegment(),i=t.getLastSegment();n._point.equals(i._point)&&t.reverse();var r,s=t.getFirstSegment();return n._point.equals(s._point)?(n.setHandleOut(s._handleOut),this._add(e.slice(1))):(r=this.getFirstSegment(),r._point.equals(s._point)&&t.reverse(),i=t.getLastSegment(),r._point.equals(i._point)?(r.setHandleIn(i._handleIn),this._add(e.slice(0,e.length-1),0)):this._add(e.slice())),t.closed&&this._add([e[0]]),t.remove(),r=this.getFirstSegment(),n=this.getLastSegment(),n._point.equals(r._point)&&(r.setHandleIn(n._handleIn),n.remove(),this.setClosed(!0)),this._changed(5),!0}return!1},getLength:function(){if(null==this._length){var t=this.getCurves();this._length=0;for(var e=0,n=t.length;n>e;e++)this._length+=t[e].getLength()}return this._length},getArea:function(){for(var t=this.getCurves(),e=0,n=0,i=t.length;i>n;n++)e+=t[n].getArea();return e},_getOffset:function(t){var e=t&&t.getIndex();if(null!=e){for(var n=this.getCurves(),i=0,r=0;e>r;r++)i+=n[r].getLength();var s=n[e];return i+s.getLength(0,t.getParameter())}return null},getLocationOf:function(t){t=h.read(arguments);for(var e=this.getCurves(),n=0,i=e.length;i>n;n++){var r=e[n].getLocationOf(t);if(r)return r}return null},getLocationAt:function(t,e){var n=this.getCurves(),i=0;if(e){var r=~~t;return n[r].getLocationAt(t-r,!0)}for(var s=0,a=n.length;a>s;s++){var o=i,h=n[s];if(i+=h.getLength(),i>=t)return h.getLocationAt(t-o)}return t<=this.getLength()?new I(n[n.length-1],1):null},getPointAt:function(t,e){var n=this.getLocationAt(t,e);return n&&n.getPoint()},getTangentAt:function(t,e){var n=this.getLocationAt(t,e);return n&&n.getTangent()},getNormalAt:function(t,e){var n=this.getLocationAt(t,e); +return n&&n.getNormal()},getNearestLocation:function(t){t=h.read(arguments);for(var e=this.getCurves(),n=1/0,i=null,r=0,s=e.length;s>r;r++){var a=e[r].getNearestLocation(t);a._distanceh;h++){var l=n[h].getValues(),c=l[0],d=l[1];(c!==l[2]||d!==l[3]||c!==l[4]||d!==l[5]||c!==l[6]||d!==l[7])&&(r+=M._getWinding(l,t.x,t.y,s,a))}return e||(r+=M._getWinding(o,t.x,t.y,s,a)),r},_hitTest:function(e,n){function i(n,i,r){return e.getDistance(i)s;s++)r+=M._getWinding(a(s),t.x,t.y,n,i);return!!r}function h(t){return("round"!==u||"round"!==l)&&(d=[],v||t._index>0&&t._index0)?o(e):e.getDistance(t._point)<=y}var u,l,c,d,f,_,g=this.getStyle(),p=this._segments,v=this._closed,m=n.tolerance,y=0,w=this;if(n.stroke&&(y=g.getStrokeWidth()/2,y>0?(u=g.getStrokeJoin(),l=g.getStrokeCap(),c=y*g.getMiterLimit()):u=l="round",y+=m),!n.ends||n.segments||v){if(n.segments||n.handles)for(var x=0,b=p.length;b>x;x++)if(_=r(p[x]))return _}else if(_=r(p[0],!0)||r(p[p.length-1],!0))return _;if(y>0){if(f=this.getNearestLocation(e)){var C=f.getParameter();0===C||1===C?h(f.getSegment())||(f=null):f._distance>y&&(f=null)}if(!f&&"miter"===u)for(var x=0,b=p.length;b>x;x++){var S=p[x];if(e.getDistance(S._point)<=c&&h(S)){f=S.getLocation();break}}}return!f&&n.fill&&this.hasFill()&&this.contains(e)?new P("fill",this):f?new P("stroke",this,{location:f}):null}},new function(){function t(t,e,n,i){function r(e){var n=a[e],i=a[e+1];(d!=n||f!=i)&&(t.beginPath(),t.moveTo(d,f),t.lineTo(n,i),t.stroke(),t.beginPath(),t.arc(n,i,s,0,2*Math.PI,!0),t.fill())}for(var s=i/2,a=Array(6),o=0,h=e.length;h>o;o++){var u=e[o];u._transformCoordinates(n,a,!1);var l=u._selectionState,c=4&l,d=a[0],f=a[1];(c||1&l)&&r(2),(c||2&l)&&r(4),t.save(),t.beginPath(),t.rect(d-s,f-s,i,i),t.fill(),c||(t.beginPath(),t.rect(d-s+1,f-s+1,i-2,i-2),t.fillStyle="#ffffff",t.fill()),t.restore()}}function e(t,e,n){function i(e){var i=d[e];if(n)i._transformCoordinates(n,_,!1),r=_[0],s=_[1];else{var f=i._point;r=f._x,s=f._y}if(g)t.moveTo(r,s),g=!1;else{if(n)h=_[2],u=_[3];else{var p=i._handleIn;h=r+p._x,u=s+p._y}h==r&&u==s&&l==a&&c==o?t.lineTo(r,s):t.bezierCurveTo(l,c,h,u,r,s)}if(a=r,o=s,n)l=_[4],c=_[5];else{var p=i._handleOut;l=a+p._x,c=o+p._y}}for(var r,s,a,o,h,u,l,c,d=e._segments,f=d.length,_=Array(6),g=!0,p=0;f>p;p++)i(p);e._closed&&f>1&&i(0)}return{_draw:function(t,n){function i(t){return u[(t%l+l)%l]}var r=n.clip,s=n.compound;s||t.beginPath();var a=this.getStyle(),o=a.hasFill(),h=a.hasStroke(),u=a.getDashArray(),l=!paper.support.nativeDash&&h&&u&&u.length;if((o||h&&!l||s||r)&&e(t,this),this._closed&&t.closePath(),!r&&!s&&(o||h)&&(this._setStyles(t),o&&(t.fill(a.getWindingRule()),t.shadowColor="rgba(0,0,0,0)"),h)){if(l){t.beginPath();var c,d=new T(this),f=d.length,_=-a.getDashOffset(),g=0;for(_%=f;_>0;)_-=i(g--)+i(g--);for(;f>_;)c=_+i(g++),(_>0||c>0)&&d.drawPart(t,Math.max(_,0),Math.max(c,0)),_=c+i(g++)}t.stroke()}},_drawSelected:function(n,i){n.beginPath(),e(n,this,i),n.stroke(),t(n,this._segments,i,this._project.options.handleSize||4)}}},new function(){function t(t){var e=t.length,n=[],i=[],r=2;n[0]=t[0]/r;for(var s=1;e>s;s++)i[s]=1/r,r=(e-1>s?4:2)-i[s],n[s]=(t[s]-n[s-1])/r;for(var s=1;e>s;s++)n[e-s-1]-=i[e-s]*n[e-s];return n}return{smooth:function(){var e,n=this._segments,i=n.length,r=i;if(!(2>=i)){this._closed?(e=Math.min(i,4),r+=2*Math.min(i,e)):e=0;for(var s=[],a=0;i>a;a++)s[a+e]=n[a]._point;if(this._closed)for(var a=0;e>a;a++)s[a]=n[a+i-e]._point,s[a+i+e]=n[a]._point;else r--;for(var o=[],a=1;r-1>a;a++)o[a]=4*s[a]._x+2*s[a+1]._x;o[0]=s[0]._x+2*s[1]._x,o[r-1]=3*s[r-1]._x;for(var u=t(o),a=1;r-1>a;a++)o[a]=4*s[a]._y+2*s[a+1]._y;o[0]=s[0]._y+2*s[1]._y,o[r-1]=3*s[r-1]._y;var l=t(o);if(this._closed){for(var a=0,c=i;e>a;a++,c++){var d=a/e,f=1-d,_=a+e,g=c+e;u[c]=u[a]*d+u[c]*f,l[c]=l[a]*d+l[c]*f,u[g]=u[_]*f+u[g]*d,l[g]=l[_]*f+l[g]*d}r--}for(var p=null,a=e;r-e>=a;a++){var v=n[a-e];p&&v.setHandleIn(p.subtract(v._point)),r>a&&(v.setHandleOut(new h(u[a],l[a]).subtract(v._point)),p=r-1>a?new h(2*s[a+1]._x-u[a+1],2*s[a+1]._y-l[a+1]):new h((s[r]._x+u[r-1])/2,(s[r]._y+l[r-1])/2))}if(this._closed&&p){var v=this._segments[0];v.setHandleIn(p.subtract(v._point))}}}}},new function(){function t(t){var e=t._segments;if(0==e.length)throw Error("Use a moveTo() command first");return e[e.length-1]}return{moveTo:function(){1===this._segments.length&&this.removeSegment(0),this._segments.length||this._add([new k(h.read(arguments))])},moveBy:function(){throw Error("moveBy() is unsupported on Path items.")},lineTo:function(){this._add([new k(h.read(arguments))])},cubicCurveTo:function(){var e=h.read(arguments),n=h.read(arguments),i=h.read(arguments),r=t(this);r.setHandleOut(e.subtract(r._point)),this._add([new k(i,n.subtract(i))])},quadraticCurveTo:function(){var e=h.read(arguments),n=h.read(arguments),i=t(this)._point;this.cubicCurveTo(e.add(i.subtract(e).multiply(1/3)),e.add(n.subtract(e).multiply(1/3)),n)},curveTo:function(){var n=h.read(arguments),i=h.read(arguments),r=e.pick(e.read(arguments),.5),s=1-r,a=t(this)._point,o=n.subtract(a.multiply(s*s)).subtract(i.multiply(r*r)).divide(2*r*s);if(o.isNaN())throw Error("Cannot put a curve through points with parameter = "+r);this.quadraticCurveTo(o,i)},arcTo:function(n,i){var r,s=t(this),a=s._point,o=h.read(arguments),u=e.pick(e.peek(arguments),!0);if("boolean"==typeof u){n=o,i=u;var l=a.add(n).divide(2),r=l.add(l.subtract(a).rotate(i?-90:90))}else r=o,n=h.read(arguments);var c=new p(a.add(r).divide(2),r.subtract(a).rotate(90),!0),d=new p(r.add(n).divide(2),n.subtract(r).rotate(90),!0),f=c.intersect(d,!0),_=new p(a,n),g=_.getSide(r);if(!f){if(!g)return this.lineTo(n);throw Error("Cannot put an arc through the given points: "+[a,r,n])}var v=a.subtract(f),m=v.getDirectedAngle(n.subtract(f)),y=_.getSide(f);0==y?m=g*Math.abs(m):g==y&&(m-=360*(0>m?-1:1));for(var w=Math.abs(m),x=w>=360?4:Math.ceil(w/90),b=m/x,C=b*Math.PI/360,S=4/3*Math.sin(C)/(1+Math.cos(C)),P=[],z=0;x>=z;z++){var M=x>z?f.add(v):n,I=x>z?v.rotate(90).multiply(S):null;0==z?s.setHandleOut(I):P.push(new k(M,v.rotate(-90).multiply(S),I)),v=v.rotate(b)}this._add(P)},lineBy:function(){var e=h.read(arguments),n=t(this)._point;this.lineTo(n.add(e))},curveBy:function(){var n=h.read(arguments),i=h.read(arguments),r=e.read(arguments),s=t(this)._point;this.curveTo(s.add(n),s.add(i),r)},cubicCurveBy:function(){var e=h.read(arguments),n=h.read(arguments),i=h.read(arguments),r=t(this)._point;this.cubicCurveTo(r.add(e),r.add(n),r.add(i))},quadraticCurveBy:function(){var e=h.read(arguments),n=h.read(arguments),i=t(this)._point;this.quadraticCurveTo(i.add(e),i.add(n))},arcBy:function(){var e=h.read(arguments),n=h.read(arguments),i=t(this)._point;this.arcTo(i.add(e),i.add(n))},closePath:function(){var t=this.getFirstSegment(),e=this.getLastSegment();t._point.equals(e._point)&&(t.setHandleIn(e._handleIn),e.remove()),this.setClosed(!0)}}},{_getBounds:function(t,e){return O[t](this._segments,this._closed,this.getStyle(),e)},statics:{isClockwise:function(t){for(var e=0,n=0,i=t.length;i>n;n++)for(var r=M.getValues(t[n],t[i>n+1?n+1:0]),s=2;8>s;s+=2)e+=(r[s-2]-r[s])*(r[s+1]+r[s-1]);return e>0},getBounds:function(t,e,n,i,r){function s(t){t._transformCoordinates(i,o,!1);for(var e=0;2>e;e++)M._addBounds(h[e],h[e+4],o[e+2],o[e],e,r?r[e]:0,u,l,c);var n=h;h=o,o=n}var a=t[0];if(!a)return new f;for(var o=Array(6),h=a._transformCoordinates(i,Array(6),!1),u=h.slice(0,2),l=u.slice(),c=Array(2),d=1,_=t.length;_>d;d++)s(t[d]);return e&&s(a),new f(u[0],u[1],l[0]-u[0],l[1]-u[1])},getStrokeBounds:function(t,e,n,i){function r(t,e){if(!e)return[t,t];var n=e.shiftless(),i=n.transform(new h(t,0)),r=n.transform(new h(0,t)),s=i.getAngleInRadians(),a=i.getLength(),o=r.getLength(),u=Math.sin(s),l=Math.cos(s),c=Math.tan(s),d=-Math.atan(o*c/a),f=Math.atan(o/(c*a));return[Math.abs(a*Math.cos(d)*l-o*Math.sin(d)*u),Math.abs(o*Math.sin(f)*l+a*Math.cos(f)*u)]}function s(t){_=_.include(i?i._transformPoint(t,t):t)}function a(t,e){"round"===e||!t._handleIn.isZero()&&!t._handleOut.isZero()?_=_.unite(m.setCenter(i?i._transformPoint(t._point):t._point)):O._addSquareJoin(t,e,l,v,s)}function o(t,e){switch(e){case"round":a(t,e);break;case"butt":case"square":O._addSquareCap(t,e,l,s)}}if(!n.hasStroke())return O.getBounds(t,e,n,i);for(var u=t.length-(e?0:1),l=n.getStrokeWidth()/2,d=r(l,i),_=O.getBounds(t,e,n,i,d),g=n.getStrokeJoin(),p=n.getStrokeCap(),v=l*n.getMiterLimit(),m=new f(new c(d).multiply(2)),y=1;u>y;y++)a(t[y],g);return e?a(t[0],g):(o(t[0],p),o(t[t.length-1],p)),_},_addSquareJoin:function(t,e,n,i,r,s){var a=t.getCurve(),o=a.getPrevious(),u=a.getPointAt(0,!0),l=o.getNormalAt(1,!0),c=a.getNormalAt(0,!0),d=l.getDirectedAngle(c)<0?-n:n;if(l.setLength(d),c.setLength(d),s&&(r(u),r(u.add(l))),"miter"===e){var f=new p(u.add(l),new h(-l.y,l.x),!0).intersect(new p(u.add(c),new h(-c.y,c.x),!0),!0);if(f&&u.getDistance(f)<=i&&(r(f),!s))return}s||r(u.add(l)),r(u.add(c))},_addSquareCap:function(t,e,n,i,r){var s=t._point,a=t.getLocation(),o=a.getNormal().normalize(n);r&&(i(s.subtract(o)),i(s.add(o))),"square"===e&&(s=s.add(o.rotate(0==a.getParameter()?-90:90))),i(s.add(o)),i(s.subtract(o))},getHandleBounds:function(t,e,n,i,r,s){var a=Array(6),o=1/0,h=-o,u=o,l=h;r=r/2||0,s=s/2||0;for(var c=0,d=t.length;d>c;c++){var _=t[c];_._transformCoordinates(i,a,!1);for(var g=0;6>g;g+=2){var p=0==g?s:r,v=a[g],m=a[g+1],y=v-p,w=v+p,x=m-p,b=m+p;o>y&&(o=y),w>h&&(h=w),u>x&&(u=x),b>l&&(l=b)}}return new f(o,u,h-o,l-u)},getRoughBounds:function(t,e,n,i){var r=n.getStrokeColor()?n.getStrokeWidth():0,s=r;return 0===r?r=1e-5:("miter"===n.getStrokeJoin()&&(s=r*n.getMiterLimit()),"square"===n.getStrokeCap()&&(s=Math.max(s,r*Math.sqrt(2)))),O.getHandleBounds(t,e,n,i,r,s)}}});O.inject({statics:new function(){function t(t,n,r){for(var s=new O,a=Array(4),o=0;4>o;o++){var h=i[o];a[o]=new k(h._point.multiply(n).add(t),h._handleIn.multiply(n),h._handleOut.multiply(n))}return s._add(a),s._closed=!0,s.set(e.getNamed(r))}var n=o.KAPPA,i=[new k([-1,0],[0,n],[0,-n]),new k([0,-1],[-n,0],[n,0]),new k([1,0],[0,-n],[0,n]),new k([0,1],[n,0],[-n,0])];return{Line:function(){return new O(h.readNamed(arguments,"from"),h.readNamed(arguments,"to")).set(e.getNamed(arguments))},Circle:function(){var n=h.readNamed(arguments,"center"),i=e.readNamed(arguments,"radius");return t(n,new c(i),arguments)},Rectangle:function(){var t=f.readNamed(arguments,"rectangle"),i=c.readNamed(arguments,"radius",0,0,{readNull:!0}),r=t.getBottomLeft(!0),s=t.getTopLeft(!0),a=t.getTopRight(!0),o=t.getBottomRight(!0);if(path=new O,!i||i.isZero())path._add([new k(r),new k(s),new k(a),new k(o)]);else{i=c.min(i,t.getSize(!0).divide(2));var h=i.width,u=i.height,l=h*n,d=u*n;path._add([new k(r.add(h,0),null,[-l,0]),new k(r.subtract(0,u),[0,d]),new k(s.add(0,u),null,[0,-d]),new k(s.add(h,0),[-l,0],null),new k(a.subtract(h,0),null,[l,0]),new k(a.add(0,u),[0,-d],null),new k(o.subtract(0,u),null,[0,d]),new k(o.subtract(h,0),[l,0])])}return path._closed=!0,path.set(e.getNamed(arguments))},RoundRectangle:"#Rectangle",Ellipse:function(){var e=b._readEllipse(arguments);return t(e.center,e.radius,arguments)},Oval:"#Ellipse",Arc:function(){var t=h.readNamed(arguments,"from"),n=h.readNamed(arguments,"through"),i=h.readNamed(arguments,"to"),r=new O;return r.moveTo(t),r.arcTo(n,i),r.set(e.getNamed(arguments))},RegularPolygon:function(){for(var t=h.readNamed(arguments,"center"),n=e.readNamed(arguments,"sides"),i=e.readNamed(arguments,"radius"),r=new O,s=360/n,a=!(n%3),o=new h(0,a?-i:i),u=a?-1:.5,l=Array(n),c=0;n>c;c++)l[c]=new k(t.add(o.rotate((c+u)*s)));return r._add(l),r._closed=!0,r.set(e.getNamed(arguments))},Star:function(){for(var t=h.readNamed(arguments,"center"),n=2*e.readNamed(arguments,"points"),i=e.readNamed(arguments,"radius1"),r=e.readNamed(arguments,"radius2"),s=new O,a=360/n,o=new h(0,-1),u=Array(n),l=0;n>l;l++)u[l]=new k(t.add(o.rotate(a*l).multiply(l%2?r:i)));return s._add(u),s._closed=!0,s.set(e.getNamed(arguments))}}}});var L=A.extend({_class:"CompoundPath",_serializeFields:{children:[]},initialize:function(t){this._children=[],this._namedChildren={},this._initialize(t)||this.addChildren(Array.isArray(t)?t:arguments)},insertChildren:function ye(e,n,i){n=ye.base.call(this,e,n,i,"path");for(var r=0,s=!i&&n&&n.length;s>r;r++){var a=n[r];a._clockwise===t&&a.setClockwise(0===a._index)}return n},reverse:function(){for(var t=this._children,e=0,n=t.length;n>e;e++)t[e].reverse()},smooth:function(){for(var t=0,e=this._children.length;e>t;t++)this._children[t].smooth()},isClockwise:function(){var t=this.getFirstChild();return t&&t.isClockwise()},setClockwise:function(t){this.isClockwise()!=!!t&&this.reverse()},getFirstSegment:function(){var t=this.getFirstChild();return t&&t.getFirstSegment()},getLastSegment:function(){var t=this.getLastChild();return t&&t.getLastSegment()},getCurves:function(){for(var t=this._children,e=[],n=0,i=t.length;i>n;n++)e=e.concat(t[n].getCurves());return e},getFirstCurve:function(){var t=this.getFirstChild();return t&&t.getFirstCurve()},getLastCurve:function(){var t=this.getLastChild();return t&&t.getFirstCurve()},getArea:function(){for(var t=this._children,e=0,n=0,i=t.length;i>n;n++)e+=t[n].getArea();return e},getPathData:function(){for(var t=this._children,e=[],n=0,i=t.length;i>n;n++)e.push(t[n].getPathData(arguments[0]));return e.join(" ")},_getWinding:function(t){for(var e=this._children,n=0,i=0,r=e.length;r>i;i++)n+=e[i]._getWinding(t);return n},_hitTest:function we(t,n){var i=we.base.call(this,t,e.merge(n,{fill:!1}));if(!i)if(n.compoundChildren)for(var r=this._children,s=r.length-1;s>=0&&!i;s--)i=r[s]._hitTest(t,n);else n.fill&&this.hasFill()&&this._contains(t)&&(i=new P("fill",this));return i},_draw:function(t,e){var n=this._children;if(0!==n.length){t.beginPath(),e=e.extend({compound:!0});for(var i=0,r=n.length;r>i;i++)n[i].draw(t,e);if(!e.clip){this._setStyles(t);var s=this._style;s.hasFill()&&(t.fill(s.getWindingRule()),t.shadowColor="rgba(0,0,0,0)"),s.hasStroke()&&t.stroke()}}}},new function(){function t(t){if(!t._children.length)throw Error("Use a moveTo() command first");return t._children[t._children.length-1]}var n={moveTo:function(){var t=new O;this.addChild(t),t.moveTo.apply(t,arguments)},moveBy:function(){this.moveTo(t(this).getLastSegment()._point.add(h.read(arguments)))},closePath:function(){t(this).closePath()}};return e.each(["lineTo","cubicCurveTo","quadraticCurveTo","curveTo","arcTo","lineBy","cubicCurveBy","quadraticCurveBy","curveBy","arcBy"],function(e){n[e]=function(){var n=t(this);n[e].apply(n,arguments)}}),n}),T=e.extend({initialize:function(t){function e(t,e){var n=M.getValues(t,e);s.curves.push(n),s._computeParts(n,t._index,0,1)}this.curves=[],this.parts=[],this.length=0,this.index=0;for(var n,i=t._segments,r=i[0],s=this,a=1,o=i.length;o>a;a++)n=i[a],e(r,n),r=n;t._closed&&e(n,i[0])},_computeParts:function(t,e,n,i){if(i-n>1/32&&!M.isFlatEnough(t,.25)){var r=M.subdivide(t),s=(n+i)/2;this._computeParts(r[0],e,n,s),this._computeParts(r[1],e,s,i)}else{var a=t[6]-t[0],o=t[7]-t[1],h=Math.sqrt(a*a+o*o);h>1e-5&&(this.length+=h,this.parts.push({offset:this.length,value:i,index:e}))}},getParameterAt:function(t){for(var e,n=this.index;e=n,!(0==n||this.parts[--n].offsete;e++){var r=this.parts[e];if(r.offset>=t){this.index=e;var s=this.parts[e-1],a=s&&s.index==r.index?s.value:0,o=s?s.offset:0;return{value:a+(r.value-a)*(t-o)/(r.offset-o),index:r.index}}}var r=this.parts[this.parts.length-1];return{value:1,index:r.index}},evaluate:function(t,e){var n=this.getParameterAt(t);return M.evaluate(this.curves[n.index],n.value,e)},drawPart:function(t,e,n){e=this.getParameterAt(e),n=this.getParameterAt(n);for(var i=e.index;i<=n.index;i++){var r=M.getPart(this.curves[i],i==e.index?e.value:0,i==n.index?n.value:1);i==e.index&&t.moveTo(r[0],r[1]),t.bezierCurveTo.apply(t,r.slice(2))}}}),E=e.extend({initialize:function(t,e){this.points=[];for(var n,i=t._segments,r=0,s=i.length;s>r;r++){var a=i[r].point.clone();n&&n.equals(a)||(this.points.push(a),n=a)}this.error=e},fit:function(){var t=this.points,e=t.length;return this.segments=e>0?[new k(t[0])]:[],e>1&&this.fitCubic(0,e-1,t[1].subtract(t[0]).normalize(),t[e-2].subtract(t[e-1]).normalize()),this.segments},fitCubic:function(e,n,i,r){if(1==n-e){var s=this.points[e],a=this.points[n],o=s.getDistance(a)/3;return this.addCurve([s,s.add(i.normalize(o)),a.add(r.normalize(o)),a]),t}for(var h,u=this.chordLengthParameterize(e,n),l=Math.max(this.error,this.error*this.error),c=0;4>=c;c++){var d=this.generateBezier(e,n,u,i,r),f=this.findMaxError(e,n,d,u);if(f.error=l)break;this.reparameterize(e,n,u,d),l=f.error}var _=this.points[h-1].subtract(this.points[h]),g=this.points[h].subtract(this.points[h+1]),p=_.add(g).divide(2).normalize();this.fitCubic(e,h,i,p),this.fitCubic(h,n,p.negate(),r)},addCurve:function(t){var e=this.segments[this.segments.length-1];e.setHandleOut(t[1].subtract(t[0])),this.segments.push(new k(t[3],t[2].subtract(t[3])))},generateBezier:function(t,e,n,i,r){for(var s=1e-11,a=this.points[t],o=this.points[e],h=[[0,0],[0,0]],u=[0,0],l=0,c=e-t+1;c>l;l++){var d=n[l],f=1-d,_=3*d*f,g=f*f*f,p=_*f,v=_*d,m=d*d*d,y=i.normalize(p),w=r.normalize(v),x=this.points[t+l].subtract(a.multiply(g+p)).subtract(o.multiply(v+m));h[0][0]+=y.dot(y),h[0][1]+=y.dot(w),h[1][0]=h[0][1],h[1][1]+=w.dot(w),u[0]+=y.dot(x),u[1]+=w.dot(x)}var b,C,S=h[0][0]*h[1][1]-h[1][0]*h[0][1];if(Math.abs(S)>s){var P=h[0][0]*u[1]-h[1][0]*u[0],k=u[0]*h[1][1]-u[1]*h[0][1];b=k/S,C=P/S}else{var z=h[0][0]+h[0][1],M=h[1][0]+h[1][1];b=C=Math.abs(z)>s?u[0]/z:Math.abs(M)>s?u[1]/M:0}var I=o.getDistance(a);return s*=I,(s>b||s>C)&&(b=C=I/3),[a,a.add(i.normalize(b)),o.add(r.normalize(C)),o]},reparameterize:function(t,e,n,i){for(var r=t;e>=r;r++)n[r-t]=this.findRoot(i,this.points[r],n[r-t])},findRoot:function(t,e,n){for(var i=[],r=[],s=0;2>=s;s++)i[s]=t[s+1].subtract(t[s]).multiply(3);for(var s=0;1>=s;s++)r[s]=i[s+1].subtract(i[s]).multiply(2);var a=this.evaluate(3,t,n),o=this.evaluate(2,i,n),h=this.evaluate(1,r,n),u=a.subtract(e),l=o.dot(o)+u.dot(h);return Math.abs(l)<1e-5?n:n-u.dot(o)/l},evaluate:function(t,e,n){for(var i=e.slice(),r=1;t>=r;r++)for(var s=0;t-r>=s;s++)i[s]=i[s].multiply(1-n).add(i[s+1].multiply(n));return i[0]},chordLengthParameterize:function(t,e){for(var n=[0],i=t+1;e>=i;i++)n[i-t]=n[i-t-1]+this.points[i].getDistance(this.points[i-1]);for(var i=1,r=e-t;r>=i;i++)n[i]/=n[r];return n},findMaxError:function(t,e,n,i){for(var r=Math.floor((e-t+1)/2),s=0,a=t+1;e>a;a++){var o=this.evaluate(3,n,i[a-t]),h=o.subtract(this.points[a]),u=h.x*h.x+h.y*h.y;u>=s&&(s=u,r=a)}return{error:s,index:r}}});A.inject(new function(){function t(t,e){t.sort(function(t,e){var n=t.getPath(),i=e.getPath();return n===i?t.getIndex()+t.getParameter()-(e.getIndex()+e.getParameter()):n._id-i._id});for(var n=e&&[],i=t.length-1;i>=0;i--){var r=t[i],s=r.getIntersection(),a=r.divide(),o=a&&a.getSegment1()||r.getSegment();n&&n.push(s),o._intersection=s,r._segment=o}return n}function e(t){if(t instanceof L){for(var e=t._children,n=e.length,i=Array(n),r=Array(n),s=e[0].isClockwise(),a=0;n>a;a++)i[a]=e[a].getBounds(),r[a]=0;for(var a=0;n>a;a++){for(var o=1;n>o;o++)a!==o&&i[a].contains(i[o])&&r[o]++;a>0&&0===r[a]%2&&e[a].setClockwise(s)}}return t}function n(n,r,s,a){n=e(n.clone(!1)),r=e(r.clone(!1));var o=n.isClockwise(),u=r.isClockwise(),l=n.getIntersections(r);t(t(l,!0)),o||n.reverse(),a^u||r.reverse(),o=!0,u=!a;for(var c=[].concat(n._children||[n]).concat(r._children||[r]),d=[],f=new L,_=0,g=c.length;g>_;_++){var p=c[_],v=p._parent,m=p.isClockwise(),y=p._segments;p=v instanceof L?v:p;for(var w=y.length-1;w>=0;w--){var x=y[w],b=x.getCurve().getPoint(.5),C=p!==n&&n.contains(b)&&(m===o||a||!i(n,b)),S=p!==r&&r.contains(b)&&(m===u||!i(r,b));s(p===n,C,S)?x._invalid=!0:d.push(x)}}for(var _=0,g=d.length;g>_;_++){var x=d[_];if(!x._visited){var p=new O,P=x._intersection,z=P&&P.getSegment(!0);x.getPrevious()._invalid&&x.setHandleIn(z?z._handleIn:new h(0,0));do{if(x._visited=!0,x._invalid&&x._intersection){var M=x._intersection.getSegment(!0);p.add(new k(x._point,x._handleIn,M._handleOut)),M._visited=!0,x=M}else p.add(x.clone());x=x.getNext()}while(x&&!x._visited&&x!==z);var I=p._segments.length;I>1&&(I>2||!p.isPolygon())?(p.setClosed(!0),f.addChild(p,!0)):p.remove()}}return n.remove(),r.remove(),f.reduce()}function i(t,e){var n=t.getCurves(),i=t.getBounds();if(i.contains(e))for(var r=0,s=n.length;s>r;r++){var a=n[r];if(a.getBounds().contains(e)&&a.getParameterOf(e))return!0}return!1}return{unite:function(t){return n(this,t,function(t,e,n){return e||n})},intersect:function(t){return n(this,t,function(t,e,n){return!(e||n)})},subtract:function(t){return n(this,t,function(t,e,n){return t&&n||!t&&!e},!0)},exclude:function(t){return new w([this.subtract(t),t.subtract(this)])},divide:function(t){return new w([this.subtract(t),this.intersect(t)])}}});var j=y.extend({_class:"TextItem",_boundsSelected:!0,_serializeFields:{content:null},_boundsGetter:"getBounds",initialize:function(n){this._content="",this._lines=[];var i=n&&e.isPlainObject(n)&&n.x===t&&n.y===t;this._initialize(i&&n,!i&&h.read(arguments))},_equals:function(t){return this._content===t._content},_clone:function xe(t){return t.setContent(this._content),xe.base.call(this,t)},getContent:function(){return this._content},setContent:function(t){this._content=""+t,this._lines=this._content.split(/\r\n|\n|\r/gm),this._changed(69)},isEmpty:function(){return!this._content},getCharacterStyle:"#getStyle",setCharacterStyle:"#setStyle",getParagraphStyle:"#getStyle",setParagraphStyle:"#setStyle"}),D=j.extend({_class:"PointText",initialize:function(){j.apply(this,arguments)},clone:function(t){return this._clone(new D({insert:!1}),t)},getPoint:function(){var t=this._matrix.getTranslation();return new u(t.x,t.y,this,"setPoint")},setPoint:function(t){t=h.read(arguments),this.translate(t.subtract(this._matrix.getTranslation()))},_draw:function(t){if(this._content){this._setStyles(t);var e=this._style,n=this._lines,i=e.getLeading(),r=t.shadowColor;t.font=e.getFontStyle(),t.textAlign=e.getJustification();for(var s=0,a=n.length;a>s;s++){t.shadowColor=r;var o=n[s];e.hasFill()&&(t.fillText(o,0,0),t.shadowColor="rgba(0,0,0,0)"),e.hasStroke()&&t.strokeText(o,0,0),t.translate(0,i)}}}},new function(){var t=null;return{_getBounds:function(e,n){t||(t=Q.getContext(1,1));var i=this._style,r=this._lines,s=r.length,a=i.getJustification(),o=i.getLeading(),h=0;t.font=i.getFontStyle();for(var u=0,l=0;s>l;l++)u=Math.max(u,t.measureText(r[l]).width);"left"!==a&&(h-=u/("center"===a?2:1));var c=new f(h,s?-.75*o:0,u,s*o);return n?n._transformBounds(c,c):c}}}),B=e.extend(new function(){function t(t){var e=o[t];if(!e){i||(i=Q.getContext(1,1),i.globalCompositeOperation="copy"),i.fillStyle="rgba(0,0,0,0)",i.fillStyle=t,i.fillRect(0,0,1,1);var n=i.getImageData(0,0,1,1).data;e=o[t]=[n[0]/255,n[1]/255,n[2]/255]}return e.slice()}function n(t){var e=t.match(/^#?(\w{1,2})(\w{1,2})(\w{1,2})$/);if(e.length>=4){for(var n=[0,0,0],i=0;3>i;i++){var r=e[i+1];n[i]=parseInt(1==r.length?r+r:r,16)/255}return n}}var i,r={gray:["gray"],rgb:["red","green","blue"],hsb:["hue","saturation","brightness"],hsl:["hue","saturation","lightness"],gradient:["gradient","origin","destination","highlight"]},s={},o={},u=[[0,3,1],[2,0,1],[1,0,3],[1,2,0],[3,1,0],[0,1,2]],l={"rgb-hsb":function(t,e,n){var i=Math.max(t,e,n),r=Math.min(t,e,n),s=i-r,a=0===s?0:60*(i==t?(e-n)/s+(n>e?6:0):i==e?(n-t)/s+2:(t-e)/s+4);return[a,0===i?0:s/i,i]},"hsb-rgb":function(t,e,n){var t=t/60%6,i=Math.floor(t),r=t-i,i=u[i],s=[n,n*(1-e),n*(1-e*r),n*(1-e*(1-r))];return[s[i[0]],s[i[1]],s[i[2]]]},"rgb-hsl":function(t,e,n){var i=Math.max(t,e,n),r=Math.min(t,e,n),s=i-r,a=0===s,o=a?0:60*(i==t?(e-n)/s+(n>e?6:0):i==e?(n-t)/s+2:(t-e)/s+4),h=(i+r)/2,u=a?0:.5>h?s/(i+r):s/(2-i-r);return[o,u,h]},"hsl-rgb":function(t,e,n){if(t/=360,0===e)return[n,n,n];for(var i=[t+1/3,t,t-1/3],r=.5>n?n*(1+e):n+e-n*e,s=2*n-r,a=[],o=0;3>o;o++){var h=i[o];0>h&&(h+=1),h>1&&(h-=1),a[o]=1>6*h?s+6*(r-s)*h:1>2*h?r:2>3*h?s+6*(r-s)*(2/3-h):s}return a},"rgb-gray":function(t,e,n){return[.2989*t+.587*e+.114*n]},"gray-rgb":function(t){return[t,t,t]},"gray-hsb":function(t){return[0,0,t]},"gray-hsl":function(t){return[0,0,t]},"gradient-rgb":function(){return[]},"rgb-gradient":function(){return[]}};return e.each(r,function(t,n){s[n]=[],e.each(t,function(t,i){var a=e.capitalize(t),o=/^(hue|saturation)$/.test(t),u=s[n][i]="gradient"===t?function(t){var e=this._components[0];return t=N.read(Array.isArray(t)?t:arguments,0,0,{readNull:!0}),e!==t&&(e&&e._removeOwner(this),t&&t._addOwner(this)),t}:"hue"===t?function(t){return isNaN(t)?0:(t%360+360)%360}:"gradient"===n?function(){return h.read(arguments,0,0,{readNull:"highlight"===t,clone:!0})}:function(t){return isNaN(t)?0:Math.min(Math.max(t,0),1)};this["get"+a]=function(){return this._type===n||o&&/^hs[bl]$/.test(this._type)?this._components[i]:this._convert(n)[i]},this["set"+a]=function(t){this._type===n||o&&/^hs[bl]$/.test(this._type)||(this._components=this._convert(n),this._properties=r[n],this._type=n),t=u.call(this,t),null!=t&&(this._components[i]=t,this._changed())}},this)},{_class:"Color",_readIndex:!0,initialize:function c(e){var i,a,o,h,u=Array.prototype.slice,l=arguments,d=0,f=!0;Array.isArray(e)&&(l=e,e=l[0]);var _=null!=e&&typeof e;if("string"===_&&e in r&&(i=e,e=l[1],Array.isArray(e)?(a=e,o=l[2]):(this.__read&&(d=1),l=u.call(l,1),_=typeof e)),!a){if(f=!(this.__options&&this.__options.dontParse),h="number"===_?l:"object"===_&&null!=e.length?e:null){i||(i=h.length>=3?"rgb":"gray");var g=r[i].length;o=h[g],this.__read&&(d+=h===arguments?g+(null!=o?1:0):1),h.length>g&&(h=u.call(h,0,g))}else if("string"===_)a=e.match(/^#[0-9a-f]{3,6}$/i)?n(e):t(e),i="rgb";else if("object"===_)if(e.constructor===c){if(i=e._type,a=e._components.slice(),o=e._alpha,"gradient"===i)for(var p=1,v=a.length;v>p;p++){var m=a[p];m&&(a[p]=m.clone())}}else if(e.constructor===N)i="gradient",h=l;else{i="hue"in e?"lightness"in e?"hsl":"hsb":"gradient"in e||"stops"in e||"radial"in e?"gradient":"gray"in e?"gray":"rgb";var y=r[i];x=f&&s[i],this._components=a=[];for(var p=0,v=y.length;v>p;p++){var w=e[y[p]];null==w&&0===p&&"gradient"===i&&"stops"in e&&(w={stops:e.stops,radial:e.radial}),f&&(w=x[p].call(this,w)),null!=w&&(a[p]=w)}o=e.alpha}this.__read&&i&&(d=1)}if(this._type=i||"rgb","gradient"===i&&(this._id=c._id=(c._id||0)+1),!a){this._components=a=[];for(var x=s[this._type],p=0,v=x.length;v>p;p++){var w=h&&h[p];f&&(w=x[p].call(this,w)),null!=w&&(a[p]=w)}}this._components=a,this._properties=r[this._type],this._alpha=o,this.__read&&(this.__read=d)},_serialize:function(t,n){var i=this.getComponents();return e.serialize(/^(gray|rgb)$/.test(this._type)?i:[this._type].concat(i),t,!0,n)},_changed:function(){this._canvasStyle=null,this._owner&&this._owner._changed(17)},clone:function(){return new B(this)},_convert:function(t){var e;return this._type===t?this._components.slice():(e=l[this._type+"-"+t])?e.apply(this,this._components):l["rgb-"+t].apply(this,l[this._type+"-rgb"].apply(this,this._components))},convert:function(t){return new B(t,this._convert(t),this._alpha)},getType:function(){return this._type},setType:function(t){this._components=this._convert(t),this._properties=r[t],this._type=t},getComponents:function(){var t=this._components.slice();return null!=this._alpha&&t.push(this._alpha),t},getAlpha:function(){return null!=this._alpha?this._alpha:1},setAlpha:function(t){this._alpha=null==t?null:Math.min(Math.max(t,0),1),this._changed()},hasAlpha:function(){return null!=this._alpha},equals:function(t){return e.isPlainValue(t)&&(t=B.read(arguments)),t===this||t&&this._class===t._class&&this._type===t._type&&this._alpha===t._alpha&&e.equals(this._components,t._components)||!1},toString:function(){for(var t=this._properties,e=[],n="gradient"===this._type,i=a.instance,r=0,s=t.length;s>r;r++){var o=this._components[r];null!=o&&e.push(t[r]+": "+(n?o:i.number(o)))}return null!=this._alpha&&e.push("alpha: "+i.number(this._alpha)),"{ "+e.join(", ")+" }"},toCSS:function(t){var e=this._convert("rgb"),n=t||null==this._alpha?1:this._alpha;return e=[Math.round(255*e[0]),Math.round(255*e[1]),Math.round(255*e[2])],1>n&&e.push(n),(4==e.length?"rgba(":"rgb(")+e.join(",")+")"},toCanvasStyle:function(t){if(this._canvasStyle)return this._canvasStyle;if("gradient"!==this._type)return this._canvasStyle=this.toCSS();var e,n=this._components,i=n[0],r=i._stops,s=n[1],a=n[2];if(i._radial){var o=a.getDistance(s),h=n[3];if(h){var u=h.subtract(s);u.getLength()>o&&(h=s.add(u.normalize(o-.1)))}var l=h||s;e=t.createRadialGradient(l.x,l.y,0,s.x,s.y,o)}else e=t.createLinearGradient(s.x,s.y,a.x,a.y);for(var c=0,d=r.length;d>c;c++){var f=r[c];e.addColorStop(f._rampPoint,f._color.toCanvasStyle())}return this._canvasStyle=e},transform:function(t){if("gradient"===this._type){for(var e=this._components,n=1,i=e.length;i>n;n++){var r=e[n];t._transformPoint(r,r,!0)}this._changed()}},statics:{_types:r,random:function(){var t=Math.random;return new B(t(),t(),t())}}})},new function(){function t(t,e){return 0>t?0:e&&t>360?360:!e&&t>1?1:t}var n={add:function(e,n,i){return t(e+n,i)},subtract:function(e,n,i){return t(e-n,i)},multiply:function(e,n,i){return t(e*n,i)},divide:function(e,n,i){return t(e/n,i)}};return e.each(n,function(t,e){var n={dontParse:/^(multiply|divide)$/.test(e)};this[e]=function(e){e=B.read(arguments,0,0,n);for(var i=this._type,r=this._properties,s=this._components,a=e._convert(i),o=0,h=s.length;h>o;o++)a[o]=t(s[o],a[o],"hue"===r[o]);return new B(i,a,null!=this._alpha?t(this._alpha,e.getAlpha()):null)}},{})});e.each(B._types,function(t,n){var i=this[e.capitalize(n)+"Color"]=function(t){var e=null!=t&&typeof t,i="object"===e&&null!=t.length?t:"string"===e?null:arguments;return i?new B(n,i):new B(t)};if(3==n.length){var r=n.toUpperCase();B[r]=this[r+"Color"]=i}},e.exports);var N=e.extend({_class:"Gradient",initialize:function be(t,e){this._id=be._id=(be._id||0)+1,t&&this._set(t)&&(t=e=null),this._stops||this.setStops(t||["white","black"]),null==this._radial&&this.setRadial("string"==typeof e&&"radial"===e||e||!1) +},_serialize:function(t,n){return n.add(this,function(){return e.serialize([this._stops,this._radial],t,!0,n)})},_changed:function(){for(var t=0,e=this._owners&&this._owners.length;e>t;t++)this._owners[t]._changed()},_addOwner:function(t){this._owners||(this._owners=[]),this._owners.push(t)},_removeOwner:function(t){var e=this._owners?this._owners.indexOf(t):-1;-1!=e&&(this._owners.splice(e,1),0===this._owners.length&&delete this._owners)},clone:function(){for(var t=[],e=0,n=this._stops.length;n>e;e++)t[e]=this._stops[e].clone();return new this.constructor(t)},getStops:function(){return this._stops},setStops:function(t){if(this.stops)for(var e=0,n=this._stops.length;n>e;e++)delete this._stops[e]._owner;if(t.length<2)throw Error("Gradient stop list needs to contain at least two stops.");this._stops=q.readAll(t,0,!1,!0);for(var e=0,n=this._stops.length;n>e;e++){var i=this._stops[e];i._owner=this,i._defaultRamp&&i.setRampPoint(e/(n-1))}this._changed()},getRadial:function(){return this._radial},setRadial:function(t){this._radial=t,this._changed()},equals:function(t){if(t===this)return!0;if(t&&this._class===t._class&&this._stops.length===t._stops.length){for(var e=0,n=this._stops.length;n>e;e++)if(!this._stops[e].equals(t._stops[e]))return!1;return!0}return!1}}),q=e.extend({_class:"GradientStop",initialize:function(e,n){if(e){var i,r;n===t&&Array.isArray(e)?(i=e[0],r=e[1]):e.color?(i=e.color,r=e.rampPoint):(i=e,r=n),this.setColor(i),this.setRampPoint(r)}},clone:function(){return new q(this._color.clone(),this._rampPoint)},_serialize:function(t,n){return e.serialize([this._color,this._rampPoint],t,!0,n)},_changed:function(){this._owner&&this._owner._changed(17)},getRampPoint:function(){return this._rampPoint},setRampPoint:function(t){this._defaultRamp=null==t,this._rampPoint=t||0,this._changed()},getColor:function(){return this._color},setColor:function(t){this._color=B.read(arguments),this._color===t&&(this._color=t.clone()),this._color._owner=this,this._changed()},equals:function(t){return t===this||t&&this._class===t._class&&this._color.equals(t._color)&&this._rampPoint==t._rampPoint||!1}}),F=e.extend(new function(){var n={fillColor:t,strokeColor:t,strokeWidth:1,strokeCap:"butt",strokeJoin:"miter",miterLimit:10,dashOffset:0,dashArray:[],windingRule:"nonzero",shadowColor:t,shadowBlur:0,shadowOffset:new h,selectedColor:t,font:"sans-serif",fontSize:12,leading:null,justification:"left"},i={strokeWidth:25,strokeCap:25,strokeJoin:25,miterLimit:25,font:5,fontSize:5,leading:5,justification:5},r={},s={_defaults:n,_textDefaults:e.merge(n,{fillColor:new B})};return e.each(n,function(n,a){var o=/Color$/.test(a),h=e.capitalize(a),u=i[a],l="set"+h,c="get"+h;s[l]=function(t){var e=this._item&&this._item._children;if(e&&e.length>0&&"compound-path"!==this._item._type)for(var n=0,i=e.length;i>n;n++)e[n]._style[l](t);else{var r=this._values[a];r!=t&&(o&&(r&&delete r._owner,t&&t.constructor===B&&(t._owner&&(t=t.clone()),t._owner=this._item)),this._values[a]=t,this._item&&this._item._changed(u||17))}},s[c]=function(){var n,i=this._item&&this._item._children;if(!i||0===i.length||arguments[0]||"compound-path"===this._item._type){var n=this._values[a];return n===t?(n=this._defaults[a],n&&n.clone&&(n=n.clone()),this._values[a]=n):!o||n&&n.constructor===B||(this._values[a]=n=B.read([n],0,0,{readNull:!0,clone:!0}),n&&(n._owner=this._item)),n}for(var r=0,s=i.length;s>r;r++){var h=i[r]._style[c]();if(0===r)n=h;else if(!e.equals(n,h))return t}return n},r[c]=function(){return this._style[c]()},r[l]=function(t){this._style[l](t)}}),y.inject(r),s},{_class:"Style",initialize:function(t,e){this._values={},this._item=e,e instanceof j&&(this._defaults=this._textDefaults),t&&this.set(t)},set:function(t){var e=t instanceof F,n=e?t._values:t;if(n)for(var i in n)if(i in this._defaults){var r=n[i];this[i]=r&&e&&r.clone?r.clone():r}},equals:function(t){return t===this||t&&this._class===t._class&&e.equals(this._values,t._values)||!1},hasFill:function(){return!!this.getFillColor()},hasStroke:function(){return!!this.getStrokeColor()&&this.getStrokeWidth()>0},hasShadow:function(){return!!this.getShadowColor()&&this.getShadowBlur()>0},getLeading:function Ce(){var t=Ce.base.call(this);return null!=t?t:1.2*this.getFontSize()},getFontStyle:function(){var t=this.getFontSize();return t+(/[a-z]/i.test(t+"")?" ":"px ")+this.getFont()}}),R=new function(){function n(t,i){for(var r=[],s=0,a=t&&t.length;a>s;){var o=t[s++];if("string"==typeof o)o=document.createElement(o);else if(!o||!o.nodeType)continue;e.isPlainObject(t[s])&&R.set(o,t[s++]),Array.isArray(t[s])&&n(t[s++],o),i&&i.appendChild(o),r.push(o)}return r}var i=/^(checked|value|selected|disabled)$/i,r={text:"textContent",html:"innerHTML"},s={lineHeight:1,zoom:1,zIndex:1,opacity:1};return{create:function(t,e){var i=Array.isArray(t),r=n(i?t:arguments,i?e:null);return 1==r.length?r[0]:r},find:function(t,e){return(e||document).querySelector(t)},findAll:function(t,e){return(e||document).querySelectorAll(t)},get:function(t,e){return t?i.test(e)?"value"===e||"string"!=typeof t[e]?t[e]:!0:e in r?t[r[e]]:t.getAttribute(e):null},set:function(e,n,s){if("string"!=typeof n)for(var a in n)n.hasOwnProperty(a)&&this.set(e,a,n[a]);else{if(!e||s===t)return e;i.test(n)?e[n]=s:n in r?e[r[n]]=s:"style"===n?this.setStyle(e,s):"events"===n?V.add(e,s):e.setAttribute(n,s)}return e},getStyles:function(t){var e=t&&9!==t.nodeType?t.ownerDocument:t,n=e&&e.defaultView;return n&&n.getComputedStyle(t,"")},getStyle:function(t,e){return t&&t.style[e]||this.getStyles(t)[e]||null},setStyle:function(t,e,n){if("string"!=typeof e)for(var i in e)e.hasOwnProperty(i)&&this.setStyle(t,i,e[i]);else!/^-?[\d\.]+$/.test(n)||e in s||(n+="px"),t.style[e]=n;return t},hasClass:function(t,e){return RegExp("\\s*"+e+"\\s*").test(t.className)},addClass:function(t,e){t.className=(t.className+" "+e).trim()},removeClass:function(t,e){t.className=t.className.replace(RegExp("\\s*"+e+"\\s*")," ").trim()},remove:function(t){t.parentNode&&t.parentNode.removeChild(t)},removeChildren:function(t){for(;t.firstChild;)t.removeChild(t.firstChild)},getBounds:function(t,e){var n,i=t.ownerDocument,r=i.body,s=i.documentElement;try{n=t.getBoundingClientRect()}catch(a){n={left:0,top:0,width:0,height:0}}var o=n.left-(s.clientLeft||r.clientLeft||0),h=n.top-(s.clientTop||r.clientTop||0);if(!e){var u=i.defaultView;o+=u.pageXOffset||s.scrollLeft||r.scrollLeft,h+=u.pageYOffset||s.scrollTop||r.scrollTop}return new f(o,h,n.width,n.height)},getViewportBounds:function(t){var e=t.ownerDocument,n=e.defaultView,i=e.documentElement;return new f(0,0,n.innerWidth||i.clientWidth,n.innerHeight||i.clientHeight)},getOffset:function(t,e){return this.getBounds(t,e).getPoint()},getSize:function(t){return this.getBounds(t,!0).getSize()},isInvisible:function(t){return this.getSize(t).equals(new c(0,0))},isInView:function(t){return!this.isInvisible(t)&&this.getViewportBounds(t).intersects(this.getBounds(t,!0))},getPrefixValue:function(t,e){for(var n=t[e],i=["webkit","moz","ms","o"],r=e[0].toUpperCase()+e.substring(1),s=0;4>s&&null==n;s++)n=t[i[s]+r];return n}}},V={add:function(t,e){for(var n in e){var i=e[n];t.addEventListener?t.addEventListener(n,i,!1):t.attachEvent&&t.attachEvent("on"+n,i.bound=function(){i.call(t,window.event)})}},remove:function(t,e){for(var n in e){var i=e[n];t.removeEventListener?t.removeEventListener(n,i,!1):t.detachEvent&&t.detachEvent("on"+n,i.bound)}},getPoint:function(t){var e=t.targetTouches?t.targetTouches.length?t.targetTouches[0]:t.changedTouches[0]:t;return new h(e.pageX||e.clientX+document.documentElement.scrollLeft,e.pageY||e.clientY+document.documentElement.scrollTop)},getTarget:function(t){return t.target||t.srcElement},getOffset:function(t,e){return V.getPoint(t).subtract(R.getOffset(e||V.getTarget(t)))},preventDefault:function(t){t.preventDefault?t.preventDefault():t.returnValue=!1},stopPropagation:function(t){t.stopPropagation?t.stopPropagation():t.cancelBubble=!0},stop:function(t){V.stopPropagation(t),V.preventDefault(t)}};V.requestAnimationFrame=new function(){function t(){for(var e=s.length-1;e>=0;e--){var o=s[e],h=o[0],u=o[1];(!u||("true"==r.getAttribute(u,"keepalive")||a)&&R.isInView(u))&&(s.splice(e,1),h())}n&&(s.length?n(t):i=!1)}var e,n=R.getPrefixValue(window,"requestAnimationFrame"),i=!1,s=[],a=!0;return V.add(window,{focus:function(){a=!0},blur:function(){a=!1}}),function(r,a){s.push([r,a]),n?i||(n(t),i=!0):e||(e=setInterval(t,1e3/60))}};var H=e.extend(n,{_class:"View",initialize:function Se(t){this._scope=paper,this._project=paper.project,this._element=t;var e;if(this._id=t.getAttribute("id"),null==this._id&&t.setAttribute("id",this._id="view-"+Se._id++),V.add(t,this._viewHandlers),r.hasAttribute(t,"resize")){var n=R.getOffset(t,!0),i=this;e=R.getViewportBounds(t).getSize().subtract(n),this._windowHandlers={resize:function(){R.isInvisible(t)||(n=R.getOffset(t,!0)),i.setViewSize(R.getViewportBounds(t).getSize().subtract(n))}},V.add(window,this._windowHandlers)}else e=new c(parseInt(t.getAttribute("width"),10),parseInt(t.getAttribute("height"),10)),e.isNaN()&&(e=R.getSize(t));if(t.width=e.width,t.height=e.height,r.hasAttribute(t,"stats")&&"object"==typeof Stats){this._stats=new Stats;var s=this._stats.domElement,a=s.style,n=R.getOffset(t);a.position="absolute",a.left=n.x+"px",a.top=n.y+"px",document.body.appendChild(s)}Se._views.push(this),Se._viewsById[this._id]=this,this._viewSize=new d(e.width,e.height,this,"setViewSize"),this._matrix=new g,this._zoom=1,Se._focused||(Se._focused=this),this._frameItems={},this._frameItemCount=0},remove:function(){return this._project?(H._focused==this&&(H._focused=null),H._views.splice(H._views.indexOf(this),1),delete H._viewsById[this._id],this._project.view==this&&(this._project.view=null),V.remove(this._element,this._viewHandlers),V.remove(window,this._windowHandlers),this._element=this._project=null,this.detach("frame"),this._frameItems={},!0):!1},_events:{onFrame:{install:function(){this._requested||(this._animate=!0,this._requestFrame())},uninstall:function(){this._animate=!1}},onResize:{}},_animate:!1,_time:0,_count:0,_requestFrame:function(){var t=this;V.requestAnimationFrame(function(){t._requested=!1,t._animate&&(t._requestFrame(),t._handleFrame())},this._element),this._requested=!0},_handleFrame:function(){paper=this._scope;var t=Date.now()/1e3,n=this._before?t-this._before:0;this._before=t,this._handlingFrame=!0,this.fire("frame",e.merge({delta:n,time:this._time+=n,count:this._count++})),this._stats&&this._stats.update(),this._handlingFrame=!1,this.draw(!0)},_animateItem:function(t,e){var n=this._frameItems;e?(n[t._id]={item:t,time:0,count:0},1===++this._frameItemCount&&this.attach("frame",this._handleFrameItems)):(delete n[t._id],0===--this._frameItemCount&&this.detach("frame",this._handleFrameItems))},_handleFrameItems:function(t){for(var n in this._frameItems){var i=this._frameItems[n];i.item.fire("frame",e.merge(t,{time:i.time+=t.delta,count:i.count++}))}},_redraw:function(){this._project._needsRedraw=!0,this._handlingFrame||(this._animate?this._handleFrame():this.draw())},_transform:function(t){this._matrix.concatenate(t),this._bounds=null,this._redraw()},getElement:function(){return this._element},getViewSize:function(){return this._viewSize},setViewSize:function(t){t=c.read(arguments);var e=t.subtract(this._viewSize);e.isZero()||(this._element.width=t.width,this._element.height=t.height,this._viewSize.set(t.width,t.height,!0),this._bounds=null,this.fire("resize",{size:t,delta:e}),this._redraw())},getBounds:function(){return this._bounds||(this._bounds=this._matrix.inverted()._transformBounds(new f(new h,this._viewSize))),this._bounds},getSize:function(){return this.getBounds().getSize(arguments[0])},getCenter:function(){return this.getBounds().getCenter(arguments[0])},setCenter:function(t){t=h.read(arguments),this.scrollBy(t.subtract(this.getCenter()))},getZoom:function(){return this._zoom},setZoom:function(t){this._transform((new g).scale(t/this._zoom,this.getCenter())),this._zoom=t},isVisible:function(){return R.isInView(this._element)},scrollBy:function(){this._transform((new g).translate(h.read(arguments).negate()))},projectToView:function(){return this._matrix._transformPoint(h.read(arguments))},viewToProject:function(){return this._matrix._inverseTransform(h.read(arguments))}},{statics:{_views:[],_viewsById:{},_id:0,create:function(t){return"string"==typeof t&&(t=document.getElementById(t)),new Z(t)}}},new function(){function t(t){var e=V.getTarget(t);return e.getAttribute&&H._viewsById[e.getAttribute("id")]}function e(t,e){return t.viewToProject(V.getOffset(e,t._element))}function n(){if(!H._focused||!H._focused.isVisible())for(var t=0,e=H._views.length;e>t;t++){var n=H._views[t];if(n&&n.isVisible()){H._focused=u=n;break}}}function i(n){var i=H._focused=t(n),r=e(i,n);l=!0,i._onMouseDown&&i._onMouseDown(n,r),(o=i._scope._tool)&&o._onHandleEvent("mousedown",r,n),i.draw(!0)}function r(i){var r;if(l||(r=t(i),r?(h=H._focused,H._focused=u=r):u&&u==H._focused&&(H._focused=h,n())),r=r||H._focused){var s=i&&e(r,i);r._onMouseMove&&r._onMouseMove(i,s),(o=r._scope._tool)&&o._onHandleEvent(l&&o.responds("mousedrag")?"mousedrag":"mousemove",s,i)&&V.stop(i),r.draw(!0)}}function s(t){var n=H._focused;if(n&&l){var i=e(n,t);curPoint=null,l=!1,n._onMouseUp&&n._onMouseUp(t,i),o&&o._onHandleEvent("mouseup",i,t)&&V.stop(t),n.draw(!0)}}function a(t){l&&V.stop(t)}var o,h,u,l=!1;return V.add(document,{mousemove:r,mouseup:s,touchmove:r,touchend:s,selectstart:a,scroll:n}),V.add(window,{load:n}),{_viewHandlers:{mousedown:i,touchstart:i,selectstart:a},statics:{updateFocus:n}}}),Z=H.extend({_class:"CanvasView",initialize:function(t){if(!(t instanceof HTMLCanvasElement)){var e=c.read(arguments);if(e.isZero())throw Error("Cannot create CanvasView with the provided arguments: "+arguments);t=Q.getCanvas(e)}var n=this._context=t.getContext("2d");this._eventCounters={};var i=(window.devicePixelRatio||1)/(R.getPrefixValue(n,"backingStorePixelRatio")||1);if(i>1){var r=t.clientWidth,s=t.clientHeight,a=t.style;t.width=r*i,t.height=s*i,a.width=r+"px",a.height=s+"px",n.scale(i,i)}H.call(this,t)},draw:function(t){if(t&&!this._project._needsRedraw)return!1;var e=this._context,n=this._viewSize;return e.clearRect(0,0,n._width+1,n._height+1),this._project.draw(e,this._matrix),this._project._needsRedraw=!1,!0}},new function(){function t(t,e,n,i,r,s){for(var a,o=i;o;){if(o.responds(t)&&(a||(a=new G(t,e,n,i,r?n.subtract(r):null)),o.fire(t,a)&&(!s||a._stopped)))return!1;o=o.getParent()}return!0}function e(e,n,i,r,s){if(e._eventCounters[n]){var a=e._project,u=a.hitTest(r,{tolerance:a.options.hitTolerance||0,fill:!0,stroke:!0}),l=u&&u.item;if(l)return"mousemove"===n&&l!=o&&(s=r),"mousemove"===n&&h||t(n,i,r,l,s),l}}var n,i,r,s,a,o,h,u,l;return{_onMouseDown:function(t,o){var c=e(this,"mousedown",t,o);u=a==c&&Date.now()-l<300,s=a=c,n=i=r=o,h=s&&s.responds("mousedrag")},_onMouseUp:function(a,o){var c=e(this,"mouseup",a,o);h&&(i&&!i.equals(o)&&t("mousedrag",a,o,s,i),c!=s&&(r=o,t("mousemove",a,o,c,r))),c===s&&(l=Date.now(),(!u||t("doubleclick",a,n,c))&&t("click",a,n,c),u=!1),s=null,h=!1},_onMouseMove:function(n,a){s&&t("mousedrag",n,a,s,i);var h=e(this,"mousemove",n,a,r);i=r=a,h!==o&&(t("mouseleave",n,a,o),o=h,t("mouseenter",n,a,h))}}}),U=e.extend({_class:"Event",initialize:function(t){this.event=t},preventDefault:function(){this._prevented=!0,V.preventDefault(this.event)},stopPropagation:function(){this._stopped=!0,V.stopPropagation(this.event)},stop:function(){this.stopPropagation(),this.preventDefault()},getModifiers:function(){return X.modifiers}}),W=U.extend({_class:"KeyEvent",initialize:function(t,e,n,i){U.call(this,i),this.type=t?"keydown":"keyup",this.key=e,this.character=n},toString:function(){return"{ type: '"+this.type+"', key: '"+this.key+"', character: '"+this.character+"', modifiers: "+this.getModifiers()+" }"}}),X=new function(){function t(t,e,n,r){var s=String.fromCharCode(n),o=i[e]||s.toLowerCase(),h=t?"keydown":"keyup",u=H._focused,l=u&&u.isVisible()&&u._scope,c=l&&l._tool;a[o]=t,c&&c.responds(h)&&(paper=l,c.fire(h,new W(t,o,s,r)),u&&u.draw(!0))}var n,i={8:"backspace",9:"tab",13:"enter",16:"shift",17:"control",18:"option",19:"pause",20:"caps-lock",27:"escape",32:"space",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",46:"delete",91:"command",93:"command",224:"command"},r=e.merge({shift:!1,control:!1,option:!1,command:!1,capsLock:!1,space:!1}),s={},a={};return V.add(document,{keydown:function(a){var o,h=a.which||a.keyCode,u=i[h];u?((o=e.camelize(u))in r&&(r[o]=!0),s[h]=0,t(!0,h,null,a)):n=h},keypress:function(e){if(null!=n){var i=e.which||e.keyCode;s[n]=i,t(!0,n,i,e),n=null}},keyup:function(n){var a,o=n.which||n.keyCode,h=i[o];h&&(a=e.camelize(h))in r&&(r[a]=!1),null!=s[o]&&(t(!1,o,s[o],n),delete s[o])}}),{modifiers:r,isDown:function(t){return!!a[t]}}},G=U.extend({_class:"MouseEvent",initialize:function(t,e,n,i,r){U.call(this,e),this.type=t,this.point=n,this.target=i,this.delta=r},toString:function(){return"{ type: '"+this.type+"', point: "+this.point+", target: "+this.target+(this.delta?", delta: "+this.delta:"")+", modifiers: "+this.getModifiers()+" }"}});e.extend(n,{_class:"Palette",_events:["onChange"],initialize:function(n,i,r){var s=R.find(".palettejs-panel")||R.find("body").appendChild(R.create("div",{"class":"palettejs-panel"}));this._element=s.appendChild(R.create("table",{"class":"palettejs-pane"})),this._title=n,r||(r={});for(var a in this._components=i){var o=i[a];o instanceof J||(null==o.value&&(o.value=r[a]),o.name=a,o=i[a]=new J(o)),this._element.appendChild(o._element),o._palette=this,r[a]===t&&(r[a]=o.value)}this._values=e.each(r,function(t,n){var s=i[n];s&&e.define(r,n,{enumerable:!0,configurable:!0,get:function(){return s._value},set:function(t){s.setValue(t)}})}),window.paper&&paper.palettes.push(this)},reset:function(){for(var t in this._components)this._components[t].reset()},remove:function(){R.remove(this._element)}});var J=e.extend(n,{_class:"Component",_events:["onChange","onClick"],_types:{"boolean":{type:"checkbox",value:"checked"},string:{type:"text"},number:{type:"number",number:!0},button:{type:"button"},text:{tag:"div",value:"text"},slider:{type:"range",number:!0},list:{tag:"select",options:function(){R.removeChildren(this._inputItem),R.create(e.each(this._options,function(t){this.push("option",{value:t,text:t})},[]),this._inputItem)}}},initialize:function(t){this._type=t.type in this._types?t.type:"options"in t?"list":"onClick"in t?"button":typeof t.value,this._info=this._types[this._type]||{type:this._type};var n=this,i=!0;this._inputItem=R.create(this._info.tag||"input",{type:this._info.type,events:{change:function(){n.setValue(R.get(this,n._info.value||"value"),i)},click:function(){n.fire("click")}}}),this.attach("change",function(t){i||this._palette.fire("change",this,this.name,t)}),this._element=R.create("tr",[this._labelItem=R.create("td"),"td",[this._inputItem]]),e.each(t,function(t,e){this[e]=t},this),this._defaultValue=this._value,i=!1},getType:function(){return this._type},getLabel:function(){return this._label},setLabel:function(t){this._label=t,R.set(this._labelItem,"text",t+":")},getOptions:function(){return this._options},setOptions:function(t){this._options=t,this._info.options&&this._info.options.call(this)},getValue:function(){return this._value},setValue:function(t,e){var n=this._info.value||"value";R.set(this._inputItem,n,t),t=R.get(this._inputItem,n),this._info.number&&(t=parseFloat(t,10)),this._value!==t&&(this._value=t,e||this.fire("change",t))},getRange:function(){return[parseFloat(R.get(this._inputItem,"min")),parseFloat(R.get(this._inputItem,"max"))]},setRange:function(t,e){var n=Array.isArray(t)?t:[t,e];R.set(this._inputItem,{min:n[0],max:n[1]})},getMin:function(){return this.getRange()[0]},setMin:function(t){this.setRange(t,this.getMax())},getMax:function(){return this.getRange()[1]},setMax:function(t){this.setRange(this.getMin(),t)},getStep:function(){return parseFloat(R.get(this._inputItem,"step"))},setStep:function(t){R.set(this._inputItem,"step",t)},reset:function(){this.setValue(this._defaultValue)}}),$=U.extend({_class:"ToolEvent",_item:null,initialize:function(t,e,n){this.tool=t,this.type=e,this.event=n},_choosePoint:function(t,e){return t?t:e?e.clone():null},getPoint:function(){return this._choosePoint(this._point,this.tool._point)},setPoint:function(t){this._point=t},getLastPoint:function(){return this._choosePoint(this._lastPoint,this.tool._lastPoint)},setLastPoint:function(t){this._lastPoint=t},getDownPoint:function(){return this._choosePoint(this._downPoint,this.tool._downPoint)},setDownPoint:function(t){this._downPoint=t},getMiddlePoint:function(){return!this._middlePoint&&this.tool._lastPoint?this.tool._point.add(this.tool._lastPoint).divide(2):this._middlePoint},setMiddlePoint:function(t){this._middlePoint=t},getDelta:function(){return!this._delta&&this.tool._lastPoint?this.tool._point.subtract(this.tool._lastPoint):this._delta},setDelta:function(t){this._delta=t},getCount:function(){return/^mouse(down|up)$/.test(this.type)?this.tool._downCount:this.tool._count},setCount:function(t){this.tool[/^mouse(down|up)$/.test(this.type)?"downCount":"count"]=t},getItem:function(){if(!this._item){var t=this.tool._scope.project.hitTest(this.getPoint());if(t){for(var e=t.item,n=e._parent;/^(group|compound-path)$/.test(n._type);)e=n,n=n._parent;this._item=e}}return this._item},setItem:function(t){this._item=t},toString:function(){return"{ type: "+this.type+", point: "+this.getPoint()+", count: "+this.getCount()+", modifiers: "+this.getModifiers()+" }"}}),Y=s.extend({_class:"Tool",_list:"tools",_reference:"_tool",_events:["onActivate","onDeactivate","onEditOptions","onMouseDown","onMouseUp","onMouseDrag","onMouseMove","onKeyDown","onKeyUp"],initialize:function(t){s.call(this),this._firstMove=!0,this._count=0,this._downCount=0,this._set(t)},getMinDistance:function(){return this._minDistance},setMinDistance:function(t){this._minDistance=t,null!=this._minDistance&&null!=this._maxDistance&&this._minDistance>this._maxDistance&&(this._maxDistance=this._minDistance)},getMaxDistance:function(){return this._maxDistance},setMaxDistance:function(t){this._maxDistance=t,null!=this._minDistance&&null!=this._maxDistance&&this._maxDistanceu)return!1;var l=null!=i?i:0;if(0!=l)if(u>l)e=this._point.add(h.normalize(l));else if(a)return!1}if(s&&e.equals(this._point))return!1}switch(this._lastPoint=r&&"mousemove"==t?e:this._point,this._point=e,t){case"mousedown":this._lastPoint=this._downPoint,this._downPoint=this._point,this._downCount++;break;case"mouseup":this._lastPoint=this._downPoint}return this._count=r?0:this._count+1,!0},_fireEvent:function(t,e){var n=paper.project._removeSets;if(n){"mouseup"===t&&(n.mousedrag=null);var i=n[t];if(i){for(var r in i){var s=i[r];for(var a in n){var o=n[a];o&&o!=i&&delete o[s._id]}s.remove()}n[t]=null}}return this.responds(t)&&this.fire(t,new $(this,t,e))},_onHandleEvent:function(t,e,n){paper=this._scope;var i=!1;switch(t){case"mousedown":this._updateEvent(t,e,null,null,!0,!1,!1),i=this._fireEvent(t,n);break;case"mousedrag":for(var r=!1,s=!1;this._updateEvent(t,e,this.minDistance,this.maxDistance,!1,r,s);)i=this._fireEvent(t,n)||i,r=!0,s=!0;break;case"mouseup":!e.equals(this._point)&&this._updateEvent("mousedrag",e,this.minDistance,this.maxDistance,!1,!1,!1)&&(i=this._fireEvent("mousedrag",n)),this._updateEvent(t,e,null,this.maxDistance,!1,!1,!1),i=this._fireEvent(t,n)||i,this._updateEvent(t,e,null,null,!0,!1,!1),this._firstMove=!0;break;case"mousemove":for(;this._updateEvent(t,e,this.minDistance,this.maxDistance,this._firstMove,!0,!1);)i=this._fireEvent(t,n)||i,this._firstMove=!1}return i}}),K={request:function(t,e,n){var i=new(window.ActiveXObject||XMLHttpRequest)("Microsoft.XMLHTTP");return i.open(t.toUpperCase(),e,!0),"overrideMimeType"in i&&i.overrideMimeType("text/plain"),i.onreadystatechange=function(){if(4===i.readyState){var t=i.status;if(0!==t&&200!==t)throw Error("Could not load "+e+" (Error "+t+")");n.call(i,i.responseText)}},i.send(null)}},Q={canvases:[],getCanvas:function(e,n){var i,r=n===t?e:new c(e,n),s=!0;i=this.canvases.length?this.canvases.pop():document.createElement("canvas");var a=i.getContext("2d");return a.save(),i.width===r.width&&i.height===r.height?s&&a.clearRect(0,0,r.width+1,r.height+1):(i.width=r.width,i.height=r.height),i},getContext:function(t,e){return this.getCanvas(t,e).getContext("2d")},release:function(t){var e=t.canvas?t.canvas:t;e.getContext("2d").restore(),this.canvases.push(e)}},te=new function(){function t(t,e,n){return.2989*t+.587*e+.114*n}function n(e,n,i,r){var s=r-t(e,n,i);f=e+s,_=n+s,g=i+s;var r=t(f,_,g),a=p(f,_,g),o=v(f,_,g);if(0>a){var h=r-a;f=r+(f-r)*r/h,_=r+(_-r)*r/h,g=r+(g-r)*r/h}if(o>255){var u=255-r,l=o-r;f=r+(f-r)*u/l,_=r+(_-r)*u/l,g=r+(g-r)*u/l}}function i(t,e,n){return v(t,e,n)-p(t,e,n)}function r(t,e,n,i){var r,s=[t,e,n],a=v(t,e,n),o=p(t,e,n);o=o===t?0:o===e?1:2,a=a===t?0:a===e?1:2,r=0===p(o,a)?1===v(o,a)?2:1:0,s[a]>s[o]?(s[r]=(s[r]-s[o])*i/(s[a]-s[o]),s[a]=i):s[r]=s[a]=0,s[o]=0,f=s[0],_=s[1],g=s[2]}var s,a,o,h,u,l,c,d,f,_,g,p=Math.min,v=Math.max,m=Math.abs,y={multiply:function(){f=u*s/255,_=l*a/255,g=c*o/255},screen:function(){f=u+s-u*s/255,_=l+a-l*a/255,g=c+o-c*o/255},overlay:function(){f=128>u?2*u*s/255:255-2*(255-u)*(255-s)/255,_=128>l?2*l*a/255:255-2*(255-l)*(255-a)/255,g=128>c?2*c*o/255:255-2*(255-c)*(255-o)/255},"soft-light":function(){var t=s*u/255;f=t+u*(255-(255-u)*(255-s)/255-t)/255,t=a*l/255,_=t+l*(255-(255-l)*(255-a)/255-t)/255,t=o*c/255,g=t+c*(255-(255-c)*(255-o)/255-t)/255},"hard-light":function(){f=128>s?2*s*u/255:255-2*(255-s)*(255-u)/255,_=128>a?2*a*l/255:255-2*(255-a)*(255-l)/255,g=128>o?2*o*c/255:255-2*(255-o)*(255-c)/255},"color-dodge":function(){f=0===u?0:255===s?255:p(255,255*u/(255-s)),_=0===l?0:255===a?255:p(255,255*l/(255-a)),g=0===c?0:255===o?255:p(255,255*c/(255-o))},"color-burn":function(){f=255===u?255:0===s?0:v(0,255-255*(255-u)/s),_=255===l?255:0===a?0:v(0,255-255*(255-l)/a),g=255===c?255:0===o?0:v(0,255-255*(255-c)/o)},darken:function(){f=s>u?u:s,_=a>l?l:a,g=o>c?c:o},lighten:function(){f=u>s?u:s,_=l>a?l:a,g=c>o?c:o},difference:function(){f=u-s,0>f&&(f=-f),_=l-a,0>_&&(_=-_),g=c-o,0>g&&(g=-g)},exclusion:function(){f=u+s*(255-u-u)/255,_=l+a*(255-l-l)/255,g=c+o*(255-c-c)/255},hue:function(){r(s,a,o,i(u,l,c)),n(f,_,g,t(u,l,c))},saturation:function(){r(u,l,c,i(s,a,o)),n(f,_,g,t(u,l,c))},luminosity:function(){n(u,l,c,t(s,a,o))},color:function(){n(s,a,o,t(u,l,c))},add:function(){f=p(u+s,255),_=p(l+a,255),g=p(c+o,255)},subtract:function(){f=v(u-s,0),_=v(l-a,0),g=v(c-o,0)},average:function(){f=(u+s)/2,_=(l+a)/2,g=(c+o)/2},negation:function(){f=255-m(255-s-u),_=255-m(255-a-l),g=255-m(255-o-c)}},w=this.nativeModes=e.each(["source-over","source-in","source-out","source-atop","destination-over","destination-in","destination-out","destination-atop","lighter","darker","copy","xor"],function(t){this[t]=!0},{}),x=Q.getContext(1,1);e.each(y,function(t,e){x.save();var n="darken"===e,i=!1;x.fillStyle=n?"#300":"#a00",x.fillRect(0,0,1,1),x.globalCompositeOperation=e,x.globalCompositeOperation===e&&(x.fillStyle=n?"#a00":"#300",x.fillRect(0,0,1,1),i=x.getImageData(0,0,1,1).data[0]!==(n?170:51)),w[e]=i,x.restore()}),Q.release(x),this.process=function(t,e,n,i,r){var p=e.canvas,v="normal"===t;if(v||w[t])n.save(),n.setTransform(1,0,0,1,0,0),n.globalAlpha=i,v||(n.globalCompositeOperation=t),n.drawImage(p,r.x,r.y),n.restore();else{var m=y[t];if(!m)return;for(var x=n.getImageData(r.x,r.y,p.width,p.height),b=x.data,C=e.getImageData(0,0,p.width,p.height).data,S=0,P=b.length;P>S;S+=4){s=C[S],u=b[S],a=C[S+1],l=b[S+1],o=C[S+2],c=b[S+2],h=C[S+3],d=b[S+3],m();var k=h*i/255,z=1-k;b[S]=k*f+z*u,b[S+1]=k*_+z*l,b[S+2]=k*g+z*c,b[S+3]=h*i+z*d}n.putImageData(x,r.x,r.y)}}},ee=e.each({fillColor:["fill","color"],strokeColor:["stroke","color"],strokeWidth:["stroke-width","number"],strokeCap:["stroke-linecap","string"],strokeJoin:["stroke-linejoin","string"],miterLimit:["stroke-miterlimit","number"],dashArray:["stroke-dasharray","array"],dashOffset:["stroke-dashoffset","number"],font:["font-family","string"],fontSize:["font-size","number"],justification:["text-anchor","lookup",{left:"start",center:"middle",right:"end"}],opacity:["opacity","number"],blendMode:["mix-blend-mode","string"]},function(t,n){var i=e.capitalize(n),r=t[2];this[n]={type:t[1],property:n,attribute:t[0],toSVG:r,fromSVG:r&&e.each(r,function(t,e){this[t]=e},{}),get:"get"+i,set:"set"+i}},{}),ne={href:"http://www.w3.org/1999/xlink",xlink:"http://www.w3.org/2000/xmlns"};return new function(){function t(t,e){for(var n in e){var i=e[n],r=ne[n];"number"==typeof i&&(i=S.number(i)),r?t.setAttributeNS(r,n,i):t.setAttribute(n,i)}return t}function n(e,n){return t(document.createElementNS("http://www.w3.org/2000/svg",e),n)}function r(t,e,n){var i=t._matrix,r=i.getTranslation(),s={};if(e){i=i.shiftless();var a=i._inverseTransform(r);s[n?"cx":"x"]=a.x,s[n?"cy":"y"]=a.y,r=null}if(i.isIdentity())return s;var h=i.decompose();if(h&&!h.shearing){var u=[],l=h.rotation,c=h.scaling;r&&!r.isZero()&&u.push("translate("+S.point(r)+")"),o.isZero(c.x-1)&&o.isZero(c.y-1)||u.push("scale("+S.point(c)+")"),l&&u.push("rotate("+S.number(l)+")"),s.transform=u.join(" ")}else s.transform="matrix("+i.getValues().join(",")+")";return s}function s(e,i){for(var s=r(e),a=e._children,o=n("g",s),h=0,u=a.length;u>h;h++){var l=a[h],c=b(l,i);if(c)if(l.isClipMask()){var d=n("clipPath");d.appendChild(c),w(l,d,"clip"),t(o,{"clip-path":"url(#"+d.id+")"})}else o.appendChild(c)}return o}function h(t){var e=r(t,!0),i=t.getSize();return e.x-=i.width/2,e.y-=i.height/2,e.width=i.width,e.height=i.height,e.href=t.toDataURL(),n("image",e)}function u(t,e){if(e.matchShapes){var r=t.toShape(!1);if(r)return c(r,e)}var s,a,o=t._segments;if(0===o.length)return null;if(t.isPolygon())if(o.length>=3){s=t._closed?"polygon":"polyline";var h=[];for(i=0,l=o.length;l>i;i++)h.push(S.point(o[i]._point));a={points:h.join(" ")}}else{s="line";var u=o[0]._point,d=o[o.length-1]._point;a={x1:u.x,y1:u.y,x2:d.x,y2:d.y}}else{s="path";var f=t.getPathData();a=f&&{d:f}}return n(s,a)}function c(t){var e=t._shape,i=t._radius,s=r(t,!0,"rectangle"!==e);if("rectangle"===e){e="rect";var a=t._size,o=a.width,h=a.height;s.x-=o/2,s.y-=h/2,s.width=o,s.height=h,i.isZero()&&(i=null)}return i&&("circle"===e?s.r=i:(s.rx=i.width,s.ry=i.height)),n(e,s)}function d(t){var e=r(t,!0),i=t.getPathData();return i&&(e.d=i),n("path",e)}function f(t,e){var i=r(t,!0),s=t.getSymbol(),a=m(s,"symbol"),o=s.getDefinition(),h=o.getBounds();return a||(a=n("symbol",{viewBox:S.rectangle(h)}),a.appendChild(b(o,e)),w(s,a,"symbol")),i.href="#"+a.id,i.x+=h.x,i.y+=h.y,i.width=S.number(h.width),i.height=S.number(h.height),n("use",i)}function _(t){var e=m(t,"color");if(!e){var i,r=t.getGradient(),s=r._radial,a=t.getOrigin().transform(),o=t.getDestination().transform();if(s){i={cx:a.x,cy:a.y,r:a.getDistance(o)};var h=t.getHighlight();h&&(h=h.transform(),i.fx=h.x,i.fy=h.y)}else i={x1:a.x,y1:a.y,x2:o.x,y2:o.y};i.gradientUnits="userSpaceOnUse",e=n((s?"radial":"linear")+"Gradient",i);for(var u=r._stops,l=0,c=u.length;c>l;l++){var d=u[l],f=d._color,_=f.getAlpha();i={offset:d._rampPoint,"stop-color":f.toCSS(!0)},1>_&&(i["stop-opacity"]=_),e.appendChild(n("stop",i))}w(t,e,"color")}return"url(#"+e.id+")"}function g(t){var e=n("text",r(t,!0));return e.textContent=t._content,e}function p(n,i){var r={},s=n.getParent();return null!=n._name&&(r.id=n._name),e.each(ee,function(t){var i=t.get,a=t.type,o=n[i]();if(!s||!e.equals(s[i](),o)){if("color"===a&&null!=o){var h=o.getAlpha();1>h&&(r[t.attribute+"-opacity"]=h)}r[t.attribute]=null==o?"none":"number"===a?S.number(o):"color"===a?o.gradient?_(o,n):o.toCSS(!0):"array"===a?o.join(","):"lookup"===a?t.toSVG[o]:o +}}),1===r.opacity&&delete r.opacity,null==n._visibility||n._visibility||(r.visibility="hidden"),t(i,r)}function m(t,e){return P||(P={ids:{},svgs:{}}),t&&P.svgs[e+"-"+t._id]}function w(t,e,n){P||m();var i=P.ids[n]=(P.ids[n]||0)+1;e.id=n+"-"+i,P.svgs[n+"-"+t._id]=e}function x(t,e){var i=t,r=null;if(P){i="svg"===t.nodeName.toLowerCase()&&t;for(var s in P.svgs)r||(i||(i=n("svg"),i.appendChild(t)),r=i.insertBefore(n("defs"),i.firstChild)),r.appendChild(P.svgs[s]);P=null}return e.asString?(new XMLSerializer).serializeToString(i):i}function b(t,e){var n=k[t._type],i=n&&n(t,e);return i&&t._data&&i.setAttribute("data-paper-data",JSON.stringify(t._data)),i&&p(t,i)}function C(t){return t||(t={}),S=new a(t.precision),t}var S,P,k={group:s,layer:s,raster:h,path:u,shape:c,"compound-path":d,"placed-symbol":f,"point-text":g};y.inject({exportSVG:function(t){return t=C(t),x(b(this,t),t)}}),v.inject({exportSVG:function(t){t=C(t);for(var e=this.layers,i=this.view.getSize(),r=n("svg",{x:0,y:0,width:i.width,height:i.height,version:"1.1",xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink"}),s=0,a=e.length;a>s;s++)r.appendChild(b(e[s],t));return x(r,t)}})},new function(){function n(t,e,n,i){var r=ne[e],s=r?t.getAttributeNS(r,e):t.getAttribute(e);return"null"===s&&(s=null),null==s?i?null:n?"":0:n?s:parseFloat(s)}function i(t,e,i,r){return e=n(t,e,!1,r),i=n(t,i,!1,r),!r||null!=e&&null!=i?new h(e,i):null}function r(t,e,i,r){return e=n(t,e,!1,r),i=n(t,i,!1,r),!r||null!=e&&null!=i?new c(e,i):null}function s(t,e,n){return"none"===t?null:"number"===e?parseFloat(t):"array"===e?t?t.split(/[\s,]+/g).map(parseFloat):[]:"color"===e?S(t)||t:"lookup"===e?n[t]:t}function a(t,e,n,i){var r=t.childNodes,s="clippath"===e,a=new w,o=a._project,h=o._currentStyle,u=[];s||(a._transformContent=!1,a=x(a,t,n),o._currentStyle=a._style.clone());for(var l=0,c=r.length;c>l;l++){var d,f=r[l];1!==f.nodeType||!(d=P(f,!1,i))||d instanceof m||u.push(d)}return a.addChildren(u),s&&(a=x(a.reduce(),t,n)),o._currentStyle=h,(s||"defs"===e)&&(a.remove(),a=null),a}function o(t,e){var n=new O,i=t.points;n.moveTo(i.getItem(0));for(var r=1,s=i.numberOfItems;s>r;r++)n.lineTo(i.getItem(r));return"polygon"===e&&n.closePath(),n}function u(t){var e=t.getAttribute("d"),n=e.match(/m/gi).length>1?new L:new O;return n.setPathData(e),n}function l(t,e){for(var r=t.childNodes,s=[],a=0,o=r.length;o>a;a++){var h=r[a];1===h.nodeType&&s.push(x(new q,h))}var u,l,c,d="radialgradient"===e,f=new N(s,d);return d?(u=i(t,"cx","cy"),l=u.add(n(t,"r"),0),c=i(t,"fx","fy",!0)):(u=i(t,"x1","y1"),l=i(t,"x2","y2")),x(new B(f,u,l,c),t),null}function d(t,e,n,i){for(var r=(i.getAttribute(n)||"").split(/\)\s*/g),s=new g,a=0,o=r.length;o>a;a++){var h=r[a];if(!h)break;for(var u=h.split("("),l=u[0],c=u[1].split(/[\s,]+/g),d=0,f=c.length;f>d;d++)c[d]=parseFloat(c[d]);switch(l){case"matrix":s.concatenate(new g(c[0],c[1],c[2],c[3],c[4],c[5]));break;case"rotate":s.rotate(c[0],c[1],c[2]);break;case"translate":s.translate(c[0],c[1]);break;case"scale":s.scale(c);break;case"skewX":case"skewY":var e=Math.tan(c[0]*Math.PI/180),_="skewX"==l;s.shear(_?e:0,_?0:e)}}t.transform(s)}function _(t,e,n){var i=t["fill-opacity"===n?"getFillColor":"getStrokeColor"]();i&&i.setAlpha(parseFloat(e))}function p(n,i,r){var s=n.attributes[i],a=s&&s.value;if(!a){var o=e.camelize(i);a=n.style[o],a||r.node[o]===r.parent[o]||(a=r.node[o])}return a?"none"===a?null:a:t}function x(n,i,r){var s={node:R.getStyles(i)||{},parent:!r&&R.getStyles(i.parentNode)||{}};return e.each(z,function(r,a){var o=p(i,a,s);o!==t&&(n=e.pick(r(n,o,a,i,s),n))}),n}function S(t){var e=t&&t.match(/\((?:#|)([^)']+)/);return e&&M[e[1]]}function P(t,e,n){if(n||(n={}),"string"==typeof t){if(e&&!/^.*e;e++){var i=s[e];if(i[0]>=t)break;t+=i[1]}return t}function n(n){return t.substring(e(n.range[0]),e(n.range[1]))}function i(n,i){for(var r=e(n.range[0]),a=e(n.range[1]),o=0,h=s.length-1;h>=0;h--)if(r>s[h][0]){o=h+1;break}s.splice(o,0,[r,i.length-a+r]),t=t.substring(0,r)+i+t.substring(a)}function r(t,e){if(t){for(var s in t)if("range"!==s){var a=t[s];if(Array.isArray(a))for(var o=0,h=a.length;h>o;o++)r(a[o],t);else a&&"object"==typeof a&&r(a,t)}switch(t&&t.type){case"BinaryExpression":if(t.operator in binaryOperators&&"Literal"!==t.left.type){var u=n(t.left),l=n(t.right);i(t,"_$_("+u+', "'+t.operator+'", '+l+")")}break;case"AssignmentExpression":if(/^.=$/.test(t.operator)&&"Literal"!==t.left.type){var u=n(t.left),l=n(t.right);i(t,u+" = _$_("+u+', "'+t.operator[0]+'", '+l+")")}break;case"UpdateExpression":if(!(t.prefix||e&&("BinaryExpression"===e.type&&/^[=!<>]/.test(e.operator)||"MemberExpression"===e.type&&e.computed))){var c=n(t.argument);i(t,c+" = _$_("+c+', "'+t.operator[0]+'", 1)')}break;case"UnaryExpression":if(t.operator in unaryOperators&&"Literal"!==t.argument.type){var c=n(t.argument);i(t,'$_("'+t.operator+'", '+c+")")}}}}var s=[];return r(scope.acorn.parse(t,{ranges:!0})),t}function evaluate(code,scope){paper=scope;var view=scope.project&&scope.project.view,res;with(scope)!function(){var onActivate,onDeactivate,onEditOptions,onMouseDown,onMouseUp,onMouseDrag,onMouseMove,onKeyDown,onKeyUp,onFrame,onResize;res=eval(compile(code)),/on(?:Key|Mouse)(?:Up|Down|Move|Drag)/.test(code)&&Base.each(paper.Tool.prototype._events,function(key){var value=eval(key);value&&(scope.getTool()[key]=value)}),view&&(view.setOnResize(onResize),view.fire("resize",{size:view.size,delta:new Point}),view.setOnFrame(onFrame),view.draw())}.call(scope);return res}function load(){for(var t=document.getElementsByTagName("script"),e=0,n=t.length;n>e;e++){var i=t[e];if(/^text\/(?:x-|)paperscript$/.test(i.type)&&!i.getAttribute("data-paper-ignore")){var r=PaperScope.getAttribute(i,"canvas"),s=PaperScope.get(r)||new PaperScope(i).setup(r),a=i.src;a?Http.request("get",a,function(t){evaluate(t,s)}):evaluate(i.innerHTML,s),i.setAttribute("data-paper-ignore",!0)}}}var Base=paper.Base,PaperScope=paper.PaperScope,exports,define,scope=this;!function(t,e){return"object"==typeof exports&&"object"==typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):(e(t.acorn||(t.acorn={})),void 0)}(this,function(t){"use strict";function e(t){ce=t||{};for(var e in ge)Object.prototype.hasOwnProperty.call(ce,e)||(ce[e]=ge[e]);_e=ce.sourceFile||null}function n(t,e){var n=pe(de,t);e+=" ("+n.line+":"+n.column+")";var i=new SyntaxError(e);throw i.pos=t,i.loc=n,i.raisedAt=ve,i}function i(t){function e(t){if(1==t.length)return n+="return str === "+JSON.stringify(t[0])+";";n+="switch(str){";for(var e=0;e3){i.sort(function(t,e){return e.length-t.length}),n+="switch(str.length){";for(var r=0;rve&&10!==n&&13!==n&&8232!==n&&8329!==n;)++ve,n=de.charCodeAt(ve);ce.onComment&&ce.onComment(!1,de.slice(t+2,ve),t,ve,e,ce.locations&&new r)}function u(){for(;fe>ve;){var t=de.charCodeAt(ve);if(32===t)++ve;else if(13===t){++ve;var e=de.charCodeAt(ve);10===e&&++ve,ce.locations&&(++Pe,ke=ve)}else if(10===t)++ve,++Pe,ke=ve;else if(14>t&&t>8)++ve;else if(47===t){var e=de.charCodeAt(ve+1);if(42===e)o();else{if(47!==e)break;h()}}else if(160===t)++ve;else{if(!(t>=5760&&Un.test(String.fromCharCode(t))))break;++ve}}}function l(){var t=de.charCodeAt(ve+1);return t>=48&&57>=t?S(!0):(++ve,a(xn))}function c(){var t=de.charCodeAt(ve+1);return Se?(++ve,x()):61===t?w(Pn,2):w(Cn,1)}function d(){var t=de.charCodeAt(ve+1);return 61===t?w(Pn,2):w(Bn,1)}function f(t){var e=de.charCodeAt(ve+1);return e===t?w(124===t?In:An,2):61===e?w(Pn,2):w(124===t?On:Tn,1)}function _(){var t=de.charCodeAt(ve+1);return 61===t?w(Pn,2):w(Ln,1)}function g(t){var e=de.charCodeAt(ve+1);return e===t?w(zn,2):61===e?w(Pn,2):w(kn,1)}function p(t){var e=de.charCodeAt(ve+1),n=1;return e===t?(n=62===t&&62===de.charCodeAt(ve+2)?3:2,61===de.charCodeAt(ve+n)?w(Pn,n+1):w(Dn,n)):(61===e&&(n=61===de.charCodeAt(ve+2)?3:2),w(jn,n))}function v(t){var e=de.charCodeAt(ve+1);return 61===e?w(En,61===de.charCodeAt(ve+2)?3:2):w(61===t?Sn:Mn,1)}function m(t){switch(t){case 46:return l();case 40:return++ve,a(pn);case 41:return++ve,a(vn);case 59:return++ve,a(yn);case 44:return++ve,a(mn);case 91:return++ve,a(dn);case 93:return++ve,a(fn);case 123:return++ve,a(_n);case 125:return++ve,a(gn);case 58:return++ve,a(wn);case 63:return++ve,a(bn);case 48:var e=de.charCodeAt(ve+1);if(120===e||88===e)return C();case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return S(!1);case 34:case 39:return P(t);case 47:return c(t);case 37:case 42:return d();case 124:case 38:return f(t);case 94:return _();case 43:case 45:return g(t);case 60:case 62:return p(t);case 61:case 33:return v(t);case 126:return w(Mn,1)}return!1}function y(t){if(t?ve=me+1:me=ve,ce.locations&&(we=new r),t)return x();if(ve>=fe)return a(Ne);var e=de.charCodeAt(ve);if(Kn(e)||92===e)return M();var i=m(e);if(i===!1){var s=String.fromCharCode(e);if("\\"===s||Gn.test(s))return M();n(ve,"Unexpected character '"+s+"'")}return i}function w(t,e){var n=de.slice(ve,ve+e);ve+=e,a(t,n)}function x(){for(var t,e,i="",r=ve;;){ve>=fe&&n(r,"Unterminated regular expression");var s=de.charAt(ve);if($n.test(s)&&n(r,"Unterminated regular expression"),t)t=!1;else{if("["===s)e=!0;else if("]"===s&&e)e=!1;else if("/"===s&&!e)break;t="\\"===s}++ve}var i=de.slice(r,ve);++ve;var o=z();return o&&!/^[gmsiy]*$/.test(o)&&n(r,"Invalid regexp flag"),a(je,RegExp(i,o))}function b(t,e){for(var n=ve,i=0,r=0,s=null==e?1/0:e;s>r;++r){var a,o=de.charCodeAt(ve);if(a=o>=97?o-97+10:o>=65?o-65+10:o>=48&&57>=o?o-48:1/0,a>=t)break;++ve,i=i*t+a}return ve===n||null!=e&&ve-n!==e?null:i}function C(){ve+=2;var t=b(16);return null==t&&n(me+2,"Expected hexadecimal number"),Kn(de.charCodeAt(ve))&&n(ve,"Identifier directly after number"),a(Ee,t)}function S(t){var e=ve,i=!1,r=48===de.charCodeAt(ve);t||null!==b(10)||n(e,"Invalid number"),46===de.charCodeAt(ve)&&(++ve,b(10),i=!0);var s=de.charCodeAt(ve);(69===s||101===s)&&(s=de.charCodeAt(++ve),(43===s||45===s)&&++ve,null===b(10)&&n(e,"Invalid number"),i=!0),Kn(de.charCodeAt(ve))&&n(ve,"Identifier directly after number");var o,h=de.slice(e,ve);return i?o=parseFloat(h):r&&1!==h.length?/[89]/.test(h)||Le?n(e,"Invalid number"):o=parseInt(h,8):o=parseInt(h,10),a(Ee,o)}function P(t){ve++;for(var e="";;){ve>=fe&&n(me,"Unterminated string constant");var i=de.charCodeAt(ve);if(i===t)return++ve,a(De,e);if(92===i){i=de.charCodeAt(++ve);var r=/^[0-7]+/.exec(de.slice(ve,ve+3));for(r&&(r=r[0]);r&&parseInt(r,8)>255;)r=r.slice(0,r.length-1);if("0"===r&&(r=null),++ve,r)Le&&n(ve-2,"Octal literal in strict mode"),e+=String.fromCharCode(parseInt(r,8)),ve+=r.length-1;else switch(i){case 110:e+="\n";break;case 114:e+="\r";break;case 120:e+=String.fromCharCode(k(2));break;case 117:e+=String.fromCharCode(k(4));break;case 85:e+=String.fromCharCode(k(8));break;case 116:e+=" ";break;case 98:e+="\b";break;case 118:e+=" ";break;case 102:e+="\f";break;case 48:e+="\0";break;case 13:10===de.charCodeAt(ve)&&++ve;case 10:ce.locations&&(ke=ve,++Pe);break;default:e+=String.fromCharCode(i)}}else(13===i||10===i||8232===i||8329===i)&&n(me,"Unterminated string constant"),e+=String.fromCharCode(i),++ve}}function k(t){var e=b(16,t);return null===e&&n(me,"Bad character escape sequence"),e}function z(){qn=!1;for(var t,e=!0,i=ve;;){var r=de.charCodeAt(ve);if(Qn(r))qn&&(t+=de.charAt(ve)),++ve;else{if(92!==r)break;qn||(t=de.slice(i,ve)),qn=!0,117!=de.charCodeAt(++ve)&&n(ve,"Expecting Unicode escape sequence \\uXXXX"),++ve;var s=k(4),a=String.fromCharCode(s);a||n(ve-1,"Invalid Unicode escape"),(e?Kn(s):Qn(s))||n(ve-4,"Invalid Unicode escape"),t+=a}e=!1}return qn?t:de.slice(i,ve)}function M(){var t=z(),e=Be;return qn||(Zn(t)?e=cn[t]:(ce.forbidReserved&&(3===ce.ecmaVersion?Fn:Rn)(t)||Le&&Vn(t))&&n(me,"The keyword '"+t+"' is reserved")),a(e,t)}function I(){ze=me,Me=ye,Ie=xe,y()}function A(t){for(Le=t,ve=Me;ke>ve;)ke=de.lastIndexOf("\n",ke-2)+1,--Pe;u(),y()}function O(){this.type=null,this.start=me,this.end=null}function L(){this.start=we,this.end=null,null!==_e&&(this.source=_e)}function T(){var t=new O;return ce.locations&&(t.loc=new L),ce.ranges&&(t.range=[me,0]),t}function E(t){var e=new O;return e.start=t.start,ce.locations&&(e.loc=new L,e.loc.start=t.loc.start),ce.ranges&&(e.range=[t.range[0],0]),e}function j(t,e){return t.type=e,t.end=Me,ce.locations&&(t.loc.end=Ie),ce.ranges&&(t.range[1]=Me),t}function D(t){return ce.ecmaVersion>=5&&"ExpressionStatement"===t.type&&"Literal"===t.expression.type&&"use strict"===t.expression.value}function B(t){return be===t?(I(),!0):void 0}function N(){return!ce.strictSemicolons&&(be===Ne||be===gn||$n.test(de.slice(Me,me)))}function q(){B(yn)||N()||R()}function F(t){be===t?I():R()}function R(){n(me,"Unexpected token")}function V(t){"Identifier"!==t.type&&"MemberExpression"!==t.type&&n(t.start,"Assigning to rvalue"),Le&&"Identifier"===t.type&&Hn(t.name)&&n(t.start,"Assigning to "+t.name+" in strict mode")}function H(t){ze=Me=ve,ce.locations&&(Ie=new r),Ae=Le=null,Oe=[],y();var e=t||T(),n=!0;for(t||(e.body=[]);be!==Ne;){var i=Z();e.body.push(i),n&&D(i)&&A(!0),n=!1}return j(e,"Program")}function Z(){be===Cn&&y(!0);var t=be,e=T();switch(t){case qe:case Ve:I();var i=t===qe;B(yn)||N()?e.label=null:be!==Be?R():(e.label=le(),q());for(var r=0;re){var r=E(t);r.left=t,r.operator=Ce,I(),r.right=te(ee(),i,n);var r=j(r,/&&|\|\|/.test(r.operator)?"LogicalExpression":"BinaryExpression");return te(r,e,n)}return t}function ee(){if(be.prefix){var t=T(),e=be.isUpdate;return t.operator=Ce,t.prefix=!0,I(),t.argument=ee(),e?V(t.argument):Le&&"delete"===t.operator&&"Identifier"===t.argument.type&&n(t.start,"Deleting local variable in strict mode"),j(t,e?"UpdateExpression":"UnaryExpression")}for(var i=ne();be.postfix&&!N();){var t=E(i);t.operator=Ce,t.prefix=!1,t.argument=i,V(i),I(),i=j(t,"UpdateExpression")}return i}function ne(){return ie(re())}function ie(t,e){if(B(xn)){var n=E(t);return n.object=t,n.property=le(!0),n.computed=!1,ie(j(n,"MemberExpression"),e)}if(B(dn)){var n=E(t);return n.object=t,n.property=$(),n.computed=!0,F(fn),ie(j(n,"MemberExpression"),e)}if(!e&&B(pn)){var n=E(t);return n.callee=t,n.arguments=ue(vn,!1),ie(j(n,"CallExpression"),e)}return t}function re(){switch(be){case an:var t=T();return I(),j(t,"ThisExpression");case Be:return le();case Ee:case De:case je:var t=T();return t.value=Ce,t.raw=de.slice(me,ye),I(),j(t,"Literal");case on:case hn:case un:var t=T();return t.value=be.atomValue,t.raw=be.keyword,I(),j(t,"Literal");case pn:var e=we,n=me;I();var i=$();return i.start=n,i.end=ye,ce.locations&&(i.loc.start=e,i.loc.end=xe),ce.ranges&&(i.range=[n,ye]),F(vn),i;case dn:var t=T();return I(),t.elements=ue(fn,!0,!0),j(t,"ArrayExpression");case _n:return ae();case Je:var t=T();return I(),he(t,!1);case sn:return se();default:R()}}function se(){var t=T();return I(),t.callee=ie(re(),!0),t.arguments=B(pn)?ue(vn,!1):Te,j(t,"NewExpression")}function ae(){var t=T(),e=!0,i=!1;for(t.properties=[],I();!B(gn);){if(e)e=!1;else if(F(mn),ce.allowTrailingCommas&&B(gn))break;var r,s={key:oe()},a=!1;if(B(wn)?(s.value=$(!0),r=s.kind="init"):ce.ecmaVersion>=5&&"Identifier"===s.key.type&&("get"===s.key.name||"set"===s.key.name)?(a=i=!0,r=s.kind=s.key.name,s.key=oe(),be!==pn&&R(),s.value=he(T(),!1)):R(),"Identifier"===s.key.type&&(Le||i))for(var o=0;oa?t.id:t.params[a];if((Vn(o.name)||Hn(o.name))&&n(o.start,"Defining '"+o.name+"' in strict mode"),a>=0)for(var h=0;a>h;++h)o.name===t.params[h].name&&n(o.start,"Argument name clash in strict mode")}return j(t,e?"FunctionDeclaration":"FunctionExpression")}function ue(t,e,n){for(var i=[],r=!0;!B(t);){if(r)r=!1;else if(F(mn),e&&ce.allowTrailingCommas&&B(t))break;n&&be===mn?i.push(null):i.push($(!0))}return i}function le(t){var e=T();return e.name=be===Be?Ce:t&&!ce.forbidReserved&&be.keyword||R(),I(),j(e,"Identifier")}t.version="0.3.2";var ce,de,fe,_e;t.parse=function(t,n){return de=t+"",fe=de.length,e(n),s(),H(ce.program)};var ge=t.defaultOptions={ecmaVersion:5,strictSemicolons:!1,allowTrailingCommas:!0,forbidReserved:!1,locations:!1,onComment:null,ranges:!1,program:null,sourceFile:null},pe=t.getLineInfo=function(t,e){for(var n=1,i=0;;){Yn.lastIndex=i;var r=Yn.exec(t);if(!(r&&r.indext?36===t:91>t?!0:97>t?95===t:123>t?!0:t>=170&&Gn.test(String.fromCharCode(t)) },Qn=t.isIdentifierChar=function(t){return 48>t?36===t:58>t?!0:65>t?!1:91>t?!0:97>t?95===t:123>t?!0:t>=170&&Jn.test(String.fromCharCode(t))},ti={kind:"loop"},ei={kind:"switch"}});var binaryOperators={"+":"_add","-":"_subtract","*":"_multiply","/":"_divide","%":"_modulo","==":"equals","!=":"equals"},unaryOperators={"-":"_negate","+":null},fields=Base.each("add,subtract,multiply,divide,modulo,negate".split(","),function(t){this["_"+t]="#"+t},{});return paper.Point.inject(fields),paper.Size.inject(fields),paper.Color.inject(fields),"complete"===document.readyState?setTimeout(load):paper.DomEvent.add(window,{load:load}),{compile:compile,evaluate:evaluate,load:load}}(this); \ No newline at end of file diff --git a/dist/paper-node.js b/dist/paper-node.js index a2e8c274..2abad25a 100644 --- a/dist/paper-node.js +++ b/dist/paper-node.js @@ -1,5 +1,5 @@ /*! - * Paper.js v0.9.10 - The Swiss Army Knife of Vector Graphics Scripting. + * Paper.js v0.9.11 - The Swiss Army Knife of Vector Graphics Scripting. * http://paperjs.org/ * * Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey @@ -9,7 +9,7 @@ * * All rights reserved. * - * Date: Tue Oct 29 21:56:00 2013 +0100 + * Date: Sat Nov 2 21:26:32 2013 +0100 * *** * @@ -466,31 +466,33 @@ Base.inject({ : res; }, - deserialize: function(obj, data) { - var res = obj; - data = data || {}; - if (Array.isArray(obj)) { - var type = obj[0], + deserialize: function(json, target, _data) { + var res = json; + _data = _data || {}; + if (Array.isArray(json)) { + var type = json[0], isDictionary = type === 'dictionary'; if (!isDictionary) { - if (data.dictionary && obj.length == 1 && /^#/.test(type)) - return data.dictionary[type]; + if (_data.dictionary && json.length == 1 && /^#/.test(type)) + return _data.dictionary[type]; type = Base.exports[type]; } res = []; - for (var i = type ? 1 : 0, l = obj.length; i < l; i++) - res.push(Base.deserialize(obj[i], data)); + for (var i = type ? 1 : 0, l = json.length; i < l; i++) + res.push(Base.deserialize(json[i], null, _data)); if (isDictionary) { - data.dictionary = res[0]; + _data.dictionary = res[0]; } else if (type) { var args = res; - res = Base.create(type.prototype); + res = target instanceof type + ? target + : Base.create(type.prototype); type.apply(res, args); } - } else if (Base.isPlainObject(obj)) { + } else if (Base.isPlainObject(json)) { res = {}; - for (var key in obj) - res[key] = Base.deserialize(obj[key], data); + for (var key in json) + res[key] = Base.deserialize(json[key], null, _data); } return res; }, @@ -499,9 +501,9 @@ Base.inject({ return JSON.stringify(Base.serialize(obj, options)); }, - importJSON: function(json) { + importJSON: function(json, target) { return Base.deserialize( - typeof json === 'string' ? JSON.parse(json) : json); + typeof json === 'string' ? JSON.parse(json) : json, target); }, splice: function(list, items, index, remove) { @@ -682,7 +684,7 @@ var PaperScope = Base.extend({ } }, - version: '0.9.10', + version: '0.9.11', getView: function() { return this.project && this.project.view; @@ -694,6 +696,10 @@ var PaperScope = Base.extend({ return this._tool; }, + getPaper: function() { + return this; + }, + evaluate: function(code) { var res = paper.PaperScript.evaluate(code, this); View.updateFocus(); @@ -2009,10 +2015,10 @@ var Matrix = Base.extend({ return !this._getDeterminant(); }, - transform: function( src, srcOff, dst, dstOff, numPts) { + transform: function( src, srcOffset, dst, dstOffset, count) { return arguments.length < 5 ? this._transformPoint(Point.read(arguments)) - : this._transformCoordinates(src, srcOff, dst, dstOff, numPts); + : this._transformCoordinates(src, srcOffset, dst, dstOffset, count); }, _transformPoint: function(point, dest, dontNotify) { @@ -2027,10 +2033,11 @@ var Matrix = Base.extend({ ); }, - _transformCoordinates: function(src, srcOff, dst, dstOff, numPts) { - var i = srcOff, j = dstOff, - srcEnd = srcOff + 2 * numPts; - while (i < srcEnd) { + _transformCoordinates: function(src, srcOffset, dst, dstOffset, count) { + var i = srcOffset, + j = dstOffset, + max = i + 2 * count; + while (i < max) { var x = src[i++], y = src[i++]; dst[j++] = x * this._a + y * this._b + this._tx; @@ -2736,6 +2743,10 @@ var Item = Base.extend(Callback, { hasStroke: function() { return this.getStyle().hasStroke(); + }, + + hasShadow: function() { + return this.getStyle().hasShadow(); } }, Base.each(['locked', 'visible', 'blendMode', 'opacity', 'guide'], function(name) { @@ -3251,7 +3262,10 @@ var Item = Base.extend(Callback, { }, { importJSON: function(json) { - return this.addChild(Base.importJSON(json)); + var res = Base.importJSON(json, this); + return res !== this + ? this.addChild(res) + : res; }, addChild: function(item, _preserve) { @@ -3387,6 +3401,8 @@ var Item = Base.extend(Callback, { return removed; }, + clear: '#removeChildren', + reverseChildren: function() { if (this._children) { this._children.reverse(); @@ -3561,43 +3577,49 @@ var Item = Base.extend(Callback, { _setStyles: function(ctx) { var style = this._style, - matrix = this._matrix, - strokeWidth = style.getStrokeWidth(), fillColor = style.getFillColor(), strokeColor = style.getStrokeColor(), shadowColor = style.getShadowColor(); if (fillColor) - ctx.fillStyle = fillColor.toCanvasStyle(ctx, matrix); - if (strokeColor && strokeWidth > 0) { - ctx.strokeStyle = strokeColor.toCanvasStyle(ctx, matrix); - ctx.lineWidth = strokeWidth; - var strokeJoin = style.getStrokeJoin(), - strokeCap = style.getStrokeCap(), - miterLimit = style.getMiterLimit(), - dashArray = style.getDashArray(), - dashOffset = style.getDashOffset(); - if (strokeJoin) - ctx.lineJoin = strokeJoin; - if (strokeCap) - ctx.lineCap = strokeCap; - if (miterLimit) - ctx.miterLimit = miterLimit; - if (paper.support.nativeDash && dashArray && dashArray.length) { - if ('setLineDash' in ctx) { - ctx.setLineDash(dashArray); - ctx.lineDashOffset = dashOffset; - } else { - ctx.mozDash = dashArray; - ctx.mozDashOffset = dashOffset; + ctx.fillStyle = fillColor.toCanvasStyle(ctx); + if (strokeColor) { + var strokeWidth = style.getStrokeWidth(); + if (strokeWidth > 0) { + ctx.strokeStyle = strokeColor.toCanvasStyle(ctx); + ctx.lineWidth = strokeWidth; + var strokeJoin = style.getStrokeJoin(), + strokeCap = style.getStrokeCap(), + miterLimit = style.getMiterLimit(); + if (strokeJoin) + ctx.lineJoin = strokeJoin; + if (strokeCap) + ctx.lineCap = strokeCap; + if (miterLimit) + ctx.miterLimit = miterLimit; + if (paper.support.nativeDash) { + var dashArray = style.getDashArray(), + dashOffset = style.getDashOffset(); + if (dashArray && dashArray.length) { + if ('setLineDash' in ctx) { + ctx.setLineDash(dashArray); + ctx.lineDashOffset = dashOffset; + } else { + ctx.mozDash = dashArray; + ctx.mozDashOffset = dashOffset; + } + } } } } if (shadowColor) { - ctx.shadowColor = shadowColor.toCanvasStyle(ctx); - ctx.shadowBlur = style.getShadowBlur(); - var offset = this.getShadowOffset(); - ctx.shadowOffsetX = offset.x; - ctx.shadowOffsetY = offset.y; + var shadowBlur = style.getShadowBlur(); + if (shadowBlur > 0) { + ctx.shadowColor = shadowColor.toCanvasStyle(ctx); + ctx.shadowBlur = shadowBlur; + var offset = this.getShadowOffset(); + ctx.shadowOffsetX = offset.x; + ctx.shadowOffsetY = offset.y; + } } }, @@ -3894,8 +3916,8 @@ var Shape = Item.extend({ radius: this._radius, insert: false }); - path.transform(this._matrix); path.setStyle(this._style); + path.transform(this._matrix); if (insert || insert === undefined) path.insertAbove(this); return path; @@ -3951,8 +3973,10 @@ var Shape = Item.extend({ } if (!clip && (hasFill || hasStroke)) { this._setStyles(ctx); - if (hasFill) + if (hasFill) { ctx.fill(style.getWindingRule()); + ctx.shadowColor = 'rgba(0,0,0,0)'; + } if (hasStroke) ctx.stroke(); } @@ -5893,7 +5917,7 @@ var PathItem = Item.extend({ setPathData: function(data) { - var parts = data.match(/[a-z][^a-z]*/ig), + var parts = data.match(/[mlhvcsqtaz][^mlhvcsqtaz]*/ig), coords, relative = false, control, @@ -5915,18 +5939,15 @@ var PathItem = Item.extend({ ); } - if (this._type === 'path') - this.removeSegments(); - else - this.removeChildren(); + this.clear(); for (var i = 0, l = parts.length; i < l; i++) { var part = parts[i], cmd = part[0], lower = cmd.toLowerCase(); - coords = part.slice(1).trim().split(/[\s,]+|(?=[+-])/); + coords = part.match(/[+-]?(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?/g); + var length = coords && coords.length; relative = cmd === lower; - var length = coords.length; switch (lower) { case 'm': case 'l': @@ -6285,6 +6306,8 @@ var Path = PathItem.extend({ return removed; }, + clear: '#removeSegments', + isFullySelected: function() { var length = this._segments.length; return this._selected && length > 0 && this._selectedSegmentState @@ -6880,8 +6903,10 @@ var Path = PathItem.extend({ if (!clip && !compound && (hasFill || hasStroke)) { this._setStyles(ctx); - if (hasFill) + if (hasFill) { ctx.fill(style.getWindingRule()); + ctx.shadowColor = 'rgba(0,0,0,0)'; + } if (hasStroke) { if (dashLength) { ctx.beginPath(); @@ -7038,16 +7063,16 @@ var Path = PathItem.extend({ cubicCurveTo: function() { var handle1 = Point.read(arguments), handle2 = Point.read(arguments), - to = Point.read(arguments); - var current = getCurrentSegment(this); + to = Point.read(arguments), + current = getCurrentSegment(this); current.setHandleOut(handle1.subtract(current._point)); this._add([ new Segment(to, handle2.subtract(to)) ]); }, quadraticCurveTo: function() { var handle = Point.read(arguments), - to = Point.read(arguments); - var current = getCurrentSegment(this)._point; + to = Point.read(arguments), + current = getCurrentSegment(this)._point; this.cubicCurveTo( handle.add(current.subtract(handle).multiply(1 / 3)), handle.add(to.subtract(handle).multiply(1 / 3)), @@ -7126,25 +7151,41 @@ var Path = PathItem.extend({ this._add(segments); }, - lineBy: function(vector) { - vector = Point.read(arguments); - var current = getCurrentSegment(this); - this.lineTo(current._point.add(vector)); + lineBy: function() { + var to = Point.read(arguments), + current = getCurrentSegment(this)._point; + this.lineTo(current.add(to)); }, - curveBy: function(throughVector, toVector, parameter) { - throughVector = Point.read(throughVector); - toVector = Point.read(toVector); - var current = getCurrentSegment(this)._point; - this.curveTo(current.add(throughVector), current.add(toVector), - parameter); + curveBy: function() { + var through = Point.read(arguments), + to = Point.read(arguments), + parameter = Base.read(arguments), + current = getCurrentSegment(this)._point; + this.curveTo(current.add(through), current.add(to), parameter); }, - arcBy: function(throughVector, toVector) { - throughVector = Point.read(throughVector); - toVector = Point.read(toVector); - var current = getCurrentSegment(this)._point; - this.arcTo(current.add(throughVector), current.add(toVector)); + cubicCurveBy: function() { + var handle1 = Point.read(arguments), + handle2 = Point.read(arguments), + to = Point.read(arguments), + current = getCurrentSegment(this)._point; + this.cubicCurveTo(current.add(handle1), current.add(handle2), + current.add(to)); + }, + + quadraticCurveBy: function() { + var handle = Point.read(arguments), + to = Point.read(arguments), + current = getCurrentSegment(this)._point; + this.quadraticCurveTo(current.add(handle), current.add(to)); + }, + + arcBy: function() { + var through = Point.read(arguments), + to = Point.read(arguments), + current = getCurrentSegment(this)._point; + this.arcTo(current.add(through), current.add(to)); }, closePath: function() { @@ -7625,8 +7666,10 @@ var CompoundPath = PathItem.extend({ if (!param.clip) { this._setStyles(ctx); var style = this._style; - if (style.hasFill()) + if (style.hasFill()) { ctx.fill(style.getWindingRule()); + ctx.shadowColor = 'rgba(0,0,0,0)'; + } if (style.hasStroke()) ctx.stroke(); } @@ -7655,13 +7698,15 @@ var CompoundPath = PathItem.extend({ } }; - Base.each(['lineTo', 'cubicCurveTo', 'quadraticCurveTo', 'curveTo', - 'arcTo', 'lineBy', 'curveBy', 'arcBy'], function(key) { - fields[key] = function() { - var path = getCurrentPath(this); - path[key].apply(path, arguments); - }; - }); + Base.each(['lineTo', 'cubicCurveTo', 'quadraticCurveTo', 'curveTo', 'arcTo', + 'lineBy', 'cubicCurveBy', 'quadraticCurveBy', 'curveBy', 'arcBy'], + function(key) { + fields[key] = function() { + var path = getCurrentPath(this); + path[key].apply(path, arguments); + }; + } + ); return fields; }); @@ -8193,13 +8238,18 @@ var PointText = TextItem.extend({ this._setStyles(ctx); var style = this._style, lines = this._lines, - leading = style.getLeading(); + leading = style.getLeading(), + shadowColor = ctx.shadowColor; + ctx.font = style.getFontStyle(); ctx.textAlign = style.getJustification(); for (var i = 0, l = lines.length; i < l; i++) { + ctx.shadowColor = shadowColor; var line = lines[i]; - if (style.hasFill()) + if (style.hasFill()) { ctx.fillText(line, 0, 0); + ctx.shadowColor = 'rgba(0,0,0,0)'; + } if (style.hasStroke()) ctx.strokeText(line, 0, 0); ctx.translate(0, leading); @@ -8578,7 +8628,7 @@ var Color = Base.extend(new function() { }, clone: function() { - return new Color(this._type, this._components.slice(), this._alpha); + return new Color(this); }, _convert: function(type) { @@ -8666,23 +8716,21 @@ var Color = Base.extend(new function() { + components.join(',') + ')'; }, - toCanvasStyle: function(ctx, matrix) { + toCanvasStyle: function(ctx) { if (this._canvasStyle) return this._canvasStyle; if (this._type !== 'gradient') return this._canvasStyle = this.toCSS(); var components = this._components, - translation = matrix ? matrix.getTranslation() : new Point(), gradient = components[0], stops = gradient._stops, - origin = components[1].subtract(translation), - destination = components[2].subtract(translation), + origin = components[1], + destination = components[2], canvasGradient; if (gradient._radial) { var radius = destination.getDistance(origin), highlight = components[3]; if (highlight) { - highlight = highlight.subtract(translation); var vector = highlight.subtract(origin); if (vector.getLength() > radius) highlight = origin.add(vector.normalize(radius - 0.1)); @@ -9008,8 +9056,11 @@ var Style = Base.extend(new function() { if (isColor) { if (old) delete old._owner; - if (value && value.constructor === Color) + if (value && value.constructor === Color) { + if (value._owner) + value = value.clone(); value._owner = this._item; + } } this._values[key] = value; if (this._item) @@ -9099,6 +9150,10 @@ var Style = Base.extend(new function() { return !!this.getStrokeColor() && this.getStrokeWidth() > 0; }, + hasShadow: function() { + return !!this.getShadowColor() && this.getShadowBlur() > 0; + }, + getLeading: function getLeading() { var leading = getLeading.base.call(this); return leading != null ? leading : this.getFontSize() * 1.2; @@ -10109,13 +10164,13 @@ new function() { return attrs; } - function exportGroup(item) { + function exportGroup(item, options) { var attrs = getTransform(item), children = item._children; var node = createElement('g', attrs); for (var i = 0, l = children.length; i < l; i++) { var child = children[i]; - var childNode = exportSVG(child); + var childNode = exportSVG(child, options); if (childNode) { if (child.isClipMask()) { var clip = createElement('clipPath'); @@ -10143,7 +10198,12 @@ new function() { return createElement('image', attrs); } - function exportPath(item) { + function exportPath(item, options) { + if (options.matchShapes) { + var shape = item.toShape(false); + if (shape) + return exportShape(shape, options); + } var segments = item._segments, type, attrs; @@ -10179,7 +10239,6 @@ new function() { function exportShape(item) { var shape = item._shape, - center = item.getPosition(true), radius = item._radius, attrs = getTransform(item, true, shape !== 'rectangle'); if (shape === 'rectangle') { @@ -10213,7 +10272,7 @@ new function() { return createElement('path', attrs); } - function exportPlacedSymbol(item) { + function exportPlacedSymbol(item, options) { var attrs = getTransform(item, true), symbol = item.getSymbol(), symbolNode = getDefinition(symbol, 'symbol'), @@ -10223,7 +10282,7 @@ new function() { symbolNode = createElement('symbol', { viewBox: formatter.rectangle(bounds) }); - symbolNode.appendChild(exportSVG(definition)); + symbolNode.appendChild(exportSVG(definition, options)); setDefinition(symbol, symbolNode, 'symbol'); } attrs.href = '#' + symbolNode.id; @@ -10234,7 +10293,7 @@ new function() { return createElement('use', attrs); } - function exportGradient(color, item) { + function exportGradient(color) { var gradientNode = getDefinition(color, 'color'); if (!gradientNode) { var gradient = color.getGradient(), @@ -10358,29 +10417,31 @@ new function() { } function exportDefinitions(node, options) { - if (!definitions) - return node; - var svg = node.nodeName.toLowerCase() === 'svg' && node, + var svg = node, defs = null; - for (var i in definitions.svgs) { - if (!defs) { - if (!svg) { - svg = createElement('svg'); - svg.appendChild(node); + if (definitions) { + svg = node.nodeName.toLowerCase() === 'svg' && node; + for (var i in definitions.svgs) { + if (!defs) { + if (!svg) { + svg = createElement('svg'); + svg.appendChild(node); + } + defs = svg.insertBefore(createElement('defs'), + svg.firstChild); } - defs = svg.insertBefore(createElement('defs'), svg.firstChild); + defs.appendChild(definitions.svgs[i]); } - defs.appendChild(definitions.svgs[i]); + definitions = null; } - definitions = null; return options.asString ? new XMLSerializer().serializeToString(svg) : svg; } - function exportSVG(item) { + function exportSVG(item, options) { var exporter = exporters[item._type], - node = exporter && exporter(item, item._type); + node = exporter && exporter(item, options); if (node && item._data) node.setAttribute('data-paper-data', JSON.stringify(item._data)); return node && applyStyle(item, node); @@ -10396,7 +10457,7 @@ new function() { Item.inject({ exportSVG: function(options) { options = setOptions(options); - return exportDefinitions(exportSVG(this), options); + return exportDefinitions(exportSVG(this, options), options); } }); @@ -10415,7 +10476,7 @@ new function() { 'xmlns:xlink': 'http://www.w3.org/1999/xlink' }); for (var i = 0, l = layers.length; i < l; i++) - node.appendChild(exportSVG(layers[i])); + node.appendChild(exportSVG(layers[i], options)); return exportDefinitions(node, options); } }); @@ -10444,15 +10505,15 @@ new function() { function getPoint(node, x, y, allowNull) { x = getValue(node, x, false, allowNull); y = getValue(node, y, false, allowNull); - return allowNull && x == null && y == null ? null - : new Point(x || 0, y || 0); + return allowNull && (x == null || y == null) ? null + : new Point(x, y); } function getSize(node, w, h, allowNull) { w = getValue(node, w, false, allowNull); h = getValue(node, h, false, allowNull); - return allowNull && w == null && h == null ? null - : new Size(w || 0, h || 0); + return allowNull && (w == null || h == null) ? null + : new Size(w, h); } function convertValue(value, type, lookup) { @@ -10469,7 +10530,7 @@ new function() { : value; } - function importGroup(node, type, options) { + function importGroup(node, type, isRoot, options) { var nodes = node.childNodes, clip = type === 'clippath', item = new Group(), @@ -10478,20 +10539,20 @@ new function() { children = []; if (!clip) { item._transformContent = false; - item = applyAttributes(item, node); + item = applyAttributes(item, node, isRoot); project._currentStyle = item._style.clone(); } for (var i = 0, l = nodes.length; i < l; i++) { var childNode = nodes[i], child; if (childNode.nodeType === 1 - && (child = importSVG(childNode, options)) + && (child = importSVG(childNode, false, options)) && !(child instanceof Symbol)) children.push(child); } item.addChildren(children); if (clip) - item = applyAttributes(item.reduce(), node); + item = applyAttributes(item.reduce(), node, isRoot); project._currentStyle = currentStyle; if (clip || type === 'defs') { item.remove(); @@ -10545,8 +10606,8 @@ new function() { } var importers = { - '#document': function(node, type, options) { - return importSVG(node.childNodes[0], options); + '#document': function(node, type, isRoot, options) { + return importSVG(node.childNodes[0], isRoot, options); }, g: importGroup, @@ -10568,8 +10629,8 @@ new function() { return raster; }, - symbol: function(node, type) { - return new Symbol(importGroup(node, type), true); + symbol: function(node, type, isRoot, options) { + return new Symbol(importGroup(node, type, isRoot, options), true); }, defs: importGroup, @@ -10663,8 +10724,13 @@ new function() { var attributes = Base.merge(Base.each(SVGStyles, function(entry) { this[entry.attribute] = function(item, value) { - item[entry.set]( - convertValue(value, entry.type, entry.fromSVG)); + item[entry.set](convertValue(value, entry.type, entry.fromSVG)); + if (entry.type === 'color' && item instanceof Shape) { + var color = item[entry.get](); + if (color) + color.transform(new Matrix().translate( + item.getPosition(true).negate())); + } }; }, {}), { id: function(item, value) { @@ -10750,10 +10816,10 @@ new function() { : value; } - function applyAttributes(item, node) { + function applyAttributes(item, node, isRoot) { var styles = { node: DomElement.getStyles(node) || {}, - parent: DomElement.getStyles(node.parentNode) || {} + parent: !isRoot && DomElement.getStyles(node.parentNode) || {} }; Base.each(attributes, function(apply, name) { var value = getAttribute(node, name, styles); @@ -10769,38 +10835,55 @@ new function() { return match && definitions[match[1]]; } - function importSVG(node, options, clearDefs) { + function importSVG(node, isRoot, options) { if (!options) options = {}; - if (typeof node === 'string') + if (typeof node === 'string') { + if (isRoot && !/^.* 0) { - ctx.strokeStyle = strokeColor.toCanvasStyle(ctx, matrix); - ctx.lineWidth = strokeWidth; - var strokeJoin = style.getStrokeJoin(), - strokeCap = style.getStrokeCap(), - miterLimit = style.getMiterLimit(), - dashArray = style.getDashArray(), - dashOffset = style.getDashOffset(); - if (strokeJoin) - ctx.lineJoin = strokeJoin; - if (strokeCap) - ctx.lineCap = strokeCap; - if (miterLimit) - ctx.miterLimit = miterLimit; - if (paper.support.nativeDash && dashArray && dashArray.length) { - if ('setLineDash' in ctx) { - ctx.setLineDash(dashArray); - ctx.lineDashOffset = dashOffset; - } else { - ctx.mozDash = dashArray; - ctx.mozDashOffset = dashOffset; + ctx.fillStyle = fillColor.toCanvasStyle(ctx); + if (strokeColor) { + var strokeWidth = style.getStrokeWidth(); + if (strokeWidth > 0) { + ctx.strokeStyle = strokeColor.toCanvasStyle(ctx); + ctx.lineWidth = strokeWidth; + var strokeJoin = style.getStrokeJoin(), + strokeCap = style.getStrokeCap(), + miterLimit = style.getMiterLimit(); + if (strokeJoin) + ctx.lineJoin = strokeJoin; + if (strokeCap) + ctx.lineCap = strokeCap; + if (miterLimit) + ctx.miterLimit = miterLimit; + if (paper.support.nativeDash) { + var dashArray = style.getDashArray(), + dashOffset = style.getDashOffset(); + if (dashArray && dashArray.length) { + if ('setLineDash' in ctx) { + ctx.setLineDash(dashArray); + ctx.lineDashOffset = dashOffset; + } else { + ctx.mozDash = dashArray; + ctx.mozDashOffset = dashOffset; + } + } } } } if (shadowColor) { - ctx.shadowColor = shadowColor.toCanvasStyle(ctx); - ctx.shadowBlur = style.getShadowBlur(); - var offset = this.getShadowOffset(); - ctx.shadowOffsetX = offset.x; - ctx.shadowOffsetY = offset.y; + var shadowBlur = style.getShadowBlur(); + if (shadowBlur > 0) { + ctx.shadowColor = shadowColor.toCanvasStyle(ctx); + ctx.shadowBlur = shadowBlur; + var offset = this.getShadowOffset(); + ctx.shadowOffsetX = offset.x; + ctx.shadowOffsetY = offset.y; + } } }, @@ -3894,8 +3916,8 @@ var Shape = Item.extend({ radius: this._radius, insert: false }); - path.transform(this._matrix); path.setStyle(this._style); + path.transform(this._matrix); if (insert || insert === undefined) path.insertAbove(this); return path; @@ -3951,8 +3973,10 @@ var Shape = Item.extend({ } if (!clip && (hasFill || hasStroke)) { this._setStyles(ctx); - if (hasFill) + if (hasFill) { ctx.fill(style.getWindingRule()); + ctx.shadowColor = 'rgba(0,0,0,0)'; + } if (hasStroke) ctx.stroke(); } @@ -5912,7 +5936,7 @@ var PathItem = Item.extend({ setPathData: function(data) { - var parts = data.match(/[a-z][^a-z]*/ig), + var parts = data.match(/[mlhvcsqtaz][^mlhvcsqtaz]*/ig), coords, relative = false, control, @@ -5934,18 +5958,15 @@ var PathItem = Item.extend({ ); } - if (this._type === 'path') - this.removeSegments(); - else - this.removeChildren(); + this.clear(); for (var i = 0, l = parts.length; i < l; i++) { var part = parts[i], cmd = part[0], lower = cmd.toLowerCase(); - coords = part.slice(1).trim().split(/[\s,]+|(?=[+-])/); + coords = part.match(/[+-]?(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?/g); + var length = coords && coords.length; relative = cmd === lower; - var length = coords.length; switch (lower) { case 'm': case 'l': @@ -6304,6 +6325,8 @@ var Path = PathItem.extend({ return removed; }, + clear: '#removeSegments', + isFullySelected: function() { var length = this._segments.length; return this._selected && length > 0 && this._selectedSegmentState @@ -6899,8 +6922,10 @@ var Path = PathItem.extend({ if (!clip && !compound && (hasFill || hasStroke)) { this._setStyles(ctx); - if (hasFill) + if (hasFill) { ctx.fill(style.getWindingRule()); + ctx.shadowColor = 'rgba(0,0,0,0)'; + } if (hasStroke) { if (dashLength) { ctx.beginPath(); @@ -7057,16 +7082,16 @@ var Path = PathItem.extend({ cubicCurveTo: function() { var handle1 = Point.read(arguments), handle2 = Point.read(arguments), - to = Point.read(arguments); - var current = getCurrentSegment(this); + to = Point.read(arguments), + current = getCurrentSegment(this); current.setHandleOut(handle1.subtract(current._point)); this._add([ new Segment(to, handle2.subtract(to)) ]); }, quadraticCurveTo: function() { var handle = Point.read(arguments), - to = Point.read(arguments); - var current = getCurrentSegment(this)._point; + to = Point.read(arguments), + current = getCurrentSegment(this)._point; this.cubicCurveTo( handle.add(current.subtract(handle).multiply(1 / 3)), handle.add(to.subtract(handle).multiply(1 / 3)), @@ -7145,25 +7170,41 @@ var Path = PathItem.extend({ this._add(segments); }, - lineBy: function(vector) { - vector = Point.read(arguments); - var current = getCurrentSegment(this); - this.lineTo(current._point.add(vector)); + lineBy: function() { + var to = Point.read(arguments), + current = getCurrentSegment(this)._point; + this.lineTo(current.add(to)); }, - curveBy: function(throughVector, toVector, parameter) { - throughVector = Point.read(throughVector); - toVector = Point.read(toVector); - var current = getCurrentSegment(this)._point; - this.curveTo(current.add(throughVector), current.add(toVector), - parameter); + curveBy: function() { + var through = Point.read(arguments), + to = Point.read(arguments), + parameter = Base.read(arguments), + current = getCurrentSegment(this)._point; + this.curveTo(current.add(through), current.add(to), parameter); }, - arcBy: function(throughVector, toVector) { - throughVector = Point.read(throughVector); - toVector = Point.read(toVector); - var current = getCurrentSegment(this)._point; - this.arcTo(current.add(throughVector), current.add(toVector)); + cubicCurveBy: function() { + var handle1 = Point.read(arguments), + handle2 = Point.read(arguments), + to = Point.read(arguments), + current = getCurrentSegment(this)._point; + this.cubicCurveTo(current.add(handle1), current.add(handle2), + current.add(to)); + }, + + quadraticCurveBy: function() { + var handle = Point.read(arguments), + to = Point.read(arguments), + current = getCurrentSegment(this)._point; + this.quadraticCurveTo(current.add(handle), current.add(to)); + }, + + arcBy: function() { + var through = Point.read(arguments), + to = Point.read(arguments), + current = getCurrentSegment(this)._point; + this.arcTo(current.add(through), current.add(to)); }, closePath: function() { @@ -7644,8 +7685,10 @@ var CompoundPath = PathItem.extend({ if (!param.clip) { this._setStyles(ctx); var style = this._style; - if (style.hasFill()) + if (style.hasFill()) { ctx.fill(style.getWindingRule()); + ctx.shadowColor = 'rgba(0,0,0,0)'; + } if (style.hasStroke()) ctx.stroke(); } @@ -7674,13 +7717,15 @@ var CompoundPath = PathItem.extend({ } }; - Base.each(['lineTo', 'cubicCurveTo', 'quadraticCurveTo', 'curveTo', - 'arcTo', 'lineBy', 'curveBy', 'arcBy'], function(key) { - fields[key] = function() { - var path = getCurrentPath(this); - path[key].apply(path, arguments); - }; - }); + Base.each(['lineTo', 'cubicCurveTo', 'quadraticCurveTo', 'curveTo', 'arcTo', + 'lineBy', 'cubicCurveBy', 'quadraticCurveBy', 'curveBy', 'arcBy'], + function(key) { + fields[key] = function() { + var path = getCurrentPath(this); + path[key].apply(path, arguments); + }; + } + ); return fields; }); @@ -8212,13 +8257,18 @@ var PointText = TextItem.extend({ this._setStyles(ctx); var style = this._style, lines = this._lines, - leading = style.getLeading(); + leading = style.getLeading(), + shadowColor = ctx.shadowColor; + ctx.font = style.getFontStyle(); ctx.textAlign = style.getJustification(); for (var i = 0, l = lines.length; i < l; i++) { + ctx.shadowColor = shadowColor; var line = lines[i]; - if (style.hasFill()) + if (style.hasFill()) { ctx.fillText(line, 0, 0); + ctx.shadowColor = 'rgba(0,0,0,0)'; + } if (style.hasStroke()) ctx.strokeText(line, 0, 0); ctx.translate(0, leading); @@ -8597,7 +8647,7 @@ var Color = Base.extend(new function() { }, clone: function() { - return new Color(this._type, this._components.slice(), this._alpha); + return new Color(this); }, _convert: function(type) { @@ -8685,23 +8735,21 @@ var Color = Base.extend(new function() { + components.join(',') + ')'; }, - toCanvasStyle: function(ctx, matrix) { + toCanvasStyle: function(ctx) { if (this._canvasStyle) return this._canvasStyle; if (this._type !== 'gradient') return this._canvasStyle = this.toCSS(); var components = this._components, - translation = matrix ? matrix.getTranslation() : new Point(), gradient = components[0], stops = gradient._stops, - origin = components[1].subtract(translation), - destination = components[2].subtract(translation), + origin = components[1], + destination = components[2], canvasGradient; if (gradient._radial) { var radius = destination.getDistance(origin), highlight = components[3]; if (highlight) { - highlight = highlight.subtract(translation); var vector = highlight.subtract(origin); if (vector.getLength() > radius) highlight = origin.add(vector.normalize(radius - 0.1)); @@ -9027,8 +9075,11 @@ var Style = Base.extend(new function() { if (isColor) { if (old) delete old._owner; - if (value && value.constructor === Color) + if (value && value.constructor === Color) { + if (value._owner) + value = value.clone(); value._owner = this._item; + } } this._values[key] = value; if (this._item) @@ -9118,6 +9169,10 @@ var Style = Base.extend(new function() { return !!this.getStrokeColor() && this.getStrokeWidth() > 0; }, + hasShadow: function() { + return !!this.getShadowColor() && this.getShadowBlur() > 0; + }, + getLeading: function getLeading() { var leading = getLeading.base.call(this); return leading != null ? leading : this.getFontSize() * 1.2; @@ -9377,18 +9432,10 @@ var DomEvent = { }; DomEvent.requestAnimationFrame = new function() { - var part = 'equestAnimationFrame', - request = window['r' + part] || window['webkitR' + part] - || window['mozR' + part] || window['oR' + part] - || window['msR' + part]; - if (request) { - request(function(time) { - if (time == null) - request = null; - }); - } - - var callbacks = [], + var nativeRequest = DomElement.getPrefixValue(window, + 'requestAnimationFrame'), + requested = false, + callbacks = [], focused = true, timer; @@ -9401,24 +9448,36 @@ DomEvent.requestAnimationFrame = new function() { } }); - return function(callback, element) { - if (request) - return request(callback, element); - callbacks.push([callback, element]); - if (timer) - return; - timer = setInterval(function() { - for (var i = callbacks.length - 1; i >= 0; i--) { - var entry = callbacks[i], - func = entry[0], - el = entry[1]; - if (!el || (PaperScope.getAttribute(el, 'keepalive') == 'true' - || focused) && DomElement.isInView(el)) { - callbacks.splice(i, 1); - func(Date.now()); - } + function handleCallbacks() { + for (var i = callbacks.length - 1; i >= 0; i--) { + var entry = callbacks[i], + func = entry[0], + el = entry[1]; + if (!el || (PaperScope.getAttribute(el, 'keepalive') == 'true' + || focused) && DomElement.isInView(el)) { + callbacks.splice(i, 1); + func(); } - }, 1000 / 60); + } + if (nativeRequest) { + if (callbacks.length) { + nativeRequest(handleCallbacks); + } else { + requested = false; + } + } + } + + return function(callback, element) { + callbacks.push([callback, element]); + if (nativeRequest) { + if (!requested) { + nativeRequest(handleCallbacks); + requested = true; + } + } else if (!timer) { + timer = setInterval(handleCallbacks, 1000 / 60); + } }; }; @@ -10005,6 +10064,7 @@ var Key = new function() { tool = scope && scope._tool; keyMap[key] = down; if (tool && tool.responds(type)) { + paper = scope; tool.fire(type, new KeyEvent(down, key, character, event)); if (view) view.draw(true); @@ -10545,6 +10605,28 @@ var Tool = PaperScopeItem.extend({ }); +var Http = { + request: function(method, url, callback) { + var xhr = new (window.ActiveXObject || XMLHttpRequest)( + 'Microsoft.XMLHTTP'); + xhr.open(method.toUpperCase(), url, true); + if ('overrideMimeType' in xhr) + xhr.overrideMimeType('text/plain'); + xhr.onreadystatechange = function() { + if (xhr.readyState === 4) { + var status = xhr.status; + if (status === 0 || status === 200) { + callback.call(xhr, xhr.responseText); + } else { + throw new Error('Could not load ' + url + ' (Error ' + + status + ')'); + } + } + }; + return xhr.send(null); + } +}; + var CanvasProvider = { canvases: [], @@ -10920,13 +11002,13 @@ new function() { return attrs; } - function exportGroup(item) { + function exportGroup(item, options) { var attrs = getTransform(item), children = item._children; var node = createElement('g', attrs); for (var i = 0, l = children.length; i < l; i++) { var child = children[i]; - var childNode = exportSVG(child); + var childNode = exportSVG(child, options); if (childNode) { if (child.isClipMask()) { var clip = createElement('clipPath'); @@ -10954,7 +11036,12 @@ new function() { return createElement('image', attrs); } - function exportPath(item) { + function exportPath(item, options) { + if (options.matchShapes) { + var shape = item.toShape(false); + if (shape) + return exportShape(shape, options); + } var segments = item._segments, type, attrs; @@ -10990,7 +11077,6 @@ new function() { function exportShape(item) { var shape = item._shape, - center = item.getPosition(true), radius = item._radius, attrs = getTransform(item, true, shape !== 'rectangle'); if (shape === 'rectangle') { @@ -11024,7 +11110,7 @@ new function() { return createElement('path', attrs); } - function exportPlacedSymbol(item) { + function exportPlacedSymbol(item, options) { var attrs = getTransform(item, true), symbol = item.getSymbol(), symbolNode = getDefinition(symbol, 'symbol'), @@ -11034,7 +11120,7 @@ new function() { symbolNode = createElement('symbol', { viewBox: formatter.rectangle(bounds) }); - symbolNode.appendChild(exportSVG(definition)); + symbolNode.appendChild(exportSVG(definition, options)); setDefinition(symbol, symbolNode, 'symbol'); } attrs.href = '#' + symbolNode.id; @@ -11045,7 +11131,7 @@ new function() { return createElement('use', attrs); } - function exportGradient(color, item) { + function exportGradient(color) { var gradientNode = getDefinition(color, 'color'); if (!gradientNode) { var gradient = color.getGradient(), @@ -11169,29 +11255,31 @@ new function() { } function exportDefinitions(node, options) { - if (!definitions) - return node; - var svg = node.nodeName.toLowerCase() === 'svg' && node, + var svg = node, defs = null; - for (var i in definitions.svgs) { - if (!defs) { - if (!svg) { - svg = createElement('svg'); - svg.appendChild(node); + if (definitions) { + svg = node.nodeName.toLowerCase() === 'svg' && node; + for (var i in definitions.svgs) { + if (!defs) { + if (!svg) { + svg = createElement('svg'); + svg.appendChild(node); + } + defs = svg.insertBefore(createElement('defs'), + svg.firstChild); } - defs = svg.insertBefore(createElement('defs'), svg.firstChild); + defs.appendChild(definitions.svgs[i]); } - defs.appendChild(definitions.svgs[i]); + definitions = null; } - definitions = null; return options.asString ? new XMLSerializer().serializeToString(svg) : svg; } - function exportSVG(item) { + function exportSVG(item, options) { var exporter = exporters[item._type], - node = exporter && exporter(item, item._type); + node = exporter && exporter(item, options); if (node && item._data) node.setAttribute('data-paper-data', JSON.stringify(item._data)); return node && applyStyle(item, node); @@ -11207,7 +11295,7 @@ new function() { Item.inject({ exportSVG: function(options) { options = setOptions(options); - return exportDefinitions(exportSVG(this), options); + return exportDefinitions(exportSVG(this, options), options); } }); @@ -11226,7 +11314,7 @@ new function() { 'xmlns:xlink': 'http://www.w3.org/1999/xlink' }); for (var i = 0, l = layers.length; i < l; i++) - node.appendChild(exportSVG(layers[i])); + node.appendChild(exportSVG(layers[i], options)); return exportDefinitions(node, options); } }); @@ -11255,15 +11343,15 @@ new function() { function getPoint(node, x, y, allowNull) { x = getValue(node, x, false, allowNull); y = getValue(node, y, false, allowNull); - return allowNull && x == null && y == null ? null - : new Point(x || 0, y || 0); + return allowNull && (x == null || y == null) ? null + : new Point(x, y); } function getSize(node, w, h, allowNull) { w = getValue(node, w, false, allowNull); h = getValue(node, h, false, allowNull); - return allowNull && w == null && h == null ? null - : new Size(w || 0, h || 0); + return allowNull && (w == null || h == null) ? null + : new Size(w, h); } function convertValue(value, type, lookup) { @@ -11280,7 +11368,7 @@ new function() { : value; } - function importGroup(node, type, options) { + function importGroup(node, type, isRoot, options) { var nodes = node.childNodes, clip = type === 'clippath', item = new Group(), @@ -11289,20 +11377,20 @@ new function() { children = []; if (!clip) { item._transformContent = false; - item = applyAttributes(item, node); + item = applyAttributes(item, node, isRoot); project._currentStyle = item._style.clone(); } for (var i = 0, l = nodes.length; i < l; i++) { var childNode = nodes[i], child; if (childNode.nodeType === 1 - && (child = importSVG(childNode, options)) + && (child = importSVG(childNode, false, options)) && !(child instanceof Symbol)) children.push(child); } item.addChildren(children); if (clip) - item = applyAttributes(item.reduce(), node); + item = applyAttributes(item.reduce(), node, isRoot); project._currentStyle = currentStyle; if (clip || type === 'defs') { item.remove(); @@ -11356,8 +11444,8 @@ new function() { } var importers = { - '#document': function(node, type, options) { - return importSVG(node.childNodes[0], options); + '#document': function(node, type, isRoot, options) { + return importSVG(node.childNodes[0], isRoot, options); }, g: importGroup, @@ -11379,8 +11467,8 @@ new function() { return raster; }, - symbol: function(node, type) { - return new Symbol(importGroup(node, type), true); + symbol: function(node, type, isRoot, options) { + return new Symbol(importGroup(node, type, isRoot, options), true); }, defs: importGroup, @@ -11474,8 +11562,13 @@ new function() { var attributes = Base.merge(Base.each(SVGStyles, function(entry) { this[entry.attribute] = function(item, value) { - item[entry.set]( - convertValue(value, entry.type, entry.fromSVG)); + item[entry.set](convertValue(value, entry.type, entry.fromSVG)); + if (entry.type === 'color' && item instanceof Shape) { + var color = item[entry.get](); + if (color) + color.transform(new Matrix().translate( + item.getPosition(true).negate())); + } }; }, {}), { id: function(item, value) { @@ -11561,10 +11654,10 @@ new function() { : value; } - function applyAttributes(item, node) { + function applyAttributes(item, node, isRoot) { var styles = { node: DomElement.getStyles(node) || {}, - parent: DomElement.getStyles(node.parentNode) || {} + parent: !isRoot && DomElement.getStyles(node.parentNode) || {} }; Base.each(attributes, function(apply, name) { var value = getAttribute(node, name, styles); @@ -11580,38 +11673,55 @@ new function() { return match && definitions[match[1]]; } - function importSVG(node, options, clearDefs) { + function importSVG(node, isRoot, options) { if (!options) options = {}; - if (typeof node === 'string') + if (typeof node === 'string') { + if (isRoot && !/^.*